wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /*------------------------------------------------------------------------ |
| 2 | . smc91111.c |
| 3 | . This is a driver for SMSC's 91C111 single-chip Ethernet device. |
| 4 | . |
| 5 | . (C) Copyright 2002 |
| 6 | . Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | . Rolf Offermanns <rof@sysgo.de> |
| 8 | . |
| 9 | . Copyright (C) 2001 Standard Microsystems Corporation (SMSC) |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 10 | . Developed by Simple Network Magic Corporation (SNMC) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 11 | . Copyright (C) 1996 by Erik Stahlman (ES) |
| 12 | . |
| 13 | . This program is free software; you can redistribute it and/or modify |
| 14 | . it under the terms of the GNU General Public License as published by |
| 15 | . the Free Software Foundation; either version 2 of the License, or |
| 16 | . (at your option) any later version. |
| 17 | . |
| 18 | . This program is distributed in the hope that it will be useful, |
| 19 | . but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 20 | . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 21 | . GNU General Public License for more details. |
| 22 | . |
| 23 | . You should have received a copy of the GNU General Public License |
| 24 | . along with this program; if not, write to the Free Software |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 25 | . Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 26 | . |
| 27 | . Information contained in this file was obtained from the LAN91C111 |
| 28 | . manual from SMC. To get a copy, if you really want one, you can find |
| 29 | . information under www.smsc.com. |
| 30 | . |
| 31 | . |
| 32 | . "Features" of the SMC chip: |
| 33 | . Integrated PHY/MAC for 10/100BaseT Operation |
| 34 | . Supports internal and external MII |
| 35 | . Integrated 8K packet memory |
| 36 | . EEPROM interface for configuration |
| 37 | . |
| 38 | . Arguments: |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 39 | . io = for the base address |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 40 | . irq = for the IRQ |
| 41 | . |
| 42 | . author: |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 43 | . Erik Stahlman ( erik@vt.edu ) |
| 44 | . Daris A Nevil ( dnevil@snmc.com ) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 45 | . |
| 46 | . |
| 47 | . Hardware multicast code from Peter Cammaert ( pc@denkart.be ) |
| 48 | . |
| 49 | . Sources: |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 50 | . o SMSC LAN91C111 databook (www.smsc.com) |
| 51 | . o smc9194.c by Erik Stahlman |
| 52 | . o skeleton.c by Donald Becker ( becker@cesdis.gsfc.nasa.gov ) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 53 | . |
| 54 | . History: |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 55 | . 06/19/03 Richard Woodruff Made u-boot environment aware and added mac addr checks. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 56 | . 10/17/01 Marco Hasewinkel Modify for DNP/1110 |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 57 | . 07/25/01 Woojung Huh Modify for ADS Bitsy |
| 58 | . 04/25/01 Daris A Nevil Initial public release through SMSC |
| 59 | . 03/16/01 Daris A Nevil Modified smc9194.c for use with LAN91C111 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 60 | ----------------------------------------------------------------------------*/ |
| 61 | |
| 62 | #include <common.h> |
| 63 | #include <command.h> |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 64 | #include <config.h> |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 65 | #include <malloc.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 66 | #include "smc91111.h" |
| 67 | #include <net.h> |
| 68 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 69 | /* Use power-down feature of the chip */ |
| 70 | #define POWER_DOWN 0 |
| 71 | |
| 72 | #define NO_AUTOPROBE |
| 73 | |
Wolfgang Denk | 2105aa2 | 2006-03-07 00:22:36 +0100 | [diff] [blame] | 74 | #define SMC_DEBUG 0 |
wdenk | f4cec3f | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 75 | |
| 76 | #if SMC_DEBUG > 1 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 77 | static const char version[] = |
| 78 | "smc91111.c:v1.0 04/25/01 by Daris A Nevil (dnevil@snmc.com)\n"; |
wdenk | f4cec3f | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 79 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 80 | |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 81 | /* Autonegotiation timeout in seconds */ |
| 82 | #ifndef CONFIG_SMC_AUTONEG_TIMEOUT |
| 83 | #define CONFIG_SMC_AUTONEG_TIMEOUT 10 |
| 84 | #endif |
| 85 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 86 | /*------------------------------------------------------------------------ |
| 87 | . |
| 88 | . Configuration options, for the experienced user to change. |
| 89 | . |
| 90 | -------------------------------------------------------------------------*/ |
| 91 | |
| 92 | /* |
| 93 | . Wait time for memory to be free. This probably shouldn't be |
| 94 | . tuned that much, as waiting for this means nothing else happens |
| 95 | . in the system |
| 96 | */ |
| 97 | #define MEMORY_WAIT_TIME 16 |
| 98 | |
| 99 | |
| 100 | #if (SMC_DEBUG > 2 ) |
| 101 | #define PRINTK3(args...) printf(args) |
| 102 | #else |
| 103 | #define PRINTK3(args...) |
| 104 | #endif |
| 105 | |
| 106 | #if SMC_DEBUG > 1 |
| 107 | #define PRINTK2(args...) printf(args) |
| 108 | #else |
| 109 | #define PRINTK2(args...) |
| 110 | #endif |
| 111 | |
| 112 | #ifdef SMC_DEBUG |
| 113 | #define PRINTK(args...) printf(args) |
| 114 | #else |
| 115 | #define PRINTK(args...) |
| 116 | #endif |
| 117 | |
| 118 | |
| 119 | /*------------------------------------------------------------------------ |
| 120 | . |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 121 | . The internal workings of the driver. If you are changing anything |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 122 | . here with the SMC stuff, you should have the datasheet and know |
| 123 | . what you are doing. |
| 124 | . |
| 125 | -------------------------------------------------------------------------*/ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 126 | |
| 127 | /* Memory sizing constant */ |
| 128 | #define LAN91C111_MEMORY_MULTIPLIER (1024*2) |
| 129 | |
| 130 | #ifndef CONFIG_SMC91111_BASE |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 131 | #error "SMC91111 Base address must be passed to initialization funciton" |
| 132 | /* #define CONFIG_SMC91111_BASE 0x20000300 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 133 | #endif |
| 134 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 135 | #define SMC_DEV_NAME "SMC91111" |
| 136 | #define SMC_PHY_ADDR 0x0000 |
| 137 | #define SMC_ALLOC_MAX_TRY 5 |
| 138 | #define SMC_TX_TIMEOUT 30 |
| 139 | |
| 140 | #define SMC_PHY_CLOCK_DELAY 1000 |
| 141 | |
| 142 | #define ETH_ZLEN 60 |
| 143 | |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 144 | #ifdef CONFIG_SMC_USE_32_BIT |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 145 | #define USE_32_BIT 1 |
| 146 | #else |
| 147 | #undef USE_32_BIT |
| 148 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 149 | |
Wolfgang Denk | 46d2b52 | 2006-03-12 02:10:00 +0100 | [diff] [blame] | 150 | #ifdef SHARED_RESOURCES |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 151 | extern void swap_to(int device_id); |
| 152 | #else |
| 153 | # define swap_to(x) |
Wolfgang Denk | 46d2b52 | 2006-03-12 02:10:00 +0100 | [diff] [blame] | 154 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 155 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 156 | #ifndef CONFIG_SMC91111_EXT_PHY |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 157 | static void smc_phy_configure(struct eth_device *dev); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 158 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 159 | |
| 160 | /* |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 161 | ------------------------------------------------------------ |
| 162 | . |
| 163 | . Internal routines |
| 164 | . |
| 165 | ------------------------------------------------------------ |
| 166 | */ |
| 167 | |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 168 | #ifdef CONFIG_SMC_USE_IOFUNCS |
| 169 | /* |
| 170 | * input and output functions |
| 171 | * |
| 172 | * Implemented due to inx,outx macros accessing the device improperly |
| 173 | * and putting the device into an unkown state. |
| 174 | * |
| 175 | * For instance, on Sharp LPD7A400 SDK, affects were chip memory |
| 176 | * could not be free'd (hence the alloc failures), duplicate packets, |
| 177 | * packets being corrupt (shifted) on the wire, etc. Switching to the |
| 178 | * inx,outx functions fixed this problem. |
| 179 | */ |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 180 | |
| 181 | #define barrier() __asm__ __volatile__("": : :"memory") |
| 182 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 183 | static inline word SMC_inw(struct eth_device *dev, dword offset) |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 184 | { |
| 185 | word v; |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 186 | v = *((volatile word*)(dev->iobase + offset)); |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 187 | barrier(); *(volatile u32*)(0xc0000000); |
| 188 | return v; |
| 189 | } |
| 190 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 191 | static inline void SMC_outw(struct eth_device *dev, word value, dword offset) |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 192 | { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 193 | *((volatile word*)(dev->iobase + offset)) = value; |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 194 | barrier(); *(volatile u32*)(0xc0000000); |
| 195 | } |
| 196 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 197 | static inline byte SMC_inb(struct eth_device *dev, dword offset) |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 198 | { |
| 199 | word _w; |
| 200 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 201 | _w = SMC_inw(dev, offset & ~((dword)1)); |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 202 | return (offset & 1) ? (byte)(_w >> 8) : (byte)(_w); |
| 203 | } |
| 204 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 205 | static inline void SMC_outb(struct eth_device *dev, byte value, dword offset) |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 206 | { |
| 207 | word _w; |
| 208 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 209 | _w = SMC_inw(dev, offset & ~((dword)1)); |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 210 | if (offset & 1) |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 211 | *((volatile word*)(dev->iobase + (offset & ~((dword)1)))) = |
| 212 | (value<<8) | (_w & 0x00ff); |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 213 | else |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 214 | *((volatile word*)(dev->iobase + offset)) = |
| 215 | value | (_w & 0xff00); |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 218 | static inline void SMC_insw(struct eth_device *dev, dword offset, |
| 219 | volatile uchar* buf, dword len) |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 220 | { |
Wolfgang Denk | 7fa6e90 | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 221 | volatile word *p = (volatile word *)buf; |
| 222 | |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 223 | while (len-- > 0) { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 224 | *p++ = SMC_inw(dev, offset); |
Wolfgang Denk | 7fa6e90 | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 225 | barrier(); |
| 226 | *((volatile u32*)(0xc0000000)); |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 230 | static inline void SMC_outsw(struct eth_device *dev, dword offset, |
| 231 | uchar* buf, dword len) |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 232 | { |
Wolfgang Denk | 7fa6e90 | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 233 | volatile word *p = (volatile word *)buf; |
| 234 | |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 235 | while (len-- > 0) { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 236 | SMC_outw(dev, *p++, offset); |
Wolfgang Denk | 7fa6e90 | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 237 | barrier(); |
| 238 | *(volatile u32*)(0xc0000000); |
wdenk | 76dd6c7 | 2004-06-09 14:47:54 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | #endif /* CONFIG_SMC_USE_IOFUNCS */ |
| 242 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 243 | /* |
| 244 | . A rather simple routine to print out a packet for debugging purposes. |
| 245 | */ |
| 246 | #if SMC_DEBUG > 2 |
| 247 | static void print_packet( byte *, int ); |
| 248 | #endif |
| 249 | |
| 250 | #define tx_done(dev) 1 |
| 251 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 252 | static int poll4int (struct eth_device *dev, byte mask, int timeout) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 253 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 254 | int tmo = get_timer (0) + timeout * CONFIG_SYS_HZ; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 255 | int is_timeout = 0; |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 256 | word old_bank = SMC_inw (dev, BSR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 257 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 258 | PRINTK2 ("Polling...\n"); |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 259 | SMC_SELECT_BANK (dev, 2); |
| 260 | while ((SMC_inw (dev, SMC91111_INT_REG) & mask) == 0) { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 261 | if (get_timer (0) >= tmo) { |
| 262 | is_timeout = 1; |
| 263 | break; |
| 264 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 265 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 266 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 267 | /* restore old bank selection */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 268 | SMC_SELECT_BANK (dev, old_bank); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 269 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 270 | if (is_timeout) |
| 271 | return 1; |
| 272 | else |
| 273 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 274 | } |
| 275 | |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 276 | /* Only one release command at a time, please */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 277 | static inline void smc_wait_mmu_release_complete (struct eth_device *dev) |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 278 | { |
| 279 | int count = 0; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 280 | |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 281 | /* assume bank 2 selected */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 282 | while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 283 | udelay (1); /* Wait until not busy */ |
| 284 | if (++count > 200) |
| 285 | break; |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 289 | /* |
| 290 | . Function: smc_reset( void ) |
| 291 | . Purpose: |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 292 | . This sets the SMC91111 chip to its normal state, hopefully from whatever |
| 293 | . mess that any other DOS driver has put it in. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 294 | . |
| 295 | . Maybe I should reset more registers to defaults in here? SOFTRST should |
| 296 | . do that for me. |
| 297 | . |
| 298 | . Method: |
| 299 | . 1. send a SOFT RESET |
| 300 | . 2. wait for it to finish |
| 301 | . 3. enable autorelease mode |
| 302 | . 4. reset the memory management unit |
| 303 | . 5. clear all interrupts |
| 304 | . |
| 305 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 306 | static void smc_reset (struct eth_device *dev) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 307 | { |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 308 | PRINTK2 ("%s: smc_reset\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 309 | |
| 310 | /* This resets the registers mostly to defaults, but doesn't |
| 311 | affect EEPROM. That seems unnecessary */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 312 | SMC_SELECT_BANK (dev, 0); |
| 313 | SMC_outw (dev, RCR_SOFTRST, RCR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 314 | |
| 315 | /* Setup the Configuration Register */ |
| 316 | /* This is necessary because the CONFIG_REG is not affected */ |
| 317 | /* by a soft reset */ |
| 318 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 319 | SMC_SELECT_BANK (dev, 1); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 320 | #if defined(CONFIG_SMC91111_EXT_PHY) |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 321 | SMC_outw (dev, CONFIG_DEFAULT | CONFIG_EXT_PHY, CONFIG_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 322 | #else |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 323 | SMC_outw (dev, CONFIG_DEFAULT, CONFIG_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 324 | #endif |
| 325 | |
| 326 | |
| 327 | /* Release from possible power-down state */ |
| 328 | /* Configuration register is not affected by Soft Reset */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 329 | SMC_outw (dev, SMC_inw (dev, CONFIG_REG) | CONFIG_EPH_POWER_EN, |
| 330 | CONFIG_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 331 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 332 | SMC_SELECT_BANK (dev, 0); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 333 | |
| 334 | /* this should pause enough for the chip to be happy */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 335 | udelay (10); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 336 | |
| 337 | /* Disable transmit and receive functionality */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 338 | SMC_outw (dev, RCR_CLEAR, RCR_REG); |
| 339 | SMC_outw (dev, TCR_CLEAR, TCR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 340 | |
| 341 | /* set the control register */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 342 | SMC_SELECT_BANK (dev, 1); |
| 343 | SMC_outw (dev, CTL_DEFAULT, CTL_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 344 | |
| 345 | /* Reset the MMU */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 346 | SMC_SELECT_BANK (dev, 2); |
| 347 | smc_wait_mmu_release_complete (dev); |
| 348 | SMC_outw (dev, MC_RESET, MMU_CMD_REG); |
| 349 | while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 350 | udelay (1); /* Wait until not busy */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 351 | |
| 352 | /* Note: It doesn't seem that waiting for the MMU busy is needed here, |
| 353 | but this is a place where future chipsets _COULD_ break. Be wary |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 354 | of issuing another MMU command right after this */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 355 | |
| 356 | /* Disable all interrupts */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 357 | SMC_outb (dev, 0, IM_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /* |
| 361 | . Function: smc_enable |
| 362 | . Purpose: let the chip talk to the outside work |
| 363 | . Method: |
| 364 | . 1. Enable the transmitter |
| 365 | . 2. Enable the receiver |
| 366 | . 3. Enable interrupts |
| 367 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 368 | static void smc_enable(struct eth_device *dev) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 369 | { |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 370 | PRINTK2("%s: smc_enable\n", SMC_DEV_NAME); |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 371 | SMC_SELECT_BANK( dev, 0 ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 372 | /* see the header file for options in TCR/RCR DEFAULT*/ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 373 | SMC_outw( dev, TCR_DEFAULT, TCR_REG ); |
| 374 | SMC_outw( dev, RCR_DEFAULT, RCR_REG ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 375 | |
| 376 | /* clear MII_DIS */ |
| 377 | /* smc_write_phy_register(PHY_CNTL_REG, 0x0000); */ |
| 378 | } |
| 379 | |
| 380 | /* |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 381 | . Function: smc_halt |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 382 | . Purpose: closes down the SMC91xxx chip. |
| 383 | . Method: |
| 384 | . 1. zero the interrupt mask |
| 385 | . 2. clear the enable receive flag |
| 386 | . 3. clear the enable xmit flags |
| 387 | . |
| 388 | . TODO: |
| 389 | . (1) maybe utilize power down mode. |
| 390 | . Why not yet? Because while the chip will go into power down mode, |
| 391 | . the manual says that it will wake up in response to any I/O requests |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 392 | . in the register space. Empirical results do not show this working. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 393 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 394 | static void smc_halt(struct eth_device *dev) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 395 | { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 396 | PRINTK2("%s: smc_halt\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 397 | |
| 398 | /* no more interrupts for me */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 399 | SMC_SELECT_BANK( dev, 2 ); |
| 400 | SMC_outb( dev, 0, IM_REG ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 401 | |
| 402 | /* and tell the card to stay away from that nasty outside world */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 403 | SMC_SELECT_BANK( dev, 0 ); |
| 404 | SMC_outb( dev, RCR_CLEAR, RCR_REG ); |
| 405 | SMC_outb( dev, TCR_CLEAR, TCR_REG ); |
| 406 | |
Wolfgang Denk | 46d2b52 | 2006-03-12 02:10:00 +0100 | [diff] [blame] | 407 | swap_to(FLASH); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
| 411 | /* |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 412 | . Function: smc_send(struct net_device * ) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 413 | . Purpose: |
| 414 | . This sends the actual packet to the SMC9xxx chip. |
| 415 | . |
| 416 | . Algorithm: |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 417 | . First, see if a saved_skb is available. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 418 | . ( this should NOT be called if there is no 'saved_skb' |
| 419 | . Now, find the packet number that the chip allocated |
| 420 | . Point the data pointers at it in memory |
| 421 | . Set the length word in the chip's memory |
| 422 | . Dump the packet to chip memory |
| 423 | . Check if a last byte is needed ( odd length packet ) |
| 424 | . if so, set the control flag right |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 425 | . Tell the card to send it |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 426 | . Enable the transmit interrupt, so I know if it failed |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 427 | . Free the kernel data if I actually sent it. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 428 | */ |
Joe Hershberger | a391c7c | 2012-05-21 14:45:32 +0000 | [diff] [blame] | 429 | static int smc_send(struct eth_device *dev, void *packet, int packet_length) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 430 | { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 431 | byte packet_no; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 432 | byte *buf; |
| 433 | int length; |
| 434 | int numPages; |
| 435 | int try = 0; |
| 436 | int time_out; |
| 437 | byte status; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 438 | byte saved_pnr; |
| 439 | word saved_ptr; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 440 | |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 441 | /* save PTR and PNR registers before manipulation */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 442 | SMC_SELECT_BANK (dev, 2); |
| 443 | saved_pnr = SMC_inb( dev, PN_REG ); |
| 444 | saved_ptr = SMC_inw( dev, PTR_REG ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 445 | |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 446 | PRINTK3 ("%s: smc_hardware_send_packet\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 447 | |
| 448 | length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN; |
| 449 | |
| 450 | /* allocate memory |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 451 | ** The MMU wants the number of pages to be the number of 256 bytes |
| 452 | ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) ) |
| 453 | ** |
| 454 | ** The 91C111 ignores the size bits, but the code is left intact |
| 455 | ** for backwards and future compatibility. |
| 456 | ** |
| 457 | ** Pkt size for allocating is data length +6 (for additional status |
| 458 | ** words, length and ctl!) |
| 459 | ** |
| 460 | ** If odd size then last byte is included in this header. |
| 461 | */ |
| 462 | numPages = ((length & 0xfffe) + 6); |
| 463 | numPages >>= 8; /* Divide by 256 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 464 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 465 | if (numPages > 7) { |
| 466 | printf ("%s: Far too big packet error. \n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | /* now, try to allocate the memory */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 471 | SMC_SELECT_BANK (dev, 2); |
| 472 | SMC_outw (dev, MC_ALLOC | numPages, MMU_CMD_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 473 | |
wdenk | c8434db | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 474 | /* FIXME: the ALLOC_INT bit never gets set * |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 475 | * so the following will always give a * |
| 476 | * memory allocation error. * |
| 477 | * same code works in armboot though * |
wdenk | c8434db | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 478 | * -ro |
| 479 | */ |
| 480 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 481 | again: |
| 482 | try++; |
| 483 | time_out = MEMORY_WAIT_TIME; |
| 484 | do { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 485 | status = SMC_inb (dev, SMC91111_INT_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 486 | if (status & IM_ALLOC_INT) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 487 | /* acknowledge the interrupt */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 488 | SMC_outb (dev, IM_ALLOC_INT, SMC91111_INT_REG); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 489 | break; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 490 | } |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 491 | } while (--time_out); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 492 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 493 | if (!time_out) { |
| 494 | PRINTK2 ("%s: memory allocation, try %d failed ...\n", |
| 495 | SMC_DEV_NAME, try); |
| 496 | if (try < SMC_ALLOC_MAX_TRY) |
| 497 | goto again; |
| 498 | else |
| 499 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 500 | } |
| 501 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 502 | PRINTK2 ("%s: memory allocation, try %d succeeded ...\n", |
| 503 | SMC_DEV_NAME, try); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 504 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 505 | buf = (byte *) packet; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 506 | |
| 507 | /* If I get here, I _know_ there is a packet slot waiting for me */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 508 | packet_no = SMC_inb (dev, AR_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 509 | if (packet_no & AR_FAILED) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 510 | /* or isn't there? BAD CHIP! */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 511 | printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /* we have a packet address, so tell the card to use it */ |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 516 | #ifndef CONFIG_XAENIAX |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 517 | SMC_outb (dev, packet_no, PN_REG); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 518 | #else |
| 519 | /* On Xaeniax board, we can't use SMC_outb here because that way |
| 520 | * the Allocate MMU command will end up written to the command register |
| 521 | * as well, which will lead to a problem. |
| 522 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 523 | SMC_outl (dev, packet_no << 16, 0); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 524 | #endif |
wdenk | d360213 | 2004-03-25 15:14:43 +0000 | [diff] [blame] | 525 | /* do not write new ptr value if Write data fifo not empty */ |
| 526 | while ( saved_ptr & PTR_NOTEMPTY ) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 527 | printf ("Write data fifo not empty!\n"); |
| 528 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 529 | /* point to the beginning of the packet */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 530 | SMC_outw (dev, PTR_AUTOINC, PTR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 531 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 532 | PRINTK3 ("%s: Trying to xmit packet of length %x\n", |
| 533 | SMC_DEV_NAME, length); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 534 | |
| 535 | #if SMC_DEBUG > 2 |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 536 | printf ("Transmitting Packet\n"); |
| 537 | print_packet (buf, length); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 538 | #endif |
| 539 | |
| 540 | /* send the packet length ( +6 for status, length and ctl byte ) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 541 | and the status word ( set to zeros ) */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 542 | #ifdef USE_32_BIT |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 543 | SMC_outl (dev, (length + 6) << 16, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 544 | #else |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 545 | SMC_outw (dev, 0, SMC91111_DATA_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 546 | /* send the packet length ( +6 for status words, length, and ctl */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 547 | SMC_outw (dev, (length + 6), SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 548 | #endif |
| 549 | |
| 550 | /* send the actual data |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 551 | . I _think_ it's faster to send the longs first, and then |
| 552 | . mop up by sending the last word. It depends heavily |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 553 | . on alignment, at least on the 486. Maybe it would be |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 554 | . a good idea to check which is optimal? But that could take |
| 555 | . almost as much time as is saved? |
| 556 | */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 557 | #ifdef USE_32_BIT |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 558 | SMC_outsl (dev, SMC91111_DATA_REG, buf, length >> 2); |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 559 | #ifndef CONFIG_XAENIAX |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 560 | if (length & 0x2) |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 561 | SMC_outw (dev, *((word *) (buf + (length & 0xFFFFFFFC))), |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 562 | SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 563 | #else |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 564 | /* On XANEIAX, we can only use 32-bit writes, so we need to handle |
| 565 | * unaligned tail part specially. The standard code doesn't work. |
| 566 | */ |
| 567 | if ((length & 3) == 3) { |
| 568 | u16 * ptr = (u16*) &buf[length-3]; |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 569 | SMC_outl(dev, (*ptr) | ((0x2000 | buf[length-1]) << 16), |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 570 | SMC91111_DATA_REG); |
| 571 | } else if ((length & 2) == 2) { |
| 572 | u16 * ptr = (u16*) &buf[length-2]; |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 573 | SMC_outl(dev, *ptr, SMC91111_DATA_REG); |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 574 | } else if (length & 1) { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 575 | SMC_outl(dev, (0x2000 | buf[length-1]), SMC91111_DATA_REG); |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 576 | } else { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 577 | SMC_outl(dev, 0, SMC91111_DATA_REG); |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 578 | } |
| 579 | #endif |
| 580 | #else |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 581 | SMC_outsw (dev, SMC91111_DATA_REG, buf, (length) >> 1); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 582 | #endif /* USE_32_BIT */ |
| 583 | |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 584 | #ifndef CONFIG_XAENIAX |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 585 | /* Send the last byte, if there is one. */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 586 | if ((length & 1) == 0) { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 587 | SMC_outw (dev, 0, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 588 | } else { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 589 | SMC_outw (dev, buf[length - 1] | 0x2000, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 590 | } |
wdenk | 28375a7 | 2004-11-22 22:20:07 +0000 | [diff] [blame] | 591 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 592 | |
| 593 | /* and let the chipset deal with it */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 594 | SMC_outw (dev, MC_ENQUEUE, MMU_CMD_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 595 | |
| 596 | /* poll for TX INT */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 597 | /* if (poll4int (dev, IM_TX_INT, SMC_TX_TIMEOUT)) { */ |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 598 | /* poll for TX_EMPTY INT - autorelease enabled */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 599 | if (poll4int(dev, IM_TX_EMPTY_INT, SMC_TX_TIMEOUT)) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 600 | /* sending failed */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 601 | PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 602 | |
| 603 | /* release packet */ |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 604 | /* no need to release, MMU does that now */ |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 605 | #ifdef CONFIG_XAENIAX |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 606 | SMC_outw (dev, MC_FREEPKT, MMU_CMD_REG); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 607 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 608 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 609 | /* wait for MMU getting ready (low) */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 610 | while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 611 | udelay (10); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 612 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 613 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 614 | PRINTK2 ("MMU ready\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 615 | |
| 616 | |
| 617 | return 0; |
| 618 | } else { |
| 619 | /* ack. int */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 620 | SMC_outb (dev, IM_TX_EMPTY_INT, SMC91111_INT_REG); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 621 | /* SMC_outb (IM_TX_INT, SMC91111_INT_REG); */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 622 | PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, |
| 623 | length); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 624 | |
| 625 | /* release packet */ |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 626 | /* no need to release, MMU does that now */ |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 627 | #ifdef CONFIG_XAENIAX |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 628 | SMC_outw (dev, MC_FREEPKT, MMU_CMD_REG); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 629 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 630 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 631 | /* wait for MMU getting ready (low) */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 632 | while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 633 | udelay (10); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 634 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 635 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 636 | PRINTK2 ("MMU ready\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 637 | |
| 638 | |
| 639 | } |
| 640 | |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 641 | /* restore previously saved registers */ |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 642 | #ifndef CONFIG_XAENIAX |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 643 | SMC_outb( dev, saved_pnr, PN_REG ); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 644 | #else |
| 645 | /* On Xaeniax board, we can't use SMC_outb here because that way |
| 646 | * the Allocate MMU command will end up written to the command register |
| 647 | * as well, which will lead to a problem. |
| 648 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 649 | SMC_outl(dev, saved_pnr << 16, 0); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 650 | #endif |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 651 | SMC_outw( dev, saved_ptr, PTR_REG ); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 652 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 653 | return length; |
| 654 | } |
| 655 | |
Thomas Chou | c25126d | 2010-10-06 09:16:10 +0800 | [diff] [blame] | 656 | static int smc_write_hwaddr(struct eth_device *dev) |
| 657 | { |
| 658 | int i; |
| 659 | |
| 660 | swap_to(ETHERNET); |
| 661 | SMC_SELECT_BANK (dev, 1); |
| 662 | #ifdef USE_32_BIT |
| 663 | for (i = 0; i < 6; i += 2) { |
| 664 | word address; |
| 665 | |
| 666 | address = dev->enetaddr[i + 1] << 8; |
| 667 | address |= dev->enetaddr[i]; |
| 668 | SMC_outw(dev, address, (ADDR0_REG + i)); |
| 669 | } |
| 670 | #else |
| 671 | for (i = 0; i < 6; i++) |
| 672 | SMC_outb(dev, dev->enetaddr[i], (ADDR0_REG + i)); |
| 673 | #endif |
| 674 | swap_to(FLASH); |
| 675 | return 0; |
| 676 | } |
| 677 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 678 | /* |
| 679 | * Open and Initialize the board |
| 680 | * |
| 681 | * Set up everything, reset the card, etc .. |
| 682 | * |
| 683 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 684 | static int smc_init(struct eth_device *dev, bd_t *bd) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 685 | { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 686 | swap_to(ETHERNET); |
| 687 | |
| 688 | PRINTK2 ("%s: smc_init\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 689 | |
| 690 | /* reset the hardware */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 691 | smc_reset (dev); |
| 692 | smc_enable (dev); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 693 | |
| 694 | /* Configure the PHY */ |
| 695 | #ifndef CONFIG_SMC91111_EXT_PHY |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 696 | smc_phy_configure (dev); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 697 | #endif |
| 698 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 699 | /* conservative setting (10Mbps, HalfDuplex, no AutoNeg.) */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 700 | /* SMC_SELECT_BANK(dev, 0); */ |
| 701 | /* SMC_outw(dev, 0, RPC_REG); */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 702 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 703 | printf(SMC_DEV_NAME ": MAC %pM\n", dev->enetaddr); |
| 704 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 705 | return 0; |
| 706 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 707 | |
| 708 | /*------------------------------------------------------------- |
| 709 | . |
| 710 | . smc_rcv - receive a packet from the card |
| 711 | . |
| 712 | . There is ( at least ) a packet waiting to be read from |
| 713 | . chip-memory. |
| 714 | . |
| 715 | . o Read the status |
| 716 | . o If an error, record it |
| 717 | . o otherwise, read in the packet |
| 718 | -------------------------------------------------------------- |
| 719 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 720 | static int smc_rcv(struct eth_device *dev) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 721 | { |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 722 | int packet_number; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 723 | word status; |
| 724 | word packet_length; |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 725 | int is_error = 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 726 | #ifdef USE_32_BIT |
| 727 | dword stat_len; |
| 728 | #endif |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 729 | byte saved_pnr; |
| 730 | word saved_ptr; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 731 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 732 | SMC_SELECT_BANK(dev, 2); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 733 | /* save PTR and PTR registers */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 734 | saved_pnr = SMC_inb( dev, PN_REG ); |
| 735 | saved_ptr = SMC_inw( dev, PTR_REG ); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 736 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 737 | packet_number = SMC_inw( dev, RXFIFO_REG ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 738 | |
| 739 | if ( packet_number & RXFIFO_REMPTY ) { |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 744 | PRINTK3("%s: smc_rcv\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 745 | /* start reading from the start of the packet */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 746 | SMC_outw( dev, PTR_READ | PTR_RCV | PTR_AUTOINC, PTR_REG ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 747 | |
| 748 | /* First two words are status and packet_length */ |
| 749 | #ifdef USE_32_BIT |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 750 | stat_len = SMC_inl(dev, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 751 | status = stat_len & 0xffff; |
| 752 | packet_length = stat_len >> 16; |
| 753 | #else |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 754 | status = SMC_inw( dev, SMC91111_DATA_REG ); |
| 755 | packet_length = SMC_inw( dev, SMC91111_DATA_REG ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 756 | #endif |
| 757 | |
| 758 | packet_length &= 0x07ff; /* mask off top bits */ |
| 759 | |
| 760 | PRINTK2("RCV: STATUS %4x LENGTH %4x\n", status, packet_length ); |
| 761 | |
| 762 | if ( !(status & RS_ERRORS ) ){ |
| 763 | /* Adjust for having already read the first two words */ |
| 764 | packet_length -= 4; /*4; */ |
| 765 | |
| 766 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 767 | /* set odd length for bug in LAN91C111, */ |
| 768 | /* which never sets RS_ODDFRAME */ |
| 769 | /* TODO ? */ |
| 770 | |
| 771 | |
| 772 | #ifdef USE_32_BIT |
| 773 | PRINTK3(" Reading %d dwords (and %d bytes) \n", |
| 774 | packet_length >> 2, packet_length & 3 ); |
| 775 | /* QUESTION: Like in the TX routine, do I want |
| 776 | to send the DWORDs or the bytes first, or some |
| 777 | mixture. A mixture might improve already slow PIO |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 778 | performance */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 779 | SMC_insl( dev, SMC91111_DATA_REG, NetRxPackets[0], |
| 780 | packet_length >> 2 ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 781 | /* read the left over bytes */ |
| 782 | if (packet_length & 3) { |
| 783 | int i; |
| 784 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 785 | byte *tail = (byte *)(NetRxPackets[0] + |
| 786 | (packet_length & ~3)); |
| 787 | dword leftover = SMC_inl(dev, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 788 | for (i=0; i<(packet_length & 3); i++) |
| 789 | *tail++ = (byte) (leftover >> (8*i)) & 0xff; |
| 790 | } |
| 791 | #else |
| 792 | PRINTK3(" Reading %d words and %d byte(s) \n", |
| 793 | (packet_length >> 1 ), packet_length & 1 ); |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 794 | SMC_insw(dev, SMC91111_DATA_REG , NetRxPackets[0], |
| 795 | packet_length >> 1); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 796 | |
| 797 | #endif /* USE_32_BIT */ |
| 798 | |
| 799 | #if SMC_DEBUG > 2 |
| 800 | printf("Receiving Packet\n"); |
| 801 | print_packet( NetRxPackets[0], packet_length ); |
| 802 | #endif |
| 803 | } else { |
| 804 | /* error ... */ |
| 805 | /* TODO ? */ |
| 806 | is_error = 1; |
| 807 | } |
| 808 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 809 | while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY ) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 810 | udelay(1); /* Wait until not busy */ |
| 811 | |
| 812 | /* error or good, tell the card to get rid of this packet */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 813 | SMC_outw( dev, MC_RELEASE, MMU_CMD_REG ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 814 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 815 | while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY ) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 816 | udelay(1); /* Wait until not busy */ |
| 817 | |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 818 | /* restore saved registers */ |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 819 | #ifndef CONFIG_XAENIAX |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 820 | SMC_outb( dev, saved_pnr, PN_REG ); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 821 | #else |
| 822 | /* On Xaeniax board, we can't use SMC_outb here because that way |
| 823 | * the Allocate MMU command will end up written to the command register |
| 824 | * as well, which will lead to a problem. |
| 825 | */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 826 | SMC_outl( dev, saved_pnr << 16, 0); |
wdenk | ce5b6a9 | 2004-11-02 13:00:33 +0000 | [diff] [blame] | 827 | #endif |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 828 | SMC_outw( dev, saved_ptr, PTR_REG ); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 829 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 830 | if (!is_error) { |
| 831 | /* Pass the packet up to the protocol layers. */ |
| 832 | NetReceive(NetRxPackets[0], packet_length); |
| 833 | return packet_length; |
| 834 | } else { |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | } |
| 839 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 840 | |
| 841 | #if 0 |
| 842 | /*------------------------------------------------------------ |
| 843 | . Modify a bit in the LAN91C111 register set |
| 844 | .-------------------------------------------------------------*/ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 845 | static word smc_modify_regbit(struct eth_device *dev, int bank, int ioaddr, int reg, |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 846 | unsigned int bit, int val) |
| 847 | { |
| 848 | word regval; |
| 849 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 850 | SMC_SELECT_BANK( dev, bank ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 851 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 852 | regval = SMC_inw( dev, reg ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 853 | if (val) |
| 854 | regval |= bit; |
| 855 | else |
| 856 | regval &= ~bit; |
| 857 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 858 | SMC_outw( dev, regval, 0 ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 859 | return(regval); |
| 860 | } |
| 861 | |
| 862 | |
| 863 | /*------------------------------------------------------------ |
| 864 | . Retrieve a bit in the LAN91C111 register set |
| 865 | .-------------------------------------------------------------*/ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 866 | static int smc_get_regbit(struct eth_device *dev, int bank, int ioaddr, int reg, unsigned int bit) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 867 | { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 868 | SMC_SELECT_BANK( dev, bank ); |
| 869 | if ( SMC_inw( dev, reg ) & bit) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 870 | return(1); |
| 871 | else |
| 872 | return(0); |
| 873 | } |
| 874 | |
| 875 | |
| 876 | /*------------------------------------------------------------ |
| 877 | . Modify a LAN91C111 register (word access only) |
| 878 | .-------------------------------------------------------------*/ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 879 | static void smc_modify_reg(struct eth_device *dev, int bank, int ioaddr, int reg, word val) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 880 | { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 881 | SMC_SELECT_BANK( dev, bank ); |
| 882 | SMC_outw( dev, val, reg ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | |
| 886 | /*------------------------------------------------------------ |
| 887 | . Retrieve a LAN91C111 register (word access only) |
| 888 | .-------------------------------------------------------------*/ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 889 | static int smc_get_reg(struct eth_device *dev, int bank, int ioaddr, int reg) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 890 | { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 891 | SMC_SELECT_BANK( dev, bank ); |
| 892 | return(SMC_inw( dev, reg )); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | #endif /* 0 */ |
| 896 | |
| 897 | /*---PHY CONTROL AND CONFIGURATION----------------------------------------- */ |
| 898 | |
| 899 | #if (SMC_DEBUG > 2 ) |
| 900 | |
| 901 | /*------------------------------------------------------------ |
| 902 | . Debugging function for viewing MII Management serial bitstream |
| 903 | .-------------------------------------------------------------*/ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 904 | static void smc_dump_mii_stream (byte * bits, int size) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 905 | { |
| 906 | int i; |
| 907 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 908 | printf ("BIT#:"); |
| 909 | for (i = 0; i < size; ++i) { |
| 910 | printf ("%d", i % 10); |
| 911 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 912 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 913 | printf ("\nMDOE:"); |
| 914 | for (i = 0; i < size; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 915 | if (bits[i] & MII_MDOE) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 916 | printf ("1"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 917 | else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 918 | printf ("0"); |
| 919 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 920 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 921 | printf ("\nMDO :"); |
| 922 | for (i = 0; i < size; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 923 | if (bits[i] & MII_MDO) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 924 | printf ("1"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 925 | else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 926 | printf ("0"); |
| 927 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 928 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 929 | printf ("\nMDI :"); |
| 930 | for (i = 0; i < size; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 931 | if (bits[i] & MII_MDI) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 932 | printf ("1"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 933 | else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 934 | printf ("0"); |
| 935 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 936 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 937 | printf ("\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 938 | } |
| 939 | #endif |
| 940 | |
| 941 | /*------------------------------------------------------------ |
| 942 | . Reads a register from the MII Management serial interface |
| 943 | .-------------------------------------------------------------*/ |
| 944 | #ifndef CONFIG_SMC91111_EXT_PHY |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 945 | static word smc_read_phy_register (struct eth_device *dev, byte phyreg) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 946 | { |
| 947 | int oldBank; |
| 948 | int i; |
| 949 | byte mask; |
| 950 | word mii_reg; |
| 951 | byte bits[64]; |
| 952 | int clk_idx = 0; |
| 953 | int input_idx; |
| 954 | word phydata; |
| 955 | byte phyaddr = SMC_PHY_ADDR; |
| 956 | |
| 957 | /* 32 consecutive ones on MDO to establish sync */ |
| 958 | for (i = 0; i < 32; ++i) |
| 959 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 960 | |
| 961 | /* Start code <01> */ |
| 962 | bits[clk_idx++] = MII_MDOE; |
| 963 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 964 | |
| 965 | /* Read command <10> */ |
| 966 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 967 | bits[clk_idx++] = MII_MDOE; |
| 968 | |
| 969 | /* Output the PHY address, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 970 | mask = (byte) 0x10; |
| 971 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 972 | if (phyaddr & mask) |
| 973 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 974 | else |
| 975 | bits[clk_idx++] = MII_MDOE; |
| 976 | |
| 977 | /* Shift to next lowest bit */ |
| 978 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 979 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 980 | |
| 981 | /* Output the phy register number, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 982 | mask = (byte) 0x10; |
| 983 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 984 | if (phyreg & mask) |
| 985 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 986 | else |
| 987 | bits[clk_idx++] = MII_MDOE; |
| 988 | |
| 989 | /* Shift to next lowest bit */ |
| 990 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 991 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 992 | |
| 993 | /* Tristate and turnaround (2 bit times) */ |
| 994 | bits[clk_idx++] = 0; |
| 995 | /*bits[clk_idx++] = 0; */ |
| 996 | |
| 997 | /* Input starts at this bit time */ |
| 998 | input_idx = clk_idx; |
| 999 | |
| 1000 | /* Will input 16 bits */ |
| 1001 | for (i = 0; i < 16; ++i) |
| 1002 | bits[clk_idx++] = 0; |
| 1003 | |
| 1004 | /* Final clock bit */ |
| 1005 | bits[clk_idx++] = 0; |
| 1006 | |
| 1007 | /* Save the current bank */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1008 | oldBank = SMC_inw (dev, BANK_SELECT); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1009 | |
| 1010 | /* Select bank 3 */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1011 | SMC_SELECT_BANK (dev, 3); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1012 | |
| 1013 | /* Get the current MII register value */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1014 | mii_reg = SMC_inw (dev, MII_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1015 | |
| 1016 | /* Turn off all MII Interface bits */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1017 | mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1018 | |
| 1019 | /* Clock all 64 cycles */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1020 | for (i = 0; i < sizeof bits; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1021 | /* Clock Low - output data */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1022 | SMC_outw (dev, mii_reg | bits[i], MII_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1023 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1024 | |
| 1025 | |
| 1026 | /* Clock Hi - input data */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1027 | SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1028 | udelay (SMC_PHY_CLOCK_DELAY); |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1029 | bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1030 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1031 | |
| 1032 | /* Return to idle state */ |
| 1033 | /* Set clock to low, data to low, and output tristated */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1034 | SMC_outw (dev, mii_reg, MII_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1035 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1036 | |
| 1037 | /* Restore original bank select */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1038 | SMC_SELECT_BANK (dev, oldBank); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1039 | |
| 1040 | /* Recover input data */ |
| 1041 | phydata = 0; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1042 | for (i = 0; i < 16; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1043 | phydata <<= 1; |
| 1044 | |
| 1045 | if (bits[input_idx++] & MII_MDI) |
| 1046 | phydata |= 0x0001; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1047 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1048 | |
| 1049 | #if (SMC_DEBUG > 2 ) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1050 | printf ("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n", |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1051 | phyaddr, phyreg, phydata); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1052 | smc_dump_mii_stream (bits, sizeof bits); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1053 | #endif |
| 1054 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1055 | return (phydata); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | /*------------------------------------------------------------ |
| 1060 | . Writes a register to the MII Management serial interface |
| 1061 | .-------------------------------------------------------------*/ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1062 | static void smc_write_phy_register (struct eth_device *dev, byte phyreg, |
| 1063 | word phydata) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1064 | { |
| 1065 | int oldBank; |
| 1066 | int i; |
| 1067 | word mask; |
| 1068 | word mii_reg; |
| 1069 | byte bits[65]; |
| 1070 | int clk_idx = 0; |
| 1071 | byte phyaddr = SMC_PHY_ADDR; |
| 1072 | |
| 1073 | /* 32 consecutive ones on MDO to establish sync */ |
| 1074 | for (i = 0; i < 32; ++i) |
| 1075 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1076 | |
| 1077 | /* Start code <01> */ |
| 1078 | bits[clk_idx++] = MII_MDOE; |
| 1079 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1080 | |
| 1081 | /* Write command <01> */ |
| 1082 | bits[clk_idx++] = MII_MDOE; |
| 1083 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1084 | |
| 1085 | /* Output the PHY address, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1086 | mask = (byte) 0x10; |
| 1087 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1088 | if (phyaddr & mask) |
| 1089 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1090 | else |
| 1091 | bits[clk_idx++] = MII_MDOE; |
| 1092 | |
| 1093 | /* Shift to next lowest bit */ |
| 1094 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1095 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1096 | |
| 1097 | /* Output the phy register number, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1098 | mask = (byte) 0x10; |
| 1099 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1100 | if (phyreg & mask) |
| 1101 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1102 | else |
| 1103 | bits[clk_idx++] = MII_MDOE; |
| 1104 | |
| 1105 | /* Shift to next lowest bit */ |
| 1106 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1107 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1108 | |
| 1109 | /* Tristate and turnaround (2 bit times) */ |
| 1110 | bits[clk_idx++] = 0; |
| 1111 | bits[clk_idx++] = 0; |
| 1112 | |
| 1113 | /* Write out 16 bits of data, msb first */ |
| 1114 | mask = 0x8000; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1115 | for (i = 0; i < 16; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1116 | if (phydata & mask) |
| 1117 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1118 | else |
| 1119 | bits[clk_idx++] = MII_MDOE; |
| 1120 | |
| 1121 | /* Shift to next lowest bit */ |
| 1122 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1123 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1124 | |
| 1125 | /* Final clock bit (tristate) */ |
| 1126 | bits[clk_idx++] = 0; |
| 1127 | |
| 1128 | /* Save the current bank */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1129 | oldBank = SMC_inw (dev, BANK_SELECT); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1130 | |
| 1131 | /* Select bank 3 */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1132 | SMC_SELECT_BANK (dev, 3); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1133 | |
| 1134 | /* Get the current MII register value */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1135 | mii_reg = SMC_inw (dev, MII_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1136 | |
| 1137 | /* Turn off all MII Interface bits */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1138 | mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1139 | |
| 1140 | /* Clock all cycles */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1141 | for (i = 0; i < sizeof bits; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1142 | /* Clock Low - output data */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1143 | SMC_outw (dev, mii_reg | bits[i], MII_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1144 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1145 | |
| 1146 | |
| 1147 | /* Clock Hi - input data */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1148 | SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1149 | udelay (SMC_PHY_CLOCK_DELAY); |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1150 | bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1151 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1152 | |
| 1153 | /* Return to idle state */ |
| 1154 | /* Set clock to low, data to low, and output tristated */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1155 | SMC_outw (dev, mii_reg, MII_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1156 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1157 | |
| 1158 | /* Restore original bank select */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1159 | SMC_SELECT_BANK (dev, oldBank); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1160 | |
| 1161 | #if (SMC_DEBUG > 2 ) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1162 | printf ("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n", |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1163 | phyaddr, phyreg, phydata); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1164 | smc_dump_mii_stream (bits, sizeof bits); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1165 | #endif |
| 1166 | } |
| 1167 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 1168 | |
| 1169 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1170 | /*------------------------------------------------------------ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1171 | . Configures the specified PHY using Autonegotiation. Calls |
| 1172 | . smc_phy_fixed() if the user has requested a certain config. |
| 1173 | .-------------------------------------------------------------*/ |
| 1174 | #ifndef CONFIG_SMC91111_EXT_PHY |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1175 | static void smc_phy_configure (struct eth_device *dev) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1176 | { |
| 1177 | int timeout; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1178 | word my_phy_caps; /* My PHY capabilities */ |
| 1179 | word my_ad_caps; /* My Advertised capabilities */ |
| 1180 | word status = 0; /*;my status = 0 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1181 | |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1182 | PRINTK3 ("%s: smc_program_phy()\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1183 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1184 | /* Reset the PHY, setting all other bits to zero */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1185 | smc_write_phy_register (dev, PHY_CNTL_REG, PHY_CNTL_RST); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1186 | |
| 1187 | /* Wait for the reset to complete, or time out */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1188 | timeout = 6; /* Wait up to 3 seconds */ |
| 1189 | while (timeout--) { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1190 | if (!(smc_read_phy_register (dev, PHY_CNTL_REG) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1191 | & PHY_CNTL_RST)) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1192 | /* reset complete */ |
| 1193 | break; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Mike Frysinger | 03130cb | 2012-03-05 13:46:51 +0000 | [diff] [blame] | 1196 | mdelay(500); /* wait 500 millisecs */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | if (timeout < 1) { |
| 1200 | printf ("%s:PHY reset timed out\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1201 | goto smc_phy_configure_exit; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1202 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1203 | |
| 1204 | /* Read PHY Register 18, Status Output */ |
| 1205 | /* lp->lastPhy18 = smc_read_phy_register(PHY_INT_REG); */ |
| 1206 | |
| 1207 | /* Enable PHY Interrupts (for register 18) */ |
| 1208 | /* Interrupts listed here are disabled */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1209 | smc_write_phy_register (dev, PHY_MASK_REG, 0xffff); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1210 | |
| 1211 | /* Configure the Receive/Phy Control register */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1212 | SMC_SELECT_BANK (dev, 0); |
| 1213 | SMC_outw (dev, RPC_DEFAULT, RPC_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1214 | |
| 1215 | /* Copy our capabilities from PHY_STAT_REG to PHY_AD_REG */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1216 | my_phy_caps = smc_read_phy_register (dev, PHY_STAT_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1217 | my_ad_caps = PHY_AD_CSMA; /* I am CSMA capable */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1218 | |
| 1219 | if (my_phy_caps & PHY_STAT_CAP_T4) |
| 1220 | my_ad_caps |= PHY_AD_T4; |
| 1221 | |
| 1222 | if (my_phy_caps & PHY_STAT_CAP_TXF) |
| 1223 | my_ad_caps |= PHY_AD_TX_FDX; |
| 1224 | |
| 1225 | if (my_phy_caps & PHY_STAT_CAP_TXH) |
| 1226 | my_ad_caps |= PHY_AD_TX_HDX; |
| 1227 | |
| 1228 | if (my_phy_caps & PHY_STAT_CAP_TF) |
| 1229 | my_ad_caps |= PHY_AD_10_FDX; |
| 1230 | |
| 1231 | if (my_phy_caps & PHY_STAT_CAP_TH) |
| 1232 | my_ad_caps |= PHY_AD_10_HDX; |
| 1233 | |
| 1234 | /* Update our Auto-Neg Advertisement Register */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1235 | smc_write_phy_register (dev, PHY_AD_REG, my_ad_caps); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1236 | |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 1237 | /* Read the register back. Without this, it appears that when */ |
| 1238 | /* auto-negotiation is restarted, sometimes it isn't ready and */ |
| 1239 | /* the link does not come up. */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1240 | smc_read_phy_register(dev, PHY_AD_REG); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 1241 | |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1242 | PRINTK2 ("%s: phy caps=%x\n", SMC_DEV_NAME, my_phy_caps); |
| 1243 | PRINTK2 ("%s: phy advertised caps=%x\n", SMC_DEV_NAME, my_ad_caps); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1244 | |
| 1245 | /* Restart auto-negotiation process in order to advertise my caps */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1246 | smc_write_phy_register (dev, PHY_CNTL_REG, |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1247 | PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1248 | |
| 1249 | /* Wait for the auto-negotiation to complete. This may take from */ |
| 1250 | /* 2 to 3 seconds. */ |
| 1251 | /* Wait for the reset to complete, or time out */ |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1252 | timeout = CONFIG_SMC_AUTONEG_TIMEOUT * 2; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1253 | while (timeout--) { |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1254 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1255 | status = smc_read_phy_register (dev, PHY_STAT_REG); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1256 | if (status & PHY_STAT_ANEG_ACK) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1257 | /* auto-negotiate complete */ |
| 1258 | break; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1259 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1260 | |
Mike Frysinger | 03130cb | 2012-03-05 13:46:51 +0000 | [diff] [blame] | 1261 | mdelay(500); /* wait 500 millisecs */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1262 | |
| 1263 | /* Restart auto-negotiation if remote fault */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1264 | if (status & PHY_STAT_REM_FLT) { |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1265 | printf ("%s: PHY remote fault detected\n", |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1266 | SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1267 | |
| 1268 | /* Restart auto-negotiation */ |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1269 | printf ("%s: PHY restarting auto-negotiation\n", |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1270 | SMC_DEV_NAME); |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1271 | smc_write_phy_register (dev, PHY_CNTL_REG, |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1272 | PHY_CNTL_ANEG_EN | |
| 1273 | PHY_CNTL_ANEG_RST | |
| 1274 | PHY_CNTL_SPEED | |
| 1275 | PHY_CNTL_DPLX); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1276 | } |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1277 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1278 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1279 | if (timeout < 1) { |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1280 | printf ("%s: PHY auto-negotiate timed out\n", SMC_DEV_NAME); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1281 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1282 | |
| 1283 | /* Fail if we detected an auto-negotiate remote fault */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1284 | if (status & PHY_STAT_REM_FLT) { |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1285 | printf ("%s: PHY remote fault detected\n", SMC_DEV_NAME); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame] | 1286 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1287 | |
| 1288 | /* Re-Configure the Receive/Phy Control register */ |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1289 | SMC_outw (dev, RPC_DEFAULT, RPC_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1290 | |
wdenk | ec5dc0d | 2004-07-09 22:51:01 +0000 | [diff] [blame] | 1291 | smc_phy_configure_exit: ; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1292 | |
| 1293 | } |
| 1294 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 1295 | |
| 1296 | |
| 1297 | #if SMC_DEBUG > 2 |
| 1298 | static void print_packet( byte * buf, int length ) |
| 1299 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1300 | int i; |
| 1301 | int remainder; |
| 1302 | int lines; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1303 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1304 | printf("Packet of length %d \n", length ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1305 | |
| 1306 | #if SMC_DEBUG > 3 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1307 | lines = length / 16; |
| 1308 | remainder = length % 16; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1309 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1310 | for ( i = 0; i < lines ; i ++ ) { |
| 1311 | int cur; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1312 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1313 | for ( cur = 0; cur < 8; cur ++ ) { |
| 1314 | byte a, b; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1315 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1316 | a = *(buf ++ ); |
| 1317 | b = *(buf ++ ); |
| 1318 | printf("%02x%02x ", a, b ); |
| 1319 | } |
| 1320 | printf("\n"); |
| 1321 | } |
| 1322 | for ( i = 0; i < remainder/2 ; i++ ) { |
| 1323 | byte a, b; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1324 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1325 | a = *(buf ++ ); |
| 1326 | b = *(buf ++ ); |
| 1327 | printf("%02x%02x ", a, b ); |
| 1328 | } |
| 1329 | printf("\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1330 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1331 | } |
| 1332 | #endif |
| 1333 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1334 | int smc91111_initialize(u8 dev_num, int base_addr) |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1335 | { |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1336 | struct smc91111_priv *priv; |
| 1337 | struct eth_device *dev; |
| 1338 | int i; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1339 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1340 | priv = malloc(sizeof(*priv)); |
| 1341 | if (!priv) |
| 1342 | return 0; |
| 1343 | dev = malloc(sizeof(*dev)); |
| 1344 | if (!dev) { |
| 1345 | free(priv); |
| 1346 | return 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1347 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1348 | |
Thomas Chou | c25126d | 2010-10-06 09:16:10 +0800 | [diff] [blame] | 1349 | memset(dev, 0, sizeof(*dev)); |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1350 | priv->dev_num = dev_num; |
| 1351 | dev->priv = priv; |
| 1352 | dev->iobase = base_addr; |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1353 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1354 | swap_to(ETHERNET); |
| 1355 | SMC_SELECT_BANK(dev, 1); |
| 1356 | for (i = 0; i < 6; ++i) |
| 1357 | dev->enetaddr[i] = SMC_inb(dev, (ADDR0_REG + i)); |
| 1358 | swap_to(FLASH); |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1359 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1360 | dev->init = smc_init; |
| 1361 | dev->halt = smc_halt; |
| 1362 | dev->send = smc_send; |
| 1363 | dev->recv = smc_rcv; |
Thomas Chou | c25126d | 2010-10-06 09:16:10 +0800 | [diff] [blame] | 1364 | dev->write_hwaddr = smc_write_hwaddr; |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1365 | sprintf(dev->name, "%s-%hu", SMC_DEV_NAME, dev_num); |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 1366 | |
Ben Warren | 0fd6aae | 2009-10-04 22:37:03 -0700 | [diff] [blame] | 1367 | eth_register(dev); |
| 1368 | return 0; |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1369 | } |