Skip to content

Commit d6306fc

Browse files
AngeloGioacchino Del Regnovinodkoul
authored andcommitted
phy: mediatek: tphy: Cleanup and document slew calibration
While it's true that, generally, the T-PHY V3 does not support the slew calibration process, some minor versions of it actually do, moreover, some SoCs may not support this even though the version of the PHY IP does. The reference clock and rate coefficient parameters are used only for slew calibration: move those to platform data, then document and change the checks in hs_slew_rate_calibrate() to perform the calibration only if: - EYE value was not supplied (pre-calculated calibration); and - Slew reference clock value is present (not zero); and - Slew coefficient is present (not zero). Moreover, change the probe function to always check if both the slew reference clock and coefficient properties are present and, if not, assign the value from platform data (which, as reminder, if not added means that it's zero!), instead of checking the PHY IP version. Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Neil Armstrong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 9cc82c2 commit d6306fc

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

drivers/phy/mediatek/phy-mtk-tphy.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@
210210
#define P2F_USB_FM_VALID BIT(0)
211211
#define P2F_RG_FRCK_EN BIT(8)
212212

213-
#define U3P_REF_CLK 26 /* MHZ */
214-
#define U3P_SLEW_RATE_COEF 28
215213
#define U3P_SR_COEF_DIVISOR 1000
216214
#define U3P_FM_DET_CYCLE_CNT 1024
217215

@@ -285,12 +283,16 @@ enum mtk_phy_version {
285283
* @sw_efuse_supported: Switches off eFuse auto-load from PHY and applies values
286284
* read from different nvmem (usually different eFuse array)
287285
* that is pointed at in the device tree node for this PHY
286+
* @slew_ref_clk_mhz: Default reference clock (in MHz) for slew rate calibration
287+
* @slew_rate_coefficient: Coefficient for slew rate calibration
288288
* @version: PHY IP Version
289289
*/
290290
struct mtk_phy_pdata {
291291
bool avoid_rx_sen_degradation;
292292
bool sw_pll_48m_to_26m;
293293
bool sw_efuse_supported;
294+
u8 slew_ref_clock_mhz;
295+
u8 slew_rate_coefficient;
294296
enum mtk_phy_version version;
295297
};
296298

@@ -686,12 +688,14 @@ static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
686688
int fm_out;
687689
u32 tmp;
688690

689-
/* HW V3 doesn't support slew rate cal anymore */
690-
if (tphy->pdata->version == MTK_PHY_V3)
691-
return;
692-
693-
/* use force value */
694-
if (instance->eye_src)
691+
/*
692+
* If a fixed HS slew rate (EYE) value was supplied, don't run the
693+
* calibration sequence and prefer using that value instead; also,
694+
* if there is no reference clock for slew calibration or there is
695+
* no slew coefficient, this means that the slew rate calibration
696+
* sequence is not supported.
697+
*/
698+
if (instance->eye_src || !tphy->src_ref_clk || !tphy->src_coef)
695699
return;
696700

697701
/* enable USB ring oscillator */
@@ -1516,12 +1520,16 @@ static const struct phy_ops mtk_tphy_ops = {
15161520

15171521
static const struct mtk_phy_pdata tphy_v1_pdata = {
15181522
.avoid_rx_sen_degradation = false,
1523+
.slew_ref_clock_mhz = 26,
1524+
.slew_rate_coefficient = 28,
15191525
.version = MTK_PHY_V1,
15201526
};
15211527

15221528
static const struct mtk_phy_pdata tphy_v2_pdata = {
15231529
.avoid_rx_sen_degradation = false,
15241530
.sw_efuse_supported = true,
1531+
.slew_ref_clock_mhz = 26,
1532+
.slew_rate_coefficient = 28,
15251533
.version = MTK_PHY_V2,
15261534
};
15271535

@@ -1532,6 +1540,8 @@ static const struct mtk_phy_pdata tphy_v3_pdata = {
15321540

15331541
static const struct mtk_phy_pdata mt8173_pdata = {
15341542
.avoid_rx_sen_degradation = true,
1543+
.slew_ref_clock_mhz = 26,
1544+
.slew_rate_coefficient = 28,
15351545
.version = MTK_PHY_V1,
15361546
};
15371547

@@ -1561,7 +1571,7 @@ static int mtk_tphy_probe(struct platform_device *pdev)
15611571
struct resource *sif_res;
15621572
struct mtk_tphy *tphy;
15631573
struct resource res;
1564-
int port;
1574+
int port, ret;
15651575

15661576
tphy = devm_kzalloc(dev, sizeof(*tphy), GFP_KERNEL);
15671577
if (!tphy)
@@ -1591,15 +1601,14 @@ static int mtk_tphy_probe(struct platform_device *pdev)
15911601
}
15921602
}
15931603

1594-
if (tphy->pdata->version < MTK_PHY_V3) {
1595-
tphy->src_ref_clk = U3P_REF_CLK;
1596-
tphy->src_coef = U3P_SLEW_RATE_COEF;
1597-
/* update parameters of slew rate calibrate if exist */
1598-
device_property_read_u32(dev, "mediatek,src-ref-clk-mhz",
1599-
&tphy->src_ref_clk);
1600-
device_property_read_u32(dev, "mediatek,src-coef",
1601-
&tphy->src_coef);
1602-
}
1604+
/* Optional properties for slew calibration variation */
1605+
ret = device_property_read_u32(dev, "mediatek,src-ref-clk-mhz", &tphy->src_ref_clk);
1606+
if (ret)
1607+
tphy->src_ref_clk = tphy->pdata->slew_ref_clock_mhz;
1608+
1609+
ret = device_property_read_u32(dev, "mediatek,src-coef", &tphy->src_coef);
1610+
if (ret)
1611+
tphy->src_coef = tphy->pdata->slew_rate_coefficient;
16031612

16041613
port = 0;
16051614
for_each_child_of_node_scoped(np, child_np) {

0 commit comments

Comments
 (0)