[PATCH 2/9] i2c: add generic routine to parse DT for timing information
Mika Westerberg
mika.westerberg at linux.intel.com
Fri Dec 4 00:34:28 PST 2015
On Thu, Dec 03, 2015 at 04:51:32PM +0100, Wolfram Sang wrote:
> From: Wolfram Sang <wsa+renesas at 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 at 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?
More information about the Linux-rockchip
mailing list