encoder-tfp410.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * TFP410 DPI-to-DVI encoder driver
  3. *
  4. * Copyright (C) 2013 Texas Instruments
  5. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. */
  11. #include <linux/gpio.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/slab.h>
  15. #include <linux/of_gpio.h>
  16. #include <video/omapdss.h>
  17. #include <video/omap-panel-data.h>
  18. struct panel_drv_data {
  19. struct omap_dss_device dssdev;
  20. struct omap_dss_device *in;
  21. int pd_gpio;
  22. int data_lines;
  23. struct omap_video_timings timings;
  24. };
  25. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  26. static int tfp410_connect(struct omap_dss_device *dssdev,
  27. struct omap_dss_device *dst)
  28. {
  29. struct panel_drv_data *ddata = to_panel_data(dssdev);
  30. struct omap_dss_device *in = ddata->in;
  31. int r;
  32. if (omapdss_device_is_connected(dssdev))
  33. return -EBUSY;
  34. r = in->ops.dpi->connect(in, dssdev);
  35. if (r)
  36. return r;
  37. dst->src = dssdev;
  38. dssdev->dst = dst;
  39. return 0;
  40. }
  41. static void tfp410_disconnect(struct omap_dss_device *dssdev,
  42. struct omap_dss_device *dst)
  43. {
  44. struct panel_drv_data *ddata = to_panel_data(dssdev);
  45. struct omap_dss_device *in = ddata->in;
  46. WARN_ON(!omapdss_device_is_connected(dssdev));
  47. if (!omapdss_device_is_connected(dssdev))
  48. return;
  49. WARN_ON(dst != dssdev->dst);
  50. if (dst != dssdev->dst)
  51. return;
  52. dst->src = NULL;
  53. dssdev->dst = NULL;
  54. in->ops.dpi->disconnect(in, &ddata->dssdev);
  55. }
  56. static int tfp410_enable(struct omap_dss_device *dssdev)
  57. {
  58. struct panel_drv_data *ddata = to_panel_data(dssdev);
  59. struct omap_dss_device *in = ddata->in;
  60. int r;
  61. if (!omapdss_device_is_connected(dssdev))
  62. return -ENODEV;
  63. if (omapdss_device_is_enabled(dssdev))
  64. return 0;
  65. in->ops.dpi->set_timings(in, &ddata->timings);
  66. if (ddata->data_lines)
  67. in->ops.dpi->set_data_lines(in, ddata->data_lines);
  68. r = in->ops.dpi->enable(in);
  69. if (r)
  70. return r;
  71. if (gpio_is_valid(ddata->pd_gpio))
  72. gpio_set_value_cansleep(ddata->pd_gpio, 1);
  73. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  74. return 0;
  75. }
  76. static void tfp410_disable(struct omap_dss_device *dssdev)
  77. {
  78. struct panel_drv_data *ddata = to_panel_data(dssdev);
  79. struct omap_dss_device *in = ddata->in;
  80. if (!omapdss_device_is_enabled(dssdev))
  81. return;
  82. if (gpio_is_valid(ddata->pd_gpio))
  83. gpio_set_value_cansleep(ddata->pd_gpio, 0);
  84. in->ops.dpi->disable(in);
  85. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  86. }
  87. static void tfp410_fix_timings(struct omap_video_timings *timings)
  88. {
  89. timings->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  90. timings->sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  91. timings->de_level = OMAPDSS_SIG_ACTIVE_HIGH;
  92. }
  93. static void tfp410_set_timings(struct omap_dss_device *dssdev,
  94. struct omap_video_timings *timings)
  95. {
  96. struct panel_drv_data *ddata = to_panel_data(dssdev);
  97. struct omap_dss_device *in = ddata->in;
  98. tfp410_fix_timings(timings);
  99. ddata->timings = *timings;
  100. dssdev->panel.timings = *timings;
  101. in->ops.dpi->set_timings(in, timings);
  102. }
  103. static void tfp410_get_timings(struct omap_dss_device *dssdev,
  104. struct omap_video_timings *timings)
  105. {
  106. struct panel_drv_data *ddata = to_panel_data(dssdev);
  107. *timings = ddata->timings;
  108. }
  109. static int tfp410_check_timings(struct omap_dss_device *dssdev,
  110. struct omap_video_timings *timings)
  111. {
  112. struct panel_drv_data *ddata = to_panel_data(dssdev);
  113. struct omap_dss_device *in = ddata->in;
  114. tfp410_fix_timings(timings);
  115. return in->ops.dpi->check_timings(in, timings);
  116. }
  117. static const struct omapdss_dvi_ops tfp410_dvi_ops = {
  118. .connect = tfp410_connect,
  119. .disconnect = tfp410_disconnect,
  120. .enable = tfp410_enable,
  121. .disable = tfp410_disable,
  122. .check_timings = tfp410_check_timings,
  123. .set_timings = tfp410_set_timings,
  124. .get_timings = tfp410_get_timings,
  125. };
  126. static int tfp410_probe_pdata(struct platform_device *pdev)
  127. {
  128. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  129. struct encoder_tfp410_platform_data *pdata;
  130. struct omap_dss_device *dssdev, *in;
  131. pdata = dev_get_platdata(&pdev->dev);
  132. ddata->pd_gpio = pdata->power_down_gpio;
  133. ddata->data_lines = pdata->data_lines;
  134. in = omap_dss_find_output(pdata->source);
  135. if (in == NULL) {
  136. dev_err(&pdev->dev, "Failed to find video source\n");
  137. return -ENODEV;
  138. }
  139. ddata->in = in;
  140. dssdev = &ddata->dssdev;
  141. dssdev->name = pdata->name;
  142. return 0;
  143. }
  144. static int tfp410_probe_of(struct platform_device *pdev)
  145. {
  146. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  147. struct device_node *node = pdev->dev.of_node;
  148. struct omap_dss_device *in;
  149. int gpio;
  150. gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
  151. if (gpio_is_valid(gpio) || gpio == -ENOENT) {
  152. ddata->pd_gpio = gpio;
  153. } else {
  154. dev_err(&pdev->dev, "failed to parse PD gpio\n");
  155. return gpio;
  156. }
  157. in = omapdss_of_find_source_for_first_ep(node);
  158. if (IS_ERR(in)) {
  159. dev_err(&pdev->dev, "failed to find video source\n");
  160. return PTR_ERR(in);
  161. }
  162. ddata->in = in;
  163. return 0;
  164. }
  165. static int tfp410_probe(struct platform_device *pdev)
  166. {
  167. struct panel_drv_data *ddata;
  168. struct omap_dss_device *dssdev;
  169. int r;
  170. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  171. if (!ddata)
  172. return -ENOMEM;
  173. platform_set_drvdata(pdev, ddata);
  174. if (dev_get_platdata(&pdev->dev)) {
  175. r = tfp410_probe_pdata(pdev);
  176. if (r)
  177. return r;
  178. } else if (pdev->dev.of_node) {
  179. r = tfp410_probe_of(pdev);
  180. if (r)
  181. return r;
  182. } else {
  183. return -ENODEV;
  184. }
  185. if (gpio_is_valid(ddata->pd_gpio)) {
  186. r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
  187. GPIOF_OUT_INIT_LOW, "tfp410 PD");
  188. if (r) {
  189. dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
  190. ddata->pd_gpio);
  191. goto err_gpio;
  192. }
  193. }
  194. dssdev = &ddata->dssdev;
  195. dssdev->ops.dvi = &tfp410_dvi_ops;
  196. dssdev->dev = &pdev->dev;
  197. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  198. dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
  199. dssdev->owner = THIS_MODULE;
  200. dssdev->phy.dpi.data_lines = ddata->data_lines;
  201. dssdev->port_num = 1;
  202. r = omapdss_register_output(dssdev);
  203. if (r) {
  204. dev_err(&pdev->dev, "Failed to register output\n");
  205. goto err_reg;
  206. }
  207. return 0;
  208. err_reg:
  209. err_gpio:
  210. omap_dss_put_device(ddata->in);
  211. return r;
  212. }
  213. static int __exit tfp410_remove(struct platform_device *pdev)
  214. {
  215. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  216. struct omap_dss_device *dssdev = &ddata->dssdev;
  217. struct omap_dss_device *in = ddata->in;
  218. omapdss_unregister_output(&ddata->dssdev);
  219. WARN_ON(omapdss_device_is_enabled(dssdev));
  220. if (omapdss_device_is_enabled(dssdev))
  221. tfp410_disable(dssdev);
  222. WARN_ON(omapdss_device_is_connected(dssdev));
  223. if (omapdss_device_is_connected(dssdev))
  224. tfp410_disconnect(dssdev, dssdev->dst);
  225. omap_dss_put_device(in);
  226. return 0;
  227. }
  228. static const struct of_device_id tfp410_of_match[] = {
  229. { .compatible = "omapdss,ti,tfp410", },
  230. {},
  231. };
  232. MODULE_DEVICE_TABLE(of, tfp410_of_match);
  233. static struct platform_driver tfp410_driver = {
  234. .probe = tfp410_probe,
  235. .remove = __exit_p(tfp410_remove),
  236. .driver = {
  237. .name = "tfp410",
  238. .of_match_table = tfp410_of_match,
  239. .suppress_bind_attrs = true,
  240. },
  241. };
  242. module_platform_driver(tfp410_driver);
  243. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  244. MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
  245. MODULE_LICENSE("GPL");