diff mbox

[3/5] i2c: rcar: add Device Tree support

Message ID 1378742120-11135-4-git-send-email-g.liakhovetski@gmx.de (mailing list archive)
State Changes Requested
Headers show

Commit Message

Guennadi Liakhovetski Sept. 9, 2013, 3:55 p.m. UTC
This patch adds Device Tree support to the i2c-rcar driver and respective
documentation.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
---
 Documentation/devicetree/bindings/i2c/i2c-rcar.txt |   22 ++++++++++++++++++++
 drivers/i2c/busses/i2c-rcar.c                      |   20 ++++++++++++++++-
 2 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-rcar.txt

Comments

Magnus Damm Sept. 10, 2013, 10:40 p.m. UTC | #1
Hi Guennadi,

[CC Simon, Laurent]

On Tue, Sep 10, 2013 at 12:55 AM, Guennadi Liakhovetski
<g.liakhovetski@gmx.de> wrote:
> This patch adds Device Tree support to the i2c-rcar driver and respective
> documentation.
>
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-rcar.txt |   22 ++++++++++++++++++++
>  drivers/i2c/busses/i2c-rcar.c                      |   20 ++++++++++++++++-
>  2 files changed, 40 insertions(+), 2 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/i2c/i2c-rcar.txt
>
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> new file mode 100644
> index 0000000..b3c030b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> @@ -0,0 +1,22 @@
> +I2C for R-Car platforms
> +
> +Required properties:
> +- compatible: Must be one of
> +       "renesas,i2c-rcar"
> +       "renesas,i2c-rcar-h1"
> +       "renesas,i2c-rcar-h2"

Is this following the same style as other DT patches? It looks to me
that you may want to use r8a7779 and r8a7790 instead of h1 and h2.

Simon, Laurent, what do you think about this?

/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart Sept. 10, 2013, 10:46 p.m. UTC | #2
Hi Magnus,

On Wednesday 11 September 2013 07:40:54 Magnus Damm wrote:
> Hi Guennadi,
> 
> [CC Simon, Laurent]
> 
> On Tue, Sep 10, 2013 at 12:55 AM, Guennadi Liakhovetski wrote:
> > This patch adds Device Tree support to the i2c-rcar driver and respective
> > documentation.
> > 
> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
> > ---
> > 
> >  Documentation/devicetree/bindings/i2c/i2c-rcar.txt |   22 +++++++++++++++
> >  drivers/i2c/busses/i2c-rcar.c                      |   20 ++++++++++++++-
> >  2 files changed, 40 insertions(+), 2 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> > b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt new file mode 100644
> > index 0000000..b3c030b
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> > @@ -0,0 +1,22 @@
> > +I2C for R-Car platforms
> > +
> > +Required properties:
> > +- compatible: Must be one of
> > +       "renesas,i2c-rcar"
> > +       "renesas,i2c-rcar-h1"
> > +       "renesas,i2c-rcar-h2"
> 
> Is this following the same style as other DT patches? It looks to me
> that you may want to use r8a7779 and r8a7790 instead of h1 and h2.
> 
> Simon, Laurent, what do you think about this?

I think that should be "renesas,i2c-r8a7779" and "renesas,i2c-r8a7790", yes.
Magnus Damm Sept. 10, 2013, 10:49 p.m. UTC | #3
Hi Laurent,

On Wed, Sep 11, 2013 at 7:46 AM, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
> Hi Magnus,
>
> On Wednesday 11 September 2013 07:40:54 Magnus Damm wrote:
>> Hi Guennadi,
>>
>> [CC Simon, Laurent]
>>
>> On Tue, Sep 10, 2013 at 12:55 AM, Guennadi Liakhovetski wrote:
>> > This patch adds Device Tree support to the i2c-rcar driver and respective
>> > documentation.
>> >
>> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
>> > ---
>> >
>> >  Documentation/devicetree/bindings/i2c/i2c-rcar.txt |   22 +++++++++++++++
>> >  drivers/i2c/busses/i2c-rcar.c                      |   20 ++++++++++++++-
>> >  2 files changed, 40 insertions(+), 2 deletions(-)
>> >  create mode 100644 Documentation/devicetree/bindings/i2c/i2c-rcar.txt
>> >
>> > diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
>> > b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt new file mode 100644
>> > index 0000000..b3c030b
>> > --- /dev/null
>> > +++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
>> > @@ -0,0 +1,22 @@
>> > +I2C for R-Car platforms
>> > +
>> > +Required properties:
>> > +- compatible: Must be one of
>> > +       "renesas,i2c-rcar"
>> > +       "renesas,i2c-rcar-h1"
>> > +       "renesas,i2c-rcar-h2"
>>
>> Is this following the same style as other DT patches? It looks to me
>> that you may want to use r8a7779 and r8a7790 instead of h1 and h2.
>>
>> Simon, Laurent, what do you think about this?
>
> I think that should be "renesas,i2c-r8a7779" and "renesas,i2c-r8a7790", yes.

Thanks for your comments. I recall that r8a7790 has a bunch of
channels and at least two types of i2c controllers. I wonder what the
proper naming would be then...

/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Guennadi Liakhovetski Sept. 11, 2013, 7:37 a.m. UTC | #4
Hi Magnus, Laurent

On Wed, 11 Sep 2013, Magnus Damm wrote:

> Hi Laurent,
> 
> On Wed, Sep 11, 2013 at 7:46 AM, Laurent Pinchart
> <laurent.pinchart@ideasonboard.com> wrote:
> > Hi Magnus,
> >
> > On Wednesday 11 September 2013 07:40:54 Magnus Damm wrote:
> >> Hi Guennadi,
> >>
> >> [CC Simon, Laurent]
> >>
> >> On Tue, Sep 10, 2013 at 12:55 AM, Guennadi Liakhovetski wrote:
> >> > This patch adds Device Tree support to the i2c-rcar driver and respective
> >> > documentation.
> >> >
> >> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
> >> > ---
> >> >
> >> >  Documentation/devicetree/bindings/i2c/i2c-rcar.txt |   22 +++++++++++++++
> >> >  drivers/i2c/busses/i2c-rcar.c                      |   20 ++++++++++++++-
> >> >  2 files changed, 40 insertions(+), 2 deletions(-)
> >> >  create mode 100644 Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> >> >
> >> > diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> >> > b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt new file mode 100644
> >> > index 0000000..b3c030b
> >> > --- /dev/null
> >> > +++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
> >> > @@ -0,0 +1,22 @@
> >> > +I2C for R-Car platforms
> >> > +
> >> > +Required properties:
> >> > +- compatible: Must be one of
> >> > +       "renesas,i2c-rcar"
> >> > +       "renesas,i2c-rcar-h1"
> >> > +       "renesas,i2c-rcar-h2"
> >>
> >> Is this following the same style as other DT patches? It looks to me
> >> that you may want to use r8a7779 and r8a7790 instead of h1 and h2.
> >>
> >> Simon, Laurent, what do you think about this?
> >
> > I think that should be "renesas,i2c-r8a7779" and "renesas,i2c-r8a7790", yes.

Yes, agree, those names look better. I modelled my names after the 
respective strings in the struct platform_device_id table in the driver, 
looks like that wasn't a very good idea. Yes, I realise that those 
platform device ID don't matter much - they aren't a part of any ABI 
(fortunately), can freely be changed at any time, but maybe it would be 
good to also try to create them according to a certain pattern... But yes, 
that's unrelated.

> Thanks for your comments. I recall that r8a7790 has a bunch of
> channels and at least two types of i2c controllers. I wonder what the
> proper naming would be then...

You're right. r8a7790 has 4 I2C interfaces, each of them can be used with 
either an i2c-sh_mobile - compatible or an i2c-rcar - compatible 
controller instance. Some of those interfaces can also be configured to 
use one of several pin groups.

The i2c-sh_mobile driver already has DT support and it's compatibility 
string, as added by your patch "i2c: sh_mobile: add device tree support" 
of almost 1.5 years ago, is "renesas,rmobile-iic", so, it wouldn't clash 
with the proposed "renesas,i2c-<soc>" naming scheme for i2c-rcar.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
new file mode 100644
index 0000000..b3c030b
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
@@ -0,0 +1,22 @@ 
+I2C for R-Car platforms
+
+Required properties:
+- compatible: Must be one of
+	"renesas,i2c-rcar"
+	"renesas,i2c-rcar-h1"
+	"renesas,i2c-rcar-h2"
+- reg: physical base address of the controller and length of memory mapped
+  region.
+- interrupts: interrupt specifier.
+
+Optional properties:
+- clock-frequency: desired I2C bus clock frequency in Hz. The absence of this
+  propoerty indicates the default frequency 100 kHz.
+
+Examples :
+
+i2c0: i2c@e6500000 {
+	compatible = "renesas,i2c-rcar-h2";
+	reg = <0 0xe6500000 0 0x428>;
+	interrupts = <0 174 0x4>;
+};
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 9325db4..be801b9 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -33,6 +33,7 @@ 
 #include <linux/i2c/i2c-rcar.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
@@ -638,6 +639,14 @@  static const struct i2c_algorithm rcar_i2c_algo = {
 	.functionality	= rcar_i2c_func,
 };
 
+static const struct of_device_id rcar_i2c_dt_ids[] = {
+	{ .compatible = "renesas,i2c-rcar", .data = (void *)I2C_RCAR_H1 },
+	{ .compatible = "renesas,i2c-rcar-h1", .data = (void *)I2C_RCAR_H1 },
+	{ .compatible = "renesas,i2c-rcar-h2", .data = (void *)I2C_RCAR_H2 },
+	{},
+};
+MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids);
+
 static int rcar_i2c_probe(struct platform_device *pdev)
 {
 	struct i2c_rcar_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -655,10 +664,15 @@  static int rcar_i2c_probe(struct platform_device *pdev)
 	}
 
 	bus_speed = 100000; /* default 100 kHz */
-	if (pdata && pdata->bus_speed)
+	ret = of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed);
+	if (ret < 0 && pdata && pdata->bus_speed)
 		bus_speed = pdata->bus_speed;
 
-	priv->devtype = platform_get_device_id(pdev)->driver_data;
+	if (pdev->dev.of_node)
+		priv->devtype = (long)of_match_device(rcar_i2c_dt_ids,
+						      dev)->data;
+	else
+		priv->devtype = platform_get_device_id(pdev)->driver_data;
 
 	ret = rcar_i2c_clock_calculate(priv, bus_speed, dev);
 	if (ret < 0)
@@ -679,6 +693,7 @@  static int rcar_i2c_probe(struct platform_device *pdev)
 	adap->class		= I2C_CLASS_HWMON | I2C_CLASS_SPD;
 	adap->retries		= 3;
 	adap->dev.parent	= dev;
+	adap->dev.of_node	= dev->of_node;
 	i2c_set_adapdata(adap, priv);
 	strlcpy(adap->name, pdev->name, sizeof(adap->name));
 
@@ -726,6 +741,7 @@  static struct platform_driver rcar_i2c_driver = {
 	.driver	= {
 		.name	= "i2c-rcar",
 		.owner	= THIS_MODULE,
+		.of_match_table = rcar_i2c_dt_ids,
 	},
 	.probe		= rcar_i2c_probe,
 	.remove		= rcar_i2c_remove,