Skip to contentSkip to conversation

ARM: dra7: fix DCAN glitch

PATCH Superseded Roger Quadros 4 participants 20 messages Jul 7, 2015 – Jul 13, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ARM: dra7: fix DCAN glitch

Hi,

If "default" pins are active for CAN then there is a slight window during boot when CAN pins are in active mode and can affect DRA7 CAN stability. This is because device core automatically selects "default" before probe.

These patches change "default" pins to inactive and adds a new "active" pin state so that we don't encounter the glitch mentioned above.

cheers,
-roger

J.D. Schroeder (1):
net: can: c_can: Fix default pinmux glitch at init

Roger Quadros (1):
ARM: dts: dra7x-evm: Prevent glitch on DCAN1 pinmux

 arch/arm/boot/dts/dra7-evm.dts  |  5 +++--
 arch/arm/boot/dts/dra72-evm.dts |  5 +++--
 drivers/net/can/c_can/c_can.c   | 13 ++++++++++++-
 3 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/2 net: can: c_can: Fix default pinmux glitch at init

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
 drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +12 -1
index 041525d..66e98e7 100644
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
 	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
 	/* activate pins */
-	pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL
+	if (priv->device->pins) {
+		struct pinctrl_state *s;
+
+		/* Attempt to use "active" if available else use "default" */
+		s = pinctrl_lookup_state(priv->device->pins->p, "active");
+		if (!IS_ERR(s))
+			pinctrl_select_state(priv->device->pins->p, s);
+		else
+			pinctrl_pm_select_default_state(dev->dev.parent);
+	}
+#endif
 	return 0;
 }
 
Signature · 1 line
2.1.4
#16 lore raw

PATCH 2/2 ARM: dts: dra7x-evm: Prevent glitch on DCAN1 pinmux

In reply to Roger Quadros

Driver core sets "default" pinmux on on probe and CAN driver sets "sleep" pinmux during register. This causes a small window where the CAN pins are in "default" state with the DCAN module being disabled.

Change the "default" state to be like sleep so this glitch is avoided. Add a new "active" state that is used by the driver when CAN is actually active.

---
 arch/arm/boot/dts/dra7-evm.dts  | 5 +++--
 arch/arm/boot/dts/dra72-evm.dts | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/arm/boot/dts/dra7-evm.dts +3 -2
index aa46590..096f68b 100644
@@ -686,7 +686,8 @@
 
 &dcan1 {
 	status = "ok";
-	pinctrl-names = "default", "sleep";
-	pinctrl-0 = <&dcan1_pins_default>;
+	pinctrl-names = "default", "sleep", "active";
+	pinctrl-0 = <&dcan1_pins_sleep>;
 	pinctrl-1 = <&dcan1_pins_sleep>;
+	pinctrl-2 = <&dcan1_pins_default>;
 };
arch/arm/boot/dts/dra72-evm.dts +3 -2
index 4e1b605..8037384 100644
@@ -587,9 +587,10 @@
 
 &dcan1 {
 	status = "ok";
-	pinctrl-names = "default", "sleep";
-	pinctrl-0 = <&dcan1_pins_default>;
+	pinctrl-names = "default", "sleep", "active";
+	pinctrl-0 = <&dcan1_pins_sleep>;
 	pinctrl-1 = <&dcan1_pins_sleep>;
+	pinctrl-2 = <&dcan1_pins_default>;
 };
 
 &qspi {
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

In reply to Roger Quadros
Quoted 26 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
 drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 5 lines
drivers/net/can/c_can/c_can.c +1 -1
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
 	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
 	/* activate pins */
-	pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

Quoted 5 lines
drivers/net/can/c_can/c_can.c +4 -0
+	if (priv->device->pins) {
+		struct pinctrl_state *s;
+
+		/* Attempt to use "active" if available else use "default" */

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 622

Quoted 10 lines
drivers/net/can/c_can/c_can.c +7 -0
+		s = pinctrl_lookup_state(priv->device->pins->p, "active");
+		if (!IS_ERR(s))
+			pinctrl_select_state(priv->device->pins->p, s);
+		else
+			pinctrl_pm_select_default_state(dev->dev.parent);
+	}
+#endif
 	return 0;
 }
 

Marc

Signature · 4 lines
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   |
#3 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

Quoted 29 lines · Marc Kleine-Budde
Quoted 28 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
  drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
  	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
Quoted 6 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 3 lines
drivers/net/can/c_can/c_can.c +1 -1
  	/* activate pins */
-	pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

yes, you are right.

cheers,
-roger

Quoted 19 lines
Quoted 6 lines
drivers/net/can/c_can/c_can.c +4 -0
+	if (priv->device->pins) {
+		struct pinctrl_state *s;
+
+		/* Attempt to use "active" if available else use "default" */

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 622

Quoted 10 lines
drivers/net/can/c_can/c_can.c +7 -0
+		s = pinctrl_lookup_state(priv->device->pins->p, "active");
+		if (!IS_ERR(s))
+			pinctrl_select_state(priv->device->pins->p, s);
+		else
+			pinctrl_pm_select_default_state(dev->dev.parent);
+	}
+#endif
  	return 0;
  }
 

Marc

#4 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

Quoted 32 lines · Roger Quadros
Quoted 31 lines · Marc Kleine-Budde
Quoted 30 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface
is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
  drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
      priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
Quoted 8 lines
Quoted 6 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 3 lines
drivers/net/can/c_can/c_can.c +1 -1
      /* activate pins */
-    pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

yes, you are right.

On second thoughts

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

cheers,
-roger

Quoted 24 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/can/c_can/c_can.c +9 -0
+    if (priv->device->pins) {
+        struct pinctrl_state *s;
+
+        /* Attempt to use "active" if available else use "default" */
+        s = pinctrl_lookup_state(priv->device->pins->p, "active");
+        if (!IS_ERR(s))
+            pinctrl_select_state(priv->device->pins->p, s);
+        else
+            pinctrl_pm_select_default_state(dev->dev.parent);
Quoted 9 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 622

Quoted 6 lines
drivers/net/can/c_can/c_can.c +2 -0
+    }
+#endif
      return 0;
  }
 

Marc

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

Quoted 15 lines · Roger Quadros
Quoted 15 lines
Quoted 14 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 11 lines
drivers/net/can/c_can/c_can.c +1 -1
index 041525d..66e98e7 100644
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
      priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
      /* activate pins */
-    pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

Quoted 6 lines
Quoted 1 line

yes, you are right.

On second thoughts

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

Too bad :(

okay - should I add [email protected] on Cc?

Marc

Signature · 4 lines
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   |
#8 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

In reply to Roger Quadros
Quoted 42 lines · Roger Quadros
Quoted 41 lines · Roger Quadros
Quoted 39 lines · Marc Kleine-Budde
Quoted 30 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface
is down) causes a slight glitch on the pinctrl settings when used. Since
commit ab78029 (drivers/pinctrl: grab default handles from device core),
the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
  drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 5 lines
drivers/net/can/c_can/c_can.c +1 -1
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
      priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
      /* activate pins */
-    pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

Quoted 6 lines
Quoted 1 line

yes, you are right.

On second thoughts

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

May be you can use [devm_]pinctrl_get?

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/net/can/c_can/c_can.c +11 -0
+    if (priv->device->pins) {
+        struct pinctrl_state *s;
+
+        /* Attempt to use "active" if available else use "default" */
+        s = pinctrl_lookup_state(priv->device->pins->p, "active");
+        if (!IS_ERR(s))
+            pinctrl_select_state(priv->device->pins->p, s);
+        else
+            pinctrl_pm_select_default_state(dev->dev.parent);
+    }
+#endif
      return 0;
  }
 
Signature · 2 lines
regards,
-grygorii
#6 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

In reply to Marc Kleine-Budde

Marc,

Quoted 18 lines · Marc Kleine-Budde
Quoted 17 lines · Roger Quadros
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
       priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
Quoted 6 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 3 lines
drivers/net/can/c_can/c_can.c +1 -1
       /* activate pins */
-    pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

yes, you are right.

Quoted 8 lines
Quoted 4 lines

On second thoughts

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

Too bad :(

okay - should I add [email protected] on Cc?

I'm not sure if it would help. This patch by itself won't fix anything. It needs to go in together with the DTS change in patch 2.

Maybe if Tony can Ack the second patch then both should be applicable on v4.0+ for stable.

cheers,
-roger

#9 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

In reply to Grygorii Strashko
Quoted 43 lines · Grygorii Strashko
Quoted 42 lines · Roger Quadros
Quoted 41 lines · Roger Quadros
Quoted 39 lines · Marc Kleine-Budde
Quoted 30 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface
is down) causes a slight glitch on the pinctrl settings when used. Since
commit ab78029 (drivers/pinctrl: grab default handles from device core),
the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
  drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 5 lines
drivers/net/can/c_can/c_can.c +1 -1
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
      priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
      /* activate pins */
-    pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

yes, you are right.

On second thoughts

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

May be you can use [devm_]pinctrl_get?

Why should we do that? The device core has already done the pinctrl_get() and it is available in device->pins->p.

cheers,
-roger

Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/can/c_can/c_can.c +11 -0
+    if (priv->device->pins) {
+        struct pinctrl_state *s;
+
+        /* Attempt to use "active" if available else use "default" */
+        s = pinctrl_lookup_state(priv->device->pins->p, "active");
+        if (!IS_ERR(s))
+            pinctrl_select_state(priv->device->pins->p, s);
+        else
+            pinctrl_pm_select_default_state(dev->dev.parent);
+    }
+#endif
      return 0;
  }
 
#7 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

In reply to Roger Quadros
Quoted 9 lines · Roger Quadros
Quoted 6 lines
Quoted 2 lines

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

Too bad :(

okay - should I add [email protected] on Cc?

I'm not sure if it would help. This patch by itself won't fix anything. It needs to go in together with the DTS change in patch 2.

Of course.

Quoted 2 lines

Maybe if Tony can Ack the second patch then both should be applicable on v4.0+ for stable.

Marc

Signature · 4 lines
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   |
#10 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

In reply to Roger Quadros
Quoted 49 lines · Roger Quadros
Quoted 47 lines · Grygorii Strashko
Quoted 46 lines · Roger Quadros
Quoted 34 lines · Roger Quadros
Quoted 33 lines · Marc Kleine-Budde
Quoted 32 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface
is down) causes a slight glitch on the pinctrl settings when used. Since
commit ab78029 (drivers/pinctrl: grab default handles from device core),
the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
  drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
      priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
Quoted 8 lines
Quoted 6 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 3 lines
drivers/net/can/c_can/c_can.c +1 -1
      /* activate pins */
-    pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

yes, you are right.

On second thoughts

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

May be you can use [devm_]pinctrl_get?

Why should we do that? The device core has already done the pinctrl_get() and it is available in device->pins->p.

True. But It seems, you are going to be only one direct user of pin->p in whole kernel (outside of pictrl core) !? ;)

pinctrl_get() will just return a pointer on pinctrl associated with dev if called not the first time and increment kbobj use-counter.

Also, there is nice API pinctrl_get_select() and example in kernel 2c7c2c1d.

So, according to the documentation and pinctrl code, below sequence should work:

struct pinctrl *p;
p = pinctrl_get_select(priv->device, "active");

if (!IS_ERR(p))
pinctrl_put(p);
else
pinctrl_pm_select_default_state(priv->device);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 615

Quoted 9 lines
drivers/net/can/c_can/c_can.c +4 -0
+    if (priv->device->pins) {
+        struct pinctrl_state *s;
+
+        /* Attempt to use "active" if available else use 

"default" */

drivers/net/can/c_can/c_can.c +3 -0
+        s = pinctrl_lookup_state(priv->device->pins->p, "active");
+        if (!IS_ERR(s))
+            pinctrl_select_state(priv->device->pins->p, s);

^^ different devices passed here

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 617

Quoted 2 lines
drivers/net/can/c_can/c_can.c +2 -0
+        else
+            pinctrl_pm_select_default_state(dev->dev.parent);

^^ and here ? Is it ok?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/can/c_can/c_can.c +2 -0
+    }
+#endif
      return 0;
  }
Signature · 2 lines
regards,
-grygorii
#11 lore raw

Re: [PATCH 1/2] net: can: c_can: Fix default pinmux glitch at init

Quoted 53 lines · Grygorii Strashko
Quoted 52 lines · Roger Quadros
Quoted 50 lines · Grygorii Strashko
Quoted 48 lines · Roger Quadros
Quoted 34 lines · Roger Quadros
Quoted 33 lines · Marc Kleine-Budde
Quoted 32 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface
is down) causes a slight glitch on the pinctrl settings when used. Since
commit ab78029 (drivers/pinctrl: grab default handles from device core),
the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2

---
  drivers/net/can/c_can/c_can.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +0 -0
index 041525d..66e98e7 100644
@@ -605,7 +605,18 @@ static int c_can_start(struct net_device *dev)
      priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
Quoted 8 lines
Quoted 6 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 608

Quoted 3 lines
drivers/net/can/c_can/c_can.c +1 -1
      /* activate pins */
-    pinctrl_pm_select_default_state(dev->dev.parent);
+#ifdef CONFIG_PINCTRL

Please remove the ifdef, AFAICS there are static inline noop functions if CONFIG_PINCTRL switched off.

yes, you are right.

On second thoughts

device->pins are not defined if CONFIG_PINCTRL is not set. so we can't remove the #ifdef.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

May be you can use [devm_]pinctrl_get?

Why should we do that? The device core has already done the pinctrl_get() and it is available in device->pins->p.

True. But It seems, you are going to be only one direct user of pin->p in whole kernel (outside of pictrl core) !? ;)

good point :).

Quoted 8 lines

pinctrl_get() will just return a pointer on pinctrl associated with dev if called not the first time and increment kbobj use-counter.

Also, there is nice API pinctrl_get_select() and example in kernel 2c7c2c1d.

So, according to the documentation and pinctrl code, below sequence should work:

Quoted 7 lines

struct pinctrl *p;
p = pinctrl_get_select(priv->device, "active");

if (!IS_ERR(p))
pinctrl_put(p);
else
pinctrl_pm_select_default_state(priv->device);

This is much neater. I will give that a try. Thanks.

cheers,
-roger

Quoted 29 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/net/can/c_can/c_can.c

Quoted 8 lines
drivers/net/can/c_can/c_can.c +4 -0
+    if (priv->device->pins) {
+        struct pinctrl_state *s;
+
+        /* Attempt to use "active" if available else use 

"default" */

drivers/net/can/c_can/c_can.c +3 -0
+        s = pinctrl_lookup_state(priv->device->pins->p, "active");
+        if (!IS_ERR(s))
+            pinctrl_select_state(priv->device->pins->p, s);

^^ different devices passed here

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/can/c_can/c_can.c

Quoted 2 lines
drivers/net/can/c_can/c_can.c +2 -0
+        else
+            pinctrl_pm_select_default_state(dev->dev.parent);

^^ and here ? Is it ok?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/can/c_can/c_can.c +2 -0
+    }
+#endif
      return 0;
  }
#12 lore raw

PATCH v2 1/2 net: can: c_can: Fix default pinmux glitch at init

In reply to Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2 and use pinctrl_get_select().

---
 drivers/net/can/c_can/c_can.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +8 -2
index 041525d..5d214d1 100644
@@ -592,6 +592,7 @@ static int c_can_start(struct net_device *dev)
 {
 	struct c_can_priv *priv = netdev_priv(dev);
 	int err;
+	struct pinctrl *p;
 
 	/* basic c_can configuration */
 	err = c_can_chip_config(dev);
@@ -604,8 +605,13 @@ static int c_can_start(struct net_device *dev)
 
 	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
-	/* activate pins */
-	pinctrl_pm_select_default_state(dev->dev.parent);
+	/* Attempt to use "active" if available else use "default" */
+	p = pinctrl_get_select(priv->device, "active");
+	if (!IS_ERR(p))
+		pinctrl_put(p);
+	else
+		pinctrl_pm_select_default_state(priv->device);
+
 	return 0;
 }
 
Signature · 1 line
2.1.4
#13 lore raw

Re: [PATCH v2 1/2] net: can: c_can: Fix default pinmux glitch at init

Quoted 36 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2 and use pinctrl_get_select().

---
  drivers/net/can/c_can/c_can.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +1 -0
index 041525d..5d214d1 100644
@@ -592,6 +592,7 @@ static int c_can_start(struct net_device *dev)
  {
  	struct c_can_priv *priv = netdev_priv(dev);
  	int err;
+	struct pinctrl *p;
 
  	/* basic c_can configuration */
  	err = c_can_chip_config(dev);
@@ -604,8 +605,13 @@ static int c_can_start(struct net_device *dev)
 
  	priv->can.state = CAN_STATE_ERROR_ACTIVE;

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 614

Quoted 10 lines
drivers/net/can/c_can/c_can.c +7 -2
 
-	/* activate pins */
-	pinctrl_pm_select_default_state(dev->dev.parent);
+	/* Attempt to use "active" if available else use "default" */
+	p = pinctrl_get_select(priv->device, "active");
+	if (!IS_ERR(p))
+		pinctrl_put(p);
+	else
+		pinctrl_pm_select_default_state(priv->device);
+

Thanks. This part looks good to me now.

Quoted 4 lines
drivers/net/can/c_can/c_can.c +0 -0
  	return 0;
  }
 
Signature · 2 lines
regards,
-grygorii
#14 lore raw

Re: [PATCH v2 1/2] net: can: c_can: Fix default pinmux glitch at init

Quoted 38 lines · Grygorii Strashko
Quoted 37 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2 and use pinctrl_get_select().

---
  drivers/net/can/c_can/c_can.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +1 -0
index 041525d..5d214d1 100644
@@ -592,6 +592,7 @@ static int c_can_start(struct net_device *dev)
  {
  	struct c_can_priv *priv = netdev_priv(dev);
  	int err;
+	struct pinctrl *p;
 
  	/* basic c_can configuration */
  	err = c_can_chip_config(dev);
@@ -604,8 +605,13 @@ static int c_can_start(struct net_device *dev)
 
  	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
Quoted 11 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 614

Quoted 9 lines
drivers/net/can/c_can/c_can.c +7 -2
-	/* activate pins */
-	pinctrl_pm_select_default_state(dev->dev.parent);
+	/* Attempt to use "active" if available else use "default" */
+	p = pinctrl_get_select(priv->device, "active");
+	if (!IS_ERR(p))
+		pinctrl_put(p);
+	else
+		pinctrl_pm_select_default_state(priv->device);
+

Thanks. This part looks good to me now.

Is this an Acked-by?

Marc

Signature · 4 lines
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   |
#15 lore raw

Re: [PATCH v2 1/2] net: can: c_can: Fix default pinmux glitch at init

Quoted 51 lines · Marc Kleine-Budde
Quoted 38 lines · Grygorii Strashko
Quoted 37 lines · Roger Quadros

From: "J.D. Schroeder" <[email protected]>

The previous change 3973c526ae9c (net: can: c_can: Disable pins when CAN interface is down) causes a slight glitch on the pinctrl settings when used. Since commit ab78029 (drivers/pinctrl: grab default handles from device core), the device core will automatically set the default pins. This causes the pins to be momentarily set to the default and then to the sleep state in register_c_can_dev(). By adding an optional "enable" state, boards can set the default pin state to be disabled and avoid the glitch when the switch from default to sleep first occurs. If the "enable" state is not available c_can_pinctrl_select_state() falls back to using the "default" pinctrl state.

[Roger Q] - Forward port to v4.2 and use pinctrl_get_select().

---
   drivers/net/can/c_can/c_can.c | 10 ++++++++--
   1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +1 -0
index 041525d..5d214d1 100644
@@ -592,6 +592,7 @@ static int c_can_start(struct net_device *dev)
   {
   	struct c_can_priv *priv = netdev_priv(dev);
   	int err;
+	struct pinctrl *p;
 
   	/* basic c_can configuration */
   	err = c_can_chip_config(dev);
@@ -604,8 +605,13 @@ static int c_can_start(struct net_device *dev)
 
   	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
Quoted 11 lines

drivers/net/can/c_can/c_can.c static int c_can_start(struct net_device *dev) · line 614

Quoted 9 lines
drivers/net/can/c_can/c_can.c +7 -2
-	/* activate pins */
-	pinctrl_pm_select_default_state(dev->dev.parent);
+	/* Attempt to use "active" if available else use "default" */
+	p = pinctrl_get_select(priv->device, "active");
+	if (!IS_ERR(p))
+		pinctrl_put(p);
+	else
+		pinctrl_pm_select_default_state(priv->device);
+

Thanks. This part looks good to me now.

Quoted 1 line

Is this an Acked-by?

Not sure I can ack overall patch - is up to can driver maintainer for this part Reviewed-by: Grygorii Strashko <[email protected]>

Signature · 2 lines
regards,
-grygorii
#17 lore raw

Re: [PATCH 2/2] ARM: dts: dra7x-evm: Prevent glitch on DCAN1 pinmux

In reply to Roger Quadros
Quoted 8 lines · Roger Quadros

Driver core sets "default" pinmux on on probe and CAN driver sets "sleep" pinmux during register. This causes a small window where the CAN pins are in "default" state with the DCAN module being disabled.

Change the "default" state to be like sleep so this glitch is avoided. Add a new "active" state that is used by the driver when CAN is actually active.

Who is taking care of this patch? I'm applying 1/2 (v2) to linux-can, should I take this patch, too?

Marc

Signature · 4 lines
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   |
#18 lore raw

Re: [PATCH 2/2] ARM: dts: dra7x-evm: Prevent glitch on DCAN1 pinmux

Quoted 6 lines · Marc Kleine-Budde
Quoted 5 lines · Roger Quadros

Driver core sets "default" pinmux on on probe and CAN driver sets "sleep" pinmux during register. This causes a small window where the CAN pins are in "default" state with the DCAN module being disabled.

Quoted 6 lines
Quoted 3 lines

Change the "default" state to be like sleep so this glitch is avoided. Add a new "active" state that is used by the driver when CAN is actually active.

Who is taking care of this patch? I'm applying 1/2 (v2) to linux-can, should I take this patch, too?

I've included this patch in my pull request.

Marc

Signature · 4 lines
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   |
#19 lore raw

Re: [PATCH 2/2] ARM: dts: dra7x-evm: Prevent glitch on DCAN1 pinmux

Quoted 7 lines · Marc Kleine-Budde
Quoted 6 lines · Marc Kleine-Budde
Quoted 5 lines · Roger Quadros

Driver core sets "default" pinmux on on probe and CAN driver sets "sleep" pinmux during register. This causes a small window where the CAN pins are in "default" state with the DCAN module being disabled.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Change the "default" state to be like sleep so this glitch is avoided. Add a new "active" state that is used by the driver when CAN is actually active.

Who is taking care of this patch? I'm applying 1/2 (v2) to linux-can, should I take this patch, too?

I've included this patch in my pull request.

That's fine thanks there should not be any merge conflicts.

For things going in during the merge windows we need to worry about the dts merge conflicts. Usually not a problem for fixes.

Regards,

Tony