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
7 drivers/video/metronomefb.c | 788 +++++++++++++++++++++++++++++++++++++------
8 include/video/metronomefb.h | 33 ++-
9 2 files changed, 710 insertions(+), 111 deletions(-)
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
16 * is provided as am200epd.c
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
25 +#include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 #include <linux/delay.h>
28 #include <linux/interrupt.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/uaccess.h>
32 #include <linux/irq.h>
33 +#include <linux/ctype.h>
35 #include <video/metronomefb.h>
37 #include <asm/unaligned.h>
39 -/* Display specific information */
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
47 +#define DEFAULT_MANUAL_REFRESH_THRESHOLD 12
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 */
54 -static int user_wfm_size;
55 +static int temp = 25;
57 /* frame differs from image. frame includes non-visible pixels */
59 @@ -53,7 +64,7 @@ struct epd_frame {
63 -static struct epd_frame epd_frame_table[] = {
64 +static const struct epd_frame epd_frame_table[] = {
68 @@ -97,24 +108,40 @@ static struct epd_frame epd_frame_table[] = {
77 + | 2 << 8 /* sdosz */
78 + | 0 << 11 /* sdor */
79 + | 0 << 12 /* sdces */
80 + | 0 << 15, /* sdcer */
83 + | 1 << 9 /* sdshr */
84 + | 0 << 15, /* gdspp */
86 + | 0 << 15, /* dispc */
89 + | 0 << 12, /* dsic */
95 -static struct fb_fix_screeninfo metronomefb_fix __devinitdata = {
96 +static const struct fb_fix_screeninfo metronomefb_fix __devinitconst = {
98 .type = FB_TYPE_PACKED_PIXELS,
99 .visual = FB_VISUAL_STATIC_PSEUDOCOLOR,
103 - .line_length = DPY_W,
104 .accel = FB_ACCEL_NONE,
107 -static struct fb_var_screeninfo metronomefb_var __devinitdata = {
110 - .xres_virtual = DPY_W,
111 - .yres_virtual = DPY_H,
112 +static const struct fb_var_screeninfo metronomefb_var __devinitconst = {
116 @@ -167,7 +194,7 @@ static u16 calc_img_cksum(u16 *start, int length)
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)
125 @@ -181,16 +208,12 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
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;
136 - epd_frame_table[par->dt].wfm_size = user_wfm_size;
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);
143 + dev_dbg(dev, "Loading waveforms, mode %d, temperature %d\n", m, t);
145 wfm_hdr = (struct waveform_hdr *) mem;
147 @@ -208,8 +231,9 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
153 + mc = wfm_hdr->mc + 1;
154 + trc = wfm_hdr->trc + 1;
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)
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++) {
170 trn = i - sizeof(*wfm_hdr) - 1;
172 @@ -232,7 +256,7 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
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)
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,
183 if (cksum_idx > size)
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,
191 par->frame_count = (mem_idx/64);
193 + p = (u16 *)par->metromem_wfm;
194 + img_cksum = calc_img_cksum(p, 16384 / 2);
195 + p[16384 / 2] = __cpu_to_le16(img_cksum);
197 + par->current_wf_mode = m;
198 + par->current_wf_temp = t;
203 +static int check_err(struct metronomefb_par *par)
207 + res = par->board->get_err(par);
208 + dev_dbg(&par->pdev->dev, "ERR = %d\n", res);
212 +static inline int wait_for_rdy(struct metronomefb_par *par)
216 + if (!par->board->get_rdy(par))
217 + res = par->board->met_wait_event_intr(par);
222 static int metronome_display_cmd(struct metronomefb_par *par)
227 - static u8 borderval;
230 + res = wait_for_rdy(par);
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)
240 /* set the args ( 2 bytes ) for display */
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 */
246 +// | ((borderval++ % 4) & 0x0F) << 4
247 | (par->frame_count - 1) << 8;
248 cs += par->metromem_cmd->args[i++];
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 */
254 - return par->board->met_wait_event_intr(par);
259 static int __devinit metronome_powerup_cmd(struct metronomefb_par *par)
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;
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];
278 @@ -364,7 +425,9 @@ static int __devinit metronome_powerup_cmd(struct metronomefb_par *par)
280 par->board->set_stdby(par, 1);
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);
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 */
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));
299 memset((u8 *) (par->metromem_cmd->args + 4), 0, (32-4)*2);
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 */
305 + dev_dbg(&par->pdev->dev, "%s: ENTER\n", __func__);
308 /* set the args ( 2 bytes ) for init */
310 - par->metromem_cmd->args[i] = 0;
311 + par->metromem_cmd->args[i] = 0x0007;
312 cs += par->metromem_cmd->args[i++];
315 @@ -411,76 +476,268 @@ static int __devinit metronome_init_cmd(struct metronomefb_par *par)
316 return par->board->met_wait_event(par);
319 -static int __devinit metronome_init_regs(struct metronomefb_par *par)
320 +static int metronome_bootup(struct metronomefb_par *par)
324 - res = par->board->setup_io(par);
328 res = metronome_powerup_cmd(par);
332 + dev_err(&par->pdev->dev, "metronomefb: POWERUP cmd failed\n");
337 res = metronome_config_cmd(par);
341 + dev_err(&par->pdev->dev, "metronomefb: CONFIG cmd failed\n");
346 res = metronome_init_cmd(par);
348 + dev_err(&par->pdev->dev, "metronomefb: INIT cmd failed\n");
355 +static int __devinit metronome_init_regs(struct metronomefb_par *par)
359 + if (par->board->power_ctl)
360 + par->board->power_ctl(par, METRONOME_POWER_ON);
362 + res = metronome_bootup(par);
367 -static void metronomefb_dpy_update(struct metronomefb_par *par)
368 +static uint16_t metronomefb_update_img_buffer_rotated(struct metronomefb_par *par)
372 - unsigned char *buf = (unsigned char __force *)par->info->screen_base;
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;
387 + switch (par->rotation) {
390 + ystep = fw * fh + 1;
398 + case FB_ROTATE_CCW:
400 + ystep = -fw * fh - 1;
408 + memset(fxbuckets, 0, fw_buf * sizeof(*fxbuckets));
409 + memset(fybuckets, 0, fh * sizeof(*fybuckets));
411 - fbsize = par->info->fix.smem_len;
412 - /* copy from vm to metromem */
413 - memcpy(par->metromem_img, buf, fbsize);
415 + for (y = 0; y < fh; y++) {
416 + for(x = 0; x < fw_buf; x++, i++) {
417 + tmp = (buf[j] << 5);
419 + tmp |= (buf[j] << 13);
421 + tmp |= (buf[j] << 21);
423 + tmp |= (buf[j] << 29);
427 + img[i] &= 0xf0f0f0f0;
428 + diff = img[i] ^ tmp;
430 + fxbuckets[x] |= diff;
431 + fybuckets[y] |= diff;
433 + img[i] = (img[i] >> 4) | tmp;
434 + cksum += img[i] & 0x0000ffff;
435 + cksum += (img[i] >> 16);
437 - cksum = calc_img_cksum((u16 *) par->metromem_img, fbsize/2);
438 - *((u16 *)(par->metromem_img) + fbsize/2) = cksum;
439 - metronome_display_cmd(par);
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)
452 - u16 *buf = (u16 __force *)(par->info->screen_base + index);
453 - u16 *img = (u16 *)(par->metromem_img + index);
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);
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;
466 + memset(fxbuckets, 0, fw_buf * sizeof(*fxbuckets));
467 + memset(fybuckets, 0, fh * sizeof(*fybuckets));
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;
476 + fxbuckets[x] |= diff;
477 + fybuckets[y] |= diff;
479 + img[i] = (img[i] >> 4) | tmp;
480 + cksum += img[i] & 0x0000ffff;
481 + cksum += (img[i] >> 16);
488 +static unsigned int metronomefb_get_change_count(struct metronomefb_par *par)
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;
500 + for (min_x = 0; min_x < fw; ++min_x) {
501 + if(fxbuckets[min_x])
505 + for (max_x = fw - 1; max_x >= 0; --max_x) {
506 + if(fxbuckets[max_x])
510 + for (min_y = 0; min_y < fh; min_y++) {
511 + if(fybuckets[min_y])
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])
525 + if ((min_x > max_x) || (min_y > max_y))
528 + change_count = (max_x - min_x + 1) * (max_y - min_y + 1) * 4;
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);
533 + return change_count;
536 +static void metronomefb_dpy_update(struct metronomefb_par *par, int clear_all)
538 + unsigned int fbsize = par->info->fix.smem_len;
544 + if (par->rotation == 0)
545 + cksum = metronomefb_update_img_buffer_normal(par);
547 + cksum = metronomefb_update_img_buffer_rotated(par);
549 + *par->metromem_img_csum = __cpu_to_le16(cksum);
551 + if (clear_all || par->is_first_update ||
552 + (par->partial_updates_count == par->partial_autorefresh_interval)) {
554 + par->partial_updates_count = 0;
556 + int change_count = metronomefb_get_change_count(par);
557 + if (change_count < fbsize / 100 * par->manual_refresh_threshold)
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;
568 + if (m != par->current_wf_mode)
569 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
570 + m, par->current_wf_temp, par);
573 + if (likely(!check_err(par))) {
574 + metronome_display_cmd(par);
578 + par->board->set_stdby(par, 0);
579 + dev_warn(&par->pdev->dev, "Resetting Metronome\n");
580 + par->board->set_rst(par, 0);
582 + if (par->board->power_ctl)
583 + par->board->power_ctl(par, METRONOME_POWER_OFF);
586 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
587 + WF_MODE_GC, par->current_wf_temp, par);
589 + if (par->board->power_ctl)
590 + par->board->power_ctl(par, METRONOME_POWER_ON);
591 + metronome_bootup(par);
594 + par->is_first_update = 0;
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)
603 - struct fb_deferred_io *fbdefio = info->fbdefio;
604 struct metronomefb_par *par = info->par;
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;
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
620 + mutex_lock(&par->lock);
621 + metronomefb_dpy_update(par, 0);
622 + mutex_unlock(&par->lock);
625 static void metronomefb_fillrect(struct fb_info *info,
626 @@ -488,8 +745,10 @@ static void metronomefb_fillrect(struct fb_info *info,
628 struct metronomefb_par *par = info->par;
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);
637 static void metronomefb_copyarea(struct fb_info *info,
638 @@ -497,8 +756,10 @@ static void metronomefb_copyarea(struct fb_info *info,
640 struct metronomefb_par *par = info->par;
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);
649 static void metronomefb_imageblit(struct fb_info *info,
650 @@ -506,8 +767,10 @@ static void metronomefb_imageblit(struct fb_info *info,
652 struct metronomefb_par *par = info->par;
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);
662 @@ -545,30 +808,229 @@ static ssize_t metronomefb_write(struct fb_info *info, const char __user *buf,
664 dst = (void __force *)(info->screen_base + p);
666 + mutex_lock(&par->lock);
668 if (copy_from_user(dst, buf, count))
674 - metronomefb_dpy_update(par);
675 + metronomefb_dpy_update(par, 0);
676 + mutex_unlock(&par->lock);
678 return (err) ? err : count;
681 +static int metronome_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
683 + struct metronomefb_par *par = info->par;
685 + var->grayscale = 1;
687 + switch (par->rotation) {
689 + case FB_ROTATE_CCW:
690 + if (par->epd_frame->fw == var->yres && par->epd_frame->fh == var->xres)
695 + if (par->epd_frame->fw == var->xres && par->epd_frame->fh == var->yres)
703 +static int metronomefb_set_par(struct fb_info *info)
705 + struct metronomefb_par *par = info->par;
707 + par->rotation = (par->board->panel_rotation + info->var.rotate) % 4;
709 + switch (par->rotation) {
711 + case FB_ROTATE_CCW:
712 + info->fix.line_length = par->epd_frame->fh;
716 + info->fix.line_length = par->epd_frame->fw;
720 + mutex_lock(&par->lock);
721 + metronomefb_dpy_update(info->par, 1);
722 + mutex_unlock(&par->lock);
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,
737 static struct fb_deferred_io metronomefb_defio = {
740 .deferred_io = metronomefb_dpy_deferred_io,
743 +static ssize_t metronomefb_defio_delay_show(struct device *dev,
744 + struct device_attribute *attr, char *buf)
746 + struct fb_info *info = dev_get_drvdata(dev);
748 + sprintf(buf, "%lu\n", info->fbdefio->delay * 1000 / HZ);
749 + return strlen(buf) + 1;
752 +static ssize_t metronomefb_defio_delay_store(struct device *dev,
753 + struct device_attribute *attr, const char *buf, size_t size)
755 + struct fb_info *info = dev_get_drvdata(dev);
757 + unsigned long state = simple_strtoul(buf, &after, 10);
758 + size_t count = after - buf;
759 + ssize_t ret = -EINVAL;
761 + if (*after && isspace(*after))
764 + state = state * HZ / 1000;
769 + if (count == size) {
771 + info->fbdefio->delay = state;
777 +static ssize_t metronomefb_manual_refresh_thr_show(struct device *dev,
778 + struct device_attribute *attr, char *buf)
780 + struct fb_info *info = dev_get_drvdata(dev);
781 + struct metronomefb_par *par = info->par;
783 + return sprintf(buf, "%u\n", par->manual_refresh_threshold);
786 +static ssize_t metronomefb_manual_refresh_thr_store(struct device *dev,
787 + struct device_attribute *attr, const char *buf, size_t size)
789 + struct fb_info *info = dev_get_drvdata(dev);
790 + struct metronomefb_par *par = info->par;
792 + unsigned long val = simple_strtoul(buf, &after, 10);
793 + size_t count = after - buf;
794 + ssize_t ret = -EINVAL;
796 + if (*after && isspace(*after))
803 + if (count == size) {
805 + par->manual_refresh_threshold = val;
811 +static ssize_t metronomefb_autorefresh_interval_show(struct device *dev,
812 + struct device_attribute *attr, char *buf)
814 + struct fb_info *info = dev_get_drvdata(dev);
815 + struct metronomefb_par *par = info->par;
817 + return sprintf(buf, "%u\n", par->partial_autorefresh_interval);
820 +static ssize_t metronomefb_autorefresh_interval_store(struct device *dev,
821 + struct device_attribute *attr, const char *buf, size_t size)
823 + struct fb_info *info = dev_get_drvdata(dev);
824 + struct metronomefb_par *par = info->par;
826 + unsigned long val = simple_strtoul(buf, &after, 10);
827 + size_t count = after - buf;
828 + ssize_t ret = -EINVAL;
830 + if (*after && isspace(*after))
837 + if (count == size) {
839 + par->partial_autorefresh_interval = val;
845 +static ssize_t metronomefb_temp_show(struct device *dev,
846 + struct device_attribute *attr, char *buf)
848 + struct fb_info *info = dev_get_drvdata(dev);
849 + struct metronomefb_par *par = info->par;
851 + return sprintf(buf, "%u\n", par->current_wf_temp);
854 +static ssize_t metronomefb_temp_store(struct device *dev,
855 + struct device_attribute *attr, const char *buf, size_t size)
857 + struct fb_info *info = dev_get_drvdata(dev);
858 + struct metronomefb_par *par = info->par;
860 + unsigned long val = simple_strtoul(buf, &after, 10);
861 + size_t count = after - buf;
862 + ssize_t ret = -EINVAL;
864 + if (*after && isspace(*after))
871 + if (count == size) {
873 + if (val != par->current_wf_temp)
874 + load_waveform((u8 *) par->firmware->data, par->firmware->size,
875 + par->current_wf_mode, val, par);
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);
891 static int __devinit metronomefb_probe(struct platform_device *dev)
893 struct fb_info *info;
894 @@ -607,6 +1069,9 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
896 panel_type = board->get_panel_type();
897 switch (panel_type) {
904 @@ -632,29 +1097,59 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
908 - memset(videomemory, 0, videomemorysize);
909 + memset(videomemory, 0xff, videomemorysize);
911 info->screen_base = (char __force __iomem *)videomemory;
912 info->fbops = &metronomefb_ops;
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) {
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;
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;
940 + info->fix.smem_len = fw * fh; /* Real size of image area */
944 - par->dt = epd_dt_index;
945 + par->epd_frame = &epd_frame_table[epd_dt_index];
948 + par->rotation = board->panel_rotation;
950 + par->fxbuckets = kmalloc((fw / 4 + 1) * sizeof(*par->fxbuckets), GFP_KERNEL);
951 + if (!par->fxbuckets)
954 + par->fybuckets = kmalloc(fh * sizeof(*par->fybuckets), GFP_KERNEL);
955 + if (!par->fybuckets)
956 + goto err_fxbuckets;
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);
965 /* this table caches per page csum values. */
966 par->csum_table = vmalloc(videomemorysize/PAGE_SIZE);
967 if (!par->csum_table)
969 + goto err_fybuckets;
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)
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,
980 - release_firmware(fw_entry);
982 dev_err(&dev->dev, "Failed processing waveform\n");
985 + par->firmware = fw_entry;
987 + retval = board->setup_io(par);
989 + dev_err(&dev->dev, "metronomefb: setup_io() failed\n");
990 + goto err_csum_table;
993 if (board->setup_irq(info))
995 @@ -712,7 +1213,7 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
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);
1004 @@ -722,18 +1223,47 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
1006 platform_set_drvdata(dev, info);
1008 - dev_dbg(&dev->dev,
1009 + retval = device_create_file(info->dev, &dev_attr_defio_delay);
1011 + goto err_devattr_defio_delay;
1013 + retval = device_create_file(info->dev, &dev_attr_manual_refresh_threshold);
1015 + goto err_devattr_manual_refresh_thr;
1017 + retval = device_create_file(info->dev, &dev_attr_temp);
1019 + goto err_devattr_temp;
1021 + retval = device_create_file(info->dev, &dev_attr_autorefresh_interval);
1023 + goto err_devattr_autorefresh;
1025 + dev_info(&dev->dev,
1026 "fb%d: Metronome frame buffer device, using %dK of video"
1027 " memory\n", info->node, videomemorysize >> 10);
1031 + device_remove_file(info->dev, &dev_attr_autorefresh_interval);
1032 +err_devattr_autorefresh:
1033 + device_remove_file(info->dev, &dev_attr_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);
1041 fb_dealloc_cmap(&info->cmap);
1043 board->cleanup(par);
1045 vfree(par->csum_table);
1047 + kfree(par->fybuckets);
1049 + kfree(par->fxbuckets);
1053 @@ -750,26 +1280,76 @@ static int __devexit metronomefb_remove(struct platform_device *dev)
1055 struct metronomefb_par *par = info->par;
1057 + par->board->set_stdby(par, 0);
1059 + if (par->board->power_ctl)
1060 + par->board->power_ctl(par, METRONOME_POWER_OFF);
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);
1083 +static int metronomefb_suspend(struct platform_device *pdev, pm_message_t message)
1085 + struct fb_info *info = platform_get_drvdata(pdev);
1086 + struct metronomefb_par *par = info->par;
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);
1097 +static int metronomefb_resume(struct platform_device *pdev)
1099 + struct fb_info *info = platform_get_drvdata(pdev);
1100 + struct metronomefb_par *par = info->par;
1102 + if (par->board->power_ctl)
1103 + par->board->power_ctl(par, METRONOME_POWER_ON);
1105 + mutex_lock(&par->lock);
1106 + metronome_bootup(par);
1107 + mutex_unlock(&par->lock);
1113 +#define metronomefb_suspend NULL
1114 +#define metronomefb_resume NULL
1118 static struct platform_driver metronomefb_driver = {
1119 - .probe = metronomefb_probe,
1120 - .remove = metronomefb_remove,
1122 - .owner = THIS_MODULE,
1123 - .name = "metronomefb",
1126 + .owner = THIS_MODULE,
1127 + .name = "metronomefb",
1129 + .probe = metronomefb_probe,
1130 + .remove = __devexit_p(metronomefb_remove),
1131 + .suspend = metronomefb_suspend,
1132 + .resume = metronomefb_resume,
1135 static int __init metronomefb_init(void)
1136 @@ -782,8 +1362,8 @@ static void __exit metronomefb_exit(void)
1137 platform_driver_unregister(&metronomefb_driver);
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");
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 {
1153 u16 args[((64-2)/2)];
1156 +} __attribute__((packed));
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;
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;
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;
1184 + unsigned int partial_updates_count;
1185 + unsigned is_first_update:1;
1187 + struct mutex lock;
1190 +#define METRONOME_POWER_OFF 0
1191 +#define METRONOME_POWER_ON 1
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;
1212 - struct fb_info *host_fbinfo; /* the host LCD controller's fbi */
1213 + int panel_rotation;