hdmi_panel.c 9.2 KB

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