netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] Add OF bindings to Micrel ksz9021 PHY
@ 2013-08-01  9:19 Sean Cross
  2013-08-01  9:19 ` [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021 Sean Cross
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Cross @ 2013-08-01  9:19 UTC (permalink / raw)
  To: Sascha Hauer, Duan Fugang-B38611, netdev, devicetree
  Cc: David Miller, stephen, Steven Rostedt, Sean Cross

Some boards require custom parameters be passed to the Micrel PHY.
Allow these boards to specify custom timing parameters in the device
tree node.

Changes since v2:
 - limited the scope to just ksz9021 rather than all PHYs

Changes since v1:
 - removed redefinition of registers and addresses 

Sean Cross (1):
  net/phy: micrel: Add OF configuration support for ksz9021

 .../devicetree/bindings/net/micrel-ksz9021.txt     |   19 +++++++
 drivers/net/phy/micrel.c                           |   57 +++++++++++++++++++-
 2 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/net/micrel-ksz9021.txt

-- 
1.7.9.5

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

* [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021
  2013-08-01  9:19 [PATCH v3] Add OF bindings to Micrel ksz9021 PHY Sean Cross
@ 2013-08-01  9:19 ` Sean Cross
  2013-08-04  4:56   ` David Miller
  2013-08-05  1:58   ` Duan Fugang-B38611
  0 siblings, 2 replies; 6+ messages in thread
From: Sean Cross @ 2013-08-01  9:19 UTC (permalink / raw)
  To: Sascha Hauer, Duan Fugang-B38611, netdev, devicetree
  Cc: David Miller, stephen, Steven Rostedt, Sean Cross

Some boards require custom PHY configuration, for example due to trace
length differences.  Add the ability to configure these registers in
order to get the PHY to function on boards that need it.

Because PHYs are auto-detected based on MDIO device IDs, allow PHY
configuration to be specified in the parent Ethernet device node if no
PHY device node is present.

Signed-off-by: Sean Cross <xobs@kosagi.com>
---
 .../devicetree/bindings/net/micrel-ksz9021.txt     |   19 +++++++
 drivers/net/phy/micrel.c                           |   57 +++++++++++++++++++-
 2 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/net/micrel-ksz9021.txt

diff --git a/Documentation/devicetree/bindings/net/micrel-ksz9021.txt b/Documentation/devicetree/bindings/net/micrel-ksz9021.txt
new file mode 100644
index 0000000..b3e5cd2
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/micrel-ksz9021.txt
@@ -0,0 +1,19 @@
+Micrel KSZ9021 Gigabit Ethernet PHY
+
+Some boards require special tuning values, particularly when it comes to
+clock delays.  You can specify clock delay values by adding
+micrel-specific properties to an Ethernet OF device node.
+
+Optional properties:
+- micrel,clk-control-pad-skew : Timing offset for the MII clock line
+- micrel,rx-data-pad-skew : Timing offset for the RX MII pad
+- micrel,tx-data-pad-skew : Timing offset for the TX MII pad
+
+Example:
+	&enet {
+		micrel,clk-control-pad-skew = <0xf0f0>;
+		micrel,rx-data-pad-skew = <0x0000>;
+		micrel,tx-data-pad-skew = <0xffff>;
+		status = "okay";
+	};
+
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 2510435..376d63a 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -25,6 +25,7 @@
 #include <linux/module.h>
 #include <linux/phy.h>
 #include <linux/micrel_phy.h>
+#include <linux/of.h>
 
 /* Operation Mode Strap Override */
 #define MII_KSZPHY_OMSO				0x16
@@ -53,6 +54,18 @@
 #define KS8737_CTRL_INT_ACTIVE_HIGH		(1 << 14)
 #define KSZ8051_RMII_50MHZ_CLK			(1 << 7)
 
+/* Write/read to/from extended registers */
+#define MII_KSZPHY_EXTREG                       0x0b
+#define KSZPHY_EXTREG_WRITE                     0x8000
+
+#define MII_KSZPHY_EXTREG_WRITE                 0x0c
+#define MII_KSZPHY_EXTREG_READ                  0x0d
+
+/* Extended registers */
+#define MII_KSZPHY_CLK_CONTROL_PAD_SKEW         0x104
+#define MII_KSZPHY_RX_DATA_PAD_SKEW             0x105
+#define MII_KSZPHY_TX_DATA_PAD_SKEW             0x106
+
 static int ksz_config_flags(struct phy_device *phydev)
 {
 	int regval;
@@ -65,6 +78,13 @@ static int ksz_config_flags(struct phy_device *phydev)
 	return 0;
 }
 
+static int kszphy_extended_write(struct phy_device *phydev,
+                                 u32 regnum, u16 val)
+{
+	phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum);
+	return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val);
+}
+
 static int kszphy_ack_interrupt(struct phy_device *phydev)
 {
 	/* bit[7..0] int status, which is a read and clear register. */
@@ -141,6 +161,41 @@ static int ks8051_config_init(struct phy_device *phydev)
 	return rc < 0 ? rc : 0;
 }
 
+static int ksz9021_config_init(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->dev;
+	struct device_node *of_node = dev->of_node;
+
+	if (!of_node && dev->parent->of_node)
+		of_node = dev->parent->of_node;
+
+	if (of_node) {
+		u32 val;
+
+		if (!of_property_read_u32(of_node,
+					  "micrel,clk-control-pad-skew",
+					  &val))
+			kszphy_extended_write(phydev,
+					      MII_KSZPHY_CLK_CONTROL_PAD_SKEW,
+					      val);
+
+		if (!of_property_read_u32(of_node,
+					  "micrel,rx-data-pad-skew",
+					  &val))
+			kszphy_extended_write(phydev,
+					      MII_KSZPHY_RX_DATA_PAD_SKEW,
+					      val);
+
+		if (!of_property_read_u32(of_node,
+					  "micrel,tx-data-pad-skew",
+					  &val))
+			kszphy_extended_write(phydev,
+					      MII_KSZPHY_TX_DATA_PAD_SKEW,
+					      val);
+	}
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	(1 << 6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	(1 << 4)
@@ -281,7 +336,7 @@ static struct phy_driver ksphy_driver[] = {
 	.name		= "Micrel KSZ9021 Gigabit PHY",
 	.features	= (PHY_GBIT_FEATURES | SUPPORTED_Pause),
 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
-	.config_init	= kszphy_config_init,
+	.config_init	= ksz9021_config_init,
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
 	.ack_interrupt	= kszphy_ack_interrupt,
-- 
1.7.9.5

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

* Re: [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021
  2013-08-01  9:19 ` [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021 Sean Cross
@ 2013-08-04  4:56   ` David Miller
  2013-08-05  1:58   ` Duan Fugang-B38611
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2013-08-04  4:56 UTC (permalink / raw)
  To: xobs; +Cc: s.hauer, B38611, netdev, devicetree, stephen, rostedt

From: Sean Cross <xobs@kosagi.com>
Date: Thu,  1 Aug 2013 09:19:17 +0000

> Some boards require custom PHY configuration, for example due to trace
> length differences.  Add the ability to configure these registers in
> order to get the PHY to function on boards that need it.
> 
> Because PHYs are auto-detected based on MDIO device IDs, allow PHY
> configuration to be specified in the parent Ethernet device node if no
> PHY device node is present.
> 
> Signed-off-by: Sean Cross <xobs@kosagi.com>

Can someone knowledgable in this area please review this patch?

Thanks.

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

* RE: [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021
  2013-08-01  9:19 ` [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021 Sean Cross
  2013-08-04  4:56   ` David Miller
@ 2013-08-05  1:58   ` Duan Fugang-B38611
  2013-08-05  2:23     ` Sean Cross
  1 sibling, 1 reply; 6+ messages in thread
From: Duan Fugang-B38611 @ 2013-08-05  1:58 UTC (permalink / raw)
  To: Sean Cross, Sascha Hauer, netdev, devicetree
  Cc: David Miller, stephen, Steven Rostedt

From: Sean Cross [mailto:xobs@kosagi.com]
Data: Thursday, August 01, 2013 5:19 PM

> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/micrel-ksz9021.txt
> @@ -0,0 +1,19 @@
> +Micrel KSZ9021 Gigabit Ethernet PHY
> +
> +Some boards require special tuning values, particularly when it comes
> +to clock delays.  You can specify clock delay values by adding
> +micrel-specific properties to an Ethernet OF device node.
> +
> +Optional properties:
> +- micrel,clk-control-pad-skew : Timing offset for the MII clock line
> +- micrel,rx-data-pad-skew : Timing offset for the RX MII pad
> +- micrel,tx-data-pad-skew : Timing offset for the TX MII pad
> +
> +Example:
> +	&enet {
> +		micrel,clk-control-pad-skew = <0xf0f0>;
> +		micrel,rx-data-pad-skew = <0x0000>;
> +		micrel,tx-data-pad-skew = <0xffff>;
> +		status = "okay";
> +	};
> +

The phy binding must be the phy node, not the ethernet node.
Pls refer to:  
		  Documentation/devicetree/booting-without-of.txt
		  Documentation/devicetree/bindings/net/phy.txt
	

> +static int ksz9021_config_init(struct phy_device *phydev) {
> +	struct device *dev = &phydev->dev;
> +	struct device_node *of_node = dev->of_node;
> +
> +	if (!of_node && dev->parent->of_node)
> +		of_node = dev->parent->of_node;
> +
If phy binding is phy node, there only check of_node, don't re-evaluate the phy node.

Thanks,
Andy

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

* Re: [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021
  2013-08-05  1:58   ` Duan Fugang-B38611
@ 2013-08-05  2:23     ` Sean Cross
  2013-08-05  3:03       ` Duan Fugang-B38611
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Cross @ 2013-08-05  2:23 UTC (permalink / raw)
  To: Duan Fugang-B38611
  Cc: Sascha Hauer, netdev, devicetree, David Miller, stephen, Steven Rostedt

On Monday, 5 August, 2013 at 9:58 AM, Duan Fugang-B38611 wrote:
> From: Sean Cross [mailto:xobs@kosagi.com]
> Data: Thursday, August 01, 2013 5:19 PM
> 
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/net/micrel-ksz9021.txt
> > @@ -0,0 +1,19 @@
> > +Micrel KSZ9021 Gigabit Ethernet PHY
> > +
> > +Some boards require special tuning values, particularly when it comes
> > +to clock delays. You can specify clock delay values by adding
> > +micrel-specific properties to an Ethernet OF device node.
> > +
> > +Optional properties:
> > +- micrel,clk-control-pad-skew : Timing offset for the MII clock line
> > +- micrel,rx-data-pad-skew : Timing offset for the RX MII pad
> > +- micrel,tx-data-pad-skew : Timing offset for the TX MII pad
> > +
> > +Example:
> > + &enet {
> > + micrel,clk-control-pad-skew = <0xf0f0>;
> > + micrel,rx-data-pad-skew = <0x0000>;
> > + micrel,tx-data-pad-skew = <0xffff>;
> > + status = "okay";
> > + };
> > +
> 
> 
> 
> The phy binding must be the phy node, not the ethernet node.
> Pls refer to: 
> Documentation/devicetree/booting-without-of.txt
> Documentation/devicetree/bindings/net/phy.txt

This won't necessarily work.  In my board, I don't think it's possible to manually specify the PHY, as most of the fields required by the OF PHY node don't apply to this device (at least according to phy.txt).  There are no interrupts, no interrupt parent, and it's unclear what the reg or linux,phandle fields do.  All of these are required fields, none of which seem to apply to this particular board.  Furthermore, it doesn't seem to be possible to specify a particular PHY, such as the ksz9021.

I see the pattern of getting OF settings from a parent's node used elsewhere in the kernel.  For example, in mmc_of_parse(), or more similarly in the chipidea ci_hdrc_probe() driver.  
> > +static int ksz9021_config_init(struct phy_device *phydev) {
> > + struct device *dev = &phydev->dev;
> > + struct device_node *of_node = dev->of_node;
> > +
> > + if (!of_node && dev->parent->of_node)
> > + of_node = dev->parent->of_node;
> > +
> 
> 
> If phy binding is phy node, there only check of_node, don't re-evaluate the phy node.
It's done this way in case it's not possible to add a phy node, as in this case. 

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

* RE: [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021
  2013-08-05  2:23     ` Sean Cross
@ 2013-08-05  3:03       ` Duan Fugang-B38611
  0 siblings, 0 replies; 6+ messages in thread
From: Duan Fugang-B38611 @ 2013-08-05  3:03 UTC (permalink / raw)
  To: Sean Cross
  Cc: Sascha Hauer, netdev, devicetree, David Miller, stephen, Steven Rostedt

From: Sean Cross [mailto:xobs@kosagi.com]
Data: Monday, August 05, 2013 10:24 AM

> > > +Example:
> > > + &enet {
> > > + micrel,clk-control-pad-skew = <0xf0f0>;  micrel,rx-data-pad-skew =
> > > +<0x0000>;  micrel,tx-data-pad-skew = <0xffff>;  status = "okay";
> > > +};
> > > +
> >
> >
> >
> > The phy binding must be the phy node, not the ethernet node.
> > Pls refer to:
> > Documentation/devicetree/booting-without-of.txt
> > Documentation/devicetree/bindings/net/phy.txt
> 
> This won't necessarily work.  In my board, I don't think it's possible to
> manually specify the PHY, as most of the fields required by the OF PHY
> node don't apply to this device (at least according to phy.txt).  There
> are no interrupts, no interrupt parent, and it's unclear what the reg or
> linux,phandle fields do.  All of these are required fields, none of which
> seem to apply to this particular board.  Furthermore, it doesn't seem to
> be possible to specify a particular PHY, such as the ksz9021.
> 
> I see the pattern of getting OF settings from a parent's node used
> elsewhere in the kernel.  For example, in mmc_of_parse(), or more
> similarly in the chipidea ci_hdrc_probe() driver.

Yes, the patch is only reasonable for your platform, but it is the phy driver for different platforms that you must considerate.
Please add more example cases in binding doc.


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

end of thread, other threads:[~2013-08-05  3:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-01  9:19 [PATCH v3] Add OF bindings to Micrel ksz9021 PHY Sean Cross
2013-08-01  9:19 ` [PATCH v3] net/phy: micrel: Add OF configuration support for ksz9021 Sean Cross
2013-08-04  4:56   ` David Miller
2013-08-05  1:58   ` Duan Fugang-B38611
2013-08-05  2:23     ` Sean Cross
2013-08-05  3:03       ` Duan Fugang-B38611

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).