blob: fd49eff183d0adff2b152b75f0e411d69499c368 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
wdenk97d80fc2004-06-09 00:34:46 +00002 * Freescale Three Speed Ethernet Controller driver
wdenk42d1f032003-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 Gopalpetb9e186f2009-10-31 00:35:04 +05308 * Copyright 2004-2009 Freescale Semiconductor, Inc.
wdenk42d1f032003-10-15 23:53:47 +00009 * (C) Copyright 2003, Motorola, Inc.
wdenk42d1f032003-10-15 23:53:47 +000010 * author Andy Fleming
11 *
12 */
13
14#include <config.h>
wdenk42d1f032003-10-15 23:53:47 +000015#include <common.h>
16#include <malloc.h>
17#include <net.h>
18#include <command.h>
Andy Flemingdd3d1f52008-08-31 16:33:25 -050019#include <tsec.h>
Kim Phillips0d071cd2009-08-24 14:32:26 -050020#include <asm/errno.h>
wdenk42d1f032003-10-15 23:53:47 +000021
Marian Balakowicz63ff0042005-10-28 22:30:33 +020022#include "miiphy.h"
wdenk42d1f032003-10-15 23:53:47 +000023
Wolfgang Denkd87080b2006-03-31 18:32:53 +020024DECLARE_GLOBAL_DATA_PTR;
25
Marian Balakowicz63ff0042005-10-28 22:30:33 +020026#define TX_BUF_CNT 2
wdenk42d1f032003-10-15 23:53:47 +000027
Jon Loeliger89875e92006-10-10 17:03:43 -050028static uint rxIdx; /* index of the current RX buffer */
29static uint txIdx; /* index of the current TX buffer */
wdenk42d1f032003-10-15 23:53:47 +000030
31typedef volatile struct rtxbd {
32 txbd8_t txbd[TX_BUF_CNT];
33 rxbd8_t rxbd[PKTBUFSRX];
Jon Loeliger89875e92006-10-10 17:03:43 -050034} RTXBD;
wdenk42d1f032003-10-15 23:53:47 +000035
Andy Fleming75b9d4a2008-08-31 16:33:26 -050036#define MAXCONTROLLERS (8)
wdenk97d80fc2004-06-09 00:34:46 +000037
wdenk97d80fc2004-06-09 00:34:46 +000038static struct tsec_private *privlist[MAXCONTROLLERS];
Andy Fleming75b9d4a2008-08-31 16:33:26 -050039static int num_tsecs = 0;
wdenk97d80fc2004-06-09 00:34:46 +000040
wdenk42d1f032003-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 Loeliger89875e92006-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 Tysere1957ef2009-11-09 13:09:45 -060051static int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info);
Jon Loeliger89875e92006-10-10 17:03:43 -050052static void tsec_halt(struct eth_device *dev);
53static void init_registers(volatile tsec_t * regs);
wdenk97d80fc2004-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 Tysere1957ef2009-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);
wdenk97d80fc2004-06-09 00:34:46 +000060static void adjust_link(struct eth_device *dev);
Wolfgang Denk409ecdc2007-11-18 16:36:27 +010061#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
62 && !defined(BITBANGMII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +020063static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -050064 unsigned char reg, unsigned short value);
Marian Balakowicz63ff0042005-10-28 22:30:33 +020065static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -050066 unsigned char reg, unsigned short *value);
Wolfgang Denk409ecdc2007-11-18 16:36:27 +010067#endif
David Updegraff53a5c422007-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
wdenk7abf0c52004-04-18 21:45:42 +000071
Andy Fleming75b9d4a2008-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 Gopalpetb9e186f2009-10-31 00:35:04 +053084 .miiregs = (tsec_mdio_t *)(MDIO_BASE_ADDR),
Andy Fleming75b9d4a2008-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
wdenk97d80fc2004-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 Tysere1957ef2009-11-09 13:09:45 -0600116static int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info)
wdenk42d1f032003-10-15 23:53:47 +0000117{
Jon Loeliger89875e92006-10-10 17:03:43 -0500118 struct eth_device *dev;
wdenk42d1f032003-10-15 23:53:47 +0000119 int i;
wdenk97d80fc2004-06-09 00:34:46 +0000120 struct tsec_private *priv;
wdenk42d1f032003-10-15 23:53:47 +0000121
Jon Loeliger89875e92006-10-10 17:03:43 -0500122 dev = (struct eth_device *)malloc(sizeof *dev);
wdenk42d1f032003-10-15 23:53:47 +0000123
Jon Loeliger89875e92006-10-10 17:03:43 -0500124 if (NULL == dev)
wdenk42d1f032003-10-15 23:53:47 +0000125 return 0;
126
127 memset(dev, 0, sizeof *dev);
128
Jon Loeliger89875e92006-10-10 17:03:43 -0500129 priv = (struct tsec_private *)malloc(sizeof(*priv));
wdenk97d80fc2004-06-09 00:34:46 +0000130
Jon Loeliger89875e92006-10-10 17:03:43 -0500131 if (NULL == priv)
wdenk97d80fc2004-06-09 00:34:46 +0000132 return 0;
133
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500134 privlist[num_tsecs++] = priv;
135 priv->regs = tsec_info->regs;
136 priv->phyregs = tsec_info->miiregs;
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +0530137 priv->phyregs_sgmii = tsec_info->miiregs_sgmii;
wdenk97d80fc2004-06-09 00:34:46 +0000138
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500139 priv->phyaddr = tsec_info->phyaddr;
140 priv->flags = tsec_info->flags;
wdenk97d80fc2004-06-09 00:34:46 +0000141
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500142 sprintf(dev->name, tsec_info->devname);
wdenk42d1f032003-10-15 23:53:47 +0000143 dev->iobase = 0;
Jon Loeliger89875e92006-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 Updegraff53a5c422007-06-11 10:41:07 -0500149#ifdef CONFIG_MCAST_TFTP
150 dev->mcast = tsec_mcast_addr;
151#endif
wdenk42d1f032003-10-15 23:53:47 +0000152
153 /* Tell u-boot to get the addr from the env */
Jon Loeliger89875e92006-10-10 17:03:43 -0500154 for (i = 0; i < 6; i++)
wdenk42d1f032003-10-15 23:53:47 +0000155 dev->enetaddr[i] = 0;
156
157 eth_register(dev);
158
wdenk97d80fc2004-06-09 00:34:46 +0000159 /* Reset the MAC */
160 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
Andy Fleming9e5be822009-02-03 18:26:41 -0600161 udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
wdenk97d80fc2004-06-09 00:34:46 +0000162 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
wdenk7abf0c52004-04-18 21:45:42 +0000163
Jon Loeligercb51c0b2007-07-09 17:39:42 -0500164#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200165 && !defined(BITBANGMII)
166 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
167#endif
168
wdenk97d80fc2004-06-09 00:34:46 +0000169 /* Try to initialize PHY here, and return */
170 return init_phy(dev);
wdenk42d1f032003-10-15 23:53:47 +0000171}
172
wdenk42d1f032003-10-15 23:53:47 +0000173/* Initializes data structures and registers for the controller,
wdenk9d46ea42005-03-14 23:56:42 +0000174 * and brings the interface up. Returns the link status, meaning
wdenk97d80fc2004-06-09 00:34:46 +0000175 * that it returns success if the link is up, failure otherwise.
Jon Loeliger89875e92006-10-10 17:03:43 -0500176 * This allows u-boot to find the first active controller.
177 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600178static int tsec_init(struct eth_device *dev, bd_t * bd)
wdenk42d1f032003-10-15 23:53:47 +0000179{
wdenk42d1f032003-10-15 23:53:47 +0000180 uint tempval;
181 char tmpbuf[MAC_ADDR_LEN];
182 int i;
wdenk97d80fc2004-06-09 00:34:46 +0000183 struct tsec_private *priv = (struct tsec_private *)dev->priv;
184 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000185
186 /* Make sure the controller is stopped */
187 tsec_halt(dev);
188
wdenk97d80fc2004-06-09 00:34:46 +0000189 /* Init MACCFG2. Defaults to GMII */
wdenk42d1f032003-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 Loeliger89875e92006-10-10 17:03:43 -0500197 for (i = 0; i < MAC_ADDR_LEN; i++) {
wdenk97d80fc2004-06-09 00:34:46 +0000198 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenk42d1f032003-10-15 23:53:47 +0000199 }
Kim Phillips88ad3fd2009-07-17 12:17:00 -0500200 tempval = (tmpbuf[0] << 24) | (tmpbuf[1] << 16) | (tmpbuf[2] << 8) |
201 tmpbuf[3];
202
203 regs->macstnaddr1 = tempval;
wdenk42d1f032003-10-15 23:53:47 +0000204
Jon Loeliger89875e92006-10-10 17:03:43 -0500205 tempval = *((uint *) (tmpbuf + 4));
wdenk42d1f032003-10-15 23:53:47 +0000206
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200207 regs->macstnaddr2 = tempval;
wdenk42d1f032003-10-15 23:53:47 +0000208
wdenk42d1f032003-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 */
wdenk97d80fc2004-06-09 00:34:46 +0000217 startup_tsec(dev);
wdenk42d1f032003-10-15 23:53:47 +0000218
wdenk97d80fc2004-06-09 00:34:46 +0000219 /* If there's no link, fail */
Ben Warren422b1a02008-01-09 18:15:53 -0500220 return (priv->link ? 0 : -1);
wdenk42d1f032003-10-15 23:53:47 +0000221}
222
Andy Fleming2abe3612008-08-31 16:33:27 -0500223/* Writes the given phy's reg with value, using the specified MDIO regs */
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +0530224static void tsec_local_mdio_write(volatile tsec_mdio_t *phyregs, uint addr,
Andy Fleming2abe3612008-08-31 16:33:27 -0500225 uint reg, uint value)
wdenk97d80fc2004-06-09 00:34:46 +0000226{
Jon Loeliger89875e92006-10-10 17:03:43 -0500227 int timeout = 1000000;
wdenk97d80fc2004-06-09 00:34:46 +0000228
Andy Fleming2abe3612008-08-31 16:33:27 -0500229 phyregs->miimadd = (addr << 8) | reg;
230 phyregs->miimcon = value;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500231 asm("sync");
wdenk97d80fc2004-06-09 00:34:46 +0000232
Jon Loeliger89875e92006-10-10 17:03:43 -0500233 timeout = 1000000;
Andy Fleming2abe3612008-08-31 16:33:27 -0500234 while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk97d80fc2004-06-09 00:34:46 +0000235}
236
Andy Fleming2abe3612008-08-31 16:33:27 -0500237
238/* Provide the default behavior of writing the PHY of this ethernet device */
Peter Tyserc6dbdfd2009-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.com55fe7c52008-01-16 11:40:51 +0000241
wdenk97d80fc2004-06-09 00:34:46 +0000242/* Reads register regnum on the device's PHY through the
Andy Fleming2abe3612008-08-31 16:33:27 -0500243 * specified registers. It lowers and raises the read
wdenk97d80fc2004-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 Tysere1957ef2009-11-09 13:09:45 -0600248static uint tsec_local_mdio_read(volatile tsec_mdio_t *phyregs,
249 uint phyid, uint regnum)
wdenk42d1f032003-10-15 23:53:47 +0000250{
251 uint value;
252
wdenk97d80fc2004-06-09 00:34:46 +0000253 /* Put the address of the phy, and the register
254 * number into MIIMADD */
Andy Fleming2abe3612008-08-31 16:33:27 -0500255 phyregs->miimadd = (phyid << 8) | regnum;
wdenk42d1f032003-10-15 23:53:47 +0000256
257 /* Clear the command register, and wait */
Andy Fleming2abe3612008-08-31 16:33:27 -0500258 phyregs->miimcom = 0;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500259 asm("sync");
wdenk42d1f032003-10-15 23:53:47 +0000260
261 /* Initiate a read command, and wait */
Andy Fleming2abe3612008-08-31 16:33:27 -0500262 phyregs->miimcom = MIIM_READ_COMMAND;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500263 asm("sync");
wdenk42d1f032003-10-15 23:53:47 +0000264
265 /* Wait for the the indication that the read is done */
Andy Fleming2abe3612008-08-31 16:33:27 -0500266 while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
wdenk42d1f032003-10-15 23:53:47 +0000267
268 /* Grab the value read from the PHY */
Andy Fleming2abe3612008-08-31 16:33:27 -0500269 value = phyregs->miimstat;
wdenk42d1f032003-10-15 23:53:47 +0000270
271 return value;
272}
273
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +0000274/* #define to provide old read_phy_reg functionality without duplicating code */
Peter Tyserc6dbdfd2009-11-09 13:09:46 -0600275#define read_phy_reg(priv,regnum) \
276 tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
Andy Fleming2abe3612008-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 Tyser46e91672009-11-03 17:52:07 -0600284/* Force the TBI PHY into 1000Mbps full duplex when in SGMII mode */
Andy Fleming2abe3612008-08-31 16:33:27 -0500285#define TBICR_SETTINGS ( \
286 TBICR_PHY_RESET \
Andy Fleming2abe3612008-08-31 16:33:27 -0500287 | TBICR_FULL_DUPLEX \
288 | TBICR_SPEED1_SET \
289 )
Peter Tyser46e91672009-11-03 17:52:07 -0600290
Andy Fleming2abe3612008-08-31 16:33:27 -0500291/* Configure the TBI for SGMII operation */
292static void tsec_configure_serdes(struct tsec_private *priv)
293{
Peter Tyserc6dbdfd2009-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 Gopalpetb9e186f2009-10-31 00:35:04 +0530296 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_ANA,
Andy Fleming2abe3612008-08-31 16:33:27 -0500297 TBIANA_SETTINGS);
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +0530298 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_TBICON,
Andy Fleming2abe3612008-08-31 16:33:27 -0500299 TBICON_CLK_SELECT);
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +0530300 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_CR,
Andy Fleming2abe3612008-08-31 16:33:27 -0500301 TBICR_SETTINGS);
302}
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +0000303
wdenk97d80fc2004-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)
wdenk42d1f032003-10-15 23:53:47 +0000309{
wdenk97d80fc2004-06-09 00:34:46 +0000310 struct tsec_private *priv = (struct tsec_private *)dev->priv;
311 struct phy_info *curphy;
Andy Fleming2abe3612008-08-31 16:33:27 -0500312 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000313
314 /* Assign a Physical address to the TBI */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200315 regs->tbipa = CONFIG_SYS_TBIPA_VALUE;
Jon Loeliger89875e92006-10-10 17:03:43 -0500316 asm("sync");
wdenk3dd7f0f2005-04-04 23:43:44 +0000317
318 /* Reset MII (due to new addresses) */
319 priv->phyregs->miimcfg = MIIMCFG_RESET;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500320 asm("sync");
wdenk3dd7f0f2005-04-04 23:43:44 +0000321 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500322 asm("sync");
Jon Loeliger89875e92006-10-10 17:03:43 -0500323 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
wdenk42d1f032003-10-15 23:53:47 +0000324
wdenk97d80fc2004-06-09 00:34:46 +0000325 /* Get the cmd structure corresponding to the attached
326 * PHY */
327 curphy = get_phy_info(dev);
wdenk42d1f032003-10-15 23:53:47 +0000328
Ben Warren4653f912006-10-26 14:38:25 -0400329 if (curphy == NULL) {
330 priv->phyinfo = NULL;
wdenk97d80fc2004-06-09 00:34:46 +0000331 printf("%s: No PHY found\n", dev->name);
wdenk42d1f032003-10-15 23:53:47 +0000332
wdenk97d80fc2004-06-09 00:34:46 +0000333 return 0;
wdenk42d1f032003-10-15 23:53:47 +0000334 }
335
Andy Fleming2abe3612008-08-31 16:33:27 -0500336 if (regs->ecntrl & ECNTRL_SGMII_MODE)
337 tsec_configure_serdes(priv);
338
wdenk97d80fc2004-06-09 00:34:46 +0000339 priv->phyinfo = curphy;
wdenk42d1f032003-10-15 23:53:47 +0000340
wdenk97d80fc2004-06-09 00:34:46 +0000341 phy_run_commands(priv, priv->phyinfo->config);
wdenk42d1f032003-10-15 23:53:47 +0000342
wdenk97d80fc2004-06-09 00:34:46 +0000343 return 1;
wdenk42d1f032003-10-15 23:53:47 +0000344}
345
Jon Loeliger89875e92006-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 Tysere1957ef2009-11-09 13:09:45 -0600350static uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000351{
Jon Loeliger89875e92006-10-10 17:03:43 -0500352 if (priv->flags & TSEC_GIGABIT)
wdenk97d80fc2004-06-09 00:34:46 +0000353 return MIIM_CONTROL_INIT;
354 else
355 return MIIM_CR_INIT;
356}
357
Peter Tyserb1e849f2009-02-04 15:14:05 -0600358/*
359 * Wait for auto-negotiation to complete, then determine link
Jon Loeliger89875e92006-10-10 17:03:43 -0500360 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600361static uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000362{
Stefan Roese5810dc32005-09-21 18:20:22 +0200363 /*
Andy Fleming7613afd2007-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 Roese5810dc32005-09-21 18:20:22 +0200366 */
367 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Peter Tyserb1e849f2009-02-04 15:14:05 -0600368 if ((mii_reg & PHY_BMSR_AUTN_ABLE) && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roese5810dc32005-09-21 18:20:22 +0200369 int i = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000370
Jon Loeliger89875e92006-10-10 17:03:43 -0500371 puts("Waiting for PHY auto negotiation to complete");
Andy Fleming7613afd2007-08-15 20:03:44 -0500372 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roese5810dc32005-09-21 18:20:22 +0200373 /*
374 * Timeout reached ?
375 */
376 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500377 puts(" TIMEOUT !\n");
Stefan Roese5810dc32005-09-21 18:20:22 +0200378 priv->link = 0;
Jin Zhengxiong-R64188fcfb9a52006-06-27 18:12:23 +0800379 return 0;
Stefan Roese5810dc32005-09-21 18:20:22 +0200380 }
wdenk97d80fc2004-06-09 00:34:46 +0000381
Kim Phillips0d071cd2009-08-24 14:32:26 -0500382 if (ctrlc()) {
383 puts("user interrupt!\n");
384 priv->link = 0;
385 return -EINTR;
386 }
387
Stefan Roese5810dc32005-09-21 18:20:22 +0200388 if ((i++ % 1000) == 0) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500389 putc('.');
Stefan Roese5810dc32005-09-21 18:20:22 +0200390 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500391 udelay(1000); /* 1 ms */
wdenk97d80fc2004-06-09 00:34:46 +0000392 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roese5810dc32005-09-21 18:20:22 +0200393 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500394 puts(" done\n");
Peter Tyserb1e849f2009-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 Loeliger89875e92006-10-10 17:03:43 -0500399 udelay(500000); /* another 500 ms (results in faster booting) */
wdenk97d80fc2004-06-09 00:34:46 +0000400 }
401
Peter Tyserb1e849f2009-02-04 15:14:05 -0600402 priv->link = mii_reg & MIIM_STATUS_LINK ? 1 : 0;
403
wdenk97d80fc2004-06-09 00:34:46 +0000404 return 0;
405}
406
David Updegraffaf1c2b82007-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 Tysere1957ef2009-11-09 13:09:45 -0600415static uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
David Updegraffaf1c2b82007-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 Gortmaker91e25762007-01-16 11:38:14 -0500477/*
Zach LeRoy091dc9f2009-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 Tysere1957ef2009-11-09 13:09:45 -0600484static uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv)
Zach LeRoy091dc9f2009-05-22 10:26:33 -0500485{
486 return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010;
487}
488
489/*
Paul Gortmaker91e25762007-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 Tysere1957ef2009-11-09 13:09:45 -0600493static uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
Paul Gortmaker91e25762007-01-16 11:38:14 -0500494{
Peter Tyser27165b52009-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 Gortmaker91e25762007-01-16 11:38:14 -0500498
Peter Tyser27165b52009-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 Gortmaker91e25762007-01-16 11:38:14 -0500530 }
531
532 return 0;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500533}
Peter Tyser8abb8dc2009-11-09 13:09:47 -0600534
535/*
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;
566}
567
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);
Peter Tyser5f6b1442009-11-09 13:09:48 -0600620 priv->flags |= TSEC_FIBER;
Peter Tyser8abb8dc2009-11-09 13:09:47 -0600621 } else {
622 /* Wait for auto-negotiation to complete or fail */
623 mii_parse_sr(mii_reg, priv);
624
625 /* Parse BCM54xx copper aux status register */
626 mii_reg = read_phy_reg(priv, MIIM_BCM54xx_AUXSTATUS);
627 mii_parse_BCM54xx_sr(mii_reg, priv);
628 }
629
630 return 0;
631}
632
wdenk97d80fc2004-06-09 00:34:46 +0000633/* Parse the 88E1011's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500634 * information
635 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600636static uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000637{
638 uint speed;
639
Stefan Roese5810dc32005-09-21 18:20:22 +0200640 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
641
Andy Fleming7613afd2007-08-15 20:03:44 -0500642 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
643 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roese5810dc32005-09-21 18:20:22 +0200644 int i = 0;
645
Jon Loeliger89875e92006-10-10 17:03:43 -0500646 puts("Waiting for PHY realtime link");
Andy Fleming7613afd2007-08-15 20:03:44 -0500647 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
648 /* Timeout reached ? */
Stefan Roese5810dc32005-09-21 18:20:22 +0200649 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500650 puts(" TIMEOUT !\n");
Stefan Roese5810dc32005-09-21 18:20:22 +0200651 priv->link = 0;
652 break;
653 }
654
655 if ((i++ % 1000) == 0) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500656 putc('.');
Stefan Roese5810dc32005-09-21 18:20:22 +0200657 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500658 udelay(1000); /* 1 ms */
Stefan Roese5810dc32005-09-21 18:20:22 +0200659 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
660 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500661 puts(" done\n");
662 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming7613afd2007-08-15 20:03:44 -0500663 } else {
664 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
665 priv->link = 1;
666 else
667 priv->link = 0;
Stefan Roese5810dc32005-09-21 18:20:22 +0200668 }
669
Jon Loeliger89875e92006-10-10 17:03:43 -0500670 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenk97d80fc2004-06-09 00:34:46 +0000671 priv->duplexity = 1;
672 else
673 priv->duplexity = 0;
674
Jon Loeliger89875e92006-10-10 17:03:43 -0500675 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenk97d80fc2004-06-09 00:34:46 +0000676
Jon Loeliger89875e92006-10-10 17:03:43 -0500677 switch (speed) {
678 case MIIM_88E1011_PHYSTAT_GBIT:
679 priv->speed = 1000;
680 break;
681 case MIIM_88E1011_PHYSTAT_100:
682 priv->speed = 100;
683 break;
684 default:
685 priv->speed = 10;
wdenk97d80fc2004-06-09 00:34:46 +0000686 }
687
688 return 0;
689}
690
Dave Liu18ee3202008-01-11 18:45:28 +0800691/* Parse the RTL8211B's status register for speed and duplex
692 * information
693 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600694static uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
Dave Liu18ee3202008-01-11 18:45:28 +0800695{
696 uint speed;
697
698 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsovc7604782008-03-14 23:20:30 +0300699 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liu18ee3202008-01-11 18:45:28 +0800700 int i = 0;
701
Anton Vorontsovc7604782008-03-14 23:20:30 +0300702 /* in case of timeout ->link is cleared */
703 priv->link = 1;
Dave Liu18ee3202008-01-11 18:45:28 +0800704 puts("Waiting for PHY realtime link");
705 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
706 /* Timeout reached ? */
707 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
708 puts(" TIMEOUT !\n");
709 priv->link = 0;
710 break;
711 }
712
713 if ((i++ % 1000) == 0) {
714 putc('.');
715 }
716 udelay(1000); /* 1 ms */
717 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
718 }
719 puts(" done\n");
720 udelay(500000); /* another 500 ms (results in faster booting) */
721 } else {
722 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
723 priv->link = 1;
724 else
725 priv->link = 0;
726 }
727
728 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
729 priv->duplexity = 1;
730 else
731 priv->duplexity = 0;
732
733 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
734
735 switch (speed) {
736 case MIIM_RTL8211B_PHYSTAT_GBIT:
737 priv->speed = 1000;
738 break;
739 case MIIM_RTL8211B_PHYSTAT_100:
740 priv->speed = 100;
741 break;
742 default:
743 priv->speed = 10;
744 }
745
746 return 0;
747}
748
wdenk97d80fc2004-06-09 00:34:46 +0000749/* Parse the cis8201's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500750 * information
751 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600752static uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000753{
754 uint speed;
755
Jon Loeliger89875e92006-10-10 17:03:43 -0500756 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenk97d80fc2004-06-09 00:34:46 +0000757 priv->duplexity = 1;
758 else
759 priv->duplexity = 0;
760
761 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeliger89875e92006-10-10 17:03:43 -0500762 switch (speed) {
763 case MIIM_CIS8201_AUXCONSTAT_GBIT:
764 priv->speed = 1000;
765 break;
766 case MIIM_CIS8201_AUXCONSTAT_100:
767 priv->speed = 100;
768 break;
769 default:
770 priv->speed = 10;
771 break;
wdenk97d80fc2004-06-09 00:34:46 +0000772 }
773
774 return 0;
775}
Jon Loeliger89875e92006-10-10 17:03:43 -0500776
Jon Loeligerdebb7352006-04-26 17:58:56 -0500777/* Parse the vsc8244's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500778 * information
779 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600780static uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500781{
Jon Loeliger89875e92006-10-10 17:03:43 -0500782 uint speed;
783
784 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
785 priv->duplexity = 1;
786 else
787 priv->duplexity = 0;
788
789 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
790 switch (speed) {
791 case MIIM_VSC8244_AUXCONSTAT_GBIT:
792 priv->speed = 1000;
793 break;
794 case MIIM_VSC8244_AUXCONSTAT_100:
795 priv->speed = 100;
796 break;
797 default:
798 priv->speed = 10;
799 break;
800 }
801
802 return 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500803}
wdenk97d80fc2004-06-09 00:34:46 +0000804
wdenk97d80fc2004-06-09 00:34:46 +0000805/* Parse the DM9161's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500806 * information
807 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600808static uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000809{
Jon Loeliger89875e92006-10-10 17:03:43 -0500810 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenk97d80fc2004-06-09 00:34:46 +0000811 priv->speed = 100;
812 else
813 priv->speed = 10;
814
Jon Loeliger89875e92006-10-10 17:03:43 -0500815 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenk97d80fc2004-06-09 00:34:46 +0000816 priv->duplexity = 1;
817 else
818 priv->duplexity = 0;
819
820 return 0;
821}
822
Jon Loeliger89875e92006-10-10 17:03:43 -0500823/*
824 * Hack to write all 4 PHYs with the LED values
825 */
Peter Tysere1957ef2009-11-09 13:09:45 -0600826static uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000827{
828 uint phyid;
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +0530829 volatile tsec_mdio_t *regbase = priv->phyregs;
Jon Loeliger89875e92006-10-10 17:03:43 -0500830 int timeout = 1000000;
wdenk97d80fc2004-06-09 00:34:46 +0000831
Jon Loeliger89875e92006-10-10 17:03:43 -0500832 for (phyid = 0; phyid < 4; phyid++) {
wdenk97d80fc2004-06-09 00:34:46 +0000833 regbase->miimadd = (phyid << 8) | mii_reg;
834 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500835 asm("sync");
wdenk97d80fc2004-06-09 00:34:46 +0000836
Jon Loeliger89875e92006-10-10 17:03:43 -0500837 timeout = 1000000;
838 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk97d80fc2004-06-09 00:34:46 +0000839 }
840
841 return MIIM_CIS8204_SLEDCON_INIT;
842}
843
Peter Tysere1957ef2009-11-09 13:09:45 -0600844static uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500845{
846 if (priv->flags & TSEC_REDUCED)
847 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
848 else
849 return MIIM_CIS8204_EPHYCON_INIT;
850}
wdenk97d80fc2004-06-09 00:34:46 +0000851
Peter Tysere1957ef2009-11-09 13:09:45 -0600852static uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
Dave Liu19580e62007-09-18 12:37:57 +0800853{
854 uint mii_data = read_phy_reg(priv, mii_reg);
855
856 if (priv->flags & TSEC_REDUCED)
857 mii_data = (mii_data & 0xfff0) | 0x000b;
858 return mii_data;
859}
860
wdenk97d80fc2004-06-09 00:34:46 +0000861/* Initialized required registers to appropriate values, zeroing
862 * those we don't care about (unless zero is bad, in which case,
Jon Loeliger89875e92006-10-10 17:03:43 -0500863 * choose a more appropriate value)
864 */
865static void init_registers(volatile tsec_t * regs)
wdenk42d1f032003-10-15 23:53:47 +0000866{
867 /* Clear IEVENT */
868 regs->ievent = IEVENT_INIT_CLEAR;
869
870 regs->imask = IMASK_INIT_CLEAR;
871
872 regs->hash.iaddr0 = 0;
873 regs->hash.iaddr1 = 0;
874 regs->hash.iaddr2 = 0;
875 regs->hash.iaddr3 = 0;
876 regs->hash.iaddr4 = 0;
877 regs->hash.iaddr5 = 0;
878 regs->hash.iaddr6 = 0;
879 regs->hash.iaddr7 = 0;
880
881 regs->hash.gaddr0 = 0;
882 regs->hash.gaddr1 = 0;
883 regs->hash.gaddr2 = 0;
884 regs->hash.gaddr3 = 0;
885 regs->hash.gaddr4 = 0;
886 regs->hash.gaddr5 = 0;
887 regs->hash.gaddr6 = 0;
888 regs->hash.gaddr7 = 0;
889
890 regs->rctrl = 0x00000000;
891
892 /* Init RMON mib registers */
893 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
894
895 regs->rmon.cam1 = 0xffffffff;
896 regs->rmon.cam2 = 0xffffffff;
897
898 regs->mrblr = MRBLR_INIT_SETTINGS;
899
900 regs->minflr = MINFLR_INIT_SETTINGS;
901
902 regs->attr = ATTR_INIT_SETTINGS;
903 regs->attreli = ATTRELI_INIT_SETTINGS;
904
905}
906
wdenk97d80fc2004-06-09 00:34:46 +0000907/* Configure maccfg2 based on negotiated speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500908 * reported by PHY handling code
909 */
wdenk97d80fc2004-06-09 00:34:46 +0000910static void adjust_link(struct eth_device *dev)
911{
912 struct tsec_private *priv = (struct tsec_private *)dev->priv;
913 volatile tsec_t *regs = priv->regs;
914
Jon Loeliger89875e92006-10-10 17:03:43 -0500915 if (priv->link) {
916 if (priv->duplexity != 0)
wdenk97d80fc2004-06-09 00:34:46 +0000917 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
918 else
919 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
920
Jon Loeliger89875e92006-10-10 17:03:43 -0500921 switch (priv->speed) {
922 case 1000:
923 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
924 | MACCFG2_GMII);
925 break;
926 case 100:
927 case 10:
928 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
929 | MACCFG2_MII);
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500930
Nick Spencef484dc72006-09-07 07:39:46 -0700931 /* Set R100 bit in all modes although
932 * it is only used in RGMII mode
Jon Loeliger89875e92006-10-10 17:03:43 -0500933 */
Nick Spencef484dc72006-09-07 07:39:46 -0700934 if (priv->speed == 100)
Jon Loeliger89875e92006-10-10 17:03:43 -0500935 regs->ecntrl |= ECNTRL_R100;
936 else
937 regs->ecntrl &= ~(ECNTRL_R100);
938 break;
939 default:
940 printf("%s: Speed was bad\n", dev->name);
941 break;
wdenk97d80fc2004-06-09 00:34:46 +0000942 }
943
Peter Tyser5f6b1442009-11-09 13:09:48 -0600944 printf("Speed: %d, %s duplex%s\n", priv->speed,
945 (priv->duplexity) ? "full" : "half",
946 (priv->flags & TSEC_FIBER) ? ", fiber mode" : "");
wdenk97d80fc2004-06-09 00:34:46 +0000947
948 } else {
949 printf("%s: No link.\n", dev->name);
950 }
951}
952
wdenk97d80fc2004-06-09 00:34:46 +0000953/* Set up the buffers and their descriptors, and bring up the
Jon Loeliger89875e92006-10-10 17:03:43 -0500954 * interface
955 */
wdenk97d80fc2004-06-09 00:34:46 +0000956static void startup_tsec(struct eth_device *dev)
wdenk42d1f032003-10-15 23:53:47 +0000957{
958 int i;
wdenk97d80fc2004-06-09 00:34:46 +0000959 struct tsec_private *priv = (struct tsec_private *)dev->priv;
960 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000961
962 /* Point to the buffer descriptors */
963 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
964 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
965
966 /* Initialize the Rx Buffer descriptors */
967 for (i = 0; i < PKTBUFSRX; i++) {
968 rtx.rxbd[i].status = RXBD_EMPTY;
969 rtx.rxbd[i].length = 0;
Jon Loeliger89875e92006-10-10 17:03:43 -0500970 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
wdenk42d1f032003-10-15 23:53:47 +0000971 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500972 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
wdenk42d1f032003-10-15 23:53:47 +0000973
974 /* Initialize the TX Buffer Descriptors */
Jon Loeliger89875e92006-10-10 17:03:43 -0500975 for (i = 0; i < TX_BUF_CNT; i++) {
wdenk42d1f032003-10-15 23:53:47 +0000976 rtx.txbd[i].status = 0;
977 rtx.txbd[i].length = 0;
978 rtx.txbd[i].bufPtr = 0;
979 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500980 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
wdenk42d1f032003-10-15 23:53:47 +0000981
wdenk97d80fc2004-06-09 00:34:46 +0000982 /* Start up the PHY */
Ben Warren4653f912006-10-26 14:38:25 -0400983 if(priv->phyinfo)
984 phy_run_commands(priv, priv->phyinfo->startup);
David Updegraffaf1c2b82007-04-20 14:34:48 -0500985
wdenk97d80fc2004-06-09 00:34:46 +0000986 adjust_link(dev);
987
wdenk42d1f032003-10-15 23:53:47 +0000988 /* Enable Transmit and Receive */
989 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
990
991 /* Tell the DMA it is clear to go */
992 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
993 regs->tstat = TSTAT_CLEAR_THALT;
Dan Wilson5c7ea642007-10-19 11:33:48 -0500994 regs->rstat = RSTAT_CLEAR_RHALT;
wdenk42d1f032003-10-15 23:53:47 +0000995 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
996}
997
wdenk9d46ea42005-03-14 23:56:42 +0000998/* This returns the status bits of the device. The return value
wdenk42d1f032003-10-15 23:53:47 +0000999 * is never checked, and this is what the 8260 driver did, so we
wdenk9d46ea42005-03-14 23:56:42 +00001000 * do the same. Presumably, this would be zero if there were no
Jon Loeliger89875e92006-10-10 17:03:43 -05001001 * errors
1002 */
1003static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
wdenk42d1f032003-10-15 23:53:47 +00001004{
1005 int i;
1006 int result = 0;
wdenk97d80fc2004-06-09 00:34:46 +00001007 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1008 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +00001009
1010 /* Find an empty buffer descriptor */
Jon Loeliger89875e92006-10-10 17:03:43 -05001011 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk42d1f032003-10-15 23:53:47 +00001012 if (i >= TOUT_LOOP) {
Jon Loeliger89875e92006-10-10 17:03:43 -05001013 debug("%s: tsec: tx buffers full\n", dev->name);
wdenk42d1f032003-10-15 23:53:47 +00001014 return result;
1015 }
1016 }
1017
Jon Loeliger89875e92006-10-10 17:03:43 -05001018 rtx.txbd[txIdx].bufPtr = (uint) packet;
wdenk42d1f032003-10-15 23:53:47 +00001019 rtx.txbd[txIdx].length = length;
Jon Loeliger89875e92006-10-10 17:03:43 -05001020 rtx.txbd[txIdx].status |=
1021 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
wdenk42d1f032003-10-15 23:53:47 +00001022
1023 /* Tell the DMA to go */
1024 regs->tstat = TSTAT_CLEAR_THALT;
1025
1026 /* Wait for buffer to be transmitted */
Jon Loeliger89875e92006-10-10 17:03:43 -05001027 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk42d1f032003-10-15 23:53:47 +00001028 if (i >= TOUT_LOOP) {
Jon Loeliger89875e92006-10-10 17:03:43 -05001029 debug("%s: tsec: tx error\n", dev->name);
wdenk42d1f032003-10-15 23:53:47 +00001030 return result;
1031 }
1032 }
1033
1034 txIdx = (txIdx + 1) % TX_BUF_CNT;
1035 result = rtx.txbd[txIdx].status & TXBD_STATS;
1036
1037 return result;
1038}
1039
Jon Loeliger89875e92006-10-10 17:03:43 -05001040static int tsec_recv(struct eth_device *dev)
wdenk42d1f032003-10-15 23:53:47 +00001041{
1042 int length;
wdenk97d80fc2004-06-09 00:34:46 +00001043 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1044 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +00001045
Jon Loeliger89875e92006-10-10 17:03:43 -05001046 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenk42d1f032003-10-15 23:53:47 +00001047
1048 length = rtx.rxbd[rxIdx].length;
1049
1050 /* Send the packet up if there were no errors */
1051 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
1052 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenk97d80fc2004-06-09 00:34:46 +00001053 } else {
1054 printf("Got error %x\n",
Jon Loeliger89875e92006-10-10 17:03:43 -05001055 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk42d1f032003-10-15 23:53:47 +00001056 }
1057
1058 rtx.rxbd[rxIdx].length = 0;
1059
1060 /* Set the wrap bit if this is the last element in the list */
Jon Loeliger89875e92006-10-10 17:03:43 -05001061 rtx.rxbd[rxIdx].status =
1062 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
wdenk42d1f032003-10-15 23:53:47 +00001063
1064 rxIdx = (rxIdx + 1) % PKTBUFSRX;
1065 }
1066
Jon Loeliger89875e92006-10-10 17:03:43 -05001067 if (regs->ievent & IEVENT_BSY) {
wdenk42d1f032003-10-15 23:53:47 +00001068 regs->ievent = IEVENT_BSY;
1069 regs->rstat = RSTAT_CLEAR_RHALT;
1070 }
1071
1072 return -1;
1073
1074}
1075
wdenk97d80fc2004-06-09 00:34:46 +00001076/* Stop the interface */
Jon Loeliger89875e92006-10-10 17:03:43 -05001077static void tsec_halt(struct eth_device *dev)
wdenk42d1f032003-10-15 23:53:47 +00001078{
wdenk97d80fc2004-06-09 00:34:46 +00001079 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1080 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +00001081
1082 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
1083 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
1084
Jon Loeliger89875e92006-10-10 17:03:43 -05001085 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
wdenk42d1f032003-10-15 23:53:47 +00001086
1087 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
1088
wdenk97d80fc2004-06-09 00:34:46 +00001089 /* Shut down the PHY, as needed */
Ben Warren4653f912006-10-26 14:38:25 -04001090 if(priv->phyinfo)
1091 phy_run_commands(priv, priv->phyinfo->shutdown);
wdenk42d1f032003-10-15 23:53:47 +00001092}
wdenk7abf0c52004-04-18 21:45:42 +00001093
Peter Tysere1957ef2009-11-09 13:09:45 -06001094static struct phy_info phy_info_M88E1149S = {
Wolfgang Denk5728be32007-08-06 01:01:49 +02001095 0x1410ca,
1096 "Marvell 88E1149S",
1097 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001098 (struct phy_cmd[]) { /* config */
Wolfgang Denk5728be32007-08-06 01:01:49 +02001099 /* Reset and configure the PHY */
1100 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1101 {0x1d, 0x1f, NULL},
1102 {0x1e, 0x200c, NULL},
1103 {0x1d, 0x5, NULL},
1104 {0x1e, 0x0, NULL},
1105 {0x1e, 0x100, NULL},
1106 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1107 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1108 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1109 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1110 {miim_end,}
1111 },
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001112 (struct phy_cmd[]) { /* startup */
Wolfgang Denk5728be32007-08-06 01:01:49 +02001113 /* Status is read once to clear old link state */
1114 {MIIM_STATUS, miim_read, NULL},
1115 /* Auto-negotiate */
1116 {MIIM_STATUS, miim_read, &mii_parse_sr},
1117 /* Read the status */
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001118 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
Wolfgang Denk5728be32007-08-06 01:01:49 +02001119 {miim_end,}
1120 },
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001121 (struct phy_cmd[]) { /* shutdown */
Wolfgang Denk5728be32007-08-06 01:01:49 +02001122 {miim_end,}
1123 },
Andy Flemingc7e717e2007-08-03 04:05:25 -05001124};
1125
Paul Gortmaker91e25762007-01-16 11:38:14 -05001126/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
Peter Tysere1957ef2009-11-09 13:09:45 -06001127static struct phy_info phy_info_BCM5461S = {
Paul Gortmaker91e25762007-01-16 11:38:14 -05001128 0x02060c1, /* 5461 ID */
1129 "Broadcom BCM5461S",
1130 0, /* not clear to me what minor revisions we can shift away */
1131 (struct phy_cmd[]) { /* config */
1132 /* Reset and configure the PHY */
1133 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1134 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1135 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1136 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1137 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1138 {miim_end,}
1139 },
1140 (struct phy_cmd[]) { /* startup */
1141 /* Status is read once to clear old link state */
1142 {MIIM_STATUS, miim_read, NULL},
1143 /* Auto-negotiate */
1144 {MIIM_STATUS, miim_read, &mii_parse_sr},
1145 /* Read the status */
1146 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1147 {miim_end,}
1148 },
1149 (struct phy_cmd[]) { /* shutdown */
1150 {miim_end,}
1151 },
1152};
1153
Peter Tysere1957ef2009-11-09 13:09:45 -06001154static struct phy_info phy_info_BCM5464S = {
Joe Hammanc3243cf2007-04-30 16:47:28 -05001155 0x02060b1, /* 5464 ID */
1156 "Broadcom BCM5464S",
1157 0, /* not clear to me what minor revisions we can shift away */
1158 (struct phy_cmd[]) { /* config */
1159 /* Reset and configure the PHY */
1160 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1161 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1162 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1163 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1164 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1165 {miim_end,}
1166 },
1167 (struct phy_cmd[]) { /* startup */
1168 /* Status is read once to clear old link state */
1169 {MIIM_STATUS, miim_read, NULL},
1170 /* Auto-negotiate */
1171 {MIIM_STATUS, miim_read, &mii_parse_sr},
1172 /* Read the status */
1173 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1174 {miim_end,}
1175 },
1176 (struct phy_cmd[]) { /* shutdown */
1177 {miim_end,}
1178 },
1179};
1180
Peter Tysere1957ef2009-11-09 13:09:45 -06001181static struct phy_info phy_info_BCM5482S = {
Zach LeRoy091dc9f2009-05-22 10:26:33 -05001182 0x0143bcb,
1183 "Broadcom BCM5482S",
1184 4,
1185 (struct phy_cmd[]) { /* config */
1186 /* Reset and configure the PHY */
1187 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1188 /* Setup read from auxilary control shadow register 7 */
1189 {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
1190 /* Read Misc Control register and or in Ethernet@Wirespeed */
1191 {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
1192 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Peter Tyser8abb8dc2009-11-09 13:09:47 -06001193 /* Initial config/enable of secondary SerDes interface */
1194 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf), NULL},
1195 /* Write intial value to secondary SerDes Contol */
1196 {MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_SSD | 0, NULL},
1197 {MIIM_BCM54XX_EXP_DATA, MIIM_CONTROL_RESTART, NULL},
1198 /* Enable copper/fiber auto-detect */
1199 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201)},
Zach LeRoy091dc9f2009-05-22 10:26:33 -05001200 {miim_end,}
1201 },
1202 (struct phy_cmd[]) { /* startup */
1203 /* Status is read once to clear old link state */
1204 {MIIM_STATUS, miim_read, NULL},
Peter Tyser8abb8dc2009-11-09 13:09:47 -06001205 /* Determine copper/fiber, auto-negotiate, and read the result */
1206 {MIIM_STATUS, miim_read, &mii_parse_BCM5482_sr},
Zach LeRoy091dc9f2009-05-22 10:26:33 -05001207 {miim_end,}
1208 },
1209 (struct phy_cmd[]) { /* shutdown */
1210 {miim_end,}
1211 },
1212};
1213
Peter Tysere1957ef2009-11-09 13:09:45 -06001214static struct phy_info phy_info_M88E1011S = {
wdenk97d80fc2004-06-09 00:34:46 +00001215 0x01410c6,
1216 "Marvell 88E1011S",
1217 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001218 (struct phy_cmd[]) { /* config */
1219 /* Reset and configure the PHY */
1220 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1221 {0x1d, 0x1f, NULL},
1222 {0x1e, 0x200c, NULL},
1223 {0x1d, 0x5, NULL},
1224 {0x1e, 0x0, NULL},
1225 {0x1e, 0x100, NULL},
1226 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1227 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1228 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1229 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1230 {miim_end,}
1231 },
1232 (struct phy_cmd[]) { /* startup */
1233 /* Status is read once to clear old link state */
1234 {MIIM_STATUS, miim_read, NULL},
1235 /* Auto-negotiate */
1236 {MIIM_STATUS, miim_read, &mii_parse_sr},
1237 /* Read the status */
1238 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1239 {miim_end,}
1240 },
1241 (struct phy_cmd[]) { /* shutdown */
1242 {miim_end,}
1243 },
wdenk97d80fc2004-06-09 00:34:46 +00001244};
1245
Peter Tysere1957ef2009-11-09 13:09:45 -06001246static struct phy_info phy_info_M88E1111S = {
wdenk9d46ea42005-03-14 23:56:42 +00001247 0x01410cc,
1248 "Marvell 88E1111S",
1249 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001250 (struct phy_cmd[]) { /* config */
1251 /* Reset and configure the PHY */
1252 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1253 {0x1b, 0x848f, &mii_m88e1111s_setmode},
1254 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
1255 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1256 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1257 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1258 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1259 {miim_end,}
1260 },
1261 (struct phy_cmd[]) { /* startup */
1262 /* Status is read once to clear old link state */
1263 {MIIM_STATUS, miim_read, NULL},
1264 /* Auto-negotiate */
1265 {MIIM_STATUS, miim_read, &mii_parse_sr},
1266 /* Read the status */
1267 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1268 {miim_end,}
1269 },
1270 (struct phy_cmd[]) { /* shutdown */
1271 {miim_end,}
1272 },
wdenk9d46ea42005-03-14 23:56:42 +00001273};
1274
Peter Tysere1957ef2009-11-09 13:09:45 -06001275static struct phy_info phy_info_M88E1118 = {
Ron Madrid290ef642008-05-23 15:37:05 -07001276 0x01410e1,
1277 "Marvell 88E1118",
1278 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001279 (struct phy_cmd[]) { /* config */
Ron Madrid290ef642008-05-23 15:37:05 -07001280 /* Reset and configure the PHY */
1281 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1282 {0x16, 0x0002, NULL}, /* Change Page Number */
1283 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
Ron Madrid12a8b9d2009-01-28 16:17:21 -08001284 {0x16, 0x0003, NULL}, /* Change Page Number */
1285 {0x10, 0x021e, NULL}, /* Adjust LED control */
1286 {0x16, 0x0000, NULL}, /* Change Page Number */
Ron Madrid290ef642008-05-23 15:37:05 -07001287 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1288 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1289 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1290 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1291 {miim_end,}
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001292 },
1293 (struct phy_cmd[]) { /* startup */
Ron Madrid290ef642008-05-23 15:37:05 -07001294 {0x16, 0x0000, NULL}, /* Change Page Number */
1295 /* Status is read once to clear old link state */
1296 {MIIM_STATUS, miim_read, NULL},
1297 /* Auto-negotiate */
Ron Madrid12a8b9d2009-01-28 16:17:21 -08001298 {MIIM_STATUS, miim_read, &mii_parse_sr},
Ron Madrid290ef642008-05-23 15:37:05 -07001299 /* Read the status */
1300 {MIIM_88E1011_PHY_STATUS, miim_read,
1301 &mii_parse_88E1011_psr},
1302 {miim_end,}
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001303 },
1304 (struct phy_cmd[]) { /* shutdown */
Ron Madrid290ef642008-05-23 15:37:05 -07001305 {miim_end,}
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001306 },
Ron Madrid290ef642008-05-23 15:37:05 -07001307};
1308
Sergei Poselenovd23dc392008-06-06 15:52:44 +02001309/*
1310 * Since to access LED register we need do switch the page, we
1311 * do LED configuring in the miim_read-like function as follows
1312 */
Peter Tysere1957ef2009-11-09 13:09:45 -06001313static uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
Sergei Poselenovd23dc392008-06-06 15:52:44 +02001314{
1315 uint pg;
1316
1317 /* Switch the page to access the led register */
1318 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1319 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1320
1321 /* Configure leds */
1322 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1323 MIIM_88E1121_PHY_LED_DEF);
1324
1325 /* Restore the page pointer */
1326 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1327 return 0;
1328}
1329
Peter Tysere1957ef2009-11-09 13:09:45 -06001330static struct phy_info phy_info_M88E1121R = {
Sergei Poselenovd23dc392008-06-06 15:52:44 +02001331 0x01410cb,
1332 "Marvell 88E1121R",
1333 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001334 (struct phy_cmd[]) { /* config */
1335 /* Reset and configure the PHY */
1336 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1337 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1338 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1339 /* Configure leds */
1340 {MIIM_88E1121_PHY_LED_CTRL, miim_read, &mii_88E1121_set_led},
1341 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1342 /* Disable IRQs and de-assert interrupt */
1343 {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
1344 {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
1345 {miim_end,}
1346 },
1347 (struct phy_cmd[]) { /* startup */
1348 /* Status is read once to clear old link state */
1349 {MIIM_STATUS, miim_read, NULL},
1350 {MIIM_STATUS, miim_read, &mii_parse_sr},
1351 {MIIM_STATUS, miim_read, &mii_parse_link},
1352 {miim_end,}
1353 },
1354 (struct phy_cmd[]) { /* shutdown */
1355 {miim_end,}
1356 },
Sergei Poselenovd23dc392008-06-06 15:52:44 +02001357};
1358
Andy Fleming09f3e092006-09-13 10:34:18 -05001359static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1360{
Andy Fleming09f3e092006-09-13 10:34:18 -05001361 uint mii_data = read_phy_reg(priv, mii_reg);
1362
Andy Fleming09f3e092006-09-13 10:34:18 -05001363 /* Setting MIIM_88E1145_PHY_EXT_CR */
1364 if (priv->flags & TSEC_REDUCED)
1365 return mii_data |
Jon Loeliger89875e92006-10-10 17:03:43 -05001366 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming09f3e092006-09-13 10:34:18 -05001367 else
1368 return mii_data;
1369}
1370
1371static struct phy_info phy_info_M88E1145 = {
1372 0x01410cd,
1373 "Marvell 88E1145",
1374 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001375 (struct phy_cmd[]) { /* config */
1376 /* Reset the PHY */
1377 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Andy Fleming7507d562007-05-08 17:23:02 -05001378
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001379 /* Errata E0, E1 */
1380 {29, 0x001b, NULL},
1381 {30, 0x418f, NULL},
1382 {29, 0x0016, NULL},
1383 {30, 0xa2da, NULL},
Andy Fleming09f3e092006-09-13 10:34:18 -05001384
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001385 /* Configure the PHY */
1386 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1387 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1388 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, NULL},
1389 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1390 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1391 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1392 {miim_end,}
1393 },
1394 (struct phy_cmd[]) { /* startup */
1395 /* Status is read once to clear old link state */
1396 {MIIM_STATUS, miim_read, NULL},
1397 /* Auto-negotiate */
1398 {MIIM_STATUS, miim_read, &mii_parse_sr},
1399 {MIIM_88E1111_PHY_LED_CONTROL, MIIM_88E1111_PHY_LED_DIRECT, NULL},
1400 /* Read the Status */
1401 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
1402 {miim_end,}
1403 },
1404 (struct phy_cmd[]) { /* shutdown */
1405 {miim_end,}
1406 },
Andy Fleming09f3e092006-09-13 10:34:18 -05001407};
1408
Peter Tysere1957ef2009-11-09 13:09:45 -06001409static struct phy_info phy_info_cis8204 = {
wdenk97d80fc2004-06-09 00:34:46 +00001410 0x3f11,
1411 "Cicada Cis8204",
1412 6,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001413 (struct phy_cmd[]) { /* config */
1414 /* Override PHY config settings */
1415 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1416 /* Configure some basic stuff */
1417 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1418 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1419 &mii_cis8204_fixled},
1420 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1421 &mii_cis8204_setmode},
1422 {miim_end,}
1423 },
1424 (struct phy_cmd[]) { /* startup */
1425 /* Read the Status (2x to make sure link is right) */
1426 {MIIM_STATUS, miim_read, NULL},
1427 /* Auto-negotiate */
1428 {MIIM_STATUS, miim_read, &mii_parse_sr},
1429 /* Read the status */
1430 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1431 {miim_end,}
1432 },
1433 (struct phy_cmd[]) { /* shutdown */
1434 {miim_end,}
1435 },
wdenk97d80fc2004-06-09 00:34:46 +00001436};
1437
1438/* Cicada 8201 */
Peter Tysere1957ef2009-11-09 13:09:45 -06001439static struct phy_info phy_info_cis8201 = {
wdenk97d80fc2004-06-09 00:34:46 +00001440 0xfc41,
1441 "CIS8201",
1442 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001443 (struct phy_cmd[]) { /* config */
1444 /* Override PHY config settings */
1445 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1446 /* Set up the interface mode */
1447 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1448 /* Configure some basic stuff */
1449 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1450 {miim_end,}
1451 },
1452 (struct phy_cmd[]) { /* startup */
1453 /* Read the Status (2x to make sure link is right) */
1454 {MIIM_STATUS, miim_read, NULL},
1455 /* Auto-negotiate */
1456 {MIIM_STATUS, miim_read, &mii_parse_sr},
1457 /* Read the status */
1458 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1459 {miim_end,}
1460 },
1461 (struct phy_cmd[]) { /* shutdown */
1462 {miim_end,}
1463 },
wdenk97d80fc2004-06-09 00:34:46 +00001464};
Peter Tysere1957ef2009-11-09 13:09:45 -06001465
1466static struct phy_info phy_info_VSC8211 = {
Pieter Henning736323a2009-02-22 23:17:15 -08001467 0xfc4b,
1468 "Vitesse VSC8211",
1469 4,
1470 (struct phy_cmd[]) { /* config */
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001471 /* Override PHY config settings */
1472 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1473 /* Set up the interface mode */
1474 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1475 /* Configure some basic stuff */
1476 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1477 {miim_end,}
1478 },
Pieter Henning736323a2009-02-22 23:17:15 -08001479 (struct phy_cmd[]) { /* startup */
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001480 /* Read the Status (2x to make sure link is right) */
1481 {MIIM_STATUS, miim_read, NULL},
1482 /* Auto-negotiate */
1483 {MIIM_STATUS, miim_read, &mii_parse_sr},
1484 /* Read the status */
1485 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1486 {miim_end,}
1487 },
Pieter Henning736323a2009-02-22 23:17:15 -08001488 (struct phy_cmd[]) { /* shutdown */
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001489 {miim_end,}
Pieter Henning736323a2009-02-22 23:17:15 -08001490 },
1491};
Peter Tysere1957ef2009-11-09 13:09:45 -06001492
1493static struct phy_info phy_info_VSC8244 = {
Jon Loeliger89875e92006-10-10 17:03:43 -05001494 0x3f1b,
1495 "Vitesse VSC8244",
1496 6,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001497 (struct phy_cmd[]) { /* config */
1498 /* Override PHY config settings */
1499 /* Configure some basic stuff */
1500 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1501 {miim_end,}
1502 },
1503 (struct phy_cmd[]) { /* startup */
1504 /* Read the Status (2x to make sure link is right) */
1505 {MIIM_STATUS, miim_read, NULL},
1506 /* Auto-negotiate */
1507 {MIIM_STATUS, miim_read, &mii_parse_sr},
1508 /* Read the status */
1509 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1510 {miim_end,}
1511 },
1512 (struct phy_cmd[]) { /* shutdown */
1513 {miim_end,}
1514 },
Jon Loeligerdebb7352006-04-26 17:58:56 -05001515};
wdenk97d80fc2004-06-09 00:34:46 +00001516
Peter Tysere1957ef2009-11-09 13:09:45 -06001517static struct phy_info phy_info_VSC8641 = {
Poonam Aggrwalb7fe25d2009-07-02 16:15:13 +05301518 0x7043,
1519 "Vitesse VSC8641",
1520 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001521 (struct phy_cmd[]) { /* config */
1522 /* Configure some basic stuff */
1523 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1524 {miim_end,}
1525 },
1526 (struct phy_cmd[]) { /* startup */
1527 /* Read the Status (2x to make sure link is right) */
1528 {MIIM_STATUS, miim_read, NULL},
1529 /* Auto-negotiate */
1530 {MIIM_STATUS, miim_read, &mii_parse_sr},
1531 /* Read the status */
1532 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1533 {miim_end,}
1534 },
1535 (struct phy_cmd[]) { /* shutdown */
1536 {miim_end,}
1537 },
Poonam Aggrwalb7fe25d2009-07-02 16:15:13 +05301538};
1539
Peter Tysere1957ef2009-11-09 13:09:45 -06001540static struct phy_info phy_info_VSC8221 = {
Poonam Aggrwalb7fe25d2009-07-02 16:15:13 +05301541 0xfc55,
1542 "Vitesse VSC8221",
1543 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001544 (struct phy_cmd[]) { /* config */
1545 /* Configure some basic stuff */
1546 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1547 {miim_end,}
1548 },
1549 (struct phy_cmd[]) { /* startup */
1550 /* Read the Status (2x to make sure link is right) */
1551 {MIIM_STATUS, miim_read, NULL},
1552 /* Auto-negotiate */
1553 {MIIM_STATUS, miim_read, &mii_parse_sr},
1554 /* Read the status */
1555 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1556 {miim_end,}
1557 },
1558 (struct phy_cmd[]) { /* shutdown */
1559 {miim_end,}
1560 },
Poonam Aggrwalb7fe25d2009-07-02 16:15:13 +05301561};
1562
Peter Tysere1957ef2009-11-09 13:09:45 -06001563static struct phy_info phy_info_VSC8601 = {
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001564 0x00007042,
1565 "Vitesse VSC8601",
1566 4,
1567 (struct phy_cmd[]) { /* config */
1568 /* Override PHY config settings */
1569 /* Configure some basic stuff */
1570 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001571#ifdef CONFIG_SYS_VSC8601_SKEWFIX
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001572 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001573#if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001574 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1575#define VSC8101_SKEW \
1576 (CONFIG_SYS_VSC8601_SKEW_TX << 14) | (CONFIG_SYS_VSC8601_SKEW_RX << 12)
1577 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1578 {MIIM_EXT_PAGE_ACCESS,0,NULL},
Andre Schwarz9acde122008-04-29 19:18:32 +02001579#endif
Tor Krill2d934ea2008-03-28 15:29:45 +01001580#endif
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001581 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1582 {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
1583 {miim_end,}
1584 },
1585 (struct phy_cmd[]) { /* startup */
1586 /* Read the Status (2x to make sure link is right) */
1587 {MIIM_STATUS, miim_read, NULL},
1588 /* Auto-negotiate */
1589 {MIIM_STATUS, miim_read, &mii_parse_sr},
1590 /* Read the status */
1591 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1592 {miim_end,}
1593 },
1594 (struct phy_cmd[]) { /* shutdown */
1595 {miim_end,}
1596 },
Tor Krill2d934ea2008-03-28 15:29:45 +01001597};
1598
Peter Tysere1957ef2009-11-09 13:09:45 -06001599static struct phy_info phy_info_dm9161 = {
wdenk97d80fc2004-06-09 00:34:46 +00001600 0x0181b88,
1601 "Davicom DM9161E",
1602 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001603 (struct phy_cmd[]) { /* config */
1604 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1605 /* Do not bypass the scrambler/descrambler */
1606 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1607 /* Clear 10BTCSR to default */
1608 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
1609 /* Configure some basic stuff */
1610 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1611 /* Restart Auto Negotiation */
1612 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1613 {miim_end,}
1614 },
1615 (struct phy_cmd[]) { /* startup */
1616 /* Status is read once to clear old link state */
1617 {MIIM_STATUS, miim_read, NULL},
1618 /* Auto-negotiate */
1619 {MIIM_STATUS, miim_read, &mii_parse_sr},
1620 /* Read the status */
1621 {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
1622 {miim_end,}
1623 },
1624 (struct phy_cmd[]) { /* shutdown */
1625 {miim_end,}
1626 },
wdenk97d80fc2004-06-09 00:34:46 +00001627};
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001628
David Updegraffaf1c2b82007-04-20 14:34:48 -05001629/* a generic flavor. */
Peter Tysere1957ef2009-11-09 13:09:45 -06001630static struct phy_info phy_info_generic = {
David Updegraffaf1c2b82007-04-20 14:34:48 -05001631 0,
1632 "Unknown/Generic PHY",
1633 32,
1634 (struct phy_cmd[]) { /* config */
1635 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1636 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1637 {miim_end,}
1638 },
1639 (struct phy_cmd[]) { /* startup */
1640 {PHY_BMSR, miim_read, NULL},
1641 {PHY_BMSR, miim_read, &mii_parse_sr},
1642 {PHY_BMSR, miim_read, &mii_parse_link},
1643 {miim_end,}
1644 },
1645 (struct phy_cmd[]) { /* shutdown */
1646 {miim_end,}
1647 }
1648};
1649
Peter Tysere1957ef2009-11-09 13:09:45 -06001650static uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
wdenk3dd7f0f2005-04-04 23:43:44 +00001651{
wdenk3c2b3d42005-04-05 23:32:21 +00001652 unsigned int speed;
1653 if (priv->link) {
1654 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenk3dd7f0f2005-04-04 23:43:44 +00001655
wdenk3c2b3d42005-04-05 23:32:21 +00001656 switch (speed) {
1657 case MIIM_LXT971_SR2_10HDX:
1658 priv->speed = 10;
1659 priv->duplexity = 0;
1660 break;
1661 case MIIM_LXT971_SR2_10FDX:
1662 priv->speed = 10;
1663 priv->duplexity = 1;
1664 break;
1665 case MIIM_LXT971_SR2_100HDX:
1666 priv->speed = 100;
1667 priv->duplexity = 0;
urwithsughosh@gmail.comcd2d1602007-09-10 14:54:56 -04001668 break;
wdenk3c2b3d42005-04-05 23:32:21 +00001669 default:
1670 priv->speed = 100;
1671 priv->duplexity = 1;
wdenk3c2b3d42005-04-05 23:32:21 +00001672 }
1673 } else {
1674 priv->speed = 0;
1675 priv->duplexity = 0;
1676 }
wdenk3dd7f0f2005-04-04 23:43:44 +00001677
wdenk3c2b3d42005-04-05 23:32:21 +00001678 return 0;
wdenk3dd7f0f2005-04-04 23:43:44 +00001679}
1680
wdenk9d46ea42005-03-14 23:56:42 +00001681static struct phy_info phy_info_lxt971 = {
1682 0x0001378e,
1683 "LXT971",
1684 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001685 (struct phy_cmd[]) { /* config */
1686 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1687 {miim_end,}
1688 },
1689 (struct phy_cmd[]) { /* startup - enable interrupts */
1690 /* { 0x12, 0x00f2, NULL }, */
1691 {MIIM_STATUS, miim_read, NULL},
1692 {MIIM_STATUS, miim_read, &mii_parse_sr},
1693 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1694 {miim_end,}
1695 },
1696 (struct phy_cmd[]) { /* shutdown - disable interrupts */
1697 {miim_end,}
1698 },
wdenk9d46ea42005-03-14 23:56:42 +00001699};
1700
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001701/* Parse the DP83865's link and auto-neg status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -05001702 * information
1703 */
Peter Tysere1957ef2009-11-09 13:09:45 -06001704static uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001705{
1706 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1707
1708 case MIIM_DP83865_SPD_1000:
1709 priv->speed = 1000;
1710 break;
1711
1712 case MIIM_DP83865_SPD_100:
1713 priv->speed = 100;
1714 break;
1715
1716 default:
1717 priv->speed = 10;
1718 break;
1719
1720 }
1721
1722 if (mii_reg & MIIM_DP83865_DPX_FULL)
1723 priv->duplexity = 1;
1724 else
1725 priv->duplexity = 0;
1726
1727 return 0;
1728}
1729
Peter Tysere1957ef2009-11-09 13:09:45 -06001730static struct phy_info phy_info_dp83865 = {
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001731 0x20005c7,
1732 "NatSemi DP83865",
1733 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001734 (struct phy_cmd[]) { /* config */
1735 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1736 {miim_end,}
1737 },
1738 (struct phy_cmd[]) { /* startup */
1739 /* Status is read once to clear old link state */
1740 {MIIM_STATUS, miim_read, NULL},
1741 /* Auto-negotiate */
1742 {MIIM_STATUS, miim_read, &mii_parse_sr},
1743 /* Read the link and auto-neg status */
1744 {MIIM_DP83865_LANR, miim_read, &mii_parse_dp83865_lanr},
1745 {miim_end,}
1746 },
1747 (struct phy_cmd[]) { /* shutdown */
1748 {miim_end,}
1749 },
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001750};
1751
Peter Tysere1957ef2009-11-09 13:09:45 -06001752static struct phy_info phy_info_rtl8211b = {
Dave Liu18ee3202008-01-11 18:45:28 +08001753 0x001cc91,
1754 "RealTek RTL8211B",
1755 4,
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001756 (struct phy_cmd[]) { /* config */
Dave Liu18ee3202008-01-11 18:45:28 +08001757 /* Reset and configure the PHY */
1758 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1759 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1760 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1761 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1762 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1763 {miim_end,}
1764 },
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001765 (struct phy_cmd[]) { /* startup */
Dave Liu18ee3202008-01-11 18:45:28 +08001766 /* Status is read once to clear old link state */
1767 {MIIM_STATUS, miim_read, NULL},
1768 /* Auto-negotiate */
1769 {MIIM_STATUS, miim_read, &mii_parse_sr},
1770 /* Read the status */
1771 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1772 {miim_end,}
1773 },
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001774 (struct phy_cmd[]) { /* shutdown */
Dave Liu18ee3202008-01-11 18:45:28 +08001775 {miim_end,}
1776 },
1777};
1778
Peter Tysere1957ef2009-11-09 13:09:45 -06001779static struct phy_info *phy_info[] = {
wdenk97d80fc2004-06-09 00:34:46 +00001780 &phy_info_cis8204,
Timur Tabi2ad6b512006-10-31 18:44:42 -06001781 &phy_info_cis8201,
Paul Gortmaker91e25762007-01-16 11:38:14 -05001782 &phy_info_BCM5461S,
Joe Hammanc3243cf2007-04-30 16:47:28 -05001783 &phy_info_BCM5464S,
Zach LeRoy091dc9f2009-05-22 10:26:33 -05001784 &phy_info_BCM5482S,
wdenk97d80fc2004-06-09 00:34:46 +00001785 &phy_info_M88E1011S,
wdenk9d46ea42005-03-14 23:56:42 +00001786 &phy_info_M88E1111S,
Ron Madrid290ef642008-05-23 15:37:05 -07001787 &phy_info_M88E1118,
Sergei Poselenovd23dc392008-06-06 15:52:44 +02001788 &phy_info_M88E1121R,
Andy Fleming09f3e092006-09-13 10:34:18 -05001789 &phy_info_M88E1145,
Wolfgang Denk5728be32007-08-06 01:01:49 +02001790 &phy_info_M88E1149S,
wdenk97d80fc2004-06-09 00:34:46 +00001791 &phy_info_dm9161,
wdenk9d46ea42005-03-14 23:56:42 +00001792 &phy_info_lxt971,
Pieter Henning736323a2009-02-22 23:17:15 -08001793 &phy_info_VSC8211,
Jon Loeligerdebb7352006-04-26 17:58:56 -05001794 &phy_info_VSC8244,
Tor Krill2d934ea2008-03-28 15:29:45 +01001795 &phy_info_VSC8601,
Poonam Aggrwalb7fe25d2009-07-02 16:15:13 +05301796 &phy_info_VSC8641,
1797 &phy_info_VSC8221,
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001798 &phy_info_dp83865,
Dave Liu18ee3202008-01-11 18:45:28 +08001799 &phy_info_rtl8211b,
Paul Gortmaker04523522009-03-09 18:07:53 -05001800 &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
wdenk97d80fc2004-06-09 00:34:46 +00001801 NULL
1802};
1803
wdenk97d80fc2004-06-09 00:34:46 +00001804/* Grab the identifier of the device's PHY, and search through
wdenk9d46ea42005-03-14 23:56:42 +00001805 * all of the known PHYs to see if one matches. If so, return
Jon Loeliger89875e92006-10-10 17:03:43 -05001806 * it, if not, return NULL
1807 */
Peter Tysere1957ef2009-11-09 13:09:45 -06001808static struct phy_info *get_phy_info(struct eth_device *dev)
wdenk97d80fc2004-06-09 00:34:46 +00001809{
1810 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1811 uint phy_reg, phy_ID;
1812 int i;
1813 struct phy_info *theInfo = NULL;
1814
1815 /* Grab the bits from PHYIR1, and put them in the upper half */
1816 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1817 phy_ID = (phy_reg & 0xffff) << 16;
1818
1819 /* Grab the bits from PHYIR2, and put them in the lower half */
1820 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1821 phy_ID |= (phy_reg & 0xffff);
1822
1823 /* loop through all the known PHY types, and find one that */
1824 /* matches the ID we read from the PHY. */
Jon Loeliger89875e92006-10-10 17:03:43 -05001825 for (i = 0; phy_info[i]; i++) {
Andy Fleming2a3cee42007-05-09 00:54:20 -05001826 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
wdenk97d80fc2004-06-09 00:34:46 +00001827 theInfo = phy_info[i];
Andy Fleming2a3cee42007-05-09 00:54:20 -05001828 break;
1829 }
wdenk97d80fc2004-06-09 00:34:46 +00001830 }
1831
Paul Gortmaker04523522009-03-09 18:07:53 -05001832 if (theInfo == &phy_info_generic) {
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001833 printf("%s: No support for PHY id %x; assuming generic\n",
1834 dev->name, phy_ID);
wdenk97d80fc2004-06-09 00:34:46 +00001835 } else {
Stefan Roese5810dc32005-09-21 18:20:22 +02001836 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
wdenk97d80fc2004-06-09 00:34:46 +00001837 }
1838
1839 return theInfo;
1840}
1841
wdenk97d80fc2004-06-09 00:34:46 +00001842/* Execute the given series of commands on the given device's
Jon Loeliger89875e92006-10-10 17:03:43 -05001843 * PHY, running functions as necessary
1844 */
Peter Tysere1957ef2009-11-09 13:09:45 -06001845static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
wdenk97d80fc2004-06-09 00:34:46 +00001846{
1847 int i;
1848 uint result;
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +05301849 volatile tsec_mdio_t *phyregs = priv->phyregs;
wdenk97d80fc2004-06-09 00:34:46 +00001850
1851 phyregs->miimcfg = MIIMCFG_RESET;
1852
1853 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1854
Jon Loeliger89875e92006-10-10 17:03:43 -05001855 while (phyregs->miimind & MIIMIND_BUSY) ;
wdenk97d80fc2004-06-09 00:34:46 +00001856
Jon Loeliger89875e92006-10-10 17:03:43 -05001857 for (i = 0; cmd->mii_reg != miim_end; i++) {
1858 if (cmd->mii_data == miim_read) {
wdenk97d80fc2004-06-09 00:34:46 +00001859 result = read_phy_reg(priv, cmd->mii_reg);
1860
Jon Loeliger89875e92006-10-10 17:03:43 -05001861 if (cmd->funct != NULL)
1862 (*(cmd->funct)) (result, priv);
wdenk97d80fc2004-06-09 00:34:46 +00001863
1864 } else {
Jon Loeliger89875e92006-10-10 17:03:43 -05001865 if (cmd->funct != NULL)
1866 result = (*(cmd->funct)) (cmd->mii_reg, priv);
wdenk97d80fc2004-06-09 00:34:46 +00001867 else
1868 result = cmd->mii_data;
1869
1870 write_phy_reg(priv, cmd->mii_reg, result);
1871
1872 }
1873 cmd++;
1874 }
1875}
1876
Jon Loeligercb51c0b2007-07-09 17:39:42 -05001877#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001878 && !defined(BITBANGMII)
wdenk97d80fc2004-06-09 00:34:46 +00001879
wdenk7abf0c52004-04-18 21:45:42 +00001880/*
1881 * Read a MII PHY register.
1882 *
1883 * Returns:
wdenk97d80fc2004-06-09 00:34:46 +00001884 * 0 on success
wdenk7abf0c52004-04-18 21:45:42 +00001885 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001886static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -05001887 unsigned char reg, unsigned short *value)
wdenk7abf0c52004-04-18 21:45:42 +00001888{
wdenk97d80fc2004-06-09 00:34:46 +00001889 unsigned short ret;
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +00001890 struct tsec_private *priv = privlist[0];
wdenk7abf0c52004-04-18 21:45:42 +00001891
Jon Loeliger89875e92006-10-10 17:03:43 -05001892 if (NULL == priv) {
wdenk97d80fc2004-06-09 00:34:46 +00001893 printf("Can't read PHY at address %d\n", addr);
1894 return -1;
1895 }
1896
Andy Fleming2abe3612008-08-31 16:33:27 -05001897 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
wdenk97d80fc2004-06-09 00:34:46 +00001898 *value = ret;
wdenk7abf0c52004-04-18 21:45:42 +00001899
1900 return 0;
1901}
1902
1903/*
1904 * Write a MII PHY register.
1905 *
1906 * Returns:
wdenk97d80fc2004-06-09 00:34:46 +00001907 * 0 on success
wdenk7abf0c52004-04-18 21:45:42 +00001908 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001909static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -05001910 unsigned char reg, unsigned short value)
wdenk7abf0c52004-04-18 21:45:42 +00001911{
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +00001912 struct tsec_private *priv = privlist[0];
wdenk7abf0c52004-04-18 21:45:42 +00001913
Jon Loeliger89875e92006-10-10 17:03:43 -05001914 if (NULL == priv) {
wdenk97d80fc2004-06-09 00:34:46 +00001915 printf("Can't write PHY at address %d\n", addr);
1916 return -1;
1917 }
1918
Andy Fleming2abe3612008-08-31 16:33:27 -05001919 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
wdenk7abf0c52004-04-18 21:45:42 +00001920
1921 return 0;
1922}
wdenk97d80fc2004-06-09 00:34:46 +00001923
Jon Loeligercb51c0b2007-07-09 17:39:42 -05001924#endif
wdenk97d80fc2004-06-09 00:34:46 +00001925
David Updegraff53a5c422007-06-11 10:41:07 -05001926#ifdef CONFIG_MCAST_TFTP
1927
1928/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1929
1930/* Set the appropriate hash bit for the given addr */
1931
1932/* The algorithm works like so:
1933 * 1) Take the Destination Address (ie the multicast address), and
1934 * do a CRC on it (little endian), and reverse the bits of the
1935 * result.
1936 * 2) Use the 8 most significant bits as a hash into a 256-entry
1937 * table. The table is controlled through 8 32-bit registers:
1938 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1939 * gaddr7. This means that the 3 most significant bits in the
1940 * hash index which gaddr register to use, and the 5 other bits
1941 * indicate which bit (assuming an IBM numbering scheme, which
1942 * for PowerPC (tm) is usually the case) in the tregister holds
1943 * the entry. */
1944static int
1945tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1946{
Peter Tyserc6dbdfd2009-11-09 13:09:46 -06001947 struct tsec_private *priv = privlist[1];
1948 volatile tsec_t *regs = priv->regs;
1949 volatile u32 *reg_array, value;
1950 u8 result, whichbit, whichreg;
David Updegraff53a5c422007-06-11 10:41:07 -05001951
1952 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1953 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1954 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1955 value = (1 << (31-whichbit));
1956
1957 reg_array = &(regs->hash.gaddr0);
1958
1959 if (set) {
1960 reg_array[whichreg] |= value;
1961 } else {
1962 reg_array[whichreg] &= ~value;
1963 }
1964 return 0;
1965}
1966#endif /* Multicast TFTP ? */