hecubafb.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 = par->info->screen_buffer;
  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, struct list_head *pagereflist)
  100. {
  101. hecubafb_dpy_update(info->par);
  102. }
  103. static void hecubafb_defio_damage_range(struct fb_info *info, off_t off, size_t len)
  104. {
  105. struct hecubafb_par *par = info->par;
  106. hecubafb_dpy_update(par);
  107. }
  108. static void hecubafb_defio_damage_area(struct fb_info *info, u32 x, u32 y,
  109. u32 width, u32 height)
  110. {
  111. struct hecubafb_par *par = info->par;
  112. hecubafb_dpy_update(par);
  113. }
  114. FB_GEN_DEFAULT_DEFERRED_SYSMEM_OPS(hecubafb,
  115. hecubafb_defio_damage_range,
  116. hecubafb_defio_damage_area)
  117. static const struct fb_ops hecubafb_ops = {
  118. .owner = THIS_MODULE,
  119. FB_DEFAULT_DEFERRED_OPS(hecubafb),
  120. };
  121. static struct fb_deferred_io hecubafb_defio = {
  122. .delay = HZ,
  123. .deferred_io = hecubafb_dpy_deferred_io,
  124. };
  125. static int hecubafb_probe(struct platform_device *dev)
  126. {
  127. struct fb_info *info;
  128. struct hecuba_board *board;
  129. int retval = -ENOMEM;
  130. int videomemorysize;
  131. unsigned char *videomemory;
  132. struct hecubafb_par *par;
  133. /* pick up board specific routines */
  134. board = dev->dev.platform_data;
  135. if (!board)
  136. return -EINVAL;
  137. /* try to count device specific driver, if can't, platform recalls */
  138. if (!try_module_get(board->owner))
  139. return -ENODEV;
  140. videomemorysize = (DPY_W*DPY_H)/8;
  141. videomemory = vzalloc(videomemorysize);
  142. if (!videomemory)
  143. goto err_videomem_alloc;
  144. info = framebuffer_alloc(sizeof(struct hecubafb_par), &dev->dev);
  145. if (!info)
  146. goto err_fballoc;
  147. info->screen_buffer = videomemory;
  148. info->fbops = &hecubafb_ops;
  149. info->var = hecubafb_var;
  150. info->fix = hecubafb_fix;
  151. info->fix.smem_len = videomemorysize;
  152. par = info->par;
  153. par->info = info;
  154. par->board = board;
  155. par->send_command = apollo_send_command;
  156. par->send_data = apollo_send_data;
  157. info->flags = FBINFO_VIRTFB;
  158. info->fbdefio = &hecubafb_defio;
  159. fb_deferred_io_init(info);
  160. retval = register_framebuffer(info);
  161. if (retval < 0)
  162. goto err_fbreg;
  163. platform_set_drvdata(dev, info);
  164. fb_info(info, "Hecuba frame buffer device, using %dK of video memory\n",
  165. videomemorysize >> 10);
  166. /* this inits the dpy */
  167. retval = par->board->init(par);
  168. if (retval < 0)
  169. goto err_fbreg;
  170. return 0;
  171. err_fbreg:
  172. framebuffer_release(info);
  173. err_fballoc:
  174. vfree(videomemory);
  175. err_videomem_alloc:
  176. module_put(board->owner);
  177. return retval;
  178. }
  179. static void hecubafb_remove(struct platform_device *dev)
  180. {
  181. struct fb_info *info = platform_get_drvdata(dev);
  182. if (info) {
  183. struct hecubafb_par *par = info->par;
  184. fb_deferred_io_cleanup(info);
  185. unregister_framebuffer(info);
  186. vfree(info->screen_buffer);
  187. if (par->board->remove)
  188. par->board->remove(par);
  189. module_put(par->board->owner);
  190. framebuffer_release(info);
  191. }
  192. }
  193. static struct platform_driver hecubafb_driver = {
  194. .probe = hecubafb_probe,
  195. .remove = hecubafb_remove,
  196. .driver = {
  197. .name = "hecubafb",
  198. },
  199. };
  200. module_platform_driver(hecubafb_driver);
  201. MODULE_DESCRIPTION("fbdev driver for Hecuba/Apollo controller");
  202. MODULE_AUTHOR("Jaya Kumar");
  203. MODULE_LICENSE("GPL");