2 * Common code for AUO-K190X framebuffer drivers
4 * Copyright (C) 2012 Heiko Stuebner <heiko@sntech.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/module.h>
12 #include <linux/sched/mm.h>
13 #include <linux/kernel.h>
14 #include <linux/gpio.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_runtime.h>
18 #include <linux/delay.h>
19 #include <linux/uaccess.h>
20 #include <linux/vmalloc.h>
21 #include <linux/regulator/consumer.h>
23 #include <video/auo_k190xfb.h>
25 #include "auo_k190x.h"
32 /* table of panel specific parameters to be indexed into by the board drivers */
33 static struct panel_info panel_table
[] = {
35 [AUOK190X_RESOLUTION_800_600
] = {
40 [AUOK190X_RESOLUTION_1024_768
] = {
44 [AUOK190X_RESOLUTION_600_800
] = {
48 [AUOK190X_RESOLUTION_768_1024
] = {
55 * private I80 interface to the board driver
58 static void auok190x_issue_data(struct auok190xfb_par
*par
, u16 data
)
60 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 0);
61 par
->board
->set_hdb(par
, data
);
62 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 1);
65 static void auok190x_issue_cmd(struct auok190xfb_par
*par
, u16 data
)
67 par
->board
->set_ctl(par
, AUOK190X_I80_DC
, 0);
68 auok190x_issue_data(par
, data
);
69 par
->board
->set_ctl(par
, AUOK190X_I80_DC
, 1);
73 * Conversion of 16bit color to 4bit grayscale
74 * does roughly (0.3 * R + 0.6 G + 0.1 B) / 2
76 static inline int rgb565_to_gray4(u16 data
, struct fb_var_screeninfo
*var
)
78 return ((((data
& 0xF800) >> var
->red
.offset
) * 77 +
79 ((data
& 0x07E0) >> (var
->green
.offset
+ 1)) * 151 +
80 ((data
& 0x1F) >> var
->blue
.offset
) * 28) >> 8 >> 1);
83 static int auok190x_issue_pixels_rgb565(struct auok190xfb_par
*par
, int size
,
86 struct fb_var_screeninfo
*var
= &par
->info
->var
;
87 struct device
*dev
= par
->info
->device
;
92 dev_err(dev
, "issue_pixels: size %d must be a multiple of 8\n",
97 for (i
= 0; i
< (size
>> 2); i
++) {
98 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 0);
100 tmp
= (rgb565_to_gray4(data
[4*i
], var
) & 0x000F);
101 tmp
|= (rgb565_to_gray4(data
[4*i
+1], var
) << 4) & 0x00F0;
102 tmp
|= (rgb565_to_gray4(data
[4*i
+2], var
) << 8) & 0x0F00;
103 tmp
|= (rgb565_to_gray4(data
[4*i
+3], var
) << 12) & 0xF000;
105 par
->board
->set_hdb(par
, tmp
);
106 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 1);
112 static int auok190x_issue_pixels_gray8(struct auok190xfb_par
*par
, int size
,
115 struct device
*dev
= par
->info
->device
;
120 dev_err(dev
, "issue_pixels: size %d must be a multiple of 4\n",
125 for (i
= 0; i
< (size
>> 1); i
++) {
126 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 0);
128 /* simple reduction of 8bit staticgray to 4bit gray
129 * combines 4 * 4bit pixel values into a 16bit value
131 tmp
= (data
[2*i
] & 0xF0) >> 4;
132 tmp
|= (data
[2*i
] & 0xF000) >> 8;
133 tmp
|= (data
[2*i
+1] & 0xF0) << 4;
134 tmp
|= (data
[2*i
+1] & 0xF000);
136 par
->board
->set_hdb(par
, tmp
);
137 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 1);
143 static int auok190x_issue_pixels(struct auok190xfb_par
*par
, int size
,
146 struct fb_info
*info
= par
->info
;
147 struct device
*dev
= par
->info
->device
;
149 if (info
->var
.bits_per_pixel
== 8 && info
->var
.grayscale
)
150 auok190x_issue_pixels_gray8(par
, size
, data
);
151 else if (info
->var
.bits_per_pixel
== 16)
152 auok190x_issue_pixels_rgb565(par
, size
, data
);
154 dev_err(dev
, "unsupported color mode (bits: %d, gray: %d)\n",
155 info
->var
.bits_per_pixel
, info
->var
.grayscale
);
160 static u16
auok190x_read_data(struct auok190xfb_par
*par
)
164 par
->board
->set_ctl(par
, AUOK190X_I80_OE
, 0);
165 data
= par
->board
->get_hdb(par
);
166 par
->board
->set_ctl(par
, AUOK190X_I80_OE
, 1);
172 * Command interface for the controller drivers
175 void auok190x_send_command_nowait(struct auok190xfb_par
*par
, u16 data
)
177 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
178 auok190x_issue_cmd(par
, data
);
179 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
181 EXPORT_SYMBOL_GPL(auok190x_send_command_nowait
);
183 void auok190x_send_cmdargs_nowait(struct auok190xfb_par
*par
, u16 cmd
,
188 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
189 auok190x_issue_cmd(par
, cmd
);
191 for (i
= 0; i
< argc
; i
++)
192 auok190x_issue_data(par
, argv
[i
]);
193 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
195 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_nowait
);
197 int auok190x_send_command(struct auok190xfb_par
*par
, u16 data
)
201 ret
= par
->board
->wait_for_rdy(par
);
205 auok190x_send_command_nowait(par
, data
);
208 EXPORT_SYMBOL_GPL(auok190x_send_command
);
210 int auok190x_send_cmdargs(struct auok190xfb_par
*par
, u16 cmd
,
215 ret
= par
->board
->wait_for_rdy(par
);
219 auok190x_send_cmdargs_nowait(par
, cmd
, argc
, argv
);
222 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs
);
224 int auok190x_read_cmdargs(struct auok190xfb_par
*par
, u16 cmd
,
229 ret
= par
->board
->wait_for_rdy(par
);
233 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
234 auok190x_issue_cmd(par
, cmd
);
236 for (i
= 0; i
< argc
; i
++)
237 argv
[i
] = auok190x_read_data(par
);
238 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
242 EXPORT_SYMBOL_GPL(auok190x_read_cmdargs
);
244 void auok190x_send_cmdargs_pixels_nowait(struct auok190xfb_par
*par
, u16 cmd
,
245 int argc
, u16
*argv
, int size
, u16
*data
)
249 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
251 auok190x_issue_cmd(par
, cmd
);
253 for (i
= 0; i
< argc
; i
++)
254 auok190x_issue_data(par
, argv
[i
]);
256 auok190x_issue_pixels(par
, size
, data
);
258 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
260 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels_nowait
);
262 int auok190x_send_cmdargs_pixels(struct auok190xfb_par
*par
, u16 cmd
,
263 int argc
, u16
*argv
, int size
, u16
*data
)
267 ret
= par
->board
->wait_for_rdy(par
);
271 auok190x_send_cmdargs_pixels_nowait(par
, cmd
, argc
, argv
, size
, data
);
275 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels
);
278 * fbdefio callbacks - common on both controllers.
281 static void auok190xfb_dpy_first_io(struct fb_info
*info
)
283 /* tell runtime-pm that we wish to use the device in a short time */
284 pm_runtime_get(info
->device
);
287 /* this is called back from the deferred io workqueue */
288 static void auok190xfb_dpy_deferred_io(struct fb_info
*info
,
289 struct list_head
*pagelist
)
291 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
292 struct auok190xfb_par
*par
= info
->par
;
293 u16 line_length
= info
->fix
.line_length
;
294 u16 yres
= info
->var
.yres
;
301 if (!list_empty(pagelist
))
302 /* the device resume should've been requested through first_io,
303 * if the resume did not finish until now, wait for it.
305 pm_runtime_barrier(info
->device
);
307 /* We reached this via the fsync or some other way.
308 * In either case the first_io function did not run,
309 * so we runtime_resume the device here synchronously.
311 pm_runtime_get_sync(info
->device
);
313 /* Do a full screen update every n updates to prevent
314 * excessive darkening of the Sipix display.
315 * If we do this, there is no need to walk the pages.
317 if (par
->need_refresh(par
)) {
318 par
->update_all(par
);
322 /* height increment is fixed per page */
323 h_inc
= DIV_ROUND_UP(PAGE_SIZE
, line_length
);
325 /* calculate number of pages from pixel height */
326 threshold
= par
->consecutive_threshold
/ h_inc
;
330 /* walk the written page list and swizzle the data */
331 list_for_each_entry(cur
, &fbdefio
->pagelist
, lru
) {
332 if (prev_index
< 0) {
333 /* just starting so assign first page */
334 y1
= (cur
->index
<< PAGE_SHIFT
) / line_length
;
336 } else if ((cur
->index
- prev_index
) <= threshold
) {
337 /* page is within our threshold for single updates */
338 h
+= h_inc
* (cur
->index
- prev_index
);
340 /* page not consecutive, issue previous update first */
341 par
->update_partial(par
, y1
, y1
+ h
);
343 /* start over with our non consecutive page */
344 y1
= (cur
->index
<< PAGE_SHIFT
) / line_length
;
347 prev_index
= cur
->index
;
350 /* if we still have any pages to update we do so now */
352 /* its a full screen update, just do it */
353 par
->update_all(par
);
355 par
->update_partial(par
, y1
, min((u16
) (y1
+ h
), yres
));
358 pm_runtime_mark_last_busy(info
->device
);
359 pm_runtime_put_autosuspend(info
->device
);
363 * framebuffer operations
367 * this is the slow path from userspace. they can seek and write to
368 * the fb. it's inefficient to do anything less than a full screen draw
370 static ssize_t
auok190xfb_write(struct fb_info
*info
, const char __user
*buf
,
371 size_t count
, loff_t
*ppos
)
373 struct auok190xfb_par
*par
= info
->par
;
374 unsigned long p
= *ppos
;
377 unsigned long total_size
;
379 if (info
->state
!= FBINFO_STATE_RUNNING
)
382 total_size
= info
->fix
.smem_len
;
387 if (count
> total_size
) {
392 if (count
+ p
> total_size
) {
396 count
= total_size
- p
;
399 dst
= (void *)(info
->screen_base
+ p
);
401 if (copy_from_user(dst
, buf
, count
))
407 par
->update_all(par
);
409 return (err
) ? err
: count
;
412 static void auok190xfb_fillrect(struct fb_info
*info
,
413 const struct fb_fillrect
*rect
)
415 struct auok190xfb_par
*par
= info
->par
;
417 sys_fillrect(info
, rect
);
419 par
->update_all(par
);
422 static void auok190xfb_copyarea(struct fb_info
*info
,
423 const struct fb_copyarea
*area
)
425 struct auok190xfb_par
*par
= info
->par
;
427 sys_copyarea(info
, area
);
429 par
->update_all(par
);
432 static void auok190xfb_imageblit(struct fb_info
*info
,
433 const struct fb_image
*image
)
435 struct auok190xfb_par
*par
= info
->par
;
437 sys_imageblit(info
, image
);
439 par
->update_all(par
);
442 static int auok190xfb_check_var(struct fb_var_screeninfo
*var
,
443 struct fb_info
*info
)
445 struct device
*dev
= info
->device
;
446 struct auok190xfb_par
*par
= info
->par
;
447 struct panel_info
*panel
= &panel_table
[par
->resolution
];
454 if (var
->bits_per_pixel
== 8 && var
->grayscale
== 1) {
456 * For 8-bit grayscale, R, G, and B offset are equal.
460 var
->red
.msb_right
= 0;
462 var
->green
.length
= 8;
463 var
->green
.offset
= 0;
464 var
->green
.msb_right
= 0;
466 var
->blue
.length
= 8;
467 var
->blue
.offset
= 0;
468 var
->blue
.msb_right
= 0;
470 var
->transp
.length
= 0;
471 var
->transp
.offset
= 0;
472 var
->transp
.msb_right
= 0;
473 } else if (var
->bits_per_pixel
== 16) {
475 var
->red
.offset
= 11;
476 var
->red
.msb_right
= 0;
478 var
->green
.length
= 6;
479 var
->green
.offset
= 5;
480 var
->green
.msb_right
= 0;
482 var
->blue
.length
= 5;
483 var
->blue
.offset
= 0;
484 var
->blue
.msb_right
= 0;
486 var
->transp
.length
= 0;
487 var
->transp
.offset
= 0;
488 var
->transp
.msb_right
= 0;
490 dev_warn(dev
, "unsupported color mode (bits: %d, grayscale: %d)\n",
491 info
->var
.bits_per_pixel
, info
->var
.grayscale
);
499 switch (var
->rotate
) {
502 var
->xres
= panel
->w
;
503 var
->yres
= panel
->h
;
507 var
->xres
= panel
->h
;
508 var
->yres
= panel
->w
;
511 dev_dbg(dev
, "Invalid rotation request\n");
515 var
->xres_virtual
= var
->xres
;
516 var
->yres_virtual
= var
->yres
;
522 size
= var
->xres_virtual
* var
->yres_virtual
* var
->bits_per_pixel
/ 8;
523 if (size
> info
->fix
.smem_len
) {
524 dev_err(dev
, "Memory limit exceeded, requested %dK\n",
532 static int auok190xfb_set_fix(struct fb_info
*info
)
534 struct fb_fix_screeninfo
*fix
= &info
->fix
;
535 struct fb_var_screeninfo
*var
= &info
->var
;
537 fix
->line_length
= var
->xres_virtual
* var
->bits_per_pixel
/ 8;
539 fix
->type
= FB_TYPE_PACKED_PIXELS
;
540 fix
->accel
= FB_ACCEL_NONE
;
541 fix
->visual
= (var
->grayscale
) ? FB_VISUAL_STATIC_PSEUDOCOLOR
542 : FB_VISUAL_TRUECOLOR
;
550 static int auok190xfb_set_par(struct fb_info
*info
)
552 struct auok190xfb_par
*par
= info
->par
;
554 par
->rotation
= info
->var
.rotate
;
555 auok190xfb_set_fix(info
);
557 /* reinit the controller to honor the rotation */
560 /* wait for init to complete */
561 par
->board
->wait_for_rdy(par
);
566 static struct fb_ops auok190xfb_ops
= {
567 .owner
= THIS_MODULE
,
568 .fb_read
= fb_sys_read
,
569 .fb_write
= auok190xfb_write
,
570 .fb_fillrect
= auok190xfb_fillrect
,
571 .fb_copyarea
= auok190xfb_copyarea
,
572 .fb_imageblit
= auok190xfb_imageblit
,
573 .fb_check_var
= auok190xfb_check_var
,
574 .fb_set_par
= auok190xfb_set_par
,
578 * Controller-functions common to both K1900 and K1901
581 static int auok190x_read_temperature(struct auok190xfb_par
*par
)
583 struct device
*dev
= par
->info
->device
;
587 pm_runtime_get_sync(dev
);
589 mutex_lock(&(par
->io_lock
));
591 auok190x_read_cmdargs(par
, AUOK190X_CMD_READ_VERSION
, 4, data
);
593 mutex_unlock(&(par
->io_lock
));
595 pm_runtime_mark_last_busy(dev
);
596 pm_runtime_put_autosuspend(dev
);
598 /* sanitize and split of half-degrees for now */
599 temp
= ((data
[0] & AUOK190X_VERSION_TEMP_MASK
) >> 1);
601 /* handle positive and negative temperatures */
603 return (255 - temp
+ 1) * (-1);
608 static void auok190x_identify(struct auok190xfb_par
*par
)
610 struct device
*dev
= par
->info
->device
;
613 pm_runtime_get_sync(dev
);
615 mutex_lock(&(par
->io_lock
));
617 auok190x_read_cmdargs(par
, AUOK190X_CMD_READ_VERSION
, 4, data
);
619 mutex_unlock(&(par
->io_lock
));
621 par
->epd_type
= data
[1] & AUOK190X_VERSION_TEMP_MASK
;
623 par
->panel_size_int
= AUOK190X_VERSION_SIZE_INT(data
[2]);
624 par
->panel_size_float
= AUOK190X_VERSION_SIZE_FLOAT(data
[2]);
625 par
->panel_model
= AUOK190X_VERSION_MODEL(data
[2]);
627 par
->tcon_version
= AUOK190X_VERSION_TCON(data
[3]);
628 par
->lut_version
= AUOK190X_VERSION_LUT(data
[3]);
630 dev_dbg(dev
, "panel %d.%din, model 0x%x, EPD 0x%x TCON-rev 0x%x, LUT-rev 0x%x",
631 par
->panel_size_int
, par
->panel_size_float
, par
->panel_model
,
632 par
->epd_type
, par
->tcon_version
, par
->lut_version
);
634 pm_runtime_mark_last_busy(dev
);
635 pm_runtime_put_autosuspend(dev
);
642 static ssize_t
update_mode_show(struct device
*dev
,
643 struct device_attribute
*attr
, char *buf
)
645 struct fb_info
*info
= dev_get_drvdata(dev
);
646 struct auok190xfb_par
*par
= info
->par
;
648 return sprintf(buf
, "%d\n", par
->update_mode
);
651 static ssize_t
update_mode_store(struct device
*dev
,
652 struct device_attribute
*attr
,
653 const char *buf
, size_t count
)
655 struct fb_info
*info
= dev_get_drvdata(dev
);
656 struct auok190xfb_par
*par
= info
->par
;
659 ret
= kstrtoint(buf
, 10, &mode
);
663 par
->update_mode
= mode
;
665 /* if we enter a better mode, do a full update */
666 if (par
->last_mode
> 1 && mode
< par
->last_mode
)
667 par
->update_all(par
);
672 static ssize_t
flash_show(struct device
*dev
, struct device_attribute
*attr
,
675 struct fb_info
*info
= dev_get_drvdata(dev
);
676 struct auok190xfb_par
*par
= info
->par
;
678 return sprintf(buf
, "%d\n", par
->flash
);
681 static ssize_t
flash_store(struct device
*dev
, struct device_attribute
*attr
,
682 const char *buf
, size_t count
)
684 struct fb_info
*info
= dev_get_drvdata(dev
);
685 struct auok190xfb_par
*par
= info
->par
;
688 ret
= kstrtoint(buf
, 10, &flash
);
700 static ssize_t
temp_show(struct device
*dev
, struct device_attribute
*attr
,
703 struct fb_info
*info
= dev_get_drvdata(dev
);
704 struct auok190xfb_par
*par
= info
->par
;
707 temp
= auok190x_read_temperature(par
);
708 return sprintf(buf
, "%d\n", temp
);
711 static DEVICE_ATTR_RW(update_mode
);
712 static DEVICE_ATTR_RW(flash
);
713 static DEVICE_ATTR(temp
, 0644, temp_show
, NULL
);
715 static struct attribute
*auok190x_attributes
[] = {
716 &dev_attr_update_mode
.attr
,
717 &dev_attr_flash
.attr
,
722 static const struct attribute_group auok190x_attr_group
= {
723 .attrs
= auok190x_attributes
,
726 static int auok190x_power(struct auok190xfb_par
*par
, bool on
)
728 struct auok190x_board
*board
= par
->board
;
732 /* We should maintain POWER up for at least 80ms before set
733 * RST_N and SLP_N to high (TCON spec 20100803_v35 p59)
735 ret
= regulator_enable(par
->regulator
);
740 gpio_set_value(board
->gpio_nrst
, 1);
741 gpio_set_value(board
->gpio_nsleep
, 1);
744 regulator_disable(par
->regulator
);
745 gpio_set_value(board
->gpio_nrst
, 0);
746 gpio_set_value(board
->gpio_nsleep
, 0);
753 * Recovery - powercycle the controller
756 static void auok190x_recover(struct auok190xfb_par
*par
)
758 struct device
*dev
= par
->info
->device
;
760 auok190x_power(par
, 0);
762 auok190x_power(par
, 1);
764 /* after powercycling the device, it's always active */
765 pm_runtime_set_active(dev
);
770 /* wait for init to complete */
771 par
->board
->wait_for_rdy(par
);
777 static int __maybe_unused
auok190x_runtime_suspend(struct device
*dev
)
779 struct platform_device
*pdev
= to_platform_device(dev
);
780 struct fb_info
*info
= platform_get_drvdata(pdev
);
781 struct auok190xfb_par
*par
= info
->par
;
782 struct auok190x_board
*board
= par
->board
;
785 /* take and keep the lock until we are resumed, as the controller
786 * will never reach the non-busy state when in standby mode
788 mutex_lock(&(par
->io_lock
));
791 dev_warn(dev
, "already in standby, runtime-pm pairing mismatch\n");
792 mutex_unlock(&(par
->io_lock
));
796 /* according to runtime_pm.txt runtime_suspend only means, that the
797 * device will not process data and will not communicate with the CPU
798 * As we hold the lock, this stays true even without standby
800 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
801 dev_dbg(dev
, "runtime suspend without standby\n");
803 } else if (board
->quirks
& AUOK190X_QUIRK_STANDBYPARAM
) {
804 /* for some TCON versions STANDBY expects a parameter (0) but
805 * it seems the real tcon version has to be determined yet.
807 dev_dbg(dev
, "runtime suspend with additional empty param\n");
809 auok190x_send_cmdargs(par
, AUOK190X_CMD_STANDBY
, 1,
812 dev_dbg(dev
, "runtime suspend without param\n");
813 auok190x_send_command(par
, AUOK190X_CMD_STANDBY
);
824 static int __maybe_unused
auok190x_runtime_resume(struct device
*dev
)
826 struct platform_device
*pdev
= to_platform_device(dev
);
827 struct fb_info
*info
= platform_get_drvdata(pdev
);
828 struct auok190xfb_par
*par
= info
->par
;
829 struct auok190x_board
*board
= par
->board
;
832 dev_warn(dev
, "not in standby, runtime-pm pairing mismatch\n");
836 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
837 dev_dbg(dev
, "runtime resume without standby\n");
839 /* when in standby, controller is always busy
840 * and only accepts the wakeup command
842 dev_dbg(dev
, "runtime resume from standby\n");
843 auok190x_send_command_nowait(par
, AUOK190X_CMD_WAKEUP
);
847 /* wait for the controller to be ready and release the lock */
848 board
->wait_for_rdy(par
);
853 mutex_unlock(&(par
->io_lock
));
858 static int __maybe_unused
auok190x_suspend(struct device
*dev
)
860 struct platform_device
*pdev
= to_platform_device(dev
);
861 struct fb_info
*info
= platform_get_drvdata(pdev
);
862 struct auok190xfb_par
*par
= info
->par
;
863 struct auok190x_board
*board
= par
->board
;
866 dev_dbg(dev
, "suspend\n");
867 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
868 /* suspend via powering off the ic */
869 dev_dbg(dev
, "suspend with broken standby\n");
871 auok190x_power(par
, 0);
873 dev_dbg(dev
, "suspend using sleep\n");
875 /* the sleep state can only be entered from the standby state.
876 * pm_runtime_get_noresume gets called before the suspend call.
877 * So the devices usage count is >0 but it is not necessarily
880 if (!pm_runtime_status_suspended(dev
)) {
881 ret
= auok190x_runtime_suspend(dev
);
883 dev_err(dev
, "auok190x_runtime_suspend failed with %d\n",
887 par
->manual_standby
= 1;
890 gpio_direction_output(board
->gpio_nsleep
, 0);
898 static int __maybe_unused
auok190x_resume(struct device
*dev
)
900 struct platform_device
*pdev
= to_platform_device(dev
);
901 struct fb_info
*info
= platform_get_drvdata(pdev
);
902 struct auok190xfb_par
*par
= info
->par
;
903 struct auok190x_board
*board
= par
->board
;
905 dev_dbg(dev
, "resume\n");
906 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
907 dev_dbg(dev
, "resume with broken standby\n");
909 auok190x_power(par
, 1);
913 dev_dbg(dev
, "resume from sleep\n");
915 /* device should be in runtime suspend when we were suspended
916 * and pm_runtime_put_sync gets called after this function.
917 * So there is no need to touch the standby mode here at all.
919 gpio_direction_output(board
->gpio_nsleep
, 1);
922 /* an additional init call seems to be necessary after sleep */
923 auok190x_runtime_resume(dev
);
926 /* if we were runtime-suspended before, suspend again*/
927 if (!par
->manual_standby
)
928 auok190x_runtime_suspend(dev
);
930 par
->manual_standby
= 0;
936 const struct dev_pm_ops auok190x_pm
= {
937 SET_RUNTIME_PM_OPS(auok190x_runtime_suspend
, auok190x_runtime_resume
,
939 SET_SYSTEM_SLEEP_PM_OPS(auok190x_suspend
, auok190x_resume
)
941 EXPORT_SYMBOL_GPL(auok190x_pm
);
944 * Common probe and remove code
947 int auok190x_common_probe(struct platform_device
*pdev
,
948 struct auok190x_init_data
*init
)
950 struct auok190x_board
*board
= init
->board
;
951 struct auok190xfb_par
*par
;
952 struct fb_info
*info
;
953 struct panel_info
*panel
;
954 int videomemorysize
, ret
;
955 unsigned char *videomemory
;
957 /* check board contents */
958 if (!board
->init
|| !board
->cleanup
|| !board
->wait_for_rdy
959 || !board
->set_ctl
|| !board
->set_hdb
|| !board
->get_hdb
960 || !board
->setup_irq
)
963 info
= framebuffer_alloc(sizeof(struct auok190xfb_par
), &pdev
->dev
);
970 par
->recover
= auok190x_recover
;
971 par
->update_partial
= init
->update_partial
;
972 par
->update_all
= init
->update_all
;
973 par
->need_refresh
= init
->need_refresh
;
974 par
->init
= init
->init
;
976 /* init update modes */
978 par
->update_mode
= -1;
982 par
->regulator
= regulator_get(info
->device
, "vdd");
983 if (IS_ERR(par
->regulator
)) {
984 ret
= PTR_ERR(par
->regulator
);
985 dev_err(info
->device
, "Failed to get regulator: %d\n", ret
);
989 ret
= board
->init(par
);
991 dev_err(info
->device
, "board init failed, %d\n", ret
);
995 ret
= gpio_request(board
->gpio_nsleep
, "AUOK190x sleep");
997 dev_err(info
->device
, "could not request sleep gpio, %d\n",
1002 ret
= gpio_direction_output(board
->gpio_nsleep
, 0);
1004 dev_err(info
->device
, "could not set sleep gpio, %d\n", ret
);
1008 ret
= gpio_request(board
->gpio_nrst
, "AUOK190x reset");
1010 dev_err(info
->device
, "could not request reset gpio, %d\n",
1015 ret
= gpio_direction_output(board
->gpio_nrst
, 0);
1017 dev_err(info
->device
, "could not set reset gpio, %d\n", ret
);
1021 ret
= auok190x_power(par
, 1);
1023 dev_err(info
->device
, "could not power on the device, %d\n",
1028 mutex_init(&par
->io_lock
);
1030 init_waitqueue_head(&par
->waitq
);
1032 ret
= par
->board
->setup_irq(par
->info
);
1034 dev_err(info
->device
, "could not setup ready-irq, %d\n", ret
);
1038 /* wait for init to complete */
1039 par
->board
->wait_for_rdy(par
);
1042 * From here on the controller can talk to us
1045 /* initialise fix, var, resolution and rotation */
1047 strlcpy(info
->fix
.id
, init
->id
, 16);
1048 info
->var
.bits_per_pixel
= 8;
1049 info
->var
.grayscale
= 1;
1051 panel
= &panel_table
[board
->resolution
];
1053 par
->resolution
= board
->resolution
;
1056 /* videomemory handling */
1058 videomemorysize
= roundup((panel
->w
* panel
->h
) * 2, PAGE_SIZE
);
1059 videomemory
= vzalloc(videomemorysize
);
1065 info
->screen_base
= (char *)videomemory
;
1066 info
->fix
.smem_len
= videomemorysize
;
1068 info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_VIRTFB
;
1069 info
->fbops
= &auok190xfb_ops
;
1071 ret
= auok190xfb_check_var(&info
->var
, info
);
1075 auok190xfb_set_fix(info
);
1077 /* deferred io init */
1079 info
->fbdefio
= devm_kzalloc(info
->device
,
1080 sizeof(struct fb_deferred_io
),
1082 if (!info
->fbdefio
) {
1083 dev_err(info
->device
, "Failed to allocate memory\n");
1088 dev_dbg(info
->device
, "targeting %d frames per second\n", board
->fps
);
1089 info
->fbdefio
->delay
= HZ
/ board
->fps
;
1090 info
->fbdefio
->first_io
= auok190xfb_dpy_first_io
,
1091 info
->fbdefio
->deferred_io
= auok190xfb_dpy_deferred_io
,
1092 fb_deferred_io_init(info
);
1096 ret
= fb_alloc_cmap(&info
->cmap
, 256, 0);
1098 dev_err(info
->device
, "Failed to allocate colormap\n");
1102 /* controller init */
1104 par
->consecutive_threshold
= 100;
1106 auok190x_identify(par
);
1108 platform_set_drvdata(pdev
, info
);
1110 ret
= register_framebuffer(info
);
1114 ret
= sysfs_create_group(&info
->device
->kobj
, &auok190x_attr_group
);
1118 dev_info(info
->device
, "fb%d: %dx%d using %dK of video memory\n",
1119 info
->node
, info
->var
.xres
, info
->var
.yres
,
1120 videomemorysize
>> 10);
1122 /* increase autosuspend_delay when we use alternative methods
1125 par
->autosuspend_delay
= (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
)
1128 pm_runtime_set_active(info
->device
);
1129 pm_runtime_enable(info
->device
);
1130 pm_runtime_set_autosuspend_delay(info
->device
, par
->autosuspend_delay
);
1131 pm_runtime_use_autosuspend(info
->device
);
1136 unregister_framebuffer(info
);
1138 fb_dealloc_cmap(&info
->cmap
);
1140 fb_deferred_io_cleanup(info
);
1142 vfree((void *)info
->screen_base
);
1144 auok190x_power(par
, 0);
1146 gpio_free(board
->gpio_nrst
);
1148 gpio_free(board
->gpio_nsleep
);
1150 board
->cleanup(par
);
1152 regulator_put(par
->regulator
);
1154 framebuffer_release(info
);
1158 EXPORT_SYMBOL_GPL(auok190x_common_probe
);
1160 int auok190x_common_remove(struct platform_device
*pdev
)
1162 struct fb_info
*info
= platform_get_drvdata(pdev
);
1163 struct auok190xfb_par
*par
= info
->par
;
1164 struct auok190x_board
*board
= par
->board
;
1166 pm_runtime_disable(info
->device
);
1168 sysfs_remove_group(&info
->device
->kobj
, &auok190x_attr_group
);
1170 unregister_framebuffer(info
);
1172 fb_dealloc_cmap(&info
->cmap
);
1174 fb_deferred_io_cleanup(info
);
1176 vfree((void *)info
->screen_base
);
1178 auok190x_power(par
, 0);
1180 gpio_free(board
->gpio_nrst
);
1181 gpio_free(board
->gpio_nsleep
);
1183 board
->cleanup(par
);
1185 regulator_put(par
->regulator
);
1187 framebuffer_release(info
);
1191 EXPORT_SYMBOL_GPL(auok190x_common_remove
);
1193 MODULE_DESCRIPTION("Common code for AUO-K190X controllers");
1194 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
1195 MODULE_LICENSE("GPL");