All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <monstr@monstr.eu>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Michal Simek <monstr@monstr.eu>,
	Wendy Liang <wendy.liang@petalogix.com>,
	Nico Augustijn <Nico.Augustijn@Adeas.nl>,
	Anirudha Sarangi <anirudh@xilinx.com>,
	John Linn <John.Linn@xilinx.com>,
	Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 04/11] net: axienet: Additional MDIO clock functionality
Date: Thu,  4 Oct 2012 20:14:50 +0200	[thread overview]
Message-ID: <1349374497-9540-4-git-send-email-monstr@monstr.eu> (raw)
In-Reply-To: <1349374497-9540-1-git-send-email-monstr@monstr.eu>

The MDIO clock was previously hard coded and it is now
calculated thanks to a patch from the community.

Modify the Xilinx patch to get the clock frequency from
the connected AXI bus instead of the CPU.

Currently, the AXI ethernet mdio bus id is set as the mdio device node start
address, but the mdio node don't have a start address. Use the start address
of the AXI ethernet controller which connects to the MDIO bus instead.

Signed-off-by: Wendy Liang <wendy.liang@petalogix.com>
Signed-off-by: Nico Augustijn <Nico.Augustijn@Adeas.nl>
CC: Anirudha Sarangi <anirudh@xilinx.com>
CC: John Linn <John.Linn@xilinx.com>
CC: Grant Likely <grant.likely@secretlab.ca>
CC: Rob Herring <rob.herring@calxeda.com>
CC: David S. Miller <davem@davemloft.net>
---
 drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c |   76 +++++++++++----------
 1 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
index e90e1f4..49acc1e 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
@@ -128,11 +128,11 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
 int axienet_mdio_setup(struct axienet_local *lp, struct device_node *np)
 {
 	int ret;
-	u32 clk_div, host_clock;
-	u32 *property_p;
+	u32 clk_div;
 	struct mii_bus *bus;
 	struct resource res;
 	struct device_node *np1;
+	struct device_node *npp = 0; /* the ethernet controller device node */
 
 	/* clk_div can be calculated by deriving it from the equation:
 	 * fMDIO = fHOST / ((1 + clk_div) * 2)
@@ -158,41 +158,46 @@ int axienet_mdio_setup(struct axienet_local *lp, struct device_node *np)
 	 * fHOST can be read from the flattened device tree as property
 	 * "clock-frequency" from the CPU
 	 */
-
-	np1 = of_find_node_by_name(NULL, "cpu");
-	if (!np1) {
-		printk(KERN_WARNING "%s(): Could not find CPU device node.",
-		       __func__);
-		printk(KERN_WARNING "Setting MDIO clock divisor to "
-		       "default %d\n", DEFAULT_CLOCK_DIVISOR);
-		clk_div = DEFAULT_CLOCK_DIVISOR;
-		goto issue;
-	}
-	property_p = (u32 *) of_get_property(np1, "clock-frequency", NULL);
-	if (!property_p) {
-		printk(KERN_WARNING "%s(): Could not find CPU property: "
-		       "clock-frequency.", __func__);
-		printk(KERN_WARNING "Setting MDIO clock divisor to "
-		       "default %d\n", DEFAULT_CLOCK_DIVISOR);
+	np1 = of_get_parent(lp->phy_node);
+	if (np1)
+		npp = of_get_parent(np1);
+	if (!npp) {
+		dev_warn(lp->dev,
+			"Could not find ethernet controller device node.");
+		dev_warn(lp->dev, "Setting MDIO clock divisor to default %d\n",
+		       DEFAULT_CLOCK_DIVISOR);
 		clk_div = DEFAULT_CLOCK_DIVISOR;
-		goto issue;
+	} else {
+		u32 *property_p;
+
+		property_p = (uint32_t *)of_get_property(npp,
+						"clock-frequency", NULL);
+		if (!property_p) {
+			dev_warn(lp->dev, "Could not find clock ethernet " \
+						      "controller property.");
+			dev_warn(lp->dev,
+				 "Setting MDIO clock divisor to default %d\n",
+							DEFAULT_CLOCK_DIVISOR);
+			clk_div = DEFAULT_CLOCK_DIVISOR;
+		} else {
+			u32 host_clock = be32_to_cpup(property_p);
+
+			clk_div = (host_clock / (MAX_MDIO_FREQ * 2)) - 1;
+
+			/* If there is any remainder from the division of
+			 * fHOST / (MAX_MDIO_FREQ * 2), then we need to add 1
+			 * to the clock divisor or we will surely be
+			 * above 2.5 MHz */
+			if (host_clock % (MAX_MDIO_FREQ * 2))
+				clk_div++;
+			dev_dbg(lp->dev, "Setting MDIO clock divisor to %u " \
+						"based on %u Hz host clock.\n",
+						clk_div, host_clock);
+		}
 	}
 
-	host_clock = be32_to_cpup(property_p);
-	clk_div = (host_clock / (MAX_MDIO_FREQ * 2)) - 1;
-	/* If there is any remainder from the division of
-	 * fHOST / (MAX_MDIO_FREQ * 2), then we need to add
-	 * 1 to the clock divisor or we will surely be above 2.5 MHz */
-	if (host_clock % (MAX_MDIO_FREQ * 2))
-		clk_div++;
-
-	printk(KERN_DEBUG "%s(): Setting MDIO clock divisor to %u based "
-	       "on %u Hz host clock.\n", __func__, clk_div, host_clock);
-
-	of_node_put(np1);
-issue:
-	axienet_iow(lp, XAE_MDIO_MC_OFFSET,
-		    (((u32) clk_div) | XAE_MDIO_MC_MDIOEN_MASK));
+	axienet_iow(lp, XAE_MDIO_MC_OFFSET, (((u32)clk_div) |
+						XAE_MDIO_MC_MDIOEN_MASK));
 
 	ret = axienet_mdio_wait_until_ready(lp);
 	if (ret < 0)
@@ -202,8 +207,7 @@ issue:
 	if (!bus)
 		return -ENOMEM;
 
-	np1 = of_get_parent(lp->phy_node);
-	of_address_to_resource(np1, 0, &res);
+	of_address_to_resource(npp, 0, &res);
 	snprintf(bus->id, MII_BUS_ID_SIZE, "%.8llx",
 		 (unsigned long long) res.start);
 
-- 
1.7.0.4


  parent reply	other threads:[~2012-10-04 18:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-04 18:14 [PATCH 01/11] net: axienet: Remove NETIF_F_SG dropping for no checksum feature Michal Simek
2012-10-04 18:14 ` [PATCH 02/11] net: axienet: Add ioctl support Michal Simek
2012-10-04 19:17   ` Ben Hutchings
2012-10-05  5:54     ` Michal Simek
2012-10-04 18:14 ` [PATCH 03/11] net: axienet: Do not use NO_IRQ Michal Simek
2012-10-04 18:14 ` Michal Simek [this message]
2012-10-04 18:14 ` [PATCH 05/11] net: axienet: Enable VLAN support by default Michal Simek
2012-10-04 18:14 ` [PATCH 06/11] net: ll_temac: Fix mdio initialization Michal Simek
2012-10-04 18:14 ` [PATCH 07/11] net: ll_temac: Fix DMA map size bug Michal Simek
2012-10-04 18:14 ` [PATCH 08/11] net: ll_temac: Do not use fixed mtu size Michal Simek
2012-10-04 19:22   ` Ben Hutchings
2012-10-05  5:58     ` Michal Simek
2012-10-04 18:14 ` [PATCH 09/11] net: ll_temac: Move frag loading to frag loop Michal Simek
2012-10-04 18:14 ` [PATCH 10/11] net: ll_temac: Simplify xmit Michal Simek
2012-10-04 18:14 ` [PATCH 11/11] net: xilinx: Show csum in bootlog Michal Simek
2012-10-04 19:15   ` Ben Hutchings
2012-10-05  5:48     ` Michal Simek
2012-10-05 13:36       ` Ben Hutchings
2012-10-05  9:35     ` Michal Simek
2012-10-05 13:51       ` Ben Hutchings
2012-10-09  9:08         ` Michal Simek
2012-10-09 16:56           ` Ben Hutchings
2012-10-10 16:06             ` Michal Simek
2012-10-10 16:14               ` Ben Hutchings
2012-10-04 18:26 ` [PATCH 01/11] net: axienet: Remove NETIF_F_SG dropping for no checksum feature David Miller
2012-10-05  5:22   ` Michal Simek

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=1349374497-9540-4-git-send-email-monstr@monstr.eu \
    --to=monstr@monstr.eu \
    --cc=John.Linn@xilinx.com \
    --cc=Nico.Augustijn@Adeas.nl \
    --cc=anirudh@xilinx.com \
    --cc=davem@davemloft.net \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=wendy.liang@petalogix.com \
    /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.