encoder-tfp410.c 6.3 KB

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