2022-08-29 18:17:39

by Jerry Ray

[permalink] [raw]
Subject: [PATCH 2/2] net: dsa: LAN9303: Add basic support for LAN9354

Adding support for the LAN9354 device by allowing it to use
the LAN9303 DSA driver. These devices have the same underlying
access and control methods and from a feature set point of view
the LAN9354 is a superset of the LAN9303.

The MDIO access method has been tested on a SAMA5D3-EDS board
with a LAN9354 RMII daughter card.

While the SPI access method should also be the same, it has not
been tested and as such is not included at this time.

Signed-off-by: Jerry Ray <[email protected]>
---
drivers/net/dsa/Kconfig | 6 +++---
drivers/net/dsa/lan9303-core.c | 11 ++++++++---
drivers/net/dsa/lan9303_mdio.c | 1 +
3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index d8ae0e8af2a0..07507b4820d7 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -76,7 +76,7 @@ config NET_DSA_SMSC_LAN9303
select NET_DSA_TAG_LAN9303
select REGMAP
help
- This enables support for the SMSC/Microchip LAN9303 3 port ethernet
+ This enables support for the Microchip LAN9303/LAN9354 3 port ethernet
switch chips.

config NET_DSA_SMSC_LAN9303_I2C
@@ -90,11 +90,11 @@ config NET_DSA_SMSC_LAN9303_I2C
for I2C managed mode.

config NET_DSA_SMSC_LAN9303_MDIO
- tristate "SMSC/Microchip LAN9303 3-ports 10/100 ethernet switch in MDIO managed mode"
+ tristate "Microchip LAN9303/LAN9354 3-ports 10/100 ethernet switch in MDIO managed mode"
select NET_DSA_SMSC_LAN9303
depends on VLAN_8021Q || VLAN_8021Q=n
help
- Enable access functions if the SMSC/Microchip LAN9303 is configured
+ Enable access functions if the Microchip LAN9303/LAN9354 is configured
for MDIO managed mode.

config NET_DSA_VITESSE_VSC73XX
diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index 17ae02a56bfe..4ea8c95cc23e 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -22,6 +22,10 @@
*/
#define LAN9303_CHIP_REV 0x14
# define LAN9303_CHIP_ID 0x9303
+# define LAN9352_CHIP_ID 0x9352
+# define LAN9353_CHIP_ID 0x9353
+# define LAN9354_CHIP_ID 0x9354
+# define LAN9355_CHIP_ID 0x9355
#define LAN9303_IRQ_CFG 0x15
# define LAN9303_IRQ_CFG_IRQ_ENABLE BIT(8)
# define LAN9303_IRQ_CFG_IRQ_POL BIT(4)
@@ -867,8 +871,9 @@ static int lan9303_check_device(struct lan9303 *chip)
return ret;
}

- if ((reg >> 16) != LAN9303_CHIP_ID) {
- dev_err(chip->dev, "expecting LAN9303 chip, but found: %X\n",
+ if (((reg >> 16) != LAN9303_CHIP_ID) &&
+ ((reg >> 16) != LAN9354_CHIP_ID)) {
+ dev_err(chip->dev, "unexpected device found: LAN%4.4X\n",
reg >> 16);
return -ENODEV;
}
@@ -884,7 +889,7 @@ static int lan9303_check_device(struct lan9303 *chip)
if (ret)
dev_warn(chip->dev, "failed to disable switching %d\n", ret);

- dev_info(chip->dev, "Found LAN9303 rev. %u\n", reg & 0xffff);
+ dev_info(chip->dev, "Found LAN%4.4X rev. %u\n", (reg >> 16), reg & 0xffff);

ret = lan9303_detect_phy_setup(chip);
if (ret) {
diff --git a/drivers/net/dsa/lan9303_mdio.c b/drivers/net/dsa/lan9303_mdio.c
index bbb7032409ba..d12c55fdc811 100644
--- a/drivers/net/dsa/lan9303_mdio.c
+++ b/drivers/net/dsa/lan9303_mdio.c
@@ -158,6 +158,7 @@ static void lan9303_mdio_shutdown(struct mdio_device *mdiodev)

static const struct of_device_id lan9303_mdio_of_match[] = {
{ .compatible = "smsc,lan9303-mdio" },
+ { .compatible = "microchip,lan9354-mdio" },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, lan9303_mdio_of_match);
--
2.17.1


2022-08-29 19:34:03

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH 2/2] net: dsa: LAN9303: Add basic support for LAN9354

> - if ((reg >> 16) != LAN9303_CHIP_ID) {
> - dev_err(chip->dev, "expecting LAN9303 chip, but found: %X\n",
> + if (((reg >> 16) != LAN9303_CHIP_ID) &&
> + ((reg >> 16) != LAN9354_CHIP_ID)) {
> + dev_err(chip->dev, "unexpected device found: LAN%4.4X\n",
> reg >> 16);
> return -ENODEV;
> }
> @@ -884,7 +889,7 @@ static int lan9303_check_device(struct lan9303 *chip)
> if (ret)
> dev_warn(chip->dev, "failed to disable switching %d\n", ret);
>
> - dev_info(chip->dev, "Found LAN9303 rev. %u\n", reg & 0xffff);
> + dev_info(chip->dev, "Found LAN%4.4X rev. %u\n", (reg >> 16), reg & 0xffff);
>
> ret = lan9303_detect_phy_setup(chip);
> if (ret) {
> diff --git a/drivers/net/dsa/lan9303_mdio.c b/drivers/net/dsa/lan9303_mdio.c
> index bbb7032409ba..d12c55fdc811 100644
> --- a/drivers/net/dsa/lan9303_mdio.c
> +++ b/drivers/net/dsa/lan9303_mdio.c
> @@ -158,6 +158,7 @@ static void lan9303_mdio_shutdown(struct mdio_device *mdiodev)
>
> static const struct of_device_id lan9303_mdio_of_match[] = {
> { .compatible = "smsc,lan9303-mdio" },
> + { .compatible = "microchip,lan9354-mdio" },

Please validate that what you find on the board actually is what the
compatible says it should be. If you don't validate it, there will be
some DT blobs that have the wrong value, but probe fine. But then you
cannot actually make use of the compatible string in the driver to do
something different between the 9303 and the 9354 because some boards
have the wrong compatible....

Andrew

2022-08-29 19:49:13

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH 2/2] net: dsa: LAN9303: Add basic support for LAN9354

> static const struct of_device_id lan9303_mdio_of_match[] = {
> { .compatible = "smsc,lan9303-mdio" },
> + { .compatible = "microchip,lan9354-mdio" },
> { /* sentinel */ },

Please add this compatible to
Documentation/devicetree/bindings/net/dsa/lan9303.txt. Better still,
please convert it to YAML.

Andrew

2022-09-02 20:38:45

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH 2/2] net: dsa: LAN9303: Add basic support for LAN9354

> >Please validate that what you find on the board actually is what the compatible says it should be. If you don't validate it, there will be some DT blobs that have the wrong value, but probe fine. But then you cannot actually make use of the compatible string in the driver to do something different between the 9303 and the 9354 because some boards have the wrong compatible....

Please configure your mail client to stop corrupting emails. My reply
definitely did not have lines this long.

> >
> > Andrew
> >
>

> At this time, the driver is meant to support both devices equally. In the future, I will be adding content that only applies to the LAN9354. That is when I'm planning to add .data to the .compatible entries.

Which makes it even more important to validate the compatible against
what is actually on the board. As i said, in its current state, people
are going to get it wrong, and your .data won't work, since it will be
for a different chip to which is actually on the board.

Andrew

2022-09-02 20:42:47

by Jerry Ray

[permalink] [raw]
Subject: RE: [PATCH 2/2] net: dsa: LAN9303: Add basic support for LAN9354

>> static const struct of_device_id lan9303_mdio_of_match[] = {
>> { .compatible = "smsc,lan9303-mdio" },
>> + { .compatible = "microchip,lan9354-mdio" },
>> { /* sentinel */ },
>
>Please add this compatible to
>Documentation/devicetree/bindings/net/dsa/lan9303.txt. Better still, please convert it to YAML.
>
> Andrew
>

I was planning the conversion to YAML as a separate patch as I didn't want to delay this one.

Jerry.

2022-09-02 20:44:15

by Jerry Ray

[permalink] [raw]
Subject: RE: [PATCH 2/2] net: dsa: LAN9303: Add basic support for LAN9354

>> - if ((reg >> 16) != LAN9303_CHIP_ID) {
>> - dev_err(chip->dev, "expecting LAN9303 chip, but found: %X\n",
>> + if (((reg >> 16) != LAN9303_CHIP_ID) &&
>> + ((reg >> 16) != LAN9354_CHIP_ID)) {
>> + dev_err(chip->dev, "unexpected device found:
>> + LAN%4.4X\n",
>> reg >> 16);
>> return -ENODEV;
>> }
>> @@ -884,7 +889,7 @@ static int lan9303_check_device(struct lan9303 *chip)
>> if (ret)
>> dev_warn(chip->dev, "failed to disable switching %d\n",
>> ret);
>>
>> - dev_info(chip->dev, "Found LAN9303 rev. %u\n", reg & 0xffff);
>> + dev_info(chip->dev, "Found LAN%4.4X rev. %u\n", (reg >> 16), reg
>> + & 0xffff);
>>
>> ret = lan9303_detect_phy_setup(chip);
>> if (ret) {
>> diff --git a/drivers/net/dsa/lan9303_mdio.c
>> b/drivers/net/dsa/lan9303_mdio.c index bbb7032409ba..d12c55fdc811
>> 100644
>> --- a/drivers/net/dsa/lan9303_mdio.c
>> +++ b/drivers/net/dsa/lan9303_mdio.c
>> @@ -158,6 +158,7 @@ static void lan9303_mdio_shutdown(struct
>> mdio_device *mdiodev)
>>
>> static const struct of_device_id lan9303_mdio_of_match[] = {
>> { .compatible = "smsc,lan9303-mdio" },
>> + { .compatible = "microchip,lan9354-mdio" },
>
>Please validate that what you find on the board actually is what the compatible says it should be. If you don't validate it, there will be some DT blobs that have the wrong value, but probe fine. But then you cannot actually make use of the compatible string in the driver to do something different between the 9303 and the 9354 because some boards have the wrong compatible....
>
> Andrew
>

At this time, the driver is meant to support both devices equally. In the future, I will be adding content that only applies to the LAN9354. That is when I'm planning to add .data to the .compatible entries.

Jerry.