phy_device.c 18 KB

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