hdmi_panel.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. DSSDBG("ENTER hdmi_panel_probe\n");
  40. dssdev->panel.timings = (struct omap_video_timings)
  41. { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
  42. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  43. };
  44. DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
  45. dssdev->panel.timings.x_res,
  46. dssdev->panel.timings.y_res);
  47. return 0;
  48. }
  49. static void hdmi_panel_remove(struct omap_dss_device *dssdev)
  50. {
  51. }
  52. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  53. static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
  54. {
  55. unsigned long flags;
  56. int r;
  57. mutex_lock(&hdmi.lock);
  58. spin_lock_irqsave(&hdmi.audio_lock, flags);
  59. /* enable audio only if the display is active and supports audio */
  60. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
  61. !hdmi_mode_has_audio()) {
  62. DSSERR("audio not supported or display is off\n");
  63. r = -EPERM;
  64. goto err;
  65. }
  66. r = hdmi_audio_enable();
  67. if (!r)
  68. dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
  69. err:
  70. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  71. mutex_unlock(&hdmi.lock);
  72. return r;
  73. }
  74. static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
  75. {
  76. unsigned long flags;
  77. spin_lock_irqsave(&hdmi.audio_lock, flags);
  78. hdmi_audio_disable();
  79. dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
  80. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  81. }
  82. static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
  83. {
  84. unsigned long flags;
  85. int r;
  86. spin_lock_irqsave(&hdmi.audio_lock, flags);
  87. /*
  88. * No need to check the panel state. It was checked when trasitioning
  89. * to AUDIO_ENABLED.
  90. */
  91. if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED) {
  92. DSSERR("audio start from invalid state\n");
  93. r = -EPERM;
  94. goto err;
  95. }
  96. r = hdmi_audio_start();
  97. if (!r)
  98. dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
  99. err:
  100. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  101. return r;
  102. }
  103. static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
  104. {
  105. unsigned long flags;
  106. spin_lock_irqsave(&hdmi.audio_lock, flags);
  107. hdmi_audio_stop();
  108. dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
  109. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  110. }
  111. static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
  112. {
  113. bool r = false;
  114. mutex_lock(&hdmi.lock);
  115. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  116. goto err;
  117. if (!hdmi_mode_has_audio())
  118. goto err;
  119. r = true;
  120. err:
  121. mutex_unlock(&hdmi.lock);
  122. return r;
  123. }
  124. static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
  125. struct omap_dss_audio *audio)
  126. {
  127. unsigned long flags;
  128. int r;
  129. mutex_lock(&hdmi.lock);
  130. spin_lock_irqsave(&hdmi.audio_lock, flags);
  131. /* config audio only if the display is active and supports audio */
  132. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
  133. !hdmi_mode_has_audio()) {
  134. DSSERR("audio not supported or display is off\n");
  135. r = -EPERM;
  136. goto err;
  137. }
  138. r = hdmi_audio_config(audio);
  139. if (!r)
  140. dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
  141. err:
  142. spin_unlock_irqrestore(&hdmi.audio_lock, flags);
  143. mutex_unlock(&hdmi.lock);
  144. return r;
  145. }
  146. #else
  147. static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
  148. {
  149. return -EPERM;
  150. }
  151. static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
  152. {
  153. }
  154. static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
  155. {
  156. return -EPERM;
  157. }
  158. static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
  159. {
  160. }
  161. static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
  162. {
  163. return false;
  164. }
  165. static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
  166. struct omap_dss_audio *audio)
  167. {
  168. return -EPERM;
  169. }
  170. #endif
  171. static int hdmi_panel_enable(struct omap_dss_device *dssdev)
  172. {
  173. int r = 0;
  174. DSSDBG("ENTER hdmi_panel_enable\n");
  175. mutex_lock(&hdmi.lock);
  176. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  177. r = -EINVAL;
  178. goto err;
  179. }
  180. r = omapdss_hdmi_display_enable(dssdev);
  181. if (r) {
  182. DSSERR("failed to power on\n");
  183. goto err;
  184. }
  185. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  186. err:
  187. mutex_unlock(&hdmi.lock);
  188. return r;
  189. }
  190. static void hdmi_panel_disable(struct omap_dss_device *dssdev)
  191. {
  192. mutex_lock(&hdmi.lock);
  193. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  194. /*
  195. * TODO: notify audio users that the display was disabled. For
  196. * now, disable audio locally to not break our audio state
  197. * machine.
  198. */
  199. hdmi_panel_audio_disable(dssdev);
  200. omapdss_hdmi_display_disable(dssdev);
  201. }
  202. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  203. mutex_unlock(&hdmi.lock);
  204. }
  205. static int hdmi_panel_suspend(struct omap_dss_device *dssdev)
  206. {
  207. int r = 0;
  208. mutex_lock(&hdmi.lock);
  209. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  210. r = -EINVAL;
  211. goto err;
  212. }
  213. /*
  214. * TODO: notify audio users that the display was suspended. For now,
  215. * disable audio locally to not break our audio state machine.
  216. */
  217. hdmi_panel_audio_disable(dssdev);
  218. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  219. omapdss_hdmi_display_disable(dssdev);
  220. err:
  221. mutex_unlock(&hdmi.lock);
  222. return r;
  223. }
  224. static int hdmi_panel_resume(struct omap_dss_device *dssdev)
  225. {
  226. int r = 0;
  227. mutex_lock(&hdmi.lock);
  228. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  229. r = -EINVAL;
  230. goto err;
  231. }
  232. r = omapdss_hdmi_display_enable(dssdev);
  233. if (r) {
  234. DSSERR("failed to power on\n");
  235. goto err;
  236. }
  237. /* TODO: notify audio users that the panel resumed. */
  238. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  239. err:
  240. mutex_unlock(&hdmi.lock);
  241. return r;
  242. }
  243. static void hdmi_get_timings(struct omap_dss_device *dssdev,
  244. struct omap_video_timings *timings)
  245. {
  246. mutex_lock(&hdmi.lock);
  247. *timings = dssdev->panel.timings;
  248. mutex_unlock(&hdmi.lock);
  249. }
  250. static void hdmi_set_timings(struct omap_dss_device *dssdev,
  251. struct omap_video_timings *timings)
  252. {
  253. DSSDBG("hdmi_set_timings\n");
  254. mutex_lock(&hdmi.lock);
  255. /*
  256. * TODO: notify audio users that there was a timings change. For
  257. * now, disable audio locally to not break our audio state machine.
  258. */
  259. hdmi_panel_audio_disable(dssdev);
  260. dssdev->panel.timings = *timings;
  261. omapdss_hdmi_display_set_timing(dssdev);
  262. mutex_unlock(&hdmi.lock);
  263. }
  264. static int hdmi_check_timings(struct omap_dss_device *dssdev,
  265. struct omap_video_timings *timings)
  266. {
  267. int r = 0;
  268. DSSDBG("hdmi_check_timings\n");
  269. mutex_lock(&hdmi.lock);
  270. r = omapdss_hdmi_display_check_timing(dssdev, timings);
  271. mutex_unlock(&hdmi.lock);
  272. return r;
  273. }
  274. static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
  275. {
  276. int r;
  277. mutex_lock(&hdmi.lock);
  278. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  279. r = omapdss_hdmi_display_enable(dssdev);
  280. if (r)
  281. goto err;
  282. }
  283. r = omapdss_hdmi_read_edid(buf, len);
  284. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
  285. dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
  286. omapdss_hdmi_display_disable(dssdev);
  287. err:
  288. mutex_unlock(&hdmi.lock);
  289. return r;
  290. }
  291. static bool hdmi_detect(struct omap_dss_device *dssdev)
  292. {
  293. int r;
  294. mutex_lock(&hdmi.lock);
  295. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  296. r = omapdss_hdmi_display_enable(dssdev);
  297. if (r)
  298. goto err;
  299. }
  300. r = omapdss_hdmi_detect();
  301. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
  302. dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
  303. omapdss_hdmi_display_disable(dssdev);
  304. err:
  305. mutex_unlock(&hdmi.lock);
  306. return r;
  307. }
  308. static struct omap_dss_driver hdmi_driver = {
  309. .probe = hdmi_panel_probe,
  310. .remove = hdmi_panel_remove,
  311. .enable = hdmi_panel_enable,
  312. .disable = hdmi_panel_disable,
  313. .suspend = hdmi_panel_suspend,
  314. .resume = hdmi_panel_resume,
  315. .get_timings = hdmi_get_timings,
  316. .set_timings = hdmi_set_timings,
  317. .check_timings = hdmi_check_timings,
  318. .read_edid = hdmi_read_edid,
  319. .detect = hdmi_detect,
  320. .audio_enable = hdmi_panel_audio_enable,
  321. .audio_disable = hdmi_panel_audio_disable,
  322. .audio_start = hdmi_panel_audio_start,
  323. .audio_stop = hdmi_panel_audio_stop,
  324. .audio_supported = hdmi_panel_audio_supported,
  325. .audio_config = hdmi_panel_audio_config,
  326. .driver = {
  327. .name = "hdmi_panel",
  328. .owner = THIS_MODULE,
  329. },
  330. };
  331. int hdmi_panel_init(void)
  332. {
  333. mutex_init(&hdmi.lock);
  334. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  335. spin_lock_init(&hdmi.audio_lock);
  336. #endif
  337. omap_dss_register_driver(&hdmi_driver);
  338. return 0;
  339. }
  340. void hdmi_panel_exit(void)
  341. {
  342. omap_dss_unregister_driver(&hdmi_driver);
  343. }