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.
11 * maintained by Jon Loeliger (loeliger@freescale.com)
23 #if defined(CONFIG_TSEC_ENET)
28 static uint rxIdx; /* index of the current RX buffer */
29 static uint txIdx; /* index of the current TX buffer */
31 typedef volatile struct rtxbd {
32 txbd8_t txbd[TX_BUF_CNT];
33 rxbd8_t rxbd[PKTBUFSRX];
36 struct tsec_info_struct {
39 unsigned int phyregidx;
43 /* The tsec_info structure contains 3 values which the
44 * driver uses to determine how to operate a given ethernet
45 * device. For now, the structure is initialized with the
46 * knowledge that all current implementations have 2 TSEC
47 * devices, and one FEC. The information needed is:
48 * phyaddr - The address of the PHY which is attached to
51 * flags - This variable indicates whether the device
52 * supports gigabit speed ethernet, and whether it should be
55 * phyregidx - This variable specifies which ethernet device
56 * controls the MII Management registers which are connected
57 * to the PHY. For 8540/8560, only TSEC1 (index 0) has
58 * access to the PHYs, so all of the entries have "0".
60 * The values specified in the table are taken from the board's
61 * config file in include/configs/. When implementing a new
62 * board with ethernet capability, it is necessary to define:
72 static struct tsec_info_struct tsec_info[] = {
73 #ifdef CONFIG_MPC85XX_TSEC1
74 {TSEC1_PHY_ADDR, TSEC_GIGABIT, TSEC1_PHYIDX},
78 #ifdef CONFIG_MPC85XX_TSEC2
79 {TSEC2_PHY_ADDR, TSEC_GIGABIT, TSEC2_PHYIDX},
83 #ifdef CONFIG_MPC85XX_FEC
84 {FEC_PHY_ADDR, 0, FEC_PHYIDX},
86 # ifdef CONFIG_MPC85XX_TSEC3
87 {TSEC3_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC3_PHYIDX},
91 # ifdef CONFIG_MPC85XX_TSEC4
92 {TSEC4_PHY_ADDR, TSEC_REDUCED, TSEC4_PHYIDX},
99 #define MAXCONTROLLERS (4)
101 static int relocated = 0;
103 static struct tsec_private *privlist[MAXCONTROLLERS];
106 static RTXBD rtx __attribute__ ((aligned(8)));
108 #error "rtx must be 64-bit aligned"
111 static int tsec_send(struct eth_device* dev, volatile void *packet, int length);
112 static int tsec_recv(struct eth_device* dev);
113 static int tsec_init(struct eth_device* dev, bd_t * bd);
114 static void tsec_halt(struct eth_device* dev);
115 static void init_registers(volatile tsec_t *regs);
116 static void startup_tsec(struct eth_device *dev);
117 static int init_phy(struct eth_device *dev);
118 void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
119 uint read_phy_reg(struct tsec_private *priv, uint regnum);
120 struct phy_info * get_phy_info(struct eth_device *dev);
121 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
122 static void adjust_link(struct eth_device *dev);
123 static void relocate_cmds(void);
125 /* Initialize device structure. Returns success if PHY
126 * initialization succeeded (i.e. if it recognizes the PHY)
128 int tsec_initialize(bd_t *bis, int index, char *devname)
130 struct eth_device* dev;
132 struct tsec_private *priv;
134 dev = (struct eth_device*) malloc(sizeof *dev);
139 memset(dev, 0, sizeof *dev);
141 priv = (struct tsec_private *) malloc(sizeof(*priv));
146 privlist[index] = priv;
147 priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index*TSEC_SIZE);
148 priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
149 tsec_info[index].phyregidx*TSEC_SIZE);
151 priv->phyaddr = tsec_info[index].phyaddr;
152 priv->flags = tsec_info[index].flags;
154 sprintf(dev->name, devname);
157 dev->init = tsec_init;
158 dev->halt = tsec_halt;
159 dev->send = tsec_send;
160 dev->recv = tsec_recv;
162 /* Tell u-boot to get the addr from the env */
164 dev->enetaddr[i] = 0;
170 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
171 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
173 /* Try to initialize PHY here, and return */
174 return init_phy(dev);
178 /* Initializes data structures and registers for the controller,
179 * and brings the interface up. Returns the link status, meaning
180 * that it returns success if the link is up, failure otherwise.
181 * This allows u-boot to find the first active controller. */
182 int tsec_init(struct eth_device* dev, bd_t * bd)
185 char tmpbuf[MAC_ADDR_LEN];
187 struct tsec_private *priv = (struct tsec_private *)dev->priv;
188 volatile tsec_t *regs = priv->regs;
190 /* Make sure the controller is stopped */
193 /* Init MACCFG2. Defaults to GMII */
194 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
197 regs->ecntrl = ECNTRL_INIT_SETTINGS;
199 /* Copy the station address into the address registers.
200 * Backwards, because little endian MACS are dumb */
201 for(i=0;i<MAC_ADDR_LEN;i++) {
202 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
204 (uint)(regs->macstnaddr1) = *((uint *)(tmpbuf));
206 tempval = *((uint *)(tmpbuf +4));
208 (uint)(regs->macstnaddr2) = tempval;
210 /* reset the indices to zero */
214 /* Clear out (for the most part) the other registers */
215 init_registers(regs);
217 /* Ready the device for tx/rx */
220 /* If there's no link, fail */
226 /* Write value to the device's PHY through the registers
227 * specified in priv, modifying the register specified in regnum.
228 * It will wait for the write to be done (or for a timeout to
229 * expire) before exiting
231 void write_phy_reg(struct tsec_private *priv, uint regnum, uint value)
233 volatile tsec_t *regbase = priv->phyregs;
234 uint phyid = priv->phyaddr;
237 regbase->miimadd = (phyid << 8) | regnum;
238 regbase->miimcon = value;
242 while((regbase->miimind & MIIMIND_BUSY) && timeout--);
246 /* Reads register regnum on the device's PHY through the
247 * registers specified in priv. It lowers and raises the read
248 * command, and waits for the data to become valid (miimind
249 * notvalid bit cleared), and the bus to cease activity (miimind
250 * busy bit cleared), and then returns the value
252 uint read_phy_reg(struct tsec_private *priv, uint regnum)
255 volatile tsec_t *regbase = priv->phyregs;
256 uint phyid = priv->phyaddr;
258 /* Put the address of the phy, and the register
259 * number into MIIMADD */
260 regbase->miimadd = (phyid << 8) | regnum;
262 /* Clear the command register, and wait */
263 regbase->miimcom = 0;
266 /* Initiate a read command, and wait */
267 regbase->miimcom = MIIM_READ_COMMAND;
270 /* Wait for the the indication that the read is done */
271 while((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY)));
273 /* Grab the value read from the PHY */
274 value = regbase->miimstat;
280 /* Discover which PHY is attached to the device, and configure it
281 * properly. If the PHY is not recognized, then return 0
282 * (failure). Otherwise, return 1
284 static int init_phy(struct eth_device *dev)
286 struct tsec_private *priv = (struct tsec_private *)dev->priv;
287 struct phy_info *curphy;
289 /* Assign a Physical address to the TBI */
292 volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
293 regs->tbipa = TBIPA_VALUE;
294 regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
295 regs->tbipa = TBIPA_VALUE;
299 /* Reset MII (due to new addresses) */
300 priv->phyregs->miimcfg = MIIMCFG_RESET;
302 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
304 while(priv->phyregs->miimind & MIIMIND_BUSY);
309 /* Get the cmd structure corresponding to the attached
311 curphy = get_phy_info(dev);
314 printf("%s: No PHY found\n", dev->name);
319 priv->phyinfo = curphy;
321 phy_run_commands(priv, priv->phyinfo->config);
327 /* Returns which value to write to the control register. */
328 /* For 10/100, the value is slightly different */
329 uint mii_cr_init(uint mii_reg, struct tsec_private *priv)
331 if(priv->flags & TSEC_GIGABIT)
332 return MIIM_CONTROL_INIT;
338 /* Parse the status register for link, and then do
339 * auto-negotiation */
340 uint mii_parse_sr(uint mii_reg, struct tsec_private *priv)
342 uint timeout = TSEC_TIMEOUT;
344 if(mii_reg & MIIM_STATUS_LINK)
350 while((!(mii_reg & MIIM_STATUS_AN_DONE)) && timeout--)
351 mii_reg = read_phy_reg(priv, MIIM_STATUS);
358 /* Parse the 88E1011's status register for speed and duplex
360 uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private *priv)
364 if(mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
369 speed = (mii_reg &MIIM_88E1011_PHYSTAT_SPEED);
372 case MIIM_88E1011_PHYSTAT_GBIT:
375 case MIIM_88E1011_PHYSTAT_100:
386 /* Parse the cis8201's status register for speed and duplex
388 uint mii_parse_cis8201(uint mii_reg, struct tsec_private *priv)
392 if(mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
397 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
399 case MIIM_CIS8201_AUXCONSTAT_GBIT:
402 case MIIM_CIS8201_AUXCONSTAT_100:
414 /* Parse the DM9161's status register for speed and duplex
416 uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private *priv)
418 if(mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
423 if(mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
432 /* Hack to write all 4 PHYs with the LED values */
433 uint mii_cis8204_fixled(uint mii_reg, struct tsec_private *priv)
436 volatile tsec_t *regbase = priv->phyregs;
439 for(phyid=0;phyid<4;phyid++) {
440 regbase->miimadd = (phyid << 8) | mii_reg;
441 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
445 while((regbase->miimind & MIIMIND_BUSY) && timeout--);
448 return MIIM_CIS8204_SLEDCON_INIT;
451 uint mii_cis8204_setmode(uint mii_reg, struct tsec_private *priv)
453 if (priv->flags & TSEC_REDUCED)
454 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
456 return MIIM_CIS8204_EPHYCON_INIT;
459 /* Initialized required registers to appropriate values, zeroing
460 * those we don't care about (unless zero is bad, in which case,
461 * choose a more appropriate value) */
462 static void init_registers(volatile tsec_t *regs)
465 regs->ievent = IEVENT_INIT_CLEAR;
467 regs->imask = IMASK_INIT_CLEAR;
469 regs->hash.iaddr0 = 0;
470 regs->hash.iaddr1 = 0;
471 regs->hash.iaddr2 = 0;
472 regs->hash.iaddr3 = 0;
473 regs->hash.iaddr4 = 0;
474 regs->hash.iaddr5 = 0;
475 regs->hash.iaddr6 = 0;
476 regs->hash.iaddr7 = 0;
478 regs->hash.gaddr0 = 0;
479 regs->hash.gaddr1 = 0;
480 regs->hash.gaddr2 = 0;
481 regs->hash.gaddr3 = 0;
482 regs->hash.gaddr4 = 0;
483 regs->hash.gaddr5 = 0;
484 regs->hash.gaddr6 = 0;
485 regs->hash.gaddr7 = 0;
487 regs->rctrl = 0x00000000;
489 /* Init RMON mib registers */
490 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
492 regs->rmon.cam1 = 0xffffffff;
493 regs->rmon.cam2 = 0xffffffff;
495 regs->mrblr = MRBLR_INIT_SETTINGS;
497 regs->minflr = MINFLR_INIT_SETTINGS;
499 regs->attr = ATTR_INIT_SETTINGS;
500 regs->attreli = ATTRELI_INIT_SETTINGS;
505 /* Configure maccfg2 based on negotiated speed and duplex
506 * reported by PHY handling code */
507 static void adjust_link(struct eth_device *dev)
509 struct tsec_private *priv = (struct tsec_private *)dev->priv;
510 volatile tsec_t *regs = priv->regs;
513 if(priv->duplexity != 0)
514 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
516 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
518 switch(priv->speed) {
520 regs->maccfg2 = ((regs->maccfg2&~(MACCFG2_IF))
525 regs->maccfg2 = ((regs->maccfg2&~(MACCFG2_IF))
528 /* If We're in reduced mode, we
529 * need to say whether we're 10
531 if ((priv->speed == 100)
532 && (priv->flags & TSEC_REDUCED))
533 regs->ecntrl |= ECNTRL_R100;
535 regs->ecntrl &= ~(ECNTRL_R100);
538 printf("%s: Speed was bad\n", dev->name);
542 printf("Speed: %d, %s duplex\n", priv->speed,
543 (priv->duplexity) ? "full" : "half");
546 printf("%s: No link.\n", dev->name);
551 /* Set up the buffers and their descriptors, and bring up the
553 static void startup_tsec(struct eth_device *dev)
556 struct tsec_private *priv = (struct tsec_private *)dev->priv;
557 volatile tsec_t *regs = priv->regs;
559 /* Point to the buffer descriptors */
560 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
561 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
563 /* Initialize the Rx Buffer descriptors */
564 for (i = 0; i < PKTBUFSRX; i++) {
565 rtx.rxbd[i].status = RXBD_EMPTY;
566 rtx.rxbd[i].length = 0;
567 rtx.rxbd[i].bufPtr = (uint)NetRxPackets[i];
569 rtx.rxbd[PKTBUFSRX -1].status |= RXBD_WRAP;
571 /* Initialize the TX Buffer Descriptors */
572 for(i=0; i<TX_BUF_CNT; i++) {
573 rtx.txbd[i].status = 0;
574 rtx.txbd[i].length = 0;
575 rtx.txbd[i].bufPtr = 0;
577 rtx.txbd[TX_BUF_CNT -1].status |= TXBD_WRAP;
579 /* Start up the PHY */
580 phy_run_commands(priv, priv->phyinfo->startup);
583 /* Enable Transmit and Receive */
584 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
586 /* Tell the DMA it is clear to go */
587 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
588 regs->tstat = TSTAT_CLEAR_THALT;
589 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
592 /* This returns the status bits of the device. The return value
593 * is never checked, and this is what the 8260 driver did, so we
594 * do the same. Presumably, this would be zero if there were no
596 static int tsec_send(struct eth_device* dev, volatile void *packet, int length)
600 struct tsec_private *priv = (struct tsec_private *)dev->priv;
601 volatile tsec_t *regs = priv->regs;
603 /* Find an empty buffer descriptor */
604 for(i=0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
605 if (i >= TOUT_LOOP) {
606 debug ("%s: tsec: tx buffers full\n", dev->name);
611 rtx.txbd[txIdx].bufPtr = (uint)packet;
612 rtx.txbd[txIdx].length = length;
613 rtx.txbd[txIdx].status |= (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
615 /* Tell the DMA to go */
616 regs->tstat = TSTAT_CLEAR_THALT;
618 /* Wait for buffer to be transmitted */
619 for(i=0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
620 if (i >= TOUT_LOOP) {
621 debug ("%s: tsec: tx error\n", dev->name);
626 txIdx = (txIdx + 1) % TX_BUF_CNT;
627 result = rtx.txbd[txIdx].status & TXBD_STATS;
632 static int tsec_recv(struct eth_device* dev)
635 struct tsec_private *priv = (struct tsec_private *)dev->priv;
636 volatile tsec_t *regs = priv->regs;
638 while(!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
640 length = rtx.rxbd[rxIdx].length;
642 /* Send the packet up if there were no errors */
643 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
644 NetReceive(NetRxPackets[rxIdx], length - 4);
646 printf("Got error %x\n",
647 (rtx.rxbd[rxIdx].status & RXBD_STATS));
650 rtx.rxbd[rxIdx].length = 0;
652 /* Set the wrap bit if this is the last element in the list */
653 rtx.rxbd[rxIdx].status = RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
655 rxIdx = (rxIdx + 1) % PKTBUFSRX;
658 if(regs->ievent&IEVENT_BSY) {
659 regs->ievent = IEVENT_BSY;
660 regs->rstat = RSTAT_CLEAR_RHALT;
668 /* Stop the interface */
669 static void tsec_halt(struct eth_device* dev)
671 struct tsec_private *priv = (struct tsec_private *)dev->priv;
672 volatile tsec_t *regs = priv->regs;
674 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
675 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
677 while(!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC)));
679 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
681 /* Shut down the PHY, as needed */
682 phy_run_commands(priv, priv->phyinfo->shutdown);
686 struct phy_info phy_info_M88E1011S = {
690 (struct phy_cmd[]) { /* config */
691 /* Reset and configure the PHY */
692 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
694 {0x1e, 0x200c, NULL},
698 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
699 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
700 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
701 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
704 (struct phy_cmd[]) { /* startup */
705 /* Status is read once to clear old link state */
706 {MIIM_STATUS, miim_read, NULL},
708 {MIIM_STATUS, miim_read, &mii_parse_sr},
709 /* Read the status */
710 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
713 (struct phy_cmd[]) { /* shutdown */
718 struct phy_info phy_info_M88E1111S = {
722 (struct phy_cmd[]) { /* config */
723 /* Reset and configure the PHY */
724 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
726 {0x1e, 0x200c, NULL},
730 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
731 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
732 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
733 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
736 (struct phy_cmd[]) { /* startup */
737 /* Status is read once to clear old link state */
738 {MIIM_STATUS, miim_read, NULL},
740 {MIIM_STATUS, miim_read, &mii_parse_sr},
741 /* Read the status */
742 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
745 (struct phy_cmd[]) { /* shutdown */
750 struct phy_info phy_info_cis8204 = {
754 (struct phy_cmd[]) { /* config */
755 /* Override PHY config settings */
756 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
757 /* Configure some basic stuff */
758 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
759 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT, &mii_cis8204_fixled},
760 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT, &mii_cis8204_setmode},
763 (struct phy_cmd[]) { /* startup */
764 /* Read the Status (2x to make sure link is right) */
765 {MIIM_STATUS, miim_read, NULL},
767 {MIIM_STATUS, miim_read, &mii_parse_sr},
768 /* Read the status */
769 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
772 (struct phy_cmd[]) { /* shutdown */
778 struct phy_info phy_info_cis8201 = {
782 (struct phy_cmd[]) { /* config */
783 /* Override PHY config settings */
784 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
785 /* Set up the interface mode */
786 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
787 /* Configure some basic stuff */
788 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
791 (struct phy_cmd[]) { /* startup */
792 /* Read the Status (2x to make sure link is right) */
793 {MIIM_STATUS, miim_read, NULL},
795 {MIIM_STATUS, miim_read, &mii_parse_sr},
796 /* Read the status */
797 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
800 (struct phy_cmd[]) { /* shutdown */
806 struct phy_info phy_info_dm9161 = {
810 (struct phy_cmd[]) { /* config */
811 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
812 /* Do not bypass the scrambler/descrambler */
813 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
814 /* Clear 10BTCSR to default */
815 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
816 /* Configure some basic stuff */
817 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
818 /* Restart Auto Negotiation */
819 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
822 (struct phy_cmd[]) { /* startup */
823 /* Status is read once to clear old link state */
824 {MIIM_STATUS, miim_read, NULL},
826 {MIIM_STATUS, miim_read, &mii_parse_sr},
827 /* Read the status */
828 {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
831 (struct phy_cmd[]) { /* shutdown */
836 uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
840 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
843 case MIIM_LXT971_SR2_10HDX:
847 case MIIM_LXT971_SR2_10FDX:
851 case MIIM_LXT971_SR2_100HDX:
867 static struct phy_info phy_info_lxt971 = {
871 (struct phy_cmd []) { /* config */
872 { MIIM_CR, MIIM_CR_INIT, mii_cr_init }, /* autonegotiate */
875 (struct phy_cmd []) { /* startup - enable interrupts */
876 /* { 0x12, 0x00f2, NULL }, */
877 { MIIM_STATUS, miim_read, NULL },
878 { MIIM_STATUS, miim_read, &mii_parse_sr },
879 { MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2 },
882 (struct phy_cmd []) { /* shutdown - disable interrupts */
887 struct phy_info *phy_info[] = {
900 /* Grab the identifier of the device's PHY, and search through
901 * all of the known PHYs to see if one matches. If so, return
902 * it, if not, return NULL */
903 struct phy_info * get_phy_info(struct eth_device *dev)
905 struct tsec_private *priv = (struct tsec_private *)dev->priv;
906 uint phy_reg, phy_ID;
908 struct phy_info *theInfo = NULL;
910 /* Grab the bits from PHYIR1, and put them in the upper half */
911 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
912 phy_ID = (phy_reg & 0xffff) << 16;
914 /* Grab the bits from PHYIR2, and put them in the lower half */
915 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
916 phy_ID |= (phy_reg & 0xffff);
918 /* loop through all the known PHY types, and find one that */
919 /* matches the ID we read from the PHY. */
920 for(i=0; phy_info[i]; i++) {
921 if(phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
922 theInfo = phy_info[i];
927 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
930 printf("%s: PHY is %s (%x)\n", dev->name, theInfo->name,
938 /* Execute the given series of commands on the given device's
939 * PHY, running functions as necessary*/
940 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
944 volatile tsec_t *phyregs = priv->phyregs;
946 phyregs->miimcfg = MIIMCFG_RESET;
948 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
950 while(phyregs->miimind & MIIMIND_BUSY);
952 for(i=0;cmd->mii_reg != miim_end;i++) {
953 if(cmd->mii_data == miim_read) {
954 result = read_phy_reg(priv, cmd->mii_reg);
956 if(cmd->funct != NULL)
957 (*(cmd->funct))(result, priv);
960 if(cmd->funct != NULL)
961 result = (*(cmd->funct))(cmd->mii_reg, priv);
963 result = cmd->mii_data;
965 write_phy_reg(priv, cmd->mii_reg, result);
973 /* Relocate the function pointers in the phy cmd lists */
974 static void relocate_cmds(void)
976 struct phy_cmd **cmdlistptr;
979 DECLARE_GLOBAL_DATA_PTR;
981 for(i=0; phy_info[i]; i++) {
982 /* First thing's first: relocate the pointers to the
983 * PHY command structures (the structs were done) */
984 phy_info[i] = (struct phy_info *) ((uint)phy_info[i]
986 phy_info[i]->name += gd->reloc_off;
987 phy_info[i]->config =
988 (struct phy_cmd *)((uint)phy_info[i]->config
990 phy_info[i]->startup =
991 (struct phy_cmd *)((uint)phy_info[i]->startup
993 phy_info[i]->shutdown =
994 (struct phy_cmd *)((uint)phy_info[i]->shutdown
997 cmdlistptr = &phy_info[i]->config;
999 for(;cmdlistptr <= &phy_info[i]->shutdown;cmdlistptr++) {
1001 for(cmd=*cmdlistptr;cmd->mii_reg != miim_end;cmd++) {
1002 /* Only relocate non-NULL pointers */
1004 cmd->funct += gd->reloc_off;
1016 #ifndef CONFIG_BITBANGMII
1018 struct tsec_private * get_priv_for_phy(unsigned char phyaddr)
1022 for(i=0;i<MAXCONTROLLERS;i++) {
1023 if(privlist[i]->phyaddr == phyaddr)
1031 * Read a MII PHY register.
1036 int miiphy_read(unsigned char addr, unsigned char reg, unsigned short *value)
1039 struct tsec_private *priv = get_priv_for_phy(addr);
1042 printf("Can't read PHY at address %d\n", addr);
1046 ret = (unsigned short)read_phy_reg(priv, reg);
1053 * Write a MII PHY register.
1058 int miiphy_write(unsigned char addr, unsigned char reg, unsigned short value)
1060 struct tsec_private *priv = get_priv_for_phy(addr);
1063 printf("Can't write PHY at address %d\n", addr);
1067 write_phy_reg(priv, reg, value);
1072 #endif /* CONFIG_BITBANGMII */
1074 #endif /* CONFIG_TSEC_ENET */