[parent not found: <1449157899-6572-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>]
* [PATCH 1/9] i2c: document generic DT bindings for timing parameters
[not found] ` <1449157899-6572-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-03 20:39 ` Rob Herring
0 siblings, 1 reply; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: linux-sh-u79uwXL29TY76Z2rM5mHXA, Magnus Damm, Simon Horman,
Laurent Pinchart, Geert Uytterhoeven, Wolfram Sang,
Yoshihiro Shimoda,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Mika Westerberg,
Andy Shevchenko, Jarkko Nikula, devicetree-u79uwXL29TY76Z2rM5mHXA
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Also, sort the properties alphabetically and make indentation
consistent. Wording largely taken from i2c-rk3x.txt, thanks guys!
Only "i2c-scl-internal-delay-ns" is new, the rest is used by two drivers
already and was documented in their driver binding documentation.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: devicetree@vger.kernel.org
---
Documentation/devicetree/bindings/i2c/i2c.txt | 31 ++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt
index 8a99150ac3a7fd..a00219f5ee0733 100644
--- a/Documentation/devicetree/bindings/i2c/i2c.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c.txt
@@ -29,12 +29,33 @@ Optional properties
These properties may not be supported by all drivers. However, if a driver
wants to support one of the below features, it should adapt the bindings below.
-- clock-frequency - frequency of bus clock in Hz.
-- wakeup-source - device can be used as a wakeup source.
+- clock-frequency
+ frequency of bus clock in Hz.
-- interrupts - interrupts used by the device.
-- interrupt-names - "irq" and "wakeup" names are recognized by I2C core,
- other names are left to individual drivers.
+- i2c-scl-falling-time-ns
+ Number of nanoseconds the SCL signal takes to fall; t(f) in the I2C
+ specification.
+
+- i2c-scl-internal-delay-ns
+ Number of nanoseconds the IP core additionally needs to setup SCL.
+
+- i2c-scl-rising-time-ns
+ Number of nanoseconds the SCL signal takes to rise; t(r) in the I2C
+ specification.
+
+- i2c-sda-falling-time-ns
+ Number of nanoseconds the SDA signal takes to fall; t(f) in the I2C
+ specification.
+
+- interrupts
+ interrupts used by the device.
+
+- interrupt-names
+ "irq" and "wakeup" names are recognized by I2C core, other names are
+ left to individual drivers.
+
+- wakeup-source
+ device can be used as a wakeup source.
Binding may contain optional "interrupts" property, describing interrupts
used by the device. I2C core will assign "irq" interrupt (or the very first
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 1/9] i2c: document generic DT bindings for timing parameters
2015-12-03 15:51 ` [PATCH 1/9] i2c: document generic DT bindings for timing parameters Wolfram Sang
@ 2015-12-03 20:39 ` Rob Herring
0 siblings, 0 replies; 14+ messages in thread
From: Rob Herring @ 2015-12-03 20:39 UTC (permalink / raw)
To: Wolfram Sang
Cc: linux-i2c, linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Yoshihiro Shimoda, linux-rockchip,
Mika Westerberg, Andy Shevchenko, Jarkko Nikula, devicetree
On Thu, Dec 03, 2015 at 04:51:31PM +0100, Wolfram Sang wrote:
> From: Wolfram Sang <wsa+renesas@sang-engineering.com>
>
> Also, sort the properties alphabetically and make indentation
> consistent. Wording largely taken from i2c-rk3x.txt, thanks guys!
>
> Only "i2c-scl-internal-delay-ns" is new, the rest is used by two drivers
> already and was documented in their driver binding documentation.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Cc: devicetree@vger.kernel.org
Acked-by: Rob Herring <robh@kernel.org>
> ---
> Documentation/devicetree/bindings/i2c/i2c.txt | 31 ++++++++++++++++++++++-----
> 1 file changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt
> index 8a99150ac3a7fd..a00219f5ee0733 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c.txt
> @@ -29,12 +29,33 @@ Optional properties
> These properties may not be supported by all drivers. However, if a driver
> wants to support one of the below features, it should adapt the bindings below.
>
> -- clock-frequency - frequency of bus clock in Hz.
> -- wakeup-source - device can be used as a wakeup source.
> +- clock-frequency
> + frequency of bus clock in Hz.
>
> -- interrupts - interrupts used by the device.
> -- interrupt-names - "irq" and "wakeup" names are recognized by I2C core,
> - other names are left to individual drivers.
> +- i2c-scl-falling-time-ns
> + Number of nanoseconds the SCL signal takes to fall; t(f) in the I2C
> + specification.
> +
> +- i2c-scl-internal-delay-ns
> + Number of nanoseconds the IP core additionally needs to setup SCL.
> +
> +- i2c-scl-rising-time-ns
> + Number of nanoseconds the SCL signal takes to rise; t(r) in the I2C
> + specification.
> +
> +- i2c-sda-falling-time-ns
> + Number of nanoseconds the SDA signal takes to fall; t(f) in the I2C
> + specification.
> +
> +- interrupts
> + interrupts used by the device.
> +
> +- interrupt-names
> + "irq" and "wakeup" names are recognized by I2C core, other names are
> + left to individual drivers.
> +
> +- wakeup-source
> + device can be used as a wakeup source.
>
> Binding may contain optional "interrupts" property, describing interrupts
> used by the device. I2C core will assign "irq" interrupt (or the very first
> --
> 2.1.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/9] i2c: add generic routine to parse DT for timing information
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
[not found] ` <1449157899-6572-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-04 8:34 ` Mika Westerberg
2015-12-03 15:51 ` [PATCH 3/9] i2c: rcar: refactor probe function a little Wolfram Sang
` (7 subsequent siblings)
9 siblings, 1 reply; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Inspired from the i2c-rk3x driver (thanks guys!) but refactored and
extended. See built-in docs for further information.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/i2c-core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/i2c.h | 22 ++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index ba8eb087f22465..5c269dd51b2de7 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1438,6 +1438,56 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
}
}
+/**
+ * of_i2c_parse_timings - get I2C related timing parameters from DT
+ * @node: The DT node to scan for I2C timing properties
+ * @t: the i2c_timings struct to be filled with values
+ * @use_defaults: bool to use sane defaults derived from the I2C specification
+ * when properties are not found, otherwise use 0
+ *
+ * Scan the node pointer for the generic I2C DT properties describing timing
+ * parameters for the signal and fill the given struct with the results. If a
+ * property was not found and use_defaults was true, then maximum timings are
+ * assumed which are derived from the I2C specification. If use_defaults is not
+ * used, the result will be 0, so drivers can apply their own defaults later.
+ * The latter is mainly intended for avoiding regressions of existing drivers
+ * which want to switch to this function. New drivers almost always should use
+ * the defaults.
+ */
+void of_i2c_parse_timings(struct device_node *node, struct i2c_timings *t, bool use_defaults)
+{
+ memset(t, 0, sizeof(*t));
+
+ if (of_property_read_u32(node, "clock-frequency", &t->bus_freq_hz) && use_defaults)
+ t->bus_freq_hz = 100000;
+
+ /*
+ * Read rise and fall time from device tree. If not available, use
+ * the default maximum timing from the specification.
+ */
+ if (of_property_read_u32(node, "i2c-scl-rising-time-ns", &t->scl_rise_ns) && use_defaults) {
+ if (t->bus_freq_hz <= 100000)
+ t->scl_rise_ns = 1000;
+ else if (t->bus_freq_hz <= 400000)
+ t->scl_rise_ns = 300;
+ else
+ t->scl_rise_ns = 120;
+ }
+
+ if (of_property_read_u32(node, "i2c-scl-falling-time-ns", &t->scl_fall_ns) && use_defaults) {
+ if (t->bus_freq_hz <= 400000)
+ t->scl_fall_ns = 300;
+ else
+ t->scl_fall_ns = 120;
+ }
+
+ of_property_read_u32(node, "i2c-scl-internal-delay-ns", &t->scl_int_delay_ns);
+
+ if (of_property_read_u32(node, "i2c-sda-falling-time-ns", &t->sda_fall_ns) && use_defaults)
+ t->sda_fall_ns = t->scl_fall_ns;
+}
+EXPORT_SYMBOL_GPL(of_i2c_parse_timings);
+
static int of_dev_node_match(struct device *dev, void *data)
{
return dev->of_node = data;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 768063baafbf5e..c3f53666df117e 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -414,6 +414,22 @@ struct i2c_algorithm {
};
/**
+ * struct i2c_timings - I2C timing information
+ * @bus_freq_hz: the bus frequency in Hz
+ * @scl_rise_ns: time SCL signal takes to rise in ns; t(r) in the I2C specification
+ * @scl_fall_ns: time SCL signal takes to fall in ns; t(f) in the I2C specification
+ * @scl_int_delay_ns: time IP core additionally needs to setup SCL in ns
+ * @sda_fall_ns: time SDA signal takes to fall in ns; t(f) in the I2C specification
+ */
+struct i2c_timings {
+ u32 bus_freq_hz;
+ u32 scl_rise_ns;
+ u32 scl_fall_ns;
+ u32 scl_int_delay_ns;
+ u32 sda_fall_ns;
+};
+
+/**
* struct i2c_bus_recovery_info - I2C bus recovery information
* @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or
* i2c_generic_scl_recovery() or i2c_generic_gpio_recovery().
@@ -644,6 +660,8 @@ extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
/* must call i2c_put_adapter() when done with returned i2c_adapter device */
struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
+
+void of_i2c_parse_timings(struct device_node *node, struct i2c_timings *t, bool use_defaults);
#else
static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
@@ -660,6 +678,10 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node
{
return NULL;
}
+
+static inline void of_i2c_parse_timings(struct device_node *node, struct i2c_timings *t, bool use_defaults)
+{
+}
#endif /* CONFIG_OF */
#endif /* _LINUX_I2C_H */
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 2/9] i2c: add generic routine to parse DT for timing information
2015-12-03 15:51 ` [PATCH 2/9] i2c: add generic routine to parse DT for timing information Wolfram Sang
@ 2015-12-04 8:34 ` Mika Westerberg
2015-12-04 8:41 ` Wolfram Sang
0 siblings, 1 reply; 14+ messages in thread
From: Mika Westerberg @ 2015-12-04 8:34 UTC (permalink / raw)
To: Wolfram Sang
Cc: linux-i2c, linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Yoshihiro Shimoda, linux-rockchip,
Andy Shevchenko, Jarkko Nikula
On Thu, Dec 03, 2015 at 04:51:32PM +0100, Wolfram Sang wrote:
> From: Wolfram Sang <wsa+renesas@sang-engineering.com>
>
> Inspired from the i2c-rk3x driver (thanks guys!) but refactored and
> extended. See built-in docs for further information.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> drivers/i2c/i2c-core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/i2c.h | 22 ++++++++++++++++++++++
> 2 files changed, 72 insertions(+)
>
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index ba8eb087f22465..5c269dd51b2de7 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -1438,6 +1438,56 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
> }
> }
>
> +/**
> + * of_i2c_parse_timings - get I2C related timing parameters from DT
> + * @node: The DT node to scan for I2C timing properties
> + * @t: the i2c_timings struct to be filled with values
> + * @use_defaults: bool to use sane defaults derived from the I2C specification
> + * when properties are not found, otherwise use 0
> + *
> + * Scan the node pointer for the generic I2C DT properties describing timing
> + * parameters for the signal and fill the given struct with the results. If a
> + * property was not found and use_defaults was true, then maximum timings are
> + * assumed which are derived from the I2C specification. If use_defaults is not
> + * used, the result will be 0, so drivers can apply their own defaults later.
> + * The latter is mainly intended for avoiding regressions of existing drivers
> + * which want to switch to this function. New drivers almost always should use
> + * the defaults.
> + */
> +void of_i2c_parse_timings(struct device_node *node, struct i2c_timings *t, bool use_defaults)
> +{
> + memset(t, 0, sizeof(*t));
> +
> + if (of_property_read_u32(node, "clock-frequency", &t->bus_freq_hz) && use_defaults)
> + t->bus_freq_hz = 100000;
Why not create device_i2c_parse_timings() instead and use unified device
properties API?
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 2/9] i2c: add generic routine to parse DT for timing information
2015-12-04 8:34 ` Mika Westerberg
@ 2015-12-04 8:41 ` Wolfram Sang
0 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-04 8:41 UTC (permalink / raw)
To: Mika Westerberg
Cc: linux-i2c, linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Yoshihiro Shimoda, linux-rockchip,
Andy Shevchenko, Jarkko Nikula
[-- Attachment #1: Type: text/plain, Size: 398 bytes --]
> > +void of_i2c_parse_timings(struct device_node *node, struct i2c_timings *t, bool use_defaults)
> > +{
> > + memset(t, 0, sizeof(*t));
> > +
> > + if (of_property_read_u32(node, "clock-frequency", &t->bus_freq_hz) && use_defaults)
> > + t->bus_freq_hz = 100000;
>
> Why not create device_i2c_parse_timings() instead and use unified device
> properties API?
Sure, just missed it.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/9] i2c: rcar: refactor probe function a little
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
[not found] ` <1449157899-6572-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2015-12-03 15:51 ` [PATCH 2/9] i2c: add generic routine to parse DT for timing information Wolfram Sang
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-03 15:51 ` [PATCH 4/9] i2c: rcar: switch to i2c generic dt parsing Wolfram Sang
` (6 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
The probe function is a little bit messy, something here, something
there. Rework it so that there is some order: first init the private
structure, then the adapter, then do HW init. This also allows us to
remove the device argument of the clock calculation function, because it
now can be deduced from the private structure. Also, shorten some lines
where possible. This is a preparation for further refactoring.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/busses/i2c-rcar.c | 40 +++++++++++++++++-----------------------
1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 3ed1f0aa5eeb16..d4322a9096786f 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -162,15 +162,11 @@ static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv)
return -EBUSY;
}
-static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
- u32 bus_speed,
- struct device *dev)
+static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, u32 bus_speed)
{
- u32 scgd, cdf;
- u32 round, ick;
- u32 scl;
- u32 cdf_width;
+ u32 scgd, cdf, round, ick, scl, cdf_width;
unsigned long rate;
+ struct device *dev = rcar_i2c_priv_to_dev(priv);
switch (priv->devtype) {
case I2C_RCAR_GEN1:
@@ -610,21 +606,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
if (IS_ERR(priv->io))
return PTR_ERR(priv->io);
- bus_speed = 100000; /* default 100 kHz */
- of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed);
-
priv->devtype = (enum rcar_i2c_type)of_match_device(rcar_i2c_dt_ids, dev)->data;
-
- pm_runtime_enable(dev);
- pm_runtime_get_sync(dev);
- ret = rcar_i2c_clock_calculate(priv, bus_speed, dev);
- if (ret < 0)
- goto out_pm_put;
-
- rcar_i2c_init(priv);
- pm_runtime_put(dev);
-
- irq = platform_get_irq(pdev, 0);
init_waitqueue_head(&priv->wait);
adap = &priv->adap;
@@ -637,8 +619,20 @@ static int rcar_i2c_probe(struct platform_device *pdev)
i2c_set_adapdata(adap, priv);
strlcpy(adap->name, pdev->name, sizeof(adap->name));
- ret = devm_request_irq(dev, irq, rcar_i2c_irq, 0,
- dev_name(dev), priv);
+ bus_speed = 100000; /* default 100 kHz */
+ of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed);
+
+ pm_runtime_enable(dev);
+ pm_runtime_get_sync(dev);
+ ret = rcar_i2c_clock_calculate(priv, bus_speed);
+ if (ret < 0)
+ goto out_pm_put;
+
+ rcar_i2c_init(priv);
+ pm_runtime_put(dev);
+
+ irq = platform_get_irq(pdev, 0);
+ ret = devm_request_irq(dev, irq, rcar_i2c_irq, 0, dev_name(dev), priv);
if (ret < 0) {
dev_err(dev, "cannot get irq %d\n", irq);
goto out_pm_disable;
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 4/9] i2c: rcar: switch to i2c generic dt parsing
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
` (2 preceding siblings ...)
2015-12-03 15:51 ` [PATCH 3/9] i2c: rcar: refactor probe function a little Wolfram Sang
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-03 15:51 ` [PATCH 5/9] i2c: rcar: honor additional i2c timings from DT Wolfram Sang
` (5 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Switch to the new generic functions. Plain convert, no functionality
added yet.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/busses/i2c-rcar.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index d4322a9096786f..05274fda57eb08 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -162,12 +162,15 @@ static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv)
return -EBUSY;
}
-static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, u32 bus_speed)
+static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timings *t)
{
u32 scgd, cdf, round, ick, scl, cdf_width;
unsigned long rate;
struct device *dev = rcar_i2c_priv_to_dev(priv);
+ /* Fall back to previously used values if not supplied */
+ t->bus_freq_hz = t->bus_freq_hz ?: 100000;
+
switch (priv->devtype) {
case I2C_RCAR_GEN1:
cdf_width = 2;
@@ -230,7 +233,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, u32 bus_speed)
*/
for (scgd = 0; scgd < 0x40; scgd++) {
scl = ick / (20 + (scgd * 8) + round);
- if (scl <= bus_speed)
+ if (scl <= t->bus_freq_hz)
goto scgd_find;
}
dev_err(dev, "it is impossible to calculate best SCL\n");
@@ -238,7 +241,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, u32 bus_speed)
scgd_find:
dev_dbg(dev, "clk %d/%d(%lu), round %u, CDF:0x%x, SCGD: 0x%x\n",
- scl, bus_speed, clk_get_rate(priv->clk), round, cdf, scgd);
+ scl, t->bus_freq_hz, clk_get_rate(priv->clk), round, cdf, scgd);
/* keep icccr value */
priv->icccr = scgd << cdf_width | cdf;
@@ -588,7 +591,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
struct i2c_adapter *adap;
struct resource *res;
struct device *dev = &pdev->dev;
- u32 bus_speed;
+ struct i2c_timings i2c_t;
int irq, ret;
priv = devm_kzalloc(dev, sizeof(struct rcar_i2c_priv), GFP_KERNEL);
@@ -619,12 +622,11 @@ static int rcar_i2c_probe(struct platform_device *pdev)
i2c_set_adapdata(adap, priv);
strlcpy(adap->name, pdev->name, sizeof(adap->name));
- bus_speed = 100000; /* default 100 kHz */
- of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed);
+ of_i2c_parse_timings(dev->of_node, &i2c_t, false);
pm_runtime_enable(dev);
pm_runtime_get_sync(dev);
- ret = rcar_i2c_clock_calculate(priv, bus_speed);
+ ret = rcar_i2c_clock_calculate(priv, &i2c_t);
if (ret < 0)
goto out_pm_put;
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 5/9] i2c: rcar: honor additional i2c timings from DT
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
` (3 preceding siblings ...)
2015-12-03 15:51 ` [PATCH 4/9] i2c: rcar: switch to i2c generic dt parsing Wolfram Sang
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-03 15:51 ` [PATCH 6/9] ARM: shmobile: r8a7790: dtsi: add internal delay for i2c IPs Wolfram Sang
` (4 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Documentation/devicetree/bindings/i2c/i2c-rcar.txt | 4 ++++
drivers/i2c/busses/i2c-rcar.c | 21 ++++++++++++---------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
index ea406eb20fa5ad..95e97223a71c83 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
@@ -20,6 +20,10 @@ Optional properties:
propoerty indicates the default frequency 100 kHz.
- clocks: clock specifier.
+- i2c-scl-falling-time-ns: see i2c.txt
+- i2c-scl-internal-delay-ns: see i2c.txt
+- i2c-scl-rising-time-ns: see i2c.txt
+
Examples :
i2c0: i2c@e6508000 {
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 05274fda57eb08..cd1796e51764ee 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -164,12 +164,15 @@ static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv)
static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timings *t)
{
- u32 scgd, cdf, round, ick, scl, cdf_width;
+ u32 scgd, cdf, round, ick, sum, scl, cdf_width;
unsigned long rate;
struct device *dev = rcar_i2c_priv_to_dev(priv);
/* Fall back to previously used values if not supplied */
t->bus_freq_hz = t->bus_freq_hz ?: 100000;
+ t->scl_fall_ns = t->scl_fall_ns ?: 35;
+ t->scl_rise_ns = t->scl_rise_ns ?: 200;
+ t->scl_int_delay_ns = t->scl_int_delay_ns ?: 50;
switch (priv->devtype) {
case I2C_RCAR_GEN1:
@@ -193,9 +196,9 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timin
* SCL = ick / (20 + SCGD * 8 + F[(ticf + tr + intd) * ick])
*
* ick : I2C internal clock < 20 MHz
- * ticf : I2C SCL falling time = 35 ns here
- * tr : I2C SCL rising time = 200 ns here
- * intd : LSI internal delay = 50 ns here
+ * ticf : I2C SCL falling time
+ * tr : I2C SCL rising time
+ * intd : LSI internal delay
* clkp : peripheral_clk
* F[] : integer up-valuation
*/
@@ -211,12 +214,12 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timin
* it is impossible to calculate large scale
* number on u32. separate it
*
- * F[(ticf + tr + intd) * ick]
- * = F[(35 + 200 + 50)ns * ick]
- * = F[285 * ick / 1000000000]
- * = F[(ick / 1000000) * 285 / 1000]
+ * F[(ticf + tr + intd) * ick] with sum = (ticf + tr + intd)
+ * = F[sum * ick / 1000000000]
+ * = F[(ick / 1000000) * sum / 1000]
*/
- round = (ick + 500000) / 1000000 * 285;
+ sum = t->scl_fall_ns + t->scl_rise_ns + t->scl_int_delay_ns;
+ round = (ick + 500000) / 1000000 * sum;
round = (round + 500) / 1000;
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 6/9] ARM: shmobile: r8a7790: dtsi: add internal delay for i2c IPs
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
` (4 preceding siblings ...)
2015-12-03 15:51 ` [PATCH 5/9] i2c: rcar: honor additional i2c timings from DT Wolfram Sang
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-03 15:51 ` [PATCH 7/9] ARM: shmobile: r8a7791: " Wolfram Sang
` (3 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
arch/arm/boot/dts/r8a7790.dtsi | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm/boot/dts/r8a7790.dtsi b/arch/arm/boot/dts/r8a7790.dtsi
index 6cfd0dc79bbec0..64a3f4a05f36d0 100644
--- a/arch/arm/boot/dts/r8a7790.dtsi
+++ b/arch/arm/boot/dts/r8a7790.dtsi
@@ -417,6 +417,7 @@
interrupts = <0 287 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7790_CLK_I2C0>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <110>;
status = "disabled";
};
@@ -428,6 +429,7 @@
interrupts = <0 288 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7790_CLK_I2C1>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -439,6 +441,7 @@
interrupts = <0 286 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7790_CLK_I2C2>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -450,6 +453,7 @@
interrupts = <0 290 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7790_CLK_I2C3>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <110>;
status = "disabled";
};
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 7/9] ARM: shmobile: r8a7791: dtsi: add internal delay for i2c IPs
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
` (5 preceding siblings ...)
2015-12-03 15:51 ` [PATCH 6/9] ARM: shmobile: r8a7790: dtsi: add internal delay for i2c IPs Wolfram Sang
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-03 15:51 ` [PATCH 8/9] ARM: shmobile: r8a7794: " Wolfram Sang
` (2 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
arch/arm/boot/dts/r8a7791.dtsi | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm/boot/dts/r8a7791.dtsi b/arch/arm/boot/dts/r8a7791.dtsi
index 76b33e895513c1..3161dfcdd002dd 100644
--- a/arch/arm/boot/dts/r8a7791.dtsi
+++ b/arch/arm/boot/dts/r8a7791.dtsi
@@ -407,6 +407,7 @@
interrupts = <0 287 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7791_CLK_I2C0>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -418,6 +419,7 @@
interrupts = <0 288 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7791_CLK_I2C1>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -429,6 +431,7 @@
interrupts = <0 286 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7791_CLK_I2C2>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -440,6 +443,7 @@
interrupts = <0 290 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7791_CLK_I2C3>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -451,6 +455,7 @@
interrupts = <0 19 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7791_CLK_I2C4>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -463,6 +468,7 @@
interrupts = <0 20 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&mstp9_clks R8A7791_CLK_I2C5>;
power-domains = <&cpg_clocks>;
+ i2c-scl-internal-delay-ns = <110>;
status = "disabled";
};
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 8/9] ARM: shmobile: r8a7794: dtsi: add internal delay for i2c IPs
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
` (6 preceding siblings ...)
2015-12-03 15:51 ` [PATCH 7/9] ARM: shmobile: r8a7791: " Wolfram Sang
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-03 15:51 ` [PATCH 9/9] arm64: renesas: r8a7795: " Wolfram Sang
2015-12-07 6:39 ` [PATCH 0/9] i2c: add generic support for timing parameters in DT Simon Horman
9 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
arch/arm/boot/dts/r8a7794.dtsi | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm/boot/dts/r8a7794.dtsi b/arch/arm/boot/dts/r8a7794.dtsi
index 6f2f01914db295..37809b8aae65f9 100644
--- a/arch/arm/boot/dts/r8a7794.dtsi
+++ b/arch/arm/boot/dts/r8a7794.dtsi
@@ -519,6 +519,7 @@
power-domains = <&cpg_clocks>;
#address-cells = <1>;
#size-cells = <0>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -530,6 +531,7 @@
power-domains = <&cpg_clocks>;
#address-cells = <1>;
#size-cells = <0>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -541,6 +543,7 @@
power-domains = <&cpg_clocks>;
#address-cells = <1>;
#size-cells = <0>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -552,6 +555,7 @@
power-domains = <&cpg_clocks>;
#address-cells = <1>;
#size-cells = <0>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -563,6 +567,7 @@
power-domains = <&cpg_clocks>;
#address-cells = <1>;
#size-cells = <0>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -574,6 +579,7 @@
power-domains = <&cpg_clocks>;
#address-cells = <1>;
#size-cells = <0>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 9/9] arm64: renesas: r8a7795: add internal delay for i2c IPs
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
` (7 preceding siblings ...)
2015-12-03 15:51 ` [PATCH 8/9] ARM: shmobile: r8a7794: " Wolfram Sang
@ 2015-12-03 15:51 ` Wolfram Sang
2015-12-07 6:39 ` [PATCH 0/9] i2c: add generic support for timing parameters in DT Simon Horman
9 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2015-12-03 15:51 UTC (permalink / raw)
To: linux-i2c
Cc: linux-sh, Magnus Damm, Simon Horman, Laurent Pinchart,
Geert Uytterhoeven, Wolfram Sang, Yoshihiro Shimoda,
linux-rockchip, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
arch/arm64/boot/dts/renesas/r8a7795.dtsi | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 56d6a5b23a4e38..b02a7ad1583933 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -519,6 +519,7 @@
interrupts = <GIC_SPI 287 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 931>;
power-domains = <&cpg>;
+ i2c-scl-internal-delay-ns = <110>;
status = "disabled";
};
@@ -530,6 +531,7 @@
interrupts = <GIC_SPI 288 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 930>;
power-domains = <&cpg>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -541,6 +543,7 @@
interrupts = <GIC_SPI 286 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 929>;
power-domains = <&cpg>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
@@ -552,6 +555,7 @@
interrupts = <GIC_SPI 290 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 928>;
power-domains = <&cpg>;
+ i2c-scl-internal-delay-ns = <110>;
status = "disabled";
};
@@ -563,6 +567,7 @@
interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 927>;
power-domains = <&cpg>;
+ i2c-scl-internal-delay-ns = <110>;
status = "disabled";
};
@@ -574,6 +579,7 @@
interrupts = <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 919>;
power-domains = <&cpg>;
+ i2c-scl-internal-delay-ns = <110>;
status = "disabled";
};
@@ -585,6 +591,7 @@
interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 918>;
power-domains = <&cpg>;
+ i2c-scl-internal-delay-ns = <6>;
status = "disabled";
};
--
2.1.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 0/9] i2c: add generic support for timing parameters in DT
2015-12-03 15:51 [PATCH 0/9] i2c: add generic support for timing parameters in DT Wolfram Sang
` (8 preceding siblings ...)
2015-12-03 15:51 ` [PATCH 9/9] arm64: renesas: r8a7795: " Wolfram Sang
@ 2015-12-07 6:39 ` Simon Horman
9 siblings, 0 replies; 14+ messages in thread
From: Simon Horman @ 2015-12-07 6:39 UTC (permalink / raw)
To: Wolfram Sang
Cc: linux-i2c, linux-sh, Magnus Damm, Laurent Pinchart,
Geert Uytterhoeven, Yoshihiro Shimoda, linux-rockchip,
Mika Westerberg, Andy Shevchenko, Jarkko Nikula
On Thu, Dec 03, 2015 at 04:51:30PM +0100, Wolfram Sang wrote:
> Here is a patch series adding better DT support for timing parameters like the
> raise time or the fall time which are generic for the I2C subsystem. There is a
> core function for parsing and an implementation for the RCar driver how to use
> it.
>
> I added people of the designware and rk3x driver to CC because they might be
> interested in this new function. They provided the basis for this series, so it
> should be easy to convert them.
>
> Please have a look, test, comment...
>
> Thanks,
>
> Wolfram
>
>
> Changes since RFC:
> * better tested
> * added documentation for the new function and the new struct
> * reworded some commit messages slightly
> * moved the new property in the dtsi above the "status" property
>
>
> Wolfram Sang (9):
> i2c: document generic DT bindings for timing parameters
> i2c: add generic routine to parse DT for timing information
> i2c: rcar: refactor probe function a little
> i2c: rcar: switch to i2c generic dt parsing
> i2c: rcar: honor additional i2c timings from DT
I have marked the integration patches (below) as deferred pending
acceptance of the driver changes (above). Please repost the former
once the latter have been accepted (by you :).
> ARM: shmobile: r8a7790: dtsi: add internal delay for i2c IPs
> ARM: shmobile: r8a7791: dtsi: add internal delay for i2c IPs
> ARM: shmobile: r8a7794: dtsi: add internal delay for i2c IPs
> arm64: renesas: r8a7795: add internal delay for i2c IPs
>
> Documentation/devicetree/bindings/i2c/i2c-rcar.txt | 4 ++
> Documentation/devicetree/bindings/i2c/i2c.txt | 31 ++++++++--
> arch/arm/boot/dts/r8a7790.dtsi | 4 ++
> arch/arm/boot/dts/r8a7791.dtsi | 6 ++
> arch/arm/boot/dts/r8a7794.dtsi | 6 ++
> arch/arm64/boot/dts/renesas/r8a7795.dtsi | 7 +++
> drivers/i2c/busses/i2c-rcar.c | 67 +++++++++++-----------
> drivers/i2c/i2c-core.c | 50 ++++++++++++++++
> include/linux/i2c.h | 22 +++++++
> 9 files changed, 158 insertions(+), 39 deletions(-)
>
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 14+ messages in thread