[package] base-files: add an experimental "-c" flag which tries to preserve *all...
[openwrt.git] / target / linux / xburst / patches-2.6.34 / 440-metronome.patch
1 From c62dfb5d44444dd3add45e10c8950140dcb9f421 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Wed, 12 May 2010 14:24:46 +0200
4 Subject: [PATCH] metronome patches
5
6 ---
7 drivers/video/metronomefb.c | 788 +++++++++++++++++++++++++++++++++++++------
8 include/video/metronomefb.h | 33 ++-
9 2 files changed, 710 insertions(+), 111 deletions(-)
10
11 diff --git a/drivers/video/metronomefb.c b/drivers/video/metronomefb.c
12 index 9b3d6e4..719149e 100644
13 --- a/drivers/video/metronomefb.c
14 +++ b/drivers/video/metronomefb.c
15 @@ -18,11 +18,13 @@
16 * is provided as am200epd.c
17 *
18 */
19 +
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
24 #include <linux/mm.h>
25 +#include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 #include <linux/delay.h>
28 #include <linux/interrupt.h>
29 @@ -34,16 +36,25 @@
30 #include <linux/dma-mapping.h>
31 #include <linux/uaccess.h>
32 #include <linux/irq.h>
33 +#include <linux/ctype.h>
34
35 #include <video/metronomefb.h>
36
37 #include <asm/unaligned.h>
38
39 -/* Display specific information */
40 -#define DPY_W 832
41 -#define DPY_H 622
42 +/*
43 + * 12 is ok to avoid refreshing whole screen while small elements are changed,
44 + * while forcing full refresh if largish dialog boxes or menus are
45 + * shown/dismissed.
46 + */
47 +#define DEFAULT_MANUAL_REFRESH_THRESHOLD 12
48 +
49 +#define WF_MODE_INIT 0 /* Initialization */
50 +#define WF_MODE_MU 1 /* Monochrome update */
51 +#define WF_MODE_GU 2 /* Grayscale update */
52 +#define WF_MODE_GC 3 /* Grayscale clearing */
53
54 -static int user_wfm_size;
55 +static int temp = 25;
56
57 /* frame differs from image. frame includes non-visible pixels */
58 struct epd_frame {
59 @@ -53,7 +64,7 @@ struct epd_frame {
60 int wfm_size;
61 };
62
63 -static struct epd_frame epd_frame_table[] = {
64 +static const struct epd_frame epd_frame_table[] = {
65 {
66 .fw = 832,
67 .fh = 622,
68 @@ -97,24 +108,40 @@ static struct epd_frame epd_frame_table[] = {
69 },
70 .wfm_size = 46770,
71 },
72 + {
73 + .fw = 800,
74 + .fh = 600,
75 + .config = {
76 + 15 /* sdlew */
77 + | 2 << 8 /* sdosz */
78 + | 0 << 11 /* sdor */
79 + | 0 << 12 /* sdces */
80 + | 0 << 15, /* sdcer */
81 + 42 /* gdspl */
82 + | 1 << 8 /* gdr1 */
83 + | 1 << 9 /* sdshr */
84 + | 0 << 15, /* gdspp */
85 + 18 /* gdspw */
86 + | 0 << 15, /* dispc */
87 + 599 /* vdlc */
88 + | 0 << 11 /* dsi */
89 + | 0 << 12, /* dsic */
90 + },
91 + .wfm_size = 46901,
92 + },
93 };
94
95 -static struct fb_fix_screeninfo metronomefb_fix __devinitdata = {
96 +static const struct fb_fix_screeninfo metronomefb_fix __devinitconst = {
97 .id = "metronomefb",
98 .type = FB_TYPE_PACKED_PIXELS,
99 .visual = FB_VISUAL_STATIC_PSEUDOCOLOR,
100 .xpanstep = 0,
101 .ypanstep = 0,
102 .ywrapstep = 0,
103 - .line_length = DPY_W,
104 .accel = FB_ACCEL_NONE,
105 };
106
107 -static struct fb_var_screeninfo metronomefb_var __devinitdata = {
108 - .xres = DPY_W,
109 - .yres = DPY_H,
110 - .xres_virtual = DPY_W,
111 - .yres_virtual = DPY_H,
112 +static const struct fb_var_screeninfo metronomefb_var __devinitconst = {
113 .bits_per_pixel = 8,
114 .grayscale = 1,
115 .nonstd = 1,
116 @@ -167,7 +194,7 @@ static u16 calc_img_cksum(u16 *start, int length)
117 }
118
119 /* here we decode the incoming waveform file and populate metromem */
120 -static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
121 +static int load_waveform(u8 *mem, size_t size, int m, int t,
122 struct metronomefb_par *par)
123 {
124 int tta;
125 @@ -181,16 +208,12 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
126 int mem_idx = 0;
127 struct waveform_hdr *wfm_hdr;
128 u8 *metromem = par->metromem_wfm;
129 - struct device *dev = par->info->dev;
130 + struct device *dev = &par->pdev->dev;
131 + u8 mc, trc;
132 + u16 *p;
133 + u16 img_cksum;
134
135 - if (user_wfm_size)
136 - epd_frame_table[par->dt].wfm_size = user_wfm_size;
137 -
138 - if (size != epd_frame_table[par->dt].wfm_size) {
139 - dev_err(dev, "Error: unexpected size %Zd != %d\n", size,
140 - epd_frame_table[par->dt].wfm_size);
141 - return -EINVAL;
142 - }
143 + dev_dbg(dev, "Loading waveforms, mode %d, temperature %d\n", m, t);
144
145 wfm_hdr = (struct waveform_hdr *) mem;
146
147 @@ -208,8 +231,9 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
148 wfm_hdr->wfm_cs);
149 return -EINVAL;
150 }
151 - wfm_hdr->mc += 1;
152 - wfm_hdr->trc += 1;
153 + mc = wfm_hdr->mc + 1;
154 + trc = wfm_hdr->trc + 1;
155 +
156 for (i = 0; i < 5; i++) {
157 if (*(wfm_hdr->stuff2a + i) != 0) {
158 dev_err(dev, "Error: unexpected value in padding\n");
159 @@ -221,10 +245,10 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
160 the waveform. presumably selecting the right one for the
161 desired temperature. it works out the offset of the first
162 v that exceeds the specified temperature */
163 - if ((sizeof(*wfm_hdr) + wfm_hdr->trc) > size)
164 + if ((sizeof(*wfm_hdr) + trc) > size)
165 return -EINVAL;
166
167 - for (i = sizeof(*wfm_hdr); i <= sizeof(*wfm_hdr) + wfm_hdr->trc; i++) {
168 + for (i = sizeof(*wfm_hdr); i <= sizeof(*wfm_hdr) + trc; i++) {
169 if (mem[i] > t) {
170 trn = i - sizeof(*wfm_hdr) - 1;
171 break;
172 @@ -232,7 +256,7 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
173 }
174
175 /* check temperature range table checksum */
176 - cksum_idx = sizeof(*wfm_hdr) + wfm_hdr->trc + 1;
177 + cksum_idx = sizeof(*wfm_hdr) + trc + 1;
178 if (cksum_idx > size)
179 return -EINVAL;
180 cksum = calc_cksum(sizeof(*wfm_hdr), cksum_idx, mem);
181 @@ -294,6 +318,7 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
182 cksum_idx = wfm_idx;
183 if (cksum_idx > size)
184 return -EINVAL;
185 + dev_dbg(dev, "mem_idx = %u\n", mem_idx);
186 cksum = calc_cksum(owfm_idx, cksum_idx, mem);
187 if (cksum != mem[cksum_idx]) {
188 dev_err(dev, "Error: bad waveform data cksum"
189 @@ -302,16 +327,47 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
190 }
191 par->frame_count = (mem_idx/64);
192
193 + p = (u16 *)par->metromem_wfm;
194 + img_cksum = calc_img_cksum(p, 16384 / 2);
195 + p[16384 / 2] = __cpu_to_le16(img_cksum);
196 +
197 + par->current_wf_mode = m;
198 + par->current_wf_temp = t;
199 +
200 return 0;
201 }
202
203 +static int check_err(struct metronomefb_par *par)
204 +{
205 + int res;
206 +
207 + res = par->board->get_err(par);
208 + dev_dbg(&par->pdev->dev, "ERR = %d\n", res);
209 + return res;
210 +}
211 +
212 +static inline int wait_for_rdy(struct metronomefb_par *par)
213 +{
214 + int res = 0;
215 +
216 + if (!par->board->get_rdy(par))
217 + res = par->board->met_wait_event_intr(par);
218 +
219 + return res;
220 +}
221 +
222 static int metronome_display_cmd(struct metronomefb_par *par)
223 {
224 int i;
225 u16 cs;
226 u16 opcode;
227 - static u8 borderval;
228 + int res;
229 +
230 + res = wait_for_rdy(par);
231 + if (res)
232 + return res;
233
234 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
235 /* setup display command
236 we can't immediately set the opcode since the controller
237 will try parse the command before we've set it all up
238 @@ -324,8 +380,9 @@ static int metronome_display_cmd(struct metronomefb_par *par)
239
240 /* set the args ( 2 bytes ) for display */
241 i = 0;
242 - par->metromem_cmd->args[i] = 1 << 3 /* border update */
243 - | ((borderval++ % 4) & 0x0F) << 4
244 + par->metromem_cmd->args[i] = 0 << 3 /* border update */
245 + | (3 << 4)
246 +// | ((borderval++ % 4) & 0x0F) << 4
247 | (par->frame_count - 1) << 8;
248 cs += par->metromem_cmd->args[i++];
249
250 @@ -335,21 +392,25 @@ static int metronome_display_cmd(struct metronomefb_par *par)
251 par->metromem_cmd->csum = cs;
252 par->metromem_cmd->opcode = opcode; /* display cmd */
253
254 - return par->board->met_wait_event_intr(par);
255 + return 0;
256 +
257 }
258
259 static int __devinit metronome_powerup_cmd(struct metronomefb_par *par)
260 {
261 int i;
262 u16 cs;
263 + int res;
264
265 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
266 /* setup power up command */
267 par->metromem_cmd->opcode = 0x1234; /* pwr up pseudo cmd */
268 cs = par->metromem_cmd->opcode;
269
270 /* set pwr1,2,3 to 1024 */
271 for (i = 0; i < 3; i++) {
272 - par->metromem_cmd->args[i] = 1024;
273 +// par->metromem_cmd->args[i] = 1024;
274 + par->metromem_cmd->args[i] = 100;
275 cs += par->metromem_cmd->args[i];
276 }
277
278 @@ -364,7 +425,9 @@ static int __devinit metronome_powerup_cmd(struct metronomefb_par *par)
279 msleep(1);
280 par->board->set_stdby(par, 1);
281
282 - return par->board->met_wait_event(par);
283 + res = par->board->met_wait_event(par);
284 + dev_dbg(&par->pdev->dev, "%s: EXIT: %d\n", __func__, res);
285 + return res;
286 }
287
288 static int __devinit metronome_config_cmd(struct metronomefb_par *par)
289 @@ -373,8 +436,9 @@ static int __devinit metronome_config_cmd(struct metronomefb_par *par)
290 we can't immediately set the opcode since the controller
291 will try parse the command before we've set it all up */
292
293 - memcpy(par->metromem_cmd->args, epd_frame_table[par->dt].config,
294 - sizeof(epd_frame_table[par->dt].config));
295 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
296 + memcpy(par->metromem_cmd->args, par->epd_frame->config,
297 + sizeof(par->epd_frame->config));
298 /* the rest are 0 */
299 memset((u8 *) (par->metromem_cmd->args + 4), 0, (32-4)*2);
300
301 @@ -395,11 +459,12 @@ static int __devinit metronome_init_cmd(struct metronomefb_par *par)
302 will try parse the command before we've set it all up
303 so we just set cs here and set the opcode at the end */
304
305 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
306 cs = 0xCC20;
307
308 /* set the args ( 2 bytes ) for init */
309 i = 0;
310 - par->metromem_cmd->args[i] = 0;
311 + par->metromem_cmd->args[i] = 0x0007;
312 cs += par->metromem_cmd->args[i++];
313
314 /* the rest are 0 */
315 @@ -411,76 +476,268 @@ static int __devinit metronome_init_cmd(struct metronomefb_par *par)
316 return par->board->met_wait_event(par);
317 }
318
319 -static int __devinit metronome_init_regs(struct metronomefb_par *par)
320 +static int metronome_bootup(struct metronomefb_par *par)
321 {
322 int res;
323
324 - res = par->board->setup_io(par);
325 - if (res)
326 - return res;
327 -
328 res = metronome_powerup_cmd(par);
329 - if (res)
330 - return res;
331 + if (res) {
332 + dev_err(&par->pdev->dev, "metronomefb: POWERUP cmd failed\n");
333 + goto finish;
334 + }
335
336 + check_err(par);
337 res = metronome_config_cmd(par);
338 - if (res)
339 - return res;
340 + if (res) {
341 + dev_err(&par->pdev->dev, "metronomefb: CONFIG cmd failed\n");
342 + goto finish;
343 + }
344 + check_err(par);
345
346 res = metronome_init_cmd(par);
347 + if (res)
348 + dev_err(&par->pdev->dev, "metronomefb: INIT cmd failed\n");
349 + check_err(par);
350 +
351 +finish:
352 + return res;
353 +}
354 +
355 +static int __devinit metronome_init_regs(struct metronomefb_par *par)
356 +{
357 + int res;
358 +
359 + if (par->board->power_ctl)
360 + par->board->power_ctl(par, METRONOME_POWER_ON);
361 +
362 + res = metronome_bootup(par);
363
364 return res;
365 }
366
367 -static void metronomefb_dpy_update(struct metronomefb_par *par)
368 +static uint16_t metronomefb_update_img_buffer_rotated(struct metronomefb_par *par)
369 {
370 - int fbsize;
371 - u16 cksum;
372 - unsigned char *buf = (unsigned char __force *)par->info->screen_base;
373 + int x, y;
374 + int xstep, ystep;
375 + int i, j;
376 + uint16_t cksum = 0;
377 + uint8_t *buf = par->info->screen_base;
378 + uint32_t *img = (uint32_t *)(par->metromem_img);
379 + int fw = par->epd_frame->fw;
380 + int fh = par->epd_frame->fh;
381 + int fw_buf = fw / 4;
382 + uint32_t *fxbuckets = par->fxbuckets;
383 + uint32_t *fybuckets = par->fybuckets;
384 + uint32_t diff;
385 + uint32_t tmp;
386 +
387 + switch (par->rotation) {
388 + case FB_ROTATE_CW:
389 + xstep = -fh;
390 + ystep = fw * fh + 1;
391 + j = (fw - 1) * fh;
392 + break;
393 + case FB_ROTATE_UD:
394 + xstep = -1;
395 + ystep = 0;
396 + j = fw * fh - 1;
397 + break;
398 + case FB_ROTATE_CCW:
399 + xstep = fh;
400 + ystep = -fw * fh - 1;
401 + j = fh - 1;
402 + break;
403 + default:
404 + BUG();
405 + break;
406 + }
407 +
408 + memset(fxbuckets, 0, fw_buf * sizeof(*fxbuckets));
409 + memset(fybuckets, 0, fh * sizeof(*fybuckets));
410
411 - fbsize = par->info->fix.smem_len;
412 - /* copy from vm to metromem */
413 - memcpy(par->metromem_img, buf, fbsize);
414 + i = 0;
415 + for (y = 0; y < fh; y++) {
416 + for(x = 0; x < fw_buf; x++, i++) {
417 + tmp = (buf[j] << 5);
418 + j += xstep;
419 + tmp |= (buf[j] << 13);
420 + j += xstep;
421 + tmp |= (buf[j] << 21);
422 + j += xstep;
423 + tmp |= (buf[j] << 29);
424 + j += xstep;
425 + tmp &= 0xe0e0e0e0;
426 +
427 + img[i] &= 0xf0f0f0f0;
428 + diff = img[i] ^ tmp;
429 +
430 + fxbuckets[x] |= diff;
431 + fybuckets[y] |= diff;
432 +
433 + img[i] = (img[i] >> 4) | tmp;
434 + cksum += img[i] & 0x0000ffff;
435 + cksum += (img[i] >> 16);
436
437 - cksum = calc_img_cksum((u16 *) par->metromem_img, fbsize/2);
438 - *((u16 *)(par->metromem_img) + fbsize/2) = cksum;
439 - metronome_display_cmd(par);
440 + }
441 + j += ystep;
442 + }
443 +
444 + return cksum;
445 }
446
447 -static u16 metronomefb_dpy_update_page(struct metronomefb_par *par, int index)
448 +static uint16_t metronomefb_update_img_buffer_normal(struct metronomefb_par *par)
449 {
450 - int i;
451 - u16 csum = 0;
452 - u16 *buf = (u16 __force *)(par->info->screen_base + index);
453 - u16 *img = (u16 *)(par->metromem_img + index);
454 + int x, y, i;
455 + uint16_t cksum = 0;
456 + uint32_t *buf = (uint32_t __force *)par->info->screen_base;
457 + uint32_t *img = (uint32_t *)(par->metromem_img);
458 + uint32_t diff;
459 + uint32_t tmp;
460 + int fw = par->epd_frame->fw;
461 + int fh = par->epd_frame->fh;
462 + int fw_buf = fw / sizeof(*buf);
463 + uint32_t *fxbuckets = par->fxbuckets;
464 + uint32_t *fybuckets = par->fybuckets;
465 +
466 + memset(fxbuckets, 0, fw_buf * sizeof(*fxbuckets));
467 + memset(fybuckets, 0, fh * sizeof(*fybuckets));
468 +
469 + i = 0;
470 + for (y = 0; y < fh; y++) {
471 + for(x = 0; x < fw_buf; x++, i++) {
472 + tmp = (buf[i] << 5) & 0xe0e0e0e0;
473 + img[i] &= 0xf0f0f0f0;
474 + diff = img[i] ^ tmp;
475 +
476 + fxbuckets[x] |= diff;
477 + fybuckets[y] |= diff;
478 +
479 + img[i] = (img[i] >> 4) | tmp;
480 + cksum += img[i] & 0x0000ffff;
481 + cksum += (img[i] >> 16);
482 + }
483 + }
484 +
485 + return cksum;
486 +}
487 +
488 +static unsigned int metronomefb_get_change_count(struct metronomefb_par *par)
489 +{
490 + int min_x;
491 + int max_x;
492 + int min_y;
493 + int max_y;
494 + int fw = par->epd_frame->fw / 4;
495 + int fh = par->epd_frame->fh;
496 + unsigned int change_count;
497 + uint32_t *fxbuckets = par->fxbuckets;
498 + uint32_t *fybuckets = par->fybuckets;
499 +
500 + for (min_x = 0; min_x < fw; ++min_x) {
501 + if(fxbuckets[min_x])
502 + break;
503 + }
504 +
505 + for (max_x = fw - 1; max_x >= 0; --max_x) {
506 + if(fxbuckets[max_x])
507 + break;
508 + }
509 +
510 + for (min_y = 0; min_y < fh; min_y++) {
511 + if(fybuckets[min_y])
512 + break;
513 + }
514
515 - /* swizzle from vm to metromem and recalc cksum at the same time*/
516 - for (i = 0; i < PAGE_SIZE/2; i++) {
517 - *(img + i) = (buf[i] << 5) & 0xE0E0;
518 - csum += *(img + i);
519 + for (max_y = fh - 1; max_y >= 0; --max_y) {
520 + if(fybuckets[max_y])
521 + break;
522 }
523 - return csum;
524 +
525 + if ((min_x > max_x) || (min_y > max_y))
526 + change_count = 0;
527 + else
528 + change_count = (max_x - min_x + 1) * (max_y - min_y + 1) * 4;
529 +
530 + dev_dbg(&par->pdev->dev, "min_x = %d, max_x = %d, min_y = %d, max_y = %d\n",
531 + min_x, max_x, min_y, max_y);
532 +
533 + return change_count;
534 +}
535 +
536 +static void metronomefb_dpy_update(struct metronomefb_par *par, int clear_all)
537 +{
538 + unsigned int fbsize = par->info->fix.smem_len;
539 + uint16_t cksum;
540 + int m;
541 +
542 + wait_for_rdy(par);
543 +
544 + if (par->rotation == 0)
545 + cksum = metronomefb_update_img_buffer_normal(par);
546 + else
547 + cksum = metronomefb_update_img_buffer_rotated(par);
548 +
549 + *par->metromem_img_csum = __cpu_to_le16(cksum);
550 +
551 + if (clear_all || par->is_first_update ||
552 + (par->partial_updates_count == par->partial_autorefresh_interval)) {
553 + m = WF_MODE_GC;
554 + par->partial_updates_count = 0;
555 + } else {
556 + int change_count = metronomefb_get_change_count(par);
557 + if (change_count < fbsize / 100 * par->manual_refresh_threshold)
558 + m = WF_MODE_GU;
559 + else
560 + m = WF_MODE_GC;
561 +
562 + dev_dbg(&par->pdev->dev, "change_count = %u, treshold = %u%% (%u pixels)\n",
563 + change_count, par->manual_refresh_threshold,
564 + fbsize / 100 * par->manual_refresh_threshold);
565 + ++par->partial_updates_count;
566 + }
567 +
568 + if (m != par->current_wf_mode)
569 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
570 + m, par->current_wf_temp, par);
571 +
572 + for (;;) {
573 + if (likely(!check_err(par))) {
574 + metronome_display_cmd(par);
575 + break;
576 + }
577 +
578 + par->board->set_stdby(par, 0);
579 + dev_warn(&par->pdev->dev, "Resetting Metronome\n");
580 + par->board->set_rst(par, 0);
581 + mdelay(1);
582 + if (par->board->power_ctl)
583 + par->board->power_ctl(par, METRONOME_POWER_OFF);
584 +
585 + mdelay(1);
586 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
587 + WF_MODE_GC, par->current_wf_temp, par);
588 +
589 + if (par->board->power_ctl)
590 + par->board->power_ctl(par, METRONOME_POWER_ON);
591 + metronome_bootup(par);
592 + }
593 +
594 + par->is_first_update = 0;
595 }
596
597 /* this is called back from the deferred io workqueue */
598 static void metronomefb_dpy_deferred_io(struct fb_info *info,
599 struct list_head *pagelist)
600 {
601 - u16 cksum;
602 - struct page *cur;
603 - struct fb_deferred_io *fbdefio = info->fbdefio;
604 struct metronomefb_par *par = info->par;
605
606 - /* walk the written page list and swizzle the data */
607 - list_for_each_entry(cur, &fbdefio->pagelist, lru) {
608 - cksum = metronomefb_dpy_update_page(par,
609 - (cur->index << PAGE_SHIFT));
610 - par->metromem_img_csum -= par->csum_table[cur->index];
611 - par->csum_table[cur->index] = cksum;
612 - par->metromem_img_csum += cksum;
613 - }
614 -
615 - metronome_display_cmd(par);
616 + /* We will update entire display because we need to change
617 + * 'previous image' field in pixels which was changed at
618 + * previous refresh
619 + */
620 + mutex_lock(&par->lock);
621 + metronomefb_dpy_update(par, 0);
622 + mutex_unlock(&par->lock);
623 }
624
625 static void metronomefb_fillrect(struct fb_info *info,
626 @@ -488,8 +745,10 @@ static void metronomefb_fillrect(struct fb_info *info,
627 {
628 struct metronomefb_par *par = info->par;
629
630 + mutex_lock(&par->lock);
631 sys_fillrect(info, rect);
632 - metronomefb_dpy_update(par);
633 + metronomefb_dpy_update(par, 0);
634 + mutex_unlock(&par->lock);
635 }
636
637 static void metronomefb_copyarea(struct fb_info *info,
638 @@ -497,8 +756,10 @@ static void metronomefb_copyarea(struct fb_info *info,
639 {
640 struct metronomefb_par *par = info->par;
641
642 + mutex_lock(&par->lock);
643 sys_copyarea(info, area);
644 - metronomefb_dpy_update(par);
645 + metronomefb_dpy_update(par, 0);
646 + mutex_unlock(&par->lock);
647 }
648
649 static void metronomefb_imageblit(struct fb_info *info,
650 @@ -506,8 +767,10 @@ static void metronomefb_imageblit(struct fb_info *info,
651 {
652 struct metronomefb_par *par = info->par;
653
654 + mutex_lock(&par->lock);
655 sys_imageblit(info, image);
656 - metronomefb_dpy_update(par);
657 + metronomefb_dpy_update(par, 0);
658 + mutex_unlock(&par->lock);
659 }
660
661 /*
662 @@ -545,30 +808,229 @@ static ssize_t metronomefb_write(struct fb_info *info, const char __user *buf,
663
664 dst = (void __force *)(info->screen_base + p);
665
666 + mutex_lock(&par->lock);
667 +
668 if (copy_from_user(dst, buf, count))
669 err = -EFAULT;
670
671 if (!err)
672 *ppos += count;
673
674 - metronomefb_dpy_update(par);
675 + metronomefb_dpy_update(par, 0);
676 + mutex_unlock(&par->lock);
677
678 return (err) ? err : count;
679 }
680
681 +static int metronome_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
682 +{
683 + struct metronomefb_par *par = info->par;
684 +
685 + var->grayscale = 1;
686 +
687 + switch (par->rotation) {
688 + case FB_ROTATE_CW:
689 + case FB_ROTATE_CCW:
690 + if (par->epd_frame->fw == var->yres && par->epd_frame->fh == var->xres)
691 + return 0;
692 + break;
693 + case FB_ROTATE_UD:
694 + default:
695 + if (par->epd_frame->fw == var->xres && par->epd_frame->fh == var->yres)
696 + return 0;
697 + break;
698 + }
699 +
700 + return -EINVAL;
701 +}
702 +
703 +static int metronomefb_set_par(struct fb_info *info)
704 +{
705 + struct metronomefb_par *par = info->par;
706 +
707 + par->rotation = (par->board->panel_rotation + info->var.rotate) % 4;
708 +
709 + switch (par->rotation) {
710 + case FB_ROTATE_CW:
711 + case FB_ROTATE_CCW:
712 + info->fix.line_length = par->epd_frame->fh;
713 + break;
714 + case FB_ROTATE_UD:
715 + default:
716 + info->fix.line_length = par->epd_frame->fw;
717 + break;
718 + }
719 +
720 + mutex_lock(&par->lock);
721 + metronomefb_dpy_update(info->par, 1);
722 + mutex_unlock(&par->lock);
723 +
724 + return 0;
725 +}
726 +
727 static struct fb_ops metronomefb_ops = {
728 .owner = THIS_MODULE,
729 .fb_write = metronomefb_write,
730 .fb_fillrect = metronomefb_fillrect,
731 .fb_copyarea = metronomefb_copyarea,
732 .fb_imageblit = metronomefb_imageblit,
733 + .fb_check_var = metronome_check_var,
734 + .fb_set_par = metronomefb_set_par,
735 };
736
737 static struct fb_deferred_io metronomefb_defio = {
738 - .delay = HZ,
739 + .delay = HZ / 4,
740 .deferred_io = metronomefb_dpy_deferred_io,
741 };
742
743 +static ssize_t metronomefb_defio_delay_show(struct device *dev,
744 + struct device_attribute *attr, char *buf)
745 +{
746 + struct fb_info *info = dev_get_drvdata(dev);
747 +
748 + sprintf(buf, "%lu\n", info->fbdefio->delay * 1000 / HZ);
749 + return strlen(buf) + 1;
750 +}
751 +
752 +static ssize_t metronomefb_defio_delay_store(struct device *dev,
753 + struct device_attribute *attr, const char *buf, size_t size)
754 +{
755 + struct fb_info *info = dev_get_drvdata(dev);
756 + char *after;
757 + unsigned long state = simple_strtoul(buf, &after, 10);
758 + size_t count = after - buf;
759 + ssize_t ret = -EINVAL;
760 +
761 + if (*after && isspace(*after))
762 + count++;
763 +
764 + state = state * HZ / 1000;
765 +
766 + if (!state)
767 + state = 1;
768 +
769 + if (count == size) {
770 + ret = count;
771 + info->fbdefio->delay = state;
772 + }
773 +
774 + return ret;
775 +}
776 +
777 +static ssize_t metronomefb_manual_refresh_thr_show(struct device *dev,
778 + struct device_attribute *attr, char *buf)
779 +{
780 + struct fb_info *info = dev_get_drvdata(dev);
781 + struct metronomefb_par *par = info->par;
782 +
783 + return sprintf(buf, "%u\n", par->manual_refresh_threshold);
784 +}
785 +
786 +static ssize_t metronomefb_manual_refresh_thr_store(struct device *dev,
787 + struct device_attribute *attr, const char *buf, size_t size)
788 +{
789 + struct fb_info *info = dev_get_drvdata(dev);
790 + struct metronomefb_par *par = info->par;
791 + char *after;
792 + unsigned long val = simple_strtoul(buf, &after, 10);
793 + size_t count = after - buf;
794 + ssize_t ret = -EINVAL;
795 +
796 + if (*after && isspace(*after))
797 + count++;
798 +
799 + if (val > 100)
800 + return -EINVAL;
801 +
802 +
803 + if (count == size) {
804 + ret = count;
805 + par->manual_refresh_threshold = val;
806 + }
807 +
808 + return ret;
809 +}
810 +
811 +static ssize_t metronomefb_autorefresh_interval_show(struct device *dev,
812 + struct device_attribute *attr, char *buf)
813 +{
814 + struct fb_info *info = dev_get_drvdata(dev);
815 + struct metronomefb_par *par = info->par;
816 +
817 + return sprintf(buf, "%u\n", par->partial_autorefresh_interval);
818 +}
819 +
820 +static ssize_t metronomefb_autorefresh_interval_store(struct device *dev,
821 + struct device_attribute *attr, const char *buf, size_t size)
822 +{
823 + struct fb_info *info = dev_get_drvdata(dev);
824 + struct metronomefb_par *par = info->par;
825 + char *after;
826 + unsigned long val = simple_strtoul(buf, &after, 10);
827 + size_t count = after - buf;
828 + ssize_t ret = -EINVAL;
829 +
830 + if (*after && isspace(*after))
831 + count++;
832 +
833 + if (val > 100)
834 + return -EINVAL;
835 +
836 +
837 + if (count == size) {
838 + ret = count;
839 + par->partial_autorefresh_interval = val;
840 + }
841 +
842 + return ret;
843 +}
844 +
845 +static ssize_t metronomefb_temp_show(struct device *dev,
846 + struct device_attribute *attr, char *buf)
847 +{
848 + struct fb_info *info = dev_get_drvdata(dev);
849 + struct metronomefb_par *par = info->par;
850 +
851 + return sprintf(buf, "%u\n", par->current_wf_temp);
852 +}
853 +
854 +static ssize_t metronomefb_temp_store(struct device *dev,
855 + struct device_attribute *attr, const char *buf, size_t size)
856 +{
857 + struct fb_info *info = dev_get_drvdata(dev);
858 + struct metronomefb_par *par = info->par;
859 + char *after;
860 + unsigned long val = simple_strtoul(buf, &after, 10);
861 + size_t count = after - buf;
862 + ssize_t ret = -EINVAL;
863 +
864 + if (*after && isspace(*after))
865 + count++;
866 +
867 + if (val > 100)
868 + return -EINVAL;
869 +
870 +
871 + if (count == size) {
872 + ret = count;
873 + if (val != par->current_wf_temp)
874 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
875 + par->current_wf_mode, val, par);
876 + }
877 +
878 + return ret;
879 +}
880 +
881 +DEVICE_ATTR(defio_delay, 0644,
882 + metronomefb_defio_delay_show, metronomefb_defio_delay_store);
883 +DEVICE_ATTR(manual_refresh_threshold, 0644,
884 + metronomefb_manual_refresh_thr_show, metronomefb_manual_refresh_thr_store);
885 +DEVICE_ATTR(temp, 0644,
886 + metronomefb_temp_show, metronomefb_temp_store);
887 +DEVICE_ATTR(autorefresh_interval, 0644,
888 + metronomefb_autorefresh_interval_show, metronomefb_autorefresh_interval_store);
889 +
890 +
891 static int __devinit metronomefb_probe(struct platform_device *dev)
892 {
893 struct fb_info *info;
894 @@ -607,6 +1069,9 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
895
896 panel_type = board->get_panel_type();
897 switch (panel_type) {
898 + case 5:
899 + epd_dt_index = 3;
900 + break;
901 case 6:
902 epd_dt_index = 0;
903 break;
904 @@ -632,29 +1097,59 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
905 if (!videomemory)
906 goto err_fb_rel;
907
908 - memset(videomemory, 0, videomemorysize);
909 + memset(videomemory, 0xff, videomemorysize);
910
911 info->screen_base = (char __force __iomem *)videomemory;
912 info->fbops = &metronomefb_ops;
913
914 - metronomefb_fix.line_length = fw;
915 - metronomefb_var.xres = fw;
916 - metronomefb_var.yres = fh;
917 - metronomefb_var.xres_virtual = fw;
918 - metronomefb_var.yres_virtual = fh;
919 info->var = metronomefb_var;
920 info->fix = metronomefb_fix;
921 - info->fix.smem_len = videomemorysize;
922 + switch (board->panel_rotation) {
923 + case FB_ROTATE_CW:
924 + case FB_ROTATE_CCW:
925 + info->var.xres = fh;
926 + info->var.yres = fw;
927 + info->var.xres_virtual = fh;
928 + info->var.yres_virtual = fw;
929 + info->fix.line_length = fh;
930 + break;
931 + case FB_ROTATE_UD:
932 + default:
933 + info->var.xres = fw;
934 + info->var.yres = fh;
935 + info->var.xres_virtual = fw;
936 + info->var.yres_virtual = fh;
937 + info->fix.line_length = fw;
938 + break;
939 + }
940 + info->fix.smem_len = fw * fh; /* Real size of image area */
941 par = info->par;
942 par->info = info;
943 par->board = board;
944 - par->dt = epd_dt_index;
945 + par->epd_frame = &epd_frame_table[epd_dt_index];
946 + par->pdev = dev;
947 +
948 + par->rotation = board->panel_rotation;
949 +
950 + par->fxbuckets = kmalloc((fw / 4 + 1) * sizeof(*par->fxbuckets), GFP_KERNEL);
951 + if (!par->fxbuckets)
952 + goto err_vfree;
953 +
954 + par->fybuckets = kmalloc(fh * sizeof(*par->fybuckets), GFP_KERNEL);
955 + if (!par->fybuckets)
956 + goto err_fxbuckets;
957 +
958 init_waitqueue_head(&par->waitq);
959 + par->manual_refresh_threshold = DEFAULT_MANUAL_REFRESH_THRESHOLD;
960 + par->partial_autorefresh_interval = 256;
961 + par->partial_updates_count = 0;
962 + par->is_first_update = 1;
963 + mutex_init(&par->lock);
964
965 /* this table caches per page csum values. */
966 par->csum_table = vmalloc(videomemorysize/PAGE_SIZE);
967 if (!par->csum_table)
968 - goto err_vfree;
969 + goto err_fybuckets;
970
971 /* the physical framebuffer that we use is setup by
972 * the platform device driver. It will provide us
973 @@ -684,13 +1179,19 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
974 goto err_csum_table;
975 }
976
977 - retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, 3, 31,
978 + retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, WF_MODE_GC, temp,
979 par);
980 - release_firmware(fw_entry);
981 if (retval < 0) {
982 dev_err(&dev->dev, "Failed processing waveform\n");
983 goto err_csum_table;
984 }
985 + par->firmware = fw_entry;
986 +
987 + retval = board->setup_io(par);
988 + if (retval) {
989 + dev_err(&dev->dev, "metronomefb: setup_io() failed\n");
990 + goto err_csum_table;
991 + }
992
993 if (board->setup_irq(info))
994 goto err_csum_table;
995 @@ -712,7 +1213,7 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
996
997 /* set cmap */
998 for (i = 0; i < 8; i++)
999 - info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16;
1000 + info->cmap.red[i] = ((2 * i + 1)*(0xFFFF))/16;
1001 memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8);
1002 memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);
1003
1004 @@ -722,18 +1223,47 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
1005
1006 platform_set_drvdata(dev, info);
1007
1008 - dev_dbg(&dev->dev,
1009 + retval = device_create_file(info->dev, &dev_attr_defio_delay);
1010 + if (retval)
1011 + goto err_devattr_defio_delay;
1012 +
1013 + retval = device_create_file(info->dev, &dev_attr_manual_refresh_threshold);
1014 + if (retval)
1015 + goto err_devattr_manual_refresh_thr;
1016 +
1017 + retval = device_create_file(info->dev, &dev_attr_temp);
1018 + if (retval)
1019 + goto err_devattr_temp;
1020 +
1021 + retval = device_create_file(info->dev, &dev_attr_autorefresh_interval);
1022 + if (retval)
1023 + goto err_devattr_autorefresh;
1024 +
1025 + dev_info(&dev->dev,
1026 "fb%d: Metronome frame buffer device, using %dK of video"
1027 " memory\n", info->node, videomemorysize >> 10);
1028
1029 return 0;
1030
1031 + device_remove_file(info->dev, &dev_attr_autorefresh_interval);
1032 +err_devattr_autorefresh:
1033 + device_remove_file(info->dev, &dev_attr_temp);
1034 +err_devattr_temp:
1035 + device_remove_file(info->dev, &dev_attr_manual_refresh_threshold);
1036 +err_devattr_manual_refresh_thr:
1037 + device_remove_file(info->dev, &dev_attr_defio_delay);
1038 +err_devattr_defio_delay:
1039 + unregister_framebuffer(info);
1040 err_cmap:
1041 fb_dealloc_cmap(&info->cmap);
1042 err_free_irq:
1043 board->cleanup(par);
1044 err_csum_table:
1045 vfree(par->csum_table);
1046 +err_fybuckets:
1047 + kfree(par->fybuckets);
1048 +err_fxbuckets:
1049 + kfree(par->fxbuckets);
1050 err_vfree:
1051 vfree(videomemory);
1052 err_fb_rel:
1053 @@ -750,26 +1280,76 @@ static int __devexit metronomefb_remove(struct platform_device *dev)
1054 if (info) {
1055 struct metronomefb_par *par = info->par;
1056
1057 + par->board->set_stdby(par, 0);
1058 + mdelay(1);
1059 + if (par->board->power_ctl)
1060 + par->board->power_ctl(par, METRONOME_POWER_OFF);
1061 +
1062 + device_remove_file(info->dev, &dev_attr_autorefresh_interval);
1063 + device_remove_file(info->dev, &dev_attr_temp);
1064 + device_remove_file(info->dev, &dev_attr_manual_refresh_threshold);
1065 + device_remove_file(info->dev, &dev_attr_defio_delay);
1066 unregister_framebuffer(info);
1067 fb_deferred_io_cleanup(info);
1068 fb_dealloc_cmap(&info->cmap);
1069 par->board->cleanup(par);
1070 vfree(par->csum_table);
1071 + kfree(par->fybuckets);
1072 + kfree(par->fxbuckets);
1073 vfree((void __force *)info->screen_base);
1074 module_put(par->board->owner);
1075 + release_firmware(par->firmware);
1076 dev_dbg(&dev->dev, "calling release\n");
1077 framebuffer_release(info);
1078 }
1079 return 0;
1080 }
1081
1082 +#ifdef CONFIG_PM
1083 +static int metronomefb_suspend(struct platform_device *pdev, pm_message_t message)
1084 +{
1085 + struct fb_info *info = platform_get_drvdata(pdev);
1086 + struct metronomefb_par *par = info->par;
1087 +
1088 + par->board->set_stdby(par, 0);
1089 + par->board->set_rst(par, 0);
1090 + if (par->board->power_ctl)
1091 + par->board->power_ctl(par, METRONOME_POWER_OFF);
1092 +
1093 +
1094 + return 0;
1095 +}
1096 +
1097 +static int metronomefb_resume(struct platform_device *pdev)
1098 +{
1099 + struct fb_info *info = platform_get_drvdata(pdev);
1100 + struct metronomefb_par *par = info->par;
1101 +
1102 + if (par->board->power_ctl)
1103 + par->board->power_ctl(par, METRONOME_POWER_ON);
1104 +
1105 + mutex_lock(&par->lock);
1106 + metronome_bootup(par);
1107 + mutex_unlock(&par->lock);
1108 +
1109 + return 0;
1110 +}
1111 +
1112 +#else
1113 +#define metronomefb_suspend NULL
1114 +#define metronomefb_resume NULL
1115 +#endif
1116 +
1117 +
1118 static struct platform_driver metronomefb_driver = {
1119 - .probe = metronomefb_probe,
1120 - .remove = metronomefb_remove,
1121 - .driver = {
1122 - .owner = THIS_MODULE,
1123 - .name = "metronomefb",
1124 - },
1125 + .driver = {
1126 + .owner = THIS_MODULE,
1127 + .name = "metronomefb",
1128 + },
1129 + .probe = metronomefb_probe,
1130 + .remove = __devexit_p(metronomefb_remove),
1131 + .suspend = metronomefb_suspend,
1132 + .resume = metronomefb_resume,
1133 };
1134
1135 static int __init metronomefb_init(void)
1136 @@ -782,8 +1362,8 @@ static void __exit metronomefb_exit(void)
1137 platform_driver_unregister(&metronomefb_driver);
1138 }
1139
1140 -module_param(user_wfm_size, uint, 0);
1141 -MODULE_PARM_DESC(user_wfm_size, "Set custom waveform size");
1142 +module_param(temp, int, 0);
1143 +MODULE_PARM_DESC(temp, "Set current temperature");
1144
1145 module_init(metronomefb_init);
1146 module_exit(metronomefb_exit);
1147 diff --git a/include/video/metronomefb.h b/include/video/metronomefb.h
1148 index 9863f4b..f505348 100644
1149 --- a/include/video/metronomefb.h
1150 +++ b/include/video/metronomefb.h
1151 @@ -17,7 +17,9 @@ struct metromem_cmd {
1152 u16 opcode;
1153 u16 args[((64-2)/2)];
1154 u16 csum;
1155 -};
1156 +} __attribute__((packed));
1157 +
1158 +struct epd_frame;
1159
1160 /* struct used by metronome. board specific stuff comes from *board */
1161 struct metronomefb_par {
1162 @@ -27,19 +29,40 @@ struct metronomefb_par {
1163 u16 *metromem_img_csum;
1164 u16 *csum_table;
1165 dma_addr_t metromem_dma;
1166 + const struct firmware *firmware;
1167 struct fb_info *info;
1168 struct metronome_board *board;
1169 + struct platform_device *pdev;
1170 wait_queue_head_t waitq;
1171 u8 frame_count;
1172 int extra_size;
1173 - int dt;
1174 + int current_wf_mode;
1175 + int current_wf_temp;
1176 + unsigned int manual_refresh_threshold;
1177 + unsigned int partial_autorefresh_interval;
1178 + const struct epd_frame *epd_frame;
1179 + u32 *fxbuckets;
1180 + u32 *fybuckets;
1181 +
1182 + int rotation;
1183 +
1184 + unsigned int partial_updates_count;
1185 + unsigned is_first_update:1;
1186 +
1187 + struct mutex lock;
1188 };
1189
1190 +#define METRONOME_POWER_OFF 0
1191 +#define METRONOME_POWER_ON 1
1192 +
1193 /* board specific routines and data */
1194 struct metronome_board {
1195 struct module *owner; /* the platform device */
1196 + void (*power_ctl)(struct metronomefb_par *, int);
1197 void (*set_rst)(struct metronomefb_par *, int);
1198 void (*set_stdby)(struct metronomefb_par *, int);
1199 + int (*get_err)(struct metronomefb_par *);
1200 + int (*get_rdy)(struct metronomefb_par *);
1201 void (*cleanup)(struct metronomefb_par *);
1202 int (*met_wait_event)(struct metronomefb_par *);
1203 int (*met_wait_event_intr)(struct metronomefb_par *);
1204 @@ -47,11 +70,7 @@ struct metronome_board {
1205 int (*setup_fb)(struct metronomefb_par *);
1206 int (*setup_io)(struct metronomefb_par *);
1207 int (*get_panel_type)(void);
1208 - unsigned char *metromem;
1209 - int fw;
1210 - int fh;
1211 - int wfm_size;
1212 - struct fb_info *host_fbinfo; /* the host LCD controller's fbi */
1213 + int panel_rotation;
1214 };
1215
1216 #endif
1217 --
1218 1.5.6.5
1219
This page took 0.090553 seconds and 5 git commands to generate.