All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <jic23@kernel.org>, <eugen.hristev@microchip.com>,
	<nicolas.ferre@microchip.com>, <ludovic.desroches@microchip.com>,
	<bleung@chromium.org>, <enric.balletbo@collabora.com>,
	<groeck@chromium.org>, <srinivas.pandruvada@linux.intel.com>,
	<andy.shevchenko@gmail.com>, <gwendal@chromium.org>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v3 2/9] iio: adc: at91-sama5d2_adc: merge buffer & trigger init into a function
Date: Tue, 29 Sep 2020 15:59:42 +0300	[thread overview]
Message-ID: <20200929125949.69934-3-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20200929125949.69934-1-alexandru.ardelean@analog.com>

This change is mostly cosmetic, but it's also a pre-cursor to the
the change for 'iio_buffer_set_attrs()', where the helper gets updated to
better support multiple IIO buffers for 1 IIO device.

The only functional change is that the error message for the trigger alloc
failure is bound to the parent device vs the IIO device object.

Also, the new at91_adc_buffer_and_trigger_init() function was moved after
the definition of the 'at91_adc_fifo_attributes'.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/at91-sama5d2_adc.c | 78 ++++++++++++++----------------
 1 file changed, 36 insertions(+), 42 deletions(-)

diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index ad7d9819f83c..b9c3cc6d5913 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -1014,21 +1014,6 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio,
 
 	return trig;
 }
-
-static int at91_adc_trigger_init(struct iio_dev *indio)
-{
-	struct at91_adc_state *st = iio_priv(indio);
-
-	st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name);
-	if (IS_ERR(st->trig)) {
-		dev_err(&indio->dev,
-			"could not allocate trigger\n");
-		return PTR_ERR(st->trig);
-	}
-
-	return 0;
-}
-
 static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev,
 					   struct iio_poll_func *pf)
 {
@@ -1156,13 +1141,6 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
-static int at91_adc_buffer_init(struct iio_dev *indio)
-{
-	return devm_iio_triggered_buffer_setup(&indio->dev, indio,
-		&iio_pollfunc_store_time,
-		&at91_adc_trigger_handler, &at91_buffer_setup_ops);
-}
-
 static unsigned at91_adc_startup_time(unsigned startup_time_min,
 				      unsigned adc_clk_khz)
 {
@@ -1683,6 +1661,40 @@ static const struct iio_info at91_adc_info = {
 	.hwfifo_set_watermark = &at91_adc_set_watermark,
 };
 
+static int at91_adc_buffer_and_trigger_init(struct device *dev,
+					    struct iio_dev *indio)
+{
+	struct at91_adc_state *st = iio_priv(indio);
+	int ret;
+
+	ret = devm_iio_triggered_buffer_setup(&indio->dev, indio,
+		&iio_pollfunc_store_time,
+		&at91_adc_trigger_handler, &at91_buffer_setup_ops);
+	if (ret < 0) {
+		dev_err(dev, "couldn't initialize the buffer.\n");
+		return ret;
+	}
+
+	if (!st->selected_trig->hw_trig)
+		return 0;
+
+	iio_buffer_set_attrs(indio->buffer, at91_adc_fifo_attributes);
+
+	st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name);
+	if (IS_ERR(st->trig)) {
+		dev_err(dev, "could not allocate trigger\n");
+		return PTR_ERR(st->trig);
+	}
+
+	/*
+	 * Initially the iio buffer has a length of 2 and
+	 * a watermark of 1
+	 */
+	st->dma_st.watermark = 1;
+
+	return 0;
+}
+
 static int at91_adc_probe(struct platform_device *pdev)
 {
 	struct iio_dev *indio_dev;
@@ -1818,27 +1830,9 @@ static int at91_adc_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, indio_dev);
 
-	ret = at91_adc_buffer_init(indio_dev);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "couldn't initialize the buffer.\n");
+	ret = at91_adc_buffer_and_trigger_init(&pdev->dev, indio_dev);
+	if (ret < 0)
 		goto per_clk_disable_unprepare;
-	}
-
-	if (st->selected_trig->hw_trig) {
-		ret = at91_adc_trigger_init(indio_dev);
-		if (ret < 0) {
-			dev_err(&pdev->dev, "couldn't setup the triggers.\n");
-			goto per_clk_disable_unprepare;
-		}
-		/*
-		 * Initially the iio buffer has a length of 2 and
-		 * a watermark of 1
-		 */
-		st->dma_st.watermark = 1;
-
-		iio_buffer_set_attrs(indio_dev->buffer,
-				     at91_adc_fifo_attributes);
-	}
 
 	if (dma_coerce_mask_and_coherent(&indio_dev->dev, DMA_BIT_MASK(32)))
 		dev_info(&pdev->dev, "cannot set DMA mask to 32-bit\n");
-- 
2.17.1


  parent reply	other threads:[~2020-09-29 12:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 12:59 [PATCH v3 0/9] iio: remove iio_buffer_set_attrs() and assign buffer attrs during alloc Alexandru Ardelean
2020-09-29 12:59 ` [PATCH v3 1/9] iio: buffer: dmaengine: unwrap the use of iio_buffer_set_attrs() Alexandru Ardelean
2020-09-29 12:59 ` Alexandru Ardelean [this message]
2020-09-29 12:59 ` [PATCH v3 3/9] iio: triggered-buffer: add {devm_}iio_triggered_buffer_setup_ext variants Alexandru Ardelean
2020-09-29 12:59 ` [PATCH v3 4/9] iio: accel: adxl372: use devm_iio_triggered_buffer_setup_ext() Alexandru Ardelean
2020-09-29 12:59 ` [PATCH v3 5/9] iio: accel: bmc150: use iio_triggered_buffer_setup_ext() Alexandru Ardelean
2020-09-29 12:59 ` [PATCH v3 6/9] iio: adc: at91-sama5d2_adc: use devm_iio_triggered_buffer_setup_ext() Alexandru Ardelean
2020-09-29 12:59 ` [PATCH v3 7/9] iio: cros_ec: " Alexandru Ardelean
2020-09-29 13:08   ` Andy Shevchenko
2020-09-29 14:31     ` Alexandru Ardelean
2020-09-29 15:40       ` Jonathan Cameron
2020-11-18 10:35         ` Alexandru Ardelean
2020-11-21 14:47           ` Jonathan Cameron
2020-11-21 14:55             ` Jonathan Cameron
2020-11-21 14:56               ` Jonathan Cameron
2020-09-29 12:59 ` [PATCH v3 8/9] iio: hid-sensors: use iio_triggered_buffer_setup_ext() Alexandru Ardelean
2020-09-29 12:59 ` [PATCH v3 9/9] iio: buffer: remove iio_buffer_set_attrs() helper Alexandru Ardelean
2020-09-29 13:09 ` [PATCH v3 0/9] iio: remove iio_buffer_set_attrs() and assign buffer attrs during alloc Andy Shevchenko
2020-09-29 13:09   ` Andy Shevchenko

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=20200929125949.69934-3-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bleung@chromium.org \
    --cc=enric.balletbo@collabora.com \
    --cc=eugen.hristev@microchip.com \
    --cc=groeck@chromium.org \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=srinivas.pandruvada@linux.intel.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.