Skip to contentSkip to conversation

W1: Support onewire master on i.MX53

PATCH Superseded Martin Fuzzey 4 participants 10 messages Jan 16, 2013 – Jan 22, 2013

Subsystems (7)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover W1: Support onewire master on i.MX53

W1: Support onewire master on i.MX53
* Add device tree and pinctrl support to the MXC master driver
* Convert to use devm_
* Add i.MX53 clocks
* Add i.MX53 device tree entries

Changes since V1
* Applied comments from Sascha Hauer:
* Move patch converting driver to devm_ before the one adding devm_ based pinctrl
* Fix existing unbalanced clk_prepare_enable/clk_disable_unprepare in probe error path

* Place DT patch last since it includes pinctrls for driver.

#1 lore raw

PATCH v2 1/5 W1: Add device tree support to MXC onewire master.

---
 drivers/w1/masters/mxc_w1.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
drivers/w1/masters/mxc_w1.c +8 -1
index 708a25f..949e566 100644
@@ -186,9 +186,16 @@ static int mxc_w1_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static struct of_device_id mxc_w1_dt_ids[] = {
+	{ .compatible = "fsl,imx21-owire" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mxc_w1_dt_ids);
+
 static struct platform_driver mxc_w1_driver = {
 	.driver = {
-		   .name = "mxc_w1",
+		.name = "mxc_w1",
+		.of_match_table = mxc_w1_dt_ids,
 	},
 	.probe = mxc_w1_probe,
 	.remove = mxc_w1_remove,
#2 lore raw

PATCH v2 2/5 ARM: i.MX53: Add clocks for i.mx53 onewire master.

In reply to Martin Fuzzey
---
 .../devicetree/bindings/clock/imx5-clock.txt       |    1 +
 arch/arm/mach-imx/clk-imx51-imx53.c                |    4 +++-
 2 files changed, 4 insertions(+), 1 deletions(-)
Documentation/devicetree/bindings/clock/imx5-clock.txt +1 -0
index 04ad478..2a0c904 100644
@@ -171,6 +171,7 @@ clocks and IDs.
 	can_sel			156
 	can1_serial_gate	157
 	can1_ipg_gate		158
+	owire_gate		159
 
 Examples (for mx53):
 
arch/arm/mach-imx/clk-imx51-imx53.c +3 -1
index 579023f..7ff293b 100644
@@ -83,6 +83,7 @@ enum imx5_clks {
 	ssi2_root_gate, ssi3_root_gate, ssi_ext1_gate, ssi_ext2_gate,
 	epit1_ipg_gate, epit1_hf_gate, epit2_ipg_gate, epit2_hf_gate,
 	can_sel, can1_serial_gate, can1_ipg_gate,
+	owire_gate,
 	clk_max
 };
 
@@ -233,12 +234,13 @@ static void __init mx5_clocks_common_init(unsigned long rate_ckil,
 	clk[epit1_hf_gate] = imx_clk_gate2("epit1_hf_gate", "per_root", MXC_CCM_CCGR2, 4);
 	clk[epit2_ipg_gate] = imx_clk_gate2("epit2_ipg_gate", "ipg", MXC_CCM_CCGR2, 6);
 	clk[epit2_hf_gate] = imx_clk_gate2("epit2_hf_gate", "per_root", MXC_CCM_CCGR2, 8);
+	clk[owire_gate] = imx_clk_gate2("owire_gate", "per_root", MXC_CCM_CCGR2, 22);
 
 	for (i = 0; i < ARRAY_SIZE(clk); i++)
 		if (IS_ERR(clk[i]))
 			pr_err("i.MX5 clk %d: register failed with %ld\n",
 				i, PTR_ERR(clk[i]));
-	
+
 	clk_register_clkdev(clk[gpt_hf_gate], "per", "imx-gpt.0");
 	clk_register_clkdev(clk[gpt_ipg_gate], "ipg", "imx-gpt.0");
 	clk_register_clkdev(clk[uart1_per_gate], "per", "imx21-uart.0");
#3 lore raw

PATCH v2 3/5 W1: Convert MXC onewire master to devm_ functions.

In reply to Martin Fuzzey

While doing this fix missing clk_disable_unprepare in error path.

---
 drivers/w1/masters/mxc_w1.c |   26 ++++++--------------------
 1 files changed, 6 insertions(+), 20 deletions(-)
drivers/w1/masters/mxc_w1.c +6 -20
index 949e566..317b2bc 100644
@@ -117,7 +117,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (!mdev)
 		return -ENOMEM;
 
-	mdev->clk = clk_get(&pdev->dev, NULL);
+	mdev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(mdev->clk)) {
 		err = PTR_ERR(mdev->clk);
 		goto failed_clk;
@@ -125,17 +125,11 @@ static int mxc_w1_probe(struct platform_device *pdev)
 
 	mdev->clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1;
 
-	res = request_mem_region(res->start, resource_size(res),
-				"mxc_w1");
-	if (!res) {
-		err = -EBUSY;
-		goto failed_req;
-	}
-
-	mdev->regs = ioremap(res->start, resource_size(res));
+	mdev->regs = devm_request_and_ioremap(&pdev->dev, res);
 	if (!mdev->regs) {
 		dev_err(&pdev->dev, "Cannot map mxc_w1 registers\n");
-		goto failed_ioremap;
+		err = -ENXIO;
+		goto failed_req;
 	}
 
 	clk_prepare_enable(mdev->clk);
@@ -154,11 +148,9 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	return 0;
 
 failed_add:
-	iounmap(mdev->regs);
-failed_ioremap:
-	release_mem_region(res->start, resource_size(res));
+	clk_disable_unprepare(mdev->clk);
+
 failed_req:
-	clk_put(mdev->clk);
 failed_clk:
 	kfree(mdev);
 	return err;
@@ -170,16 +162,10 @@ failed_clk:
 static int mxc_w1_remove(struct platform_device *pdev)
 {
 	struct mxc_w1_device *mdev = platform_get_drvdata(pdev);
-	struct resource *res;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
 	w1_remove_master_device(&mdev->bus_master);
 
-	iounmap(mdev->regs);
-	release_mem_region(res->start, resource_size(res));
 	clk_disable_unprepare(mdev->clk);
-	clk_put(mdev->clk);
 
 	platform_set_drvdata(pdev, NULL);
 
#4 lore raw

PATCH v2 4/5 W1: Add pinctrl support to MXC onewire master.

In reply to Martin Fuzzey
---
 drivers/w1/masters/mxc_w1.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/w1/masters/mxc_w1.c +10 -0
index 317b2bc..48afc2c 100644
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/pinctrl/consumer.h>
 
 #include "../w1.h"
 #include "../w1_int.h"
@@ -107,6 +108,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 {
 	struct mxc_w1_device *mdev;
 	struct resource *res;
+	struct pinctrl *pinctrl;
 	int err = 0;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -117,6 +119,13 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (!mdev)
 		return -ENOMEM;
 
+	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+	if (IS_ERR(pinctrl)) {
+		err = PTR_ERR(pinctrl);
+		dev_err(&pdev->dev, "failed to get default pinctrl: %d\n", err);
+		goto failed_pin;
+	}
+
 	mdev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(mdev->clk)) {
 		err = PTR_ERR(mdev->clk);
@@ -152,6 +161,7 @@ failed_add:
 
 failed_req:
 failed_clk:
+failed_pin:
 	kfree(mdev);
 	return err;
 }
#5 lore raw

PATCH v2 5/5 DTS: Add device tree entry for onewire master on i.MX53

In reply to Martin Fuzzey
---
 arch/arm/boot/dts/imx53.dtsi |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
arch/arm/boot/dts/imx53.dtsi +15 -0
index edc3f1e..00c957c 100644
@@ -387,6 +387,14 @@
 					};
 				};
 
+				owire {
+					pinctrl_owire_1: owiregrp-1 {
+						fsl,pins = <
+								1166 0x80000000 /* MX53_PAD_GPIO_18__OWIRE_LINE */
+						>;
+					};
+				};
+
 				uart1 {
 					pinctrl_uart1_1: uart1grp-1 {
 						fsl,pins = <
@@ -570,6 +578,13 @@
 				status = "disabled";
 			};
 
+			owire: owire@63fa4000 {
+				compatible = "fsl,imx53-owire", "fsl,imx21-owire";
+				reg = <0x63fa4000 0x4000>;
+				clocks = <&clks 159>;
+				status = "disabled";
+			};
+
 			ecspi2: ecspi at 63fac000 {
 				#address-cells = <1>;
 				#size-cells = <0>;
maintainer
#6 lore raw

v2 cover W1: Support onewire master on i.MX53

In reply to Martin Fuzzey
Quoted 6 lines · Martin Fuzzey

W1: Support onewire master on i.MX53
* Add device tree and pinctrl support to the MXC master driver
* Convert to use devm_
* Add i.MX53 clocks
* Add i.MX53 device tree entries

Quoted 7 lines

Changes since V1
* Applied comments from Sascha Hauer:
* Move patch converting driver to devm_ before the one adding devm_ based pinctrl
* Fix existing unbalanced clk_prepare_enable/clk_disable_unprepare in probe error path

* Place DT patch last since it includes pinctrls for driver.

This looks good now.

You might have to send this again in two series, one for the w1 maintainer and one for arm-soc. Both series should be sufficiently orthogonal.

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

v2 cover W1: Support onewire master on i.MX53

Quoted 15 lines · Sascha Hauer
Quoted 6 lines · Martin Fuzzey

W1: Support onewire master on i.MX53
* Add device tree and pinctrl support to the MXC master driver
* Convert to use devm_
* Add i.MX53 clocks
* Add i.MX53 device tree entries

Quoted 7 lines

Changes since V1
* Applied comments from Sascha Hauer:
* Move patch converting driver to devm_ before the one adding devm_ based pinctrl
* Fix existing unbalanced clk_prepare_enable/clk_disable_unprepare in probe error path

* Place DT patch last since it includes pinctrls for driver.

Quoted 8 lines

This looks good now.

You might have to send this again in two series, one for the w1 maintainer and one for arm-soc. Both series should be sufficiently orthogonal.

Evgeniy has already ACK-ed the v1 series, so maybe he does not see any problem with the whole series going through one tree. In that case, we may just have it go via arm-soc tree? Otherwise, please let us know, Evgeniy.

Shawn

#8 lore raw

v2 cover W1: Support onewire master on i.MX53

Quoted 23 lines · Shawn Guo
Quoted 13 lines · Sascha Hauer
Quoted 12 lines · Martin Fuzzey

W1: Support onewire master on i.MX53
* Add device tree and pinctrl support to the MXC master driver
* Convert to use devm_
* Add i.MX53 clocks
* Add i.MX53 device tree entries

Changes since V1
* Applied comments from Sascha Hauer:
* Move patch converting driver to devm_ before the one adding devm_ based pinctrl
* Fix existing unbalanced clk_prepare_enable/clk_disable_unprepare in probe error path

Quoted 9 lines
Quoted 1 line

* Place DT patch last since it includes pinctrls for driver.

This looks good now.

You might have to send this again in two series, one for the w1 maintainer and one for arm-soc. Both series should be sufficiently orthogonal.

Quoted 7 lines

Evgeniy has already ACK-ed the v1 series, so maybe he does not see any problem with the whole series going through one tree. In that case, we may just have it go via arm-soc tree? Otherwise, please let us know, Evgeniy.

Shawn

There was also the question raised by Mark Rutland on the DT compatible string.
Currently this is "fsl,imx21-owire" but Mark thought "fsl,imx21-w1" to be better.

Do I take your Acks to mean "fsl,imx21-owire" is OK?
I should add a Documentation file for the DT binding too but I was waiting for consensus
on the compatible string first.

Martin

#9 lore raw

v2 cover W1: Support onewire master on i.MX53

Quoted 29 lines · Martin Fuzzey
Quoted 28 lines · Shawn Guo
Quoted 13 lines · Sascha Hauer
Quoted 12 lines · Martin Fuzzey

W1: Support onewire master on i.MX53
* Add device tree and pinctrl support to the MXC master driver
* Convert to use devm_
* Add i.MX53 clocks
* Add i.MX53 device tree entries

Changes since V1
* Applied comments from Sascha Hauer:
* Move patch converting driver to devm_ before the one adding devm_ based pinctrl
* Fix existing unbalanced clk_prepare_enable/clk_disable_unprepare in probe error path

Quoted 9 lines
Quoted 1 line

* Place DT patch last since it includes pinctrls for driver.

This looks good now.

You might have to send this again in two series, one for the w1 maintainer and one for arm-soc. Both series should be sufficiently orthogonal.

Evgeniy has already ACK-ed the v1 series, so maybe he does not see any problem with the whole series going through one tree. In that case, we may just have it go via arm-soc tree? Otherwise, please let us know, Evgeniy.

Quoted 6 lines
Quoted 2 lines

Shawn

There was also the question raised by Mark Rutland on the DT compatible string.
Currently this is "fsl,imx21-owire" but Mark thought "fsl,imx21-w1" to be better.

Your reasoning that "fsl,imx21-owire" better matched the hardware name is convincing -- bindings don't have to match the Linux view of things. I'm happy either way, as long as the binding is documented.

Apologies for any inconvenience I've caused.

Quoted 8 lines

Do I take your Acks to mean "fsl,imx21-owire" is OK?
I should add a Documentation file for the DT binding too but I was waiting for consensus
on the compatible string first.

Martin

Thanks,
Mark.