mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
drm/rockchip: inno-hdmi: Convert to drm bridge
Convert it to drm bridge driver, it will be convenient for us to migrate the connector part to the display driver later. Signed-off-by: Andy Yan <andy.yan@rock-chips.com> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Link: https://patch.msgid.link/20251016083843.76675-2-andyshrk@163.com Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
This commit is contained in:
parent
c08c123d4c
commit
969325a259
|
|
@ -100,6 +100,13 @@ config DRM_I2C_NXP_TDA998X
|
||||||
help
|
help
|
||||||
Support for NXP Semiconductors TDA998X HDMI encoders.
|
Support for NXP Semiconductors TDA998X HDMI encoders.
|
||||||
|
|
||||||
|
config DRM_INNO_HDMI
|
||||||
|
tristate
|
||||||
|
select DRM_BRIDGE_CONNECTOR
|
||||||
|
select DRM_DISPLAY_HDMI_HELPER
|
||||||
|
select DRM_DISPLAY_HELPER
|
||||||
|
select DRM_KMS_HELPER
|
||||||
|
|
||||||
config DRM_ITE_IT6263
|
config DRM_ITE_IT6263
|
||||||
tristate "ITE IT6263 LVDS/HDMI bridge"
|
tristate "ITE IT6263 LVDS/HDMI bridge"
|
||||||
depends on OF
|
depends on OF
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ obj-$(CONFIG_DRM_FSL_LDB) += fsl-ldb.o
|
||||||
tda998x-y := tda998x_drv.o
|
tda998x-y := tda998x_drv.o
|
||||||
obj-$(CONFIG_DRM_I2C_NXP_TDA998X) += tda998x.o
|
obj-$(CONFIG_DRM_I2C_NXP_TDA998X) += tda998x.o
|
||||||
|
|
||||||
|
obj-$(CONFIG_DRM_INNO_HDMI) += inno-hdmi.o
|
||||||
obj-$(CONFIG_DRM_ITE_IT6263) += ite-it6263.o
|
obj-$(CONFIG_DRM_ITE_IT6263) += ite-it6263.o
|
||||||
obj-$(CONFIG_DRM_ITE_IT6505) += ite-it6505.o
|
obj-$(CONFIG_DRM_ITE_IT6505) += ite-it6505.o
|
||||||
obj-$(CONFIG_DRM_LONTIUM_LT8912B) += lontium-lt8912b.o
|
obj-$(CONFIG_DRM_LONTIUM_LT8912B) += lontium-lt8912b.o
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,15 @@
|
||||||
* Copyright (C) Rockchip Electronics Co., Ltd.
|
* Copyright (C) Rockchip Electronics Co., Ltd.
|
||||||
* Zheng Yang <zhengyang@rock-chips.com>
|
* Zheng Yang <zhengyang@rock-chips.com>
|
||||||
* Yakir Yang <ykk@rock-chips.com>
|
* Yakir Yang <ykk@rock-chips.com>
|
||||||
|
* Andy Yan <andyshrk@163.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/irq.h>
|
#include <linux/irq.h>
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
|
#include <linux/i2c.h>
|
||||||
#include <linux/hdmi.h>
|
#include <linux/hdmi.h>
|
||||||
#include <linux/hw_bitfield.h>
|
|
||||||
#include <linux/mfd/syscon.h>
|
#include <linux/mfd/syscon.h>
|
||||||
#include <linux/mod_devicetable.h>
|
#include <linux/mod_devicetable.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
|
@ -18,6 +19,7 @@
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
|
|
||||||
|
#include <drm/bridge/inno_hdmi.h>
|
||||||
#include <drm/drm_atomic.h>
|
#include <drm/drm_atomic.h>
|
||||||
#include <drm/drm_atomic_helper.h>
|
#include <drm/drm_atomic_helper.h>
|
||||||
#include <drm/drm_edid.h>
|
#include <drm/drm_edid.h>
|
||||||
|
|
@ -29,8 +31,6 @@
|
||||||
#include <drm/display/drm_hdmi_helper.h>
|
#include <drm/display/drm_hdmi_helper.h>
|
||||||
#include <drm/display/drm_hdmi_state_helper.h>
|
#include <drm/display/drm_hdmi_state_helper.h>
|
||||||
|
|
||||||
#include "rockchip_drm_drv.h"
|
|
||||||
|
|
||||||
#define INNO_HDMI_MIN_TMDS_CLOCK 25000000U
|
#define INNO_HDMI_MIN_TMDS_CLOCK 25000000U
|
||||||
|
|
||||||
#define DDC_SEGMENT_ADDR 0x30
|
#define DDC_SEGMENT_ADDR 0x30
|
||||||
|
|
@ -384,27 +384,6 @@ enum {
|
||||||
#define HDMI_CEC_BUSFREETIME_H 0xdd
|
#define HDMI_CEC_BUSFREETIME_H 0xdd
|
||||||
#define HDMI_CEC_LOGICADDR 0xde
|
#define HDMI_CEC_LOGICADDR 0xde
|
||||||
|
|
||||||
#define RK3036_GRF_SOC_CON2 0x148
|
|
||||||
#define RK3036_HDMI_PHSYNC BIT(4)
|
|
||||||
#define RK3036_HDMI_PVSYNC BIT(5)
|
|
||||||
|
|
||||||
enum inno_hdmi_dev_type {
|
|
||||||
RK3036_HDMI,
|
|
||||||
RK3128_HDMI,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct inno_hdmi_phy_config {
|
|
||||||
unsigned long pixelclock;
|
|
||||||
u8 pre_emphasis;
|
|
||||||
u8 voltage_level_control;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct inno_hdmi_variant {
|
|
||||||
enum inno_hdmi_dev_type dev_type;
|
|
||||||
struct inno_hdmi_phy_config *phy_configs;
|
|
||||||
struct inno_hdmi_phy_config *default_phy_config;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct inno_hdmi_i2c {
|
struct inno_hdmi_i2c {
|
||||||
struct i2c_adapter adap;
|
struct i2c_adapter adap;
|
||||||
|
|
||||||
|
|
@ -417,41 +396,17 @@ struct inno_hdmi_i2c {
|
||||||
|
|
||||||
struct inno_hdmi {
|
struct inno_hdmi {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
struct drm_bridge bridge;
|
||||||
struct clk *pclk;
|
struct clk *pclk;
|
||||||
struct clk *refclk;
|
struct clk *refclk;
|
||||||
void __iomem *regs;
|
void __iomem *regs;
|
||||||
struct regmap *grf;
|
struct regmap *grf;
|
||||||
|
|
||||||
struct drm_connector connector;
|
|
||||||
struct rockchip_encoder encoder;
|
|
||||||
|
|
||||||
struct inno_hdmi_i2c *i2c;
|
struct inno_hdmi_i2c *i2c;
|
||||||
struct i2c_adapter *ddc;
|
struct i2c_adapter *ddc;
|
||||||
|
const struct inno_hdmi_plat_data *plat_data;
|
||||||
const struct inno_hdmi_variant *variant;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct inno_hdmi_connector_state {
|
|
||||||
struct drm_connector_state base;
|
|
||||||
unsigned int colorimetry;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct inno_hdmi *encoder_to_inno_hdmi(struct drm_encoder *encoder)
|
|
||||||
{
|
|
||||||
struct rockchip_encoder *rkencoder = to_rockchip_encoder(encoder);
|
|
||||||
|
|
||||||
return container_of(rkencoder, struct inno_hdmi, encoder);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct inno_hdmi *connector_to_inno_hdmi(struct drm_connector *connector)
|
|
||||||
{
|
|
||||||
return container_of(connector, struct inno_hdmi, connector);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define to_inno_hdmi_conn_state(conn_state) \
|
|
||||||
container_of_const(conn_state, struct inno_hdmi_connector_state, base)
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CSC_RGB_0_255_TO_ITU601_16_235_8BIT,
|
CSC_RGB_0_255_TO_ITU601_16_235_8BIT,
|
||||||
CSC_RGB_0_255_TO_ITU709_16_235_8BIT,
|
CSC_RGB_0_255_TO_ITU709_16_235_8BIT,
|
||||||
|
|
@ -494,23 +449,15 @@ static const char coeff_csc[][24] = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct inno_hdmi_phy_config rk3036_hdmi_phy_configs[] = {
|
static struct inno_hdmi *bridge_to_inno_hdmi(struct drm_bridge *bridge)
|
||||||
{ 74250000, 0x3f, 0xbb },
|
{
|
||||||
{ 165000000, 0x6f, 0xbb },
|
return container_of(bridge, struct inno_hdmi, bridge);
|
||||||
{ ~0UL, 0x00, 0x00 }
|
}
|
||||||
};
|
|
||||||
|
|
||||||
static struct inno_hdmi_phy_config rk3128_hdmi_phy_configs[] = {
|
|
||||||
{ 74250000, 0x3f, 0xaa },
|
|
||||||
{ 165000000, 0x5f, 0xaa },
|
|
||||||
{ ~0UL, 0x00, 0x00 }
|
|
||||||
};
|
|
||||||
|
|
||||||
static int inno_hdmi_find_phy_config(struct inno_hdmi *hdmi,
|
static int inno_hdmi_find_phy_config(struct inno_hdmi *hdmi,
|
||||||
unsigned long pixelclk)
|
unsigned long pixelclk)
|
||||||
{
|
{
|
||||||
const struct inno_hdmi_phy_config *phy_configs =
|
const struct inno_hdmi_phy_config *phy_configs = hdmi->plat_data->phy_configs;
|
||||||
hdmi->variant->phy_configs;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; phy_configs[i].pixelclock != ~0UL; i++) {
|
for (i = 0; phy_configs[i].pixelclock != ~0UL; i++) {
|
||||||
|
|
@ -582,12 +529,12 @@ static void inno_hdmi_power_up(struct inno_hdmi *hdmi,
|
||||||
int ret = inno_hdmi_find_phy_config(hdmi, mpixelclock);
|
int ret = inno_hdmi_find_phy_config(hdmi, mpixelclock);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
phy_config = hdmi->variant->default_phy_config;
|
phy_config = hdmi->plat_data->default_phy_config;
|
||||||
DRM_DEV_ERROR(hdmi->dev,
|
DRM_DEV_ERROR(hdmi->dev,
|
||||||
"Using default phy configuration for TMDS rate %lu",
|
"Using default phy configuration for TMDS rate %lu",
|
||||||
mpixelclock);
|
mpixelclock);
|
||||||
} else {
|
} else {
|
||||||
phy_config = &hdmi->variant->phy_configs[ret];
|
phy_config = &hdmi->plat_data->phy_configs[ret];
|
||||||
}
|
}
|
||||||
|
|
||||||
inno_hdmi_sys_power(hdmi, false);
|
inno_hdmi_sys_power(hdmi, false);
|
||||||
|
|
@ -637,14 +584,13 @@ static void inno_hdmi_init_hw(struct inno_hdmi *hdmi)
|
||||||
hdmi_modb(hdmi, HDMI_STATUS, m_MASK_INT_HOTPLUG, v_MASK_INT_HOTPLUG(1));
|
hdmi_modb(hdmi, HDMI_STATUS, m_MASK_INT_HOTPLUG, v_MASK_INT_HOTPLUG(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inno_hdmi_disable_frame(struct drm_connector *connector,
|
static int inno_hdmi_bridge_clear_infoframe(struct drm_bridge *bridge,
|
||||||
enum hdmi_infoframe_type type)
|
enum hdmi_infoframe_type type)
|
||||||
{
|
{
|
||||||
struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
|
struct inno_hdmi *hdmi = bridge_to_inno_hdmi(bridge);
|
||||||
|
|
||||||
if (type != HDMI_INFOFRAME_TYPE_AVI) {
|
if (type != HDMI_INFOFRAME_TYPE_AVI) {
|
||||||
drm_err(connector->dev,
|
drm_err(bridge->dev, "Unsupported infoframe type: %u\n", type);
|
||||||
"Unsupported infoframe type: %u\n", type);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -653,20 +599,19 @@ static int inno_hdmi_disable_frame(struct drm_connector *connector,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inno_hdmi_upload_frame(struct drm_connector *connector,
|
static int inno_hdmi_bridge_write_infoframe(struct drm_bridge *bridge,
|
||||||
enum hdmi_infoframe_type type,
|
enum hdmi_infoframe_type type,
|
||||||
const u8 *buffer, size_t len)
|
const u8 *buffer, size_t len)
|
||||||
{
|
{
|
||||||
struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
|
struct inno_hdmi *hdmi = bridge_to_inno_hdmi(bridge);
|
||||||
ssize_t i;
|
ssize_t i;
|
||||||
|
|
||||||
if (type != HDMI_INFOFRAME_TYPE_AVI) {
|
if (type != HDMI_INFOFRAME_TYPE_AVI) {
|
||||||
drm_err(connector->dev,
|
drm_err(bridge->dev, "Unsupported infoframe type: %u\n", type);
|
||||||
"Unsupported infoframe type: %u\n", type);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inno_hdmi_disable_frame(connector, type);
|
inno_hdmi_bridge_clear_infoframe(bridge, type);
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_ADDR + i, buffer[i]);
|
hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_ADDR + i, buffer[i]);
|
||||||
|
|
@ -674,23 +619,26 @@ static int inno_hdmi_upload_frame(struct drm_connector *connector,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct drm_connector_hdmi_funcs inno_hdmi_hdmi_connector_funcs = {
|
static int inno_hdmi_config_video_csc(struct inno_hdmi *hdmi,
|
||||||
.clear_infoframe = inno_hdmi_disable_frame,
|
struct drm_connector *connector,
|
||||||
.write_infoframe = inno_hdmi_upload_frame,
|
struct drm_display_mode *mode)
|
||||||
};
|
|
||||||
|
|
||||||
static int inno_hdmi_config_video_csc(struct inno_hdmi *hdmi)
|
|
||||||
{
|
{
|
||||||
struct drm_connector *connector = &hdmi->connector;
|
|
||||||
struct drm_connector_state *conn_state = connector->state;
|
struct drm_connector_state *conn_state = connector->state;
|
||||||
struct inno_hdmi_connector_state *inno_conn_state =
|
|
||||||
to_inno_hdmi_conn_state(conn_state);
|
|
||||||
int c0_c2_change = 0;
|
int c0_c2_change = 0;
|
||||||
int csc_enable = 0;
|
int csc_enable = 0;
|
||||||
int csc_mode = 0;
|
int csc_mode = 0;
|
||||||
int auto_csc = 0;
|
int auto_csc = 0;
|
||||||
int value;
|
int value;
|
||||||
int i;
|
int i;
|
||||||
|
int colorimetry;
|
||||||
|
u8 vic = drm_match_cea_mode(mode);
|
||||||
|
|
||||||
|
if (vic == 6 || vic == 7 || vic == 21 || vic == 22 ||
|
||||||
|
vic == 2 || vic == 3 || vic == 17 || vic == 18)
|
||||||
|
colorimetry = HDMI_COLORIMETRY_ITU_601;
|
||||||
|
else
|
||||||
|
colorimetry = HDMI_COLORIMETRY_ITU_709;
|
||||||
|
|
||||||
|
|
||||||
/* Input video mode is SDR RGB24bit, data enable signal from external */
|
/* Input video mode is SDR RGB24bit, data enable signal from external */
|
||||||
hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL1, v_DE_EXTERNAL |
|
hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL1, v_DE_EXTERNAL |
|
||||||
|
|
@ -720,7 +668,7 @@ static int inno_hdmi_config_video_csc(struct inno_hdmi *hdmi)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (inno_conn_state->colorimetry == HDMI_COLORIMETRY_ITU_601) {
|
if (colorimetry == HDMI_COLORIMETRY_ITU_601) {
|
||||||
if (conn_state->hdmi.output_format == HDMI_COLORSPACE_YUV444) {
|
if (conn_state->hdmi.output_format == HDMI_COLORSPACE_YUV444) {
|
||||||
csc_mode = CSC_RGB_0_255_TO_ITU601_16_235_8BIT;
|
csc_mode = CSC_RGB_0_255_TO_ITU601_16_235_8BIT;
|
||||||
auto_csc = AUTO_CSC_DISABLE;
|
auto_csc = AUTO_CSC_DISABLE;
|
||||||
|
|
@ -738,8 +686,7 @@ static int inno_hdmi_config_video_csc(struct inno_hdmi *hdmi)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 24; i++)
|
for (i = 0; i < 24; i++)
|
||||||
hdmi_writeb(hdmi, HDMI_VIDEO_CSC_COEF + i,
|
hdmi_writeb(hdmi, HDMI_VIDEO_CSC_COEF + i, coeff_csc[csc_mode][i]);
|
||||||
coeff_csc[csc_mode][i]);
|
|
||||||
|
|
||||||
value = v_SOF_DISABLE | csc_enable | v_COLOR_DEPTH_NOT_INDICATED(1);
|
value = v_SOF_DISABLE | csc_enable | v_COLOR_DEPTH_NOT_INDICATED(1);
|
||||||
hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL3, value);
|
hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL3, value);
|
||||||
|
|
@ -753,15 +700,11 @@ static int inno_hdmi_config_video_csc(struct inno_hdmi *hdmi)
|
||||||
static int inno_hdmi_config_video_timing(struct inno_hdmi *hdmi,
|
static int inno_hdmi_config_video_timing(struct inno_hdmi *hdmi,
|
||||||
struct drm_display_mode *mode)
|
struct drm_display_mode *mode)
|
||||||
{
|
{
|
||||||
int value, psync;
|
const struct inno_hdmi_plat_ops *plat_ops = hdmi->plat_data->ops;
|
||||||
|
u32 value;
|
||||||
|
|
||||||
if (hdmi->variant->dev_type == RK3036_HDMI) {
|
if (plat_ops && plat_ops->enable)
|
||||||
psync = mode->flags & DRM_MODE_FLAG_PHSYNC ? 1 : 0;
|
plat_ops->enable(hdmi->dev, mode);
|
||||||
value = FIELD_PREP_WM16(RK3036_HDMI_PHSYNC, psync);
|
|
||||||
psync = mode->flags & DRM_MODE_FLAG_PVSYNC ? 1 : 0;
|
|
||||||
value |= FIELD_PREP_WM16(RK3036_HDMI_PVSYNC, psync);
|
|
||||||
regmap_write(hdmi->grf, RK3036_GRF_SOC_CON2, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set detail external video timing polarity and interlace mode */
|
/* Set detail external video timing polarity and interlace mode */
|
||||||
value = v_EXTERANL_VIDEO(1);
|
value = v_EXTERANL_VIDEO(1);
|
||||||
|
|
@ -810,14 +753,16 @@ static int inno_hdmi_config_video_timing(struct inno_hdmi *hdmi,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inno_hdmi_setup(struct inno_hdmi *hdmi,
|
static int inno_hdmi_setup(struct inno_hdmi *hdmi, struct drm_atomic_state *state)
|
||||||
struct drm_atomic_state *state)
|
|
||||||
{
|
{
|
||||||
struct drm_connector *connector = &hdmi->connector;
|
struct drm_bridge *bridge = &hdmi->bridge;
|
||||||
struct drm_display_info *display = &connector->display_info;
|
struct drm_connector *connector;
|
||||||
|
struct drm_display_info *info;
|
||||||
struct drm_connector_state *new_conn_state;
|
struct drm_connector_state *new_conn_state;
|
||||||
struct drm_crtc_state *new_crtc_state;
|
struct drm_crtc_state *new_crtc_state;
|
||||||
|
|
||||||
|
connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder);
|
||||||
|
|
||||||
new_conn_state = drm_atomic_get_new_connector_state(state, connector);
|
new_conn_state = drm_atomic_get_new_connector_state(state, connector);
|
||||||
if (WARN_ON(!new_conn_state))
|
if (WARN_ON(!new_conn_state))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
@ -826,17 +771,18 @@ static int inno_hdmi_setup(struct inno_hdmi *hdmi,
|
||||||
if (WARN_ON(!new_crtc_state))
|
if (WARN_ON(!new_crtc_state))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
info = &connector->display_info;
|
||||||
|
|
||||||
/* Mute video and audio output */
|
/* Mute video and audio output */
|
||||||
hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK,
|
hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK,
|
||||||
v_AUDIO_MUTE(1) | v_VIDEO_MUTE(1));
|
v_AUDIO_MUTE(1) | v_VIDEO_MUTE(1));
|
||||||
|
|
||||||
/* Set HDMI Mode */
|
/* Set HDMI Mode */
|
||||||
hdmi_writeb(hdmi, HDMI_HDCP_CTRL,
|
hdmi_writeb(hdmi, HDMI_HDCP_CTRL, v_HDMI_DVI(info->is_hdmi));
|
||||||
v_HDMI_DVI(display->is_hdmi));
|
|
||||||
|
|
||||||
inno_hdmi_config_video_timing(hdmi, &new_crtc_state->adjusted_mode);
|
inno_hdmi_config_video_timing(hdmi, &new_crtc_state->adjusted_mode);
|
||||||
|
|
||||||
inno_hdmi_config_video_csc(hdmi);
|
inno_hdmi_config_video_csc(hdmi, connector, &new_crtc_state->adjusted_mode);
|
||||||
|
|
||||||
drm_atomic_helper_connector_hdmi_update_infoframes(connector, state);
|
drm_atomic_helper_connector_hdmi_update_infoframes(connector, state);
|
||||||
|
|
||||||
|
|
@ -857,9 +803,11 @@ static int inno_hdmi_setup(struct inno_hdmi *hdmi,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum drm_mode_status inno_hdmi_display_mode_valid(struct inno_hdmi *hdmi,
|
static enum drm_mode_status inno_hdmi_bridge_mode_valid(struct drm_bridge *bridge,
|
||||||
const struct drm_display_mode *mode)
|
const struct drm_display_info *info,
|
||||||
|
const struct drm_display_mode *mode)
|
||||||
{
|
{
|
||||||
|
struct inno_hdmi *hdmi = bridge_to_inno_hdmi(bridge);
|
||||||
unsigned long mpixelclk, max_tolerance;
|
unsigned long mpixelclk, max_tolerance;
|
||||||
long rounded_refclk;
|
long rounded_refclk;
|
||||||
|
|
||||||
|
|
@ -889,189 +837,57 @@ static enum drm_mode_status inno_hdmi_display_mode_valid(struct inno_hdmi *hdmi,
|
||||||
return MODE_OK;
|
return MODE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inno_hdmi_encoder_enable(struct drm_encoder *encoder,
|
|
||||||
struct drm_atomic_state *state)
|
|
||||||
{
|
|
||||||
struct inno_hdmi *hdmi = encoder_to_inno_hdmi(encoder);
|
|
||||||
|
|
||||||
inno_hdmi_setup(hdmi, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void inno_hdmi_encoder_disable(struct drm_encoder *encoder,
|
|
||||||
struct drm_atomic_state *state)
|
|
||||||
{
|
|
||||||
struct inno_hdmi *hdmi = encoder_to_inno_hdmi(encoder);
|
|
||||||
|
|
||||||
inno_hdmi_standby(hdmi);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
inno_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
|
|
||||||
struct drm_crtc_state *crtc_state,
|
|
||||||
struct drm_connector_state *conn_state)
|
|
||||||
{
|
|
||||||
struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
|
|
||||||
struct drm_display_mode *mode = &crtc_state->adjusted_mode;
|
|
||||||
u8 vic = drm_match_cea_mode(mode);
|
|
||||||
struct inno_hdmi_connector_state *inno_conn_state =
|
|
||||||
to_inno_hdmi_conn_state(conn_state);
|
|
||||||
|
|
||||||
s->output_mode = ROCKCHIP_OUT_MODE_P888;
|
|
||||||
s->output_type = DRM_MODE_CONNECTOR_HDMIA;
|
|
||||||
|
|
||||||
if (vic == 6 || vic == 7 ||
|
|
||||||
vic == 21 || vic == 22 ||
|
|
||||||
vic == 2 || vic == 3 ||
|
|
||||||
vic == 17 || vic == 18)
|
|
||||||
inno_conn_state->colorimetry = HDMI_COLORIMETRY_ITU_601;
|
|
||||||
else
|
|
||||||
inno_conn_state->colorimetry = HDMI_COLORIMETRY_ITU_709;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct drm_encoder_helper_funcs inno_hdmi_encoder_helper_funcs = {
|
|
||||||
.atomic_check = inno_hdmi_encoder_atomic_check,
|
|
||||||
.atomic_enable = inno_hdmi_encoder_enable,
|
|
||||||
.atomic_disable = inno_hdmi_encoder_disable,
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum drm_connector_status
|
static enum drm_connector_status
|
||||||
inno_hdmi_connector_detect(struct drm_connector *connector, bool force)
|
inno_hdmi_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector)
|
||||||
{
|
{
|
||||||
struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
|
struct inno_hdmi *hdmi = bridge_to_inno_hdmi(bridge);
|
||||||
|
|
||||||
return (hdmi_readb(hdmi, HDMI_STATUS) & m_HOTPLUG) ?
|
return (hdmi_readb(hdmi, HDMI_STATUS) & m_HOTPLUG) ?
|
||||||
connector_status_connected : connector_status_disconnected;
|
connector_status_connected : connector_status_disconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inno_hdmi_connector_get_modes(struct drm_connector *connector)
|
static const struct drm_edid *
|
||||||
|
inno_hdmi_bridge_edid_read(struct drm_bridge *bridge, struct drm_connector *connector)
|
||||||
{
|
{
|
||||||
struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
|
struct inno_hdmi *hdmi = bridge_to_inno_hdmi(bridge);
|
||||||
const struct drm_edid *drm_edid;
|
const struct drm_edid *drm_edid;
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (!hdmi->ddc)
|
drm_edid = drm_edid_read_ddc(connector, bridge->ddc);
|
||||||
return 0;
|
if (!drm_edid)
|
||||||
|
dev_dbg(hdmi->dev, "failed to get edid\n");
|
||||||
|
|
||||||
drm_edid = drm_edid_read_ddc(connector, hdmi->ddc);
|
return drm_edid;
|
||||||
drm_edid_connector_update(connector, drm_edid);
|
|
||||||
ret = drm_edid_connector_add_modes(connector);
|
|
||||||
drm_edid_free(drm_edid);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum drm_mode_status
|
static void inno_hdmi_bridge_atomic_enable(struct drm_bridge *bridge,
|
||||||
inno_hdmi_connector_mode_valid(struct drm_connector *connector,
|
struct drm_atomic_state *state)
|
||||||
const struct drm_display_mode *mode)
|
|
||||||
{
|
{
|
||||||
struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
|
struct inno_hdmi *hdmi = bridge_to_inno_hdmi(bridge);
|
||||||
|
|
||||||
return inno_hdmi_display_mode_valid(hdmi, mode);
|
inno_hdmi_setup(hdmi, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void inno_hdmi_bridge_atomic_disable(struct drm_bridge *bridge,
|
||||||
inno_hdmi_connector_destroy_state(struct drm_connector *connector,
|
struct drm_atomic_state *state)
|
||||||
struct drm_connector_state *state)
|
|
||||||
{
|
{
|
||||||
struct inno_hdmi_connector_state *inno_conn_state =
|
struct inno_hdmi *hdmi = bridge_to_inno_hdmi(bridge);
|
||||||
to_inno_hdmi_conn_state(state);
|
|
||||||
|
|
||||||
__drm_atomic_helper_connector_destroy_state(&inno_conn_state->base);
|
inno_hdmi_standby(hdmi);
|
||||||
kfree(inno_conn_state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inno_hdmi_connector_reset(struct drm_connector *connector)
|
static const struct drm_bridge_funcs inno_hdmi_bridge_funcs = {
|
||||||
{
|
.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
|
||||||
struct inno_hdmi_connector_state *inno_conn_state;
|
.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
|
||||||
|
.atomic_reset = drm_atomic_helper_bridge_reset,
|
||||||
if (connector->state) {
|
.atomic_enable = inno_hdmi_bridge_atomic_enable,
|
||||||
inno_hdmi_connector_destroy_state(connector, connector->state);
|
.atomic_disable = inno_hdmi_bridge_atomic_disable,
|
||||||
connector->state = NULL;
|
.detect = inno_hdmi_bridge_detect,
|
||||||
}
|
.edid_read = inno_hdmi_bridge_edid_read,
|
||||||
|
.hdmi_clear_infoframe = inno_hdmi_bridge_clear_infoframe,
|
||||||
inno_conn_state = kzalloc(sizeof(*inno_conn_state), GFP_KERNEL);
|
.hdmi_write_infoframe = inno_hdmi_bridge_write_infoframe,
|
||||||
if (!inno_conn_state)
|
.mode_valid = inno_hdmi_bridge_mode_valid,
|
||||||
return;
|
|
||||||
|
|
||||||
__drm_atomic_helper_connector_reset(connector, &inno_conn_state->base);
|
|
||||||
__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
|
|
||||||
|
|
||||||
inno_conn_state->colorimetry = HDMI_COLORIMETRY_ITU_709;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct drm_connector_state *
|
|
||||||
inno_hdmi_connector_duplicate_state(struct drm_connector *connector)
|
|
||||||
{
|
|
||||||
struct inno_hdmi_connector_state *inno_conn_state;
|
|
||||||
|
|
||||||
if (WARN_ON(!connector->state))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
inno_conn_state = kmemdup(to_inno_hdmi_conn_state(connector->state),
|
|
||||||
sizeof(*inno_conn_state), GFP_KERNEL);
|
|
||||||
|
|
||||||
if (!inno_conn_state)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
__drm_atomic_helper_connector_duplicate_state(connector,
|
|
||||||
&inno_conn_state->base);
|
|
||||||
|
|
||||||
return &inno_conn_state->base;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct drm_connector_funcs inno_hdmi_connector_funcs = {
|
|
||||||
.fill_modes = drm_helper_probe_single_connector_modes,
|
|
||||||
.detect = inno_hdmi_connector_detect,
|
|
||||||
.reset = inno_hdmi_connector_reset,
|
|
||||||
.atomic_duplicate_state = inno_hdmi_connector_duplicate_state,
|
|
||||||
.atomic_destroy_state = inno_hdmi_connector_destroy_state,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct drm_connector_helper_funcs inno_hdmi_connector_helper_funcs = {
|
|
||||||
.atomic_check = drm_atomic_helper_connector_hdmi_check,
|
|
||||||
.get_modes = inno_hdmi_connector_get_modes,
|
|
||||||
.mode_valid = inno_hdmi_connector_mode_valid,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int inno_hdmi_register(struct drm_device *drm, struct inno_hdmi *hdmi)
|
|
||||||
{
|
|
||||||
struct drm_encoder *encoder = &hdmi->encoder.encoder;
|
|
||||||
struct device *dev = hdmi->dev;
|
|
||||||
|
|
||||||
encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If we failed to find the CRTC(s) which this encoder is
|
|
||||||
* supposed to be connected to, it's because the CRTC has
|
|
||||||
* not been registered yet. Defer probing, and hope that
|
|
||||||
* the required CRTC is added later.
|
|
||||||
*/
|
|
||||||
if (encoder->possible_crtcs == 0)
|
|
||||||
return -EPROBE_DEFER;
|
|
||||||
|
|
||||||
drm_encoder_helper_add(encoder, &inno_hdmi_encoder_helper_funcs);
|
|
||||||
drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_TMDS);
|
|
||||||
|
|
||||||
hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD;
|
|
||||||
|
|
||||||
drm_connector_helper_add(&hdmi->connector,
|
|
||||||
&inno_hdmi_connector_helper_funcs);
|
|
||||||
drmm_connector_hdmi_init(drm, &hdmi->connector,
|
|
||||||
"Rockchip", "Inno HDMI",
|
|
||||||
&inno_hdmi_connector_funcs,
|
|
||||||
&inno_hdmi_hdmi_connector_funcs,
|
|
||||||
DRM_MODE_CONNECTOR_HDMIA,
|
|
||||||
hdmi->ddc,
|
|
||||||
BIT(HDMI_COLORSPACE_RGB),
|
|
||||||
8);
|
|
||||||
|
|
||||||
drm_connector_attach_encoder(&hdmi->connector, encoder);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static irqreturn_t inno_hdmi_i2c_irq(struct inno_hdmi *hdmi)
|
static irqreturn_t inno_hdmi_i2c_irq(struct inno_hdmi *hdmi)
|
||||||
{
|
{
|
||||||
struct inno_hdmi_i2c *i2c = hdmi->i2c;
|
struct inno_hdmi_i2c *i2c = hdmi->i2c;
|
||||||
|
|
@ -1111,7 +927,7 @@ static irqreturn_t inno_hdmi_irq(int irq, void *dev_id)
|
||||||
{
|
{
|
||||||
struct inno_hdmi *hdmi = dev_id;
|
struct inno_hdmi *hdmi = dev_id;
|
||||||
|
|
||||||
drm_helper_hpd_irq_event(hdmi->connector.dev);
|
drm_helper_hpd_irq_event(hdmi->bridge.dev);
|
||||||
|
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
@ -1243,128 +1059,80 @@ static struct i2c_adapter *inno_hdmi_i2c_adapter(struct inno_hdmi *hdmi)
|
||||||
return adap;
|
return adap;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inno_hdmi_bind(struct device *dev, struct device *master,
|
struct inno_hdmi *inno_hdmi_bind(struct device *dev,
|
||||||
void *data)
|
struct drm_encoder *encoder,
|
||||||
|
const struct inno_hdmi_plat_data *plat_data)
|
||||||
{
|
{
|
||||||
struct platform_device *pdev = to_platform_device(dev);
|
struct platform_device *pdev = to_platform_device(dev);
|
||||||
struct drm_device *drm = data;
|
|
||||||
struct inno_hdmi *hdmi;
|
struct inno_hdmi *hdmi;
|
||||||
const struct inno_hdmi_variant *variant;
|
|
||||||
int irq;
|
int irq;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
|
if (!plat_data->phy_configs || !plat_data->default_phy_config) {
|
||||||
if (!hdmi)
|
dev_err(dev, "Missing platform PHY ops\n");
|
||||||
return -ENOMEM;
|
return ERR_PTR(-ENODEV);
|
||||||
|
}
|
||||||
|
|
||||||
|
hdmi = devm_drm_bridge_alloc(dev, struct inno_hdmi, bridge, &inno_hdmi_bridge_funcs);
|
||||||
|
if (IS_ERR(hdmi))
|
||||||
|
return ERR_CAST(hdmi);
|
||||||
|
|
||||||
hdmi->dev = dev;
|
hdmi->dev = dev;
|
||||||
|
hdmi->plat_data = plat_data;
|
||||||
variant = of_device_get_match_data(hdmi->dev);
|
|
||||||
if (!variant)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
hdmi->variant = variant;
|
|
||||||
|
|
||||||
hdmi->regs = devm_platform_ioremap_resource(pdev, 0);
|
hdmi->regs = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (IS_ERR(hdmi->regs))
|
if (IS_ERR(hdmi->regs))
|
||||||
return PTR_ERR(hdmi->regs);
|
return ERR_CAST(hdmi->regs);
|
||||||
|
|
||||||
hdmi->pclk = devm_clk_get_enabled(hdmi->dev, "pclk");
|
hdmi->pclk = devm_clk_get_enabled(hdmi->dev, "pclk");
|
||||||
if (IS_ERR(hdmi->pclk))
|
if (IS_ERR(hdmi->pclk)) {
|
||||||
return dev_err_probe(dev, PTR_ERR(hdmi->pclk), "Unable to get HDMI pclk\n");
|
dev_err_probe(dev, PTR_ERR(hdmi->pclk), "Unable to get HDMI pclk\n");
|
||||||
|
return ERR_CAST(hdmi->pclk);
|
||||||
hdmi->refclk = devm_clk_get_optional_enabled(hdmi->dev, "ref");
|
|
||||||
if (IS_ERR(hdmi->refclk))
|
|
||||||
return dev_err_probe(dev, PTR_ERR(hdmi->refclk), "Unable to get HDMI refclk\n");
|
|
||||||
|
|
||||||
if (hdmi->variant->dev_type == RK3036_HDMI) {
|
|
||||||
hdmi->grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf");
|
|
||||||
if (IS_ERR(hdmi->grf))
|
|
||||||
return dev_err_probe(dev,
|
|
||||||
PTR_ERR(hdmi->grf), "Unable to get rockchip,grf\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
irq = platform_get_irq(pdev, 0);
|
hdmi->refclk = devm_clk_get_optional_enabled(hdmi->dev, "ref");
|
||||||
if (irq < 0)
|
if (IS_ERR(hdmi->refclk)) {
|
||||||
return irq;
|
dev_err_probe(dev, PTR_ERR(hdmi->refclk), "Unable to get HDMI refclk\n");
|
||||||
|
return ERR_CAST(hdmi->refclk);
|
||||||
|
}
|
||||||
|
|
||||||
inno_hdmi_init_hw(hdmi);
|
inno_hdmi_init_hw(hdmi);
|
||||||
|
|
||||||
hdmi->ddc = inno_hdmi_i2c_adapter(hdmi);
|
irq = platform_get_irq(pdev, 0);
|
||||||
if (IS_ERR(hdmi->ddc))
|
if (irq < 0)
|
||||||
return PTR_ERR(hdmi->ddc);
|
return ERR_PTR(irq);
|
||||||
|
|
||||||
ret = inno_hdmi_register(drm, hdmi);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
dev_set_drvdata(dev, hdmi);
|
|
||||||
|
|
||||||
ret = devm_request_threaded_irq(dev, irq, inno_hdmi_hardirq,
|
ret = devm_request_threaded_irq(dev, irq, inno_hdmi_hardirq,
|
||||||
inno_hdmi_irq, IRQF_SHARED,
|
inno_hdmi_irq, IRQF_SHARED,
|
||||||
dev_name(dev), hdmi);
|
dev_name(dev), hdmi);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err_cleanup_hdmi;
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
return 0;
|
hdmi->bridge.driver_private = hdmi;
|
||||||
err_cleanup_hdmi:
|
hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT |
|
||||||
hdmi->connector.funcs->destroy(&hdmi->connector);
|
DRM_BRIDGE_OP_EDID |
|
||||||
hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
|
DRM_BRIDGE_OP_HDMI |
|
||||||
return ret;
|
DRM_BRIDGE_OP_HPD;
|
||||||
|
hdmi->bridge.of_node = pdev->dev.of_node;
|
||||||
|
hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
|
||||||
|
hdmi->bridge.vendor = "Inno";
|
||||||
|
hdmi->bridge.product = "Inno HDMI";
|
||||||
|
|
||||||
|
hdmi->bridge.ddc = inno_hdmi_i2c_adapter(hdmi);
|
||||||
|
if (IS_ERR(hdmi->bridge.ddc))
|
||||||
|
return ERR_CAST(hdmi->bridge.ddc);
|
||||||
|
|
||||||
|
ret = devm_drm_bridge_add(dev, &hdmi->bridge);
|
||||||
|
if (ret)
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
|
ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
|
||||||
|
if (ret)
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
|
return hdmi;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(inno_hdmi_bind);
|
||||||
static void inno_hdmi_unbind(struct device *dev, struct device *master,
|
MODULE_AUTHOR("Andy Yan <andyshrk@163.com>");
|
||||||
void *data)
|
MODULE_DESCRIPTION("INNOSILICON HDMI transmitter library");
|
||||||
{
|
MODULE_LICENSE("GPL");
|
||||||
struct inno_hdmi *hdmi = dev_get_drvdata(dev);
|
|
||||||
|
|
||||||
hdmi->connector.funcs->destroy(&hdmi->connector);
|
|
||||||
hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct component_ops inno_hdmi_ops = {
|
|
||||||
.bind = inno_hdmi_bind,
|
|
||||||
.unbind = inno_hdmi_unbind,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int inno_hdmi_probe(struct platform_device *pdev)
|
|
||||||
{
|
|
||||||
return component_add(&pdev->dev, &inno_hdmi_ops);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void inno_hdmi_remove(struct platform_device *pdev)
|
|
||||||
{
|
|
||||||
component_del(&pdev->dev, &inno_hdmi_ops);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct inno_hdmi_variant rk3036_inno_hdmi_variant = {
|
|
||||||
.dev_type = RK3036_HDMI,
|
|
||||||
.phy_configs = rk3036_hdmi_phy_configs,
|
|
||||||
.default_phy_config = &rk3036_hdmi_phy_configs[1],
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct inno_hdmi_variant rk3128_inno_hdmi_variant = {
|
|
||||||
.dev_type = RK3128_HDMI,
|
|
||||||
.phy_configs = rk3128_hdmi_phy_configs,
|
|
||||||
.default_phy_config = &rk3128_hdmi_phy_configs[1],
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct of_device_id inno_hdmi_dt_ids[] = {
|
|
||||||
{ .compatible = "rockchip,rk3036-inno-hdmi",
|
|
||||||
.data = &rk3036_inno_hdmi_variant,
|
|
||||||
},
|
|
||||||
{ .compatible = "rockchip,rk3128-inno-hdmi",
|
|
||||||
.data = &rk3128_inno_hdmi_variant,
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
};
|
|
||||||
MODULE_DEVICE_TABLE(of, inno_hdmi_dt_ids);
|
|
||||||
|
|
||||||
struct platform_driver inno_hdmi_driver = {
|
|
||||||
.probe = inno_hdmi_probe,
|
|
||||||
.remove = inno_hdmi_remove,
|
|
||||||
.driver = {
|
|
||||||
.name = "innohdmi-rockchip",
|
|
||||||
.of_match_table = inno_hdmi_dt_ids,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
@ -15,6 +15,7 @@ config DRM_ROCKCHIP
|
||||||
select DRM_DW_HDMI_QP if ROCKCHIP_DW_HDMI_QP
|
select DRM_DW_HDMI_QP if ROCKCHIP_DW_HDMI_QP
|
||||||
select DRM_DW_MIPI_DSI if ROCKCHIP_DW_MIPI_DSI
|
select DRM_DW_MIPI_DSI if ROCKCHIP_DW_MIPI_DSI
|
||||||
select DRM_DW_MIPI_DSI2 if ROCKCHIP_DW_MIPI_DSI2
|
select DRM_DW_MIPI_DSI2 if ROCKCHIP_DW_MIPI_DSI2
|
||||||
|
select DRM_INNO_HDMI if ROCKCHIP_INNO_HDMI
|
||||||
select GENERIC_PHY if ROCKCHIP_DW_MIPI_DSI
|
select GENERIC_PHY if ROCKCHIP_DW_MIPI_DSI
|
||||||
select GENERIC_PHY_MIPI_DPHY if ROCKCHIP_DW_MIPI_DSI
|
select GENERIC_PHY_MIPI_DPHY if ROCKCHIP_DW_MIPI_DSI
|
||||||
select SND_SOC_HDMI_CODEC if ROCKCHIP_CDN_DP && SND_SOC
|
select SND_SOC_HDMI_CODEC if ROCKCHIP_CDN_DP && SND_SOC
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ rockchipdrm-$(CONFIG_ROCKCHIP_DW_HDMI_QP) += dw_hdmi_qp-rockchip.o
|
||||||
rockchipdrm-$(CONFIG_ROCKCHIP_DW_MIPI_DSI) += dw-mipi-dsi-rockchip.o
|
rockchipdrm-$(CONFIG_ROCKCHIP_DW_MIPI_DSI) += dw-mipi-dsi-rockchip.o
|
||||||
rockchipdrm-$(CONFIG_ROCKCHIP_DW_MIPI_DSI2) += dw-mipi-dsi2-rockchip.o
|
rockchipdrm-$(CONFIG_ROCKCHIP_DW_MIPI_DSI2) += dw-mipi-dsi2-rockchip.o
|
||||||
rockchipdrm-$(CONFIG_ROCKCHIP_DW_DP) += dw_dp-rockchip.o
|
rockchipdrm-$(CONFIG_ROCKCHIP_DW_DP) += dw_dp-rockchip.o
|
||||||
rockchipdrm-$(CONFIG_ROCKCHIP_INNO_HDMI) += inno_hdmi.o
|
rockchipdrm-$(CONFIG_ROCKCHIP_INNO_HDMI) += inno_hdmi-rockchip.o
|
||||||
rockchipdrm-$(CONFIG_ROCKCHIP_LVDS) += rockchip_lvds.o
|
rockchipdrm-$(CONFIG_ROCKCHIP_LVDS) += rockchip_lvds.o
|
||||||
rockchipdrm-$(CONFIG_ROCKCHIP_RGB) += rockchip_rgb.o
|
rockchipdrm-$(CONFIG_ROCKCHIP_RGB) += rockchip_rgb.o
|
||||||
rockchipdrm-$(CONFIG_ROCKCHIP_RK3066_HDMI) += rk3066_hdmi.o
|
rockchipdrm-$(CONFIG_ROCKCHIP_RK3066_HDMI) += rk3066_hdmi.o
|
||||||
|
|
|
||||||
189
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
Normal file
189
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
Normal file
|
|
@ -0,0 +1,189 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
/*
|
||||||
|
* Copyright (C) Rockchip Electronics Co., Ltd.
|
||||||
|
* Zheng Yang <zhengyang@rock-chips.com>
|
||||||
|
* Andy Yan <andy.yan@rock-chips.com>
|
||||||
|
*/
|
||||||
|
#include <linux/err.h>
|
||||||
|
#include <linux/hw_bitfield.h>
|
||||||
|
#include <linux/mfd/syscon.h>
|
||||||
|
#include <linux/mod_devicetable.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/platform_device.h>
|
||||||
|
#include <linux/regmap.h>
|
||||||
|
|
||||||
|
#include <drm/bridge/inno_hdmi.h>
|
||||||
|
#include <drm/drm_bridge_connector.h>
|
||||||
|
#include <drm/drm_of.h>
|
||||||
|
|
||||||
|
#include "rockchip_drm_drv.h"
|
||||||
|
|
||||||
|
#define HIWORD_UPDATE(val, mask) ((val) | (mask) << 16)
|
||||||
|
|
||||||
|
#define RK3036_GRF_SOC_CON2 0x148
|
||||||
|
#define RK3036_HDMI_PHSYNC BIT(4)
|
||||||
|
#define RK3036_HDMI_PVSYNC BIT(5)
|
||||||
|
|
||||||
|
enum inno_hdmi_dev_type {
|
||||||
|
RK3036_HDMI,
|
||||||
|
RK3128_HDMI,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct inno_hdmi_connector_state {
|
||||||
|
struct drm_connector_state base;
|
||||||
|
unsigned int colorimetry;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct rockchip_inno_hdmi {
|
||||||
|
struct inno_hdmi *base;
|
||||||
|
struct device *dev;
|
||||||
|
struct regmap *grf;
|
||||||
|
struct rockchip_encoder encoder;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct inno_hdmi_phy_config rk3036_hdmi_phy_configs[] = {
|
||||||
|
{ 74250000, 0x3f, 0xbb },
|
||||||
|
{ 165000000, 0x6f, 0xbb },
|
||||||
|
{ ~0UL, 0x00, 0x00 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct inno_hdmi_phy_config rk3128_hdmi_phy_configs[] = {
|
||||||
|
{ 74250000, 0x3f, 0xaa },
|
||||||
|
{ 165000000, 0x5f, 0xaa },
|
||||||
|
{ ~0UL, 0x00, 0x00 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void inno_hdmi_rk3036_enable(struct device *dev, struct drm_display_mode *mode)
|
||||||
|
{
|
||||||
|
struct rockchip_inno_hdmi *hdmi = dev_get_drvdata(dev);
|
||||||
|
int value, psync;
|
||||||
|
|
||||||
|
psync = mode->flags & DRM_MODE_FLAG_PHSYNC ? 1 : 0;
|
||||||
|
value = FIELD_PREP_WM16(RK3036_HDMI_PHSYNC, psync);
|
||||||
|
psync = mode->flags & DRM_MODE_FLAG_PVSYNC ? 1 : 0;
|
||||||
|
value |= FIELD_PREP_WM16(RK3036_HDMI_PVSYNC, psync);
|
||||||
|
regmap_write(hdmi->grf, RK3036_GRF_SOC_CON2, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int inno_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
|
||||||
|
struct drm_crtc_state *crtc_state,
|
||||||
|
struct drm_connector_state *conn_state)
|
||||||
|
{
|
||||||
|
struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
|
||||||
|
|
||||||
|
s->output_mode = ROCKCHIP_OUT_MODE_P888;
|
||||||
|
s->output_type = DRM_MODE_CONNECTOR_HDMIA;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct drm_encoder_helper_funcs inno_hdmi_rockchip_encoder_helper_funcs = {
|
||||||
|
.atomic_check = inno_hdmi_encoder_atomic_check,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int inno_hdmi_rockchip_bind(struct device *dev, struct device *master, void *data)
|
||||||
|
{
|
||||||
|
struct drm_device *drm = data;
|
||||||
|
struct drm_connector *connector;
|
||||||
|
struct drm_encoder *encoder;
|
||||||
|
struct rockchip_inno_hdmi *hdmi;
|
||||||
|
const struct inno_hdmi_plat_data *plat_data;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
|
||||||
|
if (!hdmi)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
hdmi->dev = dev;
|
||||||
|
|
||||||
|
plat_data = of_device_get_match_data(hdmi->dev);
|
||||||
|
if (!plat_data)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (of_device_is_compatible(dev->of_node, "rockchip,rk3036-inno-hdmi")) {
|
||||||
|
hdmi->grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf");
|
||||||
|
if (IS_ERR(hdmi->grf))
|
||||||
|
return dev_err_probe(dev,
|
||||||
|
PTR_ERR(hdmi->grf), "Unable to get rockchip,grf\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
encoder = &hdmi->encoder.encoder;
|
||||||
|
encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we failed to find the CRTC(s) which this encoder is
|
||||||
|
* supposed to be connected to, it's because the CRTC has
|
||||||
|
* not been registered yet. Defer probing, and hope that
|
||||||
|
* the required CRTC is added later.
|
||||||
|
*/
|
||||||
|
if (encoder->possible_crtcs == 0)
|
||||||
|
return -EPROBE_DEFER;
|
||||||
|
|
||||||
|
ret = drmm_encoder_init(drm, encoder, NULL, DRM_MODE_ENCODER_TMDS, NULL);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
drm_encoder_helper_add(encoder, &inno_hdmi_rockchip_encoder_helper_funcs);
|
||||||
|
|
||||||
|
dev_set_drvdata(dev, hdmi);
|
||||||
|
|
||||||
|
hdmi->base = inno_hdmi_bind(dev, encoder, plat_data);
|
||||||
|
|
||||||
|
connector = drm_bridge_connector_init(drm, encoder);
|
||||||
|
if (IS_ERR(connector)) {
|
||||||
|
ret = PTR_ERR(connector);
|
||||||
|
dev_err(hdmi->dev, "failed to init bridge connector: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return drm_connector_attach_encoder(connector, encoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct component_ops inno_hdmi_rockchip_ops = {
|
||||||
|
.bind = inno_hdmi_rockchip_bind,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int inno_hdmi_rockchip_probe(struct platform_device *pdev)
|
||||||
|
{
|
||||||
|
return component_add(&pdev->dev, &inno_hdmi_rockchip_ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void inno_hdmi_rockchip_remove(struct platform_device *pdev)
|
||||||
|
{
|
||||||
|
component_del(&pdev->dev, &inno_hdmi_rockchip_ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct inno_hdmi_plat_ops rk3036_inno_hdmi_plat_ops = {
|
||||||
|
.enable = inno_hdmi_rk3036_enable,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct inno_hdmi_plat_data rk3036_inno_hdmi_plat_data = {
|
||||||
|
.ops = &rk3036_inno_hdmi_plat_ops,
|
||||||
|
.phy_configs = rk3036_hdmi_phy_configs,
|
||||||
|
.default_phy_config = &rk3036_hdmi_phy_configs[1],
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct inno_hdmi_plat_data rk3128_inno_hdmi_plat_data = {
|
||||||
|
.phy_configs = rk3128_hdmi_phy_configs,
|
||||||
|
.default_phy_config = &rk3128_hdmi_phy_configs[1],
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct of_device_id inno_hdmi_rockchip_dt_ids[] = {
|
||||||
|
{ .compatible = "rockchip,rk3036-inno-hdmi",
|
||||||
|
.data = &rk3036_inno_hdmi_plat_data,
|
||||||
|
},
|
||||||
|
{ .compatible = "rockchip,rk3128-inno-hdmi",
|
||||||
|
.data = &rk3128_inno_hdmi_plat_data,
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(of, inno_hdmi_rockchip_dt_ids);
|
||||||
|
|
||||||
|
struct platform_driver inno_hdmi_driver = {
|
||||||
|
.probe = inno_hdmi_rockchip_probe,
|
||||||
|
.remove = inno_hdmi_rockchip_remove,
|
||||||
|
.driver = {
|
||||||
|
.name = "innohdmi-rockchip",
|
||||||
|
.of_match_table = inno_hdmi_rockchip_dt_ids,
|
||||||
|
},
|
||||||
|
};
|
||||||
33
include/drm/bridge/inno_hdmi.h
Normal file
33
include/drm/bridge/inno_hdmi.h
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Rockchip Electronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __INNO_HDMI__
|
||||||
|
#define __INNO_HDMI__
|
||||||
|
|
||||||
|
struct device;
|
||||||
|
struct drm_encoder;
|
||||||
|
struct drm_display_mode;
|
||||||
|
struct inno_hdmi;
|
||||||
|
|
||||||
|
struct inno_hdmi_plat_ops {
|
||||||
|
void (*enable)(struct device *pdev, struct drm_display_mode *mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct inno_hdmi_phy_config {
|
||||||
|
unsigned long pixelclock;
|
||||||
|
u8 pre_emphasis;
|
||||||
|
u8 voltage_level_control;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct inno_hdmi_plat_data {
|
||||||
|
const struct inno_hdmi_plat_ops *ops;
|
||||||
|
struct inno_hdmi_phy_config *phy_configs;
|
||||||
|
struct inno_hdmi_phy_config *default_phy_config;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct inno_hdmi *inno_hdmi_bind(struct device *pdev,
|
||||||
|
struct drm_encoder *encoder,
|
||||||
|
const struct inno_hdmi_plat_data *plat_data);
|
||||||
|
#endif /* __INNO_HDMI__ */
|
||||||
Loading…
Reference in New Issue
Block a user