devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] iio: frequency: adf4371: Create a power down/up function
@ 2019-12-19 13:37 Beniamin Bia
  2019-12-19 13:37 ` [PATCH 2/3] iio: frequency: adf4371: Introduce channel child nodes Beniamin Bia
  2019-12-19 13:37 ` [PATCH 3/3] dt-binding: iio: Add documentation for ADF4371 channel child notes Beniamin Bia
  0 siblings, 2 replies; 5+ messages in thread
From: Beniamin Bia @ 2019-12-19 13:37 UTC (permalink / raw)
  To: jic23
  Cc: knaack.h, lars, pmeerw, robh+dt, mark.rutland, Michael.Hennerich,
	linux-iio, devicetree, biabeniamin, Stefan Popa, Beniamin Bia

From: Stefan Popa <stefan.popa@analog.com>

This patch creates a helper function which powers down/up the PLL output
channels. Currently, this function is called only once, but it will be
needed in future patches to support multiple features.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
---
 drivers/iio/frequency/adf4371.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/frequency/adf4371.c b/drivers/iio/frequency/adf4371.c
index ff82863cbf42..7d77ebdbea82 100644
--- a/drivers/iio/frequency/adf4371.c
+++ b/drivers/iio/frequency/adf4371.c
@@ -321,6 +321,24 @@ static int adf4371_set_freq(struct adf4371_state *st, unsigned long long freq,
 	return regmap_write(st->regmap, ADF4371_REG(0x10), st->integer & 0xFF);
 }
 
+static int adf4371_channel_power_down(struct adf4371_state *st,
+				      unsigned int channel, bool power_down)
+{
+	unsigned int bit, readval, reg;
+	int ret;
+
+	reg = adf4371_pwrdown_ch[channel].reg;
+	bit = adf4371_pwrdown_ch[channel].bit;
+	ret = regmap_read(st->regmap, reg, &readval);
+	if (ret < 0)
+		return ret;
+
+	readval &= ~BIT(bit);
+	readval |= (!power_down << bit);
+
+	return regmap_write(st->regmap, reg, readval);
+}
+
 static ssize_t adf4371_read(struct iio_dev *indio_dev,
 			    uintptr_t private,
 			    const struct iio_chan_spec *chan,
@@ -372,7 +390,6 @@ static ssize_t adf4371_write(struct iio_dev *indio_dev,
 	struct adf4371_state *st = iio_priv(indio_dev);
 	unsigned long long freq;
 	bool power_down;
-	unsigned int bit, readval, reg;
 	int ret;
 
 	mutex_lock(&st->lock);
@@ -389,16 +406,7 @@ static ssize_t adf4371_write(struct iio_dev *indio_dev,
 		if (ret)
 			break;
 
-		reg = adf4371_pwrdown_ch[chan->channel].reg;
-		bit = adf4371_pwrdown_ch[chan->channel].bit;
-		ret = regmap_read(st->regmap, reg, &readval);
-		if (ret < 0)
-			break;
-
-		readval &= ~BIT(bit);
-		readval |= (!power_down << bit);
-
-		ret = regmap_write(st->regmap, reg, readval);
+		ret = adf4371_channel_power_down(st, chan->channel, power_down);
 		break;
 	default:
 		ret = -EINVAL;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-12-23 11:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19 13:37 [PATCH 1/3] iio: frequency: adf4371: Create a power down/up function Beniamin Bia
2019-12-19 13:37 ` [PATCH 2/3] iio: frequency: adf4371: Introduce channel child nodes Beniamin Bia
2019-12-23 11:02   ` Jonathan Cameron
2019-12-19 13:37 ` [PATCH 3/3] dt-binding: iio: Add documentation for ADF4371 channel child notes Beniamin Bia
2019-12-23 11:00   ` Jonathan Cameron

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).