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)
50 #if !(defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII))
51 #error "CONFIG_MII has to be defined!"
56 #if defined(CONFIG_RMII) && !defined(WANT_MII)
57 #error RMII support is unusable without a working PHY.
60 #ifdef CFG_DISCOVER_PHY
61 static int mii_discover_phy(struct eth_device *dev);
64 int fec8xx_miiphy_read(char *devname, unsigned char addr,
65 unsigned char reg, unsigned short *value);
66 int fec8xx_miiphy_write(char *devname, unsigned char addr,
67 unsigned char reg, unsigned short value);
69 static struct ether_fcc_info_s
78 #if defined(CONFIG_ETHER_ON_FEC1)
81 offsetof(immap_t, im_cpm.cp_fec1),
82 #if defined(CONFIG_FEC1_PHY)
92 #if defined(CONFIG_ETHER_ON_FEC2)
95 offsetof(immap_t, im_cpm.cp_fec2),
96 #if defined(CONFIG_FEC2_PHY)
107 /* Ethernet Transmit and Receive Buffers */
108 #define DBUF_LENGTH 1520
112 #define TOUT_LOOP 100
114 #define PKT_MAXBUF_SIZE 1518
115 #define PKT_MINBUF_SIZE 64
116 #define PKT_MAXBLR_SIZE 1520
119 static char txbuf[DBUF_LENGTH] __attribute__ ((aligned(8)));
121 #error txbuf must be aligned.
124 static uint rxIdx; /* index of the current RX buffer */
125 static uint txIdx; /* index of the current TX buffer */
128 * FEC Ethernet Tx and Rx buffer descriptors allocated at the
129 * immr->udata_bd address on Dual-Port RAM
130 * Provide for Double Buffering
133 typedef volatile struct CommonBufferDescriptor {
134 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
135 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
138 static RTXBD *rtx = NULL;
140 static int fec_send(struct eth_device* dev, volatile void *packet, int length);
141 static int fec_recv(struct eth_device* dev);
142 static int fec_init(struct eth_device* dev, bd_t * bd);
143 static void fec_halt(struct eth_device* dev);
145 int fec_initialize(bd_t *bis)
147 struct eth_device* dev;
148 struct ether_fcc_info_s *efis;
151 for (i = 0; i < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); i++) {
153 dev = malloc(sizeof(*dev));
157 memset(dev, 0, sizeof(*dev));
159 /* for FEC1 make sure that the name of the interface is the same
160 as the old one for compatibility reasons */
162 sprintf (dev->name, "FEC ETHERNET");
164 sprintf (dev->name, "FEC%d ETHERNET",
165 ether_fcc_info[i].ether_index + 1);
168 efis = ðer_fcc_info[i];
171 * reset actual phy addr
173 efis->actual_phy_addr = -1;
176 dev->init = fec_init;
177 dev->halt = fec_halt;
178 dev->send = fec_send;
179 dev->recv = fec_recv;
183 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
184 miiphy_register(dev->name,
185 fec8xx_miiphy_read, fec8xx_miiphy_write);
191 static int fec_send(struct eth_device* dev, volatile void *packet, int length)
194 struct ether_fcc_info_s *efis = dev->priv;
195 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
201 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
206 printf("TX not ready\n");
209 rtx->txbd[txIdx].cbd_bufaddr = (uint)packet;
210 rtx->txbd[txIdx].cbd_datlen = length;
211 rtx->txbd[txIdx].cbd_sc |= BD_ENET_TX_READY | BD_ENET_TX_LAST;
214 /* Activate transmit Buffer Descriptor polling */
215 fecp->fec_x_des_active = 0x01000000; /* Descriptor polling active */
218 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
219 #if defined(CONFIG_ICU862)
227 printf("TX timeout\n");
230 printf("%s[%d] %s: cycles: %d status: %x retry cnt: %d\n",
231 __FILE__,__LINE__,__FUNCTION__,j,rtx->txbd[txIdx].cbd_sc,
232 (rtx->txbd[txIdx].cbd_sc & 0x003C)>>2);
234 /* return only status bits */;
235 rc = (rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_STATS);
237 txIdx = (txIdx + 1) % TX_BUF_CNT;
242 static int fec_recv (struct eth_device *dev)
244 struct ether_fcc_info_s *efis = dev->priv;
245 volatile fec_t *fecp =
246 (volatile fec_t *) (CFG_IMMR + efis->fecp_offset);
250 /* section 16.9.23.2 */
251 if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
253 break; /* nothing received - leave for() loop */
256 length = rtx->rxbd[rxIdx].cbd_datlen;
258 if (rtx->rxbd[rxIdx].cbd_sc & 0x003f) {
260 printf ("%s[%d] err: %x\n",
261 __FUNCTION__, __LINE__,
262 rtx->rxbd[rxIdx].cbd_sc);
265 volatile uchar *rx = NetRxPackets[rxIdx];
269 #if (CONFIG_COMMANDS & CFG_CMD_CDP)
271 && memcmp ((uchar *) rx, NetBcastAddr, 6) != 0
272 && memcmp ((uchar *) rx, NetCDPAddr, 6) != 0)
276 * Pass the packet up to the protocol layers.
279 NetReceive (rx, length);
282 /* Give the buffer back to the FEC. */
283 rtx->rxbd[rxIdx].cbd_datlen = 0;
285 /* wrap around buffer index when necessary */
286 if ((rxIdx + 1) >= PKTBUFSRX) {
287 rtx->rxbd[PKTBUFSRX - 1].cbd_sc =
288 (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
291 rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
297 /* Try to fill Buffer Descriptors */
298 fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
304 /**************************************************************
306 * FEC Ethernet Initialization Routine
308 *************************************************************/
310 #define FEC_ECNTRL_PINMUX 0x00000004
311 #define FEC_ECNTRL_ETHER_EN 0x00000002
312 #define FEC_ECNTRL_RESET 0x00000001
314 #define FEC_RCNTRL_BC_REJ 0x00000010
315 #define FEC_RCNTRL_PROM 0x00000008
316 #define FEC_RCNTRL_MII_MODE 0x00000004
317 #define FEC_RCNTRL_DRT 0x00000002
318 #define FEC_RCNTRL_LOOP 0x00000001
320 #define FEC_TCNTRL_FDEN 0x00000004
321 #define FEC_TCNTRL_HBC 0x00000002
322 #define FEC_TCNTRL_GTS 0x00000001
324 #define FEC_RESET_DELAY 50
326 #if defined(CONFIG_RMII)
328 static inline void fec_10Mbps(struct eth_device *dev)
330 struct ether_fcc_info_s *efis = dev->priv;
331 int fecidx = efis->ether_index;
332 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
334 if ((unsigned int)fecidx >= 2)
337 ((volatile immap_t *)CFG_IMMR)->im_cpm.cp_cptr |= mask;
340 static inline void fec_100Mbps(struct eth_device *dev)
342 struct ether_fcc_info_s *efis = dev->priv;
343 int fecidx = efis->ether_index;
344 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
346 if ((unsigned int)fecidx >= 2)
349 ((volatile immap_t *)CFG_IMMR)->im_cpm.cp_cptr &= ~mask;
354 static inline void fec_full_duplex(struct eth_device *dev)
356 struct ether_fcc_info_s *efis = dev->priv;
357 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
359 fecp->fec_r_cntrl &= ~FEC_RCNTRL_DRT;
360 fecp->fec_x_cntrl |= FEC_TCNTRL_FDEN; /* FD enable */
363 static inline void fec_half_duplex(struct eth_device *dev)
365 struct ether_fcc_info_s *efis = dev->priv;
366 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
368 fecp->fec_r_cntrl |= FEC_RCNTRL_DRT;
369 fecp->fec_x_cntrl &= ~FEC_TCNTRL_FDEN; /* FD disable */
372 static void fec_pin_init(int fecidx)
374 DECLARE_GLOBAL_DATA_PTR;
376 volatile immap_t *immr = (immap_t *) CFG_IMMR;
377 volatile fec_t *fecp;
380 * only two FECs please
382 if ((unsigned int)fecidx >= 2)
386 fecp = &immr->im_cpm.cp_fec1;
388 fecp = &immr->im_cpm.cp_fec2;
391 * Set MII speed to 2.5 MHz or slightly below.
392 * * According to the MPC860T (Rev. D) Fast ethernet controller user
394 * * the MII management interface clock must be less than or equal
396 * * This MDC frequency is equal to system clock / (2 * MII_SPEED).
397 * * Then MII_SPEED = system_clock / 2 * 2,5 Mhz.
399 fecp->fec_mii_speed = ((bd->bi_intfreq + 4999999) / 5000000) << 1;
401 #if defined(CONFIG_NETTA) || defined(CONFIG_NETPHONE) || defined(CONFIG_NETTA2)
402 /* our PHYs are the limit at 2.5 MHz */
403 fecp->fec_mii_speed <<= 1;
406 #if defined(CONFIG_MPC885_FAMILY) && defined(WANT_MII)
407 /* use MDC for MII */
408 immr->im_ioport.iop_pdpar |= 0x0080;
409 immr->im_ioport.iop_pddir &= ~0x0080;
413 #if defined(CONFIG_ETHER_ON_FEC1)
415 #if defined(CONFIG_MPC885_FAMILY) /* MPC87x/88x have got 2 FECs and different pinout */
417 #if !defined(CONFIG_RMII)
419 immr->im_ioport.iop_papar |= 0xf830;
420 immr->im_ioport.iop_padir |= 0x0830;
421 immr->im_ioport.iop_padir &= ~0xf000;
423 immr->im_cpm.cp_pbpar |= 0x00001001;
424 immr->im_cpm.cp_pbdir &= ~0x00001001;
426 immr->im_ioport.iop_pcpar |= 0x000c;
427 immr->im_ioport.iop_pcdir &= ~0x000c;
429 immr->im_cpm.cp_pepar |= 0x00000003;
430 immr->im_cpm.cp_pedir |= 0x00000003;
431 immr->im_cpm.cp_peso &= ~0x00000003;
433 immr->im_cpm.cp_cptr &= ~0x00000100;
437 #if !defined(CONFIG_FEC1_PHY_NORXERR)
438 immr->im_ioport.iop_papar |= 0x1000;
439 immr->im_ioport.iop_padir &= ~0x1000;
441 immr->im_ioport.iop_papar |= 0xe810;
442 immr->im_ioport.iop_padir |= 0x0810;
443 immr->im_ioport.iop_padir &= ~0xe000;
445 immr->im_cpm.cp_pbpar |= 0x00000001;
446 immr->im_cpm.cp_pbdir &= ~0x00000001;
448 immr->im_cpm.cp_cptr |= 0x00000100;
449 immr->im_cpm.cp_cptr &= ~0x00000050;
451 #endif /* !CONFIG_RMII */
453 #elif !defined(CONFIG_ICU862) && !defined(CONFIG_IAD210)
455 * Configure all of port D for MII.
457 immr->im_ioport.iop_pdpar = 0x1fff;
460 * Bits moved from Rev. D onward
462 if ((get_immr(0) & 0xffff) < 0x0501)
463 immr->im_ioport.iop_pddir = 0x1c58; /* Pre rev. D */
465 immr->im_ioport.iop_pddir = 0x1fff; /* Rev. D and later */
468 * Configure port A for MII.
471 #if defined(CONFIG_ICU862) && defined(CFG_DISCOVER_PHY)
474 * On the ICU862 board the MII-MDC pin is routed to PD8 pin
475 * * of CPU, so for this board we need to configure Utopia and
476 * * enable PD8 to MII-MDC function
478 immr->im_ioport.iop_pdpar |= 0x4080;
482 * Has Utopia been configured?
484 if (immr->im_ioport.iop_pdpar & (0x8000 >> 1)) {
486 * YES - Use MUXED mode for UTOPIA bus.
487 * This frees Port A for use by MII (see 862UM table 41-6).
489 immr->im_ioport.utmode &= ~0x80;
492 * NO - set SPLIT mode for UTOPIA bus.
494 * This doesn't really effect UTOPIA (which isn't
495 * enabled anyway) but just tells the 862
496 * to use port A for MII (see 862UM table 41-6).
498 immr->im_ioport.utmode |= 0x80;
500 #endif /* !defined(CONFIG_ICU862) */
502 #endif /* CONFIG_ETHER_ON_FEC1 */
503 } else if (fecidx == 1) {
505 #if defined(CONFIG_ETHER_ON_FEC2)
507 #if defined(CONFIG_MPC885_FAMILY) /* MPC87x/88x have got 2 FECs and different pinout */
509 #if !defined(CONFIG_RMII)
511 #warning this configuration is not tested; please report if it works
512 immr->im_cpm.cp_pepar |= 0x0003fffc;
513 immr->im_cpm.cp_pedir |= 0x0003fffc;
514 immr->im_cpm.cp_peso &= ~0x000087fc;
515 immr->im_cpm.cp_peso |= 0x00037800;
517 immr->im_cpm.cp_cptr &= ~0x00000080;
520 #if !defined(CONFIG_FEC2_PHY_NORXERR)
521 immr->im_cpm.cp_pepar |= 0x00000010;
522 immr->im_cpm.cp_pedir |= 0x00000010;
523 immr->im_cpm.cp_peso &= ~0x00000010;
525 immr->im_cpm.cp_pepar |= 0x00039620;
526 immr->im_cpm.cp_pedir |= 0x00039620;
527 immr->im_cpm.cp_peso |= 0x00031000;
528 immr->im_cpm.cp_peso &= ~0x00008620;
530 immr->im_cpm.cp_cptr |= 0x00000080;
531 immr->im_cpm.cp_cptr &= ~0x00000028;
532 #endif /* CONFIG_RMII */
534 #endif /* CONFIG_MPC885_FAMILY */
536 #endif /* CONFIG_ETHER_ON_FEC2 */
541 static int fec_init (struct eth_device *dev, bd_t * bd)
543 struct ether_fcc_info_s *efis = dev->priv;
544 volatile immap_t *immr = (immap_t *) CFG_IMMR;
545 volatile fec_t *fecp =
546 (volatile fec_t *) (CFG_IMMR + efis->fecp_offset);
549 if (efis->ether_index == 0) {
550 #if defined(CONFIG_FADS) /* FADS family uses FPGA (BCSR) to control PHYs */
551 #if defined(CONFIG_MPC885ADS)
552 *(vu_char *) BCSR5 &= ~(BCSR5_MII1_EN | BCSR5_MII1_RST);
554 /* configure FADS for fast (FEC) ethernet, half-duplex */
555 /* The LXT970 needs about 50ms to recover from reset, so
556 * wait for it by discovering the PHY before leaving eth_init().
559 volatile uint *bcsr4 = (volatile uint *) BCSR4;
561 *bcsr4 = (*bcsr4 & ~(BCSR4_FETH_EN | BCSR4_FETHCFG1))
562 | (BCSR4_FETHCFG0 | BCSR4_FETHFDE |
565 /* reset the LXT970 PHY */
566 *bcsr4 &= ~BCSR4_FETHRST;
568 *bcsr4 |= BCSR4_FETHRST;
571 #endif /* CONFIG_MPC885ADS */
572 #endif /* CONFIG_FADS */
576 * A delay is required between a reset of the FEC block and
577 * initialization of other FEC registers because the reset takes
578 * some time to complete. If you don't delay, subsequent writes
579 * to FEC registers might get killed by the reset routine which is
582 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
584 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
588 if (i == FEC_RESET_DELAY) {
589 printf ("FEC_RESET_DELAY timeout\n");
593 /* We use strictly polling mode only
597 /* Clear any pending interrupt
599 fecp->fec_ievent = 0xffc0;
601 /* No need to set the IVEC register */
603 /* Set station address
605 #define ea eth_get_dev()->enetaddr
606 fecp->fec_addr_low = (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
607 fecp->fec_addr_high = (ea[4] << 8) | (ea[5]);
610 #if (CONFIG_COMMANDS & CFG_CMD_CDP)
612 * Turn on multicast address hash table
614 fecp->fec_hash_table_high = 0xffffffff;
615 fecp->fec_hash_table_low = 0xffffffff;
617 /* Clear multicast address hash table
619 fecp->fec_hash_table_high = 0;
620 fecp->fec_hash_table_low = 0;
623 /* Set maximum receive buffer size.
625 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
627 /* Set maximum frame length
629 fecp->fec_r_hash = PKT_MAXBUF_SIZE;
632 * Setup Buffers and Buffer Desriptors
638 #ifdef CFG_ALLOC_DPRAM
639 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem +
640 dpram_alloc_align (sizeof (RTXBD), 8));
642 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
646 * Setup Receiver Buffer Descriptors (13.14.24.18)
650 for (i = 0; i < PKTBUFSRX; i++) {
651 rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
652 rtx->rxbd[i].cbd_datlen = 0; /* Reset */
653 rtx->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
655 rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
658 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
662 for (i = 0; i < TX_BUF_CNT; i++) {
663 rtx->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
664 rtx->txbd[i].cbd_datlen = 0; /* Reset */
665 rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
667 rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
669 /* Set receive and transmit descriptor base
671 fecp->fec_r_des_start = (unsigned int) (&rtx->rxbd[0]);
672 fecp->fec_x_des_start = (unsigned int) (&rtx->txbd[0]);
676 #if 0 /* Full duplex mode */
677 fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE;
678 fecp->fec_x_cntrl = FEC_TCNTRL_FDEN;
679 #else /* Half duplex mode */
680 fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT;
681 fecp->fec_x_cntrl = 0;
684 /* Enable big endian and don't care about SDMA FC.
686 fecp->fec_fun_code = 0x78000000;
689 * Setup the pin configuration of the FEC
691 fec_pin_init (efis->ether_index);
697 * Now enable the transmit and receive processing
699 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
701 if (efis->phy_addr == -1) {
702 #ifdef CFG_DISCOVER_PHY
704 * wait for the PHY to wake up after reset
706 efis->actual_phy_addr = mii_discover_phy (dev);
708 if (efis->actual_phy_addr == -1) {
709 printf ("Unable to discover phy!\n");
713 efis->actual_phy_addr = -1;
716 efis->actual_phy_addr = efis->phy_addr;
718 #if defined(CONFIG_MII) && defined(CONFIG_RMII)
720 /* the MII interface is connected to FEC1
721 * so for the miiphy_xxx function to work we must
722 * call mii_init since fec_halt messes the thing up
724 if (efis->ether_index != 0)
728 * adapt the RMII speed to the speed of the phy
730 if (miiphy_speed (dev->name, efis->actual_phy_addr) == _100BASET) {
737 #if defined(CONFIG_MII)
739 * adapt to the half/full speed settings
741 if (miiphy_duplex (dev->name, efis->actual_phy_addr) == FULL) {
742 fec_full_duplex (dev);
744 fec_half_duplex (dev);
748 /* And last, try to fill Rx Buffer Descriptors */
749 fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
751 efis->initialized = 1;
757 static void fec_halt(struct eth_device* dev)
759 struct ether_fcc_info_s *efis = dev->priv;
760 volatile fec_t *fecp = (volatile fec_t *)(CFG_IMMR + efis->fecp_offset);
763 /* avoid halt if initialized; mii gets stuck otherwise */
764 if (!efis->initialized)
768 * A delay is required between a reset of the FEC block and
769 * initialization of other FEC registers because the reset takes
770 * some time to complete. If you don't delay, subsequent writes
771 * to FEC registers might get killed by the reset routine which is
775 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
777 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
781 if (i == FEC_RESET_DELAY) {
782 printf ("FEC_RESET_DELAY timeout\n");
786 efis->initialized = 0;
789 #if defined(CFG_DISCOVER_PHY) || defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
791 /* Make MII read/write commands for the FEC.
794 #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
797 #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
798 (REG & 0x1f) << 18) | \
801 /* Interrupt events/masks.
803 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
804 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
805 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
806 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
807 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
808 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
809 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
810 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
811 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
812 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
814 /* PHY identification
816 #define PHY_ID_LXT970 0x78100000 /* LXT970 */
817 #define PHY_ID_LXT971 0x001378e0 /* LXT971 and 972 */
818 #define PHY_ID_82555 0x02a80150 /* Intel 82555 */
819 #define PHY_ID_QS6612 0x01814400 /* QS6612 */
820 #define PHY_ID_AMD79C784 0x00225610 /* AMD 79C784 */
821 #define PHY_ID_LSI80225 0x0016f870 /* LSI 80225 */
822 #define PHY_ID_LSI80225B 0x0016f880 /* LSI 80225/B */
823 #define PHY_ID_DM9161 0x0181B880 /* Davicom DM9161 */
825 /* send command to phy using mii, wait for result */
827 mii_send(uint mii_cmd)
833 ep = &(((immap_t *)CFG_IMMR)->im_cpm.cp_fec);
835 ep->fec_mii_data = mii_cmd; /* command to phy */
837 /* wait for mii complete */
839 while (!(ep->fec_ievent & FEC_ENET_MII)) {
841 printf("mii_send STUCK!\n");
845 mii_reply = ep->fec_mii_data; /* result from phy */
846 ep->fec_ievent = FEC_ENET_MII; /* clear MII complete */
848 printf("%s[%d] %s: sent=0x%8.8x, reply=0x%8.8x\n",
849 __FILE__,__LINE__,__FUNCTION__,mii_cmd,mii_reply);
851 return (mii_reply & 0xffff); /* data read from phy */
853 #endif /* CFG_DISCOVER_PHY || (CONFIG_COMMANDS & CFG_CMD_MII) */
855 #if defined(CFG_DISCOVER_PHY)
856 static int mii_discover_phy(struct eth_device *dev)
858 #define MAX_PHY_PASSES 11
864 phyaddr = -1; /* didn't find a PHY yet */
865 for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
867 /* PHY may need more time to recover from reset.
868 * The LXT970 needs 50ms typical, no maximum is
869 * specified, so wait 10ms before try again.
870 * With 11 passes this gives it 100ms to wake up.
872 udelay(10000); /* wait 10ms */
874 for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
875 phytype = mii_send(mk_mii_read(phyno, PHY_PHYIDR1));
877 printf("PHY type 0x%x pass %d type ", phytype, pass);
879 if (phytype != 0xffff) {
882 phytype |= mii_send(mk_mii_read(phyno,
886 printf("PHY @ 0x%x pass %d type ",phyno,pass);
887 switch (phytype & 0xfffffff0) {
900 case PHY_ID_AMD79C784:
901 printf("AMD79C784\n");
903 case PHY_ID_LSI80225B:
904 printf("LSI L80225/B\n");
907 printf("Davicom DM9161\n");
910 printf("0x%08x\n", phytype);
918 printf("No PHY device found.\n");
922 #endif /* CFG_DISCOVER_PHY */
924 #if (defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)) && !defined(CONFIG_BITBANGMII)
926 /****************************************************************************
927 * mii_init -- Initialize the MII for MII command without ethernet
928 * This function is a subset of eth_init
929 ****************************************************************************
933 volatile immap_t *immr = (immap_t *) CFG_IMMR;
934 volatile fec_t *fecp = &(immr->im_cpm.cp_fec);
937 for (j = 0; j < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); j++) {
940 * A delay is required between a reset of the FEC block and
941 * initialization of other FEC registers because the reset takes
942 * some time to complete. If you don't delay, subsequent writes
943 * to FEC registers might get killed by the reset routine which is
947 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
949 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
953 if (i == FEC_RESET_DELAY) {
954 printf ("FEC_RESET_DELAY timeout\n");
958 /* We use strictly polling mode only
962 /* Clear any pending interrupt
964 fecp->fec_ievent = 0xffc0;
966 /* Setup the pin configuration of the FEC(s)
968 fec_pin_init(ether_fcc_info[i].ether_index);
970 /* Now enable the transmit and receive processing
972 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
976 /*****************************************************************************
977 * Read and write a MII PHY register, routines used by MII Utilities
979 * FIXME: These routines are expected to return 0 on success, but mii_send
980 * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
981 * no PHY connected...
982 * For now always return 0.
983 * FIXME: These routines only work after calling eth_init() at least once!
984 * Otherwise they hang in mii_send() !!! Sorry!
985 *****************************************************************************/
987 int fec8xx_miiphy_read(char *devname, unsigned char addr,
988 unsigned char reg, unsigned short *value)
990 short rdreg; /* register working value */
993 printf ("miiphy_read(0x%x) @ 0x%x = ", reg, addr);
995 rdreg = mii_send(mk_mii_read(addr, reg));
999 printf ("0x%04x\n", *value);
1004 int fec8xx_miiphy_write(char *devname, unsigned char addr,
1005 unsigned char reg, unsigned short value)
1007 short rdreg; /* register working value */
1009 printf ("miiphy_write(0x%x) @ 0x%x = ", reg, addr);
1011 rdreg = mii_send(mk_mii_write(addr, reg, value));
1014 printf ("0x%04x\n", value);
1018 #endif /* (CONFIG_COMMANDS & CFG_CMD_MII) && !defined(CONFIG_BITBANGMII)*/
1020 #endif /* CFG_CMD_NET, FEC_ENET */