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