Commit ecb27c5e authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: st_sensors: Make use of device properties

Device property API allows to gather device resources from different sources,
such as ACPI. Convert the drivers to unleash the power of device property API.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent efc78983
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include <linux/iio/common/st_sensors_i2c.h> #include <linux/iio/common/st_sensors_i2c.h>
#include "st_accel.h" #include "st_accel.h"
#ifdef CONFIG_OF
static const struct of_device_id st_accel_of_match[] = { static const struct of_device_id st_accel_of_match[] = {
{ {
/* An older compatible */ /* An older compatible */
...@@ -108,9 +107,6 @@ static const struct of_device_id st_accel_of_match[] = { ...@@ -108,9 +107,6 @@ static const struct of_device_id st_accel_of_match[] = {
{}, {},
}; };
MODULE_DEVICE_TABLE(of, st_accel_of_match); MODULE_DEVICE_TABLE(of, st_accel_of_match);
#else
#define st_accel_of_match NULL
#endif
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
static const struct acpi_device_id st_accel_acpi_match[] = { static const struct acpi_device_id st_accel_acpi_match[] = {
...@@ -193,7 +189,7 @@ static int st_accel_i2c_remove(struct i2c_client *client) ...@@ -193,7 +189,7 @@ static int st_accel_i2c_remove(struct i2c_client *client)
static struct i2c_driver st_accel_driver = { static struct i2c_driver st_accel_driver = {
.driver = { .driver = {
.name = "st-accel-i2c", .name = "st-accel-i2c",
.of_match_table = of_match_ptr(st_accel_of_match), .of_match_table = st_accel_of_match,
.acpi_match_table = ACPI_PTR(st_accel_acpi_match), .acpi_match_table = ACPI_PTR(st_accel_acpi_match),
}, },
.probe_new = st_accel_i2c_probe, .probe_new = st_accel_i2c_probe,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/iio/common/st_sensors_spi.h> #include <linux/iio/common/st_sensors_spi.h>
#include "st_accel.h" #include "st_accel.h"
#ifdef CONFIG_OF
/* /*
* For new single-chip sensors use <device_name> as compatible string. * For new single-chip sensors use <device_name> as compatible string.
* For old single-chip devices keep <device_name>-accel to maintain * For old single-chip devices keep <device_name>-accel to maintain
...@@ -96,9 +95,6 @@ static const struct of_device_id st_accel_of_match[] = { ...@@ -96,9 +95,6 @@ static const struct of_device_id st_accel_of_match[] = {
{} {}
}; };
MODULE_DEVICE_TABLE(of, st_accel_of_match); MODULE_DEVICE_TABLE(of, st_accel_of_match);
#else
#define st_accel_of_match NULL
#endif
static int st_accel_spi_probe(struct spi_device *spi) static int st_accel_spi_probe(struct spi_device *spi)
{ {
...@@ -165,7 +161,7 @@ MODULE_DEVICE_TABLE(spi, st_accel_id_table); ...@@ -165,7 +161,7 @@ MODULE_DEVICE_TABLE(spi, st_accel_id_table);
static struct spi_driver st_accel_driver = { static struct spi_driver st_accel_driver = {
.driver = { .driver = {
.name = "st-accel-spi", .name = "st-accel-spi",
.of_match_table = of_match_ptr(st_accel_of_match), .of_match_table = st_accel_of_match,
}, },
.probe = st_accel_spi_probe, .probe = st_accel_spi_probe,
.remove = st_accel_spi_remove, .remove = st_accel_spi_remove,
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/property.h> #include <linux/property.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
#include <linux/iio/common/st_sensors.h> #include <linux/iio/common/st_sensors.h>
...@@ -320,34 +318,25 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, ...@@ -320,34 +318,25 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
return 0; return 0;
} }
#ifdef CONFIG_OF static struct st_sensors_platform_data *st_sensors_dev_probe(struct device *dev,
static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
struct st_sensors_platform_data *defdata) struct st_sensors_platform_data *defdata)
{ {
struct st_sensors_platform_data *pdata; struct st_sensors_platform_data *pdata;
struct device_node *np = dev->of_node;
u32 val; u32 val;
if (!np) if (!dev_fwnode(dev))
return NULL; return NULL;
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!of_property_read_u32(np, "st,drdy-int-pin", &val) && (val <= 2)) if (!device_property_read_u32(dev, "st,drdy-int-pin", &val) && (val <= 2))
pdata->drdy_int_pin = (u8) val; pdata->drdy_int_pin = (u8) val;
else else
pdata->drdy_int_pin = defdata ? defdata->drdy_int_pin : 0; pdata->drdy_int_pin = defdata ? defdata->drdy_int_pin : 0;
pdata->open_drain = of_property_read_bool(np, "drive-open-drain"); pdata->open_drain = device_property_read_bool(dev, "drive-open-drain");
return pdata; 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
/** /**
* st_sensors_dev_name_probe() - device probe for ST sensor name * st_sensors_dev_name_probe() - device probe for ST sensor name
...@@ -381,7 +370,7 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev, ...@@ -381,7 +370,7 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev,
int err = 0; int err = 0;
/* If OF/DT pdata exists, it will take precedence of anything else */ /* If OF/DT pdata exists, it will take precedence of anything else */
of_pdata = st_sensors_of_probe(indio_dev->dev.parent, pdata); of_pdata = st_sensors_dev_probe(indio_dev->dev.parent, pdata);
if (of_pdata) if (of_pdata)
pdata = of_pdata; pdata = of_pdata;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/property.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/iio/common/st_sensors_spi.h> #include <linux/iio/common/st_sensors_spi.h>
...@@ -37,14 +38,15 @@ static const struct regmap_config st_sensors_spi_regmap_multiread_bit_config = { ...@@ -37,14 +38,15 @@ static const struct regmap_config st_sensors_spi_regmap_multiread_bit_config = {
*/ */
static bool st_sensors_is_spi_3_wire(struct spi_device *spi) static bool st_sensors_is_spi_3_wire(struct spi_device *spi)
{ {
struct device_node *np = spi->dev.of_node;
struct st_sensors_platform_data *pdata; struct st_sensors_platform_data *pdata;
struct device *dev = &spi->dev;
pdata = (struct st_sensors_platform_data *)spi->dev.platform_data; if (device_property_read_bool(dev, "spi-3wire"))
if ((np && of_property_read_bool(np, "spi-3wire")) || return true;
(pdata && pdata->spi_3wire)) {
pdata = (struct st_sensors_platform_data *)dev->platform_data;
if (pdata && pdata->spi_3wire)
return true; return true;
}
return false; return false;
} }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/iio/common/st_sensors_i2c.h> #include <linux/iio/common/st_sensors_i2c.h>
#include "st_gyro.h" #include "st_gyro.h"
#ifdef CONFIG_OF
static const struct of_device_id st_gyro_of_match[] = { static const struct of_device_id st_gyro_of_match[] = {
{ {
.compatible = "st,l3g4200d-gyro", .compatible = "st,l3g4200d-gyro",
...@@ -58,9 +57,6 @@ static const struct of_device_id st_gyro_of_match[] = { ...@@ -58,9 +57,6 @@ static const struct of_device_id st_gyro_of_match[] = {
{}, {},
}; };
MODULE_DEVICE_TABLE(of, st_gyro_of_match); MODULE_DEVICE_TABLE(of, st_gyro_of_match);
#else
#define st_gyro_of_match NULL
#endif
static int st_gyro_i2c_probe(struct i2c_client *client, static int st_gyro_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
...@@ -121,7 +117,7 @@ MODULE_DEVICE_TABLE(i2c, st_gyro_id_table); ...@@ -121,7 +117,7 @@ MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
static struct i2c_driver st_gyro_driver = { static struct i2c_driver st_gyro_driver = {
.driver = { .driver = {
.name = "st-gyro-i2c", .name = "st-gyro-i2c",
.of_match_table = of_match_ptr(st_gyro_of_match), .of_match_table = st_gyro_of_match,
}, },
.probe = st_gyro_i2c_probe, .probe = st_gyro_i2c_probe,
.remove = st_gyro_i2c_remove, .remove = st_gyro_i2c_remove,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/iio/common/st_sensors_spi.h> #include <linux/iio/common/st_sensors_spi.h>
#include "st_gyro.h" #include "st_gyro.h"
#ifdef CONFIG_OF
/* /*
* For new single-chip sensors use <device_name> as compatible string. * For new single-chip sensors use <device_name> as compatible string.
* For old single-chip devices keep <device_name>-gyro to maintain * For old single-chip devices keep <device_name>-gyro to maintain
...@@ -63,9 +62,6 @@ static const struct of_device_id st_gyro_of_match[] = { ...@@ -63,9 +62,6 @@ static const struct of_device_id st_gyro_of_match[] = {
{}, {},
}; };
MODULE_DEVICE_TABLE(of, st_gyro_of_match); MODULE_DEVICE_TABLE(of, st_gyro_of_match);
#else
#define st_gyro_of_match NULL
#endif
static int st_gyro_spi_probe(struct spi_device *spi) static int st_gyro_spi_probe(struct spi_device *spi)
{ {
...@@ -125,7 +121,7 @@ MODULE_DEVICE_TABLE(spi, st_gyro_id_table); ...@@ -125,7 +121,7 @@ MODULE_DEVICE_TABLE(spi, st_gyro_id_table);
static struct spi_driver st_gyro_driver = { static struct spi_driver st_gyro_driver = {
.driver = { .driver = {
.name = "st-gyro-spi", .name = "st-gyro-spi",
.of_match_table = of_match_ptr(st_gyro_of_match), .of_match_table = st_gyro_of_match,
}, },
.probe = st_gyro_spi_probe, .probe = st_gyro_spi_probe,
.remove = st_gyro_spi_remove, .remove = st_gyro_spi_remove,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/iio/common/st_sensors_i2c.h> #include <linux/iio/common/st_sensors_i2c.h>
#include "st_magn.h" #include "st_magn.h"
#ifdef CONFIG_OF
static const struct of_device_id st_magn_of_match[] = { static const struct of_device_id st_magn_of_match[] = {
{ {
.compatible = "st,lsm303dlh-magn", .compatible = "st,lsm303dlh-magn",
...@@ -50,9 +49,6 @@ static const struct of_device_id st_magn_of_match[] = { ...@@ -50,9 +49,6 @@ static const struct of_device_id st_magn_of_match[] = {
{}, {},
}; };
MODULE_DEVICE_TABLE(of, st_magn_of_match); MODULE_DEVICE_TABLE(of, st_magn_of_match);
#else
#define st_magn_of_match NULL
#endif
static int st_magn_i2c_probe(struct i2c_client *client, static int st_magn_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
...@@ -112,7 +108,7 @@ MODULE_DEVICE_TABLE(i2c, st_magn_id_table); ...@@ -112,7 +108,7 @@ MODULE_DEVICE_TABLE(i2c, st_magn_id_table);
static struct i2c_driver st_magn_driver = { static struct i2c_driver st_magn_driver = {
.driver = { .driver = {
.name = "st-magn-i2c", .name = "st-magn-i2c",
.of_match_table = of_match_ptr(st_magn_of_match), .of_match_table = st_magn_of_match,
}, },
.probe = st_magn_i2c_probe, .probe = st_magn_i2c_probe,
.remove = st_magn_i2c_remove, .remove = st_magn_i2c_remove,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/iio/common/st_sensors_spi.h> #include <linux/iio/common/st_sensors_spi.h>
#include "st_magn.h" #include "st_magn.h"
#ifdef CONFIG_OF
/* /*
* For new single-chip sensors use <device_name> as compatible string. * For new single-chip sensors use <device_name> as compatible string.
* For old single-chip devices keep <device_name>-magn to maintain * For old single-chip devices keep <device_name>-magn to maintain
...@@ -45,9 +44,6 @@ static const struct of_device_id st_magn_of_match[] = { ...@@ -45,9 +44,6 @@ static const struct of_device_id st_magn_of_match[] = {
{} {}
}; };
MODULE_DEVICE_TABLE(of, st_magn_of_match); MODULE_DEVICE_TABLE(of, st_magn_of_match);
#else
#define st_magn_of_match NULL
#endif
static int st_magn_spi_probe(struct spi_device *spi) static int st_magn_spi_probe(struct spi_device *spi)
{ {
...@@ -103,7 +99,7 @@ MODULE_DEVICE_TABLE(spi, st_magn_id_table); ...@@ -103,7 +99,7 @@ MODULE_DEVICE_TABLE(spi, st_magn_id_table);
static struct spi_driver st_magn_driver = { static struct spi_driver st_magn_driver = {
.driver = { .driver = {
.name = "st-magn-spi", .name = "st-magn-spi",
.of_match_table = of_match_ptr(st_magn_of_match), .of_match_table = st_magn_of_match,
}, },
.probe = st_magn_spi_probe, .probe = st_magn_spi_probe,
.remove = st_magn_spi_remove, .remove = st_magn_spi_remove,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/iio/common/st_sensors_i2c.h> #include <linux/iio/common/st_sensors_i2c.h>
#include "st_pressure.h" #include "st_pressure.h"
#ifdef CONFIG_OF
static const struct of_device_id st_press_of_match[] = { static const struct of_device_id st_press_of_match[] = {
{ {
.compatible = "st,lps001wp-press", .compatible = "st,lps001wp-press",
...@@ -50,9 +49,6 @@ static const struct of_device_id st_press_of_match[] = { ...@@ -50,9 +49,6 @@ static const struct of_device_id st_press_of_match[] = {
{}, {},
}; };
MODULE_DEVICE_TABLE(of, st_press_of_match); MODULE_DEVICE_TABLE(of, st_press_of_match);
#else
#define st_press_of_match NULL
#endif
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
static const struct acpi_device_id st_press_acpi_match[] = { static const struct acpi_device_id st_press_acpi_match[] = {
...@@ -119,7 +115,7 @@ static int st_press_i2c_remove(struct i2c_client *client) ...@@ -119,7 +115,7 @@ static int st_press_i2c_remove(struct i2c_client *client)
static struct i2c_driver st_press_driver = { static struct i2c_driver st_press_driver = {
.driver = { .driver = {
.name = "st-press-i2c", .name = "st-press-i2c",
.of_match_table = of_match_ptr(st_press_of_match), .of_match_table = st_press_of_match,
.acpi_match_table = ACPI_PTR(st_press_acpi_match), .acpi_match_table = ACPI_PTR(st_press_acpi_match),
}, },
.probe = st_press_i2c_probe, .probe = st_press_i2c_probe,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/iio/common/st_sensors_spi.h> #include <linux/iio/common/st_sensors_spi.h>
#include "st_pressure.h" #include "st_pressure.h"
#ifdef CONFIG_OF
/* /*
* For new single-chip sensors use <device_name> as compatible string. * For new single-chip sensors use <device_name> as compatible string.
* For old single-chip devices keep <device_name>-press to maintain * For old single-chip devices keep <device_name>-press to maintain
...@@ -55,9 +54,6 @@ static const struct of_device_id st_press_of_match[] = { ...@@ -55,9 +54,6 @@ static const struct of_device_id st_press_of_match[] = {
{}, {},
}; };
MODULE_DEVICE_TABLE(of, st_press_of_match); MODULE_DEVICE_TABLE(of, st_press_of_match);
#else
#define st_press_of_match NULL
#endif
static int st_press_spi_probe(struct spi_device *spi) static int st_press_spi_probe(struct spi_device *spi)
{ {
...@@ -115,7 +111,7 @@ MODULE_DEVICE_TABLE(spi, st_press_id_table); ...@@ -115,7 +111,7 @@ MODULE_DEVICE_TABLE(spi, st_press_id_table);
static struct spi_driver st_press_driver = { static struct spi_driver st_press_driver = {
.driver = { .driver = {
.name = "st-press-spi", .name = "st-press-spi",
.of_match_table = of_match_ptr(st_press_of_match), .of_match_table = st_press_of_match,
}, },
.probe = st_press_spi_probe, .probe = st_press_spi_probe,
.remove = st_press_spi_remove, .remove = st_press_spi_remove,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment