am200epd.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * linux/drivers/video/am200epd.c -- Platform device for AM200 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 work was made possible by help and equipment support from E-Ink
  13. * Corporation. http://support.eink.com/community
  14. *
  15. * This driver is written to be used with the Metronome display controller.
  16. * on the AM200 EPD prototype kit/development kit with an E-Ink 800x600
  17. * Vizplex EPD on a Gumstix board using the Lyre interface board.
  18. *
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/string.h>
  24. #include <linux/delay.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/fb.h>
  27. #include <linux/init.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/list.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/irq.h>
  32. #include <video/metronomefb.h>
  33. #include <asm/arch/pxa-regs.h>
  34. /* register offsets for gpio control */
  35. #define LED_GPIO_PIN 51
  36. #define STDBY_GPIO_PIN 48
  37. #define RST_GPIO_PIN 49
  38. #define RDY_GPIO_PIN 32
  39. #define ERR_GPIO_PIN 17
  40. #define PCBPWR_GPIO_PIN 16
  41. #define AF_SEL_GPIO_N 0x3
  42. #define GAFR0_U_OFFSET(pin) ((pin - 16) * 2)
  43. #define GAFR1_L_OFFSET(pin) ((pin - 32) * 2)
  44. #define GAFR1_U_OFFSET(pin) ((pin - 48) * 2)
  45. #define GPDR1_OFFSET(pin) (pin - 32)
  46. #define GPCR1_OFFSET(pin) (pin - 32)
  47. #define GPSR1_OFFSET(pin) (pin - 32)
  48. #define GPCR0_OFFSET(pin) (pin)
  49. #define GPSR0_OFFSET(pin) (pin)
  50. static void am200_set_gpio_output(int pin, int val)
  51. {
  52. u8 index;
  53. index = pin >> 4;
  54. switch (index) {
  55. case 1:
  56. if (val)
  57. GPSR0 |= (1 << GPSR0_OFFSET(pin));
  58. else
  59. GPCR0 |= (1 << GPCR0_OFFSET(pin));
  60. break;
  61. case 2:
  62. break;
  63. case 3:
  64. if (val)
  65. GPSR1 |= (1 << GPSR1_OFFSET(pin));
  66. else
  67. GPCR1 |= (1 << GPCR1_OFFSET(pin));
  68. break;
  69. default:
  70. printk(KERN_ERR "unimplemented\n");
  71. }
  72. }
  73. static void __devinit am200_init_gpio_pin(int pin, int dir)
  74. {
  75. u8 index;
  76. /* dir 0 is output, 1 is input
  77. - do 2 things here:
  78. - set gpio alternate function to standard gpio
  79. - set gpio direction to input or output */
  80. index = pin >> 4;
  81. switch (index) {
  82. case 1:
  83. GAFR0_U &= ~(AF_SEL_GPIO_N << GAFR0_U_OFFSET(pin));
  84. if (dir)
  85. GPDR0 &= ~(1 << pin);
  86. else
  87. GPDR0 |= (1 << pin);
  88. break;
  89. case 2:
  90. GAFR1_L &= ~(AF_SEL_GPIO_N << GAFR1_L_OFFSET(pin));
  91. if (dir)
  92. GPDR1 &= ~(1 << GPDR1_OFFSET(pin));
  93. else
  94. GPDR1 |= (1 << GPDR1_OFFSET(pin));
  95. break;
  96. case 3:
  97. GAFR1_U &= ~(AF_SEL_GPIO_N << GAFR1_U_OFFSET(pin));
  98. if (dir)
  99. GPDR1 &= ~(1 << GPDR1_OFFSET(pin));
  100. else
  101. GPDR1 |= (1 << GPDR1_OFFSET(pin));
  102. break;
  103. default:
  104. printk(KERN_ERR "unimplemented\n");
  105. }
  106. }
  107. static void am200_init_gpio_regs(struct metronomefb_par *par)
  108. {
  109. am200_init_gpio_pin(LED_GPIO_PIN, 0);
  110. am200_set_gpio_output(LED_GPIO_PIN, 0);
  111. am200_init_gpio_pin(STDBY_GPIO_PIN, 0);
  112. am200_set_gpio_output(STDBY_GPIO_PIN, 0);
  113. am200_init_gpio_pin(RST_GPIO_PIN, 0);
  114. am200_set_gpio_output(RST_GPIO_PIN, 0);
  115. am200_init_gpio_pin(RDY_GPIO_PIN, 1);
  116. am200_init_gpio_pin(ERR_GPIO_PIN, 1);
  117. am200_init_gpio_pin(PCBPWR_GPIO_PIN, 0);
  118. am200_set_gpio_output(PCBPWR_GPIO_PIN, 0);
  119. }
  120. static void am200_disable_lcd_controller(struct metronomefb_par *par)
  121. {
  122. LCSR = 0xffffffff; /* Clear LCD Status Register */
  123. LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */
  124. /* we reset and just wait for things to settle */
  125. msleep(200);
  126. }
  127. static void am200_enable_lcd_controller(struct metronomefb_par *par)
  128. {
  129. LCSR = 0xffffffff;
  130. FDADR0 = par->metromem_desc_dma;
  131. LCCR0 |= LCCR0_ENB;
  132. }
  133. static void am200_init_lcdc_regs(struct metronomefb_par *par)
  134. {
  135. /* here we do:
  136. - disable the lcd controller
  137. - setup lcd control registers
  138. - setup dma descriptor
  139. - reenable lcd controller
  140. */
  141. /* disable the lcd controller */
  142. am200_disable_lcd_controller(par);
  143. /* setup lcd control registers */
  144. LCCR0 = LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM | LCCR0_PAS
  145. | LCCR0_QDM | LCCR0_BM | LCCR0_OUM;
  146. LCCR1 = (par->info->var.xres/2 - 1) /* pixels per line */
  147. | (27 << 10) /* hsync pulse width - 1 */
  148. | (33 << 16) /* eol pixel count */
  149. | (33 << 24); /* bol pixel count */
  150. LCCR2 = (par->info->var.yres - 1) /* lines per panel */
  151. | (24 << 10) /* vsync pulse width - 1 */
  152. | (2 << 16) /* eof pixel count */
  153. | (0 << 24); /* bof pixel count */
  154. LCCR3 = 2 /* pixel clock divisor */
  155. | (24 << 8) /* AC Bias pin freq */
  156. | LCCR3_16BPP /* BPP */
  157. | LCCR3_PCP; /* PCP falling edge */
  158. }
  159. static void am200_post_dma_setup(struct metronomefb_par *par)
  160. {
  161. par->metromem_desc->mFDADR0 = par->metromem_desc_dma;
  162. par->metromem_desc->mFSADR0 = par->metromem_dma;
  163. par->metromem_desc->mFIDR0 = 0;
  164. par->metromem_desc->mLDCMD0 = par->info->var.xres
  165. * par->info->var.yres;
  166. am200_enable_lcd_controller(par);
  167. }
  168. static void am200_free_irq(struct fb_info *info)
  169. {
  170. free_irq(IRQ_GPIO(RDY_GPIO_PIN), info);
  171. }
  172. static irqreturn_t am200_handle_irq(int irq, void *dev_id)
  173. {
  174. struct fb_info *info = dev_id;
  175. struct metronomefb_par *par = info->par;
  176. wake_up_interruptible(&par->waitq);
  177. return IRQ_HANDLED;
  178. }
  179. static int am200_setup_irq(struct fb_info *info)
  180. {
  181. int retval;
  182. retval = request_irq(IRQ_GPIO(RDY_GPIO_PIN), am200_handle_irq,
  183. IRQF_DISABLED, "AM200", info);
  184. if (retval) {
  185. printk(KERN_ERR "am200epd: request_irq failed: %d\n", retval);
  186. return retval;
  187. }
  188. return set_irq_type(IRQ_GPIO(RDY_GPIO_PIN), IRQT_FALLING);
  189. }
  190. static void am200_set_rst(struct metronomefb_par *par, int state)
  191. {
  192. am200_set_gpio_output(RST_GPIO_PIN, state);
  193. }
  194. static void am200_set_stdby(struct metronomefb_par *par, int state)
  195. {
  196. am200_set_gpio_output(STDBY_GPIO_PIN, state);
  197. }
  198. static int am200_wait_event(struct metronomefb_par *par)
  199. {
  200. return wait_event_timeout(par->waitq, (GPLR1 & 0x01), HZ);
  201. }
  202. static int am200_wait_event_intr(struct metronomefb_par *par)
  203. {
  204. return wait_event_interruptible_timeout(par->waitq, (GPLR1 & 0x01), HZ);
  205. }
  206. static struct metronome_board am200_board = {
  207. .owner = THIS_MODULE,
  208. .free_irq = am200_free_irq,
  209. .setup_irq = am200_setup_irq,
  210. .init_gpio_regs = am200_init_gpio_regs,
  211. .init_lcdc_regs = am200_init_lcdc_regs,
  212. .post_dma_setup = am200_post_dma_setup,
  213. .set_rst = am200_set_rst,
  214. .set_stdby = am200_set_stdby,
  215. .met_wait_event = am200_wait_event,
  216. .met_wait_event_intr = am200_wait_event_intr,
  217. };
  218. static struct platform_device *am200_device;
  219. static int __init am200_init(void)
  220. {
  221. int ret;
  222. /* request our platform independent driver */
  223. request_module("metronomefb");
  224. am200_device = platform_device_alloc("metronomefb", -1);
  225. if (!am200_device)
  226. return -ENOMEM;
  227. platform_device_add_data(am200_device, &am200_board,
  228. sizeof(am200_board));
  229. /* this _add binds metronomefb to am200. metronomefb refcounts am200 */
  230. ret = platform_device_add(am200_device);
  231. if (ret)
  232. platform_device_put(am200_device);
  233. return ret;
  234. }
  235. static void __exit am200_exit(void)
  236. {
  237. platform_device_unregister(am200_device);
  238. }
  239. module_init(am200_init);
  240. module_exit(am200_exit);
  241. MODULE_DESCRIPTION("board driver for am200 metronome epd kit");
  242. MODULE_AUTHOR("Jaya Kumar");
  243. MODULE_LICENSE("GPL");