Skip to content

Commit b2e3120

Browse files
committed
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.
2 parents ec14121 + f790923 commit b2e3120

File tree

13 files changed

+87
-26
lines changed

13 files changed

+87
-26
lines changed

drivers/iio/adc/ad7793.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
257257
unsigned int vref_mv)
258258
{
259259
struct ad7793_state *st = iio_priv(indio_dev);
260-
int i, ret = -1;
260+
int i, ret;
261261
unsigned long long scale_uv;
262262
u32 id;
263263

@@ -266,7 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
266266
return ret;
267267

268268
/* reset the serial interface */
269-
ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret));
269+
ret = ad_sd_reset(&st->sd, 32);
270270
if (ret < 0)
271271
goto out;
272272
usleep_range(500, 2000); /* Wait for at least 500us */

drivers/iio/adc/ad_sigma_delta.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
177177
}
178178
EXPORT_SYMBOL_GPL(ad_sd_read_reg);
179179

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+
180208
static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
181209
unsigned int mode, unsigned int channel)
182210
{

drivers/iio/adc/mcp320x.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* MCP3204
1818
* MCP3208
1919
* ------------
20+
* 13 bit converter
21+
* MCP3301
2022
*
2123
* Datasheet can be found here:
2224
* http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001
@@ -96,7 +98,7 @@ static int mcp320x_channel_to_tx_data(int device_index,
9698
}
9799

98100
static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
99-
bool differential, int device_index)
101+
bool differential, int device_index, int *val)
100102
{
101103
int ret;
102104

@@ -117,19 +119,25 @@ static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
117119

118120
switch (device_index) {
119121
case mcp3001:
120-
return (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3);
122+
*val = (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3);
123+
return 0;
121124
case mcp3002:
122125
case mcp3004:
123126
case mcp3008:
124-
return (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6);
127+
*val = (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6);
128+
return 0;
125129
case mcp3201:
126-
return (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1);
130+
*val = (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1);
131+
return 0;
127132
case mcp3202:
128133
case mcp3204:
129134
case mcp3208:
130-
return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
135+
*val = (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
136+
return 0;
131137
case mcp3301:
132-
return sign_extend32((adc->rx_buf[0] & 0x1f) << 8 | adc->rx_buf[1], 12);
138+
*val = sign_extend32((adc->rx_buf[0] & 0x1f) << 8
139+
| adc->rx_buf[1], 12);
140+
return 0;
133141
default:
134142
return -EINVAL;
135143
}
@@ -150,12 +158,10 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev,
150158
switch (mask) {
151159
case IIO_CHAN_INFO_RAW:
152160
ret = mcp320x_adc_conversion(adc, channel->address,
153-
channel->differential, device_index);
154-
161+
channel->differential, device_index, val);
155162
if (ret < 0)
156163
goto out;
157164

158-
*val = ret;
159165
ret = IIO_VAL_INT;
160166
break;
161167

@@ -312,6 +318,7 @@ static int mcp320x_probe(struct spi_device *spi)
312318
indio_dev->name = spi_get_device_id(spi)->name;
313319
indio_dev->modes = INDIO_DIRECT_MODE;
314320
indio_dev->info = &mcp320x_info;
321+
spi_set_drvdata(spi, indio_dev);
315322

316323
chip_info = &mcp320x_chip_infos[spi_get_device_id(spi)->driver_data];
317324
indio_dev->channels = chip_info->channels;

drivers/iio/adc/stm32-adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
16661666

16671667
num_channels = of_property_count_u32_elems(node, "st,adc-channels");
16681668
if (num_channels < 0 ||
1669-
num_channels >= adc_info->max_channels) {
1669+
num_channels > adc_info->max_channels) {
16701670
dev_err(&indio_dev->dev, "Bad st,adc-channels?\n");
16711671
return num_channels < 0 ? num_channels : -EINVAL;
16721672
}

drivers/iio/adc/ti-ads1015.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
#define ADS1015_CFG_COMP_QUE_MASK GENMASK(1, 0)
5454
#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)
5656
#define ADS1015_CFG_COMP_MODE_MASK BIT(4)
5757
#define ADS1015_CFG_DR_MASK GENMASK(7, 5)
5858
#define ADS1015_CFG_MOD_MASK BIT(8)
@@ -1017,10 +1017,12 @@ static int ads1015_probe(struct i2c_client *client,
10171017

10181018
switch (irq_trig) {
10191019
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;
10211022
break;
10221023
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;
10241026
break;
10251027
default:
10261028
return -EINVAL;

drivers/iio/adc/twl4030-madc.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,21 +887,27 @@ static int twl4030_madc_probe(struct platform_device *pdev)
887887

888888
/* Enable 3v1 bias regulator for MADC[3:6] */
889889
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+
}
892894

893895
ret = regulator_enable(madc->usb3v1);
894-
if (ret)
896+
if (ret) {
895897
dev_err(madc->dev, "could not enable 3v1 bias regulator\n");
898+
goto err_i2c;
899+
}
896900

897901
ret = iio_device_register(iio_dev);
898902
if (ret) {
899903
dev_err(&pdev->dev, "could not register iio device\n");
900-
goto err_i2c;
904+
goto err_usb3v1;
901905
}
902906

903907
return 0;
904908

909+
err_usb3v1:
910+
regulator_disable(madc->usb3v1);
905911
err_i2c:
906912
twl4030_madc_set_current_generator(madc, 0, 0);
907913
err_current_generator:

drivers/iio/common/st_sensors/st_sensors_core.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,17 @@ int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
463463
u8 drdy_mask;
464464
struct st_sensor_data *sdata = iio_priv(indio_dev);
465465

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;
467475
return 0;
476+
}
468477

469478
/* Enable/Disable the interrupt generator 1. */
470479
if (sdata->sensor_settings->drdy_irq.ig1.en_addr > 0) {

drivers/iio/industrialio-core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,10 @@ static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
310310
ret = indio_dev->info->debugfs_reg_access(indio_dev,
311311
indio_dev->cached_reg_addr,
312312
0, &val);
313-
if (ret)
313+
if (ret) {
314314
dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
315+
return ret;
316+
}
315317

316318
len = snprintf(buf, sizeof(buf), "0x%X\n", val);
317319

drivers/iio/magnetometer/st_magn_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
315315
},
316316
},
317317
},
318+
.drdy_irq = {
319+
/* drdy line is routed drdy pin */
320+
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
321+
},
318322
.multi_read_bit = true,
319323
.bootime = 2,
320324
},

drivers/iio/pressure/bmp280-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int bmp280_chip_config(struct bmp280_data *data)
573573
u8 osrs = BMP280_OSRS_TEMP_X(data->oversampling_temp + 1) |
574574
BMP280_OSRS_PRESS_X(data->oversampling_press + 1);
575575

576-
ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_MEAS,
576+
ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS,
577577
BMP280_OSRS_TEMP_MASK |
578578
BMP280_OSRS_PRESS_MASK |
579579
BMP280_MODE_MASK,

drivers/iio/trigger/stm32-timer-trigger.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static void stm32_timer_stop(struct stm32_timer_trigger *priv)
174174
clk_disable(priv->clk);
175175

176176
/* Stop timer */
177+
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0);
177178
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
178179
regmap_write(priv->regmap, TIM_PSC, 0);
179180
regmap_write(priv->regmap, TIM_ARR, 0);
@@ -715,8 +716,9 @@ static ssize_t stm32_count_set_preset(struct iio_dev *indio_dev,
715716
if (ret)
716717
return ret;
717718

719+
/* TIMx_ARR register shouldn't be buffered (ARPE=0) */
720+
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0);
718721
regmap_write(priv->regmap, TIM_ARR, preset);
719-
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
720722

721723
return len;
722724
}

drivers/staging/iio/adc/ad7192.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,9 @@ static int ad7192_setup(struct ad7192_state *st,
223223
struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi);
224224
unsigned long long scale_uv;
225225
int i, ret, id;
226-
u8 ones[6];
227226

228227
/* 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);
231229
if (ret < 0)
232230
goto out;
233231
usleep_range(500, 1000); /* Wait for at least 500us */

include/linux/iio/adc/ad_sigma_delta.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
111111
int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
112112
unsigned int size, unsigned int *val);
113113

114+
int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
115+
unsigned int reset_length);
116+
114117
int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
115118
const struct iio_chan_spec *chan, int *val);
116119
int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,

0 commit comments

Comments
 (0)