* [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements
@ 2013-09-12 12:36 Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 1/5] i2c: rcar: (cosmetic) remove superfluous parenthesis Guennadi Liakhovetski
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2013-09-12 12:36 UTC (permalink / raw)
To: linux-i2c
Cc: Magnus Damm, linux-sh, Wolfram Sang, devicetree, Grant Likely,
Rob Herring, Guennadi Liakhovetski
Device Tree support for i2c-rcar isn't too complex, only usual or standard
properties are used. Apart from it several clock handling improvements are
included in this patch series.
Developed on top of -next of 12.09.2013
v2: only DT compatibility strings have been changed.
Cc: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
Guennadi Liakhovetski (5):
i2c: rcar: (cosmetic) remove superfluous parenthesis
i2c: rcar: get clock rate only once and simplify calculation
i2c: rcar: add Device Tree support
i2c: rcar: fix clk_get() error handling
i2c: rcar: use per-device clock
Documentation/devicetree/bindings/i2c/i2c-rcar.txt | 23 +++++++++
drivers/i2c/busses/i2c-rcar.c | 51 ++++++++++++++-----
2 files changed, 60 insertions(+), 14 deletions(-)
create mode 100644 Documentation/devicetree/bindings/i2c/i2c-rcar.txt
--
1.7.2.5
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/5] i2c: rcar: (cosmetic) remove superfluous parenthesis
2013-09-12 12:36 [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements Guennadi Liakhovetski
@ 2013-09-12 12:36 ` Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 2/5] i2c: rcar: get clock rate only once and simplify calculation Guennadi Liakhovetski
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2013-09-12 12:36 UTC (permalink / raw)
To: linux-i2c
Cc: Magnus Damm, linux-sh, Wolfram Sang, devicetree, Grant Likely,
Rob Herring, Guennadi Liakhovetski
A recent patch added even more superfluous parenthesis to those, which
already were there. Remove them again.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
---
drivers/i2c/busses/i2c-rcar.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index d2fe11d..15eef94 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -306,7 +306,7 @@ scgd_find:
/*
* keep icccr value
*/
- priv->icccr = (scgd << (cdf_width) | cdf);
+ priv->icccr = scgd << cdf_width | cdf;
return 0;
}
--
1.7.2.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/5] i2c: rcar: get clock rate only once and simplify calculation
2013-09-12 12:36 [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 1/5] i2c: rcar: (cosmetic) remove superfluous parenthesis Guennadi Liakhovetski
@ 2013-09-12 12:36 ` Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 3/5] i2c: rcar: add Device Tree support Guennadi Liakhovetski
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2013-09-12 12:36 UTC (permalink / raw)
To: linux-i2c
Cc: Magnus Damm, linux-sh, Wolfram Sang, devicetree, Grant Likely,
Rob Herring, Guennadi Liakhovetski
There is no need to repeatedly query clock frequency, where it is not
expected to change. The complete loop can also trivially be replaced with
a simple division. A further loop below the one, being simplified, could
also be replaced, but that would get more complicated.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
---
drivers/i2c/busses/i2c-rcar.c | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 15eef94..9325db4 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -231,6 +231,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
u32 round, ick;
u32 scl;
u32 cdf_width;
+ unsigned long rate;
if (!clkp) {
dev_err(dev, "there is no peripheral_clk\n");
@@ -264,15 +265,14 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
* clkp : peripheral_clk
* F[] : integer up-valuation
*/
- for (cdf = 0; cdf < (1 << cdf_width); cdf++) {
- ick = clk_get_rate(clkp) / (1 + cdf);
- if (ick < 20000000)
- goto ick_find;
+ rate = clk_get_rate(clkp);
+ cdf = rate / 20000000;
+ if (cdf >= 1 << cdf_width) {
+ dev_err(dev, "Input clock %lu too high\n", rate);
+ return -EIO;
}
- dev_err(dev, "there is no best CDF\n");
- return -EIO;
+ ick = rate / (cdf + 1);
-ick_find:
/*
* it is impossible to calculate large scale
* number on u32. separate it
@@ -290,6 +290,12 @@ ick_find:
*
* Calculation result (= SCL) should be less than
* bus_speed for hardware safety
+ *
+ * We could use something along the lines of
+ * div = ick / (bus_speed + 1) + 1;
+ * scgd = (div - 20 - round + 7) / 8;
+ * scl = ick / (20 + (scgd * 8) + round);
+ * (not fully verified) but that would get pretty involved
*/
for (scgd = 0; scgd < 0x40; scgd++) {
scl = ick / (20 + (scgd * 8) + round);
--
1.7.2.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/5] i2c: rcar: add Device Tree support
2013-09-12 12:36 [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 1/5] i2c: rcar: (cosmetic) remove superfluous parenthesis Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 2/5] i2c: rcar: get clock rate only once and simplify calculation Guennadi Liakhovetski
@ 2013-09-12 12:36 ` Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 4/5] i2c: rcar: fix clk_get() error handling Guennadi Liakhovetski
[not found] ` <1378989408-10618-1-git-send-email-g.liakhovetski-Mmb7MZpHnFY@public.gmane.org>
4 siblings, 0 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2013-09-12 12:36 UTC (permalink / raw)
To: linux-i2c
Cc: Magnus Damm, linux-sh, Wolfram Sang, devicetree, Grant Likely,
Rob Herring, Guennadi Liakhovetski
This patch adds Device Tree support to the i2c-rcar driver and respective
documentation.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
---
v2: change compatibility string to the common <unit>-<soc> format
Documentation/devicetree/bindings/i2c/i2c-rcar.txt | 22 ++++++++++++++++++++
drivers/i2c/busses/i2c-rcar.c | 21 +++++++++++++++++-
2 files changed, 41 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,23 @@
+I2C for R-Car platforms
+
+Required properties:
+- compatible: Must be one of
+ "renesas,i2c-rcar"
+ "renesas,i2c-r8a7778"
+ "renesas,i2c-r8a7779"
+ "renesas,i2c-r8a7790"
+- 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..1f285a3 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,15 @@ 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-r8a7778", .data = (void *)I2C_RCAR_H1 },
+ { .compatible = "renesas,i2c-r8a7779", .data = (void *)I2C_RCAR_H1 },
+ { .compatible = "renesas,i2c-r8a7790", .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 +665,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 +694,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 +742,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,
--
1.7.2.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/5] i2c: rcar: fix clk_get() error handling
2013-09-12 12:36 [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements Guennadi Liakhovetski
` (2 preceding siblings ...)
2013-09-12 12:36 ` [PATCH v2 3/5] i2c: rcar: add Device Tree support Guennadi Liakhovetski
@ 2013-09-12 12:36 ` Guennadi Liakhovetski
[not found] ` <1378989408-10618-1-git-send-email-g.liakhovetski-Mmb7MZpHnFY@public.gmane.org>
4 siblings, 0 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2013-09-12 12:36 UTC (permalink / raw)
To: linux-i2c
Cc: Magnus Damm, linux-sh, Wolfram Sang, devicetree, Grant Likely,
Rob Herring, Guennadi Liakhovetski
When clk_get() fails, it returns an error code, not a NULL. This patch
fixes such an error handling bug.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
---
drivers/i2c/busses/i2c-rcar.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 1f285a3..98276eb 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -234,9 +234,9 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
u32 cdf_width;
unsigned long rate;
- if (!clkp) {
- dev_err(dev, "there is no peripheral_clk\n");
- return -EIO;
+ if (IS_ERR(clkp)) {
+ dev_err(dev, "couldn't get clock\n");
+ return PTR_ERR(clkp);
}
switch (priv->devtype) {
--
1.7.2.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 5/5] i2c: rcar: use per-device clock
[not found] ` <1378989408-10618-1-git-send-email-g.liakhovetski-Mmb7MZpHnFY@public.gmane.org>
@ 2013-09-12 12:36 ` Guennadi Liakhovetski
2013-09-27 16:42 ` [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements Wolfram Sang
1 sibling, 0 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2013-09-12 12:36 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: Magnus Damm, linux-sh-u79uwXL29TY76Z2rM5mHXA, Wolfram Sang,
devicetree-u79uwXL29TY76Z2rM5mHXA, Grant Likely, Rob Herring,
Guennadi Liakhovetski
Using the same clock for all device instances is non-portable and obtaining
clock references by an ID without using a device pointer is discouraged.
This is also not needed, because on platforms, where this driver is used,
suitable clocks are available for the I2C controllers, that are children of
the peripheral clock and just pass its rate 1-to-1 to controllers. This
patch switches the driver to obtain references to correct clocks.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/i2c/busses/i2c-rcar.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 98276eb..8603f5e 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -227,7 +227,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
u32 bus_speed,
struct device *dev)
{
- struct clk *clkp = clk_get(NULL, "peripheral_clk");
+ struct clk *clkp = clk_get(dev, NULL);
u32 scgd, cdf;
u32 round, ick;
u32 scl;
--
1.7.2.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements
[not found] ` <1378989408-10618-1-git-send-email-g.liakhovetski-Mmb7MZpHnFY@public.gmane.org>
2013-09-12 12:36 ` [PATCH v2 5/5] i2c: rcar: use per-device clock Guennadi Liakhovetski
@ 2013-09-27 16:42 ` Wolfram Sang
1 sibling, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2013-09-27 16:42 UTC (permalink / raw)
To: Guennadi Liakhovetski
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Magnus Damm,
linux-sh-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA, Grant Likely, Rob Herring,
Guennadi Liakhovetski
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
On Thu, Sep 12, 2013 at 02:36:43PM +0200, Guennadi Liakhovetski wrote:
> Device Tree support for i2c-rcar isn't too complex, only usual or standard
> properties are used. Apart from it several clock handling improvements are
> included in this patch series.
>
> Developed on top of -next of 12.09.2013
>
> v2: only DT compatibility strings have been changed.
Applied to for-next, thanks!
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-09-27 16:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-12 12:36 [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 1/5] i2c: rcar: (cosmetic) remove superfluous parenthesis Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 2/5] i2c: rcar: get clock rate only once and simplify calculation Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 3/5] i2c: rcar: add Device Tree support Guennadi Liakhovetski
2013-09-12 12:36 ` [PATCH v2 4/5] i2c: rcar: fix clk_get() error handling Guennadi Liakhovetski
[not found] ` <1378989408-10618-1-git-send-email-g.liakhovetski-Mmb7MZpHnFY@public.gmane.org>
2013-09-12 12:36 ` [PATCH v2 5/5] i2c: rcar: use per-device clock Guennadi Liakhovetski
2013-09-27 16:42 ` [PATCH v2 0/5] i2c: rcar: Device Tree support and clock improvements Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).