mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: "Leonard Göhrs" <l.goehrs@pengutronix.de>
Cc: <kernel@pengutronix.de>, Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>, <linux-iio@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] iio: adc: add buffering support to the TI LMP92064 ADC driver
Date: Sun, 2 Jul 2023 18:09:03 +0800	[thread overview]
Message-ID: <20230702180903.00004a1a@Huawei.com> (raw)
In-Reply-To: <20230622065341.1100525-1-l.goehrs@pengutronix.de>

On Thu, 22 Jun 2023 08:53:41 +0200
Leonard Göhrs <l.goehrs@pengutronix.de> wrote:

> Enable buffered reading of samples from the LMP92064 ADC.
> The main benefit of this change is being able to read out current and
> voltage measurements in a single transfer, allowing instantaneous power
> measurements.
> 
> Reads into the buffer can be triggered by any software triggers, e.g.
> the iio-trig-hrtimer:
> 
>     $ mkdir /sys/kernel/config/iio/triggers/hrtimer/my-trigger
>     $ cat /sys/bus/iio/devices/iio\:device3/name
>     lmp92064
>     $ iio_readdev -t my-trigger -b 16 iio:device3 | hexdump
>     WARNING: High-speed mode not enabled
>     0000000 0000 0176 0101 0001 5507 abd5 7645 1768
>     0000010 0000 016d 0101 0001 ee1e ac6b 7645 1768
>     ...
> 
> Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>

A minor follow up comment inline.

>  static int lmp92064_read_meas(struct lmp92064_adc_priv *priv, u16 *res)
> @@ -171,6 +192,29 @@ static int lmp92064_read_raw(struct iio_dev *indio_dev,
>  	}
>  }
>  
> +static irqreturn_t lmp92064_trigger_handler(int irq, void *p)
> +{
> +	struct iio_poll_func *pf = p;
> +	struct iio_dev *indio_dev = pf->indio_dev;
> +	struct lmp92064_adc_priv *priv = iio_priv(indio_dev);
> +	struct {
> +		u16 values[2];
> +		int64_t timestamp;
> +	} data;
> +	int ret;
> +
> +	ret = lmp92064_read_meas(priv, data.values);
> +	if (ret >= 0) {
Even thought it's more code, in IIO at least we tend to prefer to handle
errors out of line

	if (ret) 
		goto err;
	
	iio_push_to_buffers....


err:
	iio_trigger_notify_done()

	return IRQ_HANDLED;

Also, read_meas doesn't return > 0 which is implied by the above check.

> +		/* Only push values if the read succeeded */
> +		iio_push_to_buffers_with_timestamp(indio_dev, &data,
> +						   iio_get_time_ns(indio_dev));
> +	}
> +
> +	iio_trigger_notify_done(indio_dev->trig);
> +
> +	return IRQ_HANDLED;
> +}
> +


      reply	other threads:[~2023-07-02 10:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22  6:53 Leonard Göhrs
2023-07-02 10:09 ` Jonathan Cameron [this message]

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=20230702180903.00004a1a@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=jic23@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=l.goehrs@pengutronix.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®