2002-11-03 08:24:07 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-11-03 08:24:07 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This provides a bit-banged interface to the ethernet MII management
|
|
|
|
* channel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <miiphy.h>
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
#include <phy.h>
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-10-29 04:30:33 +08:00
|
|
|
#include <asm/types.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <net.h>
|
|
|
|
|
|
|
|
/* local debug macro */
|
|
|
|
#undef MII_DEBUG
|
|
|
|
|
|
|
|
#undef debug
|
|
|
|
#ifdef MII_DEBUG
|
2011-04-08 03:38:35 +08:00
|
|
|
#define debug(fmt, args...) printf(fmt, ##args)
|
2005-10-29 04:30:33 +08:00
|
|
|
#else
|
2011-04-08 03:38:35 +08:00
|
|
|
#define debug(fmt, args...)
|
2005-10-29 04:30:33 +08:00
|
|
|
#endif /* MII_DEBUG */
|
|
|
|
|
|
|
|
static struct list_head mii_devs;
|
|
|
|
static struct mii_dev *current_mii;
|
|
|
|
|
2010-07-28 06:35:09 +08:00
|
|
|
/*
|
|
|
|
* Lookup the mii_dev struct by the registered device name.
|
|
|
|
*/
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
struct mii_dev *miiphy_get_dev_by_name(const char *devname)
|
2010-07-28 06:35:09 +08:00
|
|
|
{
|
|
|
|
struct list_head *entry;
|
|
|
|
struct mii_dev *dev;
|
|
|
|
|
|
|
|
if (!devname) {
|
|
|
|
printf("NULL device name!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each(entry, &mii_devs) {
|
|
|
|
dev = list_entry(entry, struct mii_dev, link);
|
|
|
|
if (strcmp(dev->name, devname) == 0)
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-01 01:06:04 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Initialize global data. Need to be called before any other miiphy routine.
|
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
void miiphy_init(void)
|
2005-12-01 01:06:04 +08:00
|
|
|
{
|
2011-04-08 03:38:35 +08:00
|
|
|
INIT_LIST_HEAD(&mii_devs);
|
2007-11-01 00:21:29 +08:00
|
|
|
current_mii = NULL;
|
2005-12-01 01:06:04 +08:00
|
|
|
}
|
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
static int legacy_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
|
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
int ret;
|
|
|
|
struct legacy_mii_dev *ldev = bus->priv;
|
|
|
|
|
|
|
|
ret = ldev->read(bus->name, addr, reg, &val);
|
|
|
|
|
|
|
|
return ret ? -1 : (int)val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int legacy_miiphy_write(struct mii_dev *bus, int addr, int devad,
|
|
|
|
int reg, u16 val)
|
|
|
|
{
|
|
|
|
struct legacy_mii_dev *ldev = bus->priv;
|
|
|
|
|
|
|
|
return ldev->write(bus->name, addr, reg, val);
|
|
|
|
}
|
|
|
|
|
2005-10-29 04:30:33 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Register read and write MII access routines for the device <name>.
|
2011-10-31 22:46:13 +08:00
|
|
|
* This API is now deprecated. Please use mdio_alloc and mdio_register, instead.
|
2005-10-29 04:30:33 +08:00
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
void miiphy_register(const char *name,
|
2011-04-08 03:38:35 +08:00
|
|
|
int (*read)(const char *devname, unsigned char addr,
|
2011-12-07 15:35:14 +08:00
|
|
|
unsigned char reg, unsigned short *value),
|
2011-04-08 03:38:35 +08:00
|
|
|
int (*write)(const char *devname, unsigned char addr,
|
2011-12-07 15:35:14 +08:00
|
|
|
unsigned char reg, unsigned short value))
|
2005-10-29 04:30:33 +08:00
|
|
|
{
|
|
|
|
struct mii_dev *new_dev;
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
struct legacy_mii_dev *ldev;
|
2011-07-15 07:21:45 +08:00
|
|
|
|
|
|
|
BUG_ON(strlen(name) >= MDIO_NAME_LEN);
|
2005-10-29 04:30:33 +08:00
|
|
|
|
|
|
|
/* check if we have unique name */
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
new_dev = miiphy_get_dev_by_name(name);
|
2010-07-28 06:35:09 +08:00
|
|
|
if (new_dev) {
|
|
|
|
printf("miiphy_register: non unique device name '%s'\n", name);
|
|
|
|
return;
|
2005-10-29 04:30:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate memory */
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
new_dev = mdio_alloc();
|
|
|
|
ldev = malloc(sizeof(*ldev));
|
2005-10-29 04:30:33 +08:00
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
if (new_dev == NULL || ldev == NULL) {
|
2011-04-08 03:38:35 +08:00
|
|
|
printf("miiphy_register: cannot allocate memory for '%s'\n",
|
2007-11-01 00:21:29 +08:00
|
|
|
name);
|
2005-10-29 04:30:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initalize mii_dev struct fields */
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
new_dev->read = legacy_miiphy_read;
|
|
|
|
new_dev->write = legacy_miiphy_write;
|
2011-07-15 07:21:45 +08:00
|
|
|
strncpy(new_dev->name, name, MDIO_NAME_LEN);
|
|
|
|
new_dev->name[MDIO_NAME_LEN - 1] = 0;
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
ldev->read = read;
|
|
|
|
ldev->write = write;
|
|
|
|
new_dev->priv = ldev;
|
2005-10-29 04:30:33 +08:00
|
|
|
|
2011-04-08 03:38:35 +08:00
|
|
|
debug("miiphy_register: added '%s', read=0x%08lx, write=0x%08lx\n",
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
new_dev->name, ldev->read, ldev->write);
|
2005-10-29 04:30:33 +08:00
|
|
|
|
|
|
|
/* add it to the list */
|
2011-04-08 03:38:35 +08:00
|
|
|
list_add_tail(&new_dev->link, &mii_devs);
|
2005-10-29 04:30:33 +08:00
|
|
|
|
|
|
|
if (!current_mii)
|
|
|
|
current_mii = new_dev;
|
|
|
|
}
|
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
struct mii_dev *mdio_alloc(void)
|
|
|
|
{
|
|
|
|
struct mii_dev *bus;
|
|
|
|
|
|
|
|
bus = malloc(sizeof(*bus));
|
|
|
|
if (!bus)
|
|
|
|
return bus;
|
|
|
|
|
|
|
|
memset(bus, 0, sizeof(*bus));
|
|
|
|
|
|
|
|
/* initalize mii_dev struct fields */
|
|
|
|
INIT_LIST_HEAD(&bus->link);
|
|
|
|
|
|
|
|
return bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mdio_register(struct mii_dev *bus)
|
|
|
|
{
|
|
|
|
if (!bus || !bus->name || !bus->read || !bus->write)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* check if we have unique name */
|
|
|
|
if (miiphy_get_dev_by_name(bus->name)) {
|
|
|
|
printf("mdio_register: non unique device name '%s'\n",
|
|
|
|
bus->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add it to the list */
|
|
|
|
list_add_tail(&bus->link, &mii_devs);
|
|
|
|
|
|
|
|
if (!current_mii)
|
|
|
|
current_mii = bus;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mdio_list_devices(void)
|
|
|
|
{
|
|
|
|
struct list_head *entry;
|
|
|
|
|
|
|
|
list_for_each(entry, &mii_devs) {
|
|
|
|
int i;
|
|
|
|
struct mii_dev *bus = list_entry(entry, struct mii_dev, link);
|
|
|
|
|
|
|
|
printf("%s:\n", bus->name);
|
|
|
|
|
|
|
|
for (i = 0; i < PHY_MAX_ADDR; i++) {
|
|
|
|
struct phy_device *phydev = bus->phymap[i];
|
|
|
|
|
|
|
|
if (phydev) {
|
|
|
|
printf("%d - %s", i, phydev->drv->name);
|
|
|
|
|
|
|
|
if (phydev->dev)
|
|
|
|
printf(" <--> %s\n", phydev->dev->name);
|
|
|
|
else
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-28 06:35:08 +08:00
|
|
|
int miiphy_set_current_dev(const char *devname)
|
2005-10-29 04:30:33 +08:00
|
|
|
{
|
|
|
|
struct mii_dev *dev;
|
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
dev = miiphy_get_dev_by_name(devname);
|
2010-07-28 06:35:09 +08:00
|
|
|
if (dev) {
|
|
|
|
current_mii = dev;
|
|
|
|
return 0;
|
2005-10-29 04:30:33 +08:00
|
|
|
}
|
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
printf("No such device: %s\n", devname);
|
|
|
|
|
2005-10-29 04:30:33 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
struct mii_dev *mdio_get_current_dev(void)
|
|
|
|
{
|
|
|
|
return current_mii;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct phy_device *mdio_phydev_for_ethname(const char *ethname)
|
|
|
|
{
|
|
|
|
struct list_head *entry;
|
|
|
|
struct mii_dev *bus;
|
|
|
|
|
|
|
|
list_for_each(entry, &mii_devs) {
|
|
|
|
int i;
|
|
|
|
bus = list_entry(entry, struct mii_dev, link);
|
|
|
|
|
|
|
|
for (i = 0; i < PHY_MAX_ADDR; i++) {
|
|
|
|
if (!bus->phymap[i] || !bus->phymap[i]->dev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(bus->phymap[i]->dev->name, ethname) == 0)
|
|
|
|
return bus->phymap[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s is not a known ethernet\n", ethname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-28 06:35:08 +08:00
|
|
|
const char *miiphy_get_current_dev(void)
|
2005-10-29 04:30:33 +08:00
|
|
|
{
|
|
|
|
if (current_mii)
|
|
|
|
return current_mii->name;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-28 06:35:10 +08:00
|
|
|
static struct mii_dev *miiphy_get_active_dev(const char *devname)
|
|
|
|
{
|
|
|
|
/* If the current mii is the one we want, return it */
|
|
|
|
if (current_mii)
|
|
|
|
if (strcmp(current_mii->name, devname) == 0)
|
|
|
|
return current_mii;
|
|
|
|
|
|
|
|
/* Otherwise, set the active one to the one we want */
|
|
|
|
if (miiphy_set_current_dev(devname))
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return current_mii;
|
|
|
|
}
|
|
|
|
|
2005-10-29 04:30:33 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Read to variable <value> from the PHY attached to device <devname>,
|
|
|
|
* use PHY address <addr> and register <reg>.
|
|
|
|
*
|
2011-10-31 22:46:13 +08:00
|
|
|
* This API is deprecated. Use phy_read on a phy_device found via phy_connect
|
|
|
|
*
|
2005-10-29 04:30:33 +08:00
|
|
|
* Returns:
|
|
|
|
* 0 on success
|
|
|
|
*/
|
2011-12-07 15:35:14 +08:00
|
|
|
int miiphy_read(const char *devname, unsigned char addr, unsigned char reg,
|
2007-11-01 00:21:29 +08:00
|
|
|
unsigned short *value)
|
2005-10-29 04:30:33 +08:00
|
|
|
{
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
struct mii_dev *bus;
|
2011-04-30 10:17:44 +08:00
|
|
|
int ret;
|
2005-10-29 04:30:33 +08:00
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
bus = miiphy_get_active_dev(devname);
|
2011-04-30 10:17:44 +08:00
|
|
|
if (!bus)
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
return 1;
|
2005-10-29 04:30:33 +08:00
|
|
|
|
2011-04-30 10:17:44 +08:00
|
|
|
ret = bus->read(bus, addr, MDIO_DEVAD_NONE, reg);
|
|
|
|
if (ret < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
*value = (unsigned short)ret;
|
|
|
|
return 0;
|
2005-10-29 04:30:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Write <value> to the PHY attached to device <devname>,
|
|
|
|
* use PHY address <addr> and register <reg>.
|
|
|
|
*
|
2011-10-31 22:46:13 +08:00
|
|
|
* This API is deprecated. Use phy_write on a phy_device found by phy_connect
|
|
|
|
*
|
2005-10-29 04:30:33 +08:00
|
|
|
* Returns:
|
|
|
|
* 0 on success
|
|
|
|
*/
|
2011-12-07 15:35:14 +08:00
|
|
|
int miiphy_write(const char *devname, unsigned char addr, unsigned char reg,
|
2007-11-01 00:21:29 +08:00
|
|
|
unsigned short value)
|
2005-10-29 04:30:33 +08:00
|
|
|
{
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
struct mii_dev *bus;
|
2005-10-29 04:30:33 +08:00
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
bus = miiphy_get_active_dev(devname);
|
|
|
|
if (bus)
|
|
|
|
return bus->write(bus, addr, MDIO_DEVAD_NONE, reg, value);
|
2005-10-29 04:30:33 +08:00
|
|
|
|
2010-07-28 06:35:09 +08:00
|
|
|
return 1;
|
2005-10-29 04:30:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Print out list of registered MII capable devices.
|
|
|
|
*/
|
2011-04-08 03:38:35 +08:00
|
|
|
void miiphy_listdev(void)
|
2005-10-29 04:30:33 +08:00
|
|
|
{
|
|
|
|
struct list_head *entry;
|
|
|
|
struct mii_dev *dev;
|
|
|
|
|
2011-04-08 03:38:35 +08:00
|
|
|
puts("MII devices: ");
|
|
|
|
list_for_each(entry, &mii_devs) {
|
|
|
|
dev = list_entry(entry, struct mii_dev, link);
|
|
|
|
printf("'%s' ", dev->name);
|
2005-10-29 04:30:33 +08:00
|
|
|
}
|
2011-04-08 03:38:35 +08:00
|
|
|
puts("\n");
|
2005-10-29 04:30:33 +08:00
|
|
|
|
|
|
|
if (current_mii)
|
2011-04-08 03:38:35 +08:00
|
|
|
printf("Current device: '%s'\n", current_mii->name);
|
2005-10-29 04:30:33 +08:00
|
|
|
}
|
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Read the OUI, manufacture's model number, and revision number.
|
|
|
|
*
|
|
|
|
* OUI: 22 bits (unsigned int)
|
|
|
|
* Model: 6 bits (unsigned char)
|
|
|
|
* Revision: 4 bits (unsigned char)
|
|
|
|
*
|
2011-10-31 22:46:13 +08:00
|
|
|
* This API is deprecated.
|
|
|
|
*
|
2002-11-03 08:24:07 +08:00
|
|
|
* Returns:
|
|
|
|
* 0 on success
|
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
int miiphy_info(const char *devname, unsigned char addr, unsigned int *oui,
|
2002-11-03 08:24:07 +08:00
|
|
|
unsigned char *model, unsigned char *rev)
|
|
|
|
{
|
|
|
|
unsigned int reg = 0;
|
2003-12-07 07:20:41 +08:00
|
|
|
unsigned short tmp;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_PHYSID2, &tmp) != 0) {
|
|
|
|
debug("PHY ID register 2 read failed\n");
|
|
|
|
return -1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2003-12-07 07:20:41 +08:00
|
|
|
reg = tmp;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2011-04-08 03:38:35 +08:00
|
|
|
debug("MII_PHYSID2 @ 0x%x = 0x%04x\n", addr, reg);
|
2008-01-19 09:25:59 +08:00
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
if (reg == 0xFFFF) {
|
|
|
|
/* No physical device present at this address */
|
2011-04-08 03:38:35 +08:00
|
|
|
return -1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_PHYSID1, &tmp) != 0) {
|
|
|
|
debug("PHY ID register 1 read failed\n");
|
|
|
|
return -1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2003-12-07 07:20:41 +08:00
|
|
|
reg |= tmp << 16;
|
2011-04-08 03:38:35 +08:00
|
|
|
debug("PHY_PHYIDR[1,2] @ 0x%x = 0x%08x\n", addr, reg);
|
2008-01-19 09:25:59 +08:00
|
|
|
|
2007-11-01 00:21:29 +08:00
|
|
|
*oui = (reg >> 10);
|
|
|
|
*model = (unsigned char)((reg >> 4) & 0x0000003F);
|
|
|
|
*rev = (unsigned char)(reg & 0x0000000F);
|
2011-04-08 03:38:35 +08:00
|
|
|
return 0;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
#ifndef CONFIG_PHYLIB
|
2002-11-03 08:24:07 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Reset the PHY.
|
2011-10-31 22:46:13 +08:00
|
|
|
*
|
|
|
|
* This API is deprecated. Use PHYLIB.
|
|
|
|
*
|
2002-11-03 08:24:07 +08:00
|
|
|
* Returns:
|
|
|
|
* 0 on success
|
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
int miiphy_reset(const char *devname, unsigned char addr)
|
2002-11-03 08:24:07 +08:00
|
|
|
{
|
|
|
|
unsigned short reg;
|
2010-02-02 20:43:48 +08:00
|
|
|
int timeout = 500;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_BMCR, ®) != 0) {
|
|
|
|
debug("PHY status read failed\n");
|
|
|
|
return -1;
|
2005-08-13 05:15:53 +08:00
|
|
|
}
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_write(devname, addr, MII_BMCR, reg | BMCR_RESET) != 0) {
|
|
|
|
debug("PHY reset failed\n");
|
|
|
|
return -1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2004-02-09 06:55:38 +08:00
|
|
|
#ifdef CONFIG_PHY_RESET_DELAY
|
2011-04-08 03:38:35 +08:00
|
|
|
udelay(CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */
|
2004-02-09 06:55:38 +08:00
|
|
|
#endif
|
2002-11-03 08:24:07 +08:00
|
|
|
/*
|
|
|
|
* Poll the control register for the reset bit to go to 0 (it is
|
|
|
|
* auto-clearing). This should happen within 0.5 seconds per the
|
|
|
|
* IEEE spec.
|
|
|
|
*/
|
|
|
|
reg = 0x8000;
|
2010-02-02 20:43:48 +08:00
|
|
|
while (((reg & 0x8000) != 0) && timeout--) {
|
2010-12-24 04:40:12 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_BMCR, ®) != 0) {
|
2010-02-02 20:43:48 +08:00
|
|
|
debug("PHY status read failed\n");
|
|
|
|
return -1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2010-02-02 20:43:48 +08:00
|
|
|
udelay(1000);
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
if ((reg & 0x8000) == 0) {
|
2011-04-08 03:38:35 +08:00
|
|
|
return 0;
|
2002-11-03 08:24:07 +08:00
|
|
|
} else {
|
2011-04-08 03:38:35 +08:00
|
|
|
puts("PHY reset timed out\n");
|
|
|
|
return -1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2011-04-08 03:38:35 +08:00
|
|
|
return 0;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
Create PHY Lib for U-Boot
Extends the mii_dev structure to participate in a full-blown MDIO and
PHY driver scheme. The mii_dev structure and miiphy calls are modified
in such a way to allow the original mii command and miiphy
infrastructure to work as before, but also to support a new set of APIs
which allow (among other things) sharing of PHY driver code and 10G support
The mii command will continue to support normal PHY management functions
(Clause 22 of 802.3), but will not be changed to support 10G
(Clause 45).
The basic design is similar to PHY Lib from Linux, but simplified for
U-Boot's network and driver infrastructure.
We now have MDIO drivers and PHY drivers
An MDIO driver provides:
read
write
reset
A PHY driver provides:
(optionally): probe
config - initial setup, starting of auto-negotiation
startup - waiting for AN, and reading link state
shutdown - any cleanup needed
The ethernet drivers interact with the PHY Lib using these functions:
phy_connect()
phy_config()
phy_startup()
phy_shutdown()
Each PHY driver can be configured separately, or all at once using
config_phylib_all_drivers.h (added in the patch which adds the drivers)
We also provide generic drivers for Clause 22 (10/100/1000), and
Clause 45 (10G) PHYs.
We also implement phy_reset(), and call it in phy_connect(). Because
phy_reset() is essentially the same as miiphy_reset, but:
a) must support 10G PHYs, and
b) should use the phylib primitives,
we implement miiphy_reset, using phy_reset(), but only when
CONFIG_PHYLIB is set. Otherwise, we just use the old version. In this
way, we save on compile size, even if we don't manage to save code size.
Pulled ethtool.h and mdio.h from:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
782d640afd15af7a1faf01cfe566ca4ac511319d
With many, many deletions so as to enable compilation under u-boot
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Detlev Zundel <dzu@denx.de>
2011-04-08 15:10:27 +08:00
|
|
|
#endif /* !PHYLIB */
|
2002-11-03 08:24:07 +08:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2007-11-01 21:46:50 +08:00
|
|
|
* Determine the ethernet speed (10/100/1000). Return 10 on error.
|
2002-11-03 08:24:07 +08:00
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
int miiphy_speed(const char *devname, unsigned char addr)
|
2002-11-03 08:24:07 +08:00
|
|
|
{
|
2007-11-01 21:46:50 +08:00
|
|
|
u16 bmcr, anlpar;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2004-03-24 07:20:24 +08:00
|
|
|
#if defined(CONFIG_PHY_GIGE)
|
2007-11-01 21:46:50 +08:00
|
|
|
u16 btsr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for 1000BASE-X. If it is supported, then assume that the speed
|
|
|
|
* is 1000.
|
|
|
|
*/
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_is_1000base_x(devname, addr))
|
2007-11-01 21:46:50 +08:00
|
|
|
return _1000BASET;
|
2011-04-08 03:38:35 +08:00
|
|
|
|
2007-11-01 21:46:50 +08:00
|
|
|
/*
|
|
|
|
* No 1000BASE-X, so assume 1000BASE-T/100BASE-TX/10BASE-T register set.
|
|
|
|
*/
|
|
|
|
/* Check for 1000BASE-T. */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_STAT1000, &btsr)) {
|
|
|
|
printf("PHY 1000BT status");
|
2007-11-01 21:46:50 +08:00
|
|
|
goto miiphy_read_failed;
|
|
|
|
}
|
|
|
|
if (btsr != 0xFFFF &&
|
2011-04-08 03:38:35 +08:00
|
|
|
(btsr & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)))
|
2007-11-01 21:46:50 +08:00
|
|
|
return _1000BASET;
|
2004-03-24 07:20:24 +08:00
|
|
|
#endif /* CONFIG_PHY_GIGE */
|
2004-03-15 02:23:55 +08:00
|
|
|
|
2004-06-07 07:13:55 +08:00
|
|
|
/* Check Basic Management Control Register first. */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_BMCR, &bmcr)) {
|
|
|
|
printf("PHY speed");
|
2007-11-01 21:46:50 +08:00
|
|
|
goto miiphy_read_failed;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2004-06-07 07:13:55 +08:00
|
|
|
/* Check if auto-negotiation is on. */
|
2010-12-24 04:40:12 +08:00
|
|
|
if (bmcr & BMCR_ANENABLE) {
|
2004-06-07 07:13:55 +08:00
|
|
|
/* Get auto-negotiation results. */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_LPA, &anlpar)) {
|
|
|
|
printf("PHY AN speed");
|
2007-11-01 21:46:50 +08:00
|
|
|
goto miiphy_read_failed;
|
2004-06-07 07:13:55 +08:00
|
|
|
}
|
2010-12-24 04:40:12 +08:00
|
|
|
return (anlpar & LPA_100) ? _100BASET : _10BASET;
|
2004-06-07 07:13:55 +08:00
|
|
|
}
|
|
|
|
/* Get speed from basic control settings. */
|
2010-12-24 04:40:12 +08:00
|
|
|
return (bmcr & BMCR_SPEED100) ? _100BASET : _10BASET;
|
2004-06-07 07:13:55 +08:00
|
|
|
|
2010-02-28 22:28:25 +08:00
|
|
|
miiphy_read_failed:
|
2011-04-08 03:38:35 +08:00
|
|
|
printf(" read failed, assuming 10BASE-T\n");
|
2007-11-01 21:46:50 +08:00
|
|
|
return _10BASET;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2007-11-01 21:46:50 +08:00
|
|
|
* Determine full/half duplex. Return half on error.
|
2002-11-03 08:24:07 +08:00
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
int miiphy_duplex(const char *devname, unsigned char addr)
|
2002-11-03 08:24:07 +08:00
|
|
|
{
|
2007-11-01 21:46:50 +08:00
|
|
|
u16 bmcr, anlpar;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2004-03-24 07:20:24 +08:00
|
|
|
#if defined(CONFIG_PHY_GIGE)
|
2007-11-01 21:46:50 +08:00
|
|
|
u16 btsr;
|
|
|
|
|
|
|
|
/* Check for 1000BASE-X. */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_is_1000base_x(devname, addr)) {
|
2007-11-01 21:46:50 +08:00
|
|
|
/* 1000BASE-X */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_LPA, &anlpar)) {
|
|
|
|
printf("1000BASE-X PHY AN duplex");
|
2007-11-01 21:46:50 +08:00
|
|
|
goto miiphy_read_failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* No 1000BASE-X, so assume 1000BASE-T/100BASE-TX/10BASE-T register set.
|
|
|
|
*/
|
|
|
|
/* Check for 1000BASE-T. */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_STAT1000, &btsr)) {
|
|
|
|
printf("PHY 1000BT status");
|
2007-11-01 21:46:50 +08:00
|
|
|
goto miiphy_read_failed;
|
|
|
|
}
|
|
|
|
if (btsr != 0xFFFF) {
|
|
|
|
if (btsr & PHY_1000BTSR_1000FD) {
|
|
|
|
return FULL;
|
|
|
|
} else if (btsr & PHY_1000BTSR_1000HD) {
|
|
|
|
return HALF;
|
2004-03-15 02:23:55 +08:00
|
|
|
}
|
|
|
|
}
|
2004-03-24 07:20:24 +08:00
|
|
|
#endif /* CONFIG_PHY_GIGE */
|
2004-03-15 02:23:55 +08:00
|
|
|
|
2004-06-07 07:13:55 +08:00
|
|
|
/* Check Basic Management Control Register first. */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_BMCR, &bmcr)) {
|
|
|
|
puts("PHY duplex");
|
2007-11-01 21:46:50 +08:00
|
|
|
goto miiphy_read_failed;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2004-06-07 07:13:55 +08:00
|
|
|
/* Check if auto-negotiation is on. */
|
2010-12-24 04:40:12 +08:00
|
|
|
if (bmcr & BMCR_ANENABLE) {
|
2004-06-07 07:13:55 +08:00
|
|
|
/* Get auto-negotiation results. */
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_LPA, &anlpar)) {
|
|
|
|
puts("PHY AN duplex");
|
2007-11-01 21:46:50 +08:00
|
|
|
goto miiphy_read_failed;
|
2004-06-07 07:13:55 +08:00
|
|
|
}
|
2010-12-24 04:40:12 +08:00
|
|
|
return (anlpar & (LPA_10FULL | LPA_100FULL)) ?
|
2007-11-01 21:46:50 +08:00
|
|
|
FULL : HALF;
|
2004-06-07 07:13:55 +08:00
|
|
|
}
|
|
|
|
/* Get speed from basic control settings. */
|
2010-12-24 04:40:12 +08:00
|
|
|
return (bmcr & BMCR_FULLDPLX) ? FULL : HALF;
|
2007-11-01 21:46:50 +08:00
|
|
|
|
2010-02-28 22:28:25 +08:00
|
|
|
miiphy_read_failed:
|
2011-04-08 03:38:35 +08:00
|
|
|
printf(" read failed, assuming half duplex\n");
|
2007-11-01 21:46:50 +08:00
|
|
|
return HALF;
|
|
|
|
}
|
2004-06-07 07:13:55 +08:00
|
|
|
|
2007-11-01 21:46:50 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Return 1 if PHY supports 1000BASE-X, 0 if PHY supports 10BASE-T/100BASE-TX/
|
|
|
|
* 1000BASE-T, or on error.
|
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
int miiphy_is_1000base_x(const char *devname, unsigned char addr)
|
2007-11-01 21:46:50 +08:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_PHY_GIGE)
|
|
|
|
u16 exsr;
|
|
|
|
|
2011-04-08 03:38:35 +08:00
|
|
|
if (miiphy_read(devname, addr, MII_ESTATUS, &exsr)) {
|
|
|
|
printf("PHY extended status read failed, assuming no "
|
2007-11-01 21:46:50 +08:00
|
|
|
"1000BASE-X\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-12-24 04:40:12 +08:00
|
|
|
return 0 != (exsr & (ESTATUS_1000XF | ESTATUS_1000XH));
|
2007-11-01 21:46:50 +08:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#ifdef CONFIG_SYS_FAULT_ECHO_LINK_DOWN
|
2003-10-09 06:33:00 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Determine link status
|
|
|
|
*/
|
2010-07-28 06:35:08 +08:00
|
|
|
int miiphy_link(const char *devname, unsigned char addr)
|
2003-10-09 06:33:00 +08:00
|
|
|
{
|
|
|
|
unsigned short reg;
|
|
|
|
|
2004-04-16 05:48:45 +08:00
|
|
|
/* dummy read; needed to latch some phys */
|
2011-04-08 03:38:35 +08:00
|
|
|
(void)miiphy_read(devname, addr, MII_BMSR, ®);
|
|
|
|
if (miiphy_read(devname, addr, MII_BMSR, ®)) {
|
|
|
|
puts("MII_BMSR read failed, assuming no link\n");
|
|
|
|
return 0;
|
2003-10-09 06:33:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine if a link is active */
|
2010-12-24 04:40:12 +08:00
|
|
|
if ((reg & BMSR_LSTATUS) != 0) {
|
2011-04-08 03:38:35 +08:00
|
|
|
return 1;
|
2003-10-09 06:33:00 +08:00
|
|
|
} else {
|
2011-04-08 03:38:35 +08:00
|
|
|
return 0;
|
2003-10-09 06:33:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|