uec_phy.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Copyright (C) 2005 Freescale Semiconductor, Inc.
  3. *
  4. * Author: Shlomi Gridish
  5. *
  6. * Description: UCC GETH Driver -- PHY handling
  7. * Driver for UEC on QE
  8. * Based on 8260_io/fcc_enet.c
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include "common.h"
  17. #include "net.h"
  18. #include "malloc.h"
  19. #include "asm/errno.h"
  20. #include "asm/immap_qe.h"
  21. #include "asm/io.h"
  22. #include "qe.h"
  23. #include "uccf.h"
  24. #include "uec.h"
  25. #include "uec_phy.h"
  26. #include "miiphy.h"
  27. #define ugphy_printk(format, arg...) \
  28. printf(format "\n", ## arg)
  29. #define ugphy_dbg(format, arg...) \
  30. ugphy_printk(format , ## arg)
  31. #define ugphy_err(format, arg...) \
  32. ugphy_printk(format , ## arg)
  33. #define ugphy_info(format, arg...) \
  34. ugphy_printk(format , ## arg)
  35. #define ugphy_warn(format, arg...) \
  36. ugphy_printk(format , ## arg)
  37. #ifdef UEC_VERBOSE_DEBUG
  38. #define ugphy_vdbg ugphy_dbg
  39. #else
  40. #define ugphy_vdbg(ugeth, fmt, args...) do { } while (0)
  41. #endif /* UEC_VERBOSE_DEBUG */
  42. static void config_genmii_advert (struct uec_mii_info *mii_info);
  43. static void genmii_setup_forced (struct uec_mii_info *mii_info);
  44. static void genmii_restart_aneg (struct uec_mii_info *mii_info);
  45. static int gbit_config_aneg (struct uec_mii_info *mii_info);
  46. static int genmii_config_aneg (struct uec_mii_info *mii_info);
  47. static int genmii_update_link (struct uec_mii_info *mii_info);
  48. static int genmii_read_status (struct uec_mii_info *mii_info);
  49. u16 phy_read (struct uec_mii_info *mii_info, u16 regnum);
  50. void phy_write (struct uec_mii_info *mii_info, u16 regnum, u16 val);
  51. /* Write value to the PHY for this device to the register at regnum, */
  52. /* waiting until the write is done before it returns. All PHY */
  53. /* configuration has to be done through the TSEC1 MIIM regs */
  54. void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum, int value)
  55. {
  56. uec_private_t *ugeth = (uec_private_t *) dev->priv;
  57. uec_mii_t *ug_regs;
  58. enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
  59. u32 tmp_reg;
  60. ug_regs = ugeth->uec_mii_regs;
  61. /* Stop the MII management read cycle */
  62. out_be32 (&ug_regs->miimcom, 0);
  63. /* Setting up the MII Mangement Address Register */
  64. tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
  65. out_be32 (&ug_regs->miimadd, tmp_reg);
  66. /* Setting up the MII Mangement Control Register with the value */
  67. out_be32 (&ug_regs->miimcon, (u32) value);
  68. sync();
  69. /* Wait till MII management write is complete */
  70. while ((in_be32 (&ug_regs->miimind)) & MIIMIND_BUSY);
  71. }
  72. /* Reads from register regnum in the PHY for device dev, */
  73. /* returning the value. Clears miimcom first. All PHY */
  74. /* configuration has to be done through the TSEC1 MIIM regs */
  75. int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum)
  76. {
  77. uec_private_t *ugeth = (uec_private_t *) dev->priv;
  78. uec_mii_t *ug_regs;
  79. enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
  80. u32 tmp_reg;
  81. u16 value;
  82. ug_regs = ugeth->uec_mii_regs;
  83. /* Setting up the MII Mangement Address Register */
  84. tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
  85. out_be32 (&ug_regs->miimadd, tmp_reg);
  86. /* clear MII management command cycle */
  87. out_be32 (&ug_regs->miimcom, 0);
  88. sync();
  89. /* Perform an MII management read cycle */
  90. out_be32 (&ug_regs->miimcom, MIIMCOM_READ_CYCLE);
  91. /* Wait till MII management write is complete */
  92. while ((in_be32 (&ug_regs->miimind)) &
  93. (MIIMIND_NOT_VALID | MIIMIND_BUSY));
  94. /* Read MII management status */
  95. value = (u16) in_be32 (&ug_regs->miimstat);
  96. if (value == 0xffff)
  97. ugphy_vdbg
  98. ("read wrong value : mii_id %d,mii_reg %d, base %08x",
  99. mii_id, mii_reg, (u32) & (ug_regs->miimcfg));
  100. return (value);
  101. }
  102. void mii_clear_phy_interrupt (struct uec_mii_info *mii_info)
  103. {
  104. if (mii_info->phyinfo->ack_interrupt)
  105. mii_info->phyinfo->ack_interrupt (mii_info);
  106. }
  107. void mii_configure_phy_interrupt (struct uec_mii_info *mii_info,
  108. u32 interrupts)
  109. {
  110. mii_info->interrupts = interrupts;
  111. if (mii_info->phyinfo->config_intr)
  112. mii_info->phyinfo->config_intr (mii_info);
  113. }
  114. /* Writes MII_ADVERTISE with the appropriate values, after
  115. * sanitizing advertise to make sure only supported features
  116. * are advertised
  117. */
  118. static void config_genmii_advert (struct uec_mii_info *mii_info)
  119. {
  120. u32 advertise;
  121. u16 adv;
  122. /* Only allow advertising what this PHY supports */
  123. mii_info->advertising &= mii_info->phyinfo->features;
  124. advertise = mii_info->advertising;
  125. /* Setup standard advertisement */
  126. adv = phy_read (mii_info, PHY_ANAR);
  127. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
  128. if (advertise & ADVERTISED_10baseT_Half)
  129. adv |= ADVERTISE_10HALF;
  130. if (advertise & ADVERTISED_10baseT_Full)
  131. adv |= ADVERTISE_10FULL;
  132. if (advertise & ADVERTISED_100baseT_Half)
  133. adv |= ADVERTISE_100HALF;
  134. if (advertise & ADVERTISED_100baseT_Full)
  135. adv |= ADVERTISE_100FULL;
  136. phy_write (mii_info, PHY_ANAR, adv);
  137. }
  138. static void genmii_setup_forced (struct uec_mii_info *mii_info)
  139. {
  140. u16 ctrl;
  141. u32 features = mii_info->phyinfo->features;
  142. ctrl = phy_read (mii_info, PHY_BMCR);
  143. ctrl &= ~(PHY_BMCR_DPLX | PHY_BMCR_100_MBPS |
  144. PHY_BMCR_1000_MBPS | PHY_BMCR_AUTON);
  145. ctrl |= PHY_BMCR_RESET;
  146. switch (mii_info->speed) {
  147. case SPEED_1000:
  148. if (features & (SUPPORTED_1000baseT_Half
  149. | SUPPORTED_1000baseT_Full)) {
  150. ctrl |= PHY_BMCR_1000_MBPS;
  151. break;
  152. }
  153. mii_info->speed = SPEED_100;
  154. case SPEED_100:
  155. if (features & (SUPPORTED_100baseT_Half
  156. | SUPPORTED_100baseT_Full)) {
  157. ctrl |= PHY_BMCR_100_MBPS;
  158. break;
  159. }
  160. mii_info->speed = SPEED_10;
  161. case SPEED_10:
  162. if (features & (SUPPORTED_10baseT_Half
  163. | SUPPORTED_10baseT_Full))
  164. break;
  165. default: /* Unsupported speed! */
  166. ugphy_err ("%s: Bad speed!", mii_info->dev->name);
  167. break;
  168. }
  169. phy_write (mii_info, PHY_BMCR, ctrl);
  170. }
  171. /* Enable and Restart Autonegotiation */
  172. static void genmii_restart_aneg (struct uec_mii_info *mii_info)
  173. {
  174. u16 ctl;
  175. ctl = phy_read (mii_info, PHY_BMCR);
  176. ctl |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG);
  177. phy_write (mii_info, PHY_BMCR, ctl);
  178. }
  179. static int gbit_config_aneg (struct uec_mii_info *mii_info)
  180. {
  181. u16 adv;
  182. u32 advertise;
  183. if (mii_info->autoneg) {
  184. /* Configure the ADVERTISE register */
  185. config_genmii_advert (mii_info);
  186. advertise = mii_info->advertising;
  187. adv = phy_read (mii_info, MII_1000BASETCONTROL);
  188. adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
  189. MII_1000BASETCONTROL_HALFDUPLEXCAP);
  190. if (advertise & SUPPORTED_1000baseT_Half)
  191. adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
  192. if (advertise & SUPPORTED_1000baseT_Full)
  193. adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
  194. phy_write (mii_info, MII_1000BASETCONTROL, adv);
  195. /* Start/Restart aneg */
  196. genmii_restart_aneg (mii_info);
  197. } else
  198. genmii_setup_forced (mii_info);
  199. return 0;
  200. }
  201. static int marvell_config_aneg (struct uec_mii_info *mii_info)
  202. {
  203. /* The Marvell PHY has an errata which requires
  204. * that certain registers get written in order
  205. * to restart autonegotiation */
  206. phy_write (mii_info, PHY_BMCR, PHY_BMCR_RESET);
  207. phy_write (mii_info, 0x1d, 0x1f);
  208. phy_write (mii_info, 0x1e, 0x200c);
  209. phy_write (mii_info, 0x1d, 0x5);
  210. phy_write (mii_info, 0x1e, 0);
  211. phy_write (mii_info, 0x1e, 0x100);
  212. gbit_config_aneg (mii_info);
  213. return 0;
  214. }
  215. static int genmii_config_aneg (struct uec_mii_info *mii_info)
  216. {
  217. if (mii_info->autoneg) {
  218. config_genmii_advert (mii_info);
  219. genmii_restart_aneg (mii_info);
  220. } else
  221. genmii_setup_forced (mii_info);
  222. return 0;
  223. }
  224. static int genmii_update_link (struct uec_mii_info *mii_info)
  225. {
  226. u16 status;
  227. /* Status is read once to clear old link state */
  228. phy_read (mii_info, PHY_BMSR);
  229. /*
  230. * Wait if the link is up, and autonegotiation is in progress
  231. * (ie - we're capable and it's not done)
  232. */
  233. status = phy_read(mii_info, PHY_BMSR);
  234. if ((status & PHY_BMSR_LS) && (status & PHY_BMSR_AUTN_ABLE)
  235. && !(status & PHY_BMSR_AUTN_COMP)) {
  236. int i = 0;
  237. while (!(status & PHY_BMSR_AUTN_COMP)) {
  238. /*
  239. * Timeout reached ?
  240. */
  241. if (i > UGETH_AN_TIMEOUT) {
  242. mii_info->link = 0;
  243. return 0;
  244. }
  245. i++;
  246. udelay(1000); /* 1 ms */
  247. status = phy_read(mii_info, PHY_BMSR);
  248. }
  249. mii_info->link = 1;
  250. udelay(500000); /* another 500 ms (results in faster booting) */
  251. } else {
  252. if (status & PHY_BMSR_LS)
  253. mii_info->link = 1;
  254. else
  255. mii_info->link = 0;
  256. }
  257. return 0;
  258. }
  259. static int genmii_read_status (struct uec_mii_info *mii_info)
  260. {
  261. u16 status;
  262. int err;
  263. /* Update the link, but return if there
  264. * was an error */
  265. err = genmii_update_link (mii_info);
  266. if (err)
  267. return err;
  268. if (mii_info->autoneg) {
  269. status = phy_read(mii_info, MII_1000BASETSTATUS);
  270. if (status & (LPA_1000FULL | LPA_1000HALF)) {
  271. mii_info->speed = SPEED_1000;
  272. if (status & LPA_1000FULL)
  273. mii_info->duplex = DUPLEX_FULL;
  274. else
  275. mii_info->duplex = DUPLEX_HALF;
  276. } else {
  277. status = phy_read(mii_info, PHY_ANLPAR);
  278. if (status & (PHY_ANLPAR_10FD | PHY_ANLPAR_TXFD))
  279. mii_info->duplex = DUPLEX_FULL;
  280. else
  281. mii_info->duplex = DUPLEX_HALF;
  282. if (status & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX))
  283. mii_info->speed = SPEED_100;
  284. else
  285. mii_info->speed = SPEED_10;
  286. }
  287. mii_info->pause = 0;
  288. }
  289. /* On non-aneg, we assume what we put in BMCR is the speed,
  290. * though magic-aneg shouldn't prevent this case from occurring
  291. */
  292. return 0;
  293. }
  294. static int bcm_init(struct uec_mii_info *mii_info)
  295. {
  296. struct eth_device *edev = mii_info->dev;
  297. uec_private_t *uec = edev->priv;
  298. gbit_config_aneg(mii_info);
  299. if (uec->uec_info->enet_interface == ENET_1000_RGMII_RXID) {
  300. u16 val;
  301. int cnt = 50;
  302. /* Wait for aneg to complete. */
  303. do
  304. val = phy_read(mii_info, PHY_BMSR);
  305. while (--cnt && !(val & PHY_BMSR_AUTN_COMP));
  306. /* Set RDX clk delay. */
  307. phy_write(mii_info, 0x18, 0x7 | (7 << 12));
  308. val = phy_read(mii_info, 0x18);
  309. /* Set RDX-RXC skew. */
  310. val |= (1 << 8);
  311. val |= (7 | (7 << 12));
  312. /* Write bits 14:0. */
  313. val |= (1 << 15);
  314. phy_write(mii_info, 0x18, val);
  315. }
  316. return 0;
  317. }
  318. static int marvell_init(struct uec_mii_info *mii_info)
  319. {
  320. struct eth_device *edev = mii_info->dev;
  321. uec_private_t *uec = edev->priv;
  322. if (uec->uec_info->enet_interface == ENET_1000_RGMII_ID) {
  323. int temp;
  324. temp = phy_read(mii_info, MII_M1111_PHY_EXT_CR);
  325. temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
  326. phy_write(mii_info, MII_M1111_PHY_EXT_CR, temp);
  327. temp = phy_read(mii_info, MII_M1111_PHY_EXT_SR);
  328. temp &= ~MII_M1111_HWCFG_MODE_MASK;
  329. temp |= MII_M1111_HWCFG_MODE_RGMII;
  330. phy_write(mii_info, MII_M1111_PHY_EXT_SR, temp);
  331. phy_write(mii_info, PHY_BMCR, PHY_BMCR_RESET);
  332. }
  333. return 0;
  334. }
  335. static int marvell_read_status (struct uec_mii_info *mii_info)
  336. {
  337. u16 status;
  338. int err;
  339. /* Update the link, but return if there
  340. * was an error */
  341. err = genmii_update_link (mii_info);
  342. if (err)
  343. return err;
  344. /* If the link is up, read the speed and duplex */
  345. /* If we aren't autonegotiating, assume speeds
  346. * are as set */
  347. if (mii_info->autoneg && mii_info->link) {
  348. int speed;
  349. status = phy_read (mii_info, MII_M1011_PHY_SPEC_STATUS);
  350. /* Get the duplexity */
  351. if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
  352. mii_info->duplex = DUPLEX_FULL;
  353. else
  354. mii_info->duplex = DUPLEX_HALF;
  355. /* Get the speed */
  356. speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK;
  357. switch (speed) {
  358. case MII_M1011_PHY_SPEC_STATUS_1000:
  359. mii_info->speed = SPEED_1000;
  360. break;
  361. case MII_M1011_PHY_SPEC_STATUS_100:
  362. mii_info->speed = SPEED_100;
  363. break;
  364. default:
  365. mii_info->speed = SPEED_10;
  366. break;
  367. }
  368. mii_info->pause = 0;
  369. }
  370. return 0;
  371. }
  372. static int marvell_ack_interrupt (struct uec_mii_info *mii_info)
  373. {
  374. /* Clear the interrupts by reading the reg */
  375. phy_read (mii_info, MII_M1011_IEVENT);
  376. return 0;
  377. }
  378. static int marvell_config_intr (struct uec_mii_info *mii_info)
  379. {
  380. if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
  381. phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
  382. else
  383. phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
  384. return 0;
  385. }
  386. static int dm9161_init (struct uec_mii_info *mii_info)
  387. {
  388. /* Reset the PHY */
  389. phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) |
  390. PHY_BMCR_RESET);
  391. /* PHY and MAC connect */
  392. phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) &
  393. ~PHY_BMCR_ISO);
  394. phy_write (mii_info, MII_DM9161_SCR, MII_DM9161_SCR_INIT);
  395. config_genmii_advert (mii_info);
  396. /* Start/restart aneg */
  397. genmii_config_aneg (mii_info);
  398. return 0;
  399. }
  400. static int dm9161_config_aneg (struct uec_mii_info *mii_info)
  401. {
  402. return 0;
  403. }
  404. static int dm9161_read_status (struct uec_mii_info *mii_info)
  405. {
  406. u16 status;
  407. int err;
  408. /* Update the link, but return if there was an error */
  409. err = genmii_update_link (mii_info);
  410. if (err)
  411. return err;
  412. /* If the link is up, read the speed and duplex
  413. If we aren't autonegotiating assume speeds are as set */
  414. if (mii_info->autoneg && mii_info->link) {
  415. status = phy_read (mii_info, MII_DM9161_SCSR);
  416. if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
  417. mii_info->speed = SPEED_100;
  418. else
  419. mii_info->speed = SPEED_10;
  420. if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F))
  421. mii_info->duplex = DUPLEX_FULL;
  422. else
  423. mii_info->duplex = DUPLEX_HALF;
  424. }
  425. return 0;
  426. }
  427. static int dm9161_ack_interrupt (struct uec_mii_info *mii_info)
  428. {
  429. /* Clear the interrupt by reading the reg */
  430. phy_read (mii_info, MII_DM9161_INTR);
  431. return 0;
  432. }
  433. static int dm9161_config_intr (struct uec_mii_info *mii_info)
  434. {
  435. if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
  436. phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);
  437. else
  438. phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);
  439. return 0;
  440. }
  441. static void dm9161_close (struct uec_mii_info *mii_info)
  442. {
  443. }
  444. static struct phy_info phy_info_dm9161 = {
  445. .phy_id = 0x0181b880,
  446. .phy_id_mask = 0x0ffffff0,
  447. .name = "Davicom DM9161E",
  448. .init = dm9161_init,
  449. .config_aneg = dm9161_config_aneg,
  450. .read_status = dm9161_read_status,
  451. .close = dm9161_close,
  452. };
  453. static struct phy_info phy_info_dm9161a = {
  454. .phy_id = 0x0181b8a0,
  455. .phy_id_mask = 0x0ffffff0,
  456. .name = "Davicom DM9161A",
  457. .features = MII_BASIC_FEATURES,
  458. .init = dm9161_init,
  459. .config_aneg = dm9161_config_aneg,
  460. .read_status = dm9161_read_status,
  461. .ack_interrupt = dm9161_ack_interrupt,
  462. .config_intr = dm9161_config_intr,
  463. .close = dm9161_close,
  464. };
  465. static struct phy_info phy_info_marvell = {
  466. .phy_id = 0x01410c00,
  467. .phy_id_mask = 0xffffff00,
  468. .name = "Marvell 88E11x1",
  469. .features = MII_GBIT_FEATURES,
  470. .init = &marvell_init,
  471. .config_aneg = &marvell_config_aneg,
  472. .read_status = &marvell_read_status,
  473. .ack_interrupt = &marvell_ack_interrupt,
  474. .config_intr = &marvell_config_intr,
  475. };
  476. static struct phy_info phy_info_bcm5481 = {
  477. .phy_id = 0x0143bca0,
  478. .phy_id_mask = 0xffffff0,
  479. .name = "Broadcom 5481",
  480. .features = MII_GBIT_FEATURES,
  481. .read_status = genmii_read_status,
  482. .init = bcm_init,
  483. };
  484. static struct phy_info phy_info_genmii = {
  485. .phy_id = 0x00000000,
  486. .phy_id_mask = 0x00000000,
  487. .name = "Generic MII",
  488. .features = MII_BASIC_FEATURES,
  489. .config_aneg = genmii_config_aneg,
  490. .read_status = genmii_read_status,
  491. };
  492. static struct phy_info *phy_info[] = {
  493. &phy_info_dm9161,
  494. &phy_info_dm9161a,
  495. &phy_info_marvell,
  496. &phy_info_bcm5481,
  497. &phy_info_genmii,
  498. NULL
  499. };
  500. u16 phy_read (struct uec_mii_info *mii_info, u16 regnum)
  501. {
  502. return mii_info->mdio_read (mii_info->dev, mii_info->mii_id, regnum);
  503. }
  504. void phy_write (struct uec_mii_info *mii_info, u16 regnum, u16 val)
  505. {
  506. mii_info->mdio_write (mii_info->dev, mii_info->mii_id, regnum, val);
  507. }
  508. /* Use the PHY ID registers to determine what type of PHY is attached
  509. * to device dev. return a struct phy_info structure describing that PHY
  510. */
  511. struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info)
  512. {
  513. u16 phy_reg;
  514. u32 phy_ID;
  515. int i;
  516. struct phy_info *theInfo = NULL;
  517. /* Grab the bits from PHYIR1, and put them in the upper half */
  518. phy_reg = phy_read (mii_info, PHY_PHYIDR1);
  519. phy_ID = (phy_reg & 0xffff) << 16;
  520. /* Grab the bits from PHYIR2, and put them in the lower half */
  521. phy_reg = phy_read (mii_info, PHY_PHYIDR2);
  522. phy_ID |= (phy_reg & 0xffff);
  523. /* loop through all the known PHY types, and find one that */
  524. /* matches the ID we read from the PHY. */
  525. for (i = 0; phy_info[i]; i++)
  526. if (phy_info[i]->phy_id ==
  527. (phy_ID & phy_info[i]->phy_id_mask)) {
  528. theInfo = phy_info[i];
  529. break;
  530. }
  531. /* This shouldn't happen, as we have generic PHY support */
  532. if (theInfo == NULL) {
  533. ugphy_info ("UEC: PHY id %x is not supported!", phy_ID);
  534. return NULL;
  535. } else {
  536. ugphy_info ("UEC: PHY is %s (%x)", theInfo->name, phy_ID);
  537. }
  538. return theInfo;
  539. }
  540. void marvell_phy_interface_mode (struct eth_device *dev,
  541. enet_interface_e mode)
  542. {
  543. uec_private_t *uec = (uec_private_t *) dev->priv;
  544. struct uec_mii_info *mii_info;
  545. u16 status;
  546. if (!uec->mii_info) {
  547. printf ("%s: the PHY not initialized\n", __FUNCTION__);
  548. return;
  549. }
  550. mii_info = uec->mii_info;
  551. if (mode == ENET_100_RGMII) {
  552. phy_write (mii_info, 0x00, 0x9140);
  553. phy_write (mii_info, 0x1d, 0x001f);
  554. phy_write (mii_info, 0x1e, 0x200c);
  555. phy_write (mii_info, 0x1d, 0x0005);
  556. phy_write (mii_info, 0x1e, 0x0000);
  557. phy_write (mii_info, 0x1e, 0x0100);
  558. phy_write (mii_info, 0x09, 0x0e00);
  559. phy_write (mii_info, 0x04, 0x01e1);
  560. phy_write (mii_info, 0x00, 0x9140);
  561. phy_write (mii_info, 0x00, 0x1000);
  562. udelay (100000);
  563. phy_write (mii_info, 0x00, 0x2900);
  564. phy_write (mii_info, 0x14, 0x0cd2);
  565. phy_write (mii_info, 0x00, 0xa100);
  566. phy_write (mii_info, 0x09, 0x0000);
  567. phy_write (mii_info, 0x1b, 0x800b);
  568. phy_write (mii_info, 0x04, 0x05e1);
  569. phy_write (mii_info, 0x00, 0xa100);
  570. phy_write (mii_info, 0x00, 0x2100);
  571. udelay (1000000);
  572. } else if (mode == ENET_10_RGMII) {
  573. phy_write (mii_info, 0x14, 0x8e40);
  574. phy_write (mii_info, 0x1b, 0x800b);
  575. phy_write (mii_info, 0x14, 0x0c82);
  576. phy_write (mii_info, 0x00, 0x8100);
  577. udelay (1000000);
  578. }
  579. /* handle 88e1111 rev.B2 erratum 5.6 */
  580. if (mii_info->autoneg) {
  581. status = phy_read (mii_info, PHY_BMCR);
  582. phy_write (mii_info, PHY_BMCR, status | PHY_BMCR_AUTON);
  583. }
  584. /* now the B2 will correctly report autoneg completion status */
  585. }
  586. void change_phy_interface_mode (struct eth_device *dev, enet_interface_e mode)
  587. {
  588. #ifdef CONFIG_PHY_MODE_NEED_CHANGE
  589. marvell_phy_interface_mode (dev, mode);
  590. #endif
  591. }