encoder-tfp410.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 const struct omap_dss_device_ops tfp410_ops = {
  60. .connect = tfp410_connect,
  61. .disconnect = tfp410_disconnect,
  62. .enable = tfp410_enable,
  63. .disable = tfp410_disable,
  64. };
  65. static int tfp410_probe(struct platform_device *pdev)
  66. {
  67. struct panel_drv_data *ddata;
  68. struct omap_dss_device *dssdev;
  69. struct gpio_desc *gpio;
  70. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  71. if (!ddata)
  72. return -ENOMEM;
  73. platform_set_drvdata(pdev, ddata);
  74. /* Powerdown GPIO */
  75. gpio = devm_gpiod_get_optional(&pdev->dev, "powerdown", GPIOD_OUT_HIGH);
  76. if (IS_ERR(gpio)) {
  77. dev_err(&pdev->dev, "failed to parse powerdown gpio\n");
  78. return PTR_ERR(gpio);
  79. }
  80. ddata->pd_gpio = gpio;
  81. dssdev = &ddata->dssdev;
  82. dssdev->ops = &tfp410_ops;
  83. dssdev->dev = &pdev->dev;
  84. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  85. dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
  86. dssdev->owner = THIS_MODULE;
  87. dssdev->of_ports = BIT(1) | BIT(0);
  88. dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
  89. | DRM_BUS_FLAG_PIXDATA_POSEDGE;
  90. dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
  91. if (IS_ERR(dssdev->next)) {
  92. if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
  93. dev_err(&pdev->dev, "failed to find video sink\n");
  94. return PTR_ERR(dssdev->next);
  95. }
  96. omapdss_device_register(dssdev);
  97. return 0;
  98. }
  99. static int __exit tfp410_remove(struct platform_device *pdev)
  100. {
  101. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  102. struct omap_dss_device *dssdev = &ddata->dssdev;
  103. if (dssdev->next)
  104. omapdss_device_put(dssdev->next);
  105. omapdss_device_unregister(&ddata->dssdev);
  106. WARN_ON(omapdss_device_is_enabled(dssdev));
  107. if (omapdss_device_is_enabled(dssdev))
  108. tfp410_disable(dssdev);
  109. WARN_ON(omapdss_device_is_connected(dssdev));
  110. if (omapdss_device_is_connected(dssdev))
  111. omapdss_device_disconnect(NULL, dssdev);
  112. return 0;
  113. }
  114. static const struct of_device_id tfp410_of_match[] = {
  115. { .compatible = "omapdss,ti,tfp410", },
  116. {},
  117. };
  118. MODULE_DEVICE_TABLE(of, tfp410_of_match);
  119. static struct platform_driver tfp410_driver = {
  120. .probe = tfp410_probe,
  121. .remove = __exit_p(tfp410_remove),
  122. .driver = {
  123. .name = "tfp410",
  124. .of_match_table = tfp410_of_match,
  125. .suppress_bind_attrs = true,
  126. },
  127. };
  128. module_platform_driver(tfp410_driver);
  129. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  130. MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
  131. MODULE_LICENSE("GPL");