提交 1478a388 编写于 作者: M Mircea Caprioru 提交者: Jonathan Cameron

iio: adc: ad7124: Shift to dynamic allocation for channel configuration

This patch changes the channel configuration member of the device
structure from a fixed size array to a dynamic allocated one with a size
equal to the number of channels specified in the device tree. This will
ensure a more flexibility for compatible devices.

Ex. ad7124-4 - can have 4 differential or 8 pseudo-differential channels
ad7124-8 - can have 8 differential or 16 pseudo-differential channels

Also the device can suspport any other combination of differential and
pseudo-differential channels base on the physical number of inputs
available.
Signed-off-by: NMircea Caprioru <mircea.caprioru@analog.com>
Signed-off-by: NJonathan Cameron <Jonathan.Cameron@huawei.com>
上级 0eaecea6
...@@ -121,7 +121,7 @@ struct ad7124_channel_config { ...@@ -121,7 +121,7 @@ struct ad7124_channel_config {
struct ad7124_state { struct ad7124_state {
const struct ad7124_chip_info *chip_info; const struct ad7124_chip_info *chip_info;
struct ad_sigma_delta sd; struct ad_sigma_delta sd;
struct ad7124_channel_config channel_config[4]; struct ad7124_channel_config *channel_config;
struct regulator *vref[4]; struct regulator *vref[4];
struct clk *mclk; struct clk *mclk;
unsigned int adc_control; unsigned int adc_control;
...@@ -439,6 +439,7 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, ...@@ -439,6 +439,7 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
struct ad7124_state *st = iio_priv(indio_dev); struct ad7124_state *st = iio_priv(indio_dev);
struct device_node *child; struct device_node *child;
struct iio_chan_spec *chan; struct iio_chan_spec *chan;
struct ad7124_channel_config *chan_config;
unsigned int ain[2], channel = 0, tmp; unsigned int ain[2], channel = 0, tmp;
int ret; int ret;
...@@ -453,8 +454,14 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, ...@@ -453,8 +454,14 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
if (!chan) if (!chan)
return -ENOMEM; return -ENOMEM;
chan_config = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
sizeof(*chan_config), GFP_KERNEL);
if (!chan_config)
return -ENOMEM;
indio_dev->channels = chan; indio_dev->channels = chan;
indio_dev->num_channels = st->num_channels; indio_dev->num_channels = st->num_channels;
st->channel_config = chan_config;
for_each_available_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
ret = of_property_read_u32(child, "reg", &channel); ret = of_property_read_u32(child, "reg", &channel);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册