f09142c5ed446dd0464844e4a1515033a74796b8
[openwrt/staging/wigyori.git] /
1 From d43cff3f82336c0bd965ea552232d9f4ddac71a6 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Fri, 8 Dec 2023 15:51:51 +0100
4 Subject: [PATCH 04/13] net: phy: at803x: move qca83xx specific check in
5 dedicated functions
6
7 Rework qca83xx specific check to dedicated function to tidy things up
8 and drop useless phy_id check.
9
10 Also drop an useless link_change_notify for QCA8337 as it did nothing an
11 returned early.
12
13 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
14 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 ---
17 drivers/net/phy/at803x.c | 68 ++++++++++++++++++++++------------------
18 1 file changed, 37 insertions(+), 31 deletions(-)
19
20 --- a/drivers/net/phy/at803x.c
21 +++ b/drivers/net/phy/at803x.c
22 @@ -1623,27 +1623,26 @@ static int qca83xx_config_init(struct ph
23 break;
24 }
25
26 + /* Following original QCA sourcecode set port to prefer master */
27 + phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
28 +
29 + return 0;
30 +}
31 +
32 +static int qca8327_config_init(struct phy_device *phydev)
33 +{
34 /* QCA8327 require DAC amplitude adjustment for 100m set to +6%.
35 * Disable on init and enable only with 100m speed following
36 * qca original source code.
37 */
38 - if (phydev->drv->phy_id == QCA8327_A_PHY_ID ||
39 - phydev->drv->phy_id == QCA8327_B_PHY_ID)
40 - at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
41 - QCA8327_DEBUG_MANU_CTRL_EN, 0);
42 + at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
43 + QCA8327_DEBUG_MANU_CTRL_EN, 0);
44
45 - /* Following original QCA sourcecode set port to prefer master */
46 - phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
47 -
48 - return 0;
49 + return qca83xx_config_init(phydev);
50 }
51
52 static void qca83xx_link_change_notify(struct phy_device *phydev)
53 {
54 - /* QCA8337 doesn't require DAC Amplitude adjustement */
55 - if (phydev->drv->phy_id == QCA8337_PHY_ID)
56 - return;
57 -
58 /* Set DAC Amplitude adjustment to +6% for 100m on link running */
59 if (phydev->state == PHY_RUNNING) {
60 if (phydev->speed == SPEED_100)
61 @@ -1686,19 +1685,6 @@ static int qca83xx_resume(struct phy_dev
62
63 static int qca83xx_suspend(struct phy_device *phydev)
64 {
65 - u16 mask = 0;
66 -
67 - /* Only QCA8337 support actual suspend.
68 - * QCA8327 cause port unreliability when phy suspend
69 - * is set.
70 - */
71 - if (phydev->drv->phy_id == QCA8337_PHY_ID) {
72 - genphy_suspend(phydev);
73 - } else {
74 - mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
75 - phy_modify(phydev, MII_BMCR, mask, 0);
76 - }
77 -
78 at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN,
79 AT803X_DEBUG_GATE_CLK_IN1000, 0);
80
81 @@ -1709,6 +1695,27 @@ static int qca83xx_suspend(struct phy_de
82 return 0;
83 }
84
85 +static int qca8337_suspend(struct phy_device *phydev)
86 +{
87 + /* Only QCA8337 support actual suspend. */
88 + genphy_suspend(phydev);
89 +
90 + return qca83xx_suspend(phydev);
91 +}
92 +
93 +static int qca8327_suspend(struct phy_device *phydev)
94 +{
95 + u16 mask = 0;
96 +
97 + /* QCA8327 cause port unreliability when phy suspend
98 + * is set.
99 + */
100 + mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
101 + phy_modify(phydev, MII_BMCR, mask, 0);
102 +
103 + return qca83xx_suspend(phydev);
104 +}
105 +
106 static int qca808x_phy_fast_retrain_config(struct phy_device *phydev)
107 {
108 int ret;
109 @@ -2170,7 +2177,6 @@ static struct phy_driver at803x_driver[]
110 .phy_id_mask = QCA8K_PHY_ID_MASK,
111 .name = "Qualcomm Atheros 8337 internal PHY",
112 /* PHY_GBIT_FEATURES */
113 - .link_change_notify = qca83xx_link_change_notify,
114 .probe = at803x_probe,
115 .flags = PHY_IS_INTERNAL,
116 .config_init = qca83xx_config_init,
117 @@ -2178,7 +2184,7 @@ static struct phy_driver at803x_driver[]
118 .get_sset_count = qca83xx_get_sset_count,
119 .get_strings = qca83xx_get_strings,
120 .get_stats = qca83xx_get_stats,
121 - .suspend = qca83xx_suspend,
122 + .suspend = qca8337_suspend,
123 .resume = qca83xx_resume,
124 }, {
125 /* QCA8327-A from switch QCA8327-AL1A */
126 @@ -2189,12 +2195,12 @@ static struct phy_driver at803x_driver[]
127 .link_change_notify = qca83xx_link_change_notify,
128 .probe = at803x_probe,
129 .flags = PHY_IS_INTERNAL,
130 - .config_init = qca83xx_config_init,
131 + .config_init = qca8327_config_init,
132 .soft_reset = genphy_soft_reset,
133 .get_sset_count = qca83xx_get_sset_count,
134 .get_strings = qca83xx_get_strings,
135 .get_stats = qca83xx_get_stats,
136 - .suspend = qca83xx_suspend,
137 + .suspend = qca8327_suspend,
138 .resume = qca83xx_resume,
139 }, {
140 /* QCA8327-B from switch QCA8327-BL1A */
141 @@ -2205,12 +2211,12 @@ static struct phy_driver at803x_driver[]
142 .link_change_notify = qca83xx_link_change_notify,
143 .probe = at803x_probe,
144 .flags = PHY_IS_INTERNAL,
145 - .config_init = qca83xx_config_init,
146 + .config_init = qca8327_config_init,
147 .soft_reset = genphy_soft_reset,
148 .get_sset_count = qca83xx_get_sset_count,
149 .get_strings = qca83xx_get_strings,
150 .get_stats = qca83xx_get_stats,
151 - .suspend = qca83xx_suspend,
152 + .suspend = qca8327_suspend,
153 .resume = qca83xx_resume,
154 }, {
155 /* Qualcomm QCA8081 */