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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'iio-for-6.10b-take2' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next

Jonathan writes:

IIO: 2nd set of new device support, features and cleanup for 6.10 (take 2)

The usual mixed bag from towards the end of the cycle.
Changes since take 1. Fixed the fixes tag and indeed fixed a rebase I
messed up on the same fix.

New devices support
===================

invensense,icm42600
- Support the ICM-42686-P a high range device going up to 32g and 4000 dps

New features
============

adi,ad7944
- Add support for chain mode in which many ADCs may be daisy chained and
read out via a single long read.
adi,ad9467/backend library
- Add bus tuning related interfaces.
adi,axi-adc
- Add control for the AXI clock - seems always enabled early in boot for other
reasons, but the driver should not rely on that..

Cleanups and minor or late breaking fixes
=========================================

Micrsoft/ACPI mount matrix handling.
- Replace several implementations of the Microsoft defined ROTM ACPI
method with a single one.
multiple drivers
- Don't call the result of wait_for_completion() timeout as it's
more accurate as time_left.
adi,ad7266
- Stop setting the iio_dev->masklength as it's done by the IIO core and
should not be set from drivers.
adi,ad799x
- Some checkpatch type fixes.
adi,ad9839
- Ensure compelte MU_CNT1 is written during lock phase.
adi,axi-dac
- Fix inverted parameter.
adi,adis16475
- Drop documentation of non existent sysfs files.
avago,apds9306
- Fix an off by one error that overly restricts the range of persistence
and adaptive thresholds that the driver accepts.
freescale,mxs-lradc
- Stop setting the iio_dev->masklength as it's done by the IIO core and
should not be set from drivers.
invensense,timestamp library
- Fix timestamp vs interupt alignment and aovid soms glitches that
occured when switching sampling frequency.
microchip,mcp3564
- Make use of device_for_each_child_node_scoped() to allow early release
without manual fwnode_handle_put().
microchip,mcp9600
- Allow for negative temperatures.
microchip,pac1934
- Avoid an out of bounds array index.
richtek,rtq6056
- Use iio_device_claim_direct_scoped() to automate lock release and simplify
the code.
sensortek,stk3110
- Drop a likely incorrect ACPI ID. No known users of this ID and it's
not a valid ACPI ID.
ti,ads1015
- Make use of device_for_each_child_node_scoped() to allow early release
without manual fwnode_handle_put().

* tag 'iio-for-6.10b-take2' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (41 commits)
iio: temperature: mcp9600: Fix temperature reading for negative values
iio: adc: PAC1934: fix accessing out of bounds array index
iio: invensense: fix timestamp glitches when switching frequency
iio: invensense: fix interrupt timestamp alignment
iio: dac: ad9739a: write complete MU_CNT1 register during lock
iio: pressure: zpa2326: use 'time_left' variable with wait_for_completion_interruptible_timeout()
iio: adc: twl6030-gpadc: use 'time_left' variable with wait_for_completion_interruptible_timeout()
iio: adc: stm32-dfsdm-adc: use 'time_left' variable with wait_for_completion_interruptible_timeout()
iio: adc: stm32-adc: use 'time_left' variable with wait_for_completion_interruptible_timeout()
iio: adc: intel_mrfld_adc: use 'time_left' variable with wait_for_completion_interruptible_timeout()
iio: adc: fsl-imx25-gcq: use 'time_left' variable with wait_for_completion_interruptible_timeout()
iio: adc: exynos_adc: use 'time_left' variable with wait_for_completion_timeout()
iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout()
iio: adc: ti-ads1015: use device_for_each_child_node_scoped()
iio: adc: ad799x: Prefer to use octal permission
iio: adc: ad799x: add blank line to avoid warning messages
iio: adc: ad799x: change 'unsigned' to 'unsigned int' declaration
iio: adc: mcp3564: Use device_for_each_child_node_scoped()
iio: adc: ad9467: support digital interface calibration
iio: adc: adi-axi-adc: support digital interface calibration
...

+1282 -406
+5
Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
··· 28 28 reg: 29 29 maxItems: 1 30 30 31 + clocks: 32 + maxItems: 1 33 + 31 34 dmas: 32 35 maxItems: 1 33 36 ··· 51 48 - compatible 52 49 - dmas 53 50 - reg 51 + - clocks 54 52 55 53 additionalProperties: false 56 54 ··· 62 58 reg = <0x44a00000 0x10000>; 63 59 dmas = <&rx_dma 0>; 64 60 dma-names = "rx"; 61 + clocks = <&axi_clk>; 65 62 #io-backend-cells = <0>; 66 63 }; 67 64 ...
+1
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml
··· 32 32 - invensense,icm42605 33 33 - invensense,icm42622 34 34 - invensense,icm42631 35 + - invensense,icm42686 35 36 - invensense,icm42688 36 37 37 38 reg:
+28 -2
Documentation/iio/ad7944.rst
··· 24 24 SPI wiring modes 25 25 ---------------- 26 26 27 - The driver currently supports two of the many possible SPI wiring configurations. 27 + The driver currently supports three of the many possible SPI wiring configurations. 28 28 29 29 CS mode, 3-wire, without busy indicator 30 30 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ··· 68 68 To select this mode in the device tree, omit the ``adi,spi-mode`` property and 69 69 provide the ``cnv-gpios`` property. 70 70 71 + Chain mode, without busy indicator 72 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 73 + 74 + .. code-block:: 75 + 76 + +-------------+ 77 + +-------------------------+--------------------| CS | 78 + v v | | 79 + +--------------------+ +--------------------+ | HOST | 80 + | CNV | | CNV | | | 81 + +--->| SDI AD7944 SDO |--->| SDI AD7944 SDO |-------->| SDI | 82 + | | SCK | | SCK | | | 83 + GND +--------------------+ +--------------------+ | | 84 + ^ ^ | | 85 + +-------------------------+--------------------| SCLK | 86 + +-------------+ 87 + 88 + To select this mode in the device tree, set the ``adi,spi-mode`` property to 89 + ``"chain"``, add the ``spi-cs-high`` flag, add the ``#daisy-chained-devices`` 90 + property, and omit the ``cnv-gpios`` property. 91 + 71 92 Reference voltage 72 93 ----------------- 73 94 ··· 107 86 108 87 - ``BUSY`` indication 109 88 - ``TURBO`` mode 110 - - Daisy chain mode 111 89 112 90 113 91 Device attributes ··· 128 108 | ``in_voltage0_scale`` | Scale factor to convert raw value to mV. | 129 109 +---------------------------------------+--------------------------------------------------------------+ 130 110 111 + In "chain" mode, additional chips will appear as additional voltage input 112 + channels, e.g. ``in_voltage1_raw``. 113 + 131 114 Fully-differential ADCs 132 115 ----------------------- 133 116 ··· 143 120 +---------------------------------------+--------------------------------------------------------------+ 144 121 | ``in_voltage0-voltage1_scale`` | Scale factor to convert raw value to mV. | 145 122 +---------------------------------------+--------------------------------------------------------------+ 123 + 124 + In "chain" mode, additional chips will appear as additional voltage input 125 + channels, e.g. ``in_voltage2-voltage3_raw``. 146 126 147 127 148 128 Device buffers
+2 -6
Documentation/iio/adis16475.rst
··· 66 66 +-------------------------------------------+----------------------------------------------------------+ 67 67 | in_accel_x_calibbias | Calibration offset for the X-axis accelerometer channel. | 68 68 +-------------------------------------------+----------------------------------------------------------+ 69 - | in_accel_calibbias_x | x-axis acceleration offset correction | 70 - +-------------------------------------------+----------------------------------------------------------+ 71 69 | in_accel_x_raw | Raw X-axis accelerometer channel value. | 72 70 +-------------------------------------------+----------------------------------------------------------+ 73 - | in_accel_calibbias_y | y-axis acceleration offset correction | 71 + | in_accel_y_calibbias | Calibration offset for the Y-axis accelerometer channel. | 74 72 +-------------------------------------------+----------------------------------------------------------+ 75 73 | in_accel_y_raw | Raw Y-axis accelerometer channel value. | 76 74 +-------------------------------------------+----------------------------------------------------------+ ··· 92 94 +---------------------------------------+------------------------------------------------------+ 93 95 | in_anglvel_x_calibbias | Calibration offset for the X-axis gyroscope channel. | 94 96 +---------------------------------------+------------------------------------------------------+ 95 - | in_anglvel_calibbias_x | x-axis gyroscope offset correction | 96 - +---------------------------------------+------------------------------------------------------+ 97 97 | in_anglvel_x_raw | Raw X-axis gyroscope channel value. | 98 98 +---------------------------------------+------------------------------------------------------+ 99 - | in_anglvel_calibbias_y | y-axis gyroscope offset correction | 99 + | in_anglvel_y_calibbias | Calibration offset for the Y-axis gyroscope channel. | 100 100 +---------------------------------------+------------------------------------------------------+ 101 101 | in_anglvel_y_raw | Raw Y-axis gyroscope channel value. | 102 102 +---------------------------------------+------------------------------------------------------+
+1
drivers/iio/Makefile
··· 7 7 industrialio-y := industrialio-core.o industrialio-event.o inkern.o 8 8 industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o 9 9 industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o 10 + industrialio-$(CONFIG_ACPI) += industrialio-acpi.o 10 11 11 12 obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o 12 13 obj-$(CONFIG_IIO_GTS_HELPER) += industrialio-gts-helper.o
+2 -42
drivers/iio/accel/bmc150-accel-core.c
··· 386 386 static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev, 387 387 struct iio_mount_matrix *orientation) 388 388 { 389 - struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 390 389 struct iio_dev *indio_dev = dev_get_drvdata(dev); 391 390 struct acpi_device *adev = ACPI_COMPANION(dev); 392 - char *name, *alt_name, *label, *str; 393 - union acpi_object *obj, *elements; 394 - acpi_status status; 395 - int i, j, val[3]; 391 + char *name, *alt_name, *label; 396 392 397 393 if (strcmp(dev_name(dev), "i2c-BOSC0200:base") == 0) { 398 394 alt_name = "ROMK"; ··· 407 411 return false; 408 412 } 409 413 410 - status = acpi_evaluate_object(adev->handle, name, NULL, &buffer); 411 - if (ACPI_FAILURE(status)) { 412 - dev_warn(dev, "Failed to get ACPI mount matrix: %d\n", status); 413 - return false; 414 - } 415 - 416 - obj = buffer.pointer; 417 - if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) 418 - goto unknown_format; 419 - 420 - elements = obj->package.elements; 421 - for (i = 0; i < 3; i++) { 422 - if (elements[i].type != ACPI_TYPE_STRING) 423 - goto unknown_format; 424 - 425 - str = elements[i].string.pointer; 426 - if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3) 427 - goto unknown_format; 428 - 429 - for (j = 0; j < 3; j++) { 430 - switch (val[j]) { 431 - case -1: str = "-1"; break; 432 - case 0: str = "0"; break; 433 - case 1: str = "1"; break; 434 - default: goto unknown_format; 435 - } 436 - orientation->rotation[i * 3 + j] = str; 437 - } 438 - } 439 - 440 - kfree(buffer.pointer); 441 - return true; 442 - 443 - unknown_format: 444 - dev_warn(dev, "Unknown ACPI mount matrix format, ignoring\n"); 445 - kfree(buffer.pointer); 446 - return false; 414 + return iio_read_acpi_mount_matrix(dev, orientation, name); 447 415 } 448 416 449 417 static bool bmc150_apply_dual250e_acpi_orientation(struct device *dev,
+1 -79
drivers/iio/accel/kxcjk-1013.c
··· 636 636 return 0; 637 637 } 638 638 639 - #ifdef CONFIG_ACPI 640 - static bool kxj_acpi_orientation(struct device *dev, 641 - struct iio_mount_matrix *orientation) 642 - { 643 - struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 644 - struct acpi_device *adev = ACPI_COMPANION(dev); 645 - char *str; 646 - union acpi_object *obj, *elements; 647 - acpi_status status; 648 - int i, j, val[3]; 649 - bool ret = false; 650 - 651 - if (!acpi_has_method(adev->handle, "ROTM")) 652 - return false; 653 - 654 - status = acpi_evaluate_object(adev->handle, "ROTM", NULL, &buffer); 655 - if (ACPI_FAILURE(status)) { 656 - dev_err(dev, "Failed to get ACPI mount matrix: %d\n", status); 657 - return false; 658 - } 659 - 660 - obj = buffer.pointer; 661 - if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) { 662 - dev_err(dev, "Unknown ACPI mount matrix package format\n"); 663 - goto out_free_buffer; 664 - } 665 - 666 - elements = obj->package.elements; 667 - for (i = 0; i < 3; i++) { 668 - if (elements[i].type != ACPI_TYPE_STRING) { 669 - dev_err(dev, "Unknown ACPI mount matrix element format\n"); 670 - goto out_free_buffer; 671 - } 672 - 673 - str = elements[i].string.pointer; 674 - if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3) { 675 - dev_err(dev, "Incorrect ACPI mount matrix string format\n"); 676 - goto out_free_buffer; 677 - } 678 - 679 - for (j = 0; j < 3; j++) { 680 - switch (val[j]) { 681 - case -1: str = "-1"; break; 682 - case 0: str = "0"; break; 683 - case 1: str = "1"; break; 684 - default: 685 - dev_err(dev, "Invalid value in ACPI mount matrix: %d\n", val[j]); 686 - goto out_free_buffer; 687 - } 688 - orientation->rotation[i * 3 + j] = str; 689 - } 690 - } 691 - 692 - ret = true; 693 - 694 - out_free_buffer: 695 - kfree(buffer.pointer); 696 - return ret; 697 - } 698 - 699 - static bool kxj1009_apply_acpi_orientation(struct device *dev, 700 - struct iio_mount_matrix *orientation) 701 - { 702 - struct acpi_device *adev = ACPI_COMPANION(dev); 703 - 704 - if (adev && acpi_dev_hid_uid_match(adev, "KIOX000A", NULL)) 705 - return kxj_acpi_orientation(dev, orientation); 706 - 707 - return false; 708 - } 709 - #else 710 - static bool kxj1009_apply_acpi_orientation(struct device *dev, 711 - struct iio_mount_matrix *orientation) 712 - { 713 - return false; 714 - } 715 - #endif 716 - 717 639 static int kxcjk1013_chip_update_thresholds(struct kxcjk1013_data *data) 718 640 { 719 641 int ret; ··· 1466 1544 } else { 1467 1545 data->active_high_intr = true; /* default polarity */ 1468 1546 1469 - if (!kxj1009_apply_acpi_orientation(&client->dev, &data->orientation)) { 1547 + if (!iio_read_acpi_mount_matrix(&client->dev, &data->orientation, "ROTM")) { 1470 1548 ret = iio_read_mount_matrix(&client->dev, &data->orientation); 1471 1549 if (ret) 1472 1550 return ret;
+22
drivers/iio/accel/mxc4005.c
··· 56 56 struct mutex mutex; 57 57 struct regmap *regmap; 58 58 struct iio_trigger *dready_trig; 59 + struct iio_mount_matrix orientation; 59 60 /* Ensure timestamp is naturally aligned */ 60 61 struct { 61 62 __be16 chans[3]; ··· 260 259 } 261 260 } 262 261 262 + static const struct iio_mount_matrix * 263 + mxc4005_get_mount_matrix(const struct iio_dev *indio_dev, 264 + const struct iio_chan_spec *chan) 265 + { 266 + struct mxc4005_data *data = iio_priv(indio_dev); 267 + 268 + return &data->orientation; 269 + } 270 + 271 + static const struct iio_chan_spec_ext_info mxc4005_ext_info[] = { 272 + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, mxc4005_get_mount_matrix), 273 + { } 274 + }; 275 + 263 276 static const struct iio_info mxc4005_info = { 264 277 .read_raw = mxc4005_read_raw, 265 278 .write_raw = mxc4005_write_raw, ··· 300 285 .shift = 4, \ 301 286 .endianness = IIO_BE, \ 302 287 }, \ 288 + .ext_info = mxc4005_ext_info, \ 303 289 } 304 290 305 291 static const struct iio_chan_spec mxc4005_channels[] = { ··· 430 414 } 431 415 432 416 mutex_init(&data->mutex); 417 + 418 + if (!iio_read_acpi_mount_matrix(&client->dev, &data->orientation, "ROTM")) { 419 + ret = iio_read_mount_matrix(&client->dev, &data->orientation); 420 + if (ret) 421 + return ret; 422 + } 433 423 434 424 indio_dev->channels = mxc4005_channels; 435 425 indio_dev->num_channels = ARRAY_SIZE(mxc4005_channels);
-1
drivers/iio/adc/ad7266.c
··· 371 371 indio_dev->channels = chan_info->channels; 372 372 indio_dev->num_channels = chan_info->num_channels; 373 373 indio_dev->available_scan_masks = chan_info->scan_masks; 374 - indio_dev->masklength = chan_info->num_channels - 1; 375 374 } 376 375 377 376 static const char * const ad7266_gpio_labels[] = {
+176 -10
drivers/iio/adc/ad7944.c
··· 6 6 * Copyright 2024 BayLibre, SAS 7 7 */ 8 8 9 + #include <linux/align.h> 9 10 #include <linux/bitfield.h> 10 11 #include <linux/bitops.h> 11 12 #include <linux/delay.h> ··· 54 53 enum ad7944_spi_mode spi_mode; 55 54 struct spi_transfer xfers[3]; 56 55 struct spi_message msg; 56 + void *chain_mode_buf; 57 57 /* Chip-specific timing specifications. */ 58 58 const struct ad7944_timing_spec *timing_spec; 59 59 /* GPIO connected to CNV pin. */ ··· 216 214 return devm_add_action_or_reset(dev, ad7944_unoptimize_msg, &adc->msg); 217 215 } 218 216 217 + static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adc, 218 + const struct iio_chan_spec *chan, 219 + u32 n_chain_dev) 220 + { 221 + struct spi_transfer *xfers = adc->xfers; 222 + int ret; 223 + 224 + /* 225 + * NB: SCLK has to be low before we toggle CS to avoid triggering the 226 + * busy indication. 227 + */ 228 + if (adc->spi->mode & SPI_CPOL) 229 + return dev_err_probe(dev, -EINVAL, 230 + "chain mode requires ~SPI_CPOL\n"); 231 + 232 + /* 233 + * We only support CNV connected to CS in chain mode and we need CNV 234 + * to be high during the transfer to trigger the conversion. 235 + */ 236 + if (!(adc->spi->mode & SPI_CS_HIGH)) 237 + return dev_err_probe(dev, -EINVAL, 238 + "chain mode requires SPI_CS_HIGH\n"); 239 + 240 + /* CNV has to be high for full conversion time before reading data. */ 241 + xfers[0].delay.value = adc->timing_spec->conv_ns; 242 + xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS; 243 + 244 + xfers[1].rx_buf = adc->chain_mode_buf; 245 + xfers[1].len = BITS_TO_BYTES(chan->scan_type.storagebits) * n_chain_dev; 246 + xfers[1].bits_per_word = chan->scan_type.realbits; 247 + 248 + spi_message_init_with_transfers(&adc->msg, xfers, 2); 249 + 250 + ret = spi_optimize_message(adc->spi, &adc->msg); 251 + if (ret) 252 + return ret; 253 + 254 + return devm_add_action_or_reset(dev, ad7944_unoptimize_msg, &adc->msg); 255 + } 256 + 219 257 /** 220 258 * ad7944_convert_and_acquire - Perform a single conversion and acquisition 221 259 * @adc: The ADC device structure ··· 265 223 * Perform a conversion and acquisition of a single sample using the 266 224 * pre-optimized adc->msg. 267 225 * 268 - * Upon successful return adc->sample.raw will contain the conversion result. 226 + * Upon successful return adc->sample.raw will contain the conversion result 227 + * (or adc->chain_mode_buf if the device is using chain mode). 269 228 */ 270 229 static int ad7944_convert_and_acquire(struct ad7944_adc *adc, 271 230 const struct iio_chan_spec *chan) ··· 295 252 if (ret) 296 253 return ret; 297 254 298 - if (chan->scan_type.storagebits > 16) 299 - *val = adc->sample.raw.u32; 300 - else 301 - *val = adc->sample.raw.u16; 255 + if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) { 256 + if (chan->scan_type.storagebits > 16) 257 + *val = ((u32 *)adc->chain_mode_buf)[chan->scan_index]; 258 + else 259 + *val = ((u16 *)adc->chain_mode_buf)[chan->scan_index]; 260 + } else { 261 + if (chan->scan_type.storagebits > 16) 262 + *val = adc->sample.raw.u32; 263 + else 264 + *val = adc->sample.raw.u16; 265 + } 302 266 303 267 if (chan->scan_type.sign == 's') 304 268 *val = sign_extend32(*val, chan->scan_type.realbits - 1); ··· 365 315 if (ret) 366 316 goto out; 367 317 368 - iio_push_to_buffers_with_timestamp(indio_dev, &adc->sample.raw, 369 - pf->timestamp); 318 + if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) 319 + iio_push_to_buffers_with_timestamp(indio_dev, adc->chain_mode_buf, 320 + pf->timestamp); 321 + else 322 + iio_push_to_buffers_with_timestamp(indio_dev, &adc->sample.raw, 323 + pf->timestamp); 370 324 371 325 out: 372 326 iio_trigger_notify_done(indio_dev->trig); 373 327 374 328 return IRQ_HANDLED; 329 + } 330 + 331 + /** 332 + * ad7944_chain_mode_alloc - allocate and initialize channel specs and buffers 333 + * for daisy-chained devices 334 + * @dev: The device for devm_ functions 335 + * @chan_template: The channel template for the devices (array of 2 channels 336 + * voltage and timestamp) 337 + * @n_chain_dev: The number of devices in the chain 338 + * @chain_chan: Pointer to receive the allocated channel specs 339 + * @chain_mode_buf: Pointer to receive the allocated rx buffer 340 + * @chain_scan_masks: Pointer to receive the allocated scan masks 341 + * Return: 0 on success, a negative error code on failure 342 + */ 343 + static int ad7944_chain_mode_alloc(struct device *dev, 344 + const struct iio_chan_spec *chan_template, 345 + u32 n_chain_dev, 346 + struct iio_chan_spec **chain_chan, 347 + void **chain_mode_buf, 348 + unsigned long **chain_scan_masks) 349 + { 350 + struct iio_chan_spec *chan; 351 + size_t chain_mode_buf_size; 352 + unsigned long *scan_masks; 353 + void *buf; 354 + int i; 355 + 356 + /* 1 channel for each device in chain plus 1 for soft timestamp */ 357 + 358 + chan = devm_kcalloc(dev, n_chain_dev + 1, sizeof(*chan), GFP_KERNEL); 359 + if (!chan) 360 + return -ENOMEM; 361 + 362 + for (i = 0; i < n_chain_dev; i++) { 363 + chan[i] = chan_template[0]; 364 + 365 + if (chan_template[0].differential) { 366 + chan[i].channel = 2 * i; 367 + chan[i].channel2 = 2 * i + 1; 368 + } else { 369 + chan[i].channel = i; 370 + } 371 + 372 + chan[i].scan_index = i; 373 + } 374 + 375 + /* soft timestamp */ 376 + chan[i] = chan_template[1]; 377 + chan[i].scan_index = i; 378 + 379 + *chain_chan = chan; 380 + 381 + /* 1 word for each voltage channel + aligned u64 for timestamp */ 382 + 383 + chain_mode_buf_size = ALIGN(n_chain_dev * 384 + BITS_TO_BYTES(chan[0].scan_type.storagebits), sizeof(u64)) 385 + + sizeof(u64); 386 + buf = devm_kzalloc(dev, chain_mode_buf_size, GFP_KERNEL); 387 + if (!buf) 388 + return -ENOMEM; 389 + 390 + *chain_mode_buf = buf; 391 + 392 + /* 393 + * Have to limit n_chain_dev due to current implementation of 394 + * available_scan_masks. 395 + */ 396 + if (n_chain_dev > BITS_PER_LONG) 397 + return dev_err_probe(dev, -EINVAL, 398 + "chain is limited to 32 devices\n"); 399 + 400 + scan_masks = devm_kcalloc(dev, 2, sizeof(*scan_masks), GFP_KERNEL); 401 + if (!scan_masks) 402 + return -ENOMEM; 403 + 404 + /* 405 + * Scan mask is needed since we always have to read all devices in the 406 + * chain in one SPI transfer. 407 + */ 408 + scan_masks[0] = GENMASK(n_chain_dev - 1, 0); 409 + 410 + *chain_scan_masks = scan_masks; 411 + 412 + return 0; 375 413 } 376 414 377 415 static const char * const ad7944_power_supplies[] = { ··· 479 341 struct ad7944_adc *adc; 480 342 bool have_refin = false; 481 343 struct regulator *ref; 344 + struct iio_chan_spec *chain_chan; 345 + unsigned long *chain_scan_masks; 346 + u32 n_chain_dev; 482 347 int ret; 483 348 484 349 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); ··· 615 474 616 475 break; 617 476 case AD7944_SPI_MODE_CHAIN: 618 - return dev_err_probe(dev, -EINVAL, "chain mode is not implemented\n"); 477 + ret = device_property_read_u32(dev, "#daisy-chained-devices", 478 + &n_chain_dev); 479 + if (ret) 480 + return dev_err_probe(dev, ret, 481 + "failed to get #daisy-chained-devices\n"); 482 + 483 + ret = ad7944_chain_mode_alloc(dev, chip_info->channels, 484 + n_chain_dev, &chain_chan, 485 + &adc->chain_mode_buf, 486 + &chain_scan_masks); 487 + if (ret) 488 + return ret; 489 + 490 + ret = ad7944_chain_mode_init_msg(dev, adc, &chain_chan[0], 491 + n_chain_dev); 492 + if (ret) 493 + return ret; 494 + 495 + break; 619 496 } 620 497 621 498 indio_dev->name = chip_info->name; 622 499 indio_dev->modes = INDIO_DIRECT_MODE; 623 500 indio_dev->info = &ad7944_iio_info; 624 - indio_dev->channels = chip_info->channels; 625 - indio_dev->num_channels = ARRAY_SIZE(chip_info->channels); 501 + 502 + if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) { 503 + indio_dev->available_scan_masks = chain_scan_masks; 504 + indio_dev->channels = chain_chan; 505 + indio_dev->num_channels = n_chain_dev + 1; 506 + } else { 507 + indio_dev->channels = chip_info->channels; 508 + indio_dev->num_channels = ARRAY_SIZE(chip_info->channels); 509 + } 626 510 627 511 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 628 512 iio_pollfunc_store_time,
+4 -3
drivers/iio/adc/ad799x.c
··· 128 128 struct regulator *vref; 129 129 /* lock to protect against multiple access to the device */ 130 130 struct mutex lock; 131 - unsigned id; 131 + unsigned int id; 132 132 u16 config; 133 133 134 134 u8 *rx_buf; ··· 253 253 } 254 254 } 255 255 256 - static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch) 256 + static int ad799x_scan_direct(struct ad799x_state *st, unsigned int ch) 257 257 { 258 258 u8 cmd; 259 259 ··· 335 335 struct ad799x_state *st = iio_priv(indio_dev); 336 336 337 337 int ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG); 338 + 338 339 if (ret < 0) 339 340 return ret; 340 341 ··· 524 523 return IRQ_HANDLED; 525 524 } 526 525 527 - static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, 526 + static IIO_DEV_ATTR_SAMP_FREQ(0644, 528 527 ad799x_read_frequency, 529 528 ad799x_write_frequency); 530 529 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0");
+335 -39
drivers/iio/adc/ad9467.c
··· 4 4 * 5 5 * Copyright 2012-2020 Analog Devices Inc. 6 6 */ 7 + 8 + #include <linux/bitmap.h> 9 + #include <linux/bitops.h> 7 10 #include <linux/cleanup.h> 11 + #include <linux/debugfs.h> 8 12 #include <linux/module.h> 9 13 #include <linux/mutex.h> 10 14 #include <linux/device.h> ··· 104 100 #define AD9467_DEF_OUTPUT_MODE 0x08 105 101 #define AD9467_REG_VREF_MASK 0x0F 106 102 103 + #define AD9647_MAX_TEST_POINTS 32 104 + 107 105 struct ad9467_chip_info { 108 106 const char *name; 109 107 unsigned int id; ··· 116 110 unsigned long max_rate; 117 111 unsigned int default_output_mode; 118 112 unsigned int vref_mask; 113 + unsigned int num_lanes; 114 + /* data clock output */ 115 + bool has_dco; 119 116 }; 120 117 121 118 struct ad9467_state { ··· 128 119 struct clk *clk; 129 120 unsigned int output_mode; 130 121 unsigned int (*scales)[2]; 131 - 122 + /* 123 + * Times 2 because we may also invert the signal polarity and run the 124 + * calibration again. For some reference on the test points (ad9265) see: 125 + * https://www.analog.com/media/en/technical-documentation/data-sheets/ad9265.pdf 126 + * at page 38 for the dco output delay. On devices as ad9467, the 127 + * calibration is done at the backend level. For the ADI axi-adc: 128 + * https://wiki.analog.com/resources/fpga/docs/axi_adc_ip 129 + * at the io delay control section. 130 + */ 131 + DECLARE_BITMAP(calib_map, AD9647_MAX_TEST_POINTS * 2); 132 132 struct gpio_desc *pwrdown_gpio; 133 133 /* ensure consistent state obtained on multiple related accesses */ 134 134 struct mutex lock; ··· 260 242 .num_channels = ARRAY_SIZE(ad9467_channels), 261 243 .default_output_mode = AD9467_DEF_OUTPUT_MODE, 262 244 .vref_mask = AD9467_REG_VREF_MASK, 245 + .num_lanes = 8, 263 246 }; 264 247 265 248 static const struct ad9467_chip_info ad9434_chip_tbl = { ··· 273 254 .num_channels = ARRAY_SIZE(ad9434_channels), 274 255 .default_output_mode = AD9434_DEF_OUTPUT_MODE, 275 256 .vref_mask = AD9434_REG_VREF_MASK, 257 + .num_lanes = 6, 276 258 }; 277 259 278 260 static const struct ad9467_chip_info ad9265_chip_tbl = { ··· 286 266 .num_channels = ARRAY_SIZE(ad9467_channels), 287 267 .default_output_mode = AD9265_DEF_OUTPUT_MODE, 288 268 .vref_mask = AD9265_REG_VREF_MASK, 269 + .has_dco = true, 289 270 }; 290 271 291 272 static int ad9467_get_scale(struct ad9467_state *st, int *val, int *val2) ··· 342 321 return -EINVAL; 343 322 } 344 323 324 + static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) 325 + { 326 + int ret; 327 + 328 + ret = ad9467_spi_write(spi, AN877_ADC_REG_OUTPUT_MODE, mode); 329 + if (ret < 0) 330 + return ret; 331 + 332 + return ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, 333 + AN877_ADC_TRANSFER_SYNC); 334 + } 335 + 336 + static int ad9647_calibrate_prepare(const struct ad9467_state *st) 337 + { 338 + struct iio_backend_data_fmt data = { 339 + .enable = false, 340 + }; 341 + unsigned int c; 342 + int ret; 343 + 344 + ret = ad9467_spi_write(st->spi, AN877_ADC_REG_TEST_IO, 345 + AN877_ADC_TESTMODE_PN9_SEQ); 346 + if (ret) 347 + return ret; 348 + 349 + ret = ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, 350 + AN877_ADC_TRANSFER_SYNC); 351 + if (ret) 352 + return ret; 353 + 354 + ret = ad9467_outputmode_set(st->spi, st->info->default_output_mode); 355 + if (ret) 356 + return ret; 357 + 358 + for (c = 0; c < st->info->num_channels; c++) { 359 + ret = iio_backend_data_format_set(st->back, c, &data); 360 + if (ret) 361 + return ret; 362 + } 363 + 364 + ret = iio_backend_test_pattern_set(st->back, 0, 365 + IIO_BACKEND_ADI_PRBS_9A); 366 + if (ret) 367 + return ret; 368 + 369 + return iio_backend_chan_enable(st->back, 0); 370 + } 371 + 372 + static int ad9647_calibrate_polarity_set(const struct ad9467_state *st, 373 + bool invert) 374 + { 375 + enum iio_backend_sample_trigger trigger; 376 + 377 + if (st->info->has_dco) { 378 + unsigned int phase = AN877_ADC_OUTPUT_EVEN_ODD_MODE_EN; 379 + 380 + if (invert) 381 + phase |= AN877_ADC_INVERT_DCO_CLK; 382 + 383 + return ad9467_spi_write(st->spi, AN877_ADC_REG_OUTPUT_PHASE, 384 + phase); 385 + } 386 + 387 + if (invert) 388 + trigger = IIO_BACKEND_SAMPLE_TRIGGER_EDGE_FALLING; 389 + else 390 + trigger = IIO_BACKEND_SAMPLE_TRIGGER_EDGE_RISING; 391 + 392 + return iio_backend_data_sample_trigger(st->back, trigger); 393 + } 394 + 395 + /* 396 + * The idea is pretty simple. Find the max number of successful points in a row 397 + * and get the one in the middle. 398 + */ 399 + static unsigned int ad9467_find_optimal_point(const unsigned long *calib_map, 400 + unsigned int start, 401 + unsigned int nbits, 402 + unsigned int *val) 403 + { 404 + unsigned int bit = start, end, start_cnt, cnt = 0; 405 + 406 + for_each_clear_bitrange_from(bit, end, calib_map, nbits + start) { 407 + if (end - bit > cnt) { 408 + cnt = end - bit; 409 + start_cnt = bit; 410 + } 411 + } 412 + 413 + if (cnt) 414 + *val = start_cnt + cnt / 2; 415 + 416 + return cnt; 417 + } 418 + 419 + static int ad9467_calibrate_apply(const struct ad9467_state *st, 420 + unsigned int val) 421 + { 422 + unsigned int lane; 423 + int ret; 424 + 425 + if (st->info->has_dco) { 426 + ret = ad9467_spi_write(st->spi, AN877_ADC_REG_OUTPUT_DELAY, 427 + val); 428 + if (ret) 429 + return ret; 430 + 431 + return ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, 432 + AN877_ADC_TRANSFER_SYNC); 433 + } 434 + 435 + for (lane = 0; lane < st->info->num_lanes; lane++) { 436 + ret = iio_backend_iodelay_set(st->back, lane, val); 437 + if (ret) 438 + return ret; 439 + } 440 + 441 + return 0; 442 + } 443 + 444 + static int ad9647_calibrate_stop(const struct ad9467_state *st) 445 + { 446 + struct iio_backend_data_fmt data = { 447 + .sign_extend = true, 448 + .enable = true, 449 + }; 450 + unsigned int c, mode; 451 + int ret; 452 + 453 + ret = iio_backend_chan_disable(st->back, 0); 454 + if (ret) 455 + return ret; 456 + 457 + ret = iio_backend_test_pattern_set(st->back, 0, 458 + IIO_BACKEND_NO_TEST_PATTERN); 459 + if (ret) 460 + return ret; 461 + 462 + for (c = 0; c < st->info->num_channels; c++) { 463 + ret = iio_backend_data_format_set(st->back, c, &data); 464 + if (ret) 465 + return ret; 466 + } 467 + 468 + mode = st->info->default_output_mode | AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT; 469 + ret = ad9467_outputmode_set(st->spi, mode); 470 + if (ret) 471 + return ret; 472 + 473 + ret = ad9467_spi_write(st->spi, AN877_ADC_REG_TEST_IO, 474 + AN877_ADC_TESTMODE_OFF); 475 + if (ret) 476 + return ret; 477 + 478 + return ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, 479 + AN877_ADC_TRANSFER_SYNC); 480 + } 481 + 482 + static int ad9467_calibrate(struct ad9467_state *st) 483 + { 484 + unsigned int point, val, inv_val, cnt, inv_cnt = 0; 485 + /* 486 + * Half of the bitmap is for the inverted signal. The number of test 487 + * points is the same though... 488 + */ 489 + unsigned int test_points = AD9647_MAX_TEST_POINTS; 490 + unsigned long sample_rate = clk_get_rate(st->clk); 491 + struct device *dev = &st->spi->dev; 492 + bool invert = false, stat; 493 + int ret; 494 + 495 + /* all points invalid */ 496 + bitmap_fill(st->calib_map, BITS_PER_TYPE(st->calib_map)); 497 + 498 + ret = ad9647_calibrate_prepare(st); 499 + if (ret) 500 + return ret; 501 + retune: 502 + ret = ad9647_calibrate_polarity_set(st, invert); 503 + if (ret) 504 + return ret; 505 + 506 + for (point = 0; point < test_points; point++) { 507 + ret = ad9467_calibrate_apply(st, point); 508 + if (ret) 509 + return ret; 510 + 511 + ret = iio_backend_chan_status(st->back, 0, &stat); 512 + if (ret) 513 + return ret; 514 + 515 + __assign_bit(point + invert * test_points, st->calib_map, stat); 516 + } 517 + 518 + if (!invert) { 519 + cnt = ad9467_find_optimal_point(st->calib_map, 0, test_points, 520 + &val); 521 + /* 522 + * We're happy if we find, at least, three good test points in 523 + * a row. 524 + */ 525 + if (cnt < 3) { 526 + invert = true; 527 + goto retune; 528 + } 529 + } else { 530 + inv_cnt = ad9467_find_optimal_point(st->calib_map, test_points, 531 + test_points, &inv_val); 532 + if (!inv_cnt && !cnt) 533 + return -EIO; 534 + } 535 + 536 + if (inv_cnt < cnt) { 537 + ret = ad9647_calibrate_polarity_set(st, false); 538 + if (ret) 539 + return ret; 540 + } else { 541 + /* 542 + * polarity inverted is the last test to run. Hence, there's no 543 + * need to re-do any configuration. We just need to "normalize" 544 + * the selected value. 545 + */ 546 + val = inv_val - test_points; 547 + } 548 + 549 + if (st->info->has_dco) 550 + dev_dbg(dev, "%sDCO 0x%X CLK %lu Hz\n", inv_cnt >= cnt ? "INVERT " : "", 551 + val, sample_rate); 552 + else 553 + dev_dbg(dev, "%sIDELAY 0x%x\n", inv_cnt >= cnt ? "INVERT " : "", 554 + val); 555 + 556 + ret = ad9467_calibrate_apply(st, val); 557 + if (ret) 558 + return ret; 559 + 560 + /* finally apply the optimal value */ 561 + return ad9647_calibrate_stop(st); 562 + } 563 + 345 564 static int ad9467_read_raw(struct iio_dev *indio_dev, 346 565 struct iio_chan_spec const *chan, 347 566 int *val, int *val2, long m) ··· 606 345 { 607 346 struct ad9467_state *st = iio_priv(indio_dev); 608 347 const struct ad9467_chip_info *info = st->info; 348 + unsigned long sample_rate; 609 349 long r_clk; 350 + int ret; 610 351 611 352 switch (mask) { 612 353 case IIO_CHAN_INFO_SCALE: ··· 621 358 return -EINVAL; 622 359 } 623 360 624 - return clk_set_rate(st->clk, r_clk); 361 + sample_rate = clk_get_rate(st->clk); 362 + /* 363 + * clk_set_rate() would also do this but since we would still 364 + * need it for avoiding an unnecessary calibration, do it now. 365 + */ 366 + if (sample_rate == r_clk) 367 + return 0; 368 + 369 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 370 + ret = clk_set_rate(st->clk, r_clk); 371 + if (ret) 372 + return ret; 373 + 374 + guard(mutex)(&st->lock); 375 + ret = ad9467_calibrate(st); 376 + } 377 + return ret; 625 378 default: 626 379 return -EINVAL; 627 380 } ··· 690 411 .read_avail = ad9467_read_avail, 691 412 }; 692 413 693 - static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) 694 - { 695 - int ret; 696 - 697 - ret = ad9467_spi_write(spi, AN877_ADC_REG_OUTPUT_MODE, mode); 698 - if (ret < 0) 699 - return ret; 700 - 701 - return ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, 702 - AN877_ADC_TRANSFER_SYNC); 703 - } 704 - 705 414 static int ad9467_scale_fill(struct ad9467_state *st) 706 415 { 707 416 const struct ad9467_chip_info *info = st->info; ··· 704 437 __ad9467_get_scale(st, i, &val1, &val2); 705 438 st->scales[i][0] = val1; 706 439 st->scales[i][1] = val2; 707 - } 708 - 709 - return 0; 710 - } 711 - 712 - static int ad9467_setup(struct ad9467_state *st) 713 - { 714 - struct iio_backend_data_fmt data = { 715 - .sign_extend = true, 716 - .enable = true, 717 - }; 718 - unsigned int c, mode; 719 - int ret; 720 - 721 - mode = st->info->default_output_mode | AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT; 722 - ret = ad9467_outputmode_set(st->spi, mode); 723 - if (ret) 724 - return ret; 725 - 726 - for (c = 0; c < st->info->num_channels; c++) { 727 - ret = iio_backend_data_format_set(st->back, c, &data); 728 - if (ret) 729 - return ret; 730 440 } 731 441 732 442 return 0; ··· 765 521 return -ENODEV; 766 522 } 767 523 524 + static ssize_t ad9467_dump_calib_table(struct file *file, 525 + char __user *userbuf, 526 + size_t count, loff_t *ppos) 527 + { 528 + struct ad9467_state *st = file->private_data; 529 + unsigned int bit, size = BITS_PER_TYPE(st->calib_map); 530 + /* +2 for the newline and +1 for the string termination */ 531 + unsigned char map[AD9647_MAX_TEST_POINTS * 2 + 3]; 532 + ssize_t len = 0; 533 + 534 + guard(mutex)(&st->lock); 535 + if (*ppos) 536 + goto out_read; 537 + 538 + for (bit = 0; bit < size; bit++) { 539 + if (bit == size / 2) 540 + len += scnprintf(map + len, sizeof(map) - len, "\n"); 541 + 542 + len += scnprintf(map + len, sizeof(map) - len, "%c", 543 + test_bit(bit, st->calib_map) ? 'x' : 'o'); 544 + } 545 + 546 + len += scnprintf(map + len, sizeof(map) - len, "\n"); 547 + out_read: 548 + return simple_read_from_buffer(userbuf, count, ppos, map, len); 549 + } 550 + 551 + static const struct file_operations ad9467_calib_table_fops = { 552 + .open = simple_open, 553 + .read = ad9467_dump_calib_table, 554 + .llseek = default_llseek, 555 + .owner = THIS_MODULE, 556 + }; 557 + 558 + static void ad9467_debugfs_init(struct iio_dev *indio_dev) 559 + { 560 + struct dentry *d = iio_get_debugfs_dentry(indio_dev); 561 + struct ad9467_state *st = iio_priv(indio_dev); 562 + 563 + if (!IS_ENABLED(CONFIG_DEBUG_FS)) 564 + return; 565 + 566 + debugfs_create_file("calibration_table_dump", 0400, d, st, 567 + &ad9467_calib_table_fops); 568 + } 569 + 768 570 static int ad9467_probe(struct spi_device *spi) 769 571 { 770 572 struct iio_dev *indio_dev; ··· 870 580 if (ret) 871 581 return ret; 872 582 873 - ret = ad9467_setup(st); 583 + ret = ad9467_calibrate(st); 874 584 if (ret) 875 585 return ret; 876 586 877 - return devm_iio_device_register(&spi->dev, indio_dev); 587 + ret = devm_iio_device_register(&spi->dev, indio_dev); 588 + if (ret) 589 + return ret; 590 + 591 + ad9467_debugfs_init(indio_dev); 592 + 593 + return 0; 878 594 } 879 595 880 596 static const struct of_device_id ad9467_of_match[] = {
+3 -3
drivers/iio/adc/ad_sigma_delta.c
··· 206 206 unsigned int mode, unsigned int channel) 207 207 { 208 208 int ret; 209 - unsigned long timeout; 209 + unsigned long time_left; 210 210 211 211 ret = ad_sigma_delta_set_channel(sigma_delta, channel); 212 212 if (ret) ··· 223 223 224 224 sigma_delta->irq_dis = false; 225 225 enable_irq(sigma_delta->irq_line); 226 - timeout = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ); 227 - if (timeout == 0) { 226 + time_left = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ); 227 + if (time_left == 0) { 228 228 sigma_delta->irq_dis = true; 229 229 disable_irq_nosync(sigma_delta->irq_line); 230 230 ret = -EIO;
+124 -3
drivers/iio/adc/adi-axi-adc.c
··· 7 7 */ 8 8 9 9 #include <linux/bitfield.h> 10 + #include <linux/cleanup.h> 10 11 #include <linux/clk.h> 11 12 #include <linux/err.h> 12 13 #include <linux/io.h> 13 14 #include <linux/delay.h> 14 15 #include <linux/module.h> 16 + #include <linux/mutex.h> 15 17 #include <linux/of.h> 16 18 #include <linux/platform_device.h> 17 19 #include <linux/property.h> ··· 39 37 #define ADI_AXI_REG_RSTN_MMCM_RSTN BIT(1) 40 38 #define ADI_AXI_REG_RSTN_RSTN BIT(0) 41 39 40 + #define ADI_AXI_ADC_REG_CTRL 0x0044 41 + #define ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK BIT(1) 42 + 42 43 /* ADC Channel controls */ 43 44 44 45 #define ADI_AXI_REG_CHAN_CTRL(c) (0x0400 + (c) * 0x40) ··· 56 51 #define ADI_AXI_REG_CHAN_CTRL_PN_TYPE_OWR BIT(1) 57 52 #define ADI_AXI_REG_CHAN_CTRL_ENABLE BIT(0) 58 53 54 + #define ADI_AXI_ADC_REG_CHAN_STATUS(c) (0x0404 + (c) * 0x40) 55 + #define ADI_AXI_ADC_CHAN_STAT_PN_MASK GENMASK(2, 1) 56 + 57 + #define ADI_AXI_ADC_REG_CHAN_CTRL_3(c) (0x0418 + (c) * 0x40) 58 + #define ADI_AXI_ADC_CHAN_PN_SEL_MASK GENMASK(19, 16) 59 + 60 + /* IO Delays */ 61 + #define ADI_AXI_ADC_REG_DELAY(l) (0x0800 + (l) * 0x4) 62 + #define AXI_ADC_DELAY_CTRL_MASK GENMASK(4, 0) 63 + 64 + #define ADI_AXI_ADC_MAX_IO_NUM_LANES 15 65 + 59 66 #define ADI_AXI_REG_CHAN_CTRL_DEFAULTS \ 60 67 (ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT | \ 61 68 ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ 62 69 ADI_AXI_REG_CHAN_CTRL_ENABLE) 63 70 64 71 struct adi_axi_adc_state { 65 - struct regmap *regmap; 66 - struct device *dev; 72 + struct regmap *regmap; 73 + struct device *dev; 74 + /* lock to protect multiple accesses to the device registers */ 75 + struct mutex lock; 67 76 }; 68 77 69 78 static int axi_adc_enable(struct iio_backend *back) ··· 123 104 ADI_AXI_REG_CHAN_CTRL_FMT_MASK, val); 124 105 } 125 106 107 + static int axi_adc_data_sample_trigger(struct iio_backend *back, 108 + enum iio_backend_sample_trigger trigger) 109 + { 110 + struct adi_axi_adc_state *st = iio_backend_get_priv(back); 111 + 112 + switch (trigger) { 113 + case IIO_BACKEND_SAMPLE_TRIGGER_EDGE_RISING: 114 + return regmap_clear_bits(st->regmap, ADI_AXI_ADC_REG_CTRL, 115 + ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK); 116 + case IIO_BACKEND_SAMPLE_TRIGGER_EDGE_FALLING: 117 + return regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CTRL, 118 + ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK); 119 + default: 120 + return -EINVAL; 121 + } 122 + } 123 + 124 + static int axi_adc_iodelays_set(struct iio_backend *back, unsigned int lane, 125 + unsigned int tap) 126 + { 127 + struct adi_axi_adc_state *st = iio_backend_get_priv(back); 128 + int ret; 129 + u32 val; 130 + 131 + if (tap > FIELD_MAX(AXI_ADC_DELAY_CTRL_MASK)) 132 + return -EINVAL; 133 + if (lane > ADI_AXI_ADC_MAX_IO_NUM_LANES) 134 + return -EINVAL; 135 + 136 + guard(mutex)(&st->lock); 137 + ret = regmap_write(st->regmap, ADI_AXI_ADC_REG_DELAY(lane), tap); 138 + if (ret) 139 + return ret; 140 + /* 141 + * If readback is ~0, that means there are issues with the 142 + * delay_clk. 143 + */ 144 + ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_DELAY(lane), &val); 145 + if (ret) 146 + return ret; 147 + if (val == U32_MAX) 148 + return -EIO; 149 + 150 + return 0; 151 + } 152 + 153 + static int axi_adc_test_pattern_set(struct iio_backend *back, 154 + unsigned int chan, 155 + enum iio_backend_test_pattern pattern) 156 + { 157 + struct adi_axi_adc_state *st = iio_backend_get_priv(back); 158 + 159 + switch (pattern) { 160 + case IIO_BACKEND_NO_TEST_PATTERN: 161 + /* nothing to do */ 162 + return 0; 163 + case IIO_BACKEND_ADI_PRBS_9A: 164 + return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CHAN_CTRL_3(chan), 165 + ADI_AXI_ADC_CHAN_PN_SEL_MASK, 166 + FIELD_PREP(ADI_AXI_ADC_CHAN_PN_SEL_MASK, 0)); 167 + default: 168 + return -EINVAL; 169 + } 170 + } 171 + 172 + static int axi_adc_chan_status(struct iio_backend *back, unsigned int chan, 173 + bool *error) 174 + { 175 + struct adi_axi_adc_state *st = iio_backend_get_priv(back); 176 + int ret; 177 + u32 val; 178 + 179 + guard(mutex)(&st->lock); 180 + /* reset test bits by setting them */ 181 + ret = regmap_write(st->regmap, ADI_AXI_ADC_REG_CHAN_STATUS(chan), 182 + ADI_AXI_ADC_CHAN_STAT_PN_MASK); 183 + if (ret) 184 + return ret; 185 + 186 + /* let's give enough time to validate or erroring the incoming pattern */ 187 + fsleep(1000); 188 + 189 + ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_CHAN_STATUS(chan), &val); 190 + if (ret) 191 + return ret; 192 + 193 + if (ADI_AXI_ADC_CHAN_STAT_PN_MASK & val) 194 + *error = true; 195 + else 196 + *error = false; 197 + 198 + return 0; 199 + } 200 + 126 201 static int axi_adc_chan_enable(struct iio_backend *back, unsigned int chan) 127 202 { 128 203 struct adi_axi_adc_state *st = iio_backend_get_priv(back); ··· 255 142 .val_bits = 32, 256 143 .reg_bits = 32, 257 144 .reg_stride = 4, 258 - .max_register = 0x0800, 259 145 }; 260 146 261 147 static const struct iio_backend_ops adi_axi_adc_generic = { ··· 265 153 .chan_disable = axi_adc_chan_disable, 266 154 .request_buffer = axi_adc_request_buffer, 267 155 .free_buffer = axi_adc_free_buffer, 156 + .data_sample_trigger = axi_adc_data_sample_trigger, 157 + .iodelay_set = axi_adc_iodelays_set, 158 + .test_pattern_set = axi_adc_test_pattern_set, 159 + .chan_status = axi_adc_chan_status, 268 160 }; 269 161 270 162 static int adi_axi_adc_probe(struct platform_device *pdev) ··· 277 161 struct adi_axi_adc_state *st; 278 162 void __iomem *base; 279 163 unsigned int ver; 164 + struct clk *clk; 280 165 int ret; 281 166 282 167 st = devm_kzalloc(&pdev->dev, sizeof(*st), GFP_KERNEL); ··· 297 180 expected_ver = device_get_match_data(&pdev->dev); 298 181 if (!expected_ver) 299 182 return -ENODEV; 183 + 184 + clk = devm_clk_get_enabled(&pdev->dev, NULL); 185 + if (IS_ERR(clk)) 186 + return PTR_ERR(clk); 300 187 301 188 /* 302 189 * Force disable the core. Up to the frontend to enable us. And we can
+8 -8
drivers/iio/adc/exynos_adc.c
··· 538 538 long mask) 539 539 { 540 540 struct exynos_adc *info = iio_priv(indio_dev); 541 - unsigned long timeout; 541 + unsigned long time_left; 542 542 int ret; 543 543 544 544 if (mask == IIO_CHAN_INFO_SCALE) { ··· 562 562 if (info->data->start_conv) 563 563 info->data->start_conv(info, chan->address); 564 564 565 - timeout = wait_for_completion_timeout(&info->completion, 566 - EXYNOS_ADC_TIMEOUT); 567 - if (timeout == 0) { 565 + time_left = wait_for_completion_timeout(&info->completion, 566 + EXYNOS_ADC_TIMEOUT); 567 + if (time_left == 0) { 568 568 dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n"); 569 569 if (info->data->init_hw) 570 570 info->data->init_hw(info); ··· 583 583 static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y) 584 584 { 585 585 struct exynos_adc *info = iio_priv(indio_dev); 586 - unsigned long timeout; 586 + unsigned long time_left; 587 587 int ret; 588 588 589 589 mutex_lock(&info->lock); ··· 597 597 /* Select the ts channel to be used and Trigger conversion */ 598 598 info->data->start_conv(info, ADC_S3C2410_MUX_TS); 599 599 600 - timeout = wait_for_completion_timeout(&info->completion, 601 - EXYNOS_ADC_TIMEOUT); 602 - if (timeout == 0) { 600 + time_left = wait_for_completion_timeout(&info->completion, 601 + EXYNOS_ADC_TIMEOUT); 602 + if (time_left == 0) { 603 603 dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n"); 604 604 if (info->data->init_hw) 605 605 info->data->init_hw(info);
+5 -5
drivers/iio/adc/fsl-imx25-gcq.c
··· 108 108 struct mx25_gcq_priv *priv, 109 109 int *val) 110 110 { 111 - long timeout; 111 + long time_left; 112 112 u32 data; 113 113 114 114 /* Setup the configuration we want to use */ ··· 121 121 regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS, 122 122 MX25_ADCQ_CR_FQS); 123 123 124 - timeout = wait_for_completion_interruptible_timeout( 124 + time_left = wait_for_completion_interruptible_timeout( 125 125 &priv->completed, MX25_GCQ_TIMEOUT); 126 - if (timeout < 0) { 126 + if (time_left < 0) { 127 127 dev_err(dev, "ADC wait for measurement failed\n"); 128 - return timeout; 129 - } else if (timeout == 0) { 128 + return time_left; 129 + } else if (time_left == 0) { 130 130 dev_err(dev, "ADC timed out\n"); 131 131 return -ETIMEDOUT; 132 132 }
+6 -6
drivers/iio/adc/intel_mrfld_adc.c
··· 75 75 struct mrfld_adc *adc = iio_priv(indio_dev); 76 76 struct regmap *regmap = adc->regmap; 77 77 unsigned int req; 78 - long timeout; 78 + long time_left; 79 79 __be16 value; 80 80 int ret; 81 81 ··· 95 95 if (ret) 96 96 goto done; 97 97 98 - timeout = wait_for_completion_interruptible_timeout(&adc->completion, 99 - BCOVE_ADC_TIMEOUT); 100 - if (timeout < 0) { 101 - ret = timeout; 98 + time_left = wait_for_completion_interruptible_timeout(&adc->completion, 99 + BCOVE_ADC_TIMEOUT); 100 + if (time_left < 0) { 101 + ret = time_left; 102 102 goto done; 103 103 } 104 - if (timeout == 0) { 104 + if (time_left == 0) { 105 105 ret = -ETIMEDOUT; 106 106 goto done; 107 107 }
+7 -9
drivers/iio/adc/mcp3564.c
··· 998 998 struct mcp3564_state *adc = iio_priv(indio_dev); 999 999 struct device *dev = &adc->spi->dev; 1000 1000 struct iio_chan_spec *channels; 1001 - struct fwnode_handle *child; 1002 1001 struct iio_chan_spec chanspec = mcp3564_channel_template; 1003 1002 struct iio_chan_spec temp_chanspec = mcp3564_temp_channel_template; 1004 1003 struct iio_chan_spec burnout_chanspec = mcp3564_burnout_channel_template; ··· 1024 1025 if (!channels) 1025 1026 return dev_err_probe(dev, -ENOMEM, "Can't allocate memory\n"); 1026 1027 1027 - device_for_each_child_node(dev, child) { 1028 + device_for_each_child_node_scoped(dev, child) { 1028 1029 node_name = fwnode_get_name(child); 1029 1030 1030 1031 if (fwnode_property_present(child, "diff-channels")) { ··· 1032 1033 "diff-channels", 1033 1034 inputs, 1034 1035 ARRAY_SIZE(inputs)); 1036 + if (ret) 1037 + return ret; 1038 + 1035 1039 chanspec.differential = 1; 1036 1040 } else { 1037 1041 ret = fwnode_property_read_u32(child, "reg", &inputs[0]); 1042 + if (ret) 1043 + return ret; 1038 1044 1039 1045 chanspec.differential = 0; 1040 1046 inputs[1] = MCP3564_AGND; 1041 1047 } 1042 - if (ret) { 1043 - fwnode_handle_put(child); 1044 - return ret; 1045 - } 1046 1048 1047 1049 if (inputs[0] > MCP3564_INTERNAL_VCM || 1048 - inputs[1] > MCP3564_INTERNAL_VCM) { 1049 - fwnode_handle_put(child); 1050 + inputs[1] > MCP3564_INTERNAL_VCM) 1050 1051 return dev_err_probe(&indio_dev->dev, -EINVAL, 1051 1052 "Channel index > %d, for %s\n", 1052 1053 MCP3564_INTERNAL_VCM + 1, 1053 1054 node_name); 1054 - } 1055 1055 1056 1056 chanspec.address = (inputs[0] << 4) | inputs[1]; 1057 1057 chanspec.channel = inputs[0];
-1
drivers/iio/adc/mxs-lradc-adc.c
··· 724 724 iio->dev.of_node = dev->parent->of_node; 725 725 iio->info = &mxs_lradc_adc_iio_info; 726 726 iio->modes = INDIO_DIRECT_MODE; 727 - iio->masklength = LRADC_MAX_TOTAL_CHANS; 728 727 729 728 if (lradc->soc == IMX23_LRADC) { 730 729 iio->channels = mx23_lradc_chan_spec;
+9
drivers/iio/adc/pac1934.c
··· 787 787 s64 curr_energy; 788 788 int ret, channel = chan->channel - 1; 789 789 790 + /* 791 + * For AVG the index should be between 5 to 8. 792 + * To calculate PAC1934_CH_VOLTAGE_AVERAGE, 793 + * respectively PAC1934_CH_CURRENT real index, we need 794 + * to remove the added offset (PAC1934_MAX_NUM_CHANNELS). 795 + */ 796 + if (channel >= PAC1934_MAX_NUM_CHANNELS) 797 + channel = channel - PAC1934_MAX_NUM_CHANNELS; 798 + 790 799 ret = pac1934_retrieve_data(info, PAC1934_MIN_UPDATE_WAIT_TIME_US); 791 800 if (ret < 0) 792 801 return ret;
+11 -23
drivers/iio/adc/rtq6056.c
··· 520 520 { 521 521 struct rtq6056_priv *priv = iio_priv(indio_dev); 522 522 const struct richtek_dev_data *devdata = priv->devdata; 523 - int ret; 524 523 525 - ret = iio_device_claim_direct_mode(indio_dev); 526 - if (ret) 527 - return ret; 528 - 529 - switch (mask) { 530 - case IIO_CHAN_INFO_SAMP_FREQ: 531 - if (devdata->fixed_samp_freq) { 532 - ret = -EINVAL; 533 - break; 524 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 525 + switch (mask) { 526 + case IIO_CHAN_INFO_SAMP_FREQ: 527 + if (devdata->fixed_samp_freq) 528 + return -EINVAL; 529 + return rtq6056_adc_set_samp_freq(priv, chan, val); 530 + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 531 + return devdata->set_average(priv, val); 532 + default: 533 + return -EINVAL; 534 534 } 535 - 536 - ret = rtq6056_adc_set_samp_freq(priv, chan, val); 537 - break; 538 - case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 539 - ret = devdata->set_average(priv, val); 540 - break; 541 - default: 542 - ret = -EINVAL; 543 - break; 544 535 } 545 - 546 - iio_device_release_direct_mode(indio_dev); 547 - 548 - return ret; 536 + unreachable(); 549 537 } 550 538 551 539 static const char *rtq6056_channel_labels[RTQ6056_MAX_CHANNEL] = {
+5 -5
drivers/iio/adc/stm32-adc.c
··· 1408 1408 struct stm32_adc *adc = iio_priv(indio_dev); 1409 1409 struct device *dev = indio_dev->dev.parent; 1410 1410 const struct stm32_adc_regspec *regs = adc->cfg->regs; 1411 - long timeout; 1411 + long time_left; 1412 1412 u32 val; 1413 1413 int ret; 1414 1414 ··· 1440 1440 1441 1441 adc->cfg->start_conv(indio_dev, false); 1442 1442 1443 - timeout = wait_for_completion_interruptible_timeout( 1443 + time_left = wait_for_completion_interruptible_timeout( 1444 1444 &adc->completion, STM32_ADC_TIMEOUT); 1445 - if (timeout == 0) { 1445 + if (time_left == 0) { 1446 1446 ret = -ETIMEDOUT; 1447 - } else if (timeout < 0) { 1448 - ret = timeout; 1447 + } else if (time_left < 0) { 1448 + ret = time_left; 1449 1449 } else { 1450 1450 *res = adc->buffer[0]; 1451 1451 ret = IIO_VAL_INT;
+6 -6
drivers/iio/adc/stm32-dfsdm-adc.c
··· 1116 1116 const struct iio_chan_spec *chan, int *res) 1117 1117 { 1118 1118 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); 1119 - long timeout; 1119 + long time_left; 1120 1120 int ret; 1121 1121 1122 1122 reinit_completion(&adc->completion); ··· 1141 1141 goto stop_dfsdm; 1142 1142 } 1143 1143 1144 - timeout = wait_for_completion_interruptible_timeout(&adc->completion, 1145 - DFSDM_TIMEOUT); 1144 + time_left = wait_for_completion_interruptible_timeout(&adc->completion, 1145 + DFSDM_TIMEOUT); 1146 1146 1147 1147 /* Mask IRQ for regular conversion achievement*/ 1148 1148 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), 1149 1149 DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0)); 1150 1150 1151 - if (timeout == 0) 1151 + if (time_left == 0) 1152 1152 ret = -ETIMEDOUT; 1153 - else if (timeout < 0) 1154 - ret = timeout; 1153 + else if (time_left < 0) 1154 + ret = time_left; 1155 1155 else 1156 1156 ret = IIO_VAL_INT; 1157 1157
+1 -4
drivers/iio/adc/ti-ads1015.c
··· 902 902 struct iio_dev *indio_dev = i2c_get_clientdata(client); 903 903 struct ads1015_data *data = iio_priv(indio_dev); 904 904 struct device *dev = &client->dev; 905 - struct fwnode_handle *node; 906 905 int i = -1; 907 906 908 - device_for_each_child_node(dev, node) { 907 + device_for_each_child_node_scoped(dev, node) { 909 908 u32 pval; 910 909 unsigned int channel; 911 910 unsigned int pga = ADS1015_DEFAULT_PGA; ··· 926 927 pga = pval; 927 928 if (pga > 5) { 928 929 dev_err(dev, "invalid gain on %pfw\n", node); 929 - fwnode_handle_put(node); 930 930 return -EINVAL; 931 931 } 932 932 } ··· 934 936 data_rate = pval; 935 937 if (data_rate > 7) { 936 938 dev_err(dev, "invalid data_rate on %pfw\n", node); 937 - fwnode_handle_put(node); 938 939 return -EINVAL; 939 940 } 940 941 }
+4 -4
drivers/iio/adc/twl6030-gpadc.c
··· 519 519 { 520 520 struct twl6030_gpadc_data *gpadc = iio_priv(indio_dev); 521 521 int ret; 522 - long timeout; 522 + long time_left; 523 523 524 524 mutex_lock(&gpadc->lock); 525 525 ··· 529 529 goto err; 530 530 } 531 531 /* wait for conversion to complete */ 532 - timeout = wait_for_completion_interruptible_timeout( 532 + time_left = wait_for_completion_interruptible_timeout( 533 533 &gpadc->irq_complete, msecs_to_jiffies(5000)); 534 - if (timeout == 0) { 534 + if (time_left == 0) { 535 535 ret = -ETIMEDOUT; 536 536 goto err; 537 - } else if (timeout < 0) { 537 + } else if (time_left < 0) { 538 538 ret = -EINTR; 539 539 goto err; 540 540 }
+18 -15
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
··· 70 70 } 71 71 EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_update_odr, IIO_INV_SENSORS_TIMESTAMP); 72 72 73 - static bool inv_validate_period(struct inv_sensors_timestamp *ts, uint32_t period, uint32_t mult) 73 + static bool inv_validate_period(struct inv_sensors_timestamp *ts, uint32_t period) 74 74 { 75 75 uint32_t period_min, period_max; 76 76 77 77 /* check that period is acceptable */ 78 - period_min = ts->min_period * mult; 79 - period_max = ts->max_period * mult; 78 + period_min = ts->min_period * ts->mult; 79 + period_max = ts->max_period * ts->mult; 80 80 if (period > period_min && period < period_max) 81 81 return true; 82 82 else ··· 84 84 } 85 85 86 86 static bool inv_update_chip_period(struct inv_sensors_timestamp *ts, 87 - uint32_t mult, uint32_t period) 87 + uint32_t period) 88 88 { 89 89 uint32_t new_chip_period; 90 90 91 - if (!inv_validate_period(ts, period, mult)) 91 + if (!inv_validate_period(ts, period)) 92 92 return false; 93 93 94 94 /* update chip internal period estimation */ 95 - new_chip_period = period / mult; 95 + new_chip_period = period / ts->mult; 96 96 inv_update_acc(&ts->chip_period, new_chip_period); 97 97 ts->period = ts->mult * ts->chip_period.val; 98 98 ··· 101 101 102 102 static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts) 103 103 { 104 + const int64_t period_min = ts->min_period * ts->mult; 105 + const int64_t period_max = ts->max_period * ts->mult; 106 + int64_t add_max, sub_max; 104 107 int64_t delta, jitter; 105 108 int64_t adjust; 106 109 ··· 111 108 delta = ts->it.lo - ts->timestamp; 112 109 113 110 /* adjust timestamp while respecting jitter */ 111 + add_max = period_max - (int64_t)ts->period; 112 + sub_max = period_min - (int64_t)ts->period; 114 113 jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter); 115 114 if (delta > jitter) 116 - adjust = jitter; 115 + adjust = add_max; 117 116 else if (delta < -jitter) 118 - adjust = -jitter; 117 + adjust = sub_max; 119 118 else 120 119 adjust = 0; 121 120 ··· 125 120 } 126 121 127 122 void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, 128 - uint32_t fifo_period, size_t fifo_nb, 129 - size_t sensor_nb, int64_t timestamp) 123 + size_t sample_nb, int64_t timestamp) 130 124 { 131 125 struct inv_sensors_timestamp_interval *it; 132 126 int64_t delta, interval; 133 - const uint32_t fifo_mult = fifo_period / ts->chip.clock_period; 134 127 uint32_t period; 135 128 bool valid = false; 136 129 137 - if (fifo_nb == 0) 130 + if (sample_nb == 0) 138 131 return; 139 132 140 133 /* update interrupt timestamp and compute chip and sensor periods */ ··· 142 139 delta = it->up - it->lo; 143 140 if (it->lo != 0) { 144 141 /* compute period: delta time divided by number of samples */ 145 - period = div_s64(delta, fifo_nb); 146 - valid = inv_update_chip_period(ts, fifo_mult, period); 142 + period = div_s64(delta, sample_nb); 143 + valid = inv_update_chip_period(ts, period); 147 144 } 148 145 149 146 /* no previous data, compute theoritical value from interrupt */ 150 147 if (ts->timestamp == 0) { 151 148 /* elapsed time: sensor period * sensor samples number */ 152 - interval = (int64_t)ts->period * (int64_t)sensor_nb; 149 + interval = (int64_t)ts->period * (int64_t)sample_nb; 153 150 ts->timestamp = it->up - interval; 154 151 return; 155 152 }
+3 -2
drivers/iio/dac/ad9739a.c
··· 45 45 #define AD9739A_REG_MU_DUTY 0x25 46 46 #define AD9739A_REG_MU_CNT1 0x26 47 47 #define AD9739A_MU_EN_MASK BIT(0) 48 + #define AD9739A_MU_GAIN_MASK BIT(1) 48 49 #define AD9739A_REG_MU_CNT2 0x27 49 50 #define AD9739A_REG_MU_CNT3 0x28 50 51 #define AD9739A_REG_MU_CNT4 0x29 ··· 221 220 return ret; 222 221 223 222 /* Enable the Mu controller search and track mode. */ 224 - ret = regmap_set_bits(st->regmap, AD9739A_REG_MU_CNT1, 225 - AD9739A_MU_EN_MASK); 223 + ret = regmap_write(st->regmap, AD9739A_REG_MU_CNT1, 224 + AD9739A_MU_EN_MASK | AD9739A_MU_GAIN_MASK); 226 225 if (ret) 227 226 return ret; 228 227
+3 -3
drivers/iio/dac/adi-axi-dac.c
··· 383 383 case AXI_DAC_FREQ_TONE_1: 384 384 case AXI_DAC_FREQ_TONE_2: 385 385 return axi_dac_frequency_set(st, chan, buf, len, 386 - private - AXI_DAC_FREQ_TONE_1); 386 + private == AXI_DAC_FREQ_TONE_2); 387 387 case AXI_DAC_SCALE_TONE_1: 388 388 case AXI_DAC_SCALE_TONE_2: 389 389 return axi_dac_scale_set(st, chan, buf, len, 390 - private - AXI_DAC_SCALE_TONE_1); 390 + private == AXI_DAC_SCALE_TONE_2); 391 391 case AXI_DAC_PHASE_TONE_1: 392 392 case AXI_DAC_PHASE_TONE_2: 393 393 return axi_dac_phase_set(st, chan, buf, len, 394 - private - AXI_DAC_PHASE_TONE_2); 394 + private == AXI_DAC_PHASE_TONE_2); 395 395 default: 396 396 return -EOPNOTSUPP; 397 397 }
+35
drivers/iio/imu/inv_icm42600/inv_icm42600.h
··· 13 13 #include <linux/regulator/consumer.h> 14 14 #include <linux/pm.h> 15 15 #include <linux/iio/iio.h> 16 + #include <linux/iio/common/inv_sensors_timestamp.h> 16 17 17 18 #include "inv_icm42600_buffer.h" 18 19 ··· 22 21 INV_CHIP_ICM42600, 23 22 INV_CHIP_ICM42602, 24 23 INV_CHIP_ICM42605, 24 + INV_CHIP_ICM42686, 25 25 INV_CHIP_ICM42622, 26 26 INV_CHIP_ICM42688, 27 27 INV_CHIP_ICM42631, ··· 59 57 INV_ICM42600_GYRO_FS_15_625DPS, 60 58 INV_ICM42600_GYRO_FS_NB, 61 59 }; 60 + enum inv_icm42686_gyro_fs { 61 + INV_ICM42686_GYRO_FS_4000DPS, 62 + INV_ICM42686_GYRO_FS_2000DPS, 63 + INV_ICM42686_GYRO_FS_1000DPS, 64 + INV_ICM42686_GYRO_FS_500DPS, 65 + INV_ICM42686_GYRO_FS_250DPS, 66 + INV_ICM42686_GYRO_FS_125DPS, 67 + INV_ICM42686_GYRO_FS_62_5DPS, 68 + INV_ICM42686_GYRO_FS_31_25DPS, 69 + INV_ICM42686_GYRO_FS_NB, 70 + }; 62 71 63 72 /* accelerometer fullscale values */ 64 73 enum inv_icm42600_accel_fs { ··· 78 65 INV_ICM42600_ACCEL_FS_4G, 79 66 INV_ICM42600_ACCEL_FS_2G, 80 67 INV_ICM42600_ACCEL_FS_NB, 68 + }; 69 + enum inv_icm42686_accel_fs { 70 + INV_ICM42686_ACCEL_FS_32G, 71 + INV_ICM42686_ACCEL_FS_16G, 72 + INV_ICM42686_ACCEL_FS_8G, 73 + INV_ICM42686_ACCEL_FS_4G, 74 + INV_ICM42686_ACCEL_FS_2G, 75 + INV_ICM42686_ACCEL_FS_NB, 81 76 }; 82 77 83 78 /* ODR suffixed by LN or LP are Low-Noise or Low-Power mode only */ ··· 170 149 int64_t gyro; 171 150 int64_t accel; 172 151 } timestamp; 152 + }; 153 + 154 + 155 + /** 156 + * struct inv_icm42600_sensor_state - sensor state variables 157 + * @scales: table of scales. 158 + * @scales_len: length (nb of items) of the scales table. 159 + * @ts: timestamp module states. 160 + */ 161 + struct inv_icm42600_sensor_state { 162 + const int *scales; 163 + size_t scales_len; 164 + struct inv_sensors_timestamp ts; 173 165 }; 174 166 175 167 /* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */ ··· 338 304 #define INV_ICM42600_WHOAMI_ICM42600 0x40 339 305 #define INV_ICM42600_WHOAMI_ICM42602 0x41 340 306 #define INV_ICM42600_WHOAMI_ICM42605 0x42 307 + #define INV_ICM42600_WHOAMI_ICM42686 0x44 341 308 #define INV_ICM42600_WHOAMI_ICM42622 0x46 342 309 #define INV_ICM42600_WHOAMI_ICM42688 0x47 343 310 #define INV_ICM42600_WHOAMI_ICM42631 0x5C
+56 -19
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
··· 99 99 const unsigned long *scan_mask) 100 100 { 101 101 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 102 - struct inv_sensors_timestamp *ts = iio_priv(indio_dev); 102 + struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev); 103 + struct inv_sensors_timestamp *ts = &accel_st->ts; 103 104 struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; 104 105 unsigned int fifo_en = 0; 105 106 unsigned int sleep_temp = 0; ··· 211 210 [2 * INV_ICM42600_ACCEL_FS_2G] = 0, 212 211 [2 * INV_ICM42600_ACCEL_FS_2G + 1] = 598550, 213 212 }; 213 + static const int inv_icm42686_accel_scale[] = { 214 + /* +/- 32G => 0.009576807 m/s-2 */ 215 + [2 * INV_ICM42686_ACCEL_FS_32G] = 0, 216 + [2 * INV_ICM42686_ACCEL_FS_32G + 1] = 9576807, 217 + /* +/- 16G => 0.004788403 m/s-2 */ 218 + [2 * INV_ICM42686_ACCEL_FS_16G] = 0, 219 + [2 * INV_ICM42686_ACCEL_FS_16G + 1] = 4788403, 220 + /* +/- 8G => 0.002394202 m/s-2 */ 221 + [2 * INV_ICM42686_ACCEL_FS_8G] = 0, 222 + [2 * INV_ICM42686_ACCEL_FS_8G + 1] = 2394202, 223 + /* +/- 4G => 0.001197101 m/s-2 */ 224 + [2 * INV_ICM42686_ACCEL_FS_4G] = 0, 225 + [2 * INV_ICM42686_ACCEL_FS_4G + 1] = 1197101, 226 + /* +/- 2G => 0.000598550 m/s-2 */ 227 + [2 * INV_ICM42686_ACCEL_FS_2G] = 0, 228 + [2 * INV_ICM42686_ACCEL_FS_2G + 1] = 598550, 229 + }; 214 230 215 - static int inv_icm42600_accel_read_scale(struct inv_icm42600_state *st, 231 + static int inv_icm42600_accel_read_scale(struct iio_dev *indio_dev, 216 232 int *val, int *val2) 217 233 { 234 + struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 235 + struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev); 218 236 unsigned int idx; 219 237 220 238 idx = st->conf.accel.fs; 221 239 222 - *val = inv_icm42600_accel_scale[2 * idx]; 223 - *val2 = inv_icm42600_accel_scale[2 * idx + 1]; 240 + *val = accel_st->scales[2 * idx]; 241 + *val2 = accel_st->scales[2 * idx + 1]; 224 242 return IIO_VAL_INT_PLUS_NANO; 225 243 } 226 244 227 - static int inv_icm42600_accel_write_scale(struct inv_icm42600_state *st, 245 + static int inv_icm42600_accel_write_scale(struct iio_dev *indio_dev, 228 246 int val, int val2) 229 247 { 248 + struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 249 + struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev); 230 250 struct device *dev = regmap_get_device(st->map); 231 251 unsigned int idx; 232 252 struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; 233 253 int ret; 234 254 235 - for (idx = 0; idx < ARRAY_SIZE(inv_icm42600_accel_scale); idx += 2) { 236 - if (val == inv_icm42600_accel_scale[idx] && 237 - val2 == inv_icm42600_accel_scale[idx + 1]) 255 + for (idx = 0; idx < accel_st->scales_len; idx += 2) { 256 + if (val == accel_st->scales[idx] && 257 + val2 == accel_st->scales[idx + 1]) 238 258 break; 239 259 } 240 - if (idx >= ARRAY_SIZE(inv_icm42600_accel_scale)) 260 + if (idx >= accel_st->scales_len) 241 261 return -EINVAL; 242 262 243 263 conf.fs = idx / 2; ··· 331 309 int val, int val2) 332 310 { 333 311 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 334 - struct inv_sensors_timestamp *ts = iio_priv(indio_dev); 312 + struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev); 313 + struct inv_sensors_timestamp *ts = &accel_st->ts; 335 314 struct device *dev = regmap_get_device(st->map); 336 315 unsigned int idx; 337 316 struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; ··· 588 565 *val = data; 589 566 return IIO_VAL_INT; 590 567 case IIO_CHAN_INFO_SCALE: 591 - return inv_icm42600_accel_read_scale(st, val, val2); 568 + return inv_icm42600_accel_read_scale(indio_dev, val, val2); 592 569 case IIO_CHAN_INFO_SAMP_FREQ: 593 570 return inv_icm42600_accel_read_odr(st, val, val2); 594 571 case IIO_CHAN_INFO_CALIBBIAS: ··· 603 580 const int **vals, 604 581 int *type, int *length, long mask) 605 582 { 583 + struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev); 584 + 606 585 if (chan->type != IIO_ACCEL) 607 586 return -EINVAL; 608 587 609 588 switch (mask) { 610 589 case IIO_CHAN_INFO_SCALE: 611 - *vals = inv_icm42600_accel_scale; 590 + *vals = accel_st->scales; 612 591 *type = IIO_VAL_INT_PLUS_NANO; 613 - *length = ARRAY_SIZE(inv_icm42600_accel_scale); 592 + *length = accel_st->scales_len; 614 593 return IIO_AVAIL_LIST; 615 594 case IIO_CHAN_INFO_SAMP_FREQ: 616 595 *vals = inv_icm42600_accel_odr; ··· 643 618 ret = iio_device_claim_direct_mode(indio_dev); 644 619 if (ret) 645 620 return ret; 646 - ret = inv_icm42600_accel_write_scale(st, val, val2); 621 + ret = inv_icm42600_accel_write_scale(indio_dev, val, val2); 647 622 iio_device_release_direct_mode(indio_dev); 648 623 return ret; 649 624 case IIO_CHAN_INFO_SAMP_FREQ: ··· 730 705 { 731 706 struct device *dev = regmap_get_device(st->map); 732 707 const char *name; 708 + struct inv_icm42600_sensor_state *accel_st; 733 709 struct inv_sensors_timestamp_chip ts_chip; 734 - struct inv_sensors_timestamp *ts; 735 710 struct iio_dev *indio_dev; 736 711 int ret; 737 712 ··· 739 714 if (!name) 740 715 return ERR_PTR(-ENOMEM); 741 716 742 - indio_dev = devm_iio_device_alloc(dev, sizeof(*ts)); 717 + indio_dev = devm_iio_device_alloc(dev, sizeof(*accel_st)); 743 718 if (!indio_dev) 744 719 return ERR_PTR(-ENOMEM); 720 + accel_st = iio_priv(indio_dev); 721 + 722 + switch (st->chip) { 723 + case INV_CHIP_ICM42686: 724 + accel_st->scales = inv_icm42686_accel_scale; 725 + accel_st->scales_len = ARRAY_SIZE(inv_icm42686_accel_scale); 726 + break; 727 + default: 728 + accel_st->scales = inv_icm42600_accel_scale; 729 + accel_st->scales_len = ARRAY_SIZE(inv_icm42600_accel_scale); 730 + break; 731 + } 745 732 746 733 /* 747 734 * clock period is 32kHz (31250ns) ··· 762 725 ts_chip.clock_period = 31250; 763 726 ts_chip.jitter = 20; 764 727 ts_chip.init_period = inv_icm42600_odr_to_period(st->conf.accel.odr); 765 - ts = iio_priv(indio_dev); 766 - inv_sensors_timestamp_init(ts, &ts_chip); 728 + inv_sensors_timestamp_init(&accel_st->ts, &ts_chip); 767 729 768 730 iio_device_set_drvdata(indio_dev, st); 769 731 indio_dev->name = name; ··· 787 751 int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev) 788 752 { 789 753 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 790 - struct inv_sensors_timestamp *ts = iio_priv(indio_dev); 754 + struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev); 755 + struct inv_sensors_timestamp *ts = &accel_st->ts; 791 756 ssize_t i, size; 792 757 unsigned int no; 793 758 const void *accel, *gyro, *timestamp;
+16 -15
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
··· 276 276 { 277 277 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 278 278 struct device *dev = regmap_get_device(st->map); 279 - struct inv_sensors_timestamp *ts = iio_priv(indio_dev); 279 + struct inv_icm42600_sensor_state *sensor_st = iio_priv(indio_dev); 280 + struct inv_sensors_timestamp *ts = &sensor_st->ts; 280 281 281 282 pm_runtime_get_sync(dev); 282 283 ··· 503 502 504 503 int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st) 505 504 { 505 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(st->indio_gyro); 506 + struct inv_icm42600_sensor_state *accel_st = iio_priv(st->indio_accel); 506 507 struct inv_sensors_timestamp *ts; 507 508 int ret; 508 509 ··· 512 509 return 0; 513 510 514 511 /* handle gyroscope timestamp and FIFO data parsing */ 515 - ts = iio_priv(st->indio_gyro); 516 - inv_sensors_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, 517 - st->fifo.nb.gyro, st->timestamp.gyro); 518 512 if (st->fifo.nb.gyro > 0) { 513 + ts = &gyro_st->ts; 514 + inv_sensors_timestamp_interrupt(ts, st->fifo.nb.gyro, 515 + st->timestamp.gyro); 519 516 ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro); 520 517 if (ret) 521 518 return ret; 522 519 } 523 520 524 521 /* handle accelerometer timestamp and FIFO data parsing */ 525 - ts = iio_priv(st->indio_accel); 526 - inv_sensors_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, 527 - st->fifo.nb.accel, st->timestamp.accel); 528 522 if (st->fifo.nb.accel > 0) { 523 + ts = &accel_st->ts; 524 + inv_sensors_timestamp_interrupt(ts, st->fifo.nb.accel, 525 + st->timestamp.accel); 529 526 ret = inv_icm42600_accel_parse_fifo(st->indio_accel); 530 527 if (ret) 531 528 return ret; ··· 537 534 int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st, 538 535 unsigned int count) 539 536 { 537 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(st->indio_gyro); 538 + struct inv_icm42600_sensor_state *accel_st = iio_priv(st->indio_accel); 540 539 struct inv_sensors_timestamp *ts; 541 540 int64_t gyro_ts, accel_ts; 542 541 int ret; ··· 554 549 return 0; 555 550 556 551 if (st->fifo.nb.gyro > 0) { 557 - ts = iio_priv(st->indio_gyro); 558 - inv_sensors_timestamp_interrupt(ts, st->fifo.period, 559 - st->fifo.nb.total, st->fifo.nb.gyro, 560 - gyro_ts); 552 + ts = &gyro_st->ts; 553 + inv_sensors_timestamp_interrupt(ts, st->fifo.nb.gyro, gyro_ts); 561 554 ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro); 562 555 if (ret) 563 556 return ret; 564 557 } 565 558 566 559 if (st->fifo.nb.accel > 0) { 567 - ts = iio_priv(st->indio_accel); 568 - inv_sensors_timestamp_interrupt(ts, st->fifo.period, 569 - st->fifo.nb.total, st->fifo.nb.accel, 570 - accel_ts); 560 + ts = &accel_st->ts; 561 + inv_sensors_timestamp_interrupt(ts, st->fifo.nb.accel, accel_ts); 571 562 ret = inv_icm42600_accel_parse_fifo(st->indio_accel); 572 563 if (ret) 573 564 return ret;
+21
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
··· 66 66 .temp_en = false, 67 67 }; 68 68 69 + static const struct inv_icm42600_conf inv_icm42686_default_conf = { 70 + .gyro = { 71 + .mode = INV_ICM42600_SENSOR_MODE_OFF, 72 + .fs = INV_ICM42686_GYRO_FS_4000DPS, 73 + .odr = INV_ICM42600_ODR_50HZ, 74 + .filter = INV_ICM42600_FILTER_BW_ODR_DIV_2, 75 + }, 76 + .accel = { 77 + .mode = INV_ICM42600_SENSOR_MODE_OFF, 78 + .fs = INV_ICM42686_ACCEL_FS_32G, 79 + .odr = INV_ICM42600_ODR_50HZ, 80 + .filter = INV_ICM42600_FILTER_BW_ODR_DIV_2, 81 + }, 82 + .temp_en = false, 83 + }; 84 + 69 85 static const struct inv_icm42600_hw inv_icm42600_hw[INV_CHIP_NB] = { 70 86 [INV_CHIP_ICM42600] = { 71 87 .whoami = INV_ICM42600_WHOAMI_ICM42600, ··· 97 81 .whoami = INV_ICM42600_WHOAMI_ICM42605, 98 82 .name = "icm42605", 99 83 .conf = &inv_icm42600_default_conf, 84 + }, 85 + [INV_CHIP_ICM42686] = { 86 + .whoami = INV_ICM42600_WHOAMI_ICM42686, 87 + .name = "icm42686", 88 + .conf = &inv_icm42686_default_conf, 100 89 }, 101 90 [INV_CHIP_ICM42622] = { 102 91 .whoami = INV_ICM42600_WHOAMI_ICM42622,
+65 -19
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
··· 99 99 const unsigned long *scan_mask) 100 100 { 101 101 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 102 - struct inv_sensors_timestamp *ts = iio_priv(indio_dev); 102 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(indio_dev); 103 + struct inv_sensors_timestamp *ts = &gyro_st->ts; 103 104 struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; 104 105 unsigned int fifo_en = 0; 105 106 unsigned int sleep_gyro = 0; ··· 223 222 [2 * INV_ICM42600_GYRO_FS_15_625DPS] = 0, 224 223 [2 * INV_ICM42600_GYRO_FS_15_625DPS + 1] = 8322, 225 224 }; 225 + static const int inv_icm42686_gyro_scale[] = { 226 + /* +/- 4000dps => 0.002130529 rad/s */ 227 + [2 * INV_ICM42686_GYRO_FS_4000DPS] = 0, 228 + [2 * INV_ICM42686_GYRO_FS_4000DPS + 1] = 2130529, 229 + /* +/- 2000dps => 0.001065264 rad/s */ 230 + [2 * INV_ICM42686_GYRO_FS_2000DPS] = 0, 231 + [2 * INV_ICM42686_GYRO_FS_2000DPS + 1] = 1065264, 232 + /* +/- 1000dps => 0.000532632 rad/s */ 233 + [2 * INV_ICM42686_GYRO_FS_1000DPS] = 0, 234 + [2 * INV_ICM42686_GYRO_FS_1000DPS + 1] = 532632, 235 + /* +/- 500dps => 0.000266316 rad/s */ 236 + [2 * INV_ICM42686_GYRO_FS_500DPS] = 0, 237 + [2 * INV_ICM42686_GYRO_FS_500DPS + 1] = 266316, 238 + /* +/- 250dps => 0.000133158 rad/s */ 239 + [2 * INV_ICM42686_GYRO_FS_250DPS] = 0, 240 + [2 * INV_ICM42686_GYRO_FS_250DPS + 1] = 133158, 241 + /* +/- 125dps => 0.000066579 rad/s */ 242 + [2 * INV_ICM42686_GYRO_FS_125DPS] = 0, 243 + [2 * INV_ICM42686_GYRO_FS_125DPS + 1] = 66579, 244 + /* +/- 62.5dps => 0.000033290 rad/s */ 245 + [2 * INV_ICM42686_GYRO_FS_62_5DPS] = 0, 246 + [2 * INV_ICM42686_GYRO_FS_62_5DPS + 1] = 33290, 247 + /* +/- 31.25dps => 0.000016645 rad/s */ 248 + [2 * INV_ICM42686_GYRO_FS_31_25DPS] = 0, 249 + [2 * INV_ICM42686_GYRO_FS_31_25DPS + 1] = 16645, 250 + }; 226 251 227 - static int inv_icm42600_gyro_read_scale(struct inv_icm42600_state *st, 252 + static int inv_icm42600_gyro_read_scale(struct iio_dev *indio_dev, 228 253 int *val, int *val2) 229 254 { 255 + struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 256 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(indio_dev); 230 257 unsigned int idx; 231 258 232 259 idx = st->conf.gyro.fs; 233 260 234 - *val = inv_icm42600_gyro_scale[2 * idx]; 235 - *val2 = inv_icm42600_gyro_scale[2 * idx + 1]; 261 + *val = gyro_st->scales[2 * idx]; 262 + *val2 = gyro_st->scales[2 * idx + 1]; 236 263 return IIO_VAL_INT_PLUS_NANO; 237 264 } 238 265 239 - static int inv_icm42600_gyro_write_scale(struct inv_icm42600_state *st, 266 + static int inv_icm42600_gyro_write_scale(struct iio_dev *indio_dev, 240 267 int val, int val2) 241 268 { 269 + struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 270 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(indio_dev); 242 271 struct device *dev = regmap_get_device(st->map); 243 272 unsigned int idx; 244 273 struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; 245 274 int ret; 246 275 247 - for (idx = 0; idx < ARRAY_SIZE(inv_icm42600_gyro_scale); idx += 2) { 248 - if (val == inv_icm42600_gyro_scale[idx] && 249 - val2 == inv_icm42600_gyro_scale[idx + 1]) 276 + for (idx = 0; idx < gyro_st->scales_len; idx += 2) { 277 + if (val == gyro_st->scales[idx] && 278 + val2 == gyro_st->scales[idx + 1]) 250 279 break; 251 280 } 252 - if (idx >= ARRAY_SIZE(inv_icm42600_gyro_scale)) 281 + if (idx >= gyro_st->scales_len) 253 282 return -EINVAL; 254 283 255 284 conf.fs = idx / 2; ··· 352 321 int val, int val2) 353 322 { 354 323 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 355 - struct inv_sensors_timestamp *ts = iio_priv(indio_dev); 324 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(indio_dev); 325 + struct inv_sensors_timestamp *ts = &gyro_st->ts; 356 326 struct device *dev = regmap_get_device(st->map); 357 327 unsigned int idx; 358 328 struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; ··· 608 576 *val = data; 609 577 return IIO_VAL_INT; 610 578 case IIO_CHAN_INFO_SCALE: 611 - return inv_icm42600_gyro_read_scale(st, val, val2); 579 + return inv_icm42600_gyro_read_scale(indio_dev, val, val2); 612 580 case IIO_CHAN_INFO_SAMP_FREQ: 613 581 return inv_icm42600_gyro_read_odr(st, val, val2); 614 582 case IIO_CHAN_INFO_CALIBBIAS: ··· 623 591 const int **vals, 624 592 int *type, int *length, long mask) 625 593 { 594 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(indio_dev); 595 + 626 596 if (chan->type != IIO_ANGL_VEL) 627 597 return -EINVAL; 628 598 629 599 switch (mask) { 630 600 case IIO_CHAN_INFO_SCALE: 631 - *vals = inv_icm42600_gyro_scale; 601 + *vals = gyro_st->scales; 632 602 *type = IIO_VAL_INT_PLUS_NANO; 633 - *length = ARRAY_SIZE(inv_icm42600_gyro_scale); 603 + *length = gyro_st->scales_len; 634 604 return IIO_AVAIL_LIST; 635 605 case IIO_CHAN_INFO_SAMP_FREQ: 636 606 *vals = inv_icm42600_gyro_odr; ··· 663 629 ret = iio_device_claim_direct_mode(indio_dev); 664 630 if (ret) 665 631 return ret; 666 - ret = inv_icm42600_gyro_write_scale(st, val, val2); 632 + ret = inv_icm42600_gyro_write_scale(indio_dev, val, val2); 667 633 iio_device_release_direct_mode(indio_dev); 668 634 return ret; 669 635 case IIO_CHAN_INFO_SAMP_FREQ: ··· 750 716 { 751 717 struct device *dev = regmap_get_device(st->map); 752 718 const char *name; 719 + struct inv_icm42600_sensor_state *gyro_st; 753 720 struct inv_sensors_timestamp_chip ts_chip; 754 - struct inv_sensors_timestamp *ts; 755 721 struct iio_dev *indio_dev; 756 722 int ret; 757 723 ··· 759 725 if (!name) 760 726 return ERR_PTR(-ENOMEM); 761 727 762 - indio_dev = devm_iio_device_alloc(dev, sizeof(*ts)); 728 + indio_dev = devm_iio_device_alloc(dev, sizeof(*gyro_st)); 763 729 if (!indio_dev) 764 730 return ERR_PTR(-ENOMEM); 731 + gyro_st = iio_priv(indio_dev); 732 + 733 + switch (st->chip) { 734 + case INV_CHIP_ICM42686: 735 + gyro_st->scales = inv_icm42686_gyro_scale; 736 + gyro_st->scales_len = ARRAY_SIZE(inv_icm42686_gyro_scale); 737 + break; 738 + default: 739 + gyro_st->scales = inv_icm42600_gyro_scale; 740 + gyro_st->scales_len = ARRAY_SIZE(inv_icm42600_gyro_scale); 741 + break; 742 + } 765 743 766 744 /* 767 745 * clock period is 32kHz (31250ns) ··· 782 736 ts_chip.clock_period = 31250; 783 737 ts_chip.jitter = 20; 784 738 ts_chip.init_period = inv_icm42600_odr_to_period(st->conf.accel.odr); 785 - ts = iio_priv(indio_dev); 786 - inv_sensors_timestamp_init(ts, &ts_chip); 739 + inv_sensors_timestamp_init(&gyro_st->ts, &ts_chip); 787 740 788 741 iio_device_set_drvdata(indio_dev, st); 789 742 indio_dev->name = name; ··· 808 763 int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev) 809 764 { 810 765 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 811 - struct inv_sensors_timestamp *ts = iio_priv(indio_dev); 766 + struct inv_icm42600_sensor_state *gyro_st = iio_priv(indio_dev); 767 + struct inv_sensors_timestamp *ts = &gyro_st->ts; 812 768 ssize_t i, size; 813 769 unsigned int no; 814 770 const void *accel, *gyro, *timestamp;
+3
drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c
··· 82 82 .compatible = "invensense,icm42605", 83 83 .data = (void *)INV_CHIP_ICM42605, 84 84 }, { 85 + .compatible = "invensense,icm42686", 86 + .data = (void *)INV_CHIP_ICM42686, 87 + }, { 85 88 .compatible = "invensense,icm42622", 86 89 .data = (void *)INV_CHIP_ICM42622, 87 90 }, {
+3
drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c
··· 78 78 .compatible = "invensense,icm42605", 79 79 .data = (void *)INV_CHIP_ICM42605, 80 80 }, { 81 + .compatible = "invensense,icm42686", 82 + .data = (void *)INV_CHIP_ICM42686, 83 + }, { 81 84 .compatible = "invensense,icm42622", 82 85 .data = (void *)INV_CHIP_ICM42622, 83 86 }, {
+1 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
··· 100 100 goto end_session; 101 101 /* Each FIFO data contains all sensors, so same number for FIFO and sensor data */ 102 102 fifo_period = NSEC_PER_SEC / INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); 103 - inv_sensors_timestamp_interrupt(&st->timestamp, fifo_period, nb, nb, pf->timestamp); 103 + inv_sensors_timestamp_interrupt(&st->timestamp, nb, pf->timestamp); 104 104 inv_sensors_timestamp_apply_odr(&st->timestamp, fifo_period, nb, 0); 105 105 106 106 /* clear internal data buffer for avoiding kernel data leak */
+85
drivers/iio/industrialio-acpi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* IIO ACPI helper functions */ 3 + 4 + #include <linux/acpi.h> 5 + #include <linux/dev_printk.h> 6 + #include <linux/iio/iio.h> 7 + #include <linux/sprintf.h> 8 + 9 + /** 10 + * iio_read_acpi_mount_matrix() - Read accelerometer mount matrix info from ACPI 11 + * @dev: Device structure 12 + * @orientation: iio_mount_matrix struct to fill 13 + * @acpi_method: ACPI method name to read the matrix from, usually "ROTM" 14 + * 15 + * Try to read the mount-matrix by calling the specified method on the device's 16 + * ACPI firmware-node. If the device has no ACPI firmware-node; or the method 17 + * does not exist then this will fail silently. This expects the method to 18 + * return data in the ACPI "ROTM" format defined by Microsoft: 19 + * https://learn.microsoft.com/en-us/windows-hardware/drivers/sensors/sensors-acpi-entries 20 + * This is a Microsoft extension and not part of the official ACPI spec. 21 + * The method name is configurable because some dual-accel setups define 2 mount 22 + * matrices in a single ACPI device using separate "ROMK" and "ROMS" methods. 23 + * 24 + * Returns: true if the matrix was successfully, false otherwise. 25 + */ 26 + bool iio_read_acpi_mount_matrix(struct device *dev, 27 + struct iio_mount_matrix *orientation, 28 + char *acpi_method) 29 + { 30 + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 31 + struct acpi_device *adev = ACPI_COMPANION(dev); 32 + char *str; 33 + union acpi_object *obj, *elements; 34 + acpi_status status; 35 + int i, j, val[3]; 36 + bool ret = false; 37 + 38 + if (!adev || !acpi_has_method(adev->handle, acpi_method)) 39 + return false; 40 + 41 + status = acpi_evaluate_object(adev->handle, acpi_method, NULL, &buffer); 42 + if (ACPI_FAILURE(status)) { 43 + dev_err(dev, "Failed to get ACPI mount matrix: %d\n", status); 44 + return false; 45 + } 46 + 47 + obj = buffer.pointer; 48 + if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) { 49 + dev_err(dev, "Unknown ACPI mount matrix package format\n"); 50 + goto out_free_buffer; 51 + } 52 + 53 + elements = obj->package.elements; 54 + for (i = 0; i < 3; i++) { 55 + if (elements[i].type != ACPI_TYPE_STRING) { 56 + dev_err(dev, "Unknown ACPI mount matrix element format\n"); 57 + goto out_free_buffer; 58 + } 59 + 60 + str = elements[i].string.pointer; 61 + if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3) { 62 + dev_err(dev, "Incorrect ACPI mount matrix string format\n"); 63 + goto out_free_buffer; 64 + } 65 + 66 + for (j = 0; j < 3; j++) { 67 + switch (val[j]) { 68 + case -1: str = "-1"; break; 69 + case 0: str = "0"; break; 70 + case 1: str = "1"; break; 71 + default: 72 + dev_err(dev, "Invalid value in ACPI mount matrix: %d\n", val[j]); 73 + goto out_free_buffer; 74 + } 75 + orientation->rotation[i * 3 + j] = str; 76 + } 77 + } 78 + 79 + ret = true; 80 + 81 + out_free_buffer: 82 + kfree(buffer.pointer); 83 + return ret; 84 + } 85 + EXPORT_SYMBOL_GPL(iio_read_acpi_mount_matrix);
+124 -38
drivers/iio/industrialio-backend.c
··· 115 115 116 116 /** 117 117 * iio_backend_chan_enable - Enable a backend channel 118 - * @back: Backend device 119 - * @chan: Channel number 118 + * @back: Backend device 119 + * @chan: Channel number 120 120 * 121 121 * RETURNS: 122 122 * 0 on success, negative error number on failure. ··· 129 129 130 130 /** 131 131 * iio_backend_chan_disable - Disable a backend channel 132 - * @back: Backend device 133 - * @chan: Channel number 132 + * @back: Backend device 133 + * @chan: Channel number 134 134 * 135 135 * RETURNS: 136 136 * 0 on success, negative error number on failure. ··· 148 148 149 149 /** 150 150 * devm_iio_backend_enable - Device managed backend enable 151 - * @dev: Consumer device for the backend 152 - * @back: Backend device 151 + * @dev: Consumer device for the backend 152 + * @back: Backend device 153 153 * 154 154 * RETURNS: 155 155 * 0 on success, negative error number on failure. ··· 168 168 169 169 /** 170 170 * iio_backend_data_format_set - Configure the channel data format 171 - * @back: Backend device 172 - * @chan: Channel number 173 - * @data: Data format 171 + * @back: Backend device 172 + * @chan: Channel number 173 + * @data: Data format 174 174 * 175 175 * Properly configure a channel with respect to the expected data format. A 176 176 * @struct iio_backend_data_fmt must be passed with the settings. ··· 190 190 191 191 /** 192 192 * iio_backend_data_source_set - Select data source 193 - * @back: Backend device 194 - * @chan: Channel number 195 - * @data: Data source 193 + * @back: Backend device 194 + * @chan: Channel number 195 + * @data: Data source 196 196 * 197 197 * A given backend may have different sources to stream/sync data. This allows 198 198 * to choose that source. ··· 212 212 213 213 /** 214 214 * iio_backend_set_sampling_freq - Set channel sampling rate 215 - * @back: Backend device 216 - * @chan: Channel number 217 - * @sample_rate_hz: Sample rate 215 + * @back: Backend device 216 + * @chan: Channel number 217 + * @sample_rate_hz: Sample rate 218 218 * 219 219 * RETURNS: 220 220 * 0 on success, negative error number on failure. ··· 226 226 } 227 227 EXPORT_SYMBOL_NS_GPL(iio_backend_set_sampling_freq, IIO_BACKEND); 228 228 229 + /** 230 + * iio_backend_test_pattern_set - Configure a test pattern 231 + * @back: Backend device 232 + * @chan: Channel number 233 + * @pattern: Test pattern 234 + * 235 + * Configure a test pattern on the backend. This is typically used for 236 + * calibrating the timings on the data digital interface. 237 + * 238 + * RETURNS: 239 + * 0 on success, negative error number on failure. 240 + */ 241 + int iio_backend_test_pattern_set(struct iio_backend *back, 242 + unsigned int chan, 243 + enum iio_backend_test_pattern pattern) 244 + { 245 + if (pattern >= IIO_BACKEND_TEST_PATTERN_MAX) 246 + return -EINVAL; 247 + 248 + return iio_backend_op_call(back, test_pattern_set, chan, pattern); 249 + } 250 + EXPORT_SYMBOL_NS_GPL(iio_backend_test_pattern_set, IIO_BACKEND); 251 + 252 + /** 253 + * iio_backend_chan_status - Get the channel status 254 + * @back: Backend device 255 + * @chan: Channel number 256 + * @error: Error indication 257 + * 258 + * Get the current state of the backend channel. Typically used to check if 259 + * there were any errors sending/receiving data. 260 + * 261 + * RETURNS: 262 + * 0 on success, negative error number on failure. 263 + */ 264 + int iio_backend_chan_status(struct iio_backend *back, unsigned int chan, 265 + bool *error) 266 + { 267 + return iio_backend_op_call(back, chan_status, chan, error); 268 + } 269 + EXPORT_SYMBOL_NS_GPL(iio_backend_chan_status, IIO_BACKEND); 270 + 271 + /** 272 + * iio_backend_iodelay_set - Set digital I/O delay 273 + * @back: Backend device 274 + * @lane: Lane number 275 + * @taps: Number of taps 276 + * 277 + * Controls delays on sending/receiving data. One usecase for this is to 278 + * calibrate the data digital interface so we get the best results when 279 + * transferring data. Note that @taps has no unit since the actual delay per tap 280 + * is very backend specific. Hence, frontend devices typically should go through 281 + * an array of @taps (the size of that array should typically match the size of 282 + * calibration points on the frontend device) and call this API. 283 + * 284 + * RETURNS: 285 + * 0 on success, negative error number on failure. 286 + */ 287 + int iio_backend_iodelay_set(struct iio_backend *back, unsigned int lane, 288 + unsigned int taps) 289 + { 290 + return iio_backend_op_call(back, iodelay_set, lane, taps); 291 + } 292 + EXPORT_SYMBOL_NS_GPL(iio_backend_iodelay_set, IIO_BACKEND); 293 + 294 + /** 295 + * iio_backend_data_sample_trigger - Control when to sample data 296 + * @back: Backend device 297 + * @trigger: Data trigger 298 + * 299 + * Mostly useful for input backends. Configures the backend for when to sample 300 + * data (eg: rising vs falling edge). 301 + * 302 + * RETURNS: 303 + * 0 on success, negative error number on failure. 304 + */ 305 + int iio_backend_data_sample_trigger(struct iio_backend *back, 306 + enum iio_backend_sample_trigger trigger) 307 + { 308 + if (trigger >= IIO_BACKEND_SAMPLE_TRIGGER_MAX) 309 + return -EINVAL; 310 + 311 + return iio_backend_op_call(back, data_sample_trigger, trigger); 312 + } 313 + EXPORT_SYMBOL_NS_GPL(iio_backend_data_sample_trigger, IIO_BACKEND); 314 + 229 315 static void iio_backend_free_buffer(void *arg) 230 316 { 231 317 struct iio_backend_buffer_pair *pair = arg; ··· 321 235 322 236 /** 323 237 * devm_iio_backend_request_buffer - Device managed buffer request 324 - * @dev: Consumer device for the backend 325 - * @back: Backend device 326 - * @indio_dev: IIO device 238 + * @dev: Consumer device for the backend 239 + * @back: Backend device 240 + * @indio_dev: IIO device 327 241 * 328 242 * Request an IIO buffer from the backend. The type of the buffer (typically 329 243 * INDIO_BUFFER_HARDWARE) is up to the backend to decide. This is because, ··· 386 300 387 301 /** 388 302 * iio_backend_ext_info_get - IIO ext_info read callback 389 - * @indio_dev: IIO device 390 - * @private: Data private to the driver 391 - * @chan: IIO channel 392 - * @buf: Buffer where to place the attribute data 303 + * @indio_dev: IIO device 304 + * @private: Data private to the driver 305 + * @chan: IIO channel 306 + * @buf: Buffer where to place the attribute data 393 307 * 394 308 * This helper is intended to be used by backends that extend an IIO channel 395 309 * (through iio_backend_extend_chan_spec()) with extended info. In that case, ··· 421 335 422 336 /** 423 337 * iio_backend_ext_info_set - IIO ext_info write callback 424 - * @indio_dev: IIO device 425 - * @private: Data private to the driver 426 - * @chan: IIO channel 427 - * @buf: Buffer holding the sysfs attribute 428 - * @len: Buffer length 338 + * @indio_dev: IIO device 339 + * @private: Data private to the driver 340 + * @chan: IIO channel 341 + * @buf: Buffer holding the sysfs attribute 342 + * @len: Buffer length 429 343 * 430 344 * This helper is intended to be used by backends that extend an IIO channel 431 345 * (trough iio_backend_extend_chan_spec()) with extended info. In that case, ··· 451 365 452 366 /** 453 367 * iio_backend_extend_chan_spec - Extend an IIO channel 454 - * @indio_dev: IIO device 455 - * @back: Backend device 456 - * @chan: IIO channel 368 + * @indio_dev: IIO device 369 + * @back: Backend device 370 + * @chan: IIO channel 457 371 * 458 372 * Some backends may have their own functionalities and hence capable of 459 373 * extending a frontend's channel. ··· 535 449 536 450 /** 537 451 * devm_iio_backend_get - Device managed backend device get 538 - * @dev: Consumer device for the backend 539 - * @name: Backend name 452 + * @dev: Consumer device for the backend 453 + * @name: Backend name 540 454 * 541 455 * Get's the backend associated with @dev. 542 456 * ··· 587 501 588 502 /** 589 503 * __devm_iio_backend_get_from_fwnode_lookup - Device managed fwnode backend device get 590 - * @dev: Consumer device for the backend 591 - * @fwnode: Firmware node of the backend device 504 + * @dev: Consumer device for the backend 505 + * @fwnode: Firmware node of the backend device 592 506 * 593 507 * Search the backend list for a device matching @fwnode. 594 508 * This API should not be used and it's only present for preventing the first ··· 622 536 623 537 /** 624 538 * iio_backend_get_priv - Get driver private data 625 - * @back: Backend device 539 + * @back: Backend device 626 540 */ 627 541 void *iio_backend_get_priv(const struct iio_backend *back) 628 542 { ··· 640 554 641 555 /** 642 556 * devm_iio_backend_register - Device managed backend device register 643 - * @dev: Backend device being registered 644 - * @ops: Backend ops 645 - * @priv: Device private data 557 + * @dev: Backend device being registered 558 + * @ops: Backend ops 559 + * @priv: Device private data 646 560 * 647 561 * @ops is mandatory. Not providing it results in -EINVAL. 648 562 *
+1 -1
drivers/iio/industrialio-buffer.c
··· 1744 1744 1745 1745 channels = indio_dev->channels; 1746 1746 if (channels) { 1747 - int ml = indio_dev->masklength; 1747 + int ml = 0; 1748 1748 1749 1749 for (i = 0; i < indio_dev->num_channels; i++) 1750 1750 ml = max(ml, channels[i].scan_index + 1);
+6 -6
drivers/iio/light/apds9306.c
··· 55 55 #define APDS9306_ALS_DATA_STAT_MASK BIT(3) 56 56 57 57 #define APDS9306_ALS_THRES_VAL_MAX (BIT(20) - 1) 58 - #define APDS9306_ALS_THRES_VAR_VAL_MAX (BIT(3) - 1) 59 - #define APDS9306_ALS_PERSIST_VAL_MAX (BIT(4) - 1) 58 + #define APDS9306_ALS_THRES_VAR_NUM_VALS 8 59 + #define APDS9306_ALS_PERSIST_NUM_VALS 16 60 60 #define APDS9306_ALS_READ_DATA_DELAY_US (20 * USEC_PER_MSEC) 61 61 #define APDS9306_NUM_REPEAT_RATES 7 62 62 #define APDS9306_INT_SRC_CLEAR 0 ··· 726 726 if (ret) 727 727 return ret; 728 728 729 - if (!in_range(period, 0, APDS9306_ALS_PERSIST_VAL_MAX)) 729 + if (!in_range(period, 0, APDS9306_ALS_PERSIST_NUM_VALS)) 730 730 return -EINVAL; 731 731 732 732 *val = period; ··· 738 738 { 739 739 struct apds9306_regfields *rf = &data->rf; 740 740 741 - if (!in_range(val, 0, APDS9306_ALS_PERSIST_VAL_MAX)) 741 + if (!in_range(val, 0, APDS9306_ALS_PERSIST_NUM_VALS)) 742 742 return -EINVAL; 743 743 744 744 return regmap_field_write(rf->int_persist_val, val); ··· 796 796 if (ret) 797 797 return ret; 798 798 799 - if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_VAL_MAX)) 799 + if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_NUM_VALS)) 800 800 return -EINVAL; 801 801 802 802 *val = thr_adpt; ··· 808 808 { 809 809 struct apds9306_regfields *rf = &data->rf; 810 810 811 - if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_VAL_MAX)) 811 + if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_NUM_VALS)) 812 812 return -EINVAL; 813 813 814 814 return regmap_field_write(rf->int_thresh_var_val, val);
-1
drivers/iio/light/stk3310.c
··· 693 693 static const struct acpi_device_id stk3310_acpi_id[] = { 694 694 {"STK3310", 0}, 695 695 {"STK3311", 0}, 696 - {"STK3335", 0}, 697 696 {} 698 697 }; 699 698
+5 -5
drivers/iio/pressure/zpa2326.c
··· 861 861 struct zpa2326_private *private) 862 862 { 863 863 unsigned int val; 864 - long timeout; 864 + long time_left; 865 865 866 866 zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt"); 867 867 868 - timeout = wait_for_completion_interruptible_timeout( 868 + time_left = wait_for_completion_interruptible_timeout( 869 869 &private->data_ready, ZPA2326_CONVERSION_JIFFIES); 870 - if (timeout > 0) 870 + if (time_left > 0) 871 871 /* 872 872 * Interrupt handler completed before timeout: return operation 873 873 * status. ··· 877 877 /* Clear all interrupts just to be sure. */ 878 878 regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val); 879 879 880 - if (!timeout) { 880 + if (!time_left) { 881 881 /* Timed out. */ 882 882 zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)", 883 - timeout); 883 + time_left); 884 884 return -ETIME; 885 885 } 886 886
+2 -1
drivers/iio/temperature/mcp9600.c
··· 52 52 53 53 if (ret < 0) 54 54 return ret; 55 - *val = ret; 55 + 56 + *val = sign_extend32(ret, 15); 56 57 57 58 return 0; 58 59 }
+55 -19
include/linux/iio/backend.h
··· 24 24 25 25 /** 26 26 * IIO_BACKEND_EX_INFO - Helper for an IIO extended channel attribute 27 - * @_name: Attribute name 28 - * @_shared: Whether the attribute is shared between all channels 29 - * @_what: Data private to the driver 27 + * @_name: Attribute name 28 + * @_shared: Whether the attribute is shared between all channels 29 + * @_what: Data private to the driver 30 30 */ 31 31 #define IIO_BACKEND_EX_INFO(_name, _shared, _what) { \ 32 32 .name = (_name), \ ··· 38 38 39 39 /** 40 40 * struct iio_backend_data_fmt - Backend data format 41 - * @type: Data type. 42 - * @sign_extend: Bool to tell if the data is sign extended. 43 - * @enable: Enable/Disable the data format module. If disabled, 44 - * not formatting will happen. 41 + * @type: Data type. 42 + * @sign_extend: Bool to tell if the data is sign extended. 43 + * @enable: Enable/Disable the data format module. If disabled, 44 + * not formatting will happen. 45 45 */ 46 46 struct iio_backend_data_fmt { 47 47 enum iio_backend_data_type type; ··· 49 49 bool enable; 50 50 }; 51 51 52 + /* vendor specific from 32 */ 53 + enum iio_backend_test_pattern { 54 + IIO_BACKEND_NO_TEST_PATTERN, 55 + /* modified prbs9 */ 56 + IIO_BACKEND_ADI_PRBS_9A = 32, 57 + IIO_BACKEND_TEST_PATTERN_MAX 58 + }; 59 + 60 + enum iio_backend_sample_trigger { 61 + IIO_BACKEND_SAMPLE_TRIGGER_EDGE_FALLING, 62 + IIO_BACKEND_SAMPLE_TRIGGER_EDGE_RISING, 63 + IIO_BACKEND_SAMPLE_TRIGGER_MAX 64 + }; 65 + 52 66 /** 53 67 * struct iio_backend_ops - operations structure for an iio_backend 54 - * @enable: Enable backend. 55 - * @disable: Disable backend. 56 - * @chan_enable: Enable one channel. 57 - * @chan_disable: Disable one channel. 58 - * @data_format_set: Configure the data format for a specific channel. 59 - * @data_source_set: Configure the data source for a specific channel. 60 - * @set_sample_rate: Configure the sampling rate for a specific channel. 61 - * @request_buffer: Request an IIO buffer. 62 - * @free_buffer: Free an IIO buffer. 63 - * @extend_chan_spec: Extend an IIO channel. 64 - * @ext_info_set: Extended info setter. 65 - * @ext_info_get: Extended info getter. 68 + * @enable: Enable backend. 69 + * @disable: Disable backend. 70 + * @chan_enable: Enable one channel. 71 + * @chan_disable: Disable one channel. 72 + * @data_format_set: Configure the data format for a specific channel. 73 + * @data_source_set: Configure the data source for a specific channel. 74 + * @set_sample_rate: Configure the sampling rate for a specific channel. 75 + * @test_pattern_set: Configure a test pattern. 76 + * @chan_status: Get the channel status. 77 + * @iodelay_set: Set digital I/O delay. 78 + * @data_sample_trigger: Control when to sample data. 79 + * @request_buffer: Request an IIO buffer. 80 + * @free_buffer: Free an IIO buffer. 81 + * @extend_chan_spec: Extend an IIO channel. 82 + * @ext_info_set: Extended info setter. 83 + * @ext_info_get: Extended info getter. 66 84 **/ 67 85 struct iio_backend_ops { 68 86 int (*enable)(struct iio_backend *back); ··· 93 75 enum iio_backend_data_source data); 94 76 int (*set_sample_rate)(struct iio_backend *back, unsigned int chan, 95 77 u64 sample_rate_hz); 78 + int (*test_pattern_set)(struct iio_backend *back, 79 + unsigned int chan, 80 + enum iio_backend_test_pattern pattern); 81 + int (*chan_status)(struct iio_backend *back, unsigned int chan, 82 + bool *error); 83 + int (*iodelay_set)(struct iio_backend *back, unsigned int chan, 84 + unsigned int taps); 85 + int (*data_sample_trigger)(struct iio_backend *back, 86 + enum iio_backend_sample_trigger trigger); 96 87 struct iio_buffer *(*request_buffer)(struct iio_backend *back, 97 88 struct iio_dev *indio_dev); 98 89 void (*free_buffer)(struct iio_backend *back, ··· 124 97 enum iio_backend_data_source data); 125 98 int iio_backend_set_sampling_freq(struct iio_backend *back, unsigned int chan, 126 99 u64 sample_rate_hz); 100 + int iio_backend_test_pattern_set(struct iio_backend *back, 101 + unsigned int chan, 102 + enum iio_backend_test_pattern pattern); 103 + int iio_backend_chan_status(struct iio_backend *back, unsigned int chan, 104 + bool *error); 105 + int iio_backend_iodelay_set(struct iio_backend *back, unsigned int lane, 106 + unsigned int taps); 107 + int iio_backend_data_sample_trigger(struct iio_backend *back, 108 + enum iio_backend_sample_trigger trigger); 127 109 int devm_iio_backend_request_buffer(struct device *dev, 128 110 struct iio_backend *back, 129 111 struct iio_dev *indio_dev);
+1 -2
include/linux/iio/common/inv_sensors_timestamp.h
··· 71 71 uint32_t period, bool fifo); 72 72 73 73 void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, 74 - uint32_t fifo_period, size_t fifo_nb, 75 - size_t sensor_nb, int64_t timestamp); 74 + size_t sample_nb, int64_t timestamp); 76 75 77 76 static inline int64_t inv_sensors_timestamp_pop(struct inv_sensors_timestamp *ts) 78 77 {
+13
include/linux/iio/iio.h
··· 788 788 } 789 789 #endif 790 790 791 + #ifdef CONFIG_ACPI 792 + bool iio_read_acpi_mount_matrix(struct device *dev, 793 + struct iio_mount_matrix *orientation, 794 + char *acpi_method); 795 + #else 796 + static inline bool iio_read_acpi_mount_matrix(struct device *dev, 797 + struct iio_mount_matrix *orientation, 798 + char *acpi_method) 799 + { 800 + return false; 801 + } 802 + #endif 803 + 791 804 ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals); 792 805 793 806 int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,