hecubafb.c 7.2 KB

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