diff options
author | Anton Vorontsov <avorontsov@ru.mvista.com> | 2009-12-30 03:23:30 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-12-31 01:03:42 -0500 |
commit | 2f5cb43406d0b29b96248f5328a14a6f6abf8ae6 (patch) | |
tree | f43e017599e590a9fbff22e2973dd77e2bc4fb41 /drivers/net | |
parent | 541cd3ee00a4fe975b22fac6a3bc846bacef37f7 (diff) |
phylib: Properly reinitialize PHYs after hibernation
Since hibernation assumes power loss, we should fully reinitialize
PHYs (including platform fixups), as if PHYs were just attached.
This patch factors phy_init_hw() out of phy_attach_direct(), then
converts mdio_bus to dev_pm_ops and adds an appropriate restore()
callback.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 50 | ||||
-rw-r--r-- | drivers/net/phy/phy_device.c | 30 |
2 files changed, 58 insertions, 22 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 49252d390903..e17b70291bbc 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -264,6 +264,8 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv) | |||
264 | (phydev->phy_id & phydrv->phy_id_mask)); | 264 | (phydev->phy_id & phydrv->phy_id_mask)); |
265 | } | 265 | } |
266 | 266 | ||
267 | #ifdef CONFIG_PM | ||
268 | |||
267 | static bool mdio_bus_phy_may_suspend(struct phy_device *phydev) | 269 | static bool mdio_bus_phy_may_suspend(struct phy_device *phydev) |
268 | { | 270 | { |
269 | struct device_driver *drv = phydev->dev.driver; | 271 | struct device_driver *drv = phydev->dev.driver; |
@@ -295,10 +297,7 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev) | |||
295 | return true; | 297 | return true; |
296 | } | 298 | } |
297 | 299 | ||
298 | /* Suspend and resume. Copied from platform_suspend and | 300 | static int mdio_bus_suspend(struct device *dev) |
299 | * platform_resume | ||
300 | */ | ||
301 | static int mdio_bus_suspend(struct device * dev, pm_message_t state) | ||
302 | { | 301 | { |
303 | struct phy_driver *phydrv = to_phy_driver(dev->driver); | 302 | struct phy_driver *phydrv = to_phy_driver(dev->driver); |
304 | struct phy_device *phydev = to_phy_device(dev); | 303 | struct phy_device *phydev = to_phy_device(dev); |
@@ -318,7 +317,7 @@ static int mdio_bus_suspend(struct device * dev, pm_message_t state) | |||
318 | return phydrv->suspend(phydev); | 317 | return phydrv->suspend(phydev); |
319 | } | 318 | } |
320 | 319 | ||
321 | static int mdio_bus_resume(struct device * dev) | 320 | static int mdio_bus_resume(struct device *dev) |
322 | { | 321 | { |
323 | struct phy_driver *phydrv = to_phy_driver(dev->driver); | 322 | struct phy_driver *phydrv = to_phy_driver(dev->driver); |
324 | struct phy_device *phydev = to_phy_device(dev); | 323 | struct phy_device *phydev = to_phy_device(dev); |
@@ -338,11 +337,48 @@ no_resume: | |||
338 | return 0; | 337 | return 0; |
339 | } | 338 | } |
340 | 339 | ||
340 | static int mdio_bus_restore(struct device *dev) | ||
341 | { | ||
342 | struct phy_device *phydev = to_phy_device(dev); | ||
343 | struct net_device *netdev = phydev->attached_dev; | ||
344 | int ret; | ||
345 | |||
346 | if (!netdev) | ||
347 | return 0; | ||
348 | |||
349 | ret = phy_init_hw(phydev); | ||
350 | if (ret < 0) | ||
351 | return ret; | ||
352 | |||
353 | /* The PHY needs to renegotiate. */ | ||
354 | phydev->link = 0; | ||
355 | phydev->state = PHY_UP; | ||
356 | |||
357 | phy_start_machine(phydev, NULL); | ||
358 | |||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | static struct dev_pm_ops mdio_bus_pm_ops = { | ||
363 | .suspend = mdio_bus_suspend, | ||
364 | .resume = mdio_bus_resume, | ||
365 | .freeze = mdio_bus_suspend, | ||
366 | .thaw = mdio_bus_resume, | ||
367 | .restore = mdio_bus_restore, | ||
368 | }; | ||
369 | |||
370 | #define MDIO_BUS_PM_OPS (&mdio_bus_pm_ops) | ||
371 | |||
372 | #else | ||
373 | |||
374 | #define MDIO_BUS_PM_OPS NULL | ||
375 | |||
376 | #endif /* CONFIG_PM */ | ||
377 | |||
341 | struct bus_type mdio_bus_type = { | 378 | struct bus_type mdio_bus_type = { |
342 | .name = "mdio_bus", | 379 | .name = "mdio_bus", |
343 | .match = mdio_bus_match, | 380 | .match = mdio_bus_match, |
344 | .suspend = mdio_bus_suspend, | 381 | .pm = MDIO_BUS_PM_OPS, |
345 | .resume = mdio_bus_resume, | ||
346 | }; | 382 | }; |
347 | EXPORT_SYMBOL(mdio_bus_type); | 383 | EXPORT_SYMBOL(mdio_bus_type); |
348 | 384 | ||
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index b10fedd82143..8212b2b93422 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c | |||
@@ -378,6 +378,20 @@ void phy_disconnect(struct phy_device *phydev) | |||
378 | } | 378 | } |
379 | EXPORT_SYMBOL(phy_disconnect); | 379 | EXPORT_SYMBOL(phy_disconnect); |
380 | 380 | ||
381 | int phy_init_hw(struct phy_device *phydev) | ||
382 | { | ||
383 | int ret; | ||
384 | |||
385 | if (!phydev->drv || !phydev->drv->config_init) | ||
386 | return 0; | ||
387 | |||
388 | ret = phy_scan_fixups(phydev); | ||
389 | if (ret < 0) | ||
390 | return ret; | ||
391 | |||
392 | return phydev->drv->config_init(phydev); | ||
393 | } | ||
394 | |||
381 | /** | 395 | /** |
382 | * phy_attach_direct - attach a network device to a given PHY device pointer | 396 | * phy_attach_direct - attach a network device to a given PHY device pointer |
383 | * @dev: network device to attach | 397 | * @dev: network device to attach |
@@ -425,21 +439,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, | |||
425 | /* Do initial configuration here, now that | 439 | /* Do initial configuration here, now that |
426 | * we have certain key parameters | 440 | * we have certain key parameters |
427 | * (dev_flags and interface) */ | 441 | * (dev_flags and interface) */ |
428 | if (phydev->drv->config_init) { | 442 | return phy_init_hw(phydev); |
429 | int err; | ||
430 | |||
431 | err = phy_scan_fixups(phydev); | ||
432 | |||
433 | if (err < 0) | ||
434 | return err; | ||
435 | |||
436 | err = phydev->drv->config_init(phydev); | ||
437 | |||
438 | if (err < 0) | ||
439 | return err; | ||
440 | } | ||
441 | |||
442 | return 0; | ||
443 | } | 443 | } |
444 | EXPORT_SYMBOL(phy_attach_direct); | 444 | EXPORT_SYMBOL(phy_attach_direct); |
445 | 445 | ||