Merge tag 'iio-fixes-for-4.14a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus

Jonathan writes:

First round of IIO fixes for the 4.14 cycle

Note this includes fixes from recent merge window. As such the tree
is based on top of a prior staging/staging-next tree.

* iio core
- return and error for a failed read_reg debugfs call rather than
eating the error.
* ad7192
- Use the dedicated reset function in the ad_sigma_delta library
instead of an spi transfer with the data on the stack which
could cause problems with DMA.
* ad7793
- Implement a dedicate reset function in the ad_sigma_delta library
and use it to correctly reset this part.
* bme280
- ctrl_reg write must occur after any register writes
for updates to take effect.
* mcp320x
- negative voltage readout was broken.
- Fix an oops on module unload due to spi_set_drvdata not being called
in probe.
* st_magn
- Fix the data ready line configuration for the lis3mdl. It is not
configurable so the st_magn core was assuming it didn't exist
and so wasn't consuming interrupts resulting in an unhandled
interrupt.
* stm32-adc
- off by one error on max channels checking.
* stm32-timer
- preset should not be buffered - reorganising register writes avoids
this.
- fix a corner case in which write preset goes wrong when a timer is
used first as a trigger then as a counter with preset. Odd case but
you never know.
* ti-ads1015
- Fix setting of comparator polarity by fixing bitfield definition.
* twl4030
- Error path handling fix to cleanup in event of regulator
registration failure.
- Disable the vusb3v1 regulator correctly in error handling
- Don't paper over a regulator enable failure.

+87 -26
+2 -2
drivers/iio/adc/ad7793.c
··· 257 257 unsigned int vref_mv) 258 258 { 259 259 struct ad7793_state *st = iio_priv(indio_dev); 260 - int i, ret = -1; 260 + int i, ret; 261 261 unsigned long long scale_uv; 262 262 u32 id; 263 263 ··· 266 266 return ret; 267 267 268 268 /* reset the serial interface */ 269 - ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret)); 269 + ret = ad_sd_reset(&st->sd, 32); 270 270 if (ret < 0) 271 271 goto out; 272 272 usleep_range(500, 2000); /* Wait for at least 500us */
+28
drivers/iio/adc/ad_sigma_delta.c
··· 177 177 } 178 178 EXPORT_SYMBOL_GPL(ad_sd_read_reg); 179 179 180 + /** 181 + * ad_sd_reset() - Reset the serial interface 182 + * 183 + * @sigma_delta: The sigma delta device 184 + * @reset_length: Number of SCLKs with DIN = 1 185 + * 186 + * Returns 0 on success, an error code otherwise. 187 + **/ 188 + int ad_sd_reset(struct ad_sigma_delta *sigma_delta, 189 + unsigned int reset_length) 190 + { 191 + uint8_t *buf; 192 + unsigned int size; 193 + int ret; 194 + 195 + size = DIV_ROUND_UP(reset_length, 8); 196 + buf = kcalloc(size, sizeof(*buf), GFP_KERNEL); 197 + if (!buf) 198 + return -ENOMEM; 199 + 200 + memset(buf, 0xff, size); 201 + ret = spi_write(sigma_delta->spi, buf, size); 202 + kfree(buf); 203 + 204 + return ret; 205 + } 206 + EXPORT_SYMBOL_GPL(ad_sd_reset); 207 + 180 208 static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta, 181 209 unsigned int mode, unsigned int channel) 182 210 {
+16 -9
drivers/iio/adc/mcp320x.c
··· 17 17 * MCP3204 18 18 * MCP3208 19 19 * ------------ 20 + * 13 bit converter 21 + * MCP3301 20 22 * 21 23 * Datasheet can be found here: 22 24 * http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001 ··· 98 96 } 99 97 100 98 static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel, 101 - bool differential, int device_index) 99 + bool differential, int device_index, int *val) 102 100 { 103 101 int ret; 104 102 ··· 119 117 120 118 switch (device_index) { 121 119 case mcp3001: 122 - return (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3); 120 + *val = (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3); 121 + return 0; 123 122 case mcp3002: 124 123 case mcp3004: 125 124 case mcp3008: 126 - return (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6); 125 + *val = (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6); 126 + return 0; 127 127 case mcp3201: 128 - return (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1); 128 + *val = (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1); 129 + return 0; 129 130 case mcp3202: 130 131 case mcp3204: 131 132 case mcp3208: 132 - return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4); 133 + *val = (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4); 134 + return 0; 133 135 case mcp3301: 134 - return sign_extend32((adc->rx_buf[0] & 0x1f) << 8 | adc->rx_buf[1], 12); 136 + *val = sign_extend32((adc->rx_buf[0] & 0x1f) << 8 137 + | adc->rx_buf[1], 12); 138 + return 0; 135 139 default: 136 140 return -EINVAL; 137 141 } ··· 158 150 switch (mask) { 159 151 case IIO_CHAN_INFO_RAW: 160 152 ret = mcp320x_adc_conversion(adc, channel->address, 161 - channel->differential, device_index); 162 - 153 + channel->differential, device_index, val); 163 154 if (ret < 0) 164 155 goto out; 165 156 166 - *val = ret; 167 157 ret = IIO_VAL_INT; 168 158 break; 169 159 ··· 318 312 indio_dev->name = spi_get_device_id(spi)->name; 319 313 indio_dev->modes = INDIO_DIRECT_MODE; 320 314 indio_dev->info = &mcp320x_info; 315 + spi_set_drvdata(spi, indio_dev); 321 316 322 317 chip_info = &mcp320x_chip_infos[spi_get_device_id(spi)->driver_data]; 323 318 indio_dev->channels = chip_info->channels;
+1 -1
drivers/iio/adc/stm32-adc.c
··· 1666 1666 1667 1667 num_channels = of_property_count_u32_elems(node, "st,adc-channels"); 1668 1668 if (num_channels < 0 || 1669 - num_channels >= adc_info->max_channels) { 1669 + num_channels > adc_info->max_channels) { 1670 1670 dev_err(&indio_dev->dev, "Bad st,adc-channels?\n"); 1671 1671 return num_channels < 0 ? num_channels : -EINVAL; 1672 1672 }
+5 -3
drivers/iio/adc/ti-ads1015.c
··· 52 52 53 53 #define ADS1015_CFG_COMP_QUE_MASK GENMASK(1, 0) 54 54 #define ADS1015_CFG_COMP_LAT_MASK BIT(2) 55 - #define ADS1015_CFG_COMP_POL_MASK BIT(2) 55 + #define ADS1015_CFG_COMP_POL_MASK BIT(3) 56 56 #define ADS1015_CFG_COMP_MODE_MASK BIT(4) 57 57 #define ADS1015_CFG_DR_MASK GENMASK(7, 5) 58 58 #define ADS1015_CFG_MOD_MASK BIT(8) ··· 1017 1017 1018 1018 switch (irq_trig) { 1019 1019 case IRQF_TRIGGER_LOW: 1020 - cfg_comp |= ADS1015_CFG_COMP_POL_LOW; 1020 + cfg_comp |= ADS1015_CFG_COMP_POL_LOW << 1021 + ADS1015_CFG_COMP_POL_SHIFT; 1021 1022 break; 1022 1023 case IRQF_TRIGGER_HIGH: 1023 - cfg_comp |= ADS1015_CFG_COMP_POL_HIGH; 1024 + cfg_comp |= ADS1015_CFG_COMP_POL_HIGH << 1025 + ADS1015_CFG_COMP_POL_SHIFT; 1024 1026 break; 1025 1027 default: 1026 1028 return -EINVAL;
+10 -4
drivers/iio/adc/twl4030-madc.c
··· 887 887 888 888 /* Enable 3v1 bias regulator for MADC[3:6] */ 889 889 madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1"); 890 - if (IS_ERR(madc->usb3v1)) 891 - return -ENODEV; 890 + if (IS_ERR(madc->usb3v1)) { 891 + ret = -ENODEV; 892 + goto err_i2c; 893 + } 892 894 893 895 ret = regulator_enable(madc->usb3v1); 894 - if (ret) 896 + if (ret) { 895 897 dev_err(madc->dev, "could not enable 3v1 bias regulator\n"); 898 + goto err_i2c; 899 + } 896 900 897 901 ret = iio_device_register(iio_dev); 898 902 if (ret) { 899 903 dev_err(&pdev->dev, "could not register iio device\n"); 900 - goto err_i2c; 904 + goto err_usb3v1; 901 905 } 902 906 903 907 return 0; 904 908 909 + err_usb3v1: 910 + regulator_disable(madc->usb3v1); 905 911 err_i2c: 906 912 twl4030_madc_set_current_generator(madc, 0, 0); 907 913 err_current_generator:
+10 -1
drivers/iio/common/st_sensors/st_sensors_core.c
··· 463 463 u8 drdy_mask; 464 464 struct st_sensor_data *sdata = iio_priv(indio_dev); 465 465 466 - if (!sdata->sensor_settings->drdy_irq.addr) 466 + if (!sdata->sensor_settings->drdy_irq.addr) { 467 + /* 468 + * there are some devices (e.g. LIS3MDL) where drdy line is 469 + * routed to a given pin and it is not possible to select a 470 + * different one. Take into account irq status register 471 + * to understand if irq trigger can be properly supported 472 + */ 473 + if (sdata->sensor_settings->drdy_irq.addr_stat_drdy) 474 + sdata->hw_irq_trigger = enable; 467 475 return 0; 476 + } 468 477 469 478 /* Enable/Disable the interrupt generator 1. */ 470 479 if (sdata->sensor_settings->drdy_irq.ig1.en_addr > 0) {
+3 -1
drivers/iio/industrialio-core.c
··· 310 310 ret = indio_dev->info->debugfs_reg_access(indio_dev, 311 311 indio_dev->cached_reg_addr, 312 312 0, &val); 313 - if (ret) 313 + if (ret) { 314 314 dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__); 315 + return ret; 316 + } 315 317 316 318 len = snprintf(buf, sizeof(buf), "0x%X\n", val); 317 319
+4
drivers/iio/magnetometer/st_magn_core.c
··· 315 315 }, 316 316 }, 317 317 }, 318 + .drdy_irq = { 319 + /* drdy line is routed drdy pin */ 320 + .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 321 + }, 318 322 .multi_read_bit = true, 319 323 .bootime = 2, 320 324 },
+1 -1
drivers/iio/pressure/bmp280-core.c
··· 573 573 u8 osrs = BMP280_OSRS_TEMP_X(data->oversampling_temp + 1) | 574 574 BMP280_OSRS_PRESS_X(data->oversampling_press + 1); 575 575 576 - ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_MEAS, 576 + ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, 577 577 BMP280_OSRS_TEMP_MASK | 578 578 BMP280_OSRS_PRESS_MASK | 579 579 BMP280_MODE_MASK,
+3 -1
drivers/iio/trigger/stm32-timer-trigger.c
··· 174 174 clk_disable(priv->clk); 175 175 176 176 /* Stop timer */ 177 + regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0); 177 178 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0); 178 179 regmap_write(priv->regmap, TIM_PSC, 0); 179 180 regmap_write(priv->regmap, TIM_ARR, 0); ··· 716 715 if (ret) 717 716 return ret; 718 717 718 + /* TIMx_ARR register shouldn't be buffered (ARPE=0) */ 719 + regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0); 719 720 regmap_write(priv->regmap, TIM_ARR, preset); 720 - regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE); 721 721 722 722 return len; 723 723 }
+1 -3
drivers/staging/iio/adc/ad7192.c
··· 223 223 struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi); 224 224 unsigned long long scale_uv; 225 225 int i, ret, id; 226 - u8 ones[6]; 227 226 228 227 /* reset the serial interface */ 229 - memset(&ones, 0xFF, 6); 230 - ret = spi_write(st->sd.spi, &ones, 6); 228 + ret = ad_sd_reset(&st->sd, 48); 231 229 if (ret < 0) 232 230 goto out; 233 231 usleep_range(500, 1000); /* Wait for at least 500us */
+3
include/linux/iio/adc/ad_sigma_delta.h
··· 111 111 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg, 112 112 unsigned int size, unsigned int *val); 113 113 114 + int ad_sd_reset(struct ad_sigma_delta *sigma_delta, 115 + unsigned int reset_length); 116 + 114 117 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, 115 118 const struct iio_chan_spec *chan, int *val); 116 119 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,