summaryrefslogtreecommitdiffstats
path: root/drivers/net/at91_ether.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:22 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:22 +0200
commitf6508e1c4b45f0d5dc06a56eac8738eeaa9dd877 (patch)
tree4731ee2452a81eb90097ae42c0433405e451f7df /drivers/net/at91_ether.c
parent793babe674c9551b3bc9bcc0f1f7c2389b91b186 (diff)
downloadbarebox-f6508e1c4b45f0d5dc06a56eac8738eeaa9dd877.tar.gz
barebox-f6508e1c4b45f0d5dc06a56eac8738eeaa9dd877.tar.xz
svn_rev_095
Currently U-Boot uses globally defined eth_* functions. This is horribly unflexible. This patch replaces the global functions with pointers from structs. We could also use CONFIG_NET_MULTI, but this has other implications, though we should merge this some day. Also, U-Boot has no unique way to handle MAC addresses. Each and every board and network driver uses it's own mechanism to set the MAC address. There are several problems which I've for too often. For example everything goes well if we boot from network, but when we boot from flash U-Boot forgets to set the MAC address and the linux network driver has none. This patch adds [gs]et_mac_address to the eth_device struct and handles it as follows: - First try to get a valid MAC address from the EEPROM and set 'ethaddr' accordingly. - If no valid MAC address is found in the EEPROM (or no EEPROM is connected), we set the devices MAC address from 'ethaddr' This is done in eth_initialize which is called on startup for every board.
Diffstat (limited to 'drivers/net/at91_ether.c')
-rw-r--r--drivers/net/at91_ether.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/drivers/net/at91_ether.c b/drivers/net/at91_ether.c
index 67008d0b91..305372a1e0 100644
--- a/drivers/net/at91_ether.c
+++ b/drivers/net/at91_ether.c
@@ -151,7 +151,7 @@ UCHAR at91rm9200_EmacWritePhy (AT91PS_EMAC p_mac,
return TRUE;
}
-int eth_init (bd_t * bd)
+static int at91rm9200_eth_init (struct eth_device *ndev, bd_t * bd)
{
int ret;
int i;
@@ -190,10 +190,6 @@ int eth_init (bd_t * bd)
rbfdt[RBF_FRAMEMAX - 1].addr |= RBF_WRAP;
rbfp = &rbfdt[0];
- p_mac->EMAC_SA2L = (bd->bi_enetaddr[3] << 24) | (bd->bi_enetaddr[2] << 16)
- | (bd->bi_enetaddr[1] << 8) | (bd->bi_enetaddr[0]);
- p_mac->EMAC_SA2H = (bd->bi_enetaddr[5] << 8) | (bd->bi_enetaddr[4]);
-
p_mac->EMAC_RBQP = (long) (&rbfdt[0]);
p_mac->EMAC_RSR &= ~(AT91C_EMAC_RSR_OVR | AT91C_EMAC_REC | AT91C_EMAC_BNA);
@@ -211,6 +207,13 @@ int eth_init (bd_t * bd)
p_mac->EMAC_CTL |= AT91C_EMAC_TE | AT91C_EMAC_RE;
+ return 0;
+}
+
+static int at91rm9200_eth_open (struct eth_device *ndev, bd_t * bd)
+{
+ int ret;
+
at91rm9200_GetPhyInterface (& PhyOps);
if (!PhyOps.IsPhyConnected (p_mac))
@@ -226,11 +229,9 @@ int eth_init (bd_t * bd)
printf ("No link\n\r");
return 0;
}
-
- return 0;
}
-int eth_send (volatile void *packet, int length)
+static int at91rm9200_eth_send (struct eth_device *ndev, volatile void *packet, int length)
{
while (!(p_mac->EMAC_TSR & AT91C_EMAC_BNQ));
p_mac->EMAC_TAR = (long) packet;
@@ -240,7 +241,7 @@ int eth_send (volatile void *packet, int length)
return 0;
}
-int eth_rx (void)
+static int at91rm9200_eth_rx (struct eth_device *ndev)
{
int size;
@@ -261,7 +262,7 @@ int eth_rx (void)
return size;
}
-void eth_halt (void)
+static void at91rm9200_eth_halt (struct eth_device *ndev)
{
};
@@ -294,6 +295,31 @@ int at91rm9200_miiphy_initialize(bd_t *bis)
return 0;
}
+static int at91rm9200_get_mac_address(struct eth_device *eth, unsigned char *adr)
+{
+ /* We have no eeprom */
+ return -1;
+}
+
+static int at91rm9200_set_mac_address(struct eth_device *eth, unsigned char *adr)
+{
+ p_mac->EMAC_SA2L = (adr[3] << 24) | (adr[2] << 16)
+ | (adr[1] << 8) | (adr[0]);
+ p_mac->EMAC_SA2H = (adr[5] << 8) | (adr[4]);
+
+ return -0;
+}
+
+struct eth_device at91rm9200_eth = {
+ .init = at91rm9200_eth_init,
+ .open = at91rm9200_eth_open,
+ .send = at91rm9200_eth_send,
+ .recv = at91rm9200_eth_rx,
+ .halt = at91rm9200_eth_halt,
+ .get_mac_address = at91rm9200_get_mac_address,
+ .set_mac_address = at91rm9200_set_mac_address,
+};
+
#endif /* CONFIG_COMMANDS & CFG_CMD_NET */
#endif /* CONFIG_DRIVER_ETHER */