1 // SPDX-License-Identifier: GPL-2.0+
3 * Freescale Three Speed Ethernet Controller driver
5 * Copyright 2004-2011, 2013 Freescale Semiconductor, Inc.
6 * (C) Copyright 2003, Motorola, Inc.
18 #include <linux/delay.h>
19 #include <linux/errno.h>
20 #include <asm/processor.h>
24 /* Default initializations for TSEC controllers. */
26 static struct tsec_info_struct tsec_info[] = {
28 STD_TSEC_INFO(1), /* TSEC1 */
31 STD_TSEC_INFO(2), /* TSEC2 */
33 #ifdef CONFIG_MPC85XX_FEC
35 .regs = TSEC_GET_REGS(2, 0x2000),
36 .devname = CONFIG_MPC85XX_FEC_NAME,
37 .phyaddr = FEC_PHY_ADDR,
39 .mii_devname = DEFAULT_MII_NAME
43 STD_TSEC_INFO(3), /* TSEC3 */
46 STD_TSEC_INFO(4), /* TSEC4 */
49 #endif /* CONFIG_DM_ETH */
51 #define TBIANA_SETTINGS ( \
52 TBIANA_ASYMMETRIC_PAUSE \
53 | TBIANA_SYMMETRIC_PAUSE \
54 | TBIANA_FULL_DUPLEX \
57 /* By default force the TBI PHY into 1000Mbps full duplex when in SGMII mode */
58 #ifndef CONFIG_TSEC_TBICR_SETTINGS
59 #define CONFIG_TSEC_TBICR_SETTINGS ( \
65 #endif /* CONFIG_TSEC_TBICR_SETTINGS */
67 /* Configure the TBI for SGMII operation */
68 static void tsec_configure_serdes(struct tsec_private *priv)
71 * Access TBI PHY registers at given TSEC register offset as opposed
72 * to the register offset used for external PHY accesses
74 tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
75 0, TBI_ANA, TBIANA_SETTINGS);
76 tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
77 0, TBI_TBICON, TBICON_CLK_SELECT);
78 tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
79 0, TBI_CR, CONFIG_TSEC_TBICR_SETTINGS);
82 /* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c
83 * and this is the ethernet-crc method needed for TSEC -- and perhaps
84 * some other adapter -- hash tables
86 #define CRCPOLY_LE 0xedb88320
87 static u32 ether_crc(size_t len, unsigned char const *p)
95 for (i = 0; i < 8; i++)
96 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
98 /* an reverse the bits, cuz of way they arrive -- last-first */
99 crc = (crc >> 16) | (crc << 16);
100 crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00);
101 crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0);
102 crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc);
103 crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa);
107 /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
109 /* Set the appropriate hash bit for the given addr */
112 * The algorithm works like so:
113 * 1) Take the Destination Address (ie the multicast address), and
114 * do a CRC on it (little endian), and reverse the bits of the
116 * 2) Use the 8 most significant bits as a hash into a 256-entry
117 * table. The table is controlled through 8 32-bit registers:
118 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is entry
119 * 255. This means that the 3 most significant bits in the
120 * hash index which gaddr register to use, and the 5 other bits
121 * indicate which bit (assuming an IBM numbering scheme, which
122 * for PowerPC (tm) is usually the case) in the register holds
125 #ifndef CONFIG_DM_ETH
126 static int tsec_mcast_addr(struct eth_device *dev, const u8 *mcast_mac,
129 static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join)
132 struct tsec_private *priv = (struct tsec_private *)dev->priv;
133 struct tsec __iomem *regs = priv->regs;
135 u8 whichbit, whichreg;
137 result = ether_crc(MAC_ADDR_LEN, mcast_mac);
138 whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */
139 whichreg = result >> 29; /* the 3 MSB = which reg to set it in */
141 value = BIT(31 - whichbit);
144 setbits_be32(®s->hash.gaddr0 + whichreg, value);
146 clrbits_be32(®s->hash.gaddr0 + whichreg, value);
152 * Initialized required registers to appropriate values, zeroing
153 * those we don't care about (unless zero is bad, in which case,
154 * choose a more appropriate value)
156 static void init_registers(struct tsec __iomem *regs)
159 out_be32(®s->ievent, IEVENT_INIT_CLEAR);
161 out_be32(®s->imask, IMASK_INIT_CLEAR);
163 out_be32(®s->hash.iaddr0, 0);
164 out_be32(®s->hash.iaddr1, 0);
165 out_be32(®s->hash.iaddr2, 0);
166 out_be32(®s->hash.iaddr3, 0);
167 out_be32(®s->hash.iaddr4, 0);
168 out_be32(®s->hash.iaddr5, 0);
169 out_be32(®s->hash.iaddr6, 0);
170 out_be32(®s->hash.iaddr7, 0);
172 out_be32(®s->hash.gaddr0, 0);
173 out_be32(®s->hash.gaddr1, 0);
174 out_be32(®s->hash.gaddr2, 0);
175 out_be32(®s->hash.gaddr3, 0);
176 out_be32(®s->hash.gaddr4, 0);
177 out_be32(®s->hash.gaddr5, 0);
178 out_be32(®s->hash.gaddr6, 0);
179 out_be32(®s->hash.gaddr7, 0);
181 out_be32(®s->rctrl, 0x00000000);
183 /* Init RMON mib registers */
184 memset((void *)®s->rmon, 0, sizeof(regs->rmon));
186 out_be32(®s->rmon.cam1, 0xffffffff);
187 out_be32(®s->rmon.cam2, 0xffffffff);
189 out_be32(®s->mrblr, MRBLR_INIT_SETTINGS);
191 out_be32(®s->minflr, MINFLR_INIT_SETTINGS);
193 out_be32(®s->attr, ATTR_INIT_SETTINGS);
194 out_be32(®s->attreli, ATTRELI_INIT_SETTINGS);
198 * Configure maccfg2 based on negotiated speed and duplex
199 * reported by PHY handling code
201 static void adjust_link(struct tsec_private *priv, struct phy_device *phydev)
203 struct tsec __iomem *regs = priv->regs;
207 printf("%s: No link.\n", phydev->dev->name);
211 /* clear all bits relative with interface mode */
212 ecntrl = in_be32(®s->ecntrl);
213 ecntrl &= ~ECNTRL_R100;
215 maccfg2 = in_be32(®s->maccfg2);
216 maccfg2 &= ~(MACCFG2_IF | MACCFG2_FULL_DUPLEX);
219 maccfg2 |= MACCFG2_FULL_DUPLEX;
221 switch (phydev->speed) {
223 maccfg2 |= MACCFG2_GMII;
227 maccfg2 |= MACCFG2_MII;
230 * Set R100 bit in all modes although
231 * it is only used in RGMII mode
233 if (phydev->speed == 100)
234 ecntrl |= ECNTRL_R100;
237 printf("%s: Speed was bad\n", phydev->dev->name);
241 out_be32(®s->ecntrl, ecntrl);
242 out_be32(®s->maccfg2, maccfg2);
244 printf("Speed: %d, %s duplex%s\n", phydev->speed,
245 (phydev->duplex) ? "full" : "half",
246 (phydev->port == PORT_FIBRE) ? ", fiber mode" : "");
250 * This returns the status bits of the device. The return value
251 * is never checked, and this is what the 8260 driver did, so we
252 * do the same. Presumably, this would be zero if there were no
255 #ifndef CONFIG_DM_ETH
256 static int tsec_send(struct eth_device *dev, void *packet, int length)
258 static int tsec_send(struct udevice *dev, void *packet, int length)
261 struct tsec_private *priv = (struct tsec_private *)dev->priv;
262 struct tsec __iomem *regs = priv->regs;
267 /* Find an empty buffer descriptor */
269 in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY;
271 if (i >= TOUT_LOOP) {
272 printf("%s: tsec: tx buffers full\n", dev->name);
277 out_be32(&priv->txbd[priv->tx_idx].bufptr, (u32)packet);
278 out_be16(&priv->txbd[priv->tx_idx].length, length);
279 status = in_be16(&priv->txbd[priv->tx_idx].status);
280 out_be16(&priv->txbd[priv->tx_idx].status, status |
281 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT));
283 /* Tell the DMA to go */
284 out_be32(®s->tstat, TSTAT_CLEAR_THALT);
286 /* Wait for buffer to be transmitted */
288 in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY;
290 if (i >= TOUT_LOOP) {
291 printf("%s: tsec: tx error\n", dev->name);
296 priv->tx_idx = (priv->tx_idx + 1) % TX_BUF_CNT;
297 result = in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_STATS;
302 #ifndef CONFIG_DM_ETH
303 static int tsec_recv(struct eth_device *dev)
305 struct tsec_private *priv = (struct tsec_private *)dev->priv;
306 struct tsec __iomem *regs = priv->regs;
308 while (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) {
309 int length = in_be16(&priv->rxbd[priv->rx_idx].length);
310 u16 status = in_be16(&priv->rxbd[priv->rx_idx].status);
311 uchar *packet = net_rx_packets[priv->rx_idx];
313 /* Send the packet up if there were no errors */
314 if (!(status & RXBD_STATS))
315 net_process_received_packet(packet, length - 4);
317 printf("Got error %x\n", (status & RXBD_STATS));
319 out_be16(&priv->rxbd[priv->rx_idx].length, 0);
322 /* Set the wrap bit if this is the last element in the list */
323 if ((priv->rx_idx + 1) == PKTBUFSRX)
325 out_be16(&priv->rxbd[priv->rx_idx].status, status);
327 priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
330 if (in_be32(®s->ievent) & IEVENT_BSY) {
331 out_be32(®s->ievent, IEVENT_BSY);
332 out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
338 static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
340 struct tsec_private *priv = (struct tsec_private *)dev->priv;
341 struct tsec __iomem *regs = priv->regs;
344 if (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) {
345 int length = in_be16(&priv->rxbd[priv->rx_idx].length);
346 u16 status = in_be16(&priv->rxbd[priv->rx_idx].status);
349 /* Send the packet up if there were no errors */
350 if (!(status & RXBD_STATS)) {
351 buf = in_be32(&priv->rxbd[priv->rx_idx].bufptr);
352 *packetp = (uchar *)buf;
355 printf("Got error %x\n", (status & RXBD_STATS));
359 if (in_be32(®s->ievent) & IEVENT_BSY) {
360 out_be32(®s->ievent, IEVENT_BSY);
361 out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
367 static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length)
369 struct tsec_private *priv = (struct tsec_private *)dev->priv;
372 out_be16(&priv->rxbd[priv->rx_idx].length, 0);
375 /* Set the wrap bit if this is the last element in the list */
376 if ((priv->rx_idx + 1) == PKTBUFSRX)
378 out_be16(&priv->rxbd[priv->rx_idx].status, status);
380 priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
386 /* Stop the interface */
387 #ifndef CONFIG_DM_ETH
388 static void tsec_halt(struct eth_device *dev)
390 static void tsec_halt(struct udevice *dev)
393 struct tsec_private *priv = (struct tsec_private *)dev->priv;
394 struct tsec __iomem *regs = priv->regs;
396 clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
397 setbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
399 while ((in_be32(®s->ievent) & (IEVENT_GRSC | IEVENT_GTSC))
400 != (IEVENT_GRSC | IEVENT_GTSC))
403 clrbits_be32(®s->maccfg1, MACCFG1_TX_EN | MACCFG1_RX_EN);
405 /* Shut down the PHY, as needed */
406 phy_shutdown(priv->phydev);
409 #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129
411 * When MACCFG1[Rx_EN] is enabled during system boot as part
412 * of the eTSEC port initialization sequence,
413 * the eTSEC Rx logic may not be properly initialized.
415 void redundant_init(struct tsec_private *priv)
417 struct tsec __iomem *regs = priv->regs;
420 static const u8 pkt[] = {
421 0x00, 0x1e, 0x4f, 0x12, 0xcb, 0x2c, 0x00, 0x25,
422 0x64, 0xbb, 0xd1, 0xab, 0x08, 0x00, 0x45, 0x00,
423 0x00, 0x5c, 0xdd, 0x22, 0x00, 0x00, 0x80, 0x01,
424 0x1f, 0x71, 0x0a, 0xc1, 0x14, 0x22, 0x0a, 0xc1,
425 0x14, 0x6a, 0x08, 0x00, 0xef, 0x7e, 0x02, 0x00,
426 0x94, 0x05, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
427 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
428 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
429 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
430 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
431 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
432 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
433 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
436 /* Enable promiscuous mode */
437 setbits_be32(®s->rctrl, 0x8);
438 /* Enable loopback mode */
439 setbits_be32(®s->maccfg1, MACCFG1_LOOPBACK);
440 /* Enable transmit and receive */
441 setbits_be32(®s->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN);
443 /* Tell the DMA it is clear to go */
444 setbits_be32(®s->dmactrl, DMACTRL_INIT_SETTINGS);
445 out_be32(®s->tstat, TSTAT_CLEAR_THALT);
446 out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
447 clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
452 tsec_send(priv->dev, (void *)pkt, sizeof(pkt));
454 /* Wait for buffer to be received */
456 in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY;
458 if (t >= 10 * TOUT_LOOP) {
459 printf("%s: tsec: rx error\n", priv->dev->name);
464 if (!memcmp(pkt, net_rx_packets[priv->rx_idx], sizeof(pkt)))
467 out_be16(&priv->rxbd[priv->rx_idx].length, 0);
469 if ((priv->rx_idx + 1) == PKTBUFSRX)
471 out_be16(&priv->rxbd[priv->rx_idx].status, status);
472 priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
474 if (in_be32(®s->ievent) & IEVENT_BSY) {
475 out_be32(®s->ievent, IEVENT_BSY);
476 out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
479 printf("loopback recv packet error!\n");
480 clrbits_be32(®s->maccfg1, MACCFG1_RX_EN);
482 setbits_be32(®s->maccfg1, MACCFG1_RX_EN);
484 } while ((count++ < 4) && (fail == 1));
487 panic("eTSEC init fail!\n");
488 /* Disable promiscuous mode */
489 clrbits_be32(®s->rctrl, 0x8);
490 /* Disable loopback mode */
491 clrbits_be32(®s->maccfg1, MACCFG1_LOOPBACK);
496 * Set up the buffers and their descriptors, and bring up the
499 static void startup_tsec(struct tsec_private *priv)
501 struct tsec __iomem *regs = priv->regs;
505 /* reset the indices to zero */
508 #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129
512 /* Point to the buffer descriptors */
513 out_be32(®s->tbase, (u32)&priv->txbd[0]);
514 out_be32(®s->rbase, (u32)&priv->rxbd[0]);
516 /* Initialize the Rx Buffer descriptors */
517 for (i = 0; i < PKTBUFSRX; i++) {
518 out_be16(&priv->rxbd[i].status, RXBD_EMPTY);
519 out_be16(&priv->rxbd[i].length, 0);
520 out_be32(&priv->rxbd[i].bufptr, (u32)net_rx_packets[i]);
522 status = in_be16(&priv->rxbd[PKTBUFSRX - 1].status);
523 out_be16(&priv->rxbd[PKTBUFSRX - 1].status, status | RXBD_WRAP);
525 /* Initialize the TX Buffer Descriptors */
526 for (i = 0; i < TX_BUF_CNT; i++) {
527 out_be16(&priv->txbd[i].status, 0);
528 out_be16(&priv->txbd[i].length, 0);
529 out_be32(&priv->txbd[i].bufptr, 0);
531 status = in_be16(&priv->txbd[TX_BUF_CNT - 1].status);
532 out_be16(&priv->txbd[TX_BUF_CNT - 1].status, status | TXBD_WRAP);
534 #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129
536 if ((SVR_MAJ(svr) == 1) || IS_SVR_REV(svr, 2, 0))
537 redundant_init(priv);
539 /* Enable Transmit and Receive */
540 setbits_be32(®s->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN);
542 /* Tell the DMA it is clear to go */
543 setbits_be32(®s->dmactrl, DMACTRL_INIT_SETTINGS);
544 out_be32(®s->tstat, TSTAT_CLEAR_THALT);
545 out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
546 clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
550 * Initializes data structures and registers for the controller,
551 * and brings the interface up. Returns the link status, meaning
552 * that it returns success if the link is up, failure otherwise.
553 * This allows U-Boot to find the first active controller.
555 #ifndef CONFIG_DM_ETH
556 static int tsec_init(struct eth_device *dev, bd_t *bd)
558 static int tsec_init(struct udevice *dev)
561 struct tsec_private *priv = (struct tsec_private *)dev->priv;
563 struct eth_pdata *pdata = dev_get_platdata(dev);
565 struct eth_device *pdata = dev;
567 struct tsec __iomem *regs = priv->regs;
571 /* Make sure the controller is stopped */
574 /* Init MACCFG2. Defaults to GMII */
575 out_be32(®s->maccfg2, MACCFG2_INIT_SETTINGS);
578 out_be32(®s->ecntrl, ECNTRL_INIT_SETTINGS);
581 * Copy the station address into the address registers.
582 * For a station address of 0x12345678ABCD in transmission
583 * order (BE), MACnADDR1 is set to 0xCDAB7856 and
584 * MACnADDR2 is set to 0x34120000.
586 tempval = (pdata->enetaddr[5] << 24) | (pdata->enetaddr[4] << 16) |
587 (pdata->enetaddr[3] << 8) | pdata->enetaddr[2];
589 out_be32(®s->macstnaddr1, tempval);
591 tempval = (pdata->enetaddr[1] << 24) | (pdata->enetaddr[0] << 16);
593 out_be32(®s->macstnaddr2, tempval);
595 /* Clear out (for the most part) the other registers */
596 init_registers(regs);
598 /* Ready the device for tx/rx */
601 /* Start up the PHY */
602 ret = phy_startup(priv->phydev);
604 printf("Could not initialize PHY %s\n",
605 priv->phydev->dev->name);
609 adjust_link(priv, priv->phydev);
611 /* If there's no link, fail */
612 return priv->phydev->link ? 0 : -1;
615 static phy_interface_t tsec_get_interface(struct tsec_private *priv)
617 struct tsec __iomem *regs = priv->regs;
620 ecntrl = in_be32(®s->ecntrl);
622 if (ecntrl & ECNTRL_SGMII_MODE)
623 return PHY_INTERFACE_MODE_SGMII;
625 if (ecntrl & ECNTRL_TBI_MODE) {
626 if (ecntrl & ECNTRL_REDUCED_MODE)
627 return PHY_INTERFACE_MODE_RTBI;
629 return PHY_INTERFACE_MODE_TBI;
632 if (ecntrl & ECNTRL_REDUCED_MODE) {
633 phy_interface_t interface;
635 if (ecntrl & ECNTRL_REDUCED_MII_MODE)
636 return PHY_INTERFACE_MODE_RMII;
638 interface = priv->interface;
641 * This isn't autodetected, so it must
642 * be set by the platform code.
644 if (interface == PHY_INTERFACE_MODE_RGMII_ID ||
645 interface == PHY_INTERFACE_MODE_RGMII_TXID ||
646 interface == PHY_INTERFACE_MODE_RGMII_RXID)
649 return PHY_INTERFACE_MODE_RGMII;
652 if (priv->flags & TSEC_GIGABIT)
653 return PHY_INTERFACE_MODE_GMII;
655 return PHY_INTERFACE_MODE_MII;
659 * Discover which PHY is attached to the device, and configure it
660 * properly. If the PHY is not recognized, then return 0
661 * (failure). Otherwise, return 1
663 static int init_phy(struct tsec_private *priv)
665 struct phy_device *phydev;
666 struct tsec __iomem *regs = priv->regs;
667 u32 supported = (SUPPORTED_10baseT_Half |
668 SUPPORTED_10baseT_Full |
669 SUPPORTED_100baseT_Half |
670 SUPPORTED_100baseT_Full);
672 if (priv->flags & TSEC_GIGABIT)
673 supported |= SUPPORTED_1000baseT_Full;
675 /* Assign a Physical address to the TBI */
676 out_be32(®s->tbipa, priv->tbiaddr);
678 priv->interface = tsec_get_interface(priv);
680 if (priv->interface == PHY_INTERFACE_MODE_SGMII)
681 tsec_configure_serdes(priv);
683 phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev,
688 phydev->supported &= supported;
689 phydev->advertising = phydev->supported;
691 priv->phydev = phydev;
698 #ifndef CONFIG_DM_ETH
700 * Initialize device structure. Returns success if PHY
701 * initialization succeeded (i.e. if it recognizes the PHY)
703 static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info)
705 struct tsec_private *priv;
706 struct eth_device *dev;
709 dev = (struct eth_device *)malloc(sizeof(*dev));
714 memset(dev, 0, sizeof(*dev));
716 priv = (struct tsec_private *)malloc(sizeof(*priv));
723 priv->regs = tsec_info->regs;
724 priv->phyregs_sgmii = tsec_info->miiregs_sgmii;
726 priv->phyaddr = tsec_info->phyaddr;
727 priv->tbiaddr = CONFIG_SYS_TBIPA_VALUE;
728 priv->flags = tsec_info->flags;
730 strcpy(dev->name, tsec_info->devname);
731 priv->interface = tsec_info->interface;
732 priv->bus = miiphy_get_dev_by_name(tsec_info->mii_devname);
736 dev->init = tsec_init;
737 dev->halt = tsec_halt;
738 dev->send = tsec_send;
739 dev->recv = tsec_recv;
740 dev->mcast = tsec_mcast_addr;
742 /* Tell U-Boot to get the addr from the env */
743 for (i = 0; i < 6; i++)
744 dev->enetaddr[i] = 0;
749 setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
750 udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
751 clrbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
753 /* Try to initialize PHY here, and return */
754 return init_phy(priv);
758 * Initialize all the TSEC devices
760 * Returns the number of TSEC devices that were initialized
762 int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num)
767 for (i = 0; i < num; i++) {
768 int ret = tsec_initialize(bis, &tsecs[i]);
777 int tsec_standard_init(bd_t *bis)
779 struct fsl_pq_mdio_info info;
781 info.regs = TSEC_GET_MDIO_REGS_BASE(1);
782 info.name = DEFAULT_MII_NAME;
784 fsl_pq_mdio_init(bis, &info);
786 return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
788 #else /* CONFIG_DM_ETH */
789 int tsec_probe(struct udevice *dev)
791 struct eth_pdata *pdata = dev_get_platdata(dev);
792 struct tsec_private *priv = dev_get_priv(dev);
793 struct ofnode_phandle_args phandle_args;
794 u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
795 struct fsl_pq_mdio_info mdio_info;
796 const char *phy_mode;
801 pdata->iobase = (phys_addr_t)dev_read_addr(dev);
802 priv->regs = (struct tsec *)pdata->iobase;
804 if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
806 printf("phy-handle does not exist under tsec %s\n", dev->name);
809 int reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
814 parent = ofnode_get_parent(phandle_args.node);
815 if (!ofnode_valid(parent)) {
816 printf("No parent node for PHY?\n");
820 reg = ofnode_get_addr_index(parent, 0);
821 priv->phyregs_sgmii = (struct tsec_mii_mng *)
822 (reg + TSEC_MDIO_REGS_OFFSET);
824 ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
827 ofnode_read_u32(phandle_args.node, "reg", &tbiaddr);
829 priv->tbiaddr = tbiaddr;
831 phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
833 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
834 if (pdata->phy_interface == -1) {
835 printf("Invalid PHY interface '%s'\n", phy_mode);
838 priv->interface = pdata->phy_interface;
840 /* Initialize flags */
841 priv->flags = TSEC_GIGABIT;
842 if (priv->interface == PHY_INTERFACE_MODE_SGMII)
843 priv->flags |= TSEC_SGMII;
845 mdio_info.regs = priv->phyregs_sgmii;
846 mdio_info.name = (char *)dev->name;
847 ret = fsl_pq_mdio_init(NULL, &mdio_info);
852 setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
853 udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
854 clrbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
857 priv->bus = miiphy_get_dev_by_name(dev->name);
859 /* Try to initialize PHY here, and return */
860 return !init_phy(priv);
863 int tsec_remove(struct udevice *dev)
865 struct tsec_private *priv = dev->priv;
868 mdio_unregister(priv->bus);
869 mdio_free(priv->bus);
874 static const struct eth_ops tsec_ops = {
878 .free_pkt = tsec_free_pkt,
880 .mcast = tsec_mcast_addr,
883 static const struct udevice_id tsec_ids[] = {
884 { .compatible = "fsl,etsec2" },
888 U_BOOT_DRIVER(eth_tsec) = {
891 .of_match = tsec_ids,
893 .remove = tsec_remove,
895 .priv_auto_alloc_size = sizeof(struct tsec_private),
896 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
897 .flags = DM_FLAG_ALLOC_PRIV_DMA,
899 #endif /* CONFIG_DM_ETH */