Skip to content

Commit ffd034a

Browse files
dangowrtPaolo Abeni
authored andcommitted
net: dsa: mxl-gsw1xx: configure SerDes port polarities
Configure SerDes (port 4) RX and TX polarities using the newly introduced generic properties. The polarities are described at the port level which equals the polarities of the external pins of the chip. Note that the RX lane is inverted internally and the vendor driver simply always sets bit GSW1XX_SGMII_PHY_RX0_CFG2_INVERT unconditionally to end up with the correct (ie. as documented in datasheets) polarity at the external pins. In this sense, PHY_POLARITY_NORMAL denotes normal polarity for pins as documented for the MRQFN 105-pin package (GSW120, GSW125, GSW140, GSW141 and GSW145 all use the same package and have identical pin layouts except for TP port 2 and 3 being N/C on GSW12x): pin B18 (TX0_P) positive signal of the differential SGMII data output pair pin B19 (TX0_M) negative signal of the differential SGMII data output pair pin B20 (RX0_P) positive signal of the differential SGMII data input pair pin B21 (RX0_M) negative signal of the differential SGMII data input pair Signed-off-by: Daniel Golle <daniel@makrotopia.org> Link: https://patch.msgid.link/8bf79b3476e23673fceffbe2bc9d6abc13d132e5.1769916962.git.daniel@makrotopia.org Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 431b777 commit ffd034a

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

drivers/net/dsa/lantiq/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ config NET_DSA_MXL_GSW1XX
1515
tristate "MaxLinear GSW1xx Ethernet switch support"
1616
select NET_DSA_TAG_MXL_GSW1XX
1717
select NET_DSA_LANTIQ_COMMON
18+
select PHY_COMMON_PROPS
1819
help
1920
This enables support for the Intel/MaxLinear GSW1xx family of 1GE
2021
switches.

drivers/net/dsa/lantiq/mxl-gsw1xx.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/module.h>
1616
#include <linux/of_device.h>
1717
#include <linux/of_mdio.h>
18+
#include <linux/phy/phy-common-props.h>
19+
#include <linux/property.h>
1820
#include <linux/regmap.h>
1921
#include <linux/workqueue.h>
2022
#include <net/dsa.h>
@@ -229,11 +231,17 @@ static int gsw1xx_pcs_phy_xaui_write(struct gsw1xx_priv *priv, u16 addr,
229231
1000, 100000);
230232
}
231233

232-
static int gsw1xx_pcs_reset(struct gsw1xx_priv *priv)
234+
static int gsw1xx_pcs_reset(struct gsw1xx_priv *priv, phy_interface_t interface)
233235
{
236+
struct dsa_port *sgmii_port;
237+
unsigned int pol;
234238
int ret;
235239
u16 val;
236240

241+
sgmii_port = dsa_to_port(priv->gswip.ds, GSW1XX_SGMII_PORT);
242+
if (!sgmii_port)
243+
return -EINVAL;
244+
237245
/* Assert and deassert SGMII shell reset */
238246
ret = regmap_set_bits(priv->shell, GSW1XX_SHELL_RST_REQ,
239247
GSW1XX_RST_REQ_SGMII_SHELL);
@@ -260,15 +268,20 @@ static int gsw1xx_pcs_reset(struct gsw1xx_priv *priv)
260268
FIELD_PREP(GSW1XX_SGMII_PHY_RX0_CFG2_FILT_CNT,
261269
GSW1XX_SGMII_PHY_RX0_CFG2_FILT_CNT_DEF);
262270

271+
ret = phy_get_manual_rx_polarity(of_fwnode_handle(sgmii_port->dn),
272+
phy_modes(interface), &pol);
273+
if (ret)
274+
return ret;
275+
263276
/* RX lane seems to be inverted internally, so bit
264277
* GSW1XX_SGMII_PHY_RX0_CFG2_INVERT needs to be set for normal
265-
* (ie. non-inverted) operation.
266-
*
267-
* TODO: Take care of inverted RX pair once generic property is
268-
* available
278+
* (ie. non-inverted) operation matching the chips external pins as
279+
* described in datasheets dated 2023-11-08, ie. pin B20 (RX0_P) being
280+
* the positive signal and pin B21 (RX0_M) being the negative signal of
281+
* the differential input pair.
269282
*/
270-
271-
val |= GSW1XX_SGMII_PHY_RX0_CFG2_INVERT;
283+
if (pol == PHY_POL_NORMAL)
284+
val |= GSW1XX_SGMII_PHY_RX0_CFG2_INVERT;
272285

273286
ret = regmap_write(priv->sgmii, GSW1XX_SGMII_PHY_RX0_CFG2, val);
274287
if (ret < 0)
@@ -277,9 +290,13 @@ static int gsw1xx_pcs_reset(struct gsw1xx_priv *priv)
277290
val = FIELD_PREP(GSW1XX_SGMII_PHY_TX0_CFG3_VBOOST_LEVEL,
278291
GSW1XX_SGMII_PHY_TX0_CFG3_VBOOST_LEVEL_DEF);
279292

280-
/* TODO: Take care of inverted TX pair once generic property is
281-
* available
282-
*/
293+
ret = phy_get_manual_tx_polarity(of_fwnode_handle(sgmii_port->dn),
294+
phy_modes(interface), &pol);
295+
if (ret)
296+
return ret;
297+
298+
if (pol == PHY_POL_INVERT)
299+
val |= GSW1XX_SGMII_PHY_TX0_CFG3_INVERT;
283300

284301
ret = regmap_write(priv->sgmii, GSW1XX_SGMII_PHY_TX0_CFG3, val);
285302
if (ret < 0)
@@ -336,7 +353,7 @@ static int gsw1xx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
336353
priv->tbi_interface = PHY_INTERFACE_MODE_NA;
337354

338355
if (!reconf)
339-
ret = gsw1xx_pcs_reset(priv);
356+
ret = gsw1xx_pcs_reset(priv, interface);
340357

341358
if (ret)
342359
return ret;

0 commit comments

Comments
 (0)