encoder-opa362.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 omap_dss_device *in;
  24. struct gpio_desc *enable_gpio;
  25. struct videomode vm;
  26. };
  27. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  28. static int opa362_connect(struct omap_dss_device *dssdev,
  29. struct omap_dss_device *dst)
  30. {
  31. struct panel_drv_data *ddata = to_panel_data(dssdev);
  32. struct omap_dss_device *in;
  33. int r;
  34. dev_dbg(dssdev->dev, "connect\n");
  35. if (omapdss_device_is_connected(dssdev))
  36. return -EBUSY;
  37. in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
  38. if (IS_ERR(in)) {
  39. dev_err(dssdev->dev, "failed to find video source\n");
  40. return PTR_ERR(in);
  41. }
  42. r = in->ops.atv->connect(in, dssdev);
  43. if (r) {
  44. omap_dss_put_device(in);
  45. return r;
  46. }
  47. dst->src = dssdev;
  48. dssdev->dst = dst;
  49. ddata->in = in;
  50. return 0;
  51. }
  52. static void opa362_disconnect(struct omap_dss_device *dssdev,
  53. struct omap_dss_device *dst)
  54. {
  55. struct panel_drv_data *ddata = to_panel_data(dssdev);
  56. struct omap_dss_device *in = ddata->in;
  57. dev_dbg(dssdev->dev, "disconnect\n");
  58. WARN_ON(!omapdss_device_is_connected(dssdev));
  59. if (!omapdss_device_is_connected(dssdev))
  60. return;
  61. WARN_ON(dst != dssdev->dst);
  62. if (dst != dssdev->dst)
  63. return;
  64. dst->src = NULL;
  65. dssdev->dst = NULL;
  66. in->ops.atv->disconnect(in, &ddata->dssdev);
  67. omap_dss_put_device(in);
  68. ddata->in = NULL;
  69. }
  70. static int opa362_enable(struct omap_dss_device *dssdev)
  71. {
  72. struct panel_drv_data *ddata = to_panel_data(dssdev);
  73. struct omap_dss_device *in = ddata->in;
  74. int r;
  75. dev_dbg(dssdev->dev, "enable\n");
  76. if (!omapdss_device_is_connected(dssdev))
  77. return -ENODEV;
  78. if (omapdss_device_is_enabled(dssdev))
  79. return 0;
  80. in->ops.atv->set_timings(in, &ddata->vm);
  81. r = in->ops.atv->enable(in);
  82. if (r)
  83. return r;
  84. if (ddata->enable_gpio)
  85. gpiod_set_value_cansleep(ddata->enable_gpio, 1);
  86. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  87. return 0;
  88. }
  89. static void opa362_disable(struct omap_dss_device *dssdev)
  90. {
  91. struct panel_drv_data *ddata = to_panel_data(dssdev);
  92. struct omap_dss_device *in = ddata->in;
  93. dev_dbg(dssdev->dev, "disable\n");
  94. if (!omapdss_device_is_enabled(dssdev))
  95. return;
  96. if (ddata->enable_gpio)
  97. gpiod_set_value_cansleep(ddata->enable_gpio, 0);
  98. in->ops.atv->disable(in);
  99. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  100. }
  101. static void opa362_set_timings(struct omap_dss_device *dssdev,
  102. struct videomode *vm)
  103. {
  104. struct panel_drv_data *ddata = to_panel_data(dssdev);
  105. struct omap_dss_device *in = ddata->in;
  106. dev_dbg(dssdev->dev, "set_timings\n");
  107. ddata->vm = *vm;
  108. dssdev->panel.vm = *vm;
  109. in->ops.atv->set_timings(in, vm);
  110. }
  111. static void opa362_get_timings(struct omap_dss_device *dssdev,
  112. struct videomode *vm)
  113. {
  114. struct panel_drv_data *ddata = to_panel_data(dssdev);
  115. dev_dbg(dssdev->dev, "get_timings\n");
  116. *vm = ddata->vm;
  117. }
  118. static int opa362_check_timings(struct omap_dss_device *dssdev,
  119. struct videomode *vm)
  120. {
  121. struct panel_drv_data *ddata = to_panel_data(dssdev);
  122. struct omap_dss_device *in = ddata->in;
  123. dev_dbg(dssdev->dev, "check_timings\n");
  124. return in->ops.atv->check_timings(in, vm);
  125. }
  126. static const struct omapdss_atv_ops opa362_atv_ops = {
  127. .connect = opa362_connect,
  128. .disconnect = opa362_disconnect,
  129. .enable = opa362_enable,
  130. .disable = opa362_disable,
  131. .check_timings = opa362_check_timings,
  132. .set_timings = opa362_set_timings,
  133. .get_timings = opa362_get_timings,
  134. };
  135. static int opa362_probe(struct platform_device *pdev)
  136. {
  137. struct panel_drv_data *ddata;
  138. struct omap_dss_device *dssdev;
  139. struct gpio_desc *gpio;
  140. int r;
  141. dev_dbg(&pdev->dev, "probe\n");
  142. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  143. if (!ddata)
  144. return -ENOMEM;
  145. platform_set_drvdata(pdev, ddata);
  146. gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
  147. if (IS_ERR(gpio))
  148. return PTR_ERR(gpio);
  149. ddata->enable_gpio = gpio;
  150. dssdev = &ddata->dssdev;
  151. dssdev->ops.atv = &opa362_atv_ops;
  152. dssdev->dev = &pdev->dev;
  153. dssdev->type = OMAP_DISPLAY_TYPE_VENC;
  154. dssdev->output_type = OMAP_DISPLAY_TYPE_VENC;
  155. dssdev->owner = THIS_MODULE;
  156. r = omapdss_register_output(dssdev);
  157. if (r) {
  158. dev_err(&pdev->dev, "Failed to register output\n");
  159. return r;
  160. }
  161. return 0;
  162. }
  163. static int __exit opa362_remove(struct platform_device *pdev)
  164. {
  165. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  166. struct omap_dss_device *dssdev = &ddata->dssdev;
  167. omapdss_unregister_output(&ddata->dssdev);
  168. WARN_ON(omapdss_device_is_enabled(dssdev));
  169. if (omapdss_device_is_enabled(dssdev))
  170. opa362_disable(dssdev);
  171. WARN_ON(omapdss_device_is_connected(dssdev));
  172. if (omapdss_device_is_connected(dssdev))
  173. opa362_disconnect(dssdev, dssdev->dst);
  174. return 0;
  175. }
  176. static const struct of_device_id opa362_of_match[] = {
  177. { .compatible = "omapdss,ti,opa362", },
  178. {},
  179. };
  180. MODULE_DEVICE_TABLE(of, opa362_of_match);
  181. static struct platform_driver opa362_driver = {
  182. .probe = opa362_probe,
  183. .remove = __exit_p(opa362_remove),
  184. .driver = {
  185. .name = "amplifier-opa362",
  186. .of_match_table = opa362_of_match,
  187. .suppress_bind_attrs = true,
  188. },
  189. };
  190. module_platform_driver(opa362_driver);
  191. MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
  192. MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
  193. MODULE_LICENSE("GPL v2");