Skip to content

Commit 9eb8e3d

Browse files
abelvesavinodkoul
authored andcommitted
phy: qcom: edp: Move v4 specific settings to version ops
In order to support different HW versions move everything specific to v4 into so-called version ops. Signed-off-by: Abel Vesa <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 5d56078 commit 9eb8e3d

File tree

1 file changed

+118
-65
lines changed

1 file changed

+118
-65
lines changed

drivers/phy/qualcomm/phy-qcom-edp.c

Lines changed: 118 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,20 @@ struct qcom_edp_swing_pre_emph_cfg {
7777
const u8 (*pre_emphasis_hbr3_hbr2)[4][4];
7878
};
7979

80+
struct qcom_edp;
81+
82+
struct phy_ver_ops {
83+
int (*com_power_on)(const struct qcom_edp *edp);
84+
int (*com_resetsm_cntrl)(const struct qcom_edp *edp);
85+
int (*com_bias_en_clkbuflr)(const struct qcom_edp *edp);
86+
int (*com_configure_pll)(const struct qcom_edp *edp);
87+
int (*com_configure_ssc)(const struct qcom_edp *edp);
88+
};
89+
8090
struct qcom_edp_phy_cfg {
8191
bool is_edp;
8292
const struct qcom_edp_swing_pre_emph_cfg *swing_pre_emph_cfg;
93+
const struct phy_ver_ops *ver_ops;
8394
};
8495

8596
struct qcom_edp {
@@ -174,18 +185,6 @@ static const struct qcom_edp_swing_pre_emph_cfg edp_phy_swing_pre_emph_cfg = {
174185
.pre_emphasis_hbr3_hbr2 = &edp_pre_emp_hbr2_hbr3,
175186
};
176187

177-
static const struct qcom_edp_phy_cfg sc7280_dp_phy_cfg = {
178-
};
179-
180-
static const struct qcom_edp_phy_cfg sc8280xp_dp_phy_cfg = {
181-
.swing_pre_emph_cfg = &dp_phy_swing_pre_emph_cfg,
182-
};
183-
184-
static const struct qcom_edp_phy_cfg sc8280xp_edp_phy_cfg = {
185-
.is_edp = true,
186-
.swing_pre_emph_cfg = &edp_phy_swing_pre_emph_cfg,
187-
};
188-
189188
static int qcom_edp_phy_init(struct phy *phy)
190189
{
191190
struct qcom_edp *edp = phy_get_drvdata(phy);
@@ -204,8 +203,9 @@ static int qcom_edp_phy_init(struct phy *phy)
204203
DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
205204
edp->edp + DP_PHY_PD_CTL);
206205

207-
/* Turn on BIAS current for PHY/PLL */
208-
writel(0x17, edp->pll + QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN);
206+
ret = edp->cfg->ver_ops->com_bias_en_clkbuflr(edp);
207+
if (ret)
208+
return ret;
209209

210210
writel(DP_PHY_PD_CTL_PSR_PWRDN, edp->edp + DP_PHY_PD_CTL);
211211
msleep(20);
@@ -312,6 +312,84 @@ static int qcom_edp_phy_configure(struct phy *phy, union phy_configure_opts *opt
312312
}
313313

314314
static int qcom_edp_configure_ssc(const struct qcom_edp *edp)
315+
{
316+
return edp->cfg->ver_ops->com_configure_ssc(edp);
317+
}
318+
319+
static int qcom_edp_configure_pll(const struct qcom_edp *edp)
320+
{
321+
return edp->cfg->ver_ops->com_configure_pll(edp);
322+
}
323+
324+
static int qcom_edp_set_vco_div(const struct qcom_edp *edp, unsigned long *pixel_freq)
325+
{
326+
const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
327+
u32 vco_div;
328+
329+
switch (dp_opts->link_rate) {
330+
case 1620:
331+
vco_div = 0x1;
332+
*pixel_freq = 1620000000UL / 2;
333+
break;
334+
335+
case 2700:
336+
vco_div = 0x1;
337+
*pixel_freq = 2700000000UL / 2;
338+
break;
339+
340+
case 5400:
341+
vco_div = 0x2;
342+
*pixel_freq = 5400000000UL / 4;
343+
break;
344+
345+
case 8100:
346+
vco_div = 0x0;
347+
*pixel_freq = 8100000000UL / 6;
348+
break;
349+
350+
default:
351+
/* Other link rates aren't supported */
352+
return -EINVAL;
353+
}
354+
355+
writel(vco_div, edp->edp + DP_PHY_VCO_DIV);
356+
357+
return 0;
358+
}
359+
360+
static int qcom_edp_phy_power_on_v4(const struct qcom_edp *edp)
361+
{
362+
u32 val;
363+
364+
writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
365+
DP_PHY_PD_CTL_LANE_0_1_PWRDN | DP_PHY_PD_CTL_LANE_2_3_PWRDN |
366+
DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
367+
edp->edp + DP_PHY_PD_CTL);
368+
writel(0xfc, edp->edp + DP_PHY_MODE);
369+
370+
return readl_poll_timeout(edp->pll + QSERDES_V4_COM_CMN_STATUS,
371+
val, val & BIT(7), 5, 200);
372+
}
373+
374+
static int qcom_edp_phy_com_resetsm_cntrl_v4(const struct qcom_edp *edp)
375+
{
376+
u32 val;
377+
378+
writel(0x20, edp->pll + QSERDES_V4_COM_RESETSM_CNTRL);
379+
380+
return readl_poll_timeout(edp->pll + QSERDES_V4_COM_C_READY_STATUS,
381+
val, val & BIT(0), 500, 10000);
382+
}
383+
384+
static int qcom_edp_com_bias_en_clkbuflr_v4(const struct qcom_edp *edp)
385+
{
386+
/* Turn on BIAS current for PHY/PLL */
387+
writel(0x17, edp->pll + QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN);
388+
389+
return 0;
390+
}
391+
392+
static int qcom_edp_com_configure_ssc_v4(const struct qcom_edp *edp)
315393
{
316394
const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
317395
u32 step1;
@@ -345,7 +423,7 @@ static int qcom_edp_configure_ssc(const struct qcom_edp *edp)
345423
return 0;
346424
}
347425

348-
static int qcom_edp_configure_pll(const struct qcom_edp *edp)
426+
static int qcom_edp_com_configure_pll_v4(const struct qcom_edp *edp)
349427
{
350428
const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
351429
u32 div_frac_start2_mode0;
@@ -431,64 +509,42 @@ static int qcom_edp_configure_pll(const struct qcom_edp *edp)
431509
return 0;
432510
}
433511

434-
static int qcom_edp_set_vco_div(const struct qcom_edp *edp, unsigned long *pixel_freq)
435-
{
436-
const struct phy_configure_opts_dp *dp_opts = &edp->dp_opts;
437-
u32 vco_div;
438-
439-
switch (dp_opts->link_rate) {
440-
case 1620:
441-
vco_div = 0x1;
442-
*pixel_freq = 1620000000UL / 2;
443-
break;
444-
445-
case 2700:
446-
vco_div = 0x1;
447-
*pixel_freq = 2700000000UL / 2;
448-
break;
449-
450-
case 5400:
451-
vco_div = 0x2;
452-
*pixel_freq = 5400000000UL / 4;
453-
break;
454-
455-
case 8100:
456-
vco_div = 0x0;
457-
*pixel_freq = 8100000000UL / 6;
458-
break;
512+
static const struct phy_ver_ops qcom_edp_phy_ops_v4 = {
513+
.com_power_on = qcom_edp_phy_power_on_v4,
514+
.com_resetsm_cntrl = qcom_edp_phy_com_resetsm_cntrl_v4,
515+
.com_bias_en_clkbuflr = qcom_edp_com_bias_en_clkbuflr_v4,
516+
.com_configure_pll = qcom_edp_com_configure_pll_v4,
517+
.com_configure_ssc = qcom_edp_com_configure_ssc_v4,
518+
};
459519

460-
default:
461-
/* Other link rates aren't supported */
462-
return -EINVAL;
463-
}
520+
static const struct qcom_edp_phy_cfg sc7280_dp_phy_cfg = {
521+
.ver_ops = &qcom_edp_phy_ops_v4,
522+
};
464523

465-
writel(vco_div, edp->edp + DP_PHY_VCO_DIV);
524+
static const struct qcom_edp_phy_cfg sc8280xp_dp_phy_cfg = {
525+
.swing_pre_emph_cfg = &dp_phy_swing_pre_emph_cfg,
526+
.ver_ops = &qcom_edp_phy_ops_v4,
527+
};
466528

467-
return 0;
468-
}
529+
static const struct qcom_edp_phy_cfg sc8280xp_edp_phy_cfg = {
530+
.is_edp = true,
531+
.swing_pre_emph_cfg = &edp_phy_swing_pre_emph_cfg,
532+
.ver_ops = &qcom_edp_phy_ops_v4,
533+
};
469534

470535
static int qcom_edp_phy_power_on(struct phy *phy)
471536
{
472537
const struct qcom_edp *edp = phy_get_drvdata(phy);
473538
u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
474539
unsigned long pixel_freq;
475540
u8 ldo_config = 0x0;
476-
int timeout;
477541
int ret;
478542
u32 val;
479543
u8 cfg1;
480544

481-
writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
482-
DP_PHY_PD_CTL_LANE_0_1_PWRDN | DP_PHY_PD_CTL_LANE_2_3_PWRDN |
483-
DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
484-
edp->edp + DP_PHY_PD_CTL);
485-
writel(0xfc, edp->edp + DP_PHY_MODE);
486-
487-
timeout = readl_poll_timeout(edp->pll + QSERDES_V4_COM_CMN_STATUS,
488-
val, val & BIT(7), 5, 200);
489-
if (timeout)
490-
return timeout;
491-
545+
ret = edp->cfg->ver_ops->com_power_on(edp);
546+
if (ret)
547+
return ret;
492548

493549
if (edp->cfg->swing_pre_emph_cfg && !edp->is_edp)
494550
ldo_config = 0x1;
@@ -535,12 +591,9 @@ static int qcom_edp_phy_power_on(struct phy *phy)
535591
writel(0x01, edp->edp + DP_PHY_CFG);
536592
writel(0x09, edp->edp + DP_PHY_CFG);
537593

538-
writel(0x20, edp->pll + QSERDES_V4_COM_RESETSM_CNTRL);
539-
540-
timeout = readl_poll_timeout(edp->pll + QSERDES_V4_COM_C_READY_STATUS,
541-
val, val & BIT(0), 500, 10000);
542-
if (timeout)
543-
return timeout;
594+
ret = edp->cfg->ver_ops->com_resetsm_cntrl(edp);
595+
if (ret)
596+
return ret;
544597

545598
writel(0x19, edp->edp + DP_PHY_CFG);
546599
writel(0x1f, edp->tx0 + TXn_HIGHZ_DRVR_EN);

0 commit comments

Comments
 (0)