summaryrefslogtreecommitdiff
path: root/drivers/iio/adc
AgeCommit message (Collapse)Author
2020-01-31iio: adc: qcom-vadc-common: use <linux/units.h> helpersAkinobu Mita
This switches the qcom-vadc-common to use milli_kelvin_to_millicelsius() in <linux/units.h>. Link: http://lkml.kernel.org/r/1576386975-7941-13-git-send-email-akinobu.mita@gmail.com Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Hartmut Knaack <knaack.h@gmx.de> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Amit Kucheria <amit.kucheria@verdurent.com> Cc: Andy Shevchenko <andy@infradead.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Darren Hart <dvhart@infradead.org> Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com> Cc: Guenter Roeck <linux@roeck-us.net> Cc: Jean Delvare <jdelvare@suse.com> Cc: Jens Axboe <axboe@fb.com> Cc: Johannes Berg <johannes.berg@intel.com> Cc: Jonathan Cameron <jic23@kernel.org> Cc: Kalle Valo <kvalo@codeaurora.org> Cc: Keith Busch <kbusch@kernel.org> Cc: Luca Coelho <luciano.coelho@intel.com> Cc: Sagi Grimberg <sagi@grimberg.me> Cc: Stanislaw Gruszka <sgruszka@redhat.com> Cc: Sujith Thomas <sujith.thomas@intel.com> Cc: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-22Merge 5.5-rc7 into staging-nextGreg Kroah-Hartman
We want the staging fixes in here as well Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-18iio: adc: stm32-adc: don't print an error on probe deferralEtienne Carriere
Do not print an error trace when deferring probe for some resource. Signed-off-by: Etienne Carriere <etienne.carriere@st.com> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-18iio: adc: ad7124: Set IRQ type to fallingAlexandru Tachici
Ad7124 data-sheet specifies that the falling edge of the DOUT line should be used for an interrupt. The current irq flag (IRQF_TRIGGER_LOW) used will cause unwanted behaviour. When enabling the interrupt it will fire once because the DOUT line is already low. This will make the driver to read an unfinished conversion from the chip. This patch sets the irq type to the one specified in the data-sheet. Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-18iio: adc: ad-sigma-delta: Allow custom IRQ flagsAlexandru Tachici
Before this patch the ad_sigma_delta implementation hardcoded the irq trigger type to low, assuming that all Sigma-Delta ADCs have the same interrupt-type. This patch allows all drivers using the ad_sigma_delta layer to set the irq trigger type to the one specified in the datasheet. Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-13iio: adc: stm32-dfsdm: adapt sampling rate to oversampling ratioOlivier Moysan
Update sampling rate when oversampling ratio is changed through the IIO ABI. Signed-off-by: Olivier Moysan <olivier.moysan@st.com> Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-13iio: adc: stm32-dfsdm: fix single conversionOlivier Moysan
Apply data formatting to single conversion, as this is already done in continuous and trigger modes. Fixes: 102afde62937 ("iio: adc: stm32-dfsdm: manage data resolution in trigger mode") Signed-off-by: Olivier Moysan <olivier.moysan@st.com> Cc: <Stable@vger.kernel.org> Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-13iio: adc: ad7124: Fix DT channel configurationAlexandru Tachici
This patch fixes device tree channel configuration. ad7124 driver reads channels configuration from the device tree. It expects to find channel specifications as child nodes. Before this patch ad7124 driver assumed that the child nodes are parsed by for_each_available_child_of_node in the order 0,1,2,3... This is wrong and the real order of the children can be seen by running: dtc -I fs /sys/firmware/devicetree/base on the machine. For example, running this on an rpi 3B+ yields the real children order: 4,2,0,7,5,3,1,6 Before this patch the driver assigned the channel configuration like this: - 0 <- 4 - 1 <- 2 - 2 <- 0 ........ For example, the symptoms can be observed by connecting the 4th channel to a 1V tension and then reading the in_voltage0-voltage19_raw sysfs (multiplied of course by the scale) one would see that channel 0 measures 1V and channel 4 measures only noise. Now the driver uses the reg property of each child in order to correctly identify to which channel the parsed configuration belongs to. Fixes b3af341bbd966: ("iio: adc: Add ad7124 support") Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-12iio: adc: at91-sama5d2_adc: Use dma_request_chan() instead ↵Peter Ujfalusi
dma_request_slave_channel() dma_request_slave_channel() is a wrapper on top of dma_request_chan() eating up the error code. The dma_request_chan() is the standard API to request slave channel, clients should be moved away from the legacy API to allow us to retire them. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-12iio: adc: stm32-adc: Use dma_request_chan() instead dma_request_slave_channel()Peter Ujfalusi
dma_request_slave_channel() is a wrapper on top of dma_request_chan() eating up the error code. By using dma_request_chan() directly the driver can support deferred probing against DMA. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-12iio: adc: stm32-dfsdm: Use dma_request_chan() instead ↵Peter Ujfalusi
dma_request_slave_channel() dma_request_slave_channel() is a wrapper on top of dma_request_chan() eating up the error code. By using dma_request_chan() directly the driver can support deferred probing against DMA. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Acked-by: Olivier Moysan <olivier.moysan@st.com> Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-01-10Merge tag 'iio-for-5.6a' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: First set of new device support, features and cleanups for IIO in the 5.6 cycle New device support * ad7091r5 ADC - New driver with follow up patch adding scale and vref support. - DT bindings * ad7923 - Support for ad7908, ad7918 and ad7928 added to driver. * bma180 - Support the BMA254 accelerometer. Required fairly substantial rework to allow for small differences between this an existing parts. * bma400 accelerometer - New driver with follow up patch for regulator support. - DT bindings. * asc dlhl60d - New driver support this range of pressure and temperature sensors. - DT bindings. * ltc2496 ADC - New driver to support this ADC. - Split the existing LTC2497 driver generic component out and reuse. - DT bindings. * parallax ping - New driver supporting ultrasonic and laser tof distance sensors. - Bindings for these sensors. New features * core - New char type for read_raw returns, used for thermocouple types. - Rename read_first_n callback to read. The reasons behind the original naming are lost to the mists of time. * ad799x - Allow pm_ops to disable device completely allowing regulator power down. * bma180 - Enable basic regulator support. * dmaengine buffer - Report platform data alignment requirements via new ABI. * max31856 - Add option to set mains filter rejection frequency and document new in_temp_filter_notch_center_frequency ABI. - Add support for configuring HW averaging (oversampling ratio) - Add runtime configuration of thermocouple type and document new ABI. * maxim-thermocouple - Add read only access to thermocouple type using new ABI, includes adding more specific compatibles to reflect which variant of the chip is being used. * mpu6050 - Provide option to support the PMU9150 in package magnetometer directly rather than via auxiliary bus. * stm32_adc - Add overrun interrupt checks to detect if this happens. * st_lsm6dsx - Enable the sensor-hub support for lsm6dsm. Includes various reworks to allow this. Cleanups and minor fixes * Subsystem wide - Tidy up indentation in Kconfig and fix alphabetical order of AD7091R5. - Drop linux/gpio.h and linux/of_gpio.h from drivers that don't use them. * ad7266 - Convert to GPIO descriptors. * ad7303 - Avoid a dance with checking if the regulator is supplied by just using the optional request interface. * ad7887 - Simplify channel specification assignment to enable adding more devices. * ad7923 - Drop some unused and largely pointless defines of BOB_N==N variety. - Tidy up checkpatch warnings. - Add missing of_device_id table. * adf4350 - Convert to GPIO descriptors. * ak8975 - Convert to GPIO descriptors. * ADIS library and drivers - Expand scope of txrx_lock to cover all state and rename as state_lock - Add unlocked read / write to allow grouping of consecutive calls under single lock / unlock. - Add unlocked check_status, reset to allow grouping under single lock / unlock. - Remove remaining uses of core mlock for local state protection. mlock should never be used directly as it protects tightly defined core IIO device management state. * adis16240 - Enforce only supported SPI mode on driver load + add DT binding doc. * atlas-ph-sensor - Rename to atlas-sensor given it now covers things beyond ph sensors. * bma180 - Use local dev variable to tidy up code. - Use c99 style explicity .member assignment to make driver more readable. * bmp280 - Drop ACPI support. No evidence this was used and appropriate ID is not registered. - Allow ACPI to bind device via PRP0001 * dmaengine buffer - Use dma_request_chan instead of dma_request_slave_channel_reason as that ABI is going away. - Add module info to avoid tainting the kernel. * hts221 - Avoid magic number defines when only used to fill structure elements that are self describing. * lm3533 - Drop a stray semicolon. * max9611 - Cleanup enum handling to be more resilient to future changes. * mpu6050 - Delete MPU9150 from supported SPI devices as doesn't provide SPI. - Select I2C_MUX again after kbuild issue fixed elsewhere. * stm32-timer - Drop an unnecessary register update. * ssp_sensors - Convert to GPIO descriptors. * st_sensors - drop !CONFIG_ACPI defines as ACPI_PTR() will stop them being used anyway. - Make default platform data structures __maybe_unsued. - Fill in some missing kernel-doc function parameters. * st_lsm6dsx - white space fixes. - Mark some constants that aren't always used as __maybe_unused. - Drop of ID table guards as they just pervent use under ACPI. - Switch to device properties to allow ACPI usage. * st_uvis25 - Drop acpi.h include as no ACPI APIs used. * ti-ads1015 - Drop legacy platform data as no one seems to be using it. - Use the device property API instead of OF specific. * ti-ads7950 - typo fix in error message. * tag 'iio-for-5.6a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (99 commits) iio: accel: bma180: BMA254 support iio: pressure: bmp280: Allow device to be enumerated from ACPI iio: pressure: bmp280: Drop ACPI support dt-bindings: iio: adc: convert sd modulator to json-schema iio: buffer: rename 'read_first_n' callback to 'read' iio: buffer-dmaengine: Report buffer length requirements bindings: iio: pressure: Add documentation for dlh driver dt-bindings: Add asc vendor iio: pressure: Add driver for DLH pressure sensors iio: buffer-dmaengine: Add module information iio: accel: bma180: Use explicit member assignment iio: accel: bma180: Basic regulator support iio: accel: bma180: Add dev helper variable iio: imu: st_lsm6dsx: enable sensor-hub support for lsm6dsm iio: imu: st_lsm6dsx: rename st_lsm6dsx_shub_read_reg in st_lsm6dsx_shub_read_output iio: imu: st_lsm6dsx: check if shub_output reg is located in primary page iio: imu: st_lsm6dsx: check if pull_up is located in primary page iio: imu: st_lsm6dsx: check if master_enable is located in primary page iio: imu: st_lsm6dsx: export max num of slave devices in st_lsm6dsx_shub_settings iio: light: remove unneeded semicolon ...
2019-12-29iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928Daniel Junho
The ad7928 is software compatible with the ad7923. The ad7908 and ad7918 are the 8 and 10-bit versions of the ad7928. Signed-off-by: Daniel Junho <djunho@gmail.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-29iio: adc: ad7923: Add of_device_id tableDaniel Junho
Accomplish device tree compatibility to driver AD7923 by adding of_device_id table and making a subsequent call to MODULE_DEVICE_TABLE. Signed-off-by: Daniel Junho <djunho@gmail.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-29iio: adc: ad7923: Fix checkpatch warningDaniel Junho
Fix checkpatch warning: WARNING: Prefer 'unsigned int' to bare use of 'unsigned' +static int ad7923_scan_direct(struct ad7923_state *st, unsigned ch) Signed-off-by: Daniel Junho <djunho@gmail.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-29iio: adc: ad7923: Remove the unused definesDaniel Junho
Removes the unused define AD7923_CHANNEL_x from the code. Signed-off-by: Daniel Junho <djunho@gmail.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: new driver to support Linear technology's ltc2496Uwe Kleine-König
This chip is similar to the LTC2497 ADC, it just uses SPI instead of I2C and so has a slightly different protocol. Only the actual hardware access is different. The spi protocol is different enough to not be able to map the differences via a regmap. Also generalize the entry in MAINTAINER to cover the newly introduced file. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: ltc2497: split protocol independent part in a separate moduleUwe Kleine-König
This allows to share most of this driver for the ltc2496 driver added in the next commit that is an SPI variant of the ltc2497. Initially I named the generic part ltc249x, but wild card names are frowned upon, so the generic part is called ltc2497-core even though it's not obvious that this is then to be reused for the ltc2496 driver. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: ti-ads1015: Make use of device property APIAndy Shevchenko
Make use of device property API in this driver so that both OF based system and ACPI based system can use this driver. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: ti-ads1015: Get rid of legacy platform dataAndy Shevchenko
Platform data is a legacy interface to supply device properties to the driver. In this case we even don't have in-kernel users for it. Just remove it for good. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: ti-ads7950: Fix a typo in an error messageChristophe JAILLET
Fix a typo: s/get get/to get/ Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: stm32-adc: Add check on overrun interruptFabrice Gasnier
Enable overrun interrupt on STM32 ADC. In case data register hasn't been read (by CPU or DMA), overrun condition is detected when there's new conversion data available. Stop grabbing data and log an error message. Use a threaded irq to avoid printing the error message from hard irq context. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: Move AD7091R5 entry in a alphabetical order in MakefileBeniamin Bia
Ad7091R5 was added in a non alphabetical order after AD7124 in Makefile and KConfig. This patch fixes that and place Ad7091R5 before AD7124. Signed-off-by: Beniamin Bia <beniamin.bia@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: ad7266: Convert to use GPIO descriptorsLinus Walleij
The AD7266 have no in-tree users making use of the platform data mechanism to pass address GPIO lines when not using a fixed address, so we can easily convert this to use GPIO descriptors instead of the platform data integers currently passed. Lowercase the labels "ad0".."ad2" as this will make a better fit for platform descriptions like device tree that prefer lowercase names such as "ad0-gpios" rather than "AD0-gpios". Board files and other static users of this device can pass the same GPIO descriptors using machine descriptor tables if need be. Cc: Alison Schofield <amsfield22@gmail.com> Cc: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: ad799x: add pm_ops to disable the device completelyMarco Felsch
The device is always in a low-power state due to the hardware design. It wakes up upon a conversion request and goes back into the low-power state. The pm ops are added to disable the device completely and to free the regulator. Disbaling the device completely should be not that notable but freeing the regulator is important. Because if it is a shared power-rail the regulator won't be disabled during suspend-to-ram/disk and so all devices connected to that rail keeps on. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-15iio: adc: ad7887: Cleanup channel assignmentBeniamin Bia
The channels specification assignment in chip info was simplified. This patch makes supporting other devices by this driver easier. Signed-off-by: Beniamin Bia <beniamin.bia@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-09Merge tag 'iio-fixes-for-5.5a' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus Jonathan writes: First set of fixes for IIO in the 5.5 cycle. Mixture of old things people have just hit, and a few late breaking issues with things that went in during the merge window. Being sent promptly to resolve potential DT breakage causing issues for binding test builds. * ad7606 - Avoid reading extra data from the device over what was intended. * ad7124 - Enable the internal reference when in use. * ad7292 - Fix up license for newly added binding. Better to not have this go out in a release with more limited header than intended. - Fix a constraint on number of channels. * ad7949 - Fix an issue which can result in readouts being from the wrong channel. * hdc100x - Fix wrong ABI usage (units) for relative humidity channel. * intel mrfld - Allocate right amount of private data (currently allocating too much). * ltc2983 - Avoid a potential issue with machine endianness and wrong length device tree read. * max1027 - Clean up leak of an iio_trigger on probe failure. * max9611 - Ensure we sleep long enough to successfully initialize the sensor. * mpu6050 - Fix wrong ABI usage (units) for temperature channel. * st_accel - Fix an unused variable warning. * st_lsm6dsx - Fix decimation factor issue that can lead to missaligned datasets (and hence garbage) - Fix an issue with how we track enabled fifo channels. - Avoid powering off the device if wake up events are enabled. * tag 'iio-fixes-for-5.5a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: adc: max9611: Fix too short conversion time delay iio: ad7949: fix channels mixups iio: imu: st_lsm6dsx: do not power-off accel if events are enabled iio: imu: st_lsm6dsx: track hw FIFO buffering with fifo_mask iio: imu: st_lsm6dsx: fix decimation factor estimation iio: imu: inv_mpu6050: fix temperature reporting using bad unit iio: humidity: hdc100x: fix IIO_HUMIDITYRELATIVE channel reporting iio: adc: max1027: fix not unregistered iio trigger iio: adc: intel_mrfld_adc: Allocating too much data in probe() iio: adc: ad7124: Enable internal reference dt-bindings: iio: adc: ad7292: fix constraint over channel quantity dt-bindings: iio: adc: ad7292: Update SPDX identifier iio: temperature: ltc2983: fix u32 read into a unsigned long long iio: st_accel: Fix unused variable warning iio: adc: ad7606: fix reading unnecessary data from device
2019-12-08iio: adc: max9611: Fix too short conversion time delayGeert Uytterhoeven
As of commit b9ddd5091160793e ("iio: adc: max9611: Fix temperature reading in probe"), max9611 initialization sometimes fails on the Salvator-X(S) development board with: max9611 4-007f: Invalid value received from ADC 0x8000: aborting max9611: probe of 4-007f failed with error -5 The max9611 driver tests communications with the chip by reading the die temperature during the probe function, which returns an invalid value. According to the datasheet, the typical ADC conversion time is 2 ms, but no minimum or maximum values are provided. Maxim Technical Support confirmed this was tested with temperature Ta=25 degreeC, and promised to inform me if a maximum/minimum value is available (they didn't get back to me, so I assume it is not). However, the driver assumes a 1 ms conversion time. Usually the usleep_range() call returns after more than 1.8 ms, hence it succeeds. When it returns earlier, the data register may be read too early, and the previous measurement value will be returned. After boot, this is the temperature POR (power-on reset) value, causing the failure above. Fix this by increasing the delay from 1000-2000 µs to 3000-3300 µs. Note that this issue has always been present, but it was exposed by the aformentioned commit. Fixes: 69780a3bbc0b1e7e ("iio: adc: Add Maxim max9611 ADC driver") Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-08iio: ad7949: fix channels mixupsAndrea Merello
Each time we need to read a sample (from the sysfs interface, since the driver supports only it) the driver writes the configuration register with the proper settings needed to perform the said read, then it runs another xfer to actually read the resulting value. Most notably the configuration register is updated to set the ADC internal MUX depending by which channel the read targets. Unfortunately this seems not enough to ensure correct operation because the ADC works in a pipelined-like fashion and the new configuration isn't applied in time. The ADC alternates two phases: acquisition and conversion. During the acquisition phase the ADC samples the analog signal in an internal capacitor; in the conversion phase the ADC performs the actual analog to digital conversion of the stored voltage. Note that of course the MUX needs to be set to the proper channel when the acquisition phase is performed. Once the conversion phase has been completed, the device automatically switches back to a new acquisition; on the other hand the device switches from acquisition to conversion on the rising edge of SPI cs signal (that is when the xfer finishes). Only after both two phases have been completed (with the proper settings already written in the configuration register since the beginning) it is possible to read the outcome from SPI bus. With the current driver implementation, we end up in the following situation: _______ 1st xfer ____________ 2nd xfer ___________________ SPI cs.. \_________/ \_________/ SPI rd.. idle |(val N-2)+ idle | val N-1 + idle ... SPI wr.. idle | cfg N + idle | (X) + idle ... ------------------------ + -------------------- + ------------------ AD .. acq N-1 + cnv N-1 | acq N + cnv N | acq N+1 As shown in the diagram above, the value we read in the Nth read belongs to configuration setting N-1. In case the configuration is not changed (config[N] == config[N-1]), then we still get correct data, but in case the configuration changes (i.e. switching the MUX on another channel), we get wrong data (data from the previously selected channel). This patch fixes this by performing one more "dummy" transfer in order to ending up in reading the data when it's really ready, as per the following timing diagram. _______ 1st xfer ____________ 2nd xfer ___________ 3rd xfer ___ SPI cs.. \_________/ \_________/ \_________/ SPI rd.. idle |(val N-2)+ idle |(val N-1)+ idle | val N + .. SPI wr.. idle | cfg N + idle | (X) + idle | (X) + .. ------------------------ + -------------------- + ------------------- + -- AD .. acq N-1 + cnv N-1 | acq N + cnv N | acq N+1 | .. NOTE: in the latter case (cfg changes), the acquisition phase for the value to be read begins after the 1st xfer, that is after the read request has been issued on sysfs. On the other hand, if the cfg doesn't change, then we can refer to the fist diagram assuming N == (N - 1); the acquisition phase _begins_ before the 1st xfer (potentially a lot of time before the read has been issued via sysfs, but it _ends_ after the 1st xfer, that is _after_ the read has started. This should guarantee a reasonably fresh data, which value represents the voltage that the sampled signal has after the read start or maybe just around it. Signed-off-by: Andrea Merello <andrea.merello@gmail.com> Reviewed-by: Charles-Antoine Couret <charles-antoine.couret@essensium.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-08iio: adc: max1027: fix not unregistered iio triggerChuhong Yuan
The driver forgets to unregister the iio trigger in probe failure and remove. Use devm API to fix it. Signed-off-by: Chuhong Yuan <hslester96@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-08iio: adc: intel_mrfld_adc: Allocating too much data in probe()Dan Carpenter
This probe function is passing the wrong size to devm_iio_device_alloc(). It is supposed to be the size of the private data. Fortunately, sizeof(*indio_dev) is larger than sizeof(struct mrfld_adc) so it doesn't cause a runtime problem. Fixes: a7118662734a ("iio: adc: intel_mrfld_adc: Add Basin Cove ADC driver") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-08iio: adc: ad7124: Enable internal referenceMircea Caprioru
When the internal reference was selected by a channel it was not enabled. This patch fixes that and enables it. Fixes: b3af341bbd96 ("iio: adc: Add ad7124 support") Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-12-08iio: adc: ad7606: fix reading unnecessary data from deviceBeniamin Bia
When a conversion result is being read from ADC, the driver reads the number of channels + 1 because it thinks that IIO_CHAN_SOFT_TIMESTAMP is also a physical channel. This patch fixes this issue. Fixes: 2985a5d88455 ("staging: iio: adc: ad7606: Move out of staging") Reported-by: Robert Wörle <rwoerle@mibtec.de> Signed-off-by: Beniamin Bia <beniamin.bia@analog.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-27Merge tag 'staging-5.5-rc1' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging Pull staging / iio updates from Greg KH: "Here is the big staging and iio set of patches for the 5.5-rc1 release. It's the usual huge collection of cleanup patches all over the drivers/staging/ area, along with a new staging driver, and a bunch of new IIO drivers as well. Full details are in the shortlog, but all of these have been in linux-next for a long time with no reported issues" * tag 'staging-5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (548 commits) staging: vchiq: Have vchiq_dump_* functions return an error code staging: vchiq: Refactor indentation in vchiq_dump_* functions staging: fwserial: Fix Kconfig indentation (seven spaces) staging: vchiq_dump: Replace min with min_t staging: vchiq: Fix block comment format in vchiq_dump() staging: octeon: indent with tabs instead of spaces staging: comedi: usbduxfast: usbduxfast_ai_cmdtest rounding error staging: most: core: remove sysfs attr remove_link staging: vc04: Fix Kconfig indentation staging: pi433: Fix Kconfig indentation staging: nvec: Fix Kconfig indentation staging: most: Fix Kconfig indentation staging: fwserial: Fix Kconfig indentation staging: fbtft: Fix Kconfig indentation fbtft: Drop OF dependency fbtft: Make use of device property API fbtft: Drop useless #ifdef CONFIG_OF and dead code fbtft: Describe function parameters in kernel-doc fbtft: Make sure string is NULL terminated staging: rtl8723bs: remove set but not used variable 'change', 'pos' ...
2019-11-27Merge tag 'char-misc-5.5-rc1' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc Pull char/misc driver updates from Greg KH: "Here is the big set of char/misc and other driver patches for 5.5-rc1 Loads of different things in here, this feels like the catch-all of driver subsystems these days. Full details are in the shortlog, but nothing major overall, just lots of driver updates and additions. All of these have been in linux-next for a while with no reported issues" * tag 'char-misc-5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (198 commits) char: Fix Kconfig indentation, continued habanalabs: add more protection of device during reset habanalabs: flush EQ workers in hard reset habanalabs: make the reset code more consistent habanalabs: expose reset counters via existing INFO IOCTL habanalabs: make code more concise habanalabs: use defines for F/W files habanalabs: remove prints on successful device initialization habanalabs: remove unnecessary checks habanalabs: invalidate MMU cache only once habanalabs: skip VA block list update in reset flow habanalabs: optimize MMU unmap habanalabs: prevent read/write from/to the device during hard reset habanalabs: split MMU properties to PCI/DRAM habanalabs: re-factor MMU masks and documentation habanalabs: type specific MMU cache invalidation habanalabs: re-factor memory module code habanalabs: export uapi defines to user-space habanalabs: don't print error when queues are full habanalabs: increase max jobs number to 512 ...
2019-11-27Merge tag 'for-v5.5' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply Pull power supply and reset updates from Sebastian Reichel: - test_power: add support for current and charge_counter - cpcap-charger: improve charge calculation and limit default charge voltage - ab8500: convert to IIO - misc small fixes all over drivers * tag 'for-v5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (29 commits) power: supply: bd70528: Add MODULE_ALIAS to allow module auto loading power: supply: ab8500_charger: Fix inconsistent IS_ERR and PTR_ERR power: supply: cpcap-charger: cpcap_charger_voltage_to_regval() can be static power: supply: cpcap-battery: Add basic coulomb counter calibrate support power: supply: cpcap-battery: Read and save integrator register CCI power: supply: cpcap-battery: Simplify short term power average calculation power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64 power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata power: supply: cpcap-charger: Allow changing constant charge voltage power: supply: cpcap-battery: Fix handling of lowered charger voltage power: supply: cpcap-charger: Improve battery detection power: supply: cpcap-battery: Check voltage before orderly_poweroff power: supply: cpcap-charger: Limit voltage to 4.2V for battery power: supply: ab8500: Handle invalid IRQ from platform_get_irq_byname() power: supply: ab8500_fg: Do not free non-requested IRQs in probe's error path power: supply: ab8500: Cleanup probe in reverse order power: reset: at91: fix __le32 cast in reset code power: supply: abx500_chargalg: Fix code indentation mfd: Switch the AB8500 GPADC to IIO iio: adc: New driver for the AB8500 GPADC ...
2019-11-16iio: adc: max9611: Make enum relations more future proofGeert Uytterhoeven
The relations between enum values and array indices values are currently not enforced by the code, which makes them fragile w.r.t. future changes. Fix this by: 1. Using designated array initializers, to make sure array indices and enums values match, 2. Linking max9611_csa_gain enum values to the corresponding max9611_conf_ids enum values, as the latter is cast to the former in max9611_read_csa_voltage(). No change in generated code. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-16iio: adc: ad7091r5: Add scale and external VREF supportPaul Cercueil
The scale can now be obtained with the "in_voltage_scale" file. By default, the scale returned corresponds to the internal VREF of 2.5V. It is possible to use an external VREF (through the REFIN/REFOUT pin of the chip), by passing a regulator to the driver. The scale will then be calculated according to the voltage reported by the regulator. Signed-off-by: Paul Cercueil <paul.cercueil@analog.com> Co-developed-by: Beniamin Bia <beniamin.bia@analog.com> Signed-off-by: Beniamin Bia <beniamin.bia@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-16iio: adc: Add support for AD7091R5 ADCPaul Cercueil
AD7091R5 is 4-Channel, I2C, Ultra Low Power,12-Bit ADC. This driver will also support AD7091R2/4/8 in the future. Datasheet: Link: https://www.analog.com/media/en/technical-documentation/data-sheets/ad7091r-5.pdf Signed-off-by: Paul Cercueil <paul.cercueil@analog.com> Co-developed-by: Beniamin Bia <beniamin.bia@analog.com> Signed-off-by: Beniamin Bia <beniamin.bia@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-13Merge tag 'iio-for-5.5c' of ↵Greg Kroah-Hartman
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: Third set of IIO new device support cleanups and fixes for the 5.5 cycle. New device support * ad5446 - Support the ad5600 DAC (id only needed). * ad7292 ADC DAC etc - New driver plus dt-bindings. * veml6030 ambient light sensor - New driver plus dt-bindings and sysfs docs. Features * mpu6050 - Explicit VDD control. * stm32-adc - Allow limiting of max clock frequency from devicetree to ensure it's suitable for external circuitry. yaml binding conversions * ltc1660 * mcp3911 Fixes * adis16480 - Fix wrong scale factors. - Fix debugfs reg access by providing the callback. * cros_ec_baro - Fixing missing mask entry to make available sample frequencies visible in sysfs. * st_lsm6dsx - Explicitly handle different ODR table sizes. - Handle restrictions between slave ODR and accel ODR when both are enabled. - Allow ODR to be expressed more accurately by using miliHz. * tools - Fix an issue with parallel builds. Cleanups and warning fixes * adis16136, adis16400, adis16460, adis-lib - Change some checks on return values to be for 0 rather than strictly negative. Avoids some fiddly issues with the compiler concluding some variables are initialized due to a mixture of error checks. - Assign values only on success of 'read' operations - avoiding any chance the compiler will falsly suggest they might be used uninitialized. - Whitespace and simlar cleanups. * aspeed adc - devm_platfom_ioremap_resource to reduce boilerplate. * bcm-iproc-adc - Stray semicolon removal. * cc10001 - devm_platfom_ioremap_resource to reduce boilerplate. * dln2-adc - Reorganise the buffered mode setup and tear down. Part of moving towards being able to refactor this area of the IIO core. * hdc100x - Reorganise the buffered mode setup and tear down. * ingenic-adc - devm_platfom_ioremap_resource to reduce boilerplate. * lpc18xx-adc - devm_platfom_ioremap_resource to reduce boilerplate. * lpc18xx-dac - devm_platfom_ioremap_resource to reduce boilerplate. * mt6577 - devm_platfom_ioremap_resource to reduce boilerplate. * npcm - devm_platfom_ioremap_resource to reduce boilerplate. * rcar-gyroadc - devm_platfom_ioremap_resource to reduce boilerplate. * spear-adc - devm_platfom_ioremap_resource to reduce boilerplate. * vf610-adc - devm_platfom_ioremap_resource to reduce boilerplate. * vf610-dac - devm_platfom_ioremap_resource to reduce boilerplate. * tag 'iio-for-5.5c' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (43 commits) iio: adis16480: Add debugfs_reg_access entry iio: adis16480: Fix scales factors tools: iio: Correctly add make dependency for iio_utils iio: adc: Add driver support for AD7292 dt-bindings: iio: adc: Add dt-schema for AD7292 dt-bindings: iio: adc: Migrate MCP3911 documentation to yaml iio: imu: mpu6050: Add support for vdd-supply regulator dt-bindings: iio: imu: mpu6050: add vdd-supply iio: cros_ec_baro: set info_mask_shared_by_all_available field iio: dac: ad5446: Add support for new AD5600 DAC dt-bindings: iio: dac: Migrate LTC1660 documentation to yaml iio: documentation: light: Add veml6030 sysfs documentation dt-bindings: iio: light: add veml6030 ALS bindings iio: light: add driver for veml6030 ambient light sensor iio: imu: st_lsm6dsx: express odr in mHZ iio: imu: st_lsm6dsx: fix ODR check in st_lsm6dsx_write_raw iio: imu: st_lsm6dsx: explicitly define odr table size iio: adc: stm32: allow to tune analog clock dt-bindings: iio: stm32-adc: add max clock rate property iio: dac: vf610: Use devm_platform_ioremap_resource ...
2019-11-11Merge 5.4-rc7 into char-misc-nextGreg Kroah-Hartman
We need the char/misc driver fixes in here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-11-11Merge 5.4-rc7 into staging-nextGreg Kroah-Hartman
We want the staging fixes in here, and it resolves some merge issues. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-11-10iio: adc: Add driver support for AD7292Marcelo Schmitt
The AD7292 is a 10-bit monitor and control system with ADC, DACs, temperature sensor, and GPIOs. Configure AD7292 devices in direct access mode, enabling single-ended ADC readings. Datasheet: Link: https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf Signed-off-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-09iio: adc: stm32: allow to tune analog clockFabrice Gasnier
Add new optional dt property to tune analog clock prescaler. Driver looks for optional "st,max-clk-rate-hz", then computes best approximation below that rate, using ADC internal prescaler. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2019-11-09iio: adc: vf610: use devm_platform_ioremap_resourceJonathan Cameron
Reduces boilerplate. Suggested by coccinelle CHECK drivers/iio/adc/vf610_adc.c drivers/iio/adc/vf610_adc.c:819:1-11: WARNING: Use devm_platform_ioremap_resource for info -> regs Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Cc: Fugang Duan <b38611@freescale.com>
2019-11-09iio: adc: spear_adc: Use devm_platform_ioremap_resourceJonathan Cameron
Avoids local boilerplate doing the same thing. Suggested by coccinelle CHECK drivers/iio/adc/spear_adc.c drivers/iio/adc/spear_adc.c:283:1-22: WARNING: Use devm_platform_ioremap_resource for st -> adc_base_spear6xx Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
2019-11-09iio: adc: rcar-gyroadc: use devm_platform_ioremap_resourceJonathan Cameron
Avoids some local boilerplate. Suggested by coccinelle. CHECK drivers/iio/adc/rcar-gyroadc.c drivers/iio/adc/rcar-gyroadc.c:495:1-11: WARNING: Use devm_platform_ioremap_resource for priv -> regs Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Cc: Marek Vasut <marek.vasut+renesas@gmail.com>
2019-11-09iio: adc: npcm: use devm_platform_ioremap_resourceJonathan Cameron
Reduces local boilerplate code. Suggested by coccinelle via coccicheck. CHECK drivers/iio/adc/npcm_adc.c drivers/iio/adc/npcm_adc.c:200:1-11: WARNING: Use devm_platform_ioremap_resource for info -> regs Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Cc: Tomer Maimon <tmaimon77@gmail.com>
2019-11-09iio: adc: lpc18xx: use devm_platform_ioremap_resourceJonathan Cameron
Avoid local boilerplate. Identified by coccinelle CHECK drivers/iio/adc/lpc18xx_adc.c drivers/iio/adc/lpc18xx_adc.c:137:1-10: WARNING: Use devm_platform_ioremap_resource for adc -> base Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Cc: Joachim Eastwood <manabian@gmail.com>
2019-11-09iio: adc: ingenic: Use devm_platform_ioremap_resourceJonathan Cameron
Replaces local boilerplate. Identified by coccinelle. CHECK drivers/iio/adc/ingenic-adc.c drivers/iio/adc/ingenic-adc.c:449:1-10: WARNING: Use devm_platform_ioremap_resource for adc -> base Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Cc: Artur Rojek <contact@artur-rojek.eu>