encoder-tfp410.c 6.1 KB

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