diff options
author | Paul Gortmaker <paul.gortmaker@windriver.com> | 2008-04-17 00:08:10 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2008-04-29 01:57:57 -0400 |
commit | d0313587547092af7f5ee8a576793e1e5d61be89 (patch) | |
tree | 57b711ba74fe8ed4dc5219a588b17f0bf4ec7239 /drivers/net | |
parent | dac2f83fce01f0c2900918a4a8abd4c652151804 (diff) |
[netdrvr] gianfar: Determine TBIPA value dynamically
TBIPA needs to be set to a value (on connected MDIO buses) that
doesn't conflict with PHYs on the bus. By hardcoding it to 0x1f,
we were preventing boards with PHYs at 0x1f from working properly.
Instead, scan the bus when it comes up, and find an address that
doesn't have a PHY on it. The TBI PHY configuration code then
trusts that the value in TBIPA is either safe, or doesn't matter
(ie - it's not an active bus with other PHYs).
Signed-off-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/gianfar.c | 27 | ||||
-rw-r--r-- | drivers/net/gianfar.h | 1 | ||||
-rw-r--r-- | drivers/net/gianfar_mii.c | 38 | ||||
-rw-r--r-- | drivers/net/gianfar_mii.h | 3 |
4 files changed, 50 insertions, 19 deletions
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c index 99a4b990939f..587afe7be689 100644 --- a/drivers/net/gianfar.c +++ b/drivers/net/gianfar.c | |||
@@ -131,8 +131,6 @@ static void free_skb_resources(struct gfar_private *priv); | |||
131 | static void gfar_set_multi(struct net_device *dev); | 131 | static void gfar_set_multi(struct net_device *dev); |
132 | static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); | 132 | static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); |
133 | static void gfar_configure_serdes(struct net_device *dev); | 133 | static void gfar_configure_serdes(struct net_device *dev); |
134 | extern int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id, int regnum, u16 value); | ||
135 | extern int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum); | ||
136 | #ifdef CONFIG_GFAR_NAPI | 134 | #ifdef CONFIG_GFAR_NAPI |
137 | static int gfar_poll(struct napi_struct *napi, int budget); | 135 | static int gfar_poll(struct napi_struct *napi, int budget); |
138 | #endif | 136 | #endif |
@@ -477,24 +475,30 @@ static int init_phy(struct net_device *dev) | |||
477 | return 0; | 475 | return 0; |
478 | } | 476 | } |
479 | 477 | ||
478 | /* | ||
479 | * Initialize TBI PHY interface for communicating with the | ||
480 | * SERDES lynx PHY on the chip. We communicate with this PHY | ||
481 | * through the MDIO bus on each controller, treating it as a | ||
482 | * "normal" PHY at the address found in the TBIPA register. We assume | ||
483 | * that the TBIPA register is valid. Either the MDIO bus code will set | ||
484 | * it to a value that doesn't conflict with other PHYs on the bus, or the | ||
485 | * value doesn't matter, as there are no other PHYs on the bus. | ||
486 | */ | ||
480 | static void gfar_configure_serdes(struct net_device *dev) | 487 | static void gfar_configure_serdes(struct net_device *dev) |
481 | { | 488 | { |
482 | struct gfar_private *priv = netdev_priv(dev); | 489 | struct gfar_private *priv = netdev_priv(dev); |
483 | struct gfar_mii __iomem *regs = | 490 | struct gfar_mii __iomem *regs = |
484 | (void __iomem *)&priv->regs->gfar_mii_regs; | 491 | (void __iomem *)&priv->regs->gfar_mii_regs; |
492 | int tbipa = gfar_read(&priv->regs->tbipa); | ||
485 | 493 | ||
486 | /* Initialise TBI i/f to communicate with serdes (lynx phy) */ | 494 | /* Single clk mode, mii mode off(for serdes communication) */ |
495 | gfar_local_mdio_write(regs, tbipa, MII_TBICON, TBICON_CLK_SELECT); | ||
487 | 496 | ||
488 | /* Single clk mode, mii mode off(for aerdes communication) */ | 497 | gfar_local_mdio_write(regs, tbipa, MII_ADVERTISE, |
489 | gfar_local_mdio_write(regs, TBIPA_VALUE, MII_TBICON, TBICON_CLK_SELECT); | ||
490 | |||
491 | /* Supported pause and full-duplex, no half-duplex */ | ||
492 | gfar_local_mdio_write(regs, TBIPA_VALUE, MII_ADVERTISE, | ||
493 | ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE | | 498 | ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE | |
494 | ADVERTISE_1000XPSE_ASYM); | 499 | ADVERTISE_1000XPSE_ASYM); |
495 | 500 | ||
496 | /* ANEG enable, restart ANEG, full duplex mode, speed[1] set */ | 501 | gfar_local_mdio_write(regs, tbipa, MII_BMCR, BMCR_ANENABLE | |
497 | gfar_local_mdio_write(regs, TBIPA_VALUE, MII_BMCR, BMCR_ANENABLE | | ||
498 | BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000); | 502 | BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000); |
499 | } | 503 | } |
500 | 504 | ||
@@ -541,9 +545,6 @@ static void init_registers(struct net_device *dev) | |||
541 | 545 | ||
542 | /* Initialize the Minimum Frame Length Register */ | 546 | /* Initialize the Minimum Frame Length Register */ |
543 | gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS); | 547 | gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS); |
544 | |||
545 | /* Assign the TBI an address which won't conflict with the PHYs */ | ||
546 | gfar_write(&priv->regs->tbipa, TBIPA_VALUE); | ||
547 | } | 548 | } |
548 | 549 | ||
549 | 550 | ||
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h index 0d0883609469..fd487be3993e 100644 --- a/drivers/net/gianfar.h +++ b/drivers/net/gianfar.h | |||
@@ -137,7 +137,6 @@ extern const char gfar_driver_version[]; | |||
137 | #define DEFAULT_RXCOUNT 0 | 137 | #define DEFAULT_RXCOUNT 0 |
138 | #endif /* CONFIG_GFAR_NAPI */ | 138 | #endif /* CONFIG_GFAR_NAPI */ |
139 | 139 | ||
140 | #define TBIPA_VALUE 0x1f | ||
141 | #define MIIMCFG_INIT_VALUE 0x00000007 | 140 | #define MIIMCFG_INIT_VALUE 0x00000007 |
142 | #define MIIMCFG_RESET 0x80000000 | 141 | #define MIIMCFG_RESET 0x80000000 |
143 | #define MIIMIND_BUSY 0x00000001 | 142 | #define MIIMIND_BUSY 0x00000001 |
diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c index b8898927236a..ebcfb27a904e 100644 --- a/drivers/net/gianfar_mii.c +++ b/drivers/net/gianfar_mii.c | |||
@@ -78,7 +78,6 @@ int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id, | |||
78 | * same as system mdio bus, used for controlling the external PHYs, for eg. | 78 | * same as system mdio bus, used for controlling the external PHYs, for eg. |
79 | */ | 79 | */ |
80 | int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum) | 80 | int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum) |
81 | |||
82 | { | 81 | { |
83 | u16 value; | 82 | u16 value; |
84 | 83 | ||
@@ -122,7 +121,7 @@ int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum) | |||
122 | } | 121 | } |
123 | 122 | ||
124 | /* Reset the MIIM registers, and wait for the bus to free */ | 123 | /* Reset the MIIM registers, and wait for the bus to free */ |
125 | int gfar_mdio_reset(struct mii_bus *bus) | 124 | static int gfar_mdio_reset(struct mii_bus *bus) |
126 | { | 125 | { |
127 | struct gfar_mii __iomem *regs = (void __iomem *)bus->priv; | 126 | struct gfar_mii __iomem *regs = (void __iomem *)bus->priv; |
128 | unsigned int timeout = PHY_INIT_TIMEOUT; | 127 | unsigned int timeout = PHY_INIT_TIMEOUT; |
@@ -152,14 +151,15 @@ int gfar_mdio_reset(struct mii_bus *bus) | |||
152 | } | 151 | } |
153 | 152 | ||
154 | 153 | ||
155 | int gfar_mdio_probe(struct device *dev) | 154 | static int gfar_mdio_probe(struct device *dev) |
156 | { | 155 | { |
157 | struct platform_device *pdev = to_platform_device(dev); | 156 | struct platform_device *pdev = to_platform_device(dev); |
158 | struct gianfar_mdio_data *pdata; | 157 | struct gianfar_mdio_data *pdata; |
159 | struct gfar_mii __iomem *regs; | 158 | struct gfar_mii __iomem *regs; |
159 | struct gfar __iomem *enet_regs; | ||
160 | struct mii_bus *new_bus; | 160 | struct mii_bus *new_bus; |
161 | struct resource *r; | 161 | struct resource *r; |
162 | int err = 0; | 162 | int i, err = 0; |
163 | 163 | ||
164 | if (NULL == dev) | 164 | if (NULL == dev) |
165 | return -EINVAL; | 165 | return -EINVAL; |
@@ -199,6 +199,34 @@ int gfar_mdio_probe(struct device *dev) | |||
199 | new_bus->dev = dev; | 199 | new_bus->dev = dev; |
200 | dev_set_drvdata(dev, new_bus); | 200 | dev_set_drvdata(dev, new_bus); |
201 | 201 | ||
202 | /* | ||
203 | * This is mildly evil, but so is our hardware for doing this. | ||
204 | * Also, we have to cast back to struct gfar_mii because of | ||
205 | * definition weirdness done in gianfar.h. | ||
206 | */ | ||
207 | enet_regs = (struct gfar __iomem *) | ||
208 | ((char *)regs - offsetof(struct gfar, gfar_mii_regs)); | ||
209 | |||
210 | /* Scan the bus, looking for an empty spot for TBIPA */ | ||
211 | gfar_write(&enet_regs->tbipa, 0); | ||
212 | for (i = PHY_MAX_ADDR; i > 0; i--) { | ||
213 | u32 phy_id; | ||
214 | int r; | ||
215 | |||
216 | r = get_phy_id(new_bus, i, &phy_id); | ||
217 | if (r) | ||
218 | return r; | ||
219 | |||
220 | if (phy_id == 0xffffffff) | ||
221 | break; | ||
222 | } | ||
223 | |||
224 | /* The bus is full. We don't support using 31 PHYs, sorry */ | ||
225 | if (i == 0) | ||
226 | return -EBUSY; | ||
227 | |||
228 | gfar_write(&enet_regs->tbipa, i); | ||
229 | |||
202 | err = mdiobus_register(new_bus); | 230 | err = mdiobus_register(new_bus); |
203 | 231 | ||
204 | if (0 != err) { | 232 | if (0 != err) { |
@@ -218,7 +246,7 @@ reg_map_fail: | |||
218 | } | 246 | } |
219 | 247 | ||
220 | 248 | ||
221 | int gfar_mdio_remove(struct device *dev) | 249 | static int gfar_mdio_remove(struct device *dev) |
222 | { | 250 | { |
223 | struct mii_bus *bus = dev_get_drvdata(dev); | 251 | struct mii_bus *bus = dev_get_drvdata(dev); |
224 | 252 | ||
diff --git a/drivers/net/gianfar_mii.h b/drivers/net/gianfar_mii.h index b373091c7031..2af28b16a0e2 100644 --- a/drivers/net/gianfar_mii.h +++ b/drivers/net/gianfar_mii.h | |||
@@ -41,6 +41,9 @@ struct gfar_mii { | |||
41 | 41 | ||
42 | int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum); | 42 | int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum); |
43 | int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value); | 43 | int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value); |
44 | int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id, | ||
45 | int regnum, u16 value); | ||
46 | int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum); | ||
44 | int __init gfar_mdio_init(void); | 47 | int __init gfar_mdio_init(void); |
45 | void gfar_mdio_exit(void); | 48 | void gfar_mdio_exit(void); |
46 | #endif /* GIANFAR_PHY_H */ | 49 | #endif /* GIANFAR_PHY_H */ |