From: Linus Walleij Date: Mon, 7 Jul 2014 09:47:00 +0000 (+0100) Subject: iio: st_sensors: get platform data from device tree X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=3ce85cc4fbb71739f98806b9c9d63950a60cd8ae;p=deliverable%2Flinux.git iio: st_sensors: get platform data from device tree Currently the STMicroelectronics sensors only support one single platform data item: configuration of the DRDY (data ready) pin for a particular design. Augment the core to prioritize and take this information from the device tree if the parent device has an assigned device node, else fall back to passed in platform data (usually the default data). Cc: Lee Jones Cc: Denis CIOCCA Signed-off-by: Linus Walleij Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 30fb6407fad0..8a4ec00a91a0 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -14,8 +14,8 @@ #include #include #include +#include #include - #include @@ -265,14 +265,47 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, return 0; } +#ifdef CONFIG_OF +static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev, + struct st_sensors_platform_data *defdata) +{ + struct st_sensors_platform_data *pdata; + struct device_node *np = dev->of_node; + u32 val; + + if (!np) + return NULL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!of_property_read_u32(np, "st,drdy-int-pin", &val) && (val <= 2)) + pdata->drdy_int_pin = (u8) val; + else + pdata->drdy_int_pin = defdata ? defdata->drdy_int_pin : 1; + + return pdata; +} +#else +static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev, + struct st_sensors_platform_data *defdata) +{ + return NULL; +} +#endif + int st_sensors_init_sensor(struct iio_dev *indio_dev, struct st_sensors_platform_data *pdata) { struct st_sensor_data *sdata = iio_priv(indio_dev); + struct st_sensors_platform_data *of_pdata; int err = 0; mutex_init(&sdata->tb.buf_lock); + /* If OF/DT pdata exists, it will take precedence of anything else */ + of_pdata = st_sensors_of_probe(indio_dev->dev.parent, pdata); + if (of_pdata) + pdata = of_pdata; + if (pdata) err = st_sensors_set_drdy_int_pin(indio_dev, pdata);