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