encoder-opa362.c 6.2 KB

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