aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/phy
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/phy')
-rw-r--r--drivers/net/phy/Kconfig8
-rw-r--r--drivers/net/phy/Makefile11
-rw-r--r--drivers/net/phy/mdio_bus.c79
-rw-r--r--drivers/net/phy/phy.c325
-rw-r--r--drivers/net/phy/phy_device.c172
5 files changed, 493 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
15config 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
15comment "MII PHY device drivers" 23comment "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
3libphy-objs := phy.o phy_device.o mdio_bus.o 3libphy-objs := phy.o phy_device.o mdio_bus.o
4 4
5obj-$(CONFIG_MARVELL_PHY) += libphy.o marvell.o 5obj-$(CONFIG_PHYLIB) += libphy.o
6obj-$(CONFIG_DAVICOM_PHY) += libphy.o davicom.o 6obj-$(CONFIG_MARVELL_PHY) += marvell.o
7obj-$(CONFIG_CICADA_PHY) += libphy.o cicada.o 7obj-$(CONFIG_DAVICOM_PHY) += davicom.o
8obj-$(CONFIG_LXT_PHY) += libphy.o lxt.o 8obj-$(CONFIG_CICADA_PHY) += cicada.o
9obj-$(CONFIG_QSEMI_PHY) += libphy.o qsemi.o 9obj-$(CONFIG_LXT_PHY) += lxt.o
10obj-$(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 */
46int 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}
100EXPORT_SYMBOL(mdiobus_register);
101
102void 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}
113EXPORT_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 173void __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
42static void phy_timer(unsigned long data); 42/* Convenience function to print out the current phy status
43static int phy_disable_interrupts(struct phy_device *phydev); 43 */
44static void phy_sanitize_settings(struct phy_device *phydev); 44void phy_print_status(struct phy_device *phydev)
45static 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}
55EXPORT_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 */
124static 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
148out_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 */
155struct phy_setting { 129struct 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 */
244static void phy_sanitize_settings(struct phy_device *phydev) 218void 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 233EXPORT_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 */
267static 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 */
295int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) 250int 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 */
372int 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
397out_unlock:
398#endif
399 spin_unlock(&phydev->lock);
400 return err;
401}
402EXPORT_SYMBOL(phy_start_aneg);
403
404
405#ifdef CONFIG_PHYCONTROL
406static void phy_change(void *data);
407static 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 */
458static 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
465static 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 */
496static 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 */
512int 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}
525EXPORT_SYMBOL(phy_enable_interrupts);
478 526
479/* Disable the PHY interrupts from the PHY side */ 527/* Disable the PHY interrupts from the PHY side */
480static int phy_disable_interrupts(struct phy_device *phydev) 528int 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}
551EXPORT_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 */
561int 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}
582EXPORT_SYMBOL(phy_start_interrupts);
583
584int 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}
597EXPORT_SYMBOL(phy_stop_interrupts);
598
599
600/* Scheduled by the phy_interrupt/timer to handle PHY changes */
601static 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
626irq_enable_err:
627 disable_irq(phydev->irq);
628phy_err:
629 phy_error(phydev);
630}
631
632/* Bring down the PHY link, and stop checking the status. */
633void 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
650out_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 */
663void 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}
681EXPORT_SYMBOL(phy_stop);
682EXPORT_SYMBOL(phy_start);
503 683
504/* PHY timer which handles the state machine */ 684/* PHY timer which handles the state machine */
505static void phy_timer(unsigned long data) 685static 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
42static int genphy_config_init(struct phy_device *phydev); 42static struct phy_driver genphy_driver;
43 43extern int mdio_bus_init(void);
44static struct phy_driver genphy_driver = { 44extern 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 */
129struct 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}
148EXPORT_SYMBOL(phy_connect);
149
150void 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}
161EXPORT_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 */
175static int phy_compare_id(struct device *dev, void *data)
176{
177 return strcmp((char *)data, dev->bus_id) ? 0 : 1;
178}
179
180struct 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}
226EXPORT_SYMBOL(phy_attach);
227
228void 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}
242EXPORT_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 */
135static int genphy_config_advert(struct phy_device *phydev) 253int 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}
311EXPORT_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}
542EXPORT_SYMBOL(phy_driver_unregister); 661EXPORT_SYMBOL(phy_driver_unregister);
543 662
663static 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
545static int __init phy_init(void) 674static 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
560out_unreg:
561 phy_driver_unregister(&genphy_driver);
562out:
563 return rc; 686 return rc;
564} 687}
565 688
566static void __exit phy_exit(void) 689static 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
571module_init(phy_init); 695subsys_initcall(phy_init);
572module_exit(phy_exit); 696module_exit(phy_exit);