Skip to contentSkip to conversation

flexcan driver updates

PATCH In review Shawn Guo 6 participants 41 messages Jun 28, 2012 – Aug 9, 2012 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

v2 cover flexcan driver updates

Changes since v1:
* Add phy-standby-gpios support
* Remove enable-active-low and use of_get_named_gpio_flags instead
* Use devm_gpio_request_one instead of gpio_request_one

Shawn Guo (2):
net: flexcan: clock-frequency is optional for device tree probe
net: flexcan: add transceiver switch gpios support

 .../devicetree/bindings/net/can/fsl-flexcan.txt    |    5 ++
 drivers/net/can/flexcan.c                          |   62 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH v2 1/2 net: flexcan: clock-frequency is optional for device tree probe

The property clock-frequency is optional for device tree probe. When it's absent, the flexcan driver will try to get the frequency from clk system by calling clk_get_rate.

---
 .../devicetree/bindings/net/can/fsl-flexcan.txt    |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +3 -0
index f31b686..8ff324e 100644
@@ -11,6 +11,9 @@ Required properties:
 
 - reg : Offset and length of the register set for this device
 - interrupts : Interrupt tuple for this device
+
+Optional properties:
+
 - clock-frequency : The oscillator frequency driving the flexcan device
 
 Example:
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH v2 1/2 net: flexcan: clock-frequency is optional for device tree probe

Quoted 5 lines · Shawn Guo

The property clock-frequency is optional for device tree probe. When it's absent, the flexcan driver will try to get the frequency from clk system by calling clk_get_rate.

Regards
Dong Aisheng

author
#3 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo

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.

---
 .../devicetree/bindings/net/can/fsl-flexcan.txt    |    2 +
 drivers/net/can/flexcan.c                          |   62 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +2 -0
index 8ff324e..e0dbac7 100644
@@ -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:
 
drivers/net/can/flexcan.c +62 -0

115 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#4 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Hi,

Quoted 23 lines · Shawn Guo

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.

---
 .../devicetree/bindings/net/can/fsl-flexcan.txt    |    2 +
 drivers/net/can/flexcan.c                          |   62 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +0 -0
index 8ff324e..e0dbac7 100644

Documentation/devicetree/bindings/net/can/fsl-flexcan.txt Required properties: · line 20

Quoted 6 lines
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +2 -0
@@ -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
 

Why the plural form 'gpios'? It's just one gpio.
s/gpios/gpio/ ?

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
author
#5 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 6 lines · Lothar Waßmann
Quoted 3 lines
+- phy-enable-gpios : Specify the gpio used to enable phy
+- phy-standby-gpios : Specify the gpio used to put phy into STANDBY mode

Why the plural form 'gpios'? It's just one gpio.
s/gpios/gpio/ ?

It's a common pattern suggested by common gpio bindings Documentation/devicetree/bindings/gpio/gpio.txt.

Signature · 2 lines
Regards,
Shawn
#6 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo
Quoted 24 lines · Shawn Guo

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.

---
 .../devicetree/bindings/net/can/fsl-flexcan.txt    |    2 +
 drivers/net/can/flexcan.c                          |   62 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +0 -0
index 8ff324e..e0dbac7 100644

Documentation/devicetree/bindings/net/can/fsl-flexcan.txt Required properties: · line 22

Quoted 8 lines
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +2 -0
@@ -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:
 

Do we need to add new added entries in the example section as well.

E.g.

+ phy-enable-gpios = <&gpio1 4 0>; /* GPIO1_4, active high*/
+ phy-standby-gpios = <&gpio1 2 1>; /* GPIO1_2, active low */

drivers/net/can/flexcan.c line 30

Quoted 10 lines
drivers/net/can/flexcan.c +1 -0
index 38c0690..1ce3f9e 100644
@@ -26,6 +26,7 @@
 #include <linux/can/platform/flexcan.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/gpio.h>
 

It seems <linux/of_gpio.h> already unconditionally includes this header.

drivers/net/can/flexcan.c line 41

Quoted 12 lines
drivers/net/can/flexcan.c +0 -0
 #include <linux/if_arp.h>
 #include <linux/if_ether.h>

#include <linux/interrupt.h>

drivers/net/can/flexcan.c +1 -0
@@ -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>
 

Other looks fine to me.

Regards,
Hui.

author
#7 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 15 lines · Hui Wang
Quoted 10 lines
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +0 -0
index 8ff324e..e0dbac7 100644
@@ -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:

Do we need to add new added entries in the example section as well.

E.g.

Review

Quoted 2 lines
(quoted diff) +2 -0
+        phy-enable-gpios = <&gpio1 4 0>; /* GPIO1_4, active high*/
+        phy-standby-gpios = <&gpio1 2 1>; /* GPIO1_2, active low */

I chose not to because after all these two are optional properties.

Quoted 10 lines

drivers/net/can/flexcan.c line 29

Quoted 9 lines
drivers/net/can/flexcan.c +1 -0
index 38c0690..1ce3f9e 100644
@@ -26,6 +26,7 @@
 #include <linux/can/platform/flexcan.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/gpio.h>

It seems <linux/of_gpio.h> already unconditionally includes this header.

Documentation/SubmitChecklist

1: If you use a facility then #include the file that defines/declares
that facility. Don't depend on other header files pulling in ones that you use.

Signature · 2 lines
Regards,
Shawn
#8 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 15 lines · Shawn Guo
Quoted 13 lines · Hui Wang
Quoted 11 lines
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +0 -0
index 8ff324e..e0dbac7 100644
@@ -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:

Do we need to add new added entries in the example section as well.

Quoted 9 lines

Review

Quoted 6 lines

E.g.

(quoted diff) +2 -0
+        phy-enable-gpios = <&gpio1 4 0>; /* GPIO1_4, active high*/
+        phy-standby-gpios = <&gpio1 2 1>; /* GPIO1_2, active low */

I chose not to because after all these two are optional properties.

OK.

Quoted 13 lines
Quoted 12 lines

drivers/net/can/flexcan.c line 30

Quoted 10 lines
drivers/net/can/flexcan.c +1 -0
index 38c0690..1ce3f9e 100644
@@ -26,6 +26,7 @@
 #include <linux/can/platform/flexcan.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/gpio.h>
 

It seems <linux/of_gpio.h> already unconditionally includes this header.

Quoted 7 lines

Documentation/SubmitChecklist

1: If you use a facility then #include the file that defines/declares
that facility. Don't depend on other header files pulling in ones that you use.

Got it.

OK to me.

Regards,
Hui.

#9 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 44 lines · Hui Wang
Quoted 18 lines · Shawn Guo
Quoted 16 lines · Hui Wang
Quoted 9 lines

diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt index 8ff324e..e0dbac7 100644

Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +0 -0
@@ -15,6 +15,8 @@ Required properties:

Optional properties:
- clock-frequency : The oscillator frequency driving the flexcan device

Quoted 5 lines
+- phy-enable-gpios : Specify the gpio used to enable phy
+- phy-standby-gpios : Specify the gpio used to put phy into STANDBY

mode
Example:

Do we need to add new added entries in the example section as well.

Quoted 9 lines

Review

Quoted 6 lines

E.g.

(quoted diff) +2 -0
+        phy-enable-gpios = <&gpio1 4 0>; /* GPIO1_4, active high*/
+        phy-standby-gpios = <&gpio1 2 1>; /* GPIO1_2, active low */

I chose not to because after all these two are optional properties.

OK.

Quoted 15 lines
Quoted 12 lines

drivers/net/can/flexcan.c line 30

Quoted 10 lines
drivers/net/can/flexcan.c +1 -0
index 38c0690..1ce3f9e 100644
@@ -26,6 +26,7 @@
 #include <linux/can/platform/flexcan.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/gpio.h>
 

It seems <linux/of_gpio.h> already unconditionally includes this header.

Documentation/SubmitChecklist

Quoted 8 lines
Quoted 5 lines

1: If you use a facility then #include the file that defines/declares
that facility. Don't depend on other header files pulling in ones that you use.

Got it.

OK to me.

Is this an Acked-by?

Marc

Signature · 12 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   |

-------------- 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/b1b05659/attachment.sig>
#10 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo
Quoted 11 lines · Shawn Guo

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.

Quoted 88 lines
---
 .../devicetree/bindings/net/can/fsl-flexcan.txt    |    2 +
 drivers/net/can/flexcan.c                          |   62 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +2 -0
index 8ff324e..e0dbac7 100644
@@ -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:
 
drivers/net/can/flexcan.c +23 -0
index 38c0690..1ce3f9e 100644
@@ -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,

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 977

Quoted 10 lines
drivers/net/can/flexcan.c +7 -0
 						"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.

Quoted 49 lines
drivers/net/can/flexcan.c +32 -0
+			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;
 }
 
Signature · 12 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   |

-------------- 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>
author
#11 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 2 lines · Marc Kleine-Budde

Hmm I'm wondering if transceiver or phy is the correct name here. In platform_data it's called transceiver_switch.

The transceiver_switch in platform_data names a function, while we are naming a couple gpios which happen to be access in that function. It looks all correct to me.

Quoted 13 lines
Quoted 13 lines
drivers/net/can/flexcan.c +5 -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;
 
Quoted 16 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 977

Quoted 11 lines
drivers/net/can/flexcan.c +7 -0
 		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.

Ok, we will have these two bool variables named phy_en_active_low and phy_stby_active_low. Will resend to change them.

Signature · 2 lines
Regards,
Shawn
#12 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 7 lines · Shawn Guo
Quoted 2 lines · Marc Kleine-Budde

Hmm I'm wondering if transceiver or phy is the correct name here. In platform_data it's called transceiver_switch.

The transceiver_switch in platform_data names a function, while we are naming a couple gpios which happen to be access in that function. It looks all correct to me.

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Marc

Signature · 12 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   |

-------------- 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/75c661b1/attachment.sig>
author
#13 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

But it does not really matter to me, will change the name since you care about it.

Signature · 2 lines
Regards,
Shawn
author
#14 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 6 lines · Shawn Guo
Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Quoted 7 lines

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

But it does not really matter to me, will change the name since you care about it.

Do you care the variable name also? If so, we will get:

        int transceiver_en_gpio;
        int transceiver_stby_gpio;
        bool transceiver_en_high;
        bool transceiver_stby_high;

So everything becomes long :)

Signature · 2 lines
Regards,
Shawn
author
#15 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 9 lines · Shawn Guo

Do you care the variable name also? If so, we will get:

        int transceiver_en_gpio;
        int transceiver_stby_gpio;
        bool transceiver_en_high;
        bool transceiver_stby_high;

So everything becomes long :)

Oh, even longer, since we have agreed "high" should be renamed to "active_low":

	bool transceiver_en_active_low;
	bool transceiver_stby_active_low;

Can we keep using "phy" to have the names a little bit shorter?

Signature · 2 lines
Regards,
Shawn
#16 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 8 lines · Shawn Guo
Quoted 7 lines · Shawn Guo

Do you care the variable name also? If so, we will get:

        int transceiver_en_gpio;
        int transceiver_stby_gpio;
        bool transceiver_en_high;
        bool transceiver_stby_high;
Quoted 8 lines
Quoted 2 lines

So everything becomes long :)

Oh, even longer, since we have agreed "high" should be renamed to "active_low":

	bool transceiver_en_active_low;
	bool transceiver_stby_active_low;

How about just active_low since they're just temp variables?

And if you do not assign them together at last, you may only need:
int gpio;
bool active_high;

That saves you two variables.

Regards
Dong Aisheng

#17 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo
Quoted 14 lines · Shawn Guo
Quoted 6 lines · Shawn Guo
Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Quoted 7 lines

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

But it does not really matter to me, will change the name since you care about it.

Quoted 9 lines

Do you care the variable name also? If so, we will get:

        int transceiver_en_gpio;
        int transceiver_stby_gpio;
        bool transceiver_en_high;
        bool transceiver_stby_high;

So everything becomes long :)

'xcvr' is a common acronym for 'transceiver'.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#18 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo

Hi,

Quoted 6 lines · Shawn Guo
Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Quoted 7 lines

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

But it does not really matter to me, will change the name since you care about it.

A transceiver is just a dumb piece of hardware, while a PHY contains some intelligence of its own.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
author
#19 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 13 lines · Lothar Waßmann

Hi,

Quoted 10 lines · Shawn Guo
Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

Quoted 6 lines
Quoted 3 lines

But it does not really matter to me, will change the name since you care about it.

A transceiver is just a dumb piece of hardware, while a PHY contains some intelligence of its own.

Then, it sounds more like a PHY than transceiver, since it's an IC chip with some control over it.

Signature · 2 lines
Regards,
Shawn
#20 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Hi,

Quoted 14 lines · Shawn Guo
Quoted 13 lines · Lothar Wa?mann

Hi,

Quoted 10 lines · Shawn Guo
Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

But it does not really matter to me, will change the name since you care about it.

A transceiver is just a dumb piece of hardware, while a PHY contains some intelligence of its own.

Then, it sounds more like a PHY than transceiver, since it's an IC chip with some control over it.

The 'I' in 'IC' does not stand for 'intelligent', but for 'integrated'. ;)
A can transceiver is usually merely a switchable buffer. There are no registers to configure it or an internal processor that does some magic.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#21 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 34 lines · Lothar Wa?mann

Hi,

Quoted 22 lines · Shawn Guo
Quoted 20 lines · Lothar Wa?mann

Hi,

Quoted 16 lines · Shawn Guo
Quoted 6 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

But it does not really matter to me, will change the name since you care about it.

Quoted 8 lines
Quoted 4 lines

A transceiver is just a dumb piece of hardware, while a PHY contains some intelligence of its own.

Then, it sounds more like a PHY than transceiver, since it's an IC chip with some control over it.

Quoted 7 lines

The 'I' in 'IC' does not stand for 'intelligent', but for 'integrated'. ;)
A can transceiver is usually merely a switchable buffer. There are no registers to configure it or an internal processor that does some magic.

Sorry for reply late, in my first patch, i chose "phy" instead of "xcvr" because the MC33902 datasheet tell me it is a "high speed CAN physical interface", and it includes "an internal 5.0 V supply for the CAN bus transceiver".

And from the diagram in the page 1 of the MC33902 datasheet, the MC33902 includes bus xcvr, i/o control logic, power supply and external regulator control logic. As a result i decided to use phy in the driver.

Regards,
Hui.

Quoted 2 lines

Lothar Wa?mann

#22 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo
Quoted 9 lines · Shawn Guo
Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

'trx' seemed the right abbreviation
http://www.acronymfinder.com/TRX.html

thanks to Oliver, in his email on May 9th.

Kurt

#23 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 7 lines · Kurt Van Dijck
Quoted 6 lines · Shawn Guo
Quoted 5 lines · Marc Kleine-Budde

I mean which name is more precise, do these gpio enable/standy a "phy" or a "transceiver". For example:
http://www.nxp.com/documents/application_note/AN00094.pdf, this document
says: TJA1041/1041A high speed CAN transceiver.

Quoted 8 lines
Quoted 3 lines

Isn't term "phy" (physical interface) generally meant to be the same thing as "transceiver"? I just happened to like the shorter one as what Hui did in his patch.

'trx' seemed the right abbreviation
http://www.acronymfinder.com/TRX.html

thanks to Oliver, in his email on May 9th.

I was about to propose CamelCase to keep the variable names shorter:

bool transceiverStbyActiveLow;

scnr, Marc

Signature · 12 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   |

-------------- 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/667b8137/attachment.sig>
#25 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Marc Kleine-Budde
Quoted 13 lines · Marc Kleine-Budde
Quoted 11 lines · Shawn Guo

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.

Quoted 3 lines

Hmm I'm wondering if transceiver or phy is the correct name here. In platform_data it's called transceiver_switch.

Hmm, i also had this wondering.
I quote some info from the spec like:
"The MC33902 is a high speed CAN physical interface. The device includes an internal 5.0 V supply for the CAN bus transceiver, and requires only a connection to a battery line."

Maybe transceiver is more close to spec.

Regards
Dong Aisheng

#26 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo
Quoted 11 lines · Shawn Guo

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, ideally these things are not so suitable to be put in controller driver since they're platform specific.
However i also did not have better idea now.

One rough thought is maybe create a supported can phy libs and hook to controller dynamically?

Quoted 4 lines
drivers/net/can/flexcan.c +4 -0
+		phy_stby_gpio = of_get_named_gpio_flags(pdev->dev.of_node,
+							"phy-standby-gpios",
+							0, &flags);
+		if (gpio_is_valid(phy_stby_gpio)) {

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 10 lines
drivers/net/can/flexcan.c +10 -0
+			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;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

Quoted 17 lines
drivers/net/can/flexcan.c +6 -0
+			}
+		}
 	}
 
 	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);

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1092

Quoted 7 lines
drivers/net/can/flexcan.c +1 -0
@@ -1025,6 +1086,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
 	if (clk)
 		clk_put(clk);
  failed_clock:
+ failed_gpio:
 	return err;
 }
 

Regards
Dong Aisheng

author
#27 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

	can0: can@80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can@80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};
Signature · 2 lines
Regards,
Shawn
#28 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 22 lines · Shawn Guo
Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

Quoted 12 lines
	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};

Yes, that is a solution.
But it may not so reasonable since dts file should represent hw, but here we have to do some trick by we know how driver works.
Maybe we need find a better solution.

Regards
Dong Aisheng

author
#29 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 5 lines · Dong Aisheng

Yes, that is a solution.
But it may not so reasonable since dts file should represent hw, but here we have to do some trick by we know how driver works.
Maybe we need find a better solution.

I wouldn't agree that driver should take care of all such kind of board weirdness.

Signature · 2 lines
Regards,
Shawn
#30 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Dong Aisheng
Quoted 35 lines · Dong Aisheng
Quoted 22 lines · Shawn Guo
Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

Quoted 12 lines
	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};
Quoted 5 lines

Yes, that is a solution.
But it may not so reasonable since dts file should represent hw, but here we have to do some trick by we know how driver works.
Maybe we need find a better solution.

One more thing, for such dt representation, if can0 phy is disabled, can1 may be disabled wrongly too, right?

Regards
Dong Aisheng

author
#31 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 3 lines · Dong Aisheng

One more thing, for such dt representation, if can0 phy is disabled, can1 may be disabled wrongly too, right?

Right. Looks like we have to take care of the weirdness then.

Signature · 2 lines
Regards,
Shawn
#32 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Shawn Guo
Quoted 22 lines · Shawn Guo
Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

Quoted 12 lines
	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};

Will this work if can0 is down and can1 is up?

Can we abstract the transceiver power as a regulator? Or a clock? :P

Marc

Signature · 12 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   |

-------------- 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/6de502a1/attachment.sig>
#33 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 36 lines · Marc Kleine-Budde
Quoted 22 lines · Shawn Guo
Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

Quoted 12 lines
	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};
Quoted 4 lines

Will this work if can0 is down and can1 is up?

Can we abstract the transceiver power as a regulator? Or a clock? :P

Hmm, it may not be a power.
For mx28evk, it's a STBY pin.
So it may hard to abstract it as a regulator or clock.

Regards
Dong Aisheng

#34 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Hi,

Quoted 37 lines · Dong Aisheng
Quoted 36 lines · Marc Kleine-Budde
Quoted 34 lines · Shawn Guo
Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};
Quoted 8 lines
Quoted 4 lines

Will this work if can0 is down and can1 is up?

Can we abstract the transceiver power as a regulator? Or a clock? :P

Hmm, it may not be a power.
For mx28evk, it's a STBY pin.
So it may hard to abstract it as a regulator or clock.

I have created a 'gpio-switch' driver in my private tree that can be used for exactly this purpose. It takes care of the pin polarity and initial state of the pins and can handle shared pins like in this case. The client driver does not even need to care whether an actual GPIO exists for the current platform.

I could prepare a patch and post it here.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
author
#35 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

Quoted 8 lines · Lothar Waßmann

I have created a 'gpio-switch' driver in my private tree that can be used for exactly this purpose. It takes care of the pin polarity and initial state of the pins and can handle shared pins like in this case. The client driver does not even need to care whether an actual GPIO exists for the current platform.

I could prepare a patch and post it here.

That would be great.

Signature · 2 lines
Regards,
Shawn
#36 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Lothar Waßmann
Quoted 48 lines · Lothar Wa?mann

Hi,

Quoted 37 lines · Dong Aisheng
Quoted 36 lines · Marc Kleine-Budde
Quoted 34 lines · Shawn Guo
Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};
Quoted 8 lines
Quoted 4 lines

Will this work if can0 is down and can1 is up?

Can we abstract the transceiver power as a regulator? Or a clock? :P

Hmm, it may not be a power.
For mx28evk, it's a STBY pin.
So it may hard to abstract it as a regulator or clock.

Quoted 8 lines

I have created a 'gpio-switch' driver in my private tree that can be used for exactly this purpose. It takes care of the pin polarity and initial state of the pins and can handle shared pins like in this case. The client driver does not even need to care whether an actual GPIO exists for the current platform.

I could prepare a patch and post it here.

Would be glad to see your patches.
It may be useful, not only for this case,
we also meet some other issues, i'm not sure but may have similar requirement like SDIO WiFi reset, usb phy reset and etc.

Regards
Dong Aisheng

author
#37 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Dong Aisheng
Quoted 13 lines · Dong Aisheng
Quoted 13 lines
Quoted 12 lines
	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};
Quoted 8 lines
Quoted 4 lines

Will this work if can0 is down and can1 is up?

Can we abstract the transceiver power as a regulator? Or a clock? :P

Hmm, it may not be a power.
For mx28evk, it's a STBY pin.
So it may hard to abstract it as a regulator or clock.

Yes. It also reminds an error in the dts above. phy-standby-gpios should be used instead.

Signature · 2 lines
Regards,
Shawn
#38 lore raw

PATCH v2 2/2 net: flexcan: add transceiver switch gpios support

In reply to Dong Aisheng
Quoted 37 lines · Dong Aisheng
Quoted 36 lines · Marc Kleine-Budde
Quoted 34 lines · Shawn Guo
Quoted 8 lines · Dong Aisheng
Quoted 8 lines
drivers/net/can/flexcan.c +8 -0
+		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,
Quoted 9 lines

drivers/net/can/flexcan.c static int __devinit flexcan_probe(struct platform_device *pdev) · line 1002

Quoted 6 lines
drivers/net/can/flexcan.c +6 -0
+						    "phy-standby");
+			if (err) {
+				dev_err(&pdev->dev,
+					"failed to request gpio %d: %d\n",
+					phy_stby_gpio, err);
+				goto failed_gpio;

I checked mx28 evk, it seems the phy only has a STB gpio and shared by both CAN0&CAN1. I wonder the CAN1 probe may fail here.

It can be managed by dts. Here is what I have in imx28-evk.dts, where only can0 has phy-enable-gpios property.

	can0: can at 80032000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can0_pins_a>;
		phy-enable-gpios = <&gpio2 13 0>;
		status = "okay";
	};

	can1: can at 80034000 {
		pinctrl-names = "default";
		pinctrl-0 = <&can1_pins_a>;
		status = "okay";
	};
Quoted 7 lines
Quoted 4 lines

Will this work if can0 is down and can1 is up?

Can we abstract the transceiver power as a regulator? Or a clock? :P

Hmm, it may not be a power.
For mx28evk, it's a STBY pin.
So it may hard to abstract it as a regulator or clock.

I just talked to Sascha, He pointed out, that there already is regulator that toggles a gpio (only one, not several). I haven't looked at the details, but a regulator should solve the "two CAN ports share the same transceiver/phy" problem.

Marc

Signature · 12 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   |

-------------- 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/20120629/6732d95d/attachment.sig>

A message that is not in the archive (sent off-list or not yet received): [email protected]

#40 lore raw

Re: [PATCH v2 2/2] net: flexcan: add transceiver switch gpios support

adding linux-can on Cc.

Quoted 3 lines · Hui Wang

Hi Shawn,

Any progress on this patch, has it been merged?

No, for several reasons:
- I don't want to have a "toggle transceiver gpio" function open coded in every CAN driver. For now it's just flexcan, but on at91 we need the same functionality.
- The transceiver may be shared by several CAN cores, to sharing must be designed in.
- Lothar Waßmann posted a more generic solution:
http://patchwork.ozlabs.org/patch/168023/

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   |
#41 lore raw

Re: [PATCH v2 2/2] net: flexcan: add transceiver switch gpios support

Quoted 9 lines · Marc Kleine-Budde

adding linux-can on Cc.

Quoted 4 lines · Hui Wang

Hi Shawn,

Any progress on this patch, has it been merged?

Quoted 10 lines

No, for several reasons:
- I don't want to have a "toggle transceiver gpio" function open coded in every CAN driver. For now it's just flexcan, but on at91 we need the same functionality.
- The transceiver may be shared by several CAN cores, to sharing must be designed in.
- Lothar Waßmann posted a more generic solution:
http://patchwork.ozlabs.org/patch/168023/

Glad to know it, thanks.

Hui.

Quoted 3 lines

Marc