Commit 5f474919 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: imu: bmi160: Make use of device properties

Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

While at it, reuse temporary device pointer in the same function.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20220414131804.25227-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d1100dd9
...@@ -11,10 +11,9 @@ ...@@ -11,10 +11,9 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/acpi.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/of_irq.h> #include <linux/property.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
...@@ -525,17 +524,6 @@ static const struct iio_info bmi160_info = { ...@@ -525,17 +524,6 @@ static const struct iio_info bmi160_info = {
.attrs = &bmi160_attrs_group, .attrs = &bmi160_attrs_group,
}; };
static const char *bmi160_match_acpi_device(struct device *dev)
{
const struct acpi_device_id *id;
id = acpi_match_device(dev->driver->acpi_match_table, dev);
if (!id)
return NULL;
return dev_name(dev);
}
static int bmi160_write_conf_reg(struct regmap *regmap, unsigned int reg, static int bmi160_write_conf_reg(struct regmap *regmap, unsigned int reg,
unsigned int mask, unsigned int bits, unsigned int mask, unsigned int bits,
unsigned int write_usleep) unsigned int write_usleep)
...@@ -647,18 +635,18 @@ int bmi160_enable_irq(struct regmap *regmap, bool enable) ...@@ -647,18 +635,18 @@ int bmi160_enable_irq(struct regmap *regmap, bool enable)
} }
EXPORT_SYMBOL(bmi160_enable_irq); EXPORT_SYMBOL(bmi160_enable_irq);
static int bmi160_get_irq(struct device_node *of_node, enum bmi160_int_pin *pin) static int bmi160_get_irq(struct fwnode_handle *fwnode, enum bmi160_int_pin *pin)
{ {
int irq; int irq;
/* Use INT1 if possible, otherwise fall back to INT2. */ /* Use INT1 if possible, otherwise fall back to INT2. */
irq = of_irq_get_byname(of_node, "INT1"); irq = fwnode_irq_get_byname(fwnode, "INT1");
if (irq > 0) { if (irq > 0) {
*pin = BMI160_PIN_INT1; *pin = BMI160_PIN_INT1;
return irq; return irq;
} }
irq = of_irq_get_byname(of_node, "INT2"); irq = fwnode_irq_get_byname(fwnode, "INT2");
if (irq > 0) if (irq > 0)
*pin = BMI160_PIN_INT2; *pin = BMI160_PIN_INT2;
...@@ -688,7 +676,7 @@ static int bmi160_config_device_irq(struct iio_dev *indio_dev, int irq_type, ...@@ -688,7 +676,7 @@ static int bmi160_config_device_irq(struct iio_dev *indio_dev, int irq_type,
return -EINVAL; return -EINVAL;
} }
open_drain = of_property_read_bool(dev->of_node, "drive-open-drain"); open_drain = device_property_read_bool(dev, "drive-open-drain");
return bmi160_config_pin(data->regmap, pin, open_drain, irq_mask, return bmi160_config_pin(data->regmap, pin, open_drain, irq_mask,
BMI160_NORMAL_WRITE_USLEEP); BMI160_NORMAL_WRITE_USLEEP);
...@@ -864,9 +852,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, ...@@ -864,9 +852,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,
if (ret) if (ret)
return ret; return ret;
if (!name && ACPI_HANDLE(dev))
name = bmi160_match_acpi_device(dev);
indio_dev->channels = bmi160_channels; indio_dev->channels = bmi160_channels;
indio_dev->num_channels = ARRAY_SIZE(bmi160_channels); indio_dev->num_channels = ARRAY_SIZE(bmi160_channels);
indio_dev->name = name; indio_dev->name = name;
...@@ -879,7 +864,7 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, ...@@ -879,7 +864,7 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,
if (ret) if (ret)
return ret; return ret;
irq = bmi160_get_irq(dev->of_node, &int_pin); irq = bmi160_get_irq(dev_fwnode(dev), &int_pin);
if (irq > 0) { if (irq > 0) {
ret = bmi160_setup_irq(indio_dev, irq, int_pin); ret = bmi160_setup_irq(indio_dev, irq, int_pin);
if (ret) if (ret)
......
...@@ -8,10 +8,9 @@ ...@@ -8,10 +8,9 @@
* - 0x68 if SDO is pulled to GND * - 0x68 if SDO is pulled to GND
* - 0x69 if SDO is pulled to VDDIO * - 0x69 if SDO is pulled to VDDIO
*/ */
#include <linux/acpi.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include "bmi160.h" #include "bmi160.h"
...@@ -20,7 +19,7 @@ static int bmi160_i2c_probe(struct i2c_client *client, ...@@ -20,7 +19,7 @@ static int bmi160_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct regmap *regmap; struct regmap *regmap;
const char *name = NULL; const char *name;
regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config); regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap)) {
...@@ -31,6 +30,8 @@ static int bmi160_i2c_probe(struct i2c_client *client, ...@@ -31,6 +30,8 @@ static int bmi160_i2c_probe(struct i2c_client *client,
if (id) if (id)
name = id->name; name = id->name;
else
name = dev_name(&client->dev);
return bmi160_core_probe(&client->dev, regmap, name, false); return bmi160_core_probe(&client->dev, regmap, name, false);
} }
...@@ -47,19 +48,17 @@ static const struct acpi_device_id bmi160_acpi_match[] = { ...@@ -47,19 +48,17 @@ static const struct acpi_device_id bmi160_acpi_match[] = {
}; };
MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
#ifdef CONFIG_OF
static const struct of_device_id bmi160_of_match[] = { static const struct of_device_id bmi160_of_match[] = {
{ .compatible = "bosch,bmi160" }, { .compatible = "bosch,bmi160" },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, bmi160_of_match); MODULE_DEVICE_TABLE(of, bmi160_of_match);
#endif
static struct i2c_driver bmi160_i2c_driver = { static struct i2c_driver bmi160_i2c_driver = {
.driver = { .driver = {
.name = "bmi160_i2c", .name = "bmi160_i2c",
.acpi_match_table = ACPI_PTR(bmi160_acpi_match), .acpi_match_table = bmi160_acpi_match,
.of_match_table = of_match_ptr(bmi160_of_match), .of_match_table = bmi160_of_match,
}, },
.probe = bmi160_i2c_probe, .probe = bmi160_i2c_probe,
.id_table = bmi160_i2c_id, .id_table = bmi160_i2c_id,
......
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
* Copyright (c) 2016, Intel Corporation. * Copyright (c) 2016, Intel Corporation.
* *
*/ */
#include <linux/acpi.h> #include <linux/mod_devicetable.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -17,6 +16,7 @@ static int bmi160_spi_probe(struct spi_device *spi) ...@@ -17,6 +16,7 @@ static int bmi160_spi_probe(struct spi_device *spi)
{ {
struct regmap *regmap; struct regmap *regmap;
const struct spi_device_id *id = spi_get_device_id(spi); const struct spi_device_id *id = spi_get_device_id(spi);
const char *name;
regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config); regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap)) {
...@@ -24,7 +24,13 @@ static int bmi160_spi_probe(struct spi_device *spi) ...@@ -24,7 +24,13 @@ static int bmi160_spi_probe(struct spi_device *spi)
regmap); regmap);
return PTR_ERR(regmap); return PTR_ERR(regmap);
} }
return bmi160_core_probe(&spi->dev, regmap, id->name, true);
if (id)
name = id->name;
else
name = dev_name(&spi->dev);
return bmi160_core_probe(&spi->dev, regmap, name, true);
} }
static const struct spi_device_id bmi160_spi_id[] = { static const struct spi_device_id bmi160_spi_id[] = {
...@@ -39,20 +45,18 @@ static const struct acpi_device_id bmi160_acpi_match[] = { ...@@ -39,20 +45,18 @@ static const struct acpi_device_id bmi160_acpi_match[] = {
}; };
MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
#ifdef CONFIG_OF
static const struct of_device_id bmi160_of_match[] = { static const struct of_device_id bmi160_of_match[] = {
{ .compatible = "bosch,bmi160" }, { .compatible = "bosch,bmi160" },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, bmi160_of_match); MODULE_DEVICE_TABLE(of, bmi160_of_match);
#endif
static struct spi_driver bmi160_spi_driver = { static struct spi_driver bmi160_spi_driver = {
.probe = bmi160_spi_probe, .probe = bmi160_spi_probe,
.id_table = bmi160_spi_id, .id_table = bmi160_spi_id,
.driver = { .driver = {
.acpi_match_table = ACPI_PTR(bmi160_acpi_match), .acpi_match_table = bmi160_acpi_match,
.of_match_table = of_match_ptr(bmi160_of_match), .of_match_table = bmi160_of_match,
.name = "bmi160_spi", .name = "bmi160_spi",
}, },
}; };
......
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