2011-03-10 18:18:48 +08:00
|
|
|
/*
|
2011-09-08 21:36:27 +08:00
|
|
|
* hdmi_panel.c
|
2011-03-10 18:18:48 +08:00
|
|
|
*
|
|
|
|
* 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>
|
2011-05-11 19:05:07 +08:00
|
|
|
#include <video/omapdss.h>
|
2011-08-29 23:10:20 +08:00
|
|
|
#include <linux/slab.h>
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
#include "dss.h"
|
|
|
|
|
|
|
|
static struct {
|
2012-04-26 08:29:06 +08:00
|
|
|
/* This protects the panel ops, mainly when accessing the HDMI IP. */
|
|
|
|
struct mutex lock;
|
2012-05-10 10:09:50 +08:00
|
|
|
#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
|
|
|
|
/* This protects the audio ops, specifically. */
|
|
|
|
spinlock_t audio_lock;
|
|
|
|
#endif
|
2011-03-10 18:18:48 +08:00
|
|
|
} hdmi;
|
|
|
|
|
|
|
|
|
|
|
|
static int hdmi_panel_probe(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
DSSDBG("ENTER hdmi_panel_probe\n");
|
|
|
|
|
2012-06-25 14:56:38 +08:00
|
|
|
dssdev->panel.timings = (struct omap_video_timings)
|
|
|
|
{ 640, 480, 25175, 96, 16, 48, 2, 11, 31,
|
|
|
|
OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
|
2012-06-28 13:45:51 +08:00
|
|
|
false,
|
2012-06-25 14:56:38 +08:00
|
|
|
};
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
|
|
|
|
dssdev->panel.timings.x_res,
|
|
|
|
dssdev->panel.timings.y_res);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hdmi_panel_remove(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-10 10:09:50 +08:00
|
|
|
#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
|
|
|
|
|
2011-03-10 18:18:48 +08:00
|
|
|
static int hdmi_panel_enable(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
DSSDBG("ENTER hdmi_panel_enable\n");
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
|
|
|
|
r = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = omapdss_hdmi_display_enable(dssdev);
|
|
|
|
if (r) {
|
|
|
|
DSSERR("failed to power on\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
|
|
|
|
|
|
|
|
err:
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hdmi_panel_disable(struct omap_dss_device *dssdev)
|
|
|
|
{
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
2012-05-10 10:09:50 +08:00
|
|
|
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);
|
2011-03-10 18:18:48 +08:00
|
|
|
omapdss_hdmi_display_disable(dssdev);
|
2012-05-10 10:09:50 +08:00
|
|
|
}
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hdmi_panel_suspend(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
|
|
|
|
r = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2012-05-10 10:09:50 +08:00
|
|
|
/*
|
|
|
|
* TODO: notify audio users that the display was suspended. For now,
|
|
|
|
* disable audio locally to not break our audio state machine.
|
|
|
|
*/
|
|
|
|
hdmi_panel_audio_disable(dssdev);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
2012-05-10 10:09:50 +08:00
|
|
|
dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
|
2011-03-10 18:18:48 +08:00
|
|
|
omapdss_hdmi_display_disable(dssdev);
|
|
|
|
|
|
|
|
err:
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hdmi_panel_resume(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
|
|
|
|
r = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = omapdss_hdmi_display_enable(dssdev);
|
|
|
|
if (r) {
|
|
|
|
DSSERR("failed to power on\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2012-05-10 10:09:50 +08:00
|
|
|
/* TODO: notify audio users that the panel resumed. */
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
|
|
|
|
|
|
|
|
err:
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hdmi_get_timings(struct omap_dss_device *dssdev,
|
|
|
|
struct omap_video_timings *timings)
|
|
|
|
{
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
*timings = dssdev->panel.timings;
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hdmi_set_timings(struct omap_dss_device *dssdev,
|
|
|
|
struct omap_video_timings *timings)
|
|
|
|
{
|
|
|
|
DSSDBG("hdmi_set_timings\n");
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
2012-05-10 10:09:50 +08:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2011-03-10 18:18:48 +08:00
|
|
|
dssdev->panel.timings = *timings;
|
2011-08-22 19:57:33 +08:00
|
|
|
omapdss_hdmi_display_set_timing(dssdev);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hdmi_check_timings(struct omap_dss_device *dssdev,
|
|
|
|
struct omap_video_timings *timings)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
DSSDBG("hdmi_check_timings\n");
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
|
|
|
r = omapdss_hdmi_display_check_timing(dssdev, timings);
|
2011-08-25 22:13:32 +08:00
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-08-25 22:12:56 +08:00
|
|
|
static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-08-25 22:12:56 +08:00
|
|
|
|
|
|
|
if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
|
|
|
|
r = omapdss_hdmi_display_enable(dssdev);
|
|
|
|
if (r)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = omapdss_hdmi_read_edid(buf, len);
|
|
|
|
|
|
|
|
if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
|
|
|
|
dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
|
|
|
|
omapdss_hdmi_display_disable(dssdev);
|
|
|
|
err:
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-08-25 22:12:56 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-08-29 23:10:20 +08:00
|
|
|
static bool hdmi_detect(struct omap_dss_device *dssdev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_lock(&hdmi.lock);
|
2011-08-29 23:10:20 +08:00
|
|
|
|
|
|
|
if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
|
|
|
|
r = omapdss_hdmi_display_enable(dssdev);
|
|
|
|
if (r)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = omapdss_hdmi_detect();
|
|
|
|
|
|
|
|
if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
|
|
|
|
dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
|
|
|
|
omapdss_hdmi_display_disable(dssdev);
|
|
|
|
err:
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_unlock(&hdmi.lock);
|
2011-08-29 23:10:20 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-03-10 18:18:48 +08:00
|
|
|
static struct omap_dss_driver hdmi_driver = {
|
|
|
|
.probe = hdmi_panel_probe,
|
|
|
|
.remove = hdmi_panel_remove,
|
|
|
|
.enable = hdmi_panel_enable,
|
|
|
|
.disable = hdmi_panel_disable,
|
|
|
|
.suspend = hdmi_panel_suspend,
|
|
|
|
.resume = hdmi_panel_resume,
|
|
|
|
.get_timings = hdmi_get_timings,
|
|
|
|
.set_timings = hdmi_set_timings,
|
|
|
|
.check_timings = hdmi_check_timings,
|
2011-08-25 22:12:56 +08:00
|
|
|
.read_edid = hdmi_read_edid,
|
2011-08-29 23:10:20 +08:00
|
|
|
.detect = hdmi_detect,
|
2012-05-10 10:09:50 +08:00
|
|
|
.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,
|
2011-03-10 18:18:48 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "hdmi_panel",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
int hdmi_panel_init(void)
|
|
|
|
{
|
2012-04-26 08:29:06 +08:00
|
|
|
mutex_init(&hdmi.lock);
|
2011-03-10 18:18:48 +08:00
|
|
|
|
2012-05-10 10:09:50 +08:00
|
|
|
#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
|
|
|
|
spin_lock_init(&hdmi.audio_lock);
|
|
|
|
#endif
|
|
|
|
|
2011-03-10 18:18:48 +08:00
|
|
|
omap_dss_register_driver(&hdmi_driver);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hdmi_panel_exit(void)
|
|
|
|
{
|
|
|
|
omap_dss_unregister_driver(&hdmi_driver);
|
|
|
|
|
|
|
|
}
|