n411.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * linux/drivers/video/n411.c -- Platform device for N411 EPD kit
  3. *
  4. * Copyright (C) 2008, Jaya Kumar
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. *
  10. * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
  11. *
  12. * This driver is written to be used with the Hecuba display controller
  13. * board, and tested with the EInk 800x600 display in 1 bit mode.
  14. * The interface between Hecuba and the host is TTL based GPIO. The
  15. * GPIO requirements are 8 writable data lines and 6 lines for control.
  16. * Only 4 of the controls are actually used here but 6 for future use.
  17. * The driver requires the IO addresses for data and control GPIO at
  18. * load time. It is also possible to use this display with a standard
  19. * PC parallel port.
  20. *
  21. * General notes:
  22. * - User must set dio_addr=0xIOADDR cio_addr=0xIOADDR c2io_addr=0xIOADDR
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/errno.h>
  28. #include <linux/string.h>
  29. #include <linux/delay.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/fb.h>
  32. #include <linux/init.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/list.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/irq.h>
  37. #include <video/hecubafb.h>
  38. static unsigned long dio_addr;
  39. static unsigned long cio_addr;
  40. static unsigned long c2io_addr;
  41. static unsigned long splashval;
  42. static unsigned int nosplash;
  43. static unsigned char ctl;
  44. static void n411_set_ctl(struct hecubafb_par *par, unsigned char bit, unsigned
  45. char state)
  46. {
  47. switch (bit) {
  48. case HCB_CD_BIT:
  49. if (state)
  50. ctl &= ~(HCB_CD_BIT);
  51. else
  52. ctl |= HCB_CD_BIT;
  53. break;
  54. case HCB_DS_BIT:
  55. if (state)
  56. ctl &= ~(HCB_DS_BIT);
  57. else
  58. ctl |= HCB_DS_BIT;
  59. break;
  60. }
  61. outb(ctl, cio_addr);
  62. }
  63. static unsigned char n411_get_ctl(struct hecubafb_par *par)
  64. {
  65. return inb(c2io_addr);
  66. }
  67. static void n411_set_data(struct hecubafb_par *par, unsigned char value)
  68. {
  69. outb(value, dio_addr);
  70. }
  71. static void n411_wait_for_ack(struct hecubafb_par *par, int clear)
  72. {
  73. int timeout;
  74. unsigned char tmp;
  75. timeout = 500;
  76. do {
  77. tmp = n411_get_ctl(par);
  78. if ((tmp & HCB_ACK_BIT) && (!clear))
  79. return;
  80. else if (!(tmp & HCB_ACK_BIT) && (clear))
  81. return;
  82. udelay(1);
  83. } while (timeout--);
  84. printk(KERN_ERR "timed out waiting for ack\n");
  85. }
  86. static int n411_init_control(struct hecubafb_par *par)
  87. {
  88. unsigned char tmp;
  89. /* for init, we want the following setup to be set:
  90. WUP = lo
  91. ACK = hi
  92. DS = hi
  93. RW = hi
  94. CD = lo
  95. */
  96. /* write WUP to lo, DS to hi, RW to hi, CD to lo */
  97. ctl = HCB_WUP_BIT | HCB_RW_BIT | HCB_CD_BIT ;
  98. n411_set_ctl(par, HCB_DS_BIT, 1);
  99. /* check ACK is not lo */
  100. tmp = n411_get_ctl(par);
  101. if (tmp & HCB_ACK_BIT) {
  102. printk(KERN_ERR "Fail because ACK is already low\n");
  103. return -ENXIO;
  104. }
  105. return 0;
  106. }
  107. static int n411_init_board(struct hecubafb_par *par)
  108. {
  109. int retval;
  110. retval = n411_init_control(par);
  111. if (retval)
  112. return retval;
  113. par->send_command(par, APOLLO_INIT_DISPLAY);
  114. par->send_data(par, 0x81);
  115. /* have to wait while display resets */
  116. udelay(1000);
  117. /* if we were told to splash the screen, we just clear it */
  118. if (!nosplash) {
  119. par->send_command(par, APOLLO_ERASE_DISPLAY);
  120. par->send_data(par, splashval);
  121. }
  122. return 0;
  123. }
  124. static struct hecuba_board n411_board = {
  125. .owner = THIS_MODULE,
  126. .init = n411_init_board,
  127. .set_ctl = n411_set_ctl,
  128. .set_data = n411_set_data,
  129. .wait_for_ack = n411_wait_for_ack,
  130. };
  131. static struct platform_device *n411_device;
  132. static int __init n411_init(void)
  133. {
  134. int ret;
  135. if (!dio_addr || !cio_addr || !c2io_addr) {
  136. printk(KERN_WARNING "no IO addresses supplied\n");
  137. return -EINVAL;
  138. }
  139. /* request our platform independent driver */
  140. request_module("hecubafb");
  141. n411_device = platform_device_alloc("hecubafb", -1);
  142. if (!n411_device)
  143. return -ENOMEM;
  144. platform_device_add_data(n411_device, &n411_board, sizeof(n411_board));
  145. /* this _add binds hecubafb to n411. hecubafb refcounts n411 */
  146. ret = platform_device_add(n411_device);
  147. if (ret)
  148. platform_device_put(n411_device);
  149. return ret;
  150. }
  151. static void __exit n411_exit(void)
  152. {
  153. platform_device_unregister(n411_device);
  154. }
  155. module_init(n411_init);
  156. module_exit(n411_exit);
  157. module_param(nosplash, uint, 0);
  158. MODULE_PARM_DESC(nosplash, "Disable doing the splash screen");
  159. module_param(dio_addr, ulong, 0);
  160. MODULE_PARM_DESC(dio_addr, "IO address for data, eg: 0x480");
  161. module_param(cio_addr, ulong, 0);
  162. MODULE_PARM_DESC(cio_addr, "IO address for control, eg: 0x400");
  163. module_param(c2io_addr, ulong, 0);
  164. MODULE_PARM_DESC(c2io_addr, "IO address for secondary control, eg: 0x408");
  165. module_param(splashval, ulong, 0);
  166. MODULE_PARM_DESC(splashval, "Splash pattern: 0x00 is black, 0x01 is white");
  167. MODULE_DESCRIPTION("board driver for n411 hecuba/apollo epd kit");
  168. MODULE_AUTHOR("Jaya Kumar");
  169. MODULE_LICENSE("GPL");