Skip to contentSkip to conversation

ARM: Tegra: i2c driver

PATCH In review John Bonesio 6 participants 8 messages Jun 21, 2011 – Jun 22, 2011

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

PATCH 1/1 ARM: Tegra: i2c driver

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

---

 drivers/i2c/busses/i2c-tegra.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-tegra.c +16 -1
index 4d93196..d2393e6 100644
@@ -26,6 +26,7 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/i2c-tegra.h>
+#include <linux/of_i2c.h>
 
 #include <asm/unaligned.h>
 
@@ -540,6 +541,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 	struct resource *iomem;
 	struct clk *clk;
 	struct clk *i2c_clk;
+	const unsigned int *prop;
 	void *base;
 	int irq;
 	int ret = 0;
@@ -597,7 +599,17 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 	i2c_dev->irq = irq;
 	i2c_dev->cont_id = pdev->id;
 	i2c_dev->dev = &pdev->dev;
-	i2c_dev->bus_clk_rate = pdata ? pdata->bus_clk_rate : 100000;
+
+	i2c_dev->bus_clk_rate = 100000; /* default clock rate */
+	if (pdata) {
+		i2c_dev->bus_clk_rate = pdata->bus_clk_rate;
+
+	} else if (i2c_dev->dev->of_node) {    /* if there is a device tree node ... */
+		prop = of_get_property(i2c_dev->dev->of_node,
+				"clock-frequency", NULL);
+		if (prop)
+			i2c_dev->bus_clk_rate = be32_to_cpup(prop);
+	}
 
 	if (pdev->id == 3)
 		i2c_dev->is_dvc = 1;
@@ -627,6 +639,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 	i2c_dev->adapter.algo = &tegra_i2c_algo;
 	i2c_dev->adapter.dev.parent = &pdev->dev;
 	i2c_dev->adapter.nr = pdev->id;
+	i2c_dev->adapter.dev.of_node = pdev->dev.of_node;
 
 	ret = i2c_add_numbered_adapter(&i2c_dev->adapter);
 	if (ret) {
@@ -634,6 +647,8 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 		goto err_free_irq;
 	}
 
+	of_i2c_register_devices(&i2c_dev->adapter);
+
 	return 0;
 err_free_irq:
 	free_irq(i2c_dev->irq, i2c_dev);
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · John Bonesio

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

Quoted 63 lines

---

 drivers/i2c/busses/i2c-tegra.c |   17 ++++++++++++++++-

 1 files changed, 16 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-tegra.c +16 -1
index 4d93196..d2393e6 100644
@@ -26,6 +26,7 @@
  #include <linux/delay.h>
  #include <linux/slab.h>
  #include <linux/i2c-tegra.h>
+#include <linux/of_i2c.h>
 
  #include <asm/unaligned.h>
 
@@ -540,6 +541,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
        struct resource *iomem;
        struct clk *clk;
        struct clk *i2c_clk;
+       const unsigned int *prop;
        void *base;
        int irq;
        int ret = 0;
@@ -597,7 +599,17 @@ static int tegra_i2c_probe(struct platform_device *pdev)
        i2c_dev->irq = irq;
        i2c_dev->cont_id = pdev->id;
        i2c_dev->dev = &pdev->dev;
-       i2c_dev->bus_clk_rate = pdata ? pdata->bus_clk_rate : 100000;
+
+       i2c_dev->bus_clk_rate = 100000; /* default clock rate */
+       if (pdata) {
+               i2c_dev->bus_clk_rate = pdata->bus_clk_rate;
+
+       } else if (i2c_dev->dev->of_node) {    /* if there is a device tree node ... */
+               prop = of_get_property(i2c_dev->dev->of_node,
+                               "clock-frequency", NULL);
+               if (prop)
+                       i2c_dev->bus_clk_rate = be32_to_cpup(prop);
+       }
 
        if (pdev->id == 3)
                i2c_dev->is_dvc = 1;
@@ -627,6 +639,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
        i2c_dev->adapter.algo = &tegra_i2c_algo;
        i2c_dev->adapter.dev.parent = &pdev->dev;
        i2c_dev->adapter.nr = pdev->id;
+       i2c_dev->adapter.dev.of_node = pdev->dev.of_node;
 
        ret = i2c_add_numbered_adapter(&i2c_dev->adapter);
        if (ret) {
@@ -634,6 +647,8 @@ static int tegra_i2c_probe(struct platform_device *pdev)
                goto err_free_irq;
        }
 
+       of_i2c_register_devices(&i2c_dev->adapter);
+
        return 0;

 err_free_irq:
       free_irq(i2c_dev->irq, i2c_dev);

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#2 lore raw
Quoted 7 lines · Grant Likely
Quoted 4 lines · John Bonesio

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

(with the same suggestion to change subject as Stephen/Grant discussed later in the thread).

-Olof

#3 lore raw
Quoted 7 lines · Olof Johansson
Quoted 6 lines · Grant Likely
Quoted 4 lines · John Bonesio

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

Quoted 7 lines
Quoted 1 line

(with the same suggestion to change subject as Stephen/Grant discussed later in the thread).

Ben, would you like a new patch with the new subject line, or will you fix it up when you merge it?

g.

#4 lore raw
Quoted 10 lines · Grant Likely
Quoted 9 lines · Olof Johansson
Quoted 7 lines · Grant Likely
Quoted 4 lines · John Bonesio

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

Quoted 8 lines
Quoted 5 lines

(with the same suggestion to change subject as Stephen/Grant discussed later in the thread).

Ben, would you like a new patch with the new subject line, or will you fix it up when you merge it?

Would prefer to see a new subject line.

Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.
#5 lore raw
In reply to John Bonesio

John Bonesio wrote at Monday, June 20, 2011 6:23 PM:

Quoted 2 lines

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

The patch title "ARM: Tegra: i2c driver" doesn't really describe what the patch does and has the wrong tag; It sounds like adding a new driver. Perhaps "i2c: Tegra: Add DeviceTree support"?

The code looks fine.

Signature · 1 line
nvpublic
#6 lore raw
Quoted 7 lines · Stephen Warren

John Bonesio wrote at Monday, June 20, 2011 6:23 PM:

Quoted 2 lines

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

The patch title "ARM: Tegra: i2c driver" doesn't really describe what the patch does and has the wrong tag; It sounds like adding a new driver. Perhaps "i2c: Tegra: Add DeviceTree support"?

Yes, sounds appropriate to me.

g.

Quoted 7 lines

The code looks fine.

--
nvpublic

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#7 lore raw
In reply to John Bonesio

John Bonesio wrote at Monday, June 20, 2011 6:23 PM:

Quoted 2 lines

This patch modifies the tegra i2c driver so that it can be initiailized using the device tree along with the devices connected to the i2c bus.

The patch title "ARM: Tegra: i2c driver" doesn't really describe what the patch does and has the wrong tag; It sounds like adding a new driver. Perhaps "i2c: Tegra: Add DeviceTree support"?

The code looks fine.

Signature · 1 line
nvpublic