3 * Freescale Three Speed Ethernet Controller driver
5 * This software may be used and distributed according to the
6 * terms of the GNU Public License, Version 2, incorporated
9 * Copyright 2004 Freescale Semiconductor.
10 * (C) Copyright 2003, Motorola, Inc.
23 #if defined(CONFIG_TSEC_ENET)
27 DECLARE_GLOBAL_DATA_PTR;
31 static uint rxIdx; /* index of the current RX buffer */
32 static uint txIdx; /* index of the current TX buffer */
34 typedef volatile struct rtxbd {
35 txbd8_t txbd[TX_BUF_CNT];
36 rxbd8_t rxbd[PKTBUFSRX];
39 struct tsec_info_struct {
42 unsigned int phyregidx;
46 /* The tsec_info structure contains 3 values which the
47 * driver uses to determine how to operate a given ethernet
48 * device. For now, the structure is initialized with the
49 * knowledge that all current implementations have 2 TSEC
50 * devices, and one FEC. The information needed is:
51 * phyaddr - The address of the PHY which is attached to
54 * flags - This variable indicates whether the device
55 * supports gigabit speed ethernet, and whether it should be
58 * phyregidx - This variable specifies which ethernet device
59 * controls the MII Management registers which are connected
60 * to the PHY. For 8540/8560, only TSEC1 (index 0) has
61 * access to the PHYs, so all of the entries have "0".
63 * The values specified in the table are taken from the board's
64 * config file in include/configs/. When implementing a new
65 * board with ethernet capability, it is necessary to define:
75 static struct tsec_info_struct tsec_info[] = {
76 #if defined(CONFIG_MPC85XX_TSEC1) || defined(CONFIG_MPC83XX_TSEC1)
77 {TSEC1_PHY_ADDR, TSEC_GIGABIT, TSEC1_PHYIDX},
78 #elif defined(CONFIG_MPC86XX_TSEC1)
79 {TSEC1_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC1_PHYIDX},
83 #if defined(CONFIG_MPC85XX_TSEC2) || defined(CONFIG_MPC83XX_TSEC2)
84 {TSEC2_PHY_ADDR, TSEC_GIGABIT, TSEC2_PHYIDX},
85 #elif defined(CONFIG_MPC86XX_TSEC2)
86 {TSEC2_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC2_PHYIDX},
90 #ifdef CONFIG_MPC85XX_FEC
91 {FEC_PHY_ADDR, 0, FEC_PHYIDX},
93 #if defined(CONFIG_MPC85XX_TSEC3) || defined(CONFIG_MPC83XX_TSEC3) || defined(CONFIG_MPC86XX_TSEC3)
94 {TSEC3_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC3_PHYIDX},
98 #if defined(CONFIG_MPC85XX_TSEC4) || defined(CONFIG_MPC83XX_TSEC4)
99 {TSEC4_PHY_ADDR, TSEC_REDUCED, TSEC4_PHYIDX},
100 #elif defined(CONFIG_MPC86XX_TSEC4)
101 {TSEC4_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC4_PHYIDX},
108 #define MAXCONTROLLERS (4)
110 static int relocated = 0;
112 static struct tsec_private *privlist[MAXCONTROLLERS];
115 static RTXBD rtx __attribute__ ((aligned(8)));
117 #error "rtx must be 64-bit aligned"
120 static int tsec_send(struct eth_device* dev, volatile void *packet, int length);
121 static int tsec_recv(struct eth_device* dev);
122 static int tsec_init(struct eth_device* dev, bd_t * bd);
123 static void tsec_halt(struct eth_device* dev);
124 static void init_registers(volatile tsec_t *regs);
125 static void startup_tsec(struct eth_device *dev);
126 static int init_phy(struct eth_device *dev);
127 void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
128 uint read_phy_reg(struct tsec_private *priv, uint regnum);
129 struct phy_info * get_phy_info(struct eth_device *dev);
130 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
131 static void adjust_link(struct eth_device *dev);
132 static void relocate_cmds(void);
133 static int tsec_miiphy_write(char *devname, unsigned char addr,
134 unsigned char reg, unsigned short value);
135 static int tsec_miiphy_read(char *devname, unsigned char addr,
136 unsigned char reg, unsigned short *value);
138 /* Initialize device structure. Returns success if PHY
139 * initialization succeeded (i.e. if it recognizes the PHY)
141 int tsec_initialize(bd_t *bis, int index, char *devname)
143 struct eth_device* dev;
145 struct tsec_private *priv;
147 dev = (struct eth_device*) malloc(sizeof *dev);
152 memset(dev, 0, sizeof *dev);
154 priv = (struct tsec_private *) malloc(sizeof(*priv));
159 privlist[index] = priv;
160 priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index*TSEC_SIZE);
161 priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
162 tsec_info[index].phyregidx*TSEC_SIZE);
164 priv->phyaddr = tsec_info[index].phyaddr;
165 priv->flags = tsec_info[index].flags;
167 sprintf(dev->name, devname);
170 dev->init = tsec_init;
171 dev->halt = tsec_halt;
172 dev->send = tsec_send;
173 dev->recv = tsec_recv;
175 /* Tell u-boot to get the addr from the env */
177 dev->enetaddr[i] = 0;
183 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
184 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
186 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
187 && !defined(BITBANGMII)
188 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
191 /* Try to initialize PHY here, and return */
192 return init_phy(dev);
196 /* Initializes data structures and registers for the controller,
197 * and brings the interface up. Returns the link status, meaning
198 * that it returns success if the link is up, failure otherwise.
199 * This allows u-boot to find the first active controller. */
200 int tsec_init(struct eth_device* dev, bd_t * bd)
203 char tmpbuf[MAC_ADDR_LEN];
205 struct tsec_private *priv = (struct tsec_private *)dev->priv;
206 volatile tsec_t *regs = priv->regs;
208 /* Make sure the controller is stopped */
211 /* Init MACCFG2. Defaults to GMII */
212 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
215 regs->ecntrl = ECNTRL_INIT_SETTINGS;
217 /* Copy the station address into the address registers.
218 * Backwards, because little endian MACS are dumb */
219 for(i=0;i<MAC_ADDR_LEN;i++) {
220 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
222 regs->macstnaddr1 = *((uint *)(tmpbuf));
224 tempval = *((uint *)(tmpbuf +4));
226 regs->macstnaddr2 = tempval;
228 /* reset the indices to zero */
232 /* Clear out (for the most part) the other registers */
233 init_registers(regs);
235 /* Ready the device for tx/rx */
238 /* If there's no link, fail */
244 /* Write value to the device's PHY through the registers
245 * specified in priv, modifying the register specified in regnum.
246 * It will wait for the write to be done (or for a timeout to
247 * expire) before exiting
249 void write_phy_reg(struct tsec_private *priv, uint regnum, uint value)
251 volatile tsec_t *regbase = priv->phyregs;
252 uint phyid = priv->phyaddr;
255 regbase->miimadd = (phyid << 8) | regnum;
256 regbase->miimcon = value;
260 while((regbase->miimind & MIIMIND_BUSY) && timeout--);
264 /* Reads register regnum on the device's PHY through the
265 * registers specified in priv. It lowers and raises the read
266 * command, and waits for the data to become valid (miimind
267 * notvalid bit cleared), and the bus to cease activity (miimind
268 * busy bit cleared), and then returns the value
270 uint read_phy_reg(struct tsec_private *priv, uint regnum)
273 volatile tsec_t *regbase = priv->phyregs;
274 uint phyid = priv->phyaddr;
276 /* Put the address of the phy, and the register
277 * number into MIIMADD */
278 regbase->miimadd = (phyid << 8) | regnum;
280 /* Clear the command register, and wait */
281 regbase->miimcom = 0;
284 /* Initiate a read command, and wait */
285 regbase->miimcom = MIIM_READ_COMMAND;
288 /* Wait for the the indication that the read is done */
289 while((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY)));
291 /* Grab the value read from the PHY */
292 value = regbase->miimstat;
298 /* Discover which PHY is attached to the device, and configure it
299 * properly. If the PHY is not recognized, then return 0
300 * (failure). Otherwise, return 1
302 static int init_phy(struct eth_device *dev)
304 struct tsec_private *priv = (struct tsec_private *)dev->priv;
305 struct phy_info *curphy;
307 /* Assign a Physical address to the TBI */
310 volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
311 regs->tbipa = TBIPA_VALUE;
312 regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
313 regs->tbipa = TBIPA_VALUE;
317 /* Reset MII (due to new addresses) */
318 priv->phyregs->miimcfg = MIIMCFG_RESET;
320 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
322 while(priv->phyregs->miimind & MIIMIND_BUSY);
327 /* Get the cmd structure corresponding to the attached
329 curphy = get_phy_info(dev);
332 printf("%s: No PHY found\n", dev->name);
337 priv->phyinfo = curphy;
339 phy_run_commands(priv, priv->phyinfo->config);
345 /* Returns which value to write to the control register. */
346 /* For 10/100, the value is slightly different */
347 uint mii_cr_init(uint mii_reg, struct tsec_private *priv)
349 if(priv->flags & TSEC_GIGABIT)
350 return MIIM_CONTROL_INIT;
356 /* Parse the status register for link, and then do
357 * auto-negotiation */
358 uint mii_parse_sr(uint mii_reg, struct tsec_private *priv)
361 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
363 mii_reg = read_phy_reg(priv, MIIM_STATUS);
364 if ((mii_reg & PHY_BMSR_AUTN_ABLE) && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
367 puts ("Waiting for PHY auto negotiation to complete");
368 while (!((mii_reg & PHY_BMSR_AUTN_COMP) && (mii_reg & MIIM_STATUS_LINK))) {
372 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
373 puts (" TIMEOUT !\n");
378 if ((i++ % 1000) == 0) {
381 udelay (1000); /* 1 ms */
382 mii_reg = read_phy_reg(priv, MIIM_STATUS);
386 udelay (500000); /* another 500 ms (results in faster booting) */
395 /* Parse the 88E1011's status register for speed and duplex
397 uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private *priv)
401 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
403 if (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
404 (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
407 puts ("Waiting for PHY realtime link");
408 while (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
409 (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
413 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
414 puts (" TIMEOUT !\n");
419 if ((i++ % 1000) == 0) {
422 udelay (1000); /* 1 ms */
423 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
426 udelay (500000); /* another 500 ms (results in faster booting) */
429 if(mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
434 speed = (mii_reg &MIIM_88E1011_PHYSTAT_SPEED);
437 case MIIM_88E1011_PHYSTAT_GBIT:
440 case MIIM_88E1011_PHYSTAT_100:
451 /* Parse the cis8201's status register for speed and duplex
453 uint mii_parse_cis8201(uint mii_reg, struct tsec_private *priv)
457 if(mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
462 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
464 case MIIM_CIS8201_AUXCONSTAT_GBIT:
467 case MIIM_CIS8201_AUXCONSTAT_100:
477 /* Parse the vsc8244's status register for speed and duplex
479 uint mii_parse_vsc8244(uint mii_reg, struct tsec_private *priv)
483 if(mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
488 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
490 case MIIM_VSC8244_AUXCONSTAT_GBIT:
493 case MIIM_VSC8244_AUXCONSTAT_100:
505 /* Parse the DM9161's status register for speed and duplex
507 uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private *priv)
509 if(mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
514 if(mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
523 /* Hack to write all 4 PHYs with the LED values */
524 uint mii_cis8204_fixled(uint mii_reg, struct tsec_private *priv)
527 volatile tsec_t *regbase = priv->phyregs;
530 for(phyid=0;phyid<4;phyid++) {
531 regbase->miimadd = (phyid << 8) | mii_reg;
532 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
536 while((regbase->miimind & MIIMIND_BUSY) && timeout--);
539 return MIIM_CIS8204_SLEDCON_INIT;
542 uint mii_cis8204_setmode(uint mii_reg, struct tsec_private *priv)
544 if (priv->flags & TSEC_REDUCED)
545 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
547 return MIIM_CIS8204_EPHYCON_INIT;
550 /* Initialized required registers to appropriate values, zeroing
551 * those we don't care about (unless zero is bad, in which case,
552 * choose a more appropriate value) */
553 static void init_registers(volatile tsec_t *regs)
556 regs->ievent = IEVENT_INIT_CLEAR;
558 regs->imask = IMASK_INIT_CLEAR;
560 regs->hash.iaddr0 = 0;
561 regs->hash.iaddr1 = 0;
562 regs->hash.iaddr2 = 0;
563 regs->hash.iaddr3 = 0;
564 regs->hash.iaddr4 = 0;
565 regs->hash.iaddr5 = 0;
566 regs->hash.iaddr6 = 0;
567 regs->hash.iaddr7 = 0;
569 regs->hash.gaddr0 = 0;
570 regs->hash.gaddr1 = 0;
571 regs->hash.gaddr2 = 0;
572 regs->hash.gaddr3 = 0;
573 regs->hash.gaddr4 = 0;
574 regs->hash.gaddr5 = 0;
575 regs->hash.gaddr6 = 0;
576 regs->hash.gaddr7 = 0;
578 regs->rctrl = 0x00000000;
580 /* Init RMON mib registers */
581 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
583 regs->rmon.cam1 = 0xffffffff;
584 regs->rmon.cam2 = 0xffffffff;
586 regs->mrblr = MRBLR_INIT_SETTINGS;
588 regs->minflr = MINFLR_INIT_SETTINGS;
590 regs->attr = ATTR_INIT_SETTINGS;
591 regs->attreli = ATTRELI_INIT_SETTINGS;
596 /* Configure maccfg2 based on negotiated speed and duplex
597 * reported by PHY handling code */
598 static void adjust_link(struct eth_device *dev)
600 struct tsec_private *priv = (struct tsec_private *)dev->priv;
601 volatile tsec_t *regs = priv->regs;
604 if(priv->duplexity != 0)
605 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
607 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
609 switch(priv->speed) {
611 regs->maccfg2 = ((regs->maccfg2&~(MACCFG2_IF))
616 regs->maccfg2 = ((regs->maccfg2&~(MACCFG2_IF))
619 /* If We're in reduced mode, we need
620 * to say whether we're 10 or 100 MB.
622 if ((priv->speed == 100)
623 && (priv->flags & TSEC_REDUCED))
624 regs->ecntrl |= ECNTRL_R100;
626 regs->ecntrl &= ~(ECNTRL_R100);
629 printf("%s: Speed was bad\n", dev->name);
633 printf("Speed: %d, %s duplex\n", priv->speed,
634 (priv->duplexity) ? "full" : "half");
637 printf("%s: No link.\n", dev->name);
642 /* Set up the buffers and their descriptors, and bring up the
644 static void startup_tsec(struct eth_device *dev)
647 struct tsec_private *priv = (struct tsec_private *)dev->priv;
648 volatile tsec_t *regs = priv->regs;
650 /* Point to the buffer descriptors */
651 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
652 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
654 /* Initialize the Rx Buffer descriptors */
655 for (i = 0; i < PKTBUFSRX; i++) {
656 rtx.rxbd[i].status = RXBD_EMPTY;
657 rtx.rxbd[i].length = 0;
658 rtx.rxbd[i].bufPtr = (uint)NetRxPackets[i];
660 rtx.rxbd[PKTBUFSRX -1].status |= RXBD_WRAP;
662 /* Initialize the TX Buffer Descriptors */
663 for(i=0; i<TX_BUF_CNT; i++) {
664 rtx.txbd[i].status = 0;
665 rtx.txbd[i].length = 0;
666 rtx.txbd[i].bufPtr = 0;
668 rtx.txbd[TX_BUF_CNT -1].status |= TXBD_WRAP;
670 /* Start up the PHY */
671 phy_run_commands(priv, priv->phyinfo->startup);
674 /* Enable Transmit and Receive */
675 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
677 /* Tell the DMA it is clear to go */
678 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
679 regs->tstat = TSTAT_CLEAR_THALT;
680 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
683 /* This returns the status bits of the device. The return value
684 * is never checked, and this is what the 8260 driver did, so we
685 * do the same. Presumably, this would be zero if there were no
687 static int tsec_send(struct eth_device* dev, volatile void *packet, int length)
691 struct tsec_private *priv = (struct tsec_private *)dev->priv;
692 volatile tsec_t *regs = priv->regs;
694 /* Find an empty buffer descriptor */
695 for(i=0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
696 if (i >= TOUT_LOOP) {
697 debug ("%s: tsec: tx buffers full\n", dev->name);
702 rtx.txbd[txIdx].bufPtr = (uint)packet;
703 rtx.txbd[txIdx].length = length;
704 rtx.txbd[txIdx].status |= (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
706 /* Tell the DMA to go */
707 regs->tstat = TSTAT_CLEAR_THALT;
709 /* Wait for buffer to be transmitted */
710 for(i=0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
711 if (i >= TOUT_LOOP) {
712 debug ("%s: tsec: tx error\n", dev->name);
717 txIdx = (txIdx + 1) % TX_BUF_CNT;
718 result = rtx.txbd[txIdx].status & TXBD_STATS;
723 static int tsec_recv(struct eth_device* dev)
726 struct tsec_private *priv = (struct tsec_private *)dev->priv;
727 volatile tsec_t *regs = priv->regs;
729 while(!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
731 length = rtx.rxbd[rxIdx].length;
733 /* Send the packet up if there were no errors */
734 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
735 NetReceive(NetRxPackets[rxIdx], length - 4);
737 printf("Got error %x\n",
738 (rtx.rxbd[rxIdx].status & RXBD_STATS));
741 rtx.rxbd[rxIdx].length = 0;
743 /* Set the wrap bit if this is the last element in the list */
744 rtx.rxbd[rxIdx].status = RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
746 rxIdx = (rxIdx + 1) % PKTBUFSRX;
749 if(regs->ievent&IEVENT_BSY) {
750 regs->ievent = IEVENT_BSY;
751 regs->rstat = RSTAT_CLEAR_RHALT;
759 /* Stop the interface */
760 static void tsec_halt(struct eth_device* dev)
762 struct tsec_private *priv = (struct tsec_private *)dev->priv;
763 volatile tsec_t *regs = priv->regs;
765 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
766 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
768 while(!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC)));
770 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
772 /* Shut down the PHY, as needed */
773 phy_run_commands(priv, priv->phyinfo->shutdown);
777 struct phy_info phy_info_M88E1011S = {
781 (struct phy_cmd[]) { /* config */
782 /* Reset and configure the PHY */
783 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
785 {0x1e, 0x200c, NULL},
789 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
790 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
791 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
792 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
795 (struct phy_cmd[]) { /* startup */
796 /* Status is read once to clear old link state */
797 {MIIM_STATUS, miim_read, NULL},
799 {MIIM_STATUS, miim_read, &mii_parse_sr},
800 /* Read the status */
801 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
804 (struct phy_cmd[]) { /* shutdown */
809 struct phy_info phy_info_M88E1111S = {
813 (struct phy_cmd[]) { /* config */
814 /* Reset and configure the PHY */
815 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
817 {0x1e, 0x200c, NULL},
821 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
822 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
823 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
824 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
827 (struct phy_cmd[]) { /* startup */
828 /* Status is read once to clear old link state */
829 {MIIM_STATUS, miim_read, NULL},
831 {MIIM_STATUS, miim_read, &mii_parse_sr},
832 /* Read the status */
833 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
836 (struct phy_cmd[]) { /* shutdown */
841 struct phy_info phy_info_cis8204 = {
845 (struct phy_cmd[]) { /* config */
846 /* Override PHY config settings */
847 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
848 /* Configure some basic stuff */
849 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
850 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT, &mii_cis8204_fixled},
851 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT, &mii_cis8204_setmode},
854 (struct phy_cmd[]) { /* startup */
855 /* Read the Status (2x to make sure link is right) */
856 {MIIM_STATUS, miim_read, NULL},
858 {MIIM_STATUS, miim_read, &mii_parse_sr},
859 /* Read the status */
860 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
863 (struct phy_cmd[]) { /* shutdown */
869 struct phy_info phy_info_cis8201 = {
873 (struct phy_cmd[]) { /* config */
874 /* Override PHY config settings */
875 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
876 /* Set up the interface mode */
877 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
878 /* Configure some basic stuff */
879 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
882 (struct phy_cmd[]) { /* startup */
883 /* Read the Status (2x to make sure link is right) */
884 {MIIM_STATUS, miim_read, NULL},
886 {MIIM_STATUS, miim_read, &mii_parse_sr},
887 /* Read the status */
888 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
891 (struct phy_cmd[]) { /* shutdown */
895 struct phy_info phy_info_VSC8244 = {
899 (struct phy_cmd[]) { /* config */
900 /* Override PHY config settings */
901 /* Configure some basic stuff */
902 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
905 (struct phy_cmd[]) { /* startup */
906 /* Read the Status (2x to make sure link is right) */
907 {MIIM_STATUS, miim_read, NULL},
909 {MIIM_STATUS, miim_read, &mii_parse_sr},
910 /* Read the status */
911 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
914 (struct phy_cmd[]) { /* shutdown */
920 struct phy_info phy_info_dm9161 = {
924 (struct phy_cmd[]) { /* config */
925 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
926 /* Do not bypass the scrambler/descrambler */
927 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
928 /* Clear 10BTCSR to default */
929 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
930 /* Configure some basic stuff */
931 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
932 /* Restart Auto Negotiation */
933 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
936 (struct phy_cmd[]) { /* startup */
937 /* Status is read once to clear old link state */
938 {MIIM_STATUS, miim_read, NULL},
940 {MIIM_STATUS, miim_read, &mii_parse_sr},
941 /* Read the status */
942 {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
945 (struct phy_cmd[]) { /* shutdown */
950 uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
954 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
957 case MIIM_LXT971_SR2_10HDX:
961 case MIIM_LXT971_SR2_10FDX:
965 case MIIM_LXT971_SR2_100HDX:
981 static struct phy_info phy_info_lxt971 = {
985 (struct phy_cmd []) { /* config */
986 { MIIM_CR, MIIM_CR_INIT, mii_cr_init }, /* autonegotiate */
989 (struct phy_cmd []) { /* startup - enable interrupts */
990 /* { 0x12, 0x00f2, NULL }, */
991 { MIIM_STATUS, miim_read, NULL },
992 { MIIM_STATUS, miim_read, &mii_parse_sr },
993 { MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2 },
996 (struct phy_cmd []) { /* shutdown - disable interrupts */
1001 /* Parse the DP83865's link and auto-neg status register for speed and duplex
1003 uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1005 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1007 case MIIM_DP83865_SPD_1000:
1011 case MIIM_DP83865_SPD_100:
1021 if (mii_reg & MIIM_DP83865_DPX_FULL)
1022 priv->duplexity = 1;
1024 priv->duplexity = 0;
1029 struct phy_info phy_info_dp83865 = {
1033 (struct phy_cmd[]) { /* config */
1034 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1037 (struct phy_cmd[]) { /* startup */
1038 /* Status is read once to clear old link state */
1039 {MIIM_STATUS, miim_read, NULL},
1040 /* Auto-negotiate */
1041 {MIIM_STATUS, miim_read, &mii_parse_sr},
1042 /* Read the link and auto-neg status */
1043 {MIIM_DP83865_LANR, miim_read, &mii_parse_dp83865_lanr},
1046 (struct phy_cmd[]) { /* shutdown */
1051 struct phy_info *phy_info[] = {
1056 &phy_info_M88E1011S,
1057 &phy_info_M88E1111S,
1066 /* Grab the identifier of the device's PHY, and search through
1067 * all of the known PHYs to see if one matches. If so, return
1068 * it, if not, return NULL */
1069 struct phy_info * get_phy_info(struct eth_device *dev)
1071 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1072 uint phy_reg, phy_ID;
1074 struct phy_info *theInfo = NULL;
1076 /* Grab the bits from PHYIR1, and put them in the upper half */
1077 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1078 phy_ID = (phy_reg & 0xffff) << 16;
1080 /* Grab the bits from PHYIR2, and put them in the lower half */
1081 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1082 phy_ID |= (phy_reg & 0xffff);
1084 /* loop through all the known PHY types, and find one that */
1085 /* matches the ID we read from the PHY. */
1086 for(i=0; phy_info[i]; i++) {
1087 if(phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
1088 theInfo = phy_info[i];
1093 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
1096 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
1103 /* Execute the given series of commands on the given device's
1104 * PHY, running functions as necessary*/
1105 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1109 volatile tsec_t *phyregs = priv->phyregs;
1111 phyregs->miimcfg = MIIMCFG_RESET;
1113 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1115 while(phyregs->miimind & MIIMIND_BUSY);
1117 for(i=0;cmd->mii_reg != miim_end;i++) {
1118 if(cmd->mii_data == miim_read) {
1119 result = read_phy_reg(priv, cmd->mii_reg);
1121 if(cmd->funct != NULL)
1122 (*(cmd->funct))(result, priv);
1125 if(cmd->funct != NULL)
1126 result = (*(cmd->funct))(cmd->mii_reg, priv);
1128 result = cmd->mii_data;
1130 write_phy_reg(priv, cmd->mii_reg, result);
1138 /* Relocate the function pointers in the phy cmd lists */
1139 static void relocate_cmds(void)
1141 struct phy_cmd **cmdlistptr;
1142 struct phy_cmd *cmd;
1145 for(i=0; phy_info[i]; i++) {
1146 /* First thing's first: relocate the pointers to the
1147 * PHY command structures (the structs were done) */
1148 phy_info[i] = (struct phy_info *) ((uint)phy_info[i]
1150 phy_info[i]->name += gd->reloc_off;
1151 phy_info[i]->config =
1152 (struct phy_cmd *)((uint)phy_info[i]->config
1154 phy_info[i]->startup =
1155 (struct phy_cmd *)((uint)phy_info[i]->startup
1157 phy_info[i]->shutdown =
1158 (struct phy_cmd *)((uint)phy_info[i]->shutdown
1161 cmdlistptr = &phy_info[i]->config;
1163 for(;cmdlistptr <= &phy_info[i]->shutdown;cmdlistptr++) {
1165 for(cmd=*cmdlistptr;cmd->mii_reg != miim_end;cmd++) {
1166 /* Only relocate non-NULL pointers */
1168 cmd->funct += gd->reloc_off;
1180 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
1181 && !defined(BITBANGMII)
1183 struct tsec_private * get_priv_for_phy(unsigned char phyaddr)
1187 for(i=0;i<MAXCONTROLLERS;i++) {
1188 if(privlist[i]->phyaddr == phyaddr)
1196 * Read a MII PHY register.
1201 static int tsec_miiphy_read(char *devname, unsigned char addr,
1202 unsigned char reg, unsigned short *value)
1205 struct tsec_private *priv = get_priv_for_phy(addr);
1208 printf("Can't read PHY at address %d\n", addr);
1212 ret = (unsigned short)read_phy_reg(priv, reg);
1219 * Write a MII PHY register.
1224 static int tsec_miiphy_write(char *devname, unsigned char addr,
1225 unsigned char reg, unsigned short value)
1227 struct tsec_private *priv = get_priv_for_phy(addr);
1230 printf("Can't write PHY at address %d\n", addr);
1234 write_phy_reg(priv, reg, value);
1239 #endif /* defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
1240 && !defined(BITBANGMII) */
1242 #endif /* CONFIG_TSEC_ENET */