encoder-tfp410.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_of(struct platform_device *pdev)
  127. {
  128. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  129. struct device_node *node = pdev->dev.of_node;
  130. struct omap_dss_device *in;
  131. int gpio;
  132. gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
  133. if (gpio_is_valid(gpio) || gpio == -ENOENT) {
  134. ddata->pd_gpio = gpio;
  135. } else {
  136. dev_err(&pdev->dev, "failed to parse PD gpio\n");
  137. return gpio;
  138. }
  139. in = omapdss_of_find_source_for_first_ep(node);
  140. if (IS_ERR(in)) {
  141. dev_err(&pdev->dev, "failed to find video source\n");
  142. return PTR_ERR(in);
  143. }
  144. ddata->in = in;
  145. return 0;
  146. }
  147. static int tfp410_probe(struct platform_device *pdev)
  148. {
  149. struct panel_drv_data *ddata;
  150. struct omap_dss_device *dssdev;
  151. int r;
  152. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  153. if (!ddata)
  154. return -ENOMEM;
  155. platform_set_drvdata(pdev, ddata);
  156. if (!pdev->dev.of_node)
  157. return -ENODEV;
  158. r = tfp410_probe_of(pdev);
  159. if (r)
  160. return r;
  161. if (gpio_is_valid(ddata->pd_gpio)) {
  162. r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
  163. GPIOF_OUT_INIT_LOW, "tfp410 PD");
  164. if (r) {
  165. dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
  166. ddata->pd_gpio);
  167. goto err_gpio;
  168. }
  169. }
  170. dssdev = &ddata->dssdev;
  171. dssdev->ops.dvi = &tfp410_dvi_ops;
  172. dssdev->dev = &pdev->dev;
  173. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  174. dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
  175. dssdev->owner = THIS_MODULE;
  176. dssdev->phy.dpi.data_lines = ddata->data_lines;
  177. dssdev->port_num = 1;
  178. r = omapdss_register_output(dssdev);
  179. if (r) {
  180. dev_err(&pdev->dev, "Failed to register output\n");
  181. goto err_reg;
  182. }
  183. return 0;
  184. err_reg:
  185. err_gpio:
  186. omap_dss_put_device(ddata->in);
  187. return r;
  188. }
  189. static int __exit tfp410_remove(struct platform_device *pdev)
  190. {
  191. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  192. struct omap_dss_device *dssdev = &ddata->dssdev;
  193. struct omap_dss_device *in = ddata->in;
  194. omapdss_unregister_output(&ddata->dssdev);
  195. WARN_ON(omapdss_device_is_enabled(dssdev));
  196. if (omapdss_device_is_enabled(dssdev))
  197. tfp410_disable(dssdev);
  198. WARN_ON(omapdss_device_is_connected(dssdev));
  199. if (omapdss_device_is_connected(dssdev))
  200. tfp410_disconnect(dssdev, dssdev->dst);
  201. omap_dss_put_device(in);
  202. return 0;
  203. }
  204. static const struct of_device_id tfp410_of_match[] = {
  205. { .compatible = "omapdss,ti,tfp410", },
  206. {},
  207. };
  208. MODULE_DEVICE_TABLE(of, tfp410_of_match);
  209. static struct platform_driver tfp410_driver = {
  210. .probe = tfp410_probe,
  211. .remove = __exit_p(tfp410_remove),
  212. .driver = {
  213. .name = "tfp410",
  214. .of_match_table = tfp410_of_match,
  215. .suppress_bind_attrs = true,
  216. },
  217. };
  218. module_platform_driver(tfp410_driver);
  219. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  220. MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
  221. MODULE_LICENSE("GPL");