Skip to contentSkip to conversation

ARM: imx: flexcan: convert transceiver switching to DT

PATCH New Marc Kleine-Budde 3 participants 6 messages Jun 27, 2013

Subsystems (5)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

cover ARM: imx: flexcan: convert transceiver switching to DT

Hello,

this series converts the flexcan driver from using a callback function (configured via platform data), to switch the transceiver on and off, to a standard regulator. As there are no in-tree users of the platform data, it's finally removed.

If there are no objections I'd like to upstream this via can-next and David Miller's net-next. As these patches are touching arch/arm/mach-imx, I don't want to continue without some Acked-bys.

regards,
Marc

author maintainer
#1 lore raw

PATCH 1/3 ARM: imx: prepare for removal of flexcan_platform_data

As there are no imx in-tree users of flexcan_platform_data, this patch removes the possibility to register a flexcan device with platform data.

The functionality to swith on/off CAN transceivers is added to DT via regulators on a later patch.

Compile time tested with imx_v4_v5_defconfig and imx_v6_v7_defconfig.

---
 arch/arm/mach-imx/devices-imx25.h              | 8 ++++----
 arch/arm/mach-imx/devices-imx35.h              | 8 ++++----
 arch/arm/mach-imx/devices/devices-common.h     | 4 +---
 arch/arm/mach-imx/devices/platform-flexcan.c   | 5 ++---
 arch/arm/mach-imx/eukrea_mbimxsd25-baseboard.c | 2 +-
 arch/arm/mach-imx/eukrea_mbimxsd35-baseboard.c | 2 +-
 arch/arm/mach-imx/mach-mx25_3ds.c              | 2 +-
 arch/arm/mach-imx/mach-pcm043.c                | 2 +-
 8 files changed, 15 insertions(+), 18 deletions(-)
arch/arm/mach-imx/devices-imx25.h +4 -4
index 0d2922b..769563f 100644
@@ -13,10 +13,10 @@ extern const struct imx_fec_data imx25_fec_data;
 	imx_add_fec(&imx25_fec_data, pdata)
 
 extern const struct imx_flexcan_data imx25_flexcan_data[];
-#define imx25_add_flexcan(id, pdata)	\
-	imx_add_flexcan(&imx25_flexcan_data[id], pdata)
-#define imx25_add_flexcan0(pdata)	imx25_add_flexcan(0, pdata)
-#define imx25_add_flexcan1(pdata)	imx25_add_flexcan(1, pdata)
+#define imx25_add_flexcan(id)	\
+	imx_add_flexcan(&imx25_flexcan_data[id])
+#define imx25_add_flexcan0()		imx25_add_flexcan(0)
+#define imx25_add_flexcan1()		imx25_add_flexcan(1)
 
 extern const struct imx_fsl_usb2_udc_data imx25_fsl_usb2_udc_data;
 #define imx25_add_fsl_usb2_udc(pdata)	\
arch/arm/mach-imx/devices-imx35.h +4 -4
index e2675f1..780d824 100644
@@ -17,10 +17,10 @@ extern const struct imx_fsl_usb2_udc_data imx35_fsl_usb2_udc_data;
 	imx_add_fsl_usb2_udc(&imx35_fsl_usb2_udc_data, pdata)
 
 extern const struct imx_flexcan_data imx35_flexcan_data[];
-#define imx35_add_flexcan(id, pdata)	\
-	imx_add_flexcan(&imx35_flexcan_data[id], pdata)
-#define imx35_add_flexcan0(pdata)	imx35_add_flexcan(0, pdata)
-#define imx35_add_flexcan1(pdata)	imx35_add_flexcan(1, pdata)
+#define imx35_add_flexcan(id)	\
+	imx_add_flexcan(&imx35_flexcan_data[id])
+#define imx35_add_flexcan0()		imx35_add_flexcan(0)
+#define imx35_add_flexcan1()		imx35_add_flexcan(1)
 
 extern const struct imx_imx2_wdt_data imx35_imx2_wdt_data;
 #define imx35_add_imx2_wdt()       \
arch/arm/mach-imx/devices/devices-common.h +1 -3
index 453e20b..c13b76b 100644
@@ -50,7 +50,6 @@ struct platform_device *__init imx_add_fec(
 		const struct imx_fec_data *data,
 		const struct fec_platform_data *pdata);
 
-#include <linux/can/platform/flexcan.h>
 struct imx_flexcan_data {
 	int id;
 	resource_size_t iobase;
@@ -58,8 +57,7 @@ struct imx_flexcan_data {
 	resource_size_t irq;
 };
 struct platform_device *__init imx_add_flexcan(
-		const struct imx_flexcan_data *data,
-		const struct flexcan_platform_data *pdata);
+		const struct imx_flexcan_data *data);
 
 #include <linux/fsl_devices.h>
 struct imx_fsl_usb2_udc_data {
arch/arm/mach-imx/devices/platform-flexcan.c +2 -3
index 1078bf0..55d61ea 100644
@@ -38,8 +38,7 @@ const struct imx_flexcan_data imx35_flexcan_data[] __initconst = {
 #endif /* ifdef CONFIG_SOC_IMX35 */
 
 struct platform_device *__init imx_add_flexcan(
-		const struct imx_flexcan_data *data,
-		const struct flexcan_platform_data *pdata)
+		const struct imx_flexcan_data *data)
 {
 	struct resource res[] = {
 		{
@@ -54,5 +53,5 @@ struct platform_device *__init imx_add_flexcan(
 	};
 
 	return imx_add_platform_device("flexcan", data->id,
-			res, ARRAY_SIZE(res), pdata, sizeof(*pdata));
+			res, ARRAY_SIZE(res), NULL, 0);
 }
arch/arm/mach-imx/eukrea_mbimxsd25-baseboard.c +1 -1
index e2b70f4c..e77cc3a 100644
@@ -279,7 +279,7 @@ void __init eukrea_mbimxsd25_baseboard_init(void)
 	imx25_add_imx_fb(&eukrea_mximxsd_fb_pdata);
 	imx25_add_imx_ssi(0, &eukrea_mbimxsd_ssi_pdata);
 
-	imx25_add_flexcan1(NULL);
+	imx25_add_flexcan1();
 	imx25_add_sdhci_esdhc_imx(0, &sd1_pdata);
 
 	gpio_request(GPIO_LED1, "LED1");
arch/arm/mach-imx/eukrea_mbimxsd35-baseboard.c +1 -1
index 5a2d5ef..14d6c82 100644
@@ -287,7 +287,7 @@ void __init eukrea_mbimxsd35_baseboard_init(void)
 
 	imx35_add_imx_ssi(0, &eukrea_mbimxsd_ssi_pdata);
 
-	imx35_add_flexcan1(NULL);
+	imx35_add_flexcan1();
 	imx35_add_sdhci_esdhc_imx(0, &sd1_pdata);
 
 	gpio_request(GPIO_LED1, "LED1");
arch/arm/mach-imx/mach-mx25_3ds.c +1 -1
index 8bcda68..13490c2 100644
@@ -249,7 +249,7 @@ static void __init mx25pdk_init(void)
 	imx25_add_imx_i2c0(&mx25_3ds_i2c0_data);
 
 	gpio_request_one(MX25PDK_CAN_PWDN, GPIOF_OUT_INIT_LOW, "can-pwdn");
-	imx25_add_flexcan0(NULL);
+	imx25_add_flexcan0();
 }
 
 static void __init mx25pdk_timer_init(void)
arch/arm/mach-imx/mach-pcm043.c +1 -1
index 8ed533f..b726cb1 100644
@@ -385,7 +385,7 @@ static void __init pcm043_init(void)
 	if (!otg_mode_host)
 		imx35_add_fsl_usb2_udc(&otg_device_pdata);
 
-	imx35_add_flexcan1(NULL);
+	imx35_add_flexcan1();
 	imx35_add_sdhci_esdhc_imx(0, &sd1_pdata);
 }
 
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw

PATCH 1/3 ARM: imx: prepare for removal of flexcan_platform_data

Quoted 10 lines · Marc Kleine-Budde

As there are no imx in-tree users of flexcan_platform_data, this patch removes the possibility to register a flexcan device with platform data.

The functionality to swith on/off CAN transceivers is added to DT via regulators on a later patch.

Compile time tested with imx_v4_v5_defconfig and imx_v6_v7_defconfig.

Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>

I like to see platform stuff go away ;)

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author maintainer
#3 lore raw

PATCH 2/3 can: flexcan: Use a regulator to control the CAN transceiver

In reply to Marc Kleine-Budde

From: Fabio Estevam <[email protected]>

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

---
 .../devicetree/bindings/net/can/fsl-flexcan.txt    |  2 +
 arch/arm/boot/dts/imx28-evk.dts                    | 12 ++++++
 arch/arm/mach-mxs/mach-mxs.c                       | 50 +---------------------
 drivers/net/can/flexcan.c                          | 25 +++++------
 4 files changed, 28 insertions(+), 61 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +2 -0
index 8ff324e..56d6cc3 100644
@@ -16,6 +16,8 @@ Optional properties:
 
 - clock-frequency : The oscillator frequency driving the flexcan device
 
+- xceiver-supply: Regulator that powers the CAN transceiver
+
 Example:
 
 	can at 1c000 {
arch/arm/boot/dts/imx28-evk.dts +12 -0
index 3637bf3..1f0d38d 100644
@@ -155,12 +155,14 @@
 			can0: can at 80032000 {
 				pinctrl-names = "default";
 				pinctrl-0 = <&can0_pins_a>;
+				xceiver-supply = <&reg_can_3v3>;
 				status = "okay";
 			};
 
 			can1: can at 80034000 {
 				pinctrl-names = "default";
 				pinctrl-0 = <&can1_pins_a>;
+				xceiver-supply = <&reg_can_3v3>;
 				status = "okay";
 			};
 		};
@@ -319,6 +321,16 @@
 			gpio = <&gpio3 30 0>;
 			enable-active-high;
 		};
+
+		reg_can_3v3: can-3v3 {
+			compatible = "regulator-fixed";
+			regulator-name = "can-3v3";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+			gpio = <&gpio2 13 0>;
+			enable-active-high;
+		};
+
 	};
 
 	sound {
arch/arm/mach-mxs/mach-mxs.c +1 -49

77 lines not on this page · raw message

drivers/net/can/flexcan.c +13 -12
index f873b9f..7b0be09 100644
@@ -24,7 +24,6 @@
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
 #include <linux/can/led.h>
-#include <linux/can/platform/flexcan.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/if_arp.h>
@@ -37,6 +36,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 
 #define DRV_NAME			"flexcan"
 
@@ -211,6 +211,7 @@ struct flexcan_priv {
 	struct clk *clk_per;
 	struct flexcan_platform_data *pdata;
 	const struct flexcan_devtype_data *devtype_data;
+	struct regulator *reg_xceiver;
 };
 
 static struct flexcan_devtype_data fsl_p1010_devtype_data = {
@@ -258,15 +259,6 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
 }
 #endif
 
-/*
- * Swtich transceiver on or off
- */
-static void flexcan_transceiver_switch(const struct flexcan_priv *priv, int on)
-{
-	if (priv->pdata && priv->pdata->transceiver_switch)
-		priv->pdata->transceiver_switch(on);
-}
-
 static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
 					      u32 reg_esr)
 {
@@ -799,7 +791,11 @@ static int flexcan_chip_start(struct net_device *dev)
 	if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES)
 		flexcan_write(0x0, &regs->rxfgmask);
 
-	flexcan_transceiver_switch(priv, 1);
+	if (priv->reg_xceiver)	{
+		err = regulator_enable(priv->reg_xceiver);
+		if (err)
+			goto out;
+	}
 
 	/* synchronize with the can bus */
 	reg_mcr = flexcan_read(&regs->mcr);
@@ -842,7 +838,8 @@ static void flexcan_chip_stop(struct net_device *dev)
 	reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
 	flexcan_write(reg, &regs->mcr);
 
-	flexcan_transceiver_switch(priv, 0);
+	if (priv->reg_xceiver)
+		regulator_disable(priv->reg_xceiver);
 	priv->can.state = CAN_STATE_STOPPED;
 
 	return;
@@ -1084,6 +1081,10 @@ static int flexcan_probe(struct platform_device *pdev)
 	priv->pdata = pdev->dev.platform_data;
 	priv->devtype_data = devtype_data;
 
+	priv->reg_xceiver = devm_regulator_get(&pdev->dev, "xceiver");
+	if (IS_ERR(priv->reg_xceiver))
+		priv->reg_xceiver = NULL;
+
 	netif_napi_add(dev, &priv->napi, flexcan_poll, FLEXCAN_NAPI_WEIGHT);
 
 	dev_set_drvdata(&pdev->dev, dev);
Signature · 1 line
1.8.3.1
author maintainer
#4 lore raw

PATCH 3/3 ARM: imx: flexcan: Remove platform file

In reply to Marc Kleine-Budde

From: Fabio Estevam <[email protected]>

As there are no more users of the flexcan platform file, let's remove it.

---
 include/linux/can/platform/flexcan.h | 20 --------------------
 1 file changed, 20 deletions(-)
 delete mode 100644 include/linux/can/platform/flexcan.h
include/linux/can/platform/flexcan.h deleted +0 -20
deleted file mode 100644
index 72b713a..0000000
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2010 Marc Kleine-Budde <[email protected]>
- *
- * This file is released under the GPLv2
- *
- */
-
-#ifndef __CAN_PLATFORM_FLEXCAN_H
-#define __CAN_PLATFORM_FLEXCAN_H
-
-/**
- * struct flexcan_platform_data - flex CAN controller platform data
- * @transceiver_enable:         - called to power on/off the transceiver
- *
- */
-struct flexcan_platform_data {
-	void (*transceiver_switch)(int enable);
-};
-
-#endif /* __CAN_PLATFORM_FLEXCAN_H */
Signature · 1 line
1.8.3.1
#5 lore raw

cover ARM: imx: flexcan: convert transceiver switching to DT

In reply to Marc Kleine-Budde
Quoted 10 lines · Marc Kleine-Budde

Hello,

this series converts the flexcan driver from using a callback function (configured via platform data), to switch the transceiver on and off, to a standard regulator. As there are no in-tree users of the platform data, it's finally removed.

If there are no objections I'd like to upstream this via can-next and David Miller's net-next. As these patches are touching arch/arm/mach-imx, I don't want to continue without some Acked-bys.

For the series,