encoder-tfp410.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 = 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. if (gpio != -EPROBE_DEFER)
  132. dev_err(&pdev->dev, "failed to parse PD gpio\n");
  133. return gpio;
  134. }
  135. in = omapdss_of_find_source_for_first_ep(node);
  136. if (IS_ERR(in)) {
  137. dev_err(&pdev->dev, "failed to find video source\n");
  138. return PTR_ERR(in);
  139. }
  140. ddata->in = in;
  141. return 0;
  142. }
  143. static int tfp410_probe(struct platform_device *pdev)
  144. {
  145. struct panel_drv_data *ddata;
  146. struct omap_dss_device *dssdev;
  147. int r;
  148. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  149. if (!ddata)
  150. return -ENOMEM;
  151. platform_set_drvdata(pdev, ddata);
  152. if (!pdev->dev.of_node)
  153. return -ENODEV;
  154. r = tfp410_probe_of(pdev);
  155. if (r)
  156. return r;
  157. if (gpio_is_valid(ddata->pd_gpio)) {
  158. r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
  159. GPIOF_OUT_INIT_LOW, "tfp410 PD");
  160. if (r) {
  161. dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
  162. ddata->pd_gpio);
  163. goto err_gpio;
  164. }
  165. }
  166. dssdev = &ddata->dssdev;
  167. dssdev->ops.dvi = &tfp410_dvi_ops;
  168. dssdev->dev = &pdev->dev;
  169. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  170. dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
  171. dssdev->owner = THIS_MODULE;
  172. dssdev->port_num = 1;
  173. r = omapdss_register_output(dssdev);
  174. if (r) {
  175. dev_err(&pdev->dev, "Failed to register output\n");
  176. goto err_reg;
  177. }
  178. return 0;
  179. err_reg:
  180. err_gpio:
  181. omap_dss_put_device(ddata->in);
  182. return r;
  183. }
  184. static int __exit tfp410_remove(struct platform_device *pdev)
  185. {
  186. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  187. struct omap_dss_device *dssdev = &ddata->dssdev;
  188. struct omap_dss_device *in = ddata->in;
  189. omapdss_unregister_output(&ddata->dssdev);
  190. WARN_ON(omapdss_device_is_enabled(dssdev));
  191. if (omapdss_device_is_enabled(dssdev))
  192. tfp410_disable(dssdev);
  193. WARN_ON(omapdss_device_is_connected(dssdev));
  194. if (omapdss_device_is_connected(dssdev))
  195. tfp410_disconnect(dssdev, dssdev->dst);
  196. omap_dss_put_device(in);
  197. return 0;
  198. }
  199. static const struct of_device_id tfp410_of_match[] = {
  200. { .compatible = "omapdss,ti,tfp410", },
  201. {},
  202. };
  203. MODULE_DEVICE_TABLE(of, tfp410_of_match);
  204. static struct platform_driver tfp410_driver = {
  205. .probe = tfp410_probe,
  206. .remove = __exit_p(tfp410_remove),
  207. .driver = {
  208. .name = "tfp410",
  209. .of_match_table = tfp410_of_match,
  210. .suppress_bind_attrs = true,
  211. },
  212. };
  213. module_platform_driver(tfp410_driver);
  214. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  215. MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
  216. MODULE_LICENSE("GPL");