2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2003-10-09 20:09:04 +00:00
|
|
|
/* Only eth0 supported for now
|
|
|
|
*
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Thomas.Lange@corelatus.se
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_DISCOVER_PHY)
|
2005-09-24 22:53:22 +00:00
|
|
|
#error "PHY not supported yet"
|
2003-10-09 20:09:04 +00:00
|
|
|
/* We just assume that we are running 100FD for now */
|
|
|
|
/* We all use switches, right? ;-) */
|
|
|
|
#endif
|
|
|
|
|
2003-12-07 18:32:37 +00:00
|
|
|
/* I assume ethernet behaves like au1000 */
|
|
|
|
|
2008-06-07 11:51:56 +00:00
|
|
|
#ifdef CONFIG_SOC_AU1000
|
2003-10-09 20:09:04 +00:00
|
|
|
/* Base address differ between cpu:s */
|
|
|
|
#define ETH0_BASE AU1000_ETH0_BASE
|
|
|
|
#define MAC0_ENABLE AU1000_MAC0_ENABLE
|
|
|
|
#else
|
2008-06-07 11:51:56 +00:00
|
|
|
#ifdef CONFIG_SOC_AU1100
|
2003-12-07 18:32:37 +00:00
|
|
|
#define ETH0_BASE AU1100_ETH0_BASE
|
|
|
|
#define MAC0_ENABLE AU1100_MAC0_ENABLE
|
|
|
|
#else
|
2008-06-07 11:51:56 +00:00
|
|
|
#ifdef CONFIG_SOC_AU1500
|
2003-12-07 18:32:37 +00:00
|
|
|
#define ETH0_BASE AU1500_ETH0_BASE
|
|
|
|
#define MAC0_ENABLE AU1500_MAC0_ENABLE
|
|
|
|
#else
|
2008-06-07 11:51:56 +00:00
|
|
|
#ifdef CONFIG_SOC_AU1550
|
2005-01-09 22:28:56 +00:00
|
|
|
#define ETH0_BASE AU1550_ETH0_BASE
|
|
|
|
#define MAC0_ENABLE AU1550_MAC0_ENABLE
|
|
|
|
#else
|
2003-12-07 18:32:37 +00:00
|
|
|
#error "No valid cpu set"
|
|
|
|
#endif
|
|
|
|
#endif
|
2003-10-09 20:09:04 +00:00
|
|
|
#endif
|
2005-01-09 22:28:56 +00:00
|
|
|
#endif
|
2003-10-09 20:09:04 +00:00
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <asm/io.h>
|
2015-12-21 15:35:14 +00:00
|
|
|
#include <mach/au1x00.h>
|
2003-10-09 20:09:04 +00:00
|
|
|
|
2007-07-10 00:06:00 +00:00
|
|
|
#if defined(CONFIG_CMD_MII)
|
2005-10-28 20:30:33 +00:00
|
|
|
#include <miiphy.h>
|
|
|
|
#endif
|
|
|
|
|
2003-10-09 20:09:04 +00:00
|
|
|
/* Ethernet Transmit and Receive Buffers */
|
|
|
|
#define DBUF_LENGTH 1520
|
|
|
|
#define PKT_MAXBUF_SIZE 1518
|
|
|
|
|
|
|
|
static char txbuf[DBUF_LENGTH];
|
|
|
|
|
|
|
|
static int next_tx;
|
|
|
|
static int next_rx;
|
|
|
|
|
|
|
|
/* 4 rx and 4 tx fifos */
|
|
|
|
#define NO_OF_FIFOS 4
|
|
|
|
|
|
|
|
typedef struct{
|
|
|
|
u32 status;
|
|
|
|
u32 addr;
|
|
|
|
u32 len; /* Only used for tx */
|
|
|
|
u32 not_used;
|
|
|
|
} mac_fifo_t;
|
|
|
|
|
|
|
|
mac_fifo_t mac_fifo[NO_OF_FIFOS];
|
|
|
|
|
|
|
|
#define MAX_WAIT 1000
|
|
|
|
|
2007-10-27 06:00:25 +00:00
|
|
|
#if defined(CONFIG_CMD_MII)
|
2016-08-08 16:28:38 +00:00
|
|
|
int au1x00_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
|
2007-10-27 06:00:25 +00:00
|
|
|
{
|
2016-08-08 16:28:38 +00:00
|
|
|
unsigned short value = 0;
|
2007-10-27 06:00:25 +00:00
|
|
|
volatile u32 *mii_control_reg = (volatile u32*)(ETH0_BASE+MAC_MII_CNTRL);
|
|
|
|
volatile u32 *mii_data_reg = (volatile u32*)(ETH0_BASE+MAC_MII_DATA);
|
|
|
|
u32 mii_control;
|
|
|
|
unsigned int timedout = 20;
|
|
|
|
|
|
|
|
while (*mii_control_reg & MAC_MII_BUSY) {
|
|
|
|
udelay(1000);
|
|
|
|
if (--timedout == 0) {
|
|
|
|
printf("au1x00_eth: miiphy_read busy timeout!!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mii_control = MAC_SET_MII_SELECT_REG(reg) |
|
|
|
|
MAC_SET_MII_SELECT_PHY(addr) | MAC_MII_READ;
|
|
|
|
|
|
|
|
*mii_control_reg = mii_control;
|
|
|
|
|
|
|
|
timedout = 20;
|
|
|
|
while (*mii_control_reg & MAC_MII_BUSY) {
|
|
|
|
udelay(1000);
|
|
|
|
if (--timedout == 0) {
|
|
|
|
printf("au1x00_eth: miiphy_read busy timeout!!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2016-08-08 16:28:38 +00:00
|
|
|
value = *mii_data_reg;
|
|
|
|
return value;
|
2007-10-27 06:00:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 16:28:38 +00:00
|
|
|
int au1x00_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
|
|
|
|
u16 value)
|
2007-10-27 06:00:25 +00:00
|
|
|
{
|
|
|
|
volatile u32 *mii_control_reg = (volatile u32*)(ETH0_BASE+MAC_MII_CNTRL);
|
|
|
|
volatile u32 *mii_data_reg = (volatile u32*)(ETH0_BASE+MAC_MII_DATA);
|
|
|
|
u32 mii_control;
|
|
|
|
unsigned int timedout = 20;
|
|
|
|
|
|
|
|
while (*mii_control_reg & MAC_MII_BUSY) {
|
|
|
|
udelay(1000);
|
|
|
|
if (--timedout == 0) {
|
|
|
|
printf("au1x00_eth: miiphy_write busy timeout!!\n");
|
2007-10-27 06:22:33 +00:00
|
|
|
return -1;
|
2007-10-27 06:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mii_control = MAC_SET_MII_SELECT_REG(reg) |
|
|
|
|
MAC_SET_MII_SELECT_PHY(addr) | MAC_MII_WRITE;
|
|
|
|
|
|
|
|
*mii_data_reg = value;
|
|
|
|
*mii_control_reg = mii_control;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-22 18:36:19 +00:00
|
|
|
static int au1x00_send(struct eth_device *dev, void *packet, int length)
|
|
|
|
{
|
2003-10-09 20:09:04 +00:00
|
|
|
volatile mac_fifo_t *fifo_tx =
|
|
|
|
(volatile mac_fifo_t*)(MAC0_TX_DMA_ADDR+MAC_TX_BUFF0_STATUS);
|
|
|
|
int i;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
/* tx fifo should always be idle */
|
|
|
|
fifo_tx[next_tx].len = length;
|
|
|
|
fifo_tx[next_tx].addr = (virt_to_phys(packet))|TX_DMA_ENABLE;
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
udelay(1);
|
|
|
|
i=0;
|
|
|
|
while(!(fifo_tx[next_tx].addr&TX_T_DONE)){
|
|
|
|
if(i>MAX_WAIT){
|
|
|
|
printf("TX timeout\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
udelay(1);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear done bit */
|
|
|
|
fifo_tx[next_tx].addr = 0;
|
|
|
|
fifo_tx[next_tx].len = 0;
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
res = fifo_tx[next_tx].status;
|
|
|
|
|
|
|
|
next_tx++;
|
|
|
|
if(next_tx>=NO_OF_FIFOS){
|
|
|
|
next_tx=0;
|
|
|
|
}
|
|
|
|
return(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int au1x00_recv(struct eth_device* dev){
|
|
|
|
volatile mac_fifo_t *fifo_rx =
|
|
|
|
(volatile mac_fifo_t*)(MAC0_RX_DMA_ADDR+MAC_RX_BUFF0_STATUS);
|
|
|
|
|
|
|
|
int length;
|
|
|
|
u32 status;
|
|
|
|
|
|
|
|
for(;;){
|
|
|
|
if(!(fifo_rx[next_rx].addr&RX_T_DONE)){
|
|
|
|
/* Nothing has been received */
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
status = fifo_rx[next_rx].status;
|
|
|
|
|
|
|
|
length = status&0x3FFF;
|
|
|
|
|
|
|
|
if(status&RX_ERROR){
|
|
|
|
printf("Rx error 0x%x\n", status);
|
2015-04-08 06:41:06 +00:00
|
|
|
} else {
|
2003-10-09 20:09:04 +00:00
|
|
|
/* Pass the packet up to the protocol layers. */
|
2015-04-08 06:41:06 +00:00
|
|
|
net_process_received_packet(net_rx_packets[next_rx],
|
|
|
|
length - 4);
|
2003-10-09 20:09:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 06:41:06 +00:00
|
|
|
fifo_rx[next_rx].addr =
|
|
|
|
(virt_to_phys(net_rx_packets[next_rx])) | RX_DMA_ENABLE;
|
2003-10-09 20:09:04 +00:00
|
|
|
|
|
|
|
next_rx++;
|
|
|
|
if(next_rx>=NO_OF_FIFOS){
|
|
|
|
next_rx=0;
|
|
|
|
}
|
|
|
|
} /* for */
|
|
|
|
|
|
|
|
return(0); /* Does anyone use this? */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int au1x00_init(struct eth_device* dev, bd_t * bd){
|
|
|
|
|
|
|
|
volatile u32 *macen = (volatile u32*)MAC0_ENABLE;
|
|
|
|
volatile u32 *mac_ctrl = (volatile u32*)(ETH0_BASE+MAC_CONTROL);
|
|
|
|
volatile u32 *mac_addr_high = (volatile u32*)(ETH0_BASE+MAC_ADDRESS_HIGH);
|
|
|
|
volatile u32 *mac_addr_low = (volatile u32*)(ETH0_BASE+MAC_ADDRESS_LOW);
|
|
|
|
volatile u32 *mac_mcast_high = (volatile u32*)(ETH0_BASE+MAC_MCAST_HIGH);
|
|
|
|
volatile u32 *mac_mcast_low = (volatile u32*)(ETH0_BASE+MAC_MCAST_LOW);
|
|
|
|
volatile mac_fifo_t *fifo_tx =
|
|
|
|
(volatile mac_fifo_t*)(MAC0_TX_DMA_ADDR+MAC_TX_BUFF0_STATUS);
|
|
|
|
volatile mac_fifo_t *fifo_rx =
|
|
|
|
(volatile mac_fifo_t*)(MAC0_RX_DMA_ADDR+MAC_RX_BUFF0_STATUS);
|
|
|
|
int i;
|
|
|
|
|
2005-09-24 20:05:40 +00:00
|
|
|
next_tx = TX_GET_DMA_BUFFER(fifo_tx[0].addr);
|
|
|
|
next_rx = RX_GET_DMA_BUFFER(fifo_rx[0].addr);
|
2003-10-09 20:09:04 +00:00
|
|
|
|
|
|
|
/* We have to enable clocks before releasing reset */
|
|
|
|
*macen = MAC_EN_CLOCK_ENABLE;
|
|
|
|
udelay(10);
|
|
|
|
|
|
|
|
/* Enable MAC0 */
|
|
|
|
/* We have to release reset before accessing registers */
|
|
|
|
*macen = MAC_EN_CLOCK_ENABLE|MAC_EN_RESET0|
|
|
|
|
MAC_EN_RESET1|MAC_EN_RESET2;
|
|
|
|
udelay(10);
|
|
|
|
|
|
|
|
for(i=0;i<NO_OF_FIFOS;i++){
|
|
|
|
fifo_tx[i].len = 0;
|
|
|
|
fifo_tx[i].addr = virt_to_phys(&txbuf[0]);
|
2015-04-08 06:41:06 +00:00
|
|
|
fifo_rx[i].addr = (virt_to_phys(net_rx_packets[i])) |
|
|
|
|
RX_DMA_ENABLE;
|
2003-10-09 20:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Put mac addr in little endian */
|
2015-03-22 22:09:00 +00:00
|
|
|
#define ea eth_get_ethaddr()
|
2005-09-24 22:53:22 +00:00
|
|
|
*mac_addr_high = (ea[5] << 8) | (ea[4] ) ;
|
|
|
|
*mac_addr_low = (ea[3] << 24) | (ea[2] << 16) |
|
|
|
|
(ea[1] << 8) | (ea[0] ) ;
|
2003-10-09 20:09:04 +00:00
|
|
|
#undef ea
|
|
|
|
*mac_mcast_low = 0;
|
|
|
|
*mac_mcast_high = 0;
|
|
|
|
|
2004-01-02 15:01:32 +00:00
|
|
|
/* Make sure the MAC buffer is in the correct endian mode */
|
|
|
|
#ifdef __LITTLE_ENDIAN
|
|
|
|
*mac_ctrl = MAC_FULL_DUPLEX;
|
|
|
|
udelay(1);
|
|
|
|
*mac_ctrl = MAC_FULL_DUPLEX|MAC_RX_ENABLE|MAC_TX_ENABLE;
|
|
|
|
#else
|
2003-10-09 20:09:04 +00:00
|
|
|
*mac_ctrl = MAC_BIG_ENDIAN|MAC_FULL_DUPLEX;
|
|
|
|
udelay(1);
|
|
|
|
*mac_ctrl = MAC_BIG_ENDIAN|MAC_FULL_DUPLEX|MAC_RX_ENABLE|MAC_TX_ENABLE;
|
2004-01-02 15:01:32 +00:00
|
|
|
#endif
|
2003-10-09 20:09:04 +00:00
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au1x00_halt(struct eth_device* dev){
|
2009-04-24 14:22:16 +00:00
|
|
|
volatile u32 *macen = (volatile u32*)MAC0_ENABLE;
|
|
|
|
|
|
|
|
/* Put MAC0 in reset */
|
|
|
|
*macen = 0;
|
2003-10-09 20:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int au1x00_enet_initialize(bd_t *bis){
|
|
|
|
struct eth_device* dev;
|
|
|
|
|
2006-03-13 00:00:22 +00:00
|
|
|
if ((dev = (struct eth_device*)malloc(sizeof *dev)) == NULL) {
|
|
|
|
puts ("malloc failed\n");
|
2008-10-19 03:08:50 +00:00
|
|
|
return -1;
|
2006-03-13 00:00:22 +00:00
|
|
|
}
|
|
|
|
|
2003-10-09 20:09:04 +00:00
|
|
|
memset(dev, 0, sizeof *dev);
|
|
|
|
|
2015-12-30 13:05:58 +00:00
|
|
|
strcpy(dev->name, "Au1X00 ethernet");
|
2003-10-09 20:09:04 +00:00
|
|
|
dev->iobase = 0;
|
|
|
|
dev->priv = 0;
|
|
|
|
dev->init = au1x00_init;
|
|
|
|
dev->halt = au1x00_halt;
|
|
|
|
dev->send = au1x00_send;
|
|
|
|
dev->recv = au1x00_recv;
|
|
|
|
|
|
|
|
eth_register(dev);
|
|
|
|
|
2007-07-10 00:06:00 +00:00
|
|
|
#if defined(CONFIG_CMD_MII)
|
2016-08-08 16:28:38 +00:00
|
|
|
int retval;
|
|
|
|
struct mii_dev *mdiodev = mdio_alloc();
|
|
|
|
if (!mdiodev)
|
|
|
|
return -ENOMEM;
|
|
|
|
strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
|
|
|
|
mdiodev->read = au1x00_miiphy_read;
|
|
|
|
mdiodev->write = au1x00_miiphy_write;
|
|
|
|
|
|
|
|
retval = mdio_register(mdiodev);
|
|
|
|
if (retval < 0)
|
|
|
|
return retval;
|
2005-10-28 20:30:33 +00:00
|
|
|
#endif
|
|
|
|
|
2003-10-09 20:09:04 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2015-01-29 13:47:01 +00:00
|
|
|
|
|
|
|
int cpu_eth_init(bd_t *bis)
|
|
|
|
{
|
|
|
|
au1x00_enet_initialize(bis);
|
|
|
|
return 0;
|
|
|
|
}
|