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 2/4] macb: support higher rate GEM MDIO clock divisors
Date: Thu, 18 Aug 2011 14:32:17 +0100	[thread overview]
Message-ID: <1313674339-1834-3-git-send-email-fovsoft@gmail.com> (raw)
In-Reply-To: <1313674339-1834-1-git-send-email-fovsoft@gmail.com>

GEM devices support larger clock divisors and have a different
range of divisors.  Program the MDIO clock divisors based on the
device type.

Signed-off-by: Dave Aldridge <fovsoft@gmail.com>
---
 drivers/net/macb.c |   63 ++++++++++++++++++++++++++++++++++++++--------------
 drivers/net/macb.h |   12 ++++++++++
 2 files changed, 58 insertions(+), 17 deletions(-)

diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index d52dda0..fd99cdb 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -532,11 +532,52 @@ static int macb_write_hwaddr(struct eth_device *dev)
 	return 0;
 }
 
+static u32 gem_mdc_clk_div(int id)
+{
+	u32 ncfgr;
+	unsigned long pclk_hz = get_macb_pclk_rate(id);
+
+	if (pclk_hz <= 20000000)
+		ncfgr = GEM_BF(CLK, GEM_CLK_DIV8);
+	else if (pclk_hz <= 40000000)
+		ncfgr = GEM_BF(CLK, GEM_CLK_DIV16);
+	else if (pclk_hz <= 80000000)
+		ncfgr = GEM_BF(CLK, GEM_CLK_DIV32);
+	else if (pclk_hz <= 120000000)
+		ncfgr = GEM_BF(CLK, GEM_CLK_DIV48);
+	else if (pclk_hz <= 160000000)
+		ncfgr = GEM_BF(CLK, GEM_CLK_DIV64);
+	else
+		ncfgr = GEM_BF(CLK, GEM_CLK_DIV96);
+
+	return ncfgr;
+}
+
+static u32 macb_mdc_clk_div(struct macb_device *macb, int id)
+{
+	u32 ncfgr;
+	unsigned long pclk_hz;
+
+	if (macb->is_gem)
+		return gem_mdc_clk_div(id);
+
+	pclk_hz = get_macb_pclk_rate(id);
+	if (pclk_hz <= 20000000)
+		ncfgr = MACB_BF(CLK, MACB_CLK_DIV8);
+	else if (pclk_hz <= 40000000)
+		ncfgr = MACB_BF(CLK, MACB_CLK_DIV16);
+	else if (pclk_hz <= 80000000)
+		ncfgr = MACB_BF(CLK, MACB_CLK_DIV32);
+	else
+		ncfgr = MACB_BF(CLK, MACB_CLK_DIV64);
+
+	return ncfgr;
+}
+
 int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
 {
 	struct macb_device *macb;
 	struct eth_device *netdev;
-	unsigned long macb_hz;
 	u32 ncfgr;
 
 	macb = malloc(sizeof(struct macb_device));
@@ -567,26 +608,14 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
 	netdev->recv = macb_recv;
 	netdev->write_hwaddr = macb_write_hwaddr;
 
-	/*
-	 * Do some basic initialization so that we at least can talk
-	 * to the PHY
-	 */
-	macb_hz = get_macb_pclk_rate(id);
-	if (macb_hz < 20000000)
-		ncfgr = MACB_BF(CLK, MACB_CLK_DIV8);
-	else if (macb_hz < 40000000)
-		ncfgr = MACB_BF(CLK, MACB_CLK_DIV16);
-	else if (macb_hz < 80000000)
-		ncfgr = MACB_BF(CLK, MACB_CLK_DIV32);
-	else
-		ncfgr = MACB_BF(CLK, MACB_CLK_DIV64);
-
-	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;
 
+	/* Set MII management clock divider */
+	ncfgr = macb_mdc_clk_div(macb, id);
+	macb_writel(macb, NCFGR, ncfgr);
+
 	eth_register(netdev);
 
 #if defined(CONFIG_CMD_MII)
diff --git a/drivers/net/macb.h b/drivers/net/macb.h
index a2913f2..b08a057 100644
--- a/drivers/net/macb.h
+++ b/drivers/net/macb.h
@@ -147,6 +147,10 @@
 #define MACB_IRXFCS_OFFSET			19
 #define MACB_IRXFCS_SIZE			1
 
+/* GEM specific NCFGR bitfields. */
+#define GEM_CLK_OFFSET				18
+#define GEM_CLK_SIZE				3
+
 /* Bitfields in NSR */
 #define MACB_NSR_LINK_OFFSET			0
 #define MACB_NSR_LINK_SIZE			1
@@ -261,6 +265,14 @@
 #define MACB_CLK_DIV32				2
 #define MACB_CLK_DIV64				3
 
+/* GEM specific constants for CLK. */
+#define GEM_CLK_DIV8				0
+#define GEM_CLK_DIV16				1
+#define GEM_CLK_DIV32				2
+#define GEM_CLK_DIV48				3
+#define GEM_CLK_DIV64				4
+#define GEM_CLK_DIV96				5
+
 /* Constants for MAN register */
 #define MACB_MAN_SOF				1
 #define MACB_MAN_WRITE				1
-- 
1.7.3.4

  parent 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 ` [U-Boot] [PATCH 1/4] macb: initial support for Cadence GEM Dave Aldridge
2011-08-18 14:03   ` Andreas Bießmann
2011-08-18 15:26     ` Dave Aldridge
2011-10-06 21:50   ` Wolfgang Denk
2011-08-18 13:32 ` Dave Aldridge [this message]
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-3-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