connector-hdmi.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * HDMI Connector driver
  3. *
  4. * Copyright (C) 2013 Texas Instruments
  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/slab.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/of.h>
  15. #include <linux/of_gpio.h>
  16. #include <drm/drm_edid.h>
  17. #include <video/omapdss.h>
  18. #include <video/omap-panel-data.h>
  19. static const struct omap_video_timings hdmic_default_timings = {
  20. .x_res = 640,
  21. .y_res = 480,
  22. .pixelclock = 25175000,
  23. .hsw = 96,
  24. .hfp = 16,
  25. .hbp = 48,
  26. .vsw = 2,
  27. .vfp = 11,
  28. .vbp = 31,
  29. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  30. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  31. .interlace = false,
  32. };
  33. struct panel_drv_data {
  34. struct omap_dss_device dssdev;
  35. struct omap_dss_device *in;
  36. struct device *dev;
  37. struct omap_video_timings timings;
  38. int hpd_gpio;
  39. };
  40. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  41. static int hdmic_connect(struct omap_dss_device *dssdev)
  42. {
  43. struct panel_drv_data *ddata = to_panel_data(dssdev);
  44. struct omap_dss_device *in = ddata->in;
  45. int r;
  46. dev_dbg(ddata->dev, "connect\n");
  47. if (omapdss_device_is_connected(dssdev))
  48. return 0;
  49. r = in->ops.hdmi->connect(in, dssdev);
  50. if (r)
  51. return r;
  52. return 0;
  53. }
  54. static void hdmic_disconnect(struct omap_dss_device *dssdev)
  55. {
  56. struct panel_drv_data *ddata = to_panel_data(dssdev);
  57. struct omap_dss_device *in = ddata->in;
  58. dev_dbg(ddata->dev, "disconnect\n");
  59. if (!omapdss_device_is_connected(dssdev))
  60. return;
  61. in->ops.hdmi->disconnect(in, dssdev);
  62. }
  63. static int hdmic_enable(struct omap_dss_device *dssdev)
  64. {
  65. struct panel_drv_data *ddata = to_panel_data(dssdev);
  66. struct omap_dss_device *in = ddata->in;
  67. int r;
  68. dev_dbg(ddata->dev, "enable\n");
  69. if (!omapdss_device_is_connected(dssdev))
  70. return -ENODEV;
  71. if (omapdss_device_is_enabled(dssdev))
  72. return 0;
  73. in->ops.hdmi->set_timings(in, &ddata->timings);
  74. r = in->ops.hdmi->enable(in);
  75. if (r)
  76. return r;
  77. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  78. return r;
  79. }
  80. static void hdmic_disable(struct omap_dss_device *dssdev)
  81. {
  82. struct panel_drv_data *ddata = to_panel_data(dssdev);
  83. struct omap_dss_device *in = ddata->in;
  84. dev_dbg(ddata->dev, "disable\n");
  85. if (!omapdss_device_is_enabled(dssdev))
  86. return;
  87. in->ops.hdmi->disable(in);
  88. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  89. }
  90. static void hdmic_set_timings(struct omap_dss_device *dssdev,
  91. struct omap_video_timings *timings)
  92. {
  93. struct panel_drv_data *ddata = to_panel_data(dssdev);
  94. struct omap_dss_device *in = ddata->in;
  95. ddata->timings = *timings;
  96. dssdev->panel.timings = *timings;
  97. in->ops.hdmi->set_timings(in, timings);
  98. }
  99. static void hdmic_get_timings(struct omap_dss_device *dssdev,
  100. struct omap_video_timings *timings)
  101. {
  102. struct panel_drv_data *ddata = to_panel_data(dssdev);
  103. *timings = ddata->timings;
  104. }
  105. static int hdmic_check_timings(struct omap_dss_device *dssdev,
  106. struct omap_video_timings *timings)
  107. {
  108. struct panel_drv_data *ddata = to_panel_data(dssdev);
  109. struct omap_dss_device *in = ddata->in;
  110. return in->ops.hdmi->check_timings(in, timings);
  111. }
  112. static int hdmic_read_edid(struct omap_dss_device *dssdev,
  113. u8 *edid, int len)
  114. {
  115. struct panel_drv_data *ddata = to_panel_data(dssdev);
  116. struct omap_dss_device *in = ddata->in;
  117. return in->ops.hdmi->read_edid(in, edid, len);
  118. }
  119. static bool hdmic_detect(struct omap_dss_device *dssdev)
  120. {
  121. struct panel_drv_data *ddata = to_panel_data(dssdev);
  122. struct omap_dss_device *in = ddata->in;
  123. if (gpio_is_valid(ddata->hpd_gpio))
  124. return gpio_get_value_cansleep(ddata->hpd_gpio);
  125. else
  126. return in->ops.hdmi->detect(in);
  127. }
  128. static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
  129. {
  130. struct panel_drv_data *ddata = to_panel_data(dssdev);
  131. struct omap_dss_device *in = ddata->in;
  132. return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
  133. }
  134. static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
  135. const struct hdmi_avi_infoframe *avi)
  136. {
  137. struct panel_drv_data *ddata = to_panel_data(dssdev);
  138. struct omap_dss_device *in = ddata->in;
  139. return in->ops.hdmi->set_infoframe(in, avi);
  140. }
  141. static struct omap_dss_driver hdmic_driver = {
  142. .connect = hdmic_connect,
  143. .disconnect = hdmic_disconnect,
  144. .enable = hdmic_enable,
  145. .disable = hdmic_disable,
  146. .set_timings = hdmic_set_timings,
  147. .get_timings = hdmic_get_timings,
  148. .check_timings = hdmic_check_timings,
  149. .get_resolution = omapdss_default_get_resolution,
  150. .read_edid = hdmic_read_edid,
  151. .detect = hdmic_detect,
  152. .set_hdmi_mode = hdmic_set_hdmi_mode,
  153. .set_hdmi_infoframe = hdmic_set_infoframe,
  154. };
  155. static int hdmic_probe_of(struct platform_device *pdev)
  156. {
  157. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  158. struct device_node *node = pdev->dev.of_node;
  159. struct omap_dss_device *in;
  160. int gpio;
  161. /* HPD GPIO */
  162. gpio = of_get_named_gpio(node, "hpd-gpios", 0);
  163. if (gpio_is_valid(gpio))
  164. ddata->hpd_gpio = gpio;
  165. else
  166. ddata->hpd_gpio = -ENODEV;
  167. in = omapdss_of_find_source_for_first_ep(node);
  168. if (IS_ERR(in)) {
  169. dev_err(&pdev->dev, "failed to find video source\n");
  170. return PTR_ERR(in);
  171. }
  172. ddata->in = in;
  173. return 0;
  174. }
  175. static int hdmic_probe(struct platform_device *pdev)
  176. {
  177. struct panel_drv_data *ddata;
  178. struct omap_dss_device *dssdev;
  179. int r;
  180. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  181. if (!ddata)
  182. return -ENOMEM;
  183. platform_set_drvdata(pdev, ddata);
  184. ddata->dev = &pdev->dev;
  185. if (!pdev->dev.of_node)
  186. return -ENODEV;
  187. r = hdmic_probe_of(pdev);
  188. if (r)
  189. return r;
  190. if (gpio_is_valid(ddata->hpd_gpio)) {
  191. r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
  192. GPIOF_DIR_IN, "hdmi_hpd");
  193. if (r)
  194. goto err_reg;
  195. }
  196. ddata->timings = hdmic_default_timings;
  197. dssdev = &ddata->dssdev;
  198. dssdev->driver = &hdmic_driver;
  199. dssdev->dev = &pdev->dev;
  200. dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
  201. dssdev->owner = THIS_MODULE;
  202. dssdev->panel.timings = hdmic_default_timings;
  203. r = omapdss_register_display(dssdev);
  204. if (r) {
  205. dev_err(&pdev->dev, "Failed to register panel\n");
  206. goto err_reg;
  207. }
  208. return 0;
  209. err_reg:
  210. omap_dss_put_device(ddata->in);
  211. return r;
  212. }
  213. static int __exit hdmic_remove(struct platform_device *pdev)
  214. {
  215. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  216. struct omap_dss_device *dssdev = &ddata->dssdev;
  217. struct omap_dss_device *in = ddata->in;
  218. omapdss_unregister_display(&ddata->dssdev);
  219. hdmic_disable(dssdev);
  220. hdmic_disconnect(dssdev);
  221. omap_dss_put_device(in);
  222. return 0;
  223. }
  224. static const struct of_device_id hdmic_of_match[] = {
  225. { .compatible = "omapdss,hdmi-connector", },
  226. {},
  227. };
  228. MODULE_DEVICE_TABLE(of, hdmic_of_match);
  229. static struct platform_driver hdmi_connector_driver = {
  230. .probe = hdmic_probe,
  231. .remove = __exit_p(hdmic_remove),
  232. .driver = {
  233. .name = "connector-hdmi",
  234. .of_match_table = hdmic_of_match,
  235. .suppress_bind_attrs = true,
  236. },
  237. };
  238. module_platform_driver(hdmi_connector_driver);
  239. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  240. MODULE_DESCRIPTION("HDMI Connector driver");
  241. MODULE_LICENSE("GPL");