1
0
Fork 0
Commit Graph

27 Commits (redonkable)

Author SHA1 Message Date
Jonathan Cameron e94ec7f512 iio: accel: kxsd9: Fix alignment of local buffer.
commit 95ad67577d upstream.

iio_push_to_buffers_with_timestamp assumes 8 byte alignment which
is not guaranteed by an array of smaller elements.

Note that whilst in this particular case the alignment forcing
of the ts element is not strictly necessary it acts as good
documentation.  Doing this where not necessary should cut
down on the number of cut and paste introduced errors elsewhere.

Fixes: 0427a106a9 ("iio: accel: kxsd9: Add triggered buffer handling")
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>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-09-17 13:47:51 +02:00
Thomas Gleixner d2912cb15b treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
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-06-19 17:09:55 +02:00
Andy Shevchenko fb1589710e iio: Allow to read mount matrix from ACPI
Currently mount matrix is allowed in Device Tree, though there is
no technical issue to extend it to support ACPI.

Convert the function to use device_property_read_string_array() and
thus allow to read mount matrix from ACPI if available.

Example of use in _DSD method:

  Name (_DSD, Package ()
  {
     ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
     Package ()
     {
        Package () { "mount-matrix", Package() {
                "1", "0",     "0",
                "0", "0.866", "0.5",
                "0", "-0.5",  "0.866",
        } },
     }
  })

At the same time drop the "of" prefix from its name and
convert current users.

No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-04-04 20:19:46 +01:00
Jonathan Cameron 6c5bffa80e iio:accel: drop assign iio_info.driver_module and iio_trigger_ops.owner
The equivalent of both of these are now done via macro magic when
the relevant register calls are made.  The actual structure
elements will shortly go away.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
2017-08-22 21:22:40 +01:00
Linus Walleij 12884004f1 iio: accel: kxsd9: Support reading a mounting matrix
This adds support for the mounting matrix to the KXSD9 driver.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:36:32 +01:00
Linus Walleij 9a9a369d61 iio: accel: kxsd9: Deploy system and runtime PM
This deploys runtime and system PM in the KXSD9 driver:

- Use the force_runtime_suspend/resume callbacks as system PM
  operations.

- Add buffer prepare/unprepare callbacks to grab the runtime
  PM while we're using buffered reads and put get/put_autosuspend
  in these.

- Insert get/put_autosuspend calls anywhere the IO is used from
  the raw read/write callbacks.

- Move the fullscale setting to be cached in the state container
  so we can restore it properly when coming back from
  system/runtime suspend.

- Set the autosuspend delay to two orders of magnitude that of
  the sensor start-up time (20ms) so we will autosuspend after
  2s.

- Register the callbacks in both the SPI and I2C subdrivers.

Tested with the I2C KXSD9 on the Qualcomm APQ8060 Dragonboard.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:35:59 +01:00
Linus Walleij 79383aaec4 iio: accel: kxsd9: Replace "parent" with "dev"
What is passed to the .probe() and .remove() functions is
technically the parent of the created IIO device but it becomes
a big confusion for the head to have it named like this since
it is usually clear from context the "dev" refers to the physical
device, and when next adding PM callbacks a clean
"struct device *dev" pointer is passed to these and that makes
it even more confused. Rename "parent" to "dev" like in most
other drivers.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:35:26 +01:00
Linus Walleij 2bb4a02aad iio: accel: kxsd9: Fetch and handle regulators
This adds supply regulator handling for the VDD and IOVDD inputs
on the KXSD9 component, makes sure to bring the regulators online
during probe and disable them on remove or the errorpath.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:33:28 +01:00
Linus Walleij 11adc2b218 iio: accel: kxsd9: Deploy proper register bit defines
There are some hardcoded register values etc in the code, define
proper bitfield definitions, and use them when getting and setting
the scale. Optimize a read/modify/write to use regmap_update_bits()
at the same time.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:32:49 +01:00
Linus Walleij 0427a106a9 iio: accel: kxsd9: Add triggered buffer handling
As is custom with all modern sensors, add a clever burst mode
that will just stream out values from the sensor and provide it
to userspace to do the proper offsetting and scaling.

This is the result when tested with an HRTimer trigger:

$ generic_buffer -a -c 10 -n kxsd9 -t foo
/sys/bus/iio/devices/iio:device1 foo
0.371318 0.718680 9.869872 1795.000000 97545896129
-0.586922 0.179670 9.378775 2398.000000 97555864721
-0.299450 0.179670 10.348992 2672.000000 97565874055
0.371318 0.335384 11.103606 2816.000000 97575883240
0.179670 0.574944 10.540640 2847.000000 97585862351
0.335384 0.754614 9.953718 2840.000000 97595872425
0.179670 0.754614 10.732288 2879.000000 97605882351
0.000000 0.754614 10.348992 2872.000000 97615891832
-0.730658 0.574944 9.570422 2831.000000 97625871536
0.000000 1.137910 10.732288 2872.000000 97635881610

Columns shown are x, y, z acceleration, so a positive acceleration
of ~9.81 (shaky due to bad calibration) along the z axis. The
fourth column is the AUX IN which is floating on this system,
it seems to float up to the 2.85V VDD voltage.

To be able to cleanup the triggered buffer, we need to add .remove()
callbacks to the I2C and SPI subdrivers and call back into an
exported .remove() callback in the core.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:32:15 +01:00
Linus Walleij 84e2f6f958 iio: accel: kxsd9: Fix up offset and scaling
This fixes several errors in the offset and scaling of the raw
values from the KXSD9 sensor:

- The code did not convert the big endian value from the sensor
  into the endianness of the host CPU. Fix this with
  be16_to_cpu() on the raw obtained value.

- The code did not regard the fact that only the upper 12 bits of
  the accelerometer values are valid. Shift these
  down four bits to yield the real raw value.

- Further the sensor provides 2048 at zero g. This means that an
  offset of 2048 must be subtracted from the raw value before
  scaling. This was not taken into account by the driver,
  yielding a weird value. Fix this by providing this offset in
  sysfs.

To house the scaling code better, the value reading code was
factored into the raw reading function.

This proper scaling and offseting is necessary to get proper
values out of triggered buffer by offsetting, shifting and scaling
them.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:31:31 +01:00
Linus Walleij dc6ac050c7 iio: accel: kxsd9: Drop the buffer lock
The RX/TX buffers are gone so drop the lock (it should have been
in the transport struct anyway).

Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:29:48 +01:00
Linus Walleij 0d1fb2d52d iio: accel: kxsd9: Convert to use regmap for transport
This converts the KXSD9 driver to drop the custom transport
mechanism and just use regmap like everything else.

Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:28:21 +01:00
Linus Walleij ab04f734b0 iio: accel: kxsd9: Do away with the write2 helper
This is just a masquerading register write function, so use the
register write function instead.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:27:18 +01:00
Linus Walleij bf96f6e80c iio: accel: kxsd9: Split out SPI transport
This moves the KXSD9 SPI transport out to its own file and Kconfig
entry, so that we will be able to add another transport method.
We export the common probe and add a local header file for the
functionality shared between the main driver and the transport
driver.

We make the SPI transport the default for the driver if SPI is
available and the KXSD9 driver was selected, so the oldconfig
upgrade path will be clear.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:26:53 +01:00
Linus Walleij 154021a317 iio: accel: kxsd9: split out a common remove() function
This makes it possible to later split the transport mechanism
using a generic probe() and a generic remove().

Use dev_set_drvdata() and dev_get_drvdata() as a paired
accessor to operate on the abstract struct device * regardless
of the transport mechanism in use.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 11:07:50 +01:00
Linus Walleij 9f9079720a iio: accel: kxsd9: Split out transport mechanism
Split off a transport mechanism struct that will deal with the SPI
traffic in preparation for adding I2C support.

Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-18 10:49:46 +01:00
Linus Walleij 307fe9dd11 iio: accel: kxsd9: Fix scaling bug
All the scaling of the KXSD9 involves multiplication with a
fraction number < 1.

However the scaling value returned from IIO_INFO_SCALE was
unpredictable as only the micros of the value was assigned, and
not the integer part, resulting in scaling like this:

$cat in_accel_scale
-1057462640.011978

Fix this by assigning zero to the integer part.

Cc: stable@vger.kernel.org
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-03 18:30:45 +01:00
Linus Walleij 7ac61a062f iio: accel: kxsd9: Fix raw read return
Any readings from the raw interface of the KXSD9 driver will
return an empty string, because it does not return
IIO_VAL_INT but rather some random value from the accelerometer
to the caller.

Cc: stable@vger.kernel.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-08-21 20:42:16 +01:00
Linus Walleij 0c1f91b985 iio: accel: kxsd9: fix the usage of spi_w8r8()
These two spi_w8r8() calls return a value with is used by the code
following the error check. The dubious use was caused by a cleanup
patch.

Fixes: d34dbee8ac ("staging:iio:accel:kxsd9 cleanup and conversion to iio_chan_spec.")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-06-26 17:32:19 +01:00
Andrew F. Davis 3821a065f5 spi: Drop owner assignment from spi_drivers
An spi_driver does not need to set an owner, it will be populated by the
driver core.

Signed-off-by: Andrew F. Davis <afd@ti.com>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-10-28 10:30:17 +09:00
Frank Zago 0ee005c7dc iio:accel:kxsd9 fix missing mutex unlock
This will leave a lock held after reading from the device, preventing
any further reads.

Signed-off-by: Frank Zago <frank@zago.net>
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-11-17 15:22:00 +00:00
Sachin Kamat dcf5272cac iio: accel: kxsd9: Remove redundant variable
Return directly thereby eliminating an intermediate variable.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-10-24 14:43:24 +01:00
Sachin Kamat 4ee309337e iio: accel: kxsd9: Use devm_iio_device_alloc
Using devm_iio_device_alloc makes code simpler.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-08-03 18:41:18 +01:00
Jonathan Cameron 2f6bb53480 iio:accel:kxsd9 move to info_mask_(shared_by_type/separate)
The original info_mask is going away in favour of the broken out versions.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-03-17 19:49:21 +00:00
Lars-Peter Clausen 14543a00fc iio: Use spi_sync_transfer()
Use the new spi_sync_transfer() helper function instead of open-coding it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-02-09 11:08:42 +00:00
Jonathan Cameron 81ca486fe5 iio:accel:kxsd9 move out of staging
This is a very simple driver giving basic access to this part over an
spi bus.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-01-26 10:07:53 +00:00