am300epd.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * am300epd.c -- Platform device for AM300 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. * This work was made possible by help and equipment support from E-Ink
  11. * Corporation. http://support.eink.com/community
  12. *
  13. * This driver is written to be used with the Broadsheet display controller.
  14. * on the AM300 EPD prototype kit/development kit with an E-Ink 800x600
  15. * Vizplex EPD on a Gumstix board using the Broadsheet interface board.
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/string.h>
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/fb.h>
  25. #include <linux/init.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/irq.h>
  28. #include <linux/gpio.h>
  29. #include "gumstix.h"
  30. #include "mfp-pxa25x.h"
  31. #include <mach/irqs.h>
  32. #include <linux/platform_data/video-pxafb.h>
  33. #include "generic.h"
  34. #include <video/broadsheetfb.h>
  35. static unsigned int panel_type = 6;
  36. static struct platform_device *am300_device;
  37. static struct broadsheet_board am300_board;
  38. static unsigned long am300_pin_config[] __initdata = {
  39. GPIO16_GPIO,
  40. GPIO17_GPIO,
  41. GPIO32_GPIO,
  42. GPIO48_GPIO,
  43. GPIO49_GPIO,
  44. GPIO51_GPIO,
  45. GPIO74_GPIO,
  46. GPIO75_GPIO,
  47. GPIO76_GPIO,
  48. GPIO77_GPIO,
  49. /* this is the 16-bit hdb bus 58-73 */
  50. GPIO58_GPIO,
  51. GPIO59_GPIO,
  52. GPIO60_GPIO,
  53. GPIO61_GPIO,
  54. GPIO62_GPIO,
  55. GPIO63_GPIO,
  56. GPIO64_GPIO,
  57. GPIO65_GPIO,
  58. GPIO66_GPIO,
  59. GPIO67_GPIO,
  60. GPIO68_GPIO,
  61. GPIO69_GPIO,
  62. GPIO70_GPIO,
  63. GPIO71_GPIO,
  64. GPIO72_GPIO,
  65. GPIO73_GPIO,
  66. };
  67. /* register offsets for gpio control */
  68. #define PWR_GPIO_PIN 16
  69. #define CFG_GPIO_PIN 17
  70. #define RDY_GPIO_PIN 32
  71. #define DC_GPIO_PIN 48
  72. #define RST_GPIO_PIN 49
  73. #define LED_GPIO_PIN 51
  74. #define RD_GPIO_PIN 74
  75. #define WR_GPIO_PIN 75
  76. #define CS_GPIO_PIN 76
  77. #define IRQ_GPIO_PIN 77
  78. /* hdb bus */
  79. #define DB0_GPIO_PIN 58
  80. #define DB15_GPIO_PIN 73
  81. static int gpios[] = { PWR_GPIO_PIN, CFG_GPIO_PIN, RDY_GPIO_PIN, DC_GPIO_PIN,
  82. RST_GPIO_PIN, RD_GPIO_PIN, WR_GPIO_PIN, CS_GPIO_PIN,
  83. IRQ_GPIO_PIN, LED_GPIO_PIN };
  84. static char *gpio_names[] = { "PWR", "CFG", "RDY", "DC", "RST", "RD", "WR",
  85. "CS", "IRQ", "LED" };
  86. static int am300_wait_event(struct broadsheetfb_par *par)
  87. {
  88. /* todo: improve err recovery */
  89. wait_event(par->waitq, gpio_get_value(RDY_GPIO_PIN));
  90. return 0;
  91. }
  92. static int am300_init_gpio_regs(struct broadsheetfb_par *par)
  93. {
  94. int i;
  95. int err;
  96. char dbname[8];
  97. for (i = 0; i < ARRAY_SIZE(gpios); i++) {
  98. err = gpio_request(gpios[i], gpio_names[i]);
  99. if (err) {
  100. dev_err(&am300_device->dev, "failed requesting "
  101. "gpio %s, err=%d\n", gpio_names[i], err);
  102. goto err_req_gpio;
  103. }
  104. }
  105. /* we also need to take care of the hdb bus */
  106. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++) {
  107. sprintf(dbname, "DB%d", i);
  108. err = gpio_request(i, dbname);
  109. if (err) {
  110. dev_err(&am300_device->dev, "failed requesting "
  111. "gpio %d, err=%d\n", i, err);
  112. goto err_req_gpio2;
  113. }
  114. }
  115. /* setup the outputs and init values */
  116. gpio_direction_output(PWR_GPIO_PIN, 0);
  117. gpio_direction_output(CFG_GPIO_PIN, 1);
  118. gpio_direction_output(DC_GPIO_PIN, 0);
  119. gpio_direction_output(RD_GPIO_PIN, 1);
  120. gpio_direction_output(WR_GPIO_PIN, 1);
  121. gpio_direction_output(CS_GPIO_PIN, 1);
  122. gpio_direction_output(RST_GPIO_PIN, 0);
  123. /* setup the inputs */
  124. gpio_direction_input(RDY_GPIO_PIN);
  125. gpio_direction_input(IRQ_GPIO_PIN);
  126. /* start the hdb bus as an input */
  127. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++)
  128. gpio_direction_output(i, 0);
  129. /* go into command mode */
  130. gpio_set_value(CFG_GPIO_PIN, 1);
  131. gpio_set_value(RST_GPIO_PIN, 0);
  132. msleep(10);
  133. gpio_set_value(RST_GPIO_PIN, 1);
  134. msleep(10);
  135. am300_wait_event(par);
  136. return 0;
  137. err_req_gpio2:
  138. while (--i >= DB0_GPIO_PIN)
  139. gpio_free(i);
  140. i = ARRAY_SIZE(gpios);
  141. err_req_gpio:
  142. while (--i >= 0)
  143. gpio_free(gpios[i]);
  144. return err;
  145. }
  146. static int am300_init_board(struct broadsheetfb_par *par)
  147. {
  148. return am300_init_gpio_regs(par);
  149. }
  150. static void am300_cleanup(struct broadsheetfb_par *par)
  151. {
  152. int i;
  153. free_irq(PXA_GPIO_TO_IRQ(RDY_GPIO_PIN), par);
  154. for (i = 0; i < ARRAY_SIZE(gpios); i++)
  155. gpio_free(gpios[i]);
  156. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++)
  157. gpio_free(i);
  158. }
  159. static u16 am300_get_hdb(struct broadsheetfb_par *par)
  160. {
  161. u16 res = 0;
  162. int i;
  163. for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
  164. res |= (gpio_get_value(DB0_GPIO_PIN + i)) ? (1 << i) : 0;
  165. return res;
  166. }
  167. static void am300_set_hdb(struct broadsheetfb_par *par, u16 data)
  168. {
  169. int i;
  170. for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
  171. gpio_set_value(DB0_GPIO_PIN + i, (data >> i) & 0x01);
  172. }
  173. static void am300_set_ctl(struct broadsheetfb_par *par, unsigned char bit,
  174. u8 state)
  175. {
  176. switch (bit) {
  177. case BS_CS:
  178. gpio_set_value(CS_GPIO_PIN, state);
  179. break;
  180. case BS_DC:
  181. gpio_set_value(DC_GPIO_PIN, state);
  182. break;
  183. case BS_WR:
  184. gpio_set_value(WR_GPIO_PIN, state);
  185. break;
  186. }
  187. }
  188. static int am300_get_panel_type(void)
  189. {
  190. return panel_type;
  191. }
  192. static irqreturn_t am300_handle_irq(int irq, void *dev_id)
  193. {
  194. struct broadsheetfb_par *par = dev_id;
  195. wake_up(&par->waitq);
  196. return IRQ_HANDLED;
  197. }
  198. static int am300_setup_irq(struct fb_info *info)
  199. {
  200. int ret;
  201. struct broadsheetfb_par *par = info->par;
  202. ret = request_irq(PXA_GPIO_TO_IRQ(RDY_GPIO_PIN), am300_handle_irq,
  203. IRQF_TRIGGER_RISING, "AM300", par);
  204. if (ret)
  205. dev_err(&am300_device->dev, "request_irq failed: %d\n", ret);
  206. return ret;
  207. }
  208. static struct broadsheet_board am300_board = {
  209. .owner = THIS_MODULE,
  210. .init = am300_init_board,
  211. .cleanup = am300_cleanup,
  212. .set_hdb = am300_set_hdb,
  213. .get_hdb = am300_get_hdb,
  214. .set_ctl = am300_set_ctl,
  215. .wait_for_rdy = am300_wait_event,
  216. .get_panel_type = am300_get_panel_type,
  217. .setup_irq = am300_setup_irq,
  218. };
  219. int __init am300_init(void)
  220. {
  221. int ret;
  222. pxa2xx_mfp_config(ARRAY_AND_SIZE(am300_pin_config));
  223. /* request our platform independent driver */
  224. request_module("broadsheetfb");
  225. am300_device = platform_device_alloc("broadsheetfb", -1);
  226. if (!am300_device)
  227. return -ENOMEM;
  228. /* the am300_board that will be seen by broadsheetfb is a copy */
  229. platform_device_add_data(am300_device, &am300_board,
  230. sizeof(am300_board));
  231. ret = platform_device_add(am300_device);
  232. if (ret) {
  233. platform_device_put(am300_device);
  234. return ret;
  235. }
  236. return 0;
  237. }
  238. module_param(panel_type, uint, 0);
  239. MODULE_PARM_DESC(panel_type, "Select the panel type: 37, 6, 97");
  240. MODULE_DESCRIPTION("board driver for am300 epd kit");
  241. MODULE_AUTHOR("Jaya Kumar");
  242. MODULE_LICENSE("GPL");