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