3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
14 DECLARE_GLOBAL_DATA_PTR;
18 #if defined(CONFIG_CMD_NET) && \
19 (defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FEC1) || defined(CONFIG_ETHER_ON_FEC2))
21 /* compatibility test, if only FEC_ENET defined assume ETHER on FEC1 */
22 #if defined(FEC_ENET) && !defined(CONFIG_ETHER_ON_FEC1) && !defined(CONFIG_ETHER_ON_FEC2)
23 #define CONFIG_ETHER_ON_FEC1 1
26 /* define WANT_MII when MII support is required */
27 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_FEC1_PHY) || defined(CONFIG_FEC2_PHY)
36 #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
37 #error "CONFIG_MII has to be defined!"
42 #if defined(CONFIG_RMII) && !defined(WANT_MII)
43 #error RMII support is unusable without a working PHY.
46 #ifdef CONFIG_SYS_DISCOVER_PHY
47 static int mii_discover_phy(struct eth_device *dev);
50 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg);
51 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
54 static struct ether_fcc_info_s
63 #if defined(CONFIG_ETHER_ON_FEC1)
66 offsetof(immap_t, im_cpm.cp_fec1),
67 #if defined(CONFIG_FEC1_PHY)
77 #if defined(CONFIG_ETHER_ON_FEC2)
80 offsetof(immap_t, im_cpm.cp_fec2),
81 #if defined(CONFIG_FEC2_PHY)
92 /* Ethernet Transmit and Receive Buffers */
93 #define DBUF_LENGTH 1520
99 #define PKT_MAXBUF_SIZE 1518
100 #define PKT_MINBUF_SIZE 64
101 #define PKT_MAXBLR_SIZE 1520
104 static char txbuf[DBUF_LENGTH] __attribute__ ((aligned(8)));
106 #error txbuf must be aligned.
109 static uint rxIdx; /* index of the current RX buffer */
110 static uint txIdx; /* index of the current TX buffer */
113 * FEC Ethernet Tx and Rx buffer descriptors allocated at the
114 * immr->udata_bd address on Dual-Port RAM
115 * Provide for Double Buffering
118 typedef volatile struct CommonBufferDescriptor {
119 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
120 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
123 static RTXBD *rtx = NULL;
125 static int fec_send(struct eth_device *dev, void *packet, int length);
126 static int fec_recv(struct eth_device* dev);
127 static int fec_init(struct eth_device* dev, bd_t * bd);
128 static void fec_halt(struct eth_device* dev);
129 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
130 static void __mii_init(void);
133 int fec_initialize(bd_t *bis)
135 struct eth_device* dev;
136 struct ether_fcc_info_s *efis;
139 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++) {
141 dev = malloc(sizeof(*dev));
145 memset(dev, 0, sizeof(*dev));
147 /* for FEC1 make sure that the name of the interface is the same
148 as the old one for compatibility reasons */
150 strcpy(dev->name, "FEC");
152 sprintf (dev->name, "FEC%d",
153 ether_fcc_info[i].ether_index + 1);
156 efis = ðer_fcc_info[i];
159 * reset actual phy addr
161 efis->actual_phy_addr = -1;
164 dev->init = fec_init;
165 dev->halt = fec_halt;
166 dev->send = fec_send;
167 dev->recv = fec_recv;
171 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
173 struct mii_dev *mdiodev = mdio_alloc();
176 strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
177 mdiodev->read = fec8xx_miiphy_read;
178 mdiodev->write = fec8xx_miiphy_write;
180 retval = mdio_register(mdiodev);
188 static int fec_send(struct eth_device *dev, void *packet, int length)
191 struct ether_fcc_info_s *efis = dev->priv;
192 volatile fec_t *fecp = (volatile fec_t *)(CONFIG_SYS_IMMR + efis->fecp_offset);
198 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
203 printf("TX not ready\n");
206 rtx->txbd[txIdx].cbd_bufaddr = (uint)packet;
207 rtx->txbd[txIdx].cbd_datlen = length;
208 rtx->txbd[txIdx].cbd_sc |= BD_ENET_TX_READY | BD_ENET_TX_LAST;
211 /* Activate transmit Buffer Descriptor polling */
212 fecp->fec_x_des_active = 0x01000000; /* Descriptor polling active */
215 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j<TOUT_LOOP)) {
220 printf("TX timeout\n");
223 printf("%s[%d] %s: cycles: %d status: %x retry cnt: %d\n",
224 __FILE__,__LINE__,__FUNCTION__,j,rtx->txbd[txIdx].cbd_sc,
225 (rtx->txbd[txIdx].cbd_sc & 0x003C)>>2);
227 /* return only status bits */;
228 rc = (rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_STATS);
230 txIdx = (txIdx + 1) % TX_BUF_CNT;
235 static int fec_recv (struct eth_device *dev)
237 struct ether_fcc_info_s *efis = dev->priv;
238 volatile fec_t *fecp =
239 (volatile fec_t *) (CONFIG_SYS_IMMR + efis->fecp_offset);
243 /* section 16.9.23.2 */
244 if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
246 break; /* nothing received - leave for() loop */
249 length = rtx->rxbd[rxIdx].cbd_datlen;
251 if (rtx->rxbd[rxIdx].cbd_sc & 0x003f) {
253 printf ("%s[%d] err: %x\n",
254 __FUNCTION__, __LINE__,
255 rtx->rxbd[rxIdx].cbd_sc);
258 uchar *rx = net_rx_packets[rxIdx];
262 #if defined(CONFIG_CMD_CDP)
263 if ((rx[0] & 1) != 0 &&
264 memcmp((uchar *)rx, net_bcast_ethaddr, 6) != 0 &&
265 !is_cdp_packet((uchar *)rx))
269 * Pass the packet up to the protocol layers.
272 net_process_received_packet(rx, length);
275 /* Give the buffer back to the FEC. */
276 rtx->rxbd[rxIdx].cbd_datlen = 0;
278 /* wrap around buffer index when necessary */
279 if ((rxIdx + 1) >= PKTBUFSRX) {
280 rtx->rxbd[PKTBUFSRX - 1].cbd_sc =
281 (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
284 rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
290 /* Try to fill Buffer Descriptors */
291 fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
297 /**************************************************************
299 * FEC Ethernet Initialization Routine
301 *************************************************************/
303 #define FEC_ECNTRL_PINMUX 0x00000004
304 #define FEC_ECNTRL_ETHER_EN 0x00000002
305 #define FEC_ECNTRL_RESET 0x00000001
307 #define FEC_RCNTRL_BC_REJ 0x00000010
308 #define FEC_RCNTRL_PROM 0x00000008
309 #define FEC_RCNTRL_MII_MODE 0x00000004
310 #define FEC_RCNTRL_DRT 0x00000002
311 #define FEC_RCNTRL_LOOP 0x00000001
313 #define FEC_TCNTRL_FDEN 0x00000004
314 #define FEC_TCNTRL_HBC 0x00000002
315 #define FEC_TCNTRL_GTS 0x00000001
317 #define FEC_RESET_DELAY 50
319 #if defined(CONFIG_RMII)
321 static inline void fec_10Mbps(struct eth_device *dev)
323 struct ether_fcc_info_s *efis = dev->priv;
324 int fecidx = efis->ether_index;
325 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
327 if ((unsigned int)fecidx >= 2)
330 ((volatile immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_cptr |= mask;
333 static inline void fec_100Mbps(struct eth_device *dev)
335 struct ether_fcc_info_s *efis = dev->priv;
336 int fecidx = efis->ether_index;
337 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
339 if ((unsigned int)fecidx >= 2)
342 ((volatile immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_cptr &= ~mask;
347 static inline void fec_full_duplex(struct eth_device *dev)
349 struct ether_fcc_info_s *efis = dev->priv;
350 volatile fec_t *fecp = (volatile fec_t *)(CONFIG_SYS_IMMR + efis->fecp_offset);
352 fecp->fec_r_cntrl &= ~FEC_RCNTRL_DRT;
353 fecp->fec_x_cntrl |= FEC_TCNTRL_FDEN; /* FD enable */
356 static inline void fec_half_duplex(struct eth_device *dev)
358 struct ether_fcc_info_s *efis = dev->priv;
359 volatile fec_t *fecp = (volatile fec_t *)(CONFIG_SYS_IMMR + efis->fecp_offset);
361 fecp->fec_r_cntrl |= FEC_RCNTRL_DRT;
362 fecp->fec_x_cntrl &= ~FEC_TCNTRL_FDEN; /* FD disable */
365 static void fec_pin_init(int fecidx)
368 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
371 * Set MII speed to 2.5 MHz or slightly below.
373 * According to the MPC860T (Rev. D) Fast ethernet controller user
375 * the MII management interface clock must be less than or equal
377 * This MDC frequency is equal to system clock / (2 * MII_SPEED).
378 * Then MII_SPEED = system_clock / 2 * 2,5 MHz.
380 * All MII configuration is done via FEC1 registers:
382 immr->im_cpm.cp_fec1.fec_mii_speed = ((bd->bi_intfreq + 4999999) / 5000000) << 1;
384 #if defined(CONFIG_MPC885_FAMILY) && defined(WANT_MII)
385 /* use MDC for MII */
386 immr->im_ioport.iop_pdpar |= 0x0080;
387 immr->im_ioport.iop_pddir &= ~0x0080;
391 #if defined(CONFIG_ETHER_ON_FEC1)
393 #if defined(CONFIG_MPC885_FAMILY) /* MPC87x/88x have got 2 FECs and different pinout */
395 #if !defined(CONFIG_RMII)
397 immr->im_ioport.iop_papar |= 0xf830;
398 immr->im_ioport.iop_padir |= 0x0830;
399 immr->im_ioport.iop_padir &= ~0xf000;
401 immr->im_cpm.cp_pbpar |= 0x00001001;
402 immr->im_cpm.cp_pbdir &= ~0x00001001;
404 immr->im_ioport.iop_pcpar |= 0x000c;
405 immr->im_ioport.iop_pcdir &= ~0x000c;
407 immr->im_cpm.cp_pepar |= 0x00000003;
408 immr->im_cpm.cp_pedir |= 0x00000003;
409 immr->im_cpm.cp_peso &= ~0x00000003;
411 immr->im_cpm.cp_cptr &= ~0x00000100;
415 #if !defined(CONFIG_FEC1_PHY_NORXERR)
416 immr->im_ioport.iop_papar |= 0x1000;
417 immr->im_ioport.iop_padir &= ~0x1000;
419 immr->im_ioport.iop_papar |= 0xe810;
420 immr->im_ioport.iop_padir |= 0x0810;
421 immr->im_ioport.iop_padir &= ~0xe000;
423 immr->im_cpm.cp_pbpar |= 0x00000001;
424 immr->im_cpm.cp_pbdir &= ~0x00000001;
426 immr->im_cpm.cp_cptr |= 0x00000100;
427 immr->im_cpm.cp_cptr &= ~0x00000050;
429 #endif /* !CONFIG_RMII */
433 * Configure all of port D for MII.
435 immr->im_ioport.iop_pdpar = 0x1fff;
438 * Bits moved from Rev. D onward
440 if ((get_immr(0) & 0xffff) < 0x0501)
441 immr->im_ioport.iop_pddir = 0x1c58; /* Pre rev. D */
443 immr->im_ioport.iop_pddir = 0x1fff; /* Rev. D and later */
446 #endif /* CONFIG_ETHER_ON_FEC1 */
447 } else if (fecidx == 1) {
449 #if defined(CONFIG_ETHER_ON_FEC2)
451 #if defined(CONFIG_MPC885_FAMILY) /* MPC87x/88x have got 2 FECs and different pinout */
453 #if !defined(CONFIG_RMII)
454 immr->im_cpm.cp_pepar |= 0x0003fffc;
455 immr->im_cpm.cp_pedir |= 0x0003fffc;
456 immr->im_cpm.cp_peso &= ~0x000087fc;
457 immr->im_cpm.cp_peso |= 0x00037800;
459 immr->im_cpm.cp_cptr &= ~0x00000080;
462 #if !defined(CONFIG_FEC2_PHY_NORXERR)
463 immr->im_cpm.cp_pepar |= 0x00000010;
464 immr->im_cpm.cp_pedir |= 0x00000010;
465 immr->im_cpm.cp_peso &= ~0x00000010;
467 immr->im_cpm.cp_pepar |= 0x00039620;
468 immr->im_cpm.cp_pedir |= 0x00039620;
469 immr->im_cpm.cp_peso |= 0x00031000;
470 immr->im_cpm.cp_peso &= ~0x00008620;
472 immr->im_cpm.cp_cptr |= 0x00000080;
473 immr->im_cpm.cp_cptr &= ~0x00000028;
474 #endif /* CONFIG_RMII */
476 #endif /* CONFIG_MPC885_FAMILY */
478 #endif /* CONFIG_ETHER_ON_FEC2 */
483 static int fec_reset(volatile fec_t *fecp)
488 * A delay is required between a reset of the FEC block and
489 * initialization of other FEC registers because the reset takes
490 * some time to complete. If you don't delay, subsequent writes
491 * to FEC registers might get killed by the reset routine which is
495 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
497 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
501 if (i == FEC_RESET_DELAY)
507 static int fec_init (struct eth_device *dev, bd_t * bd)
509 struct ether_fcc_info_s *efis = dev->priv;
510 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
511 volatile fec_t *fecp =
512 (volatile fec_t *) (CONFIG_SYS_IMMR + efis->fecp_offset);
515 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
516 /* the MII interface is connected to FEC1
517 * so for the miiphy_xxx function to work we must
518 * call mii_init since fec_halt messes the thing up
520 if (efis->ether_index != 0)
524 if (fec_reset(fecp) < 0)
525 printf ("FEC_RESET_DELAY timeout\n");
527 /* We use strictly polling mode only
531 /* Clear any pending interrupt
533 fecp->fec_ievent = 0xffc0;
535 /* No need to set the IVEC register */
537 /* Set station address
539 #define ea dev->enetaddr
540 fecp->fec_addr_low = (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
541 fecp->fec_addr_high = (ea[4] << 8) | (ea[5]);
544 #if defined(CONFIG_CMD_CDP)
546 * Turn on multicast address hash table
548 fecp->fec_hash_table_high = 0xffffffff;
549 fecp->fec_hash_table_low = 0xffffffff;
551 /* Clear multicast address hash table
553 fecp->fec_hash_table_high = 0;
554 fecp->fec_hash_table_low = 0;
557 /* Set maximum receive buffer size.
559 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
561 /* Set maximum frame length
563 fecp->fec_r_hash = PKT_MAXBUF_SIZE;
566 * Setup Buffers and Buffer Desriptors
572 #ifdef CONFIG_SYS_ALLOC_DPRAM
573 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem +
574 dpram_alloc_align (sizeof (RTXBD), 8));
576 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
580 * Setup Receiver Buffer Descriptors (13.14.24.18)
584 for (i = 0; i < PKTBUFSRX; i++) {
585 rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
586 rtx->rxbd[i].cbd_datlen = 0; /* Reset */
587 rtx->rxbd[i].cbd_bufaddr = (uint) net_rx_packets[i];
589 rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
592 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
596 for (i = 0; i < TX_BUF_CNT; i++) {
597 rtx->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
598 rtx->txbd[i].cbd_datlen = 0; /* Reset */
599 rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
601 rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
603 /* Set receive and transmit descriptor base
605 fecp->fec_r_des_start = (unsigned int) (&rtx->rxbd[0]);
606 fecp->fec_x_des_start = (unsigned int) (&rtx->txbd[0]);
610 #if 0 /* Full duplex mode */
611 fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE;
612 fecp->fec_x_cntrl = FEC_TCNTRL_FDEN;
613 #else /* Half duplex mode */
614 fecp->fec_r_cntrl = FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT;
615 fecp->fec_x_cntrl = 0;
618 /* Enable big endian and don't care about SDMA FC.
620 fecp->fec_fun_code = 0x78000000;
623 * Setup the pin configuration of the FEC
625 fec_pin_init (efis->ether_index);
631 * Now enable the transmit and receive processing
633 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
635 if (efis->phy_addr == -1) {
636 #ifdef CONFIG_SYS_DISCOVER_PHY
638 * wait for the PHY to wake up after reset
640 efis->actual_phy_addr = mii_discover_phy (dev);
642 if (efis->actual_phy_addr == -1) {
643 printf ("Unable to discover phy!\n");
647 efis->actual_phy_addr = -1;
650 efis->actual_phy_addr = efis->phy_addr;
653 #if defined(CONFIG_MII) && defined(CONFIG_RMII)
655 * adapt the RMII speed to the speed of the phy
657 if (miiphy_speed (dev->name, efis->actual_phy_addr) == _100BASET) {
664 #if defined(CONFIG_MII)
666 * adapt to the half/full speed settings
668 if (miiphy_duplex (dev->name, efis->actual_phy_addr) == FULL) {
669 fec_full_duplex (dev);
671 fec_half_duplex (dev);
675 /* And last, try to fill Rx Buffer Descriptors */
676 fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
678 efis->initialized = 1;
684 static void fec_halt(struct eth_device* dev)
686 struct ether_fcc_info_s *efis = dev->priv;
687 volatile fec_t *fecp = (volatile fec_t *)(CONFIG_SYS_IMMR + efis->fecp_offset);
690 /* avoid halt if initialized; mii gets stuck otherwise */
691 if (!efis->initialized)
695 * A delay is required between a reset of the FEC block and
696 * initialization of other FEC registers because the reset takes
697 * some time to complete. If you don't delay, subsequent writes
698 * to FEC registers might get killed by the reset routine which is
702 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET;
704 (fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
708 if (i == FEC_RESET_DELAY) {
709 printf ("FEC_RESET_DELAY timeout\n");
713 efis->initialized = 0;
716 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
718 /* Make MII read/write commands for the FEC.
721 #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
724 #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
725 (REG & 0x1f) << 18) | \
728 /* Interrupt events/masks.
730 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
731 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
732 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
733 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
734 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
735 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
736 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
737 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
738 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
739 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
741 /* PHY identification
743 #define PHY_ID_LXT970 0x78100000 /* LXT970 */
744 #define PHY_ID_LXT971 0x001378e0 /* LXT971 and 972 */
745 #define PHY_ID_82555 0x02a80150 /* Intel 82555 */
746 #define PHY_ID_QS6612 0x01814400 /* QS6612 */
747 #define PHY_ID_AMD79C784 0x00225610 /* AMD 79C784 */
748 #define PHY_ID_LSI80225 0x0016f870 /* LSI 80225 */
749 #define PHY_ID_LSI80225B 0x0016f880 /* LSI 80225/B */
750 #define PHY_ID_DM9161 0x0181B880 /* Davicom DM9161 */
751 #define PHY_ID_KSM8995M 0x00221450 /* MICREL KS8995MA */
753 /* send command to phy using mii, wait for result */
755 mii_send(uint mii_cmd)
761 ep = &(((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_fec);
763 ep->fec_mii_data = mii_cmd; /* command to phy */
765 /* wait for mii complete */
767 while (!(ep->fec_ievent & FEC_ENET_MII)) {
769 printf("mii_send STUCK!\n");
773 mii_reply = ep->fec_mii_data; /* result from phy */
774 ep->fec_ievent = FEC_ENET_MII; /* clear MII complete */
776 printf("%s[%d] %s: sent=0x%8.8x, reply=0x%8.8x\n",
777 __FILE__,__LINE__,__FUNCTION__,mii_cmd,mii_reply);
779 return (mii_reply & 0xffff); /* data read from phy */
783 #if defined(CONFIG_SYS_DISCOVER_PHY)
784 static int mii_discover_phy(struct eth_device *dev)
786 #define MAX_PHY_PASSES 11
792 phyaddr = -1; /* didn't find a PHY yet */
793 for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
795 /* PHY may need more time to recover from reset.
796 * The LXT970 needs 50ms typical, no maximum is
797 * specified, so wait 10ms before try again.
798 * With 11 passes this gives it 100ms to wake up.
800 udelay(10000); /* wait 10ms */
802 for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
803 phytype = mii_send(mk_mii_read(phyno, MII_PHYSID2));
805 printf("PHY type 0x%x pass %d type ", phytype, pass);
807 if (phytype != 0xffff) {
809 phytype |= mii_send(mk_mii_read(phyno,
813 printf("PHY @ 0x%x pass %d type ",phyno,pass);
814 switch (phytype & 0xfffffff0) {
827 case PHY_ID_AMD79C784:
828 printf("AMD79C784\n");
830 case PHY_ID_LSI80225B:
831 printf("LSI L80225/B\n");
834 printf("Davicom DM9161\n");
836 case PHY_ID_KSM8995M:
837 printf("MICREL KS8995M\n");
840 printf("0x%08x\n", phytype);
848 printf("No PHY device found.\n");
852 #endif /* CONFIG_SYS_DISCOVER_PHY */
854 #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && !defined(CONFIG_BITBANGMII)
856 /****************************************************************************
857 * mii_init -- Initialize the MII via FEC 1 for MII command without ethernet
858 * This function is a subset of eth_init
859 ****************************************************************************
861 static void __mii_init(void)
863 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
864 volatile fec_t *fecp = &(immr->im_cpm.cp_fec);
866 if (fec_reset(fecp) < 0)
867 printf ("FEC_RESET_DELAY timeout\n");
869 /* We use strictly polling mode only
873 /* Clear any pending interrupt
875 fecp->fec_ievent = 0xffc0;
877 /* Now enable the transmit and receive processing
879 fecp->fec_ecntrl = FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN;
888 /* Setup the pin configuration of the FEC(s)
890 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
891 fec_pin_init(ether_fcc_info[i].ether_index);
894 /*****************************************************************************
895 * Read and write a MII PHY register, routines used by MII Utilities
897 * FIXME: These routines are expected to return 0 on success, but mii_send
898 * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
899 * no PHY connected...
900 * For now always return 0.
901 * FIXME: These routines only work after calling eth_init() at least once!
902 * Otherwise they hang in mii_send() !!! Sorry!
903 *****************************************************************************/
905 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
907 unsigned short value = 0;
908 short rdreg; /* register working value */
911 printf ("miiphy_read(0x%x) @ 0x%x = ", reg, addr);
913 rdreg = mii_send(mk_mii_read(addr, reg));
917 printf ("0x%04x\n", value);
922 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
926 printf ("miiphy_write(0x%x) @ 0x%x = ", reg, addr);
928 (void)mii_send(mk_mii_write(addr, reg, value));
931 printf ("0x%04x\n", value);