hdmi_panel.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * hdmi_panel.c
  3. *
  4. * HDMI library support functions for TI OMAP4 processors.
  5. *
  6. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  7. * Authors: Mythri P k <mythripk@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/err.h>
  23. #include <linux/io.h>
  24. #include <linux/mutex.h>
  25. #include <linux/module.h>
  26. #include <video/omapdss.h>
  27. #include <linux/slab.h>
  28. #include "dss.h"
  29. static struct {
  30. /* This protects the panel ops, mainly when accessing the HDMI IP. */
  31. struct mutex lock;
  32. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  33. /* This protects the audio ops, specifically. */
  34. spinlock_t audio_lock;
  35. #endif
  36. } hdmi;
  37. static int hdmi_panel_probe(struct omap_dss_device *dssdev)
  38. {
  39. /* Initialize default timings to VGA in DVI mode */
  40. const struct omap_video_timings default_timings = {
  41. .x_res = 640,
  42. .y_res = 480,
  43. .pixel_clock = 25175,
  44. .hsw = 96,
  45. .hfp = 16,
  46. .hbp = 48,
  47. .vsw = 2,
  48. .vfp = 11,
  49. .vbp = 31,
  50. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  51. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  52. .interlace = false,
  53. };
  54. DSSDBG("ENTER hdmi_panel_probe\n");
  55. dssdev->panel.timings = default_timings;
  56. DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
  57. dssdev->panel.timings.x_res,
  58. dssdev->panel.timings.y_res);
  59. omapdss_hdmi_display_set_timing(dssdev, &dssdev->panel.timings);
  60. return 0;
  61. }
  62. static void hdmi_panel_remove(struct omap_dss_device *dssdev)
  63. {
  64. }
  65. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  66. static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
  67. {
  68. unsigned long flags;
  69. int r;
  70. mutex_lock(&hdmi.lock);
  71. spin_lock_irqsave(&hdmi.audio_lock, flags);
  72. /* enable audio only if the display is active and supports audio */
  73. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
  74. !hdmi_mode_has_audio()) {
  75. DSSERR("audio not supported or display is off\n");
  76. r = -EPERM;
  77. goto err;
  78. }
  79. r = hdmi_audio_enable();
  80. if (!r)
  81. dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
  82. err:
  83. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  84. mutex_unlock(&hdmi.lock);
  85. return r;
  86. }
  87. static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
  88. {
  89. unsigned long flags;
  90. spin_lock_irqsave(&hdmi.audio_lock, flags);
  91. hdmi_audio_disable();
  92. dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
  93. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  94. }
  95. static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
  96. {
  97. unsigned long flags;
  98. int r;
  99. spin_lock_irqsave(&hdmi.audio_lock, flags);
  100. /*
  101. * No need to check the panel state. It was checked when trasitioning
  102. * to AUDIO_ENABLED.
  103. */
  104. if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED) {
  105. DSSERR("audio start from invalid state\n");
  106. r = -EPERM;
  107. goto err;
  108. }
  109. r = hdmi_audio_start();
  110. if (!r)
  111. dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
  112. err:
  113. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  114. return r;
  115. }
  116. static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
  117. {
  118. unsigned long flags;
  119. spin_lock_irqsave(&hdmi.audio_lock, flags);
  120. hdmi_audio_stop();
  121. dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
  122. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  123. }
  124. static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
  125. {
  126. bool r = false;
  127. mutex_lock(&hdmi.lock);
  128. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  129. goto err;
  130. if (!hdmi_mode_has_audio())
  131. goto err;
  132. r = true;
  133. err:
  134. mutex_unlock(&hdmi.lock);
  135. return r;
  136. }
  137. static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
  138. struct omap_dss_audio *audio)
  139. {
  140. unsigned long flags;
  141. int r;
  142. mutex_lock(&hdmi.lock);
  143. spin_lock_irqsave(&hdmi.audio_lock, flags);
  144. /* config audio only if the display is active and supports audio */
  145. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
  146. !hdmi_mode_has_audio()) {
  147. DSSERR("audio not supported or display is off\n");
  148. r = -EPERM;
  149. goto err;
  150. }
  151. r = hdmi_audio_config(audio);
  152. if (!r)
  153. dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
  154. err:
  155. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  156. mutex_unlock(&hdmi.lock);
  157. return r;
  158. }
  159. #else
  160. static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
  161. {
  162. return -EPERM;
  163. }
  164. static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
  165. {
  166. }
  167. static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
  168. {
  169. return -EPERM;
  170. }
  171. static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
  172. {
  173. }
  174. static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
  175. {
  176. return false;
  177. }
  178. static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
  179. struct omap_dss_audio *audio)
  180. {
  181. return -EPERM;
  182. }
  183. #endif
  184. static int hdmi_panel_enable(struct omap_dss_device *dssdev)
  185. {
  186. int r = 0;
  187. DSSDBG("ENTER hdmi_panel_enable\n");
  188. mutex_lock(&hdmi.lock);
  189. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  190. r = -EINVAL;
  191. goto err;
  192. }
  193. omapdss_hdmi_display_set_timing(dssdev, &dssdev->panel.timings);
  194. r = omapdss_hdmi_display_enable(dssdev);
  195. if (r) {
  196. DSSERR("failed to power on\n");
  197. goto err;
  198. }
  199. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  200. err:
  201. mutex_unlock(&hdmi.lock);
  202. return r;
  203. }
  204. static void hdmi_panel_disable(struct omap_dss_device *dssdev)
  205. {
  206. mutex_lock(&hdmi.lock);
  207. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  208. /*
  209. * TODO: notify audio users that the display was disabled. For
  210. * now, disable audio locally to not break our audio state
  211. * machine.
  212. */
  213. hdmi_panel_audio_disable(dssdev);
  214. omapdss_hdmi_display_disable(dssdev);
  215. }
  216. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  217. mutex_unlock(&hdmi.lock);
  218. }
  219. static void hdmi_get_timings(struct omap_dss_device *dssdev,
  220. struct omap_video_timings *timings)
  221. {
  222. mutex_lock(&hdmi.lock);
  223. *timings = dssdev->panel.timings;
  224. mutex_unlock(&hdmi.lock);
  225. }
  226. static void hdmi_set_timings(struct omap_dss_device *dssdev,
  227. struct omap_video_timings *timings)
  228. {
  229. DSSDBG("hdmi_set_timings\n");
  230. mutex_lock(&hdmi.lock);
  231. /*
  232. * TODO: notify audio users that there was a timings change. For
  233. * now, disable audio locally to not break our audio state machine.
  234. */
  235. hdmi_panel_audio_disable(dssdev);
  236. omapdss_hdmi_display_set_timing(dssdev, timings);
  237. dssdev->panel.timings = *timings;
  238. mutex_unlock(&hdmi.lock);
  239. }
  240. static int hdmi_check_timings(struct omap_dss_device *dssdev,
  241. struct omap_video_timings *timings)
  242. {
  243. int r = 0;
  244. DSSDBG("hdmi_check_timings\n");
  245. mutex_lock(&hdmi.lock);
  246. r = omapdss_hdmi_display_check_timing(dssdev, timings);
  247. mutex_unlock(&hdmi.lock);
  248. return r;
  249. }
  250. static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
  251. {
  252. int r;
  253. bool need_enable;
  254. mutex_lock(&hdmi.lock);
  255. need_enable = dssdev->state == OMAP_DSS_DISPLAY_DISABLED;
  256. if (need_enable) {
  257. r = omapdss_hdmi_core_enable(dssdev);
  258. if (r)
  259. goto err;
  260. }
  261. r = omapdss_hdmi_read_edid(buf, len);
  262. if (need_enable)
  263. omapdss_hdmi_core_disable(dssdev);
  264. err:
  265. mutex_unlock(&hdmi.lock);
  266. return r;
  267. }
  268. static bool hdmi_detect(struct omap_dss_device *dssdev)
  269. {
  270. int r;
  271. bool need_enable;
  272. mutex_lock(&hdmi.lock);
  273. need_enable = dssdev->state == OMAP_DSS_DISPLAY_DISABLED;
  274. if (need_enable) {
  275. r = omapdss_hdmi_core_enable(dssdev);
  276. if (r)
  277. goto err;
  278. }
  279. r = omapdss_hdmi_detect();
  280. if (need_enable)
  281. omapdss_hdmi_core_disable(dssdev);
  282. err:
  283. mutex_unlock(&hdmi.lock);
  284. return r;
  285. }
  286. static struct omap_dss_driver hdmi_driver = {
  287. .probe = hdmi_panel_probe,
  288. .remove = hdmi_panel_remove,
  289. .enable = hdmi_panel_enable,
  290. .disable = hdmi_panel_disable,
  291. .get_timings = hdmi_get_timings,
  292. .set_timings = hdmi_set_timings,
  293. .check_timings = hdmi_check_timings,
  294. .read_edid = hdmi_read_edid,
  295. .detect = hdmi_detect,
  296. .audio_enable = hdmi_panel_audio_enable,
  297. .audio_disable = hdmi_panel_audio_disable,
  298. .audio_start = hdmi_panel_audio_start,
  299. .audio_stop = hdmi_panel_audio_stop,
  300. .audio_supported = hdmi_panel_audio_supported,
  301. .audio_config = hdmi_panel_audio_config,
  302. .driver = {
  303. .name = "hdmi_panel",
  304. .owner = THIS_MODULE,
  305. },
  306. };
  307. int hdmi_panel_init(void)
  308. {
  309. mutex_init(&hdmi.lock);
  310. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  311. spin_lock_init(&hdmi.audio_lock);
  312. #endif
  313. return omap_dss_register_driver(&hdmi_driver);
  314. }
  315. void hdmi_panel_exit(void)
  316. {
  317. omap_dss_unregister_driver(&hdmi_driver);
  318. }