encoder-tfp410.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "../dss/omapdss.h"
  16. struct panel_drv_data {
  17. struct omap_dss_device dssdev;
  18. struct gpio_desc *pd_gpio;
  19. };
  20. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  21. static int tfp410_connect(struct omap_dss_device *src,
  22. struct omap_dss_device *dst)
  23. {
  24. return omapdss_device_connect(dst->dss, dst, dst->next);
  25. }
  26. static void tfp410_disconnect(struct omap_dss_device *src,
  27. struct omap_dss_device *dst)
  28. {
  29. omapdss_device_disconnect(dst, dst->next);
  30. }
  31. static int tfp410_enable(struct omap_dss_device *dssdev)
  32. {
  33. struct panel_drv_data *ddata = to_panel_data(dssdev);
  34. struct omap_dss_device *src = dssdev->src;
  35. int r;
  36. if (!omapdss_device_is_connected(dssdev))
  37. return -ENODEV;
  38. if (omapdss_device_is_enabled(dssdev))
  39. return 0;
  40. r = src->ops->enable(src);
  41. if (r)
  42. return r;
  43. if (ddata->pd_gpio)
  44. gpiod_set_value_cansleep(ddata->pd_gpio, 0);
  45. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  46. return 0;
  47. }
  48. static void tfp410_disable(struct omap_dss_device *dssdev)
  49. {
  50. struct panel_drv_data *ddata = to_panel_data(dssdev);
  51. struct omap_dss_device *src = dssdev->src;
  52. if (!omapdss_device_is_enabled(dssdev))
  53. return;
  54. if (ddata->pd_gpio)
  55. gpiod_set_value_cansleep(ddata->pd_gpio, 0);
  56. src->ops->disable(src);
  57. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  58. }
  59. static void tfp410_set_timings(struct omap_dss_device *dssdev,
  60. const struct videomode *vm)
  61. {
  62. struct omap_dss_device *src = dssdev->src;
  63. src->ops->set_timings(src, vm);
  64. }
  65. static const struct omap_dss_device_ops tfp410_ops = {
  66. .connect = tfp410_connect,
  67. .disconnect = tfp410_disconnect,
  68. .enable = tfp410_enable,
  69. .disable = tfp410_disable,
  70. .set_timings = tfp410_set_timings,
  71. };
  72. static int tfp410_probe(struct platform_device *pdev)
  73. {
  74. struct panel_drv_data *ddata;
  75. struct omap_dss_device *dssdev;
  76. struct gpio_desc *gpio;
  77. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  78. if (!ddata)
  79. return -ENOMEM;
  80. platform_set_drvdata(pdev, ddata);
  81. /* Powerdown GPIO */
  82. gpio = devm_gpiod_get_optional(&pdev->dev, "powerdown", GPIOD_OUT_HIGH);
  83. if (IS_ERR(gpio)) {
  84. dev_err(&pdev->dev, "failed to parse powerdown gpio\n");
  85. return PTR_ERR(gpio);
  86. }
  87. ddata->pd_gpio = gpio;
  88. dssdev = &ddata->dssdev;
  89. dssdev->ops = &tfp410_ops;
  90. dssdev->dev = &pdev->dev;
  91. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  92. dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
  93. dssdev->owner = THIS_MODULE;
  94. dssdev->of_ports = BIT(1) | BIT(0);
  95. dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
  96. | DRM_BUS_FLAG_PIXDATA_POSEDGE;
  97. dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
  98. if (IS_ERR(dssdev->next)) {
  99. if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
  100. dev_err(&pdev->dev, "failed to find video sink\n");
  101. return PTR_ERR(dssdev->next);
  102. }
  103. omapdss_device_register(dssdev);
  104. return 0;
  105. }
  106. static int __exit tfp410_remove(struct platform_device *pdev)
  107. {
  108. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  109. struct omap_dss_device *dssdev = &ddata->dssdev;
  110. if (dssdev->next)
  111. omapdss_device_put(dssdev->next);
  112. omapdss_device_unregister(&ddata->dssdev);
  113. WARN_ON(omapdss_device_is_enabled(dssdev));
  114. if (omapdss_device_is_enabled(dssdev))
  115. tfp410_disable(dssdev);
  116. WARN_ON(omapdss_device_is_connected(dssdev));
  117. if (omapdss_device_is_connected(dssdev))
  118. omapdss_device_disconnect(NULL, dssdev);
  119. return 0;
  120. }
  121. static const struct of_device_id tfp410_of_match[] = {
  122. { .compatible = "omapdss,ti,tfp410", },
  123. {},
  124. };
  125. MODULE_DEVICE_TABLE(of, tfp410_of_match);
  126. static struct platform_driver tfp410_driver = {
  127. .probe = tfp410_probe,
  128. .remove = __exit_p(tfp410_remove),
  129. .driver = {
  130. .name = "tfp410",
  131. .of_match_table = tfp410_of_match,
  132. .suppress_bind_attrs = true,
  133. },
  134. };
  135. module_platform_driver(tfp410_driver);
  136. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  137. MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
  138. MODULE_LICENSE("GPL");