2013-08-31 00:02:15 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Red Hat
|
|
|
|
* Author: Rob Clark <robdclark@gmail.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 "hdmi.h"
|
|
|
|
|
|
|
|
struct hdmi_bridge {
|
|
|
|
struct drm_bridge base;
|
|
|
|
struct hdmi *hdmi;
|
|
|
|
};
|
|
|
|
#define to_hdmi_bridge(x) container_of(x, struct hdmi_bridge, base)
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
void msm_hdmi_bridge_destroy(struct drm_bridge *bridge)
|
2013-08-31 00:02:15 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
static void msm_hdmi_power_on(struct drm_bridge *bridge)
|
2013-12-02 00:12:54 +07:00
|
|
|
{
|
|
|
|
struct drm_device *dev = bridge->dev;
|
|
|
|
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
|
|
|
|
struct hdmi *hdmi = hdmi_bridge->hdmi;
|
|
|
|
const struct hdmi_platform_config *config = hdmi->config;
|
|
|
|
int i, ret;
|
|
|
|
|
2017-07-28 17:47:02 +07:00
|
|
|
pm_runtime_get_sync(&hdmi->pdev->dev);
|
|
|
|
|
2013-12-02 00:12:54 +07:00
|
|
|
for (i = 0; i < config->pwr_reg_cnt; i++) {
|
|
|
|
ret = regulator_enable(hdmi->pwr_regs[i]);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev->dev, "failed to enable pwr regulator: %s (%d)\n",
|
|
|
|
config->pwr_reg_names[i], ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->pwr_clk_cnt > 0) {
|
2013-12-12 02:44:02 +07:00
|
|
|
DBG("pixclock: %lu", hdmi->pixclock);
|
|
|
|
ret = clk_set_rate(hdmi->pwr_clks[0], hdmi->pixclock);
|
2013-12-02 00:12:54 +07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(dev->dev, "failed to set pixel clk: %s (%d)\n",
|
|
|
|
config->pwr_clk_names[0], ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < config->pwr_clk_cnt; i++) {
|
|
|
|
ret = clk_prepare_enable(hdmi->pwr_clks[i]);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev->dev, "failed to enable pwr clk: %s (%d)\n",
|
|
|
|
config->pwr_clk_names[i], ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void power_off(struct drm_bridge *bridge)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = bridge->dev;
|
|
|
|
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
|
|
|
|
struct hdmi *hdmi = hdmi_bridge->hdmi;
|
|
|
|
const struct hdmi_platform_config *config = hdmi->config;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
/* TODO do we need to wait for final vblank somewhere before
|
|
|
|
* cutting the clocks?
|
|
|
|
*/
|
|
|
|
mdelay(16 + 4);
|
|
|
|
|
|
|
|
for (i = 0; i < config->pwr_clk_cnt; i++)
|
|
|
|
clk_disable_unprepare(hdmi->pwr_clks[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < config->pwr_reg_cnt; i++) {
|
|
|
|
ret = regulator_disable(hdmi->pwr_regs[i]);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev->dev, "failed to disable pwr regulator: %s (%d)\n",
|
|
|
|
config->pwr_reg_names[i], ret);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 17:47:02 +07:00
|
|
|
|
|
|
|
pm_runtime_put_autosuspend(&hdmi->pdev->dev);
|
2013-12-02 00:12:54 +07:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:09:36 +07:00
|
|
|
#define AVI_IFRAME_LINE_NUMBER 1
|
|
|
|
|
|
|
|
static void msm_hdmi_config_avi_infoframe(struct hdmi *hdmi)
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc = hdmi->encoder->crtc;
|
|
|
|
const struct drm_display_mode *mode = &crtc->state->adjusted_mode;
|
|
|
|
union hdmi_infoframe frame;
|
|
|
|
u8 buffer[HDMI_INFOFRAME_SIZE(AVI)];
|
|
|
|
u32 val;
|
|
|
|
int len;
|
|
|
|
|
drm: handle HDMI 2.0 VICs in AVI info-frames
HDMI 1.4b support the CEA video modes as per range of CEA-861-D (VIC 1-64).
For any other mode, the VIC filed in AVI infoframes should be 0.
HDMI 2.0 sinks, support video modes range as per CEA-861-F spec, which is
extended to (VIC 1-107).
This patch adds a bool input variable, which indicates if the connected
sink is a HDMI 2.0 sink or not. This will make sure that we don't pass a
HDMI 2.0 VIC to a HDMI 1.4 sink.
This patch touches all drm drivers, who are callers of this function
drm_hdmi_avi_infoframe_from_display_mode but to make sure there is
no change in current behavior, is_hdmi2 is kept as false.
In case of I915 driver, this patch:
- checks if the connected display is HDMI 2.0.
- HDMI infoframes carry one of this two type of information:
- VIC for 4K modes for HDMI 1.4 sinks
- S3D information for S3D modes
As CEA-861-F has already defined VICs for 4K videomodes, this
patch doesn't allow sending HDMI infoframes for HDMI 2.0 sinks,
until the mode is 3D.
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Jose Abreu <jose.abreu@synopsys.com>
Cc: Andrzej Hajda <a.hajda@samsung.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>
PS: This patch touches a few lines in few files, which were
already above 80 char, so checkpatch gives 80 char warning again.
- gpu/drm/omapdrm/omap_encoder.c
- gpu/drm/i915/intel_sdvo.c
V2: Rebase, Added r-b from Andrzej
V3: Addressed review comment from Ville:
- Do not send VICs in both AVI-IF and HDMI-IF
send only one of it.
V4: Rebase
V5: Added r-b from Neil.
Addressed review comments from Ville
- Do not block HDMI vendor IF, instead check for VIC while
handling AVI infoframes
V6: Rebase
V7: Rebase
Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1499960000-9232-2-git-send-email-shashank.sharma@intel.com
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
2017-07-13 22:33:07 +07:00
|
|
|
drm_hdmi_avi_infoframe_from_display_mode(&frame.avi, mode, false);
|
2017-06-16 12:09:36 +07:00
|
|
|
|
|
|
|
len = hdmi_infoframe_pack(&frame, buffer, sizeof(buffer));
|
|
|
|
if (len < 0) {
|
|
|
|
dev_err(&hdmi->pdev->dev,
|
|
|
|
"failed to configure avi infoframe\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the AVI_INFOx registers don't map exactly to how the AVI infoframes
|
|
|
|
* are packed according to the spec. The checksum from the header is
|
|
|
|
* written to the LSB byte of AVI_INFO0 and the version is written to
|
|
|
|
* the third byte from the LSB of AVI_INFO3
|
|
|
|
*/
|
|
|
|
hdmi_write(hdmi, REG_HDMI_AVI_INFO(0),
|
|
|
|
buffer[3] |
|
|
|
|
buffer[4] << 8 |
|
|
|
|
buffer[5] << 16 |
|
|
|
|
buffer[6] << 24);
|
|
|
|
|
|
|
|
hdmi_write(hdmi, REG_HDMI_AVI_INFO(1),
|
|
|
|
buffer[7] |
|
|
|
|
buffer[8] << 8 |
|
|
|
|
buffer[9] << 16 |
|
|
|
|
buffer[10] << 24);
|
|
|
|
|
|
|
|
hdmi_write(hdmi, REG_HDMI_AVI_INFO(2),
|
|
|
|
buffer[11] |
|
|
|
|
buffer[12] << 8 |
|
|
|
|
buffer[13] << 16 |
|
|
|
|
buffer[14] << 24);
|
|
|
|
|
|
|
|
hdmi_write(hdmi, REG_HDMI_AVI_INFO(3),
|
|
|
|
buffer[15] |
|
|
|
|
buffer[16] << 8 |
|
|
|
|
buffer[1] << 24);
|
|
|
|
|
|
|
|
hdmi_write(hdmi, REG_HDMI_INFOFRAME_CTRL0,
|
|
|
|
HDMI_INFOFRAME_CTRL0_AVI_SEND |
|
|
|
|
HDMI_INFOFRAME_CTRL0_AVI_CONT);
|
|
|
|
|
|
|
|
val = hdmi_read(hdmi, REG_HDMI_INFOFRAME_CTRL1);
|
|
|
|
val &= ~HDMI_INFOFRAME_CTRL1_AVI_INFO_LINE__MASK;
|
|
|
|
val |= HDMI_INFOFRAME_CTRL1_AVI_INFO_LINE(AVI_IFRAME_LINE_NUMBER);
|
|
|
|
hdmi_write(hdmi, REG_HDMI_INFOFRAME_CTRL1, val);
|
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
static void msm_hdmi_bridge_pre_enable(struct drm_bridge *bridge)
|
2013-08-31 00:02:15 +07:00
|
|
|
{
|
|
|
|
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
|
|
|
|
struct hdmi *hdmi = hdmi_bridge->hdmi;
|
|
|
|
struct hdmi_phy *phy = hdmi->phy;
|
|
|
|
|
|
|
|
DBG("power up");
|
2013-12-02 00:12:54 +07:00
|
|
|
|
2013-12-12 02:44:02 +07:00
|
|
|
if (!hdmi->power_on) {
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_phy_resource_enable(phy);
|
|
|
|
msm_hdmi_power_on(bridge);
|
2013-12-12 02:44:02 +07:00
|
|
|
hdmi->power_on = true;
|
2017-06-16 12:09:36 +07:00
|
|
|
if (hdmi->hdmi_mode) {
|
|
|
|
msm_hdmi_config_avi_infoframe(hdmi);
|
|
|
|
msm_hdmi_audio_update(hdmi);
|
|
|
|
}
|
2013-12-02 00:12:54 +07:00
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_phy_powerup(phy, hdmi->pixclock);
|
2015-06-20 03:04:47 +07:00
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_set_mode(hdmi, true);
|
2015-04-03 04:49:01 +07:00
|
|
|
|
|
|
|
if (hdmi->hdcp_ctrl)
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_hdcp_on(hdmi->hdcp_ctrl);
|
2013-08-31 00:02:15 +07:00
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
static void msm_hdmi_bridge_enable(struct drm_bridge *bridge)
|
2013-08-31 00:02:15 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
static void msm_hdmi_bridge_disable(struct drm_bridge *bridge)
|
2013-08-31 00:02:15 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
static void msm_hdmi_bridge_post_disable(struct drm_bridge *bridge)
|
2013-08-31 00:02:15 +07:00
|
|
|
{
|
|
|
|
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
|
|
|
|
struct hdmi *hdmi = hdmi_bridge->hdmi;
|
|
|
|
struct hdmi_phy *phy = hdmi->phy;
|
|
|
|
|
2015-04-03 04:49:01 +07:00
|
|
|
if (hdmi->hdcp_ctrl)
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_hdcp_off(hdmi->hdcp_ctrl);
|
2015-04-03 04:49:01 +07:00
|
|
|
|
2013-08-31 00:02:15 +07:00
|
|
|
DBG("power down");
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_set_mode(hdmi, false);
|
2015-06-20 03:04:47 +07:00
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_phy_powerdown(phy);
|
2013-12-02 00:12:54 +07:00
|
|
|
|
2013-12-12 02:44:02 +07:00
|
|
|
if (hdmi->power_on) {
|
2013-12-02 00:12:54 +07:00
|
|
|
power_off(bridge);
|
2013-12-12 02:44:02 +07:00
|
|
|
hdmi->power_on = false;
|
2017-06-16 12:09:36 +07:00
|
|
|
if (hdmi->hdmi_mode)
|
|
|
|
msm_hdmi_audio_update(hdmi);
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_phy_resource_disable(phy);
|
2013-12-02 00:12:54 +07:00
|
|
|
}
|
2013-08-31 00:02:15 +07:00
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
static void msm_hdmi_bridge_mode_set(struct drm_bridge *bridge,
|
2013-08-31 00:02:15 +07:00
|
|
|
struct drm_display_mode *mode,
|
|
|
|
struct drm_display_mode *adjusted_mode)
|
|
|
|
{
|
|
|
|
struct hdmi_bridge *hdmi_bridge = to_hdmi_bridge(bridge);
|
|
|
|
struct hdmi *hdmi = hdmi_bridge->hdmi;
|
|
|
|
int hstart, hend, vstart, vend;
|
|
|
|
uint32_t frame_ctrl;
|
|
|
|
|
|
|
|
mode = adjusted_mode;
|
|
|
|
|
2013-12-12 02:44:02 +07:00
|
|
|
hdmi->pixclock = mode->clock * 1000;
|
2013-08-31 00:02:15 +07:00
|
|
|
|
|
|
|
hstart = mode->htotal - mode->hsync_start;
|
|
|
|
hend = mode->htotal - mode->hsync_start + mode->hdisplay;
|
|
|
|
|
|
|
|
vstart = mode->vtotal - mode->vsync_start - 1;
|
|
|
|
vend = mode->vtotal - mode->vsync_start + mode->vdisplay - 1;
|
|
|
|
|
|
|
|
DBG("htotal=%d, vtotal=%d, hstart=%d, hend=%d, vstart=%d, vend=%d",
|
|
|
|
mode->htotal, mode->vtotal, hstart, hend, vstart, vend);
|
|
|
|
|
|
|
|
hdmi_write(hdmi, REG_HDMI_TOTAL,
|
|
|
|
HDMI_TOTAL_H_TOTAL(mode->htotal - 1) |
|
|
|
|
HDMI_TOTAL_V_TOTAL(mode->vtotal - 1));
|
|
|
|
|
|
|
|
hdmi_write(hdmi, REG_HDMI_ACTIVE_HSYNC,
|
|
|
|
HDMI_ACTIVE_HSYNC_START(hstart) |
|
|
|
|
HDMI_ACTIVE_HSYNC_END(hend));
|
|
|
|
hdmi_write(hdmi, REG_HDMI_ACTIVE_VSYNC,
|
|
|
|
HDMI_ACTIVE_VSYNC_START(vstart) |
|
|
|
|
HDMI_ACTIVE_VSYNC_END(vend));
|
|
|
|
|
|
|
|
if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
|
|
|
|
hdmi_write(hdmi, REG_HDMI_VSYNC_TOTAL_F2,
|
|
|
|
HDMI_VSYNC_TOTAL_F2_V_TOTAL(mode->vtotal));
|
|
|
|
hdmi_write(hdmi, REG_HDMI_VSYNC_ACTIVE_F2,
|
|
|
|
HDMI_VSYNC_ACTIVE_F2_START(vstart + 1) |
|
|
|
|
HDMI_VSYNC_ACTIVE_F2_END(vend + 1));
|
|
|
|
} else {
|
|
|
|
hdmi_write(hdmi, REG_HDMI_VSYNC_TOTAL_F2,
|
|
|
|
HDMI_VSYNC_TOTAL_F2_V_TOTAL(0));
|
|
|
|
hdmi_write(hdmi, REG_HDMI_VSYNC_ACTIVE_F2,
|
|
|
|
HDMI_VSYNC_ACTIVE_F2_START(0) |
|
|
|
|
HDMI_VSYNC_ACTIVE_F2_END(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_ctrl = 0;
|
|
|
|
if (mode->flags & DRM_MODE_FLAG_NHSYNC)
|
|
|
|
frame_ctrl |= HDMI_FRAME_CTRL_HSYNC_LOW;
|
|
|
|
if (mode->flags & DRM_MODE_FLAG_NVSYNC)
|
|
|
|
frame_ctrl |= HDMI_FRAME_CTRL_VSYNC_LOW;
|
|
|
|
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
|
|
|
|
frame_ctrl |= HDMI_FRAME_CTRL_INTERLACED_EN;
|
|
|
|
DBG("frame_ctrl=%08x", frame_ctrl);
|
|
|
|
hdmi_write(hdmi, REG_HDMI_FRAME_CTRL, frame_ctrl);
|
|
|
|
|
2017-06-16 12:09:36 +07:00
|
|
|
if (hdmi->hdmi_mode)
|
|
|
|
msm_hdmi_audio_update(hdmi);
|
2013-08-31 00:02:15 +07:00
|
|
|
}
|
|
|
|
|
2016-02-23 04:08:35 +07:00
|
|
|
static const struct drm_bridge_funcs msm_hdmi_bridge_funcs = {
|
|
|
|
.pre_enable = msm_hdmi_bridge_pre_enable,
|
|
|
|
.enable = msm_hdmi_bridge_enable,
|
|
|
|
.disable = msm_hdmi_bridge_disable,
|
|
|
|
.post_disable = msm_hdmi_bridge_post_disable,
|
|
|
|
.mode_set = msm_hdmi_bridge_mode_set,
|
2013-08-31 00:02:15 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* initialize bridge */
|
2016-02-23 04:08:35 +07:00
|
|
|
struct drm_bridge *msm_hdmi_bridge_init(struct hdmi *hdmi)
|
2013-08-31 00:02:15 +07:00
|
|
|
{
|
|
|
|
struct drm_bridge *bridge = NULL;
|
|
|
|
struct hdmi_bridge *hdmi_bridge;
|
|
|
|
int ret;
|
|
|
|
|
2015-01-31 23:45:09 +07:00
|
|
|
hdmi_bridge = devm_kzalloc(hdmi->dev->dev,
|
|
|
|
sizeof(*hdmi_bridge), GFP_KERNEL);
|
2013-08-31 00:02:15 +07:00
|
|
|
if (!hdmi_bridge) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-11-18 20:40:44 +07:00
|
|
|
hdmi_bridge->hdmi = hdmi;
|
2013-08-31 00:02:15 +07:00
|
|
|
|
|
|
|
bridge = &hdmi_bridge->base;
|
2016-02-23 04:08:35 +07:00
|
|
|
bridge->funcs = &msm_hdmi_bridge_funcs;
|
2013-08-31 00:02:15 +07:00
|
|
|
|
2016-11-28 22:59:08 +07:00
|
|
|
ret = drm_bridge_attach(hdmi->encoder, bridge, NULL);
|
2015-01-31 23:45:09 +07:00
|
|
|
if (ret)
|
|
|
|
goto fail;
|
2013-08-31 00:02:15 +07:00
|
|
|
|
|
|
|
return bridge;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (bridge)
|
2016-02-23 04:08:35 +07:00
|
|
|
msm_hdmi_bridge_destroy(bridge);
|
2013-08-31 00:02:15 +07:00
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|