blob: 7600e40de906d20d5885744878296d265f1333fc [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
wdenka445ddf2004-06-09 00:34:46 +00002 * Freescale Three Speed Ethernet Controller driver
wdenk9c53f402003-10-15 23:53:47 +00003 *
4 * This software may be used and distributed according to the
5 * terms of the GNU Public License, Version 2, incorporated
6 * herein by reference.
7 *
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +05308 * Copyright 2004-2009 Freescale Semiconductor, Inc.
wdenk9c53f402003-10-15 23:53:47 +00009 * (C) Copyright 2003, Motorola, Inc.
wdenk9c53f402003-10-15 23:53:47 +000010 * author Andy Fleming
11 *
12 */
13
14#include <config.h>
wdenk9c53f402003-10-15 23:53:47 +000015#include <common.h>
16#include <malloc.h>
17#include <net.h>
18#include <command.h>
Andy Flemingc067fc12008-08-31 16:33:25 -050019#include <tsec.h>
Kim Phillipsae4dd972009-08-24 14:32:26 -050020#include <asm/errno.h>
wdenk9c53f402003-10-15 23:53:47 +000021
Marian Balakowiczaab8c492005-10-28 22:30:33 +020022#include "miiphy.h"
wdenk9c53f402003-10-15 23:53:47 +000023
Wolfgang Denk6405a152006-03-31 18:32:53 +020024DECLARE_GLOBAL_DATA_PTR;
25
Marian Balakowiczaab8c492005-10-28 22:30:33 +020026#define TX_BUF_CNT 2
wdenk9c53f402003-10-15 23:53:47 +000027
Jon Loeligerb7ced082006-10-10 17:03:43 -050028static uint rxIdx; /* index of the current RX buffer */
29static uint txIdx; /* index of the current TX buffer */
wdenk9c53f402003-10-15 23:53:47 +000030
31typedef volatile struct rtxbd {
32 txbd8_t txbd[TX_BUF_CNT];
33 rxbd8_t rxbd[PKTBUFSRX];
Jon Loeligerb7ced082006-10-10 17:03:43 -050034} RTXBD;
wdenk9c53f402003-10-15 23:53:47 +000035
Andy Flemingfecff2b2008-08-31 16:33:26 -050036#define MAXCONTROLLERS (8)
wdenka445ddf2004-06-09 00:34:46 +000037
wdenka445ddf2004-06-09 00:34:46 +000038static struct tsec_private *privlist[MAXCONTROLLERS];
Andy Flemingfecff2b2008-08-31 16:33:26 -050039static int num_tsecs = 0;
wdenka445ddf2004-06-09 00:34:46 +000040
wdenk9c53f402003-10-15 23:53:47 +000041#ifdef __GNUC__
42static RTXBD rtx __attribute__ ((aligned(8)));
43#else
44#error "rtx must be 64-bit aligned"
45#endif
46
Jon Loeligerb7ced082006-10-10 17:03:43 -050047static int tsec_send(struct eth_device *dev,
48 volatile void *packet, int length);
49static int tsec_recv(struct eth_device *dev);
50static int tsec_init(struct eth_device *dev, bd_t * bd);
Peter Tyser08b2d782009-11-09 13:09:45 -060051static int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info);
Jon Loeligerb7ced082006-10-10 17:03:43 -050052static void tsec_halt(struct eth_device *dev);
53static void init_registers(volatile tsec_t * regs);
wdenka445ddf2004-06-09 00:34:46 +000054static void startup_tsec(struct eth_device *dev);
55static int init_phy(struct eth_device *dev);
56void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
57uint read_phy_reg(struct tsec_private *priv, uint regnum);
Peter Tyser08b2d782009-11-09 13:09:45 -060058static struct phy_info *get_phy_info(struct eth_device *dev);
59static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
wdenka445ddf2004-06-09 00:34:46 +000060static void adjust_link(struct eth_device *dev);
Wolfgang Denk92254112007-11-18 16:36:27 +010061#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
62 && !defined(BITBANGMII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +020063static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -050064 unsigned char reg, unsigned short value);
Marian Balakowiczaab8c492005-10-28 22:30:33 +020065static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -050066 unsigned char reg, unsigned short *value);
Wolfgang Denk92254112007-11-18 16:36:27 +010067#endif
David Updegraff7280da72007-06-11 10:41:07 -050068#ifdef CONFIG_MCAST_TFTP
69static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set);
70#endif
wdenk78924a72004-04-18 21:45:42 +000071
Andy Flemingfecff2b2008-08-31 16:33:26 -050072/* Default initializations for TSEC controllers. */
73
74static struct tsec_info_struct tsec_info[] = {
75#ifdef CONFIG_TSEC1
76 STD_TSEC_INFO(1), /* TSEC1 */
77#endif
78#ifdef CONFIG_TSEC2
79 STD_TSEC_INFO(2), /* TSEC2 */
80#endif
81#ifdef CONFIG_MPC85XX_FEC
82 {
83 .regs = (tsec_t *)(TSEC_BASE_ADDR + 0x2000),
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +053084 .miiregs = (tsec_mdio_t *)(MDIO_BASE_ADDR),
Andy Flemingfecff2b2008-08-31 16:33:26 -050085 .devname = CONFIG_MPC85XX_FEC_NAME,
86 .phyaddr = FEC_PHY_ADDR,
87 .flags = FEC_FLAGS
88 }, /* FEC */
89#endif
90#ifdef CONFIG_TSEC3
91 STD_TSEC_INFO(3), /* TSEC3 */
92#endif
93#ifdef CONFIG_TSEC4
94 STD_TSEC_INFO(4), /* TSEC4 */
95#endif
96};
97
98int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num)
99{
100 int i;
101
102 for (i = 0; i < num; i++)
103 tsec_initialize(bis, &tsecs[i]);
104
105 return 0;
106}
107
108int tsec_standard_init(bd_t *bis)
109{
110 return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
111}
112
wdenka445ddf2004-06-09 00:34:46 +0000113/* Initialize device structure. Returns success if PHY
114 * initialization succeeded (i.e. if it recognizes the PHY)
115 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600116static int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info)
wdenk9c53f402003-10-15 23:53:47 +0000117{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500118 struct eth_device *dev;
wdenk9c53f402003-10-15 23:53:47 +0000119 int i;
wdenka445ddf2004-06-09 00:34:46 +0000120 struct tsec_private *priv;
wdenk9c53f402003-10-15 23:53:47 +0000121
Jon Loeligerb7ced082006-10-10 17:03:43 -0500122 dev = (struct eth_device *)malloc(sizeof *dev);
wdenk9c53f402003-10-15 23:53:47 +0000123
Jon Loeligerb7ced082006-10-10 17:03:43 -0500124 if (NULL == dev)
wdenk9c53f402003-10-15 23:53:47 +0000125 return 0;
126
127 memset(dev, 0, sizeof *dev);
128
Jon Loeligerb7ced082006-10-10 17:03:43 -0500129 priv = (struct tsec_private *)malloc(sizeof(*priv));
wdenka445ddf2004-06-09 00:34:46 +0000130
Jon Loeligerb7ced082006-10-10 17:03:43 -0500131 if (NULL == priv)
wdenka445ddf2004-06-09 00:34:46 +0000132 return 0;
133
Andy Flemingfecff2b2008-08-31 16:33:26 -0500134 privlist[num_tsecs++] = priv;
135 priv->regs = tsec_info->regs;
136 priv->phyregs = tsec_info->miiregs;
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530137 priv->phyregs_sgmii = tsec_info->miiregs_sgmii;
wdenka445ddf2004-06-09 00:34:46 +0000138
Andy Flemingfecff2b2008-08-31 16:33:26 -0500139 priv->phyaddr = tsec_info->phyaddr;
140 priv->flags = tsec_info->flags;
wdenka445ddf2004-06-09 00:34:46 +0000141
Andy Flemingfecff2b2008-08-31 16:33:26 -0500142 sprintf(dev->name, tsec_info->devname);
wdenk9c53f402003-10-15 23:53:47 +0000143 dev->iobase = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500144 dev->priv = priv;
145 dev->init = tsec_init;
146 dev->halt = tsec_halt;
147 dev->send = tsec_send;
148 dev->recv = tsec_recv;
David Updegraff7280da72007-06-11 10:41:07 -0500149#ifdef CONFIG_MCAST_TFTP
150 dev->mcast = tsec_mcast_addr;
151#endif
wdenk9c53f402003-10-15 23:53:47 +0000152
153 /* Tell u-boot to get the addr from the env */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500154 for (i = 0; i < 6; i++)
wdenk9c53f402003-10-15 23:53:47 +0000155 dev->enetaddr[i] = 0;
156
157 eth_register(dev);
158
wdenka445ddf2004-06-09 00:34:46 +0000159 /* Reset the MAC */
160 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
Andy Fleming2d1db142009-02-03 18:26:41 -0600161 udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
wdenka445ddf2004-06-09 00:34:46 +0000162 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
wdenk78924a72004-04-18 21:45:42 +0000163
Jon Loeliger82ecaad2007-07-09 17:39:42 -0500164#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200165 && !defined(BITBANGMII)
166 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
167#endif
168
wdenka445ddf2004-06-09 00:34:46 +0000169 /* Try to initialize PHY here, and return */
170 return init_phy(dev);
wdenk9c53f402003-10-15 23:53:47 +0000171}
172
wdenk9c53f402003-10-15 23:53:47 +0000173/* Initializes data structures and registers for the controller,
wdenkbfad55d2005-03-14 23:56:42 +0000174 * and brings the interface up. Returns the link status, meaning
wdenka445ddf2004-06-09 00:34:46 +0000175 * that it returns success if the link is up, failure otherwise.
Jon Loeligerb7ced082006-10-10 17:03:43 -0500176 * This allows u-boot to find the first active controller.
177 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600178static int tsec_init(struct eth_device *dev, bd_t * bd)
wdenk9c53f402003-10-15 23:53:47 +0000179{
wdenk9c53f402003-10-15 23:53:47 +0000180 uint tempval;
181 char tmpbuf[MAC_ADDR_LEN];
182 int i;
wdenka445ddf2004-06-09 00:34:46 +0000183 struct tsec_private *priv = (struct tsec_private *)dev->priv;
184 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000185
186 /* Make sure the controller is stopped */
187 tsec_halt(dev);
188
wdenka445ddf2004-06-09 00:34:46 +0000189 /* Init MACCFG2. Defaults to GMII */
wdenk9c53f402003-10-15 23:53:47 +0000190 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
191
192 /* Init ECNTRL */
193 regs->ecntrl = ECNTRL_INIT_SETTINGS;
194
195 /* Copy the station address into the address registers.
196 * Backwards, because little endian MACS are dumb */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500197 for (i = 0; i < MAC_ADDR_LEN; i++) {
wdenka445ddf2004-06-09 00:34:46 +0000198 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenk9c53f402003-10-15 23:53:47 +0000199 }
Kim Phillips4f8b6332009-07-17 12:17:00 -0500200 tempval = (tmpbuf[0] << 24) | (tmpbuf[1] << 16) | (tmpbuf[2] << 8) |
201 tmpbuf[3];
202
203 regs->macstnaddr1 = tempval;
wdenk9c53f402003-10-15 23:53:47 +0000204
Jon Loeligerb7ced082006-10-10 17:03:43 -0500205 tempval = *((uint *) (tmpbuf + 4));
wdenk9c53f402003-10-15 23:53:47 +0000206
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200207 regs->macstnaddr2 = tempval;
wdenk9c53f402003-10-15 23:53:47 +0000208
wdenk9c53f402003-10-15 23:53:47 +0000209 /* reset the indices to zero */
210 rxIdx = 0;
211 txIdx = 0;
212
213 /* Clear out (for the most part) the other registers */
214 init_registers(regs);
215
216 /* Ready the device for tx/rx */
wdenka445ddf2004-06-09 00:34:46 +0000217 startup_tsec(dev);
wdenk9c53f402003-10-15 23:53:47 +0000218
wdenka445ddf2004-06-09 00:34:46 +0000219 /* If there's no link, fail */
Ben Warrende9fcb52008-01-09 18:15:53 -0500220 return (priv->link ? 0 : -1);
wdenka445ddf2004-06-09 00:34:46 +0000221}
wdenk9c53f402003-10-15 23:53:47 +0000222
Andy Flemingac65e072008-08-31 16:33:27 -0500223/* Writes the given phy's reg with value, using the specified MDIO regs */
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530224static void tsec_local_mdio_write(volatile tsec_mdio_t *phyregs, uint addr,
Andy Flemingac65e072008-08-31 16:33:27 -0500225 uint reg, uint value)
wdenka445ddf2004-06-09 00:34:46 +0000226{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500227 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000228
Andy Flemingac65e072008-08-31 16:33:27 -0500229 phyregs->miimadd = (addr << 8) | reg;
230 phyregs->miimcon = value;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500231 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000232
Jon Loeligerb7ced082006-10-10 17:03:43 -0500233 timeout = 1000000;
Andy Flemingac65e072008-08-31 16:33:27 -0500234 while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000235}
236
Andy Flemingac65e072008-08-31 16:33:27 -0500237
238/* Provide the default behavior of writing the PHY of this ethernet device */
Peter Tyser4ef03c02009-11-09 13:09:46 -0600239#define write_phy_reg(priv, regnum, value) \
240 tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
michael.firth@bt.com08384842008-01-16 11:40:51 +0000241
wdenka445ddf2004-06-09 00:34:46 +0000242/* Reads register regnum on the device's PHY through the
Andy Flemingac65e072008-08-31 16:33:27 -0500243 * specified registers. It lowers and raises the read
wdenka445ddf2004-06-09 00:34:46 +0000244 * command, and waits for the data to become valid (miimind
245 * notvalid bit cleared), and the bus to cease activity (miimind
246 * busy bit cleared), and then returns the value
247 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600248static uint tsec_local_mdio_read(volatile tsec_mdio_t *phyregs,
249 uint phyid, uint regnum)
wdenk9c53f402003-10-15 23:53:47 +0000250{
251 uint value;
252
wdenka445ddf2004-06-09 00:34:46 +0000253 /* Put the address of the phy, and the register
254 * number into MIIMADD */
Andy Flemingac65e072008-08-31 16:33:27 -0500255 phyregs->miimadd = (phyid << 8) | regnum;
wdenk9c53f402003-10-15 23:53:47 +0000256
257 /* Clear the command register, and wait */
Andy Flemingac65e072008-08-31 16:33:27 -0500258 phyregs->miimcom = 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500259 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000260
261 /* Initiate a read command, and wait */
Andy Flemingac65e072008-08-31 16:33:27 -0500262 phyregs->miimcom = MIIM_READ_COMMAND;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500263 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000264
265 /* Wait for the the indication that the read is done */
Andy Flemingac65e072008-08-31 16:33:27 -0500266 while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
wdenk9c53f402003-10-15 23:53:47 +0000267
268 /* Grab the value read from the PHY */
Andy Flemingac65e072008-08-31 16:33:27 -0500269 value = phyregs->miimstat;
wdenk9c53f402003-10-15 23:53:47 +0000270
271 return value;
272}
273
michael.firth@bt.com08384842008-01-16 11:40:51 +0000274/* #define to provide old read_phy_reg functionality without duplicating code */
Peter Tyser4ef03c02009-11-09 13:09:46 -0600275#define read_phy_reg(priv,regnum) \
276 tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
Andy Flemingac65e072008-08-31 16:33:27 -0500277
278#define TBIANA_SETTINGS ( \
279 TBIANA_ASYMMETRIC_PAUSE \
280 | TBIANA_SYMMETRIC_PAUSE \
281 | TBIANA_FULL_DUPLEX \
282 )
283
Peter Tyser583c1f42009-11-03 17:52:07 -0600284/* Force the TBI PHY into 1000Mbps full duplex when in SGMII mode */
Andy Flemingac65e072008-08-31 16:33:27 -0500285#define TBICR_SETTINGS ( \
286 TBICR_PHY_RESET \
Andy Flemingac65e072008-08-31 16:33:27 -0500287 | TBICR_FULL_DUPLEX \
288 | TBICR_SPEED1_SET \
289 )
Peter Tyser583c1f42009-11-03 17:52:07 -0600290
Andy Flemingac65e072008-08-31 16:33:27 -0500291/* Configure the TBI for SGMII operation */
292static void tsec_configure_serdes(struct tsec_private *priv)
293{
Peter Tyser4ef03c02009-11-09 13:09:46 -0600294 /* Access TBI PHY registers at given TSEC register offset as opposed
295 * to the register offset used for external PHY accesses */
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530296 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_ANA,
Andy Flemingac65e072008-08-31 16:33:27 -0500297 TBIANA_SETTINGS);
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530298 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_TBICON,
Andy Flemingac65e072008-08-31 16:33:27 -0500299 TBICON_CLK_SELECT);
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530300 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_CR,
Andy Flemingac65e072008-08-31 16:33:27 -0500301 TBICR_SETTINGS);
302}
michael.firth@bt.com08384842008-01-16 11:40:51 +0000303
wdenka445ddf2004-06-09 00:34:46 +0000304/* Discover which PHY is attached to the device, and configure it
305 * properly. If the PHY is not recognized, then return 0
306 * (failure). Otherwise, return 1
307 */
308static int init_phy(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000309{
wdenka445ddf2004-06-09 00:34:46 +0000310 struct tsec_private *priv = (struct tsec_private *)dev->priv;
311 struct phy_info *curphy;
Andy Flemingac65e072008-08-31 16:33:27 -0500312 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000313
314 /* Assign a Physical address to the TBI */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200315 regs->tbipa = CONFIG_SYS_TBIPA_VALUE;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500316 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000317
318 /* Reset MII (due to new addresses) */
319 priv->phyregs->miimcfg = MIIMCFG_RESET;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500320 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000321 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500322 asm("sync");
Jon Loeligerb7ced082006-10-10 17:03:43 -0500323 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
wdenk9c53f402003-10-15 23:53:47 +0000324
wdenka445ddf2004-06-09 00:34:46 +0000325 /* Get the cmd structure corresponding to the attached
326 * PHY */
327 curphy = get_phy_info(dev);
wdenk9c53f402003-10-15 23:53:47 +0000328
Ben Warrenf11eefb2006-10-26 14:38:25 -0400329 if (curphy == NULL) {
330 priv->phyinfo = NULL;
wdenka445ddf2004-06-09 00:34:46 +0000331 printf("%s: No PHY found\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000332
wdenka445ddf2004-06-09 00:34:46 +0000333 return 0;
334 }
wdenk9c53f402003-10-15 23:53:47 +0000335
Andy Flemingac65e072008-08-31 16:33:27 -0500336 if (regs->ecntrl & ECNTRL_SGMII_MODE)
337 tsec_configure_serdes(priv);
338
wdenka445ddf2004-06-09 00:34:46 +0000339 priv->phyinfo = curphy;
wdenk9c53f402003-10-15 23:53:47 +0000340
wdenka445ddf2004-06-09 00:34:46 +0000341 phy_run_commands(priv, priv->phyinfo->config);
wdenk9c53f402003-10-15 23:53:47 +0000342
wdenka445ddf2004-06-09 00:34:46 +0000343 return 1;
344}
wdenk9c53f402003-10-15 23:53:47 +0000345
Jon Loeligerb7ced082006-10-10 17:03:43 -0500346/*
347 * Returns which value to write to the control register.
348 * For 10/100, the value is slightly different
349 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600350static uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000351{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500352 if (priv->flags & TSEC_GIGABIT)
wdenka445ddf2004-06-09 00:34:46 +0000353 return MIIM_CONTROL_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000354 else
wdenka445ddf2004-06-09 00:34:46 +0000355 return MIIM_CR_INIT;
356}
wdenk9c53f402003-10-15 23:53:47 +0000357
Peter Tyser4c84fd52009-02-04 15:14:05 -0600358/*
359 * Wait for auto-negotiation to complete, then determine link
Jon Loeligerb7ced082006-10-10 17:03:43 -0500360 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600361static uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000362{
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200363 /*
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500364 * Wait if the link is up, and autonegotiation is in progress
365 * (ie - we're capable and it's not done)
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200366 */
367 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Peter Tyser4c84fd52009-02-04 15:14:05 -0600368 if ((mii_reg & PHY_BMSR_AUTN_ABLE) && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200369 int i = 0;
wdenk9c53f402003-10-15 23:53:47 +0000370
Jon Loeligerb7ced082006-10-10 17:03:43 -0500371 puts("Waiting for PHY auto negotiation to complete");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500372 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200373 /*
374 * Timeout reached ?
375 */
376 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500377 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200378 priv->link = 0;
Jin Zhengxiong-R64188487d2232006-06-27 18:12:23 +0800379 return 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200380 }
wdenk9c53f402003-10-15 23:53:47 +0000381
Kim Phillipsae4dd972009-08-24 14:32:26 -0500382 if (ctrlc()) {
383 puts("user interrupt!\n");
384 priv->link = 0;
385 return -EINTR;
386 }
387
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200388 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500389 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200390 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500391 udelay(1000); /* 1 ms */
wdenka445ddf2004-06-09 00:34:46 +0000392 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200393 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500394 puts(" done\n");
Peter Tyser4c84fd52009-02-04 15:14:05 -0600395
396 /* Link status bit is latched low, read it again */
397 mii_reg = read_phy_reg(priv, MIIM_STATUS);
398
Jon Loeligerb7ced082006-10-10 17:03:43 -0500399 udelay(500000); /* another 500 ms (results in faster booting) */
wdenk9c53f402003-10-15 23:53:47 +0000400 }
401
Peter Tyser4c84fd52009-02-04 15:14:05 -0600402 priv->link = mii_reg & MIIM_STATUS_LINK ? 1 : 0;
403
wdenka445ddf2004-06-09 00:34:46 +0000404 return 0;
405}
406
David Updegraff0451b012007-04-20 14:34:48 -0500407/* Generic function which updates the speed and duplex. If
408 * autonegotiation is enabled, it uses the AND of the link
409 * partner's advertised capabilities and our advertised
410 * capabilities. If autonegotiation is disabled, we use the
411 * appropriate bits in the control register.
412 *
413 * Stolen from Linux's mii.c and phy_device.c
414 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600415static uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
David Updegraff0451b012007-04-20 14:34:48 -0500416{
417 /* We're using autonegotiation */
418 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
419 uint lpa = 0;
420 uint gblpa = 0;
421
422 /* Check for gigabit capability */
423 if (mii_reg & PHY_BMSR_EXT) {
424 /* We want a list of states supported by
425 * both PHYs in the link
426 */
427 gblpa = read_phy_reg(priv, PHY_1000BTSR);
428 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
429 }
430
431 /* Set the baseline so we only have to set them
432 * if they're different
433 */
434 priv->speed = 10;
435 priv->duplexity = 0;
436
437 /* Check the gigabit fields */
438 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
439 priv->speed = 1000;
440
441 if (gblpa & PHY_1000BTSR_1000FD)
442 priv->duplexity = 1;
443
444 /* We're done! */
445 return 0;
446 }
447
448 lpa = read_phy_reg(priv, PHY_ANAR);
449 lpa &= read_phy_reg(priv, PHY_ANLPAR);
450
451 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
452 priv->speed = 100;
453
454 if (lpa & PHY_ANLPAR_TXFD)
455 priv->duplexity = 1;
456
457 } else if (lpa & PHY_ANLPAR_10FD)
458 priv->duplexity = 1;
459 } else {
460 uint bmcr = read_phy_reg(priv, PHY_BMCR);
461
462 priv->speed = 10;
463 priv->duplexity = 0;
464
465 if (bmcr & PHY_BMCR_DPLX)
466 priv->duplexity = 1;
467
468 if (bmcr & PHY_BMCR_1000_MBPS)
469 priv->speed = 1000;
470 else if (bmcr & PHY_BMCR_100_MBPS)
471 priv->speed = 100;
472 }
473
474 return 0;
475}
476
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500477/*
Zach LeRoyddb7fc72009-05-22 10:26:33 -0500478 * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
479 * circumstances. eg a gigabit TSEC connected to a gigabit switch with
480 * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
481 * link. "Ethernet@Wirespeed" reduces advertised speed until link
482 * can be achieved.
483 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600484static uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv)
Zach LeRoyddb7fc72009-05-22 10:26:33 -0500485{
486 return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010;
487}
488
489/*
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500490 * Parse the BCM54xx status register for speed and duplex information.
491 * The linux sungem_phy has this information, but in a table format.
492 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600493static uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500494{
Peter Tyserf6722902009-11-09 13:09:44 -0600495 /* If there is no link, speed and duplex don't matter */
496 if (!priv->link)
497 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500498
Peter Tyserf6722902009-11-09 13:09:44 -0600499 switch ((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >>
500 MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT) {
501 case 1:
502 priv->duplexity = 0;
503 priv->speed = 10;
504 break;
505 case 2:
506 priv->duplexity = 1;
507 priv->speed = 10;
508 break;
509 case 3:
510 priv->duplexity = 0;
511 priv->speed = 100;
512 break;
513 case 5:
514 priv->duplexity = 1;
515 priv->speed = 100;
516 break;
517 case 6:
518 priv->duplexity = 0;
519 priv->speed = 1000;
520 break;
521 case 7:
522 priv->duplexity = 1;
523 priv->speed = 1000;
524 break;
525 default:
526 printf("Auto-neg error, defaulting to 10BT/HD\n");
527 priv->duplexity = 0;
528 priv->speed = 10;
529 break;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500530 }
531
532 return 0;
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600533}
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500534
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600535/*
536 * Find out if PHY is in copper or serdes mode by looking at Expansion Reg
537 * 0x42 - "Operating Mode Status Register"
538 */
539static int BCM8482_is_serdes(struct tsec_private *priv)
540{
541 u16 val;
542 int serdes = 0;
543
544 write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_ER | 0x42);
545 val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA);
546
547 switch (val & 0x1f) {
548 case 0x0d: /* RGMII-to-100Base-FX */
549 case 0x0e: /* RGMII-to-SGMII */
550 case 0x0f: /* RGMII-to-SerDes */
551 case 0x12: /* SGMII-to-SerDes */
552 case 0x13: /* SGMII-to-100Base-FX */
553 case 0x16: /* SerDes-to-Serdes */
554 serdes = 1;
555 break;
556 case 0x6: /* RGMII-to-Copper */
557 case 0x14: /* SGMII-to-Copper */
558 case 0x17: /* SerDes-to-Copper */
559 break;
560 default:
561 printf("ERROR, invalid PHY mode (0x%x\n)", val);
562 break;
563 }
564
565 return serdes;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500566}
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600567
568/*
569 * Determine SerDes link speed and duplex from Expansion reg 0x42 "Operating
570 * Mode Status Register"
571 */
572uint mii_parse_BCM5482_serdes_sr(struct tsec_private *priv)
573{
574 u16 val;
575 int i = 0;
576
577 /* Wait 1s for link - Clause 37 autonegotiation happens very fast */
578 while (1) {
579 write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL,
580 MIIM_BCM54XX_EXP_SEL_ER | 0x42);
581 val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA);
582
583 if (val & 0x8000)
584 break;
585
586 if (i++ > 1000) {
587 priv->link = 0;
588 return 1;
589 }
590
591 udelay(1000); /* 1 ms */
592 }
593
594 priv->link = 1;
595 switch ((val >> 13) & 0x3) {
596 case (0x00):
597 priv->speed = 10;
598 break;
599 case (0x01):
600 priv->speed = 100;
601 break;
602 case (0x02):
603 priv->speed = 1000;
604 break;
605 }
606
607 priv->duplexity = (val & 0x1000) == 0x1000;
608
609 return 0;
610}
611
612/*
613 * Figure out if BCM5482 is in serdes or copper mode and determine link
614 * configuration accordingly
615 */
616static uint mii_parse_BCM5482_sr(uint mii_reg, struct tsec_private *priv)
617{
618 if (BCM8482_is_serdes(priv)) {
619 mii_parse_BCM5482_serdes_sr(priv);
620 } else {
621 /* Wait for auto-negotiation to complete or fail */
622 mii_parse_sr(mii_reg, priv);
623
624 /* Parse BCM54xx copper aux status register */
625 mii_reg = read_phy_reg(priv, MIIM_BCM54xx_AUXSTATUS);
626 mii_parse_BCM54xx_sr(mii_reg, priv);
627 }
628
629 return 0;
630}
631
wdenka445ddf2004-06-09 00:34:46 +0000632/* Parse the 88E1011's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500633 * information
634 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600635static uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000636{
637 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000638
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200639 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
640
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500641 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
642 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200643 int i = 0;
644
Jon Loeligerb7ced082006-10-10 17:03:43 -0500645 puts("Waiting for PHY realtime link");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500646 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
647 /* Timeout reached ? */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200648 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500649 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200650 priv->link = 0;
651 break;
652 }
653
654 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500655 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200656 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500657 udelay(1000); /* 1 ms */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200658 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
659 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500660 puts(" done\n");
661 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500662 } else {
663 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
664 priv->link = 1;
665 else
666 priv->link = 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200667 }
668
Jon Loeligerb7ced082006-10-10 17:03:43 -0500669 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000670 priv->duplexity = 1;
671 else
672 priv->duplexity = 0;
673
Jon Loeligerb7ced082006-10-10 17:03:43 -0500674 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenka445ddf2004-06-09 00:34:46 +0000675
Jon Loeligerb7ced082006-10-10 17:03:43 -0500676 switch (speed) {
677 case MIIM_88E1011_PHYSTAT_GBIT:
678 priv->speed = 1000;
679 break;
680 case MIIM_88E1011_PHYSTAT_100:
681 priv->speed = 100;
682 break;
683 default:
684 priv->speed = 10;
wdenk9c53f402003-10-15 23:53:47 +0000685 }
686
wdenka445ddf2004-06-09 00:34:46 +0000687 return 0;
688}
689
Dave Liua304a282008-01-11 18:45:28 +0800690/* Parse the RTL8211B's status register for speed and duplex
691 * information
692 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600693static uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
Dave Liua304a282008-01-11 18:45:28 +0800694{
695 uint speed;
696
697 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300698 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liua304a282008-01-11 18:45:28 +0800699 int i = 0;
700
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300701 /* in case of timeout ->link is cleared */
702 priv->link = 1;
Dave Liua304a282008-01-11 18:45:28 +0800703 puts("Waiting for PHY realtime link");
704 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
705 /* Timeout reached ? */
706 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
707 puts(" TIMEOUT !\n");
708 priv->link = 0;
709 break;
710 }
711
712 if ((i++ % 1000) == 0) {
713 putc('.');
714 }
715 udelay(1000); /* 1 ms */
716 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
717 }
718 puts(" done\n");
719 udelay(500000); /* another 500 ms (results in faster booting) */
720 } else {
721 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
722 priv->link = 1;
723 else
724 priv->link = 0;
725 }
726
727 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
728 priv->duplexity = 1;
729 else
730 priv->duplexity = 0;
731
732 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
733
734 switch (speed) {
735 case MIIM_RTL8211B_PHYSTAT_GBIT:
736 priv->speed = 1000;
737 break;
738 case MIIM_RTL8211B_PHYSTAT_100:
739 priv->speed = 100;
740 break;
741 default:
742 priv->speed = 10;
743 }
744
745 return 0;
746}
747
wdenka445ddf2004-06-09 00:34:46 +0000748/* Parse the cis8201's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500749 * information
750 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600751static uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000752{
753 uint speed;
754
Jon Loeligerb7ced082006-10-10 17:03:43 -0500755 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000756 priv->duplexity = 1;
757 else
758 priv->duplexity = 0;
759
760 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500761 switch (speed) {
762 case MIIM_CIS8201_AUXCONSTAT_GBIT:
763 priv->speed = 1000;
764 break;
765 case MIIM_CIS8201_AUXCONSTAT_100:
766 priv->speed = 100;
767 break;
768 default:
769 priv->speed = 10;
770 break;
wdenk9c53f402003-10-15 23:53:47 +0000771 }
772
wdenka445ddf2004-06-09 00:34:46 +0000773 return 0;
774}
Jon Loeligerb7ced082006-10-10 17:03:43 -0500775
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500776/* Parse the vsc8244's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500777 * information
778 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600779static uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500780{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500781 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000782
Jon Loeligerb7ced082006-10-10 17:03:43 -0500783 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
784 priv->duplexity = 1;
785 else
786 priv->duplexity = 0;
787
788 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
789 switch (speed) {
790 case MIIM_VSC8244_AUXCONSTAT_GBIT:
791 priv->speed = 1000;
792 break;
793 case MIIM_VSC8244_AUXCONSTAT_100:
794 priv->speed = 100;
795 break;
796 default:
797 priv->speed = 10;
798 break;
799 }
800
801 return 0;
802}
wdenka445ddf2004-06-09 00:34:46 +0000803
804/* Parse the DM9161's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500805 * information
806 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600807static uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000808{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500809 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenka445ddf2004-06-09 00:34:46 +0000810 priv->speed = 100;
811 else
812 priv->speed = 10;
813
Jon Loeligerb7ced082006-10-10 17:03:43 -0500814 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenka445ddf2004-06-09 00:34:46 +0000815 priv->duplexity = 1;
816 else
817 priv->duplexity = 0;
818
819 return 0;
820}
821
Jon Loeligerb7ced082006-10-10 17:03:43 -0500822/*
823 * Hack to write all 4 PHYs with the LED values
824 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600825static uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000826{
827 uint phyid;
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530828 volatile tsec_mdio_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500829 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000830
Jon Loeligerb7ced082006-10-10 17:03:43 -0500831 for (phyid = 0; phyid < 4; phyid++) {
wdenka445ddf2004-06-09 00:34:46 +0000832 regbase->miimadd = (phyid << 8) | mii_reg;
833 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500834 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000835
Jon Loeligerb7ced082006-10-10 17:03:43 -0500836 timeout = 1000000;
837 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000838 }
wdenk9c53f402003-10-15 23:53:47 +0000839
wdenka445ddf2004-06-09 00:34:46 +0000840 return MIIM_CIS8204_SLEDCON_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000841}
842
Peter Tyser08b2d782009-11-09 13:09:45 -0600843static uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500844{
845 if (priv->flags & TSEC_REDUCED)
846 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
847 else
848 return MIIM_CIS8204_EPHYCON_INIT;
849}
wdenk9c53f402003-10-15 23:53:47 +0000850
Peter Tyser08b2d782009-11-09 13:09:45 -0600851static uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
Dave Liub19ecd32007-09-18 12:37:57 +0800852{
853 uint mii_data = read_phy_reg(priv, mii_reg);
854
855 if (priv->flags & TSEC_REDUCED)
856 mii_data = (mii_data & 0xfff0) | 0x000b;
857 return mii_data;
858}
859
wdenka445ddf2004-06-09 00:34:46 +0000860/* Initialized required registers to appropriate values, zeroing
861 * those we don't care about (unless zero is bad, in which case,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500862 * choose a more appropriate value)
863 */
864static void init_registers(volatile tsec_t * regs)
wdenk9c53f402003-10-15 23:53:47 +0000865{
866 /* Clear IEVENT */
867 regs->ievent = IEVENT_INIT_CLEAR;
868
869 regs->imask = IMASK_INIT_CLEAR;
870
871 regs->hash.iaddr0 = 0;
872 regs->hash.iaddr1 = 0;
873 regs->hash.iaddr2 = 0;
874 regs->hash.iaddr3 = 0;
875 regs->hash.iaddr4 = 0;
876 regs->hash.iaddr5 = 0;
877 regs->hash.iaddr6 = 0;
878 regs->hash.iaddr7 = 0;
879
880 regs->hash.gaddr0 = 0;
881 regs->hash.gaddr1 = 0;
882 regs->hash.gaddr2 = 0;
883 regs->hash.gaddr3 = 0;
884 regs->hash.gaddr4 = 0;
885 regs->hash.gaddr5 = 0;
886 regs->hash.gaddr6 = 0;
887 regs->hash.gaddr7 = 0;
888
889 regs->rctrl = 0x00000000;
890
891 /* Init RMON mib registers */
892 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
893
894 regs->rmon.cam1 = 0xffffffff;
895 regs->rmon.cam2 = 0xffffffff;
896
897 regs->mrblr = MRBLR_INIT_SETTINGS;
898
899 regs->minflr = MINFLR_INIT_SETTINGS;
900
901 regs->attr = ATTR_INIT_SETTINGS;
902 regs->attreli = ATTRELI_INIT_SETTINGS;
903
wdenka445ddf2004-06-09 00:34:46 +0000904}
905
wdenka445ddf2004-06-09 00:34:46 +0000906/* Configure maccfg2 based on negotiated speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500907 * reported by PHY handling code
908 */
wdenka445ddf2004-06-09 00:34:46 +0000909static void adjust_link(struct eth_device *dev)
910{
911 struct tsec_private *priv = (struct tsec_private *)dev->priv;
912 volatile tsec_t *regs = priv->regs;
913
Jon Loeligerb7ced082006-10-10 17:03:43 -0500914 if (priv->link) {
915 if (priv->duplexity != 0)
wdenka445ddf2004-06-09 00:34:46 +0000916 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
917 else
918 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
919
Jon Loeligerb7ced082006-10-10 17:03:43 -0500920 switch (priv->speed) {
921 case 1000:
922 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
923 | MACCFG2_GMII);
924 break;
925 case 100:
926 case 10:
927 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
928 | MACCFG2_MII);
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500929
Nick Spenceec9670b2006-09-07 07:39:46 -0700930 /* Set R100 bit in all modes although
931 * it is only used in RGMII mode
Jon Loeligerb7ced082006-10-10 17:03:43 -0500932 */
Nick Spenceec9670b2006-09-07 07:39:46 -0700933 if (priv->speed == 100)
Jon Loeligerb7ced082006-10-10 17:03:43 -0500934 regs->ecntrl |= ECNTRL_R100;
935 else
936 regs->ecntrl &= ~(ECNTRL_R100);
937 break;
938 default:
939 printf("%s: Speed was bad\n", dev->name);
940 break;
wdenka445ddf2004-06-09 00:34:46 +0000941 }
942
943 printf("Speed: %d, %s duplex\n", priv->speed,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500944 (priv->duplexity) ? "full" : "half");
wdenka445ddf2004-06-09 00:34:46 +0000945
946 } else {
947 printf("%s: No link.\n", dev->name);
948 }
wdenk9c53f402003-10-15 23:53:47 +0000949}
950
wdenka445ddf2004-06-09 00:34:46 +0000951/* Set up the buffers and their descriptors, and bring up the
Jon Loeligerb7ced082006-10-10 17:03:43 -0500952 * interface
953 */
wdenka445ddf2004-06-09 00:34:46 +0000954static void startup_tsec(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000955{
956 int i;
wdenka445ddf2004-06-09 00:34:46 +0000957 struct tsec_private *priv = (struct tsec_private *)dev->priv;
958 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000959
960 /* Point to the buffer descriptors */
961 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
962 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
963
964 /* Initialize the Rx Buffer descriptors */
965 for (i = 0; i < PKTBUFSRX; i++) {
966 rtx.rxbd[i].status = RXBD_EMPTY;
967 rtx.rxbd[i].length = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500968 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
wdenk9c53f402003-10-15 23:53:47 +0000969 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500970 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000971
972 /* Initialize the TX Buffer Descriptors */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500973 for (i = 0; i < TX_BUF_CNT; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000974 rtx.txbd[i].status = 0;
975 rtx.txbd[i].length = 0;
976 rtx.txbd[i].bufPtr = 0;
977 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500978 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000979
wdenka445ddf2004-06-09 00:34:46 +0000980 /* Start up the PHY */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400981 if(priv->phyinfo)
982 phy_run_commands(priv, priv->phyinfo->startup);
David Updegraff0451b012007-04-20 14:34:48 -0500983
wdenka445ddf2004-06-09 00:34:46 +0000984 adjust_link(dev);
985
wdenk9c53f402003-10-15 23:53:47 +0000986 /* Enable Transmit and Receive */
987 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
988
989 /* Tell the DMA it is clear to go */
990 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
991 regs->tstat = TSTAT_CLEAR_THALT;
Dan Wilsone3d7d6b2007-10-19 11:33:48 -0500992 regs->rstat = RSTAT_CLEAR_RHALT;
wdenk9c53f402003-10-15 23:53:47 +0000993 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
994}
995
wdenkbfad55d2005-03-14 23:56:42 +0000996/* This returns the status bits of the device. The return value
wdenk9c53f402003-10-15 23:53:47 +0000997 * is never checked, and this is what the 8260 driver did, so we
wdenkbfad55d2005-03-14 23:56:42 +0000998 * do the same. Presumably, this would be zero if there were no
Jon Loeligerb7ced082006-10-10 17:03:43 -0500999 * errors
1000 */
1001static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
wdenk9c53f402003-10-15 23:53:47 +00001002{
1003 int i;
1004 int result = 0;
wdenka445ddf2004-06-09 00:34:46 +00001005 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1006 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +00001007
1008 /* Find an empty buffer descriptor */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001009 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +00001010 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001011 debug("%s: tsec: tx buffers full\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +00001012 return result;
1013 }
1014 }
1015
Jon Loeligerb7ced082006-10-10 17:03:43 -05001016 rtx.txbd[txIdx].bufPtr = (uint) packet;
wdenk9c53f402003-10-15 23:53:47 +00001017 rtx.txbd[txIdx].length = length;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001018 rtx.txbd[txIdx].status |=
1019 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
wdenk9c53f402003-10-15 23:53:47 +00001020
1021 /* Tell the DMA to go */
1022 regs->tstat = TSTAT_CLEAR_THALT;
1023
1024 /* Wait for buffer to be transmitted */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001025 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +00001026 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001027 debug("%s: tsec: tx error\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +00001028 return result;
1029 }
1030 }
1031
1032 txIdx = (txIdx + 1) % TX_BUF_CNT;
1033 result = rtx.txbd[txIdx].status & TXBD_STATS;
1034
1035 return result;
1036}
1037
Jon Loeligerb7ced082006-10-10 17:03:43 -05001038static int tsec_recv(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +00001039{
1040 int length;
wdenka445ddf2004-06-09 00:34:46 +00001041 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1042 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +00001043
Jon Loeligerb7ced082006-10-10 17:03:43 -05001044 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenk9c53f402003-10-15 23:53:47 +00001045
1046 length = rtx.rxbd[rxIdx].length;
1047
1048 /* Send the packet up if there were no errors */
1049 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
1050 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenka445ddf2004-06-09 00:34:46 +00001051 } else {
1052 printf("Got error %x\n",
Jon Loeligerb7ced082006-10-10 17:03:43 -05001053 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk9c53f402003-10-15 23:53:47 +00001054 }
1055
1056 rtx.rxbd[rxIdx].length = 0;
1057
1058 /* Set the wrap bit if this is the last element in the list */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001059 rtx.rxbd[rxIdx].status =
1060 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
wdenk9c53f402003-10-15 23:53:47 +00001061
1062 rxIdx = (rxIdx + 1) % PKTBUFSRX;
1063 }
1064
Jon Loeligerb7ced082006-10-10 17:03:43 -05001065 if (regs->ievent & IEVENT_BSY) {
wdenk9c53f402003-10-15 23:53:47 +00001066 regs->ievent = IEVENT_BSY;
1067 regs->rstat = RSTAT_CLEAR_RHALT;
1068 }
1069
1070 return -1;
1071
1072}
1073
wdenka445ddf2004-06-09 00:34:46 +00001074/* Stop the interface */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001075static void tsec_halt(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +00001076{
wdenka445ddf2004-06-09 00:34:46 +00001077 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1078 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +00001079
1080 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
1081 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
1082
Jon Loeligerb7ced082006-10-10 17:03:43 -05001083 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
wdenk9c53f402003-10-15 23:53:47 +00001084
1085 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
1086
wdenka445ddf2004-06-09 00:34:46 +00001087 /* Shut down the PHY, as needed */
Ben Warrenf11eefb2006-10-26 14:38:25 -04001088 if(priv->phyinfo)
1089 phy_run_commands(priv, priv->phyinfo->shutdown);
wdenka445ddf2004-06-09 00:34:46 +00001090}
1091
Peter Tyser08b2d782009-11-09 13:09:45 -06001092static struct phy_info phy_info_M88E1149S = {
Wolfgang Denk15e87572007-08-06 01:01:49 +02001093 0x1410ca,
1094 "Marvell 88E1149S",
1095 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001096 (struct phy_cmd[]) { /* config */
Wolfgang Denk15e87572007-08-06 01:01:49 +02001097 /* Reset and configure the PHY */
1098 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1099 {0x1d, 0x1f, NULL},
1100 {0x1e, 0x200c, NULL},
1101 {0x1d, 0x5, NULL},
1102 {0x1e, 0x0, NULL},
1103 {0x1e, 0x100, NULL},
1104 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1105 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1106 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1107 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1108 {miim_end,}
1109 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001110 (struct phy_cmd[]) { /* startup */
Wolfgang Denk15e87572007-08-06 01:01:49 +02001111 /* Status is read once to clear old link state */
1112 {MIIM_STATUS, miim_read, NULL},
1113 /* Auto-negotiate */
1114 {MIIM_STATUS, miim_read, &mii_parse_sr},
1115 /* Read the status */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001116 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
Wolfgang Denk15e87572007-08-06 01:01:49 +02001117 {miim_end,}
1118 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001119 (struct phy_cmd[]) { /* shutdown */
Wolfgang Denk15e87572007-08-06 01:01:49 +02001120 {miim_end,}
1121 },
Andy Flemingbee67002007-08-03 04:05:25 -05001122};
1123
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001124/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001125static struct phy_info phy_info_BCM5461S = {
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001126 0x02060c1, /* 5461 ID */
1127 "Broadcom BCM5461S",
1128 0, /* not clear to me what minor revisions we can shift away */
1129 (struct phy_cmd[]) { /* config */
1130 /* Reset and configure the PHY */
1131 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1132 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1133 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1134 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1135 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1136 {miim_end,}
1137 },
1138 (struct phy_cmd[]) { /* startup */
1139 /* Status is read once to clear old link state */
1140 {MIIM_STATUS, miim_read, NULL},
1141 /* Auto-negotiate */
1142 {MIIM_STATUS, miim_read, &mii_parse_sr},
1143 /* Read the status */
1144 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1145 {miim_end,}
1146 },
1147 (struct phy_cmd[]) { /* shutdown */
1148 {miim_end,}
1149 },
1150};
1151
Peter Tyser08b2d782009-11-09 13:09:45 -06001152static struct phy_info phy_info_BCM5464S = {
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001153 0x02060b1, /* 5464 ID */
1154 "Broadcom BCM5464S",
1155 0, /* not clear to me what minor revisions we can shift away */
1156 (struct phy_cmd[]) { /* config */
1157 /* Reset and configure the PHY */
1158 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1159 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1160 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1161 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001162 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1163 {miim_end,}
1164 },
1165 (struct phy_cmd[]) { /* startup */
1166 /* Status is read once to clear old link state */
1167 {MIIM_STATUS, miim_read, NULL},
1168 /* Auto-negotiate */
1169 {MIIM_STATUS, miim_read, &mii_parse_sr},
1170 /* Read the status */
1171 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1172 {miim_end,}
1173 },
1174 (struct phy_cmd[]) { /* shutdown */
1175 {miim_end,}
1176 },
1177};
1178
Peter Tyser08b2d782009-11-09 13:09:45 -06001179static struct phy_info phy_info_BCM5482S = {
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001180 0x0143bcb,
1181 "Broadcom BCM5482S",
1182 4,
1183 (struct phy_cmd[]) { /* config */
1184 /* Reset and configure the PHY */
1185 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1186 /* Setup read from auxilary control shadow register 7 */
1187 {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
1188 /* Read Misc Control register and or in Ethernet@Wirespeed */
1189 {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001190 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Peter Tyser3c93d8b2009-11-09 13:09:47 -06001191 /* Initial config/enable of secondary SerDes interface */
1192 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf), NULL},
1193 /* Write intial value to secondary SerDes Contol */
1194 {MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_SSD | 0, NULL},
1195 {MIIM_BCM54XX_EXP_DATA, MIIM_CONTROL_RESTART, NULL},
1196 /* Enable copper/fiber auto-detect */
1197 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201)},
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001198 {miim_end,}
1199 },
1200 (struct phy_cmd[]) { /* startup */
1201 /* Status is read once to clear old link state */
1202 {MIIM_STATUS, miim_read, NULL},
Peter Tyser3c93d8b2009-11-09 13:09:47 -06001203 /* Determine copper/fiber, auto-negotiate, and read the result */
1204 {MIIM_STATUS, miim_read, &mii_parse_BCM5482_sr},
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001205 {miim_end,}
1206 },
1207 (struct phy_cmd[]) { /* shutdown */
1208 {miim_end,}
1209 },
1210};
1211
Peter Tyser08b2d782009-11-09 13:09:45 -06001212static struct phy_info phy_info_M88E1011S = {
wdenka445ddf2004-06-09 00:34:46 +00001213 0x01410c6,
1214 "Marvell 88E1011S",
1215 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001216 (struct phy_cmd[]) { /* config */
1217 /* Reset and configure the PHY */
1218 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1219 {0x1d, 0x1f, NULL},
1220 {0x1e, 0x200c, NULL},
1221 {0x1d, 0x5, NULL},
1222 {0x1e, 0x0, NULL},
1223 {0x1e, 0x100, NULL},
1224 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1225 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1226 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1227 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1228 {miim_end,}
1229 },
1230 (struct phy_cmd[]) { /* startup */
1231 /* Status is read once to clear old link state */
1232 {MIIM_STATUS, miim_read, NULL},
1233 /* Auto-negotiate */
1234 {MIIM_STATUS, miim_read, &mii_parse_sr},
1235 /* Read the status */
1236 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1237 {miim_end,}
1238 },
1239 (struct phy_cmd[]) { /* shutdown */
1240 {miim_end,}
1241 },
wdenka445ddf2004-06-09 00:34:46 +00001242};
1243
Peter Tyser08b2d782009-11-09 13:09:45 -06001244static struct phy_info phy_info_M88E1111S = {
wdenkbfad55d2005-03-14 23:56:42 +00001245 0x01410cc,
1246 "Marvell 88E1111S",
1247 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001248 (struct phy_cmd[]) { /* config */
1249 /* Reset and configure the PHY */
1250 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1251 {0x1b, 0x848f, &mii_m88e1111s_setmode},
1252 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
1253 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1254 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1255 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1256 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1257 {miim_end,}
1258 },
1259 (struct phy_cmd[]) { /* startup */
1260 /* Status is read once to clear old link state */
1261 {MIIM_STATUS, miim_read, NULL},
1262 /* Auto-negotiate */
1263 {MIIM_STATUS, miim_read, &mii_parse_sr},
1264 /* Read the status */
1265 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1266 {miim_end,}
1267 },
1268 (struct phy_cmd[]) { /* shutdown */
1269 {miim_end,}
1270 },
wdenkbfad55d2005-03-14 23:56:42 +00001271};
1272
Peter Tyser08b2d782009-11-09 13:09:45 -06001273static struct phy_info phy_info_M88E1118 = {
Ron Madridc1e2b582008-05-23 15:37:05 -07001274 0x01410e1,
1275 "Marvell 88E1118",
1276 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001277 (struct phy_cmd[]) { /* config */
Ron Madridc1e2b582008-05-23 15:37:05 -07001278 /* Reset and configure the PHY */
1279 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1280 {0x16, 0x0002, NULL}, /* Change Page Number */
1281 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
Ron Madridaa4aac42009-01-28 16:17:21 -08001282 {0x16, 0x0003, NULL}, /* Change Page Number */
1283 {0x10, 0x021e, NULL}, /* Adjust LED control */
1284 {0x16, 0x0000, NULL}, /* Change Page Number */
Ron Madridc1e2b582008-05-23 15:37:05 -07001285 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1286 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1287 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1288 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1289 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -06001290 },
1291 (struct phy_cmd[]) { /* startup */
Ron Madridc1e2b582008-05-23 15:37:05 -07001292 {0x16, 0x0000, NULL}, /* Change Page Number */
1293 /* Status is read once to clear old link state */
1294 {MIIM_STATUS, miim_read, NULL},
1295 /* Auto-negotiate */
Ron Madridaa4aac42009-01-28 16:17:21 -08001296 {MIIM_STATUS, miim_read, &mii_parse_sr},
Ron Madridc1e2b582008-05-23 15:37:05 -07001297 /* Read the status */
1298 {MIIM_88E1011_PHY_STATUS, miim_read,
1299 &mii_parse_88E1011_psr},
1300 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -06001301 },
1302 (struct phy_cmd[]) { /* shutdown */
Ron Madridc1e2b582008-05-23 15:37:05 -07001303 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -06001304 },
Ron Madridc1e2b582008-05-23 15:37:05 -07001305};
1306
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001307/*
1308 * Since to access LED register we need do switch the page, we
1309 * do LED configuring in the miim_read-like function as follows
1310 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001311static uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001312{
1313 uint pg;
1314
1315 /* Switch the page to access the led register */
1316 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1317 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1318
1319 /* Configure leds */
1320 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1321 MIIM_88E1121_PHY_LED_DEF);
1322
1323 /* Restore the page pointer */
1324 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1325 return 0;
1326}
1327
Peter Tyser08b2d782009-11-09 13:09:45 -06001328static struct phy_info phy_info_M88E1121R = {
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001329 0x01410cb,
1330 "Marvell 88E1121R",
1331 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001332 (struct phy_cmd[]) { /* config */
1333 /* Reset and configure the PHY */
1334 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1335 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1336 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1337 /* Configure leds */
1338 {MIIM_88E1121_PHY_LED_CTRL, miim_read, &mii_88E1121_set_led},
1339 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1340 /* Disable IRQs and de-assert interrupt */
1341 {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
1342 {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
1343 {miim_end,}
1344 },
1345 (struct phy_cmd[]) { /* startup */
1346 /* Status is read once to clear old link state */
1347 {MIIM_STATUS, miim_read, NULL},
1348 {MIIM_STATUS, miim_read, &mii_parse_sr},
1349 {MIIM_STATUS, miim_read, &mii_parse_link},
1350 {miim_end,}
1351 },
1352 (struct phy_cmd[]) { /* shutdown */
1353 {miim_end,}
1354 },
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001355};
1356
Andy Fleming239e75f2006-09-13 10:34:18 -05001357static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1358{
Andy Fleming239e75f2006-09-13 10:34:18 -05001359 uint mii_data = read_phy_reg(priv, mii_reg);
1360
Andy Fleming239e75f2006-09-13 10:34:18 -05001361 /* Setting MIIM_88E1145_PHY_EXT_CR */
1362 if (priv->flags & TSEC_REDUCED)
1363 return mii_data |
Jon Loeligerb7ced082006-10-10 17:03:43 -05001364 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming239e75f2006-09-13 10:34:18 -05001365 else
1366 return mii_data;
1367}
1368
1369static struct phy_info phy_info_M88E1145 = {
1370 0x01410cd,
1371 "Marvell 88E1145",
1372 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001373 (struct phy_cmd[]) { /* config */
1374 /* Reset the PHY */
1375 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Andy Fleming180d03a2007-05-08 17:23:02 -05001376
Peter Tyser4ef03c02009-11-09 13:09:46 -06001377 /* Errata E0, E1 */
1378 {29, 0x001b, NULL},
1379 {30, 0x418f, NULL},
1380 {29, 0x0016, NULL},
1381 {30, 0xa2da, NULL},
Andy Fleming239e75f2006-09-13 10:34:18 -05001382
Peter Tyser4ef03c02009-11-09 13:09:46 -06001383 /* Configure the PHY */
1384 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1385 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1386 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, NULL},
1387 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1388 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1389 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1390 {miim_end,}
1391 },
1392 (struct phy_cmd[]) { /* startup */
1393 /* Status is read once to clear old link state */
1394 {MIIM_STATUS, miim_read, NULL},
1395 /* Auto-negotiate */
1396 {MIIM_STATUS, miim_read, &mii_parse_sr},
1397 {MIIM_88E1111_PHY_LED_CONTROL, MIIM_88E1111_PHY_LED_DIRECT, NULL},
1398 /* Read the Status */
1399 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1400 {miim_end,}
1401 },
1402 (struct phy_cmd[]) { /* shutdown */
1403 {miim_end,}
1404 },
Andy Fleming239e75f2006-09-13 10:34:18 -05001405};
1406
Peter Tyser08b2d782009-11-09 13:09:45 -06001407static struct phy_info phy_info_cis8204 = {
wdenka445ddf2004-06-09 00:34:46 +00001408 0x3f11,
1409 "Cicada Cis8204",
1410 6,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001411 (struct phy_cmd[]) { /* config */
1412 /* Override PHY config settings */
1413 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1414 /* Configure some basic stuff */
1415 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1416 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1417 &mii_cis8204_fixled},
1418 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1419 &mii_cis8204_setmode},
1420 {miim_end,}
1421 },
1422 (struct phy_cmd[]) { /* startup */
1423 /* Read the Status (2x to make sure link is right) */
1424 {MIIM_STATUS, miim_read, NULL},
1425 /* Auto-negotiate */
1426 {MIIM_STATUS, miim_read, &mii_parse_sr},
1427 /* Read the status */
1428 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1429 {miim_end,}
1430 },
1431 (struct phy_cmd[]) { /* shutdown */
1432 {miim_end,}
1433 },
wdenka445ddf2004-06-09 00:34:46 +00001434};
1435
1436/* Cicada 8201 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001437static struct phy_info phy_info_cis8201 = {
wdenka445ddf2004-06-09 00:34:46 +00001438 0xfc41,
1439 "CIS8201",
1440 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001441 (struct phy_cmd[]) { /* config */
1442 /* Override PHY config settings */
1443 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1444 /* Set up the interface mode */
1445 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1446 /* Configure some basic stuff */
1447 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1448 {miim_end,}
1449 },
1450 (struct phy_cmd[]) { /* startup */
1451 /* Read the Status (2x to make sure link is right) */
1452 {MIIM_STATUS, miim_read, NULL},
1453 /* Auto-negotiate */
1454 {MIIM_STATUS, miim_read, &mii_parse_sr},
1455 /* Read the status */
1456 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1457 {miim_end,}
1458 },
1459 (struct phy_cmd[]) { /* shutdown */
1460 {miim_end,}
1461 },
wdenka445ddf2004-06-09 00:34:46 +00001462};
Peter Tyser08b2d782009-11-09 13:09:45 -06001463
1464static struct phy_info phy_info_VSC8211 = {
Pieter Henning9370c8b2009-02-22 23:17:15 -08001465 0xfc4b,
1466 "Vitesse VSC8211",
1467 4,
1468 (struct phy_cmd[]) { /* config */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001469 /* Override PHY config settings */
1470 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1471 /* Set up the interface mode */
1472 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1473 /* Configure some basic stuff */
1474 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1475 {miim_end,}
1476 },
Pieter Henning9370c8b2009-02-22 23:17:15 -08001477 (struct phy_cmd[]) { /* startup */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001478 /* Read the Status (2x to make sure link is right) */
1479 {MIIM_STATUS, miim_read, NULL},
1480 /* Auto-negotiate */
1481 {MIIM_STATUS, miim_read, &mii_parse_sr},
1482 /* Read the status */
1483 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1484 {miim_end,}
1485 },
Pieter Henning9370c8b2009-02-22 23:17:15 -08001486 (struct phy_cmd[]) { /* shutdown */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001487 {miim_end,}
Pieter Henning9370c8b2009-02-22 23:17:15 -08001488 },
1489};
Peter Tyser08b2d782009-11-09 13:09:45 -06001490
1491static struct phy_info phy_info_VSC8244 = {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001492 0x3f1b,
1493 "Vitesse VSC8244",
1494 6,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001495 (struct phy_cmd[]) { /* config */
1496 /* Override PHY config settings */
1497 /* Configure some basic stuff */
1498 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1499 {miim_end,}
1500 },
1501 (struct phy_cmd[]) { /* startup */
1502 /* Read the Status (2x to make sure link is right) */
1503 {MIIM_STATUS, miim_read, NULL},
1504 /* Auto-negotiate */
1505 {MIIM_STATUS, miim_read, &mii_parse_sr},
1506 /* Read the status */
1507 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1508 {miim_end,}
1509 },
1510 (struct phy_cmd[]) { /* shutdown */
1511 {miim_end,}
1512 },
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001513};
wdenka445ddf2004-06-09 00:34:46 +00001514
Peter Tyser08b2d782009-11-09 13:09:45 -06001515static struct phy_info phy_info_VSC8641 = {
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301516 0x7043,
1517 "Vitesse VSC8641",
1518 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001519 (struct phy_cmd[]) { /* config */
1520 /* Configure some basic stuff */
1521 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1522 {miim_end,}
1523 },
1524 (struct phy_cmd[]) { /* startup */
1525 /* Read the Status (2x to make sure link is right) */
1526 {MIIM_STATUS, miim_read, NULL},
1527 /* Auto-negotiate */
1528 {MIIM_STATUS, miim_read, &mii_parse_sr},
1529 /* Read the status */
1530 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1531 {miim_end,}
1532 },
1533 (struct phy_cmd[]) { /* shutdown */
1534 {miim_end,}
1535 },
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301536};
1537
Peter Tyser08b2d782009-11-09 13:09:45 -06001538static struct phy_info phy_info_VSC8221 = {
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301539 0xfc55,
1540 "Vitesse VSC8221",
1541 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001542 (struct phy_cmd[]) { /* config */
1543 /* Configure some basic stuff */
1544 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1545 {miim_end,}
1546 },
1547 (struct phy_cmd[]) { /* startup */
1548 /* Read the Status (2x to make sure link is right) */
1549 {MIIM_STATUS, miim_read, NULL},
1550 /* Auto-negotiate */
1551 {MIIM_STATUS, miim_read, &mii_parse_sr},
1552 /* Read the status */
1553 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1554 {miim_end,}
1555 },
1556 (struct phy_cmd[]) { /* shutdown */
1557 {miim_end,}
1558 },
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301559};
1560
Peter Tyser08b2d782009-11-09 13:09:45 -06001561static struct phy_info phy_info_VSC8601 = {
Peter Tyser4ef03c02009-11-09 13:09:46 -06001562 0x00007042,
1563 "Vitesse VSC8601",
1564 4,
1565 (struct phy_cmd[]) { /* config */
1566 /* Override PHY config settings */
1567 /* Configure some basic stuff */
1568 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001569#ifdef CONFIG_SYS_VSC8601_SKEWFIX
Peter Tyser4ef03c02009-11-09 13:09:46 -06001570 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001571#if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
Peter Tyser4ef03c02009-11-09 13:09:46 -06001572 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1573#define VSC8101_SKEW \
1574 (CONFIG_SYS_VSC8601_SKEW_TX << 14) | (CONFIG_SYS_VSC8601_SKEW_RX << 12)
1575 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1576 {MIIM_EXT_PAGE_ACCESS,0,NULL},
Andre Schwarz1e18be12008-04-29 19:18:32 +02001577#endif
Tor Krill8b3a82f2008-03-28 15:29:45 +01001578#endif
Peter Tyser4ef03c02009-11-09 13:09:46 -06001579 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1580 {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
1581 {miim_end,}
1582 },
1583 (struct phy_cmd[]) { /* startup */
1584 /* Read the Status (2x to make sure link is right) */
1585 {MIIM_STATUS, miim_read, NULL},
1586 /* Auto-negotiate */
1587 {MIIM_STATUS, miim_read, &mii_parse_sr},
1588 /* Read the status */
1589 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1590 {miim_end,}
1591 },
1592 (struct phy_cmd[]) { /* shutdown */
1593 {miim_end,}
1594 },
Tor Krill8b3a82f2008-03-28 15:29:45 +01001595};
1596
Peter Tyser08b2d782009-11-09 13:09:45 -06001597static struct phy_info phy_info_dm9161 = {
wdenka445ddf2004-06-09 00:34:46 +00001598 0x0181b88,
1599 "Davicom DM9161E",
1600 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001601 (struct phy_cmd[]) { /* config */
1602 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1603 /* Do not bypass the scrambler/descrambler */
1604 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1605 /* Clear 10BTCSR to default */
1606 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
1607 /* Configure some basic stuff */
1608 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1609 /* Restart Auto Negotiation */
1610 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1611 {miim_end,}
1612 },
1613 (struct phy_cmd[]) { /* startup */
1614 /* Status is read once to clear old link state */
1615 {MIIM_STATUS, miim_read, NULL},
1616 /* Auto-negotiate */
1617 {MIIM_STATUS, miim_read, &mii_parse_sr},
1618 /* Read the status */
1619 {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
1620 {miim_end,}
1621 },
1622 (struct phy_cmd[]) { /* shutdown */
1623 {miim_end,}
1624 },
wdenka445ddf2004-06-09 00:34:46 +00001625};
Peter Tyser4ef03c02009-11-09 13:09:46 -06001626
David Updegraff0451b012007-04-20 14:34:48 -05001627/* a generic flavor. */
Peter Tyser08b2d782009-11-09 13:09:45 -06001628static struct phy_info phy_info_generic = {
David Updegraff0451b012007-04-20 14:34:48 -05001629 0,
1630 "Unknown/Generic PHY",
1631 32,
1632 (struct phy_cmd[]) { /* config */
1633 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1634 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1635 {miim_end,}
1636 },
1637 (struct phy_cmd[]) { /* startup */
1638 {PHY_BMSR, miim_read, NULL},
1639 {PHY_BMSR, miim_read, &mii_parse_sr},
1640 {PHY_BMSR, miim_read, &mii_parse_link},
1641 {miim_end,}
1642 },
1643 (struct phy_cmd[]) { /* shutdown */
1644 {miim_end,}
1645 }
1646};
1647
Peter Tyser08b2d782009-11-09 13:09:45 -06001648static uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
wdenkf41ff3b2005-04-04 23:43:44 +00001649{
wdenke085e5b2005-04-05 23:32:21 +00001650 unsigned int speed;
1651 if (priv->link) {
1652 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenkf41ff3b2005-04-04 23:43:44 +00001653
wdenke085e5b2005-04-05 23:32:21 +00001654 switch (speed) {
1655 case MIIM_LXT971_SR2_10HDX:
1656 priv->speed = 10;
1657 priv->duplexity = 0;
1658 break;
1659 case MIIM_LXT971_SR2_10FDX:
1660 priv->speed = 10;
1661 priv->duplexity = 1;
1662 break;
1663 case MIIM_LXT971_SR2_100HDX:
1664 priv->speed = 100;
1665 priv->duplexity = 0;
urwithsughosh@gmail.com34b3f2e2007-09-10 14:54:56 -04001666 break;
wdenke085e5b2005-04-05 23:32:21 +00001667 default:
1668 priv->speed = 100;
1669 priv->duplexity = 1;
wdenke085e5b2005-04-05 23:32:21 +00001670 }
1671 } else {
1672 priv->speed = 0;
1673 priv->duplexity = 0;
1674 }
wdenkf41ff3b2005-04-04 23:43:44 +00001675
wdenke085e5b2005-04-05 23:32:21 +00001676 return 0;
wdenkf41ff3b2005-04-04 23:43:44 +00001677}
1678
wdenkbfad55d2005-03-14 23:56:42 +00001679static struct phy_info phy_info_lxt971 = {
1680 0x0001378e,
1681 "LXT971",
1682 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001683 (struct phy_cmd[]) { /* config */
1684 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1685 {miim_end,}
1686 },
1687 (struct phy_cmd[]) { /* startup - enable interrupts */
1688 /* { 0x12, 0x00f2, NULL }, */
1689 {MIIM_STATUS, miim_read, NULL},
1690 {MIIM_STATUS, miim_read, &mii_parse_sr},
1691 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1692 {miim_end,}
1693 },
1694 (struct phy_cmd[]) { /* shutdown - disable interrupts */
1695 {miim_end,}
1696 },
wdenkbfad55d2005-03-14 23:56:42 +00001697};
1698
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001699/* Parse the DP83865's link and auto-neg status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -05001700 * information
1701 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001702static uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001703{
1704 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1705
1706 case MIIM_DP83865_SPD_1000:
1707 priv->speed = 1000;
1708 break;
1709
1710 case MIIM_DP83865_SPD_100:
1711 priv->speed = 100;
1712 break;
1713
1714 default:
1715 priv->speed = 10;
1716 break;
1717
1718 }
1719
1720 if (mii_reg & MIIM_DP83865_DPX_FULL)
1721 priv->duplexity = 1;
1722 else
1723 priv->duplexity = 0;
1724
1725 return 0;
1726}
1727
Peter Tyser08b2d782009-11-09 13:09:45 -06001728static struct phy_info phy_info_dp83865 = {
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001729 0x20005c7,
1730 "NatSemi DP83865",
1731 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001732 (struct phy_cmd[]) { /* config */
1733 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1734 {miim_end,}
1735 },
1736 (struct phy_cmd[]) { /* startup */
1737 /* Status is read once to clear old link state */
1738 {MIIM_STATUS, miim_read, NULL},
1739 /* Auto-negotiate */
1740 {MIIM_STATUS, miim_read, &mii_parse_sr},
1741 /* Read the link and auto-neg status */
1742 {MIIM_DP83865_LANR, miim_read, &mii_parse_dp83865_lanr},
1743 {miim_end,}
1744 },
1745 (struct phy_cmd[]) { /* shutdown */
1746 {miim_end,}
1747 },
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001748};
1749
Peter Tyser08b2d782009-11-09 13:09:45 -06001750static struct phy_info phy_info_rtl8211b = {
Dave Liua304a282008-01-11 18:45:28 +08001751 0x001cc91,
1752 "RealTek RTL8211B",
1753 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001754 (struct phy_cmd[]) { /* config */
Dave Liua304a282008-01-11 18:45:28 +08001755 /* Reset and configure the PHY */
1756 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1757 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1758 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1759 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1760 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1761 {miim_end,}
1762 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001763 (struct phy_cmd[]) { /* startup */
Dave Liua304a282008-01-11 18:45:28 +08001764 /* Status is read once to clear old link state */
1765 {MIIM_STATUS, miim_read, NULL},
1766 /* Auto-negotiate */
1767 {MIIM_STATUS, miim_read, &mii_parse_sr},
1768 /* Read the status */
1769 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1770 {miim_end,}
1771 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001772 (struct phy_cmd[]) { /* shutdown */
Dave Liua304a282008-01-11 18:45:28 +08001773 {miim_end,}
1774 },
1775};
1776
Peter Tyser08b2d782009-11-09 13:09:45 -06001777static struct phy_info *phy_info[] = {
wdenka445ddf2004-06-09 00:34:46 +00001778 &phy_info_cis8204,
Timur Tabi054838e2006-10-31 18:44:42 -06001779 &phy_info_cis8201,
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001780 &phy_info_BCM5461S,
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001781 &phy_info_BCM5464S,
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001782 &phy_info_BCM5482S,
wdenka445ddf2004-06-09 00:34:46 +00001783 &phy_info_M88E1011S,
wdenkbfad55d2005-03-14 23:56:42 +00001784 &phy_info_M88E1111S,
Ron Madridc1e2b582008-05-23 15:37:05 -07001785 &phy_info_M88E1118,
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001786 &phy_info_M88E1121R,
Andy Fleming239e75f2006-09-13 10:34:18 -05001787 &phy_info_M88E1145,
Wolfgang Denk15e87572007-08-06 01:01:49 +02001788 &phy_info_M88E1149S,
wdenka445ddf2004-06-09 00:34:46 +00001789 &phy_info_dm9161,
wdenkbfad55d2005-03-14 23:56:42 +00001790 &phy_info_lxt971,
Pieter Henning9370c8b2009-02-22 23:17:15 -08001791 &phy_info_VSC8211,
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001792 &phy_info_VSC8244,
Tor Krill8b3a82f2008-03-28 15:29:45 +01001793 &phy_info_VSC8601,
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301794 &phy_info_VSC8641,
1795 &phy_info_VSC8221,
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001796 &phy_info_dp83865,
Dave Liua304a282008-01-11 18:45:28 +08001797 &phy_info_rtl8211b,
Paul Gortmakerf81b8232009-03-09 18:07:53 -05001798 &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
wdenka445ddf2004-06-09 00:34:46 +00001799 NULL
1800};
1801
wdenka445ddf2004-06-09 00:34:46 +00001802/* Grab the identifier of the device's PHY, and search through
wdenkbfad55d2005-03-14 23:56:42 +00001803 * all of the known PHYs to see if one matches. If so, return
Jon Loeligerb7ced082006-10-10 17:03:43 -05001804 * it, if not, return NULL
1805 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001806static struct phy_info *get_phy_info(struct eth_device *dev)
wdenka445ddf2004-06-09 00:34:46 +00001807{
1808 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1809 uint phy_reg, phy_ID;
1810 int i;
1811 struct phy_info *theInfo = NULL;
1812
1813 /* Grab the bits from PHYIR1, and put them in the upper half */
1814 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1815 phy_ID = (phy_reg & 0xffff) << 16;
1816
1817 /* Grab the bits from PHYIR2, and put them in the lower half */
1818 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1819 phy_ID |= (phy_reg & 0xffff);
1820
1821 /* loop through all the known PHY types, and find one that */
1822 /* matches the ID we read from the PHY. */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001823 for (i = 0; phy_info[i]; i++) {
Andy Flemingb2d14f42007-05-09 00:54:20 -05001824 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
wdenka445ddf2004-06-09 00:34:46 +00001825 theInfo = phy_info[i];
Andy Flemingb2d14f42007-05-09 00:54:20 -05001826 break;
1827 }
wdenka445ddf2004-06-09 00:34:46 +00001828 }
1829
Paul Gortmakerf81b8232009-03-09 18:07:53 -05001830 if (theInfo == &phy_info_generic) {
Peter Tyser4ef03c02009-11-09 13:09:46 -06001831 printf("%s: No support for PHY id %x; assuming generic\n",
1832 dev->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001833 } else {
Stefan Roesec0dc34f2005-09-21 18:20:22 +02001834 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001835 }
1836
1837 return theInfo;
1838}
1839
wdenka445ddf2004-06-09 00:34:46 +00001840/* Execute the given series of commands on the given device's
Jon Loeligerb7ced082006-10-10 17:03:43 -05001841 * PHY, running functions as necessary
1842 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001843static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
wdenka445ddf2004-06-09 00:34:46 +00001844{
1845 int i;
1846 uint result;
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +05301847 volatile tsec_mdio_t *phyregs = priv->phyregs;
wdenka445ddf2004-06-09 00:34:46 +00001848
1849 phyregs->miimcfg = MIIMCFG_RESET;
1850
1851 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1852
Jon Loeligerb7ced082006-10-10 17:03:43 -05001853 while (phyregs->miimind & MIIMIND_BUSY) ;
wdenka445ddf2004-06-09 00:34:46 +00001854
Jon Loeligerb7ced082006-10-10 17:03:43 -05001855 for (i = 0; cmd->mii_reg != miim_end; i++) {
1856 if (cmd->mii_data == miim_read) {
wdenka445ddf2004-06-09 00:34:46 +00001857 result = read_phy_reg(priv, cmd->mii_reg);
1858
Jon Loeligerb7ced082006-10-10 17:03:43 -05001859 if (cmd->funct != NULL)
1860 (*(cmd->funct)) (result, priv);
wdenka445ddf2004-06-09 00:34:46 +00001861
1862 } else {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001863 if (cmd->funct != NULL)
1864 result = (*(cmd->funct)) (cmd->mii_reg, priv);
wdenka445ddf2004-06-09 00:34:46 +00001865 else
1866 result = cmd->mii_data;
1867
1868 write_phy_reg(priv, cmd->mii_reg, result);
1869
1870 }
1871 cmd++;
1872 }
1873}
1874
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001875#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001876 && !defined(BITBANGMII)
wdenka445ddf2004-06-09 00:34:46 +00001877
wdenk78924a72004-04-18 21:45:42 +00001878/*
1879 * Read a MII PHY register.
1880 *
1881 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001882 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001883 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001884static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001885 unsigned char reg, unsigned short *value)
wdenk78924a72004-04-18 21:45:42 +00001886{
wdenka445ddf2004-06-09 00:34:46 +00001887 unsigned short ret;
michael.firth@bt.com08384842008-01-16 11:40:51 +00001888 struct tsec_private *priv = privlist[0];
wdenk78924a72004-04-18 21:45:42 +00001889
Jon Loeligerb7ced082006-10-10 17:03:43 -05001890 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001891 printf("Can't read PHY at address %d\n", addr);
1892 return -1;
1893 }
1894
Andy Flemingac65e072008-08-31 16:33:27 -05001895 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
wdenka445ddf2004-06-09 00:34:46 +00001896 *value = ret;
wdenk78924a72004-04-18 21:45:42 +00001897
1898 return 0;
1899}
1900
1901/*
1902 * Write a MII PHY register.
1903 *
1904 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001905 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001906 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001907static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001908 unsigned char reg, unsigned short value)
wdenk78924a72004-04-18 21:45:42 +00001909{
michael.firth@bt.com08384842008-01-16 11:40:51 +00001910 struct tsec_private *priv = privlist[0];
wdenka445ddf2004-06-09 00:34:46 +00001911
Jon Loeligerb7ced082006-10-10 17:03:43 -05001912 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001913 printf("Can't write PHY at address %d\n", addr);
1914 return -1;
1915 }
wdenk78924a72004-04-18 21:45:42 +00001916
Andy Flemingac65e072008-08-31 16:33:27 -05001917 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
wdenk78924a72004-04-18 21:45:42 +00001918
1919 return 0;
wdenk9c53f402003-10-15 23:53:47 +00001920}
wdenka445ddf2004-06-09 00:34:46 +00001921
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001922#endif
wdenka445ddf2004-06-09 00:34:46 +00001923
David Updegraff7280da72007-06-11 10:41:07 -05001924#ifdef CONFIG_MCAST_TFTP
1925
1926/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1927
1928/* Set the appropriate hash bit for the given addr */
1929
1930/* The algorithm works like so:
1931 * 1) Take the Destination Address (ie the multicast address), and
1932 * do a CRC on it (little endian), and reverse the bits of the
1933 * result.
1934 * 2) Use the 8 most significant bits as a hash into a 256-entry
1935 * table. The table is controlled through 8 32-bit registers:
1936 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1937 * gaddr7. This means that the 3 most significant bits in the
1938 * hash index which gaddr register to use, and the 5 other bits
1939 * indicate which bit (assuming an IBM numbering scheme, which
1940 * for PowerPC (tm) is usually the case) in the tregister holds
1941 * the entry. */
1942static int
1943tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1944{
Peter Tyser4ef03c02009-11-09 13:09:46 -06001945 struct tsec_private *priv = privlist[1];
1946 volatile tsec_t *regs = priv->regs;
1947 volatile u32 *reg_array, value;
1948 u8 result, whichbit, whichreg;
David Updegraff7280da72007-06-11 10:41:07 -05001949
1950 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1951 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1952 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1953 value = (1 << (31-whichbit));
1954
1955 reg_array = &(regs->hash.gaddr0);
1956
1957 if (set) {
1958 reg_array[whichreg] |= value;
1959 } else {
1960 reg_array[whichreg] &= ~value;
1961 }
1962 return 0;
1963}
1964#endif /* Multicast TFTP ? */