[PATCH] net: dsa: lantiq_gswip: Exclude RMII from modes that report 1 GbE

2021-01-07 Thread Aleksander Jan Bajkowski
Exclude RMII from modes that report 1 GbE support. Reduced MII supports
up to 100 MbE.

Fixes: 14fceff ("net: dsa: Add Lantiq / Intel DSA driver for vrx200")
Signed-off-by: Aleksander Jan Bajkowski 
---
 drivers/net/dsa/lantiq_gswip.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 4b36d89bec06..662e68a0e7e6 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1436,11 +1436,12 @@ static void gswip_phylink_validate(struct dsa_switch 
*ds, int port,
phylink_set(mask, Pause);
phylink_set(mask, Asym_Pause);
 
-   /* With the exclusion of MII and Reverse MII, we support Gigabit,
-* including Half duplex
+   /* With the exclusion of MII, Reverse MII and Reduced MII, we
+* support Gigabit, including Half duplex
 */
if (state->interface != PHY_INTERFACE_MODE_MII &&
-   state->interface != PHY_INTERFACE_MODE_REVMII) {
+   state->interface != PHY_INTERFACE_MODE_REVMII &&
+   state->interface != PHY_INTERFACE_MODE_RMII) {
phylink_set(mask, 1000baseT_Full);
phylink_set(mask, 1000baseT_Half);
}
-- 
2.20.1



[PATCH] dt-bindings: mips: lantiq: Document Lantiq Xway PMU bindings

2020-12-31 Thread Aleksander Jan Bajkowski
Document the Lantiq Xway SoC series Power Management Unit (PMU) bindings.

Signed-off-by: Aleksander Jan Bajkowski 
---
 .../bindings/mips/lantiq/lantiq,pmu.yaml  | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mips/lantiq/lantiq,pmu.yaml

diff --git a/Documentation/devicetree/bindings/mips/lantiq/lantiq,pmu.yaml 
b/Documentation/devicetree/bindings/mips/lantiq/lantiq,pmu.yaml
new file mode 100644
index ..4982b458ac12
--- /dev/null
+++ b/Documentation/devicetree/bindings/mips/lantiq/lantiq,pmu.yaml
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mips/lantiq/lantiq,pmu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Lantiq Xway SoC series Power Management Unit (PMU)
+
+maintainers:
+  - John Crispin 
+
+properties:
+  compatible:
+items:
+  - enum:
+  - lantiq,pmu-xway
+
+  reg:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+pmu@102000 {
+compatible = "lantiq,pmu-xway";
+reg = <0x102000 0x1000>;
+};
-- 
2.20.1



[PATCH] dt-bindings: mips: lantiq: Document Lantiq Xway CGU bindings

2021-01-01 Thread Aleksander Jan Bajkowski
Document the Lantiq Xway SoC series Clock Generation Unit (CGU) bindings.

Signed-off-by: Aleksander Jan Bajkowski 
---
 .../bindings/mips/lantiq/lantiq,cgu.yaml  | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mips/lantiq/lantiq,cgu.yaml

diff --git a/Documentation/devicetree/bindings/mips/lantiq/lantiq,cgu.yaml 
b/Documentation/devicetree/bindings/mips/lantiq/lantiq,cgu.yaml
new file mode 100644
index ..d5805725befb
--- /dev/null
+++ b/Documentation/devicetree/bindings/mips/lantiq/lantiq,cgu.yaml
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mips/lantiq/lantiq,cgu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Lantiq Xway SoC series Clock Generation Unit (CGU)
+
+maintainers:
+  - John Crispin 
+
+properties:
+  compatible:
+items:
+  - enum:
+  - lantiq,cgu-xway
+
+  reg:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+cgu@103000 {
+compatible = "lantiq,cgu-xway";
+reg = <0x103000 0x1000>;
+};
-- 
2.20.1



[PATCH] dt-bindings: mips: lantiq: Document Lantiq Xway EBU bindings

2021-01-01 Thread Aleksander Jan Bajkowski
Document the Lantiq Xway SoC series External Bus Unit (EBU) bindings.

Signed-off-by: Aleksander Jan Bajkowski 
---
 .../bindings/mips/lantiq/lantiq,ebu.yaml  | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mips/lantiq/lantiq,ebu.yaml

diff --git a/Documentation/devicetree/bindings/mips/lantiq/lantiq,ebu.yaml 
b/Documentation/devicetree/bindings/mips/lantiq/lantiq,ebu.yaml
new file mode 100644
index ..0fada1f085a9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mips/lantiq/lantiq,ebu.yaml
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mips/lantiq/lantiq,ebu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Lantiq Xway SoC series External Bus Unit (EBU)
+
+maintainers:
+  - John Crispin 
+
+properties:
+  compatible:
+items:
+  - enum:
+  - lantiq,ebu-xway
+
+  reg:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+ebu@105300 {
+compatible = "lantiq,ebu-xway";
+reg = <0x105300 0x100>;
+};
-- 
2.20.1



[PATCH] dt-bindings: mips: lantiq: Document Lantiq Xway DMA bindings

2021-01-03 Thread Aleksander Jan Bajkowski
Document the Lantiq Xway SoC DMA Controller DT bindings.

Signed-off-by: Aleksander Jan Bajkowski 
---
 .../bindings/mips/lantiq/lantiq,dma-xway.yaml | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mips/lantiq/lantiq,dma-xway.yaml

diff --git a/Documentation/devicetree/bindings/mips/lantiq/lantiq,dma-xway.yaml 
b/Documentation/devicetree/bindings/mips/lantiq/lantiq,dma-xway.yaml
new file mode 100644
index ..40130fefa2b4
--- /dev/null
+++ b/Documentation/devicetree/bindings/mips/lantiq/lantiq,dma-xway.yaml
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mips/lantiq/lantiq,dma-xway.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Lantiq Xway SoCs DMA Controller DT bindings
+
+maintainers:
+  - John Crispin 
+
+properties:
+  compatible:
+items:
+  - enum:
+  - lantiq,dma-xway
+
+  reg:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+dma@e104100 {
+compatible = "lantiq,dma-xway";
+reg = <0xe104100 0x800>;
+};
-- 
2.20.1



[PATCH v2 0/2] net: dsa: lantiq: add support for xRX300 and xRX330

2020-12-06 Thread Aleksander Jan Bajkowski
From: Aleksander Jan Bajkowski 

Changed since v1:
* gswip_mii_mask_cfg() can now change port 3 on xRX330
* changed alowed modes on port 0 and 5 for xRX300 and xRX330
* moved common part of phylink validation into gswip_phylink_set_capab()
* verify the compatible string against the hardware

Aleksander Jan Bajkowski (2):
  net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330
  dt-bindings: net: dsa: lantiq, lantiq-gswip: add example for xRX330

 .../bindings/net/dsa/lantiq-gswip.txt | 110 +++-
 drivers/net/dsa/lantiq_gswip.c| 170 +++---
 2 files changed, 250 insertions(+), 30 deletions(-)

-- 
2.20.1



[PATCH v2 2/2] dt-bindings: net: dsa: lantiq, lantiq-gswip: add example for xRX330

2020-12-06 Thread Aleksander Jan Bajkowski
Add compatible string and example for xRX300 and xRX330.

Signed-off-by: Aleksander Jan Bajkowski 
---
 .../bindings/net/dsa/lantiq-gswip.txt | 110 +-
 1 file changed, 109 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt 
b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
index 886cbe8ffb38..7a90a6a1b065 100644
--- a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
+++ b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
@@ -3,7 +3,8 @@ Lantiq GSWIP Ethernet switches
 
 Required properties for GSWIP core:
 
-- compatible   : "lantiq,xrx200-gswip" for the embedded GSWIP in the
+- compatible   : "lantiq,xrx200-gswip", "lantiq,xrx300-gswip" or
+ "lantiq,xrx330-gswip" for the embedded GSWIP in the
  xRX200 SoC
 - reg  : memory range of the GSWIP core registers
: memory range of the GSWIP MDIO registers
@@ -141,3 +142,110 @@ switch@e108000 {
};
};
 };
+
+Ethernet switch on the GRX330 SoC:
+
+switch@e108000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "lantiq,xrx300-gswip";
+   reg = < 0xe108000 0x3100/* switch */
+   0xe10b100 0xd8  /* mdio */
+   0xe10b1d8 0x130 /* mii */
+   >;
+   dsa,member = <0 0>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@1 {
+   reg = <1>;
+   label = "lan1";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@2 {
+   reg = <2>;
+   label = "lan2";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@3 {
+   reg = <3>;
+   label = "lan3";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@4 {
+   reg = <4>;
+   label = "lan4";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@6 {
+   reg = <0x6>;
+   label = "cpu";
+   ethernet = <>;
+   };
+   };
+
+   mdio {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "lantiq,xrx200-mdio";
+   reg = <0>;
+
+   phy1: ethernet-phy@1 {
+   reg = <0x1>;
+   };
+   phy2: ethernet-phy@2 {
+   reg = <0x2>;
+   };
+   phy3: ethernet-phy@3 {
+   reg = <0x3>;
+   };
+   phy4: ethernet-phy@4 {
+   reg = <0x4>;
+   };
+   };
+
+   gphy-fw {
+   compatible = "lantiq,xrx330-gphy-fw", "lantiq,gphy-fw";
+   lantiq,rcu = <>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   gphy@20 {
+   reg = <0x20>;
+
+   resets = < 31 30>;
+   reset-names = "gphy";
+   };
+
+   gphy@68 {
+   reg = <0x68>;
+
+   resets = < 29 28>;
+   reset-names = "gphy";
+   };
+
+   gphy@ac {
+   reg = <0xac>;
+
+   resets = < 28 13>;
+   reset-names = "gphy";
+   };
+
+   gphy@264 {
+   reg = <0x264>;
+
+   resets = < 10 10>;
+   reset-names = "gphy";
+   };
+   };
+};
-- 
2.20.1



[PATCH v2 1/2] net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330

2020-12-06 Thread Aleksander Jan Bajkowski
This patch allows to use all PHYs on GRX300 and GRX330. The ARX300 has 3
and the GRX330 has 4 integrated PHYs connected to different ports compared
to VRX200.

Port configurations:

xRX200:
GMAC0: RGMII/MII/REVMII/RMII port
GMAC1: RGMII/MII/REVMII/RMII port
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX300:
GMAC0: RGMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX330:
GMAC0: RGMII/GMII/RMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII) or GPHY3 (GMII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII/RMII port

Tested on D-Link DWR966 with OpenWRT.

Signed-off-by: Aleksander Jan Bajkowski 
---
 drivers/net/dsa/lantiq_gswip.c | 170 +++--
 1 file changed, 141 insertions(+), 29 deletions(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 09701c17f3f6..4c8f611ed397 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -94,6 +94,7 @@
 /* GSWIP MII Registers */
 #define GSWIP_MII_CFG0 0x00
 #define GSWIP_MII_CFG1 0x02
+#define GSWIP_MII_CFG3 0xc3
 #define GSWIP_MII_CFG5 0x04
 #define  GSWIP_MII_CFG_EN  BIT(14)
 #define  GSWIP_MII_CFG_LDCLKDISBIT(12)
@@ -102,6 +103,7 @@
 #define  GSWIP_MII_CFG_MODE_RMIIP  0x2
 #define  GSWIP_MII_CFG_MODE_RMIIM  0x3
 #define  GSWIP_MII_CFG_MODE_RGMII  0x4
+#define  GSWIP_MII_CFG_MODE_GMII   0x9
 #define  GSWIP_MII_CFG_MODE_MASK   0xf
 #define  GSWIP_MII_CFG_RATE_M2P5   0x00
 #define  GSWIP_MII_CFG_RATE_M250x10
@@ -222,6 +224,7 @@
 struct gswip_hw_info {
int max_ports;
int cpu_port;
+   struct dsa_switch_ops *ops;
 };
 
 struct xway_gphy_match_data {
@@ -392,12 +395,19 @@ static void gswip_mii_mask(struct gswip_priv *priv, u32 
clear, u32 set,
 static void gswip_mii_mask_cfg(struct gswip_priv *priv, u32 clear, u32 set,
   int port)
 {
+   struct device_node *np = priv->ds->dev->of_node;
+
switch (port) {
case 0:
gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG0);
break;
case 1:
-   gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG1);
+   if (of_device_is_compatible(np, "lantiq,xrx200-gswip"))
+   gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG1);
+   break;
+   case 3:
+   if (of_device_is_compatible(np, "lantiq,xrx330-gswip"))
+   gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG3);
break;
case 5:
gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG5);
@@ -1409,12 +1419,40 @@ static int gswip_port_fdb_dump(struct dsa_switch *ds, 
int port,
return 0;
 }
 
-static void gswip_phylink_validate(struct dsa_switch *ds, int port,
-  unsigned long *supported,
-  struct phylink_link_state *state)
+static void gswip_phylink_set_capab(unsigned long *supported, struct 
phylink_link_state *state)
 {
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 
+   /* Allow all the expected bits */
+   phylink_set(mask, Autoneg);
+   phylink_set_port_modes(mask);
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+
+   /* With the exclusion of MII and Reverse MII, we support Gigabit,
+* including Half duplex
+*/
+   if (state->interface != PHY_INTERFACE_MODE_MII &&
+   state->interface != PHY_INTERFACE_MODE_REVMII) {
+   phylink_set(mask, 1000baseT_Full);
+   phylink_set(mask, 1000baseT_Half);
+   }
+
+   phylink_set(mask, 10baseT_Half);
+   phylink_set(mask, 10baseT_Full);
+   phylink_set(mask, 100baseT_Half);
+   phylink_set(mask, 100baseT_Full);
+
+   bitmap_and(supported, supported, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
+   bitmap_and(state->advertising, state->advertising, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
+}
+
+static void gswip_xrx200_phylink_validate(struct dsa_switch *ds, int port,
+ unsigned long *supported,
+ struct phylink_link_state *state)
+{
switch (port) {
case 0:
case 1:
@@ -1441,37 +1479,56 @@ static void gswip_phylink_validate(struct dsa_switch 
*ds, int port,
return;
}
 
-   /* Allow all the expected bits */
-   phylink_set(mask, Autoneg);
-   phylink_set_port_modes(mask);
-   phylink_set(mask, Pause);
-   phylink_set(mask, Asym_Pause);
+   gswip_phylink_set_capab(supported, state);
 
-   /* With the exclusion of MII and Reverse MII, we support Gigabit,
-* in

[PATCH 1/2] net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330

2020-12-03 Thread Aleksander Jan Bajkowski
From: Aleksander Jan Bajkowski 

This patch allows you to use all phs on GRX300 and GRX330. The ARX300 has 3
and the GRX330 has 4 integrated PHYs connected to different ports compared
to VRX200.

Port configurations:

xRX200:
GMAC0: RGMII port
GMAC1: RGMII port
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX300:
GMAC0: RGMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX330:
GMAC0: RGMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY3 (GMII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

Tested on D-Link DWR966 with OpenWRT.

Signed-off-by: Aleksander Jan Bajkowski 
---
 drivers/net/dsa/lantiq_gswip.c | 110 +++--
 1 file changed, 104 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 09701c17f3f6..540cf99ad7fe 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -222,6 +222,7 @@
 struct gswip_hw_info {
int max_ports;
int cpu_port;
+   struct dsa_switch_ops *ops;
 };
 
 struct xway_gphy_match_data {
@@ -1409,9 +1410,9 @@ static int gswip_port_fdb_dump(struct dsa_switch *ds, int 
port,
return 0;
 }
 
-static void gswip_phylink_validate(struct dsa_switch *ds, int port,
-  unsigned long *supported,
-  struct phylink_link_state *state)
+static void gswip_xrx200_phylink_validate(struct dsa_switch *ds, int port,
+ unsigned long *supported,
+ struct phylink_link_state *state)
 {
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 
@@ -1471,7 +1472,70 @@ static void gswip_phylink_validate(struct dsa_switch 
*ds, int port,
bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
phy_modes(state->interface), port);
+}
+
+static void gswip_xrx300_phylink_validate(struct dsa_switch *ds, int port,
+ unsigned long *supported,
+ struct phylink_link_state *state)
+{
+   __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
+
+   switch (port) {
+   case 0:
+   if (!phy_interface_mode_is_rgmii(state->interface) &&
+   state->interface != PHY_INTERFACE_MODE_MII &&
+   state->interface != PHY_INTERFACE_MODE_REVMII &&
+   state->interface != PHY_INTERFACE_MODE_RMII)
+   goto unsupported;
+   break;
+   case 1:
+   case 2:
+   case 3:
+   case 4:
+   if (state->interface != PHY_INTERFACE_MODE_INTERNAL)
+   goto unsupported;
+   break;
+   case 5:
+   if (!phy_interface_mode_is_rgmii(state->interface) &&
+   state->interface != PHY_INTERFACE_MODE_INTERNAL)
+   goto unsupported;
+   break;
+   default:
+   bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
+   dev_err(ds->dev, "Unsupported port: %i\n", port);
+   return;
+   }
+
+   /* Allow all the expected bits */
+   phylink_set(mask, Autoneg);
+   phylink_set_port_modes(mask);
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+
+   /* With the exclusion of MII and Reverse MII, we support Gigabit,
+* including Half duplex
+*/
+   if (state->interface != PHY_INTERFACE_MODE_MII &&
+   state->interface != PHY_INTERFACE_MODE_REVMII) {
+   phylink_set(mask, 1000baseT_Full);
+   phylink_set(mask, 1000baseT_Half);
+   }
+
+   phylink_set(mask, 10baseT_Half);
+   phylink_set(mask, 10baseT_Full);
+   phylink_set(mask, 100baseT_Half);
+   phylink_set(mask, 100baseT_Full);
+
+   bitmap_and(supported, supported, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
+   bitmap_and(state->advertising, state->advertising, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
return;
+
+unsupported:
+   bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
+   dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
+   phy_modes(state->interface), port);
 }
 
 static void gswip_phylink_mac_config(struct dsa_switch *ds, int port,
@@ -1614,7 +1678,7 @@ static int gswip_get_sset_count(struct dsa_switch *ds, 
int port, int sset)
return ARRAY_SIZE(gswip_rmon_cnt);
 }
 
-static const struct dsa_switch_ops gswip_switch_ops = {
+static const struct dsa_switch_ops gswip_xrx200_switch_ops = {
.get_tag_protocol   = gswip_get_tag_protocol,
 

[PATCH 2/2] dt-bindings: net: dsa: lantiq, lantiq-gswip: add example for xRX330

2020-12-03 Thread Aleksander Jan Bajkowski
From: Aleksander Jan Bajkowski 

Add compatible string and example for xRX300 and xRX330.

Signed-off-by: Aleksander Jan Bajkowski 
---
 .../bindings/net/dsa/lantiq-gswip.txt | 110 +-
 1 file changed, 109 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt 
b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
index 886cbe8ffb38..7a90a6a1b065 100644
--- a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
+++ b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
@@ -3,7 +3,8 @@ Lantiq GSWIP Ethernet switches
 
 Required properties for GSWIP core:
 
-- compatible   : "lantiq,xrx200-gswip" for the embedded GSWIP in the
+- compatible   : "lantiq,xrx200-gswip", "lantiq,xrx300-gswip" or
+ "lantiq,xrx330-gswip" for the embedded GSWIP in the
  xRX200 SoC
 - reg  : memory range of the GSWIP core registers
: memory range of the GSWIP MDIO registers
@@ -141,3 +142,110 @@ switch@e108000 {
};
};
 };
+
+Ethernet switch on the GRX330 SoC:
+
+switch@e108000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "lantiq,xrx300-gswip";
+   reg = < 0xe108000 0x3100/* switch */
+   0xe10b100 0xd8  /* mdio */
+   0xe10b1d8 0x130 /* mii */
+   >;
+   dsa,member = <0 0>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@1 {
+   reg = <1>;
+   label = "lan1";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@2 {
+   reg = <2>;
+   label = "lan2";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@3 {
+   reg = <3>;
+   label = "lan3";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@4 {
+   reg = <4>;
+   label = "lan4";
+   phy-mode = "internal";
+   phy-handle = <>;
+   };
+
+   port@6 {
+   reg = <0x6>;
+   label = "cpu";
+   ethernet = <>;
+   };
+   };
+
+   mdio {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "lantiq,xrx200-mdio";
+   reg = <0>;
+
+   phy1: ethernet-phy@1 {
+   reg = <0x1>;
+   };
+   phy2: ethernet-phy@2 {
+   reg = <0x2>;
+   };
+   phy3: ethernet-phy@3 {
+   reg = <0x3>;
+   };
+   phy4: ethernet-phy@4 {
+   reg = <0x4>;
+   };
+   };
+
+   gphy-fw {
+   compatible = "lantiq,xrx330-gphy-fw", "lantiq,gphy-fw";
+   lantiq,rcu = <>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   gphy@20 {
+   reg = <0x20>;
+
+   resets = < 31 30>;
+   reset-names = "gphy";
+   };
+
+   gphy@68 {
+   reg = <0x68>;
+
+   resets = < 29 28>;
+   reset-names = "gphy";
+   };
+
+   gphy@ac {
+   reg = <0xac>;
+
+   resets = < 28 13>;
+   reset-names = "gphy";
+   };
+
+   gphy@264 {
+   reg = <0x264>;
+
+   resets = < 10 10>;
+   reset-names = "gphy";
+   };
+   };
+};
-- 
2.20.1



[PATCH] gpio: stp-xway: automatically drive GPHY leds on ar10 and grx390

2020-08-14 Thread Aleksander Jan Bajkowski
Ar10 (xr300) has 3 and grx390 (xrx330) has 4 built-in GPHY. PHY LEDs are
connected via STP. STP is a peripheral controller used to drive external
shift register cascades. The hardware is able to allow the GPHY to drive
some GPIO of the cascade automatically.This patch allows for this on ar10
and grx390.

Tested on D-Link DWR-966 with OpenWRT.

Signed-off-by: Aleksander Jan Bajkowski 
---
 drivers/gpio/gpio-stp-xway.c | 54 
 1 file changed, 48 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c
index 9e23a5ae8108..0ce1543426a4 100644
--- a/drivers/gpio/gpio-stp-xway.c
+++ b/drivers/gpio/gpio-stp-xway.c
@@ -41,7 +41,10 @@
 #define XWAY_STP_4HZ   BIT(23)
 #define XWAY_STP_8HZ   BIT(24)
 #define XWAY_STP_10HZ  (BIT(24) | BIT(23))
-#define XWAY_STP_SPEED_MASK(0xf << 23)
+#define XWAY_STP_SPEED_MASK(BIT(23) | BIT(24) | BIT(25) | BIT(26) | 
BIT(27))
+
+#define XWAY_STP_FPIS_VALUEBIT(21)
+#define XWAY_STP_FPIS_MASK (BIT(20) | BIT(21))
 
 /* clock source for automatic update */
 #define XWAY_STP_UPD_FPI   BIT(31)
@@ -54,7 +57,9 @@
 /* 2 groups of 3 bits can be driven by the phys */
 #define XWAY_STP_PHY_MASK  0x7
 #define XWAY_STP_PHY1_SHIFT27
-#define XWAY_STP_PHY2_SHIFT15
+#define XWAY_STP_PHY2_SHIFT3
+#define XWAY_STP_PHY3_SHIFT6
+#define XWAY_STP_PHY4_SHIFT15
 
 /* STP has 3 groups of 8 bits */
 #define XWAY_STP_GROUP0BIT(0)
@@ -80,6 +85,8 @@ struct xway_stp {
u8 dsl; /* the 2 LSBs can be driven by the dsl core */
u8 phy1;/* 3 bits can be driven by phy1 */
u8 phy2;/* 3 bits can be driven by phy2 */
+   u8 phy3;/* 3 bits can be driven by phy3 */
+   u8 phy4;/* 3 bits can be driven by phy4 */
u8 reserved;/* mask out the hw driven bits in gpio_request */
 };
 
@@ -114,7 +121,8 @@ static void xway_stp_set(struct gpio_chip *gc, unsigned 
gpio, int val)
else
chip->shadow &= ~BIT(gpio);
xway_stp_w32(chip->virt, chip->shadow, XWAY_STP_CPU0);
-   xway_stp_w32_mask(chip->virt, 0, XWAY_STP_CON_SWU, XWAY_STP_CON0);
+   if (!chip->reserved)
+   xway_stp_w32_mask(chip->virt, 0, XWAY_STP_CON_SWU, 
XWAY_STP_CON0);
 }
 
 /**
@@ -188,16 +196,37 @@ static void xway_stp_hw_init(struct xway_stp *chip)
chip->phy2 << XWAY_STP_PHY2_SHIFT,
XWAY_STP_CON1);
 
+   if (of_machine_is_compatible("lantiq,grx390")
+   || of_machine_is_compatible("lantiq,ar10")) {
+   xway_stp_w32_mask(chip->virt,
+   XWAY_STP_PHY_MASK << XWAY_STP_PHY3_SHIFT,
+   chip->phy3 << XWAY_STP_PHY3_SHIFT,
+   XWAY_STP_CON1);
+   }
+
+   if (of_machine_is_compatible("lantiq,grx390")) {
+   xway_stp_w32_mask(chip->virt,
+   XWAY_STP_PHY_MASK << XWAY_STP_PHY4_SHIFT,
+   chip->phy4 << XWAY_STP_PHY4_SHIFT,
+   XWAY_STP_CON1);
+   }
+
/* mask out the hw driven bits in gpio_request */
-   chip->reserved = (chip->phy2 << 5) | (chip->phy1 << 2) | chip->dsl;
+   chip->reserved = (chip->phy4 << 11) | (chip->phy3 << 8) | (chip->phy2 
<< 5)
+   | (chip->phy1 << 2) | chip->dsl;
 
/*
 * if we have pins that are driven by hw, we need to tell the stp what
 * clock to use as a timer.
 */
-   if (chip->reserved)
+   if (chip->reserved) {
xway_stp_w32_mask(chip->virt, XWAY_STP_UPD_MASK,
XWAY_STP_UPD_FPI, XWAY_STP_CON1);
+   xway_stp_w32_mask(chip->virt, XWAY_STP_SPEED_MASK,
+   XWAY_STP_10HZ, XWAY_STP_CON1);
+   xway_stp_w32_mask(chip->virt, XWAY_STP_FPIS_MASK,
+   XWAY_STP_FPIS_VALUE, XWAY_STP_CON1);
+   }
 }
 
 static int xway_stp_probe(struct platform_device *pdev)
@@ -242,13 +271,26 @@ static int xway_stp_probe(struct platform_device *pdev)
/* find out which gpios are controlled by the phys */
if (of_machine_is_compatible("lantiq,ar9") ||
of_machine_is_compatible("lantiq,gr9") ||
-   of_machine_is_compatible("lantiq,vr9")) {
+   of_machine_is_compatible("lantiq,vr9") ||
+   of_machine_is_compatible("lantiq,ar10") ||
+   of_machine_is_compatible("lantiq,grx390")) {
if (!of_property_read_u32(pdev->dev.of_node, "lantiq,phy1", 
))

[PATCH v4 1/3] net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330

2021-03-22 Thread Aleksander Jan Bajkowski
This patch allows to use all PHYs on GRX300 and GRX330. The ARX300
has 3 and the GRX330 has 4 integrated PHYs connected to different
ports compared to VRX200. Each integrated PHY can work as single
Gigabit Ethernet PHY (GMII) or as double Fast Ethernet PHY (MII).

Allowed port configurations:

xRX200:
GMAC0: RGMII, MII, REVMII or RMII port
GMAC1: RGMII, MII, REVMII or RMII port
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX300:
GMAC0: RGMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX330:
GMAC0: RGMII, GMII or RMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII) or GPHY3 (GMII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII), RGMII or RMII port

Tested on D-Link DWR966 (xRX330) with OpenWRT.

Signed-off-by: Aleksander Jan Bajkowski 
Acked-by: Hauke Mehrtens 
---
 drivers/net/dsa/lantiq_gswip.c | 142 ++---
 1 file changed, 113 insertions(+), 29 deletions(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 52e865a3912c..4cab5cd26928 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Lantiq / Intel GSWIP switch driver for VRX200 SoCs
+ * Lantiq / Intel GSWIP switch driver for VRX200, xRX300 and xRX330 SoCs
  *
  * Copyright (C) 2010 Lantiq Deutschland
  * Copyright (C) 2012 John Crispin 
@@ -100,6 +100,7 @@
 #define  GSWIP_MII_CFG_MODE_RMIIP  0x2
 #define  GSWIP_MII_CFG_MODE_RMIIM  0x3
 #define  GSWIP_MII_CFG_MODE_RGMII  0x4
+#define  GSWIP_MII_CFG_MODE_GMII   0x9
 #define  GSWIP_MII_CFG_MODE_MASK   0xf
 #define  GSWIP_MII_CFG_RATE_M2P5   0x00
 #define  GSWIP_MII_CFG_RATE_M250x10
@@ -220,6 +221,7 @@
 struct gswip_hw_info {
int max_ports;
int cpu_port;
+   const struct dsa_switch_ops *ops;
 };
 
 struct xway_gphy_match_data {
@@ -1384,12 +1386,42 @@ static int gswip_port_fdb_dump(struct dsa_switch *ds, 
int port,
return 0;
 }
 
-static void gswip_phylink_validate(struct dsa_switch *ds, int port,
-  unsigned long *supported,
-  struct phylink_link_state *state)
+static void gswip_phylink_set_capab(unsigned long *supported,
+   struct phylink_link_state *state)
 {
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 
+   /* Allow all the expected bits */
+   phylink_set(mask, Autoneg);
+   phylink_set_port_modes(mask);
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+
+   /* With the exclusion of MII, Reverse MII and Reduced MII, we
+* support Gigabit, including Half duplex
+*/
+   if (state->interface != PHY_INTERFACE_MODE_MII &&
+   state->interface != PHY_INTERFACE_MODE_REVMII &&
+   state->interface != PHY_INTERFACE_MODE_RMII) {
+   phylink_set(mask, 1000baseT_Full);
+   phylink_set(mask, 1000baseT_Half);
+   }
+
+   phylink_set(mask, 10baseT_Half);
+   phylink_set(mask, 10baseT_Full);
+   phylink_set(mask, 100baseT_Half);
+   phylink_set(mask, 100baseT_Full);
+
+   bitmap_and(supported, supported, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
+   bitmap_and(state->advertising, state->advertising, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
+}
+
+static void gswip_xrx200_phylink_validate(struct dsa_switch *ds, int port,
+ unsigned long *supported,
+ struct phylink_link_state *state)
+{
switch (port) {
case 0:
case 1:
@@ -1416,38 +1448,54 @@ static void gswip_phylink_validate(struct dsa_switch 
*ds, int port,
return;
}
 
-   /* Allow all the expected bits */
-   phylink_set(mask, Autoneg);
-   phylink_set_port_modes(mask);
-   phylink_set(mask, Pause);
-   phylink_set(mask, Asym_Pause);
+   gswip_phylink_set_capab(supported, state);
 
-   /* With the exclusion of MII, Reverse MII and Reduced MII, we
-* support Gigabit, including Half duplex
-*/
-   if (state->interface != PHY_INTERFACE_MODE_MII &&
-   state->interface != PHY_INTERFACE_MODE_REVMII &&
-   state->interface != PHY_INTERFACE_MODE_RMII) {
-   phylink_set(mask, 1000baseT_Full);
-   phylink_set(mask, 1000baseT_Half);
+   return;
+
+unsupported:
+   bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
+   dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
+   phy_modes(state->interface), port);
+}
+
+static void gswip_xrx300_phylink_validate(struct dsa_switch *ds, int port,
+ unsigned long *suppor

[PATCH v4 3/3] dt-bindings: net: dsa: lantiq: add xRx300 and xRX330 switch bindings

2021-03-22 Thread Aleksander Jan Bajkowski
Add compatible string for xRX300 and xRX330 SoCs.

Signed-off-by: Aleksander Jan Bajkowski 
---
 Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt 
b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
index 886cbe8ffb38..e3829d3e480e 100644
--- a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
+++ b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
@@ -5,6 +5,10 @@ Required properties for GSWIP core:
 
 - compatible   : "lantiq,xrx200-gswip" for the embedded GSWIP in the
  xRX200 SoC
+ "lantiq,xrx300-gswip" for the embedded GSWIP in the
+ xRX300 SoC
+ "lantiq,xrx330-gswip" for the embedded GSWIP in the
+ xRX330 SoC
 - reg  : memory range of the GSWIP core registers
: memory range of the GSWIP MDIO registers
: memory range of the GSWIP MII registers
-- 
2.20.1



[PATCH v4 0/3] net: dsa: lantiq: add support for xRX300 and xRX330

2021-03-22 Thread Aleksander Jan Bajkowski
Changed since v3:
* fixed last compilation warning

Changed since v2:
* fixed compilation warnings
* removed example bindings for xrx330
* patches has been refactored due to upstream changes

Changed since v1:
* gswip_mii_mask_cfg() can now change port 3 on xRX330
* changed alowed modes on port 0 and 5 for xRX300 and xRX330
* moved common part of phylink validation into gswip_phylink_set_capab()
* verify the compatible string against the hardware

Aleksander Jan Bajkowski (3):
  net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330
  net: dsa: lantiq: verify compatible strings against hardware
  dt-bindings: net: dsa: lantiq: add xRx300 and xRX330 switch bindings

 .../bindings/net/dsa/lantiq-gswip.txt |   4 +
 drivers/net/dsa/lantiq_gswip.c| 162 ++
 2 files changed, 136 insertions(+), 30 deletions(-)

-- 
2.20.1



[PATCH v4 2/3] net: dsa: lantiq: verify compatible strings against hardware

2021-03-22 Thread Aleksander Jan Bajkowski
Verify compatible string against hardware.

Signed-off-by: Aleksander Jan Bajkowski 
Acked-by: Hauke Mehrtens 
---
 drivers/net/dsa/lantiq_gswip.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 4cab5cd26928..26d0e3bb5dea 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1907,7 +1907,7 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
 static int gswip_probe(struct platform_device *pdev)
 {
struct gswip_priv *priv;
-   struct device_node *mdio_np, *gphy_fw_np;
+   struct device_node *np, *mdio_np, *gphy_fw_np;
struct device *dev = >dev;
int err;
int i;
@@ -1944,6 +1944,24 @@ static int gswip_probe(struct platform_device *pdev)
priv->dev = dev;
version = gswip_switch_r(priv, GSWIP_VERSION);
 
+   np = dev->of_node;
+   switch (version) {
+   case GSWIP_VERSION_2_0:
+   case GSWIP_VERSION_2_1:
+   if (!of_device_is_compatible(np, "lantiq,xrx200-gswip"))
+   return -EINVAL;
+   break;
+   case GSWIP_VERSION_2_2:
+   case GSWIP_VERSION_2_2_ETC:
+   if (!of_device_is_compatible(np, "lantiq,xrx300-gswip") &&
+   !of_device_is_compatible(np, "lantiq,xrx330-gswip"))
+   return -EINVAL;
+   break;
+   default:
+   dev_err(dev, "unknown GSWIP version: 0x%x", version);
+   return -ENOENT;
+   }
+
/* bring up the mdio bus */
gphy_fw_np = of_get_compatible_child(dev->of_node, "lantiq,gphy-fw");
if (gphy_fw_np) {
-- 
2.20.1



[PATCH v3 1/3] net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330

2021-03-21 Thread Aleksander Jan Bajkowski
This patch allows to use all PHYs on GRX300 and GRX330. The ARX300
has 3 and the GRX330 has 4 integrated PHYs connected to different
ports compared to VRX200. Each integrated PHY can work as single
Gigabit Ethernet PHY (GMII) or as double Fast Ethernet PHY (MII).

Allowed port configurations:

xRX200:
GMAC0: RGMII, MII, REVMII or RMII port
GMAC1: RGMII, MII, REVMII or RMII port
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX300:
GMAC0: RGMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII) or RGMII port

xRX330:
GMAC0: RGMII, GMII or RMII port
GMAC1: GPHY2 (GMII)
GMAC2: GPHY0 (GMII)
GMAC3: GPHY0 (MII) or GPHY3 (GMII)
GMAC4: GPHY1 (GMII)
GMAC5: GPHY1 (MII), RGMII or RMII port

Tested on D-Link DWR966 (xRX330) with OpenWRT.

Signed-off-by: Aleksander Jan Bajkowski 
---
 drivers/net/dsa/lantiq_gswip.c | 144 ++---
 1 file changed, 114 insertions(+), 30 deletions(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 52e865a3912c..7149b9fcb16a 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Lantiq / Intel GSWIP switch driver for VRX200 SoCs
+ * Lantiq / Intel GSWIP switch driver for VRX200, xRX300 and xRX330 SoCs
  *
  * Copyright (C) 2010 Lantiq Deutschland
  * Copyright (C) 2012 John Crispin 
@@ -100,6 +100,7 @@
 #define  GSWIP_MII_CFG_MODE_RMIIP  0x2
 #define  GSWIP_MII_CFG_MODE_RMIIM  0x3
 #define  GSWIP_MII_CFG_MODE_RGMII  0x4
+#define  GSWIP_MII_CFG_MODE_GMII   0x9
 #define  GSWIP_MII_CFG_MODE_MASK   0xf
 #define  GSWIP_MII_CFG_RATE_M2P5   0x00
 #define  GSWIP_MII_CFG_RATE_M250x10
@@ -220,6 +221,7 @@
 struct gswip_hw_info {
int max_ports;
int cpu_port;
+   struct dsa_switch_ops *ops;
 };
 
 struct xway_gphy_match_data {
@@ -1384,12 +1386,42 @@ static int gswip_port_fdb_dump(struct dsa_switch *ds, 
int port,
return 0;
 }
 
-static void gswip_phylink_validate(struct dsa_switch *ds, int port,
-  unsigned long *supported,
-  struct phylink_link_state *state)
+static void gswip_phylink_set_capab(unsigned long *supported,
+   struct phylink_link_state *state)
 {
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 
+   /* Allow all the expected bits */
+   phylink_set(mask, Autoneg);
+   phylink_set_port_modes(mask);
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+
+   /* With the exclusion of MII, Reverse MII and Reduced MII, we
+* support Gigabit, including Half duplex
+*/
+   if (state->interface != PHY_INTERFACE_MODE_MII &&
+   state->interface != PHY_INTERFACE_MODE_REVMII &&
+   state->interface != PHY_INTERFACE_MODE_RMII) {
+   phylink_set(mask, 1000baseT_Full);
+   phylink_set(mask, 1000baseT_Half);
+   }
+
+   phylink_set(mask, 10baseT_Half);
+   phylink_set(mask, 10baseT_Full);
+   phylink_set(mask, 100baseT_Half);
+   phylink_set(mask, 100baseT_Full);
+
+   bitmap_and(supported, supported, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
+   bitmap_and(state->advertising, state->advertising, mask,
+  __ETHTOOL_LINK_MODE_MASK_NBITS);
+}
+
+static void gswip_xrx200_phylink_validate(struct dsa_switch *ds, int port,
+ unsigned long *supported,
+ struct phylink_link_state *state)
+{
switch (port) {
case 0:
case 1:
@@ -1416,38 +1448,54 @@ static void gswip_phylink_validate(struct dsa_switch 
*ds, int port,
return;
}
 
-   /* Allow all the expected bits */
-   phylink_set(mask, Autoneg);
-   phylink_set_port_modes(mask);
-   phylink_set(mask, Pause);
-   phylink_set(mask, Asym_Pause);
+   gswip_phylink_set_capab(supported, state);
 
-   /* With the exclusion of MII, Reverse MII and Reduced MII, we
-* support Gigabit, including Half duplex
-*/
-   if (state->interface != PHY_INTERFACE_MODE_MII &&
-   state->interface != PHY_INTERFACE_MODE_REVMII &&
-   state->interface != PHY_INTERFACE_MODE_RMII) {
-   phylink_set(mask, 1000baseT_Full);
-   phylink_set(mask, 1000baseT_Half);
+   return;
+
+unsupported:
+   bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
+   dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
+   phy_modes(state->interface), port);
+}
+
+static void gswip_xrx300_phylink_validate(struct dsa_switch *ds, int port,
+ unsigned long *supported,
+  

[PATCH v3 0/3] net: dsa: lantiq: add support for xRX300 and xRX330

2021-03-21 Thread Aleksander Jan Bajkowski
From: Aleksander Jan Bajkowski 

Changed since v2:
* fixed compilation warnings
* removed example bindings for xrx330
* patches has been refactored due to upstream changes

Changed since v1:
* gswip_mii_mask_cfg() can now change port 3 on xRX330
* changed alowed modes on port 0 and 5 for xRX300 and xRX330
* moved common part of phylink validation into gswip_phylink_set_capab()
* verify the compatible string against the hardware

Aleksander Jan Bajkowski (3):
  net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330
  net: dsa: lantiq: verify compatible strings against hardware
  dt-bindings: net: dsa: lantiq: add xRx300 and xRX330 switch bindings

 .../bindings/net/dsa/lantiq-gswip.txt |   4 +
 drivers/net/dsa/lantiq_gswip.c| 164 ++
 2 files changed, 137 insertions(+), 31 deletions(-)

-- 
2.20.1



[PATCH v3 3/3] dt-bindings: net: dsa: lantiq: add xRx300 and xRX330 switch bindings

2021-03-21 Thread Aleksander Jan Bajkowski
Add compatible string for xRX300 and xRX330 SoCs.

Signed-off-by: Aleksander Jan Bajkowski 
---
 Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt 
b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
index 886cbe8ffb38..e3829d3e480e 100644
--- a/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
+++ b/Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt
@@ -5,6 +5,10 @@ Required properties for GSWIP core:
 
 - compatible   : "lantiq,xrx200-gswip" for the embedded GSWIP in the
  xRX200 SoC
+ "lantiq,xrx300-gswip" for the embedded GSWIP in the
+ xRX300 SoC
+ "lantiq,xrx330-gswip" for the embedded GSWIP in the
+ xRX330 SoC
 - reg  : memory range of the GSWIP core registers
: memory range of the GSWIP MDIO registers
: memory range of the GSWIP MII registers
-- 
2.20.1



[PATCH v3 2/3] net: dsa: lantiq: verify compatible strings against hardware

2021-03-21 Thread Aleksander Jan Bajkowski
Verify compatible string against hardware.

Signed-off-by: Aleksander Jan Bajkowski 
---
 drivers/net/dsa/lantiq_gswip.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 7149b9fcb16a..31798a7fc2cc 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1907,7 +1907,7 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
 static int gswip_probe(struct platform_device *pdev)
 {
struct gswip_priv *priv;
-   struct device_node *mdio_np, *gphy_fw_np;
+   struct device_node *np, *mdio_np, *gphy_fw_np;
struct device *dev = >dev;
int err;
int i;
@@ -1944,6 +1944,24 @@ static int gswip_probe(struct platform_device *pdev)
priv->dev = dev;
version = gswip_switch_r(priv, GSWIP_VERSION);
 
+   np = dev->of_node;
+   switch (version) {
+   case GSWIP_VERSION_2_0:
+   case GSWIP_VERSION_2_1:
+   if (!of_device_is_compatible(np, "lantiq,xrx200-gswip"))
+   return -EINVAL;
+   break;
+   case GSWIP_VERSION_2_2:
+   case GSWIP_VERSION_2_2_ETC:
+   if (!of_device_is_compatible(np, "lantiq,xrx300-gswip") &&
+   !of_device_is_compatible(np, "lantiq,xrx330-gswip"))
+   return -EINVAL;
+   break;
+   default:
+   dev_err(dev, "unknown GSWIP version: 0x%x", version);
+   return -ENOENT;
+   }
+
/* bring up the mdio bus */
gphy_fw_np = of_get_compatible_child(dev->of_node, "lantiq,gphy-fw");
if (gphy_fw_np) {
-- 
2.20.1