aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Gortmaker <paul.gortmaker@windriver.com>2008-04-15 12:49:21 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-04-17 15:31:33 -0400
commitcac1f3c8a80f3fc0b4489d1d3ba29214677ffab2 (patch)
treea4bd716695f61d11f588f5145c879cefa42d6900
parentb1394f961a90a7195ea177ee56d54fe5c37181ca (diff)
phylib: factor out get_phy_id from within get_phy_device
We were already doing what amounts to a get_phy_id from within get_phy_device, and rather than duplicate this for the TBIPA probing, we might as well just factor it out and make it available instead. Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> Acked-by: Andy Fleming <afleming@freescale.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
-rw-r--r--drivers/net/phy/phy_device.c38
-rw-r--r--include/linux/phy.h1
2 files changed, 30 insertions, 9 deletions
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index f4c4fd85425f..8b1121b02f98 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -86,35 +86,55 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
86EXPORT_SYMBOL(phy_device_create); 86EXPORT_SYMBOL(phy_device_create);
87 87
88/** 88/**
89 * get_phy_device - reads the specified PHY device and returns its @phy_device struct 89 * get_phy_id - reads the specified addr for its ID.
90 * @bus: the target MII bus 90 * @bus: the target MII bus
91 * @addr: PHY address on the MII bus 91 * @addr: PHY address on the MII bus
92 * @phy_id: where to store the ID retrieved.
92 * 93 *
93 * Description: Reads the ID registers of the PHY at @addr on the 94 * Description: Reads the ID registers of the PHY at @addr on the
94 * @bus, then allocates and returns the phy_device to represent it. 95 * @bus, stores it in @phy_id and returns zero on success.
95 */ 96 */
96struct phy_device * get_phy_device(struct mii_bus *bus, int addr) 97int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id)
97{ 98{
98 int phy_reg; 99 int phy_reg;
99 u32 phy_id;
100 struct phy_device *dev = NULL;
101 100
102 /* Grab the bits from PHYIR1, and put them 101 /* Grab the bits from PHYIR1, and put them
103 * in the upper half */ 102 * in the upper half */
104 phy_reg = bus->read(bus, addr, MII_PHYSID1); 103 phy_reg = bus->read(bus, addr, MII_PHYSID1);
105 104
106 if (phy_reg < 0) 105 if (phy_reg < 0)
107 return ERR_PTR(phy_reg); 106 return -EIO;
108 107
109 phy_id = (phy_reg & 0xffff) << 16; 108 *phy_id = (phy_reg & 0xffff) << 16;
110 109
111 /* Grab the bits from PHYIR2, and put them in the lower half */ 110 /* Grab the bits from PHYIR2, and put them in the lower half */
112 phy_reg = bus->read(bus, addr, MII_PHYSID2); 111 phy_reg = bus->read(bus, addr, MII_PHYSID2);
113 112
114 if (phy_reg < 0) 113 if (phy_reg < 0)
115 return ERR_PTR(phy_reg); 114 return -EIO;
115
116 *phy_id |= (phy_reg & 0xffff);
117
118 return 0;
119}
120
121/**
122 * get_phy_device - reads the specified PHY device and returns its @phy_device struct
123 * @bus: the target MII bus
124 * @addr: PHY address on the MII bus
125 *
126 * Description: Reads the ID registers of the PHY at @addr on the
127 * @bus, then allocates and returns the phy_device to represent it.
128 */
129struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
130{
131 struct phy_device *dev = NULL;
132 u32 phy_id;
133 int r;
116 134
117 phy_id |= (phy_reg & 0xffff); 135 r = get_phy_id(bus, addr, &phy_id);
136 if (r)
137 return ERR_PTR(r);
118 138
119 /* If the phy_id is all Fs, there is no device there */ 139 /* If the phy_id is all Fs, there is no device there */
120 if (0xffffffff == phy_id) 140 if (0xffffffff == phy_id)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 2d838448415c..779cbcd65f62 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -381,6 +381,7 @@ struct phy_driver {
381 381
382int phy_read(struct phy_device *phydev, u16 regnum); 382int phy_read(struct phy_device *phydev, u16 regnum);
383int phy_write(struct phy_device *phydev, u16 regnum, u16 val); 383int phy_write(struct phy_device *phydev, u16 regnum, u16 val);
384int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id);
384struct phy_device* get_phy_device(struct mii_bus *bus, int addr); 385struct phy_device* get_phy_device(struct mii_bus *bus, int addr);
385int phy_clear_interrupt(struct phy_device *phydev); 386int phy_clear_interrupt(struct phy_device *phydev);
386int phy_config_interrupt(struct phy_device *phydev, u32 interrupts); 387int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);