fec.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <malloc.h>
  25. #include <commproc.h>
  26. #include <net.h>
  27. #include <command.h>
  28. #undef ET_DEBUG
  29. #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(FEC_ENET)
  30. #ifdef CFG_DISCOVER_PHY
  31. #include <miiphy.h>
  32. static void mii_discover_phy(void);
  33. #endif
  34. /* Ethernet Transmit and Receive Buffers */
  35. #define DBUF_LENGTH 1520
  36. #define TX_BUF_CNT 2
  37. #define TOUT_LOOP 100
  38. #define PKT_MAXBUF_SIZE 1518
  39. #define PKT_MINBUF_SIZE 64
  40. #define PKT_MAXBLR_SIZE 1520
  41. static char txbuf[DBUF_LENGTH];
  42. static uint rxIdx; /* index of the current RX buffer */
  43. static uint txIdx; /* index of the current TX buffer */
  44. /*
  45. * FEC Ethernet Tx and Rx buffer descriptors allocated at the
  46. * immr->udata_bd address on Dual-Port RAM
  47. * Provide for Double Buffering
  48. */
  49. typedef volatile struct CommonBufferDescriptor {
  50. cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
  51. cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
  52. } RTXBD;
  53. static RTXBD *rtx = NULL;
  54. static int fec_send(struct eth_device* dev, volatile void *packet, int length);
  55. static int fec_recv(struct eth_device* dev);
  56. static int fec_init(struct eth_device* dev, bd_t * bd);
  57. static void fec_halt(struct eth_device* dev);
  58. int fec_initialize(bd_t *bis)
  59. {
  60. struct eth_device* dev;
  61. dev = (struct eth_device*) malloc(sizeof *dev);
  62. memset(dev, 0, sizeof *dev);
  63. sprintf(dev->name, "FEC ETHERNET");
  64. dev->iobase = 0;
  65. dev->priv = 0;
  66. dev->init = fec_init;
  67. dev->halt = fec_halt;
  68. dev->send = fec_send;
  69. dev->recv = fec_recv;
  70. eth_register(dev);
  71. return 1;
  72. }
  73. static int fec_send(struct eth_device* dev, volatile void *packet, int length)
  74. {
  75. int j, rc;
  76. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  77. volatile fec_t *fecp = &(immr->im_cpm.cp_fec);
  78. /* section 16.9.23.3
  79. * Wait for ready
  80. */
  81. j = 0;
  82. while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
  83. udelay(1);
  84. j++;
  85. }
  86. if (j>=TOUT_LOOP) {
  87. printf("TX not ready\n");
  88. }
  89. rtx->txbd[txIdx].cbd_bufaddr = (uint)packet;
  90. rtx->txbd[txIdx].cbd_datlen = length;
  91. rtx->txbd[txIdx].cbd_sc |= BD_ENET_TX_READY | BD_ENET_TX_LAST;
  92. __asm__ ("eieio");
  93. /* Activate transmit Buffer Descriptor polling */
  94. fecp->fec_x_des_active = 0x01000000; /* Descriptor polling active */
  95. j = 0;
  96. while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
  97. #if defined(CONFIG_ICU862)
  98. udelay(10);
  99. #else
  100. udelay(1);
  101. #endif
  102. j++;
  103. }
  104. if (j>=TOUT_LOOP) {
  105. printf("TX timeout\n");
  106. }
  107. #ifdef ET_DEBUG
  108. printf("%s[%d] %s: cycles: %d status: %x retry cnt: %d\n",
  109. __FILE__,__LINE__,__FUNCTION__,j,rtx->txbd[txIdx].cbd_sc,
  110. (rtx->txbd[txIdx].cbd_sc & 0x003C)>>2);
  111. #endif
  112. /* return only status bits */;
  113. rc = (rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_STATS);
  114. txIdx = (txIdx + 1) % TX_BUF_CNT;
  115. return rc;
  116. }
  117. static int fec_recv(struct eth_device* dev)
  118. {
  119. int length;
  120. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  121. volatile fec_t *fecp = &(immr->im_cpm.cp_fec);
  122. for (;;) {
  123. /* section 16.9.23.2 */
  124. if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
  125. length = -1;
  126. break; /* nothing received - leave for() loop */
  127. }
  128. length = rtx->rxbd[rxIdx].cbd_datlen;
  129. if (rtx->rxbd[rxIdx].cbd_sc & 0x003f) {
  130. #ifdef ET_DEBUG
  131. printf("%s[%d] err: %x\n",
  132. __FUNCTION__,__LINE__,rtx->rxbd[rxIdx].cbd_sc);
  133. #endif
  134. } else {
  135. /* Pass the packet up to the protocol layers. */
  136. NetReceive(NetRxPackets[rxIdx], length - 4);
  137. }
  138. /* Give the buffer back to the FEC. */
  139. rtx->rxbd[rxIdx].cbd_datlen = 0;
  140. /* wrap around buffer index when necessary */
  141. if ((rxIdx + 1) >= PKTBUFSRX) {
  142. rtx->rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
  143. rxIdx = 0;
  144. } else {
  145. rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
  146. rxIdx++;
  147. }
  148. __asm__ ("eieio");
  149. /* Try to fill Buffer Descriptors */
  150. fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
  151. }
  152. return length;
  153. }
  154. /**************************************************************
  155. *
  156. * FEC Ethernet Initialization Routine
  157. *
  158. *************************************************************/
  159. #define FEC_ECNTRL_PINMUX 0x00000004
  160. #define FEC_ECNTRL_ETHER_EN 0x00000002
  161. #define FEC_ECNTRL_RESET 0x00000001
  162. #define FEC_RCNTRL_BC_REJ 0x00000010
  163. #define FEC_RCNTRL_PROM 0x00000008
  164. #define FEC_RCNTRL_MII_MODE 0x00000004
  165. #define FEC_RCNTRL_DRT 0x00000002
  166. #define FEC_RCNTRL_LOOP 0x00000001
  167. #define FEC_TCNTRL_FDEN 0x00000004
  168. #define FEC_TCNTRL_HBC 0x00000002
  169. #define FEC_TCNTRL_GTS 0x00000001
  170. #define FEC_RESET_DELAY 50
  171. static int fec_init(struct eth_device* dev, bd_t * bd)
  172. {
  173. int i;
  174. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  175. volatile fec_t *fecp = &(immr->im_cpm.cp_fec);
  176. #if defined(CONFIG_FADS) /* FADS family uses FPGA (BCSR) to control PHYs */
  177. #if defined(CONFIG_DUET_ADS)
  178. *(vu_char *)BCSR5 &= ~(BCSR5_MII1_EN | BCSR5_MII1_RST);
  179. #else
  180. /* configure FADS for fast (FEC) ethernet, half-duplex */
  181. /* The LXT970 needs about 50ms to recover from reset, so
  182. * wait for it by discovering the PHY before leaving eth_init().
  183. */
  184. {
  185. volatile uint *bcsr4 = (volatile uint *) BCSR4;
  186. *bcsr4 = (*bcsr4 & ~(BCSR4_FETH_EN | BCSR4_FETHCFG1))
  187. | (BCSR4_FETHCFG0 | BCSR4_FETHFDE | BCSR4_FETHRST);
  188. /* reset the LXT970 PHY */
  189. *bcsr4 &= ~BCSR4_FETHRST;
  190. udelay (10);
  191. *bcsr4 |= BCSR4_FETHRST;
  192. udelay (10);
  193. }
  194. #endif /* CONFIG_DUET_ADS */
  195. #endif /* CONFIG_FADS */
  196. /* Whack a reset.
  197. * A delay is required between a reset of the FEC block and
  198. * initialization of other FEC registers because the reset takes
  199. * some time to complete. If you don't delay, subsequent writes
  200. * to FEC registers might get killed by the reset routine which is
  201. * still in progress.
  202. */
  203. fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
  204. for (i = 0;
  205. (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
  206. ++i) {
  207. udelay (1);
  208. }
  209. if (i == FEC_RESET_DELAY) {
  210. printf ("FEC_RESET_DELAY timeout\n");
  211. return 0;
  212. }
  213. /* We use strictly polling mode only
  214. */
  215. fecp->fec_imask = 0;
  216. /* Clear any pending interrupt
  217. */
  218. fecp->fec_ievent = 0xffc0;
  219. /* No need to set the IVEC register */
  220. /* Set station address
  221. */
  222. #define ea eth_get_dev()->enetaddr
  223. fecp->fec_addr_low = (ea[0] << 24) | (ea[1] << 16) |
  224. (ea[2] << 8) | (ea[3] ) ;
  225. fecp->fec_addr_high = (ea[4] << 8) | (ea[5] ) ;
  226. #undef ea
  227. /* Clear multicast address hash table
  228. */
  229. fecp->fec_hash_table_high = 0;
  230. fecp->fec_hash_table_low = 0;
  231. /* Set maximum receive buffer size.
  232. */
  233. fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
  234. /* Set maximum frame length
  235. */
  236. fecp->fec_r_hash = PKT_MAXBUF_SIZE;
  237. /*
  238. * Setup Buffers and Buffer Desriptors
  239. */
  240. rxIdx = 0;
  241. txIdx = 0;
  242. if (!rtx) {
  243. #ifdef CFG_ALLOC_DPRAM
  244. rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + dpram_alloc_align(sizeof(RTXBD),8));
  245. #else
  246. rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
  247. #endif
  248. }
  249. /*
  250. * Setup Receiver Buffer Descriptors (13.14.24.18)
  251. * Settings:
  252. * Empty, Wrap
  253. */
  254. for (i = 0; i < PKTBUFSRX; i++) {
  255. rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
  256. rtx->rxbd[i].cbd_datlen = 0; /* Reset */
  257. rtx->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
  258. }
  259. rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
  260. /*
  261. * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
  262. * Settings:
  263. * Last, Tx CRC
  264. */
  265. for (i = 0; i < TX_BUF_CNT; i++) {
  266. rtx->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
  267. rtx->txbd[i].cbd_datlen = 0; /* Reset */
  268. rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
  269. }
  270. rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
  271. /* Set receive and transmit descriptor base
  272. */
  273. fecp->fec_r_des_start = (unsigned int) (&rtx->rxbd[0]);
  274. fecp->fec_x_des_start = (unsigned int) (&rtx->txbd[0]);
  275. /* Enable MII mode
  276. */
  277. #if 0 /* Full duplex mode */
  278. fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE;
  279. fecp->fec_x_cntrl = FEC_TCNTRL_FDEN;
  280. #else /* Half duplex mode */
  281. fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT;
  282. fecp->fec_x_cntrl = 0;
  283. #endif
  284. /* Enable big endian and don't care about SDMA FC.
  285. */
  286. fecp->fec_fun_code = 0x78000000;
  287. /* Set MII speed to 2.5 MHz or slightly below.
  288. * According to the MPC860T (Rev. D) Fast ethernet controller user
  289. * manual (6.2.14),
  290. * the MII management interface clock must be less than or equal
  291. * to 2.5 MHz.
  292. * This MDC frequency is equal to system clock / (2 * MII_SPEED).
  293. * Then MII_SPEED = system_clock / 2 * 2,5 Mhz.
  294. */
  295. fecp->fec_mii_speed = ((bd->bi_intfreq + 4999999) / 5000000) << 1;
  296. #if defined(CONFIG_DUET) /* MPC87x/88x have got 2 FECs and different pinout */
  297. immr->im_ioport.iop_papar |= 0xf830;
  298. immr->im_ioport.iop_padir |= 0x0830;
  299. immr->im_ioport.iop_padir &= ~0xf000;
  300. immr->im_cpm.cp_pbpar |= 0x00001001;
  301. immr->im_cpm.cp_pbdir &= ~0x00001001;
  302. immr->im_ioport.iop_pcpar |= 0x000c;
  303. immr->im_ioport.iop_pcdir &= ~0x000c;
  304. immr->im_ioport.iop_pdpar |= 0x0080;
  305. immr->im_ioport.iop_pddir &= ~0x0080;
  306. immr->im_cpm.cp_pepar |= 0x00000003;
  307. immr->im_cpm.cp_pedir |= 0x00000003;
  308. immr->im_cpm.cp_peso &= ~0x00000003;
  309. #elif !defined(CONFIG_ICU862) && !defined(CONFIG_IAD210)
  310. /* Configure all of port D for MII.
  311. */
  312. immr->im_ioport.iop_pdpar = 0x1fff;
  313. /* Bits moved from Rev. D onward */
  314. if ((get_immr (0) & 0xffff) < 0x0501) {
  315. immr->im_ioport.iop_pddir = 0x1c58; /* Pre rev. D */
  316. } else {
  317. immr->im_ioport.iop_pddir = 0x1fff; /* Rev. D and later */
  318. }
  319. #else
  320. /* Configure port A for MII.
  321. */
  322. #if defined(CONFIG_ICU862) && defined(CFG_DISCOVER_PHY)
  323. /* On the ICU862 board the MII-MDC pin is routed to PD8 pin
  324. * of CPU, so for this board we need to configure Utopia and
  325. * enable PD8 to MII-MDC function */
  326. immr->im_ioport.iop_pdpar |= 0x4080;
  327. #endif
  328. /* Has Utopia been configured? */
  329. if (immr->im_ioport.iop_pdpar & (0x8000 >> 1)) {
  330. /*
  331. * YES - Use MUXED mode for UTOPIA bus.
  332. * This frees Port A for use by MII (see 862UM table 41-6).
  333. */
  334. immr->im_ioport.utmode &= ~0x80;
  335. } else {
  336. /*
  337. * NO - set SPLIT mode for UTOPIA bus.
  338. *
  339. * This doesn't really effect UTOPIA (which isn't
  340. * enabled anyway) but just tells the 862
  341. * to use port A for MII (see 862UM table 41-6).
  342. */
  343. immr->im_ioport.utmode |= 0x80;
  344. }
  345. #endif /* !defined(CONFIG_ICU862) */
  346. rxIdx = 0;
  347. txIdx = 0;
  348. /* Now enable the transmit and receive processing
  349. */
  350. fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
  351. #ifdef CFG_DISCOVER_PHY
  352. /* wait for the PHY to wake up after reset
  353. */
  354. mii_discover_phy();
  355. #endif
  356. /* And last, try to fill Rx Buffer Descriptors */
  357. fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
  358. return 1;
  359. }
  360. static void fec_halt(struct eth_device* dev)
  361. {
  362. #if 0
  363. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  364. immr->im_cpm.cp_scc[SCC_ENET].scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  365. #endif
  366. }
  367. #if 0
  368. void restart(void)
  369. {
  370. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  371. immr->im_cpm.cp_scc[SCC_ENET].scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  372. }
  373. #endif
  374. #if defined(CFG_DISCOVER_PHY) || (CONFIG_COMMANDS & CFG_CMD_MII)
  375. static int phyaddr = -1; /* didn't find a PHY yet */
  376. static uint phytype;
  377. /* Make MII read/write commands for the FEC.
  378. */
  379. #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
  380. (REG & 0x1f) << 18))
  381. #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
  382. (REG & 0x1f) << 18) | \
  383. (VAL & 0xffff))
  384. /* Interrupt events/masks.
  385. */
  386. #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
  387. #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
  388. #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
  389. #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
  390. #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
  391. #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
  392. #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
  393. #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
  394. #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
  395. #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
  396. /* PHY identification
  397. */
  398. #define PHY_ID_LXT970 0x78100000 /* LXT970 */
  399. #define PHY_ID_LXT971 0x001378e0 /* LXT971 and 972 */
  400. #define PHY_ID_82555 0x02a80150 /* Intel 82555 */
  401. #define PHY_ID_QS6612 0x01814400 /* QS6612 */
  402. #define PHY_ID_AMD79C784 0x00225610 /* AMD 79C784 */
  403. #define PHY_ID_LSI80225 0x0016f870 /* LSI 80225 */
  404. #define PHY_ID_LSI80225B 0x0016f880 /* LSI 80225/B */
  405. #define PHY_ID_DM9161 0x0181B880 /* Davicom DM9161 */
  406. /* send command to phy using mii, wait for result */
  407. static uint
  408. mii_send(uint mii_cmd)
  409. {
  410. uint mii_reply;
  411. volatile fec_t *ep;
  412. ep = &(((immap_t *)CFG_IMMR)->im_cpm.cp_fec);
  413. ep->fec_mii_data = mii_cmd; /* command to phy */
  414. /* wait for mii complete */
  415. while (!(ep->fec_ievent & FEC_ENET_MII))
  416. ; /* spin until done */
  417. mii_reply = ep->fec_mii_data; /* result from phy */
  418. ep->fec_ievent = FEC_ENET_MII; /* clear MII complete */
  419. #if 0
  420. printf("%s[%d] %s: sent=0x%8.8x, reply=0x%8.8x\n",
  421. __FILE__,__LINE__,__FUNCTION__,mii_cmd,mii_reply);
  422. #endif
  423. return (mii_reply & 0xffff); /* data read from phy */
  424. }
  425. #endif /* CFG_DISCOVER_PHY || (CONFIG_COMMANDS & CFG_CMD_MII) */
  426. #if defined(CFG_DISCOVER_PHY)
  427. static void
  428. mii_discover_phy(void)
  429. {
  430. #define MAX_PHY_PASSES 11
  431. uint phyno;
  432. int pass;
  433. phyaddr = -1; /* didn't find a PHY yet */
  434. for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
  435. if (pass > 1) {
  436. /* PHY may need more time to recover from reset.
  437. * The LXT970 needs 50ms typical, no maximum is
  438. * specified, so wait 10ms before try again.
  439. * With 11 passes this gives it 100ms to wake up.
  440. */
  441. udelay(10000); /* wait 10ms */
  442. }
  443. for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
  444. phytype = mii_send(mk_mii_read(phyno, PHY_PHYIDR1));
  445. #ifdef ET_DEBUG
  446. printf("PHY type 0x%x pass %d type ", phytype, pass);
  447. #endif
  448. if (phytype != 0xffff) {
  449. phyaddr = phyno;
  450. phytype <<= 16;
  451. phytype |= mii_send(mk_mii_read(phyno,
  452. PHY_PHYIDR2));
  453. #ifdef ET_DEBUG
  454. printf("PHY @ 0x%x pass %d type ",phyno,pass);
  455. switch (phytype & 0xfffffff0) {
  456. case PHY_ID_LXT970:
  457. printf("LXT970\n");
  458. break;
  459. case PHY_ID_LXT971:
  460. printf("LXT971\n");
  461. break;
  462. case PHY_ID_82555:
  463. printf("82555\n");
  464. break;
  465. case PHY_ID_QS6612:
  466. printf("QS6612\n");
  467. break;
  468. case PHY_ID_AMD79C784:
  469. printf("AMD79C784\n");
  470. break;
  471. case PHY_ID_LSI80225B:
  472. printf("LSI L80225/B\n");
  473. break;
  474. case PHY_ID_DM9161:
  475. printf("Davicom DM9161\n");
  476. break;
  477. default:
  478. printf("0x%08x\n", phytype);
  479. break;
  480. }
  481. #endif
  482. }
  483. }
  484. }
  485. if (phyaddr < 0) {
  486. printf("No PHY device found.\n");
  487. }
  488. }
  489. #endif /* CFG_DISCOVER_PHY */
  490. #if (CONFIG_COMMANDS & CFG_CMD_MII) && !defined(CONFIG_BITBANGMII)
  491. static int mii_init_done = 0;
  492. /****************************************************************************
  493. * mii_init -- Initialize the MII for MII command without ethernet
  494. * This function is a subset of eth_init
  495. ****************************************************************************
  496. */
  497. void mii_init (void)
  498. {
  499. DECLARE_GLOBAL_DATA_PTR;
  500. bd_t *bd = gd->bd;
  501. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  502. volatile fec_t *fecp = &(immr->im_cpm.cp_fec);
  503. int i;
  504. if (mii_init_done != 0) {
  505. return;
  506. }
  507. /* Whack a reset.
  508. * A delay is required between a reset of the FEC block and
  509. * initialization of other FEC registers because the reset takes
  510. * some time to complete. If you don't delay, subsequent writes
  511. * to FEC registers might get killed by the reset routine which is
  512. * still in progress.
  513. */
  514. fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
  515. for (i = 0;
  516. (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
  517. ++i) {
  518. udelay (1);
  519. }
  520. if (i == FEC_RESET_DELAY) {
  521. printf ("FEC_RESET_DELAY timeout\n");
  522. return;
  523. }
  524. /* We use strictly polling mode only
  525. */
  526. fecp->fec_imask = 0;
  527. /* Clear any pending interrupt
  528. */
  529. fecp->fec_ievent = 0xffc0;
  530. /* Set MII speed to 2.5 MHz or slightly below.
  531. * According to the MPC860T (Rev. D) Fast ethernet controller user
  532. * manual (6.2.14),
  533. * the MII management interface clock must be less than or equal
  534. * to 2.5 MHz.
  535. * This MDC frequency is equal to system clock / (2 * MII_SPEED).
  536. * Then MII_SPEED = system_clock / 2 * 2,5 Mhz.
  537. */
  538. fecp->fec_mii_speed = ((bd->bi_intfreq + 4999999) / 5000000) << 1;
  539. #if defined(CONFIG_DUET) /* MPC87x/88x have got 2 FECs and different pinout */
  540. immr->im_ioport.iop_papar |= 0xf830;
  541. immr->im_ioport.iop_padir |= 0x0830;
  542. immr->im_ioport.iop_padir &= ~0xf000;
  543. immr->im_cpm.cp_pbpar |= 0x00001001;
  544. immr->im_cpm.cp_pbdir &= ~0x00001001;
  545. immr->im_ioport.iop_pcpar |= 0x000c;
  546. immr->im_ioport.iop_pcdir &= ~0x000c;
  547. immr->im_ioport.iop_pdpar |= 0x0080;
  548. immr->im_ioport.iop_pddir &= ~0x0080;
  549. immr->im_cpm.cp_pepar |= 0x00000003;
  550. immr->im_cpm.cp_pedir |= 0x00000003;
  551. immr->im_cpm.cp_peso &= ~0x00000003;
  552. #elif !defined(CONFIG_ICU862) && !defined(CONFIG_IAD210)
  553. /* Configure all of port D for MII.
  554. */
  555. immr->im_ioport.iop_pdpar = 0x1fff;
  556. /* Bits moved from Rev. D onward */
  557. if ((get_immr (0) & 0xffff) < 0x0501) {
  558. immr->im_ioport.iop_pddir = 0x1c58; /* Pre rev. D */
  559. } else {
  560. immr->im_ioport.iop_pddir = 0x1fff; /* Rev. D and later */
  561. }
  562. #else
  563. /* Configure port A for MII.
  564. */
  565. #if defined(CONFIG_ICU862)
  566. /* On the ICU862 board the MII-MDC pin is routed to PD8 pin
  567. * of CPU, so for this board we need to configure Utopia and
  568. * enable PD8 to MII-MDC function */
  569. immr->im_ioport.iop_pdpar |= 0x4080;
  570. #endif
  571. /* Has Utopia been configured? */
  572. if (immr->im_ioport.iop_pdpar & (0x8000 >> 1)) {
  573. /*
  574. * YES - Use MUXED mode for UTOPIA bus.
  575. * This frees Port A for use by MII (see 862UM table 41-6).
  576. */
  577. immr->im_ioport.utmode &= ~0x80;
  578. } else {
  579. /*
  580. * NO - set SPLIT mode for UTOPIA bus.
  581. *
  582. * This doesn't really effect UTOPIA (which isn't
  583. * enabled anyway) but just tells the 862
  584. * to use port A for MII (see 862UM table 41-6).
  585. */
  586. immr->im_ioport.utmode |= 0x80;
  587. }
  588. #endif /* !defined(CONFIG_ICU862) */
  589. /* Now enable the transmit and receive processing
  590. */
  591. fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
  592. mii_init_done = 1;
  593. }
  594. /*****************************************************************************
  595. * Read and write a MII PHY register, routines used by MII Utilities
  596. *
  597. * FIXME: These routines are expected to return 0 on success, but mii_send
  598. * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
  599. * no PHY connected...
  600. * For now always return 0.
  601. * FIXME: These routines only work after calling eth_init() at least once!
  602. * Otherwise they hang in mii_send() !!! Sorry!
  603. *****************************************************************************/
  604. int miiphy_read(unsigned char addr, unsigned char reg, unsigned short *value)
  605. {
  606. short rdreg; /* register working value */
  607. #ifdef MII_DEBUG
  608. printf ("miiphy_read(0x%x) @ 0x%x = ", reg, addr);
  609. #endif
  610. rdreg = mii_send(mk_mii_read(addr, reg));
  611. *value = rdreg;
  612. #ifdef MII_DEBUG
  613. printf ("0x%04x\n", *value);
  614. #endif
  615. return 0;
  616. }
  617. int miiphy_write(unsigned char addr, unsigned char reg, unsigned short value)
  618. {
  619. short rdreg; /* register working value */
  620. #ifdef MII_DEBUG
  621. printf ("miiphy_write(0x%x) @ 0x%x = ", reg, addr);
  622. #endif
  623. rdreg = mii_send(mk_mii_write(addr, reg, value));
  624. #ifdef MII_DEBUG
  625. printf ("0x%04x\n", value);
  626. #endif
  627. return 0;
  628. }
  629. #endif /* (CONFIG_COMMANDS & CFG_CMD_MII) && !defined(CONFIG_BITBANGMII)*/
  630. #endif /* CFG_CMD_NET, FEC_ENET */