* [PATCH v2 01/10] net/fec: fix MMFR_OP type in fec_enet_mdio_write
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:24 ` [PATCH v2 02/10] net/fec: remove the use of "index" which is legacy Shawn Guo
` (8 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
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)
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
drivers/net/fec.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index cce32d4..52e9ca8 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -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);
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 02/10] net/fec: remove the use of "index" which is legacy
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
2011-01-04 9:24 ` [PATCH v2 01/10] net/fec: fix MMFR_OP type in fec_enet_mdio_write Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:24 ` [PATCH v2 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac Shawn Guo
` (7 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
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.
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
drivers/net/fec.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 52e9ca8..47f6b3b 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -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;
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
2011-01-04 9:24 ` [PATCH v2 01/10] net/fec: fix MMFR_OP type in fec_enet_mdio_write Shawn Guo
2011-01-04 9:24 ` [PATCH v2 02/10] net/fec: remove the use of "index" which is legacy Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:24 ` [PATCH v2 04/10] net/fec: improve pm for better suspend/resume Shawn Guo
` (6 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
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
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
drivers/net/fec.c | 90 ++++++++++++++++++++++++++++----------------------
include/linux/fec.h | 2 +
2 files changed, 52 insertions(+), 40 deletions(-)
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 47f6b3b..cd59814 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -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;
diff --git a/include/linux/fec.h b/include/linux/fec.h
index 5d3523d..bf0c69f 100644
--- a/include/linux/fec.h
+++ b/include/linux/fec.h
@@ -1,6 +1,7 @@
/* include/linux/fec.h
*
* Copyright (c) 2009 Orex Computed Radiography
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
* Baruch Siach <baruch@tkos.co.il>
*
* 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
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 04/10] net/fec: improve pm for better suspend/resume
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
` (2 preceding siblings ...)
2011-01-04 9:24 ` [PATCH v2 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:24 ` [PATCH v2 05/10] net/fec: add dual fec support for mx28 Shawn Guo
` (5 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
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.
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
drivers/net/fec.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index cd59814..f147508 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -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;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 05/10] net/fec: add dual fec support for mx28
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
` (3 preceding siblings ...)
2011-01-04 9:24 ` [PATCH v2 04/10] net/fec: improve pm for better suspend/resume Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:59 ` Baruch Siach
2011-01-04 9:24 ` [PATCH v2 06/10] ARM: mx28: update clocks for dual fec support Shawn Guo
` (4 subsequent siblings)
9 siblings, 1 reply; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
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.
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
Changes for v2:
- Use module parameter fec.macaddr over new kernel command line
fec_mac to pass mac address
- Update comment in fec_get_mac() to stop using confusing word
"default"
- Fix copyright breakage in fec.h
drivers/net/Kconfig | 7 ++-
drivers/net/fec.c | 139 ++++++++++++++++++++++++++++++++++++++++----------
drivers/net/fec.h | 5 +-
include/linux/fec.h | 3 +-
4 files changed, 120 insertions(+), 34 deletions(-)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 4f1755b..f34629b 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -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"
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index f147508..b2b3e37 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -17,6 +17,8 @@
*
* Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
* Copyright (c) 2004-2006 Macq Electronique SA.
+ *
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
*/
#include <linux/module.h>
@@ -45,21 +47,34 @@
#include <asm/cacheflush.h>
-#ifndef CONFIG_ARCH_MXC
+#if !defined(CONFIG_ARCH_MXC) && !defined(CONFIG_SOC_IMX28)
#include <asm/coldfire.h>
#include <asm/mcfsim.h>
#endif
#include "fec.h"
-#ifdef CONFIG_ARCH_MXC
-#include <mach/hardware.h>
+#ifdef CONFIG_SOC_IMX28
+/*
+ * mx28 does not have MIIGSK registers
+ */
+#undef FEC_MIIGSK_ENR
+#include <mach/mxs.h>
+#else
+#define cpu_is_mx28() (0)
+#endif
+
+#if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
#define FEC_ALIGNMENT 0xf
#else
#define FEC_ALIGNMENT 0x3
#endif
-static unsigned char fec_mac_default[ETH_ALEN];
+static unsigned char macaddr[ETH_ALEN];
+module_param_array(macaddr, byte, NULL, 0);
+MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
+
+static struct mii_bus *fec_mii_bus;
#if defined(CONFIG_M5272)
/*
@@ -127,7 +142,8 @@ static unsigned char fec_mac_default[ETH_ALEN];
* account when setting it.
*/
#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)
#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
#else
#define OPT_FRAME_SIZE 0
@@ -206,6 +222,17 @@ static void fec_stop(struct net_device *dev);
/* Transmitter timeout */
#define TX_TIMEOUT (2 * HZ)
+static void *swap_buffer(void *bufaddr, int len)
+{
+ int i;
+ unsigned int *buf = bufaddr;
+
+ for (i = 0; i < (len + 3) / 4; i++, buf++)
+ *buf = __swab32(*buf);
+
+ return bufaddr;
+}
+
static netdev_tx_t
fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
@@ -254,6 +281,14 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
bufaddr = fep->tx_bounce[index];
}
+ /*
+ * mx28 fec design made an incorrect assumption that it's running
+ * on a big endian system. As the result, the driver has to swap
+ * every frame going to and coming from the controller.
+ */
+ if (cpu_is_mx28())
+ swap_buffer(bufaddr, skb->len);
+
/* Save skb pointer */
fep->tx_skbuff[fep->skb_cur] = skb;
@@ -485,6 +520,9 @@ fec_enet_rx(struct net_device *dev)
dma_unmap_single(NULL, bdp->cbd_bufaddr, bdp->cbd_datlen,
DMA_FROM_DEVICE);
+ if (cpu_is_mx28())
+ swap_buffer(data, pkt_len);
+
/* This does 16 byte alignment, exactly what we need.
* The packet length includes FCS, but we don't want to
* include that when passing upstream as it messes up
@@ -540,9 +578,10 @@ static void __inline__ fec_get_mac(struct net_device *dev)
/*
* try to get mac address in following order:
*
- * 1) kernel command line fec_mac=xx:xx:xx...
+ * 1) module parameter via kernel command line in form
+ * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
*/
- iap = fec_mac_default;
+ iap = macaddr;
/*
* 2) from flash or fuse (via platform data)
@@ -570,9 +609,9 @@ static void __inline__ fec_get_mac(struct net_device *dev)
memcpy(dev->dev_addr, iap, ETH_ALEN);
- /* 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;
+ /* Adjust MAC if using macaddr */
+ if (iap == macaddr)
+ dev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->pdev->id;
}
/* ------------------------------------------------------------------------- */
@@ -686,6 +725,7 @@ static int fec_enet_mii_probe(struct net_device *dev)
char mdio_bus_id[MII_BUS_ID_SIZE];
char phy_name[MII_BUS_ID_SIZE + 3];
int phy_id;
+ int dev_id = fep->pdev->id;
fep->phy_dev = NULL;
@@ -697,6 +737,8 @@ static int fec_enet_mii_probe(struct net_device *dev)
continue;
if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
continue;
+ if (cpu_is_mx28() && dev_id--)
+ continue;
strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
break;
}
@@ -738,6 +780,28 @@ static int fec_enet_mii_init(struct platform_device *pdev)
struct fec_enet_private *fep = netdev_priv(dev);
int err = -ENXIO, i;
+ /*
+ * The dual fec interfaces are not equivalent on mx28. Here are the
+ * differences:
+ *
+ * - fec0 supports MII & RMII modes while fec1 only supports RMII
+ * - fec0 acts as the 1588 time master while fec1 is slave
+ * - external phys can only be configured by fec0
+ *
+ * That is to say fec1 can not work independently. It only works
+ * when fec0 is working. The reason behind this design is that the
+ * second interface is added primarily for Switch mode.
+ *
+ * Because of the last point above, both phys are attached on fec0
+ * mdio interface in board design, and need to be configured by
+ * fec0 mii_bus.
+ */
+ if (cpu_is_mx28() && pdev->id) {
+ /* fec1 uses fec0 mii_bus */
+ fep->mii_bus = fec_mii_bus;
+ return 0;
+ }
+
fep->mii_timeout = 0;
/*
@@ -774,6 +838,10 @@ static int fec_enet_mii_init(struct platform_device *pdev)
if (mdiobus_register(fep->mii_bus))
goto err_out_free_mdio_irq;
+ /* save fec0 mii_bus */
+ if (cpu_is_mx28())
+ fec_mii_bus = fep->mii_bus;
+
return 0;
err_out_free_mdio_irq:
@@ -1069,24 +1137,6 @@ 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.
*
@@ -1164,11 +1214,22 @@ fec_restart(struct net_device *dev, int duplex)
{
struct fec_enet_private *fep = netdev_priv(dev);
int i;
+ u32 val, temp_mac[2];
/* Whack a reset. We should wait for this. */
writel(1, fep->hwp + FEC_ECNTRL);
udelay(10);
+ /*
+ * The fec reset on mx28 will reset mac address too,
+ * so need to reconfigure it.
+ */
+ if (cpu_is_mx28()) {
+ memcpy(&temp_mac, dev->dev_addr, ETH_ALEN);
+ writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
+ writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
+ }
+
/* Clear any outstanding interrupt. */
writel(0xffc00000, fep->hwp + FEC_IEVENT);
@@ -1215,6 +1276,28 @@ fec_restart(struct net_device *dev, int duplex)
/* Set MII speed */
writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
+ /*
+ * The phy interface and speed need to get configured
+ * differently on mx28.
+ */
+ if (cpu_is_mx28()) {
+ val = readl(fep->hwp + FEC_R_CNTRL);
+
+ /* MII or RMII */
+ if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
+ val |= (1 << 8);
+ else
+ val &= ~(1 << 8);
+
+ /* 10M or 100M */
+ if (fep->phy_dev && fep->phy_dev->speed == SPEED_100)
+ val &= ~(1 << 9);
+ else
+ val |= (1 << 9);
+
+ writel(val, fep->hwp + FEC_R_CNTRL);
+ }
+
#ifdef FEC_MIIGSK_ENR
if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) {
/* disable the gasket and wait */
diff --git a/drivers/net/fec.h b/drivers/net/fec.h
index 2c48b25..ace318d 100644
--- a/drivers/net/fec.h
+++ b/drivers/net/fec.h
@@ -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 */
diff --git a/include/linux/fec.h b/include/linux/fec.h
index bf0c69f..bcff455 100644
--- a/include/linux/fec.h
+++ b/include/linux/fec.h
@@ -1,9 +1,10 @@
/* include/linux/fec.h
*
* Copyright (c) 2009 Orex Computed Radiography
- * Copyright (C) 2010 Freescale Semiconductor, Inc.
* Baruch Siach <baruch@tkos.co.il>
*
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
+ *
* Header file for the FEC platform data
*
* This program is free software; you can redistribute it and/or modify
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v2 05/10] net/fec: add dual fec support for mx28
2011-01-04 9:24 ` [PATCH v2 05/10] net/fec: add dual fec support for mx28 Shawn Guo
@ 2011-01-04 9:59 ` Baruch Siach
2011-01-04 14:13 ` Shawn Guo
0 siblings, 1 reply; 19+ messages in thread
From: Baruch Siach @ 2011-01-04 9:59 UTC (permalink / raw)
To: Shawn Guo
Cc: gerg, B32542, netdev, s.hauer, u.kleine-koenig, w.sang, r64343,
eric, bryan.wu, davem, linux-arm-kernel, lw
Hi Shawn,
On Tue, Jan 04, 2011 at 05:24:11PM +0800, Shawn Guo wrote:
> 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.
>
> Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
> ---
> Changes for v2:
> - Use module parameter fec.macaddr over new kernel command line
> fec_mac to pass mac address
Since you introduce this new kernel command line parameter in patch #3 of this
series, why not just make it right in the first place? This should make both
patches smaller and easier for review.
> - Update comment in fec_get_mac() to stop using confusing word
> "default"
> - Fix copyright breakage in fec.h
Ditto.
> drivers/net/Kconfig | 7 ++-
> drivers/net/fec.c | 139 ++++++++++++++++++++++++++++++++++++++++----------
> drivers/net/fec.h | 5 +-
> include/linux/fec.h | 3 +-
> 4 files changed, 120 insertions(+), 34 deletions(-)
[snip]
> diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> index f147508..b2b3e37 100644
> --- a/drivers/net/fec.c
> +++ b/drivers/net/fec.c
> @@ -17,6 +17,8 @@
> *
> * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
> * Copyright (c) 2004-2006 Macq Electronique SA.
> + *
> + * Copyright (C) 2010 Freescale Semiconductor, Inc.
> */
>
> #include <linux/module.h>
> @@ -45,21 +47,34 @@
>
> #include <asm/cacheflush.h>
>
> -#ifndef CONFIG_ARCH_MXC
> +#if !defined(CONFIG_ARCH_MXC) && !defined(CONFIG_SOC_IMX28)
> #include <asm/coldfire.h>
> #include <asm/mcfsim.h>
> #endif
>
> #include "fec.h"
>
> -#ifdef CONFIG_ARCH_MXC
> -#include <mach/hardware.h>
Since you now remove mach/hardware.h for ARCH_MXC, does this build for all
i.MX variants?
> +#ifdef CONFIG_SOC_IMX28
> +/*
> + * mx28 does not have MIIGSK registers
> + */
> +#undef FEC_MIIGSK_ENR
> +#include <mach/mxs.h>
> +#else
> +#define cpu_is_mx28() (0)
> +#endif
This breaks kernels for multiple archs (e.g. i.MX28 and i.MX25). Please use
run-time detection of CPU type, and do the MII/RMII etc. configuration
accordingly.
> +
> +#if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
> #define FEC_ALIGNMENT 0xf
> #else
> #define FEC_ALIGNMENT 0x3
> #endif
[snip]
baruch
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 05/10] net/fec: add dual fec support for mx28
2011-01-04 9:59 ` Baruch Siach
@ 2011-01-04 14:13 ` Shawn Guo
2011-01-04 15:07 ` Baruch Siach
2011-01-05 8:45 ` Sascha Hauer
0 siblings, 2 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 14:13 UTC (permalink / raw)
To: Baruch Siach
Cc: davem, gerg, eric, bryan.wu, r64343, B32542, u.kleine-koenig, lw,
w.sang, s.hauer, netdev, linux-arm-kernel
Hi Baruch,
On Tue, Jan 04, 2011 at 11:59:16AM +0200, Baruch Siach wrote:
> Hi Shawn,
>
> On Tue, Jan 04, 2011 at 05:24:11PM +0800, Shawn Guo wrote:
> > 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.
> >
> > Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
> > ---
> > Changes for v2:
> > - Use module parameter fec.macaddr over new kernel command line
> > fec_mac to pass mac address
>
> Since you introduce this new kernel command line parameter in patch #3 of this
> series, why not just make it right in the first place? This should make both
> patches smaller and easier for review.
>
> > - Update comment in fec_get_mac() to stop using confusing word
> > "default"
> > - Fix copyright breakage in fec.h
>
> Ditto.
>
Sorry for rushing to send the patch set out. All these updates
should happen on patch #3 than #5. This is a serious problem,
and I will fix it soon and resend as v3.
> > drivers/net/Kconfig | 7 ++-
> > drivers/net/fec.c | 139 ++++++++++++++++++++++++++++++++++++++++----------
> > drivers/net/fec.h | 5 +-
> > include/linux/fec.h | 3 +-
> > 4 files changed, 120 insertions(+), 34 deletions(-)
>
> [snip]
>
> > diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> > index f147508..b2b3e37 100644
> > --- a/drivers/net/fec.c
> > +++ b/drivers/net/fec.c
> > @@ -17,6 +17,8 @@
> > *
> > * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
> > * Copyright (c) 2004-2006 Macq Electronique SA.
> > + *
> > + * Copyright (C) 2010 Freescale Semiconductor, Inc.
> > */
> >
> > #include <linux/module.h>
> > @@ -45,21 +47,34 @@
> >
> > #include <asm/cacheflush.h>
> >
> > -#ifndef CONFIG_ARCH_MXC
> > +#if !defined(CONFIG_ARCH_MXC) && !defined(CONFIG_SOC_IMX28)
> > #include <asm/coldfire.h>
> > #include <asm/mcfsim.h>
> > #endif
> >
> > #include "fec.h"
> >
> > -#ifdef CONFIG_ARCH_MXC
> > -#include <mach/hardware.h>
>
> Since you now remove mach/hardware.h for ARCH_MXC, does this build for all
> i.MX variants?
>
Did the test build for mx25, mx27, mx3 and mx51.
> > +#ifdef CONFIG_SOC_IMX28
> > +/*
> > + * mx28 does not have MIIGSK registers
> > + */
> > +#undef FEC_MIIGSK_ENR
> > +#include <mach/mxs.h>
> > +#else
> > +#define cpu_is_mx28() (0)
> > +#endif
>
> This breaks kernels for multiple archs (e.g. i.MX28 and i.MX25). Please use
> run-time detection of CPU type, and do the MII/RMII etc. configuration
> accordingly.
>
I do not find a good way to detect cpu type. Neither adding a new
platform data field nor using __machine_arch_type to enumerate all
mx28 based machine (though there is only one currently) seems to be
good for me.
I will try to manipulate some mx28 unique register to identify mx28
from other i.mx variants. Hopefully, it will work.
Thanks for the comments.
--
Regards,
Shawn
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 05/10] net/fec: add dual fec support for mx28
2011-01-04 14:13 ` Shawn Guo
@ 2011-01-04 15:07 ` Baruch Siach
2011-01-05 8:45 ` Sascha Hauer
1 sibling, 0 replies; 19+ messages in thread
From: Baruch Siach @ 2011-01-04 15:07 UTC (permalink / raw)
To: Shawn Guo
Cc: davem, gerg, eric, bryan.wu, r64343, B32542, u.kleine-koenig, lw,
w.sang, s.hauer, netdev, linux-arm-kernel
Hi Shawn,
On Tue, Jan 04, 2011 at 10:13:09PM +0800, Shawn Guo wrote:
> On Tue, Jan 04, 2011 at 11:59:16AM +0200, Baruch Siach wrote:
> > On Tue, Jan 04, 2011 at 05:24:11PM +0800, Shawn Guo wrote:
[snip]
> > > -#ifdef CONFIG_ARCH_MXC
> > > -#include <mach/hardware.h>
> >
> > Since you now remove mach/hardware.h for ARCH_MXC, does this build for all
> > i.MX variants?
> >
> Did the test build for mx25, mx27, mx3 and mx51.
This is surprising. It means that this include was not needed in the first
place. git blame says this was added in 196719ec (fec: Add support for
Freescale MX27) by Sascha.
> > > +#ifdef CONFIG_SOC_IMX28
> > > +/*
> > > + * mx28 does not have MIIGSK registers
> > > + */
> > > +#undef FEC_MIIGSK_ENR
> > > +#include <mach/mxs.h>
> > > +#else
> > > +#define cpu_is_mx28() (0)
> > > +#endif
> >
> > This breaks kernels for multiple archs (e.g. i.MX28 and i.MX25). Please use
> > run-time detection of CPU type, and do the MII/RMII etc. configuration
> > accordingly.
> >
> I do not find a good way to detect cpu type. Neither adding a new
> platform data field nor using __machine_arch_type to enumerate all
> mx28 based machine (though there is only one currently) seems to be
> good for me.
How about:
#ifdef CONFIG_SOC_IMX28
#include <mach/mxs.h>
#else
#define cpu_is_mx28() (0)
#endif
if (cpu_is_mx28() {
/* Do i.MX28 stuff */
} else {
/* Do other i.MX stuff */
}
Note that the '#ifdef FEC_MIIGSK_ENR' section in fec_restart() is there only
to allow build for M5272 which does not have this define in fec.h. Physically,
i.MX27 does not have this register either.
> I will try to manipulate some mx28 unique register to identify mx28
> from other i.mx variants. Hopefully, it will work.
>
> Thanks for the comments.
baruch
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 05/10] net/fec: add dual fec support for mx28
2011-01-04 14:13 ` Shawn Guo
2011-01-04 15:07 ` Baruch Siach
@ 2011-01-05 8:45 ` Sascha Hauer
2011-01-05 9:03 ` Uwe Kleine-König
1 sibling, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2011-01-05 8:45 UTC (permalink / raw)
To: Shawn Guo
Cc: Baruch Siach, gerg, B32542, netdev, u.kleine-koenig, w.sang,
r64343, eric, bryan.wu, davem, linux-arm-kernel, lw
On Tue, Jan 04, 2011 at 10:13:09PM +0800, Shawn Guo wrote:
> Hi Baruch,
>
> On Tue, Jan 04, 2011 at 11:59:16AM +0200, Baruch Siach wrote:
> > Hi Shawn,
> >
> > On Tue, Jan 04, 2011 at 05:24:11PM +0800, Shawn Guo wrote:
> > > 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.
> > >
> > > Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
> > > ---
> > > Changes for v2:
> > > - Use module parameter fec.macaddr over new kernel command line
> > > fec_mac to pass mac address
> >
> > Since you introduce this new kernel command line parameter in patch #3 of this
> > series, why not just make it right in the first place? This should make both
> > patches smaller and easier for review.
> >
> > > - Update comment in fec_get_mac() to stop using confusing word
> > > "default"
> > > - Fix copyright breakage in fec.h
> >
> > Ditto.
> >
> Sorry for rushing to send the patch set out. All these updates
> should happen on patch #3 than #5. This is a serious problem,
> and I will fix it soon and resend as v3.
>
> > > drivers/net/Kconfig | 7 ++-
> > > drivers/net/fec.c | 139 ++++++++++++++++++++++++++++++++++++++++----------
> > > drivers/net/fec.h | 5 +-
> > > include/linux/fec.h | 3 +-
> > > 4 files changed, 120 insertions(+), 34 deletions(-)
> >
> > [snip]
> >
> > > diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> > > index f147508..b2b3e37 100644
> > > --- a/drivers/net/fec.c
> > > +++ b/drivers/net/fec.c
> > > @@ -17,6 +17,8 @@
> > > *
> > > * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
> > > * Copyright (c) 2004-2006 Macq Electronique SA.
> > > + *
> > > + * Copyright (C) 2010 Freescale Semiconductor, Inc.
> > > */
> > >
> > > #include <linux/module.h>
> > > @@ -45,21 +47,34 @@
> > >
> > > #include <asm/cacheflush.h>
> > >
> > > -#ifndef CONFIG_ARCH_MXC
> > > +#if !defined(CONFIG_ARCH_MXC) && !defined(CONFIG_SOC_IMX28)
> > > #include <asm/coldfire.h>
> > > #include <asm/mcfsim.h>
> > > #endif
> > >
> > > #include "fec.h"
> > >
> > > -#ifdef CONFIG_ARCH_MXC
> > > -#include <mach/hardware.h>
> >
> > Since you now remove mach/hardware.h for ARCH_MXC, does this build for all
> > i.MX variants?
> >
> Did the test build for mx25, mx27, mx3 and mx51.
>
> > > +#ifdef CONFIG_SOC_IMX28
> > > +/*
> > > + * mx28 does not have MIIGSK registers
> > > + */
> > > +#undef FEC_MIIGSK_ENR
> > > +#include <mach/mxs.h>
> > > +#else
> > > +#define cpu_is_mx28() (0)
> > > +#endif
> >
> > This breaks kernels for multiple archs (e.g. i.MX28 and i.MX25). Please use
> > run-time detection of CPU type, and do the MII/RMII etc. configuration
> > accordingly.
> >
> I do not find a good way to detect cpu type. Neither adding a new
> platform data field nor using __machine_arch_type to enumerate all
> mx28 based machine (though there is only one currently) seems to be
> good for me.
>
> I will try to manipulate some mx28 unique register to identify mx28
> from other i.mx variants. Hopefully, it will work.
There won't be a register which you can safely read on all i.MX
variants.
Why don't you implement it the same way the other i.MX do? They do not
need SoC detection and the macro expands to 0 at compile time when the
cpu is not enabled.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 05/10] net/fec: add dual fec support for mx28
2011-01-05 8:45 ` Sascha Hauer
@ 2011-01-05 9:03 ` Uwe Kleine-König
2011-01-05 9:40 ` Shawn Guo
0 siblings, 1 reply; 19+ messages in thread
From: Uwe Kleine-König @ 2011-01-05 9:03 UTC (permalink / raw)
To: Shawn Guo
Cc: Sascha Hauer, Baruch Siach, B32542, netdev, bryan.wu, gerg,
w.sang, r64343, eric, davem, linux-arm-kernel, lw
Hello Shawn,
On Wed, Jan 05, 2011 at 09:45:13AM +0100, Sascha Hauer wrote:
> On Tue, Jan 04, 2011 at 10:13:09PM +0800, Shawn Guo wrote:
> > Hi Baruch,
> >
> > On Tue, Jan 04, 2011 at 11:59:16AM +0200, Baruch Siach wrote:
> > > Hi Shawn,
> > >
> > > On Tue, Jan 04, 2011 at 05:24:11PM +0800, Shawn Guo wrote:
> > > > 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.
> > > >
> > > > Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
> > > > ---
> > > > Changes for v2:
> > > > - Use module parameter fec.macaddr over new kernel command line
> > > > fec_mac to pass mac address
> > >
> > > Since you introduce this new kernel command line parameter in patch #3 of this
> > > series, why not just make it right in the first place? This should make both
> > > patches smaller and easier for review.
> > >
> > > > - Update comment in fec_get_mac() to stop using confusing word
> > > > "default"
> > > > - Fix copyright breakage in fec.h
> > >
> > > Ditto.
> > >
> > Sorry for rushing to send the patch set out. All these updates
> > should happen on patch #3 than #5. This is a serious problem,
> > and I will fix it soon and resend as v3.
> >
> > > > drivers/net/Kconfig | 7 ++-
> > > > drivers/net/fec.c | 139 ++++++++++++++++++++++++++++++++++++++++----------
> > > > drivers/net/fec.h | 5 +-
> > > > include/linux/fec.h | 3 +-
> > > > 4 files changed, 120 insertions(+), 34 deletions(-)
> > >
> > > [snip]
> > >
> > > > diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> > > > index f147508..b2b3e37 100644
> > > > --- a/drivers/net/fec.c
> > > > +++ b/drivers/net/fec.c
> > > > @@ -17,6 +17,8 @@
> > > > *
> > > > * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
> > > > * Copyright (c) 2004-2006 Macq Electronique SA.
> > > > + *
> > > > + * Copyright (C) 2010 Freescale Semiconductor, Inc.
> > > > */
> > > >
> > > > #include <linux/module.h>
> > > > @@ -45,21 +47,34 @@
> > > >
> > > > #include <asm/cacheflush.h>
> > > >
> > > > -#ifndef CONFIG_ARCH_MXC
> > > > +#if !defined(CONFIG_ARCH_MXC) && !defined(CONFIG_SOC_IMX28)
> > > > #include <asm/coldfire.h>
> > > > #include <asm/mcfsim.h>
> > > > #endif
> > > >
> > > > #include "fec.h"
> > > >
> > > > -#ifdef CONFIG_ARCH_MXC
> > > > -#include <mach/hardware.h>
> > >
> > > Since you now remove mach/hardware.h for ARCH_MXC, does this build for all
> > > i.MX variants?
> > >
> > Did the test build for mx25, mx27, mx3 and mx51.
> >
> > > > +#ifdef CONFIG_SOC_IMX28
> > > > +/*
> > > > + * mx28 does not have MIIGSK registers
> > > > + */
> > > > +#undef FEC_MIIGSK_ENR
> > > > +#include <mach/mxs.h>
> > > > +#else
> > > > +#define cpu_is_mx28() (0)
> > > > +#endif
> > >
> > > This breaks kernels for multiple archs (e.g. i.MX28 and i.MX25). Please use
> > > run-time detection of CPU type, and do the MII/RMII etc. configuration
> > > accordingly.
> > >
> > I do not find a good way to detect cpu type. Neither adding a new
> > platform data field nor using __machine_arch_type to enumerate all
> > mx28 based machine (though there is only one currently) seems to be
> > good for me.
> >
> > I will try to manipulate some mx28 unique register to identify mx28
> > from other i.mx variants. Hopefully, it will work.
>
> There won't be a register which you can safely read on all i.MX
> variants.
> Why don't you implement it the same way the other i.MX do? They do not
> need SoC detection and the macro expands to 0 at compile time when the
> cpu is not enabled.
Alternatively you can use the approach I used for spi-imx and identify
the device by name.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 05/10] net/fec: add dual fec support for mx28
2011-01-05 9:03 ` Uwe Kleine-König
@ 2011-01-05 9:40 ` Shawn Guo
0 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-05 9:40 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Sascha Hauer, Baruch Siach, B32542, netdev, bryan.wu, gerg,
w.sang, r64343, eric, davem, linux-arm-kernel, lw
On Wed, Jan 05, 2011 at 10:03:12AM +0100, Uwe Kleine-König wrote:
> Hello Shawn,
>
> On Wed, Jan 05, 2011 at 09:45:13AM +0100, Sascha Hauer wrote:
> > On Tue, Jan 04, 2011 at 10:13:09PM +0800, Shawn Guo wrote:
> > > Hi Baruch,
> > >
> > > On Tue, Jan 04, 2011 at 11:59:16AM +0200, Baruch Siach wrote:
> > > > Hi Shawn,
> > > >
> > > > On Tue, Jan 04, 2011 at 05:24:11PM +0800, Shawn Guo wrote:
> > > > > 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.
> > > > >
> > > > > Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
> > > > > ---
> > > > > Changes for v2:
> > > > > - Use module parameter fec.macaddr over new kernel command line
> > > > > fec_mac to pass mac address
> > > >
> > > > Since you introduce this new kernel command line parameter in patch #3 of this
> > > > series, why not just make it right in the first place? This should make both
> > > > patches smaller and easier for review.
> > > >
> > > > > - Update comment in fec_get_mac() to stop using confusing word
> > > > > "default"
> > > > > - Fix copyright breakage in fec.h
> > > >
> > > > Ditto.
> > > >
> > > Sorry for rushing to send the patch set out. All these updates
> > > should happen on patch #3 than #5. This is a serious problem,
> > > and I will fix it soon and resend as v3.
> > >
> > > > > drivers/net/Kconfig | 7 ++-
> > > > > drivers/net/fec.c | 139 ++++++++++++++++++++++++++++++++++++++++----------
> > > > > drivers/net/fec.h | 5 +-
> > > > > include/linux/fec.h | 3 +-
> > > > > 4 files changed, 120 insertions(+), 34 deletions(-)
> > > >
> > > > [snip]
> > > >
> > > > > diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> > > > > index f147508..b2b3e37 100644
> > > > > --- a/drivers/net/fec.c
> > > > > +++ b/drivers/net/fec.c
> > > > > @@ -17,6 +17,8 @@
> > > > > *
> > > > > * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
> > > > > * Copyright (c) 2004-2006 Macq Electronique SA.
> > > > > + *
> > > > > + * Copyright (C) 2010 Freescale Semiconductor, Inc.
> > > > > */
> > > > >
> > > > > #include <linux/module.h>
> > > > > @@ -45,21 +47,34 @@
> > > > >
> > > > > #include <asm/cacheflush.h>
> > > > >
> > > > > -#ifndef CONFIG_ARCH_MXC
> > > > > +#if !defined(CONFIG_ARCH_MXC) && !defined(CONFIG_SOC_IMX28)
> > > > > #include <asm/coldfire.h>
> > > > > #include <asm/mcfsim.h>
> > > > > #endif
> > > > >
> > > > > #include "fec.h"
> > > > >
> > > > > -#ifdef CONFIG_ARCH_MXC
> > > > > -#include <mach/hardware.h>
> > > >
> > > > Since you now remove mach/hardware.h for ARCH_MXC, does this build for all
> > > > i.MX variants?
> > > >
> > > Did the test build for mx25, mx27, mx3 and mx51.
> > >
> > > > > +#ifdef CONFIG_SOC_IMX28
> > > > > +/*
> > > > > + * mx28 does not have MIIGSK registers
> > > > > + */
> > > > > +#undef FEC_MIIGSK_ENR
> > > > > +#include <mach/mxs.h>
> > > > > +#else
> > > > > +#define cpu_is_mx28() (0)
> > > > > +#endif
> > > >
> > > > This breaks kernels for multiple archs (e.g. i.MX28 and i.MX25). Please use
> > > > run-time detection of CPU type, and do the MII/RMII etc. configuration
> > > > accordingly.
> > > >
> > > I do not find a good way to detect cpu type. Neither adding a new
> > > platform data field nor using __machine_arch_type to enumerate all
> > > mx28 based machine (though there is only one currently) seems to be
> > > good for me.
> > >
> > > I will try to manipulate some mx28 unique register to identify mx28
> > > from other i.mx variants. Hopefully, it will work.
> >
> > There won't be a register which you can safely read on all i.MX
> > variants.FEC_TRUNC_FL
Register FEC_TRUNC_FL (offset 0x1b0) is one I found I can use to
distinguish ENET-MAC from FEC. This address is being reserved on
FEC, and I knew from designer that access the address on FEC
will not generate exception as it's valid in FEC address range.
I proved it on mx51.
/*
* Detect ENET-MAC by writing and reading back on TRUNC_FL register,
* which is accessible on ENET-MAC while always return 0 on FEC.
*/
writel(0x7ff, fep->hwp + 0x1b0);
if (readl(fep->hwp + 0x1b0) == 0x7ff)
fec_is_enetmac = 1;
But it does not matter. I more like the solution that offered by Uwe
below.
Thanks, Sascha.
> > Why don't you implement it the same way the other i.MX do? They do not
> > need SoC detection and the macro expands to 0 at compile time when the
> > cpu is not enabled.
> Alternatively you can use the approach I used for spi-imx and identify
> the device by name.
>
Thanks, Uwe.
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | http://www.pengutronix.de/ |
>
--
Regards,
Shawn
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 06/10] ARM: mx28: update clocks for dual fec support
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
` (4 preceding siblings ...)
2011-01-04 9:24 ` [PATCH v2 05/10] net/fec: add dual fec support for mx28 Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 13:58 ` Uwe Kleine-König
2011-01-04 9:24 ` [PATCH v2 07/10] ARM: mx28: add the second fec device registration Shawn Guo
` (3 subsequent siblings)
9 siblings, 1 reply; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
Register clocks fec.0 and fec.1 for dual fec support.
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
Changes for v2:
- Rebase the patch against patch below which gets fundamental
clocks explicitly called in clk_enable.
[PATCH v4] ARM: mxs: Change duart device to use amba-pl011
- Register clocks fec.0 and fec.1 respectively than use wildcard
NULL for both instances.
arch/arm/mach-mxs/clock-mx28.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index f20b254..f79587b 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -607,6 +607,7 @@ static struct clk_lookup lookups[] = {
/* for amba-pl011 driver */
_REGISTER_CLOCK("duart", NULL, uart_clk)
_REGISTER_CLOCK("fec.0", NULL, fec_clk)
+ _REGISTER_CLOCK("fec.1", NULL, fec_clk)
_REGISTER_CLOCK("rtc", NULL, rtc_clk)
_REGISTER_CLOCK("pll2", NULL, pll2_clk)
_REGISTER_CLOCK(NULL, "hclk", hbus_clk)
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v2 06/10] ARM: mx28: update clocks for dual fec support
2011-01-04 9:24 ` [PATCH v2 06/10] ARM: mx28: update clocks for dual fec support Shawn Guo
@ 2011-01-04 13:58 ` Uwe Kleine-König
2011-01-04 14:26 ` Shawn Guo
0 siblings, 1 reply; 19+ messages in thread
From: Uwe Kleine-König @ 2011-01-04 13:58 UTC (permalink / raw)
To: Shawn Guo
Cc: davem, gerg, baruch, eric, bryan.wu, r64343, B32542, lw, w.sang,
s.hauer, netdev, linux-arm-kernel
Hello Shawn,
On Tue, Jan 04, 2011 at 05:24:12PM +0800, Shawn Guo wrote:
> Register clocks fec.0 and fec.1 for dual fec support.
>
> Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
> ---
> Changes for v2:
> - Rebase the patch against patch below which gets fundamental
> clocks explicitly called in clk_enable.
> [PATCH v4] ARM: mxs: Change duart device to use amba-pl011
> - Register clocks fec.0 and fec.1 respectively than use wildcard
> NULL for both instances.
>
> arch/arm/mach-mxs/clock-mx28.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
> index f20b254..f79587b 100644
> --- a/arch/arm/mach-mxs/clock-mx28.c
> +++ b/arch/arm/mach-mxs/clock-mx28.c
> @@ -607,6 +607,7 @@ static struct clk_lookup lookups[] = {
> /* for amba-pl011 driver */
> _REGISTER_CLOCK("duart", NULL, uart_clk)
> _REGISTER_CLOCK("fec.0", NULL, fec_clk)
> + _REGISTER_CLOCK("fec.1", NULL, fec_clk)
Did you verify this works as intended? I didn't and consider it
possible that after
clk_enable("fec.0");
clk_enable("fec.1");
clk_disable("fec.1");
the clk is off. Probably it just works, just want to prevent hard to
find bugs ...
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 06/10] ARM: mx28: update clocks for dual fec support
2011-01-04 13:58 ` Uwe Kleine-König
@ 2011-01-04 14:26 ` Shawn Guo
0 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 14:26 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: davem, gerg, baruch, eric, bryan.wu, r64343, B32542, lw, w.sang,
s.hauer, netdev, linux-arm-kernel
Hi Uwe,
On Tue, Jan 04, 2011 at 02:58:18PM +0100, Uwe Kleine-König wrote:
> Hello Shawn,
>
> On Tue, Jan 04, 2011 at 05:24:12PM +0800, Shawn Guo wrote:
> > Register clocks fec.0 and fec.1 for dual fec support.
> >
> > Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
> > ---
> > Changes for v2:
> > - Rebase the patch against patch below which gets fundamental
> > clocks explicitly called in clk_enable.
> > [PATCH v4] ARM: mxs: Change duart device to use amba-pl011
> > - Register clocks fec.0 and fec.1 respectively than use wildcard
> > NULL for both instances.
> >
> > arch/arm/mach-mxs/clock-mx28.c | 1 +
> > 1 files changed, 1 insertions(+), 0 deletions(-)
> >
> > diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
> > index f20b254..f79587b 100644
> > --- a/arch/arm/mach-mxs/clock-mx28.c
> > +++ b/arch/arm/mach-mxs/clock-mx28.c
> > @@ -607,6 +607,7 @@ static struct clk_lookup lookups[] = {
> > /* for amba-pl011 driver */
> > _REGISTER_CLOCK("duart", NULL, uart_clk)
> > _REGISTER_CLOCK("fec.0", NULL, fec_clk)
> > + _REGISTER_CLOCK("fec.1", NULL, fec_clk)
> Did you verify this works as intended? I didn't and consider it
> possible that after
>
> clk_enable("fec.0");
> clk_enable("fec.1");
> clk_disable("fec.1");
>
> the clk is off. Probably it just works, just want to prevent hard to
> find bugs ...
>
The clk should not be off. Looking at _REGISTER_CLOCK below, we are
registering both fec.0 and fec.1 on the same one fec_clk. IOW, the
usecount of the clk is working to control the on/off of the clk.
#define _REGISTER_CLOCK(d, n, c) \
{ \
.dev_id = d, \
.con_id = n, \
.clk = &c, \
},
--
Regards,
Shawn
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 07/10] ARM: mx28: add the second fec device registration
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
` (5 preceding siblings ...)
2011-01-04 9:24 ` [PATCH v2 06/10] ARM: mx28: update clocks for dual fec support Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:24 ` [PATCH v2 08/10] ARM: mxs: add ocotp read function Shawn Guo
` (2 subsequent siblings)
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
arch/arm/mach-mxs/mach-mx28evk.c | 28 +++++++++++++++++++++++++---
1 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/arch/arm/mach-mxs/mach-mx28evk.c b/arch/arm/mach-mxs/mach-mx28evk.c
index d162e95..def6519 100644
--- a/arch/arm/mach-mxs/mach-mx28evk.c
+++ b/arch/arm/mach-mxs/mach-mx28evk.c
@@ -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)
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 08/10] ARM: mxs: add ocotp read function
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
` (6 preceding siblings ...)
2011-01-04 9:24 ` [PATCH v2 07/10] ARM: mx28: add the second fec device registration Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:24 ` [PATCH v2 09/10] ARM: mx28: read fec mac address from ocotp Shawn Guo
2011-01-04 9:24 ` [PATCH v2 10/10] ARM: mxs: add initial pm support Shawn Guo
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
Changes for v2:
- Add mutex locking for mxs_read_ocotp()
- Use type size_t for count and i
- Add comment for clk_enable/disable skipping
- Add ERROR bit clearing and polling step
arch/arm/mach-mxs/Makefile | 2 +-
arch/arm/mach-mxs/include/mach/common.h | 1 +
arch/arm/mach-mxs/ocotp.c | 79 +++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+), 1 deletions(-)
create mode 100644 arch/arm/mach-mxs/ocotp.c
diff --git a/arch/arm/mach-mxs/Makefile b/arch/arm/mach-mxs/Makefile
index 39d3f9c..f23ebbd 100644
--- a/arch/arm/mach-mxs/Makefile
+++ b/arch/arm/mach-mxs/Makefile
@@ -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
diff --git a/arch/arm/mach-mxs/include/mach/common.h b/arch/arm/mach-mxs/include/mach/common.h
index 59133eb..cf02552 100644
--- a/arch/arm/mach-mxs/include/mach/common.h
+++ b/arch/arm/mach-mxs/include/mach/common.h
@@ -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);
diff --git a/arch/arm/mach-mxs/ocotp.c b/arch/arm/mach-mxs/ocotp.c
new file mode 100644
index 0000000..902ef59
--- /dev/null
+++ b/arch/arm/mach-mxs/ocotp.c
@@ -0,0 +1,79 @@
+/*
+ * 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 <linux/mutex.h>
+
+#include <mach/mxs.h>
+
+#define BM_OCOTP_CTRL_BUSY (1 << 8)
+#define BM_OCOTP_CTRL_ERROR (1 << 9)
+#define BM_OCOTP_CTRL_RD_BANK_OPEN (1 << 12)
+
+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 timeout = 0x400;
+ size_t i;
+
+ mutex_lock(&ocotp_mutex);
+
+ /*
+ * clk_enable(hbus_clk) for ocotp can be skipped
+ * as it must be on when system is running.
+ */
+
+ /* try to clear ERROR bit */
+ __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_unlock;
+
+ /* 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_unlock;
+
+ 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_unlock:
+ mutex_unlock(&ocotp_mutex);
+ pr_err("%s: timeout in reading OCOTP\n", __func__);
+ return -ETIMEDOUT;
+}
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 09/10] ARM: mx28: read fec mac address from ocotp
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
` (7 preceding siblings ...)
2011-01-04 9:24 ` [PATCH v2 08/10] ARM: mxs: add ocotp read function Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
2011-01-04 9:24 ` [PATCH v2 10/10] ARM: mxs: add initial pm support Shawn Guo
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
Read fec mac address from ocotp and save it into fec_platform_data
mac field for fec driver to use.
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
Changes for v2:
- It's not necessary to remove "const" for fec_platform_data from
platform-fec.c and devices-common.h, so add it back.
- Hard-coding Freescale OUI (00:04:9f) instead of just the first
two two octets.
- Correct the return of mx28evk_fec_get_mac() and check it
with caller
arch/arm/mach-mxs/mach-mx28evk.c | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mach-mxs/mach-mx28evk.c b/arch/arm/mach-mxs/mach-mx28evk.c
index def6519..54fa512 100644
--- a/arch/arm/mach-mxs/mach-mx28evk.c
+++ b/arch/arm/mach-mxs/mach-mx28evk.c
@@ -129,12 +129,44 @@ 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-code Freescale OUI (00:04:9f) here.
+ */
+ 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] = 0x9f;
+ 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 ret;
+}
+
static void __init mx28evk_init(void)
{
mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
mx28_add_duart();
+ if (mx28evk_fec_get_mac())
+ pr_warn("%s: failed on fec mac setup\n", __func__);
+
mx28evk_fec_reset();
mx28_add_fec(0, &mx28_fec_pdata[0]);
#ifdef CONFIG_FEC2
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 10/10] ARM: mxs: add initial pm support
2011-01-04 9:24 [PATCH v2 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
` (8 preceding siblings ...)
2011-01-04 9:24 ` [PATCH v2 09/10] ARM: mx28: read fec mac address from ocotp Shawn Guo
@ 2011-01-04 9:24 ` Shawn Guo
9 siblings, 0 replies; 19+ messages in thread
From: Shawn Guo @ 2011-01-04 9:24 UTC (permalink / raw)
To: davem, gerg, baruch, eric, bryan.wu, r64343, B32542,
u.kleine-koenig
This is a very initial pm support and basically does nothing.
With this pm support entry, drivers can start testing their own
pm functions.
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
---
Changes for v2:
- Let build of pm.c depend on CONFIG_PM
- Remove the blank line above device_initcall in pm.c
arch/arm/mach-mxs/Makefile | 2 ++
arch/arm/mach-mxs/pm.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)
create mode 100644 arch/arm/mach-mxs/pm.c
diff --git a/arch/arm/mach-mxs/Makefile b/arch/arm/mach-mxs/Makefile
index f23ebbd..45a2925 100644
--- a/arch/arm/mach-mxs/Makefile
+++ b/arch/arm/mach-mxs/Makefile
@@ -1,6 +1,8 @@
# Common support
obj-y := clock.o devices.o gpio.o icoll.o iomux.o ocotp.o system.o timer.o
+obj-$(CONFIG_PM) += pm.o
+
obj-$(CONFIG_SOC_IMX23) += clock-mx23.o mm-mx23.o
obj-$(CONFIG_SOC_IMX28) += clock-mx28.o mm-mx28.o
diff --git a/arch/arm/mach-mxs/pm.c b/arch/arm/mach-mxs/pm.c
new file mode 100644
index 0000000..fb042da
--- /dev/null
+++ b/arch/arm/mach-mxs/pm.c
@@ -0,0 +1,43 @@
+/*
+ * 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,
+};
+
+static int __init mxs_pm_init(void)
+{
+ suspend_set_ops(&mxs_suspend_ops);
+ return 0;
+}
+device_initcall(mxs_pm_init);
--
1.7.1
^ permalink raw reply related [flat|nested] 19+ messages in thread