2012-08-23 15:01:48

by Lee Jones

[permalink] [raw]
Subject: [PATCH 1/3] ARM: ux500: Add i2c configurations to the Device Tree for DB8500 based devices

Since initial support was provided for the Nomadik I2C driver, it
has been converted to an AMBA device. AMBA devices are probed in
a slightly different way to other devices, so we have to identify
them using an "arm,primecell" compatible string. As well as doing
just that, this patch specifies which regulators the controller
should use and requests a clock-speed. The latter is provided as
more of an example, as it's the same as the recently changed
default configuration.

Acked-by: Linus Walleij <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
---
arch/arm/boot/dts/dbx5x0.dtsi | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boot/dts/dbx5x0.dtsi b/arch/arm/boot/dts/dbx5x0.dtsi
index 51209a8..3708a6b 100644
--- a/arch/arm/boot/dts/dbx5x0.dtsi
+++ b/arch/arm/boot/dts/dbx5x0.dtsi
@@ -480,43 +480,58 @@
};

i2c@80004000 {
- compatible = "stericsson,db8500-i2c", "st,nomadik-i2c";
+ compatible = "stericsson,db8500-i2c", "st,nomadik-i2c", "arm,primecell";
reg = <0x80004000 0x1000>;
interrupts = <0 21 0x4>;
#address-cells = <1>;
#size-cells = <0>;
+ v-i2c-supply = <&db8500_vape_reg>;
+
+ clock-frequency = <400000>;
};

i2c@80122000 {
- compatible = "stericsson,db8500-i2c", "st,nomadik-i2c";
+ compatible = "stericsson,db8500-i2c", "st,nomadik-i2c", "arm,primecell";
reg = <0x80122000 0x1000>;
interrupts = <0 22 0x4>;
#address-cells = <1>;
#size-cells = <0>;
+ v-i2c-supply = <&db8500_vape_reg>;
+
+ clock-frequency = <400000>;
};

i2c@80128000 {
- compatible = "stericsson,db8500-i2c", "st,nomadik-i2c";
+ compatible = "stericsson,db8500-i2c", "st,nomadik-i2c", "arm,primecell";
reg = <0x80128000 0x1000>;
interrupts = <0 55 0x4>;
#address-cells = <1>;
#size-cells = <0>;
+ v-i2c-supply = <&db8500_vape_reg>;
+
+ clock-frequency = <400000>;
};

i2c@80110000 {
- compatible = "stericsson,db8500-i2c", "st,nomadik-i2c";
+ compatible = "stericsson,db8500-i2c", "st,nomadik-i2c", "arm,primecell";
reg = <0x80110000 0x1000>;
interrupts = <0 12 0x4>;
#address-cells = <1>;
#size-cells = <0>;
+ v-i2c-supply = <&db8500_vape_reg>;
+
+ clock-frequency = <400000>;
};

i2c@8012a000 {
- compatible = "stericsson,db8500-i2c", "st,nomadik-i2c";
+ compatible = "stericsson,db8500-i2c", "st,nomadik-i2c", "arm,primecell";
reg = <0x8012a000 0x1000>;
interrupts = <0 51 0x4>;
#address-cells = <1>;
#size-cells = <0>;
+ v-i2c-supply = <&db8500_vape_reg>;
+
+ clock-frequency = <400000>;
};

ssp@80002000 {
--
1.7.9.5


2012-08-23 15:01:50

by Lee Jones

[permalink] [raw]
Subject: [PATCH 3/3] i2c: nomadik: Add Device Tree support to the Nomadik I2C driver

Here we apply the bindings required for successful Device Tree
probing of the i2c-nomadik driver.

Cc: [email protected]
Acked-by: srinidhi kasagar <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
---
drivers/i2c/busses/i2c-nomadik.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 61b00ed..8168389 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -25,6 +25,7 @@
#include <linux/regulator/consumer.h>
#include <linux/pm_runtime.h>
#include <linux/platform_data/i2c-nomadik.h>
+#include <linux/of.h>

#define DRIVER_NAME "nmk-i2c"

@@ -920,15 +921,42 @@ static struct nmk_i2c_controller u8500_i2c = {
.sm = I2C_FREQ_MODE_FAST,
};

+static void nmk_i2c_of_probe(struct device_node *np,
+ struct nmk_i2c_controller *pdata)
+{
+ /* Provide the default configuration as a base. */
+ pdata = &u8500_i2c;
+
+ of_property_read_u32(np, "clock-frequency", (u32*)&pdata->clk_freq);
+
+ /* This driver only supports 'standard' and 'fast' modes of operation. */
+ if (pdata->clk_freq <= 100000)
+ pdata->sm = I2C_FREQ_MODE_STANDARD;
+ else
+ pdata->sm = I2C_FREQ_MODE_FAST;
+}
+
static atomic_t adapter_id = ATOMIC_INIT(0);

static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
{
int ret = 0;
struct nmk_i2c_controller *pdata = adev->dev.platform_data;
+ struct device_node *np = adev->dev.of_node;
struct nmk_i2c_dev *dev;
struct i2c_adapter *adap;

+ if (np) {
+ if (!pdata) {
+ pdata = devm_kzalloc(&adev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata) {
+ ret = -ENOMEM;
+ goto err_no_mem;
+ }
+ }
+ nmk_i2c_of_probe(np, pdata);
+ }
+
if (!pdata)
/* No i2c configuration found, using the default. */
pdata = &u8500_i2c;
--
1.7.9.5

2012-08-23 15:02:13

by Lee Jones

[permalink] [raw]
Subject: [PATCH 2/3] Documentation: Device Tree binding information for i2c-nomadik driver

This document describes each of the non-standard Device Tree bindings
used in the Nomadik I2C driver.

Acked-by: Linus Walleij <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
---
Documentation/devicetree/bindings/i2c/nomadik.txt | 23 +++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 Documentation/devicetree/bindings/i2c/nomadik.txt

diff --git a/Documentation/devicetree/bindings/i2c/nomadik.txt b/Documentation/devicetree/bindings/i2c/nomadik.txt
new file mode 100644
index 0000000..72065b0
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/nomadik.txt
@@ -0,0 +1,23 @@
+I2C for Nomadik based systems
+
+Required (non-standard) properties:
+ - Nil
+
+Recommended (non-standard) properties:
+ - clock-frequency : Maximum bus clock frequency for the device
+
+Optional (non-standard) properties:
+ - Nil
+
+Example :
+
+i2c@80004000 {
+ compatible = "stericsson,db8500-i2c", "st,nomadik-i2c";
+ reg = <0x80004000 0x1000>;
+ interrupts = <0 21 0x4>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+ v-i2c-supply = <&db8500_vape_reg>;
+
+ clock-frequency = <400000>;
+};
--
1.7.9.5

2012-08-27 23:42:52

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: nomadik: Add Device Tree support to the Nomadik I2C driver

On Thu, Aug 23, 2012 at 8:01 AM, Lee Jones <[email protected]> wrote:

> Here we apply the bindings required for successful Device Tree
> probing of the i2c-nomadik driver.
>
> Cc: [email protected]
> Acked-by: srinidhi kasagar <[email protected]>
> Signed-off-by: Lee Jones <[email protected]>

Acked-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij

2012-08-31 10:36:44

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: nomadik: Add Device Tree support to the Nomadik I2C driver

On Mon, Aug 27, 2012 at 04:42:49PM -0700, Linus Walleij wrote:
> On Thu, Aug 23, 2012 at 8:01 AM, Lee Jones <[email protected]> wrote:
>
> > Here we apply the bindings required for successful Device Tree
> > probing of the i2c-nomadik driver.
> >
> > Cc: [email protected]
> > Acked-by: srinidhi kasagar <[email protected]>
> > Signed-off-by: Lee Jones <[email protected]>
>
> Acked-by: Linus Walleij <[email protected]>

I'm assuming I still need Wolfram's Ack on this?

--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2012-08-31 11:23:05

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: nomadik: Add Device Tree support to the Nomadik I2C driver

On Thu, Aug 23, 2012 at 04:01:27PM +0100, Lee Jones wrote:
> Here we apply the bindings required for successful Device Tree
> probing of the i2c-nomadik driver.
>
> Cc: [email protected]
> Acked-by: srinidhi kasagar <[email protected]>

Two acks? I'd think this cannot work for multiple reasons.

BTW, patch 2 and 3 should be merged. It is a lot easier to review the
code with the binding description together.

Is there some dependency other than updating the dts files? If not, I'd
like to pick up the patch via I2C.

> Signed-off-by: Lee Jones <[email protected]>
> ---
> drivers/i2c/busses/i2c-nomadik.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
> index 61b00ed..8168389 100644
> --- a/drivers/i2c/busses/i2c-nomadik.c
> +++ b/drivers/i2c/busses/i2c-nomadik.c
> @@ -25,6 +25,7 @@
> #include <linux/regulator/consumer.h>
> #include <linux/pm_runtime.h>
> #include <linux/platform_data/i2c-nomadik.h>
> +#include <linux/of.h>
>
> #define DRIVER_NAME "nmk-i2c"
>
> @@ -920,15 +921,42 @@ static struct nmk_i2c_controller u8500_i2c = {
> .sm = I2C_FREQ_MODE_FAST,
> };
>
> +static void nmk_i2c_of_probe(struct device_node *np,
> + struct nmk_i2c_controller *pdata)
> +{
> + /* Provide the default configuration as a base. */
> + pdata = &u8500_i2c;

?????? I wonder how that could work... have you tested the patch?

> +
> + of_property_read_u32(np, "clock-frequency", (u32*)&pdata->clk_freq);

Might be worth changing clk_freq to u32?

> +
> + /* This driver only supports 'standard' and 'fast' modes of operation. */
> + if (pdata->clk_freq <= 100000)
> + pdata->sm = I2C_FREQ_MODE_STANDARD;

Is standard == 100000 Hz?


> + else
> + pdata->sm = I2C_FREQ_MODE_FAST;

If those two are fixed frequencies, you should omit a warning if the
devicetree has a different frequency set and report which one is going
to be used actually.


> +}
> +
> static atomic_t adapter_id = ATOMIC_INIT(0);
>
> static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
> {
> int ret = 0;
> struct nmk_i2c_controller *pdata = adev->dev.platform_data;
> + struct device_node *np = adev->dev.of_node;
> struct nmk_i2c_dev *dev;
> struct i2c_adapter *adap;
>
> + if (np) {
> + if (!pdata) {
> + pdata = devm_kzalloc(&adev->dev, sizeof(*pdata), GFP_KERNEL);
> + if (!pdata) {
> + ret = -ENOMEM;
> + goto err_no_mem;
> + }
> + }
> + nmk_i2c_of_probe(np, pdata);
> + }
> +
> if (!pdata)
> /* No i2c configuration found, using the default. */
> pdata = &u8500_i2c;
> --
> 1.7.9.5
>

--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |


Attachments:
(No filename) (2.77 kB)
signature.asc (198.00 B)
Digital signature
Download all attachments

2012-08-31 12:04:21

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: nomadik: Add Device Tree support to the Nomadik I2C driver

> Is there some dependency other than updating the dts files? If not, I'd
> like to pick up the patch via I2C.

There's no other dependency. Feel free to take them into your tree.

> > +static void nmk_i2c_of_probe(struct device_node *np,
> > + struct nmk_i2c_controller *pdata)
> > +{
> > + /* Provide the default configuration as a base. */
> > + pdata = &u8500_i2c;
>
> ?????? I wonder how that could work... have you tested the patch?

Wow, that's a great spot!

I have tested the patch, but I don't have any i2c devices, so can't
test full functionality. I, wrongly it seems, assumed there would be
a complaint from the I2C subsystem if any of the values seemed wrong.
What I will do before next submission is print out the entire pdata
structure to ensure it's populated in the correct way.

> > +
> > + of_property_read_u32(np, "clock-frequency", (u32*)&pdata->clk_freq);
>
> Might be worth changing clk_freq to u32?

Yes, makes sense.

> > +
> > + /* This driver only supports 'standard' and 'fast' modes of operation. */
> > + if (pdata->clk_freq <= 100000)
> > + pdata->sm = I2C_FREQ_MODE_STANDARD;
>
> Is standard == 100000 Hz?

Well it depends on how you interpret the comments in:
include/linux/platform_data/i2c-nomadik.h

enum i2c_freq_mode {
I2C_FREQ_MODE_STANDARD, /* up to 100 Kb/s */
I2C_FREQ_MODE_FAST, /* up to 400 Kb/s */
I2C_FREQ_MODE_HIGH_SPEED, /* up to 3.4 Mb/s */
I2C_FREQ_MODE_FAST_PLUS, /* up to 1 Mb/s */
};

I guess your guess would be better than mine.

> > + else
> > + pdata->sm = I2C_FREQ_MODE_FAST;
>
> If those two are fixed frequencies, you should omit a warning if the
> devicetree has a different frequency set and report which one is going
> to be used actually.

Well, again by the comments above I would say that in between values
were valid, but I'm willing to bow down to your knowledge if you think
they are fixed values?

Thanks for reviewing.

--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2012-08-31 12:23:34

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: nomadik: Add Device Tree support to the Nomadik I2C driver

Hopefully this is more to your liking:

Author: Lee Jones <[email protected]>
Date: Mon Aug 6 11:09:57 2012 +0100

i2c: nomadik: Add Device Tree support to the Nomadik I2C driver

Here we apply the bindings required for successful Device Tree
probing of the i2c-nomadik driver.

Cc: [email protected]
Signed-off-by: Lee Jones <[email protected]>

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 61b00ed..2c85de1 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -25,6 +25,7 @@
#include <linux/regulator/consumer.h>
#include <linux/pm_runtime.h>
#include <linux/platform_data/i2c-nomadik.h>
+#include <linux/of.h>

#define DRIVER_NAME "nmk-i2c"

@@ -920,15 +921,41 @@ static struct nmk_i2c_controller u8500_i2c = {
.sm = I2C_FREQ_MODE_FAST,
};

+static void nmk_i2c_of_probe(struct device_node *np,
+ struct nmk_i2c_controller *pdata)
+{
+ of_property_read_u32(np, "clock-frequency", &pdata->clk_freq);
+
+ /* This driver only supports 'standard' and 'fast' modes of operation. */
+ if (pdata->clk_freq <= 100000)
+ pdata->sm = I2C_FREQ_MODE_STANDARD;
+ else
+ pdata->sm = I2C_FREQ_MODE_FAST;
+}
+
static atomic_t adapter_id = ATOMIC_INIT(0);

static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
{
int ret = 0;
struct nmk_i2c_controller *pdata = adev->dev.platform_data;
+ struct device_node *np = adev->dev.of_node;
struct nmk_i2c_dev *dev;
struct i2c_adapter *adap;

+ if (np) {
+ if (!pdata) {
+ pdata = devm_kzalloc(&adev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata) {
+ ret = -ENOMEM;
+ goto err_no_mem;
+ }
+ }
+ /* Provide the default configuration as a base. */
+ pdata = &u8500_i2c;
+ nmk_i2c_of_probe(np, pdata);
+ }
+
if (!pdata)
/* No i2c configuration found, using the default. */
pdata = &u8500_i2c;
diff --git a/include/linux/platform_data/i2c-nomadik.h b/include/linux/platform_data/i2c-nomadik.h
index c2303c3..3a8be9c 100644
--- a/include/linux/platform_data/i2c-nomadik.h
+++ b/include/linux/platform_data/i2c-nomadik.h
@@ -28,7 +28,7 @@ enum i2c_freq_mode {
* @sm: speed mode
*/
struct nmk_i2c_controller {
- unsigned long clk_freq;
+ u32 clk_freq;
unsigned short slsu;
unsigned char tft;
unsigned char rft;