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