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.

bu27034: ROHM BU27034NUC to BU27034ANUC drop data2

The ROHM BU27034NUC was cancelled and BU27034ANUC is replacing this
sensor. The BU27034ANUC does not have the data2 channel.

Drop the data2 channel.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://patch.msgid.link/6f261d4499e9c0e161279717261cc9a20764a6bd.1720176341.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
acfc80c7 dd77c0ff

+28 -104
+28 -104
drivers/iio/light/rohm-bu27034.c
··· 29 29 30 30 #define BU27034_REG_MODE_CONTROL2 0x42 31 31 #define BU27034_MASK_D01_GAIN GENMASK(7, 3) 32 - #define BU27034_MASK_D2_GAIN_HI GENMASK(7, 6) 33 - #define BU27034_MASK_D2_GAIN_LO GENMASK(2, 0) 34 32 35 33 #define BU27034_REG_MODE_CONTROL3 0x43 36 34 #define BU27034_REG_MODE_CONTROL4 0x44 37 35 #define BU27034_MASK_MEAS_EN BIT(0) 38 36 #define BU27034_MASK_VALID BIT(7) 37 + #define BU27034_NUM_HW_DATA_CHANS 2 39 38 #define BU27034_REG_DATA0_LO 0x50 40 39 #define BU27034_REG_DATA1_LO 0x52 41 - #define BU27034_REG_DATA2_LO 0x54 42 - #define BU27034_REG_DATA2_HI 0x55 40 + #define BU27034_REG_DATA1_HI 0x53 43 41 #define BU27034_REG_MANUFACTURER_ID 0x92 44 42 #define BU27034_REG_MAX BU27034_REG_MANUFACTURER_ID 45 43 ··· 85 87 BU27034_CHAN_ALS, 86 88 BU27034_CHAN_DATA0, 87 89 BU27034_CHAN_DATA1, 88 - BU27034_CHAN_DATA2, 89 90 BU27034_NUM_CHANS 90 91 }; 91 92 92 93 static const unsigned long bu27034_scan_masks[] = { 93 - GENMASK(BU27034_CHAN_DATA2, BU27034_CHAN_ALS), 0 94 + GENMASK(BU27034_CHAN_DATA1, BU27034_CHAN_DATA0), 95 + GENMASK(BU27034_CHAN_DATA1, BU27034_CHAN_ALS), 0 94 96 }; 95 97 96 98 /* ··· 153 155 GAIN_SCALE_ITIME_US(55000, BU27034_MEAS_MODE_55MS, 1), 154 156 }; 155 157 156 - #define BU27034_CHAN_DATA(_name, _ch2) \ 158 + #define BU27034_CHAN_DATA(_name) \ 157 159 { \ 158 160 .type = IIO_INTENSITY, \ 159 161 .channel = BU27034_CHAN_##_name, \ 160 - .channel2 = (_ch2), \ 161 162 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 162 163 BIT(IIO_CHAN_INFO_SCALE), \ 163 164 .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE), \ ··· 191 194 /* 192 195 * The BU27034 DATA0 and DATA1 channels are both on the visible light 193 196 * area (mostly). The data0 sensitivity peaks at 500nm, DATA1 at 600nm. 194 - * These wave lengths are pretty much on the border of colours making 195 - * these a poor candidates for R/G/B standardization. Hence they're both 196 - * marked as clear channels 197 + * These wave lengths are cyan(ish) and orange(ish), making these 198 + * sub-optiomal candidates for R/G/B standardization. Hence the 199 + * colour modifier is omitted. 197 200 */ 198 - BU27034_CHAN_DATA(DATA0, IIO_MOD_LIGHT_CLEAR), 199 - BU27034_CHAN_DATA(DATA1, IIO_MOD_LIGHT_CLEAR), 200 - BU27034_CHAN_DATA(DATA2, IIO_MOD_LIGHT_IR), 201 + BU27034_CHAN_DATA(DATA0), 202 + BU27034_CHAN_DATA(DATA1), 201 203 IIO_CHAN_SOFT_TIMESTAMP(4), 202 204 }; 203 205 ··· 210 214 struct mutex mutex; 211 215 struct iio_gts gts; 212 216 struct task_struct *task; 213 - __le16 raw[3]; 217 + __le16 raw[BU27034_NUM_HW_DATA_CHANS]; 214 218 struct { 215 219 u32 mlux; 216 - __le16 channels[3]; 220 + __le16 channels[BU27034_NUM_HW_DATA_CHANS]; 217 221 s64 ts __aligned(8); 218 222 } scan; 219 223 }; ··· 227 231 .range_max = BU27034_REG_MODE_CONTROL4, 228 232 }, { 229 233 .range_min = BU27034_REG_DATA0_LO, 230 - .range_max = BU27034_REG_DATA2_HI, 234 + .range_max = BU27034_REG_DATA1_HI, 231 235 }, 232 236 }; 233 237 ··· 239 243 static const struct regmap_range bu27034_read_only_ranges[] = { 240 244 { 241 245 .range_min = BU27034_REG_DATA0_LO, 242 - .range_max = BU27034_REG_DATA2_HI, 246 + .range_max = BU27034_REG_DATA1_HI, 243 247 }, { 244 248 .range_min = BU27034_REG_MANUFACTURER_ID, 245 249 .range_max = BU27034_REG_MANUFACTURER_ID, ··· 268 272 269 273 static int bu27034_get_gain_sel(struct bu27034_data *data, int chan) 270 274 { 275 + int reg[] = { 276 + [BU27034_CHAN_DATA0] = BU27034_REG_MODE_CONTROL2, 277 + [BU27034_CHAN_DATA1] = BU27034_REG_MODE_CONTROL3, 278 + }; 271 279 int ret, val; 272 280 273 - switch (chan) { 274 - case BU27034_CHAN_DATA0: 275 - case BU27034_CHAN_DATA1: 276 - { 277 - int reg[] = { 278 - [BU27034_CHAN_DATA0] = BU27034_REG_MODE_CONTROL2, 279 - [BU27034_CHAN_DATA1] = BU27034_REG_MODE_CONTROL3, 280 - }; 281 - ret = regmap_read(data->regmap, reg[chan], &val); 282 - if (ret) 283 - return ret; 281 + ret = regmap_read(data->regmap, reg[chan], &val); 282 + if (ret) 283 + return ret; 284 284 285 - return FIELD_GET(BU27034_MASK_D01_GAIN, val); 286 - } 287 - case BU27034_CHAN_DATA2: 288 - { 289 - int d2_lo_bits = fls(BU27034_MASK_D2_GAIN_LO); 290 - 291 - ret = regmap_read(data->regmap, BU27034_REG_MODE_CONTROL2, &val); 292 - if (ret) 293 - return ret; 294 - 295 - /* 296 - * The data2 channel gain is composed by 5 non continuous bits 297 - * [7:6], [2:0]. Thus when we combine the 5-bit 'selector' 298 - * from register value we must right shift the high bits by 3. 299 - */ 300 - return FIELD_GET(BU27034_MASK_D2_GAIN_HI, val) << d2_lo_bits | 301 - FIELD_GET(BU27034_MASK_D2_GAIN_LO, val); 302 - } 303 - default: 304 - return -EINVAL; 305 - } 285 + return FIELD_GET(BU27034_MASK_D01_GAIN, val); 306 286 } 307 287 308 288 static int bu27034_get_gain(struct bu27034_data *data, int chan, int *gain) ··· 361 389 }; 362 390 int mask, val; 363 391 364 - if (chan != BU27034_CHAN_DATA0 && chan != BU27034_CHAN_DATA1) 365 - return -EINVAL; 366 - 367 392 val = FIELD_PREP(BU27034_MASK_D01_GAIN, sel); 368 - 369 393 mask = BU27034_MASK_D01_GAIN; 370 - 371 - if (chan == BU27034_CHAN_DATA0) { 372 - /* 373 - * We keep the same gain for channel 2 as we set for channel 0 374 - * We can't allow them to be individually controlled because 375 - * setting one will impact also the other. Also, if we don't 376 - * always update both gains we may result unsupported bit 377 - * combinations. 378 - * 379 - * This is not nice but this is yet another place where the 380 - * user space must be prepared to surprizes. Namely, see chan 2 381 - * gain changed when chan 0 gain is changed. 382 - * 383 - * This is not fatal for most users though. I don't expect the 384 - * channel 2 to be used in any generic cases - the intensity 385 - * values provided by the sensor for IR area are not openly 386 - * documented. Also, channel 2 is not used for visible light. 387 - * 388 - * So, if there is application which is written to utilize the 389 - * channel 2 - then it is probably specifically targeted to this 390 - * sensor and knows how to utilize those values. It is safe to 391 - * hope such user can also cope with the gain changes. 392 - */ 393 - mask |= BU27034_MASK_D2_GAIN_LO; 394 - 395 - /* 396 - * The D2 gain bits are directly the lowest bits of selector. 397 - * Just do add those bits to the value 398 - */ 399 - val |= sel & BU27034_MASK_D2_GAIN_LO; 400 - } 401 394 402 395 return regmap_update_bits(data->regmap, reg[chan], mask, val); 403 396 } ··· 370 433 static int bu27034_set_gain(struct bu27034_data *data, int chan, int gain) 371 434 { 372 435 int ret; 373 - 374 - /* 375 - * We don't allow setting channel 2 gain as it messes up the 376 - * gain for channel 0 - which shares the high bits 377 - */ 378 - if (chan != BU27034_CHAN_DATA0 && chan != BU27034_CHAN_DATA1) 379 - return -EINVAL; 380 436 381 437 ret = iio_gts_find_sel_by_gain(&data->gts, gain); 382 438 if (ret < 0) ··· 494 564 int ret, time_sel, gain_sel, i; 495 565 bool found = false; 496 566 497 - if (chan == BU27034_CHAN_DATA2) 498 - return -EINVAL; 499 - 500 567 if (chan == BU27034_CHAN_ALS) { 501 568 if (val == 0 && val2 == 1000000) 502 569 return 0; ··· 518 591 519 592 /* 520 593 * Populate information for the other channel which should also 521 - * maintain the scale. (Due to the HW limitations the chan2 522 - * gets the same gain as chan0, so we only need to explicitly 523 - * set the chan 0 and 1). 594 + * maintain the scale. 524 595 */ 525 596 if (chan == BU27034_CHAN_DATA0) 526 597 gain.chan = BU27034_CHAN_DATA1; ··· 532 607 /* 533 608 * Iterate through all the times to see if we find one which 534 609 * can support requested scale for requested channel, while 535 - * maintaining the scale for other channels 610 + * maintaining the scale for the other channel 536 611 */ 537 612 for (i = 0; i < data->gts.num_itime; i++) { 538 613 new_time_sel = data->gts.itime_table[i].sel; ··· 547 622 if (ret) 548 623 continue; 549 624 550 - /* Can the other channel(s) maintain scale? */ 625 + /* Can the other channel maintain scale? */ 551 626 ret = iio_gts_find_new_gain_sel_by_old_gain_time( 552 627 &data->gts, gain.old_gain, time_sel, 553 628 new_time_sel, &gain.new_gain); ··· 559 634 } 560 635 if (!found) { 561 636 dev_dbg(data->dev, 562 - "Can't set scale maintaining other channels\n"); 637 + "Can't set scale maintaining other channel\n"); 563 638 ret = -EINVAL; 564 639 565 640 goto unlock_out; ··· 891 966 int reg[] = { 892 967 [BU27034_CHAN_DATA0] = BU27034_REG_DATA0_LO, 893 968 [BU27034_CHAN_DATA1] = BU27034_REG_DATA1_LO, 894 - [BU27034_CHAN_DATA2] = BU27034_REG_DATA2_LO, 895 969 }; 896 970 int valid, ret; 897 971 __le16 val; ··· 957 1033 { 958 1034 int ret; 959 1035 960 - if (chan < BU27034_CHAN_DATA0 || chan > BU27034_CHAN_DATA2) 1036 + if (chan < BU27034_CHAN_DATA0 || chan > BU27034_CHAN_DATA1) 961 1037 return -EINVAL; 962 1038 963 1039 ret = bu27034_meas_set(data, true); ··· 1056 1132 1057 1133 static int bu27034_get_mlux(struct bu27034_data *data, int chan, int *val) 1058 1134 { 1059 - __le16 res[3]; 1135 + __le16 res[BU27034_NUM_HW_DATA_CHANS]; 1060 1136 int ret; 1061 1137 1062 1138 ret = bu27034_meas_set(data, true);