Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 1 | /* |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 2 | * linux/drivers/video/hecubafb.c -- FB driver for Hecuba/Apollo controller |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2006, Jaya Kumar |
| 5 | * This work was sponsored by CIS(M) Sdn Bhd |
| 6 | * |
| 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 |
| 9 | * more details. |
| 10 | * |
| 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. |
| 19 | * |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 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. |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 23 | * |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 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 |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/errno.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/mm.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/vmalloc.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/interrupt.h> |
| 39 | #include <linux/fb.h> |
| 40 | #include <linux/init.h> |
| 41 | #include <linux/platform_device.h> |
| 42 | #include <linux/list.h> |
Krzysztof Helt | 84902b7 | 2007-10-16 01:29:04 -0700 | [diff] [blame] | 43 | #include <linux/uaccess.h> |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 44 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 45 | #include <video/hecubafb.h> |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 46 | |
| 47 | /* Display specific information */ |
| 48 | #define DPY_W 600 |
| 49 | #define DPY_H 800 |
| 50 | |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 51 | static struct fb_fix_screeninfo hecubafb_fix __devinitdata = { |
| 52 | .id = "hecubafb", |
| 53 | .type = FB_TYPE_PACKED_PIXELS, |
| 54 | .visual = FB_VISUAL_MONO01, |
| 55 | .xpanstep = 0, |
| 56 | .ypanstep = 0, |
| 57 | .ywrapstep = 0, |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 58 | .line_length = DPY_W, |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 59 | .accel = FB_ACCEL_NONE, |
| 60 | }; |
| 61 | |
| 62 | static struct fb_var_screeninfo hecubafb_var __devinitdata = { |
| 63 | .xres = DPY_W, |
| 64 | .yres = DPY_H, |
| 65 | .xres_virtual = DPY_W, |
| 66 | .yres_virtual = DPY_H, |
| 67 | .bits_per_pixel = 1, |
| 68 | .nonstd = 1, |
| 69 | }; |
| 70 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 71 | /* main hecubafb functions */ |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 72 | |
Adrian Bunk | 9a268a6 | 2007-05-08 00:37:45 -0700 | [diff] [blame] | 73 | static void apollo_send_data(struct hecubafb_par *par, unsigned char data) |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 74 | { |
| 75 | /* set data */ |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 76 | par->board->set_data(par, data); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 77 | |
| 78 | /* set DS low */ |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 79 | par->board->set_ctl(par, HCB_DS_BIT, 0); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 80 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 81 | /* wait for ack */ |
| 82 | par->board->wait_for_ack(par, 0); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 83 | |
| 84 | /* set DS hi */ |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 85 | par->board->set_ctl(par, HCB_DS_BIT, 1); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 86 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 87 | /* wait for ack to clear */ |
| 88 | par->board->wait_for_ack(par, 1); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Adrian Bunk | 9a268a6 | 2007-05-08 00:37:45 -0700 | [diff] [blame] | 91 | static void apollo_send_command(struct hecubafb_par *par, unsigned char data) |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 92 | { |
| 93 | /* command so set CD to high */ |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 94 | par->board->set_ctl(par, HCB_CD_BIT, 1); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 95 | |
| 96 | /* actually strobe with command */ |
| 97 | apollo_send_data(par, data); |
| 98 | |
| 99 | /* clear CD back to low */ |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 100 | par->board->set_ctl(par, HCB_CD_BIT, 0); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 103 | static void hecubafb_dpy_update(struct hecubafb_par *par) |
| 104 | { |
| 105 | int i; |
Antonino A. Daplas | 28cdf76 | 2007-05-08 00:38:50 -0700 | [diff] [blame] | 106 | unsigned char *buf = (unsigned char __force *)par->info->screen_base; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 107 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 108 | apollo_send_command(par, APOLLO_START_NEW_IMG); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 109 | |
| 110 | for (i=0; i < (DPY_W*DPY_H/8); i++) { |
| 111 | apollo_send_data(par, *(buf++)); |
| 112 | } |
| 113 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 114 | apollo_send_command(par, APOLLO_STOP_IMG_DATA); |
| 115 | apollo_send_command(par, APOLLO_DISPLAY_IMG); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 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) |
| 121 | { |
| 122 | hecubafb_dpy_update(info->par); |
| 123 | } |
| 124 | |
| 125 | static void hecubafb_fillrect(struct fb_info *info, |
| 126 | const struct fb_fillrect *rect) |
| 127 | { |
| 128 | struct hecubafb_par *par = info->par; |
| 129 | |
Antonino A. Daplas | d677493 | 2007-05-08 00:39:00 -0700 | [diff] [blame] | 130 | sys_fillrect(info, rect); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 131 | |
| 132 | hecubafb_dpy_update(par); |
| 133 | } |
| 134 | |
| 135 | static void hecubafb_copyarea(struct fb_info *info, |
| 136 | const struct fb_copyarea *area) |
| 137 | { |
| 138 | struct hecubafb_par *par = info->par; |
| 139 | |
Antonino A. Daplas | d677493 | 2007-05-08 00:39:00 -0700 | [diff] [blame] | 140 | sys_copyarea(info, area); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 141 | |
| 142 | hecubafb_dpy_update(par); |
| 143 | } |
| 144 | |
| 145 | static void hecubafb_imageblit(struct fb_info *info, |
| 146 | const struct fb_image *image) |
| 147 | { |
| 148 | struct hecubafb_par *par = info->par; |
| 149 | |
Antonino A. Daplas | d677493 | 2007-05-08 00:39:00 -0700 | [diff] [blame] | 150 | sys_imageblit(info, image); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 151 | |
| 152 | hecubafb_dpy_update(par); |
| 153 | } |
| 154 | |
| 155 | /* |
| 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 |
| 158 | */ |
Antonino A. Daplas | 3f9b088 | 2007-05-08 00:39:02 -0700 | [diff] [blame] | 159 | static ssize_t hecubafb_write(struct fb_info *info, const char __user *buf, |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 160 | size_t count, loff_t *ppos) |
| 161 | { |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 162 | struct hecubafb_par *par = info->par; |
| 163 | unsigned long p = *ppos; |
| 164 | void *dst; |
| 165 | int err = 0; |
| 166 | unsigned long total_size; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 167 | |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 168 | if (info->state != FBINFO_STATE_RUNNING) |
| 169 | return -EPERM; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 170 | |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 171 | total_size = info->fix.smem_len; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 172 | |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 173 | if (p > total_size) |
| 174 | return -EFBIG; |
| 175 | |
| 176 | if (count > total_size) { |
| 177 | err = -EFBIG; |
| 178 | count = total_size; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 181 | if (count + p > total_size) { |
| 182 | if (!err) |
| 183 | err = -ENOSPC; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 184 | |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 185 | count = total_size - p; |
| 186 | } |
| 187 | |
| 188 | dst = (void __force *) (info->screen_base + p); |
| 189 | |
| 190 | if (copy_from_user(dst, buf, count)) |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 191 | err = -EFAULT; |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 192 | |
| 193 | if (!err) |
| 194 | *ppos += count; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 195 | |
| 196 | hecubafb_dpy_update(par); |
| 197 | |
Jaya Kumar | 963654a | 2008-04-28 02:15:37 -0700 | [diff] [blame] | 198 | return (err) ? err : count; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static struct fb_ops hecubafb_ops = { |
| 202 | .owner = THIS_MODULE, |
Antonino A. Daplas | 28d4564 | 2007-05-08 00:39:06 -0700 | [diff] [blame] | 203 | .fb_read = fb_sys_read, |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 204 | .fb_write = hecubafb_write, |
| 205 | .fb_fillrect = hecubafb_fillrect, |
| 206 | .fb_copyarea = hecubafb_copyarea, |
| 207 | .fb_imageblit = hecubafb_imageblit, |
| 208 | }; |
| 209 | |
| 210 | static struct fb_deferred_io hecubafb_defio = { |
| 211 | .delay = HZ, |
| 212 | .deferred_io = hecubafb_dpy_deferred_io, |
| 213 | }; |
| 214 | |
| 215 | static int __devinit hecubafb_probe(struct platform_device *dev) |
| 216 | { |
| 217 | struct fb_info *info; |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 218 | struct hecuba_board *board; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 219 | int retval = -ENOMEM; |
| 220 | int videomemorysize; |
| 221 | unsigned char *videomemory; |
| 222 | struct hecubafb_par *par; |
| 223 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 224 | /* pick up board specific routines */ |
| 225 | board = dev->dev.platform_data; |
| 226 | if (!board) |
| 227 | return -EINVAL; |
| 228 | |
| 229 | /* try to count device specific driver, if can't, platform recalls */ |
| 230 | if (!try_module_get(board->owner)) |
| 231 | return -ENODEV; |
| 232 | |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 233 | videomemorysize = (DPY_W*DPY_H)/8; |
| 234 | |
| 235 | if (!(videomemory = vmalloc(videomemorysize))) |
| 236 | return retval; |
| 237 | |
| 238 | memset(videomemory, 0, videomemorysize); |
| 239 | |
| 240 | info = framebuffer_alloc(sizeof(struct hecubafb_par), &dev->dev); |
| 241 | if (!info) |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 242 | goto err_fballoc; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 243 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 244 | info->screen_base = (char __force __iomem *)videomemory; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 245 | info->fbops = &hecubafb_ops; |
| 246 | |
| 247 | info->var = hecubafb_var; |
| 248 | info->fix = hecubafb_fix; |
| 249 | info->fix.smem_len = videomemorysize; |
| 250 | par = info->par; |
| 251 | par->info = info; |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 252 | par->board = board; |
| 253 | par->send_command = apollo_send_command; |
| 254 | par->send_data = apollo_send_data; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 255 | |
Konrad Rzeszutek Wilk | a9b5ff9 | 2009-12-03 10:31:58 -0500 | [diff] [blame] | 256 | info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 257 | |
| 258 | info->fbdefio = &hecubafb_defio; |
| 259 | fb_deferred_io_init(info); |
| 260 | |
| 261 | retval = register_framebuffer(info); |
| 262 | if (retval < 0) |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 263 | goto err_fbreg; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 264 | platform_set_drvdata(dev, info); |
| 265 | |
| 266 | printk(KERN_INFO |
| 267 | "fb%d: Hecuba frame buffer device, using %dK of video memory\n", |
| 268 | info->node, videomemorysize >> 10); |
| 269 | |
| 270 | /* this inits the dpy */ |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 271 | retval = par->board->init(par); |
| 272 | if (retval < 0) |
| 273 | goto err_fbreg; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 274 | |
| 275 | return 0; |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 276 | err_fbreg: |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 277 | framebuffer_release(info); |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 278 | err_fballoc: |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 279 | vfree(videomemory); |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 280 | module_put(board->owner); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 281 | return retval; |
| 282 | } |
| 283 | |
| 284 | static int __devexit hecubafb_remove(struct platform_device *dev) |
| 285 | { |
| 286 | struct fb_info *info = platform_get_drvdata(dev); |
| 287 | |
| 288 | if (info) { |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 289 | struct hecubafb_par *par = info->par; |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 290 | fb_deferred_io_cleanup(info); |
| 291 | unregister_framebuffer(info); |
Antonino A. Daplas | 28cdf76 | 2007-05-08 00:38:50 -0700 | [diff] [blame] | 292 | vfree((void __force *)info->screen_base); |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 293 | if (par->board->remove) |
| 294 | par->board->remove(par); |
| 295 | module_put(par->board->owner); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 296 | framebuffer_release(info); |
| 297 | } |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static struct platform_driver hecubafb_driver = { |
| 302 | .probe = hecubafb_probe, |
| 303 | .remove = hecubafb_remove, |
| 304 | .driver = { |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 305 | .owner = THIS_MODULE, |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 306 | .name = "hecubafb", |
| 307 | }, |
| 308 | }; |
| 309 | |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 310 | static int __init hecubafb_init(void) |
| 311 | { |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 312 | return platform_driver_register(&hecubafb_driver); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static void __exit hecubafb_exit(void) |
| 316 | { |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 317 | platform_driver_unregister(&hecubafb_driver); |
| 318 | } |
| 319 | |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 320 | module_init(hecubafb_init); |
| 321 | module_exit(hecubafb_exit); |
| 322 | |
Jaya Kumar | 0e27aa3 | 2008-04-28 02:15:40 -0700 | [diff] [blame] | 323 | MODULE_DESCRIPTION("fbdev driver for Hecuba/Apollo controller"); |
Jaya Kumar | aad09e5 | 2007-05-08 00:37:43 -0700 | [diff] [blame] | 324 | MODULE_AUTHOR("Jaya Kumar"); |
| 325 | MODULE_LICENSE("GPL"); |