diff options
-rw-r--r-- | drivers/net/phy/Kconfig | 8 | ||||
-rw-r--r-- | drivers/net/phy/Makefile | 11 | ||||
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 79 | ||||
-rw-r--r-- | drivers/net/phy/phy.c | 325 | ||||
-rw-r--r-- | drivers/net/phy/phy_device.c | 172 | ||||
-rw-r--r-- | include/linux/phy.h | 17 |
6 files changed, 510 insertions, 102 deletions
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 6450bd71deb4..6a2fe3583478 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig | |||
@@ -12,6 +12,14 @@ config PHYLIB | |||
12 | devices. This option provides infrastructure for | 12 | devices. This option provides infrastructure for |
13 | managing PHY devices. | 13 | managing PHY devices. |
14 | 14 | ||
15 | config PHYCONTROL | ||
16 | bool " Support for automatically handling PHY state changes" | ||
17 | depends on PHYLIB | ||
18 | help | ||
19 | Adds code to perform all the work for keeping PHY link | ||
20 | state (speed/duplex/etc) up-to-date. Also handles | ||
21 | interrupts. | ||
22 | |||
15 | comment "MII PHY device drivers" | 23 | comment "MII PHY device drivers" |
16 | depends on PHYLIB | 24 | depends on PHYLIB |
17 | 25 | ||
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index fb7cb385a659..e4116a5fbb4c 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile | |||
@@ -2,8 +2,9 @@ | |||
2 | 2 | ||
3 | libphy-objs := phy.o phy_device.o mdio_bus.o | 3 | libphy-objs := phy.o phy_device.o mdio_bus.o |
4 | 4 | ||
5 | obj-$(CONFIG_MARVELL_PHY) += libphy.o marvell.o | 5 | obj-$(CONFIG_PHYLIB) += libphy.o |
6 | obj-$(CONFIG_DAVICOM_PHY) += libphy.o davicom.o | 6 | obj-$(CONFIG_MARVELL_PHY) += marvell.o |
7 | obj-$(CONFIG_CICADA_PHY) += libphy.o cicada.o | 7 | obj-$(CONFIG_DAVICOM_PHY) += davicom.o |
8 | obj-$(CONFIG_LXT_PHY) += libphy.o lxt.o | 8 | obj-$(CONFIG_CICADA_PHY) += cicada.o |
9 | obj-$(CONFIG_QSEMI_PHY) += libphy.o qsemi.o | 9 | obj-$(CONFIG_LXT_PHY) += lxt.o |
10 | obj-$(CONFIG_QSEMI_PHY) += qsemi.o | ||
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index d5a05be28818..41f62c0c5fcb 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -38,6 +38,80 @@ | |||
38 | #include <asm/irq.h> | 38 | #include <asm/irq.h> |
39 | #include <asm/uaccess.h> | 39 | #include <asm/uaccess.h> |
40 | 40 | ||
41 | /* mdiobus_register | ||
42 | * | ||
43 | * description: Called by a bus driver to bring up all the PHYs | ||
44 | * on a given bus, and attach them to the bus | ||
45 | */ | ||
46 | int mdiobus_register(struct mii_bus *bus) | ||
47 | { | ||
48 | int i; | ||
49 | int err = 0; | ||
50 | |||
51 | spin_lock_init(&bus->mdio_lock); | ||
52 | |||
53 | if (NULL == bus || NULL == bus->name || | ||
54 | NULL == bus->read || | ||
55 | NULL == bus->write) | ||
56 | return -EINVAL; | ||
57 | |||
58 | if (bus->reset) | ||
59 | bus->reset(bus); | ||
60 | |||
61 | for (i = 0; i < PHY_MAX_ADDR; i++) { | ||
62 | struct phy_device *phydev; | ||
63 | |||
64 | phydev = get_phy_device(bus, i); | ||
65 | |||
66 | if (IS_ERR(phydev)) | ||
67 | return PTR_ERR(phydev); | ||
68 | |||
69 | /* There's a PHY at this address | ||
70 | * We need to set: | ||
71 | * 1) IRQ | ||
72 | * 2) bus_id | ||
73 | * 3) parent | ||
74 | * 4) bus | ||
75 | * 5) mii_bus | ||
76 | * And, we need to register it */ | ||
77 | if (phydev) { | ||
78 | phydev->irq = bus->irq[i]; | ||
79 | |||
80 | phydev->dev.parent = bus->dev; | ||
81 | phydev->dev.bus = &mdio_bus_type; | ||
82 | sprintf(phydev->dev.bus_id, "phy%d:%d", bus->id, i); | ||
83 | |||
84 | phydev->bus = bus; | ||
85 | |||
86 | err = device_register(&phydev->dev); | ||
87 | |||
88 | if (err) | ||
89 | printk(KERN_ERR "phy %d failed to register\n", | ||
90 | i); | ||
91 | } | ||
92 | |||
93 | bus->phy_map[i] = phydev; | ||
94 | } | ||
95 | |||
96 | pr_info("%s: probed\n", bus->name); | ||
97 | |||
98 | return err; | ||
99 | } | ||
100 | EXPORT_SYMBOL(mdiobus_register); | ||
101 | |||
102 | void mdiobus_unregister(struct mii_bus *bus) | ||
103 | { | ||
104 | int i; | ||
105 | |||
106 | for (i = 0; i < PHY_MAX_ADDR; i++) { | ||
107 | if (bus->phy_map[i]) { | ||
108 | device_unregister(&bus->phy_map[i]->dev); | ||
109 | kfree(bus->phy_map[i]); | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | EXPORT_SYMBOL(mdiobus_unregister); | ||
114 | |||
41 | /* mdio_bus_match | 115 | /* mdio_bus_match |
42 | * | 116 | * |
43 | * description: Given a PHY device, and a PHY driver, return 1 if | 117 | * description: Given a PHY device, and a PHY driver, return 1 if |
@@ -96,4 +170,7 @@ int __init mdio_bus_init(void) | |||
96 | return bus_register(&mdio_bus_type); | 170 | return bus_register(&mdio_bus_type); |
97 | } | 171 | } |
98 | 172 | ||
99 | 173 | void __exit mdio_bus_exit(void) | |
174 | { | ||
175 | bus_unregister(&mdio_bus_type); | ||
176 | } | ||
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index d3e43631b89b..d9e11f93bf3a 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c | |||
@@ -39,10 +39,20 @@ | |||
39 | #include <asm/irq.h> | 39 | #include <asm/irq.h> |
40 | #include <asm/uaccess.h> | 40 | #include <asm/uaccess.h> |
41 | 41 | ||
42 | static void phy_timer(unsigned long data); | 42 | /* Convenience function to print out the current phy status |
43 | static int phy_disable_interrupts(struct phy_device *phydev); | 43 | */ |
44 | static void phy_sanitize_settings(struct phy_device *phydev); | 44 | void phy_print_status(struct phy_device *phydev) |
45 | static int phy_stop_interrupts(struct phy_device *phydev); | 45 | { |
46 | pr_info("%s: Link is %s", phydev->dev.bus_id, | ||
47 | phydev->link ? "Up" : "Down"); | ||
48 | if (phydev->link) | ||
49 | printk(" - %d/%s", phydev->speed, | ||
50 | DUPLEX_FULL == phydev->duplex ? | ||
51 | "Full" : "Half"); | ||
52 | |||
53 | printk("\n"); | ||
54 | } | ||
55 | EXPORT_SYMBOL(phy_print_status); | ||
46 | 56 | ||
47 | 57 | ||
48 | /* Convenience functions for reading/writing a given PHY | 58 | /* Convenience functions for reading/writing a given PHY |
@@ -114,42 +124,6 @@ static inline int phy_aneg_done(struct phy_device *phydev) | |||
114 | return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE); | 124 | return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE); |
115 | } | 125 | } |
116 | 126 | ||
117 | /* phy_start_aneg | ||
118 | * | ||
119 | * description: Calls the PHY driver's config_aneg, and then | ||
120 | * sets the PHY state to PHY_AN if auto-negotiation is enabled, | ||
121 | * and to PHY_FORCING if auto-negotiation is disabled. Unless | ||
122 | * the PHY is currently HALTED. | ||
123 | */ | ||
124 | static int phy_start_aneg(struct phy_device *phydev) | ||
125 | { | ||
126 | int err; | ||
127 | |||
128 | spin_lock(&phydev->lock); | ||
129 | |||
130 | if (AUTONEG_DISABLE == phydev->autoneg) | ||
131 | phy_sanitize_settings(phydev); | ||
132 | |||
133 | err = phydev->drv->config_aneg(phydev); | ||
134 | |||
135 | if (err < 0) | ||
136 | goto out_unlock; | ||
137 | |||
138 | if (phydev->state != PHY_HALTED) { | ||
139 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
140 | phydev->state = PHY_AN; | ||
141 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
142 | } else { | ||
143 | phydev->state = PHY_FORCING; | ||
144 | phydev->link_timeout = PHY_FORCE_TIMEOUT; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | out_unlock: | ||
149 | spin_unlock(&phydev->lock); | ||
150 | return err; | ||
151 | } | ||
152 | |||
153 | /* A structure for mapping a particular speed and duplex | 127 | /* A structure for mapping a particular speed and duplex |
154 | * combination to a particular SUPPORTED and ADVERTISED value */ | 128 | * combination to a particular SUPPORTED and ADVERTISED value */ |
155 | struct phy_setting { | 129 | struct phy_setting { |
@@ -241,7 +215,7 @@ static inline int phy_find_valid(int idx, u32 features) | |||
241 | * duplexes. Drop down by one in this order: 1000/FULL, | 215 | * duplexes. Drop down by one in this order: 1000/FULL, |
242 | * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF | 216 | * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF |
243 | */ | 217 | */ |
244 | static void phy_sanitize_settings(struct phy_device *phydev) | 218 | void phy_sanitize_settings(struct phy_device *phydev) |
245 | { | 219 | { |
246 | u32 features = phydev->supported; | 220 | u32 features = phydev->supported; |
247 | int idx; | 221 | int idx; |
@@ -256,31 +230,7 @@ static void phy_sanitize_settings(struct phy_device *phydev) | |||
256 | phydev->speed = settings[idx].speed; | 230 | phydev->speed = settings[idx].speed; |
257 | phydev->duplex = settings[idx].duplex; | 231 | phydev->duplex = settings[idx].duplex; |
258 | } | 232 | } |
259 | 233 | EXPORT_SYMBOL(phy_sanitize_settings); | |
260 | /* phy_force_reduction | ||
261 | * | ||
262 | * description: Reduces the speed/duplex settings by | ||
263 | * one notch. The order is so: | ||
264 | * 1000/FULL, 1000/HALF, 100/FULL, 100/HALF, | ||
265 | * 10/FULL, 10/HALF. The function bottoms out at 10/HALF. | ||
266 | */ | ||
267 | static void phy_force_reduction(struct phy_device *phydev) | ||
268 | { | ||
269 | int idx; | ||
270 | |||
271 | idx = phy_find_setting(phydev->speed, phydev->duplex); | ||
272 | |||
273 | idx++; | ||
274 | |||
275 | idx = phy_find_valid(idx, phydev->supported); | ||
276 | |||
277 | phydev->speed = settings[idx].speed; | ||
278 | phydev->duplex = settings[idx].duplex; | ||
279 | |||
280 | pr_info("Trying %d/%s\n", phydev->speed, | ||
281 | DUPLEX_FULL == phydev->duplex ? | ||
282 | "FULL" : "HALF"); | ||
283 | } | ||
284 | 234 | ||
285 | /* phy_ethtool_sset: | 235 | /* phy_ethtool_sset: |
286 | * A generic ethtool sset function. Handles all the details | 236 | * A generic ethtool sset function. Handles all the details |
@@ -291,6 +241,11 @@ static void phy_force_reduction(struct phy_device *phydev) | |||
291 | * - phy_start_aneg() will make sure forced settings are sane, and | 241 | * - phy_start_aneg() will make sure forced settings are sane, and |
292 | * choose the next best ones from the ones selected, so we don't | 242 | * choose the next best ones from the ones selected, so we don't |
293 | * care if ethtool tries to give us bad values | 243 | * care if ethtool tries to give us bad values |
244 | * | ||
245 | * A note about the PHYCONTROL Layer. If you turn off | ||
246 | * CONFIG_PHYCONTROL, you will need to read the PHY status | ||
247 | * registers after this function completes, and update your | ||
248 | * controller manually. | ||
294 | */ | 249 | */ |
295 | int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) | 250 | int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) |
296 | { | 251 | { |
@@ -406,6 +361,51 @@ int phy_mii_ioctl(struct phy_device *phydev, | |||
406 | return 0; | 361 | return 0; |
407 | } | 362 | } |
408 | 363 | ||
364 | /* phy_start_aneg | ||
365 | * | ||
366 | * description: Sanitizes the settings (if we're not | ||
367 | * autonegotiating them), and then calls the driver's | ||
368 | * config_aneg function. If the PHYCONTROL Layer is operating, | ||
369 | * we change the state to reflect the beginning of | ||
370 | * Auto-negotiation or forcing. | ||
371 | */ | ||
372 | int phy_start_aneg(struct phy_device *phydev) | ||
373 | { | ||
374 | int err; | ||
375 | |||
376 | spin_lock(&phydev->lock); | ||
377 | |||
378 | if (AUTONEG_DISABLE == phydev->autoneg) | ||
379 | phy_sanitize_settings(phydev); | ||
380 | |||
381 | err = phydev->drv->config_aneg(phydev); | ||
382 | |||
383 | #ifdef CONFIG_PHYCONTROL | ||
384 | if (err < 0) | ||
385 | goto out_unlock; | ||
386 | |||
387 | if (phydev->state != PHY_HALTED) { | ||
388 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
389 | phydev->state = PHY_AN; | ||
390 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
391 | } else { | ||
392 | phydev->state = PHY_FORCING; | ||
393 | phydev->link_timeout = PHY_FORCE_TIMEOUT; | ||
394 | } | ||
395 | } | ||
396 | |||
397 | out_unlock: | ||
398 | #endif | ||
399 | spin_unlock(&phydev->lock); | ||
400 | return err; | ||
401 | } | ||
402 | EXPORT_SYMBOL(phy_start_aneg); | ||
403 | |||
404 | |||
405 | #ifdef CONFIG_PHYCONTROL | ||
406 | static void phy_change(void *data); | ||
407 | static void phy_timer(unsigned long data); | ||
408 | |||
409 | /* phy_start_machine: | 409 | /* phy_start_machine: |
410 | * | 410 | * |
411 | * description: The PHY infrastructure can run a state machine | 411 | * description: The PHY infrastructure can run a state machine |
@@ -448,6 +448,32 @@ void phy_stop_machine(struct phy_device *phydev) | |||
448 | phydev->adjust_state = NULL; | 448 | phydev->adjust_state = NULL; |
449 | } | 449 | } |
450 | 450 | ||
451 | /* phy_force_reduction | ||
452 | * | ||
453 | * description: Reduces the speed/duplex settings by | ||
454 | * one notch. The order is so: | ||
455 | * 1000/FULL, 1000/HALF, 100/FULL, 100/HALF, | ||
456 | * 10/FULL, 10/HALF. The function bottoms out at 10/HALF. | ||
457 | */ | ||
458 | static void phy_force_reduction(struct phy_device *phydev) | ||
459 | { | ||
460 | int idx; | ||
461 | |||
462 | idx = phy_find_setting(phydev->speed, phydev->duplex); | ||
463 | |||
464 | idx++; | ||
465 | |||
466 | idx = phy_find_valid(idx, phydev->supported); | ||
467 | |||
468 | phydev->speed = settings[idx].speed; | ||
469 | phydev->duplex = settings[idx].duplex; | ||
470 | |||
471 | pr_info("Trying %d/%s\n", phydev->speed, | ||
472 | DUPLEX_FULL == phydev->duplex ? | ||
473 | "FULL" : "HALF"); | ||
474 | } | ||
475 | |||
476 | |||
451 | /* phy_error: | 477 | /* phy_error: |
452 | * | 478 | * |
453 | * Moves the PHY to the HALTED state in response to a read | 479 | * Moves the PHY to the HALTED state in response to a read |
@@ -462,22 +488,44 @@ void phy_error(struct phy_device *phydev) | |||
462 | spin_unlock(&phydev->lock); | 488 | spin_unlock(&phydev->lock); |
463 | } | 489 | } |
464 | 490 | ||
465 | static int phy_stop_interrupts(struct phy_device *phydev) | 491 | /* phy_interrupt |
492 | * | ||
493 | * description: When a PHY interrupt occurs, the handler disables | ||
494 | * interrupts, and schedules a work task to clear the interrupt. | ||
495 | */ | ||
496 | static irqreturn_t phy_interrupt(int irq, void *phy_dat, struct pt_regs *regs) | ||
497 | { | ||
498 | struct phy_device *phydev = phy_dat; | ||
499 | |||
500 | /* The MDIO bus is not allowed to be written in interrupt | ||
501 | * context, so we need to disable the irq here. A work | ||
502 | * queue will write the PHY to disable and clear the | ||
503 | * interrupt, and then reenable the irq line. */ | ||
504 | disable_irq_nosync(irq); | ||
505 | |||
506 | schedule_work(&phydev->phy_queue); | ||
507 | |||
508 | return IRQ_HANDLED; | ||
509 | } | ||
510 | |||
511 | /* Enable the interrupts from the PHY side */ | ||
512 | int phy_enable_interrupts(struct phy_device *phydev) | ||
466 | { | 513 | { |
467 | int err; | 514 | int err; |
468 | 515 | ||
469 | err = phy_disable_interrupts(phydev); | 516 | err = phy_clear_interrupt(phydev); |
470 | 517 | ||
471 | if (err) | 518 | if (err < 0) |
472 | phy_error(phydev); | 519 | return err; |
473 | 520 | ||
474 | free_irq(phydev->irq, phydev); | 521 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); |
475 | 522 | ||
476 | return err; | 523 | return err; |
477 | } | 524 | } |
525 | EXPORT_SYMBOL(phy_enable_interrupts); | ||
478 | 526 | ||
479 | /* Disable the PHY interrupts from the PHY side */ | 527 | /* Disable the PHY interrupts from the PHY side */ |
480 | static int phy_disable_interrupts(struct phy_device *phydev) | 528 | int phy_disable_interrupts(struct phy_device *phydev) |
481 | { | 529 | { |
482 | int err; | 530 | int err; |
483 | 531 | ||
@@ -500,6 +548,138 @@ phy_err: | |||
500 | 548 | ||
501 | return err; | 549 | return err; |
502 | } | 550 | } |
551 | EXPORT_SYMBOL(phy_disable_interrupts); | ||
552 | |||
553 | /* phy_start_interrupts | ||
554 | * | ||
555 | * description: Request the interrupt for the given PHY. If | ||
556 | * this fails, then we set irq to PHY_POLL. | ||
557 | * Otherwise, we enable the interrupts in the PHY. | ||
558 | * Returns 0 on success. | ||
559 | * This should only be called with a valid IRQ number. | ||
560 | */ | ||
561 | int phy_start_interrupts(struct phy_device *phydev) | ||
562 | { | ||
563 | int err = 0; | ||
564 | |||
565 | INIT_WORK(&phydev->phy_queue, phy_change, phydev); | ||
566 | |||
567 | if (request_irq(phydev->irq, phy_interrupt, | ||
568 | SA_SHIRQ, | ||
569 | "phy_interrupt", | ||
570 | phydev) < 0) { | ||
571 | printk(KERN_WARNING "%s: Can't get IRQ %d (PHY)\n", | ||
572 | phydev->bus->name, | ||
573 | phydev->irq); | ||
574 | phydev->irq = PHY_POLL; | ||
575 | return 0; | ||
576 | } | ||
577 | |||
578 | err = phy_enable_interrupts(phydev); | ||
579 | |||
580 | return err; | ||
581 | } | ||
582 | EXPORT_SYMBOL(phy_start_interrupts); | ||
583 | |||
584 | int phy_stop_interrupts(struct phy_device *phydev) | ||
585 | { | ||
586 | int err; | ||
587 | |||
588 | err = phy_disable_interrupts(phydev); | ||
589 | |||
590 | if (err) | ||
591 | phy_error(phydev); | ||
592 | |||
593 | free_irq(phydev->irq, phydev); | ||
594 | |||
595 | return err; | ||
596 | } | ||
597 | EXPORT_SYMBOL(phy_stop_interrupts); | ||
598 | |||
599 | |||
600 | /* Scheduled by the phy_interrupt/timer to handle PHY changes */ | ||
601 | static void phy_change(void *data) | ||
602 | { | ||
603 | int err; | ||
604 | struct phy_device *phydev = data; | ||
605 | |||
606 | err = phy_disable_interrupts(phydev); | ||
607 | |||
608 | if (err) | ||
609 | goto phy_err; | ||
610 | |||
611 | spin_lock(&phydev->lock); | ||
612 | if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state)) | ||
613 | phydev->state = PHY_CHANGELINK; | ||
614 | spin_unlock(&phydev->lock); | ||
615 | |||
616 | enable_irq(phydev->irq); | ||
617 | |||
618 | /* Reenable interrupts */ | ||
619 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | ||
620 | |||
621 | if (err) | ||
622 | goto irq_enable_err; | ||
623 | |||
624 | return; | ||
625 | |||
626 | irq_enable_err: | ||
627 | disable_irq(phydev->irq); | ||
628 | phy_err: | ||
629 | phy_error(phydev); | ||
630 | } | ||
631 | |||
632 | /* Bring down the PHY link, and stop checking the status. */ | ||
633 | void phy_stop(struct phy_device *phydev) | ||
634 | { | ||
635 | spin_lock(&phydev->lock); | ||
636 | |||
637 | if (PHY_HALTED == phydev->state) | ||
638 | goto out_unlock; | ||
639 | |||
640 | if (phydev->irq != PHY_POLL) { | ||
641 | /* Clear any pending interrupts */ | ||
642 | phy_clear_interrupt(phydev); | ||
643 | |||
644 | /* Disable PHY Interrupts */ | ||
645 | phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); | ||
646 | } | ||
647 | |||
648 | phydev->state = PHY_HALTED; | ||
649 | |||
650 | out_unlock: | ||
651 | spin_unlock(&phydev->lock); | ||
652 | } | ||
653 | |||
654 | |||
655 | /* phy_start | ||
656 | * | ||
657 | * description: Indicates the attached device's readiness to | ||
658 | * handle PHY-related work. Used during startup to start the | ||
659 | * PHY, and after a call to phy_stop() to resume operation. | ||
660 | * Also used to indicate the MDIO bus has cleared an error | ||
661 | * condition. | ||
662 | */ | ||
663 | void phy_start(struct phy_device *phydev) | ||
664 | { | ||
665 | spin_lock(&phydev->lock); | ||
666 | |||
667 | switch (phydev->state) { | ||
668 | case PHY_STARTING: | ||
669 | phydev->state = PHY_PENDING; | ||
670 | break; | ||
671 | case PHY_READY: | ||
672 | phydev->state = PHY_UP; | ||
673 | break; | ||
674 | case PHY_HALTED: | ||
675 | phydev->state = PHY_RESUMING; | ||
676 | default: | ||
677 | break; | ||
678 | } | ||
679 | spin_unlock(&phydev->lock); | ||
680 | } | ||
681 | EXPORT_SYMBOL(phy_stop); | ||
682 | EXPORT_SYMBOL(phy_start); | ||
503 | 683 | ||
504 | /* PHY timer which handles the state machine */ | 684 | /* PHY timer which handles the state machine */ |
505 | static void phy_timer(unsigned long data) | 685 | static void phy_timer(unsigned long data) |
@@ -688,3 +868,4 @@ static void phy_timer(unsigned long data) | |||
688 | mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ); | 868 | mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ); |
689 | } | 869 | } |
690 | 870 | ||
871 | #endif /* CONFIG_PHYCONTROL */ | ||
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c44d54f6310a..33f7bdb5857c 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c | |||
@@ -39,18 +39,9 @@ | |||
39 | #include <asm/irq.h> | 39 | #include <asm/irq.h> |
40 | #include <asm/uaccess.h> | 40 | #include <asm/uaccess.h> |
41 | 41 | ||
42 | static int genphy_config_init(struct phy_device *phydev); | 42 | static struct phy_driver genphy_driver; |
43 | 43 | extern int mdio_bus_init(void); | |
44 | static struct phy_driver genphy_driver = { | 44 | extern void mdio_bus_exit(void); |
45 | .phy_id = 0xffffffff, | ||
46 | .phy_id_mask = 0xffffffff, | ||
47 | .name = "Generic PHY", | ||
48 | .config_init = genphy_config_init, | ||
49 | .features = 0, | ||
50 | .config_aneg = genphy_config_aneg, | ||
51 | .read_status = genphy_read_status, | ||
52 | .driver = {.owner = THIS_MODULE, }, | ||
53 | }; | ||
54 | 45 | ||
55 | /* get_phy_device | 46 | /* get_phy_device |
56 | * | 47 | * |
@@ -110,6 +101,7 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr) | |||
110 | return dev; | 101 | return dev; |
111 | } | 102 | } |
112 | 103 | ||
104 | #ifdef CONFIG_PHYCONTROL | ||
113 | /* phy_prepare_link: | 105 | /* phy_prepare_link: |
114 | * | 106 | * |
115 | * description: Tells the PHY infrastructure to handle the | 107 | * description: Tells the PHY infrastructure to handle the |
@@ -124,6 +116,132 @@ void phy_prepare_link(struct phy_device *phydev, | |||
124 | phydev->adjust_link = handler; | 116 | phydev->adjust_link = handler; |
125 | } | 117 | } |
126 | 118 | ||
119 | /* phy_connect: | ||
120 | * | ||
121 | * description: Convenience function for connecting ethernet | ||
122 | * devices to PHY devices. The default behavior is for | ||
123 | * the PHY infrastructure to handle everything, and only notify | ||
124 | * the connected driver when the link status changes. If you | ||
125 | * don't want, or can't use the provided functionality, you may | ||
126 | * choose to call only the subset of functions which provide | ||
127 | * the desired functionality. | ||
128 | */ | ||
129 | struct phy_device * phy_connect(struct net_device *dev, const char *phy_id, | ||
130 | void (*handler)(struct net_device *), u32 flags) | ||
131 | { | ||
132 | struct phy_device *phydev; | ||
133 | |||
134 | phydev = phy_attach(dev, phy_id, flags); | ||
135 | |||
136 | if (IS_ERR(phydev)) | ||
137 | return phydev; | ||
138 | |||
139 | phy_prepare_link(phydev, handler); | ||
140 | |||
141 | phy_start_machine(phydev, NULL); | ||
142 | |||
143 | if (phydev->irq > 0) | ||
144 | phy_start_interrupts(phydev); | ||
145 | |||
146 | return phydev; | ||
147 | } | ||
148 | EXPORT_SYMBOL(phy_connect); | ||
149 | |||
150 | void phy_disconnect(struct phy_device *phydev) | ||
151 | { | ||
152 | if (phydev->irq > 0) | ||
153 | phy_stop_interrupts(phydev); | ||
154 | |||
155 | phy_stop_machine(phydev); | ||
156 | |||
157 | phydev->adjust_link = NULL; | ||
158 | |||
159 | phy_detach(phydev); | ||
160 | } | ||
161 | EXPORT_SYMBOL(phy_disconnect); | ||
162 | |||
163 | #endif /* CONFIG_PHYCONTROL */ | ||
164 | |||
165 | /* phy_attach: | ||
166 | * | ||
167 | * description: Called by drivers to attach to a particular PHY | ||
168 | * device. The phy_device is found, and properly hooked up | ||
169 | * to the phy_driver. If no driver is attached, then the | ||
170 | * genphy_driver is used. The phy_device is given a ptr to | ||
171 | * the attaching device, and given a callback for link status | ||
172 | * change. The phy_device is returned to the attaching | ||
173 | * driver. | ||
174 | */ | ||
175 | static int phy_compare_id(struct device *dev, void *data) | ||
176 | { | ||
177 | return strcmp((char *)data, dev->bus_id) ? 0 : 1; | ||
178 | } | ||
179 | |||
180 | struct phy_device *phy_attach(struct net_device *dev, | ||
181 | const char *phy_id, u32 flags) | ||
182 | { | ||
183 | struct bus_type *bus = &mdio_bus_type; | ||
184 | struct phy_device *phydev; | ||
185 | struct device *d; | ||
186 | |||
187 | /* Search the list of PHY devices on the mdio bus for the | ||
188 | * PHY with the requested name */ | ||
189 | d = bus_find_device(bus, NULL, (void *)phy_id, phy_compare_id); | ||
190 | |||
191 | if (d) { | ||
192 | phydev = to_phy_device(d); | ||
193 | } else { | ||
194 | printk(KERN_ERR "%s not found\n", phy_id); | ||
195 | return ERR_PTR(-ENODEV); | ||
196 | } | ||
197 | |||
198 | /* Assume that if there is no driver, that it doesn't | ||
199 | * exist, and we should use the genphy driver. */ | ||
200 | if (NULL == d->driver) { | ||
201 | int err; | ||
202 | down_write(&d->bus->subsys.rwsem); | ||
203 | d->driver = &genphy_driver.driver; | ||
204 | |||
205 | err = d->driver->probe(d); | ||
206 | |||
207 | if (err < 0) | ||
208 | return ERR_PTR(err); | ||
209 | |||
210 | device_bind_driver(d); | ||
211 | up_write(&d->bus->subsys.rwsem); | ||
212 | } | ||
213 | |||
214 | if (phydev->attached_dev) { | ||
215 | printk(KERN_ERR "%s: %s already attached\n", | ||
216 | dev->name, phy_id); | ||
217 | return ERR_PTR(-EBUSY); | ||
218 | } | ||
219 | |||
220 | phydev->attached_dev = dev; | ||
221 | |||
222 | phydev->dev_flags = flags; | ||
223 | |||
224 | return phydev; | ||
225 | } | ||
226 | EXPORT_SYMBOL(phy_attach); | ||
227 | |||
228 | void phy_detach(struct phy_device *phydev) | ||
229 | { | ||
230 | phydev->attached_dev = NULL; | ||
231 | |||
232 | /* If the device had no specific driver before (i.e. - it | ||
233 | * was using the generic driver), we unbind the device | ||
234 | * from the generic driver so that there's a chance a | ||
235 | * real driver could be loaded */ | ||
236 | if (phydev->dev.driver == &genphy_driver.driver) { | ||
237 | down_write(&phydev->dev.bus->subsys.rwsem); | ||
238 | device_release_driver(&phydev->dev); | ||
239 | up_write(&phydev->dev.bus->subsys.rwsem); | ||
240 | } | ||
241 | } | ||
242 | EXPORT_SYMBOL(phy_detach); | ||
243 | |||
244 | |||
127 | /* Generic PHY support and helper functions */ | 245 | /* Generic PHY support and helper functions */ |
128 | 246 | ||
129 | /* genphy_config_advert | 247 | /* genphy_config_advert |
@@ -132,7 +250,7 @@ void phy_prepare_link(struct phy_device *phydev, | |||
132 | * after sanitizing the values to make sure we only advertise | 250 | * after sanitizing the values to make sure we only advertise |
133 | * what is supported | 251 | * what is supported |
134 | */ | 252 | */ |
135 | static int genphy_config_advert(struct phy_device *phydev) | 253 | int genphy_config_advert(struct phy_device *phydev) |
136 | { | 254 | { |
137 | u32 advertise; | 255 | u32 advertise; |
138 | int adv; | 256 | int adv; |
@@ -190,6 +308,7 @@ static int genphy_config_advert(struct phy_device *phydev) | |||
190 | 308 | ||
191 | return adv; | 309 | return adv; |
192 | } | 310 | } |
311 | EXPORT_SYMBOL(genphy_config_advert); | ||
193 | 312 | ||
194 | /* genphy_setup_forced | 313 | /* genphy_setup_forced |
195 | * | 314 | * |
@@ -541,32 +660,37 @@ void phy_driver_unregister(struct phy_driver *drv) | |||
541 | } | 660 | } |
542 | EXPORT_SYMBOL(phy_driver_unregister); | 661 | EXPORT_SYMBOL(phy_driver_unregister); |
543 | 662 | ||
663 | static struct phy_driver genphy_driver = { | ||
664 | .phy_id = 0xffffffff, | ||
665 | .phy_id_mask = 0xffffffff, | ||
666 | .name = "Generic PHY", | ||
667 | .config_init = genphy_config_init, | ||
668 | .features = 0, | ||
669 | .config_aneg = genphy_config_aneg, | ||
670 | .read_status = genphy_read_status, | ||
671 | .driver = {.owner= THIS_MODULE, }, | ||
672 | }; | ||
544 | 673 | ||
545 | static int __init phy_init(void) | 674 | static int __init phy_init(void) |
546 | { | 675 | { |
547 | int rc; | 676 | int rc; |
548 | extern int mdio_bus_init(void); | ||
549 | |||
550 | rc = phy_driver_register(&genphy_driver); | ||
551 | if (rc) | ||
552 | goto out; | ||
553 | 677 | ||
554 | rc = mdio_bus_init(); | 678 | rc = mdio_bus_init(); |
555 | if (rc) | 679 | if (rc) |
556 | goto out_unreg; | 680 | return rc; |
557 | 681 | ||
558 | return 0; | 682 | rc = phy_driver_register(&genphy_driver); |
683 | if (rc) | ||
684 | mdio_bus_exit(); | ||
559 | 685 | ||
560 | out_unreg: | ||
561 | phy_driver_unregister(&genphy_driver); | ||
562 | out: | ||
563 | return rc; | 686 | return rc; |
564 | } | 687 | } |
565 | 688 | ||
566 | static void __exit phy_exit(void) | 689 | static void __exit phy_exit(void) |
567 | { | 690 | { |
568 | phy_driver_unregister(&genphy_driver); | 691 | phy_driver_unregister(&genphy_driver); |
692 | mdio_bus_exit(); | ||
569 | } | 693 | } |
570 | 694 | ||
571 | module_init(phy_init); | 695 | subsys_initcall(phy_init); |
572 | module_exit(phy_exit); | 696 | module_exit(phy_exit); |
diff --git a/include/linux/phy.h b/include/linux/phy.h index 4f2b5effc16b..72cb67b66e0c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h | |||
@@ -334,11 +334,26 @@ int phy_write(struct phy_device *phydev, u16 regnum, u16 val); | |||
334 | struct phy_device* get_phy_device(struct mii_bus *bus, int addr); | 334 | struct phy_device* get_phy_device(struct mii_bus *bus, int addr); |
335 | int phy_clear_interrupt(struct phy_device *phydev); | 335 | int phy_clear_interrupt(struct phy_device *phydev); |
336 | int phy_config_interrupt(struct phy_device *phydev, u32 interrupts); | 336 | int phy_config_interrupt(struct phy_device *phydev, u32 interrupts); |
337 | struct phy_device * phy_attach(struct net_device *dev, | ||
338 | const char *phy_id, u32 flags); | ||
339 | struct phy_device * phy_connect(struct net_device *dev, const char *phy_id, | ||
340 | void (*handler)(struct net_device *), u32 flags); | ||
341 | void phy_disconnect(struct phy_device *phydev); | ||
342 | void phy_detach(struct phy_device *phydev); | ||
343 | void phy_start(struct phy_device *phydev); | ||
344 | void phy_stop(struct phy_device *phydev); | ||
345 | int phy_start_aneg(struct phy_device *phydev); | ||
346 | |||
347 | int mdiobus_register(struct mii_bus *bus); | ||
348 | void mdiobus_unregister(struct mii_bus *bus); | ||
349 | void phy_sanitize_settings(struct phy_device *phydev); | ||
350 | int phy_stop_interrupts(struct phy_device *phydev); | ||
337 | 351 | ||
338 | static inline int phy_read_status(struct phy_device *phydev) { | 352 | static inline int phy_read_status(struct phy_device *phydev) { |
339 | return phydev->drv->read_status(phydev); | 353 | return phydev->drv->read_status(phydev); |
340 | } | 354 | } |
341 | 355 | ||
356 | int genphy_config_advert(struct phy_device *phydev); | ||
342 | int genphy_setup_forced(struct phy_device *phydev); | 357 | int genphy_setup_forced(struct phy_device *phydev); |
343 | int genphy_restart_aneg(struct phy_device *phydev); | 358 | int genphy_restart_aneg(struct phy_device *phydev); |
344 | int genphy_config_aneg(struct phy_device *phydev); | 359 | int genphy_config_aneg(struct phy_device *phydev); |
@@ -355,6 +370,8 @@ int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd); | |||
355 | int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd); | 370 | int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd); |
356 | int phy_mii_ioctl(struct phy_device *phydev, | 371 | int phy_mii_ioctl(struct phy_device *phydev, |
357 | struct mii_ioctl_data *mii_data, int cmd); | 372 | struct mii_ioctl_data *mii_data, int cmd); |
373 | int phy_start_interrupts(struct phy_device *phydev); | ||
374 | void phy_print_status(struct phy_device *phydev); | ||
358 | 375 | ||
359 | extern struct bus_type mdio_bus_type; | 376 | extern struct bus_type mdio_bus_type; |
360 | #endif /* __PHY_H */ | 377 | #endif /* __PHY_H */ |