encoder-tfp410.c 6.5 KB

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