]>
Commit | Line | Data |
---|---|---|
53027cdf HS |
1 | /* |
2 | * auok190xfb.c -- FB driver for AUO-K1901 controllers | |
3 | * | |
4 | * Copyright (C) 2011, 2012 Heiko Stuebner <heiko@sntech.de> | |
5 | * | |
6 | * based on broadsheetfb.c | |
7 | * | |
8 | * Copyright (C) 2008, Jaya Kumar | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License version 2 as | |
12 | * published by the Free Software Foundation. | |
13 | * | |
14 | * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven. | |
15 | * | |
16 | * This driver is written to be used with the AUO-K1901 display controller. | |
17 | * | |
18 | * It is intended to be architecture independent. A board specific driver | |
19 | * must be used to perform all the physical IO interactions. | |
20 | * | |
21 | * The controller supports different update modes: | |
22 | * mode0+1 16 step gray (4bit) | |
23 | * mode2+3 4 step gray (2bit) | |
24 | * mode4+5 2 step gray (1bit) | |
25 | * - mode4 is described as "without LUT" | |
26 | * mode7 automatic selection of update mode | |
27 | * | |
28 | * The most interesting difference to the K1900 is the ability to do screen | |
29 | * updates in an asynchronous fashion. Where the K1900 needs to wait for the | |
30 | * current update to complete, the K1901 can process later updates already. | |
31 | */ | |
32 | ||
33 | #include <linux/module.h> | |
34 | #include <linux/kernel.h> | |
35 | #include <linux/errno.h> | |
36 | #include <linux/string.h> | |
37 | #include <linux/mm.h> | |
38 | #include <linux/slab.h> | |
39 | #include <linux/delay.h> | |
40 | #include <linux/interrupt.h> | |
41 | #include <linux/fb.h> | |
42 | #include <linux/init.h> | |
43 | #include <linux/platform_device.h> | |
44 | #include <linux/list.h> | |
45 | #include <linux/firmware.h> | |
46 | #include <linux/gpio.h> | |
47 | #include <linux/pm_runtime.h> | |
48 | ||
49 | #include <video/auo_k190xfb.h> | |
50 | ||
51 | #include "auo_k190x.h" | |
52 | ||
53 | /* | |
54 | * AUO-K1901 specific commands | |
55 | */ | |
56 | ||
57 | #define AUOK1901_CMD_LUT_INTERFACE 0x0005 | |
58 | #define AUOK1901_CMD_DMA_START 0x1001 | |
59 | #define AUOK1901_CMD_CURSOR_START 0x1007 | |
60 | #define AUOK1901_CMD_CURSOR_STOP AUOK190X_CMD_DATA_STOP | |
61 | #define AUOK1901_CMD_DDMA_START 0x1009 | |
62 | ||
63 | #define AUOK1901_INIT_GATE_PULSE_LOW (0 << 14) | |
64 | #define AUOK1901_INIT_GATE_PULSE_HIGH (1 << 14) | |
65 | #define AUOK1901_INIT_SINGLE_GATE (0 << 13) | |
66 | #define AUOK1901_INIT_DOUBLE_GATE (1 << 13) | |
67 | ||
68 | /* Bits to pixels | |
69 | * Mode 15-12 11-8 7-4 3-0 | |
70 | * format2 2 T 1 T | |
71 | * format3 1 T 2 T | |
72 | * format4 T 2 T 1 | |
73 | * format5 T 1 T 2 | |
74 | * | |
75 | * halftone modes: | |
76 | * format6 2 2 1 1 | |
77 | * format7 1 1 2 2 | |
78 | */ | |
79 | #define AUOK1901_INIT_FORMAT2 (1 << 7) | |
80 | #define AUOK1901_INIT_FORMAT3 ((1 << 7) | (1 << 6)) | |
81 | #define AUOK1901_INIT_FORMAT4 (1 << 8) | |
82 | #define AUOK1901_INIT_FORMAT5 ((1 << 8) | (1 << 6)) | |
83 | #define AUOK1901_INIT_FORMAT6 ((1 << 8) | (1 << 7)) | |
84 | #define AUOK1901_INIT_FORMAT7 ((1 << 8) | (1 << 7) | (1 << 6)) | |
85 | ||
86 | /* res[4] to bit 10 | |
87 | * res[3-0] to bits 5-2 | |
88 | */ | |
89 | #define AUOK1901_INIT_RESOLUTION(_res) (((_res & (1 << 4)) << 6) \ | |
90 | | ((_res & 0xf) << 2)) | |
91 | ||
92 | /* | |
93 | * portrait / landscape orientation in AUOK1901_CMD_DMA_START | |
94 | */ | |
95 | #define AUOK1901_DMA_ROTATE90(_rot) ((_rot & 1) << 13) | |
96 | ||
97 | /* | |
98 | * equivalent to 1 << 11, needs the ~ to have same rotation like K1900 | |
99 | */ | |
100 | #define AUOK1901_DDMA_ROTATE180(_rot) ((~_rot & 2) << 10) | |
101 | ||
102 | static void auok1901_init(struct auok190xfb_par *par) | |
103 | { | |
104 | struct auok190x_board *board = par->board; | |
105 | u16 init_param = 0; | |
106 | ||
107 | init_param |= AUOK190X_INIT_INVERSE_WHITE; | |
108 | init_param |= AUOK190X_INIT_FORMAT0; | |
109 | init_param |= AUOK1901_INIT_RESOLUTION(par->resolution); | |
110 | init_param |= AUOK190X_INIT_SHIFT_LEFT; | |
111 | ||
112 | auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param); | |
113 | ||
114 | /* let the controller finish */ | |
115 | board->wait_for_rdy(par); | |
116 | } | |
117 | ||
118 | static void auok1901_update_region(struct auok190xfb_par *par, int mode, | |
119 | u16 y1, u16 y2) | |
120 | { | |
121 | struct device *dev = par->info->device; | |
122 | unsigned char *buf = (unsigned char *)par->info->screen_base; | |
123 | int xres = par->info->var.xres; | |
a1655100 | 124 | int line_length = par->info->fix.line_length; |
53027cdf HS |
125 | u16 args[5]; |
126 | ||
127 | pm_runtime_get_sync(dev); | |
128 | ||
129 | mutex_lock(&(par->io_lock)); | |
130 | ||
131 | /* y1 and y2 must be a multiple of 2 so drop the lowest bit */ | |
132 | y1 &= 0xfffe; | |
133 | y2 &= 0xfffe; | |
134 | ||
135 | dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n", | |
136 | 1, y1+1, xres, y2-y1, mode); | |
137 | ||
138 | /* K1901: first transfer the region data */ | |
139 | args[0] = AUOK1901_DMA_ROTATE90(par->rotation) | 1; | |
140 | args[1] = y1 + 1; | |
141 | args[2] = xres; | |
142 | args[3] = y2 - y1; | |
a1655100 | 143 | buf += y1 * line_length; |
53027cdf | 144 | auok190x_send_cmdargs_pixels_nowait(par, AUOK1901_CMD_DMA_START, 4, |
a1655100 | 145 | args, ((y2 - y1) * line_length)/2, |
53027cdf HS |
146 | (u16 *) buf); |
147 | auok190x_send_command_nowait(par, AUOK190X_CMD_DATA_STOP); | |
148 | ||
149 | /* K1901: second tell the controller to update the region with mode */ | |
150 | args[0] = mode | AUOK1901_DDMA_ROTATE180(par->rotation); | |
151 | args[1] = 1; | |
152 | args[2] = y1 + 1; | |
153 | args[3] = xres; | |
154 | args[4] = y2 - y1; | |
155 | auok190x_send_cmdargs_nowait(par, AUOK1901_CMD_DDMA_START, 5, args); | |
156 | ||
157 | par->update_cnt++; | |
158 | ||
159 | mutex_unlock(&(par->io_lock)); | |
160 | ||
161 | pm_runtime_mark_last_busy(dev); | |
162 | pm_runtime_put_autosuspend(dev); | |
163 | } | |
164 | ||
165 | static void auok1901fb_dpy_update_pages(struct auok190xfb_par *par, | |
166 | u16 y1, u16 y2) | |
167 | { | |
168 | int mode; | |
169 | ||
170 | if (par->update_mode < 0) { | |
171 | mode = AUOK190X_UPDATE_MODE(1); | |
172 | par->last_mode = -1; | |
173 | } else { | |
174 | mode = AUOK190X_UPDATE_MODE(par->update_mode); | |
175 | par->last_mode = par->update_mode; | |
176 | } | |
177 | ||
178 | if (par->flash) | |
179 | mode |= AUOK190X_UPDATE_NONFLASH; | |
180 | ||
181 | auok1901_update_region(par, mode, y1, y2); | |
182 | } | |
183 | ||
184 | static void auok1901fb_dpy_update(struct auok190xfb_par *par) | |
185 | { | |
186 | int mode; | |
187 | ||
188 | /* When doing full updates, wait for the controller to be ready | |
189 | * This will hopefully catch some hangs of the K1901 | |
190 | */ | |
191 | par->board->wait_for_rdy(par); | |
192 | ||
193 | if (par->update_mode < 0) { | |
194 | mode = AUOK190X_UPDATE_MODE(0); | |
195 | par->last_mode = -1; | |
196 | } else { | |
197 | mode = AUOK190X_UPDATE_MODE(par->update_mode); | |
198 | par->last_mode = par->update_mode; | |
199 | } | |
200 | ||
201 | if (par->flash) | |
202 | mode |= AUOK190X_UPDATE_NONFLASH; | |
203 | ||
204 | auok1901_update_region(par, mode, 0, par->info->var.yres); | |
205 | par->update_cnt = 0; | |
206 | } | |
207 | ||
208 | static bool auok1901fb_need_refresh(struct auok190xfb_par *par) | |
209 | { | |
210 | return (par->update_cnt > 10); | |
211 | } | |
212 | ||
48c68c4f | 213 | static int auok1901fb_probe(struct platform_device *pdev) |
53027cdf HS |
214 | { |
215 | struct auok190x_init_data init; | |
216 | struct auok190x_board *board; | |
217 | ||
218 | /* pick up board specific routines */ | |
219 | board = pdev->dev.platform_data; | |
220 | if (!board) | |
221 | return -EINVAL; | |
222 | ||
223 | /* fill temporary init struct for common init */ | |
224 | init.id = "auo_k1901fb"; | |
225 | init.board = board; | |
226 | init.update_partial = auok1901fb_dpy_update_pages; | |
227 | init.update_all = auok1901fb_dpy_update; | |
228 | init.need_refresh = auok1901fb_need_refresh; | |
229 | init.init = auok1901_init; | |
230 | ||
231 | return auok190x_common_probe(pdev, &init); | |
232 | } | |
233 | ||
48c68c4f | 234 | static int auok1901fb_remove(struct platform_device *pdev) |
53027cdf HS |
235 | { |
236 | return auok190x_common_remove(pdev); | |
237 | } | |
238 | ||
239 | static struct platform_driver auok1901fb_driver = { | |
240 | .probe = auok1901fb_probe, | |
48c68c4f | 241 | .remove = auok1901fb_remove, |
53027cdf HS |
242 | .driver = { |
243 | .owner = THIS_MODULE, | |
244 | .name = "auo_k1901fb", | |
245 | .pm = &auok190x_pm, | |
246 | }, | |
247 | }; | |
248 | module_platform_driver(auok1901fb_driver); | |
249 | ||
250 | MODULE_DESCRIPTION("framebuffer driver for the AUO-K1901 EPD controller"); | |
251 | MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>"); | |
252 | MODULE_LICENSE("GPL"); |