mddi_client_toshiba.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* drivers/video/msm_fb/mddi_client_toshiba.c
  2. *
  3. * Support for Toshiba TC358720XBG mddi client devices which require no
  4. * special initialization code.
  5. *
  6. * Copyright (C) 2007 Google Incorporated
  7. *
  8. * This software is licensed under the terms of the GNU General Public
  9. * License version 2, as published by the Free Software Foundation, and
  10. * may be copied, distributed, and modified under those terms.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/gpio.h>
  22. #include <linux/sched.h>
  23. #include <linux/slab.h>
  24. #include <mach/msm_fb.h>
  25. #define LCD_CONTROL_BLOCK_BASE 0x110000
  26. #define CMN (LCD_CONTROL_BLOCK_BASE|0x10)
  27. #define INTFLG (LCD_CONTROL_BLOCK_BASE|0x18)
  28. #define HCYCLE (LCD_CONTROL_BLOCK_BASE|0x34)
  29. #define HDE_START (LCD_CONTROL_BLOCK_BASE|0x3C)
  30. #define VPOS (LCD_CONTROL_BLOCK_BASE|0xC0)
  31. #define MPLFBUF (LCD_CONTROL_BLOCK_BASE|0x20)
  32. #define WAKEUP (LCD_CONTROL_BLOCK_BASE|0x54)
  33. #define WSYN_DLY (LCD_CONTROL_BLOCK_BASE|0x58)
  34. #define REGENB (LCD_CONTROL_BLOCK_BASE|0x5C)
  35. #define BASE5 0x150000
  36. #define BASE6 0x160000
  37. #define BASE7 0x170000
  38. #define GPIOIEV (BASE5 + 0x10)
  39. #define GPIOIE (BASE5 + 0x14)
  40. #define GPIORIS (BASE5 + 0x18)
  41. #define GPIOMIS (BASE5 + 0x1C)
  42. #define GPIOIC (BASE5 + 0x20)
  43. #define INTMASK (BASE6 + 0x0C)
  44. #define INTMASK_VWAKEOUT (1U << 0)
  45. #define INTMASK_VWAKEOUT_ACTIVE_LOW (1U << 8)
  46. #define GPIOSEL (BASE7 + 0x00)
  47. #define GPIOSEL_VWAKEINT (1U << 0)
  48. static DECLARE_WAIT_QUEUE_HEAD(toshiba_vsync_wait);
  49. struct panel_info {
  50. struct msm_mddi_client_data *client_data;
  51. struct platform_device pdev;
  52. struct msm_panel_data panel_data;
  53. struct msmfb_callback *toshiba_callback;
  54. int toshiba_got_int;
  55. };
  56. static void toshiba_request_vsync(struct msm_panel_data *panel_data,
  57. struct msmfb_callback *callback)
  58. {
  59. struct panel_info *panel = container_of(panel_data, struct panel_info,
  60. panel_data);
  61. struct msm_mddi_client_data *client_data = panel->client_data;
  62. panel->toshiba_callback = callback;
  63. if (panel->toshiba_got_int) {
  64. panel->toshiba_got_int = 0;
  65. client_data->activate_link(client_data);
  66. }
  67. }
  68. static void toshiba_clear_vsync(struct msm_panel_data *panel_data)
  69. {
  70. struct panel_info *panel = container_of(panel_data, struct panel_info,
  71. panel_data);
  72. struct msm_mddi_client_data *client_data = panel->client_data;
  73. client_data->activate_link(client_data);
  74. }
  75. static void toshiba_wait_vsync(struct msm_panel_data *panel_data)
  76. {
  77. struct panel_info *panel = container_of(panel_data, struct panel_info,
  78. panel_data);
  79. struct msm_mddi_client_data *client_data = panel->client_data;
  80. if (panel->toshiba_got_int) {
  81. panel->toshiba_got_int = 0;
  82. client_data->activate_link(client_data); /* clears interrupt */
  83. }
  84. if (wait_event_timeout(toshiba_vsync_wait, panel->toshiba_got_int,
  85. HZ/2) == 0)
  86. printk(KERN_ERR "timeout waiting for VSYNC\n");
  87. panel->toshiba_got_int = 0;
  88. /* interrupt clears when screen dma starts */
  89. }
  90. static int toshiba_suspend(struct msm_panel_data *panel_data)
  91. {
  92. struct panel_info *panel = container_of(panel_data, struct panel_info,
  93. panel_data);
  94. struct msm_mddi_client_data *client_data = panel->client_data;
  95. struct msm_mddi_bridge_platform_data *bridge_data =
  96. client_data->private_client_data;
  97. int ret;
  98. ret = bridge_data->uninit(bridge_data, client_data);
  99. if (ret) {
  100. printk(KERN_INFO "mddi toshiba client: non zero return from "
  101. "uninit\n");
  102. return ret;
  103. }
  104. client_data->suspend(client_data);
  105. return 0;
  106. }
  107. static int toshiba_resume(struct msm_panel_data *panel_data)
  108. {
  109. struct panel_info *panel = container_of(panel_data, struct panel_info,
  110. panel_data);
  111. struct msm_mddi_client_data *client_data = panel->client_data;
  112. struct msm_mddi_bridge_platform_data *bridge_data =
  113. client_data->private_client_data;
  114. int ret;
  115. client_data->resume(client_data);
  116. ret = bridge_data->init(bridge_data, client_data);
  117. if (ret)
  118. return ret;
  119. return 0;
  120. }
  121. static int toshiba_blank(struct msm_panel_data *panel_data)
  122. {
  123. struct panel_info *panel = container_of(panel_data, struct panel_info,
  124. panel_data);
  125. struct msm_mddi_client_data *client_data = panel->client_data;
  126. struct msm_mddi_bridge_platform_data *bridge_data =
  127. client_data->private_client_data;
  128. return bridge_data->blank(bridge_data, client_data);
  129. }
  130. static int toshiba_unblank(struct msm_panel_data *panel_data)
  131. {
  132. struct panel_info *panel = container_of(panel_data, struct panel_info,
  133. panel_data);
  134. struct msm_mddi_client_data *client_data = panel->client_data;
  135. struct msm_mddi_bridge_platform_data *bridge_data =
  136. client_data->private_client_data;
  137. return bridge_data->unblank(bridge_data, client_data);
  138. }
  139. irqreturn_t toshiba_vsync_interrupt(int irq, void *data)
  140. {
  141. struct panel_info *panel = data;
  142. panel->toshiba_got_int = 1;
  143. if (panel->toshiba_callback) {
  144. panel->toshiba_callback->func(panel->toshiba_callback);
  145. panel->toshiba_callback = 0;
  146. }
  147. wake_up(&toshiba_vsync_wait);
  148. return IRQ_HANDLED;
  149. }
  150. static int setup_vsync(struct panel_info *panel,
  151. int init)
  152. {
  153. int ret;
  154. int gpio = 97;
  155. unsigned int irq;
  156. if (!init) {
  157. ret = 0;
  158. goto uninit;
  159. }
  160. ret = gpio_request(gpio, "vsync");
  161. if (ret)
  162. goto err_request_gpio_failed;
  163. ret = gpio_direction_input(gpio);
  164. if (ret)
  165. goto err_gpio_direction_input_failed;
  166. ret = irq = gpio_to_irq(gpio);
  167. if (ret < 0)
  168. goto err_get_irq_num_failed;
  169. ret = request_irq(irq, toshiba_vsync_interrupt, IRQF_TRIGGER_RISING,
  170. "vsync", panel);
  171. if (ret)
  172. goto err_request_irq_failed;
  173. printk(KERN_INFO "vsync on gpio %d now %d\n",
  174. gpio, gpio_get_value(gpio));
  175. return 0;
  176. uninit:
  177. free_irq(gpio_to_irq(gpio), panel);
  178. err_request_irq_failed:
  179. err_get_irq_num_failed:
  180. err_gpio_direction_input_failed:
  181. gpio_free(gpio);
  182. err_request_gpio_failed:
  183. return ret;
  184. }
  185. static int mddi_toshiba_probe(struct platform_device *pdev)
  186. {
  187. int ret;
  188. struct msm_mddi_client_data *client_data = pdev->dev.platform_data;
  189. struct msm_mddi_bridge_platform_data *bridge_data =
  190. client_data->private_client_data;
  191. struct panel_info *panel =
  192. kzalloc(sizeof(struct panel_info), GFP_KERNEL);
  193. if (!panel)
  194. return -ENOMEM;
  195. platform_set_drvdata(pdev, panel);
  196. /* mddi_remote_write(mddi, 0, WAKEUP); */
  197. client_data->remote_write(client_data, GPIOSEL_VWAKEINT, GPIOSEL);
  198. client_data->remote_write(client_data, INTMASK_VWAKEOUT, INTMASK);
  199. ret = setup_vsync(panel, 1);
  200. if (ret) {
  201. dev_err(&pdev->dev, "mddi_bridge_setup_vsync failed\n");
  202. return ret;
  203. }
  204. panel->client_data = client_data;
  205. panel->panel_data.suspend = toshiba_suspend;
  206. panel->panel_data.resume = toshiba_resume;
  207. panel->panel_data.wait_vsync = toshiba_wait_vsync;
  208. panel->panel_data.request_vsync = toshiba_request_vsync;
  209. panel->panel_data.clear_vsync = toshiba_clear_vsync;
  210. panel->panel_data.blank = toshiba_blank;
  211. panel->panel_data.unblank = toshiba_unblank;
  212. panel->panel_data.fb_data = &bridge_data->fb_data;
  213. panel->panel_data.caps = MSMFB_CAP_PARTIAL_UPDATES;
  214. panel->pdev.name = "msm_panel";
  215. panel->pdev.id = pdev->id;
  216. panel->pdev.resource = client_data->fb_resource;
  217. panel->pdev.num_resources = 1;
  218. panel->pdev.dev.platform_data = &panel->panel_data;
  219. bridge_data->init(bridge_data, client_data);
  220. platform_device_register(&panel->pdev);
  221. return 0;
  222. }
  223. static int mddi_toshiba_remove(struct platform_device *pdev)
  224. {
  225. struct panel_info *panel = platform_get_drvdata(pdev);
  226. setup_vsync(panel, 0);
  227. kfree(panel);
  228. return 0;
  229. }
  230. static struct platform_driver mddi_client_d263_0000 = {
  231. .probe = mddi_toshiba_probe,
  232. .remove = mddi_toshiba_remove,
  233. .driver = { .name = "mddi_c_d263_0000" },
  234. };
  235. static int __init mddi_client_toshiba_init(void)
  236. {
  237. platform_driver_register(&mddi_client_d263_0000);
  238. return 0;
  239. }
  240. module_init(mddi_client_toshiba_init);