sungem_phy.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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");