[PATCH 1/3] iio: frequency: adf4371: Create a power down/up function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Stefan Popa <stefan.popa@xxxxxxxxxx>

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@xxxxxxxxxx>
Signed-off-by: Beniamin Bia <beniamin.bia@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux