Commit 2ef9dfed authored by Kieran Bingham's avatar Kieran Bingham Committed by Archit Taneja

drm: bridge: dw-hdmi: Add support for custom PHY configuration

The DWC HDMI TX controller interfaces with a companion PHY. While
Synopsys provides multiple standard PHYs, SoC vendors can also integrate
a custom PHY.

Modularize PHY configuration to support vendor PHYs through platform
data. The existing PHY configuration code was originally written to
support the DWC HDMI 3D TX PHY, and seems to be compatible with the DWC
MLP PHY. The HDMI 2.0 PHY will require a separate configuration
function.
Signed-off-by: default avatarKieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tested-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
Reviewed-by: default avatarJose Abreu <Jose.Abreu@synopsys.com>
Signed-off-by: default avatarArchit Taneja <architt@codeaurora.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20170303172007.26541-8-laurent.pinchart+renesas@ideasonboard.com
parent f1585f6e
...@@ -118,6 +118,9 @@ struct dw_hdmi_phy_data { ...@@ -118,6 +118,9 @@ struct dw_hdmi_phy_data {
const char *name; const char *name;
unsigned int gen; unsigned int gen;
bool has_svsret; bool has_svsret;
int (*configure)(struct dw_hdmi *hdmi,
const struct dw_hdmi_plat_data *pdata,
unsigned long mpixelclock);
}; };
struct dw_hdmi { struct dw_hdmi {
...@@ -860,7 +863,7 @@ static bool hdmi_phy_wait_i2c_done(struct dw_hdmi *hdmi, int msec) ...@@ -860,7 +863,7 @@ static bool hdmi_phy_wait_i2c_done(struct dw_hdmi *hdmi, int msec)
return true; return true;
} }
static void hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data, void dw_hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data,
unsigned char addr) unsigned char addr)
{ {
hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0); hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0);
...@@ -873,6 +876,7 @@ static void hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data, ...@@ -873,6 +876,7 @@ static void hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data,
HDMI_PHY_I2CM_OPERATION_ADDR); HDMI_PHY_I2CM_OPERATION_ADDR);
hdmi_phy_wait_i2c_done(hdmi, 1000); hdmi_phy_wait_i2c_done(hdmi, 1000);
} }
EXPORT_SYMBOL_GPL(dw_hdmi_phy_i2c_write);
static void dw_hdmi_phy_enable_powerdown(struct dw_hdmi *hdmi, bool enable) static void dw_hdmi_phy_enable_powerdown(struct dw_hdmi *hdmi, bool enable)
{ {
...@@ -993,37 +997,67 @@ static int dw_hdmi_phy_power_on(struct dw_hdmi *hdmi) ...@@ -993,37 +997,67 @@ static int dw_hdmi_phy_power_on(struct dw_hdmi *hdmi)
return 0; return 0;
} }
static int hdmi_phy_configure(struct dw_hdmi *hdmi) /*
* PHY configuration function for the DWC HDMI 3D TX PHY. Based on the available
* information the DWC MHL PHY has the same register layout and is thus also
* supported by this function.
*/
static int hdmi_phy_configure_dwc_hdmi_3d_tx(struct dw_hdmi *hdmi,
const struct dw_hdmi_plat_data *pdata,
unsigned long mpixelclock)
{ {
const struct dw_hdmi_phy_data *phy = hdmi->phy.data;
const struct dw_hdmi_plat_data *pdata = hdmi->plat_data;
const struct dw_hdmi_mpll_config *mpll_config = pdata->mpll_cfg; const struct dw_hdmi_mpll_config *mpll_config = pdata->mpll_cfg;
const struct dw_hdmi_curr_ctrl *curr_ctrl = pdata->cur_ctr; const struct dw_hdmi_curr_ctrl *curr_ctrl = pdata->cur_ctr;
const struct dw_hdmi_phy_config *phy_config = pdata->phy_config; const struct dw_hdmi_phy_config *phy_config = pdata->phy_config;
/* PLL/MPLL Cfg - always match on final entry */ /* PLL/MPLL Cfg - always match on final entry */
for (; mpll_config->mpixelclock != ~0UL; mpll_config++) for (; mpll_config->mpixelclock != ~0UL; mpll_config++)
if (hdmi->hdmi_data.video_mode.mpixelclock <= if (mpixelclock <= mpll_config->mpixelclock)
mpll_config->mpixelclock)
break; break;
for (; curr_ctrl->mpixelclock != ~0UL; curr_ctrl++) for (; curr_ctrl->mpixelclock != ~0UL; curr_ctrl++)
if (hdmi->hdmi_data.video_mode.mpixelclock <= if (mpixelclock <= curr_ctrl->mpixelclock)
curr_ctrl->mpixelclock)
break; break;
for (; phy_config->mpixelclock != ~0UL; phy_config++) for (; phy_config->mpixelclock != ~0UL; phy_config++)
if (hdmi->hdmi_data.video_mode.mpixelclock <= if (mpixelclock <= phy_config->mpixelclock)
phy_config->mpixelclock)
break; break;
if (mpll_config->mpixelclock == ~0UL || if (mpll_config->mpixelclock == ~0UL ||
curr_ctrl->mpixelclock == ~0UL || curr_ctrl->mpixelclock == ~0UL ||
phy_config->mpixelclock == ~0UL) { phy_config->mpixelclock == ~0UL)
dev_err(hdmi->dev, "Pixel clock %d - unsupported by HDMI\n",
hdmi->hdmi_data.video_mode.mpixelclock);
return -EINVAL; return -EINVAL;
}
dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce,
HDMI_3D_TX_PHY_CPCE_CTRL);
dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp,
HDMI_3D_TX_PHY_GMPCTRL);
dw_hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0],
HDMI_3D_TX_PHY_CURRCTRL);
dw_hdmi_phy_i2c_write(hdmi, 0, HDMI_3D_TX_PHY_PLLPHBYCTRL);
dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK,
HDMI_3D_TX_PHY_MSM_CTRL);
dw_hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM);
dw_hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr,
HDMI_3D_TX_PHY_CKSYMTXCTRL);
dw_hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr,
HDMI_3D_TX_PHY_VLEVCTRL);
/* Override and disable clock termination. */
dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_CKCALCTRL_OVERRIDE,
HDMI_3D_TX_PHY_CKCALCTRL);
return 0;
}
static int hdmi_phy_configure(struct dw_hdmi *hdmi)
{
const struct dw_hdmi_phy_data *phy = hdmi->phy.data;
const struct dw_hdmi_plat_data *pdata = hdmi->plat_data;
unsigned long mpixelclock = hdmi->hdmi_data.video_mode.mpixelclock;
int ret;
dw_hdmi_phy_power_off(hdmi); dw_hdmi_phy_power_off(hdmi);
...@@ -1042,26 +1076,16 @@ static int hdmi_phy_configure(struct dw_hdmi *hdmi) ...@@ -1042,26 +1076,16 @@ static int hdmi_phy_configure(struct dw_hdmi *hdmi)
HDMI_PHY_I2CM_SLAVE_ADDR); HDMI_PHY_I2CM_SLAVE_ADDR);
hdmi_phy_test_clear(hdmi, 0); hdmi_phy_test_clear(hdmi, 0);
hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce, /* Write to the PHY as configured by the platform */
HDMI_3D_TX_PHY_CPCE_CTRL); if (pdata->configure_phy)
hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp, ret = pdata->configure_phy(hdmi, pdata, mpixelclock);
HDMI_3D_TX_PHY_GMPCTRL); else
hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0], ret = phy->configure(hdmi, pdata, mpixelclock);
HDMI_3D_TX_PHY_CURRCTRL); if (ret) {
dev_err(hdmi->dev, "PHY configuration failed (clock %lu)\n",
hdmi_phy_i2c_write(hdmi, 0, HDMI_3D_TX_PHY_PLLPHBYCTRL); mpixelclock);
hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK, return ret;
HDMI_3D_TX_PHY_MSM_CTRL); }
hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM);
hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr,
HDMI_3D_TX_PHY_CKSYMTXCTRL);
hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr,
HDMI_3D_TX_PHY_VLEVCTRL);
/* Override and disable clock termination. */
hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_CKCALCTRL_OVERRIDE,
HDMI_3D_TX_PHY_CKCALCTRL);
return dw_hdmi_phy_power_on(hdmi); return dw_hdmi_phy_power_on(hdmi);
} }
...@@ -1895,24 +1919,31 @@ static const struct dw_hdmi_phy_data dw_hdmi_phys[] = { ...@@ -1895,24 +1919,31 @@ static const struct dw_hdmi_phy_data dw_hdmi_phys[] = {
.name = "DWC MHL PHY + HEAC PHY", .name = "DWC MHL PHY + HEAC PHY",
.gen = 2, .gen = 2,
.has_svsret = true, .has_svsret = true,
.configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
}, { }, {
.type = DW_HDMI_PHY_DWC_MHL_PHY, .type = DW_HDMI_PHY_DWC_MHL_PHY,
.name = "DWC MHL PHY", .name = "DWC MHL PHY",
.gen = 2, .gen = 2,
.has_svsret = true, .has_svsret = true,
.configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
}, { }, {
.type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY_HEAC, .type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY_HEAC,
.name = "DWC HDMI 3D TX PHY + HEAC PHY", .name = "DWC HDMI 3D TX PHY + HEAC PHY",
.gen = 2, .gen = 2,
.configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
}, { }, {
.type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY, .type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY,
.name = "DWC HDMI 3D TX PHY", .name = "DWC HDMI 3D TX PHY",
.gen = 2, .gen = 2,
.configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
}, { }, {
.type = DW_HDMI_PHY_DWC_HDMI20_TX_PHY, .type = DW_HDMI_PHY_DWC_HDMI20_TX_PHY,
.name = "DWC HDMI 2.0 TX PHY", .name = "DWC HDMI 2.0 TX PHY",
.gen = 2, .gen = 2,
.has_svsret = true, .has_svsret = true,
}, {
.type = DW_HDMI_PHY_VENDOR_PHY,
.name = "Vendor PHY",
} }
}; };
...@@ -1943,6 +1974,14 @@ static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi) ...@@ -1943,6 +1974,14 @@ static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi)
hdmi->phy.ops = &dw_hdmi_synopsys_phy_ops; hdmi->phy.ops = &dw_hdmi_synopsys_phy_ops;
hdmi->phy.name = dw_hdmi_phys[i].name; hdmi->phy.name = dw_hdmi_phys[i].name;
hdmi->phy.data = (void *)&dw_hdmi_phys[i]; hdmi->phy.data = (void *)&dw_hdmi_phys[i];
if (!dw_hdmi_phys[i].configure &&
!hdmi->plat_data->configure_phy) {
dev_err(hdmi->dev, "%s requires platform support\n",
hdmi->phy.name);
return -ENODEV;
}
return 0; return 0;
} }
} }
......
...@@ -78,6 +78,9 @@ struct dw_hdmi_plat_data { ...@@ -78,6 +78,9 @@ struct dw_hdmi_plat_data {
const struct dw_hdmi_mpll_config *mpll_cfg; const struct dw_hdmi_mpll_config *mpll_cfg;
const struct dw_hdmi_curr_ctrl *cur_ctr; const struct dw_hdmi_curr_ctrl *cur_ctr;
const struct dw_hdmi_phy_config *phy_config; const struct dw_hdmi_phy_config *phy_config;
int (*configure_phy)(struct dw_hdmi *hdmi,
const struct dw_hdmi_plat_data *pdata,
unsigned long mpixelclock);
}; };
int dw_hdmi_probe(struct platform_device *pdev, int dw_hdmi_probe(struct platform_device *pdev,
...@@ -91,4 +94,8 @@ void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate); ...@@ -91,4 +94,8 @@ void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate);
void dw_hdmi_audio_enable(struct dw_hdmi *hdmi); void dw_hdmi_audio_enable(struct dw_hdmi *hdmi);
void dw_hdmi_audio_disable(struct dw_hdmi *hdmi); void dw_hdmi_audio_disable(struct dw_hdmi *hdmi);
/* PHY configuration */
void dw_hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data,
unsigned char addr);
#endif /* __IMX_HDMI_H__ */ #endif /* __IMX_HDMI_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment