aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/stm32-adc.c
AgeCommit message (Collapse)Author
2018-11-25iio: adc: stm32-adc: add power management supportFabrice Gasnier
Add support for runtime PM & sleep. Move all regulator and clock management to dedicated HW start/stop routines. Then rely on (runtime) PM OPS to call them. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-25iio: adc: stm32-adc: move self-calibration to prepare routineFabrice Gasnier
Move self-calibration routine to prepare routine. - This is precursor patch to ease power management handling. - This also allow to factorize few error cases (error handling). Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-05-07iio: adc: stm32-adc: add support for STM32MP1Fabrice Gasnier
Add support for STM32MP1 ADC. It's quite similar to STM32H7 ADC. Introduce new compatible to handle variants of this hardware such as vregready flag, trigger list, interrupts, clock rate. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-01-28iio: adc: stm32: fix stm32h7_adc_enable error handlingFabrice Gasnier
Error handling in stm32h7_adc_enable routine doesn't unwind enable sequence correctly. ADEN can only be cleared by hardware (e.g. by writing one to ADDIS). It's also better to clear ADRDY just after it's been set by hardware. Fixes: 95e339b6e85d ("iio: adc: stm32: add support for STM32H7") Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-01-08iio: adc: stm32: fix scan of multiple channels with DMAFabrice Gasnier
By default, watermark is set to '1'. Watermark is used to fine tune cyclic dma buffer period. In case watermark is left untouched (e.g. 1) and several channels are being scanned, buffer period is wrongly set (e.g. to 1 sample). As a consequence, data is never pushed to upper layer. Fix buffer period size, by taking scan channels number into account. Fixes: 2763ea0585c9 ("iio: adc: stm32: add optional dma support") Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-01-08iio: stm32: Adopt SPDX identifierBenjamin Gaignard
Add SPDX identifier in stm32's files in IIO directory Signed-off-by: Benjamin Gaignard <benjamin.gaignard@st.com> Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com> Acked-by: Philippe Ombredanne <pombredanne@nexb.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-12-02iio: adc: stm32: add support for differential channelsFabrice Gasnier
STM32H7 ADC channels can be configured either as single ended or differential with 'st,adc-channels' or 'st,adc-diff-channels' (positive and negative input pair: <vinp vinn>, ...). Differential channels have different offset and scale, from spec: raw value = (full_scale / 2) * (1 + (vinp - vinn) / vref). Add offset attribute. Differential channels are selected by DIFSEL register. Negative inputs must be added to pre-selected channels as well (PCSEL). Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-12-02iio: adc: stm32: remove const channel names definitionFabrice Gasnier
Remove const array that defines channels. Build channels definition at probe time, when initializing channels (only for requested ones). This will ease adding differential channels support. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-10-21iio: adc: stm32: add tim15 triggerFabrice Gasnier
Add TIM15_TRGO trigger that is now supported on STM32H7. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-10-09Merge 4.14-rc4 into staging-nextGreg Kroah-Hartman
We want the staging/iio fixes in here as well to handle merge issues. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-25Merge tag 'iio-for-4.15a' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: Round one of new device support, features and cleanup for IIO in the 4.15 cycle. Note there is a misc driver drop in here given we have support in IIO and the feeling is no one will care. A large part of this series is a boiler plate removal series avoiding the need to explicitly provide THIS_MODULE in various locations. It's very dull but touches all drivers. New device support * ad5446 - add ids to support compatible parts DAC081S101, DAC101S101, DAC121S101. - add the dac7512 id and drop the misc driver as feeling is no one is using it (was introduced for a board that is long obsolete) * mt6577 - add bindings for mt2712 which is fully compatible with other supported parts. * st_pressure - add support for LPS33HW and LPS35HW with bindings (ids mostly). New features * ccs811 - Add support for the data ready trigger. * mma8452 - remove artifical restriction on supporting multiple event types at the same time. * tcs3472 - support out of threshold events Core and tree wide cleanup * Use macro magic to remove the need to provide THIS_MODULE as part of struct iio_info or struct iio_trigger_ops. This is similar to work done in a number of other subsystems (e.g. i2c, spi). All drivers are fixed and then the fields in these structures are removed. This will cause build failures for out of tree drivers and any new drivers that cross with this work going into the kernel. Note mostly done with a coccinelle patch, included in the series on the mailing list but not merged as the fields no longer exist in the structures so the any hold outs will cause a build failure. Cleanups * ads1015 - avoid writing config register when it doesn't change. - add 10% to conversion wait time as it seems it is sometimes a little small. * ade7753 - replace use of core mlock with a local lock. This is part of a long term effort to make the use of mlock opaque and single purpose. * ade7759 - expand the use of buf_lock to cover previous mlock cases. This is a slightly nicer solution to the same issue as in ade7753. * cros_ec - drop an unused variable * inv_mpu6050 - add a missing break in a switch for consistency - not actual bug, - make some local arrays static to save on object code size. * max5481 - drop manual setting of the spi module owner as handled by the spi core. * max5487 - drop manual setting of the spi module owner as handled by the spi core. * max9611 - drop explicit setting of the i2c module owner as handled by the i2c core. * mcp320x - speed up reads on single channel devices, - drop unused of_device_id data elements, - document the struct mcp320x, - improve binding docs to reflect restrictions on spi setup and to make it explicit that the reference regulator is needed. * mma8452 - symbolic to octal permissions, - unsigned to unsigned int. * st_lsm6dsx - avoid setting odr values multiple times, - drop config of LIR as it is only ever set to the existing defaults, - drop rounding configuration as it only ever matches the defaults. * ti-ads8688 - drop manual setting of the spi module owner as handled by the spi core. * tsl2x7x - constify the i2c_device_id, - cleanup limit checks to avoid static checker warnings (and generally have nicer code).
2017-09-25Merge tag 'iio-fixes-for-4.14a' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus Jonathan writes: First round of IIO fixes for the 4.14 cycle Note this includes fixes from recent merge window. As such the tree is based on top of a prior staging/staging-next tree. * iio core - return and error for a failed read_reg debugfs call rather than eating the error. * ad7192 - Use the dedicated reset function in the ad_sigma_delta library instead of an spi transfer with the data on the stack which could cause problems with DMA. * ad7793 - Implement a dedicate reset function in the ad_sigma_delta library and use it to correctly reset this part. * bme280 - ctrl_reg write must occur after any register writes for updates to take effect. * mcp320x - negative voltage readout was broken. - Fix an oops on module unload due to spi_set_drvdata not being called in probe. * st_magn - Fix the data ready line configuration for the lis3mdl. It is not configurable so the st_magn core was assuming it didn't exist and so wasn't consuming interrupts resulting in an unhandled interrupt. * stm32-adc - off by one error on max channels checking. * stm32-timer - preset should not be buffered - reorganising register writes avoids this. - fix a corner case in which write preset goes wrong when a timer is used first as a trigger then as a counter with preset. Odd case but you never know. * ti-ads1015 - Fix setting of comparator polarity by fixing bitfield definition. * twl4030 - Error path handling fix to cleanup in event of regulator registration failure. - Disable the vusb3v1 regulator correctly in error handling - Don't paper over a regulator enable failure.
2017-09-24iio: adc: stm32: fix bad error check on max_channelsFabrice Gasnier
Fix a bad error check when counting 'st,adc-channels' array elements. This is seen when all channels are in use simultaneously. Fixes: 64ad7f643 ("iio: adc: stm32: introduce compatible data cfg") Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-09-07Merge tag 'mfd-next-4.14' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd Pull MFD updates from Lee Jones: "New Drivers - RK805 Power Management IC (PMIC) - ROHM BD9571MWV-M MFD Power Management IC (PMIC) - Texas Instruments TPS68470 Power Management IC (PMIC) & LEDs New Device Support: - Add support for HiSilicon Hi6421v530 to hi6421-pmic-core - Add support for X-Powers AXP806 to axp20x - Add support for X-Powers AXP813 to axp20x - Add support for Intel Sunrise Point LPSS to intel-lpss-pci New Functionality: - Amend API to provide register layout; atmel-smc Fix-ups: - DT re-work; omap, nokia - Header file location change {I2C => MFD}; dm355evm_msp, tps65010 - Fix chip ID formatting issue(s); rk808 - Optionally register touchscreen devices; da9052-core - Documentation improvements; twl-core - Constification; rtsx_pcr, ab8500-core, da9055-i2c, da9052-spi - Drop unnecessary static declaration; max8925-i2c - Kconfig changes (missing deps and remove module support) - Slim down oversized licence statement; hi6421-pmic-core - Use managed resources (devm_*); lp87565 - Supply proper error checking/handling; t7l66xb Bug Fixes: - Fix counter duplication issue; da9052-core - Fix potential NULL deference issue; max8998 - Leave SPI-NOR write-protection bit alone; lpc_ich - Ensure device is put into reset during suspend; intel-lpss - Correct register offset variable size; omap-usb-tll" * tag 'mfd-next-4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd: (61 commits) mfd: intel_soc_pmic: Differentiate between Bay and Cherry Trail CRC variants mfd: intel_soc_pmic: Export separate mfd-cell configs for BYT and CHT dt-bindings: mfd: Add bindings for ZII RAVE devices mfd: omap-usb-tll: Fix register offsets mfd: da9052: Constify spi_device_id mfd: intel-lpss: Put I2C and SPI controllers into reset state on suspend mfd: da9055: Constify i2c_device_id mfd: intel-lpss: Add missing PCI ID for Intel Sunrise Point LPSS devices mfd: t7l66xb: Handle return value of clk_prepare_enable mfd: Add ROHM BD9571MWV-M PMIC DT bindings mfd: intel_soc_pmic_chtwc: Turn Kconfig option into a bool mfd: lp87565: Convert to use devm_mfd_add_devices() mfd: Add support for TPS68470 device mfd: lpc_ich: Do not touch SPI-NOR write protection bit on Haswell/Broadwell mfd: syscon: atmel-smc: Add helper to retrieve register layout mfd: axp20x: Use correct platform device ID for many PEK dt-bindings: mfd: axp20x: Introduce bindings for AXP813 mfd: axp20x: Add support for AXP813 PMIC dt-bindings: mfd: axp20x: Add AXP806 to supported list of chips mfd: Add ROHM BD9571MWV-M MFD PMIC driver ...
2017-09-04iio: adc: stm32: add support for lptimer triggersFabrice Gasnier
STM32 ADC supports hardware triggers like STM32 Low-Power Timer. For instance, STM32H7 ADC may be triggered by instances 1, 2 or 3. Add hardware triggered mode so Low-Power Timer Trigger driver can validate device. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
2017-08-22iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.ownerJonathan Cameron
The equivalent of both of these are now done via macro magic when the relevant register calls are made. The actual structure elements will shortly go away. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
2017-08-09iio: adc: stm32: add optional st,min-sample-time-nsecsFabrice Gasnier
STM32 ADC allows each channel to be sampled with a different sampling time, by setting SMPR registers. Basically, value depends on local electrical properties. Selecting correct value for sampling time highly depends on analog source impedance. There is a manual that may help in this process: 'How to get the best ADC accuracy in STM32...' This patch allows to configure minimum sampling time via device tree, either for: - all channels at once: st,min-sample-time-nsecs = <10000>; - independently for each channel (must match "st,adc-channels" list): st,adc-channels = <0 1>; st,min-sample-time-nsecs = <5000 10000>; Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-06-11iio: adc: stm32: add support for STM32H7Fabrice Gasnier
Add support for STM32H7 Analog to Digital Converter. It has up to 20 external channels, resolution ranges from 8 to 16bits. Either bus or asynchronous adc clock may be used. Add registers & bitfields definition. Also add new configuration options to enter/exit powerdown and perform self-calibration. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-06-11iio: adc: stm32: make per instance bus clock optionalFabrice Gasnier
STM32F4 requires one clock per ADC instance for register access. But, newer version of ADC hardware block have common bus clock for all instances (per instance driver isn't responsible for getting it). So, make it optional by default. Still, enforce it's required on STM32F4. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-06-11iio: adc: stm32: introduce compatible data cfgFabrice Gasnier
Prepare support for stm32h7 adc variant by introducing compatible configuration data. Move STM32F4 specific stuff to compatible data structure: - registers & bit fields - input channels data - start/stop procedures - trigger definitions Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-04-03iio: adc: stm32: add dt option to set resolutionFabrice Gasnier
stm32 adc supports several resolution. Add 'assigned-resolution-bits' dt optional property to set it. Default to maximum resolution in case it isn't set. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-29iio: adc: stm32: add optional dma supportFabrice Gasnier
Add DMA optional support to STM32 ADC, as there is a limited number DMA channels (request lines) that can be assigned to ADC. This way, driver may fall back using interrupts when all DMA channels are in use for other IPs. Use dma cyclic mode with two periods. Allow to tune period length by using watermark. Coherent memory is used for dma (max buffer size is fixed to PAGE_SIZE). Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-28iio: adc: stm32: add trigger polarity extended attributeFabrice Gasnier
Define extended attribute so that user may choose rising, falling or both edges for external trigger sources. Default to rising edge in case it isn't set. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-28iio: adc: stm32: Enable use of stm32 timer triggersFabrice Gasnier
STM32 ADC has external timer trigger sources. Use stm32 timer triggers API (e.g. is_stm32_timer_trigger()) with local ADC lookup table to validate a trigger can be used. This also provides correct trigger selection value (e.g. extsel). Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-28iio: adc: stm32: add support for triggered buffer modeFabrice Gasnier
STM32 ADC conversions can be launched using hardware triggers. It can be used to start conversion sequences (group of channels). Selected channels are select via sequence registers. Trigger source is selected via 'extsel' (external trigger mux). Trigger polarity is set to rising edge by default. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-19iio: adc: Add support for STM32 ADCFabrice Gasnier
This patch adds support for STMicroelectronics STM32 MCU's analog to digital converter. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>