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

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

Jonathan writes:

Second set of IIO fixes for the 4.2 cycle. Note these depend (mostly) on
material in the recent merge window, hence their separation from set (a)
as the fixes-togreg branch predated the merge window. I am running rather
later with these than I would have liked hence the large set.

* stk3310 fixes from Hartmut's review that came in post merge
- fix direction of proximity inline with recent documentation
clarification.
- fix missing REGMAP_I2C dependency
- rework the error handling for raw readings to fix an failure to power
down in the event of a raw reading failing.
- fix a bug in the compensation code which was toggling an extra bit in the
register.
* mmc35240 - reported samplign frequencies were wrong.
* ltr501 fixes
- fix a case of returning the return value of a regmap_read instead of
the value read.
- fix missing regmap dependency
* sx9500 - fix missing default values for ret in a couple of places to handle
the case of no enabled channels.
* tmp006 - check that writes to info_mask elements are actually to writable
ones. Otherwise, writing to any of them will change the sampling frequency.

+59 -64
+2
drivers/iio/light/Kconfig
··· 188 188 config LTR501 189 189 tristate "LTR-501ALS-01 light sensor" 190 190 depends on I2C 191 + select REGMAP_I2C 191 192 select IIO_BUFFER 192 193 select IIO_TRIGGERED_BUFFER 193 194 help ··· 202 201 config STK3310 203 202 tristate "STK3310 ALS and proximity sensor" 204 203 depends on I2C 204 + select REGMAP_I2C 205 205 help 206 206 Say yes here to get support for the Sensortek STK3310 ambient light 207 207 and proximity sensor. The STK3311 model is also supported by this
+1 -1
drivers/iio/light/ltr501.c
··· 1302 1302 if (ret < 0) 1303 1303 return ret; 1304 1304 1305 - data->als_contr = ret | data->chip_info->als_mode_active; 1305 + data->als_contr = status | data->chip_info->als_mode_active; 1306 1306 1307 1307 ret = regmap_read(data->regmap, LTR501_PS_CONTR, &status); 1308 1308 if (ret < 0)
+17 -36
drivers/iio/light/stk3310.c
··· 43 43 #define STK3311_CHIP_ID_VAL 0x1D 44 44 #define STK3310_PSINT_EN 0x01 45 45 #define STK3310_PS_MAX_VAL 0xFFFF 46 - #define STK3310_THRESH_MAX 0xFFFF 47 46 48 47 #define STK3310_DRIVER_NAME "stk3310" 49 48 #define STK3310_REGMAP_NAME "stk3310_regmap" ··· 83 84 REG_FIELD(STK3310_REG_FLAG, 4, 4); 84 85 static const struct reg_field stk3310_reg_field_flag_nf = 85 86 REG_FIELD(STK3310_REG_FLAG, 0, 0); 86 - /* 87 - * Maximum PS values with regard to scale. Used to export the 'inverse' 88 - * PS value (high values for far objects, low values for near objects). 89 - */ 87 + 88 + /* Estimate maximum proximity values with regard to measurement scale. */ 90 89 static const int stk3310_ps_max[4] = { 91 - STK3310_PS_MAX_VAL / 64, 92 - STK3310_PS_MAX_VAL / 16, 93 - STK3310_PS_MAX_VAL / 4, 94 - STK3310_PS_MAX_VAL, 90 + STK3310_PS_MAX_VAL / 640, 91 + STK3310_PS_MAX_VAL / 160, 92 + STK3310_PS_MAX_VAL / 40, 93 + STK3310_PS_MAX_VAL / 10 95 94 }; 96 95 97 96 static const int stk3310_scale_table[][2] = { ··· 125 128 /* Proximity event */ 126 129 { 127 130 .type = IIO_EV_TYPE_THRESH, 128 - .dir = IIO_EV_DIR_FALLING, 131 + .dir = IIO_EV_DIR_RISING, 129 132 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 130 133 BIT(IIO_EV_INFO_ENABLE), 131 134 }, 132 135 /* Out-of-proximity event */ 133 136 { 134 137 .type = IIO_EV_TYPE_THRESH, 135 - .dir = IIO_EV_DIR_RISING, 138 + .dir = IIO_EV_DIR_FALLING, 136 139 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 137 140 BIT(IIO_EV_INFO_ENABLE), 138 141 }, ··· 202 205 u8 reg; 203 206 u16 buf; 204 207 int ret; 205 - unsigned int index; 206 208 struct stk3310_data *data = iio_priv(indio_dev); 207 209 208 210 if (info != IIO_EV_INFO_VALUE) 209 211 return -EINVAL; 210 212 211 - /* 212 - * Only proximity interrupts are implemented at the moment. 213 - * Since we're inverting proximity values, the sensor's 'high' 214 - * threshold will become our 'low' threshold, associated with 215 - * 'near' events. Similarly, the sensor's 'low' threshold will 216 - * be our 'high' threshold, associated with 'far' events. 217 - */ 213 + /* Only proximity interrupts are implemented at the moment. */ 218 214 if (dir == IIO_EV_DIR_RISING) 219 - reg = STK3310_REG_THDL_PS; 220 - else if (dir == IIO_EV_DIR_FALLING) 221 215 reg = STK3310_REG_THDH_PS; 216 + else if (dir == IIO_EV_DIR_FALLING) 217 + reg = STK3310_REG_THDL_PS; 222 218 else 223 219 return -EINVAL; 224 220 ··· 222 232 dev_err(&data->client->dev, "register read failed\n"); 223 233 return ret; 224 234 } 225 - regmap_field_read(data->reg_ps_gain, &index); 226 - *val = swab16(stk3310_ps_max[index] - buf); 235 + *val = swab16(buf); 227 236 228 237 return IIO_VAL_INT; 229 238 } ··· 246 257 return -EINVAL; 247 258 248 259 if (dir == IIO_EV_DIR_RISING) 249 - reg = STK3310_REG_THDL_PS; 250 - else if (dir == IIO_EV_DIR_FALLING) 251 260 reg = STK3310_REG_THDH_PS; 261 + else if (dir == IIO_EV_DIR_FALLING) 262 + reg = STK3310_REG_THDL_PS; 252 263 else 253 264 return -EINVAL; 254 265 255 - buf = swab16(stk3310_ps_max[index] - val); 266 + buf = swab16(val); 256 267 ret = regmap_bulk_write(data->regmap, reg, &buf, 2); 257 268 if (ret < 0) 258 269 dev_err(&client->dev, "failed to set PS threshold!\n"); ··· 323 334 return ret; 324 335 } 325 336 *val = swab16(buf); 326 - if (chan->type == IIO_PROXIMITY) { 327 - /* 328 - * Invert the proximity data so we return low values 329 - * for close objects and high values for far ones. 330 - */ 331 - regmap_field_read(data->reg_ps_gain, &index); 332 - *val = stk3310_ps_max[index] - *val; 333 - } 334 337 mutex_unlock(&data->lock); 335 338 return IIO_VAL_INT; 336 339 case IIO_CHAN_INFO_INT_TIME: ··· 562 581 } 563 582 event = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1, 564 583 IIO_EV_TYPE_THRESH, 565 - (dir ? IIO_EV_DIR_RISING : 566 - IIO_EV_DIR_FALLING)); 584 + (dir ? IIO_EV_DIR_FALLING : 585 + IIO_EV_DIR_RISING)); 567 586 iio_push_event(indio_dev, event, data->timestamp); 568 587 569 588 /* Reset the interrupt flag */
+21 -14
drivers/iio/magnetometer/mmc35240.c
··· 84 84 #define MMC35240_OTP_START_ADDR 0x1B 85 85 86 86 enum mmc35240_resolution { 87 - MMC35240_16_BITS_SLOW = 0, /* 100 Hz */ 88 - MMC35240_16_BITS_FAST, /* 200 Hz */ 89 - MMC35240_14_BITS, /* 333 Hz */ 90 - MMC35240_12_BITS, /* 666 Hz */ 87 + MMC35240_16_BITS_SLOW = 0, /* 7.92 ms */ 88 + MMC35240_16_BITS_FAST, /* 4.08 ms */ 89 + MMC35240_14_BITS, /* 2.16 ms */ 90 + MMC35240_12_BITS, /* 1.20 ms */ 91 91 }; 92 92 93 93 enum mmc35240_axis { ··· 100 100 int sens[3]; /* sensitivity per X, Y, Z axis */ 101 101 int nfo; /* null field output */ 102 102 } mmc35240_props_table[] = { 103 - /* 16 bits, 100Hz ODR */ 103 + /* 16 bits, 125Hz ODR */ 104 104 { 105 105 {1024, 1024, 1024}, 106 106 32768, 107 107 }, 108 - /* 16 bits, 200Hz ODR */ 108 + /* 16 bits, 250Hz ODR */ 109 109 { 110 110 {1024, 1024, 770}, 111 111 32768, 112 112 }, 113 - /* 14 bits, 333Hz ODR */ 113 + /* 14 bits, 450Hz ODR */ 114 114 { 115 115 {256, 256, 193}, 116 116 8192, 117 117 }, 118 - /* 12 bits, 666Hz ODR */ 118 + /* 12 bits, 800Hz ODR */ 119 119 { 120 120 {64, 64, 48}, 121 121 2048, ··· 133 133 int axis_scale[3]; 134 134 }; 135 135 136 - static const int mmc35240_samp_freq[] = {100, 200, 333, 666}; 136 + static const struct { 137 + int val; 138 + int val2; 139 + } mmc35240_samp_freq[] = { {1, 500000}, 140 + {13, 0}, 141 + {25, 0}, 142 + {50, 0} }; 137 143 138 - static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("100 200 333 666"); 144 + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("1.5 13 25 50"); 139 145 140 146 #define MMC35240_CHANNEL(_axis) { \ 141 147 .type = IIO_MAGN, \ ··· 174 168 int i; 175 169 176 170 for (i = 0; i < ARRAY_SIZE(mmc35240_samp_freq); i++) 177 - if (mmc35240_samp_freq[i] == val) 171 + if (mmc35240_samp_freq[i].val == val && 172 + mmc35240_samp_freq[i].val2 == val2) 178 173 return i; 179 174 return -EINVAL; 180 175 } ··· 385 378 if (i < 0 || i >= ARRAY_SIZE(mmc35240_samp_freq)) 386 379 return -EINVAL; 387 380 388 - *val = mmc35240_samp_freq[i]; 389 - *val2 = 0; 390 - return IIO_VAL_INT; 381 + *val = mmc35240_samp_freq[i].val; 382 + *val2 = mmc35240_samp_freq[i].val2; 383 + return IIO_VAL_INT_PLUS_MICRO; 391 384 default: 392 385 return -EINVAL; 393 386 }
+15 -13
drivers/iio/proximity/sx9500.c
··· 80 80 #define SX9500_COMPSTAT_MASK GENMASK(3, 0) 81 81 82 82 #define SX9500_NUM_CHANNELS 4 83 + #define SX9500_CHAN_MASK GENMASK(SX9500_NUM_CHANNELS - 1, 0) 83 84 84 85 struct sx9500_data { 85 86 struct mutex mutex; ··· 330 329 else 331 330 ret = sx9500_wait_for_sample(data); 332 331 333 - if (ret < 0) 334 - return ret; 335 - 336 332 mutex_lock(&data->mutex); 333 + 334 + if (ret < 0) 335 + goto out_dec_data_rdy; 337 336 338 337 ret = sx9500_read_prox_data(data, chan, val); 339 338 if (ret < 0) 340 - goto out; 341 - 342 - ret = sx9500_dec_chan_users(data, chan->channel); 343 - if (ret < 0) 344 - goto out; 339 + goto out_dec_data_rdy; 345 340 346 341 ret = sx9500_dec_data_rdy_users(data); 342 + if (ret < 0) 343 + goto out_dec_chan; 344 + 345 + ret = sx9500_dec_chan_users(data, chan->channel); 347 346 if (ret < 0) 348 347 goto out; 349 348 ··· 351 350 352 351 goto out; 353 352 353 + out_dec_data_rdy: 354 + sx9500_dec_data_rdy_users(data); 354 355 out_dec_chan: 355 356 sx9500_dec_chan_users(data, chan->channel); 356 357 out: ··· 682 679 static int sx9500_buffer_preenable(struct iio_dev *indio_dev) 683 680 { 684 681 struct sx9500_data *data = iio_priv(indio_dev); 685 - int ret, i; 682 + int ret = 0, i; 686 683 687 684 mutex_lock(&data->mutex); 688 685 ··· 706 703 static int sx9500_buffer_predisable(struct iio_dev *indio_dev) 707 704 { 708 705 struct sx9500_data *data = iio_priv(indio_dev); 709 - int ret, i; 706 + int ret = 0, i; 710 707 711 708 iio_triggered_buffer_predisable(indio_dev); 712 709 ··· 803 800 unsigned int val; 804 801 805 802 ret = regmap_update_bits(data->regmap, SX9500_REG_PROX_CTRL0, 806 - GENMASK(SX9500_NUM_CHANNELS, 0), 807 - GENMASK(SX9500_NUM_CHANNELS, 0)); 803 + SX9500_CHAN_MASK, SX9500_CHAN_MASK); 808 804 if (ret < 0) 809 805 return ret; 810 806 ··· 823 821 824 822 out: 825 823 regmap_update_bits(data->regmap, SX9500_REG_PROX_CTRL0, 826 - GENMASK(SX9500_NUM_CHANNELS, 0), 0); 824 + SX9500_CHAN_MASK, 0); 827 825 return ret; 828 826 } 829 827
+3
drivers/iio/temperature/tmp006.c
··· 132 132 struct tmp006_data *data = iio_priv(indio_dev); 133 133 int i; 134 134 135 + if (mask != IIO_CHAN_INFO_SAMP_FREQ) 136 + return -EINVAL; 137 + 135 138 for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) 136 139 if ((val == tmp006_freqs[i][0]) && 137 140 (val2 == tmp006_freqs[i][1])) {