[U-Boot] [PATCH] Convert SMC911X Ethernet driver to CONFIG_NET_MULTI API

Mike Frysinger vapier at gentoo.org
Fri Jul 17 05:46:45 CEST 2009


couple changes to squash into this:
 - fix build error for systems using in 16bit
 - tweak bf548-ezkit update
 - do not leak priv malloc() if dev malloc() failed
 - make sure we clear eth_device (we really need a zalloc())
 - initialize dev->enetaddr in the driver register func
 - initialize the driver mac with dev->enetaddr

seems to work on my bf548-ezkit:
....
Net:   smc911x-0
Hit any key to stop autoboot:  0
bfin> t 0 u-boot.bin
smc911x: initializing
smc911x: detected LAN9218 controller
smc911x: phy initialized
smc911x: MAC 00:e0:22:fe:bd:04
Using smc911x-0 device
TFTP from server 192.168.0.2; our IP address is 192.168.0.15
Filename 'u-boot.bin'.
Load address: 0x0
Loading: ##################
done
Bytes transferred = 258112 (3f040 hex)
bfin>

-mike

diff --git a/board/bf548-ezkit/bf548-ezkit.c b/board/bf548-ezkit/bf548-ezkit.c
index 69a581b..88a0cd4 100644
--- a/board/bf548-ezkit/bf548-ezkit.c
+++ b/board/bf548-ezkit/bf548-ezkit.c
@@ -79,12 +79,9 @@ int board_early_init_f(void)
 	return 0;
 }
 
+#ifdef CONFIG_SMC911X
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC911X
-	rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
-#endif
-	return rc;
+	return smc911x_initialize(0, CONFIG_SMC911X_BASE);
 }
-
+#endif
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 9eb080f..2bbd7ea 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -37,49 +37,17 @@ void pkt_data_push(struct eth_device *dev, u32 addr, u32 val) \
 
 #define mdelay(n)       udelay((n)*1000)
 
-static int smx911x_handle_mac_address(struct eth_device *dev)
+static void smx911x_handle_mac_address(struct eth_device *dev)
 {
 	unsigned long addrh, addrl;
-	uchar m[6];
-	char env_parm_name[10];  /* Long enough for ethxxaddr */
-	u8 dev_num = ((struct smc911x_priv *)(dev->priv))->dev_num;
-
-	if (dev_num == 0)
-		strncpy(env_parm_name, "ethaddr", 7);
-	else
-		sprintf(env_parm_name, "eth%huaddr", dev_num);
-
-	if (eth_getenv_enetaddr(env_parm_name, m)) {
-		/* if the environment has a valid mac address then use it */
-		addrl = m[0] | (m[1] << 8) | (m[2] << 16) | (m[3] << 24);
-		addrh = m[4] | (m[5] << 8);
-		smc911x_set_mac_csr(dev, ADDRL, addrl);
-		smc911x_set_mac_csr(dev, ADDRH, addrh);
-	} else {
-		/* if not, try to get one from the eeprom */
-		addrh = smc911x_get_mac_csr(dev, ADDRH);
-		addrl = smc911x_get_mac_csr(dev, ADDRL);
-
-		m[0] = (addrl       ) & 0xff;
-		m[1] = (addrl >>  8 ) & 0xff;
-		m[2] = (addrl >> 16 ) & 0xff;
-		m[3] = (addrl >> 24 ) & 0xff;
-		m[4] = (addrh       ) & 0xff;
-		m[5] = (addrh >>  8 ) & 0xff;
-
-		/* we get 0xff when there is no eeprom connected */
-		if ((m[0] & m[1] & m[2] & m[3] & m[4] & m[5]) == 0xff) {
-			printf(DRIVERNAME ": no valid mac address in "
-				"environment and no eeprom found\n");
-			return -1;
-		}
-
-		eth_setenv_enetaddr(env_parm_name, m);
-	}
+	uchar *m = dev->enetaddr;
 
-	printf(DRIVERNAME ": MAC %pM\n", m);
+	addrl = m[0] | (m[1] << 8) | (m[2] << 16) | (m[3] << 24);
+	addrh = m[4] | (m[5] << 8);
+	smc911x_set_mac_csr(dev, ADDRL, addrl);
+	smc911x_set_mac_csr(dev, ADDRH, addrh);
 
-	return 0;
+	printf(DRIVERNAME ": MAC %pM\n", m);
 }
 
 static int smc911x_miiphy_read(struct eth_device *dev,
@@ -188,8 +156,7 @@ static int smc911x_init(struct eth_device *dev, bd_t * bd)
 	/* Configure the PHY, initialize the link state */
 	smc911x_phy_configure(dev);
 
-	if ((smx911x_handle_mac_address(dev)) < 0)
-		goto err_out;
+	smx911x_handle_mac_address(dev);
 
 	/* Turn on Tx + Rx */
 	smc911x_enable(dev);
@@ -274,16 +241,34 @@ static int smc911x_rx(struct eth_device *dev)
 
 int smc911x_initialize(u8 dev_num, int base_addr)
 {
-	struct smc911x_priv *priv = malloc(sizeof(struct smc911x_priv));
+	unsigned long addrl, addrh;
+	struct smc911x_priv *priv;
+	struct eth_device *dev;
+
+	priv = malloc(sizeof(*priv));
 	if (!priv)
 		return 0;
-	struct eth_device *dev = malloc(sizeof(struct eth_device));
-	if (!dev)
+
+	dev = malloc(sizeof(*dev));
+	if (!dev) {
+		free(dev);
 		return 0;
+	}
+	memset(dev, 0, sizeof(*dev));
+
 	priv->dev_num = dev_num;
 	dev->priv = priv;
 	dev->iobase = base_addr;
 
+	addrh = smc911x_get_mac_csr(dev, ADDRH);
+	addrl = smc911x_get_mac_csr(dev, ADDRL);
+	dev->enetaddr[0] = addrl;
+	dev->enetaddr[1] = addrl >>  8;
+	dev->enetaddr[2] = addrl >> 16;
+	dev->enetaddr[3] = addrl >> 24;
+	dev->enetaddr[4] = addrh;
+	dev->enetaddr[5] = addrh >> 8;
+
 	dev->init = smc911x_init;
 	dev->halt = smc911x_halt;
 	dev->send = smc911x_send;
diff --git a/drivers/net/smc911x.h b/drivers/net/smc911x.h
index 67af519..58dac80 100644
--- a/drivers/net/smc911x.h
+++ b/drivers/net/smc911x.h
@@ -64,8 +64,8 @@ static inline u32 smc911x_reg_read(struct eth_device *dev, u32 offset)
 static inline void smc911x_reg_write(struct eth_device *dev,
 					u32 offset, u32 val)
 {
-	*(volatile u16*)(dev->iobase + addr) = (u16)val;
-	*(volatile u16*)(dev->iobase + addr + 2) = (u16)(val >> 16);
+	*(volatile u16 *)(dev->iobase + offset) = (u16)val;
+	*(volatile u16 *)(dev->iobase + offset + 2) = (u16)(val >> 16);
 }
 #else
 #error "SMC911X: undefined bus width"

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090716/27a929bb/attachment.pgp 


More information about the U-Boot mailing list