diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-04-04 23:25:29 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-04-04 23:25:29 +0300 |
commit | 932f98922f6fca9f8c45274346b49058dd50d51a (patch) | |
tree | 75635c62cfbaa0397d7169a69e132c0a2a235ade /drivers/staging/iio | |
parent | 44b8ef17c435ecc1a2a505e39e8556f26c0da4ef (diff) | |
parent | df1d80aee963480c5c2938c64ec0ac3e4a0df2e0 (diff) | |
download | linux-932f98922f6fca9f8c45274346b49058dd50d51a.tar.xz |
Merge tag 'iio-for-5.2a-2' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
First set of new device support, features and fixes for IIO in the 5.2 cycle
Staging graduations
* ad7780
- Move this ADC driver out of staging. Included adding some new features
along the way (see below). Also added DT bindings.
New device support
* adis16480
- Support the ADIS16495 and ADIS16497 IMU devices making
heavy use of refactoring of various aspects of the driver in precursor
patches.
* lsm6dsx
- Support for the ASM330LHH 6-axis (accelerometer + gyro) sensor.
- Support for the LSM6DS0X
* matbotix mb1232
- New driver for this ultrasound ranging device family. Including bindings.
- Supports mb1202, mb1212, mb1222, mb1232, mb1242, mb7040 and mb7137.
* max31856
- New driver for this thermocouple temperature sensor.
* meson saradc
- Support the Meson-G12A (ID addition only).
* stmpe-adc
- New driver supporting generic ADC alongside touchscreen support which
previously existed. Includes DT bindings.
* vcnl4000
- Support for the vcln4040 proximity and light sensor, including adding
DT bindings for this and parts previously supported.
Features
* core
- Allow reading of mount matrices from ACPI in addition to DT.
- Common binding for theromcouple types.
* ad5933
- Add ABI docs as there are a few 'unsual' elements about this
device - perhaps because it's our only impedance analyser.
* ad7780
- Add gain and filter gpio support + readback of current gain and filter.
* adis16480
- Allow selection fo the dataready pin to be used.
- Device tree ID table and binding documentation.
- Support external clock modes, including new bindings.
* bma180
- Mount matrix support.
* bmc150
- Mount matrix support.
* bmg160
- Mount matrix support.
- DT id table and bindings doc.
* bmp280
- Put calibration data into the entropy pool.
* hmc5843
- Mount matrix support.
* itg3200
- Mount matrix support.
* kxcjk1013
- Device tree id table, and binding docs.
* lpc32xx
- Add scale when regulator specified including DT docs for regulator.
* pms7003
- Add device IDs for all supported parts to driver and binding.
* stm32-dfsdm
- Enable hw consumer support, scan mode control and a complex set of
triggered buffer modes.
- Power management.
* stm32-lptimer-counter
- power management.
- Document the pinctrl sleep state binding.
* ti-ads7950
- GPIO pin support.
Cleanups, minor fixes
* core
- Use bitmap_zalloc to make it explicit that is what we are doing.
- Tidy up all the Kconfig files (which had slowly gotten messy)
- Fix a forwards definition missing issue in iio/driver.h
* ad sigma delta core
- Improve handling of SPI bus locking vs CS assertion. This has been
wrong a long time so not rushing this in.
* ad5064
- Mlock to local lock.
* ad5933 (staging cleanup)
- Multiline comment fixes.
- Include ordering.
- SPDX.
- Tidy up Kconfig help which was a bit missleading.
- Change some non standard attributes to ABI defined ones.
* ad7124
- White space fix.
* ad7192
- White space.
- Use DT clock binding.
- Improve error reporting.
- Platform data to DT conversion.
- Use read_avail callback, mostly to avoid the endless series of
patches from new contributors trying to falsely put spaces around
the negative sign.
* ad7280a
- Add brackets to macros to avoid potential precedence isseus.
- Add temp vars for event codes to reduce indent and improved readability.
- Clean out som CamelCase notation.
- White space.
* ad7606
- Fix broken file naming in MAINTAINERS.
* ad7780
- Missing switch defaults to supress warnings and harden the code slightly.
- Set pattern masks more directly.
- Add ID values and masks for all supported chips.
- SPDX + add Renato as a copyright holder as he has done a lot of work on
this driver.
- Add brackets to macros to avoid potential precedence issues.
* ad7923
- White space fixes.
- Use BIT macro to improve readability.
- Add brackets to macros to avoid potential precedence issues.
- Tidy up a null comparisom.
* ad9523
- Fix a typo in naming of variables.
* adis16400
- Combine trigger file into main code as no advantage in separate files.
Rename core file to just adis16400.
- Squash the header into the c file now there is only one file.
- Generalize burst mode to support new variants.
* ak8975
- Local variable to improve readability around mount matrix support.
* as3935
- Avoid potential race by ensuring remove does exact opposite of
probe rather than a slightly different order.
* cross_ec
- Drop some unnecessary includes.
- Fix some warning and the slightly 'unusual' code.
- Add some docs for non obvious function.
- SPDX
* hmc5843
- Potential unhandled error case.
* iio trigger core
- Print an error if there is no available irq due to max consumers per
trigger being set to low.
* iio loop trigger
- Drop an unlikely on IS_ERR as IS_ERR already has the annotation.
* ingenic-adc
- Drop a redundant dev_err call as devm_ioremap_resource reports the same
internally.
* lmp91000
- Drop some unncessary parentheses and white space tidy up.
- Invert and if statement to improve readability.
- Fix a wrong error message.
* lpc32xx
- Header sorting + drop some unused ones.
* mma8542
- Mark a switch fallthrough.
* mpu6050
- Add a local variable to improve code readability around mount matrix
support.
* mxs-lradc-adc
- Handle devm_iio_trigger_alloc failure.
* sps30
- Fix up a kernel version in the ABI docs.
* srf04
- DT binding doc converted to yaml.
* ssp_sensors
- Supress a clang build warning due to lack of visibility of conditional
within a iio_push_to_buffers_with_timestamp. (reasonable false warning!)
* st_accel
- Drop pointless less than 0 comparisom of unsigned int.
* stm32-dfsdm
- Improve accuracy of spi_master_frequency calculation.
- Improve calculation fo sampling frequency.
- Rework various internals to simplify adding triggered buffer support.
- Claim direct mode to avoid racing around read_raw and being in buffered
mode.
* stmpe
- Fix a clang false positive warning.
* ti-ads7950
- Use local lock rather than using the core mlock when not locking around
the device mode.
* vcnl4000
- Use word writes instead of byte writes. It seems byte writes are fine
for some parts (undocument) but not others that the driver will shortly
support.
Other
* mailmap
- Add email address change for Sean Nyekjaer. Update in relevant drivers
* tag 'iio-for-5.2a-2' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (129 commits)
iio: ad_sigma_delta: Properly handle SPI bus locking vs CS assertion
iio: adc: stm32-dfsdm: add PM support
iio: adc: stm32-dfsdm: improve sampling frequency accuracy
staging: iio: adc: ad7280a: Tab alignment
MAINTAINERS: Fix the link to ad7606 dt-bindings
iio:temperature: Add MAX31856 thermocouple support
iio:temperature:max31856:Add device tree bind info
dt-bindings: iio/temperature: Add thermocouple types (and doc)
devantech-srf04.yaml: transform DT binding to YAML
iio: frequency: ad9523: Fix typo in ad9523_platform_data
iio: Make possible to include driver.h first
dt-bindings: iio: add Bosch BMG160 gyroscope sensor
iio: gyro: bmg160: add device tree compatibility table
staging: iio: adc: ad7192: Use read_avail for available attributes
dt-bindings: iio: light: add vcnl4040 devicetree bindings
iio: light: vcnl4000 add support for the VCNL4040 proximity and light sensor
dt-bindings: iio: light: add vcnl4000 devicetree bindings
iio: light: vcnl4000 add devicetree hooks
iio: light: vcnl4000 use word writes instead of byte writes
iio: adc: stm32-dfsdm: claim direct mode for raw read and settings
...
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r-- | drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 | 30 | ||||
-rw-r--r-- | drivers/staging/iio/adc/Kconfig | 13 | ||||
-rw-r--r-- | drivers/staging/iio/adc/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7192.c | 233 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7192.h | 9 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7280a.c | 109 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7780.c | 276 | ||||
-rw-r--r-- | drivers/staging/iio/impedance-analyzer/Kconfig | 2 | ||||
-rw-r--r-- | drivers/staging/iio/impedance-analyzer/ad5933.c | 51 |
9 files changed, 227 insertions, 497 deletions
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 b/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 deleted file mode 100644 index 79c7e88c64cd..000000000000 --- a/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 +++ /dev/null @@ -1,30 +0,0 @@ -What: /sys/bus/iio/devices/iio:deviceX/outY_freq_start -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Frequency sweep start frequency in Hz. - -What: /sys/bus/iio/devices/iio:deviceX/outY_freq_increment -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Frequency increment in Hz (step size) between consecutive - frequency points along the sweep. - -What: /sys/bus/iio/devices/iio:deviceX/outY_freq_points -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Number of frequency points (steps) in the frequency sweep. - This value, in conjunction with the outY_freq_start and the - outY_freq_increment, determines the frequency sweep range - for the sweep operation. - -What: /sys/bus/iio/devices/iio:deviceX/outY_settling_cycles -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Number of output excitation cycles (settling time cycles) - that are allowed to pass through the unknown impedance, - after each frequency increment, and before the ADC is triggered - to perform a conversion sequence of the response signal. diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index 94ad59fefb0e..23d9a655a520 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -4,19 +4,6 @@ # menu "Analog to digital converters" -config AD7780 - tristate "Analog Devices AD7780 and similar ADCs driver" - depends on SPI - depends on GPIOLIB || COMPILE_TEST - select AD_SIGMA_DELTA - help - Say yes here to build support for Analog Devices AD7170, AD7171, - AD7780 and AD7781 SPI analog to digital converters (ADC). - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called ad7780. - config AD7816 tristate "Analog Devices AD7816/7/8 temperature sensor and ADC driver" depends on SPI diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile index 7a421088ff82..4b76769b32bc 100644 --- a/drivers/staging/iio/adc/Makefile +++ b/drivers/staging/iio/adc/Makefile @@ -3,7 +3,6 @@ # Makefile for industrial I/O ADC drivers # -obj-$(CONFIG_AD7780) += ad7780.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_AD7192) += ad7192.o obj-$(CONFIG_AD7280) += ad7280a.o diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index dfb79fbf63f4..2d86167aeeed 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -6,6 +6,7 @@ */ #include <linux/interrupt.h> +#include <linux/clk.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/slab.h> @@ -155,14 +156,16 @@ struct ad7192_state { struct regulator *avdd; struct regulator *dvdd; + struct clk *mclk; u16 int_vref_mv; - u32 mclk; + u32 fclk; u32 f_order; u32 mode; u32 conf; u32 scale_avail[8][2]; u8 gpocon; u8 devid; + u8 clock_sel; struct mutex lock; /* protect sensor state */ struct ad_sigma_delta sd; @@ -215,8 +218,8 @@ static const struct ad_sd_calib_data ad7192_calib_arr[8] = { static int ad7192_calibrate_all(struct ad7192_state *st) { - return ad_sd_calibrate_all(&st->sd, ad7192_calib_arr, - ARRAY_SIZE(ad7192_calib_arr)); + return ad_sd_calibrate_all(&st->sd, ad7192_calib_arr, + ARRAY_SIZE(ad7192_calib_arr)); } static inline bool ad7192_valid_external_frequency(u32 freq) @@ -225,23 +228,45 @@ static inline bool ad7192_valid_external_frequency(u32 freq) freq <= AD7192_EXT_FREQ_MHZ_MAX); } -static int ad7192_setup(struct ad7192_state *st, - const struct ad7192_platform_data *pdata) +static int ad7192_of_clock_select(struct ad7192_state *st) +{ + struct device_node *np = st->sd.spi->dev.of_node; + unsigned int clock_sel; + + clock_sel = AD7192_CLK_INT; + + /* use internal clock */ + if (PTR_ERR(st->mclk) == -ENOENT) { + if (of_property_read_bool(np, "adi,int-clock-output-enable")) + clock_sel = AD7192_CLK_INT_CO; + } else { + if (of_property_read_bool(np, "adi,clock-xtal")) + clock_sel = AD7192_CLK_EXT_MCLK1_2; + else + clock_sel = AD7192_CLK_EXT_MCLK2; + } + + return clock_sel; +} + +static int ad7192_setup(struct ad7192_state *st, struct device_node *np) { struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi); + bool rej60_en, sinc3_en, refin2_en, chop_en; + bool buf_en, bipolar, burnout_curr_en; unsigned long long scale_uv; int i, ret, id; /* reset the serial interface */ ret = ad_sd_reset(&st->sd, 48); if (ret < 0) - goto out; + return ret; usleep_range(500, 1000); /* Wait for at least 500us */ /* write/read test for device presence */ ret = ad_sd_read_reg(&st->sd, AD7192_REG_ID, 1, &id); if (ret) - goto out; + return ret; id &= AD7192_ID_MASK; @@ -249,44 +274,28 @@ static int ad7192_setup(struct ad7192_state *st, dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X)\n", id); - switch (pdata->clock_source_sel) { - case AD7192_CLK_INT: - case AD7192_CLK_INT_CO: - st->mclk = AD7192_INT_FREQ_MHZ; - break; - case AD7192_CLK_EXT_MCLK1_2: - case AD7192_CLK_EXT_MCLK2: - if (ad7192_valid_external_frequency(pdata->ext_clk_hz)) { - st->mclk = pdata->ext_clk_hz; - break; - } - dev_err(&st->sd.spi->dev, "Invalid frequency setting %u\n", - pdata->ext_clk_hz); - ret = -EINVAL; - goto out; - default: - ret = -EINVAL; - goto out; - } - st->mode = AD7192_MODE_SEL(AD7192_MODE_IDLE) | - AD7192_MODE_CLKSRC(pdata->clock_source_sel) | + AD7192_MODE_CLKSRC(st->clock_sel) | AD7192_MODE_RATE(480); st->conf = AD7192_CONF_GAIN(0); - if (pdata->rej60_en) + rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable"); + if (rej60_en) st->mode |= AD7192_MODE_REJ60; - if (pdata->sinc3_en) + sinc3_en = of_property_read_bool(np, "adi,sinc3-filter-enable"); + if (sinc3_en) st->mode |= AD7192_MODE_SINC3; - if (pdata->refin2_en && st->devid != ID_AD7195) + refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable"); + if (refin2_en && st->devid != ID_AD7195) st->conf |= AD7192_CONF_REFSEL; - if (pdata->chop_en) { + chop_en = of_property_read_bool(np, "adi,chop-enable"); + if (chop_en) { st->conf |= AD7192_CONF_CHOP; - if (pdata->sinc3_en) + if (sinc3_en) st->f_order = 3; /* SINC 3rd order */ else st->f_order = 4; /* SINC 4th order */ @@ -294,30 +303,34 @@ static int ad7192_setup(struct ad7192_state *st, st->f_order = 1; } - if (pdata->buf_en) + buf_en = of_property_read_bool(np, "adi,buffer-enable"); + if (buf_en) st->conf |= AD7192_CONF_BUF; - if (pdata->unipolar_en) + bipolar = of_property_read_bool(np, "bipolar"); + if (!bipolar) st->conf |= AD7192_CONF_UNIPOLAR; - if (pdata->burnout_curr_en && pdata->buf_en && !pdata->chop_en) { + burnout_curr_en = of_property_read_bool(np, + "adi,burnout-currents-enable"); + if (burnout_curr_en && buf_en && !chop_en) { st->conf |= AD7192_CONF_BURN; - } else if (pdata->burnout_curr_en) { + } else if (burnout_curr_en) { dev_warn(&st->sd.spi->dev, "Can't enable burnout currents: see CHOP or buffer\n"); } ret = ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); if (ret) - goto out; + return ret; ret = ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, st->conf); if (ret) - goto out; + return ret; ret = ad7192_calibrate_all(st); if (ret) - goto out; + return ret; /* Populate available ADC input ranges */ for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) { @@ -331,35 +344,8 @@ static int ad7192_setup(struct ad7192_state *st, } return 0; -out: - dev_err(&st->sd.spi->dev, "setup failed\n"); - return ret; } -static ssize_t -ad7192_show_scale_available(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7192_state *st = iio_priv(indio_dev); - int i, len = 0; - - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) - len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], - st->scale_avail[i][1]); - - len += sprintf(buf + len, "\n"); - - return len; -} - -static IIO_DEVICE_ATTR_NAMED(in_v_m_v_scale_available, - in_voltage-voltage_scale_available, - 0444, ad7192_show_scale_available, NULL, 0); - -static IIO_DEVICE_ATTR(in_voltage_scale_available, 0444, - ad7192_show_scale_available, NULL, 0); - static ssize_t ad7192_show_ac_excitation(struct device *dev, struct device_attribute *attr, char *buf) @@ -434,8 +420,6 @@ static IIO_DEVICE_ATTR(ac_excitation_en, 0644, AD7192_REG_MODE); static struct attribute *ad7192_attributes[] = { - &iio_dev_attr_in_v_m_v_scale_available.dev_attr.attr, - &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, &iio_dev_attr_bridge_switch_en.dev_attr.attr, &iio_dev_attr_ac_excitation_en.dev_attr.attr, NULL @@ -446,8 +430,6 @@ static const struct attribute_group ad7192_attribute_group = { }; static struct attribute *ad7195_attributes[] = { - &iio_dev_attr_in_v_m_v_scale_available.dev_attr.attr, - &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, &iio_dev_attr_bridge_switch_en.dev_attr.attr, NULL }; @@ -498,7 +480,7 @@ static int ad7192_read_raw(struct iio_dev *indio_dev, *val -= 273 * ad7192_get_temp_scale(unipolar); return IIO_VAL_INT; case IIO_CHAN_INFO_SAMP_FREQ: - *val = st->mclk / + *val = st->fclk / (st->f_order * 1024 * AD7192_MODE_RATE(st->mode)); return IIO_VAL_INT; } @@ -545,7 +527,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, break; } - div = st->mclk / (val * st->f_order * 1024); + div = st->fclk / (val * st->f_order * 1024); if (div < 1 || div > 1023) { ret = -EINVAL; break; @@ -578,10 +560,31 @@ static int ad7192_write_raw_get_fmt(struct iio_dev *indio_dev, } } +static int ad7192_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct ad7192_state *st = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *vals = (int *)st->scale_avail; + *type = IIO_VAL_INT_PLUS_NANO; + /* Values are stored in a 2D matrix */ + *length = ARRAY_SIZE(st->scale_avail) * 2; + + return IIO_AVAIL_LIST; + } + + return -EINVAL; +} + static const struct iio_info ad7192_info = { .read_raw = ad7192_read_raw, .write_raw = ad7192_write_raw, .write_raw_get_fmt = ad7192_write_raw_get_fmt, + .read_avail = ad7192_read_avail, .attrs = &ad7192_attribute_group, .validate_trigger = ad_sd_validate_trigger, }; @@ -590,6 +593,7 @@ static const struct iio_info ad7195_info = { .read_raw = ad7192_read_raw, .write_raw = ad7192_write_raw, .write_raw_get_fmt = ad7192_write_raw_get_fmt, + .read_avail = ad7192_read_avail, .attrs = &ad7195_attribute_group, .validate_trigger = ad_sd_validate_trigger, }; @@ -624,6 +628,42 @@ static const struct iio_chan_spec ad7193_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(14), }; +static int ad7192_channels_config(struct iio_dev *indio_dev) +{ + struct ad7192_state *st = iio_priv(indio_dev); + const struct iio_chan_spec *channels; + struct iio_chan_spec *chan; + int i; + + switch (st->devid) { + case ID_AD7193: + channels = ad7193_channels; + indio_dev->num_channels = ARRAY_SIZE(ad7193_channels); + break; + default: + channels = ad7192_channels; + indio_dev->num_channels = ARRAY_SIZE(ad7192_channels); + break; + } + + chan = devm_kcalloc(indio_dev->dev.parent, indio_dev->num_channels, + sizeof(*chan), GFP_KERNEL); + if (!chan) + return -ENOMEM; + + indio_dev->channels = chan; + + for (i = 0; i < indio_dev->num_channels; i++) { + *chan = channels[i]; + if (chan->type != IIO_TEMP) + chan->info_mask_shared_by_type_available |= + BIT(IIO_CHAN_INFO_SCALE); + chan++; + } + + return 0; +} + static int ad7192_probe(struct spi_device *spi) { const struct ad7192_platform_data *pdata = dev_get_platdata(&spi->dev); @@ -686,16 +726,9 @@ static int ad7192_probe(struct spi_device *spi) indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; - switch (st->devid) { - case ID_AD7193: - indio_dev->channels = ad7193_channels; - indio_dev->num_channels = ARRAY_SIZE(ad7193_channels); - break; - default: - indio_dev->channels = ad7192_channels; - indio_dev->num_channels = ARRAY_SIZE(ad7192_channels); - break; - } + ret = ad7192_channels_config(indio_dev); + if (ret < 0) + goto error_disable_dvdd; if (st->devid == ID_AD7195) indio_dev->info = &ad7195_info; @@ -708,15 +741,42 @@ static int ad7192_probe(struct spi_device *spi) if (ret) goto error_disable_dvdd; - ret = ad7192_setup(st, pdata); - if (ret) + st->fclk = AD7192_INT_FREQ_MHZ; + + st->mclk = devm_clk_get(&st->sd.spi->dev, "mclk"); + if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) { + ret = PTR_ERR(st->mclk); goto error_remove_trigger; + } + + st->clock_sel = ad7192_of_clock_select(st); + + if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || + st->clock_sel == AD7192_CLK_EXT_MCLK2) { + ret = clk_prepare_enable(st->mclk); + if (ret < 0) + goto error_remove_trigger; + + st->fclk = clk_get_rate(st->mclk); + if (!ad7192_valid_external_frequency(st->fclk)) { + ret = -EINVAL; + dev_err(&spi->dev, + "External clock frequency out of bounds\n"); + goto error_disable_clk; + } + } + + ret = ad7192_setup(st, spi->dev.of_node); + if (ret) + goto error_disable_clk; ret = iio_device_register(indio_dev); if (ret < 0) - goto error_remove_trigger; + goto error_disable_clk; return 0; +error_disable_clk: + clk_disable_unprepare(st->mclk); error_remove_trigger: ad_sd_cleanup_buffer_and_trigger(indio_dev); error_disable_dvdd: @@ -733,6 +793,7 @@ static int ad7192_remove(struct spi_device *spi) struct ad7192_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); + clk_disable_unprepare(st->mclk); ad_sd_cleanup_buffer_and_trigger(indio_dev); regulator_disable(st->dvdd); diff --git a/drivers/staging/iio/adc/ad7192.h b/drivers/staging/iio/adc/ad7192.h index e382b22c460b..f3669e1df084 100644 --- a/drivers/staging/iio/adc/ad7192.h +++ b/drivers/staging/iio/adc/ad7192.h @@ -32,15 +32,6 @@ struct ad7192_platform_data { u16 vref_mv; - u8 clock_source_sel; - u32 ext_clk_hz; - bool refin2_en; - bool rej60_en; - bool sinc3_en; - bool chop_en; - bool buf_en; - bool unipolar_en; - bool burnout_curr_en; }; #endif /* IIO_ADC_AD7192_H_ */ diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 47cfe920b2ae..19a5f244dcae 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -96,9 +96,10 @@ #define AD7280A_NUM_CH (AD7280A_AUX_ADC_6 - \ AD7280A_CELL_VOLTAGE_1 + 1) -#define AD7280A_CALC_VOLTAGE_CHAN_NUM(d, c) ((d * AD7280A_CELLS_PER_DEV) + c) -#define AD7280A_CALC_TEMP_CHAN_NUM(d, c) ((d * AD7280A_CELLS_PER_DEV) + \ - c - AD7280A_CELLS_PER_DEV) +#define AD7280A_CALC_VOLTAGE_CHAN_NUM(d, c) (((d) * AD7280A_CELLS_PER_DEV) + \ + (c)) +#define AD7280A_CALC_TEMP_CHAN_NUM(d, c) (((d) * AD7280A_CELLS_PER_DEV) + \ + (c) - AD7280A_CELLS_PER_DEV) #define AD7280A_DEVADDR_MASTER 0 #define AD7280A_DEVADDR_ALL 0x1F @@ -782,43 +783,38 @@ static irqreturn_t ad7280_event_handler(int irq, void *private) for (i = 0; i < st->scan_cnt; i++) { if (((channels[i] >> 23) & 0xF) <= AD7280A_CELL_VOLTAGE_6) { if (((channels[i] >> 11) & 0xFFF) >= - st->cell_threshhigh) - iio_push_event(indio_dev, - IIO_EVENT_CODE(IIO_VOLTAGE, - 1, - 0, - IIO_EV_DIR_RISING, - IIO_EV_TYPE_THRESH, - 0, 0, 0), + st->cell_threshhigh) { + u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0, + IIO_EV_DIR_RISING, + IIO_EV_TYPE_THRESH, + 0, 0, 0); + iio_push_event(indio_dev, tmp, iio_get_time_ns(indio_dev)); - else if (((channels[i] >> 11) & 0xFFF) <= - st->cell_threshlow) - iio_push_event(indio_dev, - IIO_EVENT_CODE(IIO_VOLTAGE, - 1, - 0, - IIO_EV_DIR_FALLING, - IIO_EV_TYPE_THRESH, - 0, 0, 0), + } else if (((channels[i] >> 11) & 0xFFF) <= + st->cell_threshlow) { + u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0, + IIO_EV_DIR_FALLING, + IIO_EV_TYPE_THRESH, + 0, 0, 0); + iio_push_event(indio_dev, tmp, iio_get_time_ns(indio_dev)); + } } else { - if (((channels[i] >> 11) & 0xFFF) >= st->aux_threshhigh) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE( - IIO_TEMP, - 0, + if (((channels[i] >> 11) & 0xFFF) >= + st->aux_threshhigh) { + u64 tmp = IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING), + IIO_EV_DIR_RISING); + iio_push_event(indio_dev, tmp, iio_get_time_ns(indio_dev)); - else if (((channels[i] >> 11) & 0xFFF) <= - st->aux_threshlow) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE( - IIO_TEMP, - 0, + } else if (((channels[i] >> 11) & 0xFFF) <= + st->aux_threshlow) { + u64 tmp = IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, IIO_EV_TYPE_THRESH, - IIO_EV_DIR_FALLING), + IIO_EV_DIR_FALLING); + iio_push_event(indio_dev, tmp, iio_get_time_ns(indio_dev)); + } } } @@ -829,30 +825,30 @@ out: } static IIO_DEVICE_ATTR_NAMED(in_thresh_low_value, - in_voltage-voltage_thresh_low_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_CELL_UNDERVOLTAGE); + in_voltage-voltage_thresh_low_value, + 0644, + ad7280_read_channel_config, + ad7280_write_channel_config, + AD7280A_CELL_UNDERVOLTAGE); static IIO_DEVICE_ATTR_NAMED(in_thresh_high_value, - in_voltage-voltage_thresh_high_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_CELL_OVERVOLTAGE); + in_voltage-voltage_thresh_high_value, + 0644, + ad7280_read_channel_config, + ad7280_write_channel_config, + AD7280A_CELL_OVERVOLTAGE); static IIO_DEVICE_ATTR(in_temp_thresh_low_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_AUX_ADC_UNDERVOLTAGE); + 0644, + ad7280_read_channel_config, + ad7280_write_channel_config, + AD7280A_AUX_ADC_UNDERVOLTAGE); static IIO_DEVICE_ATTR(in_temp_thresh_high_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_AUX_ADC_OVERVOLTAGE); + 0644, + ad7280_read_channel_config, + ad7280_write_channel_config, + AD7280A_AUX_ADC_OVERVOLTAGE); static struct attribute *ad7280_event_attributes[] = { &iio_dev_attr_in_thresh_low_value.dev_attr.attr, @@ -920,8 +916,8 @@ static int ad7280_probe(struct spi_device *spi) const struct ad7280_platform_data *pdata = dev_get_platdata(&spi->dev); struct ad7280_state *st; int ret; - const unsigned short tACQ_ns[4] = {465, 1010, 1460, 1890}; - const unsigned short nAVG[4] = {1, 2, 4, 8}; + const unsigned short t_acq_ns[4] = {465, 1010, 1460, 1890}; + const unsigned short n_avg[4] = {1, 2, 4, 8}; struct iio_dev *indio_dev; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); @@ -969,10 +965,9 @@ static int ad7280_probe(struct spi_device *spi) */ st->readback_delay_us = - ((tACQ_ns[pdata->acquisition_time & 0x3] + 695) * - (AD7280A_NUM_CH * nAVG[pdata->conversion_averaging & 0x3])) - - tACQ_ns[pdata->acquisition_time & 0x3] + - st->slave_num * 250; + ((t_acq_ns[pdata->acquisition_time & 0x3] + 695) * + (AD7280A_NUM_CH * n_avg[pdata->conversion_averaging & 0x3])) - + t_acq_ns[pdata->acquisition_time & 0x3] + st->slave_num * 250; /* Convert to usecs */ st->readback_delay_us = DIV_ROUND_UP(st->readback_delay_us, 1000); diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c deleted file mode 100644 index c15389f562b2..000000000000 --- a/drivers/staging/iio/adc/ad7780.c +++ /dev/null @@ -1,276 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - */ - -#include <linux/interrupt.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/sysfs.h> -#include <linux/spi/spi.h> -#include <linux/regulator/consumer.h> -#include <linux/err.h> -#include <linux/sched.h> -#include <linux/gpio/consumer.h> -#include <linux/module.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/adc/ad_sigma_delta.h> - -#define AD7780_RDY BIT(7) -#define AD7780_FILTER BIT(6) -#define AD7780_ERR BIT(5) -#define AD7780_ID1 BIT(4) -#define AD7780_ID0 BIT(3) -#define AD7780_GAIN BIT(2) -#define AD7780_PAT1 BIT(1) -#define AD7780_PAT0 BIT(0) - -#define AD7780_PATTERN (AD7780_PAT0) -#define AD7780_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1) - -#define AD7170_PAT2 BIT(2) - -#define AD7170_PATTERN (AD7780_PAT0 | AD7170_PAT2) -#define AD7170_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2) - -struct ad7780_chip_info { - struct iio_chan_spec channel; - unsigned int pattern_mask; - unsigned int pattern; - bool is_ad778x; -}; - -struct ad7780_state { - const struct ad7780_chip_info *chip_info; - struct regulator *reg; - struct gpio_desc *powerdown_gpio; - unsigned int gain; - - struct ad_sigma_delta sd; -}; - -enum ad7780_supported_device_ids { - ID_AD7170, - ID_AD7171, - ID_AD7780, - ID_AD7781, -}; - -static struct ad7780_state *ad_sigma_delta_to_ad7780(struct ad_sigma_delta *sd) -{ - return container_of(sd, struct ad7780_state, sd); -} - -static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta, - enum ad_sigma_delta_mode mode) -{ - struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); - unsigned int val; - - switch (mode) { - case AD_SD_MODE_SINGLE: - case AD_SD_MODE_CONTINUOUS: - val = 1; - break; - default: - val = 0; - break; - } - - gpiod_set_value(st->powerdown_gpio, val); - - return 0; -} - -static int ad7780_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - struct ad7780_state *st = iio_priv(indio_dev); - int voltage_uv; - - switch (m) { - case IIO_CHAN_INFO_RAW: - return ad_sigma_delta_single_conversion(indio_dev, chan, val); - case IIO_CHAN_INFO_SCALE: - voltage_uv = regulator_get_voltage(st->reg); - if (voltage_uv < 0) - return voltage_uv; - *val = (voltage_uv / 1000) * st->gain; - *val2 = chan->scan_type.realbits - 1; - return IIO_VAL_FRACTIONAL_LOG2; - case IIO_CHAN_INFO_OFFSET: - *val = -(1 << (chan->scan_type.realbits - 1)); - return IIO_VAL_INT; - } - - return -EINVAL; -} - -static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, - unsigned int raw_sample) -{ - struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); - const struct ad7780_chip_info *chip_info = st->chip_info; - - if ((raw_sample & AD7780_ERR) || - ((raw_sample & chip_info->pattern_mask) != chip_info->pattern)) - return -EIO; - - if (chip_info->is_ad778x) { - if (raw_sample & AD7780_GAIN) - st->gain = 1; - else - st->gain = 128; - } - - return 0; -} - -static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { - .set_mode = ad7780_set_mode, - .postprocess_sample = ad7780_postprocess_sample, - .has_registers = false, -}; - -#define AD7780_CHANNEL(bits, wordsize) \ - AD_SD_CHANNEL_NO_SAMP_FREQ(1, 0, 0, bits, 32, wordsize - bits) - -static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { - [ID_AD7170] = { - .channel = AD7780_CHANNEL(12, 24), - .pattern = AD7170_PATTERN, - .pattern_mask = AD7170_PATTERN_MASK, - .is_ad778x = false, - }, - [ID_AD7171] = { - .channel = AD7780_CHANNEL(16, 24), - .pattern = AD7170_PATTERN, - .pattern_mask = AD7170_PATTERN_MASK, - .is_ad778x = false, - }, - [ID_AD7780] = { - .channel = AD7780_CHANNEL(24, 32), - .pattern = AD7780_PATTERN, - .pattern_mask = AD7780_PATTERN_MASK, - .is_ad778x = true, - }, - [ID_AD7781] = { - .channel = AD7780_CHANNEL(20, 32), - .pattern = AD7780_PATTERN, - .pattern_mask = AD7780_PATTERN_MASK, - .is_ad778x = true, - }, -}; - -static const struct iio_info ad7780_info = { - .read_raw = ad7780_read_raw, -}; - -static int ad7780_probe(struct spi_device *spi) -{ - struct ad7780_state *st; - struct iio_dev *indio_dev; - int ret; - - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); - if (!indio_dev) - return -ENOMEM; - - st = iio_priv(indio_dev); - st->gain = 1; - - ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info); - - st->reg = devm_regulator_get(&spi->dev, "avdd"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); - return ret; - } - - st->chip_info = - &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - - spi_set_drvdata(spi, indio_dev); - - indio_dev->dev.parent = &spi->dev; - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = &st->chip_info->channel; - indio_dev->num_channels = 1; - indio_dev->info = &ad7780_info; - - st->powerdown_gpio = devm_gpiod_get_optional(&spi->dev, - "powerdown", - GPIOD_OUT_LOW); - if (IS_ERR(st->powerdown_gpio)) { - ret = PTR_ERR(st->powerdown_gpio); - dev_err(&spi->dev, "Failed to request powerdown GPIO: %d\n", - ret); - goto error_disable_reg; - } - - ret = ad_sd_setup_buffer_and_trigger(indio_dev); - if (ret) - goto error_disable_reg; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_cleanup_buffer_and_trigger; - - return 0; - -error_cleanup_buffer_and_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - regulator_disable(st->reg); - - return ret; -} - -static int ad7780_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7780_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - regulator_disable(st->reg); - - return 0; -} - -static const struct spi_device_id ad7780_id[] = { - {"ad7170", ID_AD7170}, - {"ad7171", ID_AD7171}, - {"ad7780", ID_AD7780}, - {"ad7781", ID_AD7781}, - {} -}; -MODULE_DEVICE_TABLE(spi, ad7780_id); - -static struct spi_driver ad7780_driver = { - .driver = { - .name = "ad7780", - }, - .probe = ad7780_probe, - .remove = ad7780_remove, - .id_table = ad7780_id, -}; -module_spi_driver(ad7780_driver); - -MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); -MODULE_DESCRIPTION("Analog Devices AD7780 and similar ADCs"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig b/drivers/staging/iio/impedance-analyzer/Kconfig index a5b3ee8b02cb..841648847edf 100644 --- a/drivers/staging/iio/impedance-analyzer/Kconfig +++ b/drivers/staging/iio/impedance-analyzer/Kconfig @@ -11,7 +11,7 @@ config AD5933 select IIO_KFIFO_BUF help Say yes here to build support for Analog Devices Impedance Converter, - Network Analyzer, AD5933/4, provides direct access via sysfs. + Network Analyzer, AD5933/4. To compile this driver as a module, choose M here: the module will be called ad5933. diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index d69904899112..af0bcf95ee8a 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -5,22 +5,22 @@ * Copyright 2011 Analog Devices Inc. */ -#include <linux/interrupt.h> +#include <linux/clk.h> +#include <linux/delay.h> #include <linux/device.h> -#include <linux/kernel.h> -#include <linux/sysfs.h> +#include <linux/err.h> #include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> #include <linux/regulator/consumer.h> +#include <linux/sysfs.h> #include <linux/types.h> -#include <linux/err.h> -#include <linux/delay.h> -#include <linux/module.h> -#include <linux/clk.h> -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/iio.h> #include <linux/iio/kfifo_buf.h> +#include <linux/iio/sysfs.h> /* AD5933/AD5934 Registers */ #define AD5933_REG_CONTROL_HB 0x80 /* R/W, 1 byte */ @@ -315,12 +315,12 @@ static ssize_t ad5933_store_frequency(struct device *dev, return ret ? ret : len; } -static IIO_DEVICE_ATTR(out_voltage0_freq_start, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_start, 0644, ad5933_show_frequency, ad5933_store_frequency, AD5933_REG_FREQ_START); -static IIO_DEVICE_ATTR(out_voltage0_freq_increment, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_increment, 0644, ad5933_show_frequency, ad5933_store_frequency, AD5933_REG_FREQ_INC); @@ -443,12 +443,12 @@ static ssize_t ad5933_store(struct device *dev, return ret ? ret : len; } -static IIO_DEVICE_ATTR(out_voltage0_scale, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_raw, 0644, ad5933_show, ad5933_store, AD5933_OUT_RANGE); -static IIO_DEVICE_ATTR(out_voltage0_scale_available, 0444, +static IIO_DEVICE_ATTR(out_altvoltage0_scale_available, 0444, ad5933_show, NULL, AD5933_OUT_RANGE_AVAIL); @@ -463,28 +463,29 @@ static IIO_DEVICE_ATTR(in_voltage0_scale_available, 0444, NULL, AD5933_IN_PGA_GAIN_AVAIL); -static IIO_DEVICE_ATTR(out_voltage0_freq_points, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_points, 0644, ad5933_show, ad5933_store, AD5933_FREQ_POINTS); -static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_settling_cycles, 0644, ad5933_show, ad5933_store, AD5933_OUT_SETTLING_CYCLES); -/* note: +/* + * note: * ideally we would handle the scale attributes via the iio_info * (read|write)_raw methods, however this part is a untypical since we * don't create dedicated sysfs channel attributes for out0 and in0. */ static struct attribute *ad5933_attributes[] = { - &iio_dev_attr_out_voltage0_scale.dev_attr.attr, - &iio_dev_attr_out_voltage0_scale_available.dev_attr.attr, - &iio_dev_attr_out_voltage0_freq_start.dev_attr.attr, - &iio_dev_attr_out_voltage0_freq_increment.dev_attr.attr, - &iio_dev_attr_out_voltage0_freq_points.dev_attr.attr, - &iio_dev_attr_out_voltage0_settling_cycles.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_raw.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_scale_available.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_start.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_increment.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_points.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_settling_cycles.dev_attr.attr, &iio_dev_attr_in_voltage0_scale.dev_attr.attr, &iio_dev_attr_in_voltage0_scale_available.dev_attr.attr, NULL @@ -571,7 +572,8 @@ static int ad5933_ring_postenable(struct iio_dev *indio_dev) { struct ad5933_state *st = iio_priv(indio_dev); - /* AD5933_CTRL_INIT_START_FREQ: + /* + * AD5933_CTRL_INIT_START_FREQ: * High Q complex circuits require a long time to reach steady state. * To facilitate the measurement of such impedances, this mode allows * the user full control of the settling time requirement before @@ -662,7 +664,8 @@ static void ad5933_work(struct work_struct *work) } if (status & AD5933_STAT_SWEEP_DONE) { - /* last sample received - power down do + /* + * last sample received - power down do * nothing until the ring enable is toggled */ ad5933_cmd(st, AD5933_CTRL_POWER_DOWN); |