diff options
Diffstat (limited to 'drivers/net/phy')
-rw-r--r-- | drivers/net/phy/broadcom.c | 4 | ||||
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 72 | ||||
-rw-r--r-- | drivers/net/phy/phy.c | 4 | ||||
-rw-r--r-- | drivers/net/phy/phy_device.c | 31 |
4 files changed, 83 insertions, 28 deletions
diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index c13cf64095b6..33c4b12a63ba 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c | |||
@@ -331,8 +331,8 @@ static void bcm54xx_adjust_rxrefclk(struct phy_device *phydev) | |||
331 | bool clk125en = true; | 331 | bool clk125en = true; |
332 | 332 | ||
333 | /* Abort if we are using an untested phy. */ | 333 | /* Abort if we are using an untested phy. */ |
334 | if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM57780 || | 334 | if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM57780 && |
335 | BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610 || | 335 | BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610 && |
336 | BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610M) | 336 | BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610M) |
337 | return; | 337 | return; |
338 | 338 | ||
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index bd4e8d72dc08..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,34 +297,88 @@ 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); |
305 | 304 | ||
305 | /* | ||
306 | * We must stop the state machine manually, otherwise it stops out of | ||
307 | * control, possibly with the phydev->lock held. Upon resume, netdev | ||
308 | * may call phy routines that try to grab the same lock, and that may | ||
309 | * lead to a deadlock. | ||
310 | */ | ||
311 | if (phydev->attached_dev) | ||
312 | phy_stop_machine(phydev); | ||
313 | |||
306 | if (!mdio_bus_phy_may_suspend(phydev)) | 314 | if (!mdio_bus_phy_may_suspend(phydev)) |
307 | return 0; | 315 | return 0; |
316 | |||
308 | return phydrv->suspend(phydev); | 317 | return phydrv->suspend(phydev); |
309 | } | 318 | } |
310 | 319 | ||
311 | static int mdio_bus_resume(struct device * dev) | 320 | static int mdio_bus_resume(struct device *dev) |
312 | { | 321 | { |
313 | struct phy_driver *phydrv = to_phy_driver(dev->driver); | 322 | struct phy_driver *phydrv = to_phy_driver(dev->driver); |
314 | struct phy_device *phydev = to_phy_device(dev); | 323 | struct phy_device *phydev = to_phy_device(dev); |
324 | int ret; | ||
315 | 325 | ||
316 | if (!mdio_bus_phy_may_suspend(phydev)) | 326 | if (!mdio_bus_phy_may_suspend(phydev)) |
327 | goto no_resume; | ||
328 | |||
329 | ret = phydrv->resume(phydev); | ||
330 | if (ret < 0) | ||
331 | return ret; | ||
332 | |||
333 | no_resume: | ||
334 | if (phydev->attached_dev) | ||
335 | phy_start_machine(phydev, NULL); | ||
336 | |||
337 | return 0; | ||
338 | } | ||
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) | ||
317 | return 0; | 347 | return 0; |
318 | return phydrv->resume(phydev); | 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; | ||
319 | } | 360 | } |
320 | 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 | |||
321 | struct bus_type mdio_bus_type = { | 378 | struct bus_type mdio_bus_type = { |
322 | .name = "mdio_bus", | 379 | .name = "mdio_bus", |
323 | .match = mdio_bus_match, | 380 | .match = mdio_bus_match, |
324 | .suspend = mdio_bus_suspend, | 381 | .pm = MDIO_BUS_PM_OPS, |
325 | .resume = mdio_bus_resume, | ||
326 | }; | 382 | }; |
327 | EXPORT_SYMBOL(mdio_bus_type); | 383 | EXPORT_SYMBOL(mdio_bus_type); |
328 | 384 | ||
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index b0e9f9c51721..0295097d6c44 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c | |||
@@ -410,7 +410,6 @@ EXPORT_SYMBOL(phy_start_aneg); | |||
410 | 410 | ||
411 | 411 | ||
412 | static void phy_change(struct work_struct *work); | 412 | static void phy_change(struct work_struct *work); |
413 | static void phy_state_machine(struct work_struct *work); | ||
414 | 413 | ||
415 | /** | 414 | /** |
416 | * phy_start_machine - start PHY state machine tracking | 415 | * phy_start_machine - start PHY state machine tracking |
@@ -430,7 +429,6 @@ void phy_start_machine(struct phy_device *phydev, | |||
430 | { | 429 | { |
431 | phydev->adjust_state = handler; | 430 | phydev->adjust_state = handler; |
432 | 431 | ||
433 | INIT_DELAYED_WORK(&phydev->state_queue, phy_state_machine); | ||
434 | schedule_delayed_work(&phydev->state_queue, HZ); | 432 | schedule_delayed_work(&phydev->state_queue, HZ); |
435 | } | 433 | } |
436 | 434 | ||
@@ -761,7 +759,7 @@ EXPORT_SYMBOL(phy_start); | |||
761 | * phy_state_machine - Handle the state machine | 759 | * phy_state_machine - Handle the state machine |
762 | * @work: work_struct that describes the work to be done | 760 | * @work: work_struct that describes the work to be done |
763 | */ | 761 | */ |
764 | static void phy_state_machine(struct work_struct *work) | 762 | void phy_state_machine(struct work_struct *work) |
765 | { | 763 | { |
766 | struct delayed_work *dwork = to_delayed_work(work); | 764 | struct delayed_work *dwork = to_delayed_work(work); |
767 | struct phy_device *phydev = | 765 | struct phy_device *phydev = |
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index b10fedd82143..adbc0fded130 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c | |||
@@ -177,6 +177,7 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id) | |||
177 | dev->state = PHY_DOWN; | 177 | dev->state = PHY_DOWN; |
178 | 178 | ||
179 | mutex_init(&dev->lock); | 179 | mutex_init(&dev->lock); |
180 | INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); | ||
180 | 181 | ||
181 | return dev; | 182 | return dev; |
182 | } | 183 | } |
@@ -378,6 +379,20 @@ void phy_disconnect(struct phy_device *phydev) | |||
378 | } | 379 | } |
379 | EXPORT_SYMBOL(phy_disconnect); | 380 | EXPORT_SYMBOL(phy_disconnect); |
380 | 381 | ||
382 | int phy_init_hw(struct phy_device *phydev) | ||
383 | { | ||
384 | int ret; | ||
385 | |||
386 | if (!phydev->drv || !phydev->drv->config_init) | ||
387 | return 0; | ||
388 | |||
389 | ret = phy_scan_fixups(phydev); | ||
390 | if (ret < 0) | ||
391 | return ret; | ||
392 | |||
393 | return phydev->drv->config_init(phydev); | ||
394 | } | ||
395 | |||
381 | /** | 396 | /** |
382 | * phy_attach_direct - attach a network device to a given PHY device pointer | 397 | * phy_attach_direct - attach a network device to a given PHY device pointer |
383 | * @dev: network device to attach | 398 | * @dev: network device to attach |
@@ -425,21 +440,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, | |||
425 | /* Do initial configuration here, now that | 440 | /* Do initial configuration here, now that |
426 | * we have certain key parameters | 441 | * we have certain key parameters |
427 | * (dev_flags and interface) */ | 442 | * (dev_flags and interface) */ |
428 | if (phydev->drv->config_init) { | 443 | 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 | } | 444 | } |
444 | EXPORT_SYMBOL(phy_attach_direct); | 445 | EXPORT_SYMBOL(phy_attach_direct); |
445 | 446 | ||