2002-11-03 00:24:07 +00:00
|
|
|
/*
|
|
|
|
* Cirrus Logic CS8900A Ethernet
|
|
|
|
*
|
2009-08-25 20:09:37 +00:00
|
|
|
* (C) 2009 Ben Warren , biggerbadderben@gmail.com
|
|
|
|
* Converted to use CONFIG_NET_MULTI API
|
|
|
|
*
|
2003-02-28 00:49:47 +00:00
|
|
|
* (C) 2003 Wolfgang Denk, wd@denx.de
|
|
|
|
* Extension to synchronize ethaddr environment variable
|
|
|
|
* against value in EEPROM
|
|
|
|
*
|
2002-11-03 00:24:07 +00:00
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Ben Williamson <benw@pobox.com>
|
|
|
|
*
|
|
|
|
* This program is loaded into SRAM in bootstrap mode, where it waits
|
|
|
|
* for commands on UART1 to read and write memory, jump to code etc.
|
|
|
|
* A design goal for this program is to be entirely independent of the
|
|
|
|
* target board. Anything with a CL-PS7111 or EP7211 should be able to run
|
|
|
|
* this code in bootstrap mode. All the board specifics can be handled on
|
|
|
|
* the host.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-11-03 00:24:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2009-08-25 20:09:37 +00:00
|
|
|
#include <asm/io.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <net.h>
|
2009-08-25 20:09:37 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include "cs8900.h"
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-12-07 18:32:37 +00:00
|
|
|
#undef DEBUG
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
/* packet page register access functions */
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
#ifdef CONFIG_CS8900_BUS32
|
|
|
|
|
|
|
|
#define REG_WRITE(v, a) writel((v),(a))
|
|
|
|
#define REG_READ(a) readl((a))
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
/* we don't need 16 bit initialisation on 32 bit bus */
|
2009-11-09 19:43:18 +00:00
|
|
|
#define get_reg_init_bus(r,d) get_reg((r),(d))
|
2009-08-25 20:09:37 +00:00
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
#else
|
2003-02-28 00:49:47 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
#define REG_WRITE(v, a) writew((v),(a))
|
|
|
|
#define REG_READ(a) readw((a))
|
2003-02-28 00:49:47 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
static u16 get_reg_init_bus(struct eth_device *dev, int regno)
|
|
|
|
{
|
|
|
|
/* force 16 bit busmode */
|
|
|
|
struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv);
|
|
|
|
uint8_t volatile * const iob = (uint8_t volatile * const)dev->iobase;
|
|
|
|
|
2011-11-19 13:12:14 +00:00
|
|
|
readb(iob);
|
|
|
|
readb(iob + 1);
|
|
|
|
readb(iob);
|
|
|
|
readb(iob + 1);
|
|
|
|
readb(iob);
|
2009-08-25 20:09:37 +00:00
|
|
|
|
|
|
|
REG_WRITE(regno, &priv->regs->pptr);
|
|
|
|
return REG_READ(&priv->regs->pdata);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
static u16 get_reg(struct eth_device *dev, int regno)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2009-08-25 20:09:37 +00:00
|
|
|
struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv);
|
|
|
|
REG_WRITE(regno, &priv->regs->pptr);
|
|
|
|
return REG_READ(&priv->regs->pdata);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
static void put_reg(struct eth_device *dev, int regno, u16 val)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2009-08-25 20:09:37 +00:00
|
|
|
struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv);
|
|
|
|
REG_WRITE(regno, &priv->regs->pptr);
|
|
|
|
REG_WRITE(val, &priv->regs->pdata);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
static void cs8900_reset(struct eth_device *dev)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2003-02-28 00:49:47 +00:00
|
|
|
int tmo;
|
2009-08-25 20:09:37 +00:00
|
|
|
u16 us;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
/* reset NIC */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_SelfCTL, get_reg(dev, PP_SelfCTL) | PP_SelfCTL_Reset);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
/* wait for 200ms */
|
2009-08-25 20:09:37 +00:00
|
|
|
udelay(200000);
|
2003-02-28 00:49:47 +00:00
|
|
|
/* Wait until the chip is reset */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
tmo = get_timer(0) + 1 * CONFIG_SYS_HZ;
|
|
|
|
while ((((us = get_reg_init_bus(dev, PP_SelfSTAT)) &
|
|
|
|
PP_SelfSTAT_InitD) == 0) && tmo < get_timer(0))
|
2003-02-28 00:49:47 +00:00
|
|
|
/*NOP*/;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
static void cs8900_reginit(struct eth_device *dev)
|
2003-12-07 18:32:37 +00:00
|
|
|
{
|
|
|
|
/* receive only error free packets addressed to this card */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_RxCTL,
|
|
|
|
PP_RxCTL_IA | PP_RxCTL_Broadcast | PP_RxCTL_RxOK);
|
2003-12-07 18:32:37 +00:00
|
|
|
/* do not generate any interrupts on receive operations */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_RxCFG, 0);
|
2003-12-07 18:32:37 +00:00
|
|
|
/* do not generate any interrupts on transmit operations */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_TxCFG, 0);
|
2003-12-07 18:32:37 +00:00
|
|
|
/* do not generate any interrupts on buffer operations */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_BufCFG, 0);
|
2003-12-07 18:32:37 +00:00
|
|
|
/* enable transmitter/receiver mode */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_LineCTL, PP_LineCTL_Rx | PP_LineCTL_Tx);
|
2003-12-07 18:32:37 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
void cs8900_get_enetaddr(struct eth_device *dev)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2003-02-28 00:49:47 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* verify chip id */
|
2009-08-25 20:09:37 +00:00
|
|
|
if (get_reg_init_bus(dev, PP_ChipID) != 0x630e)
|
2003-02-28 00:49:47 +00:00
|
|
|
return;
|
2009-08-25 20:09:37 +00:00
|
|
|
cs8900_reset(dev);
|
|
|
|
if ((get_reg(dev, PP_SelfSTAT) &
|
|
|
|
(PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) ==
|
|
|
|
(PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) {
|
2003-02-28 00:49:47 +00:00
|
|
|
|
|
|
|
/* Load the MAC from EEPROM */
|
2009-08-25 20:09:37 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
u32 Addr;
|
2003-02-28 00:49:47 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
Addr = get_reg(dev, PP_IA + i * 2);
|
|
|
|
dev->enetaddr[i * 2] = Addr & 0xFF;
|
|
|
|
dev->enetaddr[i * 2 + 1] = Addr >> 8;
|
2003-02-28 00:49:47 +00:00
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
void cs8900_halt(struct eth_device *dev)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2003-02-28 00:49:47 +00:00
|
|
|
/* disable transmitter/receiver mode */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_LineCTL, 0);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
/* "shutdown" to show ChipID or kernel wouldn't find he cs8900 ... */
|
2009-08-25 20:09:37 +00:00
|
|
|
get_reg_init_bus(dev, PP_ChipID);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
static int cs8900_init(struct eth_device *dev, bd_t * bd)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2009-08-25 20:09:37 +00:00
|
|
|
uchar *enetaddr = dev->enetaddr;
|
|
|
|
u16 id;
|
2009-02-12 00:06:09 +00:00
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
/* verify chip id */
|
2009-08-25 20:09:37 +00:00
|
|
|
id = get_reg_init_bus(dev, PP_ChipID);
|
|
|
|
if (id != 0x630e) {
|
|
|
|
printf ("CS8900 Ethernet chip not found: "
|
|
|
|
"ID=0x%04x instead 0x%04x\n", id, 0x630e);
|
|
|
|
return 1;
|
2003-02-28 00:49:47 +00:00
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
cs8900_reset (dev);
|
2003-02-28 00:49:47 +00:00
|
|
|
/* set the ethernet address */
|
2009-08-25 20:09:37 +00:00
|
|
|
put_reg(dev, PP_IA + 0, enetaddr[0] | (enetaddr[1] << 8));
|
|
|
|
put_reg(dev, PP_IA + 2, enetaddr[2] | (enetaddr[3] << 8));
|
|
|
|
put_reg(dev, PP_IA + 4, enetaddr[4] | (enetaddr[5] << 8));
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
cs8900_reginit(dev);
|
2003-02-28 00:49:47 +00:00
|
|
|
return 0;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a data block via Ethernet */
|
2009-08-25 20:09:37 +00:00
|
|
|
static int cs8900_recv(struct eth_device *dev)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2003-02-28 00:49:47 +00:00
|
|
|
int i;
|
2009-08-25 20:09:37 +00:00
|
|
|
u16 rxlen;
|
|
|
|
u16 *addr;
|
|
|
|
u16 status;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv);
|
|
|
|
|
|
|
|
status = get_reg(dev, PP_RER);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
if ((status & PP_RER_RxOK) == 0)
|
|
|
|
return 0;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
status = REG_READ(&priv->regs->rtdata);
|
|
|
|
rxlen = REG_READ(&priv->regs->rtdata);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
if (rxlen > PKTSIZE_ALIGN + PKTALIGN)
|
2009-08-25 20:09:37 +00:00
|
|
|
debug("packet too big!\n");
|
|
|
|
for (addr = (u16 *) NetRxPackets[0], i = rxlen >> 1; i > 0;
|
2003-02-28 00:49:47 +00:00
|
|
|
i--)
|
2009-08-25 20:09:37 +00:00
|
|
|
*addr++ = REG_READ(&priv->regs->rtdata);
|
2003-02-28 00:49:47 +00:00
|
|
|
if (rxlen & 1)
|
2009-08-25 20:09:37 +00:00
|
|
|
*addr++ = REG_READ(&priv->regs->rtdata);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
/* Pass the packet up to the protocol layers. */
|
|
|
|
NetReceive (NetRxPackets[0], rxlen);
|
|
|
|
return rxlen;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send a data block via Ethernet. */
|
2012-05-21 14:45:21 +00:00
|
|
|
static int cs8900_send(struct eth_device *dev, void *packet, int length)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2009-08-25 20:09:37 +00:00
|
|
|
volatile u16 *addr;
|
2003-02-28 00:49:47 +00:00
|
|
|
int tmo;
|
2009-08-25 20:09:37 +00:00
|
|
|
u16 s;
|
|
|
|
struct cs8900_priv *priv = (struct cs8900_priv *)(dev->priv);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
retry:
|
2003-02-28 00:49:47 +00:00
|
|
|
/* initiate a transmit sequence */
|
2009-08-25 20:09:37 +00:00
|
|
|
REG_WRITE(PP_TxCmd_TxStart_Full, &priv->regs->txcmd);
|
|
|
|
REG_WRITE(length, &priv->regs->txlen);
|
2003-02-28 00:49:47 +00:00
|
|
|
|
|
|
|
/* Test to see if the chip has allocated memory for the packet */
|
2009-08-25 20:09:37 +00:00
|
|
|
if ((get_reg(dev, PP_BusSTAT) & PP_BusSTAT_TxRDY) == 0) {
|
2003-02-28 00:49:47 +00:00
|
|
|
/* Oops... this should not happen! */
|
2009-08-25 20:09:37 +00:00
|
|
|
debug("cs: unable to send packet; retrying...\n");
|
|
|
|
for (tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
|
|
|
|
get_timer(0) < tmo;)
|
2003-02-28 00:49:47 +00:00
|
|
|
/*NOP*/;
|
2009-08-25 20:09:37 +00:00
|
|
|
cs8900_reset(dev);
|
|
|
|
cs8900_reginit(dev);
|
2003-02-28 00:49:47 +00:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the contents of the packet */
|
|
|
|
/* assume even number of bytes */
|
|
|
|
for (addr = packet; length > 0; length -= 2)
|
2009-08-25 20:09:37 +00:00
|
|
|
REG_WRITE(*addr++, &priv->regs->rtdata);
|
2003-02-28 00:49:47 +00:00
|
|
|
|
|
|
|
/* wait for transfer to succeed */
|
2009-08-25 20:09:37 +00:00
|
|
|
tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
|
|
|
|
while ((s = get_reg(dev, PP_TER) & ~0x1F) == 0) {
|
|
|
|
if (get_timer(0) >= tmo)
|
2003-02-28 00:49:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nothing */ ;
|
2009-08-25 20:09:37 +00:00
|
|
|
if((s & (PP_TER_CRS | PP_TER_TxOK)) != PP_TER_TxOK) {
|
|
|
|
debug("\ntransmission error %#x\n", s);
|
2003-02-28 00:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
static void cs8900_e2prom_ready(struct eth_device *dev)
|
2003-03-06 21:55:29 +00:00
|
|
|
{
|
2009-08-25 20:09:37 +00:00
|
|
|
while (get_reg(dev, PP_SelfSTAT) & SI_BUSY)
|
2008-04-03 11:36:18 +00:00
|
|
|
;
|
2003-03-06 21:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
/* read a 16-bit word out of the EEPROM */
|
|
|
|
/***********************************************************/
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
int cs8900_e2prom_read(struct eth_device *dev,
|
|
|
|
u8 addr, u16 *value)
|
2003-03-06 21:55:29 +00:00
|
|
|
{
|
2009-08-25 20:09:37 +00:00
|
|
|
cs8900_e2prom_ready(dev);
|
|
|
|
put_reg(dev, PP_EECMD, EEPROM_READ_CMD | addr);
|
|
|
|
cs8900_e2prom_ready(dev);
|
|
|
|
*value = get_reg(dev, PP_EEData);
|
2003-03-06 21:55:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
/* write a 16-bit word into the EEPROM */
|
|
|
|
/***********************************************************/
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
int cs8900_e2prom_write(struct eth_device *dev, u8 addr, u16 value)
|
|
|
|
{
|
|
|
|
cs8900_e2prom_ready(dev);
|
|
|
|
put_reg(dev, PP_EECMD, EEPROM_WRITE_EN);
|
|
|
|
cs8900_e2prom_ready(dev);
|
|
|
|
put_reg(dev, PP_EEData, value);
|
|
|
|
put_reg(dev, PP_EECMD, EEPROM_WRITE_CMD | addr);
|
|
|
|
cs8900_e2prom_ready(dev);
|
|
|
|
put_reg(dev, PP_EECMD, EEPROM_WRITE_DIS);
|
|
|
|
cs8900_e2prom_ready(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cs8900_initialize(u8 dev_num, int base_addr)
|
2003-03-06 21:55:29 +00:00
|
|
|
{
|
2009-08-25 20:09:37 +00:00
|
|
|
struct eth_device *dev;
|
|
|
|
struct cs8900_priv *priv;
|
|
|
|
|
|
|
|
dev = malloc(sizeof(*dev));
|
|
|
|
if (!dev) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
|
|
|
|
|
|
priv = malloc(sizeof(*priv));
|
|
|
|
if (!priv) {
|
2010-01-21 21:16:34 +00:00
|
|
|
free(dev);
|
2009-08-25 20:09:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memset(priv, 0, sizeof(*priv));
|
|
|
|
priv->regs = (struct cs8900_regs *)base_addr;
|
|
|
|
|
|
|
|
dev->iobase = base_addr;
|
|
|
|
dev->priv = priv;
|
|
|
|
dev->init = cs8900_init;
|
|
|
|
dev->halt = cs8900_halt;
|
|
|
|
dev->send = cs8900_send;
|
|
|
|
dev->recv = cs8900_recv;
|
2009-11-05 01:58:44 +00:00
|
|
|
|
|
|
|
/* Load MAC address from EEPROM */
|
|
|
|
cs8900_get_enetaddr(dev);
|
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
sprintf(dev->name, "%s-%hu", CS8900_DRIVERNAME, dev_num);
|
2003-03-06 21:55:29 +00:00
|
|
|
|
2009-08-25 20:09:37 +00:00
|
|
|
eth_register(dev);
|
2003-03-14 20:47:52 +00:00
|
|
|
return 0;
|
2003-03-06 21:55:29 +00:00
|
|
|
}
|