[U-Boot] [PATCH 1/1] davinci_emac driver: modify to allow support for DA8xx

Nick Thompson nick.thompson at gefanuc.com
Tue Oct 20 15:20:41 CEST 2009


Abstract out $ARCH specific parts of the davinci_emac driver.

Some Davinci devices contain an EMAC implemetation that has small
differences from the devices currently supported by the driver.
Abstrating those sections into static inlines in the $ARCH include
files allows those parts to be modified per $ARCH.

Specifically this patch will allow DA830 and DA850 devices to use
the same driver as many DMXXXX devices.

Signed-off-by: Nick Thompson <nick.thompson at gefanuc.com>
---
Applies to u-boot-ti
Only tested on DA830

 drivers/net/davinci_emac.c               |   61 ++++++++++++------------------
 include/asm-arm/arch-davinci/emac_defs.h |   35 +++++++++++++++++
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index fa8cee4..0d61b9f 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -1,6 +1,10 @@
 /*
  * Ethernet driver for TI TMS320DM644x (DaVinci) chips.
  *
+ * Copyright (C) 2009 Nick Thompson, GE Fanuc Ltd <nick.thompson at gefanuc.com>
+ *
+ * Abstracted out code not common to all davinci class devices.
+ *
  * Copyright (C) 2007 Sergey Kubushyn <ksi at koi8.net>
  *
  * Parts shamelessly stolen from TI's dm644x_emac.c. Original copyright
@@ -119,7 +123,8 @@ static int davinci_eth_phy_detect(void)
 
 	active_phy_addr = 0xff;
 
-	if ((phy_act_state = adap_mdio->ALIVE) == 0)
+	phy_act_state = adap_mdio->ALIVE & EMAC_MDIO_PHY_MASK;
+	if (phy_act_state == 0)
 		return(0);				/* No active PHYs */
 
 	debug_emac("davinci_eth_phy_detect(), ALIVE = 0x%08x\n", phy_act_state);
@@ -261,10 +266,7 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
 	/* Reset EMAC module and disable interrupts in wrapper */
 	adap_emac->SOFTRESET = 1;
 	while (adap_emac->SOFTRESET != 0) {;}
-	adap_ewrap->EWCTL = 0;
-	for (cnt = 0; cnt < 5; cnt++) {
-		clkdiv = adap_ewrap->EWCTL;
-	}
+	davinci_reset_emac_wrapper(adap_ewrap);
 
 	rx_desc = emac_rx_desc;
 
@@ -272,30 +274,11 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
 	adap_emac->RXCONTROL = 0x01;
 
 	/* Set MAC Addresses & Init multicast Hash to 0 (disable any multicast receive) */
-	/* Using channel 0 only - other channels are disabled */
-	adap_emac->MACINDEX = 0;
-	adap_emac->MACADDRHI =
-		(davinci_eth_mac_addr[3] << 24) |
-		(davinci_eth_mac_addr[2] << 16) |
-		(davinci_eth_mac_addr[1] << 8)  |
-		(davinci_eth_mac_addr[0]);
-	adap_emac->MACADDRLO =
-		(davinci_eth_mac_addr[5] << 8) |
-		(davinci_eth_mac_addr[4]);
+	davinci_emac_set_mac_addr(adap_emac, davinci_eth_mac_addr);
 
 	adap_emac->MACHASH1 = 0;
 	adap_emac->MACHASH2 = 0;
 
-	/* Set source MAC address - REQUIRED */
-	adap_emac->MACSRCADDRHI =
-		(davinci_eth_mac_addr[3] << 24) |
-		(davinci_eth_mac_addr[2] << 16) |
-		(davinci_eth_mac_addr[1] << 8)  |
-		(davinci_eth_mac_addr[0]);
-	adap_emac->MACSRCADDRLO =
-		(davinci_eth_mac_addr[4] << 8) |
-		(davinci_eth_mac_addr[5]);
-
 	/* Set DMA 8 TX / 8 RX Head pointers to 0 */
 	addr = &adap_emac->TX0HDP;
 	for(cnt = 0; cnt < 16; cnt++)
@@ -341,7 +324,7 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
 	adap_emac->RXUNICASTSET = 0x01;
 
 	/* Enable MII interface and Full duplex mode */
-	adap_emac->MACCONTROL = (EMAC_MACCONTROL_MIIEN_ENABLE | EMAC_MACCONTROL_FULLDUPLEX_ENABLE);
+	davinci_enable_mii(adap_emac);
 
 	/* Init MDIO & get link state */
 	clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
@@ -374,9 +357,9 @@ static void davinci_eth_ch_teardown(int ch)
 			 * Note: A task delay can be called here to pend rather than
 			 * occupying CPU cycles - anyway it has been found that teardown
 			 * takes very few cpu cycles and does not affect functionality */
-			 dly--;
-			 udelay(1);
-			 if (dly == 0)
+			dly--;
+			udelay(1);
+			if (dly == 0)
 				break;
 		}
 		adap_emac->TX0CP = cnt;
@@ -389,9 +372,9 @@ static void davinci_eth_ch_teardown(int ch)
 			 * Note: A task delay can be called here to pend rather than
 			 * occupying CPU cycles - anyway it has been found that teardown
 			 * takes very few cpu cycles and does not affect functionality */
-			 dly--;
-			 udelay(1);
-			 if (dly == 0)
+			dly--;
+			udelay(1);
+			if (dly == 0)
 				break;
 		}
 		adap_emac->RX0CP = cnt;
@@ -411,7 +394,7 @@ static void davinci_eth_close(struct eth_device *dev)
 
 	/* Reset EMAC module and disable interrupts in wrapper */
 	adap_emac->SOFTRESET = 1;
-	adap_ewrap->EWCTL = 0;
+	davinci_reset_emac_wrapper(adap_ewrap);
 
 	debug_emac("- emac_close\n");
 }
@@ -445,9 +428,9 @@ static int davinci_eth_send_packet (struct eth_device *dev,
 	emac_tx_desc->buffer = (u_int8_t *) packet;
 	emac_tx_desc->buff_off_len = (length & 0xffff);
 	emac_tx_desc->pkt_flag_len = ((length & 0xffff) |
-				      EMAC_CPPI_SOP_BIT |
-				      EMAC_CPPI_OWNERSHIP_BIT |
-				      EMAC_CPPI_EOP_BIT);
+				EMAC_CPPI_SOP_BIT |
+				EMAC_CPPI_OWNERSHIP_BIT |
+				EMAC_CPPI_EOP_BIT);
 	/* Send the packet */
 	adap_emac->TX0HDP = (unsigned int) emac_tx_desc;
 
@@ -485,7 +468,7 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
 			printf ("WARN: emac_rcv_pkt: Error in packet\n");
 		} else {
 			NetReceive (rx_curr_desc->buffer,
-				    (rx_curr_desc->buff_off_len & 0xffff));
+				(rx_curr_desc->buff_off_len & 0xffff));
 			ret = rx_curr_desc->buff_off_len & 0xffff;
 		}
 
@@ -596,6 +579,7 @@ int davinci_emac_initialize(void)
 	phy_id |= tmp & 0x0000ffff;
 
 	switch (phy_id) {
+#ifdef PHY_LXT972
 		case PHY_LXT972:
 			sprintf(phy.name, "LXT972 @ 0x%02x", active_phy_addr);
 			phy.init = lxt972_init_phy;
@@ -603,6 +587,8 @@ int davinci_emac_initialize(void)
 			phy.get_link_speed = lxt972_get_link_speed;
 			phy.auto_negotiate = lxt972_auto_negotiate;
 			break;
+#endif
+#ifdef PHY_DP83848
 		case PHY_DP83848:
 			sprintf(phy.name, "DP83848 @ 0x%02x", active_phy_addr);
 			phy.init = dp83848_init_phy;
@@ -610,6 +596,7 @@ int davinci_emac_initialize(void)
 			phy.get_link_speed = dp83848_get_link_speed;
 			phy.auto_negotiate = dp83848_auto_negotiate;
 			break;
+#endif
 		default:
 			sprintf(phy.name, "GENERIC @ 0x%02x", active_phy_addr);
 			phy.init = gen_init_phy;
diff --git a/include/asm-arm/arch-davinci/emac_defs.h b/include/asm-arm/arch-davinci/emac_defs.h
index 96bc80e..fc70a31 100644
--- a/include/asm-arm/arch-davinci/emac_defs.h
+++ b/include/asm-arm/arch-davinci/emac_defs.h
@@ -338,4 +338,39 @@ int dp83848_get_link_speed(int phy_addr);
 int dp83848_init_phy(int phy_addr);
 int dp83848_auto_negotiate(int phy_addr);
 
+static inline void davinci_emac_set_mac_addr(volatile emac_regs *adap_emac,
+						u_init8 *mac_addr)
+{
+	unsigned long mac_hi;
+	unsigned long mac_lo;
+
+	mac_hi = (mac_addr[3] << 24) | (mac_addr[2] << 16) |
+		(mac_addr[1] << 8) | (mac_addr[0]);
+	mac_lo = (mac_addr[5] << 8) | (mac_addr[4]);
+
+	/* Using channel 0 only - other channels are disabled */
+	adap_emac->MACINDEX = 0;
+	adap_emac->MACADDRHI = mac_hi;
+	adap_emac->MACADDRLO = mac_lo;
+
+	/* Set source MAC address - REQUIRED */
+	adap_emac->MACSRCADDRHI = mac_hi;
+	adap_emac->MACSRCADDRLO = mac_lo;
+}
+
+static inline void davinci_enable_mii(volatile emac_regs *adap_emac)
+{
+	adap_emac->MACCONTROL = (EMAC_MACCONTROL_MIIEN_ENABLE |
+				EMAC_MACCONTROL_FULLDUPLEX_ENABLE);
+}
+
+static inline void davinci_reset_emac_wrapper(volatile ewrap_regs *adap_ewrap)
+{
+	u_int32_t dummy;
+
+	adap_ewrap->EWCTL = 0;
+	for (cnt = 0; cnt < 5; cnt++)
+		dummy = adap_ewrap->EWCTL;
+}
+
 #endif  /* _DM644X_EMAC_H_ */


More information about the U-Boot mailing list