phy_device.c 18 KB

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