Linux IIO development
 help / color / mirror / Atom feed
* [PATCH 1/2] drivers: iio: filter: admv8818: add bypass mode
@ 2023-07-26 14:33 Antoniu Miclaus
  2023-07-26 14:33 ` [PATCH 2/2] Documentation: ABI: testing: admv8818: add bypass Antoniu Miclaus
  2023-07-29 14:19 ` [PATCH 1/2] drivers: iio: filter: admv8818: add bypass mode Jonathan Cameron
  0 siblings, 2 replies; 3+ messages in thread
From: Antoniu Miclaus @ 2023-07-26 14:33 UTC (permalink / raw)
  To: jic23, linux-iio, linux-kernel; +Cc: Antoniu Miclaus

Add filter bypass mode, which bypasses the low pass filter, high pass
filter and disables/unregister the clock rate notifier.

The patch contains minimal changes in order to add the functionality.

It was requested by users of the driver to ease the interaction with
different configuration modes of the device.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 drivers/iio/filter/admv8818.c | 51 ++++++++++++++++++++++++++++++++---
 1 file changed, 48 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/filter/admv8818.c b/drivers/iio/filter/admv8818.c
index fe8d46cb7f1d..f0d6bb606507 100644
--- a/drivers/iio/filter/admv8818.c
+++ b/drivers/iio/filter/admv8818.c
@@ -78,6 +78,7 @@ enum {
 enum {
 	ADMV8818_AUTO_MODE,
 	ADMV8818_MANUAL_MODE,
+	ADMV8818_BYPASS_MODE,
 };
 
 struct admv8818_state {
@@ -114,7 +115,8 @@ static const struct regmap_config admv8818_regmap_config = {
 
 static const char * const admv8818_modes[] = {
 	[0] = "auto",
-	[1] = "manual"
+	[1] = "manual",
+	[2] = "bypass"
 };
 
 static int __admv8818_hpf_select(struct admv8818_state *st, u64 freq)
@@ -394,6 +396,36 @@ static int admv8818_reg_access(struct iio_dev *indio_dev,
 		return regmap_write(st->regmap, reg, write_val);
 }
 
+static int admv8818_filter_bypass(struct admv8818_state *st)
+{
+	int ret;
+
+	mutex_lock(&st->lock);
+
+	ret = regmap_update_bits(st->regmap, ADMV8818_REG_WR0_SW,
+				 ADMV8818_SW_IN_SET_WR0_MSK |
+				 ADMV8818_SW_IN_WR0_MSK |
+				 ADMV8818_SW_OUT_SET_WR0_MSK |
+				 ADMV8818_SW_OUT_WR0_MSK,
+				 FIELD_PREP(ADMV8818_SW_IN_SET_WR0_MSK, 1) |
+				 FIELD_PREP(ADMV8818_SW_IN_WR0_MSK, 0) |
+				 FIELD_PREP(ADMV8818_SW_OUT_SET_WR0_MSK, 1) |
+				 FIELD_PREP(ADMV8818_SW_OUT_WR0_MSK, 0));
+	if (ret)
+		goto exit;
+
+	ret = regmap_update_bits(st->regmap, ADMV8818_REG_WR0_FILTER,
+				 ADMV8818_HPF_WR0_MSK |
+				 ADMV8818_LPF_WR0_MSK,
+				 FIELD_PREP(ADMV8818_HPF_WR0_MSK, 0) |
+				 FIELD_PREP(ADMV8818_LPF_WR0_MSK, 0));
+
+exit:
+	mutex_unlock(&st->lock);
+
+	return ret;
+}
+
 static int admv8818_get_mode(struct iio_dev *indio_dev,
 			     const struct iio_chan_spec *chan)
 {
@@ -411,7 +443,10 @@ static int admv8818_set_mode(struct iio_dev *indio_dev,
 
 	if (!st->clkin) {
 		if (mode == ADMV8818_MANUAL_MODE)
-			return 0;
+			goto set_mode;
+
+		if (mode == ADMV8818_BYPASS_MODE)
+			goto bypass_filter;
 
 		return -EINVAL;
 	}
@@ -434,8 +469,9 @@ static int admv8818_set_mode(struct iio_dev *indio_dev,
 
 		break;
 	case ADMV8818_MANUAL_MODE:
+	case ADMV8818_BYPASS_MODE:
 		if (st->filter_mode)
-			return 0;
+			break;
 
 		clk_disable_unprepare(st->clkin);
 
@@ -448,6 +484,15 @@ static int admv8818_set_mode(struct iio_dev *indio_dev,
 		return -EINVAL;
 	}
 
+bypass_filter:
+	if (st->filter_mode != ADMV8818_BYPASS_MODE &&
+	    mode == ADMV8818_BYPASS_MODE) {
+		ret = admv8818_filter_bypass(st);
+		if (ret)
+			return ret;
+	}
+
+set_mode:
 	st->filter_mode = mode;
 
 	return ret;
-- 
2.41.0


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

end of thread, other threads:[~2023-07-29 14:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26 14:33 [PATCH 1/2] drivers: iio: filter: admv8818: add bypass mode Antoniu Miclaus
2023-07-26 14:33 ` [PATCH 2/2] Documentation: ABI: testing: admv8818: add bypass Antoniu Miclaus
2023-07-29 14:19 ` [PATCH 1/2] drivers: iio: filter: admv8818: add bypass mode Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox