* [PATCH v2 0/3] Add device tree probe support for imx fec driver
@ 2011-07-05 15:13 Shawn Guo
2011-07-05 15:13 ` [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode Shawn Guo
` (3 more replies)
0 siblings, 4 replies; 16+ messages in thread
From: Shawn Guo @ 2011-07-05 15:13 UTC (permalink / raw)
To: linux-arm-kernel
The first two patches are a little off topic. Patch #1 adds a helper
function of_get_phy_mode into of_net, and #2 converts ibm_newemac net
driver to use this helper function. Patch #3 is the actual one adding
tree probe support for imx fec driver, with of_get_phy_mode being used.
Changes since v1:
* Address review comments given by Grant
* Add patch #1 and #2
Shawn Guo (3):
dt/net: add helper function of_get_phy_mode
net: ibm_newemac: convert it to use of_get_phy_mode
net/fec: add device tree probe support
Documentation/devicetree/bindings/net/fsl-fec.txt | 24 +++++
drivers/net/fec.c | 99 +++++++++++++++++++-
drivers/net/ibm_newemac/core.c | 33 +------
drivers/net/ibm_newemac/emac.h | 19 ++--
drivers/net/ibm_newemac/phy.c | 7 +-
drivers/of/of_net.c | 45 +++++++++
include/linux/of_net.h | 1 +
include/linux/phy.h | 4 +-
8 files changed, 186 insertions(+), 46 deletions(-)
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode
2011-07-05 15:13 [PATCH v2 0/3] Add device tree probe support for imx fec driver Shawn Guo
@ 2011-07-05 15:13 ` Shawn Guo
2011-07-05 17:35 ` Grant Likely
2011-07-05 15:13 ` [PATCH v2 2/3] net: ibm_newemac: convert it to use of_get_phy_mode Shawn Guo
` (2 subsequent siblings)
3 siblings, 1 reply; 16+ messages in thread
From: Shawn Guo @ 2011-07-05 15:13 UTC (permalink / raw)
To: linux-arm-kernel
It adds the helper function of_get_phy_mode getting phy interface
from device tree.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
drivers/of/of_net.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/linux/of_net.h | 1 +
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 86f334a..cc117db 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -8,6 +8,49 @@
#include <linux/etherdevice.h>
#include <linux/kernel.h>
#include <linux/of_net.h>
+#include <linux/phy.h>
+
+/**
+ * It maps 'enum phy_interface_t' found in include/linux/phy.h
+ * into the device tree binding of 'phy-mode', so that Ethernet
+ * device driver can get phy interface from device tree.
+ */
+static const char *phy_modes[] = {
+ [PHY_INTERFACE_MODE_MII] = "mii",
+ [PHY_INTERFACE_MODE_GMII] = "gmii",
+ [PHY_INTERFACE_MODE_SGMII] = "sgmii",
+ [PHY_INTERFACE_MODE_TBI] = "tbi",
+ [PHY_INTERFACE_MODE_RMII] = "rmii",
+ [PHY_INTERFACE_MODE_RGMII] = "rgmii",
+ [PHY_INTERFACE_MODE_RGMII_ID] = "rgmii-id",
+ [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
+ [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
+ [PHY_INTERFACE_MODE_RTBI] = "rtbi",
+};
+
+/**
+ * of_get_phy_mode - Get phy mode for given device_node
+ * @np: Pointer to the given device_node
+ *
+ * The function gets phy interface string from property 'phy-mode',
+ * and return its index in phy_modes table, or errno in error case.
+ */
+const int of_get_phy_mode(struct device_node *np)
+{
+ const char *pm;
+ int err, i;
+
+ err = of_property_read_string(np, "phy-mode", &pm);
+ if (err < 0)
+ return err;
+
+ for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
+ if (!strcasecmp(pm, phy_modes[i]))
+ return i;
+
+ return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_phy_mode);
/**
* Search the device tree for the best MAC address to use. 'mac-address' is
diff --git a/include/linux/of_net.h b/include/linux/of_net.h
index e913081..f474641 100644
--- a/include/linux/of_net.h
+++ b/include/linux/of_net.h
@@ -9,6 +9,7 @@
#ifdef CONFIG_OF_NET
#include <linux/of.h>
+extern const int of_get_phy_mode(struct device_node *np);
extern const void *of_get_mac_address(struct device_node *np);
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 2/3] net: ibm_newemac: convert it to use of_get_phy_mode
2011-07-05 15:13 [PATCH v2 0/3] Add device tree probe support for imx fec driver Shawn Guo
2011-07-05 15:13 ` [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode Shawn Guo
@ 2011-07-05 15:13 ` Shawn Guo
2011-07-05 17:38 ` Grant Likely
2011-07-05 15:13 ` [PATCH v2 3/3] net/fec: add device tree probe support Shawn Guo
2011-07-06 2:48 ` [PATCH v2 0/3] Add device tree probe support for imx fec driver David Miller
3 siblings, 1 reply; 16+ messages in thread
From: Shawn Guo @ 2011-07-05 15:13 UTC (permalink / raw)
To: linux-arm-kernel
The patch extends 'enum phy_interface_t' and of_get_phy_mode a little
bit with PHY_INTERFACE_MODE_NA and PHY_INTERFACE_MODE_SMII added,
and then converts ibm_newemac net driver to use of_get_phy_mode
getting phy mode from device tree.
It also resolves the namespace conflict on phy_read/write between
common mdiobus interface and ibm_newemac private one.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
drivers/net/ibm_newemac/core.c | 33 ++++-----------------------------
drivers/net/ibm_newemac/emac.h | 19 ++++++++++---------
drivers/net/ibm_newemac/phy.c | 7 +++++--
drivers/of/of_net.c | 2 ++
include/linux/phy.h | 4 +++-
5 files changed, 24 insertions(+), 41 deletions(-)
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 725399e..70cb7d8 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -39,6 +39,7 @@
#include <linux/bitops.h>
#include <linux/workqueue.h>
#include <linux/of.h>
+#include <linux/of_net.h>
#include <linux/slab.h>
#include <asm/processor.h>
@@ -2506,18 +2507,6 @@ static int __devinit emac_init_config(struct emac_instance *dev)
{
struct device_node *np = dev->ofdev->dev.of_node;
const void *p;
- unsigned int plen;
- const char *pm, *phy_modes[] = {
- [PHY_MODE_NA] = "",
- [PHY_MODE_MII] = "mii",
- [PHY_MODE_RMII] = "rmii",
- [PHY_MODE_SMII] = "smii",
- [PHY_MODE_RGMII] = "rgmii",
- [PHY_MODE_TBI] = "tbi",
- [PHY_MODE_GMII] = "gmii",
- [PHY_MODE_RTBI] = "rtbi",
- [PHY_MODE_SGMII] = "sgmii",
- };
/* Read config from device-tree */
if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1))
@@ -2566,23 +2555,9 @@ static int __devinit emac_init_config(struct emac_instance *dev)
dev->mal_burst_size = 256;
/* PHY mode needs some decoding */
- dev->phy_mode = PHY_MODE_NA;
- pm = of_get_property(np, "phy-mode", &plen);
- if (pm != NULL) {
- int i;
- for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
- if (!strcasecmp(pm, phy_modes[i])) {
- dev->phy_mode = i;
- break;
- }
- }
-
- /* Backward compat with non-final DT */
- if (dev->phy_mode == PHY_MODE_NA && pm != NULL && plen == 4) {
- u32 nmode = *(const u32 *)pm;
- if (nmode > PHY_MODE_NA && nmode <= PHY_MODE_SGMII)
- dev->phy_mode = nmode;
- }
+ dev->phy_mode = of_get_phy_mode(np);
+ if (dev->phy_mode < 0)
+ dev->phy_mode = PHY_MODE_NA;
/* Check EMAC version */
if (of_device_is_compatible(np, "ibm,emac4sync")) {
diff --git a/drivers/net/ibm_newemac/emac.h b/drivers/net/ibm_newemac/emac.h
index 8a61b597..1568278 100644
--- a/drivers/net/ibm_newemac/emac.h
+++ b/drivers/net/ibm_newemac/emac.h
@@ -26,6 +26,7 @@
#define __IBM_NEWEMAC_H
#include <linux/types.h>
+#include <linux/phy.h>
/* EMAC registers Write Access rules */
struct emac_regs {
@@ -106,15 +107,15 @@ struct emac_regs {
/*
* PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY)
*/
-#define PHY_MODE_NA 0
-#define PHY_MODE_MII 1
-#define PHY_MODE_RMII 2
-#define PHY_MODE_SMII 3
-#define PHY_MODE_RGMII 4
-#define PHY_MODE_TBI 5
-#define PHY_MODE_GMII 6
-#define PHY_MODE_RTBI 7
-#define PHY_MODE_SGMII 8
+#define PHY_MODE_NA PHY_INTERFACE_MODE_NA
+#define PHY_MODE_MII PHY_INTERFACE_MODE_MII
+#define PHY_MODE_RMII PHY_INTERFACE_MODE_RMII
+#define PHY_MODE_SMII PHY_INTERFACE_MODE_SMII
+#define PHY_MODE_RGMII PHY_INTERFACE_MODE_RGMII
+#define PHY_MODE_TBI PHY_INTERFACE_MODE_TBI
+#define PHY_MODE_GMII PHY_INTERFACE_MODE_GMII
+#define PHY_MODE_RTBI PHY_INTERFACE_MODE_RTBI
+#define PHY_MODE_SGMII PHY_INTERFACE_MODE_SGMII
/* EMACx_MR0 */
#define EMAC_MR0_RXI 0x80000000
diff --git a/drivers/net/ibm_newemac/phy.c b/drivers/net/ibm_newemac/phy.c
index ac9d964..ab4e596 100644
--- a/drivers/net/ibm_newemac/phy.c
+++ b/drivers/net/ibm_newemac/phy.c
@@ -28,12 +28,15 @@
#include "emac.h"
#include "phy.h"
-static inline int phy_read(struct mii_phy *phy, int reg)
+#define phy_read _phy_read
+#define phy_write _phy_write
+
+static inline int _phy_read(struct mii_phy *phy, int reg)
{
return phy->mdio_read(phy->dev, phy->address, reg);
}
-static inline void phy_write(struct mii_phy *phy, int reg, int val)
+static inline void _phy_write(struct mii_phy *phy, int reg, int val)
{
phy->mdio_write(phy->dev, phy->address, reg, val);
}
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index cc117db..bb18471 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -16,6 +16,7 @@
* device driver can get phy interface from device tree.
*/
static const char *phy_modes[] = {
+ [PHY_INTERFACE_MODE_NA] = "",
[PHY_INTERFACE_MODE_MII] = "mii",
[PHY_INTERFACE_MODE_GMII] = "gmii",
[PHY_INTERFACE_MODE_SGMII] = "sgmii",
@@ -26,6 +27,7 @@ static const char *phy_modes[] = {
[PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
[PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
[PHY_INTERFACE_MODE_RTBI] = "rtbi",
+ [PHY_INTERFACE_MODE_SMII] = "smii",
};
/**
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 7da5fa8..1622081 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -53,6 +53,7 @@
/* Interface Mode definitions */
typedef enum {
+ PHY_INTERFACE_MODE_NA,
PHY_INTERFACE_MODE_MII,
PHY_INTERFACE_MODE_GMII,
PHY_INTERFACE_MODE_SGMII,
@@ -62,7 +63,8 @@ typedef enum {
PHY_INTERFACE_MODE_RGMII_ID,
PHY_INTERFACE_MODE_RGMII_RXID,
PHY_INTERFACE_MODE_RGMII_TXID,
- PHY_INTERFACE_MODE_RTBI
+ PHY_INTERFACE_MODE_RTBI,
+ PHY_INTERFACE_MODE_SMII,
} phy_interface_t;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 3/3] net/fec: add device tree probe support
2011-07-05 15:13 [PATCH v2 0/3] Add device tree probe support for imx fec driver Shawn Guo
2011-07-05 15:13 ` [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode Shawn Guo
2011-07-05 15:13 ` [PATCH v2 2/3] net: ibm_newemac: convert it to use of_get_phy_mode Shawn Guo
@ 2011-07-05 15:13 ` Shawn Guo
2011-07-05 17:42 ` Grant Likely
2011-07-06 16:22 ` [PATCH RESEND " Shawn Guo
2011-07-06 2:48 ` [PATCH v2 0/3] Add device tree probe support for imx fec driver David Miller
3 siblings, 2 replies; 16+ messages in thread
From: Shawn Guo @ 2011-07-05 15:13 UTC (permalink / raw)
To: linux-arm-kernel
It adds device tree probe support for fec driver.
Signed-off-by: Jason Liu <jason.hui@linaro.org>
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
---
Documentation/devicetree/bindings/net/fsl-fec.txt | 24 +++++
drivers/net/fec.c | 99 +++++++++++++++++++-
2 files changed, 118 insertions(+), 5 deletions(-)
create mode 100644 Documentation/devicetree/bindings/net/fsl-fec.txt
diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt b/Documentation/devicetree/bindings/net/fsl-fec.txt
new file mode 100644
index 0000000..1dad888
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
@@ -0,0 +1,24 @@
+* Freescale Fast Ethernet Controller (FEC)
+
+Required properties:
+- compatible : Should be "fsl,<soc>-fec"
+- reg : Address and length of the register set for the device
+- interrupts : Should contain fec interrupt
+- phy-mode : String, operation mode of the PHY interface.
+ Supported values are: "mii", "gmii", "sgmii", "tbi", "rmii",
+ "rgmii", "rgmii-id", "rgmii-rxid", "rgmii-txid", "rtbi".
+- gpios : Should specify the gpio for phy reset
+
+Optional properties:
+- local-mac-address : 6 bytes, mac address
+
+Example:
+
+fec at 83fec000 {
+ compatible = "fsl,imx51-fec", "fsl,imx27-fec";
+ reg = <0x83fec000 0x4000>;
+ interrupts = <87>;
+ phy-mode = "mii";
+ gpios = <&gpio1 14 0>; /* phy-reset, GPIO2_14 */
+ local-mac-address = [00 04 9F 01 1B B9];
+};
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 7ae3f28..dec94f4 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -44,6 +44,10 @@
#include <linux/platform_device.h>
#include <linux/phy.h>
#include <linux/fec.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_net.h>
#include <asm/cacheflush.h>
@@ -78,6 +82,17 @@ static struct platform_device_id fec_devtype[] = {
{ }
};
+enum fec_type {
+ IMX27_FEC,
+ IMX28_FEC,
+};
+
+static const struct of_device_id fec_dt_ids[] = {
+ { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
+ { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
+ { /* sentinel */ }
+};
+
static unsigned char macaddr[ETH_ALEN];
module_param_array(macaddr, byte, NULL, 0);
MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
@@ -734,8 +749,22 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
*/
iap = macaddr;
+#ifdef CONFIG_OF
+ /*
+ * 2) from device tree data
+ */
+ if (!is_valid_ether_addr(iap)) {
+ struct device_node *np = fep->pdev->dev.of_node;
+ if (np) {
+ const char *mac = of_get_mac_address(np);
+ if (mac)
+ iap = (unsigned char *) mac;
+ }
+ }
+#endif
+
/*
- * 2) from flash or fuse (via platform data)
+ * 3) from flash or fuse (via platform data)
*/
if (!is_valid_ether_addr(iap)) {
#ifdef CONFIG_M5272
@@ -748,7 +777,7 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
}
/*
- * 3) FEC mac registers set by bootloader
+ * 4) FEC mac registers set by bootloader
*/
if (!is_valid_ether_addr(iap)) {
*((unsigned long *) &tmpaddr[0]) =
@@ -1358,6 +1387,53 @@ static int fec_enet_init(struct net_device *ndev)
return 0;
}
+#ifdef CONFIG_OF
+static int __devinit fec_get_phy_mode_dt(struct platform_device *pdev)
+{
+ struct device_node *np = pdev->dev.of_node;
+
+ if (np)
+ return of_get_phy_mode(np);
+
+ return -ENODEV;
+}
+
+static int __devinit fec_reset_phy(struct platform_device *pdev)
+{
+ int err, phy_reset;
+ struct device_node *np = pdev->dev.of_node;
+
+ if (!np)
+ return -ENODEV;
+
+ phy_reset = of_get_gpio(np, 0);
+ err = gpio_request_one(phy_reset, GPIOF_OUT_INIT_LOW, "phy-reset");
+ if (err) {
+ pr_warn("FEC: failed to get gpio phy-reset: %d\n", err);
+ return err;
+ }
+
+ msleep(1);
+ gpio_set_value(phy_reset, 1);
+
+ return 0;
+}
+#else /* CONFIG_OF */
+static inline int fec_get_phy_mode_dt(struct platform_device *pdev)
+{
+ return -ENODEV;
+}
+
+static inline int fec_reset_phy(struct platform_device *pdev)
+{
+ /*
+ * In case of platform probe, the reset has been done
+ * by machine code.
+ */
+ return 0;
+}
+#endif /* CONFIG_OF */
+
static int __devinit
fec_probe(struct platform_device *pdev)
{
@@ -1366,6 +1442,11 @@ fec_probe(struct platform_device *pdev)
struct net_device *ndev;
int i, irq, ret = 0;
struct resource *r;
+ const struct of_device_id *of_id;
+
+ of_id = of_match_device(fec_dt_ids, &pdev->dev);
+ if (of_id)
+ pdev->id_entry = of_id->data;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r)
@@ -1397,9 +1478,16 @@ fec_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ndev);
- pdata = pdev->dev.platform_data;
- if (pdata)
- fep->phy_interface = pdata->phy;
+ fep->phy_interface = fec_get_phy_mode_dt(pdev);
+ if (fep->phy_interface < 0) {
+ pdata = pdev->dev.platform_data;
+ if (pdata)
+ fep->phy_interface = pdata->phy;
+ else
+ fep->phy_interface = PHY_INTERFACE_MODE_MII;
+ }
+
+ fec_reset_phy(pdev);
/* This device has up to three irqs on some platforms */
for (i = 0; i < 3; i++) {
@@ -1534,6 +1622,7 @@ static struct platform_driver fec_driver = {
#ifdef CONFIG_PM
.pm = &fec_pm_ops,
#endif
+ .of_match_table = fec_dt_ids,
},
.id_table = fec_devtype,
.probe = fec_probe,
--
1.7.4.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode
2011-07-05 15:13 ` [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode Shawn Guo
@ 2011-07-05 17:35 ` Grant Likely
0 siblings, 0 replies; 16+ messages in thread
From: Grant Likely @ 2011-07-05 17:35 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 5, 2011 at 9:13 AM, Shawn Guo <shawn.guo@linaro.org> wrote:
> It adds the helper function of_get_phy_mode getting phy interface
> from device tree.
>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> Cc: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Dave, this should probably get merged via your tree since the rest of
this series depends on it.
g.
> ---
> ?drivers/of/of_net.c ? ?| ? 43 +++++++++++++++++++++++++++++++++++++++++++
> ?include/linux/of_net.h | ? ?1 +
> ?2 files changed, 44 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
> index 86f334a..cc117db 100644
> --- a/drivers/of/of_net.c
> +++ b/drivers/of/of_net.c
> @@ -8,6 +8,49 @@
> ?#include <linux/etherdevice.h>
> ?#include <linux/kernel.h>
> ?#include <linux/of_net.h>
> +#include <linux/phy.h>
> +
> +/**
> + * It maps 'enum phy_interface_t' found in include/linux/phy.h
> + * into the device tree binding of 'phy-mode', so that Ethernet
> + * device driver can get phy interface from device tree.
> + */
> +static const char *phy_modes[] = {
> + ? ? ? [PHY_INTERFACE_MODE_MII] ? ? ? ?= "mii",
> + ? ? ? [PHY_INTERFACE_MODE_GMII] ? ? ? = "gmii",
> + ? ? ? [PHY_INTERFACE_MODE_SGMII] ? ? ?= "sgmii",
> + ? ? ? [PHY_INTERFACE_MODE_TBI] ? ? ? ?= "tbi",
> + ? ? ? [PHY_INTERFACE_MODE_RMII] ? ? ? = "rmii",
> + ? ? ? [PHY_INTERFACE_MODE_RGMII] ? ? ?= "rgmii",
> + ? ? ? [PHY_INTERFACE_MODE_RGMII_ID] ? = "rgmii-id",
> + ? ? ? [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
> + ? ? ? [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
> + ? ? ? [PHY_INTERFACE_MODE_RTBI] ? ? ? = "rtbi",
> +};
> +
> +/**
> + * of_get_phy_mode - Get phy mode for given device_node
> + * @np: ? ? ? ?Pointer to the given device_node
> + *
> + * The function gets phy interface string from property 'phy-mode',
> + * and return its index in phy_modes table, or errno in error case.
> + */
> +const int of_get_phy_mode(struct device_node *np)
> +{
> + ? ? ? const char *pm;
> + ? ? ? int err, i;
> +
> + ? ? ? err = of_property_read_string(np, "phy-mode", &pm);
> + ? ? ? if (err < 0)
> + ? ? ? ? ? ? ? return err;
> +
> + ? ? ? for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
> + ? ? ? ? ? ? ? if (!strcasecmp(pm, phy_modes[i]))
> + ? ? ? ? ? ? ? ? ? ? ? return i;
> +
> + ? ? ? return -ENODEV;
> +}
> +EXPORT_SYMBOL_GPL(of_get_phy_mode);
>
> ?/**
> ?* Search the device tree for the best MAC address to use. ?'mac-address' is
> diff --git a/include/linux/of_net.h b/include/linux/of_net.h
> index e913081..f474641 100644
> --- a/include/linux/of_net.h
> +++ b/include/linux/of_net.h
> @@ -9,6 +9,7 @@
>
> ?#ifdef CONFIG_OF_NET
> ?#include <linux/of.h>
> +extern const int of_get_phy_mode(struct device_node *np);
> ?extern const void *of_get_mac_address(struct device_node *np);
> ?#endif
>
> --
> 1.7.4.1
>
>
>
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 2/3] net: ibm_newemac: convert it to use of_get_phy_mode
2011-07-05 15:13 ` [PATCH v2 2/3] net: ibm_newemac: convert it to use of_get_phy_mode Shawn Guo
@ 2011-07-05 17:38 ` Grant Likely
0 siblings, 0 replies; 16+ messages in thread
From: Grant Likely @ 2011-07-05 17:38 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 5, 2011 at 9:13 AM, Shawn Guo <shawn.guo@linaro.org> wrote:
> The patch extends 'enum phy_interface_t' and of_get_phy_mode a little
> bit with PHY_INTERFACE_MODE_NA and PHY_INTERFACE_MODE_SMII added,
> and then converts ibm_newemac net driver to use of_get_phy_mode
> getting phy mode from device tree.
>
> It also resolves the namespace conflict on phy_read/write between
> common mdiobus interface and ibm_newemac private one.
>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Grant Likely <grant.likely@secretlab.ca>
I'm okay with this, but I'm don't know if it is a good idea to add the
new PHY_INTERFACE_MODE defines (but I cannot think of a reason why
not). I'll let someone else comment on that.
Acked-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> ?drivers/net/ibm_newemac/core.c | ? 33 ++++-----------------------------
> ?drivers/net/ibm_newemac/emac.h | ? 19 ++++++++++---------
> ?drivers/net/ibm_newemac/phy.c ?| ? ?7 +++++--
> ?drivers/of/of_net.c ? ? ? ? ? ?| ? ?2 ++
> ?include/linux/phy.h ? ? ? ? ? ?| ? ?4 +++-
> ?5 files changed, 24 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
> index 725399e..70cb7d8 100644
> --- a/drivers/net/ibm_newemac/core.c
> +++ b/drivers/net/ibm_newemac/core.c
> @@ -39,6 +39,7 @@
> ?#include <linux/bitops.h>
> ?#include <linux/workqueue.h>
> ?#include <linux/of.h>
> +#include <linux/of_net.h>
> ?#include <linux/slab.h>
>
> ?#include <asm/processor.h>
> @@ -2506,18 +2507,6 @@ static int __devinit emac_init_config(struct emac_instance *dev)
> ?{
> ? ? ? ?struct device_node *np = dev->ofdev->dev.of_node;
> ? ? ? ?const void *p;
> - ? ? ? unsigned int plen;
> - ? ? ? const char *pm, *phy_modes[] = {
> - ? ? ? ? ? ? ? [PHY_MODE_NA] = "",
> - ? ? ? ? ? ? ? [PHY_MODE_MII] = "mii",
> - ? ? ? ? ? ? ? [PHY_MODE_RMII] = "rmii",
> - ? ? ? ? ? ? ? [PHY_MODE_SMII] = "smii",
> - ? ? ? ? ? ? ? [PHY_MODE_RGMII] = "rgmii",
> - ? ? ? ? ? ? ? [PHY_MODE_TBI] = "tbi",
> - ? ? ? ? ? ? ? [PHY_MODE_GMII] = "gmii",
> - ? ? ? ? ? ? ? [PHY_MODE_RTBI] = "rtbi",
> - ? ? ? ? ? ? ? [PHY_MODE_SGMII] = "sgmii",
> - ? ? ? };
>
> ? ? ? ?/* Read config from device-tree */
> ? ? ? ?if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1))
> @@ -2566,23 +2555,9 @@ static int __devinit emac_init_config(struct emac_instance *dev)
> ? ? ? ? ? ? ? ?dev->mal_burst_size = 256;
>
> ? ? ? ?/* PHY mode needs some decoding */
> - ? ? ? dev->phy_mode = PHY_MODE_NA;
> - ? ? ? pm = of_get_property(np, "phy-mode", &plen);
> - ? ? ? if (pm != NULL) {
> - ? ? ? ? ? ? ? int i;
> - ? ? ? ? ? ? ? for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
> - ? ? ? ? ? ? ? ? ? ? ? if (!strcasecmp(pm, phy_modes[i])) {
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dev->phy_mode = i;
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
> - ? ? ? ? ? ? ? ? ? ? ? }
> - ? ? ? }
> -
> - ? ? ? /* Backward compat with non-final DT */
> - ? ? ? if (dev->phy_mode == PHY_MODE_NA && pm != NULL && plen == 4) {
> - ? ? ? ? ? ? ? u32 nmode = *(const u32 *)pm;
> - ? ? ? ? ? ? ? if (nmode > PHY_MODE_NA && nmode <= PHY_MODE_SGMII)
> - ? ? ? ? ? ? ? ? ? ? ? dev->phy_mode = nmode;
> - ? ? ? }
> + ? ? ? dev->phy_mode = of_get_phy_mode(np);
> + ? ? ? if (dev->phy_mode < 0)
> + ? ? ? ? ? ? ? dev->phy_mode = PHY_MODE_NA;
>
> ? ? ? ?/* Check EMAC version */
> ? ? ? ?if (of_device_is_compatible(np, "ibm,emac4sync")) {
> diff --git a/drivers/net/ibm_newemac/emac.h b/drivers/net/ibm_newemac/emac.h
> index 8a61b597..1568278 100644
> --- a/drivers/net/ibm_newemac/emac.h
> +++ b/drivers/net/ibm_newemac/emac.h
> @@ -26,6 +26,7 @@
> ?#define __IBM_NEWEMAC_H
>
> ?#include <linux/types.h>
> +#include <linux/phy.h>
>
> ?/* EMAC registers ? ? ? ? ? ? ? ? ? ? ?Write Access rules */
> ?struct emac_regs {
> @@ -106,15 +107,15 @@ struct emac_regs {
> ?/*
> ?* PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY)
> ?*/
> -#define PHY_MODE_NA ? ?0
> -#define PHY_MODE_MII ? 1
> -#define PHY_MODE_RMII ?2
> -#define PHY_MODE_SMII ?3
> -#define PHY_MODE_RGMII 4
> -#define PHY_MODE_TBI ? 5
> -#define PHY_MODE_GMII ?6
> -#define PHY_MODE_RTBI ?7
> -#define PHY_MODE_SGMII 8
> +#define PHY_MODE_NA ? ?PHY_INTERFACE_MODE_NA
> +#define PHY_MODE_MII ? PHY_INTERFACE_MODE_MII
> +#define PHY_MODE_RMII ?PHY_INTERFACE_MODE_RMII
> +#define PHY_MODE_SMII ?PHY_INTERFACE_MODE_SMII
> +#define PHY_MODE_RGMII PHY_INTERFACE_MODE_RGMII
> +#define PHY_MODE_TBI ? PHY_INTERFACE_MODE_TBI
> +#define PHY_MODE_GMII ?PHY_INTERFACE_MODE_GMII
> +#define PHY_MODE_RTBI ?PHY_INTERFACE_MODE_RTBI
> +#define PHY_MODE_SGMII PHY_INTERFACE_MODE_SGMII
>
> ?/* EMACx_MR0 */
> ?#define EMAC_MR0_RXI ? ? ? ? ? ? ? ? ? 0x80000000
> diff --git a/drivers/net/ibm_newemac/phy.c b/drivers/net/ibm_newemac/phy.c
> index ac9d964..ab4e596 100644
> --- a/drivers/net/ibm_newemac/phy.c
> +++ b/drivers/net/ibm_newemac/phy.c
> @@ -28,12 +28,15 @@
> ?#include "emac.h"
> ?#include "phy.h"
>
> -static inline int phy_read(struct mii_phy *phy, int reg)
> +#define phy_read _phy_read
> +#define phy_write _phy_write
> +
> +static inline int _phy_read(struct mii_phy *phy, int reg)
> ?{
> ? ? ? ?return phy->mdio_read(phy->dev, phy->address, reg);
> ?}
>
> -static inline void phy_write(struct mii_phy *phy, int reg, int val)
> +static inline void _phy_write(struct mii_phy *phy, int reg, int val)
> ?{
> ? ? ? ?phy->mdio_write(phy->dev, phy->address, reg, val);
> ?}
> diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
> index cc117db..bb18471 100644
> --- a/drivers/of/of_net.c
> +++ b/drivers/of/of_net.c
> @@ -16,6 +16,7 @@
> ?* device driver can get phy interface from device tree.
> ?*/
> ?static const char *phy_modes[] = {
> + ? ? ? [PHY_INTERFACE_MODE_NA] ? ? ? ? = "",
> ? ? ? ?[PHY_INTERFACE_MODE_MII] ? ? ? ?= "mii",
> ? ? ? ?[PHY_INTERFACE_MODE_GMII] ? ? ? = "gmii",
> ? ? ? ?[PHY_INTERFACE_MODE_SGMII] ? ? ?= "sgmii",
> @@ -26,6 +27,7 @@ static const char *phy_modes[] = {
> ? ? ? ?[PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
> ? ? ? ?[PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
> ? ? ? ?[PHY_INTERFACE_MODE_RTBI] ? ? ? = "rtbi",
> + ? ? ? [PHY_INTERFACE_MODE_SMII] ? ? ? = "smii",
> ?};
>
> ?/**
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 7da5fa8..1622081 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -53,6 +53,7 @@
>
> ?/* Interface Mode definitions */
> ?typedef enum {
> + ? ? ? PHY_INTERFACE_MODE_NA,
> ? ? ? ?PHY_INTERFACE_MODE_MII,
> ? ? ? ?PHY_INTERFACE_MODE_GMII,
> ? ? ? ?PHY_INTERFACE_MODE_SGMII,
> @@ -62,7 +63,8 @@ typedef enum {
> ? ? ? ?PHY_INTERFACE_MODE_RGMII_ID,
> ? ? ? ?PHY_INTERFACE_MODE_RGMII_RXID,
> ? ? ? ?PHY_INTERFACE_MODE_RGMII_TXID,
> - ? ? ? PHY_INTERFACE_MODE_RTBI
> + ? ? ? PHY_INTERFACE_MODE_RTBI,
> + ? ? ? PHY_INTERFACE_MODE_SMII,
> ?} phy_interface_t;
>
>
> --
> 1.7.4.1
>
>
>
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 3/3] net/fec: add device tree probe support
2011-07-05 15:13 ` [PATCH v2 3/3] net/fec: add device tree probe support Shawn Guo
@ 2011-07-05 17:42 ` Grant Likely
2011-07-06 16:22 ` [PATCH RESEND " Shawn Guo
1 sibling, 0 replies; 16+ messages in thread
From: Grant Likely @ 2011-07-05 17:42 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 5, 2011 at 9:13 AM, Shawn Guo <shawn.guo@linaro.org> wrote:
> It adds device tree probe support for fec driver.
>
> Signed-off-by: Jason Liu <jason.hui@linaro.org>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
Minor comments below, but my Acked-by above still stands.
g.
> ---
> ?Documentation/devicetree/bindings/net/fsl-fec.txt | ? 24 +++++
> ?drivers/net/fec.c ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ? 99 +++++++++++++++++++-
> ?2 files changed, 118 insertions(+), 5 deletions(-)
> ?create mode 100644 Documentation/devicetree/bindings/net/fsl-fec.txt
>
> diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt b/Documentation/devicetree/bindings/net/fsl-fec.txt
> new file mode 100644
> index 0000000..1dad888
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
> @@ -0,0 +1,24 @@
> +* Freescale Fast Ethernet Controller (FEC)
> +
> +Required properties:
> +- compatible : Should be "fsl,<soc>-fec"
> +- reg : Address and length of the register set for the device
> +- interrupts : Should contain fec interrupt
> +- phy-mode : String, operation mode of the PHY interface.
> + ?Supported values are: "mii", "gmii", "sgmii", "tbi", "rmii",
> + ?"rgmii", "rgmii-id", "rgmii-rxid", "rgmii-txid", "rtbi".
> +- gpios : Should specify the gpio for phy reset
Let's be explicit for the gpio property: phy-reset-gpios.
> +
> +Optional properties:
> +- local-mac-address : 6 bytes, mac address
> +
> +Example:
> +
> +fec at 83fec000 {
> + ? ? ? compatible = "fsl,imx51-fec", "fsl,imx27-fec";
> + ? ? ? reg = <0x83fec000 0x4000>;
> + ? ? ? interrupts = <87>;
> + ? ? ? phy-mode = "mii";
> + ? ? ? gpios = <&gpio1 14 0>; /* phy-reset, GPIO2_14 */
> + ? ? ? local-mac-address = [00 04 9F 01 1B B9];
> +};
> diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> index 7ae3f28..dec94f4 100644
> --- a/drivers/net/fec.c
> +++ b/drivers/net/fec.c
> @@ -44,6 +44,10 @@
> ?#include <linux/platform_device.h>
> ?#include <linux/phy.h>
> ?#include <linux/fec.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_net.h>
>
> ?#include <asm/cacheflush.h>
>
> @@ -78,6 +82,17 @@ static struct platform_device_id fec_devtype[] = {
> ? ? ? ?{ }
> ?};
>
> +enum fec_type {
> + ? ? ? IMX27_FEC,
> + ? ? ? IMX28_FEC,
> +};
> +
> +static const struct of_device_id fec_dt_ids[] = {
> + ? ? ? { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
> + ? ? ? { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
> + ? ? ? { /* sentinel */ }
> +};
> +
> ?static unsigned char macaddr[ETH_ALEN];
> ?module_param_array(macaddr, byte, NULL, 0);
> ?MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
> @@ -734,8 +749,22 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
> ? ? ? ? */
> ? ? ? ?iap = macaddr;
>
> +#ifdef CONFIG_OF
> + ? ? ? /*
> + ? ? ? ?* 2) from device tree data
> + ? ? ? ?*/
> + ? ? ? if (!is_valid_ether_addr(iap)) {
> + ? ? ? ? ? ? ? struct device_node *np = fep->pdev->dev.of_node;
> + ? ? ? ? ? ? ? if (np) {
> + ? ? ? ? ? ? ? ? ? ? ? const char *mac = of_get_mac_address(np);
> + ? ? ? ? ? ? ? ? ? ? ? if (mac)
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? iap = (unsigned char *) mac;
> + ? ? ? ? ? ? ? }
> + ? ? ? }
> +#endif
> +
> ? ? ? ?/*
> - ? ? ? ?* 2) from flash or fuse (via platform data)
> + ? ? ? ?* 3) from flash or fuse (via platform data)
> ? ? ? ? */
> ? ? ? ?if (!is_valid_ether_addr(iap)) {
> ?#ifdef CONFIG_M5272
> @@ -748,7 +777,7 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
> ? ? ? ?}
>
> ? ? ? ?/*
> - ? ? ? ?* 3) FEC mac registers set by bootloader
> + ? ? ? ?* 4) FEC mac registers set by bootloader
> ? ? ? ? */
> ? ? ? ?if (!is_valid_ether_addr(iap)) {
> ? ? ? ? ? ? ? ?*((unsigned long *) &tmpaddr[0]) =
> @@ -1358,6 +1387,53 @@ static int fec_enet_init(struct net_device *ndev)
> ? ? ? ?return 0;
> ?}
>
> +#ifdef CONFIG_OF
> +static int __devinit fec_get_phy_mode_dt(struct platform_device *pdev)
> +{
> + ? ? ? struct device_node *np = pdev->dev.of_node;
> +
> + ? ? ? if (np)
> + ? ? ? ? ? ? ? return of_get_phy_mode(np);
> +
> + ? ? ? return -ENODEV;
> +}
> +
> +static int __devinit fec_reset_phy(struct platform_device *pdev)
> +{
> + ? ? ? int err, phy_reset;
> + ? ? ? struct device_node *np = pdev->dev.of_node;
> +
> + ? ? ? if (!np)
> + ? ? ? ? ? ? ? return -ENODEV;
> +
> + ? ? ? phy_reset = of_get_gpio(np, 0);
> + ? ? ? err = gpio_request_one(phy_reset, GPIOF_OUT_INIT_LOW, "phy-reset");
> + ? ? ? if (err) {
> + ? ? ? ? ? ? ? pr_warn("FEC: failed to get gpio phy-reset: %d\n", err);
> + ? ? ? ? ? ? ? return err;
> + ? ? ? }
> +
> + ? ? ? msleep(1);
> + ? ? ? gpio_set_value(phy_reset, 1);
> +
> + ? ? ? return 0;
> +}
> +#else /* CONFIG_OF */
> +static inline int fec_get_phy_mode_dt(struct platform_device *pdev)
> +{
> + ? ? ? return -ENODEV;
> +}
> +
> +static inline int fec_reset_phy(struct platform_device *pdev)
> +{
> + ? ? ? /*
> + ? ? ? ?* In case of platform probe, the reset has been done
> + ? ? ? ?* by machine code.
> + ? ? ? ?*/
> + ? ? ? return 0;
Perhaps platform code should be reworked to use GPIO also.
> +}
> +#endif /* CONFIG_OF */
> +
> ?static int __devinit
> ?fec_probe(struct platform_device *pdev)
> ?{
> @@ -1366,6 +1442,11 @@ fec_probe(struct platform_device *pdev)
> ? ? ? ?struct net_device *ndev;
> ? ? ? ?int i, irq, ret = 0;
> ? ? ? ?struct resource *r;
> + ? ? ? const struct of_device_id *of_id;
> +
> + ? ? ? of_id = of_match_device(fec_dt_ids, &pdev->dev);
> + ? ? ? if (of_id)
> + ? ? ? ? ? ? ? pdev->id_entry = of_id->data;
>
> ? ? ? ?r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> ? ? ? ?if (!r)
> @@ -1397,9 +1478,16 @@ fec_probe(struct platform_device *pdev)
>
> ? ? ? ?platform_set_drvdata(pdev, ndev);
>
> - ? ? ? pdata = pdev->dev.platform_data;
> - ? ? ? if (pdata)
> - ? ? ? ? ? ? ? fep->phy_interface = pdata->phy;
> + ? ? ? fep->phy_interface = fec_get_phy_mode_dt(pdev);
> + ? ? ? if (fep->phy_interface < 0) {
> + ? ? ? ? ? ? ? pdata = pdev->dev.platform_data;
> + ? ? ? ? ? ? ? if (pdata)
> + ? ? ? ? ? ? ? ? ? ? ? fep->phy_interface = pdata->phy;
> + ? ? ? ? ? ? ? else
> + ? ? ? ? ? ? ? ? ? ? ? fep->phy_interface = PHY_INTERFACE_MODE_MII;
> + ? ? ? }
> +
> + ? ? ? fec_reset_phy(pdev);
>
> ? ? ? ?/* This device has up to three irqs on some platforms */
> ? ? ? ?for (i = 0; i < 3; i++) {
> @@ -1534,6 +1622,7 @@ static struct platform_driver fec_driver = {
> ?#ifdef CONFIG_PM
> ? ? ? ? ? ? ? ?.pm ? ? = &fec_pm_ops,
> ?#endif
> + ? ? ? ? ? ? ? .of_match_table = fec_dt_ids,
> ? ? ? ?},
> ? ? ? ?.id_table = fec_devtype,
> ? ? ? ?.probe ?= fec_probe,
> --
> 1.7.4.1
>
>
>
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-05 15:13 [PATCH v2 0/3] Add device tree probe support for imx fec driver Shawn Guo
` (2 preceding siblings ...)
2011-07-05 15:13 ` [PATCH v2 3/3] net/fec: add device tree probe support Shawn Guo
@ 2011-07-06 2:48 ` David Miller
2011-07-06 5:30 ` David Miller
3 siblings, 1 reply; 16+ messages in thread
From: David Miller @ 2011-07-06 2:48 UTC (permalink / raw)
To: linux-arm-kernel
From: Shawn Guo <shawn.guo@linaro.org>
Date: Tue, 5 Jul 2011 23:13:56 +0800
> The first two patches are a little off topic. Patch #1 adds a helper
> function of_get_phy_mode into of_net, and #2 converts ibm_newemac net
> driver to use this helper function. Patch #3 is the actual one adding
> tree probe support for imx fec driver, with of_get_phy_mode being used.
>
> Changes since v1:
> * Address review comments given by Grant
> * Add patch #1 and #2
>
> Shawn Guo (3):
> dt/net: add helper function of_get_phy_mode
> net: ibm_newemac: convert it to use of_get_phy_mode
> net/fec: add device tree probe support
All applied to net-next-2.6, thanks.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-06 2:48 ` [PATCH v2 0/3] Add device tree probe support for imx fec driver David Miller
@ 2011-07-06 5:30 ` David Miller
2011-07-06 6:19 ` Grant Likely
0 siblings, 1 reply; 16+ messages in thread
From: David Miller @ 2011-07-06 5:30 UTC (permalink / raw)
To: linux-arm-kernel
From: David Miller <davem@davemloft.net>
Date: Tue, 05 Jul 2011 19:48:54 -0700 (PDT)
> All applied to net-next-2.6, thanks.
Come on guys:
drivers/of/of_net.c: In function 'of_get_phy_mode':
drivers/of/of_net.c:45: error: implicit declaration of function 'of_property_read_string'
This is completely rediculious.
Don't tell me that it's appropriate to merge something into
my net tree when it uses interfaces that don't even exist
in Linus's tree.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-06 5:30 ` David Miller
@ 2011-07-06 6:19 ` Grant Likely
2011-07-06 6:22 ` David Miller
0 siblings, 1 reply; 16+ messages in thread
From: Grant Likely @ 2011-07-06 6:19 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 05, 2011 at 10:30:45PM -0700, David Miller wrote:
> From: David Miller <davem@davemloft.net>
> Date: Tue, 05 Jul 2011 19:48:54 -0700 (PDT)
>
> > All applied to net-next-2.6, thanks.
>
> Come on guys:
>
> drivers/of/of_net.c: In function 'of_get_phy_mode':
> drivers/of/of_net.c:45: error: implicit declaration of function 'of_property_read_string'
>
> This is completely rediculious.
>
> Don't tell me that it's appropriate to merge something into
> my net tree when it uses interfaces that don't even exist
> in Linus's tree.
Sorry about that, I missed the reference to that function which is
currently in my devicetree/next branch. I can either take the series
via devicetree/next, or I can provide you with a topic branch
containing the needed commit that you can merge. Whichever you prefer.
g.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-06 6:19 ` Grant Likely
@ 2011-07-06 6:22 ` David Miller
2011-07-06 6:29 ` Grant Likely
2011-07-22 2:08 ` Shawn Guo
0 siblings, 2 replies; 16+ messages in thread
From: David Miller @ 2011-07-06 6:22 UTC (permalink / raw)
To: linux-arm-kernel
From: Grant Likely <grant.likely@secretlab.ca>
Date: Wed, 6 Jul 2011 00:19:01 -0600
> Sorry about that, I missed the reference to that function which is
> currently in my devicetree/next branch. I can either take the series
> via devicetree/next, or I can provide you with a topic branch
> containing the needed commit that you can merge. Whichever you prefer.
Please just take the series, thanks.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-06 6:22 ` David Miller
@ 2011-07-06 6:29 ` Grant Likely
2011-07-06 11:59 ` Shawn Guo
2011-07-22 2:08 ` Shawn Guo
1 sibling, 1 reply; 16+ messages in thread
From: Grant Likely @ 2011-07-06 6:29 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 05, 2011 at 11:22:52PM -0700, David Miller wrote:
> From: Grant Likely <grant.likely@secretlab.ca>
> Date: Wed, 6 Jul 2011 00:19:01 -0600
>
> > Sorry about that, I missed the reference to that function which is
> > currently in my devicetree/next branch. I can either take the series
> > via devicetree/next, or I can provide you with a topic branch
> > containing the needed commit that you can merge. Whichever you prefer.
>
> Please just take the series, thanks.
Will do.
g.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-06 6:29 ` Grant Likely
@ 2011-07-06 11:59 ` Shawn Guo
0 siblings, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2011-07-06 11:59 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Jul 06, 2011 at 12:29:01AM -0600, Grant Likely wrote:
> On Tue, Jul 05, 2011 at 11:22:52PM -0700, David Miller wrote:
> > From: Grant Likely <grant.likely@secretlab.ca>
> > Date: Wed, 6 Jul 2011 00:19:01 -0600
> >
> > > Sorry about that, I missed the reference to that function which is
> > > currently in my devicetree/next branch. I can either take the series
> > > via devicetree/next, or I can provide you with a topic branch
> > > containing the needed commit that you can merge. Whichever you prefer.
> >
> > Please just take the series, thanks.
>
> Will do.
>
Grant, please hold for a while. I will send an update to use
of_get_named_gpio for phy-reset-gpios.
--
Regards,
Shawn
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH RESEND v2 3/3] net/fec: add device tree probe support
2011-07-05 15:13 ` [PATCH v2 3/3] net/fec: add device tree probe support Shawn Guo
2011-07-05 17:42 ` Grant Likely
@ 2011-07-06 16:22 ` Shawn Guo
1 sibling, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2011-07-06 16:22 UTC (permalink / raw)
To: linux-arm-kernel
It adds device tree probe support for fec driver.
Signed-off-by: Jason Liu <jason.hui@linaro.org>
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
---
Resend with changes:
* use of_get_named_gpio for phy-reset-gpios
Documentation/devicetree/bindings/net/fsl-fec.txt | 24 +++++
drivers/net/fec.c | 98 +++++++++++++++++++-
2 files changed, 117 insertions(+), 5 deletions(-)
create mode 100644 Documentation/devicetree/bindings/net/fsl-fec.txt
diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt b/Documentation/devicetree/bindings/net/fsl-fec.txt
new file mode 100644
index 0000000..de43951
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
@@ -0,0 +1,24 @@
+* Freescale Fast Ethernet Controller (FEC)
+
+Required properties:
+- compatible : Should be "fsl,<soc>-fec"
+- reg : Address and length of the register set for the device
+- interrupts : Should contain fec interrupt
+- phy-mode : String, operation mode of the PHY interface.
+ Supported values are: "mii", "gmii", "sgmii", "tbi", "rmii",
+ "rgmii", "rgmii-id", "rgmii-rxid", "rgmii-txid", "rtbi", "smii".
+- phy-reset-gpios : Should specify the gpio for phy reset
+
+Optional properties:
+- local-mac-address : 6 bytes, mac address
+
+Example:
+
+fec at 83fec000 {
+ compatible = "fsl,imx51-fec", "fsl,imx27-fec";
+ reg = <0x83fec000 0x4000>;
+ interrupts = <87>;
+ phy-mode = "mii";
+ phy-reset-gpios = <&gpio1 14 0>; /* GPIO2_14 */
+ local-mac-address = [00 04 9F 01 1B B9];
+};
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 7ae3f28..720aa63 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -44,6 +44,10 @@
#include <linux/platform_device.h>
#include <linux/phy.h>
#include <linux/fec.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_net.h>
#include <asm/cacheflush.h>
@@ -78,6 +82,17 @@ static struct platform_device_id fec_devtype[] = {
{ }
};
+enum fec_type {
+ IMX27_FEC,
+ IMX28_FEC,
+};
+
+static const struct of_device_id fec_dt_ids[] = {
+ { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
+ { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
+ { /* sentinel */ }
+};
+
static unsigned char macaddr[ETH_ALEN];
module_param_array(macaddr, byte, NULL, 0);
MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
@@ -734,8 +749,22 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
*/
iap = macaddr;
+#ifdef CONFIG_OF
+ /*
+ * 2) from device tree data
+ */
+ if (!is_valid_ether_addr(iap)) {
+ struct device_node *np = fep->pdev->dev.of_node;
+ if (np) {
+ const char *mac = of_get_mac_address(np);
+ if (mac)
+ iap = (unsigned char *) mac;
+ }
+ }
+#endif
+
/*
- * 2) from flash or fuse (via platform data)
+ * 3) from flash or fuse (via platform data)
*/
if (!is_valid_ether_addr(iap)) {
#ifdef CONFIG_M5272
@@ -748,7 +777,7 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
}
/*
- * 3) FEC mac registers set by bootloader
+ * 4) FEC mac registers set by bootloader
*/
if (!is_valid_ether_addr(iap)) {
*((unsigned long *) &tmpaddr[0]) =
@@ -1358,6 +1387,52 @@ static int fec_enet_init(struct net_device *ndev)
return 0;
}
+#ifdef CONFIG_OF
+static int __devinit fec_get_phy_mode_dt(struct platform_device *pdev)
+{
+ struct device_node *np = pdev->dev.of_node;
+
+ if (np)
+ return of_get_phy_mode(np);
+
+ return -ENODEV;
+}
+
+static int __devinit fec_reset_phy(struct platform_device *pdev)
+{
+ int err, phy_reset;
+ struct device_node *np = pdev->dev.of_node;
+
+ if (!np)
+ return -ENODEV;
+
+ phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
+ err = gpio_request_one(phy_reset, GPIOF_OUT_INIT_LOW, "phy-reset");
+ if (err) {
+ pr_warn("FEC: failed to get gpio phy-reset: %d\n", err);
+ return err;
+ }
+
+ gpio_set_value(phy_reset, 1);
+
+ return 0;
+}
+#else /* CONFIG_OF */
+static inline int fec_get_phy_mode_dt(struct platform_device *pdev)
+{
+ return -ENODEV;
+}
+
+static inline int fec_reset_phy(struct platform_device *pdev)
+{
+ /*
+ * In case of platform probe, the reset has been done
+ * by machine code.
+ */
+ return 0;
+}
+#endif /* CONFIG_OF */
+
static int __devinit
fec_probe(struct platform_device *pdev)
{
@@ -1366,6 +1441,11 @@ fec_probe(struct platform_device *pdev)
struct net_device *ndev;
int i, irq, ret = 0;
struct resource *r;
+ const struct of_device_id *of_id;
+
+ of_id = of_match_device(fec_dt_ids, &pdev->dev);
+ if (of_id)
+ pdev->id_entry = of_id->data;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r)
@@ -1397,9 +1477,16 @@ fec_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ndev);
- pdata = pdev->dev.platform_data;
- if (pdata)
- fep->phy_interface = pdata->phy;
+ fep->phy_interface = fec_get_phy_mode_dt(pdev);
+ if (fep->phy_interface < 0) {
+ pdata = pdev->dev.platform_data;
+ if (pdata)
+ fep->phy_interface = pdata->phy;
+ else
+ fep->phy_interface = PHY_INTERFACE_MODE_MII;
+ }
+
+ fec_reset_phy(pdev);
/* This device has up to three irqs on some platforms */
for (i = 0; i < 3; i++) {
@@ -1534,6 +1621,7 @@ static struct platform_driver fec_driver = {
#ifdef CONFIG_PM
.pm = &fec_pm_ops,
#endif
+ .of_match_table = fec_dt_ids,
},
.id_table = fec_devtype,
.probe = fec_probe,
--
1.7.4.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-06 6:22 ` David Miller
2011-07-06 6:29 ` Grant Likely
@ 2011-07-22 2:08 ` Shawn Guo
2011-07-22 3:19 ` David Miller
1 sibling, 1 reply; 16+ messages in thread
From: Shawn Guo @ 2011-07-22 2:08 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 05, 2011 at 11:22:52PM -0700, David Miller wrote:
> From: Grant Likely <grant.likely@secretlab.ca>
> Date: Wed, 6 Jul 2011 00:19:01 -0600
>
> > Sorry about that, I missed the reference to that function which is
> > currently in my devicetree/next branch. I can either take the series
> > via devicetree/next, or I can provide you with a topic branch
> > containing the needed commit that you can merge. Whichever you prefer.
>
> Please just take the series, thanks.
>
I think the easier way is that I repost the series after
devicetree/next and i.mx tree get merged in the coming window, and
let them go through i.mx tree.
David, I assume I can add your acks to all 3 patches, otherwise
please let me know.
--
Regards,
Shawn
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/3] Add device tree probe support for imx fec driver
2011-07-22 2:08 ` Shawn Guo
@ 2011-07-22 3:19 ` David Miller
0 siblings, 0 replies; 16+ messages in thread
From: David Miller @ 2011-07-22 3:19 UTC (permalink / raw)
To: linux-arm-kernel
From: Shawn Guo <shawn.guo@freescale.com>
Date: Fri, 22 Jul 2011 10:08:19 +0800
> David, I assume I can add your acks to all 3 patches, otherwise
> please let me know.
Yes, you can.
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2011-07-22 3:19 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-05 15:13 [PATCH v2 0/3] Add device tree probe support for imx fec driver Shawn Guo
2011-07-05 15:13 ` [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode Shawn Guo
2011-07-05 17:35 ` Grant Likely
2011-07-05 15:13 ` [PATCH v2 2/3] net: ibm_newemac: convert it to use of_get_phy_mode Shawn Guo
2011-07-05 17:38 ` Grant Likely
2011-07-05 15:13 ` [PATCH v2 3/3] net/fec: add device tree probe support Shawn Guo
2011-07-05 17:42 ` Grant Likely
2011-07-06 16:22 ` [PATCH RESEND " Shawn Guo
2011-07-06 2:48 ` [PATCH v2 0/3] Add device tree probe support for imx fec driver David Miller
2011-07-06 5:30 ` David Miller
2011-07-06 6:19 ` Grant Likely
2011-07-06 6:22 ` David Miller
2011-07-06 6:29 ` Grant Likely
2011-07-06 11:59 ` Shawn Guo
2011-07-22 2:08 ` Shawn Guo
2011-07-22 3:19 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).