1 // SPDX-License-Identifier: GPL-2.0+
13 #include <asm/cpm_8xx.h>
14 #include <asm/global_data.h>
16 #include <linux/delay.h>
19 #include <linux/mii.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 /* define WANT_MII when MII support is required */
24 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_FEC1_PHY) || defined(CONFIG_FEC2_PHY)
33 #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
34 #error "CONFIG_MII has to be defined!"
39 #if defined(CONFIG_RMII) && !defined(WANT_MII)
40 #error RMII support is unusable without a working PHY.
43 #ifdef CONFIG_SYS_DISCOVER_PHY
44 static int mii_discover_phy(struct eth_device *dev);
47 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg);
48 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
51 static struct ether_fcc_info_s
60 #if defined(CONFIG_ETHER_ON_FEC1)
63 offsetof(immap_t, im_cpm.cp_fec1),
70 #if defined(CONFIG_ETHER_ON_FEC2)
73 offsetof(immap_t, im_cpm.cp_fec2),
81 /* Ethernet Transmit and Receive Buffers */
82 #define DBUF_LENGTH 1520
88 #define PKT_MAXBUF_SIZE 1518
89 #define PKT_MINBUF_SIZE 64
90 #define PKT_MAXBLR_SIZE 1520
93 static char txbuf[DBUF_LENGTH] __aligned(8);
95 #error txbuf must be aligned.
98 static uint rxIdx; /* index of the current RX buffer */
99 static uint txIdx; /* index of the current TX buffer */
102 * FEC Ethernet Tx and Rx buffer descriptors allocated at the
103 * immr->udata_bd address on Dual-Port RAM
104 * Provide for Double Buffering
107 struct common_buf_desc {
108 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
109 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
112 static struct common_buf_desc __iomem *rtx;
114 static int fec_send(struct eth_device *dev, void *packet, int length);
115 static int fec_recv(struct eth_device *dev);
116 static int fec_init(struct eth_device *dev, struct bd_info *bd);
117 static void fec_halt(struct eth_device *dev);
118 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
119 static void __mii_init(void);
122 int fec_initialize(struct bd_info *bis)
124 struct eth_device *dev;
125 struct ether_fcc_info_s *efis;
128 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++) {
129 dev = malloc(sizeof(*dev));
133 memset(dev, 0, sizeof(*dev));
135 /* for FEC1 make sure that the name of the interface is the same
136 as the old one for compatibility reasons */
138 strcpy(dev->name, "FEC");
140 sprintf(dev->name, "FEC%d",
141 ether_fcc_info[i].ether_index + 1);
143 efis = ðer_fcc_info[i];
146 * reset actual phy addr
148 efis->actual_phy_addr = -1;
151 dev->init = fec_init;
152 dev->halt = fec_halt;
153 dev->send = fec_send;
154 dev->recv = fec_recv;
158 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
160 struct mii_dev *mdiodev = mdio_alloc();
163 strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
164 mdiodev->read = fec8xx_miiphy_read;
165 mdiodev->write = fec8xx_miiphy_write;
167 retval = mdio_register(mdiodev);
175 static int fec_send(struct eth_device *dev, void *packet, int length)
178 struct ether_fcc_info_s *efis = dev->priv;
179 fec_t __iomem *fecp =
180 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
186 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
192 printf("TX not ready\n");
194 out_be32(&rtx->txbd[txIdx].cbd_bufaddr, (uint)packet);
195 out_be16(&rtx->txbd[txIdx].cbd_datlen, length);
196 setbits_be16(&rtx->txbd[txIdx].cbd_sc,
197 BD_ENET_TX_READY | BD_ENET_TX_LAST);
199 /* Activate transmit Buffer Descriptor polling */
200 /* Descriptor polling active */
201 out_be32(&fecp->fec_x_des_active, 0x01000000);
204 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
210 printf("TX timeout\n");
212 /* return only status bits */;
213 rc = in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_STATS;
215 txIdx = (txIdx + 1) % TX_BUF_CNT;
220 static int fec_recv(struct eth_device *dev)
222 struct ether_fcc_info_s *efis = dev->priv;
223 fec_t __iomem *fecp =
224 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
228 /* section 16.9.23.2 */
229 if (in_be16(&rtx->rxbd[rxIdx].cbd_sc) & BD_ENET_RX_EMPTY) {
231 break; /* nothing received - leave for() loop */
234 length = in_be16(&rtx->rxbd[rxIdx].cbd_datlen);
236 if (!(in_be16(&rtx->rxbd[rxIdx].cbd_sc) & 0x003f)) {
237 uchar *rx = net_rx_packets[rxIdx];
241 #if defined(CONFIG_CMD_CDP)
242 if ((rx[0] & 1) != 0 &&
243 memcmp((uchar *)rx, net_bcast_ethaddr, 6) != 0 &&
244 !is_cdp_packet((uchar *)rx))
248 * Pass the packet up to the protocol layers.
251 net_process_received_packet(rx, length);
254 /* Give the buffer back to the FEC. */
255 out_be16(&rtx->rxbd[rxIdx].cbd_datlen, 0);
257 /* wrap around buffer index when necessary */
258 if ((rxIdx + 1) >= PKTBUFSRX) {
259 out_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc,
260 BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
263 out_be16(&rtx->rxbd[rxIdx].cbd_sc, BD_ENET_RX_EMPTY);
267 /* Try to fill Buffer Descriptors */
268 /* Descriptor polling active */
269 out_be32(&fecp->fec_r_des_active, 0x01000000);
275 /**************************************************************
277 * FEC Ethernet Initialization Routine
279 *************************************************************/
281 #define FEC_ECNTRL_PINMUX 0x00000004
282 #define FEC_ECNTRL_ETHER_EN 0x00000002
283 #define FEC_ECNTRL_RESET 0x00000001
285 #define FEC_RCNTRL_BC_REJ 0x00000010
286 #define FEC_RCNTRL_PROM 0x00000008
287 #define FEC_RCNTRL_MII_MODE 0x00000004
288 #define FEC_RCNTRL_DRT 0x00000002
289 #define FEC_RCNTRL_LOOP 0x00000001
291 #define FEC_TCNTRL_FDEN 0x00000004
292 #define FEC_TCNTRL_HBC 0x00000002
293 #define FEC_TCNTRL_GTS 0x00000001
295 #define FEC_RESET_DELAY 50
297 #if defined(CONFIG_RMII)
299 static inline void fec_10Mbps(struct eth_device *dev)
301 struct ether_fcc_info_s *efis = dev->priv;
302 int fecidx = efis->ether_index;
303 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
304 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
306 if ((unsigned int)fecidx >= 2)
309 setbits_be32(&immr->im_cpm.cp_cptr, mask);
312 static inline void fec_100Mbps(struct eth_device *dev)
314 struct ether_fcc_info_s *efis = dev->priv;
315 int fecidx = efis->ether_index;
316 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
317 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
319 if ((unsigned int)fecidx >= 2)
322 clrbits_be32(&immr->im_cpm.cp_cptr, mask);
327 static inline void fec_full_duplex(struct eth_device *dev)
329 struct ether_fcc_info_s *efis = dev->priv;
330 fec_t __iomem *fecp =
331 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
333 clrbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
334 setbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
337 static inline void fec_half_duplex(struct eth_device *dev)
339 struct ether_fcc_info_s *efis = dev->priv;
340 fec_t __iomem *fecp =
341 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
343 setbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
344 clrbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD disable */
347 static void fec_pin_init(int fecidx)
349 struct bd_info *bd = gd->bd;
350 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
353 * Set MII speed to 2.5 MHz or slightly below.
355 * According to the MPC860T (Rev. D) Fast ethernet controller user
357 * the MII management interface clock must be less than or equal
359 * This MDC frequency is equal to system clock / (2 * MII_SPEED).
360 * Then MII_SPEED = system_clock / 2 * 2,5 MHz.
362 * All MII configuration is done via FEC1 registers:
364 out_be32(&immr->im_cpm.cp_fec1.fec_mii_speed,
365 ((bd->bi_intfreq + 4999999) / 5000000) << 1);
367 #if defined(CONFIG_MPC885) && defined(WANT_MII)
368 /* use MDC for MII */
369 setbits_be16(&immr->im_ioport.iop_pdpar, 0x0080);
370 clrbits_be16(&immr->im_ioport.iop_pddir, 0x0080);
374 #if defined(CONFIG_ETHER_ON_FEC1)
376 #if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
378 #if !defined(CONFIG_RMII)
380 setbits_be16(&immr->im_ioport.iop_papar, 0xf830);
381 setbits_be16(&immr->im_ioport.iop_padir, 0x0830);
382 clrbits_be16(&immr->im_ioport.iop_padir, 0xf000);
384 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00001001);
385 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00001001);
387 setbits_be16(&immr->im_ioport.iop_pcpar, 0x000c);
388 clrbits_be16(&immr->im_ioport.iop_pcdir, 0x000c);
390 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000003);
391 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000003);
392 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000003);
394 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
398 #if !defined(CONFIG_FEC1_PHY_NORXERR)
399 setbits_be16(&immr->im_ioport.iop_papar, 0x1000);
400 clrbits_be16(&immr->im_ioport.iop_padir, 0x1000);
402 setbits_be16(&immr->im_ioport.iop_papar, 0xe810);
403 setbits_be16(&immr->im_ioport.iop_padir, 0x0810);
404 clrbits_be16(&immr->im_ioport.iop_padir, 0xe000);
406 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00000001);
407 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00000001);
409 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
410 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000050);
412 #endif /* !CONFIG_RMII */
416 * Configure all of port D for MII.
418 out_be16(&immr->im_ioport.iop_pdpar, 0x1fff);
419 out_be16(&immr->im_ioport.iop_pddir, 0x1fff);
421 #if defined(CONFIG_TARGET_MCR3000)
422 out_be16(&immr->im_ioport.iop_papar, 0xBBFF);
423 out_be16(&immr->im_ioport.iop_padir, 0x04F0);
424 out_be16(&immr->im_ioport.iop_paodr, 0x0000);
426 out_be32(&immr->im_cpm.cp_pbpar, 0x000133FF);
427 out_be32(&immr->im_cpm.cp_pbdir, 0x0003BF0F);
428 out_be16(&immr->im_cpm.cp_pbodr, 0x0000);
430 out_be16(&immr->im_ioport.iop_pcpar, 0x0400);
431 out_be16(&immr->im_ioport.iop_pcdir, 0x0080);
432 out_be16(&immr->im_ioport.iop_pcso , 0x0D53);
433 out_be16(&immr->im_ioport.iop_pcint, 0x0000);
435 out_be16(&immr->im_ioport.iop_pdpar, 0x03FE);
436 out_be16(&immr->im_ioport.iop_pddir, 0x1C09);
438 setbits_be32(&immr->im_ioport.utmode, 0x80);
442 #endif /* CONFIG_ETHER_ON_FEC1 */
443 } else if (fecidx == 1) {
444 #if defined(CONFIG_ETHER_ON_FEC2)
446 #if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
448 #if !defined(CONFIG_RMII)
449 setbits_be32(&immr->im_cpm.cp_pepar, 0x0003fffc);
450 setbits_be32(&immr->im_cpm.cp_pedir, 0x0003fffc);
451 clrbits_be32(&immr->im_cpm.cp_peso, 0x000087fc);
452 setbits_be32(&immr->im_cpm.cp_peso, 0x00037800);
454 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
457 #if !defined(CONFIG_FEC2_PHY_NORXERR)
458 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000010);
459 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000010);
460 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000010);
462 setbits_be32(&immr->im_cpm.cp_pepar, 0x00039620);
463 setbits_be32(&immr->im_cpm.cp_pedir, 0x00039620);
464 setbits_be32(&immr->im_cpm.cp_peso, 0x00031000);
465 clrbits_be32(&immr->im_cpm.cp_peso, 0x00008620);
467 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
468 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000028);
469 #endif /* CONFIG_RMII */
471 #endif /* CONFIG_MPC885 */
473 #endif /* CONFIG_ETHER_ON_FEC2 */
477 static int fec_reset(fec_t __iomem *fecp)
482 * A delay is required between a reset of the FEC block and
483 * initialization of other FEC registers because the reset takes
484 * some time to complete. If you don't delay, subsequent writes
485 * to FEC registers might get killed by the reset routine which is
489 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
490 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
491 (i < FEC_RESET_DELAY); ++i)
494 if (i == FEC_RESET_DELAY)
500 static int fec_init(struct eth_device *dev, struct bd_info *bd)
502 struct ether_fcc_info_s *efis = dev->priv;
503 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
504 fec_t __iomem *fecp =
505 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
508 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
509 /* the MII interface is connected to FEC1
510 * so for the miiphy_xxx function to work we must
511 * call mii_init since fec_halt messes the thing up
513 if (efis->ether_index != 0)
517 if (fec_reset(fecp) < 0)
518 printf("FEC_RESET_DELAY timeout\n");
520 /* We use strictly polling mode only
522 out_be32(&fecp->fec_imask, 0);
524 /* Clear any pending interrupt
526 out_be32(&fecp->fec_ievent, 0xffc0);
528 /* No need to set the IVEC register */
530 /* Set station address
532 #define ea dev->enetaddr
533 out_be32(&fecp->fec_addr_low, (ea[0] << 24) | (ea[1] << 16) |
534 (ea[2] << 8) | ea[3]);
535 out_be16(&fecp->fec_addr_high, (ea[4] << 8) | ea[5]);
538 #if defined(CONFIG_CMD_CDP)
540 * Turn on multicast address hash table
542 out_be32(&fecp->fec_hash_table_high, 0xffffffff);
543 out_be32(&fecp->fec_hash_table_low, 0xffffffff);
545 /* Clear multicast address hash table
547 out_be32(&fecp->fec_hash_table_high, 0);
548 out_be32(&fecp->fec_hash_table_low, 0);
551 /* Set maximum receive buffer size.
553 out_be32(&fecp->fec_r_buff_size, PKT_MAXBLR_SIZE);
555 /* Set maximum frame length
557 out_be32(&fecp->fec_r_hash, PKT_MAXBUF_SIZE);
560 * Setup Buffers and Buffer Descriptors
566 rtx = (struct common_buf_desc __iomem *)
567 (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
569 * Setup Receiver Buffer Descriptors (13.14.24.18)
573 for (i = 0; i < PKTBUFSRX; i++) {
574 out_be16(&rtx->rxbd[i].cbd_sc, BD_ENET_RX_EMPTY);
575 out_be16(&rtx->rxbd[i].cbd_datlen, 0); /* Reset */
576 out_be32(&rtx->rxbd[i].cbd_bufaddr, (uint)net_rx_packets[i]);
578 setbits_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc, BD_ENET_RX_WRAP);
581 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
585 for (i = 0; i < TX_BUF_CNT; i++) {
586 out_be16(&rtx->txbd[i].cbd_sc, BD_ENET_TX_LAST | BD_ENET_TX_TC);
587 out_be16(&rtx->txbd[i].cbd_datlen, 0); /* Reset */
588 out_be32(&rtx->txbd[i].cbd_bufaddr, (uint)txbuf);
590 setbits_be16(&rtx->txbd[TX_BUF_CNT - 1].cbd_sc, BD_ENET_TX_WRAP);
592 /* Set receive and transmit descriptor base
594 out_be32(&fecp->fec_r_des_start, (__force unsigned int)rtx->rxbd);
595 out_be32(&fecp->fec_x_des_start, (__force unsigned int)rtx->txbd);
599 /* Half duplex mode */
600 out_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT);
601 out_be32(&fecp->fec_x_cntrl, 0);
603 /* Enable big endian and don't care about SDMA FC.
605 out_be32(&fecp->fec_fun_code, 0x78000000);
608 * Setup the pin configuration of the FEC
610 fec_pin_init(efis->ether_index);
616 * Now enable the transmit and receive processing
618 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
620 if (efis->phy_addr == -1) {
621 #ifdef CONFIG_SYS_DISCOVER_PHY
623 * wait for the PHY to wake up after reset
625 efis->actual_phy_addr = mii_discover_phy(dev);
627 if (efis->actual_phy_addr == -1) {
628 printf("Unable to discover phy!\n");
632 efis->actual_phy_addr = -1;
635 efis->actual_phy_addr = efis->phy_addr;
638 #if defined(CONFIG_MII) && defined(CONFIG_RMII)
640 * adapt the RMII speed to the speed of the phy
642 if (miiphy_speed(dev->name, efis->actual_phy_addr) == _100BASET)
648 #if defined(CONFIG_MII)
650 * adapt to the half/full speed settings
652 if (miiphy_duplex(dev->name, efis->actual_phy_addr) == FULL)
653 fec_full_duplex(dev);
655 fec_half_duplex(dev);
658 /* And last, try to fill Rx Buffer Descriptors */
659 /* Descriptor polling active */
660 out_be32(&fecp->fec_r_des_active, 0x01000000);
662 efis->initialized = 1;
668 static void fec_halt(struct eth_device *dev)
670 struct ether_fcc_info_s *efis = dev->priv;
671 fec_t __iomem *fecp =
672 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
675 /* avoid halt if initialized; mii gets stuck otherwise */
676 if (!efis->initialized)
680 * A delay is required between a reset of the FEC block and
681 * initialization of other FEC registers because the reset takes
682 * some time to complete. If you don't delay, subsequent writes
683 * to FEC registers might get killed by the reset routine which is
687 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
688 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
689 (i < FEC_RESET_DELAY); ++i)
692 if (i == FEC_RESET_DELAY) {
693 printf("FEC_RESET_DELAY timeout\n");
697 efis->initialized = 0;
700 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
702 /* Make MII read/write commands for the FEC.
705 #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
708 #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
709 (REG & 0x1f) << 18) | \
712 /* Interrupt events/masks.
714 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
715 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
716 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
717 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
718 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
719 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
720 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
721 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
722 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
723 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
725 /* send command to phy using mii, wait for result */
727 mii_send(uint mii_cmd)
732 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
734 ep = &immr->im_cpm.cp_fec;
736 out_be32(&ep->fec_mii_data, mii_cmd); /* command to phy */
738 /* wait for mii complete */
740 while (!(in_be32(&ep->fec_ievent) & FEC_ENET_MII)) {
742 printf("mii_send STUCK!\n");
746 mii_reply = in_be32(&ep->fec_mii_data); /* result from phy */
747 out_be32(&ep->fec_ievent, FEC_ENET_MII); /* clear MII complete */
748 return mii_reply & 0xffff; /* data read from phy */
752 #if defined(CONFIG_SYS_DISCOVER_PHY)
753 static int mii_discover_phy(struct eth_device *dev)
755 #define MAX_PHY_PASSES 11
761 phyaddr = -1; /* didn't find a PHY yet */
762 for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
764 /* PHY may need more time to recover from reset.
765 * The LXT970 needs 50ms typical, no maximum is
766 * specified, so wait 10ms before try again.
767 * With 11 passes this gives it 100ms to wake up.
769 udelay(10000); /* wait 10ms */
771 for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
772 phytype = mii_send(mk_mii_read(phyno, MII_PHYSID2));
773 if (phytype != 0xffff) {
775 phytype |= mii_send(mk_mii_read(phyno,
781 printf("No PHY device found.\n");
785 #endif /* CONFIG_SYS_DISCOVER_PHY */
787 #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && !defined(CONFIG_BITBANGMII)
789 /****************************************************************************
790 * mii_init -- Initialize the MII via FEC 1 for MII command without ethernet
791 * This function is a subset of eth_init
792 ****************************************************************************
794 static void __mii_init(void)
796 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
797 fec_t __iomem *fecp = &immr->im_cpm.cp_fec;
799 if (fec_reset(fecp) < 0)
800 printf("FEC_RESET_DELAY timeout\n");
802 /* We use strictly polling mode only
804 out_be32(&fecp->fec_imask, 0);
806 /* Clear any pending interrupt
808 out_be32(&fecp->fec_ievent, 0xffc0);
810 /* Now enable the transmit and receive processing
812 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
821 /* Setup the pin configuration of the FEC(s)
823 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
824 fec_pin_init(ether_fcc_info[i].ether_index);
827 /*****************************************************************************
828 * Read and write a MII PHY register, routines used by MII Utilities
830 * FIXME: These routines are expected to return 0 on success, but mii_send
831 * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
832 * no PHY connected...
833 * For now always return 0.
834 * FIXME: These routines only work after calling eth_init() at least once!
835 * Otherwise they hang in mii_send() !!! Sorry!
836 *****************************************************************************/
838 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
840 unsigned short value = 0;
841 short rdreg; /* register working value */
843 rdreg = mii_send(mk_mii_read(addr, reg));
849 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
852 (void)mii_send(mk_mii_write(addr, reg, value));