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/kernel.h>
13 #include <linux/gpio.h>
14 #include <linux/platform_device.h>
15 #include <linux/pm_runtime.h>
17 #include <linux/delay.h>
18 #include <linux/uaccess.h>
19 #include <linux/vmalloc.h>
20 #include <linux/regulator/consumer.h>
22 #include <video/auo_k190xfb.h>
24 #include "auo_k190x.h"
31 /* table of panel specific parameters to be indexed into by the board drivers */
32 static struct panel_info panel_table
[] = {
34 [AUOK190X_RESOLUTION_800_600
] = {
39 [AUOK190X_RESOLUTION_1024_768
] = {
46 * private I80 interface to the board driver
49 static void auok190x_issue_data(struct auok190xfb_par
*par
, u16 data
)
51 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 0);
52 par
->board
->set_hdb(par
, data
);
53 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 1);
56 static void auok190x_issue_cmd(struct auok190xfb_par
*par
, u16 data
)
58 par
->board
->set_ctl(par
, AUOK190X_I80_DC
, 0);
59 auok190x_issue_data(par
, data
);
60 par
->board
->set_ctl(par
, AUOK190X_I80_DC
, 1);
63 static int auok190x_issue_pixels(struct auok190xfb_par
*par
, int size
,
66 struct device
*dev
= par
->info
->device
;
71 dev_err(dev
, "issue_pixels: size %d must be a multiple of 4\n",
76 for (i
= 0; i
< (size
>> 1); i
++) {
77 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 0);
79 /* simple reduction of 8bit staticgray to 4bit gray
80 * combines 4 * 4bit pixel values into a 16bit value
82 tmp
= (data
[2*i
] & 0xF0) >> 4;
83 tmp
|= (data
[2*i
] & 0xF000) >> 8;
84 tmp
|= (data
[2*i
+1] & 0xF0) << 4;
85 tmp
|= (data
[2*i
+1] & 0xF000);
87 par
->board
->set_hdb(par
, tmp
);
88 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 1);
94 static u16
auok190x_read_data(struct auok190xfb_par
*par
)
98 par
->board
->set_ctl(par
, AUOK190X_I80_OE
, 0);
99 data
= par
->board
->get_hdb(par
);
100 par
->board
->set_ctl(par
, AUOK190X_I80_OE
, 1);
106 * Command interface for the controller drivers
109 void auok190x_send_command_nowait(struct auok190xfb_par
*par
, u16 data
)
111 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
112 auok190x_issue_cmd(par
, data
);
113 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
115 EXPORT_SYMBOL_GPL(auok190x_send_command_nowait
);
117 void auok190x_send_cmdargs_nowait(struct auok190xfb_par
*par
, u16 cmd
,
122 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
123 auok190x_issue_cmd(par
, cmd
);
125 for (i
= 0; i
< argc
; i
++)
126 auok190x_issue_data(par
, argv
[i
]);
127 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
129 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_nowait
);
131 int auok190x_send_command(struct auok190xfb_par
*par
, u16 data
)
135 ret
= par
->board
->wait_for_rdy(par
);
139 auok190x_send_command_nowait(par
, data
);
142 EXPORT_SYMBOL_GPL(auok190x_send_command
);
144 int auok190x_send_cmdargs(struct auok190xfb_par
*par
, u16 cmd
,
149 ret
= par
->board
->wait_for_rdy(par
);
153 auok190x_send_cmdargs_nowait(par
, cmd
, argc
, argv
);
156 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs
);
158 int auok190x_read_cmdargs(struct auok190xfb_par
*par
, u16 cmd
,
163 ret
= par
->board
->wait_for_rdy(par
);
167 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
168 auok190x_issue_cmd(par
, cmd
);
170 for (i
= 0; i
< argc
; i
++)
171 argv
[i
] = auok190x_read_data(par
);
172 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
176 EXPORT_SYMBOL_GPL(auok190x_read_cmdargs
);
178 void auok190x_send_cmdargs_pixels_nowait(struct auok190xfb_par
*par
, u16 cmd
,
179 int argc
, u16
*argv
, int size
, u16
*data
)
183 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
185 auok190x_issue_cmd(par
, cmd
);
187 for (i
= 0; i
< argc
; i
++)
188 auok190x_issue_data(par
, argv
[i
]);
190 auok190x_issue_pixels(par
, size
, data
);
192 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
194 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels_nowait
);
196 int auok190x_send_cmdargs_pixels(struct auok190xfb_par
*par
, u16 cmd
,
197 int argc
, u16
*argv
, int size
, u16
*data
)
201 ret
= par
->board
->wait_for_rdy(par
);
205 auok190x_send_cmdargs_pixels_nowait(par
, cmd
, argc
, argv
, size
, data
);
209 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels
);
212 * fbdefio callbacks - common on both controllers.
215 static void auok190xfb_dpy_first_io(struct fb_info
*info
)
217 /* tell runtime-pm that we wish to use the device in a short time */
218 pm_runtime_get(info
->device
);
221 /* this is called back from the deferred io workqueue */
222 static void auok190xfb_dpy_deferred_io(struct fb_info
*info
,
223 struct list_head
*pagelist
)
225 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
226 struct auok190xfb_par
*par
= info
->par
;
227 u16 line_length
= info
->fix
.line_length
;
228 u16 yres
= info
->var
.yres
;
235 if (!list_empty(pagelist
))
236 /* the device resume should've been requested through first_io,
237 * if the resume did not finish until now, wait for it.
239 pm_runtime_barrier(info
->device
);
241 /* We reached this via the fsync or some other way.
242 * In either case the first_io function did not run,
243 * so we runtime_resume the device here synchronously.
245 pm_runtime_get_sync(info
->device
);
247 /* Do a full screen update every n updates to prevent
248 * excessive darkening of the Sipix display.
249 * If we do this, there is no need to walk the pages.
251 if (par
->need_refresh(par
)) {
252 par
->update_all(par
);
256 /* height increment is fixed per page */
257 h_inc
= DIV_ROUND_UP(PAGE_SIZE
, line_length
);
259 /* calculate number of pages from pixel height */
260 threshold
= par
->consecutive_threshold
/ h_inc
;
264 /* walk the written page list and swizzle the data */
265 list_for_each_entry(cur
, &fbdefio
->pagelist
, lru
) {
266 if (prev_index
< 0) {
267 /* just starting so assign first page */
268 y1
= (cur
->index
<< PAGE_SHIFT
) / line_length
;
270 } else if ((cur
->index
- prev_index
) <= threshold
) {
271 /* page is within our threshold for single updates */
272 h
+= h_inc
* (cur
->index
- prev_index
);
274 /* page not consecutive, issue previous update first */
275 par
->update_partial(par
, y1
, y1
+ h
);
277 /* start over with our non consecutive page */
278 y1
= (cur
->index
<< PAGE_SHIFT
) / line_length
;
281 prev_index
= cur
->index
;
284 /* if we still have any pages to update we do so now */
286 /* its a full screen update, just do it */
287 par
->update_all(par
);
289 par
->update_partial(par
, y1
, min((u16
) (y1
+ h
), yres
));
292 pm_runtime_mark_last_busy(info
->device
);
293 pm_runtime_put_autosuspend(info
->device
);
297 * framebuffer operations
301 * this is the slow path from userspace. they can seek and write to
302 * the fb. it's inefficient to do anything less than a full screen draw
304 static ssize_t
auok190xfb_write(struct fb_info
*info
, const char __user
*buf
,
305 size_t count
, loff_t
*ppos
)
307 struct auok190xfb_par
*par
= info
->par
;
308 unsigned long p
= *ppos
;
311 unsigned long total_size
;
313 if (info
->state
!= FBINFO_STATE_RUNNING
)
316 total_size
= info
->fix
.smem_len
;
321 if (count
> total_size
) {
326 if (count
+ p
> total_size
) {
330 count
= total_size
- p
;
333 dst
= (void *)(info
->screen_base
+ p
);
335 if (copy_from_user(dst
, buf
, count
))
341 par
->update_all(par
);
343 return (err
) ? err
: count
;
346 static void auok190xfb_fillrect(struct fb_info
*info
,
347 const struct fb_fillrect
*rect
)
349 struct auok190xfb_par
*par
= info
->par
;
351 sys_fillrect(info
, rect
);
353 par
->update_all(par
);
356 static void auok190xfb_copyarea(struct fb_info
*info
,
357 const struct fb_copyarea
*area
)
359 struct auok190xfb_par
*par
= info
->par
;
361 sys_copyarea(info
, area
);
363 par
->update_all(par
);
366 static void auok190xfb_imageblit(struct fb_info
*info
,
367 const struct fb_image
*image
)
369 struct auok190xfb_par
*par
= info
->par
;
371 sys_imageblit(info
, image
);
373 par
->update_all(par
);
376 static int auok190xfb_check_var(struct fb_var_screeninfo
*var
,
377 struct fb_info
*info
)
379 struct device
*dev
= info
->device
;
382 if (info
->var
.xres
!= var
->xres
|| info
->var
.yres
!= var
->yres
||
383 info
->var
.xres_virtual
!= var
->xres_virtual
||
384 info
->var
.yres_virtual
!= var
->yres_virtual
) {
385 pr_info("%s: Resolution not supported: X%u x Y%u\n",
386 __func__
, var
->xres
, var
->yres
);
394 size
= var
->xres_virtual
* var
->yres_virtual
* var
->bits_per_pixel
/ 8;
395 if (size
> info
->fix
.smem_len
) {
396 dev_err(dev
, "Memory limit exceeded, requested %dK\n",
404 static struct fb_ops auok190xfb_ops
= {
405 .owner
= THIS_MODULE
,
406 .fb_read
= fb_sys_read
,
407 .fb_write
= auok190xfb_write
,
408 .fb_fillrect
= auok190xfb_fillrect
,
409 .fb_copyarea
= auok190xfb_copyarea
,
410 .fb_imageblit
= auok190xfb_imageblit
,
411 .fb_check_var
= auok190xfb_check_var
,
415 * Controller-functions common to both K1900 and K1901
418 static int auok190x_read_temperature(struct auok190xfb_par
*par
)
420 struct device
*dev
= par
->info
->device
;
424 pm_runtime_get_sync(dev
);
426 mutex_lock(&(par
->io_lock
));
428 auok190x_read_cmdargs(par
, AUOK190X_CMD_READ_VERSION
, 4, data
);
430 mutex_unlock(&(par
->io_lock
));
432 pm_runtime_mark_last_busy(dev
);
433 pm_runtime_put_autosuspend(dev
);
435 /* sanitize and split of half-degrees for now */
436 temp
= ((data
[0] & AUOK190X_VERSION_TEMP_MASK
) >> 1);
438 /* handle positive and negative temperatures */
440 return (255 - temp
+ 1) * (-1);
445 static void auok190x_identify(struct auok190xfb_par
*par
)
447 struct device
*dev
= par
->info
->device
;
450 pm_runtime_get_sync(dev
);
452 mutex_lock(&(par
->io_lock
));
454 auok190x_read_cmdargs(par
, AUOK190X_CMD_READ_VERSION
, 4, data
);
456 mutex_unlock(&(par
->io_lock
));
458 par
->epd_type
= data
[1] & AUOK190X_VERSION_TEMP_MASK
;
460 par
->panel_size_int
= AUOK190X_VERSION_SIZE_INT(data
[2]);
461 par
->panel_size_float
= AUOK190X_VERSION_SIZE_FLOAT(data
[2]);
462 par
->panel_model
= AUOK190X_VERSION_MODEL(data
[2]);
464 par
->tcon_version
= AUOK190X_VERSION_TCON(data
[3]);
465 par
->lut_version
= AUOK190X_VERSION_LUT(data
[3]);
467 dev_dbg(dev
, "panel %d.%din, model 0x%x, EPD 0x%x TCON-rev 0x%x, LUT-rev 0x%x",
468 par
->panel_size_int
, par
->panel_size_float
, par
->panel_model
,
469 par
->epd_type
, par
->tcon_version
, par
->lut_version
);
471 pm_runtime_mark_last_busy(dev
);
472 pm_runtime_put_autosuspend(dev
);
479 static ssize_t
update_mode_show(struct device
*dev
,
480 struct device_attribute
*attr
, char *buf
)
482 struct fb_info
*info
= dev_get_drvdata(dev
);
483 struct auok190xfb_par
*par
= info
->par
;
485 return sprintf(buf
, "%d\n", par
->update_mode
);
488 static ssize_t
update_mode_store(struct device
*dev
,
489 struct device_attribute
*attr
,
490 const char *buf
, size_t count
)
492 struct fb_info
*info
= dev_get_drvdata(dev
);
493 struct auok190xfb_par
*par
= info
->par
;
496 ret
= kstrtoint(buf
, 10, &mode
);
500 par
->update_mode
= mode
;
502 /* if we enter a better mode, do a full update */
503 if (par
->last_mode
> 1 && mode
< par
->last_mode
)
504 par
->update_all(par
);
509 static ssize_t
flash_show(struct device
*dev
, struct device_attribute
*attr
,
512 struct fb_info
*info
= dev_get_drvdata(dev
);
513 struct auok190xfb_par
*par
= info
->par
;
515 return sprintf(buf
, "%d\n", par
->flash
);
518 static ssize_t
flash_store(struct device
*dev
, struct device_attribute
*attr
,
519 const char *buf
, size_t count
)
521 struct fb_info
*info
= dev_get_drvdata(dev
);
522 struct auok190xfb_par
*par
= info
->par
;
525 ret
= kstrtoint(buf
, 10, &flash
);
537 static ssize_t
temp_show(struct device
*dev
, struct device_attribute
*attr
,
540 struct fb_info
*info
= dev_get_drvdata(dev
);
541 struct auok190xfb_par
*par
= info
->par
;
544 temp
= auok190x_read_temperature(par
);
545 return sprintf(buf
, "%d\n", temp
);
548 static DEVICE_ATTR(update_mode
, 0644, update_mode_show
, update_mode_store
);
549 static DEVICE_ATTR(flash
, 0644, flash_show
, flash_store
);
550 static DEVICE_ATTR(temp
, 0644, temp_show
, NULL
);
552 static struct attribute
*auok190x_attributes
[] = {
553 &dev_attr_update_mode
.attr
,
554 &dev_attr_flash
.attr
,
559 static const struct attribute_group auok190x_attr_group
= {
560 .attrs
= auok190x_attributes
,
563 static int auok190x_power(struct auok190xfb_par
*par
, bool on
)
565 struct auok190x_board
*board
= par
->board
;
569 /* We should maintain POWER up for at least 80ms before set
570 * RST_N and SLP_N to high (TCON spec 20100803_v35 p59)
572 ret
= regulator_enable(par
->regulator
);
577 gpio_set_value(board
->gpio_nrst
, 1);
578 gpio_set_value(board
->gpio_nsleep
, 1);
581 regulator_disable(par
->regulator
);
582 gpio_set_value(board
->gpio_nrst
, 0);
583 gpio_set_value(board
->gpio_nsleep
, 0);
590 * Recovery - powercycle the controller
593 static void auok190x_recover(struct auok190xfb_par
*par
)
595 struct device
*dev
= par
->info
->device
;
597 auok190x_power(par
, 0);
599 auok190x_power(par
, 1);
601 /* after powercycling the device, it's always active */
602 pm_runtime_set_active(dev
);
607 /* wait for init to complete */
608 par
->board
->wait_for_rdy(par
);
616 static int auok190x_runtime_suspend(struct device
*dev
)
618 struct platform_device
*pdev
= to_platform_device(dev
);
619 struct fb_info
*info
= platform_get_drvdata(pdev
);
620 struct auok190xfb_par
*par
= info
->par
;
621 struct auok190x_board
*board
= par
->board
;
624 /* take and keep the lock until we are resumed, as the controller
625 * will never reach the non-busy state when in standby mode
627 mutex_lock(&(par
->io_lock
));
630 dev_warn(dev
, "already in standby, runtime-pm pairing mismatch\n");
631 mutex_unlock(&(par
->io_lock
));
635 /* according to runtime_pm.txt runtime_suspend only means, that the
636 * device will not process data and will not communicate with the CPU
637 * As we hold the lock, this stays true even without standby
639 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
640 dev_dbg(dev
, "runtime suspend without standby\n");
642 } else if (board
->quirks
& AUOK190X_QUIRK_STANDBYPARAM
) {
643 /* for some TCON versions STANDBY expects a parameter (0) but
644 * it seems the real tcon version has to be determined yet.
646 dev_dbg(dev
, "runtime suspend with additional empty param\n");
648 auok190x_send_cmdargs(par
, AUOK190X_CMD_STANDBY
, 1,
651 dev_dbg(dev
, "runtime suspend without param\n");
652 auok190x_send_command(par
, AUOK190X_CMD_STANDBY
);
663 static int auok190x_runtime_resume(struct device
*dev
)
665 struct platform_device
*pdev
= to_platform_device(dev
);
666 struct fb_info
*info
= platform_get_drvdata(pdev
);
667 struct auok190xfb_par
*par
= info
->par
;
668 struct auok190x_board
*board
= par
->board
;
671 dev_warn(dev
, "not in standby, runtime-pm pairing mismatch\n");
675 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
676 dev_dbg(dev
, "runtime resume without standby\n");
678 /* when in standby, controller is always busy
679 * and only accepts the wakeup command
681 dev_dbg(dev
, "runtime resume from standby\n");
682 auok190x_send_command_nowait(par
, AUOK190X_CMD_WAKEUP
);
686 /* wait for the controller to be ready and release the lock */
687 board
->wait_for_rdy(par
);
692 mutex_unlock(&(par
->io_lock
));
697 static int auok190x_suspend(struct device
*dev
)
699 struct platform_device
*pdev
= to_platform_device(dev
);
700 struct fb_info
*info
= platform_get_drvdata(pdev
);
701 struct auok190xfb_par
*par
= info
->par
;
702 struct auok190x_board
*board
= par
->board
;
705 dev_dbg(dev
, "suspend\n");
706 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
707 /* suspend via powering off the ic */
708 dev_dbg(dev
, "suspend with broken standby\n");
710 auok190x_power(par
, 0);
712 dev_dbg(dev
, "suspend using sleep\n");
714 /* the sleep state can only be entered from the standby state.
715 * pm_runtime_get_noresume gets called before the suspend call.
716 * So the devices usage count is >0 but it is not necessarily
719 if (!pm_runtime_status_suspended(dev
)) {
720 ret
= auok190x_runtime_suspend(dev
);
722 dev_err(dev
, "auok190x_runtime_suspend failed with %d\n",
726 par
->manual_standby
= 1;
729 gpio_direction_output(board
->gpio_nsleep
, 0);
737 static int auok190x_resume(struct device
*dev
)
739 struct platform_device
*pdev
= to_platform_device(dev
);
740 struct fb_info
*info
= platform_get_drvdata(pdev
);
741 struct auok190xfb_par
*par
= info
->par
;
742 struct auok190x_board
*board
= par
->board
;
744 dev_dbg(dev
, "resume\n");
745 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
746 dev_dbg(dev
, "resume with broken standby\n");
748 auok190x_power(par
, 1);
752 dev_dbg(dev
, "resume from sleep\n");
754 /* device should be in runtime suspend when we were suspended
755 * and pm_runtime_put_sync gets called after this function.
756 * So there is no need to touch the standby mode here at all.
758 gpio_direction_output(board
->gpio_nsleep
, 1);
761 /* an additional init call seems to be necessary after sleep */
762 auok190x_runtime_resume(dev
);
765 /* if we were runtime-suspended before, suspend again*/
766 if (!par
->manual_standby
)
767 auok190x_runtime_suspend(dev
);
769 par
->manual_standby
= 0;
776 const struct dev_pm_ops auok190x_pm
= {
777 SET_RUNTIME_PM_OPS(auok190x_runtime_suspend
, auok190x_runtime_resume
,
779 SET_SYSTEM_SLEEP_PM_OPS(auok190x_suspend
, auok190x_resume
)
781 EXPORT_SYMBOL_GPL(auok190x_pm
);
784 * Common probe and remove code
787 int auok190x_common_probe(struct platform_device
*pdev
,
788 struct auok190x_init_data
*init
)
790 struct auok190x_board
*board
= init
->board
;
791 struct auok190xfb_par
*par
;
792 struct fb_info
*info
;
793 struct panel_info
*panel
;
794 int videomemorysize
, ret
;
795 unsigned char *videomemory
;
797 /* check board contents */
798 if (!board
->init
|| !board
->cleanup
|| !board
->wait_for_rdy
799 || !board
->set_ctl
|| !board
->set_hdb
|| !board
->get_hdb
800 || !board
->setup_irq
)
803 info
= framebuffer_alloc(sizeof(struct auok190xfb_par
), &pdev
->dev
);
810 par
->recover
= auok190x_recover
;
811 par
->update_partial
= init
->update_partial
;
812 par
->update_all
= init
->update_all
;
813 par
->need_refresh
= init
->need_refresh
;
814 par
->init
= init
->init
;
816 /* init update modes */
818 par
->update_mode
= -1;
822 par
->regulator
= regulator_get(info
->device
, "vdd");
823 if (IS_ERR(par
->regulator
)) {
824 ret
= PTR_ERR(par
->regulator
);
825 dev_err(info
->device
, "Failed to get regulator: %d\n", ret
);
829 ret
= board
->init(par
);
831 dev_err(info
->device
, "board init failed, %d\n", ret
);
835 ret
= gpio_request(board
->gpio_nsleep
, "AUOK190x sleep");
837 dev_err(info
->device
, "could not request sleep gpio, %d\n",
842 ret
= gpio_direction_output(board
->gpio_nsleep
, 0);
844 dev_err(info
->device
, "could not set sleep gpio, %d\n", ret
);
848 ret
= gpio_request(board
->gpio_nrst
, "AUOK190x reset");
850 dev_err(info
->device
, "could not request reset gpio, %d\n",
855 ret
= gpio_direction_output(board
->gpio_nrst
, 0);
857 dev_err(info
->device
, "could not set reset gpio, %d\n", ret
);
861 ret
= auok190x_power(par
, 1);
863 dev_err(info
->device
, "could not power on the device, %d\n",
868 mutex_init(&par
->io_lock
);
870 init_waitqueue_head(&par
->waitq
);
872 ret
= par
->board
->setup_irq(par
->info
);
874 dev_err(info
->device
, "could not setup ready-irq, %d\n", ret
);
878 /* wait for init to complete */
879 par
->board
->wait_for_rdy(par
);
882 * From here on the controller can talk to us
885 /* initialise fix, var, resolution and rotation */
887 strlcpy(info
->fix
.id
, init
->id
, 16);
888 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
889 info
->fix
.visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
890 info
->fix
.xpanstep
= 0;
891 info
->fix
.ypanstep
= 0;
892 info
->fix
.ywrapstep
= 0;
893 info
->fix
.accel
= FB_ACCEL_NONE
;
895 info
->var
.bits_per_pixel
= 8;
896 info
->var
.grayscale
= 1;
897 info
->var
.red
.length
= 8;
898 info
->var
.green
.length
= 8;
899 info
->var
.blue
.length
= 8;
901 panel
= &panel_table
[board
->resolution
];
903 /* if 90 degree rotation, switch width and height */
904 if (board
->rotation
& 1) {
905 info
->var
.xres
= panel
->h
;
906 info
->var
.yres
= panel
->w
;
907 info
->var
.xres_virtual
= panel
->h
;
908 info
->var
.yres_virtual
= panel
->w
;
909 info
->fix
.line_length
= panel
->h
* info
->var
.bits_per_pixel
/ 8;
911 info
->var
.xres
= panel
->w
;
912 info
->var
.yres
= panel
->h
;
913 info
->var
.xres_virtual
= panel
->w
;
914 info
->var
.yres_virtual
= panel
->h
;
915 info
->fix
.line_length
= panel
->w
* info
->var
.bits_per_pixel
/ 8;
918 par
->resolution
= board
->resolution
;
919 par
->rotation
= board
->rotation
;
921 /* videomemory handling */
923 videomemorysize
= roundup((panel
->w
* panel
->h
) *
924 info
->var
.bits_per_pixel
/ 8, PAGE_SIZE
);
925 videomemory
= vmalloc(videomemorysize
);
931 memset(videomemory
, 0, videomemorysize
);
932 info
->screen_base
= (char *)videomemory
;
933 info
->fix
.smem_len
= videomemorysize
;
935 info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_VIRTFB
;
936 info
->fbops
= &auok190xfb_ops
;
938 /* deferred io init */
940 info
->fbdefio
= devm_kzalloc(info
->device
,
941 sizeof(struct fb_deferred_io
),
943 if (!info
->fbdefio
) {
944 dev_err(info
->device
, "Failed to allocate memory\n");
949 dev_dbg(info
->device
, "targetting %d frames per second\n", board
->fps
);
950 info
->fbdefio
->delay
= HZ
/ board
->fps
;
951 info
->fbdefio
->first_io
= auok190xfb_dpy_first_io
,
952 info
->fbdefio
->deferred_io
= auok190xfb_dpy_deferred_io
,
953 fb_deferred_io_init(info
);
957 ret
= fb_alloc_cmap(&info
->cmap
, 256, 0);
959 dev_err(info
->device
, "Failed to allocate colormap\n");
963 /* controller init */
965 par
->consecutive_threshold
= 100;
967 auok190x_identify(par
);
969 platform_set_drvdata(pdev
, info
);
971 ret
= register_framebuffer(info
);
975 ret
= sysfs_create_group(&info
->device
->kobj
, &auok190x_attr_group
);
979 dev_info(info
->device
, "fb%d: %dx%d using %dK of video memory\n",
980 info
->node
, info
->var
.xres
, info
->var
.yres
,
981 videomemorysize
>> 10);
983 /* increase autosuspend_delay when we use alternative methods
986 par
->autosuspend_delay
= (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
)
989 pm_runtime_set_active(info
->device
);
990 pm_runtime_enable(info
->device
);
991 pm_runtime_set_autosuspend_delay(info
->device
, par
->autosuspend_delay
);
992 pm_runtime_use_autosuspend(info
->device
);
997 unregister_framebuffer(info
);
999 fb_dealloc_cmap(&info
->cmap
);
1001 fb_deferred_io_cleanup(info
);
1003 vfree((void *)info
->screen_base
);
1005 auok190x_power(par
, 0);
1007 gpio_free(board
->gpio_nrst
);
1009 gpio_free(board
->gpio_nsleep
);
1011 board
->cleanup(par
);
1013 regulator_put(par
->regulator
);
1015 framebuffer_release(info
);
1019 EXPORT_SYMBOL_GPL(auok190x_common_probe
);
1021 int auok190x_common_remove(struct platform_device
*pdev
)
1023 struct fb_info
*info
= platform_get_drvdata(pdev
);
1024 struct auok190xfb_par
*par
= info
->par
;
1025 struct auok190x_board
*board
= par
->board
;
1027 pm_runtime_disable(info
->device
);
1029 sysfs_remove_group(&info
->device
->kobj
, &auok190x_attr_group
);
1031 unregister_framebuffer(info
);
1033 fb_dealloc_cmap(&info
->cmap
);
1035 fb_deferred_io_cleanup(info
);
1037 vfree((void *)info
->screen_base
);
1039 auok190x_power(par
, 0);
1041 gpio_free(board
->gpio_nrst
);
1042 gpio_free(board
->gpio_nsleep
);
1044 board
->cleanup(par
);
1046 regulator_put(par
->regulator
);
1048 framebuffer_release(info
);
1052 EXPORT_SYMBOL_GPL(auok190x_common_remove
);
1054 MODULE_DESCRIPTION("Common code for AUO-K190X controllers");
1055 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
1056 MODULE_LICENSE("GPL");