encoder-tfp410.c 6.2 KB

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