]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - drivers/net/phy/phy.c
net: phy: don't try autonegotiation if it is not enabled in the PHY
[karo-tx-uboot.git] / drivers / net / phy / phy.c
1 /*
2  * Generic PHY Management code
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17  * MA 02111-1307 USA
18  *
19  *
20  * Copyright 2011 Freescale Semiconductor, Inc.
21  * author Andy Fleming
22  *
23  * Based loosely off of Linux's PHY Lib
24  */
25
26 #include <config.h>
27 #include <common.h>
28 #include <malloc.h>
29 #include <net.h>
30 #include <command.h>
31 #include <miiphy.h>
32 #include <phy.h>
33 #include <errno.h>
34
35 /* Generic PHY support and helper functions */
36
37 /**
38  * genphy_config_advert - sanitize and advertise auto-negotation parameters
39  * @phydev: target phy_device struct
40  *
41  * Description: Writes MII_ADVERTISE with the appropriate values,
42  *   after sanitizing the values to make sure we only advertise
43  *   what is supported.  Returns < 0 on error, 0 if the PHY's advertisement
44  *   hasn't changed, and > 0 if it has changed.
45  */
46 static int genphy_config_advert(struct phy_device *phydev)
47 {
48         u32 advertise;
49         int oldadv, adv;
50         int err, changed = 0;
51
52         /* Only allow advertising what
53          * this PHY supports */
54         phydev->advertising &= phydev->supported;
55         advertise = phydev->advertising;
56
57         /* Setup standard advertisement */
58         oldadv = adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
59
60         if (adv < 0)
61                 return adv;
62
63         adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP |
64                  ADVERTISE_PAUSE_ASYM);
65         if (advertise & ADVERTISED_10baseT_Half)
66                 adv |= ADVERTISE_10HALF;
67         if (advertise & ADVERTISED_10baseT_Full)
68                 adv |= ADVERTISE_10FULL;
69         if (advertise & ADVERTISED_100baseT_Half)
70                 adv |= ADVERTISE_100HALF;
71         if (advertise & ADVERTISED_100baseT_Full)
72                 adv |= ADVERTISE_100FULL;
73         if (advertise & ADVERTISED_Pause)
74                 adv |= ADVERTISE_PAUSE_CAP;
75         if (advertise & ADVERTISED_Asym_Pause)
76                 adv |= ADVERTISE_PAUSE_ASYM;
77
78         if (adv != oldadv) {
79                 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE, adv);
80
81                 if (err < 0)
82                         return err;
83                 changed = 1;
84         }
85
86         /* Configure gigabit if it's supported */
87         if (phydev->supported & (SUPPORTED_1000baseT_Half |
88                                 SUPPORTED_1000baseT_Full)) {
89                 oldadv = adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
90
91                 if (adv < 0)
92                         return adv;
93
94                 adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
95                 if (advertise & SUPPORTED_1000baseT_Half)
96                         adv |= ADVERTISE_1000HALF;
97                 if (advertise & SUPPORTED_1000baseT_Full)
98                         adv |= ADVERTISE_1000FULL;
99
100                 if (adv != oldadv) {
101                         err = phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000,
102                                         adv);
103
104                         if (err < 0)
105                                 return err;
106                         changed = 1;
107                 }
108         }
109
110         return changed;
111 }
112
113
114 /**
115  * genphy_setup_forced - configures/forces speed/duplex from @phydev
116  * @phydev: target phy_device struct
117  *
118  * Description: Configures MII_BMCR to force speed/duplex
119  *   to the values in phydev. Assumes that the values are valid.
120  */
121 static int genphy_setup_forced(struct phy_device *phydev)
122 {
123         int ctl = 0;
124
125         phydev->pause = phydev->asym_pause = 0;
126
127         if (SPEED_1000 == phydev->speed)
128                 ctl |= BMCR_SPEED1000;
129         else if (SPEED_100 == phydev->speed)
130                 ctl |= BMCR_SPEED100;
131
132         if (DUPLEX_FULL == phydev->duplex)
133                 ctl |= BMCR_FULLDPLX;
134
135         return phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
136 }
137
138
139 /**
140  * genphy_restart_aneg - Enable and Restart Autonegotiation
141  * @phydev: target phy_device struct
142  */
143 int genphy_restart_aneg(struct phy_device *phydev)
144 {
145         int ctl;
146
147         ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
148
149         if (ctl < 0)
150                 return ctl;
151
152         ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
153
154         /* Don't isolate the PHY if we're negotiating */
155         ctl &= ~(BMCR_ISOLATE);
156
157         return phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
158 }
159
160
161 /**
162  * genphy_config_aneg - restart auto-negotiation or write BMCR
163  * @phydev: target phy_device struct
164  *
165  * Description: If auto-negotiation is enabled, we configure the
166  *   advertising, and then restart auto-negotiation.  If it is not
167  *   enabled, then we write the BMCR.
168  */
169 int genphy_config_aneg(struct phy_device *phydev)
170 {
171         int result;
172
173         if (AUTONEG_ENABLE != phydev->autoneg)
174                 return genphy_setup_forced(phydev);
175
176         result = genphy_config_advert(phydev);
177
178         if (result < 0) /* error */
179                 return result;
180
181         if (result == 0) {
182                 /* Advertisment hasn't changed, but maybe aneg was never on to
183                  * begin with?  Or maybe phy was isolated? */
184                 int ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
185
186                 if (ctl < 0)
187                         return ctl;
188
189                 if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
190                         result = 1; /* do restart aneg */
191         }
192
193         /* Only restart aneg if we are advertising something different
194          * than we were before.  */
195         if (result > 0)
196                 result = genphy_restart_aneg(phydev);
197
198         return result;
199 }
200
201 /**
202  * genphy_update_link - update link status in @phydev
203  * @phydev: target phy_device struct
204  *
205  * Description: Update the value in phydev->link to reflect the
206  *   current link value.  In order to do this, we need to read
207  *   the status register twice, keeping the second value.
208  */
209 int genphy_update_link(struct phy_device *phydev)
210 {
211         int mii_reg;
212         int bmcr;
213
214         /*
215          * Wait if the link is up, and autonegotiation is in progress
216          * (ie - we're capable and it's not done)
217          */
218         mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
219         if (mii_reg < 0)
220                 return mii_reg;
221
222         /*
223          * If we already saw the link up, and it hasn't gone down, then
224          * we don't need to wait for autoneg again
225          */
226         if (phydev->link && mii_reg & BMSR_LSTATUS)
227                 return 0;
228
229         bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
230         if (bmcr < 0)
231                 return bmcr;
232
233         if (!(bmcr & BMCR_ANENABLE))
234                 return 0;
235
236         if ((mii_reg & BMSR_ANEGCAPABLE) && !(mii_reg & BMSR_ANEGCOMPLETE)) {
237                 int i = 0;
238
239                 printf("%s Waiting for PHY auto negotiation to complete",
240                         phydev->dev->name);
241                 while (!(mii_reg & BMSR_ANEGCOMPLETE)) {
242                         /*
243                          * Timeout reached ?
244                          */
245                         if (i > PHY_ANEG_TIMEOUT) {
246                                 printf(" TIMEOUT !\n");
247                                 phydev->link = 0;
248                                 return 0;
249                         }
250
251                         if (ctrlc()) {
252                                 puts("user interrupt!\n");
253                                 phydev->link = 0;
254                                 return -EINTR;
255                         }
256
257                         if ((i++ % 500) == 0)
258                                 printf(".");
259
260                         udelay(1000);   /* 1 ms */
261                         mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
262                         if (mii_reg < 0)
263                                 return mii_reg;
264                 }
265                 printf(" done\n");
266                 phydev->link = 1;
267         } else {
268                 /* Read the link a second time to clear the latched state */
269                 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
270                 if (mii_reg < 0)
271                         return mii_reg;
272
273                 if (mii_reg & BMSR_LSTATUS)
274                         phydev->link = 1;
275                 else
276                         phydev->link = 0;
277         }
278
279         return 0;
280 }
281
282 /*
283  * Generic function which updates the speed and duplex.  If
284  * autonegotiation is enabled, it uses the AND of the link
285  * partner's advertised capabilities and our advertised
286  * capabilities.  If autonegotiation is disabled, we use the
287  * appropriate bits in the control register.
288  *
289  * Stolen from Linux's mii.c and phy_device.c
290  */
291 static int genphy_parse_link(struct phy_device *phydev)
292 {
293         int mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
294
295         if (mii_reg < 0)
296                 return mii_reg;
297
298         /* We're using autonegotiation */
299         if (mii_reg & BMSR_ANEGCAPABLE) {
300                 int ret;
301                 u16 lpa;
302                 u16 gblpa = 0;
303
304                 /* Check for gigabit capability */
305                 if (mii_reg & BMSR_ERCAP) {
306                         /* We want a list of states supported by
307                          * both PHYs in the link
308                          */
309                         ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000);
310                         if (ret < 0)
311                                 return ret;
312                         gblpa = ret;
313
314                         ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
315                         if (ret < 0)
316                                 return ret;
317                         gblpa &= ret << 2;
318                 }
319
320                 /* Set the baseline so we only have to set them
321                  * if they're different
322                  */
323                 phydev->speed = SPEED_10;
324                 phydev->duplex = DUPLEX_HALF;
325
326                 /* Check the gigabit fields */
327                 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
328                         phydev->speed = SPEED_1000;
329
330                         if (gblpa & PHY_1000BTSR_1000FD)
331                                 phydev->duplex = DUPLEX_FULL;
332
333                         /* We're done! */
334                         return 0;
335                 }
336
337                 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
338                 if (ret < 0)
339                         return ret;
340                 lpa = ret;
341
342                 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
343                 if (ret < 0)
344                         return ret;
345                 lpa &= ret;
346
347                 if (lpa & (LPA_100FULL | LPA_100HALF)) {
348                         phydev->speed = SPEED_100;
349
350                         if (lpa & LPA_100FULL)
351                                 phydev->duplex = DUPLEX_FULL;
352
353                 } else if (lpa & LPA_10FULL)
354                         phydev->duplex = DUPLEX_FULL;
355         } else {
356                 int bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
357
358                 if (bmcr < 0)
359                         return bmcr;
360
361                 phydev->speed = SPEED_10;
362                 phydev->duplex = DUPLEX_HALF;
363
364                 if (bmcr & BMCR_FULLDPLX)
365                         phydev->duplex = DUPLEX_FULL;
366
367                 if (bmcr & BMCR_SPEED1000)
368                         phydev->speed = SPEED_1000;
369                 else if (bmcr & BMCR_SPEED100)
370                         phydev->speed = SPEED_100;
371         }
372
373         return 0;
374 }
375
376 int genphy_config(struct phy_device *phydev)
377 {
378         int val;
379         u32 features;
380
381         /* For now, I'll claim that the generic driver supports
382          * all possible port types */
383         features = (SUPPORTED_TP | SUPPORTED_MII
384                         | SUPPORTED_AUI | SUPPORTED_FIBRE |
385                         SUPPORTED_BNC);
386
387         /* Do we support autonegotiation? */
388         val = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
389
390         if (val < 0)
391                 return val;
392
393         if (val & BMSR_ANEGCAPABLE)
394                 features |= SUPPORTED_Autoneg;
395
396         if (val & BMSR_100FULL)
397                 features |= SUPPORTED_100baseT_Full;
398         if (val & BMSR_100HALF)
399                 features |= SUPPORTED_100baseT_Half;
400         if (val & BMSR_10FULL)
401                 features |= SUPPORTED_10baseT_Full;
402         if (val & BMSR_10HALF)
403                 features |= SUPPORTED_10baseT_Half;
404
405         if (val & BMSR_ESTATEN) {
406                 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_ESTATUS);
407
408                 if (val < 0)
409                         return val;
410
411                 if (val & ESTATUS_1000_TFULL)
412                         features |= SUPPORTED_1000baseT_Full;
413                 if (val & ESTATUS_1000_THALF)
414                         features |= SUPPORTED_1000baseT_Half;
415         }
416
417         phydev->supported = features;
418         phydev->advertising = features;
419
420         genphy_config_aneg(phydev);
421
422         return 0;
423 }
424
425 int genphy_startup(struct phy_device *phydev)
426 {
427         genphy_update_link(phydev);
428         genphy_parse_link(phydev);
429
430         return 0;
431 }
432
433 int genphy_shutdown(struct phy_device *phydev)
434 {
435         return 0;
436 }
437
438 static struct phy_driver genphy_driver = {
439         .uid            = 0xffffffff,
440         .mask           = 0xffffffff,
441         .name           = "Generic PHY",
442         .features       = 0,
443         .config         = genphy_config,
444         .startup        = genphy_startup,
445         .shutdown       = genphy_shutdown,
446 };
447
448 static LIST_HEAD(phy_drivers);
449
450 int phy_init(void)
451 {
452 #ifdef CONFIG_PHY_ATHEROS
453         phy_atheros_init();
454 #endif
455 #ifdef CONFIG_PHY_BROADCOM
456         phy_broadcom_init();
457 #endif
458 #ifdef CONFIG_PHY_DAVICOM
459         phy_davicom_init();
460 #endif
461 #ifdef CONFIG_PHY_LXT
462         phy_lxt_init();
463 #endif
464 #ifdef CONFIG_PHY_MARVELL
465         phy_marvell_init();
466 #endif
467 #ifdef CONFIG_PHY_MICREL
468         phy_micrel_init();
469 #endif
470 #ifdef CONFIG_PHY_NATSEMI
471         phy_natsemi_init();
472 #endif
473 #ifdef CONFIG_PHY_REALTEK
474         phy_realtek_init();
475 #endif
476 #ifdef CONFIG_PHY_SMSC
477         phy_smsc_init();
478 #endif
479 #ifdef CONFIG_PHY_TERANETICS
480         phy_teranetics_init();
481 #endif
482 #ifdef CONFIG_PHY_VITESSE
483         phy_vitesse_init();
484 #endif
485
486         return 0;
487 }
488
489 int phy_register(struct phy_driver *drv)
490 {
491         INIT_LIST_HEAD(&drv->list);
492         list_add_tail(&drv->list, &phy_drivers);
493
494         return 0;
495 }
496
497 static int phy_probe(struct phy_device *phydev)
498 {
499         int err = 0;
500
501         phydev->advertising = phydev->supported = phydev->drv->features;
502         phydev->mmds = phydev->drv->mmds;
503
504         if (phydev->drv->probe)
505                 err = phydev->drv->probe(phydev);
506
507         return err;
508 }
509
510 static struct phy_driver *generic_for_interface(phy_interface_t interface)
511 {
512 #ifdef CONFIG_PHYLIB_10G
513         if (is_10g_interface(interface))
514                 return &gen10g_driver;
515 #endif
516
517         return &genphy_driver;
518 }
519
520 static struct phy_driver *get_phy_driver(struct phy_device *phydev,
521                                 phy_interface_t interface)
522 {
523         struct list_head *entry;
524         int phy_id = phydev->phy_id;
525         struct phy_driver *drv = NULL;
526
527         list_for_each(entry, &phy_drivers) {
528                 drv = list_entry(entry, struct phy_driver, list);
529                 if ((drv->uid & drv->mask) == (phy_id & drv->mask))
530                         return drv;
531         }
532
533         /* If we made it here, there's no driver for this PHY */
534         return generic_for_interface(interface);
535 }
536
537 static struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
538                                             int phy_id,
539                                             phy_interface_t interface)
540 {
541         struct phy_device *dev;
542
543         /* We allocate the device, and initialize the
544          * default values */
545         dev = malloc(sizeof(*dev));
546         if (!dev) {
547                 printf("Failed to allocate PHY device for %s:%d\n",
548                         bus->name, addr);
549                 return NULL;
550         }
551
552         memset(dev, 0, sizeof(*dev));
553
554         dev->duplex = -1;
555         dev->link = 1;
556         dev->interface = interface;
557
558         dev->autoneg = AUTONEG_ENABLE;
559
560         dev->addr = addr;
561         dev->phy_id = phy_id;
562         dev->bus = bus;
563
564         dev->drv = get_phy_driver(dev, interface);
565
566         phy_probe(dev);
567
568         bus->phymap[addr] = dev;
569
570         return dev;
571 }
572
573 /**
574  * get_phy_id - reads the specified addr for its ID.
575  * @bus: the target MII bus
576  * @addr: PHY address on the MII bus
577  * @phy_id: where to store the ID retrieved.
578  *
579  * Description: Reads the ID registers of the PHY at @addr on the
580  *   @bus, stores it in @phy_id and returns zero on success.
581  */
582 static int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
583 {
584         int phy_reg;
585
586         /* Grab the bits from PHYIR1, and put them
587          * in the upper half */
588         phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
589
590         if (phy_reg < 0)
591                 return -EIO;
592
593         *phy_id = (phy_reg & 0xffff) << 16;
594
595         /* Grab the bits from PHYIR2, and put them in the lower half */
596         phy_reg = bus->read(bus, addr, devad, MII_PHYSID2);
597
598         if (phy_reg < 0)
599                 return -EIO;
600
601         *phy_id |= (phy_reg & 0xffff);
602
603         return 0;
604 }
605
606 /**
607  * get_phy_device - reads the specified PHY device and returns its @phy_device struct
608  * @bus: the target MII bus
609  * @addr: PHY address on the MII bus
610  *
611  * Description: Reads the ID registers of the PHY at @addr on the
612  *   @bus, then allocates and returns the phy_device to represent it.
613  */
614 static struct phy_device *get_phy_device(struct mii_dev *bus, int addr,
615                                          phy_interface_t interface)
616 {
617         u32 phy_id = 0x1fffffff;
618         int i;
619         int r;
620
621         /* If we have one, return the existing device, with new interface */
622         if (bus->phymap[addr]) {
623                 bus->phymap[addr]->interface = interface;
624
625                 return bus->phymap[addr];
626         }
627
628         /* Try Standard (ie Clause 22) access */
629         r = get_phy_id(bus, addr, MDIO_DEVAD_NONE, &phy_id);
630         if (r)
631                 return NULL;
632
633         /* If the PHY ID is mostly f's, we didn't find anything */
634         if ((phy_id & 0x1fffffff) != 0x1fffffff)
635                 return phy_device_create(bus, addr, phy_id, interface);
636
637         /* Otherwise we have to try Clause 45 */
638         for (i = 1; i < 5; i++) {
639                 r = get_phy_id(bus, addr, i, &phy_id);
640                 if (r)
641                         return NULL;
642
643                 /* If the phy_id is mostly Fs, there is no device there */
644                 if ((phy_id & 0x1fffffff) != 0x1fffffff)
645                         return phy_device_create(bus, addr, phy_id, interface);
646         }
647         return NULL;
648 }
649
650 int phy_reset(struct phy_device *phydev)
651 {
652         int err;
653         int reg;
654         int timeout = 500;
655         int devad = MDIO_DEVAD_NONE;
656
657 #ifdef CONFIG_PHYLIB_10G
658         /* If it's 10G, we need to issue reset through one of the MMDs */
659         if (is_10g_interface(phydev->interface)) {
660                 if (!phydev->mmds)
661                         gen10g_discover_mmds(phydev);
662
663                 devad = ffs(phydev->mmds) - 1;
664         }
665 #endif
666
667         reg = phy_read(phydev, devad, MII_BMCR);
668         if (reg < 0) {
669                 debug("PHY status read failed\n");
670                 return -1;
671         }
672
673         reg |= BMCR_RESET;
674
675         err = phy_write(phydev, devad, MII_BMCR, reg);
676         if (err < 0) {
677                 debug("PHY reset failed\n");
678                 return err;
679         }
680
681 #ifdef CONFIG_PHY_RESET_DELAY
682         udelay(CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */
683 #endif
684         /*
685          * Poll the control register for the reset bit to go to 0 (it is
686          * auto-clearing).  This should happen within 0.5 seconds per the
687          * IEEE spec.
688          */
689         while ((reg & BMCR_RESET) && timeout-- >= 0) {
690                 reg = phy_read(phydev, devad, MII_BMCR);
691
692                 if (reg < 0) {
693                         debug("PHY status read failed\n");
694                         return reg;
695                 }
696                 udelay(1000);
697         }
698
699         if (reg & BMCR_RESET) {
700                 puts("PHY reset timed out\n");
701                 return -ETIMEDOUT;
702         }
703
704         return 0;
705 }
706
707 int miiphy_reset(const char *devname, unsigned char addr)
708 {
709         struct mii_dev *bus = miiphy_get_dev_by_name(devname);
710         struct phy_device *phydev;
711
712         /*
713          * miiphy_reset was only used on standard PHYs, so we'll fake it here.
714          * If later code tries to connect with the right interface, this will
715          * be corrected by get_phy_device in phy_connect()
716          */
717         phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII);
718
719         return phy_reset(phydev);
720 }
721
722 struct phy_device *phy_connect(struct mii_dev *bus, int addr,
723                                 struct eth_device *dev,
724                                 phy_interface_t interface)
725 {
726         struct phy_device *phydev;
727
728         /* Reset the bus */
729         if (bus->reset)
730                 bus->reset(bus);
731
732         /* Wait 15ms to make sure the PHY has come out of hard reset */
733         udelay(15000);
734
735         phydev = get_phy_device(bus, addr, interface);
736
737         if (!phydev) {
738                 printf("Could not get PHY for %s:%d\n", bus->name, addr);
739
740                 return NULL;
741         }
742
743         /* Soft Reset the PHY */
744         phy_reset(phydev);
745
746         if (phydev->dev)
747                 printf("%s:%d is connected to %s.  Reconnecting to %s\n",
748                         bus->name, addr, phydev->dev->name, dev->name);
749
750         phydev->dev = dev;
751
752         debug("%s connected to %s\n", dev->name, phydev->drv->name);
753
754         return phydev;
755 }
756
757 /*
758  * Start the PHY.  Returns 0 on success, or a negative error code.
759  */
760 int phy_startup(struct phy_device *phydev)
761 {
762         if (phydev->drv->startup)
763                 return phydev->drv->startup(phydev);
764
765         return 0;
766 }
767
768 static int __board_phy_config(struct phy_device *phydev)
769 {
770         if (phydev->drv->config)
771                 return phydev->drv->config(phydev);
772         return 0;
773 }
774
775 int board_phy_config(struct phy_device *phydev)
776         __attribute__((weak, alias("__board_phy_config")));
777
778 int phy_config(struct phy_device *phydev)
779 {
780         /* Invoke an optional board-specific helper */
781         board_phy_config(phydev);
782
783         return 0;
784 }
785
786 int phy_shutdown(struct phy_device *phydev)
787 {
788         if (phydev->drv->shutdown)
789                 phydev->drv->shutdown(phydev);
790
791         return 0;
792 }