encoder-opa362.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 const struct omapdss_atv_ops opa362_atv_ops = {
  117. .connect = opa362_connect,
  118. .disconnect = opa362_disconnect,
  119. .enable = opa362_enable,
  120. .disable = opa362_disable,
  121. .check_timings = opa362_check_timings,
  122. .set_timings = opa362_set_timings,
  123. .get_timings = opa362_get_timings,
  124. };
  125. static int opa362_probe(struct platform_device *pdev)
  126. {
  127. struct device_node *node = pdev->dev.of_node;
  128. struct panel_drv_data *ddata;
  129. struct omap_dss_device *dssdev, *in;
  130. struct gpio_desc *gpio;
  131. int r;
  132. dev_dbg(&pdev->dev, "probe\n");
  133. if (node == NULL) {
  134. dev_err(&pdev->dev, "Unable to find device tree\n");
  135. return -EINVAL;
  136. }
  137. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  138. if (!ddata)
  139. return -ENOMEM;
  140. platform_set_drvdata(pdev, ddata);
  141. gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
  142. if (IS_ERR(gpio))
  143. return PTR_ERR(gpio);
  144. ddata->enable_gpio = gpio;
  145. in = omapdss_of_find_source_for_first_ep(node);
  146. if (IS_ERR(in)) {
  147. dev_err(&pdev->dev, "failed to find video source\n");
  148. return PTR_ERR(in);
  149. }
  150. ddata->in = in;
  151. dssdev = &ddata->dssdev;
  152. dssdev->ops.atv = &opa362_atv_ops;
  153. dssdev->dev = &pdev->dev;
  154. dssdev->type = OMAP_DISPLAY_TYPE_VENC;
  155. dssdev->output_type = OMAP_DISPLAY_TYPE_VENC;
  156. dssdev->owner = THIS_MODULE;
  157. r = omapdss_register_output(dssdev);
  158. if (r) {
  159. dev_err(&pdev->dev, "Failed to register output\n");
  160. goto err_reg;
  161. }
  162. return 0;
  163. err_reg:
  164. omap_dss_put_device(ddata->in);
  165. return r;
  166. }
  167. static int __exit opa362_remove(struct platform_device *pdev)
  168. {
  169. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  170. struct omap_dss_device *dssdev = &ddata->dssdev;
  171. struct omap_dss_device *in = ddata->in;
  172. omapdss_unregister_output(&ddata->dssdev);
  173. WARN_ON(omapdss_device_is_enabled(dssdev));
  174. if (omapdss_device_is_enabled(dssdev))
  175. opa362_disable(dssdev);
  176. WARN_ON(omapdss_device_is_connected(dssdev));
  177. if (omapdss_device_is_connected(dssdev))
  178. opa362_disconnect(dssdev, dssdev->dst);
  179. omap_dss_put_device(in);
  180. return 0;
  181. }
  182. static const struct of_device_id opa362_of_match[] = {
  183. { .compatible = "omapdss,ti,opa362", },
  184. {},
  185. };
  186. MODULE_DEVICE_TABLE(of, opa362_of_match);
  187. static struct platform_driver opa362_driver = {
  188. .probe = opa362_probe,
  189. .remove = __exit_p(opa362_remove),
  190. .driver = {
  191. .name = "amplifier-opa362",
  192. .of_match_table = opa362_of_match,
  193. .suppress_bind_attrs = true,
  194. },
  195. };
  196. module_platform_driver(opa362_driver);
  197. MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
  198. MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
  199. MODULE_LICENSE("GPL v2");