summaryrefslogtreecommitdiff
path: root/drivers/iio/adc/ti-ads1015.c
AgeCommit message (Collapse)Author
2019-06-05treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 330Thomas Gleixner
Based on 1 normalized pattern(s): this file is subject to the terms and conditions of version 2 of the gnu general public license see the file copying in the main directory of this archive for more details extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 55 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190530000436.108941081@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
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-03iio: adc: ti-ads1015: add 10% to conversion wait timeLadislav Michl
As user's guide "ADS1015EVM, ADS1115EVM, ADS1015EVM-PDK, ADS1115EVM-PDK User Guide (Rev. B)" (http://www.ti.com/lit/ug/sbau157b/sbau157b.pdf) states at page 16: "Note that both the ADS1115 and ADS1015 have internal clocks with a ±10% accuracy. If performing FFT tests, frequencies may appear to be incorrect as a result of this tolerance range.", add those 10% to converion wait time. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Reviewed-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-09-03iio: adc: ti-ads1015: write config register only on changeLadislav Michl
There is no point writing ADS1015_CFG_REG when configuration didn't change. Avoid that. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Reviewed-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-09-03iio: adc: ti-ads1015: fix comparator polarity settingAkinobu Mita
The comparator polarity field in config register is not correctly initialized as per the interrupt trigger setting. Because the bitfield definision is wrong and bit shifting is missed. Fixes: d9f39babd8ba ("iio: adc: ti-ads1015: add threshold event support") Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
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-20iio: adc: ti-ads1015: add threshold event supportAkinobu Mita
The ADS1015 device provides programmable comparator that can issue an interrupt on the ALERT pin. This change adds the iio threshold event support for that feature. The ADS1015 device only have a single config register which contains an input multiplexer selection, comparator settings, and etc. So only a single event channel can be enabled at a time. Also enabling both buffer and event are prohibited for simplicity. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: use iio_device_claim_direct_mode()Akinobu Mita
While the iio buffer for the ti-ads1015 driver is enabled, reading the raw ADC channel data is restricted. We usually use the iio_device_claim_direct_mode()/iio_device_release_direct_mode() pair for that. This change consequently reverses the locking order for the driver's private lock and indio_dev->mlock which acquired by iio_device_claim_direct_mode() internally. But it's safe because there is no other dependency between these locks. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: use devm_iio_triggered_buffer_setupAkinobu Mita
Use devm_iio_triggered_buffer_setup to simplify the error path in the probe() and remove() function. This changes the remove order, but the end result of remove function actually does the reverse of probe. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: add helper to set conversion modeAkinobu Mita
This adds a helper function to set conversion mode as there are a fair number of users. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: remove unnecessary config register updateAkinobu Mita
The ti-ads1015 driver has eight iio voltage channels and each iio channel can hold own scale information. The ADS1015 device only have a single config register which contains an input multiplexer selection, PGA and data rate settings. So the driver should load the correct settings when the input multiplexer selection is changed. However, regardless of which channlel is currently selected, changing any iio channel's scale information immediately overwrites the current PGA setting in the config register. It is harmless because the correct PGA settings are reloaded just before getting adc result anyway. But it is unnecessary register update and should be removed. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: add adequate wait time to get correct conversionAkinobu Mita
This driver assumes that the device is operating in the continuous conversion mode which performs the conversion continuously. So this driver inserts a wait time before reading the conversion register if the configuration is changed from a previous request. Currently, the wait time is only the period required for a single conversion that is calculated as the reciprocal of the sampling frequency. However we also need to wait for the the previous conversion to complete. Otherwise we probably get the conversion result for the previous configuration when the sampling frequency is lower. Cc: Daniel Baluta <daniel.baluta@gmail.com> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: don't return invalid value from buffer setup callbacksAkinobu Mita
pm_runtime_get_sync() and pm_runtime_put_autosuspend() return 0 on success, 1 if the device's runtime PM status was already requested status or error code on failure. So a positive return value doesn't indicate an error condition. However, any non-zero return values from buffer preenable and postdisable callbacks are recognized as an error and this driver reuses the return value from pm_runtime_get_sync() and pm_runtime_put_autosuspend() in these callbacks. This change fixes the false error detections. Cc: Daniel Baluta <daniel.baluta@gmail.com> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: avoid getting stale result after runtime resumeAkinobu Mita
This driver assumes that the device is operating in the continuous conversion mode which performs the conversion continuously. So this driver doesn't insert a wait time before reading the conversion register if the configuration is not changed from a previous request. This assumption is broken if the device is runtime suspended and entered a power-down state. The forthcoming request causes reading a stale result from the conversion register as the device is runtime resumed just before. Fix it by adding a flag to detect that condition and insert a necessary wait time. Cc: Daniel Baluta <daniel.baluta@gmail.com> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: enable conversion when CONFIG_PM is not setAkinobu Mita
The ADS1015 device have two operating modes, continuous conversion mode and single-shot mode. This driver assumes that the continuous conversion mode is selected by runtime resume callback when the ADC result is requested. If CONFIG_PM is disabled, the device is always in the default single-shot mode and no one begins a single conversion. So the conversion register doesn't contain valid ADC result. Fix it by changing the continuous mode in probe function. Cc: Daniel Baluta <daniel.baluta@gmail.com> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: fix scale information for ADS1115Akinobu Mita
The ti-ads1015 driver supports ADS1015 and ADS1115 devices. The same scale information is used for both devices in this driver, however they have actually different values and the ADS1115's one is not correct. These devices have the same full-scale input voltage range for each PGA selection. So instead of adding another hardcoded scale information, compute a correct scale on demand from each device's resolution. Cc: Daniel Baluta <daniel.baluta@gmail.com> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-20iio: adc: ti-ads1015: fix incorrect data rate setting updateAkinobu Mita
The ti-ads1015 driver has eight iio voltage channels and each iio channel can hold own sampling frequency information. The ADS1015 device only have a single config register which contains an input multiplexer selection, PGA and data rate settings. So the driver should load the correct settings when the input multiplexer selection is changed. However, regardless of which channlel is currently selected, changing any iio channel's sampling frequency information immediately overwrites the current data rate setting in the config register. It breaks the current data rate setting if the different channel's sampling frequency information is changed because the data rate setting is not reloaded when the input multiplexer is switched. This removes the unexpected config register update and correctly load the data rate setting before getting adc result. Cc: Daniel Baluta <daniel.baluta@gmail.com> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-07-27Merge tag 'iio-for-4.14a' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: First round of IIO new device support, features and cleanups for the 4.14 cycle. 4 completely new drivers in this set and plenty of other stuff. One ABI change due to a silly mistake a long time back. Hopefully no one will notice. It effects the numerical order of consumer device channels which was the reverse of the obvious. It's going the slow way to allow us some margin to spot if we have broken userspace or not (seems unlikely) New Device Support * ccs811 - new driver for the Volatile Organic Compounds (VOC) sensor. * dln2 adc - new driver for the ADC on this flexible usb board. * EP93xx - new driver for this Cirrus logic SoC ADC. * ltc2471 - new ADC driver support the ltc2471 and ltc2473 * st_accel - add trivial table entries to support H3LIS331DL, LIS331DL, LIS3LV02DL. * st_gyro - add L3GD20H support (again) having fixed the various things that were broken in the first try. Includes devicetree binding. * stm32 dac - add support for the DACs in the STM32F4 series Features * Documentation - add missing power attribute documentation to the ABI docs. * at91-sama5d2 - add hardware trigger and buffered capture support with bindings. - suspend and resume functionality. * bmc150 - support for the BOSC0200 ACPI device id seen on some tablets. * hdc100x - devicetree bindings - document supported devices - match table and device ids. * hts221 - support active low interrupts (with bindings) - open drain mode with bindings. * htu21 - OF match table and bindings. * lsm6dsx - open drain mode with bindings * ltc2497 - add support for board file based consumer mapping. * ms5367 - OF match table and bindings. * mt7622 - binding document and OF match table. - suspend and resume support. * rpr0521 - triggered buffer support. * tsys01 - OF match table and bindings. Cleanups and minor fixes * core - fix ordering of IIO channels to entry numbers when using iio_map_array_register rather than reversing them. - use the new %pOF format specifier rather than full name for the device tree nodes. * ad7280a - fix potential issue with macro argument reuse. * ad7766 - drop a pointless NULL value check as it's done in the gpiod code. * adis16400 - unsigned -> unsigned int. * at91 adc - make some init data static to reduce code size. * at91-sama5d2 ADC - make some init data static to reduce code size. * da311 - make some init data static to reduce code size. * hid-sensor-rotation - drop an unnecessary static. * hts221 - refactor the write_with_mask code. - move the BDU configuration to probe time as there is no reason for it to change. - avoid overwriting reserved data during power-down. This is a fix, but the infrastructure need was too invasive to send it to mainline except in a merge window. It's not a regression as it was always wrong. - avoid reconfigure the sampling frequency multiple times by just doing it in the write_raw function directly. - refactor the power_on/off calls into a set_enable. - move the dry-enable logic into trig_set_state as that is the only place it was used. * ina219 - fix polling of ina226 conversion ready flag. * imx7d - add vendor name in kconfig for consistency with similar parts. * mcp3422 - Change initial channel to 0 as it feels more logical. - Check for some errors in probe. * meson-saradc - add a check of of_match_device return value. * mpu3050 - allow open drain for any interrupt type. * rockchip adc - add check on of_match_device return value. * sca3000 - drop a trailing whitespace. * stm32 adc - make array stm32h7_adc_ckmodes_spec static. * stm32 dac - fix an error message. * stm32 timers - fix clock name in docs to match reality after changes. * st_accel - explicit OF table (spi). - add missing entries to OF table (i2c). - rename of_device_id table to drop the part name. - adding missing lis3l02dq entry to bindings. - rename H3LIS331DL_DRIVER_NAME to line up with similar entries in driver. * st_gyro - explicit OF table (spi). * st_magn - explicit OF table (spi). - enable multiread for lis3mdl. * st_pressure - explicit OF table (spi). * st_sensors common. - move st_sensors_of_i2c_probe and rename to make it available for spi drivers. * tsc3472 - don't write an extra byte when writing the ATIME register. - add a link to the datasheet. * tsl2x7x - continued staging cleanups - add of_match_table. - drop redundant power_state sysfs attribute. - drop wrapper tsl2x7x_i2c_read. - clean up i2c calls made in tsl2x7x_als_calibrate. - refactor the read and write _event_value callbacks to handle additional elements. - use usleep_range instead of mdelay. - check return value from tsl2x7x_invoke_change. * zpa2326 - add some newline to the end of logging macros.
2017-07-22iio: Convert to using %pOF instead of full_nameRob Herring
Now that we have a custom printf format specifier, convert users of full_name to use %pOF instead. This is preparation to remove storing of the full path string for each node. Signed-off-by: Rob Herring <robh@kernel.org> Cc: Jonathan Cameron <jic23@kernel.org> Cc: Hartmut Knaack <knaack.h@gmx.de> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Carlo Caione <carlo@caione.org> Cc: Kevin Hilman <khilman@baylibre.com> Cc: linux-iio@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-amlogic@lists.infradead.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-06-11hwmon: (ads1015) move header file out of I2C realmWolfram Sang
include/linux/i2c is not for client devices. Move the header file to a more appropriate location. Signed-off-by: Wolfram Sang <wsa@the-dreams.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-03-19iio: adc: ti-ads1015: Add OF device ID tableJavier Martinez Canillas
The driver doesn't have a struct of_device_id table but supported devices are registered via Device Trees. This is working on the assumption that a I2C device registered via OF will always match a legacy I2C device ID and that the MODALIAS reported will always be of the form i2c:<device>. But this could change in the future so the correct approach is to have an OF device ID table if the devices are registered via OF. Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-22iio: adc: constify iio_info structuresBhumika Goyal
Declare iio_info structures as const as they are only stored in the info field of a iio_dev structure. This field is of type const, so iio_info structures having similar properties can be made const too. File size before: text data bss dec hex filename 6944 792 0 7736 1e38 drivers/iio/adc/ti-ads1015.o File size after: text data bss dec hex filename 7264 472 0 7736 1e38 drivers/iio/adc/ti-ads1015.o Signed-off-by: Bhumika Goyal <bhumirks@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-14Merge tag 'iio-for-4.9b' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: Second set of iio new device support, features and cleanups for the 4.9 cycle. New device support * ad8801 dac - new driver supporting ad8801 and ad8803 DACs. * adc12138 - new driver supporting TI adc12130/adc12132 and adc12138 ADCs. * ltc2485 adc - new driver * mxc6255 - add support for the mxc6225 part name and fixup the ID check so it works. * vz89x VOC sensor - add support for the vz89te part which drops the voc_short channel and adds CRCs compared to other supported parts. New features * core - immutable triggers. These effectively grant exclusive control over a trigger. The typical usecase is a device representing an analog part (perhaps a MUX) that needs to control the sampling of a downstream ADC. - resource managed trigger registration and triggered_buffer_init. - iio_push_event now protected against case of the event interface registration not having yet occured. Only matters if an interrupt can occur during this window - might happen on shared interrupt lines. - helper to let a driver query if the trigger it is using is provided by itself (using the convention of both device and trigger having the same parent). * tools - iio-utils. Used channel modifier scaling in preference to generic scaling when both exist. * at91-adc - Add support for touchscreen switches closure time needed by some newer parts. * stx104 - support the ADC channels on this ADC/DAC board. As these are the primary feature of the board also move the driver to the iio/adc directory. * sx9500 - device tree bindings. Cleanups / Fixes * ad5755 - fix an off-by-one on devnr limit check (introduced earlier this cycle) * ad7266 - drop NULL check on devm_regulator_get_optional as it can't return NULL. * ak8974 - avoid an unused functional warning due to rework in PM core code. - remove .owner field setting as done by i2c_core. * ina2xx - clear out a left over debug field from chip global data. * hid-sensors - avoid an unused functional warning due to rework in PM core code. * maxim-thermocouple - fix non static symbol warnings. * ms5611 - fetch and enable regulators unconditionally when they aren't optional. * sca3000 - whitespace cleanup. * st_sensors - fetch and enable regulators unconditionally rather than having them supported as optional regulators (missunderstanding on my part amongst others a while back) - followup to previous patch fixes error checking on the regulators. - mark symbols static where possible. - use the 'is it my trigger' help function. This prevents the odd case of another device triggering from the st-sensors trigger whilst the st-sensors trigger is itself not using it but rather using say an hrtimer. * ti-ads1015 - add missing of_node_put. * vz89x - rework to all support of new devices. - prevent reading of a corrupted buffer. - fixup a return value of 0/1 in a bool returning function. Address updates - Vlad Dogaru email address change.
2016-08-29iio: adc: ti-ads1015: add missing of_node_put() in ↵Wei Yongjun
ads1015_get_channels_config_of() When terminating for_each_child_of_node() iteration with break or return, of_node_put() should be used to prevent stale device node references from being left behind. This is detected by Coccinelle semantic patch. Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-08-21iio:ti-ads1015: fix a wrong pointer definition.Giorgio Dal Molin
The call to i2c_get_clientdata(client) returns a struct iio_dev*, not the needed struct ads1015_data*. We need here an intermediate step as in the function: void ads1015_get_channels_config(struct i2c_client *client). Signed-off-by: Giorgio Dal Molin <giorgio.nicole@arcor.de> Fixes: ecc24e72f437 ("iio: adc: Add TI ADS1015 ADC driver support") Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-07-03iio: adc: ti-ads1015: add indio_dev->dev.of_node referenceMatt Ranostay
Add the pointer to the device tree node of the ADC so that iio consumers can reference the respective channels. Signed-off-by: Matt Ranostay <mranostay@gmail.com> Acked-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-06-30iio:core: timestamping clock selection supportGregor Boirie
Adds a new per-device sysfs attribute "current_timestamp_clock" to allow userspace to select a particular POSIX clock for buffered samples and events timestamping. Following clocks, as listed in clock_gettime(2), are supported: CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE, CLOCK_BOOTTIME and CLOCK_TAI. Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com> Acked-by: Sanchayan Maity <maitysanchayan@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-05-28iio: adc: ti-ads1015: add datasheet namesMatt Ranostay
Add datasheet names for ADC channels to allow iio consumers access. Signed-off-by: Matt Ranostay <matt.ranostay@intel.com> Acked-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-05-21iio: adc: ti-ads1015: add support for ADS1115 partMatt Ranostay
TI ADS1115 is a 16-bit resolution ADC that is register map compatible with the ADS1015 device. Signed-off-by: Matt Ranostay <matt.ranostay@intel.com> Acked-by: Daniel Baluta <daniel.baluta@intel.com> Acked-by: Crt Mori <cmo@melexis.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-02-13iio: adc: Add TI ADS1015 ADC driver supportDaniel Baluta
The driver has sysfs readings with runtime PM support for power saving. It also offers buffer support that can be used together with IIO software triggers. Datasheet can be found here: http://www.ti.com.cn/cn/lit/ds/symlink/ads1015.pdf Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>