2 * 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/irq.h>
31 #include <linux/gpio.h>
33 #include <mach/pxafb.h>
35 #include <video/metronomefb.h>
37 static unsigned int panel_type
= 6;
38 static struct platform_device
*am200_device
;
39 static struct metronome_board am200_board
;
41 static struct pxafb_mode_info am200_fb_mode_9inch7
= {
52 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
55 static struct pxafb_mode_info am200_fb_mode_8inch
= {
66 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
69 static struct pxafb_mode_info am200_fb_mode_6inch
= {
80 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
83 static struct pxafb_mach_info am200_fb_info
= {
84 .modes
= &am200_fb_mode_6inch
,
86 .lcd_conn
= LCD_TYPE_COLOR_TFT
| LCD_PCLK_EDGE_FALL
|
90 /* register offsets for gpio control */
91 #define LED_GPIO_PIN 51
92 #define STDBY_GPIO_PIN 48
93 #define RST_GPIO_PIN 49
94 #define RDY_GPIO_PIN 32
95 #define ERR_GPIO_PIN 17
96 #define PCBPWR_GPIO_PIN 16
97 static int gpios
[] = { LED_GPIO_PIN
, STDBY_GPIO_PIN
, RST_GPIO_PIN
,
98 RDY_GPIO_PIN
, ERR_GPIO_PIN
, PCBPWR_GPIO_PIN
};
99 static char *gpio_names
[] = { "LED" , "STDBY" , "RST", "RDY", "ERR", "PCBPWR" };
101 static int am200_init_gpio_regs(struct metronomefb_par
*par
)
106 for (i
= 0; i
< ARRAY_SIZE(gpios
); i
++) {
107 err
= gpio_request(gpios
[i
], gpio_names
[i
]);
109 dev_err(&am200_device
->dev
, "failed requesting "
110 "gpio %s, err=%d\n", gpio_names
[i
], err
);
115 gpio_direction_output(LED_GPIO_PIN
, 0);
116 gpio_direction_output(STDBY_GPIO_PIN
, 0);
117 gpio_direction_output(RST_GPIO_PIN
, 0);
119 gpio_direction_input(RDY_GPIO_PIN
);
120 gpio_direction_input(ERR_GPIO_PIN
);
122 gpio_direction_output(PCBPWR_GPIO_PIN
, 0);
128 gpio_free(gpios
[i
--]);
133 static void am200_cleanup(struct metronomefb_par
*par
)
137 free_irq(IRQ_GPIO(RDY_GPIO_PIN
), par
);
139 for (i
= 0; i
< ARRAY_SIZE(gpios
); i
++)
143 static int am200_share_video_mem(struct fb_info
*info
)
145 /* rough check if this is our desired fb and not something else */
146 if ((info
->var
.xres
!= am200_fb_info
.modes
->xres
)
147 || (info
->var
.yres
!= am200_fb_info
.modes
->yres
))
150 /* we've now been notified that we have our new fb */
151 am200_board
.metromem
= info
->screen_base
;
152 am200_board
.host_fbinfo
= info
;
154 /* try to refcount host drv since we are the consumer after this */
155 if (!try_module_get(info
->fbops
->owner
))
161 static int am200_unshare_video_mem(struct fb_info
*info
)
163 dev_dbg(&am200_device
->dev
, "ENTER %s\n", __func__
);
165 if (info
!= am200_board
.host_fbinfo
)
168 module_put(am200_board
.host_fbinfo
->fbops
->owner
);
172 static int am200_fb_notifier_callback(struct notifier_block
*self
,
173 unsigned long event
, void *data
)
175 struct fb_event
*evdata
= data
;
176 struct fb_info
*info
= evdata
->info
;
178 dev_dbg(&am200_device
->dev
, "ENTER %s\n", __func__
);
180 if (event
== FB_EVENT_FB_REGISTERED
)
181 return am200_share_video_mem(info
);
182 else if (event
== FB_EVENT_FB_UNREGISTERED
)
183 return am200_unshare_video_mem(info
);
188 static struct notifier_block am200_fb_notif
= {
189 .notifier_call
= am200_fb_notifier_callback
,
192 /* this gets called as part of our init. these steps must be done now so
193 * that we can use set_pxa_fb_info */
194 static void __init
am200_presetup_fb(void)
201 switch (panel_type
) {
203 am200_fb_info
.modes
= &am200_fb_mode_6inch
;
206 am200_fb_info
.modes
= &am200_fb_mode_8inch
;
209 am200_fb_info
.modes
= &am200_fb_mode_9inch7
;
212 dev_err(&am200_device
->dev
, "invalid panel_type selection,"
214 am200_fb_info
.modes
= &am200_fb_mode_6inch
;
218 /* the frame buffer is divided as follows:
219 command | CRC | padding
220 16kb waveform data | CRC | padding
224 fw
= am200_fb_info
.modes
->xres
;
225 fh
= am200_fb_info
.modes
->yres
;
227 /* waveform must be 16k + 2 for checksum */
228 am200_board
.wfm_size
= roundup(16*1024 + 2, fw
);
230 padding_size
= PAGE_SIZE
+ (4 * fw
);
232 /* total is 1 cmd , 1 wfm, padding and image */
233 totalsize
= fw
+ am200_board
.wfm_size
+ padding_size
+ (fw
*fh
);
235 /* save this off because we're manipulating fw after this and
236 * we'll need it when we're ready to setup the framebuffer */
240 /* the reason we do this adjustment is because we want to acquire
241 * more framebuffer memory without imposing custom awareness on the
242 * underlying pxafb driver */
243 am200_fb_info
.modes
->yres
= DIV_ROUND_UP(totalsize
, fw
);
245 /* we divide since we told the LCD controller we're 16bpp */
246 am200_fb_info
.modes
->xres
/= 2;
248 set_pxa_fb_info(&am200_fb_info
);
252 /* this gets called by metronomefb as part of its init, in our case, we
253 * have already completed initial framebuffer init in presetup_fb so we
254 * can just setup the fb access pointers */
255 static int am200_setup_fb(struct metronomefb_par
*par
)
263 /* metromem was set up by the notifier in share_video_mem so now
264 * we can use its value to calculate the other entries */
265 par
->metromem_cmd
= (struct metromem_cmd
*) am200_board
.metromem
;
266 par
->metromem_wfm
= am200_board
.metromem
+ fw
;
267 par
->metromem_img
= par
->metromem_wfm
+ am200_board
.wfm_size
;
268 par
->metromem_img_csum
= (u16
*) (par
->metromem_img
+ (fw
* fh
));
269 par
->metromem_dma
= am200_board
.host_fbinfo
->fix
.smem_start
;
274 static int am200_get_panel_type(void)
279 static irqreturn_t
am200_handle_irq(int irq
, void *dev_id
)
281 struct metronomefb_par
*par
= dev_id
;
283 wake_up_interruptible(&par
->waitq
);
287 static int am200_setup_irq(struct fb_info
*info
)
291 ret
= request_irq(IRQ_GPIO(RDY_GPIO_PIN
), am200_handle_irq
,
292 IRQF_DISABLED
|IRQF_TRIGGER_FALLING
,
295 dev_err(&am200_device
->dev
, "request_irq failed: %d\n", ret
);
300 static void am200_set_rst(struct metronomefb_par
*par
, int state
)
302 gpio_set_value(RST_GPIO_PIN
, state
);
305 static void am200_set_stdby(struct metronomefb_par
*par
, int state
)
307 gpio_set_value(STDBY_GPIO_PIN
, state
);
310 static int am200_wait_event(struct metronomefb_par
*par
)
312 return wait_event_timeout(par
->waitq
, gpio_get_value(RDY_GPIO_PIN
), HZ
);
315 static int am200_wait_event_intr(struct metronomefb_par
*par
)
317 return wait_event_interruptible_timeout(par
->waitq
,
318 gpio_get_value(RDY_GPIO_PIN
), HZ
);
321 static struct metronome_board am200_board
= {
322 .owner
= THIS_MODULE
,
323 .setup_irq
= am200_setup_irq
,
324 .setup_io
= am200_init_gpio_regs
,
325 .setup_fb
= am200_setup_fb
,
326 .set_rst
= am200_set_rst
,
327 .set_stdby
= am200_set_stdby
,
328 .met_wait_event
= am200_wait_event
,
329 .met_wait_event_intr
= am200_wait_event_intr
,
330 .get_panel_type
= am200_get_panel_type
,
331 .cleanup
= am200_cleanup
,
334 static int __init
am200_init(void)
338 /* before anything else, we request notification for any fb
340 fb_register_client(&am200_fb_notif
);
342 /* request our platform independent driver */
343 request_module("metronomefb");
345 am200_device
= platform_device_alloc("metronomefb", -1);
349 /* the am200_board that will be seen by metronomefb is a copy */
350 platform_device_add_data(am200_device
, &am200_board
,
351 sizeof(am200_board
));
353 /* this _add binds metronomefb to am200. metronomefb refcounts am200 */
354 ret
= platform_device_add(am200_device
);
357 platform_device_put(am200_device
);
358 fb_unregister_client(&am200_fb_notif
);
367 module_param(panel_type
, uint
, 0);
368 MODULE_PARM_DESC(panel_type
, "Select the panel type: 6, 8, 97");
370 module_init(am200_init
);
372 MODULE_DESCRIPTION("board driver for am200 metronome epd kit");
373 MODULE_AUTHOR("Jaya Kumar");
374 MODULE_LICENSE("GPL");