linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY
@ 2018-10-18 19:06 Yuiko Oshino
  2018-10-18 19:06 ` [PATCH v3 net-next 1/2] net: phy: micrel: add Microchip KSZ9131 initial driver Yuiko Oshino
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yuiko Oshino @ 2018-10-18 19:06 UTC (permalink / raw)
  To: davem, robh+dt, devicetree, f.fainelli, andrew
  Cc: linux-kernel, mark.rutland, m.felsch, Markus.Niebel, netdev,
	UNGLinuxDriver


This is the initial driver for Microchip KSZ9131 10/100/1000 Ethernet PHY

v3:
- KSZ9131 uses picosecond units for values of devicetree properties.
- rewrite micrel.c and micrel-ksz90x1.txt to use the picosecond values.
v2:
- Creating a series from two related patches.

Yuiko Oshino (2):
  net: phy: micrel: add Microchip KSZ9131 initial driver
  dt-bindings: net: add support for Microchip KSZ9131

 .../devicetree/bindings/net/micrel-ksz90x1.txt     |  28 ++++-
 drivers/net/phy/micrel.c                           | 130 ++++++++++++++++++++-
 include/linux/micrel_phy.h                         |   1 +
 3 files changed, 157 insertions(+), 2 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 net-next 1/2] net: phy: micrel: add Microchip KSZ9131 initial driver
  2018-10-18 19:06 [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY Yuiko Oshino
@ 2018-10-18 19:06 ` Yuiko Oshino
  2018-10-18 19:06 ` [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131 Yuiko Oshino
  2018-10-20  0:02 ` [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: Yuiko Oshino @ 2018-10-18 19:06 UTC (permalink / raw)
  To: davem, robh+dt, devicetree, f.fainelli, andrew
  Cc: linux-kernel, mark.rutland, m.felsch, Markus.Niebel, netdev,
	UNGLinuxDriver

Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY

Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>
---
 drivers/net/phy/micrel.c   | 130 ++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/micrel_phy.h |   1 +
 2 files changed, 130 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 3db06b4..270ea16 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -14,7 +14,7 @@
  * option) any later version.
  *
  * Support : Micrel Phys:
- *		Giga phys: ksz9021, ksz9031
+ *		Giga phys: ksz9021, ksz9031, ksz9131
  *		100/10 Phys : ksz8001, ksz8721, ksz8737, ksz8041
  *			   ksz8021, ksz8031, ksz8051,
  *			   ksz8081, ksz8091,
@@ -609,6 +609,116 @@ static int ksz9031_config_init(struct phy_device *phydev)
 	return result;
 }
 
+#define KSZ9131_SKEW_5BIT_MAX	2400
+#define KSZ9131_SKEW_4BIT_MAX	800
+#define KSZ9131_OFFSET		700
+#define KSZ9131_STEP		100
+
+static int ksz9131_of_load_skew_values(struct phy_device *phydev,
+				       struct device_node *of_node,
+				       u16 reg, size_t field_sz,
+				       char *field[], u8 numfields)
+{
+	int val[4] = {-(1 + KSZ9131_OFFSET), -(2 + KSZ9131_OFFSET),
+		      -(3 + KSZ9131_OFFSET), -(4 + KSZ9131_OFFSET)};
+	int skewval, skewmax = 0;
+	int matches = 0;
+	u16 maxval;
+	u16 newval;
+	u16 mask;
+	int i;
+
+	/* psec properties in dts should mean x pico seconds */
+	if (field_sz == 5)
+		skewmax = KSZ9131_SKEW_5BIT_MAX;
+	else
+		skewmax = KSZ9131_SKEW_4BIT_MAX;
+
+	for (i = 0; i < numfields; i++)
+		if (!of_property_read_s32(of_node, field[i], &skewval)) {
+			if (skewval < -KSZ9131_OFFSET)
+				skewval = -KSZ9131_OFFSET;
+			else if (skewval > skewmax)
+				skewval = skewmax;
+
+			val[i] = skewval + KSZ9131_OFFSET;
+			matches++;
+		}
+
+	if (!matches)
+		return 0;
+
+	if (matches < numfields)
+		newval = ksz9031_extended_read(phydev, OP_DATA, 2, reg);
+	else
+		newval = 0;
+
+	maxval = (field_sz == 4) ? 0xf : 0x1f;
+	for (i = 0; i < numfields; i++)
+		if (val[i] != -(i + 1 + KSZ9131_OFFSET)) {
+			mask = 0xffff;
+			mask ^= maxval << (field_sz * i);
+			newval = (newval & mask) |
+				(((val[i] / KSZ9131_STEP) & maxval)
+					<< (field_sz * i));
+		}
+
+	return ksz9031_extended_write(phydev, OP_DATA, 2, reg, newval);
+}
+
+static int ksz9131_config_init(struct phy_device *phydev)
+{
+	const struct device *dev = &phydev->mdio.dev;
+	struct device_node *of_node = dev->of_node;
+	char *clk_skews[2] = {"rxc-skew-psec", "txc-skew-psec"};
+	char *rx_data_skews[4] = {
+		"rxd0-skew-psec", "rxd1-skew-psec",
+		"rxd2-skew-psec", "rxd3-skew-psec"
+	};
+	char *tx_data_skews[4] = {
+		"txd0-skew-psec", "txd1-skew-psec",
+		"txd2-skew-psec", "txd3-skew-psec"
+	};
+	char *control_skews[2] = {"txen-skew-psec", "rxdv-skew-psec"};
+	const struct device *dev_walker;
+	int ret;
+
+	dev_walker = &phydev->mdio.dev;
+	do {
+		of_node = dev_walker->of_node;
+		dev_walker = dev_walker->parent;
+	} while (!of_node && dev_walker);
+
+	if (!of_node)
+		return 0;
+
+	ret = ksz9131_of_load_skew_values(phydev, of_node,
+					  MII_KSZ9031RN_CLK_PAD_SKEW, 5,
+					  clk_skews, 2);
+	if (ret < 0)
+		return ret;
+
+	ret = ksz9131_of_load_skew_values(phydev, of_node,
+					  MII_KSZ9031RN_CONTROL_PAD_SKEW, 4,
+					  control_skews, 2);
+	if (ret < 0)
+		return ret;
+
+	ret = ksz9131_of_load_skew_values(phydev, of_node,
+					  MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4,
+					  rx_data_skews, 4);
+	if (ret < 0)
+		return ret;
+
+	ret = ksz9131_of_load_skew_values(phydev, of_node,
+					  MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4,
+					  tx_data_skews, 4);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)
@@ -975,6 +1085,23 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= kszphy_resume,
 }, {
+	.phy_id		= PHY_ID_KSZ9131,
+	.phy_id_mask	= MICREL_PHY_ID_MASK,
+	.name		= "Microchip KSZ9131 Gigabit PHY",
+	.features	= PHY_GBIT_FEATURES,
+	.flags		= PHY_HAS_INTERRUPT,
+	.driver_data	= &ksz9021_type,
+	.probe		= kszphy_probe,
+	.config_init	= ksz9131_config_init,
+	.read_status	= ksz9031_read_status,
+	.ack_interrupt	= kszphy_ack_interrupt,
+	.config_intr	= kszphy_config_intr,
+	.get_sset_count = kszphy_get_sset_count,
+	.get_strings	= kszphy_get_strings,
+	.get_stats	= kszphy_get_stats,
+	.suspend	= genphy_suspend,
+	.resume		= kszphy_resume,
+}, {
 	.phy_id		= PHY_ID_KSZ8873MLL,
 	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8873MLL Switch",
@@ -1022,6 +1149,7 @@ MODULE_LICENSE("GPL");
 static struct mdio_device_id __maybe_unused micrel_tbl[] = {
 	{ PHY_ID_KSZ9021, 0x000ffffe },
 	{ PHY_ID_KSZ9031, MICREL_PHY_ID_MASK },
+	{ PHY_ID_KSZ9131, MICREL_PHY_ID_MASK },
 	{ PHY_ID_KSZ8001, 0x00fffffc },
 	{ PHY_ID_KS8737, MICREL_PHY_ID_MASK },
 	{ PHY_ID_KSZ8021, 0x00ffffff },
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index 472fa4d..7361cd3 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -31,6 +31,7 @@
 #define PHY_ID_KSZ8081		0x00221560
 #define PHY_ID_KSZ8061		0x00221570
 #define PHY_ID_KSZ9031		0x00221620
+#define PHY_ID_KSZ9131		0x00221640
 
 #define PHY_ID_KSZ886X		0x00221430
 #define PHY_ID_KSZ8863		0x00221435
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131
  2018-10-18 19:06 [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY Yuiko Oshino
  2018-10-18 19:06 ` [PATCH v3 net-next 1/2] net: phy: micrel: add Microchip KSZ9131 initial driver Yuiko Oshino
@ 2018-10-18 19:06 ` Yuiko Oshino
  2018-10-18 20:28   ` Rob Herring
  2021-10-13 15:38   ` Geert Uytterhoeven
  2018-10-20  0:02 ` [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY David Miller
  2 siblings, 2 replies; 6+ messages in thread
From: Yuiko Oshino @ 2018-10-18 19:06 UTC (permalink / raw)
  To: davem, robh+dt, devicetree, f.fainelli, andrew
  Cc: linux-kernel, mark.rutland, m.felsch, Markus.Niebel, netdev,
	UNGLinuxDriver

Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY

Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>
---
 .../devicetree/bindings/net/micrel-ksz90x1.txt     | 28 +++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt b/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
index e22d8cf..5100358 100644
--- a/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
+++ b/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
@@ -1,4 +1,4 @@
-Micrel KSZ9021/KSZ9031 Gigabit Ethernet PHY
+Micrel KSZ9021/KSZ9031/KSZ9131 Gigabit Ethernet PHY
 
 Some boards require special tuning values, particularly when it comes
 to clock delays. You can specify clock delay values in the PHY OF
@@ -64,6 +64,32 @@ KSZ9031:
         Attention: The link partner must be configurable as slave otherwise
         no link will be established.
 
+KSZ9131:
+
+  All skew control options are specified in picoseconds. The increment
+  step is 100ps. Unlike KSZ9031, the values represent picoseccond delays.
+  A negative value can be assigned as rxc-skew-psec = <(-100)>;.
+
+  Optional properties:
+
+    Range of the value -700 to 2400, default value 0:
+
+      - rxc-skew-psec : Skew control of RX clock pad
+      - txc-skew-psec : Skew control of TX clock pad
+
+    Range of the value -700 to 800, default value 0:
+
+      - rxdv-skew-psec : Skew control of RX CTL pad
+      - txen-skew-psec : Skew control of TX CTL pad
+      - rxd0-skew-psec : Skew control of RX data 0 pad
+      - rxd1-skew-psec : Skew control of RX data 1 pad
+      - rxd2-skew-psec : Skew control of RX data 2 pad
+      - rxd3-skew-psec : Skew control of RX data 3 pad
+      - txd0-skew-psec : Skew control of TX data 0 pad
+      - txd1-skew-psec : Skew control of TX data 1 pad
+      - txd2-skew-psec : Skew control of TX data 2 pad
+      - txd3-skew-psec : Skew control of TX data 3 pad
+
 Examples:
 
 	mdio {
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131
  2018-10-18 19:06 ` [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131 Yuiko Oshino
@ 2018-10-18 20:28   ` Rob Herring
  2021-10-13 15:38   ` Geert Uytterhoeven
  1 sibling, 0 replies; 6+ messages in thread
From: Rob Herring @ 2018-10-18 20:28 UTC (permalink / raw)
  To: Yuiko Oshino
  Cc: davem, robh+dt, devicetree, f.fainelli, andrew, linux-kernel,
	mark.rutland, m.felsch, Markus.Niebel, netdev, UNGLinuxDriver

On Thu, 18 Oct 2018 15:06:02 -0400, Yuiko Oshino wrote:
> Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY
> 
> Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>
> ---
>  .../devicetree/bindings/net/micrel-ksz90x1.txt     | 28 +++++++++++++++++++++-
>  1 file changed, 27 insertions(+), 1 deletion(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY
  2018-10-18 19:06 [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY Yuiko Oshino
  2018-10-18 19:06 ` [PATCH v3 net-next 1/2] net: phy: micrel: add Microchip KSZ9131 initial driver Yuiko Oshino
  2018-10-18 19:06 ` [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131 Yuiko Oshino
@ 2018-10-20  0:02 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2018-10-20  0:02 UTC (permalink / raw)
  To: yuiko.oshino
  Cc: robh+dt, devicetree, f.fainelli, andrew, linux-kernel,
	mark.rutland, m.felsch, Markus.Niebel, netdev, UNGLinuxDriver

From: Yuiko Oshino <yuiko.oshino@microchip.com>
Date: Thu, 18 Oct 2018 15:06:00 -0400

> This is the initial driver for Microchip KSZ9131 10/100/1000 Ethernet PHY
> 
> v3:
> - KSZ9131 uses picosecond units for values of devicetree properties.
> - rewrite micrel.c and micrel-ksz90x1.txt to use the picosecond values.
> v2:
> - Creating a series from two related patches.

Series applied.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131
  2018-10-18 19:06 ` [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131 Yuiko Oshino
  2018-10-18 20:28   ` Rob Herring
@ 2021-10-13 15:38   ` Geert Uytterhoeven
  1 sibling, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-10-13 15:38 UTC (permalink / raw)
  To: Yuiko Oshino
  Cc: David S. Miller, Rob Herring,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Florian Fainelli, Andrew Lunn, Linux Kernel Mailing List,
	Mark Rutland, Marco Felsch, Markus.Niebel, netdev,
	Microchip Linux Driver Support

Hi Yuiko,

On Thu, Oct 18, 2018 at 8:16 PM Yuiko Oshino <yuiko.oshino@microchip.com> wrote:
> Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY
>
> Signed-off-by: Yuiko Oshino <yuiko.oshino@microchip.com>

Thanks for your patch, which is commit 806700bab41e9297
("dt-bindings: net: add support for Microchip KSZ9131") in v4.20.

> --- a/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
> +++ b/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
> @@ -1,4 +1,4 @@
> -Micrel KSZ9021/KSZ9031 Gigabit Ethernet PHY
> +Micrel KSZ9021/KSZ9031/KSZ9131 Gigabit Ethernet PHY
>
>  Some boards require special tuning values, particularly when it comes
>  to clock delays. You can specify clock delay values in the PHY OF
> @@ -64,6 +64,32 @@ KSZ9031:
>          Attention: The link partner must be configurable as slave otherwise
>          no link will be established.
>
> +KSZ9131:
> +
> +  All skew control options are specified in picoseconds. The increment
> +  step is 100ps. Unlike KSZ9031, the values represent picoseccond delays.
> +  A negative value can be assigned as rxc-skew-psec = <(-100)>;.
> +
> +  Optional properties:
> +
> +    Range of the value -700 to 2400, default value 0:
> +
> +      - rxc-skew-psec : Skew control of RX clock pad
> +      - txc-skew-psec : Skew control of TX clock pad
> +
> +    Range of the value -700 to 800, default value 0:
> +
> +      - rxdv-skew-psec : Skew control of RX CTL pad
> +      - txen-skew-psec : Skew control of TX CTL pad
> +      - rxd0-skew-psec : Skew control of RX data 0 pad
> +      - rxd1-skew-psec : Skew control of RX data 1 pad
> +      - rxd2-skew-psec : Skew control of RX data 2 pad
> +      - rxd3-skew-psec : Skew control of RX data 3 pad
> +      - txd0-skew-psec : Skew control of TX data 0 pad
> +      - txd1-skew-psec : Skew control of TX data 1 pad
> +      - txd2-skew-psec : Skew control of TX data 2 pad
> +      - txd3-skew-psec : Skew control of TX data 3 pad

Shouldn't all these use "*-skew-ps" instead of "*-skew-psec", like all
other documented skew properties?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-13 15:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-18 19:06 [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY Yuiko Oshino
2018-10-18 19:06 ` [PATCH v3 net-next 1/2] net: phy: micrel: add Microchip KSZ9131 initial driver Yuiko Oshino
2018-10-18 19:06 ` [PATCH v3 net-next 2/2] dt-bindings: net: add support for Microchip KSZ9131 Yuiko Oshino
2018-10-18 20:28   ` Rob Herring
2021-10-13 15:38   ` Geert Uytterhoeven
2018-10-20  0:02 ` [PATCH v3 net-next 0/2] Add support for Microchip Technology KSZ9131 10/100/1000 Ethernet PHY David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).