Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] i2c: Tegra: Add DeviceTree support

1 view
Skip to first unread message

John Bonesio

unread,
Jun 22, 2011, 12:20:01 PM6/22/11
to
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.

Signed-off-by: John Bonesio <bo...@secretlab.ca>
Acked-by: Grant Likely <grant....@secretlab.ca>
Acked-by: OIof Johansson <ol...@lixom.net>
---

drivers/i2c/busses/i2c-tegra.c | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 4d93196..d2393e6 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -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);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Grant Likely

unread,
Jun 28, 2011, 6:20:02 PM6/28/11
to
On Wed, Jun 22, 2011 at 10:16 AM, John Bonesio <bo...@secretlab.ca> wrote:
> 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.
>
> Signed-off-by: John Bonesio <bo...@secretlab.ca>
> Acked-by: Grant Likely <grant....@secretlab.ca>
> Acked-by: OIof Johansson <ol...@lixom.net>

I just noticed something. This patch is incomplete because it does
not have the of_match_table addition (that bit showed up in the 'fill
in' patch that you sent me privately.) Please respin and include the
of_match_table hunk.

Thanks,
g.

--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

John Bonesio

unread,
Jun 28, 2011, 8:00:02 PM6/28/11
to
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.

Signed-off-by: John Bonesio <bo...@secretlab.ca>
Acked-by: Grant Likely <grant....@secretlab.ca>
Acked-by: OIof Johansson <ol...@lixom.net>

---

Sorry about the previous patch. It's not complete. This is the right one.

- John

drivers/i2c/busses/i2c-tegra.c | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 4d93196..b1d1456 100644

@@ -698,6 +713,17 @@ 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,tegra250-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,
@@ -708,6 +734,7 @@ static struct platform_driver tegra_i2c_driver = {
.driver = {
.name = "tegra-i2c",
.owner = THIS_MODULE,
+ .of_match_table = tegra_i2c_of_match,
},
};

John Bonesio

unread,
Jun 28, 2011, 7:30:01 PM6/28/11
to
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.

Signed-off-by: John Bonesio <bo...@secretlab.ca>
Acked-by: Grant Likely <grant....@secretlab.ca>
Acked-by: OIof Johansson <ol...@lixom.net>
---

drivers/i2c/busses/i2c-tegra.c | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 4d93196..48bb250 100644

@@ -708,6 +723,7 @@ static struct platform_driver tegra_i2c_driver = {

0 new messages