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.
22 #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 #if defined(CONFIG_MPC85XX_TSEC1) || defined(CONFIG_MPC83XX_TSEC1)
74 {TSEC1_PHY_ADDR
, TSEC_GIGABIT
, TSEC1_PHYIDX
},
78 #if defined(CONFIG_MPC85XX_TSEC2) || defined(CONFIG_MPC83XX_TSEC2)
79 {TSEC2_PHY_ADDR
, TSEC_GIGABIT
, TSEC2_PHYIDX
},
83 #ifdef CONFIG_MPC85XX_FEC
84 {FEC_PHY_ADDR
, 0, FEC_PHYIDX
},
86 # if defined(CONFIG_MPC85XX_TSEC3) || defined(CONFIG_MPC83XX_TSEC3)
87 {TSEC3_PHY_ADDR
, TSEC_GIGABIT
| TSEC_REDUCED
, TSEC3_PHYIDX
},
91 # if defined(CONFIG_MPC85XX_TSEC4) || defined(CONFIG_MPC83XX_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);
124 static int tsec_miiphy_write(char *devname
, unsigned char addr
,
125 unsigned char reg
, unsigned short value
);
126 static int tsec_miiphy_read(char *devname
, unsigned char addr
,
127 unsigned char reg
, unsigned short *value
);
129 /* Initialize device structure. Returns success if PHY
130 * initialization succeeded (i.e. if it recognizes the PHY)
132 int tsec_initialize(bd_t
*bis
, int index
, char *devname
)
134 struct eth_device
* dev
;
136 struct tsec_private
*priv
;
138 dev
= (struct eth_device
*) malloc(sizeof *dev
);
143 memset(dev
, 0, sizeof *dev
);
145 priv
= (struct tsec_private
*) malloc(sizeof(*priv
));
150 privlist
[index
] = priv
;
151 priv
->regs
= (volatile tsec_t
*)(TSEC_BASE_ADDR
+ index
*TSEC_SIZE
);
152 priv
->phyregs
= (volatile tsec_t
*)(TSEC_BASE_ADDR
+
153 tsec_info
[index
].phyregidx
*TSEC_SIZE
);
155 priv
->phyaddr
= tsec_info
[index
].phyaddr
;
156 priv
->flags
= tsec_info
[index
].flags
;
158 sprintf(dev
->name
, devname
);
161 dev
->init
= tsec_init
;
162 dev
->halt
= tsec_halt
;
163 dev
->send
= tsec_send
;
164 dev
->recv
= tsec_recv
;
166 /* Tell u-boot to get the addr from the env */
168 dev
->enetaddr
[i
] = 0;
174 priv
->regs
->maccfg1
|= MACCFG1_SOFT_RESET
;
175 priv
->regs
->maccfg1
&= ~(MACCFG1_SOFT_RESET
);
177 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
178 && !defined(BITBANGMII)
179 miiphy_register(dev
->name
, tsec_miiphy_read
, tsec_miiphy_write
);
182 /* Try to initialize PHY here, and return */
183 return init_phy(dev
);
187 /* Initializes data structures and registers for the controller,
188 * and brings the interface up. Returns the link status, meaning
189 * that it returns success if the link is up, failure otherwise.
190 * This allows u-boot to find the first active controller. */
191 int tsec_init(struct eth_device
* dev
, bd_t
* bd
)
194 char tmpbuf
[MAC_ADDR_LEN
];
196 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
197 volatile tsec_t
*regs
= priv
->regs
;
199 /* Make sure the controller is stopped */
202 /* Init MACCFG2. Defaults to GMII */
203 regs
->maccfg2
= MACCFG2_INIT_SETTINGS
;
206 regs
->ecntrl
= ECNTRL_INIT_SETTINGS
;
208 /* Copy the station address into the address registers.
209 * Backwards, because little endian MACS are dumb */
210 for(i
=0;i
<MAC_ADDR_LEN
;i
++) {
211 tmpbuf
[MAC_ADDR_LEN
- 1 - i
] = dev
->enetaddr
[i
];
213 regs
->macstnaddr1
= *((uint
*)(tmpbuf
));
215 tempval
= *((uint
*)(tmpbuf
+4));
217 regs
->macstnaddr2
= tempval
;
219 /* reset the indices to zero */
223 /* Clear out (for the most part) the other registers */
224 init_registers(regs
);
226 /* Ready the device for tx/rx */
229 /* If there's no link, fail */
235 /* Write value to the device's PHY through the registers
236 * specified in priv, modifying the register specified in regnum.
237 * It will wait for the write to be done (or for a timeout to
238 * expire) before exiting
240 void write_phy_reg(struct tsec_private
*priv
, uint regnum
, uint value
)
242 volatile tsec_t
*regbase
= priv
->phyregs
;
243 uint phyid
= priv
->phyaddr
;
246 regbase
->miimadd
= (phyid
<< 8) | regnum
;
247 regbase
->miimcon
= value
;
251 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
;
289 /* Discover which PHY is attached to the device, and configure it
290 * properly. If the PHY is not recognized, then return 0
291 * (failure). Otherwise, return 1
293 static int init_phy(struct eth_device
*dev
)
295 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
296 struct phy_info
*curphy
;
298 /* Assign a Physical address to the TBI */
301 volatile tsec_t
*regs
= (volatile tsec_t
*)(TSEC_BASE_ADDR
);
302 regs
->tbipa
= TBIPA_VALUE
;
303 regs
= (volatile tsec_t
*)(TSEC_BASE_ADDR
+ TSEC_SIZE
);
304 regs
->tbipa
= TBIPA_VALUE
;
308 /* Reset MII (due to new addresses) */
309 priv
->phyregs
->miimcfg
= MIIMCFG_RESET
;
311 priv
->phyregs
->miimcfg
= MIIMCFG_INIT_VALUE
;
313 while(priv
->phyregs
->miimind
& MIIMIND_BUSY
);
318 /* Get the cmd structure corresponding to the attached
320 curphy
= get_phy_info(dev
);
323 printf("%s: No PHY found\n", dev
->name
);
328 priv
->phyinfo
= curphy
;
330 phy_run_commands(priv
, priv
->phyinfo
->config
);
336 /* Returns which value to write to the control register. */
337 /* For 10/100, the value is slightly different */
338 uint
mii_cr_init(uint mii_reg
, struct tsec_private
*priv
)
340 if(priv
->flags
& TSEC_GIGABIT
)
341 return MIIM_CONTROL_INIT
;
347 /* Parse the status register for link, and then do
348 * auto-negotiation */
349 uint
mii_parse_sr(uint mii_reg
, struct tsec_private
*priv
)
352 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
354 mii_reg
= read_phy_reg(priv
, MIIM_STATUS
);
355 if ((mii_reg
& PHY_BMSR_AUTN_ABLE
) && !(mii_reg
& PHY_BMSR_AUTN_COMP
)) {
358 puts ("Waiting for PHY auto negotiation to complete");
359 while (!((mii_reg
& PHY_BMSR_AUTN_COMP
) && (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) */
386 /* 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
:
442 /* 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
:
470 /* Parse the DM9161's status register for speed and duplex
472 uint
mii_parse_dm9161_scsr(uint mii_reg
, struct tsec_private
*priv
)
474 if(mii_reg
& (MIIM_DM9161_SCSR_100F
| MIIM_DM9161_SCSR_100H
))
479 if(mii_reg
& (MIIM_DM9161_SCSR_100F
| MIIM_DM9161_SCSR_10F
))
488 /* Hack to write all 4 PHYs with the LED values */
489 uint
mii_cis8204_fixled(uint mii_reg
, struct tsec_private
*priv
)
492 volatile tsec_t
*regbase
= priv
->phyregs
;
495 for(phyid
=0;phyid
<4;phyid
++) {
496 regbase
->miimadd
= (phyid
<< 8) | mii_reg
;
497 regbase
->miimcon
= MIIM_CIS8204_SLEDCON_INIT
;
501 while((regbase
->miimind
& MIIMIND_BUSY
) && timeout
--);
504 return MIIM_CIS8204_SLEDCON_INIT
;
507 uint
mii_cis8204_setmode(uint mii_reg
, struct tsec_private
*priv
)
509 if (priv
->flags
& TSEC_REDUCED
)
510 return MIIM_CIS8204_EPHYCON_INIT
| MIIM_CIS8204_EPHYCON_RGMII
;
512 return MIIM_CIS8204_EPHYCON_INIT
;
515 /* Initialized required registers to appropriate values, zeroing
516 * those we don't care about (unless zero is bad, in which case,
517 * choose a more appropriate value) */
518 static void init_registers(volatile tsec_t
*regs
)
521 regs
->ievent
= IEVENT_INIT_CLEAR
;
523 regs
->imask
= IMASK_INIT_CLEAR
;
525 regs
->hash
.iaddr0
= 0;
526 regs
->hash
.iaddr1
= 0;
527 regs
->hash
.iaddr2
= 0;
528 regs
->hash
.iaddr3
= 0;
529 regs
->hash
.iaddr4
= 0;
530 regs
->hash
.iaddr5
= 0;
531 regs
->hash
.iaddr6
= 0;
532 regs
->hash
.iaddr7
= 0;
534 regs
->hash
.gaddr0
= 0;
535 regs
->hash
.gaddr1
= 0;
536 regs
->hash
.gaddr2
= 0;
537 regs
->hash
.gaddr3
= 0;
538 regs
->hash
.gaddr4
= 0;
539 regs
->hash
.gaddr5
= 0;
540 regs
->hash
.gaddr6
= 0;
541 regs
->hash
.gaddr7
= 0;
543 regs
->rctrl
= 0x00000000;
545 /* Init RMON mib registers */
546 memset((void *)&(regs
->rmon
), 0, sizeof(rmon_mib_t
));
548 regs
->rmon
.cam1
= 0xffffffff;
549 regs
->rmon
.cam2
= 0xffffffff;
551 regs
->mrblr
= MRBLR_INIT_SETTINGS
;
553 regs
->minflr
= MINFLR_INIT_SETTINGS
;
555 regs
->attr
= ATTR_INIT_SETTINGS
;
556 regs
->attreli
= ATTRELI_INIT_SETTINGS
;
561 /* Configure maccfg2 based on negotiated speed and duplex
562 * reported by PHY handling code */
563 static void adjust_link(struct eth_device
*dev
)
565 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
566 volatile tsec_t
*regs
= priv
->regs
;
569 if(priv
->duplexity
!= 0)
570 regs
->maccfg2
|= MACCFG2_FULL_DUPLEX
;
572 regs
->maccfg2
&= ~(MACCFG2_FULL_DUPLEX
);
574 switch(priv
->speed
) {
576 regs
->maccfg2
= ((regs
->maccfg2
&~(MACCFG2_IF
))
581 regs
->maccfg2
= ((regs
->maccfg2
&~(MACCFG2_IF
))
584 /* If We're in reduced mode, we need
585 * to say whether we're 10 or 100 MB.
587 if ((priv
->speed
== 100)
588 && (priv
->flags
& TSEC_REDUCED
))
589 regs
->ecntrl
|= ECNTRL_R100
;
591 regs
->ecntrl
&= ~(ECNTRL_R100
);
594 printf("%s: Speed was bad\n", dev
->name
);
598 printf("Speed: %d, %s duplex\n", priv
->speed
,
599 (priv
->duplexity
) ? "full" : "half");
602 printf("%s: No link.\n", dev
->name
);
607 /* Set up the buffers and their descriptors, and bring up the
609 static void startup_tsec(struct eth_device
*dev
)
612 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
613 volatile tsec_t
*regs
= priv
->regs
;
615 /* Point to the buffer descriptors */
616 regs
->tbase
= (unsigned int)(&rtx
.txbd
[txIdx
]);
617 regs
->rbase
= (unsigned int)(&rtx
.rxbd
[rxIdx
]);
619 /* Initialize the Rx Buffer descriptors */
620 for (i
= 0; i
< PKTBUFSRX
; i
++) {
621 rtx
.rxbd
[i
].status
= RXBD_EMPTY
;
622 rtx
.rxbd
[i
].length
= 0;
623 rtx
.rxbd
[i
].bufPtr
= (uint
)NetRxPackets
[i
];
625 rtx
.rxbd
[PKTBUFSRX
-1].status
|= RXBD_WRAP
;
627 /* Initialize the TX Buffer Descriptors */
628 for(i
=0; i
<TX_BUF_CNT
; i
++) {
629 rtx
.txbd
[i
].status
= 0;
630 rtx
.txbd
[i
].length
= 0;
631 rtx
.txbd
[i
].bufPtr
= 0;
633 rtx
.txbd
[TX_BUF_CNT
-1].status
|= TXBD_WRAP
;
635 /* Start up the PHY */
636 phy_run_commands(priv
, priv
->phyinfo
->startup
);
639 /* Enable Transmit and Receive */
640 regs
->maccfg1
|= (MACCFG1_RX_EN
| MACCFG1_TX_EN
);
642 /* Tell the DMA it is clear to go */
643 regs
->dmactrl
|= DMACTRL_INIT_SETTINGS
;
644 regs
->tstat
= TSTAT_CLEAR_THALT
;
645 regs
->dmactrl
&= ~(DMACTRL_GRS
| DMACTRL_GTS
);
648 /* This returns the status bits of the device. The return value
649 * is never checked, and this is what the 8260 driver did, so we
650 * do the same. Presumably, this would be zero if there were no
652 static int tsec_send(struct eth_device
* dev
, volatile void *packet
, int length
)
656 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
657 volatile tsec_t
*regs
= priv
->regs
;
659 /* Find an empty buffer descriptor */
660 for(i
=0; rtx
.txbd
[txIdx
].status
& TXBD_READY
; i
++) {
661 if (i
>= TOUT_LOOP
) {
662 debug ("%s: tsec: tx buffers full\n", dev
->name
);
667 rtx
.txbd
[txIdx
].bufPtr
= (uint
)packet
;
668 rtx
.txbd
[txIdx
].length
= length
;
669 rtx
.txbd
[txIdx
].status
|= (TXBD_READY
| TXBD_LAST
| TXBD_CRC
| TXBD_INTERRUPT
);
671 /* Tell the DMA to go */
672 regs
->tstat
= TSTAT_CLEAR_THALT
;
674 /* Wait for buffer to be transmitted */
675 for(i
=0; rtx
.txbd
[txIdx
].status
& TXBD_READY
; i
++) {
676 if (i
>= TOUT_LOOP
) {
677 debug ("%s: tsec: tx error\n", dev
->name
);
682 txIdx
= (txIdx
+ 1) % TX_BUF_CNT
;
683 result
= rtx
.txbd
[txIdx
].status
& TXBD_STATS
;
688 static int tsec_recv(struct eth_device
* dev
)
691 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
692 volatile tsec_t
*regs
= priv
->regs
;
694 while(!(rtx
.rxbd
[rxIdx
].status
& RXBD_EMPTY
)) {
696 length
= rtx
.rxbd
[rxIdx
].length
;
698 /* Send the packet up if there were no errors */
699 if (!(rtx
.rxbd
[rxIdx
].status
& RXBD_STATS
)) {
700 NetReceive(NetRxPackets
[rxIdx
], length
- 4);
702 printf("Got error %x\n",
703 (rtx
.rxbd
[rxIdx
].status
& RXBD_STATS
));
706 rtx
.rxbd
[rxIdx
].length
= 0;
708 /* Set the wrap bit if this is the last element in the list */
709 rtx
.rxbd
[rxIdx
].status
= RXBD_EMPTY
| (((rxIdx
+ 1) == PKTBUFSRX
) ? RXBD_WRAP
: 0);
711 rxIdx
= (rxIdx
+ 1) % PKTBUFSRX
;
714 if(regs
->ievent
&IEVENT_BSY
) {
715 regs
->ievent
= IEVENT_BSY
;
716 regs
->rstat
= RSTAT_CLEAR_RHALT
;
724 /* Stop the interface */
725 static void tsec_halt(struct eth_device
* dev
)
727 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
728 volatile tsec_t
*regs
= priv
->regs
;
730 regs
->dmactrl
&= ~(DMACTRL_GRS
| DMACTRL_GTS
);
731 regs
->dmactrl
|= (DMACTRL_GRS
| DMACTRL_GTS
);
733 while(!(regs
->ievent
& (IEVENT_GRSC
| IEVENT_GTSC
)));
735 regs
->maccfg1
&= ~(MACCFG1_TX_EN
| MACCFG1_RX_EN
);
737 /* Shut down the PHY, as needed */
738 phy_run_commands(priv
, priv
->phyinfo
->shutdown
);
742 struct phy_info phy_info_M88E1011S
= {
746 (struct phy_cmd
[]) { /* config */
747 /* Reset and configure the PHY */
748 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
750 {0x1e, 0x200c, NULL
},
754 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
755 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
756 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
757 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
760 (struct phy_cmd
[]) { /* startup */
761 /* Status is read once to clear old link state */
762 {MIIM_STATUS
, miim_read
, NULL
},
764 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
765 /* Read the status */
766 {MIIM_88E1011_PHY_STATUS
, miim_read
, &mii_parse_88E1011_psr
},
769 (struct phy_cmd
[]) { /* shutdown */
774 struct phy_info phy_info_M88E1111S
= {
778 (struct phy_cmd
[]) { /* config */
779 /* Reset and configure the PHY */
780 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
782 {0x1e, 0x200c, NULL
},
786 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
787 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
788 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
789 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
792 (struct phy_cmd
[]) { /* startup */
793 /* Status is read once to clear old link state */
794 {MIIM_STATUS
, miim_read
, NULL
},
796 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
797 /* Read the status */
798 {MIIM_88E1011_PHY_STATUS
, miim_read
, &mii_parse_88E1011_psr
},
801 (struct phy_cmd
[]) { /* shutdown */
806 struct phy_info phy_info_cis8204
= {
810 (struct phy_cmd
[]) { /* config */
811 /* Override PHY config settings */
812 {MIIM_CIS8201_AUX_CONSTAT
, MIIM_CIS8201_AUXCONSTAT_INIT
, NULL
},
813 /* Configure some basic stuff */
814 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
815 {MIIM_CIS8204_SLED_CON
, MIIM_CIS8204_SLEDCON_INIT
, &mii_cis8204_fixled
},
816 {MIIM_CIS8204_EPHY_CON
, MIIM_CIS8204_EPHYCON_INIT
, &mii_cis8204_setmode
},
819 (struct phy_cmd
[]) { /* startup */
820 /* Read the Status (2x to make sure link is right) */
821 {MIIM_STATUS
, miim_read
, NULL
},
823 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
824 /* Read the status */
825 {MIIM_CIS8201_AUX_CONSTAT
, miim_read
, &mii_parse_cis8201
},
828 (struct phy_cmd
[]) { /* shutdown */
834 struct phy_info phy_info_cis8201
= {
838 (struct phy_cmd
[]) { /* config */
839 /* Override PHY config settings */
840 {MIIM_CIS8201_AUX_CONSTAT
, MIIM_CIS8201_AUXCONSTAT_INIT
, NULL
},
841 /* Set up the interface mode */
842 {MIIM_CIS8201_EXT_CON1
, MIIM_CIS8201_EXTCON1_INIT
, NULL
},
843 /* Configure some basic stuff */
844 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
847 (struct phy_cmd
[]) { /* startup */
848 /* Read the Status (2x to make sure link is right) */
849 {MIIM_STATUS
, miim_read
, NULL
},
851 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
852 /* Read the status */
853 {MIIM_CIS8201_AUX_CONSTAT
, miim_read
, &mii_parse_cis8201
},
856 (struct phy_cmd
[]) { /* shutdown */
862 struct phy_info phy_info_dm9161
= {
866 (struct phy_cmd
[]) { /* config */
867 {MIIM_CONTROL
, MIIM_DM9161_CR_STOP
, NULL
},
868 /* Do not bypass the scrambler/descrambler */
869 {MIIM_DM9161_SCR
, MIIM_DM9161_SCR_INIT
, NULL
},
870 /* Clear 10BTCSR to default */
871 {MIIM_DM9161_10BTCSR
, MIIM_DM9161_10BTCSR_INIT
, NULL
},
872 /* Configure some basic stuff */
873 {MIIM_CONTROL
, MIIM_CR_INIT
, NULL
},
874 /* Restart Auto Negotiation */
875 {MIIM_CONTROL
, MIIM_DM9161_CR_RSTAN
, NULL
},
878 (struct phy_cmd
[]) { /* startup */
879 /* Status is read once to clear old link state */
880 {MIIM_STATUS
, miim_read
, NULL
},
882 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
883 /* Read the status */
884 {MIIM_DM9161_SCSR
, miim_read
, &mii_parse_dm9161_scsr
},
887 (struct phy_cmd
[]) { /* shutdown */
892 uint
mii_parse_lxt971_sr2(uint mii_reg
, struct tsec_private
*priv
)
896 speed
= mii_reg
& MIIM_LXT971_SR2_SPEED_MASK
;
899 case MIIM_LXT971_SR2_10HDX
:
903 case MIIM_LXT971_SR2_10FDX
:
907 case MIIM_LXT971_SR2_100HDX
:
923 static struct phy_info phy_info_lxt971
= {
927 (struct phy_cmd
[]) { /* config */
928 { MIIM_CR
, MIIM_CR_INIT
, mii_cr_init
}, /* autonegotiate */
931 (struct phy_cmd
[]) { /* startup - enable interrupts */
932 /* { 0x12, 0x00f2, NULL }, */
933 { MIIM_STATUS
, miim_read
, NULL
},
934 { MIIM_STATUS
, miim_read
, &mii_parse_sr
},
935 { MIIM_LXT971_SR2
, miim_read
, &mii_parse_lxt971_sr2
},
938 (struct phy_cmd
[]) { /* shutdown - disable interrupts */
943 /* Parse the DP83865's link and auto-neg status register for speed and duplex
945 uint
mii_parse_dp83865_lanr(uint mii_reg
, struct tsec_private
*priv
)
947 switch (mii_reg
& MIIM_DP83865_SPD_MASK
) {
949 case MIIM_DP83865_SPD_1000
:
953 case MIIM_DP83865_SPD_100
:
963 if (mii_reg
& MIIM_DP83865_DPX_FULL
)
971 struct phy_info phy_info_dp83865
= {
975 (struct phy_cmd
[]) { /* config */
976 {MIIM_CONTROL
, MIIM_DP83865_CR_INIT
, NULL
},
979 (struct phy_cmd
[]) { /* startup */
980 /* Status is read once to clear old link state */
981 {MIIM_STATUS
, miim_read
, NULL
},
983 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
984 /* Read the link and auto-neg status */
985 {MIIM_DP83865_LANR
, miim_read
, &mii_parse_dp83865_lanr
},
988 (struct phy_cmd
[]) { /* shutdown */
993 struct phy_info
*phy_info
[] = {
1007 /* Grab the identifier of the device's PHY, and search through
1008 * all of the known PHYs to see if one matches. If so, return
1009 * it, if not, return NULL */
1010 struct phy_info
* get_phy_info(struct eth_device
*dev
)
1012 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
1013 uint phy_reg
, phy_ID
;
1015 struct phy_info
*theInfo
= NULL
;
1017 /* Grab the bits from PHYIR1, and put them in the upper half */
1018 phy_reg
= read_phy_reg(priv
, MIIM_PHYIR1
);
1019 phy_ID
= (phy_reg
& 0xffff) << 16;
1021 /* Grab the bits from PHYIR2, and put them in the lower half */
1022 phy_reg
= read_phy_reg(priv
, MIIM_PHYIR2
);
1023 phy_ID
|= (phy_reg
& 0xffff);
1025 /* loop through all the known PHY types, and find one that */
1026 /* matches the ID we read from the PHY. */
1027 for(i
=0; phy_info
[i
]; i
++) {
1028 if(phy_info
[i
]->id
== (phy_ID
>> phy_info
[i
]->shift
))
1029 theInfo
= phy_info
[i
];
1034 printf("%s: PHY id %x is not supported!\n", dev
->name
, phy_ID
);
1037 debug("%s: PHY is %s (%x)\n", dev
->name
, theInfo
->name
, phy_ID
);
1044 /* Execute the given series of commands on the given device's
1045 * PHY, running functions as necessary*/
1046 void phy_run_commands(struct tsec_private
*priv
, struct phy_cmd
*cmd
)
1050 volatile tsec_t
*phyregs
= priv
->phyregs
;
1052 phyregs
->miimcfg
= MIIMCFG_RESET
;
1054 phyregs
->miimcfg
= MIIMCFG_INIT_VALUE
;
1056 while(phyregs
->miimind
& MIIMIND_BUSY
);
1058 for(i
=0;cmd
->mii_reg
!= miim_end
;i
++) {
1059 if(cmd
->mii_data
== miim_read
) {
1060 result
= read_phy_reg(priv
, cmd
->mii_reg
);
1062 if(cmd
->funct
!= NULL
)
1063 (*(cmd
->funct
))(result
, priv
);
1066 if(cmd
->funct
!= NULL
)
1067 result
= (*(cmd
->funct
))(cmd
->mii_reg
, priv
);
1069 result
= cmd
->mii_data
;
1071 write_phy_reg(priv
, cmd
->mii_reg
, result
);
1079 /* Relocate the function pointers in the phy cmd lists */
1080 static void relocate_cmds(void)
1082 struct phy_cmd
**cmdlistptr
;
1083 struct phy_cmd
*cmd
;
1085 DECLARE_GLOBAL_DATA_PTR
;
1087 for(i
=0; phy_info
[i
]; i
++) {
1088 /* First thing's first: relocate the pointers to the
1089 * PHY command structures (the structs were done) */
1090 phy_info
[i
] = (struct phy_info
*) ((uint
)phy_info
[i
]
1092 phy_info
[i
]->name
+= gd
->reloc_off
;
1093 phy_info
[i
]->config
=
1094 (struct phy_cmd
*)((uint
)phy_info
[i
]->config
1096 phy_info
[i
]->startup
=
1097 (struct phy_cmd
*)((uint
)phy_info
[i
]->startup
1099 phy_info
[i
]->shutdown
=
1100 (struct phy_cmd
*)((uint
)phy_info
[i
]->shutdown
1103 cmdlistptr
= &phy_info
[i
]->config
;
1105 for(;cmdlistptr
<= &phy_info
[i
]->shutdown
;cmdlistptr
++) {
1107 for(cmd
=*cmdlistptr
;cmd
->mii_reg
!= miim_end
;cmd
++) {
1108 /* Only relocate non-NULL pointers */
1110 cmd
->funct
+= gd
->reloc_off
;
1122 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
1123 && !defined(BITBANGMII)
1125 struct tsec_private
* get_priv_for_phy(unsigned char phyaddr
)
1129 for(i
=0;i
<MAXCONTROLLERS
;i
++) {
1130 if(privlist
[i
]->phyaddr
== phyaddr
)
1138 * Read a MII PHY register.
1143 static int tsec_miiphy_read(char *devname
, unsigned char addr
,
1144 unsigned char reg
, unsigned short *value
)
1147 struct tsec_private
*priv
= get_priv_for_phy(addr
);
1150 printf("Can't read PHY at address %d\n", addr
);
1154 ret
= (unsigned short)read_phy_reg(priv
, reg
);
1161 * Write a MII PHY register.
1166 static int tsec_miiphy_write(char *devname
, unsigned char addr
,
1167 unsigned char reg
, unsigned short value
)
1169 struct tsec_private
*priv
= get_priv_for_phy(addr
);
1172 printf("Can't write PHY at address %d\n", addr
);
1176 write_phy_reg(priv
, reg
, value
);
1181 #endif /* defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
1182 && !defined(BITBANGMII) */
1184 #endif /* CONFIG_TSEC_ENET */