3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 #if (CONFIG_COMMANDS & CFG_CMD_NET) && \
33 (defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FEC1) || defined(CONFIG_ETHER_ON_FEC2))
35 /* compatibility test, if only FEC_ENET defined assume ETHER on FEC1 */
36 #if defined(FEC_ENET) && !defined(CONFIG_ETHER_ON_FEC1) && !defined(CONFIG_ETHER_ON_FEC2)
37 #define CONFIG_ETHER_ON_FEC1 1
40 /* define WANT_MII when MII support is required */
41 #if defined(CFG_DISCOVER_PHY) || defined(CONFIG_FEC1_PHY) || defined(CONFIG_FEC2_PHY)
51 #if defined(CONFIG_RMII) && !defined(WANT_MII)
52 #error RMII support is unusable without a working PHY.
55 #ifdef CFG_DISCOVER_PHY
56 static int mii_discover_phy(struct eth_device *dev);
59 static struct ether_fcc_info_s
68 #if defined(CONFIG_ETHER_ON_FEC1)
71 offsetof(immap_t, im_cpm.cp_fec1),
72 #if defined(CONFIG_FEC1_PHY)
82 #if defined(CONFIG_ETHER_ON_FEC2)
85 offsetof(immap_t, im_cpm.cp_fec2),
86 #if defined(CONFIG_FEC2_PHY)
97 /* Ethernet Transmit and Receive Buffers */
98 #define DBUF_LENGTH 1520
102 #define TOUT_LOOP 100
104 #define PKT_MAXBUF_SIZE 1518
105 #define PKT_MINBUF_SIZE 64
106 #define PKT_MAXBLR_SIZE 1520
109 static char txbuf[DBUF_LENGTH] __attribute__ ((aligned(8)));
111 #error txbuf must be aligned.
114 static uint rxIdx; /* index of the current RX buffer */
115 static uint txIdx; /* index of the current TX buffer */
118 * FEC Ethernet Tx and Rx buffer descriptors allocated at the
119 * immr->udata_bd address on Dual-Port RAM
120 * Provide for Double Buffering
123 typedef volatile struct CommonBufferDescriptor {
124 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
125 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
128 static RTXBD *rtx = NULL;
130 static int fec_send(struct eth_device* dev, volatile void *packet, int length);
131 static int fec_recv(struct eth_device* dev);
132 static int fec_init(struct eth_device* dev, bd_t * bd);
133 static void fec_halt(struct eth_device* dev);
135 int fec_initialize(bd_t *bis)
137 struct eth_device* dev;
138 struct ether_fcc_info_s *efis;
141 for (i = 0; i < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); i++) {
143 dev = malloc(sizeof(*dev));
147 memset(dev, 0, sizeof(*dev));
149 /* for FEC1 make sure that the name of the interface is the same
150 as the old one for compatibility reasons */
152 sprintf (dev->name, "FEC ETHERNET");
154 sprintf (dev->name, "FEC%d ETHERNET",
155 ether_fcc_info[i].ether_index + 1);
158 efis = ðer_fcc_info[i];
161 * reset actual phy addr
163 efis->actual_phy_addr = -1;
166 dev->init = fec_init;
167 dev->halt = fec_halt;
168 dev->send = fec_send;
169 dev->recv = fec_recv;
176 static int fec_send(struct eth_device* dev, volatile void *packet, int length)
179 struct ether_fcc_info_s *efis = dev->priv;
180 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
186 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
191 printf("TX not ready\n");
194 rtx->txbd[txIdx].cbd_bufaddr = (uint)packet;
195 rtx->txbd[txIdx].cbd_datlen = length;
196 rtx->txbd[txIdx].cbd_sc |= BD_ENET_TX_READY | BD_ENET_TX_LAST;
199 /* Activate transmit Buffer Descriptor polling */
200 fecp->fec_x_des_active = 0x01000000; /* Descriptor polling active */
203 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
204 #if defined(CONFIG_ICU862)
212 printf("TX timeout\n");
215 printf("%s[%d] %s: cycles: %d status: %x retry cnt: %d\n",
216 __FILE__,__LINE__,__FUNCTION__,j,rtx->txbd[txIdx].cbd_sc,
217 (rtx->txbd[txIdx].cbd_sc & 0x003C)>>2);
219 /* return only status bits */;
220 rc = (rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_STATS);
222 txIdx = (txIdx + 1) % TX_BUF_CNT;
227 static int fec_recv (struct eth_device *dev)
229 struct ether_fcc_info_s *efis = dev->priv;
230 volatile fec_t *fecp =
231 (volatile fec_t *) (CFG_IMMR + efis->fecp_offset);
235 /* section 16.9.23.2 */
236 if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
238 break; /* nothing received - leave for() loop */
241 length = rtx->rxbd[rxIdx].cbd_datlen;
243 if (rtx->rxbd[rxIdx].cbd_sc & 0x003f) {
245 printf ("%s[%d] err: %x\n",
246 __FUNCTION__, __LINE__,
247 rtx->rxbd[rxIdx].cbd_sc);
250 volatile uchar *rx = NetRxPackets[rxIdx];
254 #if (CONFIG_COMMANDS & CFG_CMD_CDP)
256 && memcmp ((uchar *) rx, NetBcastAddr, 6) != 0
257 && memcmp ((uchar *) rx, NetCDPAddr, 6) != 0)
261 * Pass the packet up to the protocol layers.
264 NetReceive (rx, length);
267 /* Give the buffer back to the FEC. */
268 rtx->rxbd[rxIdx].cbd_datlen = 0;
270 /* wrap around buffer index when necessary */
271 if ((rxIdx + 1) >= PKTBUFSRX) {
272 rtx->rxbd[PKTBUFSRX - 1].cbd_sc =
273 (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
276 rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
282 /* Try to fill Buffer Descriptors */
283 fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
289 /**************************************************************
291 * FEC Ethernet Initialization Routine
293 *************************************************************/
295 #define FEC_ECNTRL_PINMUX 0x00000004
296 #define FEC_ECNTRL_ETHER_EN 0x00000002
297 #define FEC_ECNTRL_RESET 0x00000001
299 #define FEC_RCNTRL_BC_REJ 0x00000010
300 #define FEC_RCNTRL_PROM 0x00000008
301 #define FEC_RCNTRL_MII_MODE 0x00000004
302 #define FEC_RCNTRL_DRT 0x00000002
303 #define FEC_RCNTRL_LOOP 0x00000001
305 #define FEC_TCNTRL_FDEN 0x00000004
306 #define FEC_TCNTRL_HBC 0x00000002
307 #define FEC_TCNTRL_GTS 0x00000001
309 #define FEC_RESET_DELAY 50
311 #if defined(CONFIG_RMII)
313 static inline void fec_10Mbps(struct eth_device *dev)
315 struct ether_fcc_info_s *efis = dev->priv;
316 int fecidx = efis->ether_index;
317 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
319 if ((unsigned int)fecidx >= 2)
322 ((volatile immap_t *)CFG_IMMR)->im_cpm.cp_cptr |= mask;
325 static inline void fec_100Mbps(struct eth_device *dev)
327 struct ether_fcc_info_s *efis = dev->priv;
328 int fecidx = efis->ether_index;
329 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
331 if ((unsigned int)fecidx >= 2)
334 ((volatile immap_t *)CFG_IMMR)->im_cpm.cp_cptr &= ~mask;
339 static inline void fec_full_duplex(struct eth_device *dev)
341 struct ether_fcc_info_s *efis = dev->priv;
342 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
344 fecp->fec_r_cntrl &= ~FEC_RCNTRL_DRT;
345 fecp->fec_x_cntrl |= FEC_TCNTRL_FDEN; /* FD enable */
348 static inline void fec_half_duplex(struct eth_device *dev)
350 struct ether_fcc_info_s *efis = dev->priv;
351 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
353 fecp->fec_r_cntrl |= FEC_RCNTRL_DRT;
354 fecp->fec_x_cntrl &= ~FEC_TCNTRL_FDEN; /* FD disable */
357 static void fec_pin_init(int fecidx)
359 DECLARE_GLOBAL_DATA_PTR;
361 volatile immap_t *immr = (immap_t *) CFG_IMMR;
362 volatile fec_t *fecp;
365 * only two FECs please
367 if ((unsigned int)fecidx >= 2)
371 fecp = &immr->im_cpm.cp_fec1;
373 fecp = &immr->im_cpm.cp_fec2;
376 * Set MII speed to 2.5 MHz or slightly below.
377 * * According to the MPC860T (Rev. D) Fast ethernet controller user
379 * * the MII management interface clock must be less than or equal
381 * * This MDC frequency is equal to system clock / (2 * MII_SPEED).
382 * * Then MII_SPEED = system_clock / 2 * 2,5 Mhz.
384 fecp->fec_mii_speed = ((bd->bi_intfreq + 4999999) / 5000000) << 1;
386 #if defined(CONFIG_NETTA) || defined(CONFIG_NETPHONE) || defined(CONFIG_NETTA2)
387 /* our PHYs are the limit at 2.5 MHz */
388 fecp->fec_mii_speed <<= 1;
391 #if defined(CONFIG_MPC885_FAMILY) && defined(WANT_MII)
392 /* use MDC for MII */
393 immr->im_ioport.iop_pdpar |= 0x0080;
394 immr->im_ioport.iop_pddir &= ~0x0080;
398 #if defined(CONFIG_ETHER_ON_FEC1)
400 #if defined(CONFIG_MPC885_FAMILY) /* MPC87x/88x have got 2 FECs and different pinout */
402 #if !defined(CONFIG_RMII)
404 immr->im_ioport.iop_papar |= 0xf830;
405 immr->im_ioport.iop_padir |= 0x0830;
406 immr->im_ioport.iop_padir &= ~0xf000;
408 immr->im_cpm.cp_pbpar |= 0x00001001;
409 immr->im_cpm.cp_pbdir &= ~0x00001001;
411 immr->im_ioport.iop_pcpar |= 0x000c;
412 immr->im_ioport.iop_pcdir &= ~0x000c;
414 immr->im_cpm.cp_pepar |= 0x00000003;
415 immr->im_cpm.cp_pedir |= 0x00000003;
416 immr->im_cpm.cp_peso &= ~0x00000003;
418 immr->im_cpm.cp_cptr &= ~0x00000100;
422 #if !defined(CONFIG_FEC1_PHY_NORXERR)
423 immr->im_ioport.iop_papar |= 0x1000;
424 immr->im_ioport.iop_padir &= ~0x1000;
426 immr->im_ioport.iop_papar |= 0xe810;
427 immr->im_ioport.iop_padir |= 0x0810;
428 immr->im_ioport.iop_padir &= ~0xe000;
430 immr->im_cpm.cp_pbpar |= 0x00000001;
431 immr->im_cpm.cp_pbdir &= ~0x00000001;
433 immr->im_cpm.cp_cptr |= 0x00000100;
434 immr->im_cpm.cp_cptr &= ~0x00000050;
436 #endif /* !CONFIG_RMII */
438 #elif !defined(CONFIG_ICU862) && !defined(CONFIG_IAD210)
440 * Configure all of port D for MII.
442 immr->im_ioport.iop_pdpar = 0x1fff;
445 * Bits moved from Rev. D onward
447 if ((get_immr(0) & 0xffff) < 0x0501)
448 immr->im_ioport.iop_pddir = 0x1c58; /* Pre rev. D */
450 immr->im_ioport.iop_pddir = 0x1fff; /* Rev. D and later */
453 * Configure port A for MII.
456 #if defined(CONFIG_ICU862) && defined(CFG_DISCOVER_PHY)
459 * On the ICU862 board the MII-MDC pin is routed to PD8 pin
460 * * of CPU, so for this board we need to configure Utopia and
461 * * enable PD8 to MII-MDC function
463 immr->im_ioport.iop_pdpar |= 0x4080;
467 * Has Utopia been configured?
469 if (immr->im_ioport.iop_pdpar & (0x8000 >> 1)) {
471 * YES - Use MUXED mode for UTOPIA bus.
472 * This frees Port A for use by MII (see 862UM table 41-6).
474 immr->im_ioport.utmode &= ~0x80;
477 * NO - set SPLIT mode for UTOPIA bus.
479 * This doesn't really effect UTOPIA (which isn't
480 * enabled anyway) but just tells the 862
481 * to use port A for MII (see 862UM table 41-6).
483 immr->im_ioport.utmode |= 0x80;
485 #endif /* !defined(CONFIG_ICU862) */
487 #endif /* CONFIG_ETHER_ON_FEC1 */
488 } else if (fecidx == 1) {
490 #if defined(CONFIG_ETHER_ON_FEC2)
492 #if defined(CONFIG_MPC885_FAMILY) /* MPC87x/88x have got 2 FECs and different pinout */
494 #if !defined(CONFIG_RMII)
496 #warning this configuration is not tested; please report if it works
497 immr->im_cpm.cp_pepar |= 0x0003fffc;
498 immr->im_cpm.cp_pedir |= 0x0003fffc;
499 immr->im_cpm.cp_peso &= ~0x000087fc;
500 immr->im_cpm.cp_peso |= 0x00037800;
502 immr->im_cpm.cp_cptr &= ~0x00000080;
505 #if !defined(CONFIG_FEC2_PHY_NORXERR)
506 immr->im_cpm.cp_pepar |= 0x00000010;
507 immr->im_cpm.cp_pedir |= 0x00000010;
508 immr->im_cpm.cp_peso &= ~0x00000010;
510 immr->im_cpm.cp_pepar |= 0x00039620;
511 immr->im_cpm.cp_pedir |= 0x00039620;
512 immr->im_cpm.cp_peso |= 0x00031000;
513 immr->im_cpm.cp_peso &= ~0x00008620;
515 immr->im_cpm.cp_cptr |= 0x00000080;
516 immr->im_cpm.cp_cptr &= ~0x00000028;
517 #endif /* CONFIG_RMII */
519 #endif /* CONFIG_MPC885_FAMILY */
521 #endif /* CONFIG_ETHER_ON_FEC2 */
526 static int fec_init (struct eth_device *dev, bd_t * bd)
528 struct ether_fcc_info_s *efis = dev->priv;
529 volatile immap_t *immr = (immap_t *) CFG_IMMR;
530 volatile fec_t *fecp =
531 (volatile fec_t *) (CFG_IMMR + efis->fecp_offset);
534 if (efis->ether_index == 0) {
535 #if defined(CONFIG_FADS) /* FADS family uses FPGA (BCSR) to control PHYs */
536 #if defined(CONFIG_MPC885ADS)
537 *(vu_char *) BCSR5 &= ~(BCSR5_MII1_EN | BCSR5_MII1_RST);
539 /* configure FADS for fast (FEC) ethernet, half-duplex */
540 /* The LXT970 needs about 50ms to recover from reset, so
541 * wait for it by discovering the PHY before leaving eth_init().
544 volatile uint *bcsr4 = (volatile uint *) BCSR4;
546 *bcsr4 = (*bcsr4 & ~(BCSR4_FETH_EN | BCSR4_FETHCFG1))
547 | (BCSR4_FETHCFG0 | BCSR4_FETHFDE |
550 /* reset the LXT970 PHY */
551 *bcsr4 &= ~BCSR4_FETHRST;
553 *bcsr4 |= BCSR4_FETHRST;
556 #endif /* CONFIG_MPC885ADS */
557 #endif /* CONFIG_FADS */
561 * A delay is required between a reset of the FEC block and
562 * initialization of other FEC registers because the reset takes
563 * some time to complete. If you don't delay, subsequent writes
564 * to FEC registers might get killed by the reset routine which is
567 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
569 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
573 if (i == FEC_RESET_DELAY) {
574 printf ("FEC_RESET_DELAY timeout\n");
578 /* We use strictly polling mode only
582 /* Clear any pending interrupt
584 fecp->fec_ievent = 0xffc0;
586 /* No need to set the IVEC register */
588 /* Set station address
590 #define ea eth_get_dev()->enetaddr
591 fecp->fec_addr_low = (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
592 fecp->fec_addr_high = (ea[4] << 8) | (ea[5]);
595 #if (CONFIG_COMMANDS & CFG_CMD_CDP)
597 * Turn on multicast address hash table
599 fecp->fec_hash_table_high = 0xffffffff;
600 fecp->fec_hash_table_low = 0xffffffff;
602 /* Clear multicast address hash table
604 fecp->fec_hash_table_high = 0;
605 fecp->fec_hash_table_low = 0;
608 /* Set maximum receive buffer size.
610 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
612 /* Set maximum frame length
614 fecp->fec_r_hash = PKT_MAXBUF_SIZE;
617 * Setup Buffers and Buffer Desriptors
623 #ifdef CFG_ALLOC_DPRAM
624 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem +
625 dpram_alloc_align (sizeof (RTXBD), 8));
627 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
631 * Setup Receiver Buffer Descriptors (13.14.24.18)
635 for (i = 0; i < PKTBUFSRX; i++) {
636 rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
637 rtx->rxbd[i].cbd_datlen = 0; /* Reset */
638 rtx->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
640 rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
643 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
647 for (i = 0; i < TX_BUF_CNT; i++) {
648 rtx->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
649 rtx->txbd[i].cbd_datlen = 0; /* Reset */
650 rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
652 rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
654 /* Set receive and transmit descriptor base
656 fecp->fec_r_des_start = (unsigned int) (&rtx->rxbd[0]);
657 fecp->fec_x_des_start = (unsigned int) (&rtx->txbd[0]);
661 #if 0 /* Full duplex mode */
662 fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE;
663 fecp->fec_x_cntrl = FEC_TCNTRL_FDEN;
664 #else /* Half duplex mode */
665 fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT;
666 fecp->fec_x_cntrl = 0;
669 /* Enable big endian and don't care about SDMA FC.
671 fecp->fec_fun_code = 0x78000000;
674 * Setup the pin configuration of the FEC
676 fec_pin_init (efis->ether_index);
682 * Now enable the transmit and receive processing
684 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
686 if (efis->phy_addr == -1) {
687 #ifdef CFG_DISCOVER_PHY
689 * wait for the PHY to wake up after reset
691 efis->actual_phy_addr = mii_discover_phy (dev);
693 if (efis->actual_phy_addr == -1) {
694 printf ("Unable to discover phy!\n");
698 efis->actual_phy_addr = -1;
701 efis->actual_phy_addr = efis->phy_addr;
703 #if defined(CONFIG_MII) && defined(CONFIG_RMII)
705 /* the MII interface is connected to FEC1
706 * so for the miiphy_xxx function to work we must
707 * call mii_init since fec_halt messes the thing up
709 if (efis->ether_index != 0)
713 * adapt the RMII speed to the speed of the phy
715 if (miiphy_speed (efis->actual_phy_addr) == _100BASET) {
722 #if defined(CONFIG_MII)
724 * adapt to the half/full speed settings
726 if (miiphy_duplex (efis->actual_phy_addr) == FULL) {
727 fec_full_duplex (dev);
729 fec_half_duplex (dev);
733 /* And last, try to fill Rx Buffer Descriptors */
734 fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
736 efis->initialized = 1;
742 static void fec_halt(struct eth_device* dev)
744 struct ether_fcc_info_s *efis = dev->priv;
745 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
748 /* avoid halt if initialized; mii gets stuck otherwise */
749 if (!efis->initialized)
753 * A delay is required between a reset of the FEC block and
754 * initialization of other FEC registers because the reset takes
755 * some time to complete. If you don't delay, subsequent writes
756 * to FEC registers might get killed by the reset routine which is
760 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
762 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
766 if (i == FEC_RESET_DELAY) {
767 printf ("FEC_RESET_DELAY timeout\n");
771 efis->initialized = 0;
774 #if defined(CFG_DISCOVER_PHY) || defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
776 /* Make MII read/write commands for the FEC.
779 #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
782 #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
783 (REG & 0x1f) << 18) | \
786 /* Interrupt events/masks.
788 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
789 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
790 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
791 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
792 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
793 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
794 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
795 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
796 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
797 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
799 /* PHY identification
801 #define PHY_ID_LXT970 0x78100000 /* LXT970 */
802 #define PHY_ID_LXT971 0x001378e0 /* LXT971 and 972 */
803 #define PHY_ID_82555 0x02a80150 /* Intel 82555 */
804 #define PHY_ID_QS6612 0x01814400 /* QS6612 */
805 #define PHY_ID_AMD79C784 0x00225610 /* AMD 79C784 */
806 #define PHY_ID_LSI80225 0x0016f870 /* LSI 80225 */
807 #define PHY_ID_LSI80225B 0x0016f880 /* LSI 80225/B */
808 #define PHY_ID_DM9161 0x0181B880 /* Davicom DM9161 */
810 /* send command to phy using mii, wait for result */
812 mii_send(uint mii_cmd)
818 ep = &(((immap_t *)CFG_IMMR)->im_cpm.cp_fec);
820 ep->fec_mii_data = mii_cmd; /* command to phy */
822 /* wait for mii complete */
824 while (!(ep->fec_ievent & FEC_ENET_MII)) {
826 printf("mii_send STUCK!\n");
830 mii_reply = ep->fec_mii_data; /* result from phy */
831 ep->fec_ievent = FEC_ENET_MII; /* clear MII complete */
833 printf("%s[%d] %s: sent=0x%8.8x, reply=0x%8.8x\n",
834 __FILE__,__LINE__,__FUNCTION__,mii_cmd,mii_reply);
836 return (mii_reply & 0xffff); /* data read from phy */
838 #endif /* CFG_DISCOVER_PHY || (CONFIG_COMMANDS & CFG_CMD_MII) */
840 #if defined(CFG_DISCOVER_PHY)
841 static int mii_discover_phy(struct eth_device *dev)
843 #define MAX_PHY_PASSES 11
849 phyaddr = -1; /* didn't find a PHY yet */
850 for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
852 /* PHY may need more time to recover from reset.
853 * The LXT970 needs 50ms typical, no maximum is
854 * specified, so wait 10ms before try again.
855 * With 11 passes this gives it 100ms to wake up.
857 udelay(10000); /* wait 10ms */
859 for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
860 phytype = mii_send(mk_mii_read(phyno, PHY_PHYIDR1));
862 printf("PHY type 0x%x pass %d type ", phytype, pass);
864 if (phytype != 0xffff) {
867 phytype |= mii_send(mk_mii_read(phyno,
871 printf("PHY @ 0x%x pass %d type ",phyno,pass);
872 switch (phytype & 0xfffffff0) {
885 case PHY_ID_AMD79C784:
886 printf("AMD79C784\n");
888 case PHY_ID_LSI80225B:
889 printf("LSI L80225/B\n");
892 printf("Davicom DM9161\n");
895 printf("0x%08x\n", phytype);
903 printf("No PHY device found.\n");
907 #endif /* CFG_DISCOVER_PHY */
909 #if (defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)) && !defined(CONFIG_BITBANGMII)
911 /****************************************************************************
912 * mii_init -- Initialize the MII for MII command without ethernet
913 * This function is a subset of eth_init
914 ****************************************************************************
918 volatile immap_t *immr = (immap_t *) CFG_IMMR;
919 volatile fec_t *fecp = &(immr->im_cpm.cp_fec);
922 for (j = 0; j < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); j++) {
925 * A delay is required between a reset of the FEC block and
926 * initialization of other FEC registers because the reset takes
927 * some time to complete. If you don't delay, subsequent writes
928 * to FEC registers might get killed by the reset routine which is
932 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
934 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
938 if (i == FEC_RESET_DELAY) {
939 printf ("FEC_RESET_DELAY timeout\n");
943 /* We use strictly polling mode only
947 /* Clear any pending interrupt
949 fecp->fec_ievent = 0xffc0;
951 /* Setup the pin configuration of the FEC(s)
953 fec_pin_init(ether_fcc_info[i].ether_index);
955 /* Now enable the transmit and receive processing
957 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
961 /*****************************************************************************
962 * Read and write a MII PHY register, routines used by MII Utilities
964 * FIXME: These routines are expected to return 0 on success, but mii_send
965 * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
966 * no PHY connected...
967 * For now always return 0.
968 * FIXME: These routines only work after calling eth_init() at least once!
969 * Otherwise they hang in mii_send() !!! Sorry!
970 *****************************************************************************/
972 int miiphy_read(unsigned char addr, unsigned char reg, unsigned short *value)
974 short rdreg; /* register working value */
977 printf ("miiphy_read(0x%x) @ 0x%x = ", reg, addr);
979 rdreg = mii_send(mk_mii_read(addr, reg));
983 printf ("0x%04x\n", *value);
988 int miiphy_write(unsigned char addr, unsigned char reg, unsigned short value)
990 short rdreg; /* register working value */
992 printf ("miiphy_write(0x%x) @ 0x%x = ", reg, addr);
994 rdreg = mii_send(mk_mii_write(addr, reg, value));
997 printf ("0x%04x\n", value);
1001 #endif /* (CONFIG_COMMANDS & CFG_CMD_MII) && !defined(CONFIG_BITBANGMII)*/
1003 #endif /* CFG_CMD_NET, FEC_ENET */