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

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

Jonathan writes:

First round of new drivers, cleanups and functionality for IIO in the 4.3 cycle.

Core and tools new stuff
* Allow explicit flush of hardware fifo by using an non blocking read.
This is needed to support some of the Android requirements for HW fifo
devices - also makes sense generally and clarifies a corner of the ABI.
* Add some missing modifier names. Mostly these exist for weird and
wonderful event types, but should still be present in the name array.
* Update iio_event_monitor to cope with new channel types.
* generic_buffer gains support for single byte scan elements (no idea
how this never got implemented before!)

New device support
* ROHM rpr0521 light and proximity sensor driver.
* bmc150 gains bmc156 support.
* ms5611 gains ms5607 temperature and pressure sensor support.

Driver functionality
* inv-mpu - add scale_available attributes to aid userspace in
configuring these devices.
* isl29125 - add scale_available attributes.
* stk8ba50 - sampling frequency control, triggered buffer support.
* stk8312 - sampling frequency control, triggered buffer support.
* cc10001 - ensure ADC powered up at probe time if shared by non linux
running CPUs.
* bmc150-magn - decouple the buffer and trigger allowing other triggers
to be used to drive this device's sampling.
Documentation
* Add some previously missed *scale_available attributes to the ABI docs.

Cleanups
* Clarify some crazy naming in iio_triggered_buffer_setup that seems to
have somehow ended up backwards (dates back a long way). Avoid the top
half and bottom half naming entirely given we are how dealing with a
handler and a thread in all cases.
* Tools cleanup including coding style, variable naming improvements, also
a new sanity check on a full event having been read.
* stk8ba50 - replace the scale table with a struct for clarity. Also suspend
the sensor if an error occurs in init.
* hid-sensor-prox - drop uneeded line break.
* mma9551 - use size in words for word read / write avoiding accidental
sending of an odd number of bytes.
* mma9553 - fix code alignment and document the use of a mutex.
* light/Kconfig - typo fix in commment.
* cm3323 - don't eat an error value, replace an unneeded local variable with
a generic local variable with the same use, add some blank lines for clarity.
* pressure/Kconfig - typo in Measurement Specialties name.
* bmc150-accel - actually use a mask definition rather than repeating the
value inline, code style cleanup.
* adc/Kconfig - general help description cleanup.
* ssp_sensors - drop redundant spi driver bus initialization (done in the
spi core)
* tmp006 - use genmask rather than hand generated masks.
* ms5611 - drop IIO_CHAN_INFO_SCALE as this driver provides a processed
output and as such the read only scale adds nothing useful.
* kxcjk-1013, adf4350, dummy - drop unwanted blank lines.
* Drop all owner assignments from i2c_drivers and this is done in the
i2c core.

+1872 -454
+5
Documentation/ABI/testing/sysfs-bus-iio
··· 413 413 to compute the calories burnt by the user. 414 414 415 415 What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale_available 416 + What: /sys/.../iio:deviceX/in_anglvel_scale_available 417 + What: /sys/.../iio:deviceX/in_magn_scale_available 418 + What: /sys/.../iio:deviceX/in_illuminance_scale_available 419 + What: /sys/.../iio:deviceX/in_intensity_scale_available 420 + What: /sys/.../iio:deviceX/in_proximity_scale_available 416 421 What: /sys/.../iio:deviceX/in_voltageX_scale_available 417 422 What: /sys/.../iio:deviceX/in_voltage-voltage_scale_available 418 423 What: /sys/.../iio:deviceX/out_voltageX_scale_available
-1
drivers/iio/accel/bma180.c
··· 846 846 static struct i2c_driver bma180_driver = { 847 847 .driver = { 848 848 .name = "bma180", 849 - .owner = THIS_MODULE, 850 849 .pm = BMA180_PM_OPS, 851 850 }, 852 851 .probe = bma180_probe,
+50 -43
drivers/iio/accel/bmc150-accel.c
··· 241 241 {500000, BMC150_ACCEL_SLEEP_500_MS}, 242 242 {1000000, BMC150_ACCEL_SLEEP_1_SEC} }; 243 243 244 - 245 244 static int bmc150_accel_set_mode(struct bmc150_accel_data *data, 246 245 enum bmc150_power_modes mode, 247 246 int dur_us) ··· 258 259 dur_val = 259 260 bmc150_accel_sleep_value_table[i].reg_value; 260 261 } 261 - } else 262 + } else { 262 263 dur_val = 0; 264 + } 263 265 264 266 if (dur_val < 0) 265 267 return -EINVAL; ··· 288 288 289 289 for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) { 290 290 if (bmc150_accel_samp_freq_table[i].val == val && 291 - bmc150_accel_samp_freq_table[i].val2 == val2) { 291 + bmc150_accel_samp_freq_table[i].val2 == val2) { 292 292 ret = i2c_smbus_write_byte_data( 293 293 data->client, 294 294 BMC150_ACCEL_REG_PMU_BW, ··· 351 351 352 352 ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID); 353 353 if (ret < 0) { 354 - dev_err(&data->client->dev, 355 - "Error: Reading chip id\n"); 354 + dev_err(&data->client->dev, "Error: Reading chip id\n"); 356 355 return ret; 357 356 } 358 357 ··· 375 376 BMC150_ACCEL_REG_PMU_RANGE, 376 377 BMC150_ACCEL_DEF_RANGE_4G); 377 378 if (ret < 0) { 378 - dev_err(&data->client->dev, 379 - "Error writing reg_pmu_range\n"); 379 + dev_err(&data->client->dev, "Error writing reg_pmu_range\n"); 380 380 return ret; 381 381 } 382 382 ··· 435 437 { 436 438 int ret; 437 439 438 - if (on) 440 + if (on) { 439 441 ret = pm_runtime_get_sync(&data->client->dev); 440 - else { 442 + } else { 441 443 pm_runtime_mark_last_busy(&data->client->dev); 442 444 ret = pm_runtime_put_autosuspend(&data->client->dev); 443 445 } 446 + 444 447 if (ret < 0) { 445 448 dev_err(&data->client->dev, 446 449 "Failed: bmc150_accel_set_power_state for %d\n", on); ··· 513 514 } 514 515 515 516 /* 516 - * We will expect the enable and disable to do operation in 517 - * in reverse order. This will happen here anyway as our 518 - * resume operation uses sync mode runtime pm calls, the 519 - * suspend operation will be delayed by autosuspend delay 520 - * So the disable operation will still happen in reverse of 521 - * enable operation. When runtime pm is disabled the mode 522 - * is always on so sequence doesn't matter 517 + * We will expect the enable and disable to do operation in reverse 518 + * order. This will happen here anyway, as our resume operation uses 519 + * sync mode runtime pm calls. The suspend operation will be delayed 520 + * by autosuspend delay. 521 + * So the disable operation will still happen in reverse order of 522 + * enable operation. When runtime pm is disabled the mode is always on, 523 + * so sequence doesn't matter. 523 524 */ 524 525 ret = bmc150_accel_set_power_state(data, state); 525 526 if (ret < 0) ··· 572 573 bmc150_accel_set_power_state(data, false); 573 574 return ret; 574 575 } 575 - 576 576 577 577 static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val) 578 578 { ··· 672 674 if (chan->type == IIO_TEMP) { 673 675 *val = BMC150_ACCEL_TEMP_CENTER_VAL; 674 676 return IIO_VAL_INT; 675 - } else 677 + } else { 676 678 return -EINVAL; 679 + } 677 680 case IIO_CHAN_INFO_SCALE: 678 681 *val = 0; 679 682 switch (chan->type) { ··· 775 776 776 777 switch (info) { 777 778 case IIO_EV_INFO_VALUE: 778 - data->slope_thres = val & 0xFF; 779 + data->slope_thres = val & BMC150_ACCEL_SLOPE_THRES_MASK; 779 780 break; 780 781 case IIO_EV_INFO_PERIOD: 781 782 data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK; ··· 792 793 enum iio_event_type type, 793 794 enum iio_event_direction dir) 794 795 { 795 - 796 796 struct bmc150_accel_data *data = iio_priv(indio_dev); 797 797 798 798 return data->ev_enable_state; ··· 825 827 } 826 828 827 829 static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev, 828 - struct iio_trigger *trig) 830 + struct iio_trigger *trig) 829 831 { 830 832 struct bmc150_accel_data *data = iio_priv(indio_dev); 831 833 int i; ··· 961 963 u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3]; 962 964 int64_t tstamp; 963 965 uint64_t sample_period; 966 + 964 967 ret = i2c_smbus_read_byte_data(data->client, 965 968 BMC150_ACCEL_REG_FIFO_STATUS); 966 969 if (ret < 0) { ··· 1254 1255 } 1255 1256 1256 1257 static int bmc150_accel_trigger_set_state(struct iio_trigger *trig, 1257 - bool state) 1258 + bool state) 1258 1259 { 1259 1260 struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig); 1260 1261 struct bmc150_accel_data *data = t->data; ··· 1313 1314 dir = IIO_EV_DIR_RISING; 1314 1315 1315 1316 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X) 1316 - iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1317 - 0, 1318 - IIO_MOD_X, 1319 - IIO_EV_TYPE_ROC, 1320 - dir), 1321 - data->timestamp); 1317 + iio_push_event(indio_dev, 1318 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 1319 + 0, 1320 + IIO_MOD_X, 1321 + IIO_EV_TYPE_ROC, 1322 + dir), 1323 + data->timestamp); 1324 + 1322 1325 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y) 1323 - iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1324 - 0, 1325 - IIO_MOD_Y, 1326 - IIO_EV_TYPE_ROC, 1327 - dir), 1328 - data->timestamp); 1326 + iio_push_event(indio_dev, 1327 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 1328 + 0, 1329 + IIO_MOD_Y, 1330 + IIO_EV_TYPE_ROC, 1331 + dir), 1332 + data->timestamp); 1333 + 1329 1334 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z) 1330 - iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1331 - 0, 1332 - IIO_MOD_Z, 1333 - IIO_EV_TYPE_ROC, 1334 - dir), 1335 - data->timestamp); 1335 + iio_push_event(indio_dev, 1336 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 1337 + 0, 1338 + IIO_MOD_Z, 1339 + IIO_EV_TYPE_ROC, 1340 + dir), 1341 + data->timestamp); 1342 + 1336 1343 return ret; 1337 1344 } 1338 1345 ··· 1370 1365 BMC150_ACCEL_INT_MODE_LATCH_INT | 1371 1366 BMC150_ACCEL_INT_MODE_LATCH_RESET); 1372 1367 if (ret) 1373 - dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n"); 1368 + dev_err(&data->client->dev, 1369 + "Error writing reg_int_rst_latch\n"); 1370 + 1374 1371 ret = IRQ_HANDLED; 1375 1372 } else { 1376 1373 ret = IRQ_NONE; ··· 1419 1412 if (!id) 1420 1413 return NULL; 1421 1414 1422 - *data = (int) id->driver_data; 1415 + *data = (int)id->driver_data; 1423 1416 1424 1417 return dev_name(dev); 1425 1418 } 1426 1419 1427 1420 static int bmc150_accel_gpio_probe(struct i2c_client *client, 1428 - struct bmc150_accel_data *data) 1421 + struct bmc150_accel_data *data) 1429 1422 { 1430 1423 struct device *dev; 1431 1424 struct gpio_desc *gpio;
-3
drivers/iio/accel/kxcjk-1013.c
··· 658 658 int ret, i; 659 659 enum kxcjk1013_mode store_mode; 660 660 661 - 662 661 for (i = 0; i < ARRAY_SIZE(KXCJK1013_scale_table); ++i) { 663 662 if (KXCJK1013_scale_table[i].scale == val) { 664 - 665 663 ret = kxcjk1013_get_mode(data, &store_mode); 666 664 if (ret < 0) 667 665 return ret; ··· 818 820 enum iio_event_type type, 819 821 enum iio_event_direction dir) 820 822 { 821 - 822 823 struct kxcjk1013_data *data = iio_priv(indio_dev); 823 824 824 825 return data->ev_enable_state;
+16 -19
drivers/iio/accel/mma9551_core.c
··· 297 297 * Returns: 0 on success, negative value on failure. 298 298 */ 299 299 int mma9551_read_config_word(struct i2c_client *client, u8 app_id, 300 - u16 reg, u16 *val) 300 + u16 reg, u16 *val) 301 301 { 302 302 int ret; 303 303 __be16 v; ··· 328 328 * Returns: 0 on success, negative value on failure. 329 329 */ 330 330 int mma9551_write_config_word(struct i2c_client *client, u8 app_id, 331 - u16 reg, u16 val) 331 + u16 reg, u16 val) 332 332 { 333 333 __be16 v = cpu_to_be16(val); 334 334 335 335 return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, reg, 336 - (u8 *) &v, 2, NULL, 0); 336 + (u8 *)&v, 2, NULL, 0); 337 337 } 338 338 EXPORT_SYMBOL(mma9551_write_config_word); 339 339 ··· 373 373 * @client: I2C client 374 374 * @app_id: Application ID 375 375 * @reg: Application register 376 - * @len: Length of array to read in bytes 376 + * @len: Length of array to read (in words) 377 377 * @buf: Array of words to read 378 378 * 379 379 * Read multiple configuration registers (word-sized registers). ··· 385 385 * Returns: 0 on success, negative value on failure. 386 386 */ 387 387 int mma9551_read_config_words(struct i2c_client *client, u8 app_id, 388 - u16 reg, u8 len, u16 *buf) 388 + u16 reg, u8 len, u16 *buf) 389 389 { 390 390 int ret, i; 391 - int len_words = len / sizeof(u16); 392 391 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; 393 392 394 - if (len_words > ARRAY_SIZE(be_buf)) { 393 + if (len > ARRAY_SIZE(be_buf)) { 395 394 dev_err(&client->dev, "Invalid buffer size %d\n", len); 396 395 return -EINVAL; 397 396 } 398 397 399 398 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG, 400 - reg, NULL, 0, (u8 *) be_buf, len); 399 + reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16)); 401 400 if (ret < 0) 402 401 return ret; 403 402 404 - for (i = 0; i < len_words; i++) 403 + for (i = 0; i < len; i++) 405 404 buf[i] = be16_to_cpu(be_buf[i]); 406 405 407 406 return 0; ··· 412 413 * @client: I2C client 413 414 * @app_id: Application ID 414 415 * @reg: Application register 415 - * @len: Length of array to read in bytes 416 + * @len: Length of array to read (in words) 416 417 * @buf: Array of words to read 417 418 * 418 419 * Read multiple status registers (word-sized registers). ··· 427 428 u16 reg, u8 len, u16 *buf) 428 429 { 429 430 int ret, i; 430 - int len_words = len / sizeof(u16); 431 431 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; 432 432 433 - if (len_words > ARRAY_SIZE(be_buf)) { 433 + if (len > ARRAY_SIZE(be_buf)) { 434 434 dev_err(&client->dev, "Invalid buffer size %d\n", len); 435 435 return -EINVAL; 436 436 } 437 437 438 438 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS, 439 - reg, NULL, 0, (u8 *) be_buf, len); 439 + reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16)); 440 440 if (ret < 0) 441 441 return ret; 442 442 443 - for (i = 0; i < len_words; i++) 443 + for (i = 0; i < len; i++) 444 444 buf[i] = be16_to_cpu(be_buf[i]); 445 445 446 446 return 0; ··· 451 453 * @client: I2C client 452 454 * @app_id: Application ID 453 455 * @reg: Application register 454 - * @len: Length of array to write in bytes 456 + * @len: Length of array to write (in words) 455 457 * @buf: Array of words to write 456 458 * 457 459 * Write multiple configuration registers (word-sized registers). ··· 466 468 u16 reg, u8 len, u16 *buf) 467 469 { 468 470 int i; 469 - int len_words = len / sizeof(u16); 470 471 __be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2]; 471 472 472 - if (len_words > ARRAY_SIZE(be_buf)) { 473 + if (len > ARRAY_SIZE(be_buf)) { 473 474 dev_err(&client->dev, "Invalid buffer size %d\n", len); 474 475 return -EINVAL; 475 476 } 476 477 477 - for (i = 0; i < len_words; i++) 478 + for (i = 0; i < len; i++) 478 479 be_buf[i] = cpu_to_be16(buf[i]); 479 480 480 481 return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, 481 - reg, (u8 *) be_buf, len, NULL, 0); 482 + reg, (u8 *)be_buf, len * sizeof(u16), NULL, 0); 482 483 } 483 484 EXPORT_SYMBOL(mma9551_write_config_words); 484 485
+3 -3
drivers/iio/accel/mma9551_core.h
··· 53 53 int mma9551_read_status_byte(struct i2c_client *client, u8 app_id, 54 54 u16 reg, u8 *val); 55 55 int mma9551_read_config_word(struct i2c_client *client, u8 app_id, 56 - u16 reg, u16 *val); 56 + u16 reg, u16 *val); 57 57 int mma9551_write_config_word(struct i2c_client *client, u8 app_id, 58 - u16 reg, u16 val); 58 + u16 reg, u16 val); 59 59 int mma9551_read_status_word(struct i2c_client *client, u8 app_id, 60 60 u16 reg, u16 *val); 61 61 int mma9551_read_config_words(struct i2c_client *client, u8 app_id, 62 - u16 reg, u8 len, u16 *buf); 62 + u16 reg, u8 len, u16 *buf); 63 63 int mma9551_read_status_words(struct i2c_client *client, u8 app_id, 64 64 u16 reg, u8 len, u16 *buf); 65 65 int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
+42 -39
drivers/iio/accel/mma9553.c
··· 182 182 183 183 struct mma9553_data { 184 184 struct i2c_client *client; 185 + /* 186 + * 1. Serialize access to HW (requested by mma9551_core API). 187 + * 2. Serialize sequences that power on/off the device and access HW. 188 + */ 185 189 struct mutex mutex; 186 190 struct mma9553_conf_regs conf; 187 191 struct mma9553_event events[MMA9553_EVENTS_INFO_SIZE]; ··· 326 322 int ret; 327 323 328 324 ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER, 329 - MMA9553_REG_STATUS, sizeof(u32), buf); 325 + MMA9553_REG_STATUS, ARRAY_SIZE(buf), 326 + buf); 330 327 if (ret < 0) { 331 328 dev_err(&data->client->dev, 332 329 "error reading status and stepcnt\n"); ··· 347 342 struct mma9553_event *ev_step_detect; 348 343 bool activity_enabled; 349 344 350 - activity_enabled = 351 - mma9553_is_any_event_enabled(data, true, IIO_ACTIVITY); 352 - ev_step_detect = 353 - mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, IIO_EV_DIR_NONE); 345 + activity_enabled = mma9553_is_any_event_enabled(data, true, 346 + IIO_ACTIVITY); 347 + ev_step_detect = mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, 348 + IIO_EV_DIR_NONE); 354 349 355 350 /* 356 351 * If both step detector and activity are enabled, use the MRGFL bit. ··· 376 371 return ret; 377 372 } 378 373 379 - ret = mma9551_gpio_config(data->client, 380 - MMA9553_DEFAULT_GPIO_PIN, 381 - appid, bitnum, MMA9553_DEFAULT_GPIO_POLARITY); 374 + ret = mma9551_gpio_config(data->client, MMA9553_DEFAULT_GPIO_PIN, appid, 375 + bitnum, MMA9553_DEFAULT_GPIO_POLARITY); 382 376 if (ret < 0) 383 377 return ret; 384 378 data->gpio_bitnum = bitnum; ··· 398 394 * a device identification command to differentiate the MMA9553L 399 395 * from the MMA9550L. 400 396 */ 401 - ret = 402 - mma9551_read_config_words(data->client, MMA9551_APPID_PEDOMETER, 403 - MMA9553_REG_CONF_SLEEPMIN, 404 - sizeof(data->conf), (u16 *) &data->conf); 397 + ret = mma9551_read_config_words(data->client, MMA9551_APPID_PEDOMETER, 398 + MMA9553_REG_CONF_SLEEPMIN, 399 + sizeof(data->conf) / sizeof(u16), 400 + (u16 *)&data->conf); 405 401 if (ret < 0) { 406 402 dev_err(&data->client->dev, 407 403 "failed to read configuration registers\n"); 408 404 return ret; 409 405 } 410 - 411 406 412 407 /* Reset GPIO */ 413 408 data->gpio_bitnum = MMA9553_MAX_BITNUM; ··· 422 419 data->conf.sleepmin = MMA9553_DEFAULT_SLEEPMIN; 423 420 data->conf.sleepmax = MMA9553_DEFAULT_SLEEPMAX; 424 421 data->conf.sleepthd = MMA9553_DEFAULT_SLEEPTHD; 425 - data->conf.config = 426 - mma9553_set_bits(data->conf.config, 1, MMA9553_MASK_CONF_CONFIG); 422 + data->conf.config = mma9553_set_bits(data->conf.config, 1, 423 + MMA9553_MASK_CONF_CONFIG); 427 424 /* 428 425 * Clear the activity debounce counter when the activity level changes, 429 426 * so that the confidence level applies for any activity level. 430 427 */ 431 428 data->conf.config = mma9553_set_bits(data->conf.config, 1, 432 429 MMA9553_MASK_CONF_ACT_DBCNTM); 433 - ret = 434 - mma9551_write_config_words(data->client, MMA9551_APPID_PEDOMETER, 435 - MMA9553_REG_CONF_SLEEPMIN, 436 - sizeof(data->conf), (u16 *) &data->conf); 430 + ret = mma9551_write_config_words(data->client, MMA9551_APPID_PEDOMETER, 431 + MMA9553_REG_CONF_SLEEPMIN, 432 + sizeof(data->conf) / sizeof(u16), 433 + (u16 *)&data->conf); 437 434 if (ret < 0) { 438 435 dev_err(&data->client->dev, 439 436 "failed to write configuration registers\n"); ··· 570 567 return IIO_VAL_INT; 571 568 case IIO_CHAN_INFO_CALIBHEIGHT: 572 569 tmp = mma9553_get_bits(data->conf.height_weight, 573 - MMA9553_MASK_CONF_HEIGHT); 570 + MMA9553_MASK_CONF_HEIGHT); 574 571 *val = tmp / 100; /* cm to m */ 575 572 *val2 = (tmp % 100) * 10000; 576 573 return IIO_VAL_INT_PLUS_MICRO; ··· 722 719 enum iio_event_type type, 723 720 enum iio_event_direction dir) 724 721 { 725 - 726 722 struct mma9553_data *data = iio_priv(indio_dev); 727 723 struct mma9553_event *event; 728 724 ··· 1028 1026 return IRQ_HANDLED; 1029 1027 } 1030 1028 1031 - ev_prev_activity = 1032 - mma9553_get_event(data, IIO_ACTIVITY, 1033 - mma9553_activity_to_mod(data->activity), 1034 - IIO_EV_DIR_FALLING); 1035 - ev_activity = 1036 - mma9553_get_event(data, IIO_ACTIVITY, 1037 - mma9553_activity_to_mod(activity), 1038 - IIO_EV_DIR_RISING); 1039 - ev_step_detect = 1040 - mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, IIO_EV_DIR_NONE); 1029 + ev_prev_activity = mma9553_get_event(data, IIO_ACTIVITY, 1030 + mma9553_activity_to_mod( 1031 + data->activity), 1032 + IIO_EV_DIR_FALLING); 1033 + ev_activity = mma9553_get_event(data, IIO_ACTIVITY, 1034 + mma9553_activity_to_mod(activity), 1035 + IIO_EV_DIR_RISING); 1036 + ev_step_detect = mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, 1037 + IIO_EV_DIR_NONE); 1041 1038 1042 1039 if (ev_step_detect->enabled && (stepcnt != data->stepcnt)) { 1043 1040 data->stepcnt = stepcnt; 1044 1041 iio_push_event(indio_dev, 1045 1042 IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD, 1046 - IIO_EV_DIR_NONE, IIO_EV_TYPE_CHANGE, 0, 0, 0), 1043 + IIO_EV_DIR_NONE, 1044 + IIO_EV_TYPE_CHANGE, 0, 0, 0), 1047 1045 data->timestamp); 1048 1046 } 1049 1047 ··· 1053 1051 if (ev_prev_activity && ev_prev_activity->enabled) 1054 1052 iio_push_event(indio_dev, 1055 1053 IIO_EVENT_CODE(IIO_ACTIVITY, 0, 1056 - ev_prev_activity->info->mod, 1057 - IIO_EV_DIR_FALLING, 1058 - IIO_EV_TYPE_THRESH, 0, 0, 0), 1054 + ev_prev_activity->info->mod, 1055 + IIO_EV_DIR_FALLING, 1056 + IIO_EV_TYPE_THRESH, 0, 0, 1057 + 0), 1059 1058 data->timestamp); 1060 1059 1061 1060 if (ev_activity && ev_activity->enabled) 1062 1061 iio_push_event(indio_dev, 1063 1062 IIO_EVENT_CODE(IIO_ACTIVITY, 0, 1064 - ev_activity->info->mod, 1065 - IIO_EV_DIR_RISING, 1066 - IIO_EV_TYPE_THRESH, 0, 0, 0), 1063 + ev_activity->info->mod, 1064 + IIO_EV_DIR_RISING, 1065 + IIO_EV_TYPE_THRESH, 0, 0, 1066 + 0), 1067 1067 data->timestamp); 1068 1068 } 1069 1069 mutex_unlock(&data->mutex); ··· 1160 1156 client->irq); 1161 1157 goto out_poweroff; 1162 1158 } 1163 - 1164 1159 } 1165 1160 1166 1161 ret = iio_device_register(indio_dev);
-1
drivers/iio/accel/st_accel_i2c.c
··· 122 122 123 123 static struct i2c_driver st_accel_driver = { 124 124 .driver = { 125 - .owner = THIS_MODULE, 126 125 .name = "st-accel-i2c", 127 126 .of_match_table = of_match_ptr(st_accel_of_match), 128 127 },
+339 -41
drivers/iio/accel/stk8312.c
··· 11 11 */ 12 12 13 13 #include <linux/acpi.h> 14 + #include <linux/gpio/consumer.h> 14 15 #include <linux/i2c.h> 16 + #include <linux/interrupt.h> 15 17 #include <linux/kernel.h> 16 18 #include <linux/module.h> 17 19 #include <linux/delay.h> 20 + #include <linux/iio/buffer.h> 18 21 #include <linux/iio/iio.h> 19 22 #include <linux/iio/sysfs.h> 23 + #include <linux/iio/trigger.h> 24 + #include <linux/iio/triggered_buffer.h> 25 + #include <linux/iio/trigger_consumer.h> 20 26 21 27 #define STK8312_REG_XOUT 0x00 22 28 #define STK8312_REG_YOUT 0x01 23 29 #define STK8312_REG_ZOUT 0x02 30 + #define STK8312_REG_INTSU 0x06 24 31 #define STK8312_REG_MODE 0x07 32 + #define STK8312_REG_SR 0x08 25 33 #define STK8312_REG_STH 0x13 26 34 #define STK8312_REG_RESET 0x20 27 35 #define STK8312_REG_AFECTRL 0x24 ··· 37 29 #define STK8312_REG_OTPDATA 0x3E 38 30 #define STK8312_REG_OTPCTRL 0x3F 39 31 40 - #define STK8312_MODE_ACTIVE 1 41 - #define STK8312_MODE_STANDBY 0 42 - #define STK8312_MODE_MASK 0x01 32 + #define STK8312_MODE_ACTIVE 0x01 33 + #define STK8312_MODE_STANDBY 0x00 34 + #define STK8312_DREADY_BIT 0x10 35 + #define STK8312_INT_MODE 0xC0 43 36 #define STK8312_RNG_MASK 0xC0 37 + #define STK8312_SR_MASK 0x07 38 + #define STK8312_SR_400HZ_IDX 0 44 39 #define STK8312_RNG_SHIFT 6 45 40 #define STK8312_READ_RETRIES 16 41 + #define STK8312_ALL_CHANNEL_MASK 7 42 + #define STK8312_ALL_CHANNEL_SIZE 3 46 43 47 44 #define STK8312_DRIVER_NAME "stk8312" 45 + #define STK8312_GPIO "stk8312_gpio" 46 + #define STK8312_IRQ_NAME "stk8312_event" 48 47 49 48 /* 50 49 * The accelerometer has two measurement ranges: ··· 68 53 {0, 461600}, {1, 231100} 69 54 }; 70 55 71 - #define STK8312_ACCEL_CHANNEL(reg, axis) { \ 72 - .type = IIO_ACCEL, \ 73 - .address = reg, \ 74 - .modified = 1, \ 75 - .channel2 = IIO_MOD_##axis, \ 76 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 77 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 56 + static const struct { 57 + u16 val; 58 + u32 val2; 59 + } stk8312_samp_freq_table[] = { 60 + {400, 0}, {200, 0}, {100, 0}, {50, 0}, {25, 0}, 61 + {12, 500000}, {6, 250000}, {3, 125000} 62 + }; 63 + 64 + #define STK8312_ACCEL_CHANNEL(index, reg, axis) { \ 65 + .type = IIO_ACCEL, \ 66 + .address = reg, \ 67 + .modified = 1, \ 68 + .channel2 = IIO_MOD_##axis, \ 69 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 70 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 71 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 72 + .scan_index = index, \ 73 + .scan_type = { \ 74 + .sign = 's', \ 75 + .realbits = 8, \ 76 + .storagebits = 8, \ 77 + .endianness = IIO_CPU, \ 78 + }, \ 78 79 } 79 80 80 81 static const struct iio_chan_spec stk8312_channels[] = { 81 - STK8312_ACCEL_CHANNEL(STK8312_REG_XOUT, X), 82 - STK8312_ACCEL_CHANNEL(STK8312_REG_YOUT, Y), 83 - STK8312_ACCEL_CHANNEL(STK8312_REG_ZOUT, Z), 82 + STK8312_ACCEL_CHANNEL(0, STK8312_REG_XOUT, X), 83 + STK8312_ACCEL_CHANNEL(1, STK8312_REG_YOUT, Y), 84 + STK8312_ACCEL_CHANNEL(2, STK8312_REG_ZOUT, Z), 85 + IIO_CHAN_SOFT_TIMESTAMP(3), 84 86 }; 85 87 86 88 struct stk8312_data { 87 89 struct i2c_client *client; 88 90 struct mutex lock; 89 91 int range; 92 + u8 sample_rate_idx; 90 93 u8 mode; 94 + struct iio_trigger *dready_trig; 95 + bool dready_trigger_on; 96 + s8 buffer[16]; /* 3x8-bit channels + 5x8 padding + 64-bit timestamp */ 91 97 }; 92 98 93 99 static IIO_CONST_ATTR(in_accel_scale_available, STK8312_SCALE_AVAIL); 94 100 101 + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("3.125 6.25 12.5 25 50 100 200 400"); 102 + 95 103 static struct attribute *stk8312_attributes[] = { 96 104 &iio_const_attr_in_accel_scale_available.dev_attr.attr, 105 + &iio_const_attr_sampling_frequency_available.dev_attr.attr, 97 106 NULL, 98 107 }; 99 108 ··· 169 130 static int stk8312_set_mode(struct stk8312_data *data, u8 mode) 170 131 { 171 132 int ret; 172 - u8 masked_reg; 173 133 struct i2c_client *client = data->client; 174 134 175 - if (mode > 1) 176 - return -EINVAL; 177 - else if (mode == data->mode) 135 + if (mode == data->mode) 178 136 return 0; 179 137 180 - ret = i2c_smbus_read_byte_data(client, STK8312_REG_MODE); 181 - if (ret < 0) { 182 - dev_err(&client->dev, "failed to change sensor mode\n"); 183 - return ret; 184 - } 185 - masked_reg = ret & (~STK8312_MODE_MASK); 186 - masked_reg |= mode; 187 - 188 - ret = i2c_smbus_write_byte_data(client, 189 - STK8312_REG_MODE, masked_reg); 138 + ret = i2c_smbus_write_byte_data(client, STK8312_REG_MODE, mode); 190 139 if (ret < 0) { 191 140 dev_err(&client->dev, "failed to change sensor mode\n"); 192 141 return ret; 193 142 } 194 143 195 144 data->mode = mode; 196 - if (mode == STK8312_MODE_ACTIVE) { 145 + if (mode & STK8312_MODE_ACTIVE) { 197 146 /* Need to run OTP sequence before entering active mode */ 198 147 usleep_range(1000, 5000); 199 148 ret = stk8312_otp_init(data); 200 149 } 201 150 202 151 return ret; 152 + } 153 + 154 + static int stk8312_set_interrupts(struct stk8312_data *data, u8 int_mask) 155 + { 156 + int ret; 157 + u8 mode; 158 + struct i2c_client *client = data->client; 159 + 160 + mode = data->mode; 161 + /* We need to go in standby mode to modify registers */ 162 + ret = stk8312_set_mode(data, STK8312_MODE_STANDBY); 163 + if (ret < 0) 164 + return ret; 165 + 166 + ret = i2c_smbus_write_byte_data(client, STK8312_REG_INTSU, int_mask); 167 + if (ret < 0) 168 + dev_err(&client->dev, "failed to set interrupts\n"); 169 + 170 + return stk8312_set_mode(data, mode); 171 + } 172 + 173 + static int stk8312_data_rdy_trigger_set_state(struct iio_trigger *trig, 174 + bool state) 175 + { 176 + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 177 + struct stk8312_data *data = iio_priv(indio_dev); 178 + int ret; 179 + 180 + if (state) 181 + ret = stk8312_set_interrupts(data, STK8312_DREADY_BIT); 182 + else 183 + ret = stk8312_set_interrupts(data, 0x00); 184 + 185 + if (ret < 0) { 186 + dev_err(&data->client->dev, "failed to set trigger state\n"); 187 + return ret; 188 + } 189 + 190 + data->dready_trigger_on = state; 191 + 192 + return ret; 193 + } 194 + 195 + static const struct iio_trigger_ops stk8312_trigger_ops = { 196 + .set_trigger_state = stk8312_data_rdy_trigger_set_state, 197 + .owner = THIS_MODULE, 198 + }; 199 + 200 + static int stk8312_set_sample_rate(struct stk8312_data *data, int rate) 201 + { 202 + int ret; 203 + u8 masked_reg; 204 + u8 mode; 205 + struct i2c_client *client = data->client; 206 + 207 + if (rate == data->sample_rate_idx) 208 + return 0; 209 + 210 + mode = data->mode; 211 + /* We need to go in standby mode to modify registers */ 212 + ret = stk8312_set_mode(data, STK8312_MODE_STANDBY); 213 + if (ret < 0) 214 + return ret; 215 + 216 + ret = i2c_smbus_read_byte_data(client, STK8312_REG_SR); 217 + if (ret < 0) { 218 + dev_err(&client->dev, "failed to set sampling rate\n"); 219 + return ret; 220 + } 221 + 222 + masked_reg = (ret & (~STK8312_SR_MASK)) | rate; 223 + 224 + ret = i2c_smbus_write_byte_data(client, STK8312_REG_SR, masked_reg); 225 + if (ret < 0) 226 + dev_err(&client->dev, "failed to set sampling rate\n"); 227 + else 228 + data->sample_rate_idx = rate; 229 + 230 + return stk8312_set_mode(data, mode); 203 231 } 204 232 205 233 static int stk8312_set_range(struct stk8312_data *data, u8 range) ··· 314 208 return -EINVAL; 315 209 316 210 ret = i2c_smbus_read_byte_data(client, address); 317 - if (ret < 0) { 211 + if (ret < 0) 318 212 dev_err(&client->dev, "register read failed\n"); 319 - return ret; 320 - } 321 213 322 - return sign_extend32(ret, 7); 214 + return ret; 323 215 } 324 216 325 217 static int stk8312_read_raw(struct iio_dev *indio_dev, ··· 325 221 int *val, int *val2, long mask) 326 222 { 327 223 struct stk8312_data *data = iio_priv(indio_dev); 328 - 329 - if (chan->type != IIO_ACCEL) 330 - return -EINVAL; 224 + int ret; 331 225 332 226 switch (mask) { 333 227 case IIO_CHAN_INFO_RAW: 228 + if (iio_buffer_enabled(indio_dev)) 229 + return -EBUSY; 334 230 mutex_lock(&data->lock); 335 - *val = stk8312_read_accel(data, chan->address); 231 + ret = stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE); 232 + if (ret < 0) { 233 + mutex_unlock(&data->lock); 234 + return -EINVAL; 235 + } 236 + ret = stk8312_read_accel(data, chan->address); 237 + if (ret < 0) { 238 + stk8312_set_mode(data, 239 + data->mode & (~STK8312_MODE_ACTIVE)); 240 + mutex_unlock(&data->lock); 241 + return -EINVAL; 242 + } 243 + *val = sign_extend32(ret, 7); 244 + stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); 336 245 mutex_unlock(&data->lock); 337 246 return IIO_VAL_INT; 338 247 case IIO_CHAN_INFO_SCALE: 339 248 *val = stk8312_scale_table[data->range - 1][0]; 340 249 *val2 = stk8312_scale_table[data->range - 1][1]; 250 + return IIO_VAL_INT_PLUS_MICRO; 251 + case IIO_CHAN_INFO_SAMP_FREQ: 252 + *val = stk8312_samp_freq_table[data->sample_rate_idx].val; 253 + *val2 = stk8312_samp_freq_table[data->sample_rate_idx].val2; 341 254 return IIO_VAL_INT_PLUS_MICRO; 342 255 } 343 256 ··· 386 265 mutex_unlock(&data->lock); 387 266 388 267 return ret; 268 + case IIO_CHAN_INFO_SAMP_FREQ: 269 + for (i = 0; i < ARRAY_SIZE(stk8312_samp_freq_table); i++) 270 + if (val == stk8312_samp_freq_table[i].val && 271 + val2 == stk8312_samp_freq_table[i].val2) { 272 + index = i; 273 + break; 274 + } 275 + if (index < 0) 276 + return -EINVAL; 277 + mutex_lock(&data->lock); 278 + ret = stk8312_set_sample_rate(data, index); 279 + mutex_unlock(&data->lock); 280 + 281 + return ret; 389 282 } 390 283 391 284 return -EINVAL; ··· 411 276 .write_raw = stk8312_write_raw, 412 277 .attrs = &stk8312_attribute_group, 413 278 }; 279 + 280 + static irqreturn_t stk8312_trigger_handler(int irq, void *p) 281 + { 282 + struct iio_poll_func *pf = p; 283 + struct iio_dev *indio_dev = pf->indio_dev; 284 + struct stk8312_data *data = iio_priv(indio_dev); 285 + int bit, ret, i = 0; 286 + u8 buffer[STK8312_ALL_CHANNEL_SIZE]; 287 + 288 + mutex_lock(&data->lock); 289 + /* 290 + * Do a bulk read if all channels are requested, 291 + * from 0x00 (XOUT) to 0x02 (ZOUT) 292 + */ 293 + if (*(indio_dev->active_scan_mask) == STK8312_ALL_CHANNEL_MASK) { 294 + ret = i2c_smbus_read_i2c_block_data(data->client, 295 + STK8312_REG_XOUT, 296 + STK8312_ALL_CHANNEL_SIZE, 297 + buffer); 298 + if (ret < STK8312_ALL_CHANNEL_SIZE) { 299 + dev_err(&data->client->dev, "register read failed\n"); 300 + mutex_unlock(&data->lock); 301 + goto err; 302 + } 303 + data->buffer[0] = buffer[0]; 304 + data->buffer[1] = buffer[1]; 305 + data->buffer[2] = buffer[2]; 306 + } else { 307 + for_each_set_bit(bit, indio_dev->active_scan_mask, 308 + indio_dev->masklength) { 309 + ret = stk8312_read_accel(data, bit); 310 + if (ret < 0) { 311 + mutex_unlock(&data->lock); 312 + goto err; 313 + } 314 + data->buffer[i++] = ret; 315 + } 316 + } 317 + mutex_unlock(&data->lock); 318 + 319 + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 320 + pf->timestamp); 321 + err: 322 + iio_trigger_notify_done(indio_dev->trig); 323 + 324 + return IRQ_HANDLED; 325 + } 326 + 327 + static irqreturn_t stk8312_data_rdy_trig_poll(int irq, void *private) 328 + { 329 + struct iio_dev *indio_dev = private; 330 + struct stk8312_data *data = iio_priv(indio_dev); 331 + 332 + if (data->dready_trigger_on) 333 + iio_trigger_poll(data->dready_trig); 334 + 335 + return IRQ_HANDLED; 336 + } 337 + 338 + static int stk8312_buffer_preenable(struct iio_dev *indio_dev) 339 + { 340 + struct stk8312_data *data = iio_priv(indio_dev); 341 + 342 + return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE); 343 + } 344 + 345 + static int stk8312_buffer_postdisable(struct iio_dev *indio_dev) 346 + { 347 + struct stk8312_data *data = iio_priv(indio_dev); 348 + 349 + return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); 350 + } 351 + 352 + static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = { 353 + .preenable = stk8312_buffer_preenable, 354 + .postenable = iio_triggered_buffer_postenable, 355 + .predisable = iio_triggered_buffer_predisable, 356 + .postdisable = stk8312_buffer_postdisable, 357 + }; 358 + 359 + static int stk8312_gpio_probe(struct i2c_client *client) 360 + { 361 + struct device *dev; 362 + struct gpio_desc *gpio; 363 + int ret; 364 + 365 + if (!client) 366 + return -EINVAL; 367 + 368 + dev = &client->dev; 369 + 370 + /* data ready gpio interrupt pin */ 371 + gpio = devm_gpiod_get_index(dev, STK8312_GPIO, 0, GPIOD_IN); 372 + if (IS_ERR(gpio)) { 373 + dev_err(dev, "acpi gpio get index failed\n"); 374 + return PTR_ERR(gpio); 375 + } 376 + 377 + ret = gpiod_to_irq(gpio); 378 + dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); 379 + 380 + return ret; 381 + } 414 382 415 383 static int stk8312_probe(struct i2c_client *client, 416 384 const struct i2c_device_id *id) ··· 546 308 dev_err(&client->dev, "failed to reset sensor\n"); 547 309 return ret; 548 310 } 311 + data->sample_rate_idx = STK8312_SR_400HZ_IDX; 549 312 ret = stk8312_set_range(data, 1); 550 313 if (ret < 0) 551 314 return ret; 552 315 553 - ret = stk8312_set_mode(data, STK8312_MODE_ACTIVE); 316 + ret = stk8312_set_mode(data, STK8312_INT_MODE | STK8312_MODE_ACTIVE); 554 317 if (ret < 0) 555 318 return ret; 319 + 320 + if (client->irq < 0) 321 + client->irq = stk8312_gpio_probe(client); 322 + 323 + if (client->irq >= 0) { 324 + ret = devm_request_threaded_irq(&client->dev, client->irq, 325 + stk8312_data_rdy_trig_poll, 326 + NULL, 327 + IRQF_TRIGGER_RISING | 328 + IRQF_ONESHOT, 329 + STK8312_IRQ_NAME, 330 + indio_dev); 331 + if (ret < 0) { 332 + dev_err(&client->dev, "request irq %d failed\n", 333 + client->irq); 334 + goto err_power_off; 335 + } 336 + 337 + data->dready_trig = devm_iio_trigger_alloc(&client->dev, 338 + "%s-dev%d", 339 + indio_dev->name, 340 + indio_dev->id); 341 + if (!data->dready_trig) { 342 + ret = -ENOMEM; 343 + goto err_power_off; 344 + } 345 + 346 + data->dready_trig->dev.parent = &client->dev; 347 + data->dready_trig->ops = &stk8312_trigger_ops; 348 + iio_trigger_set_drvdata(data->dready_trig, indio_dev); 349 + ret = iio_trigger_register(data->dready_trig); 350 + if (ret) { 351 + dev_err(&client->dev, "iio trigger register failed\n"); 352 + goto err_power_off; 353 + } 354 + } 355 + 356 + ret = iio_triggered_buffer_setup(indio_dev, 357 + iio_pollfunc_store_time, 358 + stk8312_trigger_handler, 359 + &stk8312_buffer_setup_ops); 360 + if (ret < 0) { 361 + dev_err(&client->dev, "iio triggered buffer setup failed\n"); 362 + goto err_trigger_unregister; 363 + } 556 364 557 365 ret = iio_device_register(indio_dev); 558 366 if (ret < 0) { 559 367 dev_err(&client->dev, "device_register failed\n"); 560 - stk8312_set_mode(data, STK8312_MODE_STANDBY); 368 + goto err_buffer_cleanup; 561 369 } 562 370 371 + return ret; 372 + 373 + err_buffer_cleanup: 374 + iio_triggered_buffer_cleanup(indio_dev); 375 + err_trigger_unregister: 376 + if (data->dready_trig) 377 + iio_trigger_unregister(data->dready_trig); 378 + err_power_off: 379 + stk8312_set_mode(data, STK8312_MODE_STANDBY); 563 380 return ret; 564 381 } 565 382 566 383 static int stk8312_remove(struct i2c_client *client) 567 384 { 568 385 struct iio_dev *indio_dev = i2c_get_clientdata(client); 386 + struct stk8312_data *data = iio_priv(indio_dev); 569 387 570 388 iio_device_unregister(indio_dev); 389 + iio_triggered_buffer_cleanup(indio_dev); 571 390 572 - return stk8312_set_mode(iio_priv(indio_dev), STK8312_MODE_STANDBY); 391 + if (data->dready_trig) 392 + iio_trigger_unregister(data->dready_trig); 393 + 394 + return stk8312_set_mode(data, STK8312_MODE_STANDBY); 573 395 } 574 396 575 397 #ifdef CONFIG_PM_SLEEP ··· 639 341 640 342 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 641 343 642 - return stk8312_set_mode(data, STK8312_MODE_STANDBY); 344 + return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); 643 345 } 644 346 645 347 static int stk8312_resume(struct device *dev) ··· 648 350 649 351 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 650 352 651 - return stk8312_set_mode(data, STK8312_MODE_ACTIVE); 353 + return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE); 652 354 } 653 355 654 356 static SIMPLE_DEV_PM_OPS(stk8312_pm_ops, stk8312_suspend, stk8312_resume);
+365 -69
drivers/iio/accel/stk8ba50.c
··· 11 11 */ 12 12 13 13 #include <linux/acpi.h> 14 + #include <linux/gpio/consumer.h> 14 15 #include <linux/i2c.h> 16 + #include <linux/interrupt.h> 15 17 #include <linux/kernel.h> 16 18 #include <linux/module.h> 19 + #include <linux/iio/buffer.h> 17 20 #include <linux/iio/iio.h> 18 21 #include <linux/iio/sysfs.h> 22 + #include <linux/iio/trigger.h> 23 + #include <linux/iio/triggered_buffer.h> 24 + #include <linux/iio/trigger_consumer.h> 19 25 20 26 #define STK8BA50_REG_XOUT 0x02 21 27 #define STK8BA50_REG_YOUT 0x04 22 28 #define STK8BA50_REG_ZOUT 0x06 23 29 #define STK8BA50_REG_RANGE 0x0F 30 + #define STK8BA50_REG_BWSEL 0x10 24 31 #define STK8BA50_REG_POWMODE 0x11 25 32 #define STK8BA50_REG_SWRST 0x14 33 + #define STK8BA50_REG_INTEN2 0x17 34 + #define STK8BA50_REG_INTMAP2 0x1A 26 35 27 36 #define STK8BA50_MODE_NORMAL 0 28 37 #define STK8BA50_MODE_SUSPEND 1 29 38 #define STK8BA50_MODE_POWERBIT BIT(7) 30 39 #define STK8BA50_DATA_SHIFT 6 31 40 #define STK8BA50_RESET_CMD 0xB6 41 + #define STK8BA50_SR_1792HZ_IDX 7 42 + #define STK8BA50_DREADY_INT_MASK 0x10 43 + #define STK8BA50_DREADY_INT_MAP 0x81 44 + #define STK8BA50_ALL_CHANNEL_MASK 7 45 + #define STK8BA50_ALL_CHANNEL_SIZE 6 32 46 33 47 #define STK8BA50_DRIVER_NAME "stk8ba50" 48 + #define STK8BA50_GPIO "stk8ba50_gpio" 49 + #define STK8BA50_IRQ_NAME "stk8ba50_event" 34 50 35 51 #define STK8BA50_SCALE_AVAIL "0.0384 0.0767 0.1534 0.3069" 36 52 ··· 66 50 * 67 51 * Locally, the range is stored as a table index. 68 52 */ 69 - static const int stk8ba50_scale_table[][2] = { 53 + static const struct { 54 + u8 reg_val; 55 + u32 scale_val; 56 + } stk8ba50_scale_table[] = { 70 57 {3, 38400}, {5, 76700}, {8, 153400}, {12, 306900} 58 + }; 59 + 60 + /* Sample rates are stored as { <register value>, <Hz value> } */ 61 + static const struct { 62 + u8 reg_val; 63 + u16 samp_freq; 64 + } stk8ba50_samp_freq_table[] = { 65 + {0x08, 14}, {0x09, 25}, {0x0A, 56}, {0x0B, 112}, 66 + {0x0C, 224}, {0x0D, 448}, {0x0E, 896}, {0x0F, 1792} 67 + }; 68 + 69 + /* Used to map scan mask bits to their corresponding channel register. */ 70 + static const int stk8ba50_channel_table[] = { 71 + STK8BA50_REG_XOUT, 72 + STK8BA50_REG_YOUT, 73 + STK8BA50_REG_ZOUT 71 74 }; 72 75 73 76 struct stk8ba50_data { 74 77 struct i2c_client *client; 75 78 struct mutex lock; 76 79 int range; 80 + u8 sample_rate_idx; 81 + struct iio_trigger *dready_trig; 82 + bool dready_trigger_on; 83 + /* 84 + * 3 x 16-bit channels (10-bit data, 6-bit padding) + 85 + * 1 x 16 padding + 86 + * 4 x 16 64-bit timestamp 87 + */ 88 + s16 buffer[8]; 77 89 }; 78 90 79 - #define STK8BA50_ACCEL_CHANNEL(reg, axis) { \ 80 - .type = IIO_ACCEL, \ 81 - .address = reg, \ 82 - .modified = 1, \ 83 - .channel2 = IIO_MOD_##axis, \ 84 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 85 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 91 + #define STK8BA50_ACCEL_CHANNEL(index, reg, axis) { \ 92 + .type = IIO_ACCEL, \ 93 + .address = reg, \ 94 + .modified = 1, \ 95 + .channel2 = IIO_MOD_##axis, \ 96 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 97 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 98 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 99 + .scan_index = index, \ 100 + .scan_type = { \ 101 + .sign = 's', \ 102 + .realbits = 10, \ 103 + .storagebits = 16, \ 104 + .shift = STK8BA50_DATA_SHIFT, \ 105 + .endianness = IIO_CPU, \ 106 + }, \ 86 107 } 87 108 88 109 static const struct iio_chan_spec stk8ba50_channels[] = { 89 - STK8BA50_ACCEL_CHANNEL(STK8BA50_REG_XOUT, X), 90 - STK8BA50_ACCEL_CHANNEL(STK8BA50_REG_YOUT, Y), 91 - STK8BA50_ACCEL_CHANNEL(STK8BA50_REG_ZOUT, Z), 110 + STK8BA50_ACCEL_CHANNEL(0, STK8BA50_REG_XOUT, X), 111 + STK8BA50_ACCEL_CHANNEL(1, STK8BA50_REG_YOUT, Y), 112 + STK8BA50_ACCEL_CHANNEL(2, STK8BA50_REG_ZOUT, Z), 113 + IIO_CHAN_SOFT_TIMESTAMP(3), 92 114 }; 93 115 94 116 static IIO_CONST_ATTR(in_accel_scale_available, STK8BA50_SCALE_AVAIL); 95 117 118 + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("14 25 56 112 224 448 896 1792"); 119 + 96 120 static struct attribute *stk8ba50_attributes[] = { 97 121 &iio_const_attr_in_accel_scale_available.dev_attr.attr, 122 + &iio_const_attr_sampling_frequency_available.dev_attr.attr, 98 123 NULL, 99 124 }; 100 125 ··· 154 97 return ret; 155 98 } 156 99 157 - return sign_extend32(ret >> STK8BA50_DATA_SHIFT, 9); 100 + return ret; 158 101 } 159 102 160 - static int stk8ba50_read_raw(struct iio_dev *indio_dev, 161 - struct iio_chan_spec const *chan, 162 - int *val, int *val2, long mask) 103 + static int stk8ba50_data_rdy_trigger_set_state(struct iio_trigger *trig, 104 + bool state) 163 105 { 106 + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 164 107 struct stk8ba50_data *data = iio_priv(indio_dev); 165 - 166 - switch (mask) { 167 - case IIO_CHAN_INFO_RAW: 168 - mutex_lock(&data->lock); 169 - *val = stk8ba50_read_accel(data, chan->address); 170 - mutex_unlock(&data->lock); 171 - return IIO_VAL_INT; 172 - case IIO_CHAN_INFO_SCALE: 173 - *val = 0; 174 - *val2 = stk8ba50_scale_table[data->range][1]; 175 - return IIO_VAL_INT_PLUS_MICRO; 176 - } 177 - 178 - return -EINVAL; 179 - } 180 - 181 - static int stk8ba50_write_raw(struct iio_dev *indio_dev, 182 - struct iio_chan_spec const *chan, 183 - int val, int val2, long mask) 184 - { 185 108 int ret; 186 - int i; 187 - int index = -1; 188 - struct stk8ba50_data *data = iio_priv(indio_dev); 189 109 190 - switch (mask) { 191 - case IIO_CHAN_INFO_SCALE: 192 - if (val != 0) 193 - return -EINVAL; 194 - 195 - for (i = 0; i < ARRAY_SIZE(stk8ba50_scale_table); i++) 196 - if (val2 == stk8ba50_scale_table[i][1]) { 197 - index = i; 198 - break; 199 - } 200 - if (index < 0) 201 - return -EINVAL; 202 - 110 + if (state) 203 111 ret = i2c_smbus_write_byte_data(data->client, 204 - STK8BA50_REG_RANGE, 205 - stk8ba50_scale_table[index][0]); 206 - if (ret < 0) 207 - dev_err(&data->client->dev, 208 - "failed to set measurement range\n"); 209 - else 210 - data->range = index; 112 + STK8BA50_REG_INTEN2, STK8BA50_DREADY_INT_MASK); 113 + else 114 + ret = i2c_smbus_write_byte_data(data->client, 115 + STK8BA50_REG_INTEN2, 0x00); 211 116 212 - return ret; 213 - } 117 + if (ret < 0) 118 + dev_err(&data->client->dev, "failed to set trigger state\n"); 119 + else 120 + data->dready_trigger_on = state; 214 121 215 - return -EINVAL; 122 + return ret; 216 123 } 217 124 218 - static const struct iio_info stk8ba50_info = { 219 - .driver_module = THIS_MODULE, 220 - .read_raw = stk8ba50_read_raw, 221 - .write_raw = stk8ba50_write_raw, 222 - .attrs = &stk8ba50_attribute_group, 125 + static const struct iio_trigger_ops stk8ba50_trigger_ops = { 126 + .set_trigger_state = stk8ba50_data_rdy_trigger_set_state, 127 + .owner = THIS_MODULE, 223 128 }; 224 129 225 130 static int stk8ba50_set_power(struct stk8ba50_data *data, bool mode) ··· 208 189 209 190 exit_err: 210 191 dev_err(&client->dev, "failed to change sensor mode\n"); 192 + return ret; 193 + } 194 + 195 + static int stk8ba50_read_raw(struct iio_dev *indio_dev, 196 + struct iio_chan_spec const *chan, 197 + int *val, int *val2, long mask) 198 + { 199 + struct stk8ba50_data *data = iio_priv(indio_dev); 200 + int ret; 201 + 202 + switch (mask) { 203 + case IIO_CHAN_INFO_RAW: 204 + if (iio_buffer_enabled(indio_dev)) 205 + return -EBUSY; 206 + mutex_lock(&data->lock); 207 + ret = stk8ba50_set_power(data, STK8BA50_MODE_NORMAL); 208 + if (ret < 0) { 209 + mutex_unlock(&data->lock); 210 + return -EINVAL; 211 + } 212 + ret = stk8ba50_read_accel(data, chan->address); 213 + if (ret < 0) { 214 + stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 215 + mutex_unlock(&data->lock); 216 + return -EINVAL; 217 + } 218 + *val = sign_extend32(ret >> STK8BA50_DATA_SHIFT, 9); 219 + stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 220 + mutex_unlock(&data->lock); 221 + return IIO_VAL_INT; 222 + case IIO_CHAN_INFO_SCALE: 223 + *val = 0; 224 + *val2 = stk8ba50_scale_table[data->range].scale_val; 225 + return IIO_VAL_INT_PLUS_MICRO; 226 + case IIO_CHAN_INFO_SAMP_FREQ: 227 + *val = stk8ba50_samp_freq_table 228 + [data->sample_rate_idx].samp_freq; 229 + *val2 = 0; 230 + return IIO_VAL_INT; 231 + } 232 + 233 + return -EINVAL; 234 + } 235 + 236 + static int stk8ba50_write_raw(struct iio_dev *indio_dev, 237 + struct iio_chan_spec const *chan, 238 + int val, int val2, long mask) 239 + { 240 + int ret; 241 + int i; 242 + int index = -1; 243 + struct stk8ba50_data *data = iio_priv(indio_dev); 244 + 245 + switch (mask) { 246 + case IIO_CHAN_INFO_SCALE: 247 + if (val != 0) 248 + return -EINVAL; 249 + 250 + for (i = 0; i < ARRAY_SIZE(stk8ba50_scale_table); i++) 251 + if (val2 == stk8ba50_scale_table[i].scale_val) { 252 + index = i; 253 + break; 254 + } 255 + if (index < 0) 256 + return -EINVAL; 257 + 258 + ret = i2c_smbus_write_byte_data(data->client, 259 + STK8BA50_REG_RANGE, 260 + stk8ba50_scale_table[index].reg_val); 261 + if (ret < 0) 262 + dev_err(&data->client->dev, 263 + "failed to set measurement range\n"); 264 + else 265 + data->range = index; 266 + 267 + return ret; 268 + case IIO_CHAN_INFO_SAMP_FREQ: 269 + for (i = 0; i < ARRAY_SIZE(stk8ba50_samp_freq_table); i++) 270 + if (val == stk8ba50_samp_freq_table[i].samp_freq) { 271 + index = i; 272 + break; 273 + } 274 + if (index < 0) 275 + return -EINVAL; 276 + 277 + ret = i2c_smbus_write_byte_data(data->client, 278 + STK8BA50_REG_BWSEL, 279 + stk8ba50_samp_freq_table[index].reg_val); 280 + if (ret < 0) 281 + dev_err(&data->client->dev, 282 + "failed to set sampling rate\n"); 283 + else 284 + data->sample_rate_idx = index; 285 + 286 + return ret; 287 + } 288 + 289 + return -EINVAL; 290 + } 291 + 292 + static const struct iio_info stk8ba50_info = { 293 + .driver_module = THIS_MODULE, 294 + .read_raw = stk8ba50_read_raw, 295 + .write_raw = stk8ba50_write_raw, 296 + .attrs = &stk8ba50_attribute_group, 297 + }; 298 + 299 + static irqreturn_t stk8ba50_trigger_handler(int irq, void *p) 300 + { 301 + struct iio_poll_func *pf = p; 302 + struct iio_dev *indio_dev = pf->indio_dev; 303 + struct stk8ba50_data *data = iio_priv(indio_dev); 304 + int bit, ret, i = 0; 305 + 306 + mutex_lock(&data->lock); 307 + /* 308 + * Do a bulk read if all channels are requested, 309 + * from 0x02 (XOUT1) to 0x07 (ZOUT2) 310 + */ 311 + if (*(indio_dev->active_scan_mask) == STK8BA50_ALL_CHANNEL_MASK) { 312 + ret = i2c_smbus_read_i2c_block_data(data->client, 313 + STK8BA50_REG_XOUT, 314 + STK8BA50_ALL_CHANNEL_SIZE, 315 + (u8 *)data->buffer); 316 + if (ret < STK8BA50_ALL_CHANNEL_SIZE) { 317 + dev_err(&data->client->dev, "register read failed\n"); 318 + goto err; 319 + } 320 + } else { 321 + for_each_set_bit(bit, indio_dev->active_scan_mask, 322 + indio_dev->masklength) { 323 + ret = stk8ba50_read_accel(data, 324 + stk8ba50_channel_table[bit]); 325 + if (ret < 0) 326 + goto err; 327 + 328 + data->buffer[i++] = ret; 329 + } 330 + } 331 + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 332 + pf->timestamp); 333 + err: 334 + mutex_unlock(&data->lock); 335 + iio_trigger_notify_done(indio_dev->trig); 336 + 337 + return IRQ_HANDLED; 338 + } 339 + 340 + static irqreturn_t stk8ba50_data_rdy_trig_poll(int irq, void *private) 341 + { 342 + struct iio_dev *indio_dev = private; 343 + struct stk8ba50_data *data = iio_priv(indio_dev); 344 + 345 + if (data->dready_trigger_on) 346 + iio_trigger_poll(data->dready_trig); 347 + 348 + return IRQ_HANDLED; 349 + } 350 + 351 + static int stk8ba50_buffer_preenable(struct iio_dev *indio_dev) 352 + { 353 + struct stk8ba50_data *data = iio_priv(indio_dev); 354 + 355 + return stk8ba50_set_power(data, STK8BA50_MODE_NORMAL); 356 + } 357 + 358 + static int stk8ba50_buffer_postdisable(struct iio_dev *indio_dev) 359 + { 360 + struct stk8ba50_data *data = iio_priv(indio_dev); 361 + 362 + return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 363 + } 364 + 365 + static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = { 366 + .preenable = stk8ba50_buffer_preenable, 367 + .postenable = iio_triggered_buffer_postenable, 368 + .predisable = iio_triggered_buffer_predisable, 369 + .postdisable = stk8ba50_buffer_postdisable, 370 + }; 371 + 372 + static int stk8ba50_gpio_probe(struct i2c_client *client) 373 + { 374 + struct device *dev; 375 + struct gpio_desc *gpio; 376 + int ret; 377 + 378 + if (!client) 379 + return -EINVAL; 380 + 381 + dev = &client->dev; 382 + 383 + /* data ready gpio interrupt pin */ 384 + gpio = devm_gpiod_get_index(dev, STK8BA50_GPIO, 0, GPIOD_IN); 385 + if (IS_ERR(gpio)) { 386 + dev_err(dev, "acpi gpio get index failed\n"); 387 + return PTR_ERR(gpio); 388 + } 389 + 390 + ret = gpiod_to_irq(gpio); 391 + dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); 392 + 211 393 return ret; 212 394 } 213 395 ··· 442 222 STK8BA50_REG_SWRST, STK8BA50_RESET_CMD); 443 223 if (ret < 0) { 444 224 dev_err(&client->dev, "failed to reset sensor\n"); 445 - return ret; 225 + goto err_power_off; 446 226 } 447 227 448 228 /* The default range is +/-2g */ 449 229 data->range = 0; 450 230 231 + /* The default sampling rate is 1792 Hz (maximum) */ 232 + data->sample_rate_idx = STK8BA50_SR_1792HZ_IDX; 233 + 234 + /* Set up interrupts */ 235 + ret = i2c_smbus_write_byte_data(client, 236 + STK8BA50_REG_INTEN2, STK8BA50_DREADY_INT_MASK); 237 + if (ret < 0) { 238 + dev_err(&client->dev, "failed to set up interrupts\n"); 239 + goto err_power_off; 240 + } 241 + ret = i2c_smbus_write_byte_data(client, 242 + STK8BA50_REG_INTMAP2, STK8BA50_DREADY_INT_MAP); 243 + if (ret < 0) { 244 + dev_err(&client->dev, "failed to set up interrupts\n"); 245 + goto err_power_off; 246 + } 247 + 248 + if (client->irq < 0) 249 + client->irq = stk8ba50_gpio_probe(client); 250 + 251 + if (client->irq >= 0) { 252 + ret = devm_request_threaded_irq(&client->dev, client->irq, 253 + stk8ba50_data_rdy_trig_poll, 254 + NULL, 255 + IRQF_TRIGGER_RISING | 256 + IRQF_ONESHOT, 257 + STK8BA50_IRQ_NAME, 258 + indio_dev); 259 + if (ret < 0) { 260 + dev_err(&client->dev, "request irq %d failed\n", 261 + client->irq); 262 + goto err_power_off; 263 + } 264 + 265 + data->dready_trig = devm_iio_trigger_alloc(&client->dev, 266 + "%s-dev%d", 267 + indio_dev->name, 268 + indio_dev->id); 269 + if (!data->dready_trig) { 270 + ret = -ENOMEM; 271 + goto err_power_off; 272 + } 273 + 274 + data->dready_trig->dev.parent = &client->dev; 275 + data->dready_trig->ops = &stk8ba50_trigger_ops; 276 + iio_trigger_set_drvdata(data->dready_trig, indio_dev); 277 + ret = iio_trigger_register(data->dready_trig); 278 + if (ret) { 279 + dev_err(&client->dev, "iio trigger register failed\n"); 280 + goto err_power_off; 281 + } 282 + } 283 + 284 + ret = iio_triggered_buffer_setup(indio_dev, 285 + iio_pollfunc_store_time, 286 + stk8ba50_trigger_handler, 287 + &stk8ba50_buffer_setup_ops); 288 + if (ret < 0) { 289 + dev_err(&client->dev, "iio triggered buffer setup failed\n"); 290 + goto err_trigger_unregister; 291 + } 292 + 451 293 ret = iio_device_register(indio_dev); 452 294 if (ret < 0) { 453 295 dev_err(&client->dev, "device_register failed\n"); 454 - stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 296 + goto err_buffer_cleanup; 455 297 } 456 298 299 + return ret; 300 + 301 + err_buffer_cleanup: 302 + iio_triggered_buffer_cleanup(indio_dev); 303 + err_trigger_unregister: 304 + if (data->dready_trig) 305 + iio_trigger_unregister(data->dready_trig); 306 + err_power_off: 307 + stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 457 308 return ret; 458 309 } 459 310 460 311 static int stk8ba50_remove(struct i2c_client *client) 461 312 { 462 313 struct iio_dev *indio_dev = i2c_get_clientdata(client); 314 + struct stk8ba50_data *data = iio_priv(indio_dev); 463 315 464 316 iio_device_unregister(indio_dev); 317 + iio_triggered_buffer_cleanup(indio_dev); 465 318 466 - return stk8ba50_set_power(iio_priv(indio_dev), STK8BA50_MODE_SUSPEND); 319 + if (data->dready_trig) 320 + iio_trigger_unregister(data->dready_trig); 321 + 322 + return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 467 323 } 468 324 469 325 #ifdef CONFIG_PM_SLEEP
+38 -10
drivers/iio/adc/Kconfig
··· 20 20 Say yes here to build support for Analog Devices AD7265 and AD7266 21 21 ADCs. 22 22 23 + To compile this driver as a module, choose M here: the module will be 24 + called ad7266. 25 + 23 26 config AD7291 24 27 tristate "Analog Devices AD7291 ADC driver" 25 28 depends on I2C ··· 55 52 AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, 56 53 AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC). 57 54 58 - If unsure, say N (but it's safe to say "Y"). 59 - 60 55 To compile this driver as a module, choose M here: the 61 56 module will be called ad7476. 62 57 ··· 64 63 select AD_SIGMA_DELTA 65 64 help 66 65 Say yes here to build support for Analog Devices AD7787, AD7788, AD7789, 67 - AD7790 and AD7791 SPI analog to digital converters (ADC). If unsure, say 68 - N (but it is safe to say "Y"). 66 + AD7790 and AD7791 SPI analog to digital converters (ADC). 69 67 70 68 To compile this driver as a module, choose M here: the module will be 71 69 called ad7791. ··· 76 76 help 77 77 Say yes here to build support for Analog Devices AD7785, AD7792, AD7793, 78 78 AD7794 and AD7795 SPI analog to digital converters (ADC). 79 - If unsure, say N (but it's safe to say "Y"). 80 79 81 80 To compile this driver as a module, choose M here: the 82 81 module will be called AD7793. ··· 88 89 help 89 90 Say yes here to build support for Analog Devices 90 91 AD7887 SPI analog to digital converter (ADC). 91 - If unsure, say N (but it's safe to say "Y"). 92 92 93 93 To compile this driver as a module, choose M here: the 94 94 module will be called ad7887. ··· 115 117 i2c analog to digital converters (ADC). Provides direct access 116 118 via sysfs. 117 119 120 + To compile this driver as a module, choose M here: the module will be 121 + called ad799x. 122 + 118 123 config AT91_ADC 119 124 tristate "Atmel AT91 ADC" 120 125 depends on ARCH_AT91 ··· 128 127 help 129 128 Say yes here to build support for Atmel AT91 ADC. 130 129 130 + To compile this driver as a module, choose M here: the module will be 131 + called at91_adc. 132 + 131 133 config AXP288_ADC 132 134 tristate "X-Powers AXP288 ADC driver" 133 135 depends on MFD_AXP20X ··· 138 134 Say yes here to have support for X-Powers power management IC (PMIC) ADC 139 135 device. Depending on platform configuration, this general purpose ADC can 140 136 be used for sampling sensors such as thermal resistors. 137 + 138 + To compile this driver as a module, choose M here: the module will be 139 + called axp288_adc. 141 140 142 141 config BERLIN2_ADC 143 142 tristate "Marvell Berlin2 ADC driver" ··· 157 150 158 151 This driver can also be built as a module. If chosen, the module name 159 152 will be da9150-gpadc. 153 + 154 + To compile this driver as a module, choose M here: the module will be 155 + called berlin2-adc. 160 156 161 157 config CC10001_ADC 162 158 tristate "Cosmic Circuits 10001 ADC driver" ··· 181 171 of SoCs for drivers such as the touchscreen and hwmon to use to share 182 172 this resource. 183 173 174 + To compile this driver as a module, choose M here: the module will be 175 + called exynos_adc. 176 + 184 177 config LP8788_ADC 185 178 tristate "LP8788 ADC driver" 186 179 depends on MFD_LP8788 187 180 help 188 181 Say yes here to build support for TI LP8788 ADC. 182 + 183 + To compile this driver as a module, choose M here: the module will be 184 + called lp8788_adc. 189 185 190 186 config MAX1027 191 187 tristate "Maxim max1027 ADC driver" ··· 201 185 help 202 186 Say yes here to build support for Maxim SPI ADC models 203 187 max1027, max1029 and max1031. 188 + 189 + To compile this driver as a module, choose M here: the module will be 190 + called max1027. 204 191 205 192 config MAX1363 206 193 tristate "Maxim max1363 ADC driver" ··· 220 201 max11614, max11615, max11616, max11617, max11644, max11645, 221 202 max11646, max11647) Provides direct access via sysfs and buffered 222 203 data via the iio dev interface. 204 + 205 + To compile this driver as a module, choose M here: the module will be 206 + called max1363. 223 207 224 208 config MCP320X 225 209 tristate "Microchip Technology MCP3x01/02/04/08" ··· 332 310 Say yes here to build support for Texas Instruments ADC 333 311 driver which is also a MFD client. 334 312 313 + To compile this driver as a module, choose M here: the module will be 314 + called ti_am335x_adc. 315 + 335 316 config TWL4030_MADC 336 317 tristate "TWL4030 MADC (Monitoring A/D Converter)" 337 318 depends on TWL4030_CORE 338 319 help 339 - This driver provides support for Triton TWL4030-MADC. The 340 - driver supports both RT and SW conversion methods. 320 + This driver provides support for Triton TWL4030-MADC. The 321 + driver supports both RT and SW conversion methods. 341 322 342 - This driver can also be built as a module. If so, the module will be 343 - called twl4030-madc. 323 + This driver can also be built as a module. If so, the module will be 324 + called twl4030-madc. 344 325 345 326 config TWL6030_GPADC 346 327 tristate "TWL6030 GPADC (General Purpose A/D Converter) Support" ··· 375 350 help 376 351 Say yes here to access the ADC part of the Nano River 377 352 Technologies Viperboard. 353 + 354 + To compile this driver as a module, choose M here: the module will be 355 + called viperboard_adc. 378 356 379 357 config XILINX_XADC 380 358 tristate "Xilinx XADC driver"
+21 -5
drivers/iio/adc/cc10001_adc.c
··· 62 62 struct regulator *reg; 63 63 u16 *buf; 64 64 65 + bool shared; 65 66 struct mutex lock; 66 67 unsigned int start_delay_ns; 67 68 unsigned int eoc_delay_ns; ··· 154 153 155 154 mutex_lock(&adc_dev->lock); 156 155 157 - cc10001_adc_power_up(adc_dev); 156 + if (!adc_dev->shared) 157 + cc10001_adc_power_up(adc_dev); 158 158 159 159 /* Calculate delay step for eoc and sampled data */ 160 160 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; ··· 179 177 } 180 178 181 179 done: 182 - cc10001_adc_power_down(adc_dev); 180 + if (!adc_dev->shared) 181 + cc10001_adc_power_down(adc_dev); 183 182 184 183 mutex_unlock(&adc_dev->lock); 185 184 ··· 199 196 unsigned int delay_ns; 200 197 u16 val; 201 198 202 - cc10001_adc_power_up(adc_dev); 199 + if (!adc_dev->shared) 200 + cc10001_adc_power_up(adc_dev); 203 201 204 202 /* Calculate delay step for eoc and sampled data */ 205 203 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; ··· 209 205 210 206 val = cc10001_adc_poll_done(indio_dev, chan->channel, delay_ns); 211 207 212 - cc10001_adc_power_down(adc_dev); 208 + if (!adc_dev->shared) 209 + cc10001_adc_power_down(adc_dev); 213 210 214 211 return val; 215 212 } ··· 327 322 adc_dev = iio_priv(indio_dev); 328 323 329 324 channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0); 330 - if (!of_property_read_u32(node, "adc-reserved-channels", &ret)) 325 + if (!of_property_read_u32(node, "adc-reserved-channels", &ret)) { 326 + adc_dev->shared = true; 331 327 channel_map &= ~ret; 328 + } 332 329 333 330 adc_dev->reg = devm_regulator_get(&pdev->dev, "vref"); 334 331 if (IS_ERR(adc_dev->reg)) ··· 375 368 adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate; 376 369 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES; 377 370 371 + /* 372 + * There is only one register to power-up/power-down the AUX ADC. 373 + * If the ADC is shared among multiple CPUs, always power it up here. 374 + * If the ADC is used only by the MIPS, power-up/power-down at runtime. 375 + */ 376 + if (adc_dev->shared) 377 + cc10001_adc_power_up(adc_dev); 378 + 378 379 /* Setup the ADC channels available on the device */ 379 380 ret = cc10001_adc_channel_init(indio_dev, channel_map); 380 381 if (ret < 0) ··· 417 402 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 418 403 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev); 419 404 405 + cc10001_adc_power_down(adc_dev); 420 406 iio_device_unregister(indio_dev); 421 407 iio_triggered_buffer_cleanup(indio_dev); 422 408 clk_disable_unprepare(adc_dev->adc_clk);
-1
drivers/iio/adc/mcp3422.c
··· 404 404 static struct i2c_driver mcp3422_driver = { 405 405 .driver = { 406 406 .name = "mcp3422", 407 - .owner = THIS_MODULE, 408 407 .of_match_table = of_match_ptr(mcp3422_of_match), 409 408 }, 410 409 .probe = mcp3422_probe,
-1
drivers/iio/adc/ti-adc081c.c
··· 140 140 static struct i2c_driver adc081c_driver = { 141 141 .driver = { 142 142 .name = "adc081c", 143 - .owner = THIS_MODULE, 144 143 .of_match_table = of_match_ptr(adc081c_of_match), 145 144 }, 146 145 .probe = adc081c_probe,
-1
drivers/iio/common/ssp_sensors/ssp_dev.c
··· 700 700 .remove = ssp_remove, 701 701 .driver = { 702 702 .pm = &ssp_pm_ops, 703 - .bus = &spi_bus_type, 704 703 .owner = THIS_MODULE, 705 704 .of_match_table = of_match_ptr(ssp_of_match), 706 705 .name = "sensorhub"
-1
drivers/iio/dac/ad5064.c
··· 630 630 static struct i2c_driver ad5064_i2c_driver = { 631 631 .driver = { 632 632 .name = "ad5064", 633 - .owner = THIS_MODULE, 634 633 }, 635 634 .probe = ad5064_i2c_probe, 636 635 .remove = ad5064_i2c_remove,
-1
drivers/iio/dac/ad5380.c
··· 593 593 static struct i2c_driver ad5380_i2c_driver = { 594 594 .driver = { 595 595 .name = "ad5380", 596 - .owner = THIS_MODULE, 597 596 }, 598 597 .probe = ad5380_i2c_probe, 599 598 .remove = ad5380_i2c_remove,
-1
drivers/iio/dac/ad5446.c
··· 569 569 static struct i2c_driver ad5446_i2c_driver = { 570 570 .driver = { 571 571 .name = "ad5446", 572 - .owner = THIS_MODULE, 573 572 }, 574 573 .probe = ad5446_i2c_probe, 575 574 .remove = ad5446_i2c_remove,
-1
drivers/iio/dac/max5821.c
··· 392 392 .driver = { 393 393 .name = "max5821", 394 394 .pm = MAX5821_PM_OPS, 395 - .owner = THIS_MODULE, 396 395 }, 397 396 .probe = max5821_probe, 398 397 .remove = max5821_remove,
-1
drivers/iio/frequency/adf4350.c
··· 72 72 for (i = ADF4350_REG5; i >= ADF4350_REG0; i--) { 73 73 if ((st->regs_hw[i] != st->regs[i]) || 74 74 ((i == ADF4350_REG0) && doublebuf)) { 75 - 76 75 switch (i) { 77 76 case ADF4350_REG1: 78 77 case ADF4350_REG4:
-1
drivers/iio/gyro/itg3200_core.c
··· 379 379 380 380 static struct i2c_driver itg3200_driver = { 381 381 .driver = { 382 - .owner = THIS_MODULE, 383 382 .name = "itg3200", 384 383 .pm = &itg3200_pm_ops, 385 384 },
-1
drivers/iio/gyro/st_gyro_i2c.c
··· 99 99 100 100 static struct i2c_driver st_gyro_driver = { 101 101 .driver = { 102 - .owner = THIS_MODULE, 103 102 .name = "st-gyro-i2c", 104 103 .of_match_table = of_match_ptr(st_gyro_of_match), 105 104 },
-1
drivers/iio/humidity/si7005.c
··· 177 177 static struct i2c_driver si7005_driver = { 178 178 .driver = { 179 179 .name = "si7005", 180 - .owner = THIS_MODULE, 181 180 }, 182 181 .probe = si7005_probe, 183 182 .id_table = si7005_id,
+6 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 673 673 674 674 /* constant IIO attribute */ 675 675 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 20 50 100 200 500"); 676 + static IIO_CONST_ATTR(in_anglvel_scale_available, 677 + "0.000133090 0.000266181 0.000532362 0.001064724"); 678 + static IIO_CONST_ATTR(in_accel_scale_available, 679 + "0.000598 0.001196 0.002392 0.004785"); 676 680 static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, inv_fifo_rate_show, 677 681 inv_mpu6050_fifo_rate_store); 678 682 static IIO_DEVICE_ATTR(in_gyro_matrix, S_IRUGO, inv_attr_show, NULL, ··· 689 685 &iio_dev_attr_in_accel_matrix.dev_attr.attr, 690 686 &iio_dev_attr_sampling_frequency.dev_attr.attr, 691 687 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 688 + &iio_const_attr_in_accel_scale_available.dev_attr.attr, 689 + &iio_const_attr_in_anglvel_scale_available.dev_attr.attr, 692 690 NULL, 693 691 }; 694 692 ··· 909 903 .remove = inv_mpu_remove, 910 904 .id_table = inv_mpu_id, 911 905 .driver = { 912 - .owner = THIS_MODULE, 913 906 .name = "inv-mpu6050", 914 907 .pm = INV_MPU6050_PMOPS, 915 908 .acpi_match_table = ACPI_PTR(inv_acpi_match),
+9 -9
drivers/iio/industrialio-buffer.c
··· 71 71 72 72 if (avail >= to_wait) { 73 73 /* force a flush for non-blocking reads */ 74 - if (!to_wait && !avail && to_flush) 75 - iio_buffer_flush_hwfifo(indio_dev, buf, to_flush); 74 + if (!to_wait && avail < to_flush) 75 + iio_buffer_flush_hwfifo(indio_dev, buf, 76 + to_flush - avail); 76 77 return true; 77 78 } 78 79 ··· 101 100 struct iio_dev *indio_dev = filp->private_data; 102 101 struct iio_buffer *rb = indio_dev->buffer; 103 102 size_t datum_size; 104 - size_t to_wait = 0; 105 - size_t to_read; 103 + size_t to_wait; 106 104 int ret; 107 105 108 106 if (!indio_dev->info) ··· 119 119 if (!datum_size) 120 120 return 0; 121 121 122 - to_read = min_t(size_t, n / datum_size, rb->watermark); 123 - 124 - if (!(filp->f_flags & O_NONBLOCK)) 125 - to_wait = to_read; 122 + if (filp->f_flags & O_NONBLOCK) 123 + to_wait = 0; 124 + else 125 + to_wait = min_t(size_t, n / datum_size, rb->watermark); 126 126 127 127 do { 128 128 ret = wait_event_interruptible(rb->pollq, 129 - iio_buffer_ready(indio_dev, rb, to_wait, to_read)); 129 + iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size)); 130 130 if (ret) 131 131 return ret; 132 132
+8
drivers/iio/industrialio-core.c
··· 81 81 [IIO_MOD_X] = "x", 82 82 [IIO_MOD_Y] = "y", 83 83 [IIO_MOD_Z] = "z", 84 + [IIO_MOD_X_AND_Y] = "x&y", 85 + [IIO_MOD_X_AND_Z] = "x&z", 86 + [IIO_MOD_Y_AND_Z] = "y&z", 87 + [IIO_MOD_X_AND_Y_AND_Z] = "x&y&z", 88 + [IIO_MOD_X_OR_Y] = "x|y", 89 + [IIO_MOD_X_OR_Z] = "x|z", 90 + [IIO_MOD_Y_OR_Z] = "y|z", 91 + [IIO_MOD_X_OR_Y_OR_Z] = "x|y|z", 84 92 [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)", 85 93 [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2", 86 94 [IIO_MOD_LIGHT_BOTH] = "both",
+6 -6
drivers/iio/industrialio-triggered-buffer.c
··· 24 24 /** 25 25 * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc 26 26 * @indio_dev: IIO device structure 27 - * @pollfunc_bh: Function which will be used as pollfunc bottom half 28 - * @pollfunc_th: Function which will be used as pollfunc top half 27 + * @h: Function which will be used as pollfunc top half 28 + * @thread: Function which will be used as pollfunc bottom half 29 29 * @setup_ops: Buffer setup functions to use for this device. 30 30 * If NULL the default setup functions for triggered 31 31 * buffers will be used. ··· 42 42 * iio_triggered_buffer_cleanup(). 43 43 */ 44 44 int iio_triggered_buffer_setup(struct iio_dev *indio_dev, 45 - irqreturn_t (*pollfunc_bh)(int irq, void *p), 46 - irqreturn_t (*pollfunc_th)(int irq, void *p), 45 + irqreturn_t (*h)(int irq, void *p), 46 + irqreturn_t (*thread)(int irq, void *p), 47 47 const struct iio_buffer_setup_ops *setup_ops) 48 48 { 49 49 struct iio_buffer *buffer; ··· 57 57 58 58 iio_device_attach_buffer(indio_dev, buffer); 59 59 60 - indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh, 61 - pollfunc_th, 60 + indio_dev->pollfunc = iio_alloc_pollfunc(h, 61 + thread, 62 62 IRQF_ONESHOT, 63 63 indio_dev, 64 64 "%s_consumer%d",
+12 -1
drivers/iio/light/Kconfig
··· 86 86 depends on I2C 87 87 tristate "Capella CM3323 color light sensor" 88 88 help 89 - Say Y here if you want to build a driver for Capela CM3323 89 + Say Y here if you want to build a driver for Capella CM3323 90 90 color sensor. 91 91 92 92 To compile this driver as a module, choose M here: the module will ··· 167 167 168 168 To compile this driver as a module, choose M here: 169 169 the module will be called jsa1212. 170 + 171 + config RPR0521 172 + tristate "ROHM RPR0521 ALS and proximity sensor driver" 173 + depends on I2C 174 + select REGMAP_I2C 175 + help 176 + Say Y here if you want to build support for ROHM's RPR0521 177 + ambient light and proximity sensor device. 178 + 179 + To compile this driver as a module, choose M here: 180 + the module will be called rpr0521. 170 181 171 182 config SENSORS_LM3533 172 183 tristate "LM3533 ambient light sensor"
+1
drivers/iio/light/Makefile
··· 19 19 obj-$(CONFIG_JSA1212) += jsa1212.o 20 20 obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o 21 21 obj-$(CONFIG_LTR501) += ltr501.o 22 + obj-$(CONFIG_RPR0521) += rpr0521.o 22 23 obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o 23 24 obj-$(CONFIG_STK3310) += stk3310.o 24 25 obj-$(CONFIG_TCS3414) += tcs3414.o
-1
drivers/iio/light/apds9300.c
··· 515 515 static struct i2c_driver apds9300_driver = { 516 516 .driver = { 517 517 .name = APDS9300_DRV_NAME, 518 - .owner = THIS_MODULE, 519 518 .pm = APDS9300_PM_OPS, 520 519 }, 521 520 .probe = apds9300_probe,
-1
drivers/iio/light/bh1750.c
··· 319 319 static struct i2c_driver bh1750_driver = { 320 320 .driver = { 321 321 .name = "bh1750", 322 - .owner = THIS_MODULE, 323 322 .pm = BH1750_PM_OPS, 324 323 }, 325 324 .probe = bh1750_probe,
-1
drivers/iio/light/cm32181.c
··· 358 358 .driver = { 359 359 .name = "cm32181", 360 360 .of_match_table = of_match_ptr(cm32181_of_match), 361 - .owner = THIS_MODULE, 362 361 }, 363 362 .id_table = cm32181_id, 364 363 .probe = cm32181_probe,
-1
drivers/iio/light/cm3232.c
··· 421 421 static struct i2c_driver cm3232_driver = { 422 422 .driver = { 423 423 .name = "cm3232", 424 - .owner = THIS_MODULE, 425 424 .of_match_table = of_match_ptr(cm3232_of_match), 426 425 #ifdef CONFIG_PM_SLEEP 427 426 .pm = &cm3232_pm_ops,
+12 -7
drivers/iio/light/cm3323.c
··· 29 29 30 30 #define CM3323_CONF_SD_BIT BIT(0) /* sensor disable */ 31 31 #define CM3323_CONF_AF_BIT BIT(1) /* auto/manual force mode */ 32 - #define CM3323_CONF_IT_MASK (BIT(4) | BIT(5) | BIT(6)) 32 + #define CM3323_CONF_IT_MASK GENMASK(6, 4) 33 33 #define CM3323_CONF_IT_SHIFT 4 34 34 35 35 #define CM3323_INT_TIME_AVAILABLE "0.04 0.08 0.16 0.32 0.64 1.28" ··· 133 133 return ret; 134 134 135 135 data->reg_conf = reg_conf; 136 + 136 137 return 0; 137 138 } 138 139 } 140 + 139 141 return -EINVAL; 140 142 } 141 143 ··· 150 148 151 149 if (bits >= ARRAY_SIZE(cm3323_int_time)) 152 150 return -EINVAL; 151 + 153 152 return bits; 154 153 } 155 154 ··· 158 155 struct iio_chan_spec const *chan, int *val, 159 156 int *val2, long mask) 160 157 { 161 - int i, ret; 158 + int ret; 162 159 struct cm3323_data *data = iio_priv(indio_dev); 163 160 164 161 switch (mask) { ··· 175 172 return IIO_VAL_INT; 176 173 case IIO_CHAN_INFO_INT_TIME: 177 174 mutex_lock(&data->mutex); 178 - i = cm3323_get_it_bits(data); 179 - if (i < 0) { 175 + ret = cm3323_get_it_bits(data); 176 + if (ret < 0) { 180 177 mutex_unlock(&data->mutex); 181 - return -EINVAL; 178 + return ret; 182 179 } 183 180 184 - *val = cm3323_int_time[i].val; 185 - *val2 = cm3323_int_time[i].val2; 181 + *val = cm3323_int_time[ret].val; 182 + *val2 = cm3323_int_time[ret].val2; 186 183 mutex_unlock(&data->mutex); 187 184 188 185 return IIO_VAL_INT_PLUS_MICRO; ··· 246 243 dev_err(&client->dev, "cm3323 chip init failed\n"); 247 244 return ret; 248 245 } 246 + 249 247 ret = iio_device_register(indio_dev); 250 248 if (ret < 0) { 251 249 dev_err(&client->dev, "failed to register iio dev\n"); 252 250 goto err_init; 253 251 } 252 + 254 253 return 0; 255 254 err_init: 256 255 cm3323_disable(indio_dev);
-1
drivers/iio/light/cm36651.c
··· 736 736 .driver = { 737 737 .name = "cm36651", 738 738 .of_match_table = cm36651_of_match, 739 - .owner = THIS_MODULE, 740 739 }, 741 740 .probe = cm36651_probe, 742 741 .remove = cm36651_remove,
-1
drivers/iio/light/gp2ap020a00f.c
··· 1640 1640 .driver = { 1641 1641 .name = GP2A_I2C_NAME, 1642 1642 .of_match_table = of_match_ptr(gp2ap020a00f_of_match), 1643 - .owner = THIS_MODULE, 1644 1643 }, 1645 1644 .probe = gp2ap020a00f_probe, 1646 1645 .remove = gp2ap020a00f_remove,
+1 -2
drivers/iio/light/hid-sensor-prox.c
··· 284 284 goto error_free_dev_mem; 285 285 } 286 286 287 - indio_dev->num_channels = 288 - ARRAY_SIZE(prox_channels); 287 + indio_dev->num_channels = ARRAY_SIZE(prox_channels); 289 288 indio_dev->dev.parent = &pdev->dev; 290 289 indio_dev->info = &prox_info; 291 290 indio_dev->name = name;
+12 -1
drivers/iio/light/isl29125.c
··· 197 197 return IRQ_HANDLED; 198 198 } 199 199 200 + static IIO_CONST_ATTR(scale_available, "0.005722 0.152590"); 201 + 202 + static struct attribute *isl29125_attributes[] = { 203 + &iio_const_attr_scale_available.dev_attr.attr, 204 + NULL 205 + }; 206 + 207 + static const struct attribute_group isl29125_attribute_group = { 208 + .attrs = isl29125_attributes, 209 + }; 210 + 200 211 static const struct iio_info isl29125_info = { 201 212 .read_raw = isl29125_read_raw, 202 213 .write_raw = isl29125_write_raw, 214 + .attrs = &isl29125_attribute_group, 203 215 .driver_module = THIS_MODULE, 204 216 }; 205 217 ··· 346 334 .driver = { 347 335 .name = ISL29125_DRV_NAME, 348 336 .pm = &isl29125_pm_ops, 349 - .owner = THIS_MODULE, 350 337 }, 351 338 .probe = isl29125_probe, 352 339 .remove = isl29125_remove,
-1
drivers/iio/light/jsa1212.c
··· 457 457 .driver = { 458 458 .name = JSA1212_DRIVER_NAME, 459 459 .pm = JSA1212_PM_OPS, 460 - .owner = THIS_MODULE, 461 460 .acpi_match_table = ACPI_PTR(jsa1212_acpi_match), 462 461 }, 463 462 .probe = jsa1212_probe,
-1
drivers/iio/light/ltr501.c
··· 1551 1551 .name = LTR501_DRV_NAME, 1552 1552 .pm = &ltr501_pm_ops, 1553 1553 .acpi_match_table = ACPI_PTR(ltr_acpi_match), 1554 - .owner = THIS_MODULE, 1555 1554 }, 1556 1555 .probe = ltr501_probe, 1557 1556 .remove = ltr501_remove,
+615
drivers/iio/light/rpr0521.c
··· 1 + /* 2 + * RPR-0521 ROHM Ambient Light and Proximity Sensor 3 + * 4 + * Copyright (c) 2015, Intel Corporation. 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + * 10 + * IIO driver for RPR-0521RS (7-bit I2C slave address 0x38). 11 + * 12 + * TODO: illuminance channel, PM support, buffer 13 + */ 14 + 15 + #include <linux/module.h> 16 + #include <linux/init.h> 17 + #include <linux/i2c.h> 18 + #include <linux/regmap.h> 19 + #include <linux/delay.h> 20 + #include <linux/acpi.h> 21 + 22 + #include <linux/iio/iio.h> 23 + #include <linux/iio/sysfs.h> 24 + #include <linux/pm_runtime.h> 25 + 26 + #define RPR0521_REG_SYSTEM_CTRL 0x40 27 + #define RPR0521_REG_MODE_CTRL 0x41 28 + #define RPR0521_REG_ALS_CTRL 0x42 29 + #define RPR0521_REG_PXS_CTRL 0x43 30 + #define RPR0521_REG_PXS_DATA 0x44 /* 16-bit, little endian */ 31 + #define RPR0521_REG_ALS_DATA0 0x46 /* 16-bit, little endian */ 32 + #define RPR0521_REG_ALS_DATA1 0x48 /* 16-bit, little endian */ 33 + #define RPR0521_REG_ID 0x92 34 + 35 + #define RPR0521_MODE_ALS_MASK BIT(7) 36 + #define RPR0521_MODE_PXS_MASK BIT(6) 37 + #define RPR0521_MODE_MEAS_TIME_MASK GENMASK(3, 0) 38 + #define RPR0521_ALS_DATA0_GAIN_MASK GENMASK(5, 4) 39 + #define RPR0521_ALS_DATA0_GAIN_SHIFT 4 40 + #define RPR0521_ALS_DATA1_GAIN_MASK GENMASK(3, 2) 41 + #define RPR0521_ALS_DATA1_GAIN_SHIFT 2 42 + #define RPR0521_PXS_GAIN_MASK GENMASK(5, 4) 43 + #define RPR0521_PXS_GAIN_SHIFT 4 44 + 45 + #define RPR0521_MODE_ALS_ENABLE BIT(7) 46 + #define RPR0521_MODE_ALS_DISABLE 0x00 47 + #define RPR0521_MODE_PXS_ENABLE BIT(6) 48 + #define RPR0521_MODE_PXS_DISABLE 0x00 49 + 50 + #define RPR0521_MANUFACT_ID 0xE0 51 + #define RPR0521_DEFAULT_MEAS_TIME 0x06 /* ALS - 100ms, PXS - 100ms */ 52 + 53 + #define RPR0521_DRV_NAME "RPR0521" 54 + #define RPR0521_REGMAP_NAME "rpr0521_regmap" 55 + 56 + #define RPR0521_SLEEP_DELAY_MS 2000 57 + 58 + #define RPR0521_ALS_SCALE_AVAIL "0.007812 0.015625 0.5 1" 59 + #define RPR0521_PXS_SCALE_AVAIL "0.125 0.5 1" 60 + 61 + struct rpr0521_gain { 62 + int scale; 63 + int uscale; 64 + }; 65 + 66 + static const struct rpr0521_gain rpr0521_als_gain[4] = { 67 + {1, 0}, /* x1 */ 68 + {0, 500000}, /* x2 */ 69 + {0, 15625}, /* x64 */ 70 + {0, 7812}, /* x128 */ 71 + }; 72 + 73 + static const struct rpr0521_gain rpr0521_pxs_gain[3] = { 74 + {1, 0}, /* x1 */ 75 + {0, 500000}, /* x2 */ 76 + {0, 125000}, /* x4 */ 77 + }; 78 + 79 + enum rpr0521_channel { 80 + RPR0521_CHAN_ALS_DATA0, 81 + RPR0521_CHAN_ALS_DATA1, 82 + RPR0521_CHAN_PXS, 83 + }; 84 + 85 + struct rpr0521_reg_desc { 86 + u8 address; 87 + u8 device_mask; 88 + }; 89 + 90 + static const struct rpr0521_reg_desc rpr0521_data_reg[] = { 91 + [RPR0521_CHAN_ALS_DATA0] = { 92 + .address = RPR0521_REG_ALS_DATA0, 93 + .device_mask = RPR0521_MODE_ALS_MASK, 94 + }, 95 + [RPR0521_CHAN_ALS_DATA1] = { 96 + .address = RPR0521_REG_ALS_DATA1, 97 + .device_mask = RPR0521_MODE_ALS_MASK, 98 + }, 99 + [RPR0521_CHAN_PXS] = { 100 + .address = RPR0521_REG_PXS_DATA, 101 + .device_mask = RPR0521_MODE_PXS_MASK, 102 + }, 103 + }; 104 + 105 + static const struct rpr0521_gain_info { 106 + u8 reg; 107 + u8 mask; 108 + u8 shift; 109 + const struct rpr0521_gain *gain; 110 + int size; 111 + } rpr0521_gain[] = { 112 + [RPR0521_CHAN_ALS_DATA0] = { 113 + .reg = RPR0521_REG_ALS_CTRL, 114 + .mask = RPR0521_ALS_DATA0_GAIN_MASK, 115 + .shift = RPR0521_ALS_DATA0_GAIN_SHIFT, 116 + .gain = rpr0521_als_gain, 117 + .size = ARRAY_SIZE(rpr0521_als_gain), 118 + }, 119 + [RPR0521_CHAN_ALS_DATA1] = { 120 + .reg = RPR0521_REG_ALS_CTRL, 121 + .mask = RPR0521_ALS_DATA1_GAIN_MASK, 122 + .shift = RPR0521_ALS_DATA1_GAIN_SHIFT, 123 + .gain = rpr0521_als_gain, 124 + .size = ARRAY_SIZE(rpr0521_als_gain), 125 + }, 126 + [RPR0521_CHAN_PXS] = { 127 + .reg = RPR0521_REG_PXS_CTRL, 128 + .mask = RPR0521_PXS_GAIN_MASK, 129 + .shift = RPR0521_PXS_GAIN_SHIFT, 130 + .gain = rpr0521_pxs_gain, 131 + .size = ARRAY_SIZE(rpr0521_pxs_gain), 132 + }, 133 + }; 134 + 135 + struct rpr0521_data { 136 + struct i2c_client *client; 137 + 138 + /* protect device params updates (e.g state, gain) */ 139 + struct mutex lock; 140 + 141 + /* device active status */ 142 + bool als_dev_en; 143 + bool pxs_dev_en; 144 + 145 + /* optimize runtime pm ops - enable device only if needed */ 146 + bool als_ps_need_en; 147 + bool pxs_ps_need_en; 148 + 149 + struct regmap *regmap; 150 + }; 151 + 152 + static IIO_CONST_ATTR(in_intensity_scale_available, RPR0521_ALS_SCALE_AVAIL); 153 + static IIO_CONST_ATTR(in_proximity_scale_available, RPR0521_PXS_SCALE_AVAIL); 154 + 155 + static struct attribute *rpr0521_attributes[] = { 156 + &iio_const_attr_in_intensity_scale_available.dev_attr.attr, 157 + &iio_const_attr_in_proximity_scale_available.dev_attr.attr, 158 + NULL, 159 + }; 160 + 161 + static const struct attribute_group rpr0521_attribute_group = { 162 + .attrs = rpr0521_attributes, 163 + }; 164 + 165 + static const struct iio_chan_spec rpr0521_channels[] = { 166 + { 167 + .type = IIO_INTENSITY, 168 + .modified = 1, 169 + .address = RPR0521_CHAN_ALS_DATA0, 170 + .channel2 = IIO_MOD_LIGHT_BOTH, 171 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 172 + BIT(IIO_CHAN_INFO_SCALE), 173 + }, 174 + { 175 + .type = IIO_INTENSITY, 176 + .modified = 1, 177 + .address = RPR0521_CHAN_ALS_DATA1, 178 + .channel2 = IIO_MOD_LIGHT_IR, 179 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 180 + BIT(IIO_CHAN_INFO_SCALE), 181 + }, 182 + { 183 + .type = IIO_PROXIMITY, 184 + .address = RPR0521_CHAN_PXS, 185 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 186 + BIT(IIO_CHAN_INFO_SCALE), 187 + } 188 + }; 189 + 190 + static int rpr0521_als_enable(struct rpr0521_data *data, u8 status) 191 + { 192 + int ret; 193 + 194 + ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL, 195 + RPR0521_MODE_ALS_MASK, 196 + status); 197 + if (ret < 0) 198 + return ret; 199 + 200 + data->als_dev_en = true; 201 + 202 + return 0; 203 + } 204 + 205 + static int rpr0521_pxs_enable(struct rpr0521_data *data, u8 status) 206 + { 207 + int ret; 208 + 209 + ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL, 210 + RPR0521_MODE_PXS_MASK, 211 + status); 212 + if (ret < 0) 213 + return ret; 214 + 215 + data->pxs_dev_en = true; 216 + 217 + return 0; 218 + } 219 + 220 + /** 221 + * rpr0521_set_power_state - handles runtime PM state and sensors enabled status 222 + * 223 + * @data: rpr0521 device private data 224 + * @on: state to be set for devices in @device_mask 225 + * @device_mask: bitmask specifying for which device we need to update @on state 226 + * 227 + * We rely on rpr0521_runtime_resume to enable our @device_mask devices, but 228 + * if (for example) PXS was enabled (pxs_dev_en = true) by a previous call to 229 + * rpr0521_runtime_resume and we want to enable ALS we MUST set ALS enable 230 + * bit of RPR0521_REG_MODE_CTRL here because rpr0521_runtime_resume will not 231 + * be called twice. 232 + */ 233 + static int rpr0521_set_power_state(struct rpr0521_data *data, bool on, 234 + u8 device_mask) 235 + { 236 + #ifdef CONFIG_PM 237 + int ret; 238 + u8 update_mask = 0; 239 + 240 + if (device_mask & RPR0521_MODE_ALS_MASK) { 241 + if (on && !data->als_ps_need_en && data->pxs_dev_en) 242 + update_mask |= RPR0521_MODE_ALS_MASK; 243 + else 244 + data->als_ps_need_en = on; 245 + } 246 + 247 + if (device_mask & RPR0521_MODE_PXS_MASK) { 248 + if (on && !data->pxs_ps_need_en && data->als_dev_en) 249 + update_mask |= RPR0521_MODE_PXS_MASK; 250 + else 251 + data->pxs_ps_need_en = on; 252 + } 253 + 254 + if (update_mask) { 255 + ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL, 256 + update_mask, update_mask); 257 + if (ret < 0) 258 + return ret; 259 + } 260 + 261 + if (on) { 262 + ret = pm_runtime_get_sync(&data->client->dev); 263 + } else { 264 + pm_runtime_mark_last_busy(&data->client->dev); 265 + ret = pm_runtime_put_autosuspend(&data->client->dev); 266 + } 267 + if (ret < 0) { 268 + dev_err(&data->client->dev, 269 + "Failed: rpr0521_set_power_state for %d, ret %d\n", 270 + on, ret); 271 + if (on) 272 + pm_runtime_put_noidle(&data->client->dev); 273 + 274 + return ret; 275 + } 276 + #endif 277 + return 0; 278 + } 279 + 280 + static int rpr0521_get_gain(struct rpr0521_data *data, int chan, 281 + int *val, int *val2) 282 + { 283 + int ret, reg, idx; 284 + 285 + ret = regmap_read(data->regmap, rpr0521_gain[chan].reg, &reg); 286 + if (ret < 0) 287 + return ret; 288 + 289 + idx = (rpr0521_gain[chan].mask & reg) >> rpr0521_gain[chan].shift; 290 + *val = rpr0521_gain[chan].gain[idx].scale; 291 + *val2 = rpr0521_gain[chan].gain[idx].uscale; 292 + 293 + return 0; 294 + } 295 + 296 + static int rpr0521_set_gain(struct rpr0521_data *data, int chan, 297 + int val, int val2) 298 + { 299 + int i, idx = -EINVAL; 300 + 301 + /* get gain index */ 302 + for (i = 0; i < rpr0521_gain[chan].size; i++) 303 + if (val == rpr0521_gain[chan].gain[i].scale && 304 + val2 == rpr0521_gain[chan].gain[i].uscale) { 305 + idx = i; 306 + break; 307 + } 308 + 309 + if (idx < 0) 310 + return idx; 311 + 312 + return regmap_update_bits(data->regmap, rpr0521_gain[chan].reg, 313 + rpr0521_gain[chan].mask, 314 + idx << rpr0521_gain[chan].shift); 315 + } 316 + 317 + static int rpr0521_read_raw(struct iio_dev *indio_dev, 318 + struct iio_chan_spec const *chan, int *val, 319 + int *val2, long mask) 320 + { 321 + struct rpr0521_data *data = iio_priv(indio_dev); 322 + int ret; 323 + u8 device_mask; 324 + __le16 raw_data; 325 + 326 + switch (mask) { 327 + case IIO_CHAN_INFO_RAW: 328 + if (chan->type != IIO_INTENSITY && chan->type != IIO_PROXIMITY) 329 + return -EINVAL; 330 + 331 + device_mask = rpr0521_data_reg[chan->address].device_mask; 332 + 333 + mutex_lock(&data->lock); 334 + ret = rpr0521_set_power_state(data, true, device_mask); 335 + if (ret < 0) { 336 + mutex_unlock(&data->lock); 337 + return ret; 338 + } 339 + 340 + ret = regmap_bulk_read(data->regmap, 341 + rpr0521_data_reg[chan->address].address, 342 + &raw_data, 2); 343 + if (ret < 0) { 344 + rpr0521_set_power_state(data, false, device_mask); 345 + mutex_unlock(&data->lock); 346 + return ret; 347 + } 348 + 349 + ret = rpr0521_set_power_state(data, false, device_mask); 350 + mutex_unlock(&data->lock); 351 + if (ret < 0) 352 + return ret; 353 + 354 + *val = le16_to_cpu(raw_data); 355 + 356 + return IIO_VAL_INT; 357 + case IIO_CHAN_INFO_SCALE: 358 + mutex_lock(&data->lock); 359 + ret = rpr0521_get_gain(data, chan->address, val, val2); 360 + mutex_unlock(&data->lock); 361 + if (ret < 0) 362 + return ret; 363 + 364 + return IIO_VAL_INT_PLUS_MICRO; 365 + default: 366 + return -EINVAL; 367 + } 368 + } 369 + 370 + static int rpr0521_write_raw(struct iio_dev *indio_dev, 371 + struct iio_chan_spec const *chan, int val, 372 + int val2, long mask) 373 + { 374 + struct rpr0521_data *data = iio_priv(indio_dev); 375 + int ret; 376 + 377 + switch (mask) { 378 + case IIO_CHAN_INFO_SCALE: 379 + mutex_lock(&data->lock); 380 + ret = rpr0521_set_gain(data, chan->address, val, val2); 381 + mutex_unlock(&data->lock); 382 + 383 + return ret; 384 + default: 385 + return -EINVAL; 386 + } 387 + } 388 + 389 + static const struct iio_info rpr0521_info = { 390 + .driver_module = THIS_MODULE, 391 + .read_raw = rpr0521_read_raw, 392 + .write_raw = rpr0521_write_raw, 393 + .attrs = &rpr0521_attribute_group, 394 + }; 395 + 396 + static int rpr0521_init(struct rpr0521_data *data) 397 + { 398 + int ret; 399 + int id; 400 + 401 + ret = regmap_read(data->regmap, RPR0521_REG_ID, &id); 402 + if (ret < 0) { 403 + dev_err(&data->client->dev, "Failed to read REG_ID register\n"); 404 + return ret; 405 + } 406 + 407 + if (id != RPR0521_MANUFACT_ID) { 408 + dev_err(&data->client->dev, "Wrong id, got %x, expected %x\n", 409 + id, RPR0521_MANUFACT_ID); 410 + return -ENODEV; 411 + } 412 + 413 + /* set default measurement time - 100 ms for both ALS and PS */ 414 + ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL, 415 + RPR0521_MODE_MEAS_TIME_MASK, 416 + RPR0521_DEFAULT_MEAS_TIME); 417 + if (ret) { 418 + pr_err("regmap_update_bits returned %d\n", ret); 419 + return ret; 420 + } 421 + 422 + ret = rpr0521_als_enable(data, RPR0521_MODE_ALS_ENABLE); 423 + if (ret < 0) 424 + return ret; 425 + ret = rpr0521_pxs_enable(data, RPR0521_MODE_PXS_ENABLE); 426 + if (ret < 0) 427 + return ret; 428 + 429 + return 0; 430 + } 431 + 432 + static int rpr0521_poweroff(struct rpr0521_data *data) 433 + { 434 + int ret; 435 + 436 + ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL, 437 + RPR0521_MODE_ALS_MASK | 438 + RPR0521_MODE_PXS_MASK, 439 + RPR0521_MODE_ALS_DISABLE | 440 + RPR0521_MODE_PXS_DISABLE); 441 + if (ret < 0) 442 + return ret; 443 + 444 + data->als_dev_en = false; 445 + data->pxs_dev_en = false; 446 + 447 + return 0; 448 + } 449 + 450 + static bool rpr0521_is_volatile_reg(struct device *dev, unsigned int reg) 451 + { 452 + switch (reg) { 453 + case RPR0521_REG_MODE_CTRL: 454 + case RPR0521_REG_ALS_CTRL: 455 + case RPR0521_REG_PXS_CTRL: 456 + return false; 457 + default: 458 + return true; 459 + } 460 + } 461 + 462 + static const struct regmap_config rpr0521_regmap_config = { 463 + .name = RPR0521_REGMAP_NAME, 464 + 465 + .reg_bits = 8, 466 + .val_bits = 8, 467 + 468 + .max_register = RPR0521_REG_ID, 469 + .cache_type = REGCACHE_RBTREE, 470 + .volatile_reg = rpr0521_is_volatile_reg, 471 + }; 472 + 473 + static int rpr0521_probe(struct i2c_client *client, 474 + const struct i2c_device_id *id) 475 + { 476 + struct rpr0521_data *data; 477 + struct iio_dev *indio_dev; 478 + struct regmap *regmap; 479 + int ret; 480 + 481 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 482 + if (!indio_dev) 483 + return -ENOMEM; 484 + 485 + regmap = devm_regmap_init_i2c(client, &rpr0521_regmap_config); 486 + if (IS_ERR(regmap)) { 487 + dev_err(&client->dev, "regmap_init failed!\n"); 488 + return PTR_ERR(regmap); 489 + } 490 + 491 + data = iio_priv(indio_dev); 492 + i2c_set_clientdata(client, indio_dev); 493 + data->client = client; 494 + data->regmap = regmap; 495 + 496 + mutex_init(&data->lock); 497 + 498 + indio_dev->dev.parent = &client->dev; 499 + indio_dev->info = &rpr0521_info; 500 + indio_dev->name = RPR0521_DRV_NAME; 501 + indio_dev->channels = rpr0521_channels; 502 + indio_dev->num_channels = ARRAY_SIZE(rpr0521_channels); 503 + indio_dev->modes = INDIO_DIRECT_MODE; 504 + 505 + ret = rpr0521_init(data); 506 + if (ret < 0) { 507 + dev_err(&client->dev, "rpr0521 chip init failed\n"); 508 + return ret; 509 + } 510 + ret = iio_device_register(indio_dev); 511 + if (ret < 0) 512 + return ret; 513 + 514 + ret = pm_runtime_set_active(&client->dev); 515 + if (ret < 0) 516 + goto err_iio_unregister; 517 + 518 + pm_runtime_enable(&client->dev); 519 + pm_runtime_set_autosuspend_delay(&client->dev, RPR0521_SLEEP_DELAY_MS); 520 + pm_runtime_use_autosuspend(&client->dev); 521 + 522 + return 0; 523 + 524 + err_iio_unregister: 525 + iio_device_unregister(indio_dev); 526 + return ret; 527 + } 528 + 529 + static int rpr0521_remove(struct i2c_client *client) 530 + { 531 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 532 + 533 + pm_runtime_disable(&client->dev); 534 + pm_runtime_set_suspended(&client->dev); 535 + pm_runtime_put_noidle(&client->dev); 536 + 537 + iio_device_unregister(indio_dev); 538 + rpr0521_poweroff(iio_priv(indio_dev)); 539 + 540 + return 0; 541 + } 542 + 543 + #ifdef CONFIG_PM 544 + static int rpr0521_runtime_suspend(struct device *dev) 545 + { 546 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 547 + struct rpr0521_data *data = iio_priv(indio_dev); 548 + int ret; 549 + 550 + /* disable channels and sets {als,pxs}_dev_en to false */ 551 + mutex_lock(&data->lock); 552 + ret = rpr0521_poweroff(data); 553 + mutex_unlock(&data->lock); 554 + 555 + return ret; 556 + } 557 + 558 + static int rpr0521_runtime_resume(struct device *dev) 559 + { 560 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 561 + struct rpr0521_data *data = iio_priv(indio_dev); 562 + int ret; 563 + 564 + if (data->als_ps_need_en) { 565 + ret = rpr0521_als_enable(data, RPR0521_MODE_ALS_ENABLE); 566 + if (ret < 0) 567 + return ret; 568 + data->als_ps_need_en = false; 569 + } 570 + 571 + if (data->pxs_ps_need_en) { 572 + ret = rpr0521_pxs_enable(data, RPR0521_MODE_PXS_ENABLE); 573 + if (ret < 0) 574 + return ret; 575 + data->pxs_ps_need_en = false; 576 + } 577 + 578 + return 0; 579 + } 580 + #endif 581 + 582 + static const struct dev_pm_ops rpr0521_pm_ops = { 583 + SET_RUNTIME_PM_OPS(rpr0521_runtime_suspend, 584 + rpr0521_runtime_resume, NULL) 585 + }; 586 + 587 + static const struct acpi_device_id rpr0521_acpi_match[] = { 588 + {"RPR0521", 0}, 589 + { } 590 + }; 591 + MODULE_DEVICE_TABLE(acpi, rpr0521_acpi_match); 592 + 593 + static const struct i2c_device_id rpr0521_id[] = { 594 + {"rpr0521", 0}, 595 + { } 596 + }; 597 + 598 + MODULE_DEVICE_TABLE(i2c, rpr0521_id); 599 + 600 + static struct i2c_driver rpr0521_driver = { 601 + .driver = { 602 + .name = RPR0521_DRV_NAME, 603 + .pm = &rpr0521_pm_ops, 604 + .acpi_match_table = ACPI_PTR(rpr0521_acpi_match), 605 + }, 606 + .probe = rpr0521_probe, 607 + .remove = rpr0521_remove, 608 + .id_table = rpr0521_id, 609 + }; 610 + 611 + module_i2c_driver(rpr0521_driver); 612 + 613 + MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); 614 + MODULE_DESCRIPTION("RPR0521 ROHM Ambient Light and Proximity Sensor driver"); 615 + MODULE_LICENSE("GPL v2");
-1
drivers/iio/light/tcs3414.c
··· 392 392 .driver = { 393 393 .name = TCS3414_DRV_NAME, 394 394 .pm = &tcs3414_pm_ops, 395 - .owner = THIS_MODULE, 396 395 }, 397 396 .probe = tcs3414_probe, 398 397 .remove = tcs3414_remove,
-1
drivers/iio/light/tcs3472.c
··· 366 366 .driver = { 367 367 .name = TCS3472_DRV_NAME, 368 368 .pm = &tcs3472_pm_ops, 369 - .owner = THIS_MODULE, 370 369 }, 371 370 .probe = tcs3472_probe, 372 371 .remove = tcs3472_remove,
-1
drivers/iio/light/tsl4531.c
··· 247 247 .driver = { 248 248 .name = TSL4531_DRV_NAME, 249 249 .pm = TSL4531_PM_OPS, 250 - .owner = THIS_MODULE, 251 250 }, 252 251 .probe = tsl4531_probe, 253 252 .remove = tsl4531_remove,
-1
drivers/iio/light/vcnl4000.c
··· 185 185 static struct i2c_driver vcnl4000_driver = { 186 186 .driver = { 187 187 .name = VCNL4000_DRV_NAME, 188 - .owner = THIS_MODULE, 189 188 }, 190 189 .probe = vcnl4000_probe, 191 190 .id_table = vcnl4000_id,
+40 -31
drivers/iio/magnetometer/bmc150_magn.c
··· 588 588 } 589 589 } 590 590 591 - static int bmc150_magn_validate_trigger(struct iio_dev *indio_dev, 592 - struct iio_trigger *trig) 593 - { 594 - struct bmc150_magn_data *data = iio_priv(indio_dev); 595 - 596 - if (data->dready_trig != trig) 597 - return -EINVAL; 598 - 599 - return 0; 600 - } 601 - 602 591 static ssize_t bmc150_magn_show_samp_freq_avail(struct device *dev, 603 592 struct device_attribute *attr, 604 593 char *buf) ··· 648 659 .attrs = &bmc150_magn_attrs_group, 649 660 .read_raw = bmc150_magn_read_raw, 650 661 .write_raw = bmc150_magn_write_raw, 651 - .validate_trigger = bmc150_magn_validate_trigger, 652 662 .driver_module = THIS_MODULE, 653 663 }; 654 664 ··· 670 682 pf->timestamp); 671 683 672 684 err: 673 - iio_trigger_notify_done(data->dready_trig); 685 + iio_trigger_notify_done(indio_dev->trig); 674 686 675 687 return IRQ_HANDLED; 676 688 } ··· 815 827 .owner = THIS_MODULE, 816 828 }; 817 829 830 + static int bmc150_magn_buffer_preenable(struct iio_dev *indio_dev) 831 + { 832 + struct bmc150_magn_data *data = iio_priv(indio_dev); 833 + 834 + return bmc150_magn_set_power_state(data, true); 835 + } 836 + 837 + static int bmc150_magn_buffer_postdisable(struct iio_dev *indio_dev) 838 + { 839 + struct bmc150_magn_data *data = iio_priv(indio_dev); 840 + 841 + return bmc150_magn_set_power_state(data, false); 842 + } 843 + 844 + static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = { 845 + .preenable = bmc150_magn_buffer_preenable, 846 + .postenable = iio_triggered_buffer_postenable, 847 + .predisable = iio_triggered_buffer_predisable, 848 + .postdisable = bmc150_magn_buffer_postdisable, 849 + }; 850 + 818 851 static int bmc150_magn_gpio_probe(struct i2c_client *client) 819 852 { 820 853 struct device *dev; ··· 941 932 goto err_poweroff; 942 933 } 943 934 944 - ret = iio_triggered_buffer_setup(indio_dev, 945 - &iio_pollfunc_store_time, 946 - bmc150_magn_trigger_handler, 947 - NULL); 948 - if (ret < 0) { 949 - dev_err(&client->dev, 950 - "iio triggered buffer setup failed\n"); 951 - goto err_trigger_unregister; 952 - } 953 - 954 935 ret = request_threaded_irq(client->irq, 955 936 iio_trigger_generic_data_rdy_poll, 956 937 NULL, ··· 950 951 if (ret < 0) { 951 952 dev_err(&client->dev, "request irq %d failed\n", 952 953 client->irq); 953 - goto err_buffer_cleanup; 954 + goto err_trigger_unregister; 954 955 } 956 + } 957 + 958 + ret = iio_triggered_buffer_setup(indio_dev, 959 + iio_pollfunc_store_time, 960 + bmc150_magn_trigger_handler, 961 + &bmc150_magn_buffer_setup_ops); 962 + if (ret < 0) { 963 + dev_err(&client->dev, 964 + "iio triggered buffer setup failed\n"); 965 + goto err_free_irq; 955 966 } 956 967 957 968 ret = iio_device_register(indio_dev); 958 969 if (ret < 0) { 959 970 dev_err(&client->dev, "unable to register iio device\n"); 960 - goto err_free_irq; 971 + goto err_buffer_cleanup; 961 972 } 962 973 963 974 ret = pm_runtime_set_active(&client->dev); ··· 985 976 986 977 err_iio_unregister: 987 978 iio_device_unregister(indio_dev); 979 + err_buffer_cleanup: 980 + iio_triggered_buffer_cleanup(indio_dev); 988 981 err_free_irq: 989 982 if (client->irq > 0) 990 983 free_irq(client->irq, data->dready_trig); 991 - err_buffer_cleanup: 992 - if (data->dready_trig) 993 - iio_triggered_buffer_cleanup(indio_dev); 994 984 err_trigger_unregister: 995 985 if (data->dready_trig) 996 986 iio_trigger_unregister(data->dready_trig); ··· 1008 1000 pm_runtime_put_noidle(&client->dev); 1009 1001 1010 1002 iio_device_unregister(indio_dev); 1003 + iio_triggered_buffer_cleanup(indio_dev); 1011 1004 1012 1005 if (client->irq > 0) 1013 1006 free_irq(data->client->irq, data->dready_trig); 1014 1007 1015 - if (data->dready_trig) { 1016 - iio_triggered_buffer_cleanup(indio_dev); 1008 + if (data->dready_trig) 1017 1009 iio_trigger_unregister(data->dready_trig); 1018 - } 1019 1010 1020 1011 mutex_lock(&data->mutex); 1021 1012 bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, true); ··· 1089 1082 1090 1083 static const struct acpi_device_id bmc150_magn_acpi_match[] = { 1091 1084 {"BMC150B", 0}, 1085 + {"BMC156B", 0}, 1092 1086 {}, 1093 1087 }; 1094 1088 MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 1095 1089 1096 1090 static const struct i2c_device_id bmc150_magn_id[] = { 1097 1091 {"bmc150_magn", 0}, 1092 + {"bmc156_magn", 0}, 1098 1093 {}, 1099 1094 }; 1100 1095 MODULE_DEVICE_TABLE(i2c, bmc150_magn_id);
-1
drivers/iio/magnetometer/st_magn_i2c.c
··· 85 85 86 86 static struct i2c_driver st_magn_driver = { 87 87 .driver = { 88 - .owner = THIS_MODULE, 89 88 .name = "st-magn-i2c", 90 89 .of_match_table = of_match_ptr(st_magn_of_match), 91 90 },
+3 -3
drivers/iio/pressure/Kconfig
··· 53 53 will be called mpl3115. 54 54 55 55 config MS5611 56 - tristate "Measurement Specialities MS5611 pressure sensor driver" 56 + tristate "Measurement Specialties MS5611 pressure sensor driver" 57 57 help 58 - Say Y here to build support for the Measurement Specialities 59 - MS5611 pressure and temperature sensor. 58 + Say Y here to build support for the Measurement Specialties 59 + MS5611, MS5607 pressure and temperature sensors. 60 60 61 61 To compile this driver as a module, choose M here: the module will 62 62 be called ms5611_core.
+14 -2
drivers/iio/pressure/ms5611.h
··· 27 27 28 28 #define MS5611_PROM_WORDS_NB 8 29 29 30 + enum { 31 + MS5611, 32 + MS5607, 33 + }; 34 + 35 + struct ms5611_chip_info { 36 + u16 prom[MS5611_PROM_WORDS_NB]; 37 + 38 + int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info, 39 + s32 *temp, s32 *pressure); 40 + }; 41 + 30 42 struct ms5611_state { 31 43 void *client; 32 44 struct mutex lock; ··· 48 36 int (*read_adc_temp_and_pressure)(struct device *dev, 49 37 s32 *temp, s32 *pressure); 50 38 51 - u16 prom[MS5611_PROM_WORDS_NB]; 39 + struct ms5611_chip_info *chip_info; 52 40 }; 53 41 54 - int ms5611_probe(struct iio_dev *indio_dev, struct device *dev); 42 + int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type); 55 43 56 44 #endif /* _MS5611_H */
+68 -14
drivers/iio/pressure/ms5611_core.c
··· 9 9 * 10 10 * Data sheet: 11 11 * http://www.meas-spec.com/downloads/MS5611-01BA03.pdf 12 + * http://www.meas-spec.com/downloads/MS5607-02BA03.pdf 12 13 * 13 14 */ 14 15 ··· 51 50 struct ms5611_state *st = iio_priv(indio_dev); 52 51 53 52 for (i = 0; i < MS5611_PROM_WORDS_NB; i++) { 54 - ret = st->read_prom_word(&indio_dev->dev, i, &st->prom[i]); 53 + ret = st->read_prom_word(&indio_dev->dev, 54 + i, &st->chip_info->prom[i]); 55 55 if (ret < 0) { 56 56 dev_err(&indio_dev->dev, 57 57 "failed to read prom at %d\n", i); ··· 60 58 } 61 59 } 62 60 63 - if (!ms5611_prom_is_valid(st->prom, MS5611_PROM_WORDS_NB)) { 61 + if (!ms5611_prom_is_valid(st->chip_info->prom, MS5611_PROM_WORDS_NB)) { 64 62 dev_err(&indio_dev->dev, "PROM integrity check failed\n"); 65 63 return -ENODEV; 66 64 } ··· 72 70 s32 *temp, s32 *pressure) 73 71 { 74 72 int ret; 75 - s32 t, p; 76 - s64 off, sens, dt; 77 73 struct ms5611_state *st = iio_priv(indio_dev); 78 74 79 - ret = st->read_adc_temp_and_pressure(&indio_dev->dev, &t, &p); 75 + ret = st->read_adc_temp_and_pressure(&indio_dev->dev, temp, pressure); 80 76 if (ret < 0) { 81 77 dev_err(&indio_dev->dev, 82 78 "failed to read temperature and pressure\n"); 83 79 return ret; 84 80 } 85 81 86 - dt = t - (st->prom[5] << 8); 87 - off = ((s64)st->prom[2] << 16) + ((st->prom[4] * dt) >> 7); 88 - sens = ((s64)st->prom[1] << 15) + ((st->prom[3] * dt) >> 8); 82 + return st->chip_info->temp_and_pressure_compensate(st->chip_info, 83 + temp, pressure); 84 + } 89 85 90 - t = 2000 + ((st->prom[6] * dt) >> 23); 86 + static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info, 87 + s32 *temp, s32 *pressure) 88 + { 89 + s32 t = *temp, p = *pressure; 90 + s64 off, sens, dt; 91 + 92 + dt = t - (chip_info->prom[5] << 8); 93 + off = ((s64)chip_info->prom[2] << 16) + ((chip_info->prom[4] * dt) >> 7); 94 + sens = ((s64)chip_info->prom[1] << 15) + ((chip_info->prom[3] * dt) >> 8); 95 + 96 + t = 2000 + ((chip_info->prom[6] * dt) >> 23); 91 97 if (t < 2000) { 92 98 s64 off2, sens2, t2; 93 99 ··· 108 98 109 99 off2 += 7 * tmp; 110 100 sens2 += (11 * tmp) >> 1; 101 + } 102 + 103 + t -= t2; 104 + off -= off2; 105 + sens -= sens2; 106 + } 107 + 108 + *temp = t; 109 + *pressure = (((p * sens) >> 21) - off) >> 15; 110 + 111 + return 0; 112 + } 113 + 114 + static int ms5607_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info, 115 + s32 *temp, s32 *pressure) 116 + { 117 + s32 t = *temp, p = *pressure; 118 + s64 off, sens, dt; 119 + 120 + dt = t - (chip_info->prom[5] << 8); 121 + off = ((s64)chip_info->prom[2] << 17) + ((chip_info->prom[4] * dt) >> 6); 122 + sens = ((s64)chip_info->prom[1] << 16) + ((chip_info->prom[3] * dt) >> 7); 123 + 124 + t = 2000 + ((chip_info->prom[6] * dt) >> 23); 125 + if (t < 2000) { 126 + s64 off2, sens2, t2; 127 + 128 + t2 = (dt * dt) >> 31; 129 + off2 = (61 * (t - 2000) * (t - 2000)) >> 4; 130 + sens2 = off2 << 1; 131 + 132 + if (t < -1500) { 133 + s64 tmp = (t + 1500) * (t + 1500); 134 + 135 + off2 += 15 * tmp; 136 + sens2 += (8 * tmp); 111 137 } 112 138 113 139 t -= t2; ··· 206 160 return -EINVAL; 207 161 } 208 162 163 + static struct ms5611_chip_info chip_info_tbl[] = { 164 + [MS5611] = { 165 + .temp_and_pressure_compensate = ms5611_temp_and_pressure_compensate, 166 + }, 167 + [MS5607] = { 168 + .temp_and_pressure_compensate = ms5607_temp_and_pressure_compensate, 169 + } 170 + }; 171 + 209 172 static const struct iio_chan_spec ms5611_channels[] = { 210 173 { 211 174 .type = IIO_PRESSURE, 212 - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 213 - BIT(IIO_CHAN_INFO_SCALE) 175 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 214 176 }, 215 177 { 216 178 .type = IIO_TEMP, 217 - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 218 - BIT(IIO_CHAN_INFO_SCALE) 179 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 219 180 } 220 181 }; 221 182 ··· 242 189 return ms5611_read_prom(indio_dev); 243 190 } 244 191 245 - int ms5611_probe(struct iio_dev *indio_dev, struct device *dev) 192 + int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type) 246 193 { 247 194 int ret; 248 195 struct ms5611_state *st = iio_priv(indio_dev); 249 196 250 197 mutex_init(&st->lock); 198 + st->chip_info = &chip_info_tbl[type]; 251 199 indio_dev->dev.parent = dev; 252 200 indio_dev->name = dev->driver->name; 253 201 indio_dev->info = &ms5611_info;
+3 -3
drivers/iio/pressure/ms5611_i2c.c
··· 104 104 st->read_adc_temp_and_pressure = ms5611_i2c_read_adc_temp_and_pressure; 105 105 st->client = client; 106 106 107 - return ms5611_probe(indio_dev, &client->dev); 107 + return ms5611_probe(indio_dev, &client->dev, id->driver_data); 108 108 } 109 109 110 110 static const struct i2c_device_id ms5611_id[] = { 111 - { "ms5611", 0 }, 111 + { "ms5611", MS5611 }, 112 + { "ms5607", MS5607 }, 112 113 { } 113 114 }; 114 115 MODULE_DEVICE_TABLE(i2c, ms5611_id); ··· 117 116 static struct i2c_driver ms5611_driver = { 118 117 .driver = { 119 118 .name = "ms5611", 120 - .owner = THIS_MODULE, 121 119 }, 122 120 .id_table = ms5611_id, 123 121 .probe = ms5611_i2c_probe,
+4 -2
drivers/iio/pressure/ms5611_spi.c
··· 103 103 st->read_adc_temp_and_pressure = ms5611_spi_read_adc_temp_and_pressure; 104 104 st->client = spi; 105 105 106 - return ms5611_probe(indio_dev, &spi->dev); 106 + return ms5611_probe(indio_dev, &spi->dev, 107 + spi_get_device_id(spi)->driver_data); 107 108 } 108 109 109 110 static const struct spi_device_id ms5611_id[] = { 110 - { "ms5611", 0 }, 111 + { "ms5611", MS5611 }, 112 + { "ms5607", MS5607 }, 111 113 { } 112 114 }; 113 115 MODULE_DEVICE_TABLE(spi, ms5611_id);
-1
drivers/iio/pressure/st_pressure_i2c.c
··· 79 79 80 80 static struct i2c_driver st_press_driver = { 81 81 .driver = { 82 - .owner = THIS_MODULE, 83 82 .name = "st-press-i2c", 84 83 .of_match_table = of_match_ptr(st_press_of_match), 85 84 },
-1
drivers/iio/temperature/mlx90614.c
··· 551 551 static struct i2c_driver mlx90614_driver = { 552 552 .driver = { 553 553 .name = "mlx90614", 554 - .owner = THIS_MODULE, 555 554 .pm = &mlx90614_pm_ops, 556 555 }, 557 556 .probe = mlx90614_probe,
+2 -3
drivers/iio/temperature/tmp006.c
··· 36 36 #define TMP006_CONFIG_DRDY_EN BIT(8) 37 37 #define TMP006_CONFIG_DRDY BIT(7) 38 38 39 - #define TMP006_CONFIG_MOD_MASK 0x7000 39 + #define TMP006_CONFIG_MOD_MASK GENMASK(14, 12) 40 40 41 - #define TMP006_CONFIG_CR_MASK 0x0e00 41 + #define TMP006_CONFIG_CR_MASK GENMASK(11, 9) 42 42 #define TMP006_CONFIG_CR_SHIFT 9 43 43 44 44 #define TMP006_MANUFACTURER_MAGIC 0x5449 ··· 277 277 .driver = { 278 278 .name = "tmp006", 279 279 .pm = &tmp006_pm_ops, 280 - .owner = THIS_MODULE, 281 280 }, 282 281 .probe = tmp006_probe, 283 282 .remove = tmp006_remove,
-1
drivers/staging/iio/addac/adt7316-i2c.c
··· 124 124 .driver = { 125 125 .name = "adt7316", 126 126 .pm = ADT7316_PM_OPS, 127 - .owner = THIS_MODULE, 128 127 }, 129 128 .probe = adt7316_i2c_probe, 130 129 .id_table = adt7316_i2c_id,
+1
drivers/staging/iio/iio_dummy_evgen.c
··· 214 214 .groups = iio_evgen_groups, 215 215 .release = &iio_evgen_release, 216 216 }; 217 + 217 218 static __init int iio_dummy_evgen_init(void) 218 219 { 219 220 int ret = iio_dummy_evgen_create();
-2
drivers/staging/iio/iio_simple_dummy.c
··· 611 611 */ 612 612 iio_dummy_devs[index] = indio_dev; 613 613 614 - 615 614 /* 616 615 * Set the device name. 617 616 * ··· 673 674 * struct iio_dev *indio_dev = spi_get_drvdata(spi); 674 675 */ 675 676 struct iio_dev *indio_dev = iio_dummy_devs[index]; 676 - 677 677 678 678 /* Unregister the device */ 679 679 iio_device_unregister(indio_dev);
+1
drivers/staging/iio/iio_simple_dummy.h
··· 119 119 { 120 120 return 0; 121 121 }; 122 + 122 123 static inline 123 124 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) 124 125 {};
+1 -1
drivers/staging/iio/iio_simple_dummy_buffer.c
··· 32 32 [diffvoltage3m4] = -2, 33 33 [accelx] = 344, 34 34 }; 35 + 35 36 /** 36 37 * iio_simple_dummy_trigger_h() - the trigger handler function 37 38 * @irq: the interrupt number ··· 179 178 iio_kfifo_free(indio_dev->buffer); 180 179 error_ret: 181 180 return ret; 182 - 183 181 } 184 182 185 183 /**
-1
drivers/staging/iio/light/isl29018.c
··· 838 838 .name = "isl29018", 839 839 .acpi_match_table = ACPI_PTR(isl29018_acpi_match), 840 840 .pm = ISL29018_PM_OPS, 841 - .owner = THIS_MODULE, 842 841 .of_match_table = isl29018_of_match, 843 842 }, 844 843 .probe = isl29018_probe,
-1
drivers/staging/iio/light/isl29028.c
··· 547 547 .class = I2C_CLASS_HWMON, 548 548 .driver = { 549 549 .name = "isl29028", 550 - .owner = THIS_MODULE, 551 550 .of_match_table = isl29028_of_match, 552 551 }, 553 552 .probe = isl29028_probe,
+2 -2
include/linux/iio/triggered_buffer.h
··· 7 7 struct iio_buffer_setup_ops; 8 8 9 9 int iio_triggered_buffer_setup(struct iio_dev *indio_dev, 10 - irqreturn_t (*pollfunc_bh)(int irq, void *p), 11 - irqreturn_t (*pollfunc_th)(int irq, void *p), 10 + irqreturn_t (*h)(int irq, void *p), 11 + irqreturn_t (*thread)(int irq, void *p), 12 12 const struct iio_buffer_setup_ops *setup_ops); 13 13 void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev); 14 14
+48 -19
tools/iio/generic_buffer.c
··· 51 51 if (bytes % channels[i].bytes == 0) 52 52 channels[i].location = bytes; 53 53 else 54 - channels[i].location = bytes - bytes%channels[i].bytes 55 - + channels[i].bytes; 54 + channels[i].location = bytes - bytes % channels[i].bytes 55 + + channels[i].bytes; 56 + 56 57 bytes = channels[i].location + channels[i].bytes; 57 58 i++; 58 59 } 60 + 59 61 return bytes; 62 + } 63 + 64 + void print1byte(uint8_t input, struct iio_channel_info *info) 65 + { 66 + /* 67 + * Shift before conversion to avoid sign extension 68 + * of left aligned data 69 + */ 70 + input >>= info->shift; 71 + input &= info->mask; 72 + if (info->is_signed) { 73 + int8_t val = (int8_t)(input << (8 - info->bits_used)) >> 74 + (8 - info->bits_used); 75 + printf("%05f ", ((float)val + info->offset) * info->scale); 76 + } else { 77 + printf("%05f ", ((float)input + info->offset) * info->scale); 78 + } 60 79 } 61 80 62 81 void print2byte(uint16_t input, struct iio_channel_info *info) ··· 155 136 /** 156 137 * process_scan() - print out the values in SI units 157 138 * @data: pointer to the start of the scan 158 - * @channels: information about the channels. Note 159 - * size_from_channelarray must have been called first to fill the 160 - * location offsets. 139 + * @channels: information about the channels. 140 + * Note: size_from_channelarray must have been called first 141 + * to fill the location offsets. 161 142 * @num_channels: number of channels 162 143 **/ 163 144 void process_scan(char *data, ··· 169 150 for (k = 0; k < num_channels; k++) 170 151 switch (channels[k].bytes) { 171 152 /* only a few cases implemented so far */ 153 + case 1: 154 + print1byte(*(uint8_t *)(data + channels[k].location), 155 + &channels[k]); 156 + break; 172 157 case 2: 173 158 print2byte(*(uint16_t *)(data + channels[k].location), 174 159 &channels[k]); ··· 236 213 num_loops = strtoul(optarg, &dummy, 10); 237 214 if (errno) 238 215 return -errno; 216 + 239 217 break; 240 218 case 'e': 241 219 noevents = 1; ··· 249 225 buf_len = strtoul(optarg, &dummy, 10); 250 226 if (errno) 251 227 return -errno; 228 + 252 229 break; 253 230 case 'n': 254 231 device_name = optarg; ··· 282 257 printf("Failed to find the %s\n", device_name); 283 258 return dev_num; 284 259 } 260 + 285 261 printf("iio device number being used is %d\n", dev_num); 286 262 287 263 ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); ··· 311 285 ret = trig_num; 312 286 goto error_free_triggername; 313 287 } 288 + 314 289 printf("iio trigger number being used is %d\n", trig_num); 315 - } else 290 + } else { 316 291 printf("trigger-less mode selected\n"); 292 + } 317 293 318 294 /* 319 295 * Parse the files in scan_elements to identify what channels are ··· 342 314 343 315 if (!notrigger) { 344 316 printf("%s %s\n", dev_dir_name, trigger_name); 345 - /* Set the device trigger to be the data ready trigger found 346 - * above */ 317 + /* 318 + * Set the device trigger to be the data ready trigger found 319 + * above 320 + */ 347 321 ret = write_sysfs_string_and_verify("trigger/current_trigger", 348 322 dev_dir_name, 349 323 trigger_name); ··· 364 334 ret = write_sysfs_int("enable", buf_dir_name, 1); 365 335 if (ret < 0) 366 336 goto error_free_buf_dir_name; 337 + 367 338 scan_size = size_from_channelarray(channels, num_channels); 368 - data = malloc(scan_size*buf_len); 339 + data = malloc(scan_size * buf_len); 369 340 if (!data) { 370 341 ret = -ENOMEM; 371 342 goto error_free_buf_dir_name; ··· 380 349 381 350 /* Attempt to open non blocking the access dev */ 382 351 fp = open(buffer_access, O_RDONLY | O_NONBLOCK); 383 - if (fp == -1) { /* If it isn't there make the node */ 352 + if (fp == -1) { /* TODO: If it isn't there make the node */ 384 353 ret = -errno; 385 354 printf("Failed to open %s\n", buffer_access); 386 355 goto error_free_buffer_access; 387 356 } 388 357 389 - /* Wait for events 10 times */ 390 358 for (j = 0; j < num_loops; j++) { 391 359 if (!noevents) { 392 360 struct pollfd pfd = { ··· 402 372 } 403 373 404 374 toread = buf_len; 405 - 406 375 } else { 407 376 usleep(timedelay); 408 377 toread = 64; 409 378 } 410 379 411 - read_size = read(fp, 412 - data, 413 - toread*scan_size); 380 + read_size = read(fp, data, toread * scan_size); 414 381 if (read_size < 0) { 415 382 if (errno == EAGAIN) { 416 383 printf("nothing available\n"); 417 384 continue; 418 - } else 385 + } else { 419 386 break; 387 + } 420 388 } 421 - for (i = 0; i < read_size/scan_size; i++) 422 - process_scan(data + scan_size*i, 423 - channels, 389 + for (i = 0; i < read_size / scan_size; i++) 390 + process_scan(data + scan_size * i, channels, 424 391 num_channels); 425 392 } 426 393 ··· 436 409 error_close_buffer_access: 437 410 if (close(fp) == -1) 438 411 perror("Failed to close buffer"); 412 + 439 413 error_free_buffer_access: 440 414 free(buffer_access); 441 415 error_free_data: ··· 452 424 error_free_triggername: 453 425 if (datardytrigger) 454 426 free(trigger_name); 427 + 455 428 error_free_dev_dir_name: 456 429 free(dev_dir_name); 457 430
+22 -5
tools/iio/iio_event_monitor.c
··· 13 13 * 14 14 * Usage: 15 15 * iio_event_monitor <device_name> 16 - * 17 16 */ 18 17 19 18 #include <unistd.h> ··· 50 51 [IIO_HUMIDITYRELATIVE] = "humidityrelative", 51 52 [IIO_ACTIVITY] = "activity", 52 53 [IIO_STEPS] = "steps", 54 + [IIO_ENERGY] = "energy", 55 + [IIO_DISTANCE] = "distance", 56 + [IIO_VELOCITY] = "velocity", 53 57 }; 54 58 55 59 static const char * const iio_ev_type_text[] = { ··· 101 99 [IIO_MOD_JOGGING] = "jogging", 102 100 [IIO_MOD_WALKING] = "walking", 103 101 [IIO_MOD_STILL] = "still", 102 + [IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)", 104 103 }; 105 104 106 105 static bool event_is_known(struct iio_event_data *event) ··· 133 130 case IIO_HUMIDITYRELATIVE: 134 131 case IIO_ACTIVITY: 135 132 case IIO_STEPS: 133 + case IIO_ENERGY: 134 + case IIO_DISTANCE: 135 + case IIO_VELOCITY: 136 136 break; 137 137 default: 138 138 return false; ··· 173 167 case IIO_MOD_JOGGING: 174 168 case IIO_MOD_WALKING: 175 169 case IIO_MOD_STILL: 170 + case IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z: 176 171 break; 177 172 default: 178 173 return false; ··· 216 209 217 210 if (!event_is_known(event)) { 218 211 printf("Unknown event: time: %lld, id: %llx\n", 219 - event->timestamp, event->id); 212 + event->timestamp, event->id); 213 + 220 214 return; 221 215 } 222 216 ··· 237 229 238 230 if (dir != IIO_EV_DIR_NONE) 239 231 printf(", direction: %s", iio_ev_dir_text[dir]); 232 + 240 233 printf("\n"); 241 234 } 242 235 ··· 260 251 dev_num = find_type_by_name(device_name, "iio:device"); 261 252 if (dev_num >= 0) { 262 253 printf("Found IIO device with name %s with device number %d\n", 263 - device_name, dev_num); 254 + device_name, dev_num); 264 255 ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num); 265 256 if (ret < 0) { 266 257 return -ENOMEM; 267 258 } 268 259 } else { 269 - /* If we can't find a IIO device by name assume device_name is a 270 - IIO chrdev */ 260 + /* 261 + * If we can't find an IIO device by name assume device_name is 262 + * an IIO chrdev 263 + */ 271 264 chrdev_name = strdup(device_name); 272 265 if (!chrdev_name) 273 266 return -ENOMEM; ··· 308 297 perror("Failed to read event from device"); 309 298 break; 310 299 } 300 + } 301 + 302 + if (ret != sizeof(event)) { 303 + printf("Reading event failed!\n"); 304 + ret = -EIO; 305 + break; 311 306 } 312 307 313 308 print_event(&event);
+72 -49
tools/iio/iio_utils.c
··· 32 32 * 33 33 * Returns 0 on success, or a negative error code if string extraction failed. 34 34 **/ 35 - int iioutils_break_up_name(const char *full_name, 36 - char **generic_name) 35 + int iioutils_break_up_name(const char *full_name, char **generic_name) 37 36 { 38 37 char *current; 39 38 char *w, *r; ··· 64 65 *w = *r; 65 66 w++; 66 67 } 68 + 67 69 r++; 68 70 } 69 71 *w = '\0'; ··· 88 88 * 89 89 * Returns a value >= 0 on success, otherwise a negative error code. 90 90 **/ 91 - int iioutils_get_type(unsigned *is_signed, 92 - unsigned *bytes, 93 - unsigned *bits_used, 94 - unsigned *shift, 95 - uint64_t *mask, 96 - unsigned *be, 97 - const char *device_dir, 98 - const char *name, 99 - const char *generic_name) 91 + int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, 92 + unsigned *shift, uint64_t *mask, unsigned *be, 93 + const char *device_dir, const char *name, 94 + const char *generic_name) 100 95 { 101 96 FILE *sysfsfp; 102 97 int ret; ··· 121 126 ret = -errno; 122 127 goto error_free_builtname_generic; 123 128 } 129 + 124 130 ret = -ENOENT; 125 131 while (ent = readdir(dp), ent != NULL) 126 132 /* ··· 136 140 ret = -ENOMEM; 137 141 goto error_closedir; 138 142 } 143 + 139 144 sysfsfp = fopen(filename, "r"); 140 145 if (sysfsfp == NULL) { 141 146 ret = -errno; ··· 159 162 printf("scan type description didn't match\n"); 160 163 goto error_close_sysfsfp; 161 164 } 165 + 162 166 *be = (endianchar == 'b'); 163 167 *bytes = padint / 8; 164 168 if (*bits_used == 64) 165 169 *mask = ~0; 166 170 else 167 171 *mask = (1 << *bits_used) - 1; 172 + 168 173 *is_signed = (signchar == 's'); 169 174 if (fclose(sysfsfp)) { 170 175 ret = -errno; ··· 176 177 177 178 sysfsfp = 0; 178 179 free(filename); 179 - 180 180 filename = 0; 181 181 } 182 + 182 183 error_close_sysfsfp: 183 184 if (sysfsfp) 184 185 if (fclose(sysfsfp)) ··· 187 188 error_free_filename: 188 189 if (filename) 189 190 free(filename); 191 + 190 192 error_closedir: 191 193 if (closedir(dp) == -1) 192 194 perror("iioutils_get_type(): Failed to close directory"); ··· 212 212 * 213 213 * Returns a value >= 0 on success, otherwise a negative error code. 214 214 **/ 215 - int iioutils_get_param_float(float *output, 216 - const char *param_name, 217 - const char *device_dir, 218 - const char *name, 219 - const char *generic_name) 215 + int iioutils_get_param_float(float *output, const char *param_name, 216 + const char *device_dir, const char *name, 217 + const char *generic_name) 220 218 { 221 219 FILE *sysfsfp; 222 220 int ret; ··· 233 235 ret = -ENOMEM; 234 236 goto error_free_builtname; 235 237 } 238 + 236 239 dp = opendir(device_dir); 237 240 if (dp == NULL) { 238 241 ret = -errno; 239 242 goto error_free_builtname_generic; 240 243 } 244 + 241 245 ret = -ENOENT; 242 246 while (ent = readdir(dp), ent != NULL) 243 247 if ((strcmp(builtname, ent->d_name) == 0) || ··· 250 250 ret = -ENOMEM; 251 251 goto error_closedir; 252 252 } 253 + 253 254 sysfsfp = fopen(filename, "r"); 254 255 if (!sysfsfp) { 255 256 ret = -errno; 256 257 goto error_free_filename; 257 258 } 259 + 258 260 errno = 0; 259 261 if (fscanf(sysfsfp, "%f", output) != 1) 260 262 ret = errno ? -errno : -ENODATA; ··· 266 264 error_free_filename: 267 265 if (filename) 268 266 free(filename); 267 + 269 268 error_closedir: 270 269 if (closedir(dp) == -1) 271 270 perror("iioutils_get_param_float(): Failed to close directory"); ··· 285 282 * @cnt: the amount of array elements 286 283 **/ 287 284 288 - void bsort_channel_array_by_index(struct iio_channel_info **ci_array, 289 - int cnt) 285 + void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt) 290 286 { 291 - 292 287 struct iio_channel_info temp; 293 288 int x, y; 294 289 295 290 for (x = 0; x < cnt; x++) 296 291 for (y = 0; y < (cnt - 1); y++) 297 - if ((*ci_array)[y].index > (*ci_array)[y+1].index) { 292 + if ((*ci_array)[y].index > (*ci_array)[y + 1].index) { 298 293 temp = (*ci_array)[y + 1]; 299 294 (*ci_array)[y + 1] = (*ci_array)[y]; 300 295 (*ci_array)[y] = temp; ··· 308 307 * Returns 0 on success, otherwise a negative error code. 309 308 **/ 310 309 int build_channel_array(const char *device_dir, 311 - struct iio_channel_info **ci_array, 312 - int *counter) 310 + struct iio_channel_info **ci_array, int *counter) 313 311 { 314 312 DIR *dp; 315 313 FILE *sysfsfp; ··· 329 329 ret = -errno; 330 330 goto error_free_name; 331 331 } 332 + 332 333 while (ent = readdir(dp), ent != NULL) 333 334 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), 334 335 "_en") == 0) { ··· 339 338 ret = -ENOMEM; 340 339 goto error_close_dir; 341 340 } 341 + 342 342 sysfsfp = fopen(filename, "r"); 343 343 if (sysfsfp == NULL) { 344 344 ret = -errno; 345 345 free(filename); 346 346 goto error_close_dir; 347 347 } 348 + 348 349 errno = 0; 349 350 if (fscanf(sysfsfp, "%i", &ret) != 1) { 350 351 ret = errno ? -errno : -ENODATA; ··· 356 353 free(filename); 357 354 goto error_close_dir; 358 355 } 359 - 360 356 if (ret == 1) 361 357 (*counter)++; 358 + 362 359 if (fclose(sysfsfp)) { 363 360 ret = -errno; 364 361 free(filename); ··· 367 364 368 365 free(filename); 369 366 } 367 + 370 368 *ci_array = malloc(sizeof(**ci_array) * (*counter)); 371 369 if (*ci_array == NULL) { 372 370 ret = -ENOMEM; 373 371 goto error_close_dir; 374 372 } 373 + 375 374 seekdir(dp, 0); 376 375 while (ent = readdir(dp), ent != NULL) { 377 376 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), ··· 389 384 count--; 390 385 goto error_cleanup_array; 391 386 } 387 + 392 388 sysfsfp = fopen(filename, "r"); 393 389 if (sysfsfp == NULL) { 394 390 ret = -errno; ··· 397 391 count--; 398 392 goto error_cleanup_array; 399 393 } 394 + 400 395 errno = 0; 401 396 if (fscanf(sysfsfp, "%i", &current_enabled) != 1) { 402 397 ret = errno ? -errno : -ENODATA; ··· 430 423 count--; 431 424 goto error_cleanup_array; 432 425 } 426 + 433 427 /* Get the generic and specific name elements */ 434 428 ret = iioutils_break_up_name(current->name, 435 429 &current->generic_name); ··· 440 432 count--; 441 433 goto error_cleanup_array; 442 434 } 435 + 443 436 ret = asprintf(&filename, 444 437 "%s/%s_index", 445 438 scan_el_dir, ··· 450 441 ret = -ENOMEM; 451 442 goto error_cleanup_array; 452 443 } 444 + 453 445 sysfsfp = fopen(filename, "r"); 454 446 if (sysfsfp == NULL) { 455 447 ret = -errno; ··· 484 474 current->generic_name); 485 475 if (ret < 0) 486 476 goto error_cleanup_array; 477 + 487 478 ret = iioutils_get_param_float(&current->offset, 488 479 "offset", 489 480 device_dir, ··· 492 481 current->generic_name); 493 482 if (ret < 0) 494 483 goto error_cleanup_array; 484 + 495 485 ret = iioutils_get_type(&current->is_signed, 496 486 &current->bytes, 497 487 &current->bits_used, ··· 561 549 const struct dirent *ent; 562 550 int number, numstrlen, ret; 563 551 564 - FILE *nameFile; 552 + FILE *namefp; 565 553 DIR *dp; 566 554 char thisname[IIO_MAX_NAME_LENGTH]; 567 555 char *filename; ··· 574 562 575 563 while (ent = readdir(dp), ent != NULL) { 576 564 if (strcmp(ent->d_name, ".") != 0 && 577 - strcmp(ent->d_name, "..") != 0 && 578 - strlen(ent->d_name) > strlen(type) && 579 - strncmp(ent->d_name, type, strlen(type)) == 0) { 565 + strcmp(ent->d_name, "..") != 0 && 566 + strlen(ent->d_name) > strlen(type) && 567 + strncmp(ent->d_name, type, strlen(type)) == 0) { 580 568 errno = 0; 581 569 ret = sscanf(ent->d_name + strlen(type), "%d", &number); 582 570 if (ret < 0) { ··· 592 580 numstrlen = calc_digits(number); 593 581 /* verify the next character is not a colon */ 594 582 if (strncmp(ent->d_name + strlen(type) + numstrlen, 595 - ":", 596 - 1) != 0) { 597 - filename = malloc(strlen(iio_dir) 598 - + strlen(type) 599 - + numstrlen 600 - + 6); 583 + ":", 1) != 0) { 584 + filename = malloc(strlen(iio_dir) + strlen(type) 585 + + numstrlen + 6); 601 586 if (filename == NULL) { 602 587 ret = -ENOMEM; 603 588 goto error_close_dir; ··· 607 598 goto error_close_dir; 608 599 } 609 600 610 - nameFile = fopen(filename, "r"); 611 - if (!nameFile) { 601 + namefp = fopen(filename, "r"); 602 + if (!namefp) { 612 603 free(filename); 613 604 continue; 614 605 } 606 + 615 607 free(filename); 616 608 errno = 0; 617 - if (fscanf(nameFile, "%s", thisname) != 1) { 609 + if (fscanf(namefp, "%s", thisname) != 1) { 618 610 ret = errno ? -errno : -ENODATA; 619 611 goto error_close_dir; 620 612 } 621 613 622 - if (fclose(nameFile)) { 614 + if (fclose(namefp)) { 623 615 ret = -errno; 624 616 goto error_close_dir; 625 617 } ··· 628 618 if (strcmp(name, thisname) == 0) { 629 619 if (closedir(dp) == -1) 630 620 return -errno; 621 + 631 622 return number; 632 623 } 633 624 } ··· 642 631 error_close_dir: 643 632 if (closedir(dp) == -1) 644 633 perror("find_type_by_name(): Failed to close directory"); 634 + 645 635 return ret; 646 636 } 647 637 ··· 656 644 657 645 if (temp == NULL) 658 646 return -ENOMEM; 647 + 659 648 ret = sprintf(temp, "%s/%s", basedir, filename); 660 649 if (ret < 0) 661 650 goto error_free; ··· 667 654 printf("failed to open %s\n", temp); 668 655 goto error_free; 669 656 } 657 + 670 658 ret = fprintf(sysfsfp, "%d", val); 671 659 if (ret < 0) { 672 660 if (fclose(sysfsfp)) ··· 688 674 printf("failed to open %s\n", temp); 689 675 goto error_free; 690 676 } 677 + 691 678 if (fscanf(sysfsfp, "%d", &test) != 1) { 692 679 ret = errno ? -errno : -ENODATA; 693 680 if (fclose(sysfsfp)) ··· 703 688 } 704 689 705 690 if (test != val) { 706 - printf("Possible failure in int write %d to %s%s\n", 707 - val, 708 - basedir, 709 - filename); 691 + printf("Possible failure in int write %d to %s/%s\n", 692 + val, basedir, filename); 710 693 ret = -1; 711 694 } 712 695 } 696 + 713 697 error_free: 714 698 free(temp); 715 699 return ret; ··· 753 739 printf("Memory allocation failed\n"); 754 740 return -ENOMEM; 755 741 } 742 + 756 743 ret = sprintf(temp, "%s/%s", basedir, filename); 757 744 if (ret < 0) 758 745 goto error_free; ··· 764 749 printf("Could not open %s\n", temp); 765 750 goto error_free; 766 751 } 752 + 767 753 ret = fprintf(sysfsfp, "%s", val); 768 754 if (ret < 0) { 769 755 if (fclose(sysfsfp)) ··· 782 766 sysfsfp = fopen(temp, "r"); 783 767 if (sysfsfp == NULL) { 784 768 ret = -errno; 785 - printf("could not open file to verify\n"); 769 + printf("Could not open file to verify\n"); 786 770 goto error_free; 787 771 } 772 + 788 773 if (fscanf(sysfsfp, "%s", temp) != 1) { 789 774 ret = errno ? -errno : -ENODATA; 790 775 if (fclose(sysfsfp)) ··· 801 784 802 785 if (strcmp(temp, val) != 0) { 803 786 printf("Possible failure in string write of %s " 804 - "Should be %s " 805 - "written to %s\%s\n", 806 - temp, 807 - val, 808 - basedir, 809 - filename); 787 + "Should be %s written to %s/%s\n", temp, val, 788 + basedir, filename); 810 789 ret = -1; 811 790 } 812 791 } 792 + 813 793 error_free: 814 794 free(temp); 815 795 ··· 859 845 printf("Memory allocation failed"); 860 846 return -ENOMEM; 861 847 } 848 + 862 849 ret = sprintf(temp, "%s/%s", basedir, filename); 863 850 if (ret < 0) 864 851 goto error_free; ··· 869 854 ret = -errno; 870 855 goto error_free; 871 856 } 857 + 872 858 errno = 0; 873 859 if (fscanf(sysfsfp, "%d\n", &ret) != 1) { 874 860 ret = errno ? -errno : -ENODATA; ··· 884 868 885 869 error_free: 886 870 free(temp); 871 + 887 872 return ret; 888 873 } 889 874 ··· 906 889 printf("Memory allocation failed"); 907 890 return -ENOMEM; 908 891 } 892 + 909 893 ret = sprintf(temp, "%s/%s", basedir, filename); 910 894 if (ret < 0) 911 895 goto error_free; ··· 916 898 ret = -errno; 917 899 goto error_free; 918 900 } 901 + 919 902 errno = 0; 920 903 if (fscanf(sysfsfp, "%f\n", val) != 1) { 921 904 ret = errno ? -errno : -ENODATA; ··· 931 912 932 913 error_free: 933 914 free(temp); 915 + 934 916 return ret; 935 917 } 936 918 ··· 953 933 printf("Memory allocation failed"); 954 934 return -ENOMEM; 955 935 } 936 + 956 937 ret = sprintf(temp, "%s/%s", basedir, filename); 957 938 if (ret < 0) 958 939 goto error_free; ··· 963 942 ret = -errno; 964 943 goto error_free; 965 944 } 945 + 966 946 errno = 0; 967 947 if (fscanf(sysfsfp, "%s\n", str) != 1) { 968 948 ret = errno ? -errno : -ENODATA; ··· 978 956 979 957 error_free: 980 958 free(temp); 959 + 981 960 return ret; 982 961 } 983 962
+7 -8
tools/iio/iio_utils.h
··· 51 51 }; 52 52 53 53 int iioutils_break_up_name(const char *full_name, char **generic_name); 54 - int iioutils_get_type(unsigned *is_signed, unsigned *bytes, 55 - unsigned *bits_used, unsigned *shift, 56 - uint64_t *mask, unsigned *be, 57 - const char *device_dir, const char *name, 58 - const char *generic_name); 54 + int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, 55 + unsigned *shift, uint64_t *mask, unsigned *be, 56 + const char *device_dir, const char *name, 57 + const char *generic_name); 59 58 int iioutils_get_param_float(float *output, const char *param_name, 60 - const char *device_dir, const char *name, 61 - const char *generic_name); 59 + const char *device_dir, const char *name, 60 + const char *generic_name); 62 61 void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt); 63 62 int build_channel_array(const char *device_dir, 64 - struct iio_channel_info **ci_array, int *counter); 63 + struct iio_channel_info **ci_array, int *counter); 65 64 int find_type_by_name(const char *name, const char *type); 66 65 int write_sysfs_int(const char *filename, const char *basedir, int val); 67 66 int write_sysfs_int_and_verify(const char *filename, const char *basedir,
+23 -20
tools/iio/lsiio.c
··· 20 20 #include <sys/dir.h> 21 21 #include "iio_utils.h" 22 22 23 - 24 23 static enum verbosity { 25 24 VERBLEVEL_DEFAULT, /* 0 gives lspci behaviour */ 26 25 VERBLEVEL_SENSORS, /* 1 lists sensors */ ··· 28 29 const char *type_device = "iio:device"; 29 30 const char *type_trigger = "trigger"; 30 31 31 - 32 32 static inline int check_prefix(const char *str, const char *prefix) 33 33 { 34 34 return strlen(str) > strlen(prefix) && 35 - strncmp(str, prefix, strlen(prefix)) == 0; 35 + strncmp(str, prefix, strlen(prefix)) == 0; 36 36 } 37 37 38 38 static inline int check_postfix(const char *str, const char *postfix) 39 39 { 40 40 return strlen(str) > strlen(postfix) && 41 - strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; 41 + strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; 42 42 } 43 43 44 44 static int dump_channels(const char *dev_dir_name) ··· 48 50 dp = opendir(dev_dir_name); 49 51 if (dp == NULL) 50 52 return -errno; 53 + 51 54 while (ent = readdir(dp), ent != NULL) 52 55 if (check_prefix(ent->d_name, "in_") && 53 - check_postfix(ent->d_name, "_raw")) { 56 + check_postfix(ent->d_name, "_raw")) 54 57 printf(" %-10s\n", ent->d_name); 55 - } 56 58 57 59 return (closedir(dp) == -1) ? -errno : 0; 58 60 } ··· 61 63 { 62 64 char name[IIO_MAX_NAME_LENGTH]; 63 65 int dev_idx; 64 - int retval; 66 + int ret; 65 67 66 - retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_device), 67 - "%i", &dev_idx); 68 - if (retval != 1) 68 + ret = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_device), "%i", 69 + &dev_idx); 70 + if (ret != 1) 69 71 return -EINVAL; 70 - retval = read_sysfs_string("name", dev_dir_name, name); 71 - if (retval) 72 - return retval; 72 + 73 + ret = read_sysfs_string("name", dev_dir_name, name); 74 + if (ret) 75 + return ret; 73 76 74 77 printf("Device %03d: %s\n", dev_idx, name); 75 78 76 79 if (verblevel >= VERBLEVEL_SENSORS) 77 80 return dump_channels(dev_dir_name); 81 + 78 82 return 0; 79 83 } 80 84 ··· 84 84 { 85 85 char name[IIO_MAX_NAME_LENGTH]; 86 86 int dev_idx; 87 - int retval; 87 + int ret; 88 88 89 - retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_trigger), 90 - "%i", &dev_idx); 91 - if (retval != 1) 89 + ret = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_trigger), 90 + "%i", &dev_idx); 91 + if (ret != 1) 92 92 return -EINVAL; 93 - retval = read_sysfs_string("name", dev_dir_name, name); 94 - if (retval) 95 - return retval; 93 + 94 + ret = read_sysfs_string("name", dev_dir_name, name); 95 + if (ret) 96 + return ret; 96 97 97 98 printf("Trigger %03d: %s\n", dev_idx, name); 99 + 98 100 return 0; 99 101 } 100 102 ··· 153 151 free(dev_dir_name); 154 152 } 155 153 } 154 + 156 155 return (closedir(dp) == -1) ? -errno : 0; 157 156 158 157 error_close_dir: