encoder-opa362.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * OPA362 analog video amplifier with output/power control
  3. *
  4. * Copyright (C) 2014 Golden Delicious Computers
  5. * Author: H. Nikolaus Schaller <hns@goldelico.com>
  6. *
  7. * based on encoder-tfp410
  8. *
  9. * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
  10. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published by
  14. * the Free Software Foundation.
  15. */
  16. #include <linux/gpio/consumer.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/slab.h>
  20. #include "../dss/omapdss.h"
  21. struct panel_drv_data {
  22. struct omap_dss_device dssdev;
  23. struct gpio_desc *enable_gpio;
  24. };
  25. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  26. static int opa362_connect(struct omap_dss_device *src,
  27. struct omap_dss_device *dst)
  28. {
  29. return omapdss_device_connect(dst->dss, dst, dst->next);
  30. }
  31. static void opa362_disconnect(struct omap_dss_device *src,
  32. struct omap_dss_device *dst)
  33. {
  34. omapdss_device_disconnect(dst, dst->next);
  35. }
  36. static int opa362_enable(struct omap_dss_device *dssdev)
  37. {
  38. struct panel_drv_data *ddata = to_panel_data(dssdev);
  39. struct omap_dss_device *src = dssdev->src;
  40. int r;
  41. dev_dbg(dssdev->dev, "enable\n");
  42. if (!omapdss_device_is_connected(dssdev))
  43. return -ENODEV;
  44. if (omapdss_device_is_enabled(dssdev))
  45. return 0;
  46. r = src->ops->enable(src);
  47. if (r)
  48. return r;
  49. if (ddata->enable_gpio)
  50. gpiod_set_value_cansleep(ddata->enable_gpio, 1);
  51. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  52. return 0;
  53. }
  54. static void opa362_disable(struct omap_dss_device *dssdev)
  55. {
  56. struct panel_drv_data *ddata = to_panel_data(dssdev);
  57. struct omap_dss_device *src = dssdev->src;
  58. dev_dbg(dssdev->dev, "disable\n");
  59. if (!omapdss_device_is_enabled(dssdev))
  60. return;
  61. if (ddata->enable_gpio)
  62. gpiod_set_value_cansleep(ddata->enable_gpio, 0);
  63. src->ops->disable(src);
  64. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  65. }
  66. static const struct omap_dss_device_ops opa362_ops = {
  67. .connect = opa362_connect,
  68. .disconnect = opa362_disconnect,
  69. .enable = opa362_enable,
  70. .disable = opa362_disable,
  71. };
  72. static int opa362_probe(struct platform_device *pdev)
  73. {
  74. struct panel_drv_data *ddata;
  75. struct omap_dss_device *dssdev;
  76. struct gpio_desc *gpio;
  77. dev_dbg(&pdev->dev, "probe\n");
  78. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  79. if (!ddata)
  80. return -ENOMEM;
  81. platform_set_drvdata(pdev, ddata);
  82. gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
  83. if (IS_ERR(gpio))
  84. return PTR_ERR(gpio);
  85. ddata->enable_gpio = gpio;
  86. dssdev = &ddata->dssdev;
  87. dssdev->ops = &opa362_ops;
  88. dssdev->dev = &pdev->dev;
  89. dssdev->type = OMAP_DISPLAY_TYPE_VENC;
  90. dssdev->output_type = OMAP_DISPLAY_TYPE_VENC;
  91. dssdev->owner = THIS_MODULE;
  92. dssdev->of_ports = BIT(1) | BIT(0);
  93. dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
  94. if (IS_ERR(dssdev->next)) {
  95. if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
  96. dev_err(&pdev->dev, "failed to find video sink\n");
  97. return PTR_ERR(dssdev->next);
  98. }
  99. omapdss_device_register(dssdev);
  100. return 0;
  101. }
  102. static int __exit opa362_remove(struct platform_device *pdev)
  103. {
  104. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  105. struct omap_dss_device *dssdev = &ddata->dssdev;
  106. if (dssdev->next)
  107. omapdss_device_put(dssdev->next);
  108. omapdss_device_unregister(&ddata->dssdev);
  109. WARN_ON(omapdss_device_is_enabled(dssdev));
  110. if (omapdss_device_is_enabled(dssdev))
  111. opa362_disable(dssdev);
  112. WARN_ON(omapdss_device_is_connected(dssdev));
  113. if (omapdss_device_is_connected(dssdev))
  114. omapdss_device_disconnect(NULL, dssdev);
  115. return 0;
  116. }
  117. static const struct of_device_id opa362_of_match[] = {
  118. { .compatible = "omapdss,ti,opa362", },
  119. {},
  120. };
  121. MODULE_DEVICE_TABLE(of, opa362_of_match);
  122. static struct platform_driver opa362_driver = {
  123. .probe = opa362_probe,
  124. .remove = __exit_p(opa362_remove),
  125. .driver = {
  126. .name = "amplifier-opa362",
  127. .of_match_table = opa362_of_match,
  128. .suppress_bind_attrs = true,
  129. },
  130. };
  131. module_platform_driver(opa362_driver);
  132. MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
  133. MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
  134. MODULE_LICENSE("GPL v2");