From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Shawn Guo <shawn.guo@linaro.org>
Cc: Hui Wang <jason77.wang@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
linux-can@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 2/2] net: flexcan: add transceiver switch gpios support
Date: Thu, 28 Jun 2012 12:31:56 +0200 [thread overview]
Message-ID: <4FEC329C.7070004@pengutronix.de> (raw)
In-Reply-To: <1340853701-4488-3-git-send-email-shawn.guo@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 6162 bytes --]
On 06/28/2012 05:21 AM, Shawn Guo wrote:
> The flexcan driver has function pointer transceiver_switch defined in
> flexcan_platform_data for platform codes to hook up their transceiver
> switch implementation. However this does not cope with device tree
> probe.
>
> It's been observed that platforms mostly use gpios to control the
> switch of flexcan transceiver, like enable and standby. The patch
> adds transceiver switch gpios support into flexcan driver, so that
> platforms booting from device tree can just define properties
> phy-enable-gpios and phy-standby-gpios to have flexcan driver control
> the gpios.
Hmm I'm wondering if transceiver or phy is the correct name here. In
platform_data it's called transceiver_switch.
>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
> .../devicetree/bindings/net/can/fsl-flexcan.txt | 2 +
> drivers/net/can/flexcan.c | 62 ++++++++++++++++++++
> 2 files changed, 64 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> index 8ff324e..e0dbac7 100644
> --- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> +++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> @@ -15,6 +15,8 @@ Required properties:
> Optional properties:
>
> - clock-frequency : The oscillator frequency driving the flexcan device
> +- phy-enable-gpios : Specify the gpio used to enable phy
> +- phy-standby-gpios : Specify the gpio used to put phy into STANDBY mode
>
> Example:
>
> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> index 38c0690..1ce3f9e 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -26,6 +26,7 @@
> #include <linux/can/platform/flexcan.h>
> #include <linux/clk.h>
> #include <linux/delay.h>
> +#include <linux/gpio.h>
> #include <linux/if_arp.h>
> #include <linux/if_ether.h>
> #include <linux/interrupt.h>
> @@ -34,6 +35,7 @@
> #include <linux/list.h>
> #include <linux/module.h>
> #include <linux/of.h>
> +#include <linux/of_gpio.h>
> #include <linux/platform_device.h>
> #include <linux/pinctrl/consumer.h>
>
> @@ -180,6 +182,11 @@ struct flexcan_priv {
>
> struct clk *clk;
> struct flexcan_platform_data *pdata;
> +
> + int phy_en_gpio;
> + int phy_stby_gpio;
> + bool phy_en_high;
> + bool phy_stby_high;
> };
>
> static struct can_bittiming_const flexcan_bittiming_const = {
> @@ -224,6 +231,17 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
> */
> static void flexcan_transceiver_switch(const struct flexcan_priv *priv, int on)
> {
> + /*
> + * on == 1: enable phy and exit standby
> + * on == 0: disable phy and enter standby
> + */
> + if (gpio_is_valid(priv->phy_en_gpio))
> + gpio_set_value(priv->phy_en_gpio,
> + priv->phy_en_high ? on : !on);
> + if (gpio_is_valid(priv->phy_stby_gpio))
> + gpio_set_value(priv->phy_stby_gpio,
> + priv->phy_stby_high ? !on : on);
> +
> if (priv->pdata && priv->pdata->transceiver_switch)
> priv->pdata->transceiver_switch(on);
> }
> @@ -933,6 +951,10 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> resource_size_t mem_size;
> int err, irq;
> u32 clock_freq = 0;
> + int phy_en_gpio = -EINVAL;
> + int phy_stby_gpio = -EINVAL;
> + bool phy_en_high = true;
> + bool phy_stby_high = true;
>
> pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
> if (IS_ERR(pinctrl))
> @@ -940,11 +962,46 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
>
> if (pdev->dev.of_node) {
> const u32 *clock_freq_p;
> + enum of_gpio_flags flags;
>
> clock_freq_p = of_get_property(pdev->dev.of_node,
> "clock-frequency", NULL);
> if (clock_freq_p)
> clock_freq = *clock_freq_p;
> +
> + phy_en_gpio = of_get_named_gpio_flags(pdev->dev.of_node,
> + "phy-enable-gpios",
> + 0, &flags);
> + if (gpio_is_valid(phy_en_gpio)) {
> + if (flags == OF_GPIO_ACTIVE_LOW)
> + phy_en_high = false;
I really like the "flags" solution, much better than a DT property. What
about keeping the term active_low instead of en_high? From my limited
knowledge about electronic I say, that active low is a standard term.
> + err = devm_gpio_request_one(&pdev->dev, phy_en_gpio,
> + GPIOF_DIR_OUT,
> + "phy-enable");
> + if (err) {
> + dev_err(&pdev->dev,
> + "failed to request gpio %d: %d\n",
> + phy_en_gpio, err);
> + goto failed_gpio;
> + }
> + }
> +
> + phy_stby_gpio = of_get_named_gpio_flags(pdev->dev.of_node,
> + "phy-standby-gpios",
> + 0, &flags);
> + if (gpio_is_valid(phy_stby_gpio)) {
> + if (flags == OF_GPIO_ACTIVE_LOW)
> + phy_stby_high = false;
> + err = devm_gpio_request_one(&pdev->dev, phy_stby_gpio,
> + GPIOF_DIR_OUT,
> + "phy-standby");
> + if (err) {
> + dev_err(&pdev->dev,
> + "failed to request gpio %d: %d\n",
> + phy_stby_gpio, err);
> + goto failed_gpio;
> + }
> + }
> }
>
> if (!clock_freq) {
> @@ -997,6 +1054,10 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> priv->base = base;
> priv->dev = dev;
> priv->clk = clk;
> + priv->phy_en_gpio = phy_en_gpio;
> + priv->phy_en_high = phy_en_high;
> + priv->phy_stby_gpio = phy_stby_gpio;
> + priv->phy_stby_high = phy_stby_high;
> priv->pdata = pdev->dev.platform_data;
>
> netif_napi_add(dev, &priv->napi, flexcan_poll, FLEXCAN_NAPI_WEIGHT);
> @@ -1025,6 +1086,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> if (clk)
> clk_put(clk);
> failed_clock:
> + failed_gpio:
> return err;
> }
>
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: mkl@pengutronix.de (Marc Kleine-Budde)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 2/2] net: flexcan: add transceiver switch gpios support
Date: Thu, 28 Jun 2012 12:31:56 +0200 [thread overview]
Message-ID: <4FEC329C.7070004@pengutronix.de> (raw)
In-Reply-To: <1340853701-4488-3-git-send-email-shawn.guo@linaro.org>
On 06/28/2012 05:21 AM, Shawn Guo wrote:
> The flexcan driver has function pointer transceiver_switch defined in
> flexcan_platform_data for platform codes to hook up their transceiver
> switch implementation. However this does not cope with device tree
> probe.
>
> It's been observed that platforms mostly use gpios to control the
> switch of flexcan transceiver, like enable and standby. The patch
> adds transceiver switch gpios support into flexcan driver, so that
> platforms booting from device tree can just define properties
> phy-enable-gpios and phy-standby-gpios to have flexcan driver control
> the gpios.
Hmm I'm wondering if transceiver or phy is the correct name here. In
platform_data it's called transceiver_switch.
>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
> .../devicetree/bindings/net/can/fsl-flexcan.txt | 2 +
> drivers/net/can/flexcan.c | 62 ++++++++++++++++++++
> 2 files changed, 64 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> index 8ff324e..e0dbac7 100644
> --- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> +++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> @@ -15,6 +15,8 @@ Required properties:
> Optional properties:
>
> - clock-frequency : The oscillator frequency driving the flexcan device
> +- phy-enable-gpios : Specify the gpio used to enable phy
> +- phy-standby-gpios : Specify the gpio used to put phy into STANDBY mode
>
> Example:
>
> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> index 38c0690..1ce3f9e 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -26,6 +26,7 @@
> #include <linux/can/platform/flexcan.h>
> #include <linux/clk.h>
> #include <linux/delay.h>
> +#include <linux/gpio.h>
> #include <linux/if_arp.h>
> #include <linux/if_ether.h>
> #include <linux/interrupt.h>
> @@ -34,6 +35,7 @@
> #include <linux/list.h>
> #include <linux/module.h>
> #include <linux/of.h>
> +#include <linux/of_gpio.h>
> #include <linux/platform_device.h>
> #include <linux/pinctrl/consumer.h>
>
> @@ -180,6 +182,11 @@ struct flexcan_priv {
>
> struct clk *clk;
> struct flexcan_platform_data *pdata;
> +
> + int phy_en_gpio;
> + int phy_stby_gpio;
> + bool phy_en_high;
> + bool phy_stby_high;
> };
>
> static struct can_bittiming_const flexcan_bittiming_const = {
> @@ -224,6 +231,17 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
> */
> static void flexcan_transceiver_switch(const struct flexcan_priv *priv, int on)
> {
> + /*
> + * on == 1: enable phy and exit standby
> + * on == 0: disable phy and enter standby
> + */
> + if (gpio_is_valid(priv->phy_en_gpio))
> + gpio_set_value(priv->phy_en_gpio,
> + priv->phy_en_high ? on : !on);
> + if (gpio_is_valid(priv->phy_stby_gpio))
> + gpio_set_value(priv->phy_stby_gpio,
> + priv->phy_stby_high ? !on : on);
> +
> if (priv->pdata && priv->pdata->transceiver_switch)
> priv->pdata->transceiver_switch(on);
> }
> @@ -933,6 +951,10 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> resource_size_t mem_size;
> int err, irq;
> u32 clock_freq = 0;
> + int phy_en_gpio = -EINVAL;
> + int phy_stby_gpio = -EINVAL;
> + bool phy_en_high = true;
> + bool phy_stby_high = true;
>
> pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
> if (IS_ERR(pinctrl))
> @@ -940,11 +962,46 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
>
> if (pdev->dev.of_node) {
> const u32 *clock_freq_p;
> + enum of_gpio_flags flags;
>
> clock_freq_p = of_get_property(pdev->dev.of_node,
> "clock-frequency", NULL);
> if (clock_freq_p)
> clock_freq = *clock_freq_p;
> +
> + phy_en_gpio = of_get_named_gpio_flags(pdev->dev.of_node,
> + "phy-enable-gpios",
> + 0, &flags);
> + if (gpio_is_valid(phy_en_gpio)) {
> + if (flags == OF_GPIO_ACTIVE_LOW)
> + phy_en_high = false;
I really like the "flags" solution, much better than a DT property. What
about keeping the term active_low instead of en_high? From my limited
knowledge about electronic I say, that active low is a standard term.
> + err = devm_gpio_request_one(&pdev->dev, phy_en_gpio,
> + GPIOF_DIR_OUT,
> + "phy-enable");
> + if (err) {
> + dev_err(&pdev->dev,
> + "failed to request gpio %d: %d\n",
> + phy_en_gpio, err);
> + goto failed_gpio;
> + }
> + }
> +
> + phy_stby_gpio = of_get_named_gpio_flags(pdev->dev.of_node,
> + "phy-standby-gpios",
> + 0, &flags);
> + if (gpio_is_valid(phy_stby_gpio)) {
> + if (flags == OF_GPIO_ACTIVE_LOW)
> + phy_stby_high = false;
> + err = devm_gpio_request_one(&pdev->dev, phy_stby_gpio,
> + GPIOF_DIR_OUT,
> + "phy-standby");
> + if (err) {
> + dev_err(&pdev->dev,
> + "failed to request gpio %d: %d\n",
> + phy_stby_gpio, err);
> + goto failed_gpio;
> + }
> + }
> }
>
> if (!clock_freq) {
> @@ -997,6 +1054,10 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> priv->base = base;
> priv->dev = dev;
> priv->clk = clk;
> + priv->phy_en_gpio = phy_en_gpio;
> + priv->phy_en_high = phy_en_high;
> + priv->phy_stby_gpio = phy_stby_gpio;
> + priv->phy_stby_high = phy_stby_high;
> priv->pdata = pdev->dev.platform_data;
>
> netif_napi_add(dev, &priv->napi, flexcan_poll, FLEXCAN_NAPI_WEIGHT);
> @@ -1025,6 +1086,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> if (clk)
> clk_put(clk);
> failed_clock:
> + failed_gpio:
> return err;
> }
>
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120628/9b38782a/attachment.sig>
next prev parent reply other threads:[~2012-06-28 10:32 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-28 3:21 [PATCH v2 0/2] flexcan driver updates Shawn Guo
2012-06-28 3:21 ` Shawn Guo
2012-06-28 3:21 ` [PATCH v2 1/2] net: flexcan: clock-frequency is optional for device tree probe Shawn Guo
2012-06-28 3:21 ` Shawn Guo
2012-06-28 11:23 ` Dong Aisheng
2012-06-28 11:23 ` Dong Aisheng
2012-06-28 3:21 ` [PATCH v2 2/2] net: flexcan: add transceiver switch gpios support Shawn Guo
2012-06-28 3:21 ` Shawn Guo
2012-06-28 5:22 ` Lothar Waßmann
2012-06-28 5:22 ` Lothar Waßmann
2012-06-28 5:30 ` Shawn Guo
2012-06-28 5:30 ` Shawn Guo
2012-06-28 6:14 ` Hui Wang
2012-06-28 6:14 ` Hui Wang
2012-06-28 6:34 ` Shawn Guo
2012-06-28 6:34 ` Shawn Guo
2012-06-28 7:01 ` Hui Wang
2012-06-28 7:01 ` Hui Wang
2012-06-28 10:32 ` Marc Kleine-Budde
2012-06-28 10:32 ` Marc Kleine-Budde
2012-06-28 10:31 ` Marc Kleine-Budde [this message]
2012-06-28 10:31 ` Marc Kleine-Budde
2012-06-28 11:21 ` Shawn Guo
2012-06-28 11:21 ` Shawn Guo
2012-06-28 11:29 ` Marc Kleine-Budde
2012-06-28 11:29 ` Marc Kleine-Budde
2012-06-28 11:41 ` Shawn Guo
2012-06-28 11:41 ` Shawn Guo
2012-06-28 11:52 ` Shawn Guo
2012-06-28 11:52 ` Shawn Guo
2012-06-28 12:05 ` Shawn Guo
2012-06-28 12:05 ` Shawn Guo
2012-06-28 12:11 ` Dong Aisheng
2012-06-28 12:11 ` Dong Aisheng
2012-06-28 12:19 ` Lothar Waßmann
2012-06-28 12:19 ` Lothar Waßmann
2012-06-28 12:07 ` Lothar Waßmann
2012-06-28 12:07 ` Lothar Waßmann
2012-06-28 12:13 ` Shawn Guo
2012-06-28 12:13 ` Shawn Guo
2012-06-28 12:24 ` Lothar Waßmann
2012-06-28 12:24 ` Lothar Waßmann
2012-07-02 2:55 ` Hui Wang
2012-07-02 2:55 ` Hui Wang
2012-06-28 12:08 ` Kurt Van Dijck
2012-06-28 12:08 ` Kurt Van Dijck
2012-06-28 12:10 ` Marc Kleine-Budde
2012-06-28 12:10 ` Marc Kleine-Budde
2012-06-28 12:16 ` Shawn Guo
2012-06-28 12:16 ` Shawn Guo
2012-06-28 11:39 ` Dong Aisheng
2012-06-28 11:39 ` Dong Aisheng
2012-06-28 11:33 ` Dong Aisheng
2012-06-28 11:33 ` Dong Aisheng
2012-06-28 11:46 ` Shawn Guo
2012-06-28 11:46 ` Shawn Guo
2012-06-28 11:48 ` Dong Aisheng
2012-06-28 11:48 ` Dong Aisheng
2012-06-28 12:00 ` Shawn Guo
2012-06-28 12:00 ` Shawn Guo
2012-06-28 12:02 ` Dong Aisheng
2012-06-28 12:02 ` Dong Aisheng
2012-06-28 12:19 ` Shawn Guo
2012-06-28 12:19 ` Shawn Guo
2012-06-28 12:05 ` Marc Kleine-Budde
2012-06-28 12:05 ` Marc Kleine-Budde
2012-06-28 12:18 ` Dong Aisheng
2012-06-28 12:18 ` Dong Aisheng
2012-06-28 12:32 ` Lothar Waßmann
2012-06-28 12:32 ` Lothar Waßmann
2012-06-28 12:40 ` Shawn Guo
2012-06-28 12:40 ` Shawn Guo
2012-06-28 12:47 ` Dong Aisheng
2012-06-28 12:47 ` Dong Aisheng
2012-06-28 12:39 ` Shawn Guo
2012-06-28 12:39 ` Shawn Guo
2012-06-29 9:27 ` Marc Kleine-Budde
2012-06-29 9:27 ` Marc Kleine-Budde
[not found] ` <502226AB.4050205@gmail.com>
2012-08-08 9:55 ` Marc Kleine-Budde
2012-08-09 2:39 ` Hui Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FEC329C.7070004@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=davem@davemloft.net \
--cc=jason77.wang@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-can@vger.kernel.org \
--cc=shawn.guo@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.