devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Marcelo Schmitt <marcelo.schmitt@analog.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: jic23@kernel.org, lars@metafoo.de, Michael.Hennerich@analog.com,
	nuno.sa@analog.com, andy@kernel.org, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org,
	linus.walleij@linaro.org, brgl@bgdev.pl,
	marcelo.schmitt1@gmail.com
Subject: Re: [PATCH v5 07/11] iio: adc: ad4170: Add clock provider support
Date: Mon, 16 Jun 2025 16:11:29 -0500	[thread overview]
Message-ID: <656c43dd-c39d-4e35-a9d8-70383c0836a0@baylibre.com> (raw)
In-Reply-To: <5ac4b2d54f426d997cbb067530ab8e9af9bdcf16.1749582679.git.marcelo.schmitt@analog.com>

On 6/10/25 3:33 PM, Marcelo Schmitt wrote:
> The AD4170 chip can use an externally supplied clock at the XTAL2 pin, or
> an external crystal connected to the XTAL1 and XTAL2 pins. Alternatively,
> the AD4170 can provide its 16 MHz internal clock at the XTAL2 pin. In
> addition, the chip has a programmable clock divider that allows dividing
> the external or internal clock frequency, however, control for that is not
> provided in this patch. Extend the AD4170 driver so it effectively uses the
> provided external clock, if any, or supplies its own clock as a clock
> provider.
> 

...

> +static int ad4170_clock_select(struct iio_dev *indio_dev)
> +{
> +	struct ad4170_state *st = iio_priv(indio_dev);
> +	struct device *dev = &st->spi->dev;
> +	struct clk *ext_clk;
> +	int ret;
> +
> +	ext_clk = devm_clk_get_optional_enabled(dev, NULL);
> +	if (IS_ERR(ext_clk))
> +		return dev_err_probe(dev, PTR_ERR(ext_clk),
> +				     "Failed to get external clock\n");
> +
> +	if (!ext_clk) {
> +		/* Use internal clock reference */
> +		st->mclk_hz = AD4170_INT_CLOCK_16MHZ;
> +		st->clock_ctrl |= FIELD_PREP(AD4170_CLOCK_CTRL_CLOCKSEL_MSK,
> +					     AD4170_CLOCK_CTRL_CLOCKSEL_INT_OUT);
> +
> +		if (!device_property_read_bool(&st->spi->dev, "#clock-cells"))

This isn't a flag, so device_property_present() is probably more correct.

> +			return 0;
> +
> +		return ad4170_register_clk_provider(indio_dev);
> +	}
> +
> +	/* Read optional clock-names prop to specify the external clock type */
> +	ret = device_property_match_property_string(dev, "clock-names",
> +						    ad4170_clk_sel,
> +						    ARRAY_SIZE(ad4170_clk_sel));
> +
> +	ret = ret < 0 ? 0 : ret; /* Default to external clock if no clock-names */
> +	st->clock_ctrl |= FIELD_PREP(AD4170_CLOCK_CTRL_CLOCKSEL_MSK,
> +				     AD4170_CLOCK_CTRL_CLOCKSEL_EXT + ret);
> +
> +	st->mclk_hz = clk_get_rate(ext_clk);
> +	if (st->mclk_hz < AD4170_EXT_CLOCK_MHZ_MIN ||
> +	    st->mclk_hz > AD4170_EXT_CLOCK_MHZ_MAX) {
> +		return dev_err_probe(dev, -EINVAL,
> +				     "Invalid external clock frequency %u\n",
> +				     st->mclk_hz);
> +	}
> +
> +	return 0;
> +}


  reply	other threads:[~2025-06-16 21:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-10 20:30 [PATCH v5 00/11] iio: adc: Add support for AD4170 series of ADCs Marcelo Schmitt
2025-06-10 20:31 ` [PATCH v5 01/11] dt-bindings: iio: adc: Add AD4170 Marcelo Schmitt
2025-06-16 15:41   ` Conor Dooley
2025-06-16 17:58     ` Marcelo Schmitt
2025-06-16 20:41     ` David Lechner
2025-06-21 16:28       ` Jonathan Cameron
2025-06-23 16:03         ` Conor Dooley
2025-06-21 16:37     ` Jonathan Cameron
2025-06-10 20:31 ` [PATCH v5 02/11] iio: adc: Add basic support for AD4170 Marcelo Schmitt
2025-06-10 21:10   ` Andy Shevchenko
2025-06-11 21:04     ` Marcelo Schmitt
2025-06-12 12:48       ` Andy Shevchenko
2025-06-12 14:03         ` Marcelo Schmitt
2025-06-12 18:48           ` Andy Shevchenko
2025-06-14 10:51             ` Jonathan Cameron
2025-06-14 10:52         ` Jonathan Cameron
2025-06-16 20:41   ` David Lechner
2025-06-17 18:54     ` Marcelo Schmitt
2025-06-18 17:37   ` Dan Carpenter
2025-06-18 17:59     ` Andy Shevchenko
2025-06-10 20:31 ` [PATCH v5 03/11] iio: adc: ad4170: Add support for calibration gain Marcelo Schmitt
2025-06-10 20:32 ` [PATCH v5 04/11] iio: adc: ad4170: Add support for calibration bias Marcelo Schmitt
2025-06-10 20:32 ` [PATCH v5 05/11] iio: adc: ad4170: Add digital filter and sample frequency config support Marcelo Schmitt
2025-06-16 20:53   ` David Lechner
2025-06-10 20:32 ` [PATCH v5 06/11] iio: adc: ad4170: Add support for buffered data capture Marcelo Schmitt
2025-06-10 21:17   ` Andy Shevchenko
2025-06-10 20:33 ` [PATCH v5 07/11] iio: adc: ad4170: Add clock provider support Marcelo Schmitt
2025-06-16 21:11   ` David Lechner [this message]
2025-06-17  6:24     ` Andy Shevchenko
2025-06-10 20:33 ` [PATCH v5 08/11] iio: adc: ad4170: Add GPIO controller support Marcelo Schmitt
2025-06-18 10:15   ` Linus Walleij
2025-06-10 20:33 ` [PATCH v5 09/11] iio: adc: ad4170: Add support for internal temperature sensor Marcelo Schmitt
2025-06-10 20:33 ` [PATCH v5 10/11] iio: adc: ad4170: Add support for weigh scale and RTD sensors Marcelo Schmitt
2025-06-10 20:34 ` [PATCH v5 11/11] iio: adc: ad4170: Add timestamp channel Marcelo Schmitt
2025-06-14 11:04 ` [PATCH v5 00/11] iio: adc: Add support for AD4170 series of ADCs 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=656c43dd-c39d-4e35-a9d8-70383c0836a0@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=marcelo.schmitt@analog.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@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;
as well as URLs for NNTP newsgroup(s).