Skip to content

Commit 3082796

Browse files
author
Paolo Abeni
committed
Merge branch 'net-dsa-mxl-gsw1xx-setup-polarities-and-validate-chip'
Daniel Golle says: ==================== net: dsa: mxl-gsw1xx: setup polarities and validate chip Now that common PHY properties make it easy to configure the SerDes RX and TX polarities, use that for the SGMII/1000Base-X/2500Base-X port of the MaxLinear GSW1xx switches. Also, validate hardware in probe() function to make sure the switch is actually present and MDIO communication works properly. ==================== Link: https://patch.msgid.link/cover.1769916962.git.daniel@makrotopia.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2 parents 71e1eab + a046d6f commit 3082796

4 files changed

Lines changed: 68 additions & 12 deletions

File tree

Documentation/devicetree/bindings/net/dsa/lantiq,gswip.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ patternProperties:
105105
patternProperties:
106106
"^(ethernet-)?port@[0-6]$":
107107
$ref: dsa-port.yaml#
108+
allOf:
109+
- $ref: /schemas/phy/phy-common-props.yaml#
108110
unevaluatedProperties: false
109111

110112
properties:
@@ -288,6 +290,7 @@ examples:
288290
289291
- |
290292
#include <dt-bindings/leds/common.h>
293+
#include <dt-bindings/phy/phy.h>
291294
292295
mdio {
293296
#address-cells = <1>;
@@ -320,6 +323,7 @@ examples:
320323
label = "wan";
321324
phy-mode = "1000base-x";
322325
managed = "in-band-status";
326+
tx-polarity = <PHY_POL_INVERT>;
323327
};
324328
325329
port@5 {

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: 54 additions & 12 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;
@@ -671,7 +688,9 @@ static int gsw1xx_probe(struct mdio_device *mdiodev)
671688
{
672689
struct device *dev = &mdiodev->dev;
673690
struct gsw1xx_priv *priv;
674-
u32 version;
691+
u32 version, val;
692+
u8 shellver;
693+
u16 pnum;
675694
int ret;
676695

677696
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -719,6 +738,27 @@ static int gsw1xx_probe(struct mdio_device *mdiodev)
719738
if (IS_ERR(priv->shell))
720739
return PTR_ERR(priv->shell);
721740

741+
ret = regmap_read(priv->shell, GSW1XX_SHELL_MANU_ID, &val);
742+
if (ret < 0)
743+
return ret;
744+
745+
/* validate chip ID */
746+
if (FIELD_GET(GSW1XX_SHELL_MANU_ID_FIX1, val) != 1)
747+
return -ENODEV;
748+
749+
if (FIELD_GET(GSW1XX_SHELL_MANU_ID_MANID, val) !=
750+
GSW1XX_SHELL_MANU_ID_MANID_VAL)
751+
return -ENODEV;
752+
753+
pnum = FIELD_GET(GSW1XX_SHELL_MANU_ID_PNUML, val);
754+
755+
ret = regmap_read(priv->shell, GSW1XX_SHELL_PNUM_ID, &val);
756+
if (ret < 0)
757+
return ret;
758+
759+
pnum |= FIELD_GET(GSW1XX_SHELL_PNUM_ID_PNUMM, val) << 4;
760+
shellver = FIELD_GET(GSW1XX_SHELL_PNUM_ID_VER, val);
761+
722762
ret = gsw1xx_serdes_pcs_init(priv);
723763
if (ret < 0)
724764
return ret;
@@ -739,6 +779,8 @@ static int gsw1xx_probe(struct mdio_device *mdiodev)
739779
if (ret)
740780
return ret;
741781

782+
dev_info(dev, "standalone switch part number 0x%x v1.%u\n", pnum, shellver);
783+
742784
dev_set_drvdata(dev, &priv->gswip);
743785

744786
return 0;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@
110110
#define GSW1XX_SHELL_BASE 0xfa00
111111
#define GSW1XX_SHELL_RST_REQ 0x01
112112
#define GSW1XX_RST_REQ_SGMII_SHELL BIT(5)
113+
#define GSW1XX_SHELL_MANU_ID 0x10
114+
#define GSW1XX_SHELL_MANU_ID_PNUML GENMASK(15, 12)
115+
#define GSW1XX_SHELL_MANU_ID_MANID GENMASK(11, 1)
116+
#define GSW1XX_SHELL_MANU_ID_MANID_VAL 0x389
117+
#define GSW1XX_SHELL_MANU_ID_FIX1 BIT(0)
118+
#define GSW1XX_SHELL_PNUM_ID 0x11
119+
#define GSW1XX_SHELL_PNUM_ID_VER GENMASK(15, 12)
120+
#define GSW1XX_SHELL_PNUM_ID_PNUMM GENMASK(11, 0)
121+
113122
/* RGMII PAD Slew Control Register */
114123
#define GSW1XX_SHELL_RGMII_SLEW_CFG 0x78
115124
#define RGMII_SLEW_CFG_DRV_TXC BIT(2)

0 commit comments

Comments
 (0)