2 * linux/drivers/video/metronomefb.c -- FB driver for Metronome controller
4 * Copyright (C) 2008, Jaya Kumar
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
10 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
12 * This work was made possible by help and equipment support from E-Ink
13 * Corporation. http://support.eink.com/community
15 * This driver is written to be used with the Metronome display controller.
16 * It was tested with an E-Ink 800x600 Vizplex EPD on a Gumstix Connex board
17 * using the Lyre interface board.
20 * - User must set metronomefb_enable=1 to enable it.
21 * - See Documentation/fb/metronomefb.txt for how metronome works.
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/string.h>
28 #include <linux/slab.h>
29 #include <linux/vmalloc.h>
30 #include <linux/delay.h>
31 #include <linux/interrupt.h>
33 #include <linux/init.h>
34 #include <linux/platform_device.h>
35 #include <linux/list.h>
36 #include <linux/firmware.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/uaccess.h>
39 #include <linux/irq.h>
41 #include <asm/arch/pxa-regs.h>
42 #include <asm/unaligned.h>
46 #define DPRINTK(f, a...) printk(KERN_DEBUG "%s: " f, __func__ , ## a)
48 #define DPRINTK(f, a...)
52 /* Display specific information */
56 struct metromem_desc
{
69 struct metronomefb_par
{
70 unsigned char *metromem
;
71 struct metromem_desc
*metromem_desc
;
72 struct metromem_cmd
*metromem_cmd
;
73 unsigned char *metromem_wfm
;
74 unsigned char *metromem_img
;
75 u16
*metromem_img_csum
;
78 dma_addr_t metromem_dma
;
79 dma_addr_t metromem_desc_dma
;
81 wait_queue_head_t waitq
;
85 /* frame differs from image. frame includes non-visible pixels */
87 int fw
; /* frame width */
88 int fh
; /* frame height */
91 static struct epd_frame epd_frame_table
[] = {
98 static struct fb_fix_screeninfo metronomefb_fix __devinitdata
= {
100 .type
= FB_TYPE_PACKED_PIXELS
,
101 .visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
,
105 .line_length
= DPY_W
,
106 .accel
= FB_ACCEL_NONE
,
109 static struct fb_var_screeninfo metronomefb_var __devinitdata
= {
112 .xres_virtual
= DPY_W
,
113 .yres_virtual
= DPY_H
,
118 .green
= { 0, 0, 0 },
120 .transp
= { 0, 0, 0 },
123 static unsigned int metronomefb_enable
;
125 struct waveform_hdr
{
142 } __attribute__ ((packed
));
144 /* main metronomefb functions */
145 static u8
calc_cksum(int start
, int end
, u8
*mem
)
150 for (i
= start
; i
< end
; i
++)
156 static u16
calc_img_cksum(u16
*start
, int length
)
166 /* here we decode the incoming waveform file and populate metromem */
167 #define EXP_WFORM_SIZE 47001
168 static int load_waveform(u8
*mem
, size_t size
, u8
*metromem
, int m
, int t
,
178 int wfm_idx
, owfm_idx
;
180 struct waveform_hdr
*wfm_hdr
;
182 if (size
!= EXP_WFORM_SIZE
) {
183 printk(KERN_ERR
"Error: unexpected size %d != %d\n", size
,
188 wfm_hdr
= (struct waveform_hdr
*) mem
;
190 if (wfm_hdr
->fvsn
!= 1) {
191 printk(KERN_ERR
"Error: bad fvsn %x\n", wfm_hdr
->fvsn
);
194 if (wfm_hdr
->luts
!= 0) {
195 printk(KERN_ERR
"Error: bad luts %x\n", wfm_hdr
->luts
);
198 cksum
= calc_cksum(32, 47, mem
);
199 if (cksum
!= wfm_hdr
->wfm_cs
) {
200 printk(KERN_ERR
"Error: bad cksum %x != %x\n", cksum
,
206 for (i
= 0; i
< 5; i
++) {
207 if (*(wfm_hdr
->stuff2a
+ i
) != 0) {
208 printk(KERN_ERR
"Error: unexpected value in padding\n");
213 /* calculating trn. trn is something used to index into
214 the waveform. presumably selecting the right one for the
215 desired temperature. it works out the offset of the first
216 v that exceeds the specified temperature */
217 if ((sizeof(*wfm_hdr
) + wfm_hdr
->trc
) > size
)
220 for (i
= sizeof(*wfm_hdr
); i
<= sizeof(*wfm_hdr
) + wfm_hdr
->trc
; i
++) {
222 trn
= i
- sizeof(*wfm_hdr
) - 1;
227 /* check temperature range table checksum */
228 cksum_idx
= sizeof(*wfm_hdr
) + wfm_hdr
->trc
+ 1;
229 if (cksum_idx
> size
)
231 cksum
= calc_cksum(sizeof(*wfm_hdr
), cksum_idx
, mem
);
232 if (cksum
!= mem
[cksum_idx
]) {
233 printk(KERN_ERR
"Error: bad temperature range table cksum"
234 " %x != %x\n", cksum
, mem
[cksum_idx
]);
238 /* check waveform mode table address checksum */
239 wmta
= le32_to_cpu(get_unaligned((__le32
*) wfm_hdr
->wmta
));
241 cksum_idx
= wmta
+ m
*4 + 3;
242 if (cksum_idx
> size
)
244 cksum
= calc_cksum(cksum_idx
- 3, cksum_idx
, mem
);
245 if (cksum
!= mem
[cksum_idx
]) {
246 printk(KERN_ERR
"Error: bad mode table address cksum"
247 " %x != %x\n", cksum
, mem
[cksum_idx
]);
251 /* check waveform temperature table address checksum */
252 tta
= le32_to_cpu(get_unaligned((int *) (mem
+ wmta
+ m
*4)));
254 cksum_idx
= tta
+ trn
*4 + 3;
255 if (cksum_idx
> size
)
257 cksum
= calc_cksum(cksum_idx
- 3, cksum_idx
, mem
);
258 if (cksum
!= mem
[cksum_idx
]) {
259 printk(KERN_ERR
"Error: bad temperature table address cksum"
260 " %x != %x\n", cksum
, mem
[cksum_idx
]);
264 /* here we do the real work of putting the waveform into the
265 metromem buffer. this does runlength decoding of the waveform */
266 wfm_idx
= le32_to_cpu(get_unaligned((__le32
*) (mem
+ tta
+ trn
*4)));
267 wfm_idx
&= 0x00FFFFFF;
271 while (wfm_idx
< size
) {
274 if (v
== wfm_hdr
->swtb
) {
275 while (((v
= mem
[wfm_idx
++]) != wfm_hdr
->swtb
) &&
277 metromem
[mem_idx
++] = v
;
282 if (v
== wfm_hdr
->endb
)
286 for (i
= 0; i
<= rl
; i
++)
287 metromem
[mem_idx
++] = v
;
291 if (cksum_idx
> size
)
293 cksum
= calc_cksum(owfm_idx
, cksum_idx
, mem
);
294 if (cksum
!= mem
[cksum_idx
]) {
295 printk(KERN_ERR
"Error: bad waveform data cksum"
296 " %x != %x\n", cksum
, mem
[cksum_idx
]);
299 *frame_count
= (mem_idx
/64);
304 /* register offsets for gpio control */
305 #define LED_GPIO_PIN 51
306 #define STDBY_GPIO_PIN 48
307 #define RST_GPIO_PIN 49
308 #define RDY_GPIO_PIN 32
309 #define ERR_GPIO_PIN 17
310 #define PCBPWR_GPIO_PIN 16
312 #define AF_SEL_GPIO_N 0x3
313 #define GAFR0_U_OFFSET(pin) ((pin - 16) * 2)
314 #define GAFR1_L_OFFSET(pin) ((pin - 32) * 2)
315 #define GAFR1_U_OFFSET(pin) ((pin - 48) * 2)
316 #define GPDR1_OFFSET(pin) (pin - 32)
317 #define GPCR1_OFFSET(pin) (pin - 32)
318 #define GPSR1_OFFSET(pin) (pin - 32)
319 #define GPCR0_OFFSET(pin) (pin)
320 #define GPSR0_OFFSET(pin) (pin)
322 static void metronome_set_gpio_output(int pin
, int val
)
331 GPSR0
|= (1 << GPSR0_OFFSET(pin
));
333 GPCR0
|= (1 << GPCR0_OFFSET(pin
));
339 GPSR1
|= (1 << GPSR1_OFFSET(pin
));
341 GPCR1
|= (1 << GPCR1_OFFSET(pin
));
344 printk(KERN_ERR
"unimplemented\n");
348 static void __devinit
metronome_init_gpio_pin(int pin
, int dir
)
351 /* dir 0 is output, 1 is input
353 - set gpio alternate function to standard gpio
354 - set gpio direction to input or output */
359 GAFR0_U
&= ~(AF_SEL_GPIO_N
<< GAFR0_U_OFFSET(pin
));
362 GPDR0
&= ~(1 << pin
);
367 GAFR1_L
&= ~(AF_SEL_GPIO_N
<< GAFR1_L_OFFSET(pin
));
370 GPDR1
&= ~(1 << GPDR1_OFFSET(pin
));
372 GPDR1
|= (1 << GPDR1_OFFSET(pin
));
375 GAFR1_U
&= ~(AF_SEL_GPIO_N
<< GAFR1_U_OFFSET(pin
));
378 GPDR1
&= ~(1 << GPDR1_OFFSET(pin
));
380 GPDR1
|= (1 << GPDR1_OFFSET(pin
));
383 printk(KERN_ERR
"unimplemented\n");
387 static void __devinit
metronome_init_gpio_regs(void)
389 metronome_init_gpio_pin(LED_GPIO_PIN
, 0);
390 metronome_set_gpio_output(LED_GPIO_PIN
, 0);
392 metronome_init_gpio_pin(STDBY_GPIO_PIN
, 0);
393 metronome_set_gpio_output(STDBY_GPIO_PIN
, 0);
395 metronome_init_gpio_pin(RST_GPIO_PIN
, 0);
396 metronome_set_gpio_output(RST_GPIO_PIN
, 0);
398 metronome_init_gpio_pin(RDY_GPIO_PIN
, 1);
400 metronome_init_gpio_pin(ERR_GPIO_PIN
, 1);
402 metronome_init_gpio_pin(PCBPWR_GPIO_PIN
, 0);
403 metronome_set_gpio_output(PCBPWR_GPIO_PIN
, 0);
406 static void metronome_disable_lcd_controller(struct metronomefb_par
*par
)
408 LCSR
= 0xffffffff; /* Clear LCD Status Register */
409 LCCR0
|= LCCR0_DIS
; /* Disable LCD Controller */
411 /* we reset and just wait for things to settle */
415 static void metronome_enable_lcd_controller(struct metronomefb_par
*par
)
418 FDADR0
= par
->metromem_desc_dma
;
422 static void __devinit
metronome_init_lcdc_regs(struct metronomefb_par
*par
)
425 - disable the lcd controller
426 - setup lcd control registers
427 - setup dma descriptor
428 - reenable lcd controller
431 /* disable the lcd controller */
432 metronome_disable_lcd_controller(par
);
434 /* setup lcd control registers */
435 LCCR0
= LCCR0_LDM
| LCCR0_SFM
| LCCR0_IUM
| LCCR0_EFM
| LCCR0_PAS
436 | LCCR0_QDM
| LCCR0_BM
| LCCR0_OUM
;
438 LCCR1
= (epd_frame_table
[0].fw
/2 - 1) /* pixels per line */
439 | (27 << 10) /* hsync pulse width - 1 */
440 | (33 << 16) /* eol pixel count */
441 | (33 << 24); /* bol pixel count */
443 LCCR2
= (epd_frame_table
[0].fh
- 1) /* lines per panel */
444 | (24 << 10) /* vsync pulse width - 1 */
445 | (2 << 16) /* eof pixel count */
446 | (0 << 24); /* bof pixel count */
448 LCCR3
= 2 /* pixel clock divisor */
449 | (24 << 8) /* AC Bias pin freq */
450 | LCCR3_16BPP
/* BPP */
451 | LCCR3_PCP
; /* PCP falling edge */
453 /* setup dma descriptor */
454 par
->metromem_desc
->mFDADR0
= par
->metromem_desc_dma
;
455 par
->metromem_desc
->mFSADR0
= par
->metromem_dma
;
456 par
->metromem_desc
->mFIDR0
= 0;
457 par
->metromem_desc
->mLDCMD0
= epd_frame_table
[0].fw
458 * epd_frame_table
[0].fh
;
459 /* reenable lcd controller */
460 metronome_enable_lcd_controller(par
);
463 static int metronome_display_cmd(struct metronomefb_par
*par
)
471 /* setup display command
472 we can't immediately set the opcode since the controller
473 will try parse the command before we've set it all up
474 so we just set cs here and set the opcode at the end */
478 if (par
->metromem_cmd
->opcode
== 0xCC40)
479 opcode
= cs
= 0xCC41;
481 opcode
= cs
= 0xCC40;
483 /* set the args ( 2 bytes ) for display */
485 par
->metromem_cmd
->args
[i
] = 1 << 3 /* border update */
486 | ((borderval
++ % 4) & 0x0F) << 4
487 | (par
->frame_count
- 1) << 8;
488 cs
+= par
->metromem_cmd
->args
[i
++];
491 memset((u8
*) (par
->metromem_cmd
->args
+ i
), 0, (32-i
)*2);
493 par
->metromem_cmd
->csum
= cs
;
494 par
->metromem_cmd
->opcode
= opcode
; /* display cmd */
496 i
= wait_event_interruptible_timeout(par
->waitq
, (GPLR1
& 0x01), HZ
);
500 static int __devinit
metronome_powerup_cmd(struct metronomefb_par
*par
)
505 /* setup power up command */
506 par
->metromem_cmd
->opcode
= 0x1234; /* pwr up pseudo cmd */
507 cs
= par
->metromem_cmd
->opcode
;
509 /* set pwr1,2,3 to 1024 */
510 for (i
= 0; i
< 3; i
++) {
511 par
->metromem_cmd
->args
[i
] = 1024;
512 cs
+= par
->metromem_cmd
->args
[i
];
516 memset((u8
*) (par
->metromem_cmd
->args
+ i
), 0, (32-i
)*2);
518 par
->metromem_cmd
->csum
= cs
;
521 metronome_set_gpio_output(RST_GPIO_PIN
, 1);
524 metronome_set_gpio_output(STDBY_GPIO_PIN
, 1);
526 i
= wait_event_timeout(par
->waitq
, (GPLR1
& 0x01), HZ
);
530 static int __devinit
metronome_config_cmd(struct metronomefb_par
*par
)
535 /* setup config command
536 we can't immediately set the opcode since the controller
537 will try parse the command before we've set it all up
538 so we just set cs here and set the opcode at the end */
542 /* set the 12 args ( 8 bytes ) for config. see spec for meanings */
544 par
->metromem_cmd
->args
[i
] = 15 /* sdlew */
547 | 0 << 12 /* sdces */
548 | 0 << 15; /* sdcer */
549 cs
+= par
->metromem_cmd
->args
[i
++];
551 par
->metromem_cmd
->args
[i
] = 42 /* gdspl */
554 | 0 << 15; /* gdspp */
555 cs
+= par
->metromem_cmd
->args
[i
++];
557 par
->metromem_cmd
->args
[i
] = 18 /* gdspw */
558 | 0 << 15; /* dispc */
559 cs
+= par
->metromem_cmd
->args
[i
++];
561 par
->metromem_cmd
->args
[i
] = 599 /* vdlc */
563 | 0 << 12; /* dsic */
564 cs
+= par
->metromem_cmd
->args
[i
++];
567 memset((u8
*) (par
->metromem_cmd
->args
+ i
), 0, (32-i
)*2);
569 par
->metromem_cmd
->csum
= cs
;
570 par
->metromem_cmd
->opcode
= 0xCC10; /* config cmd */
572 i
= wait_event_timeout(par
->waitq
, (GPLR1
& 0x01), HZ
);
576 static int __devinit
metronome_init_cmd(struct metronomefb_par
*par
)
581 /* setup init command
582 we can't immediately set the opcode since the controller
583 will try parse the command before we've set it all up
584 so we just set cs here and set the opcode at the end */
588 /* set the args ( 2 bytes ) for init */
590 par
->metromem_cmd
->args
[i
] = 0;
591 cs
+= par
->metromem_cmd
->args
[i
++];
594 memset((u8
*) (par
->metromem_cmd
->args
+ i
), 0, (32-i
)*2);
596 par
->metromem_cmd
->csum
= cs
;
597 par
->metromem_cmd
->opcode
= 0xCC20; /* init cmd */
599 i
= wait_event_timeout(par
->waitq
, (GPLR1
& 0x01), HZ
);
603 static int __devinit
metronome_init_regs(struct metronomefb_par
*par
)
607 metronome_init_gpio_regs();
608 metronome_init_lcdc_regs(par
);
610 res
= metronome_powerup_cmd(par
);
614 res
= metronome_config_cmd(par
);
618 res
= metronome_init_cmd(par
);
625 static void metronomefb_dpy_update(struct metronomefb_par
*par
)
628 unsigned char *buf
= (unsigned char __force
*)par
->info
->screen_base
;
630 /* copy from vm to metromem */
631 memcpy(par
->metromem_img
, buf
, DPY_W
*DPY_H
);
633 cksum
= calc_img_cksum((u16
*) par
->metromem_img
,
634 (epd_frame_table
[0].fw
* DPY_H
)/2);
635 *((u16
*) (par
->metromem_img
) +
636 (epd_frame_table
[0].fw
* DPY_H
)/2) = cksum
;
637 metronome_display_cmd(par
);
640 static u16
metronomefb_dpy_update_page(struct metronomefb_par
*par
, int index
)
644 u16
*buf
= (u16 __force
*) (par
->info
->screen_base
+ index
);
645 u16
*img
= (u16
*) (par
->metromem_img
+ index
);
647 /* swizzle from vm to metromem and recalc cksum at the same time*/
648 for (i
= 0; i
< PAGE_SIZE
/2; i
++) {
649 *(img
+ i
) = (buf
[i
] << 5) & 0xE0E0;
655 /* this is called back from the deferred io workqueue */
656 static void metronomefb_dpy_deferred_io(struct fb_info
*info
,
657 struct list_head
*pagelist
)
661 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
662 struct metronomefb_par
*par
= info
->par
;
664 /* walk the written page list and swizzle the data */
665 list_for_each_entry(cur
, &fbdefio
->pagelist
, lru
) {
666 cksum
= metronomefb_dpy_update_page(par
,
667 (cur
->index
<< PAGE_SHIFT
));
668 par
->metromem_img_csum
-= par
->csum_table
[cur
->index
];
669 par
->csum_table
[cur
->index
] = cksum
;
670 par
->metromem_img_csum
+= cksum
;
673 metronome_display_cmd(par
);
676 static void metronomefb_fillrect(struct fb_info
*info
,
677 const struct fb_fillrect
*rect
)
679 struct metronomefb_par
*par
= info
->par
;
681 sys_fillrect(info
, rect
);
682 metronomefb_dpy_update(par
);
685 static void metronomefb_copyarea(struct fb_info
*info
,
686 const struct fb_copyarea
*area
)
688 struct metronomefb_par
*par
= info
->par
;
690 sys_copyarea(info
, area
);
691 metronomefb_dpy_update(par
);
694 static void metronomefb_imageblit(struct fb_info
*info
,
695 const struct fb_image
*image
)
697 struct metronomefb_par
*par
= info
->par
;
699 sys_imageblit(info
, image
);
700 metronomefb_dpy_update(par
);
704 * this is the slow path from userspace. they can seek and write to
705 * the fb. it is based on fb_sys_write
707 static ssize_t
metronomefb_write(struct fb_info
*info
, const char __user
*buf
,
708 size_t count
, loff_t
*ppos
)
710 struct metronomefb_par
*par
= info
->par
;
711 unsigned long p
= *ppos
;
714 unsigned long total_size
;
716 if (info
->state
!= FBINFO_STATE_RUNNING
)
719 total_size
= info
->fix
.smem_len
;
724 if (count
> total_size
) {
729 if (count
+ p
> total_size
) {
733 count
= total_size
- p
;
736 dst
= (void __force
*) (info
->screen_base
+ p
);
738 if (copy_from_user(dst
, buf
, count
))
744 metronomefb_dpy_update(par
);
746 return (err
) ? err
: count
;
749 static struct fb_ops metronomefb_ops
= {
750 .owner
= THIS_MODULE
,
751 .fb_write
= metronomefb_write
,
752 .fb_fillrect
= metronomefb_fillrect
,
753 .fb_copyarea
= metronomefb_copyarea
,
754 .fb_imageblit
= metronomefb_imageblit
,
757 static struct fb_deferred_io metronomefb_defio
= {
759 .deferred_io
= metronomefb_dpy_deferred_io
,
762 static irqreturn_t
metronome_handle_irq(int irq
, void *dev_id
)
764 struct fb_info
*info
= dev_id
;
765 struct metronomefb_par
*par
= info
->par
;
767 wake_up_interruptible(&par
->waitq
);
771 static int __devinit
metronomefb_probe(struct platform_device
*dev
)
773 struct fb_info
*info
;
774 int retval
= -ENOMEM
;
776 unsigned char *videomemory
;
777 struct metronomefb_par
*par
;
778 const struct firmware
*fw_entry
;
779 int cmd_size
, wfm_size
, img_size
, padding_size
, totalsize
;
782 /* we have two blocks of memory.
783 info->screen_base which is vm, and is the fb used by apps.
784 par->metromem which is physically contiguous memory and
785 contains the display controller commands, waveform,
786 processed image data and padding. this is the data pulled
787 by the pxa255's LCD controller and pushed to Metronome */
789 videomemorysize
= (DPY_W
*DPY_H
);
790 videomemory
= vmalloc(videomemorysize
);
794 memset(videomemory
, 0, videomemorysize
);
796 info
= framebuffer_alloc(sizeof(struct metronomefb_par
), &dev
->dev
);
800 info
->screen_base
= (char __iomem
*) videomemory
;
801 info
->fbops
= &metronomefb_ops
;
803 info
->var
= metronomefb_var
;
804 info
->fix
= metronomefb_fix
;
805 info
->fix
.smem_len
= videomemorysize
;
808 init_waitqueue_head(&par
->waitq
);
810 /* this table caches per page csum values. */
811 par
->csum_table
= vmalloc(videomemorysize
/PAGE_SIZE
);
812 if (!par
->csum_table
)
815 /* the metromem buffer is divided as follows:
816 command | CRC | padding
817 16kb waveform data | CRC | padding
819 and an extra 256 bytes for dma descriptors
820 eg: IW=832 IH=622 WS=128
823 cmd_size
= 1 * epd_frame_table
[0].fw
;
824 wfm_size
= ((16*1024 + 2 + epd_frame_table
[0].fw
- 1)
825 / epd_frame_table
[0].fw
) * epd_frame_table
[0].fw
;
826 img_size
= epd_frame_table
[0].fh
* epd_frame_table
[0].fw
;
827 padding_size
= 4 * epd_frame_table
[0].fw
;
828 totalsize
= cmd_size
+ wfm_size
+ img_size
+ padding_size
;
829 par
->metromemsize
= PAGE_ALIGN(totalsize
+ 256);
830 DPRINTK("desired memory size = %d\n", par
->metromemsize
);
831 dev
->dev
.coherent_dma_mask
= 0xffffffffull
;
832 par
->metromem
= dma_alloc_writecombine(&dev
->dev
, par
->metromemsize
,
833 &par
->metromem_dma
, GFP_KERNEL
);
834 if (!par
->metromem
) {
836 "metronomefb: unable to allocate dma buffer\n");
840 info
->fix
.smem_start
= par
->metromem_dma
;
841 par
->metromem_cmd
= (struct metromem_cmd
*) par
->metromem
;
842 par
->metromem_wfm
= par
->metromem
+ cmd_size
;
843 par
->metromem_img
= par
->metromem
+ cmd_size
+ wfm_size
;
844 par
->metromem_img_csum
= (u16
*) (par
->metromem_img
+
845 (epd_frame_table
[0].fw
* DPY_H
));
846 DPRINTK("img offset=0x%x\n", cmd_size
+ wfm_size
);
847 par
->metromem_desc
= (struct metromem_desc
*) (par
->metromem
+ cmd_size
848 + wfm_size
+ img_size
+ padding_size
);
849 par
->metromem_desc_dma
= par
->metromem_dma
+ cmd_size
+ wfm_size
850 + img_size
+ padding_size
;
852 /* load the waveform in. assume mode 3, temp 31 for now */
853 /* a) request the waveform file from userspace
854 b) process waveform and decode into metromem */
856 retval
= request_firmware(&fw_entry
, "waveform.wbf", &dev
->dev
);
858 printk(KERN_ERR
"metronomefb: couldn't get waveform\n");
862 retval
= load_waveform((u8
*) fw_entry
->data
, fw_entry
->size
,
863 par
->metromem_wfm
, 3, 31, &par
->frame_count
);
865 printk(KERN_ERR
"metronomefb: couldn't process waveform\n");
868 release_firmware(fw_entry
);
870 retval
= request_irq(IRQ_GPIO(RDY_GPIO_PIN
), metronome_handle_irq
,
871 IRQF_DISABLED
, "Metronome", info
);
873 dev_err(&dev
->dev
, "request_irq failed: %d\n", retval
);
876 set_irq_type(IRQ_GPIO(RDY_GPIO_PIN
), IRQT_FALLING
);
878 retval
= metronome_init_regs(par
);
882 info
->flags
= FBINFO_FLAG_DEFAULT
;
884 info
->fbdefio
= &metronomefb_defio
;
885 fb_deferred_io_init(info
);
887 retval
= fb_alloc_cmap(&info
->cmap
, 8, 0);
889 printk(KERN_ERR
"Failed to allocate colormap\n");
894 for (i
= 0; i
< 8; i
++)
895 info
->cmap
.red
[i
] = (((2*i
)+1)*(0xFFFF))/16;
896 memcpy(info
->cmap
.green
, info
->cmap
.red
, sizeof(u16
)*8);
897 memcpy(info
->cmap
.blue
, info
->cmap
.red
, sizeof(u16
)*8);
899 retval
= register_framebuffer(info
);
903 platform_set_drvdata(dev
, info
);
906 "fb%d: Metronome frame buffer device, using %dK of video"
907 " memory\n", info
->node
, videomemorysize
>> 10);
912 fb_dealloc_cmap(&info
->cmap
);
914 framebuffer_release(info
);
916 free_irq(IRQ_GPIO(RDY_GPIO_PIN
), info
);
918 release_firmware(fw_entry
);
920 dma_free_writecombine(&dev
->dev
, par
->metromemsize
, par
->metromem
,
923 vfree(par
->csum_table
);
929 static int __devexit
metronomefb_remove(struct platform_device
*dev
)
931 struct fb_info
*info
= platform_get_drvdata(dev
);
934 struct metronomefb_par
*par
= info
->par
;
935 fb_deferred_io_cleanup(info
);
936 dma_free_writecombine(&dev
->dev
, par
->metromemsize
,
937 par
->metromem
, par
->metromem_dma
);
938 fb_dealloc_cmap(&info
->cmap
);
939 vfree(par
->csum_table
);
940 unregister_framebuffer(info
);
941 vfree((void __force
*)info
->screen_base
);
942 free_irq(IRQ_GPIO(RDY_GPIO_PIN
), info
);
943 framebuffer_release(info
);
948 static struct platform_driver metronomefb_driver
= {
949 .probe
= metronomefb_probe
,
950 .remove
= metronomefb_remove
,
952 .name
= "metronomefb",
956 static struct platform_device
*metronomefb_device
;
958 static int __init
metronomefb_init(void)
962 if (!metronomefb_enable
) {
964 "Use metronomefb_enable to enable the device\n");
968 ret
= platform_driver_register(&metronomefb_driver
);
970 metronomefb_device
= platform_device_alloc("metronomefb", 0);
971 if (metronomefb_device
)
972 ret
= platform_device_add(metronomefb_device
);
977 platform_device_put(metronomefb_device
);
978 platform_driver_unregister(&metronomefb_driver
);
985 static void __exit
metronomefb_exit(void)
987 platform_device_unregister(metronomefb_device
);
988 platform_driver_unregister(&metronomefb_driver
);
991 module_param(metronomefb_enable
, uint
, 0);
992 MODULE_PARM_DESC(metronomefb_enable
, "Enable communication with Metronome");
994 module_init(metronomefb_init
);
995 module_exit(metronomefb_exit
);
997 MODULE_DESCRIPTION("fbdev driver for Metronome controller");
998 MODULE_AUTHOR("Jaya Kumar");
999 MODULE_LICENSE("GPL");