Skip to content

Commit 1478a38

Browse files
Mircea Capriorujic23
authored andcommitted
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: Mircea Caprioru <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 0eaecea commit 1478a38

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/iio/adc/ad7124.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct ad7124_channel_config {
121121
struct ad7124_state {
122122
const struct ad7124_chip_info *chip_info;
123123
struct ad_sigma_delta sd;
124-
struct ad7124_channel_config channel_config[4];
124+
struct ad7124_channel_config *channel_config;
125125
struct regulator *vref[4];
126126
struct clk *mclk;
127127
unsigned int adc_control;
@@ -439,6 +439,7 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
439439
struct ad7124_state *st = iio_priv(indio_dev);
440440
struct device_node *child;
441441
struct iio_chan_spec *chan;
442+
struct ad7124_channel_config *chan_config;
442443
unsigned int ain[2], channel = 0, tmp;
443444
int ret;
444445

@@ -453,8 +454,14 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
453454
if (!chan)
454455
return -ENOMEM;
455456

457+
chan_config = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
458+
sizeof(*chan_config), GFP_KERNEL);
459+
if (!chan_config)
460+
return -ENOMEM;
461+
456462
indio_dev->channels = chan;
457463
indio_dev->num_channels = st->num_channels;
464+
st->channel_config = chan_config;
458465

459466
for_each_available_child_of_node(np, child) {
460467
ret = of_property_read_u32(child, "reg", &channel);

0 commit comments

Comments
 (0)