net: mvmdio: close the gaps between mv643xx_eth and mvmdio
Subsystems (4)
cover net: mvmdio: close the gaps between mv643xx_eth and mvmdio
Hi all,
This patch series attempts to close the gaps between the SMI/MDIO driver implemented and use by the Marvell MV643XX ethernet driver and Thomas' MVMDIO driver. I did not convert yet mv643xx_eth to use it as it would require proper Device Tree bindings (which is being worked on) to easily hook into it.
Note that I could not test this properly yet, thus the RFC, and I would like to find a better way of setting/getting the PHY address than using two exports, although I have tried to make them easy enough to use so the following logic in Ethernet drivers can be used:
- lookup device tree handle from MDIO device tree node
- lookup corresponding struct platform_device from the device tree handle
- call the helpers
Comment welcome!
Florian Fainelli (4):
net: mvmdio: rename base register cookie from smireg to regs
net: mvmdio: do not assume SMI reg is at offset 0 of the resource
net: mvmdio: enhance driver to support SMI error/done interrupts
net: mvmdio: add getter and setter for PHY addresses
.../devicetree/bindings/net/marvell-orion-mdio.txt | 5 +- arch/arm/boot/dts/armada-370-xp.dtsi | 2 +- drivers/net/ethernet/marvell/mvmdio.c | 125 +++++++++++++++++--- include/linux/marvell_mvmdio.h | 10 ++ 4 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 include/linux/marvell_mvmdio.h
Signature · 1 line
1.7.10.4
RFC PATCH 1/4 net: mvmdio: rename base register cookie from smireg to regs
This patch renames the base register cookie in the mvmdio drive from "smireg" to "regs" since a subsequent patch is going to use an ioremap() cookie whose size is larger than a single register of 4 bytes. No functionnal code change introduced.
--- drivers/net/ethernet/marvell/mvmdio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +8 -8
@@ -39,7 +39,7 @@struct orion_mdio_dev {struct mutex lock; -void __iomem *smireg; +void __iomem *regs; };/* Wait for the SMI unit to be ready for another operation
@@ -52,7 +52,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) count =0 ;while (1 ) { - val =readl (dev->smireg); + val =readl (dev->regs);if (!(val &MVMDIO_SMI_BUSY ))break ;
@@ -87,12 +87,12 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id,writel (((mii_id <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | (regnum <<MVMDIO_SMI_PHY_REG_SHIFT ) |MVMDIO_SMI_READ_OPERATION ), - dev->smireg); + dev->regs);/* Wait for the value to become available */ count =0 ;while (1 ) { - val =readl (dev->smireg); + val =readl (dev->regs);if (val &MVMDIO_SMI_READ_VALID )break ;
@@ -129,7 +129,7 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id, (regnum <<MVMDIO_SMI_PHY_REG_SHIFT ) |MVMDIO_SMI_WRITE_OPERATION | (value << MVMDIO_SMI_DATA_SHIFT)), - dev->smireg); + dev->regs);mutex_unlock (&dev->lock);
@@ -173,8 +173,8 @@ static int orion_mdio_probe(struct platform_device *pdev) bus->irq[i] =PHY_POLL ; dev = bus->priv; - dev->smireg =of_iomap (pdev->dev.of_node,0 ); -if (!dev->smireg) { + dev->regs =of_iomap (pdev->dev.of_node,0 ); +if (!dev->regs) {dev_err (&pdev->dev,"No SMI register address given in DT\n" );kfree (bus->irq);mdiobus_free (bus);
@@ -186,7 +186,7 @@ static int orion_mdio_probe(struct platform_device *pdev) ret =of_mdiobus_register (bus, np);if (ret <0 ) {dev_err (&pdev->dev,"Cannot register MDIO bus (%d)\n" , ret); -iounmap (dev->smireg); +iounmap (dev->regs);kfree (bus->irq);mdiobus_free (bus);return ret;
Signature · 1 line
1.7.10.4
RFC PATCH 2/4 net: mvmdio: do not assume SMI reg is at offset 0 of the resource
In reply to Florian FainelliThis patch changes the mvmdio driver not to assume that the MVMDIO_SMI_REG is at offset 0 of the resource we are being passed via Device Tree. This is actually required to reduce the differences between the mv643xx_eth SMI driver and mvmdio. The only user of the "orion-mdio" binding is updated accordingly.
--- Documentation/devicetree/bindings/net/marvell-orion-mdio.txt | 2 +- arch/arm/boot/dts/armada-370-xp.dtsi | 2 +- drivers/net/ethernet/marvell/mvmdio.c | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/net/marvell-orion-mdio.txt +1 -1
@@ -19,7 +19,7 @@ mdio { #address-cells = <1>; #size-cells = <0>; compatible = "marvell,orion-mdio"; - reg = <0xd0072004 0x4>; + reg = <0xd0072000 0x8>; }; And at the board level:
arch/arm/boot/dts/armada-370-xp.dtsi +1 -1
@@ -91,7 +91,7 @@ #address-cells = <1>; #size-cells = <0>; compatible = "marvell,orion-mdio"; - reg = <0xd0072004 0x4>; + reg = <0xd0072000 0x8>; }; ethernet at d0070000 {
drivers/net/ethernet/marvell/mvmdio.c +5 -4
@@ -29,6 +29,7 @@#include <linux/platform_device.h> #include <linux/delay.h> +#define MVMDIO_SMI_REG 0x0004#define MVMDIO_SMI_DATA_SHIFT 0#define MVMDIO_SMI_PHY_ADDR_SHIFT 16#define MVMDIO_SMI_PHY_REG_SHIFT 21
@@ -52,7 +53,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) count =0 ;while (1 ) { - val =readl (dev->regs); + val =readl (dev->regs +MVMDIO_SMI_REG );if (!(val &MVMDIO_SMI_BUSY ))break ;
@@ -87,12 +88,12 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id,writel (((mii_id <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | (regnum <<MVMDIO_SMI_PHY_REG_SHIFT ) |MVMDIO_SMI_READ_OPERATION ), - dev->regs); + dev->regs +MVMDIO_SMI_REG );/* Wait for the value to become available */ count =0 ;while (1 ) { - val =readl (dev->regs); + val =readl (dev->regs +MVMDIO_SMI_REG );if (val &MVMDIO_SMI_READ_VALID )break ;
@@ -129,7 +130,7 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id, (regnum <<MVMDIO_SMI_PHY_REG_SHIFT ) |MVMDIO_SMI_WRITE_OPERATION | (value << MVMDIO_SMI_DATA_SHIFT)), - dev->regs); + dev->regs + MVMDIO_SMI_REG);mutex_unlock (&dev->lock);
Signature · 1 line
1.7.10.4
RFC PATCH 3/4 net: mvmdio: enhance driver to support SMI error/done interrupts
In reply to Florian FainelliThis patch enhances the "mvmdio" to support a SMI error/done interrupt line which can be used along with a wait queue instead of doing busy-waiting on the registers. This is a feature which is available in the mv643xx_eth SMI code and thus reduces again the gap between the two.
--- .../devicetree/bindings/net/marvell-orion-mdio.txt | 3 + drivers/net/ethernet/marvell/mvmdio.c | 81 +++++++++++++++++--- 2 files changed, 73 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/net/marvell-orion-mdio.txt +3 -0
@@ -9,6 +9,9 @@ Required properties: - compatible: "marvell,orion-mdio" - reg: address and length of the SMI register +Optional properties: +- interrupts: interrupt line number for the SMI error/done + The child nodes of the MDIO driver are the individual PHY devices connected to this MDIO bus. They must have a "reg" property given the PHY address on the MDIO bus.
drivers/net/ethernet/marvell/mvmdio.c +70 -11
123 lines not on this page · raw message
Signature · 1 line
1.7.10.4
RFC PATCH 4/4 net: mvmdio: add getter and setter for PHY addresses
In reply to Florian FainelliThis patch adds orion_mdio_{set,get}_phy_addr(.., port_number, phy_addr) which is a feature available in this MDIO driver to monitor a particular PHY address. This brings mvmdio one step closer to what is used in mv643x_eth.
--- drivers/net/ethernet/marvell/mvmdio.c | 29 +++++++++++++++++++++++++++++ include/linux/marvell_mvmdio.h | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 include/linux/marvell_mvmdio.h
drivers/net/ethernet/marvell/mvmdio.c +29 -0
@@ -32,7 +32,9 @@#include <linux/delay.h> #include <linux/sched.h> #include <linux/wait.h> +#include <linux/marvell_mvmdio.h> +#define MVMDIO_PHY_ADDR 0x0000#define MVMDIO_SMI_REG 0x0004#define MVMDIO_SMI_DATA_SHIFT 0#define MVMDIO_SMI_PHY_ADDR_SHIFT 16
@@ -188,6 +190,33 @@ static irqreturn_t orion_mdio_err_irq(int irq, void *dev_id)return IRQ_NONE ; } +void orion_mdio_phy_addr_set (struct platform_device *pdev, +int port_num,int phy_addr) +{ +struct orion_mdio_dev *dev = +platform_get_drvdata (pdev); +int addr_shift =5 * port_num; +u32 data; + + data =readl (dev->regs +MVMDIO_PHY_ADDR ); + data &= ~(0x1f << addr_shift); + data |= (phy_addr &0x1f ) << addr_shift; +writel (data, dev->regs +MVMDIO_PHY_ADDR ); +} +EXPORT_SYMBOL (orion_mdio_phy_addr_set); + +int orion_mdio_phy_addr_get (struct platform_device *pdev,int port_num) +{ +struct orion_mdio_dev *dev = +platform_get_drvdata (pdev); +unsigned int data; + + data =readl (dev->regs +MVMDIO_PHY_ADDR ); + +return (data >> (5 * port_num)) &0x1f ; +} +EXPORT_SYMBOL (orion_mdio_phy_addr_get); +static int orion_mdio_probe (struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;
include/linux/marvell_mvmdio.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef _MARVELL_MVMDIO_H +#define _MARVELL_MVMDIO_H + +#include <linux/platform_device.h> + +void orion_mdio_phy_addr_set (struct platform_device *pdev, +int port_num,int phy_addr); +int orion_mdio_phy_addr_get (struct platform_device *pdev,int port_num); + +#endif /* _MARVELL_MVMDIO_H */
Signature · 1 line
1.7.10.4
Re: [RFC PATCH 4/4] net: mvmdio: add getter and setter for PHY addresses
Quoted 4 lines · Florian Fainelli
This patch adds orion_mdio_{set,get}_phy_addr(..,
port_number,phy_addr) which is a feature available in this MDIO driver to monitor a particular PHY address. This brings mvmdio one step closer to what is used inmv643x_eth.
This seems really strange.
Are you sure this should be part of the MDIO driver? Based on my docs, this register is part of the ethernet controller HW, which autonomously reads from the phy via MDIO.
It seems cleaner to set this register from the ethernet controller based on the phy it is using and keep the MDIO driver purely for MDIO bus access.
It is acceptable to overlap the device address ranges, start the ethernet controller at 72000 and start the MDIO at 72004, the platform bus code automatically nests them.
Jason
Re: [RFC PATCH 4/4] net: mvmdio: add getter and setter for PHY addresses
Le 25/01/2013 19:16, Jason Gunthorpe a ?crit :
Quoted 11 lines · Florian Fainelli
Quoted 4 lines
This patch adds orion_mdio_{set,get}_phy_addr(..,
port_number,phy_addr) which is a feature available in this MDIO driver to monitor a particular PHY address. This brings mvmdio one step closer to what is used inmv643x_eth.This seems really strange.
Are you sure this should be part of the MDIO driver? Based on my docs, this register is part of the ethernet controller HW, which autonomously reads from the phy via MDIO.
My reading of the datasheets for 88F628x and Armada 370 says that it actually belongs to the MDIO part of the controller (it is just below the SMI registers).
Quoted 8 lines
It seems cleaner to set this register from the ethernet controller based on the phy it is using and keep the MDIO driver purely for MDIO bus access.
It is acceptable to overlap the device address ranges, start the ethernet controller at 72000 and start the MDIO at 72004, the platform bus code automatically nests them.
Ok I did not think this would work, but I kind of prefer that too. --
Florian