public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Trevor Gamblin" <tgamblin@baylibre.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"David Lechner" <dlechner@baylibre.com>,
	"Uwe Kleine-Konig" <u.kleine-koenig@baylibre.com>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 2/3] iio: adc: ad7625: add driver
Date: Thu, 05 Sep 2024 09:58:22 +0200	[thread overview]
Message-ID: <23c81d6735075c0b9d98833641606a661fab7194.camel@gmail.com> (raw)
In-Reply-To: <20240904-ad7625_r1-v4-2-78bc7dfb2b35@baylibre.com>

On Wed, 2024-09-04 at 15:14 -0400, Trevor Gamblin wrote:
> Add a driver for the AD762x and AD796x family of ADCs. These are
> pin-compatible devices using an LVDS interface for data transfer,
> capable of sampling at rates of 6 (AD7625), 10 (AD7626), and 5
> (AD7960/AD7961) MSPS, respectively. They also feature multiple voltage
> reference options based on the configuration of the EN1/EN0 pins, which
> can be set in the devicetree.
> 
> Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
> ---

Hi Trevor,

It LGTM, just some minor stuff from me...

With that,

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

>  MAINTAINERS              |   1 +
>  drivers/iio/adc/Kconfig  |  16 ++
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ad7625.c | 684
> +++++++++++++++++++++++++++++++++++++++++++++++
> 

...

> +
> +static int ad7625_set_sampling_freq(struct ad7625_state *st, int freq)
> +{
> +	u64 target;
> +	struct pwm_waveform clk_gate_wf = { }, cnv_wf = { };
> +	int ret;
> +
> +	target = DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq);

Not seeing any reason why it can't be DIV_ROUND_UP()?

> +	cnv_wf.period_length_ns = clamp(target, 100, 10 * KILO);
> +
> +	/*
> +	 * Use the maximum conversion time t_CNVH from the datasheet as
> +	 * the duty_cycle for ref_clk, cnv, and clk_gate
> +	 */
> +	cnv_wf.duty_length_ns = st->info->timing_spec->conv_high_ns;
> +
> +	ret = pwm_round_waveform_might_sleep(st->cnv_pwm, &cnv_wf);
> +	if (ret)
> +		return ret;
> +
> +	/*
> +	 * Set up the burst signal for transferring data. period and
> +	 * offset should mirror the CNV signal
> +	 */
> +	clk_gate_wf.period_length_ns = cnv_wf.period_length_ns;
> +
> +	clk_gate_wf.duty_length_ns = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC *
> +		st->info->chan_spec.scan_type.realbits,
> +		st->ref_clk_rate_hz);
> +
> +	/* max t_MSB from datasheet */
> +	clk_gate_wf.duty_offset_ns = st->info->timing_spec->conv_msb_ns;
> +
> +	ret = pwm_round_waveform_might_sleep(st->clk_gate_pwm, &clk_gate_wf);
> +	if (ret)
> +		return ret;
> +
> +	st->cnv_wf = cnv_wf;
> +	st->clk_gate_wf = clk_gate_wf;
> +
> +	/* TODO: Add a rounding API for PWMs that can simplify this */
> +	target = DIV_ROUND_CLOSEST_ULL(st->ref_clk_rate_hz, freq);

ditto...

> +	st->sampling_freq_hz = DIV_ROUND_CLOSEST_ULL(st->ref_clk_rate_hz,
> +						     target);
> +
> +	return 0;
> +}
> +
> 

...

> +
> +static int ad7625_buffer_preenable(struct iio_dev *indio_dev)
> +{
> +	struct ad7625_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	ret = pwm_set_waveform_might_sleep(st->cnv_pwm, &st->cnv_wf, false);
> +	if (ret)
> +		return ret;
> +
> +	ret = pwm_set_waveform_might_sleep(st->clk_gate_pwm,
> +					   &st->clk_gate_wf, false);
> +	if (ret) {
> +		/* Disable cnv PWM if clk_gate setup failed */
> +		pwm_disable(st->cnv_pwm);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static int ad7625_buffer_postdisable(struct iio_dev *indio_dev)
> +{
> +	struct ad7625_state *st = iio_priv(indio_dev);
> +
> +	pwm_disable(st->cnv_pwm);
> +	pwm_disable(st->clk_gate_pwm);
> +
> +	return 0;
> +}
> +

Might not matter but it is a good practise to disable things in the reverse
order.

- Nuno Sá



  reply	other threads:[~2024-09-05  7:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-04 19:14 [PATCH v4 0/3] iio: adc: add new ad7625 driver Trevor Gamblin
2024-09-04 19:14 ` [PATCH v4 1/3] dt-bindings: iio: adc: add AD762x/AD796x ADCs Trevor Gamblin
2024-09-05  6:35   ` Krzysztof Kozlowski
2024-09-08 11:53   ` Jonathan Cameron
2024-09-04 19:14 ` [PATCH v4 2/3] iio: adc: ad7625: add driver Trevor Gamblin
2024-09-05  7:58   ` Nuno Sá [this message]
2024-09-05 16:18     ` Trevor Gamblin
2024-09-07 22:50   ` kernel test robot
2024-09-08 11:59   ` Jonathan Cameron
2024-09-09 13:20     ` Trevor Gamblin
2024-09-04 19:14 ` [PATCH v4 3/3] docs: iio: new docs for ad7625 driver Trevor Gamblin
2024-09-04 19:16 ` [PATCH v4 0/3] iio: adc: add new " Trevor Gamblin
2024-09-05  8:01   ` Krzysztof Kozlowski
2024-09-05 16:32     ` Trevor Gamblin

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=23c81d6735075c0b9d98833641606a661fab7194.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --cc=tgamblin@baylibre.com \
    --cc=u.kleine-koenig@baylibre.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox