sungem_phy.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. /*
  2. * PHY drivers for the sungem ethernet driver.
  3. *
  4. * This file could be shared with other drivers.
  5. *
  6. * (c) 2002-2007, Benjamin Herrenscmidt (benh@kernel.crashing.org)
  7. *
  8. * TODO:
  9. * - Add support for PHYs that provide an IRQ line
  10. * - Eventually moved the entire polling state machine in
  11. * there (out of the eth driver), so that it can easily be
  12. * skipped on PHYs that implement it in hardware.
  13. * - On LXT971 & BCM5201, Apple uses some chip specific regs
  14. * to read the link status. Figure out why and if it makes
  15. * sense to do the same (magic aneg ?)
  16. * - Apple has some additional power management code for some
  17. * Broadcom PHYs that they "hide" from the OpenSource version
  18. * of darwin, still need to reverse engineer that
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/mii.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/delay.h>
  28. #ifdef CONFIG_PPC_PMAC
  29. #include <asm/prom.h>
  30. #endif
  31. #include "sungem_phy.h"
  32. /* Link modes of the BCM5400 PHY */
  33. static const int phy_BCM5400_link_table[8][3] = {
  34. { 0, 0, 0 }, /* No link */
  35. { 0, 0, 0 }, /* 10BT Half Duplex */
  36. { 1, 0, 0 }, /* 10BT Full Duplex */
  37. { 0, 1, 0 }, /* 100BT Half Duplex */
  38. { 0, 1, 0 }, /* 100BT Half Duplex */
  39. { 1, 1, 0 }, /* 100BT Full Duplex*/
  40. { 1, 0, 1 }, /* 1000BT */
  41. { 1, 0, 1 }, /* 1000BT */
  42. };
  43. static inline int __phy_read(struct mii_phy* phy, int id, int reg)
  44. {
  45. return phy->mdio_read(phy->dev, id, reg);
  46. }
  47. static inline void __phy_write(struct mii_phy* phy, int id, int reg, int val)
  48. {
  49. phy->mdio_write(phy->dev, id, reg, val);
  50. }
  51. static inline int phy_read(struct mii_phy* phy, int reg)
  52. {
  53. return phy->mdio_read(phy->dev, phy->mii_id, reg);
  54. }
  55. static inline void phy_write(struct mii_phy* phy, int reg, int val)
  56. {
  57. phy->mdio_write(phy->dev, phy->mii_id, reg, val);
  58. }
  59. static int reset_one_mii_phy(struct mii_phy* phy, int phy_id)
  60. {
  61. u16 val;
  62. int limit = 10000;
  63. val = __phy_read(phy, phy_id, MII_BMCR);
  64. val &= ~(BMCR_ISOLATE | BMCR_PDOWN);
  65. val |= BMCR_RESET;
  66. __phy_write(phy, phy_id, MII_BMCR, val);
  67. udelay(100);
  68. while (--limit) {
  69. val = __phy_read(phy, phy_id, MII_BMCR);
  70. if ((val & BMCR_RESET) == 0)
  71. break;
  72. udelay(10);
  73. }
  74. if ((val & BMCR_ISOLATE) && limit > 0)
  75. __phy_write(phy, phy_id, MII_BMCR, val & ~BMCR_ISOLATE);
  76. return limit <= 0;
  77. }
  78. static int bcm5201_init(struct mii_phy* phy)
  79. {
  80. u16 data;
  81. data = phy_read(phy, MII_BCM5201_MULTIPHY);
  82. data &= ~MII_BCM5201_MULTIPHY_SUPERISOLATE;
  83. phy_write(phy, MII_BCM5201_MULTIPHY, data);
  84. phy_write(phy, MII_BCM5201_INTERRUPT, 0);
  85. return 0;
  86. }
  87. static int bcm5201_suspend(struct mii_phy* phy)
  88. {
  89. phy_write(phy, MII_BCM5201_INTERRUPT, 0);
  90. phy_write(phy, MII_BCM5201_MULTIPHY, MII_BCM5201_MULTIPHY_SUPERISOLATE);
  91. return 0;
  92. }
  93. static int bcm5221_init(struct mii_phy* phy)
  94. {
  95. u16 data;
  96. data = phy_read(phy, MII_BCM5221_TEST);
  97. phy_write(phy, MII_BCM5221_TEST,
  98. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  99. data = phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2);
  100. phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2,
  101. data | MII_BCM5221_SHDOW_AUX_STAT2_APD);
  102. data = phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  103. phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
  104. data | MII_BCM5221_SHDOW_AUX_MODE4_CLKLOPWR);
  105. data = phy_read(phy, MII_BCM5221_TEST);
  106. phy_write(phy, MII_BCM5221_TEST,
  107. data & ~MII_BCM5221_TEST_ENABLE_SHADOWS);
  108. return 0;
  109. }
  110. static int bcm5221_suspend(struct mii_phy* phy)
  111. {
  112. u16 data;
  113. data = phy_read(phy, MII_BCM5221_TEST);
  114. phy_write(phy, MII_BCM5221_TEST,
  115. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  116. data = phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  117. phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
  118. data | MII_BCM5221_SHDOW_AUX_MODE4_IDDQMODE);
  119. return 0;
  120. }
  121. static int bcm5241_init(struct mii_phy* phy)
  122. {
  123. u16 data;
  124. data = phy_read(phy, MII_BCM5221_TEST);
  125. phy_write(phy, MII_BCM5221_TEST,
  126. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  127. data = phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2);
  128. phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2,
  129. data | MII_BCM5221_SHDOW_AUX_STAT2_APD);
  130. data = phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  131. phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
  132. data & ~MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR);
  133. data = phy_read(phy, MII_BCM5221_TEST);
  134. phy_write(phy, MII_BCM5221_TEST,
  135. data & ~MII_BCM5221_TEST_ENABLE_SHADOWS);
  136. return 0;
  137. }
  138. static int bcm5241_suspend(struct mii_phy* phy)
  139. {
  140. u16 data;
  141. data = phy_read(phy, MII_BCM5221_TEST);
  142. phy_write(phy, MII_BCM5221_TEST,
  143. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  144. data = phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  145. phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
  146. data | MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR);
  147. return 0;
  148. }
  149. static int bcm5400_init(struct mii_phy* phy)
  150. {
  151. u16 data;
  152. /* Configure for gigabit full duplex */
  153. data = phy_read(phy, MII_BCM5400_AUXCONTROL);
  154. data |= MII_BCM5400_AUXCONTROL_PWR10BASET;
  155. phy_write(phy, MII_BCM5400_AUXCONTROL, data);
  156. data = phy_read(phy, MII_BCM5400_GB_CONTROL);
  157. data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
  158. phy_write(phy, MII_BCM5400_GB_CONTROL, data);
  159. udelay(100);
  160. /* Reset and configure cascaded 10/100 PHY */
  161. (void)reset_one_mii_phy(phy, 0x1f);
  162. data = __phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY);
  163. data |= MII_BCM5201_MULTIPHY_SERIALMODE;
  164. __phy_write(phy, 0x1f, MII_BCM5201_MULTIPHY, data);
  165. data = phy_read(phy, MII_BCM5400_AUXCONTROL);
  166. data &= ~MII_BCM5400_AUXCONTROL_PWR10BASET;
  167. phy_write(phy, MII_BCM5400_AUXCONTROL, data);
  168. return 0;
  169. }
  170. static int bcm5400_suspend(struct mii_phy* phy)
  171. {
  172. #if 0 /* Commented out in Darwin... someone has those dawn docs ? */
  173. phy_write(phy, MII_BMCR, BMCR_PDOWN);
  174. #endif
  175. return 0;
  176. }
  177. static int bcm5401_init(struct mii_phy* phy)
  178. {
  179. u16 data;
  180. int rev;
  181. rev = phy_read(phy, MII_PHYSID2) & 0x000f;
  182. if (rev == 0 || rev == 3) {
  183. /* Some revisions of 5401 appear to need this
  184. * initialisation sequence to disable, according
  185. * to OF, "tap power management"
  186. *
  187. * WARNING ! OF and Darwin don't agree on the
  188. * register addresses. OF seem to interpret the
  189. * register numbers below as decimal
  190. *
  191. * Note: This should (and does) match tg3_init_5401phy_dsp
  192. * in the tg3.c driver. -DaveM
  193. */
  194. phy_write(phy, 0x18, 0x0c20);
  195. phy_write(phy, 0x17, 0x0012);
  196. phy_write(phy, 0x15, 0x1804);
  197. phy_write(phy, 0x17, 0x0013);
  198. phy_write(phy, 0x15, 0x1204);
  199. phy_write(phy, 0x17, 0x8006);
  200. phy_write(phy, 0x15, 0x0132);
  201. phy_write(phy, 0x17, 0x8006);
  202. phy_write(phy, 0x15, 0x0232);
  203. phy_write(phy, 0x17, 0x201f);
  204. phy_write(phy, 0x15, 0x0a20);
  205. }
  206. /* Configure for gigabit full duplex */
  207. data = phy_read(phy, MII_BCM5400_GB_CONTROL);
  208. data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
  209. phy_write(phy, MII_BCM5400_GB_CONTROL, data);
  210. udelay(10);
  211. /* Reset and configure cascaded 10/100 PHY */
  212. (void)reset_one_mii_phy(phy, 0x1f);
  213. data = __phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY);
  214. data |= MII_BCM5201_MULTIPHY_SERIALMODE;
  215. __phy_write(phy, 0x1f, MII_BCM5201_MULTIPHY, data);
  216. return 0;
  217. }
  218. static int bcm5401_suspend(struct mii_phy* phy)
  219. {
  220. #if 0 /* Commented out in Darwin... someone has those dawn docs ? */
  221. phy_write(phy, MII_BMCR, BMCR_PDOWN);
  222. #endif
  223. return 0;
  224. }
  225. static int bcm5411_init(struct mii_phy* phy)
  226. {
  227. u16 data;
  228. /* Here's some more Apple black magic to setup
  229. * some voltage stuffs.
  230. */
  231. phy_write(phy, 0x1c, 0x8c23);
  232. phy_write(phy, 0x1c, 0x8ca3);
  233. phy_write(phy, 0x1c, 0x8c23);
  234. /* Here, Apple seems to want to reset it, do
  235. * it as well
  236. */
  237. phy_write(phy, MII_BMCR, BMCR_RESET);
  238. phy_write(phy, MII_BMCR, 0x1340);
  239. data = phy_read(phy, MII_BCM5400_GB_CONTROL);
  240. data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
  241. phy_write(phy, MII_BCM5400_GB_CONTROL, data);
  242. udelay(10);
  243. /* Reset and configure cascaded 10/100 PHY */
  244. (void)reset_one_mii_phy(phy, 0x1f);
  245. return 0;
  246. }
  247. static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
  248. {
  249. u16 ctl, adv;
  250. phy->autoneg = 1;
  251. phy->speed = SPEED_10;
  252. phy->duplex = DUPLEX_HALF;
  253. phy->pause = 0;
  254. phy->advertising = advertise;
  255. /* Setup standard advertise */
  256. adv = phy_read(phy, MII_ADVERTISE);
  257. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
  258. if (advertise & ADVERTISED_10baseT_Half)
  259. adv |= ADVERTISE_10HALF;
  260. if (advertise & ADVERTISED_10baseT_Full)
  261. adv |= ADVERTISE_10FULL;
  262. if (advertise & ADVERTISED_100baseT_Half)
  263. adv |= ADVERTISE_100HALF;
  264. if (advertise & ADVERTISED_100baseT_Full)
  265. adv |= ADVERTISE_100FULL;
  266. phy_write(phy, MII_ADVERTISE, adv);
  267. /* Start/Restart aneg */
  268. ctl = phy_read(phy, MII_BMCR);
  269. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  270. phy_write(phy, MII_BMCR, ctl);
  271. return 0;
  272. }
  273. static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd)
  274. {
  275. u16 ctl;
  276. phy->autoneg = 0;
  277. phy->speed = speed;
  278. phy->duplex = fd;
  279. phy->pause = 0;
  280. ctl = phy_read(phy, MII_BMCR);
  281. ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_ANENABLE);
  282. /* First reset the PHY */
  283. phy_write(phy, MII_BMCR, ctl | BMCR_RESET);
  284. /* Select speed & duplex */
  285. switch(speed) {
  286. case SPEED_10:
  287. break;
  288. case SPEED_100:
  289. ctl |= BMCR_SPEED100;
  290. break;
  291. case SPEED_1000:
  292. default:
  293. return -EINVAL;
  294. }
  295. if (fd == DUPLEX_FULL)
  296. ctl |= BMCR_FULLDPLX;
  297. phy_write(phy, MII_BMCR, ctl);
  298. return 0;
  299. }
  300. static int genmii_poll_link(struct mii_phy *phy)
  301. {
  302. u16 status;
  303. (void)phy_read(phy, MII_BMSR);
  304. status = phy_read(phy, MII_BMSR);
  305. if ((status & BMSR_LSTATUS) == 0)
  306. return 0;
  307. if (phy->autoneg && !(status & BMSR_ANEGCOMPLETE))
  308. return 0;
  309. return 1;
  310. }
  311. static int genmii_read_link(struct mii_phy *phy)
  312. {
  313. u16 lpa;
  314. if (phy->autoneg) {
  315. lpa = phy_read(phy, MII_LPA);
  316. if (lpa & (LPA_10FULL | LPA_100FULL))
  317. phy->duplex = DUPLEX_FULL;
  318. else
  319. phy->duplex = DUPLEX_HALF;
  320. if (lpa & (LPA_100FULL | LPA_100HALF))
  321. phy->speed = SPEED_100;
  322. else
  323. phy->speed = SPEED_10;
  324. phy->pause = 0;
  325. }
  326. /* On non-aneg, we assume what we put in BMCR is the speed,
  327. * though magic-aneg shouldn't prevent this case from occurring
  328. */
  329. return 0;
  330. }
  331. static int generic_suspend(struct mii_phy* phy)
  332. {
  333. phy_write(phy, MII_BMCR, BMCR_PDOWN);
  334. return 0;
  335. }
  336. static int bcm5421_init(struct mii_phy* phy)
  337. {
  338. u16 data;
  339. unsigned int id;
  340. id = (phy_read(phy, MII_PHYSID1) << 16 | phy_read(phy, MII_PHYSID2));
  341. /* Revision 0 of 5421 needs some fixups */
  342. if (id == 0x002060e0) {
  343. /* This is borrowed from MacOS
  344. */
  345. phy_write(phy, 0x18, 0x1007);
  346. data = phy_read(phy, 0x18);
  347. phy_write(phy, 0x18, data | 0x0400);
  348. phy_write(phy, 0x18, 0x0007);
  349. data = phy_read(phy, 0x18);
  350. phy_write(phy, 0x18, data | 0x0800);
  351. phy_write(phy, 0x17, 0x000a);
  352. data = phy_read(phy, 0x15);
  353. phy_write(phy, 0x15, data | 0x0200);
  354. }
  355. /* Pick up some init code from OF for K2 version */
  356. if ((id & 0xfffffff0) == 0x002062e0) {
  357. phy_write(phy, 4, 0x01e1);
  358. phy_write(phy, 9, 0x0300);
  359. }
  360. /* Check if we can enable automatic low power */
  361. #ifdef CONFIG_PPC_PMAC
  362. if (phy->platform_data) {
  363. struct device_node *np = of_get_parent(phy->platform_data);
  364. int can_low_power = 1;
  365. if (np == NULL || of_get_property(np, "no-autolowpower", NULL))
  366. can_low_power = 0;
  367. if (can_low_power) {
  368. /* Enable automatic low-power */
  369. phy_write(phy, 0x1c, 0x9002);
  370. phy_write(phy, 0x1c, 0xa821);
  371. phy_write(phy, 0x1c, 0x941d);
  372. }
  373. }
  374. #endif /* CONFIG_PPC_PMAC */
  375. return 0;
  376. }
  377. static int bcm54xx_setup_aneg(struct mii_phy *phy, u32 advertise)
  378. {
  379. u16 ctl, adv;
  380. phy->autoneg = 1;
  381. phy->speed = SPEED_10;
  382. phy->duplex = DUPLEX_HALF;
  383. phy->pause = 0;
  384. phy->advertising = advertise;
  385. /* Setup standard advertise */
  386. adv = phy_read(phy, MII_ADVERTISE);
  387. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
  388. if (advertise & ADVERTISED_10baseT_Half)
  389. adv |= ADVERTISE_10HALF;
  390. if (advertise & ADVERTISED_10baseT_Full)
  391. adv |= ADVERTISE_10FULL;
  392. if (advertise & ADVERTISED_100baseT_Half)
  393. adv |= ADVERTISE_100HALF;
  394. if (advertise & ADVERTISED_100baseT_Full)
  395. adv |= ADVERTISE_100FULL;
  396. if (advertise & ADVERTISED_Pause)
  397. adv |= ADVERTISE_PAUSE_CAP;
  398. if (advertise & ADVERTISED_Asym_Pause)
  399. adv |= ADVERTISE_PAUSE_ASYM;
  400. phy_write(phy, MII_ADVERTISE, adv);
  401. /* Setup 1000BT advertise */
  402. adv = phy_read(phy, MII_1000BASETCONTROL);
  403. adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP|MII_1000BASETCONTROL_HALFDUPLEXCAP);
  404. if (advertise & SUPPORTED_1000baseT_Half)
  405. adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
  406. if (advertise & SUPPORTED_1000baseT_Full)
  407. adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
  408. phy_write(phy, MII_1000BASETCONTROL, adv);
  409. /* Start/Restart aneg */
  410. ctl = phy_read(phy, MII_BMCR);
  411. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  412. phy_write(phy, MII_BMCR, ctl);
  413. return 0;
  414. }
  415. static int bcm54xx_setup_forced(struct mii_phy *phy, int speed, int fd)
  416. {
  417. u16 ctl;
  418. phy->autoneg = 0;
  419. phy->speed = speed;
  420. phy->duplex = fd;
  421. phy->pause = 0;
  422. ctl = phy_read(phy, MII_BMCR);
  423. ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_SPD2|BMCR_ANENABLE);
  424. /* First reset the PHY */
  425. phy_write(phy, MII_BMCR, ctl | BMCR_RESET);
  426. /* Select speed & duplex */
  427. switch(speed) {
  428. case SPEED_10:
  429. break;
  430. case SPEED_100:
  431. ctl |= BMCR_SPEED100;
  432. break;
  433. case SPEED_1000:
  434. ctl |= BMCR_SPD2;
  435. }
  436. if (fd == DUPLEX_FULL)
  437. ctl |= BMCR_FULLDPLX;
  438. // XXX Should we set the sungem to GII now on 1000BT ?
  439. phy_write(phy, MII_BMCR, ctl);
  440. return 0;
  441. }
  442. static int bcm54xx_read_link(struct mii_phy *phy)
  443. {
  444. int link_mode;
  445. u16 val;
  446. if (phy->autoneg) {
  447. val = phy_read(phy, MII_BCM5400_AUXSTATUS);
  448. link_mode = ((val & MII_BCM5400_AUXSTATUS_LINKMODE_MASK) >>
  449. MII_BCM5400_AUXSTATUS_LINKMODE_SHIFT);
  450. phy->duplex = phy_BCM5400_link_table[link_mode][0] ?
  451. DUPLEX_FULL : DUPLEX_HALF;
  452. phy->speed = phy_BCM5400_link_table[link_mode][2] ?
  453. SPEED_1000 :
  454. (phy_BCM5400_link_table[link_mode][1] ?
  455. SPEED_100 : SPEED_10);
  456. val = phy_read(phy, MII_LPA);
  457. phy->pause = (phy->duplex == DUPLEX_FULL) &&
  458. ((val & LPA_PAUSE) != 0);
  459. }
  460. /* On non-aneg, we assume what we put in BMCR is the speed,
  461. * though magic-aneg shouldn't prevent this case from occurring
  462. */
  463. return 0;
  464. }
  465. static int marvell88e1111_init(struct mii_phy* phy)
  466. {
  467. u16 rev;
  468. /* magic init sequence for rev 0 */
  469. rev = phy_read(phy, MII_PHYSID2) & 0x000f;
  470. if (rev == 0) {
  471. phy_write(phy, 0x1d, 0x000a);
  472. phy_write(phy, 0x1e, 0x0821);
  473. phy_write(phy, 0x1d, 0x0006);
  474. phy_write(phy, 0x1e, 0x8600);
  475. phy_write(phy, 0x1d, 0x000b);
  476. phy_write(phy, 0x1e, 0x0100);
  477. phy_write(phy, 0x1d, 0x0004);
  478. phy_write(phy, 0x1e, 0x4850);
  479. }
  480. return 0;
  481. }
  482. #define BCM5421_MODE_MASK (1 << 5)
  483. static int bcm5421_poll_link(struct mii_phy* phy)
  484. {
  485. u32 phy_reg;
  486. int mode;
  487. /* find out in what mode we are */
  488. phy_write(phy, MII_NCONFIG, 0x1000);
  489. phy_reg = phy_read(phy, MII_NCONFIG);
  490. mode = (phy_reg & BCM5421_MODE_MASK) >> 5;
  491. if ( mode == BCM54XX_COPPER)
  492. return genmii_poll_link(phy);
  493. /* try to find out wether we have a link */
  494. phy_write(phy, MII_NCONFIG, 0x2000);
  495. phy_reg = phy_read(phy, MII_NCONFIG);
  496. if (phy_reg & 0x0020)
  497. return 0;
  498. else
  499. return 1;
  500. }
  501. static int bcm5421_read_link(struct mii_phy* phy)
  502. {
  503. u32 phy_reg;
  504. int mode;
  505. /* find out in what mode we are */
  506. phy_write(phy, MII_NCONFIG, 0x1000);
  507. phy_reg = phy_read(phy, MII_NCONFIG);
  508. mode = (phy_reg & BCM5421_MODE_MASK ) >> 5;
  509. if ( mode == BCM54XX_COPPER)
  510. return bcm54xx_read_link(phy);
  511. phy->speed = SPEED_1000;
  512. /* find out wether we are running half- or full duplex */
  513. phy_write(phy, MII_NCONFIG, 0x2000);
  514. phy_reg = phy_read(phy, MII_NCONFIG);
  515. if ( (phy_reg & 0x0080) >> 7)
  516. phy->duplex |= DUPLEX_HALF;
  517. else
  518. phy->duplex |= DUPLEX_FULL;
  519. return 0;
  520. }
  521. static int bcm5421_enable_fiber(struct mii_phy* phy, int autoneg)
  522. {
  523. /* enable fiber mode */
  524. phy_write(phy, MII_NCONFIG, 0x9020);
  525. /* LEDs active in both modes, autosense prio = fiber */
  526. phy_write(phy, MII_NCONFIG, 0x945f);
  527. if (!autoneg) {
  528. /* switch off fibre autoneg */
  529. phy_write(phy, MII_NCONFIG, 0xfc01);
  530. phy_write(phy, 0x0b, 0x0004);
  531. }
  532. phy->autoneg = autoneg;
  533. return 0;
  534. }
  535. #define BCM5461_FIBER_LINK (1 << 2)
  536. #define BCM5461_MODE_MASK (3 << 1)
  537. static int bcm5461_poll_link(struct mii_phy* phy)
  538. {
  539. u32 phy_reg;
  540. int mode;
  541. /* find out in what mode we are */
  542. phy_write(phy, MII_NCONFIG, 0x7c00);
  543. phy_reg = phy_read(phy, MII_NCONFIG);
  544. mode = (phy_reg & BCM5461_MODE_MASK ) >> 1;
  545. if ( mode == BCM54XX_COPPER)
  546. return genmii_poll_link(phy);
  547. /* find out wether we have a link */
  548. phy_write(phy, MII_NCONFIG, 0x7000);
  549. phy_reg = phy_read(phy, MII_NCONFIG);
  550. if (phy_reg & BCM5461_FIBER_LINK)
  551. return 1;
  552. else
  553. return 0;
  554. }
  555. #define BCM5461_FIBER_DUPLEX (1 << 3)
  556. static int bcm5461_read_link(struct mii_phy* phy)
  557. {
  558. u32 phy_reg;
  559. int mode;
  560. /* find out in what mode we are */
  561. phy_write(phy, MII_NCONFIG, 0x7c00);
  562. phy_reg = phy_read(phy, MII_NCONFIG);
  563. mode = (phy_reg & BCM5461_MODE_MASK ) >> 1;
  564. if ( mode == BCM54XX_COPPER) {
  565. return bcm54xx_read_link(phy);
  566. }
  567. phy->speed = SPEED_1000;
  568. /* find out wether we are running half- or full duplex */
  569. phy_write(phy, MII_NCONFIG, 0x7000);
  570. phy_reg = phy_read(phy, MII_NCONFIG);
  571. if (phy_reg & BCM5461_FIBER_DUPLEX)
  572. phy->duplex |= DUPLEX_FULL;
  573. else
  574. phy->duplex |= DUPLEX_HALF;
  575. return 0;
  576. }
  577. static int bcm5461_enable_fiber(struct mii_phy* phy, int autoneg)
  578. {
  579. /* select fiber mode, enable 1000 base-X registers */
  580. phy_write(phy, MII_NCONFIG, 0xfc0b);
  581. if (autoneg) {
  582. /* enable fiber with no autonegotiation */
  583. phy_write(phy, MII_ADVERTISE, 0x01e0);
  584. phy_write(phy, MII_BMCR, 0x1140);
  585. } else {
  586. /* enable fiber with autonegotiation */
  587. phy_write(phy, MII_BMCR, 0x0140);
  588. }
  589. phy->autoneg = autoneg;
  590. return 0;
  591. }
  592. static int marvell_setup_aneg(struct mii_phy *phy, u32 advertise)
  593. {
  594. u16 ctl, adv;
  595. phy->autoneg = 1;
  596. phy->speed = SPEED_10;
  597. phy->duplex = DUPLEX_HALF;
  598. phy->pause = 0;
  599. phy->advertising = advertise;
  600. /* Setup standard advertise */
  601. adv = phy_read(phy, MII_ADVERTISE);
  602. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
  603. if (advertise & ADVERTISED_10baseT_Half)
  604. adv |= ADVERTISE_10HALF;
  605. if (advertise & ADVERTISED_10baseT_Full)
  606. adv |= ADVERTISE_10FULL;
  607. if (advertise & ADVERTISED_100baseT_Half)
  608. adv |= ADVERTISE_100HALF;
  609. if (advertise & ADVERTISED_100baseT_Full)
  610. adv |= ADVERTISE_100FULL;
  611. if (advertise & ADVERTISED_Pause)
  612. adv |= ADVERTISE_PAUSE_CAP;
  613. if (advertise & ADVERTISED_Asym_Pause)
  614. adv |= ADVERTISE_PAUSE_ASYM;
  615. phy_write(phy, MII_ADVERTISE, adv);
  616. /* Setup 1000BT advertise & enable crossover detect
  617. * XXX How do we advertise 1000BT ? Darwin source is
  618. * confusing here, they read from specific control and
  619. * write to control... Someone has specs for those
  620. * beasts ?
  621. */
  622. adv = phy_read(phy, MII_M1011_PHY_SPEC_CONTROL);
  623. adv |= MII_M1011_PHY_SPEC_CONTROL_AUTO_MDIX;
  624. adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
  625. MII_1000BASETCONTROL_HALFDUPLEXCAP);
  626. if (advertise & SUPPORTED_1000baseT_Half)
  627. adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
  628. if (advertise & SUPPORTED_1000baseT_Full)
  629. adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
  630. phy_write(phy, MII_1000BASETCONTROL, adv);
  631. /* Start/Restart aneg */
  632. ctl = phy_read(phy, MII_BMCR);
  633. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  634. phy_write(phy, MII_BMCR, ctl);
  635. return 0;
  636. }
  637. static int marvell_setup_forced(struct mii_phy *phy, int speed, int fd)
  638. {
  639. u16 ctl, ctl2;
  640. phy->autoneg = 0;
  641. phy->speed = speed;
  642. phy->duplex = fd;
  643. phy->pause = 0;
  644. ctl = phy_read(phy, MII_BMCR);
  645. ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_SPD2|BMCR_ANENABLE);
  646. ctl |= BMCR_RESET;
  647. /* Select speed & duplex */
  648. switch(speed) {
  649. case SPEED_10:
  650. break;
  651. case SPEED_100:
  652. ctl |= BMCR_SPEED100;
  653. break;
  654. /* I'm not sure about the one below, again, Darwin source is
  655. * quite confusing and I lack chip specs
  656. */
  657. case SPEED_1000:
  658. ctl |= BMCR_SPD2;
  659. }
  660. if (fd == DUPLEX_FULL)
  661. ctl |= BMCR_FULLDPLX;
  662. /* Disable crossover. Again, the way Apple does it is strange,
  663. * though I don't assume they are wrong ;)
  664. */
  665. ctl2 = phy_read(phy, MII_M1011_PHY_SPEC_CONTROL);
  666. ctl2 &= ~(MII_M1011_PHY_SPEC_CONTROL_MANUAL_MDIX |
  667. MII_M1011_PHY_SPEC_CONTROL_AUTO_MDIX |
  668. MII_1000BASETCONTROL_FULLDUPLEXCAP |
  669. MII_1000BASETCONTROL_HALFDUPLEXCAP);
  670. if (speed == SPEED_1000)
  671. ctl2 |= (fd == DUPLEX_FULL) ?
  672. MII_1000BASETCONTROL_FULLDUPLEXCAP :
  673. MII_1000BASETCONTROL_HALFDUPLEXCAP;
  674. phy_write(phy, MII_1000BASETCONTROL, ctl2);
  675. // XXX Should we set the sungem to GII now on 1000BT ?
  676. phy_write(phy, MII_BMCR, ctl);
  677. return 0;
  678. }
  679. static int marvell_read_link(struct mii_phy *phy)
  680. {
  681. u16 status, pmask;
  682. if (phy->autoneg) {
  683. status = phy_read(phy, MII_M1011_PHY_SPEC_STATUS);
  684. if ((status & MII_M1011_PHY_SPEC_STATUS_RESOLVED) == 0)
  685. return -EAGAIN;
  686. if (status & MII_M1011_PHY_SPEC_STATUS_1000)
  687. phy->speed = SPEED_1000;
  688. else if (status & MII_M1011_PHY_SPEC_STATUS_100)
  689. phy->speed = SPEED_100;
  690. else
  691. phy->speed = SPEED_10;
  692. if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
  693. phy->duplex = DUPLEX_FULL;
  694. else
  695. phy->duplex = DUPLEX_HALF;
  696. pmask = MII_M1011_PHY_SPEC_STATUS_TX_PAUSE |
  697. MII_M1011_PHY_SPEC_STATUS_RX_PAUSE;
  698. phy->pause = (status & pmask) == pmask;
  699. }
  700. /* On non-aneg, we assume what we put in BMCR is the speed,
  701. * though magic-aneg shouldn't prevent this case from occurring
  702. */
  703. return 0;
  704. }
  705. #define MII_BASIC_FEATURES \
  706. (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \
  707. SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \
  708. SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII | \
  709. SUPPORTED_Pause)
  710. /* On gigabit capable PHYs, we advertise Pause support but not asym pause
  711. * support for now as I'm not sure it's supported and Darwin doesn't do
  712. * it neither. --BenH.
  713. */
  714. #define MII_GBIT_FEATURES \
  715. (MII_BASIC_FEATURES | \
  716. SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
  717. /* Broadcom BCM 5201 */
  718. static struct mii_phy_ops bcm5201_phy_ops = {
  719. .init = bcm5201_init,
  720. .suspend = bcm5201_suspend,
  721. .setup_aneg = genmii_setup_aneg,
  722. .setup_forced = genmii_setup_forced,
  723. .poll_link = genmii_poll_link,
  724. .read_link = genmii_read_link,
  725. };
  726. static struct mii_phy_def bcm5201_phy_def = {
  727. .phy_id = 0x00406210,
  728. .phy_id_mask = 0xfffffff0,
  729. .name = "BCM5201",
  730. .features = MII_BASIC_FEATURES,
  731. .magic_aneg = 1,
  732. .ops = &bcm5201_phy_ops
  733. };
  734. /* Broadcom BCM 5221 */
  735. static struct mii_phy_ops bcm5221_phy_ops = {
  736. .suspend = bcm5221_suspend,
  737. .init = bcm5221_init,
  738. .setup_aneg = genmii_setup_aneg,
  739. .setup_forced = genmii_setup_forced,
  740. .poll_link = genmii_poll_link,
  741. .read_link = genmii_read_link,
  742. };
  743. static struct mii_phy_def bcm5221_phy_def = {
  744. .phy_id = 0x004061e0,
  745. .phy_id_mask = 0xfffffff0,
  746. .name = "BCM5221",
  747. .features = MII_BASIC_FEATURES,
  748. .magic_aneg = 1,
  749. .ops = &bcm5221_phy_ops
  750. };
  751. /* Broadcom BCM 5241 */
  752. static struct mii_phy_ops bcm5241_phy_ops = {
  753. .suspend = bcm5241_suspend,
  754. .init = bcm5241_init,
  755. .setup_aneg = genmii_setup_aneg,
  756. .setup_forced = genmii_setup_forced,
  757. .poll_link = genmii_poll_link,
  758. .read_link = genmii_read_link,
  759. };
  760. static struct mii_phy_def bcm5241_phy_def = {
  761. .phy_id = 0x0143bc30,
  762. .phy_id_mask = 0xfffffff0,
  763. .name = "BCM5241",
  764. .features = MII_BASIC_FEATURES,
  765. .magic_aneg = 1,
  766. .ops = &bcm5241_phy_ops
  767. };
  768. /* Broadcom BCM 5400 */
  769. static struct mii_phy_ops bcm5400_phy_ops = {
  770. .init = bcm5400_init,
  771. .suspend = bcm5400_suspend,
  772. .setup_aneg = bcm54xx_setup_aneg,
  773. .setup_forced = bcm54xx_setup_forced,
  774. .poll_link = genmii_poll_link,
  775. .read_link = bcm54xx_read_link,
  776. };
  777. static struct mii_phy_def bcm5400_phy_def = {
  778. .phy_id = 0x00206040,
  779. .phy_id_mask = 0xfffffff0,
  780. .name = "BCM5400",
  781. .features = MII_GBIT_FEATURES,
  782. .magic_aneg = 1,
  783. .ops = &bcm5400_phy_ops
  784. };
  785. /* Broadcom BCM 5401 */
  786. static struct mii_phy_ops bcm5401_phy_ops = {
  787. .init = bcm5401_init,
  788. .suspend = bcm5401_suspend,
  789. .setup_aneg = bcm54xx_setup_aneg,
  790. .setup_forced = bcm54xx_setup_forced,
  791. .poll_link = genmii_poll_link,
  792. .read_link = bcm54xx_read_link,
  793. };
  794. static struct mii_phy_def bcm5401_phy_def = {
  795. .phy_id = 0x00206050,
  796. .phy_id_mask = 0xfffffff0,
  797. .name = "BCM5401",
  798. .features = MII_GBIT_FEATURES,
  799. .magic_aneg = 1,
  800. .ops = &bcm5401_phy_ops
  801. };
  802. /* Broadcom BCM 5411 */
  803. static struct mii_phy_ops bcm5411_phy_ops = {
  804. .init = bcm5411_init,
  805. .suspend = generic_suspend,
  806. .setup_aneg = bcm54xx_setup_aneg,
  807. .setup_forced = bcm54xx_setup_forced,
  808. .poll_link = genmii_poll_link,
  809. .read_link = bcm54xx_read_link,
  810. };
  811. static struct mii_phy_def bcm5411_phy_def = {
  812. .phy_id = 0x00206070,
  813. .phy_id_mask = 0xfffffff0,
  814. .name = "BCM5411",
  815. .features = MII_GBIT_FEATURES,
  816. .magic_aneg = 1,
  817. .ops = &bcm5411_phy_ops
  818. };
  819. /* Broadcom BCM 5421 */
  820. static struct mii_phy_ops bcm5421_phy_ops = {
  821. .init = bcm5421_init,
  822. .suspend = generic_suspend,
  823. .setup_aneg = bcm54xx_setup_aneg,
  824. .setup_forced = bcm54xx_setup_forced,
  825. .poll_link = bcm5421_poll_link,
  826. .read_link = bcm5421_read_link,
  827. .enable_fiber = bcm5421_enable_fiber,
  828. };
  829. static struct mii_phy_def bcm5421_phy_def = {
  830. .phy_id = 0x002060e0,
  831. .phy_id_mask = 0xfffffff0,
  832. .name = "BCM5421",
  833. .features = MII_GBIT_FEATURES,
  834. .magic_aneg = 1,
  835. .ops = &bcm5421_phy_ops
  836. };
  837. /* Broadcom BCM 5421 built-in K2 */
  838. static struct mii_phy_ops bcm5421k2_phy_ops = {
  839. .init = bcm5421_init,
  840. .suspend = generic_suspend,
  841. .setup_aneg = bcm54xx_setup_aneg,
  842. .setup_forced = bcm54xx_setup_forced,
  843. .poll_link = genmii_poll_link,
  844. .read_link = bcm54xx_read_link,
  845. };
  846. static struct mii_phy_def bcm5421k2_phy_def = {
  847. .phy_id = 0x002062e0,
  848. .phy_id_mask = 0xfffffff0,
  849. .name = "BCM5421-K2",
  850. .features = MII_GBIT_FEATURES,
  851. .magic_aneg = 1,
  852. .ops = &bcm5421k2_phy_ops
  853. };
  854. static struct mii_phy_ops bcm5461_phy_ops = {
  855. .init = bcm5421_init,
  856. .suspend = generic_suspend,
  857. .setup_aneg = bcm54xx_setup_aneg,
  858. .setup_forced = bcm54xx_setup_forced,
  859. .poll_link = bcm5461_poll_link,
  860. .read_link = bcm5461_read_link,
  861. .enable_fiber = bcm5461_enable_fiber,
  862. };
  863. static struct mii_phy_def bcm5461_phy_def = {
  864. .phy_id = 0x002060c0,
  865. .phy_id_mask = 0xfffffff0,
  866. .name = "BCM5461",
  867. .features = MII_GBIT_FEATURES,
  868. .magic_aneg = 1,
  869. .ops = &bcm5461_phy_ops
  870. };
  871. /* Broadcom BCM 5462 built-in Vesta */
  872. static struct mii_phy_ops bcm5462V_phy_ops = {
  873. .init = bcm5421_init,
  874. .suspend = generic_suspend,
  875. .setup_aneg = bcm54xx_setup_aneg,
  876. .setup_forced = bcm54xx_setup_forced,
  877. .poll_link = genmii_poll_link,
  878. .read_link = bcm54xx_read_link,
  879. };
  880. static struct mii_phy_def bcm5462V_phy_def = {
  881. .phy_id = 0x002060d0,
  882. .phy_id_mask = 0xfffffff0,
  883. .name = "BCM5462-Vesta",
  884. .features = MII_GBIT_FEATURES,
  885. .magic_aneg = 1,
  886. .ops = &bcm5462V_phy_ops
  887. };
  888. /* Marvell 88E1101 amd 88E1111 */
  889. static struct mii_phy_ops marvell88e1101_phy_ops = {
  890. .suspend = generic_suspend,
  891. .setup_aneg = marvell_setup_aneg,
  892. .setup_forced = marvell_setup_forced,
  893. .poll_link = genmii_poll_link,
  894. .read_link = marvell_read_link
  895. };
  896. static struct mii_phy_ops marvell88e1111_phy_ops = {
  897. .init = marvell88e1111_init,
  898. .suspend = generic_suspend,
  899. .setup_aneg = marvell_setup_aneg,
  900. .setup_forced = marvell_setup_forced,
  901. .poll_link = genmii_poll_link,
  902. .read_link = marvell_read_link
  903. };
  904. /* two revs in darwin for the 88e1101 ... I could use a datasheet
  905. * to get the proper names...
  906. */
  907. static struct mii_phy_def marvell88e1101v1_phy_def = {
  908. .phy_id = 0x01410c20,
  909. .phy_id_mask = 0xfffffff0,
  910. .name = "Marvell 88E1101v1",
  911. .features = MII_GBIT_FEATURES,
  912. .magic_aneg = 1,
  913. .ops = &marvell88e1101_phy_ops
  914. };
  915. static struct mii_phy_def marvell88e1101v2_phy_def = {
  916. .phy_id = 0x01410c60,
  917. .phy_id_mask = 0xfffffff0,
  918. .name = "Marvell 88E1101v2",
  919. .features = MII_GBIT_FEATURES,
  920. .magic_aneg = 1,
  921. .ops = &marvell88e1101_phy_ops
  922. };
  923. static struct mii_phy_def marvell88e1111_phy_def = {
  924. .phy_id = 0x01410cc0,
  925. .phy_id_mask = 0xfffffff0,
  926. .name = "Marvell 88E1111",
  927. .features = MII_GBIT_FEATURES,
  928. .magic_aneg = 1,
  929. .ops = &marvell88e1111_phy_ops
  930. };
  931. /* Generic implementation for most 10/100 PHYs */
  932. static struct mii_phy_ops generic_phy_ops = {
  933. .setup_aneg = genmii_setup_aneg,
  934. .setup_forced = genmii_setup_forced,
  935. .poll_link = genmii_poll_link,
  936. .read_link = genmii_read_link
  937. };
  938. static struct mii_phy_def genmii_phy_def = {
  939. .phy_id = 0x00000000,
  940. .phy_id_mask = 0x00000000,
  941. .name = "Generic MII",
  942. .features = MII_BASIC_FEATURES,
  943. .magic_aneg = 0,
  944. .ops = &generic_phy_ops
  945. };
  946. static struct mii_phy_def* mii_phy_table[] = {
  947. &bcm5201_phy_def,
  948. &bcm5221_phy_def,
  949. &bcm5241_phy_def,
  950. &bcm5400_phy_def,
  951. &bcm5401_phy_def,
  952. &bcm5411_phy_def,
  953. &bcm5421_phy_def,
  954. &bcm5421k2_phy_def,
  955. &bcm5461_phy_def,
  956. &bcm5462V_phy_def,
  957. &marvell88e1101v1_phy_def,
  958. &marvell88e1101v2_phy_def,
  959. &marvell88e1111_phy_def,
  960. &genmii_phy_def,
  961. NULL
  962. };
  963. int mii_phy_probe(struct mii_phy *phy, int mii_id)
  964. {
  965. int rc;
  966. u32 id;
  967. struct mii_phy_def* def;
  968. int i;
  969. /* We do not reset the mii_phy structure as the driver
  970. * may re-probe the PHY regulary
  971. */
  972. phy->mii_id = mii_id;
  973. /* Take PHY out of isloate mode and reset it. */
  974. rc = reset_one_mii_phy(phy, mii_id);
  975. if (rc)
  976. goto fail;
  977. /* Read ID and find matching entry */
  978. id = (phy_read(phy, MII_PHYSID1) << 16 | phy_read(phy, MII_PHYSID2));
  979. printk(KERN_DEBUG KBUILD_MODNAME ": " "PHY ID: %x, addr: %x\n",
  980. id, mii_id);
  981. for (i=0; (def = mii_phy_table[i]) != NULL; i++)
  982. if ((id & def->phy_id_mask) == def->phy_id)
  983. break;
  984. /* Should never be NULL (we have a generic entry), but... */
  985. if (def == NULL)
  986. goto fail;
  987. phy->def = def;
  988. return 0;
  989. fail:
  990. phy->speed = 0;
  991. phy->duplex = 0;
  992. phy->pause = 0;
  993. phy->advertising = 0;
  994. return -ENODEV;
  995. }
  996. EXPORT_SYMBOL(mii_phy_probe);
  997. MODULE_LICENSE("GPL");