Skip to contentSkip to conversation

Add device tree probe for i2c-imx driver

PATCH Superseded Shawn Guo 5 participants 7 messages Sep 8, 2011 – Sep 9, 2011

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

v2 cover Add device tree probe for i2c-imx driver

Hi Ben,

This is a repost of the patch set below, which has been waiting for your pickup for 6 weeks.

http://thread.gmane.org/gmane.linux.drivers.i2c/8850/

Regards,
Shawn

[PATCH REPOST 1/2] i2c-imx: remove init/exit hooks from platform data [PATCH REPOST 2/2] i2c-imx: add device tree probe support

author
#1 lore raw

PATCH v2 1/2 i2c-imx: remove init/exit hooks from platform data

The init/exit hooks in platform data are being used nowhere, so can be removed.

---
 arch/arm/plat-mxc/include/mach/i2c.h |    4 ----
 drivers/i2c/busses/i2c-imx.c         |   21 +++------------------
 2 files changed, 3 insertions(+), 22 deletions(-)
arch/arm/plat-mxc/include/mach/i2c.h +0 -4
index 4a5dc5c..375cdd0 100644
@@ -11,14 +11,10 @@
 
 /**
  * struct imxi2c_platform_data - structure of platform data for MXC I2C driver
- * @init:	Initialise gpio's and other board specific things
- * @exit:	Free everything initialised by @init
  * @bitrate:	Bus speed measured in Hz
  *
  **/
 struct imxi2c_platform_data {
-	int (*init)(struct device *dev);
-	void (*exit)(struct device *dev);
 	int bitrate;
 };
 
drivers/i2c/busses/i2c-imx.c +3 -18
index 4c2a62b..54d809e 100644
@@ -466,7 +466,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 {
 	struct imx_i2c_struct *i2c_imx;
 	struct resource *res;
-	struct imxi2c_platform_data *pdata;
+	struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
 	void __iomem *base;
 	resource_size_t res_size;
 	int irq;
@@ -485,19 +485,11 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
-	pdata = pdev->dev.platform_data;
-
-	if (pdata && pdata->init) {
-		ret = pdata->init(&pdev->dev);
-		if (ret)
-			return ret;
-	}
-
 	res_size = resource_size(res);
 
 	if (!request_mem_region(res->start, res_size, DRIVER_NAME)) {
-		ret = -EBUSY;
-		goto fail0;
+		dev_err(&pdev->dev, "request_mem_region failed\n");
+		return -EBUSY;
 	}
 
 	base = ioremap(res->start, res_size);
@@ -586,9 +578,6 @@ fail2:
 	iounmap(base);
 fail1:
 	release_mem_region(res->start, resource_size(res));
-fail0:
-	if (pdata && pdata->exit)
-		pdata->exit(&pdev->dev);
 	return ret; /* Return error number */
 }
 
@@ -611,10 +600,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
 	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 
-	/* Shut down hardware */
-	if (pdata && pdata->exit)
-		pdata->exit(&pdev->dev);
-
 	clk_put(i2c_imx->clk);
 
 	iounmap(i2c_imx->base);
Signature · 1 line
1.7.4.1
author
#2 lore raw

PATCH v2 2/2 i2c-imx: add device tree probe support

In reply to Shawn Guo

It adds device tree probe support for i2c-imx driver.

---
 .../devicetree/bindings/i2c/fsl-imx-i2c.txt        |   25 ++++++++++++++++++++
 drivers/i2c/busses/i2c-imx.c                       |   25 +++++++++++++++----
 2 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file +25 -0
new file mode 100644
index 0000000..f3cf43b
@@ -0,0 +1,25 @@
+* Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX
+
+Required properties:
+- compatible : Should be "fsl,<chip>-i2c"
+- reg : Should contain I2C/HS-I2C registers location and length
+- interrupts : Should contain I2C/HS-I2C interrupt
+
+Optional properties:
+- clock-frequency : Constains desired I2C/HS-I2C bus clock frequency in Hz.
+  The absence of the propoerty indicates the default frequency 100 kHz.
+
+Examples:
+
+i2c at 83fc4000 { /* I2C2 on i.MX51 */
+	compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
+	reg = <0x83fc4000 0x4000>;
+	interrupts = <63>;
+};
+
+i2c at 70038000 { /* HS-I2C on i.MX51 */
+	compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
+	reg = <0x70038000 0x4000>;
+	interrupts = <64>;
+	clock-frequency = <400000>;
+};
drivers/i2c/busses/i2c-imx.c +19 -6
index 54d809e..58832e5 100644
@@ -48,6 +48,9 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_i2c.h>
 
 #include <mach/irqs.h>
 #include <mach/hardware.h>
@@ -125,6 +128,11 @@ struct imx_i2c_struct {
 	unsigned int		ifdr; /* IMX_I2C_IFDR */
 };
 
+static const struct of_device_id i2c_imx_dt_ids[] = {
+	{ .compatible = "fsl,imx1-i2c", },
+	{ /* sentinel */ }
+};
+
 /** Functions for IMX I2C adapter driver ***************************************
 *******************************************************************************/
 
@@ -469,7 +477,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 	struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
 	void __iomem *base;
 	resource_size_t res_size;
-	int irq;
+	int irq, bitrate;
 	int ret;
 
 	dev_dbg(&pdev->dev, "<%s>\n", __func__);
@@ -512,6 +520,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 	i2c_imx->adapter.algo		= &i2c_imx_algo;
 	i2c_imx->adapter.dev.parent	= &pdev->dev;
 	i2c_imx->adapter.nr 		= pdev->id;
+	i2c_imx->adapter.dev.of_node	= pdev->dev.of_node;
 	i2c_imx->irq			= irq;
 	i2c_imx->base			= base;
 	i2c_imx->res			= res;
@@ -538,10 +547,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 	i2c_set_adapdata(&i2c_imx->adapter, i2c_imx);
 
 	/* Set up clock divider */
-	if (pdata && pdata->bitrate)
-		i2c_imx_set_clk(i2c_imx, pdata->bitrate);
-	else
-		i2c_imx_set_clk(i2c_imx, IMX_I2C_BIT_RATE);
+	bitrate = IMX_I2C_BIT_RATE;
+	ret = of_property_read_u32(pdev->dev.of_node,
+				   "clock-frequency", &bitrate);
+	if (ret < 0 && pdata && pdata->bitrate)
+		bitrate = pdata->bitrate;
+	i2c_imx_set_clk(i2c_imx, bitrate);
 
 	/* Set up chip registers to defaults */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
@@ -554,6 +565,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 		goto fail5;
 	}
 
+	of_i2c_register_devices(&i2c_imx->adapter);
+
 	/* Set up platform driver data */
 	platform_set_drvdata(pdev, i2c_imx);
 
@@ -584,7 +597,6 @@ fail1:
 static int __exit i2c_imx_remove(struct platform_device *pdev)
 {
 	struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
-	struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
 
 	/* remove adapter */
 	dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n");
@@ -613,6 +625,7 @@ static struct platform_driver i2c_imx_driver = {
 	.driver	= {
 		.name	= DRIVER_NAME,
 		.owner	= THIS_MODULE,
+		.of_match_table = i2c_imx_dt_ids,
 	}
 };
 
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 2/2 i2c-imx: add device tree probe support

Shawn,

Quoted 29 lines · Shawn Guo

It adds device tree probe support for i2c-imx driver.

---
 .../devicetree/bindings/i2c/fsl-imx-i2c.txt        |   25 ++++++++++++++++++++
 drivers/i2c/busses/i2c-imx.c                       |   25 +++++++++++++++----
 2 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file +10 -0
new file mode 100644
index 0000000..f3cf43b
@@ -0,0 +1,25 @@
+* Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX
+
+Required properties:
+- compatible : Should be "fsl,<chip>-i2c"
+- reg : Should contain I2C/HS-I2C registers location and length
+- interrupts : Should contain I2C/HS-I2C interrupt
+
+Optional properties:
+- clock-frequency : Constains desired I2C/HS-I2C bus clock frequency in Hz.
+  The absence of the propoerty indicates the default frequency 100 kHz.

Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt line 20

Quoted 10 lines
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file +10 -0
+
+Examples:
+
+i2c at 83fc4000 { /* I2C2 on i.MX51 */
+	compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
+	reg = <0x83fc4000 0x4000>;
+	interrupts = <63>;
+};
+
+i2c at 70038000 { /* HS-I2C on i.MX51 */

The mainline driver doesn't support the HS-I2C block does it?

The high speed and "old" i2c blocks on MX51 are basically different blocks, so the compatible property should be different.

Rob

Quoted 90 lines
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file +5 -0
+	compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
+	reg = <0x70038000 0x4000>;
+	interrupts = <64>;
+	clock-frequency = <400000>;
+};
drivers/i2c/busses/i2c-imx.c +19 -6
index 54d809e..58832e5 100644
@@ -48,6 +48,9 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_i2c.h>
 
 #include <mach/irqs.h>
 #include <mach/hardware.h>
@@ -125,6 +128,11 @@ struct imx_i2c_struct {
 	unsigned int		ifdr; /* IMX_I2C_IFDR */
 };
 
+static const struct of_device_id i2c_imx_dt_ids[] = {
+	{ .compatible = "fsl,imx1-i2c", },
+	{ /* sentinel */ }
+};
+
 /** Functions for IMX I2C adapter driver ***************************************
 *******************************************************************************/
 
@@ -469,7 +477,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 	struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
 	void __iomem *base;
 	resource_size_t res_size;
-	int irq;
+	int irq, bitrate;
 	int ret;
 
 	dev_dbg(&pdev->dev, "<%s>\n", __func__);
@@ -512,6 +520,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 	i2c_imx->adapter.algo		= &i2c_imx_algo;
 	i2c_imx->adapter.dev.parent	= &pdev->dev;
 	i2c_imx->adapter.nr 		= pdev->id;
+	i2c_imx->adapter.dev.of_node	= pdev->dev.of_node;
 	i2c_imx->irq			= irq;
 	i2c_imx->base			= base;
 	i2c_imx->res			= res;
@@ -538,10 +547,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 	i2c_set_adapdata(&i2c_imx->adapter, i2c_imx);
 
 	/* Set up clock divider */
-	if (pdata && pdata->bitrate)
-		i2c_imx_set_clk(i2c_imx, pdata->bitrate);
-	else
-		i2c_imx_set_clk(i2c_imx, IMX_I2C_BIT_RATE);
+	bitrate = IMX_I2C_BIT_RATE;
+	ret = of_property_read_u32(pdev->dev.of_node,
+				   "clock-frequency", &bitrate);
+	if (ret < 0 && pdata && pdata->bitrate)
+		bitrate = pdata->bitrate;
+	i2c_imx_set_clk(i2c_imx, bitrate);
 
 	/* Set up chip registers to defaults */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
@@ -554,6 +565,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 		goto fail5;
 	}
 
+	of_i2c_register_devices(&i2c_imx->adapter);
+
 	/* Set up platform driver data */
 	platform_set_drvdata(pdev, i2c_imx);
 
@@ -584,7 +597,6 @@ fail1:
 static int __exit i2c_imx_remove(struct platform_device *pdev)
 {
 	struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
-	struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
 
 	/* remove adapter */
 	dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n");
@@ -613,6 +625,7 @@ static struct platform_driver i2c_imx_driver = {
 	.driver	= {
 		.name	= DRIVER_NAME,
 		.owner	= THIS_MODULE,
+		.of_match_table = i2c_imx_dt_ids,
 	}
 };
 
#4 lore raw

PATCH 2/2 i2c-imx: add device tree probe support

Hello Rob,

Quoted 10 lines · Rob Herring

Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt line 20

Quoted 7 lines
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file +7 -0
+i2c at 83fc4000 { /* I2C2 on i.MX51 */
+	compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
+	reg = <0x83fc4000 0x4000>;
+	interrupts = <63>;
+};
+
+i2c at 70038000 { /* HS-I2C on i.MX51 */

The mainline driver doesn't support the HS-I2C block does it?

Quoted 2 lines

The high speed and "old" i2c blocks on MX51 are basically different blocks, so the compatible property should be different.

I stumbled about that recently, too and found in arch/arm/plat-mxc/devices/platform-imx-i2c.c that the third device description for imx51 is a normal "imx-i2c" one using MX51_HSI2C_DMA_BASE_ADDR. So I concluded it's different but compatible.

board-mx51_babbage.c uses imx51_add_hsi2c but doesn't add a bus description. So It might not attract attention if the driver doesn't match the device.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#5 lore raw

PATCH 2/2 i2c-imx: add device tree probe support

Quoted 15 lines · Uwe Kleine-K?nig

Hello Rob,

Quoted 10 lines · Rob Herring

Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt line 20

Quoted 7 lines
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file +7 -0
+i2c at 83fc4000 { /* I2C2 on i.MX51 */
+	compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
+	reg = <0x83fc4000 0x4000>;
+	interrupts = <63>;
+};
+
+i2c at 70038000 { /* HS-I2C on i.MX51 */

The mainline driver doesn't support the HS-I2C block does it?

Quoted 2 lines

The high speed and "old" i2c blocks on MX51 are basically different blocks, so the compatible property should be different.

Quoted 9 lines

I stumbled about that recently, too and found in arch/arm/plat-mxc/devices/platform-imx-i2c.c that the third device description for imx51 is a normal "imx-i2c" one using MX51_HSI2C_DMA_BASE_ADDR. So I concluded it's different but compatible.

board-mx51_babbage.c uses imx51_add_hsi2c but doesn't add a bus description. So It might not attract attention if the driver doesn't match the device.

Aha, I was confused by the platform codes. Will drop HSI2C.

Thanks for catching this, Rob.

Signature · 2 lines
Regards,
Shawn
#6 lore raw

PATCH 2/2 i2c-imx: add device tree probe support

Hi,

Quoted 21 lines · Shawn Guo
Quoted 20 lines · Uwe Kleine-K?nig

Hello Rob,

Quoted 10 lines · Rob Herring

Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt line 20

Quoted 7 lines
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file +7 -0
+i2c at 83fc4000 { /* I2C2 on i.MX51 */
+	compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
+	reg = <0x83fc4000 0x4000>;
+	interrupts = <63>;
+};
+
+i2c at 70038000 { /* HS-I2C on i.MX51 */

The mainline driver doesn't support the HS-I2C block does it?

Quoted 2 lines

The high speed and "old" i2c blocks on MX51 are basically different blocks, so the compatible property should be different.

I stumbled about that recently, too and found in arch/arm/plat-mxc/devices/platform-imx-i2c.c that the third device description for imx51 is a normal "imx-i2c" one using MX51_HSI2C_DMA_BASE_ADDR. So I concluded it's different but compatible.

Quoted 6 lines
Quoted 4 lines

board-mx51_babbage.c uses imx51_add_hsi2c but doesn't add a bus description. So It might not attract attention if the driver doesn't match the device.

Aha, I was confused by the platform codes. Will drop HSI2C.

According to the i.MX51 Ref. Manual it's so buggy that it should not even be used:

|Chapter 39
|High Speed Inter IC (HS-I2C)
|39.1 Introduction
[...]
|                                   NOTE
|Due to limited functionality, Freescale does not recommend users
|incorporate the HS-I2C module in future designs. For details on the
|limitations, refer to the MX51 IC Errata. Users should consider using the
|two standard I2C modules, which have no errata.

Fortunately there is an i2c-gpio driver that can be used on the corresponding pins. ;-)

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
___________________________________________________________