X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=common%2Fmiiphyutil.c;h=d8ebb384dbfa82012284edea1999fd6ddc0c325f;hb=0a0e53cb2ee625f603b7e2bb0caba23946f5fe40;hp=243cae97a468111c68b3b155541b73a13e00877d;hpb=5f184715ecd31bfcb8d09ba2d9f14adfa172a141;p=karo-tx-uboot.git diff --git a/common/miiphyutil.c b/common/miiphyutil.c index 243cae97a4..d8ebb384db 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,82 +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 . - */ -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; - unsigned int 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 */ - name_len = strlen(name); - if (name_len > MDIO_NAME_LEN - 1) { - /* Hopefully this won't happen, but if it does, we'll know */ - printf("miiphy_register: MDIO name was longer than %d\n", - MDIO_NAME_LEN); - return; - } - - 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; - sprintf(new_dev->name, name); - 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; @@ -172,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 */ @@ -193,6 +107,20 @@ int mdio_register(struct mii_dev *bus) return 0; } +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; @@ -287,6 +215,8 @@ static struct mii_dev *miiphy_get_active_dev(const char *devname) * Read to variable from the PHY attached to device , * use PHY address and register . * + * This API is deprecated. Use phy_read on a phy_device found via phy_connect + * * Returns: * 0 on success */ @@ -294,14 +224,18 @@ int miiphy_read(const char *devname, unsigned char addr, unsigned char reg, unsigned short *value) { struct mii_dev *bus; + int ret; bus = miiphy_get_active_dev(devname); - if (bus) - *value = bus->read(bus, addr, MDIO_DEVAD_NONE, reg); - else + if (!bus) + return 1; + + ret = bus->read(bus, addr, MDIO_DEVAD_NONE, reg); + if (ret < 0) return 1; - return (*value < 0) ? 1 : 0; + *value = (unsigned short)ret; + return 0; } /***************************************************************************** @@ -309,6 +243,8 @@ int miiphy_read(const char *devname, unsigned char addr, unsigned char reg, * Write to the PHY attached to device , * use PHY address and register . * + * This API is deprecated. Use phy_write on a phy_device found by phy_connect + * * Returns: * 0 on success */ @@ -352,6 +288,8 @@ void miiphy_listdev(void) * Model: 6 bits (unsigned char) * Revision: 4 bits (unsigned char) * + * This API is deprecated. + * * Returns: * 0 on success */ @@ -391,6 +329,9 @@ int miiphy_info(const char *devname, unsigned char addr, unsigned int *oui, /***************************************************************************** * * Reset the PHY. + * + * This API is deprecated. Use PHYLIB. + * * Returns: * 0 on success */ @@ -439,7 +380,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; @@ -476,7 +417,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; @@ -492,7 +438,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; @@ -534,7 +480,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. */