phy_device.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * drivers/net/phy/phy_device.c
  3. *
  4. * Framework for finding and configuring PHYs.
  5. * Also contains generic PHY driver
  6. *
  7. * Author: Andy Fleming
  8. *
  9. * Copyright (c) 2004 Freescale Semiconductor, Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/string.h>
  19. #include <linux/errno.h>
  20. #include <linux/unistd.h>
  21. #include <linux/slab.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/mm.h>
  30. #include <linux/module.h>
  31. #include <linux/mii.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/phy.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/uaccess.h>
  37. MODULE_DESCRIPTION("PHY library");
  38. MODULE_AUTHOR("Andy Fleming");
  39. MODULE_LICENSE("GPL");
  40. static struct phy_driver genphy_driver;
  41. extern int mdio_bus_init(void);
  42. extern void mdio_bus_exit(void);
  43. struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
  44. {
  45. struct phy_device *dev;
  46. /* We allocate the device, and initialize the
  47. * default values */
  48. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  49. if (NULL == dev)
  50. return (struct phy_device*) PTR_ERR((void*)-ENOMEM);
  51. dev->speed = 0;
  52. dev->duplex = -1;
  53. dev->pause = dev->asym_pause = 0;
  54. dev->link = 1;
  55. dev->interface = PHY_INTERFACE_MODE_GMII;
  56. dev->autoneg = AUTONEG_ENABLE;
  57. dev->addr = addr;
  58. dev->phy_id = phy_id;
  59. dev->bus = bus;
  60. dev->state = PHY_DOWN;
  61. spin_lock_init(&dev->lock);
  62. return dev;
  63. }
  64. EXPORT_SYMBOL(phy_device_create);
  65. /**
  66. * get_phy_device - reads the specified PHY device and returns its @phy_device struct
  67. * @bus: the target MII bus
  68. * @addr: PHY address on the MII bus
  69. *
  70. * Description: Reads the ID registers of the PHY at @addr on the
  71. * @bus, then allocates and returns the phy_device to represent it.
  72. */
  73. struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
  74. {
  75. int phy_reg;
  76. u32 phy_id;
  77. struct phy_device *dev = NULL;
  78. /* Grab the bits from PHYIR1, and put them
  79. * in the upper half */
  80. phy_reg = bus->read(bus, addr, MII_PHYSID1);
  81. if (phy_reg < 0)
  82. return ERR_PTR(phy_reg);
  83. phy_id = (phy_reg & 0xffff) << 16;
  84. /* Grab the bits from PHYIR2, and put them in the lower half */
  85. phy_reg = bus->read(bus, addr, MII_PHYSID2);
  86. if (phy_reg < 0)
  87. return ERR_PTR(phy_reg);
  88. phy_id |= (phy_reg & 0xffff);
  89. /* If the phy_id is all Fs, there is no device there */
  90. if (0xffffffff == phy_id)
  91. return NULL;
  92. dev = phy_device_create(bus, addr, phy_id);
  93. return dev;
  94. }
  95. /**
  96. * phy_prepare_link - prepares the PHY layer to monitor link status
  97. * @phydev: target phy_device struct
  98. * @handler: callback function for link status change notifications
  99. *
  100. * Description: Tells the PHY infrastructure to handle the
  101. * gory details on monitoring link status (whether through
  102. * polling or an interrupt), and to call back to the
  103. * connected device driver when the link status changes.
  104. * If you want to monitor your own link state, don't call
  105. * this function.
  106. */
  107. void phy_prepare_link(struct phy_device *phydev,
  108. void (*handler)(struct net_device *))
  109. {
  110. phydev->adjust_link = handler;
  111. }
  112. /**
  113. * phy_connect - connect an ethernet device to a PHY device
  114. * @dev: the network device to connect
  115. * @phy_id: the PHY device to connect
  116. * @handler: callback function for state change notifications
  117. * @flags: PHY device's dev_flags
  118. * @interface: PHY device's interface
  119. *
  120. * Description: Convenience function for connecting ethernet
  121. * devices to PHY devices. The default behavior is for
  122. * the PHY infrastructure to handle everything, and only notify
  123. * the connected driver when the link status changes. If you
  124. * don't want, or can't use the provided functionality, you may
  125. * choose to call only the subset of functions which provide
  126. * the desired functionality.
  127. */
  128. struct phy_device * phy_connect(struct net_device *dev, const char *phy_id,
  129. void (*handler)(struct net_device *), u32 flags,
  130. phy_interface_t interface)
  131. {
  132. struct phy_device *phydev;
  133. phydev = phy_attach(dev, phy_id, flags, interface);
  134. if (IS_ERR(phydev))
  135. return phydev;
  136. phy_prepare_link(phydev, handler);
  137. phy_start_machine(phydev, NULL);
  138. if (phydev->irq > 0)
  139. phy_start_interrupts(phydev);
  140. return phydev;
  141. }
  142. EXPORT_SYMBOL(phy_connect);
  143. /**
  144. * phy_disconnect - disable interrupts, stop state machine, and detach a PHY device
  145. * @phydev: target phy_device struct
  146. */
  147. void phy_disconnect(struct phy_device *phydev)
  148. {
  149. if (phydev->irq > 0)
  150. phy_stop_interrupts(phydev);
  151. phy_stop_machine(phydev);
  152. phydev->adjust_link = NULL;
  153. phy_detach(phydev);
  154. }
  155. EXPORT_SYMBOL(phy_disconnect);
  156. static int phy_compare_id(struct device *dev, void *data)
  157. {
  158. return strcmp((char *)data, dev->bus_id) ? 0 : 1;
  159. }
  160. /**
  161. * phy_attach - attach a network device to a particular PHY device
  162. * @dev: network device to attach
  163. * @phy_id: PHY device to attach
  164. * @flags: PHY device's dev_flags
  165. * @interface: PHY device's interface
  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 driver.
  173. */
  174. struct phy_device *phy_attach(struct net_device *dev,
  175. const char *phy_id, u32 flags, phy_interface_t interface)
  176. {
  177. struct bus_type *bus = &mdio_bus_type;
  178. struct phy_device *phydev;
  179. struct device *d;
  180. /* Search the list of PHY devices on the mdio bus for the
  181. * PHY with the requested name */
  182. d = bus_find_device(bus, NULL, (void *)phy_id, phy_compare_id);
  183. if (d) {
  184. phydev = to_phy_device(d);
  185. } else {
  186. printk(KERN_ERR "%s not found\n", phy_id);
  187. return ERR_PTR(-ENODEV);
  188. }
  189. /* Assume that if there is no driver, that it doesn't
  190. * exist, and we should use the genphy driver. */
  191. if (NULL == d->driver) {
  192. int err;
  193. d->driver = &genphy_driver.driver;
  194. err = d->driver->probe(d);
  195. if (err >= 0)
  196. err = device_bind_driver(d);
  197. if (err)
  198. return ERR_PTR(err);
  199. }
  200. if (phydev->attached_dev) {
  201. printk(KERN_ERR "%s: %s already attached\n",
  202. dev->name, phy_id);
  203. return ERR_PTR(-EBUSY);
  204. }
  205. phydev->attached_dev = dev;
  206. phydev->dev_flags = flags;
  207. phydev->interface = interface;
  208. /* Do initial configuration here, now that
  209. * we have certain key parameters
  210. * (dev_flags and interface) */
  211. if (phydev->drv->config_init) {
  212. int err;
  213. err = phydev->drv->config_init(phydev);
  214. if (err < 0)
  215. return ERR_PTR(err);
  216. }
  217. return phydev;
  218. }
  219. EXPORT_SYMBOL(phy_attach);
  220. /**
  221. * phy_detach - detach a PHY device from its network device
  222. * @phydev: target phy_device struct
  223. */
  224. void phy_detach(struct phy_device *phydev)
  225. {
  226. phydev->attached_dev = NULL;
  227. /* If the device had no specific driver before (i.e. - it
  228. * was using the generic driver), we unbind the device
  229. * from the generic driver so that there's a chance a
  230. * real driver could be loaded */
  231. if (phydev->dev.driver == &genphy_driver.driver)
  232. device_release_driver(&phydev->dev);
  233. }
  234. EXPORT_SYMBOL(phy_detach);
  235. /* Generic PHY support and helper functions */
  236. /**
  237. * genphy_config_advert - sanitize and advertise auto-negotation parameters
  238. * @phydev: target phy_device struct
  239. *
  240. * Description: Writes MII_ADVERTISE with the appropriate values,
  241. * after sanitizing the values to make sure we only advertise
  242. * what is supported.
  243. */
  244. int genphy_config_advert(struct phy_device *phydev)
  245. {
  246. u32 advertise;
  247. int adv;
  248. int err;
  249. /* Only allow advertising what
  250. * this PHY supports */
  251. phydev->advertising &= phydev->supported;
  252. advertise = phydev->advertising;
  253. /* Setup standard advertisement */
  254. adv = phy_read(phydev, MII_ADVERTISE);
  255. if (adv < 0)
  256. return adv;
  257. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP |
  258. ADVERTISE_PAUSE_ASYM);
  259. if (advertise & ADVERTISED_10baseT_Half)
  260. adv |= ADVERTISE_10HALF;
  261. if (advertise & ADVERTISED_10baseT_Full)
  262. adv |= ADVERTISE_10FULL;
  263. if (advertise & ADVERTISED_100baseT_Half)
  264. adv |= ADVERTISE_100HALF;
  265. if (advertise & ADVERTISED_100baseT_Full)
  266. adv |= ADVERTISE_100FULL;
  267. if (advertise & ADVERTISED_Pause)
  268. adv |= ADVERTISE_PAUSE_CAP;
  269. if (advertise & ADVERTISED_Asym_Pause)
  270. adv |= ADVERTISE_PAUSE_ASYM;
  271. err = phy_write(phydev, MII_ADVERTISE, adv);
  272. if (err < 0)
  273. return err;
  274. /* Configure gigabit if it's supported */
  275. if (phydev->supported & (SUPPORTED_1000baseT_Half |
  276. SUPPORTED_1000baseT_Full)) {
  277. adv = phy_read(phydev, MII_CTRL1000);
  278. if (adv < 0)
  279. return adv;
  280. adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
  281. if (advertise & SUPPORTED_1000baseT_Half)
  282. adv |= ADVERTISE_1000HALF;
  283. if (advertise & SUPPORTED_1000baseT_Full)
  284. adv |= ADVERTISE_1000FULL;
  285. err = phy_write(phydev, MII_CTRL1000, adv);
  286. if (err < 0)
  287. return err;
  288. }
  289. return adv;
  290. }
  291. EXPORT_SYMBOL(genphy_config_advert);
  292. /**
  293. * genphy_setup_forced - configures/forces speed/duplex from @phydev
  294. * @phydev: target phy_device struct
  295. *
  296. * Description: Configures MII_BMCR to force speed/duplex
  297. * to the values in phydev. Assumes that the values are valid.
  298. * Please see phy_sanitize_settings().
  299. */
  300. int genphy_setup_forced(struct phy_device *phydev)
  301. {
  302. int ctl = BMCR_RESET;
  303. phydev->pause = phydev->asym_pause = 0;
  304. if (SPEED_1000 == phydev->speed)
  305. ctl |= BMCR_SPEED1000;
  306. else if (SPEED_100 == phydev->speed)
  307. ctl |= BMCR_SPEED100;
  308. if (DUPLEX_FULL == phydev->duplex)
  309. ctl |= BMCR_FULLDPLX;
  310. ctl = phy_write(phydev, MII_BMCR, ctl);
  311. if (ctl < 0)
  312. return ctl;
  313. /* We just reset the device, so we'd better configure any
  314. * settings the PHY requires to operate */
  315. if (phydev->drv->config_init)
  316. ctl = phydev->drv->config_init(phydev);
  317. return ctl;
  318. }
  319. /**
  320. * genphy_restart_aneg - Enable and Restart Autonegotiation
  321. * @phydev: target phy_device struct
  322. */
  323. int genphy_restart_aneg(struct phy_device *phydev)
  324. {
  325. int ctl;
  326. ctl = phy_read(phydev, MII_BMCR);
  327. if (ctl < 0)
  328. return ctl;
  329. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  330. /* Don't isolate the PHY if we're negotiating */
  331. ctl &= ~(BMCR_ISOLATE);
  332. ctl = phy_write(phydev, MII_BMCR, ctl);
  333. return ctl;
  334. }
  335. /**
  336. * genphy_config_aneg - restart auto-negotiation or write BMCR
  337. * @phydev: target phy_device struct
  338. *
  339. * Description: If auto-negotiation is enabled, we configure the
  340. * advertising, and then restart auto-negotiation. If it is not
  341. * enabled, then we write the BMCR.
  342. */
  343. int genphy_config_aneg(struct phy_device *phydev)
  344. {
  345. int err = 0;
  346. if (AUTONEG_ENABLE == phydev->autoneg) {
  347. err = genphy_config_advert(phydev);
  348. if (err < 0)
  349. return err;
  350. err = genphy_restart_aneg(phydev);
  351. } else
  352. err = genphy_setup_forced(phydev);
  353. return err;
  354. }
  355. EXPORT_SYMBOL(genphy_config_aneg);
  356. /**
  357. * genphy_update_link - update link status in @phydev
  358. * @phydev: target phy_device struct
  359. *
  360. * Description: Update the value in phydev->link to reflect the
  361. * current link value. In order to do this, we need to read
  362. * the status register twice, keeping the second value.
  363. */
  364. int genphy_update_link(struct phy_device *phydev)
  365. {
  366. int status;
  367. /* Do a fake read */
  368. status = phy_read(phydev, MII_BMSR);
  369. if (status < 0)
  370. return status;
  371. /* Read link and autonegotiation status */
  372. status = phy_read(phydev, MII_BMSR);
  373. if (status < 0)
  374. return status;
  375. if ((status & BMSR_LSTATUS) == 0)
  376. phydev->link = 0;
  377. else
  378. phydev->link = 1;
  379. return 0;
  380. }
  381. EXPORT_SYMBOL(genphy_update_link);
  382. /**
  383. * genphy_read_status - check the link status and update current link state
  384. * @phydev: target phy_device struct
  385. *
  386. * Description: Check the link, then figure out the current state
  387. * by comparing what we advertise with what the link partner
  388. * advertises. Start by checking the gigabit possibilities,
  389. * then move on to 10/100.
  390. */
  391. int genphy_read_status(struct phy_device *phydev)
  392. {
  393. int adv;
  394. int err;
  395. int lpa;
  396. int lpagb = 0;
  397. /* Update the link, but return if there
  398. * was an error */
  399. err = genphy_update_link(phydev);
  400. if (err)
  401. return err;
  402. if (AUTONEG_ENABLE == phydev->autoneg) {
  403. if (phydev->supported & (SUPPORTED_1000baseT_Half
  404. | SUPPORTED_1000baseT_Full)) {
  405. lpagb = phy_read(phydev, MII_STAT1000);
  406. if (lpagb < 0)
  407. return lpagb;
  408. adv = phy_read(phydev, MII_CTRL1000);
  409. if (adv < 0)
  410. return adv;
  411. lpagb &= adv << 2;
  412. }
  413. lpa = phy_read(phydev, MII_LPA);
  414. if (lpa < 0)
  415. return lpa;
  416. adv = phy_read(phydev, MII_ADVERTISE);
  417. if (adv < 0)
  418. return adv;
  419. lpa &= adv;
  420. phydev->speed = SPEED_10;
  421. phydev->duplex = DUPLEX_HALF;
  422. phydev->pause = phydev->asym_pause = 0;
  423. if (lpagb & (LPA_1000FULL | LPA_1000HALF)) {
  424. phydev->speed = SPEED_1000;
  425. if (lpagb & LPA_1000FULL)
  426. phydev->duplex = DUPLEX_FULL;
  427. } else if (lpa & (LPA_100FULL | LPA_100HALF)) {
  428. phydev->speed = SPEED_100;
  429. if (lpa & LPA_100FULL)
  430. phydev->duplex = DUPLEX_FULL;
  431. } else
  432. if (lpa & LPA_10FULL)
  433. phydev->duplex = DUPLEX_FULL;
  434. if (phydev->duplex == DUPLEX_FULL){
  435. phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
  436. phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
  437. }
  438. } else {
  439. int bmcr = phy_read(phydev, MII_BMCR);
  440. if (bmcr < 0)
  441. return bmcr;
  442. if (bmcr & BMCR_FULLDPLX)
  443. phydev->duplex = DUPLEX_FULL;
  444. else
  445. phydev->duplex = DUPLEX_HALF;
  446. if (bmcr & BMCR_SPEED1000)
  447. phydev->speed = SPEED_1000;
  448. else if (bmcr & BMCR_SPEED100)
  449. phydev->speed = SPEED_100;
  450. else
  451. phydev->speed = SPEED_10;
  452. phydev->pause = phydev->asym_pause = 0;
  453. }
  454. return 0;
  455. }
  456. EXPORT_SYMBOL(genphy_read_status);
  457. static int genphy_config_init(struct phy_device *phydev)
  458. {
  459. int val;
  460. u32 features;
  461. /* For now, I'll claim that the generic driver supports
  462. * all possible port types */
  463. features = (SUPPORTED_TP | SUPPORTED_MII
  464. | SUPPORTED_AUI | SUPPORTED_FIBRE |
  465. SUPPORTED_BNC);
  466. /* Do we support autonegotiation? */
  467. val = phy_read(phydev, MII_BMSR);
  468. if (val < 0)
  469. return val;
  470. if (val & BMSR_ANEGCAPABLE)
  471. features |= SUPPORTED_Autoneg;
  472. if (val & BMSR_100FULL)
  473. features |= SUPPORTED_100baseT_Full;
  474. if (val & BMSR_100HALF)
  475. features |= SUPPORTED_100baseT_Half;
  476. if (val & BMSR_10FULL)
  477. features |= SUPPORTED_10baseT_Full;
  478. if (val & BMSR_10HALF)
  479. features |= SUPPORTED_10baseT_Half;
  480. if (val & BMSR_ESTATEN) {
  481. val = phy_read(phydev, MII_ESTATUS);
  482. if (val < 0)
  483. return val;
  484. if (val & ESTATUS_1000_TFULL)
  485. features |= SUPPORTED_1000baseT_Full;
  486. if (val & ESTATUS_1000_THALF)
  487. features |= SUPPORTED_1000baseT_Half;
  488. }
  489. phydev->supported = features;
  490. phydev->advertising = features;
  491. return 0;
  492. }
  493. /**
  494. * phy_probe - probe and init a PHY device
  495. * @dev: device to probe and init
  496. *
  497. * Description: Take care of setting up the phy_device structure,
  498. * set the state to READY (the driver's init function should
  499. * set it to STARTING if needed).
  500. */
  501. static int phy_probe(struct device *dev)
  502. {
  503. struct phy_device *phydev;
  504. struct phy_driver *phydrv;
  505. struct device_driver *drv;
  506. int err = 0;
  507. phydev = to_phy_device(dev);
  508. /* Make sure the driver is held.
  509. * XXX -- Is this correct? */
  510. drv = get_driver(phydev->dev.driver);
  511. phydrv = to_phy_driver(drv);
  512. phydev->drv = phydrv;
  513. /* Disable the interrupt if the PHY doesn't support it */
  514. if (!(phydrv->flags & PHY_HAS_INTERRUPT))
  515. phydev->irq = PHY_POLL;
  516. spin_lock(&phydev->lock);
  517. /* Start out supporting everything. Eventually,
  518. * a controller will attach, and may modify one
  519. * or both of these values */
  520. phydev->supported = phydrv->features;
  521. phydev->advertising = phydrv->features;
  522. /* Set the state to READY by default */
  523. phydev->state = PHY_READY;
  524. if (phydev->drv->probe)
  525. err = phydev->drv->probe(phydev);
  526. spin_unlock(&phydev->lock);
  527. return err;
  528. }
  529. static int phy_remove(struct device *dev)
  530. {
  531. struct phy_device *phydev;
  532. phydev = to_phy_device(dev);
  533. spin_lock(&phydev->lock);
  534. phydev->state = PHY_DOWN;
  535. spin_unlock(&phydev->lock);
  536. if (phydev->drv->remove)
  537. phydev->drv->remove(phydev);
  538. put_driver(dev->driver);
  539. phydev->drv = NULL;
  540. return 0;
  541. }
  542. /**
  543. * phy_driver_register - register a phy_driver with the PHY layer
  544. * @new_driver: new phy_driver to register
  545. */
  546. int phy_driver_register(struct phy_driver *new_driver)
  547. {
  548. int retval;
  549. memset(&new_driver->driver, 0, sizeof(new_driver->driver));
  550. new_driver->driver.name = new_driver->name;
  551. new_driver->driver.bus = &mdio_bus_type;
  552. new_driver->driver.probe = phy_probe;
  553. new_driver->driver.remove = phy_remove;
  554. retval = driver_register(&new_driver->driver);
  555. if (retval) {
  556. printk(KERN_ERR "%s: Error %d in registering driver\n",
  557. new_driver->name, retval);
  558. return retval;
  559. }
  560. pr_info("%s: Registered new driver\n", new_driver->name);
  561. return 0;
  562. }
  563. EXPORT_SYMBOL(phy_driver_register);
  564. void phy_driver_unregister(struct phy_driver *drv)
  565. {
  566. driver_unregister(&drv->driver);
  567. }
  568. EXPORT_SYMBOL(phy_driver_unregister);
  569. static struct phy_driver genphy_driver = {
  570. .phy_id = 0xffffffff,
  571. .phy_id_mask = 0xffffffff,
  572. .name = "Generic PHY",
  573. .config_init = genphy_config_init,
  574. .features = 0,
  575. .config_aneg = genphy_config_aneg,
  576. .read_status = genphy_read_status,
  577. .driver = {.owner= THIS_MODULE, },
  578. };
  579. static int __init phy_init(void)
  580. {
  581. int rc;
  582. rc = mdio_bus_init();
  583. if (rc)
  584. return rc;
  585. rc = phy_driver_register(&genphy_driver);
  586. if (rc)
  587. mdio_bus_exit();
  588. return rc;
  589. }
  590. static void __exit phy_exit(void)
  591. {
  592. phy_driver_unregister(&genphy_driver);
  593. mdio_bus_exit();
  594. }
  595. subsys_initcall(phy_init);
  596. module_exit(phy_exit);