diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-09-22 09:45:11 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-09-22 09:45:11 +0200 |
commit | b290f902b857d75a5eaeb0aa8d0a12fbc8312699 (patch) | |
tree | f7c9b88995750ca5adb25fc9dc25ea046df785e7 /drivers/iio/proximity | |
parent | Revert "staging: rtl8192e: fix kconfig dependency warning for RTLLIB_CRYPTO_WEP" (diff) | |
parent | dt-bindings: iio: vishay,vcnl4000: add interrupts property (diff) | |
download | linux-b290f902b857d75a5eaeb0aa8d0a12fbc8312699.tar.xz linux-b290f902b857d75a5eaeb0aa8d0a12fbc8312699.zip |
Merge tag 'iio-for-5.10b-take2' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
Second set of features and cleanups for IIO in 5.10
We have a couple of changes that apply to large sets of drivers, so
I have grouped those to keep this short.
There are a few late breaking fixes in here that can wait for the
merge window.
dt yaml conversions
-------------------
* adi,ad7768-1
* adi,ad7949
* aspeed,ast2400
* cosmic,10001-adc
* dlg,da9150-gpadc
* fsl,imx25-gcq
* fsl,imx7d-adc
* fsl,vf610
* holt,hi8435
* marvell,berlin2-adc
* motorola,cpcap-adc
* nuvoton,nau7802
* nuvoton,npcm750-adc
* nxp,lpc1850-adc
* nxp,lpc3220
* sprd,sc2720-adc
* st,stmpe-adc
* ti,adc12138
* ti,ads1015
* ti,ads7950
* ti,twl4030-madc
Features
--------
* adxrs290
- Add triggered buffer support and expose data ready signal as a possible
trigger. Includes updating bindings.
- Add debugfs hooks for register access.
* mlx90632
- Add a clear user interface to override the measured ambient temperature.
* vl53l0x
- Add IRQ support including dt bindings.
Cleanups and minor fixes
------------------------
(groups)
Replace mlock with local lock:
* adf4350
* exynos-adc
* fls-imx25-gcq
* stm32-dac
devm use to simplify probe error handling and remove functions.
* adis16201
* adis16203
* adis16209
* adis16240
* adis16136
* adis16260
* adis16400
* adis16460
* adis16480
* adis library - drop unused adis_setup_buffer_and_trigger()
of_match_ptr removal and incorrect ACPI binding removal
of_match_ptr() rarely makes sense in an IIO driver as space saving
is trivial and it breaks ACPI PRP0001 based instantiation.
Mostly this series is about removing examples that get copied into new
drivers.
* ad2s1200
* ad5272
* ad5446
* ad5592r
* ad5593r
* ad5703
* ak8974
* ak8975
* ams-iaq-core
* as3935
* atlas-sensor
* ds1803
* hdc100x
* htu21
* icp10100
* lmp91000
* pulsedlight
* max30102
* max5432
* max5481
* mcp4018
* mcp4131
* mcp4531
* mcp4725
* ms5611
* ms5637
* si7020
* sgp30
* ti-dac082s085
* ti-dac5571
* tmp007
* tsys01
* vz89x
* zpa2326
kernel-doc fixes
* iio-core
* ad7303
* ad7947
* adis16080
* adis16400
* iio_dummy_evgen
* sgp30
Fixes for buffer alignment when passed to iio_push_to_buffers_with_timestamp()
This is a long running effort. There are a few more drivers to come.
* inv_mpu6050
* itg3200
* si1145
* st_lsm6dsx
* ti-adc0832
* ti-adc12138
(not driver focused)
* MAINTAINERS
- Consolidate Analog Device IIO entries whilst removing Beniamin Bia.
- Remove Hartmut Knaack as a listed IIO maintainer as he hasn't been
active for a long time and people are getting intermitted bounces.
* Add __printf() markings to a few functions that were missing them.
* drop some rotted documentation from staging.
* rework buffer sysfs file creation (precursor to multiple buffer support)
(individual drivers)
* ad5592r
- Fix use of true for IIO_SHARED_BY_TYPE
- Tidy up locking and indentation.
* ad9467
- Improve error message on chip-id missmatch.
- Use more appropriate error value if chip-id not recognised.
* adis-library
- Simplify burst mode handling.
* adxrs290
- Make sure to switch device to standby mode during remove.
* as73211
- Increase measurement timeout as seems some devices are slower.
* bma180
- Fix use of true fo IIO_SHARED_BY_TYPE
* exynos_adc
- Update binding to require second interrut with touch screen.
- Update binding to not require syscon on S5Pv210
* hmc5843
- Fix use of true for IIO_SHARED_BY_TYPE
* inv_mpu6050
- Use regmap_noinc_read() for fifo reading.
* palmas_gpadc
- Use module_platform_driver() to remove boilerplate.
* meson-saradc
- style consistency fixes
* rockchip_saradc
- Allow compile testing with !ARM.
* st_lsm6dsx
- Changing scaling factor to use IIO_VAL_INT_PLUS_NANO to improve precision.
- Fix an issue with unchecked return value.
* stm32-adc
- Fix a missing return introduced in dev_err_probe() patch earlier in
cycle.
* sx9310
- Prefer async mode for probe as paticularly slow startup.
* vcnl4000
- Add missing interrupt property to dt binding.
* tag 'iio-for-5.10b-take2' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (126 commits)
dt-bindings: iio: vishay,vcnl4000: add interrupts property
iio:imu:inv_mpu6050: Use regmap_noinc_read for fifo reads.
iio:imu:inv_mpu6050 Fix dma and ts alignment and data leak issues.
iio:adc:ti-adc12138 Fix alignment issue with timestamp
iio:adc:ti-adc0832 Fix alignment issue with timestamp
iio:imu:st_lsm6dsx Fix alignment and data leak issues
iio:light:si1145: Fix timestamp alignment and prevent data leak.
iio:gyro:itg3200: Fix timestamp alignment and prevent data leak.
iio:imu:st_lsm6dsx: check st_lsm6dsx_shub_read_output return
iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
dt-bindings:iio:adc:holt,hi8435 yaml conversion
dt-bindings:iio:adc:adi,ad7768-1 yaml conversion
dt-bindings:iio:adc:adi,ad7949 yaml conversion
dt-bindings:iio:adc:dlg,da9150-gpadc yaml conversion
dt-bindings:iio:adc:motorola,cpcap-adc yaml conversion
dt-bindings:iio:adc:nxp,lpc3220-adc yaml conversion
dt-bindings:iio:adc:nxp,lpc1850-adc yaml conversion
dt-bindings:iio:adc:fsl,imx25-gcq yaml conversion
dt-bindings:iio:adc:fsl,imx7d-adc yaml conversion
dt-bindings:iio:adc:ti,ads1015 yaml conversion
...
Diffstat (limited to 'drivers/iio/proximity')
-rw-r--r-- | drivers/iio/proximity/as3935.c | 44 | ||||
-rw-r--r-- | drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 3 | ||||
-rw-r--r-- | drivers/iio/proximity/sx9310.c | 7 | ||||
-rw-r--r-- | drivers/iio/proximity/vl53l0x-i2c.c | 104 |
4 files changed, 123 insertions, 35 deletions
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c index c339e7339ec8..b79ada839e01 100644 --- a/drivers/iio/proximity/as3935.c +++ b/drivers/iio/proximity/as3935.c @@ -7,6 +7,7 @@ */ #include <linux/module.h> +#include <linux/mod_devicetable.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/delay.h> @@ -352,19 +353,19 @@ static void as3935_stop_work(void *data) static int as3935_probe(struct spi_device *spi) { + struct device *dev = &spi->dev; struct iio_dev *indio_dev; struct iio_trigger *trig; struct as3935_state *st; - struct device_node *np = spi->dev.of_node; int ret; /* Be sure lightning event interrupt is specified */ if (!spi->irq) { - dev_err(&spi->dev, "unable to get event interrupt\n"); + dev_err(dev, "unable to get event interrupt\n"); return -EINVAL; } - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; @@ -374,27 +375,24 @@ static int as3935_probe(struct spi_device *spi) spi_set_drvdata(spi, indio_dev); mutex_init(&st->lock); - ret = of_property_read_u32(np, + ret = device_property_read_u32(dev, "ams,tuning-capacitor-pf", &st->tune_cap); if (ret) { st->tune_cap = 0; - dev_warn(&spi->dev, - "no tuning-capacitor-pf set, defaulting to %d", + dev_warn(dev, "no tuning-capacitor-pf set, defaulting to %d", st->tune_cap); } if (st->tune_cap > MAX_PF_CAP) { - dev_err(&spi->dev, - "wrong tuning-capacitor-pf setting of %d\n", + dev_err(dev, "wrong tuning-capacitor-pf setting of %d\n", st->tune_cap); return -EINVAL; } - ret = of_property_read_u32(np, + ret = device_property_read_u32(dev, "ams,nflwdth", &st->nflwdth_reg); if (!ret && st->nflwdth_reg > AS3935_NFLWDTH_MASK) { - dev_err(&spi->dev, - "invalid nflwdth setting of %d\n", + dev_err(dev, "invalid nflwdth setting of %d\n", st->nflwdth_reg); return -EINVAL; } @@ -405,7 +403,7 @@ static int as3935_probe(struct spi_device *spi) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &as3935_info; - trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d", + trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id); if (!trig) @@ -417,42 +415,42 @@ static int as3935_probe(struct spi_device *spi) iio_trigger_set_drvdata(trig, indio_dev); trig->ops = &iio_interrupt_trigger_ops; - ret = devm_iio_trigger_register(&spi->dev, trig); + ret = devm_iio_trigger_register(dev, trig); if (ret) { - dev_err(&spi->dev, "failed to register trigger\n"); + dev_err(dev, "failed to register trigger\n"); return ret; } - ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, as3935_trigger_handler, NULL); if (ret) { - dev_err(&spi->dev, "cannot setup iio trigger\n"); + dev_err(dev, "cannot setup iio trigger\n"); return ret; } calibrate_as3935(st); INIT_DELAYED_WORK(&st->work, as3935_event_work); - ret = devm_add_action(&spi->dev, as3935_stop_work, indio_dev); + ret = devm_add_action(dev, as3935_stop_work, indio_dev); if (ret) return ret; - ret = devm_request_irq(&spi->dev, spi->irq, + ret = devm_request_irq(dev, spi->irq, &as3935_interrupt_handler, IRQF_TRIGGER_RISING, - dev_name(&spi->dev), + dev_name(dev), indio_dev); if (ret) { - dev_err(&spi->dev, "unable to request irq\n"); + dev_err(dev, "unable to request irq\n"); return ret; } - ret = devm_iio_device_register(&spi->dev, indio_dev); + ret = devm_iio_device_register(dev, indio_dev); if (ret < 0) { - dev_err(&spi->dev, "unable to register device\n"); + dev_err(dev, "unable to register device\n"); return ret; } return 0; @@ -473,7 +471,7 @@ MODULE_DEVICE_TABLE(spi, as3935_id); static struct spi_driver as3935_driver = { .driver = { .name = "as3935", - .of_match_table = of_match_ptr(as3935_of_match), + .of_match_table = as3935_of_match, .pm = AS3935_PM_OPS, }, .probe = as3935_probe, diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c index a8e716dbd24e..c685f10b5ae4 100644 --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c @@ -13,6 +13,7 @@ #include <linux/i2c.h> #include <linux/delay.h> #include <linux/module.h> +#include <linux/mod_devicetable.h> #include <linux/pm_runtime.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> @@ -360,7 +361,7 @@ static const struct dev_pm_ops lidar_pm_ops = { static struct i2c_driver lidar_driver = { .driver = { .name = LIDAR_DRV_NAME, - .of_match_table = of_match_ptr(lidar_dt_ids), + .of_match_table = lidar_dt_ids, .pm = &lidar_pm_ops, }, .probe = lidar_probe, diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 9d72d08ab9e7..6d3f4ab8c6b2 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -1056,6 +1056,13 @@ static struct i2c_driver sx9310_driver = { .acpi_match_table = sx9310_acpi_match, .of_match_table = sx9310_of_match, .pm = &sx9310_pm_ops, + + /* + * Lots of i2c transfers in probe + over 200 ms waiting in + * sx9310_init_compensation() mean a slow probe; prefer async + * so we don't delay boot if we're builtin to the kernel. + */ + .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, .probe_new = sx9310_probe, .id_table = sx9310_id, diff --git a/drivers/iio/proximity/vl53l0x-i2c.c b/drivers/iio/proximity/vl53l0x-i2c.c index 5fbda9475ba9..235e125aeb3a 100644 --- a/drivers/iio/proximity/vl53l0x-i2c.c +++ b/drivers/iio/proximity/vl53l0x-i2c.c @@ -4,18 +4,19 @@ * * Copyright (C) 2016 STMicroelectronics Imaging Division. * Copyright (C) 2018 Song Qiang <songqiang1304521@gmail.com> + * Copyright (C) 2020 Ivan Drobyshevskyi <drobyshevskyi@gmail.com> * * Datasheet available at * <https://www.st.com/resource/en/datasheet/vl53l0x.pdf> * * Default 7-bit i2c slave address 0x29. * - * TODO: FIFO buffer, continuous mode, interrupts, range selection, - * sensor ID check. + * TODO: FIFO buffer, continuous mode, range selection, sensor ID check. */ #include <linux/delay.h> #include <linux/i2c.h> +#include <linux/interrupt.h> #include <linux/module.h> #include <linux/iio/iio.h> @@ -29,14 +30,72 @@ #define VL_REG_SYSRANGE_MODE_TIMED BIT(2) #define VL_REG_SYSRANGE_MODE_HISTOGRAM BIT(3) +#define VL_REG_SYSTEM_INTERRUPT_CONFIG_GPIO 0x0A +#define VL_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY BIT(2) + +#define VL_REG_SYSTEM_INTERRUPT_CLEAR 0x0B + #define VL_REG_RESULT_INT_STATUS 0x13 #define VL_REG_RESULT_RANGE_STATUS 0x14 #define VL_REG_RESULT_RANGE_STATUS_COMPLETE BIT(0) struct vl53l0x_data { struct i2c_client *client; + struct completion completion; }; +static irqreturn_t vl53l0x_handle_irq(int irq, void *priv) +{ + struct iio_dev *indio_dev = priv; + struct vl53l0x_data *data = iio_priv(indio_dev); + + complete(&data->completion); + + return IRQ_HANDLED; +} + +static int vl53l0x_configure_irq(struct i2c_client *client, + struct iio_dev *indio_dev) +{ + struct vl53l0x_data *data = iio_priv(indio_dev); + int ret; + + ret = devm_request_irq(&client->dev, client->irq, vl53l0x_handle_irq, + IRQF_TRIGGER_FALLING, indio_dev->name, indio_dev); + if (ret) { + dev_err(&client->dev, "devm_request_irq error: %d\n", ret); + return ret; + } + + ret = i2c_smbus_write_byte_data(data->client, + VL_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, + VL_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY); + if (ret < 0) + dev_err(&client->dev, "failed to configure IRQ: %d\n", ret); + + return ret; +} + +static void vl53l0x_clear_irq(struct vl53l0x_data *data) +{ + struct device *dev = &data->client->dev; + int ret; + + ret = i2c_smbus_write_byte_data(data->client, + VL_REG_SYSTEM_INTERRUPT_CLEAR, 1); + if (ret < 0) + dev_err(dev, "failed to clear error irq: %d\n", ret); + + ret = i2c_smbus_write_byte_data(data->client, + VL_REG_SYSTEM_INTERRUPT_CLEAR, 0); + if (ret < 0) + dev_err(dev, "failed to clear range irq: %d\n", ret); + + ret = i2c_smbus_read_byte_data(data->client, VL_REG_RESULT_INT_STATUS); + if (ret < 0 || ret & 0x07) + dev_err(dev, "failed to clear irq: %d\n", ret); +} + static int vl53l0x_read_proximity(struct vl53l0x_data *data, const struct iio_chan_spec *chan, int *val) @@ -50,19 +109,31 @@ static int vl53l0x_read_proximity(struct vl53l0x_data *data, if (ret < 0) return ret; - do { - ret = i2c_smbus_read_byte_data(client, - VL_REG_RESULT_RANGE_STATUS); + if (data->client->irq) { + reinit_completion(&data->completion); + + ret = wait_for_completion_timeout(&data->completion, HZ/10); if (ret < 0) return ret; + else if (ret == 0) + return -ETIMEDOUT; - if (ret & VL_REG_RESULT_RANGE_STATUS_COMPLETE) - break; + vl53l0x_clear_irq(data); + } else { + do { + ret = i2c_smbus_read_byte_data(client, + VL_REG_RESULT_RANGE_STATUS); + if (ret < 0) + return ret; - usleep_range(1000, 5000); - } while (--tries); - if (!tries) - return -ETIMEDOUT; + if (ret & VL_REG_RESULT_RANGE_STATUS_COMPLETE) + break; + + usleep_range(1000, 5000); + } while (--tries); + if (!tries) + return -ETIMEDOUT; + } ret = i2c_smbus_read_i2c_block_data(client, VL_REG_RESULT_RANGE_STATUS, 12, buffer); @@ -140,6 +211,17 @@ static int vl53l0x_probe(struct i2c_client *client) indio_dev->num_channels = ARRAY_SIZE(vl53l0x_channels); indio_dev->modes = INDIO_DIRECT_MODE; + /* usage of interrupt is optional */ + if (client->irq) { + int ret; + + init_completion(&data->completion); + + ret = vl53l0x_configure_irq(client, indio_dev); + if (ret) + return ret; + } + return devm_iio_device_register(&client->dev, indio_dev); } |