mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-08 10:25:20 +02:00
iio: adc: ad7124: Switch from of specific to fwnode based property handling
[ Upstream commita6eaf02b82
] Using the generic firmware data access functions from property.h provides a number of advantages: 1) Works with different firmware types. 2) Doesn't provide a 'bad' example for new IIO drivers. 3) Lets us use the new _scoped() loops with automatic reference count cleanup for fwnode_handle Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Michael Hennerich <Michael.Hennerich@analog.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20240218172731.1023367-4-jic23@kernel.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Stable-dep-of:61cbfb5368
("iio: adc: ad7124: fix DT configuration parsing") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
bfc8dab8c7
commit
fbed740058
|
@ -14,7 +14,8 @@
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/kfifo.h>
|
#include <linux/kfifo.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of.h>
|
#include <linux/mod_devicetable.h>
|
||||||
|
#include <linux/property.h>
|
||||||
#include <linux/regulator/consumer.h>
|
#include <linux/regulator/consumer.h>
|
||||||
#include <linux/spi/spi.h>
|
#include <linux/spi/spi.h>
|
||||||
|
|
||||||
|
@ -812,22 +813,19 @@ static int ad7124_check_chip_id(struct ad7124_state *st)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
|
static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
|
||||||
struct device_node *np)
|
struct device *dev)
|
||||||
{
|
{
|
||||||
struct ad7124_state *st = iio_priv(indio_dev);
|
struct ad7124_state *st = iio_priv(indio_dev);
|
||||||
struct ad7124_channel_config *cfg;
|
struct ad7124_channel_config *cfg;
|
||||||
struct ad7124_channel *channels;
|
struct ad7124_channel *channels;
|
||||||
struct device_node *child;
|
|
||||||
struct iio_chan_spec *chan;
|
struct iio_chan_spec *chan;
|
||||||
unsigned int ain[2], channel = 0, tmp;
|
unsigned int ain[2], channel = 0, tmp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
st->num_channels = of_get_available_child_count(np);
|
st->num_channels = device_get_child_node_count(dev);
|
||||||
if (!st->num_channels) {
|
if (!st->num_channels)
|
||||||
dev_err(indio_dev->dev.parent, "no channel children\n");
|
return dev_err_probe(dev, -ENODEV, "no channel children\n");
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
|
chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
|
||||||
sizeof(*chan), GFP_KERNEL);
|
sizeof(*chan), GFP_KERNEL);
|
||||||
|
@ -843,39 +841,38 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
|
||||||
indio_dev->num_channels = st->num_channels;
|
indio_dev->num_channels = st->num_channels;
|
||||||
st->channels = channels;
|
st->channels = channels;
|
||||||
|
|
||||||
for_each_available_child_of_node(np, child) {
|
device_for_each_child_node_scoped(dev, child) {
|
||||||
cfg = &st->channels[channel].cfg;
|
cfg = &st->channels[channel].cfg;
|
||||||
|
|
||||||
ret = of_property_read_u32(child, "reg", &channel);
|
ret = fwnode_property_read_u32(child, "reg", &channel);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
return ret;
|
||||||
|
|
||||||
if (channel >= indio_dev->num_channels) {
|
if (channel >= indio_dev->num_channels)
|
||||||
dev_err(indio_dev->dev.parent,
|
return dev_err_probe(dev, -EINVAL,
|
||||||
"Channel index >= number of channels\n");
|
"Channel index >= number of channels\n");
|
||||||
ret = -EINVAL;
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = of_property_read_u32_array(child, "diff-channels",
|
ret = fwnode_property_read_u32_array(child, "diff-channels",
|
||||||
ain, 2);
|
ain, 2);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
return ret;
|
||||||
|
|
||||||
st->channels[channel].nr = channel;
|
st->channels[channel].nr = channel;
|
||||||
st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
|
st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
|
||||||
AD7124_CHANNEL_AINM(ain[1]);
|
AD7124_CHANNEL_AINM(ain[1]);
|
||||||
|
|
||||||
cfg->bipolar = of_property_read_bool(child, "bipolar");
|
cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
|
||||||
|
|
||||||
ret = of_property_read_u32(child, "adi,reference-select", &tmp);
|
ret = fwnode_property_read_u32(child, "adi,reference-select", &tmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
cfg->refsel = AD7124_INT_REF;
|
cfg->refsel = AD7124_INT_REF;
|
||||||
else
|
else
|
||||||
cfg->refsel = tmp;
|
cfg->refsel = tmp;
|
||||||
|
|
||||||
cfg->buf_positive = of_property_read_bool(child, "adi,buffered-positive");
|
cfg->buf_positive =
|
||||||
cfg->buf_negative = of_property_read_bool(child, "adi,buffered-negative");
|
fwnode_property_read_bool(child, "adi,buffered-positive");
|
||||||
|
cfg->buf_negative =
|
||||||
|
fwnode_property_read_bool(child, "adi,buffered-negative");
|
||||||
|
|
||||||
chan[channel] = ad7124_channel_template;
|
chan[channel] = ad7124_channel_template;
|
||||||
chan[channel].address = channel;
|
chan[channel].address = channel;
|
||||||
|
@ -885,10 +882,6 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
err:
|
|
||||||
of_node_put(child);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ad7124_setup(struct ad7124_state *st)
|
static int ad7124_setup(struct ad7124_state *st)
|
||||||
|
@ -948,9 +941,7 @@ static int ad7124_probe(struct spi_device *spi)
|
||||||
struct iio_dev *indio_dev;
|
struct iio_dev *indio_dev;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
info = of_device_get_match_data(&spi->dev);
|
info = spi_get_device_match_data(spi);
|
||||||
if (!info)
|
|
||||||
info = (void *)spi_get_device_id(spi)->driver_data;
|
|
||||||
if (!info)
|
if (!info)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
|
@ -970,7 +961,7 @@ static int ad7124_probe(struct spi_device *spi)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = ad7124_of_parse_channel_config(indio_dev, spi->dev.of_node);
|
ret = ad7124_parse_channel_config(indio_dev, &spi->dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user