summaryrefslogtreecommitdiffstats
path: root/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
AgeCommit message (Collapse)AuthorFilesLines
2020-09-21iio:imu:inv_mpu6050: Use regmap_noinc_read for fifo reads.Jonathan Cameron1-2/+2
We should not be assuming that we are reading a sequence of registers as here we are doing a read of a lot of data from a single register address. Not marked for stable as by coincidence it being wrong doesn't make any difference. Suggested-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Link: https://lore.kernel.org/r/20200722155103.979802-19-jic23@kernel.org
2020-09-21iio:imu:inv_mpu6050 Fix dma and ts alignment and data leak issues.Jonathan Cameron1-7/+5
This case is a bit different to the rest of the series. The driver was doing a regmap_bulk_read into a buffer that wasn't dma safe as it was on the stack with no guarantee of it being in a cacheline on it's own. Fixing that also dealt with the data leak and alignment issues that Lars-Peter pointed out. Also removed some unaligned handling as we are now aligned. Fixes tag is for the dma safe buffer issue. Potentially we would need to backport timestamp alignment futher but that is a totally different patch. Fixes: fd64df16f40e ("iio: imu: inv_mpu6050: Add SPI support for MPU6000") Reported-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Cc: <Stable@vger.kernel.org> Link: https://lore.kernel.org/r/20200722155103.979802-18-jic23@kernel.org
2020-07-20iio: imu: inv_mpu6050: inv_mpu_ring: Demote seemingly unintentional ↵Lee Jones1-1/+1
kerneldoc header This is the only use of kerneldoc in the source file and no descriptions are provided. Fixes the following W=1 kernel build warning(s): drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c:118: warning: Function parameter or member 'irq' not described in 'inv_mpu6050_read_fifo' drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c:118: warning: Function parameter or member 'p' not described in 'inv_mpu6050_read_fifo' Cc: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-03-08iio: imu: inv_mpu6050: factorize fifo enable/disableJean-Baptiste Maneyrol1-50/+4
Rework fifo enable/disable in a separate function. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-03-08iio: imu: inv_mpu6050: delete useless checkJean-Baptiste Maneyrol1-8/+5
If we are here it means we have fifo enabled for 1 sensor at least. And interrupt is always required for using trigger. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-18iio: imu/mpu6050: support dual-edge IRQMichał Mirosław1-4/+1
Make mpu6050 usable on platforms which provide only any-edge interrupts. One example of this kind of platform is AT91SAM9G45 Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Acked-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-18iio: imu: inv_mpu6050: add fifo temperature data supportJean-Baptiste Maneyrol1-2/+4
Add support of temperature data in fifo for all chips. Enable unification of scan elements for icm20602. Add macros for generating scan elements. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-11Merge 5.4-rc7 into staging-nextGreg Kroah-Hartman1-3/+12
We want the staging fixes in here, and it resolves some merge issues. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-10-22iio: imu: inv_mpu6050: fix no data on MPU6050Jean-Baptiste Maneyrol1-3/+12
Some chips have a fifo overflow bit issue where the bit is always set. The result is that every data is dropped. Change fifo overflow management by checking fifo count against a maximum value. Add fifo size in chip hardware set of values. Fixes: f5057e7b2dba ("iio: imu: inv_mpu6050: better fifo overflow handling") Cc: stable@vger.kernel.org Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-10-05iio: imu: inv_mpu6050: add fifo support for magnetometer dataJean-Baptiste Maneyrol1-2/+9
Put read magnetometer data by mpu inside the fifo. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-06-05treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 282Thomas Gleixner1-9/+1
Based on 1 normalized pattern(s): this software is licensed under the terms of the gnu general public license version 2 as published by the free software foundation and may be copied distributed and modified under those terms this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 285 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Reviewed-by: Allison Randal <allison@lohutok.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190529141900.642774971@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-14iio: imu: mpu6050: Fix FIFO layout for ICM20602Steve Moskovchenko1-0/+3
The MPU6050 driver has recently gained support for the ICM20602 IMU, which is very similar to MPU6xxx. However, the ICM20602's FIFO data specifically includes temperature readings, which were not present on MPU6xxx parts. As a result, the driver will under-read the ICM20602's FIFO register, causing the same (partial) sample to be returned for all reads, until the FIFO overflows. Fix this by adding a table of scan elements specifically for the ICM20602, which takes the extra temperature data into consideration. While we're at it, fix the temperature offset and scaling on ICM20602, since it uses different scale/offset constants than the rest of the MPU6xxx devices. Signed-off-by: Steve Moskovchenko <stevemo@skydio.com> Fixes: 22904bdff978 ("iio: imu: mpu6050: Add support for the ICM 20602 IMU") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-06-10iio: imu: inv_mpu6050: new timestamp mechanismJean-Baptiste Maneyrol1-1/+81
Check validity of interrupt timestamps by computing time between 2 interrupts. If it matches the chip frequency modulo 4%, it is used as the data timestamp and also for estimating the chip frequency measured from the system. Otherwise timestamp is computed using the estimated chip frequency. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-06-10iio: imu: inv_mpu6050: better fifo overflow handlingJean-Baptiste Maneyrol1-2/+3
Use fifo overflow bit from int status rather than using an arbitrary threshold. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-06-10iio: imu: inv_mpu6050: fix fifo count readingJean-Baptiste Maneyrol1-13/+11
Use unaligned access since buffer is a bytes table. Truncate fifo count to read only complete datum. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-06-10iio: imu: inv_mpu6050: replace timestamp fifo by generic timestampJean-Baptiste Maneyrol1-43/+1
Using a fifo for storing timestamps is useless since the interrupt is in one-shot mode, preventing the hard irq handler to be called when the irq thread is running. Instead use the generic timestamp function iio_pollfunc_store_time. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-05-12iio: imu: inv_mpu6050: make loop a do-whileMartin Kelly1-2/+2
Prior to this loop, we check if fifo_count < bytes_per_datum and bail if so. This means that when we hit the loop, we know that fifo_count >= bytes_per_datum, so the check is unneeded and we can turn the loop into a do-while for a slight performance improvement. Signed-off-by: Martin Kelly <mkelly@xevo.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-05-06iio: imu: inv_mpu6050: minor wording fixesMartin Kelly1-2/+2
Just some minor grammar/spelling fixes of things I noticed while reading the code. Signed-off-by: Martin Kelly <mkelly@xevo.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-05-06iio: imu: inv_mpu6050: fix user_ctrl register overwrittenJean-Baptiste Maneyrol1-6/+7
When in spi mode, we are setting i2c disable bit in user_ctrl register. But the register is overwritten after when turning fifo on. So save user_ctrl init value and always use it when updating the register. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-05-06iio: imu: inv_mpu6050: skip first sample when gyro is onJean-Baptiste Maneyrol1-1/+6
Implement generic skip first samples mechanism and use it to filter out first sample when gyro is on. The problem for these chips is that the first sample of the gyro is out of specs, because gyro is not completely stabilized. To ensure all data are within sensor specs, we just skip the first sample when turning gyro on. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-21iio:imu: inv_mpu6050: support more interrupt typesMartin Kelly1-0/+15
Currently, we support only rising edge interrupts, and in fact we assume that the interrupt we're given is rising edge (and things won't work if it's not). However, the device supports rising edge, falling edge, level low, and level high interrupts. Empirically, on my system, switching to level interrupts has fixed a problem I had with significant (~40%) interrupt loss with edge interrupts. This issue is likely related to the SoC I'm using (Allwinner H3), but being able to switch the interrupt type is still a very useful workaround. I tested this with each interrupt type and verified correct behavior in a logic analyzer. Add support for these interrupt types while also eliminating the error case of the device tree and driver using different interrupt types. Signed-off-by: Martin Kelly <mkelly@xevo.com> Acked-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-15iio: imu: inv_mpu6050: do not flush fifo when iio buffer is fullJean-Baptiste Maneyrol1-4/+2
There is no need to flush fifo and loose all data when the iio buffer is full. Just drop the data by ignoring the error as commonly done in other drivers. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Reviewed-by: Martin Kelly <martin@martingkelly.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-06-11iio: imu: inv_mpu6050: fix lock issues by using our own mutexJean-Baptiste Maneyrol1-3/+3
There are several locks issues when using buffer and direct polling data at the same time. Use our own mutex for managing locking and block simultaneous use of buffer and direct polling by using iio_device_{claim/release}_direct_mode. This makes chip_config enable bit obsolete, so delete it. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-06-30iio:core: timestamping clock selection supportGregor Boirie1-1/+1
Adds a new per-device sysfs attribute "current_timestamp_clock" to allow userspace to select a particular POSIX clock for buffered samples and events timestamping. Following clocks, as listed in clock_gettime(2), are supported: CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE, CLOCK_BOOTTIME and CLOCK_TAI. Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com> Acked-by: Sanchayan Maity <maitysanchayan@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-02-24iio: imu: inv_mpu6050: Fix alignment with open parenthesisDaniel Baluta1-9/+8
This makes code consistent around inv_mpu6050 driver and fixes the following checkpatch.pl warning: CHECK: Alignment should match open parenthesis Note that there were few cases were it was not possible to fix this due to making the line too long, but we can live with that. Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-02-24iio: imu: inv_mpu6050: Fix code indent for if statementDaniel Baluta1-2/+2
This fixes the following checkpatch.pl warning: WARNING: suspect code indent for conditional statements (8, 24) + if (kfifo_len(&st->timestamps) > [...] + goto flush_fifo; Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-02-24iio: imu: inv_mpu6050: Fix Yoda conditionsDaniel Baluta1-1/+1
This fixes the following checkpatch warning: * WARNING: Comparisons should place the constant on the right side of the test Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> Acked-by: Crt Mori <cmo@melexis.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-02-13iio: imu: inv_mpu6050: Separate driver into core and i2c functionality.Adriana Reus1-2/+3
Separate this driver into core and i2c functionality. This is in preparation for adding spi support. Signed-off-by: Adriana Reus <adriana.reus@intel.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-02-13iio: imu: inv_mpu6050: Use regmap instead of i2c specific functionsAdriana Reus1-16/+14
Use regmap instead of i2c specific functions. This is in preparation of splitting this driver into core and i2c specific functionality. Signed-off-by: Adriana Reus <adriana.reus@intel.com> Acked-by: Crt Mori <cmo@melexis.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-03-14iio: inv_mpu6050: Clear timestamps fifo while resetting hardware fifoViorel Suman1-11/+14
A hardware fifo reset always imply an invalidation of the existing timestamps, so we'll clear timestamps fifo on successfull hardware fifo reset. Signed-off-by: Viorel Suman <viorel.suman@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-01-11iio: delete non-required instances of include <linux/init.h>Paul Gortmaker1-1/+0
None of these files are actually using any __init type directives and hence don't need to include <linux/init.h>. Most are just a left over from __devinit and __cpuinit removal, or simply due to code getting copied from one driver to the next. Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-09-21iio:mpu6050: Use iio_push_to_buffers_with_timestamp()Lars-Peter Clausen1-4/+2
Makes the code a bit shorter and less ugly. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Cc: Ge Gao <ggao@invensense.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-03-17using kfifo_in_spinlocked instead of separate code.Ge Gao1-3/+2
Signed-off-by: Ge Gao <ggao@invensense.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-02-10Invensense MPU6050 Device Driver.Ge Gao1-0/+196
This the basic functional Invensense MPU6050 Device driver. Signed-off-by: Ge Gao <ggao@invensense.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>