public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Dave Aldridge <fovsoft@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/4] macb: initial support for Cadence GEM
Date: Thu, 18 Aug 2011 14:32:16 +0100	[thread overview]
Message-ID: <1313674339-1834-2-git-send-email-fovsoft@gmail.com> (raw)
In-Reply-To: <1313674339-1834-1-git-send-email-fovsoft@gmail.com>

The Cadence GEM is based on the MACB Ethernet controller but has a few
small changes with regards to register and bitfield placement.  This
patch detects the presence of a GEM by reading the module ID register
and setting a flag appropriately.

This handles the new HW address, USRIO and hash register base register
locations in GEM.

Signed-off-by: Dave Aldridge <fovsoft@gmail.com>
---
 drivers/net/macb.c |   18 +++++++++++-----
 drivers/net/macb.h |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index c63eea9..d52dda0 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -88,6 +88,7 @@ struct macb_dma_desc {
 
 struct macb_device {
 	void			*regs;
+        int                     is_gem;
 
 	unsigned int		rx_tail;
 	unsigned int		tx_head;
@@ -473,18 +474,19 @@ static int macb_init(struct eth_device *netdev, bd_t *bd)
 	defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
 	defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
 	defined(CONFIG_AT91SAM9XE)
-	macb_writel(macb, USRIO, MACB_BIT(RMII) | MACB_BIT(CLKEN));
+	macb_or_gem_writel(macb, USRIO, (MACB_BIT(RMII) |
+				         MACB_BIT(CLKEN)));
 #else
-	macb_writel(macb, USRIO, 0);
+	macb_or_gem_writel(macb, USRIO, 0);
 #endif
 #else
 #if	defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
 	defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
 	defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
 	defined(CONFIG_AT91SAM9XE)
-	macb_writel(macb, USRIO, MACB_BIT(CLKEN));
+	macb_or_gem_writel(macb, USRIO, MACB_BIT(CLKEN));
 #else
-	macb_writel(macb, USRIO, MACB_BIT(MII));
+	macb_or_gem_writel(macb, USRIO, MACB_BIT(MII));
 #endif
 #endif /* CONFIG_RMII */
 
@@ -524,9 +526,9 @@ static int macb_write_hwaddr(struct eth_device *dev)
 	/* set hardware address */
 	hwaddr_bottom = dev->enetaddr[0] | dev->enetaddr[1] << 8 |
 			dev->enetaddr[2] << 16 | dev->enetaddr[3] << 24;
-	macb_writel(macb, SA1B, hwaddr_bottom);
+	macb_or_gem_writel(macb, SA1B, hwaddr_bottom);
 	hwaddr_top = dev->enetaddr[4] | dev->enetaddr[5] << 8;
-	macb_writel(macb, SA1T, hwaddr_top);
+	macb_or_gem_writel(macb, SA1T, hwaddr_top);
 	return 0;
 }
 
@@ -581,6 +583,10 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
 
 	macb_writel(macb, NCFGR, ncfgr);
 
+	/* Cadence GEM has a module ID of 2. */
+	if (MACB_BFEXT(IDNUM, macb_readl(macb, MID)) == 0x2)
+		macb->is_gem = 1;
+
 	eth_register(netdev);
 
 #if defined(CONFIG_CMD_MII)
diff --git a/drivers/net/macb.h b/drivers/net/macb.h
index f92a20c..a2913f2 100644
--- a/drivers/net/macb.h
+++ b/drivers/net/macb.h
@@ -71,6 +71,15 @@
 #define MACB_TPQ				0x00bc
 #define MACB_USRIO				0x00c0
 #define MACB_WOL				0x00c4
+#define MACB_MID				0x00fc
+
+/* GEM register offsets. */
+#define GEM_NCFGR				0x0004
+#define GEM_USRIO				0x000c
+#define GEM_HRB					0x0080
+#define GEM_HRT					0x0084
+#define GEM_SA1B				0x0088
+#define GEM_SA1T				0x008C
 
 /* Bitfields in NCR */
 #define MACB_LB_OFFSET				0
@@ -240,6 +249,12 @@
 #define MACB_WOL_MTI_OFFSET			19
 #define MACB_WOL_MTI_SIZE			1
 
+/* Bitfields in MID */
+#define MACB_IDNUM_OFFSET			16
+#define MACB_IDNUM_SIZE				16
+#define MACB_REV_OFFSET				0
+#define MACB_REV_SIZE				16
+
 /* Constants for CLK */
 #define MACB_CLK_DIV8				0
 #define MACB_CLK_DIV16				1
@@ -266,10 +281,50 @@
 		    << MACB_##name##_OFFSET))		\
 	 | MACB_BF(name,value))
 
+#define GEM_BIT(name)					\
+	(1 << GEM_##name##_OFFSET)
+#define GEM_BF(name, value)				\
+	(((value) & ((1 << GEM_##name##_SIZE) - 1))	\
+	 << GEM_##name##_OFFSET)
+#define GEM_BFEXT(name, value)\
+	(((value) >> GEM_##name##_OFFSET)		\
+	 & ((1 << GEM_##name##_SIZE) - 1))
+#define GEM_BFINS(name, value, old)			\
+	(((old) & ~(((1 << GEM_##name##_SIZE) - 1)	\
+		    << GEM_##name##_OFFSET))		\
+	 | GEM_BF(name, value))
+
 /* Register access macros */
 #define macb_readl(port,reg)				\
 	readl((port)->regs + MACB_##reg)
 #define macb_writel(port,reg,value)			\
 	writel((value), (port)->regs + MACB_##reg)
+#define gem_readl(port, reg)				\
+	__raw_readl((port)->regs + GEM_##reg)
+#define gem_writel(port, reg, value)			\
+	__raw_writel((value), (port)->regs + GEM_##reg)
+
+/*
+ * Conditional GEM/MACB macros.  These perform the operation to the correct
+ * register dependent on whether the device is a GEM or a MACB.  For registers
+ * and bitfields that are common across both devices, use macb_{read,write}l
+ * to avoid the cost of the conditional.
+ */
+#define macb_or_gem_writel(__macb, __reg, __value) \
+	({ \
+		if ((__macb)->is_gem) \
+			gem_writel((__macb), __reg, __value); \
+		else \
+			macb_writel((__macb), __reg, __value); \
+	})
 
+#define macb_or_gem_readl(__macb, __reg) \
+	({ \
+		u32 __v; \
+		if ((__macb)->is_gem) \
+			__v = gem_readl((__macb), __reg); \
+		else \
+			__v = macb_readl((__macb), __reg); \
+		__v; \
+	})
 #endif /* __DRIVERS_MACB_H__ */
-- 
1.7.3.4

  reply	other threads:[~2011-08-18 13:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-18 13:32 [U-Boot] [PATCH 0/4] Add Cadence GEM support to macb Ethernet driver Dave Aldridge
2011-08-18 13:32 ` Dave Aldridge [this message]
2011-08-18 14:03   ` [U-Boot] [PATCH 1/4] macb: initial support for Cadence GEM Andreas Bießmann
2011-08-18 15:26     ` Dave Aldridge
2011-10-06 21:50   ` Wolfgang Denk
2011-08-18 13:32 ` [U-Boot] [PATCH 2/4] macb: support higher rate GEM MDIO clock divisors Dave Aldridge
2011-08-18 13:32 ` [U-Boot] [PATCH 3/4] macb: support DMA bus widths > 32 bits Dave Aldridge
2011-08-18 13:32 ` [U-Boot] [PATCH 4/4] macb: allow GEM to have configurable receive buffer size Dave Aldridge

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=1313674339-1834-2-git-send-email-fovsoft@gmail.com \
    --to=fovsoft@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox