hecubafb.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * linux/drivers/video/hecubafb.c -- FB driver for Hecuba/Apollo controller
  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. *
  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.
  23. *
  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
  27. *
  28. */
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/errno.h>
  32. #include <linux/string.h>
  33. #include <linux/mm.h>
  34. #include <linux/slab.h>
  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>
  42. #include <linux/uaccess.h>
  43. #include <video/hecubafb.h>
  44. /* Display specific information */
  45. #define DPY_W 600
  46. #define DPY_H 800
  47. static struct fb_fix_screeninfo hecubafb_fix __devinitdata = {
  48. .id = "hecubafb",
  49. .type = FB_TYPE_PACKED_PIXELS,
  50. .visual = FB_VISUAL_MONO01,
  51. .xpanstep = 0,
  52. .ypanstep = 0,
  53. .ywrapstep = 0,
  54. .line_length = DPY_W,
  55. .accel = FB_ACCEL_NONE,
  56. };
  57. static struct fb_var_screeninfo hecubafb_var __devinitdata = {
  58. .xres = DPY_W,
  59. .yres = DPY_H,
  60. .xres_virtual = DPY_W,
  61. .yres_virtual = DPY_H,
  62. .bits_per_pixel = 1,
  63. .nonstd = 1,
  64. };
  65. /* main hecubafb functions */
  66. static void apollo_send_data(struct hecubafb_par *par, unsigned char data)
  67. {
  68. /* set data */
  69. par->board->set_data(par, data);
  70. /* set DS low */
  71. par->board->set_ctl(par, HCB_DS_BIT, 0);
  72. /* wait for ack */
  73. par->board->wait_for_ack(par, 0);
  74. /* set DS hi */
  75. par->board->set_ctl(par, HCB_DS_BIT, 1);
  76. /* wait for ack to clear */
  77. par->board->wait_for_ack(par, 1);
  78. }
  79. static void apollo_send_command(struct hecubafb_par *par, unsigned char data)
  80. {
  81. /* command so set CD to high */
  82. par->board->set_ctl(par, HCB_CD_BIT, 1);
  83. /* actually strobe with command */
  84. apollo_send_data(par, data);
  85. /* clear CD back to low */
  86. par->board->set_ctl(par, HCB_CD_BIT, 0);
  87. }
  88. static void hecubafb_dpy_update(struct hecubafb_par *par)
  89. {
  90. int i;
  91. unsigned char *buf = (unsigned char __force *)par->info->screen_base;
  92. apollo_send_command(par, APOLLO_START_NEW_IMG);
  93. for (i=0; i < (DPY_W*DPY_H/8); i++) {
  94. apollo_send_data(par, *(buf++));
  95. }
  96. apollo_send_command(par, APOLLO_STOP_IMG_DATA);
  97. apollo_send_command(par, APOLLO_DISPLAY_IMG);
  98. }
  99. /* this is called back from the deferred io workqueue */
  100. static void hecubafb_dpy_deferred_io(struct fb_info *info,
  101. struct list_head *pagelist)
  102. {
  103. hecubafb_dpy_update(info->par);
  104. }
  105. static void hecubafb_fillrect(struct fb_info *info,
  106. const struct fb_fillrect *rect)
  107. {
  108. struct hecubafb_par *par = info->par;
  109. sys_fillrect(info, rect);
  110. hecubafb_dpy_update(par);
  111. }
  112. static void hecubafb_copyarea(struct fb_info *info,
  113. const struct fb_copyarea *area)
  114. {
  115. struct hecubafb_par *par = info->par;
  116. sys_copyarea(info, area);
  117. hecubafb_dpy_update(par);
  118. }
  119. static void hecubafb_imageblit(struct fb_info *info,
  120. const struct fb_image *image)
  121. {
  122. struct hecubafb_par *par = info->par;
  123. sys_imageblit(info, image);
  124. hecubafb_dpy_update(par);
  125. }
  126. /*
  127. * this is the slow path from userspace. they can seek and write to
  128. * the fb. it's inefficient to do anything less than a full screen draw
  129. */
  130. static ssize_t hecubafb_write(struct fb_info *info, const char __user *buf,
  131. size_t count, loff_t *ppos)
  132. {
  133. struct hecubafb_par *par = info->par;
  134. unsigned long p = *ppos;
  135. void *dst;
  136. int err = 0;
  137. unsigned long total_size;
  138. if (info->state != FBINFO_STATE_RUNNING)
  139. return -EPERM;
  140. total_size = info->fix.smem_len;
  141. if (p > total_size)
  142. return -EFBIG;
  143. if (count > total_size) {
  144. err = -EFBIG;
  145. count = total_size;
  146. }
  147. if (count + p > total_size) {
  148. if (!err)
  149. err = -ENOSPC;
  150. count = total_size - p;
  151. }
  152. dst = (void __force *) (info->screen_base + p);
  153. if (copy_from_user(dst, buf, count))
  154. err = -EFAULT;
  155. if (!err)
  156. *ppos += count;
  157. hecubafb_dpy_update(par);
  158. return (err) ? err : count;
  159. }
  160. static struct fb_ops hecubafb_ops = {
  161. .owner = THIS_MODULE,
  162. .fb_read = fb_sys_read,
  163. .fb_write = hecubafb_write,
  164. .fb_fillrect = hecubafb_fillrect,
  165. .fb_copyarea = hecubafb_copyarea,
  166. .fb_imageblit = hecubafb_imageblit,
  167. };
  168. static struct fb_deferred_io hecubafb_defio = {
  169. .delay = HZ,
  170. .deferred_io = hecubafb_dpy_deferred_io,
  171. };
  172. static int __devinit hecubafb_probe(struct platform_device *dev)
  173. {
  174. struct fb_info *info;
  175. struct hecuba_board *board;
  176. int retval = -ENOMEM;
  177. int videomemorysize;
  178. unsigned char *videomemory;
  179. struct hecubafb_par *par;
  180. /* pick up board specific routines */
  181. board = dev->dev.platform_data;
  182. if (!board)
  183. return -EINVAL;
  184. /* try to count device specific driver, if can't, platform recalls */
  185. if (!try_module_get(board->owner))
  186. return -ENODEV;
  187. videomemorysize = (DPY_W*DPY_H)/8;
  188. if (!(videomemory = vmalloc(videomemorysize)))
  189. return retval;
  190. memset(videomemory, 0, videomemorysize);
  191. info = framebuffer_alloc(sizeof(struct hecubafb_par), &dev->dev);
  192. if (!info)
  193. goto err_fballoc;
  194. info->screen_base = (char __force __iomem *)videomemory;
  195. info->fbops = &hecubafb_ops;
  196. info->var = hecubafb_var;
  197. info->fix = hecubafb_fix;
  198. info->fix.smem_len = videomemorysize;
  199. par = info->par;
  200. par->info = info;
  201. par->board = board;
  202. par->send_command = apollo_send_command;
  203. par->send_data = apollo_send_data;
  204. info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
  205. info->fbdefio = &hecubafb_defio;
  206. fb_deferred_io_init(info);
  207. retval = register_framebuffer(info);
  208. if (retval < 0)
  209. goto err_fbreg;
  210. platform_set_drvdata(dev, info);
  211. printk(KERN_INFO
  212. "fb%d: Hecuba frame buffer device, using %dK of video memory\n",
  213. info->node, videomemorysize >> 10);
  214. /* this inits the dpy */
  215. retval = par->board->init(par);
  216. if (retval < 0)
  217. goto err_fbreg;
  218. return 0;
  219. err_fbreg:
  220. framebuffer_release(info);
  221. err_fballoc:
  222. vfree(videomemory);
  223. module_put(board->owner);
  224. return retval;
  225. }
  226. static int __devexit hecubafb_remove(struct platform_device *dev)
  227. {
  228. struct fb_info *info = platform_get_drvdata(dev);
  229. if (info) {
  230. struct hecubafb_par *par = info->par;
  231. fb_deferred_io_cleanup(info);
  232. unregister_framebuffer(info);
  233. vfree((void __force *)info->screen_base);
  234. if (par->board->remove)
  235. par->board->remove(par);
  236. module_put(par->board->owner);
  237. framebuffer_release(info);
  238. }
  239. return 0;
  240. }
  241. static struct platform_driver hecubafb_driver = {
  242. .probe = hecubafb_probe,
  243. .remove = hecubafb_remove,
  244. .driver = {
  245. .owner = THIS_MODULE,
  246. .name = "hecubafb",
  247. },
  248. };
  249. static int __init hecubafb_init(void)
  250. {
  251. return platform_driver_register(&hecubafb_driver);
  252. }
  253. static void __exit hecubafb_exit(void)
  254. {
  255. platform_driver_unregister(&hecubafb_driver);
  256. }
  257. module_init(hecubafb_init);
  258. module_exit(hecubafb_exit);
  259. MODULE_DESCRIPTION("fbdev driver for Hecuba/Apollo controller");
  260. MODULE_AUTHOR("Jaya Kumar");
  261. MODULE_LICENSE("GPL");