blob: bc2707f17a7d15a2c4d5277660a72f3c1dc08be9 [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
Felix Radensky27f98e02010-06-28 01:57:39 +0300284/* By default force the TBI PHY into 1000Mbps full duplex when in SGMII mode */
285#ifndef CONFIG_TSEC_TBICR_SETTINGS
Andy Flemingac65e072008-08-31 16:33:27 -0500286#define TBICR_SETTINGS ( \
287 TBICR_PHY_RESET \
Andy Flemingac65e072008-08-31 16:33:27 -0500288 | TBICR_FULL_DUPLEX \
289 | TBICR_SPEED1_SET \
290 )
Felix Radensky27f98e02010-06-28 01:57:39 +0300291#else
292#define TBICR_SETTINGS CONFIG_TSEC_TBICR_SETTINGS
293#endif /* CONFIG_TSEC_TBICR_SETTINGS */
Peter Tyser583c1f42009-11-03 17:52:07 -0600294
Andy Flemingac65e072008-08-31 16:33:27 -0500295/* Configure the TBI for SGMII operation */
296static void tsec_configure_serdes(struct tsec_private *priv)
297{
Peter Tyser4ef03c02009-11-09 13:09:46 -0600298 /* Access TBI PHY registers at given TSEC register offset as opposed
299 * to the register offset used for external PHY accesses */
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530300 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_ANA,
Andy Flemingac65e072008-08-31 16:33:27 -0500301 TBIANA_SETTINGS);
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530302 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_TBICON,
Andy Flemingac65e072008-08-31 16:33:27 -0500303 TBICON_CLK_SELECT);
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530304 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_CR,
Andy Flemingac65e072008-08-31 16:33:27 -0500305 TBICR_SETTINGS);
306}
michael.firth@bt.com08384842008-01-16 11:40:51 +0000307
wdenka445ddf2004-06-09 00:34:46 +0000308/* Discover which PHY is attached to the device, and configure it
309 * properly. If the PHY is not recognized, then return 0
310 * (failure). Otherwise, return 1
311 */
312static int init_phy(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000313{
wdenka445ddf2004-06-09 00:34:46 +0000314 struct tsec_private *priv = (struct tsec_private *)dev->priv;
315 struct phy_info *curphy;
Andy Flemingac65e072008-08-31 16:33:27 -0500316 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000317
318 /* Assign a Physical address to the TBI */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200319 regs->tbipa = CONFIG_SYS_TBIPA_VALUE;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500320 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000321
322 /* Reset MII (due to new addresses) */
323 priv->phyregs->miimcfg = MIIMCFG_RESET;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500324 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000325 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500326 asm("sync");
Jon Loeligerb7ced082006-10-10 17:03:43 -0500327 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
wdenk9c53f402003-10-15 23:53:47 +0000328
wdenka445ddf2004-06-09 00:34:46 +0000329 /* Get the cmd structure corresponding to the attached
330 * PHY */
331 curphy = get_phy_info(dev);
wdenk9c53f402003-10-15 23:53:47 +0000332
Ben Warrenf11eefb2006-10-26 14:38:25 -0400333 if (curphy == NULL) {
334 priv->phyinfo = NULL;
wdenka445ddf2004-06-09 00:34:46 +0000335 printf("%s: No PHY found\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000336
wdenka445ddf2004-06-09 00:34:46 +0000337 return 0;
338 }
wdenk9c53f402003-10-15 23:53:47 +0000339
Andy Flemingac65e072008-08-31 16:33:27 -0500340 if (regs->ecntrl & ECNTRL_SGMII_MODE)
341 tsec_configure_serdes(priv);
342
wdenka445ddf2004-06-09 00:34:46 +0000343 priv->phyinfo = curphy;
wdenk9c53f402003-10-15 23:53:47 +0000344
wdenka445ddf2004-06-09 00:34:46 +0000345 phy_run_commands(priv, priv->phyinfo->config);
wdenk9c53f402003-10-15 23:53:47 +0000346
wdenka445ddf2004-06-09 00:34:46 +0000347 return 1;
348}
wdenk9c53f402003-10-15 23:53:47 +0000349
Jon Loeligerb7ced082006-10-10 17:03:43 -0500350/*
351 * Returns which value to write to the control register.
352 * For 10/100, the value is slightly different
353 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600354static uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000355{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500356 if (priv->flags & TSEC_GIGABIT)
wdenka445ddf2004-06-09 00:34:46 +0000357 return MIIM_CONTROL_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000358 else
wdenka445ddf2004-06-09 00:34:46 +0000359 return MIIM_CR_INIT;
360}
wdenk9c53f402003-10-15 23:53:47 +0000361
Peter Tyser4c84fd52009-02-04 15:14:05 -0600362/*
363 * Wait for auto-negotiation to complete, then determine link
Jon Loeligerb7ced082006-10-10 17:03:43 -0500364 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600365static uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000366{
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200367 /*
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500368 * Wait if the link is up, and autonegotiation is in progress
369 * (ie - we're capable and it's not done)
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200370 */
371 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Peter Tyser4c84fd52009-02-04 15:14:05 -0600372 if ((mii_reg & PHY_BMSR_AUTN_ABLE) && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200373 int i = 0;
wdenk9c53f402003-10-15 23:53:47 +0000374
Jon Loeligerb7ced082006-10-10 17:03:43 -0500375 puts("Waiting for PHY auto negotiation to complete");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500376 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200377 /*
378 * Timeout reached ?
379 */
380 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500381 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200382 priv->link = 0;
Jin Zhengxiong-R64188487d2232006-06-27 18:12:23 +0800383 return 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200384 }
wdenk9c53f402003-10-15 23:53:47 +0000385
Kim Phillipsae4dd972009-08-24 14:32:26 -0500386 if (ctrlc()) {
387 puts("user interrupt!\n");
388 priv->link = 0;
389 return -EINTR;
390 }
391
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200392 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500393 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200394 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500395 udelay(1000); /* 1 ms */
wdenka445ddf2004-06-09 00:34:46 +0000396 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200397 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500398 puts(" done\n");
Peter Tyser4c84fd52009-02-04 15:14:05 -0600399
400 /* Link status bit is latched low, read it again */
401 mii_reg = read_phy_reg(priv, MIIM_STATUS);
402
Jon Loeligerb7ced082006-10-10 17:03:43 -0500403 udelay(500000); /* another 500 ms (results in faster booting) */
wdenk9c53f402003-10-15 23:53:47 +0000404 }
405
Peter Tyser4c84fd52009-02-04 15:14:05 -0600406 priv->link = mii_reg & MIIM_STATUS_LINK ? 1 : 0;
407
wdenka445ddf2004-06-09 00:34:46 +0000408 return 0;
409}
410
David Updegraff0451b012007-04-20 14:34:48 -0500411/* Generic function which updates the speed and duplex. If
412 * autonegotiation is enabled, it uses the AND of the link
413 * partner's advertised capabilities and our advertised
414 * capabilities. If autonegotiation is disabled, we use the
415 * appropriate bits in the control register.
416 *
417 * Stolen from Linux's mii.c and phy_device.c
418 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600419static uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
David Updegraff0451b012007-04-20 14:34:48 -0500420{
421 /* We're using autonegotiation */
422 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
423 uint lpa = 0;
424 uint gblpa = 0;
425
426 /* Check for gigabit capability */
427 if (mii_reg & PHY_BMSR_EXT) {
428 /* We want a list of states supported by
429 * both PHYs in the link
430 */
431 gblpa = read_phy_reg(priv, PHY_1000BTSR);
432 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
433 }
434
435 /* Set the baseline so we only have to set them
436 * if they're different
437 */
438 priv->speed = 10;
439 priv->duplexity = 0;
440
441 /* Check the gigabit fields */
442 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
443 priv->speed = 1000;
444
445 if (gblpa & PHY_1000BTSR_1000FD)
446 priv->duplexity = 1;
447
448 /* We're done! */
449 return 0;
450 }
451
452 lpa = read_phy_reg(priv, PHY_ANAR);
453 lpa &= read_phy_reg(priv, PHY_ANLPAR);
454
455 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
456 priv->speed = 100;
457
458 if (lpa & PHY_ANLPAR_TXFD)
459 priv->duplexity = 1;
460
461 } else if (lpa & PHY_ANLPAR_10FD)
462 priv->duplexity = 1;
463 } else {
464 uint bmcr = read_phy_reg(priv, PHY_BMCR);
465
466 priv->speed = 10;
467 priv->duplexity = 0;
468
469 if (bmcr & PHY_BMCR_DPLX)
470 priv->duplexity = 1;
471
472 if (bmcr & PHY_BMCR_1000_MBPS)
473 priv->speed = 1000;
474 else if (bmcr & PHY_BMCR_100_MBPS)
475 priv->speed = 100;
476 }
477
478 return 0;
479}
480
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500481/*
Zach LeRoyddb7fc72009-05-22 10:26:33 -0500482 * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
483 * circumstances. eg a gigabit TSEC connected to a gigabit switch with
484 * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
485 * link. "Ethernet@Wirespeed" reduces advertised speed until link
486 * can be achieved.
487 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600488static uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv)
Zach LeRoyddb7fc72009-05-22 10:26:33 -0500489{
490 return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010;
491}
492
493/*
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500494 * Parse the BCM54xx status register for speed and duplex information.
495 * The linux sungem_phy has this information, but in a table format.
496 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600497static uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500498{
Peter Tyserf6722902009-11-09 13:09:44 -0600499 /* If there is no link, speed and duplex don't matter */
500 if (!priv->link)
501 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500502
Peter Tyserf6722902009-11-09 13:09:44 -0600503 switch ((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >>
504 MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT) {
505 case 1:
506 priv->duplexity = 0;
507 priv->speed = 10;
508 break;
509 case 2:
510 priv->duplexity = 1;
511 priv->speed = 10;
512 break;
513 case 3:
514 priv->duplexity = 0;
515 priv->speed = 100;
516 break;
517 case 5:
518 priv->duplexity = 1;
519 priv->speed = 100;
520 break;
521 case 6:
522 priv->duplexity = 0;
523 priv->speed = 1000;
524 break;
525 case 7:
526 priv->duplexity = 1;
527 priv->speed = 1000;
528 break;
529 default:
530 printf("Auto-neg error, defaulting to 10BT/HD\n");
531 priv->duplexity = 0;
532 priv->speed = 10;
533 break;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500534 }
535
536 return 0;
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600537}
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500538
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600539/*
540 * Find out if PHY is in copper or serdes mode by looking at Expansion Reg
541 * 0x42 - "Operating Mode Status Register"
542 */
543static int BCM8482_is_serdes(struct tsec_private *priv)
544{
545 u16 val;
546 int serdes = 0;
547
548 write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_ER | 0x42);
549 val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA);
550
551 switch (val & 0x1f) {
552 case 0x0d: /* RGMII-to-100Base-FX */
553 case 0x0e: /* RGMII-to-SGMII */
554 case 0x0f: /* RGMII-to-SerDes */
555 case 0x12: /* SGMII-to-SerDes */
556 case 0x13: /* SGMII-to-100Base-FX */
557 case 0x16: /* SerDes-to-Serdes */
558 serdes = 1;
559 break;
560 case 0x6: /* RGMII-to-Copper */
561 case 0x14: /* SGMII-to-Copper */
562 case 0x17: /* SerDes-to-Copper */
563 break;
564 default:
565 printf("ERROR, invalid PHY mode (0x%x\n)", val);
566 break;
567 }
568
569 return serdes;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500570}
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600571
572/*
573 * Determine SerDes link speed and duplex from Expansion reg 0x42 "Operating
574 * Mode Status Register"
575 */
576uint mii_parse_BCM5482_serdes_sr(struct tsec_private *priv)
577{
578 u16 val;
579 int i = 0;
580
581 /* Wait 1s for link - Clause 37 autonegotiation happens very fast */
582 while (1) {
583 write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL,
584 MIIM_BCM54XX_EXP_SEL_ER | 0x42);
585 val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA);
586
587 if (val & 0x8000)
588 break;
589
590 if (i++ > 1000) {
591 priv->link = 0;
592 return 1;
593 }
594
595 udelay(1000); /* 1 ms */
596 }
597
598 priv->link = 1;
599 switch ((val >> 13) & 0x3) {
600 case (0x00):
601 priv->speed = 10;
602 break;
603 case (0x01):
604 priv->speed = 100;
605 break;
606 case (0x02):
607 priv->speed = 1000;
608 break;
609 }
610
611 priv->duplexity = (val & 0x1000) == 0x1000;
612
613 return 0;
614}
615
616/*
617 * Figure out if BCM5482 is in serdes or copper mode and determine link
618 * configuration accordingly
619 */
620static uint mii_parse_BCM5482_sr(uint mii_reg, struct tsec_private *priv)
621{
622 if (BCM8482_is_serdes(priv)) {
623 mii_parse_BCM5482_serdes_sr(priv);
Peter Tyser94f63a72009-11-09 13:09:48 -0600624 priv->flags |= TSEC_FIBER;
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600625 } else {
626 /* Wait for auto-negotiation to complete or fail */
627 mii_parse_sr(mii_reg, priv);
628
629 /* Parse BCM54xx copper aux status register */
630 mii_reg = read_phy_reg(priv, MIIM_BCM54xx_AUXSTATUS);
631 mii_parse_BCM54xx_sr(mii_reg, priv);
632 }
633
634 return 0;
635}
636
wdenka445ddf2004-06-09 00:34:46 +0000637/* Parse the 88E1011's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500638 * information
639 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600640static uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000641{
642 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000643
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200644 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
645
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500646 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
647 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200648 int i = 0;
649
Jon Loeligerb7ced082006-10-10 17:03:43 -0500650 puts("Waiting for PHY realtime link");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500651 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
652 /* Timeout reached ? */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200653 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500654 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200655 priv->link = 0;
656 break;
657 }
658
659 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500660 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200661 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500662 udelay(1000); /* 1 ms */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200663 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
664 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500665 puts(" done\n");
666 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500667 } else {
668 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
669 priv->link = 1;
670 else
671 priv->link = 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200672 }
673
Jon Loeligerb7ced082006-10-10 17:03:43 -0500674 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000675 priv->duplexity = 1;
676 else
677 priv->duplexity = 0;
678
Jon Loeligerb7ced082006-10-10 17:03:43 -0500679 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenka445ddf2004-06-09 00:34:46 +0000680
Jon Loeligerb7ced082006-10-10 17:03:43 -0500681 switch (speed) {
682 case MIIM_88E1011_PHYSTAT_GBIT:
683 priv->speed = 1000;
684 break;
685 case MIIM_88E1011_PHYSTAT_100:
686 priv->speed = 100;
687 break;
688 default:
689 priv->speed = 10;
wdenk9c53f402003-10-15 23:53:47 +0000690 }
691
wdenka445ddf2004-06-09 00:34:46 +0000692 return 0;
693}
694
Dave Liua304a282008-01-11 18:45:28 +0800695/* Parse the RTL8211B's status register for speed and duplex
696 * information
697 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600698static uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
Dave Liua304a282008-01-11 18:45:28 +0800699{
700 uint speed;
701
702 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300703 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liua304a282008-01-11 18:45:28 +0800704 int i = 0;
705
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300706 /* in case of timeout ->link is cleared */
707 priv->link = 1;
Dave Liua304a282008-01-11 18:45:28 +0800708 puts("Waiting for PHY realtime link");
709 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
710 /* Timeout reached ? */
711 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
712 puts(" TIMEOUT !\n");
713 priv->link = 0;
714 break;
715 }
716
717 if ((i++ % 1000) == 0) {
718 putc('.');
719 }
720 udelay(1000); /* 1 ms */
721 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
722 }
723 puts(" done\n");
724 udelay(500000); /* another 500 ms (results in faster booting) */
725 } else {
726 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
727 priv->link = 1;
728 else
729 priv->link = 0;
730 }
731
732 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
733 priv->duplexity = 1;
734 else
735 priv->duplexity = 0;
736
737 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
738
739 switch (speed) {
740 case MIIM_RTL8211B_PHYSTAT_GBIT:
741 priv->speed = 1000;
742 break;
743 case MIIM_RTL8211B_PHYSTAT_100:
744 priv->speed = 100;
745 break;
746 default:
747 priv->speed = 10;
748 }
749
750 return 0;
751}
752
wdenka445ddf2004-06-09 00:34:46 +0000753/* Parse the cis8201's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500754 * information
755 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600756static uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000757{
758 uint speed;
759
Jon Loeligerb7ced082006-10-10 17:03:43 -0500760 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000761 priv->duplexity = 1;
762 else
763 priv->duplexity = 0;
764
765 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500766 switch (speed) {
767 case MIIM_CIS8201_AUXCONSTAT_GBIT:
768 priv->speed = 1000;
769 break;
770 case MIIM_CIS8201_AUXCONSTAT_100:
771 priv->speed = 100;
772 break;
773 default:
774 priv->speed = 10;
775 break;
wdenk9c53f402003-10-15 23:53:47 +0000776 }
777
wdenka445ddf2004-06-09 00:34:46 +0000778 return 0;
779}
Jon Loeligerb7ced082006-10-10 17:03:43 -0500780
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500781/* Parse the vsc8244's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500782 * information
783 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600784static uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500785{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500786 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000787
Jon Loeligerb7ced082006-10-10 17:03:43 -0500788 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
789 priv->duplexity = 1;
790 else
791 priv->duplexity = 0;
792
793 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
794 switch (speed) {
795 case MIIM_VSC8244_AUXCONSTAT_GBIT:
796 priv->speed = 1000;
797 break;
798 case MIIM_VSC8244_AUXCONSTAT_100:
799 priv->speed = 100;
800 break;
801 default:
802 priv->speed = 10;
803 break;
804 }
805
806 return 0;
807}
wdenka445ddf2004-06-09 00:34:46 +0000808
809/* Parse the DM9161's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500810 * information
811 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600812static uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000813{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500814 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenka445ddf2004-06-09 00:34:46 +0000815 priv->speed = 100;
816 else
817 priv->speed = 10;
818
Jon Loeligerb7ced082006-10-10 17:03:43 -0500819 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenka445ddf2004-06-09 00:34:46 +0000820 priv->duplexity = 1;
821 else
822 priv->duplexity = 0;
823
824 return 0;
825}
826
Jon Loeligerb7ced082006-10-10 17:03:43 -0500827/*
828 * Hack to write all 4 PHYs with the LED values
829 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600830static uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000831{
832 uint phyid;
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530833 volatile tsec_mdio_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500834 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000835
Jon Loeligerb7ced082006-10-10 17:03:43 -0500836 for (phyid = 0; phyid < 4; phyid++) {
wdenka445ddf2004-06-09 00:34:46 +0000837 regbase->miimadd = (phyid << 8) | mii_reg;
838 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500839 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000840
Jon Loeligerb7ced082006-10-10 17:03:43 -0500841 timeout = 1000000;
842 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000843 }
wdenk9c53f402003-10-15 23:53:47 +0000844
wdenka445ddf2004-06-09 00:34:46 +0000845 return MIIM_CIS8204_SLEDCON_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000846}
847
Peter Tyser08b2d782009-11-09 13:09:45 -0600848static uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500849{
850 if (priv->flags & TSEC_REDUCED)
851 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
852 else
853 return MIIM_CIS8204_EPHYCON_INIT;
854}
wdenk9c53f402003-10-15 23:53:47 +0000855
Peter Tyser08b2d782009-11-09 13:09:45 -0600856static uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
Dave Liub19ecd32007-09-18 12:37:57 +0800857{
858 uint mii_data = read_phy_reg(priv, mii_reg);
859
860 if (priv->flags & TSEC_REDUCED)
861 mii_data = (mii_data & 0xfff0) | 0x000b;
862 return mii_data;
863}
864
wdenka445ddf2004-06-09 00:34:46 +0000865/* Initialized required registers to appropriate values, zeroing
866 * those we don't care about (unless zero is bad, in which case,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500867 * choose a more appropriate value)
868 */
869static void init_registers(volatile tsec_t * regs)
wdenk9c53f402003-10-15 23:53:47 +0000870{
871 /* Clear IEVENT */
872 regs->ievent = IEVENT_INIT_CLEAR;
873
874 regs->imask = IMASK_INIT_CLEAR;
875
876 regs->hash.iaddr0 = 0;
877 regs->hash.iaddr1 = 0;
878 regs->hash.iaddr2 = 0;
879 regs->hash.iaddr3 = 0;
880 regs->hash.iaddr4 = 0;
881 regs->hash.iaddr5 = 0;
882 regs->hash.iaddr6 = 0;
883 regs->hash.iaddr7 = 0;
884
885 regs->hash.gaddr0 = 0;
886 regs->hash.gaddr1 = 0;
887 regs->hash.gaddr2 = 0;
888 regs->hash.gaddr3 = 0;
889 regs->hash.gaddr4 = 0;
890 regs->hash.gaddr5 = 0;
891 regs->hash.gaddr6 = 0;
892 regs->hash.gaddr7 = 0;
893
894 regs->rctrl = 0x00000000;
895
896 /* Init RMON mib registers */
897 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
898
899 regs->rmon.cam1 = 0xffffffff;
900 regs->rmon.cam2 = 0xffffffff;
901
902 regs->mrblr = MRBLR_INIT_SETTINGS;
903
904 regs->minflr = MINFLR_INIT_SETTINGS;
905
906 regs->attr = ATTR_INIT_SETTINGS;
907 regs->attreli = ATTRELI_INIT_SETTINGS;
908
wdenka445ddf2004-06-09 00:34:46 +0000909}
910
wdenka445ddf2004-06-09 00:34:46 +0000911/* Configure maccfg2 based on negotiated speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500912 * reported by PHY handling code
913 */
wdenka445ddf2004-06-09 00:34:46 +0000914static void adjust_link(struct eth_device *dev)
915{
916 struct tsec_private *priv = (struct tsec_private *)dev->priv;
917 volatile tsec_t *regs = priv->regs;
918
Jon Loeligerb7ced082006-10-10 17:03:43 -0500919 if (priv->link) {
920 if (priv->duplexity != 0)
wdenka445ddf2004-06-09 00:34:46 +0000921 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
922 else
923 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
924
Jon Loeligerb7ced082006-10-10 17:03:43 -0500925 switch (priv->speed) {
926 case 1000:
927 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
928 | MACCFG2_GMII);
929 break;
930 case 100:
931 case 10:
932 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
933 | MACCFG2_MII);
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500934
Nick Spenceec9670b2006-09-07 07:39:46 -0700935 /* Set R100 bit in all modes although
936 * it is only used in RGMII mode
Jon Loeligerb7ced082006-10-10 17:03:43 -0500937 */
Nick Spenceec9670b2006-09-07 07:39:46 -0700938 if (priv->speed == 100)
Jon Loeligerb7ced082006-10-10 17:03:43 -0500939 regs->ecntrl |= ECNTRL_R100;
940 else
941 regs->ecntrl &= ~(ECNTRL_R100);
942 break;
943 default:
944 printf("%s: Speed was bad\n", dev->name);
945 break;
wdenka445ddf2004-06-09 00:34:46 +0000946 }
947
Peter Tyser94f63a72009-11-09 13:09:48 -0600948 printf("Speed: %d, %s duplex%s\n", priv->speed,
949 (priv->duplexity) ? "full" : "half",
950 (priv->flags & TSEC_FIBER) ? ", fiber mode" : "");
wdenka445ddf2004-06-09 00:34:46 +0000951
952 } else {
953 printf("%s: No link.\n", dev->name);
954 }
wdenk9c53f402003-10-15 23:53:47 +0000955}
956
wdenka445ddf2004-06-09 00:34:46 +0000957/* Set up the buffers and their descriptors, and bring up the
Jon Loeligerb7ced082006-10-10 17:03:43 -0500958 * interface
959 */
wdenka445ddf2004-06-09 00:34:46 +0000960static void startup_tsec(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000961{
962 int i;
wdenka445ddf2004-06-09 00:34:46 +0000963 struct tsec_private *priv = (struct tsec_private *)dev->priv;
964 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000965
966 /* Point to the buffer descriptors */
967 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
968 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
969
970 /* Initialize the Rx Buffer descriptors */
971 for (i = 0; i < PKTBUFSRX; i++) {
972 rtx.rxbd[i].status = RXBD_EMPTY;
973 rtx.rxbd[i].length = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500974 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
wdenk9c53f402003-10-15 23:53:47 +0000975 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500976 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000977
978 /* Initialize the TX Buffer Descriptors */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500979 for (i = 0; i < TX_BUF_CNT; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000980 rtx.txbd[i].status = 0;
981 rtx.txbd[i].length = 0;
982 rtx.txbd[i].bufPtr = 0;
983 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500984 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000985
wdenka445ddf2004-06-09 00:34:46 +0000986 /* Start up the PHY */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400987 if(priv->phyinfo)
988 phy_run_commands(priv, priv->phyinfo->startup);
David Updegraff0451b012007-04-20 14:34:48 -0500989
wdenka445ddf2004-06-09 00:34:46 +0000990 adjust_link(dev);
991
wdenk9c53f402003-10-15 23:53:47 +0000992 /* Enable Transmit and Receive */
993 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
994
995 /* Tell the DMA it is clear to go */
996 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
997 regs->tstat = TSTAT_CLEAR_THALT;
Dan Wilsone3d7d6b2007-10-19 11:33:48 -0500998 regs->rstat = RSTAT_CLEAR_RHALT;
wdenk9c53f402003-10-15 23:53:47 +0000999 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
1000}
1001
wdenkbfad55d2005-03-14 23:56:42 +00001002/* This returns the status bits of the device. The return value
wdenk9c53f402003-10-15 23:53:47 +00001003 * is never checked, and this is what the 8260 driver did, so we
wdenkbfad55d2005-03-14 23:56:42 +00001004 * do the same. Presumably, this would be zero if there were no
Jon Loeligerb7ced082006-10-10 17:03:43 -05001005 * errors
1006 */
1007static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
wdenk9c53f402003-10-15 23:53:47 +00001008{
1009 int i;
1010 int result = 0;
wdenka445ddf2004-06-09 00:34:46 +00001011 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1012 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +00001013
1014 /* Find an empty buffer descriptor */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001015 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +00001016 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001017 debug("%s: tsec: tx buffers full\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +00001018 return result;
1019 }
1020 }
1021
Jon Loeligerb7ced082006-10-10 17:03:43 -05001022 rtx.txbd[txIdx].bufPtr = (uint) packet;
wdenk9c53f402003-10-15 23:53:47 +00001023 rtx.txbd[txIdx].length = length;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001024 rtx.txbd[txIdx].status |=
1025 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
wdenk9c53f402003-10-15 23:53:47 +00001026
1027 /* Tell the DMA to go */
1028 regs->tstat = TSTAT_CLEAR_THALT;
1029
1030 /* Wait for buffer to be transmitted */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001031 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +00001032 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001033 debug("%s: tsec: tx error\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +00001034 return result;
1035 }
1036 }
1037
1038 txIdx = (txIdx + 1) % TX_BUF_CNT;
1039 result = rtx.txbd[txIdx].status & TXBD_STATS;
1040
1041 return result;
1042}
1043
Jon Loeligerb7ced082006-10-10 17:03:43 -05001044static int tsec_recv(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +00001045{
1046 int length;
wdenka445ddf2004-06-09 00:34:46 +00001047 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1048 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +00001049
Jon Loeligerb7ced082006-10-10 17:03:43 -05001050 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenk9c53f402003-10-15 23:53:47 +00001051
1052 length = rtx.rxbd[rxIdx].length;
1053
1054 /* Send the packet up if there were no errors */
1055 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
1056 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenka445ddf2004-06-09 00:34:46 +00001057 } else {
1058 printf("Got error %x\n",
Jon Loeligerb7ced082006-10-10 17:03:43 -05001059 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk9c53f402003-10-15 23:53:47 +00001060 }
1061
1062 rtx.rxbd[rxIdx].length = 0;
1063
1064 /* Set the wrap bit if this is the last element in the list */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001065 rtx.rxbd[rxIdx].status =
1066 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
wdenk9c53f402003-10-15 23:53:47 +00001067
1068 rxIdx = (rxIdx + 1) % PKTBUFSRX;
1069 }
1070
Jon Loeligerb7ced082006-10-10 17:03:43 -05001071 if (regs->ievent & IEVENT_BSY) {
wdenk9c53f402003-10-15 23:53:47 +00001072 regs->ievent = IEVENT_BSY;
1073 regs->rstat = RSTAT_CLEAR_RHALT;
1074 }
1075
1076 return -1;
1077
1078}
1079
wdenka445ddf2004-06-09 00:34:46 +00001080/* Stop the interface */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001081static void tsec_halt(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +00001082{
wdenka445ddf2004-06-09 00:34:46 +00001083 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1084 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +00001085
1086 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
1087 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
1088
Andy Fleming18997772010-04-19 14:54:49 -05001089 while ((regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))
1090 != (IEVENT_GRSC | IEVENT_GTSC)) ;
wdenk9c53f402003-10-15 23:53:47 +00001091
1092 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
1093
wdenka445ddf2004-06-09 00:34:46 +00001094 /* Shut down the PHY, as needed */
Ben Warrenf11eefb2006-10-26 14:38:25 -04001095 if(priv->phyinfo)
1096 phy_run_commands(priv, priv->phyinfo->shutdown);
wdenka445ddf2004-06-09 00:34:46 +00001097}
1098
Peter Tyser08b2d782009-11-09 13:09:45 -06001099static struct phy_info phy_info_M88E1149S = {
Wolfgang Denk15e87572007-08-06 01:01:49 +02001100 0x1410ca,
1101 "Marvell 88E1149S",
1102 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001103 (struct phy_cmd[]) { /* config */
Wolfgang Denk15e87572007-08-06 01:01:49 +02001104 /* Reset and configure the PHY */
1105 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1106 {0x1d, 0x1f, NULL},
1107 {0x1e, 0x200c, NULL},
1108 {0x1d, 0x5, NULL},
1109 {0x1e, 0x0, NULL},
1110 {0x1e, 0x100, NULL},
1111 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1112 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1113 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1114 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1115 {miim_end,}
1116 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001117 (struct phy_cmd[]) { /* startup */
Wolfgang Denk15e87572007-08-06 01:01:49 +02001118 /* Status is read once to clear old link state */
1119 {MIIM_STATUS, miim_read, NULL},
1120 /* Auto-negotiate */
1121 {MIIM_STATUS, miim_read, &mii_parse_sr},
1122 /* Read the status */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001123 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
Wolfgang Denk15e87572007-08-06 01:01:49 +02001124 {miim_end,}
1125 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001126 (struct phy_cmd[]) { /* shutdown */
Wolfgang Denk15e87572007-08-06 01:01:49 +02001127 {miim_end,}
1128 },
Andy Flemingbee67002007-08-03 04:05:25 -05001129};
1130
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001131/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001132static struct phy_info phy_info_BCM5461S = {
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001133 0x02060c1, /* 5461 ID */
1134 "Broadcom BCM5461S",
1135 0, /* not clear to me what minor revisions we can shift away */
1136 (struct phy_cmd[]) { /* config */
1137 /* Reset and configure the PHY */
1138 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1139 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1140 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1141 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1142 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1143 {miim_end,}
1144 },
1145 (struct phy_cmd[]) { /* startup */
1146 /* Status is read once to clear old link state */
1147 {MIIM_STATUS, miim_read, NULL},
1148 /* Auto-negotiate */
1149 {MIIM_STATUS, miim_read, &mii_parse_sr},
1150 /* Read the status */
1151 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1152 {miim_end,}
1153 },
1154 (struct phy_cmd[]) { /* shutdown */
1155 {miim_end,}
1156 },
1157};
1158
Peter Tyser08b2d782009-11-09 13:09:45 -06001159static struct phy_info phy_info_BCM5464S = {
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001160 0x02060b1, /* 5464 ID */
1161 "Broadcom BCM5464S",
1162 0, /* not clear to me what minor revisions we can shift away */
1163 (struct phy_cmd[]) { /* config */
1164 /* Reset and configure the PHY */
1165 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1166 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1167 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1168 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001169 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1170 {miim_end,}
1171 },
1172 (struct phy_cmd[]) { /* startup */
1173 /* Status is read once to clear old link state */
1174 {MIIM_STATUS, miim_read, NULL},
1175 /* Auto-negotiate */
1176 {MIIM_STATUS, miim_read, &mii_parse_sr},
1177 /* Read the status */
1178 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1179 {miim_end,}
1180 },
1181 (struct phy_cmd[]) { /* shutdown */
1182 {miim_end,}
1183 },
1184};
1185
Peter Tyser08b2d782009-11-09 13:09:45 -06001186static struct phy_info phy_info_BCM5482S = {
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001187 0x0143bcb,
1188 "Broadcom BCM5482S",
1189 4,
1190 (struct phy_cmd[]) { /* config */
1191 /* Reset and configure the PHY */
1192 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1193 /* Setup read from auxilary control shadow register 7 */
1194 {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
1195 /* Read Misc Control register and or in Ethernet@Wirespeed */
1196 {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001197 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Peter Tyser3c93d8b2009-11-09 13:09:47 -06001198 /* Initial config/enable of secondary SerDes interface */
1199 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf), NULL},
1200 /* Write intial value to secondary SerDes Contol */
1201 {MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_SSD | 0, NULL},
1202 {MIIM_BCM54XX_EXP_DATA, MIIM_CONTROL_RESTART, NULL},
1203 /* Enable copper/fiber auto-detect */
1204 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201)},
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001205 {miim_end,}
1206 },
1207 (struct phy_cmd[]) { /* startup */
1208 /* Status is read once to clear old link state */
1209 {MIIM_STATUS, miim_read, NULL},
Peter Tyser3c93d8b2009-11-09 13:09:47 -06001210 /* Determine copper/fiber, auto-negotiate, and read the result */
1211 {MIIM_STATUS, miim_read, &mii_parse_BCM5482_sr},
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001212 {miim_end,}
1213 },
1214 (struct phy_cmd[]) { /* shutdown */
1215 {miim_end,}
1216 },
1217};
1218
Peter Tyser08b2d782009-11-09 13:09:45 -06001219static struct phy_info phy_info_M88E1011S = {
wdenka445ddf2004-06-09 00:34:46 +00001220 0x01410c6,
1221 "Marvell 88E1011S",
1222 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001223 (struct phy_cmd[]) { /* config */
1224 /* Reset and configure the PHY */
1225 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1226 {0x1d, 0x1f, NULL},
1227 {0x1e, 0x200c, NULL},
1228 {0x1d, 0x5, NULL},
1229 {0x1e, 0x0, NULL},
1230 {0x1e, 0x100, NULL},
1231 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1232 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1233 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1234 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1235 {miim_end,}
1236 },
1237 (struct phy_cmd[]) { /* startup */
1238 /* Status is read once to clear old link state */
1239 {MIIM_STATUS, miim_read, NULL},
1240 /* Auto-negotiate */
1241 {MIIM_STATUS, miim_read, &mii_parse_sr},
1242 /* Read the status */
1243 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1244 {miim_end,}
1245 },
1246 (struct phy_cmd[]) { /* shutdown */
1247 {miim_end,}
1248 },
wdenka445ddf2004-06-09 00:34:46 +00001249};
1250
Peter Tyser08b2d782009-11-09 13:09:45 -06001251static struct phy_info phy_info_M88E1111S = {
wdenkbfad55d2005-03-14 23:56:42 +00001252 0x01410cc,
1253 "Marvell 88E1111S",
1254 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001255 (struct phy_cmd[]) { /* config */
1256 /* Reset and configure the PHY */
1257 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1258 {0x1b, 0x848f, &mii_m88e1111s_setmode},
1259 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
1260 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1261 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1262 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1263 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1264 {miim_end,}
1265 },
1266 (struct phy_cmd[]) { /* startup */
1267 /* Status is read once to clear old link state */
1268 {MIIM_STATUS, miim_read, NULL},
1269 /* Auto-negotiate */
1270 {MIIM_STATUS, miim_read, &mii_parse_sr},
1271 /* Read the status */
1272 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1273 {miim_end,}
1274 },
1275 (struct phy_cmd[]) { /* shutdown */
1276 {miim_end,}
1277 },
wdenkbfad55d2005-03-14 23:56:42 +00001278};
1279
Peter Tyser08b2d782009-11-09 13:09:45 -06001280static struct phy_info phy_info_M88E1118 = {
Ron Madridc1e2b582008-05-23 15:37:05 -07001281 0x01410e1,
1282 "Marvell 88E1118",
1283 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001284 (struct phy_cmd[]) { /* config */
Ron Madridc1e2b582008-05-23 15:37:05 -07001285 /* Reset and configure the PHY */
1286 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1287 {0x16, 0x0002, NULL}, /* Change Page Number */
1288 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
Ron Madridaa4aac42009-01-28 16:17:21 -08001289 {0x16, 0x0003, NULL}, /* Change Page Number */
1290 {0x10, 0x021e, NULL}, /* Adjust LED control */
1291 {0x16, 0x0000, NULL}, /* Change Page Number */
Ron Madridc1e2b582008-05-23 15:37:05 -07001292 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1293 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1294 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1295 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1296 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -06001297 },
1298 (struct phy_cmd[]) { /* startup */
Ron Madridc1e2b582008-05-23 15:37:05 -07001299 {0x16, 0x0000, NULL}, /* Change Page Number */
1300 /* Status is read once to clear old link state */
1301 {MIIM_STATUS, miim_read, NULL},
1302 /* Auto-negotiate */
Ron Madridaa4aac42009-01-28 16:17:21 -08001303 {MIIM_STATUS, miim_read, &mii_parse_sr},
Ron Madridc1e2b582008-05-23 15:37:05 -07001304 /* Read the status */
1305 {MIIM_88E1011_PHY_STATUS, miim_read,
1306 &mii_parse_88E1011_psr},
1307 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -06001308 },
1309 (struct phy_cmd[]) { /* shutdown */
Ron Madridc1e2b582008-05-23 15:37:05 -07001310 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -06001311 },
Ron Madridc1e2b582008-05-23 15:37:05 -07001312};
1313
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001314/*
1315 * Since to access LED register we need do switch the page, we
1316 * do LED configuring in the miim_read-like function as follows
1317 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001318static uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001319{
1320 uint pg;
1321
1322 /* Switch the page to access the led register */
1323 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1324 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1325
1326 /* Configure leds */
1327 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1328 MIIM_88E1121_PHY_LED_DEF);
1329
1330 /* Restore the page pointer */
1331 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1332 return 0;
1333}
1334
Peter Tyser08b2d782009-11-09 13:09:45 -06001335static struct phy_info phy_info_M88E1121R = {
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001336 0x01410cb,
1337 "Marvell 88E1121R",
1338 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001339 (struct phy_cmd[]) { /* config */
1340 /* Reset and configure the PHY */
1341 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1342 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1343 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1344 /* Configure leds */
1345 {MIIM_88E1121_PHY_LED_CTRL, miim_read, &mii_88E1121_set_led},
1346 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1347 /* Disable IRQs and de-assert interrupt */
1348 {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
1349 {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
1350 {miim_end,}
1351 },
1352 (struct phy_cmd[]) { /* startup */
1353 /* Status is read once to clear old link state */
1354 {MIIM_STATUS, miim_read, NULL},
1355 {MIIM_STATUS, miim_read, &mii_parse_sr},
1356 {MIIM_STATUS, miim_read, &mii_parse_link},
1357 {miim_end,}
1358 },
1359 (struct phy_cmd[]) { /* shutdown */
1360 {miim_end,}
1361 },
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001362};
1363
Andy Fleming239e75f2006-09-13 10:34:18 -05001364static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1365{
Andy Fleming239e75f2006-09-13 10:34:18 -05001366 uint mii_data = read_phy_reg(priv, mii_reg);
1367
Andy Fleming239e75f2006-09-13 10:34:18 -05001368 /* Setting MIIM_88E1145_PHY_EXT_CR */
1369 if (priv->flags & TSEC_REDUCED)
1370 return mii_data |
Jon Loeligerb7ced082006-10-10 17:03:43 -05001371 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming239e75f2006-09-13 10:34:18 -05001372 else
1373 return mii_data;
1374}
1375
1376static struct phy_info phy_info_M88E1145 = {
1377 0x01410cd,
1378 "Marvell 88E1145",
1379 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001380 (struct phy_cmd[]) { /* config */
1381 /* Reset the PHY */
1382 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Andy Fleming180d03a2007-05-08 17:23:02 -05001383
Peter Tyser4ef03c02009-11-09 13:09:46 -06001384 /* Errata E0, E1 */
1385 {29, 0x001b, NULL},
1386 {30, 0x418f, NULL},
1387 {29, 0x0016, NULL},
1388 {30, 0xa2da, NULL},
Andy Fleming239e75f2006-09-13 10:34:18 -05001389
Peter Tyser4ef03c02009-11-09 13:09:46 -06001390 /* Configure the PHY */
1391 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1392 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1393 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, NULL},
1394 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1395 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1396 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1397 {miim_end,}
1398 },
1399 (struct phy_cmd[]) { /* startup */
1400 /* Status is read once to clear old link state */
1401 {MIIM_STATUS, miim_read, NULL},
1402 /* Auto-negotiate */
1403 {MIIM_STATUS, miim_read, &mii_parse_sr},
1404 {MIIM_88E1111_PHY_LED_CONTROL, MIIM_88E1111_PHY_LED_DIRECT, NULL},
1405 /* Read the Status */
1406 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1407 {miim_end,}
1408 },
1409 (struct phy_cmd[]) { /* shutdown */
1410 {miim_end,}
1411 },
Andy Fleming239e75f2006-09-13 10:34:18 -05001412};
1413
Peter Tyser08b2d782009-11-09 13:09:45 -06001414static struct phy_info phy_info_cis8204 = {
wdenka445ddf2004-06-09 00:34:46 +00001415 0x3f11,
1416 "Cicada Cis8204",
1417 6,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001418 (struct phy_cmd[]) { /* config */
1419 /* Override PHY config settings */
1420 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1421 /* Configure some basic stuff */
1422 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1423 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1424 &mii_cis8204_fixled},
1425 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1426 &mii_cis8204_setmode},
1427 {miim_end,}
1428 },
1429 (struct phy_cmd[]) { /* startup */
1430 /* Read the Status (2x to make sure link is right) */
1431 {MIIM_STATUS, miim_read, NULL},
1432 /* Auto-negotiate */
1433 {MIIM_STATUS, miim_read, &mii_parse_sr},
1434 /* Read the status */
1435 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1436 {miim_end,}
1437 },
1438 (struct phy_cmd[]) { /* shutdown */
1439 {miim_end,}
1440 },
wdenka445ddf2004-06-09 00:34:46 +00001441};
1442
1443/* Cicada 8201 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001444static struct phy_info phy_info_cis8201 = {
wdenka445ddf2004-06-09 00:34:46 +00001445 0xfc41,
1446 "CIS8201",
1447 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001448 (struct phy_cmd[]) { /* config */
1449 /* Override PHY config settings */
1450 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1451 /* Set up the interface mode */
1452 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1453 /* Configure some basic stuff */
1454 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1455 {miim_end,}
1456 },
1457 (struct phy_cmd[]) { /* startup */
1458 /* Read the Status (2x to make sure link is right) */
1459 {MIIM_STATUS, miim_read, NULL},
1460 /* Auto-negotiate */
1461 {MIIM_STATUS, miim_read, &mii_parse_sr},
1462 /* Read the status */
1463 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1464 {miim_end,}
1465 },
1466 (struct phy_cmd[]) { /* shutdown */
1467 {miim_end,}
1468 },
wdenka445ddf2004-06-09 00:34:46 +00001469};
Peter Tyser08b2d782009-11-09 13:09:45 -06001470
1471static struct phy_info phy_info_VSC8211 = {
Pieter Henning9370c8b2009-02-22 23:17:15 -08001472 0xfc4b,
1473 "Vitesse VSC8211",
1474 4,
1475 (struct phy_cmd[]) { /* config */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001476 /* Override PHY config settings */
1477 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1478 /* Set up the interface mode */
1479 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1480 /* Configure some basic stuff */
1481 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1482 {miim_end,}
1483 },
Pieter Henning9370c8b2009-02-22 23:17:15 -08001484 (struct phy_cmd[]) { /* startup */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001485 /* Read the Status (2x to make sure link is right) */
1486 {MIIM_STATUS, miim_read, NULL},
1487 /* Auto-negotiate */
1488 {MIIM_STATUS, miim_read, &mii_parse_sr},
1489 /* Read the status */
1490 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1491 {miim_end,}
1492 },
Pieter Henning9370c8b2009-02-22 23:17:15 -08001493 (struct phy_cmd[]) { /* shutdown */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001494 {miim_end,}
Pieter Henning9370c8b2009-02-22 23:17:15 -08001495 },
1496};
Peter Tyser08b2d782009-11-09 13:09:45 -06001497
1498static struct phy_info phy_info_VSC8244 = {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001499 0x3f1b,
1500 "Vitesse VSC8244",
1501 6,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001502 (struct phy_cmd[]) { /* config */
1503 /* Override PHY config settings */
1504 /* Configure some basic stuff */
1505 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1506 {miim_end,}
1507 },
1508 (struct phy_cmd[]) { /* startup */
1509 /* Read the Status (2x to make sure link is right) */
1510 {MIIM_STATUS, miim_read, NULL},
1511 /* Auto-negotiate */
1512 {MIIM_STATUS, miim_read, &mii_parse_sr},
1513 /* Read the status */
1514 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1515 {miim_end,}
1516 },
1517 (struct phy_cmd[]) { /* shutdown */
1518 {miim_end,}
1519 },
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001520};
wdenka445ddf2004-06-09 00:34:46 +00001521
Peter Tyser08b2d782009-11-09 13:09:45 -06001522static struct phy_info phy_info_VSC8641 = {
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301523 0x7043,
1524 "Vitesse VSC8641",
1525 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001526 (struct phy_cmd[]) { /* config */
1527 /* Configure some basic stuff */
1528 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1529 {miim_end,}
1530 },
1531 (struct phy_cmd[]) { /* startup */
1532 /* Read the Status (2x to make sure link is right) */
1533 {MIIM_STATUS, miim_read, NULL},
1534 /* Auto-negotiate */
1535 {MIIM_STATUS, miim_read, &mii_parse_sr},
1536 /* Read the status */
1537 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1538 {miim_end,}
1539 },
1540 (struct phy_cmd[]) { /* shutdown */
1541 {miim_end,}
1542 },
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301543};
1544
Peter Tyser08b2d782009-11-09 13:09:45 -06001545static struct phy_info phy_info_VSC8221 = {
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301546 0xfc55,
1547 "Vitesse VSC8221",
1548 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001549 (struct phy_cmd[]) { /* config */
1550 /* Configure some basic stuff */
1551 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1552 {miim_end,}
1553 },
1554 (struct phy_cmd[]) { /* startup */
1555 /* Read the Status (2x to make sure link is right) */
1556 {MIIM_STATUS, miim_read, NULL},
1557 /* Auto-negotiate */
1558 {MIIM_STATUS, miim_read, &mii_parse_sr},
1559 /* Read the status */
1560 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1561 {miim_end,}
1562 },
1563 (struct phy_cmd[]) { /* shutdown */
1564 {miim_end,}
1565 },
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301566};
1567
Peter Tyser08b2d782009-11-09 13:09:45 -06001568static struct phy_info phy_info_VSC8601 = {
Peter Tyser4ef03c02009-11-09 13:09:46 -06001569 0x00007042,
1570 "Vitesse VSC8601",
1571 4,
1572 (struct phy_cmd[]) { /* config */
1573 /* Override PHY config settings */
1574 /* Configure some basic stuff */
1575 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001576#ifdef CONFIG_SYS_VSC8601_SKEWFIX
Peter Tyser4ef03c02009-11-09 13:09:46 -06001577 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001578#if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
Peter Tyser4ef03c02009-11-09 13:09:46 -06001579 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1580#define VSC8101_SKEW \
1581 (CONFIG_SYS_VSC8601_SKEW_TX << 14) | (CONFIG_SYS_VSC8601_SKEW_RX << 12)
1582 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1583 {MIIM_EXT_PAGE_ACCESS,0,NULL},
Andre Schwarz1e18be12008-04-29 19:18:32 +02001584#endif
Tor Krill8b3a82f2008-03-28 15:29:45 +01001585#endif
Peter Tyser4ef03c02009-11-09 13:09:46 -06001586 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1587 {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
1588 {miim_end,}
1589 },
1590 (struct phy_cmd[]) { /* startup */
1591 /* Read the Status (2x to make sure link is right) */
1592 {MIIM_STATUS, miim_read, NULL},
1593 /* Auto-negotiate */
1594 {MIIM_STATUS, miim_read, &mii_parse_sr},
1595 /* Read the status */
1596 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1597 {miim_end,}
1598 },
1599 (struct phy_cmd[]) { /* shutdown */
1600 {miim_end,}
1601 },
Tor Krill8b3a82f2008-03-28 15:29:45 +01001602};
1603
Peter Tyser08b2d782009-11-09 13:09:45 -06001604static struct phy_info phy_info_dm9161 = {
wdenka445ddf2004-06-09 00:34:46 +00001605 0x0181b88,
1606 "Davicom DM9161E",
1607 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001608 (struct phy_cmd[]) { /* config */
1609 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1610 /* Do not bypass the scrambler/descrambler */
1611 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1612 /* Clear 10BTCSR to default */
1613 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
1614 /* Configure some basic stuff */
1615 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1616 /* Restart Auto Negotiation */
1617 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1618 {miim_end,}
1619 },
1620 (struct phy_cmd[]) { /* startup */
1621 /* Status is read once to clear old link state */
1622 {MIIM_STATUS, miim_read, NULL},
1623 /* Auto-negotiate */
1624 {MIIM_STATUS, miim_read, &mii_parse_sr},
1625 /* Read the status */
1626 {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
1627 {miim_end,}
1628 },
1629 (struct phy_cmd[]) { /* shutdown */
1630 {miim_end,}
1631 },
wdenka445ddf2004-06-09 00:34:46 +00001632};
Peter Tyser4ef03c02009-11-09 13:09:46 -06001633
Heiko Schocher6d9933f2010-07-05 12:23:04 +02001634/* micrel KSZ804 */
1635static struct phy_info phy_info_ksz804 = {
1636 0x0022151,
1637 "Micrel KSZ804 PHY",
1638 4,
1639 (struct phy_cmd[]) { /* config */
1640 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1641 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1642 {miim_end,}
1643 },
1644 (struct phy_cmd[]) { /* startup */
1645 {PHY_BMSR, miim_read, NULL},
1646 {PHY_BMSR, miim_read, &mii_parse_sr},
1647 {PHY_BMSR, miim_read, &mii_parse_link},
1648 {miim_end,}
1649 },
1650 (struct phy_cmd[]) { /* shutdown */
1651 {miim_end,}
1652 }
1653};
1654
David Updegraff0451b012007-04-20 14:34:48 -05001655/* a generic flavor. */
Peter Tyser08b2d782009-11-09 13:09:45 -06001656static struct phy_info phy_info_generic = {
David Updegraff0451b012007-04-20 14:34:48 -05001657 0,
1658 "Unknown/Generic PHY",
1659 32,
1660 (struct phy_cmd[]) { /* config */
1661 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1662 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1663 {miim_end,}
1664 },
1665 (struct phy_cmd[]) { /* startup */
1666 {PHY_BMSR, miim_read, NULL},
1667 {PHY_BMSR, miim_read, &mii_parse_sr},
1668 {PHY_BMSR, miim_read, &mii_parse_link},
1669 {miim_end,}
1670 },
1671 (struct phy_cmd[]) { /* shutdown */
1672 {miim_end,}
1673 }
1674};
1675
Peter Tyser08b2d782009-11-09 13:09:45 -06001676static uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
wdenkf41ff3b2005-04-04 23:43:44 +00001677{
wdenke085e5b2005-04-05 23:32:21 +00001678 unsigned int speed;
1679 if (priv->link) {
1680 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenkf41ff3b2005-04-04 23:43:44 +00001681
wdenke085e5b2005-04-05 23:32:21 +00001682 switch (speed) {
1683 case MIIM_LXT971_SR2_10HDX:
1684 priv->speed = 10;
1685 priv->duplexity = 0;
1686 break;
1687 case MIIM_LXT971_SR2_10FDX:
1688 priv->speed = 10;
1689 priv->duplexity = 1;
1690 break;
1691 case MIIM_LXT971_SR2_100HDX:
1692 priv->speed = 100;
1693 priv->duplexity = 0;
urwithsughosh@gmail.com34b3f2e2007-09-10 14:54:56 -04001694 break;
wdenke085e5b2005-04-05 23:32:21 +00001695 default:
1696 priv->speed = 100;
1697 priv->duplexity = 1;
wdenke085e5b2005-04-05 23:32:21 +00001698 }
1699 } else {
1700 priv->speed = 0;
1701 priv->duplexity = 0;
1702 }
wdenkf41ff3b2005-04-04 23:43:44 +00001703
wdenke085e5b2005-04-05 23:32:21 +00001704 return 0;
wdenkf41ff3b2005-04-04 23:43:44 +00001705}
1706
wdenkbfad55d2005-03-14 23:56:42 +00001707static struct phy_info phy_info_lxt971 = {
1708 0x0001378e,
1709 "LXT971",
1710 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001711 (struct phy_cmd[]) { /* config */
1712 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1713 {miim_end,}
1714 },
1715 (struct phy_cmd[]) { /* startup - enable interrupts */
1716 /* { 0x12, 0x00f2, NULL }, */
1717 {MIIM_STATUS, miim_read, NULL},
1718 {MIIM_STATUS, miim_read, &mii_parse_sr},
1719 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1720 {miim_end,}
1721 },
1722 (struct phy_cmd[]) { /* shutdown - disable interrupts */
1723 {miim_end,}
1724 },
wdenkbfad55d2005-03-14 23:56:42 +00001725};
1726
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001727/* Parse the DP83865's link and auto-neg status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -05001728 * information
1729 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001730static uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001731{
1732 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1733
1734 case MIIM_DP83865_SPD_1000:
1735 priv->speed = 1000;
1736 break;
1737
1738 case MIIM_DP83865_SPD_100:
1739 priv->speed = 100;
1740 break;
1741
1742 default:
1743 priv->speed = 10;
1744 break;
1745
1746 }
1747
1748 if (mii_reg & MIIM_DP83865_DPX_FULL)
1749 priv->duplexity = 1;
1750 else
1751 priv->duplexity = 0;
1752
1753 return 0;
1754}
1755
Peter Tyser08b2d782009-11-09 13:09:45 -06001756static struct phy_info phy_info_dp83865 = {
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001757 0x20005c7,
1758 "NatSemi DP83865",
1759 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001760 (struct phy_cmd[]) { /* config */
1761 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1762 {miim_end,}
1763 },
1764 (struct phy_cmd[]) { /* startup */
1765 /* Status is read once to clear old link state */
1766 {MIIM_STATUS, miim_read, NULL},
1767 /* Auto-negotiate */
1768 {MIIM_STATUS, miim_read, &mii_parse_sr},
1769 /* Read the link and auto-neg status */
1770 {MIIM_DP83865_LANR, miim_read, &mii_parse_dp83865_lanr},
1771 {miim_end,}
1772 },
1773 (struct phy_cmd[]) { /* shutdown */
1774 {miim_end,}
1775 },
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001776};
1777
Peter Tyser08b2d782009-11-09 13:09:45 -06001778static struct phy_info phy_info_rtl8211b = {
Dave Liua304a282008-01-11 18:45:28 +08001779 0x001cc91,
1780 "RealTek RTL8211B",
1781 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001782 (struct phy_cmd[]) { /* config */
Dave Liua304a282008-01-11 18:45:28 +08001783 /* Reset and configure the PHY */
1784 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1785 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1786 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1787 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1788 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1789 {miim_end,}
1790 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001791 (struct phy_cmd[]) { /* startup */
Dave Liua304a282008-01-11 18:45:28 +08001792 /* Status is read once to clear old link state */
1793 {MIIM_STATUS, miim_read, NULL},
1794 /* Auto-negotiate */
1795 {MIIM_STATUS, miim_read, &mii_parse_sr},
1796 /* Read the status */
1797 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1798 {miim_end,}
1799 },
Peter Tyser4ef03c02009-11-09 13:09:46 -06001800 (struct phy_cmd[]) { /* shutdown */
Dave Liua304a282008-01-11 18:45:28 +08001801 {miim_end,}
1802 },
1803};
1804
Peter Tyser08b2d782009-11-09 13:09:45 -06001805static struct phy_info *phy_info[] = {
wdenka445ddf2004-06-09 00:34:46 +00001806 &phy_info_cis8204,
Timur Tabi054838e2006-10-31 18:44:42 -06001807 &phy_info_cis8201,
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001808 &phy_info_BCM5461S,
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001809 &phy_info_BCM5464S,
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001810 &phy_info_BCM5482S,
wdenka445ddf2004-06-09 00:34:46 +00001811 &phy_info_M88E1011S,
wdenkbfad55d2005-03-14 23:56:42 +00001812 &phy_info_M88E1111S,
Ron Madridc1e2b582008-05-23 15:37:05 -07001813 &phy_info_M88E1118,
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001814 &phy_info_M88E1121R,
Andy Fleming239e75f2006-09-13 10:34:18 -05001815 &phy_info_M88E1145,
Wolfgang Denk15e87572007-08-06 01:01:49 +02001816 &phy_info_M88E1149S,
wdenka445ddf2004-06-09 00:34:46 +00001817 &phy_info_dm9161,
Heiko Schocher6d9933f2010-07-05 12:23:04 +02001818 &phy_info_ksz804,
wdenkbfad55d2005-03-14 23:56:42 +00001819 &phy_info_lxt971,
Pieter Henning9370c8b2009-02-22 23:17:15 -08001820 &phy_info_VSC8211,
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001821 &phy_info_VSC8244,
Tor Krill8b3a82f2008-03-28 15:29:45 +01001822 &phy_info_VSC8601,
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301823 &phy_info_VSC8641,
1824 &phy_info_VSC8221,
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001825 &phy_info_dp83865,
Dave Liua304a282008-01-11 18:45:28 +08001826 &phy_info_rtl8211b,
Paul Gortmakerf81b8232009-03-09 18:07:53 -05001827 &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
wdenka445ddf2004-06-09 00:34:46 +00001828 NULL
1829};
1830
wdenka445ddf2004-06-09 00:34:46 +00001831/* Grab the identifier of the device's PHY, and search through
wdenkbfad55d2005-03-14 23:56:42 +00001832 * all of the known PHYs to see if one matches. If so, return
Jon Loeligerb7ced082006-10-10 17:03:43 -05001833 * it, if not, return NULL
1834 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001835static struct phy_info *get_phy_info(struct eth_device *dev)
wdenka445ddf2004-06-09 00:34:46 +00001836{
1837 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1838 uint phy_reg, phy_ID;
1839 int i;
1840 struct phy_info *theInfo = NULL;
1841
1842 /* Grab the bits from PHYIR1, and put them in the upper half */
1843 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1844 phy_ID = (phy_reg & 0xffff) << 16;
1845
1846 /* Grab the bits from PHYIR2, and put them in the lower half */
1847 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1848 phy_ID |= (phy_reg & 0xffff);
1849
1850 /* loop through all the known PHY types, and find one that */
1851 /* matches the ID we read from the PHY. */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001852 for (i = 0; phy_info[i]; i++) {
Andy Flemingb2d14f42007-05-09 00:54:20 -05001853 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
wdenka445ddf2004-06-09 00:34:46 +00001854 theInfo = phy_info[i];
Andy Flemingb2d14f42007-05-09 00:54:20 -05001855 break;
1856 }
wdenka445ddf2004-06-09 00:34:46 +00001857 }
1858
Paul Gortmakerf81b8232009-03-09 18:07:53 -05001859 if (theInfo == &phy_info_generic) {
Peter Tyser4ef03c02009-11-09 13:09:46 -06001860 printf("%s: No support for PHY id %x; assuming generic\n",
1861 dev->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001862 } else {
Stefan Roesec0dc34f2005-09-21 18:20:22 +02001863 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001864 }
1865
1866 return theInfo;
1867}
1868
wdenka445ddf2004-06-09 00:34:46 +00001869/* Execute the given series of commands on the given device's
Jon Loeligerb7ced082006-10-10 17:03:43 -05001870 * PHY, running functions as necessary
1871 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001872static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
wdenka445ddf2004-06-09 00:34:46 +00001873{
1874 int i;
1875 uint result;
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +05301876 volatile tsec_mdio_t *phyregs = priv->phyregs;
wdenka445ddf2004-06-09 00:34:46 +00001877
1878 phyregs->miimcfg = MIIMCFG_RESET;
1879
1880 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1881
Jon Loeligerb7ced082006-10-10 17:03:43 -05001882 while (phyregs->miimind & MIIMIND_BUSY) ;
wdenka445ddf2004-06-09 00:34:46 +00001883
Jon Loeligerb7ced082006-10-10 17:03:43 -05001884 for (i = 0; cmd->mii_reg != miim_end; i++) {
1885 if (cmd->mii_data == miim_read) {
wdenka445ddf2004-06-09 00:34:46 +00001886 result = read_phy_reg(priv, cmd->mii_reg);
1887
Jon Loeligerb7ced082006-10-10 17:03:43 -05001888 if (cmd->funct != NULL)
1889 (*(cmd->funct)) (result, priv);
wdenka445ddf2004-06-09 00:34:46 +00001890
1891 } else {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001892 if (cmd->funct != NULL)
1893 result = (*(cmd->funct)) (cmd->mii_reg, priv);
wdenka445ddf2004-06-09 00:34:46 +00001894 else
1895 result = cmd->mii_data;
1896
1897 write_phy_reg(priv, cmd->mii_reg, result);
1898
1899 }
1900 cmd++;
1901 }
1902}
1903
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001904#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001905 && !defined(BITBANGMII)
wdenka445ddf2004-06-09 00:34:46 +00001906
wdenk78924a72004-04-18 21:45:42 +00001907/*
1908 * Read a MII PHY register.
1909 *
1910 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001911 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001912 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001913static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001914 unsigned char reg, unsigned short *value)
wdenk78924a72004-04-18 21:45:42 +00001915{
wdenka445ddf2004-06-09 00:34:46 +00001916 unsigned short ret;
michael.firth@bt.com08384842008-01-16 11:40:51 +00001917 struct tsec_private *priv = privlist[0];
wdenk78924a72004-04-18 21:45:42 +00001918
Jon Loeligerb7ced082006-10-10 17:03:43 -05001919 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001920 printf("Can't read PHY at address %d\n", addr);
1921 return -1;
1922 }
1923
Andy Flemingac65e072008-08-31 16:33:27 -05001924 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
wdenka445ddf2004-06-09 00:34:46 +00001925 *value = ret;
wdenk78924a72004-04-18 21:45:42 +00001926
1927 return 0;
1928}
1929
1930/*
1931 * Write a MII PHY register.
1932 *
1933 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001934 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001935 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001936static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001937 unsigned char reg, unsigned short value)
wdenk78924a72004-04-18 21:45:42 +00001938{
michael.firth@bt.com08384842008-01-16 11:40:51 +00001939 struct tsec_private *priv = privlist[0];
wdenka445ddf2004-06-09 00:34:46 +00001940
Jon Loeligerb7ced082006-10-10 17:03:43 -05001941 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001942 printf("Can't write PHY at address %d\n", addr);
1943 return -1;
1944 }
wdenk78924a72004-04-18 21:45:42 +00001945
Andy Flemingac65e072008-08-31 16:33:27 -05001946 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
wdenk78924a72004-04-18 21:45:42 +00001947
1948 return 0;
wdenk9c53f402003-10-15 23:53:47 +00001949}
wdenka445ddf2004-06-09 00:34:46 +00001950
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001951#endif
wdenka445ddf2004-06-09 00:34:46 +00001952
David Updegraff7280da72007-06-11 10:41:07 -05001953#ifdef CONFIG_MCAST_TFTP
1954
1955/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1956
1957/* Set the appropriate hash bit for the given addr */
1958
1959/* The algorithm works like so:
1960 * 1) Take the Destination Address (ie the multicast address), and
1961 * do a CRC on it (little endian), and reverse the bits of the
1962 * result.
1963 * 2) Use the 8 most significant bits as a hash into a 256-entry
1964 * table. The table is controlled through 8 32-bit registers:
1965 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1966 * gaddr7. This means that the 3 most significant bits in the
1967 * hash index which gaddr register to use, and the 5 other bits
1968 * indicate which bit (assuming an IBM numbering scheme, which
1969 * for PowerPC (tm) is usually the case) in the tregister holds
1970 * the entry. */
1971static int
1972tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1973{
Peter Tyser4ef03c02009-11-09 13:09:46 -06001974 struct tsec_private *priv = privlist[1];
1975 volatile tsec_t *regs = priv->regs;
1976 volatile u32 *reg_array, value;
1977 u8 result, whichbit, whichreg;
David Updegraff7280da72007-06-11 10:41:07 -05001978
1979 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1980 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1981 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1982 value = (1 << (31-whichbit));
1983
1984 reg_array = &(regs->hash.gaddr0);
1985
1986 if (set) {
1987 reg_array[whichreg] |= value;
1988 } else {
1989 reg_array[whichreg] &= ~value;
1990 }
1991 return 0;
1992}
1993#endif /* Multicast TFTP ? */