1 // SPDX-License-Identifier: GPL-2.0+
12 #include <asm/cpm_8xx.h>
13 #include <asm/global_data.h>
15 #include <linux/delay.h>
18 #include <linux/mii.h>
20 DECLARE_GLOBAL_DATA_PTR;
22 /* define WANT_MII when MII support is required */
23 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_FEC1_PHY) || defined(CONFIG_FEC2_PHY)
32 #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
33 #error "CONFIG_MII has to be defined!"
38 #if defined(CONFIG_RMII) && !defined(WANT_MII)
39 #error RMII support is unusable without a working PHY.
42 #ifdef CONFIG_SYS_DISCOVER_PHY
43 static int mii_discover_phy(struct udevice *dev);
46 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg);
47 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
50 static struct ether_fcc_info_s
59 #if defined(CONFIG_ETHER_ON_FEC1)
62 offsetof(immap_t, im_cpm.cp_fec1),
69 #if defined(CONFIG_ETHER_ON_FEC2)
72 offsetof(immap_t, im_cpm.cp_fec2),
80 /* Ethernet Transmit and Receive Buffers */
81 #define DBUF_LENGTH 1520
87 #define PKT_MAXBUF_SIZE 1518
88 #define PKT_MINBUF_SIZE 64
89 #define PKT_MAXBLR_SIZE 1520
92 static char txbuf[DBUF_LENGTH] __aligned(8);
94 #error txbuf must be aligned.
97 static uint rxIdx; /* index of the current RX buffer */
98 static uint txIdx; /* index of the current TX buffer */
101 * FEC Ethernet Tx and Rx buffer descriptors allocated at the
102 * immr->udata_bd address on Dual-Port RAM
103 * Provide for Double Buffering
106 struct common_buf_desc {
107 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
108 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
111 static struct common_buf_desc __iomem *rtx;
113 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
114 static void __mii_init(void);
117 static int fec_probe(struct udevice *dev)
119 struct ether_fcc_info_s *efis = dev_get_priv(dev);
120 int index = dev_get_driver_data(dev);
123 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++) {
124 if (ether_fcc_info[i].ether_index != index)
127 memcpy(efis, ðer_fcc_info[i], sizeof(*efis));
129 efis->actual_phy_addr = -1;
131 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
133 struct mii_dev *mdiodev = mdio_alloc();
136 strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
137 mdiodev->read = fec8xx_miiphy_read;
138 mdiodev->write = fec8xx_miiphy_write;
140 retval = mdio_register(mdiodev);
148 static int fec_send(struct udevice *dev, void *packet, int length)
151 struct ether_fcc_info_s *efis = dev_get_priv(dev);
152 fec_t __iomem *fecp =
153 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
159 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
165 printf("TX not ready\n");
167 out_be32(&rtx->txbd[txIdx].cbd_bufaddr, (uint)packet);
168 out_be16(&rtx->txbd[txIdx].cbd_datlen, length);
169 setbits_be16(&rtx->txbd[txIdx].cbd_sc,
170 BD_ENET_TX_READY | BD_ENET_TX_LAST);
172 /* Activate transmit Buffer Descriptor polling */
173 /* Descriptor polling active */
174 out_be32(&fecp->fec_x_des_active, 0x01000000);
177 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
183 printf("TX timeout\n");
185 /* return only status bits */;
186 rc = in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_STATS;
188 txIdx = (txIdx + 1) % TX_BUF_CNT;
193 static int fec_recv(struct udevice *dev, int flags, uchar **packetp)
197 /* section 16.9.23.2 */
198 if (in_be16(&rtx->rxbd[rxIdx].cbd_sc) & BD_ENET_RX_EMPTY)
201 length = in_be16(&rtx->rxbd[rxIdx].cbd_datlen);
203 if (!(in_be16(&rtx->rxbd[rxIdx].cbd_sc) & 0x003f)) {
204 uchar *rx = net_rx_packets[rxIdx];
206 #if defined(CONFIG_CMD_CDP)
207 if ((rx[0] & 1) != 0 &&
208 memcmp((uchar *)rx, net_bcast_ethaddr, 6) != 0 &&
209 !is_cdp_packet((uchar *)rx))
220 static int fec_free_pkt(struct udevice *dev, uchar *packet, int length)
222 struct ether_fcc_info_s *efis = dev_get_priv(dev);
223 fec_t __iomem *fecp =
224 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
226 /* Give the buffer back to the FEC. */
227 out_be16(&rtx->rxbd[rxIdx].cbd_datlen, 0);
229 /* wrap around buffer index when necessary */
230 if ((rxIdx + 1) >= PKTBUFSRX) {
231 out_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc,
232 BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
235 out_be16(&rtx->rxbd[rxIdx].cbd_sc, BD_ENET_RX_EMPTY);
239 /* Try to fill Buffer Descriptors */
240 /* Descriptor polling active */
241 out_be32(&fecp->fec_r_des_active, 0x01000000);
246 /**************************************************************
248 * FEC Ethernet Initialization Routine
250 *************************************************************/
252 #define FEC_ECNTRL_PINMUX 0x00000004
253 #define FEC_ECNTRL_ETHER_EN 0x00000002
254 #define FEC_ECNTRL_RESET 0x00000001
256 #define FEC_RCNTRL_BC_REJ 0x00000010
257 #define FEC_RCNTRL_PROM 0x00000008
258 #define FEC_RCNTRL_MII_MODE 0x00000004
259 #define FEC_RCNTRL_DRT 0x00000002
260 #define FEC_RCNTRL_LOOP 0x00000001
262 #define FEC_TCNTRL_FDEN 0x00000004
263 #define FEC_TCNTRL_HBC 0x00000002
264 #define FEC_TCNTRL_GTS 0x00000001
266 #define FEC_RESET_DELAY 50
268 #if defined(CONFIG_RMII)
270 static inline void fec_10Mbps(struct udevice *dev)
272 struct ether_fcc_info_s *efis = dev_get_priv(dev);
273 int fecidx = efis->ether_index;
274 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
275 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
277 if ((unsigned int)fecidx >= 2)
280 setbits_be32(&immr->im_cpm.cp_cptr, mask);
283 static inline void fec_100Mbps(struct udevice *dev)
285 struct ether_fcc_info_s *efis = dev_get_priv(dev);
286 int fecidx = efis->ether_index;
287 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
288 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
290 if ((unsigned int)fecidx >= 2)
293 clrbits_be32(&immr->im_cpm.cp_cptr, mask);
298 static inline void fec_full_duplex(struct udevice *dev)
300 struct ether_fcc_info_s *efis = dev_get_priv(dev);
301 fec_t __iomem *fecp =
302 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
304 clrbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
305 setbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
308 static inline void fec_half_duplex(struct udevice *dev)
310 struct ether_fcc_info_s *efis = dev_get_priv(dev);
311 fec_t __iomem *fecp =
312 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
314 setbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
315 clrbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD disable */
318 static void fec_pin_init(int fecidx)
320 struct bd_info *bd = gd->bd;
321 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
324 * Set MII speed to 2.5 MHz or slightly below.
326 * According to the MPC860T (Rev. D) Fast ethernet controller user
328 * the MII management interface clock must be less than or equal
330 * This MDC frequency is equal to system clock / (2 * MII_SPEED).
331 * Then MII_SPEED = system_clock / 2 * 2,5 MHz.
333 * All MII configuration is done via FEC1 registers:
335 out_be32(&immr->im_cpm.cp_fec1.fec_mii_speed,
336 ((bd->bi_intfreq + 4999999) / 5000000) << 1);
338 #if defined(CONFIG_MPC885) && defined(WANT_MII)
339 /* use MDC for MII */
340 setbits_be16(&immr->im_ioport.iop_pdpar, 0x0080);
341 clrbits_be16(&immr->im_ioport.iop_pddir, 0x0080);
345 #if defined(CONFIG_ETHER_ON_FEC1)
347 #if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
349 #if !defined(CONFIG_RMII)
351 setbits_be16(&immr->im_ioport.iop_papar, 0xf830);
352 setbits_be16(&immr->im_ioport.iop_padir, 0x0830);
353 clrbits_be16(&immr->im_ioport.iop_padir, 0xf000);
355 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00001001);
356 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00001001);
358 setbits_be16(&immr->im_ioport.iop_pcpar, 0x000c);
359 clrbits_be16(&immr->im_ioport.iop_pcdir, 0x000c);
361 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000003);
362 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000003);
363 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000003);
365 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
369 #if !defined(CONFIG_FEC1_PHY_NORXERR)
370 setbits_be16(&immr->im_ioport.iop_papar, 0x1000);
371 clrbits_be16(&immr->im_ioport.iop_padir, 0x1000);
373 setbits_be16(&immr->im_ioport.iop_papar, 0xe810);
374 setbits_be16(&immr->im_ioport.iop_padir, 0x0810);
375 clrbits_be16(&immr->im_ioport.iop_padir, 0xe000);
377 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00000001);
378 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00000001);
380 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
381 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000050);
383 #endif /* !CONFIG_RMII */
387 * Configure all of port D for MII.
389 out_be16(&immr->im_ioport.iop_pdpar, 0x1fff);
390 out_be16(&immr->im_ioport.iop_pddir, 0x1fff);
392 #if defined(CONFIG_TARGET_MCR3000)
393 out_be16(&immr->im_ioport.iop_papar, 0xBBFF);
394 out_be16(&immr->im_ioport.iop_padir, 0x04F0);
395 out_be16(&immr->im_ioport.iop_paodr, 0x0000);
397 out_be32(&immr->im_cpm.cp_pbpar, 0x000133FF);
398 out_be32(&immr->im_cpm.cp_pbdir, 0x0003BF0F);
399 out_be16(&immr->im_cpm.cp_pbodr, 0x0000);
401 out_be16(&immr->im_ioport.iop_pcpar, 0x0400);
402 out_be16(&immr->im_ioport.iop_pcdir, 0x0080);
403 out_be16(&immr->im_ioport.iop_pcso , 0x0D53);
404 out_be16(&immr->im_ioport.iop_pcint, 0x0000);
406 out_be16(&immr->im_ioport.iop_pdpar, 0x03FE);
407 out_be16(&immr->im_ioport.iop_pddir, 0x1C09);
409 setbits_be32(&immr->im_ioport.utmode, 0x80);
413 #endif /* CONFIG_ETHER_ON_FEC1 */
414 } else if (fecidx == 1) {
415 #if defined(CONFIG_ETHER_ON_FEC2)
417 #if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
419 #if !defined(CONFIG_RMII)
420 setbits_be32(&immr->im_cpm.cp_pepar, 0x0003fffc);
421 setbits_be32(&immr->im_cpm.cp_pedir, 0x0003fffc);
422 clrbits_be32(&immr->im_cpm.cp_peso, 0x000087fc);
423 setbits_be32(&immr->im_cpm.cp_peso, 0x00037800);
425 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
428 #if !defined(CONFIG_FEC2_PHY_NORXERR)
429 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000010);
430 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000010);
431 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000010);
433 setbits_be32(&immr->im_cpm.cp_pepar, 0x00039620);
434 setbits_be32(&immr->im_cpm.cp_pedir, 0x00039620);
435 setbits_be32(&immr->im_cpm.cp_peso, 0x00031000);
436 clrbits_be32(&immr->im_cpm.cp_peso, 0x00008620);
438 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
439 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000028);
440 #endif /* CONFIG_RMII */
442 #endif /* CONFIG_MPC885 */
444 #endif /* CONFIG_ETHER_ON_FEC2 */
448 static int fec_reset(fec_t __iomem *fecp)
453 * A delay is required between a reset of the FEC block and
454 * initialization of other FEC registers because the reset takes
455 * some time to complete. If you don't delay, subsequent writes
456 * to FEC registers might get killed by the reset routine which is
460 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
461 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
462 (i < FEC_RESET_DELAY); ++i)
465 if (i == FEC_RESET_DELAY)
471 static int fec_start(struct udevice *dev)
473 struct eth_pdata *plat = dev_get_plat(dev);
474 struct ether_fcc_info_s *efis = dev_get_priv(dev);
475 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
476 fec_t __iomem *fecp =
477 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
480 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
481 /* the MII interface is connected to FEC1
482 * so for the miiphy_xxx function to work we must
483 * call mii_init since fec_halt messes the thing up
485 if (efis->ether_index != 0)
489 if (fec_reset(fecp) < 0)
490 printf("FEC_RESET_DELAY timeout\n");
492 /* We use strictly polling mode only
494 out_be32(&fecp->fec_imask, 0);
496 /* Clear any pending interrupt
498 out_be32(&fecp->fec_ievent, 0xffc0);
500 /* No need to set the IVEC register */
502 /* Set station address
504 #define ea plat->enetaddr
505 out_be32(&fecp->fec_addr_low, (ea[0] << 24) | (ea[1] << 16) |
506 (ea[2] << 8) | ea[3]);
507 out_be16(&fecp->fec_addr_high, (ea[4] << 8) | ea[5]);
510 #if defined(CONFIG_CMD_CDP)
512 * Turn on multicast address hash table
514 out_be32(&fecp->fec_hash_table_high, 0xffffffff);
515 out_be32(&fecp->fec_hash_table_low, 0xffffffff);
517 /* Clear multicast address hash table
519 out_be32(&fecp->fec_hash_table_high, 0);
520 out_be32(&fecp->fec_hash_table_low, 0);
523 /* Set maximum receive buffer size.
525 out_be32(&fecp->fec_r_buff_size, PKT_MAXBLR_SIZE);
527 /* Set maximum frame length
529 out_be32(&fecp->fec_r_hash, PKT_MAXBUF_SIZE);
532 * Setup Buffers and Buffer Descriptors
538 rtx = (struct common_buf_desc __iomem *)
539 (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
541 * Setup Receiver Buffer Descriptors (13.14.24.18)
545 for (i = 0; i < PKTBUFSRX; i++) {
546 out_be16(&rtx->rxbd[i].cbd_sc, BD_ENET_RX_EMPTY);
547 out_be16(&rtx->rxbd[i].cbd_datlen, 0); /* Reset */
548 out_be32(&rtx->rxbd[i].cbd_bufaddr, (uint)net_rx_packets[i]);
550 setbits_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc, BD_ENET_RX_WRAP);
553 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
557 for (i = 0; i < TX_BUF_CNT; i++) {
558 out_be16(&rtx->txbd[i].cbd_sc, BD_ENET_TX_LAST | BD_ENET_TX_TC);
559 out_be16(&rtx->txbd[i].cbd_datlen, 0); /* Reset */
560 out_be32(&rtx->txbd[i].cbd_bufaddr, (uint)txbuf);
562 setbits_be16(&rtx->txbd[TX_BUF_CNT - 1].cbd_sc, BD_ENET_TX_WRAP);
564 /* Set receive and transmit descriptor base
566 out_be32(&fecp->fec_r_des_start, (__force unsigned int)rtx->rxbd);
567 out_be32(&fecp->fec_x_des_start, (__force unsigned int)rtx->txbd);
571 /* Half duplex mode */
572 out_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT);
573 out_be32(&fecp->fec_x_cntrl, 0);
575 /* Enable big endian and don't care about SDMA FC.
577 out_be32(&fecp->fec_fun_code, 0x78000000);
580 * Setup the pin configuration of the FEC
582 fec_pin_init(efis->ether_index);
588 * Now enable the transmit and receive processing
590 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
592 if (efis->phy_addr == -1) {
593 #ifdef CONFIG_SYS_DISCOVER_PHY
595 * wait for the PHY to wake up after reset
597 efis->actual_phy_addr = mii_discover_phy(dev);
599 if (efis->actual_phy_addr == -1) {
600 printf("Unable to discover phy!\n");
604 efis->actual_phy_addr = -1;
607 efis->actual_phy_addr = efis->phy_addr;
610 #if defined(CONFIG_MII) && defined(CONFIG_RMII)
612 * adapt the RMII speed to the speed of the phy
614 if (miiphy_speed(dev->name, efis->actual_phy_addr) == _100BASET)
620 #if defined(CONFIG_MII)
622 * adapt to the half/full speed settings
624 if (miiphy_duplex(dev->name, efis->actual_phy_addr) == FULL)
625 fec_full_duplex(dev);
627 fec_half_duplex(dev);
630 /* And last, try to fill Rx Buffer Descriptors */
631 /* Descriptor polling active */
632 out_be32(&fecp->fec_r_des_active, 0x01000000);
634 efis->initialized = 1;
639 static void fec_stop(struct udevice *dev)
641 struct ether_fcc_info_s *efis = dev_get_priv(dev);
642 fec_t __iomem *fecp =
643 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
646 /* avoid halt if initialized; mii gets stuck otherwise */
647 if (!efis->initialized)
651 * A delay is required between a reset of the FEC block and
652 * initialization of other FEC registers because the reset takes
653 * some time to complete. If you don't delay, subsequent writes
654 * to FEC registers might get killed by the reset routine which is
658 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
659 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
660 (i < FEC_RESET_DELAY); ++i)
663 if (i == FEC_RESET_DELAY) {
664 printf("FEC_RESET_DELAY timeout\n");
668 efis->initialized = 0;
671 #if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
673 /* Make MII read/write commands for the FEC.
676 #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
679 #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
680 (REG & 0x1f) << 18) | \
683 /* Interrupt events/masks.
685 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
686 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
687 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
688 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
689 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
690 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
691 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
692 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
693 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
694 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
696 /* send command to phy using mii, wait for result */
698 mii_send(uint mii_cmd)
703 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
705 ep = &immr->im_cpm.cp_fec;
707 out_be32(&ep->fec_mii_data, mii_cmd); /* command to phy */
709 /* wait for mii complete */
711 while (!(in_be32(&ep->fec_ievent) & FEC_ENET_MII)) {
713 printf("mii_send STUCK!\n");
717 mii_reply = in_be32(&ep->fec_mii_data); /* result from phy */
718 out_be32(&ep->fec_ievent, FEC_ENET_MII); /* clear MII complete */
719 return mii_reply & 0xffff; /* data read from phy */
723 #if defined(CONFIG_SYS_DISCOVER_PHY)
724 static int mii_discover_phy(struct udevice *dev)
726 #define MAX_PHY_PASSES 11
732 phyaddr = -1; /* didn't find a PHY yet */
733 for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
735 /* PHY may need more time to recover from reset.
736 * The LXT970 needs 50ms typical, no maximum is
737 * specified, so wait 10ms before try again.
738 * With 11 passes this gives it 100ms to wake up.
740 udelay(10000); /* wait 10ms */
742 for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
743 phytype = mii_send(mk_mii_read(phyno, MII_PHYSID2));
744 if (phytype != 0xffff) {
746 phytype |= mii_send(mk_mii_read(phyno,
752 printf("No PHY device found.\n");
756 #endif /* CONFIG_SYS_DISCOVER_PHY */
758 #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && !defined(CONFIG_BITBANGMII)
760 /****************************************************************************
761 * mii_init -- Initialize the MII via FEC 1 for MII command without ethernet
762 * This function is a subset of eth_init
763 ****************************************************************************
765 static void __mii_init(void)
767 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
768 fec_t __iomem *fecp = &immr->im_cpm.cp_fec;
770 if (fec_reset(fecp) < 0)
771 printf("FEC_RESET_DELAY timeout\n");
773 /* We use strictly polling mode only
775 out_be32(&fecp->fec_imask, 0);
777 /* Clear any pending interrupt
779 out_be32(&fecp->fec_ievent, 0xffc0);
781 /* Now enable the transmit and receive processing
783 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
792 /* Setup the pin configuration of the FEC(s)
794 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
795 fec_pin_init(ether_fcc_info[i].ether_index);
798 /*****************************************************************************
799 * Read and write a MII PHY register, routines used by MII Utilities
801 * FIXME: These routines are expected to return 0 on success, but mii_send
802 * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
803 * no PHY connected...
804 * For now always return 0.
805 * FIXME: These routines only work after calling eth_init() at least once!
806 * Otherwise they hang in mii_send() !!! Sorry!
807 *****************************************************************************/
809 int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
811 unsigned short value = 0;
812 short rdreg; /* register working value */
814 rdreg = mii_send(mk_mii_read(addr, reg));
820 int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
823 (void)mii_send(mk_mii_write(addr, reg, value));
829 static const struct eth_ops fec_ops = {
834 .free_pkt = fec_free_pkt,
837 static const struct udevice_id fec_ids[] = {
838 #ifdef CONFIG_ETHER_ON_FEC1
840 .compatible = "fsl,pq1-fec1",
844 #ifdef CONFIG_ETHER_ON_FEC2
846 .compatible = "fsl,pq1-fec2",
853 U_BOOT_DRIVER(fec) = {
859 .priv_auto = sizeof(struct ether_fcc_info_s),
860 .plat_auto = sizeof(struct eth_pdata),