[PATCH 2/2] iio: sx9310: Add debouncer-depth parameters

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

 



Semtech SX9310 SAR sensor has a debouncer filter: only when N
measurements are above/below the far/close threshold an event is
sent to the host.
By default the debouncer is set to 2 events for the close to far
transition and 1 event (no debounce) for far to close.
It is a balance speed of detection and false positive avoidance.

On some chromebooks, the debouncer is set to a larger number.

Signed-off-by: Gwendal Grignou <gwendal@xxxxxxxxxxxx>
---
 drivers/iio/proximity/sx9310.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 1ed749190bff9..6f92cf18fac31 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -1219,8 +1219,8 @@ static const struct sx9310_reg_default *
 sx9310_get_default_reg(struct device *dev, int idx,
 		       struct sx9310_reg_default *reg_def)
 {
+	u32 start = 0, raw = 0, pos = 0, depth = 0;
 	u32 combined[SX9310_NUM_CHANNELS];
-	u32 start = 0, raw = 0, pos = 0;
 	unsigned long comb_mask = 0;
 	int ret, i, count;
 	const char *res;
@@ -1325,6 +1325,25 @@ sx9310_get_default_reg(struct device *dev, int idx,
 		reg_def->def |= FIELD_PREP(SX9310_REG_PROX_CTRL7_AVGPOSFILT_MASK,
 					   pos);
 		break;
+	case SX9310_REG_PROX_CTRL10:
+		ret = device_property_read_u32(dev, "semtech,close-debouncer-depth", &depth);
+		if (ret)
+			raw = FIELD_GET(SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_MASK,
+					reg_def->def);
+		else
+			raw = ilog2(depth);
+		reg_def->def &= ~SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_MASK;
+		reg_def->def |= FIELD_PREP(SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_MASK, raw);
+
+		ret = device_property_read_u32(dev, "semtech,far-debouncer-depth", &depth);
+		if (ret)
+			raw = FIELD_GET(SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_MASK,
+					reg_def->def);
+		else
+			raw = ilog2(depth);
+		reg_def->def &= ~SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_MASK;
+		reg_def->def |= FIELD_PREP(SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_MASK, raw);
+		break;
 	}
 
 	return reg_def;
-- 
2.31.0.291.g576ba9dcdaf-goog




[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