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 | * |
Andy Fleming | 2fffa05 | 2007-04-23 02:24:28 -0500 | [diff] [blame] | 8 | * Copyright 2004, 2007 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> |
| 19 | |
| 20 | #if defined(CONFIG_TSEC_ENET) |
| 21 | #include "tsec.h" |
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 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 36 | struct tsec_info_struct { |
| 37 | unsigned int phyaddr; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 38 | u32 flags; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 39 | unsigned int phyregidx; |
| 40 | }; |
| 41 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 42 | /* The tsec_info structure contains 3 values which the |
| 43 | * driver uses to determine how to operate a given ethernet |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 44 | * device. The information needed is: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 45 | * phyaddr - The address of the PHY which is attached to |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 46 | * the given device. |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 47 | * |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 48 | * flags - This variable indicates whether the device |
| 49 | * supports gigabit speed ethernet, and whether it should be |
| 50 | * in reduced mode. |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 51 | * |
| 52 | * phyregidx - This variable specifies which ethernet device |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 53 | * controls the MII Management registers which are connected |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 54 | * to the PHY. For now, only TSEC1 (index 0) has |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 55 | * access to the PHYs, so all of the entries have "0". |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 56 | * |
| 57 | * The values specified in the table are taken from the board's |
| 58 | * config file in include/configs/. When implementing a new |
| 59 | * board with ethernet capability, it is necessary to define: |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 60 | * TSECn_PHY_ADDR |
| 61 | * TSECn_PHYIDX |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 62 | * |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 63 | * for n = 1,2,3, etc. And for FEC: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 64 | * FEC_PHY_ADDR |
| 65 | * FEC_PHYIDX |
| 66 | */ |
| 67 | static struct tsec_info_struct tsec_info[] = { |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 68 | #if defined(CONFIG_TSEC1) |
| 69 | #if defined(CONFIG_MPC8544DS) || defined(CONFIG_MPC8641HPCN) |
Wolfgang Denk | 58c495b | 2007-05-05 18:23:11 +0200 | [diff] [blame] | 70 | {TSEC1_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC1_PHYIDX}, |
Andy Fleming | 2fffa05 | 2007-04-23 02:24:28 -0500 | [diff] [blame] | 71 | #else |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 72 | {TSEC1_PHY_ADDR, TSEC_GIGABIT, TSEC1_PHYIDX}, |
Andy Fleming | 2fffa05 | 2007-04-23 02:24:28 -0500 | [diff] [blame] | 73 | #endif |
Zach Sadecki | f5dd299 | 2007-07-31 12:27:25 -0500 | [diff] [blame^] | 74 | #else |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 75 | {0, 0, 0}, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 76 | #endif |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 77 | #if defined(CONFIG_TSEC2) |
| 78 | #if defined(CONFIG_MPC8641HPCN) |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 79 | {TSEC2_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC2_PHYIDX}, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 80 | #else |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 81 | {TSEC2_PHY_ADDR, TSEC_GIGABIT, TSEC2_PHYIDX}, |
| 82 | #endif |
Zach Sadecki | f5dd299 | 2007-07-31 12:27:25 -0500 | [diff] [blame^] | 83 | #else |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 84 | {0, 0, 0}, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 85 | #endif |
| 86 | #ifdef CONFIG_MPC85XX_FEC |
| 87 | {FEC_PHY_ADDR, 0, FEC_PHYIDX}, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 88 | #else |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 89 | #if defined(CONFIG_TSEC3) |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 90 | {TSEC3_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC3_PHYIDX}, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 91 | #else |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 92 | {0, 0, 0}, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 93 | #endif |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 94 | #if defined(CONFIG_TSEC4) |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 95 | {TSEC4_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC4_PHYIDX}, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 96 | #else |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 97 | {0, 0, 0}, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 98 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 99 | #endif |
| 100 | }; |
| 101 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 102 | #define MAXCONTROLLERS (4) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 103 | |
| 104 | static int relocated = 0; |
| 105 | |
| 106 | static struct tsec_private *privlist[MAXCONTROLLERS]; |
| 107 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 108 | #ifdef __GNUC__ |
| 109 | static RTXBD rtx __attribute__ ((aligned(8))); |
| 110 | #else |
| 111 | #error "rtx must be 64-bit aligned" |
| 112 | #endif |
| 113 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 114 | static int tsec_send(struct eth_device *dev, |
| 115 | volatile void *packet, int length); |
| 116 | static int tsec_recv(struct eth_device *dev); |
| 117 | static int tsec_init(struct eth_device *dev, bd_t * bd); |
| 118 | static void tsec_halt(struct eth_device *dev); |
| 119 | static void init_registers(volatile tsec_t * regs); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 120 | static void startup_tsec(struct eth_device *dev); |
| 121 | static int init_phy(struct eth_device *dev); |
| 122 | void write_phy_reg(struct tsec_private *priv, uint regnum, uint value); |
| 123 | uint read_phy_reg(struct tsec_private *priv, uint regnum); |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 124 | struct phy_info *get_phy_info(struct eth_device *dev); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 125 | void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd); |
| 126 | static void adjust_link(struct eth_device *dev); |
| 127 | static void relocate_cmds(void); |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 128 | static int tsec_miiphy_write(char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 129 | unsigned char reg, unsigned short value); |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 130 | static int tsec_miiphy_read(char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 131 | unsigned char reg, unsigned short *value); |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 132 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 133 | /* Initialize device structure. Returns success if PHY |
| 134 | * initialization succeeded (i.e. if it recognizes the PHY) |
| 135 | */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 136 | int tsec_initialize(bd_t * bis, int index, char *devname) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 137 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 138 | struct eth_device *dev; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 139 | int i; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 140 | struct tsec_private *priv; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 141 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 142 | dev = (struct eth_device *)malloc(sizeof *dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 143 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 144 | if (NULL == dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 145 | return 0; |
| 146 | |
| 147 | memset(dev, 0, sizeof *dev); |
| 148 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 149 | priv = (struct tsec_private *)malloc(sizeof(*priv)); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 150 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 151 | if (NULL == priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 152 | return 0; |
| 153 | |
| 154 | privlist[index] = priv; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 155 | priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index * TSEC_SIZE); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 156 | priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR + |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 157 | tsec_info[index].phyregidx * |
| 158 | TSEC_SIZE); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 159 | |
| 160 | priv->phyaddr = tsec_info[index].phyaddr; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 161 | priv->flags = tsec_info[index].flags; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 162 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 163 | sprintf(dev->name, devname); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 164 | dev->iobase = 0; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 165 | dev->priv = priv; |
| 166 | dev->init = tsec_init; |
| 167 | dev->halt = tsec_halt; |
| 168 | dev->send = tsec_send; |
| 169 | dev->recv = tsec_recv; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 170 | |
| 171 | /* Tell u-boot to get the addr from the env */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 172 | for (i = 0; i < 6; i++) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 173 | dev->enetaddr[i] = 0; |
| 174 | |
| 175 | eth_register(dev); |
| 176 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 177 | /* Reset the MAC */ |
| 178 | priv->regs->maccfg1 |= MACCFG1_SOFT_RESET; |
| 179 | priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET); |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 180 | |
Jon Loeliger | 82ecaad | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 181 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 182 | && !defined(BITBANGMII) |
| 183 | miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write); |
| 184 | #endif |
| 185 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 186 | /* Try to initialize PHY here, and return */ |
| 187 | return init_phy(dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 188 | } |
| 189 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 190 | /* Initializes data structures and registers for the controller, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 191 | * and brings the interface up. Returns the link status, meaning |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 192 | * that it returns success if the link is up, failure otherwise. |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 193 | * This allows u-boot to find the first active controller. |
| 194 | */ |
| 195 | int tsec_init(struct eth_device *dev, bd_t * bd) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 196 | { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 197 | uint tempval; |
| 198 | char tmpbuf[MAC_ADDR_LEN]; |
| 199 | int i; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 200 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 201 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 202 | |
| 203 | /* Make sure the controller is stopped */ |
| 204 | tsec_halt(dev); |
| 205 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 206 | /* Init MACCFG2. Defaults to GMII */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 207 | regs->maccfg2 = MACCFG2_INIT_SETTINGS; |
| 208 | |
| 209 | /* Init ECNTRL */ |
| 210 | regs->ecntrl = ECNTRL_INIT_SETTINGS; |
| 211 | |
| 212 | /* Copy the station address into the address registers. |
| 213 | * Backwards, because little endian MACS are dumb */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 214 | for (i = 0; i < MAC_ADDR_LEN; i++) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 215 | tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i]; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 216 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 217 | regs->macstnaddr1 = *((uint *) (tmpbuf)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 218 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 219 | tempval = *((uint *) (tmpbuf + 4)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 220 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 221 | regs->macstnaddr2 = tempval; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 222 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 223 | /* reset the indices to zero */ |
| 224 | rxIdx = 0; |
| 225 | txIdx = 0; |
| 226 | |
| 227 | /* Clear out (for the most part) the other registers */ |
| 228 | init_registers(regs); |
| 229 | |
| 230 | /* Ready the device for tx/rx */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 231 | startup_tsec(dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 232 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 233 | /* If there's no link, fail */ |
| 234 | return priv->link; |
| 235 | |
| 236 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 237 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 238 | /* Write value to the device's PHY through the registers |
| 239 | * specified in priv, modifying the register specified in regnum. |
| 240 | * It will wait for the write to be done (or for a timeout to |
| 241 | * expire) before exiting |
| 242 | */ |
| 243 | void write_phy_reg(struct tsec_private *priv, uint regnum, uint value) |
| 244 | { |
| 245 | volatile tsec_t *regbase = priv->phyregs; |
| 246 | uint phyid = priv->phyaddr; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 247 | int timeout = 1000000; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 248 | |
| 249 | regbase->miimadd = (phyid << 8) | regnum; |
| 250 | regbase->miimcon = value; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 251 | asm("sync"); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 252 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 253 | timeout = 1000000; |
| 254 | while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 255 | } |
| 256 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 257 | /* Reads register regnum on the device's PHY through the |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 258 | * registers specified in priv. It lowers and raises the read |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 259 | * command, and waits for the data to become valid (miimind |
| 260 | * notvalid bit cleared), and the bus to cease activity (miimind |
| 261 | * busy bit cleared), and then returns the value |
| 262 | */ |
| 263 | uint read_phy_reg(struct tsec_private *priv, uint regnum) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 264 | { |
| 265 | uint value; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 266 | volatile tsec_t *regbase = priv->phyregs; |
| 267 | uint phyid = priv->phyaddr; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 268 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 269 | /* Put the address of the phy, and the register |
| 270 | * number into MIIMADD */ |
| 271 | regbase->miimadd = (phyid << 8) | regnum; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 272 | |
| 273 | /* Clear the command register, and wait */ |
| 274 | regbase->miimcom = 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 275 | asm("sync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 276 | |
| 277 | /* Initiate a read command, and wait */ |
| 278 | regbase->miimcom = MIIM_READ_COMMAND; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 279 | asm("sync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 280 | |
| 281 | /* Wait for the the indication that the read is done */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 282 | while ((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 283 | |
| 284 | /* Grab the value read from the PHY */ |
| 285 | value = regbase->miimstat; |
| 286 | |
| 287 | return value; |
| 288 | } |
| 289 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 290 | /* Discover which PHY is attached to the device, and configure it |
| 291 | * properly. If the PHY is not recognized, then return 0 |
| 292 | * (failure). Otherwise, return 1 |
| 293 | */ |
| 294 | static int init_phy(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 295 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 296 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 297 | struct phy_info *curphy; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 298 | volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 299 | |
| 300 | /* Assign a Physical address to the TBI */ |
Joe Hamman | 4290d4c | 2007-08-09 09:08:18 -0500 | [diff] [blame] | 301 | regs->tbipa = CFG_TBIPA_VALUE; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 302 | regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE); |
Joe Hamman | 4290d4c | 2007-08-09 09:08:18 -0500 | [diff] [blame] | 303 | regs->tbipa = CFG_TBIPA_VALUE; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 304 | asm("sync"); |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 305 | |
| 306 | /* Reset MII (due to new addresses) */ |
| 307 | priv->phyregs->miimcfg = MIIMCFG_RESET; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 308 | asm("sync"); |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 309 | priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 310 | asm("sync"); |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 311 | while (priv->phyregs->miimind & MIIMIND_BUSY) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 312 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 313 | if (0 == relocated) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 314 | relocate_cmds(); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 315 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 316 | /* Get the cmd structure corresponding to the attached |
| 317 | * PHY */ |
| 318 | curphy = get_phy_info(dev); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 319 | |
Ben Warren | f11eefb | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 320 | if (curphy == NULL) { |
| 321 | priv->phyinfo = NULL; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 322 | printf("%s: No PHY found\n", dev->name); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 323 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 324 | return 0; |
| 325 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 326 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 327 | priv->phyinfo = curphy; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 328 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 329 | phy_run_commands(priv, priv->phyinfo->config); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 330 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 331 | return 1; |
| 332 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 333 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 334 | /* |
| 335 | * Returns which value to write to the control register. |
| 336 | * For 10/100, the value is slightly different |
| 337 | */ |
| 338 | uint mii_cr_init(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 339 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 340 | if (priv->flags & TSEC_GIGABIT) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 341 | return MIIM_CONTROL_INIT; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 342 | else |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 343 | return MIIM_CR_INIT; |
| 344 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 345 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 346 | /* Parse the status register for link, and then do |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 347 | * auto-negotiation |
| 348 | */ |
| 349 | uint mii_parse_sr(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 350 | { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 351 | /* |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 352 | * Wait if PHY is capable of autonegotiation and autonegotiation |
| 353 | * is not complete. |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 354 | */ |
| 355 | mii_reg = read_phy_reg(priv, MIIM_STATUS); |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 356 | if ((mii_reg & PHY_BMSR_AUTN_ABLE) |
| 357 | && !(mii_reg & PHY_BMSR_AUTN_COMP)) { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 358 | int i = 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 359 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 360 | puts("Waiting for PHY auto negotiation to complete"); |
| 361 | while (!((mii_reg & PHY_BMSR_AUTN_COMP) |
| 362 | && (mii_reg & MIIM_STATUS_LINK))) { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 363 | /* |
| 364 | * Timeout reached ? |
| 365 | */ |
| 366 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 367 | puts(" TIMEOUT !\n"); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 368 | priv->link = 0; |
Jin Zhengxiong-R64188 | 487d223 | 2006-06-27 18:12:23 +0800 | [diff] [blame] | 369 | return 0; |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 370 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 371 | |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 372 | if ((i++ % 1000) == 0) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 373 | putc('.'); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 374 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 375 | udelay(1000); /* 1 ms */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 376 | mii_reg = read_phy_reg(priv, MIIM_STATUS); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 377 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 378 | puts(" done\n"); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 379 | priv->link = 1; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 380 | udelay(500000); /* another 500 ms (results in faster booting) */ |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 381 | } else { |
| 382 | priv->link = 1; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 383 | } |
| 384 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 388 | /* Generic function which updates the speed and duplex. If |
| 389 | * autonegotiation is enabled, it uses the AND of the link |
| 390 | * partner's advertised capabilities and our advertised |
| 391 | * capabilities. If autonegotiation is disabled, we use the |
| 392 | * appropriate bits in the control register. |
| 393 | * |
| 394 | * Stolen from Linux's mii.c and phy_device.c |
| 395 | */ |
| 396 | uint mii_parse_link(uint mii_reg, struct tsec_private *priv) |
| 397 | { |
| 398 | /* We're using autonegotiation */ |
| 399 | if (mii_reg & PHY_BMSR_AUTN_ABLE) { |
| 400 | uint lpa = 0; |
| 401 | uint gblpa = 0; |
| 402 | |
| 403 | /* Check for gigabit capability */ |
| 404 | if (mii_reg & PHY_BMSR_EXT) { |
| 405 | /* We want a list of states supported by |
| 406 | * both PHYs in the link |
| 407 | */ |
| 408 | gblpa = read_phy_reg(priv, PHY_1000BTSR); |
| 409 | gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2; |
| 410 | } |
| 411 | |
| 412 | /* Set the baseline so we only have to set them |
| 413 | * if they're different |
| 414 | */ |
| 415 | priv->speed = 10; |
| 416 | priv->duplexity = 0; |
| 417 | |
| 418 | /* Check the gigabit fields */ |
| 419 | if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) { |
| 420 | priv->speed = 1000; |
| 421 | |
| 422 | if (gblpa & PHY_1000BTSR_1000FD) |
| 423 | priv->duplexity = 1; |
| 424 | |
| 425 | /* We're done! */ |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | lpa = read_phy_reg(priv, PHY_ANAR); |
| 430 | lpa &= read_phy_reg(priv, PHY_ANLPAR); |
| 431 | |
| 432 | if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) { |
| 433 | priv->speed = 100; |
| 434 | |
| 435 | if (lpa & PHY_ANLPAR_TXFD) |
| 436 | priv->duplexity = 1; |
| 437 | |
| 438 | } else if (lpa & PHY_ANLPAR_10FD) |
| 439 | priv->duplexity = 1; |
| 440 | } else { |
| 441 | uint bmcr = read_phy_reg(priv, PHY_BMCR); |
| 442 | |
| 443 | priv->speed = 10; |
| 444 | priv->duplexity = 0; |
| 445 | |
| 446 | if (bmcr & PHY_BMCR_DPLX) |
| 447 | priv->duplexity = 1; |
| 448 | |
| 449 | if (bmcr & PHY_BMCR_1000_MBPS) |
| 450 | priv->speed = 1000; |
| 451 | else if (bmcr & PHY_BMCR_100_MBPS) |
| 452 | priv->speed = 100; |
| 453 | } |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 458 | /* |
| 459 | * Parse the BCM54xx status register for speed and duplex information. |
| 460 | * The linux sungem_phy has this information, but in a table format. |
| 461 | */ |
| 462 | uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv) |
| 463 | { |
| 464 | |
| 465 | switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){ |
| 466 | |
| 467 | case 1: |
| 468 | printf("Enet starting in 10BT/HD\n"); |
| 469 | priv->duplexity = 0; |
| 470 | priv->speed = 10; |
| 471 | break; |
| 472 | |
| 473 | case 2: |
| 474 | printf("Enet starting in 10BT/FD\n"); |
| 475 | priv->duplexity = 1; |
| 476 | priv->speed = 10; |
| 477 | break; |
| 478 | |
| 479 | case 3: |
| 480 | printf("Enet starting in 100BT/HD\n"); |
| 481 | priv->duplexity = 0; |
| 482 | priv->speed = 100; |
| 483 | break; |
| 484 | |
| 485 | case 5: |
| 486 | printf("Enet starting in 100BT/FD\n"); |
| 487 | priv->duplexity = 1; |
| 488 | priv->speed = 100; |
| 489 | break; |
| 490 | |
| 491 | case 6: |
| 492 | printf("Enet starting in 1000BT/HD\n"); |
| 493 | priv->duplexity = 0; |
| 494 | priv->speed = 1000; |
| 495 | break; |
| 496 | |
| 497 | case 7: |
| 498 | printf("Enet starting in 1000BT/FD\n"); |
| 499 | priv->duplexity = 1; |
| 500 | priv->speed = 1000; |
| 501 | break; |
| 502 | |
| 503 | default: |
| 504 | printf("Auto-neg error, defaulting to 10BT/HD\n"); |
| 505 | priv->duplexity = 0; |
| 506 | priv->speed = 10; |
| 507 | break; |
| 508 | } |
| 509 | |
| 510 | return 0; |
| 511 | |
| 512 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 513 | /* Parse the 88E1011's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 514 | * information |
| 515 | */ |
| 516 | uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 517 | { |
| 518 | uint speed; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 519 | |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 520 | mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS); |
| 521 | |
| 522 | if (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) && |
| 523 | (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) { |
| 524 | int i = 0; |
| 525 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 526 | puts("Waiting for PHY realtime link"); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 527 | while (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) && |
| 528 | (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) { |
| 529 | /* |
| 530 | * Timeout reached ? |
| 531 | */ |
| 532 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 533 | puts(" TIMEOUT !\n"); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 534 | priv->link = 0; |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | if ((i++ % 1000) == 0) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 539 | putc('.'); |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 540 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 541 | udelay(1000); /* 1 ms */ |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 542 | mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS); |
| 543 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 544 | puts(" done\n"); |
| 545 | udelay(500000); /* another 500 ms (results in faster booting) */ |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 546 | } |
| 547 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 548 | if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 549 | priv->duplexity = 1; |
| 550 | else |
| 551 | priv->duplexity = 0; |
| 552 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 553 | speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 554 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 555 | switch (speed) { |
| 556 | case MIIM_88E1011_PHYSTAT_GBIT: |
| 557 | priv->speed = 1000; |
| 558 | break; |
| 559 | case MIIM_88E1011_PHYSTAT_100: |
| 560 | priv->speed = 100; |
| 561 | break; |
| 562 | default: |
| 563 | priv->speed = 10; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 564 | } |
| 565 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 569 | /* Parse the cis8201's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 570 | * information |
| 571 | */ |
| 572 | uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 573 | { |
| 574 | uint speed; |
| 575 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 576 | if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 577 | priv->duplexity = 1; |
| 578 | else |
| 579 | priv->duplexity = 0; |
| 580 | |
| 581 | speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 582 | switch (speed) { |
| 583 | case MIIM_CIS8201_AUXCONSTAT_GBIT: |
| 584 | priv->speed = 1000; |
| 585 | break; |
| 586 | case MIIM_CIS8201_AUXCONSTAT_100: |
| 587 | priv->speed = 100; |
| 588 | break; |
| 589 | default: |
| 590 | priv->speed = 10; |
| 591 | break; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 592 | } |
| 593 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 594 | return 0; |
| 595 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 596 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 597 | /* Parse the vsc8244's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 598 | * information |
| 599 | */ |
| 600 | uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 601 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 602 | uint speed; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 603 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 604 | if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX) |
| 605 | priv->duplexity = 1; |
| 606 | else |
| 607 | priv->duplexity = 0; |
| 608 | |
| 609 | speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED; |
| 610 | switch (speed) { |
| 611 | case MIIM_VSC8244_AUXCONSTAT_GBIT: |
| 612 | priv->speed = 1000; |
| 613 | break; |
| 614 | case MIIM_VSC8244_AUXCONSTAT_100: |
| 615 | priv->speed = 100; |
| 616 | break; |
| 617 | default: |
| 618 | priv->speed = 10; |
| 619 | break; |
| 620 | } |
| 621 | |
| 622 | return 0; |
| 623 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 624 | |
| 625 | /* Parse the DM9161's status register for speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 626 | * information |
| 627 | */ |
| 628 | uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 629 | { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 630 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H)) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 631 | priv->speed = 100; |
| 632 | else |
| 633 | priv->speed = 10; |
| 634 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 635 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F)) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 636 | priv->duplexity = 1; |
| 637 | else |
| 638 | priv->duplexity = 0; |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 643 | /* |
| 644 | * Hack to write all 4 PHYs with the LED values |
| 645 | */ |
| 646 | uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 647 | { |
| 648 | uint phyid; |
| 649 | volatile tsec_t *regbase = priv->phyregs; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 650 | int timeout = 1000000; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 651 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 652 | for (phyid = 0; phyid < 4; phyid++) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 653 | regbase->miimadd = (phyid << 8) | mii_reg; |
| 654 | regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 655 | asm("sync"); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 656 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 657 | timeout = 1000000; |
| 658 | while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 659 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 660 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 661 | return MIIM_CIS8204_SLEDCON_INIT; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 664 | uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv) |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 665 | { |
| 666 | if (priv->flags & TSEC_REDUCED) |
| 667 | return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII; |
| 668 | else |
| 669 | return MIIM_CIS8204_EPHYCON_INIT; |
| 670 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 671 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 672 | /* Initialized required registers to appropriate values, zeroing |
| 673 | * 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] | 674 | * choose a more appropriate value) |
| 675 | */ |
| 676 | static void init_registers(volatile tsec_t * regs) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 677 | { |
| 678 | /* Clear IEVENT */ |
| 679 | regs->ievent = IEVENT_INIT_CLEAR; |
| 680 | |
| 681 | regs->imask = IMASK_INIT_CLEAR; |
| 682 | |
| 683 | regs->hash.iaddr0 = 0; |
| 684 | regs->hash.iaddr1 = 0; |
| 685 | regs->hash.iaddr2 = 0; |
| 686 | regs->hash.iaddr3 = 0; |
| 687 | regs->hash.iaddr4 = 0; |
| 688 | regs->hash.iaddr5 = 0; |
| 689 | regs->hash.iaddr6 = 0; |
| 690 | regs->hash.iaddr7 = 0; |
| 691 | |
| 692 | regs->hash.gaddr0 = 0; |
| 693 | regs->hash.gaddr1 = 0; |
| 694 | regs->hash.gaddr2 = 0; |
| 695 | regs->hash.gaddr3 = 0; |
| 696 | regs->hash.gaddr4 = 0; |
| 697 | regs->hash.gaddr5 = 0; |
| 698 | regs->hash.gaddr6 = 0; |
| 699 | regs->hash.gaddr7 = 0; |
| 700 | |
| 701 | regs->rctrl = 0x00000000; |
| 702 | |
| 703 | /* Init RMON mib registers */ |
| 704 | memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t)); |
| 705 | |
| 706 | regs->rmon.cam1 = 0xffffffff; |
| 707 | regs->rmon.cam2 = 0xffffffff; |
| 708 | |
| 709 | regs->mrblr = MRBLR_INIT_SETTINGS; |
| 710 | |
| 711 | regs->minflr = MINFLR_INIT_SETTINGS; |
| 712 | |
| 713 | regs->attr = ATTR_INIT_SETTINGS; |
| 714 | regs->attreli = ATTRELI_INIT_SETTINGS; |
| 715 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 716 | } |
| 717 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 718 | /* Configure maccfg2 based on negotiated speed and duplex |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 719 | * reported by PHY handling code |
| 720 | */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 721 | static void adjust_link(struct eth_device *dev) |
| 722 | { |
| 723 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 724 | volatile tsec_t *regs = priv->regs; |
| 725 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 726 | if (priv->link) { |
| 727 | if (priv->duplexity != 0) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 728 | regs->maccfg2 |= MACCFG2_FULL_DUPLEX; |
| 729 | else |
| 730 | regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX); |
| 731 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 732 | switch (priv->speed) { |
| 733 | case 1000: |
| 734 | regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF)) |
| 735 | | MACCFG2_GMII); |
| 736 | break; |
| 737 | case 100: |
| 738 | case 10: |
| 739 | regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF)) |
| 740 | | MACCFG2_MII); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 741 | |
Nick Spence | ec9670b | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 742 | /* Set R100 bit in all modes although |
| 743 | * it is only used in RGMII mode |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 744 | */ |
Nick Spence | ec9670b | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 745 | if (priv->speed == 100) |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 746 | regs->ecntrl |= ECNTRL_R100; |
| 747 | else |
| 748 | regs->ecntrl &= ~(ECNTRL_R100); |
| 749 | break; |
| 750 | default: |
| 751 | printf("%s: Speed was bad\n", dev->name); |
| 752 | break; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | printf("Speed: %d, %s duplex\n", priv->speed, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 756 | (priv->duplexity) ? "full" : "half"); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 757 | |
| 758 | } else { |
| 759 | printf("%s: No link.\n", dev->name); |
| 760 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 761 | } |
| 762 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 763 | /* Set up the buffers and their descriptors, and bring up the |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 764 | * interface |
| 765 | */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 766 | static void startup_tsec(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 767 | { |
| 768 | int i; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 769 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 770 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 771 | |
| 772 | /* Point to the buffer descriptors */ |
| 773 | regs->tbase = (unsigned int)(&rtx.txbd[txIdx]); |
| 774 | regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]); |
| 775 | |
| 776 | /* Initialize the Rx Buffer descriptors */ |
| 777 | for (i = 0; i < PKTBUFSRX; i++) { |
| 778 | rtx.rxbd[i].status = RXBD_EMPTY; |
| 779 | rtx.rxbd[i].length = 0; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 780 | rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i]; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 781 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 782 | rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 783 | |
| 784 | /* Initialize the TX Buffer Descriptors */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 785 | for (i = 0; i < TX_BUF_CNT; i++) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 786 | rtx.txbd[i].status = 0; |
| 787 | rtx.txbd[i].length = 0; |
| 788 | rtx.txbd[i].bufPtr = 0; |
| 789 | } |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 790 | rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 791 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 792 | /* Start up the PHY */ |
Ben Warren | f11eefb | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 793 | if(priv->phyinfo) |
| 794 | phy_run_commands(priv, priv->phyinfo->startup); |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 795 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 796 | adjust_link(dev); |
| 797 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 798 | /* Enable Transmit and Receive */ |
| 799 | regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN); |
| 800 | |
| 801 | /* Tell the DMA it is clear to go */ |
| 802 | regs->dmactrl |= DMACTRL_INIT_SETTINGS; |
| 803 | regs->tstat = TSTAT_CLEAR_THALT; |
| 804 | regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS); |
| 805 | } |
| 806 | |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 807 | /* This returns the status bits of the device. The return value |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 808 | * is never checked, and this is what the 8260 driver did, so we |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 809 | * do the same. Presumably, this would be zero if there were no |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 810 | * errors |
| 811 | */ |
| 812 | static int tsec_send(struct eth_device *dev, volatile void *packet, int length) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 813 | { |
| 814 | int i; |
| 815 | int result = 0; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 816 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 817 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 818 | |
| 819 | /* Find an empty buffer descriptor */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 820 | for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 821 | if (i >= TOUT_LOOP) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 822 | debug("%s: tsec: tx buffers full\n", dev->name); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 823 | return result; |
| 824 | } |
| 825 | } |
| 826 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 827 | rtx.txbd[txIdx].bufPtr = (uint) packet; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 828 | rtx.txbd[txIdx].length = length; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 829 | rtx.txbd[txIdx].status |= |
| 830 | (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 831 | |
| 832 | /* Tell the DMA to go */ |
| 833 | regs->tstat = TSTAT_CLEAR_THALT; |
| 834 | |
| 835 | /* Wait for buffer to be transmitted */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 836 | for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 837 | if (i >= TOUT_LOOP) { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 838 | debug("%s: tsec: tx error\n", dev->name); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 839 | return result; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | txIdx = (txIdx + 1) % TX_BUF_CNT; |
| 844 | result = rtx.txbd[txIdx].status & TXBD_STATS; |
| 845 | |
| 846 | return result; |
| 847 | } |
| 848 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 849 | static int tsec_recv(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 850 | { |
| 851 | int length; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 852 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 853 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 854 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 855 | while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 856 | |
| 857 | length = rtx.rxbd[rxIdx].length; |
| 858 | |
| 859 | /* Send the packet up if there were no errors */ |
| 860 | if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) { |
| 861 | NetReceive(NetRxPackets[rxIdx], length - 4); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 862 | } else { |
| 863 | printf("Got error %x\n", |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 864 | (rtx.rxbd[rxIdx].status & RXBD_STATS)); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | rtx.rxbd[rxIdx].length = 0; |
| 868 | |
| 869 | /* 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] | 870 | rtx.rxbd[rxIdx].status = |
| 871 | RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 872 | |
| 873 | rxIdx = (rxIdx + 1) % PKTBUFSRX; |
| 874 | } |
| 875 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 876 | if (regs->ievent & IEVENT_BSY) { |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 877 | regs->ievent = IEVENT_BSY; |
| 878 | regs->rstat = RSTAT_CLEAR_RHALT; |
| 879 | } |
| 880 | |
| 881 | return -1; |
| 882 | |
| 883 | } |
| 884 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 885 | /* Stop the interface */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 886 | static void tsec_halt(struct eth_device *dev) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 887 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 888 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 889 | volatile tsec_t *regs = priv->regs; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 890 | |
| 891 | regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS); |
| 892 | regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS); |
| 893 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 894 | while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 895 | |
| 896 | regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN); |
| 897 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 898 | /* Shut down the PHY, as needed */ |
Ben Warren | f11eefb | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 899 | if(priv->phyinfo) |
| 900 | phy_run_commands(priv, priv->phyinfo->shutdown); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Andy Fleming | bee6700 | 2007-08-03 04:05:25 -0500 | [diff] [blame] | 903 | struct phy_info phy_info_M88E1149S = { |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 904 | 0x1410ca, |
| 905 | "Marvell 88E1149S", |
| 906 | 4, |
| 907 | (struct phy_cmd[]){ /* config */ |
| 908 | /* Reset and configure the PHY */ |
| 909 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 910 | {0x1d, 0x1f, NULL}, |
| 911 | {0x1e, 0x200c, NULL}, |
| 912 | {0x1d, 0x5, NULL}, |
| 913 | {0x1e, 0x0, NULL}, |
| 914 | {0x1e, 0x100, NULL}, |
| 915 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 916 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 917 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 918 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 919 | {miim_end,} |
| 920 | }, |
| 921 | (struct phy_cmd[]){ /* startup */ |
| 922 | /* Status is read once to clear old link state */ |
| 923 | {MIIM_STATUS, miim_read, NULL}, |
| 924 | /* Auto-negotiate */ |
| 925 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 926 | /* Read the status */ |
| 927 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 928 | &mii_parse_88E1011_psr}, |
| 929 | {miim_end,} |
| 930 | }, |
| 931 | (struct phy_cmd[]){ /* shutdown */ |
| 932 | {miim_end,} |
| 933 | }, |
Andy Fleming | bee6700 | 2007-08-03 04:05:25 -0500 | [diff] [blame] | 934 | }; |
| 935 | |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 936 | /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */ |
| 937 | struct phy_info phy_info_BCM5461S = { |
| 938 | 0x02060c1, /* 5461 ID */ |
| 939 | "Broadcom BCM5461S", |
| 940 | 0, /* not clear to me what minor revisions we can shift away */ |
| 941 | (struct phy_cmd[]) { /* config */ |
| 942 | /* Reset and configure the PHY */ |
| 943 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 944 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 945 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 946 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 947 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 948 | {miim_end,} |
| 949 | }, |
| 950 | (struct phy_cmd[]) { /* startup */ |
| 951 | /* Status is read once to clear old link state */ |
| 952 | {MIIM_STATUS, miim_read, NULL}, |
| 953 | /* Auto-negotiate */ |
| 954 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 955 | /* Read the status */ |
| 956 | {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr}, |
| 957 | {miim_end,} |
| 958 | }, |
| 959 | (struct phy_cmd[]) { /* shutdown */ |
| 960 | {miim_end,} |
| 961 | }, |
| 962 | }; |
| 963 | |
Joe Hamman | ed7ad4e | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 964 | struct phy_info phy_info_BCM5464S = { |
| 965 | 0x02060b1, /* 5464 ID */ |
| 966 | "Broadcom BCM5464S", |
| 967 | 0, /* not clear to me what minor revisions we can shift away */ |
| 968 | (struct phy_cmd[]) { /* config */ |
| 969 | /* Reset and configure the PHY */ |
| 970 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 971 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 972 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 973 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 974 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 975 | {miim_end,} |
| 976 | }, |
| 977 | (struct phy_cmd[]) { /* startup */ |
| 978 | /* Status is read once to clear old link state */ |
| 979 | {MIIM_STATUS, miim_read, NULL}, |
| 980 | /* Auto-negotiate */ |
| 981 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 982 | /* Read the status */ |
| 983 | {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr}, |
| 984 | {miim_end,} |
| 985 | }, |
| 986 | (struct phy_cmd[]) { /* shutdown */ |
| 987 | {miim_end,} |
| 988 | }, |
| 989 | }; |
| 990 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 991 | struct phy_info phy_info_M88E1011S = { |
| 992 | 0x01410c6, |
| 993 | "Marvell 88E1011S", |
| 994 | 4, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 995 | (struct phy_cmd[]){ /* config */ |
| 996 | /* Reset and configure the PHY */ |
| 997 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 998 | {0x1d, 0x1f, NULL}, |
| 999 | {0x1e, 0x200c, NULL}, |
| 1000 | {0x1d, 0x5, NULL}, |
| 1001 | {0x1e, 0x0, NULL}, |
| 1002 | {0x1e, 0x100, NULL}, |
| 1003 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1004 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1005 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1006 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1007 | {miim_end,} |
| 1008 | }, |
| 1009 | (struct phy_cmd[]){ /* startup */ |
| 1010 | /* Status is read once to clear old link state */ |
| 1011 | {MIIM_STATUS, miim_read, NULL}, |
| 1012 | /* Auto-negotiate */ |
| 1013 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1014 | /* Read the status */ |
| 1015 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1016 | &mii_parse_88E1011_psr}, |
| 1017 | {miim_end,} |
| 1018 | }, |
| 1019 | (struct phy_cmd[]){ /* shutdown */ |
| 1020 | {miim_end,} |
| 1021 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1022 | }; |
| 1023 | |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1024 | struct phy_info phy_info_M88E1111S = { |
| 1025 | 0x01410cc, |
| 1026 | "Marvell 88E1111S", |
| 1027 | 4, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1028 | (struct phy_cmd[]){ /* config */ |
| 1029 | /* Reset and configure the PHY */ |
| 1030 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
Nick Spence | ec9670b | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 1031 | {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1032 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1033 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1034 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1035 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1036 | {miim_end,} |
| 1037 | }, |
| 1038 | (struct phy_cmd[]){ /* startup */ |
| 1039 | /* Status is read once to clear old link state */ |
| 1040 | {MIIM_STATUS, miim_read, NULL}, |
| 1041 | /* Auto-negotiate */ |
| 1042 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1043 | /* Read the status */ |
| 1044 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1045 | &mii_parse_88E1011_psr}, |
| 1046 | {miim_end,} |
| 1047 | }, |
| 1048 | (struct phy_cmd[]){ /* shutdown */ |
| 1049 | {miim_end,} |
| 1050 | }, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1051 | }; |
| 1052 | |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1053 | static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv) |
| 1054 | { |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1055 | uint mii_data = read_phy_reg(priv, mii_reg); |
| 1056 | |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1057 | /* Setting MIIM_88E1145_PHY_EXT_CR */ |
| 1058 | if (priv->flags & TSEC_REDUCED) |
| 1059 | return mii_data | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1060 | MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY; |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1061 | else |
| 1062 | return mii_data; |
| 1063 | } |
| 1064 | |
| 1065 | static struct phy_info phy_info_M88E1145 = { |
| 1066 | 0x01410cd, |
| 1067 | "Marvell 88E1145", |
| 1068 | 4, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1069 | (struct phy_cmd[]){ /* config */ |
Andy Fleming | 180d03a | 2007-05-08 17:23:02 -0500 | [diff] [blame] | 1070 | /* Reset the PHY */ |
| 1071 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1072 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1073 | /* Errata E0, E1 */ |
| 1074 | {29, 0x001b, NULL}, |
| 1075 | {30, 0x418f, NULL}, |
| 1076 | {29, 0x0016, NULL}, |
| 1077 | {30, 0xa2da, NULL}, |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1078 | |
Andy Fleming | 180d03a | 2007-05-08 17:23:02 -0500 | [diff] [blame] | 1079 | /* Configure the PHY */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1080 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1081 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1082 | {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, |
| 1083 | NULL}, |
| 1084 | {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode}, |
| 1085 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1086 | {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL}, |
| 1087 | {miim_end,} |
| 1088 | }, |
| 1089 | (struct phy_cmd[]){ /* startup */ |
| 1090 | /* Status is read once to clear old link state */ |
| 1091 | {MIIM_STATUS, miim_read, NULL}, |
| 1092 | /* Auto-negotiate */ |
| 1093 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1094 | {MIIM_88E1111_PHY_LED_CONTROL, |
| 1095 | MIIM_88E1111_PHY_LED_DIRECT, NULL}, |
| 1096 | /* Read the Status */ |
| 1097 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1098 | &mii_parse_88E1011_psr}, |
| 1099 | {miim_end,} |
| 1100 | }, |
| 1101 | (struct phy_cmd[]){ /* shutdown */ |
| 1102 | {miim_end,} |
| 1103 | }, |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1104 | }; |
| 1105 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1106 | struct phy_info phy_info_cis8204 = { |
| 1107 | 0x3f11, |
| 1108 | "Cicada Cis8204", |
| 1109 | 6, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1110 | (struct phy_cmd[]){ /* config */ |
| 1111 | /* Override PHY config settings */ |
| 1112 | {MIIM_CIS8201_AUX_CONSTAT, |
| 1113 | MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1114 | /* Configure some basic stuff */ |
| 1115 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1116 | {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT, |
| 1117 | &mii_cis8204_fixled}, |
| 1118 | {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT, |
| 1119 | &mii_cis8204_setmode}, |
| 1120 | {miim_end,} |
| 1121 | }, |
| 1122 | (struct phy_cmd[]){ /* startup */ |
| 1123 | /* Read the Status (2x to make sure link is right) */ |
| 1124 | {MIIM_STATUS, miim_read, NULL}, |
| 1125 | /* Auto-negotiate */ |
| 1126 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1127 | /* Read the status */ |
| 1128 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, |
| 1129 | &mii_parse_cis8201}, |
| 1130 | {miim_end,} |
| 1131 | }, |
| 1132 | (struct phy_cmd[]){ /* shutdown */ |
| 1133 | {miim_end,} |
| 1134 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1135 | }; |
| 1136 | |
| 1137 | /* Cicada 8201 */ |
| 1138 | struct phy_info phy_info_cis8201 = { |
| 1139 | 0xfc41, |
| 1140 | "CIS8201", |
| 1141 | 4, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1142 | (struct phy_cmd[]){ /* config */ |
| 1143 | /* Override PHY config settings */ |
| 1144 | {MIIM_CIS8201_AUX_CONSTAT, |
| 1145 | MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1146 | /* Set up the interface mode */ |
| 1147 | {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, |
| 1148 | NULL}, |
| 1149 | /* Configure some basic stuff */ |
| 1150 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1151 | {miim_end,} |
| 1152 | }, |
| 1153 | (struct phy_cmd[]){ /* startup */ |
| 1154 | /* Read the Status (2x to make sure link is right) */ |
| 1155 | {MIIM_STATUS, miim_read, NULL}, |
| 1156 | /* Auto-negotiate */ |
| 1157 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1158 | /* Read the status */ |
| 1159 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, |
| 1160 | &mii_parse_cis8201}, |
| 1161 | {miim_end,} |
| 1162 | }, |
| 1163 | (struct phy_cmd[]){ /* shutdown */ |
| 1164 | {miim_end,} |
| 1165 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1166 | }; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1167 | struct phy_info phy_info_VSC8244 = { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1168 | 0x3f1b, |
| 1169 | "Vitesse VSC8244", |
| 1170 | 6, |
| 1171 | (struct phy_cmd[]){ /* config */ |
| 1172 | /* Override PHY config settings */ |
| 1173 | /* Configure some basic stuff */ |
| 1174 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1175 | {miim_end,} |
| 1176 | }, |
| 1177 | (struct phy_cmd[]){ /* startup */ |
| 1178 | /* Read the Status (2x to make sure link is right) */ |
| 1179 | {MIIM_STATUS, miim_read, NULL}, |
| 1180 | /* Auto-negotiate */ |
| 1181 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1182 | /* Read the status */ |
| 1183 | {MIIM_VSC8244_AUX_CONSTAT, miim_read, |
| 1184 | &mii_parse_vsc8244}, |
| 1185 | {miim_end,} |
| 1186 | }, |
| 1187 | (struct phy_cmd[]){ /* shutdown */ |
| 1188 | {miim_end,} |
| 1189 | }, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1190 | }; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1191 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1192 | struct phy_info phy_info_dm9161 = { |
| 1193 | 0x0181b88, |
| 1194 | "Davicom DM9161E", |
| 1195 | 4, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1196 | (struct phy_cmd[]){ /* config */ |
| 1197 | {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL}, |
| 1198 | /* Do not bypass the scrambler/descrambler */ |
| 1199 | {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL}, |
| 1200 | /* Clear 10BTCSR to default */ |
| 1201 | {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, |
| 1202 | NULL}, |
| 1203 | /* Configure some basic stuff */ |
| 1204 | {MIIM_CONTROL, MIIM_CR_INIT, NULL}, |
| 1205 | /* Restart Auto Negotiation */ |
| 1206 | {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL}, |
| 1207 | {miim_end,} |
| 1208 | }, |
| 1209 | (struct phy_cmd[]){ /* startup */ |
| 1210 | /* Status is read once to clear old link state */ |
| 1211 | {MIIM_STATUS, miim_read, NULL}, |
| 1212 | /* Auto-negotiate */ |
| 1213 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1214 | /* Read the status */ |
| 1215 | {MIIM_DM9161_SCSR, miim_read, |
| 1216 | &mii_parse_dm9161_scsr}, |
| 1217 | {miim_end,} |
| 1218 | }, |
| 1219 | (struct phy_cmd[]){ /* shutdown */ |
| 1220 | {miim_end,} |
| 1221 | }, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1222 | }; |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 1223 | /* a generic flavor. */ |
| 1224 | struct phy_info phy_info_generic = { |
| 1225 | 0, |
| 1226 | "Unknown/Generic PHY", |
| 1227 | 32, |
| 1228 | (struct phy_cmd[]) { /* config */ |
| 1229 | {PHY_BMCR, PHY_BMCR_RESET, NULL}, |
| 1230 | {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL}, |
| 1231 | {miim_end,} |
| 1232 | }, |
| 1233 | (struct phy_cmd[]) { /* startup */ |
| 1234 | {PHY_BMSR, miim_read, NULL}, |
| 1235 | {PHY_BMSR, miim_read, &mii_parse_sr}, |
| 1236 | {PHY_BMSR, miim_read, &mii_parse_link}, |
| 1237 | {miim_end,} |
| 1238 | }, |
| 1239 | (struct phy_cmd[]) { /* shutdown */ |
| 1240 | {miim_end,} |
| 1241 | } |
| 1242 | }; |
| 1243 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1244 | |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1245 | uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv) |
| 1246 | { |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1247 | unsigned int speed; |
| 1248 | if (priv->link) { |
| 1249 | speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK; |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1250 | |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1251 | switch (speed) { |
| 1252 | case MIIM_LXT971_SR2_10HDX: |
| 1253 | priv->speed = 10; |
| 1254 | priv->duplexity = 0; |
| 1255 | break; |
| 1256 | case MIIM_LXT971_SR2_10FDX: |
| 1257 | priv->speed = 10; |
| 1258 | priv->duplexity = 1; |
| 1259 | break; |
| 1260 | case MIIM_LXT971_SR2_100HDX: |
| 1261 | priv->speed = 100; |
| 1262 | priv->duplexity = 0; |
| 1263 | default: |
| 1264 | priv->speed = 100; |
| 1265 | priv->duplexity = 1; |
| 1266 | break; |
| 1267 | } |
| 1268 | } else { |
| 1269 | priv->speed = 0; |
| 1270 | priv->duplexity = 0; |
| 1271 | } |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1272 | |
wdenk | e085e5b | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1273 | return 0; |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1276 | static struct phy_info phy_info_lxt971 = { |
| 1277 | 0x0001378e, |
| 1278 | "LXT971", |
| 1279 | 4, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1280 | (struct phy_cmd[]){ /* config */ |
| 1281 | {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */ |
| 1282 | {miim_end,} |
| 1283 | }, |
| 1284 | (struct phy_cmd[]){ /* startup - enable interrupts */ |
| 1285 | /* { 0x12, 0x00f2, NULL }, */ |
| 1286 | {MIIM_STATUS, miim_read, NULL}, |
| 1287 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1288 | {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2}, |
| 1289 | {miim_end,} |
| 1290 | }, |
| 1291 | (struct phy_cmd[]){ /* shutdown - disable interrupts */ |
| 1292 | {miim_end,} |
| 1293 | }, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1294 | }; |
| 1295 | |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1296 | /* 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] | 1297 | * information |
| 1298 | */ |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1299 | uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv) |
| 1300 | { |
| 1301 | switch (mii_reg & MIIM_DP83865_SPD_MASK) { |
| 1302 | |
| 1303 | case MIIM_DP83865_SPD_1000: |
| 1304 | priv->speed = 1000; |
| 1305 | break; |
| 1306 | |
| 1307 | case MIIM_DP83865_SPD_100: |
| 1308 | priv->speed = 100; |
| 1309 | break; |
| 1310 | |
| 1311 | default: |
| 1312 | priv->speed = 10; |
| 1313 | break; |
| 1314 | |
| 1315 | } |
| 1316 | |
| 1317 | if (mii_reg & MIIM_DP83865_DPX_FULL) |
| 1318 | priv->duplexity = 1; |
| 1319 | else |
| 1320 | priv->duplexity = 0; |
| 1321 | |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | struct phy_info phy_info_dp83865 = { |
| 1326 | 0x20005c7, |
| 1327 | "NatSemi DP83865", |
| 1328 | 4, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1329 | (struct phy_cmd[]){ /* config */ |
| 1330 | {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL}, |
| 1331 | {miim_end,} |
| 1332 | }, |
| 1333 | (struct phy_cmd[]){ /* startup */ |
| 1334 | /* Status is read once to clear old link state */ |
| 1335 | {MIIM_STATUS, miim_read, NULL}, |
| 1336 | /* Auto-negotiate */ |
| 1337 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1338 | /* Read the link and auto-neg status */ |
| 1339 | {MIIM_DP83865_LANR, miim_read, |
| 1340 | &mii_parse_dp83865_lanr}, |
| 1341 | {miim_end,} |
| 1342 | }, |
| 1343 | (struct phy_cmd[]){ /* shutdown */ |
| 1344 | {miim_end,} |
| 1345 | }, |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1346 | }; |
| 1347 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1348 | struct phy_info *phy_info[] = { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1349 | &phy_info_cis8204, |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 1350 | &phy_info_cis8201, |
Paul Gortmaker | 2bd9f1b | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 1351 | &phy_info_BCM5461S, |
Joe Hamman | ed7ad4e | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1352 | &phy_info_BCM5464S, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1353 | &phy_info_M88E1011S, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1354 | &phy_info_M88E1111S, |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1355 | &phy_info_M88E1145, |
Wolfgang Denk | 15e8757 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1356 | &phy_info_M88E1149S, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1357 | &phy_info_dm9161, |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1358 | &phy_info_lxt971, |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1359 | &phy_info_VSC8244, |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1360 | &phy_info_dp83865, |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 1361 | &phy_info_generic, |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1362 | NULL |
| 1363 | }; |
| 1364 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1365 | /* Grab the identifier of the device's PHY, and search through |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1366 | * 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] | 1367 | * it, if not, return NULL |
| 1368 | */ |
| 1369 | struct phy_info *get_phy_info(struct eth_device *dev) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1370 | { |
| 1371 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 1372 | uint phy_reg, phy_ID; |
| 1373 | int i; |
| 1374 | struct phy_info *theInfo = NULL; |
| 1375 | |
| 1376 | /* Grab the bits from PHYIR1, and put them in the upper half */ |
| 1377 | phy_reg = read_phy_reg(priv, MIIM_PHYIR1); |
| 1378 | phy_ID = (phy_reg & 0xffff) << 16; |
| 1379 | |
| 1380 | /* Grab the bits from PHYIR2, and put them in the lower half */ |
| 1381 | phy_reg = read_phy_reg(priv, MIIM_PHYIR2); |
| 1382 | phy_ID |= (phy_reg & 0xffff); |
| 1383 | |
| 1384 | /* loop through all the known PHY types, and find one that */ |
| 1385 | /* matches the ID we read from the PHY. */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1386 | for (i = 0; phy_info[i]; i++) { |
Andy Fleming | b2d14f4 | 2007-05-09 00:54:20 -0500 | [diff] [blame] | 1387 | if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1388 | theInfo = phy_info[i]; |
Andy Fleming | b2d14f4 | 2007-05-09 00:54:20 -0500 | [diff] [blame] | 1389 | break; |
| 1390 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1393 | if (theInfo == NULL) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1394 | printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID); |
| 1395 | return NULL; |
| 1396 | } else { |
Stefan Roese | c0dc34f | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 1397 | debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | return theInfo; |
| 1401 | } |
| 1402 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1403 | /* Execute the given series of commands on the given device's |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1404 | * PHY, running functions as necessary |
| 1405 | */ |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1406 | void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd) |
| 1407 | { |
| 1408 | int i; |
| 1409 | uint result; |
| 1410 | volatile tsec_t *phyregs = priv->phyregs; |
| 1411 | |
| 1412 | phyregs->miimcfg = MIIMCFG_RESET; |
| 1413 | |
| 1414 | phyregs->miimcfg = MIIMCFG_INIT_VALUE; |
| 1415 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1416 | while (phyregs->miimind & MIIMIND_BUSY) ; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1417 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1418 | for (i = 0; cmd->mii_reg != miim_end; i++) { |
| 1419 | if (cmd->mii_data == miim_read) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1420 | result = read_phy_reg(priv, cmd->mii_reg); |
| 1421 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1422 | if (cmd->funct != NULL) |
| 1423 | (*(cmd->funct)) (result, priv); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1424 | |
| 1425 | } else { |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1426 | if (cmd->funct != NULL) |
| 1427 | result = (*(cmd->funct)) (cmd->mii_reg, priv); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1428 | else |
| 1429 | result = cmd->mii_data; |
| 1430 | |
| 1431 | write_phy_reg(priv, cmd->mii_reg, result); |
| 1432 | |
| 1433 | } |
| 1434 | cmd++; |
| 1435 | } |
| 1436 | } |
| 1437 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1438 | /* Relocate the function pointers in the phy cmd lists */ |
| 1439 | static void relocate_cmds(void) |
| 1440 | { |
| 1441 | struct phy_cmd **cmdlistptr; |
| 1442 | struct phy_cmd *cmd; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1443 | int i, j, k; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1444 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1445 | for (i = 0; phy_info[i]; i++) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1446 | /* First thing's first: relocate the pointers to the |
| 1447 | * PHY command structures (the structs were done) */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1448 | phy_info[i] = (struct phy_info *)((uint) phy_info[i] |
| 1449 | + gd->reloc_off); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1450 | phy_info[i]->name += gd->reloc_off; |
| 1451 | phy_info[i]->config = |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1452 | (struct phy_cmd *)((uint) phy_info[i]->config |
| 1453 | + gd->reloc_off); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1454 | phy_info[i]->startup = |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1455 | (struct phy_cmd *)((uint) phy_info[i]->startup |
| 1456 | + gd->reloc_off); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1457 | phy_info[i]->shutdown = |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1458 | (struct phy_cmd *)((uint) phy_info[i]->shutdown |
| 1459 | + gd->reloc_off); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1460 | |
| 1461 | cmdlistptr = &phy_info[i]->config; |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1462 | j = 0; |
| 1463 | for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) { |
| 1464 | k = 0; |
| 1465 | for (cmd = *cmdlistptr; |
| 1466 | cmd->mii_reg != miim_end; |
| 1467 | cmd++) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1468 | /* Only relocate non-NULL pointers */ |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1469 | if (cmd->funct) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1470 | cmd->funct += gd->reloc_off; |
| 1471 | |
| 1472 | k++; |
| 1473 | } |
| 1474 | j++; |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | relocated = 1; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
Jon Loeliger | 82ecaad | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 1481 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1482 | && !defined(BITBANGMII) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1483 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1484 | struct tsec_private *get_priv_for_phy(unsigned char phyaddr) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1485 | { |
| 1486 | int i; |
| 1487 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1488 | for (i = 0; i < MAXCONTROLLERS; i++) { |
| 1489 | if (privlist[i]->phyaddr == phyaddr) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1490 | return privlist[i]; |
| 1491 | } |
| 1492 | |
| 1493 | return NULL; |
| 1494 | } |
| 1495 | |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1496 | /* |
| 1497 | * Read a MII PHY register. |
| 1498 | * |
| 1499 | * Returns: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1500 | * 0 on success |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1501 | */ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1502 | static int tsec_miiphy_read(char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1503 | unsigned char reg, unsigned short *value) |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1504 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1505 | unsigned short ret; |
| 1506 | struct tsec_private *priv = get_priv_for_phy(addr); |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1507 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1508 | if (NULL == priv) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1509 | printf("Can't read PHY at address %d\n", addr); |
| 1510 | return -1; |
| 1511 | } |
| 1512 | |
| 1513 | ret = (unsigned short)read_phy_reg(priv, reg); |
| 1514 | *value = ret; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1515 | |
| 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | /* |
| 1520 | * Write a MII PHY register. |
| 1521 | * |
| 1522 | * Returns: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1523 | * 0 on success |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1524 | */ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1525 | static int tsec_miiphy_write(char *devname, unsigned char addr, |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1526 | unsigned char reg, unsigned short value) |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1527 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1528 | struct tsec_private *priv = get_priv_for_phy(addr); |
| 1529 | |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1530 | if (NULL == priv) { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1531 | printf("Can't write PHY at address %d\n", addr); |
| 1532 | return -1; |
| 1533 | } |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1534 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1535 | write_phy_reg(priv, reg, value); |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1536 | |
| 1537 | return 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1538 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1539 | |
Jon Loeliger | 82ecaad | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 1540 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1541 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1542 | #endif /* CONFIG_TSEC_ENET */ |