summaryrefslogtreecommitdiff
path: root/drivers/iio/magnetometer/st_magn_core.c
AgeCommit message (Collapse)Author
2016-06-20Merge 4.7-rc4 into staging-nextGreg Kroah-Hartman
We want the fixes in here, and we can resolve a merge issue in drivers/iio/industrialio-trigger.c Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-05-29iio: st_sensors: switch to a threaded interruptLinus Walleij
commit 98ad8b41f58dff6b30713d7f09ae3834b8df7ded ("iio: st_sensors: verify interrupt event to status") caused a regression when reading ST sensors from a HRTimer trigger rather than the intrinsic interrupts: the HRTimer may trigger faster than the sensor provides new values, and as the check against new values available as a cause of the interrupt trigger was done in the poll function, this would bail out of the HRTimer interrupt with IRQ_NONE. So clearly we need to only check the new values available from the proper interrupt handler and not from the poll function, which should rather just read the raw values from the registers, put them into the buffer and be happy. To achieve this: switch the ST Sensors over to using a true threaded interrupt handler. In the interrupt thread, check if new values are available, else yield to the (potential) next device on the same interrupt line to check the registers. If the interrupt was ours, proceed to poll the values. Instead of relying on iio_trigger_generic_data_rdy_poll() as a top half to wake up the thread that polls the sensor for new data, have the thread call iio_trigger_poll_chained() after determining that is is the proper source of the interrupt. This is modelled on drivers/iio/accel/mma8452.c which is already using a properly threaded interrupt handler. In order to get the same precision in timestamps as previously, where samples would be timestamped in the poll function pf->timestamp when calling iio_trigger_generic_data_rdy_poll() we introduce a local timestamp in the sensor data, set it in the top half (fastpath) of the interrupt handler and provide that to the core when calling iio_push_to_buffers_with_timestamp(). Additionally: if the active scanmask is not set for the sensor no IRQs should be enabled and we need to bail out with IRQ_NONE. This can happen if spurious IRQs fire when installing the threaded interrupt handler. Tested with hard interrupt triggers on LIS331DL, then also tested with hrtimers on the same sensor by creating a 75Hz HRTimer and using it to poll the sensor. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Cc: Giuseppe Barba <giuseppe.barba@st.com> Cc: Denis Ciocca <denis.ciocca@st.com> Reported-by: Crestez Dan Leonard <cdleonard@gmail.com> Tested-by: Crestez Dan Leonard <cdleonard@gmail.com> Tested-by: Jonathan Cameron <jic23@kernel.org> Fixes: 97865fe41322 ("iio: st_sensors: verify interrupt event to status") Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-05-29iio:st_sensors: fix power regulator usageGregor Boirie
Ensure failure to enable power regulators is properly handled. Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-04-19iio: st_sensors: verify interrupt event to statusLinus Walleij
This makes all ST sensor drivers check that they actually have new data available for the requested channel(s) before claiming an IRQ, by reading the status register (which is conveniently the same for all ST sensors) and check that the channel has new data before proceeding to read it and fill the buffer. This way sensors can share an interrupt line: it can be flaged as shared and then the sensor that did not fire will return NO_IRQ, and the sensor that fired will handle the IRQ and return IRQ_HANDLED. Cc: Giuseppe Barba <giuseppe.barba@st.com> Cc: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-01-10iio: st_sensors: support active-low interruptsLinus Walleij
Most ST MEMS Sensors that support interrupts can also handle sending an active low interrupt, i.e. going from high to low on data ready (or other interrupt) and thus triggering on a falling edge to the interrupt controller. Set up logic to inspect the interrupt line we get for a sensor: if it is triggering on rising edge, leave everything alone, but if it triggers on falling edges, set up active low, and if unsupported configurations appear: warn with errors and reconfigure the interrupt to a rising edge, which all interrupt generating sensors support. Create a local header for st_sensors_core.h to share functions between the sensor core and the trigger setup code. Cc: Giuseppe Barba <giuseppe.barba@st.com> Cc: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-08-16iio: st_sensors: add debugfs register read hookLinus Walleij
This adds a debugfs hook to read/write registers in the ST sensors using debugfs. Proved to be awesome help when trying to debug why IRQs do not arrive. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-07-23iio: st-magn: add support for lsm303agr magnetometerGiuseppe Barba
This adds support for the lsm303agr magnetometer. Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com> Acked-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-07-23iio: st_magn: Add irq trigger handlingGiuseppe Barba
Add irq trigger handling for magnetometer also Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com> Acked-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-07-23iio: st-sensors: add configuration for WhoAmI addressGiuseppe Barba
This patch permits to configure the WhoAmI register address because some device could have not a standard address for this register. Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com> Reviewed-by: Denis Ciocca <denis.ciocca@st.com> Acked-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-05-18Merge 4.1-rc4 into staging-nextGreg Kroah-Hartman
We want the fixes in here for testing and merge issues. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-05-07iio: magnetometer: support for lsm303dlhLinus Walleij
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>
2015-04-26iio:st_sensors: Fix oops when probing SPI devicesAlban Bedel
In SPI mode the transfer buffer is locked with a mutex. However this mutex is only initilized after the probe, but some transfer needs to be done in the probe. To fix this bug we move the mutex initialization at the beginning of the device probe. Signed-off-by: Alban Bedel <alban.bedel@avionic-design.de> Acked-by: Denis Ciocca <denis.ciocca@st.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-11-05Merge tag 'iio-for-3.19a' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: First round of new drivers, features and cleanups for IIO in the 3.19 cycle. New drivers / supported parts * rockchip - rk3066-tsadc variant * si7020 humidity and temperature sensor * mcp320x - add mcp3001, mcp3002, mcp3004, mcp3008, mcp3201, mcp3202 * bmp280 pressure and temperature sensor * Qualcomm SPMI PMIC current ADC driver * Exynos_adc - support exynos7 New features * vf610-adc - add temperature sensor support * Documentation of current attributes, scaled pressure, offset and scaled humidity, RGBC intensity gain factor and scale applied to differential voltage channels. * Bring iio_event_monitor up to date with newer modifiers. * Add of_xlate function to allow for complex channel mappings from the device tree. * Add -g parameter to generic_buffer example to allow for devices with directly fed (no trigger) buffers. * Move exynos driver over to syscon for PMU register access. Cleanups, fixes for new drivers * lis3l02dq drop an unneeded else. * st sensors - renam st_sensors to st_sensor_settings (for clarity) * st sensors - drop an unused parameter from all the probe utility functions. * vf610 better error handling and tidy up. * si7020 - cleanups following merge * as3935 - drop some unnecessary semicolons. * bmp280 - fix the pressure calculation.
2014-10-04iio:magnetometer: Removed unnecessary parameter on common_probe functionDenis CIOCCA
Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-10-04iio:imu: changed structure name from st_sensors to st_sensor_settingsDenis CIOCCA
This patch change structure name and related variables names. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-09-14iio:magnetometer: bugfix magnetometers gain valuesiio-fixes-3.17aDenis CIOCCA
This patch fix gains values. The first driver was designed using engineering samples, in mass production the values are changed. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Cc: Stable@vger.kernel.org Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-07-07iio:st sensors: remove custom sampling frequence attribute in favour of core ↵Jonathan Cameron
support. This allows in kernel client drivers to access this Signed-off-by: Jonathan Cameron <jic23@kernel.org> Cc: Denis Ciocca <denis.ciocca@st.com> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
2014-04-26iio: st_sensors: move regulator retrieveal to coreiio-for-3.16aLinus Walleij
Currently the pressure sensor has code to retrieve and enable two regulators for Vdd and Vdd IO, but actually these voltage inputs are found on all of these ST sensors, so move the regulator handling to the core and make sure all the ST sensors call these functions on probe() and remove() to enable/disable power. Here also mover over to obtaining the regulator from the *parent* device of the IIO device, as the IIO device is created on-the-fly in this very subsystem it very unlikely evert have any regulators attached to it whatsoever. It is much more likely that the parent is a platform device, possibly instantiated from a device tree, which in turn have Vdd and Vdd IO supplied assigned to it. Cc: Lee Jones <lee.jones@linaro.org> Cc: Denis CIOCCA <denis.ciocca@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-04-26iio: st_sensors: announce registered sensorsLinus Walleij
It is pretty helpful to know already from dmesg that a certain device is successfully registered, instead of having to browse sysfs to see if it's actually there. Cc: Lee Jones <lee.jones@linaro.org> Cc: Denis CIOCCA <denis.ciocca@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-10-06Merge 3.12-rc4 into staging-nextGreg Kroah-Hartman
We want the staging fixes in this branch as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-09-30iio:magnetometer: Bugfix magnetometer default output registersiio-fixes-for-3.12b2Denis CIOCCA
Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-09-21iio:magn: Register buffer also without specific triggerDenis CIOCCA
This patch fix buffer registration that allows to use generic IIO trigger. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-09-21iio: magn-core: st: Clean up error handling in probe()Lee Jones
Reduce the amount of those unnecessary goto calls, as in most cases we can simply return immediately. We also only call for the IRQ number once and use that value throughout. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-08-03iio: magnetometer: st_magn: Use devm_iio_device_allocSachin Kamat
Using devm_iio_device_alloc makes code simpler. Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org> Cc: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-08-03iio: Added ST-sensors platform data to select the DRDY interrupt pinDenis CIOCCA
This patch add support to redirect the DRDY interrupt on INT1 or INT2 on accelerometer and pressure sensors. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-06-05iio:common: Removed stuff macros, added num_data_channels on st_sensors ↵Denis CIOCCA
struct and added support on one-shot sysfs reads to 3 byte channel This patch introduce num_data_channels variable on st_sensors struct to manage different type of channels (size or number) in st_sensors_get_buffer_element function. Removed ST_SENSORS_NUMBER_DATA_CHANNELS and ST_SENSORS_BYTE_FOR_CHANNEL and used struct iio_chan_spec const *ch to catch data. Added 3 byte channel data support on one-shot reads. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-06-04iio:common: ST_SENSORS_LSM_CHANNELS macro changedDenis CIOCCA
Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-02-09iio:st_sensors fix build when !CONFIG_IIO_TRIGGERJonathan Cameron
Partly a case of removing unused headers and partly a case of ifdefing out the iio_trigger_ops structures. This has come about because of an 'unusual' separation of code in this driver. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Reported-by: Randy Dunlap <rdunlap@infradead.org> Acked-by: Denis Ciocca <denis.ciocca@st.com>
2013-01-31iio:magnetometer: Add STMicroelectronics magnetometers driverDenis Ciocca
This patch adds a generic magnetometer driver for STMicroelectronics magnetometers, currently it supports: LSM303DLHC, LSM303DLM, LIS3MDL. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>