From 8b2ac51625ac96afd488d3ddd90c95c3417eb736 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Wed, 30 Jun 2021 15:30:29 +0300 Subject: [PATCH 01/77] iio: hid-sensors: bind IIO channels alloc to device object Some HID drivers use devm_kmemdup() already to clone the template IIO channels information and update it. However, there are still some drivers that kmemdup() and kfree() the channels. This change converts them to use devm_kmemdup() and bind the life-time of this allocated object to the parent device object (in these drivers). Signed-off-by: Alexandru Ardelean Acked-by: Srinivas Pandruvada Link: https://lore.kernel.org/r/20210630123029.759609-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/hid-sensor-accel-3d.c | 10 ++++------ drivers/iio/gyro/hid-sensor-gyro-3d.c | 11 ++++------- drivers/iio/light/hid-sensor-als.c | 11 ++++------- drivers/iio/light/hid-sensor-prox.c | 11 ++++------- drivers/iio/orientation/hid-sensor-incl-3d.c | 11 ++++------- drivers/iio/pressure/hid-sensor-press.c | 11 ++++------- 6 files changed, 24 insertions(+), 41 deletions(-) diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index 55cdca818b3b..a2def6f9380a 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -367,7 +367,8 @@ static int hid_accel_3d_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to setup common attributes\n"); return ret; } - indio_dev->channels = kmemdup(channel_spec, channel_size, GFP_KERNEL); + indio_dev->channels = devm_kmemdup(&pdev->dev, channel_spec, + channel_size, GFP_KERNEL); if (!indio_dev->channels) { dev_err(&pdev->dev, "failed to duplicate channels\n"); @@ -378,7 +379,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev) hsdev->usage, accel_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); - goto error_free_dev_mem; + return ret; } indio_dev->info = &accel_3d_info; @@ -391,7 +392,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev) &accel_state->common_attributes); if (ret < 0) { dev_err(&pdev->dev, "trigger setup failed\n"); - goto error_free_dev_mem; + return ret; } ret = iio_device_register(indio_dev); @@ -416,8 +417,6 @@ error_iio_unreg: iio_device_unregister(indio_dev); error_remove_trigger: hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes); -error_free_dev_mem: - kfree(indio_dev->channels); return ret; } @@ -431,7 +430,6 @@ static int hid_accel_3d_remove(struct platform_device *pdev) sensor_hub_remove_callback(hsdev, hsdev->usage); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes); - kfree(indio_dev->channels); return 0; } diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index bc63c2a34c5e..8f0ad022c7f1 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c @@ -303,8 +303,8 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) return ret; } - indio_dev->channels = kmemdup(gyro_3d_channels, - sizeof(gyro_3d_channels), GFP_KERNEL); + indio_dev->channels = devm_kmemdup(&pdev->dev, gyro_3d_channels, + sizeof(gyro_3d_channels), GFP_KERNEL); if (!indio_dev->channels) { dev_err(&pdev->dev, "failed to duplicate channels\n"); return -ENOMEM; @@ -315,7 +315,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) HID_USAGE_SENSOR_GYRO_3D, gyro_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); - goto error_free_dev_mem; + return ret; } indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels); @@ -329,7 +329,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) &gyro_state->common_attributes); if (ret < 0) { dev_err(&pdev->dev, "trigger setup failed\n"); - goto error_free_dev_mem; + return ret; } ret = iio_device_register(indio_dev); @@ -354,8 +354,6 @@ error_iio_unreg: iio_device_unregister(indio_dev); error_remove_trigger: hid_sensor_remove_trigger(indio_dev, &gyro_state->common_attributes); -error_free_dev_mem: - kfree(indio_dev->channels); return ret; } @@ -369,7 +367,6 @@ static int hid_gyro_3d_remove(struct platform_device *pdev) sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_GYRO_3D); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &gyro_state->common_attributes); - kfree(indio_dev->channels); return 0; } diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 2ff252c75c03..5a1a625d8d16 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -294,8 +294,8 @@ static int hid_als_probe(struct platform_device *pdev) return ret; } - indio_dev->channels = kmemdup(als_channels, - sizeof(als_channels), GFP_KERNEL); + indio_dev->channels = devm_kmemdup(&pdev->dev, als_channels, + sizeof(als_channels), GFP_KERNEL); if (!indio_dev->channels) { dev_err(&pdev->dev, "failed to duplicate channels\n"); return -ENOMEM; @@ -306,7 +306,7 @@ static int hid_als_probe(struct platform_device *pdev) HID_USAGE_SENSOR_ALS, als_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); - goto error_free_dev_mem; + return ret; } indio_dev->num_channels = @@ -321,7 +321,7 @@ static int hid_als_probe(struct platform_device *pdev) &als_state->common_attributes); if (ret < 0) { dev_err(&pdev->dev, "trigger setup failed\n"); - goto error_free_dev_mem; + return ret; } ret = iio_device_register(indio_dev); @@ -346,8 +346,6 @@ error_iio_unreg: iio_device_unregister(indio_dev); error_remove_trigger: hid_sensor_remove_trigger(indio_dev, &als_state->common_attributes); -error_free_dev_mem: - kfree(indio_dev->channels); return ret; } @@ -361,7 +359,6 @@ static int hid_als_remove(struct platform_device *pdev) sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &als_state->common_attributes); - kfree(indio_dev->channels); return 0; } diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index 1621530f5f61..f10fa2abfe72 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -253,8 +253,8 @@ static int hid_prox_probe(struct platform_device *pdev) return ret; } - indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels), - GFP_KERNEL); + indio_dev->channels = devm_kmemdup(&pdev->dev, prox_channels, + sizeof(prox_channels), GFP_KERNEL); if (!indio_dev->channels) { dev_err(&pdev->dev, "failed to duplicate channels\n"); return -ENOMEM; @@ -265,7 +265,7 @@ static int hid_prox_probe(struct platform_device *pdev) HID_USAGE_SENSOR_PROX, prox_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); - goto error_free_dev_mem; + return ret; } indio_dev->num_channels = ARRAY_SIZE(prox_channels); @@ -279,7 +279,7 @@ static int hid_prox_probe(struct platform_device *pdev) &prox_state->common_attributes); if (ret) { dev_err(&pdev->dev, "trigger setup failed\n"); - goto error_free_dev_mem; + return ret; } ret = iio_device_register(indio_dev); @@ -304,8 +304,6 @@ error_iio_unreg: iio_device_unregister(indio_dev); error_remove_trigger: hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes); -error_free_dev_mem: - kfree(indio_dev->channels); return ret; } @@ -319,7 +317,6 @@ static int hid_prox_remove(struct platform_device *pdev) sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PROX); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes); - kfree(indio_dev->channels); return 0; } diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c index c0079e2c8807..ba5b581d5b25 100644 --- a/drivers/iio/orientation/hid-sensor-incl-3d.c +++ b/drivers/iio/orientation/hid-sensor-incl-3d.c @@ -326,8 +326,8 @@ static int hid_incl_3d_probe(struct platform_device *pdev) return ret; } - indio_dev->channels = kmemdup(incl_3d_channels, - sizeof(incl_3d_channels), GFP_KERNEL); + indio_dev->channels = devm_kmemdup(&pdev->dev, incl_3d_channels, + sizeof(incl_3d_channels), GFP_KERNEL); if (!indio_dev->channels) { dev_err(&pdev->dev, "failed to duplicate channels\n"); return -ENOMEM; @@ -339,7 +339,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev) incl_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); - goto error_free_dev_mem; + return ret; } indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels); @@ -353,7 +353,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev) &incl_state->common_attributes); if (ret) { dev_err(&pdev->dev, "trigger setup failed\n"); - goto error_free_dev_mem; + return ret; } ret = iio_device_register(indio_dev); @@ -379,8 +379,6 @@ error_iio_unreg: iio_device_unregister(indio_dev); error_remove_trigger: hid_sensor_remove_trigger(indio_dev, &incl_state->common_attributes); -error_free_dev_mem: - kfree(indio_dev->channels); return ret; } @@ -394,7 +392,6 @@ static int hid_incl_3d_remove(struct platform_device *pdev) sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_INCLINOMETER_3D); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &incl_state->common_attributes); - kfree(indio_dev->channels); return 0; } diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c index 10c52b8df2ba..dcd593c426b4 100644 --- a/drivers/iio/pressure/hid-sensor-press.c +++ b/drivers/iio/pressure/hid-sensor-press.c @@ -259,8 +259,8 @@ static int hid_press_probe(struct platform_device *pdev) return ret; } - indio_dev->channels = kmemdup(press_channels, sizeof(press_channels), - GFP_KERNEL); + indio_dev->channels = devm_kmemdup(&pdev->dev, press_channels, + sizeof(press_channels), GFP_KERNEL); if (!indio_dev->channels) { dev_err(&pdev->dev, "failed to duplicate channels\n"); return -ENOMEM; @@ -271,7 +271,7 @@ static int hid_press_probe(struct platform_device *pdev) HID_USAGE_SENSOR_PRESSURE, press_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); - goto error_free_dev_mem; + return ret; } indio_dev->num_channels = @@ -286,7 +286,7 @@ static int hid_press_probe(struct platform_device *pdev) &press_state->common_attributes); if (ret) { dev_err(&pdev->dev, "trigger setup failed\n"); - goto error_free_dev_mem; + return ret; } ret = iio_device_register(indio_dev); @@ -311,8 +311,6 @@ error_iio_unreg: iio_device_unregister(indio_dev); error_remove_trigger: hid_sensor_remove_trigger(indio_dev, &press_state->common_attributes); -error_free_dev_mem: - kfree(indio_dev->channels); return ret; } @@ -326,7 +324,6 @@ static int hid_press_remove(struct platform_device *pdev) sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PRESSURE); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &press_state->common_attributes); - kfree(indio_dev->channels); return 0; } From 62f9eb7079a91fa19edc14971b38d8737704ef0f Mon Sep 17 00:00:00 2001 From: Jarkko Nikula Date: Tue, 29 Jun 2021 14:16:57 +0300 Subject: [PATCH 02/77] counter: intel-qep: Remove linux/bitops.h include 0-DAY CI Kernel Test Service reported following iwyu warning: drivers/counter/intel-qep.c:11:1: iwyu: warning: superfluous #include Remove that include since we don't seem to use anything from it. Reported-by: kernel test robot Signed-off-by: Jarkko Nikula Acked-by: William Breathitt Gray Link: https://lore.kernel.org/r/20210629111657.2655688-1-jarkko.nikula@linux.intel.com Signed-off-by: Jonathan Cameron --- drivers/counter/intel-qep.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index 8d7ae28fbd67..1a9512e28519 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -8,7 +8,6 @@ * Author: Jarkko Nikula * Author: Raymond Tan */ -#include #include #include #include From 458516508df977efd3ff043d5ff77cad2d8f9d64 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Wed, 14 Jul 2021 13:14:41 +0200 Subject: [PATCH 03/77] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Use 'bitmap_alloc()' instead of 'bitmap_zalloc()' because the bitmap is fully overridden by a 'bitmap_copy()' call just after its allocation. While at it, fix the style of a NULL check. Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/89d8a766eb971eda1ee362444a8711037bdb208c.1626261211.git.christophe.jaillet@wanadoo.fr Signed-off-by: Jonathan Cameron --- drivers/iio/industrialio-buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index fdd623407b96..6d4776a7f002 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -354,8 +354,8 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, const unsigned long *mask; unsigned long *trialmask; - trialmask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL); - if (trialmask == NULL) + trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL); + if (!trialmask) return -ENOMEM; if (!indio_dev->masklength) { WARN(1, "Trying to set scanmask prior to registering buffer\n"); From d21fed0675cd190bf35b9c2e3031c6064531734b Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Wed, 14 Jul 2021 13:14:51 +0200 Subject: [PATCH 04/77] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()' This is more standard to have sanity checks at the entry of a function, instead of allocating some memory first and having to free it if a condition is not met. Shuffle code a bit to check 'masklength' before calling 'bitmap_alloc()' Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/98a351adda1908c306e981b9cc86d3dbc79eb5ec.1626261211.git.christophe.jaillet@wanadoo.fr Signed-off-by: Jonathan Cameron --- drivers/iio/industrialio-buffer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 6d4776a7f002..a95cc2da56be 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -354,13 +354,14 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, const unsigned long *mask; unsigned long *trialmask; + if (!indio_dev->masklength) { + WARN(1, "Trying to set scanmask prior to registering buffer\n"); + return -EINVAL; + } + trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL); if (!trialmask) return -ENOMEM; - if (!indio_dev->masklength) { - WARN(1, "Trying to set scanmask prior to registering buffer\n"); - goto err_invalid_mask; - } bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength); set_bit(bit, trialmask); From edf021d14511e59c4618396ec6f5206c484f89df Mon Sep 17 00:00:00 2001 From: Simon Xue Date: Mon, 12 Jul 2021 09:44:37 +0800 Subject: [PATCH 05/77] dt-bindings: iio: adc: rockchip-saradc: add description for rk3568 Add description for rk3568 saradc. Signed-off-by: Simon Xue Reviewed-by: Heiko Stuebner Acked-by: Rob Herring Link: https://lore.kernel.org/r/20210712014437.97427-1-xxm@rock-chips.com Signed-off-by: Jonathan Cameron --- Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml index 1bb76197787b..e512a14e41b4 100644 --- a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml @@ -20,6 +20,7 @@ properties: - rockchip,px30-saradc - rockchip,rk3308-saradc - rockchip,rk3328-saradc + - rockchip,rk3568-saradc - rockchip,rv1108-saradc - const: rockchip,rk3399-saradc From 7786da3b5ae167c17f35e22ba35e06006338c2f6 Mon Sep 17 00:00:00 2001 From: Simon Xue Date: Mon, 12 Jul 2021 09:45:07 +0800 Subject: [PATCH 06/77] iio: adc: rockchip_saradc: add support for rk3568 saradc It is similar to other devices, but with 8 channels. Signed-off-by: Simon Xue Reviewed-by: Heiko Stuebner Link: https://lore.kernel.org/r/20210712014507.97477-1-xxm@rock-chips.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/rockchip_saradc.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c index 12584f1631d8..f3eb8d2e50dc 100644 --- a/drivers/iio/adc/rockchip_saradc.c +++ b/drivers/iio/adc/rockchip_saradc.c @@ -35,7 +35,7 @@ #define SARADC_DLY_PU_SOC_MASK 0x3f #define SARADC_TIMEOUT msecs_to_jiffies(100) -#define SARADC_MAX_CHANNELS 6 +#define SARADC_MAX_CHANNELS 8 struct rockchip_saradc_data { const struct iio_chan_spec *channels; @@ -192,6 +192,23 @@ static const struct rockchip_saradc_data rk3399_saradc_data = { .clk_rate = 1000000, }; +static const struct iio_chan_spec rockchip_rk3568_saradc_iio_channels[] = { + SARADC_CHANNEL(0, "adc0", 10), + SARADC_CHANNEL(1, "adc1", 10), + SARADC_CHANNEL(2, "adc2", 10), + SARADC_CHANNEL(3, "adc3", 10), + SARADC_CHANNEL(4, "adc4", 10), + SARADC_CHANNEL(5, "adc5", 10), + SARADC_CHANNEL(6, "adc6", 10), + SARADC_CHANNEL(7, "adc7", 10), +}; + +static const struct rockchip_saradc_data rk3568_saradc_data = { + .channels = rockchip_rk3568_saradc_iio_channels, + .num_channels = ARRAY_SIZE(rockchip_rk3568_saradc_iio_channels), + .clk_rate = 1000000, +}; + static const struct of_device_id rockchip_saradc_match[] = { { .compatible = "rockchip,saradc", @@ -202,6 +219,9 @@ static const struct of_device_id rockchip_saradc_match[] = { }, { .compatible = "rockchip,rk3399-saradc", .data = &rk3399_saradc_data, + }, { + .compatible = "rockchip,rk3568-saradc", + .data = &rk3568_saradc_data, }, {}, }; From 2427a7e95ca9c72807f5cf57afee093eeccb79d3 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Mon, 5 Jul 2021 10:14:55 +0300 Subject: [PATCH 07/77] iio: light: adjd_s311: move buffer on adjd_s311_data object This change moves the entire buffer on the private adjd_s311_data type. Since the device has 4 channels, it's not a big waste to just allocate the maximum possible buffer and use only what's needed. This is in contrast with free-ing and re-allocating the buffer on the update_scan_mode hook. Since the driver pushes buffer data with iio_push_to_buffers_with_timestamp(), the buffer must also include a 64-bit buffer for the timestamp, for each sample-set. With this change, the adjd_s311_update_scan_mode() is no longer needed. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210705071456.649659-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/light/adjd_s311.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c index 17dac8d0e11d..caf852554897 100644 --- a/drivers/iio/light/adjd_s311.c +++ b/drivers/iio/light/adjd_s311.c @@ -54,7 +54,10 @@ struct adjd_s311_data { struct i2c_client *client; - u16 *buffer; + struct { + s16 chans[4]; + s64 ts __aligned(8); + } scan; }; enum adjd_s311_channel_idx { @@ -129,10 +132,10 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) if (ret < 0) goto done; - data->buffer[j++] = ret & ADJD_S311_DATA_MASK; + data->scan.chans[j++] = ret & ADJD_S311_DATA_MASK; } - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns); + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns); done: iio_trigger_notify_done(indio_dev->trig); @@ -225,23 +228,9 @@ static int adjd_s311_write_raw(struct iio_dev *indio_dev, return -EINVAL; } -static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *scan_mask) -{ - struct adjd_s311_data *data = iio_priv(indio_dev); - - kfree(data->buffer); - data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data->buffer == NULL) - return -ENOMEM; - - return 0; -} - static const struct iio_info adjd_s311_info = { .read_raw = adjd_s311_read_raw, .write_raw = adjd_s311_write_raw, - .update_scan_mode = adjd_s311_update_scan_mode, }; static int adjd_s311_probe(struct i2c_client *client, @@ -286,11 +275,9 @@ exit_unreg_buffer: static int adjd_s311_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct adjd_s311_data *data = iio_priv(indio_dev); iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); - kfree(data->buffer); return 0; } From bb761e722f6dff05b94bdfff8a7209a442f220ff Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Mon, 5 Jul 2021 10:14:56 +0300 Subject: [PATCH 08/77] iio: light: adjd_s311: convert probe to device-managed functions Now that the driver's buffer is stored on the adjd_s311_data private object, the driver is a simple conversion to use only device-managed functions in the probe. The iio_triggered_buffer_setup() and iio_device_register() functions are the only ones needing conversion. And i2c_set_clientdata() is no longer required. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210705071456.649659-2-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/light/adjd_s311.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c index caf852554897..6b33975c8d73 100644 --- a/drivers/iio/light/adjd_s311.c +++ b/drivers/iio/light/adjd_s311.c @@ -245,7 +245,6 @@ static int adjd_s311_probe(struct i2c_client *client, return -ENOMEM; data = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); data->client = client; indio_dev->info = &adjd_s311_info; @@ -254,32 +253,12 @@ static int adjd_s311_probe(struct i2c_client *client, indio_dev->num_channels = ARRAY_SIZE(adjd_s311_channels); indio_dev->modes = INDIO_DIRECT_MODE; - err = iio_triggered_buffer_setup(indio_dev, NULL, - adjd_s311_trigger_handler, NULL); + err = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, + adjd_s311_trigger_handler, NULL); if (err < 0) return err; - err = iio_device_register(indio_dev); - if (err) - goto exit_unreg_buffer; - - dev_info(&client->dev, "ADJD-S311 color sensor registered\n"); - - return 0; - -exit_unreg_buffer: - iio_triggered_buffer_cleanup(indio_dev); - return err; -} - -static int adjd_s311_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } static const struct i2c_device_id adjd_s311_id[] = { @@ -293,7 +272,6 @@ static struct i2c_driver adjd_s311_driver = { .name = ADJD_S311_DRV_NAME, }, .probe = adjd_s311_probe, - .remove = adjd_s311_remove, .id_table = adjd_s311_id, }; module_i2c_driver(adjd_s311_driver); From 09d5135b6ffcb243580a4a77f299a0253a94f5e3 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Wed, 30 Jun 2021 16:16:35 +0300 Subject: [PATCH 09/77] iio: proximity: rfd77402: use i2c_client for rfd77402_{init,powerdown}() These 2 functions only do I2C reads/writes and don't require any of the private data of the driver. They're also used in the PM suspend/resume part of the driver. Converting them to take an i2c_client object as parameter simplifies things a bit (especially in the suspend/resume) as the driver mostly needs the reference for i2c_client, so no need to jump through hoops to get it from the private data (as was done in many places). The rfd77402_measure() function has also been converted to take an i2c_client object, since it also does only I2C ops. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210630131636.1563148-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/rfd77402.c | 60 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c index 7a0472323f17..f349526421f3 100644 --- a/drivers/iio/proximity/rfd77402.c +++ b/drivers/iio/proximity/rfd77402.c @@ -90,18 +90,18 @@ static const struct iio_chan_spec rfd77402_channels[] = { }, }; -static int rfd77402_set_state(struct rfd77402_data *data, u8 state, u16 check) +static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 check) { int ret; - ret = i2c_smbus_write_byte_data(data->client, RFD77402_CMD_R, + ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R, state | RFD77402_CMD_VALID); if (ret < 0) return ret; usleep_range(10000, 20000); - ret = i2c_smbus_read_word_data(data->client, RFD77402_STATUS_R); + ret = i2c_smbus_read_word_data(client, RFD77402_STATUS_R); if (ret < 0) return ret; if ((ret & RFD77402_STATUS_PM_MASK) != check) @@ -110,24 +110,24 @@ static int rfd77402_set_state(struct rfd77402_data *data, u8 state, u16 check) return 0; } -static int rfd77402_measure(struct rfd77402_data *data) +static int rfd77402_measure(struct i2c_client *client) { int ret; int tries = 10; - ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_ON, + ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON, RFD77402_STATUS_MCPU_ON); if (ret < 0) return ret; - ret = i2c_smbus_write_byte_data(data->client, RFD77402_CMD_R, + ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R, RFD77402_CMD_SINGLE | RFD77402_CMD_VALID); if (ret < 0) goto err; while (tries-- > 0) { - ret = i2c_smbus_read_byte_data(data->client, RFD77402_ICSR); + ret = i2c_smbus_read_byte_data(client, RFD77402_ICSR); if (ret < 0) goto err; if (ret & RFD77402_ICSR_RESULT) @@ -140,7 +140,7 @@ static int rfd77402_measure(struct rfd77402_data *data) goto err; } - ret = i2c_smbus_read_word_data(data->client, RFD77402_RESULT_R); + ret = i2c_smbus_read_word_data(client, RFD77402_RESULT_R); if (ret < 0) goto err; @@ -153,7 +153,7 @@ static int rfd77402_measure(struct rfd77402_data *data) return (ret & RFD77402_RESULT_DIST_MASK) >> 2; err: - rfd77402_set_state(data, RFD77402_CMD_MCPU_OFF, + rfd77402_set_state(client, RFD77402_CMD_MCPU_OFF, RFD77402_STATUS_MCPU_OFF); return ret; } @@ -168,7 +168,7 @@ static int rfd77402_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: mutex_lock(&data->lock); - ret = rfd77402_measure(data); + ret = rfd77402_measure(data->client); mutex_unlock(&data->lock); if (ret < 0) return ret; @@ -188,23 +188,23 @@ static const struct iio_info rfd77402_info = { .read_raw = rfd77402_read_raw, }; -static int rfd77402_init(struct rfd77402_data *data) +static int rfd77402_init(struct i2c_client *client) { int ret, i; - ret = rfd77402_set_state(data, RFD77402_CMD_STANDBY, + ret = rfd77402_set_state(client, RFD77402_CMD_STANDBY, RFD77402_STATUS_STANDBY); if (ret < 0) return ret; /* configure INT pad as push-pull, active low */ - ret = i2c_smbus_write_byte_data(data->client, RFD77402_ICSR, + ret = i2c_smbus_write_byte_data(client, RFD77402_ICSR, RFD77402_ICSR_INT_MODE); if (ret < 0) return ret; /* I2C configuration */ - ret = i2c_smbus_write_word_data(data->client, RFD77402_I2C_INIT_CFG, + ret = i2c_smbus_write_word_data(client, RFD77402_I2C_INIT_CFG, RFD77402_I2C_ADDR_INCR | RFD77402_I2C_DATA_INCR | RFD77402_I2C_HOST_DEBUG | @@ -213,42 +213,42 @@ static int rfd77402_init(struct rfd77402_data *data) return ret; /* set initialization */ - ret = i2c_smbus_write_word_data(data->client, RFD77402_PMU_CFG, 0x0500); + ret = i2c_smbus_write_word_data(client, RFD77402_PMU_CFG, 0x0500); if (ret < 0) return ret; - ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_OFF, + ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_OFF, RFD77402_STATUS_MCPU_OFF); if (ret < 0) return ret; /* set initialization */ - ret = i2c_smbus_write_word_data(data->client, RFD77402_PMU_CFG, 0x0600); + ret = i2c_smbus_write_word_data(client, RFD77402_PMU_CFG, 0x0600); if (ret < 0) return ret; - ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_ON, + ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON, RFD77402_STATUS_MCPU_ON); if (ret < 0) return ret; for (i = 0; i < ARRAY_SIZE(rf77402_tof_config); i++) { - ret = i2c_smbus_write_word_data(data->client, + ret = i2c_smbus_write_word_data(client, rf77402_tof_config[i].reg, rf77402_tof_config[i].val); if (ret < 0) return ret; } - ret = rfd77402_set_state(data, RFD77402_CMD_STANDBY, + ret = rfd77402_set_state(client, RFD77402_CMD_STANDBY, RFD77402_STATUS_STANDBY); return ret; } -static int rfd77402_powerdown(struct rfd77402_data *data) +static int rfd77402_powerdown(struct i2c_client *client) { - return rfd77402_set_state(data, RFD77402_CMD_STANDBY, + return rfd77402_set_state(client, RFD77402_CMD_STANDBY, RFD77402_STATUS_STANDBY); } @@ -280,7 +280,7 @@ static int rfd77402_probe(struct i2c_client *client, indio_dev->name = RFD77402_DRV_NAME; indio_dev->modes = INDIO_DIRECT_MODE; - ret = rfd77402_init(data); + ret = rfd77402_init(client); if (ret < 0) return ret; @@ -291,7 +291,7 @@ static int rfd77402_probe(struct i2c_client *client, return 0; err_powerdown: - rfd77402_powerdown(data); + rfd77402_powerdown(client); return ret; } @@ -300,7 +300,7 @@ static int rfd77402_remove(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); iio_device_unregister(indio_dev); - rfd77402_powerdown(iio_priv(indio_dev)); + rfd77402_powerdown(client); return 0; } @@ -308,18 +308,12 @@ static int rfd77402_remove(struct i2c_client *client) #ifdef CONFIG_PM_SLEEP static int rfd77402_suspend(struct device *dev) { - struct rfd77402_data *data = iio_priv(i2c_get_clientdata( - to_i2c_client(dev))); - - return rfd77402_powerdown(data); + return rfd77402_powerdown(to_i2c_client(dev)); } static int rfd77402_resume(struct device *dev) { - struct rfd77402_data *data = iio_priv(i2c_get_clientdata( - to_i2c_client(dev))); - - return rfd77402_init(data); + return rfd77402_init(to_i2c_client(dev)); } #endif From 148da125a0c825aa1576602391d6eece6568226f Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Wed, 30 Jun 2021 16:16:36 +0300 Subject: [PATCH 10/77] iio: proximity: rfd77402: convert probe to device-managed functions This change converts the probe hook to register the IIO device with devm_iio_device_register() and register a hook with devm_add_action_or_reset() to put the device in powerdown when the driver gets unloaded. Since the PM suspend/resume functions need only a reference to the i2c_client object (which can be obtained from the base device object), the i2c_set_clientdata() call can be removed. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210630131636.1563148-2-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/rfd77402.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c index f349526421f3..8c06d02139b6 100644 --- a/drivers/iio/proximity/rfd77402.c +++ b/drivers/iio/proximity/rfd77402.c @@ -252,6 +252,11 @@ static int rfd77402_powerdown(struct i2c_client *client) RFD77402_STATUS_STANDBY); } +static void rfd77402_disable(void *client) +{ + rfd77402_powerdown(client); +} + static int rfd77402_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -270,7 +275,6 @@ static int rfd77402_probe(struct i2c_client *client, return -ENOMEM; data = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); data->client = client; mutex_init(&data->lock); @@ -284,25 +288,11 @@ static int rfd77402_probe(struct i2c_client *client, if (ret < 0) return ret; - ret = iio_device_register(indio_dev); + ret = devm_add_action_or_reset(&client->dev, rfd77402_disable, client); if (ret) - goto err_powerdown; + return ret; - return 0; - -err_powerdown: - rfd77402_powerdown(client); - return ret; -} - -static int rfd77402_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - rfd77402_powerdown(client); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -331,7 +321,6 @@ static struct i2c_driver rfd77402_driver = { .pm = &rfd77402_pm_ops, }, .probe = rfd77402_probe, - .remove = rfd77402_remove, .id_table = rfd77402_id, }; From 689f584b9858393809dc28046a7b51f9535d913d Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Wed, 30 Jun 2021 15:15:09 +0300 Subject: [PATCH 11/77] iio: accel: dmard10: convert probe to device-managed functions This is another simple conversion to device-managed functions, requiring the use of devm_iio_device_register() and moving the disabling of the device on a devm_add_action_or_reset() hook. The i2c_set_clientdata() can be removed, as the PM functions can work with just the device object, to obtain the i2c_client object. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210630121509.653717-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/dmard10.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/iio/accel/dmard10.c b/drivers/iio/accel/dmard10.c index e84bf8db1e89..f9f173eec202 100644 --- a/drivers/iio/accel/dmard10.c +++ b/drivers/iio/accel/dmard10.c @@ -170,6 +170,11 @@ static const struct iio_info dmard10_info = { .read_raw = dmard10_read_raw, }; +static void dmard10_shutdown_cleanup(void *client) +{ + dmard10_shutdown(client); +} + static int dmard10_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -194,7 +199,6 @@ static int dmard10_probe(struct i2c_client *client, data = iio_priv(indio_dev); data->client = client; - i2c_set_clientdata(client, indio_dev); indio_dev->info = &dmard10_info; indio_dev->name = "dmard10"; @@ -206,22 +210,12 @@ static int dmard10_probe(struct i2c_client *client, if (ret < 0) return ret; - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "device_register failed\n"); - dmard10_shutdown(client); - } + ret = devm_add_action_or_reset(&client->dev, dmard10_shutdown_cleanup, + client); + if (ret) + return ret; - return ret; -} - -static int dmard10_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - - return dmard10_shutdown(client); + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -250,7 +244,6 @@ static struct i2c_driver dmard10_driver = { .pm = &dmard10_pm_ops, }, .probe = dmard10_probe, - .remove = dmard10_remove, .id_table = dmard10_i2c_id, }; From 074e1ddb87825c36ca3771ffbab23fee9204a82a Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Wed, 30 Jun 2021 15:03:38 +0300 Subject: [PATCH 12/77] iio: accel: da311: convert probe to device-managed functions This is another simple conversion to device-managed functions, requiring the use of devm_iio_device_register() and moving the disabling of the device on a devm_add_action_or_reset() hook. The i2c_set_clientdata() can be removed, as the PM functions can work with just the device object, to obtain the i2c_client object. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210630120338.482426-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/da311.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/iio/accel/da311.c b/drivers/iio/accel/da311.c index 92593a1cd1aa..04e13487e706 100644 --- a/drivers/iio/accel/da311.c +++ b/drivers/iio/accel/da311.c @@ -212,6 +212,11 @@ static const struct iio_info da311_info = { .read_raw = da311_read_raw, }; +static void da311_disable(void *client) +{ + da311_enable(client, false); +} + static int da311_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -229,7 +234,6 @@ static int da311_probe(struct i2c_client *client, data = iio_priv(indio_dev); data->client = client; - i2c_set_clientdata(client, indio_dev); indio_dev->info = &da311_info; indio_dev->name = "da311"; @@ -245,22 +249,11 @@ static int da311_probe(struct i2c_client *client, if (ret < 0) return ret; - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "device_register failed\n"); - da311_enable(client, false); - } + ret = devm_add_action_or_reset(&client->dev, da311_disable, client); + if (ret) + return ret; - return ret; -} - -static int da311_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - - return da311_enable(client, false); + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -289,7 +282,6 @@ static struct i2c_driver da311_driver = { .pm = &da311_pm_ops, }, .probe = da311_probe, - .remove = da311_remove, .id_table = da311_i2c_id, }; From 3d9efa9bd34f20d16251ad5d41fb42d27adb6b74 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Mon, 28 Jun 2021 17:17:09 +0300 Subject: [PATCH 13/77] iio: accel: da280: convert probe to device-managed functions This is another simple conversion to device-managed functions, requiring the use of devm_iio_device_register() and moving the disabling of the device on a devm_add_action_or_reset() hook. The i2c_set_clientdata() can be removed, as the PM functions can work with just the device object, to obtain the i2c_client object. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210628141709.80534-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/da280.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/iio/accel/da280.c b/drivers/iio/accel/da280.c index 5edff9ba72da..9633bdae5fd4 100644 --- a/drivers/iio/accel/da280.c +++ b/drivers/iio/accel/da280.c @@ -100,6 +100,11 @@ static enum da280_chipset da280_match_acpi_device(struct device *dev) return (enum da280_chipset) id->driver_data; } +static void da280_disable(void *client) +{ + da280_enable(client, false); +} + static int da280_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -118,7 +123,6 @@ static int da280_probe(struct i2c_client *client, data = iio_priv(indio_dev); data->client = client; - i2c_set_clientdata(client, indio_dev); indio_dev->info = &da280_info; indio_dev->modes = INDIO_DIRECT_MODE; @@ -142,22 +146,11 @@ static int da280_probe(struct i2c_client *client, if (ret < 0) return ret; - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "device_register failed\n"); - da280_enable(client, false); - } + ret = devm_add_action_or_reset(&client->dev, da280_disable, client); + if (ret) + return ret; - return ret; -} - -static int da280_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - - return da280_enable(client, false); + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -194,7 +187,6 @@ static struct i2c_driver da280_driver = { .pm = &da280_pm_ops, }, .probe = da280_probe, - .remove = da280_remove, .id_table = da280_i2c_id, }; From 4f0964f70fcf077e9f9a95ee5be71ff8be1c2b51 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:30 +0100 Subject: [PATCH 14/77] dt-bindings: iio: dac: adi,ad5421: Add missing binding document. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is documented what is currently the case. There are a number of things that could be added, but I don't feel the binding elements are obvious enough to document without a driver implementation to verify they are good choices. These include * Range * Regulators, both input and potentially output (if the loop being driven is ever described). I've listed Lars and myself as maintainers of the binding, but if anyone else wants to be added they would be most welcome! Signed-off-by: Jonathan Cameron Cc: Lars-Peter Clausen Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-2-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5421.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml new file mode 100644 index 000000000000..188f656617e3 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5421.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5421 DAC + +maintainers: + - Lars-Peter Clausen + - Jonathan Cameron + +description: | + AD5421 is designed for us in loop-powered, 4 mA to 20 mA smart transmitter + applications. It provides a 16-bit DAC, current amplifier, voltage regulator + to drive the loop and a voltage reference. + +properties: + compatible: + const: adi,ad5421 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: Fault signal. + + spi-max-frequency: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include + spi { + #address-cells = <1>; + #size-cells = <0>; + + dac@0 { + compatible = "adi,ad5421"; + reg = <0>; + spi-max-frequency = <30000000>; + interrupts = <55 IRQ_TYPE_LEVEL_HIGH>; + }; + }; +... From 613c403a7f978dddfd213e687a3ab6d104e50def Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:31 +0100 Subject: [PATCH 15/77] dt-bindings: iio: dac: adi,ad5064: Document bindings for many different DACs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note this is documenting bindings that have effectively existing ever since this driver was merged. The naming conventions for the ADI parts are inconsistent on the data sheets which has lead to a mixture of -X and -reference voltage part naming. We could attempt to clean this up, but as we are stuck supporting the existing binding it is probably not worthwhile. Signed-off-by: Jonathan Cameron Cc: Lars-Peter Clausen Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-3-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5064.yaml | 268 ++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml new file mode 100644 index 000000000000..05ed4e0ec364 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml @@ -0,0 +1,268 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5064.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5064 and similar DACs + +maintainers: + - Lars-Peter Clausen + - Jonathan Cameron + +description: | + A range of similar DAC devices with between 1 and 12 channels. Some parts + have internal references, others require a single shared external reference + and the remainder have a separate reference pin for each DAC. + +properties: + compatible: + oneOf: + - description: I2C devics + enum: + - adi,ad5024 + - adi,ad5025 + - adi,ad5044 + - adi,ad5045 + - adi,ad5064 + - adi,ad5064-1 + - adi,ad5065 + - adi,ad5628-1 + - adi,ad5628-2 + - adi,ad5648-1 + - adi,ad5648-2 + - adi,ad5666-1 + - adi,ad5666-2 + - adi,ad5668-1 + - adi,ad5668-2 + - adi,ad5668-3 + - description: SPI devices + enum: + - adi,ad5625 + - adi,ad5625r-1v25 + - adi,ad5625r-2v5 + - adi,ad5627 + - adi,ad5627r-1v25 + - adi,ad5627r-2v5 + - adi,ad5629-1 + - adi,ad5629-2 + - adi,ad5629-3 + - adi,ad5645r-1v25 + - adi,ad5645r-2v5 + - adi,ad5665 + - adi,ad5665r-1v25 + - adi,ad5665r-2v5 + - adi,ad5667 + - adi,ad5667r-1v25 + - adi,ad5667r-2v5 + - adi,ad5669-1 + - adi,ad5669-2 + - adi,ad5669-3 + - lltc,ltc2606 + - lltc,ltc2607 + - lltc,ltc2609 + - lltc,ltc2616 + - lltc,ltc2617 + - lltc,ltc2619 + - lltc,ltc2626 + - lltc,ltc2627 + - lltc,ltc2629 + - lltc,ltc2631-l12 + - lltc,ltc2631-h12 + - lltc,ltc2631-l10 + - lltc,ltc2631-h10 + - lltc,ltc2631-l8 + - lltc,ltc2631-h8 + - lltc,ltc2633-l12 + - lltc,ltc2633-h12 + - lltc,ltc2633-l10 + - lltc,ltc2633-h10 + - lltc,ltc2633-l8 + - lltc,ltc2633-h8 + - lltc,ltc2635-l12 + - lltc,ltc2635-h12 + - lltc,ltc2635-l10 + - lltc,ltc2635-h10 + - lltc,ltc2635-l8 + - lltc,ltc2635-h8 + + reg: + maxItems: 1 + + vrefA-supply: true + vrefB-supply: true + vrefC-supply: true + vrefD-supply: true + vref-supply: true + + spi-max-frequency: true + +additionalProperties: false + +required: + - compatible + - reg + +allOf: + - # Shared external vref, no internal reference + if: + properties: + compatible: + contains: + enum: + - adi,ad5064-1 + - adi,ad5625 + - adi,ad5627 + - adi,ad5665 + - adi,ad5667 + - lltc,ltc2606 + - lltc,ltc2607 + - lltc,ltc2616 + - lltc,ltc2617 + - lltc,ltc2626 + - lltc,ltc2627 + then: + properties: + vref-supply: true + vrefA-supply: false + vrefB-supply: false + vrefC-supply: false + vrefD-supply: false + required: + - vref-supply + - # Shared external vref, internal reference available + if: + properties: + compatible: + contains: + enum: + - adi,ad5625r-1v25 + - adi,ad5625r-2v5 + - adi,ad5627r-1v25 + - adi,ad5627r-2v5 + - adi,ad5628-1 + - adi,ad5628-2 + - adi,ad5629-1 + - adi,ad5629-2 + - adi,ad5629-3 + - adi,ad5645r-1v25 + - adi,ad5645r-2v5 + - adi,ad5647r-1v25 + - adi,ad5647r-2v5 + - adi,ad5648-1 + - adi,ad5648-2 + - adi,ad5665r-1v25 + - adi,ad5665r-2v5 + - adi,ad5666-1 + - adi,ad5666-2 + - adi,ad5667r-1v25 + - adi,ad5667r-2v5 + - adi,ad5668-1 + - adi,ad5668-2 + - adi,ad5668-3 + - adi,ad5669-1 + - adi,ad5669-2 + - adi,ad5669-3 + - lltc,ltc2631-l12 + - lltc,ltc2631-h12 + - lltc,ltc2631-l10 + - lltc,ltc2631-h10 + - lltc,ltc2631-l8 + - lltc,ltc2631-h8 + - lltc,ltc2633-l12 + - lltc,ltc2633-h12 + - lltc,ltc2633-l10 + - lltc,ltc2633-h10 + - lltc,ltc2633-l8 + - lltc,ltc2633-h8 + - lltc,ltc2635-l12 + - lltc,ltc2635-h12 + - lltc,ltc2635-l10 + - lltc,ltc2635-h10 + - lltc,ltc2635-l8 + - lltc,ltc2635-h8 + then: + properties: + vref-supply: true + vrefA-supply: false + vrefB-supply: false + vrefC-supply: false + vrefD-supply: false + - # 4 input devices, separate vrefs, no internal reference + if: + properties: + compatible: + contains: + enum: + - adi,ad5024 + - adi,ad5044 + - adi,ad5064 + - lltc,ltc2609 + - lltc,ltc2619 + - lltc,ltc2629 + then: + properties: + vrefA-supply: true + vrefB-supply: true + vrefC-supply: true + vrefD-supply: true + vref-supply: false + required: + - vrefA-supply + - vrefB-supply + - vrefC-supply + - vrefD-supply + - # 2 input devices, separate vrefs, no internal reference + if: + properties: + compatible: + contains: + enum: + - adi,ad5025 + - adi,ad5045 + - adi,ad5065 + then: + properties: + vrefA-supply: true + vrefB-supply: true + vrefC-supply: false + vrefD-supply: false + vref-supply: false + required: + - vrefA-supply + - vrefB-supply + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5625"; + vref-supply = <&dac_vref>; + }; + }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5625r-1v25"; + }; + }; + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + dac@42 { + reg = <0x42>; + compatible = "adi,ad5024"; + vrefA-supply = <&dac_vref>; + vrefB-supply = <&dac_vref>; + vrefC-supply = <&dac_vref2>; + vrefD-supply = <&dac_vref2>; + }; + }; +... From 0688cc60d579e9d122cbf81b7d185d711d0e3989 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:32 +0100 Subject: [PATCH 16/77] dt-bindings: iio: dac: adi,ad5360: Add missing binding document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bindings for the family of many channel DACs. Fairly straight forward with just a differing number of voltage references (an extra one for the 40 channel ad4371) Signed-off-by: Jonathan Cameron Cc: Lars-Peter Clausen Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-4-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5360.yaml | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml new file mode 100644 index 000000000000..0d8fb56f4b09 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5360 and similar DACs + +maintainers: + - Lars-Peter Clausen + - Jonathan Cameron + +properties: + compatible: + enum: + - adi,ad5360 + - adi,ad5361 + - adi,ad5363 + - adi,ad5370 + - adi,ad5371 + - adi,ad5372 + - adi,ad5373 + + reg: + maxItems: 1 + + vref0-supply: true + vref1-supply: true + vref2-supply: true + + spi-max-frequency: true + +additionalProperties: false + +required: + - compatible + - reg + - vref0-supply + - vref1-supply + +allOf: + - if: + properties: + compatible: + contains: + enum: + - adi,ad5360 + - adi,ad5361 + - adi,ad5363 + - adi,ad5370 + - adi,ad5372 + - adi,ad5373 + then: + properties: + vref2-supply: false + - if: + properties: + compatible: + contains: + enum: + - adi,ad5371 + then: + required: + - vref2-supply + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5371"; + vref0-supply = <&dac_vref0>; + vref1-supply = <&dac_vref1>; + vref2-supply = <&dac_vref2>; + }; + }; +... From 5992d5a6b563bcf4313d8c06b957052b131eba6d Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:33 +0100 Subject: [PATCH 17/77] dt-bindings: iio: dac: ad5380: Add missing binding document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A simple binding for this particular DAC familly. Signed-off-by: Jonathan Cameron Cc: Lars-Peter Clausen Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-5-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5380.yaml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml new file mode 100644 index 000000000000..d599b418a020 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5380.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5380 and similar DACs + +maintainers: + - Lars-Peter Clausen + - Jonathan Cameron + +description: | + DAC devices supporting both SPI and I2C interfaces. +properties: + compatible: + enum: + - adi,ad5380-3 + - adi,ad5380-5 + - adi,ad5381-3 + - adi,ad5381-5 + - adi,ad5382-3 + - adi,ad5382-5 + - adi,ad5383-3 + - adi,ad5383-5 + - adi,ad5384-3 + - adi,ad5384-5 + - adi,ad5390-3 + - adi,ad5390-5 + - adi,ad5391-3 + - adi,ad5391-5 + - adi,ad5392-3 + - adi,ad5392-5 + + reg: + maxItems: 1 + + vref-supply: + description: + If not supplied devices will use internal regulators. + + spi-max-frequency: true + +additionalProperties: false + +required: + - compatible + - reg + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5390-5"; + vref-supply = <&dacvref>; + }; + }; + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + dac@42 { + reg = <0x42>; + compatible = "adi,ad5380-3"; + }; + }; +... From 609bf552b034f62e8775153d943524a1ed4dbc2a Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:35 +0100 Subject: [PATCH 18/77] dt-bindings: iio: dac: ad5449: Add missing binding document. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Documenting existing binding, so little flexibility available. 2 channel devices that require separate reference voltages. Signed-off-by: Jonathan Cameron Cc: Lars-Peter Clausen Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-7-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5449.yaml | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml new file mode 100644 index 000000000000..044332c97743 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml @@ -0,0 +1,97 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5449.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5449 and similar DACs + +maintainers: + - Lars-Peter Clausen + - Jonathan Cameron + +description: + Family of multiplying DACs from Analog Devices + +properties: + compatible: + enum: + - adi,ad5415 + - adi,ad5426 + - adi,ad5429 + - adi,ad5432 + - adi,ad5439 + - adi,ad5443 + - adi,ad5449 + + reg: + maxItems: 1 + + spi-max-frequency: true + + VREF-supply: true + VREFA-supply: true + VREFB-supply: true + +additionalProperties: false + +required: + - compatible + - reg + +allOf: + - if: + properties: + compatible: + contains: + enum: + - adi,ad5415 + - adi,ad5426 + - adi,ad5432 + then: + properties: + VREF-supply: true + VREFA-supply: false + VREFB-supply: false + required: + - VREF-supply + - if: + properties: + compatible: + contains: + enum: + - adi,ad5429 + - adi,ad5439 + - adi,ad5449 + then: + properties: + VREF-supply: false + VREFA-supply: true + VREFB-supply: true + required: + - VREFA-supply + - VREFB-supply + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5415"; + VREF-supply = <&dac_ref>; + }; + }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5429"; + VREFA-supply = <&dac_refA>; + VREFB-supply = <&dac_refB>; + }; + }; +... From 790a352b6f125e0d22edc0ae479bb2f2ef930fe3 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:36 +0100 Subject: [PATCH 19/77] dt-bindings: iio: dac: ad5504: Add missing binding document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Binding for this high voltage DAC with temperature event signal. Signed-off-by: Jonathan Cameron Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-8-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5504.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml new file mode 100644 index 000000000000..9c2c038683b4 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5504.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5501 and AD5504 DACs + +maintainers: + - Lars-Peter Clausen + - Jonathan Cameron + +description: + High voltage (up to 60V) DACs with temperature sensor alarm function + +properties: + compatible: + enum: + - adi,ad5501 + - adi,ad5504 + + reg: + maxItems: 1 + + interrupts: + description: Used for temperature alarm. + maxItems: 1 + + vcc-supply: true + +additionalProperties: false + +required: + - compatible + - reg + +examples: + - | + #include + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5504"; + vcc-supply = <&dac_vcc>; + interrupts = <55 IRQ_TYPE_EDGE_FALLING>; + }; + }; +... From 97683c851f9cdbd3ea55697cbe2dcb6af4287bbd Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:37 +0100 Subject: [PATCH 20/77] iio: dac: ad5624r: Fix incorrect handling of an optional regulator. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The naming of the regulator is problematic. VCC is usually a supply voltage whereas these devices have a separate VREF pin. Secondly, the regulator core might have provided a stub regulator if a real regulator wasn't provided. That would in turn have failed to provide a voltage when queried. So reality was that there was no way to use the internal reference. In order to avoid breaking any dts out in the wild, make sure to fallback to the original vcc naming if vref is not available. Signed-off-by: Jonathan Cameron Reported-by: kernel test robot Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-9-jic23@kernel.org --- drivers/iio/dac/ad5624r_spi.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c index 9bde86982912..530529feebb5 100644 --- a/drivers/iio/dac/ad5624r_spi.c +++ b/drivers/iio/dac/ad5624r_spi.c @@ -229,7 +229,7 @@ static int ad5624r_probe(struct spi_device *spi) if (!indio_dev) return -ENOMEM; st = iio_priv(indio_dev); - st->reg = devm_regulator_get(&spi->dev, "vcc"); + st->reg = devm_regulator_get_optional(&spi->dev, "vref"); if (!IS_ERR(st->reg)) { ret = regulator_enable(st->reg); if (ret) @@ -240,6 +240,22 @@ static int ad5624r_probe(struct spi_device *spi) goto error_disable_reg; voltage_uv = ret; + } else { + if (PTR_ERR(st->reg) != -ENODEV) + return PTR_ERR(st->reg); + /* Backwards compatibility. This naming is not correct */ + st->reg = devm_regulator_get_optional(&spi->dev, "vcc"); + if (!IS_ERR(st->reg)) { + ret = regulator_enable(st->reg); + if (ret) + return ret; + + ret = regulator_get_voltage(st->reg); + if (ret < 0) + goto error_disable_reg; + + voltage_uv = ret; + } } spi_set_drvdata(spi, indio_dev); From b302c57bc9c7d11dbab7b70b9711506a63592617 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:38 +0100 Subject: [PATCH 21/77] dt-bindings: iio: dac: ad5624r: Add missing binding document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simple binding, with optional vref. Note that the Linux driver does support vcc-supply for historical reasons, but lets not let that get into any bindings that are checked going forwards. Hence I have deliberately not documented it. Signed-off-by: Jonathan Cameron Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-10-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5624r.yaml | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml new file mode 100644 index 000000000000..330383b85eeb --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5624r.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5624r and similar DACs + +maintainers: + - Jonathan Cameron + +properties: + compatible: + enum: + - adi,ad5624r3 + - adi,ad5644r3 + - adi,ad5664r3 + - adi,ad5624r5 + - adi,ad5644r5 + - adi,ad5664r5 + + reg: + maxItems: 1 + + spi-max-frequency: true + + vref-supply: + description: If not present, internal reference will be used. + +additionalProperties: false + +required: + - compatible + - reg + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5624r3"; + vref-supply = <&vref>; + }; + }; +... From 2d89b8b2c0bf8a49d9e7b5978afecc806666b5e7 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:39 +0100 Subject: [PATCH 22/77] dt-bindings: iio: dac: ad5686 and ad5696: Add missing binding document. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The use of vcc-supply for the reference voltage is unusual and should probably be deprecated as there is an explicit VREF pin on at least some of these parts. Signed-off-by: Jonathan Cameron Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-11-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5686.yaml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml new file mode 100644 index 000000000000..5c26441eae9f --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5686.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5360 and similar DACs + +maintainers: + - Michael Hennerich + - Jonathan Cameron + +properties: + compatible: + oneOf: + - description: SPI devices + enum: + - adi,ad5310r + - adi,ad5672r + - adi,ad5674r + - adi,ad5676 + - adi,ad5676r + - adi,ad5679r + - adi,ad5681r + - adi,ad5682r + - adi,ad5683 + - adi,ad5683r + - adi,ad5684 + - adi,ad5684r + - adi,ad5685r + - adi,ad5686 + - adi,ad5686r + - description: I2C devices + enum: + - adi,ad5311r + - adi,ad5338r + - adi,ad5671r + - adi,ad5675r + - adi,ad5691r + - adi,ad5692r + - adi,ad5693 + - adi,ad5693r + - adi,ad5694 + - adi,ad5694r + - adi,ad5695r + - adi,ad5696 + - adi,ad5696r + + + reg: + maxItems: 1 + + vcc-supply: + description: If not supplied the internal reference is used. + + spi-max-frequency: true + +additionalProperties: false + +required: + - compatible + - reg + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + dac@0 { + reg = <0>; + compatible = "adi,ad5310r"; + vcc-supply = <&dac_vref0>; + }; + }; +... From db8dc17e1fd820792804fa1e10ab8244b4abdd78 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:40 +0100 Subject: [PATCH 23/77] dt-bindings: iio: dac: ad5761: Add missing binding doc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Straight forward binding with vref optional for those part with internal regulators, but required for those without. Signed-off-by: Jonathan Cameron Cc: Ricardo Ribalda Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-12-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5761.yaml | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml new file mode 100644 index 000000000000..7f95a9ed55fe --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5761.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5761 and similar DACs + +maintainers: + - Ricardo Ribalda + - Jonathan Cameron + +properties: + + compatible: + enum: + - adi,ad5721 + - adi,ad5721r + - adi,ad5761 + - adi,ad5761r + + reg: + maxItems: 1 + + spi-max-frequency: true + + vref-supply: + description: If not supplied, internal reference will be used. + +additionalProperties: false + +required: + - compatible + - reg + +allOf: + - if: + properties: + compatible: + contains: + enum: + - adi,ad5721 + - adi,ad5761 + then: + required: + - vref-supply + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + dac@0 { + compatible = "adi,ad5721"; + reg = <0>; + vref-supply = <&dac_vref>; + }; + }; +... From 96e137558d5823787a410c3c89d076fdc8b8c720 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:41 +0100 Subject: [PATCH 24/77] dt-bindings: iio: dac: adi,ad5764: Add missing binding document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This binding covers the ad5744, ad5744r, ad5764 and ad5764r DACs. Note that the driver currently assumes the internal reference is used for the r parts. The binding as defined relaxes this constraint. There is no support in the binding or driver for the two digital IO signals. I do not propose to add that until we have a means to test any such binding. Signed-off-by: Jonathan Cameron Cc: Lars-Peter Clausen Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-13-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5764.yaml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml new file mode 100644 index 000000000000..8e893d52bfb1 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5764.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5744 and AD5764 DAC families + +maintainers: + - Lars-Peter Clausen + - Jonathan Cameron + +properties: + + compatible: + enum: + - adi,ad5744 + - adi,ad5744r + - adi,ad5764 + - adi,ad5764r + + reg: + maxItems: 1 + + spi-max-frequency: true + + vrefAB-supply: true + vrefCD-supply: true + +additionalProperties: false + +required: + - compatible + - reg + +allOf: + - if: + properties: + compatible: + contains: + enum: + - adi,ad5744 + - adi,ad5764 + then: + required: + - vrefAB-supply + - vrefCD-supply + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + dac@0 { + compatible = "adi,ad5744"; + reg = <0>; + vrefAB-supply = <&dac_vref>; + vrefCD-supply = <&dac_vref>; + }; + }; +... From a714ee9ea0efe516fd13c1f29f41f6394b408492 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:42 +0100 Subject: [PATCH 25/77] dt-bindings: iio: dac: adi,ad5791: Add missing bindings document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Documenting existing bindings for this device. The Linux driver in theory 'works' without the two supplies that I have listed as required, but without a valid scale. As such I've documented it as required. Signed-off-by: Jonathan Cameron Cc: Michael Hennerich Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-14-jic23@kernel.org --- .../bindings/iio/dac/adi,ad5791.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml new file mode 100644 index 000000000000..650d1ebdcec3 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad5791.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD5791 and similar DACs + +maintainers: + - Michael Hennerich + - Jonathan Cameron + +properties: + + compatible: + enum: + - adi,ad5760 + - adi,ad5780 + - adi,ad5781 + - adi,ad5790 + - adi,ad5791 + + reg: + maxItems: 1 + + spi-max-frequency: true + + vdd-supply: true + vss-supply: true + +additionalProperties: false + +required: + - compatible + - reg + - vdd-supply + - vss-supply + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + dac@0 { + compatible = "adi,ad5791"; + reg = <0>; + vss-supply = <&dac_vss>; + vdd-supply = <&dac_vdd>; + }; + }; +... From 906b00437e71764624f666b75abfe45b087b17c8 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:43 +0100 Subject: [PATCH 26/77] dt-bindings: iio: dac: adi,ad8801: Add missing binding document. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This device was missing a binding document. Simple binding with the ad8803 requiring two both low and high references whilst the 8801 only has a high reference. Signed-off-by: Jonathan Cameron Cc: Gwenhael Goavec-Merou Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-15-jic23@kernel.org --- .../bindings/iio/dac/adi,ad8801.yaml | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml new file mode 100644 index 000000000000..6a3990a8d0ad --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/adi,ad8801.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD8801 and AD8803 DACs + +maintainers: + - Jonathan Cameron + +properties: + + compatible: + enum: + - adi,ad8801 + - adi,ad8803 + + reg: + maxItems: 1 + + spi-max-frequency: true + + vrefh-supply: true + vrefl-supply: true + +additionalProperties: false + +required: + - compatible + - reg + - vrefh-supply + +allOf: + - if: + properties: + compatible: + contains: + const: adi,ad8803 + then: + required: + - vrefl-supply + else: + properties: + vrefl-supply: false + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + dac@0 { + compatible = "adi,ad8803"; + reg = <0>; + vrefl-supply = <&dac_vrefl>; + vrefh-supply = <&dac_vrefh>; + }; + }; +... From f21a5f7215420c513d2bb2d21fdf24c9a550922e Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 27 Jun 2021 17:32:44 +0100 Subject: [PATCH 27/77] dt-bindings: iio: dac: microchip,mcp4922: Add missing binding document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simple binding for this family of microchip DACs. Signed-off-by: Jonathan Cameron Cc: Michael Welling Reviewed-by: Rob Herring Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-16-jic23@kernel.org --- .../bindings/iio/dac/microchip,mcp4922.yaml | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml diff --git a/Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml b/Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml new file mode 100644 index 000000000000..12a14b3f36cb --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/dac/microchip,mcp4922.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip MCP4902, MCP4912 and MPC4922 dual output SPI DACs + +maintainers: + - Jonathan Cameron + - Michael Welling + +properties: + compatible: + enum: + - microchip,mcp4902 + - microchip,mcp4912 + - microchip,mcp4922 + + reg: + maxItems: 1 + + spi-max-frequency: true + + vref-supply: true + +additionalProperties: false + +required: + - compatible + - reg + - vref-supply + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + dac@0 { + compatible = "microchip,mcp4912"; + reg = <0>; + vref-supply = <&dac_vref>; + }; + }; +... From c336b611e9e48304589303b580292dd1bf6d4eb3 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Fri, 25 Jun 2021 17:01:36 +0300 Subject: [PATCH 28/77] iio: accel: bma220: convert probe to device-managed functions This change converts the driver to use devm_iio_triggered_buffer_setup() and devm_iio_device_register() for initializing and registering the IIO device. The bma220_deinit() is converted into a callback for a devm_add_action_or_reset() hook, so that the device is put in stand-by when the driver gets uninitialized. The return value of the bma220_deinit() function isn't used as it does not add any value. On the error path of the probe function, this can just override the actual error with -EBUSY, or can even return 0 (no error), on the error path. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210625140137.362282-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/bma220_spi.c | 44 +++++++++------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c index 0622c7936499..0095931a11f8 100644 --- a/drivers/iio/accel/bma220_spi.c +++ b/drivers/iio/accel/bma220_spi.c @@ -218,20 +218,14 @@ static int bma220_init(struct spi_device *spi) return 0; } -static int bma220_deinit(struct spi_device *spi) +static void bma220_deinit(void *spi) { int ret; /* Make sure the chip is powered off */ ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); if (ret == BMA220_SUSPEND_SLEEP) - ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); - if (ret < 0) - return ret; - if (ret == BMA220_SUSPEND_SLEEP) - return -EBUSY; - - return 0; + bma220_read_reg(spi, BMA220_REG_SUSPEND); } static int bma220_probe(struct spi_device *spi) @@ -262,34 +256,19 @@ static int bma220_probe(struct spi_device *spi) if (ret) return ret; - ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time, - bma220_trigger_handler, NULL); + ret = devm_add_action_or_reset(&spi->dev, bma220_deinit, spi); + if (ret) + return ret; + + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, + iio_pollfunc_store_time, + bma220_trigger_handler, NULL); if (ret < 0) { dev_err(&spi->dev, "iio triggered buffer setup failed\n"); - goto err_suspend; + return ret; } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&spi->dev, "iio_device_register failed\n"); - iio_triggered_buffer_cleanup(indio_dev); - goto err_suspend; - } - - return 0; - -err_suspend: - return bma220_deinit(spi); -} - -static int bma220_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - - return bma220_deinit(spi); + return devm_iio_device_register(&spi->dev, indio_dev); } static __maybe_unused int bma220_suspend(struct device *dev) @@ -326,7 +305,6 @@ static struct spi_driver bma220_driver = { .acpi_match_table = bma220_acpi_id, }, .probe = bma220_probe, - .remove = bma220_remove, .id_table = bma220_spi_id, }; module_spi_driver(bma220_driver); From 3ce868bb0595be1e4d75b0e1a055f2dc0867d335 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Fri, 25 Jun 2021 17:01:37 +0300 Subject: [PATCH 29/77] iio: accel: bma220: make suspend state setting more robust The datasheet mentions that the suspend mode is toggled by reading the suspend register. The reading returns value 0xFF if the system was in suspend mode, otherwise it returns value 0x00. The bma220_deinit() function does up to 2 reads, in case the device was in suspend mode, which suggests a level of paranoia that makes the logic in bma220_suspend() and bma220_resume() look insufficient. This change implements a bma220_power() function which does up to 2 reads of the suspend register to make sure that the chip enters a desired (suspended or normal) mode. If the transition fails, then -EBUSY is returned. Since only a reference to SPI device is required, we can remove the spi_set_drvdata() call and get the SPI device object from the base device object in the suspend/resume routines. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210625140137.362282-2-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/bma220_spi.c | 41 ++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c index 0095931a11f8..bc4c626e454d 100644 --- a/drivers/iio/accel/bma220_spi.c +++ b/drivers/iio/accel/bma220_spi.c @@ -218,14 +218,33 @@ static int bma220_init(struct spi_device *spi) return 0; } +static int bma220_power(struct spi_device *spi, bool up) +{ + int i, ret; + + /** + * The chip can be suspended/woken up by a simple register read. + * So, we need up to 2 register reads of the suspend register + * to make sure that the device is in the desired state. + */ + for (i = 0; i < 2; i++) { + ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); + if (ret < 0) + return ret; + + if (up && ret == BMA220_SUSPEND_SLEEP) + return 0; + + if (!up && ret == BMA220_SUSPEND_WAKE) + return 0; + } + + return -EBUSY; +} + static void bma220_deinit(void *spi) { - int ret; - - /* Make sure the chip is powered off */ - ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); - if (ret == BMA220_SUSPEND_SLEEP) - bma220_read_reg(spi, BMA220_REG_SUSPEND); + bma220_power(spi, false); } static int bma220_probe(struct spi_device *spi) @@ -242,7 +261,6 @@ static int bma220_probe(struct spi_device *spi) data = iio_priv(indio_dev); data->spi_device = spi; - spi_set_drvdata(spi, indio_dev); mutex_init(&data->lock); indio_dev->info = &bma220_info; @@ -273,17 +291,16 @@ static int bma220_probe(struct spi_device *spi) static __maybe_unused int bma220_suspend(struct device *dev) { - struct bma220_data *data = iio_priv(dev_get_drvdata(dev)); + struct spi_device *spi = to_spi_device(dev); - /* The chip can be suspended/woken up by a simple register read. */ - return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND); + return bma220_power(spi, false); } static __maybe_unused int bma220_resume(struct device *dev) { - struct bma220_data *data = iio_priv(dev_get_drvdata(dev)); + struct spi_device *spi = to_spi_device(dev); - return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND); + return bma220_power(spi, true); } static SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume); From 2bb3b8f69accde535daee238e0f707dec452e0e4 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Thu, 24 Jun 2021 11:19:23 +0300 Subject: [PATCH 30/77] iio: temperature: tmp006: convert probe to device-managed This change converts the driver to register via devm_iio_device_register(). For the tmp006_powerdown() hook, this uses a devm_add_action() hook to put the device in powerdown mode when it's unregistered. With these changes, the remove hook can be removed. The i2c_set_clientdata() call is staying around as the private data is used in the PM routines. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210624081924.15897-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/temperature/tmp006.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c index 54976c7dad92..db1ac6029c27 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c @@ -193,6 +193,17 @@ static bool tmp006_check_identification(struct i2c_client *client) return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; } +static int tmp006_powerdown(struct tmp006_data *data) +{ + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, + data->config & ~TMP006_CONFIG_MOD_MASK); +} + +static void tmp006_powerdown_cleanup(void *data) +{ + tmp006_powerdown(data); +} + static int tmp006_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -228,23 +239,11 @@ static int tmp006_probe(struct i2c_client *client, return ret; data->config = ret; - return iio_device_register(indio_dev); -} + ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data); + if (ret < 0) + return ret; -static int tmp006_powerdown(struct tmp006_data *data) -{ - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, - data->config & ~TMP006_CONFIG_MOD_MASK); -} - -static int tmp006_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - tmp006_powerdown(iio_priv(indio_dev)); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -277,7 +276,6 @@ static struct i2c_driver tmp006_driver = { .pm = &tmp006_pm_ops, }, .probe = tmp006_probe, - .remove = tmp006_remove, .id_table = tmp006_id, }; module_i2c_driver(tmp006_driver); From c359a80ca29099be951a1fa5c7529792cadf3e8f Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Thu, 24 Jun 2021 11:19:24 +0300 Subject: [PATCH 31/77] iio: temperature: tmp006: make sure the chip is powered up in probe When the device is probed, there's no guarantee that the device is not in power-down mode. This can happen if the driver is unregistered and re-probed. To make sure this doesn't happen, the value of the TMP006_CONFIG register (which is read in the probe function and stored in the device's private data) is being checked to see if the MOD bits have the correct value. This is a fix for a somewhat-rare corner case. As it stands, this doesn't look like a high priority to go into the Fixes route. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210624081924.15897-2-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/temperature/tmp006.c | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c index db1ac6029c27..e4943a0bc9aa 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c @@ -193,15 +193,23 @@ static bool tmp006_check_identification(struct i2c_client *client) return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; } -static int tmp006_powerdown(struct tmp006_data *data) +static int tmp006_power(struct device *dev, bool up) { + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct tmp006_data *data = iio_priv(indio_dev); + + if (up) + data->config |= TMP006_CONFIG_MOD_MASK; + else + data->config &= ~TMP006_CONFIG_MOD_MASK; + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, - data->config & ~TMP006_CONFIG_MOD_MASK); + data->config); } -static void tmp006_powerdown_cleanup(void *data) +static void tmp006_powerdown_cleanup(void *dev) { - tmp006_powerdown(data); + tmp006_power(dev, false); } static int tmp006_probe(struct i2c_client *client, @@ -239,7 +247,14 @@ static int tmp006_probe(struct i2c_client *client, return ret; data->config = ret; - ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data); + if ((ret & TMP006_CONFIG_MOD_MASK) != TMP006_CONFIG_MOD_MASK) { + ret = tmp006_power(&client->dev, true); + if (ret < 0) + return ret; + } + + ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup, + &client->dev); if (ret < 0) return ret; @@ -249,16 +264,12 @@ static int tmp006_probe(struct i2c_client *client, #ifdef CONFIG_PM_SLEEP static int tmp006_suspend(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); - return tmp006_powerdown(iio_priv(indio_dev)); + return tmp006_power(dev, false); } static int tmp006_resume(struct device *dev) { - struct tmp006_data *data = iio_priv(i2c_get_clientdata( - to_i2c_client(dev))); - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, - data->config | TMP006_CONFIG_MOD_MASK); + return tmp006_power(dev, true); } #endif From d272e0ab5f4bcaf0a29e7606854cfb5a9b725758 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Thu, 24 Jun 2021 11:06:41 +0300 Subject: [PATCH 32/77] iio: potentiometer: max5481: convert probe to device-managed The change converts the probe function to use the devm_iio_device_register() function. Before calling that, we need to register an action to store the wiper back to non-volatile memory when the device is de-registered. We don't need to do this if the probe fails, because the only place where the probe can fail now is devm_iio_device_register() and that shouldn't create an IIO device (for userspace to poke at) if it fails. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210624080641.9953-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/potentiometer/max5481.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c index 6e22b538091f..098d144a8fdd 100644 --- a/drivers/iio/potentiometer/max5481.c +++ b/drivers/iio/potentiometer/max5481.c @@ -125,6 +125,11 @@ static const struct of_device_id max5481_match[] = { }; MODULE_DEVICE_TABLE(of, max5481_match); +static void max5481_wiper_save(void *data) +{ + max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0); +} + static int max5481_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -136,7 +141,6 @@ static int max5481_probe(struct spi_device *spi) if (!indio_dev) return -ENOMEM; - spi_set_drvdata(spi, indio_dev); data = iio_priv(indio_dev); data->spi = spi; @@ -158,18 +162,11 @@ static int max5481_probe(struct spi_device *spi) if (ret < 0) return ret; - return iio_device_register(indio_dev); -} + ret = devm_add_action(&spi->dev, max5481_wiper_save, data); + if (ret < 0) + return ret; -static int max5481_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct max5481_data *data = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - /* save wiper reg to NV reg */ - return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id max5481_id_table[] = { @@ -187,7 +184,6 @@ static struct spi_driver max5481_driver = { .of_match_table = max5481_match, }, .probe = max5481_probe, - .remove = max5481_remove, .id_table = max5481_id_table, }; From 9ae8da91a22cdd916f20cc4ba59911d084c7e26e Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Thu, 24 Jun 2021 11:05:34 +0300 Subject: [PATCH 33/77] iio: light: tcs3414: convert probe to device-managed routines This change converts the driver to use only device-managed init routines in the probe function of the driver. This way, we no longer need the tcs3414_remove() hook. We still need to keep the i2c_set_clientdata() call, as that's being used for the PM routines. And lastly, a devm_add_action_or_reset() hook is added to call the powerdown handler when the chip is uninitialized or the probe fails. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210624080534.9209-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/light/tcs3414.c | 48 +++++++++++++++---------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c index 0593abd600ec..b87222141429 100644 --- a/drivers/iio/light/tcs3414.c +++ b/drivers/iio/light/tcs3414.c @@ -267,6 +267,18 @@ static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = { .predisable = tcs3414_buffer_predisable, }; +static int tcs3414_powerdown(struct tcs3414_data *data) +{ + return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, + data->control & ~(TCS3414_CONTROL_POWER | + TCS3414_CONTROL_ADC_EN)); +} + +static void tcs3414_powerdown_cleanup(void *data) +{ + tcs3414_powerdown(data); +} + static int tcs3414_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -309,6 +321,11 @@ static int tcs3414_probe(struct i2c_client *client, if (ret < 0) return ret; + ret = devm_add_action_or_reset(&client->dev, tcs3414_powerdown_cleanup, + data); + if (ret < 0) + return ret; + data->timing = TCS3414_INTEG_12MS; /* free running */ ret = i2c_smbus_write_byte_data(data->client, TCS3414_TIMING, data->timing); @@ -320,38 +337,12 @@ static int tcs3414_probe(struct i2c_client *client, return ret; data->gain = ret; - ret = iio_triggered_buffer_setup(indio_dev, NULL, + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, tcs3414_trigger_handler, &tcs3414_buffer_setup_ops); if (ret < 0) return ret; - ret = iio_device_register(indio_dev); - if (ret < 0) - goto buffer_cleanup; - - return 0; - -buffer_cleanup: - iio_triggered_buffer_cleanup(indio_dev); - return ret; -} - -static int tcs3414_powerdown(struct tcs3414_data *data) -{ - return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, - data->control & ~(TCS3414_CONTROL_POWER | - TCS3414_CONTROL_ADC_EN)); -} - -static int tcs3414_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - tcs3414_powerdown(iio_priv(indio_dev)); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -385,7 +376,6 @@ static struct i2c_driver tcs3414_driver = { .pm = &tcs3414_pm_ops, }, .probe = tcs3414_probe, - .remove = tcs3414_remove, .id_table = tcs3414_id, }; module_i2c_driver(tcs3414_driver); From d372e5a19a8eb281428954b5edbd033d824f1bf0 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Thu, 24 Jun 2021 11:04:40 +0300 Subject: [PATCH 34/77] iio: accel: adxl345: convert probe to device-managed functions This driver has two parts, one for i2c and one for spi, since the chip can operate with both wire protocols. The core file has a common adxl345_core_remove() function which puts the chip into a powerdown state. This can be implemented with a devm_add_action_or_reset() hook. Doing that means we can register the IIO device with devm_iio_device_register() and get rid of the adxl345_core_remove() function. The dev_set_drvdata() call can be removed as there is no other user of this private data anymore. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210624080441.8710-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/adxl345.h | 1 - drivers/iio/accel/adxl345_core.c | 29 +++++++++-------------------- drivers/iio/accel/adxl345_i2c.c | 6 ------ drivers/iio/accel/adxl345_spi.c | 6 ------ 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 384497776b67..af0fdd02c4f2 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -15,6 +15,5 @@ enum adxl345_device_type { int adxl345_core_probe(struct device *dev, struct regmap *regmap, enum adxl345_device_type type, const char *name); -int adxl345_core_remove(struct device *dev); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 312866530065..4b275051ef61 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -208,6 +208,11 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; +static void adxl345_powerdown(void *regmap) +{ + regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); +} + int adxl345_core_probe(struct device *dev, struct regmap *regmap, enum adxl345_device_type type, const char *name) { @@ -233,7 +238,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return -ENOMEM; data = iio_priv(indio_dev); - dev_set_drvdata(dev, indio_dev); data->regmap = regmap; data->type = type; /* Enable full-resolution mode */ @@ -260,29 +264,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return ret; } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(dev, "iio_device_register failed: %d\n", ret); - regmap_write(data->regmap, ADXL345_REG_POWER_CTL, - ADXL345_POWER_CTL_STANDBY); - } + ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); + if (ret < 0) + return ret; - return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_GPL(adxl345_core_probe); -int adxl345_core_remove(struct device *dev) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct adxl345_data *data = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - return regmap_write(data->regmap, ADXL345_REG_POWER_CTL, - ADXL345_POWER_CTL_STANDBY); -} -EXPORT_SYMBOL_GPL(adxl345_core_remove); - MODULE_AUTHOR("Eva Rachel Retuya "); MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer core driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 1561364ae296..a431cba216e6 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -38,11 +38,6 @@ static int adxl345_i2c_probe(struct i2c_client *client, id->name); } -static int adxl345_i2c_remove(struct i2c_client *client) -{ - return adxl345_core_remove(&client->dev); -} - static const struct i2c_device_id adxl345_i2c_id[] = { { "adxl345", ADXL345 }, { "adxl375", ADXL375 }, @@ -65,7 +60,6 @@ static struct i2c_driver adxl345_i2c_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_i2c_probe, - .remove = adxl345_i2c_remove, .id_table = adxl345_i2c_id, }; diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index da4591c7ef23..ea559ac2e87d 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -42,11 +42,6 @@ static int adxl345_spi_probe(struct spi_device *spi) return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name); } -static int adxl345_spi_remove(struct spi_device *spi) -{ - return adxl345_core_remove(&spi->dev); -} - static const struct spi_device_id adxl345_spi_id[] = { { "adxl345", ADXL345 }, { "adxl375", ADXL375 }, @@ -69,7 +64,6 @@ static struct spi_driver adxl345_spi_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_spi_probe, - .remove = adxl345_spi_remove, .id_table = adxl345_spi_id, }; From e46a36d92da0ded4e8519bc46912edc0d5a9f4a7 Mon Sep 17 00:00:00 2001 From: Baptiste Mansuy Date: Mon, 21 Jun 2021 10:57:31 +0200 Subject: [PATCH 35/77] Add startup time for each chip using inv_mpu6050 driver Add startup time for each chip familly. This allows a better behaviour of the gyro and the accel. The gyro has now the time to stabilise itself thus making initial data discarding for gyro irrelevant. Signed-off-by: Baptiste Mansuy Acked-by: Jean-Baptiste Maneyrol Link: https://lore.kernel.org/r/20210621085731.9212-1-bmansuy@invensense.com Signed-off-by: Jonathan Cameron --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 22 +++++++++++++++---- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 18 +++++++++++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 15 ++----------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 8a7a920e6200..597768c29a72 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -143,6 +143,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6050, .fifo_size = 1024, .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE}, + .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME}, }, { .whoami = INV_MPU6500_WHOAMI_VALUE, @@ -151,6 +152,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_MPU6515_WHOAMI_VALUE, @@ -159,6 +161,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_MPU6880_WHOAMI_VALUE, @@ -167,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 4096, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_MPU6000_WHOAMI_VALUE, @@ -175,6 +179,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6050, .fifo_size = 1024, .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE}, + .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME}, }, { .whoami = INV_MPU9150_WHOAMI_VALUE, @@ -183,6 +188,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6050, .fifo_size = 1024, .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE}, + .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME}, }, { .whoami = INV_MPU9250_WHOAMI_VALUE, @@ -191,6 +197,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_MPU9255_WHOAMI_VALUE, @@ -199,6 +206,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_ICM20608_WHOAMI_VALUE, @@ -207,6 +215,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_ICM20609_WHOAMI_VALUE, @@ -215,6 +224,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 4 * 1024, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_ICM20689_WHOAMI_VALUE, @@ -223,6 +233,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 4 * 1024, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, { .whoami = INV_ICM20602_WHOAMI_VALUE, @@ -231,6 +242,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 1008, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, + .startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME}, }, { .whoami = INV_ICM20690_WHOAMI_VALUE, @@ -239,6 +251,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 1024, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, + .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME}, }, { .whoami = INV_IAM20680_WHOAMI_VALUE, @@ -247,6 +260,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, }, }; @@ -379,12 +393,12 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, sleep = 0; if (en) { if (mask & INV_MPU6050_SENSOR_ACCL) { - if (sleep < INV_MPU6050_ACCEL_UP_TIME) - sleep = INV_MPU6050_ACCEL_UP_TIME; + if (sleep < st->hw->startup_time.accel) + sleep = st->hw->startup_time.accel; } if (mask & INV_MPU6050_SENSOR_GYRO) { - if (sleep < INV_MPU6050_GYRO_UP_TIME) - sleep = INV_MPU6050_GYRO_UP_TIME; + if (sleep < st->hw->startup_time.gyro) + sleep = st->hw->startup_time.gyro; } } else { if (mask & INV_MPU6050_SENSOR_GYRO) { diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 58188dc0dd13..c6aa36ee966a 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -149,6 +149,10 @@ struct inv_mpu6050_hw { int offset; int scale; } temp; + struct { + unsigned int accel; + unsigned int gyro; + } startup_time; }; /* @@ -320,11 +324,21 @@ struct inv_mpu6050_state { /* delay time in milliseconds */ #define INV_MPU6050_POWER_UP_TIME 100 #define INV_MPU6050_TEMP_UP_TIME 100 -#define INV_MPU6050_ACCEL_UP_TIME 20 -#define INV_MPU6050_GYRO_UP_TIME 35 +#define INV_MPU6050_ACCEL_STARTUP_TIME 20 +#define INV_MPU6050_GYRO_STARTUP_TIME 60 #define INV_MPU6050_GYRO_DOWN_TIME 150 #define INV_MPU6050_SUSPEND_DELAY_MS 2000 +#define INV_MPU6500_GYRO_STARTUP_TIME 70 +#define INV_MPU6500_ACCEL_STARTUP_TIME 30 + +#define INV_ICM20602_GYRO_STARTUP_TIME 100 +#define INV_ICM20602_ACCEL_STARTUP_TIME 20 + +#define INV_ICM20690_GYRO_STARTUP_TIME 80 +#define INV_ICM20690_ACCEL_STARTUP_TIME 10 + + /* delay time in microseconds */ #define INV_MPU6050_REG_UP_TIME_MIN 5000 #define INV_MPU6050_REG_UP_TIME_MAX 10000 diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index 2d0e8cdd4848..882546897255 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -91,22 +91,11 @@ static unsigned int inv_scan_query(struct iio_dev *indio_dev) static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st) { - unsigned int gyro_skip = 0; - unsigned int magn_skip = 0; - unsigned int skip_samples; - - /* gyro first sample is out of specs, skip it */ - if (st->chip_config.gyro_fifo_enable) - gyro_skip = 1; + unsigned int skip_samples = 0; /* mag first sample is always not ready, skip it */ if (st->chip_config.magn_fifo_enable) - magn_skip = 1; - - /* compute first samples to skip */ - skip_samples = gyro_skip; - if (magn_skip > skip_samples) - skip_samples = magn_skip; + skip_samples = 1; return skip_samples; } From 0e0761f86f10253425edac56df9950c172b923ea Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Fri, 18 Jun 2021 13:30:04 +0100 Subject: [PATCH 36/77] iio: core: Forbid use of both labels and extended names Extended names are a problem for user-space as they make the filenames in sysfs sometimes not parsable. They are now deprecated in favor of labels. This change makes sure that a device driver won't provide both labels and extended names for its channels. It has never been the case and we don't want it to happen. Signed-off-by: Paul Cercueil Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210618123005.49867-2-paul@crapouillou.net Signed-off-by: Jonathan Cameron --- drivers/iio/industrialio-core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 6d2175eb7af2..7e3c92efdfa0 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1858,6 +1858,24 @@ static int iio_check_unique_scan_index(struct iio_dev *indio_dev) return 0; } +static int iio_check_extended_name(const struct iio_dev *indio_dev) +{ + unsigned int i; + + if (!indio_dev->info->read_label) + return 0; + + for (i = 0; i < indio_dev->num_channels; i++) { + if (indio_dev->channels[i].extend_name) { + dev_err(&indio_dev->dev, + "Cannot use labels and extend_name at the same time\n"); + return -EINVAL; + } + } + + return 0; +} + static const struct iio_buffer_setup_ops noop_ring_setup_ops; int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) @@ -1882,6 +1900,10 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) if (ret < 0) return ret; + ret = iio_check_extended_name(indio_dev); + if (ret < 0) + return ret; + iio_device_register_debugfs(indio_dev); ret = iio_buffers_alloc_sysfs_and_mask(indio_dev); From 13efdc3dc9030972c81285e2dbdeac1f9cef880d Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Fri, 18 Jun 2021 13:30:05 +0100 Subject: [PATCH 37/77] iio: core: Support reading extended name as label The point of this new change is to make the IIO tree actually parsable. Before, given this attribute as a filename: in_voltage0_aux_sample_rate Userspace had no way to know if the attribute name was "aux_sample_rate" with no extended name, or "sample_rate" with "aux" as the extended name, or just "rate" with "aux_sample" as the extended name. This was somewhat possible to deduce when there was more than one attribute present for a given channel, e.g: in_voltage0_aux_sample_rate in_voltage0_aux_frequency There, it was possible to deduce that "aux" was the extended name. But even with more than one attribute, this wasn't very robust, as two attributes starting with the same prefix (e.g. "sample_rate" and "sample_size") would result in the first part of the prefix being interpreted as being part of the extended name. To address the issue, knowing that channels will never have both a label and an extended name, set the channel's label to the extended name. In this case, the label's attribute will also have the extended name in its filename, but we can live with that - userspace can open in_voltage0__label and verify that it returns to obtain the extended name. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20210618123005.49867-3-paul@crapouillou.net Signed-off-by: Jonathan Cameron --- drivers/iio/industrialio-core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 7e3c92efdfa0..2dbb37e09b8c 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -740,10 +740,13 @@ static ssize_t iio_read_channel_label(struct device *dev, struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - if (!indio_dev->info->read_label) - return -EINVAL; + if (indio_dev->info->read_label) + return indio_dev->info->read_label(indio_dev, this_attr->c, buf); - return indio_dev->info->read_label(indio_dev, this_attr->c, buf); + if (this_attr->c->extend_name) + return sprintf(buf, "%s\n", this_attr->c->extend_name); + + return -EINVAL; } static ssize_t iio_read_channel_info(struct device *dev, @@ -1183,7 +1186,7 @@ static int iio_device_add_channel_label(struct iio_dev *indio_dev, struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); int ret; - if (!indio_dev->info->read_label) + if (!indio_dev->info->read_label && !chan->extend_name) return 0; ret = __iio_add_chan_devattr("label", From b44ab6fdba6144c06ea543144b6888ac77fd2e17 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 17 Jun 2021 09:13:12 +0100 Subject: [PATCH 38/77] iio: light: si1145: remove redundant continue statement The continue statement at the end of a for-loop has no effect, remove it. Addresses-Coverity: ("Continue has no effect") Signed-off-by: Colin Ian King Link: https://lore.kernel.org/r/20210617081312.151746-1-colin.king@canonical.com Signed-off-by: Jonathan Cameron --- drivers/iio/light/si1145.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c index e2abad48b9f4..e8f6cdf26f22 100644 --- a/drivers/iio/light/si1145.c +++ b/drivers/iio/light/si1145.c @@ -220,7 +220,6 @@ static int __si1145_command_reset(struct si1145_data *data) return -ETIMEDOUT; } msleep(SI1145_COMMAND_MINSLEEP_MS); - continue; } } From 39361c997dc781dc590a8e45107b288f3e3f27d7 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 14 Jun 2021 18:31:48 +0200 Subject: [PATCH 39/77] dt-bindings: iio: accel: bma255: Fix interrupt type Bosch accelerometers similar to BMA255 are initially configured to emit an active-high interrupt signal. This is currently not re-configured in the bmc150-accel driver so the interrupt should most certainly be IRQ_TYPE_EDGE_RISING (or potentially IRQ_TYPE_LEVEL_HIGH). (Unless there is some kind of inverter installed on the board...) At the moment the bmc150-accel driver forcefully requests the IRQ using IRQF_TRIGGER_RISING, which means that the IRQ type is currently ignored in all existing device trees. Fixes: 6259551cf19b ("iio: accel: bmc150-accel: Add DT bindings") Cc: Linus Walleij Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij Acked-by: Rob Herring Link: https://lore.kernel.org/r/20210614163150.7774-2-stephan@gerhold.net Signed-off-by: Jonathan Cameron --- Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml index e830d5295b92..b37ba902e4a2 100644 --- a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml @@ -38,7 +38,7 @@ properties: description: | The first interrupt listed must be the one connected to the INT1 pin, the second (optional) interrupt listed must be the one connected to the - INT2 pin (if available). + INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING. mount-matrix: description: an optional 3x3 mounting rotation matrix. @@ -63,7 +63,7 @@ examples: reg = <0x08>; vddio-supply = <&vddio>; vdd-supply = <&vdd>; - interrupts = <57 IRQ_TYPE_EDGE_FALLING>; + interrupts = <57 IRQ_TYPE_EDGE_RISING>; }; }; - | From 562442d5a93b5b362e304b57accba43e40aad970 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 14 Jun 2021 18:31:49 +0200 Subject: [PATCH 40/77] dt-bindings: iio: accel: bma255: Sort compatibles Similar to recent rework in the bmc150-accel driver, sort the compatible list in the DT schema so there is a consistent order. Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij Acked-by: Rob Herring Link: https://lore.kernel.org/r/20210614163150.7774-3-stephan@gerhold.net Signed-off-by: Jonathan Cameron --- .../devicetree/bindings/iio/accel/bosch,bma255.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml index b37ba902e4a2..f35c57b8105f 100644 --- a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml @@ -16,15 +16,15 @@ description: properties: compatible: enum: - - bosch,bmc150_accel - - bosch,bmi055_accel + - bosch,bma222 + - bosch,bma222e + - bosch,bma250e - bosch,bma253 - bosch,bma254 - bosch,bma255 - - bosch,bma250e - - bosch,bma222 - - bosch,bma222e - bosch,bma280 + - bosch,bmc150_accel + - bosch,bmi055_accel reg: maxItems: 1 From 7e6b78663c2fb96adaff613f2a25c177c7fbd3c4 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 14 Jun 2021 18:31:50 +0200 Subject: [PATCH 41/77] dt-bindings: iio: accel: bma255: Merge bosch,bma180 schema In Linux the bma180 and bmc150-accel driver cover fairly similar chips from Bosch (just with minor register differences). For the DT schema, this does not make any difference: They both represent I2C/SPI devices, have one or two interrupts plus a vdd/vddio-supply. This means there is no need to duplicate the schema, we can just document the compatibles for both drivers in a single DT schema. Suggested-by: Jonathan Cameron Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20210614163150.7774-4-stephan@gerhold.net Signed-off-by: Jonathan Cameron --- .../bindings/iio/accel/bosch,bma180.yaml | 61 ------------------- .../bindings/iio/accel/bosch,bma255.yaml | 9 +++ 2 files changed, 9 insertions(+), 61 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bma180.yaml diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma180.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma180.yaml deleted file mode 100644 index a7e84089cc3d..000000000000 --- a/Documentation/devicetree/bindings/iio/accel/bosch,bma180.yaml +++ /dev/null @@ -1,61 +0,0 @@ -# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/iio/accel/bosch,bma180.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Bosch BMA023 / BMA150/ BMA180 / BMA250 / SMB380 triaxial accelerometers - -maintainers: - - Jonathan Cameron - -description: | - https://media.digikey.com/pdf/Data%20Sheets/Bosch/BMA150.pdf - http://omapworld.com/BMA180_111_1002839.pdf - http://ae-bst.resource.bosch.com/media/products/dokumente/bma250/bst-bma250-ds002-05.pdf - -properties: - compatible: - enum: - - bosch,bma023 - - bosch,bma150 - - bosch,bma180 - - bosch,bma250 - - bosch,smb380 - - reg: - maxItems: 1 - - vdd-supply: true - - vddio-supply: true - - interrupts: - minItems: 1 - maxItems: 2 - description: | - Type should be either IRQ_TYPE_LEVEL_HIGH or IRQ_TYPE_EDGE_RISING. - For the bma250 the first interrupt listed must be the one - connected to the INT1 pin, the second (optional) interrupt - listed must be the one connected to the INT2 pin. - -required: - - compatible - - reg - -additionalProperties: false - -examples: - - | - #include - i2c { - #address-cells = <1>; - #size-cells = <0>; - accel@40 { - compatible = "bosch,bma180"; - reg = <0x40>; - interrupt-parent = <&gpio6>; - interrupts = <18 (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING)>; - }; - }; -... diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml index f35c57b8105f..5b35856b1942 100644 --- a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml @@ -8,6 +8,7 @@ title: Bosch BMA255 and Similar Accelerometers maintainers: - Linus Walleij + - Stephan Gerhold description: 3 axis accelerometers with varying range and I2C or SPI @@ -16,6 +17,7 @@ description: properties: compatible: enum: + # bmc150-accel driver in Linux - bosch,bma222 - bosch,bma222e - bosch,bma250e @@ -26,6 +28,13 @@ properties: - bosch,bmc150_accel - bosch,bmi055_accel + # bma180 driver in Linux + - bosch,bma023 + - bosch,bma150 + - bosch,bma180 + - bosch,bma250 + - bosch,smb380 + reg: maxItems: 1 From 9c6cd755b548767ae1780fa41967ac602604d456 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Tue, 8 Jun 2021 18:51:49 +0100 Subject: [PATCH 42/77] iio: st-sensors: Remove some unused includes and add some that should be there The st-sensors drivers have changed in structure over time, and includes have not always kept up with this. Let's bring them back to nearer the ideal. Identified with the include-what-you-use tool and careful checking of its suggestions. Note I haven't been particularly aggressive here, so this is just the cases where the include obviously isn't needed rather than the more subtle corners. Note I took the opportunity to add mod_devicetable.h as I generally prefer to see that when acpi or of match tables are present. Signed-off-by: Jonathan Cameron Cc: Linus Walleij Cc: Denis Ciocca Cc: Hans de Goede Acked-by: Linus Walleij Link: https://lore.kernel.org/r/20210608175149.4019289-1-jic23@kernel.org --- drivers/iio/accel/st_accel_buffer.c | 7 +------ drivers/iio/accel/st_accel_core.c | 8 ++------ drivers/iio/accel/st_accel_i2c.c | 3 +-- drivers/iio/accel/st_accel_spi.c | 2 +- drivers/iio/common/st_sensors/st_sensors_buffer.c | 2 -- drivers/iio/common/st_sensors/st_sensors_core.c | 1 + drivers/iio/common/st_sensors/st_sensors_core.h | 1 + drivers/iio/common/st_sensors/st_sensors_i2c.c | 3 +-- drivers/iio/common/st_sensors/st_sensors_spi.c | 3 +-- drivers/iio/common/st_sensors/st_sensors_trigger.c | 1 - drivers/iio/gyro/st_gyro_buffer.c | 7 +------ drivers/iio/gyro/st_gyro_core.c | 9 ++------- drivers/iio/gyro/st_gyro_i2c.c | 2 +- drivers/iio/gyro/st_gyro_spi.c | 2 +- drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c | 1 + drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c | 3 ++- drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c | 3 ++- drivers/iio/magnetometer/st_magn_buffer.c | 7 +------ drivers/iio/magnetometer/st_magn_core.c | 11 +++-------- drivers/iio/magnetometer/st_magn_i2c.c | 2 +- drivers/iio/magnetometer/st_magn_spi.c | 2 +- drivers/iio/pressure/st_pressure_buffer.c | 7 +------ drivers/iio/pressure/st_pressure_core.c | 10 ++-------- drivers/iio/pressure/st_pressure_i2c.c | 3 ++- drivers/iio/pressure/st_pressure_spi.c | 2 +- 25 files changed, 31 insertions(+), 71 deletions(-) diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c index 492263589e04..f89770f251d9 100644 --- a/drivers/iio/accel/st_accel_buffer.c +++ b/drivers/iio/accel/st_accel_buffer.c @@ -9,14 +9,9 @@ #include #include -#include -#include -#include -#include -#include #include #include -#include +#include #include #include diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 28fceac9f2f6..365e4e64ca18 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -9,17 +9,13 @@ #include #include +#include +#include #include #include -#include -#include -#include -#include -#include #include #include #include -#include #include #include "st_accel.h" diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index 95e305b88d5e..f711756e41e3 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -9,11 +9,10 @@ #include #include -#include +#include #include #include #include -#include #include #include "st_accel.h" diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c index 83d3308ce5cc..bb45d9ff95b8 100644 --- a/drivers/iio/accel/st_accel_spi.c +++ b/drivers/iio/accel/st_accel_spi.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c index 802f9ae04cf4..dccc471e79da 100644 --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c @@ -9,13 +9,11 @@ #include #include -#include #include #include #include #include #include -#include #include #include diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 7a69c1be7393..0bbb090b108c 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/iio/common/st_sensors/st_sensors_core.h b/drivers/iio/common/st_sensors/st_sensors_core.h index e8894be55660..09f3e602a2e2 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.h +++ b/drivers/iio/common/st_sensors/st_sensors_core.h @@ -4,6 +4,7 @@ */ #ifndef __ST_SENSORS_CORE_H #define __ST_SENSORS_CORE_H +struct iio_dev; int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, u8 reg_addr, u8 mask, u8 data); #endif diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c index b9e59ad32a02..b3ff88700866 100644 --- a/drivers/iio/common/st_sensors/st_sensors_i2c.c +++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c @@ -7,15 +7,14 @@ * Denis Ciocca */ +#include #include #include -#include #include #include #include - #define ST_SENSORS_I2C_MULTIREAD 0x80 static const struct regmap_config st_sensors_i2c_regmap_config = { diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c index 48fc41dc5633..0d1d66c77cd8 100644 --- a/drivers/iio/common/st_sensors/st_sensors_spi.c +++ b/drivers/iio/common/st_sensors/st_sensors_spi.c @@ -9,13 +9,12 @@ #include #include -#include #include #include #include +#include #include -#include "st_sensors_core.h" #define ST_SENSORS_SPI_MULTIREAD 0xc0 diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c index 0b511665dee5..64e0a748a855 100644 --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c @@ -9,7 +9,6 @@ #include #include -#include #include #include #include diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c index 4feb7ada7195..02b5562b6585 100644 --- a/drivers/iio/gyro/st_gyro_buffer.c +++ b/drivers/iio/gyro/st_gyro_buffer.c @@ -9,14 +9,9 @@ #include #include -#include -#include -#include -#include -#include #include #include -#include +#include #include #include diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index b86ee4d940d9..fe227ad400f0 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -9,17 +9,12 @@ #include #include -#include -#include -#include +#include #include -#include -#include -#include +#include #include #include #include -#include #include #include "st_gyro.h" diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c index a25cc0379e16..3ef86e16ee65 100644 --- a/drivers/iio/gyro/st_gyro_i2c.c +++ b/drivers/iio/gyro/st_gyro_i2c.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c index 18d6a2aeda45..41d835493347 100644 --- a/drivers/iio/gyro/st_gyro_spi.c +++ b/drivers/iio/gyro/st_gyro_spi.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c index 8204f7303fd7..5e6625140db7 100644 --- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c +++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c index 50a36ab53bc3..78bede358747 100644 --- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c @@ -10,7 +10,8 @@ #include #include #include -#include +#include +#include #include diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c index 272c88990dd0..180b54e66438 100644 --- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c +++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c @@ -9,7 +9,8 @@ #include #include -#include +#include +#include #include #include diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c index 4917721fa2e5..68f01714304f 100644 --- a/drivers/iio/magnetometer/st_magn_buffer.c +++ b/drivers/iio/magnetometer/st_magn_buffer.c @@ -9,14 +9,9 @@ #include #include -#include -#include -#include -#include -#include #include #include -#include +#include #include #include diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 0048c3cd36ee..2c44a92590fc 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -9,16 +9,11 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include -#include +#include #include #include "st_magn.h" diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c index 3e23c117de8e..2dfe4ee99591 100644 --- a/drivers/iio/magnetometer/st_magn_i2c.c +++ b/drivers/iio/magnetometer/st_magn_i2c.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c index 03c0a737aba6..fba978796395 100644 --- a/drivers/iio/magnetometer/st_magn_spi.c +++ b/drivers/iio/magnetometer/st_magn_spi.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c index 7cf6f06797e1..b651e7c31e90 100644 --- a/drivers/iio/pressure/st_pressure_buffer.c +++ b/drivers/iio/pressure/st_pressure_buffer.c @@ -9,14 +9,9 @@ #include #include -#include -#include -#include -#include -#include #include #include -#include +#include #include #include diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index 7912b5a68395..4ff6d40e3670 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c @@ -9,17 +9,11 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include -#include #include #include diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c index f0a5af314ceb..52fa98f24478 100644 --- a/drivers/iio/pressure/st_pressure_i2c.c +++ b/drivers/iio/pressure/st_pressure_i2c.c @@ -7,9 +7,10 @@ * Denis Ciocca */ +#include #include #include -#include +#include #include #include diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c index b48cf7d01cd7..ee393df54cee 100644 --- a/drivers/iio/pressure/st_pressure_spi.c +++ b/drivers/iio/pressure/st_pressure_spi.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include From f5e9e38e7063dbe2c811bb5ee7d255318eb064b3 Mon Sep 17 00:00:00 2001 From: Ivan Mikhaylov Date: Thu, 22 Jul 2021 18:44:18 +0300 Subject: [PATCH 43/77] iio: proximity: vcnl3020: add DMA safe buffer Add DMA safe buffer for bulk transfers. Signed-off-by: Ivan Mikhaylov Link: https://lore.kernel.org/r/20210722154420.915082-2-i.mikhaylov@yadro.com Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/vcnl3020.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iio/proximity/vcnl3020.c b/drivers/iio/proximity/vcnl3020.c index 43817f6b3086..c90f9c6e9e97 100644 --- a/drivers/iio/proximity/vcnl3020.c +++ b/drivers/iio/proximity/vcnl3020.c @@ -57,12 +57,14 @@ static const int vcnl3020_prox_sampling_frequency[][2] = { * @dev: vcnl3020 device. * @rev: revision id. * @lock: lock for protecting access to device hardware registers. + * @buf: DMA safe __be16 buffer. */ struct vcnl3020_data { struct regmap *regmap; struct device *dev; u8 rev; struct mutex lock; + __be16 buf ____cacheline_aligned; }; /** @@ -144,7 +146,6 @@ static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val) { int rc; unsigned int reg; - __be16 res; mutex_lock(&data->lock); @@ -163,12 +164,12 @@ static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val) } /* high & low result bytes read */ - rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &res, - sizeof(res)); + rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &data->buf, + sizeof(data->buf)); if (rc) goto err_unlock; - *val = be16_to_cpu(res); + *val = be16_to_cpu(data->buf); err_unlock: mutex_unlock(&data->lock); From 3363fbbe19e542e183bcc32780cf1d5d4156a5b2 Mon Sep 17 00:00:00 2001 From: Ivan Mikhaylov Date: Thu, 22 Jul 2021 18:44:19 +0300 Subject: [PATCH 44/77] iio: proximity: vcnl3020: add periodic mode Add the possibility to run proximity sensor in periodic measurement mode with thresholds. Reported-by: kernel test robot #repeated include Signed-off-by: Ivan Mikhaylov Link: https://lore.kernel.org/r/20210722154420.915082-3-i.mikhaylov@yadro.com Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/vcnl3020.c | 315 ++++++++++++++++++++++++++++++- 1 file changed, 312 insertions(+), 3 deletions(-) diff --git a/drivers/iio/proximity/vcnl3020.c b/drivers/iio/proximity/vcnl3020.c index c90f9c6e9e97..bcc4cef127a4 100644 --- a/drivers/iio/proximity/vcnl3020.c +++ b/drivers/iio/proximity/vcnl3020.c @@ -2,8 +2,6 @@ /* * Support for Vishay VCNL3020 proximity sensor on i2c bus. * Based on Vishay VCNL4000 driver code. - * - * TODO: interrupts. */ #include @@ -11,9 +9,10 @@ #include #include #include +#include #include -#include +#include #define VCNL3020_PROD_ID 0x21 @@ -37,6 +36,21 @@ * measurement */ +/* Enables periodic proximity measurement */ +#define VCNL_PS_EN BIT(1) + +/* Enables state machine and LP oscillator for self timed measurements */ +#define VCNL_PS_SELFTIMED_EN BIT(0) + +/* Bit masks for ICR */ + +/* Enable interrupts on low or high thresholds */ +#define VCNL_ICR_THRES_EN BIT(1) + +/* Bit masks for ISR */ +#define VCNL_INT_TH_HI BIT(0) /* High threshold hit */ +#define VCNL_INT_TH_LOW BIT(1) /* Low threshold hit */ + #define VCNL_ON_DEMAND_TIMEOUT_US 100000 #define VCNL_POLL_US 20000 @@ -142,6 +156,21 @@ static int vcnl3020_init(struct vcnl3020_data *data) vcnl3020_led_current_property); }; +static bool vcnl3020_is_in_periodic_mode(struct vcnl3020_data *data) +{ + int rc; + unsigned int cmd; + + rc = regmap_read(data->regmap, VCNL_COMMAND, &cmd); + if (rc) { + dev_err(data->dev, + "Error (%d) reading command register\n", rc); + return false; + } + + return !!(cmd & VCNL_PS_SELFTIMED_EN); +} + static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val) { int rc; @@ -149,6 +178,12 @@ static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val) mutex_lock(&data->lock); + /* Protect against event capture. */ + if (vcnl3020_is_in_periodic_mode(data)) { + rc = -EBUSY; + goto err_unlock; + } + rc = regmap_write(data->regmap, VCNL_COMMAND, VCNL_PS_OD); if (rc) goto err_unlock; @@ -202,6 +237,10 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val, unsigned int i; int index = -1; + /* Protect against event capture. */ + if (vcnl3020_is_in_periodic_mode(data)) + return -EBUSY; + for (i = 0; i < ARRAY_SIZE(vcnl3020_prox_sampling_frequency); i++) { if (val == vcnl3020_prox_sampling_frequency[i][0] && val2 == vcnl3020_prox_sampling_frequency[i][1]) { @@ -216,12 +255,234 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val, return regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index); } +static bool vcnl3020_is_thr_enabled(struct vcnl3020_data *data) +{ + int rc; + unsigned int icr; + + rc = regmap_read(data->regmap, VCNL_PS_ICR, &icr); + if (rc) { + dev_err(data->dev, + "Error (%d) reading ICR register\n", rc); + return false; + } + + return !!(icr & VCNL_ICR_THRES_EN); +} + +static int vcnl3020_read_event(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2) +{ + int rc; + struct vcnl3020_data *data = iio_priv(indio_dev); + + switch (info) { + case IIO_EV_INFO_VALUE: + switch (dir) { + case IIO_EV_DIR_RISING: + rc = regmap_bulk_read(data->regmap, VCNL_PS_HI_THR_HI, + &data->buf, sizeof(data->buf)); + if (rc < 0) + return rc; + *val = be16_to_cpu(data->buf); + return IIO_VAL_INT; + case IIO_EV_DIR_FALLING: + rc = regmap_bulk_read(data->regmap, VCNL_PS_LO_THR_HI, + &data->buf, sizeof(data->buf)); + if (rc < 0) + return rc; + *val = be16_to_cpu(data->buf); + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +static int vcnl3020_write_event(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2) +{ + int rc; + struct vcnl3020_data *data = iio_priv(indio_dev); + + mutex_lock(&data->lock); + + switch (info) { + case IIO_EV_INFO_VALUE: + switch (dir) { + case IIO_EV_DIR_RISING: + /* 16 bit word/ low * high */ + data->buf = cpu_to_be16(val); + rc = regmap_bulk_write(data->regmap, VCNL_PS_HI_THR_HI, + &data->buf, sizeof(data->buf)); + if (rc < 0) + goto err_unlock; + rc = IIO_VAL_INT; + goto err_unlock; + case IIO_EV_DIR_FALLING: + data->buf = cpu_to_be16(val); + rc = regmap_bulk_write(data->regmap, VCNL_PS_LO_THR_HI, + &data->buf, sizeof(data->buf)); + if (rc < 0) + goto err_unlock; + rc = IIO_VAL_INT; + goto err_unlock; + default: + rc = -EINVAL; + goto err_unlock; + } + default: + rc = -EINVAL; + goto err_unlock; + } +err_unlock: + mutex_unlock(&data->lock); + + return rc; +} + +static int vcnl3020_enable_periodic(struct iio_dev *indio_dev, + struct vcnl3020_data *data) +{ + int rc; + int cmd; + + mutex_lock(&data->lock); + + /* Enable periodic measurement of proximity data. */ + cmd = VCNL_PS_EN | VCNL_PS_SELFTIMED_EN; + + rc = regmap_write(data->regmap, VCNL_COMMAND, cmd); + if (rc) { + dev_err(data->dev, + "Error (%d) writing command register\n", rc); + goto err_unlock; + } + + /* + * Enable interrupts on threshold, for proximity data by + * default. + */ + rc = regmap_write(data->regmap, VCNL_PS_ICR, VCNL_ICR_THRES_EN); + if (rc) + dev_err(data->dev, + "Error (%d) reading ICR register\n", rc); + +err_unlock: + mutex_unlock(&data->lock); + + return rc; +} + +static int vcnl3020_disable_periodic(struct iio_dev *indio_dev, + struct vcnl3020_data *data) +{ + int rc; + + mutex_lock(&data->lock); + + rc = regmap_write(data->regmap, VCNL_COMMAND, 0); + if (rc) { + dev_err(data->dev, + "Error (%d) writing command register\n", rc); + goto err_unlock; + } + + rc = regmap_write(data->regmap, VCNL_PS_ICR, 0); + if (rc) { + dev_err(data->dev, + "Error (%d) writing ICR register\n", rc); + goto err_unlock; + } + + /* Clear interrupt flag bit */ + rc = regmap_write(data->regmap, VCNL_ISR, 0); + if (rc) + dev_err(data->dev, + "Error (%d) writing ISR register\n", rc); + +err_unlock: + mutex_unlock(&data->lock); + + return rc; +} + +static int vcnl3020_config_threshold(struct iio_dev *indio_dev, bool state) +{ + struct vcnl3020_data *data = iio_priv(indio_dev); + + if (state) { + return vcnl3020_enable_periodic(indio_dev, data); + } else { + if (!vcnl3020_is_thr_enabled(data)) + return 0; + return vcnl3020_disable_periodic(indio_dev, data); + } +} + +static int vcnl3020_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + int state) +{ + switch (chan->type) { + case IIO_PROXIMITY: + return vcnl3020_config_threshold(indio_dev, state); + default: + return -EINVAL; + } +} + +static int vcnl3020_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct vcnl3020_data *data = iio_priv(indio_dev); + + switch (chan->type) { + case IIO_PROXIMITY: + return vcnl3020_is_thr_enabled(data); + default: + return -EINVAL; + } +} + +static const struct iio_event_spec vcnl3020_event_spec[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE), + }, { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_VALUE), + }, { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_EITHER, + .mask_separate = BIT(IIO_EV_INFO_ENABLE), + }, +}; + static const struct iio_chan_spec vcnl3020_channels[] = { { .type = IIO_PROXIMITY, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SAMP_FREQ), .info_mask_separate_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .event_spec = vcnl3020_event_spec, + .num_event_specs = ARRAY_SIZE(vcnl3020_event_spec), }, }; @@ -288,6 +549,10 @@ static const struct iio_info vcnl3020_info = { .read_raw = vcnl3020_read_raw, .write_raw = vcnl3020_write_raw, .read_avail = vcnl3020_read_avail, + .read_event_value = vcnl3020_read_event, + .write_event_value = vcnl3020_write_event, + .read_event_config = vcnl3020_read_event_config, + .write_event_config = vcnl3020_write_event_config, }; static const struct regmap_config vcnl3020_regmap_config = { @@ -296,6 +561,37 @@ static const struct regmap_config vcnl3020_regmap_config = { .max_register = VCNL_PS_MOD_ADJ, }; +static irqreturn_t vcnl3020_handle_irq_thread(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct vcnl3020_data *data = iio_priv(indio_dev); + unsigned int isr; + int rc; + + rc = regmap_read(data->regmap, VCNL_ISR, &isr); + if (rc) { + dev_err(data->dev, "Error (%d) reading reg (0x%x)\n", + rc, VCNL_ISR); + return IRQ_HANDLED; + } + + if (!(isr & VCNL_ICR_THRES_EN)) + return IRQ_NONE; + + iio_push_event(indio_dev, + IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_RISING), + iio_get_time_ns(indio_dev)); + + rc = regmap_write(data->regmap, VCNL_ISR, isr & VCNL_ICR_THRES_EN); + if (rc) + dev_err(data->dev, "Error (%d) writing in reg (0x%x)\n", + rc, VCNL_ISR); + + return IRQ_HANDLED; +} + static int vcnl3020_probe(struct i2c_client *client) { struct vcnl3020_data *data; @@ -328,6 +624,19 @@ static int vcnl3020_probe(struct i2c_client *client) indio_dev->name = "vcnl3020"; indio_dev->modes = INDIO_DIRECT_MODE; + if (client->irq) { + rc = devm_request_threaded_irq(&client->dev, client->irq, + NULL, vcnl3020_handle_irq_thread, + IRQF_ONESHOT, indio_dev->name, + indio_dev); + if (rc) { + dev_err(&client->dev, + "Error (%d) irq request failed (%u)\n", rc, + client->irq); + return rc; + } + } + return devm_iio_device_register(&client->dev, indio_dev); } From 7ff98c8afa46ea0ca207bcc89185ea28e6e83829 Mon Sep 17 00:00:00 2001 From: Ivan Mikhaylov Date: Thu, 22 Jul 2021 18:44:20 +0300 Subject: [PATCH 45/77] iio: proximity: vcnl3020: remove iio_claim/release_direct Remove iio_claim/release and change it on mutex accordingly in vcnl3020_write_proxy_samp_freq. Signed-off-by: Ivan Mikhaylov Link: https://lore.kernel.org/r/20210722154420.915082-4-i.mikhaylov@yadro.com Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/vcnl3020.c | 33 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/iio/proximity/vcnl3020.c b/drivers/iio/proximity/vcnl3020.c index bcc4cef127a4..ff83638db16f 100644 --- a/drivers/iio/proximity/vcnl3020.c +++ b/drivers/iio/proximity/vcnl3020.c @@ -236,10 +236,15 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val, { unsigned int i; int index = -1; + int rc; + + mutex_lock(&data->lock); /* Protect against event capture. */ - if (vcnl3020_is_in_periodic_mode(data)) - return -EBUSY; + if (vcnl3020_is_in_periodic_mode(data)) { + rc = -EBUSY; + goto err_unlock; + } for (i = 0; i < ARRAY_SIZE(vcnl3020_prox_sampling_frequency); i++) { if (val == vcnl3020_prox_sampling_frequency[i][0] && @@ -249,10 +254,20 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val, } } - if (index < 0) - return -EINVAL; + if (index < 0) { + rc = -EINVAL; + goto err_unlock; + } - return regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index); + rc = regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index); + if (rc) + dev_err(data->dev, + "Error (%d) writing proximity rate register\n", rc); + +err_unlock: + mutex_unlock(&data->lock); + + return rc; } static bool vcnl3020_is_thr_enabled(struct vcnl3020_data *data) @@ -513,17 +528,11 @@ static int vcnl3020_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - int rc; struct vcnl3020_data *data = iio_priv(indio_dev); switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: - rc = iio_device_claim_direct_mode(indio_dev); - if (rc) - return rc; - rc = vcnl3020_write_proxy_samp_freq(data, val, val2); - iio_device_release_direct_mode(indio_dev); - return rc; + return vcnl3020_write_proxy_samp_freq(data, val, val2); default: return -EINVAL; } From 78a6af334662879780718b18d91dc5f2576f5e5d Mon Sep 17 00:00:00 2001 From: Tang Bin Date: Tue, 20 Jul 2021 20:59:45 +0800 Subject: [PATCH 46/77] iio: adc: fsl-imx25-gcq: Use the defined variable to clean code Use the defined variable "dev" to make the code cleaner. Co-developed-by: Zhang Shengju Signed-off-by: Zhang Shengju Signed-off-by: Tang Bin Link: https://lore.kernel.org/r/20210720125945.11548-1-tangbin@cmss.chinamobile.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/fsl-imx25-gcq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c index ab5139e911c3..0c771d60541a 100644 --- a/drivers/iio/adc/fsl-imx25-gcq.c +++ b/drivers/iio/adc/fsl-imx25-gcq.c @@ -201,11 +201,11 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, */ priv->vref[MX25_ADC_REFP_INT] = NULL; priv->vref[MX25_ADC_REFP_EXT] = - devm_regulator_get_optional(&pdev->dev, "vref-ext"); + devm_regulator_get_optional(dev, "vref-ext"); priv->vref[MX25_ADC_REFP_XP] = - devm_regulator_get_optional(&pdev->dev, "vref-xp"); + devm_regulator_get_optional(dev, "vref-xp"); priv->vref[MX25_ADC_REFP_YP] = - devm_regulator_get_optional(&pdev->dev, "vref-yp"); + devm_regulator_get_optional(dev, "vref-yp"); for_each_child_of_node(np, child) { u32 reg; @@ -307,7 +307,7 @@ static int mx25_gcq_probe(struct platform_device *pdev) int ret; int i; - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); if (!indio_dev) return -ENOMEM; From 674db1e9217a8cebe4e348989f9e9ec428ff2859 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Tue, 20 Jul 2021 10:46:39 +0300 Subject: [PATCH 47/77] iio: pressure: st_pressure: use devm_iio_triggered_buffer_setup() for buffer The st_press_allocate_ring() function calls iio_triggered_buffer_setup() to allocate a triggered buffer. But the same can be done with devm_iio_triggered_buffer_setup() and then the st_press_common_remove() no longer needs to manually deallocate it. We know that the parent of the IIO device is used to manage other instances of the devm unwind, so it can be used in the st_press_allocate_ring() as well. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210720074642.223293-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/pressure/st_pressure.h | 5 ----- drivers/iio/pressure/st_pressure_buffer.c | 9 ++------- drivers/iio/pressure/st_pressure_core.c | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h index 9417b3bd7513..156e6a72dc5c 100644 --- a/drivers/iio/pressure/st_pressure.h +++ b/drivers/iio/pressure/st_pressure.h @@ -43,7 +43,6 @@ static __maybe_unused const struct st_sensors_platform_data default_press_pdata #ifdef CONFIG_IIO_BUFFER int st_press_allocate_ring(struct iio_dev *indio_dev); -void st_press_deallocate_ring(struct iio_dev *indio_dev); int st_press_trig_set_state(struct iio_trigger *trig, bool state); #define ST_PRESS_TRIGGER_SET_STATE (&st_press_trig_set_state) #else /* CONFIG_IIO_BUFFER */ @@ -51,10 +50,6 @@ static inline int st_press_allocate_ring(struct iio_dev *indio_dev) { return 0; } - -static inline void st_press_deallocate_ring(struct iio_dev *indio_dev) -{ -} #define ST_PRESS_TRIGGER_SET_STATE NULL #endif /* CONFIG_IIO_BUFFER */ diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c index b651e7c31e90..25dbd5476b26 100644 --- a/drivers/iio/pressure/st_pressure_buffer.c +++ b/drivers/iio/pressure/st_pressure_buffer.c @@ -41,13 +41,8 @@ static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = { int st_press_allocate_ring(struct iio_dev *indio_dev) { - return iio_triggered_buffer_setup(indio_dev, NULL, - &st_sensors_trigger_handler, &st_press_buffer_setup_ops); -} - -void st_press_deallocate_ring(struct iio_dev *indio_dev) -{ - iio_triggered_buffer_cleanup(indio_dev); + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, + NULL, &st_sensors_trigger_handler, &st_press_buffer_setup_ops); } MODULE_AUTHOR("Denis Ciocca "); diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index 4ff6d40e3670..ab1c17fac807 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c @@ -718,7 +718,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) err = st_sensors_allocate_trigger(indio_dev, ST_PRESS_TRIGGER_OPS); if (err < 0) - goto st_press_probe_trigger_error; + return err; } err = iio_device_register(indio_dev); @@ -733,8 +733,6 @@ int st_press_common_probe(struct iio_dev *indio_dev) st_press_device_register_error: if (press_data->irq > 0) st_sensors_deallocate_trigger(indio_dev); -st_press_probe_trigger_error: - st_press_deallocate_ring(indio_dev); return err; } EXPORT_SYMBOL(st_press_common_probe); @@ -746,8 +744,6 @@ void st_press_common_remove(struct iio_dev *indio_dev) iio_device_unregister(indio_dev); if (press_data->irq > 0) st_sensors_deallocate_trigger(indio_dev); - - st_press_deallocate_ring(indio_dev); } EXPORT_SYMBOL(st_press_common_remove); From a442673b40f22be1d7ce7bfb9626461638a638da Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Tue, 20 Jul 2021 10:46:40 +0300 Subject: [PATCH 48/77] iio: accel: st_accel: use devm_iio_triggered_buffer_setup() for buffer The st_accel_allocate_ring() function calls iio_triggered_buffer_setup() to allocate a triggered buffer. But the same can be done with devm_iio_triggered_buffer_setup() and then the st_accel_common_remove() no longer needs to manually deallocate it. We know that the parent of the IIO device is used to manage other instances of the devm unwind, so it can be used in the st_accel_allocate_ring() as well. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210720074642.223293-2-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/st_accel.h | 4 ---- drivers/iio/accel/st_accel_buffer.c | 9 ++------- drivers/iio/accel/st_accel_core.c | 6 +----- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h index f5b0b8bbaff7..8750dea56fcb 100644 --- a/drivers/iio/accel/st_accel.h +++ b/drivers/iio/accel/st_accel.h @@ -64,7 +64,6 @@ enum st_accel_type { #ifdef CONFIG_IIO_BUFFER int st_accel_allocate_ring(struct iio_dev *indio_dev); -void st_accel_deallocate_ring(struct iio_dev *indio_dev); int st_accel_trig_set_state(struct iio_trigger *trig, bool state); #define ST_ACCEL_TRIGGER_SET_STATE (&st_accel_trig_set_state) #else /* CONFIG_IIO_BUFFER */ @@ -72,9 +71,6 @@ static inline int st_accel_allocate_ring(struct iio_dev *indio_dev) { return 0; } -static inline void st_accel_deallocate_ring(struct iio_dev *indio_dev) -{ -} #define ST_ACCEL_TRIGGER_SET_STATE NULL #endif /* CONFIG_IIO_BUFFER */ diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c index f89770f251d9..fc82fa83f1fb 100644 --- a/drivers/iio/accel/st_accel_buffer.c +++ b/drivers/iio/accel/st_accel_buffer.c @@ -62,13 +62,8 @@ static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = { int st_accel_allocate_ring(struct iio_dev *indio_dev) { - return iio_triggered_buffer_setup(indio_dev, NULL, - &st_sensors_trigger_handler, &st_accel_buffer_setup_ops); -} - -void st_accel_deallocate_ring(struct iio_dev *indio_dev) -{ - iio_triggered_buffer_cleanup(indio_dev); + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, + NULL, &st_sensors_trigger_handler, &st_accel_buffer_setup_ops); } MODULE_AUTHOR("Denis Ciocca "); diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 365e4e64ca18..f1e6ec380667 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -1377,7 +1377,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) err = st_sensors_allocate_trigger(indio_dev, ST_ACCEL_TRIGGER_OPS); if (err < 0) - goto st_accel_probe_trigger_error; + return err; } err = iio_device_register(indio_dev); @@ -1392,8 +1392,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev) st_accel_device_register_error: if (adata->irq > 0) st_sensors_deallocate_trigger(indio_dev); -st_accel_probe_trigger_error: - st_accel_deallocate_ring(indio_dev); return err; } EXPORT_SYMBOL(st_accel_common_probe); @@ -1405,8 +1403,6 @@ void st_accel_common_remove(struct iio_dev *indio_dev) iio_device_unregister(indio_dev); if (adata->irq > 0) st_sensors_deallocate_trigger(indio_dev); - - st_accel_deallocate_ring(indio_dev); } EXPORT_SYMBOL(st_accel_common_remove); From 899f6791469f658d395199c33997391cdd53fa5e Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Tue, 20 Jul 2021 10:46:41 +0300 Subject: [PATCH 49/77] iio: magn: st_magn: use devm_iio_triggered_buffer_setup() for buffer The st_magn_allocate_ring() function calls iio_triggered_buffer_setup() to allocate a triggered buffer. But the same can be done with devm_iio_triggered_buffer_setup() and then the st_magn_common_remove() no longer needs to manually deallocate it. We know that the parent of the IIO device is used to manage other instances of the devm unwind, so it can be used in the st_magn_allocate_ring() as well. This change also removes some omitted st_magn_{probe,remove}_trigger() inline hooks. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210720074642.223293-3-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/magnetometer/st_magn.h | 12 ------------ drivers/iio/magnetometer/st_magn_buffer.c | 9 ++------- drivers/iio/magnetometer/st_magn_core.c | 6 +----- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h index fb6c906c4c0c..785b7f7b8b06 100644 --- a/drivers/iio/magnetometer/st_magn.h +++ b/drivers/iio/magnetometer/st_magn.h @@ -25,25 +25,13 @@ #ifdef CONFIG_IIO_BUFFER int st_magn_allocate_ring(struct iio_dev *indio_dev); -void st_magn_deallocate_ring(struct iio_dev *indio_dev); int st_magn_trig_set_state(struct iio_trigger *trig, bool state); #define ST_MAGN_TRIGGER_SET_STATE (&st_magn_trig_set_state) #else /* CONFIG_IIO_BUFFER */ -static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq) -{ - return 0; -} -static inline void st_magn_remove_trigger(struct iio_dev *indio_dev, int irq) -{ - return; -} static inline int st_magn_allocate_ring(struct iio_dev *indio_dev) { return 0; } -static inline void st_magn_deallocate_ring(struct iio_dev *indio_dev) -{ -} #define ST_MAGN_TRIGGER_SET_STATE NULL #endif /* CONFIG_IIO_BUFFER */ diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c index 68f01714304f..cb43ccda808d 100644 --- a/drivers/iio/magnetometer/st_magn_buffer.c +++ b/drivers/iio/magnetometer/st_magn_buffer.c @@ -41,13 +41,8 @@ static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = { int st_magn_allocate_ring(struct iio_dev *indio_dev) { - return iio_triggered_buffer_setup(indio_dev, NULL, - &st_sensors_trigger_handler, &st_magn_buffer_setup_ops); -} - -void st_magn_deallocate_ring(struct iio_dev *indio_dev) -{ - iio_triggered_buffer_cleanup(indio_dev); + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, + NULL, &st_sensors_trigger_handler, &st_magn_buffer_setup_ops); } MODULE_AUTHOR("Denis Ciocca "); diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 2c44a92590fc..9ffd50d796bf 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -647,7 +647,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev) err = st_sensors_allocate_trigger(indio_dev, ST_MAGN_TRIGGER_OPS); if (err < 0) - goto st_magn_probe_trigger_error; + return err; } err = iio_device_register(indio_dev); @@ -662,8 +662,6 @@ int st_magn_common_probe(struct iio_dev *indio_dev) st_magn_device_register_error: if (mdata->irq > 0) st_sensors_deallocate_trigger(indio_dev); -st_magn_probe_trigger_error: - st_magn_deallocate_ring(indio_dev); return err; } EXPORT_SYMBOL(st_magn_common_probe); @@ -675,8 +673,6 @@ void st_magn_common_remove(struct iio_dev *indio_dev) iio_device_unregister(indio_dev); if (mdata->irq > 0) st_sensors_deallocate_trigger(indio_dev); - - st_magn_deallocate_ring(indio_dev); } EXPORT_SYMBOL(st_magn_common_remove); From a574e68ff5135d4782260ad38d4b29b8e94e44d6 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Tue, 20 Jul 2021 10:46:42 +0300 Subject: [PATCH 50/77] iio: gyro: st_gyro: use devm_iio_triggered_buffer_setup() for buffer The st_gyro_allocate_ring() function calls iio_triggered_buffer_setup() to allocate a triggered buffer. But the same can be done with devm_iio_triggered_buffer_setup() and then the st_gyro_common_remove() no longer needs to manually deallocate it. We know that the parent of the IIO device is used to manage other instances of the devm unwind, so it can be used in the st_gyro_allocate_ring() as well. Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210720074642.223293-4-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- drivers/iio/gyro/st_gyro.h | 4 ---- drivers/iio/gyro/st_gyro_buffer.c | 9 ++------- drivers/iio/gyro/st_gyro_core.c | 6 +----- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h index 6537f5cb8320..f5332b6a02bc 100644 --- a/drivers/iio/gyro/st_gyro.h +++ b/drivers/iio/gyro/st_gyro.h @@ -26,7 +26,6 @@ #ifdef CONFIG_IIO_BUFFER int st_gyro_allocate_ring(struct iio_dev *indio_dev); -void st_gyro_deallocate_ring(struct iio_dev *indio_dev); int st_gyro_trig_set_state(struct iio_trigger *trig, bool state); #define ST_GYRO_TRIGGER_SET_STATE (&st_gyro_trig_set_state) #else /* CONFIG_IIO_BUFFER */ @@ -34,9 +33,6 @@ static inline int st_gyro_allocate_ring(struct iio_dev *indio_dev) { return 0; } -static inline void st_gyro_deallocate_ring(struct iio_dev *indio_dev) -{ -} #define ST_GYRO_TRIGGER_SET_STATE NULL #endif /* CONFIG_IIO_BUFFER */ diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c index 02b5562b6585..4ae33ef25b9c 100644 --- a/drivers/iio/gyro/st_gyro_buffer.c +++ b/drivers/iio/gyro/st_gyro_buffer.c @@ -61,13 +61,8 @@ static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = { int st_gyro_allocate_ring(struct iio_dev *indio_dev) { - return iio_triggered_buffer_setup(indio_dev, NULL, - &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops); -} - -void st_gyro_deallocate_ring(struct iio_dev *indio_dev) -{ - iio_triggered_buffer_cleanup(indio_dev); + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, + NULL, &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops); } MODULE_AUTHOR("Denis Ciocca "); diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index fe227ad400f0..e8fc8af65143 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -512,7 +512,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) err = st_sensors_allocate_trigger(indio_dev, ST_GYRO_TRIGGER_OPS); if (err < 0) - goto st_gyro_probe_trigger_error; + return err; } err = iio_device_register(indio_dev); @@ -527,8 +527,6 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) st_gyro_device_register_error: if (gdata->irq > 0) st_sensors_deallocate_trigger(indio_dev); -st_gyro_probe_trigger_error: - st_gyro_deallocate_ring(indio_dev); return err; } EXPORT_SYMBOL(st_gyro_common_probe); @@ -540,8 +538,6 @@ void st_gyro_common_remove(struct iio_dev *indio_dev) iio_device_unregister(indio_dev); if (gdata->irq > 0) st_sensors_deallocate_trigger(indio_dev); - - st_gyro_deallocate_ring(indio_dev); } EXPORT_SYMBOL(st_gyro_common_remove); From 48dc1abde015c6c62f05c4c29b73f77d175a2ee6 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Sun, 18 Jul 2021 01:37:16 +0200 Subject: [PATCH 51/77] iio: adc: meson-saradc: Disable BL30 integration on G12A and newer SoCs G12A and newer don't use the SAR ADC to read the SoC temperature from within the firmware. Instead there's now a dedicated thermal sensor. Disable the BL30 integration for G12A and newer SoCs to save a few CPU cycles when reading samples. Adding a separate struct meson_sar_adc_data is a good idea anyways because starting with G12A there's some extra registers to read the samples in a simplified way. Signed-off-by: Martin Blumenstingl Link: https://lore.kernel.org/r/20210717233718.332267-2-martin.blumenstingl@googlemail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/meson_saradc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index 66dc452d643a..e140db3e4016 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -1104,6 +1104,14 @@ static const struct meson_sar_adc_param meson_sar_adc_gxl_param = { .resolution = 12, }; +static const struct meson_sar_adc_param meson_sar_adc_g12a_param = { + .has_bl30_integration = false, + .clock_rate = 1200000, + .bandgap_reg = MESON_SAR_ADC_REG11, + .regmap_config = &meson_sar_adc_regmap_config_gxbb, + .resolution = 12, +}; + static const struct meson_sar_adc_data meson_sar_adc_meson8_data = { .param = &meson_sar_adc_meson8_param, .name = "meson-meson8-saradc", @@ -1140,7 +1148,7 @@ static const struct meson_sar_adc_data meson_sar_adc_axg_data = { }; static const struct meson_sar_adc_data meson_sar_adc_g12a_data = { - .param = &meson_sar_adc_gxl_param, + .param = &meson_sar_adc_g12a_param, .name = "meson-g12a-saradc", }; From 0e1d2a5ec77e98fa8a3362d5c28b367742325aa2 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Sun, 18 Jul 2021 01:37:17 +0200 Subject: [PATCH 52/77] iio: adc: meson-saradc: Add missing space between if and parenthesis Add a missing space between if and the opening parenthesis to make the coding style consistent across the whole driver. No functional changes intended. Signed-off-by: Martin Blumenstingl Link: https://lore.kernel.org/r/20210717233718.332267-3-martin.blumenstingl@googlemail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/meson_saradc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index e140db3e4016..b4e16f2e957f 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -347,7 +347,7 @@ static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev, struct meson_sar_adc_priv *priv = iio_priv(indio_dev); int regval, fifo_chan, fifo_val, count; - if(!wait_for_completion_timeout(&priv->done, + if (!wait_for_completion_timeout(&priv->done, msecs_to_jiffies(MESON_SAR_ADC_TIMEOUT))) return -ETIMEDOUT; From 9491b9177fd0015f4dd118e94328a3a768f4bea3 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Sun, 18 Jul 2021 01:37:18 +0200 Subject: [PATCH 53/77] iio: adc: meson-saradc: Fix indentation of arguments after a line-break Align the function arguments after a line-break with the opening parenthesis on the previous line. No functional changes intended. Signed-off-by: Martin Blumenstingl Link: https://lore.kernel.org/r/20210717233718.332267-4-martin.blumenstingl@googlemail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/meson_saradc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index b4e16f2e957f..705d5e11a54b 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -497,8 +497,8 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev) if (priv->param->has_bl30_integration) { /* prevent BL30 from using the SAR ADC while we are using it */ regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, - MESON_SAR_ADC_DELAY_KERNEL_BUSY, - MESON_SAR_ADC_DELAY_KERNEL_BUSY); + MESON_SAR_ADC_DELAY_KERNEL_BUSY, + MESON_SAR_ADC_DELAY_KERNEL_BUSY); /* * wait until BL30 releases it's lock (so we can use the SAR @@ -525,7 +525,7 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev) if (priv->param->has_bl30_integration) /* allow BL30 to use the SAR ADC again */ regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, - MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); + MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); mutex_unlock(&indio_dev->mlock); } @@ -791,7 +791,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev) * on the vendor driver), which we don't support at the moment. */ regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, - MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL, 0); + MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL, 0); /* disable all channels by default */ regmap_write(priv->regmap, MESON_SAR_ADC_CHAN_LIST, 0x0); From 7a3605bef87801bc7c86e23c608bd2d096433966 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Wed, 28 Jul 2021 11:17:57 -0700 Subject: [PATCH 54/77] iio: sx9310: Support ACPI property Use device_property_read_... to support both device tree and ACPI bindings. Simplify the logic for reading "combined-sensors" array, as we assume it has been vetted at firmware build time. Signed-off-by: Gwendal Grignou Reviewed-by: Stephen Boyd Link: https://lore.kernel.org/r/20210728181757.187627-1-gwendal@chromium.org Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/sx9310.c | 48 ++++++++++++---------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 175f3b7c61d7..a3fdb59b06d2 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -1221,10 +1222,9 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev) } static const struct sx9310_reg_default * -sx9310_get_default_reg(struct sx9310_data *data, int idx, +sx9310_get_default_reg(struct device *dev, int idx, struct sx9310_reg_default *reg_def) { - const struct device_node *np = data->client->dev.of_node; u32 combined[SX9310_NUM_CHANNELS]; u32 start = 0, raw = 0, pos = 0; unsigned long comb_mask = 0; @@ -1232,39 +1232,23 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, const char *res; memcpy(reg_def, &sx9310_default_regs[idx], sizeof(*reg_def)); - if (!np) - return reg_def; - switch (reg_def->reg) { case SX9310_REG_PROX_CTRL2: - if (of_property_read_bool(np, "semtech,cs0-ground")) { + if (device_property_read_bool(dev, "semtech,cs0-ground")) { reg_def->def &= ~SX9310_REG_PROX_CTRL2_SHIELDEN_MASK; reg_def->def |= SX9310_REG_PROX_CTRL2_SHIELDEN_GROUND; } - count = of_property_count_elems_of_size(np, "semtech,combined-sensors", - sizeof(u32)); - if (count > 0 && count <= ARRAY_SIZE(combined)) { - ret = of_property_read_u32_array(np, "semtech,combined-sensors", - combined, count); - if (ret) - break; - } else { - /* - * Either the property does not exist in the DT or the - * number of entries is incorrect. - */ + count = device_property_count_u32(dev, "semtech,combined-sensors"); + if (count < 0 || count > ARRAY_SIZE(combined)) break; - } - for (i = 0; i < count; i++) { - if (combined[i] >= SX9310_NUM_CHANNELS) { - /* Invalid sensor (invalid DT). */ - break; - } + ret = device_property_read_u32_array(dev, "semtech,combined-sensors", + combined, count); + if (ret) + break; + + for (i = 0; i < count; i++) comb_mask |= BIT(combined[i]); - } - if (i < count) - break; reg_def->def &= ~SX9310_REG_PROX_CTRL2_COMBMODE_MASK; if (comb_mask == (BIT(3) | BIT(2) | BIT(1) | BIT(0))) @@ -1278,7 +1262,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, break; case SX9310_REG_PROX_CTRL4: - ret = of_property_read_string(np, "semtech,resolution", &res); + ret = device_property_read_string(dev, "semtech,resolution", &res); if (ret) break; @@ -1302,7 +1286,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, break; case SX9310_REG_PROX_CTRL5: - ret = of_property_read_u32(np, "semtech,startup-sensor", &start); + ret = device_property_read_u32(dev, "semtech,startup-sensor", &start); if (ret) { start = FIELD_GET(SX9310_REG_PROX_CTRL5_STARTUPSENS_MASK, reg_def->def); @@ -1312,7 +1296,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, reg_def->def |= FIELD_PREP(SX9310_REG_PROX_CTRL5_STARTUPSENS_MASK, start); - ret = of_property_read_u32(np, "semtech,proxraw-strength", &raw); + ret = device_property_read_u32(dev, "semtech,proxraw-strength", &raw); if (ret) { raw = FIELD_GET(SX9310_REG_PROX_CTRL5_RAWFILT_MASK, reg_def->def); @@ -1325,7 +1309,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, raw); break; case SX9310_REG_PROX_CTRL7: - ret = of_property_read_u32(np, "semtech,avg-pos-strength", &pos); + ret = device_property_read_u32(dev, "semtech,avg-pos-strength", &pos); if (ret) break; @@ -1361,7 +1345,7 @@ static int sx9310_init_device(struct iio_dev *indio_dev) /* Program some sane defaults. */ for (i = 0; i < ARRAY_SIZE(sx9310_default_regs); i++) { - initval = sx9310_get_default_reg(data, i, &tmp); + initval = sx9310_get_default_reg(&indio_dev->dev, i, &tmp); ret = regmap_write(data->regmap, initval->reg, initval->def); if (ret) return ret; From 9c5eb724f96f8d15226d7500d9412737598930f1 Mon Sep 17 00:00:00 2001 From: Christophe Branchereau Date: Mon, 26 Jul 2021 10:20:29 +0200 Subject: [PATCH 55/77] iio/adc: ingenic: rename has_aux2 to has_aux_md The jz4760(b) socs have 3 aux channels. The purpose of has_aux2 is to set the MD bits used to select the AUX channel to be sampled, not to describe the hardware. Rename it to a more appropriate name. Signed-off-by: Christophe Branchereau Reviewed-by: Paul Cercueil Link: https://lore.kernel.org/r/20210726082033.351533-2-cbranchereau@gmail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ingenic-adc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c index 34c03a264f74..40f2d8c2cf72 100644 --- a/drivers/iio/adc/ingenic-adc.c +++ b/drivers/iio/adc/ingenic-adc.c @@ -92,7 +92,7 @@ struct ingenic_adc_soc_data { const int *battery_scale_avail; size_t battery_scale_avail_size; unsigned int battery_vref_mode: 1; - unsigned int has_aux2: 1; + unsigned int has_aux_md: 1; const struct iio_chan_spec *channels; unsigned int num_channels; int (*init_clk_div)(struct device *dev, struct ingenic_adc *adc); @@ -506,7 +506,7 @@ static const struct ingenic_adc_soc_data jz4725b_adc_soc_data = { .battery_scale_avail = jz4725b_adc_battery_scale_avail, .battery_scale_avail_size = ARRAY_SIZE(jz4725b_adc_battery_scale_avail), .battery_vref_mode = true, - .has_aux2 = false, + .has_aux_md = false, .channels = jz4740_channels, .num_channels = ARRAY_SIZE(jz4740_channels), .init_clk_div = jz4725b_adc_init_clk_div, @@ -520,7 +520,7 @@ static const struct ingenic_adc_soc_data jz4740_adc_soc_data = { .battery_scale_avail = jz4740_adc_battery_scale_avail, .battery_scale_avail_size = ARRAY_SIZE(jz4740_adc_battery_scale_avail), .battery_vref_mode = true, - .has_aux2 = false, + .has_aux_md = false, .channels = jz4740_channels, .num_channels = ARRAY_SIZE(jz4740_channels), .init_clk_div = NULL, /* no ADCLK register on JZ4740 */ @@ -534,7 +534,7 @@ static const struct ingenic_adc_soc_data jz4770_adc_soc_data = { .battery_scale_avail = jz4770_adc_battery_scale_avail, .battery_scale_avail_size = ARRAY_SIZE(jz4770_adc_battery_scale_avail), .battery_vref_mode = false, - .has_aux2 = true, + .has_aux_md = true, .channels = jz4770_channels, .num_channels = ARRAY_SIZE(jz4770_channels), .init_clk_div = jz4770_adc_init_clk_div, @@ -581,7 +581,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev, /* We cannot sample AUX/AUX2 in parallel. */ mutex_lock(&adc->aux_lock); - if (adc->soc_data->has_aux2 && engine == 0) { + if (adc->soc_data->has_aux_md && engine == 0) { bit = BIT(chan->channel == INGENIC_ADC_AUX2); ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, bit); } From d827cbcdb34e1972e31cf7e603410c05de584ca9 Mon Sep 17 00:00:00 2001 From: Christophe Branchereau Date: Mon, 26 Jul 2021 10:20:30 +0200 Subject: [PATCH 56/77] dt-bindings: iio/adc: add an INGENIC_ADC_AUX0 entry The JZ4760(B) socs have 3 AUX inputs, add an entry to prepare including the one named AUX in the sadc driver. Leaving the rest untouched as it's ABI. Signed-off-by: Christophe Branchereau Reviewed-by: Paul Cercueil Acked-by: Rob Herring Link: https://lore.kernel.org/r/20210726082033.351533-3-cbranchereau@gmail.com Signed-off-by: Jonathan Cameron --- include/dt-bindings/iio/adc/ingenic,adc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/iio/adc/ingenic,adc.h b/include/dt-bindings/iio/adc/ingenic,adc.h index 4627a00e369e..a6ccc031635b 100644 --- a/include/dt-bindings/iio/adc/ingenic,adc.h +++ b/include/dt-bindings/iio/adc/ingenic,adc.h @@ -13,5 +13,6 @@ #define INGENIC_ADC_TOUCH_YN 6 #define INGENIC_ADC_TOUCH_XD 7 #define INGENIC_ADC_TOUCH_YD 8 +#define INGENIC_ADC_AUX0 9 #endif From b9e9bdd425a3c99e15f5dfd465bef936130b7491 Mon Sep 17 00:00:00 2001 From: Christophe Branchereau Date: Mon, 26 Jul 2021 10:20:31 +0200 Subject: [PATCH 57/77] iio/adc: ingenic: add JZ4760 support to the sadc driver The jz4760 sadc is very similar to the jz4770 one, but has a VREF of 2.5V and 3 aux channels. modify ingenic_adc_read_chan_info_raw() needs a change to account for it. Signed-off-by: Christophe Branchereau Reviewed-by: Paul Cercueil Link: https://lore.kernel.org/r/20210726082033.351533-4-cbranchereau@gmail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ingenic-adc.c | 82 +++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c index 40f2d8c2cf72..6b9af0530590 100644 --- a/drivers/iio/adc/ingenic-adc.c +++ b/drivers/iio/adc/ingenic-adc.c @@ -71,6 +71,7 @@ #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS 10 #define JZ4740_ADC_BATTERY_HIGH_VREF (7500 * 0.986) #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS 12 +#define JZ4760_ADC_BATTERY_VREF 2500 #define JZ4770_ADC_BATTERY_VREF 1200 #define JZ4770_ADC_BATTERY_VREF_BITS 12 @@ -295,6 +296,10 @@ static const int jz4740_adc_battery_scale_avail[] = { JZ_ADC_BATTERY_LOW_VREF, JZ_ADC_BATTERY_LOW_VREF_BITS, }; +static const int jz4760_adc_battery_scale_avail[] = { + JZ4760_ADC_BATTERY_VREF, JZ4770_ADC_BATTERY_VREF_BITS, +}; + static const int jz4770_adc_battery_raw_avail[] = { 0, 1, (1 << JZ4770_ADC_BATTERY_VREF_BITS) - 1, }; @@ -400,6 +405,47 @@ static const struct iio_chan_spec jz4740_channels[] = { }, }; +static const struct iio_chan_spec jz4760_channels[] = { + { + .extend_name = "aux", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_AUX0, + .scan_index = -1, + }, + { + .extend_name = "aux1", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_AUX, + .scan_index = -1, + }, + { + .extend_name = "aux2", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_AUX2, + .scan_index = -1, + }, + { + .extend_name = "battery", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_BATTERY, + .scan_index = -1, + }, +}; + static const struct iio_chan_spec jz4770_channels[] = { { .type = IIO_VOLTAGE, @@ -526,6 +572,20 @@ static const struct ingenic_adc_soc_data jz4740_adc_soc_data = { .init_clk_div = NULL, /* no ADCLK register on JZ4740 */ }; +static const struct ingenic_adc_soc_data jz4760_adc_soc_data = { + .battery_high_vref = JZ4760_ADC_BATTERY_VREF, + .battery_high_vref_bits = JZ4770_ADC_BATTERY_VREF_BITS, + .battery_raw_avail = jz4770_adc_battery_raw_avail, + .battery_raw_avail_size = ARRAY_SIZE(jz4770_adc_battery_raw_avail), + .battery_scale_avail = jz4760_adc_battery_scale_avail, + .battery_scale_avail_size = ARRAY_SIZE(jz4760_adc_battery_scale_avail), + .battery_vref_mode = false, + .has_aux_md = true, + .channels = jz4760_channels, + .num_channels = ARRAY_SIZE(jz4760_channels), + .init_clk_div = jz4770_adc_init_clk_div, +}; + static const struct ingenic_adc_soc_data jz4770_adc_soc_data = { .battery_high_vref = JZ4770_ADC_BATTERY_VREF, .battery_high_vref_bits = JZ4770_ADC_BATTERY_VREF_BITS, @@ -569,7 +629,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev, struct iio_chan_spec const *chan, int *val) { - int bit, ret, engine = (chan->channel == INGENIC_ADC_BATTERY); + int cmd, ret, engine = (chan->channel == INGENIC_ADC_BATTERY); struct ingenic_adc *adc = iio_priv(iio_dev); ret = clk_enable(adc->clk); @@ -579,11 +639,22 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev, return ret; } - /* We cannot sample AUX/AUX2 in parallel. */ + /* We cannot sample the aux channels in parallel. */ mutex_lock(&adc->aux_lock); if (adc->soc_data->has_aux_md && engine == 0) { - bit = BIT(chan->channel == INGENIC_ADC_AUX2); - ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, bit); + switch (chan->channel) { + case INGENIC_ADC_AUX0: + cmd = 0; + break; + case INGENIC_ADC_AUX: + cmd = 1; + break; + case INGENIC_ADC_AUX2: + cmd = 2; + break; + } + + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd); } ret = ingenic_adc_capture(adc, engine); @@ -591,6 +662,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev, goto out; switch (chan->channel) { + case INGENIC_ADC_AUX0: case INGENIC_ADC_AUX: case INGENIC_ADC_AUX2: *val = readw(adc->base + JZ_ADC_REG_ADSDAT); @@ -621,6 +693,7 @@ static int ingenic_adc_read_raw(struct iio_dev *iio_dev, return ingenic_adc_read_chan_info_raw(iio_dev, chan, val); case IIO_CHAN_INFO_SCALE: switch (chan->channel) { + case INGENIC_ADC_AUX0: case INGENIC_ADC_AUX: case INGENIC_ADC_AUX2: *val = JZ_ADC_AUX_VREF; @@ -832,6 +905,7 @@ static int ingenic_adc_probe(struct platform_device *pdev) static const struct of_device_id ingenic_adc_of_match[] = { { .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, }, { .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data, }, + { .compatible = "ingenic,jz4760-adc", .data = &jz4760_adc_soc_data, }, { .compatible = "ingenic,jz4770-adc", .data = &jz4770_adc_soc_data, }, { }, }; From bf1b2418c2f56a81f405925b10a02c25681179cd Mon Sep 17 00:00:00 2001 From: Christophe Branchereau Date: Mon, 26 Jul 2021 10:20:32 +0200 Subject: [PATCH 58/77] iio/adc: ingenic: add JZ4760B support to the sadc driver The JZ4760B variant differs slightly from the JZ4760: it has a bit called VBAT_SEL in the CFG register. In order to correctly sample the battery voltage on existing handhelds using this SOC, the bit must be cleared. We leave the possibility to set the bit, by using the "ingenic,use-internal-divider" in the devicetree. Signed-off-by: Christophe Branchereau Link: https://lore.kernel.org/r/20210726082033.351533-5-cbranchereau@gmail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ingenic-adc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c index 6b9af0530590..2b3912c6ca6b 100644 --- a/drivers/iio/adc/ingenic-adc.c +++ b/drivers/iio/adc/ingenic-adc.c @@ -37,6 +37,7 @@ #define JZ_ADC_REG_CFG_SAMPLE_NUM(n) ((n) << 10) #define JZ_ADC_REG_CFG_PULL_UP(n) ((n) << 16) #define JZ_ADC_REG_CFG_CMD_SEL BIT(22) +#define JZ_ADC_REG_CFG_VBAT_SEL BIT(30) #define JZ_ADC_REG_CFG_TOUCH_OPS_MASK (BIT(31) | GENMASK(23, 10)) #define JZ_ADC_REG_ADCLK_CLKDIV_LSB 0 #define JZ4725B_ADC_REG_ADCLK_CLKDIV10US_LSB 16 @@ -879,6 +880,14 @@ static int ingenic_adc_probe(struct platform_device *pdev) /* Put hardware in a known passive state. */ writeb(0x00, adc->base + JZ_ADC_REG_ENABLE); writeb(0xff, adc->base + JZ_ADC_REG_CTRL); + + /* JZ4760B specific */ + if (device_property_present(dev, "ingenic,use-internal-divider")) + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, + JZ_ADC_REG_CFG_VBAT_SEL); + else + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, 0); + usleep_range(2000, 3000); /* Must wait at least 2ms. */ clk_disable(adc->clk); @@ -906,6 +915,7 @@ static const struct of_device_id ingenic_adc_of_match[] = { { .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, }, { .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data, }, { .compatible = "ingenic,jz4760-adc", .data = &jz4760_adc_soc_data, }, + { .compatible = "ingenic,jz4760b-adc", .data = &jz4760_adc_soc_data, }, { .compatible = "ingenic,jz4770-adc", .data = &jz4770_adc_soc_data, }, { }, }; From eaaa23d71ebf0c598eedb81d4a814b0a475273f6 Mon Sep 17 00:00:00 2001 From: Christophe Branchereau Date: Mon, 26 Jul 2021 10:20:33 +0200 Subject: [PATCH 59/77] dt-bindings: iio/adc: ingenic: add the JZ4760(B) socs to the sadc Documentation Add both the jz4760 and jz4760b, plus a property to use the internal divider on the b variant and document it. Signed-off-by: Christophe Branchereau Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20210726082033.351533-6-cbranchereau@gmail.com Signed-off-by: Jonathan Cameron --- .../bindings/iio/adc/ingenic,adc.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml index 433a3fb55a2e..3eb7aa8822c3 100644 --- a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml @@ -23,6 +23,8 @@ properties: enum: - ingenic,jz4725b-adc - ingenic,jz4740-adc + - ingenic,jz4760-adc + - ingenic,jz4760b-adc - ingenic,jz4770-adc '#io-channel-cells': @@ -43,6 +45,23 @@ properties: interrupts: maxItems: 1 + ingenic,use-internal-divider: + description: + If present, battery voltage is read from the VBAT_IR pin, which has an + internal 1/4 divider. If absent, it is read through the VBAT_ER pin, + which does not have such a divider. + type: boolean + +if: + not: + properties: + compatible: + contains: + const: ingenic,jz4760b-adc +then: + properties: + ingenic,use-internal-divider: false + required: - compatible - '#io-channel-cells' From 6a25893cb0e255ab8888d6a4f40e8d1e9d554ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Bor=C3=A9m=20Fabris?= Date: Sat, 24 Jul 2021 19:02:00 -0300 Subject: [PATCH 60/77] iio: dac: max5821: convert device register to device managed function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a device managed hook, via devm_add_action_or_reset() and max5821_regulator_disable(), to disable voltage regulator on device detach. Replace iio_device_register() by devm_iio_device_register() and remove the max5821_remove() function used to unregister the device and disable the voltage regulator. Remove i2c_set_clientdata() from the probe function, since i2c_get_clientdata() is not used anymore. Remove regulator_disable() calls from the probe function. Signed-off-by: Théo Borém Fabris Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210724220159.11998-1-theobf@usp.br Signed-off-by: Jonathan Cameron --- drivers/iio/dac/max5821.c | 41 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c index bd6e75699a63..bd0b7f361154 100644 --- a/drivers/iio/dac/max5821.c +++ b/drivers/iio/dac/max5821.c @@ -294,6 +294,11 @@ static const struct iio_info max5821_info = { .write_raw = max5821_write_raw, }; +static void max5821_regulator_disable(void *reg) +{ + regulator_disable(reg); +} + static int max5821_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -306,7 +311,6 @@ static int max5821_probe(struct i2c_client *client, if (!indio_dev) return -ENOMEM; data = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); data->client = client; mutex_init(&data->lock); @@ -321,21 +325,29 @@ static int max5821_probe(struct i2c_client *client, ret = PTR_ERR(data->vref_reg); dev_err(&client->dev, "Failed to get vref regulator: %d\n", ret); - goto error_free_reg; + return ret; } ret = regulator_enable(data->vref_reg); if (ret) { dev_err(&client->dev, "Failed to enable vref regulator: %d\n", ret); - goto error_free_reg; + return ret; + } + + ret = devm_add_action_or_reset(&client->dev, max5821_regulator_disable, + data->vref_reg); + if (ret) { + dev_err(&client->dev, + "Failed to add action to managed regulator: %d\n", ret); + return ret; } ret = regulator_get_voltage(data->vref_reg); if (ret < 0) { dev_err(&client->dev, "Failed to get voltage on regulator: %d\n", ret); - goto error_disable_reg; + return ret; } data->vref_mv = ret / 1000; @@ -346,25 +358,7 @@ static int max5821_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &max5821_info; - return iio_device_register(indio_dev); - -error_disable_reg: - regulator_disable(data->vref_reg); - -error_free_reg: - - return ret; -} - -static int max5821_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct max5821_data *data = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - regulator_disable(data->vref_reg); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } static const struct i2c_device_id max5821_id[] = { @@ -386,7 +380,6 @@ static struct i2c_driver max5821_driver = { .pm = &max5821_pm_ops, }, .probe = max5821_probe, - .remove = max5821_remove, .id_table = max5821_id, }; module_i2c_driver(max5821_driver); From f27b1b2a04dda77454659e0b2572afe9620b55ec Mon Sep 17 00:00:00 2001 From: Tang Bin Date: Mon, 2 Aug 2021 20:09:29 +0800 Subject: [PATCH 61/77] iio: adc: fsl-imx25-gcq: adjust irq check to match docs and simplify code For the function of platform_get_irq(), the example in platform.c is * int irq = platform_get_irq(pdev, 0); * if (irq < 0) * return irq; the return value of zero is unnecessary to check, so make the right check and simplify code. Note that platform_get_irq() is documented as never returning 0 so this is a minor optmization rather than a fix. Co-developed-by: Zhang Shengju Signed-off-by: Zhang Shengju Signed-off-by: Tang Bin Link: https://lore.kernel.org/r/20210802120929.33760-1-tangbin@cmss.chinamobile.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/fsl-imx25-gcq.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c index 0c771d60541a..329c555b55cc 100644 --- a/drivers/iio/adc/fsl-imx25-gcq.c +++ b/drivers/iio/adc/fsl-imx25-gcq.c @@ -347,14 +347,11 @@ static int mx25_gcq_probe(struct platform_device *pdev) goto err_vref_disable; } - priv->irq = platform_get_irq(pdev, 0); - if (priv->irq <= 0) { - ret = priv->irq; - if (!ret) - ret = -ENXIO; + ret = platform_get_irq(pdev, 0); + if (ret < 0) goto err_clk_unprepare; - } + priv->irq = ret; ret = request_irq(priv->irq, mx25_gcq_irq, 0, pdev->name, priv); if (ret) { dev_err(dev, "Failed requesting IRQ\n"); From 6c3ce4049b772858f3c86f3088e171a955cdbe95 Mon Sep 17 00:00:00 2001 From: Alexander Sverdlin Date: Mon, 14 Jun 2021 01:30:35 +0200 Subject: [PATCH 62/77] iio: ep93xx: Prepare clock before using it Use clk_prepare_enable()/clk_disable_unprepare() in preparation for switch to Common Clock Framework, otherwise the following is visible: WARNING: CPU: 0 PID: 1 at drivers/clk/clk.c:1011 clk_core_enable+0x9c/0xbc Enabling unprepared ep93xx-adc CPU: 0 PID: 1 Comm: swapper Not tainted 5.13.0-rc5-... #1 Hardware name: Cirrus Logic EDB9302 Evaluation Board [] (unwind_backtrace) from [] (show_stack+0x10/0x18) [] (show_stack) from [] (dump_stack+0x20/0x2c) [] (dump_stack) from [] (__warn+0x98/0xc0) [] (__warn) from [] (warn_slowpath_fmt+0x90/0xc0) [] (warn_slowpath_fmt) from [] (clk_core_enable+0x9c/0xbc) [] (clk_core_enable) from [] (clk_core_enable_lock+0x18/0x30) [] (clk_core_enable_lock) from [] (ep93xx_adc_probe+0xe4/0x1a0) [] (ep93xx_adc_probe) from [] (platform_probe+0x34/0x80) [] (platform_probe) from [] (really_probe+0xe8/0x394) [] (really_probe) from [] (device_driver_attach+0x5c/0x64) [] (device_driver_attach) from [] (__driver_attach+0x7c/0xec) [] (__driver_attach) from [] (bus_for_each_dev+0x78/0xc4) [] (bus_for_each_dev) from [] (driver_attach+0x18/0x24) [] (driver_attach) from [] (bus_add_driver+0x140/0x1cc) [] (bus_add_driver) from [] (driver_register+0x74/0x114) [] (driver_register) from [] (__platform_driver_register+0x18/0x24) [] (__platform_driver_register) from [] (ep93xx_adc_driver_init+0x10/0x1c) [] (ep93xx_adc_driver_init) from [] (do_one_initcall+0x7c/0x1a4) [] (do_one_initcall) from [] (kernel_init_freeable+0x17c/0x1fc) [] (kernel_init_freeable) from [] (kernel_init+0x8/0xf8) [] (kernel_init) from [] (ret_from_fork+0x14/0x3c) ... ep93xx-adc ep93xx-adc: Cannot enable clock ep93xx-adc: probe of ep93xx-adc failed with error -108 Signed-off-by: Alexander Sverdlin Link: https://lore.kernel.org/r/20210613233041.128961-2-alexander.sverdlin@gmail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ep93xx_adc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/ep93xx_adc.c b/drivers/iio/adc/ep93xx_adc.c index a10a4e8d94fd..8edd6407b7c3 100644 --- a/drivers/iio/adc/ep93xx_adc.c +++ b/drivers/iio/adc/ep93xx_adc.c @@ -205,7 +205,7 @@ static int ep93xx_adc_probe(struct platform_device *pdev) */ } - ret = clk_enable(priv->clk); + ret = clk_prepare_enable(priv->clk); if (ret) { dev_err(&pdev->dev, "Cannot enable clock\n"); return ret; @@ -213,7 +213,7 @@ static int ep93xx_adc_probe(struct platform_device *pdev) ret = iio_device_register(iiodev); if (ret) - clk_disable(priv->clk); + clk_disable_unprepare(priv->clk); return ret; } @@ -224,7 +224,7 @@ static int ep93xx_adc_remove(struct platform_device *pdev) struct ep93xx_adc_priv *priv = iio_priv(iiodev); iio_device_unregister(iiodev); - clk_disable(priv->clk); + clk_disable_unprepare(priv->clk); return 0; } From 3722c105ecd1129bba593a9599b8c513c0129536 Mon Sep 17 00:00:00 2001 From: Andreas Klinger Date: Wed, 4 Aug 2021 17:45:50 +0200 Subject: [PATCH 63/77] dt-bindings: iio: chemical: Add trivial DT binding for sgp40 Add devicetree binding for Sensirion sgp40 gas sensor to trivial devices. Acked-by: Rob Herring Signed-off-by: Andreas Klinger Link: https://lore.kernel.org/r/20210804154549.GA3223@arbad Signed-off-by: Jonathan Cameron --- Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index 919a4bf03a5a..be313b6b4f81 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -269,6 +269,8 @@ properties: - sensirion,sgpc3 # Sensirion multi-pixel gas sensor with I2C interface - sensirion,sgp30 + # Sensirion gas sensor with I2C interface + - sensirion,sgp40 # Sensortek 3 axis accelerometer - sensortek,stk8312 # Sensortek 3 axis accelerometer From 1081b9d97152e6aa28a1868ec8e0587b2b8fb2ae Mon Sep 17 00:00:00 2001 From: Andreas Klinger Date: Wed, 4 Aug 2021 17:46:42 +0200 Subject: [PATCH 64/77] iio: chemical: Add driver support for sgp40 sgp40 is a gas sensor used for measuring the air quality. This driver is reading the raw resistance value which can be passed to an userspace algorithm for further calculation. The raw value is also used to calculate an estimated absolute voc index in the range from 0 to 500. For this purpose the raw_mean value of the resistance for which the index value is 250 might be set up as a calibration step. This can be done with in_resistance_calibbias. Compensation of relative humidity and temperature is supported and can be used by writing to output values of out_humidityrelative_raw and out_temp_raw. There is a predecesor sensor type (sgp30) already existing. This driver module was not extended because the new sensor is quite different in its i2c telegrams. Signed-off-by: Andreas Klinger Reported-by: kernel test robot Link: https://lore.kernel.org/r/20210804154641.GA3237@arbad Signed-off-by: Jonathan Cameron --- .../ABI/testing/sysfs-bus-iio-chemical-sgp40 | 31 ++ MAINTAINERS | 6 + drivers/iio/chemical/Kconfig | 11 + drivers/iio/chemical/Makefile | 1 + drivers/iio/chemical/sgp40.c | 378 ++++++++++++++++++ 5 files changed, 427 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 create mode 100644 drivers/iio/chemical/sgp40.c diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 b/Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 new file mode 100644 index 000000000000..469a7c00fad4 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 @@ -0,0 +1,31 @@ +What: /sys/bus/iio/devices/iio:deviceX/out_temp_raw +Date: August 2021 +KernelVersion: 5.15 +Contact: Andreas Klinger +Description: + Set the temperature. This value is sent to the sensor for + temperature compensation. + Default value: 25000 (25 °C) + +What: /sys/bus/iio/devices/iio:deviceX/out_humidityrelative_raw +Date: August 2021 +KernelVersion: 5.15 +Contact: Andreas Klinger +Description: + Set the relative humidity. This value is sent to the sensor for + humidity compensation. + Default value: 50000 (50 % relative humidity) + +What: /sys/bus/iio/devices/iio:deviceX/in_resistance_calibbias +Date: August 2021 +KernelVersion: 5.15 +Contact: Andreas Klinger +Description: + Set the bias value for the resistance which is used for + calculation of in_concentration_input as follows: + + x = (in_resistance_raw - in_resistance_calibbias) * 0.65 + + in_concentration_input = 500 / (1 + e^x) + + Default value: 30000 diff --git a/MAINTAINERS b/MAINTAINERS index a61f4f3b78a9..d0464b83b5b5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16698,6 +16698,12 @@ F: drivers/iio/chemical/scd30_core.c F: drivers/iio/chemical/scd30_i2c.c F: drivers/iio/chemical/scd30_serial.c +SENSIRION SGP40 GAS SENSOR DRIVER +M: Andreas Klinger +S: Maintained +F: Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 +F: drivers/iio/chemical/sgp40.c + SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski S: Maintained diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig index a4920646e9be..c03667e62732 100644 --- a/drivers/iio/chemical/Kconfig +++ b/drivers/iio/chemical/Kconfig @@ -131,6 +131,17 @@ config SENSIRION_SGP30 To compile this driver as module, choose M here: the module will be called sgp30. +config SENSIRION_SGP40 + tristate "Sensirion SGP40 gas sensor" + depends on I2C + select CRC8 + help + Say Y here to build I2C interface to support Sensirion SGP40 gas + sensor + + To compile this driver as module, choose M here: the + module will be called sgp40. + config SPS30 tristate select IIO_BUFFER diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile index 4898690cc155..d07af581f234 100644 --- a/drivers/iio/chemical/Makefile +++ b/drivers/iio/chemical/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_SCD30_CORE) += scd30_core.o obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o +obj-$(CONFIG_SENSIRION_SGP40) += sgp40.o obj-$(CONFIG_SPS30) += sps30.o obj-$(CONFIG_SPS30_I2C) += sps30_i2c.o obj-$(CONFIG_SPS30_SERIAL) += sps30_serial.o diff --git a/drivers/iio/chemical/sgp40.c b/drivers/iio/chemical/sgp40.c new file mode 100644 index 000000000000..8a56394cea4e --- /dev/null +++ b/drivers/iio/chemical/sgp40.c @@ -0,0 +1,378 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * sgp40.c - Support for Sensirion SGP40 Gas Sensor + * + * Copyright (C) 2021 Andreas Klinger + * + * I2C slave address: 0x59 + * + * Datasheet can be found here: + * https://www.sensirion.com/file/datasheet_sgp40 + * + * There are two functionalities supported: + * + * 1) read raw logarithmic resistance value from sensor + * --> useful to pass it to the algorithm of the sensor vendor for + * measuring deteriorations and improvements of air quality. + * + * 2) calculate an estimated absolute voc index (0 - 500 index points) for + * measuring the air quality. + * For this purpose the value of the resistance for which the voc index + * will be 250 can be set up using calibbias. + * + * Compensation values of relative humidity and temperature can be set up + * by writing to the out values of temp and humidityrelative. + */ + +#include +#include +#include +#include +#include +#include + +/* + * floating point calculation of voc is done as integer + * where numbers are multiplied by 1 << SGP40_CALC_POWER + */ +#define SGP40_CALC_POWER 14 + +#define SGP40_CRC8_POLYNOMIAL 0x31 +#define SGP40_CRC8_INIT 0xff + +DECLARE_CRC8_TABLE(sgp40_crc8_table); + +struct sgp40_data { + struct device *dev; + struct i2c_client *client; + int rht; + int temp; + int res_calibbias; + /* Prevent concurrent access to rht, tmp, calibbias */ + struct mutex lock; +}; + +struct sgp40_tg_measure { + u8 command[2]; + __be16 rht_ticks; + u8 rht_crc; + __be16 temp_ticks; + u8 temp_crc; +} __packed; + +struct sgp40_tg_result { + __be16 res_ticks; + u8 res_crc; +} __packed; + +static const struct iio_chan_spec sgp40_channels[] = { + { + .type = IIO_CONCENTRATION, + .channel2 = IIO_MOD_VOC, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, + { + .type = IIO_RESISTANCE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_CALIBBIAS), + }, + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .output = 1, + }, + { + .type = IIO_HUMIDITYRELATIVE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .output = 1, + }, +}; + +/* + * taylor approximation of e^x: + * y = 1 + x + x^2 / 2 + x^3 / 6 + x^4 / 24 + ... + x^n / n! + * + * Because we are calculating x real value multiplied by 2^power we get + * an additional 2^power^n to divide for every element. For a reasonable + * precision this would overflow after a few iterations. Therefore we + * divide the x^n part whenever its about to overflow (xmax). + */ + +static u32 sgp40_exp(int exp, u32 power, u32 rounds) +{ + u32 x, y, xp; + u32 factorial, divider, xmax; + int sign = 1; + int i; + + if (exp == 0) + return 1 << power; + else if (exp < 0) { + sign = -1; + exp *= -1; + } + + xmax = 0x7FFFFFFF / exp; + x = exp; + xp = 1; + factorial = 1; + y = 1 << power; + divider = 0; + + for (i = 1; i <= rounds; i++) { + xp *= x; + factorial *= i; + y += (xp >> divider) / factorial; + divider += power; + /* divide when next multiplication would overflow */ + if (xp >= xmax) { + xp >>= power; + divider -= power; + } + } + + if (sign == -1) + return (1 << (power * 2)) / y; + else + return y; +} + +static int sgp40_calc_voc(struct sgp40_data *data, u16 resistance_raw, int *voc) +{ + int x; + u32 exp = 0; + + /* we calculate as a multiple of 16384 (2^14) */ + mutex_lock(&data->lock); + x = ((int)resistance_raw - data->res_calibbias) * 106; + mutex_unlock(&data->lock); + + /* voc = 500 / (1 + e^x) */ + exp = sgp40_exp(x, SGP40_CALC_POWER, 18); + *voc = 500 * ((1 << (SGP40_CALC_POWER * 2)) / ((1<dev, "raw: %d res_calibbias: %d x: %d exp: %d voc: %d\n", + resistance_raw, data->res_calibbias, x, exp, *voc); + + return 0; +} + +static int sgp40_measure_resistance_raw(struct sgp40_data *data, u16 *resistance_raw) +{ + int ret; + struct i2c_client *client = data->client; + u32 ticks; + u16 ticks16; + u8 crc; + struct sgp40_tg_measure tg = {.command = {0x26, 0x0F}}; + struct sgp40_tg_result tgres; + + mutex_lock(&data->lock); + + ticks = (data->rht / 10) * 65535 / 10000; + ticks16 = (u16)clamp(ticks, 0u, 65535u); /* clamp between 0 .. 100 %rH */ + tg.rht_ticks = cpu_to_be16(ticks16); + tg.rht_crc = crc8(sgp40_crc8_table, (u8 *)&tg.rht_ticks, 2, SGP40_CRC8_INIT); + + ticks = ((data->temp + 45000) / 10 ) * 65535 / 17500; + ticks16 = (u16)clamp(ticks, 0u, 65535u); /* clamp between -45 .. +130 °C */ + tg.temp_ticks = cpu_to_be16(ticks16); + tg.temp_crc = crc8(sgp40_crc8_table, (u8 *)&tg.temp_ticks, 2, SGP40_CRC8_INIT); + + mutex_unlock(&data->lock); + + ret = i2c_master_send(client, (const char *)&tg, sizeof(tg)); + if (ret != sizeof(tg)) { + dev_warn(data->dev, "i2c_master_send ret: %d sizeof: %zu\n", ret, sizeof(tg)); + return -EIO; + } + msleep(30); + + ret = i2c_master_recv(client, (u8 *)&tgres, sizeof(tgres)); + if (ret < 0) + return ret; + if (ret != sizeof(tgres)) { + dev_warn(data->dev, "i2c_master_recv ret: %d sizeof: %zu\n", ret, sizeof(tgres)); + return -EIO; + } + + crc = crc8(sgp40_crc8_table, (u8 *)&tgres.res_ticks, 2, SGP40_CRC8_INIT); + if (crc != tgres.res_crc) { + dev_err(data->dev, "CRC error while measure-raw\n"); + return -EIO; + } + + *resistance_raw = be16_to_cpu(tgres.res_ticks); + + return 0; +} + +static int sgp40_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct sgp40_data *data = iio_priv(indio_dev); + int ret, voc; + u16 resistance_raw; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_RESISTANCE: + ret = sgp40_measure_resistance_raw(data, &resistance_raw); + if (ret) + return ret; + + *val = resistance_raw; + return IIO_VAL_INT; + case IIO_TEMP: + mutex_lock(&data->lock); + *val = data->temp; + mutex_unlock(&data->lock); + return IIO_VAL_INT; + case IIO_HUMIDITYRELATIVE: + mutex_lock(&data->lock); + *val = data->rht; + mutex_unlock(&data->lock); + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_PROCESSED: + ret = sgp40_measure_resistance_raw(data, &resistance_raw); + if (ret) + return ret; + + ret = sgp40_calc_voc(data, resistance_raw, &voc); + if (ret) + return ret; + + *val = voc / (1 << SGP40_CALC_POWER); + /* + * calculation should fit into integer, where: + * voc <= (500 * 2^SGP40_CALC_POWER) = 8192000 + * (with SGP40_CALC_POWER = 14) + */ + *val2 = ((voc % (1 << SGP40_CALC_POWER)) * 244) / (1 << (SGP40_CALC_POWER - 12)); + dev_dbg(data->dev, "voc: %d val: %d.%06d\n", voc, *val, *val2); + return IIO_VAL_INT_PLUS_MICRO; + case IIO_CHAN_INFO_CALIBBIAS: + mutex_lock(&data->lock); + *val = data->res_calibbias; + mutex_unlock(&data->lock); + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int sgp40_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long mask) +{ + struct sgp40_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_TEMP: + if ((val < -45000) || (val > 130000)) + return -EINVAL; + + mutex_lock(&data->lock); + data->temp = val; + mutex_unlock(&data->lock); + return 0; + case IIO_HUMIDITYRELATIVE: + if ((val < 0) || (val > 100000)) + return -EINVAL; + + mutex_lock(&data->lock); + data->rht = val; + mutex_unlock(&data->lock); + return 0; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_CALIBBIAS: + if ((val < 20000) || (val > 52768)) + return -EINVAL; + + mutex_lock(&data->lock); + data->res_calibbias = val; + mutex_unlock(&data->lock); + return 0; + } + return -EINVAL; +} + +static const struct iio_info sgp40_info = { + .read_raw = sgp40_read_raw, + .write_raw = sgp40_write_raw, +}; + +static int sgp40_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct iio_dev *indio_dev; + struct sgp40_data *data; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + data->client = client; + data->dev = dev; + + crc8_populate_msb(sgp40_crc8_table, SGP40_CRC8_POLYNOMIAL); + + mutex_init(&data->lock); + + /* set default values */ + data->rht = 50000; /* 50 % */ + data->temp = 25000; /* 25 °C */ + data->res_calibbias = 30000; /* resistance raw value for voc index of 250 */ + + indio_dev->info = &sgp40_info; + indio_dev->name = id->name; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = sgp40_channels; + indio_dev->num_channels = ARRAY_SIZE(sgp40_channels); + + ret = devm_iio_device_register(dev, indio_dev); + if (ret) + dev_err(dev, "failed to register iio device\n"); + + return ret; +} + +static const struct i2c_device_id sgp40_id[] = { + { "sgp40" }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, sgp40_id); + +static const struct of_device_id sgp40_dt_ids[] = { + { .compatible = "sensirion,sgp40" }, + { } +}; + +MODULE_DEVICE_TABLE(of, sgp40_dt_ids); + +static struct i2c_driver sgp40_driver = { + .driver = { + .name = "sgp40", + .of_match_table = sgp40_dt_ids, + }, + .probe = sgp40_probe, + .id_table = sgp40_id, +}; +module_i2c_driver(sgp40_driver); + +MODULE_AUTHOR("Andreas Klinger "); +MODULE_DESCRIPTION("Sensirion SGP40 gas sensor"); +MODULE_LICENSE("GPL v2"); From a5dfc572eeee7bbba6749814ce39e9fda139c531 Mon Sep 17 00:00:00 2001 From: Siddharth Manthan Date: Wed, 28 Jul 2021 16:30:47 +0530 Subject: [PATCH 65/77] dt-bindings: Add bindings for Capella cm3323 Ambient Light Sensor Update trivial-devices.yaml with Capella cm3323 Ambient Light Sensor description. Signed-off-by: Siddharth Manthan Acked-by: Rob Herring Link: https://lore.kernel.org/r/20210728110048.14593-1-siddharth.manthan@gmail.com Signed-off-by: Jonathan Cameron --- Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index be313b6b4f81..02a30e779fb3 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -61,6 +61,8 @@ properties: - capella,cm32181 # CM3232: Ambient Light Sensor - capella,cm3232 + # CM3323: Ambient Light Sensor + - capella,cm3323 # High-Precision Digital Thermometer - dallas,ds1631 # Total-Elapsed-Time Recorder with Alarm From ee8ea7472ff7e56d015fcaf0924c043688ca29e8 Mon Sep 17 00:00:00 2001 From: Siddharth Manthan Date: Wed, 28 Jul 2021 16:30:48 +0530 Subject: [PATCH 66/77] iio: light: cm3323: Add of_device_id table Add an of_device_id table to explicitly support the Capella cm3323 Ambient Light Sensor rather than relying on matching against the i2c_device_id table. Signed-off-by: Siddharth Manthan Link: https://lore.kernel.org/r/20210728110048.14593-2-siddharth.manthan@gmail.com Signed-off-by: Jonathan Cameron --- drivers/iio/light/cm3323.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c index 6d1b0ffd144b..fd9a8c27de2e 100644 --- a/drivers/iio/light/cm3323.c +++ b/drivers/iio/light/cm3323.c @@ -256,9 +256,16 @@ static const struct i2c_device_id cm3323_id[] = { }; MODULE_DEVICE_TABLE(i2c, cm3323_id); +static const struct of_device_id cm3323_of_match[] = { + { .compatible = "capella,cm3323", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, cm3323_of_match); + static struct i2c_driver cm3323_driver = { .driver = { .name = CM3323_DRV_NAME, + .of_match_table = cm3323_of_match, }, .probe = cm3323_probe, .id_table = cm3323_id, From 84c31a0466c12110af72d56c1dcc40759e848c55 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 2 Aug 2021 17:56:54 +0200 Subject: [PATCH 67/77] dt-bindings: iio: accel: bma255: Add interrupt-names The binding already allows specifying both interrupt pins, but there is currently no way to describe a board where (for whatever reason) only INT2 is connected. Make it possible to use "interrupt-names" to make it explicit which interrupt pin is meant in the interrupts. Reviewed-by: Linus Walleij Signed-off-by: Stephan Gerhold Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20210802155657.102766-2-stephan@gerhold.net Signed-off-by: Jonathan Cameron --- .../bindings/iio/accel/bosch,bma255.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml index 5b35856b1942..253b2051d0b1 100644 --- a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml @@ -45,9 +45,18 @@ properties: minItems: 1 maxItems: 2 description: | - The first interrupt listed must be the one connected to the INT1 pin, - the second (optional) interrupt listed must be the one connected to the - INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING. + Without interrupt-names, the first interrupt listed must be the one + connected to the INT1 pin, the second (optional) interrupt listed must be + the one connected to the INT2 pin (if available). The type should be + IRQ_TYPE_EDGE_RISING. + + interrupt-names: + minItems: 1 + maxItems: 2 + items: + enum: + - INT1 + - INT2 mount-matrix: description: an optional 3x3 mounting rotation matrix. @@ -73,6 +82,7 @@ examples: vddio-supply = <&vddio>; vdd-supply = <&vdd>; interrupts = <57 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "INT1"; }; }; - | From 02104141f3fa08c0b8d3924e0db4744212ed5b9a Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 2 Aug 2021 17:56:55 +0200 Subject: [PATCH 68/77] dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel BMC156 is very smilar to BMC150, but it has only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch decided to only have an INT2 pin. In this case, it does not make sense if the first interrupt pin is treated as INT1 (since that pin does not exist). Add a note to the bindings that the first interrupt pin is treated as INT2 for BMC156. Reviewed-by: Linus Walleij Reviewed-by: Rob Herring Signed-off-by: Stephan Gerhold Link: https://lore.kernel.org/r/20210802155657.102766-3-stephan@gerhold.net Signed-off-by: Jonathan Cameron --- .../bindings/iio/accel/bosch,bma255.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml index 253b2051d0b1..478e75ae0885 100644 --- a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml @@ -26,6 +26,7 @@ properties: - bosch,bma255 - bosch,bma280 - bosch,bmc150_accel + - bosch,bmc156_accel - bosch,bmi055_accel # bma180 driver in Linux @@ -50,6 +51,9 @@ properties: the one connected to the INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING. + BMC156 does not have an INT1 pin, therefore the first interrupt pin is + always treated as INT2. + interrupt-names: minItems: 1 maxItems: 2 @@ -85,6 +89,20 @@ examples: interrupt-names = "INT1"; }; }; + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + accelerometer@10 { + compatible = "bosch,bmc156_accel"; + reg = <0x10>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + interrupts = <116 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "INT2"; + }; + }; - | # include spi { From 73d672e63f3062e987f9c92abdeb332e280f47db Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 2 Aug 2021 17:56:56 +0200 Subject: [PATCH 69/77] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1 Some Bosch accelerometers have two interrupt pins (INT1 and INT2). At the moment, the driver uses only the first one, which is fine for most situations. However, some boards might only have INT2 connected for some reason. Add the necessary bits and configuration to set up INT2. Then try to detect this situation at least for device tree setups by checking if the first interrupt (the one picked by the I2C/SPI core) is actually named "INT2" using the interrupt-names property. of_irq_get_byname() returns either 0 or some error code in case the driver probed without device tree, so in all other cases we fall back to configuring INT1 as before. Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij Link: https://lore.kernel.org/r/20210802155657.102766-4-stephan@gerhold.net Signed-off-by: Jonathan Cameron --- drivers/iio/accel/bmc150-accel-core.c | 71 ++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 5ce384ebe6c7..8d3dd3c2bcc2 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -57,12 +58,18 @@ #define BMC150_ACCEL_RESET_VAL 0xB6 #define BMC150_ACCEL_REG_INT_MAP_0 0x19 -#define BMC150_ACCEL_INT_MAP_0_BIT_SLOPE BIT(2) +#define BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE BIT(2) #define BMC150_ACCEL_REG_INT_MAP_1 0x1A -#define BMC150_ACCEL_INT_MAP_1_BIT_DATA BIT(0) -#define BMC150_ACCEL_INT_MAP_1_BIT_FWM BIT(1) -#define BMC150_ACCEL_INT_MAP_1_BIT_FFULL BIT(2) +#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA BIT(0) +#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM BIT(1) +#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FFULL BIT(2) +#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FFULL BIT(5) +#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM BIT(6) +#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA BIT(7) + +#define BMC150_ACCEL_REG_INT_MAP_2 0x1B +#define BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE BIT(2) #define BMC150_ACCEL_REG_INT_RST_LATCH 0x21 #define BMC150_ACCEL_INT_MODE_LATCH_RESET 0x80 @@ -81,6 +88,7 @@ #define BMC150_ACCEL_REG_INT_OUT_CTRL 0x20 #define BMC150_ACCEL_INT_OUT_CTRL_INT1_LVL BIT(0) +#define BMC150_ACCEL_INT_OUT_CTRL_INT2_LVL BIT(2) #define BMC150_ACCEL_REG_INT_5 0x27 #define BMC150_ACCEL_SLOPE_DUR_MASK 0x03 @@ -476,21 +484,24 @@ static bool bmc150_apply_acpi_orientation(struct device *dev, } #endif -static const struct bmc150_accel_interrupt_info { +struct bmc150_accel_interrupt_info { u8 map_reg; u8 map_bitmask; u8 en_reg; u8 en_bitmask; -} bmc150_accel_interrupts[BMC150_ACCEL_INTERRUPTS] = { +}; + +static const struct bmc150_accel_interrupt_info +bmc150_accel_interrupts_int1[BMC150_ACCEL_INTERRUPTS] = { { /* data ready interrupt */ .map_reg = BMC150_ACCEL_REG_INT_MAP_1, - .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_DATA, + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA, .en_reg = BMC150_ACCEL_REG_INT_EN_1, .en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN, }, { /* motion interrupt */ .map_reg = BMC150_ACCEL_REG_INT_MAP_0, - .map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_SLOPE, + .map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE, .en_reg = BMC150_ACCEL_REG_INT_EN_0, .en_bitmask = BMC150_ACCEL_INT_EN_BIT_SLP_X | BMC150_ACCEL_INT_EN_BIT_SLP_Y | @@ -498,19 +509,55 @@ static const struct bmc150_accel_interrupt_info { }, { /* fifo watermark interrupt */ .map_reg = BMC150_ACCEL_REG_INT_MAP_1, - .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_FWM, + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM, + .en_reg = BMC150_ACCEL_REG_INT_EN_1, + .en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN, + }, +}; + +static const struct bmc150_accel_interrupt_info +bmc150_accel_interrupts_int2[BMC150_ACCEL_INTERRUPTS] = { + { /* data ready interrupt */ + .map_reg = BMC150_ACCEL_REG_INT_MAP_1, + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA, + .en_reg = BMC150_ACCEL_REG_INT_EN_1, + .en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN, + }, + { /* motion interrupt */ + .map_reg = BMC150_ACCEL_REG_INT_MAP_2, + .map_bitmask = BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE, + .en_reg = BMC150_ACCEL_REG_INT_EN_0, + .en_bitmask = BMC150_ACCEL_INT_EN_BIT_SLP_X | + BMC150_ACCEL_INT_EN_BIT_SLP_Y | + BMC150_ACCEL_INT_EN_BIT_SLP_Z + }, + { /* fifo watermark interrupt */ + .map_reg = BMC150_ACCEL_REG_INT_MAP_1, + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM, .en_reg = BMC150_ACCEL_REG_INT_EN_1, .en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN, }, }; static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev, - struct bmc150_accel_data *data) + struct bmc150_accel_data *data, int irq) { + const struct bmc150_accel_interrupt_info *irq_info = NULL; + struct device *dev = regmap_get_device(data->regmap); int i; + /* + * For now we map all interrupts to the same output pin. + * However, some boards may have just INT2 (and not INT1) connected, + * so we try to detect which IRQ it is based on the interrupt-names. + * Without interrupt-names, we assume the irq belongs to INT1. + */ + irq_info = bmc150_accel_interrupts_int1; + if (irq == of_irq_get_byname(dev->of_node, "INT2")) + irq_info = bmc150_accel_interrupts_int2; + for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++) - data->interrupts[i].info = &bmc150_accel_interrupts[i]; + data->interrupts[i].info = &irq_info[i]; } static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i, @@ -1714,7 +1761,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, goto err_buffer_cleanup; } - bmc150_accel_interrupts_setup(indio_dev, data); + bmc150_accel_interrupts_setup(indio_dev, data, irq); ret = bmc150_accel_triggers_setup(indio_dev, data); if (ret) From 52ae7c708d970e28848f206573a9f11a7826a980 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 2 Aug 2021 17:56:57 +0200 Subject: [PATCH 70/77] iio: accel: bmc150: Add support for BMC156 BMC156 is another accelerometer that works just fine with the bmc150-accel driver. It's very similar to BMC150 (also a accelerometer + magnetometer combo) but with only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch decided to only have an INT2 pin. Try to deal with this by making use of the INT2 support introduced in the previous commit and force using INT2 for BMC156. To detect that we need to bring up a simplified version of the previous type IDs. Note that unlike the type IDs removed in commit c06a6aba6835 ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers") here I only add one for the special case of BMC156. Everything else still happens by reading the CHIP_ID register since the chip type information often is not accurate in ACPI tables. Tested-by: Nikita Travkin # BMC156 Reviewed-by: Linus Walleij Signed-off-by: Stephan Gerhold Link: https://lore.kernel.org/r/20210802155657.102766-5-stephan@gerhold.net Signed-off-by: Jonathan Cameron --- drivers/iio/accel/Kconfig | 5 +++-- drivers/iio/accel/bmc150-accel-core.c | 9 ++++++--- drivers/iio/accel/bmc150-accel-i2c.c | 10 ++++++++-- drivers/iio/accel/bmc150-accel-spi.c | 10 +++++++++- drivers/iio/accel/bmc150-accel.h | 20 +++++++++++++++++++- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index 0e56ace61103..2f0c0d512ae7 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -143,10 +143,11 @@ config BMC150_ACCEL select BMC150_ACCEL_SPI if SPI help Say yes here to build support for the following Bosch accelerometers: - BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMI055. + BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMC156 + BMI055. Note that some of these are combo modules: - - BMC150: accelerometer and magnetometer + - BMC150/BMC156: accelerometer and magnetometer - BMI055: accelerometer and gyroscope This driver is only implementing accelerometer part, which has diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 8d3dd3c2bcc2..e8693a42ad46 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -553,7 +553,8 @@ static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev, * Without interrupt-names, we assume the irq belongs to INT1. */ irq_info = bmc150_accel_interrupts_int1; - if (irq == of_irq_get_byname(dev->of_node, "INT2")) + if (data->type == BOSCH_BMC156 || + irq == of_irq_get_byname(dev->of_node, "INT2")) irq_info = bmc150_accel_interrupts_int2; for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++) @@ -1174,7 +1175,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { {306458, BMC150_ACCEL_DEF_RANGE_16G} }, }, { - .name = "BMA253/BMA254/BMA255/BMC150/BMI055", + .name = "BMA253/BMA254/BMA255/BMC150/BMC156/BMI055", .chip_id = 0xFA, .channels = bmc150_accel_channels, .num_channels = ARRAY_SIZE(bmc150_accel_channels), @@ -1661,7 +1662,8 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data) } int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, - const char *name, bool block_supported) + enum bmc150_type type, const char *name, + bool block_supported) { const struct attribute **fifo_attrs; struct bmc150_accel_data *data; @@ -1676,6 +1678,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, dev_set_drvdata(dev, indio_dev); data->regmap = regmap; + data->type = type; if (!bmc150_apply_acpi_orientation(dev, &data->orientation)) { ret = iio_read_mount_matrix(dev, &data->orientation); diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c index 999495f0669d..88bd8a25f142 100644 --- a/drivers/iio/accel/bmc150-accel-i2c.c +++ b/drivers/iio/accel/bmc150-accel-i2c.c @@ -176,6 +176,7 @@ static int bmc150_accel_probe(struct i2c_client *client, { struct regmap *regmap; const char *name = NULL; + enum bmc150_type type = BOSCH_UNKNOWN; bool block_supported = i2c_check_functionality(client->adapter, I2C_FUNC_I2C) || i2c_check_functionality(client->adapter, @@ -188,10 +189,13 @@ static int bmc150_accel_probe(struct i2c_client *client, return PTR_ERR(regmap); } - if (id) + if (id) { name = id->name; + type = id->driver_data; + } - ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported); + ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, + type, name, block_supported); if (ret) return ret; @@ -236,6 +240,7 @@ static const struct i2c_device_id bmc150_accel_id[] = { {"bma255"}, {"bma280"}, {"bmc150_accel"}, + {"bmc156_accel", BOSCH_BMC156}, {"bmi055_accel"}, {} }; @@ -251,6 +256,7 @@ static const struct of_device_id bmc150_accel_of_match[] = { { .compatible = "bosch,bma255" }, { .compatible = "bosch,bma280" }, { .compatible = "bosch,bmc150_accel" }, + { .compatible = "bosch,bmc156_accel" }, { .compatible = "bosch,bmi055_accel" }, { }, }; diff --git a/drivers/iio/accel/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c index 54b8c9c8068b..191e312dc91a 100644 --- a/drivers/iio/accel/bmc150-accel-spi.c +++ b/drivers/iio/accel/bmc150-accel-spi.c @@ -16,6 +16,8 @@ static int bmc150_accel_probe(struct spi_device *spi) { struct regmap *regmap; + const char *name = NULL; + enum bmc150_type type = BOSCH_UNKNOWN; const struct spi_device_id *id = spi_get_device_id(spi); regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf); @@ -24,7 +26,12 @@ static int bmc150_accel_probe(struct spi_device *spi) return PTR_ERR(regmap); } - return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name, + if (id) { + name = id->name; + type = id->driver_data; + } + + return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name, true); } @@ -54,6 +61,7 @@ static const struct spi_device_id bmc150_accel_id[] = { {"bma255"}, {"bma280"}, {"bmc150_accel"}, + {"bmc156_accel", BOSCH_BMC156}, {"bmi055_accel"}, {} }; diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h index 47121f070fe9..1bb5023e8ed9 100644 --- a/drivers/iio/accel/bmc150-accel.h +++ b/drivers/iio/accel/bmc150-accel.h @@ -13,6 +13,22 @@ struct i2c_client; struct bmc150_accel_chip_info; struct bmc150_accel_interrupt_info; +/* + * We can often guess better than "UNKNOWN" based on the device IDs + * but unfortunately this information is not always accurate. There are some + * devices where ACPI firmware specifies an ID like "BMA250E" when the device + * actually has a BMA222E. The driver attempts to detect those by reading the + * chip ID from the registers but this information is not always enough either. + * + * Therefore, this enum should be only used when the chip ID detection is not + * enough and we can be reasonably sure that the device IDs are reliable + * in practice (e.g. for device tree platforms). + */ +enum bmc150_type { + BOSCH_UNKNOWN, + BOSCH_BMC156, +}; + struct bmc150_accel_interrupt { const struct bmc150_accel_interrupt_info *info; atomic_t users; @@ -62,6 +78,7 @@ struct bmc150_accel_data { int ev_enable_state; int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */ const struct bmc150_accel_chip_info *chip_info; + enum bmc150_type type; struct i2c_client *second_device; void (*resume_callback)(struct device *dev); struct delayed_work resume_work; @@ -69,7 +86,8 @@ struct bmc150_accel_data { }; int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, - const char *name, bool block_supported); + enum bmc150_type type, const char *name, + bool block_supported); int bmc150_accel_core_remove(struct device *dev); extern const struct dev_pm_ops bmc150_accel_pm_ops; extern const struct regmap_config bmc150_regmap_conf; From 728246e8f7269ecd35a2c6e6795323e6d8f48db7 Mon Sep 17 00:00:00 2001 From: William Breathitt Gray Date: Tue, 3 Aug 2021 21:06:11 +0900 Subject: [PATCH 71/77] counter: 104-quad-8: Return error when invalid mode during ceiling_write The 104-QUAD-8 only has two count modes where a ceiling value makes sense: Range Limit and Modulo-N. Outside of these two modes, setting a ceiling value is an invalid operation -- so let's report it as such by returning -EINVAL. Fixes: fc069262261c ("counter: 104-quad-8: Add lock guards - generic interface") Acked-by: Syed Nayyar Waris Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/a2147f022829b66839a1db5530a7fada47856847.1627990337.git.vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron --- drivers/counter/104-quad-8.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 09a9a77cce06..81f9642777fb 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -715,12 +715,13 @@ static ssize_t quad8_count_ceiling_write(struct counter_device *counter, case 1: case 3: quad8_preset_register_set(priv, count->id, ceiling); - break; + mutex_unlock(&priv->lock); + return len; } mutex_unlock(&priv->lock); - return len; + return -EINVAL; } static ssize_t quad8_count_preset_enable_read(struct counter_device *counter, From b11eed1554e8ea33b748094ea73d8b42fa2bbe3b Mon Sep 17 00:00:00 2001 From: William Breathitt Gray Date: Tue, 3 Aug 2021 21:06:12 +0900 Subject: [PATCH 72/77] counter: Return error code on invalid modes Only a select set of modes (function, action, etc.) are valid for a given device configuration. This patch ensures that invalid modes result in a return -EINVAL. Such a situation should never occur in reality, but it's good to define a default switch case for the sake of making the intent of the code clear. Cc: Kamel Bouhara Cc: Maxime Coquelin Cc: Alexandre Torgue Acked-by: David Lechner Acked-by: Syed Nayyar Waris Reviewed-by: Fabrice Gasnier Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/7af82d4e39610da11edce0ee370285fe1cb1eac8.1627990337.git.vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron --- drivers/counter/104-quad-8.c | 20 ++++++++++++------ drivers/counter/microchip-tcb-capture.c | 6 ++++++ drivers/counter/stm32-lptimer-cnt.c | 10 +++++---- drivers/counter/ti-eqep.c | 27 +++++++++++++++---------- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 81f9642777fb..b358b2b2b883 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -273,6 +273,10 @@ static int quad8_function_set(struct counter_device *counter, *scale = 2; mode_cfg |= QUAD8_CMR_QUADRATURE_X4; break; + default: + /* should never reach this path */ + mutex_unlock(&priv->lock); + return -EINVAL; } } @@ -349,7 +353,7 @@ static int quad8_action_get(struct counter_device *counter, case QUAD8_COUNT_FUNCTION_PULSE_DIRECTION: if (synapse->signal->id == signal_a_id) *action = QUAD8_SYNAPSE_ACTION_RISING_EDGE; - break; + return 0; case QUAD8_COUNT_FUNCTION_QUADRATURE_X1: if (synapse->signal->id == signal_a_id) { quad8_direction_get(counter, count, &direction); @@ -359,17 +363,18 @@ static int quad8_action_get(struct counter_device *counter, else *action = QUAD8_SYNAPSE_ACTION_FALLING_EDGE; } - break; + return 0; case QUAD8_COUNT_FUNCTION_QUADRATURE_X2: if (synapse->signal->id == signal_a_id) *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES; - break; + return 0; case QUAD8_COUNT_FUNCTION_QUADRATURE_X4: *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES; - break; + return 0; + default: + /* should never reach this path */ + return -EINVAL; } - - return 0; } static const struct counter_ops quad8_ops = { @@ -529,6 +534,9 @@ static int quad8_count_mode_set(struct counter_device *counter, case COUNTER_COUNT_MODE_MODULO_N: cnt_mode = 3; break; + default: + /* should never reach this path */ + return -EINVAL; } mutex_lock(&priv->lock); diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index 51b8af80f98b..0c9a61962911 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -133,6 +133,9 @@ static int mchp_tc_count_function_set(struct counter_device *counter, bmr |= ATMEL_TC_QDEN | ATMEL_TC_POSEN; cmr |= ATMEL_TC_ETRGEDG_RISING | ATMEL_TC_ABETRG | ATMEL_TC_XC0; break; + default: + /* should never reach this path */ + return -EINVAL; } regmap_write(priv->regmap, ATMEL_TC_BMR, bmr); @@ -226,6 +229,9 @@ static int mchp_tc_count_action_set(struct counter_device *counter, case MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE: edge = ATMEL_TC_ETRGEDG_BOTH; break; + default: + /* should never reach this path */ + return -EINVAL; } return regmap_write_bits(priv->regmap, diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c index c19d998df5ba..78f383b77bd2 100644 --- a/drivers/counter/stm32-lptimer-cnt.c +++ b/drivers/counter/stm32-lptimer-cnt.c @@ -206,9 +206,10 @@ static int stm32_lptim_cnt_function_set(struct counter_device *counter, priv->quadrature_mode = 1; priv->polarity = STM32_LPTIM_SYNAPSE_ACTION_BOTH_EDGES; return 0; + default: + /* should never reach this path */ + return -EINVAL; } - - return -EINVAL; } static ssize_t stm32_lptim_cnt_enable_read(struct counter_device *counter, @@ -326,9 +327,10 @@ static int stm32_lptim_cnt_action_get(struct counter_device *counter, case STM32_LPTIM_ENCODER_BOTH_EDGE: *action = priv->polarity; return 0; + default: + /* should never reach this path */ + return -EINVAL; } - - return -EINVAL; } static int stm32_lptim_cnt_action_set(struct counter_device *counter, diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c index 65df9ef5b5bc..c303eb17c111 100644 --- a/drivers/counter/ti-eqep.c +++ b/drivers/counter/ti-eqep.c @@ -157,7 +157,7 @@ static int ti_eqep_action_get(struct counter_device *counter, * QEPA and QEPB trigger QCLK. */ *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES; - break; + return 0; case TI_EQEP_COUNT_FUNC_DIR_COUNT: /* In direction-count mode only rising edge of QEPA is counted * and QEPB gives direction. @@ -165,12 +165,14 @@ static int ti_eqep_action_get(struct counter_device *counter, switch (synapse->signal->id) { case TI_EQEP_SIGNAL_QEPA: *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE; - break; - default: + return 0; + case TI_EQEP_SIGNAL_QEPB: *action = TI_EQEP_SYNAPSE_ACTION_NONE; - break; + return 0; + default: + /* should never reach this path */ + return -EINVAL; } - break; case TI_EQEP_COUNT_FUNC_UP_COUNT: case TI_EQEP_COUNT_FUNC_DOWN_COUNT: /* In up/down-count modes only QEPA is counted and QEPB is not @@ -186,15 +188,18 @@ static int ti_eqep_action_get(struct counter_device *counter, *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES; else *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE; - break; - default: + return 0; + case TI_EQEP_SIGNAL_QEPB: *action = TI_EQEP_SYNAPSE_ACTION_NONE; - break; + return 0; + default: + /* should never reach this path */ + return -EINVAL; } - break; + default: + /* should never reach this path */ + return -EINVAL; } - - return 0; } static const struct counter_ops ti_eqep_counter_ops = { From e2ff3198c580a3a3acfdc50cce5b5f8a941cbcd1 Mon Sep 17 00:00:00 2001 From: William Breathitt Gray Date: Tue, 3 Aug 2021 21:06:13 +0900 Subject: [PATCH 73/77] counter: Standardize to ERANGE for limit exceeded errors ERANGE is a semantically better error code to return when an argument value falls outside the supported limit range of a device. Cc: Jarkko Nikula Cc: Oleksij Rempel Cc: Maxime Coquelin Cc: Alexandre Torgue Acked-by: Syed Nayyar Waris Reviewed-by: David Lechner Reviewed-by: Fabrice Gasnier Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/ae8d3b20b8b02c96b1c9898ffa2f9fa5d99edc81.1627990337.git.vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron --- drivers/counter/104-quad-8.c | 6 +++--- drivers/counter/intel-qep.c | 2 +- drivers/counter/interrupt-cnt.c | 3 +++ drivers/counter/stm32-lptimer-cnt.c | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index b358b2b2b883..d54efdb8d393 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -154,7 +154,7 @@ static int quad8_count_write(struct counter_device *counter, /* Only 24-bit values are supported */ if (val > 0xFFFFFF) - return -EINVAL; + return -ERANGE; mutex_lock(&priv->lock); @@ -669,7 +669,7 @@ static ssize_t quad8_count_preset_write(struct counter_device *counter, /* Only 24-bit values are supported */ if (preset > 0xFFFFFF) - return -EINVAL; + return -ERANGE; mutex_lock(&priv->lock); @@ -714,7 +714,7 @@ static ssize_t quad8_count_ceiling_write(struct counter_device *counter, /* Only 24-bit values are supported */ if (ceiling > 0xFFFFFF) - return -EINVAL; + return -ERANGE; mutex_lock(&priv->lock); diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index 1a9512e28519..204f94577666 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -319,7 +319,7 @@ static ssize_t spike_filter_ns_write(struct counter_device *counter, } if (length > INTEL_QEPFLT_MAX_COUNT(length)) - return -EINVAL; + return -ERANGE; mutex_lock(&qep->lock); if (qep->enabled) { diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c index 5df7cd13d4c7..66cac4900327 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -107,6 +107,9 @@ static int interrupt_cnt_write(struct counter_device *counter, { struct interrupt_cnt_priv *priv = counter->priv; + if (val != (typeof(priv->count.counter))val) + return -ERANGE; + atomic_set(&priv->count, val); return 0; diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c index 78f383b77bd2..49aeb9e393f3 100644 --- a/drivers/counter/stm32-lptimer-cnt.c +++ b/drivers/counter/stm32-lptimer-cnt.c @@ -283,7 +283,7 @@ static ssize_t stm32_lptim_cnt_ceiling_write(struct counter_device *counter, return ret; if (ceiling > STM32_LPTIM_MAX_ARR) - return -EINVAL; + return -ERANGE; priv->ceiling = ceiling; From 493b938a14ed78d7e44c33d1c1e349656a16c360 Mon Sep 17 00:00:00 2001 From: William Breathitt Gray Date: Tue, 3 Aug 2021 21:06:14 +0900 Subject: [PATCH 74/77] counter: Rename counter_signal_value to counter_signal_level Signal values will always be levels so let's be explicit it about it to make the intent of the code clear. Cc: Oleksij Rempel Cc: Kamel Bouhara Acked-by: Syed Nayyar Waris Reviewed-by: David Lechner Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/3f17010abe2415859cea9a5fddabd3c97f635ff5.1627990337.git.vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron --- drivers/counter/104-quad-8.c | 5 +++-- drivers/counter/counter.c | 12 ++++++------ drivers/counter/interrupt-cnt.c | 4 ++-- drivers/counter/microchip-tcb-capture.c | 4 ++-- include/linux/counter.h | 12 ++++++------ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index d54efdb8d393..b4dd07cf51eb 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -97,7 +97,8 @@ struct quad8 { #define QUAD8_CMR_QUADRATURE_X4 0x18 static int quad8_signal_read(struct counter_device *counter, - struct counter_signal *signal, enum counter_signal_value *val) + struct counter_signal *signal, + enum counter_signal_level *level) { const struct quad8 *const priv = counter->priv; unsigned int state; @@ -109,7 +110,7 @@ static int quad8_signal_read(struct counter_device *counter, state = inb(priv->base + QUAD8_REG_INDEX_INPUT_LEVELS) & BIT(signal->id - 16); - *val = (state) ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW; + *level = (state) ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW; return 0; } diff --git a/drivers/counter/counter.c b/drivers/counter/counter.c index 6a683d086008..cb92673552b5 100644 --- a/drivers/counter/counter.c +++ b/drivers/counter/counter.c @@ -289,9 +289,9 @@ struct counter_signal_unit { struct counter_signal *signal; }; -static const char *const counter_signal_value_str[] = { - [COUNTER_SIGNAL_LOW] = "low", - [COUNTER_SIGNAL_HIGH] = "high" +static const char *const counter_signal_level_str[] = { + [COUNTER_SIGNAL_LEVEL_LOW] = "low", + [COUNTER_SIGNAL_LEVEL_HIGH] = "high" }; static ssize_t counter_signal_show(struct device *dev, @@ -302,13 +302,13 @@ static ssize_t counter_signal_show(struct device *dev, const struct counter_signal_unit *const component = devattr->component; struct counter_signal *const signal = component->signal; int err; - enum counter_signal_value val; + enum counter_signal_level level; - err = counter->ops->signal_read(counter, signal, &val); + err = counter->ops->signal_read(counter, signal, &level); if (err) return err; - return sprintf(buf, "%s\n", counter_signal_value_str[val]); + return sprintf(buf, "%s\n", counter_signal_level_str[level]); } struct counter_name_unit { diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c index 66cac4900327..d06367bef8f0 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -130,7 +130,7 @@ static int interrupt_cnt_function_get(struct counter_device *counter, static int interrupt_cnt_signal_read(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_value *val) + enum counter_signal_level *level) { struct interrupt_cnt_priv *priv = counter->priv; int ret; @@ -142,7 +142,7 @@ static int interrupt_cnt_signal_read(struct counter_device *counter, if (ret < 0) return ret; - *val = ret ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW; + *level = ret ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW; return 0; } diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index 0c9a61962911..6be3adf74114 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -158,7 +158,7 @@ static int mchp_tc_count_function_set(struct counter_device *counter, static int mchp_tc_count_signal_read(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_value *val) + enum counter_signal_level *lvl) { struct mchp_tc_data *const priv = counter->priv; bool sigstatus; @@ -171,7 +171,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter, else sigstatus = (sr & ATMEL_TC_MTIOA); - *val = sigstatus ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW; + *lvl = sigstatus ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW; return 0; } diff --git a/include/linux/counter.h b/include/linux/counter.h index 9dbd5df4cd34..79f5dcaf6ba0 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -290,16 +290,16 @@ struct counter_device_state { const struct attribute_group **groups; }; -enum counter_signal_value { - COUNTER_SIGNAL_LOW = 0, - COUNTER_SIGNAL_HIGH +enum counter_signal_level { + COUNTER_SIGNAL_LEVEL_LOW, + COUNTER_SIGNAL_LEVEL_HIGH, }; /** * struct counter_ops - Callbacks from driver * @signal_read: optional read callback for Signal attribute. The read - * value of the respective Signal should be passed back via - * the val parameter. + * level of the respective Signal should be passed back via + * the level parameter. * @count_read: optional read callback for Count attribute. The read * value of the respective Count should be passed back via * the val parameter. @@ -324,7 +324,7 @@ enum counter_signal_value { struct counter_ops { int (*signal_read)(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_value *val); + enum counter_signal_level *level); int (*count_read)(struct counter_device *counter, struct counter_count *count, unsigned long *val); int (*count_write)(struct counter_device *counter, From 394a0150a0644389ce4d587f5c67393308eec28c Mon Sep 17 00:00:00 2001 From: William Breathitt Gray Date: Tue, 3 Aug 2021 21:06:15 +0900 Subject: [PATCH 75/77] counter: Rename counter_count_function to counter_function The phrase "Counter Count function" is verbose and unintentionally implies that function is a Count extension. This patch adjusts the Counter subsystem code to use the more direct "Counter function" phrase to make the intent of this code clearer. Cc: Jarkko Nikula Cc: Patrick Havelange Cc: Oleksij Rempel Cc: Kamel Bouhara Cc: Maxime Coquelin Cc: Alexandre Torgue Cc: David Lechner Acked-by: Syed Nayyar Waris Reviewed-by: Fabrice Gasnier Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/8268c54d6f42075a19bb08151a37831e22652499.1627990337.git.vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron --- drivers/counter/104-quad-8.c | 10 +++---- drivers/counter/counter.c | 38 ++++++++++++------------- drivers/counter/ftm-quaddec.c | 5 ++-- drivers/counter/intel-qep.c | 4 +-- drivers/counter/interrupt-cnt.c | 4 +-- drivers/counter/microchip-tcb-capture.c | 6 ++-- drivers/counter/stm32-lptimer-cnt.c | 6 ++-- drivers/counter/stm32-timer-cnt.c | 10 +++---- drivers/counter/ti-eqep.c | 10 +++---- include/linux/counter.h | 20 ++++++------- 10 files changed, 56 insertions(+), 57 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index b4dd07cf51eb..5283ff128c17 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -194,11 +194,11 @@ enum quad8_count_function { QUAD8_COUNT_FUNCTION_QUADRATURE_X4 }; -static const enum counter_count_function quad8_count_functions_list[] = { - [QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = COUNTER_COUNT_FUNCTION_PULSE_DIRECTION, - [QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A, - [QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, - [QUAD8_COUNT_FUNCTION_QUADRATURE_X4] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4 +static const enum counter_function quad8_count_functions_list[] = { + [QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = COUNTER_FUNCTION_PULSE_DIRECTION, + [QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = COUNTER_FUNCTION_QUADRATURE_X1_A, + [QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = COUNTER_FUNCTION_QUADRATURE_X2_A, + [QUAD8_COUNT_FUNCTION_QUADRATURE_X4] = COUNTER_FUNCTION_QUADRATURE_X4 }; static int quad8_function_get(struct counter_device *counter, diff --git a/drivers/counter/counter.c b/drivers/counter/counter.c index cb92673552b5..de921e8a3f72 100644 --- a/drivers/counter/counter.c +++ b/drivers/counter/counter.c @@ -744,15 +744,15 @@ static ssize_t counter_count_store(struct device *dev, return len; } -static const char *const counter_count_function_str[] = { - [COUNTER_COUNT_FUNCTION_INCREASE] = "increase", - [COUNTER_COUNT_FUNCTION_DECREASE] = "decrease", - [COUNTER_COUNT_FUNCTION_PULSE_DIRECTION] = "pulse-direction", - [COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A] = "quadrature x1 a", - [COUNTER_COUNT_FUNCTION_QUADRATURE_X1_B] = "quadrature x1 b", - [COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A] = "quadrature x2 a", - [COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B] = "quadrature x2 b", - [COUNTER_COUNT_FUNCTION_QUADRATURE_X4] = "quadrature x4" +static const char *const counter_function_str[] = { + [COUNTER_FUNCTION_INCREASE] = "increase", + [COUNTER_FUNCTION_DECREASE] = "decrease", + [COUNTER_FUNCTION_PULSE_DIRECTION] = "pulse-direction", + [COUNTER_FUNCTION_QUADRATURE_X1_A] = "quadrature x1 a", + [COUNTER_FUNCTION_QUADRATURE_X1_B] = "quadrature x1 b", + [COUNTER_FUNCTION_QUADRATURE_X2_A] = "quadrature x2 a", + [COUNTER_FUNCTION_QUADRATURE_X2_B] = "quadrature x2 b", + [COUNTER_FUNCTION_QUADRATURE_X4] = "quadrature x4" }; static ssize_t counter_function_show(struct device *dev, @@ -764,7 +764,7 @@ static ssize_t counter_function_show(struct device *dev, const struct counter_count_unit *const component = devattr->component; struct counter_count *const count = component->count; size_t func_index; - enum counter_count_function function; + enum counter_function function; err = counter->ops->function_get(counter, count, &func_index); if (err) @@ -773,7 +773,7 @@ static ssize_t counter_function_show(struct device *dev, count->function = func_index; function = count->functions_list[func_index]; - return sprintf(buf, "%s\n", counter_count_function_str[function]); + return sprintf(buf, "%s\n", counter_function_str[function]); } static ssize_t counter_function_store(struct device *dev, @@ -785,14 +785,14 @@ static ssize_t counter_function_store(struct device *dev, struct counter_count *const count = component->count; const size_t num_functions = count->num_functions; size_t func_index; - enum counter_count_function function; + enum counter_function function; int err; struct counter_device *const counter = dev_get_drvdata(dev); /* Find requested Count function mode */ for (func_index = 0; func_index < num_functions; func_index++) { function = count->functions_list[func_index]; - if (sysfs_streq(buf, counter_count_function_str[function])) + if (sysfs_streq(buf, counter_function_str[function])) break; } /* Return error if requested Count function mode not found */ @@ -880,25 +880,25 @@ err_free_attr_list: } struct counter_func_avail_unit { - const enum counter_count_function *functions_list; + const enum counter_function *functions_list; size_t num_functions; }; -static ssize_t counter_count_function_available_show(struct device *dev, +static ssize_t counter_function_available_show(struct device *dev, struct device_attribute *attr, char *buf) { const struct counter_device_attr *const devattr = to_counter_attr(attr); const struct counter_func_avail_unit *const component = devattr->component; - const enum counter_count_function *const func_list = component->functions_list; + const enum counter_function *const func_list = component->functions_list; const size_t num_functions = component->num_functions; size_t i; - enum counter_count_function function; + enum counter_function function; ssize_t len = 0; for (i = 0; i < num_functions; i++) { function = func_list[i]; len += sprintf(buf + len, "%s\n", - counter_count_function_str[function]); + counter_function_str[function]); } return len; @@ -968,7 +968,7 @@ static int counter_count_attributes_create( parm.group = group; parm.prefix = ""; parm.name = "function_available"; - parm.show = counter_count_function_available_show; + parm.show = counter_function_available_show; parm.store = NULL; parm.component = avail_comp; err = counter_attribute_create(&parm); diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c index 9371532406ca..53c15f84909b 100644 --- a/drivers/counter/ftm-quaddec.c +++ b/drivers/counter/ftm-quaddec.c @@ -171,9 +171,8 @@ enum ftm_quaddec_count_function { FTM_QUADDEC_COUNT_ENCODER_MODE_1, }; -static const enum counter_count_function ftm_quaddec_count_functions[] = { - [FTM_QUADDEC_COUNT_ENCODER_MODE_1] = - COUNTER_COUNT_FUNCTION_QUADRATURE_X4 +static const enum counter_function ftm_quaddec_count_functions[] = { + [FTM_QUADDEC_COUNT_ENCODER_MODE_1] = COUNTER_FUNCTION_QUADRATURE_X4 }; static int ftm_quaddec_count_read(struct counter_device *counter, diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index 204f94577666..8a6847d5fb2b 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -126,8 +126,8 @@ static int intel_qep_count_read(struct counter_device *counter, return 0; } -static const enum counter_count_function intel_qep_count_functions[] = { - COUNTER_COUNT_FUNCTION_QUADRATURE_X4, +static const enum counter_function intel_qep_count_functions[] = { + COUNTER_FUNCTION_QUADRATURE_X4, }; static int intel_qep_function_get(struct counter_device *counter, diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c index d06367bef8f0..1de4243db488 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -115,8 +115,8 @@ static int interrupt_cnt_write(struct counter_device *counter, return 0; } -static const enum counter_count_function interrupt_cnt_functions[] = { - COUNTER_COUNT_FUNCTION_INCREASE, +static const enum counter_function interrupt_cnt_functions[] = { + COUNTER_FUNCTION_INCREASE, }; static int interrupt_cnt_function_get(struct counter_device *counter, diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index 6be3adf74114..1aa70b9c4833 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -37,9 +37,9 @@ enum mchp_tc_count_function { MCHP_TC_FUNCTION_QUADRATURE, }; -static const enum counter_count_function mchp_tc_count_functions[] = { - [MCHP_TC_FUNCTION_INCREASE] = COUNTER_COUNT_FUNCTION_INCREASE, - [MCHP_TC_FUNCTION_QUADRATURE] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, +static const enum counter_function mchp_tc_count_functions[] = { + [MCHP_TC_FUNCTION_INCREASE] = COUNTER_FUNCTION_INCREASE, + [MCHP_TC_FUNCTION_QUADRATURE] = COUNTER_FUNCTION_QUADRATURE_X4, }; enum mchp_tc_synapse_action { diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c index 49aeb9e393f3..13656957c45f 100644 --- a/drivers/counter/stm32-lptimer-cnt.c +++ b/drivers/counter/stm32-lptimer-cnt.c @@ -134,9 +134,9 @@ enum stm32_lptim_cnt_function { STM32_LPTIM_ENCODER_BOTH_EDGE, }; -static const enum counter_count_function stm32_lptim_cnt_functions[] = { - [STM32_LPTIM_COUNTER_INCREASE] = COUNTER_COUNT_FUNCTION_INCREASE, - [STM32_LPTIM_ENCODER_BOTH_EDGE] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, +static const enum counter_function stm32_lptim_cnt_functions[] = { + [STM32_LPTIM_COUNTER_INCREASE] = COUNTER_FUNCTION_INCREASE, + [STM32_LPTIM_ENCODER_BOTH_EDGE] = COUNTER_FUNCTION_QUADRATURE_X4, }; enum stm32_lptim_synapse_action { diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c index 603b30ada839..3fb0debd7425 100644 --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -50,11 +50,11 @@ enum stm32_count_function { STM32_COUNT_ENCODER_MODE_3, }; -static const enum counter_count_function stm32_count_functions[] = { - [STM32_COUNT_SLAVE_MODE_DISABLED] = COUNTER_COUNT_FUNCTION_INCREASE, - [STM32_COUNT_ENCODER_MODE_1] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, - [STM32_COUNT_ENCODER_MODE_2] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B, - [STM32_COUNT_ENCODER_MODE_3] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, +static const enum counter_function stm32_count_functions[] = { + [STM32_COUNT_SLAVE_MODE_DISABLED] = COUNTER_FUNCTION_INCREASE, + [STM32_COUNT_ENCODER_MODE_1] = COUNTER_FUNCTION_QUADRATURE_X2_A, + [STM32_COUNT_ENCODER_MODE_2] = COUNTER_FUNCTION_QUADRATURE_X2_B, + [STM32_COUNT_ENCODER_MODE_3] = COUNTER_FUNCTION_QUADRATURE_X4, }; static int stm32_count_read(struct counter_device *counter, diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c index c303eb17c111..94fe58bb3eab 100644 --- a/drivers/counter/ti-eqep.c +++ b/drivers/counter/ti-eqep.c @@ -294,11 +294,11 @@ static struct counter_signal ti_eqep_signals[] = { }, }; -static const enum counter_count_function ti_eqep_position_functions[] = { - [TI_EQEP_COUNT_FUNC_QUAD_COUNT] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, - [TI_EQEP_COUNT_FUNC_DIR_COUNT] = COUNTER_COUNT_FUNCTION_PULSE_DIRECTION, - [TI_EQEP_COUNT_FUNC_UP_COUNT] = COUNTER_COUNT_FUNCTION_INCREASE, - [TI_EQEP_COUNT_FUNC_DOWN_COUNT] = COUNTER_COUNT_FUNCTION_DECREASE, +static const enum counter_function ti_eqep_position_functions[] = { + [TI_EQEP_COUNT_FUNC_QUAD_COUNT] = COUNTER_FUNCTION_QUADRATURE_X4, + [TI_EQEP_COUNT_FUNC_DIR_COUNT] = COUNTER_FUNCTION_PULSE_DIRECTION, + [TI_EQEP_COUNT_FUNC_UP_COUNT] = COUNTER_FUNCTION_INCREASE, + [TI_EQEP_COUNT_FUNC_DOWN_COUNT] = COUNTER_FUNCTION_DECREASE, }; static const enum counter_synapse_action ti_eqep_position_synapse_actions[] = { diff --git a/include/linux/counter.h b/include/linux/counter.h index 79f5dcaf6ba0..d16ce2819b48 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -162,15 +162,15 @@ struct counter_count_ext { void *priv; }; -enum counter_count_function { - COUNTER_COUNT_FUNCTION_INCREASE = 0, - COUNTER_COUNT_FUNCTION_DECREASE, - COUNTER_COUNT_FUNCTION_PULSE_DIRECTION, - COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A, - COUNTER_COUNT_FUNCTION_QUADRATURE_X1_B, - COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, - COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B, - COUNTER_COUNT_FUNCTION_QUADRATURE_X4 +enum counter_function { + COUNTER_FUNCTION_INCREASE = 0, + COUNTER_FUNCTION_DECREASE, + COUNTER_FUNCTION_PULSE_DIRECTION, + COUNTER_FUNCTION_QUADRATURE_X1_A, + COUNTER_FUNCTION_QUADRATURE_X1_B, + COUNTER_FUNCTION_QUADRATURE_X2_A, + COUNTER_FUNCTION_QUADRATURE_X2_B, + COUNTER_FUNCTION_QUADRATURE_X4 }; /** @@ -192,7 +192,7 @@ struct counter_count { const char *name; size_t function; - const enum counter_count_function *functions_list; + const enum counter_function *functions_list; size_t num_functions; struct counter_synapse *synapses; From 3304d2b69a36996fb9bf708310de5cd76a04c09e Mon Sep 17 00:00:00 2001 From: Ye Xiang Date: Sat, 31 Jul 2021 11:25:56 +0800 Subject: [PATCH 76/77] iio: hid-sensor-press: Add timestamp channel Each sample has a timestamp field with this change. This timestamp may be from the sensor hub when present or local kernel timestamp. The unit of timestamp is nanosecond. Signed-off-by: Ye Xiang Link: https://lore.kernel.org/r/20210731032556.26813-1-xiang.ye@intel.com Signed-off-by: Jonathan Cameron --- drivers/iio/pressure/hid-sensor-press.c | 40 +++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c index dcd593c426b4..a9215eb32d70 100644 --- a/drivers/iio/pressure/hid-sensor-press.c +++ b/drivers/iio/pressure/hid-sensor-press.c @@ -13,17 +13,24 @@ #include #include "../common/hid-sensors/hid-sensor-trigger.h" -#define CHANNEL_SCAN_INDEX_PRESSURE 0 +enum { + CHANNEL_SCAN_INDEX_PRESSURE, + CHANNEL_SCAN_INDEX_TIMESTAMP, +}; struct press_state { struct hid_sensor_hub_callbacks callbacks; struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info press_attr; - u32 press_data; + struct { + u32 press_data; + u64 timestamp __aligned(8); + } scan; int scale_pre_decml; int scale_post_decml; int scale_precision; int value_offset; + s64 timestamp; }; static const u32 press_sensitivity_addresses[] = { @@ -41,7 +48,9 @@ static const struct iio_chan_spec press_channels[] = { BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_HYSTERESIS), .scan_index = CHANNEL_SCAN_INDEX_PRESSURE, - } + }, + IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP) + }; /* Adjust channel real bits based on report descriptor */ @@ -154,14 +163,6 @@ static const struct iio_info press_info = { .write_raw = &press_write_raw, }; -/* Function to push data to buffer */ -static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, - int len) -{ - dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); - iio_push_to_buffers(indio_dev, data); -} - /* Callback handler to send event after all samples are received and captured */ static int press_proc_event(struct hid_sensor_hub_device *hsdev, unsigned usage_id, @@ -171,10 +172,13 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev, struct press_state *press_state = iio_priv(indio_dev); dev_dbg(&indio_dev->dev, "press_proc_event\n"); - if (atomic_read(&press_state->common_attributes.data_ready)) - hid_sensor_push_data(indio_dev, - &press_state->press_data, - sizeof(press_state->press_data)); + if (atomic_read(&press_state->common_attributes.data_ready)) { + if (!press_state->timestamp) + press_state->timestamp = iio_get_time_ns(indio_dev); + + iio_push_to_buffers_with_timestamp( + indio_dev, &press_state->scan, press_state->timestamp); + } return 0; } @@ -191,9 +195,13 @@ static int press_capture_sample(struct hid_sensor_hub_device *hsdev, switch (usage_id) { case HID_USAGE_SENSOR_ATMOSPHERIC_PRESSURE: - press_state->press_data = *(u32 *)raw_data; + press_state->scan.press_data = *(u32 *)raw_data; ret = 0; break; + case HID_USAGE_SENSOR_TIME_TIMESTAMP: + press_state->timestamp = hid_sensor_convert_timestamp( + &press_state->common_attributes, *(s64 *)raw_data); + break; default: break; } From 94a853eca720ac9e385e59f27e859b4a01123f58 Mon Sep 17 00:00:00 2001 From: William Breathitt Gray Date: Mon, 9 Aug 2021 21:37:26 +0900 Subject: [PATCH 77/77] counter: 104-quad-8: Describe member 'lock' in 'quad8' This adds a kernel-doc comment line describing the 'lock' member of the 'quad8' structure. Acked-by: Syed Nayyar Waris Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/43b4acab9e238638c7067dd4a363a42f94c94ccb.1628511445.git.vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron --- drivers/counter/104-quad-8.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 5283ff128c17..0caa60537b14 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -28,6 +28,7 @@ MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses"); /** * struct quad8 - device private data structure + * @lock: lock to prevent clobbering device states during R/W ops * @counter: instance of the counter_device * @fck_prescaler: array of filter clock prescaler configurations * @preset: array of preset values