aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/vf610_adc.c
AgeCommit message (Collapse)Author
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-07-06iio: adc: vf610_adc: Fix VALT selection value for REFSEL bitsStefan-Gabriel Mirea
In order to select the alternate voltage reference pair (VALTH/VALTL), the right value for the REFSEL field in the ADCx_CFG register is "01", leading to 0x800 as register mask. See section 8.2.6.4 in the reference manual[1]. [1] http://www.nxp.com/docs/en/reference-manual/VFXXXRM.pdf Fixes: a775427632fd ("iio:adc:imx: add Freescale Vybrid vf610 adc driver") Signed-off-by: Stefan-Gabriel Mirea <stefan-gabriel.mirea@nxp.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-04-02iio: adc: Remove unnecessary cast on void pointersimran singhal
The following Coccinelle script was used to detect this: @r@ expression x; void* e; type T; identifier f; @@ ( *((T *)e) | ((T *)x)[...] | ((T*)x)->f | - (T*) e ) Signed-off-by: simran singhal <singhalsimran0@gmail.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-04-16iio: adc: vf610_adc: fix case label indentSlawomir Stepien
This fixes the error reported by checkpatch.pl: ERROR: switch and case should be at the same indent Signed-off-by: Slawomir Stepien <sst@poczta.fm> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-11-18Merge tag 'iio-fixes-for-4.4a' of ↵Greg Kroah-Hartman
ssh://ra.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus Jonathan writes: First set of IIO fixes for the 4.4 cycle. This set does not include those for issues introduced during the merge window. Fixes of those will follow in a future series. * ad5064 - Make sure the local i2c_write returns 0 on success rather than the number of bytes transfered. Otherwise we report an error on all writes. - Fix a shift for ad5629 and ad5669 which gives incorrect DAC output on these parts. * ad7793 - The product ID on the datasheet is wrong. Fix it in the driver. * IIO_DUMMY_EVGEN - select IRQ_WORK as a dependency. * lpc32xx - make sure clock is prepared before enabling. * si7020 - data byte order was reversed. Fix it. * vf610 - Internal temperature calculation was wrong if a different reference voltage was used. Now use a linear interpolation function to make it work over the full range. - Fix a division by zero in the case of a device tree property not being present (same issue two fixes). * xilinx XADC - VREFN scale was wrong - fix it.
2015-11-08iio: adc: vf610_adc: Fix division by zero errorSanchayan Maity
In case the fsl,adck-max-frequency property is not present in the device tree, a division by zero error results during the probe call on kernel boot (see below). This patch fixes it and also restores device tree compatibility in case kernels are booting with old device trees without this property specified. [ 1.063229] Division by zero in kernel. [ 1.067152] CPU: 0 PID: 1 Comm: swapper Not tainted 4.3.0-rc5-00212-gcc88cef #37 [ 1.074650] Hardware name: Freescale Vybrid VF5xx/VF6xx (Device Tree) [ 1.081135] Backtrace: [ 1.083694] [<800134a4>] (dump_backtrace) from [<8001369c>] (show_stack+0x18/0x1c) [ 1.091340] r7:00000008 r6:8e0ae210 r5:00000000 r4:8e299800 [ 1.097146] [<80013684>] (show_stack) from [<80297b1c>] (dump_stack+0x24/0x28) [ 1.104483] [<80297af8>] (dump_stack) from [<80013608>] (__div0+0x1c/0x20) [ 1.111421] [<800135ec>] (__div0) from [<802968b4>] (Ldiv0+0x8/0x10) [ 1.117865] [<80424350>] (vf610_adc_probe) from [<803153b4>] (platform_drv_probe+0x4c/0xac) [ 1.126311] r10:00000000 r9:8076a5ec r8:00000000 r7:fffffdfb r6:807cc67c r5:8e0ae210 [ 1.134319] r4:807f6c54 [ 1.136915] [<80315368>] (platform_drv_probe) from [<803138bc>] (driver_probe_device+0x20c/0x2f8) [ 1.145882] r7:807cc67c r6:00000000 r5:8e0ae210 r4:807f6c54 [ 1.151657] [<803136b0>] (driver_probe_device) from [<80313a3c>] (__driver_attach+0x94/0x98) [ 1.160190] r9:8076a5ec r8:00000098 r7:00000000 r6:8e0ae244 r5:807cc67c r4:8e0ae210 [ 1.168112] [<803139a8>] (__driver_attach) from [<80311cb8>] (bus_for_each_dev+0x70/0xa4) [ 1.176383] r7:00000000 r6:803139a8 r5:807cc67c r4:00000000 [ 1.182159] [<80311c48>] (bus_for_each_dev) from [<80313318>] (driver_attach+0x24/0x28) [ 1.190260] r6:807bb568 r5:8e2a5b00 r4:807cc67c [ 1.194996] [<803132f4>] (driver_attach) from [<80312f50>] (bus_add_driver+0x1a4/0x21c) [ 1.203113] [<80312dac>] (bus_add_driver) from [<803142a8>] (driver_register+0x80/0x100) [ 1.211275] r7:8e2a7dc0 r6:807a8160 r5:80789e14 r4:807cc67c [ 1.217075] [<80314228>] (driver_register) from [<803152f8>] (__platform_driver_register+0x5c/0x64) [ 1.226216] r5:80789e14 r4:807a8160 [ 1.229877] [<8031529c>] (__platform_driver_register) from [<80789e30>] (vf610_adc_driver_init+0x1c/0x20) [ 1.239556] [<80789e14>] (vf610_adc_driver_init) from [<800095f8>] (do_one_initcall+0x94/0x1dc) [ 1.248365] [<80009564>] (do_one_initcall) from [<8076ae34>] (kernel_init_freeable+0x13c/0x1e0) [ 1.257155] r10:80794830 r9:8076a5ec r8:00000098 r7:807d5780 r6:807d5780 r5:00000006 [ 1.265153] r4:807a0ee8 [ 1.267753] [<8076acf8>] (kernel_init_freeable) from [<80590ef0>] (kernel_init+0x18/0xf0) [ 1.276021] r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:80590ed8 [ 1.284015] r4:807d5780 [ 1.286615] [<80590ed8>] (kernel_init) from [<8000f878>] (ret_from_fork+0x14/0x3c) [ 1.294278] r5:80590ed8 r4:00000000 Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com> Acked-by: Fugang Duan <B38611@freescale.com> Acked-by: Stefan Agner <stefan@agner.ch> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-10-25vf610_adc: Fix internal temperature calculationBhuvanchandra DV
Calculate ADCR_VTEMP25 using VTEMP25 at VREFH_ADC 3V3. Existing calculations consider the typical values provided in datasheet. Those typical values are valid for VREFH_ADC at 3.0V. VTEMP25 is different for different VREFH_ADC voltages. With VREFH_ADC at 3.3V, voltage at 25°C is 0.699V. Hence update the VTEMP25 to 0.699V which gives ADCR@Temp25 as 867. Formula for finding ADCR@Temp25: ADCR@Temp25 = (ADCR@Vdd * V@TEMP25 * 10) / VDDconv ADCR@Vdd for 12-Bit ADC = 4095 VDDconv = VREFH_ADC * 10 VREFH_ADC@3.3V ADCR@Temp25 = (4095 * .699 * 10) / 33 ADCR@Temp25 ~= 867 | VREFH_ADC | V@TEMP25 | VDDconv | ADCR@Temp25 | | 3.0V | 0.696mV | 30 | 950 | | 3.3V | 0.699mV | 33 | 867 | Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com> Acked-by: Fugang Duan <B38611@freescale.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-09-23iio: adc: vf610: fix simple_return.cocci warningskbuild test robot
drivers/iio/adc/vf610_adc.c:766:1-4: WARNING: end returns can be simpified and declaration on line 755 can be dropped Simplify a trivial if-return sequence. Possibly combine with a preceding function call. Generated by: scripts/coccinelle/misc/simple_return.cocci CC: Sanchayan Maity <maitysanchayan@gmail.com> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-08-31iio: adc: vf610: Add IIO buffer support for Vybrid ADCSanchayan Maity
This patch adds support for IIO buffer to the Vybrid ADC driver. IIO triggered buffer infrastructure along with iio sysfs trigger is used to leverage continuous sampling support provided by the ADC block. Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com> Acked-by: Fugang Duan <B38611@freescale.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-08-12Merge tag 'iio-for-4.3b-2' of ↵Greg Kroah-Hartman
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: Second set of new device support, features and cleanup for the 4.3 cycle. Take 2 also includes a fix set that was too late for the 4.2 cycle. As we had a lot of tools and docs work in this set, I have broken those out into their own categories in this description. Fixes from the pull request '4th set of IIO fixes for the 4.2 cycle'. * Poll functions for both event chardev and the buffer one were returning negative error codes (via a positive value). * A recent change to lsiio adding some error handling that was wrong and stopped the tool working. * bmg160 was missing some dependencies in Kconfig * berlin2-adc had a misshandled register (wrote a value rather than a bitmap) New device support * TI opt3001 light sensor * TXC PA12 ALS and proximity sensor. * mcp3301 ADC support (in mcp320x driver) * ST lsm303agr accelerometer and magnetometer drivers (plus some st-sensors common support to allow different WHOAMI register addresses, devices with fixed scale and allow interrupt equiped magnetometers). * ADIS16305, ADIS16367, ADIS16445IMUs (in the adis16400 driver) * ADIS16266 gyro (in the adis16260 driver) * ADIS16137 gyro (in the adis16136 driver) New functionality * mmc35240 DT bindings. * Inverse unit conversion macros to aid handing of values written to sysfs attributes. Core cleanup * Forward declaration of struct iio_trigger to avoid a compile warning. Driver cleanup / fixes * mxs-lradc - Clarify which parts are supported. - Fix spelling erorrs. - Missing/extra includes - reorder includes - add datasheet name listings for all usable channels (to allow them to be bound by name from consumer drivers) * acpi-als - add some function prefixes as per general iio style. * bmc150_magn - replace a magic value with the existing define. * vf610 - determine possible sample frequencies taking into account the electrical characteristics (defining a minimum sample time) * dht11 - whitespace - additional docs - avoid mulitple assignments in one line - Use the new funciton ktime_get_resolution_ns to cleanup a nasty trick previously used for timing. * Fix all drivers that consider 0 a valid IRQ for historical reasons. * Export I2C module alias info where previously missing (to allow autoprobing) * Export OF module alias info where previously missing. * mmc35240 - switch some variables into arrays to improve readability. * mlx90614 - define some magic numbers for readability. * bmc150_magn - expand area locked by a mutex to cover all the use of the data->buffer. - use descriptive naming for a mask instead of a magic value. * berin2-adc - pass up an error code rather that a generic error - constify the iio_chan_spec - some other little tidy ups. * stk8312 - fix a dependency on triggered buffers in kconfig - add a check for invalid attribute values - improve error handling by returning error codes where possible and return immediately where relevant - rework macro defs to use GENMASK etc - change some variable types to reduce unnecessary casting - clean up code style - drop a local buffer copy for bulk reads and use the one in data->buffer instead. * adis16400 - the adis16448 gyroscope scale was wrong. * adis16480 - some more wrong scales for various parts. * adis16300 - has an undocumented product id and serial number registers so use them. * iio_simple_dummy - fix some wrong code indentation. * bmc150-accel - use the chip ID to detect the chip present rather than verifying the expected part was there. This was in response to a wrong ACPI entry on the WinBook TW100. * mma8452 - fix _get_hp_filter_index - drop a double include - pass up an error code rather than rewriting it - range check input values to attribute writes - register defs tidy up using GENMASK and reordering them to be easier to follow. - various coding style cleanups - put the Kconfig entry in the write place (alphabetically). Tools related * Tools cleanup - drop an explicity NULL comparison, some unnecessary braces, use the ARRAY_SIZE macro, send error messages to stderr instead of dropping them in the middle of normal output. * Fix tools to allow that scale and offset attributes are optional. * More tools fixes including allowing true 32bit data (previously an overflow prevented more than 31bits) * Drop a stray header guard that ended up in a c file. * Make calc_digits static as it isn't exported or in the header. * Set ci_array pointer to NULL after free as a protection against non safe usage of the tools core code. Also convert a double pointer to a single one as the extra level of indirection was unnecessary. Docs * DocBook introduction by Daniel Baluta. Glad we are beginning to draw together some more introductory docs to suplement the various tools / examples. * Drop bytes_per_datum sysfs attribute docs as it no longer exists. * A whole load of missing / fixing of kernel-doc for the core of IIO. * Document the trigger name sysfs attribute in the ABI docs. * Minor typos in the ABI docs related to power down modes.
2015-07-20iio: adc: vf610: Determine sampling frequencies by using minimum sample timeSanchayan Maity
The driver currently does not take into account the minimum sample time as per the Figure 6-8 Chapter 9.1.1 12-bit ADC electrical characteristics. We set a static amount of cycles instead of considering the sample time as a given value, which depends on hardware characteristics. Determine sampling frequencies by first reading the device tree property node and then calculating the required Long Sample Time Adder (LSTAdder) value, based on the ADC clock frequency and sample time value obtained from the device tree. This LSTAdder value is then used for calculating the sampling frequencies possible. In case the sample time property is not specified through the device tree, a safe default value of 1000ns is assumed. Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com> Acked-by: Stefan Agner <stefan@agner.ch> Acked-by: Fugang Duan <B38611@freescale.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-07-19iio: adc: vf610: fix the adc register read fail issueFugang Duan
Read the register only when the adc register address is 4 byte aligned. (rather than the other way around). Signed-off-by: Haibo Chen <haibo.chen@freescale.com> Signed-off-by: Fugang Duan <B38611@freescale.com> Cc: <Stable.vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-06-07iio: adc: vf610: implement configurable conversion modesStefan Agner
Support configurable conversion mode through sysfs. So far, the mode used was low-power, which is enabled by default now. Beside that, the modes normal and high-speed are selectable as well. Use the new device tree property which specifies the maximum ADC conversion clock frequencies. Depending on the mode used, the available resulting conversion frequency are calculated dynamically. Acked-by: Fugang Duan <B38611@freescale.com> Signed-off-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-04-07Merge 4.0-rc7 into staging-nextGreg Kroah-Hartman
We want those fixes (iio primarily) into the -next branch to help with merge and testing issues. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-03-28iio: adc: vf610: use ADC clock within specificationStefan Agner
Depending on conversion mode used, the ADC clock (ADCK) needs to be below a maximum frequency. According to Vybrid's data sheet this is 20MHz for the low power conversion mode. The ADC clock is depending on input clock, which is the bus clock by default. Vybrid SoC are typically clocked at at 400MHz or 500MHz, which leads to 66MHz or 83MHz bus clock respectively. Hence, a divider of 8 is required to stay below the specified maximum clock of 20MHz. Due to the different bus clock speeds, the resulting sampling frequency is not static. Hence use the ADC clock and calculate the actual available sampling frequency dynamically. This fixes bogous values observed on some 500MHz clocked Vybrid SoC. The resulting value usually showed Bit 9 being stuck at 1, or 0, which lead to a value of +/-512. Signed-off-by: Stefan Agner <stefan@agner.ch> Acked-by: Fugang Duan <B38611@freescale.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-02-04iio: vf610_adc: cleanup wait_for_completion return handlingNicholas Mc Guire
return type of wait_for_completion_timeout is unsigned long not int, this patch only fixes up the return handling. Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-10-22iio: adc: vf610: Propagate the real error when platform_get_irq() failsFabio Estevam
There is no need to pass a 'fake' return value when platform_get_irq() fails. Propagate the real error instead. While at it, only consider negative numbers returned by platform_get_irq() as error. Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-10-04iio: adc: vf610: SIMPLE_DEV_PM_OPS can fit on a single lineFabio Estevam
No need to call the SIMPLE_DEV_PM_OPS() macro in several lines. It can fit into the 80-column range. Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-10-04iio: adc: vf610: Disable the regulator on errorFabio Estevam
If clk_prepare_enable() fails we should disable the regulator that was previously enabled. Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-10-04iio: adc: vf610: Return the error code directlyFabio Estevam
There is no need to pass the error clock code to the variable 'ret'. Just return the error directly. Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-09-21iio:adc:vf610-adc: Add temperature sensor supportSanchayan Maity
Vybrid ADC peripheral includes a temperature sensor which is connected to channel number 26. This patch adds support for the sensor. The raw value is read and the temperature calculated in milli degree Celsius, which is returned using IIO_CHAN_INFO_PROCESSED option. Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-08-26iio: remove .owner field for driver using module_platform_driverSanjeev Sharma
This patch removes the .owner field for drivers which use the platform_driver_register api because this is overriden in _platform_driver_register. Signed-off-by: Sanjeev Sharma <Sanjeev_Sharma@mentor.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-03-02iio:adc:vf610 ensure correct handing of interruption of wait for completionJonathan Cameron
Issue highlighted by smatch warning: CHECK drivers/iio/adc/vf610_adc.c drivers/iio/adc/vf610_adc.c:466 vf610_read_raw() warn: unsigned 'ret' is never less than zero. As wait_for_completion_interruptible_timeout can return -ERESTARTSTSYS, if interrupted, ret must be signed. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Acked-by: Fugang Duan <B38611@freescale.com>
2014-02-15iio:adc:imx: add Freescale Vybrid vf610 adc driverFugang Duan
Add Freescale Vybrid vf610 adc driver. The driver only support ADC software trigger. VF610 ADC device documentation is available at below reference manual (chapter 37): http://cache.freescale.com/files/32bit/doc/ref_manual/VYBRIDRM.pdf? fpsp=1&WT_TYPE=Reference%20Manuals&WT_VENDOR=FREESCALE&WT_FILE_FORMAT =pdf&WT_ASSET=Documentation CC: Shawn Guo <shawn.guo@linaro.org> CC: Jonathan Cameron <jic23@kernel.org> CC: Mark Rutland <mark.rutland@arm.com> CC: Otavio Salvador <otavio@ossystems.com.br> CC: Peter Meerwald <pmeerw@pmeerw.net> CC: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Fugang Duan <B38611@freescale.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>