123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- /*
- * hdmi_panel.c
- *
- * HDMI library support functions for TI OMAP4 processors.
- *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
- * Authors: Mythri P k <mythripk@ti.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <linux/kernel.h>
- #include <linux/err.h>
- #include <linux/io.h>
- #include <linux/mutex.h>
- #include <linux/module.h>
- #include <video/omapdss.h>
- #include <linux/slab.h>
- #include "dss.h"
- static struct {
- /* This protects the panel ops, mainly when accessing the HDMI IP. */
- struct mutex lock;
- #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
- /* This protects the audio ops, specifically. */
- spinlock_t audio_lock;
- #endif
- } hdmi;
- static int hdmi_panel_probe(struct omap_dss_device *dssdev)
- {
- /* Initialize default timings to VGA in DVI mode */
- const struct omap_video_timings default_timings = {
- .x_res = 640,
- .y_res = 480,
- .pixel_clock = 25175,
- .hsw = 96,
- .hfp = 16,
- .hbp = 48,
- .vsw = 2,
- .vfp = 11,
- .vbp = 31,
- .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
- .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
- .interlace = false,
- };
- DSSDBG("ENTER hdmi_panel_probe\n");
- dssdev->panel.timings = default_timings;
- DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
- dssdev->panel.timings.x_res,
- dssdev->panel.timings.y_res);
- omapdss_hdmi_display_set_timing(dssdev, &dssdev->panel.timings);
- return 0;
- }
- static void hdmi_panel_remove(struct omap_dss_device *dssdev)
- {
- }
- #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
- static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
- {
- unsigned long flags;
- int r;
- mutex_lock(&hdmi.lock);
- spin_lock_irqsave(&hdmi.audio_lock, flags);
- /* enable audio only if the display is active and supports audio */
- if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
- !hdmi_mode_has_audio()) {
- DSSERR("audio not supported or display is off\n");
- r = -EPERM;
- goto err;
- }
- r = hdmi_audio_enable();
- if (!r)
- dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
- err:
- spin_unlock_irqrestore(&hdmi.audio_lock, flags);
- mutex_unlock(&hdmi.lock);
- return r;
- }
- static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
- {
- unsigned long flags;
- spin_lock_irqsave(&hdmi.audio_lock, flags);
- hdmi_audio_disable();
- dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
- spin_unlock_irqrestore(&hdmi.audio_lock, flags);
- }
- static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
- {
- unsigned long flags;
- int r;
- spin_lock_irqsave(&hdmi.audio_lock, flags);
- /*
- * No need to check the panel state. It was checked when trasitioning
- * to AUDIO_ENABLED.
- */
- if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED) {
- DSSERR("audio start from invalid state\n");
- r = -EPERM;
- goto err;
- }
- r = hdmi_audio_start();
- if (!r)
- dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
- err:
- spin_unlock_irqrestore(&hdmi.audio_lock, flags);
- return r;
- }
- static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
- {
- unsigned long flags;
- spin_lock_irqsave(&hdmi.audio_lock, flags);
- hdmi_audio_stop();
- dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
- spin_unlock_irqrestore(&hdmi.audio_lock, flags);
- }
- static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
- {
- bool r = false;
- mutex_lock(&hdmi.lock);
- if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
- goto err;
- if (!hdmi_mode_has_audio())
- goto err;
- r = true;
- err:
- mutex_unlock(&hdmi.lock);
- return r;
- }
- static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
- struct omap_dss_audio *audio)
- {
- unsigned long flags;
- int r;
- mutex_lock(&hdmi.lock);
- spin_lock_irqsave(&hdmi.audio_lock, flags);
- /* config audio only if the display is active and supports audio */
- if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
- !hdmi_mode_has_audio()) {
- DSSERR("audio not supported or display is off\n");
- r = -EPERM;
- goto err;
- }
- r = hdmi_audio_config(audio);
- if (!r)
- dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
- err:
- spin_unlock_irqrestore(&hdmi.audio_lock, flags);
- mutex_unlock(&hdmi.lock);
- return r;
- }
- #else
- static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
- {
- return -EPERM;
- }
- static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
- {
- }
- static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
- {
- return -EPERM;
- }
- static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
- {
- }
- static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
- {
- return false;
- }
- static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
- struct omap_dss_audio *audio)
- {
- return -EPERM;
- }
- #endif
- static int hdmi_panel_enable(struct omap_dss_device *dssdev)
- {
- int r = 0;
- DSSDBG("ENTER hdmi_panel_enable\n");
- mutex_lock(&hdmi.lock);
- if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
- r = -EINVAL;
- goto err;
- }
- omapdss_hdmi_display_set_timing(dssdev, &dssdev->panel.timings);
- r = omapdss_hdmi_display_enable(dssdev);
- if (r) {
- DSSERR("failed to power on\n");
- goto err;
- }
- dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
- err:
- mutex_unlock(&hdmi.lock);
- return r;
- }
- static void hdmi_panel_disable(struct omap_dss_device *dssdev)
- {
- mutex_lock(&hdmi.lock);
- if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
- /*
- * TODO: notify audio users that the display was disabled. For
- * now, disable audio locally to not break our audio state
- * machine.
- */
- hdmi_panel_audio_disable(dssdev);
- omapdss_hdmi_display_disable(dssdev);
- }
- dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
- mutex_unlock(&hdmi.lock);
- }
- static void hdmi_get_timings(struct omap_dss_device *dssdev,
- struct omap_video_timings *timings)
- {
- mutex_lock(&hdmi.lock);
- *timings = dssdev->panel.timings;
- mutex_unlock(&hdmi.lock);
- }
- static void hdmi_set_timings(struct omap_dss_device *dssdev,
- struct omap_video_timings *timings)
- {
- DSSDBG("hdmi_set_timings\n");
- mutex_lock(&hdmi.lock);
- /*
- * TODO: notify audio users that there was a timings change. For
- * now, disable audio locally to not break our audio state machine.
- */
- hdmi_panel_audio_disable(dssdev);
- omapdss_hdmi_display_set_timing(dssdev, timings);
- dssdev->panel.timings = *timings;
- mutex_unlock(&hdmi.lock);
- }
- static int hdmi_check_timings(struct omap_dss_device *dssdev,
- struct omap_video_timings *timings)
- {
- int r = 0;
- DSSDBG("hdmi_check_timings\n");
- mutex_lock(&hdmi.lock);
- r = omapdss_hdmi_display_check_timing(dssdev, timings);
- mutex_unlock(&hdmi.lock);
- return r;
- }
- static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
- {
- int r;
- bool need_enable;
- mutex_lock(&hdmi.lock);
- need_enable = dssdev->state == OMAP_DSS_DISPLAY_DISABLED;
- if (need_enable) {
- r = omapdss_hdmi_core_enable(dssdev);
- if (r)
- goto err;
- }
- r = omapdss_hdmi_read_edid(buf, len);
- if (need_enable)
- omapdss_hdmi_core_disable(dssdev);
- err:
- mutex_unlock(&hdmi.lock);
- return r;
- }
- static bool hdmi_detect(struct omap_dss_device *dssdev)
- {
- int r;
- bool need_enable;
- mutex_lock(&hdmi.lock);
- need_enable = dssdev->state == OMAP_DSS_DISPLAY_DISABLED;
- if (need_enable) {
- r = omapdss_hdmi_core_enable(dssdev);
- if (r)
- goto err;
- }
- r = omapdss_hdmi_detect();
- if (need_enable)
- omapdss_hdmi_core_disable(dssdev);
- err:
- mutex_unlock(&hdmi.lock);
- return r;
- }
- static struct omap_dss_driver hdmi_driver = {
- .probe = hdmi_panel_probe,
- .remove = hdmi_panel_remove,
- .enable = hdmi_panel_enable,
- .disable = hdmi_panel_disable,
- .get_timings = hdmi_get_timings,
- .set_timings = hdmi_set_timings,
- .check_timings = hdmi_check_timings,
- .read_edid = hdmi_read_edid,
- .detect = hdmi_detect,
- .audio_enable = hdmi_panel_audio_enable,
- .audio_disable = hdmi_panel_audio_disable,
- .audio_start = hdmi_panel_audio_start,
- .audio_stop = hdmi_panel_audio_stop,
- .audio_supported = hdmi_panel_audio_supported,
- .audio_config = hdmi_panel_audio_config,
- .driver = {
- .name = "hdmi_panel",
- .owner = THIS_MODULE,
- },
- };
- int hdmi_panel_init(void)
- {
- mutex_init(&hdmi.lock);
- #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
- spin_lock_init(&hdmi.audio_lock);
- #endif
- return omap_dss_register_driver(&hdmi_driver);
- }
- void hdmi_panel_exit(void)
- {
- omap_dss_unregister_driver(&hdmi_driver);
- }
|