1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
13 #include <asm/cpm_8xx.h>
17 #include <linux/mii.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 /* define WANT_MII when MII support is required */
22 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_FEC1_PHY) || defined(CONFIG_FEC2_PHY)
31 #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
32 #error "CONFIG_MII has to be defined!"
37 #if defined(CONFIG_RMII) && !defined(WANT_MII)
38 #error RMII support is unusable without a working PHY.
41 #ifdef CONFIG_SYS_DISCOVER_PHY
42 static int mii_discover_phy(struct eth_device *dev);
45 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg);
46 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
49 static struct ether_fcc_info_s
58 #if defined(CONFIG_ETHER_ON_FEC1)
61 offsetof(immap_t, im_cpm.cp_fec1),
68 #if defined(CONFIG_ETHER_ON_FEC2)
71 offsetof(immap_t, im_cpm.cp_fec2),
79 /* Ethernet Transmit and Receive Buffers */
80 #define DBUF_LENGTH 1520
86 #define PKT_MAXBUF_SIZE 1518
87 #define PKT_MINBUF_SIZE 64
88 #define PKT_MAXBLR_SIZE 1520
91 static char txbuf[DBUF_LENGTH] __aligned(8);
93 #error txbuf must be aligned.
96 static uint rxIdx; /* index of the current RX buffer */
97 static uint txIdx; /* index of the current TX buffer */
100 * FEC Ethernet Tx and Rx buffer descriptors allocated at the
101 * immr->udata_bd address on Dual-Port RAM
102 * Provide for Double Buffering
105 struct common_buf_desc {
106 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
107 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
110 static struct common_buf_desc __iomem *rtx;
112 static int fec_send(struct eth_device *dev, void *packet, int length);
113 static int fec_recv(struct eth_device *dev);
114 static int fec_init(struct eth_device *dev, bd_t *bd);
115 static void fec_halt(struct eth_device *dev);
116 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
117 static void __mii_init(void);
120 int fec_initialize(bd_t *bis)
122 struct eth_device *dev;
123 struct ether_fcc_info_s *efis;
126 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++) {
127 dev = malloc(sizeof(*dev));
131 memset(dev, 0, sizeof(*dev));
133 /* for FEC1 make sure that the name of the interface is the same
134 as the old one for compatibility reasons */
136 strcpy(dev->name, "FEC");
138 sprintf(dev->name, "FEC%d",
139 ether_fcc_info[i].ether_index + 1);
141 efis = ðer_fcc_info[i];
144 * reset actual phy addr
146 efis->actual_phy_addr = -1;
149 dev->init = fec_init;
150 dev->halt = fec_halt;
151 dev->send = fec_send;
152 dev->recv = fec_recv;
156 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
158 struct mii_dev *mdiodev = mdio_alloc();
161 strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
162 mdiodev->read = fec8xx_miiphy_read;
163 mdiodev->write = fec8xx_miiphy_write;
165 retval = mdio_register(mdiodev);
173 static int fec_send(struct eth_device *dev, void *packet, int length)
176 struct ether_fcc_info_s *efis = dev->priv;
177 fec_t __iomem *fecp =
178 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
184 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
190 printf("TX not ready\n");
192 out_be32(&rtx->txbd[txIdx].cbd_bufaddr, (uint)packet);
193 out_be16(&rtx->txbd[txIdx].cbd_datlen, length);
194 setbits_be16(&rtx->txbd[txIdx].cbd_sc,
195 BD_ENET_TX_READY | BD_ENET_TX_LAST);
197 /* Activate transmit Buffer Descriptor polling */
198 /* Descriptor polling active */
199 out_be32(&fecp->fec_x_des_active, 0x01000000);
202 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
208 printf("TX timeout\n");
210 /* return only status bits */;
211 rc = in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_STATS;
213 txIdx = (txIdx + 1) % TX_BUF_CNT;
218 static int fec_recv(struct eth_device *dev)
220 struct ether_fcc_info_s *efis = dev->priv;
221 fec_t __iomem *fecp =
222 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
226 /* section 16.9.23.2 */
227 if (in_be16(&rtx->rxbd[rxIdx].cbd_sc) & BD_ENET_RX_EMPTY) {
229 break; /* nothing received - leave for() loop */
232 length = in_be16(&rtx->rxbd[rxIdx].cbd_datlen);
234 if (!(in_be16(&rtx->rxbd[rxIdx].cbd_sc) & 0x003f)) {
235 uchar *rx = net_rx_packets[rxIdx];
239 #if defined(CONFIG_CMD_CDP)
240 if ((rx[0] & 1) != 0 &&
241 memcmp((uchar *)rx, net_bcast_ethaddr, 6) != 0 &&
242 !is_cdp_packet((uchar *)rx))
246 * Pass the packet up to the protocol layers.
249 net_process_received_packet(rx, length);
252 /* Give the buffer back to the FEC. */
253 out_be16(&rtx->rxbd[rxIdx].cbd_datlen, 0);
255 /* wrap around buffer index when necessary */
256 if ((rxIdx + 1) >= PKTBUFSRX) {
257 out_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc,
258 BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
261 out_be16(&rtx->rxbd[rxIdx].cbd_sc, BD_ENET_RX_EMPTY);
265 /* Try to fill Buffer Descriptors */
266 /* Descriptor polling active */
267 out_be32(&fecp->fec_r_des_active, 0x01000000);
273 /**************************************************************
275 * FEC Ethernet Initialization Routine
277 *************************************************************/
279 #define FEC_ECNTRL_PINMUX 0x00000004
280 #define FEC_ECNTRL_ETHER_EN 0x00000002
281 #define FEC_ECNTRL_RESET 0x00000001
283 #define FEC_RCNTRL_BC_REJ 0x00000010
284 #define FEC_RCNTRL_PROM 0x00000008
285 #define FEC_RCNTRL_MII_MODE 0x00000004
286 #define FEC_RCNTRL_DRT 0x00000002
287 #define FEC_RCNTRL_LOOP 0x00000001
289 #define FEC_TCNTRL_FDEN 0x00000004
290 #define FEC_TCNTRL_HBC 0x00000002
291 #define FEC_TCNTRL_GTS 0x00000001
293 #define FEC_RESET_DELAY 50
295 #if defined(CONFIG_RMII)
297 static inline void fec_10Mbps(struct eth_device *dev)
299 struct ether_fcc_info_s *efis = dev->priv;
300 int fecidx = efis->ether_index;
301 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
302 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
304 if ((unsigned int)fecidx >= 2)
307 setbits_be32(&immr->im_cpm.cp_cptr, mask);
310 static inline void fec_100Mbps(struct eth_device *dev)
312 struct ether_fcc_info_s *efis = dev->priv;
313 int fecidx = efis->ether_index;
314 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
315 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
317 if ((unsigned int)fecidx >= 2)
320 clrbits_be32(&immr->im_cpm.cp_cptr, mask);
325 static inline void fec_full_duplex(struct eth_device *dev)
327 struct ether_fcc_info_s *efis = dev->priv;
328 fec_t __iomem *fecp =
329 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
331 clrbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
332 setbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
335 static inline void fec_half_duplex(struct eth_device *dev)
337 struct ether_fcc_info_s *efis = dev->priv;
338 fec_t __iomem *fecp =
339 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
341 setbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
342 clrbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD disable */
345 static void fec_pin_init(int fecidx)
348 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
351 * Set MII speed to 2.5 MHz or slightly below.
353 * According to the MPC860T (Rev. D) Fast ethernet controller user
355 * the MII management interface clock must be less than or equal
357 * This MDC frequency is equal to system clock / (2 * MII_SPEED).
358 * Then MII_SPEED = system_clock / 2 * 2,5 MHz.
360 * All MII configuration is done via FEC1 registers:
362 out_be32(&immr->im_cpm.cp_fec1.fec_mii_speed,
363 ((bd->bi_intfreq + 4999999) / 5000000) << 1);
365 #if defined(CONFIG_MPC885) && defined(WANT_MII)
366 /* use MDC for MII */
367 setbits_be16(&immr->im_ioport.iop_pdpar, 0x0080);
368 clrbits_be16(&immr->im_ioport.iop_pddir, 0x0080);
372 #if defined(CONFIG_ETHER_ON_FEC1)
374 #if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
376 #if !defined(CONFIG_RMII)
378 setbits_be16(&immr->im_ioport.iop_papar, 0xf830);
379 setbits_be16(&immr->im_ioport.iop_padir, 0x0830);
380 clrbits_be16(&immr->im_ioport.iop_padir, 0xf000);
382 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00001001);
383 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00001001);
385 setbits_be16(&immr->im_ioport.iop_pcpar, 0x000c);
386 clrbits_be16(&immr->im_ioport.iop_pcdir, 0x000c);
388 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000003);
389 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000003);
390 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000003);
392 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
396 #if !defined(CONFIG_FEC1_PHY_NORXERR)
397 setbits_be16(&immr->im_ioport.iop_papar, 0x1000);
398 clrbits_be16(&immr->im_ioport.iop_padir, 0x1000);
400 setbits_be16(&immr->im_ioport.iop_papar, 0xe810);
401 setbits_be16(&immr->im_ioport.iop_padir, 0x0810);
402 clrbits_be16(&immr->im_ioport.iop_padir, 0xe000);
404 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00000001);
405 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00000001);
407 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
408 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000050);
410 #endif /* !CONFIG_RMII */
414 * Configure all of port D for MII.
416 out_be16(&immr->im_ioport.iop_pdpar, 0x1fff);
417 out_be16(&immr->im_ioport.iop_pddir, 0x1fff);
419 #if defined(CONFIG_TARGET_MCR3000)
420 out_be16(&immr->im_ioport.iop_papar, 0xBBFF);
421 out_be16(&immr->im_ioport.iop_padir, 0x04F0);
422 out_be16(&immr->im_ioport.iop_paodr, 0x0000);
424 out_be32(&immr->im_cpm.cp_pbpar, 0x000133FF);
425 out_be32(&immr->im_cpm.cp_pbdir, 0x0003BF0F);
426 out_be16(&immr->im_cpm.cp_pbodr, 0x0000);
428 out_be16(&immr->im_ioport.iop_pcpar, 0x0400);
429 out_be16(&immr->im_ioport.iop_pcdir, 0x0080);
430 out_be16(&immr->im_ioport.iop_pcso , 0x0D53);
431 out_be16(&immr->im_ioport.iop_pcint, 0x0000);
433 out_be16(&immr->im_ioport.iop_pdpar, 0x03FE);
434 out_be16(&immr->im_ioport.iop_pddir, 0x1C09);
436 setbits_be32(&immr->im_ioport.utmode, 0x80);
440 #endif /* CONFIG_ETHER_ON_FEC1 */
441 } else if (fecidx == 1) {
442 #if defined(CONFIG_ETHER_ON_FEC2)
444 #if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
446 #if !defined(CONFIG_RMII)
447 setbits_be32(&immr->im_cpm.cp_pepar, 0x0003fffc);
448 setbits_be32(&immr->im_cpm.cp_pedir, 0x0003fffc);
449 clrbits_be32(&immr->im_cpm.cp_peso, 0x000087fc);
450 setbits_be32(&immr->im_cpm.cp_peso, 0x00037800);
452 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
455 #if !defined(CONFIG_FEC2_PHY_NORXERR)
456 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000010);
457 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000010);
458 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000010);
460 setbits_be32(&immr->im_cpm.cp_pepar, 0x00039620);
461 setbits_be32(&immr->im_cpm.cp_pedir, 0x00039620);
462 setbits_be32(&immr->im_cpm.cp_peso, 0x00031000);
463 clrbits_be32(&immr->im_cpm.cp_peso, 0x00008620);
465 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
466 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000028);
467 #endif /* CONFIG_RMII */
469 #endif /* CONFIG_MPC885 */
471 #endif /* CONFIG_ETHER_ON_FEC2 */
475 static int fec_reset(fec_t __iomem *fecp)
480 * A delay is required between a reset of the FEC block and
481 * initialization of other FEC registers because the reset takes
482 * some time to complete. If you don't delay, subsequent writes
483 * to FEC registers might get killed by the reset routine which is
487 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
488 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
489 (i < FEC_RESET_DELAY); ++i)
492 if (i == FEC_RESET_DELAY)
498 static int fec_init(struct eth_device *dev, bd_t *bd)
500 struct ether_fcc_info_s *efis = dev->priv;
501 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
502 fec_t __iomem *fecp =
503 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
506 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
507 /* the MII interface is connected to FEC1
508 * so for the miiphy_xxx function to work we must
509 * call mii_init since fec_halt messes the thing up
511 if (efis->ether_index != 0)
515 if (fec_reset(fecp) < 0)
516 printf("FEC_RESET_DELAY timeout\n");
518 /* We use strictly polling mode only
520 out_be32(&fecp->fec_imask, 0);
522 /* Clear any pending interrupt
524 out_be32(&fecp->fec_ievent, 0xffc0);
526 /* No need to set the IVEC register */
528 /* Set station address
530 #define ea dev->enetaddr
531 out_be32(&fecp->fec_addr_low, (ea[0] << 24) | (ea[1] << 16) |
532 (ea[2] << 8) | ea[3]);
533 out_be16(&fecp->fec_addr_high, (ea[4] << 8) | ea[5]);
536 #if defined(CONFIG_CMD_CDP)
538 * Turn on multicast address hash table
540 out_be32(&fecp->fec_hash_table_high, 0xffffffff);
541 out_be32(&fecp->fec_hash_table_low, 0xffffffff);
543 /* Clear multicast address hash table
545 out_be32(&fecp->fec_hash_table_high, 0);
546 out_be32(&fecp->fec_hash_table_low, 0);
549 /* Set maximum receive buffer size.
551 out_be32(&fecp->fec_r_buff_size, PKT_MAXBLR_SIZE);
553 /* Set maximum frame length
555 out_be32(&fecp->fec_r_hash, PKT_MAXBUF_SIZE);
558 * Setup Buffers and Buffer Descriptors
564 rtx = (struct common_buf_desc __iomem *)
565 (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
567 * Setup Receiver Buffer Descriptors (13.14.24.18)
571 for (i = 0; i < PKTBUFSRX; i++) {
572 out_be16(&rtx->rxbd[i].cbd_sc, BD_ENET_RX_EMPTY);
573 out_be16(&rtx->rxbd[i].cbd_datlen, 0); /* Reset */
574 out_be32(&rtx->rxbd[i].cbd_bufaddr, (uint)net_rx_packets[i]);
576 setbits_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc, BD_ENET_RX_WRAP);
579 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
583 for (i = 0; i < TX_BUF_CNT; i++) {
584 out_be16(&rtx->txbd[i].cbd_sc, BD_ENET_TX_LAST | BD_ENET_TX_TC);
585 out_be16(&rtx->txbd[i].cbd_datlen, 0); /* Reset */
586 out_be32(&rtx->txbd[i].cbd_bufaddr, (uint)txbuf);
588 setbits_be16(&rtx->txbd[TX_BUF_CNT - 1].cbd_sc, BD_ENET_TX_WRAP);
590 /* Set receive and transmit descriptor base
592 out_be32(&fecp->fec_r_des_start, (__force unsigned int)rtx->rxbd);
593 out_be32(&fecp->fec_x_des_start, (__force unsigned int)rtx->txbd);
597 /* Half duplex mode */
598 out_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT);
599 out_be32(&fecp->fec_x_cntrl, 0);
601 /* Enable big endian and don't care about SDMA FC.
603 out_be32(&fecp->fec_fun_code, 0x78000000);
606 * Setup the pin configuration of the FEC
608 fec_pin_init(efis->ether_index);
614 * Now enable the transmit and receive processing
616 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
618 if (efis->phy_addr == -1) {
619 #ifdef CONFIG_SYS_DISCOVER_PHY
621 * wait for the PHY to wake up after reset
623 efis->actual_phy_addr = mii_discover_phy(dev);
625 if (efis->actual_phy_addr == -1) {
626 printf("Unable to discover phy!\n");
630 efis->actual_phy_addr = -1;
633 efis->actual_phy_addr = efis->phy_addr;
636 #if defined(CONFIG_MII) && defined(CONFIG_RMII)
638 * adapt the RMII speed to the speed of the phy
640 if (miiphy_speed(dev->name, efis->actual_phy_addr) == _100BASET)
646 #if defined(CONFIG_MII)
648 * adapt to the half/full speed settings
650 if (miiphy_duplex(dev->name, efis->actual_phy_addr) == FULL)
651 fec_full_duplex(dev);
653 fec_half_duplex(dev);
656 /* And last, try to fill Rx Buffer Descriptors */
657 /* Descriptor polling active */
658 out_be32(&fecp->fec_r_des_active, 0x01000000);
660 efis->initialized = 1;
666 static void fec_halt(struct eth_device *dev)
668 struct ether_fcc_info_s *efis = dev->priv;
669 fec_t __iomem *fecp =
670 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
673 /* avoid halt if initialized; mii gets stuck otherwise */
674 if (!efis->initialized)
678 * A delay is required between a reset of the FEC block and
679 * initialization of other FEC registers because the reset takes
680 * some time to complete. If you don't delay, subsequent writes
681 * to FEC registers might get killed by the reset routine which is
685 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
686 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
687 (i < FEC_RESET_DELAY); ++i)
690 if (i == FEC_RESET_DELAY) {
691 printf("FEC_RESET_DELAY timeout\n");
695 efis->initialized = 0;
698 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
700 /* Make MII read/write commands for the FEC.
703 #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
706 #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
707 (REG & 0x1f) << 18) | \
710 /* Interrupt events/masks.
712 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
713 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
714 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
715 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
716 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
717 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
718 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
719 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
720 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
721 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
723 /* send command to phy using mii, wait for result */
725 mii_send(uint mii_cmd)
730 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
732 ep = &immr->im_cpm.cp_fec;
734 out_be32(&ep->fec_mii_data, mii_cmd); /* command to phy */
736 /* wait for mii complete */
738 while (!(in_be32(&ep->fec_ievent) & FEC_ENET_MII)) {
740 printf("mii_send STUCK!\n");
744 mii_reply = in_be32(&ep->fec_mii_data); /* result from phy */
745 out_be32(&ep->fec_ievent, FEC_ENET_MII); /* clear MII complete */
746 return mii_reply & 0xffff; /* data read from phy */
750 #if defined(CONFIG_SYS_DISCOVER_PHY)
751 static int mii_discover_phy(struct eth_device *dev)
753 #define MAX_PHY_PASSES 11
759 phyaddr = -1; /* didn't find a PHY yet */
760 for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
762 /* PHY may need more time to recover from reset.
763 * The LXT970 needs 50ms typical, no maximum is
764 * specified, so wait 10ms before try again.
765 * With 11 passes this gives it 100ms to wake up.
767 udelay(10000); /* wait 10ms */
769 for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
770 phytype = mii_send(mk_mii_read(phyno, MII_PHYSID2));
771 if (phytype != 0xffff) {
773 phytype |= mii_send(mk_mii_read(phyno,
779 printf("No PHY device found.\n");
783 #endif /* CONFIG_SYS_DISCOVER_PHY */
785 #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && !defined(CONFIG_BITBANGMII)
787 /****************************************************************************
788 * mii_init -- Initialize the MII via FEC 1 for MII command without ethernet
789 * This function is a subset of eth_init
790 ****************************************************************************
792 static void __mii_init(void)
794 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
795 fec_t __iomem *fecp = &immr->im_cpm.cp_fec;
797 if (fec_reset(fecp) < 0)
798 printf("FEC_RESET_DELAY timeout\n");
800 /* We use strictly polling mode only
802 out_be32(&fecp->fec_imask, 0);
804 /* Clear any pending interrupt
806 out_be32(&fecp->fec_ievent, 0xffc0);
808 /* Now enable the transmit and receive processing
810 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
819 /* Setup the pin configuration of the FEC(s)
821 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
822 fec_pin_init(ether_fcc_info[i].ether_index);
825 /*****************************************************************************
826 * Read and write a MII PHY register, routines used by MII Utilities
828 * FIXME: These routines are expected to return 0 on success, but mii_send
829 * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
830 * no PHY connected...
831 * For now always return 0.
832 * FIXME: These routines only work after calling eth_init() at least once!
833 * Otherwise they hang in mii_send() !!! Sorry!
834 *****************************************************************************/
836 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
838 unsigned short value = 0;
839 short rdreg; /* register working value */
841 rdreg = mii_send(mk_mii_read(addr, reg));
847 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
850 (void)mii_send(mk_mii_write(addr, reg, value));