The LSM303DLH accelerometer/magnetometer has a different
device identification method than using register 0x0f, instead
three registers contain a magic value. We rely on WhoAmI
to be zero for this variant.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
The ST sensors are detected by reading a WhoAmI register and
matching the number found to a sensor name string. To make it
easier to figure out what happens when things go wrong, print
the WhoAmI value and the device name we're trying to match.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Not all sensors support BDU (block data update) and in fact a
bunch of the in-kernel sensor settings do not specify the
BDU address field. Make this optional.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Some sensors such as magnetometers and pressure sensors doesn't
have interrupts at all, and thus no DRDY setting applies. Make
the assignment of an interrupt optional, and do not call
st_sensors_set_drdy_int_pin() if there is no drdy (data ready)
pin specified.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Print a proper error message if we're missing the trigger
IRQ.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Some extra blank lines between if checks don't hurt and improve
readability.
Signed-off-by: Antonio Ospite <ao2@ao2.it>
Cc: Bastien Nocera <hadess@hadess.net>
Reviewed-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This id has been seen in the DSDT of the Teclast X98 Air 3G tablet based
on Intel Bay Trail.
Signed-off-by: Antonio Ospite <ao2@ao2.it>
Cc: Bastien Nocera <hadess@hadess.net>
Reviewed-by: Daniel Baluta <daniel.baluta@intel.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Clearly the intent was to error if the value was not 0 or 1.
As implemented we have (A != 0 || A != 1) which is always true
as A is never both 0 and 1 at the same time.
As the autobuilder suggested, && makes more sense for this error
check.
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Cc: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Initial value of gpio bitnum is set to -1, but
the variable is declared as unsigned.
Use a positive invalid value for initial gpio
bitnum.
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Suggested-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Add mma9553_ prefix to all local functions/declarations.
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Suggested-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Use GENMASK instead of BIT or direct value to
define a mask.
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Suggested-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Use "GPIO" instead of "gpio" and "ACPI" instead of "acpi".
Includes a couple of small style fixes in comments
(missing full stop, whitespace, paranthesis).
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Suggested-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Use return 0 instead of return ret to mark
clearly the success return path.
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Suggested-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
When configuring gpio, we need to read initial values for activity and
step count. This function may fail due to i2c read errors.
Check the error code returned by mma9553_read_activity_stepcnt
and return the appropriate error in gpio config function.
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Reported-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Added support for Liteon 301 Ambient light sensor. Since
LTR-301 and LTR-501 are register compatible(and even have same
part id), LTR-501 driver has been extended to support both
devices. LTR-501 is similar to LTR-301 in ALS sensing, But the
only difference is, LTR-501 also supports proximity sensing.
LTR-501 - ALS + Proximity combo
LTR-301 - ALS sensor.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This device is register compatible with LTR501, with a minor difference for
ALS control register as showed below:
ALS Control register for LTR501:
7 6 5 4 3 2 1 0
+------+------+------+------+------+------+------+------+
| | | | |
| Reserved | Gain | SW | ALS Mode |
| | | Reset| |
+------+------+------+------+------+------+------+------+
ALS Control register for LTR559:
7 6 5 4 3 2 1 0
+------+------+------+------+------+------+------+------+
| | | | |
| Reserved | Gain | SW | ALS |
| | | Reset| Mode |
+------+------+------+------+------+------+------+------+
We handle this difference by introducing ltr501_chip_info.
Datasheet for LTR559 is at:
http://optoelectronics.liteon.com/upload/download/DS86-2013-0003/S_110_LTR-559ALS-01_DS_V1.pdf
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Added ACPI enumeration support for LTR501 chip.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Added rate control support for ALS and proximity
threshold interrupts.Also, Added support to modify
and read ALS & proximity sensor sampling frequency.
LTR-501 supports interrupt rate control using persistence
register settings. Writing <n> to persistence register
would generate interrupt only if there are <n> consecutive
data values outside the threshold range.
Since we don't have any existing ABI's to directly
control the persistence register count, we have implemented
the rate control using IIO_EV_INFO_PERIOD. _period event
attribute represents the amount of time in seconds an
event should be true for the device to generate the
interrupt. So using _period value and device frequency,
persistence count is calculated in driver using following
logic.
count = period / measurement_rate
If the given period is not a multiple of measurement rate then
we round up the value to next multiple.
This patch also handles change to persistence count whenever
there is change in frequency.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This patch adds interrupt support for Liteon 501 chip.
Interrupt will be generated whenever ALS or proximity
data exceeds values given in upper and lower threshold
register settings.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Added support to modify and read ALS integration time.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
If a GPIO reset pin is listed in ACPI or Device Tree, use it to reset
the device on initialization.
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
In the interest of lowering power usage, we only activate the proximity
channels and interrupts that we are currently using.
For raw reads, we activate the corresponding channel and the data ready
interrupt and wait for the interrupt to trigger. If no interrupt is
available, we wait for the documented scan period, as specified in the
datasheet.
The following types of usage patterns may overlap:
* raw proximity reads (need a single data ready interrupt)
* trigger usage (needs data ready interrupts as long as active)
* proximity events (need near/far interrupts)
* triggered buffer reads (don't need any interrupts, but are usually
coupled with our own trigger.
To mitigate all possible patterns, we implement usage counting for all
the resources used: data ready interrupts, near/far interrupts and
individual channels.
The device enters sleep mode as documented in the data sheet when its
buffer, trigger and events are disabled, and no raw reads are currently
running.
Because of this new usage pattern, it is important that we give the
device a chance to perform an initial compensation for all its channels
at probe time.
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Fix a typo triggering a duplicate const warning on some compilers.
Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Added regmap support. It will be useful to handle
bitwise updates to als & ps control registers.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This makes ltr501 code consistent with the coding style adopted
for the new drivers added to IIO.
We prepare the path for adding support for LTR559 chip.
Reported by checkpatch.pl
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Refactor DT parsing into a separate function from probe() to
help addition of more DT parameters later.
No functional changes.
Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
The device uses the MSB of the returned temperature value as an error
flag. Return a read error when this bit is set.
Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Add support for system sleep and runtime power management.
To wake up the device, the SDA line should be held low for at least 33ms
while SCL is high. As this is not possible using the i2c API (and not
supported by all i2c adapters), a GPIO connected to the SDA line is
needed. The GPIO is named "wakeup" and can be specified in a device
tree with the "wakeup-gpios" binding.
If the wake-up GPIO is not given, disable power management for the
device. Entering sleep requires an SMBus byte access, hence power
management is also disabled if byte access is not supported by the
adapter.
Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
The mapping from the 16-bit EEPROM value to the decimal 0-1 range is
approximate. A special case ensures 0xFFFF shows as 1.0 instead of
0.999998565.
Writing to EEPROM requires an explicit erase by writing zero. In
addition, it takes 20ms for the erase/write to complete. During this
time no EEPROM register should be accessed. Therefore, two msleep()s
are added to the write function and a mutex protects against concurrent
access.
Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Contact-less IR temperature sensors measure the temperature of an object
by using its thermal radiation. Surfaces with different emissivity
ratios emit different amounts of energy at the same temperature.
IIO_CHAN_INFO_CALIBEMISSIVITY allows the user to inform the sensor of the
emissivity of the object in front of it, in order to effectively measure
its temperature.
A device providing such setting is Melexis's MLX90614:
http://melexis.com/Assets/IR-sensor-thermometer-MLX90614-Datasheet-5152.aspx.
Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
In its present state, the driver mandates that its buffer only be
triggered by one of the device's own triggers (data ready or any
motion). This is not always desirable, for example because the
interrupt pins may not be wired in.
Patch the driver to be able to accept using an external trigger, such as
one based on hrtimer. When using such a trigger, we need to ensure that
the device is powered on when the buffer is started. We do that by
setting setup_ops for the buffer.
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
We want those fixes (iio primarily) into the -next branch to help with
merge and testing issues.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Power down device when an error occurs in order to avoid wasting
power. Move powerdown function up to be seen by the new call and
align parameters for the ltr501_write_contr() call.
Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Place driver on standby mode on error in order to prevent wasting
power. Move standby function above to be seen by the new call.
Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
The model is detected by reading the EEPROM configuration during
probing.
Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Add symbols for all accessible RAM and EEPROM registers, as well as the
sleep command and timings defined in the datasheet.
Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
We only advertise hardware fifo support if the I2C bus supports full
I2C or smbus I2C block data reads since it is mandatory to read the
full frame in one read (otherwise the rest of the frame is discarded).
The hardware fifo is enabled only when triggers are not active because:
(a) when using the any-motion trigger the user expects to see samples
based on ROC events, but the fifo stores samples based on the sample
frequency
(b) the data-ready trigger is waking the CPU for for every sample, so
using the hardware fifo does not have any benefit
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Some devices have hardware buffers that can store a number of samples
for later consumption. Hardware usually provides interrupts to notify
the processor when the FIFO is full or when it has reached a certain
watermark level. This helps with reducing the number of interrupts to
the host processor and thus it helps decreasing the power consumption.
This patch enables usage of hardware FIFOs for IIO devices in
conjunction with software device buffers. When the hardware FIFO is
enabled the samples are stored in the hardware FIFO. The samples are
later flushed to the device software buffer when the number of entries
in the hardware FIFO reaches the hardware watermark or when a flush
operation is triggered by the user when doing a non-blocking read
on an empty software device buffer.
In order to implement hardware FIFO support the device drivers must
implement the following new operations: setting and getting the
hardware FIFO watermark level, flushing the hardware FIFO to the
software device buffer. The device must also expose information about
the hardware FIFO such it's minimum and maximum watermark and if
necessary a list of supported watermark values. Finally, the device
driver must activate the hardware FIFO when the device buffer is
enabled, if the current device settings allows it.
The software device buffer watermark is passed by the IIO core to the
device driver as a hint for the hardware FIFO watermark. The device
driver can adjust this value to allow for hardware limitations (such
as capping it to the maximum hardware watermark or adjust it to a
value that is supported by the hardware). It can also disable the
hardware watermark (and implicitly the hardware FIFO) it this value is
below the minimum hardware watermark.
Since a driver may support hardware FIFO only when not in triggered
buffer mode (due to different semantics of hardware FIFO sampling and
triggered sampling) this patch changes the IIO core code to allow
falling back to non-triggered buffered mode if no trigger is enabled.
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Currently the IIO buffer blocking read only wait until at least one
data element is available.
This patch makes the reader sleep until enough data is collected before
returning to userspace. This should limit the read() calls count when
trying to get data in batches.
Co-author: Yannick Bedhomme <yannick.bedhomme@mobile-devices.fr>
Signed-off-by: Josselin Costanzi <josselin.costanzi@mobile-devices.fr>
[rebased and remove buffer timeout]
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>