aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/phy/phy.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/phy/phy.c')
-rw-r--r--drivers/net/phy/phy.c120
1 files changed, 44 insertions, 76 deletions
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 36722620f0c..1121b99abff 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -490,6 +490,9 @@ int phy_init(void)
#ifdef CONFIG_MV88E61XX_SWITCH
phy_mv88e61xx_init();
#endif
+#ifdef CONFIG_PHY_ADIN
+ phy_adin_init();
+#endif
#ifdef CONFIG_PHY_AQUANTIA
phy_aquantia_init();
#endif
@@ -635,18 +638,17 @@ static int phy_probe(struct phy_device *phydev)
return err;
}
-static struct phy_driver *generic_for_interface(phy_interface_t interface)
+static struct phy_driver *generic_for_phy(struct phy_device *phydev)
{
#ifdef CONFIG_PHYLIB_10G
- if (is_10g_interface(interface))
+ if (phydev->is_c45)
return &gen10g_driver;
#endif
return &genphy_driver;
}
-static struct phy_driver *get_phy_driver(struct phy_device *phydev,
- phy_interface_t interface)
+static struct phy_driver *get_phy_driver(struct phy_device *phydev)
{
struct list_head *entry;
int phy_id = phydev->phy_id;
@@ -659,12 +661,11 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev,
}
/* If we made it here, there's no driver for this PHY */
- return generic_for_interface(interface);
+ return generic_for_phy(phydev);
}
struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
- u32 phy_id, bool is_c45,
- phy_interface_t interface)
+ u32 phy_id, bool is_c45)
{
struct phy_device *dev;
@@ -683,7 +684,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
dev->duplex = -1;
dev->link = 0;
- dev->interface = interface;
+ dev->interface = PHY_INTERFACE_MODE_NA;
#ifdef CONFIG_DM_ETH
dev->node = ofnode_null();
@@ -696,7 +697,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
dev->is_c45 = is_c45;
dev->bus = bus;
- dev->drv = get_phy_driver(dev, interface);
+ dev->drv = get_phy_driver(dev);
if (phy_probe(dev)) {
printf("%s, PHY probe failed\n", __func__);
@@ -745,8 +746,7 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
}
static struct phy_device *create_phy_by_mask(struct mii_dev *bus,
- uint phy_mask, int devad,
- phy_interface_t interface)
+ uint phy_mask, int devad)
{
u32 phy_id = 0xffffffff;
bool is_c45;
@@ -767,8 +767,7 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus,
/* If the PHY ID is mostly f's, we didn't find anything */
if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) {
is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true;
- return phy_device_create(bus, addr, phy_id, is_c45,
- interface);
+ return phy_device_create(bus, addr, phy_id, is_c45);
}
next:
phy_mask &= ~(1 << addr);
@@ -777,25 +776,22 @@ next:
}
static struct phy_device *search_for_existing_phy(struct mii_dev *bus,
- uint phy_mask,
- phy_interface_t interface)
+ uint phy_mask)
{
/* If we have one, return the existing device, with new interface */
while (phy_mask) {
int addr = ffs(phy_mask) - 1;
- if (bus->phymap[addr]) {
- bus->phymap[addr]->interface = interface;
+ if (bus->phymap[addr])
return bus->phymap[addr];
- }
+
phy_mask &= ~(1 << addr);
}
return NULL;
}
static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
- uint phy_mask,
- phy_interface_t interface)
+ uint phy_mask)
{
struct phy_device *phydev;
int devad[] = {
@@ -811,13 +807,12 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
int i, devad_cnt;
devad_cnt = sizeof(devad)/sizeof(int);
- phydev = search_for_existing_phy(bus, phy_mask, interface);
+ phydev = search_for_existing_phy(bus, phy_mask);
if (phydev)
return phydev;
/* try different access clauses */
for (i = 0; i < devad_cnt; i++) {
- phydev = create_phy_by_mask(bus, phy_mask,
- devad[i], interface);
+ phydev = create_phy_by_mask(bus, phy_mask, devad[i]);
if (IS_ERR(phydev))
return NULL;
if (phydev)
@@ -845,10 +840,9 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
* Description: Reads the ID registers of the PHY at @addr on the
* @bus, then allocates and returns the phy_device to represent it.
*/
-static struct phy_device *get_phy_device(struct mii_dev *bus, int addr,
- phy_interface_t interface)
+static struct phy_device *get_phy_device(struct mii_dev *bus, int addr)
{
- return get_phy_device_by_mask(bus, 1 << addr, interface);
+ return get_phy_device_by_mask(bus, 1 << addr);
}
int phy_reset(struct phy_device *phydev)
@@ -862,7 +856,7 @@ int phy_reset(struct phy_device *phydev)
#ifdef CONFIG_PHYLIB_10G
/* If it's 10G, we need to issue reset through one of the MMDs */
- if (is_10g_interface(phydev->interface)) {
+ if (phydev->is_c45) {
if (!phydev->mmds)
gen10g_discover_mmds(phydev);
@@ -907,18 +901,12 @@ int miiphy_reset(const char *devname, unsigned char addr)
struct mii_dev *bus = miiphy_get_dev_by_name(devname);
struct phy_device *phydev;
- /*
- * miiphy_reset was only used on standard PHYs, so we'll fake it here.
- * If later code tries to connect with the right interface, this will
- * be corrected by get_phy_device in phy_connect()
- */
- phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII);
+ phydev = get_phy_device(bus, addr);
return phy_reset(phydev);
}
-struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask,
- phy_interface_t interface)
+struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask)
{
/* Reset the bus */
if (bus->reset) {
@@ -928,13 +916,15 @@ struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask,
mdelay(15);
}
- return get_phy_device_by_mask(bus, phy_mask, interface);
+ return get_phy_device_by_mask(bus, phy_mask);
}
#ifdef CONFIG_DM_ETH
-void phy_connect_dev(struct phy_device *phydev, struct udevice *dev)
+void phy_connect_dev(struct phy_device *phydev, struct udevice *dev,
+ phy_interface_t interface)
#else
-void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
+void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev,
+ phy_interface_t interface)
#endif
{
/* Soft Reset the PHY */
@@ -945,13 +935,14 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
phydev->dev->name, dev->name);
}
phydev->dev = dev;
- debug("%s connected to %s\n", dev->name, phydev->drv->name);
+ phydev->interface = interface;
+ debug("%s connected to %s mode %s\n", dev->name, phydev->drv->name,
+ phy_string_for_interface(interface));
}
#ifdef CONFIG_PHY_XILINX_GMII2RGMII
static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
- struct udevice *dev,
- phy_interface_t interface)
+ struct udevice *dev)
{
struct phy_device *phydev = NULL;
ofnode node;
@@ -960,8 +951,7 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
node = ofnode_by_compatible(node, "xlnx,gmii-to-rgmii-1.0");
if (ofnode_valid(node)) {
phydev = phy_device_create(bus, 0,
- PHY_GMII2RGMII_ID, false,
- interface);
+ PHY_GMII2RGMII_ID, false);
if (phydev)
phydev->node = node;
break;
@@ -985,41 +975,31 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
*/
struct phy_device *fixed_phy_create(ofnode node)
{
- phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
struct phy_device *phydev;
- const char *if_str;
ofnode subnode;
- if_str = ofnode_read_string(node, "phy-mode");
- if (!if_str) {
- if_str = ofnode_read_string(node, "phy-interface-type");
- }
- if (if_str) {
- interface = phy_get_interface_by_name(if_str);
- }
-
subnode = ofnode_find_subnode(node, "fixed-link");
if (!ofnode_valid(subnode)) {
return NULL;
}
- phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface);
+ phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false);
if (phydev)
phydev->node = subnode;
+ phydev->interface = ofnode_read_phy_mode(node);
+
return phydev;
}
static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
- struct udevice *dev,
- phy_interface_t interface)
+ struct udevice *dev)
{
ofnode node = dev_ofnode(dev), subnode;
struct phy_device *phydev = NULL;
if (ofnode_phy_is_fixed_link(node, &subnode)) {
- phydev = phy_device_create(bus, 0, PHY_FIXED_ID,
- false, interface);
+ phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false);
if (phydev)
phydev->node = subnode;
}
@@ -1042,29 +1022,29 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,
uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff;
#ifdef CONFIG_PHY_FIXED
- phydev = phy_connect_fixed(bus, dev, interface);
+ phydev = phy_connect_fixed(bus, dev);
#endif
#ifdef CONFIG_PHY_NCSI
if (!phydev)
- phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface);
+ phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false);
#endif
#ifdef CONFIG_PHY_ETHERNET_ID
if (!phydev)
- phydev = phy_connect_phy_id(bus, dev, addr, interface);
+ phydev = phy_connect_phy_id(bus, dev, addr);
#endif
#ifdef CONFIG_PHY_XILINX_GMII2RGMII
if (!phydev)
- phydev = phy_connect_gmii2rgmii(bus, dev, interface);
+ phydev = phy_connect_gmii2rgmii(bus, dev);
#endif
if (!phydev)
- phydev = phy_find_by_mask(bus, mask, interface);
+ phydev = phy_find_by_mask(bus, mask);
if (phydev)
- phy_connect_dev(phydev, dev);
+ phy_connect_dev(phydev, dev, interface);
else
printf("Could not get PHY for %s: addr %d\n", bus->name, addr);
return phydev;
@@ -1102,18 +1082,6 @@ int phy_shutdown(struct phy_device *phydev)
return 0;
}
-int phy_get_interface_by_name(const char *str)
-{
- int i;
-
- for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) {
- if (!strcmp(str, phy_interface_strings[i]))
- return i;
- }
-
- return -1;
-}
-
/**
* phy_modify - Convenience function for modifying a given PHY register
* @phydev: the phy_device struct