1 From 057f6f13cff319e9f2fff39736371e95ff5ac47b 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 1/5] metronome patches
7 drivers/video/metronomefb.c | 788 +++++++++++++++++++++++++++++++++++++------
8 include/video/metronomefb.h | 33 ++-
9 2 files changed, 710 insertions(+), 111 deletions(-)
11 --- a/drivers/video/metronomefb.c
12 +++ b/drivers/video/metronomefb.c
14 * is provided as am200epd.c
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/string.h>
23 +#include <linux/slab.h>
24 #include <linux/vmalloc.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/uaccess.h>
30 #include <linux/irq.h>
31 +#include <linux/ctype.h>
33 #include <video/metronomefb.h>
35 #include <asm/unaligned.h>
37 -/* Display specific information */
41 + * 12 is ok to avoid refreshing whole screen while small elements are changed,
42 + * while forcing full refresh if largish dialog boxes or menus are
45 +#define DEFAULT_MANUAL_REFRESH_THRESHOLD 12
47 +#define WF_MODE_INIT 0 /* Initialization */
48 +#define WF_MODE_MU 1 /* Monochrome update */
49 +#define WF_MODE_GU 2 /* Grayscale update */
50 +#define WF_MODE_GC 3 /* Grayscale clearing */
52 -static int user_wfm_size;
53 +static int temp = 25;
55 /* frame differs from image. frame includes non-visible pixels */
57 @@ -53,7 +64,7 @@ struct epd_frame {
61 -static struct epd_frame epd_frame_table[] = {
62 +static const struct epd_frame epd_frame_table[] = {
66 @@ -97,24 +108,40 @@ static struct epd_frame epd_frame_table[
75 + | 2 << 8 /* sdosz */
76 + | 0 << 11 /* sdor */
77 + | 0 << 12 /* sdces */
78 + | 0 << 15, /* sdcer */
81 + | 1 << 9 /* sdshr */
82 + | 0 << 15, /* gdspp */
84 + | 0 << 15, /* dispc */
87 + | 0 << 12, /* dsic */
93 -static struct fb_fix_screeninfo metronomefb_fix __devinitdata = {
94 +static const struct fb_fix_screeninfo metronomefb_fix __devinitconst = {
96 .type = FB_TYPE_PACKED_PIXELS,
97 .visual = FB_VISUAL_STATIC_PSEUDOCOLOR,
101 - .line_length = DPY_W,
102 .accel = FB_ACCEL_NONE,
105 -static struct fb_var_screeninfo metronomefb_var __devinitdata = {
108 - .xres_virtual = DPY_W,
109 - .yres_virtual = DPY_H,
110 +static const struct fb_var_screeninfo metronomefb_var __devinitconst = {
114 @@ -167,7 +194,7 @@ static u16 calc_img_cksum(u16 *start, in
117 /* here we decode the incoming waveform file and populate metromem */
118 -static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
119 +static int load_waveform(u8 *mem, size_t size, int m, int t,
120 struct metronomefb_par *par)
123 @@ -181,16 +208,12 @@ static int __devinit load_waveform(u8 *m
125 struct waveform_hdr *wfm_hdr;
126 u8 *metromem = par->metromem_wfm;
127 - struct device *dev = par->info->dev;
128 + struct device *dev = &par->pdev->dev;
134 - epd_frame_table[par->dt].wfm_size = user_wfm_size;
136 - if (size != epd_frame_table[par->dt].wfm_size) {
137 - dev_err(dev, "Error: unexpected size %Zd != %d\n", size,
138 - epd_frame_table[par->dt].wfm_size);
141 + dev_dbg(dev, "Loading waveforms, mode %d, temperature %d\n", m, t);
143 wfm_hdr = (struct waveform_hdr *) mem;
145 @@ -208,8 +231,9 @@ static int __devinit load_waveform(u8 *m
151 + mc = wfm_hdr->mc + 1;
152 + trc = wfm_hdr->trc + 1;
154 for (i = 0; i < 5; i++) {
155 if (*(wfm_hdr->stuff2a + i) != 0) {
156 dev_err(dev, "Error: unexpected value in padding\n");
157 @@ -221,10 +245,10 @@ static int __devinit load_waveform(u8 *m
158 the waveform. presumably selecting the right one for the
159 desired temperature. it works out the offset of the first
160 v that exceeds the specified temperature */
161 - if ((sizeof(*wfm_hdr) + wfm_hdr->trc) > size)
162 + if ((sizeof(*wfm_hdr) + trc) > size)
165 - for (i = sizeof(*wfm_hdr); i <= sizeof(*wfm_hdr) + wfm_hdr->trc; i++) {
166 + for (i = sizeof(*wfm_hdr); i <= sizeof(*wfm_hdr) + trc; i++) {
168 trn = i - sizeof(*wfm_hdr) - 1;
170 @@ -232,7 +256,7 @@ static int __devinit load_waveform(u8 *m
173 /* check temperature range table checksum */
174 - cksum_idx = sizeof(*wfm_hdr) + wfm_hdr->trc + 1;
175 + cksum_idx = sizeof(*wfm_hdr) + trc + 1;
176 if (cksum_idx > size)
178 cksum = calc_cksum(sizeof(*wfm_hdr), cksum_idx, mem);
179 @@ -294,6 +318,7 @@ static int __devinit load_waveform(u8 *m
181 if (cksum_idx > size)
183 + dev_dbg(dev, "mem_idx = %u\n", mem_idx);
184 cksum = calc_cksum(owfm_idx, cksum_idx, mem);
185 if (cksum != mem[cksum_idx]) {
186 dev_err(dev, "Error: bad waveform data cksum"
187 @@ -302,16 +327,47 @@ static int __devinit load_waveform(u8 *m
189 par->frame_count = (mem_idx/64);
191 + p = (u16 *)par->metromem_wfm;
192 + img_cksum = calc_img_cksum(p, 16384 / 2);
193 + p[16384 / 2] = __cpu_to_le16(img_cksum);
195 + par->current_wf_mode = m;
196 + par->current_wf_temp = t;
201 +static int check_err(struct metronomefb_par *par)
205 + res = par->board->get_err(par);
206 + dev_dbg(&par->pdev->dev, "ERR = %d\n", res);
210 +static inline int wait_for_rdy(struct metronomefb_par *par)
214 + if (!par->board->get_rdy(par))
215 + res = par->board->met_wait_event_intr(par);
220 static int metronome_display_cmd(struct metronomefb_par *par)
225 - static u8 borderval;
228 + res = wait_for_rdy(par);
232 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
233 /* setup display command
234 we can't immediately set the opcode since the controller
235 will try parse the command before we've set it all up
236 @@ -324,8 +380,9 @@ static int metronome_display_cmd(struct
238 /* set the args ( 2 bytes ) for display */
240 - par->metromem_cmd->args[i] = 1 << 3 /* border update */
241 - | ((borderval++ % 4) & 0x0F) << 4
242 + par->metromem_cmd->args[i] = 0 << 3 /* border update */
244 +// | ((borderval++ % 4) & 0x0F) << 4
245 | (par->frame_count - 1) << 8;
246 cs += par->metromem_cmd->args[i++];
248 @@ -335,21 +392,25 @@ static int metronome_display_cmd(struct
249 par->metromem_cmd->csum = cs;
250 par->metromem_cmd->opcode = opcode; /* display cmd */
252 - return par->board->met_wait_event_intr(par);
257 static int __devinit metronome_powerup_cmd(struct metronomefb_par *par)
263 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
264 /* setup power up command */
265 par->metromem_cmd->opcode = 0x1234; /* pwr up pseudo cmd */
266 cs = par->metromem_cmd->opcode;
268 /* set pwr1,2,3 to 1024 */
269 for (i = 0; i < 3; i++) {
270 - par->metromem_cmd->args[i] = 1024;
271 +// par->metromem_cmd->args[i] = 1024;
272 + par->metromem_cmd->args[i] = 100;
273 cs += par->metromem_cmd->args[i];
276 @@ -364,7 +425,9 @@ static int __devinit metronome_powerup_c
278 par->board->set_stdby(par, 1);
280 - return par->board->met_wait_event(par);
281 + res = par->board->met_wait_event(par);
282 + dev_dbg(&par->pdev->dev, "%s: EXIT: %d\n", __func__, res);
286 static int __devinit metronome_config_cmd(struct metronomefb_par *par)
287 @@ -373,8 +436,9 @@ static int __devinit metronome_config_cm
288 we can't immediately set the opcode since the controller
289 will try parse the command before we've set it all up */
291 - memcpy(par->metromem_cmd->args, epd_frame_table[par->dt].config,
292 - sizeof(epd_frame_table[par->dt].config));
293 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
294 + memcpy(par->metromem_cmd->args, par->epd_frame->config,
295 + sizeof(par->epd_frame->config));
297 memset((u8 *) (par->metromem_cmd->args + 4), 0, (32-4)*2);
299 @@ -395,11 +459,12 @@ static int __devinit metronome_init_cmd(
300 will try parse the command before we've set it all up
301 so we just set cs here and set the opcode at the end */
303 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
306 /* set the args ( 2 bytes ) for init */
308 - par->metromem_cmd->args[i] = 0;
309 + par->metromem_cmd->args[i] = 0x0007;
310 cs += par->metromem_cmd->args[i++];
313 @@ -411,76 +476,268 @@ static int __devinit metronome_init_cmd(
314 return par->board->met_wait_event(par);
317 -static int __devinit metronome_init_regs(struct metronomefb_par *par)
318 +static int metronome_bootup(struct metronomefb_par *par)
322 - res = par->board->setup_io(par);
326 res = metronome_powerup_cmd(par);
330 + dev_err(&par->pdev->dev, "metronomefb: POWERUP cmd failed\n");
335 res = metronome_config_cmd(par);
339 + dev_err(&par->pdev->dev, "metronomefb: CONFIG cmd failed\n");
344 res = metronome_init_cmd(par);
346 + dev_err(&par->pdev->dev, "metronomefb: INIT cmd failed\n");
353 +static int __devinit metronome_init_regs(struct metronomefb_par *par)
357 + if (par->board->power_ctl)
358 + par->board->power_ctl(par, METRONOME_POWER_ON);
360 + res = metronome_bootup(par);
365 -static void metronomefb_dpy_update(struct metronomefb_par *par)
366 +static uint16_t metronomefb_update_img_buffer_rotated(struct metronomefb_par *par)
370 - unsigned char *buf = (unsigned char __force *)par->info->screen_base;
374 + uint16_t cksum = 0;
375 + uint8_t *buf = par->info->screen_base;
376 + uint32_t *img = (uint32_t *)(par->metromem_img);
377 + int fw = par->epd_frame->fw;
378 + int fh = par->epd_frame->fh;
379 + int fw_buf = fw / 4;
380 + uint32_t *fxbuckets = par->fxbuckets;
381 + uint32_t *fybuckets = par->fybuckets;
385 + switch (par->rotation) {
388 + ystep = fw * fh + 1;
396 + case FB_ROTATE_CCW:
398 + ystep = -fw * fh - 1;
406 - fbsize = par->info->fix.smem_len;
407 - /* copy from vm to metromem */
408 - memcpy(par->metromem_img, buf, fbsize);
409 + memset(fxbuckets, 0, fw_buf * sizeof(*fxbuckets));
410 + memset(fybuckets, 0, fh * sizeof(*fybuckets));
413 + for (y = 0; y < fh; y++) {
414 + for(x = 0; x < fw_buf; x++, i++) {
415 + tmp = (buf[j] << 5);
417 + tmp |= (buf[j] << 13);
419 + tmp |= (buf[j] << 21);
421 + tmp |= (buf[j] << 29);
425 + img[i] &= 0xf0f0f0f0;
426 + diff = img[i] ^ tmp;
428 + fxbuckets[x] |= diff;
429 + fybuckets[y] |= diff;
431 + img[i] = (img[i] >> 4) | tmp;
432 + cksum += img[i] & 0x0000ffff;
433 + cksum += (img[i] >> 16);
435 - cksum = calc_img_cksum((u16 *) par->metromem_img, fbsize/2);
436 - *((u16 *)(par->metromem_img) + fbsize/2) = cksum;
437 - metronome_display_cmd(par);
445 -static u16 metronomefb_dpy_update_page(struct metronomefb_par *par, int index)
446 +static uint16_t metronomefb_update_img_buffer_normal(struct metronomefb_par *par)
450 - u16 *buf = (u16 __force *)(par->info->screen_base + index);
451 - u16 *img = (u16 *)(par->metromem_img + index);
453 - /* swizzle from vm to metromem and recalc cksum at the same time*/
454 - for (i = 0; i < PAGE_SIZE/2; i++) {
455 - *(img + i) = (buf[i] << 5) & 0xE0E0;
456 - csum += *(img + i);
458 + uint16_t cksum = 0;
459 + uint32_t *buf = (uint32_t __force *)par->info->screen_base;
460 + uint32_t *img = (uint32_t *)(par->metromem_img);
463 + int fw = par->epd_frame->fw;
464 + int fh = par->epd_frame->fh;
465 + int fw_buf = fw / sizeof(*buf);
466 + uint32_t *fxbuckets = par->fxbuckets;
467 + uint32_t *fybuckets = par->fybuckets;
469 + memset(fxbuckets, 0, fw_buf * sizeof(*fxbuckets));
470 + memset(fybuckets, 0, fh * sizeof(*fybuckets));
473 + for (y = 0; y < fh; y++) {
474 + for(x = 0; x < fw_buf; x++, i++) {
475 + tmp = (buf[i] << 5) & 0xe0e0e0e0;
476 + img[i] &= 0xf0f0f0f0;
477 + diff = img[i] ^ tmp;
479 + fxbuckets[x] |= diff;
480 + fybuckets[y] |= diff;
482 + img[i] = (img[i] >> 4) | tmp;
483 + cksum += img[i] & 0x0000ffff;
484 + cksum += (img[i] >> 16);
492 +static unsigned int metronomefb_get_change_count(struct metronomefb_par *par)
498 + int fw = par->epd_frame->fw / 4;
499 + int fh = par->epd_frame->fh;
500 + unsigned int change_count;
501 + uint32_t *fxbuckets = par->fxbuckets;
502 + uint32_t *fybuckets = par->fybuckets;
504 + for (min_x = 0; min_x < fw; ++min_x) {
505 + if(fxbuckets[min_x])
509 + for (max_x = fw - 1; max_x >= 0; --max_x) {
510 + if(fxbuckets[max_x])
514 + for (min_y = 0; min_y < fh; min_y++) {
515 + if(fybuckets[min_y])
519 + for (max_y = fh - 1; max_y >= 0; --max_y) {
520 + if(fybuckets[max_y])
524 + if ((min_x > max_x) || (min_y > max_y))
527 + change_count = (max_x - min_x + 1) * (max_y - min_y + 1) * 4;
529 + dev_dbg(&par->pdev->dev, "min_x = %d, max_x = %d, min_y = %d, max_y = %d\n",
530 + min_x, max_x, min_y, max_y);
532 + return change_count;
535 +static void metronomefb_dpy_update(struct metronomefb_par *par, int clear_all)
537 + unsigned int fbsize = par->info->fix.smem_len;
543 + if (par->rotation == 0)
544 + cksum = metronomefb_update_img_buffer_normal(par);
546 + cksum = metronomefb_update_img_buffer_rotated(par);
548 + *par->metromem_img_csum = __cpu_to_le16(cksum);
550 + if (clear_all || par->is_first_update ||
551 + (par->partial_updates_count == par->partial_autorefresh_interval)) {
553 + par->partial_updates_count = 0;
555 + int change_count = metronomefb_get_change_count(par);
556 + if (change_count < fbsize / 100 * par->manual_refresh_threshold)
561 + dev_dbg(&par->pdev->dev, "change_count = %u, treshold = %u%% (%u pixels)\n",
562 + change_count, par->manual_refresh_threshold,
563 + fbsize / 100 * par->manual_refresh_threshold);
564 + ++par->partial_updates_count;
567 + if (m != par->current_wf_mode)
568 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
569 + m, par->current_wf_temp, par);
572 + if (likely(!check_err(par))) {
573 + metronome_display_cmd(par);
577 + par->board->set_stdby(par, 0);
578 + dev_warn(&par->pdev->dev, "Resetting Metronome\n");
579 + par->board->set_rst(par, 0);
581 + if (par->board->power_ctl)
582 + par->board->power_ctl(par, METRONOME_POWER_OFF);
585 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
586 + WF_MODE_GC, par->current_wf_temp, par);
588 + if (par->board->power_ctl)
589 + par->board->power_ctl(par, METRONOME_POWER_ON);
590 + metronome_bootup(par);
593 + par->is_first_update = 0;
596 /* this is called back from the deferred io workqueue */
597 static void metronomefb_dpy_deferred_io(struct fb_info *info,
598 struct list_head *pagelist)
602 - struct fb_deferred_io *fbdefio = info->fbdefio;
603 struct metronomefb_par *par = info->par;
605 - /* walk the written page list and swizzle the data */
606 - list_for_each_entry(cur, &fbdefio->pagelist, lru) {
607 - cksum = metronomefb_dpy_update_page(par,
608 - (cur->index << PAGE_SHIFT));
609 - par->metromem_img_csum -= par->csum_table[cur->index];
610 - par->csum_table[cur->index] = cksum;
611 - par->metromem_img_csum += cksum;
614 - metronome_display_cmd(par);
615 + /* We will update entire display because we need to change
616 + * 'previous image' field in pixels which was changed at
619 + mutex_lock(&par->lock);
620 + metronomefb_dpy_update(par, 0);
621 + mutex_unlock(&par->lock);
624 static void metronomefb_fillrect(struct fb_info *info,
625 @@ -488,8 +745,10 @@ static void metronomefb_fillrect(struct
627 struct metronomefb_par *par = info->par;
629 + mutex_lock(&par->lock);
630 sys_fillrect(info, rect);
631 - metronomefb_dpy_update(par);
632 + metronomefb_dpy_update(par, 0);
633 + mutex_unlock(&par->lock);
636 static void metronomefb_copyarea(struct fb_info *info,
637 @@ -497,8 +756,10 @@ static void metronomefb_copyarea(struct
639 struct metronomefb_par *par = info->par;
641 + mutex_lock(&par->lock);
642 sys_copyarea(info, area);
643 - metronomefb_dpy_update(par);
644 + metronomefb_dpy_update(par, 0);
645 + mutex_unlock(&par->lock);
648 static void metronomefb_imageblit(struct fb_info *info,
649 @@ -506,8 +767,10 @@ static void metronomefb_imageblit(struct
651 struct metronomefb_par *par = info->par;
653 + mutex_lock(&par->lock);
654 sys_imageblit(info, image);
655 - metronomefb_dpy_update(par);
656 + metronomefb_dpy_update(par, 0);
657 + mutex_unlock(&par->lock);
661 @@ -545,30 +808,229 @@ static ssize_t metronomefb_write(struct
663 dst = (void __force *)(info->screen_base + p);
665 + mutex_lock(&par->lock);
667 if (copy_from_user(dst, buf, count))
673 - metronomefb_dpy_update(par);
674 + metronomefb_dpy_update(par, 0);
675 + mutex_unlock(&par->lock);
677 return (err) ? err : count;
680 +static int metronome_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
682 + struct metronomefb_par *par = info->par;
684 + var->grayscale = 1;
686 + switch (par->rotation) {
688 + case FB_ROTATE_CCW:
689 + if (par->epd_frame->fw == var->yres && par->epd_frame->fh == var->xres)
694 + if (par->epd_frame->fw == var->xres && par->epd_frame->fh == var->yres)
702 +static int metronomefb_set_par(struct fb_info *info)
704 + struct metronomefb_par *par = info->par;
706 + par->rotation = (par->board->panel_rotation + info->var.rotate) % 4;
708 + switch (par->rotation) {
710 + case FB_ROTATE_CCW:
711 + info->fix.line_length = par->epd_frame->fh;
715 + info->fix.line_length = par->epd_frame->fw;
719 + mutex_lock(&par->lock);
720 + metronomefb_dpy_update(info->par, 1);
721 + mutex_unlock(&par->lock);
726 static struct fb_ops metronomefb_ops = {
727 .owner = THIS_MODULE,
728 .fb_write = metronomefb_write,
729 .fb_fillrect = metronomefb_fillrect,
730 .fb_copyarea = metronomefb_copyarea,
731 .fb_imageblit = metronomefb_imageblit,
732 + .fb_check_var = metronome_check_var,
733 + .fb_set_par = metronomefb_set_par,
736 static struct fb_deferred_io metronomefb_defio = {
739 .deferred_io = metronomefb_dpy_deferred_io,
742 +static ssize_t metronomefb_defio_delay_show(struct device *dev,
743 + struct device_attribute *attr, char *buf)
745 + struct fb_info *info = dev_get_drvdata(dev);
747 + sprintf(buf, "%lu\n", info->fbdefio->delay * 1000 / HZ);
748 + return strlen(buf) + 1;
751 +static ssize_t metronomefb_defio_delay_store(struct device *dev,
752 + struct device_attribute *attr, const char *buf, size_t size)
754 + struct fb_info *info = dev_get_drvdata(dev);
756 + unsigned long state = simple_strtoul(buf, &after, 10);
757 + size_t count = after - buf;
758 + ssize_t ret = -EINVAL;
760 + if (*after && isspace(*after))
763 + state = state * HZ / 1000;
768 + if (count == size) {
770 + info->fbdefio->delay = state;
776 +static ssize_t metronomefb_manual_refresh_thr_show(struct device *dev,
777 + struct device_attribute *attr, char *buf)
779 + struct fb_info *info = dev_get_drvdata(dev);
780 + struct metronomefb_par *par = info->par;
782 + return sprintf(buf, "%u\n", par->manual_refresh_threshold);
785 +static ssize_t metronomefb_manual_refresh_thr_store(struct device *dev,
786 + struct device_attribute *attr, const char *buf, size_t size)
788 + struct fb_info *info = dev_get_drvdata(dev);
789 + struct metronomefb_par *par = info->par;
791 + unsigned long val = simple_strtoul(buf, &after, 10);
792 + size_t count = after - buf;
793 + ssize_t ret = -EINVAL;
795 + if (*after && isspace(*after))
802 + if (count == size) {
804 + par->manual_refresh_threshold = val;
810 +static ssize_t metronomefb_autorefresh_interval_show(struct device *dev,
811 + struct device_attribute *attr, char *buf)
813 + struct fb_info *info = dev_get_drvdata(dev);
814 + struct metronomefb_par *par = info->par;
816 + return sprintf(buf, "%u\n", par->partial_autorefresh_interval);
819 +static ssize_t metronomefb_autorefresh_interval_store(struct device *dev,
820 + struct device_attribute *attr, const char *buf, size_t size)
822 + struct fb_info *info = dev_get_drvdata(dev);
823 + struct metronomefb_par *par = info->par;
825 + unsigned long val = simple_strtoul(buf, &after, 10);
826 + size_t count = after - buf;
827 + ssize_t ret = -EINVAL;
829 + if (*after && isspace(*after))
836 + if (count == size) {
838 + par->partial_autorefresh_interval = val;
844 +static ssize_t metronomefb_temp_show(struct device *dev,
845 + struct device_attribute *attr, char *buf)
847 + struct fb_info *info = dev_get_drvdata(dev);
848 + struct metronomefb_par *par = info->par;
850 + return sprintf(buf, "%u\n", par->current_wf_temp);
853 +static ssize_t metronomefb_temp_store(struct device *dev,
854 + struct device_attribute *attr, const char *buf, size_t size)
856 + struct fb_info *info = dev_get_drvdata(dev);
857 + struct metronomefb_par *par = info->par;
859 + unsigned long val = simple_strtoul(buf, &after, 10);
860 + size_t count = after - buf;
861 + ssize_t ret = -EINVAL;
863 + if (*after && isspace(*after))
870 + if (count == size) {
872 + if (val != par->current_wf_temp)
873 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
874 + par->current_wf_mode, val, par);
880 +DEVICE_ATTR(defio_delay, 0644,
881 + metronomefb_defio_delay_show, metronomefb_defio_delay_store);
882 +DEVICE_ATTR(manual_refresh_threshold, 0644,
883 + metronomefb_manual_refresh_thr_show, metronomefb_manual_refresh_thr_store);
884 +DEVICE_ATTR(temp, 0644,
885 + metronomefb_temp_show, metronomefb_temp_store);
886 +DEVICE_ATTR(autorefresh_interval, 0644,
887 + metronomefb_autorefresh_interval_show, metronomefb_autorefresh_interval_store);
890 static int __devinit metronomefb_probe(struct platform_device *dev)
892 struct fb_info *info;
893 @@ -607,6 +1069,9 @@ static int __devinit metronomefb_probe(s
895 panel_type = board->get_panel_type();
896 switch (panel_type) {
903 @@ -632,29 +1097,59 @@ static int __devinit metronomefb_probe(s
907 - memset(videomemory, 0, videomemorysize);
908 + memset(videomemory, 0xff, videomemorysize);
910 info->screen_base = (char __force __iomem *)videomemory;
911 info->fbops = &metronomefb_ops;
913 - metronomefb_fix.line_length = fw;
914 - metronomefb_var.xres = fw;
915 - metronomefb_var.yres = fh;
916 - metronomefb_var.xres_virtual = fw;
917 - metronomefb_var.yres_virtual = fh;
918 info->var = metronomefb_var;
919 info->fix = metronomefb_fix;
920 - info->fix.smem_len = videomemorysize;
921 + switch (board->panel_rotation) {
923 + case FB_ROTATE_CCW:
924 + info->var.xres = fh;
925 + info->var.yres = fw;
926 + info->var.xres_virtual = fh;
927 + info->var.yres_virtual = fw;
928 + info->fix.line_length = fh;
932 + info->var.xres = fw;
933 + info->var.yres = fh;
934 + info->var.xres_virtual = fw;
935 + info->var.yres_virtual = fh;
936 + info->fix.line_length = fw;
939 + info->fix.smem_len = fw * fh; /* Real size of image area */
943 - par->dt = epd_dt_index;
944 + par->epd_frame = &epd_frame_table[epd_dt_index];
947 + par->rotation = board->panel_rotation;
949 + par->fxbuckets = kmalloc((fw / 4 + 1) * sizeof(*par->fxbuckets), GFP_KERNEL);
950 + if (!par->fxbuckets)
953 + par->fybuckets = kmalloc(fh * sizeof(*par->fybuckets), GFP_KERNEL);
954 + if (!par->fybuckets)
955 + goto err_fxbuckets;
957 init_waitqueue_head(&par->waitq);
958 + par->manual_refresh_threshold = DEFAULT_MANUAL_REFRESH_THRESHOLD;
959 + par->partial_autorefresh_interval = 256;
960 + par->partial_updates_count = 0;
961 + par->is_first_update = 1;
962 + mutex_init(&par->lock);
964 /* this table caches per page csum values. */
965 par->csum_table = vmalloc(videomemorysize/PAGE_SIZE);
966 if (!par->csum_table)
968 + goto err_fybuckets;
970 /* the physical framebuffer that we use is setup by
971 * the platform device driver. It will provide us
972 @@ -684,13 +1179,19 @@ static int __devinit metronomefb_probe(s
976 - retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, 3, 31,
977 + retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, WF_MODE_GC, temp,
979 - release_firmware(fw_entry);
981 dev_err(&dev->dev, "Failed processing waveform\n");
984 + par->firmware = fw_entry;
986 + retval = board->setup_io(par);
988 + dev_err(&dev->dev, "metronomefb: setup_io() failed\n");
989 + goto err_csum_table;
992 if (board->setup_irq(info))
994 @@ -712,7 +1213,7 @@ static int __devinit metronomefb_probe(s
997 for (i = 0; i < 8; i++)
998 - info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16;
999 + info->cmap.red[i] = ((2 * i + 1)*(0xFFFF))/16;
1000 memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8);
1001 memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);
1003 @@ -722,18 +1223,47 @@ static int __devinit metronomefb_probe(s
1005 platform_set_drvdata(dev, info);
1007 - dev_dbg(&dev->dev,
1008 + retval = device_create_file(info->dev, &dev_attr_defio_delay);
1010 + goto err_devattr_defio_delay;
1012 + retval = device_create_file(info->dev, &dev_attr_manual_refresh_threshold);
1014 + goto err_devattr_manual_refresh_thr;
1016 + retval = device_create_file(info->dev, &dev_attr_temp);
1018 + goto err_devattr_temp;
1020 + retval = device_create_file(info->dev, &dev_attr_autorefresh_interval);
1022 + goto err_devattr_autorefresh;
1024 + dev_info(&dev->dev,
1025 "fb%d: Metronome frame buffer device, using %dK of video"
1026 " memory\n", info->node, videomemorysize >> 10);
1030 + device_remove_file(info->dev, &dev_attr_autorefresh_interval);
1031 +err_devattr_autorefresh:
1032 + device_remove_file(info->dev, &dev_attr_temp);
1034 + device_remove_file(info->dev, &dev_attr_manual_refresh_threshold);
1035 +err_devattr_manual_refresh_thr:
1036 + device_remove_file(info->dev, &dev_attr_defio_delay);
1037 +err_devattr_defio_delay:
1038 + unregister_framebuffer(info);
1040 fb_dealloc_cmap(&info->cmap);
1042 board->cleanup(par);
1044 vfree(par->csum_table);
1046 + kfree(par->fybuckets);
1048 + kfree(par->fxbuckets);
1052 @@ -750,26 +1280,76 @@ static int __devexit metronomefb_remove(
1054 struct metronomefb_par *par = info->par;
1056 + par->board->set_stdby(par, 0);
1058 + if (par->board->power_ctl)
1059 + par->board->power_ctl(par, METRONOME_POWER_OFF);
1061 + device_remove_file(info->dev, &dev_attr_autorefresh_interval);
1062 + device_remove_file(info->dev, &dev_attr_temp);
1063 + device_remove_file(info->dev, &dev_attr_manual_refresh_threshold);
1064 + device_remove_file(info->dev, &dev_attr_defio_delay);
1065 unregister_framebuffer(info);
1066 fb_deferred_io_cleanup(info);
1067 fb_dealloc_cmap(&info->cmap);
1068 par->board->cleanup(par);
1069 vfree(par->csum_table);
1070 + kfree(par->fybuckets);
1071 + kfree(par->fxbuckets);
1072 vfree((void __force *)info->screen_base);
1073 module_put(par->board->owner);
1074 + release_firmware(par->firmware);
1075 dev_dbg(&dev->dev, "calling release\n");
1076 framebuffer_release(info);
1082 +static int metronomefb_suspend(struct platform_device *pdev, pm_message_t message)
1084 + struct fb_info *info = platform_get_drvdata(pdev);
1085 + struct metronomefb_par *par = info->par;
1087 + par->board->set_stdby(par, 0);
1088 + par->board->set_rst(par, 0);
1089 + if (par->board->power_ctl)
1090 + par->board->power_ctl(par, METRONOME_POWER_OFF);
1096 +static int metronomefb_resume(struct platform_device *pdev)
1098 + struct fb_info *info = platform_get_drvdata(pdev);
1099 + struct metronomefb_par *par = info->par;
1101 + if (par->board->power_ctl)
1102 + par->board->power_ctl(par, METRONOME_POWER_ON);
1104 + mutex_lock(&par->lock);
1105 + metronome_bootup(par);
1106 + mutex_unlock(&par->lock);
1112 +#define metronomefb_suspend NULL
1113 +#define metronomefb_resume NULL
1117 static struct platform_driver metronomefb_driver = {
1118 - .probe = metronomefb_probe,
1119 - .remove = metronomefb_remove,
1121 - .owner = THIS_MODULE,
1122 - .name = "metronomefb",
1125 + .owner = THIS_MODULE,
1126 + .name = "metronomefb",
1128 + .probe = metronomefb_probe,
1129 + .remove = __devexit_p(metronomefb_remove),
1130 + .suspend = metronomefb_suspend,
1131 + .resume = metronomefb_resume,
1134 static int __init metronomefb_init(void)
1135 @@ -782,8 +1362,8 @@ static void __exit metronomefb_exit(void
1136 platform_driver_unregister(&metronomefb_driver);
1139 -module_param(user_wfm_size, uint, 0);
1140 -MODULE_PARM_DESC(user_wfm_size, "Set custom waveform size");
1141 +module_param(temp, int, 0);
1142 +MODULE_PARM_DESC(temp, "Set current temperature");
1144 module_init(metronomefb_init);
1145 module_exit(metronomefb_exit);
1146 --- a/include/video/metronomefb.h
1147 +++ b/include/video/metronomefb.h
1148 @@ -17,7 +17,9 @@ struct metromem_cmd {
1150 u16 args[((64-2)/2)];
1153 +} __attribute__((packed));
1157 /* struct used by metronome. board specific stuff comes from *board */
1158 struct metronomefb_par {
1159 @@ -27,19 +29,40 @@ struct metronomefb_par {
1160 u16 *metromem_img_csum;
1162 dma_addr_t metromem_dma;
1163 + const struct firmware *firmware;
1164 struct fb_info *info;
1165 struct metronome_board *board;
1166 + struct platform_device *pdev;
1167 wait_queue_head_t waitq;
1171 + int current_wf_mode;
1172 + int current_wf_temp;
1173 + unsigned int manual_refresh_threshold;
1174 + unsigned int partial_autorefresh_interval;
1175 + const struct epd_frame *epd_frame;
1181 + unsigned int partial_updates_count;
1182 + unsigned is_first_update:1;
1184 + struct mutex lock;
1187 +#define METRONOME_POWER_OFF 0
1188 +#define METRONOME_POWER_ON 1
1190 /* board specific routines and data */
1191 struct metronome_board {
1192 struct module *owner; /* the platform device */
1193 + void (*power_ctl)(struct metronomefb_par *, int);
1194 void (*set_rst)(struct metronomefb_par *, int);
1195 void (*set_stdby)(struct metronomefb_par *, int);
1196 + int (*get_err)(struct metronomefb_par *);
1197 + int (*get_rdy)(struct metronomefb_par *);
1198 void (*cleanup)(struct metronomefb_par *);
1199 int (*met_wait_event)(struct metronomefb_par *);
1200 int (*met_wait_event_intr)(struct metronomefb_par *);
1201 @@ -47,11 +70,7 @@ struct metronome_board {
1202 int (*setup_fb)(struct metronomefb_par *);
1203 int (*setup_io)(struct metronomefb_par *);
1204 int (*get_panel_type)(void);
1205 - unsigned char *metromem;
1209 - struct fb_info *host_fbinfo; /* the host LCD controller's fbi */
1210 + int panel_rotation;