Skip to contentSkip to conversation

net/fec: add dual fec support for i.MX28

PATCH Superseded Shawn Guo 4 participants 55 messages Dec 28, 2010 – Jan 1, 2011

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

cover net/fec: add dual fec support for i.MX28

This patch series is to add dual fec support for mx28, which is a mxs-based soc. Some code changes related to the following commits are also made in this patch set for some reasons.

e6b043d512fa8d9a3801bf5d72bfa3b8fc3b3cc8
netdev/fec.c: add phylib supporting to enable carrier detection (v2)

e3fe8558c7fc182972c3d947d88744482111f304
net/fec: fix pm to survive to suspend/resume

Also I do not understand one line change made in commit below.

commit 6fcc040f02d281c7e9563127358a77ce2bbfe284
net: allow FEC driver to use fixed PHY support

- snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
+ snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id + 1);

Can someone help me understand if it's really needed? The patch set can work with this change, and I'm just curious.

It's been tested on mx28 evk and mx51 babbage. For mx28, it has to work against the following patch set, which has not got merged yet.

[PATCH v8 00/15] ARM: mxs: Add initial support for MX23 and MX28

Thanks for review.

Regards,
Shawn

Shawn Guo (10):

 arch/arm/mach-mxs/Makefile                      |    2 +-
 arch/arm/mach-mxs/clock-mx28.c                  |    7 +-
 arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
 arch/arm/mach-mxs/include/mach/common.h         |    1 +
 arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c                |   59 ++++++-
 arch/arm/mach-mxs/ocotp.c                       |   52 ++++++
 arch/arm/mach-mxs/pm.c                          |   44 +++++
 drivers/net/Kconfig                             |    7 +-
 drivers/net/fec.c                               |  220 +++++++++++++++++------
 drivers/net/fec.h                               |    5 +-
 include/linux/fec.h                             |    2 +
 12 files changed, 335 insertions(+), 68 deletions(-)

[PATCH 01/10] net/fec: fix MMFR_OP type in fec_enet_mdio_write
[PATCH 02/10] net/fec: remove the use of "index" which is legacy [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac [PATCH 04/10] net/fec: improve pm for better suspend/resume
[PATCH 05/10] net/fec: add dual fec support for mx28
[PATCH 06/10] ARM: mx28: update clocks for dual fec support
[PATCH 07/10] ARM: mx28: add the second fec device registration [PATCH 08/10] ARM: mxs: add ocotp read function
[PATCH 09/10] ARM: mx28: read fec mac address from ocotp
[PATCH 10/10] ARM: mxs: add initial pm support

author
#1 lore raw

PATCH 1/10 net/fec: fix MMFR_OP type in fec_enet_mdio_write

FEC_MMFR_OP_WRITE should be used than FEC_MMFR_OP_READ in a mdio write operation.

It's probably a typo introduced by commit:

e6b043d512fa8d9a3801bf5d72bfa3b8fc3b3cc8
netdev/fec.c: add phylib supporting to enable carrier detection (v2)

---
 drivers/net/fec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/fec.c +2 -2
index cce32d4..52e9ca8 100644
@@ -651,8 +651,8 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	fep->mii_timeout = 0;
 	init_completion(&fep->mdio_done);
 
-	/* start a read op */
-	writel(FEC_MMFR_ST | FEC_MMFR_OP_READ |
+	/* start a write op */
+	writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE |
 		FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
 		FEC_MMFR_TA | FEC_MMFR_DATA(value),
 		fep->hwp + FEC_MII_DATA);
Signature · 1 line
1.7.1
author
#2 lore raw

PATCH 2/10 net/fec: remove the use of "index" which is legacy

In reply to Shawn Guo

The "index" becomes legacy since fep->pdev->id starts working to identify the instance.

Moreover, the call of fec_enet_init(ndev, 0) always passes 0 to fep->index. This makes the following code in fec_get_mac buggy.

	/* Adjust MAC if using default MAC address */
	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;

It may be the time to remove "index" and use fep->pdev->id instead.

---
 drivers/net/fec.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
drivers/net/fec.c +3 -6
index 52e9ca8..47f6b3b 100644
@@ -186,7 +186,6 @@ struct fec_enet_private {
 	int     mii_timeout;
 	uint    phy_speed;
 	phy_interface_t	phy_interface;
-	int	index;
 	int	link;
 	int	full_duplex;
 	struct	completion mdio_done;
@@ -566,7 +565,7 @@ static void __inline__ fec_get_mac(struct net_device *dev)
 
 	/* Adjust MAC if using default MAC address */
 	if (iap == fec_mac_default)
-		 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
+		 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
 }
 #endif
 
@@ -1067,9 +1066,8 @@ static const struct net_device_ops fec_netdev_ops = {
  /*
   * XXX:  We need to clean up on failure exits here.
   *
-  * index is only used in legacy code
   */
-static int fec_enet_init(struct net_device *dev, int index)
+static int fec_enet_init(struct net_device *dev)
 {
 	struct fec_enet_private *fep = netdev_priv(dev);
 	struct bufdesc *cbd_base;
@@ -1086,7 +1084,6 @@ static int fec_enet_init(struct net_device *dev, int index)
 
 	spin_lock_init(&fep->hw_lock);
 
-	fep->index = index;
 	fep->hwp = (void __iomem *)dev->base_addr;
 	fep->netdev = dev;
 
@@ -1316,7 +1313,7 @@ fec_probe(struct platform_device *pdev)
 	}
 	clk_enable(fep->clk);
 
-	ret = fec_enet_init(ndev, 0);
+	ret = fec_enet_init(ndev);
 	if (ret)
 		goto failed_init;
 
Signature · 1 line
1.7.1
author
#3 lore raw

PATCH 3/10 net/fec: add mac field into platform data and consolidate fec_get_mac

In reply to Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

1) kernel command line fec_mac=xx:xx:xx...
2) from flash in case of CONFIG_M5272 or fec_platform_data mac field for others, which typically have mac stored in fuse
3) fec mac address registers set by bootloader

---
 drivers/net/fec.c   |   90 ++++++++++++++++++++++++++++----------------------
 include/linux/fec.h |    2 +
 2 files changed, 52 insertions(+), 40 deletions(-)
drivers/net/fec.c +50 -40
index 47f6b3b..cd59814 100644
@@ -59,15 +59,9 @@
 #define FEC_ALIGNMENT	0x3
 #endif
 
-/*
- * Define the fixed address of the FEC hardware.
- */
-#if defined(CONFIG_M5272)
-
-static unsigned char	fec_mac_default[] = {
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-};
+static unsigned char fec_mac_default[ETH_ALEN];
 
+#if defined(CONFIG_M5272)
 /*
  * Some hardware gets it MAC address out of local flash memory.
  * if this is non-zero then assume it is the address to get MAC from.
@@ -537,27 +531,40 @@ rx_processing_done:
 }
 
 /* ------------------------------------------------------------------------- */
-#ifdef CONFIG_M5272
 static void __inline__ fec_get_mac(struct net_device *dev)
 {
 	struct fec_enet_private *fep = netdev_priv(dev);
+	struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
 	unsigned char *iap, tmpaddr[ETH_ALEN];
 
-	if (FEC_FLASHMAC) {
-		/*
-		 * Get MAC address from FLASH.
-		 * If it is all 1's or 0's, use the default.
-		 */
-		iap = (unsigned char *)FEC_FLASHMAC;
-		if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
-		    (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
-			iap = fec_mac_default;
-		if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
-		    (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
-			iap = fec_mac_default;
-	} else {
-		*((unsigned long *) &tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW);
-		*((unsigned short *) &tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */
+	if (!is_valid_ether_addr(iap)) {
+#ifdef CONFIG_M5272
+		if (FEC_FLASHMAC)
+			iap = (unsigned char *)FEC_FLASHMAC;
+#else
+		if (pdata)
+			memcpy(iap, pdata->mac, ETH_ALEN);
+#endif
+	}
+
+	/*
+	 * 3) FEC mac registers set by bootloader
+	 */
+	if (!is_valid_ether_addr(iap)) {
+		*((unsigned long *) &tmpaddr[0]) =
+			be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
+		*((unsigned short *) &tmpaddr[4]) =
+			be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
 		iap = &tmpaddr[0];
 	}
 
@@ -567,7 +574,6 @@ static void __inline__ fec_get_mac(struct net_device *dev)
 	if (iap == fec_mac_default)
 		 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
 }
-#endif
 
 /* ------------------------------------------------------------------------- */
 
@@ -1063,6 +1069,24 @@ static const struct net_device_ops fec_netdev_ops = {
 	.ndo_do_ioctl           = fec_enet_ioctl,
 };
 
+static int __init fec_mac_addr_setup(char *mac_addr)
+{
+	int i;
+	unsigned int tmp;
+
+	for (i = 0; i < ETH_ALEN; i++) {
+		if (sscanf(mac_addr + 3*i, "%2x", &tmp) != 1) {
+			printk(KERN_WARNING "Malformed fec mac address\n");
+			return 0;
+		}
+		fec_mac_default[i] = tmp;
+	}
+
+	return 1;
+}
+
+__setup("fec_mac=", fec_mac_addr_setup);
+
  /*
   * XXX:  We need to clean up on failure exits here.
   *
@@ -1087,22 +1111,8 @@ static int fec_enet_init(struct net_device *dev)
 	fep->hwp = (void __iomem *)dev->base_addr;
 	fep->netdev = dev;
 
-	/* Set the Ethernet address */
-#ifdef CONFIG_M5272
+	/* Get the Ethernet address */
 	fec_get_mac(dev);
-#else
-	{
-		unsigned long l;
-		l = readl(fep->hwp + FEC_ADDR_LOW);
-		dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24);
-		dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16);
-		dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8);
-		dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0);
-		l = readl(fep->hwp + FEC_ADDR_HIGH);
-		dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24);
-		dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16);
-	}
-#endif
 
 	/* Set receive and transmit descriptor base. */
 	fep->rx_bd_base = cbd_base;
include/linux/fec.h +2 -0
index 5d3523d..bf0c69f 100644
@@ -1,6 +1,7 @@
 /* include/linux/fec.h
  *
  * Copyright (c) 2009 Orex Computed Radiography
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
  *   Baruch Siach <[email protected]>
  *
  * Header file for the FEC platform data
@@ -16,6 +17,7 @@
 
 struct fec_platform_data {
 	phy_interface_t phy;
+	unsigned char mac[ETH_ALEN];
 };
 
 #endif
Signature · 1 line
1.7.1
#4 lore raw

PATCH 3/10 net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Shawn,

Quoted 6 lines · Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

1) kernel command line fec_mac=xx:xx:xx...
2) from flash in case of CONFIG_M5272 or fec_platform_data mac field for others, which typically have mac stored in fuse

Looking at this we can move that 5272 specific code into its arch code with these changes. I can do that later if you don't want to do it in this series.

Regards
Greg

Quoted 164 lines

3) fec mac address registers set by bootloader

---
  drivers/net/fec.c   |   90 ++++++++++++++++++++++++++++----------------------
  include/linux/fec.h |    2 +
  2 files changed, 52 insertions(+), 40 deletions(-)
drivers/net/fec.c +50 -40
index 47f6b3b..cd59814 100644
@@ -59,15 +59,9 @@
  #define FEC_ALIGNMENT	0x3
  #endif
 
-/*
- * Define the fixed address of the FEC hardware.
- */
-#if defined(CONFIG_M5272)
-
-static unsigned char	fec_mac_default[] = {
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-};
+static unsigned char fec_mac_default[ETH_ALEN];
 
+#if defined(CONFIG_M5272)
  /*
   * Some hardware gets it MAC address out of local flash memory.
   * if this is non-zero then assume it is the address to get MAC from.
@@ -537,27 +531,40 @@ rx_processing_done:
  }
 
  /* ------------------------------------------------------------------------- */
-#ifdef CONFIG_M5272
  static void __inline__ fec_get_mac(struct net_device *dev)
  {
  	struct fec_enet_private *fep = netdev_priv(dev);
+	struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
  	unsigned char *iap, tmpaddr[ETH_ALEN];
 
-	if (FEC_FLASHMAC) {
-		/*
-		 * Get MAC address from FLASH.
-		 * If it is all 1's or 0's, use the default.
-		 */
-		iap = (unsigned char *)FEC_FLASHMAC;
-		if ((iap[0] == 0)&&  (iap[1] == 0)&&  (iap[2] == 0)&&
-		    (iap[3] == 0)&&  (iap[4] == 0)&&  (iap[5] == 0))
-			iap = fec_mac_default;
-		if ((iap[0] == 0xff)&&  (iap[1] == 0xff)&&  (iap[2] == 0xff)&&
-		    (iap[3] == 0xff)&&  (iap[4] == 0xff)&&  (iap[5] == 0xff))
-			iap = fec_mac_default;
-	} else {
-		*((unsigned long *)&tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW);
-		*((unsigned short *)&tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH)>>  16);
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */
+	if (!is_valid_ether_addr(iap)) {
+#ifdef CONFIG_M5272
+		if (FEC_FLASHMAC)
+			iap = (unsigned char *)FEC_FLASHMAC;
+#else
+		if (pdata)
+			memcpy(iap, pdata->mac, ETH_ALEN);
+#endif
+	}
+
+	/*
+	 * 3) FEC mac registers set by bootloader
+	 */
+	if (!is_valid_ether_addr(iap)) {
+		*((unsigned long *)&tmpaddr[0]) =
+			be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
+		*((unsigned short *)&tmpaddr[4]) =
+			be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH)>>  16);
  		iap =&tmpaddr[0];
  	}
 
@@ -567,7 +574,6 @@ static void __inline__ fec_get_mac(struct net_device *dev)
  	if (iap == fec_mac_default)
  		 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
  }
-#endif
 
  /* ------------------------------------------------------------------------- */
 
@@ -1063,6 +1069,24 @@ static const struct net_device_ops fec_netdev_ops = {
  	.ndo_do_ioctl           = fec_enet_ioctl,
  };
 
+static int __init fec_mac_addr_setup(char *mac_addr)
+{
+	int i;
+	unsigned int tmp;
+
+	for (i = 0; i<  ETH_ALEN; i++) {
+		if (sscanf(mac_addr + 3*i, "%2x",&tmp) != 1) {
+			printk(KERN_WARNING "Malformed fec mac address\n");
+			return 0;
+		}
+		fec_mac_default[i] = tmp;
+	}
+
+	return 1;
+}
+
+__setup("fec_mac=", fec_mac_addr_setup);
+
   /*
    * XXX:  We need to clean up on failure exits here.
    *
@@ -1087,22 +1111,8 @@ static int fec_enet_init(struct net_device *dev)
  	fep->hwp = (void __iomem *)dev->base_addr;
  	fep->netdev = dev;
 
-	/* Set the Ethernet address */
-#ifdef CONFIG_M5272
+	/* Get the Ethernet address */
  	fec_get_mac(dev);
-#else
-	{
-		unsigned long l;
-		l = readl(fep->hwp + FEC_ADDR_LOW);
-		dev->dev_addr[0] = (unsigned char)((l&  0xFF000000)>>  24);
-		dev->dev_addr[1] = (unsigned char)((l&  0x00FF0000)>>  16);
-		dev->dev_addr[2] = (unsigned char)((l&  0x0000FF00)>>  8);
-		dev->dev_addr[3] = (unsigned char)((l&  0x000000FF)>>  0);
-		l = readl(fep->hwp + FEC_ADDR_HIGH);
-		dev->dev_addr[4] = (unsigned char)((l&  0xFF000000)>>  24);
-		dev->dev_addr[5] = (unsigned char)((l&  0x00FF0000)>>  16);
-	}
-#endif
 
  	/* Set receive and transmit descriptor base. */
  	fep->rx_bd_base = cbd_base;
include/linux/fec.h +2 -0
index 5d3523d..bf0c69f 100644
@@ -1,6 +1,7 @@
  /* include/linux/fec.h
   *
   * Copyright (c) 2009 Orex Computed Radiography
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
   *   Baruch Siach<[email protected]>
   *
   * Header file for the FEC platform data
@@ -16,6 +17,7 @@
 
  struct fec_platform_data {
  	phy_interface_t phy;
+	unsigned char mac[ETH_ALEN];
  };
 
  #endif
Signature · 5 lines
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     gerg at snapgear.com
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com
author
#5 lore raw

PATCH 3/10 net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Greg,

Quoted 6 lines · Greg Ungerer

Hi Shawn,

Quoted 3 lines · Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

Quoted 8 lines
Quoted 3 lines

1) kernel command line fec_mac=xx:xx:xx...
2) from flash in case of CONFIG_M5272 or fec_platform_data mac field for others, which typically have mac stored in fuse

Looking at this we can move that 5272 specific code into its arch code with these changes. I can do that later if you don't want to do it in this series.

It would be great if you can do that, since I do not have the the platform to test anyway.

Signature · 2 lines
Regards,
Shawn
#6 lore raw

PATCH 3/10 net/fec: add mac field into platform data and consolidate fec_get_mac

In reply to Shawn Guo

Hi Shawn,

Please add netdev at vger.kernel.org to the Cc of all your fec driver patches.

Quoted 4 lines · Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

1) kernel command line fec_mac=xx:xx:xx...

In the case of dual MAC that you later add support for, the address which one is being set? Is there a way to set both in kernel command line?

Also, instead of inventing another kernel command line parameter, it is better IMO to use the module parameters mechanism. The greth NIC driver already uses this method for setting MAC address. Look for 'macaddr' in drivers/net/greth.c, and the explanation at the beginning of Documentation/kernel-parameters.txt.

Quoted 58 lines

2) from flash in case of CONFIG_M5272 or fec_platform_data mac field for others, which typically have mac stored in fuse
3) fec mac address registers set by bootloader

---
 drivers/net/fec.c   |   90 ++++++++++++++++++++++++++++----------------------
 include/linux/fec.h |    2 +
 2 files changed, 52 insertions(+), 40 deletions(-)
drivers/net/fec.c +3 -24
index 47f6b3b..cd59814 100644
@@ -59,15 +59,9 @@
 #define FEC_ALIGNMENT	0x3
 #endif
 
-/*
- * Define the fixed address of the FEC hardware.
- */
-#if defined(CONFIG_M5272)
-
-static unsigned char	fec_mac_default[] = {
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-};
+static unsigned char fec_mac_default[ETH_ALEN];
 
+#if defined(CONFIG_M5272)
 /*
  * Some hardware gets it MAC address out of local flash memory.
  * if this is non-zero then assume it is the address to get MAC from.
@@ -537,27 +531,40 @@ rx_processing_done:
 }
 
 /* ------------------------------------------------------------------------- */
-#ifdef CONFIG_M5272
 static void __inline__ fec_get_mac(struct net_device *dev)
 {
 	struct fec_enet_private *fep = netdev_priv(dev);
+	struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
 	unsigned char *iap, tmpaddr[ETH_ALEN];
 
-	if (FEC_FLASHMAC) {
-		/*
-		 * Get MAC address from FLASH.
-		 * If it is all 1's or 0's, use the default.
-		 */
-		iap = (unsigned char *)FEC_FLASHMAC;
-		if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
-		    (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
-			iap = fec_mac_default;
-		if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
-		    (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
-			iap = fec_mac_default;
-	} else {
-		*((unsigned long *) &tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW);
-		*((unsigned short *) &tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH) >> 16);

drivers/net/fec.c rx_processing_done: · line 549

Quoted 10 lines
drivers/net/fec.c +10 -0
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */

Again, how do you handle the dual MAC case?

Quoted 83 lines
drivers/net/fec.c +37 -16
+	if (!is_valid_ether_addr(iap)) {
+#ifdef CONFIG_M5272
+		if (FEC_FLASHMAC)
+			iap = (unsigned char *)FEC_FLASHMAC;
+#else
+		if (pdata)
+			memcpy(iap, pdata->mac, ETH_ALEN);
+#endif
+	}
+
+	/*
+	 * 3) FEC mac registers set by bootloader
+	 */
+	if (!is_valid_ether_addr(iap)) {
+		*((unsigned long *) &tmpaddr[0]) =
+			be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
+		*((unsigned short *) &tmpaddr[4]) =
+			be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
 		iap = &tmpaddr[0];
 	}
 
@@ -567,7 +574,6 @@ static void __inline__ fec_get_mac(struct net_device *dev)
 	if (iap == fec_mac_default)
 		 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
 }
-#endif
 
 /* ------------------------------------------------------------------------- */
 
@@ -1063,6 +1069,24 @@ static const struct net_device_ops fec_netdev_ops = {
 	.ndo_do_ioctl           = fec_enet_ioctl,
 };
 
+static int __init fec_mac_addr_setup(char *mac_addr)
+{
+	int i;
+	unsigned int tmp;
+
+	for (i = 0; i < ETH_ALEN; i++) {
+		if (sscanf(mac_addr + 3*i, "%2x", &tmp) != 1) {
+			printk(KERN_WARNING "Malformed fec mac address\n");
+			return 0;
+		}
+		fec_mac_default[i] = tmp;
+	}
+
+	return 1;
+}
+
+__setup("fec_mac=", fec_mac_addr_setup);
+
  /*
   * XXX:  We need to clean up on failure exits here.
   *
@@ -1087,22 +1111,8 @@ static int fec_enet_init(struct net_device *dev)
 	fep->hwp = (void __iomem *)dev->base_addr;
 	fep->netdev = dev;
 
-	/* Set the Ethernet address */
-#ifdef CONFIG_M5272
+	/* Get the Ethernet address */
 	fec_get_mac(dev);
-#else
-	{
-		unsigned long l;
-		l = readl(fep->hwp + FEC_ADDR_LOW);
-		dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24);
-		dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16);
-		dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8);
-		dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0);
-		l = readl(fep->hwp + FEC_ADDR_HIGH);
-		dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24);
-		dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16);
-	}
-#endif
 
 	/* Set receive and transmit descriptor base. */
 	fep->rx_bd_base = cbd_base;
include/linux/fec.h +0 -0
index 5d3523d..bf0c69f 100644

include/linux/fec.h line 5

Quoted 5 lines
include/linux/fec.h +1 -0
@@ -1,6 +1,7 @@
 /* include/linux/fec.h
  *
  * Copyright (c) 2009 Orex Computed Radiography
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
  *   Baruch Siach <[email protected]>

This breaks the original copyright notice. Please move the Freescale copyright notice below the original one.

include/linux/fec.h line 23

Quoted 10 lines
include/linux/fec.h +1 -0
  *
  * Header file for the FEC platform data
@@ -16,6 +17,7 @@
 
 struct fec_platform_data {
 	phy_interface_t phy;
+	unsigned char mac[ETH_ALEN];
 };
 
 #endif

baruch

Signature · 3 lines
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
author
#7 lore raw

PATCH 3/10 net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Baruch,

Quoted 4 lines · Baruch Siach

Hi Shawn,

Please add netdev at vger.kernel.org to the Cc of all your fec driver patches.

Quoted 9 lines
Quoted 4 lines · Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

1) kernel command line fec_mac=xx:xx:xx...

In the case of dual MAC that you later add support for, the address which one is being set? Is there a way to set both in kernel command line?

The fec0 gets fec_mac and fec1 gets fec_mac + 1. The following code in function fec_get_mac takes care of it.

	/* Adjust MAC if using default MAC address */
	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
Quoted 6 lines

Also, instead of inventing another kernel command line parameter, it is better IMO to use the module parameters mechanism. The greth NIC driver already uses this method for setting MAC address. Look for 'macaddr' in drivers/net/greth.c, and the explanation at the beginning of Documentation/kernel-parameters.txt.

Sounds good. Thanks.

[...]

Quoted 4 lines
Quoted 4 lines
drivers/net/fec.c +4 -0
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
Quoted 9 lines

drivers/net/fec.c rx_processing_done: · line 549

Quoted 6 lines
drivers/net/fec.c +6 -0
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */

Again, how do you handle the dual MAC case?

See above, please.

[...]

Quoted 10 lines

include/linux/fec.h line 5

Quoted 6 lines
include/linux/fec.h +1 -0
@@ -1,6 +1,7 @@
 /* include/linux/fec.h
  *
  * Copyright (c) 2009 Orex Computed Radiography
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
  *   Baruch Siach <[email protected]>

This breaks the original copyright notice. Please move the Freescale copyright notice below the original one.

Sorry. Will fix it.

Signature · 2 lines
Regards,
Shawn
#8 lore raw

PATCH 3/10 net/fec: add mac field into platform data and consolidate fec_get_mac

Hello Shawn,

Quoted 9 lines · Shawn Guo
Quoted 4 lines · Baruch Siach

Hi Shawn,
In the case of dual MAC that you later add support for, the address which one is being set? Is there a way to set both in kernel command line?

The fec0 gets fec_mac and fec1 gets fec_mac + 1. The following code in function fec_get_mac takes care of it.

	/* Adjust MAC if using default MAC address */

default MAC address means the address passed via cmdline? Sounds confusing to me.

Quoted 2 lines
	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;

Can this overflow? (I didn't check the code, so my concern might be completely stupid here.)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#9 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Uwe,

Quoted 8 lines · Uwe Kleine-König

Hello Shawn,

Quoted 5 lines · Shawn Guo
Quoted 4 lines · Baruch Siach

Hi Shawn,
In the case of dual MAC that you later add support for, the address which one is being set? Is there a way to set both in kernel command line?

Quoted 6 lines
Quoted 4 lines

The fec0 gets fec_mac and fec1 gets fec_mac + 1. The following code in function fec_get_mac takes care of it.

	/* Adjust MAC if using default MAC address */

default MAC address means the address passed via cmdline? Sounds confusing to me.

Will change the comment and fec_mac_default name to address the concern.

Quoted 5 lines
Quoted 3 lines
	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;

Can this overflow? (I didn't check the code, so my concern might be completely stupid here.)

No. dev->dev_addr points to netdev_hw_addr->addr, which is a 32 bytes array.

Signature · 2 lines
Regards,
Shawn
#10 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hello Shawn,

Quoted 8 lines · Shawn Guo
Quoted 6 lines · Uwe Kleine-K?nig
Quoted 3 lines · Shawn Guo

On Wed, Dec 29, 2010 at 08:53:30AM +0200, Baruch Siach wrote:

	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;

Can this overflow? (I didn't check the code, so my concern might be completely stupid here.)

No. dev->dev_addr points to netdev_hw_addr->addr, which is a 32 bytes array.

I didn't mean an out-of-bound access, but what is if fec_mac_default[ETH_ALEN-1] is 0xff and you add 1? Does that result in 0x100 or 0? What if id is <0? For big ids you might even handle a carry to indixes <ETH_ALEN-2.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#11 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Uwe,

Quoted 8 lines · Uwe Kleine-König

Hello Shawn,

Quoted 5 lines · Shawn Guo
Quoted 4 lines · Uwe Kleine-König
Quoted 3 lines · Shawn Guo

On Wed, Dec 29, 2010 at 08:53:30AM +0200, Baruch Siach wrote:

	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Can this overflow? (I didn't check the code, so my concern might be completely stupid here.)

No. dev->dev_addr points to netdev_hw_addr->addr, which is a 32 bytes array.

I didn't mean an out-of-bound access, but what is if fec_mac_default[ETH_ALEN-1] is 0xff and you add 1? Does that result in 0x100 or 0? What if id is <0? For big ids you might even handle a carry to indixes <ETH_ALEN-2.

First of all, all my patch did is changing fep->index to, fep->pdev->id, which should not bring any problem you are concerned.

Secondly, I do not understand how the overflow on fec_mac_default[ETH_ALEN-1] can result in a carry on the next array element. Here is what I'm seeing with fec_mac=00:04:9f:01:30:ff.

eth0      Link encap:Ethernet  HWaddr 00:04:9F:01:30:FF
eth1      Link encap:Ethernet  HWaddr 00:04:9F:01:30:00
Signature · 2 lines
Regards,
Shawn
#12 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hello Shawn,

Quoted 15 lines · Shawn Guo
Quoted 6 lines · Uwe Kleine-K?nig
Quoted 5 lines · Shawn Guo
Quoted 4 lines · Uwe Kleine-K?nig
Quoted 3 lines · Shawn Guo

On Wed, Dec 29, 2010 at 08:53:30AM +0200, Baruch Siach wrote:

	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Can this overflow? (I didn't check the code, so my concern might be completely stupid here.)

No. dev->dev_addr points to netdev_hw_addr->addr, which is a 32 bytes array.

I didn't mean an out-of-bound access, but what is if fec_mac_default[ETH_ALEN-1] is 0xff and you add 1? Does that result in 0x100 or 0? What if id is <0? For big ids you might even handle a carry to indixes <ETH_ALEN-2.

Quoted 6 lines

First of all, all my patch did is changing fep->index to, fep->pdev->id, which should not bring any problem you are concerned.

Secondly, I do not understand how the overflow on fec_mac_default[ETH_ALEN-1] can result in a carry on the next array element. Here is what I'm seeing with fec_mac=00:04:9f:01:30:ff.

There is no automatic carry to the next array element. I just wondered how overflow should be handled ...

Quoted 2 lines
eth0      Link encap:Ethernet  HWaddr 00:04:9F:01:30:FF
eth1      Link encap:Ethernet  HWaddr 00:04:9F:01:30:00

If this is intended, it's totally OK for me.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#13 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

In reply to Shawn Guo

Hi Baruch,

Quoted 24 lines · Shawn Guo

Hi Baruch,

Quoted 4 lines · Baruch Siach

Hi Shawn,

Please add [email protected] to the Cc of all your fec driver patches.

Quoted 9 lines
Quoted 4 lines · Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

1) kernel command line fec_mac=xx:xx:xx...

In the case of dual MAC that you later add support for, the address which one is being set? Is there a way to set both in kernel command line?

The fec0 gets fec_mac and fec1 gets fec_mac + 1. The following code in function fec_get_mac takes care of it.

	/* Adjust MAC if using default MAC address */
	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
Quoted 8 lines
Quoted 6 lines

Also, instead of inventing another kernel command line parameter, it is better IMO to use the module parameters mechanism. The greth NIC driver already uses this method for setting MAC address. Look for 'macaddr' in drivers/net/greth.c, and the explanation at the beginning of Documentation/kernel-parameters.txt.

Sounds good. Thanks.

I just thought this over again. Module parameter might not be the best here. fec is usually used to mount nfs during boot, which requires a built-in driver other than module.

Signature · 2 lines
Regards,
Shawn
#14 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Shawn,

Quoted 26 lines · Shawn Guo
Quoted 25 lines · Shawn Guo
Quoted 12 lines · Baruch Siach

Please add netdev at vger.kernel.org to the Cc of all your fec driver patches.

Quoted 4 lines · Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

1) kernel command line fec_mac=xx:xx:xx...

In the case of dual MAC that you later add support for, the address which one is being set? Is there a way to set both in kernel command line?

The fec0 gets fec_mac and fec1 gets fec_mac + 1. The following code in function fec_get_mac takes care of it.

	/* Adjust MAC if using default MAC address */
	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
Quoted 6 lines

Also, instead of inventing another kernel command line parameter, it is better IMO to use the module parameters mechanism. The greth NIC driver already uses this method for setting MAC address. Look for 'macaddr' in drivers/net/greth.c, and the explanation at the beginning of Documentation/kernel-parameters.txt.

Quoted 5 lines
Quoted 2 lines

Sounds good. Thanks.

I just thought this over again. Module parameter might not be the best here. fec is usually used to mount nfs during boot, which requires a built-in driver other than module.

See the explanation at the beginning of Documentation/kernel-parameters.txt. You can give module parameters at the kernel command line.

baruch

Signature · 3 lines
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
author
#15 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Quoted 29 lines · Baruch Siach

Hi Shawn,

Quoted 26 lines · Shawn Guo
Quoted 25 lines · Shawn Guo
Quoted 12 lines · Baruch Siach

Please add [email protected] to the Cc of all your fec driver patches.

Quoted 4 lines · Shawn Guo

Add mac field into fec_platform_data and consolidate function fec_get_mac to get mac address in following order.

1) kernel command line fec_mac=xx:xx:xx...

In the case of dual MAC that you later add support for, the address which one is being set? Is there a way to set both in kernel command line?

The fec0 gets fec_mac and fec1 gets fec_mac + 1. The following code in function fec_get_mac takes care of it.

	/* Adjust MAC if using default MAC address */
	if (iap == fec_mac_default)
		dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
Quoted 6 lines

Also, instead of inventing another kernel command line parameter, it is better IMO to use the module parameters mechanism. The greth NIC driver already uses this method for setting MAC address. Look for 'macaddr' in drivers/net/greth.c, and the explanation at the beginning of Documentation/kernel-parameters.txt.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Sounds good. Thanks.

I just thought this over again. Module parameter might not be the best here. fec is usually used to mount nfs during boot, which requires a built-in driver other than module.

See the explanation at the beginning of Documentation/kernel-parameters.txt. You can give module parameters at the kernel command line.

Ah, my dumb.

Just tested, and it works. Thanks, Baruch.

Signature · 2 lines
Regards,
Shawn
author
#16 lore raw

PATCH 3/10 net/fec: add mac field into platform data and consolidate fec_get_mac

In reply to Baruch Siach

Sorry, Baruch. I missed two comments in the last reply.

Quoted 4 lines · Baruch Siach

Hi Shawn,

Please add netdev at vger.kernel.org to the Cc of all your fec driver patches.

I was aware of this after I sent out the patch set last night. Can I just resend all the patches in v2 and get netdev at vger.kernel.org included?

Quoted 1 line · Shawn Guo

[...]

Quoted 4 lines
Quoted 4 lines
drivers/net/fec.c +4 -0
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
Quoted 9 lines

drivers/net/fec.c rx_processing_done: · line 549

Quoted 6 lines
drivers/net/fec.c +6 -0
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */

Again, how do you handle the dual MAC case?

For the platform data case, the following patch reads both mac addresses.

[PATCH 09/10] ARM: mx28: read fec mac address from ocotp

+static int __init mx28evk_fec_get_mac(void)
+{
+ int i, ret;
+ u32 val;
+
+ /*

+        * OCOTP only stores the last 4 octets for each mac address,
+        * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+        * is needed.
+        */

+ for (i = 0; i < 2; i++) {
+ ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+ if (ret)
+ goto error;
+

+               mx28_fec_pdata[i].mac[0] = 0x00;
+               mx28_fec_pdata[i].mac[1] = 0x04;
+               mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+               mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+               mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+               mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;

+ }
+
+ return 0;
+
+error:
+ pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
+ return -ETIMEDOUT;
+}
+

Signature · 2 lines
Regards,
Shawn
#17 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hello,

Quoted 10 lines · Shawn Guo

Sorry, Baruch. I missed two comments in the last reply.

Quoted 4 lines · Baruch Siach

Hi Shawn,

Please add netdev at vger.kernel.org to the Cc of all your fec driver patches.

I was aware of this after I sent out the patch set last night. Can I just resend all the patches in v2 and get netdev at vger.kernel.org included?

[I just added netdev for this reply. I think adding it for v2 is OK then. For those interested, the whole series can be found at

	http://thread.gmane.org/gmane.linux.ports.arm.kernel/100902

.]

Quoted 31 lines
Quoted 1 line · Shawn Guo

[...]

Quoted 4 lines
Quoted 4 lines
drivers/net/fec.c +4 -0
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
Quoted 9 lines

drivers/net/fec.c rx_processing_done: · line 549

Quoted 6 lines
drivers/net/fec.c +6 -0
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */

Again, how do you handle the dual MAC case?

For the platform data case, the following patch reads both mac addresses.

[PATCH 09/10] ARM: mx28: read fec mac address from ocotp

(quoted diff) +11 -0
+static int __init mx28evk_fec_get_mac(void)
+{
+       int i, ret;
+       u32 val;
+
+       /*
+        * OCOTP only stores the last 4 octets for each mac address,
+        * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+        * is needed.
+        */
+       for (i = 0; i < 2; i++) {

Review

Quoted 10 lines
(quoted diff) +10 -0
+               ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+               if (ret)
+                       goto error;
+
+               mx28_fec_pdata[i].mac[0] = 0x00;
+               mx28_fec_pdata[i].mac[1] = 0x04;
+               mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+               mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+               mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+               mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;

uuh. Is ((val >> 24) & 0xff) supposed to be 0x9f? If not this might have unwanted effects (practical, don't know about legal ones).

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#18 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Uwe,

Quoted 13 lines · Uwe Kleine-König

Hello,

Quoted 10 lines · Shawn Guo

Sorry, Baruch. I missed two comments in the last reply.

Quoted 4 lines · Baruch Siach

Hi Shawn,

Please add [email protected] to the Cc of all your fec driver patches.

I was aware of this after I sent out the patch set last night. Can I just resend all the patches in v2 and get [email protected] included?

Quoted 7 lines

[I just added netdev for this reply. I think adding it for v2 is OK then. For those interested, the whole series can be found at

	http://thread.gmane.org/gmane.linux.ports.arm.kernel/100902

.]

Thanks.

Quoted 35 lines
Quoted 35 lines
Quoted 1 line · Shawn Guo

[...]

Quoted 4 lines
Quoted 4 lines
drivers/net/fec.c +4 -0
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
Quoted 9 lines

drivers/net/fec.c rx_processing_done: · line 549

Quoted 6 lines
drivers/net/fec.c +6 -0
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */

Again, how do you handle the dual MAC case?

For the platform data case, the following patch reads both mac addresses.

[PATCH 09/10] ARM: mx28: read fec mac address from ocotp

(quoted diff) +15 -0
+static int __init mx28evk_fec_get_mac(void)
+{
+       int i, ret;
+       u32 val;
+
+       /*
+        * OCOTP only stores the last 4 octets for each mac address,
+        * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+        * is needed.
+        */
+       for (i = 0; i < 2; i++) {
+               ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+               if (ret)
+                       goto error;
+
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+               mx28_fec_pdata[i].mac[0] = 0x00;
+               mx28_fec_pdata[i].mac[1] = 0x04;
+               mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+               mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+               mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+               mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;

uuh. Is ((val >> 24) & 0xff) supposed to be 0x9f? If not this might have unwanted effects (practical, don't know about legal ones).

Yes, it is 0x9f.

Signature · 2 lines
Regards,
Shawn
#19 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Shawn,

Quoted 45 lines · Shawn Guo
Quoted 36 lines · Uwe Kleine-K?nig
Quoted 35 lines · Shawn Guo
Quoted 1 line · Shawn Guo

[...]

Quoted 4 lines
Quoted 4 lines
drivers/net/fec.c +4 -0
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
Quoted 9 lines

drivers/net/fec.c rx_processing_done: · line 549

Quoted 6 lines
drivers/net/fec.c +6 -0
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */

Again, how do you handle the dual MAC case?

For the platform data case, the following patch reads both mac addresses.

[PATCH 09/10] ARM: mx28: read fec mac address from ocotp

(quoted diff) +15 -0
+static int __init mx28evk_fec_get_mac(void)
+{
+       int i, ret;
+       u32 val;
+
+       /*
+        * OCOTP only stores the last 4 octets for each mac address,
+        * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+        * is needed.
+        */
+       for (i = 0; i < 2; i++) {
+               ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+               if (ret)
+                       goto error;
+
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+               mx28_fec_pdata[i].mac[0] = 0x00;
+               mx28_fec_pdata[i].mac[1] = 0x04;
+               mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+               mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+               mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+               mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;

uuh. Is ((val >> 24) & 0xff) supposed to be 0x9f? If not this might have unwanted effects (practical, don't know about legal ones).

Quoted 1 line

Yes, it is 0x9f.

Then maybe hardcode that, or at least warn if it's not?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#20 lore raw

Re: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac

Hi Uwe,

Quoted 48 lines · Uwe Kleine-König

Hi Shawn,

Quoted 45 lines · Shawn Guo
Quoted 44 lines · Uwe Kleine-König
Quoted 31 lines · Shawn Guo
Quoted 1 line · Shawn Guo

[...]

Quoted 4 lines
Quoted 4 lines
drivers/net/fec.c +4 -0
+	/*
+	 * try to get mac address in following order:
+	 *
+	 * 1) kernel command line fec_mac=xx:xx:xx...
Quoted 9 lines

drivers/net/fec.c rx_processing_done: · line 549

Quoted 6 lines
drivers/net/fec.c +6 -0
+	 */
+	iap = fec_mac_default;
+
+	/*
+	 * 2) from flash or fuse (via platform data)
+	 */

Again, how do you handle the dual MAC case?

For the platform data case, the following patch reads both mac addresses.

[PATCH 09/10] ARM: mx28: read fec mac address from ocotp

(quoted diff) +11 -0
+static int __init mx28evk_fec_get_mac(void)
+{
+       int i, ret;
+       u32 val;
+
+       /*
+        * OCOTP only stores the last 4 octets for each mac address,
+        * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+        * is needed.
+        */
+       for (i = 0; i < 2; i++) {

Review

Quoted 10 lines
(quoted diff) +10 -0
+               ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+               if (ret)
+                       goto error;
+
+               mx28_fec_pdata[i].mac[0] = 0x00;
+               mx28_fec_pdata[i].mac[1] = 0x04;
+               mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+               mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+               mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+               mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;

uuh. Is ((val >> 24) & 0xff) supposed to be 0x9f? If not this might have unwanted effects (practical, don't know about legal ones).

Quoted 3 lines
Quoted 1 line

Yes, it is 0x9f.

Then maybe hardcode that, or at least warn if it's not?

Will hard-code it.

Signature · 2 lines
Regards,
Shawn
author
#21 lore raw

PATCH 4/10 net/fec: improve pm for better suspend/resume

In reply to Shawn Guo

The following commit made a fix to use fec_enet_open/fec_enet_close over fec_enet_init/fec_stop for suspend/resume, because fec_enet_init does not allow to have a working network interface at resume.

e3fe8558c7fc182972c3d947d88744482111f304
net/fec: fix pm to survive to suspend/resume

This fix works for i.mx/mxc fec controller, but fails on mx28 fec which gets a different interrupt logic design. On i.mx fec, interrupt can be triggered even bit ETHER_EN of ECR register is not set. But on mx28 fec, ETHER_EN must be set to get interrupt work. Meanwhile, MII interrupt is mandatory to resume the driver, because MDIO read/write changed to interrupt mode by commit below.

97b72e4320a9aaa4a7f1592ee7d2da7e2c9bd349
fec: use interrupt for MDIO completion indication

fec_restart/fec_stop comes out as the solution working for both cases.

---
 drivers/net/fec.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/net/fec.c +8 -4
index cd59814..f147508 100644
@@ -1387,8 +1387,10 @@ fec_suspend(struct device *dev)
 
 	if (ndev) {
 		fep = netdev_priv(ndev);
-		if (netif_running(ndev))
-			fec_enet_close(ndev);
+		if (netif_running(ndev)) {
+			fec_stop(ndev);
+			netif_device_detach(ndev);
+		}
 		clk_disable(fep->clk);
 	}
 	return 0;
@@ -1403,8 +1405,10 @@ fec_resume(struct device *dev)
 	if (ndev) {
 		fep = netdev_priv(ndev);
 		clk_enable(fep->clk);
-		if (netif_running(ndev))
-			fec_enet_open(ndev);
+		if (netif_running(ndev)) {
+			fec_restart(ndev, fep->full_duplex);
+			netif_device_attach(ndev);
+		}
 	}
 	return 0;
 }
Signature · 1 line
1.7.1
author
#22 lore raw

PATCH 5/10 net/fec: add dual fec support for mx28

In reply to Shawn Guo

This patch is to add mx28 dual fec support. Here are some key notes for mx28 fec controller.

- mx28 fec design made an assumption that it runs on a big-endian system, which is incorrect. As the result, the driver has to swap every frame going to and coming from the controller.
- external phys can only be configured by fec0, which means fec1 can not work independently and both phys need to be configured by mii_bus attached on fec0.
- mx28 fec reset will get mac address registers reset too.
- MII/RMII mode and 10M/100M speed are configured differently from i.mx/mxs fec controller.
- ETHER_EN bit must be set to get interrupt work.

---
 drivers/net/Kconfig |    7 ++-
 drivers/net/fec.c   |  105 +++++++++++++++++++++++++++++++++++++++++++++++++--
 drivers/net/fec.h   |    5 +-
 3 files changed, 108 insertions(+), 9 deletions(-)
drivers/net/Kconfig +4 -3
index 4f1755b..f34629b 100644
@@ -1944,18 +1944,19 @@ config 68360_ENET
 config FEC
 	bool "FEC ethernet controller (of ColdFire and some i.MX CPUs)"
 	depends on M523x || M527x || M5272 || M528x || M520x || M532x || \
-		MACH_MX27 || ARCH_MX35 || ARCH_MX25 || ARCH_MX5
+		MACH_MX27 || ARCH_MX35 || ARCH_MX25 || ARCH_MX5 || SOC_IMX28
 	select PHYLIB
 	help
 	  Say Y here if you want to use the built-in 10/100 Fast ethernet
 	  controller on some Motorola ColdFire and Freescale i.MX processors.
 
 config FEC2
-	bool "Second FEC ethernet controller (on some ColdFire CPUs)"
+	bool "Second FEC ethernet controller"
 	depends on FEC
 	help
 	  Say Y here if you want to use the second built-in 10/100 Fast
-	  ethernet controller on some Motorola ColdFire processors.
+	  ethernet controller on some Motorola ColdFire and Freescale
+	  i.MX processors.
 
 config FEC_MPC52xx
 	tristate "MPC52xx FEC driver"
drivers/net/fec.c +101 -4

194 lines not on this page · raw message

drivers/net/fec.h +3 -2
index 2c48b25..ace318d 100644
@@ -14,7 +14,8 @@
 /****************************************************************************/
 
 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
-    defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARCH_MXC)
+    defined(CONFIG_M520x) || defined(CONFIG_M532x) || \
+    defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
 /*
  *	Just figures, Motorola would have to change the offsets for
  *	registers in the same peripheral device on different models
@@ -78,7 +79,7 @@
 /*
  *	Define the buffer descriptor structure.
  */
-#ifdef CONFIG_ARCH_MXC
+#if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
 struct bufdesc {
 	unsigned short cbd_datlen;	/* Data length */
 	unsigned short cbd_sc;	/* Control and status info */
Signature · 1 line
1.7.1
author
#23 lore raw

PATCH 6/10 ARM: mx28: update clocks for dual fec support

In reply to Shawn Guo

* Change fec clock registration to use con_id only for looking up, so that dual fec driver can find the same clock for both fec0 and fec1.

* Explicitly call clk_enable for some clocks that have been on to reflect the clock status and get usecount updated. Otherwise, clocks could be turned off by pair call of clk_enable/clk_disable in drivers, because of the incorrect initial usecount.

---
 arch/arm/mach-mxs/clock-mx28.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +6 -1
index dd6d158..6b77aff 100644
@@ -603,7 +603,7 @@ _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk);
 
 static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("uart", NULL, uart_clk)
-	_REGISTER_CLOCK("fec.0", NULL, fec_clk)
+	_REGISTER_CLOCK(NULL, "fec_clk", fec_clk)
 	_REGISTER_CLOCK("rtc", NULL, rtc_clk)
 	_REGISTER_CLOCK("pll2", NULL, pll2_clk)
 	_REGISTER_CLOCK(NULL, "hclk", hbus_clk)
@@ -726,6 +726,11 @@ int __init mx28_clocks_init(void)
 {
 	clk_misc_init();
 
+	clk_enable(&cpu_clk);
+	clk_enable(&hbus_clk);
+	clk_enable(&emi_clk);
+	clk_enable(&uart_clk);
+
 	clkdev_add_table(lookups, ARRAY_SIZE(lookups));
 
 	mxs_timer_init(&clk32k_clk, MX28_INT_TIMER0);
Signature · 1 line
1.7.1
#24 lore raw

PATCH 6/10 ARM: mx28: update clocks for dual fec support

Hi Shawn,

Quoted 19 lines · Shawn Guo

* Change fec clock registration to use con_id only for looking up, so that dual fec driver can find the same clock for both fec0 and fec1.

* Explicitly call clk_enable for some clocks that have been on to reflect the clock status and get usecount updated. Otherwise, clocks could be turned off by pair call of clk_enable/clk_disable in drivers, because of the incorrect initial usecount.

---
 arch/arm/mach-mxs/clock-mx28.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +0 -0
index dd6d158..6b77aff 100644

arch/arm/mach-mxs/clock-mx28.c _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk); · line 606

Quoted 5 lines
arch/arm/mach-mxs/clock-mx28.c +1 -1
@@ -603,7 +603,7 @@ _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk);
 
 static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("uart", NULL, uart_clk)
-	_REGISTER_CLOCK("fec.0", NULL, fec_clk)
+	_REGISTER_CLOCK(NULL, "fec_clk", fec_clk)

Looks like a wrong use of the clk API. You should define define two clocks "fec.0" and "fec.1".

baruch

Signature · 3 lines
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#25 lore raw

PATCH 6/10 ARM: mx28: update clocks for dual fec support

Quoted 23 lines · Baruch Siach

Hi Shawn,

Quoted 20 lines · Shawn Guo

* Change fec clock registration to use con_id only for looking up, so that dual fec driver can find the same clock for both fec0 and fec1.

* Explicitly call clk_enable for some clocks that have been on to reflect the clock status and get usecount updated. Otherwise, clocks could be turned off by pair call of clk_enable/clk_disable in drivers, because of the incorrect initial usecount.

---
 arch/arm/mach-mxs/clock-mx28.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +0 -0
index dd6d158..6b77aff 100644
@@ -603,7 +603,7 @@ _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk);
 
Quoted 7 lines

arch/arm/mach-mxs/clock-mx28.c _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk); · line 606

Quoted 4 lines
arch/arm/mach-mxs/clock-mx28.c +1 -1
 static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("uart", NULL, uart_clk)
-	_REGISTER_CLOCK("fec.0", NULL, fec_clk)
+	_REGISTER_CLOCK(NULL, "fec_clk", fec_clk)

Looks like a wrong use of the clk API. You should define define two clocks "fec.0" and "fec.1".

The commit log suggests that both should enable the same (hardware) clock. Still I agree with Baruch that in this case clk_get() should just return the same clock for both fec.0 and fec.1.
I think it's a bit more work than just adding

	_REGISTER_CLOCK("fec.1", NULL, fec_clk)

, maybe just define fec1_clk as a dummy clk with parent=fec_clk?

(And IMHO don't inlude "_clk" in clknames, that's implicit.)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#26 lore raw

PATCH 6/10 ARM: mx28: update clocks for dual fec support

Hi Uwe,

Quoted 31 lines · Uwe Kleine-K?nig
Quoted 23 lines · Baruch Siach

Hi Shawn,

Quoted 20 lines · Shawn Guo

* Change fec clock registration to use con_id only for looking up, so that dual fec driver can find the same clock for both fec0 and fec1.

* Explicitly call clk_enable for some clocks that have been on to reflect the clock status and get usecount updated. Otherwise, clocks could be turned off by pair call of clk_enable/clk_disable in drivers, because of the incorrect initial usecount.

---
 arch/arm/mach-mxs/clock-mx28.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +0 -0
index dd6d158..6b77aff 100644
@@ -603,7 +603,7 @@ _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk);
 
Quoted 7 lines

arch/arm/mach-mxs/clock-mx28.c _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk); · line 606

Quoted 4 lines
arch/arm/mach-mxs/clock-mx28.c +1 -1
 static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("uart", NULL, uart_clk)
-	_REGISTER_CLOCK("fec.0", NULL, fec_clk)
+	_REGISTER_CLOCK(NULL, "fec_clk", fec_clk)

Looks like a wrong use of the clk API. You should define define two clocks "fec.0" and "fec.1".

Quoted 6 lines

The commit log suggests that both should enable the same (hardware) clock. Still I agree with Baruch that in this case clk_get() should just return the same clock for both fec.0 and fec.1.
I think it's a bit more work than just adding

	_REGISTER_CLOCK("fec.1", NULL, fec_clk)

I originally had what you suggest above. But when I found fec driver only calls clk_get like below, I change the code to current one to save one line code.

	fep->clk = clk_get(&pdev->dev, "fec_clk");

But it looks people use dev_id to address clock as the preference. Will change it back.

Quoted 4 lines

, maybe just define fec1_clk as a dummy clk with parent=fec_clk?

(And IMHO don't inlude "_clk" in clknames, that's implicit.)

Signature · 2 lines
Regards,
Shawn
#27 lore raw

PATCH 6/10 ARM: mx28: update clocks for dual fec support

Hello,

Quoted 38 lines · Shawn Guo
Quoted 31 lines · Uwe Kleine-K?nig
Quoted 23 lines · Baruch Siach

Hi Shawn,

Quoted 20 lines · Shawn Guo

* Change fec clock registration to use con_id only for looking up, so that dual fec driver can find the same clock for both fec0 and fec1.

* Explicitly call clk_enable for some clocks that have been on to reflect the clock status and get usecount updated. Otherwise, clocks could be turned off by pair call of clk_enable/clk_disable in drivers, because of the incorrect initial usecount.

---
 arch/arm/mach-mxs/clock-mx28.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +0 -0
index dd6d158..6b77aff 100644
@@ -603,7 +603,7 @@ _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk);
 
Quoted 7 lines

arch/arm/mach-mxs/clock-mx28.c _DEFINE_CLOCK(fec_clk, ENET, DISABLE, &hbus_clk); · line 606

Quoted 4 lines
arch/arm/mach-mxs/clock-mx28.c +1 -1
 static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("uart", NULL, uart_clk)
-	_REGISTER_CLOCK("fec.0", NULL, fec_clk)
+	_REGISTER_CLOCK(NULL, "fec_clk", fec_clk)

Looks like a wrong use of the clk API. You should define define two clocks "fec.0" and "fec.1".

Quoted 6 lines

The commit log suggests that both should enable the same (hardware) clock. Still I agree with Baruch that in this case clk_get() should just return the same clock for both fec.0 and fec.1.
I think it's a bit more work than just adding

	_REGISTER_CLOCK("fec.1", NULL, fec_clk)
Quoted 5 lines

I originally had what you suggest above. But when I found fec driver only calls clk_get like below, I change the code to current one to save one line code.

	fep->clk = clk_get(&pdev->dev, "fec_clk");

if there is only a single (software) clock for the fec, the driver should pass NULL as 2nd argument to clk_get.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#28 lore raw

PATCH 7/10 ARM: mx28: add the second fec device registration

In reply to Shawn Guo
---
 arch/arm/mach-mxs/mach-mx28evk.c |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)
arch/arm/mach-mxs/mach-mx28evk.c +25 -3
index d162e95..def6519 100644
@@ -57,6 +57,19 @@ static const iomux_cfg_t mx28evk_pads[] __initconst = {
 		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
 	MX28_PAD_ENET_CLK__CLKCTRL_ENET |
 		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
+	/* fec1 */
+	MX28_PAD_ENET0_CRS__ENET1_RX_EN |
+		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
+	MX28_PAD_ENET0_RXD2__ENET1_RXD0 |
+		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
+	MX28_PAD_ENET0_RXD3__ENET1_RXD1 |
+		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
+	MX28_PAD_ENET0_COL__ENET1_TX_EN |
+		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
+	MX28_PAD_ENET0_TXD2__ENET1_TXD0 |
+		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
+	MX28_PAD_ENET0_TXD3__ENET1_TXD1 |
+		(MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
 	/* phy power line */
 	MX28_PAD_SSP1_DATA3__GPIO_2_15 |
 		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
@@ -106,8 +119,14 @@ static void __init mx28evk_fec_reset(void)
 	gpio_set_value(MX28EVK_FEC_PHY_RESET, 1);
 }
 
-static const struct fec_platform_data mx28_fec_pdata __initconst = {
-	.phy = PHY_INTERFACE_MODE_RMII,
+static struct fec_platform_data mx28_fec_pdata[] = {
+	{
+		/* fec0 */
+		.phy = PHY_INTERFACE_MODE_RMII,
+	}, {
+		/* fec1 */
+		.phy = PHY_INTERFACE_MODE_RMII,
+	},
 };
 
 static void __init mx28evk_init(void)
@@ -117,7 +136,10 @@ static void __init mx28evk_init(void)
 	mx28_add_duart();
 
 	mx28evk_fec_reset();
-	mx28_add_fec(0, &mx28_fec_pdata);
+	mx28_add_fec(0, &mx28_fec_pdata[0]);
+#ifdef CONFIG_FEC2
+	mx28_add_fec(1, &mx28_fec_pdata[1]);
+#endif
 }
 
 static void __init mx28evk_timer_init(void)
Signature · 1 line
1.7.1
#29 lore raw

PATCH 7/10 ARM: mx28: add the second fec device registration

Hello Shawn,

arch/arm/mach-mxs/mach-mx28evk.c static void __init mx28evk_fec_reset(void) · line 130

Quoted 11 lines
arch/arm/mach-mxs/mach-mx28evk.c +8 -2
-static const struct fec_platform_data mx28_fec_pdata __initconst = {
-	.phy = PHY_INTERFACE_MODE_RMII,
+static struct fec_platform_data mx28_fec_pdata[] = {
+	{
+		/* fec0 */
+		.phy = PHY_INTERFACE_MODE_RMII,
+	}, {
+		/* fec1 */
+		.phy = PHY_INTERFACE_MODE_RMII,
+	},
 };

I think there is no need to duplicate the platform_data as mx28_add_fec makes a copy anyhow. Did you remove __initconst and const on purpose?

arch/arm/mach-mxs/mach-mx28evk.c static void __init mx28evk_init(void) · line 145

Quoted 13 lines

static void __init mx28evk_init(void)

arch/arm/mach-mxs/mach-mx28evk.c +4 -1
@@ -117,7 +136,10 @@ static void __init mx28evk_init(void)
 	mx28_add_duart();
 
 	mx28evk_fec_reset();
-	mx28_add_fec(0, &mx28_fec_pdata);
+	mx28_add_fec(0, &mx28_fec_pdata[0]);
+#ifdef CONFIG_FEC2
+	mx28_add_fec(1, &mx28_fec_pdata[1]);
+#endif
 }
 
 static void __init mx28evk_timer_init(void)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#30 lore raw

PATCH 7/10 ARM: mx28: add the second fec device registration

Hi Uwe,

Quoted 16 lines · Uwe Kleine-K?nig

Hello Shawn,

arch/arm/mach-mxs/mach-mx28evk.c static void __init mx28evk_fec_reset(void) · line 130

Quoted 11 lines
arch/arm/mach-mxs/mach-mx28evk.c +8 -2
-static const struct fec_platform_data mx28_fec_pdata __initconst = {
-	.phy = PHY_INTERFACE_MODE_RMII,
+static struct fec_platform_data mx28_fec_pdata[] = {
+	{
+		/* fec0 */
+		.phy = PHY_INTERFACE_MODE_RMII,
+	}, {
+		/* fec1 */
+		.phy = PHY_INTERFACE_MODE_RMII,
+	},
 };

I think there is no need to duplicate the platform_data as mx28_add_fec makes a copy anyhow. Did you remove __initconst and const on purpose?

The mac field is different for fec0 and fec1 and needs to be assigned in mx28evk_fec_get_mac.

Signature · 2 lines
Regards,
Shawn
author
#31 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

In reply to Shawn Guo
---
 arch/arm/mach-mxs/Makefile              |    2 +-
 arch/arm/mach-mxs/include/mach/common.h |    1 +
 arch/arm/mach-mxs/ocotp.c               |   52 +++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/ocotp.c
arch/arm/mach-mxs/Makefile +1 -1
index 39d3f9c..f23ebbd 100644
@@ -1,5 +1,5 @@
 # Common support
-obj-y := clock.o devices.o gpio.o icoll.o iomux.o system.o timer.o
+obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
 
 obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
 obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
arch/arm/mach-mxs/include/mach/common.h +1 -0
index 59133eb..cf02552 100644
@@ -13,6 +13,7 @@
 
 struct clk;
 
+extern int mxs_read_ocotp(int offset, int count, u32 *values);
 extern int mxs_reset_block(void __iomem *);
 extern void mxs_timer_init(struct clk *, int);
 
arch/arm/mach-mxs/ocotp.c new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.7.1
#32 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Hello Shawn,

Quoted 50 lines · Shawn Guo
---
 arch/arm/mach-mxs/Makefile              |    2 +-
 arch/arm/mach-mxs/include/mach/common.h |    1 +
 arch/arm/mach-mxs/ocotp.c               |   52 +++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/ocotp.c
arch/arm/mach-mxs/Makefile +1 -1
index 39d3f9c..f23ebbd 100644
@@ -1,5 +1,5 @@
 # Common support
-obj-y := clock.o devices.o gpio.o icoll.o iomux.o system.o timer.o
+obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
 
 obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
 obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
arch/arm/mach-mxs/include/mach/common.h +1 -0
index 59133eb..cf02552 100644
@@ -13,6 +13,7 @@
 
 struct clk;
 
+extern int mxs_read_ocotp(int offset, int count, u32 *values);
 extern int mxs_reset_block(void __iomem *);
 extern void mxs_timer_init(struct clk *, int);
 
arch/arm/mach-mxs/ocotp.c new file +13 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

arch/arm/mach-mxs/ocotp.c line 23

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)

Maybe use size_t as type for count? unsigned for offset?

Quoted 19 lines
arch/arm/mach-mxs/ocotp.c new file +19 -0
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
+
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;
+
+	for (i = 0; i < count; i++, offset += 4)
+		*values++ = __raw_readl(ocotp_base + offset);

arch/arm/mach-mxs/ocotp.c line 52

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+
+	/* close banks for power saving */
+	__mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
+
+	return 0;
+
+error:
+	pr_err("%s: timeout in reading OCOTP\n", __func__);
+	return -ETIMEDOUT;
+}

does this need locking?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#33 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Quoted 56 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 53 lines · Shawn Guo
---
 arch/arm/mach-mxs/Makefile              |    2 +-
 arch/arm/mach-mxs/include/mach/common.h |    1 +
 arch/arm/mach-mxs/ocotp.c               |   52 +++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/ocotp.c
arch/arm/mach-mxs/Makefile +1 -1
index 39d3f9c..f23ebbd 100644
@@ -1,5 +1,5 @@
 # Common support
-obj-y := clock.o devices.o gpio.o icoll.o iomux.o system.o timer.o
+obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
 
 obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
 obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
arch/arm/mach-mxs/include/mach/common.h +1 -0
index 59133eb..cf02552 100644
@@ -13,6 +13,7 @@
 
 struct clk;
 
+extern int mxs_read_ocotp(int offset, int count, u32 *values);
 extern int mxs_reset_block(void __iomem *);
 extern void mxs_timer_init(struct clk *, int);
 
arch/arm/mach-mxs/ocotp.c new file +16 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
Quoted 9 lines

arch/arm/mach-mxs/ocotp.c line 23

Quoted 7 lines
arch/arm/mach-mxs/ocotp.c new file +7 -0
+
+#include <mach/mxs.h>
+
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)

Maybe use size_t as type for count? unsigned for offset?

OK.

Quoted 22 lines
Quoted 22 lines
arch/arm/mach-mxs/ocotp.c new file +22 -0
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
+
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;
+
+	for (i = 0; i < count; i++, offset += 4)
+		*values++ = __raw_readl(ocotp_base + offset);
+
+	/* close banks for power saving */
+	__mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
Quoted 9 lines

arch/arm/mach-mxs/ocotp.c line 52

Quoted 7 lines
arch/arm/mach-mxs/ocotp.c new file +7 -0
+
+	return 0;
+
+error:
+	pr_err("%s: timeout in reading OCOTP\n", __func__);
+	return -ETIMEDOUT;
+}

does this need locking?

You are suggesting mutex or spinlock?

Signature · 2 lines
Regards,
Shawn
#34 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Hello Shawn,

Quoted 33 lines · Shawn Guo
Quoted 23 lines · Uwe Kleine-K?nig
Quoted 22 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +22 -0
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
+
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;
+
+	for (i = 0; i < count; i++, offset += 4)
+		*values++ = __raw_readl(ocotp_base + offset);
+
+	/* close banks for power saving */
+	__mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
Quoted 9 lines

arch/arm/mach-mxs/ocotp.c line 52

Quoted 7 lines
arch/arm/mach-mxs/ocotp.c new file +7 -0
+
+	return 0;
+
+error:
+	pr_err("%s: timeout in reading OCOTP\n", __func__);
+	return -ETIMEDOUT;
+}

does this need locking?

Quoted 1 line

You are suggesting mutex or spinlock?

This isn't time critical, so I'd advice to use a mutex.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#35 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

In reply to Shawn Guo

Hello,

Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

1. isn't done (which is probably OK, or should it aquire a clk?) For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

(Independant of that, shouldn't the list use BM_ prefixes as you did in the code?)

arch/arm/mach-mxs/ocotp.c line 39

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;

And I think you should recheck for BM_OCOTP_CTRL_RD_BANK_OPEN here (step 4 from the reference manual).

arch/arm/mach-mxs/ocotp.c line 52

Quoted 13 lines
arch/arm/mach-mxs/ocotp.c new file +13 -0
+
+	for (i = 0; i < count; i++, offset += 4)
+		*values++ = __raw_readl(ocotp_base + offset);
+
+	/* close banks for power saving */
+	__mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
+
+	return 0;
+
+error:
+	pr_err("%s: timeout in reading OCOTP\n", __func__);
+	return -ETIMEDOUT;
+}

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#36 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Hi Uwe,

Quoted 44 lines · Uwe Kleine-K?nig

Hello,

Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 4 lines

1. isn't done (which is probably OK, or should it aquire a clk?) For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

Will add the check. Thanks.

Quoted 3 lines

(Independant of that, shouldn't the list use BM_ prefixes as you did in the code?)

Document description uses register name followed by bit-field name to mean the bit.

Quoted 4 lines
Quoted 4 lines
arch/arm/mach-mxs/ocotp.c new file +4 -0
+
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
Quoted 9 lines

arch/arm/mach-mxs/ocotp.c line 39

Quoted 6 lines
arch/arm/mach-mxs/ocotp.c new file +6 -0
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;

And I think you should recheck for BM_OCOTP_CTRL_RD_BANK_OPEN here (step 4 from the reference manual).

The RM says:

Poll for HW_OCOTP_CTRL_BUSY clear. When HW_OCOTP_CTRL_BUSY is clear and HW_OCOTP_CTRL_RD_BANK_OPEN is set, read the data from the appropriate memory-mapped address.

My understanding is we only need to poll busy bit clear. And the second sentence just tells that read operation should be working when bit busy clear and rd_bank_open set, which has been done in step 3. I also consulted the designer and was told that only busy clear polling is needed.

Signature · 2 lines
Regards,
Shawn
#37 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Hello Shawn,

Quoted 47 lines · Shawn Guo
Quoted 42 lines · Uwe Kleine-K?nig
Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 4 lines

1. isn't done (which is probably OK, or should it aquire a clk?) For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

Quoted 7 lines

Will add the check. Thanks.

Quoted 3 lines

(Independant of that, shouldn't the list use BM_ prefixes as you did in the code?)

Document description uses register name followed by bit-field name to mean the bit.

After rereading chapter 39.4 (Register Macro Usage/Naming Convention) I wonder if the BM_ values are shifted or not. If they are not (as I think it is meant) your usage is inconsitent with the manual (but IMHO sane). sigh.

Quoted 18 lines
Quoted 12 lines

arch/arm/mach-mxs/ocotp.c line 39

Quoted 9 lines
arch/arm/mach-mxs/ocotp.c new file +9 -0
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;

And I think you should recheck for BM_OCOTP_CTRL_RD_BANK_OPEN here (step 4 from the reference manual).

The RM says:

Poll for HW_OCOTP_CTRL_BUSY clear. When HW_OCOTP_CTRL_BUSY is clear and HW_OCOTP_CTRL_RD_BANK_OPEN is set, read the data from the appropriate memory-mapped address.

Quoted 5 lines

My understanding is we only need to poll busy bit clear. And the second sentence just tells that read operation should be working when bit busy clear and rd_bank_open set, which has been done in step 3. I also consulted the designer and was told that only busy clear polling is needed.

I expected to need this (shortend the names to improve readability):

	while (__raw_readl(ocotp_base) & BUSY) && --timeout);

	if (unlikely((__raw_readl(ocotp_base) & (BUSY | RDBOPEN)) != RDBOPEN))
		goto error_unlock;

*shrug*

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#38 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Quoted 55 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 52 lines · Shawn Guo
Quoted 42 lines · Uwe Kleine-K?nig
Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 4 lines

1. isn't done (which is probably OK, or should it aquire a clk?) For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

Will add the check. Thanks.

Quoted 3 lines

(Independant of that, shouldn't the list use BM_ prefixes as you did in the code?)

Quoted 7 lines
Quoted 2 lines

Document description uses register name followed by bit-field name to mean the bit.

After rereading chapter 39.4 (Register Macro Usage/Naming Convention) I wonder if the BM_ values are shifted or not. If they are not (as I think it is meant) your usage is inconsitent with the manual (but IMHO sane). sigh.

They are shifted. You can check regs-clkctrl-mx28.h as an example.

Quoted 18 lines
Quoted 18 lines
Quoted 12 lines

arch/arm/mach-mxs/ocotp.c line 39

Quoted 9 lines
arch/arm/mach-mxs/ocotp.c new file +9 -0
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;

And I think you should recheck for BM_OCOTP_CTRL_RD_BANK_OPEN here (step 4 from the reference manual).

The RM says:

Poll for HW_OCOTP_CTRL_BUSY clear. When HW_OCOTP_CTRL_BUSY is clear and HW_OCOTP_CTRL_RD_BANK_OPEN is set, read the data from the appropriate memory-mapped address.

Quoted 7 lines
Quoted 5 lines

My understanding is we only need to poll busy bit clear. And the second sentence just tells that read operation should be working when bit busy clear and rd_bank_open set, which has been done in step 3. I also consulted the designer and was told that only busy clear polling is needed.

I expected to need this (shortend the names to improve readability):

IMHO, BM_OCOTP_CTRL_BUSY is more readable than BUSY. Reader can understand which bit it is more easily than BUSY.

Quoted 5 lines
	while (__raw_readl(ocotp_base) & BUSY) && --timeout);

	if (unlikely((__raw_readl(ocotp_base) & (BUSY | RDBOPEN)) != RDBOPEN))
		goto error_unlock;

I still did not get it. When we set bit RDBOPEN in step 3, it gets set. That is it. Why do we still need to bother the unnecessary checking?

Quoted 9 lines

*shrug*

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Signature · 2 lines
Regards,
Shawn
#39 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Hello Shawn,

Quoted 88 lines · Shawn Guo
Quoted 55 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 52 lines · Shawn Guo
Quoted 42 lines · Uwe Kleine-K?nig
Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 4 lines

1. isn't done (which is probably OK, or should it aquire a clk?) For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

Will add the check. Thanks.

Quoted 3 lines

(Independant of that, shouldn't the list use BM_ prefixes as you did in the code?)

Quoted 7 lines
Quoted 2 lines

Document description uses register name followed by bit-field name to mean the bit.

After rereading chapter 39.4 (Register Macro Usage/Naming Convention) I wonder if the BM_ values are shifted or not. If they are not (as I think it is meant) your usage is inconsitent with the manual (but IMHO sane). sigh.

They are shifted. You can check regs-clkctrl-mx28.h as an example.

Quoted 23 lines
Quoted 23 lines
Quoted 12 lines

arch/arm/mach-mxs/ocotp.c line 39

Quoted 9 lines
arch/arm/mach-mxs/ocotp.c new file +9 -0
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;

And I think you should recheck for BM_OCOTP_CTRL_RD_BANK_OPEN here (step 4 from the reference manual).

The RM says:

Poll for HW_OCOTP_CTRL_BUSY clear. When HW_OCOTP_CTRL_BUSY is clear and HW_OCOTP_CTRL_RD_BANK_OPEN is set, read the data from the appropriate memory-mapped address.

My understanding is we only need to poll busy bit clear. And the second sentence just tells that read operation should be working when bit busy clear and rd_bank_open set, which has been done in step 3. I also consulted the designer and was told that only busy clear polling is needed.

Quoted 4 lines
Quoted 2 lines

I expected to need this (shortend the names to improve readability):

IMHO, BM_OCOTP_CTRL_BUSY is more readable than BUSY. Reader can understand which bit it is more easily than BUSY.

I only shortend it for the mail. For a patch of course use the full name.

Quoted 7 lines
Quoted 5 lines
	while (__raw_readl(ocotp_base) & BUSY) && --timeout);

	if (unlikely((__raw_readl(ocotp_base) & (BUSY | RDBOPEN)) != RDBOPEN))
		goto error_unlock;

I still did not get it. When we set bit RDBOPEN in step 3, it gets set. That is it. Why do we still need to bother the unnecessary checking?

That's how I interpret the hardware reference. And note, registers are not memory. Just because you write a value to it it doesn't mean it is set when you reread it.

Best regards and happy new year (don't know if you have that? :-) Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#40 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Quoted 100 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 88 lines · Shawn Guo
Quoted 55 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 52 lines · Shawn Guo
Quoted 42 lines · Uwe Kleine-K?nig
Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 4 lines

1. isn't done (which is probably OK, or should it aquire a clk?) For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

Will add the check. Thanks.

Quoted 3 lines

(Independant of that, shouldn't the list use BM_ prefixes as you did in the code?)

Quoted 7 lines
Quoted 2 lines

Document description uses register name followed by bit-field name to mean the bit.

After rereading chapter 39.4 (Register Macro Usage/Naming Convention) I wonder if the BM_ values are shifted or not. If they are not (as I think it is meant) your usage is inconsitent with the manual (but IMHO sane). sigh.

They are shifted. You can check regs-clkctrl-mx28.h as an example.

Quoted 23 lines
Quoted 23 lines
Quoted 12 lines

arch/arm/mach-mxs/ocotp.c line 39

Quoted 9 lines
arch/arm/mach-mxs/ocotp.c new file +9 -0
+	/* approximately wait 32 hclk cycles */
+	udelay(1);
+
+	/* poll BUSY bit becoming cleared */
+	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
+		/* nothing */;
+
+	if (unlikely(!timeout))
+		goto error;

And I think you should recheck for BM_OCOTP_CTRL_RD_BANK_OPEN here (step 4 from the reference manual).

The RM says:

Poll for HW_OCOTP_CTRL_BUSY clear. When HW_OCOTP_CTRL_BUSY is clear and HW_OCOTP_CTRL_RD_BANK_OPEN is set, read the data from the appropriate memory-mapped address.

My understanding is we only need to poll busy bit clear. And the second sentence just tells that read operation should be working when bit busy clear and rd_bank_open set, which has been done in step 3. I also consulted the designer and was told that only busy clear polling is needed.

Quoted 4 lines
Quoted 2 lines

I expected to need this (shortend the names to improve readability):

IMHO, BM_OCOTP_CTRL_BUSY is more readable than BUSY. Reader can understand which bit it is more easily than BUSY.

I only shortend it for the mail. For a patch of course use the full name.

Quoted 2 lines
Quoted 2 lines
	while (__raw_readl(ocotp_base) & BUSY) && --timeout);
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
	if (unlikely((__raw_readl(ocotp_base) & (BUSY | RDBOPEN)) != RDBOPEN))
		goto error_unlock;

I still did not get it. When we set bit RDBOPEN in step 3, it gets set. That is it. Why do we still need to bother the unnecessary checking?

That's how I interpret the hardware reference. And note, registers are not memory. Just because you write a value to it it doesn't mean it is set when you reread it.

The note is right. That why I asked designer whether the bit will definitely get set or not if software sets the bit implicitly. The answer I got is yes.

Quoted 1 line

Best regards and happy new year (don't know if you have that? :-)

I have that holiday, but I still need to check your reply ;)

Quoted 6 lines

Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Signature · 2 lines
Regards,
Shawn
author
#41 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

In reply to Uwe Kleine-König
Quoted 44 lines · Uwe Kleine-K?nig

Hello,

Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 1 line

1. isn't done (which is probably OK, or should it aquire a clk?)

ocotp needs clk_h, which must be on when system is running.

Quoted 3 lines

For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

How does the new code look to you?

static DEFINE_MUTEX(ocotp_mutex);

int mxs_read_ocotp(unsigned offset, size_t count, u32 *values)

{
	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
	int i, timeout = 0x400;

	mutex_lock(&ocotp_mutex);

	/* clear ERROR bit anyway */
	__mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base);

	/* check both BUSY and ERROR cleared */
	while ((__raw_readl(ocotp_base) &
		(BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout)
		/* nothing */;

	if (unlikely(!timeout))
		goto error;

	/* open OCOTP banks for read */
	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

	/* approximately wait 32 hclk cycles */
	udelay(1);

	/* poll BUSY bit becoming cleared */
	timeout = 0x400;
	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
		/* nothing */;

	if (unlikely(!timeout))
		goto error;

	for (i = 0; i < count; i++, offset += 4)
		*values++ = __raw_readl(ocotp_base + offset);

	/* close banks for power saving */
	__mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

	mutex_unlock(&ocotp_mutex);

	return 0;

error:

	pr_err("%s: timeout in reading OCOTP\n", __func__);
	return -ETIMEDOUT;
}
Signature · 2 lines
Regards,
Shawn
#42 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Hello Shawn,

Quoted 43 lines · Shawn Guo
Quoted 42 lines · Uwe Kleine-K?nig
Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 2 lines
Quoted 1 line

1. isn't done (which is probably OK, or should it aquire a clk?)

ocotp needs clk_h, which must be on when system is running.

maybe add a comment? "clk_enable(clk_h) can be skipped as it must be on anyhow because ..." or similar? It's always good to document implicit assumptions.

Quoted 11 lines
Quoted 3 lines

For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

How does the new code look to you?

static DEFINE_MUTEX(ocotp_mutex);

int mxs_read_ocotp(unsigned offset, size_t count, u32 *values)

{
	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
	int i, timeout = 0x400;

i should be size_t, too

Quoted 4 lines
	mutex_lock(&ocotp_mutex);

	/* clear ERROR bit anyway */

anyway? Better?: "try to clear ERROR bit"

Quoted 9 lines
	__mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base);

	/* check both BUSY and ERROR cleared */
	while ((__raw_readl(ocotp_base) &
		(BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout)
		/* nothing */;

	if (unlikely(!timeout))
		goto error;

This goto and some more leave the critical section without unlocking the mutex.

Quoted 25 lines
	/* open OCOTP banks for read */
	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

	/* approximately wait 32 hclk cycles */
	udelay(1);

	/* poll BUSY bit becoming cleared */
	timeout = 0x400;
	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
		/* nothing */;

	if (unlikely(!timeout))
		goto error;

	for (i = 0; i < count; i++, offset += 4)
		*values++ = __raw_readl(ocotp_base + offset);

	/* close banks for power saving */
	__mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

	mutex_unlock(&ocotp_mutex);

	return 0;
Quoted 4 lines

error:

	pr_err("%s: timeout in reading OCOTP\n", __func__);
	return -ETIMEDOUT;
}

I think it's OK then. One optimisation that comes to my mind is to make BM_OCOTP_CTRL_RD_BANK_OPEN a clk (that can depend on clk_h). This would allow for multiple readers, but I think it's not worth the effort.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#43 lore raw

PATCH 8/10 ARM: mxs: add ocotp read function

Hi Uwe,

Quoted 46 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 43 lines · Shawn Guo
Quoted 42 lines · Uwe Kleine-K?nig
Quoted 25 lines · Shawn Guo
arch/arm/mach-mxs/ocotp.c new file +19 -0
new file mode 100644
index 0000000..24457d7
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+
+#include <mach/mxs.h>
+

arch/arm/mach-mxs/ocotp.c line 29

Quoted 10 lines
arch/arm/mach-mxs/ocotp.c new file +10 -0
+#define BM_OCOTP_CTRL_RD_BANK_OPEN	(1 << 12)
+#define BM_OCOTP_CTRL_BUSY		(1 << 8)
+
+int mxs_read_ocotp(int offset, int count, u32 *values)
+{
+	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
+	int i, timeout = 0x400;
+
+	/* open OCOTP banks for read */
+	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

The reference manual specifies:
1. Program the HCLK to a frequency up to the maximum allowable HCLK frequency. [...]
2. Check that HW_OCOTP_CTRL_BUSY and HW_OCOTP_CTRL_ERROR are clear.
3. Set HW_OCOTP_CTRL_RD_BANK_OPEN. [...]

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

1. isn't done (which is probably OK, or should it aquire a clk?)

ocotp needs clk_h, which must be on when system is running.

maybe add a comment? "clk_enable(clk_h) can be skipped as it must be on anyhow because ..." or similar? It's always good to document implicit assumptions.

OK.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

For 2. there is no check for HW_OCOTP_CTRL_ERROR which is not OK i guess?!

How does the new code look to you?

Quoted 8 lines
Quoted 6 lines

static DEFINE_MUTEX(ocotp_mutex);

int mxs_read_ocotp(unsigned offset, size_t count, u32 *values)

{
	void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
	int i, timeout = 0x400;

i should be size_t, too

OK.

Quoted 13 lines
Quoted 4 lines
	mutex_lock(&ocotp_mutex);

	/* clear ERROR bit anyway */

anyway? Better?: "try to clear ERROR bit"

Quoted 7 lines
	__mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base);

	/* check both BUSY and ERROR cleared */
	while ((__raw_readl(ocotp_base) &
		(BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout)
		/* nothing */;
Quoted 5 lines
Quoted 2 lines
	if (unlikely(!timeout))
		goto error;

This goto and some more leave the critical section without unlocking the mutex.

My bad. Thanks.

Quoted 40 lines
Quoted 25 lines
	/* open OCOTP banks for read */
	__mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

	/* approximately wait 32 hclk cycles */
	udelay(1);

	/* poll BUSY bit becoming cleared */
	timeout = 0x400;
	while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
		/* nothing */;

	if (unlikely(!timeout))
		goto error;

	for (i = 0; i < count; i++, offset += 4)
		*values++ = __raw_readl(ocotp_base + offset);

	/* close banks for power saving */
	__mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);

	mutex_unlock(&ocotp_mutex);

	return 0;
Quoted 4 lines

error:

	pr_err("%s: timeout in reading OCOTP\n", __func__);
	return -ETIMEDOUT;
}

I think it's OK then. One optimisation that comes to my mind is to make BM_OCOTP_CTRL_RD_BANK_OPEN a clk (that can depend on clk_h). This would allow for multiple readers, but I think it's not worth the effort.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Signature · 2 lines
Regards,
Shawn
author
#44 lore raw

PATCH 9/10 ARM: mx28: read fec mac address from ocotp

In reply to Shawn Guo

Read fec mac address from ocotp and save it into fec_platform_data mac field for fec driver to use.

---
 arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c                |   31 +++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/devices/platform-fec.c +1 -1
index c08168c..dc978ee 100644
@@ -31,7 +31,7 @@ const struct mxs_fec_data mx28_fec_data[] __initconst = {
 
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata)
+		struct fec_platform_data *pdata)
 {
 	struct resource res[] = {
 		{
arch/arm/mach-mxs/include/mach/devices-common.h +1 -1
index fca0551..d206e0a 100644
@@ -38,4 +38,4 @@ struct mxs_fec_data {
 };
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata);
+		struct fec_platform_data *pdata);
arch/arm/mach-mxs/mach-mx28evk.c +31 -0
index def6519..d133733 100644
@@ -129,6 +129,36 @@ static struct fec_platform_data mx28_fec_pdata[] = {
 	},
 };
 
+static int __init mx28evk_fec_get_mac(void)
+{
+	int i, ret;
+	u32 val;
+
+	/*
+	 * OCOTP only stores the last 4 octets for each mac address,
+	 * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+	 * is needed.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+		if (ret)
+			goto error;
+
+		mx28_fec_pdata[i].mac[0] = 0x00;
+		mx28_fec_pdata[i].mac[1] = 0x04;
+		mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+		mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+		mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+		mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
+	}
+
+	return 0;
+
+error:
+	pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
+	return -ETIMEDOUT;
+}
+
 static void __init mx28evk_init(void)
 {
 	mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
@@ -136,6 +166,7 @@ static void __init mx28evk_init(void)
 	mx28_add_duart();
 
 	mx28evk_fec_reset();
+	mx28evk_fec_get_mac();
 	mx28_add_fec(0, &mx28_fec_pdata[0]);
 #ifdef CONFIG_FEC2
 	mx28_add_fec(1, &mx28_fec_pdata[1]);
Signature · 1 line
1.7.1
#45 lore raw

PATCH 9/10 ARM: mx28: read fec mac address from ocotp

Hello Shawn,

Quoted 28 lines · Shawn Guo

Read fec mac address from ocotp and save it into fec_platform_data mac field for fec driver to use.

---
 arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c                |   31 +++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/devices/platform-fec.c +1 -1
index c08168c..dc978ee 100644
@@ -31,7 +31,7 @@ const struct mxs_fec_data mx28_fec_data[] __initconst = {
 
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata)
+		struct fec_platform_data *pdata)
 {
 	struct resource res[] = {
 		{
arch/arm/mach-mxs/include/mach/devices-common.h +0 -0
index fca0551..d206e0a 100644

arch/arm/mach-mxs/include/mach/devices-common.h struct mxs_fec_data { · line 41

Quoted 5 lines
arch/arm/mach-mxs/include/mach/devices-common.h +1 -1
@@ -38,4 +38,4 @@ struct mxs_fec_data {
 };
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata);
+		struct fec_platform_data *pdata);

Why that?

Quoted 26 lines
arch/arm/mach-mxs/mach-mx28evk.c +18 -0
index def6519..d133733 100644
@@ -129,6 +129,36 @@ static struct fec_platform_data mx28_fec_pdata[] = {
 	},
 };
 
+static int __init mx28evk_fec_get_mac(void)
+{
+	int i, ret;
+	u32 val;
+
+	/*
+	 * OCOTP only stores the last 4 octets for each mac address,
+	 * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+	 * is needed.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+		if (ret)
+			goto error;
+
+		mx28_fec_pdata[i].mac[0] = 0x00;
+		mx28_fec_pdata[i].mac[1] = 0x04;
+		mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 159

Quoted 10 lines
arch/arm/mach-mxs/mach-mx28evk.c +10 -0
+		mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+		mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+		mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
+	}
+
+	return 0;
+
+error:
+	pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
+	return -ETIMEDOUT;

return ret please.

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 160

Quoted 1 line
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
+}

I think this should be defined in a more generic place.

arch/arm/mach-mxs/mach-mx28evk.c static void __init mx28evk_init(void) · line 169

Quoted 9 lines
arch/arm/mach-mxs/mach-mx28evk.c +2 -0
+
 static void __init mx28evk_init(void)
 {
 	mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
@@ -136,6 +166,7 @@ static void __init mx28evk_init(void)
 	mx28_add_duart();
 
 	mx28evk_fec_reset();
+	mx28evk_fec_get_mac();

You ignore the return value here. Intended?

Quoted 8 lines
arch/arm/mach-mxs/mach-mx28evk.c +0 -0
 	mx28_add_fec(0, &mx28_fec_pdata[0]);
 #ifdef CONFIG_FEC2
 	mx28_add_fec(1, &mx28_fec_pdata[1]);
Signature · 1 line
1.7.1
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#46 lore raw

PATCH 9/10 ARM: mx28: read fec mac address from ocotp

Hi Uwe,

Quoted 29 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 26 lines · Shawn Guo

Read fec mac address from ocotp and save it into fec_platform_data mac field for fec driver to use.

---
 arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c                |   31 +++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/devices/platform-fec.c +1 -1
index c08168c..dc978ee 100644
@@ -31,7 +31,7 @@ const struct mxs_fec_data mx28_fec_data[] __initconst = {
 
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata)
+		struct fec_platform_data *pdata)
 {
 	struct resource res[] = {
 		{
arch/arm/mach-mxs/include/mach/devices-common.h +0 -1
index fca0551..d206e0a 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
Quoted 9 lines

arch/arm/mach-mxs/include/mach/devices-common.h struct mxs_fec_data { · line 41

Quoted 7 lines

+++ b/arch/arm/mach-mxs/include/mach/devices-common.h

arch/arm/mach-mxs/include/mach/devices-common.h +1 -1
@@ -38,4 +38,4 @@ struct mxs_fec_data {
 };
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata);
+		struct fec_platform_data *pdata);

Why that?

pdata->mac needs to get assigned by ocotp read function.

Quoted 29 lines
Quoted 29 lines
arch/arm/mach-mxs/mach-mx28evk.c +21 -0
index def6519..d133733 100644
@@ -129,6 +129,36 @@ static struct fec_platform_data mx28_fec_pdata[] = {
 	},
 };
 
+static int __init mx28evk_fec_get_mac(void)
+{
+	int i, ret;
+	u32 val;
+
+	/*
+	 * OCOTP only stores the last 4 octets for each mac address,
+	 * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+	 * is needed.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+		if (ret)
+			goto error;
+
+		mx28_fec_pdata[i].mac[0] = 0x00;
+		mx28_fec_pdata[i].mac[1] = 0x04;
+		mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+		mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+		mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+		mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
Quoted 9 lines

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 159

Quoted 7 lines
arch/arm/mach-mxs/mach-mx28evk.c +7 -0
+	}
+
+	return 0;
+
+error:
+	pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
+	return -ETIMEDOUT;

return ret please.

OK.

Quoted 3 lines

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 160

Quoted 1 line
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
+}

I think this should be defined in a more generic place.

Necessary?

Quoted 11 lines

arch/arm/mach-mxs/mach-mx28evk.c static void __init mx28evk_init(void) · line 169

Quoted 9 lines
arch/arm/mach-mxs/mach-mx28evk.c +2 -0
+
 static void __init mx28evk_init(void)
 {
 	mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
@@ -136,6 +166,7 @@ static void __init mx28evk_init(void)
 	mx28_add_duart();
 
 	mx28evk_fec_reset();
+	mx28evk_fec_get_mac();

You ignore the return value here. Intended?

Not intended. Will check and give a warning.

Quoted 13 lines
Quoted 8 lines
arch/arm/mach-mxs/mach-mx28evk.c +0 -0
 	mx28_add_fec(0, &mx28_fec_pdata[0]);
 #ifdef CONFIG_FEC2
 	mx28_add_fec(1, &mx28_fec_pdata[1]);
Signature · 1 line
1.7.1
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Signature · 2 lines
Regards,
Shawn
#47 lore raw

PATCH 9/10 ARM: mx28: read fec mac address from ocotp

Hello Shawn,

Quoted 37 lines · Shawn Guo
Quoted 27 lines · Uwe Kleine-K?nig
Quoted 26 lines · Shawn Guo

Read fec mac address from ocotp and save it into fec_platform_data mac field for fec driver to use.

---
 arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c                |   31 +++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/devices/platform-fec.c +1 -1
index c08168c..dc978ee 100644
@@ -31,7 +31,7 @@ const struct mxs_fec_data mx28_fec_data[] __initconst = {
 
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata)
+		struct fec_platform_data *pdata)
 {
 	struct resource res[] = {
 		{
arch/arm/mach-mxs/include/mach/devices-common.h +0 -1
index fca0551..d206e0a 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
Quoted 9 lines

arch/arm/mach-mxs/include/mach/devices-common.h struct mxs_fec_data { · line 41

Quoted 7 lines

+++ b/arch/arm/mach-mxs/include/mach/devices-common.h

arch/arm/mach-mxs/include/mach/devices-common.h +1 -1
@@ -38,4 +38,4 @@ struct mxs_fec_data {
 };
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata);
+		struct fec_platform_data *pdata);

Why that?

Quoted 1 line

pdata->mac needs to get assigned by ocotp read function.

... which is done before mxs_add_fec is called.

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
arch/arm/mach-mxs/mach-mx28evk.c +21 -0
index def6519..d133733 100644
@@ -129,6 +129,36 @@ static struct fec_platform_data mx28_fec_pdata[] = {
 	},
 };
 
+static int __init mx28evk_fec_get_mac(void)
+{
+	int i, ret;
+	u32 val;
+
+	/*
+	 * OCOTP only stores the last 4 octets for each mac address,
+	 * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+	 * is needed.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+		if (ret)
+			goto error;
+
+		mx28_fec_pdata[i].mac[0] = 0x00;
+		mx28_fec_pdata[i].mac[1] = 0x04;
+		mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+		mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+		mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+		mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
Quoted 9 lines

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 159

Quoted 7 lines
arch/arm/mach-mxs/mach-mx28evk.c +7 -0
+	}
+
+	return 0;
+
+error:
+	pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
+	return -ETIMEDOUT;

return ret please.

Quoted 6 lines

OK.

Quoted 3 lines

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 160

Quoted 1 line
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
+}

I think this should be defined in a more generic place.

Necessary?

I just rechecked with the reference manual and it's not documented that 0x20 and 0x30 are used to hold the mac address. Then it's probably OK to keep this function machine-local.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
+
 static void __init mx28evk_init(void)
 {
 	mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
@@ -136,6 +166,7 @@ static void __init mx28evk_init(void)
 	mx28_add_duart();
 
Quoted 7 lines
Quoted 4 lines

arch/arm/mach-mxs/mach-mx28evk.c static void __init mx28evk_init(void) · line 169

Quoted 2 lines
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
 	mx28evk_fec_reset();
+	mx28evk_fec_get_mac();

You ignore the return value here. Intended?

Not intended. Will check and give a warning.

Quoted 1 line
Quoted 1 line
arch/arm/mach-mxs/mach-mx28evk.c +0 -0
 	mx28_add_fec(0, &mx28_fec_pdata[0]);

... and maybe skip the call to add_fec? Up to you.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#48 lore raw

PATCH 9/10 ARM: mx28: read fec mac address from ocotp

Hi Uwe,

Quoted 98 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 37 lines · Shawn Guo
Quoted 27 lines · Uwe Kleine-K?nig
Quoted 26 lines · Shawn Guo

Read fec mac address from ocotp and save it into fec_platform_data mac field for fec driver to use.

---
 arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c                |   31 +++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/devices/platform-fec.c +1 -1
index c08168c..dc978ee 100644
@@ -31,7 +31,7 @@ const struct mxs_fec_data mx28_fec_data[] __initconst = {
 
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata)
+		struct fec_platform_data *pdata)
 {
 	struct resource res[] = {
 		{
arch/arm/mach-mxs/include/mach/devices-common.h +0 -1
index fca0551..d206e0a 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
Quoted 9 lines

arch/arm/mach-mxs/include/mach/devices-common.h struct mxs_fec_data { · line 41

Quoted 7 lines

+++ b/arch/arm/mach-mxs/include/mach/devices-common.h

arch/arm/mach-mxs/include/mach/devices-common.h +1 -1
@@ -38,4 +38,4 @@ struct mxs_fec_data {
 };
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata);
+		struct fec_platform_data *pdata);

Why that?

Quoted 1 line

pdata->mac needs to get assigned by ocotp read function.

... which is done before mxs_add_fec is called.

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
arch/arm/mach-mxs/mach-mx28evk.c +21 -0
index def6519..d133733 100644
@@ -129,6 +129,36 @@ static struct fec_platform_data mx28_fec_pdata[] = {
 	},
 };
 
+static int __init mx28evk_fec_get_mac(void)
+{
+	int i, ret;
+	u32 val;
+
+	/*
+	 * OCOTP only stores the last 4 octets for each mac address,
+	 * so hard-coding the first two octets as Freescale OUI (00:04:9f)
+	 * is needed.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = mxs_read_ocotp(0x20 + i * 0x10, 1, &val);
+		if (ret)
+			goto error;
+
+		mx28_fec_pdata[i].mac[0] = 0x00;
+		mx28_fec_pdata[i].mac[1] = 0x04;
+		mx28_fec_pdata[i].mac[2] = (val >> 24) & 0xff;
+		mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
+		mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
+		mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
Quoted 9 lines

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 159

Quoted 7 lines
arch/arm/mach-mxs/mach-mx28evk.c +7 -0
+	}
+
+	return 0;
+
+error:
+	pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
+	return -ETIMEDOUT;

return ret please.

Quoted 6 lines

OK.

Quoted 3 lines

arch/arm/mach-mxs/mach-mx28evk.c static struct fec_platform_data mx28_fec_pdata[] = { · line 160

Quoted 1 line
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
+}

I think this should be defined in a more generic place.

Necessary?

I just rechecked with the reference manual and it's not documented that 0x20 and 0x30 are used to hold the mac address. Then it's probably OK to keep this function machine-local.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
+
 static void __init mx28evk_init(void)
 {
 	mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
@@ -136,6 +166,7 @@ static void __init mx28evk_init(void)
 	mx28_add_duart();
 
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

arch/arm/mach-mxs/mach-mx28evk.c static void __init mx28evk_init(void) · line 169

Quoted 2 lines
arch/arm/mach-mxs/mach-mx28evk.c +1 -0
 	mx28evk_fec_reset();
+	mx28evk_fec_get_mac();

You ignore the return value here. Intended?

Not intended. Will check and give a warning.

Quoted 1 line
Quoted 1 line
arch/arm/mach-mxs/mach-mx28evk.c +0 -0
 	mx28_add_fec(0, &mx28_fec_pdata[0]);

... and maybe skip the call to add_fec? Up to you.

I would not. fec driver still has the last chance to get mac address from fec mac registers which may set up by bootloader.

Signature · 2 lines
Regards,
Shawn
author
#49 lore raw

PATCH 9/10 ARM: mx28: read fec mac address from ocotp

In reply to Uwe Kleine-König

Hi Uwe,

Quoted 40 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 37 lines · Shawn Guo
Quoted 36 lines · Uwe Kleine-K?nig
Quoted 28 lines · Shawn Guo

Read fec mac address from ocotp and save it into fec_platform_data mac field for fec driver to use.

---
 arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c                |   31 +++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/devices/platform-fec.c +1 -1
index c08168c..dc978ee 100644
@@ -31,7 +31,7 @@ const struct mxs_fec_data mx28_fec_data[] __initconst = {
 
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata)
+		struct fec_platform_data *pdata)
 {
 	struct resource res[] = {
 		{
arch/arm/mach-mxs/include/mach/devices-common.h +0 -0
index fca0551..d206e0a 100644

arch/arm/mach-mxs/include/mach/devices-common.h struct mxs_fec_data { · line 41

Quoted 5 lines
arch/arm/mach-mxs/include/mach/devices-common.h +1 -1
@@ -38,4 +38,4 @@ struct mxs_fec_data {
 };
 struct platform_device *__init mxs_add_fec(
 		const struct mxs_fec_data *data,
-		const struct fec_platform_data *pdata);
+		struct fec_platform_data *pdata);

Why that?

Quoted 3 lines
Quoted 1 line

pdata->mac needs to get assigned by ocotp read function.

... which is done before mxs_add_fec is called.

My bad. Will add it back.

Signature · 2 lines
Regards,
Shawn
author
#50 lore raw

PATCH 10/10 ARM: mxs: add initial pm support

In reply to Shawn Guo

This is a very initial pm support and basically does nothing. With this pm support entry, drivers can start testing their own pm functions.

---
 arch/arm/mach-mxs/Makefile |    2 +-
 arch/arm/mach-mxs/pm.c     |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/pm.c
arch/arm/mach-mxs/Makefile +1 -1
index f23ebbd..020547d 100644
@@ -1,5 +1,5 @@
 # Common support
-obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
+obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o pm.o system.o timer.o
 
 obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
 obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
arch/arm/mach-mxs/pm.c new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
1.7.1
#51 lore raw

PATCH 10/10 ARM: mxs: add initial pm support

Hello Shawn,

Quoted 16 lines · Shawn Guo

This is a very initial pm support and basically does nothing. With this pm support entry, drivers can start testing their own pm functions.

---
 arch/arm/mach-mxs/Makefile |    2 +-
 arch/arm/mach-mxs/pm.c     |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/pm.c
arch/arm/mach-mxs/Makefile +0 -0
index f23ebbd..020547d 100644

arch/arm/mach-mxs/Makefile line 2

Quoted 3 lines
arch/arm/mach-mxs/Makefile +1 -1
@@ -1,5 +1,5 @@
 # Common support
-obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
+obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o pm.o system.o timer.o

I don't know what is usual here, but I guess doing

	obj-$(CONFIG_PM) += pm.o

is better. (Or CONFIG_SUSPEND?)

Quoted 41 lines
arch/arm/mach-mxs/Makefile +0 -0
 obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
 obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
arch/arm/mach-mxs/pm.c new file +33 -0
new file mode 100644
index 0000000..e4f4e31
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/suspend.h>
+#include <linux/io.h>
+#include <mach/system.h>
+
+static int mxs_suspend_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_MEM:
+		arch_idle();
+		break;
+
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static struct platform_suspend_ops mxs_suspend_ops = {

arch/arm/mach-mxs/pm.c line 43

Quoted 10 lines
arch/arm/mach-mxs/pm.c new file +10 -0
+	.enter = mxs_suspend_enter,
+	.valid = suspend_valid_only_mem,
+};
+
+static int __init mxs_pm_init(void)
+{
+	suspend_set_ops(&mxs_suspend_ops);
+	return 0;
+}
+

can you please remove this empty line?

Quoted 6 lines
arch/arm/mach-mxs/pm.c new file +1 -0
+device_initcall(mxs_pm_init);
Signature · 1 line
1.7.1
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#52 lore raw

PATCH 10/10 ARM: mxs: add initial pm support

Hi Uwe,

Quoted 24 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 16 lines · Shawn Guo

This is a very initial pm support and basically does nothing. With this pm support entry, drivers can start testing their own pm functions.

---
 arch/arm/mach-mxs/Makefile |    2 +-
 arch/arm/mach-mxs/pm.c     |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/pm.c
arch/arm/mach-mxs/Makefile +0 -0
index f23ebbd..020547d 100644

arch/arm/mach-mxs/Makefile line 2

Quoted 3 lines
arch/arm/mach-mxs/Makefile +1 -1
@@ -1,5 +1,5 @@
 # Common support
-obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
+obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o pm.o system.o timer.o

I don't know what is usual here, but I guess doing

Quoted 4 lines
	obj-$(CONFIG_PM) += pm.o

is better. (Or CONFIG_SUSPEND?)

OK.

Quoted 44 lines
Quoted 44 lines
arch/arm/mach-mxs/Makefile +0 -0
 obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
 obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
arch/arm/mach-mxs/pm.c new file +36 -0
new file mode 100644
index 0000000..e4f4e31
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/suspend.h>
+#include <linux/io.h>
+#include <mach/system.h>
+
+static int mxs_suspend_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_MEM:
+		arch_idle();
+		break;
+
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static struct platform_suspend_ops mxs_suspend_ops = {
+	.enter = mxs_suspend_enter,
+	.valid = suspend_valid_only_mem,
+};
Quoted 9 lines

arch/arm/mach-mxs/pm.c line 43

Quoted 7 lines
arch/arm/mach-mxs/pm.c new file +7 -0
+
+static int __init mxs_pm_init(void)
+{
+	suspend_set_ops(&mxs_suspend_ops);
+	return 0;
+}
+

can you please remove this empty line?

OK.

Quoted 11 lines
Quoted 6 lines
arch/arm/mach-mxs/pm.c new file +1 -0
+device_initcall(mxs_pm_init);
Signature · 1 line
1.7.1
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Signature · 2 lines
Regards,
Shawn
author
#53 lore raw

PATCH 10/10 ARM: mxs: add initial pm support

In reply to Uwe Kleine-König

Hi Uwe,

Quoted 24 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 16 lines · Shawn Guo

This is a very initial pm support and basically does nothing. With this pm support entry, drivers can start testing their own pm functions.

---
 arch/arm/mach-mxs/Makefile |    2 +-
 arch/arm/mach-mxs/pm.c     |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/pm.c
arch/arm/mach-mxs/Makefile +0 -0
index f23ebbd..020547d 100644

arch/arm/mach-mxs/Makefile line 2

Quoted 3 lines
arch/arm/mach-mxs/Makefile +1 -1
@@ -1,5 +1,5 @@
 # Common support
-obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
+obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o pm.o system.o timer.o

I don't know what is usual here, but I guess doing

Quoted 2 lines
	obj-$(CONFIG_PM) += pm.o

Will do. Thanks.

Quoted 46 lines

is better. (Or CONFIG_SUSPEND?)

Quoted 44 lines
arch/arm/mach-mxs/Makefile +0 -0
 obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
 obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
arch/arm/mach-mxs/pm.c new file +36 -0
new file mode 100644
index 0000000..e4f4e31
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/suspend.h>
+#include <linux/io.h>
+#include <mach/system.h>
+
+static int mxs_suspend_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_MEM:
+		arch_idle();
+		break;
+
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static struct platform_suspend_ops mxs_suspend_ops = {
+	.enter = mxs_suspend_enter,
+	.valid = suspend_valid_only_mem,
+};
Quoted 9 lines

arch/arm/mach-mxs/pm.c line 43

Quoted 7 lines
arch/arm/mach-mxs/pm.c new file +7 -0
+
+static int __init mxs_pm_init(void)
+{
+	suspend_set_ops(&mxs_suspend_ops);
+	return 0;
+}
+

can you please remove this empty line?

OK.

Signature · 2 lines
Regards,
Shawn
#54 lore raw

cover net/fec: add dual fec support for i.MX28

In reply to Shawn Guo

Hi Shawn,

Quoted 18 lines · Shawn Guo

This patch series is to add dual fec support for mx28, which is a mxs-based soc. Some code changes related to the following commits are also made in this patch set for some reasons.

e6b043d512fa8d9a3801bf5d72bfa3b8fc3b3cc8
netdev/fec.c: add phylib supporting to enable carrier detection (v2)

e3fe8558c7fc182972c3d947d88744482111f304
net/fec: fix pm to survive to suspend/resume

Also I do not understand one line change made in commit below.

commit 6fcc040f02d281c7e9563127358a77ce2bbfe284
net: allow FEC driver to use fixed PHY support

(quoted diff) +1 -1
-	snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
+	snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id + 1);
Quoted 2 lines

Can someone help me understand if it's really needed? The patch set can work with this change, and I'm just curious.

It is needed, at least in my case. I can't recall exactly why right at the moment though. It was either that 0 didn't work with the fixed phy setup, or it there ended up being a a duplicate id. I'll need to check on that board/setup again.

Regards
Greg

Quoted 38 lines

It's been tested on mx28 evk and mx51 babbage. For mx28, it has to work against the following patch set, which has not got merged yet.

[PATCH v8 00/15] ARM: mxs: Add initial support for MX23 and MX28

Thanks for review.

Regards,
Shawn

Shawn Guo (10):

  arch/arm/mach-mxs/Makefile                      |    2 +-
  arch/arm/mach-mxs/clock-mx28.c                  |    7 +-
  arch/arm/mach-mxs/devices/platform-fec.c        |    2 +-
  arch/arm/mach-mxs/include/mach/common.h         |    1 +
  arch/arm/mach-mxs/include/mach/devices-common.h |    2 +-
  arch/arm/mach-mxs/mach-mx28evk.c                |   59 ++++++-
  arch/arm/mach-mxs/ocotp.c                       |   52 ++++++
  arch/arm/mach-mxs/pm.c                          |   44 +++++
  drivers/net/Kconfig                             |    7 +-
  drivers/net/fec.c                               |  220 +++++++++++++++++------
  drivers/net/fec.h                               |    5 +-
  include/linux/fec.h                             |    2 +
  12 files changed, 335 insertions(+), 68 deletions(-)

[PATCH 01/10] net/fec: fix MMFR_OP type in fec_enet_mdio_write
[PATCH 02/10] net/fec: remove the use of "index" which is legacy [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac [PATCH 04/10] net/fec: improve pm for better suspend/resume
[PATCH 05/10] net/fec: add dual fec support for mx28
[PATCH 06/10] ARM: mx28: update clocks for dual fec support
[PATCH 07/10] ARM: mx28: add the second fec device registration [PATCH 08/10] ARM: mxs: add ocotp read function
[PATCH 09/10] ARM: mx28: read fec mac address from ocotp
[PATCH 10/10] ARM: mxs: add initial pm support

Signature · 5 lines
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     gerg at snapgear.com
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com