All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
@ 2013-06-05 19:27 Fabio Estevam
  2013-06-05 19:27 ` [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove Fabio Estevam
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Fabio Estevam @ 2013-06-05 19:27 UTC (permalink / raw)
  To: mkl; +Cc: shawn.guo, linux-can, Fabio Estevam

From: Fabio Estevam <fabio.estevam@freescale.com>

Instead of using a GPIO to turn on/off the CAN transceiver, it is better to
use a regulator as some systems may use a PMIC to power the CAN transceiver.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 .../devicetree/bindings/net/can/fsl-flexcan.txt    |  2 +
 arch/arm/boot/dts/imx28-evk.dts                    | 11 +++++
 arch/arm/mach-mxs/mach-mxs.c                       | 54 ++--------------------
 drivers/net/can/flexcan.c                          | 24 +++++-----
 4 files changed, 29 insertions(+), 62 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
index 8ff324e..56d6cc3 100644
--- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
+++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
@@ -16,6 +16,8 @@ Optional properties:
 
 - clock-frequency : The oscillator frequency driving the flexcan device
 
+- xceiver-supply: Regulator that powers the CAN transceiver
+
 Example:
 
 	can@1c000 {
diff --git a/arch/arm/boot/dts/imx28-evk.dts b/arch/arm/boot/dts/imx28-evk.dts
index 3637bf3..dff42b3 100644
--- a/arch/arm/boot/dts/imx28-evk.dts
+++ b/arch/arm/boot/dts/imx28-evk.dts
@@ -155,6 +155,7 @@
 			can0: can@80032000 {
 				pinctrl-names = "default";
 				pinctrl-0 = <&can0_pins_a>;
+				xceiver-supply = <&reg_can_3v3>;
 				status = "okay";
 			};
 
@@ -319,6 +320,16 @@
 			gpio = <&gpio3 30 0>;
 			enable-active-high;
 		};
+
+		reg_can_3v3: can-3v3 {
+			compatible = "regulator-fixed";
+			regulator-name = "can-3v3";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+			gpio = <&gpio2 13 0>;
+			enable-active-high;
+		};
+
 	};
 
 	sound {
diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index bd225e9..22735c1 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -14,7 +14,6 @@
 #include <linux/clk/mxs.h>
 #include <linux/clkdev.h>
 #include <linux/clocksource.h>
-#include <linux/can/platform/flexcan.h>
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
@@ -59,41 +58,6 @@ static inline void __mxs_togl(u32 mask, void __iomem *reg)
 	__raw_writel(mask, reg + MXS_TOG_ADDR);
 }
 
-/*
- * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers
- */
-#define MX28EVK_FLEXCAN_SWITCH	MXS_GPIO_NR(2, 13)
-
-static int flexcan0_en, flexcan1_en;
-
-static void mx28evk_flexcan_switch(void)
-{
-	if (flexcan0_en || flexcan1_en)
-		gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1);
-	else
-		gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0);
-}
-
-static void mx28evk_flexcan0_switch(int enable)
-{
-	flexcan0_en = enable;
-	mx28evk_flexcan_switch();
-}
-
-static void mx28evk_flexcan1_switch(int enable)
-{
-	flexcan1_en = enable;
-	mx28evk_flexcan_switch();
-}
-
-static struct flexcan_platform_data flexcan_pdata[2];
-
-static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = {
-	OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80032000, NULL, &flexcan_pdata[0]),
-	OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80034000, NULL, &flexcan_pdata[1]),
-	{ /* sentinel */ }
-};
-
 #define OCOTP_WORD_OFFSET		0x20
 #define OCOTP_WORD_COUNT		0x20
 
@@ -253,15 +217,6 @@ static void __init imx28_evk_init(void)
 	mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0);
 }
 
-static void __init imx28_evk_post_init(void)
-{
-	if (!gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT,
-			      "flexcan-switch")) {
-		flexcan_pdata[0].transceiver_switch = mx28evk_flexcan0_switch;
-		flexcan_pdata[1].transceiver_switch = mx28evk_flexcan1_switch;
-	}
-}
-
 static int apx4devkit_phy_fixup(struct phy_device *phy)
 {
 	phy->dev_flags |= MICREL_PHY_50MHZ_CLK;
@@ -371,15 +326,12 @@ static void __init mxs_machine_init(void)
 		cfa10037_init();
 	else if (of_machine_is_compatible("crystalfontz,cfa10049"))
 		cfa10049_init();
-
-	of_platform_populate(NULL, of_default_bus_match_table,
-			     mxs_auxdata_lookup, NULL);
+
+	of_platform_populate(NULL, of_default_bus_match_table,
+			     NULL, NULL);
 
 	if (of_machine_is_compatible("karo,tx28"))
 		tx28_post_init();
-
-	if (of_machine_is_compatible("fsl,imx28-evk"))
-		imx28_evk_post_init();
 }
 
 #define MX23_CLKCTRL_RESET_OFFSET	0x120
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index f873b9f..3de02b1 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -37,6 +37,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 
 #define DRV_NAME			"flexcan"
 
@@ -211,6 +212,7 @@ struct flexcan_priv {
 	struct clk *clk_per;
 	struct flexcan_platform_data *pdata;
 	const struct flexcan_devtype_data *devtype_data;
+	struct regulator *reg_xceiver;
 };
 
 static struct flexcan_devtype_data fsl_p1010_devtype_data = {
@@ -258,15 +260,6 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
 }
 #endif
 
-/*
- * Swtich transceiver on or off
- */
-static void flexcan_transceiver_switch(const struct flexcan_priv *priv, int on)
-{
-	if (priv->pdata && priv->pdata->transceiver_switch)
-		priv->pdata->transceiver_switch(on);
-}
-
 static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
 					      u32 reg_esr)
 {
@@ -799,7 +792,11 @@ static int flexcan_chip_start(struct net_device *dev)
 	if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES)
 		flexcan_write(0x0, &regs->rxfgmask);
 
-	flexcan_transceiver_switch(priv, 1);
+	if (priv->reg_xceiver)	{
+		err = regulator_enable(priv->reg_xceiver);
+		if (err)
+			goto out;
+	}
 
 	/* synchronize with the can bus */
 	reg_mcr = flexcan_read(&regs->mcr);
@@ -842,7 +839,8 @@ static void flexcan_chip_stop(struct net_device *dev)
 	reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
 	flexcan_write(reg, &regs->mcr);
 
-	flexcan_transceiver_switch(priv, 0);
+	if (priv->reg_xceiver)
+		regulator_disable(priv->reg_xceiver);
 	priv->can.state = CAN_STATE_STOPPED;
 
 	return;
@@ -1084,6 +1082,10 @@ static int flexcan_probe(struct platform_device *pdev)
 	priv->pdata = pdev->dev.platform_data;
 	priv->devtype_data = devtype_data;
 
+	priv->reg_xceiver = devm_regulator_get(&pdev->dev, "xceiver");
+	if (IS_ERR(priv->reg_xceiver))
+		priv->reg_xceiver = NULL;
+
 	netif_napi_add(dev, &priv->napi, flexcan_poll, FLEXCAN_NAPI_WEIGHT);
 
 	dev_set_drvdata(&pdev->dev, dev);
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove
  2013-06-05 19:27 [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Fabio Estevam
@ 2013-06-05 19:27 ` Fabio Estevam
  2013-06-10 17:02   ` Marc Kleine-Budde
  2013-06-06  5:21 ` [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Marc Kleine-Budde
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 14+ messages in thread
From: Fabio Estevam @ 2013-06-05 19:27 UTC (permalink / raw)
  To: mkl; +Cc: shawn.guo, linux-can, Fabio Estevam

From: Fabio Estevam <fabio.estevam@freescale.com>

mx28evk has two CAN ports and they are controlled by the same GPIO.

If can0 runs flexcan_chip_stop(), then the regulator will be disabled, which
means that can1 cannot run anymore.

To overcome such scenario, let's enable the CAN regulator in flexcan_probe()
and disabled it in flexcan_remove().

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 drivers/net/can/flexcan.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 3de02b1..456a549 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -792,12 +792,6 @@ static int flexcan_chip_start(struct net_device *dev)
 	if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES)
 		flexcan_write(0x0, &regs->rxfgmask);
 
-	if (priv->reg_xceiver)	{
-		err = regulator_enable(priv->reg_xceiver);
-		if (err)
-			goto out;
-	}
-
 	/* synchronize with the can bus */
 	reg_mcr = flexcan_read(&regs->mcr);
 	reg_mcr &= ~FLEXCAN_MCR_HALT;
@@ -839,8 +833,6 @@ static void flexcan_chip_stop(struct net_device *dev)
 	reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
 	flexcan_write(reg, &regs->mcr);
 
-	if (priv->reg_xceiver)
-		regulator_disable(priv->reg_xceiver);
 	priv->can.state = CAN_STATE_STOPPED;
 
 	return;
@@ -1099,6 +1091,12 @@ static int flexcan_probe(struct platform_device *pdev)
 
 	devm_can_led_init(dev);
 
+	if (priv->reg_xceiver) {
+		err = regulator_enable(priv->reg_xceiver);
+		if (err)
+			goto failed_register;
+	}
+
 	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
 		 priv->base, dev->irq);
 
@@ -1122,6 +1120,9 @@ static int flexcan_remove(struct platform_device *pdev)
 	struct flexcan_priv *priv = netdev_priv(dev);
 	struct resource *mem;
 
+	if (priv->reg_xceiver)
+		regulator_disable(priv->reg_xceiver);
+
 	unregister_flexcandev(dev);
 	iounmap(priv->base);
 
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
  2013-06-05 19:27 [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Fabio Estevam
  2013-06-05 19:27 ` [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove Fabio Estevam
@ 2013-06-06  5:21 ` Marc Kleine-Budde
  2013-06-10 16:59 ` Marc Kleine-Budde
  2013-06-12 11:42 ` Shawn Guo
  3 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2013-06-06  5:21 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: shawn.guo, linux-can, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 745 bytes --]

On 06/05/2013 09:27 PM, Fabio Estevam wrote:
> Instead of using a GPIO to turn on/off the CAN transceiver, it is better to
> use a regulator as some systems may use a PMIC to power the CAN transceiver.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

Just a short note, as I'm not in the office today.

I like the idea of using an established subsystem for the
transceiver/phy. But I don't like the solution you suggested in patch 2.

Marc

-- 
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: 263 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
  2013-06-05 19:27 [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Fabio Estevam
  2013-06-05 19:27 ` [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove Fabio Estevam
  2013-06-06  5:21 ` [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Marc Kleine-Budde
@ 2013-06-10 16:59 ` Marc Kleine-Budde
  2013-06-10 17:03   ` Fabio Estevam
  2013-06-11  2:38   ` Fabio Estevam
  2013-06-12 11:42 ` Shawn Guo
  3 siblings, 2 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2013-06-10 16:59 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: shawn.guo, linux-can, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 2511 bytes --]

On 06/05/2013 09:27 PM, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
> Instead of using a GPIO to turn on/off the CAN transceiver, it is better to
> use a regulator as some systems may use a PMIC to power the CAN transceiver.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

I'm preparing a patch to remove the usage of flexcan_platform_data from
the imx tree. Can you add that patch to your series and remove
"linux/can/platform/flexcan.h" from the source tree in this patch?

> ---
>  .../devicetree/bindings/net/can/fsl-flexcan.txt    |  2 +
>  arch/arm/boot/dts/imx28-evk.dts                    | 11 +++++
>  arch/arm/mach-mxs/mach-mxs.c                       | 54 ++--------------------
>  drivers/net/can/flexcan.c                          | 24 +++++-----
>  4 files changed, 29 insertions(+), 62 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> index 8ff324e..56d6cc3 100644
> --- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> +++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> @@ -16,6 +16,8 @@ Optional properties:
>  
>  - clock-frequency : The oscillator frequency driving the flexcan device
>  
> +- xceiver-supply: Regulator that powers the CAN transceiver
> +
>  Example:
>  
>  	can@1c000 {
> diff --git a/arch/arm/boot/dts/imx28-evk.dts b/arch/arm/boot/dts/imx28-evk.dts
> index 3637bf3..dff42b3 100644
> --- a/arch/arm/boot/dts/imx28-evk.dts
> +++ b/arch/arm/boot/dts/imx28-evk.dts
> @@ -155,6 +155,7 @@
>  			can0: can@80032000 {
>  				pinctrl-names = "default";
>  				pinctrl-0 = <&can0_pins_a>;
> +				xceiver-supply = <&reg_can_3v3>;
>  				status = "okay";
>  			};
>  
> @@ -319,6 +320,16 @@
>  			gpio = <&gpio3 30 0>;
>  			enable-active-high;
>  		};
> +
> +		reg_can_3v3: can-3v3 {
> +			compatible = "regulator-fixed";
> +			regulator-name = "can-3v3";
> +			regulator-min-microvolt = <3300000>;
> +			regulator-max-microvolt = <3300000>;
> +			gpio = <&gpio2 13 0>;

Can you convert GPIO2_13 from a hog gpio to a normal pinctl gpio?

Looks good otherwise.

Marc

-- 
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: 263 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove
  2013-06-05 19:27 ` [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove Fabio Estevam
@ 2013-06-10 17:02   ` Marc Kleine-Budde
  2013-06-10 19:05     ` Fabio Estevam
  0 siblings, 1 reply; 14+ messages in thread
From: Marc Kleine-Budde @ 2013-06-10 17:02 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: shawn.guo, linux-can, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

On 06/05/2013 09:27 PM, Fabio Estevam wrote:
> mx28evk has two CAN ports and they are controlled by the same GPIO.
> 
> If can0 runs flexcan_chip_stop(), then the regulator will be disabled, which
> means that can1 cannot run anymore.

Are you sure? I think the regulator framework has a proper refcount.

> To overcome such scenario, let's enable the CAN regulator in flexcan_probe()
> and disabled it in flexcan_remove().

Marc

-- 
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: 263 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
  2013-06-10 16:59 ` Marc Kleine-Budde
@ 2013-06-10 17:03   ` Fabio Estevam
  2013-06-11  2:38   ` Fabio Estevam
  1 sibling, 0 replies; 14+ messages in thread
From: Fabio Estevam @ 2013-06-10 17:03 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: shawn.guo, linux-can, Fabio Estevam

On Mon, Jun 10, 2013 at 1:59 PM, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
> On 06/05/2013 09:27 PM, Fabio Estevam wrote:
>> From: Fabio Estevam <fabio.estevam@freescale.com>
>>
>> Instead of using a GPIO to turn on/off the CAN transceiver, it is better to
>> use a regulator as some systems may use a PMIC to power the CAN transceiver.
>>
>> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
>
> I'm preparing a patch to remove the usage of flexcan_platform_data from
> the imx tree. Can you add that patch to your series and remove
> "linux/can/platform/flexcan.h" from the source tree in this patch?

Sure, no problem. I can send your patch as part of my series and work
through your other comments.

Regards,

Fabio Estevam

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove
  2013-06-10 17:02   ` Marc Kleine-Budde
@ 2013-06-10 19:05     ` Fabio Estevam
  2013-06-10 20:39       ` Marc Kleine-Budde
  0 siblings, 1 reply; 14+ messages in thread
From: Fabio Estevam @ 2013-06-10 19:05 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: shawn.guo, linux-can, Fabio Estevam

Hi Marc,

On Mon, Jun 10, 2013 at 2:02 PM, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
> On 06/05/2013 09:27 PM, Fabio Estevam wrote:
>> mx28evk has two CAN ports and they are controlled by the same GPIO.
>>
>> If can0 runs flexcan_chip_stop(), then the regulator will be disabled, which
>> means that can1 cannot run anymore.
>
> Are you sure? I think the regulator framework has a proper refcount.

Yes, the refcount is OK. The problem is that on mx28evk we have two
CAN ports controlled by the same regulator.

Let's say that can0 executes flexcan_chip_stop:

static void flexcan_chip_stop(struct net_device *dev)
{
	struct flexcan_priv *priv = netdev_priv(dev);
	struct flexcan_regs __iomem *regs = priv->base;
	u32 reg;

	/* Disable all interrupts */
	flexcan_write(0, &regs->imask1);

	/* Disable + halt module */
	reg = flexcan_read(&regs->mcr);
	reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
	flexcan_write(reg, &regs->mcr);

        if (priv->reg_xceiver)
	        regulator_disabled(priv->reg_xceiver);
...

It will turn off the transceiver here, which means that can1 will not
be able to operate.

Currently this situation is properly handled inside mach-mxs by only
disabling the CAN transceiver when both CAN ports are not used.

With the conversion to regulator I thought on enabling the regulator
at the probe function and disabling it at remove.

I understand that the power consumption will be higher in this case,
but I could not find a better alternative so far.

Regards,

Fabio Estevam

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove
  2013-06-10 19:05     ` Fabio Estevam
@ 2013-06-10 20:39       ` Marc Kleine-Budde
  2013-06-10 20:49         ` Fabio Estevam
  0 siblings, 1 reply; 14+ messages in thread
From: Marc Kleine-Budde @ 2013-06-10 20:39 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: shawn.guo, linux-can, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 1735 bytes --]

On 06/10/2013 09:05 PM, Fabio Estevam wrote:
> Hi Marc,
> 
> On Mon, Jun 10, 2013 at 2:02 PM, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
>> On 06/05/2013 09:27 PM, Fabio Estevam wrote:
>>> mx28evk has two CAN ports and they are controlled by the same GPIO.
>>>
>>> If can0 runs flexcan_chip_stop(), then the regulator will be disabled, which
>>> means that can1 cannot run anymore.
>>
>> Are you sure? I think the regulator framework has a proper refcount.
> 
> Yes, the refcount is OK. The problem is that on mx28evk we have two
> CAN ports controlled by the same regulator.
> 
> Let's say that can0 executes flexcan_chip_stop:
> 
> static void flexcan_chip_stop(struct net_device *dev)
> {
> 	struct flexcan_priv *priv = netdev_priv(dev);
> 	struct flexcan_regs __iomem *regs = priv->base;
> 	u32 reg;
> 
> 	/* Disable all interrupts */
> 	flexcan_write(0, &regs->imask1);
> 
> 	/* Disable + halt module */
> 	reg = flexcan_read(&regs->mcr);
> 	reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
> 	flexcan_write(reg, &regs->mcr);
> 
>         if (priv->reg_xceiver)
> 	        regulator_disabled(priv->reg_xceiver);
> ...
> 
> It will turn off the transceiver here, which means that can1 will not
> be able to operate.
> 
> Currently this situation is properly handled inside mach-mxs by only
> disabling the CAN transceiver when both CAN ports are not used.

Why don't you enable the regulator in can1, too?

Marc

-- 
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: 263 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove
  2013-06-10 20:39       ` Marc Kleine-Budde
@ 2013-06-10 20:49         ` Fabio Estevam
  2013-06-10 23:35           ` Marc Kleine-Budde
  0 siblings, 1 reply; 14+ messages in thread
From: Fabio Estevam @ 2013-06-10 20:49 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: shawn.guo, linux-can, Fabio Estevam

On Mon, Jun 10, 2013 at 5:39 PM, Marc Kleine-Budde <mkl@pengutronix.de> wrote:

>> It will turn off the transceiver here, which means that can1 will not
>> be able to operate.
>>
>> Currently this situation is properly handled inside mach-mxs by only
>> disabling the CAN transceiver when both CAN ports are not used.
>
> Why don't you enable the regulator in can1, too?

Since they use the same regulator (the same GPIO pin control both CAN
ports on mx28evk), I can not have regulator disabled for can0 and
regulator enabled for can1.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove
  2013-06-10 20:49         ` Fabio Estevam
@ 2013-06-10 23:35           ` Marc Kleine-Budde
  0 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2013-06-10 23:35 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: shawn.guo, linux-can, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 1031 bytes --]

On 06/10/2013 10:49 PM, Fabio Estevam wrote:
> On Mon, Jun 10, 2013 at 5:39 PM, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
> 
>>> It will turn off the transceiver here, which means that can1 will not
>>> be able to operate.
>>>
>>> Currently this situation is properly handled inside mach-mxs by only
>>> disabling the CAN transceiver when both CAN ports are not used.
>>
>> Why don't you enable the regulator in can1, too?
> 
> Since they use the same regulator (the same GPIO pin control both CAN
> ports on mx28evk), I can not have regulator disabled for can0 and
> regulator enabled for can1.

Why not? I think regulators have proper refcounts and will stay enabled
in the "disabled for CAN0 and enabled for CAN1" case.

Marc


-- 
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: 263 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
  2013-06-10 16:59 ` Marc Kleine-Budde
  2013-06-10 17:03   ` Fabio Estevam
@ 2013-06-11  2:38   ` Fabio Estevam
  2013-06-12  9:39     ` Marc Kleine-Budde
  1 sibling, 1 reply; 14+ messages in thread
From: Fabio Estevam @ 2013-06-11  2:38 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: shawn.guo, linux-can, Fabio Estevam

Hi Marc,

On Mon, Jun 10, 2013 at 1:59 PM, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
};
>> +
>> +             reg_can_3v3: can-3v3 {
>> +                     compatible = "regulator-fixed";
>> +                     regulator-name = "can-3v3";
>> +                     regulator-min-microvolt = <3300000>;
>> +                     regulator-max-microvolt = <3300000>;
>> +                     gpio = <&gpio2 13 0>;
>
> Can you convert GPIO2_13 from a hog gpio to a normal pinctl gpio?

I kept gpio2_13 as a hog gpio because on imx28-evk.dts we use this
approach for the fec and usb regulators.

Hope this is OK.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
  2013-06-11  2:38   ` Fabio Estevam
@ 2013-06-12  9:39     ` Marc Kleine-Budde
  0 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2013-06-12  9:39 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: shawn.guo, linux-can, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]

On 06/11/2013 04:38 AM, Fabio Estevam wrote:
> On Mon, Jun 10, 2013 at 1:59 PM, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
> };
>>> +
>>> +             reg_can_3v3: can-3v3 {
>>> +                     compatible = "regulator-fixed";
>>> +                     regulator-name = "can-3v3";
>>> +                     regulator-min-microvolt = <3300000>;
>>> +                     regulator-max-microvolt = <3300000>;
>>> +                     gpio = <&gpio2 13 0>;
>>
>> Can you convert GPIO2_13 from a hog gpio to a normal pinctl gpio?
> 
> I kept gpio2_13 as a hog gpio because on imx28-evk.dts we use this
> approach for the fec and usb regulators.

Using the hog gpio pinmux for the fec and usb might be due to historical
reasons. I personally prefer the pinmux properly added to the regulator.
But I'm not the mxs maintainer, so I don't insist on changing the pinmux
setup. However a Acked-by from Shawn Guo would be fine.

Marc
-- 
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: 263 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
  2013-06-05 19:27 [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Fabio Estevam
                   ` (2 preceding siblings ...)
  2013-06-10 16:59 ` Marc Kleine-Budde
@ 2013-06-12 11:42 ` Shawn Guo
  2013-06-12 12:06   ` Marc Kleine-Budde
  3 siblings, 1 reply; 14+ messages in thread
From: Shawn Guo @ 2013-06-12 11:42 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: mkl, linux-can, Fabio Estevam

On Wed, Jun 05, 2013 at 04:27:24PM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
> Instead of using a GPIO to turn on/off the CAN transceiver, it is better to
> use a regulator as some systems may use a PMIC to power the CAN transceiver.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
>  .../devicetree/bindings/net/can/fsl-flexcan.txt    |  2 +
>  arch/arm/boot/dts/imx28-evk.dts                    | 11 +++++
>  arch/arm/mach-mxs/mach-mxs.c                       | 54 ++--------------------

Acked-by: Shawn Guo <shawn.guo@linaro.org>

>  drivers/net/can/flexcan.c                          | 24 +++++-----
>  4 files changed, 29 insertions(+), 62 deletions(-)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver
  2013-06-12 11:42 ` Shawn Guo
@ 2013-06-12 12:06   ` Marc Kleine-Budde
  0 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2013-06-12 12:06 UTC (permalink / raw)
  To: Shawn Guo; +Cc: Fabio Estevam, linux-can, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 1467 bytes --]

On 06/12/2013 01:42 PM, Shawn Guo wrote:
> On Wed, Jun 05, 2013 at 04:27:24PM -0300, Fabio Estevam wrote:
>> From: Fabio Estevam <fabio.estevam@freescale.com>
>>
>> Instead of using a GPIO to turn on/off the CAN transceiver, it is better to
>> use a regulator as some systems may use a PMIC to power the CAN transceiver.
>>
>> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
>> ---
>>  .../devicetree/bindings/net/can/fsl-flexcan.txt    |  2 +
>>  arch/arm/boot/dts/imx28-evk.dts                    | 11 +++++
>>  arch/arm/mach-mxs/mach-mxs.c                       | 54 ++--------------------
> 
> Acked-by: Shawn Guo <shawn.guo@linaro.org>

Tnx, I (back) ported the patch to current net-next/master, resulting in
this diff between the patches.

        of_platform_populate(NULL, of_default_bus_match_table,
--                           mxs_auxdata_lookup, parent);
-+                           NULL, parent);
+-                           mxs_auxdata_lookup, NULL);
++                           NULL, NULL);

Hope it's alright to keep your Acked-by. I will post the resulting patch
set soon, but I want to test it on real hardware next Monday.

Marc

-- 
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: 263 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-06-12 12:06 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-05 19:27 [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Fabio Estevam
2013-06-05 19:27 ` [PATCH 2/2] flexcan: Enable/Disable the CAN regulator in probe/remove Fabio Estevam
2013-06-10 17:02   ` Marc Kleine-Budde
2013-06-10 19:05     ` Fabio Estevam
2013-06-10 20:39       ` Marc Kleine-Budde
2013-06-10 20:49         ` Fabio Estevam
2013-06-10 23:35           ` Marc Kleine-Budde
2013-06-06  5:21 ` [PATCH 1/2] flexcan: Use a regulator to control the CAN transceiver Marc Kleine-Budde
2013-06-10 16:59 ` Marc Kleine-Budde
2013-06-10 17:03   ` Fabio Estevam
2013-06-11  2:38   ` Fabio Estevam
2013-06-12  9:39     ` Marc Kleine-Budde
2013-06-12 11:42 ` Shawn Guo
2013-06-12 12:06   ` Marc Kleine-Budde

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.