1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
69
70
71
72
73
74
75
76
77
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
87
88
89#define AUOK1901_INIT_RESOLUTION(_res) (((_res & (1 << 4)) << 6) \
90 | ((_res & 0xf) << 2))
91
92
93
94
95#define AUOK1901_DMA_ROTATE90(_rot) ((_rot & 1) << 13)
96
97
98
99
100#define AUOK1901_DDMA_ROTATE180(_rot) ((~_rot & 2) << 10)
101
102static void auok1901_init(struct auok190xfb_par *par)
103{
104 struct device *dev = par->info->device;
105 struct auok190x_board *board = par->board;
106 u16 init_param = 0;
107
108 pm_runtime_get_sync(dev);
109
110 init_param |= AUOK190X_INIT_INVERSE_WHITE;
111 init_param |= AUOK190X_INIT_FORMAT0;
112 init_param |= AUOK1901_INIT_RESOLUTION(par->resolution);
113 init_param |= AUOK190X_INIT_SHIFT_LEFT;
114
115 auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
116
117
118 board->wait_for_rdy(par);
119
120 pm_runtime_mark_last_busy(dev);
121 pm_runtime_put_autosuspend(dev);
122}
123
124static void auok1901_update_region(struct auok190xfb_par *par, int mode,
125 u16 y1, u16 y2)
126{
127 struct device *dev = par->info->device;
128 unsigned char *buf = (unsigned char *)par->info->screen_base;
129 int xres = par->info->var.xres;
130 int line_length = par->info->fix.line_length;
131 u16 args[5];
132
133 pm_runtime_get_sync(dev);
134
135 mutex_lock(&(par->io_lock));
136
137
138 y1 &= 0xfffe;
139 y2 &= 0xfffe;
140
141 dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
142 1, y1+1, xres, y2-y1, mode);
143
144
145 args[0] = AUOK1901_DMA_ROTATE90(par->rotation) | 1;
146 args[1] = y1 + 1;
147 args[2] = xres;
148 args[3] = y2 - y1;
149 buf += y1 * line_length;
150 auok190x_send_cmdargs_pixels_nowait(par, AUOK1901_CMD_DMA_START, 4,
151 args, ((y2 - y1) * line_length)/2,
152 (u16 *) buf);
153 auok190x_send_command_nowait(par, AUOK190X_CMD_DATA_STOP);
154
155
156 args[0] = mode | AUOK1901_DDMA_ROTATE180(par->rotation);
157 args[1] = 1;
158 args[2] = y1 + 1;
159 args[3] = xres;
160 args[4] = y2 - y1;
161 auok190x_send_cmdargs_nowait(par, AUOK1901_CMD_DDMA_START, 5, args);
162
163 par->update_cnt++;
164
165 mutex_unlock(&(par->io_lock));
166
167 pm_runtime_mark_last_busy(dev);
168 pm_runtime_put_autosuspend(dev);
169}
170
171static void auok1901fb_dpy_update_pages(struct auok190xfb_par *par,
172 u16 y1, u16 y2)
173{
174 int mode;
175
176 if (par->update_mode < 0) {
177 mode = AUOK190X_UPDATE_MODE(1);
178 par->last_mode = -1;
179 } else {
180 mode = AUOK190X_UPDATE_MODE(par->update_mode);
181 par->last_mode = par->update_mode;
182 }
183
184 if (par->flash)
185 mode |= AUOK190X_UPDATE_NONFLASH;
186
187 auok1901_update_region(par, mode, y1, y2);
188}
189
190static void auok1901fb_dpy_update(struct auok190xfb_par *par)
191{
192 int mode;
193
194
195
196
197 par->board->wait_for_rdy(par);
198
199 if (par->update_mode < 0) {
200 mode = AUOK190X_UPDATE_MODE(0);
201 par->last_mode = -1;
202 } else {
203 mode = AUOK190X_UPDATE_MODE(par->update_mode);
204 par->last_mode = par->update_mode;
205 }
206
207 if (par->flash)
208 mode |= AUOK190X_UPDATE_NONFLASH;
209
210 auok1901_update_region(par, mode, 0, par->info->var.yres);
211 par->update_cnt = 0;
212}
213
214static bool auok1901fb_need_refresh(struct auok190xfb_par *par)
215{
216 return (par->update_cnt > 10);
217}
218
219static int auok1901fb_probe(struct platform_device *pdev)
220{
221 struct auok190x_init_data init;
222 struct auok190x_board *board;
223
224
225 board = pdev->dev.platform_data;
226 if (!board)
227 return -EINVAL;
228
229
230 init.id = "auo_k1901fb";
231 init.board = board;
232 init.update_partial = auok1901fb_dpy_update_pages;
233 init.update_all = auok1901fb_dpy_update;
234 init.need_refresh = auok1901fb_need_refresh;
235 init.init = auok1901_init;
236
237 return auok190x_common_probe(pdev, &init);
238}
239
240static int auok1901fb_remove(struct platform_device *pdev)
241{
242 return auok190x_common_remove(pdev);
243}
244
245static struct platform_driver auok1901fb_driver = {
246 .probe = auok1901fb_probe,
247 .remove = auok1901fb_remove,
248 .driver = {
249 .name = "auo_k1901fb",
250 .pm = &auok190x_pm,
251 },
252};
253module_platform_driver(auok1901fb_driver);
254
255MODULE_DESCRIPTION("framebuffer driver for the AUO-K1901 EPD controller");
256MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
257MODULE_LICENSE("GPL");
258