sungem_phy.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  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 <linux/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 __sungem_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 __sungem_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 sungem_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 sungem_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 = __sungem_phy_read(phy, phy_id, MII_BMCR);
  64. val &= ~(BMCR_ISOLATE | BMCR_PDOWN);
  65. val |= BMCR_RESET;
  66. __sungem_phy_write(phy, phy_id, MII_BMCR, val);
  67. udelay(100);
  68. while (--limit) {
  69. val = __sungem_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. __sungem_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 = sungem_phy_read(phy, MII_BCM5201_MULTIPHY);
  82. data &= ~MII_BCM5201_MULTIPHY_SUPERISOLATE;
  83. sungem_phy_write(phy, MII_BCM5201_MULTIPHY, data);
  84. sungem_phy_write(phy, MII_BCM5201_INTERRUPT, 0);
  85. return 0;
  86. }
  87. static int bcm5201_suspend(struct mii_phy* phy)
  88. {
  89. sungem_phy_write(phy, MII_BCM5201_INTERRUPT, 0);
  90. sungem_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 = sungem_phy_read(phy, MII_BCM5221_TEST);
  97. sungem_phy_write(phy, MII_BCM5221_TEST,
  98. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  99. data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2);
  100. sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2,
  101. data | MII_BCM5221_SHDOW_AUX_STAT2_APD);
  102. data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  103. sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
  104. data | MII_BCM5221_SHDOW_AUX_MODE4_CLKLOPWR);
  105. data = sungem_phy_read(phy, MII_BCM5221_TEST);
  106. sungem_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 = sungem_phy_read(phy, MII_BCM5221_TEST);
  114. sungem_phy_write(phy, MII_BCM5221_TEST,
  115. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  116. data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  117. sungem_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 = sungem_phy_read(phy, MII_BCM5221_TEST);
  125. sungem_phy_write(phy, MII_BCM5221_TEST,
  126. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  127. data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2);
  128. sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2,
  129. data | MII_BCM5221_SHDOW_AUX_STAT2_APD);
  130. data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  131. sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
  132. data & ~MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR);
  133. data = sungem_phy_read(phy, MII_BCM5221_TEST);
  134. sungem_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 = sungem_phy_read(phy, MII_BCM5221_TEST);
  142. sungem_phy_write(phy, MII_BCM5221_TEST,
  143. data | MII_BCM5221_TEST_ENABLE_SHADOWS);
  144. data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
  145. sungem_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 = sungem_phy_read(phy, MII_BCM5400_AUXCONTROL);
  154. data |= MII_BCM5400_AUXCONTROL_PWR10BASET;
  155. sungem_phy_write(phy, MII_BCM5400_AUXCONTROL, data);
  156. data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL);
  157. data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
  158. sungem_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 = __sungem_phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY);
  163. data |= MII_BCM5201_MULTIPHY_SERIALMODE;
  164. __sungem_phy_write(phy, 0x1f, MII_BCM5201_MULTIPHY, data);
  165. data = sungem_phy_read(phy, MII_BCM5400_AUXCONTROL);
  166. data &= ~MII_BCM5400_AUXCONTROL_PWR10BASET;
  167. sungem_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. sungem_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 = sungem_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. sungem_phy_write(phy, 0x18, 0x0c20);
  195. sungem_phy_write(phy, 0x17, 0x0012);
  196. sungem_phy_write(phy, 0x15, 0x1804);
  197. sungem_phy_write(phy, 0x17, 0x0013);
  198. sungem_phy_write(phy, 0x15, 0x1204);
  199. sungem_phy_write(phy, 0x17, 0x8006);
  200. sungem_phy_write(phy, 0x15, 0x0132);
  201. sungem_phy_write(phy, 0x17, 0x8006);
  202. sungem_phy_write(phy, 0x15, 0x0232);
  203. sungem_phy_write(phy, 0x17, 0x201f);
  204. sungem_phy_write(phy, 0x15, 0x0a20);
  205. }
  206. /* Configure for gigabit full duplex */
  207. data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL);
  208. data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
  209. sungem_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 = __sungem_phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY);
  214. data |= MII_BCM5201_MULTIPHY_SERIALMODE;
  215. __sungem_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. sungem_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. sungem_phy_write(phy, 0x1c, 0x8c23);
  232. sungem_phy_write(phy, 0x1c, 0x8ca3);
  233. sungem_phy_write(phy, 0x1c, 0x8c23);
  234. /* Here, Apple seems to want to reset it, do
  235. * it as well
  236. */
  237. sungem_phy_write(phy, MII_BMCR, BMCR_RESET);
  238. sungem_phy_write(phy, MII_BMCR, 0x1340);
  239. data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL);
  240. data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
  241. sungem_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 = sungem_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. sungem_phy_write(phy, MII_ADVERTISE, adv);
  267. /* Start/Restart aneg */
  268. ctl = sungem_phy_read(phy, MII_BMCR);
  269. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  270. sungem_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 = sungem_phy_read(phy, MII_BMCR);
  281. ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_ANENABLE);
  282. /* First reset the PHY */
  283. sungem_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. sungem_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)sungem_phy_read(phy, MII_BMSR);
  304. status = sungem_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 = sungem_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. sungem_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 = (sungem_phy_read(phy, MII_PHYSID1) << 16 | sungem_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. sungem_phy_write(phy, 0x18, 0x1007);
  346. data = sungem_phy_read(phy, 0x18);
  347. sungem_phy_write(phy, 0x18, data | 0x0400);
  348. sungem_phy_write(phy, 0x18, 0x0007);
  349. data = sungem_phy_read(phy, 0x18);
  350. sungem_phy_write(phy, 0x18, data | 0x0800);
  351. sungem_phy_write(phy, 0x17, 0x000a);
  352. data = sungem_phy_read(phy, 0x15);
  353. sungem_phy_write(phy, 0x15, data | 0x0200);
  354. }
  355. /* Pick up some init code from OF for K2 version */
  356. if ((id & 0xfffffff0) == 0x002062e0) {
  357. sungem_phy_write(phy, 4, 0x01e1);
  358. sungem_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. sungem_phy_write(phy, 0x1c, 0x9002);
  370. sungem_phy_write(phy, 0x1c, 0xa821);
  371. sungem_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 = sungem_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. sungem_phy_write(phy, MII_ADVERTISE, adv);
  401. /* Setup 1000BT advertise */
  402. adv = sungem_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. sungem_phy_write(phy, MII_1000BASETCONTROL, adv);
  409. /* Start/Restart aneg */
  410. ctl = sungem_phy_read(phy, MII_BMCR);
  411. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  412. sungem_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 = sungem_phy_read(phy, MII_BMCR);
  423. ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_SPD2|BMCR_ANENABLE);
  424. /* First reset the PHY */
  425. sungem_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. sungem_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 = sungem_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 = sungem_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 = sungem_phy_read(phy, MII_PHYSID2) & 0x000f;
  470. if (rev == 0) {
  471. sungem_phy_write(phy, 0x1d, 0x000a);
  472. sungem_phy_write(phy, 0x1e, 0x0821);
  473. sungem_phy_write(phy, 0x1d, 0x0006);
  474. sungem_phy_write(phy, 0x1e, 0x8600);
  475. sungem_phy_write(phy, 0x1d, 0x000b);
  476. sungem_phy_write(phy, 0x1e, 0x0100);
  477. sungem_phy_write(phy, 0x1d, 0x0004);
  478. sungem_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. sungem_phy_write(phy, MII_NCONFIG, 0x1000);
  489. phy_reg = sungem_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 whether we have a link */
  494. sungem_phy_write(phy, MII_NCONFIG, 0x2000);
  495. phy_reg = sungem_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. sungem_phy_write(phy, MII_NCONFIG, 0x1000);
  507. phy_reg = sungem_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 whether we are running half- or full duplex */
  513. sungem_phy_write(phy, MII_NCONFIG, 0x2000);
  514. phy_reg = sungem_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. sungem_phy_write(phy, MII_NCONFIG, 0x9020);
  525. /* LEDs active in both modes, autosense prio = fiber */
  526. sungem_phy_write(phy, MII_NCONFIG, 0x945f);
  527. if (!autoneg) {
  528. /* switch off fibre autoneg */
  529. sungem_phy_write(phy, MII_NCONFIG, 0xfc01);
  530. sungem_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. sungem_phy_write(phy, MII_NCONFIG, 0x7c00);
  543. phy_reg = sungem_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 whether we have a link */
  548. sungem_phy_write(phy, MII_NCONFIG, 0x7000);
  549. phy_reg = sungem_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. sungem_phy_write(phy, MII_NCONFIG, 0x7c00);
  562. phy_reg = sungem_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 whether we are running half- or full duplex */
  569. sungem_phy_write(phy, MII_NCONFIG, 0x7000);
  570. phy_reg = sungem_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. sungem_phy_write(phy, MII_NCONFIG, 0xfc0b);
  581. if (autoneg) {
  582. /* enable fiber with no autonegotiation */
  583. sungem_phy_write(phy, MII_ADVERTISE, 0x01e0);
  584. sungem_phy_write(phy, MII_BMCR, 0x1140);
  585. } else {
  586. /* enable fiber with autonegotiation */
  587. sungem_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 = sungem_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. sungem_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 = sungem_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. sungem_phy_write(phy, MII_1000BASETCONTROL, adv);
  631. /* Start/Restart aneg */
  632. ctl = sungem_phy_read(phy, MII_BMCR);
  633. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  634. sungem_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 = sungem_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 = sungem_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. sungem_phy_write(phy, MII_1000BASETCONTROL, ctl2);
  675. // XXX Should we set the sungem to GII now on 1000BT ?
  676. sungem_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 = sungem_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 sungem_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 = (sungem_phy_read(phy, MII_PHYSID1) << 16 | sungem_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(sungem_phy_probe);
  997. MODULE_LICENSE("GPL");