2 * linux/drivers/video/am200epd.c -- Platform device for AM200 EPD kit
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 * on the AM200 EPD prototype kit/development kit with an E-Ink 800x600
17 * Vizplex EPD on a Gumstix board using the Lyre interface board.
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/string.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/platform_device.h>
30 #include <linux/list.h>
31 #include <linux/uaccess.h>
32 #include <linux/irq.h>
34 #include <video/metronomefb.h>
36 #include <mach/pxa-regs.h>
38 /* register offsets for gpio control */
39 #define LED_GPIO_PIN 51
40 #define STDBY_GPIO_PIN 48
41 #define RST_GPIO_PIN 49
42 #define RDY_GPIO_PIN 32
43 #define ERR_GPIO_PIN 17
44 #define PCBPWR_GPIO_PIN 16
46 #define AF_SEL_GPIO_N 0x3
47 #define GAFR0_U_OFFSET(pin) ((pin - 16) * 2)
48 #define GAFR1_L_OFFSET(pin) ((pin - 32) * 2)
49 #define GAFR1_U_OFFSET(pin) ((pin - 48) * 2)
50 #define GPDR1_OFFSET(pin) (pin - 32)
51 #define GPCR1_OFFSET(pin) (pin - 32)
52 #define GPSR1_OFFSET(pin) (pin - 32)
53 #define GPCR0_OFFSET(pin) (pin)
54 #define GPSR0_OFFSET(pin) (pin)
56 static void am200_set_gpio_output(int pin
, int val
)
65 GPSR0
|= (1 << GPSR0_OFFSET(pin
));
67 GPCR0
|= (1 << GPCR0_OFFSET(pin
));
73 GPSR1
|= (1 << GPSR1_OFFSET(pin
));
75 GPCR1
|= (1 << GPCR1_OFFSET(pin
));
78 printk(KERN_ERR
"unimplemented\n");
82 static void __devinit
am200_init_gpio_pin(int pin
, int dir
)
85 /* dir 0 is output, 1 is input
87 - set gpio alternate function to standard gpio
88 - set gpio direction to input or output */
93 GAFR0_U
&= ~(AF_SEL_GPIO_N
<< GAFR0_U_OFFSET(pin
));
101 GAFR1_L
&= ~(AF_SEL_GPIO_N
<< GAFR1_L_OFFSET(pin
));
104 GPDR1
&= ~(1 << GPDR1_OFFSET(pin
));
106 GPDR1
|= (1 << GPDR1_OFFSET(pin
));
109 GAFR1_U
&= ~(AF_SEL_GPIO_N
<< GAFR1_U_OFFSET(pin
));
112 GPDR1
&= ~(1 << GPDR1_OFFSET(pin
));
114 GPDR1
|= (1 << GPDR1_OFFSET(pin
));
117 printk(KERN_ERR
"unimplemented\n");
121 static void am200_init_gpio_regs(struct metronomefb_par
*par
)
123 am200_init_gpio_pin(LED_GPIO_PIN
, 0);
124 am200_set_gpio_output(LED_GPIO_PIN
, 0);
126 am200_init_gpio_pin(STDBY_GPIO_PIN
, 0);
127 am200_set_gpio_output(STDBY_GPIO_PIN
, 0);
129 am200_init_gpio_pin(RST_GPIO_PIN
, 0);
130 am200_set_gpio_output(RST_GPIO_PIN
, 0);
132 am200_init_gpio_pin(RDY_GPIO_PIN
, 1);
134 am200_init_gpio_pin(ERR_GPIO_PIN
, 1);
136 am200_init_gpio_pin(PCBPWR_GPIO_PIN
, 0);
137 am200_set_gpio_output(PCBPWR_GPIO_PIN
, 0);
140 static void am200_disable_lcd_controller(struct metronomefb_par
*par
)
142 LCSR
= 0xffffffff; /* Clear LCD Status Register */
143 LCCR0
|= LCCR0_DIS
; /* Disable LCD Controller */
145 /* we reset and just wait for things to settle */
149 static void am200_enable_lcd_controller(struct metronomefb_par
*par
)
152 FDADR0
= par
->metromem_desc_dma
;
156 static void am200_init_lcdc_regs(struct metronomefb_par
*par
)
159 - disable the lcd controller
160 - setup lcd control registers
161 - setup dma descriptor
162 - reenable lcd controller
165 /* disable the lcd controller */
166 am200_disable_lcd_controller(par
);
168 /* setup lcd control registers */
169 LCCR0
= LCCR0_LDM
| LCCR0_SFM
| LCCR0_IUM
| LCCR0_EFM
| LCCR0_PAS
170 | LCCR0_QDM
| LCCR0_BM
| LCCR0_OUM
;
172 LCCR1
= (par
->info
->var
.xres
/2 - 1) /* pixels per line */
173 | (27 << 10) /* hsync pulse width - 1 */
174 | (33 << 16) /* eol pixel count */
175 | (33 << 24); /* bol pixel count */
177 LCCR2
= (par
->info
->var
.yres
- 1) /* lines per panel */
178 | (24 << 10) /* vsync pulse width - 1 */
179 | (2 << 16) /* eof pixel count */
180 | (0 << 24); /* bof pixel count */
182 LCCR3
= 2 /* pixel clock divisor */
183 | (24 << 8) /* AC Bias pin freq */
184 | LCCR3_16BPP
/* BPP */
185 | LCCR3_PCP
; /* PCP falling edge */
189 static void am200_post_dma_setup(struct metronomefb_par
*par
)
191 par
->metromem_desc
->mFDADR0
= par
->metromem_desc_dma
;
192 par
->metromem_desc
->mFSADR0
= par
->metromem_dma
;
193 par
->metromem_desc
->mFIDR0
= 0;
194 par
->metromem_desc
->mLDCMD0
= par
->info
->var
.xres
195 * par
->info
->var
.yres
;
196 am200_enable_lcd_controller(par
);
199 static void am200_free_irq(struct fb_info
*info
)
201 free_irq(IRQ_GPIO(RDY_GPIO_PIN
), info
);
204 static irqreturn_t
am200_handle_irq(int irq
, void *dev_id
)
206 struct fb_info
*info
= dev_id
;
207 struct metronomefb_par
*par
= info
->par
;
209 wake_up_interruptible(&par
->waitq
);
213 static int am200_setup_irq(struct fb_info
*info
)
217 retval
= request_irq(IRQ_GPIO(RDY_GPIO_PIN
), am200_handle_irq
,
218 IRQF_DISABLED
, "AM200", info
);
220 printk(KERN_ERR
"am200epd: request_irq failed: %d\n", retval
);
224 return set_irq_type(IRQ_GPIO(RDY_GPIO_PIN
), IRQ_TYPE_EDGE_FALLING
);
227 static void am200_set_rst(struct metronomefb_par
*par
, int state
)
229 am200_set_gpio_output(RST_GPIO_PIN
, state
);
232 static void am200_set_stdby(struct metronomefb_par
*par
, int state
)
234 am200_set_gpio_output(STDBY_GPIO_PIN
, state
);
237 static int am200_wait_event(struct metronomefb_par
*par
)
239 return wait_event_timeout(par
->waitq
, (GPLR1
& 0x01), HZ
);
242 static int am200_wait_event_intr(struct metronomefb_par
*par
)
244 return wait_event_interruptible_timeout(par
->waitq
, (GPLR1
& 0x01), HZ
);
247 static struct metronome_board am200_board
= {
248 .owner
= THIS_MODULE
,
249 .free_irq
= am200_free_irq
,
250 .setup_irq
= am200_setup_irq
,
251 .init_gpio_regs
= am200_init_gpio_regs
,
252 .init_lcdc_regs
= am200_init_lcdc_regs
,
253 .post_dma_setup
= am200_post_dma_setup
,
254 .set_rst
= am200_set_rst
,
255 .set_stdby
= am200_set_stdby
,
256 .met_wait_event
= am200_wait_event
,
257 .met_wait_event_intr
= am200_wait_event_intr
,
260 static struct platform_device
*am200_device
;
262 static int __init
am200_init(void)
266 /* request our platform independent driver */
267 request_module("metronomefb");
269 am200_device
= platform_device_alloc("metronomefb", -1);
273 platform_device_add_data(am200_device
, &am200_board
,
274 sizeof(am200_board
));
276 /* this _add binds metronomefb to am200. metronomefb refcounts am200 */
277 ret
= platform_device_add(am200_device
);
280 platform_device_put(am200_device
);
285 static void __exit
am200_exit(void)
287 platform_device_unregister(am200_device
);
290 module_init(am200_init
);
291 module_exit(am200_exit
);
293 MODULE_DESCRIPTION("board driver for am200 metronome epd kit");
294 MODULE_AUTHOR("Jaya Kumar");
295 MODULE_LICENSE("GPL");