X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=common%2Fmiiphyutil.c;h=8eb0f761bb0164de32d4a47f69a8b19dd9f98756;hb=33554fcec99b7c8b57e004fdf18588ce21d85e68;hp=2cc23b410a22bf38ed1d55eecf4f4915fa8e2082;hpb=f915c9316cf1dd16a5ec4da02447656f200660f0;p=people%2Fms%2Fu-boot.git diff --git a/common/miiphyutil.c b/common/miiphyutil.c index 2cc23b410a..8eb0f761bb 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -2,23 +2,7 @@ * (C) Copyright 2001 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -27,6 +11,7 @@ */ #include +#include #include #include @@ -80,77 +65,6 @@ void miiphy_init(void) current_mii = NULL; } -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); -} - -/***************************************************************************** - * - * Register read and write MII access routines for the device . - * This API is now deprecated. Please use mdio_alloc and mdio_register, instead. - */ -void miiphy_register(const char *name, - int (*read)(const char *devname, unsigned char addr, - unsigned char reg, unsigned short *value), - int (*write)(const char *devname, unsigned char addr, - unsigned char reg, unsigned short value)) -{ - struct mii_dev *new_dev; - struct legacy_mii_dev *ldev; - - BUG_ON(strlen(name) >= MDIO_NAME_LEN); - - /* check if we have unique name */ - new_dev = miiphy_get_dev_by_name(name); - if (new_dev) { - printf("miiphy_register: non unique device name '%s'\n", name); - return; - } - - /* allocate memory */ - new_dev = mdio_alloc(); - ldev = malloc(sizeof(*ldev)); - - if (new_dev == NULL || ldev == NULL) { - printf("miiphy_register: cannot allocate memory for '%s'\n", - name); - return; - } - - /* initalize mii_dev struct fields */ - new_dev->read = legacy_miiphy_read; - new_dev->write = legacy_miiphy_write; - strncpy(new_dev->name, name, MDIO_NAME_LEN); - new_dev->name[MDIO_NAME_LEN - 1] = 0; - ldev->read = read; - ldev->write = write; - new_dev->priv = ldev; - - debug("miiphy_register: added '%s', read=0x%08lx, write=0x%08lx\n", - new_dev->name, ldev->read, ldev->write); - - /* add it to the list */ - list_add_tail(&new_dev->link, &mii_devs); - - if (!current_mii) - current_mii = new_dev; -} - struct mii_dev *mdio_alloc(void) { struct mii_dev *bus; @@ -167,9 +81,14 @@ struct mii_dev *mdio_alloc(void) return bus; } +void mdio_free(struct mii_dev *bus) +{ + free(bus); +} + int mdio_register(struct mii_dev *bus) { - if (!bus || !bus->name || !bus->read || !bus->write) + if (!bus || !bus->read || !bus->write) return -1; /* check if we have unique name */ @@ -188,6 +107,32 @@ int mdio_register(struct mii_dev *bus) return 0; } +int mdio_register_seq(struct mii_dev *bus, int seq) +{ + int ret; + + /* Setup a unique name for each mdio bus */ + ret = snprintf(bus->name, MDIO_NAME_LEN, "eth%d", seq); + if (ret < 0) + return ret; + + return mdio_register(bus); +} + +int mdio_unregister(struct mii_dev *bus) +{ + if (!bus) + return 0; + + /* delete it from the list */ + list_del(&bus->link); + + if (current_mii == bus) + current_mii = NULL; + + return 0; +} + void mdio_list_devices(void) { struct list_head *entry; @@ -202,7 +147,7 @@ void mdio_list_devices(void) struct phy_device *phydev = bus->phymap[i]; if (phydev) { - printf("%d - %s", i, phydev->drv->name); + printf("%x - %s", i, phydev->drv->name); if (phydev->dev) printf(" <--> %s\n", phydev->dev->name); @@ -447,7 +392,7 @@ int miiphy_reset(const char *devname, unsigned char addr) */ int miiphy_speed(const char *devname, unsigned char addr) { - u16 bmcr, anlpar; + u16 bmcr, anlpar, adv; #if defined(CONFIG_PHY_GIGE) u16 btsr; @@ -484,7 +429,12 @@ int miiphy_speed(const char *devname, unsigned char addr) printf("PHY AN speed"); goto miiphy_read_failed; } - return (anlpar & LPA_100) ? _100BASET : _10BASET; + + if (miiphy_read(devname, addr, MII_ADVERTISE, &adv)) { + puts("PHY AN adv speed"); + goto miiphy_read_failed; + } + return ((anlpar & adv) & LPA_100) ? _100BASET : _10BASET; } /* Get speed from basic control settings. */ return (bmcr & BMCR_SPEED100) ? _100BASET : _10BASET; @@ -500,7 +450,7 @@ miiphy_read_failed: */ int miiphy_duplex(const char *devname, unsigned char addr) { - u16 bmcr, anlpar; + u16 bmcr, anlpar, adv; #if defined(CONFIG_PHY_GIGE) u16 btsr; @@ -542,7 +492,12 @@ int miiphy_duplex(const char *devname, unsigned char addr) puts("PHY AN duplex"); goto miiphy_read_failed; } - return (anlpar & (LPA_10FULL | LPA_100FULL)) ? + + if (miiphy_read(devname, addr, MII_ADVERTISE, &adv)) { + puts("PHY AN adv duplex"); + goto miiphy_read_failed; + } + return ((anlpar & adv) & (LPA_10FULL | LPA_100FULL)) ? FULL : HALF; } /* Get speed from basic control settings. */