am300epd.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. while (i >= DB0_GPIO_PIN)
  112. gpio_free(i--);
  113. i = ARRAY_SIZE(gpios) - 1;
  114. goto err_req_gpio;
  115. }
  116. }
  117. /* setup the outputs and init values */
  118. gpio_direction_output(PWR_GPIO_PIN, 0);
  119. gpio_direction_output(CFG_GPIO_PIN, 1);
  120. gpio_direction_output(DC_GPIO_PIN, 0);
  121. gpio_direction_output(RD_GPIO_PIN, 1);
  122. gpio_direction_output(WR_GPIO_PIN, 1);
  123. gpio_direction_output(CS_GPIO_PIN, 1);
  124. gpio_direction_output(RST_GPIO_PIN, 0);
  125. /* setup the inputs */
  126. gpio_direction_input(RDY_GPIO_PIN);
  127. gpio_direction_input(IRQ_GPIO_PIN);
  128. /* start the hdb bus as an input */
  129. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++)
  130. gpio_direction_output(i, 0);
  131. /* go into command mode */
  132. gpio_set_value(CFG_GPIO_PIN, 1);
  133. gpio_set_value(RST_GPIO_PIN, 0);
  134. msleep(10);
  135. gpio_set_value(RST_GPIO_PIN, 1);
  136. msleep(10);
  137. am300_wait_event(par);
  138. return 0;
  139. err_req_gpio:
  140. while (i > 0)
  141. gpio_free(gpios[i--]);
  142. return err;
  143. }
  144. static int am300_init_board(struct broadsheetfb_par *par)
  145. {
  146. return am300_init_gpio_regs(par);
  147. }
  148. static void am300_cleanup(struct broadsheetfb_par *par)
  149. {
  150. int i;
  151. free_irq(IRQ_GPIO(RDY_GPIO_PIN), par);
  152. for (i = 0; i < ARRAY_SIZE(gpios); i++)
  153. gpio_free(gpios[i]);
  154. for (i = DB0_GPIO_PIN; i <= DB15_GPIO_PIN; i++)
  155. gpio_free(i);
  156. }
  157. static u16 am300_get_hdb(struct broadsheetfb_par *par)
  158. {
  159. u16 res = 0;
  160. int i;
  161. for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
  162. res |= (gpio_get_value(DB0_GPIO_PIN + i)) ? (1 << i) : 0;
  163. return res;
  164. }
  165. static void am300_set_hdb(struct broadsheetfb_par *par, u16 data)
  166. {
  167. int i;
  168. for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
  169. gpio_set_value(DB0_GPIO_PIN + i, (data >> i) & 0x01);
  170. }
  171. static void am300_set_ctl(struct broadsheetfb_par *par, unsigned char bit,
  172. u8 state)
  173. {
  174. switch (bit) {
  175. case BS_CS:
  176. gpio_set_value(CS_GPIO_PIN, state);
  177. break;
  178. case BS_DC:
  179. gpio_set_value(DC_GPIO_PIN, state);
  180. break;
  181. case BS_WR:
  182. gpio_set_value(WR_GPIO_PIN, state);
  183. break;
  184. }
  185. }
  186. static int am300_get_panel_type(void)
  187. {
  188. return panel_type;
  189. }
  190. static irqreturn_t am300_handle_irq(int irq, void *dev_id)
  191. {
  192. struct broadsheetfb_par *par = dev_id;
  193. wake_up(&par->waitq);
  194. return IRQ_HANDLED;
  195. }
  196. static int am300_setup_irq(struct fb_info *info)
  197. {
  198. int ret;
  199. struct broadsheetfb_par *par = info->par;
  200. ret = request_irq(IRQ_GPIO(RDY_GPIO_PIN), am300_handle_irq,
  201. IRQF_DISABLED|IRQF_TRIGGER_RISING,
  202. "AM300", par);
  203. if (ret)
  204. dev_err(&am300_device->dev, "request_irq failed: %d\n", ret);
  205. return ret;
  206. }
  207. static struct broadsheet_board am300_board = {
  208. .owner = THIS_MODULE,
  209. .init = am300_init_board,
  210. .cleanup = am300_cleanup,
  211. .set_hdb = am300_set_hdb,
  212. .get_hdb = am300_get_hdb,
  213. .set_ctl = am300_set_ctl,
  214. .wait_for_rdy = am300_wait_event,
  215. .get_panel_type = am300_get_panel_type,
  216. .setup_irq = am300_setup_irq,
  217. };
  218. int __init am300_init(void)
  219. {
  220. int ret;
  221. pxa2xx_mfp_config(ARRAY_AND_SIZE(am300_pin_config));
  222. /* request our platform independent driver */
  223. request_module("broadsheetfb");
  224. am300_device = platform_device_alloc("broadsheetfb", -1);
  225. if (!am300_device)
  226. return -ENOMEM;
  227. /* the am300_board that will be seen by broadsheetfb is a copy */
  228. platform_device_add_data(am300_device, &am300_board,
  229. sizeof(am300_board));
  230. ret = platform_device_add(am300_device);
  231. if (ret) {
  232. platform_device_put(am300_device);
  233. return ret;
  234. }
  235. return 0;
  236. }
  237. module_param(panel_type, uint, 0);
  238. MODULE_PARM_DESC(panel_type, "Select the panel type: 6, 8, 97");
  239. MODULE_DESCRIPTION("board driver for am300 epd kit");
  240. MODULE_AUTHOR("Jaya Kumar");
  241. MODULE_LICENSE("GPL");