From: Jonathan Cameron <jic23@kernel.org>
To: Antoniu Miclaus <antoniu.miclaus@analog.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
"Rob Herring" <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>, <linux-iio@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] iio: frequency: adf4350: add clk provider
Date: Sat, 8 Jun 2024 16:15:15 +0100 [thread overview]
Message-ID: <20240608161515.0d63a803@jic23-huawei> (raw)
In-Reply-To: <20240607095806.3299-2-antoniu.miclaus@analog.com>
On Fri, 7 Jun 2024 12:57:53 +0300
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:
> Add clk provider feature for the adf4350.
>
> Even though the driver was sent as an IIO driver in most cases the
> device is actually seen as a clock provider.
>
> This patch aims to cover actual usecases requested by users in order to
> completely control the output frequencies from userspace.
>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> ---
> changes in v2:
> - rework commit title
> drivers/iio/frequency/adf4350.c | 129 ++++++++++++++++++++++++++++++++
> 1 file changed, 129 insertions(+)
>
> diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c
> index 4abf80f75ef5..1eb8bce71fe1 100644
> --- a/drivers/iio/frequency/adf4350.c
> +++ b/drivers/iio/frequency/adf4350.c
> @@ -19,6 +19,7 @@
> #include <linux/gpio/consumer.h>
> #include <asm/div64.h>
> #include <linux/clk.h>
> +#include <linux/clk-provider.h>
>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -31,11 +32,21 @@ enum {
> ADF4350_PWRDOWN,
> };
>
> +struct adf4350_output {
I can't see why this is needed. Looks to me like you only ever
go from hw here to the state. Use container_of to do that.
> + struct clk_hw hw;
> + struct iio_dev *indio_dev;
I wouldn't expect this clk_hw path to need the generic iio structure.
I think you only did this to make the lookup of adf4350_state possible?
If so, as above, container_of() is your friend.
> +};
> +
> +#define to_output(_hw) container_of(_hw, struct adf4350_output, hw)
> +
> struct adf4350_state {
> struct spi_device *spi;
> struct gpio_desc *lock_detect_gpiod;
> struct adf4350_platform_data *pdata;
> struct clk *clk;
> + struct clk *clkout;
> + const char *clk_out_name;
> + struct adf4350_output output;
> unsigned long clkin;
> unsigned long chspc; /* Channel Spacing */
> unsigned long fpfd; /* Phase Frequency Detector */
> @@ -264,6 +275,10 @@ static ssize_t adf4350_write(struct iio_dev *indio_dev,
> mutex_lock(&st->lock);
> switch ((u32)private) {
> case ADF4350_FREQ:
> + if (st->clkout) {
> + ret = clk_set_rate(st->clkout, readin);
> + break;
> + }
> ret = adf4350_set_freq(st, readin);
> break;
> case ADF4350_FREQ_REFIN:
> @@ -381,6 +396,115 @@ static const struct iio_info adf4350_info = {
> .debugfs_reg_access = &adf4350_reg_access,
> };
>
> +static void adf4350_clk_del_provider(void *data)
> +{
> + struct adf4350_state *st = data;
> +
> + of_clk_del_provider(st->spi->dev.of_node);
> +}
> +
> +static unsigned long adf4350_clk_recalc_rate(struct clk_hw *hw,
> + unsigned long parent_rate)
> +{
> + struct iio_dev *indio_dev = to_output(hw)->indio_dev;
You have the output in the state, so use container_of() to get to the
containing structure.
> + struct adf4350_state *st = iio_priv(indio_dev);
> + unsigned long long tmp;
> +
> + tmp = (u64)(st->r0_int * st->r1_mod + st->r0_fract) * st->fpfd;
> + do_div(tmp, st->r1_mod * (1 << st->r4_rf_div_sel));
> +
> + return tmp;
> +}
prev parent reply other threads:[~2024-06-08 15:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-07 9:57 [PATCH v2 1/2] dt-bindings: iio: adf4350: add clk provider prop Antoniu Miclaus
2024-06-07 9:57 ` [PATCH v2 2/2] iio: frequency: adf4350: add clk provider Antoniu Miclaus
2024-06-07 11:08 ` Nuno Sá
2024-06-08 15:08 ` Jonathan Cameron
2024-06-10 9:00 ` Hennerich, Michael
2024-06-08 15:15 ` 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=20240608161515.0d63a803@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=antoniu.miclaus@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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