Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'iio-fixes-for-7.0b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linux

Jonathan writes:

IIO: 2nd set of fixes for the 7.0 cycle

Usual mixed bag of fixes for recent code and much older issues that have
surfaced. Biggest group are continued resolution of IRQF_ONE_SHOT
being used incorrectly (which now triggers a warning)

adi,ad4062
- Replace IRQF_ONESHOT (as no threaded handler) with IRQF_NO_THREAD as
the caller makes use of iio_trigger_poll() which cannot run from a
thread.
adi,ade9000
- Move mutex_init() earlier to ensure it is available if spurious IRQ
occurs.
adi,adis16550
- Fix swapped gyro and accel filter functions.
adi,adxl3380
- Fix some bit manipulation that was always resulting in 0.
- Fix incorrect register map for calibbias on the active power channel.
- Fix returning IRQF_HANDLED from a function that should return 0 or
-ERRNO.
aspeed,adc
- Clear a reference voltage bit that might be set prior to driver load.
bosch,bno055
- Off by one channel buffer sizing. Benine due to padding prior to the
subsequent timestamp.
hid-sensors
- A more complex fix to IRQF_ONESHOT warning as this driver had a trigger
that was never actually used but the ABI that exposed had to be
maintained to avoid regressions.
hid-sensors-rotation
- An obscure buffer alignment case that applies to quaternions only was
recently broken resulting in writes beyond the end of the channel buffer.
Add a new core macro and apply it in this driver to make it very clear
what was going on.
honeywell,abp2030pa
- Remove meaningless IRQF_ONESHOT from a non threaded IRQ handler.
Warning fix only.
invense,mpu3050
- Fix token passed to free_irq() to match the one used at setup.
- Fix an irq resource leak in error path.
- Reorder probe so that userspace interfaces are exposed only after
everything else has finished.
- Reorder remove slightly to cleanup the buffer only after irq removed
ensuring reverse of probe sequence.
microchip,mcp47feb02
- Fix use of mutex before it was initialized by not performing unnecessary
lock that was early enough in probe that all code was serial.
st,lsm6dsx
- Ensure that FIFO ODR is only controllable for accel and gyro channels
avoiding incorrect register accesses.
- Restrict separation of buffer sampling from main sampling rate to
accelerometer. It is only useful for running event detection faster
than the fifo and the only events are on the accelerometer.
ti,ads1018
- Fix overflow of u8 which wasn't big enough to store max data rate value.
ti,ads1119:
- Fix unbalanced pm in an error path.
- IRQF_ONESHOT (as no threaded handler) replaced with IRQF_NO_THREAD
(needed for iio_trigger_poll()).
- Ensure complete reinitialized before reuse. Previously it would have
completed immediate after the first time.
ti,ads7950
- Fix return value of gpio_get() to be 0 or 1.
- Avoid accidental overwrite of state resulting in gpio_get() only
returning 0 or -ERRNO but never 1.

* tag 'iio-fixes-for-7.0b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (25 commits)
iio: imu: adis16550: fix swapped gyro/accel filter functions
iio: adc: aspeed: clear reference voltage bits before configuring vref
iio: adc: ti-ads1119: Reinit completion before wait_for_completion_timeout()
iio: adc: ti-ads1018: fix type overflow for data rate
iio: adc: ti-ads7950: do not clobber gpio state in ti_ads7950_get()
iio: adc: ti-ads7950: normalize return value of gpio_get
iio: orientation: hid-sensor-rotation: fix quaternion alignment
iio: add IIO_DECLARE_QUATERNION() macro
iio: adc: ti-ads1119: Replace IRQF_ONESHOT with IRQF_NO_THREAD
iio: imu: bno055: fix BNO055_SCAN_CH_COUNT off by one
iio: hid-sensors: Use software trigger
iio: adc: ad4062: Replace IRQF_ONESHOT with IRQF_NO_THREAD
iio: gyro: mpu3050: Fix out-of-sequence free_irq()
iio: gyro: mpu3050: Move iio_device_register() to correct location
iio: gyro: mpu3050: Fix irq resource leak
iio: gyro: mpu3050: Fix incorrect free_irq() variable
iio: imu: st_lsm6dsx: Set buffer sampling frequency for accelerometer only
iio: imu: st_lsm6dsx: Set FIFO ODR for accelerometer and gyroscope only
iio: dac: mcp47feb02: Fix mutex used before initialization
iio: adc: ade9000: fix wrong return type in streaming push
...

+107 -60
+1 -1
drivers/iio/accel/adxl380.c
··· 877 877 ret = regmap_update_bits(st->regmap, ADXL380_FIFO_CONFIG_0_REG, 878 878 ADXL380_FIFO_SAMPLES_8_MSK, 879 879 FIELD_PREP(ADXL380_FIFO_SAMPLES_8_MSK, 880 - (fifo_samples & BIT(8)))); 880 + !!(fifo_samples & BIT(8)))); 881 881 if (ret) 882 882 return ret; 883 883
+3 -5
drivers/iio/adc/ad4062.c
··· 719 719 } 720 720 st->gpo_irq[1] = true; 721 721 722 - return devm_request_threaded_irq(dev, ret, 723 - ad4062_irq_handler_drdy, 724 - NULL, IRQF_ONESHOT, indio_dev->name, 725 - indio_dev); 722 + return devm_request_irq(dev, ret, ad4062_irq_handler_drdy, 723 + IRQF_NO_THREAD, indio_dev->name, indio_dev); 726 724 } 727 725 728 726 static const struct iio_trigger_ops ad4062_trigger_ops = { ··· 953 955 default: 954 956 return -EINVAL; 955 957 } 956 - }; 958 + } 957 959 958 960 static int ad4062_write_raw(struct iio_dev *indio_dev, 959 961 struct iio_chan_spec const *chan, int val,
+6 -6
drivers/iio/adc/ade9000.c
··· 787 787 ADE9000_MIDDLE_PAGE_BIT); 788 788 if (ret) { 789 789 dev_err_ratelimited(dev, "IRQ0 WFB write fail"); 790 - return IRQ_HANDLED; 790 + return ret; 791 791 } 792 792 793 793 ade9000_configure_scan(indio_dev, ADE9000_REG_WF_BUFF); ··· 1123 1123 tmp &= ~ADE9000_PHASE_C_POS_BIT; 1124 1124 1125 1125 switch (tmp) { 1126 - case ADE9000_REG_AWATTOS: 1126 + case ADE9000_REG_AWATT: 1127 1127 return regmap_write(st->regmap, 1128 1128 ADE9000_ADDR_ADJUST(ADE9000_REG_AWATTOS, 1129 1129 chan->channel), val); ··· 1706 1706 1707 1707 init_completion(&st->reset_completion); 1708 1708 1709 + ret = devm_mutex_init(dev, &st->lock); 1710 + if (ret) 1711 + return ret; 1712 + 1709 1713 ret = ade9000_request_irq(dev, "irq0", ade9000_irq0_thread, indio_dev); 1710 1714 if (ret) 1711 1715 return ret; ··· 1719 1715 return ret; 1720 1716 1721 1717 ret = ade9000_request_irq(dev, "dready", ade9000_dready_thread, indio_dev); 1722 - if (ret) 1723 - return ret; 1724 - 1725 - ret = devm_mutex_init(dev, &st->lock); 1726 1718 if (ret) 1727 1719 return ret; 1728 1720
+1
drivers/iio/adc/aspeed_adc.c
··· 415 415 } 416 416 adc_engine_control_reg_val = 417 417 readl(data->base + ASPEED_REG_ENGINE_CONTROL); 418 + adc_engine_control_reg_val &= ~ASPEED_ADC_REF_VOLTAGE; 418 419 419 420 ret = devm_regulator_get_enable_read_voltage(data->dev, "vref"); 420 421 if (ret < 0 && ret != -ENODEV)
+1 -1
drivers/iio/adc/ti-ads1018.c
··· 249 249 struct iio_chan_spec const *chan, u16 *cnv) 250 250 { 251 251 u8 max_drate_mode = ads1018->chip_info->num_data_rate_mode_to_hz - 1; 252 - u8 drate = ads1018->chip_info->data_rate_mode_to_hz[max_drate_mode]; 252 + u32 drate = ads1018->chip_info->data_rate_mode_to_hz[max_drate_mode]; 253 253 u8 pga_mode = ads1018->chan_data[chan->scan_index].pga_mode; 254 254 struct spi_transfer xfer[2] = { 255 255 {
+6 -5
drivers/iio/adc/ti-ads1119.c
··· 274 274 275 275 ret = pm_runtime_resume_and_get(dev); 276 276 if (ret) 277 - goto pdown; 277 + return ret; 278 278 279 279 ret = ads1119_configure_channel(st, mux, gain, datarate); 280 280 if (ret) 281 281 goto pdown; 282 + 283 + if (st->client->irq) 284 + reinit_completion(&st->completion); 282 285 283 286 ret = i2c_smbus_write_byte(st->client, ADS1119_CMD_START_SYNC); 284 287 if (ret) ··· 738 735 return dev_err_probe(dev, ret, "Failed to setup IIO buffer\n"); 739 736 740 737 if (client->irq > 0) { 741 - ret = devm_request_threaded_irq(dev, client->irq, 742 - ads1119_irq_handler, 743 - NULL, IRQF_ONESHOT, 744 - "ads1119", indio_dev); 738 + ret = devm_request_irq(dev, client->irq, ads1119_irq_handler, 739 + IRQF_NO_THREAD, "ads1119", indio_dev); 745 740 if (ret) 746 741 return dev_err_probe(dev, ret, 747 742 "Failed to allocate irq\n");
+5 -3
drivers/iio/adc/ti-ads7950.c
··· 427 427 static int ti_ads7950_get(struct gpio_chip *chip, unsigned int offset) 428 428 { 429 429 struct ti_ads7950_state *st = gpiochip_get_data(chip); 430 + bool state; 430 431 int ret; 431 432 432 433 mutex_lock(&st->slock); 433 434 434 435 /* If set as output, return the output */ 435 436 if (st->gpio_cmd_settings_bitmask & BIT(offset)) { 436 - ret = st->cmd_settings_bitmask & BIT(offset); 437 + state = st->cmd_settings_bitmask & BIT(offset); 438 + ret = 0; 437 439 goto out; 438 440 } 439 441 ··· 446 444 if (ret) 447 445 goto out; 448 446 449 - ret = ((st->single_rx >> 12) & BIT(offset)) ? 1 : 0; 447 + state = (st->single_rx >> 12) & BIT(offset); 450 448 451 449 /* Revert back to original settings */ 452 450 st->cmd_settings_bitmask &= ~TI_ADS7950_CR_GPIO_DATA; ··· 458 456 out: 459 457 mutex_unlock(&st->slock); 460 458 461 - return ret; 459 + return ret ?: state; 462 460 } 463 461 464 462 static int ti_ads7950_get_direction(struct gpio_chip *chip,
+30 -18
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
··· 14 14 #include <linux/iio/triggered_buffer.h> 15 15 #include <linux/iio/trigger_consumer.h> 16 16 #include <linux/iio/sysfs.h> 17 + #include <linux/iio/kfifo_buf.h> 17 18 #include "hid-sensor-trigger.h" 18 19 19 20 static ssize_t _hid_sensor_set_report_latency(struct device *dev, ··· 203 202 _hid_sensor_power_state(attrb, true); 204 203 } 205 204 206 - static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, 207 - bool state) 205 + static int buffer_postenable(struct iio_dev *indio_dev) 208 206 { 209 - return hid_sensor_power_state(iio_trigger_get_drvdata(trig), state); 207 + return hid_sensor_power_state(iio_device_get_drvdata(indio_dev), 1); 210 208 } 209 + 210 + static int buffer_predisable(struct iio_dev *indio_dev) 211 + { 212 + return hid_sensor_power_state(iio_device_get_drvdata(indio_dev), 0); 213 + } 214 + 215 + static const struct iio_buffer_setup_ops hid_sensor_buffer_ops = { 216 + .postenable = buffer_postenable, 217 + .predisable = buffer_predisable, 218 + }; 211 219 212 220 void hid_sensor_remove_trigger(struct iio_dev *indio_dev, 213 221 struct hid_sensor_common *attrb) ··· 229 219 cancel_work_sync(&attrb->work); 230 220 iio_trigger_unregister(attrb->trigger); 231 221 iio_trigger_free(attrb->trigger); 232 - iio_triggered_buffer_cleanup(indio_dev); 233 222 } 234 223 EXPORT_SYMBOL_NS(hid_sensor_remove_trigger, "IIO_HID"); 235 - 236 - static const struct iio_trigger_ops hid_sensor_trigger_ops = { 237 - .set_trigger_state = &hid_sensor_data_rdy_trigger_set_state, 238 - }; 239 224 240 225 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, 241 226 struct hid_sensor_common *attrb) ··· 244 239 else 245 240 fifo_attrs = NULL; 246 241 247 - ret = iio_triggered_buffer_setup_ext(indio_dev, 248 - &iio_pollfunc_store_time, NULL, 249 - IIO_BUFFER_DIRECTION_IN, 250 - NULL, fifo_attrs); 242 + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_HARDWARE_TRIGGERED; 243 + 244 + ret = devm_iio_kfifo_buffer_setup_ext(&indio_dev->dev, indio_dev, 245 + &hid_sensor_buffer_ops, 246 + fifo_attrs); 251 247 if (ret) { 252 - dev_err(&indio_dev->dev, "Triggered Buffer Setup Failed\n"); 248 + dev_err(&indio_dev->dev, "Kfifo Buffer Setup Failed\n"); 253 249 return ret; 254 250 } 251 + 252 + /* 253 + * The current user space in distro "iio-sensor-proxy" is not working in 254 + * trigerless mode and it expects 255 + * /sys/bus/iio/devices/iio:device0/trigger/current_trigger. 256 + * The change replacing iio_triggered_buffer_setup_ext() with 257 + * devm_iio_kfifo_buffer_setup_ext() will not create attribute without 258 + * registering a trigger with INDIO_HARDWARE_TRIGGERED. 259 + * So the below code fragment is still required. 260 + */ 255 261 256 262 trig = iio_trigger_alloc(indio_dev->dev.parent, 257 263 "%s-dev%d", name, iio_device_id(indio_dev)); 258 264 if (trig == NULL) { 259 265 dev_err(&indio_dev->dev, "Trigger Allocate Failed\n"); 260 - ret = -ENOMEM; 261 - goto error_triggered_buffer_cleanup; 266 + return -ENOMEM; 262 267 } 263 268 264 269 iio_trigger_set_drvdata(trig, attrb); 265 - trig->ops = &hid_sensor_trigger_ops; 266 270 ret = iio_trigger_register(trig); 267 271 268 272 if (ret) { ··· 298 284 iio_trigger_unregister(trig); 299 285 error_free_trig: 300 286 iio_trigger_free(trig); 301 - error_triggered_buffer_cleanup: 302 - iio_triggered_buffer_cleanup(indio_dev); 303 287 return ret; 304 288 } 305 289 EXPORT_SYMBOL_NS(hid_sensor_setup_trigger, "IIO_HID");
-2
drivers/iio/dac/mcp47feb02.c
··· 955 955 u32 num_channels; 956 956 u8 chan_idx = 0; 957 957 958 - guard(mutex)(&data->lock); 959 - 960 958 num_channels = device_get_child_node_count(dev); 961 959 if (num_channels > chip_features->phys_channels) 962 960 return dev_err_probe(dev, -EINVAL, "More channels than the chip supports\n");
+21 -11
drivers/iio/gyro/mpu3050-core.c
··· 1129 1129 1130 1130 ret = iio_trigger_register(mpu3050->trig); 1131 1131 if (ret) 1132 - return ret; 1132 + goto err_iio_trigger; 1133 1133 1134 1134 indio_dev->trig = iio_trigger_get(mpu3050->trig); 1135 1135 1136 1136 return 0; 1137 + 1138 + err_iio_trigger: 1139 + free_irq(mpu3050->irq, mpu3050->trig); 1140 + 1141 + return ret; 1137 1142 } 1138 1143 1139 1144 int mpu3050_common_probe(struct device *dev, ··· 1226 1221 goto err_power_down; 1227 1222 } 1228 1223 1229 - ret = iio_device_register(indio_dev); 1230 - if (ret) { 1231 - dev_err(dev, "device register failed\n"); 1232 - goto err_cleanup_buffer; 1233 - } 1234 - 1235 1224 dev_set_drvdata(dev, indio_dev); 1236 1225 1237 1226 /* Check if we have an assigned IRQ to use as trigger */ ··· 1248 1249 pm_runtime_use_autosuspend(dev); 1249 1250 pm_runtime_put(dev); 1250 1251 1252 + ret = iio_device_register(indio_dev); 1253 + if (ret) { 1254 + dev_err(dev, "device register failed\n"); 1255 + goto err_iio_device_register; 1256 + } 1257 + 1251 1258 return 0; 1252 1259 1253 - err_cleanup_buffer: 1260 + err_iio_device_register: 1261 + pm_runtime_get_sync(dev); 1262 + pm_runtime_put_noidle(dev); 1263 + pm_runtime_disable(dev); 1264 + if (irq) 1265 + free_irq(mpu3050->irq, mpu3050->trig); 1254 1266 iio_triggered_buffer_cleanup(indio_dev); 1255 1267 err_power_down: 1256 1268 mpu3050_power_down(mpu3050); ··· 1274 1264 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1275 1265 struct mpu3050 *mpu3050 = iio_priv(indio_dev); 1276 1266 1267 + iio_device_unregister(indio_dev); 1277 1268 pm_runtime_get_sync(dev); 1278 1269 pm_runtime_put_noidle(dev); 1279 1270 pm_runtime_disable(dev); 1280 - iio_triggered_buffer_cleanup(indio_dev); 1281 1271 if (mpu3050->irq) 1282 - free_irq(mpu3050->irq, mpu3050); 1283 - iio_device_unregister(indio_dev); 1272 + free_irq(mpu3050->irq, mpu3050->trig); 1273 + iio_triggered_buffer_cleanup(indio_dev); 1284 1274 mpu3050_power_down(mpu3050); 1285 1275 } 1286 1276
+4 -4
drivers/iio/imu/adis16550.c
··· 643 643 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 644 644 switch (chan->type) { 645 645 case IIO_ANGL_VEL: 646 - ret = adis16550_get_accl_filter_freq(st, val); 646 + ret = adis16550_get_gyro_filter_freq(st, val); 647 647 if (ret) 648 648 return ret; 649 649 return IIO_VAL_INT; 650 650 case IIO_ACCEL: 651 - ret = adis16550_get_gyro_filter_freq(st, val); 651 + ret = adis16550_get_accl_filter_freq(st, val); 652 652 if (ret) 653 653 return ret; 654 654 return IIO_VAL_INT; ··· 681 681 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 682 682 switch (chan->type) { 683 683 case IIO_ANGL_VEL: 684 - return adis16550_set_accl_filter_freq(st, val); 685 - case IIO_ACCEL: 686 684 return adis16550_set_gyro_filter_freq(st, val); 685 + case IIO_ACCEL: 686 + return adis16550_set_accl_filter_freq(st, val); 687 687 default: 688 688 return -EINVAL; 689 689 }
+1 -1
drivers/iio/imu/bno055/bno055.c
··· 64 64 #define BNO055_GRAVITY_DATA_X_LSB_REG 0x2E 65 65 #define BNO055_GRAVITY_DATA_Y_LSB_REG 0x30 66 66 #define BNO055_GRAVITY_DATA_Z_LSB_REG 0x32 67 - #define BNO055_SCAN_CH_COUNT ((BNO055_GRAVITY_DATA_Z_LSB_REG - BNO055_ACC_DATA_X_LSB_REG) / 2) 67 + #define BNO055_SCAN_CH_COUNT ((BNO055_GRAVITY_DATA_Z_LSB_REG - BNO055_ACC_DATA_X_LSB_REG) / 2 + 1) 68 68 #define BNO055_TEMP_REG 0x34 69 69 #define BNO055_CALIB_STAT_REG 0x35 70 70 #define BNO055_CALIB_STAT_MAGN_SHIFT 0
+14 -1
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
··· 225 225 const struct st_lsm6dsx_reg *batch_reg; 226 226 u8 data; 227 227 228 + /* Only internal sensors have a FIFO ODR configuration register. */ 229 + if (sensor->id >= ARRAY_SIZE(hw->settings->batch)) 230 + return 0; 231 + 228 232 batch_reg = &hw->settings->batch[sensor->id]; 229 233 if (batch_reg->addr) { 230 234 int val; ··· 862 858 int i, ret; 863 859 864 860 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 861 + const struct iio_dev_attr **attrs; 862 + 865 863 if (!hw->iio_devs[i]) 866 864 continue; 867 865 866 + /* 867 + * For the accelerometer, allow setting FIFO sampling frequency 868 + * values different from the sensor sampling frequency, which 869 + * may be needed to keep FIFO data rate low while sampling 870 + * acceleration data at high rates for accurate event detection. 871 + */ 872 + attrs = i == ST_LSM6DSX_ID_ACC ? st_lsm6dsx_buffer_attrs : NULL; 868 873 ret = devm_iio_kfifo_buffer_setup_ext(hw->dev, hw->iio_devs[i], 869 874 &st_lsm6dsx_buffer_ops, 870 - st_lsm6dsx_buffer_attrs); 875 + attrs); 871 876 if (ret) 872 877 return ret; 873 878 }
+1 -1
drivers/iio/orientation/hid-sensor-rotation.c
··· 19 19 struct hid_sensor_common common_attributes; 20 20 struct hid_sensor_hub_attribute_info quaternion; 21 21 struct { 22 - s32 sampled_vals[4]; 22 + IIO_DECLARE_QUATERNION(s32, sampled_vals); 23 23 aligned_s64 timestamp; 24 24 } scan; 25 25 int scale_pre_decml;
+1 -1
drivers/iio/pressure/abp2030pa.c
··· 520 520 data->p_offset = div_s64(odelta * data->pmin, pdelta) - data->outmin; 521 521 522 522 if (data->irq > 0) { 523 - ret = devm_request_irq(dev, irq, abp2_eoc_handler, IRQF_ONESHOT, 523 + ret = devm_request_irq(dev, irq, abp2_eoc_handler, 0, 524 524 dev_name(dev), data); 525 525 if (ret) 526 526 return ret;
+12
include/linux/iio/iio.h
··· 931 931 #define IIO_DECLARE_DMA_BUFFER_WITH_TS(type, name, count) \ 932 932 __IIO_DECLARE_BUFFER_WITH_TS(type, name, count) __aligned(IIO_DMA_MINALIGN) 933 933 934 + /** 935 + * IIO_DECLARE_QUATERNION() - Declare a quaternion element 936 + * @type: element type of the individual vectors 937 + * @name: identifier name 938 + * 939 + * Quaternions are a vector composed of 4 elements (W, X, Y, Z). Use this macro 940 + * to declare a quaternion element in a struct to ensure proper alignment in 941 + * an IIO buffer. 942 + */ 943 + #define IIO_DECLARE_QUATERNION(type, name) \ 944 + type name[4] __aligned(sizeof(type) * 4) 945 + 934 946 struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv); 935 947 936 948 /* The information at the returned address is guaranteed to be cacheline aligned */