4 * HDMI library support functions for TI OMAP4 processors.
6 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
7 * Authors: Mythri P k <mythripk@ti.com>
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.
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
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/>.
22 #include <linux/kernel.h>
23 #include <linux/err.h>
25 #include <linux/mutex.h>
26 #include <linux/module.h>
27 #include <video/omapdss.h>
28 #include <linux/slab.h>
33 /* This protects the panel ops, mainly when accessing the HDMI IP. */
35 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
36 /* This protects the audio ops, specifically. */
37 spinlock_t audio_lock;
42 static int hdmi_panel_probe(struct omap_dss_device *dssdev)
44 /* Initialize default timings to VGA in DVI mode */
45 const struct omap_video_timings default_timings = {
56 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
57 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
62 DSSDBG("ENTER hdmi_panel_probe\n");
64 dssdev->panel.timings = default_timings;
66 DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
67 dssdev->panel.timings.x_res,
68 dssdev->panel.timings.y_res);
70 omapdss_hdmi_display_set_timing(dssdev, &dssdev->panel.timings);
75 static void hdmi_panel_remove(struct omap_dss_device *dssdev)
80 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
81 static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
86 mutex_lock(&hdmi.lock);
87 spin_lock_irqsave(&hdmi.audio_lock, flags);
89 /* enable audio only if the display is active and supports audio */
90 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
91 !hdmi_mode_has_audio()) {
92 DSSERR("audio not supported or display is off\n");
97 r = hdmi_audio_enable();
100 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
103 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
104 mutex_unlock(&hdmi.lock);
108 static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
112 spin_lock_irqsave(&hdmi.audio_lock, flags);
114 hdmi_audio_disable();
116 dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
118 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
121 static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
126 spin_lock_irqsave(&hdmi.audio_lock, flags);
128 * No need to check the panel state. It was checked when trasitioning
131 if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED) {
132 DSSERR("audio start from invalid state\n");
137 r = hdmi_audio_start();
140 dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
143 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
147 static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
151 spin_lock_irqsave(&hdmi.audio_lock, flags);
154 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
156 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
159 static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
163 mutex_lock(&hdmi.lock);
165 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
168 if (!hdmi_mode_has_audio())
173 mutex_unlock(&hdmi.lock);
177 static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
178 struct omap_dss_audio *audio)
183 mutex_lock(&hdmi.lock);
184 spin_lock_irqsave(&hdmi.audio_lock, flags);
186 /* config audio only if the display is active and supports audio */
187 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
188 !hdmi_mode_has_audio()) {
189 DSSERR("audio not supported or display is off\n");
194 r = hdmi_audio_config(audio);
197 dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
200 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
201 mutex_unlock(&hdmi.lock);
206 static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
211 static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
215 static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
220 static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
224 static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
229 static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
230 struct omap_dss_audio *audio)
236 static int hdmi_panel_enable(struct omap_dss_device *dssdev)
239 DSSDBG("ENTER hdmi_panel_enable\n");
241 mutex_lock(&hdmi.lock);
243 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
248 omapdss_hdmi_display_set_timing(dssdev, &dssdev->panel.timings);
250 r = omapdss_hdmi_display_enable(dssdev);
252 DSSERR("failed to power on\n");
256 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
259 mutex_unlock(&hdmi.lock);
264 static void hdmi_panel_disable(struct omap_dss_device *dssdev)
266 mutex_lock(&hdmi.lock);
268 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
270 * TODO: notify audio users that the display was disabled. For
271 * now, disable audio locally to not break our audio state
274 hdmi_panel_audio_disable(dssdev);
275 omapdss_hdmi_display_disable(dssdev);
278 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
280 mutex_unlock(&hdmi.lock);
283 static void hdmi_get_timings(struct omap_dss_device *dssdev,
284 struct omap_video_timings *timings)
286 mutex_lock(&hdmi.lock);
288 *timings = dssdev->panel.timings;
290 mutex_unlock(&hdmi.lock);
293 static void hdmi_set_timings(struct omap_dss_device *dssdev,
294 struct omap_video_timings *timings)
296 DSSDBG("hdmi_set_timings\n");
298 mutex_lock(&hdmi.lock);
301 * TODO: notify audio users that there was a timings change. For
302 * now, disable audio locally to not break our audio state machine.
304 hdmi_panel_audio_disable(dssdev);
306 omapdss_hdmi_display_set_timing(dssdev, timings);
307 dssdev->panel.timings = *timings;
309 mutex_unlock(&hdmi.lock);
312 static int hdmi_check_timings(struct omap_dss_device *dssdev,
313 struct omap_video_timings *timings)
317 DSSDBG("hdmi_check_timings\n");
319 mutex_lock(&hdmi.lock);
321 r = omapdss_hdmi_display_check_timing(dssdev, timings);
323 mutex_unlock(&hdmi.lock);
327 static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
332 mutex_lock(&hdmi.lock);
334 need_enable = dssdev->state == OMAP_DSS_DISPLAY_DISABLED;
337 r = omapdss_hdmi_core_enable(dssdev);
342 r = omapdss_hdmi_read_edid(buf, len);
345 omapdss_hdmi_core_disable(dssdev);
347 mutex_unlock(&hdmi.lock);
352 static bool hdmi_detect(struct omap_dss_device *dssdev)
357 mutex_lock(&hdmi.lock);
359 need_enable = dssdev->state == OMAP_DSS_DISPLAY_DISABLED;
362 r = omapdss_hdmi_core_enable(dssdev);
367 r = omapdss_hdmi_detect();
370 omapdss_hdmi_core_disable(dssdev);
372 mutex_unlock(&hdmi.lock);
377 static struct omap_dss_driver hdmi_driver = {
378 .probe = hdmi_panel_probe,
379 .remove = hdmi_panel_remove,
380 .enable = hdmi_panel_enable,
381 .disable = hdmi_panel_disable,
382 .get_timings = hdmi_get_timings,
383 .set_timings = hdmi_set_timings,
384 .check_timings = hdmi_check_timings,
385 .read_edid = hdmi_read_edid,
386 .detect = hdmi_detect,
387 .audio_enable = hdmi_panel_audio_enable,
388 .audio_disable = hdmi_panel_audio_disable,
389 .audio_start = hdmi_panel_audio_start,
390 .audio_stop = hdmi_panel_audio_stop,
391 .audio_supported = hdmi_panel_audio_supported,
392 .audio_config = hdmi_panel_audio_config,
394 .name = "hdmi_panel",
395 .owner = THIS_MODULE,
399 int hdmi_panel_init(void)
401 mutex_init(&hdmi.lock);
403 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
404 spin_lock_init(&hdmi.audio_lock);
407 return omap_dss_register_driver(&hdmi_driver);
410 void hdmi_panel_exit(void)
412 omap_dss_unregister_driver(&hdmi_driver);