blob: a3857b3bbf380cffff9251222437dc98173c8bcd [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 *
Mingkai Hua65e6102011-01-27 12:52:45 +08008 * Copyright 2004-2011 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
Andy Flemingfecff2b2008-08-31 16:33:26 -050047/* Default initializations for TSEC controllers. */
48
49static struct tsec_info_struct tsec_info[] = {
50#ifdef CONFIG_TSEC1
51 STD_TSEC_INFO(1), /* TSEC1 */
52#endif
53#ifdef CONFIG_TSEC2
54 STD_TSEC_INFO(2), /* TSEC2 */
55#endif
56#ifdef CONFIG_MPC85XX_FEC
57 {
58 .regs = (tsec_t *)(TSEC_BASE_ADDR + 0x2000),
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +053059 .miiregs = (tsec_mdio_t *)(MDIO_BASE_ADDR),
Andy Flemingfecff2b2008-08-31 16:33:26 -050060 .devname = CONFIG_MPC85XX_FEC_NAME,
61 .phyaddr = FEC_PHY_ADDR,
62 .flags = FEC_FLAGS
63 }, /* FEC */
64#endif
65#ifdef CONFIG_TSEC3
66 STD_TSEC_INFO(3), /* TSEC3 */
67#endif
68#ifdef CONFIG_TSEC4
69 STD_TSEC_INFO(4), /* TSEC4 */
70#endif
71};
72
Andy Flemingac65e072008-08-31 16:33:27 -050073/* Writes the given phy's reg with value, using the specified MDIO regs */
Mingkai Hua65e6102011-01-27 12:52:45 +080074static void tsec_local_mdio_write(tsec_mdio_t *phyregs, uint addr,
Andy Flemingac65e072008-08-31 16:33:27 -050075 uint reg, uint value)
wdenka445ddf2004-06-09 00:34:46 +000076{
Jon Loeligerb7ced082006-10-10 17:03:43 -050077 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +000078
Mingkai Hua65e6102011-01-27 12:52:45 +080079 out_be32(&phyregs->miimadd, (addr << 8) | reg);
80 out_be32(&phyregs->miimcon, value);
wdenka445ddf2004-06-09 00:34:46 +000081
Jon Loeligerb7ced082006-10-10 17:03:43 -050082 timeout = 1000000;
Mingkai Hua65e6102011-01-27 12:52:45 +080083 while ((in_be32(&phyregs->miimind) & MIIMIND_BUSY) && timeout--)
84 ;
wdenk9c53f402003-10-15 23:53:47 +000085}
86
Andy Flemingac65e072008-08-31 16:33:27 -050087/* Provide the default behavior of writing the PHY of this ethernet device */
Peter Tyser4ef03c02009-11-09 13:09:46 -060088#define write_phy_reg(priv, regnum, value) \
89 tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
michael.firth@bt.com08384842008-01-16 11:40:51 +000090
wdenka445ddf2004-06-09 00:34:46 +000091/* Reads register regnum on the device's PHY through the
Andy Flemingac65e072008-08-31 16:33:27 -050092 * specified registers. It lowers and raises the read
wdenka445ddf2004-06-09 00:34:46 +000093 * command, and waits for the data to become valid (miimind
94 * notvalid bit cleared), and the bus to cease activity (miimind
95 * busy bit cleared), and then returns the value
96 */
Mingkai Hua65e6102011-01-27 12:52:45 +080097static uint tsec_local_mdio_read(tsec_mdio_t *phyregs, uint phyid, uint regnum)
wdenk9c53f402003-10-15 23:53:47 +000098{
99 uint value;
100
wdenka445ddf2004-06-09 00:34:46 +0000101 /* Put the address of the phy, and the register
102 * number into MIIMADD */
Mingkai Hua65e6102011-01-27 12:52:45 +0800103 out_be32(&phyregs->miimadd, (phyid << 8) | regnum);
wdenk9c53f402003-10-15 23:53:47 +0000104
105 /* Clear the command register, and wait */
Mingkai Hua65e6102011-01-27 12:52:45 +0800106 out_be32(&phyregs->miimcom, 0);
wdenk9c53f402003-10-15 23:53:47 +0000107
108 /* Initiate a read command, and wait */
Mingkai Hua65e6102011-01-27 12:52:45 +0800109 out_be32(&phyregs->miimcom, MIIM_READ_COMMAND);
wdenk9c53f402003-10-15 23:53:47 +0000110
111 /* Wait for the the indication that the read is done */
Mingkai Hua65e6102011-01-27 12:52:45 +0800112 while ((in_be32(&phyregs->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY)))
113 ;
wdenk9c53f402003-10-15 23:53:47 +0000114
115 /* Grab the value read from the PHY */
Mingkai Hua65e6102011-01-27 12:52:45 +0800116 value = in_be32(&phyregs->miimstat);
wdenk9c53f402003-10-15 23:53:47 +0000117
118 return value;
119}
120
michael.firth@bt.com08384842008-01-16 11:40:51 +0000121/* #define to provide old read_phy_reg functionality without duplicating code */
Peter Tyser4ef03c02009-11-09 13:09:46 -0600122#define read_phy_reg(priv,regnum) \
123 tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
Andy Flemingac65e072008-08-31 16:33:27 -0500124
125#define TBIANA_SETTINGS ( \
126 TBIANA_ASYMMETRIC_PAUSE \
127 | TBIANA_SYMMETRIC_PAUSE \
128 | TBIANA_FULL_DUPLEX \
129 )
130
Felix Radensky27f98e02010-06-28 01:57:39 +0300131/* By default force the TBI PHY into 1000Mbps full duplex when in SGMII mode */
132#ifndef CONFIG_TSEC_TBICR_SETTINGS
Kumar Galac1457f92010-12-01 22:55:54 -0600133#define CONFIG_TSEC_TBICR_SETTINGS ( \
Andy Flemingac65e072008-08-31 16:33:27 -0500134 TBICR_PHY_RESET \
Kumar Galac1457f92010-12-01 22:55:54 -0600135 | TBICR_ANEG_ENABLE \
Andy Flemingac65e072008-08-31 16:33:27 -0500136 | TBICR_FULL_DUPLEX \
137 | TBICR_SPEED1_SET \
138 )
Felix Radensky27f98e02010-06-28 01:57:39 +0300139#endif /* CONFIG_TSEC_TBICR_SETTINGS */
Peter Tyser583c1f42009-11-03 17:52:07 -0600140
Andy Flemingac65e072008-08-31 16:33:27 -0500141/* Configure the TBI for SGMII operation */
142static void tsec_configure_serdes(struct tsec_private *priv)
143{
Peter Tyser4ef03c02009-11-09 13:09:46 -0600144 /* Access TBI PHY registers at given TSEC register offset as opposed
145 * to the register offset used for external PHY accesses */
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530146 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_ANA,
Andy Flemingac65e072008-08-31 16:33:27 -0500147 TBIANA_SETTINGS);
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530148 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_TBICON,
Andy Flemingac65e072008-08-31 16:33:27 -0500149 TBICON_CLK_SELECT);
Sandeep Gopalpetb5541ef2009-10-31 00:35:04 +0530150 tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_CR,
Kumar Galac1457f92010-12-01 22:55:54 -0600151 CONFIG_TSEC_TBICR_SETTINGS);
Andy Flemingac65e072008-08-31 16:33:27 -0500152}
michael.firth@bt.com08384842008-01-16 11:40:51 +0000153
Jon Loeligerb7ced082006-10-10 17:03:43 -0500154/*
155 * Returns which value to write to the control register.
156 * For 10/100, the value is slightly different
157 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600158static uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000159{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500160 if (priv->flags & TSEC_GIGABIT)
wdenka445ddf2004-06-09 00:34:46 +0000161 return MIIM_CONTROL_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000162 else
wdenka445ddf2004-06-09 00:34:46 +0000163 return MIIM_CR_INIT;
164}
wdenk9c53f402003-10-15 23:53:47 +0000165
Peter Tyser4c84fd52009-02-04 15:14:05 -0600166/*
167 * Wait for auto-negotiation to complete, then determine link
Jon Loeligerb7ced082006-10-10 17:03:43 -0500168 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600169static uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000170{
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200171 /*
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500172 * Wait if the link is up, and autonegotiation is in progress
173 * (ie - we're capable and it's not done)
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200174 */
175 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Mike Frysingerd63ee712010-12-23 15:40:12 -0500176 if ((mii_reg & BMSR_ANEGCAPABLE) && !(mii_reg & BMSR_ANEGCOMPLETE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200177 int i = 0;
wdenk9c53f402003-10-15 23:53:47 +0000178
Jon Loeligerb7ced082006-10-10 17:03:43 -0500179 puts("Waiting for PHY auto negotiation to complete");
Mike Frysingerd63ee712010-12-23 15:40:12 -0500180 while (!(mii_reg & BMSR_ANEGCOMPLETE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200181 /*
182 * Timeout reached ?
183 */
184 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500185 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200186 priv->link = 0;
Jin Zhengxiong-R64188487d2232006-06-27 18:12:23 +0800187 return 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200188 }
wdenk9c53f402003-10-15 23:53:47 +0000189
Kim Phillipsae4dd972009-08-24 14:32:26 -0500190 if (ctrlc()) {
191 puts("user interrupt!\n");
192 priv->link = 0;
193 return -EINTR;
194 }
195
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200196 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500197 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200198 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500199 udelay(1000); /* 1 ms */
wdenka445ddf2004-06-09 00:34:46 +0000200 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200201 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500202 puts(" done\n");
Peter Tyser4c84fd52009-02-04 15:14:05 -0600203
204 /* Link status bit is latched low, read it again */
205 mii_reg = read_phy_reg(priv, MIIM_STATUS);
206
Jon Loeligerb7ced082006-10-10 17:03:43 -0500207 udelay(500000); /* another 500 ms (results in faster booting) */
wdenk9c53f402003-10-15 23:53:47 +0000208 }
209
Peter Tyser4c84fd52009-02-04 15:14:05 -0600210 priv->link = mii_reg & MIIM_STATUS_LINK ? 1 : 0;
211
wdenka445ddf2004-06-09 00:34:46 +0000212 return 0;
213}
214
David Updegraff0451b012007-04-20 14:34:48 -0500215/* Generic function which updates the speed and duplex. If
216 * autonegotiation is enabled, it uses the AND of the link
217 * partner's advertised capabilities and our advertised
218 * capabilities. If autonegotiation is disabled, we use the
219 * appropriate bits in the control register.
220 *
221 * Stolen from Linux's mii.c and phy_device.c
222 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600223static uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
David Updegraff0451b012007-04-20 14:34:48 -0500224{
225 /* We're using autonegotiation */
Mike Frysingerd63ee712010-12-23 15:40:12 -0500226 if (mii_reg & BMSR_ANEGCAPABLE) {
David Updegraff0451b012007-04-20 14:34:48 -0500227 uint lpa = 0;
228 uint gblpa = 0;
229
230 /* Check for gigabit capability */
Mike Frysingerd63ee712010-12-23 15:40:12 -0500231 if (mii_reg & BMSR_ERCAP) {
David Updegraff0451b012007-04-20 14:34:48 -0500232 /* We want a list of states supported by
233 * both PHYs in the link
234 */
Mike Frysingerd63ee712010-12-23 15:40:12 -0500235 gblpa = read_phy_reg(priv, MII_STAT1000);
236 gblpa &= read_phy_reg(priv, MII_CTRL1000) << 2;
David Updegraff0451b012007-04-20 14:34:48 -0500237 }
238
239 /* Set the baseline so we only have to set them
240 * if they're different
241 */
242 priv->speed = 10;
243 priv->duplexity = 0;
244
245 /* Check the gigabit fields */
246 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
247 priv->speed = 1000;
248
249 if (gblpa & PHY_1000BTSR_1000FD)
250 priv->duplexity = 1;
251
252 /* We're done! */
253 return 0;
254 }
255
Mike Frysingerd63ee712010-12-23 15:40:12 -0500256 lpa = read_phy_reg(priv, MII_ADVERTISE);
257 lpa &= read_phy_reg(priv, MII_LPA);
David Updegraff0451b012007-04-20 14:34:48 -0500258
Mike Frysingerd63ee712010-12-23 15:40:12 -0500259 if (lpa & (LPA_100FULL | LPA_100HALF)) {
David Updegraff0451b012007-04-20 14:34:48 -0500260 priv->speed = 100;
261
Mike Frysingerd63ee712010-12-23 15:40:12 -0500262 if (lpa & LPA_100FULL)
David Updegraff0451b012007-04-20 14:34:48 -0500263 priv->duplexity = 1;
264
Mike Frysingerd63ee712010-12-23 15:40:12 -0500265 } else if (lpa & LPA_10FULL)
David Updegraff0451b012007-04-20 14:34:48 -0500266 priv->duplexity = 1;
267 } else {
Mike Frysingerd63ee712010-12-23 15:40:12 -0500268 uint bmcr = read_phy_reg(priv, MII_BMCR);
David Updegraff0451b012007-04-20 14:34:48 -0500269
270 priv->speed = 10;
271 priv->duplexity = 0;
272
Mike Frysingerd63ee712010-12-23 15:40:12 -0500273 if (bmcr & BMCR_FULLDPLX)
David Updegraff0451b012007-04-20 14:34:48 -0500274 priv->duplexity = 1;
275
Mike Frysingerd63ee712010-12-23 15:40:12 -0500276 if (bmcr & BMCR_SPEED1000)
David Updegraff0451b012007-04-20 14:34:48 -0500277 priv->speed = 1000;
Mike Frysingerd63ee712010-12-23 15:40:12 -0500278 else if (bmcr & BMCR_SPEED100)
David Updegraff0451b012007-04-20 14:34:48 -0500279 priv->speed = 100;
280 }
281
282 return 0;
283}
284
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500285/*
Zach LeRoyddb7fc72009-05-22 10:26:33 -0500286 * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
287 * circumstances. eg a gigabit TSEC connected to a gigabit switch with
288 * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
289 * link. "Ethernet@Wirespeed" reduces advertised speed until link
290 * can be achieved.
291 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600292static uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv)
Zach LeRoyddb7fc72009-05-22 10:26:33 -0500293{
294 return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010;
295}
296
297/*
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500298 * Parse the BCM54xx status register for speed and duplex information.
299 * The linux sungem_phy has this information, but in a table format.
300 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600301static uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500302{
Peter Tyserf6722902009-11-09 13:09:44 -0600303 /* If there is no link, speed and duplex don't matter */
304 if (!priv->link)
305 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500306
Peter Tyserf6722902009-11-09 13:09:44 -0600307 switch ((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >>
308 MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT) {
309 case 1:
310 priv->duplexity = 0;
311 priv->speed = 10;
312 break;
313 case 2:
314 priv->duplexity = 1;
315 priv->speed = 10;
316 break;
317 case 3:
318 priv->duplexity = 0;
319 priv->speed = 100;
320 break;
321 case 5:
322 priv->duplexity = 1;
323 priv->speed = 100;
324 break;
325 case 6:
326 priv->duplexity = 0;
327 priv->speed = 1000;
328 break;
329 case 7:
330 priv->duplexity = 1;
331 priv->speed = 1000;
332 break;
333 default:
334 printf("Auto-neg error, defaulting to 10BT/HD\n");
335 priv->duplexity = 0;
336 priv->speed = 10;
337 break;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500338 }
339
340 return 0;
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600341}
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500342
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600343/*
344 * Find out if PHY is in copper or serdes mode by looking at Expansion Reg
345 * 0x42 - "Operating Mode Status Register"
346 */
347static int BCM8482_is_serdes(struct tsec_private *priv)
348{
349 u16 val;
350 int serdes = 0;
351
352 write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_ER | 0x42);
353 val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA);
354
355 switch (val & 0x1f) {
356 case 0x0d: /* RGMII-to-100Base-FX */
357 case 0x0e: /* RGMII-to-SGMII */
358 case 0x0f: /* RGMII-to-SerDes */
359 case 0x12: /* SGMII-to-SerDes */
360 case 0x13: /* SGMII-to-100Base-FX */
361 case 0x16: /* SerDes-to-Serdes */
362 serdes = 1;
363 break;
364 case 0x6: /* RGMII-to-Copper */
365 case 0x14: /* SGMII-to-Copper */
366 case 0x17: /* SerDes-to-Copper */
367 break;
368 default:
369 printf("ERROR, invalid PHY mode (0x%x\n)", val);
370 break;
371 }
372
373 return serdes;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500374}
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600375
376/*
377 * Determine SerDes link speed and duplex from Expansion reg 0x42 "Operating
378 * Mode Status Register"
379 */
380uint mii_parse_BCM5482_serdes_sr(struct tsec_private *priv)
381{
382 u16 val;
383 int i = 0;
384
385 /* Wait 1s for link - Clause 37 autonegotiation happens very fast */
386 while (1) {
387 write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL,
388 MIIM_BCM54XX_EXP_SEL_ER | 0x42);
389 val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA);
390
391 if (val & 0x8000)
392 break;
393
394 if (i++ > 1000) {
395 priv->link = 0;
396 return 1;
397 }
398
399 udelay(1000); /* 1 ms */
400 }
401
402 priv->link = 1;
403 switch ((val >> 13) & 0x3) {
404 case (0x00):
405 priv->speed = 10;
406 break;
407 case (0x01):
408 priv->speed = 100;
409 break;
410 case (0x02):
411 priv->speed = 1000;
412 break;
413 }
414
415 priv->duplexity = (val & 0x1000) == 0x1000;
416
417 return 0;
418}
419
420/*
421 * Figure out if BCM5482 is in serdes or copper mode and determine link
422 * configuration accordingly
423 */
424static uint mii_parse_BCM5482_sr(uint mii_reg, struct tsec_private *priv)
425{
426 if (BCM8482_is_serdes(priv)) {
427 mii_parse_BCM5482_serdes_sr(priv);
Peter Tyser94f63a72009-11-09 13:09:48 -0600428 priv->flags |= TSEC_FIBER;
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600429 } else {
430 /* Wait for auto-negotiation to complete or fail */
431 mii_parse_sr(mii_reg, priv);
432
433 /* Parse BCM54xx copper aux status register */
434 mii_reg = read_phy_reg(priv, MIIM_BCM54xx_AUXSTATUS);
435 mii_parse_BCM54xx_sr(mii_reg, priv);
436 }
437
438 return 0;
439}
440
wdenka445ddf2004-06-09 00:34:46 +0000441/* Parse the 88E1011's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500442 * information
443 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600444static uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000445{
446 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000447
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200448 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
449
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500450 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
451 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200452 int i = 0;
453
Jon Loeligerb7ced082006-10-10 17:03:43 -0500454 puts("Waiting for PHY realtime link");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500455 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
456 /* Timeout reached ? */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200457 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500458 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200459 priv->link = 0;
460 break;
461 }
462
463 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500464 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200465 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500466 udelay(1000); /* 1 ms */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200467 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
468 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500469 puts(" done\n");
470 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500471 } else {
472 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
473 priv->link = 1;
474 else
475 priv->link = 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200476 }
477
Jon Loeligerb7ced082006-10-10 17:03:43 -0500478 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000479 priv->duplexity = 1;
480 else
481 priv->duplexity = 0;
482
Jon Loeligerb7ced082006-10-10 17:03:43 -0500483 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenka445ddf2004-06-09 00:34:46 +0000484
Jon Loeligerb7ced082006-10-10 17:03:43 -0500485 switch (speed) {
486 case MIIM_88E1011_PHYSTAT_GBIT:
487 priv->speed = 1000;
488 break;
489 case MIIM_88E1011_PHYSTAT_100:
490 priv->speed = 100;
491 break;
492 default:
493 priv->speed = 10;
wdenk9c53f402003-10-15 23:53:47 +0000494 }
495
wdenka445ddf2004-06-09 00:34:46 +0000496 return 0;
497}
498
Dave Liua304a282008-01-11 18:45:28 +0800499/* Parse the RTL8211B's status register for speed and duplex
500 * information
501 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600502static uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
Dave Liua304a282008-01-11 18:45:28 +0800503{
504 uint speed;
505
506 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300507 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liua304a282008-01-11 18:45:28 +0800508 int i = 0;
509
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300510 /* in case of timeout ->link is cleared */
511 priv->link = 1;
Dave Liua304a282008-01-11 18:45:28 +0800512 puts("Waiting for PHY realtime link");
513 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
514 /* Timeout reached ? */
515 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
516 puts(" TIMEOUT !\n");
517 priv->link = 0;
518 break;
519 }
520
521 if ((i++ % 1000) == 0) {
522 putc('.');
523 }
524 udelay(1000); /* 1 ms */
525 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
526 }
527 puts(" done\n");
528 udelay(500000); /* another 500 ms (results in faster booting) */
529 } else {
530 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
531 priv->link = 1;
532 else
533 priv->link = 0;
534 }
535
536 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
537 priv->duplexity = 1;
538 else
539 priv->duplexity = 0;
540
541 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
542
543 switch (speed) {
544 case MIIM_RTL8211B_PHYSTAT_GBIT:
545 priv->speed = 1000;
546 break;
547 case MIIM_RTL8211B_PHYSTAT_100:
548 priv->speed = 100;
549 break;
550 default:
551 priv->speed = 10;
552 }
553
554 return 0;
555}
556
wdenka445ddf2004-06-09 00:34:46 +0000557/* Parse the cis8201's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500558 * information
559 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600560static uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000561{
562 uint speed;
563
Jon Loeligerb7ced082006-10-10 17:03:43 -0500564 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000565 priv->duplexity = 1;
566 else
567 priv->duplexity = 0;
568
569 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500570 switch (speed) {
571 case MIIM_CIS8201_AUXCONSTAT_GBIT:
572 priv->speed = 1000;
573 break;
574 case MIIM_CIS8201_AUXCONSTAT_100:
575 priv->speed = 100;
576 break;
577 default:
578 priv->speed = 10;
579 break;
wdenk9c53f402003-10-15 23:53:47 +0000580 }
581
wdenka445ddf2004-06-09 00:34:46 +0000582 return 0;
583}
Jon Loeligerb7ced082006-10-10 17:03:43 -0500584
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500585/* Parse the vsc8244's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500586 * information
587 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600588static uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500589{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500590 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000591
Jon Loeligerb7ced082006-10-10 17:03:43 -0500592 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
593 priv->duplexity = 1;
594 else
595 priv->duplexity = 0;
596
597 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
598 switch (speed) {
599 case MIIM_VSC8244_AUXCONSTAT_GBIT:
600 priv->speed = 1000;
601 break;
602 case MIIM_VSC8244_AUXCONSTAT_100:
603 priv->speed = 100;
604 break;
605 default:
606 priv->speed = 10;
607 break;
608 }
609
610 return 0;
611}
wdenka445ddf2004-06-09 00:34:46 +0000612
613/* Parse the DM9161's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500614 * information
615 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600616static uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000617{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500618 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenka445ddf2004-06-09 00:34:46 +0000619 priv->speed = 100;
620 else
621 priv->speed = 10;
622
Jon Loeligerb7ced082006-10-10 17:03:43 -0500623 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenka445ddf2004-06-09 00:34:46 +0000624 priv->duplexity = 1;
625 else
626 priv->duplexity = 0;
627
628 return 0;
629}
630
Jon Loeligerb7ced082006-10-10 17:03:43 -0500631/*
632 * Hack to write all 4 PHYs with the LED values
633 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600634static uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000635{
636 uint phyid;
Mingkai Hua65e6102011-01-27 12:52:45 +0800637 tsec_mdio_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500638 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000639
Jon Loeligerb7ced082006-10-10 17:03:43 -0500640 for (phyid = 0; phyid < 4; phyid++) {
Mingkai Hua65e6102011-01-27 12:52:45 +0800641 out_be32(&regbase->miimadd, (phyid << 8) | mii_reg);
642 out_be32(&regbase->miimcon, MIIM_CIS8204_SLEDCON_INIT);
wdenka445ddf2004-06-09 00:34:46 +0000643
Jon Loeligerb7ced082006-10-10 17:03:43 -0500644 timeout = 1000000;
Mingkai Hua65e6102011-01-27 12:52:45 +0800645 while ((in_be32(&regbase->miimind) & MIIMIND_BUSY) && timeout--)
646 ;
wdenk9c53f402003-10-15 23:53:47 +0000647 }
wdenk9c53f402003-10-15 23:53:47 +0000648
wdenka445ddf2004-06-09 00:34:46 +0000649 return MIIM_CIS8204_SLEDCON_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000650}
651
Peter Tyser08b2d782009-11-09 13:09:45 -0600652static uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500653{
654 if (priv->flags & TSEC_REDUCED)
655 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
656 else
657 return MIIM_CIS8204_EPHYCON_INIT;
658}
wdenk9c53f402003-10-15 23:53:47 +0000659
Peter Tyser08b2d782009-11-09 13:09:45 -0600660static uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
Dave Liub19ecd32007-09-18 12:37:57 +0800661{
662 uint mii_data = read_phy_reg(priv, mii_reg);
663
664 if (priv->flags & TSEC_REDUCED)
665 mii_data = (mii_data & 0xfff0) | 0x000b;
666 return mii_data;
667}
668
Mingkai Hue0653bf2011-01-27 12:52:46 +0800669static struct phy_info phy_info_M88E1149S = {
670 0x1410ca,
671 "Marvell 88E1149S",
672 4,
673 (struct phy_cmd[]) { /* config */
674 /* Reset and configure the PHY */
675 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
676 {0x1d, 0x1f, NULL},
677 {0x1e, 0x200c, NULL},
678 {0x1d, 0x5, NULL},
679 {0x1e, 0x0, NULL},
680 {0x1e, 0x100, NULL},
681 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
682 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
683 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
684 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
685 {miim_end,}
686 },
687 (struct phy_cmd[]) { /* startup */
688 /* Status is read once to clear old link state */
689 {MIIM_STATUS, miim_read, NULL},
690 /* Auto-negotiate */
691 {MIIM_STATUS, miim_read, &mii_parse_sr},
692 /* Read the status */
693 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
694 {miim_end,}
695 },
696 (struct phy_cmd[]) { /* shutdown */
697 {miim_end,}
698 },
699};
wdenk9c53f402003-10-15 23:53:47 +0000700
Mingkai Hue0653bf2011-01-27 12:52:46 +0800701/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
702static struct phy_info phy_info_BCM5461S = {
703 0x02060c1, /* 5461 ID */
704 "Broadcom BCM5461S",
705 0, /* not clear to me what minor revisions we can shift away */
706 (struct phy_cmd[]) { /* config */
707 /* Reset and configure the PHY */
708 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
709 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
710 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
711 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
712 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
713 {miim_end,}
714 },
715 (struct phy_cmd[]) { /* startup */
716 /* Status is read once to clear old link state */
717 {MIIM_STATUS, miim_read, NULL},
718 /* Auto-negotiate */
719 {MIIM_STATUS, miim_read, &mii_parse_sr},
720 /* Read the status */
721 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
722 {miim_end,}
723 },
724 (struct phy_cmd[]) { /* shutdown */
725 {miim_end,}
726 },
727};
wdenk9c53f402003-10-15 23:53:47 +0000728
Mingkai Hue0653bf2011-01-27 12:52:46 +0800729static struct phy_info phy_info_BCM5464S = {
730 0x02060b1, /* 5464 ID */
731 "Broadcom BCM5464S",
732 0, /* not clear to me what minor revisions we can shift away */
733 (struct phy_cmd[]) { /* config */
Wolfgang Denk15e87572007-08-06 01:01:49 +0200734 /* Reset and configure the PHY */
735 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Wolfgang Denk15e87572007-08-06 01:01:49 +0200736 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
737 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
738 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
739 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
740 {miim_end,}
741 },
Mingkai Hue0653bf2011-01-27 12:52:46 +0800742 (struct phy_cmd[]) { /* startup */
Wolfgang Denk15e87572007-08-06 01:01:49 +0200743 /* Status is read once to clear old link state */
744 {MIIM_STATUS, miim_read, NULL},
745 /* Auto-negotiate */
746 {MIIM_STATUS, miim_read, &mii_parse_sr},
747 /* Read the status */
Mingkai Hue0653bf2011-01-27 12:52:46 +0800748 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
Wolfgang Denk15e87572007-08-06 01:01:49 +0200749 {miim_end,}
750 },
Mingkai Hue0653bf2011-01-27 12:52:46 +0800751 (struct phy_cmd[]) { /* shutdown */
Wolfgang Denk15e87572007-08-06 01:01:49 +0200752 {miim_end,}
753 },
Andy Flemingbee67002007-08-03 04:05:25 -0500754};
755
Mingkai Hue0653bf2011-01-27 12:52:46 +0800756static struct phy_info phy_info_BCM5482S = {
757 0x0143bcb,
758 "Broadcom BCM5482S",
759 4,
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500760 (struct phy_cmd[]) { /* config */
761 /* Reset and configure the PHY */
762 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Mingkai Hue0653bf2011-01-27 12:52:46 +0800763 /* Setup read from auxilary control shadow register 7 */
764 {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
765 /* Read Misc Control register and or in Ethernet@Wirespeed */
766 {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
Joe Hammaned7ad4e2007-04-30 16:47:28 -0500767 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600768 /* Initial config/enable of secondary SerDes interface */
769 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf), NULL},
770 /* Write intial value to secondary SerDes Contol */
771 {MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_SSD | 0, NULL},
772 {MIIM_BCM54XX_EXP_DATA, MIIM_CONTROL_RESTART, NULL},
773 /* Enable copper/fiber auto-detect */
774 {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201)},
Joe Hammaned7ad4e2007-04-30 16:47:28 -0500775 {miim_end,}
776 },
777 (struct phy_cmd[]) { /* startup */
778 /* Status is read once to clear old link state */
779 {MIIM_STATUS, miim_read, NULL},
Peter Tyser3c93d8b2009-11-09 13:09:47 -0600780 /* Determine copper/fiber, auto-negotiate, and read the result */
781 {MIIM_STATUS, miim_read, &mii_parse_BCM5482_sr},
Joe Hammaned7ad4e2007-04-30 16:47:28 -0500782 {miim_end,}
783 },
784 (struct phy_cmd[]) { /* shutdown */
785 {miim_end,}
786 },
787};
788
Peter Tyser08b2d782009-11-09 13:09:45 -0600789static struct phy_info phy_info_M88E1011S = {
wdenka445ddf2004-06-09 00:34:46 +0000790 0x01410c6,
791 "Marvell 88E1011S",
792 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -0600793 (struct phy_cmd[]) { /* config */
794 /* Reset and configure the PHY */
795 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
796 {0x1d, 0x1f, NULL},
797 {0x1e, 0x200c, NULL},
798 {0x1d, 0x5, NULL},
799 {0x1e, 0x0, NULL},
800 {0x1e, 0x100, NULL},
801 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
802 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
803 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
804 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
805 {miim_end,}
806 },
807 (struct phy_cmd[]) { /* startup */
808 /* Status is read once to clear old link state */
809 {MIIM_STATUS, miim_read, NULL},
810 /* Auto-negotiate */
811 {MIIM_STATUS, miim_read, &mii_parse_sr},
812 /* Read the status */
813 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
814 {miim_end,}
815 },
816 (struct phy_cmd[]) { /* shutdown */
817 {miim_end,}
818 },
wdenka445ddf2004-06-09 00:34:46 +0000819};
820
Peter Tyser08b2d782009-11-09 13:09:45 -0600821static struct phy_info phy_info_M88E1111S = {
wdenkbfad55d2005-03-14 23:56:42 +0000822 0x01410cc,
823 "Marvell 88E1111S",
824 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -0600825 (struct phy_cmd[]) { /* config */
826 /* Reset and configure the PHY */
827 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
828 {0x1b, 0x848f, &mii_m88e1111s_setmode},
829 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
830 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
831 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
832 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
833 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
834 {miim_end,}
835 },
836 (struct phy_cmd[]) { /* startup */
837 /* Status is read once to clear old link state */
838 {MIIM_STATUS, miim_read, NULL},
839 /* Auto-negotiate */
840 {MIIM_STATUS, miim_read, &mii_parse_sr},
841 /* Read the status */
842 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
843 {miim_end,}
844 },
845 (struct phy_cmd[]) { /* shutdown */
846 {miim_end,}
847 },
wdenkbfad55d2005-03-14 23:56:42 +0000848};
849
Peter Tyser08b2d782009-11-09 13:09:45 -0600850static struct phy_info phy_info_M88E1118 = {
Ron Madridc1e2b582008-05-23 15:37:05 -0700851 0x01410e1,
852 "Marvell 88E1118",
853 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -0600854 (struct phy_cmd[]) { /* config */
Ron Madridc1e2b582008-05-23 15:37:05 -0700855 /* Reset and configure the PHY */
856 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
857 {0x16, 0x0002, NULL}, /* Change Page Number */
858 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
Ron Madridaa4aac42009-01-28 16:17:21 -0800859 {0x16, 0x0003, NULL}, /* Change Page Number */
860 {0x10, 0x021e, NULL}, /* Adjust LED control */
861 {0x16, 0x0000, NULL}, /* Change Page Number */
Ron Madridc1e2b582008-05-23 15:37:05 -0700862 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
863 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
864 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
865 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
866 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -0600867 },
868 (struct phy_cmd[]) { /* startup */
Ron Madridc1e2b582008-05-23 15:37:05 -0700869 {0x16, 0x0000, NULL}, /* Change Page Number */
870 /* Status is read once to clear old link state */
871 {MIIM_STATUS, miim_read, NULL},
872 /* Auto-negotiate */
Ron Madridaa4aac42009-01-28 16:17:21 -0800873 {MIIM_STATUS, miim_read, &mii_parse_sr},
Ron Madridc1e2b582008-05-23 15:37:05 -0700874 /* Read the status */
875 {MIIM_88E1011_PHY_STATUS, miim_read,
876 &mii_parse_88E1011_psr},
877 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -0600878 },
879 (struct phy_cmd[]) { /* shutdown */
Ron Madridc1e2b582008-05-23 15:37:05 -0700880 {miim_end,}
Peter Tyser4ef03c02009-11-09 13:09:46 -0600881 },
Ron Madridc1e2b582008-05-23 15:37:05 -0700882};
883
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +0200884/*
885 * Since to access LED register we need do switch the page, we
886 * do LED configuring in the miim_read-like function as follows
887 */
Peter Tyser08b2d782009-11-09 13:09:45 -0600888static uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +0200889{
890 uint pg;
891
892 /* Switch the page to access the led register */
893 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
894 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
895
896 /* Configure leds */
897 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
898 MIIM_88E1121_PHY_LED_DEF);
899
900 /* Restore the page pointer */
901 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
902 return 0;
903}
904
Peter Tyser08b2d782009-11-09 13:09:45 -0600905static struct phy_info phy_info_M88E1121R = {
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +0200906 0x01410cb,
907 "Marvell 88E1121R",
908 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -0600909 (struct phy_cmd[]) { /* config */
910 /* Reset and configure the PHY */
911 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
912 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
913 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
914 /* Configure leds */
915 {MIIM_88E1121_PHY_LED_CTRL, miim_read, &mii_88E1121_set_led},
916 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
917 /* Disable IRQs and de-assert interrupt */
918 {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
919 {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
920 {miim_end,}
921 },
922 (struct phy_cmd[]) { /* startup */
923 /* Status is read once to clear old link state */
924 {MIIM_STATUS, miim_read, NULL},
925 {MIIM_STATUS, miim_read, &mii_parse_sr},
926 {MIIM_STATUS, miim_read, &mii_parse_link},
927 {miim_end,}
928 },
929 (struct phy_cmd[]) { /* shutdown */
930 {miim_end,}
931 },
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +0200932};
933
Andy Fleming239e75f2006-09-13 10:34:18 -0500934static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
935{
Andy Fleming239e75f2006-09-13 10:34:18 -0500936 uint mii_data = read_phy_reg(priv, mii_reg);
937
Andy Fleming239e75f2006-09-13 10:34:18 -0500938 /* Setting MIIM_88E1145_PHY_EXT_CR */
939 if (priv->flags & TSEC_REDUCED)
940 return mii_data |
Jon Loeligerb7ced082006-10-10 17:03:43 -0500941 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming239e75f2006-09-13 10:34:18 -0500942 else
943 return mii_data;
944}
945
946static struct phy_info phy_info_M88E1145 = {
947 0x01410cd,
948 "Marvell 88E1145",
949 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -0600950 (struct phy_cmd[]) { /* config */
951 /* Reset the PHY */
952 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Andy Fleming180d03a2007-05-08 17:23:02 -0500953
Peter Tyser4ef03c02009-11-09 13:09:46 -0600954 /* Errata E0, E1 */
955 {29, 0x001b, NULL},
956 {30, 0x418f, NULL},
957 {29, 0x0016, NULL},
958 {30, 0xa2da, NULL},
Andy Fleming239e75f2006-09-13 10:34:18 -0500959
Peter Tyser4ef03c02009-11-09 13:09:46 -0600960 /* Configure the PHY */
961 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
962 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
963 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, NULL},
964 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
965 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
966 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
967 {miim_end,}
968 },
969 (struct phy_cmd[]) { /* startup */
970 /* Status is read once to clear old link state */
971 {MIIM_STATUS, miim_read, NULL},
972 /* Auto-negotiate */
973 {MIIM_STATUS, miim_read, &mii_parse_sr},
974 {MIIM_88E1111_PHY_LED_CONTROL, MIIM_88E1111_PHY_LED_DIRECT, NULL},
975 /* Read the Status */
976 {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
977 {miim_end,}
978 },
979 (struct phy_cmd[]) { /* shutdown */
980 {miim_end,}
981 },
Andy Fleming239e75f2006-09-13 10:34:18 -0500982};
983
Peter Tyser08b2d782009-11-09 13:09:45 -0600984static struct phy_info phy_info_cis8204 = {
wdenka445ddf2004-06-09 00:34:46 +0000985 0x3f11,
986 "Cicada Cis8204",
987 6,
Peter Tyser4ef03c02009-11-09 13:09:46 -0600988 (struct phy_cmd[]) { /* config */
989 /* Override PHY config settings */
990 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
991 /* Configure some basic stuff */
992 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
993 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
994 &mii_cis8204_fixled},
995 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
996 &mii_cis8204_setmode},
997 {miim_end,}
998 },
999 (struct phy_cmd[]) { /* startup */
1000 /* Read the Status (2x to make sure link is right) */
1001 {MIIM_STATUS, miim_read, NULL},
1002 /* Auto-negotiate */
1003 {MIIM_STATUS, miim_read, &mii_parse_sr},
1004 /* Read the status */
1005 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1006 {miim_end,}
1007 },
1008 (struct phy_cmd[]) { /* shutdown */
1009 {miim_end,}
1010 },
wdenka445ddf2004-06-09 00:34:46 +00001011};
1012
1013/* Cicada 8201 */
Peter Tyser08b2d782009-11-09 13:09:45 -06001014static struct phy_info phy_info_cis8201 = {
wdenka445ddf2004-06-09 00:34:46 +00001015 0xfc41,
1016 "CIS8201",
1017 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001018 (struct phy_cmd[]) { /* config */
1019 /* Override PHY config settings */
1020 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1021 /* Set up the interface mode */
1022 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1023 /* Configure some basic stuff */
1024 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1025 {miim_end,}
1026 },
1027 (struct phy_cmd[]) { /* startup */
1028 /* Read the Status (2x to make sure link is right) */
1029 {MIIM_STATUS, miim_read, NULL},
1030 /* Auto-negotiate */
1031 {MIIM_STATUS, miim_read, &mii_parse_sr},
1032 /* Read the status */
1033 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1034 {miim_end,}
1035 },
1036 (struct phy_cmd[]) { /* shutdown */
1037 {miim_end,}
1038 },
wdenka445ddf2004-06-09 00:34:46 +00001039};
Peter Tyser08b2d782009-11-09 13:09:45 -06001040
1041static struct phy_info phy_info_VSC8211 = {
Pieter Henning9370c8b2009-02-22 23:17:15 -08001042 0xfc4b,
1043 "Vitesse VSC8211",
1044 4,
1045 (struct phy_cmd[]) { /* config */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001046 /* Override PHY config settings */
1047 {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1048 /* Set up the interface mode */
1049 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
1050 /* Configure some basic stuff */
1051 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1052 {miim_end,}
1053 },
Pieter Henning9370c8b2009-02-22 23:17:15 -08001054 (struct phy_cmd[]) { /* startup */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001055 /* Read the Status (2x to make sure link is right) */
1056 {MIIM_STATUS, miim_read, NULL},
1057 /* Auto-negotiate */
1058 {MIIM_STATUS, miim_read, &mii_parse_sr},
1059 /* Read the status */
1060 {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
1061 {miim_end,}
1062 },
Pieter Henning9370c8b2009-02-22 23:17:15 -08001063 (struct phy_cmd[]) { /* shutdown */
Peter Tyser4ef03c02009-11-09 13:09:46 -06001064 {miim_end,}
Pieter Henning9370c8b2009-02-22 23:17:15 -08001065 },
1066};
Peter Tyser08b2d782009-11-09 13:09:45 -06001067
1068static struct phy_info phy_info_VSC8244 = {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001069 0x3f1b,
1070 "Vitesse VSC8244",
1071 6,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001072 (struct phy_cmd[]) { /* config */
1073 /* Override PHY config settings */
1074 /* Configure some basic stuff */
1075 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1076 {miim_end,}
1077 },
1078 (struct phy_cmd[]) { /* startup */
1079 /* Read the Status (2x to make sure link is right) */
1080 {MIIM_STATUS, miim_read, NULL},
1081 /* Auto-negotiate */
1082 {MIIM_STATUS, miim_read, &mii_parse_sr},
1083 /* Read the status */
1084 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1085 {miim_end,}
1086 },
1087 (struct phy_cmd[]) { /* shutdown */
1088 {miim_end,}
1089 },
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001090};
wdenka445ddf2004-06-09 00:34:46 +00001091
Peter Tyser08b2d782009-11-09 13:09:45 -06001092static struct phy_info phy_info_VSC8641 = {
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301093 0x7043,
1094 "Vitesse VSC8641",
1095 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001096 (struct phy_cmd[]) { /* config */
1097 /* Configure some basic stuff */
1098 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1099 {miim_end,}
1100 },
1101 (struct phy_cmd[]) { /* startup */
1102 /* Read the Status (2x to make sure link is right) */
1103 {MIIM_STATUS, miim_read, NULL},
1104 /* Auto-negotiate */
1105 {MIIM_STATUS, miim_read, &mii_parse_sr},
1106 /* Read the status */
1107 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1108 {miim_end,}
1109 },
1110 (struct phy_cmd[]) { /* shutdown */
1111 {miim_end,}
1112 },
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301113};
1114
Peter Tyser08b2d782009-11-09 13:09:45 -06001115static struct phy_info phy_info_VSC8221 = {
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301116 0xfc55,
1117 "Vitesse VSC8221",
1118 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001119 (struct phy_cmd[]) { /* config */
1120 /* Configure some basic stuff */
1121 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1122 {miim_end,}
1123 },
1124 (struct phy_cmd[]) { /* startup */
1125 /* Read the Status (2x to make sure link is right) */
1126 {MIIM_STATUS, miim_read, NULL},
1127 /* Auto-negotiate */
1128 {MIIM_STATUS, miim_read, &mii_parse_sr},
1129 /* Read the status */
1130 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1131 {miim_end,}
1132 },
1133 (struct phy_cmd[]) { /* shutdown */
1134 {miim_end,}
1135 },
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301136};
1137
Peter Tyser08b2d782009-11-09 13:09:45 -06001138static struct phy_info phy_info_VSC8601 = {
Peter Tyser4ef03c02009-11-09 13:09:46 -06001139 0x00007042,
1140 "Vitesse VSC8601",
1141 4,
1142 (struct phy_cmd[]) { /* config */
1143 /* Override PHY config settings */
1144 /* Configure some basic stuff */
1145 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001146#ifdef CONFIG_SYS_VSC8601_SKEWFIX
Peter Tyser4ef03c02009-11-09 13:09:46 -06001147 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001148#if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
Peter Tyser4ef03c02009-11-09 13:09:46 -06001149 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1150#define VSC8101_SKEW \
1151 (CONFIG_SYS_VSC8601_SKEW_TX << 14) | (CONFIG_SYS_VSC8601_SKEW_RX << 12)
1152 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1153 {MIIM_EXT_PAGE_ACCESS,0,NULL},
Andre Schwarz1e18be12008-04-29 19:18:32 +02001154#endif
Tor Krill8b3a82f2008-03-28 15:29:45 +01001155#endif
Peter Tyser4ef03c02009-11-09 13:09:46 -06001156 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1157 {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
1158 {miim_end,}
1159 },
1160 (struct phy_cmd[]) { /* startup */
1161 /* Read the Status (2x to make sure link is right) */
1162 {MIIM_STATUS, miim_read, NULL},
1163 /* Auto-negotiate */
1164 {MIIM_STATUS, miim_read, &mii_parse_sr},
1165 /* Read the status */
1166 {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
1167 {miim_end,}
1168 },
1169 (struct phy_cmd[]) { /* shutdown */
1170 {miim_end,}
1171 },
Tor Krill8b3a82f2008-03-28 15:29:45 +01001172};
1173
Peter Tyser08b2d782009-11-09 13:09:45 -06001174static struct phy_info phy_info_dm9161 = {
wdenka445ddf2004-06-09 00:34:46 +00001175 0x0181b88,
1176 "Davicom DM9161E",
1177 4,
Peter Tyser4ef03c02009-11-09 13:09:46 -06001178 (struct phy_cmd[]) { /* config */
1179 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1180 /* Do not bypass the scrambler/descrambler */
1181 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1182 /* Clear 10BTCSR to default */
1183 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
1184 /* Configure some basic stuff */
1185 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1186 /* Restart Auto Negotiation */
1187 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1188 {miim_end,}
1189 },
1190 (struct phy_cmd[]) { /* startup */
1191 /* Status is read once to clear old link state */
1192 {MIIM_STATUS, miim_read, NULL},
1193 /* Auto-negotiate */
1194 {MIIM_STATUS, miim_read, &mii_parse_sr},
1195 /* Read the status */
1196 {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
1197 {miim_end,}
1198 },
1199 (struct phy_cmd[]) { /* shutdown */
1200 {miim_end,}
1201 },
wdenka445ddf2004-06-09 00:34:46 +00001202};
Peter Tyser4ef03c02009-11-09 13:09:46 -06001203
Heiko Schocher6d9933f2010-07-05 12:23:04 +02001204/* micrel KSZ804 */
1205static struct phy_info phy_info_ksz804 = {
1206 0x0022151,
1207 "Micrel KSZ804 PHY",
1208 4,
1209 (struct phy_cmd[]) { /* config */
Mike Frysingerd63ee712010-12-23 15:40:12 -05001210 {MII_BMCR, BMCR_RESET, NULL},
1211 {MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART, NULL},
Heiko Schocher6d9933f2010-07-05 12:23:04 +02001212 {miim_end,}
1213 },
1214 (struct phy_cmd[]) { /* startup */
Mike Frysingerd63ee712010-12-23 15:40:12 -05001215 {MII_BMSR, miim_read, NULL},
1216 {MII_BMSR, miim_read, &mii_parse_sr},
1217 {MII_BMSR, miim_read, &mii_parse_link},
Heiko Schocher6d9933f2010-07-05 12:23:04 +02001218 {miim_end,}
1219 },
1220 (struct phy_cmd[]) { /* shutdown */
1221 {miim_end,}
1222 }
1223};
1224
David Updegraff0451b012007-04-20 14:34:48 -05001225/* a generic flavor. */
Peter Tyser08b2d782009-11-09 13:09:45 -06001226static struct phy_info phy_info_generic = {
David Updegraff0451b012007-04-20 14:34:48 -05001227 0,
1228 "Unknown/Generic PHY",
1229 32,
1230 (struct phy_cmd[]) { /* config */
Mike Frysingerd63ee712010-12-23 15:40:12 -05001231 {MII_BMCR, BMCR_RESET, NULL},
1232 {MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART, NULL},
David Updegraff0451b012007-04-20 14:34:48 -05001233 {miim_end,}
1234 },
1235 (struct phy_cmd[]) { /* startup */
Mike Frysingerd63ee712010-12-23 15:40:12 -05001236 {MII_BMSR, miim_read, NULL},
1237 {MII_BMSR, miim_read, &mii_parse_sr},
1238 {MII_BMSR, miim_read, &mii_parse_link},
David Updegraff0451b012007-04-20 14:34:48 -05001239 {miim_end,}
1240 },
1241 (struct phy_cmd[]) { /* shutdown */
1242 {miim_end,}
1243 }
1244};
1245
Peter Tyser08b2d782009-11-09 13:09:45 -06001246static uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
wdenkf41ff3b2005-04-04 23:43:44 +00001247{
wdenke085e5b2005-04-05 23:32:21 +00001248 unsigned int speed;
1249 if (priv->link) {
1250 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenkf41ff3b2005-04-04 23:43:44 +00001251
wdenke085e5b2005-04-05 23:32:21 +00001252 switch (speed) {
1253 case MIIM_LXT971_SR2_10HDX:
1254 priv->speed = 10;
1255 priv->duplexity = 0;
1256 break;
1257 case MIIM_LXT971_SR2_10FDX:
1258 priv->speed = 10;
1259 priv->duplexity = 1;
1260 break;
1261 case MIIM_LXT971_SR2_100HDX:
1262 priv->speed = 100;
1263 priv->duplexity = 0;
urwithsughosh@gmail.com34b3f2e2007-09-10 14:54:56 -04001264 break;
wdenke085e5b2005-04-05 23:32:21 +00001265 default:
1266 priv->speed = 100;
1267 priv->duplexity = 1;
wdenke085e5b2005-04-05 23:32:21 +00001268 }
1269 } else {
1270 priv->speed = 0;
1271 priv->duplexity = 0;
1272 }
wdenkf41ff3b2005-04-04 23:43:44 +00001273
Mingkai Hue0653bf2011-01-27 12:52:46 +08001274 return 0;
1275}
1276
1277static struct phy_info phy_info_lxt971 = {
1278 0x0001378e,
1279 "LXT971",
1280 4,
1281 (struct phy_cmd[]) { /* config */
1282 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1283 {miim_end,}
1284 },
1285 (struct phy_cmd[]) { /* startup - enable interrupts */
1286 /* { 0x12, 0x00f2, NULL }, */
1287 {MIIM_STATUS, miim_read, NULL},
1288 {MIIM_STATUS, miim_read, &mii_parse_sr},
1289 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1290 {miim_end,}
1291 },
1292 (struct phy_cmd[]) { /* shutdown - disable interrupts */
1293 {miim_end,}
1294 },
1295};
1296
1297/* Parse the DP83865's link and auto-neg status register for speed and duplex
1298 * information
1299 */
1300static uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1301{
1302 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1303
1304 case MIIM_DP83865_SPD_1000:
1305 priv->speed = 1000;
1306 break;
1307
1308 case MIIM_DP83865_SPD_100:
1309 priv->speed = 100;
1310 break;
1311
1312 default:
1313 priv->speed = 10;
1314 break;
1315
1316 }
1317
1318 if (mii_reg & MIIM_DP83865_DPX_FULL)
1319 priv->duplexity = 1;
1320 else
1321 priv->duplexity = 0;
1322
1323 return 0;
1324}
1325
1326static struct phy_info phy_info_dp83865 = {
1327 0x20005c7,
1328 "NatSemi DP83865",
1329 4,
1330 (struct phy_cmd[]) { /* config */
1331 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1332 {miim_end,}
1333 },
1334 (struct phy_cmd[]) { /* startup */
1335 /* Status is read once to clear old link state */
1336 {MIIM_STATUS, miim_read, NULL},
1337 /* Auto-negotiate */
1338 {MIIM_STATUS, miim_read, &mii_parse_sr},
1339 /* Read the link and auto-neg status */
1340 {MIIM_DP83865_LANR, miim_read, &mii_parse_dp83865_lanr},
1341 {miim_end,}
1342 },
1343 (struct phy_cmd[]) { /* shutdown */
1344 {miim_end,}
1345 },
1346};
1347
1348static struct phy_info phy_info_rtl8211b = {
1349 0x001cc91,
1350 "RealTek RTL8211B",
1351 4,
1352 (struct phy_cmd[]) { /* config */
1353 /* Reset and configure the PHY */
1354 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1355 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1356 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1357 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1358 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1359 {miim_end,}
1360 },
1361 (struct phy_cmd[]) { /* startup */
1362 /* Status is read once to clear old link state */
1363 {MIIM_STATUS, miim_read, NULL},
1364 /* Auto-negotiate */
1365 {MIIM_STATUS, miim_read, &mii_parse_sr},
1366 /* Read the status */
1367 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1368 {miim_end,}
1369 },
1370 (struct phy_cmd[]) { /* shutdown */
1371 {miim_end,}
1372 },
1373};
1374
1375struct phy_info phy_info_AR8021 = {
1376 0x4dd04,
1377 "AR8021",
1378 4,
1379 (struct phy_cmd[]) { /* config */
1380 {MII_BMCR, BMCR_RESET, NULL},
1381 {MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART, NULL},
1382 {0x1d, 0x05, NULL},
1383 {0x1e, 0x3D47, NULL},
1384 {miim_end,}
1385 },
1386 (struct phy_cmd[]) { /* startup */
1387 {MII_BMSR, miim_read, NULL},
1388 {MII_BMSR, miim_read, &mii_parse_sr},
1389 {MII_BMSR, miim_read, &mii_parse_link},
1390 {miim_end,}
1391 },
1392 (struct phy_cmd[]) { /* shutdown */
1393 {miim_end,}
1394 }
1395};
1396
1397static struct phy_info *phy_info[] = {
1398 &phy_info_cis8204,
1399 &phy_info_cis8201,
1400 &phy_info_BCM5461S,
1401 &phy_info_BCM5464S,
1402 &phy_info_BCM5482S,
1403 &phy_info_M88E1011S,
1404 &phy_info_M88E1111S,
1405 &phy_info_M88E1118,
1406 &phy_info_M88E1121R,
1407 &phy_info_M88E1145,
1408 &phy_info_M88E1149S,
1409 &phy_info_dm9161,
1410 &phy_info_ksz804,
1411 &phy_info_lxt971,
1412 &phy_info_VSC8211,
1413 &phy_info_VSC8244,
1414 &phy_info_VSC8601,
1415 &phy_info_VSC8641,
1416 &phy_info_VSC8221,
1417 &phy_info_dp83865,
1418 &phy_info_rtl8211b,
1419 &phy_info_AR8021,
1420 &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
1421 NULL
1422};
1423
1424/* Grab the identifier of the device's PHY, and search through
1425 * all of the known PHYs to see if one matches. If so, return
1426 * it, if not, return NULL
1427 */
1428static struct phy_info *get_phy_info(struct eth_device *dev)
1429{
1430 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1431 uint phy_reg, phy_ID;
1432 int i;
1433 struct phy_info *theInfo = NULL;
1434
1435 /* Grab the bits from PHYIR1, and put them in the upper half */
1436 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1437 phy_ID = (phy_reg & 0xffff) << 16;
1438
1439 /* Grab the bits from PHYIR2, and put them in the lower half */
1440 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1441 phy_ID |= (phy_reg & 0xffff);
1442
1443 /* loop through all the known PHY types, and find one that */
1444 /* matches the ID we read from the PHY. */
1445 for (i = 0; phy_info[i]; i++) {
1446 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
1447 theInfo = phy_info[i];
1448 break;
1449 }
1450 }
1451
1452 if (theInfo == &phy_info_generic) {
1453 printf("%s: No support for PHY id %x; assuming generic\n",
1454 dev->name, phy_ID);
1455 } else {
1456 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
1457 }
1458
1459 return theInfo;
1460}
1461
1462/* Execute the given series of commands on the given device's
1463 * PHY, running functions as necessary
1464 */
1465static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1466{
1467 int i;
1468 uint result;
1469 tsec_mdio_t *phyregs = priv->phyregs;
1470
1471 out_be32(&phyregs->miimcfg, MIIMCFG_RESET);
1472
1473 out_be32(&phyregs->miimcfg, MIIMCFG_INIT_VALUE);
1474
1475 while (in_be32(&phyregs->miimind) & MIIMIND_BUSY)
1476 ;
1477
1478 for (i = 0; cmd->mii_reg != miim_end; i++) {
1479 if (cmd->mii_data == miim_read) {
1480 result = read_phy_reg(priv, cmd->mii_reg);
1481
1482 if (cmd->funct != NULL)
1483 (*(cmd->funct)) (result, priv);
1484
1485 } else {
1486 if (cmd->funct != NULL)
1487 result = (*(cmd->funct)) (cmd->mii_reg, priv);
1488 else
1489 result = cmd->mii_data;
1490
1491 write_phy_reg(priv, cmd->mii_reg, result);
1492
1493 }
1494 cmd++;
1495 }
1496}
1497
1498#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
1499 && !defined(BITBANGMII)
1500
1501/*
1502 * Read a MII PHY register.
1503 *
1504 * Returns:
1505 * 0 on success
1506 */
1507static int tsec_miiphy_read(const char *devname, unsigned char addr,
1508 unsigned char reg, unsigned short *value)
1509{
1510 unsigned short ret;
1511 struct tsec_private *priv = privlist[0];
1512
1513 if (NULL == priv) {
1514 printf("Can't read PHY at address %d\n", addr);
1515 return -1;
1516 }
1517
1518 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
1519 *value = ret;
1520
1521 return 0;
1522}
1523
1524/*
1525 * Write a MII PHY register.
1526 *
1527 * Returns:
1528 * 0 on success
1529 */
1530static int tsec_miiphy_write(const char *devname, unsigned char addr,
1531 unsigned char reg, unsigned short value)
1532{
1533 struct tsec_private *priv = privlist[0];
1534
1535 if (NULL == priv) {
1536 printf("Can't write PHY at address %d\n", addr);
1537 return -1;
1538 }
1539
1540 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
1541
1542 return 0;
1543}
1544
1545#endif
1546
1547#ifdef CONFIG_MCAST_TFTP
1548
1549/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1550
1551/* Set the appropriate hash bit for the given addr */
1552
1553/* The algorithm works like so:
1554 * 1) Take the Destination Address (ie the multicast address), and
1555 * do a CRC on it (little endian), and reverse the bits of the
1556 * result.
1557 * 2) Use the 8 most significant bits as a hash into a 256-entry
1558 * table. The table is controlled through 8 32-bit registers:
1559 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1560 * gaddr7. This means that the 3 most significant bits in the
1561 * hash index which gaddr register to use, and the 5 other bits
1562 * indicate which bit (assuming an IBM numbering scheme, which
1563 * for PowerPC (tm) is usually the case) in the tregister holds
1564 * the entry. */
1565static int
1566tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1567{
1568 struct tsec_private *priv = privlist[1];
1569 volatile tsec_t *regs = priv->regs;
1570 volatile u32 *reg_array, value;
1571 u8 result, whichbit, whichreg;
1572
1573 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1574 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1575 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1576 value = (1 << (31-whichbit));
1577
1578 reg_array = &(regs->hash.gaddr0);
1579
1580 if (set) {
1581 reg_array[whichreg] |= value;
1582 } else {
1583 reg_array[whichreg] &= ~value;
1584 }
1585 return 0;
1586}
1587#endif /* Multicast TFTP ? */
1588
1589/* Initialized required registers to appropriate values, zeroing
1590 * those we don't care about (unless zero is bad, in which case,
1591 * choose a more appropriate value)
1592 */
1593static void init_registers(tsec_t *regs)
1594{
1595 /* Clear IEVENT */
1596 out_be32(&regs->ievent, IEVENT_INIT_CLEAR);
1597
1598 out_be32(&regs->imask, IMASK_INIT_CLEAR);
1599
1600 out_be32(&regs->hash.iaddr0, 0);
1601 out_be32(&regs->hash.iaddr1, 0);
1602 out_be32(&regs->hash.iaddr2, 0);
1603 out_be32(&regs->hash.iaddr3, 0);
1604 out_be32(&regs->hash.iaddr4, 0);
1605 out_be32(&regs->hash.iaddr5, 0);
1606 out_be32(&regs->hash.iaddr6, 0);
1607 out_be32(&regs->hash.iaddr7, 0);
1608
1609 out_be32(&regs->hash.gaddr0, 0);
1610 out_be32(&regs->hash.gaddr1, 0);
1611 out_be32(&regs->hash.gaddr2, 0);
1612 out_be32(&regs->hash.gaddr3, 0);
1613 out_be32(&regs->hash.gaddr4, 0);
1614 out_be32(&regs->hash.gaddr5, 0);
1615 out_be32(&regs->hash.gaddr6, 0);
1616 out_be32(&regs->hash.gaddr7, 0);
1617
1618 out_be32(&regs->rctrl, 0x00000000);
1619
1620 /* Init RMON mib registers */
1621 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
1622
1623 out_be32(&regs->rmon.cam1, 0xffffffff);
1624 out_be32(&regs->rmon.cam2, 0xffffffff);
1625
1626 out_be32(&regs->mrblr, MRBLR_INIT_SETTINGS);
1627
1628 out_be32(&regs->minflr, MINFLR_INIT_SETTINGS);
1629
1630 out_be32(&regs->attr, ATTR_INIT_SETTINGS);
1631 out_be32(&regs->attreli, ATTRELI_INIT_SETTINGS);
1632
1633}
1634
1635/* Configure maccfg2 based on negotiated speed and duplex
1636 * reported by PHY handling code
1637 */
1638static void adjust_link(struct eth_device *dev)
1639{
1640 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1641 tsec_t *regs = priv->regs;
1642 u32 ecntrl, maccfg2;
1643
1644 if (!priv->link) {
1645 printf("%s: No link.\n", dev->name);
1646 return;
1647 }
1648
1649 /* clear all bits relative with interface mode */
1650 ecntrl = in_be32(&regs->ecntrl);
1651 ecntrl &= ~ECNTRL_R100;
1652
1653 maccfg2 = in_be32(&regs->maccfg2);
1654 maccfg2 &= ~(MACCFG2_IF | MACCFG2_FULL_DUPLEX);
1655
1656 if (priv->duplexity)
1657 maccfg2 |= MACCFG2_FULL_DUPLEX;
1658
1659 switch (priv->speed) {
1660 case 1000:
1661 maccfg2 |= MACCFG2_GMII;
1662 break;
1663 case 100:
1664 case 10:
1665 maccfg2 |= MACCFG2_MII;
1666
1667 /* Set R100 bit in all modes although
1668 * it is only used in RGMII mode
1669 */
1670 if (priv->speed == 100)
1671 ecntrl |= ECNTRL_R100;
1672 break;
1673 default:
1674 printf("%s: Speed was bad\n", dev->name);
1675 break;
1676 }
1677
1678 out_be32(&regs->ecntrl, ecntrl);
1679 out_be32(&regs->maccfg2, maccfg2);
wdenkf41ff3b2005-04-04 23:43:44 +00001680
Mingkai Hue0653bf2011-01-27 12:52:46 +08001681 printf("Speed: %d, %s duplex%s\n", priv->speed,
1682 (priv->duplexity) ? "full" : "half",
1683 (priv->flags & TSEC_FIBER) ? ", fiber mode" : "");
1684}
wdenkbfad55d2005-03-14 23:56:42 +00001685
Mingkai Hue0653bf2011-01-27 12:52:46 +08001686/* Set up the buffers and their descriptors, and bring up the
1687 * interface
Jon Loeligerb7ced082006-10-10 17:03:43 -05001688 */
Mingkai Hue0653bf2011-01-27 12:52:46 +08001689static void startup_tsec(struct eth_device *dev)
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001690{
Mingkai Hue0653bf2011-01-27 12:52:46 +08001691 int i;
1692 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1693 tsec_t *regs = priv->regs;
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001694
Mingkai Hue0653bf2011-01-27 12:52:46 +08001695 /* Point to the buffer descriptors */
1696 out_be32(&regs->tbase, (unsigned int)(&rtx.txbd[txIdx]));
1697 out_be32(&regs->rbase, (unsigned int)(&rtx.rxbd[rxIdx]));
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001698
Mingkai Hue0653bf2011-01-27 12:52:46 +08001699 /* Initialize the Rx Buffer descriptors */
1700 for (i = 0; i < PKTBUFSRX; i++) {
1701 rtx.rxbd[i].status = RXBD_EMPTY;
1702 rtx.rxbd[i].length = 0;
1703 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
1704 }
1705 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001706
Mingkai Hue0653bf2011-01-27 12:52:46 +08001707 /* Initialize the TX Buffer Descriptors */
1708 for (i = 0; i < TX_BUF_CNT; i++) {
1709 rtx.txbd[i].status = 0;
1710 rtx.txbd[i].length = 0;
1711 rtx.txbd[i].bufPtr = 0;
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001712 }
Mingkai Hue0653bf2011-01-27 12:52:46 +08001713 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001714
Mingkai Hue0653bf2011-01-27 12:52:46 +08001715 /* Start up the PHY */
1716 if (priv->phyinfo)
1717 phy_run_commands(priv, priv->phyinfo->startup);
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001718
Mingkai Hue0653bf2011-01-27 12:52:46 +08001719 adjust_link(dev);
1720
1721 /* Enable Transmit and Receive */
1722 setbits_be32(&regs->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN);
1723
1724 /* Tell the DMA it is clear to go */
1725 setbits_be32(&regs->dmactrl, DMACTRL_INIT_SETTINGS);
1726 out_be32(&regs->tstat, TSTAT_CLEAR_THALT);
1727 out_be32(&regs->rstat, RSTAT_CLEAR_RHALT);
1728 clrbits_be32(&regs->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001729}
1730
Mingkai Hue0653bf2011-01-27 12:52:46 +08001731/* This returns the status bits of the device. The return value
1732 * is never checked, and this is what the 8260 driver did, so we
1733 * do the same. Presumably, this would be zero if there were no
1734 * errors
1735 */
1736static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
1737{
1738 int i;
1739 int result = 0;
1740 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1741 tsec_t *regs = priv->regs;
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001742
Mingkai Hue0653bf2011-01-27 12:52:46 +08001743 /* Find an empty buffer descriptor */
1744 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
1745 if (i >= TOUT_LOOP) {
1746 debug("%s: tsec: tx buffers full\n", dev->name);
1747 return result;
1748 }
1749 }
Dave Liua304a282008-01-11 18:45:28 +08001750
Mingkai Hue0653bf2011-01-27 12:52:46 +08001751 rtx.txbd[txIdx].bufPtr = (uint) packet;
1752 rtx.txbd[txIdx].length = length;
1753 rtx.txbd[txIdx].status |=
1754 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
Li Yang25e38bd2011-01-27 19:02:50 +08001755
Mingkai Hue0653bf2011-01-27 12:52:46 +08001756 /* Tell the DMA to go */
1757 out_be32(&regs->tstat, TSTAT_CLEAR_THALT);
wdenka445ddf2004-06-09 00:34:46 +00001758
Mingkai Hue0653bf2011-01-27 12:52:46 +08001759 /* Wait for buffer to be transmitted */
1760 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
1761 if (i >= TOUT_LOOP) {
1762 debug("%s: tsec: tx error\n", dev->name);
1763 return result;
1764 }
1765 }
1766
1767 txIdx = (txIdx + 1) % TX_BUF_CNT;
1768 result = rtx.txbd[txIdx].status & TXBD_STATS;
1769
1770 return result;
1771}
1772
1773static int tsec_recv(struct eth_device *dev)
wdenka445ddf2004-06-09 00:34:46 +00001774{
Mingkai Hue0653bf2011-01-27 12:52:46 +08001775 int length;
wdenka445ddf2004-06-09 00:34:46 +00001776 struct tsec_private *priv = (struct tsec_private *)dev->priv;
Mingkai Hue0653bf2011-01-27 12:52:46 +08001777 tsec_t *regs = priv->regs;
wdenka445ddf2004-06-09 00:34:46 +00001778
Mingkai Hue0653bf2011-01-27 12:52:46 +08001779 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenka445ddf2004-06-09 00:34:46 +00001780
Mingkai Hue0653bf2011-01-27 12:52:46 +08001781 length = rtx.rxbd[rxIdx].length;
wdenka445ddf2004-06-09 00:34:46 +00001782
Mingkai Hue0653bf2011-01-27 12:52:46 +08001783 /* Send the packet up if there were no errors */
1784 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
1785 NetReceive(NetRxPackets[rxIdx], length - 4);
1786 } else {
1787 printf("Got error %x\n",
1788 (rtx.rxbd[rxIdx].status & RXBD_STATS));
Andy Flemingb2d14f42007-05-09 00:54:20 -05001789 }
Mingkai Hue0653bf2011-01-27 12:52:46 +08001790
1791 rtx.rxbd[rxIdx].length = 0;
1792
1793 /* Set the wrap bit if this is the last element in the list */
1794 rtx.rxbd[rxIdx].status =
1795 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
1796
1797 rxIdx = (rxIdx + 1) % PKTBUFSRX;
wdenka445ddf2004-06-09 00:34:46 +00001798 }
1799
Mingkai Hue0653bf2011-01-27 12:52:46 +08001800 if (in_be32(&regs->ievent) & IEVENT_BSY) {
1801 out_be32(&regs->ievent, IEVENT_BSY);
1802 out_be32(&regs->rstat, RSTAT_CLEAR_RHALT);
wdenka445ddf2004-06-09 00:34:46 +00001803 }
1804
Mingkai Hue0653bf2011-01-27 12:52:46 +08001805 return -1;
1806
wdenka445ddf2004-06-09 00:34:46 +00001807}
1808
Mingkai Hue0653bf2011-01-27 12:52:46 +08001809/* Stop the interface */
1810static void tsec_halt(struct eth_device *dev)
1811{
1812 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1813 tsec_t *regs = priv->regs;
1814
1815 clrbits_be32(&regs->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
1816 setbits_be32(&regs->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
1817
1818 while ((in_be32(&regs->ievent) & (IEVENT_GRSC | IEVENT_GTSC))
1819 != (IEVENT_GRSC | IEVENT_GTSC))
1820 ;
1821
1822 clrbits_be32(&regs->maccfg1, MACCFG1_TX_EN | MACCFG1_RX_EN);
1823
1824 /* Shut down the PHY, as needed */
1825 if (priv->phyinfo)
1826 phy_run_commands(priv, priv->phyinfo->shutdown);
1827}
1828
1829/* Initializes data structures and registers for the controller,
1830 * and brings the interface up. Returns the link status, meaning
1831 * that it returns success if the link is up, failure otherwise.
1832 * This allows u-boot to find the first active controller.
Jon Loeligerb7ced082006-10-10 17:03:43 -05001833 */
Mingkai Hue0653bf2011-01-27 12:52:46 +08001834static int tsec_init(struct eth_device *dev, bd_t * bd)
wdenka445ddf2004-06-09 00:34:46 +00001835{
Mingkai Hue0653bf2011-01-27 12:52:46 +08001836 uint tempval;
1837 char tmpbuf[MAC_ADDR_LEN];
wdenka445ddf2004-06-09 00:34:46 +00001838 int i;
Mingkai Hue0653bf2011-01-27 12:52:46 +08001839 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1840 tsec_t *regs = priv->regs;
wdenka445ddf2004-06-09 00:34:46 +00001841
Mingkai Hue0653bf2011-01-27 12:52:46 +08001842 /* Make sure the controller is stopped */
1843 tsec_halt(dev);
wdenka445ddf2004-06-09 00:34:46 +00001844
Mingkai Hue0653bf2011-01-27 12:52:46 +08001845 /* Init MACCFG2. Defaults to GMII */
1846 out_be32(&regs->maccfg2, MACCFG2_INIT_SETTINGS);
wdenka445ddf2004-06-09 00:34:46 +00001847
Mingkai Hue0653bf2011-01-27 12:52:46 +08001848 /* Init ECNTRL */
1849 out_be32(&regs->ecntrl, ECNTRL_INIT_SETTINGS);
wdenka445ddf2004-06-09 00:34:46 +00001850
Mingkai Hue0653bf2011-01-27 12:52:46 +08001851 /* Copy the station address into the address registers.
1852 * Backwards, because little endian MACS are dumb */
1853 for (i = 0; i < MAC_ADDR_LEN; i++)
1854 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenka445ddf2004-06-09 00:34:46 +00001855
Mingkai Hue0653bf2011-01-27 12:52:46 +08001856 tempval = (tmpbuf[0] << 24) | (tmpbuf[1] << 16) | (tmpbuf[2] << 8) |
1857 tmpbuf[3];
wdenka445ddf2004-06-09 00:34:46 +00001858
Mingkai Hue0653bf2011-01-27 12:52:46 +08001859 out_be32(&regs->macstnaddr1, tempval);
wdenka445ddf2004-06-09 00:34:46 +00001860
Mingkai Hue0653bf2011-01-27 12:52:46 +08001861 tempval = *((uint *) (tmpbuf + 4));
wdenka445ddf2004-06-09 00:34:46 +00001862
Mingkai Hue0653bf2011-01-27 12:52:46 +08001863 out_be32(&regs->macstnaddr2, tempval);
wdenka445ddf2004-06-09 00:34:46 +00001864
Mingkai Hue0653bf2011-01-27 12:52:46 +08001865 /* reset the indices to zero */
1866 rxIdx = 0;
1867 txIdx = 0;
wdenka445ddf2004-06-09 00:34:46 +00001868
Mingkai Hue0653bf2011-01-27 12:52:46 +08001869 /* Clear out (for the most part) the other registers */
1870 init_registers(regs);
1871
1872 /* Ready the device for tx/rx */
1873 startup_tsec(dev);
1874
1875 /* If there's no link, fail */
1876 return priv->link ? 0 : -1;
1877}
1878
1879/* Discover which PHY is attached to the device, and configure it
1880 * properly. If the PHY is not recognized, then return 0
1881 * (failure). Otherwise, return 1
wdenk78924a72004-04-18 21:45:42 +00001882 */
Mingkai Hue0653bf2011-01-27 12:52:46 +08001883static int init_phy(struct eth_device *dev)
wdenk78924a72004-04-18 21:45:42 +00001884{
Mingkai Hue0653bf2011-01-27 12:52:46 +08001885 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1886 struct phy_info *curphy;
1887 tsec_t *regs = priv->regs;
wdenk78924a72004-04-18 21:45:42 +00001888
Mingkai Hue0653bf2011-01-27 12:52:46 +08001889 /* Assign a Physical address to the TBI */
1890 out_be32(&regs->tbipa, CONFIG_SYS_TBIPA_VALUE);
1891
1892 /* Reset MII (due to new addresses) */
1893 out_be32(&priv->phyregs->miimcfg, MIIMCFG_RESET);
1894 out_be32(&priv->phyregs->miimcfg, MIIMCFG_INIT_VALUE);
1895 while (in_be32(&priv->phyregs->miimind) & MIIMIND_BUSY)
1896 ;
1897
1898 /* Get the cmd structure corresponding to the attached
1899 * PHY */
1900 curphy = get_phy_info(dev);
1901
1902 if (curphy == NULL) {
1903 priv->phyinfo = NULL;
1904 printf("%s: No PHY found\n", dev->name);
1905
1906 return 0;
wdenka445ddf2004-06-09 00:34:46 +00001907 }
1908
Mingkai Hue0653bf2011-01-27 12:52:46 +08001909 if (in_be32(&regs->ecntrl) & ECNTRL_SGMII_MODE)
1910 tsec_configure_serdes(priv);
wdenk78924a72004-04-18 21:45:42 +00001911
Mingkai Hue0653bf2011-01-27 12:52:46 +08001912 priv->phyinfo = curphy;
1913
1914 phy_run_commands(priv, priv->phyinfo->config);
1915
1916 return 1;
wdenk78924a72004-04-18 21:45:42 +00001917}
1918
Mingkai Hue0653bf2011-01-27 12:52:46 +08001919/* Initialize device structure. Returns success if PHY
1920 * initialization succeeded (i.e. if it recognizes the PHY)
wdenk78924a72004-04-18 21:45:42 +00001921 */
Mingkai Hue0653bf2011-01-27 12:52:46 +08001922static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info)
wdenk78924a72004-04-18 21:45:42 +00001923{
Mingkai Hue0653bf2011-01-27 12:52:46 +08001924 struct eth_device *dev;
1925 int i;
1926 struct tsec_private *priv;
wdenka445ddf2004-06-09 00:34:46 +00001927
Mingkai Hue0653bf2011-01-27 12:52:46 +08001928 dev = (struct eth_device *)malloc(sizeof *dev);
wdenk78924a72004-04-18 21:45:42 +00001929
Mingkai Hue0653bf2011-01-27 12:52:46 +08001930 if (NULL == dev)
1931 return 0;
wdenk78924a72004-04-18 21:45:42 +00001932
Mingkai Hue0653bf2011-01-27 12:52:46 +08001933 memset(dev, 0, sizeof *dev);
wdenka445ddf2004-06-09 00:34:46 +00001934
Mingkai Hue0653bf2011-01-27 12:52:46 +08001935 priv = (struct tsec_private *)malloc(sizeof(*priv));
1936
1937 if (NULL == priv)
1938 return 0;
1939
1940 privlist[num_tsecs++] = priv;
1941 priv->regs = tsec_info->regs;
1942 priv->phyregs = tsec_info->miiregs;
1943 priv->phyregs_sgmii = tsec_info->miiregs_sgmii;
1944
1945 priv->phyaddr = tsec_info->phyaddr;
1946 priv->flags = tsec_info->flags;
wdenka445ddf2004-06-09 00:34:46 +00001947
Mingkai Hue0653bf2011-01-27 12:52:46 +08001948 sprintf(dev->name, tsec_info->devname);
1949 dev->iobase = 0;
1950 dev->priv = priv;
1951 dev->init = tsec_init;
1952 dev->halt = tsec_halt;
1953 dev->send = tsec_send;
1954 dev->recv = tsec_recv;
David Updegraff7280da72007-06-11 10:41:07 -05001955#ifdef CONFIG_MCAST_TFTP
Mingkai Hue0653bf2011-01-27 12:52:46 +08001956 dev->mcast = tsec_mcast_addr;
1957#endif
David Updegraff7280da72007-06-11 10:41:07 -05001958
Mingkai Hue0653bf2011-01-27 12:52:46 +08001959 /* Tell u-boot to get the addr from the env */
1960 for (i = 0; i < 6; i++)
1961 dev->enetaddr[i] = 0;
David Updegraff7280da72007-06-11 10:41:07 -05001962
Mingkai Hue0653bf2011-01-27 12:52:46 +08001963 eth_register(dev);
David Updegraff7280da72007-06-11 10:41:07 -05001964
Mingkai Hue0653bf2011-01-27 12:52:46 +08001965 /* Reset the MAC */
1966 setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
1967 udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
1968 clrbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
David Updegraff7280da72007-06-11 10:41:07 -05001969
Mingkai Hue0653bf2011-01-27 12:52:46 +08001970#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
1971 && !defined(BITBANGMII)
1972 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
1973#endif
David Updegraff7280da72007-06-11 10:41:07 -05001974
Mingkai Hue0653bf2011-01-27 12:52:46 +08001975 /* Try to initialize PHY here, and return */
1976 return init_phy(dev);
1977}
David Updegraff7280da72007-06-11 10:41:07 -05001978
Mingkai Hue0653bf2011-01-27 12:52:46 +08001979/*
1980 * Initialize all the TSEC devices
1981 *
1982 * Returns the number of TSEC devices that were initialized
1983 */
1984int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num)
1985{
1986 int i;
1987 int ret, count = 0;
1988
1989 for (i = 0; i < num; i++) {
1990 ret = tsec_initialize(bis, &tsecs[i]);
1991 if (ret > 0)
1992 count += ret;
David Updegraff7280da72007-06-11 10:41:07 -05001993 }
Mingkai Hue0653bf2011-01-27 12:52:46 +08001994
1995 return count;
David Updegraff7280da72007-06-11 10:41:07 -05001996}
Mingkai Hue0653bf2011-01-27 12:52:46 +08001997
1998int tsec_standard_init(bd_t *bis)
1999{
2000 return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
2001}
2002