Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Cirrus Logic CS8900A Ethernet |
| 4 | * |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 5 | * (C) 2009 Ben Warren , biggerbadderben@gmail.com |
| 6 | * Converted to use CONFIG_NET_MULTI API |
| 7 | * |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 8 | * (C) 2003 Wolfgang Denk, wd@denx.de |
| 9 | * Extension to synchronize ethaddr environment variable |
| 10 | * against value in EEPROM |
| 11 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 12 | * (C) Copyright 2002 |
| 13 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 14 | * Marius Groeger <mgroeger@sysgo.de> |
| 15 | * |
| 16 | * Copyright (C) 1999 Ben Williamson <benw@pobox.com> |
| 17 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 18 | * This program is loaded into SRAM in bootstrap mode, where it waits |
| 19 | * for commands on UART1 to read and write memory, jump to code etc. |
| 20 | * A design goal for this program is to be entirely independent of the |
| 21 | * target board. Anything with a CL-PS7111 or EP7211 should be able to run |
| 22 | * this code in bootstrap mode. All the board specifics can be handled on |
| 23 | * the host. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <command.h> |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 28 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | #include <net.h> |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 30 | #include <malloc.h> |
| 31 | #include "cs8900.h" |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 32 | |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 33 | #undef DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 34 | |
| 35 | /* packet page register access functions */ |
| 36 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_CS8900_BUS32 |
| 38 | |
| 39 | #define REG_WRITE(v, a) writel((v),(a)) |
| 40 | #define REG_READ(a) readl((a)) |
| 41 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 42 | /* we don't need 16 bit initialisation on 32 bit bus */ |
Ben Warren | 830c7b6 | 2009-11-09 11:43:18 -0800 | [diff] [blame] | 43 | #define get_reg_init_bus(r,d) get_reg((r),(d)) |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 44 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 45 | #else |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 46 | |
| 47 | #define REG_WRITE(v, a) writew((v),(a)) |
| 48 | #define REG_READ(a) readw((a)) |
| 49 | |
| 50 | static u16 get_reg_init_bus(struct eth_device *dev, int regno) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 51 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 52 | /* force 16 bit busmode */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 53 | struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv); |
| 54 | uint8_t volatile * const iob = (uint8_t volatile * const)dev->iobase; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 55 | |
Anatolij Gustschin | da22735 | 2011-11-19 13:12:14 +0000 | [diff] [blame] | 56 | readb(iob); |
| 57 | readb(iob + 1); |
| 58 | readb(iob); |
| 59 | readb(iob + 1); |
| 60 | readb(iob); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 61 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 62 | REG_WRITE(regno, &priv->regs->pptr); |
| 63 | return REG_READ(&priv->regs->pdata); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 64 | } |
| 65 | #endif |
| 66 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 67 | static u16 get_reg(struct eth_device *dev, int regno) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 68 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 69 | struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv); |
| 70 | REG_WRITE(regno, &priv->regs->pptr); |
| 71 | return REG_READ(&priv->regs->pdata); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 75 | static void put_reg(struct eth_device *dev, int regno, u16 val) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 76 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 77 | struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv); |
| 78 | REG_WRITE(regno, &priv->regs->pptr); |
| 79 | REG_WRITE(val, &priv->regs->pdata); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 82 | static void cs8900_reset(struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 83 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 84 | int tmo; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 85 | u16 us; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 86 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 87 | /* reset NIC */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 88 | put_reg(dev, PP_SelfCTL, get_reg(dev, PP_SelfCTL) | PP_SelfCTL_Reset); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 89 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 90 | /* wait for 200ms */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 91 | udelay(200000); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 92 | /* Wait until the chip is reset */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 93 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 94 | tmo = get_timer(0) + 1 * CONFIG_SYS_HZ; |
| 95 | while ((((us = get_reg_init_bus(dev, PP_SelfSTAT)) & |
| 96 | PP_SelfSTAT_InitD) == 0) && tmo < get_timer(0)) |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 97 | /*NOP*/; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 100 | static void cs8900_reginit(struct eth_device *dev) |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 101 | { |
| 102 | /* receive only error free packets addressed to this card */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 103 | put_reg(dev, PP_RxCTL, |
| 104 | PP_RxCTL_IA | PP_RxCTL_Broadcast | PP_RxCTL_RxOK); |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 105 | /* do not generate any interrupts on receive operations */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 106 | put_reg(dev, PP_RxCFG, 0); |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 107 | /* do not generate any interrupts on transmit operations */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 108 | put_reg(dev, PP_TxCFG, 0); |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 109 | /* do not generate any interrupts on buffer operations */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 110 | put_reg(dev, PP_BufCFG, 0); |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 111 | /* enable transmitter/receiver mode */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 112 | put_reg(dev, PP_LineCTL, PP_LineCTL_Rx | PP_LineCTL_Tx); |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 115 | void cs8900_get_enetaddr(struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 117 | int i; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 118 | |
| 119 | /* verify chip id */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 120 | if (get_reg_init_bus(dev, PP_ChipID) != 0x630e) |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 121 | return; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 122 | cs8900_reset(dev); |
| 123 | if ((get_reg(dev, PP_SelfSTAT) & |
| 124 | (PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) == |
| 125 | (PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 126 | |
| 127 | /* Load the MAC from EEPROM */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 128 | for (i = 0; i < 3; i++) { |
| 129 | u32 Addr; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 130 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 131 | Addr = get_reg(dev, PP_IA + i * 2); |
| 132 | dev->enetaddr[i * 2] = Addr & 0xFF; |
| 133 | dev->enetaddr[i * 2 + 1] = Addr >> 8; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 134 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 135 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 138 | void cs8900_halt(struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 139 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 140 | /* disable transmitter/receiver mode */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 141 | put_reg(dev, PP_LineCTL, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 142 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 143 | /* "shutdown" to show ChipID or kernel wouldn't find he cs8900 ... */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 144 | get_reg_init_bus(dev, PP_ChipID); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 147 | static int cs8900_init(struct eth_device *dev, bd_t * bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 148 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 149 | uchar *enetaddr = dev->enetaddr; |
| 150 | u16 id; |
Mike Frysinger | 0a5238c | 2009-02-11 19:06:09 -0500 | [diff] [blame] | 151 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 152 | /* verify chip id */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 153 | id = get_reg_init_bus(dev, PP_ChipID); |
| 154 | if (id != 0x630e) { |
| 155 | printf ("CS8900 Ethernet chip not found: " |
| 156 | "ID=0x%04x instead 0x%04x\n", id, 0x630e); |
| 157 | return 1; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 160 | cs8900_reset (dev); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 161 | /* set the ethernet address */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 162 | put_reg(dev, PP_IA + 0, enetaddr[0] | (enetaddr[1] << 8)); |
| 163 | put_reg(dev, PP_IA + 2, enetaddr[2] | (enetaddr[3] << 8)); |
| 164 | put_reg(dev, PP_IA + 4, enetaddr[4] | (enetaddr[5] << 8)); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 165 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 166 | cs8900_reginit(dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 167 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* Get a data block via Ethernet */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 171 | static int cs8900_recv(struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 172 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 173 | int i; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 174 | u16 rxlen; |
| 175 | u16 *addr; |
| 176 | u16 status; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 177 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 178 | struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv); |
| 179 | |
| 180 | status = get_reg(dev, PP_RER); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 181 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 182 | if ((status & PP_RER_RxOK) == 0) |
| 183 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 184 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 185 | status = REG_READ(&priv->regs->rtdata); |
| 186 | rxlen = REG_READ(&priv->regs->rtdata); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 187 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 188 | if (rxlen > PKTSIZE_ALIGN + PKTALIGN) |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 189 | debug("packet too big!\n"); |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 190 | for (addr = (u16 *)net_rx_packets[0], i = rxlen >> 1; i > 0; i--) |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 191 | *addr++ = REG_READ(&priv->regs->rtdata); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 192 | if (rxlen & 1) |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 193 | *addr++ = REG_READ(&priv->regs->rtdata); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 194 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 195 | /* Pass the packet up to the protocol layers. */ |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 196 | net_process_received_packet(net_rx_packets[0], rxlen); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 197 | return rxlen; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* Send a data block via Ethernet. */ |
Joe Hershberger | 9d29517 | 2012-05-21 14:45:21 +0000 | [diff] [blame] | 201 | static int cs8900_send(struct eth_device *dev, void *packet, int length) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 202 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 203 | volatile u16 *addr; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 204 | int tmo; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 205 | u16 s; |
| 206 | struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 207 | |
| 208 | retry: |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 209 | /* initiate a transmit sequence */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 210 | REG_WRITE(PP_TxCmd_TxStart_Full, &priv->regs->txcmd); |
| 211 | REG_WRITE(length, &priv->regs->txlen); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 212 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 213 | /* Test to see if the chip has allocated memory for the packet */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 214 | if ((get_reg(dev, PP_BusSTAT) & PP_BusSTAT_TxRDY) == 0) { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 215 | /* Oops... this should not happen! */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 216 | debug("cs: unable to send packet; retrying...\n"); |
| 217 | for (tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; |
| 218 | get_timer(0) < tmo;) |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 219 | /*NOP*/; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 220 | cs8900_reset(dev); |
| 221 | cs8900_reginit(dev); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 222 | goto retry; |
| 223 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 224 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 225 | /* Write the contents of the packet */ |
| 226 | /* assume even number of bytes */ |
| 227 | for (addr = packet; length > 0; length -= 2) |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 228 | REG_WRITE(*addr++, &priv->regs->rtdata); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 229 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 230 | /* wait for transfer to succeed */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 231 | tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; |
| 232 | while ((s = get_reg(dev, PP_TER) & ~0x1F) == 0) { |
| 233 | if (get_timer(0) >= tmo) |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 234 | break; |
| 235 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 236 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 237 | /* nothing */ ; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 238 | if((s & (PP_TER_CRS | PP_TER_TxOK)) != PP_TER_TxOK) { |
| 239 | debug("\ntransmission error %#x\n", s); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 240 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 241 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 242 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 245 | static void cs8900_e2prom_ready(struct eth_device *dev) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 246 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 247 | while (get_reg(dev, PP_SelfSTAT) & SI_BUSY) |
Guennadi Liakhovetski | 13e0b8f | 2008-04-03 13:36:18 +0200 | [diff] [blame] | 248 | ; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /***********************************************************/ |
| 252 | /* read a 16-bit word out of the EEPROM */ |
| 253 | /***********************************************************/ |
| 254 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 255 | int cs8900_e2prom_read(struct eth_device *dev, |
| 256 | u8 addr, u16 *value) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 257 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 258 | cs8900_e2prom_ready(dev); |
| 259 | put_reg(dev, PP_EECMD, EEPROM_READ_CMD | addr); |
| 260 | cs8900_e2prom_ready(dev); |
| 261 | *value = get_reg(dev, PP_EEData); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | |
| 267 | /***********************************************************/ |
| 268 | /* write a 16-bit word into the EEPROM */ |
| 269 | /***********************************************************/ |
| 270 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 271 | int cs8900_e2prom_write(struct eth_device *dev, u8 addr, u16 value) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 272 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 273 | cs8900_e2prom_ready(dev); |
| 274 | put_reg(dev, PP_EECMD, EEPROM_WRITE_EN); |
| 275 | cs8900_e2prom_ready(dev); |
| 276 | put_reg(dev, PP_EEData, value); |
| 277 | put_reg(dev, PP_EECMD, EEPROM_WRITE_CMD | addr); |
| 278 | cs8900_e2prom_ready(dev); |
| 279 | put_reg(dev, PP_EECMD, EEPROM_WRITE_DIS); |
| 280 | cs8900_e2prom_ready(dev); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 281 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 282 | return 0; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 283 | } |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 284 | |
| 285 | int cs8900_initialize(u8 dev_num, int base_addr) |
| 286 | { |
| 287 | struct eth_device *dev; |
| 288 | struct cs8900_priv *priv; |
| 289 | |
| 290 | dev = malloc(sizeof(*dev)); |
| 291 | if (!dev) { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | memset(dev, 0, sizeof(*dev)); |
| 295 | |
| 296 | priv = malloc(sizeof(*priv)); |
| 297 | if (!priv) { |
Matthias Kaehlcke | 07c9660 | 2010-01-21 22:16:34 +0100 | [diff] [blame] | 298 | free(dev); |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | memset(priv, 0, sizeof(*priv)); |
| 302 | priv->regs = (struct cs8900_regs *)base_addr; |
| 303 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 304 | dev->iobase = base_addr; |
| 305 | dev->priv = priv; |
| 306 | dev->init = cs8900_init; |
| 307 | dev->halt = cs8900_halt; |
| 308 | dev->send = cs8900_send; |
| 309 | dev->recv = cs8900_recv; |
Hui.Tang | 497ab0e | 2009-11-05 09:58:44 +0800 | [diff] [blame] | 310 | |
| 311 | /* Load MAC address from EEPROM */ |
| 312 | cs8900_get_enetaddr(dev); |
| 313 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 314 | sprintf(dev->name, "%s-%hu", CS8900_DRIVERNAME, dev_num); |
| 315 | |
| 316 | eth_register(dev); |
| 317 | return 0; |
| 318 | } |