summaryrefslogtreecommitdiffstats
path: root/drivers/iio
AgeCommit message (Collapse)Author
2017-03-12iio: pressure: mpl3115: do not rely on structure field orderingPeter Rosin
commit 9cf6cdba586ced75c69b8314b88b2d2f5ce9b3ed upstream. Fixes a regression triggered by a change in the layout of struct iio_chan_spec, but the real bug is in the driver which assumed a specific structure layout in the first place. Hint: the two bits were not OR:ed together as implied by the indentation prior to this patch, there was a comma between them, which accidentally moved the ..._SCALE bit to the next structure field. That field was .info_mask_shared_by_type before the _available attributes was added by commit 51239600074b ("iio:core: add a callback to allow drivers to provide _available attributes") and .info_mask_separate_available afterwards, and the regression happened. info_mask_shared_by_type is actually a better choice than the originally intended info_mask_separate for the ..._SCALE bit since a constant is returned from mpl3115_read_raw for the scale. Using info_mask_shared_by_type also preserves the behavior from before the regression and is therefore less likely to cause other interesting side effects. The above mentioned regression causes an unintended sysfs attibute to show up that is not backed by code, in turn causing the following NULL pointer defererence to happen on access. Segmentation fault Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = ecc3c000 [00000000] *pgd=87f91831 Internal error: Oops: 80000007 [#1] SMP ARM Modules linked in: CPU: 1 PID: 1051 Comm: cat Not tainted 4.10.0-rc5-00009-gffd8858-dirty #3 Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree) task: ed54ec00 task.stack: ee2bc000 PC is at 0x0 LR is at iio_read_channel_info_avail+0x40/0x280 pc : [<00000000>] lr : [<c06fbc1c>] psr: a0070013 sp : ee2bdda8 ip : 00000000 fp : ee2bddf4 r10: c0a53c74 r9 : ed79f000 r8 : ee8d1018 r7 : 00001000 r6 : 00000fff r5 : ee8b9a00 r4 : ed79f000 r3 : ee2bddc4 r2 : ee2bddbc r1 : c0a86dcc r0 : ee8d1000 Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none Control: 10c5387d Table: 3cc3c04a DAC: 00000051 Process cat (pid: 1051, stack limit = 0xee2bc210) Stack: (0xee2bdda8 to 0xee2be000) dda0: ee2bddc0 00000002 c016d720 c016d394 ed54ec00 00000000 ddc0: 60070013 ed413780 00000001 edffd480 ee8b9a00 00000fff 00001000 ee8d1018 dde0: ed79f000 c0a53c74 ee2bde0c ee2bddf8 c0513c58 c06fbbe8 edffd480 edffd540 de00: ee2bde3c ee2bde10 c0293474 c0513c40 c02933e4 ee2bde60 00000001 ed413780 de20: 00000001 ed413780 00000000 edffd480 ee2bde4c ee2bde40 c0291d00 c02933f0 de40: ee2bde9c ee2bde50 c024679c c0291ce0 edffd4b0 b6e37000 00020000 ee2bdf78 de60: 00000000 00000000 ed54ec00 ed013200 00000817 c0a111fc edffd540 ed413780 de80: b6e37000 00020000 00020000 ee2bdf78 ee2bded4 ee2bdea0 c0292890 c0246604 dea0: c0117940 c016ba50 00000025 c0a111fc b6e37000 ed413780 ee2bdf78 00020000 dec0: ee2bc000 b6e37000 ee2bdf44 ee2bded8 c021d158 c0292770 c0117764 b6e36004 dee0: c0f0d7c4 ee2bdfb0 b6f89228 00021008 ee2bdfac ee2bdf00 c0101374 c0117770 df00: 00000000 00000000 ee2bc000 00000000 ee2bdf34 ee2bdf20 c016ba04 c0171080 df20: 00000000 00020000 ed413780 b6e37000 00000000 ee2bdf78 ee2bdf74 ee2bdf48 df40: c021e7a0 c021d130 c023e300 c023e280 ee2bdf74 00000000 00000000 ed413780 df60: ed413780 00020000 ee2bdfa4 ee2bdf78 c021e870 c021e71c 00000000 00000000 df80: 00020000 00020000 b6e37000 00000003 c0108084 00000000 00000000 ee2bdfa8 dfa0: c0107ee0 c021e838 00020000 00020000 00000003 b6e37000 00020000 0001a2b4 dfc0: 00020000 00020000 b6e37000 00000003 7fffe000 00000000 00000000 00020000 dfe0: 00000000 be98eb4c 0000c740 b6f1985c 60070010 00000003 00000000 00000000 Backtrace: [<c06fbbdc>] (iio_read_channel_info_avail) from [<c0513c58>] (dev_attr_show+0x24/0x50) r10:c0a53c74 r9:ed79f000 r8:ee8d1018 r7:00001000 r6:00000fff r5:ee8b9a00 r4:edffd480 [<c0513c34>] (dev_attr_show) from [<c0293474>] (sysfs_kf_seq_show+0x90/0x110) r5:edffd540 r4:edffd480 [<c02933e4>] (sysfs_kf_seq_show) from [<c0291d00>] (kernfs_seq_show+0x2c/0x30) r10:edffd480 r9:00000000 r8:ed413780 r7:00000001 r6:ed413780 r5:00000001 r4:ee2bde60 r3:c02933e4 [<c0291cd4>] (kernfs_seq_show) from [<c024679c>] (seq_read+0x1a4/0x4e0) [<c02465f8>] (seq_read) from [<c0292890>] (kernfs_fop_read+0x12c/0x1cc) r10:ee2bdf78 r9:00020000 r8:00020000 r7:b6e37000 r6:ed413780 r5:edffd540 r4:c0a111fc [<c0292764>] (kernfs_fop_read) from [<c021d158>] (__vfs_read+0x34/0x118) r10:b6e37000 r9:ee2bc000 r8:00020000 r7:ee2bdf78 r6:ed413780 r5:b6e37000 r4:c0a111fc [<c021d124>] (__vfs_read) from [<c021e7a0>] (vfs_read+0x90/0x11c) r8:ee2bdf78 r7:00000000 r6:b6e37000 r5:ed413780 r4:00020000 [<c021e710>] (vfs_read) from [<c021e870>] (SyS_read+0x44/0x90) r8:00020000 r7:ed413780 r6:ed413780 r5:00000000 r4:00000000 [<c021e82c>] (SyS_read) from [<c0107ee0>] (ret_fast_syscall+0x0/0x1c) r10:00000000 r8:c0108084 r7:00000003 r6:b6e37000 r5:00020000 r4:00020000 Code: bad PC value ---[ end trace 9c4938ccd0389004 ]--- Fixes: cc26ad455f57 ("iio: Add Freescale MPL3115A2 pressure / temperature sensor driver") Fixes: 51239600074b ("iio:core: add a callback to allow drivers to provide _available attributes") Reported-by: Ken Lin <ken.lin@advantech.com> Tested-by: Ken Lin <ken.lin@advantech.com> Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-03-12iio: pressure: mpl115: do not rely on structure field orderingPeter Rosin
commit 6a6e1d56a0769795a36c0461c64bf5e5b9bbb4c0 upstream. Fixes a regression triggered by a change in the layout of struct iio_chan_spec, but the real bug is in the driver which assumed a specific structure layout in the first place. Hint: the three bits were not OR:ed together as implied by the indentation prior to this patch, there was a comma between the first two, which accidentally moved the ..._SCALE and ..._OFFSET bits to the next structure field. That field was .info_mask_shared_by_type before the _available attributes was added by commit 51239600074b ("iio:core: add a callback to allow drivers to provide _available attributes") and .info_mask_separate_available afterwards, and the regression happened. info_mask_shared_by_type is actually a better choice than the originally intended info_mask_separate for the ..._SCALE and ..._OFFSET bits since a constant is returned from mpl115_read_raw for the scale/offset. Using info_mask_shared_by_type also preserves the behavior from before the regression and is therefore less likely to cause other interesting side effects. The above mentioned regression causes unintended sysfs attibutes to show up that are not backed by code, in turn causing a NULL pointer defererence to happen on access. Fixes: 3017d90e8931 ("iio: Add Freescale MPL115A2 pressure / temperature sensor driver") Fixes: 51239600074b ("iio:core: add a callback to allow drivers to provide _available attributes") Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-01-22iio: dht11: Use usleep_range instead of msleep for start signalJohn Brooks
The DHT22 (AM2302) datasheet specifies that the LOW start pulse should not exceed 20ms. However, observations with an oscilloscope of an RPi Model 2B (rev 1.1) communicating with a DHT22 sensor showed that the driver was consistently sending start pulses longer than 20ms: Kernel 4.7.10-v7+ (n=132): Minimum pulse length: 20.20ms Maximum: 29.84ms Mean: 24.96ms StDev: 2.82ms Sensor response rate: 100% Read success rate: 76% On kernel 4.8, the start pulse was so long that the sensor would not even respond 97% of the time: Kernel 4.8.16-v7+ (n=100): Minimum pulse length: 30.4ms Maximum: 74.4ms Mean: 39.3ms StDev: 10.2ms Sensor response rate: 3% Read success rate: 3% The driver would return ETIMEDOUT and write log messages like this: [ 51.430987] dht11 dht11@0: Only 1 signal edges detected [ 66.311019] dht11 dht11@0: Only 0 signal edges detected Replacing msleep(18) with usleep_range(18000, 20000) made the pulse length sane again and restored responsiveness: Kernel 4.8.16-v7+ with usleep_range (n=123): Minimum pulse length: 18.16ms Maximum: 20.20ms Mean: 19.85ms StDev: 0.51ms Sensor response rate: 100% Read success rate: 84% Cc: stable@vger.kernel.org Signed-off-by: John Brooks <john@fastquake.com> Reviewed-by: Harald Geyer <harald@ccbib.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-21iio: adc: palmas_gpadc: retrieve a valid iio_dev in suspend/resumeAlison Schofield
The suspend/resume functions were using dev_to_iio_dev() to get the iio_dev. That only works on IIO dev's. Use dev_get_drvdata() for a platform device to get the correct iio_dev. Signed-off-by: Alison Schofield <amsfield22@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-21iio: health: max30100: fixed parenthesis around FIFO count checkMatt Ranostay
FIFO was being read every sample after the "almost full" state was reached. This was due to an incorrect placement of the parenthesis in the while condition check. Note - the fixes tag is not actually correct, but the fix in this patch would also be needed for it to function correctly so we'll go with that one. Backports should pick up both. Signed-off-by: Matt Ranostay <matt@ranostay.consulting> Fixes: b74fccad7 ("iio: health: max30100: correct FIFO check condition") Cc: Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-21iio: health: afe4404: retrieve a valid iio_dev in suspend/resumeAlison Schofield
The suspend/resume functions were using dev_to_iio_dev() to get the iio_dev. That only works on IIO dev's. Replace it with i2c functions to get the correct iio_dev. Signed-off-by: Alison Schofield <amsfield22@gmail.com> Acked-by: Andrew F. Davis <afd@ti.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-21iio: health: afe4403: retrieve a valid iio_dev in suspend/resumeAlison Schofield
The suspend/resume functions were using dev_to_iio_dev() to get the iio_dev. That only works on IIO dev's. Replace it with spi functions to get the correct iio_dev. Signed-off-by: Alison Schofield <amsfield22@gmail.com> Acked-by: Andrew F. Davis <afd@ti.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-02Merge tag 'iio-fixes-for-4.10a' 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.10 cycle. * 104-quad-8 - Fix selecting wrong register when the index control register is desired. - Fix an off by one error when addressing the input/output control register. - Fix inverted logic on the active high / low control * bmi160 - Sleep for worst case rather than best case amount of time after cmd execution begins. * max44000 - typo fix in illuminance_integration_time_available listing. * st-sensors - Fix channel data passing. This one took a while to get tested on 24bit parts. Definitely one for stable asap as the bug broke quite a few parts. - lis3lv02 needs a data alignment bit set and the scaling was wrong. * ti_am335x - depend on HAS_DMA
2016-12-31iio: accel: st_accel: fix LIS3LV02 reading and scalingLinus Walleij
The LIS3LV02 has a special bit that need to be set to get the read values left aligned. Before this patch we get gibberish like this: iio_generic_buffer -a -c10 -n lis3lv02dl_accel (...) 0.000000 -0.010042 -0.642688 19155832931907 0.000000 -0.010042 -0.642688 19155858751073 Which is because we read a raw value for 1g as 64 which is the nominal 1024 for 1g shifted 4 bits to the left by being right-aligned rather than left aligned. Since all other sensors are left aligned, add some code to set the special DAS (data alignment setting) bit to 1 so that the right value is now read like this: iio_generic_buffer -a -c10 -n lis3lv02dl_accel (...) 0.000000 -0.147095 -10.120135 24761614364956 -0.029419 -0.176514 -10.120135 24761631624540 The scaling was weird as well: we have a gain of 1000 for 1g and 3000 for 6g. I don't even remember how I came up with the old values but they are wrong. Fixes: 3acddf74f807 ("iio: st-sensors: add support for lis3lv02d accelerometer") Cc: Lorenzo Bianconi <lorenzo.bianconi@st.com> 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-12-31iio: common: st_sensors: fix channel data parsingLorenzo Bianconi
Using realbits as i2c/spi read len, when that value is not byte aligned (e.g 12 bits), lead to skip msb part of out data registers. Fix this taking into account scan_type.shift in addition to scan_type.realbits as read length: read_len = DIV_ROUND_UP(realbits + shift, 8) This fix has been tested on 8, 12, 16, 24 bit sensors Fixes: e7385de5291e ("iio:st_sensors: align on storagebits boundaries") Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> Tested-by: Linus Walleij <linus.walleij@linaro.org> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-12-30iio: max44000: correct value in illuminance_integration_time_availableAkinobu Mita
According to the datasheet, the shortest available integration time for ALS ADC conversion is 1.5625ms but illuminance_integration_time_available sysfs file shows wrong value. Cc: Crestez Dan Leonard <leonard.crestez@intel.com> 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> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Fixes: d5d8f49b6 ("max44000: Expose ambient sensor scaling") Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-12-30iio: adc: TI_AM335X_ADC should depend on HAS_DMAGeert Uytterhoeven
If NO_DMA=y: ERROR: "bad_dma_ops" [drivers/iio/adc/ti_am335x_adc.ko] undefined! Add a dependency on HAS_DMA to fix this. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Fixes: f438b9da (" drivers: iio: ti_am335x_adc: add dma support") Cc: <stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-12-30iio: bmi160: Fix time needed to sleep after command executionMarcin Niestroj
Datasheet specifies typical and maximum execution times for which CMD register is occupied after previous command execution. We took these values as minimum and maximum time for usleep_range() call before making a new command execution. To be sure, that the CMD register is no longer occupied we need to wait *at least* the maximum time specified by datasheet. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-12-25ktime: Cleanup ktime_set() usageThomas Gleixner
ktime_set(S,N) was required for the timespec storage type and is still useful for situations where a Seconds and Nanoseconds part of a time value needs to be converted. For anything where the Seconds argument is 0, this is pointless and can be replaced with a simple assignment. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org>
2016-12-03iio: 104-quad-8: Fix active level mismatch for the preset enable optionWilliam Breathitt Gray
The set_to_preset_on_index sysfs attribute provides a boolean configuration option to enable a preset operation on the respective channel's counter when Index occurs. However, the corresponding configuration bit on the Input/Output Control register must be set low to enable the preset operation. This patch inverts the internal driver boolean logic exposed via the set_to_preset_on_index attribute in order to correctly configure the device which expects an active low bit. Fixes: 28e5d3bb0325 ("iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8") Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-12-03iio: 104-quad-8: Fix off-by-one errors when addressing IORWilliam Breathitt Gray
The Input/Output Control register (IOR) is offset by 1 from the respective channel data register. This patch fixes off-by-one errors when attempting to write to a channel IOR where the base address was not properly offset. Fixes: 28e5d3bb0325 ("iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8") Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-12-03iio: 104-quad-8: Fix index control configurationWilliam Breathitt Gray
The LS7266R1 requires bits 5 & 6 to be high in order to select the Index Control Register. This patch fixes a typo that incorrectly selects the Input/Output Control Register where the Index Control Register was desired. Fixes: 28e5d3bb0325 ("iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8") Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-24iio: magnetometer: separate the values of attributes based on their usage ↵Ooi, Joyce
type for HID compass sensor There are 2 usage types (Magnetic Flux and Heading data field) for HID compass sensor, thus the values of offset, scale, and sensitivity should be separated according to their respective usage type. The changes made are as below: 1. Hysteresis: A struct hid_sensor_common rot_attributes is created in struct magn_3d_state to contain the sensitivity for IIO_ROT. 2. Scale: scale_pre_decml and scale_post_decml are separated for IIO_MAGN and IIO_ROT. 3. Offset: Same as scale, value_offset is separated for IIO_MAGN and IIO_ROT. For sensitivity, HID_USAGE_SENSOR_ORIENT_MAGN_FLUX and HID_USAGE_SENSOR_ORIENT_MAGN_HEADING are used for sensivitity fields based on the HID Sensor Usages specifications. Hence, these changes are added on the sensitivity field. Signed-off-by: Ooi, Joyce <joyce.ooi@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-24iio: tsl2583: make array large enoughDan Carpenter
This array is supposed to have 10 elements. Smatch complains that with the current code we can have n == max_ints and read beyond the end of the array. Fixes: ac4f6eee8fe8 ("staging: iio: TAOS tsl258x: Device driver") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-19iio: accel: st_accel: inline per-sensor dataLinus Walleij
We have #defines for all the individual sensor registers and value/mask pairs #defined at the top of the file and used at exactly one spot. This is usually good if the #defines give a meaning to the opaque magic numbers. However in this case, the semantic meaning is inherent in the name of the C99-addressable fields, and that means duplication of information, and only makes the code hard to maintain since you every time have to add a new #define AND update the site where it is to be used. Get rid of the #defines and just open code the values into the appropriate struct elements. Make sure to explicitly address the .hz and .value fields in the st_sensor_odr_avl struct so that the meaning of all values is clear. This patch is purely syntactic should have no semantic effect. Cc: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Lorenzo Bianconi <lorenzo.bianconi@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>
2016-11-19iio: adc: Add support for STM32 ADC coreFabrice Gasnier
Add core driver for STMicroelectronics STM32 ADC (Analog to Digital Converter). STM32 ADC can be composed of up to 3 ADCs with shared resources like clock prescaler, common interrupt line and analog reference voltage. This core driver basically manages shared resources. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-16Merge tag 'iio-for-4.10c' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: Third set of IIO new device support, features and cleanup for the 4.10 cycle. Includes Peter Rosin's interesting drivers for a comparator. First complex use we have had with an analog front end made from discrete components. Brian Masney's work on moving the tsl2583 driver out of staging also feature extensively! New Drivers * DAC based on a digital potentiometer - New driver for the use of a dpot as a DAC. Includes bindings and Axentia entry in vendor prefixes. * Envelope detector baed on DAC and a comparator including device tree bindings. Staging Graduation * tsl2583. Core new features - Core provision for _available attributes. This one had been stalled for a long time until Peter picked it up and ran with it! - In kernel interface helpers to retrieve available info from channels. Driver new features * mcp4531 - Add range of available raw values (used for the dpot dac driver). Driver cleanups and fixes for issues introduced * ad7766 - Testing the wrong variable following devm_regulator_bulk_get introduced with the driver earlier in this cycle. * ad9832 - Fix a wrong ordering in the probe introduced in the previous set of patches. A use before allocation bug. * cros_ec_sensors - Testing for an error in a u8 will never work. * mpu3050 - Remove duplicate initializer for the module owner. - Add missing i2c dependency. - Inform the i2c mux core how it is used - step one in implifying device tree bindings. * st-sensors - Get rid of large number of uninformative defines in favour of putting the constants where they are relevant. It is clear what they are from where they are used. * tsl2583 - Fix unused function warning when CONFIG_PM disabled and remove the ifdefs in favour of __maybe_unused. - Refactor taos_chip_on to only read relevant registers. - Make sure calibscale and integration time are being set. - Verify chip is in ready to be used before calibration. - Remove some repeated checks for chip status (it's protected by a mutex so can't change until it's released) - Change current state storage from a tristate enum to a boolean seeing as only two values are actually used now. - Drop a redundant write to the control regiser in taos_probe (it's a noop) - Drop the FSF mailing address. - Clean up logging to not use hard coded function names (use __func__ instead). - Cleanup up variable and function name prefixes. - Alignment of #define fixes. - Fix comparison between signed and unsigned integer warnings. - Add some newlines in favour of readability. - Combine the two sysfs ABI docs that somehow ended up in different places. - Fix multiline comment syntax. - Move a code block to inside an else statement as it makes more sense there. - Change tsl2583_als_calibrate to return 0 rather than a value nothing reads. - Drop some pointless brackets - Don't assume 32bit unsigned int. - Change to a per device instance lux table. - Add missing tsl2583 to the list of supported devices in the intro comments. - Improve commment on clearing of interrupts. - Drop some uninformative comments. - Drop a memset call that doesn't do anything useful any more. - Don't initialize some return variables that are always set. - Add Brian Masney as a module author after all these changes.
2016-11-14Merge 4.9-rc5 into staging-nextGreg Kroah-Hartman
We want the staging/iio fixes in here as well to resolve issues and merge problems. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-11-13staging: iio: tsl2583: move out of stagingBrian Masney
Move tsl2580, tsl2581, tsl2583 driver out of staging into mainline. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13iio: envelope-detector: ADC driver based on a DAC and a comparatorPeter Rosin
The DAC is used to find the peak level of an alternating voltage input signal by a binary search using the output of a comparator wired to an interrupt pin. Like so: _ | \ input +------>-------|+ \ | \ .-------. | }---. | | | / | | dac|-->--|- / | | | |_/ | | | | | | | | irq|------<-------' | | '-------' Signed-off-by: Peter Rosin <peda@axentia.se> Acked-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13iio: dpot-dac: DAC driver based on a digital potentiometerPeter Rosin
It is assumed that the dpot is used as a voltage divider between the current dpot wiper setting and the maximum resistance of the dpot. The divided voltage is provided by a vref regulator. .------. .-----------. | | | vref |--' .---. | regulator |--. | | '-----------' | | d | | | p | | | o | wiper | | t |<---------+ | | | | '---' dac output voltage | | '------+------------+ Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13iio: mcp4531: provide range of available raw valuesPeter Rosin
Example: $ cat '/sys/bus/iio/devices/iio:device0/out_resistance_raw_available' [0 1 256] Meaning: min 0, step 1 and max 256. Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13iio: inkern: add helpers to query available values from channelsPeter Rosin
Specifically a helper for reading the available maximum raw value of a channel and a helper for forwarding read_avail requests for raw values from one iio driver to an iio channel that is consumed. These rather specific helpers are in turn built with generic helpers making it easy to build more helpers for available values as needed. Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13iio:core: add a callback to allow drivers to provide _available attributesJonathan Cameron
A large number of attributes can only take a limited range of values. Currently in IIO this is handled by directly registering additional *_available attributes thus providing this information to userspace. It is desirable to provide this information via the core for much the same reason this was done for the actual channel information attributes in the first place. If it isn't there, then it can only really be accessed from userspace. Other in kernel IIO consumers have no access to what valid parameters are. Two forms are currently supported: * list of values in one particular IIO_VAL_* format. e.g. 1.300000 1.500000 1.730000 * range specification with a step size: e.g. [1.000000 0.500000 2.500000] equivalent to 1.000000 1.5000000 2.000000 2.500000 An addition set of masks are used to allow different sharing rules for the *_available attributes generated. This allows for example: in_accel_x_offset in_accel_y_offset in_accel_offset_available. We could have gone with having a specification for each and every info_mask element but that would have meant changing the existing userspace ABI. This approach does not. Signed-off-by: Jonathan Cameron <jic23@kernel.org> [forward ported, added some docs and fixed buffer overflows /peda] Acked-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13iio: maxim_thermocouple: detect invalid storage size in read()Arnd Bergmann
As found by gcc -Wmaybe-uninitialized, having a storage_bytes value other than 2 or 4 will result in undefined behavior: drivers/iio/temperature/maxim_thermocouple.c: In function 'maxim_thermocouple_read': drivers/iio/temperature/maxim_thermocouple.c:141:5: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized] This probably cannot happen, but returning -EINVAL here is appropriate and makes gcc happy and the code more robust. Fixes: 231147ee77f3 ("iio: maxim_thermocouple: Align 16 bit big endian value of raw reads") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org> (cherry picked from commit 32cb7d27e65df9daa7cee8f1fdf7b259f214bee2) Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-11-12iio: pressure: st_pressure: inline per-sensor dataLinus Walleij
We have #defines for all the individual sensor registers and value/mask pairs #defined at the top of the file and used at exactly one spot. This is usually good if the #defines give a meaning to the opaque magic numbers. However in this case, the semantic meaning is inherent in the name of the C99-addressable fields, and that means duplication of information, and only makes the code hard to maintain since you every time have to add a new #define AND update the site where it is to be used. Get rid of the #defines and just open code the values into the appropriate struct elements. Make sure to explicitly address the .hz and .value fields in the st_sensor_odr_avl struct so that the meaning of all values is clear. This patch is purely syntactic should have no semantic effect. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-12iio: magn: st_magn: inline per-sensor dataLinus Walleij
We have #defines for all the individual sensor registers and value/mask pairs #defined at the top of the file and used at exactly one spot. This is usually good if the #defines give a meaning to the opaque magic numbers. However in this case, the semantic meaning is inherent in the name of the C99-addressable fields, and that means duplication of information, and only makes the code hard to maintain since you every time have to add a new #define AND update the site where it is to be used. Get rid of the #defines and just open code the values into the appropriate struct elements. Make sure to explicitly address the .hz and .value fields in the st_sensor_odr_avl struct so that the meaning of all values is clear. This patch is purely syntactic should have no semantic effect. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-12iio: gyro: st_gyro: inline per-sensor dataLinus Walleij
We have #defines for all the individual sensor registers and value/mask pairs #defined at the top of the file and used at exactly one spot. This is usually good if the #defines give a meaning to the opaque magic numbers. However in this case, the semantic meaning is inherent in the name of the C99-addressable fields, and that means duplication of information, and only makes the code hard to maintain since you every time have to add a new #define AND update the site where it is to be used. Get rid of the #defines and just open code the values into the appropriate struct elements. Make sure to explicitly address the .hz and .value fields in the st_sensor_odr_avl struct so that the meaning of all values is clear. This patch is purely syntactic should have no semantic effect. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-12iio: imu: inv_mpu6050: inform the i2c mux core about how it is usedPeter Rosin
The i2c mux core can then take appropriate action depending on if it is used for an actual i2c mux, or for an arbitrator or gate. In this case it is used as a gate. This will make devicetree bindings simpler when they are eventually added. Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-12iio: cros_ec_sensors_core: fix unsigned compared less than zero on statusColin Ian King
status is a u8 hence the check if status is less than zero has no effect. Fix this by replacing status with int ret so the less than zero compare will correctly detect errors. Issue found with static analysis with CoverityScan, CID 1375919 Signed-off-by: Colin Ian King <colin.king@canonical.com> Fixes: 974e6f02e27e ("iio: cros_ec_sensors_core: Add common functions for the ChromeOS EC Sensor Hub") Reviewed-by: Guenter Roeck <groeck@chromium.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-12iio:adc: ad7766: testing the wrong variable in probeDan Carpenter
We should be testing "ret" here. Fixes: aa16c6bd0e09 ("iio:adc: Add support for AD7766/AD7767") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-08iio: gyro: mpu3050: add I2C dependencyArnd Bergmann
The new mpu3050 driver fails to build if I2C is disabled: drivers/iio/built-in.o: In function `mpu3050_i2c_driver_exit': mpu3050-i2c.c:(.exit.text+0x17f): undefined reference to `i2c_del_driver' drivers/iio/built-in.o: In function `mpu3050_i2c_driver_init': mpu3050-i2c.c:(.init.text+0x215): undefined reference to `i2c_register_driver' This adds a Kconfig dependency to ensure we only build it when I2C is available. Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-08iio: gyro: mpu3050: remove duplicate initializerArnd Bergmann
The newly added mpu3050 driver has two initializations for the module owner, which causes a warning for 'make W=1': include/linux/export.h:37:21: error: initialized field overwritten [-Werror=override-init] drivers/iio/gyro/mpu3050-core.c:749:19: note: in expansion of macro 'THIS_MODULE' This removes one of the two. Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-07Merge tag 'iio-for-4.10b' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-testing Jonathan writes: Second round of new device support, cleanups and fixes for IIO in the 4.10 cycle This includes two branch merges for elements that may also go via MFD. New device support * cros_ec - new driver to support these Chrome OS contiguous sensors which are behind the Chrome OS embedded controller. Requires a few minor MFD and chrome platform changes. One follow up fix deals with some dependency issues in Kconfig. * mpu-3050 - new driver and device tree bindings for this venerable device. * st_accel - support for the lng2dm an Driver features * ad7192 - Add DVdd regulator handling * ad9832 - Add DVDD regulator handling * at91 - Suspend and resume support * si7020 - Device tree bindings * ti-am335x - DMA support - uses dma to accelerate short bursts of read back rather than full blown DMA buffer support. Greatly improved performance. Includes an MFD addition to give access to the address needed for DMA. * tsl2583 - Device tree bindings Cleanups and minor fixes * ad7192 - Fix regulator naming to match datasheet - Handle regulator errors correctly (so as to not break deferred probing) - Rename reg variable to reflect which regulator it is * ad5933 - Fix regulator naming to match datasheet - Handle regulator errors correctly (so as to not break deferred probing) * ad7746 - Fix a missing return value (fallout from previous patch set) * ad7780 - Fix regulator naming to match datasheet - Handle regulator errors correctly (so as to not break deferred probing) * ad9832 - Fix regulator naming to match datasheet - Handle regulator errors correctly (so as to not break deferred probing) - Rename reg regulator to reflect which one it is * ad9834 - Fix regulator naming to match datasheet - Handle regulator errors correctly (so as to not break deferred probing) * hts221 - Remove a duplicated include * maxim thermocouple - Handle a wrong storage side in read function. Prevent any problems that might be introduced by additions to this driver in future. * tsl2583 - big set from Brian Masney to drive this towards a staging graduation. - Convert to iio_chan_spec and read_raw / write_raw (in a couple of steps) - Improved error handling in various functions - Drop redundant power_state custom sysfs attribute. - Use IIO_*_ATTR* macros for remaining attributes. - Return an error code to userspace on invalid parameters being writen to sysfs files. - Add locking to various attribute accesses to remove possible races. - Add defines for various magic numbers. - Use smbus_read_byte_data instead of a write_byte followed by read_byte. - Query only relevant registers in probe. - Tidy up ordering of code comments. - Remove a pointless power off sequence in taos_chip_on. - Don't bother shutting down the chip when updating the lux table. The table is held entirely in the driver and doesn't effect the chip at all. - Drop a redundant i2c call in taos_als_calibrate where the same register is read twice in a row.
2016-11-05iio: hid-sensors: Increase the precision of scale to fix wrong reading ↵Song Hongyan
interpretation. While testing, it was observed that on some platforms the scale value from iio sysfs for gyroscope is always 0 (E.g. Yoga 260). This results in the final angular velocity component values to be zeros. This is caused by insufficient precision of scale value displayed in sysfs. If the precision is changed to nano from current micro, then this is sufficient to display the scale value on this platform. Since this can be a problem for all other HID sensors, increase scale precision of all HID sensors to nano from current micro. Results on Yoga 260: name scale before scale now -------------------------------------------- gyro_3d 0.000000 0.000000174 als 0.001000 0.001000000 magn_3d 0.000001 0.000001000 accel_3d 0.000009 0.000009806 Signed-off-by: Song Hongyan <hongyan.song@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-05iio: orientation: hid-sensor-rotation: Add PM function (fix non working driver)Song Hongyan
This fix makes newer ISH hubs work. Previous ones worked by lucky coincidence. Rotation sensor function does not work due to miss PM function. Add common hid sensor iio pm function for rotation sensor. Further clarification from Srinivas: If CONFIG_PM is not defined, then this prevents this sensor to function. So above commit caused this. This sensor was supposed to be always on to trigger wake up in prior external hubs. But with the new ISH hub this is not the case. Signed-off-by: Song Hongyan <hongyan.song@intel.com> Fixes: 2b89635e9a9e ("iio: hid_sensor_hub: Common PM functions") Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-05Merge branch 'ib-iio-mfd-ti335x_dma' into togregJonathan Cameron
A local branch created as Lee requested these two patches were applied in a fashion that would later let him merge the same branch into MFD if needed.
2016-11-05drivers: iio: ti_am335x_adc: add dma supportMugunthan V N
This patch adds the required pieces to ti_am335x_adc driver for DMA support Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com> Reviewed-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-05iio: adc: at91: add suspend and resume callbackWenyou Yang
Add suspend/resume callback, support the pinctrl sleep state when the system suspend as well. Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com> Acked-by: Ludovic Desroches <ludovic.desroches@atmel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-05iio: hid-sensor-attributes: Check sample_frequency/hysteresis write data ↵Song Hongyan
legitimacy Neither sample frequency value nor hysteresis value can be set to be a negative number, check and return "Invalid argument" if they are negative. If not do this change, sample_frequency will be set into some unknown value, read hysteresis value after write negative number will return "Invalid argument". Signed-off-by: Song Hongyan <hongyan.song@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01Merge branch 'ib-iio-mfd-4.9rc1' into togregJonathan Cameron
Immutable branch to allow mfd changes to also be available in Lee's MFD tree.
2016-11-01iio: accel: st_accel: add support to lng2dmLorenzo Bianconi
add support to STMicroelectronics LNG2DM accelerometer to st_accel framework Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01iio: si7020: Add devicetree support and trivial bindingsPaul Kocialkowski
This adds devicetree support for the si7020 iio driver. Since it works well without requiring any additional property, its compatible string is added to the trivial i2c devices bindings list. Signed-off-by: Paul Kocialkowski <contact@paulk.fr> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01iio: humidity: remove duplicated include from hts221_buffer.cWei Yongjun
Remove duplicated include. Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>