static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc) { struct usbnet *dev = netdev_priv(netdev); __le16 res; int rc = 0; if (phy_id) { netdev_dbg(netdev, "Only internal phy supported\n"); return 0; } /* Access NSR_LINKST bit for link status instead of MII_BMSR */ if (loc == MII_BMSR) { u8 value; sr_read_reg(dev, SR_NSR, &value); if (value & NSR_LINKST) rc = 1; } sr_share_read_word(dev, 1, loc, &res); if (rc == 1) res = le16_to_cpu(res) | BMSR_LSTATUS; else res = le16_to_cpu(res) & ~BMSR_LSTATUS; netdev_dbg(netdev, "sr_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", phy_id, loc, res); return res; }
static u32 sr9700_android_get_link(struct net_device *net) { struct usbnet *dev = netdev_priv(net); int rc = 0; u8 value = 0; sr_read_reg(dev, NSR, &value); if(value & NSR_LINKST) { rc = 1; } return rc; }
static u32 sr9700_get_link(struct net_device *netdev) { struct usbnet *dev = netdev_priv(netdev); u8 value = 0; int rc = 0; /* Get the Link Status directly */ sr_read_reg(dev, SR_NSR, &value); if (value & NSR_LINKST) rc = 1; return rc; }
static int wait_phy_eeprom_ready(struct usbnet *dev, int phy) { int i; for (i = 0; i < SR_SHARE_TIMEOUT; i++) { u8 tmp = 0; int ret; udelay(1); ret = sr_read_reg(dev, SR_EPCR, &tmp); if (ret < 0) return ret; /* ready */ if (!(tmp & EPCR_ERRE)) return 0; } netdev_err(dev->net, "%s write timed out!\n", phy ? "phy" : "eeprom"); return -EIO; }
/* write one word to phy or eeprom */ static int sr_share_write_word(struct usbnet *dev, int phy, u8 reg, __le16 value) { int ret, i; mutex_lock(&dev->phy_mutex); ret = sr_write(dev, EPDR, 2, &value); if (ret < 0) goto out; sr_write_reg(dev, EPAR, phy ? (reg | 0x40) : reg); sr_write_reg(dev, EPCR, phy ? 0x1a : 0x12); for (i = 0; i < SR_SHARE_TIMEOUT; i++) { u8 tmp; udelay(1); ret = sr_read_reg(dev, EPCR, &tmp); if (ret < 0) goto out; /* ready */ if ((tmp & 1) == 0) break; } if (i >= SR_SHARE_TIMEOUT) { netdev_err(dev->net, "%s write timed out!", phy ? "phy" : "eeprom"); ret = -EIO; goto out; } sr_write_reg(dev, EPCR, 0x0); out: mutex_unlock(&dev->phy_mutex); return ret; }
/* sr9700_android mii-phy register read by word */ static int sr9700_android_mdio_read(struct net_device *netdev, int phy_id, int loc) { struct usbnet *dev = netdev_priv(netdev); __le16 res; #ifdef MII_BUG_FIX int rc = 0; #endif if (phy_id) { netdev_dbg(dev->net, "Only internal phy supported"); return 0; } #ifdef MII_BUG_FIX if(loc == MII_BMSR){ u8 value; sr_read_reg(dev, NSR, &value); if(value & NSR_LINKST) { rc = 1; } } sr_share_read_word(dev, 1, loc, &res); if(rc == 1) return (le16_to_cpu(res) | BMSR_LSTATUS); else return (le16_to_cpu(res) & ~BMSR_LSTATUS); #else sr_share_read_word(dev, 1, loc, &res); #endif netdev_dbg(dev->net, "sr9700_android_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res)); return le16_to_cpu(res); }