connector-hdmi.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 <drm/drm_edid.h>
  15. #include <video/omapdss.h>
  16. #include <video/omap-panel-data.h>
  17. static const struct omap_video_timings hdmic_default_timings = {
  18. .x_res = 640,
  19. .y_res = 480,
  20. .pixel_clock = 25175,
  21. .hsw = 96,
  22. .hfp = 16,
  23. .hbp = 48,
  24. .vsw = 2,
  25. .vfp = 11,
  26. .vbp = 31,
  27. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  28. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  29. .interlace = false,
  30. };
  31. struct panel_drv_data {
  32. struct omap_dss_device dssdev;
  33. struct omap_dss_device *in;
  34. struct device *dev;
  35. struct omap_video_timings timings;
  36. };
  37. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  38. static int hdmic_connect(struct omap_dss_device *dssdev)
  39. {
  40. struct panel_drv_data *ddata = to_panel_data(dssdev);
  41. struct omap_dss_device *in = ddata->in;
  42. int r;
  43. dev_dbg(ddata->dev, "connect\n");
  44. if (omapdss_device_is_connected(dssdev))
  45. return 0;
  46. r = in->ops.hdmi->connect(in, dssdev);
  47. if (r)
  48. return r;
  49. return 0;
  50. }
  51. static void hdmic_disconnect(struct omap_dss_device *dssdev)
  52. {
  53. struct panel_drv_data *ddata = to_panel_data(dssdev);
  54. struct omap_dss_device *in = ddata->in;
  55. dev_dbg(ddata->dev, "disconnect\n");
  56. if (!omapdss_device_is_connected(dssdev))
  57. return;
  58. in->ops.hdmi->disconnect(in, dssdev);
  59. }
  60. static int hdmic_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(ddata->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.hdmi->set_timings(in, &ddata->timings);
  71. r = in->ops.hdmi->enable(in);
  72. if (r)
  73. return r;
  74. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  75. return r;
  76. }
  77. static void hdmic_disable(struct omap_dss_device *dssdev)
  78. {
  79. struct panel_drv_data *ddata = to_panel_data(dssdev);
  80. struct omap_dss_device *in = ddata->in;
  81. dev_dbg(ddata->dev, "disable\n");
  82. if (!omapdss_device_is_enabled(dssdev))
  83. return;
  84. in->ops.hdmi->disable(in);
  85. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  86. }
  87. static void hdmic_set_timings(struct omap_dss_device *dssdev,
  88. struct omap_video_timings *timings)
  89. {
  90. struct panel_drv_data *ddata = to_panel_data(dssdev);
  91. struct omap_dss_device *in = ddata->in;
  92. ddata->timings = *timings;
  93. dssdev->panel.timings = *timings;
  94. in->ops.hdmi->set_timings(in, timings);
  95. }
  96. static void hdmic_get_timings(struct omap_dss_device *dssdev,
  97. struct omap_video_timings *timings)
  98. {
  99. struct panel_drv_data *ddata = to_panel_data(dssdev);
  100. *timings = ddata->timings;
  101. }
  102. static int hdmic_check_timings(struct omap_dss_device *dssdev,
  103. struct omap_video_timings *timings)
  104. {
  105. struct panel_drv_data *ddata = to_panel_data(dssdev);
  106. struct omap_dss_device *in = ddata->in;
  107. return in->ops.hdmi->check_timings(in, timings);
  108. }
  109. static int hdmic_read_edid(struct omap_dss_device *dssdev,
  110. u8 *edid, int len)
  111. {
  112. struct panel_drv_data *ddata = to_panel_data(dssdev);
  113. struct omap_dss_device *in = ddata->in;
  114. return in->ops.hdmi->read_edid(in, edid, len);
  115. }
  116. static bool hdmic_detect(struct omap_dss_device *dssdev)
  117. {
  118. struct panel_drv_data *ddata = to_panel_data(dssdev);
  119. struct omap_dss_device *in = ddata->in;
  120. return in->ops.hdmi->detect(in);
  121. }
  122. static int hdmic_audio_enable(struct omap_dss_device *dssdev)
  123. {
  124. struct panel_drv_data *ddata = to_panel_data(dssdev);
  125. struct omap_dss_device *in = ddata->in;
  126. int r;
  127. /* enable audio only if the display is active */
  128. if (!omapdss_device_is_enabled(dssdev))
  129. return -EPERM;
  130. r = in->ops.hdmi->audio_enable(in);
  131. if (r)
  132. return r;
  133. dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
  134. return 0;
  135. }
  136. static void hdmic_audio_disable(struct omap_dss_device *dssdev)
  137. {
  138. struct panel_drv_data *ddata = to_panel_data(dssdev);
  139. struct omap_dss_device *in = ddata->in;
  140. in->ops.hdmi->audio_disable(in);
  141. dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
  142. }
  143. static int hdmic_audio_start(struct omap_dss_device *dssdev)
  144. {
  145. struct panel_drv_data *ddata = to_panel_data(dssdev);
  146. struct omap_dss_device *in = ddata->in;
  147. int r;
  148. /*
  149. * No need to check the panel state. It was checked when trasitioning
  150. * to AUDIO_ENABLED.
  151. */
  152. if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED)
  153. return -EPERM;
  154. r = in->ops.hdmi->audio_start(in);
  155. if (r)
  156. return r;
  157. dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
  158. return 0;
  159. }
  160. static void hdmic_audio_stop(struct omap_dss_device *dssdev)
  161. {
  162. struct panel_drv_data *ddata = to_panel_data(dssdev);
  163. struct omap_dss_device *in = ddata->in;
  164. in->ops.hdmi->audio_stop(in);
  165. dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
  166. }
  167. static bool hdmic_audio_supported(struct omap_dss_device *dssdev)
  168. {
  169. struct panel_drv_data *ddata = to_panel_data(dssdev);
  170. struct omap_dss_device *in = ddata->in;
  171. if (!omapdss_device_is_enabled(dssdev))
  172. return false;
  173. return in->ops.hdmi->audio_supported(in);
  174. }
  175. static int hdmic_audio_config(struct omap_dss_device *dssdev,
  176. struct omap_dss_audio *audio)
  177. {
  178. struct panel_drv_data *ddata = to_panel_data(dssdev);
  179. struct omap_dss_device *in = ddata->in;
  180. int r;
  181. /* config audio only if the display is active */
  182. if (!omapdss_device_is_enabled(dssdev))
  183. return -EPERM;
  184. r = in->ops.hdmi->audio_config(in, audio);
  185. if (r)
  186. return r;
  187. dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
  188. return 0;
  189. }
  190. static struct omap_dss_driver hdmic_driver = {
  191. .connect = hdmic_connect,
  192. .disconnect = hdmic_disconnect,
  193. .enable = hdmic_enable,
  194. .disable = hdmic_disable,
  195. .set_timings = hdmic_set_timings,
  196. .get_timings = hdmic_get_timings,
  197. .check_timings = hdmic_check_timings,
  198. .get_resolution = omapdss_default_get_resolution,
  199. .read_edid = hdmic_read_edid,
  200. .detect = hdmic_detect,
  201. .audio_enable = hdmic_audio_enable,
  202. .audio_disable = hdmic_audio_disable,
  203. .audio_start = hdmic_audio_start,
  204. .audio_stop = hdmic_audio_stop,
  205. .audio_supported = hdmic_audio_supported,
  206. .audio_config = hdmic_audio_config,
  207. };
  208. static int hdmic_probe_pdata(struct platform_device *pdev)
  209. {
  210. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  211. struct connector_hdmi_platform_data *pdata;
  212. struct omap_dss_device *in, *dssdev;
  213. pdata = dev_get_platdata(&pdev->dev);
  214. in = omap_dss_find_output(pdata->source);
  215. if (in == NULL) {
  216. dev_err(&pdev->dev, "Failed to find video source\n");
  217. return -EPROBE_DEFER;
  218. }
  219. ddata->in = in;
  220. dssdev = &ddata->dssdev;
  221. dssdev->name = pdata->name;
  222. return 0;
  223. }
  224. static int hdmic_probe(struct platform_device *pdev)
  225. {
  226. struct panel_drv_data *ddata;
  227. struct omap_dss_device *dssdev;
  228. int r;
  229. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  230. if (!ddata)
  231. return -ENOMEM;
  232. platform_set_drvdata(pdev, ddata);
  233. ddata->dev = &pdev->dev;
  234. if (dev_get_platdata(&pdev->dev)) {
  235. r = hdmic_probe_pdata(pdev);
  236. if (r)
  237. return r;
  238. } else {
  239. return -ENODEV;
  240. }
  241. ddata->timings = hdmic_default_timings;
  242. dssdev = &ddata->dssdev;
  243. dssdev->driver = &hdmic_driver;
  244. dssdev->dev = &pdev->dev;
  245. dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
  246. dssdev->owner = THIS_MODULE;
  247. dssdev->panel.timings = hdmic_default_timings;
  248. r = omapdss_register_display(dssdev);
  249. if (r) {
  250. dev_err(&pdev->dev, "Failed to register panel\n");
  251. goto err_reg;
  252. }
  253. return 0;
  254. err_reg:
  255. omap_dss_put_device(ddata->in);
  256. return r;
  257. }
  258. static int __exit hdmic_remove(struct platform_device *pdev)
  259. {
  260. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  261. struct omap_dss_device *dssdev = &ddata->dssdev;
  262. struct omap_dss_device *in = ddata->in;
  263. omapdss_unregister_display(&ddata->dssdev);
  264. hdmic_disable(dssdev);
  265. hdmic_disconnect(dssdev);
  266. omap_dss_put_device(in);
  267. return 0;
  268. }
  269. static struct platform_driver hdmi_connector_driver = {
  270. .probe = hdmic_probe,
  271. .remove = __exit_p(hdmic_remove),
  272. .driver = {
  273. .name = "connector-hdmi",
  274. .owner = THIS_MODULE,
  275. },
  276. };
  277. module_platform_driver(hdmi_connector_driver);
  278. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  279. MODULE_DESCRIPTION("HDMI Connector driver");
  280. MODULE_LICENSE("GPL");