am300epd.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 <mach/gumstix.h>
  30. #include <mach/mfp-pxa25x.h>
  31. #include <mach/pxafb.h>
  32. #include "generic.h"
  33. #include <video/broadsheetfb.h>
  34. static unsigned int panel_type = 6;
  35. static struct platform_device *am300_device;
  36. static struct broadsheet_board am300_board;
  37. static unsigned long am300_pin_config[] __initdata = {
  38. GPIO16_GPIO,
  39. GPIO17_GPIO,
  40. GPIO32_GPIO,
  41. GPIO48_GPIO,
  42. GPIO49_GPIO,
  43. GPIO51_GPIO,
  44. GPIO74_GPIO,
  45. GPIO75_GPIO,
  46. GPIO76_GPIO,
  47. GPIO77_GPIO,
  48. /* this is the 16-bit hdb bus 58-73 */
  49. GPIO58_GPIO,
  50. GPIO59_GPIO,
  51. GPIO60_GPIO,
  52. GPIO61_GPIO,
  53. GPIO62_GPIO,
  54. GPIO63_GPIO,
  55. GPIO64_GPIO,
  56. GPIO65_GPIO,
  57. GPIO66_GPIO,
  58. GPIO67_GPIO,
  59. GPIO68_GPIO,
  60. GPIO69_GPIO,
  61. GPIO70_GPIO,
  62. GPIO71_GPIO,
  63. GPIO72_GPIO,
  64. GPIO73_GPIO,
  65. };
  66. /* register offsets for gpio control */
  67. #define PWR_GPIO_PIN 16
  68. #define CFG_GPIO_PIN 17
  69. #define RDY_GPIO_PIN 32
  70. #define DC_GPIO_PIN 48
  71. #define RST_GPIO_PIN 49
  72. #define LED_GPIO_PIN 51
  73. #define RD_GPIO_PIN 74
  74. #define WR_GPIO_PIN 75
  75. #define CS_GPIO_PIN 76
  76. #define IRQ_GPIO_PIN 77
  77. /* hdb bus */
  78. #define DB0_GPIO_PIN 58
  79. #define DB15_GPIO_PIN 73
  80. static int gpios[] = { PWR_GPIO_PIN, CFG_GPIO_PIN, RDY_GPIO_PIN, DC_GPIO_PIN,
  81. RST_GPIO_PIN, RD_GPIO_PIN, WR_GPIO_PIN, CS_GPIO_PIN,
  82. IRQ_GPIO_PIN, LED_GPIO_PIN };
  83. static char *gpio_names[] = { "PWR", "CFG", "RDY", "DC", "RST", "RD", "WR",
  84. "CS", "IRQ", "LED" };
  85. static int am300_wait_event(struct broadsheetfb_par *par)
  86. {
  87. /* todo: improve err recovery */
  88. wait_event(par->waitq, gpio_get_value(RDY_GPIO_PIN));
  89. return 0;
  90. }
  91. static int am300_init_gpio_regs(struct broadsheetfb_par *par)
  92. {
  93. int i;
  94. int err;
  95. char dbname[8];
  96. for (i = 0; i < ARRAY_SIZE(gpios); i++) {
  97. err = gpio_request(gpios[i], gpio_names[i]);
  98. if (err) {
  99. dev_err(&am300_device->dev, "failed requesting "
  100. "gpio %s, err=%d\n", gpio_names[i], err);
  101. goto err_req_gpio;
  102. }
  103. }
  104. /* we also need to take care of the hdb bus */
  105. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++) {
  106. sprintf(dbname, "DB%d", i);
  107. err = gpio_request(i, dbname);
  108. if (err) {
  109. dev_err(&am300_device->dev, "failed requesting "
  110. "gpio %d, err=%d\n", i, err);
  111. goto err_req_gpio2;
  112. }
  113. }
  114. /* setup the outputs and init values */
  115. gpio_direction_output(PWR_GPIO_PIN, 0);
  116. gpio_direction_output(CFG_GPIO_PIN, 1);
  117. gpio_direction_output(DC_GPIO_PIN, 0);
  118. gpio_direction_output(RD_GPIO_PIN, 1);
  119. gpio_direction_output(WR_GPIO_PIN, 1);
  120. gpio_direction_output(CS_GPIO_PIN, 1);
  121. gpio_direction_output(RST_GPIO_PIN, 0);
  122. /* setup the inputs */
  123. gpio_direction_input(RDY_GPIO_PIN);
  124. gpio_direction_input(IRQ_GPIO_PIN);
  125. /* start the hdb bus as an input */
  126. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++)
  127. gpio_direction_output(i, 0);
  128. /* go into command mode */
  129. gpio_set_value(CFG_GPIO_PIN, 1);
  130. gpio_set_value(RST_GPIO_PIN, 0);
  131. msleep(10);
  132. gpio_set_value(RST_GPIO_PIN, 1);
  133. msleep(10);
  134. am300_wait_event(par);
  135. return 0;
  136. err_req_gpio2:
  137. while (--i >= DB0_GPIO_PIN)
  138. gpio_free(i);
  139. i = ARRAY_SIZE(gpios);
  140. err_req_gpio:
  141. while (--i >= 0)
  142. gpio_free(gpios[i]);
  143. return err;
  144. }
  145. static int am300_init_board(struct broadsheetfb_par *par)
  146. {
  147. return am300_init_gpio_regs(par);
  148. }
  149. static void am300_cleanup(struct broadsheetfb_par *par)
  150. {
  151. int i;
  152. free_irq(IRQ_GPIO(RDY_GPIO_PIN), par);
  153. for (i = 0; i < ARRAY_SIZE(gpios); i++)
  154. gpio_free(gpios[i]);
  155. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++)
  156. gpio_free(i);
  157. }
  158. static u16 am300_get_hdb(struct broadsheetfb_par *par)
  159. {
  160. u16 res = 0;
  161. int i;
  162. for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
  163. res |= (gpio_get_value(DB0_GPIO_PIN + i)) ? (1 << i) : 0;
  164. return res;
  165. }
  166. static void am300_set_hdb(struct broadsheetfb_par *par, u16 data)
  167. {
  168. int i;
  169. for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
  170. gpio_set_value(DB0_GPIO_PIN + i, (data >> i) & 0x01);
  171. }
  172. static void am300_set_ctl(struct broadsheetfb_par *par, unsigned char bit,
  173. u8 state)
  174. {
  175. switch (bit) {
  176. case BS_CS:
  177. gpio_set_value(CS_GPIO_PIN, state);
  178. break;
  179. case BS_DC:
  180. gpio_set_value(DC_GPIO_PIN, state);
  181. break;
  182. case BS_WR:
  183. gpio_set_value(WR_GPIO_PIN, state);
  184. break;
  185. }
  186. }
  187. static int am300_get_panel_type(void)
  188. {
  189. return panel_type;
  190. }
  191. static irqreturn_t am300_handle_irq(int irq, void *dev_id)
  192. {
  193. struct broadsheetfb_par *par = dev_id;
  194. wake_up(&par->waitq);
  195. return IRQ_HANDLED;
  196. }
  197. static int am300_setup_irq(struct fb_info *info)
  198. {
  199. int ret;
  200. struct broadsheetfb_par *par = info->par;
  201. ret = request_irq(IRQ_GPIO(RDY_GPIO_PIN), am300_handle_irq,
  202. IRQF_DISABLED|IRQF_TRIGGER_RISING,
  203. "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");