summaryrefslogtreecommitdiff
path: root/drivers/iio/imu/adis16400.c
AgeCommit message (Collapse)Author
2023-03-11iio: imu: Replace all spi->chip_select and spi->cs_gpiod references with ↵Amit Kumar Mahapatra
function call Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod members of struct spi_device to be an array. But changing the type of these members to array would break the spi driver functionality. To make the transition smoother introduced four new APIs to get/set the spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and spi->cs_gpiod references with get or set API calls. While adding multi-cs support in further patches the chip_select & cs_gpiod members of the spi_device structure would be converted to arrays & the "idx" parameter of the APIs would be used as array index i.e., spi->chip_select[idx] & spi->cs_gpiod[idx] respectively. Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Michal Simek <michal.simek@amd.com> Link: https://lore.kernel.org/r/20230310173217.3429788-4-amit.kumar-mahapatra@amd.com Signed-off-by: Mark Brown <broonie@kernel.org>
2022-11-23iio: imu: adis16400: Call '__adis_initial_startup()' in probeRamona Bolboaca
Call '__adis_initial_startup()' instead of its locked variant in 'adis16400_probe()'. The locks are not needed at this point. Signed-off-by: Ramona Bolboaca <ramona.bolboaca@analog.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20221122082757.449452-7-ramona.bolboaca@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2022-02-18iio:imu:adis: Move exports into IIO_ADISLIB namespaceJonathan Cameron
In order to avoid unneessary pollution of the global symbol namespace move the common/library functions into a specific namespace and import that into the various specific device drivers that use them. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Song Bao Hua (Barry Song) <song.bao.hua@hisilicon.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20220130205701.334592-9-jic23@kernel.org
2021-10-19iio: imu: adis16400: Fix buffer alignment requirements.Jonathan Cameron
iio_push_to_buffers_with_timestamp() requires that the buffer is 8 byte alignment to ensure an inserted timestamp is naturally aligned. This requirement was not met here when burst mode is in use beause of a leading u16. Use the new iio_push_to_buffers_with_ts_unaligned() function that has more relaxed requirements. It is somewhat complex to access that actual data length, but a safe bound can be found by using scan_bytes - sizeof(timestamp) so that is used in this path. More efficient approaches exist, but this ensure correctness at the cost of using a bounce buffer. Fixes: 5075e0720d93 ("iio: imu: adis: generalize burst mode support") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20210613151039.569883-5-jic23@kernel.org
2021-06-13iio: imu: remove unused private data assigned with spi_set_drvdata()Alexandru Ardelean
These were usually used before the conversion to devm_ functions, so that the remove hook would be able to retrieve the pointer and do cleanups on remove. When the conversion happened, they should have been removed, but were omitted. Some drivers were copied from drivers that fit the criteria described above. In any case, in order to prevent more drivers from being used as example (and have spi_set_drvdata() needlessly set), this change removes it from the IIO IMU group. Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com> Link: https://lore.kernel.org/r/20210513122512.93187-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-06-04iio: adis: Cleanout unused headersJonathan Cameron
0-day recently added the include-what-you-use header checker and it gave a warning on an adis patch. As such I decided to run it on all the adis drivers and see if it made sensible suggestions. Note this doesn't represent a complete list of what it suggested changing as I filtered out a few on the basis they are standard headers used to effectively include a bunch of other headers. Could split this into a patch per driver if people prefer. Note to anyone else trying this tool is that it is somewhat of a loose cannon so you will be wanting to carefully check any suggestions before proposing patches! I thought about also reorganising the headers whilst here, but that would make this patch harder to read, or lead to another rather noisy patch across most of the files. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Link: https://lore.kernel.org/r/20210603193616.3708447-1-jic23@kernel.org
2021-05-17iio: adis16400: do not directly change spi 'max_speed_hz'Nuno Sa
With commit 3ba10e37371d ("iio: adis: add burst_max_speed_hz variable"), we just need to define 'burst_max_speed_hz' and the adis core will take care of setting up the spi transfers for burst mode. Hence, we fix a potential race with the spi core where we could be left witn an invalid 'max_speed_hz'. Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Fixes: 5eda3550a3cc1 ("staging:iio:adis16400: Preallocate transfer message") Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20210427085454.30616-7-nuno.sa@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-05-17iio: adis16400: do not return ints in irq handlersNuno Sa
On an IRQ handler we should not return normal error codes as 'irqreturn_t' is expected. Not necessary to apply to stable as the original check cannot fail and as such the bug cannot actually occur. Fixes: 5eda3550a3cc1 ("staging:iio:adis16400: Preallocate transfer message") Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20210422101911.135630-3-nuno.sa@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-03-26Merge tag 'iio-for-5.13a' of ↵Greg Kroah-Hartman
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: 1st set of IIO/counter device support, features and cleanup in the 5.13 cycle Big set in here from Alexandru Ardelean enabling multiple buffer support. This includes providing a new directory per buffer that combines what was previously in buffer/ and scan_elements/. Old interfaces still in place for compatiblity. Note immuatable branch for scmi patches to allow for some significant rework going on in that subsystem. Merge required updating to reflect some changes in IIO. Late rebase to fix some wrong fixes tags due to some earlier rebases made necessary by messing up the immutable branch. IIO New Device Support * adi,ad5686 - Add info to support AD5673R and AD5677R * bosch,bmi088 - New driver supporting this accelerometer + gyroscope * cros_ec_mkbp - New driver for this proximity sensor that exposes a 'front' sensor. Very simple switch like device, but driver allows it to share interface with more sophisticated proximity sensors. * iio_scmi - New driver to support ARM SCMI protocol to expose underlying accelerometers and gyroscopes via this firmware interface. * st,st_magn - Add ID for IISMDC magnetometer. * ti,ads131e0 - New driver supporting ads131e04, ads131e06 and ads131e08 24 bit ADCs Counter New Device Support * IRQ or GPIO based counter - New driver for a conceptually simple counter that uses interrupts to perform the count. Features * core - Dual buffer supprt including: Various helpers to centralize handling of bufferer related elements. Document existing and new IOCTLs Register the IIO chrdev only if it can actually be used for anything. Rework attribute group creation in the core (lots of patches) Merge buffer/ and scan_elements/ entries into one list + maintain backwards compatible set. Introduce the internal logic and IOCTL to allow multiple buffers + access to an anon FD per buffer to actually read from it. Tidy up tools/iio/iio_generic_buffer and switch to new interfaces. Update ABI docs. A few follow up fixes, unsuprising as this was a huge bit of rework. - Move common case setting of trig->parent to the core. - Provide an iio_read_channel_processed_scale() to avoid loss of precision from iio_read_channel_processed() then applying integer scale. Use it in ntc_thermistor driver in hwmon. - Allow drivers to specify labels from elsewhere than DT. Use it for bmc150 and kxcjk-1013 labels related to position on 2 in one tablets. - Document label usage for proximity and accelerometer sensors. - Some local variable renames for consistency tools - Add -a parameter to iio_event_monitor to allow autoenabling of events. * acpi_als - Add trigger support for devices that don't support notification method. * adi,ad7124 - Allow more than 8 channels. This is a complex little device, but is capable of supporting up to 16 channels if the share certain configuration settings. * hrtimer-trigger - Support sampling frequency below 1Hz. * mediatek,mt8195-auxadc - Add compatible to binding docs (always also includes mt8173) * st,stm32-adc - Enable timetamps when not using DMA. * vishay,vcnl3020 - Sampling frequency control. Cleanup and minor fixes: * treewide - Use some getter and setter functions instead of opencoding. - Set of fixes for pointless casts in various drivers. - Avoid wrong kernel-doc marking on comment blocks. - Fix various other minor kernel-doc issues shown by W=1 * core - Use a signed temporary for IIO_VAL_FRACTIONAL_LOG2 to avoid odd casts. - Fix IIO_VAL_FRACTIONAL_LOG2 for values between -1.0 and 0.0 - Add unit tests for iio_format_value() * docs - Fix formatting/typos in iio_configfs.rst and buffers.rst - Add documentation of index in buffers.rst - Fix scan element description - Avoid some issues with HTML generation from ABI docs by moving duplicated defintions to more generic files. - Drop reference to long dead mailing list. * 104-quad - Remove left over deprecated IIO counter ABI. * adi,adi-axi-adc - Fix wrong bit of docs. * adi,ad5791 - Typos * adi,ad9834 - Switch to device managed functions in probe. * adi,adis* - Add and use helpers for locking to reduced duplication. * adi,adis16480 - Fix calculation of sampling frequency when using pulse per second input. * adi,adis16475 - Calculate the IMU scaled internal sampling rate and runtime depending on sysfs based configuration rather than getting from DT. Drop now unnecessary property from DT bindings doc. * cros_ec - Fix result of a series of recent changes that means extended buffer attributes turn up in the wrong place. Too complex to revert the various patches unfortunately so this is a bit messy. * fsl,mma3452 - Indentation cleanup. * hid-sensors - Size of storage needs to increase for some parts when using quaternions. - Move the get sensistivity attribute to hid-sensors-common to reduce duplication. Enable it for more device types. - Correctly handle relative sensitivity if reported that way including documenting the new ABI. * maxim,max517 - Use device managed functions in probe. * mediatek,mt6360-adc - Use asm/unaligned.h instead of directly including unaligned/be_byteshift.h * novuton,npcm-adc - Local lock instead of missusing mlock. * semtech,sx9500 - Typos * st,sensor - typo fix * st,spear-adc - Local lock instead of missusing mlock. * st,stm32-adc - Long standing HAS_IOMEM dependency fix. * st,stm32-counter - Remove left over deprecated IIO counter ABI. * ti,palmas-adc - Local lock instead of missusing mlock. * ti,tmp007 - Switch to device managed functions in probe. Other * MAINTAINERS - Move Peter Meerwald-Stadler to Credits at his request * tag 'iio-for-5.13a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (119 commits) iio: acpi_als: Add trigger support iio: acpi_als: Add local variable dev in probe iio: acpi_als: Add timestamp channel iio: adc: ad7292: Modify the bool initialization assignment iio: cros: unify hw fifo attributes without API changes iio: kfifo: add devm_iio_triggered_buffer_setup_ext variant iio: event_monitor: Enable events before monitoring dt-bindings: iio: adc: Add compatible for Mediatek MT8195 iio:magnetometer: Add Support for ST IIS2MDC dt-bindings: iio: st,st-sensors add IIS2MDC. staging: iio: ad9832: kernel-doc fixes iio:dac:max517.c: Use devm_iio_device_register() iio:cros_ec_sensors: Fix a wrong function name in kernel doc. iio: buffer: kfifo_buf: kernel-doc, typo in function name. iio: accel: sca3000: kernel-doc fixes. Missing - and wrong function names. iio: adc: adi-axi-adc: Drop false marking for kernel-doc iio: adc: cpcap-adc: kernel-doc fix - that should be _ in structure name iio: dac: ad5504: fix wrong part number in kernel-doc structure name. iio: dac: ad5770r: kernel-doc fix case of letter R wrong in structure name iio: adc: ti-adc084s021: kernel-doc fixes, missing function names ...
2021-03-11iio: adis: add helpers for lockingNuno Sa
Add some helpers to lock and unlock the device. As this is such a simple change, we update all the users that were using the lock already in this patch. Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20210218114039.216091-5-nuno.sa@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-02-21iio: adis16400: Fix an error code in adis16400_initial_setup()Dan Carpenter
This is to silence a new Smatch warning: drivers/iio/imu/adis16400.c:492 adis16400_initial_setup() warn: sscanf doesn't return error codes If the condition "if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) {" is false then we return 1 instead of returning 0 and probe will fail. Fixes: 72a868b38bdd ("iio: imu: check sscanf return value") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: <Stable@vger.kernel.org> Link: https://lore.kernel.org/r/YCwgFb3JVG6qrlQ+@mwanda Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-09-21iio: adis16400: Drop adis_burst usageNuno Sá
Burst mode variables are now part of the `adis_data` struct. The driver also has now to explicitly define the length of the burst buffer. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/20200917155223.218500-3-nuno.sa@analog.com
2020-09-17iio:imu:adis16400: Sort out missing kernel doc.Jonathan Cameron
I'd like to be enable W=1 for all IIO builds as it catches real issues as well as more minor documentation issues such as this (also good to fix though!) drivers/iio/imu/adis16400.c:183: warning: Function parameter or member 'avail_scan_mask' not described in 'adis16400_state' Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Cc: Alexandru Ardelean <alexandru.ardelean@analog.com> Link: https://lore.kernel.org/r/20200913132115.800131-2-jic23@kernel.org
2020-09-16iio: adis16400: Use Managed device functionsNuno Sá
Use the adis managed device functions to setup the buffer and the trigger. The ultimate goal will be to completely drop the non devm version from the lib. Since we are here, drop the `.remove` callback by further using devm functions. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20200915120258.161587-6-nuno.sa@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-06-14iio: remove explicit IIO device parent assignmentAlexandru Ardelean
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-05-03iio: imu: adis16xxx: use helper to access iio core debugfs dirAlexandru Ardelean
The IIO core provides a iio_get_debugfs_dentry() helper. It seems that the ADIS IMU drivers access that field directly. This change converts them to use iio_get_debugfs_dentry() instead. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Acked-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-04-25iio: adis: Support different burst sizesNuno Sá
Add burst_max_len to `adis_burst`. This is useful for devices which support different burst modes with different sizes. The buffer to be used in the spi transfer is allocated with this variable making sure that has space for all burst modes. The spi transfer length should hold the "real" burst length depending on the current burst mode configured in the device. Moreover, `extra_len` in `adis_burst` is made const and it should contain the smallest extra length necessary for a burst transfer. In `struct adis` was added a new `burst_extra_len` that should hold the extra bytes needed depending on the device instance being used. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-04-19iio: imu: adis16400: use DEFINE_DEBUGFS_ATTRIBUTE instead of ↵Rohit Sarkar
DEFINE_SIMPLE_ATTRIBUTE debugfs_create_file_unsafe does not protect the fops handed to it against file removal. DEFINE_DEBUGFS_ATTRIBUTE makes the fops aware of the file lifetime and thus protects it against removal. Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com> Tested-by Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-03-08iio: imu: adis: Add self_test_reg variableNuno Sá
This patch adds a dedicated self_test_reg variable. This is also a step to let new drivers make use of `adis_initial_startup()`. Some devices use MSG_CTRL reg to request a self_test command while others use the GLOB_CMD register. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-03-08iio: imu: adis16400: initialize adis_data staticallyAlexandru Ardelean
This change overrides commit 380b107bbf944 ("iio: adis: Introduce timeouts structure"). It removes the memory allocation and moves the 'adis_data' information to be static on the chip_info struct. This also adds a timeout structure to ADIS16334, since it was initially omitted. This was omitted (by accident) when the change was done. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-12iio: adis: Remove startup_delayNuno Sá
All timeouts are now handled by a dedicated timeout struct. This variable is no longer needed. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-12iio: adis: Introduce timeouts structureNuno Sá
The adis library only allows to define a `startup_delay` which for some devices is enough. However, other devices define different timeouts with significantly different timings which could lead to devices to not wait enough time or to wait a lot more than necessary (which is not efficient). This patch introduces a new timeout struct that must be passed into `adis_init()`. There are mainly, for now, three timeouts used. This is also an introductory patch with the goal of refactoring `adis_initial_startup()`. New driver's (eg: adis16480, adis16460) are replicating code for the device initial setup. With some changes (being this the first one) we can pass this to `adis_initial_startup()`. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-23iio: imu: adis16400: rework locks using ADIS library's state lockAlexandru Ardelean
This change removes the use of indio_dev's mlock in favor using the state lock from the ADIS library. The set_freq() & get_freq() hooks are unlocked, so they require specific locking. That is because in some cases the get_freq() hook is used in combination with adis16400_set_filter(). In cases where only one read/write is done, the functions that hold the state lock are used. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-03iio: imu: adis16400: check ret val for non-zero vs less-than-zeroAlexandru Ardelean
The ADIS library functions return zero on success, and negative values for error. Positive values aren't returned, but we only care about the success value (which is zero). This change is mostly needed so that the compiler won't make any inferences about some about values being potentially un-initialized. This only triggers after making some functions inline, because the compiler can better follow return paths. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-06-19treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500Thomas Gleixner
Based on 2 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation # extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 4122 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Enrico Weigelt <info@metux.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Allison Randal <allison@lohutok.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-04iio: imu: adis16400: move adis16400.h into adis16400.cAlexandru Ardelean
Final part of the re-organization. Move the `adis16400.h` into `adis16400.c` since it no longer needs to be shared among other files. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-04-04iio: imu: adis16400: rename adis16400_core.c -> adi16400.cAlexandru Ardelean
This change does a simple 1-to-1 rename of the adis16400_core.c file. Now that the `adis16400_buffer.c` file was removed, everything can be moved into a single driver file. But first, this rename. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>