From: Jonathan Cameron <jic23@kernel.org>
To: Beniamin Bia <biabeniamin@outlook.com>
Cc: <lars@metafoo.de>, <Michael.Hennerich@analog.com>,
<knaack.h@gmx.de>, <pmeerw@pmeerw.net>,
<gregkh@linuxfoundation.org>, <linux-iio@vger.kernel.org>,
<devel@driverdev.osuosl.org>, <linux-kernel@vger.kernel.org>,
Beniamin Bia <biabeniamin@gmail.com>,
Beniamin Bia <beniamin.bia@analog.com>
Subject: Re: [PATCH v2 2/2] staging: iio: frequency: ad9833: Load clock using clock framework
Date: Sat, 2 Feb 2019 17:07:20 +0000 [thread overview]
Message-ID: <20190202170720.20dd9e4b@archlinux> (raw)
In-Reply-To: <20190201150138.31481-2-biabeniamin@outlook.com>
On Fri, 1 Feb 2019 17:01:38 +0200
Beniamin Bia <biabeniamin@outlook.com> wrote:
> From: Beniamin Bia <biabeniamin@gmail.com>
>
> The clock frequency is loaded from device-tree using clock framework
> instead of statically value. The change allow configuration of
> the device via device-trees and better initialization sequence.
> This is part of broader effort to add device-tree support to this driver
> and take it out from staging.
>
> Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.
Thanks,
Jonathan
> ---
> Changes in v2:
> -the intermidiate clk variable was replaced by the variable in
> device state
> -st variable may be uninitialized warning was fixed by adding a new
> error label
> drivers/staging/iio/frequency/ad9834.c | 35 ++++++++++++++++++--------
> 1 file changed, 24 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
> index f4f5eaa15e30..f036f75d1f22 100644
> --- a/drivers/staging/iio/frequency/ad9834.c
> +++ b/drivers/staging/iio/frequency/ad9834.c
> @@ -6,6 +6,7 @@
> * Licensed under the GPL-2.
> */
>
> +#include <linux/clk.h>
> #include <linux/interrupt.h>
> #include <linux/workqueue.h>
> #include <linux/device.h>
> @@ -71,7 +72,7 @@
> struct ad9834_state {
> struct spi_device *spi;
> struct regulator *reg;
> - unsigned int mclk;
> + struct clk *mclk;
> unsigned short control;
> unsigned short devid;
> struct spi_transfer xfer;
> @@ -110,12 +111,15 @@ static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
> static int ad9834_write_frequency(struct ad9834_state *st,
> unsigned long addr, unsigned long fout)
> {
> + unsigned long clk_freq;
> unsigned long regval;
>
> - if (fout > (st->mclk / 2))
> + clk_freq = clk_get_rate(st->mclk);
> +
> + if (fout > (clk_freq / 2))
> return -EINVAL;
>
> - regval = ad9834_calc_freqreg(st->mclk, fout);
> + regval = ad9834_calc_freqreg(clk_freq, fout);
>
> st->freq_data[0] = cpu_to_be16(addr | (regval &
> RES_MASK(AD9834_FREQ_BITS / 2)));
> @@ -415,7 +419,14 @@ static int ad9834_probe(struct spi_device *spi)
> spi_set_drvdata(spi, indio_dev);
> st = iio_priv(indio_dev);
> mutex_init(&st->lock);
> - st->mclk = 25000000;
> + st->mclk = devm_clk_get(&spi->dev, NULL);
> +
> + ret = clk_prepare_enable(st->mclk);
> + if (ret) {
> + dev_err(&spi->dev, "Failed to enable master clock\n");
> + goto error_disable_reg;
> + }
> +
> st->spi = spi;
> st->devid = spi_get_device_id(spi)->driver_data;
> st->reg = reg;
> @@ -460,31 +471,32 @@ static int ad9834_probe(struct spi_device *spi)
> ret = spi_sync(st->spi, &st->msg);
> if (ret) {
> dev_err(&spi->dev, "device init failed\n");
> - goto error_disable_reg;
> + goto error_clock_unprepare;
> }
>
> ret = ad9834_write_frequency(st, AD9834_REG_FREQ0, 1000000);
> if (ret)
> - goto error_disable_reg;
> + goto error_clock_unprepare;
>
> ret = ad9834_write_frequency(st, AD9834_REG_FREQ1, 5000000);
> if (ret)
> - goto error_disable_reg;
> + goto error_clock_unprepare;
>
> ret = ad9834_write_phase(st, AD9834_REG_PHASE0, 512);
> if (ret)
> - goto error_disable_reg;
> + goto error_clock_unprepare;
>
> ret = ad9834_write_phase(st, AD9834_REG_PHASE1, 1024);
> if (ret)
> - goto error_disable_reg;
> + goto error_clock_unprepare;
>
> ret = iio_device_register(indio_dev);
> if (ret)
> - goto error_disable_reg;
> + goto error_clock_unprepare;
>
> return 0;
> -
> +error_clock_unprepare:
> + clk_disable_unprepare(st->mclk);
> error_disable_reg:
> regulator_disable(reg);
>
> @@ -497,6 +509,7 @@ static int ad9834_remove(struct spi_device *spi)
> struct ad9834_state *st = iio_priv(indio_dev);
>
> iio_device_unregister(indio_dev);
> + clk_disable_unprepare(st->mclk);
> regulator_disable(st->reg);
>
> return 0;
prev parent reply other threads:[~2019-02-02 17:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190201150138.31481-1-biabeniamin@outlook.com>
2019-02-02 17:05 ` [PATCH v2 1/2] staging: iio: frequency: ad9833: Get frequency value statically Jonathan Cameron
[not found] ` <20190201150138.31481-2-biabeniamin@outlook.com>
2019-02-02 17:07 ` 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=20190202170720.20dd9e4b@archlinux \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=beniamin.bia@analog.com \
--cc=biabeniamin@gmail.com \
--cc=biabeniamin@outlook.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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