* Re: [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode
@ 2011-11-21 10:57 Nicolas Ferre
0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Ferre @ 2011-11-21 10:57 UTC (permalink / raw)
To: Shawn Guo, Grant Likely, devicetree-discuss
Cc: 'linux-arm-kernel@lists.infradead.org', netdev,
Rob Herring
Hi all,
> It adds the helper function of_get_phy_mode getting phy interface
> from device tree.
>
> Signed-off-by: Shawn Guo <shawn.guo <at> linaro.org>
> Cc: Grant Likely <grant.likely <at> secretlab.ca>
> ---
> drivers/of/of_net.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> include/linux/of_net.h | 1 +
[..]
> +const int of_get_phy_mode(struct device_node *np)
Nice helper function, indeed.
> +{
> + const char *pm;
> + int err, i;
> +
> + err = of_property_read_string(np, "phy-mode", &pm);
Just a quick question about the use of the "phy-mode" string:
- I know that it is widely used in drivers
- but, I discovered that in the ePAPR the string mentioned is "phy-connection-type" (6.5.2.2)
- and it is true also that in the very same document, we find the "phy-mode" in the Appendix B1 example...
Why this naming is not consistent (even in ePAPR)?
Best regards,
--
Nicolas Ferre
^ permalink raw reply [flat|nested] 3+ messages in thread* [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
0 siblings, 1 reply; 3+ messages in thread
From: Shawn Guo @ 2011-07-05 15:13 UTC (permalink / raw)
To: netdev; +Cc: linux-arm-kernel, devicetree-discuss, patches
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] 3+ 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
0 siblings, 1 reply; 3+ messages in thread
From: Shawn Guo @ 2011-07-05 15:13 UTC (permalink / raw)
To: netdev
Cc: linux-arm-kernel, devicetree-discuss, patches, Shawn Guo,
Grant Likely
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] 3+ messages in thread* Re: [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; 3+ messages in thread
From: Grant Likely @ 2011-07-05 17:35 UTC (permalink / raw)
To: Shawn Guo
Cc: netdev, linux-arm-kernel, devicetree-discuss, patches,
David Miller
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] 3+ messages in thread
end of thread, other threads:[~2011-11-21 10:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-21 10:57 [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode Nicolas Ferre
-- strict thread matches above, loose matches on Subject: below --
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
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).