diff mbox series

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

Message ID 20210328033639.1021599-3-gwendal@chromium.org (mailing list archive)
State New, archived
Headers show
Series iio: sx9310: Add debouncer-depth parameters | expand

Commit Message

Gwendal Grignou March 28, 2021, 3:36 a.m. UTC
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@chromium.org>
---
 drivers/iio/proximity/sx9310.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko March 28, 2021, 12:32 p.m. UTC | #1
On Sun, Mar 28, 2021 at 6:36 AM Gwendal Grignou <gwendal@chromium.org> wrote:
>
> 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.
...

> +               ret = device_property_read_u32(dev, "semtech,close-debouncer-depth", &depth);
> +               ret = device_property_read_u32(dev, "semtech,far-debouncer-depth", &depth);

Are they existing properties or new ones? To me sounds like the
latter. In such a case you missed DT bindings update.
Stephen Boyd March 29, 2021, 3:11 a.m. UTC | #2
Quoting Andy Shevchenko (2021-03-28 05:32:36)
> On Sun, Mar 28, 2021 at 6:36 AM Gwendal Grignou <gwendal@chromium.org> wrote:
> >
> > 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.
> ...
> 
> > +               ret = device_property_read_u32(dev, "semtech,close-debouncer-depth", &depth);
> > +               ret = device_property_read_u32(dev, "semtech,far-debouncer-depth", &depth);
> 
> Are they existing properties or new ones? To me sounds like the
> latter. In such a case you missed DT bindings update.

The bindings are part of patch #1.
Andy Shevchenko March 29, 2021, 11:12 a.m. UTC | #3
On Mon, Mar 29, 2021 at 6:11 AM Stephen Boyd <swboyd@chromium.org> wrote:
> Quoting Andy Shevchenko (2021-03-28 05:32:36)
> > On Sun, Mar 28, 2021 at 6:36 AM Gwendal Grignou <gwendal@chromium.org> wrote:
> > >
> > > 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.
> > ...
> >
> > > +               ret = device_property_read_u32(dev, "semtech,close-debouncer-depth", &depth);
> > > +               ret = device_property_read_u32(dev, "semtech,far-debouncer-depth", &depth);
> >
> > Are they existing properties or new ones? To me sounds like the
> > latter. In such a case you missed DT bindings update.
>
> The bindings are part of patch #1.

Thanks, it means _I am_ missing them :-)
diff mbox series

Patch

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;