History log of /linux-master/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
Revision Date Author Comments
# 0b4ae3f6 11-Jul-2022 Gwendal Grignou <gwendal@chromium.org>

iio: cros: Register FIFO callback after sensor is registered

Instead of registering callback to process sensor events right at
initialization time, wait for the sensor to be register in the iio
subsystem.

Events can come at probe time (in case the kernel rebooted abruptly
without switching the sensor off for instance), and be sent to IIO core
before the sensor is fully registered.

Fixes: aa984f1ba4a4 ("iio: cros_ec: Register to cros_ec_sensorhub when EC supports FIFO")
Reported-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20220711144716.642617-1-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 1f035055 10-Jun-2022 Nuno Sá <nuno.sa@analog.com>

iio: common: cros_ec_sensors: explicitly add proper header files

Do not trust the fact that iio.h includes of.h which in turn includes
all the headers we are relying on.

The ultimate goal is to actually drop of.h from iio.h.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220610084545.547700-13-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 80346b2b 18-Mar-2021 Gwendal Grignou <gwendal@chromium.org>

iio: cros: unify hw fifo attributes without API changes

Commit 2e2366c2d141 ("iio: cros_ec: unify hw fifo attributes into the core file")
should be reverted as it set buffer extended attributes at
the wrong place. However, to revert it will requires to revert more
commits:
commit 165aea80e2e2 ("iio: cros_ec: use devm_iio_triggered_buffer_setup_ext()")
commit 21232b4456ba ("iio: buffer: remove iio_buffer_set_attrs() helper")).
and we would still have conflict with more recent development.
commit ee708e6baacd ("iio: buffer: introduce support for attaching more IIO buffers")

Instead, this commit reverts the first 2 commits without re-adding
iio_buffer_set_attrs() and set the buffer extended attributes at the
right place:

1. Instead of adding has_fw_fifo, deduct it from the configuration:
- EC must support FIFO (EC_FEATURE_MOTION_SENSE_FIFO) set.
- sensors send data a regular interval (accelerometer, gyro,
magnetomer, barometer, light sensor).
- "Legacy accelerometer" is only present on EC without FIFO, so we don't
need to set buffer attributes.

2. devm_iio_triggered_buffer_setup_ext() does not need to be called when
EC does not support FIFO, as there is no FIFO to manage.

3. Use devm_iio_triggered_buffer_setup_ext() when EC has a FIFO to
specify the buffer extended attributes.

Fixes: 2e2366c2d141 ("iio: cros_ec: unify hw fifo attributes into the core file")
Fixes: 165aea80e2e2 ("iio: cros_ec: use devm_iio_triggered_buffer_setup_ext()")
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210318184857.2679181-1-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 2e2366c2 23-Sep-2020 Alexandru Ardelean <alexandru.ardelean@analog.com>

iio: cros_ec: unify hw fifo attributes into the core file

The intent here is to minimize the use of iio_buffer_set_attrs(). Since we
are planning to add support for multiple IIO buffers per IIO device, the
issue has to do with:
1. Accessing 'indio_dev->buffer' directly (as is done with
'iio_buffer_set_attrs(indio_dev->buffer, <attrs>)').
2. The way that the buffer attributes would get handled or expanded when
there are more buffers per IIO device. Current a sysfs kobj_type expands
into a 'device' object that expands into an 'iio_dev' object.
We will need to change this, so that the sysfs attributes for IIO
buffers expand into IIO buffers at some point.

Right now, the current IIO framework works fine for the
'1 IIO device == 1 IIO buffer' case (that is now).

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20200923130339.997902-1-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 1716420e 22-Aug-2020 Guenter Roeck <linux@roeck-us.net>

iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code

A follow-up patch will extend the number of errors reported by
cros_ec_cmd_xfer_status(). Specifically, the function will return
-EOPNOTSUPP if a command is not supported by the EC. Prepare for it.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>


# e7e3b9d2 26-May-2020 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Reapply range at resume

EC does not currently preserve range across sensor reinit.
If sensor is powered down at suspend, it will default to the EC default
range at resume, not the range set by the host.

Save range if modified, and apply at resume.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 6562793b 27-Mar-2020 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Expose hwfifo_timeout

Expose EC minimal interrupt period through buffer/hwfifo_timeout:
- Maximal timeout is limited to 65s.
- When timeout for all sensors is set to 0, EC will not send events,
even if the sensor sampling rate is greater than 0.

Rename frequency to sampling_frequency to match IIO ABI.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>


# 2861be4c 27-Mar-2020 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Remove pm function

Since cros_ec_sensorhub is shutting down the FIFO when the device
suspends, no need to slow down the EC sampling period rate.

It was necesseary to do that before command CMD_FIFO_INT_ENABLE was
introduced, but now all supported chromebooks have it.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>


# aa984f1b 27-Mar-2020 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Register to cros_ec_sensorhub when EC supports FIFO

When EC supports FIFO, each IIO device registers a callback, to put
samples in the buffer when they arrives from the FIFO.

When no FIFO, the user space app needs to call trigger_new, or better
register a high precision timer.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>


# 11f1eabe 03-Dec-2019 Enric Balletbo i Serra <enric.balletbo@collabora.com>

cros_ec: treewide: Remove 'include/linux/mfd/cros_ec.h'

This header file now only includes the cros_ec_dev struct, however, is the
'include/linux/platform_data/cros_ec_proto.h' who contains the definition of
all the Chrome OS EC related structs. There is no reason to have a
separate include for this struct so move to the place where other
structs are defined. That way, we can remove the include itself, but also
simplify the common pattern

#include <linux/mfd/cros_ec.h>
#include <linux/platform_data/cros_ec_proto.h>

for a single include

#include <linux/platform_data/cros_ec_proto.h>

The changes to remove the cros_ec.h include were generated with the
following shell script:

git grep -l "<linux/mfd/cros_ec.h>" | xargs sed -i '/<linux\/mfd\/cros_ec.h>/d'

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Sebastian Reichel <sre@kernel.org>
Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>


# d60ac88a 19-Nov-2019 Gwendal Grignou <gwendal@chromium.org>

mfd / platform / iio: cros_ec: Register sensor through sensorhub

Remove the duplicated code in MFD, since MFD just registers cros-ec-sensorhub
if at least one sensor is present.

Change IIO cros-ec driver to get the pointer to the cros-ec-dev through
cros-ec-sensorhub.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>


# 840d9f13 02-Sep-2019 Enric Balletbo i Serra <enric.balletbo@collabora.com>

mfd / platform: cros_ec: Reorganize platform and mfd includes

There is a bit of mess between cros-ec mfd includes and platform
includes. For example, we have a linux/mfd/cros_ec.h include that
exports the interface implemented in platform/chrome/cros_ec_proto.c. Or
we have a linux/mfd/cros_ec_commands.h file that is non related to the
multifunction device (in the sense that is not exporting any function of
the mfd device). This causes crossed includes between mfd and
platform/chrome subsystems and makes the code difficult to read, apart
from creating 'curious' situations where a platform/chrome driver includes
a linux/mfd/cros_ec.h file just to get the exported functions that are
implemented in another platform/chrome driver.

In order to have a better separation on what the cros-ec multifunction
driver does and what the cros-ec core provides move and rework the
affected includes doing:

- Move cros_ec_commands.h to include/linux/platform_data/cros_ec_commands.h
- Get rid of the parts that are implemented in the platform/chrome/cros_ec_proto.c
driver from include/linux/mfd/cros_ec.h to a new file
include/linux/platform_data/cros_ec_proto.h
- Update all the drivers with the new includes, so
- Drivers that only need to know about the protocol include
- linux/platform_data/cros_ec_proto.h
- linux/platform_data/cros_ec_commands.h
- Drivers that need to know about the cros-ec mfd device also include
- linux/mfd/cros_ec.h

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Wolfram Sang <wsa@the-dreams.de>
Acked-by: Neil Armstrong <narmstrong@baylibre.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Series changes: 3
- Fix dereferencing pointer to incomplete type 'struct cros_ec_dev' (lkp)
Signed-off-by: Lee Jones <lee.jones@linaro.org>


# ae7b02ad 16-Jul-2019 Fabien Lahoudere <fabien.lahoudere@collabora.com>

iio: common: cros_ec_sensors: Expose cros_ec_sensors frequency range via iio sysfs

Embedded controller return minimum and maximum frequencies, unfortunately
we have no way to know the step for all available frequencies.
Even if not complete, we can return a list of known values using the
standard read_avail callback (IIO_CHAN_INFO_SAMP_FREQ) to provide them to
userland.

Now cros_ec_* sensors provides frequencies values in sysfs like this:
"0 min max". 0 is always true to disable the sensor.

Default frequencies are provided for earlier protocol.

Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
[rebased on top of iio/testing and solved conflicts]
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# ed1f2e85 18-Jul-2019 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Add calibscale for 3d MEMS

Add calibration scale support to accel, gyro and magnetometer.

Check on eve with current firmware, check reading calibscale returns 1.0,
check with newer firmware values are applied.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 37aa055c 12-Mar-2019 Enric Balletbo i Serra <enric.balletbo@collabora.com>

iio: cros_ec: Switch to SPDX identifier.

Adopt the SPDX license identifier headers to ease license compliance
management. Also fix MODULE_LICENSE for cros_ec_accel_legacy to match
the SPDX and boiler plate license.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# b921d928 12-Mar-2019 Guenter Roeck <groeck@chromium.org>

iio: cros_ec: Drop unnecessary include files

The cros_ec sensors drivers do not call any sysfs functions
or use any sysfs defines, and thus do not need to include
linux/sysfs.h. Also, some cros_ec drivers include linux/delay.h
and is not used.

Signed-off-by: Guenter Roeck <groeck@chromium.org>
[remove linux/delay.h]
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 3d02d708 12-Mar-2019 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Fix the maths for gyro scale calculation

Calculation did not use IIO_DEGREE_TO_RAD and implemented a variant to
avoid precision loss as we aim a nano value. The offset added to avoid
rounding error, though, doesn't give us a close result to the expected
value. E.g.

For 1000dps, the result should be:

(1000 * pi ) / 180 >> 15 ~= 0.000532632218

But with current calculation we get

$ cat scale
0.000547890

Fix the calculation by just doing the maths involved for a nano value

val * pi * 10e12 / (180 * 2^15)

so we get a closer result.

$ cat scale
0.000532632

Fixes: c14dca07a31d ("iio: cros_ec_sensors: add ChromeOS EC Contiguous Sensors driver")
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 5a0b8cb4 13-Mar-2018 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Move cros_ec_sensors_core.h in /include

Similar to other common iio frameworks, move cros_ec_sensors_core.h from
drivers/iio/common/cros_ec_sensors/ to include/linux/iio/common.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 0dad1ece 21-Feb-2018 Gwendal Grignou <gwendal@chromium.org>

iio: cros_ec: Relax sampling frequency before suspending

If an application set a tight sampling frequency, given the interrupt
use is a wakeup source, suspend will not happen: the kernel will receive
a wake up interrupt and will cancel the suspend process.

Given cros_ec sensors type is non wake up, this patch adds prepare and
complete callbacks to set 1s sampling period just before suspend. This
ensures the sensor hub will not be a source of interrupt during the
suspend process.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# 5f045af0 18-Nov-2017 Paolo Cretaro <paolocretaro@gmail.com>

iio: cros_ec: Remove unused variables

Fix gcc warnings about variable 'ec_device' being set but not used
in these files:
common/cros_ec_sensors/cros_ec_sensors.c:194:25
light/cros_ec_light_prox.c:184:25

Signed-off-by: Paolo Cretaro <paolocretaro@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


# d177f6af 23-Jul-2017 Jonathan Cameron <jic23@kernel.org>

iio:common: 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.

Clearly this set jumps across multiple areas, but inherently it
can't be grouped like the other sets in this series so I've done
all the stuff in the common directory together.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>


# 754434c4 24-Mar-2017 Enric Balletbo i Serra <enric.balletbo@collabora.com>

iio: cros_ec_sensors: Use devm to setup the triggered buffer.

Use resourced managed function devm_iio_triggered_buffer_setup
to make error path simpler and be able to get rid of the remove
function.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>


# a096926e 24-Mar-2017 Enric Balletbo i Serra <enric.balletbo@collabora.com>

iio: cros_ec_sensors: Fix return value to get raw and calibbias data.

The cros_ec_sensors_read function must return the type of value on all
cases. This was always true except for RAW and CALIBBIAS data which
returned an error or 0. This patch just fixes the mistake I introduced
when submitting the series.

Fixes: commit c14dca07a31d (iio: cros_ec_sensors: add ChromeOS EC
Contiguous Sensors driver)

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>


# 5668bfdd 01-Aug-2016 Enric Balletbo i Serra <enric.balletbo@collabora.com>

platform/chrome: cros_ec_dev - Register cros-ec sensors

Check whether the ChromeOS Embedded Controller is a sensor hub and in
such case issue a command to get the number of sensors and register them
all.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Acked-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>


# c14dca07 01-Aug-2016 Enric Balletbo i Serra <enric.balletbo@collabora.com>

iio: cros_ec_sensors: add ChromeOS EC Contiguous Sensors driver

Handle 3d contiguous sensors like Accelerometers, Gyroscope and
Magnetometer that are presented by the ChromeOS EC Sensor hub.

Signed-off-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>