Skip to contentSkip to conversation

net: introduce phylib

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 4 messages Sep 17, 2012

Subsystems (10)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover net: introduce phylib

HI,

v5:
- drop edev in mii_device

v4:
- move phy_dev attachement to eth_device instead of mii_device this will allow multiple phy_device per mii bus
- move phy cdev to phy_device
- add interface type support (so phy driver can configure themselves if MII/RMII/RGMII etc...
- manage link status at framework level
- mx6 update to fixup the phy at device opening

v3:
- fix comment
- add phy_driver probe and remove
- renambe phydev.h to phy.h and phylib.c to phy.c as in linux

please pull
The following changes since commit 0b3c3e77945243c262f9ff1275479e6d8ea1d5c3:

net: catch error on eth_send (2012-09-16 20:39:07 +0800)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git tags/net_phylib

for you to fetch changes up to bb8f85c7aac0c3354ab374d2df110d3df84a395f:

net: introduce phylib (2012-09-17 13:41:27 +0800)

----------------------------------------------------------------
net: check error and introduce phylib

Adapt phylib from linux

This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready or down fail on open

Same behaviour as in linux and will allow to share code and simplify porting.

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (1):
net: introduce phylib

 arch/arm/boards/freescale-mx6-arm2/board.c      |   41 ++++-----
 arch/arm/boards/freescale-mx6-sabrelite/board.c |   38 +++------
 drivers/net/Kconfig                             |    2 +
 drivers/net/Makefile                            |    2 +-
 drivers/net/altera_tse.c                        |   27 +++---
 drivers/net/altera_tse.h                        |    1 +
 drivers/net/at91_ether.c                        |   32 ++++---
 drivers/net/designware.c                        |   45 +++++-----
 drivers/net/dm9k.c                              |   23 ++---
 drivers/net/ep93xx.c                            |   14 ++-
 drivers/net/fec_imx.c                           |   72 ++++++++++------
 drivers/net/fec_imx.h                           |    4 +
 drivers/net/fec_mpc5200.c                       |   34 +++++---
 drivers/net/fec_mpc5200.h                       |    2 +
 drivers/net/gianfar.c                           |   46 +++++-----
 drivers/net/ks8851_mll.c                        |   21 ++---
 drivers/net/macb.c                              |   64 ++++++++------
 drivers/net/miidev.c                            |  250 +----------------------------------------------------
 drivers/net/netx_eth.c                          |    9 +-
 drivers/net/phy/Kconfig                         |   17 ++++
 drivers/net/phy/Makefile                        |    2 +
 drivers/net/phy/generic.c                       |   36 ++++++++
 drivers/net/phy/phy.c                           |  687 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/smc91111.c                          |   30 +++----
 drivers/net/smc911x.c                           |   20 ++---
 drivers/net/usb/asix.c                          |   11 +--
 drivers/net/usb/smsc95xx.c                      |   11 +--
 drivers/net/usb/usbnet.c                        |   11 +--
 include/fec.h                                   |    3 +
 include/linux/ethtool.h                         |  114 +++++++++++++++++++++++++
 include/linux/mii.h                             |  421 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
 include/linux/phy.h                             |  206 ++++++++++++++++++++++++++++++++++++++++++++
 include/miidev.h                                |   21 +----
 include/net.h                                   |    4 +
 include/usb/usbnet.h                            |    1 +
 net/eth.c                                       |    6 +-
 36 files changed, 1673 insertions(+), 655 deletions(-)
 create mode 100644 drivers/net/phy/Kconfig
 create mode 100644 drivers/net/phy/Makefile
 create mode 100644 drivers/net/phy/generic.c
 create mode 100644 drivers/net/phy/phy.c
 create mode 100644 include/linux/ethtool.h
 create mode 100644 include/linux/phy.h

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH v5 1/1 net: introduce phylib

Adapt phylib from linux

switch all the driver to it

This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready or not up fail on open

Same behaviour as in linux and will allow to share code and simplify porting.

---
 arch/arm/boards/freescale-mx6-arm2/board.c      |   41 +-
 arch/arm/boards/freescale-mx6-sabrelite/board.c |   38 +-
 drivers/net/Kconfig                             |    2 +
 drivers/net/Makefile                            |    2 +-
 drivers/net/altera_tse.c                        |   27 +-
 drivers/net/altera_tse.h                        |    1 +
 drivers/net/at91_ether.c                        |   32 +-
 drivers/net/designware.c                        |   45 +-
 drivers/net/dm9k.c                              |   23 +-
 drivers/net/ep93xx.c                            |   14 +-
 drivers/net/fec_imx.c                           |   72 ++-
 drivers/net/fec_imx.h                           |    4 +
 drivers/net/fec_mpc5200.c                       |   34 +-
 drivers/net/fec_mpc5200.h                       |    2 +
 drivers/net/gianfar.c                           |   46 +-
 drivers/net/ks8851_mll.c                        |   21 +-
 drivers/net/macb.c                              |   64 ++-
 drivers/net/miidev.c                            |  384 +++----------
 drivers/net/netx_eth.c                          |    9 +-
 drivers/net/phy/Kconfig                         |   17 +
 drivers/net/phy/Makefile                        |    2 +
 include/fec.h => drivers/net/phy/generic.c      |   43 +-
 drivers/net/phy/phy.c                           |  687 +++++++++++++++++++++++
 drivers/net/smc91111.c                          |   30 +-
 drivers/net/smc911x.c                           |   20 +-
 drivers/net/usb/asix.c                          |   11 +-
 drivers/net/usb/smsc95xx.c                      |   11 +-
 drivers/net/usb/usbnet.c                        |   11 +-
 include/fec.h                                   |    3 +
 include/linux/ethtool.h                         |  114 ++++
 include/linux/mii.h                             |  675 ++++++++++++++--------
 include/linux/phy.h                             |  206 +++++++
 include/miidev.h                                |   21 +-
 include/net.h                                   |    4 +
 include/usb/usbnet.h                            |    1 +
 net/eth.c                                       |    6 +-
 36 files changed, 1846 insertions(+), 877 deletions(-)
 rewrite drivers/net/miidev.c (76%)
 create mode 100644 drivers/net/phy/Kconfig
 create mode 100644 drivers/net/phy/Makefile
 copy include/fec.h => drivers/net/phy/generic.c (53%)
 create mode 100644 drivers/net/phy/phy.c
 create mode 100644 include/linux/ethtool.h
 rewrite include/linux/mii.h (70%)
 create mode 100644 include/linux/phy.h
arch/arm/boards/freescale-mx6-arm2/board.c +15 -26
index e4a9a49..b9948ab 100644
@@ -104,50 +104,39 @@ static int arm2_mem_init(void)
 }
 mem_initcall(arm2_mem_init);
 
-static struct fec_platform_data fec_info = {
-	.xcv_type = RGMII,
-	.phy_addr = 0,
-};
-
-static int mx6_rgmii_rework(void)
+static void mx6_rgmii_rework(struct phy_device *dev)
 {
-	struct mii_device *mdev;
 	u16 val;
 
-	mdev = mii_open("phy0");
-	if (!mdev) {
-		printf("unable to open phy0\n");
-		return -ENODEV;
-	}
-
 	/* To enable AR8031 ouput a 125MHz clk from CLK_25M */
-	mii_write(mdev, mdev->address, 0xd, 0x7);
-	mii_write(mdev, mdev->address, 0xe, 0x8016);
-	mii_write(mdev, mdev->address, 0xd, 0x4007);
+	phy_write(dev, 0xd, 0x7);
+	phy_write(dev, 0xe, 0x8016);
+	phy_write(dev, 0xd, 0x4007);
 
-	val = mii_read(mdev, mdev->address, 0xe);
+	val = phy_read(dev, 0xe);
 	val &= 0xffe3;
 	val |= 0x18;
-	mii_write(mdev, mdev->address, 0xe, val);
+	phy_write(dev, 0xe, val);
 
 	/* introduce tx clock delay */
-	mii_write(mdev, mdev->address, 0x1d, 0x5);
+	phy_write(dev, 0x1d, 0x5);
 
-	val = mii_read(mdev, mdev->address, 0x1e);
+	val = phy_read(dev, 0x1e);
 	val |= 0x0100;
-	mii_write(mdev, mdev->address, 0x1e, val);
-
-	mii_close(mdev);
-
-	return 0;
+	phy_write(dev, 0x1e, val);
 }
 
+static struct fec_platform_data fec_info = {
+	.xcv_type = RGMII,
+	.phy_init = mx6_rgmii_rework,
+	.phy_addr = 0,
+};
+
 static int arm2_devices_init(void)
 {
 	imx6_add_mmc3(NULL);
 
 	imx6_add_fec(&fec_info);
-	mx6_rgmii_rework();
 
 	armlinux_set_bootparams((void *)0x10000100);
 	armlinux_set_architecture(3837);
arch/arm/boards/freescale-mx6-sabrelite/board.c +13 -25
index c5bcf8b..43ef28e 100644
@@ -136,38 +136,27 @@ static int sabrelite_mem_init(void)
 }
 mem_initcall(sabrelite_mem_init);
 
-static struct fec_platform_data fec_info = {
-	.xcv_type = RGMII,
-	.phy_addr = 6,
-};
-
-int mx6_rgmii_rework(void)
+static void mx6_rgmii_rework(struct phy_device *dev)
 {
-	struct mii_device *mdev;
-
-	mdev = mii_open("phy0");
-	if (!mdev) {
-		printf("unable to open phy0\n");
-		return -ENODEV;
-	}
-
-	mii_write(mdev, mdev->address, 0x09, 0x0f00);
+	phy_write(dev, 0x09, 0x0f00);
 
 	/* do same as linux kernel */
 	/* min rx data delay */
-	mii_write(mdev, mdev->address, 0x0b, 0x8105);
-	mii_write(mdev, mdev->address, 0x0c, 0x0000);
+	phy_write(dev, 0x0b, 0x8105);
+	phy_write(dev, 0x0c, 0x0000);
 
 	/* max rx/tx clock delay, min rx/tx control delay */
-	mii_write(mdev, mdev->address, 0x0b, 0x8104);
-	mii_write(mdev, mdev->address, 0x0c, 0xf0f0);
-	mii_write(mdev, mdev->address, 0x0b, 0x104);
-
-	mii_close(mdev);
-
-	return 0;
+	phy_write(dev, 0x0b, 0x8104);
+	phy_write(dev, 0x0c, 0xf0f0);
+	phy_write(dev, 0x0b, 0x104);
 }
 
+static struct fec_platform_data fec_info = {
+	.xcv_type = RGMII,
+	.phy_init = mx6_rgmii_rework,
+	.phy_addr = 6,
+};
+
 static int sabrelite_ksz9021rn_setup(void)
 {
 	mxc_iomux_v3_setup_multiple_pads(sabrelite_enet_pads, ARRAY_SIZE(sabrelite_enet_pads));
@@ -266,7 +255,6 @@ static int sabrelite_devices_init(void)
 	sabrelite_ksz9021rn_setup();
 	imx6_iim_register_fec_ethaddr();
 	imx6_add_fec(&fec_info);
-	mx6_rgmii_rework();
 
 	sabrelite_ehci_init();
 
drivers/net/Kconfig +2 -0
index 3c5f729..c2b2095 100644
@@ -25,6 +25,8 @@ config MIIDEV
 menu "Network drivers               "
 	depends on NET
 
+source "drivers/net/phy/Kconfig"
+
 config DRIVER_NET_CS8900
 	bool "cs8900 ethernet driver"
 	depends on HAS_CS8900
drivers/net/Makefile +1 -1
index 4d960e8..8a23900 100644
@@ -9,7 +9,7 @@ obj-$(CONFIG_DRIVER_NET_FEC_IMX)	+= fec_imx.o
 obj-$(CONFIG_DRIVER_NET_EP93XX)		+= ep93xx.o
 obj-$(CONFIG_DRIVER_NET_MACB)		+= macb.o
 obj-$(CONFIG_DRIVER_NET_TAP)		+= tap.o
-obj-$(CONFIG_MIIDEV)			+= miidev.o
+obj-$(CONFIG_MIIDEV)			+= miidev.o phy/
 obj-$(CONFIG_NET_USB)			+= usb/
 obj-$(CONFIG_DRIVER_NET_TSE)		+= altera_tse.o
 obj-$(CONFIG_DRIVER_NET_KS8851_MLL)	+= ks8851_mll.o
drivers/net/altera_tse.c +12 -15
index 5353a68..c3bb0f1 100644
@@ -30,6 +30,7 @@
 #include <init.h>
 #include <clock.h>
 #include <linux/mii.h>
+#include <linux/phy.h>
 
 #include <io.h>
 #include <asm/dma-mapping.h>
@@ -249,8 +250,7 @@ static int tse_set_ethaddr(struct eth_device *edev, unsigned char *m)
 
 static int tse_phy_read(struct mii_device *mdev, int phy_addr, int reg)
 {
-	struct eth_device *edev = mdev->edev;
-	struct altera_tse_priv *priv = edev->priv;
+	struct altera_tse_priv *priv = mdev->priv;
 	struct alt_tse_mac *mac_dev = priv->tse_regs;
 	uint32_t *mdio_regs;
 
@@ -263,8 +263,7 @@ static int tse_phy_read(struct mii_device *mdev, int phy_addr, int reg)
 
 static int tse_phy_write(struct mii_device *mdev, int phy_addr, int reg, int val)
 {
-	struct eth_device *edev = mdev->edev;
-	struct altera_tse_priv *priv = edev->priv;
+	struct altera_tse_priv *priv = mdev->priv;
 	struct alt_tse_mac *mac_dev = priv->tse_regs;
 	uint32_t *mdio_regs;
 
@@ -347,9 +346,12 @@ static void tse_reset(struct eth_device *edev)
 static int tse_eth_open(struct eth_device *edev)
 {
 	struct altera_tse_priv *priv = edev->priv;
+	int ret;
 
-	miidev_wait_aneg(priv->miidev);
-	miidev_print_status(priv->miidev);
+	ret = phy_device_connect(edev, priv->miidev, priv->phy_addr, NULL, 0,
+				 PHY_INTERFACE_MODE_NA);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -488,8 +490,6 @@ static int tse_init_dev(struct eth_device *edev)
 	/* enable MAC */
 	writel(ALTERA_TSE_CMD_TX_ENA_MSK | ALTERA_TSE_CMD_RX_ENA_MSK, &mac_dev->command_config);
 
-	miidev_restart_aneg(priv->miidev);
-
 	return 0;
 }
 
@@ -545,16 +545,13 @@ static int tse_probe(struct device_d *dev)
 
 	miidev->read = tse_phy_read;
 	miidev->write = tse_phy_write;
-	miidev->flags = 0;
-	miidev->edev = edev;
+	miidev->priv = priv;
 	miidev->parent = dev;
 
 	if (dev->platform_data != NULL)
-		miidev->address = *((int8_t *)(dev->platform_data));
-	else {
-		printf("No PHY address specified.\n");
-		return -ENODEV;
-	}
+		priv->phy_addr = *((int8_t *)(dev->platform_data));
+	else
+		priv->phy_addr = -1;
 
 	mii_register(miidev);
 
drivers/net/altera_tse.h +1 -0
index 866dbce..d860d9c 100644
@@ -292,6 +292,7 @@ struct altera_tse_priv {
 	void __iomem *sgdma_tx_regs;
 	void __iomem *rx_desc;
 	void __iomem *tx_desc;
+	int phy_addr;
 	struct mii_device *miidev;
 };
 
drivers/net/at91_ether.c +18 -14
index 3592141..b28a088 100644
@@ -40,18 +40,18 @@
 #include <linux/mii.h>
 #include <errno.h>
 #include <asm/mmu.h>
+#include <linux/phy.h>
 
 #include "at91_ether.h"
 
-#define SPEED_100 1
-#define DUPLEX_FULL 1
-
 struct ether_device {
 	struct eth_device netdev;
 	struct mii_device miidev;
 	struct rbf_t *rbfp;
 	struct rbf_t *rbfdt;
 	unsigned char *rbf_framebuf;
+	int phy_addr;
+	phy_interface_t interface;
 };
 #define to_ether(_nd) container_of(_nd, struct ether_device, netdev)
 
@@ -136,19 +136,19 @@ static int at91_ether_mii_write(struct mii_device *dev, int addr, int reg, int v
 	return ret;
 }
 
-static void update_linkspeed(struct mii_device *dev, int speed, int duplex)
+static void update_linkspeed(struct eth_device *edev)
 {
 	unsigned int mac_cfg;
 
 	/* Update the MAC */
 	mac_cfg = at91_emac_read(AT91_EMAC_CFG) & ~(AT91_EMAC_SPD | AT91_EMAC_FD);
-	if (speed == SPEED_100) {
-		if (duplex == DUPLEX_FULL)	/* 100 Full Duplex */
+	if (edev->phydev->speed == SPEED_100) {
+		if (edev->phydev->duplex)
 			mac_cfg |= AT91_EMAC_SPD | AT91_EMAC_FD;
 		else					/* 100 Half Duplex */
 			mac_cfg |= AT91_EMAC_SPD;
 	} else {
-		if (duplex == DUPLEX_FULL)	/* 10 Full Duplex */
+		if (edev->phydev->duplex)
 			mac_cfg |= AT91_EMAC_FD;
 		else {}					/* 10 Half Duplex */
 	}
@@ -161,11 +161,12 @@ static int at91_ether_open(struct eth_device *edev)
 	unsigned long ctl;
 	struct ether_device *etdev = to_ether(edev);
 	unsigned char *rbf_framebuf = etdev->rbf_framebuf;
+	int ret;
 
-	miidev_wait_aneg(&etdev->miidev);
-	miidev_print_status(&etdev->miidev);
-
-	update_linkspeed(&etdev->miidev, SPEED_100, DUPLEX_FULL);
+	ret = phy_device_connect(edev, &etdev->miidev, etdev->phy_addr,
+				 update_linkspeed, 0, etdev->interface);
+	if (ret)
+		return ret;
 
 	/* Clear internal statistics */
 	ctl = at91_emac_read(AT91_EMAC_CTL);
@@ -327,10 +328,9 @@ static int at91_ether_probe(struct device_d *dev)
 	ether_dev->rbf_framebuf = dma_alloc_coherent(MAX_RX_DESCR * MAX_RBUFF_SZ);
 	ether_dev->rbfdt = dma_alloc_coherent(sizeof(struct rbf_t) * MAX_RX_DESCR);
 
-	miidev->address = pdata->phy_addr;
+	ether_dev->phy_addr = pdata->phy_addr;
 	miidev->read = at91_ether_mii_read;
 	miidev->write = at91_ether_mii_write;
-	miidev->edev = edev;
 
 	/* Sanitize the clocks */
 	mac_cfg = at91_emac_read(AT91_EMAC_CFG);
@@ -347,8 +347,12 @@ static int at91_ether_probe(struct device_d *dev)
 
 	mac_cfg |= AT91_EMAC_CLK_DIV32 | AT91_EMAC_BIG;
 
-	if (pdata->flags & AT91SAM_ETHER_RMII)
+	if (pdata->flags & AT91SAM_ETHER_RMII) {
+		ether_dev->interface = PHY_INTERFACE_MODE_RGMII;
 		mac_cfg |= AT91_EMAC_RMII;
+	} else {
+		ether_dev->interface = PHY_INTERFACE_MODE_MII;
+	}
 
 	at91_emac_write(AT91_EMAC_CFG, mac_cfg);
 
drivers/net/designware.c +25 -20

95 lines not on this page · raw message

drivers/net/dm9k.c +8 -15
index 0222d98..6387370 100644
@@ -32,6 +32,7 @@
 #include <xfuncs.h>
 #include <dm9000.h>
 #include <errno.h>
+#include <linux/phy.h>
 
 #define DM9K_ID		0x90000A46
 #define CHIPR_DM9000A	0x19
@@ -356,9 +357,8 @@ static void dm9k_wd(int b_width, void __iomem *port, const void *src, int length
 static int dm9k_phy_read(struct mii_device *mdev, int addr, int reg)
 {
 	unsigned val;
-	struct eth_device *edev = mdev->edev;
-	struct device_d *dev = edev->parent;
-	struct dm9k *priv = edev->priv;
+	struct dm9k *priv = mdev->priv;
+	struct device_d *dev = &mdev->dev;
 
 	/* Fill the phyxcer register into REG_0C */
 	dm9k_iow(priv, DM9K_EPAR, DM9K_PHY | reg);
@@ -376,9 +376,8 @@ static int dm9k_phy_read(struct mii_device *mdev, int addr, int reg)
 
 static int dm9k_phy_write(struct mii_device *mdev, int addr, int reg, int val)
 {
-	struct eth_device *edev = mdev->edev;
-	struct device_d *dev = edev->parent;
-	struct dm9k *priv = edev->priv;
+	struct dm9k *priv = mdev->priv;
+	struct device_d *dev = &mdev->dev;
 
 	/* Fill the phyxcer register into REG_0C */
 	dm9k_iow(priv, DM9K_EPAR, DM9K_PHY | reg);
@@ -472,9 +471,8 @@ static int dm9k_eth_open(struct eth_device *edev)
 {
 	struct dm9k *priv = (struct dm9k *)edev->priv;
 
-	miidev_wait_aneg(&priv->miidev);
-	miidev_print_status(&priv->miidev);
-	return 0;
+	return phy_device_connect(edev, &priv->miidev, 0, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
 }
 
 static void dm9k_write_length(struct dm9k *priv, unsigned length)
@@ -696,9 +694,6 @@ static int dm9k_set_ethaddr(struct eth_device *edev, unsigned char *adr)
 
 static int dm9k_init_dev(struct eth_device *edev)
 {
-	struct dm9k *priv = (struct dm9k *)edev->priv;
-
-	miidev_restart_aneg(&priv->miidev);
 	return 0;
 }
 
@@ -742,9 +737,7 @@ static int dm9k_probe(struct device_d *dev)
 
 	priv->miidev.read = dm9k_phy_read;
 	priv->miidev.write = dm9k_phy_write;
-	priv->miidev.address = 0;
-	priv->miidev.flags = 0;
-	priv->miidev.edev = edev;
+	priv->miidev.priv = priv;
 	priv->miidev.parent = dev;
 
 	/* RESET device */
drivers/net/ep93xx.c +10 -4
index c28fb79..a0500e4 100644
@@ -38,6 +38,7 @@
 #include <io.h>
 #include <linux/types.h>
 #include <mach/ep93xx-regs.h>
+#include <linux/phy.h>
 #include "ep93xx.h"
 
 #define EP93XX_MAX_PKT_SIZE    1536
@@ -199,9 +200,15 @@ static int ep93xx_eth_open(struct eth_device *edev)
 	struct ep93xx_eth_priv *priv = ep93xx_get_priv(edev);
 	struct mac_regs *regs = ep93xx_get_regs(edev);
 	int i;
+	int ret;
 
 	pr_debug("+ep93xx_eth_open\n");
 
+	ret = phy_device_connect(edev, &priv->miidev, 0, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
+	if (ret)
+		return ret;
+
 	ep93xx_eth_reset(edev);
 
 	/* Reset the descriptor queues' current and end address values */
@@ -500,9 +507,8 @@ static int ep93xx_eth_probe(struct device_d *dev)
 
 	priv->miidev.read = ep93xx_phy_read;
 	priv->miidev.write = ep93xx_phy_write;
-	priv->miidev.address = 0;
-	priv->miidev.flags = 0;
 	priv->miidev.parent = dev;
+	priv->miidev.priv = edev;
 
 	priv->tx_dq.base = calloc(NUMTXDESC,
 				sizeof(struct tx_descriptor));
@@ -577,7 +583,7 @@ eth_probe_done:
  */
 static int ep93xx_phy_read(struct mii_device *mdev, int phy_addr, int phy_reg)
 {
-	struct mac_regs *regs = ep93xx_get_regs(mdev->edev);
+	struct mac_regs *regs = ep93xx_get_regs(mdev->priv);
 	int value = -1;
 	uint32_t self_ctl;
 
@@ -621,7 +627,7 @@ static int ep93xx_phy_read(struct mii_device *mdev, int phy_addr, int phy_reg)
 static int ep93xx_phy_write(struct mii_device *mdev, int phy_addr,
 			int phy_reg, int value)
 {
-	struct mac_regs *regs = ep93xx_get_regs(mdev->edev);
+	struct mac_regs *regs = ep93xx_get_regs(mdev->priv);
 	uint32_t self_ctl;
 
 	pr_debug("+ep93xx_phy_write\n");
drivers/net/fec_imx.c +44 -28

119 lines not on this page · raw message

drivers/net/fec_imx.h +4 -0
index b75b4d6..7f5da47 100644
@@ -137,7 +137,11 @@ struct fec_priv {
 	int rbd_index;				/* next receive BD to read   */
 	struct buffer_descriptor __iomem *tbd_base;	/* TBD ring                  */
 	int tbd_index;				/* next transmit BD to write */
+	int phy_addr;
+	phy_interface_t interface;
+	u32 phy_flags;
 	struct mii_device miidev;
+	void (*phy_init)(struct phy_device *dev);
 };
 
 /**
drivers/net/fec_mpc5200.c +22 -12
index c3f2099..e16f762 100644
@@ -17,6 +17,7 @@
 #include <mach/fec.h>
 #include <mach/clocks.h>
 #include <miidev.h>
+#include <linux/phy.h>
 #include "fec_mpc5200.h"
 
 #define CONFIG_PHY_ADDR 1 /* FIXME */
@@ -33,8 +34,7 @@ typedef struct {
  */
 static int fec5xxx_miidev_read(struct mii_device *mdev, int phyAddr, int regAddr)
 {
-	struct eth_device *edev = mdev->edev;
-	mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)edev->priv;
+	mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)mdev->priv;
 
 	uint32_t reg;		/* convenient holder for the PHY register */
 	uint32_t phy;		/* convenient holder for the PHY */
@@ -73,8 +73,7 @@ static int fec5xxx_miidev_read(struct mii_device *mdev, int phyAddr, int regAddr
 static int fec5xxx_miidev_write(struct mii_device *mdev, int phyAddr,
 	int regAddr, int data)
 {
-	struct eth_device *edev = mdev->edev;
-	mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)edev->priv;
+	mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)mdev->priv;
 
 	uint32_t reg;		/* convenient holder for the PHY register */
 	uint32_t phy;		/* convenient holder for the PHY */
@@ -381,9 +380,6 @@ static int mpc5xxx_fec_init(struct eth_device *dev)
 
 	debug("mpc5xxx_fec_init... Done \n");
 
-	if (fec->xcv_type != SEVENWIRE)
-		miidev_restart_aneg(&fec->miidev);
-
 	return 0;
 }
 
@@ -413,8 +409,8 @@ static int mpc5xxx_fec_open(struct eth_device *edev)
 	SDMA_TASK_ENABLE(FEC_RECV_TASK_NO);
 
 	if (fec->xcv_type != SEVENWIRE) {
-		miidev_wait_aneg(&fec->miidev);
-		miidev_print_status(&fec->miidev);
+		return phy_device_connect(edev, &fec->miidev, CONFIG_PHY_ADDR,
+				 NULL, fec->phy_flags, fec->interface);
 	}
 
 	return 0;
@@ -685,9 +681,23 @@ int mpc5xxx_fec_probe(struct device_d *dev)
 	if (fec->xcv_type != SEVENWIRE) {
 		fec->miidev.read = fec5xxx_miidev_read;
 		fec->miidev.write = fec5xxx_miidev_write;
-		fec->miidev.address = CONFIG_PHY_ADDR;
-		fec->miidev.flags = pdata->xcv_type == MII10 ? MIIDEV_FORCE_10 : 0;
-		fec->miidev.edev = edev;
+		switch (pdata->xcv_type) {
+		case RMII:
+			fec->interface = PHY_INTERFACE_MODE_RMII;
+			break;
+		case RGMII:
+			fec->interface = PHY_INTERFACE_MODE_RGMII;
+			break;
+		case MII10:
+			fec->phy_flags = MIIDEV_FORCE_10;
+		case MII100:
+			fec->interface = PHY_INTERFACE_MODE_MII;
+			break;
+		case SEVENWIRE:
+			fec->interface = PHY_INTERFACE_MODE_NA;
+			break;
+		}
+		fec->miidev.priv = fec;
 		fec->miidev.parent = dev;
 
 		mii_register(&fec->miidev);
drivers/net/fec_mpc5200.h +2 -0
index f6da3e5..db0bbda 100644
@@ -260,6 +260,8 @@ typedef struct {
 	uint16_t usedTbdIndex;		/* next transmit BD to clean */
 	uint16_t cleanTbdNum;		/* the number of available transmit BDs */
 
+	phy_interface_t interface;
+	u32 phy_flags;
 	struct mii_device miidev;
 } mpc5xxx_fec_priv;
 
drivers/net/gianfar.c +19 -27

115 lines not on this page · raw message

drivers/net/ks8851_mll.c +9 -12
index 71391cc..ddfc4c8 100644
@@ -33,6 +33,7 @@
 #include <errno.h>
 #include <clock.h>
 #include <io.h>
+#include <linux/phy.h>
 
 #define MAX_RECV_FRAMES			32
 #define MAX_BUF_SIZE			2048
@@ -538,8 +539,7 @@ static int ks_phy_reg(int reg)
  */
 static int ks_phy_read(struct mii_device *mdev, int addr, int reg)
 {
-	struct eth_device *edev = mdev->edev;
-	struct ks_net *priv = (struct ks_net *)edev->priv;
+	struct ks_net *priv = (struct ks_net *)mdev->priv;
 	int ksreg;
 	int result;
 
@@ -554,8 +554,7 @@ static int ks_phy_read(struct mii_device *mdev, int addr, int reg)
 
 static int ks_phy_write(struct mii_device *mdev, int addr, int reg, int val)
 {
-	struct eth_device *edev = mdev->edev;
-	struct ks_net *priv = (struct ks_net *)edev->priv;
+	struct ks_net *priv = (struct ks_net *)mdev->priv;
 	int ksreg;
 
 	ksreg = ks_phy_reg(reg);
@@ -783,11 +782,14 @@ static int ks8851_eth_open(struct eth_device *edev)
 {
 	struct ks_net *priv = (struct ks_net *)edev->priv;
 	struct device_d *dev = &edev->dev;
+	int ret;
 
 	ks_enable_qmu(priv);
 
-	miidev_wait_aneg(&priv->miidev);
-	miidev_print_status(&priv->miidev);
+	ret = phy_device_connect(edev, &priv->miidev, 1, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
+	if (ret)
+		return ret;
 
 	dev_dbg(dev, "eth_open\n");
 
@@ -796,9 +798,6 @@ static int ks8851_eth_open(struct eth_device *edev)
 
 static int ks8851_init_dev(struct eth_device *edev)
 {
-	struct ks_net *priv = (struct ks_net *)edev->priv;
-
-	miidev_restart_aneg(&priv->miidev);
 	return 0;
 }
 
@@ -844,9 +843,7 @@ static int ks8851_probe(struct device_d *dev)
 	/* setup mii state */
 	ks->miidev.read = ks_phy_read;
 	ks->miidev.write = ks_phy_write;
-	ks->miidev.address = 1;
-	ks->miidev.flags = 0;
-	ks->miidev.edev = edev;
+	ks->miidev.priv = ks;
 	ks->miidev.parent = dev;
 
 	/* simple check for a valid chip being connected to the bus */
drivers/net/macb.c +39 -25

118 lines not on this page · raw message

drivers/net/miidev.c +68 -316

384 lines not on this page · raw message

drivers/net/netx_eth.c +5 -4
index 2d92a2e..853df50 100644
@@ -9,6 +9,7 @@
 #include <xfuncs.h>
 #include <init.h>
 #include <driver.h>
+#include <linux/phy.h>
 
 #define ETH_MAC_LOCAL_CONFIG 0x1560
 #define ETH_MAC_4321         0x1564
@@ -189,13 +190,15 @@ static int netx_eth_init_dev(struct eth_device *edev)
 	for (i = 2; i <= 18; i++)
 		PFIFO_REG( PFIFO_BASE(EMPTY_PTR_FIFO(xcno)) ) = FIFO_PTR_FRAMENO(i) | FIFO_PTR_SEGMENT(xcno);
 
-	miidev_restart_aneg(&priv->miidev);
 	return 0;
 }
 
 static int netx_eth_open(struct eth_device *edev)
 {
-	return 0;
+	struct netx_eth_priv *priv = (struct netx_eth_priv *)edev->priv;
+
+	return phy_device_connect(edev, &priv->miidev, 0, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
 }
 
 static void netx_eth_halt (struct eth_device *edev)
@@ -261,8 +264,6 @@ static int netx_eth_probe(struct device_d *dev)
 
 	priv->miidev.read = netx_miidev_read;
 	priv->miidev.write = netx_miidev_write;
-	priv->miidev.address = 0;
-	priv->miidev.flags = 0;
 	priv->miidev.parent = dev;
 
 	netx_eth_init_phy();
drivers/net/phy/Kconfig new file +17 -0
new file mode 100644
index 0000000..b071057
@@ -0,0 +1,17 @@
+#
+# PHY Layer Configuration
+#
+
+menu "phylib                       "
+
+if MIIDEV
+
+comment "MII PHY device drivers"
+
+config GENERIC_PHY
+	bool "Drivers for the Generic PHYs"
+	default y
+
+endif
+
+endmenu
drivers/net/phy/Makefile new file +2 -0
new file mode 100644
index 0000000..72cf685
@@ -0,0 +1,2 @@
+obj-y += phy.o
+obj-$(CONFIG_GENERIC_PHY) += generic.o
drivers/net/phy/generic.c renamed from include/fec.h +15 -28

55 lines not on this page · raw message

drivers/net/phy/phy.c new file +687 -0

687 lines not on this page · raw message

drivers/net/smc91111.c +11 -19
index cbd9f48..7826112 100644
@@ -74,6 +74,7 @@
 #include <errno.h>
 #include <clock.h>
 #include <io.h>
+#include <linux/phy.h>
 
 /*---------------------------------------------------------------
  .
@@ -624,8 +625,7 @@ static void smc_wait_mmu_release_complete(struct smc91c111_priv *priv)
 static int smc91c111_phy_write(struct mii_device *mdev, int phyaddr,
 	int phyreg, int phydata)
 {
-	struct eth_device *edev = mdev->edev;
-	struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv;
+	struct smc91c111_priv *priv = (struct smc91c111_priv *)mdev->priv;
 	int oldBank;
 	int i;
 	unsigned mask;
@@ -725,8 +725,7 @@ static int smc91c111_phy_write(struct mii_device *mdev, int phyaddr,
 
 static int smc91c111_phy_read(struct mii_device *mdev, int phyaddr, int phyreg)
 {
-	struct eth_device *edev = mdev->edev;
-	struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv;
+	struct smc91c111_priv *priv = (struct smc91c111_priv *)mdev->priv;
 	int oldBank;
 	int i;
 	unsigned char mask;
@@ -892,12 +891,15 @@ static void smc91c111_enable(struct eth_device *edev)
 static int smc91c111_eth_open(struct eth_device *edev)
 {
 	struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv;
-	smc91c111_enable(edev);
 
-	miidev_wait_aneg(&priv->miidev);
-	miidev_print_status(&priv->miidev);
+	/* Configure the Receive/Phy Control register */
+	SMC_SELECT_BANK(priv, 0);
+	SMC_outw(priv, RPC_DEFAULT, RPC_REG);
 
-	return 0;
+	smc91c111_enable(edev);
+
+	return phy_device_connect(edev, &priv->miidev, 0, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
 }
 
 static int smc91c111_eth_send(struct eth_device *edev, void *packet,
@@ -1279,14 +1281,6 @@ static void print_packet( unsigned char * buf, int length )
 
 static int smc91c111_init_dev(struct eth_device *edev)
 {
-	struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv;
-
-	/* Configure the Receive/Phy Control register */
-	SMC_SELECT_BANK(priv, 0);
-	SMC_outw(priv, RPC_DEFAULT, RPC_REG);
-
-	miidev_restart_aneg(&priv->miidev);
-
 	return 0;
 }
 
@@ -1314,9 +1308,7 @@ static int smc91c111_probe(struct device_d *dev)
 
 	priv->miidev.read = smc91c111_phy_read;
 	priv->miidev.write = smc91c111_phy_write;
-	priv->miidev.address = 0;
-	priv->miidev.flags = 0;
-	priv->miidev.edev = edev;
+	priv->miidev.priv = priv;
 	priv->miidev.parent = dev;
 	priv->base = dev_request_mem_region(dev, 0);
 
drivers/net/smc911x.c +9 -11
index f697608..20591bf 100644
@@ -38,6 +38,7 @@
 #include <clock.h>
 #include <io.h>
 #include <smc911x.h>
+#include <linux/phy.h>
 
 #include "smc911x.h"
 
@@ -200,7 +201,7 @@ static int smc911x_set_ethaddr(struct eth_device *edev, unsigned char *m)
 
 static int smc911x_phy_read(struct mii_device *mdev, int phy_addr, int reg)
 {
-	struct eth_device *edev = mdev->edev;
+	struct eth_device *edev = mdev->priv;
 
 	while (smc911x_get_mac_csr(edev, MII_ACC) & MII_ACC_MII_BUSY);
 
@@ -215,7 +216,7 @@ static int smc911x_phy_read(struct mii_device *mdev, int phy_addr, int reg)
 static int smc911x_phy_write(struct mii_device *mdev, int phy_addr,
 	int reg, int val)
 {
-	struct eth_device *edev = mdev->edev;
+	struct eth_device *edev = mdev->priv;
 
 	while (smc911x_get_mac_csr(edev, MII_ACC) & MII_ACC_MII_BUSY);
 
@@ -308,9 +309,12 @@ static void smc911x_enable(struct eth_device *edev)
 static int smc911x_eth_open(struct eth_device *edev)
 {
 	struct smc911x_priv *priv = (struct smc911x_priv *)edev->priv;
+	int ret;
 
-	miidev_wait_aneg(&priv->miidev);
-	miidev_print_status(&priv->miidev);
+	ret = phy_device_connect(edev, &priv->miidev, 1, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
+	if (ret)
+		return ret;
 
 	/* Turn on Tx + Rx */
 	smc911x_enable(edev);
@@ -405,13 +409,9 @@ static int smc911x_eth_rx(struct eth_device *edev)
 
 static int smc911x_init_dev(struct eth_device *edev)
 {
-	struct smc911x_priv *priv = (struct smc911x_priv *)edev->priv;
-
 	smc911x_set_mac_csr(edev, MAC_CR, MAC_CR_TXEN | MAC_CR_RXEN |
 			MAC_CR_HBDIS);
 
-	miidev_restart_aneg(&priv->miidev);
-
 	return 0;
 }
 
@@ -538,9 +538,7 @@ static int smc911x_probe(struct device_d *dev)
 
 	priv->miidev.read = smc911x_phy_read;
 	priv->miidev.write = smc911x_phy_write;
-	priv->miidev.address = 1;
-	priv->miidev.flags = 0;
-	priv->miidev.edev = edev;
+	priv->miidev.priv = edev;
 	priv->miidev.parent = dev;
 
 	smc911x_reset(edev);
drivers/net/usb/asix.c +4 -7
index be5a170..4eca56c 100644
@@ -233,8 +233,7 @@ static inline int asix_set_hw_mii(struct usbnet *dev)
 
 static int asix_mdio_read(struct mii_device *mdev, int phy_id, int loc)
 {
-	struct eth_device *eth = mdev->edev;
-	struct usbnet *dev = eth->priv;
+	struct usbnet *dev = mdev->priv;
 	__le16 res;
 
 	asix_set_sw_mii(dev);
@@ -250,8 +249,7 @@ static int asix_mdio_read(struct mii_device *mdev, int phy_id, int loc)
 
 static int asix_mdio_write(struct mii_device *mdev, int phy_id, int loc, int val)
 {
-	struct eth_device *eth = mdev->edev;
-	struct usbnet *dev = eth->priv;
+	struct usbnet *dev = mdev->priv;
 	__le16 res = cpu_to_le16(val);
 
 	dev_dbg(&dev->edev.dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x",
@@ -471,9 +469,8 @@ static int asix_init_mii(struct usbnet *dev)
 {
 	dev->miidev.read = asix_mdio_read;
 	dev->miidev.write = asix_mdio_write;
-	dev->miidev.address = asix_get_phy_addr(dev);
-	dev->miidev.flags = 0;
-	dev->miidev.edev = &dev->edev;
+	dev->phy_addr = asix_get_phy_addr(dev);
+	dev->miidev.priv = dev;
 	dev->miidev.parent = &dev->udev->dev;
 
 	return mii_register(&dev->miidev);
drivers/net/usb/smsc95xx.c +4 -7
index c21705e..7d5baed 100644
@@ -125,8 +125,7 @@ static int smsc95xx_phy_wait_not_busy(struct usbnet *dev)
 
 static int smsc95xx_mdio_read(struct mii_device *mdev, int phy_id, int idx)
 {
-	struct eth_device *eth = mdev->edev;
-	struct usbnet *dev = eth->priv;
+	struct usbnet *dev = mdev->priv;
 	u32 val, addr;
 
 	/* confirm MII not busy */
@@ -152,8 +151,7 @@ static int smsc95xx_mdio_read(struct mii_device *mdev, int phy_id, int idx)
 static int smsc95xx_mdio_write(struct mii_device *mdev, int phy_id, int idx,
 		int regval)
 {
-	struct eth_device *eth = mdev->edev;
-	struct usbnet *dev = eth->priv;
+	struct usbnet *dev = mdev->priv;
 	u32 val, addr;
 
 	/* confirm MII not busy */
@@ -441,9 +439,8 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)
 	/* Initialize MII structure */
 	dev->miidev.read = smsc95xx_mdio_read;
 	dev->miidev.write = smsc95xx_mdio_write;
-	dev->miidev.address = 1; /* FIXME: asix_get_phy_addr(dev); */
-	dev->miidev.flags = 0;
-	dev->miidev.edev = &dev->edev;
+	dev->phy_addr = 1; /* FIXME: asix_get_phy_addr(dev); */
+	dev->miidev.priv = dev;
 	dev->miidev.parent = &dev->udev->dev;
 //	dev->miidev.name = dev->edev.name;
 
drivers/net/usb/usbnet.c +3 -8
index c7e3606..1a931bb 100644
@@ -4,6 +4,7 @@
 #include <asm/byteorder.h>
 #include <errno.h>
 #include <malloc.h>
+#include <linux/phy.h>
 
 static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
 {
@@ -160,8 +161,6 @@ static int usbnet_init(struct eth_device *edev)
                 return ret;
         }
 
-	miidev_restart_aneg(&dev->miidev);
-
 	return 0;
 }
 
@@ -171,12 +170,8 @@ static int usbnet_open(struct eth_device *edev)
 
 	dev_dbg(&edev->dev, "%s\n",__func__);
 
-	if (miidev_wait_aneg(&dev->miidev))
-		return -1;
-
-	miidev_print_status(&dev->miidev);
-
-	return 0;
+	return phy_device_connect(edev, &dev->miidev, dev->phy_addr, NULL,
+				0, PHY_INTERFACE_MODE_NA);
 }
 
 static void usbnet_halt(struct eth_device *edev)
include/fec.h +3 -0
index f56b023..6e1e1cd 100644
@@ -25,6 +25,8 @@
 #ifndef __INCLUDE_NETWORK_FEC_H
 #define __INCLUDE_NETWORK_FEC_H
 
+#include <linux/phy.h>
+
 /*
  * Supported phy types on this platform
  */
@@ -43,6 +45,7 @@ typedef enum {
 struct fec_platform_data {
         xceiver_type	xcv_type;
 	int		phy_addr;
+	void 		(*phy_init)(struct phy_device *dev);
 };
 
 #endif /* __INCLUDE_NETWORK_FEC_H */
include/linux/ethtool.h new file +114 -0

114 lines not on this page · raw message

include/linux/mii.h +443 -232

479 lines not on this page · raw message

include/linux/phy.h new file +206 -0

206 lines not on this page · raw message

include/miidev.h +1 -20
index 4bbf94c..b73d2ad 100644

Lines of this file are not shown. View the raw message.

include/net.h +4 -0
index 9152943..39fad12 100644

Lines of this file are not shown. View the raw message.

include/usb/usbnet.h +1 -0
index 1609b2e..0a59b6a 100644

Lines of this file are not shown. View the raw message.

net/eth.c +5 -1
index c034eaa..8d516f1 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Part of the diff is not shown here. View the raw message.

maintainer
#2 lore raw
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD

Adapt phylib from linux

switch all the driver to it

This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready or not up fail on open

Same behaviour as in linux and will allow to share code and simplify porting.

---

[...]

Quoted 34 lines
drivers/net/phy/phy.c new file +34 -0
+/* Automatically gets and returns the PHY device */
+int phy_device_connect(struct eth_device *edev, struct mii_device *bus, int addr,
+		       void (*adjust_link) (struct eth_device *edev),
+		       u32 flags, phy_interface_t interface)
+{
+	struct phy_driver* drv;
+	struct phy_device* dev = NULL;
+	unsigned int i;
+	int ret = -EINVAL;
+
+	if (!edev->phydev) {
+		if (addr >= 0) {
+			dev = get_phy_device(bus, addr);
+			if (IS_ERR(dev)) {
+				ret = PTR_ERR(dev);
+				goto fail;
+			}
+
+			dev->attached_dev = edev;
+			dev->interface = interface;
+			dev->dev_flags = flags;
+
+			ret = register_device(&dev->dev);
+			if (ret)
+				goto fail;
+		} else {
+			for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
+				dev = get_phy_device(bus, i);
+				if (IS_ERR(dev))
+					continue;
+
+				dev->attached_dev = edev;
+				dev->interface = interface;
+				dev->dev_flags = flags;

drivers/net/phy/phy.c line 165

Quoted 10 lines
drivers/net/phy/phy.c new file +10 -0
+
+				ret = register_device(&dev->dev);
+				if (ret)
+					goto fail;
+			}
+
+			if (i == 32) {
+				ret = -EIO;
+				goto fail;
+			}

I just found out the hard way that this does not work with a phy_id of
31. I don't know exactly the intention of this code, but I would just test for !edev->phydev instead of i==32.

Sascha

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
#3 lore raw
Quoted 57 lines · Sascha Hauer
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD

Adapt phylib from linux

switch all the driver to it

This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready or not up fail on open

Same behaviour as in linux and will allow to share code and simplify porting.

---

[...]

Quoted 40 lines
(quoted diff) +40 -0
+/* Automatically gets and returns the PHY device */
+int phy_device_connect(struct eth_device *edev, struct mii_device *bus, int addr,
+		       void (*adjust_link) (struct eth_device *edev),
+		       u32 flags, phy_interface_t interface)
+{
+	struct phy_driver* drv;
+	struct phy_device* dev = NULL;
+	unsigned int i;
+	int ret = -EINVAL;
+
+	if (!edev->phydev) {
+		if (addr >= 0) {
+			dev = get_phy_device(bus, addr);
+			if (IS_ERR(dev)) {
+				ret = PTR_ERR(dev);
+				goto fail;
+			}
+
+			dev->attached_dev = edev;
+			dev->interface = interface;
+			dev->dev_flags = flags;
+
+			ret = register_device(&dev->dev);
+			if (ret)
+				goto fail;
+		} else {
+			for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
+				dev = get_phy_device(bus, i);
+				if (IS_ERR(dev))
+					continue;
+
+				dev->attached_dev = edev;
+				dev->interface = interface;
+				dev->dev_flags = flags;
+
+				ret = register_device(&dev->dev);
+				if (ret)
+					goto fail;
+			}
+
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+			if (i == 32) {
+				ret = -EIO;
+				goto fail;
+			}

I just found out the hard way that this does not work with a phy_id of
31. I don't know exactly the intention of this code, but I would just test for !edev->phydev instead of i==32.

the phy_id is from 0x0 to 0x1f so 31 need to work

tag updated with

drivers/net/phy/phy.c +4 -4
index bfebe3b..ef4e771 100644
@@ -158,11 +158,11 @@ int phy_device_connect(struct eth_device *edev, struct mii_device *bus, int addr
                                if (ret)
                                        goto fail;
                        }
+               }
 
-                       if (i == 32) {
-                               ret = -EIO;
-                               goto fail;
-                       }
+               if (!edev->phydev) {
+                       ret = -EIO;
+                       goto fail;
                }
        } 
 

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox