2 * Copyright (C) 2013 Noralf Tronnes
4 * This driver is inspired by:
5 * st7735fb.c, Copyright (C) 2011, Matt Porter
6 * broadsheetfb.c, Copyright (C) 2008, Jaya Kumar
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/string.h>
28 #include <linux/vmalloc.h>
29 #include <linux/slab.h>
30 #include <linux/init.h>
32 #include <linux/gpio.h>
33 #include <linux/spi/spi.h>
34 #include <linux/delay.h>
35 #include <linux/uaccess.h>
36 #include <linux/backlight.h>
37 #include <linux/platform_device.h>
38 #include <linux/spinlock.h>
39 #include <linux/dma-mapping.h>
41 #include <linux/of_gpio.h>
45 extern void fbtft_sysfs_init(struct fbtft_par
*par
);
46 extern void fbtft_sysfs_exit(struct fbtft_par
*par
);
47 extern void fbtft_expand_debug_value(unsigned long *debug
);
48 extern int fbtft_gamma_parse_str(struct fbtft_par
*par
, unsigned long *curves
,
49 const char *str
, int size
);
51 static unsigned long debug
;
52 module_param(debug
, ulong
, 0);
53 MODULE_PARM_DESC(debug
, "override device debug level");
55 static bool dma
= true;
56 module_param(dma
, bool, 0);
57 MODULE_PARM_DESC(dma
, "Use DMA buffer");
60 void fbtft_dbg_hex(const struct device
*dev
, int groupsize
,
61 void *buf
, size_t len
, const char *fmt
, ...)
64 static char textbuf
[512];
69 text_len
= vscnprintf(text
, sizeof(textbuf
), fmt
, args
);
72 hex_dump_to_buffer(buf
, len
, 32, groupsize
, text
+ text_len
,
73 512 - text_len
, false);
76 dev_info(dev
, "%s ...\n", text
);
78 dev_info(dev
, "%s\n", text
);
80 EXPORT_SYMBOL(fbtft_dbg_hex
);
82 static unsigned long fbtft_request_gpios_match(struct fbtft_par
*par
,
83 const struct fbtft_gpio
*gpio
)
88 fbtft_par_dbg(DEBUG_REQUEST_GPIOS_MATCH
, par
, "%s('%s')\n",
89 __func__
, gpio
->name
);
91 if (strcasecmp(gpio
->name
, "reset") == 0) {
92 par
->gpio
.reset
= gpio
->gpio
;
93 return GPIOF_OUT_INIT_HIGH
;
94 } else if (strcasecmp(gpio
->name
, "dc") == 0) {
95 par
->gpio
.dc
= gpio
->gpio
;
96 return GPIOF_OUT_INIT_LOW
;
97 } else if (strcasecmp(gpio
->name
, "cs") == 0) {
98 par
->gpio
.cs
= gpio
->gpio
;
99 return GPIOF_OUT_INIT_HIGH
;
100 } else if (strcasecmp(gpio
->name
, "wr") == 0) {
101 par
->gpio
.wr
= gpio
->gpio
;
102 return GPIOF_OUT_INIT_HIGH
;
103 } else if (strcasecmp(gpio
->name
, "rd") == 0) {
104 par
->gpio
.rd
= gpio
->gpio
;
105 return GPIOF_OUT_INIT_HIGH
;
106 } else if (strcasecmp(gpio
->name
, "latch") == 0) {
107 par
->gpio
.latch
= gpio
->gpio
;
108 return GPIOF_OUT_INIT_LOW
;
109 } else if (gpio
->name
[0] == 'd' && gpio
->name
[1] == 'b') {
110 ret
= kstrtol(&gpio
->name
[2], 10, &val
);
111 if (ret
== 0 && val
< 16) {
112 par
->gpio
.db
[val
] = gpio
->gpio
;
113 return GPIOF_OUT_INIT_LOW
;
115 } else if (strcasecmp(gpio
->name
, "led") == 0) {
116 par
->gpio
.led
[0] = gpio
->gpio
;
117 return GPIOF_OUT_INIT_LOW
;
118 } else if (strcasecmp(gpio
->name
, "led_") == 0) {
119 par
->gpio
.led
[0] = gpio
->gpio
;
120 return GPIOF_OUT_INIT_HIGH
;
123 return FBTFT_GPIO_NO_MATCH
;
126 static int fbtft_request_gpios(struct fbtft_par
*par
)
128 struct fbtft_platform_data
*pdata
= par
->pdata
;
129 const struct fbtft_gpio
*gpio
;
133 if (pdata
&& pdata
->gpios
) {
135 while (gpio
->name
[0]) {
136 flags
= FBTFT_GPIO_NO_MATCH
;
137 /* if driver provides match function, try it first,
138 if no match use our own */
139 if (par
->fbtftops
.request_gpios_match
)
140 flags
= par
->fbtftops
.request_gpios_match(par
, gpio
);
141 if (flags
== FBTFT_GPIO_NO_MATCH
)
142 flags
= fbtft_request_gpios_match(par
, gpio
);
143 if (flags
!= FBTFT_GPIO_NO_MATCH
) {
144 ret
= devm_gpio_request_one(par
->info
->device
,
146 par
->info
->device
->driver
->name
);
148 dev_err(par
->info
->device
,
149 "%s: gpio_request_one('%s'=%d) failed with %d\n",
150 __func__
, gpio
->name
,
154 fbtft_par_dbg(DEBUG_REQUEST_GPIOS
, par
,
155 "%s: '%s' = GPIO%d\n",
156 __func__
, gpio
->name
, gpio
->gpio
);
166 static int fbtft_request_one_gpio(struct fbtft_par
*par
,
167 const char *name
, int index
, int *gpiop
)
169 struct device
*dev
= par
->info
->device
;
170 struct device_node
*node
= dev
->of_node
;
171 int gpio
, flags
, ret
= 0;
172 enum of_gpio_flags of_flags
;
174 if (of_find_property(node
, name
, NULL
)) {
175 gpio
= of_get_named_gpio_flags(node
, name
, index
, &of_flags
);
178 if (gpio
== -EPROBE_DEFER
)
182 "failed to get '%s' from DT\n", name
);
186 /* active low translates to initially low */
187 flags
= (of_flags
& OF_GPIO_ACTIVE_LOW
) ? GPIOF_OUT_INIT_LOW
:
189 ret
= devm_gpio_request_one(dev
, gpio
, flags
,
193 "gpio_request_one('%s'=%d) failed with %d\n",
199 fbtft_par_dbg(DEBUG_REQUEST_GPIOS
, par
, "%s: '%s' = GPIO%d\n",
200 __func__
, name
, gpio
);
206 static int fbtft_request_gpios_dt(struct fbtft_par
*par
)
211 if (!par
->info
->device
->of_node
)
214 ret
= fbtft_request_one_gpio(par
, "reset-gpios", 0, &par
->gpio
.reset
);
217 ret
= fbtft_request_one_gpio(par
, "dc-gpios", 0, &par
->gpio
.dc
);
220 ret
= fbtft_request_one_gpio(par
, "rd-gpios", 0, &par
->gpio
.rd
);
223 ret
= fbtft_request_one_gpio(par
, "wr-gpios", 0, &par
->gpio
.wr
);
226 ret
= fbtft_request_one_gpio(par
, "cs-gpios", 0, &par
->gpio
.cs
);
229 ret
= fbtft_request_one_gpio(par
, "latch-gpios", 0, &par
->gpio
.latch
);
232 for (i
= 0; i
< 16; i
++) {
233 ret
= fbtft_request_one_gpio(par
, "db-gpios", i
,
237 ret
= fbtft_request_one_gpio(par
, "led-gpios", i
,
241 ret
= fbtft_request_one_gpio(par
, "aux-gpios", i
,
251 #ifdef CONFIG_FB_BACKLIGHT
252 static int fbtft_backlight_update_status(struct backlight_device
*bd
)
254 struct fbtft_par
*par
= bl_get_data(bd
);
255 bool polarity
= !!(bd
->props
.state
& BL_CORE_DRIVER1
);
257 fbtft_par_dbg(DEBUG_BACKLIGHT
, par
,
258 "%s: polarity=%d, power=%d, fb_blank=%d\n",
259 __func__
, polarity
, bd
->props
.power
, bd
->props
.fb_blank
);
261 if ((bd
->props
.power
== FB_BLANK_UNBLANK
) && (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
))
262 gpio_set_value(par
->gpio
.led
[0], polarity
);
264 gpio_set_value(par
->gpio
.led
[0], !polarity
);
269 static int fbtft_backlight_get_brightness(struct backlight_device
*bd
)
271 return bd
->props
.brightness
;
274 void fbtft_unregister_backlight(struct fbtft_par
*par
)
276 const struct backlight_ops
*bl_ops
;
278 fbtft_par_dbg(DEBUG_BACKLIGHT
, par
, "%s()\n", __func__
);
280 if (par
->info
->bl_dev
) {
281 par
->info
->bl_dev
->props
.power
= FB_BLANK_POWERDOWN
;
282 backlight_update_status(par
->info
->bl_dev
);
283 bl_ops
= par
->info
->bl_dev
->ops
;
284 backlight_device_unregister(par
->info
->bl_dev
);
285 par
->info
->bl_dev
= NULL
;
289 void fbtft_register_backlight(struct fbtft_par
*par
)
291 struct backlight_device
*bd
;
292 struct backlight_properties bl_props
= { 0, };
293 struct backlight_ops
*bl_ops
;
295 fbtft_par_dbg(DEBUG_BACKLIGHT
, par
, "%s()\n", __func__
);
297 if (par
->gpio
.led
[0] == -1) {
298 fbtft_par_dbg(DEBUG_BACKLIGHT
, par
,
299 "%s(): led pin not set, exiting.\n", __func__
);
303 bl_ops
= devm_kzalloc(par
->info
->device
, sizeof(struct backlight_ops
),
306 dev_err(par
->info
->device
,
307 "%s: could not allocate memeory for backlight operations.\n",
312 bl_ops
->get_brightness
= fbtft_backlight_get_brightness
;
313 bl_ops
->update_status
= fbtft_backlight_update_status
;
314 bl_props
.type
= BACKLIGHT_RAW
;
315 /* Assume backlight is off, get polarity from current state of pin */
316 bl_props
.power
= FB_BLANK_POWERDOWN
;
317 if (!gpio_get_value(par
->gpio
.led
[0]))
318 bl_props
.state
|= BL_CORE_DRIVER1
;
320 bd
= backlight_device_register(dev_driver_string(par
->info
->device
),
321 par
->info
->device
, par
, bl_ops
, &bl_props
);
323 dev_err(par
->info
->device
,
324 "cannot register backlight device (%ld)\n",
328 par
->info
->bl_dev
= bd
;
330 if (!par
->fbtftops
.unregister_backlight
)
331 par
->fbtftops
.unregister_backlight
= fbtft_unregister_backlight
;
334 void fbtft_register_backlight(struct fbtft_par
*par
) { };
335 void fbtft_unregister_backlight(struct fbtft_par
*par
) { };
337 EXPORT_SYMBOL(fbtft_register_backlight
);
338 EXPORT_SYMBOL(fbtft_unregister_backlight
);
340 static void fbtft_set_addr_win(struct fbtft_par
*par
, int xs
, int ys
, int xe
,
343 fbtft_par_dbg(DEBUG_SET_ADDR_WIN
, par
,
344 "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__
, xs
, ys
, xe
, ye
);
346 /* Column address set */
348 (xs
>> 8) & 0xFF, xs
& 0xFF, (xe
>> 8) & 0xFF, xe
& 0xFF);
352 (ys
>> 8) & 0xFF, ys
& 0xFF, (ye
>> 8) & 0xFF, ye
& 0xFF);
355 write_reg(par
, 0x2C);
359 static void fbtft_reset(struct fbtft_par
*par
)
361 if (par
->gpio
.reset
== -1)
363 fbtft_par_dbg(DEBUG_RESET
, par
, "%s()\n", __func__
);
364 gpio_set_value(par
->gpio
.reset
, 0);
366 gpio_set_value(par
->gpio
.reset
, 1);
371 static void fbtft_update_display(struct fbtft_par
*par
, unsigned start_line
,
375 struct timespec ts_start
, ts_end
, ts_fps
, ts_duration
;
376 long fps_ms
, fps_us
, duration_ms
, duration_us
;
377 long fps
, throughput
;
381 if (unlikely(par
->debug
& (DEBUG_TIME_FIRST_UPDATE
| DEBUG_TIME_EACH_UPDATE
))) {
382 if ((par
->debug
& DEBUG_TIME_EACH_UPDATE
) || \
383 ((par
->debug
& DEBUG_TIME_FIRST_UPDATE
) && !par
->first_update_done
)) {
384 getnstimeofday(&ts_start
);
390 if (start_line
> end_line
) {
391 dev_warn(par
->info
->device
,
392 "%s: start_line=%u is larger than end_line=%u. Shouldn't happen, will do full display update\n",
393 __func__
, start_line
, end_line
);
395 end_line
= par
->info
->var
.yres
- 1;
397 if (start_line
> par
->info
->var
.yres
- 1 || end_line
> par
->info
->var
.yres
- 1) {
398 dev_warn(par
->info
->device
,
399 "%s: start_line=%u or end_line=%u is larger than max=%d. Shouldn't happen, will do full display update\n",
400 __func__
, start_line
, end_line
, par
->info
->var
.yres
- 1);
402 end_line
= par
->info
->var
.yres
- 1;
405 fbtft_par_dbg(DEBUG_UPDATE_DISPLAY
, par
, "%s(start_line=%u, end_line=%u)\n",
406 __func__
, start_line
, end_line
);
408 if (par
->fbtftops
.set_addr_win
)
409 par
->fbtftops
.set_addr_win(par
, 0, start_line
,
410 par
->info
->var
.xres
-1, end_line
);
412 offset
= start_line
* par
->info
->fix
.line_length
;
413 len
= (end_line
- start_line
+ 1) * par
->info
->fix
.line_length
;
414 ret
= par
->fbtftops
.write_vmem(par
, offset
, len
);
416 dev_err(par
->info
->device
,
417 "%s: write_vmem failed to update display buffer\n",
420 if (unlikely(timeit
)) {
421 getnstimeofday(&ts_end
);
422 if (par
->update_time
.tv_nsec
== 0 && par
->update_time
.tv_sec
== 0) {
423 par
->update_time
.tv_sec
= ts_start
.tv_sec
;
424 par
->update_time
.tv_nsec
= ts_start
.tv_nsec
;
426 ts_fps
= timespec_sub(ts_start
, par
->update_time
);
427 par
->update_time
.tv_sec
= ts_start
.tv_sec
;
428 par
->update_time
.tv_nsec
= ts_start
.tv_nsec
;
429 fps_ms
= (ts_fps
.tv_sec
* 1000) + ((ts_fps
.tv_nsec
/ 1000000) % 1000);
430 fps_us
= (ts_fps
.tv_nsec
/ 1000) % 1000;
431 fps
= fps_ms
* 1000 + fps_us
;
432 fps
= fps
? 1000000 / fps
: 0;
434 ts_duration
= timespec_sub(ts_end
, ts_start
);
435 duration_ms
= (ts_duration
.tv_sec
* 1000) + ((ts_duration
.tv_nsec
/ 1000000) % 1000);
436 duration_us
= (ts_duration
.tv_nsec
/ 1000) % 1000;
437 throughput
= duration_ms
* 1000 + duration_us
;
438 throughput
= throughput
? (len
* 1000) / throughput
: 0;
439 throughput
= throughput
* 1000 / 1024;
441 dev_info(par
->info
->device
,
442 "Display update: %ld kB/s (%ld.%.3ld ms), fps=%ld (%ld.%.3ld ms)\n",
443 throughput
, duration_ms
, duration_us
,
444 fps
, fps_ms
, fps_us
);
445 par
->first_update_done
= true;
450 static void fbtft_mkdirty(struct fb_info
*info
, int y
, int height
)
452 struct fbtft_par
*par
= info
->par
;
453 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
455 /* special case, needed ? */
458 height
= info
->var
.yres
- 1;
461 /* Mark display lines/area as dirty */
462 spin_lock(&par
->dirty_lock
);
463 if (y
< par
->dirty_lines_start
)
464 par
->dirty_lines_start
= y
;
465 if (y
+ height
- 1 > par
->dirty_lines_end
)
466 par
->dirty_lines_end
= y
+ height
- 1;
467 spin_unlock(&par
->dirty_lock
);
469 /* Schedule deferred_io to update display (no-op if already on queue)*/
470 schedule_delayed_work(&info
->deferred_work
, fbdefio
->delay
);
473 static void fbtft_deferred_io(struct fb_info
*info
, struct list_head
*pagelist
)
475 struct fbtft_par
*par
= info
->par
;
476 unsigned dirty_lines_start
, dirty_lines_end
;
479 unsigned y_low
= 0, y_high
= 0;
482 spin_lock(&par
->dirty_lock
);
483 dirty_lines_start
= par
->dirty_lines_start
;
484 dirty_lines_end
= par
->dirty_lines_end
;
485 /* set display line markers as clean */
486 par
->dirty_lines_start
= par
->info
->var
.yres
- 1;
487 par
->dirty_lines_end
= 0;
488 spin_unlock(&par
->dirty_lock
);
490 /* Mark display lines as dirty */
491 list_for_each_entry(page
, pagelist
, lru
) {
493 index
= page
->index
<< PAGE_SHIFT
;
494 y_low
= index
/ info
->fix
.line_length
;
495 y_high
= (index
+ PAGE_SIZE
- 1) / info
->fix
.line_length
;
496 fbtft_dev_dbg(DEBUG_DEFERRED_IO
, par
, info
->device
,
497 "page->index=%lu y_low=%d y_high=%d\n",
498 page
->index
, y_low
, y_high
);
499 if (y_high
> info
->var
.yres
- 1)
500 y_high
= info
->var
.yres
- 1;
501 if (y_low
< dirty_lines_start
)
502 dirty_lines_start
= y_low
;
503 if (y_high
> dirty_lines_end
)
504 dirty_lines_end
= y_high
;
507 par
->fbtftops
.update_display(info
->par
,
508 dirty_lines_start
, dirty_lines_end
);
512 static void fbtft_fb_fillrect(struct fb_info
*info
,
513 const struct fb_fillrect
*rect
)
515 struct fbtft_par
*par
= info
->par
;
517 fbtft_dev_dbg(DEBUG_FB_FILLRECT
, par
, info
->dev
,
518 "%s: dx=%d, dy=%d, width=%d, height=%d\n",
519 __func__
, rect
->dx
, rect
->dy
, rect
->width
, rect
->height
);
520 sys_fillrect(info
, rect
);
522 par
->fbtftops
.mkdirty(info
, rect
->dy
, rect
->height
);
525 static void fbtft_fb_copyarea(struct fb_info
*info
,
526 const struct fb_copyarea
*area
)
528 struct fbtft_par
*par
= info
->par
;
530 fbtft_dev_dbg(DEBUG_FB_COPYAREA
, par
, info
->dev
,
531 "%s: dx=%d, dy=%d, width=%d, height=%d\n",
532 __func__
, area
->dx
, area
->dy
, area
->width
, area
->height
);
533 sys_copyarea(info
, area
);
535 par
->fbtftops
.mkdirty(info
, area
->dy
, area
->height
);
538 static void fbtft_fb_imageblit(struct fb_info
*info
,
539 const struct fb_image
*image
)
541 struct fbtft_par
*par
= info
->par
;
543 fbtft_dev_dbg(DEBUG_FB_IMAGEBLIT
, par
, info
->dev
,
544 "%s: dx=%d, dy=%d, width=%d, height=%d\n",
545 __func__
, image
->dx
, image
->dy
, image
->width
, image
->height
);
546 sys_imageblit(info
, image
);
548 par
->fbtftops
.mkdirty(info
, image
->dy
, image
->height
);
551 static ssize_t
fbtft_fb_write(struct fb_info
*info
, const char __user
*buf
,
552 size_t count
, loff_t
*ppos
)
554 struct fbtft_par
*par
= info
->par
;
557 fbtft_dev_dbg(DEBUG_FB_WRITE
, par
, info
->dev
,
558 "%s: count=%zd, ppos=%llu\n", __func__
, count
, *ppos
);
559 res
= fb_sys_write(info
, buf
, count
, ppos
);
561 /* TODO: only mark changed area
562 update all for now */
563 par
->fbtftops
.mkdirty(info
, -1, 0);
569 static unsigned int chan_to_field(unsigned chan
, struct fb_bitfield
*bf
)
572 chan
>>= 16 - bf
->length
;
573 return chan
<< bf
->offset
;
576 static int fbtft_fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
577 unsigned blue
, unsigned transp
,
578 struct fb_info
*info
)
580 struct fbtft_par
*par
= info
->par
;
584 fbtft_dev_dbg(DEBUG_FB_SETCOLREG
, par
, info
->dev
,
585 "%s(regno=%u, red=0x%X, green=0x%X, blue=0x%X, trans=0x%X)\n",
586 __func__
, regno
, red
, green
, blue
, transp
);
588 switch (info
->fix
.visual
) {
589 case FB_VISUAL_TRUECOLOR
:
591 u32
*pal
= info
->pseudo_palette
;
593 val
= chan_to_field(red
, &info
->var
.red
);
594 val
|= chan_to_field(green
, &info
->var
.green
);
595 val
|= chan_to_field(blue
, &info
->var
.blue
);
606 static int fbtft_fb_blank(int blank
, struct fb_info
*info
)
608 struct fbtft_par
*par
= info
->par
;
611 fbtft_dev_dbg(DEBUG_FB_BLANK
, par
, info
->dev
, "%s(blank=%d)\n",
614 if (!par
->fbtftops
.blank
)
618 case FB_BLANK_POWERDOWN
:
619 case FB_BLANK_VSYNC_SUSPEND
:
620 case FB_BLANK_HSYNC_SUSPEND
:
621 case FB_BLANK_NORMAL
:
622 ret
= par
->fbtftops
.blank(par
, true);
624 case FB_BLANK_UNBLANK
:
625 ret
= par
->fbtftops
.blank(par
, false);
631 static void fbtft_merge_fbtftops(struct fbtft_ops
*dst
, struct fbtft_ops
*src
)
634 dst
->write
= src
->write
;
636 dst
->read
= src
->read
;
638 dst
->write_vmem
= src
->write_vmem
;
639 if (src
->write_register
)
640 dst
->write_register
= src
->write_register
;
641 if (src
->set_addr_win
)
642 dst
->set_addr_win
= src
->set_addr_win
;
644 dst
->reset
= src
->reset
;
646 dst
->mkdirty
= src
->mkdirty
;
647 if (src
->update_display
)
648 dst
->update_display
= src
->update_display
;
649 if (src
->init_display
)
650 dst
->init_display
= src
->init_display
;
652 dst
->blank
= src
->blank
;
653 if (src
->request_gpios_match
)
654 dst
->request_gpios_match
= src
->request_gpios_match
;
655 if (src
->request_gpios
)
656 dst
->request_gpios
= src
->request_gpios
;
657 if (src
->verify_gpios
)
658 dst
->verify_gpios
= src
->verify_gpios
;
659 if (src
->register_backlight
)
660 dst
->register_backlight
= src
->register_backlight
;
661 if (src
->unregister_backlight
)
662 dst
->unregister_backlight
= src
->unregister_backlight
;
664 dst
->set_var
= src
->set_var
;
666 dst
->set_gamma
= src
->set_gamma
;
670 * fbtft_framebuffer_alloc - creates a new frame buffer info structure
672 * @display: pointer to structure describing the display
673 * @dev: pointer to the device for this fb, this can be NULL
675 * Creates a new frame buffer info structure.
677 * Also creates and populates the following structures:
680 * info->pseudo_palette
684 * Returns the new structure, or NULL if an error occurred.
687 struct fb_info
*fbtft_framebuffer_alloc(struct fbtft_display
*display
,
690 struct fb_info
*info
;
691 struct fbtft_par
*par
;
692 struct fb_ops
*fbops
= NULL
;
693 struct fb_deferred_io
*fbdefio
= NULL
;
694 struct fbtft_platform_data
*pdata
= dev
->platform_data
;
700 int txbuflen
= display
->txbuflen
;
701 unsigned bpp
= display
->bpp
;
702 unsigned fps
= display
->fps
;
704 int *init_sequence
= display
->init_sequence
;
705 char *gamma
= display
->gamma
;
706 unsigned long *gamma_curves
= NULL
;
709 if (display
->gamma_num
* display
->gamma_len
> FBTFT_GAMMA_MAX_VALUES_TOTAL
) {
711 "%s: FBTFT_GAMMA_MAX_VALUES_TOTAL=%d is exceeded\n",
712 __func__
, FBTFT_GAMMA_MAX_VALUES_TOTAL
);
723 dev_err(dev
, "platform data is missing\n");
727 /* override driver values? */
731 txbuflen
= pdata
->txbuflen
;
732 if (pdata
->display
.init_sequence
)
733 init_sequence
= pdata
->display
.init_sequence
;
735 gamma
= pdata
->gamma
;
736 if (pdata
->display
.debug
)
737 display
->debug
= pdata
->display
.debug
;
738 if (pdata
->display
.backlight
)
739 display
->backlight
= pdata
->display
.backlight
;
740 if (pdata
->display
.width
)
741 display
->width
= pdata
->display
.width
;
742 if (pdata
->display
.height
)
743 display
->height
= pdata
->display
.height
;
744 if (pdata
->display
.buswidth
)
745 display
->buswidth
= pdata
->display
.buswidth
;
746 if (pdata
->display
.regwidth
)
747 display
->regwidth
= pdata
->display
.regwidth
;
749 display
->debug
|= debug
;
750 fbtft_expand_debug_value(&display
->debug
);
752 switch (pdata
->rotate
) {
755 width
= display
->height
;
756 height
= display
->width
;
759 width
= display
->width
;
760 height
= display
->height
;
763 vmem_size
= display
->width
* display
->height
* bpp
/ 8;
764 vmem
= vzalloc(vmem_size
);
768 fbops
= devm_kzalloc(dev
, sizeof(struct fb_ops
), GFP_KERNEL
);
772 fbdefio
= devm_kzalloc(dev
, sizeof(struct fb_deferred_io
), GFP_KERNEL
);
776 buf
= devm_kzalloc(dev
, 128, GFP_KERNEL
);
780 if (display
->gamma_num
&& display
->gamma_len
) {
781 gamma_curves
= devm_kzalloc(dev
, display
->gamma_num
* display
->gamma_len
* sizeof(gamma_curves
[0]),
787 info
= framebuffer_alloc(sizeof(struct fbtft_par
), dev
);
791 info
->screen_base
= (u8 __force __iomem
*)vmem
;
793 info
->fbdefio
= fbdefio
;
795 fbops
->owner
= dev
->driver
->owner
;
796 fbops
->fb_read
= fb_sys_read
;
797 fbops
->fb_write
= fbtft_fb_write
;
798 fbops
->fb_fillrect
= fbtft_fb_fillrect
;
799 fbops
->fb_copyarea
= fbtft_fb_copyarea
;
800 fbops
->fb_imageblit
= fbtft_fb_imageblit
;
801 fbops
->fb_setcolreg
= fbtft_fb_setcolreg
;
802 fbops
->fb_blank
= fbtft_fb_blank
;
804 fbdefio
->delay
= HZ
/fps
;
805 fbdefio
->deferred_io
= fbtft_deferred_io
;
806 fb_deferred_io_init(info
);
808 strncpy(info
->fix
.id
, dev
->driver
->name
, 16);
809 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
810 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
811 info
->fix
.xpanstep
= 0;
812 info
->fix
.ypanstep
= 0;
813 info
->fix
.ywrapstep
= 0;
814 info
->fix
.line_length
= width
*bpp
/8;
815 info
->fix
.accel
= FB_ACCEL_NONE
;
816 info
->fix
.smem_len
= vmem_size
;
818 info
->var
.rotate
= pdata
->rotate
;
819 info
->var
.xres
= width
;
820 info
->var
.yres
= height
;
821 info
->var
.xres_virtual
= info
->var
.xres
;
822 info
->var
.yres_virtual
= info
->var
.yres
;
823 info
->var
.bits_per_pixel
= bpp
;
824 info
->var
.nonstd
= 1;
827 info
->var
.red
.offset
= 11;
828 info
->var
.red
.length
= 5;
829 info
->var
.green
.offset
= 5;
830 info
->var
.green
.length
= 6;
831 info
->var
.blue
.offset
= 0;
832 info
->var
.blue
.length
= 5;
833 info
->var
.transp
.offset
= 0;
834 info
->var
.transp
.length
= 0;
836 info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_VIRTFB
;
840 par
->pdata
= dev
->platform_data
;
841 par
->debug
= display
->debug
;
843 spin_lock_init(&par
->dirty_lock
);
844 par
->bgr
= pdata
->bgr
;
845 par
->startbyte
= pdata
->startbyte
;
846 par
->init_sequence
= init_sequence
;
847 par
->gamma
.curves
= gamma_curves
;
848 par
->gamma
.num_curves
= display
->gamma_num
;
849 par
->gamma
.num_values
= display
->gamma_len
;
850 mutex_init(&par
->gamma
.lock
);
851 info
->pseudo_palette
= par
->pseudo_palette
;
853 if (par
->gamma
.curves
&& gamma
) {
854 if (fbtft_gamma_parse_str(par
,
855 par
->gamma
.curves
, gamma
, strlen(gamma
)))
859 /* Transmit buffer */
861 txbuflen
= vmem_size
+ 2; /* add in case startbyte is used */
863 #ifdef __LITTLE_ENDIAN
864 if ((!txbuflen
) && (bpp
> 8))
865 txbuflen
= PAGE_SIZE
; /* need buffer for byteswapping */
870 dev
->coherent_dma_mask
= ~0;
871 txbuf
= dmam_alloc_coherent(dev
, txbuflen
, &par
->txbuf
.dma
, GFP_DMA
);
873 txbuf
= devm_kzalloc(par
->info
->device
, txbuflen
, GFP_KERNEL
);
877 par
->txbuf
.buf
= txbuf
;
878 par
->txbuf
.len
= txbuflen
;
881 /* Initialize gpios to disabled */
882 par
->gpio
.reset
= -1;
887 par
->gpio
.latch
= -1;
888 for (i
= 0; i
< 16; i
++) {
889 par
->gpio
.db
[i
] = -1;
890 par
->gpio
.led
[i
] = -1;
891 par
->gpio
.aux
[i
] = -1;
894 /* default fbtft operations */
895 par
->fbtftops
.write
= fbtft_write_spi
;
896 par
->fbtftops
.read
= fbtft_read_spi
;
897 par
->fbtftops
.write_vmem
= fbtft_write_vmem16_bus8
;
898 par
->fbtftops
.write_register
= fbtft_write_reg8_bus8
;
899 par
->fbtftops
.set_addr_win
= fbtft_set_addr_win
;
900 par
->fbtftops
.reset
= fbtft_reset
;
901 par
->fbtftops
.mkdirty
= fbtft_mkdirty
;
902 par
->fbtftops
.update_display
= fbtft_update_display
;
903 par
->fbtftops
.request_gpios
= fbtft_request_gpios
;
904 if (display
->backlight
)
905 par
->fbtftops
.register_backlight
= fbtft_register_backlight
;
907 /* use driver provided functions */
908 fbtft_merge_fbtftops(&par
->fbtftops
, &display
->fbtftops
);
917 EXPORT_SYMBOL(fbtft_framebuffer_alloc
);
920 * fbtft_framebuffer_release - frees up all memory used by the framebuffer
922 * @info: frame buffer info structure
925 void fbtft_framebuffer_release(struct fb_info
*info
)
927 fb_deferred_io_cleanup(info
);
928 vfree(info
->screen_base
);
929 framebuffer_release(info
);
931 EXPORT_SYMBOL(fbtft_framebuffer_release
);
934 * fbtft_register_framebuffer - registers a tft frame buffer device
935 * @fb_info: frame buffer info structure
937 * Sets SPI driverdata if needed
938 * Requests needed gpios.
939 * Initializes display
941 * Registers a frame buffer device @fb_info.
943 * Returns negative errno on error, or zero for success.
946 int fbtft_register_framebuffer(struct fb_info
*fb_info
)
951 struct fbtft_par
*par
= fb_info
->par
;
952 struct spi_device
*spi
= par
->spi
;
955 if (!par
->fbtftops
.init_display
) {
956 dev_err(fb_info
->device
, "missing fbtftops.init_display()\n");
961 spi_set_drvdata(spi
, fb_info
);
963 platform_set_drvdata(par
->pdev
, fb_info
);
965 ret
= par
->fbtftops
.request_gpios(par
);
969 if (par
->fbtftops
.verify_gpios
) {
970 ret
= par
->fbtftops
.verify_gpios(par
);
975 ret
= par
->fbtftops
.init_display(par
);
978 if (par
->fbtftops
.set_var
) {
979 ret
= par
->fbtftops
.set_var(par
);
984 /* update the entire display */
985 par
->fbtftops
.update_display(par
, 0, par
->info
->var
.yres
- 1);
987 if (par
->fbtftops
.set_gamma
&& par
->gamma
.curves
) {
988 ret
= par
->fbtftops
.set_gamma(par
, par
->gamma
.curves
);
993 if (par
->fbtftops
.register_backlight
)
994 par
->fbtftops
.register_backlight(par
);
996 ret
= register_framebuffer(fb_info
);
1000 fbtft_sysfs_init(par
);
1003 sprintf(text1
, ", %d KiB %sbuffer memory",
1004 par
->txbuf
.len
>> 10, par
->txbuf
.dma
? "DMA " : "");
1006 sprintf(text2
, ", spi%d.%d at %d MHz", spi
->master
->bus_num
,
1007 spi
->chip_select
, spi
->max_speed_hz
/1000000);
1008 dev_info(fb_info
->dev
,
1009 "%s frame buffer, %dx%d, %d KiB video memory%s, fps=%lu%s\n",
1010 fb_info
->fix
.id
, fb_info
->var
.xres
, fb_info
->var
.yres
,
1011 fb_info
->fix
.smem_len
>> 10, text1
,
1012 HZ
/fb_info
->fbdefio
->delay
, text2
);
1014 #ifdef CONFIG_FB_BACKLIGHT
1015 /* Turn on backlight if available */
1016 if (fb_info
->bl_dev
) {
1017 fb_info
->bl_dev
->props
.power
= FB_BLANK_UNBLANK
;
1018 fb_info
->bl_dev
->ops
->update_status(fb_info
->bl_dev
);
1025 if (par
->fbtftops
.unregister_backlight
)
1026 par
->fbtftops
.unregister_backlight(par
);
1028 spi_set_drvdata(spi
, NULL
);
1030 platform_set_drvdata(par
->pdev
, NULL
);
1034 EXPORT_SYMBOL(fbtft_register_framebuffer
);
1037 * fbtft_unregister_framebuffer - releases a tft frame buffer device
1038 * @fb_info: frame buffer info structure
1040 * Frees SPI driverdata if needed
1042 * Unregisters frame buffer device.
1045 int fbtft_unregister_framebuffer(struct fb_info
*fb_info
)
1047 struct fbtft_par
*par
= fb_info
->par
;
1048 struct spi_device
*spi
= par
->spi
;
1052 spi_set_drvdata(spi
, NULL
);
1054 platform_set_drvdata(par
->pdev
, NULL
);
1055 if (par
->fbtftops
.unregister_backlight
)
1056 par
->fbtftops
.unregister_backlight(par
);
1057 fbtft_sysfs_exit(par
);
1058 ret
= unregister_framebuffer(fb_info
);
1061 EXPORT_SYMBOL(fbtft_unregister_framebuffer
);
1065 * fbtft_init_display_dt() - Device Tree init_display() function
1068 * Return: 0 if successful, negative if error
1070 static int fbtft_init_display_dt(struct fbtft_par
*par
)
1072 struct device_node
*node
= par
->info
->device
->of_node
;
1073 struct property
*prop
;
1080 fbtft_par_dbg(DEBUG_INIT_DISPLAY
, par
, "%s()\n", __func__
);
1085 prop
= of_find_property(node
, "init", NULL
);
1086 p
= of_prop_next_u32(prop
, NULL
, &val
);
1090 if (val
& FBTFT_OF_INIT_CMD
) {
1093 while (p
&& !(val
& 0xFFFF0000)) {
1095 dev_err(par
->info
->device
,
1096 "%s: Maximum register values exceeded\n",
1101 p
= of_prop_next_u32(prop
, p
, &val
);
1103 /* make debug message */
1105 for (j
= 0; j
< i
; j
++) {
1106 snprintf(str
, 128, " %02X", buf
[j
]);
1109 fbtft_par_dbg(DEBUG_INIT_DISPLAY
, par
,
1110 "init: write_register:%s\n", msg
);
1112 par
->fbtftops
.write_register(par
, i
,
1113 buf
[0], buf
[1], buf
[2], buf
[3],
1114 buf
[4], buf
[5], buf
[6], buf
[7],
1115 buf
[8], buf
[9], buf
[10], buf
[11],
1116 buf
[12], buf
[13], buf
[14], buf
[15],
1117 buf
[16], buf
[17], buf
[18], buf
[19],
1118 buf
[20], buf
[21], buf
[22], buf
[23],
1119 buf
[24], buf
[25], buf
[26], buf
[27],
1120 buf
[28], buf
[29], buf
[30], buf
[31],
1121 buf
[32], buf
[33], buf
[34], buf
[35],
1122 buf
[36], buf
[37], buf
[38], buf
[39],
1123 buf
[40], buf
[41], buf
[42], buf
[43],
1124 buf
[44], buf
[45], buf
[46], buf
[47],
1125 buf
[48], buf
[49], buf
[50], buf
[51],
1126 buf
[52], buf
[53], buf
[54], buf
[55],
1127 buf
[56], buf
[57], buf
[58], buf
[59],
1128 buf
[60], buf
[61], buf
[62], buf
[63]);
1129 } else if (val
& FBTFT_OF_INIT_DELAY
) {
1130 fbtft_par_dbg(DEBUG_INIT_DISPLAY
, par
,
1131 "init: msleep(%u)\n", val
& 0xFFFF);
1132 msleep(val
& 0xFFFF);
1133 p
= of_prop_next_u32(prop
, p
, &val
);
1135 dev_err(par
->info
->device
, "illegal init value 0x%X\n",
1146 * fbtft_init_display() - Generic init_display() function
1149 * Uses par->init_sequence to do the initialization
1151 * Return: 0 if successful, negative if error
1153 int fbtft_init_display(struct fbtft_par
*par
)
1161 fbtft_par_dbg(DEBUG_INIT_DISPLAY
, par
, "%s()\n", __func__
);
1164 if (!par
->init_sequence
) {
1165 dev_err(par
->info
->device
,
1166 "error: init_sequence is not set\n");
1170 /* make sure stop marker exists */
1171 for (i
= 0; i
< FBTFT_MAX_INIT_SEQUENCE
; i
++)
1172 if (par
->init_sequence
[i
] == -3)
1174 if (i
== FBTFT_MAX_INIT_SEQUENCE
) {
1175 dev_err(par
->info
->device
,
1176 "missing stop marker at end of init sequence\n");
1180 par
->fbtftops
.reset(par
);
1181 if (par
->gpio
.cs
!= -1)
1182 gpio_set_value(par
->gpio
.cs
, 0); /* Activate chip */
1185 while (i
< FBTFT_MAX_INIT_SEQUENCE
) {
1186 if (par
->init_sequence
[i
] == -3) {
1190 if (par
->init_sequence
[i
] >= 0) {
1191 dev_err(par
->info
->device
,
1192 "missing delimiter at position %d\n", i
);
1195 if (par
->init_sequence
[i
+1] < 0) {
1196 dev_err(par
->info
->device
,
1197 "missing value after delimiter %d at position %d\n",
1198 par
->init_sequence
[i
], i
);
1201 switch (par
->init_sequence
[i
]) {
1204 /* make debug message */
1207 while (par
->init_sequence
[j
] >= 0) {
1208 sprintf(str
, "0x%02X ", par
->init_sequence
[j
]);
1212 fbtft_par_dbg(DEBUG_INIT_DISPLAY
, par
,
1213 "init: write(0x%02X) %s\n",
1214 par
->init_sequence
[i
], msg
);
1218 while (par
->init_sequence
[i
] >= 0) {
1220 dev_err(par
->info
->device
,
1221 "%s: Maximum register values exceeded\n",
1225 buf
[j
++] = par
->init_sequence
[i
++];
1227 par
->fbtftops
.write_register(par
, j
,
1228 buf
[0], buf
[1], buf
[2], buf
[3],
1229 buf
[4], buf
[5], buf
[6], buf
[7],
1230 buf
[8], buf
[9], buf
[10], buf
[11],
1231 buf
[12], buf
[13], buf
[14], buf
[15],
1232 buf
[16], buf
[17], buf
[18], buf
[19],
1233 buf
[20], buf
[21], buf
[22], buf
[23],
1234 buf
[24], buf
[25], buf
[26], buf
[27],
1235 buf
[28], buf
[29], buf
[30], buf
[31],
1236 buf
[32], buf
[33], buf
[34], buf
[35],
1237 buf
[36], buf
[37], buf
[38], buf
[39],
1238 buf
[40], buf
[41], buf
[42], buf
[43],
1239 buf
[44], buf
[45], buf
[46], buf
[47],
1240 buf
[48], buf
[49], buf
[50], buf
[51],
1241 buf
[52], buf
[53], buf
[54], buf
[55],
1242 buf
[56], buf
[57], buf
[58], buf
[59],
1243 buf
[60], buf
[61], buf
[62], buf
[63]);
1247 fbtft_par_dbg(DEBUG_INIT_DISPLAY
, par
,
1248 "init: mdelay(%d)\n", par
->init_sequence
[i
]);
1249 mdelay(par
->init_sequence
[i
++]);
1252 dev_err(par
->info
->device
,
1253 "unknown delimiter %d at position %d\n",
1254 par
->init_sequence
[i
], i
);
1259 dev_err(par
->info
->device
,
1260 "%s: something is wrong. Shouldn't get here.\n", __func__
);
1263 EXPORT_SYMBOL(fbtft_init_display
);
1266 * fbtft_verify_gpios() - Generic verify_gpios() function
1269 * Uses @spi, @pdev and @buswidth to determine which GPIOs is needed
1271 * Return: 0 if successful, negative if error
1273 static int fbtft_verify_gpios(struct fbtft_par
*par
)
1275 struct fbtft_platform_data
*pdata
;
1278 fbtft_par_dbg(DEBUG_VERIFY_GPIOS
, par
, "%s()\n", __func__
);
1280 pdata
= par
->info
->device
->platform_data
;
1281 if (pdata
->display
.buswidth
!= 9 && par
->startbyte
== 0 && \
1283 dev_err(par
->info
->device
,
1284 "Missing info about 'dc' gpio. Aborting.\n");
1291 if (par
->gpio
.wr
< 0) {
1292 dev_err(par
->info
->device
, "Missing 'wr' gpio. Aborting.\n");
1295 for (i
= 0; i
< pdata
->display
.buswidth
; i
++) {
1296 if (par
->gpio
.db
[i
] < 0) {
1297 dev_err(par
->info
->device
,
1298 "Missing 'db%02d' gpio. Aborting.\n", i
);
1307 /* returns 0 if the property is not present */
1308 static u32
fbtft_of_value(struct device_node
*node
, const char *propname
)
1313 ret
= of_property_read_u32(node
, propname
, &val
);
1315 pr_info("%s: %s = %u\n", __func__
, propname
, val
);
1320 static struct fbtft_platform_data
*fbtft_probe_dt(struct device
*dev
)
1322 struct device_node
*node
= dev
->of_node
;
1323 struct fbtft_platform_data
*pdata
;
1326 dev_err(dev
, "Missing platform data or DT\n");
1327 return ERR_PTR(-EINVAL
);
1330 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
1332 return ERR_PTR(-ENOMEM
);
1334 pdata
->display
.width
= fbtft_of_value(node
, "width");
1335 pdata
->display
.height
= fbtft_of_value(node
, "height");
1336 pdata
->display
.regwidth
= fbtft_of_value(node
, "regwidth");
1337 pdata
->display
.buswidth
= fbtft_of_value(node
, "buswidth");
1338 pdata
->display
.backlight
= fbtft_of_value(node
, "backlight");
1339 pdata
->display
.bpp
= fbtft_of_value(node
, "bpp");
1340 pdata
->display
.debug
= fbtft_of_value(node
, "debug");
1341 pdata
->rotate
= fbtft_of_value(node
, "rotate");
1342 pdata
->bgr
= of_property_read_bool(node
, "bgr");
1343 pdata
->fps
= fbtft_of_value(node
, "fps");
1344 pdata
->txbuflen
= fbtft_of_value(node
, "txbuflen");
1345 pdata
->startbyte
= fbtft_of_value(node
, "startbyte");
1346 of_property_read_string(node
, "gamma", (const char **)&pdata
->gamma
);
1348 if (of_find_property(node
, "led-gpios", NULL
))
1349 pdata
->display
.backlight
= 1;
1350 if (of_find_property(node
, "init", NULL
))
1351 pdata
->display
.fbtftops
.init_display
= fbtft_init_display_dt
;
1352 pdata
->display
.fbtftops
.request_gpios
= fbtft_request_gpios_dt
;
1357 static struct fbtft_platform_data
*fbtft_probe_dt(struct device
*dev
)
1359 dev_err(dev
, "Missing platform data\n");
1360 return ERR_PTR(-EINVAL
);
1365 * fbtft_probe_common() - Generic device probe() helper function
1366 * @display: Display properties
1368 * @pdev: Platform device
1370 * Allocates, initializes and registers a framebuffer
1372 * Either @sdev or @pdev should be NULL
1374 * Return: 0 if successful, negative if error
1376 int fbtft_probe_common(struct fbtft_display
*display
,
1377 struct spi_device
*sdev
, struct platform_device
*pdev
)
1380 struct fb_info
*info
;
1381 struct fbtft_par
*par
;
1382 struct fbtft_platform_data
*pdata
;
1390 if (unlikely(display
->debug
& DEBUG_DRIVER_INIT_FUNCTIONS
))
1391 dev_info(dev
, "%s()\n", __func__
);
1393 pdata
= dev
->platform_data
;
1395 pdata
= fbtft_probe_dt(dev
);
1397 return PTR_ERR(pdata
);
1398 dev
->platform_data
= pdata
;
1401 info
= fbtft_framebuffer_alloc(display
, dev
);
1409 if (display
->buswidth
== 0) {
1410 dev_err(dev
, "buswidth is not set\n");
1414 /* write register functions */
1415 if (display
->regwidth
== 8 && display
->buswidth
== 8) {
1416 par
->fbtftops
.write_register
= fbtft_write_reg8_bus8
;
1418 if (display
->regwidth
== 8 && display
->buswidth
== 9 && par
->spi
) {
1419 par
->fbtftops
.write_register
= fbtft_write_reg8_bus9
;
1420 } else if (display
->regwidth
== 16 && display
->buswidth
== 8) {
1421 par
->fbtftops
.write_register
= fbtft_write_reg16_bus8
;
1422 } else if (display
->regwidth
== 16 && display
->buswidth
== 16) {
1423 par
->fbtftops
.write_register
= fbtft_write_reg16_bus16
;
1426 "no default functions for regwidth=%d and buswidth=%d\n",
1427 display
->regwidth
, display
->buswidth
);
1430 /* write_vmem() functions */
1431 if (display
->buswidth
== 8)
1432 par
->fbtftops
.write_vmem
= fbtft_write_vmem16_bus8
;
1433 else if (display
->buswidth
== 9)
1434 par
->fbtftops
.write_vmem
= fbtft_write_vmem16_bus9
;
1435 else if (display
->buswidth
== 16)
1436 par
->fbtftops
.write_vmem
= fbtft_write_vmem16_bus16
;
1438 /* GPIO write() functions */
1440 if (display
->buswidth
== 8)
1441 par
->fbtftops
.write
= fbtft_write_gpio8_wr
;
1442 else if (display
->buswidth
== 16)
1443 par
->fbtftops
.write
= fbtft_write_gpio16_wr
;
1446 /* 9-bit SPI setup */
1447 if (par
->spi
&& display
->buswidth
== 9) {
1448 par
->spi
->bits_per_word
= 9;
1449 ret
= par
->spi
->master
->setup(par
->spi
);
1451 dev_warn(&par
->spi
->dev
,
1452 "9-bit SPI not available, emulating using 8-bit.\n");
1453 par
->spi
->bits_per_word
= 8;
1454 ret
= par
->spi
->master
->setup(par
->spi
);
1457 /* allocate buffer with room for dc bits */
1458 par
->extra
= devm_kzalloc(par
->info
->device
,
1459 par
->txbuf
.len
+ (par
->txbuf
.len
/ 8) + 8,
1465 par
->fbtftops
.write
= fbtft_write_spi_emulate_9
;
1469 if (!par
->fbtftops
.verify_gpios
)
1470 par
->fbtftops
.verify_gpios
= fbtft_verify_gpios
;
1472 /* make sure we still use the driver provided functions */
1473 fbtft_merge_fbtftops(&par
->fbtftops
, &display
->fbtftops
);
1475 /* use init_sequence if provided */
1476 if (par
->init_sequence
)
1477 par
->fbtftops
.init_display
= fbtft_init_display
;
1479 /* use platform_data provided functions above all */
1480 fbtft_merge_fbtftops(&par
->fbtftops
, &pdata
->display
.fbtftops
);
1482 ret
= fbtft_register_framebuffer(info
);
1489 fbtft_framebuffer_release(info
);
1493 EXPORT_SYMBOL(fbtft_probe_common
);
1496 * fbtft_remove_common() - Generic device remove() helper function
1498 * @info: Framebuffer
1500 * Unregisters and releases the framebuffer
1502 * Return: 0 if successful, negative if error
1504 int fbtft_remove_common(struct device
*dev
, struct fb_info
*info
)
1506 struct fbtft_par
*par
;
1512 fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS
, par
,
1513 "%s()\n", __func__
);
1514 fbtft_unregister_framebuffer(info
);
1515 fbtft_framebuffer_release(info
);
1519 EXPORT_SYMBOL(fbtft_remove_common
);
1521 MODULE_LICENSE("GPL");