encoder-tfp410.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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_set_timings(struct omap_dss_device *dssdev,
  88. struct omap_video_timings *timings)
  89. {
  90. struct panel_drv_data *ddata = to_panel_data(dssdev);
  91. struct omap_dss_device *in = ddata->in;
  92. ddata->timings = *timings;
  93. dssdev->panel.timings = *timings;
  94. in->ops.dpi->set_timings(in, timings);
  95. }
  96. static void tfp410_get_timings(struct omap_dss_device *dssdev,
  97. struct omap_video_timings *timings)
  98. {
  99. struct panel_drv_data *ddata = to_panel_data(dssdev);
  100. *timings = ddata->timings;
  101. }
  102. static int tfp410_check_timings(struct omap_dss_device *dssdev,
  103. struct omap_video_timings *timings)
  104. {
  105. struct panel_drv_data *ddata = to_panel_data(dssdev);
  106. struct omap_dss_device *in = ddata->in;
  107. return in->ops.dpi->check_timings(in, timings);
  108. }
  109. static const struct omapdss_dvi_ops tfp410_dvi_ops = {
  110. .connect = tfp410_connect,
  111. .disconnect = tfp410_disconnect,
  112. .enable = tfp410_enable,
  113. .disable = tfp410_disable,
  114. .check_timings = tfp410_check_timings,
  115. .set_timings = tfp410_set_timings,
  116. .get_timings = tfp410_get_timings,
  117. };
  118. static int tfp410_probe_pdata(struct platform_device *pdev)
  119. {
  120. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  121. struct encoder_tfp410_platform_data *pdata;
  122. struct omap_dss_device *dssdev, *in;
  123. pdata = dev_get_platdata(&pdev->dev);
  124. ddata->pd_gpio = pdata->power_down_gpio;
  125. ddata->data_lines = pdata->data_lines;
  126. in = omap_dss_find_output(pdata->source);
  127. if (in == NULL) {
  128. dev_err(&pdev->dev, "Failed to find video source\n");
  129. return -ENODEV;
  130. }
  131. ddata->in = in;
  132. dssdev = &ddata->dssdev;
  133. dssdev->name = pdata->name;
  134. return 0;
  135. }
  136. static int tfp410_probe_of(struct platform_device *pdev)
  137. {
  138. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  139. struct device_node *node = pdev->dev.of_node;
  140. struct omap_dss_device *in;
  141. int gpio;
  142. gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
  143. if (gpio_is_valid(gpio) || gpio == -ENOENT) {
  144. ddata->pd_gpio = gpio;
  145. } else {
  146. dev_err(&pdev->dev, "failed to parse PD gpio\n");
  147. return gpio;
  148. }
  149. in = omapdss_of_find_source_for_first_ep(node);
  150. if (IS_ERR(in)) {
  151. dev_err(&pdev->dev, "failed to find video source\n");
  152. return PTR_ERR(in);
  153. }
  154. ddata->in = in;
  155. return 0;
  156. }
  157. static int tfp410_probe(struct platform_device *pdev)
  158. {
  159. struct panel_drv_data *ddata;
  160. struct omap_dss_device *dssdev;
  161. int r;
  162. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  163. if (!ddata)
  164. return -ENOMEM;
  165. platform_set_drvdata(pdev, ddata);
  166. if (dev_get_platdata(&pdev->dev)) {
  167. r = tfp410_probe_pdata(pdev);
  168. if (r)
  169. return r;
  170. } else if (pdev->dev.of_node) {
  171. r = tfp410_probe_of(pdev);
  172. if (r)
  173. return r;
  174. } else {
  175. return -ENODEV;
  176. }
  177. if (gpio_is_valid(ddata->pd_gpio)) {
  178. r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
  179. GPIOF_OUT_INIT_LOW, "tfp410 PD");
  180. if (r) {
  181. dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
  182. ddata->pd_gpio);
  183. goto err_gpio;
  184. }
  185. }
  186. dssdev = &ddata->dssdev;
  187. dssdev->ops.dvi = &tfp410_dvi_ops;
  188. dssdev->dev = &pdev->dev;
  189. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  190. dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
  191. dssdev->owner = THIS_MODULE;
  192. dssdev->phy.dpi.data_lines = ddata->data_lines;
  193. dssdev->port_num = 1;
  194. r = omapdss_register_output(dssdev);
  195. if (r) {
  196. dev_err(&pdev->dev, "Failed to register output\n");
  197. goto err_reg;
  198. }
  199. return 0;
  200. err_reg:
  201. err_gpio:
  202. omap_dss_put_device(ddata->in);
  203. return r;
  204. }
  205. static int __exit tfp410_remove(struct platform_device *pdev)
  206. {
  207. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  208. struct omap_dss_device *dssdev = &ddata->dssdev;
  209. struct omap_dss_device *in = ddata->in;
  210. omapdss_unregister_output(&ddata->dssdev);
  211. WARN_ON(omapdss_device_is_enabled(dssdev));
  212. if (omapdss_device_is_enabled(dssdev))
  213. tfp410_disable(dssdev);
  214. WARN_ON(omapdss_device_is_connected(dssdev));
  215. if (omapdss_device_is_connected(dssdev))
  216. tfp410_disconnect(dssdev, dssdev->dst);
  217. omap_dss_put_device(in);
  218. return 0;
  219. }
  220. static const struct of_device_id tfp410_of_match[] = {
  221. { .compatible = "omapdss,ti,tfp410", },
  222. {},
  223. };
  224. MODULE_DEVICE_TABLE(of, tfp410_of_match);
  225. static struct platform_driver tfp410_driver = {
  226. .probe = tfp410_probe,
  227. .remove = __exit_p(tfp410_remove),
  228. .driver = {
  229. .name = "tfp410",
  230. .of_match_table = tfp410_of_match,
  231. .suppress_bind_attrs = true,
  232. },
  233. };
  234. module_platform_driver(tfp410_driver);
  235. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  236. MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
  237. MODULE_LICENSE("GPL");