2 * linux/drivers/video/hecubafb.c -- FB driver for Hecuba/Apollo controller
4 * Copyright (C) 2006, Jaya Kumar
5 * This work was sponsored by CIS(M) Sdn Bhd
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
11 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
12 * This work was possible because of apollo display code from E-Ink's website
13 * http://support.eink.com/community
14 * All information used to write this code is from public material made
15 * available by E-Ink on its support site. Some commands such as 0xA4
16 * were found by looping through cmd=0x00 thru 0xFF and supplying random
17 * values. There are other commands that the display is capable of,
18 * beyond the 5 used here but they are more complex.
20 * This driver is written to be used with the Hecuba display architecture.
21 * The actual display chip is called Apollo and the interface electronics
22 * it needs is called Hecuba.
24 * It is intended to be architecture independent. A board specific driver
25 * must be used to perform all the physical IO interactions. An example
26 * is provided as n411.c
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/errno.h>
33 #include <linux/string.h>
35 #include <linux/slab.h>
36 #include <linux/vmalloc.h>
37 #include <linux/delay.h>
38 #include <linux/interrupt.h>
40 #include <linux/init.h>
41 #include <linux/platform_device.h>
42 #include <linux/list.h>
43 #include <linux/uaccess.h>
45 #include <video/hecubafb.h>
47 /* Display specific information */
51 static struct fb_fix_screeninfo hecubafb_fix __devinitdata
= {
53 .type
= FB_TYPE_PACKED_PIXELS
,
54 .visual
= FB_VISUAL_MONO01
,
59 .accel
= FB_ACCEL_NONE
,
62 static struct fb_var_screeninfo hecubafb_var __devinitdata
= {
65 .xres_virtual
= DPY_W
,
66 .yres_virtual
= DPY_H
,
71 /* main hecubafb functions */
73 static void apollo_send_data(struct hecubafb_par
*par
, unsigned char data
)
76 par
->board
->set_data(par
, data
);
79 par
->board
->set_ctl(par
, HCB_DS_BIT
, 0);
82 par
->board
->wait_for_ack(par
, 0);
85 par
->board
->set_ctl(par
, HCB_DS_BIT
, 1);
87 /* wait for ack to clear */
88 par
->board
->wait_for_ack(par
, 1);
91 static void apollo_send_command(struct hecubafb_par
*par
, unsigned char data
)
93 /* command so set CD to high */
94 par
->board
->set_ctl(par
, HCB_CD_BIT
, 1);
96 /* actually strobe with command */
97 apollo_send_data(par
, data
);
99 /* clear CD back to low */
100 par
->board
->set_ctl(par
, HCB_CD_BIT
, 0);
103 static void hecubafb_dpy_update(struct hecubafb_par
*par
)
106 unsigned char *buf
= (unsigned char __force
*)par
->info
->screen_base
;
108 apollo_send_command(par
, APOLLO_START_NEW_IMG
);
110 for (i
=0; i
< (DPY_W
*DPY_H
/8); i
++) {
111 apollo_send_data(par
, *(buf
++));
114 apollo_send_command(par
, APOLLO_STOP_IMG_DATA
);
115 apollo_send_command(par
, APOLLO_DISPLAY_IMG
);
118 /* this is called back from the deferred io workqueue */
119 static void hecubafb_dpy_deferred_io(struct fb_info
*info
,
120 struct list_head
*pagelist
)
122 hecubafb_dpy_update(info
->par
);
125 static void hecubafb_fillrect(struct fb_info
*info
,
126 const struct fb_fillrect
*rect
)
128 struct hecubafb_par
*par
= info
->par
;
130 sys_fillrect(info
, rect
);
132 hecubafb_dpy_update(par
);
135 static void hecubafb_copyarea(struct fb_info
*info
,
136 const struct fb_copyarea
*area
)
138 struct hecubafb_par
*par
= info
->par
;
140 sys_copyarea(info
, area
);
142 hecubafb_dpy_update(par
);
145 static void hecubafb_imageblit(struct fb_info
*info
,
146 const struct fb_image
*image
)
148 struct hecubafb_par
*par
= info
->par
;
150 sys_imageblit(info
, image
);
152 hecubafb_dpy_update(par
);
156 * this is the slow path from userspace. they can seek and write to
157 * the fb. it's inefficient to do anything less than a full screen draw
159 static ssize_t
hecubafb_write(struct fb_info
*info
, const char __user
*buf
,
160 size_t count
, loff_t
*ppos
)
162 struct hecubafb_par
*par
= info
->par
;
163 unsigned long p
= *ppos
;
166 unsigned long total_size
;
168 if (info
->state
!= FBINFO_STATE_RUNNING
)
171 total_size
= info
->fix
.smem_len
;
176 if (count
> total_size
) {
181 if (count
+ p
> total_size
) {
185 count
= total_size
- p
;
188 dst
= (void __force
*) (info
->screen_base
+ p
);
190 if (copy_from_user(dst
, buf
, count
))
196 hecubafb_dpy_update(par
);
198 return (err
) ? err
: count
;
201 static struct fb_ops hecubafb_ops
= {
202 .owner
= THIS_MODULE
,
203 .fb_read
= fb_sys_read
,
204 .fb_write
= hecubafb_write
,
205 .fb_fillrect
= hecubafb_fillrect
,
206 .fb_copyarea
= hecubafb_copyarea
,
207 .fb_imageblit
= hecubafb_imageblit
,
210 static struct fb_deferred_io hecubafb_defio
= {
212 .deferred_io
= hecubafb_dpy_deferred_io
,
215 static int __devinit
hecubafb_probe(struct platform_device
*dev
)
217 struct fb_info
*info
;
218 struct hecuba_board
*board
;
219 int retval
= -ENOMEM
;
221 unsigned char *videomemory
;
222 struct hecubafb_par
*par
;
224 /* pick up board specific routines */
225 board
= dev
->dev
.platform_data
;
229 /* try to count device specific driver, if can't, platform recalls */
230 if (!try_module_get(board
->owner
))
233 videomemorysize
= (DPY_W
*DPY_H
)/8;
235 if (!(videomemory
= vmalloc(videomemorysize
)))
238 memset(videomemory
, 0, videomemorysize
);
240 info
= framebuffer_alloc(sizeof(struct hecubafb_par
), &dev
->dev
);
244 info
->screen_base
= (char __force __iomem
*)videomemory
;
245 info
->fbops
= &hecubafb_ops
;
247 info
->var
= hecubafb_var
;
248 info
->fix
= hecubafb_fix
;
249 info
->fix
.smem_len
= videomemorysize
;
253 par
->send_command
= apollo_send_command
;
254 par
->send_data
= apollo_send_data
;
256 info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_VIRTFB
;
258 info
->fbdefio
= &hecubafb_defio
;
259 fb_deferred_io_init(info
);
261 retval
= register_framebuffer(info
);
264 platform_set_drvdata(dev
, info
);
267 "fb%d: Hecuba frame buffer device, using %dK of video memory\n",
268 info
->node
, videomemorysize
>> 10);
270 /* this inits the dpy */
271 retval
= par
->board
->init(par
);
277 framebuffer_release(info
);
280 module_put(board
->owner
);
284 static int __devexit
hecubafb_remove(struct platform_device
*dev
)
286 struct fb_info
*info
= platform_get_drvdata(dev
);
289 struct hecubafb_par
*par
= info
->par
;
290 fb_deferred_io_cleanup(info
);
291 unregister_framebuffer(info
);
292 vfree((void __force
*)info
->screen_base
);
293 if (par
->board
->remove
)
294 par
->board
->remove(par
);
295 module_put(par
->board
->owner
);
296 framebuffer_release(info
);
301 static struct platform_driver hecubafb_driver
= {
302 .probe
= hecubafb_probe
,
303 .remove
= hecubafb_remove
,
305 .owner
= THIS_MODULE
,
310 static int __init
hecubafb_init(void)
312 return platform_driver_register(&hecubafb_driver
);
315 static void __exit
hecubafb_exit(void)
317 platform_driver_unregister(&hecubafb_driver
);
320 module_init(hecubafb_init
);
321 module_exit(hecubafb_exit
);
323 MODULE_DESCRIPTION("fbdev driver for Hecuba/Apollo controller");
324 MODULE_AUTHOR("Jaya Kumar");
325 MODULE_LICENSE("GPL");