linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: manabian@gmail.com (Joachim Eastwood)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/5] net/at91_ether: move eth addr quirk into csb337 board setup
Date: Sun, 21 Oct 2012 16:23:10 +0200	[thread overview]
Message-ID: <1350829392-3812-4-git-send-email-manabian@gmail.com> (raw)
In-Reply-To: <1350829392-3812-1-git-send-email-manabian@gmail.com>

Move Ethernet address byte order fix for csb337 into it's board
setup.

This will allow us to remove the last mach include from at91_ether
and also to share the address setup with the macb driver.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 arch/arm/mach-at91/board-csb337.c         | 35 +++++++++++++++++++++++++++++++
 drivers/net/ethernet/cadence/Kconfig      |  1 -
 drivers/net/ethernet/cadence/at91_ether.c | 26 ++++++-----------------
 3 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/arch/arm/mach-at91/board-csb337.c b/arch/arm/mach-at91/board-csb337.c
index 3e37437..5522132 100644
--- a/arch/arm/mach-at91/board-csb337.c
+++ b/arch/arm/mach-at91/board-csb337.c
@@ -217,6 +217,40 @@ static struct gpio_led csb_leds[] = {
 	}
 };
 
+/*
+ * MicroMonitor (uMon) on the CSB337 store the ethernet address in the
+ * wrong byte order (and continues to do so, for bug-compatibility).
+ */
+#define MACB_SA1B	0x0098
+#define MACB_SA1T	0x009c
+static void __init csb337_fix_eth_addr(void)
+{
+	void __iomem *emac;
+	u32 lo, hi, tmp;
+	int i;
+
+	emac = ioremap(AT91RM9200_BASE_EMAC, SZ_16K);
+	if (!emac) {
+		printk(KERN_ERR "csb337: unable to fixup Ethernet address\n");
+		return;
+	}
+
+	/* Fix byte order on all 4 address registers */
+	for (i = 0; i < 4; i++) {
+		lo = readl(emac + MACB_SA1B + i * 8);
+		hi = readl(emac + MACB_SA1T + i * 8);
+
+		tmp = (lo & 0xff) << 8 | (lo & 0xff00) >> 8;
+		writel(tmp, emac + MACB_SA1T + i * 8);
+
+		tmp = (hi & 0xff) << 8 | (hi & 0xff00) >> 8
+			| (lo & 0xff0000) << 8
+			| (lo & 0xff000000) >> 8;
+		writel(tmp, emac + MACB_SA1B + i * 8);
+	}
+
+	iounmap(emac);
+}
 
 static void __init csb337_board_init(void)
 {
@@ -225,6 +259,7 @@ static void __init csb337_board_init(void)
 	at91_register_uart(0, 0, 0);
 	at91_add_device_serial();
 	/* Ethernet */
+	csb337_fix_eth_addr();
 	at91_add_device_eth(&csb337_eth_data);
 	/* USB Host */
 	at91_add_device_usbh(&csb337_usbh_data);
diff --git a/drivers/net/ethernet/cadence/Kconfig b/drivers/net/ethernet/cadence/Kconfig
index f6d0956..40172d1 100644
--- a/drivers/net/ethernet/cadence/Kconfig
+++ b/drivers/net/ethernet/cadence/Kconfig
@@ -21,7 +21,6 @@ if NET_CADENCE
 
 config ARM_AT91_ETHER
 	tristate "AT91RM9200 Ethernet support"
-	depends on ARM && ARCH_AT91RM9200
 	select NET_CORE
 	select MACB
 	---help---
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index 375d272..5ed1a63 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -32,8 +32,6 @@
 #include <linux/phy.h>
 #include <linux/io.h>
 
-#include <asm/mach-types.h>
-
 #include "macb.h"
 
 #define DRV_NAME	"at91_ether"
@@ -55,30 +53,18 @@
  *   U-Boot on the AT91RM9200-DK do not do this.
  *
  * - Likewise it must store the addresses in the correct byte order.
- *   MicroMonitor (uMon) on the CSB337 does this incorrectly (and
- *   continues to do so, for bug-compatibility).
  */
 
 static short __init unpack_mac_address(struct net_device *dev, unsigned int hi, unsigned int lo)
 {
 	char addr[6];
 
-	if (machine_is_csb337()) {
-		addr[5] = (lo & 0xff);			/* The CSB337 bootloader stores the MAC the wrong-way around */
-		addr[4] = (lo & 0xff00) >> 8;
-		addr[3] = (lo & 0xff0000) >> 16;
-		addr[2] = (lo & 0xff000000) >> 24;
-		addr[1] = (hi & 0xff);
-		addr[0] = (hi & 0xff00) >> 8;
-	}
-	else {
-		addr[0] = (lo & 0xff);
-		addr[1] = (lo & 0xff00) >> 8;
-		addr[2] = (lo & 0xff0000) >> 16;
-		addr[3] = (lo & 0xff000000) >> 24;
-		addr[4] = (hi & 0xff);
-		addr[5] = (hi & 0xff00) >> 8;
-	}
+	addr[0] = (lo & 0xff);
+	addr[1] = (lo & 0xff00) >> 8;
+	addr[2] = (lo & 0xff0000) >> 16;
+	addr[3] = (lo & 0xff000000) >> 24;
+	addr[4] = (hi & 0xff);
+	addr[5] = (hi & 0xff00) >> 8;
 
 	if (is_valid_ether_addr(addr)) {
 		memcpy(dev->dev_addr, &addr, 6);
-- 
1.7.12.4

  parent reply	other threads:[~2012-10-21 14:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-21 14:23 [PATCH 0/5] make cadence ethernet drivers build on any architecture Joachim Eastwood
2012-10-21 14:23 ` [PATCH 1/5] net/cadence: get rid of HAVE_NET_MACB Joachim Eastwood
2012-10-21 18:30   ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-21 20:26     ` Joachim Eastwood
2012-10-21 23:27   ` David Miller
2012-10-22  6:59     ` Joachim Eastwood
2012-10-22  7:10       ` David Miller
2012-10-21 14:23 ` [PATCH 2/5] net/at91_ether: select MACB in Kconfig Joachim Eastwood
2012-10-21 18:31   ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-21 20:27     ` Joachim Eastwood
2012-10-21 14:23 ` Joachim Eastwood [this message]
2012-10-21 18:25   ` [PATCH 3/5] net/at91_ether: move eth addr quirk into csb337 board setup Jean-Christophe PLAGNIOL-VILLARD
2012-10-21 20:39     ` Joachim Eastwood
2012-10-21 18:34   ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-21 20:30     ` Joachim Eastwood
2012-10-21 14:23 ` [PATCH 4/5] ARM: AT91: Remove HAVE_NET_MACB Joachim Eastwood
2012-10-21 14:23 ` [PATCH 5/5] AVR32: " Joachim Eastwood

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=1350829392-3812-4-git-send-email-manabian@gmail.com \
    --to=manabian@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).