1 From 54543412064edcda35437add357705996a96c492 Mon Sep 17 00:00:00 2001
2 From: "shanlong.li" <shanlong.li@starfivetech.com>
3 Date: Wed, 31 May 2023 01:14:01 -0700
4 Subject: [PATCH 073/129] net: phy: motorcomm: Add pad drive strength cfg
7 The motorcomm phy (YT8531) supports the ability to adjust the drive
8 strength of the rx_clk/rx_data, and the default strength may not be
9 suitable for all boards. So add configurable options to better match
10 the boards.(e.g. StarFive VisionFive 2)
12 Signed-off-by: shanlong.li <shanlong.li@starfivetech.com>
14 drivers/net/phy/motorcomm.c | 62 +++++++++++++++++++++++--------------
15 1 file changed, 38 insertions(+), 24 deletions(-)
17 --- a/drivers/net/phy/motorcomm.c
18 +++ b/drivers/net/phy/motorcomm.c
20 #define YTPHY_WCR_TYPE_PULSE BIT(0)
22 #define YTPHY_PAD_DRIVE_STRENGTH_REG 0xA010
23 -#define YTPHY_RGMII_RXC_DS GENMASK(15, 13)
24 -#define YTPHY_RGMII_RXD_DS GENMASK(5, 4) /* Bit 1 and 0 of rgmii_rxd_ds */
25 -#define YTPHY_RGMII_RXD_DS2 BIT(12) /* Bit 2 of rgmii_rxd_ds */
26 +#define YT8531_RGMII_RXC_DS_DEFAULT 0x3
27 +#define YT8531_RGMII_RXC_DS_MAX 0x7
28 +#define YT8531_RGMII_RXC_DS GENMASK(15, 13)
29 +#define YT8531_RGMII_RXD_DS_DEFAULT 0x3
30 +#define YT8531_RGMII_RXD_DS_MAX 0x7
31 +#define YT8531_RGMII_RXD_DS_LOW GENMASK(5, 4) /* Bit 1/0 of rxd_ds */
32 +#define YT8531_RGMII_RXD_DS_HI BIT(12) /* Bit 2 of rxd_ds */
34 #define YTPHY_SYNCE_CFG_REG 0xA012
35 #define YT8521_SCR_SYNCE_ENABLE BIT(5)
36 @@ -1500,8 +1504,8 @@ err_restore_page:
37 static int yt8531_config_init(struct phy_device *phydev)
39 struct device_node *node = phydev->mdio.dev.of_node;
44 ret = ytphy_rgmii_clk_delay_config_with_lock(phydev);
46 @@ -1525,32 +1529,42 @@ static int yt8531_config_init(struct phy
50 - if (!of_property_read_u32(node, "rx-clk-driver-strength", &val)) {
51 - ret = ytphy_modify_ext_with_lock(phydev,
52 - YTPHY_PAD_DRIVE_STRENGTH_REG,
54 - FIELD_PREP(YTPHY_RGMII_RXC_DS, val));
57 + ds = YT8531_RGMII_RXC_DS_DEFAULT;
58 + if (!of_property_read_u32(node, "motorcomm,rx-clk-driver-strength", &val)) {
59 + if (val > YT8531_RGMII_RXC_DS_MAX)
65 - if (!of_property_read_u32(node, "rx-data-driver-strength", &val)) {
66 - if (val > FIELD_MAX(YTPHY_RGMII_RXD_DS)) {
67 - val &= FIELD_MAX(YTPHY_RGMII_RXD_DS);
68 - val = FIELD_PREP(YTPHY_RGMII_RXD_DS, val);
69 - val |= YTPHY_RGMII_RXD_DS2;
70 + ret = ytphy_modify_ext_with_lock(phydev,
71 + YTPHY_PAD_DRIVE_STRENGTH_REG,
72 + YT8531_RGMII_RXC_DS,
73 + FIELD_PREP(YT8531_RGMII_RXC_DS, ds));
77 + ds = FIELD_PREP(YT8531_RGMII_RXD_DS_LOW, YT8531_RGMII_RXD_DS_DEFAULT);
78 + if (!of_property_read_u32(node, "motorcomm,rx-data-driver-strength", &val)) {
79 + if (val > YT8531_RGMII_RXD_DS_MAX)
82 + if (val > FIELD_MAX(YT8531_RGMII_RXD_DS_LOW)) {
83 + ds = val & FIELD_MAX(YT8531_RGMII_RXD_DS_LOW);
84 + ds = FIELD_PREP(YT8531_RGMII_RXD_DS_LOW, ds);
85 + ds |= YT8531_RGMII_RXD_DS_HI;
87 - val = FIELD_PREP(YTPHY_RGMII_RXD_DS, val);
88 + ds = FIELD_PREP(YT8531_RGMII_RXD_DS_LOW, val);
91 - ret = ytphy_modify_ext_with_lock(phydev,
92 - YTPHY_PAD_DRIVE_STRENGTH_REG,
93 - YTPHY_RGMII_RXD_DS | YTPHY_RGMII_RXD_DS2,
99 + ret = ytphy_modify_ext_with_lock(phydev,
100 + YTPHY_PAD_DRIVE_STRENGTH_REG,
101 + YT8531_RGMII_RXD_DS_LOW | YT8531_RGMII_RXD_DS_HI,