summaryrefslogtreecommitdiffstats
path: root/drivers/iio/proximity/sx9310.c
AgeCommit message (Collapse)AuthorFilesLines
2022-01-23iio:proximity:sx9310: Extract common Semtech sensor logicGwendal Grignou1-605/+107
Before adding new Semtech sensors, move common logic to all Semtech SAR sensor in its own file: - interface with IIO subsystem, - interrupt management, - channel access conrol, - event processing. The change adds a bidirectional interface between sx93xx and sx_common. The change is quite mechanical, as the impacted functions are moved and renamed. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Link: https://lore.kernel.org/r/20220101203817.290512-3-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2022-01-23iio:proximity:sx9310: Add frequency in read_availGwendal Grignou1-26/+7
Instead of using IIO_DEV_ATTR_SAMP_FREQ_AVAIL sysfs attribute, add a _FREQ case in read_avail() to display the frequency table. No change to |sampling_frequency_available| was observed. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Link: https://lore.kernel.org/r/20220101203817.290512-2-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-07-31iio: sx9310: Support ACPI propertyGwendal Grignou1-32/+16
Use device_property_read_... to support both device tree and ACPI bindings. Simplify the logic for reading "combined-sensors" array, as we assume it has been vetted at firmware build time. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Link: https://lore.kernel.org/r/20210728181757.187627-1-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-05-17iio: core: move @id from struct iio_dev to struct iio_dev_opaqueJonathan Cameron1-1/+1
Continuing from Alexandru Ardelean's introduction of the split between driver modifiable fields and those that should only be set by the core. This could have been done in two steps to make the actual move after introducing iio_device_id() but there seemed limited point to that given how mechanical the majority of the patch is. Includes fixup from Alex for missing mxs-lradc-adc conversion. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Link: https://lore.kernel.org/r/20210426174911.397061-2-jic23@kernel.org
2021-04-07iio: sx9310: Fix write_.._debounce()Gwendal Grignou1-2/+10
Check input to be sure it matches Semtech sx9310 specification and can fit into debounce register. Compare argument writen to thresh_.._period with read from same sysfs attribute: Before: Afer: write | read write | read -1 | 8 -1 fails: -EINVAL 0 | 8 0 | 0 1 | 0 1 | 0 2..15 | 2^log2(N) 2..15 | 2^log2(N) 16 | 0 >= 16 fails: -EINVAL Fixes: 1b6872015f0b ("iio: sx9310: Support setting debounce values") Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Cc: stable@vger.kernel.org Reviewed-by: Stephen Boyd <swboyd@chromium.org> Link: https://lore.kernel.org/r/20210331182222.219533-1-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-04-07iio: sx9310: Fix access to variable DT arrayGwendal Grignou1-12/+28
With the current code, we want to read 4 entries from DT array "semtech,combined-sensors". If there are less, we silently fail as of_property_read_u32_array() returns -EOVERFLOW. First count the number of entries and if between 1 and 4, collect the content of the array. Fixes: 5b19ca2c78a0 ("iio: sx9310: Set various settings from DT") Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20210326184603.251683-2-gwendal@chromium.org Cc: <stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-03-25iio: fix devm_iio_trigger_alloc with parent.cocciGwendal Grignou1-1/+0
Use cocci semantic patch: @@ expression trigger, P; @@ trigger = devm_iio_trigger_alloc(P, ...); ... - trigger->dev.parent = P; To remove trigger->dev.parent, since it is set by default. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20210309193620.2176163-3-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-01-14iio: sx9310: Fix semtech,avg-pos-strength setting when > 16Stephen Boyd1-1/+2
This DT property can be 0, 16, and then 64, but not 32. The math here doesn't recognize this slight bump in the power of 2 numbers and translates a DT property of 64 into the register value '3' when it really should be '2'. Fix it by subtracting one more if the number being translated is larger than 31. Also use clamp() because we're here. Cc: Daniel Campello <campello@chromium.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Douglas Anderson <dianders@chromium.org> Cc: Gwendal Grignou <gwendal@chromium.org> Cc: Evan Green <evgreen@chromium.org> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Douglas Anderson <dianders@chromium.org> Link: https://lore.kernel.org/r/20201202200252.986230-1-swboyd@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-01-14iio: sx9310: Off by one in sx9310_read_thresh()Dan Carpenter1-1/+1
This > should be >= to prevent reading one element beyond the end of the sx9310_pthresh_codes[] array. Fixes: ad2b473e2ba3 ("iio: sx9310: Support setting proximity thresholds") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Douglas Anderson <dianders@chromium.org> Link: https://lore.kernel.org/r/X8XqwK0z//8sSWJR@mwanda Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-10-10iio: sx9310: Set various settings from DTStephen Boyd1-1/+124
These properties need to be set during driver probe. Parse any DT properties and replace the default register settings with the ones parsed from DT. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Cc: Daniel Campello <campello@chromium.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Rob Herring <robh+dt@kernel.org> Cc: <devicetree@vger.kernel.org> Cc: Douglas Anderson <dianders@chromium.org> Cc: Gwendal Grignou <gwendal@chromium.org> Cc: Evan Green <evgreen@chromium.org> Link: https://lore.kernel.org/r/20201007011735.1346994-7-swboyd@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-10-10iio: sx9310: Support setting debounce valuesStephen Boyd1-0/+100
The rising and falling directions can be debounced in the hardware as "close" and "far" debounce settings. Add support for these as rising and falling debounce settings. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Cc: Daniel Campello <campello@chromium.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Douglas Anderson <dianders@chromium.org> Cc: Gwendal Grignou <gwendal@chromium.org> Cc: Evan Green <evgreen@chromium.org> Link: https://lore.kernel.org/r/20201007011735.1346994-5-swboyd@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-10-10iio: sx9310: Support setting hysteresis valuesStephen Boyd1-1/+61
Add support for setting the hysteresis as a shifted value of a channel's proximity threshold. Each channel can have a different threshold, but the hysteresis applies to all channels as a right shift factor. Therefore, duplicate the hysteresis value across all channels and make it depend on the channel's proximity threshold. This is sort of odd but seems to work in practice as most of the time only one channel is used. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Cc: Daniel Campello <campello@chromium.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Douglas Anderson <dianders@chromium.org> Cc: Gwendal Grignou <gwendal@chromium.org> Cc: Evan Green <evgreen@chromium.org> Link: https://lore.kernel.org/r/20201007011735.1346994-4-swboyd@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-10-10iio: sx9310: Support setting proximity thresholdsStephen Boyd1-0/+114
Add support to set the proximity thresholds for each channel. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Cc: Daniel Campello <campello@chromium.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Douglas Anderson <dianders@chromium.org> Cc: Gwendal Grignou <gwendal@chromium.org> Cc: Evan Green <evgreen@chromium.org> Link: https://lore.kernel.org/r/20201007011735.1346994-3-swboyd@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-10-10iio: sx9310: Support hardware gain factorStephen Boyd1-5/+104
Add support to set the hardware gain of the channels as a multiplier of 2x, 4x, or 8x. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Cc: Daniel Campello <campello@chromium.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Douglas Anderson <dianders@chromium.org> Cc: Gwendal Grignou <gwendal@chromium.org> Cc: Evan Green <evgreen@chromium.org> Link: https://lore.kernel.org/r/20201007011735.1346994-2-swboyd@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-06iio: sx9310: Prefer async probeDouglas Anderson1-0/+7
On one board I found that: probe of 5-0028 returned 1 after 259547 usecs While some of this time is attributable to the pile of i2c transfers that we do at probe time, the lion's share (over 200 ms) is sitting waiting in the polling loop in sx9310_init_compensation() waiting for the hardware to indicate that it's done. There's no reason to block probe of all other devices on our probe. Turn on async probe. Signed-off-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Daniel Campello <campello@chromium.org> Link: https://lore.kernel.org/r/20200901081920.v2.1.Id02b2f451b3eed71ddd580f4b8b44b3e33e84970@changeid Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Use irq trigger flags from firmwareStephen Boyd1-1/+1
We shouldn't need to set default irq trigger flags here as the firmware should have properly indicated the trigger type, i.e. level low, in the DT or ACPI tables. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Enable vdd and svdd regulators at probeStephen Boyd1-0/+26
Enable the main power supply (vdd) and digital IO power supply (svdd) during probe so that the i2c communication and device works properly on boards that aggressively power gate these supplies. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Drop channel_users[]Stephen Boyd1-1/+0
This struct member isn't used. Drop it. Fixes: 72ad02b15d63 ("iio: Add SEMTECH SX9310/9311 sensor driver") Signed-off-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Daniel Campello <campello@chromium.org> Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Miscellaneous format fixesDaniel Campello1-18/+10
Miscellaneous format fixes throughout the whole file. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Use variable to hold &client->devDaniel Campello1-14/+14
Improves readability by storing &client->dev in a local variable. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Simplify error return handlingDaniel Campello1-28/+28
Checks for non-zero return values to signal error conditions. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Update copyrightDaniel Campello1-2/+2
Fixes wrong copyright year. Signed-off-by: Daniel Campello <campello@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Use regmap_read_poll_timeout() for compensationDaniel Campello1-15/+10
Simplify compensation stage by using regmap_read_poll_timeout(). Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Use long instead of int for channel bitmapsDaniel Campello1-18/+21
Uses for_each_set_bit() macro to loop over channel bitmaps. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Fixes various memory handlingDaniel Campello1-5/+8
Makes use __aligned(8) to ensure that the timestamp is correctly aligned when we call io_push_to_buffers_with_timestamp(). Also makes use of sizeof() for regmap_bulk_read instead of static value. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Change from .probe to .probe_newDaniel Campello1-25/+14
Uses .probe_new in place of .probe. Also uses device_get_match_data() for whoami matching. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Remove acpi and of table macrosDaniel Campello1-3/+3
Avoids unused warnings due to acpi/of table macros. Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Fix irq handlingDaniel Campello1-3/+8
Fixes enable/disable irq handling at various points. The driver needs to only enable/disable irqs if there is an actual irq handler installed. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-03iio: sx9310: Update macros declarationsDaniel Campello1-78/+68
Follows spec sheet for macro declarations. Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-06-20iio: Move attach/detach of the poll func to the coreLars-Peter Clausen1-2/+0
All devices using a triggered buffer need to attach and detach the trigger to the device in order to properly work. Instead of doing this in each and every driver by hand move this into the core. At this point in time, all drivers should have been resolved to attach/detach the poll-function in the same order. This patch removes all explicit calls of iio_triggered_buffer_postenable() & iio_triggered_buffer_predisable() in all drivers, since the core handles now the pollfunc attach/detach. The more peculiar change is for the 'at91-sama5d2_adc' driver, since it's not immediately obvious that removing the hooks doesn't break anything. Eugen was able to test on at91-sama5d2-adc driver, sama5d2-xplained board. All seems to be fine. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Tested-by: Eugen Hristev <eugen.hristev@microchip.com> #for at91-sama5d2-adc Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-06-14iio: remove explicit IIO device parent assignmentAlexandru Ardelean1-1/+0
This patch applies the semantic patch: @@ expression I, P, SP; @@ I = devm_iio_device_alloc(P, SP); ... - I->dev.parent = P; It updates 302 files and does 307 deletions. This semantic patch also removes some comments like '/* Establish that the iio_dev is a child of the i2c device */' But this is is only done in case where the block is left empty. The patch does not seem to cover all cases. It looks like in some cases a different variable is used in some cases to assign the parent, but it points to the same reference. In other cases, the block covered by ... may be just too big to be covered by the semantic patch. However, this looks pretty good as well, as it does cover a big bulk of the drivers that should remove the parent assignment. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-03-21iio: Add SEMTECH SX9310/9311 sensor driverDaniel Campello1-0/+1069
Add SEMTECH SX9310/9311 driver. The device has the following entry points: Usual frequency: - sampling_frequency - sampling_frequency_available Instant reading of current values for different sensors: - in_proximity0_raw - in_proximity1_raw - in_proximity2_raw - in_proximity3_comb_raw and associated events in events/ Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Signed-off-by: Enrico Granata <egranata@chromium.org> Signed-off-by: Daniel Campello <campello@chromium.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>