encoder-tfp410.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 <video/omapdss.h>
  16. #include <video/omap-panel-data.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. in->ops.dpi->set_data_lines(in, ddata->data_lines);
  66. r = in->ops.dpi->enable(in);
  67. if (r)
  68. return r;
  69. if (gpio_is_valid(ddata->pd_gpio))
  70. gpio_set_value_cansleep(ddata->pd_gpio, 1);
  71. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  72. return 0;
  73. }
  74. static void tfp410_disable(struct omap_dss_device *dssdev)
  75. {
  76. struct panel_drv_data *ddata = to_panel_data(dssdev);
  77. struct omap_dss_device *in = ddata->in;
  78. if (!omapdss_device_is_enabled(dssdev))
  79. return;
  80. if (gpio_is_valid(ddata->pd_gpio))
  81. gpio_set_value_cansleep(ddata->pd_gpio, 0);
  82. in->ops.dpi->disable(in);
  83. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  84. }
  85. static void tfp410_set_timings(struct omap_dss_device *dssdev,
  86. struct omap_video_timings *timings)
  87. {
  88. struct panel_drv_data *ddata = to_panel_data(dssdev);
  89. struct omap_dss_device *in = ddata->in;
  90. ddata->timings = *timings;
  91. dssdev->panel.timings = *timings;
  92. in->ops.dpi->set_timings(in, timings);
  93. }
  94. static void tfp410_get_timings(struct omap_dss_device *dssdev,
  95. struct omap_video_timings *timings)
  96. {
  97. struct panel_drv_data *ddata = to_panel_data(dssdev);
  98. *timings = ddata->timings;
  99. }
  100. static int tfp410_check_timings(struct omap_dss_device *dssdev,
  101. struct omap_video_timings *timings)
  102. {
  103. struct panel_drv_data *ddata = to_panel_data(dssdev);
  104. struct omap_dss_device *in = ddata->in;
  105. return in->ops.dpi->check_timings(in, timings);
  106. }
  107. static const struct omapdss_dvi_ops tfp410_dvi_ops = {
  108. .connect = tfp410_connect,
  109. .disconnect = tfp410_disconnect,
  110. .enable = tfp410_enable,
  111. .disable = tfp410_disable,
  112. .check_timings = tfp410_check_timings,
  113. .set_timings = tfp410_set_timings,
  114. .get_timings = tfp410_get_timings,
  115. };
  116. static int tfp410_probe_pdata(struct platform_device *pdev)
  117. {
  118. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  119. struct encoder_tfp410_platform_data *pdata;
  120. struct omap_dss_device *dssdev, *in;
  121. pdata = dev_get_platdata(&pdev->dev);
  122. ddata->pd_gpio = pdata->power_down_gpio;
  123. ddata->data_lines = pdata->data_lines;
  124. in = omap_dss_find_output(pdata->source);
  125. if (in == NULL) {
  126. dev_err(&pdev->dev, "Failed to find video source\n");
  127. return -ENODEV;
  128. }
  129. ddata->in = in;
  130. dssdev = &ddata->dssdev;
  131. dssdev->name = pdata->name;
  132. return 0;
  133. }
  134. static int tfp410_probe(struct platform_device *pdev)
  135. {
  136. struct panel_drv_data *ddata;
  137. struct omap_dss_device *dssdev;
  138. int r;
  139. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  140. if (!ddata)
  141. return -ENOMEM;
  142. platform_set_drvdata(pdev, ddata);
  143. if (dev_get_platdata(&pdev->dev)) {
  144. r = tfp410_probe_pdata(pdev);
  145. if (r)
  146. return r;
  147. } else {
  148. return -ENODEV;
  149. }
  150. if (gpio_is_valid(ddata->pd_gpio)) {
  151. r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
  152. GPIOF_OUT_INIT_LOW, "tfp410 PD");
  153. if (r) {
  154. dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
  155. ddata->pd_gpio);
  156. goto err_gpio;
  157. }
  158. }
  159. dssdev = &ddata->dssdev;
  160. dssdev->ops.dvi = &tfp410_dvi_ops;
  161. dssdev->dev = &pdev->dev;
  162. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  163. dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
  164. dssdev->owner = THIS_MODULE;
  165. dssdev->phy.dpi.data_lines = ddata->data_lines;
  166. r = omapdss_register_output(dssdev);
  167. if (r) {
  168. dev_err(&pdev->dev, "Failed to register output\n");
  169. goto err_reg;
  170. }
  171. return 0;
  172. err_reg:
  173. err_gpio:
  174. omap_dss_put_device(ddata->in);
  175. return r;
  176. }
  177. static int __exit tfp410_remove(struct platform_device *pdev)
  178. {
  179. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  180. struct omap_dss_device *dssdev = &ddata->dssdev;
  181. struct omap_dss_device *in = ddata->in;
  182. omapdss_unregister_output(&ddata->dssdev);
  183. WARN_ON(omapdss_device_is_enabled(dssdev));
  184. if (omapdss_device_is_enabled(dssdev))
  185. tfp410_disable(dssdev);
  186. WARN_ON(omapdss_device_is_connected(dssdev));
  187. if (omapdss_device_is_connected(dssdev))
  188. tfp410_disconnect(dssdev, dssdev->dst);
  189. omap_dss_put_device(in);
  190. return 0;
  191. }
  192. static struct platform_driver tfp410_driver = {
  193. .probe = tfp410_probe,
  194. .remove = __exit_p(tfp410_remove),
  195. .driver = {
  196. .name = "tfp410",
  197. .owner = THIS_MODULE,
  198. },
  199. };
  200. module_platform_driver(tfp410_driver);
  201. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  202. MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
  203. MODULE_LICENSE("GPL");