phylib: fix + drivers
Subsystems (3)
cover phylib: fix + drivers
HI,
Today we have a bug on the match the logic is inverted. We are lucky as the generic Phy driver is not suppoed to match with any device it work so fix it. Ensure the generic phy driver is probe last if needed.
for mx53-loco we are lucky too the first phy found is the right one
The following changes since commit 272a5d738ab152347d67be062e8a4e771825493a:
at91rm9200ek: add spi support (2012-11-16 15:33:50 +0100)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git delivery/phylib_fix
for you to fetch changes up to 5ea00036e330ea58293774a36d3ee5f9c1fbe895:
phylib: add micrel support (2012-11-16 23:11:16 +0800)
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (7):
driver: introduce device_probe to manully probe a device
phylib: fix generic phy driver probe
mdio_bus: fix match
phylib: export phy_id via param
phylib: introduction of forced 100Mbps
phylib: add fixup support
phylib: add micrel support
drivers/base/driver.c | 23 +++++++++---- drivers/net/phy/Kconfig | 11 +++--- drivers/net/phy/Makefile | 2 +- drivers/net/phy/generic.c | 36 -------------------- drivers/net/phy/mdio_bus.c | 28 ++++++++++----- drivers/net/phy/micrel.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- include/driver.h | 5 +++ include/linux/micrel_phy.h | 30 ++++++++++++++++ include/linux/phy.h | 21 +++++++++++- 10 files changed, 400 insertions(+), 60 deletions(-) delete mode 100644 drivers/net/phy/generic.c create mode 100644 drivers/net/phy/micrel.c create mode 100644 include/linux/micrel_phy.h
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/7 driver: introduce device_probe to manully probe a device
This will expect a driver to be specified
This is needed by the phylib the probe the generic phy if not driver found
--- drivers/base/driver.c | 23 +++++++++++++++++------ include/driver.h | 5 +++++ 2 files changed, 22 insertions(+), 6 deletions(-)
drivers/base/driver.c +17 -6
@@ -75,6 +75,21 @@ int get_free_deviceid(const char *name_template) }; } +int device_probe (struct device_d *dev) +{ +int ret; + + ret = dev->bus->probe (dev); +if (ret) { +dev_err (dev,"probe failed: %s\n" ,strerror (-ret)); +return ret; + } + +list_add (&dev->active, &active); + +return 0 ; +} +static int match (struct driver_d *drv,struct device_d *dev) {int ret;
@@ -86,13 +101,9 @@ static int match(struct driver_d *drv, struct device_d *dev)if (dev->bus->match (dev, drv)) goto err_out; - ret = dev->bus->probe (dev); -if (ret) { -dev_err (dev,"probe failed: %s\n" ,strerror (-ret)); + ret =device_probe (dev); +if (ret) goto err_out; - } - -list_add (&dev->active, &active);return 0 ; err_out:
include/driver.h +5 -0
@@ -148,6 +148,11 @@ struct driver_d {int register_driver (struct driver_d *);int register_device (struct device_d *); +/* manualy probe a device +* the driver need to be specified +*/ +int device_probe (struct device_d *dev); +/* Unregister a device. This function can fail, e.g. when the device * has children. */
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/7 phylib: export phy_id via param
--- drivers/net/phy/mdio_bus.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/phy/mdio_bus.c +3 -0
@@ -193,6 +193,9 @@ static int mdio_bus_probe(struct device_d *_dev)sprintf (str,"%d" , dev->addr);dev_add_param_fixed (&dev->dev,"phy_addr" , str); +sprintf (str,"0x%08x" , dev->phy_id); +dev_add_param_fixed (&dev->dev,"phy_id" , str); + dev->cdev.name =asprintf ("phy%d" , _dev->id); dev->cdev.size =64 ; dev->cdev.ops = &phydev_ops;
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/7 mdio_bus: fix match
In reply to Jean-Christophe PLAGNIOL-VILLARDon barebox we have the weird way the return 0 true on bus match
--- drivers/net/phy/mdio_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/mdio_bus.c +1 -1
@@ -106,7 +106,7 @@ static int mdio_bus_match(struct device_d *dev, struct driver_d *drv)struct phy_device *phydev =to_phy_device (dev);struct phy_driver *phydrv =to_phy_driver (drv); -return ((phydrv->phy_id & phydrv->phy_id_mask) == +return ((phydrv->phy_id & phydrv->phy_id_mask) != (phydev->phy_id & phydrv->phy_id_mask)); }
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/7 phylib: introduction of forced 100Mbps
In reply to Jean-Christophe PLAGNIOL-VILLARD--- drivers/net/phy/mdio_bus.c | 4 ++++ include/linux/phy.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/net/phy/mdio_bus.c +4 -0
@@ -175,6 +175,10 @@ static int mdio_bus_probe(struct device_d *_dev) dev->speed =SPEED_10 ; dev->duplex =DUPLEX_FULL ; dev->autoneg = !AUTONEG_ENABLE ; + }else if (dev->dev_flags &PHYLIB_FORCE_100 ) { + dev->speed =SPEED_100 ; + dev->duplex =DUPLEX_FULL ; + dev->autoneg = !AUTONEG_ENABLE ; } }
include/linux/phy.h +2 -1
@@ -60,7 +60,8 @@ typedef enum {#define MII_BUS_ID_SIZE (20 - 3)#define PHYLIB_FORCE_10 (1 << 0) -#define PHYLIB_FORCE_LINK (1 << 1) +#define PHYLIB_FORCE_100 (1 << 1) +#define PHYLIB_FORCE_LINK (1 << 2)#define PHYLIB_CAPABLE_1000M (1 << 0)
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/7 phylib: fix generic phy driver probe
In reply to Jean-Christophe PLAGNIOL-VILLARDthe generic phy driver is used if no driver are found
--- drivers/net/phy/Kconfig | 8 ++------ drivers/net/phy/Makefile | 1 - drivers/net/phy/generic.c | 36 ------------------------------------ drivers/net/phy/phy.c | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 45 deletions(-) delete mode 100644 drivers/net/phy/generic.c
drivers/net/phy/Kconfig +2 -6
@@ -8,15 +8,11 @@ if PHYLIB comment "MII PHY device drivers" -config GENERIC_PHY - bool "Drivers for the Generic PHYs" - default y - -endif - config SMSC_PHY bool "Drivers for SMSC PHYs" ---help--- Currently supports the LAN83C185, LAN8187 and LAN8700 PHYs +endif + endmenu
drivers/net/phy/Makefile +0 -1
@@ -1,3 +1,2 @@ obj-y += phy.o mdio_bus.o -obj-$(CONFIG_GENERIC_PHY) += generic.o obj-$(CONFIG_SMSC_PHY) += smsc.o
drivers/net/phy/generic.c deleted +0 -36
@@ -1,36 +0,0 @@ -/* -* Copyright (c) 2009 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, -* MA 02111-1307 USA -* -*/ - -#include <common.h> -#include <linux/phy.h> -#include <init.h> - -static struct phy_driver generic_phy = { - .drv.name ="Generic PHY" , - .phy_id =PHY_ANY_UID , - .phy_id_mask =PHY_ANY_UID , - .features =0 , -}; - -static int generic_phy_register (void ) -{ -return phy_driver_register (&generic_phy); -} -device_initcall (generic_phy_register);
drivers/net/phy/phy.c +32 -2
@@ -19,6 +19,7 @@#include <common.h> #include <driver.h> +#include <init.h> #include <net.h> #include <malloc.h> #include <linux/phy.h>
@@ -27,6 +28,7 @@#define PHY_AN_TIMEOUT 10 +static struct phy_driver genphy_driver;static int genphy_config_init (struct phy_device *phydev);int phy_update_status (struct phy_device *dev)
@@ -142,6 +144,21 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr)return dev; } +static int phy_register_device (struct phy_device * dev) +{ +int ret; + + ret =register_device (&dev->dev); +if (ret) +return ret; + +if (dev->dev.driver) +return 0 ; + + dev->dev.driver = &genphy_driver.drv; +return device_probe (&dev->dev); +} +/* Automatically gets and returns the PHY device */ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr, void (*adjust_link) (struct eth_device *edev),
@@ -164,7 +181,7 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr, dev->interface = interface; dev->dev_flags = flags; - ret =register_device (&dev->dev); + ret =phy_register_device (dev);if (ret) goto fail; }else {
@@ -181,7 +198,7 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr, dev->interface = interface; dev->dev_flags = flags; - ret =register_device (&dev->dev); + ret =phy_register_device (dev);if (ret) goto fail;
@@ -597,3 +614,16 @@ int phy_drivers_register(struct phy_driver *new_driver, int n) }return ret; } + +static struct phy_driver genphy_driver = { + .drv.name ="Generic PHY" , + .phy_id =PHY_ANY_UID , + .phy_id_mask =PHY_ANY_UID , + .features =0 , +}; + +static int generic_phy_register (void ) +{ +return phy_driver_register (&genphy_driver); +} +device_initcall (generic_phy_register);
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 7/7 phylib: add micrel support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- drivers/net/phy/Kconfig | 5 ++ drivers/net/phy/Makefile | 1 + drivers/net/phy/micrel.c | 174 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/micrel_phy.h | 30 ++++++++ 4 files changed, 210 insertions(+) create mode 100644 drivers/net/phy/micrel.c create mode 100644 include/linux/micrel_phy.h
drivers/net/phy/Kconfig +5 -0
@@ -8,6 +8,11 @@ if PHYLIB comment "MII PHY device drivers" +config MICREL_PHY + bool "Driver for Micrel PHYs" + ---help--- + Supports the KSZ9021, VSC8201, KS8001 PHYs. + config SMSC_PHY bool "Drivers for SMSC PHYs" ---help---
drivers/net/phy/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-y += phy.o mdio_bus.o +obj-$(CONFIG_MICREL_PHY) += micrel.o obj-$(CONFIG_SMSC_PHY) += smsc.o
drivers/net/phy/micrel.c new file +174 -0
174 lines not on this page · raw message
include/linux/micrel_phy.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* include/linux/micrel_phy.h +* +* Micrel PHY IDs +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +*/ + +#ifndef _MICREL_PHY_H +#define _MICREL_PHY_H + +#define MICREL_PHY_ID_MASK 0x00fffff0 + +#define PHY_ID_KSZ8873MLL 0x000e7237 +#define PHY_ID_KSZ9021 0x00221610 +#define PHY_ID_KS8737 0x00221720 +#define PHY_ID_KSZ8021 0x00221555 +#define PHY_ID_KSZ8041 0x00221510 +#define PHY_ID_KSZ8051 0x00221550 +/* both for ks8001 Rev. A/B, and for ks8721 Rev 3. */ +#define PHY_ID_KSZ8001 0x0022161A + +/* struct phy_device dev_flags definitions */ +#define MICREL_PHY_50MHZ_CLK 0x00000001 + +#endif /* _MICREL_PHY_H */
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 6/7 phylib: add fixup support
In reply to Jean-Christophe PLAGNIOL-VILLARDif board need specific phy fixup they can register it and then the code will executed only if needed
--- drivers/net/phy/mdio_bus.c | 19 +++++---- drivers/net/phy/phy.c | 96 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 18 +++++++++ 3 files changed, 125 insertions(+), 8 deletions(-)
drivers/net/phy/mdio_bus.c +11 -8
@@ -153,6 +153,7 @@ static int mdio_bus_probe(struct device_d *_dev)struct phy_device *dev =to_phy_device (_dev);struct phy_driver *drv =to_phy_driver (_dev->driver); +int ret;char str[16 ]; dev->attached_dev->phydev = dev;
@@ -160,14 +161,9 @@ static int mdio_bus_probe(struct device_d *_dev)dev_add_child (dev->dev.parent, _dev);if (drv->probe) { -int ret; - ret = drv->probe (dev); -if (ret) { - dev->attached_dev->phydev =NULL ; - dev->attached_dev =NULL ; -return ret; - } +if (ret) + goto err; }if (dev->dev_flags) {
@@ -188,7 +184,9 @@ static int mdio_bus_probe(struct device_d *_dev) dev->supported = drv->features; dev->advertising = drv->features; - drv->config_init (dev); + ret =phy_init_hw (dev); +if (ret) + goto err;/* Sanitize settings based on PHY capabilities */ if ((dev->supported & SUPPORTED_Autoneg) ==0 )
@@ -208,6 +206,11 @@ static int mdio_bus_probe(struct device_d *_dev)devfs_create (&dev->cdev);return 0 ; + +err: + dev->attached_dev->phydev =NULL ; + dev->attached_dev =NULL ; +return ret; }static void mdio_bus_remove (struct device_d *_dev)
drivers/net/phy/phy.c +96 -0
108 lines not on this page · raw message
include/linux/phy.h +18 -0
@@ -226,10 +226,20 @@ struct phy_driver {#define PHY_ANY_ID "MATCH ANY PHY"#define PHY_ANY_UID 0xffffffff +/* A Structure for boards to register fixups with the PHY Lib */ +struct phy_fixup { +struct list_head list; +char bus_id[20 ]; +u32 phy_uid; +u32 phy_uid_mask; +int (*run)(struct phy_device *phydev); +}; +int phy_driver_register (struct phy_driver *drv);int phy_drivers_register (struct phy_driver *new_driver,int n);struct phy_device *get_phy_device (struct mii_bus *bus,int addr);int phy_init (void ); +int phy_init_hw (struct phy_device *phydev);/** * phy_read - Convenience function for reading a given PHY register
@@ -267,5 +277,13 @@ int genphy_config_advert(struct phy_device *phydev);int genphy_setup_forced (struct phy_device *phydev);int get_phy_id (struct mii_bus *bus,int addr,u32 *phy_id); +int phy_register_fixup (const char *bus_id,u32 phy_uid,u32 phy_uid_mask, +int (*run)(struct phy_device *)); +int phy_register_fixup_for_id (const char *bus_id, +int (*run)(struct phy_device *)); +int phy_register_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask, +int (*run)(struct phy_device *)); +int phy_scan_fixups (struct phy_device *phydev); +extern struct bus_type mdio_bus_type;#endif /* __PHYDEV_H__ */
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
HI,
Today we have a bug on the match the logic is inverted. We are lucky as the generic Phy driver is not suppoed to match with any device it work so fix it. Ensure the generic phy driver is probe last if needed.
for mx53-loco we are lucky too the first phy found is the right one
The following changes since commit
272a5d738ab152347d67be062e8a4e771825493a:at91rm9200ek: add spi support (2012-11-16 15:33:50 +0100)
Quoted 7 lines
are available in the git repository at:
git://git.jcrosoft.org/barebox.gitdelivery/phylib_fixfor you to fetch changes up to
5ea00036e330ea58293774a36d3ee5f9c1fbe895:phylib: add micrel support (2012-11-16 23:11:16 +0800)
Applied, thanks
Sascha
Quoted 34 lines
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (7):
driver: introducedevice_probeto manully probe a device
phylib: fix generic phy driver probe
mdio_bus: fix match
phylib: exportphy_idvia param
phylib: introduction of forced 100Mbps
phylib: add fixup support
phylib: add micrel supportdrivers/base/driver.c | 23 +++++++++---- drivers/net/phy/Kconfig | 11 +++--- drivers/net/phy/Makefile | 2 +- drivers/net/phy/generic.c | 36 -------------------- drivers/net/phy/mdio_bus.c | 28 ++++++++++----- drivers/net/phy/micrel.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- include/driver.h | 5 +++ include/linux/micrel_phy.h | 30 ++++++++++++++++ include/linux/phy.h | 21 +++++++++++- 10 files changed, 400 insertions(+), 60 deletions(-) delete mode 100644 drivers/net/phy/generic.c create mode 100644 drivers/net/phy/micrel.c create mode 100644 include/linux/micrel_phy.hBest Regards,
J._______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox