uec_phy.c 20 KB

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