All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Thompson <nick.thompson@gefanuc.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/1] davinci_emac driver: modify to allow support for DA8xx
Date: Tue, 20 Oct 2009 14:20:41 +0100	[thread overview]
Message-ID: <4ADDB929.4050906@gefanuc.com> (raw)

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@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@gefanuc.com>
+ *
+ * Abstracted out code not common to all davinci class devices.
+ *
  * Copyright (C) 2007 Sergey Kubushyn <ksi@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_ */

             reply	other threads:[~2009-10-20 13:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-20 13:20 Nick Thompson [this message]
2009-10-20 13:53 ` [U-Boot] [PATCH 1/1] davinci_emac driver: modify to allow support for DA8xx Paulraj, Sandeep
2009-10-21  9:11   ` Nick Thompson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ADDB929.4050906@gefanuc.com \
    --to=nick.thompson@gefanuc.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.