[RFC fs_enet: Convert MII bitbang driver to use GPIO lib
Subsystems (5)
This patch converts the MII bitband driver to use GPIO lib for GPIO access. The driver can now handle MDC and MDIO on different GPIO banks.
The patch depends on Anton Vorontsov GPIO lib support scheduled for 2.6.26. It is by no means complete, I just would like to get some feedback on the approach. I'll resubmit it when the CPM2 GPIO support patches will be available in the powerpc git tree.
--- Documentation/powerpc/booting-without-of.txt | 10 +- arch/powerpc/boot/dts/mpc8272ads.dts | 16 ++- arch/powerpc/boot/dts/pq2fads.dts | 16 ++- drivers/net/fs_enet/fs_enet-main.c | 10 +- drivers/net/fs_enet/mii-bitbang.c | 177 ++++++++++++++------------ 5 files changed, 127 insertions(+), 102 deletions(-)
Documentation/powerpc/booting-without-of.txt +4 -6
@@ -2030,21 +2030,19 @@ platforms are moved over to use the flattened-device-tree model. fsl,cpm2-mdio-bitbang (reg is port C registers) Properties for fsl,cpm2-mdio-bitbang: - fsl,mdio-pin : pin of port C controlling mdio data - fsl,mdc-pin : pin of port C controlling mdio clock + gpios : GPIOs controlling mdio clock and mdio data (in that order). Example: - mdio@10d40 { + mdio { device_type = "mdio"; compatible = "fsl,mpc8272ads-mdio-bitbang", "fsl,mpc8272-mdio-bitbang", "fsl,cpm2-mdio-bitbang"; - reg = <10d40 14>; #address-cells = <1>; #size-cells = <0>; - fsl,mdio-pin = <12>; - fsl,mdc-pin = <13>; + gpios = <&cpm_pio_c 13 0 + &cpm_pio_c 12 0>; }; v) Baud Rate Generators
arch/powerpc/boot/dts/mpc8272ads.dts +12 -4
@@ -164,16 +164,24 @@ fsl,cpm-command = <0ce00000>; }; - mdio@10d40 { + cpm_pio_c: gpio_controller@10d40 { + compatible = "fsl,cpm2-pario-bank-c", + "fsl,cpm2-pario-bank"; + reg = <0x10d40 0x18>; + #gpio-cells = <2>; + gpio-controller; + }; + + mdio { device_type = "mdio"; compatible = "fsl,mpc8272ads-mdio-bitbang", "fsl,mpc8272-mdio-bitbang", "fsl,cpm2-mdio-bitbang"; - reg = <10d40 14>; #address-cells = <1>; #size-cells = <0>; - fsl,mdio-pin = <12>; - fsl,mdc-pin = <13>; + gpios = <&cpm_pio_c 13 0 /* MDC */ + &cpm_pio_c 12 0 /* MDIO */ + >; PHY0: ethernet-phy@0 { interrupt-parent = <&PIC>;
arch/powerpc/boot/dts/pq2fads.dts +12 -4
@@ -187,16 +187,24 @@ local-mac-address = [00 e0 0c 00 79 01]; }; - mdio@10d40 { + cpm_pio_c: gpio_controller@10d40 { + compatible = "fsl,cpm2-pario-bank-c", + "fsl,cpm2-pario-bank"; + reg = <0x10d40 0x18>; + #gpio-cells = <2>; + gpio-controller; + }; + + mdio { device_type = "mdio"; compatible = "fsl,pq2fads-mdio-bitbang", "fsl,mpc8280-mdio-bitbang", "fsl,cpm2-mdio-bitbang"; #address-cells = <1>; #size-cells = <0>; - reg = <10d40 14>; - fsl,mdio-pin = <9>; - fsl,mdc-pin = <a>; + gpios = <&cpm_pio_c a 0 /* MDC */ + &cpm_pio_c 9 0 /* MDIO */ + >; PHY0: ethernet-phy@0 { interrupt-parent = <&PIC>;
drivers/net/fs_enet/fs_enet-main.c +5 -5
@@ -43,6 +43,7 @@#include <asm/uaccess.h> #ifdef CONFIG_PPC_CPM_NEW_BINDING +#include <linux/of_gpio.h> #include <asm/of_platform.h> #endif
@@ -1172,8 +1173,7 @@ static int __devinit find_phy(struct device_node *np, struct fs_platform_info *fpi) {struct device_node *phynode, *mdionode; -struct resource res; -int ret =0 , len; +int ret =0 , len, gpio;const u32 *data; data =of_get_property (np,"fixed-link" ,NULL );
@@ -1194,15 +1194,15 @@ static int __devinit find_phy(struct device_node *np,if (!mdionode) goto out_put_phy; - ret =of_address_to_resource (mdionode,0 , &res); -if (ret) + gpio =of_get_gpio (mdionode,0 ); +if (gpio <0 ) goto out_put_mdio; data =of_get_property (phynode,"reg" , &len);if (!data || len !=4 ) goto out_put_mdio; -snprintf (fpi->bus_id,16 ,PHY_ID_FMT , res.start, *data); +snprintf (fpi->bus_id,16 ,PHY_ID_FMT , gpio, *data); out_put_mdio:of_node_put (mdionode);
drivers/net/fs_enet/mii-bitbang.c +94 -83
246 lines not on this page · raw message
Signature · 13 lines
1.5.0 -- Laurent Pinchart CSE Semaphore Belgium Chaussee de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Quoted 7 lines · Laurent Pinchart
This patch converts the MII bitband driver to use GPIO lib for GPIO access. The driver can now handle MDC and MDIO on different GPIO banks.
The patch depends on Anton Vorontsov GPIO lib support scheduled for 2.6.26. It is by no means complete, I just would like to get some feedback on the approach. I'll resubmit it when the CPM2 GPIO support patches will be available in the powerpc git tree.
Cool! By the way, maybe it is worth splitting it into completely separate driver, e.g. net/mdio_gpio.c? Plus, keep in mind that somebody will eventually want this cool stuff with platform_device bindings in addition. :-)
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 11 lines · Anton Vorontsov
Quoted 7 lines · Laurent Pinchart
This patch converts the MII bitband driver to use GPIO lib for GPIO access. The driver can now handle MDC and MDIO on different GPIO banks.
The patch depends on Anton Vorontsov GPIO lib support scheduled for 2.6.26. It is by no means complete, I just would like to get some feedback on the approach. I'll resubmit it when the CPM2 GPIO support patches will be available in the powerpc git tree.
Cool! By the way, maybe it is worth splitting it into completely separate driver, e.g.
net/mdio_gpio.c?
Splitting it into a completely separate driver makes sense.
Quoted 2 lines
Plus, keep in mind that somebody will eventually want this cool stuff with
platform_devicebindings in addition. :-)
I'm sure that person will be happy to implement platform_device bindings :-)
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussee de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Quoted 13 lines · Laurent Pinchart
Quoted 11 lines · Anton Vorontsov
Quoted 7 lines · Laurent Pinchart
This patch converts the MII bitband driver to use GPIO lib for GPIO access. The driver can now handle MDC and MDIO on different GPIO banks.
The patch depends on Anton Vorontsov GPIO lib support scheduled for 2.6.26. It is by no means complete, I just would like to get some feedback on the approach. I'll resubmit it when the CPM2 GPIO support patches will be available in the powerpc git tree.
Cool! By the way, maybe it is worth splitting it into completely separate driver, e.g.
net/mdio_gpio.c?
Quoted 6 lines
Splitting it into a completely separate driver makes sense.
Quoted 2 lines
Plus, keep in mind that somebody will eventually want this cool stuff with
platform_devicebindings in addition. :-)I'm sure that person will be happy to implement
platform_devicebindings :-)
I had a first try at moving mdio gpio code into a separate driver.
Very little code is OF-independant, so the driver should probably be called mdio_of_gpio.c or mdio_ofgpio.c.
Scott Wood was concerned in
http://patchwork.ozlabs.org/linuxppc/patch?id=17490 that the gpio lib might be an unnecessary burden for memory-constraint platforms. Should we keep two mdio bitbang drivers, one with direct access to the ports and one using gpio lib ? The later solves the concurrent access issues present in the current fs_enet mdio bitbang driber.
I'll submit a patch for whichever solution gets selected (modifying the current fs enet mdio bitbang driver to use the gpio lib, or creating a new driver).
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussee de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev
Quoted 6 lines · Laurent Pinchart
Scott Wood was concerned in
http://patchwork.ozlabs.org/linuxppc/patch?id=17490 that the gpio lib might be an unnecessary burden for memory-constraint platforms. Should we keep two mdio bitbang drivers, one with direct access to the ports and one using gpio lib ? The later solves the concurrent access issues present in the currentfs_enetmdio bitbang driber.
The memory-constrained platform I had in mind was 8xx, which doesn't use bitbanged MDIO. It might nice to keep the gpiolib bit separate to avoid situations such as ep8248e where mdiobb would be the only thing requiring a gpiolib binding, though -- but it shouldn't be two separate bitbang drivers, just the existing bitbang driver plus some glue code that binds it to gpiolib.
-Scott
Quoted 8 lines · Scott Wood
Quoted 6 lines · Laurent Pinchart
Scott Wood was concerned in
http://patchwork.ozlabs.org/linuxppc/patch?id=17490 that the gpio lib might be an unnecessary burden for memory-constraint platforms. Should we keep two mdio bitbang drivers, one with direct access to the ports and one using gpio lib ? The later solves the concurrent access issues present in the currentfs_enetmdio bitbang driber.
Quoted 6 lines
The memory-constrained platform I had in mind was 8xx, which doesn't use bitbanged MDIO. It might nice to keep the gpiolib bit separate to avoid situations such as ep8248e where mdiobb would be the only thing requiring a gpiolib binding, though -- but it shouldn't be two separate bitbang drivers, just the existing bitbang driver plus some glue code that binds it to gpiolib.
I would be fine with that if the glue code wasn't 90% of the whole driver. There is really little (not to say nothing) that can be shared between the two drivers.
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussee de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Quoted 11 lines · Laurent Pinchart
Quoted 6 lines · Scott Wood
The memory-constrained platform I had in mind was 8xx, which doesn't use bitbanged MDIO. It might nice to keep the gpiolib bit separate to avoid situations such as ep8248e where mdiobb would be the only thing requiring a gpiolib binding, though -- but it shouldn't be two separate bitbang drivers, just the existing bitbang driver plus some glue code that binds it to gpiolib.
I would be fine with that if the glue code wasn't 90% of the whole driver. There is really little (not to say nothing) that can be shared between the two drivers.
I think we're thinking of a different pair of drivers... I thought you were talking about duplicating drivers/net/phy/mdio-bitbang.c, not drivers/net/fs_enet/mii-bitbang.c.
-Scott
Quoted 9 lines · Scott Wood
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Scott Wood
The memory-constrained platform I had in mind was 8xx, which doesn't use bitbanged MDIO. It might nice to keep the gpiolib bit separate to avoid situations such as ep8248e where mdiobb would be the only thing requiring a gpiolib binding, though -- but it shouldn't be two separate bitbang drivers, just the existing bitbang driver plus some glue code that binds it to gpiolib.
Quoted 7 lines
Quoted 3 lines
I would be fine with that if the glue code wasn't 90% of the whole driver. There is really little (not to say nothing) that can be shared between the two drivers.
I think we're thinking of a different pair of drivers... I thought you were talking about duplicating
drivers/net/phy/mdio-bitbang.c, notdrivers/net/fs_enet/mii-bitbang.c.
I don't plan to touch drivers/net/phy/mdio-bitbang.c at all, it does its job well enough.
As the openfirmware + gpio + mdio driver might benefit non-powerpc platforms, I plan to create a new driver (probably drivers/net/phy/mdio-ofgpio.c) that mostly ports drivers/net/fs_enet/mii-bitbang.c to the gpiolib (this replaces around 90% of the code).
If both drivers/net/fs_enet/mii-bitbang.c and drivers/net/phy/mdio-ofgpio.c must live together, I'll have a problem in drivers/net/fs_enet/fs_enet-main.c. The net device probing code searches the device tree for an associated PHY, and creates a PHY id from the PHY node. As the id will be generated from different bus ids in the two mdio drivers (the bus number is the register address for drivers/net/fs_enet/mii-bitbang.c, and is the gpio index for drivers/net/phy/mdio-ofgpio.c), things will break.
Any idea regarding how to get rid of that fs_enet/mii-bitbang hardcoded dependency ?
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussee de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Quoted 34 lines · Laurent Pinchart
Quoted 9 lines · Scott Wood
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Scott Wood
The memory-constrained platform I had in mind was 8xx, which doesn't use bitbanged MDIO. It might nice to keep the gpiolib bit separate to avoid situations such as ep8248e where mdiobb would be the only thing requiring a gpiolib binding, though -- but it shouldn't be two separate bitbang drivers, just the existing bitbang driver plus some glue code that binds it to gpiolib.
Quoted 7 lines
Quoted 3 lines
I would be fine with that if the glue code wasn't 90% of the whole driver. There is really little (not to say nothing) that can be shared between the two drivers.
I think we're thinking of a different pair of drivers... I thought you were talking about duplicating
drivers/net/phy/mdio-bitbang.c, notdrivers/net/fs_enet/mii-bitbang.c.I don't plan to touch
drivers/net/phy/mdio-bitbang.cat all, it does its job well enough.As the openfirmware + gpio + mdio driver might benefit non-powerpc platforms, I plan to create a new driver (probably
drivers/net/phy/mdio-ofgpio.c) that mostly portsdrivers/net/fs_enet/mii-bitbang.cto the gpiolib (this replaces around 90% of the code).If both
drivers/net/fs_enet/mii-bitbang.canddrivers/net/phy/mdio-ofgpio.cmust live together, I'll have a problem indrivers/net/fs_enet/fs_enet-main.c. The net device probing code searches the device tree for an associated PHY, and creates a PHY id from the PHY node. As the id will be generated from different bus ids in the two mdio drivers (the bus number is the register address fordrivers/net/fs_enet/mii-bitbang.c, and is the gpio index fordrivers/net/phy/mdio-ofgpio.c), things will break.
Quoted 2 lines
Any idea regarding how to get rid of that fs_enet/mii-bitbang hardcoded dependency ?
Hm... PHYs are having bus_id equal to MDIOBUS:PHYID, for example e0024520:02, see fs_enet-main.c find_phy() and fs_init_phy():
data = of_get_property(np, "phy-handle", &len);
phynode = of_find_node_by_phandle(*data);
mdionode = of_get_parent(phynode);
ret = of_address_to_resource(mdionode, 0, &res);
data = of_get_property(phynode, "reg", &len);
snprintf(fpi->bus_id, 16, PHY_ID_FMT, res.start, *data);
...
phydev = phy_connect(dev, fep->fpi->bus_id, &fs_adjust_link, 0,
PHY_INTERFACE_MODE_MII);So in the device tree you could do this:
mdio@<GPIO bank addr> {
compatible = "linux,mdio-gpio";
...
phy123: ethernet-phy@2 {
reg = <2>;
device_type = "ethernet-phy";
};
};ethernet@... {
...
compatible = "fs_enet";
...
phy-handle = <&phy123>;
};And fs_enet will match mdio-ofgpio driver.
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 7 lines · Laurent Pinchart
As the openfirmware + gpio + mdio driver might benefit non-powerpc platforms, I plan to create a new driver (probably
drivers/net/phy/mdio-ofgpio.c) that mostly portsdrivers/net/fs_enet/mii-bitbang.cto the gpiolib (this replaces around 90% of the code).If both
drivers/net/fs_enet/mii-bitbang.canddrivers/net/phy/mdio-ofgpio.cmust live together,
The only reason I can see for that would be if the gpiolib version doesn't work on arch/ppc -- but that's not going to be a problem for very much longer.
Quoted 9 lines
I'll have a problem in
drivers/net/fs_enet/fs_enet-main.c. The net device probing code searches the device tree for an associated PHY, and creates a PHY id from the PHY node. As the id will be generated from different bus ids in the two mdio drivers (the bus number is the register address fordrivers/net/fs_enet/mii-bitbang.c, and is the gpio index fordrivers/net/phy/mdio-ofgpio.c), things will break.Any idea regarding how to get rid of that fs_enet/mii-bitbang hardcoded dependency ?
If mii-bitbang is only used on arch/ppc, then #ifdef CONFIG_PPC_MERGE should do it.
It'd be nice to be able to give phylib an OF node rather than a string, though...
-Scott
Quoted 7 lines · Scott Wood
Quoted 6 lines · Laurent Pinchart
As the openfirmware + gpio + mdio driver might benefit non-powerpc platforms, I plan to create a new driver (probably
drivers/net/phy/mdio-ofgpio.c) that mostly portsdrivers/net/fs_enet/mii-bitbang.cto the gpiolib (this replaces around 90% of the code).
Quoted 6 lines
Quoted 2 lines
If both
drivers/net/fs_enet/mii-bitbang.canddrivers/net/phy/mdio-ofgpio.cmust live together,The only reason I can see for that would be if the gpiolib version doesn't work on
arch/ppc-- but that's not going to be a problem for very much longer.
Didn't you mention platforms such as ep8248e as well, where mdiobb would be the only gpiolib user ?
Quoted 7 lines
Quoted 7 lines
I'll have a problem in
drivers/net/fs_enet/fs_enet-main.c. The net device probing code searches the device tree for an associated PHY, and creates a PHY id from the PHY node. As the id will be generated from different bus ids in the two mdio drivers (the bus number is the register address fordrivers/net/fs_enet/mii-bitbang.c, and is the gpio index fordrivers/net/phy/mdio-ofgpio.c), things will break.
Quoted 5 lines
Quoted 2 lines
Any idea regarding how to get rid of that fs_enet/mii-bitbang hardcoded dependency ?
If mii-bitbang is only used on
arch/ppc, then #ifdefCONFIG_PPC_MERGEshould do it.
Ok.
Quoted 2 lines
It'd be nice to be able to give phylib an OF node rather than a string, though...
Doesn't phylib have non-OF users ?
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussee de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Quoted 7 lines · Laurent Pinchart
Quoted 3 lines · Scott Wood
The only reason I can see for that would be if the gpiolib version doesn't work on
arch/ppc-- but that's not going to be a problem for very much longer.Didn't you mention platforms such as ep8248e as well, where mdiobb would be the only gpiolib user ?
That was when I thought you were talking about changing drivers/net/phy/mdio-bitbang.c. ep8248e doesn't use drivers/net/fs-enet/mii-bitbang.c.
Quoted 4 lines
Quoted 2 lines
It'd be nice to be able to give phylib an OF node rather than a string, though...
Doesn't phylib have non-OF users ?
I meant as an option, not the only way to specify it.
-Scott
Quoted 7 lines · Laurent Pinchart
This patch converts the MII bitband driver to use GPIO lib for GPIO access.
The driver can now handle MDC and MDIO on different GPIO banks.The patch depends on Anton Vorontsov GPIO lib support scheduled for 2.6.26. It is by no means complete, I just would like to get some feedback on the approach. I'll resubmit it when the CPM2 GPIO support patches will be available in the powerpc git tree.
I agree with Anton; nice rework. This would be useful on other platforms too. Comment below.
Quoted 10 lines
---
a/Documentation/powerpc/booting-without-of.txt
+++b/Documentation/powerpc/booting-without-of.txt
@@ -2030,21 +2030,19 @@ platforms are moved over to use the flattened-device-tree model.
fsl,cpm2-mdio-bitbang (reg is port C registers)Properties for fsl,cpm2-mdio-bitbang:
- fsl,mdio-pin : pin of port C controlling mdio data - fsl,mdc-pin : pin of port C controlling mdio clock + gpios : GPIOs controlling mdio clock and mdio data (in that order).
Quoted 8 lines
Example:
- mdio@10d40 {
+ mdio { device_type = "mdio"; compatible = "fsl,mpc8272ads-mdio-bitbang", "fsl,mpc8272-mdio-bitbang", "fsl,cpm2-mdio-bitbang";
I think it would be better for the defined binding to use something like "virtual,mdio-bitbang" or "gpio-mdio". (I like the first better, but there is already some precedence with the "gpio-led" driver. I think there is less chance of namespace conflicts with the first)
Of course; the *driver* could also accept these additional compatible values for backwards compatibility.
Cheers,
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.