All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mircea Caprioru <mircea.caprioru@analog.com>
To: <jic23@kernel.org>
Cc: <Michael.Hennerich@analog.com>, <stefan.popa@analog.com>,
	<lars@metafoo.de>, <gregkh@linuxfoundation.org>,
	<linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <robh+dt@kernel.org>,
	Mircea Caprioru <mircea.caprioru@analog.com>
Subject: [PATCH V4 3/5] iio: adc: ad7124: Shift to dynamic allocation for channel configuration
Date: Tue, 25 Jun 2019 11:11:26 +0300	[thread overview]
Message-ID: <20190625081128.22190-3-mircea.caprioru@analog.com> (raw)
In-Reply-To: <20190625081128.22190-1-mircea.caprioru@analog.com>

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 <mircea.caprioru@analog.com>
---

Changelog v2:
- nothing changed here

Changelog v3:
- nothing changed here

Changelog v4:
- nothing changed here

 drivers/iio/adc/ad7124.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index ab52c5e9ecb1..edc6f1cc90b2 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -121,7 +121,7 @@ struct ad7124_channel_config {
 struct ad7124_state {
 	const struct ad7124_chip_info *chip_info;
 	struct ad_sigma_delta sd;
-	struct ad7124_channel_config channel_config[4];
+	struct ad7124_channel_config *channel_config;
 	struct regulator *vref[4];
 	struct clk *mclk;
 	unsigned int adc_control;
@@ -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 device_node *child;
 	struct iio_chan_spec *chan;
+	struct ad7124_channel_config *chan_config;
 	unsigned int ain[2], channel = 0, tmp;
 	int ret;
 
@@ -453,8 +454,14 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 	if (!chan)
 		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->num_channels = st->num_channels;
+	st->channel_config = chan_config;
 
 	for_each_available_child_of_node(np, child) {
 		ret = of_property_read_u32(child, "reg", &channel);
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: Mircea Caprioru <mircea.caprioru@analog.com>
To: jic23@kernel.org
Cc: Michael.Hennerich@analog.com, stefan.popa@analog.com,
	lars@metafoo.de, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org, robh+dt@kernel.org,
	Mircea Caprioru <mircea.caprioru@analog.com>
Subject: [PATCH V4 3/5] iio: adc: ad7124: Shift to dynamic allocation for channel configuration
Date: Tue, 25 Jun 2019 11:11:26 +0300	[thread overview]
Message-ID: <20190625081128.22190-3-mircea.caprioru@analog.com> (raw)
In-Reply-To: <20190625081128.22190-1-mircea.caprioru@analog.com>

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 <mircea.caprioru@analog.com>
---

Changelog v2:
- nothing changed here

Changelog v3:
- nothing changed here

Changelog v4:
- nothing changed here

 drivers/iio/adc/ad7124.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index ab52c5e9ecb1..edc6f1cc90b2 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -121,7 +121,7 @@ struct ad7124_channel_config {
 struct ad7124_state {
 	const struct ad7124_chip_info *chip_info;
 	struct ad_sigma_delta sd;
-	struct ad7124_channel_config channel_config[4];
+	struct ad7124_channel_config *channel_config;
 	struct regulator *vref[4];
 	struct clk *mclk;
 	unsigned int adc_control;
@@ -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 device_node *child;
 	struct iio_chan_spec *chan;
+	struct ad7124_channel_config *chan_config;
 	unsigned int ain[2], channel = 0, tmp;
 	int ret;
 
@@ -453,8 +454,14 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 	if (!chan)
 		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->num_channels = st->num_channels;
+	st->channel_config = chan_config;
 
 	for_each_available_child_of_node(np, child) {
 		ret = of_property_read_u32(child, "reg", &channel);
-- 
2.17.1

  parent reply	other threads:[~2019-06-25  8:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25  8:11 [PATCH V4 1/5] iio: adc: ad7124: Remove input number limitation Mircea Caprioru
2019-06-25  8:11 ` Mircea Caprioru
2019-06-25  8:11 ` [PATCHi V4 2/5] iio: adc: ad7124: Add buffered input support Mircea Caprioru
2019-06-25  8:11   ` Mircea Caprioru
2019-06-26 19:24   ` Jonathan Cameron
2019-06-26 19:24     ` Jonathan Cameron
2019-06-25  8:11 ` Mircea Caprioru [this message]
2019-06-25  8:11   ` [PATCH V4 3/5] iio: adc: ad7124: Shift to dynamic allocation for channel configuration Mircea Caprioru
2019-06-26 19:25   ` Jonathan Cameron
2019-06-26 19:25     ` Jonathan Cameron
2019-06-25  8:11 ` [PATCH V4 4/5] dt-bindings: iio: adc: Convert ad7124 documentation to YAML Mircea Caprioru
2019-06-25  8:11   ` Mircea Caprioru
2019-06-26 14:44   ` Rob Herring
2019-06-26 19:34     ` Jonathan Cameron
2019-06-26 19:57       ` Rob Herring
2019-06-25  8:11 ` [PATCH V4 5/5] dt-bindings: iio: adc: Add buffered input property Mircea Caprioru
2019-06-25  8:11   ` Mircea Caprioru
2019-06-26 14:45   ` Rob Herring
2019-06-26 19:34     ` Jonathan Cameron
2019-06-26 19:22 ` [PATCH V4 1/5] iio: adc: ad7124: Remove input number limitation Jonathan Cameron
2019-06-26 19:22   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190625081128.22190-3-mircea.caprioru@analog.com \
    --to=mircea.caprioru@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=stefan.popa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.