aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/imu (follow)
AgeCommit message (Collapse)AuthorFilesLines
2018-12-28Merge tag 'staging-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/stagingLinus Torvalds9-176/+1276
Pull staging/IIO driver updates from Greg KH: "Here is the big staging and iio driver pull request for 4.21-rc1. Lots and lots of tiny patches here, nothing major at all. Which is good, tiny cleanups is nice to see. No new huge driver removal or addition, this release cycle, although there are lots of good IIO driver changes, addtions, and movement from staging into the "real" part of the kernel, which is always great. Full details are in the shortlog, and all of these have been in linux-next for a while with no reported issues" * tag 'staging-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (553 commits) staging: mt7621-mmc: Correct spelling mistakes in comments staging: wilc1000: fix missing read_write setting when reading data mt7621-mmc: char * array declaration might be better as static const mt7621-mmc: return statement in void function unnecessary mt7621-mmc: Alignment should match open parenthesis mt7621-mmc: Removed unnecessary blank lines mt7621-mmc: Fix some coding style issues staging: android: ashmem: doc: Fix spelling staging: rtl8188eu: cleanup brace coding style issues staging: rtl8188eu: add spaces around '&' in rtw_mlme_ext.c staging: rtl8188eu: change return type of is_basicrate() to bool staging: rtl8188eu: simplify null array initializations staging: rtl8188eu: change order of declarations to improve readability staging: rtl8188eu: make some arrays static in rtw_mlme_ext.c staging: rtl8188eu: constify some arrays staging: rtl8188eu: convert unsigned char arrays to u8 staging: rtl8188eu: remove redundant declaration in rtw_mlme_ext.c staging: rtl8188eu: remove unused arrays WFD_OUI and WMM_INFO_OUI staging: rtl8188eu: remove unnecessary parentheses in rtw_mlme_ext.c staging: rtl8188eu: remove unnecessary comments in rtw_mlme_ext.c ...
2018-12-10iio: bmi160: use all devm functions in probeMartin Kelly4-41/+14
Currently, we're using the devm version of some but not all functions. Switch to the devm version of iio_triggered_buffer_setup and iio_device_register to simplify the code a bit and decrease the chance of bugs. Signed-off-by: Martin Kelly <martin@martingkelly.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-12-03iio: inv_mpu6050: Use i2c_acpi_get_i2c_resource() helperAndy Shevchenko1-10/+6
ACPI provides a generic helper to get I2C Serial Bus resources. Use it instead of open coded variant. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-25iio: imu: st_lsm6dsx: do not use a fixed read len in read_oneshotLorenzo Bianconi1-6/+8
Generalize st_lsm6dsx_shub_read_oneshot in order to not use a fixed read length and take into account iio channel realbits for single read operations Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: add hw FIFO support to i2c controllerLorenzo Bianconi4-6/+125
Introduce hw FIFO support to lsm6dsx i2c controller. st_lsm6dsx sensor-hub relies on SLV0 for slave configuration since SLV0 is the only channel that can be used to write into i2c slave devices. SLV{1,2,3} channels are used to read external data and push them into the hw FIFO Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: add st_lsm6dsx_push_tagged_data routineLorenzo Bianconi1-15/+29
Introduce st_lsm6dsx_push_tagged_data routine to push samples to iio buffers. st_lsm6dsx_push_tagged_data will be reused adding hw fifo support to st_lsm6dsx i2c embedded controller in order to improve code readability Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: add i2c embedded controller supportLorenzo Bianconi4-43/+909
i2c controller embedded in lsm6dx series can connect up to four slave devices using accelerometer sensor as trigger for i2c read/write operations. Introduce sensor hub support for lsm6dso sensor. Add register map for lis2mdl magnetometer sensor. In order to perform single read/write operations st_lsm6dsx driver relies on SLV0 channel (hw FIFO is not supported yet) Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: introduce st_lsm6dsx_sensor_set_enable routineLorenzo Bianconi3-33/+15
Add st_lsm6dsx_sensor_set_enable routine and remove st_lsm6dsx_sensor_{enable/disable} ones in order to make the code more readable and remove unnecessary functions Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: introduce ST_LSM6DSX_ID_EXT sensor idsLorenzo Bianconi3-9/+88
Add ST_LSM6DSX_ID_EXT{0,1,2} sensor ids as reference for slave devices connected to st_lsm6dsx i2c controller. Moreover introduce odr dependency between accel and ext devices since i2c embedded controller relies on the accelerometer sensor as bus read/write trigger so we need to enable accel device at odr = max(accel_odr, ext_odr) in order to properly communicate with i2c slave devices Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: remove static from st_lsm6dsx_set_watermarkLorenzo Bianconi2-1/+2
Remove static qualifier from st_lsm6dsx_set_watermark routine in order to be reused supporting st_lsm6dsx i2c controller Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: reload trimming parameter at bootstrapLorenzo Bianconi1-3/+15
Perform a complete device reset at bootstrap reloading trimming parameter after sw reset is completed. Device sw reset/boot is explained here: https://www.st.com/resource/en/application_note/dm00517282.pdf, section 5.7 Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: imu: st_lsm6dsx: introduce locked read/write utility routinesLorenzo Bianconi3-38/+90
Add st_lsm6dsx_update_bits_locked, st_lsm6dsx_read_locked and st_lsm6dsx_write_locked utility routines in order to guarantee the bus access is atomic respect to reg page configuration. This is a preliminary patch to add i2c sensor hub support since i2c master registers are accessed through a reg page multiplexer Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-09-16Merge 4.19-rc4 into staging-nextGreg Kroah-Hartman1-7/+6
Handle the merge issues and take the iio and staging driver fixes. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-02iio: imu: st_lsm6dsx: add support to LSM6DSOLorenzo Bianconi6-8/+205
Add support to STM LSM6DSO 6-axis (acc + gyro) Mems sensor https://www.st.com/resource/en/datasheet/lsm6dso.pdf Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-09-02iio: imu: st_lsm6dsx: add addr/max_word_len to st_lsm6dsx_read_block()Lorenzo Bianconi1-7/+9
Add reg addr and max_word_len parameters to st_lsm6dsx_read_block since LSM6DSO will use a different register address to read samples from the FIFO and a different sample len Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-09-02iio: imu: st_lsm6dsx: make st_lsm6dsx_check_odr() non-staticLorenzo Bianconi2-2/+2
Remove static qualifier from st_lsm6dsx_check_odr() definition in order to use it for the support of new devices Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-09-02iio: imu: st_lsm6dsx: add read_fifo callback to fifo_opsLorenzo Bianconi3-3/+11
Remove static qualifier from st_lsm6dsx_read_fifo definition and introduce read_fifo function pointer in fifo_ops data structure in order to run the proper read_fifo routine since other compliant devices will use a different FIFO queueing scheme. Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-09-02iio: imu: st_lsm6dsx: take into account ts samples in wm configurationLorenzo Bianconi1-7/+6
Take into account hw timer samples in pattern length computation done in st_lsm6dsx_update_watermark routine for watermark configuration. Moreover use samples in pattern (sip) already computed in st_lsm6dsx_update_decimators routine Fixes: 213451076bd3 ("iio: imu: st_lsm6dsx: add hw timestamp support") Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-08-18iio: imu: mpu6050: add support for regulator frameworkBrian Masney2-0/+64
This patch adds support for the regulator framework to the mpu6050 driver. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Marek <jonathan@marek.ca> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-07-25Merge tag 'iio-for-4.19b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-nextGreg Kroah-Hartman5-3/+29
Jonathan writes: Second set of IIO new device support, features and cleanups. There are also a couple of fixes that can wait for the coming merge window. Core new features * Support for phase channels (used in time of flight sensors amongst other things) * Support for deep UV light channel modifier. New Device Support * AD4758 DAC - New driver and dt bindings. * adxl345 - Support the adxl375 +-200g part which is register compatible. * isl29501 Time of flight sensor. - New driver * meson-saradc - Support the Meson8m2 Socs - right now this is just an ID, but there will be additional difference in future. * mpu6050 - New ID for 6515 variant. * si1133 UV sensor. - New driver * Spreadtrum SC27xx PMIC ADC - New driver and dt bindings. Features * adxl345 - Add calibration offset readback and writing. - Add sampling frequency control. Fixes and Cleanups * ad5933 - Use a macro for the channel definition to reduce duplication. * ad9523 - Replace use of core mlock with a local lock. Part of ongoing efforts to avoid confusing the purpose of mlock which is only about iio core state changes. - Fix displayed phase which was out by a factor of 10. * adxl345 - Add a link to the datasheet. - Rework the use of the address field in the chan_spec structures to allow addition of more per channel information. * adis imu - Mark switch fall throughs. * at91-sama5d2 - Fix some casting on big endian systems. * bmp280 - Drop some DT elements that aren't used and should mostly be done from userspace rather than in DT. * hx711 - add clock-frequency dt binding and resulting delay to deal with capacitance issue on some boards. - fix a spurious unit-address in the example. * ina2xx - Avoid a possible kthread_stop with a stale task_struct. * ltc2632 - Remove some unused local variables (assigned but value never used). * max1363 - Use device_get_match_data to remove some boilerplate. * mma8452 - Mark switch fall throughs. * sca3000 - Fix a missing return in a switch statement (a bad fallthrough previously!) * sigma-delta-modulator - Drop incorrect unit address from the DT example. * st_accel - Use device_get_match_data to drop some boiler plate. - Move to probe_new for i2c driver as second parameter not used. * st_sensors library - Use a strlcpy (safe in this case). * st_lsm6dsx - Add some error logging. * ti-ads7950 - SPDX - Allow simultaneous buffered and polled reads. Needed on a Lego Mindstorms EV3 where some channels are used for power supply monitoring at a very low rate. * ti-dac5571 - Remove an unused variable. * xadc - Drop some dead code.
2018-07-15iio: imu: st_lsm6dsx: add error logs to st_lsm6dsx_read_fifo()Lorenzo Bianconi1-3/+13
Add debug info to error conditions in st_lsm6dsx_read_fifo routine Suggested-by: Jorge Ramirez-Ortiz <jramirez@baylibre.com> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-07-15iio: imu: mpu6050: add support for 6515 variantBrian Masney3-0/+13
This patch adds support for the MPU 6515 variant. Confirmed that the driver functions correctly on a LG Nexus 5 (hammerhead) phone. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Marek <jonathan@marek.ca> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-07-07iio:imu:adis: Mark expected switch fall-throughsGustavo A. R. Silva1-0/+3
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through. Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-07-02Merge 4.18-rc3 into staging-nextGreg Kroah-Hartman1-0/+2
We want the staging/iio fixes in here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-26Merge tag 'iio-for-4.19a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-nextGreg Kroah-Hartman3-79/+131
Jonathan writes: First set of IIO new device support, features and cleanups in the 4.19 cycle The usual mixed bunch. Particular good to see is the generic touch screen driver. Will be interesting to see if this works for other ADCs without major changes. Core features * Channel types - New position relative channel type primarily for touch screen sensors to feed the generic touchscreen driver. New device support * ad5586 - Add support for the AD5311R DAC. * Generic touch screen driver as an IIO consumer. - Note this is in input, but due to dependencies is coming through the IIO tree. - Specific support for this added to the at91-sama5d2 ADC. - Various necessary DT bindings added. Staging Drops * ADIS16060 gyro - A device with a very odd interface that was never cleanly supported. It's now very difficult to get, so unlikely it'll ever be fixed up. Cleanups and minor features and fixes * core - Fix y2038 timestamp issues now the core support is in place. * 104-quad-8 - Provide some defines for magic numbers to help readability. - Fix an off by one error in register selection * ad7606 - Put in a missing function parameter name in a prototype. * adis16023 - Use generic sign_extend function rather than local version. * adis16240 - Use generic sign_extend funciton rather than local version. * at91-sama5d2 - Drop dependency on HAS_DMA now this is handled elsewhere. Will improve build test coverage. - Add oversampling ratio control. Note there is a minor ABI change here to increase the apparent depth to 14 bits so as to allow for transparent provision of different oversampling ratios that drop the actual bit depth to 13 or 12 bits. * hx711 - Add a MAINTAINERS entry for this device. * inv_mpu6050 - Replace the timestamp fifo 'special' code with generic timestamp handling. - Switch to using local store of timestamp divider rather than rate as that is more helpful for accurate time measurement. - Fix an unaligned access that didn't seem to be causing any trouble. - Use the fifo overflow bit to track the overflow status rather than a software counter. - New timestamping mechanism to deal with missed sample interrupts. * stm32-adc - Drop HAS_DMA build dependency. * sun4i-gpadc - Select REGMAP_IRQ a very rarely hit build issue fix.
2018-06-24iio: imu: inv_mpu6050: Fix probe() failure on older ACPI based machinesHans de Goede1-0/+2
Commit 5ec6486daa98 ("iio:imu: inv_mpu6050: support more interrupt types") causes inv_mpu_core_probe() to fail if the IRQ does not have a trigger-type setup. This happens on machines where the mpu6050 is enumerated through ACPI and an older Interrupt type ACPI resource is used for the interrupt, rather then a GpioInt type type, causing the mpu6050 driver to no longer work there. This happens on e.g. the Asus T100TA. This commits makes the mpu6050 fallback to the old IRQF_TRIGGER_RISING default if the irq-type is not setup, fixing this. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Fixes: 5ec6486daa98 ("iio:imu: inv_mpu6050: support more interrupt types") Reviewed-by: Martin Kelly <mkelly@xevo.com> Reviewed-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-06-12treewide: kzalloc() -> kcalloc()Kees Cook1-1/+1
The kzalloc() function has a 2-factor argument form, kcalloc(). This patch replaces cases of: kzalloc(a * b, gfp) with: kcalloc(a * b, gfp) as well as handling cases of: kzalloc(a * b * c, gfp) with: kzalloc(array3_size(a, b, c), gfp) as it's slightly less ugly than: kzalloc_array(array_size(a, b), c, gfp) This does, however, attempt to ignore constant size factors like: kzalloc(4 * 1024, gfp) though any constants defined via macros get caught up in the conversion. Any factors with a sizeof() of "unsigned char", "char", and "u8" were dropped, since they're redundant. The Coccinelle script used for this was: // Fix redundant parens around sizeof(). @@ type TYPE; expression THING, E; @@ ( kzalloc( - (sizeof(TYPE)) * E + sizeof(TYPE) * E , ...) | kzalloc( - (sizeof(THING)) * E + sizeof(THING) * E , ...) ) // Drop single-byte sizes and redundant parens. @@ expression COUNT; typedef u8; typedef __u8; @@ ( kzalloc( - sizeof(u8) * (COUNT) + COUNT , ...) | kzalloc( - sizeof(__u8) * (COUNT) + COUNT , ...) | kzalloc( - sizeof(char) * (COUNT) + COUNT , ...) | kzalloc( - sizeof(unsigned char) * (COUNT) + COUNT , ...) | kzalloc( - sizeof(u8) * COUNT + COUNT , ...) | kzalloc( - sizeof(__u8) * COUNT + COUNT , ...) | kzalloc( - sizeof(char) * COUNT + COUNT , ...) | kzalloc( - sizeof(unsigned char) * COUNT + COUNT , ...) ) // 2-factor product with sizeof(type/expression) and identifier or constant. @@ type TYPE; expression THING; identifier COUNT_ID; constant COUNT_CONST; @@ ( - kzalloc + kcalloc ( - sizeof(TYPE) * (COUNT_ID) + COUNT_ID, sizeof(TYPE) , ...) | - kzalloc + kcalloc ( - sizeof(TYPE) * COUNT_ID + COUNT_ID, sizeof(TYPE) , ...) | - kzalloc + kcalloc ( - sizeof(TYPE) * (COUNT_CONST) + COUNT_CONST, sizeof(TYPE) , ...) | - kzalloc + kcalloc ( - sizeof(TYPE) * COUNT_CONST + COUNT_CONST, sizeof(TYPE) , ...) | - kzalloc + kcalloc ( - sizeof(THING) * (COUNT_ID) + COUNT_ID, sizeof(THING) , ...) | - kzalloc + kcalloc ( - sizeof(THING) * COUNT_ID + COUNT_ID, sizeof(THING) , ...) | - kzalloc + kcalloc ( - sizeof(THING) * (COUNT_CONST) + COUNT_CONST, sizeof(THING) , ...) | - kzalloc + kcalloc ( - sizeof(THING) * COUNT_CONST + COUNT_CONST, sizeof(THING) , ...) ) // 2-factor product, only identifiers. @@ identifier SIZE, COUNT; @@ - kzalloc + kcalloc ( - SIZE * COUNT + COUNT, SIZE , ...) // 3-factor product with 1 sizeof(type) or sizeof(expression), with // redundant parens removed. @@ expression THING; identifier STRIDE, COUNT; type TYPE; @@ ( kzalloc( - sizeof(TYPE) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kzalloc( - sizeof(TYPE) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kzalloc( - sizeof(TYPE) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kzalloc( - sizeof(TYPE) * COUNT * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kzalloc( - sizeof(THING) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | kzalloc( - sizeof(THING) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | kzalloc( - sizeof(THING) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | kzalloc( - sizeof(THING) * COUNT * STRIDE + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) ) // 3-factor product with 2 sizeof(variable), with redundant parens removed. @@ expression THING1, THING2; identifier COUNT; type TYPE1, TYPE2; @@ ( kzalloc( - sizeof(TYPE1) * sizeof(TYPE2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | kzalloc( - sizeof(TYPE1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | kzalloc( - sizeof(THING1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | kzalloc( - sizeof(THING1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | kzalloc( - sizeof(TYPE1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2)) , ...) | kzalloc( - sizeof(TYPE1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2)) , ...) ) // 3-factor product, only identifiers, with redundant parens removed. @@ identifier STRIDE, SIZE, COUNT; @@ ( kzalloc( - (COUNT) * STRIDE * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | kzalloc( - COUNT * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | kzalloc( - COUNT * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kzalloc( - (COUNT) * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | kzalloc( - COUNT * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kzalloc( - (COUNT) * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kzalloc( - (COUNT) * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kzalloc( - COUNT * STRIDE * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) ) // Any remaining multi-factor products, first at least 3-factor products, // when they're not all constants... @@ expression E1, E2, E3; constant C1, C2, C3; @@ ( kzalloc(C1 * C2 * C3, ...) | kzalloc( - (E1) * E2 * E3 + array3_size(E1, E2, E3) , ...) | kzalloc( - (E1) * (E2) * E3 + array3_size(E1, E2, E3) , ...) | kzalloc( - (E1) * (E2) * (E3) + array3_size(E1, E2, E3) , ...) | kzalloc( - E1 * E2 * E3 + array3_size(E1, E2, E3) , ...) ) // And then all remaining 2 factors products when they're not all constants, // keeping sizeof() as the second factor argument. @@ expression THING, E1, E2; type TYPE; constant C1, C2, C3; @@ ( kzalloc(sizeof(THING) * C2, ...) | kzalloc(sizeof(TYPE) * C2, ...) | kzalloc(C1 * C2 * C3, ...) | kzalloc(C1 * C2, ...) | - kzalloc + kcalloc ( - sizeof(TYPE) * (E2) + E2, sizeof(TYPE) , ...) | - kzalloc + kcalloc ( - sizeof(TYPE) * E2 + E2, sizeof(TYPE) , ...) | - kzalloc + kcalloc ( - sizeof(THING) * (E2) + E2, sizeof(THING) , ...) | - kzalloc + kcalloc ( - sizeof(THING) * E2 + E2, sizeof(THING) , ...) | - kzalloc + kcalloc ( - (E1) * E2 + E1, E2 , ...) | - kzalloc + kcalloc ( - (E1) * (E2) + E1, E2 , ...) | - kzalloc + kcalloc ( - E1 * E2 + E1, E2 , ...) ) Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-10iio: imu: inv_mpu6050: new timestamp mechanismJean-Baptiste Maneyrol3-1/+96
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 Maneyrol2-3/+4
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: switch to use sample rate dividerJean-Baptiste Maneyrol2-10/+24
Instead of storing fifo rate in Hz, store the chip internal sample rate divider. This will be more useful for timestamping. There are both equivalent. 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 Maneyrol3-58/+2
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-22iio: imu: inv_mpu6050: add comment about frequenciesMartin Kelly1-1/+8
Although the driver allows frequencies between 4 and 1000 Hz, only the frequencies advertised in the available frequencies file are backed properly by a low-pass filter to prevent aliasing, so it's best to use them. Since this is not obvious to the user, add a comment explaining what's going on. 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-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 Kelly3-4/+4
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 Maneyrol5-12/+17
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 Maneyrol3-1/+10
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-05-06iio: imu: inv_mpu6050: fix possible deadlock between mutex and iioJean-Baptiste Maneyrol1-18/+16
Detected by kernel circular locking dependency checker. We are locking iio mutex (iio_device_claim_direct_mode) after locking our internal mutex. But when the buffer starts, iio first locks its mutex and then we lock our internal one. To avoid possible deadlock, we need to use the same order everwhere. So we change the ordering by locking first iio mutex, then our internal mutex. Fixes: 68cd6e5b206b ("iio: imu: inv_mpu6050: fix lock issues by using our own mutex") Cc: stable@vger.kernel.org Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-05-06iio: imu: inv_mpu6050: use i2c mux only for chip with i2c aux busJean-Baptiste Maneyrol1-16/+25
icm20608 does not have i2c aux bus, so it does not make sense to allocate an i2c mux for this chip. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-28iio: imu: inv_mpu6050: clean read channel data error pathJean-Baptiste Maneyrol1-6/+10
Delete the useless ored result and give a second chance to turn the chip back off at the end. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-28iio: imu: inv_mpu6050: clean read raw by factorizing out raw dataJean-Baptiste Maneyrol1-54/+62
Factorize reading channel data in its own function. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-28iio: imu: inv_mpu6050: use devm_* at init and delete removeJean-Baptiste Maneyrol5-47/+12
Use devm_* for iio_triggered_buffer_setup, iio_device_register, iio_trigger_register. Delete unneeded inv_mpu6050_remove_trigger, inv_mpu_core_remove, and inv_mpu_remove for spi driver. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-28iio: imu: inv_mpu6050: fix error path not turning chip back offJean-Baptiste Maneyrol2-16/+32
Some functions are turning the chip on and not back off in error path. With set_power function using a reference counter that would keep the chip on forever. 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 Kelly5-8/+64
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-21iio: imu: inv_mpu6050: use set_power_itg function in i2c muxJean-Baptiste Maneyrol1-20/+13
Set power function is rewritten manually inside i2c mux select. Better use the already identical existing function. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-21iio: imu: inv_mpu6050: clean set_power_itg and fix usageJean-Baptiste Maneyrol1-20/+24
Rewrite set_power_itg. Failing when turning power off is no more decreasing the counter now and sleeping only happens when effectively turning the chip on. Fix also usage in init function (setting power on one time is sufficient to ensure chip is effectively on). Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-15iio: imu: Add mpu9255 support to mpu6050 driverDouglas Fischer4-0/+14
Added support for the mpu9255 IMU to the mpu6050 driver. The register map is the same as the other chips; the only driver difference is the compatible string and the WHOAMI register value. Signed-off-by: Douglas Fischer <fischerdouglasc@gmail.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>
2018-04-08iio: imu: st_lsm6dsx: add support to ism330dlcLorenzo Bianconi6-7/+21
Add support to STM ISM330DLC 6-axis (acc + gyro) Mems sensor http://www.st.com/resource/en/datasheet/ism330dlc.pdf Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-08iio: imu: st_lsm6dsx: fix FIFO threshold mask for LSM6DSM/LSM6DSLLorenzo Bianconi1-2/+2
According to the latest datasheet, LSM6DSM and LSM6DSL imu sensors export GENMASK(10, 0) for FIFO threshold mask definition. Despite that is not an actual issue since write on fifo_th register is protected by max_fifo_size value, fix fifo_th and fifo_diff register definitions Fixes: 290a6ce11d93 ("iio: imu: add support to lsm6dsx driver") Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>