2 * Freescale Three Speed Ethernet Controller driver
4 * This software may be used and distributed according to the
5 * terms of the GNU Public License, Version 2, incorporated
8 * Copyright 2004 Freescale Semiconductor.
9 * (C) Copyright 2003, Motorola, Inc.
22 #if defined(CONFIG_TSEC_ENET)
26 DECLARE_GLOBAL_DATA_PTR;
30 static uint rxIdx; /* index of the current RX buffer */
31 static uint txIdx; /* index of the current TX buffer */
33 typedef volatile struct rtxbd {
34 txbd8_t txbd[TX_BUF_CNT];
35 rxbd8_t rxbd[PKTBUFSRX];
38 struct tsec_info_struct {
41 unsigned int phyregidx;
44 /* The tsec_info structure contains 3 values which the
45 * driver uses to determine how to operate a given ethernet
46 * device. The information needed is:
47 * phyaddr - The address of the PHY which is attached to
50 * flags - This variable indicates whether the device
51 * supports gigabit speed ethernet, and whether it should be
54 * phyregidx - This variable specifies which ethernet device
55 * controls the MII Management registers which are connected
56 * to the PHY. For now, only TSEC1 (index 0) has
57 * access to the PHYs, so all of the entries have "0".
59 * The values specified in the table are taken from the board's
60 * config file in include/configs/. When implementing a new
61 * board with ethernet capability, it is necessary to define:
65 * for n = 1,2,3, etc. And for FEC:
69 static struct tsec_info_struct tsec_info[] = {
70 #if defined(CONFIG_MPC85XX_TSEC1) || defined(CONFIG_MPC83XX_TSEC1)
71 {TSEC1_PHY_ADDR, TSEC_GIGABIT, TSEC1_PHYIDX},
72 #elif defined(CONFIG_MPC86XX_TSEC1)
73 {TSEC1_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC1_PHYIDX},
77 #if defined(CONFIG_MPC85XX_TSEC2) || defined(CONFIG_MPC83XX_TSEC2)
78 {TSEC2_PHY_ADDR, TSEC_GIGABIT, TSEC2_PHYIDX},
79 #elif defined(CONFIG_MPC86XX_TSEC2)
80 {TSEC2_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC2_PHYIDX},
84 #ifdef CONFIG_MPC85XX_FEC
85 {FEC_PHY_ADDR, 0, FEC_PHYIDX},
87 #if defined(CONFIG_MPC85XX_TSEC3) || defined(CONFIG_MPC83XX_TSEC3) || defined(CONFIG_MPC86XX_TSEC3)
88 {TSEC3_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC3_PHYIDX},
92 #if defined(CONFIG_MPC85XX_TSEC4) || defined(CONFIG_MPC83XX_TSEC4) || defined(CONFIG_MPC86XX_TSEC4)
93 {TSEC4_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC4_PHYIDX},
100 #define MAXCONTROLLERS (4)
102 static int relocated = 0;
104 static struct tsec_private *privlist[MAXCONTROLLERS];
107 static RTXBD rtx __attribute__ ((aligned(8)));
109 #error "rtx must be 64-bit aligned"
112 static int tsec_send(struct eth_device *dev,
113 volatile void *packet, int length);
114 static int tsec_recv(struct eth_device *dev);
115 static int tsec_init(struct eth_device *dev, bd_t * bd);
116 static void tsec_halt(struct eth_device *dev);
117 static void init_registers(volatile tsec_t * regs);
118 static void startup_tsec(struct eth_device *dev);
119 static int init_phy(struct eth_device *dev);
120 void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
121 uint read_phy_reg(struct tsec_private *priv, uint regnum);
122 struct phy_info *get_phy_info(struct eth_device *dev);
123 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
124 static void adjust_link(struct eth_device *dev);
125 static void relocate_cmds(void);
126 static int tsec_miiphy_write(char *devname, unsigned char addr,
127 unsigned char reg, unsigned short value);
128 static int tsec_miiphy_read(char *devname, unsigned char addr,
129 unsigned char reg, unsigned short *value);
131 /* Initialize device structure. Returns success if PHY
132 * initialization succeeded (i.e. if it recognizes the PHY)
134 int tsec_initialize(bd_t * bis, int index, char *devname)
136 struct eth_device *dev;
138 struct tsec_private *priv;
140 dev = (struct eth_device *)malloc(sizeof *dev);
145 memset(dev, 0, sizeof *dev);
147 priv = (struct tsec_private *)malloc(sizeof(*priv));
152 privlist[index] = priv;
153 priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index * TSEC_SIZE);
154 priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
155 tsec_info[index].phyregidx *
158 priv->phyaddr = tsec_info[index].phyaddr;
159 priv->flags = tsec_info[index].flags;
161 sprintf(dev->name, devname);
164 dev->init = tsec_init;
165 dev->halt = tsec_halt;
166 dev->send = tsec_send;
167 dev->recv = tsec_recv;
169 /* Tell u-boot to get the addr from the env */
170 for (i = 0; i < 6; i++)
171 dev->enetaddr[i] = 0;
176 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
177 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
179 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
180 && !defined(BITBANGMII)
181 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
184 /* Try to initialize PHY here, and return */
185 return init_phy(dev);
188 /* Initializes data structures and registers for the controller,
189 * and brings the interface up. Returns the link status, meaning
190 * that it returns success if the link is up, failure otherwise.
191 * This allows u-boot to find the first active controller.
193 int tsec_init(struct eth_device *dev, bd_t * bd)
196 char tmpbuf[MAC_ADDR_LEN];
198 struct tsec_private *priv = (struct tsec_private *)dev->priv;
199 volatile tsec_t *regs = priv->regs;
201 /* Make sure the controller is stopped */
204 /* Init MACCFG2. Defaults to GMII */
205 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
208 regs->ecntrl = ECNTRL_INIT_SETTINGS;
210 /* Copy the station address into the address registers.
211 * Backwards, because little endian MACS are dumb */
212 for (i = 0; i < MAC_ADDR_LEN; i++) {
213 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
215 regs->macstnaddr1 = *((uint *) (tmpbuf));
217 tempval = *((uint *) (tmpbuf + 4));
219 regs->macstnaddr2 = tempval;
221 /* reset the indices to zero */
225 /* Clear out (for the most part) the other registers */
226 init_registers(regs);
228 /* Ready the device for tx/rx */
231 /* If there's no link, fail */
236 /* Write value to the device's PHY through the registers
237 * specified in priv, modifying the register specified in regnum.
238 * It will wait for the write to be done (or for a timeout to
239 * expire) before exiting
241 void write_phy_reg(struct tsec_private *priv, uint regnum, uint value)
243 volatile tsec_t *regbase = priv->phyregs;
244 uint phyid = priv->phyaddr;
245 int timeout = 1000000;
247 regbase->miimadd = (phyid << 8) | regnum;
248 regbase->miimcon = value;
252 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
255 /* Reads register regnum on the device's PHY through the
256 * registers specified in priv. It lowers and raises the read
257 * command, and waits for the data to become valid (miimind
258 * notvalid bit cleared), and the bus to cease activity (miimind
259 * busy bit cleared), and then returns the value
261 uint read_phy_reg(struct tsec_private *priv, uint regnum)
264 volatile tsec_t *regbase = priv->phyregs;
265 uint phyid = priv->phyaddr;
267 /* Put the address of the phy, and the register
268 * number into MIIMADD */
269 regbase->miimadd = (phyid << 8) | regnum;
271 /* Clear the command register, and wait */
272 regbase->miimcom = 0;
275 /* Initiate a read command, and wait */
276 regbase->miimcom = MIIM_READ_COMMAND;
279 /* Wait for the the indication that the read is done */
280 while ((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
282 /* Grab the value read from the PHY */
283 value = regbase->miimstat;
288 /* Discover which PHY is attached to the device, and configure it
289 * properly. If the PHY is not recognized, then return 0
290 * (failure). Otherwise, return 1
292 static int init_phy(struct eth_device *dev)
294 struct tsec_private *priv = (struct tsec_private *)dev->priv;
295 struct phy_info *curphy;
296 volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
298 /* Assign a Physical address to the TBI */
299 regs->tbipa = TBIPA_VALUE;
300 regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
301 regs->tbipa = TBIPA_VALUE;
304 /* Reset MII (due to new addresses) */
305 priv->phyregs->miimcfg = MIIMCFG_RESET;
307 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
309 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
314 /* Get the cmd structure corresponding to the attached
316 curphy = get_phy_info(dev);
318 if (NULL == curphy) {
319 printf("%s: No PHY found\n", dev->name);
324 priv->phyinfo = curphy;
326 phy_run_commands(priv, priv->phyinfo->config);
332 * Returns which value to write to the control register.
333 * For 10/100, the value is slightly different
335 uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
337 if (priv->flags & TSEC_GIGABIT)
338 return MIIM_CONTROL_INIT;
343 /* Parse the status register for link, and then do
346 uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
349 * Wait if PHY is capable of autonegotiation and autonegotiation
352 mii_reg = read_phy_reg(priv, MIIM_STATUS);
353 if ((mii_reg & PHY_BMSR_AUTN_ABLE)
354 && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
357 puts("Waiting for PHY auto negotiation to complete");
358 while (!((mii_reg & PHY_BMSR_AUTN_COMP)
359 && (mii_reg & MIIM_STATUS_LINK))) {
363 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
364 puts(" TIMEOUT !\n");
369 if ((i++ % 1000) == 0) {
372 udelay(1000); /* 1 ms */
373 mii_reg = read_phy_reg(priv, MIIM_STATUS);
377 udelay(500000); /* another 500 ms (results in faster booting) */
385 /* Parse the 88E1011's status register for speed and duplex
388 uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
392 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
394 if (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
395 (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
398 puts("Waiting for PHY realtime link");
399 while (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
400 (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
404 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
405 puts(" TIMEOUT !\n");
410 if ((i++ % 1000) == 0) {
413 udelay(1000); /* 1 ms */
414 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
417 udelay(500000); /* another 500 ms (results in faster booting) */
420 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
425 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
428 case MIIM_88E1011_PHYSTAT_GBIT:
431 case MIIM_88E1011_PHYSTAT_100:
441 /* Parse the cis8201's status register for speed and duplex
444 uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
448 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
453 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
455 case MIIM_CIS8201_AUXCONSTAT_GBIT:
458 case MIIM_CIS8201_AUXCONSTAT_100:
469 /* Parse the vsc8244's status register for speed and duplex
472 uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
476 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
481 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
483 case MIIM_VSC8244_AUXCONSTAT_GBIT:
486 case MIIM_VSC8244_AUXCONSTAT_100:
497 /* Parse the DM9161's status register for speed and duplex
500 uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
502 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
507 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
516 * Hack to write all 4 PHYs with the LED values
518 uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
521 volatile tsec_t *regbase = priv->phyregs;
522 int timeout = 1000000;
524 for (phyid = 0; phyid < 4; phyid++) {
525 regbase->miimadd = (phyid << 8) | mii_reg;
526 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
530 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
533 return MIIM_CIS8204_SLEDCON_INIT;
536 uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
538 if (priv->flags & TSEC_REDUCED)
539 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
541 return MIIM_CIS8204_EPHYCON_INIT;
544 /* Initialized required registers to appropriate values, zeroing
545 * those we don't care about (unless zero is bad, in which case,
546 * choose a more appropriate value)
548 static void init_registers(volatile tsec_t * regs)
551 regs->ievent = IEVENT_INIT_CLEAR;
553 regs->imask = IMASK_INIT_CLEAR;
555 regs->hash.iaddr0 = 0;
556 regs->hash.iaddr1 = 0;
557 regs->hash.iaddr2 = 0;
558 regs->hash.iaddr3 = 0;
559 regs->hash.iaddr4 = 0;
560 regs->hash.iaddr5 = 0;
561 regs->hash.iaddr6 = 0;
562 regs->hash.iaddr7 = 0;
564 regs->hash.gaddr0 = 0;
565 regs->hash.gaddr1 = 0;
566 regs->hash.gaddr2 = 0;
567 regs->hash.gaddr3 = 0;
568 regs->hash.gaddr4 = 0;
569 regs->hash.gaddr5 = 0;
570 regs->hash.gaddr6 = 0;
571 regs->hash.gaddr7 = 0;
573 regs->rctrl = 0x00000000;
575 /* Init RMON mib registers */
576 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
578 regs->rmon.cam1 = 0xffffffff;
579 regs->rmon.cam2 = 0xffffffff;
581 regs->mrblr = MRBLR_INIT_SETTINGS;
583 regs->minflr = MINFLR_INIT_SETTINGS;
585 regs->attr = ATTR_INIT_SETTINGS;
586 regs->attreli = ATTRELI_INIT_SETTINGS;
590 /* Configure maccfg2 based on negotiated speed and duplex
591 * reported by PHY handling code
593 static void adjust_link(struct eth_device *dev)
595 struct tsec_private *priv = (struct tsec_private *)dev->priv;
596 volatile tsec_t *regs = priv->regs;
599 if (priv->duplexity != 0)
600 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
602 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
604 switch (priv->speed) {
606 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
611 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
614 /* If We're in reduced mode, we need
615 * to say whether we're 10 or 100 MB.
617 if ((priv->speed == 100)
618 && (priv->flags & TSEC_REDUCED))
619 regs->ecntrl |= ECNTRL_R100;
621 regs->ecntrl &= ~(ECNTRL_R100);
624 printf("%s: Speed was bad\n", dev->name);
628 printf("Speed: %d, %s duplex\n", priv->speed,
629 (priv->duplexity) ? "full" : "half");
632 printf("%s: No link.\n", dev->name);
636 /* Set up the buffers and their descriptors, and bring up the
639 static void startup_tsec(struct eth_device *dev)
642 struct tsec_private *priv = (struct tsec_private *)dev->priv;
643 volatile tsec_t *regs = priv->regs;
645 /* Point to the buffer descriptors */
646 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
647 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
649 /* Initialize the Rx Buffer descriptors */
650 for (i = 0; i < PKTBUFSRX; i++) {
651 rtx.rxbd[i].status = RXBD_EMPTY;
652 rtx.rxbd[i].length = 0;
653 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
655 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
657 /* Initialize the TX Buffer Descriptors */
658 for (i = 0; i < TX_BUF_CNT; i++) {
659 rtx.txbd[i].status = 0;
660 rtx.txbd[i].length = 0;
661 rtx.txbd[i].bufPtr = 0;
663 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
665 /* Start up the PHY */
666 phy_run_commands(priv, priv->phyinfo->startup);
669 /* Enable Transmit and Receive */
670 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
672 /* Tell the DMA it is clear to go */
673 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
674 regs->tstat = TSTAT_CLEAR_THALT;
675 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
678 /* This returns the status bits of the device. The return value
679 * is never checked, and this is what the 8260 driver did, so we
680 * do the same. Presumably, this would be zero if there were no
683 static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
687 struct tsec_private *priv = (struct tsec_private *)dev->priv;
688 volatile tsec_t *regs = priv->regs;
690 /* Find an empty buffer descriptor */
691 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
692 if (i >= TOUT_LOOP) {
693 debug("%s: tsec: tx buffers full\n", dev->name);
698 rtx.txbd[txIdx].bufPtr = (uint) packet;
699 rtx.txbd[txIdx].length = length;
700 rtx.txbd[txIdx].status |=
701 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
703 /* Tell the DMA to go */
704 regs->tstat = TSTAT_CLEAR_THALT;
706 /* Wait for buffer to be transmitted */
707 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
708 if (i >= TOUT_LOOP) {
709 debug("%s: tsec: tx error\n", dev->name);
714 txIdx = (txIdx + 1) % TX_BUF_CNT;
715 result = rtx.txbd[txIdx].status & TXBD_STATS;
720 static int tsec_recv(struct eth_device *dev)
723 struct tsec_private *priv = (struct tsec_private *)dev->priv;
724 volatile tsec_t *regs = priv->regs;
726 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
728 length = rtx.rxbd[rxIdx].length;
730 /* Send the packet up if there were no errors */
731 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
732 NetReceive(NetRxPackets[rxIdx], length - 4);
734 printf("Got error %x\n",
735 (rtx.rxbd[rxIdx].status & RXBD_STATS));
738 rtx.rxbd[rxIdx].length = 0;
740 /* Set the wrap bit if this is the last element in the list */
741 rtx.rxbd[rxIdx].status =
742 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
744 rxIdx = (rxIdx + 1) % PKTBUFSRX;
747 if (regs->ievent & IEVENT_BSY) {
748 regs->ievent = IEVENT_BSY;
749 regs->rstat = RSTAT_CLEAR_RHALT;
756 /* Stop the interface */
757 static void tsec_halt(struct eth_device *dev)
759 struct tsec_private *priv = (struct tsec_private *)dev->priv;
760 volatile tsec_t *regs = priv->regs;
762 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
763 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
765 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
767 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
769 /* Shut down the PHY, as needed */
770 phy_run_commands(priv, priv->phyinfo->shutdown);
773 struct phy_info phy_info_M88E1011S = {
777 (struct phy_cmd[]){ /* config */
778 /* Reset and configure the PHY */
779 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
781 {0x1e, 0x200c, NULL},
785 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
786 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
787 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
788 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
791 (struct phy_cmd[]){ /* startup */
792 /* Status is read once to clear old link state */
793 {MIIM_STATUS, miim_read, NULL},
795 {MIIM_STATUS, miim_read, &mii_parse_sr},
796 /* Read the status */
797 {MIIM_88E1011_PHY_STATUS, miim_read,
798 &mii_parse_88E1011_psr},
801 (struct phy_cmd[]){ /* shutdown */
806 struct phy_info phy_info_M88E1111S = {
810 (struct phy_cmd[]){ /* config */
811 /* Reset and configure the PHY */
812 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
814 {0x1e, 0x200c, NULL},
818 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
819 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
820 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
821 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
824 (struct phy_cmd[]){ /* startup */
825 /* Status is read once to clear old link state */
826 {MIIM_STATUS, miim_read, NULL},
828 {MIIM_STATUS, miim_read, &mii_parse_sr},
829 /* Read the status */
830 {MIIM_88E1011_PHY_STATUS, miim_read,
831 &mii_parse_88E1011_psr},
834 (struct phy_cmd[]){ /* shutdown */
839 static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
842 uint mii_data = read_phy_reg(priv, mii_reg);
844 /* Setting MIIM_88E1145_PHY_EXT_CR */
845 if (priv->flags & TSEC_REDUCED)
847 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
852 static struct phy_info phy_info_M88E1145 = {
856 (struct phy_cmd[]){ /* config */
863 /* Reset and configure the PHY */
864 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
865 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
866 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
867 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
869 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
870 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
871 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
874 (struct phy_cmd[]){ /* startup */
875 /* Status is read once to clear old link state */
876 {MIIM_STATUS, miim_read, NULL},
878 {MIIM_STATUS, miim_read, &mii_parse_sr},
879 {MIIM_88E1111_PHY_LED_CONTROL,
880 MIIM_88E1111_PHY_LED_DIRECT, NULL},
881 /* Read the Status */
882 {MIIM_88E1011_PHY_STATUS, miim_read,
883 &mii_parse_88E1011_psr},
886 (struct phy_cmd[]){ /* shutdown */
891 struct phy_info phy_info_cis8204 = {
895 (struct phy_cmd[]){ /* config */
896 /* Override PHY config settings */
897 {MIIM_CIS8201_AUX_CONSTAT,
898 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
899 /* Configure some basic stuff */
900 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
901 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
902 &mii_cis8204_fixled},
903 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
904 &mii_cis8204_setmode},
907 (struct phy_cmd[]){ /* startup */
908 /* Read the Status (2x to make sure link is right) */
909 {MIIM_STATUS, miim_read, NULL},
911 {MIIM_STATUS, miim_read, &mii_parse_sr},
912 /* Read the status */
913 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
917 (struct phy_cmd[]){ /* shutdown */
923 struct phy_info phy_info_cis8201 = {
927 (struct phy_cmd[]){ /* config */
928 /* Override PHY config settings */
929 {MIIM_CIS8201_AUX_CONSTAT,
930 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
931 /* Set up the interface mode */
932 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
934 /* Configure some basic stuff */
935 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
938 (struct phy_cmd[]){ /* startup */
939 /* Read the Status (2x to make sure link is right) */
940 {MIIM_STATUS, miim_read, NULL},
942 {MIIM_STATUS, miim_read, &mii_parse_sr},
943 /* Read the status */
944 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
948 (struct phy_cmd[]){ /* shutdown */
952 struct phy_info phy_info_VSC8244 = {
956 (struct phy_cmd[]){ /* config */
957 /* Override PHY config settings */
958 /* Configure some basic stuff */
959 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
962 (struct phy_cmd[]){ /* startup */
963 /* Read the Status (2x to make sure link is right) */
964 {MIIM_STATUS, miim_read, NULL},
966 {MIIM_STATUS, miim_read, &mii_parse_sr},
967 /* Read the status */
968 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
972 (struct phy_cmd[]){ /* shutdown */
977 struct phy_info phy_info_dm9161 = {
981 (struct phy_cmd[]){ /* config */
982 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
983 /* Do not bypass the scrambler/descrambler */
984 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
985 /* Clear 10BTCSR to default */
986 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
988 /* Configure some basic stuff */
989 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
990 /* Restart Auto Negotiation */
991 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
994 (struct phy_cmd[]){ /* startup */
995 /* Status is read once to clear old link state */
996 {MIIM_STATUS, miim_read, NULL},
998 {MIIM_STATUS, miim_read, &mii_parse_sr},
999 /* Read the status */
1000 {MIIM_DM9161_SCSR, miim_read,
1001 &mii_parse_dm9161_scsr},
1004 (struct phy_cmd[]){ /* shutdown */
1009 uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1013 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
1016 case MIIM_LXT971_SR2_10HDX:
1018 priv->duplexity = 0;
1020 case MIIM_LXT971_SR2_10FDX:
1022 priv->duplexity = 1;
1024 case MIIM_LXT971_SR2_100HDX:
1026 priv->duplexity = 0;
1029 priv->duplexity = 1;
1034 priv->duplexity = 0;
1040 static struct phy_info phy_info_lxt971 = {
1044 (struct phy_cmd[]){ /* config */
1045 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1048 (struct phy_cmd[]){ /* startup - enable interrupts */
1049 /* { 0x12, 0x00f2, NULL }, */
1050 {MIIM_STATUS, miim_read, NULL},
1051 {MIIM_STATUS, miim_read, &mii_parse_sr},
1052 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1055 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1060 /* Parse the DP83865's link and auto-neg status register for speed and duplex
1063 uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1065 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1067 case MIIM_DP83865_SPD_1000:
1071 case MIIM_DP83865_SPD_100:
1081 if (mii_reg & MIIM_DP83865_DPX_FULL)
1082 priv->duplexity = 1;
1084 priv->duplexity = 0;
1089 struct phy_info phy_info_dp83865 = {
1093 (struct phy_cmd[]){ /* config */
1094 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1097 (struct phy_cmd[]){ /* startup */
1098 /* Status is read once to clear old link state */
1099 {MIIM_STATUS, miim_read, NULL},
1100 /* Auto-negotiate */
1101 {MIIM_STATUS, miim_read, &mii_parse_sr},
1102 /* Read the link and auto-neg status */
1103 {MIIM_DP83865_LANR, miim_read,
1104 &mii_parse_dp83865_lanr},
1107 (struct phy_cmd[]){ /* shutdown */
1112 struct phy_info *phy_info[] = {
1117 &phy_info_M88E1011S,
1118 &phy_info_M88E1111S,
1127 /* Grab the identifier of the device's PHY, and search through
1128 * all of the known PHYs to see if one matches. If so, return
1129 * it, if not, return NULL
1131 struct phy_info *get_phy_info(struct eth_device *dev)
1133 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1134 uint phy_reg, phy_ID;
1136 struct phy_info *theInfo = NULL;
1138 /* Grab the bits from PHYIR1, and put them in the upper half */
1139 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1140 phy_ID = (phy_reg & 0xffff) << 16;
1142 /* Grab the bits from PHYIR2, and put them in the lower half */
1143 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1144 phy_ID |= (phy_reg & 0xffff);
1146 /* loop through all the known PHY types, and find one that */
1147 /* matches the ID we read from the PHY. */
1148 for (i = 0; phy_info[i]; i++) {
1149 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
1150 theInfo = phy_info[i];
1153 if (theInfo == NULL) {
1154 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
1157 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
1163 /* Execute the given series of commands on the given device's
1164 * PHY, running functions as necessary
1166 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1170 volatile tsec_t *phyregs = priv->phyregs;
1172 phyregs->miimcfg = MIIMCFG_RESET;
1174 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1176 while (phyregs->miimind & MIIMIND_BUSY) ;
1178 for (i = 0; cmd->mii_reg != miim_end; i++) {
1179 if (cmd->mii_data == miim_read) {
1180 result = read_phy_reg(priv, cmd->mii_reg);
1182 if (cmd->funct != NULL)
1183 (*(cmd->funct)) (result, priv);
1186 if (cmd->funct != NULL)
1187 result = (*(cmd->funct)) (cmd->mii_reg, priv);
1189 result = cmd->mii_data;
1191 write_phy_reg(priv, cmd->mii_reg, result);
1198 /* Relocate the function pointers in the phy cmd lists */
1199 static void relocate_cmds(void)
1201 struct phy_cmd **cmdlistptr;
1202 struct phy_cmd *cmd;
1205 for (i = 0; phy_info[i]; i++) {
1206 /* First thing's first: relocate the pointers to the
1207 * PHY command structures (the structs were done) */
1208 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1210 phy_info[i]->name += gd->reloc_off;
1211 phy_info[i]->config =
1212 (struct phy_cmd *)((uint) phy_info[i]->config
1214 phy_info[i]->startup =
1215 (struct phy_cmd *)((uint) phy_info[i]->startup
1217 phy_info[i]->shutdown =
1218 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1221 cmdlistptr = &phy_info[i]->config;
1223 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1225 for (cmd = *cmdlistptr;
1226 cmd->mii_reg != miim_end;
1228 /* Only relocate non-NULL pointers */
1230 cmd->funct += gd->reloc_off;
1241 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
1242 && !defined(BITBANGMII)
1244 struct tsec_private *get_priv_for_phy(unsigned char phyaddr)
1248 for (i = 0; i < MAXCONTROLLERS; i++) {
1249 if (privlist[i]->phyaddr == phyaddr)
1257 * Read a MII PHY register.
1262 static int tsec_miiphy_read(char *devname, unsigned char addr,
1263 unsigned char reg, unsigned short *value)
1266 struct tsec_private *priv = get_priv_for_phy(addr);
1269 printf("Can't read PHY at address %d\n", addr);
1273 ret = (unsigned short)read_phy_reg(priv, reg);
1280 * Write a MII PHY register.
1285 static int tsec_miiphy_write(char *devname, unsigned char addr,
1286 unsigned char reg, unsigned short value)
1288 struct tsec_private *priv = get_priv_for_phy(addr);
1291 printf("Can't write PHY at address %d\n", addr);
1295 write_phy_reg(priv, reg, value);
1300 #endif /* defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
1301 && !defined(BITBANGMII) */
1303 #endif /* CONFIG_TSEC_ENET */