Skip to contentSkip to conversation

i2c: tegra: Support DVC controller in device tree

PATCH New Stephen Warren 3 participants 6 messages Dec 18, 2011

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

PATCH 1/3 i2c: tegra: Support DVC controller in device tree

One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller) block. This block is identical to the rest of the I2C blocks, except that it only supports master mode, it has registers moved around, and it needs some extra init to get it into I2C mode. The register moves are handled by i2c_readl and i2c_writel

This patch adds a new compatible value for controllers of this "DVC" type; I figured that this approach was reasonable, as opposed to adding an is-dvc property under the existing compatible value, since the HW truly is different.

---
Ben, it'd probably be simplest if you could ack this patch, and we could take it through the Tegra tree.

 drivers/i2c/busses/i2c-tegra.c |   37 +++++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 12 deletions(-)
drivers/i2c/busses/i2c-tegra.c +25 -12
index 46b6500..c264e8c 100644
@@ -26,6 +26,7 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/i2c-tegra.h>
+#include <linux/of_device.h>
 #include <linux/of_i2c.h>
 #include <linux/module.h>
 
@@ -558,6 +559,18 @@ static const struct i2c_algorithm tegra_i2c_algo = {
 	.functionality	= tegra_i2c_func,
 };
 
+#if defined(CONFIG_OF)
+/* Match table for of_platform binding */
+static const struct of_device_id tegra_i2c_of_match[] __devinitconst = {
+	{ .compatible = "nvidia,tegra20-i2c",     .data = (void *)0},
+	{ .compatible = "nvidia,tegra20-i2c-dvc", .data = (void *)1},
+	{},
+};
+MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
+#else
+#define tegra_i2c_of_match NULL
+#endif
+
 static int tegra_i2c_probe(struct platform_device *pdev)
 {
 	struct tegra_i2c_dev *i2c_dev;
@@ -636,7 +649,18 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 			i2c_dev->bus_clk_rate = be32_to_cpup(prop);
 	}
 
-	if (pdev->id == 3)
+#if defined(CONFIG_OF)
+	if (pdev->dev.of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_device(tegra_i2c_of_match, &pdev->dev);
+		if (!match)
+			return -EINVAL;
+
+		i2c_dev->is_dvc = match->data;
+	}
+#endif
+	else if (pdev->id == 3)
 		i2c_dev->is_dvc = 1;
 	init_completion(&i2c_dev->msg_complete);
 
@@ -738,17 +762,6 @@ static int tegra_i2c_resume(struct platform_device *pdev)
 }
 #endif
 
-#if defined(CONFIG_OF)
-/* Match table for of_platform binding */
-static const struct of_device_id tegra_i2c_of_match[] __devinitconst = {
-	{ .compatible = "nvidia,tegra20-i2c", },
-	{},
-};
-MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
-#else
-#define tegra_i2c_of_match NULL
-#endif
-
 static struct platform_driver tegra_i2c_driver = {
 	.probe   = tegra_i2c_probe,
 	.remove  = tegra_i2c_remove,
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 2/3 arm/dt: tegra: Use new compatible value for DVC I2C controller

Update the device tree to indicate which I2C controller is the DVC controller. AUXDATA needs to be updated too, since the compatible value changed.

---
It'd be best to apply this to the same tree as the previous patch. If that doesn't happen, the DVC I2C driver won't be instantiated due to the compatible value not being supported. In practice, this isn't an issue though, since nothing uses the DVC I2C controller yet.

This relies on 0d4f747 "arm/tegra: convert tegra20 to GIC devicetree binding" for context.

 arch/arm/boot/dts/tegra20.dtsi |    2 +-
 arch/arm/mach-tegra/board-dt.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/boot/dts/tegra20.dtsi +1 -1
index 660c8ad..3da7afd 100644
@@ -39,7 +39,7 @@
 	i2c at 7000d000 {
 		#address-cells = <1>;
 		#size-cells = <0>;
-		compatible = "nvidia,tegra20-i2c";
+		compatible = "nvidia,tegra20-i2c-dvc";
 		reg = <0x7000D000 0x200>;
 		interrupts = < 0 53 0x04 >;
 	};
arch/arm/mach-tegra/board-dt.c +1 -1
index b44633b..9abc89d 100644
@@ -74,7 +74,7 @@ struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
 	OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_I2C_BASE, "tegra-i2c.0", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_I2C2_BASE, "tegra-i2c.1", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_I2C3_BASE, "tegra-i2c.2", NULL),
-	OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_DVC_BASE, "tegra-i2c.3", NULL),
+	OF_DEV_AUXDATA("nvidia,tegra20-i2c-dvc", TEGRA_DVC_BASE, "tegra-i2c.3", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-i2s", TEGRA_I2S1_BASE, "tegra-i2s.0", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-i2s", TEGRA_I2S2_BASE, "tegra-i2s.1", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-das", TEGRA_APB_MISC_DAS_BASE, "tegra-das", NULL),
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH 3/3 arm/dt: Add ADT7461 to Seaboard

In reply to Stephen Warren

The ADT7461 is a temperature monitoring IC. One is present on the DVC I2C bus on Seaboard.

---
For this to be useful, the previous two patches are required. Without them, all the I2C transactions to this device will time out and spew errors, but other device shouldn't be affected.

 arch/arm/boot/dts/tegra-seaboard.dts |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/arm/boot/dts/tegra-seaboard.dts +5 -0
index 3cfbd04..b55a02e 100644
@@ -25,6 +25,11 @@
 
 	i2c at 7000d000 {
 		clock-frequency = <400000>;
+
+		adt7461 at 4c {
+			compatible = "adt7461";
+			reg = <0x4c>;
+		};
 	};
 
 	serial at 70006000 {
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH 1/3 i2c: tegra: Support DVC controller in device tree

In reply to Stephen Warren

Hi,

Quoted 54 lines · Stephen Warren

One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller) block. This block is identical to the rest of the I2C blocks, except that it only supports master mode, it has registers moved around, and it needs some extra init to get it into I2C mode. The register moves are handled by i2c_readl and i2c_writel

This patch adds a new compatible value for controllers of this "DVC" type; I figured that this approach was reasonable, as opposed to adding an is-dvc property under the existing compatible value, since the HW truly is different.

---
Ben, it'd probably be simplest if you could ack this patch, and we could take it through the Tegra tree.

 drivers/i2c/busses/i2c-tegra.c |   37 +++++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 12 deletions(-)
drivers/i2c/busses/i2c-tegra.c +13 -0
index 46b6500..c264e8c 100644
@@ -26,6 +26,7 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/i2c-tegra.h>
+#include <linux/of_device.h>
 #include <linux/of_i2c.h>
 #include <linux/module.h>
 
@@ -558,6 +559,18 @@ static const struct i2c_algorithm tegra_i2c_algo = {
 	.functionality	= tegra_i2c_func,
 };
 
+#if defined(CONFIG_OF)
+/* Match table for of_platform binding */
+static const struct of_device_id tegra_i2c_of_match[] __devinitconst = {
+	{ .compatible = "nvidia,tegra20-i2c",     .data = (void *)0},
+	{ .compatible = "nvidia,tegra20-i2c-dvc", .data = (void *)1},
+	{},
+};
+MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
+#else
+#define tegra_i2c_of_match NULL
+#endif
+
 static int tegra_i2c_probe(struct platform_device *pdev)
 {
 	struct tegra_i2c_dev *i2c_dev;
@@ -636,7 +649,18 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 			i2c_dev->bus_clk_rate = be32_to_cpup(prop);
 	}
 

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_probe(struct platform_device *pdev) · line 660

Quoted 10 lines
drivers/i2c/busses/i2c-tegra.c +9 -1
-	if (pdev->id == 3)
+#if defined(CONFIG_OF)
+	if (pdev->dev.of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_device(tegra_i2c_of_match, &pdev->dev);
+		if (!match)
+			return -EINVAL;
+
+		i2c_dev->is_dvc = match->data;

I would rather see a:

		i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node,
						"nvidia,tegra20-i2c-dvc");

...instead of passing a flag through the match data.

-Olof

#4 lore raw

PATCH 1/3 i2c: tegra: Support DVC controller in device tree

In reply to Stephen Warren

* Stephen Warren wrote:
[...]

Quoted 7 lines
drivers/i2c/busses/i2c-tegra.c +2 -1
@@ -636,7 +649,18 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 			i2c_dev->bus_clk_rate = be32_to_cpup(prop);
 	}
 
-	if (pdev->id == 3)
+#if defined(CONFIG_OF)
+	if (pdev->dev.of_node) {

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_probe(struct platform_device *pdev) · line 663

Quoted 10 lines
drivers/i2c/busses/i2c-tegra.c +10 -0
+		const struct of_device_id *match;
+
+		match = of_match_device(tegra_i2c_of_match, &pdev->dev);
+		if (!match)
+			return -EINVAL;
+
+		i2c_dev->is_dvc = match->data;
+	}
+#endif
+	else if (pdev->id == 3)

Shouldn't the "else" move into the CONFIG_OF branch?

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20111218/200453ba/attachment.sig>

#5 lore raw

PATCH 1/3 i2c: tegra: Support DVC controller in device tree

Quoted 6 lines · Thierry Reding

* Stephen Warren wrote:
[...]

Quoted 4 lines
drivers/i2c/busses/i2c-tegra.c +0 -0
@@ -636,7 +649,18 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 			i2c_dev->bus_clk_rate = be32_to_cpup(prop);
 	}
 
Quoted 15 lines

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_probe(struct platform_device *pdev) · line 663

Quoted 13 lines
drivers/i2c/busses/i2c-tegra.c +12 -1
-	if (pdev->id == 3)
+#if defined(CONFIG_OF)
+	if (pdev->dev.of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_device(tegra_i2c_of_match, &pdev->dev);
+		if (!match)
+			return -EINVAL;
+
+		i2c_dev->is_dvc = match->data;
+	}
+#endif
+	else if (pdev->id == 3)

Shouldn't the "else" move into the CONFIG_OF branch?

Okay, I hadn't seen v2. Please ignore.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20111218/34f0f8ab/attachment.sig>