phy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. #include <config.h>
  26. #include <common.h>
  27. #include <malloc.h>
  28. #include <net.h>
  29. #include <command.h>
  30. #include <miiphy.h>
  31. #include <phy.h>
  32. #include <errno.h>
  33. /* Generic PHY support and helper functions */
  34. /**
  35. * genphy_config_advert - sanitize and advertise auto-negotation parameters
  36. * @phydev: target phy_device struct
  37. *
  38. * Description: Writes MII_ADVERTISE with the appropriate values,
  39. * after sanitizing the values to make sure we only advertise
  40. * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
  41. * hasn't changed, and > 0 if it has changed.
  42. */
  43. int genphy_config_advert(struct phy_device *phydev)
  44. {
  45. u32 advertise;
  46. int oldadv, adv;
  47. int err, changed = 0;
  48. /* Only allow advertising what
  49. * this PHY supports */
  50. phydev->advertising &= phydev->supported;
  51. advertise = phydev->advertising;
  52. /* Setup standard advertisement */
  53. oldadv = adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
  54. if (adv < 0)
  55. return adv;
  56. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP |
  57. ADVERTISE_PAUSE_ASYM);
  58. if (advertise & ADVERTISED_10baseT_Half)
  59. adv |= ADVERTISE_10HALF;
  60. if (advertise & ADVERTISED_10baseT_Full)
  61. adv |= ADVERTISE_10FULL;
  62. if (advertise & ADVERTISED_100baseT_Half)
  63. adv |= ADVERTISE_100HALF;
  64. if (advertise & ADVERTISED_100baseT_Full)
  65. adv |= ADVERTISE_100FULL;
  66. if (advertise & ADVERTISED_Pause)
  67. adv |= ADVERTISE_PAUSE_CAP;
  68. if (advertise & ADVERTISED_Asym_Pause)
  69. adv |= ADVERTISE_PAUSE_ASYM;
  70. if (adv != oldadv) {
  71. err = phy_write(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE, adv);
  72. if (err < 0)
  73. return err;
  74. changed = 1;
  75. }
  76. /* Configure gigabit if it's supported */
  77. if (phydev->supported & (SUPPORTED_1000baseT_Half |
  78. SUPPORTED_1000baseT_Full)) {
  79. oldadv = adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
  80. if (adv < 0)
  81. return adv;
  82. adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
  83. if (advertise & SUPPORTED_1000baseT_Half)
  84. adv |= ADVERTISE_1000HALF;
  85. if (advertise & SUPPORTED_1000baseT_Full)
  86. adv |= ADVERTISE_1000FULL;
  87. if (adv != oldadv) {
  88. err = phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000,
  89. adv);
  90. if (err < 0)
  91. return err;
  92. changed = 1;
  93. }
  94. }
  95. return changed;
  96. }
  97. /**
  98. * genphy_setup_forced - configures/forces speed/duplex from @phydev
  99. * @phydev: target phy_device struct
  100. *
  101. * Description: Configures MII_BMCR to force speed/duplex
  102. * to the values in phydev. Assumes that the values are valid.
  103. */
  104. int genphy_setup_forced(struct phy_device *phydev)
  105. {
  106. int err;
  107. int ctl = 0;
  108. phydev->pause = phydev->asym_pause = 0;
  109. if (SPEED_1000 == phydev->speed)
  110. ctl |= BMCR_SPEED1000;
  111. else if (SPEED_100 == phydev->speed)
  112. ctl |= BMCR_SPEED100;
  113. if (DUPLEX_FULL == phydev->duplex)
  114. ctl |= BMCR_FULLDPLX;
  115. err = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
  116. return err;
  117. }
  118. /**
  119. * genphy_restart_aneg - Enable and Restart Autonegotiation
  120. * @phydev: target phy_device struct
  121. */
  122. int genphy_restart_aneg(struct phy_device *phydev)
  123. {
  124. int ctl;
  125. ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
  126. if (ctl < 0)
  127. return ctl;
  128. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  129. /* Don't isolate the PHY if we're negotiating */
  130. ctl &= ~(BMCR_ISOLATE);
  131. ctl = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
  132. return ctl;
  133. }
  134. /**
  135. * genphy_config_aneg - restart auto-negotiation or write BMCR
  136. * @phydev: target phy_device struct
  137. *
  138. * Description: If auto-negotiation is enabled, we configure the
  139. * advertising, and then restart auto-negotiation. If it is not
  140. * enabled, then we write the BMCR.
  141. */
  142. int genphy_config_aneg(struct phy_device *phydev)
  143. {
  144. int result;
  145. if (AUTONEG_ENABLE != phydev->autoneg)
  146. return genphy_setup_forced(phydev);
  147. result = genphy_config_advert(phydev);
  148. if (result < 0) /* error */
  149. return result;
  150. if (result == 0) {
  151. /* Advertisment hasn't changed, but maybe aneg was never on to
  152. * begin with? Or maybe phy was isolated? */
  153. int ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
  154. if (ctl < 0)
  155. return ctl;
  156. if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
  157. result = 1; /* do restart aneg */
  158. }
  159. /* Only restart aneg if we are advertising something different
  160. * than we were before. */
  161. if (result > 0)
  162. result = genphy_restart_aneg(phydev);
  163. return result;
  164. }
  165. /**
  166. * genphy_update_link - update link status in @phydev
  167. * @phydev: target phy_device struct
  168. *
  169. * Description: Update the value in phydev->link to reflect the
  170. * current link value. In order to do this, we need to read
  171. * the status register twice, keeping the second value.
  172. */
  173. int genphy_update_link(struct phy_device *phydev)
  174. {
  175. unsigned int mii_reg;
  176. /*
  177. * Wait if the link is up, and autonegotiation is in progress
  178. * (ie - we're capable and it's not done)
  179. */
  180. mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  181. /*
  182. * If we already saw the link up, and it hasn't gone down, then
  183. * we don't need to wait for autoneg again
  184. */
  185. if (phydev->link && mii_reg & BMSR_LSTATUS)
  186. return 0;
  187. if ((mii_reg & BMSR_ANEGCAPABLE) && !(mii_reg & BMSR_ANEGCOMPLETE)) {
  188. int i = 0;
  189. printf("%s Waiting for PHY auto negotiation to complete",
  190. phydev->dev->name);
  191. while (!(mii_reg & BMSR_ANEGCOMPLETE)) {
  192. /*
  193. * Timeout reached ?
  194. */
  195. if (i > PHY_ANEG_TIMEOUT) {
  196. printf(" TIMEOUT !\n");
  197. phydev->link = 0;
  198. return 0;
  199. }
  200. if (ctrlc()) {
  201. puts("user interrupt!\n");
  202. phydev->link = 0;
  203. return -EINTR;
  204. }
  205. if ((i++ % 500) == 0)
  206. printf(".");
  207. udelay(1000); /* 1 ms */
  208. mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  209. }
  210. printf(" done\n");
  211. phydev->link = 1;
  212. } else {
  213. /* Read the link a second time to clear the latched state */
  214. mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  215. if (mii_reg & BMSR_LSTATUS)
  216. phydev->link = 1;
  217. else
  218. phydev->link = 0;
  219. }
  220. return 0;
  221. }
  222. /*
  223. * Generic function which updates the speed and duplex. If
  224. * autonegotiation is enabled, it uses the AND of the link
  225. * partner's advertised capabilities and our advertised
  226. * capabilities. If autonegotiation is disabled, we use the
  227. * appropriate bits in the control register.
  228. *
  229. * Stolen from Linux's mii.c and phy_device.c
  230. */
  231. static int genphy_parse_link(struct phy_device *phydev)
  232. {
  233. int mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  234. /* We're using autonegotiation */
  235. if (mii_reg & BMSR_ANEGCAPABLE) {
  236. u32 lpa = 0;
  237. u32 gblpa = 0;
  238. /* Check for gigabit capability */
  239. if (mii_reg & BMSR_ERCAP) {
  240. /* We want a list of states supported by
  241. * both PHYs in the link
  242. */
  243. gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000);
  244. gblpa &= phy_read(phydev,
  245. MDIO_DEVAD_NONE, MII_CTRL1000) << 2;
  246. }
  247. /* Set the baseline so we only have to set them
  248. * if they're different
  249. */
  250. phydev->speed = SPEED_10;
  251. phydev->duplex = DUPLEX_HALF;
  252. /* Check the gigabit fields */
  253. if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
  254. phydev->speed = SPEED_1000;
  255. if (gblpa & PHY_1000BTSR_1000FD)
  256. phydev->duplex = DUPLEX_FULL;
  257. /* We're done! */
  258. return 0;
  259. }
  260. lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
  261. lpa &= phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
  262. if (lpa & (LPA_100FULL | LPA_100HALF)) {
  263. phydev->speed = SPEED_100;
  264. if (lpa & LPA_100FULL)
  265. phydev->duplex = DUPLEX_FULL;
  266. } else if (lpa & LPA_10FULL)
  267. phydev->duplex = DUPLEX_FULL;
  268. } else {
  269. u32 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
  270. phydev->speed = SPEED_10;
  271. phydev->duplex = DUPLEX_HALF;
  272. if (bmcr & BMCR_FULLDPLX)
  273. phydev->duplex = DUPLEX_FULL;
  274. if (bmcr & BMCR_SPEED1000)
  275. phydev->speed = SPEED_1000;
  276. else if (bmcr & BMCR_SPEED100)
  277. phydev->speed = SPEED_100;
  278. }
  279. return 0;
  280. }
  281. int genphy_config(struct phy_device *phydev)
  282. {
  283. int val;
  284. u32 features;
  285. /* For now, I'll claim that the generic driver supports
  286. * all possible port types */
  287. features = (SUPPORTED_TP | SUPPORTED_MII
  288. | SUPPORTED_AUI | SUPPORTED_FIBRE |
  289. SUPPORTED_BNC);
  290. /* Do we support autonegotiation? */
  291. val = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  292. if (val < 0)
  293. return val;
  294. if (val & BMSR_ANEGCAPABLE)
  295. features |= SUPPORTED_Autoneg;
  296. if (val & BMSR_100FULL)
  297. features |= SUPPORTED_100baseT_Full;
  298. if (val & BMSR_100HALF)
  299. features |= SUPPORTED_100baseT_Half;
  300. if (val & BMSR_10FULL)
  301. features |= SUPPORTED_10baseT_Full;
  302. if (val & BMSR_10HALF)
  303. features |= SUPPORTED_10baseT_Half;
  304. if (val & BMSR_ESTATEN) {
  305. val = phy_read(phydev, MDIO_DEVAD_NONE, MII_ESTATUS);
  306. if (val < 0)
  307. return val;
  308. if (val & ESTATUS_1000_TFULL)
  309. features |= SUPPORTED_1000baseT_Full;
  310. if (val & ESTATUS_1000_THALF)
  311. features |= SUPPORTED_1000baseT_Half;
  312. }
  313. phydev->supported = features;
  314. phydev->advertising = features;
  315. genphy_config_aneg(phydev);
  316. return 0;
  317. }
  318. int genphy_startup(struct phy_device *phydev)
  319. {
  320. genphy_update_link(phydev);
  321. genphy_parse_link(phydev);
  322. return 0;
  323. }
  324. int genphy_shutdown(struct phy_device *phydev)
  325. {
  326. return 0;
  327. }
  328. static struct phy_driver genphy_driver = {
  329. .uid = 0xffffffff,
  330. .mask = 0xffffffff,
  331. .name = "Generic PHY",
  332. .features = 0,
  333. .config = genphy_config,
  334. .startup = genphy_startup,
  335. .shutdown = genphy_shutdown,
  336. };
  337. static LIST_HEAD(phy_drivers);
  338. int phy_init(void)
  339. {
  340. #ifdef CONFIG_PHY_ATHEROS
  341. phy_atheros_init();
  342. #endif
  343. #ifdef CONFIG_PHY_BROADCOM
  344. phy_broadcom_init();
  345. #endif
  346. #ifdef CONFIG_PHY_DAVICOM
  347. phy_davicom_init();
  348. #endif
  349. #ifdef CONFIG_PHY_LXT
  350. phy_lxt_init();
  351. #endif
  352. #ifdef CONFIG_PHY_MARVELL
  353. phy_marvell_init();
  354. #endif
  355. #ifdef CONFIG_PHY_MICREL
  356. phy_micrel_init();
  357. #endif
  358. #ifdef CONFIG_PHY_NATSEMI
  359. phy_natsemi_init();
  360. #endif
  361. #ifdef CONFIG_PHY_REALTEK
  362. phy_realtek_init();
  363. #endif
  364. #ifdef CONFIG_PHY_SMSC
  365. phy_smsc_init();
  366. #endif
  367. #ifdef CONFIG_PHY_TERANETICS
  368. phy_teranetics_init();
  369. #endif
  370. #ifdef CONFIG_PHY_VITESSE
  371. phy_vitesse_init();
  372. #endif
  373. return 0;
  374. }
  375. int phy_register(struct phy_driver *drv)
  376. {
  377. INIT_LIST_HEAD(&drv->list);
  378. list_add_tail(&drv->list, &phy_drivers);
  379. return 0;
  380. }
  381. int phy_probe(struct phy_device *phydev)
  382. {
  383. int err = 0;
  384. phydev->advertising = phydev->supported = phydev->drv->features;
  385. phydev->mmds = phydev->drv->mmds;
  386. if (phydev->drv->probe)
  387. err = phydev->drv->probe(phydev);
  388. return err;
  389. }
  390. static struct phy_driver *generic_for_interface(phy_interface_t interface)
  391. {
  392. #ifdef CONFIG_PHYLIB_10G
  393. if (is_10g_interface(interface))
  394. return &gen10g_driver;
  395. #endif
  396. return &genphy_driver;
  397. }
  398. struct phy_driver *get_phy_driver(struct phy_device *phydev,
  399. phy_interface_t interface)
  400. {
  401. struct list_head *entry;
  402. int phy_id = phydev->phy_id;
  403. struct phy_driver *drv = NULL;
  404. list_for_each(entry, &phy_drivers) {
  405. drv = list_entry(entry, struct phy_driver, list);
  406. if ((drv->uid & drv->mask) == (phy_id & drv->mask))
  407. return drv;
  408. }
  409. /* If we made it here, there's no driver for this PHY */
  410. return generic_for_interface(interface);
  411. }
  412. struct phy_device *phy_device_create(struct mii_dev *bus, int addr, int phy_id,
  413. phy_interface_t interface)
  414. {
  415. struct phy_device *dev;
  416. /* We allocate the device, and initialize the
  417. * default values */
  418. dev = malloc(sizeof(*dev));
  419. if (!dev) {
  420. printf("Failed to allocate PHY device for %s:%d\n",
  421. bus->name, addr);
  422. return NULL;
  423. }
  424. memset(dev, 0, sizeof(*dev));
  425. dev->duplex = -1;
  426. dev->link = 1;
  427. dev->interface = interface;
  428. dev->autoneg = AUTONEG_ENABLE;
  429. dev->addr = addr;
  430. dev->phy_id = phy_id;
  431. dev->bus = bus;
  432. dev->drv = get_phy_driver(dev, interface);
  433. phy_probe(dev);
  434. bus->phymap[addr] = dev;
  435. return dev;
  436. }
  437. /**
  438. * get_phy_id - reads the specified addr for its ID.
  439. * @bus: the target MII bus
  440. * @addr: PHY address on the MII bus
  441. * @phy_id: where to store the ID retrieved.
  442. *
  443. * Description: Reads the ID registers of the PHY at @addr on the
  444. * @bus, stores it in @phy_id and returns zero on success.
  445. */
  446. int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
  447. {
  448. int phy_reg;
  449. /* Grab the bits from PHYIR1, and put them
  450. * in the upper half */
  451. phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
  452. if (phy_reg < 0)
  453. return -EIO;
  454. *phy_id = (phy_reg & 0xffff) << 16;
  455. /* Grab the bits from PHYIR2, and put them in the lower half */
  456. phy_reg = bus->read(bus, addr, devad, MII_PHYSID2);
  457. if (phy_reg < 0)
  458. return -EIO;
  459. *phy_id |= (phy_reg & 0xffff);
  460. return 0;
  461. }
  462. /**
  463. * get_phy_device - reads the specified PHY device and returns its @phy_device struct
  464. * @bus: the target MII bus
  465. * @addr: PHY address on the MII bus
  466. *
  467. * Description: Reads the ID registers of the PHY at @addr on the
  468. * @bus, then allocates and returns the phy_device to represent it.
  469. */
  470. struct phy_device *get_phy_device(struct mii_dev *bus, int addr,
  471. phy_interface_t interface)
  472. {
  473. u32 phy_id = 0x1fffffff;
  474. int i;
  475. int r;
  476. /* If we have one, return the existing device, with new interface */
  477. if (bus->phymap[addr]) {
  478. bus->phymap[addr]->interface = interface;
  479. return bus->phymap[addr];
  480. }
  481. /* Try Standard (ie Clause 22) access */
  482. r = get_phy_id(bus, addr, MDIO_DEVAD_NONE, &phy_id);
  483. if (r)
  484. return NULL;
  485. /* If the PHY ID is mostly f's, we didn't find anything */
  486. if ((phy_id & 0x1fffffff) != 0x1fffffff)
  487. return phy_device_create(bus, addr, phy_id, interface);
  488. /* Otherwise we have to try Clause 45 */
  489. for (i = 1; i < 5; i++) {
  490. r = get_phy_id(bus, addr, i, &phy_id);
  491. if (r)
  492. return NULL;
  493. /* If the phy_id is mostly Fs, there is no device there */
  494. if ((phy_id & 0x1fffffff) != 0x1fffffff)
  495. break;
  496. }
  497. return phy_device_create(bus, addr, phy_id, interface);
  498. }
  499. int phy_reset(struct phy_device *phydev)
  500. {
  501. int reg;
  502. int timeout = 500;
  503. int devad = MDIO_DEVAD_NONE;
  504. #ifdef CONFIG_PHYLIB_10G
  505. /* If it's 10G, we need to issue reset through one of the MMDs */
  506. if (is_10g_interface(phydev->interface)) {
  507. if (!phydev->mmds)
  508. gen10g_discover_mmds(phydev);
  509. devad = ffs(phydev->mmds) - 1;
  510. }
  511. #endif
  512. reg = phy_read(phydev, devad, MII_BMCR);
  513. if (reg < 0) {
  514. debug("PHY status read failed\n");
  515. return -1;
  516. }
  517. reg |= BMCR_RESET;
  518. if (phy_write(phydev, devad, MII_BMCR, reg) < 0) {
  519. debug("PHY reset failed\n");
  520. return -1;
  521. }
  522. #ifdef CONFIG_PHY_RESET_DELAY
  523. udelay(CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */
  524. #endif
  525. /*
  526. * Poll the control register for the reset bit to go to 0 (it is
  527. * auto-clearing). This should happen within 0.5 seconds per the
  528. * IEEE spec.
  529. */
  530. while ((reg & BMCR_RESET) && timeout--) {
  531. reg = phy_read(phydev, devad, MII_BMCR);
  532. if (reg < 0) {
  533. debug("PHY status read failed\n");
  534. return -1;
  535. }
  536. udelay(1000);
  537. }
  538. if (reg & BMCR_RESET) {
  539. puts("PHY reset timed out\n");
  540. return -1;
  541. }
  542. return 0;
  543. }
  544. int miiphy_reset(const char *devname, unsigned char addr)
  545. {
  546. struct mii_dev *bus = miiphy_get_dev_by_name(devname);
  547. struct phy_device *phydev;
  548. /*
  549. * miiphy_reset was only used on standard PHYs, so we'll fake it here.
  550. * If later code tries to connect with the right interface, this will
  551. * be corrected by get_phy_device in phy_connect()
  552. */
  553. phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII);
  554. return phy_reset(phydev);
  555. }
  556. struct phy_device *phy_connect(struct mii_dev *bus, int addr,
  557. struct eth_device *dev,
  558. phy_interface_t interface)
  559. {
  560. struct phy_device *phydev;
  561. /* Reset the bus */
  562. if (bus->reset)
  563. bus->reset(bus);
  564. /* Wait 15ms to make sure the PHY has come out of hard reset */
  565. udelay(15000);
  566. phydev = get_phy_device(bus, addr, interface);
  567. if (!phydev) {
  568. printf("Could not get PHY for %s:%d\n", bus->name, addr);
  569. return NULL;
  570. }
  571. /* Soft Reset the PHY */
  572. phy_reset(phydev);
  573. if (phydev->dev)
  574. printf("%s:%d is connected to %s. Reconnecting to %s\n",
  575. bus->name, addr, phydev->dev->name, dev->name);
  576. phydev->dev = dev;
  577. debug("%s connected to %s\n", dev->name, phydev->drv->name);
  578. return phydev;
  579. }
  580. /*
  581. * Start the PHY. Returns 0 on success, or a negative error code.
  582. */
  583. int phy_startup(struct phy_device *phydev)
  584. {
  585. if (phydev->drv->startup)
  586. return phydev->drv->startup(phydev);
  587. return 0;
  588. }
  589. static int __board_phy_config(struct phy_device *phydev)
  590. {
  591. if (phydev->drv->config)
  592. return phydev->drv->config(phydev);
  593. return 0;
  594. }
  595. int board_phy_config(struct phy_device *phydev)
  596. __attribute__((weak, alias("__board_phy_config")));
  597. int phy_config(struct phy_device *phydev)
  598. {
  599. /* Invoke an optional board-specific helper */
  600. board_phy_config(phydev);
  601. return 0;
  602. }
  603. int phy_shutdown(struct phy_device *phydev)
  604. {
  605. if (phydev->drv->shutdown)
  606. phydev->drv->shutdown(phydev);
  607. return 0;
  608. }