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/pm_runtime.h>
16 #include <linux/delay.h>
17 #include <linux/uaccess.h>
18 #include <linux/vmalloc.h>
19 #include <linux/regulator/consumer.h>
21 #include <video/auo_k190xfb.h>
23 #include "auo_k190x.h"
30 /* table of panel specific parameters to be indexed into by the board drivers */
31 static struct panel_info panel_table
[] = {
33 [AUOK190X_RESOLUTION_800_600
] = {
38 [AUOK190X_RESOLUTION_1024_768
] = {
45 * private I80 interface to the board driver
48 static void auok190x_issue_data(struct auok190xfb_par
*par
, u16 data
)
50 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 0);
51 par
->board
->set_hdb(par
, data
);
52 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 1);
55 static void auok190x_issue_cmd(struct auok190xfb_par
*par
, u16 data
)
57 par
->board
->set_ctl(par
, AUOK190X_I80_DC
, 0);
58 auok190x_issue_data(par
, data
);
59 par
->board
->set_ctl(par
, AUOK190X_I80_DC
, 1);
62 static int auok190x_issue_pixels(struct auok190xfb_par
*par
, int size
,
65 struct device
*dev
= par
->info
->device
;
70 dev_err(dev
, "issue_pixels: size %d must be a multiple of 4\n",
75 for (i
= 0; i
< (size
>> 1); i
++) {
76 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 0);
78 /* simple reduction of 8bit staticgray to 4bit gray
79 * combines 4 * 4bit pixel values into a 16bit value
81 tmp
= (data
[2*i
] & 0xF0) >> 4;
82 tmp
|= (data
[2*i
] & 0xF000) >> 8;
83 tmp
|= (data
[2*i
+1] & 0xF0) << 4;
84 tmp
|= (data
[2*i
+1] & 0xF000);
86 par
->board
->set_hdb(par
, tmp
);
87 par
->board
->set_ctl(par
, AUOK190X_I80_WR
, 1);
93 static u16
auok190x_read_data(struct auok190xfb_par
*par
)
97 par
->board
->set_ctl(par
, AUOK190X_I80_OE
, 0);
98 data
= par
->board
->get_hdb(par
);
99 par
->board
->set_ctl(par
, AUOK190X_I80_OE
, 1);
105 * Command interface for the controller drivers
108 void auok190x_send_command_nowait(struct auok190xfb_par
*par
, u16 data
)
110 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
111 auok190x_issue_cmd(par
, data
);
112 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
114 EXPORT_SYMBOL_GPL(auok190x_send_command_nowait
);
116 void auok190x_send_cmdargs_nowait(struct auok190xfb_par
*par
, u16 cmd
,
121 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
122 auok190x_issue_cmd(par
, cmd
);
124 for (i
= 0; i
< argc
; i
++)
125 auok190x_issue_data(par
, argv
[i
]);
126 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
128 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_nowait
);
130 int auok190x_send_command(struct auok190xfb_par
*par
, u16 data
)
134 ret
= par
->board
->wait_for_rdy(par
);
138 auok190x_send_command_nowait(par
, data
);
141 EXPORT_SYMBOL_GPL(auok190x_send_command
);
143 int auok190x_send_cmdargs(struct auok190xfb_par
*par
, u16 cmd
,
148 ret
= par
->board
->wait_for_rdy(par
);
152 auok190x_send_cmdargs_nowait(par
, cmd
, argc
, argv
);
155 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs
);
157 int auok190x_read_cmdargs(struct auok190xfb_par
*par
, u16 cmd
,
162 ret
= par
->board
->wait_for_rdy(par
);
166 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
167 auok190x_issue_cmd(par
, cmd
);
169 for (i
= 0; i
< argc
; i
++)
170 argv
[i
] = auok190x_read_data(par
);
171 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
175 EXPORT_SYMBOL_GPL(auok190x_read_cmdargs
);
177 void auok190x_send_cmdargs_pixels_nowait(struct auok190xfb_par
*par
, u16 cmd
,
178 int argc
, u16
*argv
, int size
, u16
*data
)
182 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 0);
184 auok190x_issue_cmd(par
, cmd
);
186 for (i
= 0; i
< argc
; i
++)
187 auok190x_issue_data(par
, argv
[i
]);
189 auok190x_issue_pixels(par
, size
, data
);
191 par
->board
->set_ctl(par
, AUOK190X_I80_CS
, 1);
193 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels_nowait
);
195 int auok190x_send_cmdargs_pixels(struct auok190xfb_par
*par
, u16 cmd
,
196 int argc
, u16
*argv
, int size
, u16
*data
)
200 ret
= par
->board
->wait_for_rdy(par
);
204 auok190x_send_cmdargs_pixels_nowait(par
, cmd
, argc
, argv
, size
, data
);
208 EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels
);
211 * fbdefio callbacks - common on both controllers.
214 static void auok190xfb_dpy_first_io(struct fb_info
*info
)
216 /* tell runtime-pm that we wish to use the device in a short time */
217 pm_runtime_get(info
->device
);
220 /* this is called back from the deferred io workqueue */
221 static void auok190xfb_dpy_deferred_io(struct fb_info
*info
,
222 struct list_head
*pagelist
)
224 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
225 struct auok190xfb_par
*par
= info
->par
;
226 u16 yres
= info
->var
.yres
;
227 u16 xres
= info
->var
.xres
;
234 if (!list_empty(pagelist
))
235 /* the device resume should've been requested through first_io,
236 * if the resume did not finish until now, wait for it.
238 pm_runtime_barrier(info
->device
);
240 /* We reached this via the fsync or some other way.
241 * In either case the first_io function did not run,
242 * so we runtime_resume the device here synchronously.
244 pm_runtime_get_sync(info
->device
);
246 /* Do a full screen update every n updates to prevent
247 * excessive darkening of the Sipix display.
248 * If we do this, there is no need to walk the pages.
250 if (par
->need_refresh(par
)) {
251 par
->update_all(par
);
255 /* height increment is fixed per page */
256 h_inc
= DIV_ROUND_UP(PAGE_SIZE
, xres
);
258 /* calculate number of pages from pixel height */
259 threshold
= par
->consecutive_threshold
/ h_inc
;
263 /* walk the written page list and swizzle the data */
264 list_for_each_entry(cur
, &fbdefio
->pagelist
, lru
) {
265 if (prev_index
< 0) {
266 /* just starting so assign first page */
267 y1
= (cur
->index
<< PAGE_SHIFT
) / xres
;
269 } else if ((cur
->index
- prev_index
) <= threshold
) {
270 /* page is within our threshold for single updates */
271 h
+= h_inc
* (cur
->index
- prev_index
);
273 /* page not consecutive, issue previous update first */
274 par
->update_partial(par
, y1
, y1
+ h
);
276 /* start over with our non consecutive page */
277 y1
= (cur
->index
<< PAGE_SHIFT
) / xres
;
280 prev_index
= cur
->index
;
283 /* if we still have any pages to update we do so now */
285 /* its a full screen update, just do it */
286 par
->update_all(par
);
288 par
->update_partial(par
, y1
, min((u16
) (y1
+ h
), yres
));
291 pm_runtime_mark_last_busy(info
->device
);
292 pm_runtime_put_autosuspend(info
->device
);
296 * framebuffer operations
300 * this is the slow path from userspace. they can seek and write to
301 * the fb. it's inefficient to do anything less than a full screen draw
303 static ssize_t
auok190xfb_write(struct fb_info
*info
, const char __user
*buf
,
304 size_t count
, loff_t
*ppos
)
306 struct auok190xfb_par
*par
= info
->par
;
307 unsigned long p
= *ppos
;
310 unsigned long total_size
;
312 if (info
->state
!= FBINFO_STATE_RUNNING
)
315 total_size
= info
->fix
.smem_len
;
320 if (count
> total_size
) {
325 if (count
+ p
> total_size
) {
329 count
= total_size
- p
;
332 dst
= (void *)(info
->screen_base
+ p
);
334 if (copy_from_user(dst
, buf
, count
))
340 par
->update_all(par
);
342 return (err
) ? err
: count
;
345 static void auok190xfb_fillrect(struct fb_info
*info
,
346 const struct fb_fillrect
*rect
)
348 struct auok190xfb_par
*par
= info
->par
;
350 sys_fillrect(info
, rect
);
352 par
->update_all(par
);
355 static void auok190xfb_copyarea(struct fb_info
*info
,
356 const struct fb_copyarea
*area
)
358 struct auok190xfb_par
*par
= info
->par
;
360 sys_copyarea(info
, area
);
362 par
->update_all(par
);
365 static void auok190xfb_imageblit(struct fb_info
*info
,
366 const struct fb_image
*image
)
368 struct auok190xfb_par
*par
= info
->par
;
370 sys_imageblit(info
, image
);
372 par
->update_all(par
);
375 static int auok190xfb_check_var(struct fb_var_screeninfo
*var
,
376 struct fb_info
*info
)
378 if (info
->var
.xres
!= var
->xres
|| info
->var
.yres
!= var
->yres
||
379 info
->var
.xres_virtual
!= var
->xres_virtual
||
380 info
->var
.yres_virtual
!= var
->yres_virtual
) {
381 pr_info("%s: Resolution not supported: X%u x Y%u\n",
382 __func__
, var
->xres
, var
->yres
);
390 if ((info
->fix
.line_length
* var
->yres_virtual
) > info
->fix
.smem_len
) {
391 pr_info("%s: Memory Limit requested yres_virtual = %u\n",
392 __func__
, var
->yres_virtual
);
399 static struct fb_ops auok190xfb_ops
= {
400 .owner
= THIS_MODULE
,
401 .fb_read
= fb_sys_read
,
402 .fb_write
= auok190xfb_write
,
403 .fb_fillrect
= auok190xfb_fillrect
,
404 .fb_copyarea
= auok190xfb_copyarea
,
405 .fb_imageblit
= auok190xfb_imageblit
,
406 .fb_check_var
= auok190xfb_check_var
,
410 * Controller-functions common to both K1900 and K1901
413 static int auok190x_read_temperature(struct auok190xfb_par
*par
)
415 struct device
*dev
= par
->info
->device
;
419 pm_runtime_get_sync(dev
);
421 mutex_lock(&(par
->io_lock
));
423 auok190x_read_cmdargs(par
, AUOK190X_CMD_READ_VERSION
, 4, data
);
425 mutex_unlock(&(par
->io_lock
));
427 pm_runtime_mark_last_busy(dev
);
428 pm_runtime_put_autosuspend(dev
);
430 /* sanitize and split of half-degrees for now */
431 temp
= ((data
[0] & AUOK190X_VERSION_TEMP_MASK
) >> 1);
433 /* handle positive and negative temperatures */
435 return (255 - temp
+ 1) * (-1);
440 static void auok190x_identify(struct auok190xfb_par
*par
)
442 struct device
*dev
= par
->info
->device
;
445 pm_runtime_get_sync(dev
);
447 mutex_lock(&(par
->io_lock
));
449 auok190x_read_cmdargs(par
, AUOK190X_CMD_READ_VERSION
, 4, data
);
451 mutex_unlock(&(par
->io_lock
));
453 par
->epd_type
= data
[1] & AUOK190X_VERSION_TEMP_MASK
;
455 par
->panel_size_int
= AUOK190X_VERSION_SIZE_INT(data
[2]);
456 par
->panel_size_float
= AUOK190X_VERSION_SIZE_FLOAT(data
[2]);
457 par
->panel_model
= AUOK190X_VERSION_MODEL(data
[2]);
459 par
->tcon_version
= AUOK190X_VERSION_TCON(data
[3]);
460 par
->lut_version
= AUOK190X_VERSION_LUT(data
[3]);
462 dev_dbg(dev
, "panel %d.%din, model 0x%x, EPD 0x%x TCON-rev 0x%x, LUT-rev 0x%x",
463 par
->panel_size_int
, par
->panel_size_float
, par
->panel_model
,
464 par
->epd_type
, par
->tcon_version
, par
->lut_version
);
466 pm_runtime_mark_last_busy(dev
);
467 pm_runtime_put_autosuspend(dev
);
474 static ssize_t
update_mode_show(struct device
*dev
,
475 struct device_attribute
*attr
, char *buf
)
477 struct fb_info
*info
= dev_get_drvdata(dev
);
478 struct auok190xfb_par
*par
= info
->par
;
480 return sprintf(buf
, "%d\n", par
->update_mode
);
483 static ssize_t
update_mode_store(struct device
*dev
,
484 struct device_attribute
*attr
,
485 const char *buf
, size_t count
)
487 struct fb_info
*info
= dev_get_drvdata(dev
);
488 struct auok190xfb_par
*par
= info
->par
;
491 ret
= kstrtoint(buf
, 10, &mode
);
495 par
->update_mode
= mode
;
497 /* if we enter a better mode, do a full update */
498 if (par
->last_mode
> 1 && mode
< par
->last_mode
)
499 par
->update_all(par
);
504 static ssize_t
flash_show(struct device
*dev
, struct device_attribute
*attr
,
507 struct fb_info
*info
= dev_get_drvdata(dev
);
508 struct auok190xfb_par
*par
= info
->par
;
510 return sprintf(buf
, "%d\n", par
->flash
);
513 static ssize_t
flash_store(struct device
*dev
, struct device_attribute
*attr
,
514 const char *buf
, size_t count
)
516 struct fb_info
*info
= dev_get_drvdata(dev
);
517 struct auok190xfb_par
*par
= info
->par
;
520 ret
= kstrtoint(buf
, 10, &flash
);
532 static ssize_t
temp_show(struct device
*dev
, struct device_attribute
*attr
,
535 struct fb_info
*info
= dev_get_drvdata(dev
);
536 struct auok190xfb_par
*par
= info
->par
;
539 temp
= auok190x_read_temperature(par
);
540 return sprintf(buf
, "%d\n", temp
);
543 static DEVICE_ATTR(update_mode
, 0644, update_mode_show
, update_mode_store
);
544 static DEVICE_ATTR(flash
, 0644, flash_show
, flash_store
);
545 static DEVICE_ATTR(temp
, 0644, temp_show
, NULL
);
547 static struct attribute
*auok190x_attributes
[] = {
548 &dev_attr_update_mode
.attr
,
549 &dev_attr_flash
.attr
,
554 static const struct attribute_group auok190x_attr_group
= {
555 .attrs
= auok190x_attributes
,
558 static int auok190x_power(struct auok190xfb_par
*par
, bool on
)
560 struct auok190x_board
*board
= par
->board
;
564 /* We should maintain POWER up for at least 80ms before set
565 * RST_N and SLP_N to high (TCON spec 20100803_v35 p59)
567 ret
= regulator_enable(par
->regulator
);
572 gpio_set_value(board
->gpio_nrst
, 1);
573 gpio_set_value(board
->gpio_nsleep
, 1);
576 regulator_disable(par
->regulator
);
577 gpio_set_value(board
->gpio_nrst
, 0);
578 gpio_set_value(board
->gpio_nsleep
, 0);
585 * Recovery - powercycle the controller
588 static void auok190x_recover(struct auok190xfb_par
*par
)
590 auok190x_power(par
, 0);
592 auok190x_power(par
, 1);
596 /* wait for init to complete */
597 par
->board
->wait_for_rdy(par
);
605 static int auok190x_runtime_suspend(struct device
*dev
)
607 struct platform_device
*pdev
= to_platform_device(dev
);
608 struct fb_info
*info
= platform_get_drvdata(pdev
);
609 struct auok190xfb_par
*par
= info
->par
;
610 struct auok190x_board
*board
= par
->board
;
613 /* take and keep the lock until we are resumed, as the controller
614 * will never reach the non-busy state when in standby mode
616 mutex_lock(&(par
->io_lock
));
619 dev_warn(dev
, "already in standby, runtime-pm pairing mismatch\n");
620 mutex_unlock(&(par
->io_lock
));
624 /* according to runtime_pm.txt runtime_suspend only means, that the
625 * device will not process data and will not communicate with the CPU
626 * As we hold the lock, this stays true even without standby
628 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
629 dev_dbg(dev
, "runtime suspend without standby\n");
631 } else if (board
->quirks
& AUOK190X_QUIRK_STANDBYPARAM
) {
632 /* for some TCON versions STANDBY expects a parameter (0) but
633 * it seems the real tcon version has to be determined yet.
635 dev_dbg(dev
, "runtime suspend with additional empty param\n");
637 auok190x_send_cmdargs(par
, AUOK190X_CMD_STANDBY
, 1,
640 dev_dbg(dev
, "runtime suspend without param\n");
641 auok190x_send_command(par
, AUOK190X_CMD_STANDBY
);
652 static int auok190x_runtime_resume(struct device
*dev
)
654 struct platform_device
*pdev
= to_platform_device(dev
);
655 struct fb_info
*info
= platform_get_drvdata(pdev
);
656 struct auok190xfb_par
*par
= info
->par
;
657 struct auok190x_board
*board
= par
->board
;
660 dev_warn(dev
, "not in standby, runtime-pm pairing mismatch\n");
664 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
665 dev_dbg(dev
, "runtime resume without standby\n");
667 /* when in standby, controller is always busy
668 * and only accepts the wakeup command
670 dev_dbg(dev
, "runtime resume from standby\n");
671 auok190x_send_command_nowait(par
, AUOK190X_CMD_WAKEUP
);
675 /* wait for the controller to be ready and release the lock */
676 board
->wait_for_rdy(par
);
681 mutex_unlock(&(par
->io_lock
));
686 static int auok190x_suspend(struct device
*dev
)
688 struct platform_device
*pdev
= to_platform_device(dev
);
689 struct fb_info
*info
= platform_get_drvdata(pdev
);
690 struct auok190xfb_par
*par
= info
->par
;
691 struct auok190x_board
*board
= par
->board
;
694 dev_dbg(dev
, "suspend\n");
695 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
696 /* suspend via powering off the ic */
697 dev_dbg(dev
, "suspend with broken standby\n");
699 auok190x_power(par
, 0);
701 dev_dbg(dev
, "suspend using sleep\n");
703 /* the sleep state can only be entered from the standby state.
704 * pm_runtime_get_noresume gets called before the suspend call.
705 * So the devices usage count is >0 but it is not necessarily
708 if (!pm_runtime_status_suspended(dev
)) {
709 ret
= auok190x_runtime_suspend(dev
);
711 dev_err(dev
, "auok190x_runtime_suspend failed with %d\n",
715 par
->manual_standby
= 1;
718 gpio_direction_output(board
->gpio_nsleep
, 0);
726 static int auok190x_resume(struct device
*dev
)
728 struct platform_device
*pdev
= to_platform_device(dev
);
729 struct fb_info
*info
= platform_get_drvdata(pdev
);
730 struct auok190xfb_par
*par
= info
->par
;
731 struct auok190x_board
*board
= par
->board
;
733 dev_dbg(dev
, "resume\n");
734 if (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
) {
735 dev_dbg(dev
, "resume with broken standby\n");
737 auok190x_power(par
, 1);
741 dev_dbg(dev
, "resume from sleep\n");
743 /* device should be in runtime suspend when we were suspended
744 * and pm_runtime_put_sync gets called after this function.
745 * So there is no need to touch the standby mode here at all.
747 gpio_direction_output(board
->gpio_nsleep
, 1);
750 /* an additional init call seems to be necessary after sleep */
751 auok190x_runtime_resume(dev
);
754 /* if we were runtime-suspended before, suspend again*/
755 if (!par
->manual_standby
)
756 auok190x_runtime_suspend(dev
);
758 par
->manual_standby
= 0;
765 const struct dev_pm_ops auok190x_pm
= {
766 SET_RUNTIME_PM_OPS(auok190x_runtime_suspend
, auok190x_runtime_resume
,
768 SET_SYSTEM_SLEEP_PM_OPS(auok190x_suspend
, auok190x_resume
)
770 EXPORT_SYMBOL_GPL(auok190x_pm
);
773 * Common probe and remove code
776 int __devinit
auok190x_common_probe(struct platform_device
*pdev
,
777 struct auok190x_init_data
*init
)
779 struct auok190x_board
*board
= init
->board
;
780 struct auok190xfb_par
*par
;
781 struct fb_info
*info
;
782 struct panel_info
*panel
;
783 int videomemorysize
, ret
;
784 unsigned char *videomemory
;
786 /* check board contents */
787 if (!board
->init
|| !board
->cleanup
|| !board
->wait_for_rdy
788 || !board
->set_ctl
|| !board
->set_hdb
|| !board
->get_hdb
789 || !board
->setup_irq
)
792 info
= framebuffer_alloc(sizeof(struct auok190xfb_par
), &pdev
->dev
);
799 par
->recover
= auok190x_recover
;
800 par
->update_partial
= init
->update_partial
;
801 par
->update_all
= init
->update_all
;
802 par
->need_refresh
= init
->need_refresh
;
803 par
->init
= init
->init
;
805 /* init update modes */
807 par
->update_mode
= -1;
811 par
->regulator
= regulator_get(info
->device
, "vdd");
812 if (IS_ERR(par
->regulator
)) {
813 ret
= PTR_ERR(par
->regulator
);
814 dev_err(info
->device
, "Failed to get regulator: %d\n", ret
);
818 ret
= board
->init(par
);
820 dev_err(info
->device
, "board init failed, %d\n", ret
);
824 ret
= gpio_request(board
->gpio_nsleep
, "AUOK190x sleep");
826 dev_err(info
->device
, "could not request sleep gpio, %d\n",
831 ret
= gpio_direction_output(board
->gpio_nsleep
, 0);
833 dev_err(info
->device
, "could not set sleep gpio, %d\n", ret
);
837 ret
= gpio_request(board
->gpio_nrst
, "AUOK190x reset");
839 dev_err(info
->device
, "could not request reset gpio, %d\n",
844 ret
= gpio_direction_output(board
->gpio_nrst
, 0);
846 dev_err(info
->device
, "could not set reset gpio, %d\n", ret
);
850 ret
= auok190x_power(par
, 1);
852 dev_err(info
->device
, "could not power on the device, %d\n",
857 mutex_init(&par
->io_lock
);
859 init_waitqueue_head(&par
->waitq
);
861 ret
= par
->board
->setup_irq(par
->info
);
863 dev_err(info
->device
, "could not setup ready-irq, %d\n", ret
);
867 /* wait for init to complete */
868 par
->board
->wait_for_rdy(par
);
871 * From here on the controller can talk to us
874 /* initialise fix, var, resolution and rotation */
876 strlcpy(info
->fix
.id
, init
->id
, 16);
877 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
878 info
->fix
.visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
879 info
->fix
.xpanstep
= 0;
880 info
->fix
.ypanstep
= 0;
881 info
->fix
.ywrapstep
= 0;
882 info
->fix
.accel
= FB_ACCEL_NONE
;
884 info
->var
.bits_per_pixel
= 8;
885 info
->var
.grayscale
= 1;
886 info
->var
.red
.length
= 8;
887 info
->var
.green
.length
= 8;
888 info
->var
.blue
.length
= 8;
890 panel
= &panel_table
[board
->resolution
];
892 /* if 90 degree rotation, switch width and height */
893 if (board
->rotation
& 1) {
894 info
->var
.xres
= panel
->h
;
895 info
->var
.yres
= panel
->w
;
896 info
->var
.xres_virtual
= panel
->h
;
897 info
->var
.yres_virtual
= panel
->w
;
898 info
->fix
.line_length
= panel
->h
;
900 info
->var
.xres
= panel
->w
;
901 info
->var
.yres
= panel
->h
;
902 info
->var
.xres_virtual
= panel
->w
;
903 info
->var
.yres_virtual
= panel
->h
;
904 info
->fix
.line_length
= panel
->w
;
907 par
->resolution
= board
->resolution
;
908 par
->rotation
= board
->rotation
;
910 /* videomemory handling */
912 videomemorysize
= roundup((panel
->w
* panel
->h
), PAGE_SIZE
);
913 videomemory
= vmalloc(videomemorysize
);
919 memset(videomemory
, 0, videomemorysize
);
920 info
->screen_base
= (char *)videomemory
;
921 info
->fix
.smem_len
= videomemorysize
;
923 info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_VIRTFB
;
924 info
->fbops
= &auok190xfb_ops
;
926 /* deferred io init */
928 info
->fbdefio
= devm_kzalloc(info
->device
,
929 sizeof(struct fb_deferred_io
),
931 if (!info
->fbdefio
) {
932 dev_err(info
->device
, "Failed to allocate memory\n");
937 dev_dbg(info
->device
, "targetting %d frames per second\n", board
->fps
);
938 info
->fbdefio
->delay
= HZ
/ board
->fps
;
939 info
->fbdefio
->first_io
= auok190xfb_dpy_first_io
,
940 info
->fbdefio
->deferred_io
= auok190xfb_dpy_deferred_io
,
941 fb_deferred_io_init(info
);
945 ret
= fb_alloc_cmap(&info
->cmap
, 256, 0);
947 dev_err(info
->device
, "Failed to allocate colormap\n");
951 /* controller init */
953 par
->consecutive_threshold
= 100;
955 auok190x_identify(par
);
957 platform_set_drvdata(pdev
, info
);
959 ret
= register_framebuffer(info
);
963 ret
= sysfs_create_group(&info
->device
->kobj
, &auok190x_attr_group
);
967 dev_info(info
->device
, "fb%d: %dx%d using %dK of video memory\n",
968 info
->node
, info
->var
.xres
, info
->var
.yres
,
969 videomemorysize
>> 10);
971 /* increase autosuspend_delay when we use alternative methods
974 par
->autosuspend_delay
= (board
->quirks
& AUOK190X_QUIRK_STANDBYBROKEN
)
977 pm_runtime_set_active(info
->device
);
978 pm_runtime_enable(info
->device
);
979 pm_runtime_set_autosuspend_delay(info
->device
, par
->autosuspend_delay
);
980 pm_runtime_use_autosuspend(info
->device
);
985 unregister_framebuffer(info
);
987 fb_dealloc_cmap(&info
->cmap
);
989 fb_deferred_io_cleanup(info
);
990 kfree(info
->fbdefio
);
992 vfree((void *)info
->screen_base
);
994 auok190x_power(par
, 0);
996 gpio_free(board
->gpio_nrst
);
998 gpio_free(board
->gpio_nsleep
);
1000 board
->cleanup(par
);
1002 regulator_put(par
->regulator
);
1004 framebuffer_release(info
);
1008 EXPORT_SYMBOL_GPL(auok190x_common_probe
);
1010 int __devexit
auok190x_common_remove(struct platform_device
*pdev
)
1012 struct fb_info
*info
= platform_get_drvdata(pdev
);
1013 struct auok190xfb_par
*par
= info
->par
;
1014 struct auok190x_board
*board
= par
->board
;
1016 pm_runtime_disable(info
->device
);
1018 sysfs_remove_group(&info
->device
->kobj
, &auok190x_attr_group
);
1020 unregister_framebuffer(info
);
1022 fb_dealloc_cmap(&info
->cmap
);
1024 fb_deferred_io_cleanup(info
);
1025 kfree(info
->fbdefio
);
1027 vfree((void *)info
->screen_base
);
1029 auok190x_power(par
, 0);
1031 gpio_free(board
->gpio_nrst
);
1032 gpio_free(board
->gpio_nsleep
);
1034 board
->cleanup(par
);
1036 regulator_put(par
->regulator
);
1038 framebuffer_release(info
);
1042 EXPORT_SYMBOL_GPL(auok190x_common_remove
);
1044 MODULE_DESCRIPTION("Common code for AUO-K190X controllers");
1045 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
1046 MODULE_LICENSE("GPL");