phy_device.c 17 KB

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