wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 2 | * Freescale Three Speed Ethernet Controller driver |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * |
| 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 | * |
Kumar Gala | c1457f9 | 2010-12-01 22:55:54 -0600 | [diff] [blame] | 8 | * Copyright 2004-2010 Freescale Semiconductor, Inc. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 9 | * (C) Copyright 2003, Motorola, Inc. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 10 | * author Andy Fleming |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <config.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 15 | #include <common.h> |
| 16 | #include <malloc.h> |
| 17 | #include <net.h> |
| 18 | #include <command.h> |
Andy Fleming | c067fc1 | 2008-08-31 16:33:25 -0500 | [diff] [blame] | 19 | #include <tsec.h> |
Kim Phillips | ae4dd97 | 2009-08-24 14:32:26 -0500 | [diff] [blame] | 20 | #include <asm/errno.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 21 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 22 | #include "miiphy.h" |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 23 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 26 | #define TX_BUF_CNT 2 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 27 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 28 | static uint rxIdx; /* index of the current RX buffer */ |
| 29 | static uint txIdx; /* index of the current TX buffer */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 30 | |
| 31 | typedef volatile struct rtxbd { |
| 32 | txbd8_t txbd[TX_BUF_CNT]; |
| 33 | rxbd8_t rxbd[PKTBUFSRX]; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 34 | } RTXBD; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 35 | |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 36 | #define MAXCONTROLLERS (8) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 37 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 38 | static struct tsec_private *privlist[MAXCONTROLLERS]; |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 39 | static int num_tsecs = 0; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 40 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 41 | #ifdef __GNUC__ |
| 42 | static RTXBD rtx __attribute__ ((aligned(8))); |
| 43 | #else |
| 44 | #error "rtx must be 64-bit aligned" |
| 45 | #endif |
| 46 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 47 | static int tsec_send(struct eth_device *dev, |
| 48 | volatile void *packet, int length); |
| 49 | static int tsec_recv(struct eth_device *dev); |
| 50 | static int tsec_init(struct eth_device *dev, bd_t * bd); |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 51 | static int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info); |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 52 | static void tsec_halt(struct eth_device *dev); |
| 53 | static void init_registers(volatile tsec_t * regs); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 54 | static void startup_tsec(struct eth_device *dev); |
| 55 | static int init_phy(struct eth_device *dev); |
| 56 | void write_phy_reg(struct tsec_private *priv, uint regnum, uint value); |
| 57 | uint read_phy_reg(struct tsec_private *priv, uint regnum); |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 58 | static struct phy_info *get_phy_info(struct eth_device *dev); |
| 59 | static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 60 | static void adjust_link(struct eth_device *dev); |
Wolfgang Denk | 9225411 | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 61 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
| 62 | && !defined(BITBANGMII) |
Mike Frysinger | 5ff5fdb | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 63 | static int tsec_miiphy_write(const char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 64 | unsigned char reg, unsigned short value); |
Mike Frysinger | 5ff5fdb | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 65 | static int tsec_miiphy_read(const char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 66 | unsigned char reg, unsigned short *value); |
Wolfgang Denk | 9225411 | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 67 | #endif |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 68 | #ifdef CONFIG_MCAST_TFTP |
| 69 | static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set); |
| 70 | #endif |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 71 | |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 72 | /* Default initializations for TSEC controllers. */ |
| 73 | |
| 74 | static 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 Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 84 | .miiregs = (tsec_mdio_t *)(MDIO_BASE_ADDR), |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 85 | .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 | |
Timur Tabi | 7762268 | 2010-06-08 08:21:21 -0500 | [diff] [blame] | 98 | /* |
| 99 | * Initialize all the TSEC devices |
| 100 | * |
| 101 | * Returns the number of TSEC devices that were initialized |
| 102 | */ |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 103 | int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num) |
| 104 | { |
| 105 | int i; |
Timur Tabi | 7762268 | 2010-06-08 08:21:21 -0500 | [diff] [blame] | 106 | int ret, count = 0; |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 107 | |
Timur Tabi | 7762268 | 2010-06-08 08:21:21 -0500 | [diff] [blame] | 108 | for (i = 0; i < num; i++) { |
| 109 | ret = tsec_initialize(bis, &tsecs[i]); |
| 110 | if (ret > 0) |
| 111 | count += ret; |
| 112 | } |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 113 | |
Timur Tabi | 7762268 | 2010-06-08 08:21:21 -0500 | [diff] [blame] | 114 | return count; |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | int tsec_standard_init(bd_t *bis) |
| 118 | { |
| 119 | return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info)); |
| 120 | } |
| 121 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 122 | /* Initialize device structure. Returns success if PHY |
| 123 | * initialization succeeded (i.e. if it recognizes the PHY) |
| 124 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 125 | static int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 126 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 127 | struct eth_device *dev; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 128 | int i; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 129 | struct tsec_private *priv; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 130 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 131 | dev = (struct eth_device *)malloc(sizeof *dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 132 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 133 | if (NULL == dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | |
| 136 | memset(dev, 0, sizeof *dev); |
| 137 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 138 | priv = (struct tsec_private *)malloc(sizeof(*priv)); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 139 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 140 | if (NULL == priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 141 | return 0; |
| 142 | |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 143 | privlist[num_tsecs++] = priv; |
| 144 | priv->regs = tsec_info->regs; |
| 145 | priv->phyregs = tsec_info->miiregs; |
Sandeep Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 146 | priv->phyregs_sgmii = tsec_info->miiregs_sgmii; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 147 | |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 148 | priv->phyaddr = tsec_info->phyaddr; |
| 149 | priv->flags = tsec_info->flags; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 150 | |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 151 | sprintf(dev->name, tsec_info->devname); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 152 | dev->iobase = 0; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 153 | dev->priv = priv; |
| 154 | dev->init = tsec_init; |
| 155 | dev->halt = tsec_halt; |
| 156 | dev->send = tsec_send; |
| 157 | dev->recv = tsec_recv; |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 158 | #ifdef CONFIG_MCAST_TFTP |
| 159 | dev->mcast = tsec_mcast_addr; |
| 160 | #endif |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 161 | |
| 162 | /* Tell u-boot to get the addr from the env */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 163 | for (i = 0; i < 6; i++) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 164 | dev->enetaddr[i] = 0; |
| 165 | |
| 166 | eth_register(dev); |
| 167 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 168 | /* Reset the MAC */ |
| 169 | priv->regs->maccfg1 |= MACCFG1_SOFT_RESET; |
Andy Fleming | 2d1db14 | 2009-02-03 18:26:41 -0600 | [diff] [blame] | 170 | udelay(2); /* Soft Reset must be asserted for 3 TX clocks */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 171 | priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET); |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 172 | |
Jon Loeliger | 82ecaad | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 173 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 174 | && !defined(BITBANGMII) |
| 175 | miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write); |
| 176 | #endif |
| 177 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 178 | /* Try to initialize PHY here, and return */ |
| 179 | return init_phy(dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 180 | } |
| 181 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 182 | /* Initializes data structures and registers for the controller, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 183 | * and brings the interface up. Returns the link status, meaning |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 184 | * that it returns success if the link is up, failure otherwise. |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 185 | * This allows u-boot to find the first active controller. |
| 186 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 187 | static int tsec_init(struct eth_device *dev, bd_t * bd) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 188 | { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 189 | uint tempval; |
| 190 | char tmpbuf[MAC_ADDR_LEN]; |
| 191 | int i; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 192 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 193 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 194 | |
| 195 | /* Make sure the controller is stopped */ |
| 196 | tsec_halt(dev); |
| 197 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 198 | /* Init MACCFG2. Defaults to GMII */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 199 | regs->maccfg2 = MACCFG2_INIT_SETTINGS; |
| 200 | |
| 201 | /* Init ECNTRL */ |
| 202 | regs->ecntrl = ECNTRL_INIT_SETTINGS; |
| 203 | |
| 204 | /* Copy the station address into the address registers. |
| 205 | * Backwards, because little endian MACS are dumb */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 206 | for (i = 0; i < MAC_ADDR_LEN; i++) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 207 | tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i]; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 208 | } |
Kim Phillips | 4f8b633 | 2009-07-17 12:17:00 -0500 | [diff] [blame] | 209 | tempval = (tmpbuf[0] << 24) | (tmpbuf[1] << 16) | (tmpbuf[2] << 8) | |
| 210 | tmpbuf[3]; |
| 211 | |
| 212 | regs->macstnaddr1 = tempval; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 213 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 214 | tempval = *((uint *) (tmpbuf + 4)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 215 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 216 | regs->macstnaddr2 = tempval; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 217 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 218 | /* reset the indices to zero */ |
| 219 | rxIdx = 0; |
| 220 | txIdx = 0; |
| 221 | |
| 222 | /* Clear out (for the most part) the other registers */ |
| 223 | init_registers(regs); |
| 224 | |
| 225 | /* Ready the device for tx/rx */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 226 | startup_tsec(dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 227 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 228 | /* If there's no link, fail */ |
Ben Warren | de9fcb5 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 229 | return (priv->link ? 0 : -1); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 230 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 231 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 232 | /* Writes the given phy's reg with value, using the specified MDIO regs */ |
Sandeep Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 233 | static void tsec_local_mdio_write(volatile tsec_mdio_t *phyregs, uint addr, |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 234 | uint reg, uint value) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 235 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 236 | int timeout = 1000000; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 237 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 238 | phyregs->miimadd = (addr << 8) | reg; |
| 239 | phyregs->miimcon = value; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 240 | asm("sync"); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 241 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 242 | timeout = 1000000; |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 243 | while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 246 | |
| 247 | /* Provide the default behavior of writing the PHY of this ethernet device */ |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 248 | #define write_phy_reg(priv, regnum, value) \ |
| 249 | tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value) |
michael.firth@bt.com | 0838484 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 250 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 251 | /* Reads register regnum on the device's PHY through the |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 252 | * specified registers. It lowers and raises the read |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 253 | * command, and waits for the data to become valid (miimind |
| 254 | * notvalid bit cleared), and the bus to cease activity (miimind |
| 255 | * busy bit cleared), and then returns the value |
| 256 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 257 | static uint tsec_local_mdio_read(volatile tsec_mdio_t *phyregs, |
| 258 | uint phyid, uint regnum) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 259 | { |
| 260 | uint value; |
| 261 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 262 | /* Put the address of the phy, and the register |
| 263 | * number into MIIMADD */ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 264 | phyregs->miimadd = (phyid << 8) | regnum; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 265 | |
| 266 | /* Clear the command register, and wait */ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 267 | phyregs->miimcom = 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 268 | asm("sync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 269 | |
| 270 | /* Initiate a read command, and wait */ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 271 | phyregs->miimcom = MIIM_READ_COMMAND; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 272 | asm("sync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 273 | |
| 274 | /* Wait for the the indication that the read is done */ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 275 | while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 276 | |
| 277 | /* Grab the value read from the PHY */ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 278 | value = phyregs->miimstat; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 279 | |
| 280 | return value; |
| 281 | } |
| 282 | |
michael.firth@bt.com | 0838484 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 283 | /* #define to provide old read_phy_reg functionality without duplicating code */ |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 284 | #define read_phy_reg(priv,regnum) \ |
| 285 | tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum) |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 286 | |
| 287 | #define TBIANA_SETTINGS ( \ |
| 288 | TBIANA_ASYMMETRIC_PAUSE \ |
| 289 | | TBIANA_SYMMETRIC_PAUSE \ |
| 290 | | TBIANA_FULL_DUPLEX \ |
| 291 | ) |
| 292 | |
Felix Radensky | 27f98e0 | 2010-06-28 01:57:39 +0300 | [diff] [blame] | 293 | /* By default force the TBI PHY into 1000Mbps full duplex when in SGMII mode */ |
| 294 | #ifndef CONFIG_TSEC_TBICR_SETTINGS |
Kumar Gala | c1457f9 | 2010-12-01 22:55:54 -0600 | [diff] [blame] | 295 | #define CONFIG_TSEC_TBICR_SETTINGS ( \ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 296 | TBICR_PHY_RESET \ |
Kumar Gala | c1457f9 | 2010-12-01 22:55:54 -0600 | [diff] [blame] | 297 | | TBICR_ANEG_ENABLE \ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 298 | | TBICR_FULL_DUPLEX \ |
| 299 | | TBICR_SPEED1_SET \ |
| 300 | ) |
Felix Radensky | 27f98e0 | 2010-06-28 01:57:39 +0300 | [diff] [blame] | 301 | #endif /* CONFIG_TSEC_TBICR_SETTINGS */ |
Peter Tyser | 583c1f4 | 2009-11-03 17:52:07 -0600 | [diff] [blame] | 302 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 303 | /* Configure the TBI for SGMII operation */ |
| 304 | static void tsec_configure_serdes(struct tsec_private *priv) |
| 305 | { |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 306 | /* Access TBI PHY registers at given TSEC register offset as opposed |
| 307 | * to the register offset used for external PHY accesses */ |
Sandeep Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 308 | tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_ANA, |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 309 | TBIANA_SETTINGS); |
Sandeep Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 310 | tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_TBICON, |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 311 | TBICON_CLK_SELECT); |
Sandeep Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 312 | tsec_local_mdio_write(priv->phyregs_sgmii, priv->regs->tbipa, TBI_CR, |
Kumar Gala | c1457f9 | 2010-12-01 22:55:54 -0600 | [diff] [blame] | 313 | CONFIG_TSEC_TBICR_SETTINGS); |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 314 | } |
michael.firth@bt.com | 0838484 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 315 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 316 | /* Discover which PHY is attached to the device, and configure it |
| 317 | * properly. If the PHY is not recognized, then return 0 |
| 318 | * (failure). Otherwise, return 1 |
| 319 | */ |
| 320 | static int init_phy(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 321 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 322 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 323 | struct phy_info *curphy; |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 324 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 325 | |
| 326 | /* Assign a Physical address to the TBI */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 327 | regs->tbipa = CONFIG_SYS_TBIPA_VALUE; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 328 | asm("sync"); |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 329 | |
| 330 | /* Reset MII (due to new addresses) */ |
| 331 | priv->phyregs->miimcfg = MIIMCFG_RESET; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 332 | asm("sync"); |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 333 | priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 334 | asm("sync"); |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 335 | while (priv->phyregs->miimind & MIIMIND_BUSY) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 336 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 337 | /* Get the cmd structure corresponding to the attached |
| 338 | * PHY */ |
| 339 | curphy = get_phy_info(dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 340 | |
Ben Warren | f11eefb | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 341 | if (curphy == NULL) { |
| 342 | priv->phyinfo = NULL; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 343 | printf("%s: No PHY found\n", dev->name); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 344 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 345 | return 0; |
| 346 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 347 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 348 | if (regs->ecntrl & ECNTRL_SGMII_MODE) |
| 349 | tsec_configure_serdes(priv); |
| 350 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 351 | priv->phyinfo = curphy; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 352 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 353 | phy_run_commands(priv, priv->phyinfo->config); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 354 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 355 | return 1; |
| 356 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 357 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 358 | /* |
| 359 | * Returns which value to write to the control register. |
| 360 | * For 10/100, the value is slightly different |
| 361 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 362 | static uint mii_cr_init(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 363 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 364 | if (priv->flags & TSEC_GIGABIT) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 365 | return MIIM_CONTROL_INIT; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 366 | else |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 367 | return MIIM_CR_INIT; |
| 368 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 369 | |
Peter Tyser | 4c84fd5 | 2009-02-04 15:14:05 -0600 | [diff] [blame] | 370 | /* |
| 371 | * Wait for auto-negotiation to complete, then determine link |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 372 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 373 | static uint mii_parse_sr(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 374 | { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 375 | /* |
Andy Fleming | 4eb3dcf | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 376 | * Wait if the link is up, and autonegotiation is in progress |
| 377 | * (ie - we're capable and it's not done) |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 378 | */ |
| 379 | mii_reg = read_phy_reg(priv, MIIM_STATUS); |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 380 | if ((mii_reg & BMSR_ANEGCAPABLE) && !(mii_reg & BMSR_ANEGCOMPLETE)) { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 381 | int i = 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 382 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 383 | puts("Waiting for PHY auto negotiation to complete"); |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 384 | while (!(mii_reg & BMSR_ANEGCOMPLETE)) { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 385 | /* |
| 386 | * Timeout reached ? |
| 387 | */ |
| 388 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 389 | puts(" TIMEOUT !\n"); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 390 | priv->link = 0; |
Jin Zhengxiong-R64188 | 487d223 | 2006-06-27 18:12:23 +0800 | [diff] [blame] | 391 | return 0; |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 392 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 393 | |
Kim Phillips | ae4dd97 | 2009-08-24 14:32:26 -0500 | [diff] [blame] | 394 | if (ctrlc()) { |
| 395 | puts("user interrupt!\n"); |
| 396 | priv->link = 0; |
| 397 | return -EINTR; |
| 398 | } |
| 399 | |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 400 | if ((i++ % 1000) == 0) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 401 | putc('.'); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 402 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 403 | udelay(1000); /* 1 ms */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 404 | mii_reg = read_phy_reg(priv, MIIM_STATUS); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 405 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 406 | puts(" done\n"); |
Peter Tyser | 4c84fd5 | 2009-02-04 15:14:05 -0600 | [diff] [blame] | 407 | |
| 408 | /* Link status bit is latched low, read it again */ |
| 409 | mii_reg = read_phy_reg(priv, MIIM_STATUS); |
| 410 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 411 | udelay(500000); /* another 500 ms (results in faster booting) */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Peter Tyser | 4c84fd5 | 2009-02-04 15:14:05 -0600 | [diff] [blame] | 414 | priv->link = mii_reg & MIIM_STATUS_LINK ? 1 : 0; |
| 415 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 419 | /* Generic function which updates the speed and duplex. If |
| 420 | * autonegotiation is enabled, it uses the AND of the link |
| 421 | * partner's advertised capabilities and our advertised |
| 422 | * capabilities. If autonegotiation is disabled, we use the |
| 423 | * appropriate bits in the control register. |
| 424 | * |
| 425 | * Stolen from Linux's mii.c and phy_device.c |
| 426 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 427 | static uint mii_parse_link(uint mii_reg, struct tsec_private *priv) |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 428 | { |
| 429 | /* We're using autonegotiation */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 430 | if (mii_reg & BMSR_ANEGCAPABLE) { |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 431 | uint lpa = 0; |
| 432 | uint gblpa = 0; |
| 433 | |
| 434 | /* Check for gigabit capability */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 435 | if (mii_reg & BMSR_ERCAP) { |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 436 | /* We want a list of states supported by |
| 437 | * both PHYs in the link |
| 438 | */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 439 | gblpa = read_phy_reg(priv, MII_STAT1000); |
| 440 | gblpa &= read_phy_reg(priv, MII_CTRL1000) << 2; |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /* Set the baseline so we only have to set them |
| 444 | * if they're different |
| 445 | */ |
| 446 | priv->speed = 10; |
| 447 | priv->duplexity = 0; |
| 448 | |
| 449 | /* Check the gigabit fields */ |
| 450 | if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) { |
| 451 | priv->speed = 1000; |
| 452 | |
| 453 | if (gblpa & PHY_1000BTSR_1000FD) |
| 454 | priv->duplexity = 1; |
| 455 | |
| 456 | /* We're done! */ |
| 457 | return 0; |
| 458 | } |
| 459 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 460 | lpa = read_phy_reg(priv, MII_ADVERTISE); |
| 461 | lpa &= read_phy_reg(priv, MII_LPA); |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 462 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 463 | if (lpa & (LPA_100FULL | LPA_100HALF)) { |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 464 | priv->speed = 100; |
| 465 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 466 | if (lpa & LPA_100FULL) |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 467 | priv->duplexity = 1; |
| 468 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 469 | } else if (lpa & LPA_10FULL) |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 470 | priv->duplexity = 1; |
| 471 | } else { |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 472 | uint bmcr = read_phy_reg(priv, MII_BMCR); |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 473 | |
| 474 | priv->speed = 10; |
| 475 | priv->duplexity = 0; |
| 476 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 477 | if (bmcr & BMCR_FULLDPLX) |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 478 | priv->duplexity = 1; |
| 479 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 480 | if (bmcr & BMCR_SPEED1000) |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 481 | priv->speed = 1000; |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 482 | else if (bmcr & BMCR_SPEED100) |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 483 | priv->speed = 100; |
| 484 | } |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 489 | /* |
Zach LeRoy | ddb7fc7 | 2009-05-22 10:26:33 -0500 | [diff] [blame] | 490 | * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain |
| 491 | * circumstances. eg a gigabit TSEC connected to a gigabit switch with |
| 492 | * a 4-wire ethernet cable. Both ends advertise gigabit, but can't |
| 493 | * link. "Ethernet@Wirespeed" reduces advertised speed until link |
| 494 | * can be achieved. |
| 495 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 496 | static uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv) |
Zach LeRoy | ddb7fc7 | 2009-05-22 10:26:33 -0500 | [diff] [blame] | 497 | { |
| 498 | return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010; |
| 499 | } |
| 500 | |
| 501 | /* |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 502 | * Parse the BCM54xx status register for speed and duplex information. |
| 503 | * The linux sungem_phy has this information, but in a table format. |
| 504 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 505 | static uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv) |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 506 | { |
Peter Tyser | f672290 | 2009-11-09 13:09:44 -0600 | [diff] [blame] | 507 | /* If there is no link, speed and duplex don't matter */ |
| 508 | if (!priv->link) |
| 509 | return 0; |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 510 | |
Peter Tyser | f672290 | 2009-11-09 13:09:44 -0600 | [diff] [blame] | 511 | switch ((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> |
| 512 | MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT) { |
| 513 | case 1: |
| 514 | priv->duplexity = 0; |
| 515 | priv->speed = 10; |
| 516 | break; |
| 517 | case 2: |
| 518 | priv->duplexity = 1; |
| 519 | priv->speed = 10; |
| 520 | break; |
| 521 | case 3: |
| 522 | priv->duplexity = 0; |
| 523 | priv->speed = 100; |
| 524 | break; |
| 525 | case 5: |
| 526 | priv->duplexity = 1; |
| 527 | priv->speed = 100; |
| 528 | break; |
| 529 | case 6: |
| 530 | priv->duplexity = 0; |
| 531 | priv->speed = 1000; |
| 532 | break; |
| 533 | case 7: |
| 534 | priv->duplexity = 1; |
| 535 | priv->speed = 1000; |
| 536 | break; |
| 537 | default: |
| 538 | printf("Auto-neg error, defaulting to 10BT/HD\n"); |
| 539 | priv->duplexity = 0; |
| 540 | priv->speed = 10; |
| 541 | break; |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | return 0; |
Peter Tyser | 3c93d8b | 2009-11-09 13:09:47 -0600 | [diff] [blame] | 545 | } |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 546 | |
Peter Tyser | 3c93d8b | 2009-11-09 13:09:47 -0600 | [diff] [blame] | 547 | /* |
| 548 | * Find out if PHY is in copper or serdes mode by looking at Expansion Reg |
| 549 | * 0x42 - "Operating Mode Status Register" |
| 550 | */ |
| 551 | static int BCM8482_is_serdes(struct tsec_private *priv) |
| 552 | { |
| 553 | u16 val; |
| 554 | int serdes = 0; |
| 555 | |
| 556 | write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_ER | 0x42); |
| 557 | val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA); |
| 558 | |
| 559 | switch (val & 0x1f) { |
| 560 | case 0x0d: /* RGMII-to-100Base-FX */ |
| 561 | case 0x0e: /* RGMII-to-SGMII */ |
| 562 | case 0x0f: /* RGMII-to-SerDes */ |
| 563 | case 0x12: /* SGMII-to-SerDes */ |
| 564 | case 0x13: /* SGMII-to-100Base-FX */ |
| 565 | case 0x16: /* SerDes-to-Serdes */ |
| 566 | serdes = 1; |
| 567 | break; |
| 568 | case 0x6: /* RGMII-to-Copper */ |
| 569 | case 0x14: /* SGMII-to-Copper */ |
| 570 | case 0x17: /* SerDes-to-Copper */ |
| 571 | break; |
| 572 | default: |
| 573 | printf("ERROR, invalid PHY mode (0x%x\n)", val); |
| 574 | break; |
| 575 | } |
| 576 | |
| 577 | return serdes; |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 578 | } |
Peter Tyser | 3c93d8b | 2009-11-09 13:09:47 -0600 | [diff] [blame] | 579 | |
| 580 | /* |
| 581 | * Determine SerDes link speed and duplex from Expansion reg 0x42 "Operating |
| 582 | * Mode Status Register" |
| 583 | */ |
| 584 | uint mii_parse_BCM5482_serdes_sr(struct tsec_private *priv) |
| 585 | { |
| 586 | u16 val; |
| 587 | int i = 0; |
| 588 | |
| 589 | /* Wait 1s for link - Clause 37 autonegotiation happens very fast */ |
| 590 | while (1) { |
| 591 | write_phy_reg(priv, MIIM_BCM54XX_EXP_SEL, |
| 592 | MIIM_BCM54XX_EXP_SEL_ER | 0x42); |
| 593 | val = read_phy_reg(priv, MIIM_BCM54XX_EXP_DATA); |
| 594 | |
| 595 | if (val & 0x8000) |
| 596 | break; |
| 597 | |
| 598 | if (i++ > 1000) { |
| 599 | priv->link = 0; |
| 600 | return 1; |
| 601 | } |
| 602 | |
| 603 | udelay(1000); /* 1 ms */ |
| 604 | } |
| 605 | |
| 606 | priv->link = 1; |
| 607 | switch ((val >> 13) & 0x3) { |
| 608 | case (0x00): |
| 609 | priv->speed = 10; |
| 610 | break; |
| 611 | case (0x01): |
| 612 | priv->speed = 100; |
| 613 | break; |
| 614 | case (0x02): |
| 615 | priv->speed = 1000; |
| 616 | break; |
| 617 | } |
| 618 | |
| 619 | priv->duplexity = (val & 0x1000) == 0x1000; |
| 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * Figure out if BCM5482 is in serdes or copper mode and determine link |
| 626 | * configuration accordingly |
| 627 | */ |
| 628 | static uint mii_parse_BCM5482_sr(uint mii_reg, struct tsec_private *priv) |
| 629 | { |
| 630 | if (BCM8482_is_serdes(priv)) { |
| 631 | mii_parse_BCM5482_serdes_sr(priv); |
Peter Tyser | 94f63a7 | 2009-11-09 13:09:48 -0600 | [diff] [blame] | 632 | priv->flags |= TSEC_FIBER; |
Peter Tyser | 3c93d8b | 2009-11-09 13:09:47 -0600 | [diff] [blame] | 633 | } else { |
| 634 | /* Wait for auto-negotiation to complete or fail */ |
| 635 | mii_parse_sr(mii_reg, priv); |
| 636 | |
| 637 | /* Parse BCM54xx copper aux status register */ |
| 638 | mii_reg = read_phy_reg(priv, MIIM_BCM54xx_AUXSTATUS); |
| 639 | mii_parse_BCM54xx_sr(mii_reg, priv); |
| 640 | } |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 645 | /* Parse the 88E1011's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 646 | * information |
| 647 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 648 | static uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 649 | { |
| 650 | uint speed; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 651 | |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 652 | mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS); |
| 653 | |
Andy Fleming | 4eb3dcf | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 654 | if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) && |
| 655 | !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 656 | int i = 0; |
| 657 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 658 | puts("Waiting for PHY realtime link"); |
Andy Fleming | 4eb3dcf | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 659 | while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) { |
| 660 | /* Timeout reached ? */ |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 661 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 662 | puts(" TIMEOUT !\n"); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 663 | priv->link = 0; |
| 664 | break; |
| 665 | } |
| 666 | |
| 667 | if ((i++ % 1000) == 0) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 668 | putc('.'); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 669 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 670 | udelay(1000); /* 1 ms */ |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 671 | mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS); |
| 672 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 673 | puts(" done\n"); |
| 674 | udelay(500000); /* another 500 ms (results in faster booting) */ |
Andy Fleming | 4eb3dcf | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 675 | } else { |
| 676 | if (mii_reg & MIIM_88E1011_PHYSTAT_LINK) |
| 677 | priv->link = 1; |
| 678 | else |
| 679 | priv->link = 0; |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 682 | if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 683 | priv->duplexity = 1; |
| 684 | else |
| 685 | priv->duplexity = 0; |
| 686 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 687 | speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 688 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 689 | switch (speed) { |
| 690 | case MIIM_88E1011_PHYSTAT_GBIT: |
| 691 | priv->speed = 1000; |
| 692 | break; |
| 693 | case MIIM_88E1011_PHYSTAT_100: |
| 694 | priv->speed = 100; |
| 695 | break; |
| 696 | default: |
| 697 | priv->speed = 10; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 698 | } |
| 699 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 700 | return 0; |
| 701 | } |
| 702 | |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 703 | /* Parse the RTL8211B's status register for speed and duplex |
| 704 | * information |
| 705 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 706 | static uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv) |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 707 | { |
| 708 | uint speed; |
| 709 | |
| 710 | mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS); |
Anton Vorontsov | 91112ec | 2008-03-14 23:20:30 +0300 | [diff] [blame] | 711 | if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) { |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 712 | int i = 0; |
| 713 | |
Anton Vorontsov | 91112ec | 2008-03-14 23:20:30 +0300 | [diff] [blame] | 714 | /* in case of timeout ->link is cleared */ |
| 715 | priv->link = 1; |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 716 | puts("Waiting for PHY realtime link"); |
| 717 | while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) { |
| 718 | /* Timeout reached ? */ |
| 719 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
| 720 | puts(" TIMEOUT !\n"); |
| 721 | priv->link = 0; |
| 722 | break; |
| 723 | } |
| 724 | |
| 725 | if ((i++ % 1000) == 0) { |
| 726 | putc('.'); |
| 727 | } |
| 728 | udelay(1000); /* 1 ms */ |
| 729 | mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS); |
| 730 | } |
| 731 | puts(" done\n"); |
| 732 | udelay(500000); /* another 500 ms (results in faster booting) */ |
| 733 | } else { |
| 734 | if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK) |
| 735 | priv->link = 1; |
| 736 | else |
| 737 | priv->link = 0; |
| 738 | } |
| 739 | |
| 740 | if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX) |
| 741 | priv->duplexity = 1; |
| 742 | else |
| 743 | priv->duplexity = 0; |
| 744 | |
| 745 | speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED); |
| 746 | |
| 747 | switch (speed) { |
| 748 | case MIIM_RTL8211B_PHYSTAT_GBIT: |
| 749 | priv->speed = 1000; |
| 750 | break; |
| 751 | case MIIM_RTL8211B_PHYSTAT_100: |
| 752 | priv->speed = 100; |
| 753 | break; |
| 754 | default: |
| 755 | priv->speed = 10; |
| 756 | } |
| 757 | |
| 758 | return 0; |
| 759 | } |
| 760 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 761 | /* Parse the cis8201's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 762 | * information |
| 763 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 764 | static uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 765 | { |
| 766 | uint speed; |
| 767 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 768 | if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 769 | priv->duplexity = 1; |
| 770 | else |
| 771 | priv->duplexity = 0; |
| 772 | |
| 773 | speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 774 | switch (speed) { |
| 775 | case MIIM_CIS8201_AUXCONSTAT_GBIT: |
| 776 | priv->speed = 1000; |
| 777 | break; |
| 778 | case MIIM_CIS8201_AUXCONSTAT_100: |
| 779 | priv->speed = 100; |
| 780 | break; |
| 781 | default: |
| 782 | priv->speed = 10; |
| 783 | break; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 784 | } |
| 785 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 786 | return 0; |
| 787 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 788 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 789 | /* Parse the vsc8244's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 790 | * information |
| 791 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 792 | static uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 793 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 794 | uint speed; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 795 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 796 | if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX) |
| 797 | priv->duplexity = 1; |
| 798 | else |
| 799 | priv->duplexity = 0; |
| 800 | |
| 801 | speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED; |
| 802 | switch (speed) { |
| 803 | case MIIM_VSC8244_AUXCONSTAT_GBIT: |
| 804 | priv->speed = 1000; |
| 805 | break; |
| 806 | case MIIM_VSC8244_AUXCONSTAT_100: |
| 807 | priv->speed = 100; |
| 808 | break; |
| 809 | default: |
| 810 | priv->speed = 10; |
| 811 | break; |
| 812 | } |
| 813 | |
| 814 | return 0; |
| 815 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 816 | |
| 817 | /* Parse the DM9161's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 818 | * information |
| 819 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 820 | static uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 821 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 822 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H)) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 823 | priv->speed = 100; |
| 824 | else |
| 825 | priv->speed = 10; |
| 826 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 827 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F)) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 828 | priv->duplexity = 1; |
| 829 | else |
| 830 | priv->duplexity = 0; |
| 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 835 | /* |
| 836 | * Hack to write all 4 PHYs with the LED values |
| 837 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 838 | static uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 839 | { |
| 840 | uint phyid; |
Sandeep Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 841 | volatile tsec_mdio_t *regbase = priv->phyregs; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 842 | int timeout = 1000000; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 843 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 844 | for (phyid = 0; phyid < 4; phyid++) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 845 | regbase->miimadd = (phyid << 8) | mii_reg; |
| 846 | regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 847 | asm("sync"); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 848 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 849 | timeout = 1000000; |
| 850 | while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 851 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 852 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 853 | return MIIM_CIS8204_SLEDCON_INIT; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 856 | static uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv) |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 857 | { |
| 858 | if (priv->flags & TSEC_REDUCED) |
| 859 | return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII; |
| 860 | else |
| 861 | return MIIM_CIS8204_EPHYCON_INIT; |
| 862 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 863 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 864 | static uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv) |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 865 | { |
| 866 | uint mii_data = read_phy_reg(priv, mii_reg); |
| 867 | |
| 868 | if (priv->flags & TSEC_REDUCED) |
| 869 | mii_data = (mii_data & 0xfff0) | 0x000b; |
| 870 | return mii_data; |
| 871 | } |
| 872 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 873 | /* Initialized required registers to appropriate values, zeroing |
| 874 | * those we don't care about (unless zero is bad, in which case, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 875 | * choose a more appropriate value) |
| 876 | */ |
| 877 | static void init_registers(volatile tsec_t * regs) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 878 | { |
| 879 | /* Clear IEVENT */ |
| 880 | regs->ievent = IEVENT_INIT_CLEAR; |
| 881 | |
| 882 | regs->imask = IMASK_INIT_CLEAR; |
| 883 | |
| 884 | regs->hash.iaddr0 = 0; |
| 885 | regs->hash.iaddr1 = 0; |
| 886 | regs->hash.iaddr2 = 0; |
| 887 | regs->hash.iaddr3 = 0; |
| 888 | regs->hash.iaddr4 = 0; |
| 889 | regs->hash.iaddr5 = 0; |
| 890 | regs->hash.iaddr6 = 0; |
| 891 | regs->hash.iaddr7 = 0; |
| 892 | |
| 893 | regs->hash.gaddr0 = 0; |
| 894 | regs->hash.gaddr1 = 0; |
| 895 | regs->hash.gaddr2 = 0; |
| 896 | regs->hash.gaddr3 = 0; |
| 897 | regs->hash.gaddr4 = 0; |
| 898 | regs->hash.gaddr5 = 0; |
| 899 | regs->hash.gaddr6 = 0; |
| 900 | regs->hash.gaddr7 = 0; |
| 901 | |
| 902 | regs->rctrl = 0x00000000; |
| 903 | |
| 904 | /* Init RMON mib registers */ |
| 905 | memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t)); |
| 906 | |
| 907 | regs->rmon.cam1 = 0xffffffff; |
| 908 | regs->rmon.cam2 = 0xffffffff; |
| 909 | |
| 910 | regs->mrblr = MRBLR_INIT_SETTINGS; |
| 911 | |
| 912 | regs->minflr = MINFLR_INIT_SETTINGS; |
| 913 | |
| 914 | regs->attr = ATTR_INIT_SETTINGS; |
| 915 | regs->attreli = ATTRELI_INIT_SETTINGS; |
| 916 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 917 | } |
| 918 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 919 | /* Configure maccfg2 based on negotiated speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 920 | * reported by PHY handling code |
| 921 | */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 922 | static void adjust_link(struct eth_device *dev) |
| 923 | { |
| 924 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 925 | volatile tsec_t *regs = priv->regs; |
| 926 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 927 | if (priv->link) { |
| 928 | if (priv->duplexity != 0) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 929 | regs->maccfg2 |= MACCFG2_FULL_DUPLEX; |
| 930 | else |
| 931 | regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX); |
| 932 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 933 | switch (priv->speed) { |
| 934 | case 1000: |
| 935 | regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF)) |
| 936 | | MACCFG2_GMII); |
| 937 | break; |
| 938 | case 100: |
| 939 | case 10: |
| 940 | regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF)) |
| 941 | | MACCFG2_MII); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 942 | |
Nick Spence | ec9670b | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 943 | /* Set R100 bit in all modes although |
| 944 | * it is only used in RGMII mode |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 945 | */ |
Nick Spence | ec9670b | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 946 | if (priv->speed == 100) |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 947 | regs->ecntrl |= ECNTRL_R100; |
| 948 | else |
| 949 | regs->ecntrl &= ~(ECNTRL_R100); |
| 950 | break; |
| 951 | default: |
| 952 | printf("%s: Speed was bad\n", dev->name); |
| 953 | break; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Peter Tyser | 94f63a7 | 2009-11-09 13:09:48 -0600 | [diff] [blame] | 956 | printf("Speed: %d, %s duplex%s\n", priv->speed, |
| 957 | (priv->duplexity) ? "full" : "half", |
| 958 | (priv->flags & TSEC_FIBER) ? ", fiber mode" : ""); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 959 | |
| 960 | } else { |
| 961 | printf("%s: No link.\n", dev->name); |
| 962 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 963 | } |
| 964 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 965 | /* Set up the buffers and their descriptors, and bring up the |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 966 | * interface |
| 967 | */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 968 | static void startup_tsec(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 969 | { |
| 970 | int i; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 971 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 972 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 973 | |
| 974 | /* Point to the buffer descriptors */ |
| 975 | regs->tbase = (unsigned int)(&rtx.txbd[txIdx]); |
| 976 | regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]); |
| 977 | |
| 978 | /* Initialize the Rx Buffer descriptors */ |
| 979 | for (i = 0; i < PKTBUFSRX; i++) { |
| 980 | rtx.rxbd[i].status = RXBD_EMPTY; |
| 981 | rtx.rxbd[i].length = 0; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 982 | rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i]; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 983 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 984 | rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 985 | |
| 986 | /* Initialize the TX Buffer Descriptors */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 987 | for (i = 0; i < TX_BUF_CNT; i++) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 988 | rtx.txbd[i].status = 0; |
| 989 | rtx.txbd[i].length = 0; |
| 990 | rtx.txbd[i].bufPtr = 0; |
| 991 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 992 | rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 993 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 994 | /* Start up the PHY */ |
Ben Warren | f11eefb | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 995 | if(priv->phyinfo) |
| 996 | phy_run_commands(priv, priv->phyinfo->startup); |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 997 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 998 | adjust_link(dev); |
| 999 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1000 | /* Enable Transmit and Receive */ |
| 1001 | regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN); |
| 1002 | |
| 1003 | /* Tell the DMA it is clear to go */ |
| 1004 | regs->dmactrl |= DMACTRL_INIT_SETTINGS; |
| 1005 | regs->tstat = TSTAT_CLEAR_THALT; |
Dan Wilson | e3d7d6b | 2007-10-19 11:33:48 -0500 | [diff] [blame] | 1006 | regs->rstat = RSTAT_CLEAR_RHALT; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1007 | regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS); |
| 1008 | } |
| 1009 | |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1010 | /* This returns the status bits of the device. The return value |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1011 | * is never checked, and this is what the 8260 driver did, so we |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1012 | * do the same. Presumably, this would be zero if there were no |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1013 | * errors |
| 1014 | */ |
| 1015 | static int tsec_send(struct eth_device *dev, volatile void *packet, int length) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1016 | { |
| 1017 | int i; |
| 1018 | int result = 0; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1019 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 1020 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1021 | |
| 1022 | /* Find an empty buffer descriptor */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1023 | for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1024 | if (i >= TOUT_LOOP) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1025 | debug("%s: tsec: tx buffers full\n", dev->name); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1026 | return result; |
| 1027 | } |
| 1028 | } |
| 1029 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1030 | rtx.txbd[txIdx].bufPtr = (uint) packet; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1031 | rtx.txbd[txIdx].length = length; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1032 | rtx.txbd[txIdx].status |= |
| 1033 | (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1034 | |
| 1035 | /* Tell the DMA to go */ |
| 1036 | regs->tstat = TSTAT_CLEAR_THALT; |
| 1037 | |
| 1038 | /* Wait for buffer to be transmitted */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1039 | for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1040 | if (i >= TOUT_LOOP) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1041 | debug("%s: tsec: tx error\n", dev->name); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1042 | return result; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | txIdx = (txIdx + 1) % TX_BUF_CNT; |
| 1047 | result = rtx.txbd[txIdx].status & TXBD_STATS; |
| 1048 | |
| 1049 | return result; |
| 1050 | } |
| 1051 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1052 | static int tsec_recv(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1053 | { |
| 1054 | int length; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1055 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 1056 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1057 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1058 | while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1059 | |
| 1060 | length = rtx.rxbd[rxIdx].length; |
| 1061 | |
| 1062 | /* Send the packet up if there were no errors */ |
| 1063 | if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) { |
| 1064 | NetReceive(NetRxPackets[rxIdx], length - 4); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1065 | } else { |
| 1066 | printf("Got error %x\n", |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1067 | (rtx.rxbd[rxIdx].status & RXBD_STATS)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | rtx.rxbd[rxIdx].length = 0; |
| 1071 | |
| 1072 | /* Set the wrap bit if this is the last element in the list */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1073 | rtx.rxbd[rxIdx].status = |
| 1074 | RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1075 | |
| 1076 | rxIdx = (rxIdx + 1) % PKTBUFSRX; |
| 1077 | } |
| 1078 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1079 | if (regs->ievent & IEVENT_BSY) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1080 | regs->ievent = IEVENT_BSY; |
| 1081 | regs->rstat = RSTAT_CLEAR_RHALT; |
| 1082 | } |
| 1083 | |
| 1084 | return -1; |
| 1085 | |
| 1086 | } |
| 1087 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1088 | /* Stop the interface */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1089 | static void tsec_halt(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1090 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1091 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 1092 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1093 | |
| 1094 | regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS); |
| 1095 | regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS); |
| 1096 | |
Andy Fleming | 1899777 | 2010-04-19 14:54:49 -0500 | [diff] [blame] | 1097 | while ((regs->ievent & (IEVENT_GRSC | IEVENT_GTSC)) |
| 1098 | != (IEVENT_GRSC | IEVENT_GTSC)) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1099 | |
| 1100 | regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN); |
| 1101 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1102 | /* Shut down the PHY, as needed */ |
Ben Warren | f11eefb | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 1103 | if(priv->phyinfo) |
| 1104 | phy_run_commands(priv, priv->phyinfo->shutdown); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1107 | static struct phy_info phy_info_M88E1149S = { |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1108 | 0x1410ca, |
| 1109 | "Marvell 88E1149S", |
| 1110 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1111 | (struct phy_cmd[]) { /* config */ |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1112 | /* Reset and configure the PHY */ |
| 1113 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1114 | {0x1d, 0x1f, NULL}, |
| 1115 | {0x1e, 0x200c, NULL}, |
| 1116 | {0x1d, 0x5, NULL}, |
| 1117 | {0x1e, 0x0, NULL}, |
| 1118 | {0x1e, 0x100, NULL}, |
| 1119 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1120 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1121 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1122 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1123 | {miim_end,} |
| 1124 | }, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1125 | (struct phy_cmd[]) { /* startup */ |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1126 | /* Status is read once to clear old link state */ |
| 1127 | {MIIM_STATUS, miim_read, NULL}, |
| 1128 | /* Auto-negotiate */ |
| 1129 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1130 | /* Read the status */ |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1131 | {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr}, |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1132 | {miim_end,} |
| 1133 | }, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1134 | (struct phy_cmd[]) { /* shutdown */ |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1135 | {miim_end,} |
| 1136 | }, |
Andy Fleming | bee6700 | 2007-08-03 04:05:25 -0500 | [diff] [blame] | 1137 | }; |
| 1138 | |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 1139 | /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1140 | static struct phy_info phy_info_BCM5461S = { |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 1141 | 0x02060c1, /* 5461 ID */ |
| 1142 | "Broadcom BCM5461S", |
| 1143 | 0, /* not clear to me what minor revisions we can shift away */ |
| 1144 | (struct phy_cmd[]) { /* config */ |
| 1145 | /* Reset and configure the PHY */ |
| 1146 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1147 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1148 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1149 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1150 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1151 | {miim_end,} |
| 1152 | }, |
| 1153 | (struct phy_cmd[]) { /* startup */ |
| 1154 | /* Status is read once to clear old link state */ |
| 1155 | {MIIM_STATUS, miim_read, NULL}, |
| 1156 | /* Auto-negotiate */ |
| 1157 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1158 | /* Read the status */ |
| 1159 | {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr}, |
| 1160 | {miim_end,} |
| 1161 | }, |
| 1162 | (struct phy_cmd[]) { /* shutdown */ |
| 1163 | {miim_end,} |
| 1164 | }, |
| 1165 | }; |
| 1166 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1167 | static struct phy_info phy_info_BCM5464S = { |
Joe Hamman | ed7ad4e | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1168 | 0x02060b1, /* 5464 ID */ |
| 1169 | "Broadcom BCM5464S", |
| 1170 | 0, /* not clear to me what minor revisions we can shift away */ |
| 1171 | (struct phy_cmd[]) { /* config */ |
| 1172 | /* Reset and configure the PHY */ |
| 1173 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1174 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1175 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1176 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
Zach LeRoy | ddb7fc7 | 2009-05-22 10:26:33 -0500 | [diff] [blame] | 1177 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1178 | {miim_end,} |
| 1179 | }, |
| 1180 | (struct phy_cmd[]) { /* startup */ |
| 1181 | /* Status is read once to clear old link state */ |
| 1182 | {MIIM_STATUS, miim_read, NULL}, |
| 1183 | /* Auto-negotiate */ |
| 1184 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1185 | /* Read the status */ |
| 1186 | {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr}, |
| 1187 | {miim_end,} |
| 1188 | }, |
| 1189 | (struct phy_cmd[]) { /* shutdown */ |
| 1190 | {miim_end,} |
| 1191 | }, |
| 1192 | }; |
| 1193 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1194 | static struct phy_info phy_info_BCM5482S = { |
Zach LeRoy | ddb7fc7 | 2009-05-22 10:26:33 -0500 | [diff] [blame] | 1195 | 0x0143bcb, |
| 1196 | "Broadcom BCM5482S", |
| 1197 | 4, |
| 1198 | (struct phy_cmd[]) { /* config */ |
| 1199 | /* Reset and configure the PHY */ |
| 1200 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1201 | /* Setup read from auxilary control shadow register 7 */ |
| 1202 | {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL}, |
| 1203 | /* Read Misc Control register and or in Ethernet@Wirespeed */ |
| 1204 | {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed}, |
Joe Hamman | ed7ad4e | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1205 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
Peter Tyser | 3c93d8b | 2009-11-09 13:09:47 -0600 | [diff] [blame] | 1206 | /* Initial config/enable of secondary SerDes interface */ |
| 1207 | {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf), NULL}, |
| 1208 | /* Write intial value to secondary SerDes Contol */ |
| 1209 | {MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_SSD | 0, NULL}, |
| 1210 | {MIIM_BCM54XX_EXP_DATA, MIIM_CONTROL_RESTART, NULL}, |
| 1211 | /* Enable copper/fiber auto-detect */ |
| 1212 | {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201)}, |
Joe Hamman | ed7ad4e | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1213 | {miim_end,} |
| 1214 | }, |
| 1215 | (struct phy_cmd[]) { /* startup */ |
| 1216 | /* Status is read once to clear old link state */ |
| 1217 | {MIIM_STATUS, miim_read, NULL}, |
Peter Tyser | 3c93d8b | 2009-11-09 13:09:47 -0600 | [diff] [blame] | 1218 | /* Determine copper/fiber, auto-negotiate, and read the result */ |
| 1219 | {MIIM_STATUS, miim_read, &mii_parse_BCM5482_sr}, |
Joe Hamman | ed7ad4e | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1220 | {miim_end,} |
| 1221 | }, |
| 1222 | (struct phy_cmd[]) { /* shutdown */ |
| 1223 | {miim_end,} |
| 1224 | }, |
| 1225 | }; |
| 1226 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1227 | static struct phy_info phy_info_M88E1011S = { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1228 | 0x01410c6, |
| 1229 | "Marvell 88E1011S", |
| 1230 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1231 | (struct phy_cmd[]) { /* config */ |
| 1232 | /* Reset and configure the PHY */ |
| 1233 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1234 | {0x1d, 0x1f, NULL}, |
| 1235 | {0x1e, 0x200c, NULL}, |
| 1236 | {0x1d, 0x5, NULL}, |
| 1237 | {0x1e, 0x0, NULL}, |
| 1238 | {0x1e, 0x100, NULL}, |
| 1239 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1240 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1241 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1242 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1243 | {miim_end,} |
| 1244 | }, |
| 1245 | (struct phy_cmd[]) { /* startup */ |
| 1246 | /* Status is read once to clear old link state */ |
| 1247 | {MIIM_STATUS, miim_read, NULL}, |
| 1248 | /* Auto-negotiate */ |
| 1249 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1250 | /* Read the status */ |
| 1251 | {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr}, |
| 1252 | {miim_end,} |
| 1253 | }, |
| 1254 | (struct phy_cmd[]) { /* shutdown */ |
| 1255 | {miim_end,} |
| 1256 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1257 | }; |
| 1258 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1259 | static struct phy_info phy_info_M88E1111S = { |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1260 | 0x01410cc, |
| 1261 | "Marvell 88E1111S", |
| 1262 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1263 | (struct phy_cmd[]) { /* config */ |
| 1264 | /* Reset and configure the PHY */ |
| 1265 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1266 | {0x1b, 0x848f, &mii_m88e1111s_setmode}, |
| 1267 | {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */ |
| 1268 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1269 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1270 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1271 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1272 | {miim_end,} |
| 1273 | }, |
| 1274 | (struct phy_cmd[]) { /* startup */ |
| 1275 | /* Status is read once to clear old link state */ |
| 1276 | {MIIM_STATUS, miim_read, NULL}, |
| 1277 | /* Auto-negotiate */ |
| 1278 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1279 | /* Read the status */ |
| 1280 | {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr}, |
| 1281 | {miim_end,} |
| 1282 | }, |
| 1283 | (struct phy_cmd[]) { /* shutdown */ |
| 1284 | {miim_end,} |
| 1285 | }, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1286 | }; |
| 1287 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1288 | static struct phy_info phy_info_M88E1118 = { |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1289 | 0x01410e1, |
| 1290 | "Marvell 88E1118", |
| 1291 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1292 | (struct phy_cmd[]) { /* config */ |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1293 | /* Reset and configure the PHY */ |
| 1294 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1295 | {0x16, 0x0002, NULL}, /* Change Page Number */ |
| 1296 | {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */ |
Ron Madrid | aa4aac4 | 2009-01-28 16:17:21 -0800 | [diff] [blame] | 1297 | {0x16, 0x0003, NULL}, /* Change Page Number */ |
| 1298 | {0x10, 0x021e, NULL}, /* Adjust LED control */ |
| 1299 | {0x16, 0x0000, NULL}, /* Change Page Number */ |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1300 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1301 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1302 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1303 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1304 | {miim_end,} |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1305 | }, |
| 1306 | (struct phy_cmd[]) { /* startup */ |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1307 | {0x16, 0x0000, NULL}, /* Change Page Number */ |
| 1308 | /* Status is read once to clear old link state */ |
| 1309 | {MIIM_STATUS, miim_read, NULL}, |
| 1310 | /* Auto-negotiate */ |
Ron Madrid | aa4aac4 | 2009-01-28 16:17:21 -0800 | [diff] [blame] | 1311 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1312 | /* Read the status */ |
| 1313 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1314 | &mii_parse_88E1011_psr}, |
| 1315 | {miim_end,} |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1316 | }, |
| 1317 | (struct phy_cmd[]) { /* shutdown */ |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1318 | {miim_end,} |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1319 | }, |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1320 | }; |
| 1321 | |
Sergei Poselenov | 7d4a2c3 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1322 | /* |
| 1323 | * Since to access LED register we need do switch the page, we |
| 1324 | * do LED configuring in the miim_read-like function as follows |
| 1325 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1326 | static uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv) |
Sergei Poselenov | 7d4a2c3 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1327 | { |
| 1328 | uint pg; |
| 1329 | |
| 1330 | /* Switch the page to access the led register */ |
| 1331 | pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE); |
| 1332 | write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE); |
| 1333 | |
| 1334 | /* Configure leds */ |
| 1335 | write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL, |
| 1336 | MIIM_88E1121_PHY_LED_DEF); |
| 1337 | |
| 1338 | /* Restore the page pointer */ |
| 1339 | write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg); |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1343 | static struct phy_info phy_info_M88E1121R = { |
Sergei Poselenov | 7d4a2c3 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1344 | 0x01410cb, |
| 1345 | "Marvell 88E1121R", |
| 1346 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1347 | (struct phy_cmd[]) { /* config */ |
| 1348 | /* Reset and configure the PHY */ |
| 1349 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1350 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1351 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1352 | /* Configure leds */ |
| 1353 | {MIIM_88E1121_PHY_LED_CTRL, miim_read, &mii_88E1121_set_led}, |
| 1354 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1355 | /* Disable IRQs and de-assert interrupt */ |
| 1356 | {MIIM_88E1121_PHY_IRQ_EN, 0, NULL}, |
| 1357 | {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL}, |
| 1358 | {miim_end,} |
| 1359 | }, |
| 1360 | (struct phy_cmd[]) { /* startup */ |
| 1361 | /* Status is read once to clear old link state */ |
| 1362 | {MIIM_STATUS, miim_read, NULL}, |
| 1363 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1364 | {MIIM_STATUS, miim_read, &mii_parse_link}, |
| 1365 | {miim_end,} |
| 1366 | }, |
| 1367 | (struct phy_cmd[]) { /* shutdown */ |
| 1368 | {miim_end,} |
| 1369 | }, |
Sergei Poselenov | 7d4a2c3 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1370 | }; |
| 1371 | |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1372 | static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv) |
| 1373 | { |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1374 | uint mii_data = read_phy_reg(priv, mii_reg); |
| 1375 | |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1376 | /* Setting MIIM_88E1145_PHY_EXT_CR */ |
| 1377 | if (priv->flags & TSEC_REDUCED) |
| 1378 | return mii_data | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1379 | MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY; |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1380 | else |
| 1381 | return mii_data; |
| 1382 | } |
| 1383 | |
| 1384 | static struct phy_info phy_info_M88E1145 = { |
| 1385 | 0x01410cd, |
| 1386 | "Marvell 88E1145", |
| 1387 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1388 | (struct phy_cmd[]) { /* config */ |
| 1389 | /* Reset the PHY */ |
| 1390 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
Andy Fleming | 180d03a | 2007-05-08 17:23:02 -0500 | [diff] [blame] | 1391 | |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1392 | /* Errata E0, E1 */ |
| 1393 | {29, 0x001b, NULL}, |
| 1394 | {30, 0x418f, NULL}, |
| 1395 | {29, 0x0016, NULL}, |
| 1396 | {30, 0xa2da, NULL}, |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1397 | |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1398 | /* Configure the PHY */ |
| 1399 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1400 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1401 | {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, NULL}, |
| 1402 | {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode}, |
| 1403 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1404 | {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL}, |
| 1405 | {miim_end,} |
| 1406 | }, |
| 1407 | (struct phy_cmd[]) { /* startup */ |
| 1408 | /* Status is read once to clear old link state */ |
| 1409 | {MIIM_STATUS, miim_read, NULL}, |
| 1410 | /* Auto-negotiate */ |
| 1411 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1412 | {MIIM_88E1111_PHY_LED_CONTROL, MIIM_88E1111_PHY_LED_DIRECT, NULL}, |
| 1413 | /* Read the Status */ |
| 1414 | {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr}, |
| 1415 | {miim_end,} |
| 1416 | }, |
| 1417 | (struct phy_cmd[]) { /* shutdown */ |
| 1418 | {miim_end,} |
| 1419 | }, |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1420 | }; |
| 1421 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1422 | static struct phy_info phy_info_cis8204 = { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1423 | 0x3f11, |
| 1424 | "Cicada Cis8204", |
| 1425 | 6, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1426 | (struct phy_cmd[]) { /* config */ |
| 1427 | /* Override PHY config settings */ |
| 1428 | {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1429 | /* Configure some basic stuff */ |
| 1430 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1431 | {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT, |
| 1432 | &mii_cis8204_fixled}, |
| 1433 | {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT, |
| 1434 | &mii_cis8204_setmode}, |
| 1435 | {miim_end,} |
| 1436 | }, |
| 1437 | (struct phy_cmd[]) { /* startup */ |
| 1438 | /* Read the Status (2x to make sure link is right) */ |
| 1439 | {MIIM_STATUS, miim_read, NULL}, |
| 1440 | /* Auto-negotiate */ |
| 1441 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1442 | /* Read the status */ |
| 1443 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201}, |
| 1444 | {miim_end,} |
| 1445 | }, |
| 1446 | (struct phy_cmd[]) { /* shutdown */ |
| 1447 | {miim_end,} |
| 1448 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1449 | }; |
| 1450 | |
| 1451 | /* Cicada 8201 */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1452 | static struct phy_info phy_info_cis8201 = { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1453 | 0xfc41, |
| 1454 | "CIS8201", |
| 1455 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1456 | (struct phy_cmd[]) { /* config */ |
| 1457 | /* Override PHY config settings */ |
| 1458 | {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1459 | /* Set up the interface mode */ |
| 1460 | {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL}, |
| 1461 | /* Configure some basic stuff */ |
| 1462 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1463 | {miim_end,} |
| 1464 | }, |
| 1465 | (struct phy_cmd[]) { /* startup */ |
| 1466 | /* Read the Status (2x to make sure link is right) */ |
| 1467 | {MIIM_STATUS, miim_read, NULL}, |
| 1468 | /* Auto-negotiate */ |
| 1469 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1470 | /* Read the status */ |
| 1471 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201}, |
| 1472 | {miim_end,} |
| 1473 | }, |
| 1474 | (struct phy_cmd[]) { /* shutdown */ |
| 1475 | {miim_end,} |
| 1476 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1477 | }; |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1478 | |
| 1479 | static struct phy_info phy_info_VSC8211 = { |
Pieter Henning | 9370c8b | 2009-02-22 23:17:15 -0800 | [diff] [blame] | 1480 | 0xfc4b, |
| 1481 | "Vitesse VSC8211", |
| 1482 | 4, |
| 1483 | (struct phy_cmd[]) { /* config */ |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1484 | /* Override PHY config settings */ |
| 1485 | {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1486 | /* Set up the interface mode */ |
| 1487 | {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL}, |
| 1488 | /* Configure some basic stuff */ |
| 1489 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1490 | {miim_end,} |
| 1491 | }, |
Pieter Henning | 9370c8b | 2009-02-22 23:17:15 -0800 | [diff] [blame] | 1492 | (struct phy_cmd[]) { /* startup */ |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1493 | /* Read the Status (2x to make sure link is right) */ |
| 1494 | {MIIM_STATUS, miim_read, NULL}, |
| 1495 | /* Auto-negotiate */ |
| 1496 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1497 | /* Read the status */ |
| 1498 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201}, |
| 1499 | {miim_end,} |
| 1500 | }, |
Pieter Henning | 9370c8b | 2009-02-22 23:17:15 -0800 | [diff] [blame] | 1501 | (struct phy_cmd[]) { /* shutdown */ |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1502 | {miim_end,} |
Pieter Henning | 9370c8b | 2009-02-22 23:17:15 -0800 | [diff] [blame] | 1503 | }, |
| 1504 | }; |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1505 | |
| 1506 | static struct phy_info phy_info_VSC8244 = { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1507 | 0x3f1b, |
| 1508 | "Vitesse VSC8244", |
| 1509 | 6, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1510 | (struct phy_cmd[]) { /* config */ |
| 1511 | /* Override PHY config settings */ |
| 1512 | /* Configure some basic stuff */ |
| 1513 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1514 | {miim_end,} |
| 1515 | }, |
| 1516 | (struct phy_cmd[]) { /* startup */ |
| 1517 | /* Read the Status (2x to make sure link is right) */ |
| 1518 | {MIIM_STATUS, miim_read, NULL}, |
| 1519 | /* Auto-negotiate */ |
| 1520 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1521 | /* Read the status */ |
| 1522 | {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244}, |
| 1523 | {miim_end,} |
| 1524 | }, |
| 1525 | (struct phy_cmd[]) { /* shutdown */ |
| 1526 | {miim_end,} |
| 1527 | }, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1528 | }; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1529 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1530 | static struct phy_info phy_info_VSC8641 = { |
Poonam Aggrwal | c91b5de | 2009-07-02 16:15:13 +0530 | [diff] [blame] | 1531 | 0x7043, |
| 1532 | "Vitesse VSC8641", |
| 1533 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1534 | (struct phy_cmd[]) { /* config */ |
| 1535 | /* Configure some basic stuff */ |
| 1536 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1537 | {miim_end,} |
| 1538 | }, |
| 1539 | (struct phy_cmd[]) { /* startup */ |
| 1540 | /* Read the Status (2x to make sure link is right) */ |
| 1541 | {MIIM_STATUS, miim_read, NULL}, |
| 1542 | /* Auto-negotiate */ |
| 1543 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1544 | /* Read the status */ |
| 1545 | {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244}, |
| 1546 | {miim_end,} |
| 1547 | }, |
| 1548 | (struct phy_cmd[]) { /* shutdown */ |
| 1549 | {miim_end,} |
| 1550 | }, |
Poonam Aggrwal | c91b5de | 2009-07-02 16:15:13 +0530 | [diff] [blame] | 1551 | }; |
| 1552 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1553 | static struct phy_info phy_info_VSC8221 = { |
Poonam Aggrwal | c91b5de | 2009-07-02 16:15:13 +0530 | [diff] [blame] | 1554 | 0xfc55, |
| 1555 | "Vitesse VSC8221", |
| 1556 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1557 | (struct phy_cmd[]) { /* config */ |
| 1558 | /* Configure some basic stuff */ |
| 1559 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1560 | {miim_end,} |
| 1561 | }, |
| 1562 | (struct phy_cmd[]) { /* startup */ |
| 1563 | /* Read the Status (2x to make sure link is right) */ |
| 1564 | {MIIM_STATUS, miim_read, NULL}, |
| 1565 | /* Auto-negotiate */ |
| 1566 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1567 | /* Read the status */ |
| 1568 | {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244}, |
| 1569 | {miim_end,} |
| 1570 | }, |
| 1571 | (struct phy_cmd[]) { /* shutdown */ |
| 1572 | {miim_end,} |
| 1573 | }, |
Poonam Aggrwal | c91b5de | 2009-07-02 16:15:13 +0530 | [diff] [blame] | 1574 | }; |
| 1575 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1576 | static struct phy_info phy_info_VSC8601 = { |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1577 | 0x00007042, |
| 1578 | "Vitesse VSC8601", |
| 1579 | 4, |
| 1580 | (struct phy_cmd[]) { /* config */ |
| 1581 | /* Override PHY config settings */ |
| 1582 | /* Configure some basic stuff */ |
| 1583 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1584 | #ifdef CONFIG_SYS_VSC8601_SKEWFIX |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1585 | {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL}, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1586 | #if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX) |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1587 | {MIIM_EXT_PAGE_ACCESS,1,NULL}, |
| 1588 | #define VSC8101_SKEW \ |
| 1589 | (CONFIG_SYS_VSC8601_SKEW_TX << 14) | (CONFIG_SYS_VSC8601_SKEW_RX << 12) |
| 1590 | {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL}, |
| 1591 | {MIIM_EXT_PAGE_ACCESS,0,NULL}, |
Andre Schwarz | 1e18be1 | 2008-04-29 19:18:32 +0200 | [diff] [blame] | 1592 | #endif |
Tor Krill | 8b3a82f | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1593 | #endif |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1594 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1595 | {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init}, |
| 1596 | {miim_end,} |
| 1597 | }, |
| 1598 | (struct phy_cmd[]) { /* startup */ |
| 1599 | /* Read the Status (2x to make sure link is right) */ |
| 1600 | {MIIM_STATUS, miim_read, NULL}, |
| 1601 | /* Auto-negotiate */ |
| 1602 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1603 | /* Read the status */ |
| 1604 | {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244}, |
| 1605 | {miim_end,} |
| 1606 | }, |
| 1607 | (struct phy_cmd[]) { /* shutdown */ |
| 1608 | {miim_end,} |
| 1609 | }, |
Tor Krill | 8b3a82f | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1610 | }; |
| 1611 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1612 | static struct phy_info phy_info_dm9161 = { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1613 | 0x0181b88, |
| 1614 | "Davicom DM9161E", |
| 1615 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1616 | (struct phy_cmd[]) { /* config */ |
| 1617 | {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL}, |
| 1618 | /* Do not bypass the scrambler/descrambler */ |
| 1619 | {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL}, |
| 1620 | /* Clear 10BTCSR to default */ |
| 1621 | {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL}, |
| 1622 | /* Configure some basic stuff */ |
| 1623 | {MIIM_CONTROL, MIIM_CR_INIT, NULL}, |
| 1624 | /* Restart Auto Negotiation */ |
| 1625 | {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL}, |
| 1626 | {miim_end,} |
| 1627 | }, |
| 1628 | (struct phy_cmd[]) { /* startup */ |
| 1629 | /* Status is read once to clear old link state */ |
| 1630 | {MIIM_STATUS, miim_read, NULL}, |
| 1631 | /* Auto-negotiate */ |
| 1632 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1633 | /* Read the status */ |
| 1634 | {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr}, |
| 1635 | {miim_end,} |
| 1636 | }, |
| 1637 | (struct phy_cmd[]) { /* shutdown */ |
| 1638 | {miim_end,} |
| 1639 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1640 | }; |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1641 | |
Heiko Schocher | 6d9933f | 2010-07-05 12:23:04 +0200 | [diff] [blame] | 1642 | /* micrel KSZ804 */ |
| 1643 | static struct phy_info phy_info_ksz804 = { |
| 1644 | 0x0022151, |
| 1645 | "Micrel KSZ804 PHY", |
| 1646 | 4, |
| 1647 | (struct phy_cmd[]) { /* config */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 1648 | {MII_BMCR, BMCR_RESET, NULL}, |
| 1649 | {MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART, NULL}, |
Heiko Schocher | 6d9933f | 2010-07-05 12:23:04 +0200 | [diff] [blame] | 1650 | {miim_end,} |
| 1651 | }, |
| 1652 | (struct phy_cmd[]) { /* startup */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 1653 | {MII_BMSR, miim_read, NULL}, |
| 1654 | {MII_BMSR, miim_read, &mii_parse_sr}, |
| 1655 | {MII_BMSR, miim_read, &mii_parse_link}, |
Heiko Schocher | 6d9933f | 2010-07-05 12:23:04 +0200 | [diff] [blame] | 1656 | {miim_end,} |
| 1657 | }, |
| 1658 | (struct phy_cmd[]) { /* shutdown */ |
| 1659 | {miim_end,} |
| 1660 | } |
| 1661 | }; |
| 1662 | |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 1663 | /* a generic flavor. */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1664 | static struct phy_info phy_info_generic = { |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 1665 | 0, |
| 1666 | "Unknown/Generic PHY", |
| 1667 | 32, |
| 1668 | (struct phy_cmd[]) { /* config */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 1669 | {MII_BMCR, BMCR_RESET, NULL}, |
| 1670 | {MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART, NULL}, |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 1671 | {miim_end,} |
| 1672 | }, |
| 1673 | (struct phy_cmd[]) { /* startup */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 1674 | {MII_BMSR, miim_read, NULL}, |
| 1675 | {MII_BMSR, miim_read, &mii_parse_sr}, |
| 1676 | {MII_BMSR, miim_read, &mii_parse_link}, |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 1677 | {miim_end,} |
| 1678 | }, |
| 1679 | (struct phy_cmd[]) { /* shutdown */ |
| 1680 | {miim_end,} |
| 1681 | } |
| 1682 | }; |
| 1683 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1684 | static uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv) |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1685 | { |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1686 | unsigned int speed; |
| 1687 | if (priv->link) { |
| 1688 | speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK; |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1689 | |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1690 | switch (speed) { |
| 1691 | case MIIM_LXT971_SR2_10HDX: |
| 1692 | priv->speed = 10; |
| 1693 | priv->duplexity = 0; |
| 1694 | break; |
| 1695 | case MIIM_LXT971_SR2_10FDX: |
| 1696 | priv->speed = 10; |
| 1697 | priv->duplexity = 1; |
| 1698 | break; |
| 1699 | case MIIM_LXT971_SR2_100HDX: |
| 1700 | priv->speed = 100; |
| 1701 | priv->duplexity = 0; |
urwithsughosh@gmail.com | 34b3f2e | 2007-09-10 14:54:56 -0400 | [diff] [blame] | 1702 | break; |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1703 | default: |
| 1704 | priv->speed = 100; |
| 1705 | priv->duplexity = 1; |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1706 | } |
| 1707 | } else { |
| 1708 | priv->speed = 0; |
| 1709 | priv->duplexity = 0; |
| 1710 | } |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1711 | |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1712 | return 0; |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1715 | static struct phy_info phy_info_lxt971 = { |
| 1716 | 0x0001378e, |
| 1717 | "LXT971", |
| 1718 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1719 | (struct phy_cmd[]) { /* config */ |
| 1720 | {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */ |
| 1721 | {miim_end,} |
| 1722 | }, |
| 1723 | (struct phy_cmd[]) { /* startup - enable interrupts */ |
| 1724 | /* { 0x12, 0x00f2, NULL }, */ |
| 1725 | {MIIM_STATUS, miim_read, NULL}, |
| 1726 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1727 | {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2}, |
| 1728 | {miim_end,} |
| 1729 | }, |
| 1730 | (struct phy_cmd[]) { /* shutdown - disable interrupts */ |
| 1731 | {miim_end,} |
| 1732 | }, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1733 | }; |
| 1734 | |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1735 | /* Parse the DP83865's link and auto-neg status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1736 | * information |
| 1737 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1738 | static uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv) |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1739 | { |
| 1740 | switch (mii_reg & MIIM_DP83865_SPD_MASK) { |
| 1741 | |
| 1742 | case MIIM_DP83865_SPD_1000: |
| 1743 | priv->speed = 1000; |
| 1744 | break; |
| 1745 | |
| 1746 | case MIIM_DP83865_SPD_100: |
| 1747 | priv->speed = 100; |
| 1748 | break; |
| 1749 | |
| 1750 | default: |
| 1751 | priv->speed = 10; |
| 1752 | break; |
| 1753 | |
| 1754 | } |
| 1755 | |
| 1756 | if (mii_reg & MIIM_DP83865_DPX_FULL) |
| 1757 | priv->duplexity = 1; |
| 1758 | else |
| 1759 | priv->duplexity = 0; |
| 1760 | |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1764 | static struct phy_info phy_info_dp83865 = { |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1765 | 0x20005c7, |
| 1766 | "NatSemi DP83865", |
| 1767 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1768 | (struct phy_cmd[]) { /* config */ |
| 1769 | {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL}, |
| 1770 | {miim_end,} |
| 1771 | }, |
| 1772 | (struct phy_cmd[]) { /* startup */ |
| 1773 | /* Status is read once to clear old link state */ |
| 1774 | {MIIM_STATUS, miim_read, NULL}, |
| 1775 | /* Auto-negotiate */ |
| 1776 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1777 | /* Read the link and auto-neg status */ |
| 1778 | {MIIM_DP83865_LANR, miim_read, &mii_parse_dp83865_lanr}, |
| 1779 | {miim_end,} |
| 1780 | }, |
| 1781 | (struct phy_cmd[]) { /* shutdown */ |
| 1782 | {miim_end,} |
| 1783 | }, |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1784 | }; |
| 1785 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1786 | static struct phy_info phy_info_rtl8211b = { |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 1787 | 0x001cc91, |
| 1788 | "RealTek RTL8211B", |
| 1789 | 4, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1790 | (struct phy_cmd[]) { /* config */ |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 1791 | /* Reset and configure the PHY */ |
| 1792 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1793 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1794 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1795 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1796 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1797 | {miim_end,} |
| 1798 | }, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1799 | (struct phy_cmd[]) { /* startup */ |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 1800 | /* Status is read once to clear old link state */ |
| 1801 | {MIIM_STATUS, miim_read, NULL}, |
| 1802 | /* Auto-negotiate */ |
| 1803 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1804 | /* Read the status */ |
| 1805 | {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr}, |
| 1806 | {miim_end,} |
| 1807 | }, |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1808 | (struct phy_cmd[]) { /* shutdown */ |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 1809 | {miim_end,} |
| 1810 | }, |
| 1811 | }; |
| 1812 | |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1813 | static struct phy_info *phy_info[] = { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1814 | &phy_info_cis8204, |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 1815 | &phy_info_cis8201, |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 1816 | &phy_info_BCM5461S, |
Joe Hamman | ed7ad4e | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1817 | &phy_info_BCM5464S, |
Zach LeRoy | ddb7fc7 | 2009-05-22 10:26:33 -0500 | [diff] [blame] | 1818 | &phy_info_BCM5482S, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1819 | &phy_info_M88E1011S, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1820 | &phy_info_M88E1111S, |
Ron Madrid | c1e2b58 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1821 | &phy_info_M88E1118, |
Sergei Poselenov | 7d4a2c3 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1822 | &phy_info_M88E1121R, |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1823 | &phy_info_M88E1145, |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1824 | &phy_info_M88E1149S, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1825 | &phy_info_dm9161, |
Heiko Schocher | 6d9933f | 2010-07-05 12:23:04 +0200 | [diff] [blame] | 1826 | &phy_info_ksz804, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1827 | &phy_info_lxt971, |
Pieter Henning | 9370c8b | 2009-02-22 23:17:15 -0800 | [diff] [blame] | 1828 | &phy_info_VSC8211, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1829 | &phy_info_VSC8244, |
Tor Krill | 8b3a82f | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1830 | &phy_info_VSC8601, |
Poonam Aggrwal | c91b5de | 2009-07-02 16:15:13 +0530 | [diff] [blame] | 1831 | &phy_info_VSC8641, |
| 1832 | &phy_info_VSC8221, |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1833 | &phy_info_dp83865, |
Dave Liu | a304a28 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 1834 | &phy_info_rtl8211b, |
Paul Gortmaker | f81b823 | 2009-03-09 18:07:53 -0500 | [diff] [blame] | 1835 | &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1836 | NULL |
| 1837 | }; |
| 1838 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1839 | /* Grab the identifier of the device's PHY, and search through |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1840 | * all of the known PHYs to see if one matches. If so, return |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1841 | * it, if not, return NULL |
| 1842 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1843 | static struct phy_info *get_phy_info(struct eth_device *dev) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1844 | { |
| 1845 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 1846 | uint phy_reg, phy_ID; |
| 1847 | int i; |
| 1848 | struct phy_info *theInfo = NULL; |
| 1849 | |
| 1850 | /* Grab the bits from PHYIR1, and put them in the upper half */ |
| 1851 | phy_reg = read_phy_reg(priv, MIIM_PHYIR1); |
| 1852 | phy_ID = (phy_reg & 0xffff) << 16; |
| 1853 | |
| 1854 | /* Grab the bits from PHYIR2, and put them in the lower half */ |
| 1855 | phy_reg = read_phy_reg(priv, MIIM_PHYIR2); |
| 1856 | phy_ID |= (phy_reg & 0xffff); |
| 1857 | |
| 1858 | /* loop through all the known PHY types, and find one that */ |
| 1859 | /* matches the ID we read from the PHY. */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1860 | for (i = 0; phy_info[i]; i++) { |
Andy Fleming | b2d14f4 | 2007-05-09 00:54:20 -0500 | [diff] [blame] | 1861 | if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1862 | theInfo = phy_info[i]; |
Andy Fleming | b2d14f4 | 2007-05-09 00:54:20 -0500 | [diff] [blame] | 1863 | break; |
| 1864 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
Paul Gortmaker | f81b823 | 2009-03-09 18:07:53 -0500 | [diff] [blame] | 1867 | if (theInfo == &phy_info_generic) { |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1868 | printf("%s: No support for PHY id %x; assuming generic\n", |
| 1869 | dev->name, phy_ID); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1870 | } else { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 1871 | debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | return theInfo; |
| 1875 | } |
| 1876 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1877 | /* Execute the given series of commands on the given device's |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1878 | * PHY, running functions as necessary |
| 1879 | */ |
Peter Tyser | 08b2d78 | 2009-11-09 13:09:45 -0600 | [diff] [blame] | 1880 | static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1881 | { |
| 1882 | int i; |
| 1883 | uint result; |
Sandeep Gopalpet | b5541ef | 2009-10-31 00:35:04 +0530 | [diff] [blame] | 1884 | volatile tsec_mdio_t *phyregs = priv->phyregs; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1885 | |
| 1886 | phyregs->miimcfg = MIIMCFG_RESET; |
| 1887 | |
| 1888 | phyregs->miimcfg = MIIMCFG_INIT_VALUE; |
| 1889 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1890 | while (phyregs->miimind & MIIMIND_BUSY) ; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1891 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1892 | for (i = 0; cmd->mii_reg != miim_end; i++) { |
| 1893 | if (cmd->mii_data == miim_read) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1894 | result = read_phy_reg(priv, cmd->mii_reg); |
| 1895 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1896 | if (cmd->funct != NULL) |
| 1897 | (*(cmd->funct)) (result, priv); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1898 | |
| 1899 | } else { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1900 | if (cmd->funct != NULL) |
| 1901 | result = (*(cmd->funct)) (cmd->mii_reg, priv); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1902 | else |
| 1903 | result = cmd->mii_data; |
| 1904 | |
| 1905 | write_phy_reg(priv, cmd->mii_reg, result); |
| 1906 | |
| 1907 | } |
| 1908 | cmd++; |
| 1909 | } |
| 1910 | } |
| 1911 | |
Jon Loeliger | 82ecaad | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 1912 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1913 | && !defined(BITBANGMII) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1914 | |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1915 | /* |
| 1916 | * Read a MII PHY register. |
| 1917 | * |
| 1918 | * Returns: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1919 | * 0 on success |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1920 | */ |
Mike Frysinger | 5ff5fdb | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 1921 | static int tsec_miiphy_read(const char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1922 | unsigned char reg, unsigned short *value) |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1923 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1924 | unsigned short ret; |
michael.firth@bt.com | 0838484 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 1925 | struct tsec_private *priv = privlist[0]; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1926 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1927 | if (NULL == priv) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1928 | printf("Can't read PHY at address %d\n", addr); |
| 1929 | return -1; |
| 1930 | } |
| 1931 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 1932 | ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1933 | *value = ret; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1934 | |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
| 1938 | /* |
| 1939 | * Write a MII PHY register. |
| 1940 | * |
| 1941 | * Returns: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1942 | * 0 on success |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1943 | */ |
Mike Frysinger | 5ff5fdb | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 1944 | static int tsec_miiphy_write(const char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1945 | unsigned char reg, unsigned short value) |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1946 | { |
michael.firth@bt.com | 0838484 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 1947 | struct tsec_private *priv = privlist[0]; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1948 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1949 | if (NULL == priv) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1950 | printf("Can't write PHY at address %d\n", addr); |
| 1951 | return -1; |
| 1952 | } |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1953 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 1954 | tsec_local_mdio_write(priv->phyregs, addr, reg, value); |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1955 | |
| 1956 | return 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1957 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1958 | |
Jon Loeliger | 82ecaad | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 1959 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1960 | |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 1961 | #ifdef CONFIG_MCAST_TFTP |
| 1962 | |
| 1963 | /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */ |
| 1964 | |
| 1965 | /* Set the appropriate hash bit for the given addr */ |
| 1966 | |
| 1967 | /* The algorithm works like so: |
| 1968 | * 1) Take the Destination Address (ie the multicast address), and |
| 1969 | * do a CRC on it (little endian), and reverse the bits of the |
| 1970 | * result. |
| 1971 | * 2) Use the 8 most significant bits as a hash into a 256-entry |
| 1972 | * table. The table is controlled through 8 32-bit registers: |
| 1973 | * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is |
| 1974 | * gaddr7. This means that the 3 most significant bits in the |
| 1975 | * hash index which gaddr register to use, and the 5 other bits |
| 1976 | * indicate which bit (assuming an IBM numbering scheme, which |
| 1977 | * for PowerPC (tm) is usually the case) in the tregister holds |
| 1978 | * the entry. */ |
| 1979 | static int |
| 1980 | tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set) |
| 1981 | { |
Peter Tyser | 4ef03c0 | 2009-11-09 13:09:46 -0600 | [diff] [blame] | 1982 | struct tsec_private *priv = privlist[1]; |
| 1983 | volatile tsec_t *regs = priv->regs; |
| 1984 | volatile u32 *reg_array, value; |
| 1985 | u8 result, whichbit, whichreg; |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 1986 | |
| 1987 | result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff); |
| 1988 | whichbit = result & 0x1f; /* the 5 LSB = which bit to set */ |
| 1989 | whichreg = result >> 5; /* the 3 MSB = which reg to set it in */ |
| 1990 | value = (1 << (31-whichbit)); |
| 1991 | |
| 1992 | reg_array = &(regs->hash.gaddr0); |
| 1993 | |
| 1994 | if (set) { |
| 1995 | reg_array[whichreg] |= value; |
| 1996 | } else { |
| 1997 | reg_array[whichreg] &= ~value; |
| 1998 | } |
| 1999 | return 0; |
| 2000 | } |
| 2001 | #endif /* Multicast TFTP ? */ |