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

Merge tag 'iio-for-6.14a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next

Pull IIO updaate from Jonathan:

IIO: 1st set of new device support, features and cleanup for 6.14

Fairly quiet cycle. Usual mix of new drivers, device support in
existing drivers, features and more general rework and cleanup.
There are a few late breaking or long standing but complex fixes
in here as well.

There is one expected merge conflict due to an upstream fix touching
neighboring code in ti-ads1119. The trivial resolution is the right one with
the result ending up as:

struct {
s16 sample;
aligned_s64 timestamp;
} scan;

New device support
==================

adi,ad4000
- Add support for many Pulsar ADC devices: AD7685, AD7686, AD7687, AD7688,
AD7690, AD7691, AD7693, AD7942, AD7946, AD7980, AD7982, AD7983, AD7984,
AD7988-1 and AD7988-5 ADCs. Generally similar to the AD4000 series
but with lower sampling rates and no configuration registers.
Includes addition of timestamp channels.
adi,adis16480
- Add support for ADIS16486, ADIS16487 and ADIS16489 IMUs. Required a few tweaks
to existing driver and addition of tables.
kionix,kx022a
- Add support for KX134ACR-LBZ accelerometer that is similar to the
KX132ACR-LBZ but with a wider (+-64G) sensor range.
- Add support for KX134-1211 accelerometer that is similar to the
KX132-1211 but with a wider (+-16G) sensor range.
nxp,fxls8962af
- Add support for fxls8974cf and fxls8967af accelerometers, Both are
compatible with fxls8962af but with different device IDs which are used in
presence checks.
renesas,rzg2l
- Add support for Renesas RZ/GS3 SoC ADCs (various driver refactors
precede this to allow for chip differences).
rohm,bd79704
- New driver for this 6 channel DAC.
st,mpu6050
- Support he IAM20380 which is effectively a cut down IAM20608 IMU with only
a gyroscope (no accelerometer).
st,stm-timmer-trigger
- Add support for ADC trigger use case for the STM32MP25 SOC. Do not support
the counter functionality in this driver as that is handled by the
counter subsystem.
ti,opt4060
- New driver for this RGBW color sensor.

Driver drop
===========

rohm,bu20008
- Drop as decision was made to not mass produce this light sensor after
Matti had done all the work to get a driver upstream.

Features
========

adi,ad_sigma_delta library + ad7124
- Allow for GPIO to check interrupt status, enabling this device on
more platforms that don't obey prior (non general) assumptions on
how the interrupt chips work.
- Allow variation in reset sequence length allowing chip specific
optimizations rather than always using worst case.
adi,ad7124
- Add temperature channel support.
adi,ad7173
- Add support calibration modes for this family of ADCs.
adi,adxl345
- Binding update to allow specification of which interrupt line is
connected (or none).
- Support interrupts and FIFO based data capture.
bosch,bme680
- Add regulators support. Note this required a new binding doc rather than
use of trivial-devices
- Runtime PM support.
microchip,pac1921
- Add ACPI support including _DSM for shunt value and label.
renesas,rzg2l
- Enable runtime autosuspend.
- Add suspend and resume support.
tyhx,hx9023s
- Add loading of a firmware file used to set defaults for some
configuration registers.
vishay,veml6030
- Support triggered buffers allowing efficient data capture at
higher speeds.
- Add regmap cache to reduce access to device.

Cleanup and minor fixes
=======================

cross-tree
- Another batch of conversions to devm_regulator_get_enable_read_voltage()
helper and related conversions to full devm that this enables.
- Various patches using guard() to allow early returns and simpler
code flow.
- Various conversions from s64 timestamp __aligned(8) to aligned_s64 type.
Includes a few cleanups where this unsigned and it should have been
signed.
- Fix up some missing types for drive-open-drain in dt-binding docs.
core
- Add missing documentation for iio_dmaengine_buffer_setup_ext()
- Add check that all buffers passed to iio_read_channel_ext_info()
and iio_read_channel_label() are page sized and page aligned.
Done this way because the callbacks are almost always only used
to fill sysfs attributes. The check covers the tiny percentage
of cases where use is made of this data in a consumer driver.
- Mark scan_timestamp memory of struct iio_dev private ensuring no
drivers change the value which belongs to the IIO core.
documentation
- Various missing ABI docs added.
- ABI docs made to use Y consistently as the wildcard for channel
number.
- Combine duplicate in_currentY_raw entries in ABI docs.
iio-mux
- Fix alignment of buffers passed to iio_channel_read_ext_info().
adi,ad_sigma_delta library
- Respect keep_cs_asserted flag in read path.
- Close a race condition around irq enabling and disabling.
- Use explicit unsigned int in place of unsigned.
adi,ad6695
- Move dt-binding header under adc sub-directory and fix include path in dt
example.
adi,ad7124
- Check number of channels in DT doesn't exceed what the driver can handle.
- Check input specified in DT are possible.
- Improved error reporting during probe.
adi,ad7173
- Drop unused structure element.
adi,ad7293
- Ensure power is turned on before resetting.
adi,adxl345
- Some documentation simplification and parameter renames.
- Add a function than unifies handling of power up and power down.
- Add defines to have a complete set of registers defined.
- Add missing \n to end of error messages.
amlogic,meson_saradc
- Simplify handling of the REG11 register access.
awinic,aw96104
- Constify iio_info structure.
bosch,bmp085
- Add to dt-binding to indicate devices support SPI.
bosch,bmp280
- Use sizeof() to replace a somewhat magic 2.
- Rename sleep related variables so the unit is included and use
fsleep() to replace usleep_range() calls.
bosch,bno055
- Constify struct bin_attribute
capella,cm3232
- Reset device before checking hardware ID inline with suggested flow
from datasheet.
diolan,dln2
- Simplify zeroing of structure used to gather up data by just
clearing the whole thing before writing rather than trying to
clear out he padding after write.
freescale,vf610
- Use devm_ and dev_error_probe() to simplify code and allow dropping
of explicit remove() callback.
invensense,timestamp library
- Use a cast to remove possibility of integer overflow.
kionix,kx022a
- Increase reset delay a little.
maxim,max1363
- Use a buffer of sufficient size in iio_priv() rather than allocating
variable sized buffer at use time.
microchip,mcp4725
- Replace of_property_read_bool() with of_property_present() for
detecting presence of regulator which is obviously not a bool.
nxp,fxls8962af
- Add wakeup-source property to the dt binding to allow these sensors
to wake the system up from suspend.
- Enable finer grained build when not all bus types need to be supported.
renesas,rzg2l
- Use dev_err_probe(), improving handling of probe errors and simplifying
code.
- Convert to devm_ based cleanup.
- Remove unnecessary runtime PM complexity as clocks are managed through
PM domains.
- Switch pm_ptr() removing need for __maybe_unused markings.
- use read_poll_timeout() to replace open coded equivalent.
samsung, ssp_sensors
- Simplify code by always providing timestamp whether or not it
is enabled.
st,lsm6dsx
- Avoid need to include linux/i3c/master by using i3cdev_to_dev() to
get to the contained struct device.
st,stm32-timer-trigger
- Check for clk_enable() fails.
vishay,veml6030
- Use new gts-helper functions and fix the _scale attribute to take into
account changes in gain and integration time.

Various other typo fixes in variable names + documentation and help text.
A few whitespace cleanup patches.

* tag 'iio-for-6.14a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (142 commits)
iio: iio-mux: kzalloc instead of devm_kzalloc to ensure page alignment
iio: adc: ad7625: Add ending newlines to error messages
iio: accel: adxl345: complete the list of defines
iio: accel: adxl345: add FIFO with watermark events
iio: accel: adxl345: initialize FIFO delay value for SPI
iio: accel: adxl345: introduce interrupt handling
iio: light: veml3235: fix scale to conform to ABI
iio: gts-helper: add helpers to ease searches of gain_sel and new_gain
iio: light: veml3235: extend regmap to add cache
iio: light: veml3235: fix code style
dt-bindings: iio: accel: adxl345: add interrupt-names
dt-bindings: iio: accel: adxl345: make interrupts not a required property
dt-bindings: iio: imu: bmi323: add boolean type for drive-open-drain
dt-bindings: iio: imu: bmi270: add boolean type for drive-open-drain
dt-bindings: iio: imu: bmi160: add boolean type for drive-open-drain
iio: adc: meson: simplify MESON_SAR_ADC_REG11 register access
iio: adc: meson: use tabs instead of spaces for some REG11 bit fields
iio: adc: meson: fix voltage reference selection field name typo
iio: adc: rockchip: correct alignment of timestamp
iio: imu: inv_icm42600: switch timestamp type from int64_t __aligned(8) to aligned_s64
...

+4822 -3185
+38 -39
Documentation/ABI/testing/sysfs-bus-iio
··· 168 168 is required is a consistent labeling. Units after application 169 169 of scale and offset are millivolts. 170 170 171 - What: /sys/bus/iio/devices/iio:deviceX/in_currentY_raw 172 - What: /sys/bus/iio/devices/iio:deviceX/in_currentY_supply_raw 173 - KernelVersion: 3.17 174 - Contact: linux-iio@vger.kernel.org 175 - Description: 176 - Raw (unscaled no bias removal etc.) current measurement from 177 - channel Y. In special cases where the channel does not 178 - correspond to externally available input one of the named 179 - versions may be used. The number must always be specified and 180 - unique to allow association with event codes. Units after 181 - application of scale and offset are milliamps. 182 - 183 171 What: /sys/bus/iio/devices/iio:deviceX/in_powerY_raw 184 172 KernelVersion: 4.5 185 173 Contact: linux-iio@vger.kernel.org ··· 215 227 same scaling as _raw. 216 228 217 229 What: /sys/bus/iio/devices/iio:deviceX/in_temp_raw 218 - What: /sys/bus/iio/devices/iio:deviceX/in_tempX_raw 230 + What: /sys/bus/iio/devices/iio:deviceX/in_tempY_raw 219 231 What: /sys/bus/iio/devices/iio:deviceX/in_temp_x_raw 220 232 What: /sys/bus/iio/devices/iio:deviceX/in_temp_y_raw 221 233 What: /sys/bus/iio/devices/iio:deviceX/in_temp_ambient_raw ··· 404 416 Description: 405 417 Scaled humidity measurement in milli percent. 406 418 407 - What: /sys/bus/iio/devices/iio:deviceX/in_X_mean_raw 419 + What: /sys/bus/iio/devices/iio:deviceX/in_Y_mean_raw 408 420 KernelVersion: 3.5 409 421 Contact: linux-iio@vger.kernel.org 410 422 Description: 411 - Averaged raw measurement from channel X. The number of values 423 + Averaged raw measurement from channel Y. The number of values 412 424 used for averaging is device specific. The converting rules for 413 425 normal raw values also applies to the averaged raw values. 414 426 ··· 436 448 What: /sys/bus/iio/devices/iio:deviceX/in_magn_offset 437 449 What: /sys/bus/iio/devices/iio:deviceX/in_rot_offset 438 450 What: /sys/bus/iio/devices/iio:deviceX/in_angl_offset 439 - What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceX_offset 451 + What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_offset 440 452 KernelVersion: 2.6.35 441 453 Contact: linux-iio@vger.kernel.org 442 454 Description: ··· 496 508 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_x_scale 497 509 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_y_scale 498 510 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_z_scale 511 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_red_scale 512 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_green_scale 513 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_scale 499 514 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_co2_scale 500 515 KernelVersion: 2.6.35 501 516 Contact: linux-iio@vger.kernel.org ··· 651 660 What: /sys/.../iio:deviceX/in_illuminance_scale_available 652 661 What: /sys/.../iio:deviceX/in_intensity_scale_available 653 662 What: /sys/.../iio:deviceX/in_proximity_scale_available 654 - What: /sys/.../iio:deviceX/in_voltageX_scale_available 663 + What: /sys/.../iio:deviceX/in_voltageY_scale_available 655 664 What: /sys/.../iio:deviceX/in_voltage-voltage_scale_available 656 - What: /sys/.../iio:deviceX/out_voltageX_scale_available 657 - What: /sys/.../iio:deviceX/out_altvoltageX_scale_available 665 + What: /sys/.../iio:deviceX/out_voltageY_scale_available 666 + What: /sys/.../iio:deviceX/out_altvoltageY_scale_available 658 667 What: /sys/.../iio:deviceX/in_capacitance_scale_available 659 668 What: /sys/.../iio:deviceX/in_pressure_scale_available 660 669 What: /sys/.../iio:deviceX/in_pressureY_scale_available ··· 672 681 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_green_hardwaregain 673 682 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_hardwaregain 674 683 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_clear_hardwaregain 684 + What: /sys/bus/iio/devices/iio:deviceX/in_illuminance_hardwaregain 675 685 KernelVersion: 2.6.35 676 686 Contact: linux-iio@vger.kernel.org 677 687 Description: ··· 1554 1562 This attribute is used to read the amount of quadrature error 1555 1563 present in the device at a given time. 1556 1564 1557 - What: /sys/.../iio:deviceX/in_accelX_power_mode 1565 + What: /sys/.../iio:deviceX/in_accelY_power_mode 1558 1566 KernelVersion: 3.11 1559 1567 Contact: linux-iio@vger.kernel.org 1560 1568 Description: ··· 1625 1633 What: /sys/.../iio:deviceX/in_intensityY_uva_raw 1626 1634 What: /sys/.../iio:deviceX/in_intensityY_uvb_raw 1627 1635 What: /sys/.../iio:deviceX/in_intensityY_duv_raw 1636 + What: /sys/.../iio:deviceX/in_intensity_red_raw 1637 + What: /sys/.../iio:deviceX/in_intensity_green_raw 1638 + What: /sys/.../iio:deviceX/in_intensity_blue_raw 1639 + What: /sys/.../iio:deviceX/in_intensity_clear_raw 1628 1640 KernelVersion: 3.4 1629 1641 Contact: linux-iio@vger.kernel.org 1630 1642 Description: ··· 1687 1691 Raw value of rotation from true/magnetic north measured with 1688 1692 or without compensation from tilt sensors. 1689 1693 1690 - What: /sys/bus/iio/devices/iio:deviceX/in_currentX_raw 1691 - What: /sys/bus/iio/devices/iio:deviceX/in_currentX_i_raw 1692 - What: /sys/bus/iio/devices/iio:deviceX/in_currentX_q_raw 1693 - KernelVersion: 3.18 1694 + What: /sys/bus/iio/devices/iio:deviceX/in_currentY_raw 1695 + What: /sys/bus/iio/devices/iio:deviceX/in_currentY_supply_raw 1696 + What: /sys/bus/iio/devices/iio:deviceX/in_currentY_i_raw 1697 + What: /sys/bus/iio/devices/iio:deviceX/in_currentY_q_raw 1698 + KernelVersion: 3.17 1694 1699 Contact: linux-iio@vger.kernel.org 1695 1700 Description: 1696 - Raw current measurement from channel X. Units are in milliamps 1701 + Raw current measurement from channel Y. Units are in milliamps 1697 1702 after application of scale and offset. If no offset or scale is 1698 1703 present, output should be considered as processed with the 1699 - unit in milliamps. 1704 + unit in milliamps. In special cases where the channel does not 1705 + correspond to externally available input one of the named 1706 + versions may be used. 1700 1707 1701 1708 Channels with 'i' and 'q' modifiers always exist in pairs and both 1702 1709 channels refer to the same signal. The 'i' channel contains the in-phase ··· 1863 1864 hardware fifo watermark level. 1864 1865 1865 1866 What: /sys/bus/iio/devices/iio:deviceX/in_temp_calibemissivity 1866 - What: /sys/bus/iio/devices/iio:deviceX/in_tempX_calibemissivity 1867 + What: /sys/bus/iio/devices/iio:deviceX/in_tempY_calibemissivity 1867 1868 What: /sys/bus/iio/devices/iio:deviceX/in_temp_object_calibemissivity 1868 - What: /sys/bus/iio/devices/iio:deviceX/in_tempX_object_calibemissivity 1869 + What: /sys/bus/iio/devices/iio:deviceX/in_tempY_object_calibemissivity 1869 1870 KernelVersion: 4.1 1870 1871 Contact: linux-iio@vger.kernel.org 1871 1872 Description: ··· 1886 1887 is considered as one sample for <type>[_name]_sampling_frequency. 1887 1888 1888 1889 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_raw 1889 - What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_raw 1890 + What: /sys/bus/iio/devices/iio:deviceX/in_concentrationY_raw 1890 1891 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_co2_raw 1891 - What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_co2_raw 1892 + What: /sys/bus/iio/devices/iio:deviceX/in_concentrationY_co2_raw 1892 1893 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_ethanol_raw 1893 - What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_ethanol_raw 1894 + What: /sys/bus/iio/devices/iio:deviceX/in_concentrationY_ethanol_raw 1894 1895 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_h2_raw 1895 - What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_h2_raw 1896 + What: /sys/bus/iio/devices/iio:deviceX/in_concentrationY_h2_raw 1896 1897 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_o2_raw 1897 - What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_o2_raw 1898 + What: /sys/bus/iio/devices/iio:deviceX/in_concentrationY_o2_raw 1898 1899 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_voc_raw 1899 - What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_voc_raw 1900 + What: /sys/bus/iio/devices/iio:deviceX/in_concentrationY_voc_raw 1900 1901 KernelVersion: 4.3 1901 1902 Contact: linux-iio@vger.kernel.org 1902 1903 Description: ··· 1904 1905 after application of scale and offset are percents. 1905 1906 1906 1907 What: /sys/bus/iio/devices/iio:deviceX/in_resistance_raw 1907 - What: /sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw 1908 + What: /sys/bus/iio/devices/iio:deviceX/in_resistanceY_raw 1908 1909 What: /sys/bus/iio/devices/iio:deviceX/out_resistance_raw 1909 - What: /sys/bus/iio/devices/iio:deviceX/out_resistanceX_raw 1910 + What: /sys/bus/iio/devices/iio:deviceX/out_resistanceY_raw 1910 1911 KernelVersion: 4.3 1911 1912 Contact: linux-iio@vger.kernel.org 1912 1913 Description: ··· 2095 2096 One of the following thermocouple types: B, E, J, K, N, R, S, T. 2096 2097 2097 2098 What: /sys/bus/iio/devices/iio:deviceX/in_temp_object_calibambient 2098 - What: /sys/bus/iio/devices/iio:deviceX/in_tempX_object_calibambient 2099 + What: /sys/bus/iio/devices/iio:deviceX/in_tempY_object_calibambient 2099 2100 KernelVersion: 5.10 2100 2101 Contact: linux-iio@vger.kernel.org 2101 2102 Description: ··· 2171 2172 2172 2173 - a range specified as "[min step max]" 2173 2174 2174 - What: /sys/bus/iio/devices/iio:deviceX/in_voltageX_sampling_frequency 2175 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_sampling_frequency 2175 2176 What: /sys/bus/iio/devices/iio:deviceX/in_powerY_sampling_frequency 2176 - What: /sys/bus/iio/devices/iio:deviceX/in_currentZ_sampling_frequency 2177 + What: /sys/bus/iio/devices/iio:deviceX/in_currentY_sampling_frequency 2177 2178 KernelVersion: 5.20 2178 2179 Contact: linux-iio@vger.kernel.org 2179 2180 Description:
+23
Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta
··· 1 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_sys_calibration 2 + KernelVersion: 5.5 3 + Contact: linux-iio@vger.kernel.org 4 + Description: 5 + This attribute, if available, initiates the system calibration procedure. This is done on a 6 + single channel at a time. Write '1' to start the calibration. 7 + 8 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_sys_calibration_mode_available 9 + KernelVersion: 5.5 10 + Contact: linux-iio@vger.kernel.org 11 + Description: 12 + This attribute, if available, returns a list with the possible calibration modes. 13 + There are two available options: 14 + "zero_scale" - calibrate to zero scale 15 + "full_scale" - calibrate to full scale 16 + 17 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_sys_calibration_mode 18 + KernelVersion: 5.5 19 + Contact: linux-iio@vger.kernel.org 20 + Description: 21 + This attribute, if available, sets up the calibration mode used in the system calibration 22 + procedure. Reading returns the current calibration mode. 23 + Writing sets the system calibration mode.
-24
Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
··· 19 19 the bridge can be disconnected (when it is not being used 20 20 using the bridge_switch_en attribute. 21 21 22 - What: /sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration 23 - KernelVersion: 24 - Contact: linux-iio@vger.kernel.org 25 - Description: 26 - Initiates the system calibration procedure. This is done on a 27 - single channel at a time. Write '1' to start the calibration. 28 - 29 22 What: /sys/bus/iio/devices/iio:deviceX/in_voltage2-voltage2_shorted_raw 30 23 KernelVersion: 31 24 Contact: linux-iio@vger.kernel.org 32 25 Description: 33 26 Measure voltage from AIN2 pin connected to AIN(+) 34 27 and AIN(-) shorted. 35 - 36 - What: /sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration_mode_available 37 - KernelVersion: 38 - Contact: linux-iio@vger.kernel.org 39 - Description: 40 - Reading returns a list with the possible calibration modes. 41 - There are two available options: 42 - "zero_scale" - calibrate to zero scale 43 - "full_scale" - calibrate to full scale 44 - 45 - What: /sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration_mode 46 - KernelVersion: 47 - Contact: linux-iio@vger.kernel.org 48 - Description: 49 - Sets up the calibration mode used in the system calibration 50 - procedure. Reading returns the current calibration mode. 51 - Writing sets the system calibration mode.
+10 -1
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml
··· 37 37 interrupts: 38 38 maxItems: 1 39 39 40 + interrupt-names: 41 + items: 42 + - enum: [INT1, INT2] 43 + 44 + dependencies: 45 + interrupts: [ interrupt-names ] 46 + interrupt-names: [ interrupts ] 47 + 40 48 required: 41 49 - compatible 42 50 - reg 43 - - interrupts 44 51 45 52 allOf: 46 53 - $ref: /schemas/spi/spi-peripheral-props.yaml# ··· 68 61 reg = <0x2a>; 69 62 interrupt-parent = <&gpio0>; 70 63 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 64 + interrupt-names = "INT1"; 71 65 }; 72 66 }; 73 67 - | ··· 87 79 spi-cpha; 88 80 interrupt-parent = <&gpio0>; 89 81 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 82 + interrupt-names = "INT2"; 90 83 }; 91 84 };
+7 -4
Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
··· 4 4 $id: http://devicetree.org/schemas/iio/accel/kionix,kx022a.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: ROHM/Kionix KX022A, KX132-1211 and KX132ACR-LBZ Accelerometers 7 + title: ROHM/Kionix KX022A, KX132/134-1211 and KX132/134ACR-LBZ Accelerometers 8 8 9 9 maintainers: 10 10 - Matti Vaittinen <mazziesaccount@gmail.com> 11 11 12 12 description: | 13 13 KX022A, KX132ACR-LBZ and KX132-1211 are 3-axis accelerometers supporting 14 - +/- 2G, 4G, 8G and 16G ranges, variable output data-rates and a 15 - hardware-fifo buffering. These accelerometers can be accessed either 16 - via I2C or SPI. 14 + +/- 2G, 4G, 8G and 16G ranges. The KX134ACR-LBZ and KX134-1211 support 15 + +/- 8G, 16G, 32G and 64G. All the sensors also have variable output 16 + data-rates and a hardware-fifo buffering. These accelerometers can be 17 + accessed either via I2C or SPI. 17 18 18 19 properties: 19 20 compatible: 20 21 enum: 21 22 - kionix,kx022a 22 23 - kionix,kx132-1211 24 + - kionix,kx134-1211 23 25 - rohm,kx132acr-lbz 26 + - rohm,kx134acr-lbz 24 27 25 28 reg: 26 29 maxItems: 1
+17 -3
Documentation/devicetree/bindings/iio/accel/nxp,fxls8962af.yaml
··· 14 14 SPI and I2C interface. 15 15 https://www.nxp.com/docs/en/data-sheet/FXLS8962AF.pdf 16 16 https://www.nxp.com/docs/en/data-sheet/FXLS8964AF.pdf 17 + https://www.nxp.com/docs/en/data-sheet/FXLS8967AF.pdf 18 + https://www.nxp.com/docs/en/data-sheet/FXLS8974CF.pdf 17 19 18 20 properties: 19 21 compatible: 20 - enum: 21 - - nxp,fxls8962af 22 - - nxp,fxls8964af 22 + oneOf: 23 + - enum: 24 + - nxp,fxls8962af 25 + - nxp,fxls8964af 26 + - items: 27 + - enum: 28 + - nxp,fxls8967af 29 + - nxp,fxls8974cf 30 + - const: nxp,fxls8962af 23 31 24 32 reg: 25 33 maxItems: 1 ··· 45 37 46 38 drive-open-drain: 47 39 type: boolean 40 + 41 + wakeup-source: 42 + $ref: /schemas/types.yaml#/definitions/flag 43 + description: 44 + Enable wake on accelerometer event 48 45 49 46 required: 50 47 - compatible ··· 74 61 interrupt-parent = <&gpio0>; 75 62 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 76 63 interrupt-names = "INT1"; 64 + wakeup-source; 77 65 }; 78 66 }; 79 67 - |
+62 -13
Documentation/devicetree/bindings/iio/adc/adi,ad4000.yaml
··· 19 19 https://www.analog.com/media/en/technical-documentation/data-sheets/ad4020-4021-4022.pdf 20 20 https://www.analog.com/media/en/technical-documentation/data-sheets/adaq4001.pdf 21 21 https://www.analog.com/media/en/technical-documentation/data-sheets/adaq4003.pdf 22 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7685.pdf 23 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7686.pdf 24 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7687.pdf 25 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7688.pdf 26 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7690.pdf 27 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7691.pdf 28 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7693.pdf 29 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7942.pdf 30 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7946.pdf 31 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7980.pdf 32 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7982.pdf 33 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7983.pdf 34 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7984.pdf 35 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7988-1_7988-5.pdf 22 36 23 37 $ref: /schemas/spi/spi-peripheral-props.yaml# 24 38 25 39 properties: 26 40 compatible: 27 41 oneOf: 28 - - const: adi,ad4000 42 + - enum: 43 + - adi,ad4000 44 + - adi,ad4001 45 + - adi,ad4002 46 + - adi,ad4003 47 + - adi,ad4020 48 + - adi,adaq4001 49 + - adi,adaq4003 50 + - adi,ad7687 51 + - adi,ad7691 52 + - adi,ad7942 53 + - adi,ad7946 54 + - adi,ad7983 29 55 - items: 30 56 - enum: 31 57 - adi,ad4004 32 58 - adi,ad4008 33 59 - const: adi,ad4000 34 - 35 - - const: adi,ad4001 36 60 - items: 37 61 - enum: 38 62 - adi,ad4005 39 63 - const: adi,ad4001 40 - 41 - - const: adi,ad4002 42 64 - items: 43 65 - enum: 44 66 - adi,ad4006 45 67 - adi,ad4010 46 68 - const: adi,ad4002 47 - 48 - - const: adi,ad4003 49 69 - items: 50 70 - enum: 51 71 - adi,ad4007 52 72 - adi,ad4011 53 73 - const: adi,ad4003 54 - 55 - - const: adi,ad4020 56 74 - items: 57 75 - enum: 58 76 - adi,ad4021 59 77 - adi,ad4022 60 78 - const: adi,ad4020 61 - 62 - - const: adi,adaq4001 63 - 64 - - const: adi,adaq4003 79 + - items: 80 + - enum: 81 + - adi,ad7685 82 + - adi,ad7686 83 + - adi,ad7980 84 + - adi,ad7988-1 85 + - adi,ad7988-5 86 + - const: adi,ad7983 87 + - items: 88 + - enum: 89 + - adi,ad7688 90 + - adi,ad7693 91 + - const: adi,ad7687 92 + - items: 93 + - enum: 94 + - adi,ad7690 95 + - adi,ad7982 96 + - adi,ad7984 97 + - const: adi,ad7691 65 98 66 99 reg: 67 100 maxItems: 1 ··· 166 133 - ref-supply 167 134 168 135 allOf: 136 + # Single-channel PulSAR devices have SDI either tied to VIO, GND, or host CS. 137 + - if: 138 + properties: 139 + compatible: 140 + contains: 141 + enum: 142 + - adi,ad7687 143 + - adi,ad7691 144 + - adi,ad7942 145 + - adi,ad7946 146 + - adi,ad7983 147 + then: 148 + properties: 149 + adi,sdi-pin: 150 + enum: [ high, low, cs ] 151 + default: cs 169 152 # The configuration register can only be accessed if SDI is connected to MOSI 170 153 - if: 171 154 required:
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad4695.yaml
··· 134 134 description: 135 135 Describes the common mode channel for single channels. 0xFF is REFGND 136 136 and OxFE is COM. Macros are available for these values in 137 - dt-bindings/iio/adi,ad4695.h. Values 1 to 15 correspond to INx inputs. 138 - Only odd numbered INx inputs can be used as common mode channels. 137 + dt-bindings/iio/adc/adi,ad4695.h. Values 1 to 15 correspond to INx 138 + inputs. Only odd numbered INx inputs can be used as common mode 139 + channels. 139 140 enum: [1, 3, 5, 7, 9, 11, 13, 15, 0xFE, 0xFF] 140 141 default: 0xFF 141 142 ··· 210 209 examples: 211 210 - | 212 211 #include <dt-bindings/gpio/gpio.h> 213 - #include <dt-bindings/iio/adi,ad4695.h> 212 + #include <dt-bindings/iio/adc/adi,ad4695.h> 214 213 215 214 spi { 216 215 #address-cells = <1>;
+13
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
··· 37 37 description: IRQ line for the ADC 38 38 maxItems: 1 39 39 40 + rdy-gpios: 41 + description: 42 + GPIO reading the R̅D̅Y̅ line. Having such a GPIO is technically optional but 43 + highly recommended because DOUT/R̅D̅Y̅ toggles during SPI transfers (in its 44 + DOUT aka MISO role) and so usually triggers a spurious interrupt. The 45 + distinction between such a spurious event and a real one can only be done 46 + by reading such a GPIO. (There is a register telling the same 47 + information, but accessing that one needs a SPI transfer which then 48 + triggers another interrupt event.) 49 + maxItems: 1 50 + 40 51 '#address-cells': 41 52 const: 1 42 53 ··· 122 111 123 112 examples: 124 113 - | 114 + #include <dt-bindings/gpio/gpio.h> 125 115 spi { 126 116 #address-cells = <1>; 127 117 #size-cells = <0>; ··· 133 121 spi-max-frequency = <5000000>; 134 122 interrupts = <25 2>; 135 123 interrupt-parent = <&gpio>; 124 + rdy-gpios = <&gpio 25 GPIO_ACTIVE_LOW>; 136 125 refin1-supply = <&adc_vref>; 137 126 clocks = <&ad7124_mclk>; 138 127 clock-names = "mclk";
+12
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
··· 135 135 '#clock-cells': 136 136 const: 0 137 137 138 + rdy-gpios: 139 + description: 140 + GPIO reading the R̅D̅Y̅ line. Having such a GPIO is technically optional but 141 + highly recommended because DOUT/R̅D̅Y̅ toggles during SPI transfers (in its 142 + DOUT aka MISO role) and so usually triggers a spurious interrupt. The 143 + distinction between such a spurious event and a real one can only be done 144 + by reading such a GPIO. (There is a register telling the same 145 + information, but accessing that one needs a SPI transfer which then 146 + triggers another interrupt event.) 147 + maxItems: 1 148 + 138 149 patternProperties: 139 150 "^channel@[0-9a-f]$": 140 151 type: object ··· 454 443 interrupts = <25 IRQ_TYPE_EDGE_FALLING>; 455 444 interrupt-names = "rdy"; 456 445 interrupt-parent = <&gpio>; 446 + rdy-gpios = <&gpio 25 GPIO_ACTIVE_LOW>; 457 447 spi-max-frequency = <5000000>; 458 448 gpio-controller; 459 449 #gpio-cells = <2>;
+15
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
··· 106 106 description: see Documentation/devicetree/bindings/iio/adc/adc.yaml 107 107 type: boolean 108 108 109 + rdy-gpios: 110 + description: 111 + GPIO reading the R̅D̅Y̅ line. Having such a GPIO is technically optional but 112 + highly recommended because DOUT/R̅D̅Y̅ toggles during SPI transfers (in its 113 + DOUT aka MISO role) and so usually triggers a spurious interrupt. The 114 + distinction between such a spurious event and a real one can only be done 115 + by reading such a GPIO. (There is a register telling the same 116 + information, but accessing that one needs a SPI transfer which then 117 + triggers another interrupt event.) 118 + maxItems: 1 119 + 109 120 patternProperties: 110 121 "^channel@[0-9a-f]+$": 111 122 type: object ··· 192 181 193 182 examples: 194 183 - | 184 + #include <dt-bindings/gpio/gpio.h> 195 185 spi { 196 186 #address-cells = <1>; 197 187 #size-cells = <0>; ··· 207 195 clock-names = "mclk"; 208 196 interrupts = <25 0x2>; 209 197 interrupt-parent = <&gpio>; 198 + rdy-gpios = <&gpio 25 GPIO_ACTIVE_LOW>; 210 199 aincom-supply = <&aincom>; 211 200 dvdd-supply = <&dvdd>; 212 201 avdd-supply = <&avdd>; ··· 220 207 }; 221 208 }; 222 209 - | 210 + #include <dt-bindings/gpio/gpio.h> 223 211 spi { 224 212 #address-cells = <1>; 225 213 #size-cells = <0>; ··· 238 224 #clock-cells = <0>; 239 225 interrupts = <25 0x2>; 240 226 interrupt-parent = <&gpio>; 227 + rdy-gpios = <&gpio 25 GPIO_ACTIVE_LOW>; 241 228 aincom-supply = <&aincom>; 242 229 dvdd-supply = <&dvdd>; 243 230 avdd-supply = <&avdd>;
+11
Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml
··· 63 63 marked GPIO_ACTIVE_LOW. 64 64 maxItems: 1 65 65 66 + rdy-gpios: 67 + description: 68 + GPIO reading the R̅D̅Y̅ line. Having such a GPIO is technically optional but 69 + highly recommended because DOUT/R̅D̅Y̅ toggles during SPI transfers (in its 70 + DOUT aka MISO role) and so usually triggers a spurious interrupt. The 71 + distinction between such a spurious event and a real one can only be done 72 + by reading such a GPIO. (There is a register telling the same 73 + information, but accessing that one needs a SPI transfer which then 74 + triggers another interrupt event.) 75 + maxItems: 1 76 + 66 77 required: 67 78 - compatible 68 79 - reg
+26 -11
Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml
··· 17 17 18 18 properties: 19 19 compatible: 20 - items: 21 - - enum: 22 - - renesas,r9a07g043-adc # RZ/G2UL and RZ/Five 23 - - renesas,r9a07g044-adc # RZ/G2L 24 - - renesas,r9a07g054-adc # RZ/V2L 25 - - const: renesas,rzg2l-adc 20 + oneOf: 21 + - items: 22 + - enum: 23 + - renesas,r9a07g043-adc # RZ/G2UL and RZ/Five 24 + - renesas,r9a07g044-adc # RZ/G2L 25 + - renesas,r9a07g054-adc # RZ/V2L 26 + - const: renesas,rzg2l-adc 27 + - items: 28 + - const: renesas,r9a08g045-adc # RZ/G3S 26 29 27 30 reg: 28 31 maxItems: 1 ··· 60 57 '#size-cells': 61 58 const: 0 62 59 60 + "#io-channel-cells": 61 + const: 1 62 + 63 63 required: 64 64 - compatible 65 65 - reg ··· 74 68 - reset-names 75 69 76 70 patternProperties: 77 - "^channel@[0-7]$": 71 + "^channel@[0-8]$": 78 72 $ref: adc.yaml 79 73 type: object 80 74 description: | ··· 84 78 reg: 85 79 description: | 86 80 The channel number. 81 + minimum: 0 82 + maximum: 8 87 83 88 84 required: 89 85 - reg ··· 100 92 const: renesas,r9a07g043-adc 101 93 then: 102 94 patternProperties: 103 - "^channel@[2-7]$": false 95 + "^channel@[2-8]$": false 104 96 "^channel@[0-1]$": 105 97 properties: 106 98 reg: 107 - minimum: 0 108 99 maximum: 1 109 - else: 100 + 101 + - if: 102 + properties: 103 + compatible: 104 + contains: 105 + enum: 106 + - renesas,r9a07g044-adc 107 + - renesas,r9a07g054-adc 108 + then: 110 109 patternProperties: 110 + "^channel@[8]$": false 111 111 "^channel@[0-7]$": 112 112 properties: 113 113 reg: 114 - minimum: 0 115 114 maximum: 7 116 115 117 116 additionalProperties: false
+62
Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/chemical/bosch,bme680.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Bosch BME680 Gas sensor 8 + 9 + maintainers: 10 + - Vasileios Amoiridis <vassilisamir@gmail.com> 11 + 12 + description: > 13 + BME680 is a gas sensor which combines relative humidity, barometric pressure, 14 + ambient temperature and gas (VOC - Volatile Organic Compounds) measurements. 15 + 16 + https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme680-ds001.pdf 17 + 18 + properties: 19 + compatible: 20 + const: bosch,bme680 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + vdd-supply: true 26 + vddio-supply: true 27 + 28 + required: 29 + - compatible 30 + - reg 31 + 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 36 + 37 + examples: 38 + - | 39 + i2c { 40 + #address-cells = <1>; 41 + #size-cells = <0>; 42 + 43 + co2-sensor@77 { 44 + compatible = "bosch,bme680"; 45 + reg = <0x77>; 46 + vddio-supply = <&vddio>; 47 + vdd-supply = <&vdd>; 48 + }; 49 + }; 50 + - | 51 + spi { 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + 55 + co2-sensor@0 { 56 + compatible = "bosch,bme680"; 57 + reg = <0>; 58 + spi-max-frequency = <500000>; 59 + vddio-supply = <&vddio>; 60 + vdd-supply = <&vdd>; 61 + }; 62 + };
+62
Documentation/devicetree/bindings/iio/dac/rohm,bd79703.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2024 ROHM Semiconductor. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/iio/dac/rohm,bd79703.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: ROHM BD79703 DAC device driver 9 + 10 + maintainers: 11 + - Matti Vaittinen <mazziesaccount@gmail.com> 12 + 13 + description: | 14 + The ROHM BD79703 is a 6 channel, 8-bit DAC. 15 + Datasheet can be found here: 16 + https://fscdn.rohm.com/en/products/databook/datasheet/ic/data_converter/dac/bd79702fv-lb_bd79703fv-lb-e.pdf 17 + 18 + properties: 19 + compatible: 20 + const: rohm,bd79703 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + spi-max-frequency: 26 + maximum: 30000000 27 + 28 + vfs-supply: 29 + description: 30 + The regulator to use as a full scale voltage. The voltage should be between 2.7V .. VCC 31 + 32 + vcc-supply: 33 + description: 34 + The regulator supplying the operating voltage. Should be between 2.7V ... 5.5V 35 + 36 + required: 37 + - compatible 38 + - reg 39 + - spi-max-frequency 40 + - vfs-supply 41 + - vcc-supply 42 + 43 + allOf: 44 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 45 + 46 + additionalProperties: false 47 + 48 + examples: 49 + - | 50 + spi { 51 + #address-cells = <1>; 52 + #size-cells = <0>; 53 + 54 + dac@0 { 55 + compatible = "rohm,bd79703"; 56 + reg = <0>; 57 + spi-max-frequency = <30000000>; 58 + vcc-supply = <&vcc>; 59 + vfs-supply = <&vref>; 60 + }; 61 + }; 62 + ...
+24 -18
Documentation/devicetree/bindings/iio/imu/adi,adis16480.yaml
··· 11 11 12 12 properties: 13 13 compatible: 14 - enum: 15 - - adi,adis16375 16 - - adi,adis16480 17 - - adi,adis16485 18 - - adi,adis16488 19 - - adi,adis16490 20 - - adi,adis16495-1 21 - - adi,adis16495-2 22 - - adi,adis16495-3 23 - - adi,adis16497-1 24 - - adi,adis16497-2 25 - - adi,adis16497-3 26 - - adi,adis16545-1 27 - - adi,adis16545-2 28 - - adi,adis16545-3 29 - - adi,adis16547-1 30 - - adi,adis16547-2 31 - - adi,adis16547-3 14 + oneOf: 15 + - enum: 16 + - adi,adis16375 17 + - adi,adis16480 18 + - adi,adis16485 19 + - adi,adis16486 20 + - adi,adis16488 21 + - adi,adis16489 22 + - adi,adis16490 23 + - adi,adis16495-1 24 + - adi,adis16495-2 25 + - adi,adis16495-3 26 + - adi,adis16497-1 27 + - adi,adis16497-2 28 + - adi,adis16497-3 29 + - adi,adis16545-1 30 + - adi,adis16545-2 31 + - adi,adis16545-3 32 + - adi,adis16547-1 33 + - adi,adis16547-2 34 + - adi,adis16547-3 35 + - items: 36 + - const: adi,adis16487 37 + - const: adi,adis16485 32 38 33 39 reg: 34 40 maxItems: 1
+1
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml
··· 37 37 to "INT2" if INT2 pin should be used instead 38 38 39 39 drive-open-drain: 40 + type: boolean 40 41 description: | 41 42 set if the specified interrupt pin should be configured as 42 43 open drain. If not set, defaults to push-pull.
+1
Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml
··· 41 41 - INT2 42 42 43 43 drive-open-drain: 44 + type: boolean 44 45 description: 45 46 set if the specified interrupt pins should be configured as 46 47 open drain. If not set, defaults to push-pull.
+1
Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
··· 38 38 - INT2 39 39 40 40 drive-open-drain: 41 + type: boolean 41 42 description: 42 43 set if the specified interrupt pin should be configured as 43 44 open drain. If not set, defaults to push-pull.
+1
Documentation/devicetree/bindings/iio/imu/invensense,mpu6050.yaml
··· 16 16 compatible: 17 17 oneOf: 18 18 - enum: 19 + - invensense,iam20380 19 20 - invensense,iam20680 20 21 - invensense,icm20608 21 22 - invensense,icm20609
-49
Documentation/devicetree/bindings/iio/light/rohm,bu27008.yaml
··· 1 - # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 - %YAML 1.2 3 - --- 4 - $id: http://devicetree.org/schemas/iio/light/rohm,bu27008.yaml# 5 - $schema: http://devicetree.org/meta-schemas/core.yaml# 6 - 7 - title: ROHM BU27008 color sensor 8 - 9 - maintainers: 10 - - Matti Vaittinen <mazziesaccount@gmail.com> 11 - 12 - description: 13 - The ROHM BU27008 is a sensor with 5 photodiodes (red, green, blue, clear 14 - and IR) with four configurable channels. Red and green being always 15 - available and two out of the rest three (blue, clear, IR) can be 16 - selected to be simultaneously measured. Typical application is adjusting 17 - LCD backlight of TVs, mobile phones and tablet PCs. 18 - 19 - properties: 20 - compatible: 21 - const: rohm,bu27008 22 - 23 - reg: 24 - maxItems: 1 25 - 26 - interrupts: 27 - maxItems: 1 28 - 29 - vdd-supply: true 30 - 31 - required: 32 - - compatible 33 - - reg 34 - 35 - additionalProperties: false 36 - 37 - examples: 38 - - | 39 - i2c { 40 - #address-cells = <1>; 41 - #size-cells = <0>; 42 - 43 - light-sensor@38 { 44 - compatible = "rohm,bu27008"; 45 - reg = <0x38>; 46 - }; 47 - }; 48 - 49 - ...
-50
Documentation/devicetree/bindings/iio/light/rohm,bu27010.yaml
··· 1 - # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 - %YAML 1.2 3 - --- 4 - $id: http://devicetree.org/schemas/iio/light/rohm,bu27010.yaml# 5 - $schema: http://devicetree.org/meta-schemas/core.yaml# 6 - 7 - title: ROHM BU27010 color sensor 8 - 9 - maintainers: 10 - - Matti Vaittinen <mazziesaccount@gmail.com> 11 - 12 - description: | 13 - The ROHM BU27010 is a sensor with 6 photodiodes (red, green, blue, clear, 14 - IR and flickering detection) with five configurable channels. Red, green 15 - and flickering detection being always available and two out of the rest 16 - three (blue, clear, IR) can be selected to be simultaneously measured. 17 - Typical application is adjusting LCD/OLED backlight of TVs, mobile phones 18 - and tablet PCs. 19 - 20 - properties: 21 - compatible: 22 - const: rohm,bu27010 23 - 24 - reg: 25 - maxItems: 1 26 - 27 - interrupts: 28 - maxItems: 1 29 - 30 - vdd-supply: true 31 - 32 - required: 33 - - compatible 34 - - reg 35 - - vdd-supply 36 - 37 - additionalProperties: false 38 - 39 - examples: 40 - - | 41 - i2c { 42 - #address-cells = <1>; 43 - #size-cells = <0>; 44 - 45 - light-sensor@38 { 46 - compatible = "rohm,bu27010"; 47 - reg = <0x38>; 48 - vdd-supply = <&vdd>; 49 - }; 50 - };
+51
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/light/ti,opt4060.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments OPT4060 RGBW Color Sensor 8 + 9 + maintainers: 10 + - Per-Daniel Olsson <perdaniel.olsson@axis.com> 11 + 12 + description: 13 + Texas Instrument RGBW high resolution color sensor over I2C. 14 + https://www.ti.com/lit/gpn/opt4060 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - ti,opt4060 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + vdd-supply: true 28 + 29 + required: 30 + - compatible 31 + - reg 32 + - vdd-supply 33 + 34 + additionalProperties: false 35 + 36 + examples: 37 + - | 38 + #include <dt-bindings/interrupt-controller/irq.h> 39 + i2c { 40 + #address-cells = <1>; 41 + #size-cells = <0>; 42 + 43 + light-sensor@44 { 44 + compatible = "ti,opt4060"; 45 + reg = <0x44>; 46 + vdd-supply = <&vdd_reg>; 47 + interrupt-parent = <&gpio5>; 48 + interrupts = <13 IRQ_TYPE_EDGE_FALLING>; 49 + }; 50 + }; 51 + ...
+29
Documentation/devicetree/bindings/iio/pressure/bmp085.yaml
··· 55 55 If not set, defaults to push-pull configuration. 56 56 type: boolean 57 57 58 + spi-max-frequency: 59 + maximum: 10000000 60 + 58 61 required: 59 62 - compatible 60 63 - vddd-supply 61 64 - vdda-supply 62 65 63 66 allOf: 67 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 64 68 - if: 65 69 properties: 66 70 compatible: ··· 77 73 then: 78 74 properties: 79 75 interrupts: false 76 + - if: 77 + properties: 78 + compatible: 79 + contains: 80 + enum: 81 + - bosch,bmp085 82 + - bosch,bmp180 83 + then: 84 + properties: 85 + spi-max-frequency: false 80 86 81 87 additionalProperties: false 82 88 ··· 102 88 reg = <0x77>; 103 89 interrupt-parent = <&gpio0>; 104 90 interrupts = <25 IRQ_TYPE_EDGE_RISING>; 91 + reset-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; 92 + vddd-supply = <&foo>; 93 + vdda-supply = <&bar>; 94 + }; 95 + }; 96 + - | 97 + # include <dt-bindings/gpio/gpio.h> 98 + # include <dt-bindings/interrupt-controller/irq.h> 99 + spi { 100 + #address-cells = <1>; 101 + #size-cells = <0>; 102 + pressure@0 { 103 + compatible = "bosch,bmp280"; 104 + reg = <0>; 105 + spi-max-frequency = <10000000>; 105 106 reset-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; 106 107 vddd-supply = <&foo>; 107 108 vdda-supply = <&bar>;
-2
Documentation/devicetree/bindings/trivial-devices.yaml
··· 55 55 - atmel,atsha204a 56 56 # BPA-RS600: Power Supply 57 57 - blutek,bpa-rs600 58 - # Bosch Sensortec pressure, temperature, humididty and VOC sensor 59 - - bosch,bme680 60 58 # CM32181: Ambient Light Sensor 61 59 - capella,cm32181 62 60 # CM3232: Ambient Light Sensor
+1 -1
Documentation/iio/ad4695.rst
··· 101 101 102 102 .. code-block:: 103 103 104 - #include <dt-bindings/iio/adi,ad4695.h> 104 + #include <dt-bindings/iio/adc/adi,ad4695.h> 105 105 106 106 Pairing two INx pins 107 107 ^^^^^^^^^^^^^^^^^^^^
+3
Documentation/iio/adis16480.rst
··· 12 12 * `ADIS16375 <https://www.analog.com/ADIS16375>`_ 13 13 * `ADIS16480 <https://www.analog.com/ADIS16480>`_ 14 14 * `ADIS16485 <https://www.analog.com/ADIS16485>`_ 15 + * `ADIS16486 <https://www.analog.com/ADIS16486>`_ 16 + * `ADIS16487 <https://www.analog.com/ADIS16487>`_ 15 17 * `ADIS16488 <https://www.analog.com/ADIS16488>`_ 18 + * `ADIS16489 <https://www.analog.com/ADIS16489>`_ 16 19 * `ADIS16490 <https://www.analog.com/ADIS16490>`_ 17 20 * `ADIS16495 <https://www.analog.com/ADIS16495>`_ 18 21 * `ADIS16497 <https://www.analog.com/ADIS16497>`_
+1
Documentation/iio/index.rst
··· 29 29 adxl380 30 30 bno055 31 31 ep93xx_adc 32 + opt4060
+61
Documentation/iio/opt4060.rst
··· 1 + ============================== 2 + OPT4060 driver 3 + ============================== 4 + 5 + 1. Overview 6 + ============================= 7 + 8 + This driver supports the Texas Instrument RGBW high resolution color sensor over 9 + I2C. 10 + https://www.ti.com/lit/gpn/opt4060 11 + 12 + The driver supports: 13 + - Raw values for red, green, blue and clear. 14 + - Illuminance values. 15 + - Scaled color values for red, green and blue. 16 + - IIO events for thresholds. 17 + - IIO triggered buffer using both its own data ready trigger and triggers from 18 + other drivers. 19 + 20 + 2. Illuminance calculation 21 + ============================= 22 + 23 + Illuminance is calculated using the wide spectrum green channel. 24 + 25 + lux = GREEN_RAW x 2.15e-3 26 + 27 + The value is accessed from: 28 + /sys/bus/iio/devices/iio:deviceX/in_illuminance_input 29 + 30 + See section 8.4.5.2 in the data sheet for additional details. 31 + 32 + 3. Color scale values 33 + ============================= 34 + 35 + The sensor has different sensitivity for the different color components and 36 + compensating factors are exposed from the driver. 37 + 38 + The values are accessed from: 39 + /sys/bus/iio/devices/iio:deviceX/in_intensity_red_scale 40 + /sys/bus/iio/devices/iio:deviceX/in_intensity_green_scale 41 + /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_scale 42 + 43 + A userspace application can multiply the raw values with the scale values so 44 + that for a particular test light source, typically white, the measurement 45 + intensity is the same across the different color channels. This is calculated 46 + in the following way: 47 + 48 + R = RED_RAW x SCALE_RED(2.4) 49 + G = GREEN_RAW x SCALE_GREEN(1.0) 50 + B = BLUE_RAW x SCALE_BLUE(1.3) 51 + 52 + The data sheet suggests using the scaled values to normalize the scaled R, G 53 + and B values. This is useful to get a value for the ratio between colors 54 + independent of light intensity. A userspace application can do this in the 55 + following way: 56 + 57 + R_NORMALIZED = R / (R + G + B) 58 + G_NORMALIZED = G / (R + G + B) 59 + B_NORMALIZED = B / (R + G + B) 60 + 61 + See section 8.4.5.2 in the data sheet for additional details.
+6 -2
MAINTAINERS
··· 1292 1292 F: Documentation/devicetree/bindings/iio/adc/adi,ad4695.yaml 1293 1293 F: Documentation/iio/ad4695.rst 1294 1294 F: drivers/iio/adc/ad4695.c 1295 - F: include/dt-bindings/iio/adi,ad4695.h 1295 + F: include/dt-bindings/iio/adc/adi,ad4695.h 1296 1296 1297 1297 ANALOG DEVICES INC AD7091R DRIVER 1298 1298 M: Marcelo Schmitt <marcelo.schmitt@analog.com> ··· 20304 20304 S: Odd Fixes 20305 20305 F: drivers/tty/serial/rp2.* 20306 20306 20307 + ROHM BD79703 DAC 20308 + M: Matti Vaittinen <mazziesaccount@gmail.com> 20309 + S: Supported 20310 + F: drivers/iio/dac/rohm-bd79703.c 20311 + 20307 20312 ROHM BD99954 CHARGER IC 20308 20313 M: Matti Vaittinen <mazziesaccount@gmail.com> 20309 20314 S: Supported ··· 20337 20332 M: Matti Vaittinen <mazziesaccount@gmail.com> 20338 20333 L: linux-iio@vger.kernel.org 20339 20334 S: Supported 20340 - F: drivers/iio/light/rohm-bu27008.c 20341 20335 F: drivers/iio/light/rohm-bu27034.c 20342 20336 20343 20337 ROHM MULTIFUNCTION BD9571MWV-M PMIC DEVICE DRIVERS
+69 -12
drivers/iio/accel/adxl345.h
··· 9 9 #define _ADXL345_H_ 10 10 11 11 #define ADXL345_REG_DEVID 0x00 12 + #define ADXL345_REG_THRESH_TAP 0x1D 12 13 #define ADXL345_REG_OFSX 0x1E 13 14 #define ADXL345_REG_OFSY 0x1F 14 15 #define ADXL345_REG_OFSZ 0x20 15 16 #define ADXL345_REG_OFS_AXIS(index) (ADXL345_REG_OFSX + (index)) 17 + 18 + /* Tap duration */ 19 + #define ADXL345_REG_DUR 0x21 20 + /* Tap latency */ 21 + #define ADXL345_REG_LATENT 0x22 22 + /* Tap window */ 23 + #define ADXL345_REG_WINDOW 0x23 24 + /* Activity threshold */ 25 + #define ADXL345_REG_THRESH_ACT 0x24 26 + /* Inactivity threshold */ 27 + #define ADXL345_REG_THRESH_INACT 0x25 28 + /* Inactivity time */ 29 + #define ADXL345_REG_TIME_INACT 0x26 30 + /* Axis enable control for activity and inactivity detection */ 31 + #define ADXL345_REG_ACT_INACT_CTRL 0x27 32 + /* Free-fall threshold */ 33 + #define ADXL345_REG_THRESH_FF 0x28 34 + /* Free-fall time */ 35 + #define ADXL345_REG_TIME_FF 0x29 36 + /* Axis control for single tap or double tap */ 37 + #define ADXL345_REG_TAP_AXIS 0x2A 38 + /* Source of single tap or double tap */ 39 + #define ADXL345_REG_ACT_TAP_STATUS 0x2B 40 + /* Data rate and power mode control */ 16 41 #define ADXL345_REG_BW_RATE 0x2C 17 42 #define ADXL345_REG_POWER_CTL 0x2D 43 + #define ADXL345_REG_INT_ENABLE 0x2E 44 + #define ADXL345_REG_INT_MAP 0x2F 45 + #define ADXL345_REG_INT_SOURCE 0x30 46 + #define ADXL345_REG_INT_SOURCE_MSK 0xFF 18 47 #define ADXL345_REG_DATA_FORMAT 0x31 19 - #define ADXL345_REG_DATAX0 0x32 20 - #define ADXL345_REG_DATAY0 0x34 21 - #define ADXL345_REG_DATAZ0 0x36 22 - #define ADXL345_REG_DATA_AXIS(index) \ 23 - (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) 48 + #define ADXL345_REG_XYZ_BASE 0x32 49 + #define ADXL345_REG_DATA_AXIS(index) \ 50 + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) 24 51 52 + #define ADXL345_REG_FIFO_CTL 0x38 53 + #define ADXL345_FIFO_CTL_SAMPLES_MSK GENMASK(4, 0) 54 + /* 0: INT1, 1: INT2 */ 55 + #define ADXL345_FIFO_CTL_TRIGGER_MSK BIT(5) 56 + #define ADXL345_FIFO_CTL_MODE_MSK GENMASK(7, 6) 57 + #define ADXL345_REG_FIFO_STATUS 0x39 58 + #define ADXL345_REG_FIFO_STATUS_MSK 0x3F 59 + 60 + #define ADXL345_INT_OVERRUN BIT(0) 61 + #define ADXL345_INT_WATERMARK BIT(1) 62 + #define ADXL345_INT_FREE_FALL BIT(2) 63 + #define ADXL345_INT_INACTIVITY BIT(3) 64 + #define ADXL345_INT_ACTIVITY BIT(4) 65 + #define ADXL345_INT_DOUBLE_TAP BIT(5) 66 + #define ADXL345_INT_SINGLE_TAP BIT(6) 67 + #define ADXL345_INT_DATA_READY BIT(7) 68 + 69 + /* 70 + * BW_RATE bits - Bandwidth and output data rate. The default value is 71 + * 0x0A, which translates to a 100 Hz output data rate 72 + */ 25 73 #define ADXL345_BW_RATE GENMASK(3, 0) 74 + #define ADXL345_BW_LOW_POWER BIT(4) 26 75 #define ADXL345_BASE_RATE_NANO_HZ 97656250LL 27 76 28 - #define ADXL345_POWER_CTL_MEASURE BIT(3) 29 77 #define ADXL345_POWER_CTL_STANDBY 0x00 78 + #define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) 79 + #define ADXL345_POWER_CTL_SLEEP BIT(2) 80 + #define ADXL345_POWER_CTL_MEASURE BIT(3) 81 + #define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) 82 + #define ADXL345_POWER_CTL_LINK BIT(5) 30 83 31 - #define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ 32 - #define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ 33 - #define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ 34 - #define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) /* 3-wire SPI mode */ 35 - #define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ 36 - 84 + /* Set the g range */ 85 + #define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) 86 + /* Data is left justified */ 87 + #define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) 88 + /* Up to 13-bits resolution */ 89 + #define ADXL345_DATA_FORMAT_FULL_RES BIT(3) 90 + #define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) 91 + #define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) 37 92 #define ADXL345_DATA_FORMAT_2G 0 38 93 #define ADXL345_DATA_FORMAT_4G 1 39 94 #define ADXL345_DATA_FORMAT_8G 2 40 95 #define ADXL345_DATA_FORMAT_16G 3 41 96 42 97 #define ADXL345_DEVID 0xE5 98 + #define ADXL345_FIFO_SIZE 32 43 99 44 100 /* 45 101 * In full-resolution mode, scale factor is maintained at ~4 mg/LSB ··· 118 62 }; 119 63 120 64 int adxl345_core_probe(struct device *dev, struct regmap *regmap, 65 + bool fifo_delay_default, 121 66 int (*setup)(struct device*, struct regmap*)); 122 67 123 68 #endif /* _ADXL345_H_ */
+381 -40
drivers/iio/accel/adxl345_core.c
··· 7 7 * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf 8 8 */ 9 9 10 + #include <linux/bitfield.h> 11 + #include <linux/interrupt.h> 10 12 #include <linux/module.h> 11 13 #include <linux/property.h> 12 14 #include <linux/regmap.h> ··· 16 14 17 15 #include <linux/iio/iio.h> 18 16 #include <linux/iio/sysfs.h> 17 + #include <linux/iio/buffer.h> 18 + #include <linux/iio/kfifo_buf.h> 19 19 20 20 #include "adxl345.h" 21 21 22 - struct adxl345_data { 22 + #define ADXL345_FIFO_BYPASS 0 23 + #define ADXL345_FIFO_FIFO 1 24 + #define ADXL345_FIFO_STREAM 2 25 + 26 + #define ADXL345_DIRS 3 27 + 28 + #define ADXL345_INT_NONE 0xff 29 + #define ADXL345_INT1 0 30 + #define ADXL345_INT2 1 31 + 32 + struct adxl345_state { 23 33 const struct adxl345_chip_info *info; 24 34 struct regmap *regmap; 35 + bool fifo_delay; /* delay: delay is needed for SPI */ 36 + int irq; 37 + u8 intio; 38 + u8 int_map; 39 + u8 watermark; 40 + u8 fifo_mode; 41 + __le16 fifo_buf[ADXL345_DIRS * ADXL345_FIFO_SIZE + 1] __aligned(IIO_DMA_MINALIGN); 25 42 }; 26 43 27 - #define ADXL345_CHANNEL(index, axis) { \ 44 + #define ADXL345_CHANNEL(index, reg, axis) { \ 28 45 .type = IIO_ACCEL, \ 29 46 .modified = 1, \ 30 47 .channel2 = IIO_MOD_##axis, \ 31 - .address = index, \ 48 + .address = (reg), \ 32 49 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 33 50 BIT(IIO_CHAN_INFO_CALIBBIAS), \ 34 51 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 35 52 BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 53 + .scan_index = (index), \ 54 + .scan_type = { \ 55 + .sign = 's', \ 56 + .realbits = 13, \ 57 + .storagebits = 16, \ 58 + .endianness = IIO_LE, \ 59 + }, \ 36 60 } 37 61 38 - static const struct iio_chan_spec adxl345_channels[] = { 39 - ADXL345_CHANNEL(0, X), 40 - ADXL345_CHANNEL(1, Y), 41 - ADXL345_CHANNEL(2, Z), 62 + enum adxl345_chans { 63 + chan_x, chan_y, chan_z, 42 64 }; 65 + 66 + static const struct iio_chan_spec adxl345_channels[] = { 67 + ADXL345_CHANNEL(0, chan_x, X), 68 + ADXL345_CHANNEL(1, chan_y, Y), 69 + ADXL345_CHANNEL(2, chan_z, Z), 70 + }; 71 + 72 + static const unsigned long adxl345_scan_masks[] = { 73 + BIT(chan_x) | BIT(chan_y) | BIT(chan_z), 74 + 0 75 + }; 76 + 77 + static int adxl345_set_interrupts(struct adxl345_state *st) 78 + { 79 + int ret; 80 + unsigned int int_enable = st->int_map; 81 + unsigned int int_map; 82 + 83 + /* 84 + * Any bits set to 0 in the INT map register send their respective 85 + * interrupts to the INT1 pin, whereas bits set to 1 send their respective 86 + * interrupts to the INT2 pin. The intio shall convert this accordingly. 87 + */ 88 + int_map = FIELD_GET(ADXL345_REG_INT_SOURCE_MSK, 89 + st->intio ? st->int_map : ~st->int_map); 90 + 91 + ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, int_map); 92 + if (ret) 93 + return ret; 94 + 95 + return regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, int_enable); 96 + } 43 97 44 98 static int adxl345_read_raw(struct iio_dev *indio_dev, 45 99 struct iio_chan_spec const *chan, 46 100 int *val, int *val2, long mask) 47 101 { 48 - struct adxl345_data *data = iio_priv(indio_dev); 102 + struct adxl345_state *st = iio_priv(indio_dev); 49 103 __le16 accel; 50 104 long long samp_freq_nhz; 51 105 unsigned int regval; ··· 114 56 * ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte 115 57 * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte 116 58 */ 117 - ret = regmap_bulk_read(data->regmap, 59 + ret = regmap_bulk_read(st->regmap, 118 60 ADXL345_REG_DATA_AXIS(chan->address), 119 61 &accel, sizeof(accel)); 120 62 if (ret < 0) ··· 124 66 return IIO_VAL_INT; 125 67 case IIO_CHAN_INFO_SCALE: 126 68 *val = 0; 127 - *val2 = data->info->uscale; 69 + *val2 = st->info->uscale; 128 70 return IIO_VAL_INT_PLUS_MICRO; 129 71 case IIO_CHAN_INFO_CALIBBIAS: 130 - ret = regmap_read(data->regmap, 72 + ret = regmap_read(st->regmap, 131 73 ADXL345_REG_OFS_AXIS(chan->address), &regval); 132 74 if (ret < 0) 133 75 return ret; ··· 139 81 140 82 return IIO_VAL_INT; 141 83 case IIO_CHAN_INFO_SAMP_FREQ: 142 - ret = regmap_read(data->regmap, ADXL345_REG_BW_RATE, &regval); 84 + ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, &regval); 143 85 if (ret < 0) 144 86 return ret; 145 87 ··· 157 99 struct iio_chan_spec const *chan, 158 100 int val, int val2, long mask) 159 101 { 160 - struct adxl345_data *data = iio_priv(indio_dev); 102 + struct adxl345_state *st = iio_priv(indio_dev); 161 103 s64 n; 162 104 163 105 switch (mask) { ··· 166 108 * 8-bit resolution at +/- 2g, that is 4x accel data scale 167 109 * factor 168 110 */ 169 - return regmap_write(data->regmap, 111 + return regmap_write(st->regmap, 170 112 ADXL345_REG_OFS_AXIS(chan->address), 171 113 val / 4); 172 114 case IIO_CHAN_INFO_SAMP_FREQ: 173 115 n = div_s64(val * NANOHZ_PER_HZ + val2, 174 116 ADXL345_BASE_RATE_NANO_HZ); 175 117 176 - return regmap_update_bits(data->regmap, ADXL345_REG_BW_RATE, 118 + return regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, 177 119 ADXL345_BW_RATE, 178 120 clamp_val(ilog2(n), 0, 179 121 ADXL345_BW_RATE)); 180 122 } 181 123 182 124 return -EINVAL; 125 + } 126 + 127 + static int adxl345_set_watermark(struct iio_dev *indio_dev, unsigned int value) 128 + { 129 + struct adxl345_state *st = iio_priv(indio_dev); 130 + unsigned int fifo_mask = 0x1F; 131 + int ret; 132 + 133 + value = min(value, ADXL345_FIFO_SIZE - 1); 134 + 135 + ret = regmap_update_bits(st->regmap, ADXL345_REG_FIFO_CTL, fifo_mask, value); 136 + if (ret) 137 + return ret; 138 + 139 + st->watermark = value; 140 + st->int_map |= ADXL345_INT_WATERMARK; 141 + 142 + return 0; 183 143 } 184 144 185 145 static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, ··· 214 138 } 215 139 } 216 140 141 + /** 142 + * adxl345_set_measure_en() - Enable and disable measuring. 143 + * 144 + * @st: The device data. 145 + * @en: Enable measurements, else standby mode. 146 + * 147 + * For lowest power operation, standby mode can be used. In standby mode, 148 + * current consumption is supposed to be reduced to 0.1uA (typical). In this 149 + * mode no measurements are made. Placing the device into standby mode 150 + * preserves the contents of FIFO. 151 + * 152 + * Return: Returns 0 if successful, or a negative error value. 153 + */ 154 + static int adxl345_set_measure_en(struct adxl345_state *st, bool en) 155 + { 156 + unsigned int val = en ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_STANDBY; 157 + 158 + return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); 159 + } 160 + 161 + static void adxl345_powerdown(void *ptr) 162 + { 163 + struct adxl345_state *st = ptr; 164 + 165 + adxl345_set_measure_en(st, false); 166 + } 167 + 217 168 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( 218 169 "0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" 219 170 ); ··· 254 151 .attrs = adxl345_attrs, 255 152 }; 256 153 154 + static int adxl345_set_fifo(struct adxl345_state *st) 155 + { 156 + int ret; 157 + 158 + /* FIFO should only be configured while in standby mode */ 159 + ret = adxl345_set_measure_en(st, false); 160 + if (ret < 0) 161 + return ret; 162 + 163 + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, 164 + FIELD_PREP(ADXL345_FIFO_CTL_SAMPLES_MSK, 165 + st->watermark) | 166 + FIELD_PREP(ADXL345_FIFO_CTL_TRIGGER_MSK, 167 + st->intio) | 168 + FIELD_PREP(ADXL345_FIFO_CTL_MODE_MSK, 169 + st->fifo_mode)); 170 + if (ret < 0) 171 + return ret; 172 + 173 + return adxl345_set_measure_en(st, true); 174 + } 175 + 176 + /** 177 + * adxl345_get_samples() - Read number of FIFO entries. 178 + * @st: The initialized state instance of this driver. 179 + * 180 + * The sensor does not support treating any axis individually, or exclude them 181 + * from measuring. 182 + * 183 + * Return: negative error, or value. 184 + */ 185 + static int adxl345_get_samples(struct adxl345_state *st) 186 + { 187 + unsigned int regval = 0; 188 + int ret; 189 + 190 + ret = regmap_read(st->regmap, ADXL345_REG_FIFO_STATUS, &regval); 191 + if (ret < 0) 192 + return ret; 193 + 194 + return FIELD_GET(ADXL345_REG_FIFO_STATUS_MSK, regval); 195 + } 196 + 197 + /** 198 + * adxl345_fifo_transfer() - Read samples number of elements. 199 + * @st: The instance of the state object of this sensor. 200 + * @samples: The number of lines in the FIFO referred to as fifo_entry. 201 + * 202 + * It is recommended that a multiple-byte read of all registers be performed to 203 + * prevent a change in data between reads of sequential registers. That is to 204 + * read out the data registers X0, X1, Y0, Y1, Z0, Z1, i.e. 6 bytes at once. 205 + * 206 + * Return: 0 or error value. 207 + */ 208 + static int adxl345_fifo_transfer(struct adxl345_state *st, int samples) 209 + { 210 + size_t count; 211 + int i, ret = 0; 212 + 213 + /* count is the 3x the fifo_buf element size, hence 6B */ 214 + count = sizeof(st->fifo_buf[0]) * ADXL345_DIRS; 215 + for (i = 0; i < samples; i++) { 216 + /* read 3x 2 byte elements from base address into next fifo_buf position */ 217 + ret = regmap_bulk_read(st->regmap, ADXL345_REG_XYZ_BASE, 218 + st->fifo_buf + (i * count / 2), count); 219 + if (ret < 0) 220 + return ret; 221 + 222 + /* 223 + * To ensure that the FIFO has completely popped, there must be at least 5 224 + * us between the end of reading the data registers, signified by the 225 + * transition to register 0x38 from 0x37 or the CS pin going high, and the 226 + * start of new reads of the FIFO or reading the FIFO_STATUS register. For 227 + * SPI operation at 1.5 MHz or lower, the register addressing portion of the 228 + * transmission is sufficient delay to ensure the FIFO has completely 229 + * popped. It is necessary for SPI operation greater than 1.5 MHz to 230 + * de-assert the CS pin to ensure a total of 5 us, which is at most 3.4 us 231 + * at 5 MHz operation. 232 + */ 233 + if (st->fifo_delay && samples > 1) 234 + udelay(3); 235 + } 236 + return ret; 237 + } 238 + 239 + /** 240 + * adxl345_fifo_reset() - Empty the FIFO in error condition. 241 + * @st: The instance to the state object of the sensor. 242 + * 243 + * Read all elements of the FIFO. Reading the interrupt source register 244 + * resets the sensor. 245 + */ 246 + static void adxl345_fifo_reset(struct adxl345_state *st) 247 + { 248 + int regval; 249 + int samples; 250 + 251 + adxl345_set_measure_en(st, false); 252 + 253 + samples = adxl345_get_samples(st); 254 + if (samples > 0) 255 + adxl345_fifo_transfer(st, samples); 256 + 257 + regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, &regval); 258 + 259 + adxl345_set_measure_en(st, true); 260 + } 261 + 262 + static int adxl345_buffer_postenable(struct iio_dev *indio_dev) 263 + { 264 + struct adxl345_state *st = iio_priv(indio_dev); 265 + int ret; 266 + 267 + ret = adxl345_set_interrupts(st); 268 + if (ret < 0) 269 + return ret; 270 + 271 + st->fifo_mode = ADXL345_FIFO_STREAM; 272 + return adxl345_set_fifo(st); 273 + } 274 + 275 + static int adxl345_buffer_predisable(struct iio_dev *indio_dev) 276 + { 277 + struct adxl345_state *st = iio_priv(indio_dev); 278 + int ret; 279 + 280 + st->fifo_mode = ADXL345_FIFO_BYPASS; 281 + ret = adxl345_set_fifo(st); 282 + if (ret < 0) 283 + return ret; 284 + 285 + st->int_map = 0x00; 286 + return adxl345_set_interrupts(st); 287 + } 288 + 289 + static const struct iio_buffer_setup_ops adxl345_buffer_ops = { 290 + .postenable = adxl345_buffer_postenable, 291 + .predisable = adxl345_buffer_predisable, 292 + }; 293 + 294 + static int adxl345_get_status(struct adxl345_state *st) 295 + { 296 + int ret; 297 + unsigned int regval; 298 + 299 + ret = regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, &regval); 300 + if (ret < 0) 301 + return ret; 302 + 303 + return FIELD_GET(ADXL345_REG_INT_SOURCE_MSK, regval); 304 + } 305 + 306 + static int adxl345_fifo_push(struct iio_dev *indio_dev, 307 + int samples) 308 + { 309 + struct adxl345_state *st = iio_priv(indio_dev); 310 + int i, ret; 311 + 312 + if (samples <= 0) 313 + return -EINVAL; 314 + 315 + ret = adxl345_fifo_transfer(st, samples); 316 + if (ret) 317 + return ret; 318 + 319 + for (i = 0; i < ADXL345_DIRS * samples; i += ADXL345_DIRS) 320 + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); 321 + 322 + return 0; 323 + } 324 + 325 + /** 326 + * adxl345_irq_handler() - Handle irqs of the ADXL345. 327 + * @irq: The irq being handled. 328 + * @p: The struct iio_device pointer for the device. 329 + * 330 + * Return: The interrupt was handled. 331 + */ 332 + static irqreturn_t adxl345_irq_handler(int irq, void *p) 333 + { 334 + struct iio_dev *indio_dev = p; 335 + struct adxl345_state *st = iio_priv(indio_dev); 336 + int int_stat; 337 + int samples; 338 + 339 + int_stat = adxl345_get_status(st); 340 + if (int_stat <= 0) 341 + return IRQ_NONE; 342 + 343 + if (int_stat & ADXL345_INT_OVERRUN) 344 + goto err; 345 + 346 + if (int_stat & ADXL345_INT_WATERMARK) { 347 + samples = adxl345_get_samples(st); 348 + if (samples < 0) 349 + goto err; 350 + 351 + if (adxl345_fifo_push(indio_dev, samples) < 0) 352 + goto err; 353 + } 354 + return IRQ_HANDLED; 355 + 356 + err: 357 + adxl345_fifo_reset(st); 358 + 359 + return IRQ_HANDLED; 360 + } 361 + 257 362 static const struct iio_info adxl345_info = { 258 363 .attrs = &adxl345_attrs_group, 259 364 .read_raw = adxl345_read_raw, 260 365 .write_raw = adxl345_write_raw, 261 366 .write_raw_get_fmt = adxl345_write_raw_get_fmt, 367 + .hwfifo_set_watermark = adxl345_set_watermark, 262 368 }; 263 369 264 - static int adxl345_powerup(void *regmap) 265 - { 266 - return regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_MEASURE); 267 - } 268 - 269 - static void adxl345_powerdown(void *regmap) 270 - { 271 - regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); 272 - } 273 - 274 370 /** 275 - * adxl345_core_probe() - probe and setup for the adxl345 accelerometer, 276 - * also covers the adlx375 accelerometer 371 + * adxl345_core_probe() - Probe and setup for the accelerometer. 277 372 * @dev: Driver model representation of the device 278 373 * @regmap: Regmap instance for the device 374 + * @fifo_delay_default: Using FIFO with SPI needs delay 279 375 * @setup: Setup routine to be executed right before the standard device 280 376 * setup 377 + * 378 + * For SPI operation greater than 1.6 MHz, it is necessary to deassert the CS 379 + * pin to ensure a total delay of 5 us; otherwise, the delay is not sufficient. 380 + * The total delay necessary for 5 MHz operation is at most 3.4 us. This is not 381 + * a concern when using I2C mode because the communication rate is low enough 382 + * to ensure a sufficient delay between FIFO reads. 383 + * Ref: "Retrieving Data from FIFO", p. 21 of 36, Data Sheet ADXL345 Rev. G 281 384 * 282 385 * Return: 0 on success, negative errno on error 283 386 */ 284 387 int adxl345_core_probe(struct device *dev, struct regmap *regmap, 388 + bool fifo_delay_default, 285 389 int (*setup)(struct device*, struct regmap*)) 286 390 { 287 - struct adxl345_data *data; 391 + struct adxl345_state *st; 288 392 struct iio_dev *indio_dev; 289 393 u32 regval; 290 394 unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | ··· 500 190 ADXL345_DATA_FORMAT_SELF_TEST); 501 191 int ret; 502 192 503 - indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 193 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 504 194 if (!indio_dev) 505 195 return -ENOMEM; 506 196 507 - data = iio_priv(indio_dev); 508 - data->regmap = regmap; 509 - data->info = device_get_match_data(dev); 510 - if (!data->info) 197 + st = iio_priv(indio_dev); 198 + st->regmap = regmap; 199 + st->info = device_get_match_data(dev); 200 + if (!st->info) 511 201 return -ENODEV; 202 + st->fifo_delay = fifo_delay_default; 512 203 513 - indio_dev->name = data->info->name; 204 + indio_dev->name = st->info->name; 514 205 indio_dev->info = &adxl345_info; 515 206 indio_dev->modes = INDIO_DIRECT_MODE; 516 207 indio_dev->channels = adxl345_channels; 517 208 indio_dev->num_channels = ARRAY_SIZE(adxl345_channels); 209 + indio_dev->available_scan_masks = adxl345_scan_masks; 518 210 519 211 if (setup) { 520 212 /* Perform optional initial bus specific configuration */ 521 - ret = setup(dev, data->regmap); 213 + ret = setup(dev, st->regmap); 522 214 if (ret) 523 215 return ret; 524 216 525 217 /* Enable full-resolution mode */ 526 - ret = regmap_update_bits(data->regmap, ADXL345_REG_DATA_FORMAT, 218 + ret = regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, 527 219 data_format_mask, 528 220 ADXL345_DATA_FORMAT_FULL_RES); 529 221 if (ret) ··· 534 222 535 223 } else { 536 224 /* Enable full-resolution mode (init all data_format bits) */ 537 - ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, 225 + ret = regmap_write(st->regmap, ADXL345_REG_DATA_FORMAT, 538 226 ADXL345_DATA_FORMAT_FULL_RES); 539 227 if (ret) 540 228 return dev_err_probe(dev, ret, 541 229 "Failed to set data range\n"); 542 230 } 543 231 544 - ret = regmap_read(data->regmap, ADXL345_REG_DEVID, &regval); 232 + ret = regmap_read(st->regmap, ADXL345_REG_DEVID, &regval); 545 233 if (ret < 0) 546 234 return dev_err_probe(dev, ret, "Error reading device ID\n"); 547 235 ··· 550 238 regval, ADXL345_DEVID); 551 239 552 240 /* Enable measurement mode */ 553 - ret = adxl345_powerup(data->regmap); 241 + ret = adxl345_set_measure_en(st, true); 554 242 if (ret < 0) 555 243 return dev_err_probe(dev, ret, "Failed to enable measurement mode\n"); 556 244 557 - ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); 245 + ret = devm_add_action_or_reset(dev, adxl345_powerdown, st); 558 246 if (ret < 0) 559 247 return ret; 248 + 249 + st->intio = ADXL345_INT1; 250 + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); 251 + if (st->irq < 0) { 252 + st->intio = ADXL345_INT2; 253 + st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2"); 254 + if (st->irq < 0) 255 + st->intio = ADXL345_INT_NONE; 256 + } 257 + 258 + if (st->intio != ADXL345_INT_NONE) { 259 + /* FIFO_STREAM mode is going to be activated later */ 260 + ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, &adxl345_buffer_ops); 261 + if (ret) 262 + return ret; 263 + 264 + ret = devm_request_threaded_irq(dev, st->irq, NULL, 265 + &adxl345_irq_handler, 266 + IRQF_SHARED | IRQF_ONESHOT, 267 + indio_dev->name, indio_dev); 268 + if (ret) 269 + return ret; 270 + } else { 271 + ret = regmap_write(st->regmap, ADXL345_REG_FIFO_CTL, 272 + FIELD_PREP(ADXL345_FIFO_CTL_MODE_MSK, 273 + ADXL345_FIFO_BYPASS)); 274 + if (ret < 0) 275 + return ret; 276 + } 560 277 561 278 return devm_iio_device_register(dev, indio_dev); 562 279 }
+1 -1
drivers/iio/accel/adxl345_i2c.c
··· 27 27 if (IS_ERR(regmap)) 28 28 return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n"); 29 29 30 - return adxl345_core_probe(&client->dev, regmap, NULL); 30 + return adxl345_core_probe(&client->dev, regmap, false, NULL); 31 31 } 32 32 33 33 static const struct adxl345_chip_info adxl345_i2c_info = {
+5 -2
drivers/iio/accel/adxl345_spi.c
··· 12 12 #include "adxl345.h" 13 13 14 14 #define ADXL345_MAX_SPI_FREQ_HZ 5000000 15 + #define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000 15 16 16 17 static const struct regmap_config adxl345_spi_regmap_config = { 17 18 .reg_bits = 8, ··· 29 28 static int adxl345_spi_probe(struct spi_device *spi) 30 29 { 31 30 struct regmap *regmap; 31 + bool needs_delay; 32 32 33 33 /* Bail out if max_speed_hz exceeds 5 MHz */ 34 34 if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) ··· 40 38 if (IS_ERR(regmap)) 41 39 return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n"); 42 40 41 + needs_delay = spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY; 43 42 if (spi->mode & SPI_3WIRE) 44 - return adxl345_core_probe(&spi->dev, regmap, adxl345_spi_setup); 43 + return adxl345_core_probe(&spi->dev, regmap, needs_delay, adxl345_spi_setup); 45 44 else 46 - return adxl345_core_probe(&spi->dev, regmap, NULL); 45 + return adxl345_core_probe(&spi->dev, regmap, needs_delay, NULL); 47 46 } 48 47 49 48 static const struct adxl345_chip_info adxl345_spi_info = {
+1 -1
drivers/iio/accel/bma220_spi.c
··· 66 66 struct { 67 67 s8 chans[3]; 68 68 /* Ensure timestamp is naturally aligned. */ 69 - s64 timestamp __aligned(8); 69 + aligned_s64 timestamp; 70 70 } scan; 71 71 u8 tx_buf[2] __aligned(IIO_DMA_MINALIGN); 72 72 };
+14
drivers/iio/accel/fxls8962af-core.c
··· 129 129 130 130 #define FXLS8962AF_DEVICE_ID 0x62 131 131 #define FXLS8964AF_DEVICE_ID 0x84 132 + #define FXLS8974CF_DEVICE_ID 0x86 133 + #define FXLS8967AF_DEVICE_ID 0x87 132 134 133 135 /* Raw temp channel offset */ 134 136 #define FXLS8962AF_TEMP_CENTER_VAL 25 ··· 765 763 [fxls8964af] = { 766 764 .chip_id = FXLS8964AF_DEVICE_ID, 767 765 .name = "fxls8964af", 766 + .channels = fxls8962af_channels, 767 + .num_channels = ARRAY_SIZE(fxls8962af_channels), 768 + }, 769 + [fxls8967af] = { 770 + .chip_id = FXLS8967AF_DEVICE_ID, 771 + .name = "fxls8967af", 772 + .channels = fxls8962af_channels, 773 + .num_channels = ARRAY_SIZE(fxls8962af_channels), 774 + }, 775 + [fxls8974cf] = { 776 + .chip_id = FXLS8974CF_DEVICE_ID, 777 + .name = "fxls8974cf", 768 778 .channels = fxls8962af_channels, 769 779 .num_channels = ARRAY_SIZE(fxls8962af_channels), 770 780 },
+2
drivers/iio/accel/fxls8962af-i2c.c
··· 30 30 static const struct i2c_device_id fxls8962af_id[] = { 31 31 { "fxls8962af", fxls8962af }, 32 32 { "fxls8964af", fxls8964af }, 33 + { "fxls8967af", fxls8967af }, 34 + { "fxls8974cf", fxls8974cf }, 33 35 {} 34 36 }; 35 37 MODULE_DEVICE_TABLE(i2c, fxls8962af_id);
+2
drivers/iio/accel/fxls8962af.h
··· 11 11 enum { 12 12 fxls8962af, 13 13 fxls8964af, 14 + fxls8967af, 15 + fxls8974cf, 14 16 }; 15 17 16 18 int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq);
+4
drivers/iio/accel/kionix-kx022a-i2c.c
··· 38 38 static const struct i2c_device_id kx022a_i2c_id[] = { 39 39 { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, 40 40 { .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info }, 41 + { .name = "kx134-1211", .driver_data = (kernel_ulong_t)&kx134_chip_info }, 41 42 { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info }, 43 + { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info }, 42 44 { } 43 45 }; 44 46 MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id); ··· 48 46 static const struct of_device_id kx022a_of_match[] = { 49 47 { .compatible = "kionix,kx022a", .data = &kx022a_chip_info }, 50 48 { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info }, 49 + { .compatible = "kionix,kx134-1211", .data = &kx134_chip_info }, 51 50 { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info }, 51 + { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info }, 52 52 { } 53 53 }; 54 54 MODULE_DEVICE_TABLE(of, kx022a_of_match);
+4
drivers/iio/accel/kionix-kx022a-spi.c
··· 38 38 static const struct spi_device_id kx022a_id[] = { 39 39 { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, 40 40 { .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info }, 41 + { .name = "kx134-1211", .driver_data = (kernel_ulong_t)&kx134_chip_info }, 41 42 { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info }, 43 + { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info }, 42 44 { } 43 45 }; 44 46 MODULE_DEVICE_TABLE(spi, kx022a_id); ··· 48 46 static const struct of_device_id kx022a_of_match[] = { 49 47 { .compatible = "kionix,kx022a", .data = &kx022a_chip_info }, 50 48 { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info }, 49 + { .compatible = "kionix,kx134-1211", .data = &kx134_chip_info }, 51 50 { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info }, 51 + { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info }, 52 52 { } 53 53 }; 54 54 MODULE_DEVICE_TABLE(of, kx022a_of_match);
+117 -52
drivers/iio/accel/kionix-kx022a.c
··· 5 5 * ROHM/KIONIX accelerometer driver 6 6 */ 7 7 8 + #include <linux/cleanup.h> 8 9 #include <linux/delay.h> 9 10 #include <linux/device.h> 10 11 #include <linux/interrupt.h> ··· 408 407 { 0, 4788403 }, 409 408 }; 410 409 410 + /* KX134ACR-LBZ ranges are (+/-) 8, 16, 32, 64 G */ 411 + static const int kx134acr_lbz_scale_table[][2] = { 412 + { 0, 2394202 }, 413 + { 0, 4788403 }, 414 + { 0, 9576807 }, 415 + { 0, 19153613 }, 416 + }; 417 + 411 418 static int kx022a_read_avail(struct iio_dev *indio_dev, 412 419 struct iio_chan_spec const *chan, 413 420 const int **vals, int *type, int *length, 414 421 long mask) 415 422 { 423 + struct kx022a_data *data = iio_priv(indio_dev); 424 + 416 425 switch (mask) { 417 426 case IIO_CHAN_INFO_SAMP_FREQ: 418 427 *vals = (const int *)kx022a_accel_samp_freq_table; ··· 431 420 *type = IIO_VAL_INT_PLUS_MICRO; 432 421 return IIO_AVAIL_LIST; 433 422 case IIO_CHAN_INFO_SCALE: 434 - *vals = (const int *)kx022a_scale_table; 435 - *length = ARRAY_SIZE(kx022a_scale_table) * 436 - ARRAY_SIZE(kx022a_scale_table[0]); 423 + *vals = (const int *)data->chip_info->scale_table; 424 + *length = data->chip_info->scale_table_size; 437 425 *type = IIO_VAL_INT_PLUS_NANO; 438 426 return IIO_AVAIL_LIST; 439 427 default: ··· 448 438 *val2 = kx022a_accel_samp_freq_table[val & KX022A_MASK_ODR][1]; 449 439 } 450 440 451 - static void kx022a_reg2scale(unsigned int val, unsigned int *val1, 452 - unsigned int *val2) 441 + static void kx022a_reg2scale(struct kx022a_data *data, unsigned int val, 442 + unsigned int *val1, unsigned int *val2) 453 443 { 454 444 val &= KX022A_MASK_GSEL; 455 445 val >>= KX022A_GSEL_SHIFT; 456 446 457 - *val1 = kx022a_scale_table[val][0]; 458 - *val2 = kx022a_scale_table[val][1]; 447 + *val1 = data->chip_info->scale_table[val][0]; 448 + *val2 = data->chip_info->scale_table[val][1]; 459 449 } 460 450 461 - static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on) 451 + static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) 462 452 { 463 453 int ret; 464 454 ··· 479 469 int ret; 480 470 481 471 mutex_lock(&data->mutex); 482 - ret = kx022a_turn_on_off_unlocked(data, false); 472 + ret = __kx022a_turn_on_off(data, false); 483 473 if (ret) 484 474 mutex_unlock(&data->mutex); 485 475 ··· 490 480 { 491 481 int ret; 492 482 493 - ret = kx022a_turn_on_off_unlocked(data, true); 483 + ret = __kx022a_turn_on_off(data, true); 494 484 mutex_unlock(&data->mutex); 495 485 496 486 return ret; ··· 553 543 kx022a_turn_on_unlock(data); 554 544 break; 555 545 case IIO_CHAN_INFO_SCALE: 556 - n = ARRAY_SIZE(kx022a_scale_table); 546 + n = data->chip_info->scale_table_size / 2; 557 547 558 548 while (n-- > 0) 559 - if (val == kx022a_scale_table[n][0] && 560 - val2 == kx022a_scale_table[n][1]) 549 + if (val == data->chip_info->scale_table[n][0] && 550 + val2 == data->chip_info->scale_table[n][1]) 561 551 break; 562 552 if (n < 0) { 563 553 ret = -EINVAL; ··· 652 642 if (ret < 0) 653 643 return ret; 654 644 655 - kx022a_reg2scale(regval, val, val2); 645 + kx022a_reg2scale(data, regval, val, val2); 656 646 657 647 return IIO_VAL_INT_PLUS_NANO; 658 648 } ··· 922 912 { 923 913 int ret = 0; 924 914 925 - ret = kx022a_turn_off_lock(data); 915 + guard(mutex)(&data->mutex); 916 + ret = __kx022a_turn_on_off(data, false); 926 917 if (ret) 927 918 return ret; 928 919 929 920 ret = regmap_clear_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); 930 921 if (ret) 931 - goto unlock_out; 922 + return ret; 932 923 933 924 ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2, 934 925 KX022A_MASK_BUF_EN); 935 926 if (ret) 936 - goto unlock_out; 927 + return ret; 937 928 938 929 data->state &= ~KX022A_STATE_FIFO; 939 930 ··· 942 931 943 932 kfree(data->fifo_buffer); 944 933 945 - return kx022a_turn_on_unlock(data); 946 - 947 - unlock_out: 948 - mutex_unlock(&data->mutex); 949 - 950 - return ret; 934 + return __kx022a_turn_on_off(data, true); 951 935 } 952 936 953 937 static int kx022a_buffer_predisable(struct iio_dev *idev) ··· 965 959 if (!data->fifo_buffer) 966 960 return -ENOMEM; 967 961 968 - ret = kx022a_turn_off_lock(data); 962 + guard(mutex)(&data->mutex); 963 + ret = __kx022a_turn_on_off(data, false); 969 964 if (ret) 970 965 return ret; 971 966 972 967 /* Update watermark to HW */ 973 968 ret = kx022a_fifo_set_wmi(data); 974 969 if (ret) 975 - goto unlock_out; 970 + return ret; 976 971 977 972 /* Enable buffer */ 978 973 ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, 979 974 KX022A_MASK_BUF_EN); 980 975 if (ret) 981 - goto unlock_out; 976 + return ret; 982 977 983 978 data->state |= KX022A_STATE_FIFO; 984 979 ret = regmap_set_bits(data->regmap, data->ien_reg, 985 980 KX022A_MASK_WMI); 986 981 if (ret) 987 - goto unlock_out; 982 + return ret; 988 983 989 - return kx022a_turn_on_unlock(data); 990 - 991 - unlock_out: 992 - mutex_unlock(&data->mutex); 993 - 994 - return ret; 984 + return __kx022a_turn_on_off(data, true); 995 985 } 996 986 997 987 static int kx022a_buffer_postenable(struct iio_dev *idev) ··· 1055 1053 struct kx022a_data *data = iio_priv(idev); 1056 1054 irqreturn_t ret = IRQ_NONE; 1057 1055 1058 - mutex_lock(&data->mutex); 1056 + guard(mutex)(&data->mutex); 1059 1057 1060 1058 if (data->trigger_enabled) { 1061 1059 iio_trigger_poll_nested(data->trig); ··· 1070 1068 ret = IRQ_HANDLED; 1071 1069 } 1072 1070 1073 - mutex_unlock(&data->mutex); 1074 - 1075 1071 return ret; 1076 1072 } 1077 1073 ··· 1079 1079 struct kx022a_data *data = iio_trigger_get_drvdata(trig); 1080 1080 int ret = 0; 1081 1081 1082 - mutex_lock(&data->mutex); 1082 + guard(mutex)(&data->mutex); 1083 1083 1084 1084 if (data->trigger_enabled == state) 1085 - goto unlock_out; 1085 + return 0; 1086 1086 1087 1087 if (data->state & KX022A_STATE_FIFO) { 1088 1088 dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); 1089 - ret = -EBUSY; 1090 - goto unlock_out; 1089 + return -EBUSY; 1091 1090 } 1092 1091 1093 - ret = kx022a_turn_on_off_unlocked(data, false); 1092 + ret = __kx022a_turn_on_off(data, false); 1094 1093 if (ret) 1095 - goto unlock_out; 1094 + return ret; 1096 1095 1097 1096 data->trigger_enabled = state; 1098 1097 ret = kx022a_set_drdy_irq(data, state); 1099 1098 if (ret) 1100 - goto unlock_out; 1099 + return ret; 1101 1100 1102 - ret = kx022a_turn_on_off_unlocked(data, true); 1103 - 1104 - unlock_out: 1105 - mutex_unlock(&data->mutex); 1106 - 1107 - return ret; 1101 + return __kx022a_turn_on_off(data, true); 1108 1102 } 1109 1103 1110 1104 static const struct iio_trigger_ops kx022a_trigger_ops = { ··· 1115 1121 return ret; 1116 1122 1117 1123 /* 1118 - * I've seen I2C read failures if we poll too fast after the sensor 1119 - * reset. Slight delay gives I2C block the time to recover. 1124 + * According to the power-on procedure documents, there is (at least) 1125 + * 2ms delay required after the software reset. This should be same for 1126 + * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-LBZ. 1127 + * 1128 + * https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf 1129 + * https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf 1130 + * https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf 1120 1131 */ 1121 - msleep(1); 1132 + msleep(2); 1122 1133 1123 1134 ret = regmap_read_poll_timeout(data->regmap, data->chip_info->cntl2, val, 1124 1135 !(val & KX022A_MASK_SRST), ··· 1157 1158 .regmap_config = &kx022a_regmap_config, 1158 1159 .channels = kx022a_channels, 1159 1160 .num_channels = ARRAY_SIZE(kx022a_channels), 1161 + .scale_table = kx022a_scale_table, 1162 + .scale_table_size = ARRAY_SIZE(kx022a_scale_table) * 1163 + ARRAY_SIZE(kx022a_scale_table[0]), 1160 1164 .fifo_length = KX022A_FIFO_LENGTH, 1161 1165 .who = KX022A_REG_WHO, 1162 1166 .id = KX022A_ID, ··· 1185 1183 .regmap_config = &kx132_regmap_config, 1186 1184 .channels = kx132_channels, 1187 1185 .num_channels = ARRAY_SIZE(kx132_channels), 1186 + .scale_table = kx022a_scale_table, 1187 + .scale_table_size = ARRAY_SIZE(kx022a_scale_table) * 1188 + ARRAY_SIZE(kx022a_scale_table[0]), 1188 1189 .fifo_length = KX132_FIFO_LENGTH, 1189 1190 .who = KX132_REG_WHO, 1190 1191 .id = KX132_ID, ··· 1209 1204 }; 1210 1205 EXPORT_SYMBOL_NS_GPL(kx132_chip_info, "IIO_KX022A"); 1211 1206 1207 + const struct kx022a_chip_info kx134_chip_info = { 1208 + .name = "kx134-1211", 1209 + .regmap_config = &kx132_regmap_config, 1210 + .channels = kx132_channels, 1211 + .num_channels = ARRAY_SIZE(kx132_channels), 1212 + .scale_table = kx134acr_lbz_scale_table, 1213 + .scale_table_size = ARRAY_SIZE(kx134acr_lbz_scale_table) * 1214 + ARRAY_SIZE(kx134acr_lbz_scale_table[0]), 1215 + .fifo_length = KX132_FIFO_LENGTH, 1216 + .who = KX132_REG_WHO, 1217 + .id = KX134_1211_ID, 1218 + .cntl = KX132_REG_CNTL, 1219 + .cntl2 = KX132_REG_CNTL2, 1220 + .odcntl = KX132_REG_ODCNTL, 1221 + .buf_cntl1 = KX132_REG_BUF_CNTL1, 1222 + .buf_cntl2 = KX132_REG_BUF_CNTL2, 1223 + .buf_clear = KX132_REG_BUF_CLEAR, 1224 + .buf_status1 = KX132_REG_BUF_STATUS_1, 1225 + .buf_smp_lvl_mask = KX132_MASK_BUF_SMP_LVL, 1226 + .buf_read = KX132_REG_BUF_READ, 1227 + .inc1 = KX132_REG_INC1, 1228 + .inc4 = KX132_REG_INC4, 1229 + .inc5 = KX132_REG_INC5, 1230 + .inc6 = KX132_REG_INC6, 1231 + .xout_l = KX132_REG_XOUT_L, 1232 + .get_fifo_bytes_available = kx132_get_fifo_bytes_available, 1233 + }; 1234 + EXPORT_SYMBOL_NS_GPL(kx134_chip_info, "IIO_KX022A"); 1235 + 1212 1236 /* 1213 1237 * Despite the naming, KX132ACR-LBZ is not similar to KX132-1211 but it is 1214 1238 * exact subset of KX022A. KX132ACR-LBZ is meant to be used for industrial ··· 1250 1216 .regmap_config = &kx022a_regmap_config, 1251 1217 .channels = kx022a_channels, 1252 1218 .num_channels = ARRAY_SIZE(kx022a_channels), 1219 + .scale_table = kx022a_scale_table, 1220 + .scale_table_size = ARRAY_SIZE(kx022a_scale_table) * 1221 + ARRAY_SIZE(kx022a_scale_table[0]), 1253 1222 .fifo_length = KX022A_FIFO_LENGTH, 1254 1223 .who = KX022A_REG_WHO, 1255 1224 .id = KX132ACR_LBZ_ID, ··· 1272 1235 .get_fifo_bytes_available = kx022a_get_fifo_bytes_available, 1273 1236 }; 1274 1237 EXPORT_SYMBOL_NS_GPL(kx132acr_chip_info, "IIO_KX022A"); 1238 + 1239 + const struct kx022a_chip_info kx134acr_chip_info = { 1240 + .name = "kx134acr-lbz", 1241 + .regmap_config = &kx022a_regmap_config, 1242 + .channels = kx022a_channels, 1243 + .num_channels = ARRAY_SIZE(kx022a_channels), 1244 + .scale_table = kx134acr_lbz_scale_table, 1245 + .scale_table_size = ARRAY_SIZE(kx134acr_lbz_scale_table) * 1246 + ARRAY_SIZE(kx134acr_lbz_scale_table[0]), 1247 + .fifo_length = KX022A_FIFO_LENGTH, 1248 + .who = KX022A_REG_WHO, 1249 + .id = KX134ACR_LBZ_ID, 1250 + .cntl = KX022A_REG_CNTL, 1251 + .cntl2 = KX022A_REG_CNTL2, 1252 + .odcntl = KX022A_REG_ODCNTL, 1253 + .buf_cntl1 = KX022A_REG_BUF_CNTL1, 1254 + .buf_cntl2 = KX022A_REG_BUF_CNTL2, 1255 + .buf_clear = KX022A_REG_BUF_CLEAR, 1256 + .buf_status1 = KX022A_REG_BUF_STATUS_1, 1257 + .buf_read = KX022A_REG_BUF_READ, 1258 + .inc1 = KX022A_REG_INC1, 1259 + .inc4 = KX022A_REG_INC4, 1260 + .inc5 = KX022A_REG_INC5, 1261 + .inc6 = KX022A_REG_INC6, 1262 + .xout_l = KX022A_REG_XOUT_L, 1263 + .get_fifo_bytes_available = kx022a_get_fifo_bytes_available, 1264 + }; 1265 + EXPORT_SYMBOL_NS_GPL(kx134acr_chip_info, "IIO_KX022A"); 1275 1266 1276 1267 int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info) 1277 1268 {
+14
drivers/iio/accel/kionix-kx022a.h
··· 14 14 #define KX022A_REG_WHO 0x0f 15 15 #define KX022A_ID 0xc8 16 16 #define KX132ACR_LBZ_ID 0xd8 17 + #define KX134ACR_LBZ_ID 0xcc 17 18 18 19 #define KX022A_REG_CNTL2 0x19 19 20 #define KX022A_MASK_SRST BIT(7) ··· 78 77 79 78 #define KX132_REG_WHO 0x13 80 79 #define KX132_ID 0x3d 80 + #define KX134_1211_ID 0x46 81 81 82 82 #define KX132_FIFO_LENGTH 86 83 83 ··· 137 135 * 138 136 * @name: name of the device 139 137 * @regmap_config: pointer to register map configuration 138 + * @scale_table: An array of tables of scaling factors for 139 + * a supported acceleration measurement range. 140 + * Each table containing a single scaling 141 + * factor consisting of two integers. The first 142 + * value in a table is the integer part, and 143 + * the second value is the fractional part as 144 + * parts per billion. 145 + * @scale_table_size: Amount of values in tables. 140 146 * @channels: pointer to iio_chan_spec array 141 147 * @num_channels: number of iio_chan_spec channels 142 148 * @fifo_length: number of 16-bit samples in a full buffer ··· 171 161 struct kx022a_chip_info { 172 162 const char *name; 173 163 const struct regmap_config *regmap_config; 164 + const int (*scale_table)[2]; 165 + const int scale_table_size; 174 166 const struct iio_chan_spec *channels; 175 167 unsigned int num_channels; 176 168 unsigned int fifo_length; ··· 199 187 200 188 extern const struct kx022a_chip_info kx022a_chip_info; 201 189 extern const struct kx022a_chip_info kx132_chip_info; 190 + extern const struct kx022a_chip_info kx134_chip_info; 202 191 extern const struct kx022a_chip_info kx132acr_chip_info; 192 + extern const struct kx022a_chip_info kx134acr_chip_info; 203 193 204 194 #endif
+261 -52
drivers/iio/adc/ad4000.c
··· 35 35 36 36 #define AD4000_SCALE_OPTIONS 2 37 37 38 - #define AD4000_TQUIET1_NS 190 39 - #define AD4000_TQUIET2_NS 60 40 - #define AD4000_TCONV_NS 320 41 - 42 38 #define __AD4000_DIFF_CHANNEL(_sign, _real_bits, _storage_bits, _reg_access) \ 43 39 { \ 44 40 .type = IIO_VOLTAGE, \ ··· 45 49 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 46 50 BIT(IIO_CHAN_INFO_SCALE), \ 47 51 .info_mask_separate_available = _reg_access ? BIT(IIO_CHAN_INFO_SCALE) : 0,\ 52 + .scan_index = 0, \ 48 53 .scan_type = { \ 49 54 .sign = _sign, \ 50 55 .realbits = _real_bits, \ ··· 59 62 __AD4000_DIFF_CHANNEL((_sign), (_real_bits), \ 60 63 ((_real_bits) > 16 ? 32 : 16), (_reg_access)) 61 64 65 + #define AD4000_DIFF_CHANNELS(_sign, _real_bits, _reg_access) \ 66 + { \ 67 + AD4000_DIFF_CHANNEL(_sign, _real_bits, _reg_access), \ 68 + IIO_CHAN_SOFT_TIMESTAMP(1), \ 69 + } 70 + 62 71 #define __AD4000_PSEUDO_DIFF_CHANNEL(_sign, _real_bits, _storage_bits, _reg_access)\ 63 72 { \ 64 73 .type = IIO_VOLTAGE, \ ··· 74 71 BIT(IIO_CHAN_INFO_SCALE) | \ 75 72 BIT(IIO_CHAN_INFO_OFFSET), \ 76 73 .info_mask_separate_available = _reg_access ? BIT(IIO_CHAN_INFO_SCALE) : 0,\ 74 + .scan_index = 0, \ 77 75 .scan_type = { \ 78 76 .sign = _sign, \ 79 77 .realbits = _real_bits, \ ··· 87 83 #define AD4000_PSEUDO_DIFF_CHANNEL(_sign, _real_bits, _reg_access) \ 88 84 __AD4000_PSEUDO_DIFF_CHANNEL((_sign), (_real_bits), \ 89 85 ((_real_bits) > 16 ? 32 : 16), (_reg_access)) 86 + 87 + #define AD4000_PSEUDO_DIFF_CHANNELS(_sign, _real_bits, _reg_access) \ 88 + { \ 89 + AD4000_PSEUDO_DIFF_CHANNEL(_sign, _real_bits, _reg_access), \ 90 + IIO_CHAN_SOFT_TIMESTAMP(1), \ 91 + } 90 92 91 93 static const char * const ad4000_power_supplies[] = { 92 94 "vdd", "vio" ··· 118 108 454, 909, 1000, 1900, 119 109 }; 120 110 111 + struct ad4000_time_spec { 112 + int t_conv_ns; 113 + int t_quiet2_ns; 114 + }; 115 + 116 + /* 117 + * Same timing specifications for all of AD4000, AD4001, ..., AD4008, AD4010, 118 + * ADAQ4001, and ADAQ4003. 119 + */ 120 + static const struct ad4000_time_spec ad4000_t_spec = { 121 + .t_conv_ns = 320, 122 + .t_quiet2_ns = 60, 123 + }; 124 + 125 + /* AD4020, AD4021, AD4022 */ 126 + static const struct ad4000_time_spec ad4020_t_spec = { 127 + .t_conv_ns = 350, 128 + .t_quiet2_ns = 60, 129 + }; 130 + 131 + /* AD7983, AD7984 */ 132 + static const struct ad4000_time_spec ad7983_t_spec = { 133 + .t_conv_ns = 500, 134 + .t_quiet2_ns = 0, 135 + }; 136 + 137 + /* AD7980, AD7982 */ 138 + static const struct ad4000_time_spec ad7980_t_spec = { 139 + .t_conv_ns = 800, 140 + .t_quiet2_ns = 0, 141 + }; 142 + 143 + /* AD7946, AD7686, AD7688, AD7988-5, AD7693 */ 144 + static const struct ad4000_time_spec ad7686_t_spec = { 145 + .t_conv_ns = 1600, 146 + .t_quiet2_ns = 0, 147 + }; 148 + 149 + /* AD7690 */ 150 + static const struct ad4000_time_spec ad7690_t_spec = { 151 + .t_conv_ns = 2100, 152 + .t_quiet2_ns = 0, 153 + }; 154 + 155 + /* AD7942, AD7685, AD7687 */ 156 + static const struct ad4000_time_spec ad7687_t_spec = { 157 + .t_conv_ns = 3200, 158 + .t_quiet2_ns = 0, 159 + }; 160 + 161 + /* AD7691 */ 162 + static const struct ad4000_time_spec ad7691_t_spec = { 163 + .t_conv_ns = 3700, 164 + .t_quiet2_ns = 0, 165 + }; 166 + 167 + /* AD7988-1 */ 168 + static const struct ad4000_time_spec ad7988_1_t_spec = { 169 + .t_conv_ns = 9500, 170 + .t_quiet2_ns = 0, 171 + }; 172 + 121 173 struct ad4000_chip_info { 122 174 const char *dev_name; 123 - struct iio_chan_spec chan_spec; 124 - struct iio_chan_spec reg_access_chan_spec; 175 + struct iio_chan_spec chan_spec[2]; 176 + struct iio_chan_spec reg_access_chan_spec[2]; 177 + const struct ad4000_time_spec *time_spec; 125 178 bool has_hardware_gain; 126 179 }; 127 180 128 181 static const struct ad4000_chip_info ad4000_chip_info = { 129 182 .dev_name = "ad4000", 130 - .chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 16, 0), 131 - .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 16, 1), 183 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 184 + .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 1), 185 + .time_spec = &ad4000_t_spec, 132 186 }; 133 187 134 188 static const struct ad4000_chip_info ad4001_chip_info = { 135 189 .dev_name = "ad4001", 136 - .chan_spec = AD4000_DIFF_CHANNEL('s', 16, 0), 137 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 16, 1), 190 + .chan_spec = AD4000_DIFF_CHANNELS('s', 16, 0), 191 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 16, 1), 192 + .time_spec = &ad4000_t_spec, 138 193 }; 139 194 140 195 static const struct ad4000_chip_info ad4002_chip_info = { 141 196 .dev_name = "ad4002", 142 - .chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 18, 0), 143 - .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 18, 1), 197 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 18, 0), 198 + .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 18, 1), 199 + .time_spec = &ad4000_t_spec, 144 200 }; 145 201 146 202 static const struct ad4000_chip_info ad4003_chip_info = { 147 203 .dev_name = "ad4003", 148 - .chan_spec = AD4000_DIFF_CHANNEL('s', 18, 0), 149 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 18, 1), 204 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 205 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 18, 1), 206 + .time_spec = &ad4000_t_spec, 150 207 }; 151 208 152 209 static const struct ad4000_chip_info ad4004_chip_info = { 153 210 .dev_name = "ad4004", 154 - .chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 16, 0), 155 - .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 16, 1), 211 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 212 + .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 1), 213 + .time_spec = &ad4000_t_spec, 156 214 }; 157 215 158 216 static const struct ad4000_chip_info ad4005_chip_info = { 159 217 .dev_name = "ad4005", 160 - .chan_spec = AD4000_DIFF_CHANNEL('s', 16, 0), 161 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 16, 1), 218 + .chan_spec = AD4000_DIFF_CHANNELS('s', 16, 0), 219 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 16, 1), 220 + .time_spec = &ad4000_t_spec, 162 221 }; 163 222 164 223 static const struct ad4000_chip_info ad4006_chip_info = { 165 224 .dev_name = "ad4006", 166 - .chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 18, 0), 167 - .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 18, 1), 225 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 18, 0), 226 + .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 18, 1), 227 + .time_spec = &ad4000_t_spec, 168 228 }; 169 229 170 230 static const struct ad4000_chip_info ad4007_chip_info = { 171 231 .dev_name = "ad4007", 172 - .chan_spec = AD4000_DIFF_CHANNEL('s', 18, 0), 173 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 18, 1), 232 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 233 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 18, 1), 234 + .time_spec = &ad4000_t_spec, 174 235 }; 175 236 176 237 static const struct ad4000_chip_info ad4008_chip_info = { 177 238 .dev_name = "ad4008", 178 - .chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 16, 0), 179 - .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 16, 1), 239 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 240 + .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 1), 241 + .time_spec = &ad4000_t_spec, 180 242 }; 181 243 182 244 static const struct ad4000_chip_info ad4010_chip_info = { 183 245 .dev_name = "ad4010", 184 - .chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 18, 0), 185 - .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNEL('u', 18, 1), 246 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 18, 0), 247 + .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 18, 1), 248 + .time_spec = &ad4000_t_spec, 186 249 }; 187 250 188 251 static const struct ad4000_chip_info ad4011_chip_info = { 189 252 .dev_name = "ad4011", 190 - .chan_spec = AD4000_DIFF_CHANNEL('s', 18, 0), 191 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 18, 1), 253 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 254 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 18, 1), 255 + .time_spec = &ad4000_t_spec, 192 256 }; 193 257 194 258 static const struct ad4000_chip_info ad4020_chip_info = { 195 259 .dev_name = "ad4020", 196 - .chan_spec = AD4000_DIFF_CHANNEL('s', 20, 0), 197 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 20, 1), 260 + .chan_spec = AD4000_DIFF_CHANNELS('s', 20, 0), 261 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 20, 1), 262 + .time_spec = &ad4020_t_spec, 198 263 }; 199 264 200 265 static const struct ad4000_chip_info ad4021_chip_info = { 201 266 .dev_name = "ad4021", 202 - .chan_spec = AD4000_DIFF_CHANNEL('s', 20, 0), 203 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 20, 1), 267 + .chan_spec = AD4000_DIFF_CHANNELS('s', 20, 0), 268 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 20, 1), 269 + .time_spec = &ad4020_t_spec, 204 270 }; 205 271 206 272 static const struct ad4000_chip_info ad4022_chip_info = { 207 273 .dev_name = "ad4022", 208 - .chan_spec = AD4000_DIFF_CHANNEL('s', 20, 0), 209 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 20, 1), 274 + .chan_spec = AD4000_DIFF_CHANNELS('s', 20, 0), 275 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 20, 1), 276 + .time_spec = &ad4020_t_spec, 210 277 }; 211 278 212 279 static const struct ad4000_chip_info adaq4001_chip_info = { 213 280 .dev_name = "adaq4001", 214 - .chan_spec = AD4000_DIFF_CHANNEL('s', 16, 0), 215 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 16, 1), 281 + .chan_spec = AD4000_DIFF_CHANNELS('s', 16, 0), 282 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 16, 1), 283 + .time_spec = &ad4000_t_spec, 216 284 .has_hardware_gain = true, 217 285 }; 218 286 219 287 static const struct ad4000_chip_info adaq4003_chip_info = { 220 288 .dev_name = "adaq4003", 221 - .chan_spec = AD4000_DIFF_CHANNEL('s', 18, 0), 222 - .reg_access_chan_spec = AD4000_DIFF_CHANNEL('s', 18, 1), 289 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 290 + .reg_access_chan_spec = AD4000_DIFF_CHANNELS('s', 18, 1), 291 + .time_spec = &ad4000_t_spec, 223 292 .has_hardware_gain = true, 293 + }; 294 + 295 + static const struct ad4000_chip_info ad7685_chip_info = { 296 + .dev_name = "ad7685", 297 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 298 + .time_spec = &ad7687_t_spec, 299 + }; 300 + 301 + static const struct ad4000_chip_info ad7686_chip_info = { 302 + .dev_name = "ad7686", 303 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 304 + .time_spec = &ad7686_t_spec, 305 + }; 306 + 307 + static const struct ad4000_chip_info ad7687_chip_info = { 308 + .dev_name = "ad7687", 309 + .chan_spec = AD4000_DIFF_CHANNELS('s', 16, 0), 310 + .time_spec = &ad7687_t_spec, 311 + }; 312 + 313 + static const struct ad4000_chip_info ad7688_chip_info = { 314 + .dev_name = "ad7688", 315 + .chan_spec = AD4000_DIFF_CHANNELS('s', 16, 0), 316 + .time_spec = &ad7686_t_spec, 317 + }; 318 + 319 + static const struct ad4000_chip_info ad7690_chip_info = { 320 + .dev_name = "ad7690", 321 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 322 + .time_spec = &ad7690_t_spec, 323 + }; 324 + 325 + static const struct ad4000_chip_info ad7691_chip_info = { 326 + .dev_name = "ad7691", 327 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 328 + .time_spec = &ad7691_t_spec, 329 + }; 330 + 331 + static const struct ad4000_chip_info ad7693_chip_info = { 332 + .dev_name = "ad7693", 333 + .chan_spec = AD4000_DIFF_CHANNELS('s', 16, 0), 334 + .time_spec = &ad7686_t_spec, 335 + }; 336 + 337 + static const struct ad4000_chip_info ad7942_chip_info = { 338 + .dev_name = "ad7942", 339 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 14, 0), 340 + .time_spec = &ad7687_t_spec, 341 + }; 342 + 343 + static const struct ad4000_chip_info ad7946_chip_info = { 344 + .dev_name = "ad7946", 345 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 14, 0), 346 + .time_spec = &ad7686_t_spec, 347 + }; 348 + 349 + static const struct ad4000_chip_info ad7980_chip_info = { 350 + .dev_name = "ad7980", 351 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 352 + .time_spec = &ad7980_t_spec, 353 + }; 354 + 355 + static const struct ad4000_chip_info ad7982_chip_info = { 356 + .dev_name = "ad7982", 357 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 358 + .time_spec = &ad7980_t_spec, 359 + }; 360 + 361 + static const struct ad4000_chip_info ad7983_chip_info = { 362 + .dev_name = "ad7983", 363 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 364 + .time_spec = &ad7983_t_spec, 365 + }; 366 + 367 + static const struct ad4000_chip_info ad7984_chip_info = { 368 + .dev_name = "ad7984", 369 + .chan_spec = AD4000_DIFF_CHANNELS('s', 18, 0), 370 + .time_spec = &ad7983_t_spec, 371 + }; 372 + 373 + static const struct ad4000_chip_info ad7988_1_chip_info = { 374 + .dev_name = "ad7988-1", 375 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 376 + .time_spec = &ad7988_1_t_spec, 377 + }; 378 + 379 + static const struct ad4000_chip_info ad7988_5_chip_info = { 380 + .dev_name = "ad7988-5", 381 + .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS('u', 16, 0), 382 + .time_spec = &ad7686_t_spec, 224 383 }; 225 384 226 385 struct ad4000_state { ··· 403 224 bool span_comp; 404 225 u16 gain_milli; 405 226 int scale_tbl[AD4000_SCALE_OPTIONS][2]; 227 + const struct ad4000_time_spec *time_spec; 406 228 407 229 /* 408 230 * DMA (thus cache coherency maintenance) requires the transfer buffers ··· 414 234 __be16 sample_buf16; 415 235 __be32 sample_buf32; 416 236 } data; 417 - s64 timestamp __aligned(8); 237 + aligned_s64 timestamp; 418 238 } scan __aligned(IIO_DMA_MINALIGN); 419 239 u8 tx_buf[2]; 420 240 u8 rx_buf[2]; ··· 668 488 static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st, 669 489 const struct iio_chan_spec *chan) 670 490 { 671 - unsigned int cnv_pulse_time = AD4000_TCONV_NS; 672 491 struct spi_transfer *xfers = st->xfers; 673 492 674 493 xfers[0].cs_change = 1; 675 - xfers[0].cs_change_delay.value = cnv_pulse_time; 494 + xfers[0].cs_change_delay.value = st->time_spec->t_conv_ns; 676 495 xfers[0].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS; 677 496 678 497 xfers[1].rx_buf = &st->scan.data; 679 498 xfers[1].len = BITS_TO_BYTES(chan->scan_type.storagebits); 680 - xfers[1].delay.value = AD4000_TQUIET2_NS; 499 + xfers[1].delay.value = st->time_spec->t_quiet2_ns; 681 500 xfers[1].delay.unit = SPI_DELAY_UNIT_NSECS; 682 501 683 502 spi_message_init_with_transfers(&st->msg, st->xfers, 2); ··· 694 515 static int ad4000_prepare_4wire_mode_message(struct ad4000_state *st, 695 516 const struct iio_chan_spec *chan) 696 517 { 697 - unsigned int cnv_to_sdi_time = AD4000_TCONV_NS; 698 518 struct spi_transfer *xfers = st->xfers; 699 519 700 520 /* ··· 701 523 * going low. 702 524 */ 703 525 xfers[0].cs_off = 1; 704 - xfers[0].delay.value = cnv_to_sdi_time; 526 + xfers[0].delay.value = st->time_spec->t_conv_ns; 705 527 xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS; 706 528 707 529 xfers[1].rx_buf = &st->scan.data; ··· 740 562 741 563 st = iio_priv(indio_dev); 742 564 st->spi = spi; 565 + st->time_spec = chip->time_spec; 743 566 744 567 ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(ad4000_power_supplies), 745 568 ad4000_power_supplies); ··· 770 591 switch (st->sdi_pin) { 771 592 case AD4000_SDI_MOSI: 772 593 indio_dev->info = &ad4000_reg_access_info; 773 - indio_dev->channels = &chip->reg_access_chan_spec; 594 + indio_dev->channels = chip->reg_access_chan_spec; 774 595 775 596 /* 776 597 * In "3-wire mode", the ADC SDI line must be kept high when ··· 782 603 if (ret < 0) 783 604 return ret; 784 605 785 - ret = ad4000_prepare_3wire_mode_message(st, indio_dev->channels); 606 + ret = ad4000_prepare_3wire_mode_message(st, &indio_dev->channels[0]); 786 607 if (ret) 787 608 return ret; 788 609 ··· 793 614 break; 794 615 case AD4000_SDI_VIO: 795 616 indio_dev->info = &ad4000_info; 796 - indio_dev->channels = &chip->chan_spec; 797 - ret = ad4000_prepare_3wire_mode_message(st, indio_dev->channels); 617 + indio_dev->channels = chip->chan_spec; 618 + ret = ad4000_prepare_3wire_mode_message(st, &indio_dev->channels[0]); 798 619 if (ret) 799 620 return ret; 800 621 801 622 break; 802 623 case AD4000_SDI_CS: 803 624 indio_dev->info = &ad4000_info; 804 - indio_dev->channels = &chip->chan_spec; 805 - ret = ad4000_prepare_4wire_mode_message(st, indio_dev->channels); 625 + indio_dev->channels = chip->chan_spec; 626 + ret = ad4000_prepare_4wire_mode_message(st, &indio_dev->channels[0]); 806 627 if (ret) 807 628 return ret; 808 629 ··· 816 637 } 817 638 818 639 indio_dev->name = chip->dev_name; 819 - indio_dev->num_channels = 1; 640 + indio_dev->num_channels = 2; 820 641 821 642 ret = devm_mutex_init(dev, &st->lock); 822 643 if (ret) ··· 837 658 } 838 659 } 839 660 840 - ad4000_fill_scale_tbl(st, indio_dev->channels); 661 + ad4000_fill_scale_tbl(st, &indio_dev->channels[0]); 841 662 842 663 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 843 664 &iio_pollfunc_store_time, ··· 865 686 { "ad4022", (kernel_ulong_t)&ad4022_chip_info }, 866 687 { "adaq4001", (kernel_ulong_t)&adaq4001_chip_info }, 867 688 { "adaq4003", (kernel_ulong_t)&adaq4003_chip_info }, 689 + { "ad7685", (kernel_ulong_t)&ad7685_chip_info }, 690 + { "ad7686", (kernel_ulong_t)&ad7686_chip_info }, 691 + { "ad7687", (kernel_ulong_t)&ad7687_chip_info }, 692 + { "ad7688", (kernel_ulong_t)&ad7688_chip_info }, 693 + { "ad7690", (kernel_ulong_t)&ad7690_chip_info }, 694 + { "ad7691", (kernel_ulong_t)&ad7691_chip_info }, 695 + { "ad7693", (kernel_ulong_t)&ad7693_chip_info }, 696 + { "ad7942", (kernel_ulong_t)&ad7942_chip_info }, 697 + { "ad7946", (kernel_ulong_t)&ad7946_chip_info }, 698 + { "ad7980", (kernel_ulong_t)&ad7980_chip_info }, 699 + { "ad7982", (kernel_ulong_t)&ad7982_chip_info }, 700 + { "ad7983", (kernel_ulong_t)&ad7983_chip_info }, 701 + { "ad7984", (kernel_ulong_t)&ad7984_chip_info }, 702 + { "ad7988-1", (kernel_ulong_t)&ad7988_1_chip_info }, 703 + { "ad7988-5", (kernel_ulong_t)&ad7988_5_chip_info }, 868 704 { } 869 705 }; 870 706 MODULE_DEVICE_TABLE(spi, ad4000_id); ··· 901 707 { .compatible = "adi,ad4022", .data = &ad4022_chip_info }, 902 708 { .compatible = "adi,adaq4001", .data = &adaq4001_chip_info }, 903 709 { .compatible = "adi,adaq4003", .data = &adaq4003_chip_info }, 710 + { .compatible = "adi,ad7685", .data = &ad7685_chip_info }, 711 + { .compatible = "adi,ad7686", .data = &ad7686_chip_info }, 712 + { .compatible = "adi,ad7687", .data = &ad7687_chip_info }, 713 + { .compatible = "adi,ad7688", .data = &ad7688_chip_info }, 714 + { .compatible = "adi,ad7690", .data = &ad7690_chip_info }, 715 + { .compatible = "adi,ad7691", .data = &ad7691_chip_info }, 716 + { .compatible = "adi,ad7693", .data = &ad7693_chip_info }, 717 + { .compatible = "adi,ad7942", .data = &ad7942_chip_info }, 718 + { .compatible = "adi,ad7946", .data = &ad7946_chip_info }, 719 + { .compatible = "adi,ad7980", .data = &ad7980_chip_info }, 720 + { .compatible = "adi,ad7982", .data = &ad7982_chip_info }, 721 + { .compatible = "adi,ad7983", .data = &ad7983_chip_info }, 722 + { .compatible = "adi,ad7984", .data = &ad7984_chip_info }, 723 + { .compatible = "adi,ad7988-1", .data = &ad7988_1_chip_info }, 724 + { .compatible = "adi,ad7988-5", .data = &ad7988_5_chip_info }, 904 725 { } 905 726 }; 906 727 MODULE_DEVICE_TABLE(of, ad4000_of_match);
+1 -1
drivers/iio/adc/ad4695.c
··· 30 30 #include <linux/spi/spi.h> 31 31 #include <linux/units.h> 32 32 33 - #include <dt-bindings/iio/adi,ad4695.h> 33 + #include <dt-bindings/iio/adc/adi,ad4695.h> 34 34 35 35 /* AD4695 registers */ 36 36 #define AD4695_REG_SPI_CONFIG_A 0x0000
+160 -57
drivers/iio/adc/ad7124.c
··· 95 95 #define AD7124_MAX_CONFIGS 8 96 96 #define AD7124_MAX_CHANNELS 16 97 97 98 + /* AD7124 input sources */ 99 + #define AD7124_INPUT_TEMPSENSOR 16 100 + #define AD7124_INPUT_AVSS 17 101 + 98 102 enum ad7124_ids { 99 103 ID_AD7124_4, 100 104 ID_AD7124_8, ··· 364 360 return free_cfg_slot; 365 361 } 366 362 363 + /* Only called during probe, so dev_err_probe() can be used */ 367 364 static int ad7124_init_config_vref(struct ad7124_state *st, struct ad7124_channel_config *cfg) 368 365 { 366 + struct device *dev = &st->sd.spi->dev; 369 367 unsigned int refsel = cfg->refsel; 370 368 371 369 switch (refsel) { 372 370 case AD7124_REFIN1: 373 371 case AD7124_REFIN2: 374 372 case AD7124_AVDD_REF: 375 - if (IS_ERR(st->vref[refsel])) { 376 - dev_err(&st->sd.spi->dev, 377 - "Error, trying to use external voltage reference without a %s regulator.\n", 378 - ad7124_ref_names[refsel]); 379 - return PTR_ERR(st->vref[refsel]); 380 - } 373 + if (IS_ERR(st->vref[refsel])) 374 + return dev_err_probe(dev, PTR_ERR(st->vref[refsel]), 375 + "Error, trying to use external voltage reference without a %s regulator.\n", 376 + ad7124_ref_names[refsel]); 377 + 381 378 cfg->vref_mv = regulator_get_voltage(st->vref[refsel]); 382 379 /* Conversion from uV to mV */ 383 380 cfg->vref_mv /= 1000; ··· 389 384 st->adc_control |= AD7124_ADC_CTRL_REF_EN(1); 390 385 return 0; 391 386 default: 392 - dev_err(&st->sd.spi->dev, "Invalid reference %d\n", refsel); 393 - return -EINVAL; 387 + return dev_err_probe(dev, -EINVAL, "Invalid reference %d\n", refsel); 394 388 } 395 389 } 396 390 ··· 575 571 .data_reg = AD7124_DATA, 576 572 .num_slots = 8, 577 573 .irq_flags = IRQF_TRIGGER_FALLING, 574 + .num_resetclks = 64, 578 575 }; 579 576 580 577 static int ad7124_read_raw(struct iio_dev *indio_dev, ··· 593 588 594 589 return IIO_VAL_INT; 595 590 case IIO_CHAN_INFO_SCALE: 596 - mutex_lock(&st->cfgs_lock); 591 + switch (chan->type) { 592 + case IIO_VOLTAGE: 593 + mutex_lock(&st->cfgs_lock); 597 594 598 - idx = st->channels[chan->address].cfg.pga_bits; 599 - *val = st->channels[chan->address].cfg.vref_mv; 600 - if (st->channels[chan->address].cfg.bipolar) 601 - *val2 = chan->scan_type.realbits - 1 + idx; 602 - else 603 - *val2 = chan->scan_type.realbits + idx; 595 + idx = st->channels[chan->address].cfg.pga_bits; 596 + *val = st->channels[chan->address].cfg.vref_mv; 597 + if (st->channels[chan->address].cfg.bipolar) 598 + *val2 = chan->scan_type.realbits - 1 + idx; 599 + else 600 + *val2 = chan->scan_type.realbits + idx; 604 601 605 - mutex_unlock(&st->cfgs_lock); 606 - return IIO_VAL_FRACTIONAL_LOG2; 602 + mutex_unlock(&st->cfgs_lock); 603 + return IIO_VAL_FRACTIONAL_LOG2; 604 + 605 + case IIO_TEMP: 606 + /* 607 + * According to the data sheet 608 + * Temperature (°C) 609 + * = ((Conversion − 0x800000)/13584) − 272.5 610 + * = (Conversion − 0x800000 - 13584 * 272.5) / 13584 611 + * = (Conversion − 12090248) / 13584 612 + * So scale with 1000/13584 to yield °mC. Reduce by 8 to 613 + * 125/1698. 614 + */ 615 + *val = 125; 616 + *val2 = 1698; 617 + return IIO_VAL_FRACTIONAL; 618 + 619 + default: 620 + return -EINVAL; 621 + } 622 + 607 623 case IIO_CHAN_INFO_OFFSET: 608 - mutex_lock(&st->cfgs_lock); 609 - if (st->channels[chan->address].cfg.bipolar) 610 - *val = -(1 << (chan->scan_type.realbits - 1)); 611 - else 612 - *val = 0; 624 + switch (chan->type) { 625 + case IIO_VOLTAGE: 626 + mutex_lock(&st->cfgs_lock); 627 + if (st->channels[chan->address].cfg.bipolar) 628 + *val = -(1 << (chan->scan_type.realbits - 1)); 629 + else 630 + *val = 0; 613 631 614 - mutex_unlock(&st->cfgs_lock); 615 - return IIO_VAL_INT; 632 + mutex_unlock(&st->cfgs_lock); 633 + return IIO_VAL_INT; 634 + 635 + case IIO_TEMP: 636 + /* see calculation above */ 637 + *val = -12090248; 638 + return IIO_VAL_INT; 639 + 640 + default: 641 + return -EINVAL; 642 + } 643 + 616 644 case IIO_CHAN_INFO_SAMP_FREQ: 617 645 mutex_lock(&st->cfgs_lock); 618 646 *val = st->channels[chan->address].cfg.odr; ··· 789 751 .attrs = &ad7124_attrs_group, 790 752 }; 791 753 754 + /* Only called during probe, so dev_err_probe() can be used */ 792 755 static int ad7124_soft_reset(struct ad7124_state *st) 793 756 { 757 + struct device *dev = &st->sd.spi->dev; 794 758 unsigned int readval, timeout; 795 759 int ret; 796 760 797 - ret = ad_sd_reset(&st->sd, 64); 761 + ret = ad_sd_reset(&st->sd); 798 762 if (ret < 0) 799 763 return ret; 800 764 ··· 805 765 do { 806 766 ret = ad_sd_read_reg(&st->sd, AD7124_STATUS, 1, &readval); 807 767 if (ret < 0) 808 - return ret; 768 + return dev_err_probe(dev, ret, "Error reading status register\n"); 809 769 810 770 if (!(readval & AD7124_STATUS_POR_FLAG_MSK)) 811 771 return 0; ··· 814 774 usleep_range(100, 2000); 815 775 } while (--timeout); 816 776 817 - dev_err(&st->sd.spi->dev, "Soft reset failed\n"); 818 - 819 - return -EIO; 777 + return dev_err_probe(dev, -EIO, "Soft reset failed\n"); 820 778 } 821 779 822 780 static int ad7124_check_chip_id(struct ad7124_state *st) 823 781 { 782 + struct device *dev = &st->sd.spi->dev; 824 783 unsigned int readval, chip_id, silicon_rev; 825 784 int ret; 826 785 827 786 ret = ad_sd_read_reg(&st->sd, AD7124_ID, 1, &readval); 828 787 if (ret < 0) 829 - return ret; 788 + return dev_err_probe(dev, ret, "Failure to read ID register\n"); 830 789 831 790 chip_id = AD7124_DEVICE_ID_GET(readval); 832 791 silicon_rev = AD7124_SILICON_REV_GET(readval); 833 792 834 - if (chip_id != st->chip_info->chip_id) { 835 - dev_err(&st->sd.spi->dev, 836 - "Chip ID mismatch: expected %u, got %u\n", 837 - st->chip_info->chip_id, chip_id); 838 - return -ENODEV; 839 - } 793 + if (chip_id != st->chip_info->chip_id) 794 + return dev_err_probe(dev, -ENODEV, 795 + "Chip ID mismatch: expected %u, got %u\n", 796 + st->chip_info->chip_id, chip_id); 840 797 841 - if (silicon_rev == 0) { 842 - dev_err(&st->sd.spi->dev, 843 - "Silicon revision empty. Chip may not be present\n"); 844 - return -ENODEV; 845 - } 798 + if (silicon_rev == 0) 799 + return dev_err_probe(dev, -ENODEV, 800 + "Silicon revision empty. Chip may not be present\n"); 846 801 847 802 return 0; 803 + } 804 + 805 + /* 806 + * Input specifiers 8 - 15 are explicitly reserved for ad7124-4 807 + * while they are fine for ad7124-8. Values above 31 don't fit 808 + * into the register field and so are invalid for sure. 809 + */ 810 + static bool ad7124_valid_input_select(unsigned int ain, const struct ad7124_chip_info *info) 811 + { 812 + if (ain >= info->num_inputs && ain < 16) 813 + return false; 814 + 815 + return ain <= FIELD_MAX(AD7124_CHANNEL_AINM_MSK); 848 816 } 849 817 850 818 static int ad7124_parse_channel_config(struct iio_dev *indio_dev, ··· 863 815 struct ad7124_channel *channels; 864 816 struct iio_chan_spec *chan; 865 817 unsigned int ain[2], channel = 0, tmp; 818 + unsigned int num_channels; 866 819 int ret; 867 820 868 - st->num_channels = device_get_child_node_count(dev); 869 - if (!st->num_channels) 870 - return dev_err_probe(dev, -ENODEV, "no channel children\n"); 821 + num_channels = device_get_child_node_count(dev); 822 + 823 + /* 824 + * The driver assigns each logical channel defined in the device tree 825 + * statically one channel register. So only accept 16 such logical 826 + * channels to not treat CONFIG_0 (i.e. the register following 827 + * CHANNEL_15) as an additional channel register. The driver could be 828 + * improved to lift this limitation. 829 + */ 830 + if (num_channels > AD7124_MAX_CHANNELS) 831 + return dev_err_probe(dev, -EINVAL, "Too many channels defined\n"); 832 + 833 + /* Add one for temperature */ 834 + st->num_channels = min(num_channels + 1, AD7124_MAX_CHANNELS); 871 835 872 836 chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels, 873 837 sizeof(*chan), GFP_KERNEL); ··· 898 838 device_for_each_child_node_scoped(dev, child) { 899 839 ret = fwnode_property_read_u32(child, "reg", &channel); 900 840 if (ret) 901 - return ret; 841 + return dev_err_probe(dev, ret, 842 + "Failed to parse reg property of %pfwP\n", child); 902 843 903 - if (channel >= indio_dev->num_channels) 844 + if (channel >= num_channels) 904 845 return dev_err_probe(dev, -EINVAL, 905 - "Channel index >= number of channels\n"); 846 + "Channel index >= number of channels in %pfwP\n", child); 906 847 907 848 ret = fwnode_property_read_u32_array(child, "diff-channels", 908 849 ain, 2); 909 850 if (ret) 910 - return ret; 851 + return dev_err_probe(dev, ret, 852 + "Failed to parse diff-channels property of %pfwP\n", child); 853 + 854 + if (!ad7124_valid_input_select(ain[0], st->chip_info) || 855 + !ad7124_valid_input_select(ain[1], st->chip_info)) 856 + return dev_err_probe(dev, -EINVAL, 857 + "diff-channels property of %pfwP contains invalid data\n", child); 911 858 912 859 st->channels[channel].nr = channel; 913 860 st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) | ··· 941 874 chan[channel].channel2 = ain[1]; 942 875 } 943 876 877 + if (num_channels < AD7124_MAX_CHANNELS) { 878 + st->channels[num_channels] = (struct ad7124_channel) { 879 + .nr = num_channels, 880 + .ain = AD7124_CHANNEL_AINP(AD7124_INPUT_TEMPSENSOR) | 881 + AD7124_CHANNEL_AINM(AD7124_INPUT_AVSS), 882 + .cfg = { 883 + .bipolar = true, 884 + }, 885 + }; 886 + 887 + chan[num_channels] = (struct iio_chan_spec) { 888 + .type = IIO_TEMP, 889 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 890 + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET) | 891 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 892 + .scan_type = { 893 + /* 894 + * You might find it strange that a bipolar 895 + * measurement yields an unsigned value, but 896 + * this matches the device's manual. 897 + */ 898 + .sign = 'u', 899 + .realbits = 24, 900 + .storagebits = 32, 901 + .endianness = IIO_BE, 902 + }, 903 + .address = num_channels, 904 + .scan_index = num_channels, 905 + }; 906 + } 907 + 944 908 return 0; 945 909 } 946 910 947 911 static int ad7124_setup(struct ad7124_state *st) 948 912 { 913 + struct device *dev = &st->sd.spi->dev; 949 914 unsigned int fclk, power_mode; 950 915 int i, ret; 951 916 952 917 fclk = clk_get_rate(st->mclk); 953 918 if (!fclk) 954 - return -EINVAL; 919 + return dev_err_probe(dev, -EINVAL, "Failed to get mclk rate\n"); 955 920 956 921 /* The power mode changes the master clock frequency */ 957 922 power_mode = ad7124_find_closest_match(ad7124_master_clk_freq_hz, ··· 992 893 if (fclk != ad7124_master_clk_freq_hz[power_mode]) { 993 894 ret = clk_set_rate(st->mclk, fclk); 994 895 if (ret) 995 - return ret; 896 + return dev_err_probe(dev, ret, "Failed to set mclk rate\n"); 996 897 } 997 898 998 899 /* Set the power mode */ ··· 1020 921 1021 922 ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control); 1022 923 if (ret < 0) 1023 - return ret; 924 + return dev_err_probe(dev, ret, "Failed to setup CONTROL register\n"); 1024 925 1025 926 return ret; 1026 927 } ··· 1033 934 static int ad7124_probe(struct spi_device *spi) 1034 935 { 1035 936 const struct ad7124_chip_info *info; 937 + struct device *dev = &spi->dev; 1036 938 struct ad7124_state *st; 1037 939 struct iio_dev *indio_dev; 1038 940 int i, ret; 1039 941 1040 942 info = spi_get_device_match_data(spi); 1041 943 if (!info) 1042 - return -ENODEV; 944 + return dev_err_probe(dev, -ENODEV, "Failed to get match data\n"); 1043 945 1044 946 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 1045 947 if (!indio_dev) ··· 1075 975 1076 976 ret = regulator_enable(st->vref[i]); 1077 977 if (ret) 1078 - return ret; 978 + return dev_err_probe(dev, ret, "Failed to enable regulator #%d\n", i); 1079 979 1080 980 ret = devm_add_action_or_reset(&spi->dev, ad7124_reg_disable, 1081 981 st->vref[i]); 1082 982 if (ret) 1083 - return ret; 983 + return dev_err_probe(dev, ret, "Failed to register disable handler for regulator #%d\n", i); 1084 984 } 1085 985 1086 986 st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); 1087 987 if (IS_ERR(st->mclk)) 1088 - return PTR_ERR(st->mclk); 988 + return dev_err_probe(dev, PTR_ERR(st->mclk), "Failed to get mclk\n"); 1089 989 1090 990 ret = ad7124_soft_reset(st); 1091 991 if (ret < 0) ··· 1101 1001 1102 1002 ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); 1103 1003 if (ret < 0) 1104 - return ret; 1004 + return dev_err_probe(dev, ret, "Failed to setup triggers\n"); 1105 1005 1106 - return devm_iio_device_register(&spi->dev, indio_dev); 1006 + ret = devm_iio_device_register(&spi->dev, indio_dev); 1007 + if (ret < 0) 1008 + return dev_err_probe(dev, ret, "Failed to register iio device\n"); 1107 1009 1010 + return 0; 1108 1011 } 1109 1012 1110 1013 static const struct of_device_id ad7124_of_match[] = {
+117 -2
drivers/iio/adc/ad7173.c
··· 150 150 #define AD7173_FILTER_ODR0_MASK GENMASK(5, 0) 151 151 #define AD7173_MAX_CONFIGS 8 152 152 153 + #define AD7173_MODE_CAL_INT_ZERO 0x4 /* Internal Zero-Scale Calibration */ 154 + #define AD7173_MODE_CAL_INT_FULL 0x5 /* Internal Full-Scale Calibration */ 155 + #define AD7173_MODE_CAL_SYS_ZERO 0x6 /* System Zero-Scale Calibration */ 156 + #define AD7173_MODE_CAL_SYS_FULL 0x7 /* System Full-Scale Calibration */ 157 + 153 158 struct ad7173_device_info { 154 159 const unsigned int *sinc5_data_rates; 155 160 unsigned int num_sinc5_data_rates; ··· 180 175 bool has_input_buf; 181 176 bool has_int_ref; 182 177 bool has_ref2; 178 + bool has_internal_fs_calibration; 183 179 bool higher_gpio_bits; 184 180 u8 num_gpios; 185 181 }; ··· 199 193 }; 200 194 201 195 struct ad7173_channel { 202 - unsigned int chan_reg; 203 196 unsigned int ain; 204 197 struct ad7173_channel_config cfg; 198 + u8 syscalib_mode; 205 199 }; 206 200 207 201 struct ad7173_state { ··· 278 272 .has_input_buf = true, 279 273 .has_current_inputs = true, 280 274 .has_int_ref = true, 275 + .has_internal_fs_calibration = true, 281 276 .clock = 2 * HZ_PER_MHZ, 282 277 .sinc5_data_rates = ad7173_sinc5_data_rates, 283 278 .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), ··· 298 291 .has_input_buf = true, 299 292 .has_current_inputs = true, 300 293 .has_int_ref = true, 294 + .has_internal_fs_calibration = true, 301 295 .clock = 2 * HZ_PER_MHZ, 302 296 .sinc5_data_rates = ad7173_sinc5_data_rates, 303 297 .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), ··· 334 326 .has_temp = true, 335 327 .has_input_buf = true, 336 328 .has_int_ref = true, 329 + .has_internal_fs_calibration = true, 337 330 .clock = 2 * HZ_PER_MHZ, 338 331 .sinc5_data_rates = ad7173_sinc5_data_rates, 339 332 .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), ··· 352 343 .has_temp = true, 353 344 .has_input_buf = true, 354 345 .has_int_ref = true, 346 + .has_internal_fs_calibration = true, 355 347 .clock = 8 * HZ_PER_MHZ, 356 348 .sinc5_data_rates = ad4115_sinc5_data_rates, 357 349 .num_sinc5_data_rates = ARRAY_SIZE(ad4115_sinc5_data_rates), ··· 370 360 .has_temp = true, 371 361 .has_input_buf = true, 372 362 .has_int_ref = true, 363 + .has_internal_fs_calibration = true, 373 364 .clock = 4 * HZ_PER_MHZ, 374 365 .sinc5_data_rates = ad4116_sinc5_data_rates, 375 366 .num_sinc5_data_rates = ARRAY_SIZE(ad4116_sinc5_data_rates), ··· 515 504 .wr_table = &ad7173_access_table, 516 505 .read_flag_mask = BIT(6), 517 506 }; 507 + 508 + enum { 509 + AD7173_SYSCALIB_ZERO_SCALE, 510 + AD7173_SYSCALIB_FULL_SCALE, 511 + }; 512 + 513 + static const char * const ad7173_syscalib_modes[] = { 514 + [AD7173_SYSCALIB_ZERO_SCALE] = "zero_scale", 515 + [AD7173_SYSCALIB_FULL_SCALE] = "full_scale", 516 + }; 517 + 518 + static int ad7173_set_syscalib_mode(struct iio_dev *indio_dev, 519 + const struct iio_chan_spec *chan, 520 + unsigned int mode) 521 + { 522 + struct ad7173_state *st = iio_priv(indio_dev); 523 + 524 + st->channels[chan->channel].syscalib_mode = mode; 525 + 526 + return 0; 527 + } 528 + 529 + static int ad7173_get_syscalib_mode(struct iio_dev *indio_dev, 530 + const struct iio_chan_spec *chan) 531 + { 532 + struct ad7173_state *st = iio_priv(indio_dev); 533 + 534 + return st->channels[chan->channel].syscalib_mode; 535 + } 536 + 537 + static ssize_t ad7173_write_syscalib(struct iio_dev *indio_dev, 538 + uintptr_t private, 539 + const struct iio_chan_spec *chan, 540 + const char *buf, size_t len) 541 + { 542 + struct ad7173_state *st = iio_priv(indio_dev); 543 + bool sys_calib; 544 + int ret, mode; 545 + 546 + ret = kstrtobool(buf, &sys_calib); 547 + if (ret) 548 + return ret; 549 + 550 + mode = st->channels[chan->channel].syscalib_mode; 551 + if (sys_calib) { 552 + if (mode == AD7173_SYSCALIB_ZERO_SCALE) 553 + ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_SYS_ZERO, 554 + chan->address); 555 + else 556 + ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_SYS_FULL, 557 + chan->address); 558 + } 559 + 560 + return ret ? : len; 561 + } 562 + 563 + static const struct iio_enum ad7173_syscalib_mode_enum = { 564 + .items = ad7173_syscalib_modes, 565 + .num_items = ARRAY_SIZE(ad7173_syscalib_modes), 566 + .set = ad7173_set_syscalib_mode, 567 + .get = ad7173_get_syscalib_mode 568 + }; 569 + 570 + static const struct iio_chan_spec_ext_info ad7173_calibsys_ext_info[] = { 571 + { 572 + .name = "sys_calibration", 573 + .write = ad7173_write_syscalib, 574 + .shared = IIO_SEPARATE, 575 + }, 576 + IIO_ENUM("sys_calibration_mode", IIO_SEPARATE, 577 + &ad7173_syscalib_mode_enum), 578 + IIO_ENUM_AVAILABLE("sys_calibration_mode", IIO_SHARED_BY_TYPE, 579 + &ad7173_syscalib_mode_enum), 580 + { } 581 + }; 582 + 583 + static int ad7173_calibrate_all(struct ad7173_state *st, struct iio_dev *indio_dev) 584 + { 585 + int ret; 586 + int i; 587 + 588 + for (i = 0; i < st->num_channels; i++) { 589 + if (indio_dev->channels[i].type != IIO_VOLTAGE) 590 + continue; 591 + 592 + ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, st->channels[i].ain); 593 + if (ret < 0) 594 + return ret; 595 + 596 + if (st->info->has_internal_fs_calibration) { 597 + ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_FULL, 598 + st->channels[i].ain); 599 + if (ret < 0) 600 + return ret; 601 + } 602 + } 603 + 604 + return 0; 605 + } 518 606 519 607 static int ad7173_mask_xlate(struct gpio_regmap *gpio, unsigned int base, 520 608 unsigned int offset, unsigned int *reg, ··· 874 764 .read_mask = BIT(6), 875 765 .status_ch_mask = GENMASK(3, 0), 876 766 .data_reg = AD7173_REG_DATA, 767 + .num_resetclks = 64, 877 768 }; 878 769 879 770 static int ad7173_setup(struct iio_dev *indio_dev) ··· 911 800 sizeof(*st->config_cnts), GFP_KERNEL); 912 801 if (!st->config_cnts) 913 802 return -ENOMEM; 803 + 804 + ret = ad7173_calibrate_all(st, indio_dev); 805 + if (ret) 806 + return ret; 914 807 915 808 /* All channels are enabled by default after a reset */ 916 809 return ad7173_disable_all(&st->sd); ··· 1138 1023 .storagebits = 32, 1139 1024 .endianness = IIO_BE, 1140 1025 }, 1026 + .ext_info = ad7173_calibsys_ext_info, 1141 1027 }; 1142 1028 1143 1029 static const struct iio_chan_spec ad7173_temp_iio_channel_template = { ··· 1432 1316 chan->address = chan_index; 1433 1317 chan->scan_index = chan_index; 1434 1318 chan->channel = ain[0]; 1435 - chan_st_priv->chan_reg = chan_index; 1436 1319 chan_st_priv->cfg.input_buf = st->info->has_input_buf; 1437 1320 chan_st_priv->cfg.odr = 0; 1438 1321
+3 -1
drivers/iio/adc/ad7192.c
··· 361 361 .status_ch_mask = GENMASK(3, 0), 362 362 .num_slots = 4, 363 363 .irq_flags = IRQF_TRIGGER_FALLING, 364 + .num_resetclks = 40, 364 365 }; 365 366 366 367 static const struct ad_sigma_delta_info ad7194_sigma_delta_info = { ··· 374 373 .read_mask = BIT(6), 375 374 .status_ch_mask = GENMASK(3, 0), 376 375 .irq_flags = IRQF_TRIGGER_FALLING, 376 + .num_resetclks = 40, 377 377 }; 378 378 379 379 static const struct ad_sd_calib_data ad7192_calib_arr[8] = { ··· 567 565 int i, ret, id; 568 566 569 567 /* reset the serial interface */ 570 - ret = ad_sd_reset(&st->sd, 48); 568 + ret = ad_sd_reset(&st->sd); 571 569 if (ret < 0) 572 570 return ret; 573 571 usleep_range(500, 1000); /* Wait for at least 500us */
+4 -4
drivers/iio/adc/ad7625.c
··· 477 477 ref_clk = devm_clk_get_enabled(dev, NULL); 478 478 if (IS_ERR(ref_clk)) 479 479 return dev_err_probe(dev, PTR_ERR(ref_clk), 480 - "failed to get ref_clk"); 480 + "failed to get ref_clk\n"); 481 481 482 482 ref_clk_rate_hz = clk_get_rate(ref_clk); 483 483 if (!ref_clk_rate_hz) 484 484 return dev_err_probe(dev, -EINVAL, 485 - "failed to get ref_clk rate"); 485 + "failed to get ref_clk rate\n"); 486 486 487 487 st->ref_clk_rate_hz = ref_clk_rate_hz; 488 488 ··· 533 533 534 534 if (!st->info->has_internal_vref && !st->have_refin && !ref_mv) 535 535 return dev_err_probe(dev, -EINVAL, 536 - "Need either REFIN or REF"); 536 + "Need either REFIN or REF\n"); 537 537 538 538 if (st->have_refin && ref_mv) 539 539 return dev_err_probe(dev, -EINVAL, ··· 623 623 st->back = devm_iio_backend_get(dev, NULL); 624 624 if (IS_ERR(st->back)) 625 625 return dev_err_probe(dev, PTR_ERR(st->back), 626 - "failed to get IIO backend"); 626 + "failed to get IIO backend\n"); 627 627 628 628 ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); 629 629 if (ret)
+1
drivers/iio/adc/ad7791.c
··· 254 254 .addr_shift = 4, 255 255 .read_mask = BIT(3), 256 256 .irq_flags = IRQF_TRIGGER_FALLING, 257 + .num_resetclks = 32, 257 258 }; 258 259 259 260 static int ad7791_read_raw(struct iio_dev *indio_dev,
+2 -1
drivers/iio/adc/ad7793.c
··· 206 206 .addr_shift = 3, 207 207 .read_mask = BIT(6), 208 208 .irq_flags = IRQF_TRIGGER_FALLING, 209 + .num_resetclks = 32, 209 210 }; 210 211 211 212 static const struct ad_sd_calib_data ad7793_calib_arr[6] = { ··· 266 265 return ret; 267 266 268 267 /* reset the serial interface */ 269 - ret = ad_sd_reset(&st->sd, 32); 268 + ret = ad_sd_reset(&st->sd); 270 269 if (ret < 0) 271 270 goto out; 272 271 usleep_range(500, 2000); /* Wait for at least 500us */
+1 -1
drivers/iio/adc/ad7944.c
··· 75 75 u16 u16; 76 76 u32 u32; 77 77 } raw; 78 - u64 timestamp __aligned(8); 78 + aligned_s64 timestamp; 79 79 } sample __aligned(IIO_DMA_MINALIGN); 80 80 }; 81 81
+166 -28
drivers/iio/adc/ad_sigma_delta.c
··· 29 29 #define AD_SD_COMM_CHAN_MASK 0x3 30 30 31 31 #define AD_SD_REG_COMM 0x00 32 + #define AD_SD_REG_STATUS 0x00 32 33 #define AD_SD_REG_DATA 0x03 34 + 35 + #define AD_SD_REG_STATUS_RDY 0x80 33 36 34 37 /** 35 38 * ad_sd_set_comm() - Set communications register ··· 112 109 }, { 113 110 .rx_buf = val, 114 111 .len = size, 115 - .cs_change = sigma_delta->bus_locked, 112 + .cs_change = sigma_delta->keep_cs_asserted, 116 113 }, 117 114 }; 118 115 struct spi_message m; ··· 181 178 * ad_sd_reset() - Reset the serial interface 182 179 * 183 180 * @sigma_delta: The sigma delta device 184 - * @reset_length: Number of SCLKs with DIN = 1 185 181 * 186 182 * Returns 0 on success, an error code otherwise. 187 183 **/ 188 - int ad_sd_reset(struct ad_sigma_delta *sigma_delta, 189 - unsigned int reset_length) 184 + int ad_sd_reset(struct ad_sigma_delta *sigma_delta) 190 185 { 186 + unsigned int reset_length = sigma_delta->info->num_resetclks; 191 187 uint8_t *buf; 192 188 unsigned int size; 193 189 int ret; ··· 204 202 } 205 203 EXPORT_SYMBOL_NS_GPL(ad_sd_reset, "IIO_AD_SIGMA_DELTA"); 206 204 205 + static bool ad_sd_disable_irq(struct ad_sigma_delta *sigma_delta) 206 + { 207 + guard(spinlock_irqsave)(&sigma_delta->irq_lock); 208 + 209 + /* It's already off, return false to indicate nothing was changed */ 210 + if (sigma_delta->irq_dis) 211 + return false; 212 + 213 + sigma_delta->irq_dis = true; 214 + disable_irq_nosync(sigma_delta->irq_line); 215 + return true; 216 + } 217 + 218 + static void ad_sd_enable_irq(struct ad_sigma_delta *sigma_delta) 219 + { 220 + guard(spinlock_irqsave)(&sigma_delta->irq_lock); 221 + 222 + sigma_delta->irq_dis = false; 223 + enable_irq(sigma_delta->irq_line); 224 + } 225 + 226 + #define AD_SD_CLEAR_DATA_BUFLEN 9 227 + 228 + /* Called with `sigma_delta->bus_locked == true` only. */ 229 + static int ad_sigma_delta_clear_pending_event(struct ad_sigma_delta *sigma_delta) 230 + { 231 + bool pending_event; 232 + unsigned int data_read_len = BITS_TO_BYTES(sigma_delta->info->num_resetclks); 233 + u8 *data; 234 + struct spi_transfer t[] = { 235 + { 236 + .len = 1, 237 + }, { 238 + .len = data_read_len, 239 + } 240 + }; 241 + struct spi_message m; 242 + int ret; 243 + 244 + /* 245 + * Read R̅D̅Y̅ pin (if possible) or status register to check if there is an 246 + * old event. 247 + */ 248 + if (sigma_delta->rdy_gpiod) { 249 + pending_event = gpiod_get_value(sigma_delta->rdy_gpiod); 250 + } else { 251 + unsigned int status_reg; 252 + 253 + ret = ad_sd_read_reg(sigma_delta, AD_SD_REG_STATUS, 1, &status_reg); 254 + if (ret) 255 + return ret; 256 + 257 + pending_event = !(status_reg & AD_SD_REG_STATUS_RDY); 258 + } 259 + 260 + if (!pending_event) 261 + return 0; 262 + 263 + /* 264 + * In general the size of the data register is unknown. It varies from 265 + * device to device, might be one byte longer if CONTROL.DATA_STATUS is 266 + * set and even varies on some devices depending on which input is 267 + * selected. So send one byte to start reading the data register and 268 + * then just clock for some bytes with DIN (aka MOSI) high to not 269 + * confuse the register access state machine after the data register was 270 + * completely read. Note however that the sequence length must be 271 + * shorter than the reset procedure. 272 + */ 273 + 274 + data = kzalloc(data_read_len + 1, GFP_KERNEL); 275 + if (!data) 276 + return -ENOMEM; 277 + 278 + spi_message_init(&m); 279 + if (sigma_delta->info->has_registers) { 280 + unsigned int data_reg = sigma_delta->info->data_reg ?: AD_SD_REG_DATA; 281 + 282 + data[0] = data_reg << sigma_delta->info->addr_shift; 283 + data[0] |= sigma_delta->info->read_mask; 284 + data[0] |= sigma_delta->comm; 285 + t[0].tx_buf = data; 286 + spi_message_add_tail(&t[0], &m); 287 + } 288 + 289 + /* 290 + * The first transferred byte is part of the real data register, 291 + * so this doesn't need to be 0xff. In the remaining 292 + * `data_read_len - 1` bytes are less than $num_resetclks ones. 293 + */ 294 + t[1].tx_buf = data + 1; 295 + data[1] = 0x00; 296 + memset(data + 2, 0xff, data_read_len - 1); 297 + spi_message_add_tail(&t[1], &m); 298 + 299 + ret = spi_sync_locked(sigma_delta->spi, &m); 300 + 301 + kfree(data); 302 + 303 + return ret; 304 + } 305 + 207 306 int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta, 208 307 unsigned int mode, unsigned int channel) 209 308 { ··· 320 217 sigma_delta->keep_cs_asserted = true; 321 218 reinit_completion(&sigma_delta->completion); 322 219 220 + ret = ad_sigma_delta_clear_pending_event(sigma_delta); 221 + if (ret) 222 + goto out; 223 + 323 224 ret = ad_sigma_delta_set_mode(sigma_delta, mode); 324 225 if (ret < 0) 325 226 goto out; 326 227 327 - sigma_delta->irq_dis = false; 328 - enable_irq(sigma_delta->irq_line); 228 + ad_sd_enable_irq(sigma_delta); 329 229 time_left = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ); 330 230 if (time_left == 0) { 331 - sigma_delta->irq_dis = true; 332 - disable_irq_nosync(sigma_delta->irq_line); 231 + ad_sd_disable_irq(sigma_delta); 333 232 ret = -EIO; 334 233 } else { 335 234 ret = 0; ··· 397 292 sigma_delta->keep_cs_asserted = true; 398 293 reinit_completion(&sigma_delta->completion); 399 294 295 + ret = ad_sigma_delta_clear_pending_event(sigma_delta); 296 + if (ret) 297 + goto out_unlock; 298 + 400 299 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_SINGLE); 401 300 402 - sigma_delta->irq_dis = false; 403 - enable_irq(sigma_delta->irq_line); 301 + ad_sd_enable_irq(sigma_delta); 404 302 ret = wait_for_completion_interruptible_timeout( 405 303 &sigma_delta->completion, HZ); 406 304 ··· 422 314 &raw_sample); 423 315 424 316 out: 425 - if (!sigma_delta->irq_dis) { 426 - disable_irq_nosync(sigma_delta->irq_line); 427 - sigma_delta->irq_dis = true; 428 - } 317 + ad_sd_disable_irq(sigma_delta); 429 318 430 - sigma_delta->keep_cs_asserted = false; 431 319 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE); 432 320 ad_sigma_delta_disable_one(sigma_delta, chan->address); 321 + 322 + out_unlock: 323 + sigma_delta->keep_cs_asserted = false; 433 324 sigma_delta->bus_locked = false; 434 325 spi_bus_unlock(sigma_delta->spi->controller); 435 326 iio_device_release_direct_mode(indio_dev); ··· 499 392 sigma_delta->bus_locked = true; 500 393 sigma_delta->keep_cs_asserted = true; 501 394 395 + ret = ad_sigma_delta_clear_pending_event(sigma_delta); 396 + if (ret) 397 + goto err_unlock; 398 + 502 399 ret = ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_CONTINUOUS); 503 400 if (ret) 504 401 goto err_unlock; 505 402 506 - sigma_delta->irq_dis = false; 507 - enable_irq(sigma_delta->irq_line); 403 + ad_sd_enable_irq(sigma_delta); 508 404 509 405 return 0; 510 406 ··· 524 414 reinit_completion(&sigma_delta->completion); 525 415 wait_for_completion_timeout(&sigma_delta->completion, HZ); 526 416 527 - if (!sigma_delta->irq_dis) { 528 - disable_irq_nosync(sigma_delta->irq_line); 529 - sigma_delta->irq_dis = true; 530 - } 417 + ad_sd_disable_irq(sigma_delta); 531 418 532 419 sigma_delta->keep_cs_asserted = false; 533 420 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE); ··· 623 516 624 517 irq_handled: 625 518 iio_trigger_notify_done(indio_dev->trig); 626 - sigma_delta->irq_dis = false; 627 - enable_irq(sigma_delta->irq_line); 519 + ad_sd_enable_irq(sigma_delta); 628 520 629 521 return IRQ_HANDLED; 630 522 } ··· 645 539 { 646 540 struct ad_sigma_delta *sigma_delta = private; 647 541 648 - complete(&sigma_delta->completion); 649 - disable_irq_nosync(irq); 650 - sigma_delta->irq_dis = true; 651 - iio_trigger_poll(sigma_delta->trig); 542 + /* 543 + * AD7124 and a few others use the same physical line for interrupt 544 + * reporting (R̅D̅Y̅) and MISO. 545 + * As MISO toggles when reading a register, this likely results in a 546 + * pending interrupt. This has two consequences: a) The irq might 547 + * trigger immediately after it's enabled even though the conversion 548 + * isn't done yet; and b) checking the STATUS register's R̅D̅Y̅ flag is 549 + * off-limits as reading that would trigger another irq event. 550 + * 551 + * So read the MOSI line as GPIO (if available) and only trigger the irq 552 + * if the line is active. Without such a GPIO assume this is a valid 553 + * interrupt. 554 + * 555 + * Also as disable_irq_nosync() is used to disable the irq, only act if 556 + * the irq wasn't disabled before. 557 + */ 558 + if ((!sigma_delta->rdy_gpiod || gpiod_get_value(sigma_delta->rdy_gpiod)) && 559 + ad_sd_disable_irq(sigma_delta)) { 560 + complete(&sigma_delta->completion); 561 + iio_trigger_poll(sigma_delta->trig); 652 562 653 - return IRQ_HANDLED; 563 + return IRQ_HANDLED; 564 + } 565 + 566 + return IRQ_NONE; 654 567 } 655 568 656 569 /** ··· 799 674 } 800 675 } 801 676 677 + spin_lock_init(&sigma_delta->irq_lock); 678 + 802 679 if (info->irq_line) 803 680 sigma_delta->irq_line = info->irq_line; 804 681 else 805 682 sigma_delta->irq_line = spi->irq; 683 + 684 + sigma_delta->rdy_gpiod = devm_gpiod_get_optional(&spi->dev, "rdy", GPIOD_IN); 685 + if (IS_ERR(sigma_delta->rdy_gpiod)) 686 + return dev_err_probe(&spi->dev, PTR_ERR(sigma_delta->rdy_gpiod), 687 + "Failed to find rdy gpio\n"); 688 + 689 + if (sigma_delta->rdy_gpiod && !sigma_delta->irq_line) { 690 + sigma_delta->irq_line = gpiod_to_irq(sigma_delta->rdy_gpiod); 691 + if (sigma_delta->irq_line < 0) 692 + return sigma_delta->irq_line; 693 + } 806 694 807 695 iio_device_set_drvdata(indio_dev, sigma_delta); 808 696
+2 -19
drivers/iio/adc/dln2-adc.c
··· 66 66 /* Demux table */ 67 67 unsigned int demux_count; 68 68 struct dln2_adc_demux_table demux[DLN2_ADC_MAX_CHANNELS]; 69 - /* Precomputed timestamp padding offset and length */ 70 - unsigned int ts_pad_offset, ts_pad_length; 71 69 }; 72 70 73 71 struct dln2_adc_port_chan { ··· 109 111 if (iio_get_masklength(indio_dev) && 110 112 (*indio_dev->active_scan_mask & 0xff) == 0xff) { 111 113 dln2_adc_add_demux(dln2, 0, 0, 16); 112 - dln2->ts_pad_offset = 0; 113 - dln2->ts_pad_length = 0; 114 114 return; 115 115 } 116 116 ··· 122 126 dln2_adc_add_demux(dln2, in_loc, out_loc, 2); 123 127 out_loc += 2; 124 128 in_loc += 2; 125 - } 126 - 127 - if (indio_dev->scan_timestamp) { 128 - size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1; 129 - 130 - dln2->ts_pad_offset = out_loc; 131 - dln2->ts_pad_length = ts_offset * sizeof(int64_t) - out_loc; 132 - } else { 133 - dln2->ts_pad_offset = 0; 134 - dln2->ts_pad_length = 0; 135 129 } 136 130 } 137 131 ··· 480 494 if (ret < 0) 481 495 goto done; 482 496 497 + memset(&data, 0, sizeof(data)); 498 + 483 499 /* Demux operation */ 484 500 for (i = 0; i < dln2->demux_count; ++i) { 485 501 t = &dln2->demux[i]; 486 502 memcpy((void *)data.values + t->to, 487 503 (void *)dev_data.values + t->from, t->length); 488 504 } 489 - 490 - /* Zero padding space between values and timestamp */ 491 - if (dln2->ts_pad_length) 492 - memset((void *)data.values + dln2->ts_pad_offset, 493 - 0, dln2->ts_pad_length); 494 505 495 506 iio_push_to_buffers_with_timestamp(indio_dev, &data, 496 507 iio_get_time_ns(indio_dev));
+1 -1
drivers/iio/adc/ina2xx-adc.c
··· 150 150 /* data buffer needs space for channel data and timestamp */ 151 151 struct { 152 152 u16 chan[4]; 153 - u64 ts __aligned(8); 153 + aligned_s64 ts; 154 154 } scan; 155 155 }; 156 156
+1 -1
drivers/iio/adc/max1118.c
··· 39 39 /* Ensure natural alignment of buffer elements */ 40 40 struct { 41 41 u8 channels[2]; 42 - s64 ts __aligned(8); 42 + aligned_s64 ts; 43 43 } scan; 44 44 45 45 u8 data __aligned(IIO_DMA_MINALIGN);
+1 -1
drivers/iio/adc/max11410.c
··· 143 143 int irq; 144 144 struct { 145 145 u32 data __aligned(IIO_DMA_MINALIGN); 146 - s64 ts __aligned(8); 146 + aligned_s64 ts; 147 147 } scan; 148 148 }; 149 149
+9 -21
drivers/iio/adc/max1363.c
··· 161 161 * @vref_uv: Actual (external or internal) reference voltage 162 162 * @send: function used to send data to the chip 163 163 * @recv: function used to receive data from the chip 164 + * @data: buffer to store channel data and timestamp 164 165 */ 165 166 struct max1363_state { 166 167 struct i2c_client *client; ··· 187 186 const char *buf, int count); 188 187 int (*recv)(const struct i2c_client *client, 189 188 char *buf, int count); 189 + struct { 190 + u8 buf[MAX1363_MAX_CHANNELS * 2]; 191 + aligned_s64 ts; 192 + } data; 190 193 }; 191 194 192 195 #define MAX1363_MODE_SINGLE(_num, _mask) { \ ··· 1467 1462 struct iio_poll_func *pf = p; 1468 1463 struct iio_dev *indio_dev = pf->indio_dev; 1469 1464 struct max1363_state *st = iio_priv(indio_dev); 1470 - __u8 *rxbuf; 1471 1465 int b_sent; 1472 - size_t d_size; 1473 1466 unsigned long numvals = bitmap_weight(st->current_mode->modemask, 1474 1467 MAX1363_MAX_CHANNELS); 1475 1468 1476 - /* Ensure the timestamp is 8 byte aligned */ 1477 - if (st->chip_info->bits != 8) 1478 - d_size = numvals*2; 1479 - else 1480 - d_size = numvals; 1481 - if (indio_dev->scan_timestamp) { 1482 - d_size += sizeof(s64); 1483 - if (d_size % sizeof(s64)) 1484 - d_size += sizeof(s64) - (d_size % sizeof(s64)); 1485 - } 1486 1469 /* Monitor mode prevents reading. Whilst not currently implemented 1487 1470 * might as well have this test in here in the meantime as it does 1488 1471 * no harm. ··· 1478 1485 if (numvals == 0) 1479 1486 goto done; 1480 1487 1481 - rxbuf = kmalloc(d_size, GFP_KERNEL); 1482 - if (rxbuf == NULL) 1483 - goto done; 1484 1488 if (st->chip_info->bits != 8) 1485 - b_sent = st->recv(st->client, rxbuf, numvals * 2); 1489 + b_sent = st->recv(st->client, st->data.buf, numvals * 2); 1486 1490 else 1487 - b_sent = st->recv(st->client, rxbuf, numvals); 1491 + b_sent = st->recv(st->client, st->data.buf, numvals); 1488 1492 if (b_sent < 0) 1489 - goto done_free; 1493 + goto done; 1490 1494 1491 - iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, 1495 + iio_push_to_buffers_with_timestamp(indio_dev, &st->data, 1492 1496 iio_get_time_ns(indio_dev)); 1493 1497 1494 - done_free: 1495 - kfree(rxbuf); 1496 1498 done: 1497 1499 iio_trigger_notify_done(indio_dev->trig); 1498 1500
+1 -1
drivers/iio/adc/mcp3911.c
··· 122 122 const struct mcp3911_chip_info *chip; 123 123 struct { 124 124 u32 channels[MCP39XX_MAX_NUM_CHANNELS]; 125 - s64 ts __aligned(8); 125 + aligned_s64 ts; 126 126 } scan; 127 127 128 128 u8 tx_buf __aligned(IIO_DMA_MINALIGN);
+17 -30
drivers/iio/adc/meson_saradc.c
··· 155 155 */ 156 156 #define MESON_SAR_ADC_REG11 0x2c 157 157 #define MESON_SAR_ADC_REG11_BANDGAP_EN BIT(13) 158 - #define MESON_SAR_ADC_REG11_CMV_SEL BIT(6) 159 - #define MESON_SAR_ADC_REG11_VREF_VOLTAGE BIT(5) 160 - #define MESON_SAR_ADC_REG11_EOC BIT(1) 161 - #define MESON_SAR_ADC_REG11_VREF_SEL BIT(0) 158 + #define MESON_SAR_ADC_REG11_CMV_SEL BIT(6) 159 + #define MESON_SAR_ADC_REG11_VREF_VOLTAGE BIT(5) 160 + #define MESON_SAR_ADC_REG11_EOC BIT(1) 161 + #define MESON_SAR_ADC_REG11_VREF_SEL BIT(0) 162 162 163 163 #define MESON_SAR_ADC_REG13 0x34 164 164 #define MESON_SAR_ADC_REG13_12BIT_CALIBRATION_MASK GENMASK(13, 8) ··· 315 315 struct meson_sar_adc_param { 316 316 bool has_bl30_integration; 317 317 unsigned long clock_rate; 318 - u32 bandgap_reg; 319 318 unsigned int resolution; 320 319 const struct regmap_config *regmap_config; 321 320 u8 temperature_trimming_bits; 322 321 unsigned int temperature_multiplier; 323 322 unsigned int temperature_divider; 324 323 u8 disable_ring_counter; 325 - bool has_reg11; 326 324 bool has_vref_select; 327 325 u8 vref_select; 328 326 u8 cmv_select; 329 327 u8 adc_eoc; 330 - enum meson_sar_adc_vref_sel vref_volatge; 328 + enum meson_sar_adc_vref_sel vref_voltage; 331 329 }; 332 330 333 331 struct meson_sar_adc_data { ··· 974 976 MESON_SAR_ADC_REG3_CTRL_CONT_RING_COUNTER_EN, 975 977 regval); 976 978 977 - if (priv->param->has_reg11) { 979 + if (priv->param->regmap_config->max_register >= MESON_SAR_ADC_REG11) { 978 980 regval = FIELD_PREP(MESON_SAR_ADC_REG11_EOC, priv->param->adc_eoc); 979 981 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11, 980 982 MESON_SAR_ADC_REG11_EOC, regval); ··· 987 989 } 988 990 989 991 regval = FIELD_PREP(MESON_SAR_ADC_REG11_VREF_VOLTAGE, 990 - priv->param->vref_volatge); 992 + priv->param->vref_voltage); 991 993 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11, 992 994 MESON_SAR_ADC_REG11_VREF_VOLTAGE, regval); 993 995 ··· 1011 1013 static void meson_sar_adc_set_bandgap(struct iio_dev *indio_dev, bool on_off) 1012 1014 { 1013 1015 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 1014 - const struct meson_sar_adc_param *param = priv->param; 1015 - u32 enable_mask; 1016 1016 1017 - if (param->bandgap_reg == MESON_SAR_ADC_REG11) 1018 - enable_mask = MESON_SAR_ADC_REG11_BANDGAP_EN; 1017 + if (priv->param->regmap_config->max_register >= MESON_SAR_ADC_REG11) 1018 + regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11, 1019 + MESON_SAR_ADC_REG11_BANDGAP_EN, 1020 + on_off ? MESON_SAR_ADC_REG11_BANDGAP_EN : 0); 1019 1021 else 1020 - enable_mask = MESON_SAR_ADC_DELTA_10_TS_VBG_EN; 1021 - 1022 - regmap_update_bits(priv->regmap, param->bandgap_reg, enable_mask, 1023 - on_off ? enable_mask : 0); 1022 + regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELTA_10, 1023 + MESON_SAR_ADC_DELTA_10_TS_VBG_EN, 1024 + on_off ? MESON_SAR_ADC_DELTA_10_TS_VBG_EN : 0); 1024 1025 } 1025 1026 1026 1027 static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev) ··· 1183 1186 static const struct meson_sar_adc_param meson_sar_adc_meson8_param = { 1184 1187 .has_bl30_integration = false, 1185 1188 .clock_rate = 1150000, 1186 - .bandgap_reg = MESON_SAR_ADC_DELTA_10, 1187 1189 .regmap_config = &meson_sar_adc_regmap_config_meson8, 1188 1190 .resolution = 10, 1189 1191 .temperature_trimming_bits = 4, ··· 1193 1197 static const struct meson_sar_adc_param meson_sar_adc_meson8b_param = { 1194 1198 .has_bl30_integration = false, 1195 1199 .clock_rate = 1150000, 1196 - .bandgap_reg = MESON_SAR_ADC_DELTA_10, 1197 1200 .regmap_config = &meson_sar_adc_regmap_config_meson8, 1198 1201 .resolution = 10, 1199 1202 .temperature_trimming_bits = 5, ··· 1203 1208 static const struct meson_sar_adc_param meson_sar_adc_gxbb_param = { 1204 1209 .has_bl30_integration = true, 1205 1210 .clock_rate = 1200000, 1206 - .bandgap_reg = MESON_SAR_ADC_REG11, 1207 1211 .regmap_config = &meson_sar_adc_regmap_config_gxbb, 1208 1212 .resolution = 10, 1209 - .has_reg11 = true, 1210 - .vref_volatge = 1, 1213 + .vref_voltage = 1, 1211 1214 .cmv_select = 1, 1212 1215 }; 1213 1216 1214 1217 static const struct meson_sar_adc_param meson_sar_adc_gxl_param = { 1215 1218 .has_bl30_integration = true, 1216 1219 .clock_rate = 1200000, 1217 - .bandgap_reg = MESON_SAR_ADC_REG11, 1218 1220 .regmap_config = &meson_sar_adc_regmap_config_gxbb, 1219 1221 .resolution = 12, 1220 1222 .disable_ring_counter = 1, 1221 - .has_reg11 = true, 1222 - .vref_volatge = 1, 1223 + .vref_voltage = 1, 1223 1224 .cmv_select = 1, 1224 1225 }; 1225 1226 1226 1227 static const struct meson_sar_adc_param meson_sar_adc_axg_param = { 1227 1228 .has_bl30_integration = true, 1228 1229 .clock_rate = 1200000, 1229 - .bandgap_reg = MESON_SAR_ADC_REG11, 1230 1230 .regmap_config = &meson_sar_adc_regmap_config_gxbb, 1231 1231 .resolution = 12, 1232 1232 .disable_ring_counter = 1, 1233 - .has_reg11 = true, 1234 - .vref_volatge = 1, 1233 + .vref_voltage = 1, 1235 1234 .has_vref_select = true, 1236 1235 .vref_select = VREF_VDDA, 1237 1236 .cmv_select = 1, ··· 1234 1245 static const struct meson_sar_adc_param meson_sar_adc_g12a_param = { 1235 1246 .has_bl30_integration = false, 1236 1247 .clock_rate = 1200000, 1237 - .bandgap_reg = MESON_SAR_ADC_REG11, 1238 1248 .regmap_config = &meson_sar_adc_regmap_config_gxbb, 1239 1249 .resolution = 12, 1240 1250 .disable_ring_counter = 1, 1241 - .has_reg11 = true, 1242 1251 .adc_eoc = 1, 1243 1252 .has_vref_select = true, 1244 1253 .vref_select = VREF_VDDA,
+88 -7
drivers/iio/adc/pac1921.c
··· 12 12 #include <linux/iio/iio.h> 13 13 #include <linux/iio/trigger_consumer.h> 14 14 #include <linux/iio/triggered_buffer.h> 15 + #include <linux/limits.h> 15 16 #include <linux/regmap.h> 16 17 #include <linux/units.h> 17 18 ··· 67 66 #define PAC1921_DEFAULT_DV_GAIN 0 /* 2^(value): 1x gain (HW default) */ 68 67 #define PAC1921_DEFAULT_DI_GAIN 0 /* 2^(value): 1x gain (HW default) */ 69 68 #define PAC1921_DEFAULT_NUM_SAMPLES 0 /* 2^(value): 1 sample (HW default) */ 69 + 70 + #define PAC1921_ACPI_GET_uOHMS_VALS 0 71 + #define PAC1921_ACPI_GET_LABEL 1 72 + 73 + /* f7bb9932-86ee-4516-a236-7a7a742e55cb */ 74 + static const guid_t pac1921_guid = 75 + GUID_INIT(0xf7bb9932, 0x86ee, 0x4516, 0xa2, 76 + 0x36, 0x7a, 0x7a, 0x74, 0x2e, 0x55, 0xcb); 70 77 71 78 /* 72 79 * Pre-computed scale factors for BUS voltage ··· 209 200 210 201 struct { 211 202 u16 chan[PAC1921_NUM_MEAS_CHANS]; 212 - s64 timestamp __aligned(8); 203 + aligned_s64 timestamp; 213 204 } scan; 214 205 }; 215 206 ··· 791 782 const char *buf, size_t len) 792 783 { 793 784 struct pac1921_priv *priv = iio_priv(indio_dev); 794 - u64 rshunt_uohm; 785 + u32 rshunt_uohm; 795 786 int val, val_fract; 796 787 int ret; 797 788 ··· 802 793 if (ret) 803 794 return ret; 804 795 805 - rshunt_uohm = val * MICRO + val_fract; 806 - if (rshunt_uohm == 0 || rshunt_uohm > INT_MAX) 796 + /* 797 + * This check validates the shunt is not zero and does not surpass 798 + * INT_MAX. The check is done before calculating in order to avoid 799 + * val * MICRO overflowing. 800 + */ 801 + if ((!val && !val_fract) || val > INT_MAX / MICRO || 802 + (val == INT_MAX / MICRO && val_fract > INT_MAX % MICRO)) 807 803 return -EINVAL; 804 + 805 + rshunt_uohm = val * MICRO + val_fract; 808 806 809 807 guard(mutex)(&priv->lock); 810 808 ··· 1167 1151 regulator_disable(regulator); 1168 1152 } 1169 1153 1154 + /* 1155 + * Documentation related to the ACPI device definition 1156 + * https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ApplicationNotes/ApplicationNotes/PAC193X-Integration-Notes-for-Microsoft-Windows-10-and-Windows-11-Driver-Support-DS00002534.pdf 1157 + */ 1158 + static int pac1921_match_acpi_device(struct iio_dev *indio_dev) 1159 + { 1160 + acpi_handle handle; 1161 + union acpi_object *status; 1162 + char *label; 1163 + struct pac1921_priv *priv = iio_priv(indio_dev); 1164 + struct device *dev = &priv->client->dev; 1165 + 1166 + handle = ACPI_HANDLE(dev); 1167 + 1168 + status = acpi_evaluate_dsm(handle, &pac1921_guid, 1, 1169 + PAC1921_ACPI_GET_uOHMS_VALS, NULL); 1170 + if (!status) 1171 + return dev_err_probe(dev, -EINVAL, 1172 + "Could not read shunt from ACPI table\n"); 1173 + 1174 + priv->rshunt_uohm = status->package.elements[0].integer.value; 1175 + ACPI_FREE(status); 1176 + 1177 + status = acpi_evaluate_dsm(handle, &pac1921_guid, 1, 1178 + PAC1921_ACPI_GET_LABEL, NULL); 1179 + if (!status) 1180 + return dev_err_probe(dev, -EINVAL, 1181 + "Could not read label from ACPI table\n"); 1182 + 1183 + label = devm_kstrdup(dev, status->package.elements[0].string.pointer, 1184 + GFP_KERNEL); 1185 + if (!label) 1186 + return -ENOMEM; 1187 + 1188 + indio_dev->label = label; 1189 + ACPI_FREE(status); 1190 + 1191 + return 0; 1192 + } 1193 + 1194 + static int pac1921_parse_of_fw(struct iio_dev *indio_dev) 1195 + { 1196 + int ret; 1197 + struct pac1921_priv *priv = iio_priv(indio_dev); 1198 + struct device *dev = &priv->client->dev; 1199 + 1200 + ret = device_property_read_u32(dev, "shunt-resistor-micro-ohms", 1201 + &priv->rshunt_uohm); 1202 + if (ret) 1203 + return dev_err_probe(dev, ret, 1204 + "Cannot read shunt resistor property\n"); 1205 + 1206 + return 0; 1207 + } 1208 + 1170 1209 static int pac1921_probe(struct i2c_client *client) 1171 1210 { 1172 1211 struct device *dev = &client->dev; ··· 1250 1179 priv->di_gain = PAC1921_DEFAULT_DI_GAIN; 1251 1180 priv->n_samples = PAC1921_DEFAULT_NUM_SAMPLES; 1252 1181 1253 - ret = device_property_read_u32(dev, "shunt-resistor-micro-ohms", 1254 - &priv->rshunt_uohm); 1182 + if (is_acpi_device_node(dev->fwnode)) 1183 + ret = pac1921_match_acpi_device(indio_dev); 1184 + else 1185 + ret = pac1921_parse_of_fw(indio_dev); 1255 1186 if (ret) 1256 1187 return dev_err_probe(dev, ret, 1257 - "Cannot read shunt resistor property\n"); 1188 + "Parameter parsing error\n"); 1189 + 1258 1190 if (priv->rshunt_uohm == 0 || priv->rshunt_uohm > INT_MAX) 1259 1191 return dev_err_probe(dev, -EINVAL, 1260 1192 "Invalid shunt resistor: %u\n", ··· 1320 1246 }; 1321 1247 MODULE_DEVICE_TABLE(of, pac1921_of_match); 1322 1248 1249 + static const struct acpi_device_id pac1921_acpi_match[] = { 1250 + { "MCHP1921" }, 1251 + { } 1252 + }; 1253 + MODULE_DEVICE_TABLE(acpi, pac1921_acpi_match); 1254 + 1323 1255 static struct i2c_driver pac1921_driver = { 1324 1256 .driver = { 1325 1257 .name = "pac1921", 1326 1258 .pm = pm_sleep_ptr(&pac1921_pm_ops), 1327 1259 .of_match_table = pac1921_of_match, 1260 + .acpi_match_table = pac1921_acpi_match, 1328 1261 }, 1329 1262 .probe = pac1921_probe, 1330 1263 .id_table = pac1921_id,
+1 -1
drivers/iio/adc/rockchip_saradc.c
··· 363 363 */ 364 364 struct { 365 365 u16 values[SARADC_MAX_CHANNELS]; 366 - int64_t timestamp; 366 + aligned_s64 timestamp; 367 367 } data; 368 368 int ret; 369 369 int i, j = 0;
+1 -1
drivers/iio/adc/rtq6056.c
··· 634 634 struct device *dev = priv->dev; 635 635 struct { 636 636 u16 vals[RTQ6056_MAX_CHANNEL]; 637 - s64 timestamp __aligned(8); 637 + aligned_s64 timestamp; 638 638 } data; 639 639 unsigned int raw; 640 640 int i = 0, bit, ret;
+235 -204
drivers/iio/adc/rzg2l_adc.c
··· 8 8 */ 9 9 10 10 #include <linux/bitfield.h> 11 - #include <linux/clk.h> 11 + #include <linux/cleanup.h> 12 12 #include <linux/completion.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/iio/iio.h> 15 15 #include <linux/interrupt.h> 16 16 #include <linux/io.h> 17 + #include <linux/iopoll.h> 17 18 #include <linux/mod_devicetable.h> 18 19 #include <linux/module.h> 19 20 #include <linux/platform_device.h> ··· 33 32 #define RZG2L_ADM1_MS BIT(2) 34 33 #define RZG2L_ADM1_BS BIT(4) 35 34 #define RZG2L_ADM1_EGA_MASK GENMASK(13, 12) 36 - #define RZG2L_ADM2_CHSEL_MASK GENMASK(7, 0) 37 35 #define RZG2L_ADM3_ADIL_MASK GENMASK(31, 24) 38 36 #define RZG2L_ADM3_ADCMP_MASK GENMASK(23, 16) 39 - #define RZG2L_ADM3_ADCMP_E FIELD_PREP(RZG2L_ADM3_ADCMP_MASK, 0xe) 40 - #define RZG2L_ADM3_ADSMP_MASK GENMASK(15, 0) 41 37 42 38 #define RZG2L_ADINT 0x20 43 - #define RZG2L_ADINT_INTEN_MASK GENMASK(7, 0) 44 39 #define RZG2L_ADINT_CSEEN BIT(16) 45 40 #define RZG2L_ADINT_INTS BIT(31) 46 41 47 42 #define RZG2L_ADSTS 0x24 48 43 #define RZG2L_ADSTS_CSEST BIT(16) 49 - #define RZG2L_ADSTS_INTST_MASK GENMASK(7, 0) 50 44 51 45 #define RZG2L_ADIVC 0x28 52 46 #define RZG2L_ADIVC_DIVADC_MASK GENMASK(8, 0) ··· 52 56 #define RZG2L_ADCR(n) (0x30 + ((n) * 0x4)) 53 57 #define RZG2L_ADCR_AD_MASK GENMASK(11, 0) 54 58 55 - #define RZG2L_ADSMP_DEFAULT_SAMPLING 0x578 56 - 57 - #define RZG2L_ADC_MAX_CHANNELS 8 58 - #define RZG2L_ADC_CHN_MASK 0x7 59 + #define RZG2L_ADC_MAX_CHANNELS 9 59 60 #define RZG2L_ADC_TIMEOUT usecs_to_jiffies(1 * 4) 61 + 62 + /** 63 + * struct rzg2l_adc_hw_params - ADC hardware specific parameters 64 + * @default_adsmp: default ADC sampling period (see ADM3 register); index 0 is 65 + * used for voltage channels, index 1 is used for temperature channel 66 + * @adsmp_mask: ADC sampling period mask (see ADM3 register) 67 + * @adint_inten_mask: conversion end interrupt mask (see ADINT register) 68 + * @default_adcmp: default ADC cmp (see ADM3 register) 69 + * @num_channels: number of supported channels 70 + * @adivc: specifies if ADVIC register is available 71 + */ 72 + struct rzg2l_adc_hw_params { 73 + u16 default_adsmp[2]; 74 + u16 adsmp_mask; 75 + u16 adint_inten_mask; 76 + u8 default_adcmp; 77 + u8 num_channels; 78 + bool adivc; 79 + }; 60 80 61 81 struct rzg2l_adc_data { 62 82 const struct iio_chan_spec *channels; ··· 81 69 82 70 struct rzg2l_adc { 83 71 void __iomem *base; 84 - struct clk *pclk; 85 - struct clk *adclk; 86 72 struct reset_control *presetn; 87 73 struct reset_control *adrstn; 88 - struct completion completion; 89 74 const struct rzg2l_adc_data *data; 75 + const struct rzg2l_adc_hw_params *hw_params; 76 + struct completion completion; 90 77 struct mutex lock; 91 78 u16 last_val[RZG2L_ADC_MAX_CHANNELS]; 79 + bool was_rpm_active; 92 80 }; 93 81 94 - static const char * const rzg2l_adc_channel_name[] = { 95 - "adc0", 96 - "adc1", 97 - "adc2", 98 - "adc3", 99 - "adc4", 100 - "adc5", 101 - "adc6", 102 - "adc7", 82 + /** 83 + * struct rzg2l_adc_channel - ADC channel descriptor 84 + * @name: ADC channel name 85 + * @type: ADC channel type 86 + */ 87 + struct rzg2l_adc_channel { 88 + const char * const name; 89 + enum iio_chan_type type; 90 + }; 91 + 92 + static const struct rzg2l_adc_channel rzg2l_adc_channels[] = { 93 + { "adc0", IIO_VOLTAGE }, 94 + { "adc1", IIO_VOLTAGE }, 95 + { "adc2", IIO_VOLTAGE }, 96 + { "adc3", IIO_VOLTAGE }, 97 + { "adc4", IIO_VOLTAGE }, 98 + { "adc5", IIO_VOLTAGE }, 99 + { "adc6", IIO_VOLTAGE }, 100 + { "adc7", IIO_VOLTAGE }, 101 + { "adc8", IIO_TEMP }, 103 102 }; 104 103 105 104 static unsigned int rzg2l_adc_readl(struct rzg2l_adc *adc, u32 reg) ··· 138 115 139 116 static void rzg2l_adc_start_stop(struct rzg2l_adc *adc, bool start) 140 117 { 141 - int timeout = 5; 118 + int ret; 142 119 u32 reg; 143 120 144 121 reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); ··· 151 128 if (start) 152 129 return; 153 130 154 - do { 155 - usleep_range(100, 200); 156 - reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); 157 - timeout--; 158 - if (!timeout) { 159 - pr_err("%s stopping ADC timed out\n", __func__); 160 - break; 161 - } 162 - } while (((reg & RZG2L_ADM0_ADBSY) || (reg & RZG2L_ADM0_ADCE))); 131 + ret = read_poll_timeout(rzg2l_adc_readl, reg, !(reg & (RZG2L_ADM0_ADBSY | RZG2L_ADM0_ADCE)), 132 + 200, 1000, true, adc, RZG2L_ADM(0)); 133 + if (ret) 134 + pr_err("%s stopping ADC timed out\n", __func__); 163 135 } 164 136 165 137 static void rzg2l_set_trigger(struct rzg2l_adc *adc) ··· 176 158 rzg2l_adc_writel(adc, RZG2L_ADM(1), reg); 177 159 } 178 160 161 + static u8 rzg2l_adc_ch_to_adsmp_index(u8 ch) 162 + { 163 + if (rzg2l_adc_channels[ch].type == IIO_VOLTAGE) 164 + return 0; 165 + 166 + return 1; 167 + } 168 + 179 169 static int rzg2l_adc_conversion_setup(struct rzg2l_adc *adc, u8 ch) 180 170 { 171 + const struct rzg2l_adc_hw_params *hw_params = adc->hw_params; 172 + u8 index = rzg2l_adc_ch_to_adsmp_index(ch); 181 173 u32 reg; 182 174 183 175 if (rzg2l_adc_readl(adc, RZG2L_ADM(0)) & RZG2L_ADM0_ADBSY) ··· 197 169 198 170 /* Select analog input channel subjected to conversion. */ 199 171 reg = rzg2l_adc_readl(adc, RZG2L_ADM(2)); 200 - reg &= ~RZG2L_ADM2_CHSEL_MASK; 172 + reg &= ~GENMASK(hw_params->num_channels - 1, 0); 201 173 reg |= BIT(ch); 202 174 rzg2l_adc_writel(adc, RZG2L_ADM(2), reg); 175 + 176 + reg = rzg2l_adc_readl(adc, RZG2L_ADM(3)); 177 + reg &= ~hw_params->adsmp_mask; 178 + reg |= hw_params->default_adsmp[index]; 179 + rzg2l_adc_writel(adc, RZG2L_ADM(3), reg); 203 180 204 181 /* 205 182 * Setup ADINT ··· 214 181 */ 215 182 reg = rzg2l_adc_readl(adc, RZG2L_ADINT); 216 183 reg &= ~RZG2L_ADINT_INTS; 217 - reg &= ~RZG2L_ADINT_INTEN_MASK; 184 + reg &= ~hw_params->adint_inten_mask; 218 185 reg |= (RZG2L_ADINT_CSEEN | BIT(ch)); 219 186 rzg2l_adc_writel(adc, RZG2L_ADINT, reg); 220 187 221 188 return 0; 222 189 } 223 190 224 - static int rzg2l_adc_set_power(struct iio_dev *indio_dev, bool on) 225 - { 226 - struct device *dev = indio_dev->dev.parent; 227 - 228 - if (on) 229 - return pm_runtime_resume_and_get(dev); 230 - 231 - return pm_runtime_put_sync(dev); 232 - } 233 - 234 191 static int rzg2l_adc_conversion(struct iio_dev *indio_dev, struct rzg2l_adc *adc, u8 ch) 235 192 { 193 + const struct rzg2l_adc_hw_params *hw_params = adc->hw_params; 194 + struct device *dev = indio_dev->dev.parent; 236 195 int ret; 237 196 238 - ret = rzg2l_adc_set_power(indio_dev, true); 197 + ret = pm_runtime_resume_and_get(dev); 239 198 if (ret) 240 199 return ret; 241 200 242 201 ret = rzg2l_adc_conversion_setup(adc, ch); 243 - if (ret) { 244 - rzg2l_adc_set_power(indio_dev, false); 245 - return ret; 246 - } 202 + if (ret) 203 + goto rpm_put; 247 204 248 205 reinit_completion(&adc->completion); 249 206 ··· 241 218 242 219 if (!wait_for_completion_timeout(&adc->completion, RZG2L_ADC_TIMEOUT)) { 243 220 rzg2l_adc_writel(adc, RZG2L_ADINT, 244 - rzg2l_adc_readl(adc, RZG2L_ADINT) & ~RZG2L_ADINT_INTEN_MASK); 245 - rzg2l_adc_start_stop(adc, false); 246 - rzg2l_adc_set_power(indio_dev, false); 247 - return -ETIMEDOUT; 221 + rzg2l_adc_readl(adc, RZG2L_ADINT) & ~hw_params->adint_inten_mask); 222 + ret = -ETIMEDOUT; 248 223 } 249 224 250 - return rzg2l_adc_set_power(indio_dev, false); 225 + rzg2l_adc_start_stop(adc, false); 226 + 227 + rpm_put: 228 + pm_runtime_mark_last_busy(dev); 229 + pm_runtime_put_autosuspend(dev); 230 + return ret; 251 231 } 252 232 253 233 static int rzg2l_adc_read_raw(struct iio_dev *indio_dev, ··· 259 233 { 260 234 struct rzg2l_adc *adc = iio_priv(indio_dev); 261 235 int ret; 262 - u8 ch; 263 236 264 237 switch (mask) { 265 - case IIO_CHAN_INFO_RAW: 266 - if (chan->type != IIO_VOLTAGE) 238 + case IIO_CHAN_INFO_RAW: { 239 + if (chan->type != IIO_VOLTAGE && chan->type != IIO_TEMP) 267 240 return -EINVAL; 268 241 269 - mutex_lock(&adc->lock); 270 - ch = chan->channel & RZG2L_ADC_CHN_MASK; 271 - ret = rzg2l_adc_conversion(indio_dev, adc, ch); 272 - if (ret) { 273 - mutex_unlock(&adc->lock); 242 + guard(mutex)(&adc->lock); 243 + 244 + ret = rzg2l_adc_conversion(indio_dev, adc, chan->channel); 245 + if (ret) 274 246 return ret; 275 - } 276 - *val = adc->last_val[ch]; 277 - mutex_unlock(&adc->lock); 247 + 248 + *val = adc->last_val[chan->channel]; 278 249 279 250 return IIO_VAL_INT; 251 + } 280 252 281 253 default: 282 254 return -EINVAL; ··· 285 261 const struct iio_chan_spec *chan, 286 262 char *label) 287 263 { 288 - return sysfs_emit(label, "%s\n", rzg2l_adc_channel_name[chan->channel]); 264 + return sysfs_emit(label, "%s\n", rzg2l_adc_channels[chan->channel].name); 289 265 } 290 266 291 267 static const struct iio_info rzg2l_adc_iio_info = { ··· 296 272 static irqreturn_t rzg2l_adc_isr(int irq, void *dev_id) 297 273 { 298 274 struct rzg2l_adc *adc = dev_id; 275 + const struct rzg2l_adc_hw_params *hw_params = adc->hw_params; 299 276 unsigned long intst; 300 277 u32 reg; 301 278 int ch; ··· 309 284 return IRQ_HANDLED; 310 285 } 311 286 312 - intst = reg & RZG2L_ADSTS_INTST_MASK; 287 + intst = reg & GENMASK(hw_params->num_channels - 1, 0); 313 288 if (!intst) 314 289 return IRQ_NONE; 315 290 316 - for_each_set_bit(ch, &intst, RZG2L_ADC_MAX_CHANNELS) 291 + for_each_set_bit(ch, &intst, hw_params->num_channels) 317 292 adc->last_val[ch] = rzg2l_adc_readl(adc, RZG2L_ADCR(ch)) & RZG2L_ADCR_AD_MASK; 318 293 319 294 /* clear the channel interrupt */ ··· 326 301 327 302 static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l_adc *adc) 328 303 { 304 + const struct rzg2l_adc_hw_params *hw_params = adc->hw_params; 329 305 struct iio_chan_spec *chan_array; 330 306 struct rzg2l_adc_data *data; 331 307 unsigned int channel; ··· 339 313 return -ENOMEM; 340 314 341 315 num_channels = device_get_child_node_count(&pdev->dev); 342 - if (!num_channels) { 343 - dev_err(&pdev->dev, "no channel children\n"); 344 - return -ENODEV; 345 - } 316 + if (!num_channels) 317 + return dev_err_probe(&pdev->dev, -ENODEV, "no channel children\n"); 346 318 347 - if (num_channels > RZG2L_ADC_MAX_CHANNELS) { 348 - dev_err(&pdev->dev, "num of channel children out of range\n"); 349 - return -EINVAL; 350 - } 319 + if (num_channels > hw_params->num_channels) 320 + return dev_err_probe(&pdev->dev, -EINVAL, 321 + "num of channel children out of range\n"); 351 322 352 323 chan_array = devm_kcalloc(&pdev->dev, num_channels, sizeof(*chan_array), 353 324 GFP_KERNEL); ··· 357 334 if (ret) 358 335 return ret; 359 336 360 - if (channel >= RZG2L_ADC_MAX_CHANNELS) 337 + if (channel >= hw_params->num_channels) 361 338 return -EINVAL; 362 339 363 - chan_array[i].type = IIO_VOLTAGE; 340 + chan_array[i].type = rzg2l_adc_channels[channel].type; 364 341 chan_array[i].indexed = 1; 365 342 chan_array[i].channel = channel; 366 343 chan_array[i].info_mask_separate = BIT(IIO_CHAN_INFO_RAW); 367 - chan_array[i].datasheet_name = rzg2l_adc_channel_name[channel]; 344 + chan_array[i].datasheet_name = rzg2l_adc_channels[channel].name; 368 345 i++; 369 346 } 370 347 ··· 375 352 return 0; 376 353 } 377 354 378 - static int rzg2l_adc_hw_init(struct rzg2l_adc *adc) 355 + static int rzg2l_adc_hw_init(struct device *dev, struct rzg2l_adc *adc) 379 356 { 380 - int timeout = 5; 357 + const struct rzg2l_adc_hw_params *hw_params = adc->hw_params; 381 358 u32 reg; 382 359 int ret; 383 360 384 - ret = clk_prepare_enable(adc->pclk); 361 + ret = pm_runtime_resume_and_get(dev); 385 362 if (ret) 386 363 return ret; 387 364 ··· 390 367 reg |= RZG2L_ADM0_SRESB; 391 368 rzg2l_adc_writel(adc, RZG2L_ADM(0), reg); 392 369 393 - while (!(rzg2l_adc_readl(adc, RZG2L_ADM(0)) & RZG2L_ADM0_SRESB)) { 394 - if (!timeout) { 395 - ret = -EBUSY; 396 - goto exit_hw_init; 397 - } 398 - timeout--; 399 - usleep_range(100, 200); 400 - } 370 + ret = read_poll_timeout(rzg2l_adc_readl, reg, reg & RZG2L_ADM0_SRESB, 371 + 200, 1000, false, adc, RZG2L_ADM(0)); 372 + if (ret) 373 + goto exit_hw_init; 401 374 402 - /* Only division by 4 can be set */ 403 - reg = rzg2l_adc_readl(adc, RZG2L_ADIVC); 404 - reg &= ~RZG2L_ADIVC_DIVADC_MASK; 405 - reg |= RZG2L_ADIVC_DIVADC_4; 406 - rzg2l_adc_writel(adc, RZG2L_ADIVC, reg); 375 + if (hw_params->adivc) { 376 + /* Only division by 4 can be set */ 377 + reg = rzg2l_adc_readl(adc, RZG2L_ADIVC); 378 + reg &= ~RZG2L_ADIVC_DIVADC_MASK; 379 + reg |= RZG2L_ADIVC_DIVADC_4; 380 + rzg2l_adc_writel(adc, RZG2L_ADIVC, reg); 381 + } 407 382 408 383 /* 409 384 * Setup AMD3 ··· 412 391 reg = rzg2l_adc_readl(adc, RZG2L_ADM(3)); 413 392 reg &= ~RZG2L_ADM3_ADIL_MASK; 414 393 reg &= ~RZG2L_ADM3_ADCMP_MASK; 415 - reg &= ~RZG2L_ADM3_ADSMP_MASK; 416 - reg |= (RZG2L_ADM3_ADCMP_E | RZG2L_ADSMP_DEFAULT_SAMPLING); 394 + reg &= ~hw_params->adsmp_mask; 395 + reg |= FIELD_PREP(RZG2L_ADM3_ADCMP_MASK, hw_params->default_adcmp) | 396 + hw_params->default_adsmp[0]; 397 + 417 398 rzg2l_adc_writel(adc, RZG2L_ADM(3), reg); 418 399 419 400 exit_hw_init: 420 - clk_disable_unprepare(adc->pclk); 421 - 401 + pm_runtime_mark_last_busy(dev); 402 + pm_runtime_put_autosuspend(dev); 422 403 return ret; 423 - } 424 - 425 - static void rzg2l_adc_pm_runtime_disable(void *data) 426 - { 427 - struct device *dev = data; 428 - 429 - pm_runtime_disable(dev->parent); 430 - } 431 - 432 - static void rzg2l_adc_pm_runtime_set_suspended(void *data) 433 - { 434 - struct device *dev = data; 435 - 436 - pm_runtime_set_suspended(dev->parent); 437 - } 438 - 439 - static void rzg2l_adc_reset_assert(void *data) 440 - { 441 - reset_control_assert(data); 442 404 } 443 405 444 406 static int rzg2l_adc_probe(struct platform_device *pdev) ··· 438 434 439 435 adc = iio_priv(indio_dev); 440 436 437 + adc->hw_params = device_get_match_data(dev); 438 + if (!adc->hw_params || adc->hw_params->num_channels > RZG2L_ADC_MAX_CHANNELS) 439 + return -EINVAL; 440 + 441 441 ret = rzg2l_adc_parse_properties(pdev, adc); 442 442 if (ret) 443 443 return ret; ··· 452 444 if (IS_ERR(adc->base)) 453 445 return PTR_ERR(adc->base); 454 446 455 - adc->pclk = devm_clk_get(dev, "pclk"); 456 - if (IS_ERR(adc->pclk)) { 457 - dev_err(dev, "Failed to get pclk"); 458 - return PTR_ERR(adc->pclk); 459 - } 447 + adc->adrstn = devm_reset_control_get_exclusive_deasserted(dev, "adrst-n"); 448 + if (IS_ERR(adc->adrstn)) 449 + return dev_err_probe(dev, PTR_ERR(adc->adrstn), 450 + "failed to get/deassert adrst-n\n"); 460 451 461 - adc->adclk = devm_clk_get(dev, "adclk"); 462 - if (IS_ERR(adc->adclk)) { 463 - dev_err(dev, "Failed to get adclk"); 464 - return PTR_ERR(adc->adclk); 465 - } 452 + adc->presetn = devm_reset_control_get_exclusive_deasserted(dev, "presetn"); 453 + if (IS_ERR(adc->presetn)) 454 + return dev_err_probe(dev, PTR_ERR(adc->presetn), 455 + "failed to get/deassert presetn\n"); 466 456 467 - adc->adrstn = devm_reset_control_get_exclusive(dev, "adrst-n"); 468 - if (IS_ERR(adc->adrstn)) { 469 - dev_err(dev, "failed to get adrstn\n"); 470 - return PTR_ERR(adc->adrstn); 471 - } 472 - 473 - adc->presetn = devm_reset_control_get_exclusive(dev, "presetn"); 474 - if (IS_ERR(adc->presetn)) { 475 - dev_err(dev, "failed to get presetn\n"); 476 - return PTR_ERR(adc->presetn); 477 - } 478 - 479 - ret = reset_control_deassert(adc->adrstn); 480 - if (ret) { 481 - dev_err(&pdev->dev, "failed to deassert adrstn pin, %d\n", ret); 457 + pm_runtime_set_autosuspend_delay(dev, 300); 458 + pm_runtime_use_autosuspend(dev); 459 + ret = devm_pm_runtime_enable(dev); 460 + if (ret) 482 461 return ret; 483 - } 484 462 485 - ret = devm_add_action_or_reset(&pdev->dev, 486 - rzg2l_adc_reset_assert, adc->adrstn); 487 - if (ret) { 488 - dev_err(&pdev->dev, "failed to register adrstn assert devm action, %d\n", 489 - ret); 490 - return ret; 491 - } 463 + platform_set_drvdata(pdev, indio_dev); 492 464 493 - ret = reset_control_deassert(adc->presetn); 494 - if (ret) { 495 - dev_err(&pdev->dev, "failed to deassert presetn pin, %d\n", ret); 496 - return ret; 497 - } 498 - 499 - ret = devm_add_action_or_reset(&pdev->dev, 500 - rzg2l_adc_reset_assert, adc->presetn); 501 - if (ret) { 502 - dev_err(&pdev->dev, "failed to register presetn assert devm action, %d\n", 503 - ret); 504 - return ret; 505 - } 506 - 507 - ret = rzg2l_adc_hw_init(adc); 508 - if (ret) { 509 - dev_err(&pdev->dev, "failed to initialize ADC HW, %d\n", ret); 510 - return ret; 511 - } 465 + ret = rzg2l_adc_hw_init(dev, adc); 466 + if (ret) 467 + return dev_err_probe(&pdev->dev, ret, 468 + "failed to initialize ADC HW\n"); 512 469 513 470 irq = platform_get_irq(pdev, 0); 514 471 if (irq < 0) ··· 486 513 487 514 init_completion(&adc->completion); 488 515 489 - platform_set_drvdata(pdev, indio_dev); 490 - 491 516 indio_dev->name = DRIVER_NAME; 492 517 indio_dev->info = &rzg2l_adc_iio_info; 493 518 indio_dev->modes = INDIO_DIRECT_MODE; 494 519 indio_dev->channels = adc->data->channels; 495 520 indio_dev->num_channels = adc->data->num_channels; 496 521 497 - pm_runtime_set_suspended(dev); 498 - ret = devm_add_action_or_reset(&pdev->dev, 499 - rzg2l_adc_pm_runtime_set_suspended, &indio_dev->dev); 500 - if (ret) 501 - return ret; 502 - 503 - pm_runtime_enable(dev); 504 - ret = devm_add_action_or_reset(&pdev->dev, 505 - rzg2l_adc_pm_runtime_disable, &indio_dev->dev); 506 - if (ret) 507 - return ret; 508 - 509 522 return devm_iio_device_register(dev, indio_dev); 510 523 } 511 524 525 + static const struct rzg2l_adc_hw_params rzg2l_hw_params = { 526 + .num_channels = 8, 527 + .default_adcmp = 0xe, 528 + .default_adsmp = { 0x578 }, 529 + .adsmp_mask = GENMASK(15, 0), 530 + .adint_inten_mask = GENMASK(7, 0), 531 + .adivc = true 532 + }; 533 + 534 + static const struct rzg2l_adc_hw_params rzg3s_hw_params = { 535 + .num_channels = 9, 536 + .default_adcmp = 0x1d, 537 + .default_adsmp = { 0x7f, 0xff }, 538 + .adsmp_mask = GENMASK(7, 0), 539 + .adint_inten_mask = GENMASK(11, 0), 540 + }; 541 + 512 542 static const struct of_device_id rzg2l_adc_match[] = { 513 - { .compatible = "renesas,rzg2l-adc",}, 543 + { .compatible = "renesas,r9a08g045-adc", .data = &rzg3s_hw_params }, 544 + { .compatible = "renesas,rzg2l-adc", .data = &rzg2l_hw_params }, 514 545 { /* sentinel */ } 515 546 }; 516 547 MODULE_DEVICE_TABLE(of, rzg2l_adc_match); 517 548 518 - static int __maybe_unused rzg2l_adc_pm_runtime_suspend(struct device *dev) 549 + static int rzg2l_adc_pm_runtime_suspend(struct device *dev) 519 550 { 520 551 struct iio_dev *indio_dev = dev_get_drvdata(dev); 521 552 struct rzg2l_adc *adc = iio_priv(indio_dev); 522 553 523 554 rzg2l_adc_pwr(adc, false); 524 - clk_disable_unprepare(adc->adclk); 525 - clk_disable_unprepare(adc->pclk); 526 555 527 556 return 0; 528 557 } 529 558 530 - static int __maybe_unused rzg2l_adc_pm_runtime_resume(struct device *dev) 559 + static int rzg2l_adc_pm_runtime_resume(struct device *dev) 531 560 { 532 561 struct iio_dev *indio_dev = dev_get_drvdata(dev); 533 562 struct rzg2l_adc *adc = iio_priv(indio_dev); 534 - int ret; 535 - 536 - ret = clk_prepare_enable(adc->pclk); 537 - if (ret) 538 - return ret; 539 - 540 - ret = clk_prepare_enable(adc->adclk); 541 - if (ret) { 542 - clk_disable_unprepare(adc->pclk); 543 - return ret; 544 - } 545 563 546 564 rzg2l_adc_pwr(adc, true); 547 565 548 566 return 0; 549 567 } 550 568 569 + static int rzg2l_adc_suspend(struct device *dev) 570 + { 571 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 572 + struct rzg2l_adc *adc = iio_priv(indio_dev); 573 + struct reset_control_bulk_data resets[] = { 574 + { .rstc = adc->presetn }, 575 + { .rstc = adc->adrstn }, 576 + }; 577 + int ret; 578 + 579 + if (pm_runtime_suspended(dev)) { 580 + adc->was_rpm_active = false; 581 + } else { 582 + ret = pm_runtime_force_suspend(dev); 583 + if (ret) 584 + return ret; 585 + adc->was_rpm_active = true; 586 + } 587 + 588 + ret = reset_control_bulk_assert(ARRAY_SIZE(resets), resets); 589 + if (ret) 590 + goto rpm_restore; 591 + 592 + return 0; 593 + 594 + rpm_restore: 595 + if (adc->was_rpm_active) 596 + pm_runtime_force_resume(dev); 597 + 598 + return ret; 599 + } 600 + 601 + static int rzg2l_adc_resume(struct device *dev) 602 + { 603 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 604 + struct rzg2l_adc *adc = iio_priv(indio_dev); 605 + struct reset_control_bulk_data resets[] = { 606 + { .rstc = adc->adrstn }, 607 + { .rstc = adc->presetn }, 608 + }; 609 + int ret; 610 + 611 + ret = reset_control_bulk_deassert(ARRAY_SIZE(resets), resets); 612 + if (ret) 613 + return ret; 614 + 615 + if (adc->was_rpm_active) { 616 + ret = pm_runtime_force_resume(dev); 617 + if (ret) 618 + goto resets_restore; 619 + } 620 + 621 + ret = rzg2l_adc_hw_init(dev, adc); 622 + if (ret) 623 + goto rpm_restore; 624 + 625 + return 0; 626 + 627 + rpm_restore: 628 + if (adc->was_rpm_active) { 629 + pm_runtime_mark_last_busy(dev); 630 + pm_runtime_put_autosuspend(dev); 631 + } 632 + resets_restore: 633 + reset_control_bulk_assert(ARRAY_SIZE(resets), resets); 634 + return ret; 635 + } 636 + 551 637 static const struct dev_pm_ops rzg2l_adc_pm_ops = { 552 - SET_RUNTIME_PM_OPS(rzg2l_adc_pm_runtime_suspend, 553 - rzg2l_adc_pm_runtime_resume, 554 - NULL) 638 + RUNTIME_PM_OPS(rzg2l_adc_pm_runtime_suspend, rzg2l_adc_pm_runtime_resume, NULL) 639 + SYSTEM_SLEEP_PM_OPS(rzg2l_adc_suspend, rzg2l_adc_resume) 555 640 }; 556 641 557 642 static struct platform_driver rzg2l_adc_driver = { ··· 617 586 .driver = { 618 587 .name = DRIVER_NAME, 619 588 .of_match_table = rzg2l_adc_match, 620 - .pm = &rzg2l_adc_pm_ops, 589 + .pm = pm_ptr(&rzg2l_adc_pm_ops), 621 590 }, 622 591 }; 623 592
+1 -1
drivers/iio/adc/ti-adc081c.c
··· 37 37 /* Ensure natural alignment of buffer elements */ 38 38 struct { 39 39 u16 channel; 40 - s64 ts __aligned(8); 40 + aligned_s64 ts; 41 41 } scan; 42 42 }; 43 43
+1 -1
drivers/iio/adc/ti-adc084s021.c
··· 29 29 /* Buffer used to align data */ 30 30 struct { 31 31 __be16 channels[4]; 32 - s64 ts __aligned(8); 32 + aligned_s64 ts; 33 33 } scan; 34 34 /* 35 35 * DMA (thus cache coherency maintenance) may require the
+1 -1
drivers/iio/adc/ti-ads1015.c
··· 448 448 /* Ensure natural alignment of timestamp */ 449 449 struct { 450 450 s16 chan; 451 - s64 timestamp __aligned(8); 451 + aligned_s64 timestamp; 452 452 } scan; 453 453 int chan, ret, res; 454 454
+1 -1
drivers/iio/adc/ti-ads1119.c
··· 501 501 struct ads1119_state *st = iio_priv(indio_dev); 502 502 struct { 503 503 unsigned int sample; 504 - s64 timestamp __aligned(8); 504 + aligned_s64 timestamp; 505 505 } scan; 506 506 unsigned int index; 507 507 int ret;
+1 -1
drivers/iio/adc/ti-ads131e08.c
··· 102 102 struct completion completion; 103 103 struct { 104 104 u8 data[ADS131E08_NUM_DATA_BYTES_MAX]; 105 - s64 ts __aligned(8); 105 + aligned_s64 ts; 106 106 } tmp_buf; 107 107 108 108 u8 tx_buf[3] __aligned(IIO_DMA_MINALIGN);
+1 -1
drivers/iio/adc/ti-lmp92064.c
··· 199 199 struct lmp92064_adc_priv *priv = iio_priv(indio_dev); 200 200 struct { 201 201 u16 values[2]; 202 - int64_t timestamp __aligned(8); 202 + aligned_s64 timestamp; 203 203 } data; 204 204 int ret; 205 205
+1 -1
drivers/iio/adc/ti-tsc2046.c
··· 157 157 /* Scan data for each channel */ 158 158 u16 data[TI_TSC2046_MAX_CHAN]; 159 159 /* Timestamp */ 160 - s64 ts __aligned(8); 160 + aligned_s64 ts; 161 161 } scan_buf; 162 162 163 163 /*
+44 -56
drivers/iio/adc/vf610_adc.c
··· 173 173 /* Ensure the timestamp is naturally aligned */ 174 174 struct { 175 175 u16 chan; 176 - s64 timestamp __aligned(8); 176 + aligned_s64 timestamp; 177 177 } scan; 178 + }; 179 + 180 + struct vf610_chip_info { 181 + u8 num_channels; 178 182 }; 179 183 180 184 static const u32 vf610_hw_avgs[] = { 1, 4, 8, 16, 32 }; ··· 812 808 .attrs = &vf610_attribute_group, 813 809 }; 814 810 811 + static const struct vf610_chip_info vf610_chip_info = { 812 + .num_channels = ARRAY_SIZE(vf610_adc_iio_channels), 813 + }; 814 + 815 + static const struct vf610_chip_info imx6sx_chip_info = { 816 + .num_channels = 4, 817 + }; 818 + 815 819 static const struct of_device_id vf610_adc_match[] = { 816 - { .compatible = "fsl,vf610-adc", }, 820 + { .compatible = "fsl,imx6sx-adc", .data = &imx6sx_chip_info}, 821 + { .compatible = "fsl,vf610-adc", .data = &vf610_chip_info}, 817 822 { /* sentinel */ } 818 823 }; 819 824 MODULE_DEVICE_TABLE(of, vf610_adc_match); 820 825 826 + static void vf610_adc_action_remove(void *d) 827 + { 828 + struct vf610_adc *info = d; 829 + 830 + regulator_disable(info->vref); 831 + } 832 + 821 833 static int vf610_adc_probe(struct platform_device *pdev) 822 834 { 835 + const struct vf610_chip_info *chip_info; 823 836 struct device *dev = &pdev->dev; 824 837 struct vf610_adc *info; 825 838 struct iio_dev *indio_dev; ··· 844 823 int ret; 845 824 846 825 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc)); 847 - if (!indio_dev) { 848 - dev_err(&pdev->dev, "Failed allocating iio device\n"); 849 - return -ENOMEM; 850 - } 826 + if (!indio_dev) 827 + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n"); 851 828 852 829 info = iio_priv(indio_dev); 853 830 info->dev = &pdev->dev; ··· 854 835 if (IS_ERR(info->regs)) 855 836 return PTR_ERR(info->regs); 856 837 838 + chip_info = device_get_match_data(dev); 839 + 857 840 irq = platform_get_irq(pdev, 0); 858 841 if (irq < 0) 859 842 return irq; ··· 863 842 ret = devm_request_irq(info->dev, irq, 864 843 vf610_adc_isr, 0, 865 844 dev_name(&pdev->dev), indio_dev); 866 - if (ret < 0) { 867 - dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq); 868 - return ret; 869 - } 845 + if (ret < 0) 846 + return dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq); 870 847 871 - info->clk = devm_clk_get(&pdev->dev, "adc"); 872 - if (IS_ERR(info->clk)) { 873 - dev_err(&pdev->dev, "failed getting clock, err = %ld\n", 874 - PTR_ERR(info->clk)); 875 - return PTR_ERR(info->clk); 876 - } 848 + info->clk = devm_clk_get_enabled(&pdev->dev, "adc"); 849 + if (IS_ERR(info->clk)) 850 + return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), "failed getting clock\n"); 877 851 878 852 info->vref = devm_regulator_get(&pdev->dev, "vref"); 879 853 if (IS_ERR(info->vref)) 880 854 return PTR_ERR(info->vref); 881 855 882 856 ret = regulator_enable(info->vref); 857 + if (ret) 858 + return ret; 859 + 860 + ret = devm_add_action_or_reset(&pdev->dev, vf610_adc_action_remove, info); 883 861 if (ret) 884 862 return ret; 885 863 ··· 897 877 indio_dev->info = &vf610_adc_iio_info; 898 878 indio_dev->modes = INDIO_DIRECT_MODE; 899 879 indio_dev->channels = vf610_adc_iio_channels; 900 - indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels); 901 - 902 - ret = clk_prepare_enable(info->clk); 903 - if (ret) { 904 - dev_err(&pdev->dev, 905 - "Could not prepare or enable the clock.\n"); 906 - goto error_adc_clk_enable; 907 - } 880 + indio_dev->num_channels = chip_info->num_channels; 908 881 909 882 vf610_adc_cfg_init(info); 910 883 vf610_adc_hw_init(info); 911 884 912 - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 913 - NULL, &iio_triggered_buffer_setup_ops); 914 - if (ret < 0) { 915 - dev_err(&pdev->dev, "Couldn't initialise the buffer\n"); 916 - goto error_iio_device_register; 917 - } 885 + ret = devm_iio_triggered_buffer_setup(&pdev->dev, indio_dev, &iio_pollfunc_store_time, 886 + NULL, &iio_triggered_buffer_setup_ops); 887 + if (ret < 0) 888 + return dev_err_probe(&pdev->dev, ret, "Couldn't initialise the buffer\n"); 918 889 919 890 mutex_init(&info->lock); 920 891 921 - ret = iio_device_register(indio_dev); 922 - if (ret) { 923 - dev_err(&pdev->dev, "Couldn't register the device.\n"); 924 - goto error_adc_buffer_init; 925 - } 892 + ret = devm_iio_device_register(&pdev->dev, indio_dev); 893 + if (ret) 894 + return dev_err_probe(&pdev->dev, ret, "Couldn't register the device.\n"); 926 895 927 896 return 0; 928 - 929 - error_adc_buffer_init: 930 - iio_triggered_buffer_cleanup(indio_dev); 931 - error_iio_device_register: 932 - clk_disable_unprepare(info->clk); 933 - error_adc_clk_enable: 934 - regulator_disable(info->vref); 935 - 936 - return ret; 937 - } 938 - 939 - static void vf610_adc_remove(struct platform_device *pdev) 940 - { 941 - struct iio_dev *indio_dev = platform_get_drvdata(pdev); 942 - struct vf610_adc *info = iio_priv(indio_dev); 943 - 944 - iio_device_unregister(indio_dev); 945 - iio_triggered_buffer_cleanup(indio_dev); 946 - regulator_disable(info->vref); 947 - clk_disable_unprepare(info->clk); 948 897 } 949 898 950 899 static int vf610_adc_suspend(struct device *dev) ··· 961 972 962 973 static struct platform_driver vf610_adc_driver = { 963 974 .probe = vf610_adc_probe, 964 - .remove = vf610_adc_remove, 965 975 .driver = { 966 976 .name = DRIVER_NAME, 967 977 .of_match_table = vf610_adc_match,
+17 -2
drivers/iio/buffer/industrialio-buffer-dmaengine.c
··· 206 206 207 207 /** 208 208 * iio_dmaengine_buffer_alloc() - Allocate new buffer which uses DMAengine 209 - * @dev: Parent device for the buffer 209 + * @dev: DMA channel consumer device 210 210 * @channel: DMA channel name, typically "rx". 211 211 * 212 212 * This allocates a new IIO buffer which internally uses the DMAengine framework ··· 288 288 } 289 289 EXPORT_SYMBOL_NS_GPL(iio_dmaengine_buffer_free, "IIO_DMAENGINE_BUFFER"); 290 290 291 + /** 292 + * iio_dmaengine_buffer_setup_ext() - Setup a DMA buffer for an IIO device 293 + * @dev: DMA channel consumer device 294 + * @indio_dev: IIO device to which to attach this buffer. 295 + * @channel: DMA channel name, typically "rx". 296 + * @dir: Direction of buffer (in or out) 297 + * 298 + * This allocates a new IIO buffer with devm_iio_dmaengine_buffer_alloc() 299 + * and attaches it to an IIO device with iio_device_attach_buffer(). 300 + * It also appends the INDIO_BUFFER_HARDWARE mode to the supported modes of the 301 + * IIO device. 302 + * 303 + * Once done using the buffer iio_dmaengine_buffer_free() should be used to 304 + * release it. 305 + */ 291 306 struct iio_buffer *iio_dmaengine_buffer_setup_ext(struct device *dev, 292 307 struct iio_dev *indio_dev, 293 308 const char *channel, ··· 336 321 337 322 /** 338 323 * devm_iio_dmaengine_buffer_setup_ext() - Setup a DMA buffer for an IIO device 339 - * @dev: Parent device for the buffer 324 + * @dev: Device for devm ownership and DMA channel consumer device 340 325 * @indio_dev: IIO device to which to attach this buffer. 341 326 * @channel: DMA channel name, typically "rx". 342 327 * @dir: Direction of buffer (in or out)
+2
drivers/iio/chemical/bme680.h
··· 2 2 #ifndef BME680_H_ 3 3 #define BME680_H_ 4 4 5 + #include <linux/pm.h> 5 6 #include <linux/regmap.h> 6 7 7 8 #define BME680_REG_CHIP_ID 0xD0 ··· 81 80 #define BME680_CALIB_RANGE_3_LEN 5 82 81 83 82 extern const struct regmap_config bme680_regmap_config; 83 + extern const struct dev_pm_ops bme680_dev_pm_ops; 84 84 85 85 int bme680_core_probe(struct device *dev, struct regmap *regmap, 86 86 const char *name);
+113 -7
drivers/iio/chemical/bme680_core.c
··· 14 14 #include <linux/device.h> 15 15 #include <linux/log2.h> 16 16 #include <linux/module.h> 17 + #include <linux/pm.h> 18 + #include <linux/pm_runtime.h> 17 19 #include <linux/regmap.h> 20 + #include <linux/regulator/consumer.h> 18 21 19 22 #include <linux/iio/buffer.h> 20 23 #include <linux/iio/iio.h> ··· 113 110 BME680_HUMID, 114 111 BME680_GAS, 115 112 }; 113 + 114 + static const char *const bme680_supply_names[] = { "vdd", "vddio" }; 116 115 117 116 struct bme680_data { 118 117 struct regmap *regmap; ··· 822 817 return 0; 823 818 } 824 819 825 - static int bme680_read_raw(struct iio_dev *indio_dev, 826 - struct iio_chan_spec const *chan, 827 - int *val, int *val2, long mask) 820 + static int __bme680_read_raw(struct iio_dev *indio_dev, 821 + struct iio_chan_spec const *chan, 822 + int *val, int *val2, long mask) 828 823 { 829 824 struct bme680_data *data = iio_priv(indio_dev); 830 825 int chan_val, ret; ··· 937 932 } 938 933 } 939 934 935 + static int bme680_read_raw(struct iio_dev *indio_dev, 936 + struct iio_chan_spec const *chan, 937 + int *val, int *val2, long mask) 938 + { 939 + struct bme680_data *data = iio_priv(indio_dev); 940 + struct device *dev = regmap_get_device(data->regmap); 941 + int ret; 942 + 943 + ret = pm_runtime_resume_and_get(dev); 944 + if (ret) 945 + return ret; 946 + 947 + ret = __bme680_read_raw(indio_dev, chan, val, val2, mask); 948 + pm_runtime_mark_last_busy(dev); 949 + pm_runtime_put_autosuspend(dev); 950 + 951 + return ret; 952 + } 953 + 940 954 static bool bme680_is_valid_oversampling(int rate) 941 955 { 942 956 return (rate > 0 && rate <= 16 && is_power_of_2(rate)); 943 957 } 944 958 945 - static int bme680_write_raw(struct iio_dev *indio_dev, 946 - struct iio_chan_spec const *chan, 947 - int val, int val2, long mask) 959 + static int __bme680_write_raw(struct iio_dev *indio_dev, 960 + struct iio_chan_spec const *chan, 961 + int val, int val2, long mask) 948 962 { 949 963 struct bme680_data *data = iio_priv(indio_dev); 950 964 ··· 1006 982 default: 1007 983 return -EINVAL; 1008 984 } 985 + } 986 + 987 + static int bme680_write_raw(struct iio_dev *indio_dev, 988 + struct iio_chan_spec const *chan, 989 + int val, int val2, long mask) 990 + { 991 + struct bme680_data *data = iio_priv(indio_dev); 992 + struct device *dev = regmap_get_device(data->regmap); 993 + int ret; 994 + 995 + ret = pm_runtime_resume_and_get(dev); 996 + if (ret) 997 + return ret; 998 + 999 + ret = __bme680_write_raw(indio_dev, chan, val, val2, mask); 1000 + pm_runtime_mark_last_busy(dev); 1001 + pm_runtime_put_autosuspend(dev); 1002 + 1003 + return ret; 1009 1004 } 1010 1005 1011 1006 static const char bme680_oversampling_ratio_show[] = "1 2 4 8 16"; ··· 1127 1084 return IRQ_HANDLED; 1128 1085 } 1129 1086 1087 + static int bme680_buffer_preenable(struct iio_dev *indio_dev) 1088 + { 1089 + struct bme680_data *data = iio_priv(indio_dev); 1090 + struct device *dev = regmap_get_device(data->regmap); 1091 + 1092 + return pm_runtime_resume_and_get(dev); 1093 + } 1094 + 1095 + static int bme680_buffer_postdisable(struct iio_dev *indio_dev) 1096 + { 1097 + struct bme680_data *data = iio_priv(indio_dev); 1098 + struct device *dev = regmap_get_device(data->regmap); 1099 + 1100 + pm_runtime_mark_last_busy(dev); 1101 + pm_runtime_put_autosuspend(dev); 1102 + return 0; 1103 + } 1104 + 1105 + static const struct iio_buffer_setup_ops bme680_buffer_setup_ops = { 1106 + .preenable = bme680_buffer_preenable, 1107 + .postdisable = bme680_buffer_postdisable, 1108 + }; 1109 + 1130 1110 int bme680_core_probe(struct device *dev, struct regmap *regmap, 1131 1111 const char *name) 1132 1112 { ··· 1179 1113 data->heater_temp = 320; /* degree Celsius */ 1180 1114 data->heater_dur = 150; /* milliseconds */ 1181 1115 data->preheat_curr_mA = 0; 1116 + 1117 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(bme680_supply_names), 1118 + bme680_supply_names); 1119 + if (ret) 1120 + return dev_err_probe(dev, ret, 1121 + "failed to get and enable supplies.\n"); 1122 + 1123 + fsleep(BME680_STARTUP_TIME_US); 1182 1124 1183 1125 ret = regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET); 1184 1126 if (ret < 0) ··· 1223 1149 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 1224 1150 iio_pollfunc_store_time, 1225 1151 bme680_trigger_handler, 1226 - NULL); 1152 + &bme680_buffer_setup_ops); 1227 1153 if (ret) 1228 1154 return dev_err_probe(dev, ret, 1229 1155 "iio triggered buffer setup failed\n"); 1230 1156 1157 + /* Enable runtime PM */ 1158 + pm_runtime_set_autosuspend_delay(dev, BME680_STARTUP_TIME_US); 1159 + pm_runtime_use_autosuspend(dev); 1160 + pm_runtime_set_active(dev); 1161 + ret = devm_pm_runtime_enable(dev); 1162 + if (ret) 1163 + return ret; 1164 + 1231 1165 return devm_iio_device_register(dev, indio_dev); 1232 1166 } 1233 1167 EXPORT_SYMBOL_NS_GPL(bme680_core_probe, "IIO_BME680"); 1168 + 1169 + static int bme680_runtime_suspend(struct device *dev) 1170 + { 1171 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 1172 + struct bme680_data *data = iio_priv(indio_dev); 1173 + 1174 + return bme680_set_mode(data, BME680_MODE_SLEEP); 1175 + } 1176 + 1177 + static int bme680_runtime_resume(struct device *dev) 1178 + { 1179 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 1180 + struct bme680_data *data = iio_priv(indio_dev); 1181 + int ret; 1182 + 1183 + ret = bme680_chip_config(data); 1184 + if (ret) 1185 + return ret; 1186 + 1187 + return bme680_gas_config(data); 1188 + } 1189 + 1190 + EXPORT_RUNTIME_DEV_PM_OPS(bme680_dev_pm_ops, bme680_runtime_suspend, 1191 + bme680_runtime_resume, NULL); 1234 1192 1235 1193 MODULE_AUTHOR("Himanshu Jha <himanshujha199640@gmail.com>"); 1236 1194 MODULE_DESCRIPTION("Bosch BME680 Driver");
+1
drivers/iio/chemical/bme680_i2c.c
··· 51 51 .driver = { 52 52 .name = "bme680_i2c", 53 53 .of_match_table = bme680_of_i2c_match, 54 + .pm = pm_ptr(&bme680_dev_pm_ops), 54 55 }, 55 56 .probe = bme680_i2c_probe, 56 57 .id_table = bme680_i2c_id,
+1
drivers/iio/chemical/bme680_spi.c
··· 154 154 .driver = { 155 155 .name = "bme680_spi", 156 156 .of_match_table = bme680_of_spi_match, 157 + .pm = pm_ptr(&bme680_dev_pm_ops), 157 158 }, 158 159 .probe = bme680_spi_probe, 159 160 .id_table = bme680_spi_id,
+1 -1
drivers/iio/chemical/ccs811.c
··· 81 81 /* Ensures correct alignment of timestamp if present */ 82 82 struct { 83 83 s16 channels[2]; 84 - s64 ts __aligned(8); 84 + aligned_s64 ts; 85 85 } scan; 86 86 }; 87 87
+1 -1
drivers/iio/chemical/ens160_core.c
··· 60 60 struct mutex mutex; 61 61 struct { 62 62 __le16 chans[2]; 63 - s64 timestamp __aligned(8); 63 + aligned_s64 timestamp; 64 64 } scan __aligned(IIO_DMA_MINALIGN); 65 65 u8 fw_version[3]; 66 66 __le16 buf;
+1 -1
drivers/iio/chemical/scd30_core.c
··· 594 594 struct scd30_state *state = iio_priv(indio_dev); 595 595 struct { 596 596 int data[SCD30_MEAS_COUNT]; 597 - s64 ts __aligned(8); 597 + aligned_s64 ts; 598 598 } scan; 599 599 int ret; 600 600
+1 -1
drivers/iio/chemical/scd4x.c
··· 665 665 struct scd4x_state *state = iio_priv(indio_dev); 666 666 struct { 667 667 uint16_t data[3]; 668 - int64_t ts __aligned(8); 668 + aligned_s64 ts; 669 669 } scan; 670 670 int ret; 671 671
+2 -2
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
··· 109 109 110 110 static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts) 111 111 { 112 - const int64_t period_min = ts->min_period * ts->mult; 113 - const int64_t period_max = ts->max_period * ts->mult; 112 + const int64_t period_min = (int64_t)ts->min_period * ts->mult; 113 + const int64_t period_max = (int64_t)ts->max_period * ts->mult; 114 114 int64_t add_max, sub_max; 115 115 int64_t delta, jitter; 116 116 int64_t adjust;
+5 -7
drivers/iio/common/ssp_sensors/ssp_iio.c
··· 8 8 #include <linux/iio/kfifo_buf.h> 9 9 #include <linux/module.h> 10 10 #include <linux/slab.h> 11 + #include <linux/unaligned.h> 12 + #include <linux/units.h> 11 13 #include "ssp_iio_sensor.h" 12 14 13 15 /** ··· 72 70 int ssp_common_process_data(struct iio_dev *indio_dev, void *buf, 73 71 unsigned int len, int64_t timestamp) 74 72 { 75 - __le32 time; 76 - int64_t calculated_time = 0; 73 + int64_t calculated_time; 77 74 struct ssp_sensor_data *spd = iio_priv(indio_dev); 78 75 79 76 if (indio_dev->scan_bytes == 0) ··· 83 82 */ 84 83 memcpy(spd->buffer, buf, len); 85 84 86 - if (indio_dev->scan_timestamp) { 87 - memcpy(&time, &((char *)buf)[len], SSP_TIME_SIZE); 88 - calculated_time = 89 - timestamp + (int64_t)le32_to_cpu(time) * 1000000; 90 - } 85 + calculated_time = timestamp + 86 + (int64_t)get_unaligned_le32(buf + len) * MEGA; 91 87 92 88 return iio_push_to_buffers_with_timestamp(indio_dev, spd->buffer, 93 89 calculated_time);
+9 -1
drivers/iio/dac/Kconfig
··· 80 80 depends on SPI 81 81 help 82 82 Say yes here to build support for Analog Devices AD5421 loop-powered 83 - digital-to-analog convertors (DAC). 83 + digital-to-analog converters (DAC). 84 84 85 85 To compile this driver as module choose M here: the module will be called 86 86 ad5421. ··· 347 347 348 348 To compile this driver as a module choose M here: the module will be called 349 349 ad8801. 350 + 351 + config BD79703 352 + tristate "ROHM Semiconductor BD79703 DAC driver" 353 + depends on SPI 354 + select REGMAP_SPI 355 + help 356 + Say yes here to build support for ROHM Semiconductor BD79703 Digital 357 + to Analog Converter (DAC). 350 358 351 359 config CIO_DAC 352 360 tristate "Measurement Computing CIO-DAC IIO driver"
+1
drivers/iio/dac/Makefile
··· 34 34 obj-$(CONFIG_AD8801) += ad8801.o 35 35 obj-$(CONFIG_AD9739A) += ad9739a.o 36 36 obj-$(CONFIG_ADI_AXI_DAC) += adi-axi-dac.o 37 + obj-$(CONFIG_BD79703) += rohm-bd79703.o 37 38 obj-$(CONFIG_CIO_DAC) += cio-dac.o 38 39 obj-$(CONFIG_DPOT_DAC) += dpot-dac.o 39 40 obj-$(CONFIG_DS4424) += ds4424.o
+1 -3
drivers/iio/dac/ad5624r.h
··· 41 41 }; 42 42 43 43 /** 44 - * struct ad5446_state - driver instance specific data 45 - * @indio_dev: the industrial I/O device 44 + * struct ad5624r_state - driver instance specific data 46 45 * @us: spi_device 47 46 * @chip_info: chip model specific constants, available modes etc 48 - * @reg: supply regulator 49 47 * @vref_mv: actual reference voltage used 50 48 * @pwr_down_mask power down mask 51 49 * @pwr_down_mode current power down mode
-6
drivers/iio/dac/ad5686-spi.c
··· 95 95 ad5686_spi_write, ad5686_spi_read); 96 96 } 97 97 98 - static void ad5686_spi_remove(struct spi_device *spi) 99 - { 100 - ad5686_remove(&spi->dev); 101 - } 102 - 103 98 static const struct spi_device_id ad5686_spi_id[] = { 104 99 {"ad5310r", ID_AD5310R}, 105 100 {"ad5672r", ID_AD5672R}, ··· 121 126 .name = "ad5686", 122 127 }, 123 128 .probe = ad5686_spi_probe, 124 - .remove = ad5686_spi_remove, 125 129 .id_table = ad5686_spi_id, 126 130 }; 127 131
+15 -47
drivers/iio/dac/ad5686.c
··· 455 455 struct ad5686_state *st; 456 456 struct iio_dev *indio_dev; 457 457 unsigned int val, ref_bit_msk; 458 + bool has_external_vref; 458 459 u8 cmd; 459 - int ret, i, voltage_uv = 0; 460 + int ret, i; 460 461 461 462 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 462 463 if (indio_dev == NULL) 463 464 return -ENOMEM; 464 465 465 466 st = iio_priv(indio_dev); 466 - dev_set_drvdata(dev, indio_dev); 467 467 468 468 st->dev = dev; 469 469 st->write = write; 470 470 st->read = read; 471 471 472 - st->reg = devm_regulator_get_optional(dev, "vcc"); 473 - if (!IS_ERR(st->reg)) { 474 - ret = regulator_enable(st->reg); 475 - if (ret) 476 - return ret; 477 - 478 - ret = regulator_get_voltage(st->reg); 479 - if (ret < 0) 480 - goto error_disable_reg; 481 - 482 - voltage_uv = ret; 483 - } 484 - 485 472 st->chip_info = &ad5686_chip_info_tbl[chip_type]; 486 473 487 - if (voltage_uv) 488 - st->vref_mv = voltage_uv / 1000; 489 - else 490 - st->vref_mv = st->chip_info->int_vref_mv; 474 + ret = devm_regulator_get_enable_read_voltage(dev, "vcc"); 475 + if (ret < 0 && ret != -ENODEV) 476 + return ret; 477 + 478 + has_external_vref = ret != -ENODEV; 479 + st->vref_mv = has_external_vref ? ret / 1000 : st->chip_info->int_vref_mv; 491 480 492 481 /* Set all the power down mode for all channels to 1K pulldown */ 493 482 for (i = 0; i < st->chip_info->num_channels; i++) ··· 494 505 case AD5310_REGMAP: 495 506 cmd = AD5686_CMD_CONTROL_REG; 496 507 ref_bit_msk = AD5310_REF_BIT_MSK; 497 - st->use_internal_vref = !voltage_uv; 508 + st->use_internal_vref = !has_external_vref; 498 509 break; 499 510 case AD5683_REGMAP: 500 511 cmd = AD5686_CMD_CONTROL_REG; 501 512 ref_bit_msk = AD5683_REF_BIT_MSK; 502 - st->use_internal_vref = !voltage_uv; 513 + st->use_internal_vref = !has_external_vref; 503 514 break; 504 515 case AD5686_REGMAP: 505 516 cmd = AD5686_CMD_INTERNAL_REFER_SETUP; ··· 508 519 case AD5693_REGMAP: 509 520 cmd = AD5686_CMD_CONTROL_REG; 510 521 ref_bit_msk = AD5693_REF_BIT_MSK; 511 - st->use_internal_vref = !voltage_uv; 522 + st->use_internal_vref = !has_external_vref; 512 523 break; 513 524 default: 514 - ret = -EINVAL; 515 - goto error_disable_reg; 525 + return -EINVAL; 516 526 } 517 527 518 - val = (voltage_uv | ref_bit_msk); 528 + val = (has_external_vref | ref_bit_msk); 519 529 520 530 ret = st->write(st, cmd, 0, !!val); 521 531 if (ret) 522 - goto error_disable_reg; 532 + return ret; 523 533 524 - ret = iio_device_register(indio_dev); 525 - if (ret) 526 - goto error_disable_reg; 527 - 528 - return 0; 529 - 530 - error_disable_reg: 531 - if (!IS_ERR(st->reg)) 532 - regulator_disable(st->reg); 533 - return ret; 534 + return devm_iio_device_register(dev, indio_dev); 534 535 } 535 536 EXPORT_SYMBOL_NS_GPL(ad5686_probe, "IIO_AD5686"); 536 - 537 - void ad5686_remove(struct device *dev) 538 - { 539 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 540 - struct ad5686_state *st = iio_priv(indio_dev); 541 - 542 - iio_device_unregister(indio_dev); 543 - if (!IS_ERR(st->reg)) 544 - regulator_disable(st->reg); 545 - } 546 - EXPORT_SYMBOL_NS_GPL(ad5686_remove, "IIO_AD5686"); 547 537 548 538 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); 549 539 MODULE_DESCRIPTION("Analog Devices AD5686/85/84 DAC");
+1 -5
drivers/iio/dac/ad5686.h
··· 115 115 }; 116 116 117 117 /** 118 - * struct ad5446_state - driver instance specific data 118 + * struct ad5686_state - driver instance specific data 119 119 * @spi: spi_device 120 120 * @chip_info: chip model specific constants, available modes etc 121 - * @reg: supply regulator 122 121 * @vref_mv: actual reference voltage used 123 122 * @pwr_down_mask: power down mask 124 123 * @pwr_down_mode: current power down mode ··· 129 130 struct ad5686_state { 130 131 struct device *dev; 131 132 const struct ad5686_chip_info *chip_info; 132 - struct regulator *reg; 133 133 unsigned short vref_mv; 134 134 unsigned int pwr_down_mask; 135 135 unsigned int pwr_down_mode; ··· 154 156 enum ad5686_supported_device_ids chip_type, 155 157 const char *name, ad5686_write_func write, 156 158 ad5686_read_func read); 157 - 158 - void ad5686_remove(struct device *dev); 159 159 160 160 161 161 #endif /* __DRIVERS_IIO_DAC_AD5686_H__ */
-6
drivers/iio/dac/ad5696-i2c.c
··· 65 65 ad5686_i2c_write, ad5686_i2c_read); 66 66 } 67 67 68 - static void ad5686_i2c_remove(struct i2c_client *i2c) 69 - { 70 - ad5686_remove(&i2c->dev); 71 - } 72 - 73 68 static const struct i2c_device_id ad5686_i2c_id[] = { 74 69 {"ad5311r", ID_AD5311R}, 75 70 {"ad5337r", ID_AD5337R}, ··· 111 116 .of_match_table = ad5686_of_match, 112 117 }, 113 118 .probe = ad5686_i2c_probe, 114 - .remove = ad5686_i2c_remove, 115 119 .id_table = ad5686_i2c_id, 116 120 }; 117 121
+9 -59
drivers/iio/dac/ad7293.c
··· 141 141 /* Protect against concurrent accesses to the device, page selection and data content */ 142 142 struct mutex lock; 143 143 struct gpio_desc *gpio_reset; 144 - struct regulator *reg_avdd; 145 - struct regulator *reg_vdrive; 146 144 u8 page_select; 147 145 u8 data[3] __aligned(IIO_DMA_MINALIGN); 148 146 }; ··· 775 777 static int ad7293_properties_parse(struct ad7293_state *st) 776 778 { 777 779 struct spi_device *spi = st->spi; 780 + int ret; 781 + 782 + ret = devm_regulator_get_enable(&spi->dev, "avdd"); 783 + if (ret) 784 + return dev_err_probe(&spi->dev, ret, "failed to enable AVDD\n"); 785 + 786 + ret = devm_regulator_get_enable(&spi->dev, "vdrive"); 787 + if (ret) 788 + return dev_err_probe(&spi->dev, ret, "failed to enable VDRIVE\n"); 778 789 779 790 st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset", 780 791 GPIOD_OUT_HIGH); ··· 791 784 return dev_err_probe(&spi->dev, PTR_ERR(st->gpio_reset), 792 785 "failed to get the reset GPIO\n"); 793 786 794 - st->reg_avdd = devm_regulator_get(&spi->dev, "avdd"); 795 - if (IS_ERR(st->reg_avdd)) 796 - return dev_err_probe(&spi->dev, PTR_ERR(st->reg_avdd), 797 - "failed to get the AVDD voltage\n"); 798 - 799 - st->reg_vdrive = devm_regulator_get(&spi->dev, "vdrive"); 800 - if (IS_ERR(st->reg_vdrive)) 801 - return dev_err_probe(&spi->dev, PTR_ERR(st->reg_vdrive), 802 - "failed to get the VDRIVE voltage\n"); 803 - 804 787 return 0; 805 - } 806 - 807 - static void ad7293_reg_disable(void *data) 808 - { 809 - regulator_disable(data); 810 788 } 811 789 812 790 static int ad7293_init(struct ad7293_state *st) ··· 807 815 ret = ad7293_reset(st); 808 816 if (ret) 809 817 return ret; 810 - 811 - ret = regulator_enable(st->reg_avdd); 812 - if (ret) { 813 - dev_err(&spi->dev, 814 - "Failed to enable specified AVDD Voltage!\n"); 815 - return ret; 816 - } 817 - 818 - ret = devm_add_action_or_reset(&spi->dev, ad7293_reg_disable, 819 - st->reg_avdd); 820 - if (ret) 821 - return ret; 822 - 823 - ret = regulator_enable(st->reg_vdrive); 824 - if (ret) { 825 - dev_err(&spi->dev, 826 - "Failed to enable specified VDRIVE Voltage!\n"); 827 - return ret; 828 - } 829 - 830 - ret = devm_add_action_or_reset(&spi->dev, ad7293_reg_disable, 831 - st->reg_vdrive); 832 - if (ret) 833 - return ret; 834 - 835 - ret = regulator_get_voltage(st->reg_avdd); 836 - if (ret < 0) { 837 - dev_err(&spi->dev, "Failed to read avdd regulator: %d\n", ret); 838 - return ret; 839 - } 840 - 841 - if (ret > 5500000 || ret < 4500000) 842 - return -EINVAL; 843 - 844 - ret = regulator_get_voltage(st->reg_vdrive); 845 - if (ret < 0) { 846 - dev_err(&spi->dev, 847 - "Failed to read vdrive regulator: %d\n", ret); 848 - return ret; 849 - } 850 - if (ret > 5500000 || ret < 1700000) 851 - return -EINVAL; 852 818 853 819 /* Check Chip ID */ 854 820 ret = __ad7293_spi_read(st, AD7293_REG_DEVICE_ID, &chip_id);
+12 -67
drivers/iio/dac/ad8801.c
··· 23 23 unsigned char dac_cache[8]; /* Value write on each channel */ 24 24 unsigned int vrefh_mv; 25 25 unsigned int vrefl_mv; 26 - struct regulator *vrefh_reg; 27 - struct regulator *vrefl_reg; 28 26 29 27 __be16 data __aligned(IIO_DMA_MINALIGN); 30 28 }; ··· 120 122 state->spi = spi; 121 123 id = spi_get_device_id(spi); 122 124 123 - state->vrefh_reg = devm_regulator_get(&spi->dev, "vrefh"); 124 - if (IS_ERR(state->vrefh_reg)) 125 - return dev_err_probe(&spi->dev, PTR_ERR(state->vrefh_reg), 126 - "Vrefh regulator not specified\n"); 125 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vrefh"); 126 + if (ret < 0) 127 + return dev_err_probe(&spi->dev, ret, 128 + "failed to get Vrefh voltage\n"); 127 129 128 - ret = regulator_enable(state->vrefh_reg); 129 - if (ret) { 130 - dev_err(&spi->dev, "Failed to enable vrefh regulator: %d\n", 131 - ret); 132 - return ret; 133 - } 134 - 135 - ret = regulator_get_voltage(state->vrefh_reg); 136 - if (ret < 0) { 137 - dev_err(&spi->dev, "Failed to read vrefh regulator: %d\n", 138 - ret); 139 - goto error_disable_vrefh_reg; 140 - } 141 130 state->vrefh_mv = ret / 1000; 142 131 143 132 if (id->driver_data == ID_AD8803) { 144 - state->vrefl_reg = devm_regulator_get(&spi->dev, "vrefl"); 145 - if (IS_ERR(state->vrefl_reg)) { 146 - ret = dev_err_probe(&spi->dev, PTR_ERR(state->vrefl_reg), 147 - "Vrefl regulator not specified\n"); 148 - goto error_disable_vrefh_reg; 149 - } 133 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vrefl"); 134 + if (ret < 0) 135 + return dev_err_probe(&spi->dev, ret, 136 + "failed to get Vrefl voltage\n"); 150 137 151 - ret = regulator_enable(state->vrefl_reg); 152 - if (ret) { 153 - dev_err(&spi->dev, "Failed to enable vrefl regulator: %d\n", 154 - ret); 155 - goto error_disable_vrefh_reg; 156 - } 157 - 158 - ret = regulator_get_voltage(state->vrefl_reg); 159 - if (ret < 0) { 160 - dev_err(&spi->dev, "Failed to read vrefl regulator: %d\n", 161 - ret); 162 - goto error_disable_vrefl_reg; 163 - } 164 138 state->vrefl_mv = ret / 1000; 165 - } else { 166 - state->vrefl_mv = 0; 167 - state->vrefl_reg = NULL; 168 139 } 169 140 170 - spi_set_drvdata(spi, indio_dev); 171 141 indio_dev->info = &ad8801_info; 172 142 indio_dev->modes = INDIO_DIRECT_MODE; 173 143 indio_dev->channels = ad8801_channels; 174 144 indio_dev->num_channels = ARRAY_SIZE(ad8801_channels); 175 145 indio_dev->name = id->name; 176 146 177 - ret = iio_device_register(indio_dev); 178 - if (ret) { 179 - dev_err(&spi->dev, "Failed to register iio device: %d\n", 180 - ret); 181 - goto error_disable_vrefl_reg; 182 - } 147 + ret = devm_iio_device_register(&spi->dev, indio_dev); 148 + if (ret) 149 + return dev_err_probe(&spi->dev, ret, 150 + "Failed to register iio device\n"); 183 151 184 152 return 0; 185 - 186 - error_disable_vrefl_reg: 187 - if (state->vrefl_reg) 188 - regulator_disable(state->vrefl_reg); 189 - error_disable_vrefh_reg: 190 - regulator_disable(state->vrefh_reg); 191 - return ret; 192 - } 193 - 194 - static void ad8801_remove(struct spi_device *spi) 195 - { 196 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 197 - struct ad8801_state *state = iio_priv(indio_dev); 198 - 199 - iio_device_unregister(indio_dev); 200 - if (state->vrefl_reg) 201 - regulator_disable(state->vrefl_reg); 202 - regulator_disable(state->vrefh_reg); 203 153 } 204 154 205 155 static const struct spi_device_id ad8801_ids[] = { ··· 162 216 .name = "ad8801", 163 217 }, 164 218 .probe = ad8801_probe, 165 - .remove = ad8801_remove, 166 219 .id_table = ad8801_ids, 167 220 }; 168 221 module_spi_driver(ad8801_driver);
+19 -50
drivers/iio/dac/ltc2632.c
··· 41 41 * @spi_dev: pointer to the spi_device struct 42 42 * @powerdown_cache_mask: used to show current channel powerdown state 43 43 * @vref_mv: used reference voltage (internal or external) 44 - * @vref_reg: regulator for the reference voltage 45 44 */ 46 45 struct ltc2632_state { 47 46 struct spi_device *spi_dev; 48 47 unsigned int powerdown_cache_mask; 49 48 int vref_mv; 50 - struct regulator *vref_reg; 51 49 }; 52 50 53 51 enum ltc2632_supported_device_ids { ··· 308 310 struct ltc2632_state *st; 309 311 struct iio_dev *indio_dev; 310 312 struct ltc2632_chip_info *chip_info; 313 + bool has_external_vref; 311 314 int ret; 312 315 313 316 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); ··· 317 318 318 319 st = iio_priv(indio_dev); 319 320 320 - spi_set_drvdata(spi, indio_dev); 321 321 st->spi_dev = spi; 322 322 323 323 chip_info = (struct ltc2632_chip_info *) 324 324 spi_get_device_id(spi)->driver_data; 325 325 326 - st->vref_reg = devm_regulator_get_optional(&spi->dev, "vref"); 327 - if (PTR_ERR(st->vref_reg) == -ENODEV) { 328 - /* use internal reference voltage */ 329 - st->vref_reg = NULL; 330 - st->vref_mv = chip_info->vref_mv; 326 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); 327 + if (ret < 0 && ret != -ENODEV) 328 + return dev_err_probe(&spi->dev, ret, 329 + "Failed to get vref regulator voltage\n"); 331 330 332 - ret = ltc2632_spi_write(spi, LTC2632_CMD_INTERNAL_REFER, 333 - 0, 0, 0); 334 - if (ret) { 335 - dev_err(&spi->dev, 336 - "Set internal reference command failed, %d\n", 337 - ret); 338 - return ret; 339 - } 340 - } else if (IS_ERR(st->vref_reg)) { 341 - dev_err(&spi->dev, 342 - "Error getting voltage reference regulator\n"); 343 - return PTR_ERR(st->vref_reg); 344 - } else { 345 - /* use external reference voltage */ 346 - ret = regulator_enable(st->vref_reg); 347 - if (ret) { 348 - dev_err(&spi->dev, 349 - "enable reference regulator failed, %d\n", 350 - ret); 351 - return ret; 352 - } 353 - st->vref_mv = regulator_get_voltage(st->vref_reg) / 1000; 331 + has_external_vref = ret != -ENODEV; 332 + st->vref_mv = has_external_vref ? ret / 1000 : chip_info->vref_mv; 354 333 334 + if (has_external_vref) { 355 335 ret = ltc2632_spi_write(spi, LTC2632_CMD_EXTERNAL_REFER, 356 - 0, 0, 0); 357 - if (ret) { 358 - dev_err(&spi->dev, 359 - "Set external reference command failed, %d\n", 360 - ret); 361 - return ret; 362 - } 336 + 0, 0, 0); 337 + if (ret) 338 + return dev_err_probe(&spi->dev, ret, 339 + "Set external reference command failed\n"); 340 + } else { 341 + ret = ltc2632_spi_write(spi, LTC2632_CMD_INTERNAL_REFER, 342 + 0, 0, 0); 343 + if (ret) 344 + return dev_err_probe(&spi->dev, ret, 345 + "Set internal reference command failed\n"); 363 346 } 364 347 365 348 indio_dev->name = fwnode_get_name(dev_fwnode(&spi->dev)) ?: spi_get_device_id(spi)->name; ··· 350 369 indio_dev->channels = chip_info->channels; 351 370 indio_dev->num_channels = chip_info->num_channels; 352 371 353 - return iio_device_register(indio_dev); 354 - } 355 - 356 - static void ltc2632_remove(struct spi_device *spi) 357 - { 358 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 359 - struct ltc2632_state *st = iio_priv(indio_dev); 360 - 361 - iio_device_unregister(indio_dev); 362 - 363 - if (st->vref_reg) 364 - regulator_disable(st->vref_reg); 372 + return devm_iio_device_register(&spi->dev, indio_dev); 365 373 } 366 374 367 375 static const struct spi_device_id ltc2632_id[] = { ··· 442 472 .of_match_table = ltc2632_of_match, 443 473 }, 444 474 .probe = ltc2632_probe, 445 - .remove = ltc2632_remove, 446 475 .id_table = ltc2632_id, 447 476 }; 448 477 module_spi_driver(ltc2632_driver);
+10 -34
drivers/iio/dac/ltc2688.c
··· 842 842 return 0; 843 843 } 844 844 845 - static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref) 845 + static int ltc2688_setup(struct ltc2688_state *st, bool has_external_vref) 846 846 { 847 847 struct device *dev = &st->spi->dev; 848 848 struct gpio_desc *gpio; ··· 881 881 if (ret) 882 882 return ret; 883 883 884 - if (!vref) 884 + if (!has_external_vref) 885 885 return 0; 886 886 887 887 return regmap_set_bits(st->regmap, LTC2688_CMD_CONFIG, 888 888 LTC2688_CONFIG_EXT_REF); 889 - } 890 - 891 - static void ltc2688_disable_regulator(void *regulator) 892 - { 893 - regulator_disable(regulator); 894 889 } 895 890 896 891 static bool ltc2688_reg_readable(struct device *dev, unsigned int reg) ··· 942 947 static const char * const regulators[] = { "vcc", "iovcc" }; 943 948 struct ltc2688_state *st; 944 949 struct iio_dev *indio_dev; 945 - struct regulator *vref_reg; 946 950 struct device *dev = &spi->dev; 951 + bool has_external_vref; 947 952 int ret; 948 953 949 954 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); ··· 968 973 if (ret) 969 974 return dev_err_probe(dev, ret, "Failed to enable regulators\n"); 970 975 971 - vref_reg = devm_regulator_get_optional(dev, "vref"); 972 - if (IS_ERR(vref_reg)) { 973 - if (PTR_ERR(vref_reg) != -ENODEV) 974 - return dev_err_probe(dev, PTR_ERR(vref_reg), 975 - "Failed to get vref regulator"); 976 + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); 977 + if (ret < 0 && ret != -ENODEV) 978 + return dev_err_probe(dev, ret, 979 + "Failed to get vref regulator voltage\n"); 976 980 977 - vref_reg = NULL; 978 - /* internal reference */ 979 - st->vref = 4096; 980 - } else { 981 - ret = regulator_enable(vref_reg); 982 - if (ret) 983 - return dev_err_probe(dev, ret, 984 - "Failed to enable vref regulators\n"); 981 + has_external_vref = ret != -ENODEV; 982 + st->vref = has_external_vref ? ret / 1000 : 0; 985 983 986 - ret = devm_add_action_or_reset(dev, ltc2688_disable_regulator, 987 - vref_reg); 988 - if (ret) 989 - return ret; 990 - 991 - ret = regulator_get_voltage(vref_reg); 992 - if (ret < 0) 993 - return dev_err_probe(dev, ret, "Failed to get vref\n"); 994 - 995 - st->vref = ret / 1000; 996 - } 997 - 998 - ret = ltc2688_setup(st, vref_reg); 984 + ret = ltc2688_setup(st, has_external_vref); 999 985 if (ret) 1000 986 return ret; 1001 987
+4 -32
drivers/iio/dac/max5821.c
··· 32 32 33 33 struct max5821_data { 34 34 struct i2c_client *client; 35 - struct regulator *vref_reg; 36 35 unsigned short vref_mv; 37 36 bool powerdown[MAX5821_MAX_DAC_CHANNELS]; 38 37 u8 powerdown_mode[MAX5821_MAX_DAC_CHANNELS]; ··· 294 295 .write_raw = max5821_write_raw, 295 296 }; 296 297 297 - static void max5821_regulator_disable(void *reg) 298 - { 299 - regulator_disable(reg); 300 - } 301 - 302 298 static int max5821_probe(struct i2c_client *client) 303 299 { 304 300 const struct i2c_device_id *id = i2c_client_get_device_id(client); ··· 315 321 data->powerdown_mode[tmp] = MAX5821_100KOHM_TO_GND; 316 322 } 317 323 318 - data->vref_reg = devm_regulator_get(&client->dev, "vref"); 319 - if (IS_ERR(data->vref_reg)) 320 - return dev_err_probe(&client->dev, PTR_ERR(data->vref_reg), 321 - "Failed to get vref regulator\n"); 322 - 323 - ret = regulator_enable(data->vref_reg); 324 - if (ret) { 325 - dev_err(&client->dev, 326 - "Failed to enable vref regulator: %d\n", ret); 327 - return ret; 328 - } 329 - 330 - ret = devm_add_action_or_reset(&client->dev, max5821_regulator_disable, 331 - data->vref_reg); 332 - if (ret) { 333 - dev_err(&client->dev, 334 - "Failed to add action to managed regulator: %d\n", ret); 335 - return ret; 336 - } 337 - 338 - ret = regulator_get_voltage(data->vref_reg); 339 - if (ret < 0) { 340 - dev_err(&client->dev, 341 - "Failed to get voltage on regulator: %d\n", ret); 342 - return ret; 343 - } 324 + ret = devm_regulator_get_enable_read_voltage(&client->dev, "vref"); 325 + if (ret) 326 + return dev_err_probe(&client->dev, ret, 327 + "Failed to get vref regulator voltage\n"); 344 328 345 329 data->vref_mv = ret / 1000; 346 330
+1 -1
drivers/iio/dac/mcp4725.c
··· 379 379 struct mcp4725_platform_data *pdata) 380 380 { 381 381 /* check if is the vref-supply defined */ 382 - pdata->use_vref = device_property_read_bool(dev, "vref-supply"); 382 + pdata->use_vref = device_property_present(dev, "vref-supply"); 383 383 pdata->vref_buffered = 384 384 device_property_read_bool(dev, "microchip,vref-buffered"); 385 385
+162
drivers/iio/dac/rohm-bd79703.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * BD79703 ROHM Digital to Analog converter 4 + * 5 + * Copyright (c) 2024, ROHM Semiconductor. 6 + */ 7 + 8 + #include <linux/bits.h> 9 + #include <linux/device.h> 10 + #include <linux/module.h> 11 + #include <linux/regmap.h> 12 + #include <linux/regulator/consumer.h> 13 + #include <linux/spi/spi.h> 14 + #include <linux/iio/iio.h> 15 + 16 + #define BD79703_MAX_REGISTER 0xf 17 + #define BD79703_DAC_BITS 8 18 + #define BD79703_REG_OUT_ALL GENMASK(2, 0) 19 + 20 + /* 21 + * The BD79703 uses 12-bit SPI commands. First four bits (high bits) define 22 + * channel(s) which are operated on, and also the mode. The mode can be to set 23 + * a DAC word only, or set DAC word and output. The data-sheet is not very 24 + * specific on how a previously set DAC word can be 'taken in to use'. Thus 25 + * this driver only uses the 'set DAC and output it' -mode. 26 + * 27 + * The BD79703 latches last 12-bits when the chip-select is toggled. Thus we 28 + * can use 16-bit transfers which should be widely supported. To simplify this 29 + * further, we treat the last 8 bits as a value, and first 8 bits as an 30 + * address. This allows us to separate channels/mode by address and treat the 31 + * 8-bit register value as DAC word. The highest 4 bits of address will be 32 + * discarded when the transfer is latched. 33 + */ 34 + static const struct regmap_config bd79703_regmap_config = { 35 + .reg_bits = 8, 36 + .val_bits = 8, 37 + .max_register = BD79703_MAX_REGISTER, 38 + .cache_type = REGCACHE_RBTREE, 39 + }; 40 + 41 + struct bd79703_data { 42 + struct regmap *regmap; 43 + int vfs; 44 + }; 45 + 46 + static int bd79703_read_raw(struct iio_dev *idev, 47 + struct iio_chan_spec const *chan, int *val, 48 + int *val2, long mask) 49 + { 50 + struct bd79703_data *data = iio_priv(idev); 51 + 52 + if (mask != IIO_CHAN_INFO_SCALE) 53 + return -EINVAL; 54 + 55 + *val = data->vfs / 1000; 56 + *val2 = BD79703_DAC_BITS; 57 + 58 + return IIO_VAL_FRACTIONAL_LOG2; 59 + } 60 + 61 + static int bd79703_write_raw(struct iio_dev *idev, 62 + struct iio_chan_spec const *chan, int val, 63 + int val2, long mask) 64 + { 65 + struct bd79703_data *data = iio_priv(idev); 66 + 67 + if (val < 0 || val >= 1 << BD79703_DAC_BITS) 68 + return -EINVAL; 69 + 70 + return regmap_write(data->regmap, chan->channel + 1, val); 71 + }; 72 + 73 + static const struct iio_info bd79703_info = { 74 + .read_raw = bd79703_read_raw, 75 + .write_raw = bd79703_write_raw, 76 + }; 77 + 78 + #define BD79703_CHAN(_chan) { \ 79 + .type = IIO_VOLTAGE, \ 80 + .indexed = 1, \ 81 + .output = 1, \ 82 + .channel = (_chan), \ 83 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 84 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 85 + .address = (_chan), \ 86 + } 87 + 88 + static const struct iio_chan_spec bd79703_channels[] = { 89 + BD79703_CHAN(0), 90 + BD79703_CHAN(1), 91 + BD79703_CHAN(2), 92 + BD79703_CHAN(3), 93 + BD79703_CHAN(4), 94 + BD79703_CHAN(5), 95 + }; 96 + 97 + static int bd79703_probe(struct spi_device *spi) 98 + { 99 + struct device *dev = &spi->dev; 100 + struct bd79703_data *data; 101 + struct iio_dev *idev; 102 + int ret; 103 + 104 + idev = devm_iio_device_alloc(dev, sizeof(*data)); 105 + if (!idev) 106 + return -ENOMEM; 107 + 108 + data = iio_priv(idev); 109 + 110 + data->regmap = devm_regmap_init_spi(spi, &bd79703_regmap_config); 111 + if (IS_ERR(data->regmap)) 112 + return dev_err_probe(dev, PTR_ERR(data->regmap), 113 + "Failed to initialize Regmap\n"); 114 + 115 + ret = devm_regulator_get_enable(dev, "vcc"); 116 + if (ret) 117 + return dev_err_probe(dev, ret, "Failed to enable VCC\n"); 118 + 119 + ret = devm_regulator_get_enable_read_voltage(dev, "vfs"); 120 + if (ret < 0) 121 + return dev_err_probe(dev, ret, "Failed to get Vfs\n"); 122 + 123 + data->vfs = ret; 124 + idev->channels = bd79703_channels; 125 + idev->num_channels = ARRAY_SIZE(bd79703_channels); 126 + idev->modes = INDIO_DIRECT_MODE; 127 + idev->info = &bd79703_info; 128 + idev->name = "bd79703"; 129 + 130 + /* Initialize all to output zero */ 131 + ret = regmap_write(data->regmap, BD79703_REG_OUT_ALL, 0); 132 + if (ret) 133 + return ret; 134 + 135 + return devm_iio_device_register(dev, idev); 136 + } 137 + 138 + static const struct spi_device_id bd79703_id[] = { 139 + { "bd79703", }, 140 + { } 141 + }; 142 + MODULE_DEVICE_TABLE(spi, bd79703_id); 143 + 144 + static const struct of_device_id bd79703_of_match[] = { 145 + { .compatible = "rohm,bd79703", }, 146 + { } 147 + }; 148 + MODULE_DEVICE_TABLE(of, bd79703_of_match); 149 + 150 + static struct spi_driver bd79703_driver = { 151 + .driver = { 152 + .name = "bd79703", 153 + .of_match_table = bd79703_of_match, 154 + }, 155 + .probe = bd79703_probe, 156 + .id_table = bd79703_id, 157 + }; 158 + module_spi_driver(bd79703_driver); 159 + 160 + MODULE_AUTHOR("Matti Vaittinen <mazziesaccount@gmail.com>"); 161 + MODULE_DESCRIPTION("ROHM BD79703 DAC driver"); 162 + MODULE_LICENSE("GPL");
+1 -1
drivers/iio/gyro/adxrs290.c
··· 75 75 /* Ensure correct alignment of timestamp when present */ 76 76 struct { 77 77 s16 channels[3]; 78 - s64 ts __aligned(8); 78 + aligned_s64 ts; 79 79 } buffer; 80 80 }; 81 81
+1 -1
drivers/iio/gyro/bmg160_core.c
··· 99 99 /* Ensure naturally aligned timestamp */ 100 100 struct { 101 101 s16 chans[3]; 102 - s64 timestamp __aligned(8); 102 + aligned_s64 timestamp; 103 103 } scan; 104 104 u32 dps_range; 105 105 int ev_enable_state;
+1 -1
drivers/iio/gyro/itg3200_buffer.c
··· 52 52 */ 53 53 struct { 54 54 __be16 buf[ITG3200_SCAN_ELEMENTS]; 55 - s64 ts __aligned(8); 55 + aligned_s64 ts; 56 56 } scan; 57 57 58 58 int ret = itg3200_read_all_channels(st->i2c, scan.buf);
+1 -1
drivers/iio/gyro/mpu3050-core.c
··· 474 474 int ret; 475 475 struct { 476 476 __be16 chans[4]; 477 - s64 timestamp __aligned(8); 477 + aligned_s64 timestamp; 478 478 } scan; 479 479 s64 timestamp; 480 480 unsigned int datums_from_fifo = 0;
+1 -1
drivers/iio/humidity/am2315.c
··· 35 35 /* Ensure timestamp is naturally aligned */ 36 36 struct { 37 37 s16 chans[2]; 38 - s64 timestamp __aligned(8); 38 + aligned_s64 timestamp; 39 39 } scan; 40 40 }; 41 41
+1 -1
drivers/iio/humidity/hdc100x.c
··· 44 44 /* Ensure natural alignment of timestamp */ 45 45 struct { 46 46 __be16 channels[2]; 47 - s64 ts __aligned(8); 47 + aligned_s64 ts; 48 48 } scan; 49 49 }; 50 50
+1 -1
drivers/iio/humidity/hts221.h
··· 40 40 /* Ensure natural alignment of timestamp */ 41 41 struct { 42 42 __le16 channels[2]; 43 - s64 ts __aligned(8); 43 + aligned_s64 ts; 44 44 } scan; 45 45 }; 46 46
+75
drivers/iio/imu/adis16480.c
··· 878 878 IIO_CHAN_SOFT_TIMESTAMP(17), 879 879 }; 880 880 881 + static const struct iio_chan_spec adis16489_channels[] = { 882 + ADIS16480_GYRO_CHANNEL(X), 883 + ADIS16480_GYRO_CHANNEL(Y), 884 + ADIS16480_GYRO_CHANNEL(Z), 885 + ADIS16480_ACCEL_CHANNEL(X), 886 + ADIS16480_ACCEL_CHANNEL(Y), 887 + ADIS16480_ACCEL_CHANNEL(Z), 888 + ADIS16480_PRESSURE_CHANNEL(), 889 + ADIS16480_TEMP_CHANNEL(), 890 + IIO_CHAN_SOFT_TIMESTAMP(8), 891 + ADIS16480_DELTANG_CHANNEL_NO_SCAN(X), 892 + ADIS16480_DELTANG_CHANNEL_NO_SCAN(Y), 893 + ADIS16480_DELTANG_CHANNEL_NO_SCAN(Z), 894 + ADIS16480_DELTVEL_CHANNEL_NO_SCAN(X), 895 + ADIS16480_DELTVEL_CHANNEL_NO_SCAN(Y), 896 + ADIS16480_DELTVEL_CHANNEL_NO_SCAN(Z), 897 + }; 898 + 881 899 enum adis16480_variant { 882 900 ADIS16375, 883 901 ADIS16480, 884 902 ADIS16485, 903 + ADIS16486, 904 + ADIS16487, 885 905 ADIS16488, 906 + ADIS16489, 886 907 ADIS16490, 887 908 ADIS16495_1, 888 909 ADIS16495_2, ··· 1059 1038 .filter_freqs = adis16480_def_filter_freqs, 1060 1039 .adis_data = ADIS16480_DATA(16485, &adis16485_timeouts, 0, 0), 1061 1040 }, 1041 + [ADIS16486] = { 1042 + .channels = adis16485_channels, 1043 + .num_channels = ARRAY_SIZE(adis16485_channels), 1044 + .gyro_max_val = 22500 << 16, 1045 + .gyro_max_scale = IIO_DEGREE_TO_RAD(450), 1046 + .accel_max_val = IIO_M_S_2_TO_G(20000 << 16), 1047 + .accel_max_scale = 18, 1048 + .temp_scale = 5650, /* 5.65 milli degree Celsius */ 1049 + .deltang_max_val = IIO_DEGREE_TO_RAD(720), 1050 + .deltvel_max_val = 200, 1051 + .int_clk = 2460000, 1052 + .max_dec_rate = 2048, 1053 + .has_sleep_cnt = true, 1054 + .filter_freqs = adis16480_def_filter_freqs, 1055 + .adis_data = ADIS16480_DATA(16486, &adis16480_timeouts, 0, 0), 1056 + }, 1057 + [ADIS16487] = { 1058 + .channels = adis16485_channels, 1059 + .num_channels = ARRAY_SIZE(adis16485_channels), 1060 + .gyro_max_val = 22500 << 16, 1061 + .gyro_max_scale = IIO_DEGREE_TO_RAD(450), 1062 + .accel_max_val = IIO_M_S_2_TO_G(20000 << 16), 1063 + .accel_max_scale = 5, 1064 + .temp_scale = 5650, /* 5.65 milli degree Celsius */ 1065 + .deltang_max_val = IIO_DEGREE_TO_RAD(720), 1066 + .deltvel_max_val = 50, 1067 + .int_clk = 2460000, 1068 + .max_dec_rate = 2048, 1069 + .has_sleep_cnt = true, 1070 + .filter_freqs = adis16480_def_filter_freqs, 1071 + .adis_data = ADIS16480_DATA(16487, &adis16485_timeouts, 0, 0), 1072 + }, 1062 1073 [ADIS16488] = { 1063 1074 .channels = adis16480_channels, 1064 1075 .num_channels = ARRAY_SIZE(adis16480_channels), ··· 1106 1053 .has_sleep_cnt = true, 1107 1054 .filter_freqs = adis16480_def_filter_freqs, 1108 1055 .adis_data = ADIS16480_DATA(16488, &adis16485_timeouts, 0, 0), 1056 + }, 1057 + [ADIS16489] = { 1058 + .channels = adis16489_channels, 1059 + .num_channels = ARRAY_SIZE(adis16489_channels), 1060 + .gyro_max_val = 22500 << 16, 1061 + .gyro_max_scale = IIO_DEGREE_TO_RAD(450), 1062 + .accel_max_val = IIO_M_S_2_TO_G(20000 << 16), 1063 + .accel_max_scale = 18, 1064 + .temp_scale = 5650, /* 5.65 milli degree Celsius */ 1065 + .deltang_max_val = IIO_DEGREE_TO_RAD(720), 1066 + .deltvel_max_val = 200, 1067 + .int_clk = 2460000, 1068 + .max_dec_rate = 2048, 1069 + .has_sleep_cnt = true, 1070 + .filter_freqs = adis16480_def_filter_freqs, 1071 + .adis_data = ADIS16480_DATA(16489, &adis16480_timeouts, 0, 0), 1109 1072 }, 1110 1073 [ADIS16490] = { 1111 1074 .channels = adis16485_channels, ··· 1810 1741 { "adis16375", ADIS16375 }, 1811 1742 { "adis16480", ADIS16480 }, 1812 1743 { "adis16485", ADIS16485 }, 1744 + { "adis16486", ADIS16486 }, 1745 + { "adis16487", ADIS16487 }, 1813 1746 { "adis16488", ADIS16488 }, 1747 + { "adis16489", ADIS16489 }, 1814 1748 { "adis16490", ADIS16490 }, 1815 1749 { "adis16495-1", ADIS16495_1 }, 1816 1750 { "adis16495-2", ADIS16495_2 }, ··· 1835 1763 { .compatible = "adi,adis16375" }, 1836 1764 { .compatible = "adi,adis16480" }, 1837 1765 { .compatible = "adi,adis16485" }, 1766 + { .compatible = "adi,adis16486" }, 1767 + { .compatible = "adi,adis16487" }, 1838 1768 { .compatible = "adi,adis16488" }, 1769 + { .compatible = "adi,adis16489" }, 1839 1770 { .compatible = "adi,adis16490" }, 1840 1771 { .compatible = "adi,adis16495-1" }, 1841 1772 { .compatible = "adi,adis16495-2" },
+1 -1
drivers/iio/imu/bmi323/bmi323_core.c
··· 174 174 __le16 fifo_buff[BMI323_FIFO_FULL_IN_WORDS] __aligned(IIO_DMA_MINALIGN); 175 175 struct { 176 176 __le16 channels[BMI323_CHAN_MAX]; 177 - s64 ts __aligned(8); 177 + aligned_s64 ts; 178 178 } buffer; 179 179 __le16 steps_count[BMI323_STEP_LEN]; 180 180 };
+5 -5
drivers/iio/imu/bno055/bno055.c
··· 207 207 bool sw_reset; 208 208 struct { 209 209 __le16 chans[BNO055_SCAN_CH_COUNT]; 210 - s64 timestamp __aligned(8); 210 + aligned_s64 timestamp; 211 211 } buf; 212 212 struct dentry *debugfs; 213 213 }; ··· 1193 1193 } 1194 1194 1195 1195 static ssize_t calibration_data_read(struct file *filp, struct kobject *kobj, 1196 - struct bin_attribute *bin_attr, char *buf, 1196 + const struct bin_attribute *bin_attr, char *buf, 1197 1197 loff_t pos, size_t count) 1198 1198 { 1199 1199 struct bno055_priv *priv = iio_priv(dev_to_iio_dev(kobj_to_dev(kobj))); ··· 1348 1348 NULL 1349 1349 }; 1350 1350 1351 - static BIN_ATTR_RO(calibration_data, BNO055_CALDATA_LEN); 1351 + static const BIN_ATTR_RO(calibration_data, BNO055_CALDATA_LEN); 1352 1352 1353 - static struct bin_attribute *bno055_bin_attrs[] = { 1353 + static const struct bin_attribute *const bno055_bin_attrs[] = { 1354 1354 &bin_attr_calibration_data, 1355 1355 NULL 1356 1356 }; 1357 1357 1358 1358 static const struct attribute_group bno055_attrs_group = { 1359 1359 .attrs = bno055_attrs, 1360 - .bin_attrs = bno055_bin_attrs, 1360 + .bin_attrs_new = bno055_bin_attrs, 1361 1361 }; 1362 1362 1363 1363 static const struct iio_info bno055_info = {
+1 -1
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
··· 178 178 struct inv_icm42600_accel_buffer { 179 179 struct inv_icm42600_fifo_sensor_data accel; 180 180 int16_t temp; 181 - int64_t timestamp __aligned(8); 181 + aligned_s64 timestamp; 182 182 }; 183 183 184 184 #define INV_ICM42600_SCAN_MASK_ACCEL_3AXIS \
+1 -1
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
··· 78 78 struct inv_icm42600_gyro_buffer { 79 79 struct inv_icm42600_fifo_sensor_data gyro; 80 80 int16_t temp; 81 - int64_t timestamp __aligned(8); 81 + aligned_s64 timestamp; 82 82 }; 83 83 84 84 #define INV_ICM42600_SCAN_MASK_GYRO_3AXIS \
+25
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 277 277 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 278 278 .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME}, 279 279 }, 280 + { .whoami = INV_IAM20380_WHOAMI_VALUE, 281 + .name = "IAM20380", 282 + .reg = &reg_set_6500, 283 + .config = &chip_config_6500, 284 + .fifo_size = 512, 285 + .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 286 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 287 + }, 280 288 { 281 289 .whoami = INV_IAM20680_WHOAMI_VALUE, 282 290 .name = "IAM20680", ··· 1527 1519 INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z), 1528 1520 }; 1529 1521 1522 + static const struct iio_chan_spec inv_iam20380_channels[] = { 1523 + IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP), 1524 + 1525 + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X), 1526 + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y), 1527 + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z), 1528 + }; 1529 + 1530 1530 static const struct iio_chan_spec inv_mpu6500_channels[] = { 1531 1531 IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP), 1532 1532 ··· 1638 1622 (BIT(INV_MPU9X50_SCAN_MAGN_X) \ 1639 1623 | BIT(INV_MPU9X50_SCAN_MAGN_Y) \ 1640 1624 | BIT(INV_MPU9X50_SCAN_MAGN_Z)) 1625 + 1626 + static const unsigned long inv_iam20380_scan_masks[] = { 1627 + INV_MPU6050_SCAN_MASK_3AXIS_GYRO, 1628 + }; 1641 1629 1642 1630 static const unsigned long inv_mpu9x50_scan_masks[] = { 1643 1631 /* 3-axis accel */ ··· 2045 2025 indio_dev->channels = inv_mpu9250_channels; 2046 2026 indio_dev->num_channels = ARRAY_SIZE(inv_mpu9250_channels); 2047 2027 indio_dev->available_scan_masks = inv_mpu9x50_scan_masks; 2028 + break; 2029 + case INV_IAM20380: 2030 + indio_dev->channels = inv_iam20380_channels; 2031 + indio_dev->num_channels = ARRAY_SIZE(inv_iam20380_channels); 2032 + indio_dev->available_scan_masks = inv_iam20380_scan_masks; 2048 2033 break; 2049 2034 case INV_ICM20600: 2050 2035 case INV_ICM20602:
+6
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 34 34 case INV_ICM20689: 35 35 case INV_ICM20600: 36 36 case INV_ICM20602: 37 + case INV_IAM20380: 37 38 case INV_IAM20680: 38 39 /* no i2c auxiliary bus on the chip */ 39 40 return false; ··· 188 187 {"icm20600", INV_ICM20600}, 189 188 {"icm20602", INV_ICM20602}, 190 189 {"icm20690", INV_ICM20690}, 190 + {"iam20380", INV_IAM20380}, 191 191 {"iam20680", INV_IAM20680}, 192 192 {"iam20680hp", INV_IAM20680HP}, 193 193 {"iam20680ht", INV_IAM20680HT}, ··· 253 251 { 254 252 .compatible = "invensense,icm20690", 255 253 .data = (void *)INV_ICM20690 254 + }, 255 + { 256 + .compatible = "invensense,iam20380", 257 + .data = (void *)INV_IAM20380 256 258 }, 257 259 { 258 260 .compatible = "invensense,iam20680",
+2
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 84 84 INV_ICM20600, 85 85 INV_ICM20602, 86 86 INV_ICM20690, 87 + INV_IAM20380, 87 88 INV_IAM20680, 88 89 INV_IAM20680HP, 89 90 INV_IAM20680HT, ··· 426 425 #define INV_ICM20600_WHOAMI_VALUE 0x11 427 426 #define INV_ICM20602_WHOAMI_VALUE 0x12 428 427 #define INV_ICM20690_WHOAMI_VALUE 0x20 428 + #define INV_IAM20380_WHOAMI_VALUE 0xB5 429 429 #define INV_IAM20680_WHOAMI_VALUE 0xA9 430 430 #define INV_IAM20680HP_WHOAMI_VALUE 0xF8 431 431 #define INV_IAM20680HT_WHOAMI_VALUE 0xFA
+5
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 79 79 {"icm20600", INV_ICM20600}, 80 80 {"icm20602", INV_ICM20602}, 81 81 {"icm20690", INV_ICM20690}, 82 + {"iam20380", INV_IAM20380}, 82 83 {"iam20680", INV_IAM20680}, 83 84 {"iam20680hp", INV_IAM20680HP}, 84 85 {"iam20680ht", INV_IAM20680HT}, ··· 140 139 { 141 140 .compatible = "invensense,icm20690", 142 141 .data = (void *)INV_ICM20690 142 + }, 143 + { 144 + .compatible = "invensense,iam20380", 145 + .data = (void *)INV_IAM20380 143 146 }, 144 147 { 145 148 .compatible = "invensense,iam20680",
+9 -9
drivers/iio/imu/st_lsm6dsx/Kconfig
··· 6 6 select IIO_BUFFER 7 7 select IIO_TRIGGERED_BUFFER 8 8 select IIO_KFIFO_BUF 9 - select IIO_ST_LSM6DSX_I2C if (I2C) 10 - select IIO_ST_LSM6DSX_SPI if (SPI_MASTER) 11 - select IIO_ST_LSM6DSX_I3C if (I3C) 12 9 help 13 10 Say yes here to build support for STMicroelectronics LSM6DSx imu 14 11 sensor. ··· 39 42 will be called st_lsm6dsx. 40 43 41 44 config IIO_ST_LSM6DSX_I2C 42 - tristate 43 - depends on IIO_ST_LSM6DSX 45 + tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors I2C Interface" 46 + depends on I2C && IIO_ST_LSM6DSX 47 + default I2C && IIO_ST_LSM6DSX 44 48 select REGMAP_I2C 45 49 46 50 config IIO_ST_LSM6DSX_SPI 47 - tristate 48 - depends on IIO_ST_LSM6DSX 51 + tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors SPI Interface" 52 + depends on SPI_MASTER && IIO_ST_LSM6DSX 53 + default SPI_MASTER && IIO_ST_LSM6DSX 49 54 select REGMAP_SPI 50 55 51 56 config IIO_ST_LSM6DSX_I3C 52 - tristate 53 - depends on IIO_ST_LSM6DSX 57 + tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors I3C Interface" 58 + depends on I3C && IIO_ST_LSM6DSX 59 + default I3C && IIO_ST_LSM6DSX 54 60 select REGMAP_I3C
+3 -3
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c
··· 9 9 #include <linux/mod_devicetable.h> 10 10 #include <linux/module.h> 11 11 #include <linux/i3c/device.h> 12 - #include <linux/i3c/master.h> 13 12 #include <linux/slab.h> 14 13 #include <linux/regmap.h> 15 14 ··· 29 30 }; 30 31 const struct i3c_device_id *id = i3c_device_match_id(i3cdev, 31 32 st_lsm6dsx_i3c_ids); 33 + struct device *dev = i3cdev_to_dev(i3cdev); 32 34 struct regmap *regmap; 33 35 34 36 regmap = devm_regmap_init_i3c(i3cdev, &st_lsm6dsx_i3c_regmap_config); 35 37 if (IS_ERR(regmap)) { 36 - dev_err(&i3cdev->dev, "Failed to register i3c regmap %ld\n", PTR_ERR(regmap)); 38 + dev_err(dev, "Failed to register i3c regmap %ld\n", PTR_ERR(regmap)); 37 39 return PTR_ERR(regmap); 38 40 } 39 41 40 - return st_lsm6dsx_probe(&i3cdev->dev, 0, (uintptr_t)id->data, regmap); 42 + return st_lsm6dsx_probe(dev, 0, (uintptr_t)id->data, regmap); 41 43 } 42 44 43 45 static struct i3c_driver st_lsm6dsx_driver = {
+1 -1
drivers/iio/industrialio-buffer.c
··· 1137 1137 int ret; 1138 1138 1139 1139 indio_dev->active_scan_mask = config->scan_mask; 1140 - indio_dev->scan_timestamp = config->scan_timestamp; 1140 + ACCESS_PRIVATE(indio_dev, scan_timestamp) = config->scan_timestamp; 1141 1141 indio_dev->scan_bytes = config->scan_bytes; 1142 1142 iio_dev_opaque->currentmode = config->mode; 1143 1143
+77
drivers/iio/industrialio-gts-helper.c
··· 915 915 } 916 916 EXPORT_SYMBOL_NS_GPL(iio_gts_find_gain_sel_for_scale_using_time, "IIO_GTS_HELPER"); 917 917 918 + /** 919 + * iio_gts_find_gain_time_sel_for_scale - Fetch gain and time selectors for scale 920 + * @gts: Gain time scale descriptor 921 + * @scale_int: Integral part of the scale (typically val1) 922 + * @scale_nano: Fractional part of the scale (nano or ppb) 923 + * @gain_sel: Pointer to value where gain selector is stored. 924 + * @time_sel: Pointer to value where time selector is stored. 925 + * 926 + * Wrapper around iio_gts_find_gain_for_scale_using_time() to fetch the 927 + * gain and time selectors for a given scale. 928 + * 929 + * Return: 0 on success and -EINVAL on error. 930 + */ 931 + int iio_gts_find_gain_time_sel_for_scale(struct iio_gts *gts, int scale_int, 932 + int scale_nano, int *gain_sel, 933 + int *time_sel) 934 + { 935 + int i, ret; 936 + 937 + for (i = 0; i < gts->num_itime; i++) { 938 + *time_sel = gts->itime_table[i].sel; 939 + ret = iio_gts_find_gain_sel_for_scale_using_time(gts, *time_sel, 940 + scale_int, 941 + scale_nano, 942 + gain_sel); 943 + if (ret) 944 + continue; 945 + 946 + return 0; 947 + } 948 + 949 + return -EINVAL; 950 + } 951 + EXPORT_SYMBOL_NS_GPL(iio_gts_find_gain_time_sel_for_scale, "IIO_GTS_HELPER"); 952 + 918 953 static int iio_gts_get_total_gain(struct iio_gts *gts, int gain, int time) 919 954 { 920 955 const struct iio_itime_sel_mul *itime; ··· 1120 1085 return 0; 1121 1086 } 1122 1087 EXPORT_SYMBOL_NS_GPL(iio_gts_find_new_gain_by_old_gain_time, "IIO_GTS_HELPER"); 1088 + 1089 + /** 1090 + * iio_gts_find_new_gain_by_gain_time_min - compensate for time change 1091 + * @gts: Gain time scale descriptor 1092 + * @old_gain: Previously set gain 1093 + * @old_time: Selector corresponding previously set time 1094 + * @new_time: Selector corresponding new time to be set 1095 + * @new_gain: Pointer to value where new gain is to be written 1096 + * @in_range: Indicate if the @new_gain was in the range of 1097 + * supported gains. 1098 + * 1099 + * Wrapper around iio_gts_find_new_gain_by_old_gain_time() that tries to 1100 + * set an optimal value if no exact match was found, defaulting to the 1101 + * minimum gain to avoid saturations if the optimal value is not in the 1102 + * range of supported gains. 1103 + * 1104 + * Return: 0 on success and a negative value if no gain was found. 1105 + */ 1106 + int iio_gts_find_new_gain_by_gain_time_min(struct iio_gts *gts, int old_gain, 1107 + int old_time, int new_time, 1108 + int *new_gain, bool *in_range) 1109 + { 1110 + int ret; 1111 + 1112 + *in_range = true; 1113 + ret = iio_gts_find_new_gain_by_old_gain_time(gts, old_gain, old_time, 1114 + new_time, new_gain); 1115 + if (*new_gain < 0) 1116 + return -EINVAL; 1117 + 1118 + if (ret) { 1119 + *new_gain = iio_find_closest_gain_low(gts, *new_gain, in_range); 1120 + if (*new_gain < 0) { 1121 + *new_gain = iio_gts_get_min_gain(gts); 1122 + if (*new_gain < 0) 1123 + return -EINVAL; 1124 + } 1125 + } 1126 + 1127 + return 0; 1128 + } 1129 + EXPORT_SYMBOL_NS_GPL(iio_gts_find_new_gain_by_gain_time_min, "IIO_GTS_HELPER"); 1123 1130 1124 1131 MODULE_LICENSE("GPL"); 1125 1132 MODULE_AUTHOR("Matti Vaittinen <mazziesaccount@gmail.com>");
+11
drivers/iio/inkern.c
··· 7 7 #include <linux/err.h> 8 8 #include <linux/export.h> 9 9 #include <linux/minmax.h> 10 + #include <linux/mm.h> 10 11 #include <linux/mutex.h> 11 12 #include <linux/property.h> 12 13 #include <linux/slab.h> ··· 990 989 { 991 990 const struct iio_chan_spec_ext_info *ext_info; 992 991 992 + if (!buf || offset_in_page(buf)) { 993 + pr_err("iio: invalid ext_info read buffer\n"); 994 + return -EINVAL; 995 + } 996 + 993 997 ext_info = iio_lookup_ext_info(chan, attr); 994 998 if (!ext_info) 995 999 return -EINVAL; ··· 1020 1014 1021 1015 ssize_t iio_read_channel_label(struct iio_channel *chan, char *buf) 1022 1016 { 1017 + if (!buf || offset_in_page(buf)) { 1018 + pr_err("iio: invalid label read buffer\n"); 1019 + return -EINVAL; 1020 + } 1021 + 1023 1022 return do_iio_read_channel_label(chan->indio_dev, chan->channel, buf); 1024 1023 } 1025 1024 EXPORT_SYMBOL_GPL(iio_read_channel_label);
+16 -16
drivers/iio/light/Kconfig
··· 329 329 To compile this driver as a module, choose M here: 330 330 the module will be called jsa1212. 331 331 332 - config ROHM_BU27008 333 - tristate "ROHM BU27008 color (RGB+C/IR) sensor" 334 - depends on I2C 335 - select REGMAP_I2C 336 - select IIO_GTS_HELPER 337 - select IIO_BUFFER 338 - select IIO_TRIGGERED_BUFFER 339 - help 340 - Enable support for the ROHM BU27008 color sensor. 341 - The ROHM BU27008 is a sensor with 5 photodiodes (red, green, 342 - blue, clear and IR) with four configurable channels. Red and 343 - green being always available and two out of the rest three 344 - (blue, clear, IR) can be selected to be simultaneously measured. 345 - Typical application is adjusting LCD backlight of TVs, 346 - mobile phones and tablet PCs. 347 - 348 332 config ROHM_BU27034 349 333 tristate "ROHM BU27034 ambient light sensor" 350 334 depends on I2C ··· 474 490 475 491 If built as a dynamically linked module, it will be called 476 492 opt4001. 493 + 494 + config OPT4060 495 + tristate "Texas Instruments OPT4060 RGBW Color Sensor" 496 + depends on I2C 497 + select REGMAP_I2C 498 + select IIO_BUFFER 499 + select IIO_TRIGGERED_BUFFER 500 + help 501 + If you say Y or M here, you get support for Texas Instruments 502 + OPT4060 RGBW Color Sensor. 503 + 504 + If built as a dynamically linked module, it will be called 505 + opt4060. 477 506 478 507 config PA12203001 479 508 tristate "TXC PA12203001 light and proximity sensor" ··· 669 672 config VEML3235 670 673 tristate "VEML3235 ambient light sensor" 671 674 select REGMAP_I2C 675 + select IIO_GTS_HELPER 672 676 depends on I2C 673 677 help 674 678 Say Y here if you want to build a driver for the Vishay VEML3235 ··· 681 683 config VEML6030 682 684 tristate "VEML6030 and VEML6035 ambient light sensors" 683 685 select REGMAP_I2C 686 + select IIO_BUFFER 687 + select IIO_TRIGGERED_BUFFER 684 688 depends on I2C 685 689 help 686 690 Say Y here if you want to build a driver for the Vishay VEML6030
+1 -1
drivers/iio/light/Makefile
··· 42 42 obj-$(CONFIG_NOA1305) += noa1305.o 43 43 obj-$(CONFIG_OPT3001) += opt3001.o 44 44 obj-$(CONFIG_OPT4001) += opt4001.o 45 + obj-$(CONFIG_OPT4060) += opt4060.o 45 46 obj-$(CONFIG_PA12203001) += pa12203001.o 46 - obj-$(CONFIG_ROHM_BU27008) += rohm-bu27008.o 47 47 obj-$(CONFIG_ROHM_BU27034) += rohm-bu27034.o 48 48 obj-$(CONFIG_RPR0521) += rpr0521.o 49 49 obj-$(CONFIG_SI1133) += si1133.o
+1 -1
drivers/iio/light/adjd_s311.c
··· 56 56 struct i2c_client *client; 57 57 struct { 58 58 s16 chans[4]; 59 - s64 ts __aligned(8); 59 + aligned_s64 ts; 60 60 } scan; 61 61 }; 62 62
+1 -1
drivers/iio/light/as73211.c
··· 636 636 struct as73211_data *data = iio_priv(indio_dev); 637 637 struct { 638 638 __le16 chan[4]; 639 - s64 ts __aligned(8); 639 + aligned_s64 ts; 640 640 } scan; 641 641 int data_result, ret; 642 642
+1 -1
drivers/iio/light/bh1745.c
··· 739 739 struct bh1745_data *data = iio_priv(indio_dev); 740 740 struct { 741 741 u16 chans[4]; 742 - s64 timestamp __aligned(8); 742 + aligned_s64 timestamp; 743 743 } scan; 744 744 u16 value; 745 745 int ret;
+9 -9
drivers/iio/light/cm3232.c
··· 89 89 90 90 chip->als_info = &cm3232_als_info_default; 91 91 92 + /* Disable and reset device */ 93 + chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET; 94 + ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD, 95 + chip->regs_cmd); 96 + if (ret < 0) { 97 + dev_err(&chip->client->dev, "Error writing reg_cmd\n"); 98 + return ret; 99 + } 100 + 92 101 /* Identify device */ 93 102 ret = i2c_smbus_read_word_data(client, CM3232_REG_ADDR_ID); 94 103 if (ret < 0) { ··· 107 98 108 99 if ((ret & 0xFF) != chip->als_info->hw_id) 109 100 return -ENODEV; 110 - 111 - /* Disable and reset device */ 112 - chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET; 113 - ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD, 114 - chip->regs_cmd); 115 - if (ret < 0) { 116 - dev_err(&chip->client->dev, "Error writing reg_cmd\n"); 117 - return ret; 118 - } 119 101 120 102 /* Register default value */ 121 103 chip->regs_cmd = chip->als_info->regs_cmd_default;
+1 -1
drivers/iio/light/isl29125.c
··· 54 54 /* Ensure timestamp is naturally aligned */ 55 55 struct { 56 56 u16 chans[3]; 57 - s64 timestamp __aligned(8); 57 + aligned_s64 timestamp; 58 58 } scan; 59 59 }; 60 60
+1 -1
drivers/iio/light/ltr501.c
··· 1280 1280 struct ltr501_data *data = iio_priv(indio_dev); 1281 1281 struct { 1282 1282 u16 channels[3]; 1283 - s64 ts __aligned(8); 1283 + aligned_s64 ts; 1284 1284 } scan; 1285 1285 __le16 als_buf[2]; 1286 1286 u8 mask = 0;
+1 -1
drivers/iio/light/max44000.c
··· 78 78 /* Ensure naturally aligned timestamp */ 79 79 struct { 80 80 u16 channels[2]; 81 - s64 ts __aligned(8); 81 + aligned_s64 ts; 82 82 } scan; 83 83 }; 84 84
+1343
drivers/iio/light/opt4060.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2024 Axis Communications AB 4 + * 5 + * Datasheet: https://www.ti.com/lit/gpn/opt4060 6 + * 7 + * Device driver for the Texas Instruments OPT4060 RGBW Color Sensor. 8 + */ 9 + 10 + #include <linux/bitfield.h> 11 + #include <linux/i2c.h> 12 + #include <linux/iio/iio.h> 13 + #include <linux/math64.h> 14 + #include <linux/units.h> 15 + #include <linux/limits.h> 16 + #include <linux/module.h> 17 + #include <linux/property.h> 18 + #include <linux/regmap.h> 19 + #include <linux/mutex.h> 20 + #include <linux/regulator/consumer.h> 21 + #include <linux/iio/events.h> 22 + #include <linux/iio/trigger.h> 23 + #include <linux/iio/trigger_consumer.h> 24 + #include <linux/iio/triggered_buffer.h> 25 + 26 + /* OPT4060 register set */ 27 + #define OPT4060_RED_MSB 0x00 28 + #define OPT4060_RED_LSB 0x01 29 + #define OPT4060_GREEN_MSB 0x02 30 + #define OPT4060_GREEN_LSB 0x03 31 + #define OPT4060_BLUE_MSB 0x04 32 + #define OPT4060_BLUE_LSB 0x05 33 + #define OPT4060_CLEAR_MSB 0x06 34 + #define OPT4060_CLEAR_LSB 0x07 35 + #define OPT4060_THRESHOLD_LOW 0x08 36 + #define OPT4060_THRESHOLD_HIGH 0x09 37 + #define OPT4060_CTRL 0x0a 38 + #define OPT4060_INT_CTRL 0x0b 39 + #define OPT4060_RES_CTRL 0x0c 40 + #define OPT4060_DEVICE_ID 0x11 41 + 42 + /* OPT4060 register mask */ 43 + #define OPT4060_EXPONENT_MASK GENMASK(15, 12) 44 + #define OPT4060_MSB_MASK GENMASK(11, 0) 45 + #define OPT4060_LSB_MASK GENMASK(15, 8) 46 + #define OPT4060_COUNTER_MASK GENMASK(7, 4) 47 + #define OPT4060_CRC_MASK GENMASK(3, 0) 48 + 49 + /* OPT4060 device id mask */ 50 + #define OPT4060_DEVICE_ID_MASK GENMASK(11, 0) 51 + 52 + /* OPT4060 control register masks */ 53 + #define OPT4060_CTRL_QWAKE_MASK BIT(15) 54 + #define OPT4060_CTRL_RANGE_MASK GENMASK(13, 10) 55 + #define OPT4060_CTRL_CONV_TIME_MASK GENMASK(9, 6) 56 + #define OPT4060_CTRL_OPER_MODE_MASK GENMASK(5, 4) 57 + #define OPT4060_CTRL_LATCH_MASK BIT(3) 58 + #define OPT4060_CTRL_INT_POL_MASK BIT(2) 59 + #define OPT4060_CTRL_FAULT_COUNT_MASK GENMASK(1, 0) 60 + 61 + /* OPT4060 interrupt control register masks */ 62 + #define OPT4060_INT_CTRL_THRESH_SEL GENMASK(6, 5) 63 + #define OPT4060_INT_CTRL_OUTPUT BIT(4) 64 + #define OPT4060_INT_CTRL_INT_CFG GENMASK(3, 2) 65 + #define OPT4060_INT_CTRL_THRESHOLD 0x0 66 + #define OPT4060_INT_CTRL_NEXT_CH 0x1 67 + #define OPT4060_INT_CTRL_ALL_CH 0x3 68 + 69 + /* OPT4060 result control register masks */ 70 + #define OPT4060_RES_CTRL_OVERLOAD BIT(3) 71 + #define OPT4060_RES_CTRL_CONV_READY BIT(2) 72 + #define OPT4060_RES_CTRL_FLAG_H BIT(1) 73 + #define OPT4060_RES_CTRL_FLAG_L BIT(0) 74 + 75 + /* OPT4060 constants */ 76 + #define OPT4060_DEVICE_ID_VAL 0x821 77 + 78 + /* OPT4060 operating modes */ 79 + #define OPT4060_CTRL_OPER_MODE_OFF 0x0 80 + #define OPT4060_CTRL_OPER_MODE_FORCED 0x1 81 + #define OPT4060_CTRL_OPER_MODE_ONE_SHOT 0x2 82 + #define OPT4060_CTRL_OPER_MODE_CONTINUOUS 0x3 83 + 84 + /* OPT4060 conversion control register definitions */ 85 + #define OPT4060_CTRL_CONVERSION_0_6MS 0x0 86 + #define OPT4060_CTRL_CONVERSION_1MS 0x1 87 + #define OPT4060_CTRL_CONVERSION_1_8MS 0x2 88 + #define OPT4060_CTRL_CONVERSION_3_4MS 0x3 89 + #define OPT4060_CTRL_CONVERSION_6_5MS 0x4 90 + #define OPT4060_CTRL_CONVERSION_12_7MS 0x5 91 + #define OPT4060_CTRL_CONVERSION_25MS 0x6 92 + #define OPT4060_CTRL_CONVERSION_50MS 0x7 93 + #define OPT4060_CTRL_CONVERSION_100MS 0x8 94 + #define OPT4060_CTRL_CONVERSION_200MS 0x9 95 + #define OPT4060_CTRL_CONVERSION_400MS 0xa 96 + #define OPT4060_CTRL_CONVERSION_800MS 0xb 97 + 98 + /* OPT4060 fault count control register definitions */ 99 + #define OPT4060_CTRL_FAULT_COUNT_1 0x0 100 + #define OPT4060_CTRL_FAULT_COUNT_2 0x1 101 + #define OPT4060_CTRL_FAULT_COUNT_4 0x2 102 + #define OPT4060_CTRL_FAULT_COUNT_8 0x3 103 + 104 + /* OPT4060 scale light level range definitions */ 105 + #define OPT4060_CTRL_LIGHT_SCALE_AUTO 12 106 + 107 + /* OPT4060 default values */ 108 + #define OPT4060_DEFAULT_CONVERSION_TIME OPT4060_CTRL_CONVERSION_50MS 109 + 110 + /* 111 + * enum opt4060_chan_type - OPT4060 channel types 112 + * @OPT4060_RED: Red channel. 113 + * @OPT4060_GREEN: Green channel. 114 + * @OPT4060_BLUE: Blue channel. 115 + * @OPT4060_CLEAR: Clear (white) channel. 116 + * @OPT4060_ILLUM: Calculated illuminance channel. 117 + * @OPT4060_NUM_CHANS: Number of channel types. 118 + */ 119 + enum opt4060_chan_type { 120 + OPT4060_RED, 121 + OPT4060_GREEN, 122 + OPT4060_BLUE, 123 + OPT4060_CLEAR, 124 + OPT4060_ILLUM, 125 + OPT4060_NUM_CHANS 126 + }; 127 + 128 + struct opt4060_chip { 129 + struct regmap *regmap; 130 + struct device *dev; 131 + struct iio_trigger *trig; 132 + u8 int_time; 133 + int irq; 134 + /* 135 + * Mutex for protecting sensor irq settings. Switching between interrupt 136 + * on each sample and on thresholds needs to be synchronized. 137 + */ 138 + struct mutex irq_setting_lock; 139 + /* 140 + * Mutex for protecting event enabling. 141 + */ 142 + struct mutex event_enabling_lock; 143 + struct completion completion; 144 + bool thresh_event_lo_active; 145 + bool thresh_event_hi_active; 146 + }; 147 + 148 + struct opt4060_channel_factor { 149 + u32 mul; 150 + u32 div; 151 + }; 152 + 153 + static const int opt4060_int_time_available[][2] = { 154 + { 0, 600 }, 155 + { 0, 1000 }, 156 + { 0, 1800 }, 157 + { 0, 3400 }, 158 + { 0, 6500 }, 159 + { 0, 12700 }, 160 + { 0, 25000 }, 161 + { 0, 50000 }, 162 + { 0, 100000 }, 163 + { 0, 200000 }, 164 + { 0, 400000 }, 165 + { 0, 800000 }, 166 + }; 167 + 168 + /* 169 + * Conversion time is integration time + time to set register 170 + * this is used as integration time. 171 + */ 172 + static const int opt4060_int_time_reg[][2] = { 173 + { 600, OPT4060_CTRL_CONVERSION_0_6MS }, 174 + { 1000, OPT4060_CTRL_CONVERSION_1MS }, 175 + { 1800, OPT4060_CTRL_CONVERSION_1_8MS }, 176 + { 3400, OPT4060_CTRL_CONVERSION_3_4MS }, 177 + { 6500, OPT4060_CTRL_CONVERSION_6_5MS }, 178 + { 12700, OPT4060_CTRL_CONVERSION_12_7MS }, 179 + { 25000, OPT4060_CTRL_CONVERSION_25MS }, 180 + { 50000, OPT4060_CTRL_CONVERSION_50MS }, 181 + { 100000, OPT4060_CTRL_CONVERSION_100MS }, 182 + { 200000, OPT4060_CTRL_CONVERSION_200MS }, 183 + { 400000, OPT4060_CTRL_CONVERSION_400MS }, 184 + { 800000, OPT4060_CTRL_CONVERSION_800MS }, 185 + }; 186 + 187 + static int opt4060_als_time_to_index(const u32 als_integration_time) 188 + { 189 + int i; 190 + 191 + for (i = 0; i < ARRAY_SIZE(opt4060_int_time_available); i++) { 192 + if (als_integration_time == opt4060_int_time_available[i][1]) 193 + return i; 194 + } 195 + 196 + return -EINVAL; 197 + } 198 + 199 + static u8 opt4060_calculate_crc(u8 exp, u32 mantissa, u8 count) 200 + { 201 + u8 crc; 202 + 203 + /* 204 + * Calculates a 4-bit CRC from a 20-bit mantissa, 4-bit exponent and a 4-bit counter. 205 + * crc[0] = XOR(mantissa[19:0], exp[3:0], count[3:0]) 206 + * crc[1] = XOR(mantissa[1,3,5,7,9,11,13,15,17,19], exp[1,3], count[1,3]) 207 + * crc[2] = XOR(mantissa[3,7,11,15,19], exp[3], count[3]) 208 + * crc[3] = XOR(mantissa[3,11,19]) 209 + */ 210 + crc = (hweight32(mantissa) + hweight32(exp) + hweight32(count)) % 2; 211 + crc |= ((hweight32(mantissa & 0xAAAAA) + hweight32(exp & 0xA) 212 + + hweight32(count & 0xA)) % 2) << 1; 213 + crc |= ((hweight32(mantissa & 0x88888) + hweight32(exp & 0x8) 214 + + hweight32(count & 0x8)) % 2) << 2; 215 + crc |= (hweight32(mantissa & 0x80808) % 2) << 3; 216 + 217 + return crc; 218 + } 219 + 220 + static int opt4060_set_int_state(struct opt4060_chip *chip, u32 state) 221 + { 222 + int ret; 223 + unsigned int regval; 224 + 225 + guard(mutex)(&chip->irq_setting_lock); 226 + 227 + regval = FIELD_PREP(OPT4060_INT_CTRL_INT_CFG, state); 228 + ret = regmap_update_bits(chip->regmap, OPT4060_INT_CTRL, 229 + OPT4060_INT_CTRL_INT_CFG, regval); 230 + if (ret) 231 + dev_err(chip->dev, "Failed to set interrupt config\n"); 232 + return ret; 233 + } 234 + 235 + static int opt4060_set_sampling_mode(struct opt4060_chip *chip, 236 + bool continuous) 237 + { 238 + unsigned int reg; 239 + int ret; 240 + 241 + ret = regmap_read(chip->regmap, OPT4060_CTRL, &reg); 242 + if (ret < 0) { 243 + dev_err(chip->dev, "Failed to read ctrl register\n"); 244 + return ret; 245 + } 246 + reg &= ~OPT4060_CTRL_OPER_MODE_MASK; 247 + if (continuous) 248 + reg |= FIELD_PREP(OPT4060_CTRL_OPER_MODE_MASK, 249 + OPT4060_CTRL_OPER_MODE_CONTINUOUS); 250 + else 251 + reg |= FIELD_PREP(OPT4060_CTRL_OPER_MODE_MASK, 252 + OPT4060_CTRL_OPER_MODE_ONE_SHOT); 253 + 254 + /* 255 + * Trigger a new conversions by writing to CRTL register. It is not 256 + * possible to use regmap_update_bits() since that will only write when 257 + * data is modified. 258 + */ 259 + ret = regmap_write(chip->regmap, OPT4060_CTRL, reg); 260 + if (ret) 261 + dev_err(chip->dev, "Failed to set ctrl register\n"); 262 + return ret; 263 + } 264 + 265 + static bool opt4060_event_active(struct opt4060_chip *chip) 266 + { 267 + return chip->thresh_event_lo_active || chip->thresh_event_hi_active; 268 + } 269 + 270 + static int opt4060_set_state_common(struct opt4060_chip *chip, 271 + bool continuous_sampling, 272 + bool continuous_irq) 273 + { 274 + int ret = 0; 275 + 276 + /* It is important to setup irq before sampling to avoid missing samples. */ 277 + if (continuous_irq) 278 + ret = opt4060_set_int_state(chip, OPT4060_INT_CTRL_ALL_CH); 279 + else 280 + ret = opt4060_set_int_state(chip, OPT4060_INT_CTRL_THRESHOLD); 281 + if (ret) { 282 + dev_err(chip->dev, "Failed to set irq state.\n"); 283 + return ret; 284 + } 285 + 286 + if (continuous_sampling || opt4060_event_active(chip)) 287 + ret = opt4060_set_sampling_mode(chip, true); 288 + else 289 + ret = opt4060_set_sampling_mode(chip, false); 290 + if (ret) 291 + dev_err(chip->dev, "Failed to set sampling state.\n"); 292 + return ret; 293 + } 294 + 295 + /* 296 + * Function for setting the driver state for sampling and irq. Either direct 297 + * mode of buffer mode will be claimed during the transition to prevent races 298 + * between sysfs read, buffer or events. 299 + */ 300 + static int opt4060_set_driver_state(struct iio_dev *indio_dev, 301 + bool continuous_sampling, 302 + bool continuous_irq) 303 + { 304 + struct opt4060_chip *chip = iio_priv(indio_dev); 305 + int ret = 0; 306 + any_mode_retry: 307 + if (iio_device_claim_buffer_mode(indio_dev)) { 308 + /* 309 + * This one is a *bit* hacky. If we cannot claim buffer mode, 310 + * then try direct mode so that we make sure things cannot 311 + * concurrently change. And we just keep trying until we get one 312 + * of the modes... 313 + */ 314 + if (iio_device_claim_direct_mode(indio_dev)) 315 + goto any_mode_retry; 316 + /* 317 + * This path means that we managed to claim direct mode. In 318 + * this case the buffer isn't enabled and it's okay to leave 319 + * continuous mode for sampling and/or irq. 320 + */ 321 + ret = opt4060_set_state_common(chip, continuous_sampling, 322 + continuous_irq); 323 + iio_device_release_direct_mode(indio_dev); 324 + } else { 325 + /* 326 + * This path means that we managed to claim buffer mode. In 327 + * this case the buffer is enabled and irq and sampling must go 328 + * to or remain continuous, but only if the trigger is from this 329 + * device. 330 + */ 331 + if (!iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) 332 + ret = opt4060_set_state_common(chip, true, true); 333 + else 334 + ret = opt4060_set_state_common(chip, continuous_sampling, 335 + continuous_irq); 336 + iio_device_release_buffer_mode(indio_dev); 337 + } 338 + return ret; 339 + } 340 + 341 + /* 342 + * This function is called with framework mutex locked. 343 + */ 344 + static int opt4060_trigger_set_state(struct iio_trigger *trig, bool state) 345 + { 346 + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 347 + struct opt4060_chip *chip = iio_priv(indio_dev); 348 + 349 + return opt4060_set_state_common(chip, state, state); 350 + } 351 + 352 + static int opt4060_read_raw_value(struct opt4060_chip *chip, 353 + unsigned long address, u32 *raw) 354 + { 355 + int ret; 356 + u16 result[2]; 357 + u32 mantissa_raw; 358 + u16 msb, lsb; 359 + u8 exp, count, crc, calc_crc; 360 + 361 + ret = regmap_bulk_read(chip->regmap, address, result, 2); 362 + if (ret) { 363 + dev_err(chip->dev, "Reading channel data failed\n"); 364 + return ret; 365 + } 366 + exp = FIELD_GET(OPT4060_EXPONENT_MASK, result[0]); 367 + msb = FIELD_GET(OPT4060_MSB_MASK, result[0]); 368 + count = FIELD_GET(OPT4060_COUNTER_MASK, result[1]); 369 + crc = FIELD_GET(OPT4060_CRC_MASK, result[1]); 370 + lsb = FIELD_GET(OPT4060_LSB_MASK, result[1]); 371 + mantissa_raw = (msb << 8) + lsb; 372 + calc_crc = opt4060_calculate_crc(exp, mantissa_raw, count); 373 + if (calc_crc != crc) 374 + return -EIO; 375 + *raw = mantissa_raw << exp; 376 + return 0; 377 + } 378 + 379 + static int opt4060_trigger_new_samples(struct iio_dev *indio_dev) 380 + { 381 + struct opt4060_chip *chip = iio_priv(indio_dev); 382 + int ret; 383 + 384 + /* 385 + * The conversion time should be 500us startup time plus the integration time 386 + * times the number of channels. An exact timeout isn't critical, it's better 387 + * not to get incorrect errors in the log. Setting the timeout to double the 388 + * theoretical time plus and extra 100ms margin. 389 + */ 390 + unsigned int timeout_us = (500 + OPT4060_NUM_CHANS * 391 + opt4060_int_time_reg[chip->int_time][0]) * 2 + 100000; 392 + 393 + /* Setting the state in one shot mode with irq on each sample. */ 394 + ret = opt4060_set_driver_state(indio_dev, false, true); 395 + if (ret) 396 + return ret; 397 + 398 + if (chip->irq) { 399 + guard(mutex)(&chip->irq_setting_lock); 400 + reinit_completion(&chip->completion); 401 + if (wait_for_completion_timeout(&chip->completion, 402 + usecs_to_jiffies(timeout_us)) == 0) { 403 + dev_err(chip->dev, "Completion timed out.\n"); 404 + return -ETIME; 405 + } 406 + } else { 407 + unsigned int ready; 408 + 409 + ret = regmap_read_poll_timeout(chip->regmap, OPT4060_RES_CTRL, 410 + ready, (ready & OPT4060_RES_CTRL_CONV_READY), 411 + 1000, timeout_us); 412 + if (ret) 413 + dev_err(chip->dev, "Conversion ready did not finish within timeout.\n"); 414 + } 415 + /* Setting the state in one shot mode with irq on thresholds. */ 416 + return opt4060_set_driver_state(indio_dev, false, false); 417 + } 418 + 419 + static int opt4060_read_chan_raw(struct iio_dev *indio_dev, 420 + struct iio_chan_spec const *chan, int *val) 421 + { 422 + struct opt4060_chip *chip = iio_priv(indio_dev); 423 + u32 adc_raw; 424 + int ret; 425 + 426 + ret = opt4060_trigger_new_samples(indio_dev); 427 + if (ret) { 428 + dev_err(chip->dev, "Failed to trigger new samples.\n"); 429 + return ret; 430 + } 431 + 432 + ret = opt4060_read_raw_value(chip, chan->address, &adc_raw); 433 + if (ret) { 434 + dev_err(chip->dev, "Reading raw channel data failed.\n"); 435 + return ret; 436 + } 437 + *val = adc_raw; 438 + return IIO_VAL_INT; 439 + } 440 + 441 + /* 442 + * Returns the scale values used for red, green and blue. Scales the raw value 443 + * so that for a particular test light source, typically white, the measurement 444 + * intensity is the same across different color channels. 445 + */ 446 + static int opt4060_get_chan_scale(struct iio_dev *indio_dev, 447 + struct iio_chan_spec const *chan, 448 + int *val, int *val2) 449 + { 450 + struct opt4060_chip *chip = iio_priv(indio_dev); 451 + 452 + switch (chan->scan_index) { 453 + case OPT4060_RED: 454 + /* 2.4 */ 455 + *val = 2; 456 + *val2 = 400000; 457 + break; 458 + case OPT4060_GREEN: 459 + /* 1.0 */ 460 + *val = 1; 461 + *val2 = 0; 462 + break; 463 + case OPT4060_BLUE: 464 + /* 1.3 */ 465 + *val = 1; 466 + *val2 = 300000; 467 + break; 468 + default: 469 + dev_err(chip->dev, "Unexpected channel index.\n"); 470 + return -EINVAL; 471 + } 472 + return IIO_VAL_INT_PLUS_MICRO; 473 + } 474 + 475 + static int opt4060_calc_illuminance(struct opt4060_chip *chip, int *val) 476 + { 477 + u32 lux_raw; 478 + int ret; 479 + 480 + /* The green wide spectral channel is used for illuminance. */ 481 + ret = opt4060_read_raw_value(chip, OPT4060_GREEN_MSB, &lux_raw); 482 + if (ret) { 483 + dev_err(chip->dev, "Reading raw channel data failed\n"); 484 + return ret; 485 + } 486 + 487 + /* Illuminance is calculated by ADC_RAW * 2.15e-3. */ 488 + *val = DIV_U64_ROUND_CLOSEST((u64)(lux_raw * 215), 1000); 489 + return ret; 490 + } 491 + 492 + static int opt4060_read_illuminance(struct iio_dev *indio_dev, 493 + struct iio_chan_spec const *chan, 494 + int *val) 495 + { 496 + struct opt4060_chip *chip = iio_priv(indio_dev); 497 + int ret; 498 + 499 + ret = opt4060_trigger_new_samples(indio_dev); 500 + if (ret) { 501 + dev_err(chip->dev, "Failed to trigger new samples.\n"); 502 + return ret; 503 + } 504 + ret = opt4060_calc_illuminance(chip, val); 505 + if (ret) { 506 + dev_err(chip->dev, "Failed to calculate illuminance.\n"); 507 + return ret; 508 + } 509 + 510 + return IIO_VAL_INT; 511 + } 512 + 513 + static int opt4060_set_int_time(struct opt4060_chip *chip) 514 + { 515 + unsigned int regval; 516 + int ret; 517 + 518 + regval = FIELD_PREP(OPT4060_CTRL_CONV_TIME_MASK, chip->int_time); 519 + ret = regmap_update_bits(chip->regmap, OPT4060_CTRL, 520 + OPT4060_CTRL_CONV_TIME_MASK, regval); 521 + if (ret) 522 + dev_err(chip->dev, "Failed to set integration time.\n"); 523 + 524 + return ret; 525 + } 526 + 527 + static int opt4060_power_down(struct opt4060_chip *chip) 528 + { 529 + int ret; 530 + 531 + ret = regmap_clear_bits(chip->regmap, OPT4060_CTRL, OPT4060_CTRL_OPER_MODE_MASK); 532 + if (ret) 533 + dev_err(chip->dev, "Failed to power down\n"); 534 + 535 + return ret; 536 + } 537 + 538 + static void opt4060_chip_off_action(void *chip) 539 + { 540 + opt4060_power_down(chip); 541 + } 542 + 543 + #define _OPT4060_COLOR_CHANNEL(_color, _mask, _ev_spec, _num_ev_spec) \ 544 + { \ 545 + .type = IIO_INTENSITY, \ 546 + .modified = 1, \ 547 + .channel2 = IIO_MOD_LIGHT_##_color, \ 548 + .info_mask_separate = _mask, \ 549 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), \ 550 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), \ 551 + .address = OPT4060_##_color##_MSB, \ 552 + .scan_index = OPT4060_##_color, \ 553 + .scan_type = { \ 554 + .sign = 'u', \ 555 + .realbits = 32, \ 556 + .storagebits = 32, \ 557 + .endianness = IIO_CPU, \ 558 + }, \ 559 + .event_spec = _ev_spec, \ 560 + .num_event_specs = _num_ev_spec, \ 561 + } 562 + 563 + #define OPT4060_COLOR_CHANNEL(_color, _mask) \ 564 + _OPT4060_COLOR_CHANNEL(_color, _mask, opt4060_event_spec, \ 565 + ARRAY_SIZE(opt4060_event_spec)) \ 566 + 567 + #define OPT4060_COLOR_CHANNEL_NO_EVENTS(_color, _mask) \ 568 + _OPT4060_COLOR_CHANNEL(_color, _mask, NULL, 0) \ 569 + 570 + #define OPT4060_LIGHT_CHANNEL(_channel) \ 571 + { \ 572 + .type = IIO_LIGHT, \ 573 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 574 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), \ 575 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), \ 576 + .scan_index = OPT4060_##_channel, \ 577 + .scan_type = { \ 578 + .sign = 'u', \ 579 + .realbits = 32, \ 580 + .storagebits = 32, \ 581 + .endianness = IIO_CPU, \ 582 + }, \ 583 + } 584 + 585 + static const struct iio_event_spec opt4060_event_spec[] = { 586 + { 587 + .type = IIO_EV_TYPE_THRESH, 588 + .dir = IIO_EV_DIR_RISING, 589 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 590 + BIT(IIO_EV_INFO_ENABLE), 591 + }, { 592 + .type = IIO_EV_TYPE_THRESH, 593 + .dir = IIO_EV_DIR_FALLING, 594 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 595 + BIT(IIO_EV_INFO_ENABLE), 596 + }, { 597 + .type = IIO_EV_TYPE_THRESH, 598 + .dir = IIO_EV_DIR_EITHER, 599 + .mask_separate = BIT(IIO_EV_INFO_PERIOD), 600 + }, 601 + }; 602 + 603 + static const struct iio_chan_spec opt4060_channels[] = { 604 + OPT4060_COLOR_CHANNEL(RED, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE)), 605 + OPT4060_COLOR_CHANNEL(GREEN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE)), 606 + OPT4060_COLOR_CHANNEL(BLUE, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE)), 607 + OPT4060_COLOR_CHANNEL(CLEAR, BIT(IIO_CHAN_INFO_RAW)), 608 + OPT4060_LIGHT_CHANNEL(ILLUM), 609 + IIO_CHAN_SOFT_TIMESTAMP(OPT4060_NUM_CHANS), 610 + }; 611 + 612 + static const struct iio_chan_spec opt4060_channels_no_events[] = { 613 + OPT4060_COLOR_CHANNEL_NO_EVENTS(RED, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE)), 614 + OPT4060_COLOR_CHANNEL_NO_EVENTS(GREEN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE)), 615 + OPT4060_COLOR_CHANNEL_NO_EVENTS(BLUE, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE)), 616 + OPT4060_COLOR_CHANNEL_NO_EVENTS(CLEAR, BIT(IIO_CHAN_INFO_RAW)), 617 + OPT4060_LIGHT_CHANNEL(ILLUM), 618 + IIO_CHAN_SOFT_TIMESTAMP(OPT4060_NUM_CHANS), 619 + }; 620 + 621 + static int opt4060_read_raw(struct iio_dev *indio_dev, 622 + struct iio_chan_spec const *chan, 623 + int *val, int *val2, long mask) 624 + { 625 + struct opt4060_chip *chip = iio_priv(indio_dev); 626 + 627 + switch (mask) { 628 + case IIO_CHAN_INFO_RAW: 629 + return opt4060_read_chan_raw(indio_dev, chan, val); 630 + case IIO_CHAN_INFO_SCALE: 631 + return opt4060_get_chan_scale(indio_dev, chan, val, val2); 632 + case IIO_CHAN_INFO_PROCESSED: 633 + return opt4060_read_illuminance(indio_dev, chan, val); 634 + case IIO_CHAN_INFO_INT_TIME: 635 + *val = 0; 636 + *val2 = opt4060_int_time_reg[chip->int_time][0]; 637 + return IIO_VAL_INT_PLUS_MICRO; 638 + default: 639 + return -EINVAL; 640 + } 641 + } 642 + 643 + static int opt4060_write_raw(struct iio_dev *indio_dev, 644 + struct iio_chan_spec const *chan, 645 + int val, int val2, long mask) 646 + { 647 + struct opt4060_chip *chip = iio_priv(indio_dev); 648 + int int_time; 649 + 650 + switch (mask) { 651 + case IIO_CHAN_INFO_INT_TIME: 652 + int_time = opt4060_als_time_to_index(val2); 653 + if (int_time < 0) 654 + return int_time; 655 + chip->int_time = int_time; 656 + return opt4060_set_int_time(chip); 657 + default: 658 + return -EINVAL; 659 + } 660 + } 661 + 662 + static int opt4060_write_raw_get_fmt(struct iio_dev *indio_dev, 663 + struct iio_chan_spec const *chan, 664 + long mask) 665 + { 666 + switch (mask) { 667 + case IIO_CHAN_INFO_INT_TIME: 668 + return IIO_VAL_INT_PLUS_MICRO; 669 + default: 670 + return -EINVAL; 671 + } 672 + } 673 + 674 + static u32 opt4060_calc_th_reg(u32 adc_val) 675 + { 676 + u32 th_val, th_exp, bits; 677 + /* 678 + * The threshold registers take 4 bits of exponent and 12 bits of data 679 + * ADC = TH_VAL << (8 + TH_EXP) 680 + */ 681 + bits = fls(adc_val); 682 + 683 + if (bits > 31) 684 + th_exp = 11; /* Maximum exponent */ 685 + else if (bits > 20) 686 + th_exp = bits - 20; 687 + else 688 + th_exp = 0; 689 + th_val = (adc_val >> (8 + th_exp)) & 0xfff; 690 + 691 + return (th_exp << 12) + th_val; 692 + } 693 + 694 + static u32 opt4060_calc_val_from_th_reg(u32 th_reg) 695 + { 696 + /* 697 + * The threshold registers take 4 bits of exponent and 12 bits of data 698 + * ADC = TH_VAL << (8 + TH_EXP) 699 + */ 700 + u32 th_val, th_exp; 701 + 702 + th_exp = (th_reg >> 12) & 0xf; 703 + th_val = th_reg & 0xfff; 704 + 705 + return th_val << (8 + th_exp); 706 + } 707 + 708 + static int opt4060_read_available(struct iio_dev *indio_dev, 709 + struct iio_chan_spec const *chan, 710 + const int **vals, int *type, int *length, 711 + long mask) 712 + { 713 + switch (mask) { 714 + case IIO_CHAN_INFO_INT_TIME: 715 + *length = ARRAY_SIZE(opt4060_int_time_available) * 2; 716 + *vals = (const int *)opt4060_int_time_available; 717 + *type = IIO_VAL_INT_PLUS_MICRO; 718 + return IIO_AVAIL_LIST; 719 + 720 + default: 721 + return -EINVAL; 722 + } 723 + } 724 + 725 + static ssize_t opt4060_read_ev_period(struct opt4060_chip *chip, int *val, 726 + int *val2) 727 + { 728 + int ret, pers, fault_count, int_time; 729 + u64 uval; 730 + 731 + int_time = opt4060_int_time_reg[chip->int_time][0]; 732 + 733 + ret = regmap_read(chip->regmap, OPT4060_CTRL, &fault_count); 734 + if (ret < 0) 735 + return ret; 736 + 737 + fault_count = fault_count & OPT4060_CTRL_FAULT_COUNT_MASK; 738 + switch (fault_count) { 739 + case OPT4060_CTRL_FAULT_COUNT_2: 740 + pers = 2; 741 + break; 742 + case OPT4060_CTRL_FAULT_COUNT_4: 743 + pers = 4; 744 + break; 745 + case OPT4060_CTRL_FAULT_COUNT_8: 746 + pers = 8; 747 + break; 748 + 749 + default: 750 + pers = 1; 751 + break; 752 + } 753 + 754 + uval = mul_u32_u32(int_time, pers); 755 + *val = div_u64_rem(uval, MICRO, val2); 756 + 757 + return IIO_VAL_INT_PLUS_MICRO; 758 + } 759 + 760 + static ssize_t opt4060_write_ev_period(struct opt4060_chip *chip, int val, 761 + int val2) 762 + { 763 + u64 uval, int_time; 764 + unsigned int regval, fault_count_val; 765 + 766 + uval = mul_u32_u32(val, MICRO) + val2; 767 + int_time = opt4060_int_time_reg[chip->int_time][0]; 768 + 769 + /* Check if the period is closest to 1, 2, 4 or 8 times integration time.*/ 770 + if (uval <= int_time) 771 + fault_count_val = OPT4060_CTRL_FAULT_COUNT_1; 772 + else if (uval <= int_time * 2) 773 + fault_count_val = OPT4060_CTRL_FAULT_COUNT_2; 774 + else if (uval <= int_time * 4) 775 + fault_count_val = OPT4060_CTRL_FAULT_COUNT_4; 776 + else 777 + fault_count_val = OPT4060_CTRL_FAULT_COUNT_8; 778 + 779 + regval = FIELD_PREP(OPT4060_CTRL_FAULT_COUNT_MASK, fault_count_val); 780 + return regmap_update_bits(chip->regmap, OPT4060_CTRL, 781 + OPT4060_CTRL_FAULT_COUNT_MASK, regval); 782 + } 783 + 784 + static int opt4060_get_channel_sel(struct opt4060_chip *chip, int *ch_sel) 785 + { 786 + int ret; 787 + u32 regval; 788 + 789 + ret = regmap_read(chip->regmap, OPT4060_INT_CTRL, &regval); 790 + if (ret) { 791 + dev_err(chip->dev, "Failed to get channel selection.\n"); 792 + return ret; 793 + } 794 + *ch_sel = FIELD_GET(OPT4060_INT_CTRL_THRESH_SEL, regval); 795 + return ret; 796 + } 797 + 798 + static int opt4060_set_channel_sel(struct opt4060_chip *chip, int ch_sel) 799 + { 800 + int ret; 801 + u32 regval; 802 + 803 + regval = FIELD_PREP(OPT4060_INT_CTRL_THRESH_SEL, ch_sel); 804 + ret = regmap_update_bits(chip->regmap, OPT4060_INT_CTRL, 805 + OPT4060_INT_CTRL_THRESH_SEL, regval); 806 + if (ret) 807 + dev_err(chip->dev, "Failed to set channel selection.\n"); 808 + return ret; 809 + } 810 + 811 + static int opt4060_get_thresholds(struct opt4060_chip *chip, u32 *th_lo, u32 *th_hi) 812 + { 813 + int ret; 814 + u32 regval; 815 + 816 + ret = regmap_read(chip->regmap, OPT4060_THRESHOLD_LOW, &regval); 817 + if (ret) { 818 + dev_err(chip->dev, "Failed to read THRESHOLD_LOW.\n"); 819 + return ret; 820 + } 821 + *th_lo = opt4060_calc_val_from_th_reg(regval); 822 + 823 + ret = regmap_read(chip->regmap, OPT4060_THRESHOLD_HIGH, &regval); 824 + if (ret) { 825 + dev_err(chip->dev, "Failed to read THRESHOLD_LOW.\n"); 826 + return ret; 827 + } 828 + *th_hi = opt4060_calc_val_from_th_reg(regval); 829 + 830 + return ret; 831 + } 832 + 833 + static int opt4060_set_thresholds(struct opt4060_chip *chip, u32 th_lo, u32 th_hi) 834 + { 835 + int ret; 836 + 837 + ret = regmap_write(chip->regmap, OPT4060_THRESHOLD_LOW, opt4060_calc_th_reg(th_lo)); 838 + if (ret) { 839 + dev_err(chip->dev, "Failed to write THRESHOLD_LOW.\n"); 840 + return ret; 841 + } 842 + 843 + ret = regmap_write(chip->regmap, OPT4060_THRESHOLD_HIGH, opt4060_calc_th_reg(th_hi)); 844 + if (ret) 845 + dev_err(chip->dev, "Failed to write THRESHOLD_HIGH.\n"); 846 + 847 + return ret; 848 + } 849 + 850 + static int opt4060_read_event(struct iio_dev *indio_dev, 851 + const struct iio_chan_spec *chan, 852 + enum iio_event_type type, 853 + enum iio_event_direction dir, 854 + enum iio_event_info info, 855 + int *val, int *val2) 856 + { 857 + struct opt4060_chip *chip = iio_priv(indio_dev); 858 + u32 th_lo, th_hi; 859 + int ret; 860 + 861 + if (chan->type != IIO_INTENSITY) 862 + return -EINVAL; 863 + if (type != IIO_EV_TYPE_THRESH) 864 + return -EINVAL; 865 + 866 + switch (info) { 867 + case IIO_EV_INFO_VALUE: 868 + ret = opt4060_get_thresholds(chip, &th_lo, &th_hi); 869 + if (ret) 870 + return ret; 871 + if (dir == IIO_EV_DIR_FALLING) { 872 + *val = th_lo; 873 + ret = IIO_VAL_INT; 874 + } else if (dir == IIO_EV_DIR_RISING) { 875 + *val = th_hi; 876 + ret = IIO_VAL_INT; 877 + } 878 + return ret; 879 + case IIO_EV_INFO_PERIOD: 880 + return opt4060_read_ev_period(chip, val, val2); 881 + default: 882 + return -EINVAL; 883 + } 884 + } 885 + 886 + static int opt4060_write_event(struct iio_dev *indio_dev, 887 + const struct iio_chan_spec *chan, 888 + enum iio_event_type type, 889 + enum iio_event_direction dir, 890 + enum iio_event_info info, 891 + int val, int val2) 892 + { 893 + struct opt4060_chip *chip = iio_priv(indio_dev); 894 + u32 th_lo, th_hi; 895 + int ret; 896 + 897 + if (chan->type != IIO_INTENSITY) 898 + return -EINVAL; 899 + if (type != IIO_EV_TYPE_THRESH) 900 + return -EINVAL; 901 + 902 + switch (info) { 903 + case IIO_EV_INFO_VALUE: 904 + ret = opt4060_get_thresholds(chip, &th_lo, &th_hi); 905 + if (ret) 906 + return ret; 907 + if (dir == IIO_EV_DIR_FALLING) 908 + th_lo = val; 909 + else if (dir == IIO_EV_DIR_RISING) 910 + th_hi = val; 911 + return opt4060_set_thresholds(chip, th_lo, th_hi); 912 + case IIO_EV_INFO_PERIOD: 913 + return opt4060_write_ev_period(chip, val, val2); 914 + default: 915 + return -EINVAL; 916 + } 917 + } 918 + 919 + static int opt4060_read_event_config(struct iio_dev *indio_dev, 920 + const struct iio_chan_spec *chan, 921 + enum iio_event_type type, 922 + enum iio_event_direction dir) 923 + { 924 + int ch_sel, ch_idx = chan->scan_index; 925 + struct opt4060_chip *chip = iio_priv(indio_dev); 926 + int ret; 927 + 928 + if (chan->type != IIO_INTENSITY) 929 + return -EINVAL; 930 + if (type != IIO_EV_TYPE_THRESH) 931 + return -EINVAL; 932 + 933 + ret = opt4060_get_channel_sel(chip, &ch_sel); 934 + if (ret) 935 + return ret; 936 + 937 + if (((dir == IIO_EV_DIR_FALLING) && chip->thresh_event_lo_active) || 938 + ((dir == IIO_EV_DIR_RISING) && chip->thresh_event_hi_active)) 939 + return ch_sel == ch_idx; 940 + 941 + return ret; 942 + } 943 + 944 + static int opt4060_write_event_config(struct iio_dev *indio_dev, 945 + const struct iio_chan_spec *chan, 946 + enum iio_event_type type, 947 + enum iio_event_direction dir, bool state) 948 + { 949 + int ch_sel, ch_idx = chan->scan_index; 950 + struct opt4060_chip *chip = iio_priv(indio_dev); 951 + int ret; 952 + 953 + guard(mutex)(&chip->event_enabling_lock); 954 + 955 + if (chan->type != IIO_INTENSITY) 956 + return -EINVAL; 957 + if (type != IIO_EV_TYPE_THRESH) 958 + return -EINVAL; 959 + 960 + ret = opt4060_get_channel_sel(chip, &ch_sel); 961 + if (ret) 962 + return ret; 963 + 964 + if (state) { 965 + /* Only one channel can be active at the same time */ 966 + if ((chip->thresh_event_lo_active || chip->thresh_event_hi_active) && 967 + (ch_idx != ch_sel)) 968 + return -EBUSY; 969 + if (dir == IIO_EV_DIR_FALLING) 970 + chip->thresh_event_lo_active = true; 971 + else if (dir == IIO_EV_DIR_RISING) 972 + chip->thresh_event_hi_active = true; 973 + ret = opt4060_set_channel_sel(chip, ch_idx); 974 + if (ret) 975 + return ret; 976 + } else { 977 + if (ch_idx == ch_sel) { 978 + if (dir == IIO_EV_DIR_FALLING) 979 + chip->thresh_event_lo_active = false; 980 + else if (dir == IIO_EV_DIR_RISING) 981 + chip->thresh_event_hi_active = false; 982 + } 983 + } 984 + 985 + return opt4060_set_driver_state(indio_dev, 986 + chip->thresh_event_hi_active | 987 + chip->thresh_event_lo_active, 988 + false); 989 + } 990 + 991 + static const struct iio_info opt4060_info = { 992 + .read_raw = opt4060_read_raw, 993 + .write_raw = opt4060_write_raw, 994 + .write_raw_get_fmt = opt4060_write_raw_get_fmt, 995 + .read_avail = opt4060_read_available, 996 + .read_event_value = opt4060_read_event, 997 + .write_event_value = opt4060_write_event, 998 + .read_event_config = opt4060_read_event_config, 999 + .write_event_config = opt4060_write_event_config, 1000 + }; 1001 + 1002 + static const struct iio_info opt4060_info_no_irq = { 1003 + .read_raw = opt4060_read_raw, 1004 + .write_raw = opt4060_write_raw, 1005 + .write_raw_get_fmt = opt4060_write_raw_get_fmt, 1006 + .read_avail = opt4060_read_available, 1007 + }; 1008 + 1009 + static int opt4060_load_defaults(struct opt4060_chip *chip) 1010 + { 1011 + u16 reg; 1012 + int ret; 1013 + 1014 + chip->int_time = OPT4060_DEFAULT_CONVERSION_TIME; 1015 + 1016 + /* Set initial MIN/MAX thresholds */ 1017 + ret = opt4060_set_thresholds(chip, 0, UINT_MAX); 1018 + if (ret) 1019 + return ret; 1020 + 1021 + /* 1022 + * Setting auto-range, latched window for thresholds, one-shot conversion 1023 + * and quick wake-up mode as default. 1024 + */ 1025 + reg = FIELD_PREP(OPT4060_CTRL_RANGE_MASK, 1026 + OPT4060_CTRL_LIGHT_SCALE_AUTO); 1027 + reg |= FIELD_PREP(OPT4060_CTRL_CONV_TIME_MASK, chip->int_time); 1028 + reg |= FIELD_PREP(OPT4060_CTRL_OPER_MODE_MASK, 1029 + OPT4060_CTRL_OPER_MODE_ONE_SHOT); 1030 + reg |= OPT4060_CTRL_QWAKE_MASK | OPT4060_CTRL_LATCH_MASK; 1031 + 1032 + ret = regmap_write(chip->regmap, OPT4060_CTRL, reg); 1033 + if (ret) 1034 + dev_err(chip->dev, "Failed to set configuration\n"); 1035 + 1036 + return ret; 1037 + } 1038 + 1039 + static bool opt4060_volatile_reg(struct device *dev, unsigned int reg) 1040 + { 1041 + return reg <= OPT4060_CLEAR_LSB || reg == OPT4060_RES_CTRL; 1042 + } 1043 + 1044 + static bool opt4060_writable_reg(struct device *dev, unsigned int reg) 1045 + { 1046 + return reg >= OPT4060_THRESHOLD_LOW || reg >= OPT4060_INT_CTRL; 1047 + } 1048 + 1049 + static bool opt4060_readonly_reg(struct device *dev, unsigned int reg) 1050 + { 1051 + return reg == OPT4060_DEVICE_ID; 1052 + } 1053 + 1054 + static bool opt4060_readable_reg(struct device *dev, unsigned int reg) 1055 + { 1056 + /* Volatile, writable and read-only registers are readable. */ 1057 + return opt4060_volatile_reg(dev, reg) || opt4060_writable_reg(dev, reg) || 1058 + opt4060_readonly_reg(dev, reg); 1059 + } 1060 + 1061 + static const struct regmap_config opt4060_regmap_config = { 1062 + .name = "opt4060", 1063 + .reg_bits = 8, 1064 + .val_bits = 16, 1065 + .cache_type = REGCACHE_RBTREE, 1066 + .max_register = OPT4060_DEVICE_ID, 1067 + .readable_reg = opt4060_readable_reg, 1068 + .writeable_reg = opt4060_writable_reg, 1069 + .volatile_reg = opt4060_volatile_reg, 1070 + .val_format_endian = REGMAP_ENDIAN_BIG, 1071 + }; 1072 + 1073 + static const struct iio_trigger_ops opt4060_trigger_ops = { 1074 + .set_trigger_state = opt4060_trigger_set_state, 1075 + }; 1076 + 1077 + static irqreturn_t opt4060_trigger_handler(int irq, void *p) 1078 + { 1079 + struct iio_poll_func *pf = p; 1080 + struct iio_dev *idev = pf->indio_dev; 1081 + struct opt4060_chip *chip = iio_priv(idev); 1082 + struct { 1083 + u32 chan[OPT4060_NUM_CHANS]; 1084 + aligned_s64 ts; 1085 + } raw; 1086 + int i = 0; 1087 + int chan, ret; 1088 + 1089 + /* If the trigger is not from this driver, a new sample is needed.*/ 1090 + if (iio_trigger_validate_own_device(idev->trig, idev)) 1091 + opt4060_trigger_new_samples(idev); 1092 + 1093 + memset(&raw, 0, sizeof(raw)); 1094 + 1095 + iio_for_each_active_channel(idev, chan) { 1096 + if (chan == OPT4060_ILLUM) 1097 + ret = opt4060_calc_illuminance(chip, &raw.chan[i++]); 1098 + else 1099 + ret = opt4060_read_raw_value(chip, 1100 + idev->channels[chan].address, 1101 + &raw.chan[i++]); 1102 + if (ret) { 1103 + dev_err(chip->dev, "Reading channel data failed\n"); 1104 + goto err_read; 1105 + } 1106 + } 1107 + 1108 + iio_push_to_buffers_with_timestamp(idev, &raw, pf->timestamp); 1109 + err_read: 1110 + iio_trigger_notify_done(idev->trig); 1111 + return IRQ_HANDLED; 1112 + } 1113 + 1114 + static irqreturn_t opt4060_irq_thread(int irq, void *private) 1115 + { 1116 + struct iio_dev *idev = private; 1117 + struct opt4060_chip *chip = iio_priv(idev); 1118 + int ret, dummy; 1119 + unsigned int int_res; 1120 + 1121 + ret = regmap_read(chip->regmap, OPT4060_RES_CTRL, &int_res); 1122 + if (ret < 0) { 1123 + dev_err(chip->dev, "Failed to read interrupt reasons.\n"); 1124 + return IRQ_NONE; 1125 + } 1126 + 1127 + /* Read OPT4060_CTRL to clear interrupt */ 1128 + ret = regmap_read(chip->regmap, OPT4060_CTRL, &dummy); 1129 + if (ret < 0) { 1130 + dev_err(chip->dev, "Failed to clear interrupt\n"); 1131 + return IRQ_NONE; 1132 + } 1133 + 1134 + /* Handle events */ 1135 + if (int_res & (OPT4060_RES_CTRL_FLAG_H | OPT4060_RES_CTRL_FLAG_L)) { 1136 + u64 code; 1137 + int chan = 0; 1138 + 1139 + ret = opt4060_get_channel_sel(chip, &chan); 1140 + if (ret) { 1141 + dev_err(chip->dev, "Failed to read threshold channel.\n"); 1142 + return IRQ_NONE; 1143 + } 1144 + 1145 + /* Check if the interrupt is from the lower threshold */ 1146 + if (int_res & OPT4060_RES_CTRL_FLAG_L) { 1147 + code = IIO_MOD_EVENT_CODE(IIO_INTENSITY, 1148 + chan, 1149 + idev->channels[chan].channel2, 1150 + IIO_EV_TYPE_THRESH, 1151 + IIO_EV_DIR_FALLING); 1152 + iio_push_event(idev, code, iio_get_time_ns(idev)); 1153 + } 1154 + /* Check if the interrupt is from the upper threshold */ 1155 + if (int_res & OPT4060_RES_CTRL_FLAG_H) { 1156 + code = IIO_MOD_EVENT_CODE(IIO_INTENSITY, 1157 + chan, 1158 + idev->channels[chan].channel2, 1159 + IIO_EV_TYPE_THRESH, 1160 + IIO_EV_DIR_RISING); 1161 + iio_push_event(idev, code, iio_get_time_ns(idev)); 1162 + } 1163 + } 1164 + 1165 + /* Handle conversion ready */ 1166 + if (int_res & OPT4060_RES_CTRL_CONV_READY) { 1167 + /* Signal completion for potentially waiting reads */ 1168 + complete(&chip->completion); 1169 + 1170 + /* Handle data ready triggers */ 1171 + if (iio_buffer_enabled(idev)) 1172 + iio_trigger_poll_nested(chip->trig); 1173 + } 1174 + return IRQ_HANDLED; 1175 + } 1176 + 1177 + static int opt4060_setup_buffer(struct opt4060_chip *chip, struct iio_dev *idev) 1178 + { 1179 + int ret; 1180 + 1181 + ret = devm_iio_triggered_buffer_setup(chip->dev, idev, 1182 + &iio_pollfunc_store_time, 1183 + opt4060_trigger_handler, NULL); 1184 + if (ret) 1185 + return dev_err_probe(chip->dev, ret, 1186 + "Buffer setup failed.\n"); 1187 + return ret; 1188 + } 1189 + 1190 + static int opt4060_setup_trigger(struct opt4060_chip *chip, struct iio_dev *idev) 1191 + { 1192 + struct iio_trigger *data_trigger; 1193 + char *name; 1194 + int ret; 1195 + 1196 + data_trigger = devm_iio_trigger_alloc(chip->dev, "%s-data-ready-dev%d", 1197 + idev->name, iio_device_id(idev)); 1198 + if (!data_trigger) 1199 + return -ENOMEM; 1200 + 1201 + /* 1202 + * The data trigger allows for sample capture on each new conversion 1203 + * ready interrupt. 1204 + */ 1205 + chip->trig = data_trigger; 1206 + data_trigger->ops = &opt4060_trigger_ops; 1207 + iio_trigger_set_drvdata(data_trigger, idev); 1208 + ret = devm_iio_trigger_register(chip->dev, data_trigger); 1209 + if (ret) 1210 + return dev_err_probe(chip->dev, ret, 1211 + "Data ready trigger registration failed\n"); 1212 + 1213 + name = devm_kasprintf(chip->dev, GFP_KERNEL, "%s-opt4060", 1214 + dev_name(chip->dev)); 1215 + if (!name) 1216 + return dev_err_probe(chip->dev, -ENOMEM, "Failed to alloc chip name\n"); 1217 + 1218 + ret = devm_request_threaded_irq(chip->dev, chip->irq, NULL, opt4060_irq_thread, 1219 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 1220 + name, idev); 1221 + if (ret) 1222 + return dev_err_probe(chip->dev, ret, "Could not request IRQ\n"); 1223 + 1224 + init_completion(&chip->completion); 1225 + 1226 + ret = devm_mutex_init(chip->dev, &chip->irq_setting_lock); 1227 + if (ret) 1228 + return ret; 1229 + 1230 + ret = devm_mutex_init(chip->dev, &chip->event_enabling_lock); 1231 + if (ret) 1232 + return ret; 1233 + 1234 + ret = regmap_write_bits(chip->regmap, OPT4060_INT_CTRL, 1235 + OPT4060_INT_CTRL_OUTPUT, 1236 + OPT4060_INT_CTRL_OUTPUT); 1237 + if (ret) 1238 + return dev_err_probe(chip->dev, ret, 1239 + "Failed to set interrupt as output\n"); 1240 + 1241 + return 0; 1242 + } 1243 + 1244 + static int opt4060_probe(struct i2c_client *client) 1245 + { 1246 + struct device *dev = &client->dev; 1247 + struct opt4060_chip *chip; 1248 + struct iio_dev *indio_dev; 1249 + int ret; 1250 + unsigned int regval, dev_id; 1251 + 1252 + indio_dev = devm_iio_device_alloc(dev, sizeof(*chip)); 1253 + if (!indio_dev) 1254 + return -ENOMEM; 1255 + 1256 + chip = iio_priv(indio_dev); 1257 + 1258 + ret = devm_regulator_get_enable(dev, "vdd"); 1259 + if (ret) 1260 + return dev_err_probe(dev, ret, "Failed to enable vdd supply\n"); 1261 + 1262 + chip->regmap = devm_regmap_init_i2c(client, &opt4060_regmap_config); 1263 + if (IS_ERR(chip->regmap)) 1264 + return dev_err_probe(dev, PTR_ERR(chip->regmap), 1265 + "regmap initialization failed\n"); 1266 + 1267 + chip->dev = dev; 1268 + chip->irq = client->irq; 1269 + 1270 + ret = regmap_reinit_cache(chip->regmap, &opt4060_regmap_config); 1271 + if (ret) 1272 + return dev_err_probe(dev, ret, 1273 + "failed to reinit regmap cache\n"); 1274 + 1275 + ret = regmap_read(chip->regmap, OPT4060_DEVICE_ID, &regval); 1276 + if (ret < 0) 1277 + return dev_err_probe(dev, ret, 1278 + "Failed to read the device ID register\n"); 1279 + 1280 + dev_id = FIELD_GET(OPT4060_DEVICE_ID_MASK, regval); 1281 + if (dev_id != OPT4060_DEVICE_ID_VAL) 1282 + dev_info(dev, "Device ID: %#04x unknown\n", dev_id); 1283 + 1284 + if (chip->irq) { 1285 + indio_dev->info = &opt4060_info; 1286 + indio_dev->channels = opt4060_channels; 1287 + indio_dev->num_channels = ARRAY_SIZE(opt4060_channels); 1288 + } else { 1289 + indio_dev->info = &opt4060_info_no_irq; 1290 + indio_dev->channels = opt4060_channels_no_events; 1291 + indio_dev->num_channels = ARRAY_SIZE(opt4060_channels_no_events); 1292 + } 1293 + indio_dev->modes = INDIO_DIRECT_MODE; 1294 + indio_dev->name = "opt4060"; 1295 + 1296 + ret = opt4060_load_defaults(chip); 1297 + if (ret < 0) 1298 + return dev_err_probe(dev, ret, 1299 + "Failed to set sensor defaults\n"); 1300 + 1301 + ret = devm_add_action_or_reset(dev, opt4060_chip_off_action, chip); 1302 + if (ret < 0) 1303 + return dev_err_probe(dev, ret, 1304 + "Failed to setup power off action\n"); 1305 + 1306 + ret = opt4060_setup_buffer(chip, indio_dev); 1307 + if (ret) 1308 + return ret; 1309 + 1310 + if (chip->irq) { 1311 + ret = opt4060_setup_trigger(chip, indio_dev); 1312 + if (ret) 1313 + return ret; 1314 + } 1315 + 1316 + return devm_iio_device_register(dev, indio_dev); 1317 + } 1318 + 1319 + static const struct i2c_device_id opt4060_id[] = { 1320 + { "opt4060", }, 1321 + { } 1322 + }; 1323 + MODULE_DEVICE_TABLE(i2c, opt4060_id); 1324 + 1325 + static const struct of_device_id opt4060_of_match[] = { 1326 + { .compatible = "ti,opt4060" }, 1327 + { } 1328 + }; 1329 + MODULE_DEVICE_TABLE(of, opt4060_of_match); 1330 + 1331 + static struct i2c_driver opt4060_driver = { 1332 + .driver = { 1333 + .name = "opt4060", 1334 + .of_match_table = opt4060_of_match, 1335 + }, 1336 + .probe = opt4060_probe, 1337 + .id_table = opt4060_id, 1338 + }; 1339 + module_i2c_driver(opt4060_driver); 1340 + 1341 + MODULE_AUTHOR("Per-Daniel Olsson <perdaniel.olsson@axis.com>"); 1342 + MODULE_DESCRIPTION("Texas Instruments OPT4060 RGBW color sensor driver"); 1343 + MODULE_LICENSE("GPL");
-1635
drivers/iio/light/rohm-bu27008.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * ROHM Colour Sensor driver for 4 - * - BU27008 RGBC sensor 5 - * - BU27010 RGBC + Flickering sensor 6 - * 7 - * Copyright (c) 2023, ROHM Semiconductor. 8 - */ 9 - 10 - #include <linux/bitfield.h> 11 - #include <linux/bitops.h> 12 - #include <linux/device.h> 13 - #include <linux/i2c.h> 14 - #include <linux/interrupt.h> 15 - #include <linux/module.h> 16 - #include <linux/property.h> 17 - #include <linux/regmap.h> 18 - #include <linux/regulator/consumer.h> 19 - #include <linux/units.h> 20 - 21 - #include <linux/iio/iio.h> 22 - #include <linux/iio/iio-gts-helper.h> 23 - #include <linux/iio/trigger.h> 24 - #include <linux/iio/trigger_consumer.h> 25 - #include <linux/iio/triggered_buffer.h> 26 - 27 - /* 28 - * A word about register address and mask definitions. 29 - * 30 - * At a quick glance to the data-sheet register tables, the BU27010 has all the 31 - * registers that the BU27008 has. On top of that the BU27010 adds couple of new 32 - * ones. 33 - * 34 - * So, all definitions BU27008_REG_* are there also for BU27010 but none of the 35 - * BU27010_REG_* are present on BU27008. This makes sense as BU27010 just adds 36 - * some features (Flicker FIFO, more power control) on top of the BU27008. 37 - * 38 - * Unfortunately, some of the wheel has been re-invented. Even though the names 39 - * of the registers have stayed the same, pretty much all of the functionality 40 - * provided by the registers has changed place. Contents of all MODE_CONTROL 41 - * registers on BU27008 and BU27010 are different. 42 - * 43 - * Chip-specific mapping from register addresses/bits to functionality is done 44 - * in bu27_chip_data structures. 45 - */ 46 - #define BU27008_REG_SYSTEM_CONTROL 0x40 47 - #define BU27008_MASK_SW_RESET BIT(7) 48 - #define BU27008_MASK_PART_ID GENMASK(5, 0) 49 - #define BU27008_ID 0x1a 50 - #define BU27008_REG_MODE_CONTROL1 0x41 51 - #define BU27008_MASK_MEAS_MODE GENMASK(2, 0) 52 - #define BU27008_MASK_CHAN_SEL GENMASK(3, 2) 53 - 54 - #define BU27008_REG_MODE_CONTROL2 0x42 55 - #define BU27008_MASK_RGBC_GAIN GENMASK(7, 3) 56 - #define BU27008_MASK_IR_GAIN_LO GENMASK(2, 0) 57 - #define BU27008_SHIFT_IR_GAIN 3 58 - 59 - #define BU27008_REG_MODE_CONTROL3 0x43 60 - #define BU27008_MASK_VALID BIT(7) 61 - #define BU27008_MASK_INT_EN BIT(1) 62 - #define BU27008_INT_EN BU27008_MASK_INT_EN 63 - #define BU27008_INT_DIS 0 64 - #define BU27008_MASK_MEAS_EN BIT(0) 65 - #define BU27008_MEAS_EN BIT(0) 66 - #define BU27008_MEAS_DIS 0 67 - 68 - #define BU27008_REG_DATA0_LO 0x50 69 - #define BU27008_REG_DATA1_LO 0x52 70 - #define BU27008_REG_DATA2_LO 0x54 71 - #define BU27008_REG_DATA3_LO 0x56 72 - #define BU27008_REG_DATA3_HI 0x57 73 - #define BU27008_REG_MANUFACTURER_ID 0x92 74 - #define BU27008_REG_MAX BU27008_REG_MANUFACTURER_ID 75 - 76 - /* BU27010 specific definitions */ 77 - 78 - #define BU27010_MASK_SW_RESET BIT(7) 79 - #define BU27010_ID 0x1b 80 - #define BU27010_REG_POWER 0x3e 81 - #define BU27010_MASK_POWER BIT(0) 82 - 83 - #define BU27010_REG_RESET 0x3f 84 - #define BU27010_MASK_RESET BIT(0) 85 - #define BU27010_RESET_RELEASE BU27010_MASK_RESET 86 - 87 - #define BU27010_MASK_MEAS_EN BIT(1) 88 - 89 - #define BU27010_MASK_CHAN_SEL GENMASK(7, 6) 90 - #define BU27010_MASK_MEAS_MODE GENMASK(5, 4) 91 - #define BU27010_MASK_RGBC_GAIN GENMASK(3, 0) 92 - 93 - #define BU27010_MASK_DATA3_GAIN GENMASK(7, 6) 94 - #define BU27010_MASK_DATA2_GAIN GENMASK(5, 4) 95 - #define BU27010_MASK_DATA1_GAIN GENMASK(3, 2) 96 - #define BU27010_MASK_DATA0_GAIN GENMASK(1, 0) 97 - 98 - #define BU27010_MASK_FLC_MODE BIT(7) 99 - #define BU27010_MASK_FLC_GAIN GENMASK(4, 0) 100 - 101 - #define BU27010_REG_MODE_CONTROL4 0x44 102 - /* If flicker is ever to be supported the IRQ must be handled as a field */ 103 - #define BU27010_IRQ_DIS_ALL GENMASK(1, 0) 104 - #define BU27010_DRDY_EN BIT(0) 105 - #define BU27010_MASK_INT_SEL GENMASK(1, 0) 106 - 107 - #define BU27010_REG_MODE_CONTROL5 0x45 108 - #define BU27010_MASK_RGB_VALID BIT(7) 109 - #define BU27010_MASK_FLC_VALID BIT(6) 110 - #define BU27010_MASK_WAIT_EN BIT(3) 111 - #define BU27010_MASK_FIFO_EN BIT(2) 112 - #define BU27010_MASK_RGB_EN BIT(1) 113 - #define BU27010_MASK_FLC_EN BIT(0) 114 - 115 - #define BU27010_REG_DATA_FLICKER_LO 0x56 116 - #define BU27010_MASK_DATA_FLICKER_HI GENMASK(2, 0) 117 - #define BU27010_REG_FLICKER_COUNT 0x5a 118 - #define BU27010_REG_FIFO_LEVEL_LO 0x5b 119 - #define BU27010_MASK_FIFO_LEVEL_HI BIT(0) 120 - #define BU27010_REG_FIFO_DATA_LO 0x5d 121 - #define BU27010_REG_FIFO_DATA_HI 0x5e 122 - #define BU27010_MASK_FIFO_DATA_HI GENMASK(2, 0) 123 - #define BU27010_REG_MANUFACTURER_ID 0x92 124 - #define BU27010_REG_MAX BU27010_REG_MANUFACTURER_ID 125 - 126 - /** 127 - * enum bu27008_chan_type - BU27008 channel types 128 - * @BU27008_RED: Red channel. Always via data0. 129 - * @BU27008_GREEN: Green channel. Always via data1. 130 - * @BU27008_BLUE: Blue channel. Via data2 (when used). 131 - * @BU27008_CLEAR: Clear channel. Via data2 or data3 (when used). 132 - * @BU27008_IR: IR channel. Via data3 (when used). 133 - * @BU27008_LUX: Illuminance channel, computed using RGB and IR. 134 - * @BU27008_NUM_CHANS: Number of channel types. 135 - */ 136 - enum bu27008_chan_type { 137 - BU27008_RED, 138 - BU27008_GREEN, 139 - BU27008_BLUE, 140 - BU27008_CLEAR, 141 - BU27008_IR, 142 - BU27008_LUX, 143 - BU27008_NUM_CHANS 144 - }; 145 - 146 - /** 147 - * enum bu27008_chan - BU27008 physical data channel 148 - * @BU27008_DATA0: Always red. 149 - * @BU27008_DATA1: Always green. 150 - * @BU27008_DATA2: Blue or clear. 151 - * @BU27008_DATA3: IR or clear. 152 - * @BU27008_NUM_HW_CHANS: Number of physical channels 153 - */ 154 - enum bu27008_chan { 155 - BU27008_DATA0, 156 - BU27008_DATA1, 157 - BU27008_DATA2, 158 - BU27008_DATA3, 159 - BU27008_NUM_HW_CHANS 160 - }; 161 - 162 - /* We can always measure red and green at same time */ 163 - #define ALWAYS_SCANNABLE (BIT(BU27008_RED) | BIT(BU27008_GREEN)) 164 - 165 - /* We use these data channel configs. Ensure scan_masks below follow them too */ 166 - #define BU27008_BLUE2_CLEAR3 0x0 /* buffer is R, G, B, C */ 167 - #define BU27008_CLEAR2_IR3 0x1 /* buffer is R, G, C, IR */ 168 - #define BU27008_BLUE2_IR3 0x2 /* buffer is R, G, B, IR */ 169 - 170 - static const unsigned long bu27008_scan_masks[] = { 171 - /* buffer is R, G, B, C */ 172 - ALWAYS_SCANNABLE | BIT(BU27008_BLUE) | BIT(BU27008_CLEAR), 173 - /* buffer is R, G, C, IR */ 174 - ALWAYS_SCANNABLE | BIT(BU27008_CLEAR) | BIT(BU27008_IR), 175 - /* buffer is R, G, B, IR */ 176 - ALWAYS_SCANNABLE | BIT(BU27008_BLUE) | BIT(BU27008_IR), 177 - /* buffer is R, G, B, IR, LUX */ 178 - ALWAYS_SCANNABLE | BIT(BU27008_BLUE) | BIT(BU27008_IR) | BIT(BU27008_LUX), 179 - 0 180 - }; 181 - 182 - /* 183 - * Available scales with gain 1x - 1024x, timings 55, 100, 200, 400 mS 184 - * Time impacts to gain: 1x, 2x, 4x, 8x. 185 - * 186 - * => Max total gain is HWGAIN * gain by integration time (8 * 1024) = 8192 187 - * 188 - * Max amplification is (HWGAIN * MAX integration-time multiplier) 1024 * 8 189 - * = 8192. With NANO scale we get rid of accuracy loss when we start with the 190 - * scale 16.0 for HWGAIN1, INT-TIME 55 mS. This way the nano scale for MAX 191 - * total gain 8192 will be 1953125 192 - */ 193 - #define BU27008_SCALE_1X 16 194 - 195 - /* 196 - * On BU27010 available scales with gain 1x - 4096x, 197 - * timings 55, 100, 200, 400 mS. Time impacts to gain: 1x, 2x, 4x, 8x. 198 - * 199 - * => Max total gain is HWGAIN * gain by integration time (8 * 4096) 200 - * 201 - * Using NANO precision for scale we must use scale 64x corresponding gain 1x 202 - * to avoid precision loss. 203 - */ 204 - #define BU27010_SCALE_1X 64 205 - 206 - /* See the data sheet for the "Gain Setting" table */ 207 - #define BU27008_GSEL_1X 0x00 208 - #define BU27008_GSEL_4X 0x08 209 - #define BU27008_GSEL_8X 0x09 210 - #define BU27008_GSEL_16X 0x0a 211 - #define BU27008_GSEL_32X 0x0b 212 - #define BU27008_GSEL_64X 0x0c 213 - #define BU27008_GSEL_256X 0x18 214 - #define BU27008_GSEL_512X 0x19 215 - #define BU27008_GSEL_1024X 0x1a 216 - 217 - static const struct iio_gain_sel_pair bu27008_gains[] = { 218 - GAIN_SCALE_GAIN(1, BU27008_GSEL_1X), 219 - GAIN_SCALE_GAIN(4, BU27008_GSEL_4X), 220 - GAIN_SCALE_GAIN(8, BU27008_GSEL_8X), 221 - GAIN_SCALE_GAIN(16, BU27008_GSEL_16X), 222 - GAIN_SCALE_GAIN(32, BU27008_GSEL_32X), 223 - GAIN_SCALE_GAIN(64, BU27008_GSEL_64X), 224 - GAIN_SCALE_GAIN(256, BU27008_GSEL_256X), 225 - GAIN_SCALE_GAIN(512, BU27008_GSEL_512X), 226 - GAIN_SCALE_GAIN(1024, BU27008_GSEL_1024X), 227 - }; 228 - 229 - static const struct iio_gain_sel_pair bu27008_gains_ir[] = { 230 - GAIN_SCALE_GAIN(2, BU27008_GSEL_1X), 231 - GAIN_SCALE_GAIN(4, BU27008_GSEL_4X), 232 - GAIN_SCALE_GAIN(8, BU27008_GSEL_8X), 233 - GAIN_SCALE_GAIN(16, BU27008_GSEL_16X), 234 - GAIN_SCALE_GAIN(32, BU27008_GSEL_32X), 235 - GAIN_SCALE_GAIN(64, BU27008_GSEL_64X), 236 - GAIN_SCALE_GAIN(256, BU27008_GSEL_256X), 237 - GAIN_SCALE_GAIN(512, BU27008_GSEL_512X), 238 - GAIN_SCALE_GAIN(1024, BU27008_GSEL_1024X), 239 - }; 240 - 241 - #define BU27010_GSEL_1X 0x00 /* 000000 */ 242 - #define BU27010_GSEL_4X 0x08 /* 001000 */ 243 - #define BU27010_GSEL_16X 0x09 /* 001001 */ 244 - #define BU27010_GSEL_64X 0x0e /* 001110 */ 245 - #define BU27010_GSEL_256X 0x1e /* 011110 */ 246 - #define BU27010_GSEL_1024X 0x2e /* 101110 */ 247 - #define BU27010_GSEL_4096X 0x3f /* 111111 */ 248 - 249 - static const struct iio_gain_sel_pair bu27010_gains[] = { 250 - GAIN_SCALE_GAIN(1, BU27010_GSEL_1X), 251 - GAIN_SCALE_GAIN(4, BU27010_GSEL_4X), 252 - GAIN_SCALE_GAIN(16, BU27010_GSEL_16X), 253 - GAIN_SCALE_GAIN(64, BU27010_GSEL_64X), 254 - GAIN_SCALE_GAIN(256, BU27010_GSEL_256X), 255 - GAIN_SCALE_GAIN(1024, BU27010_GSEL_1024X), 256 - GAIN_SCALE_GAIN(4096, BU27010_GSEL_4096X), 257 - }; 258 - 259 - static const struct iio_gain_sel_pair bu27010_gains_ir[] = { 260 - GAIN_SCALE_GAIN(2, BU27010_GSEL_1X), 261 - GAIN_SCALE_GAIN(4, BU27010_GSEL_4X), 262 - GAIN_SCALE_GAIN(16, BU27010_GSEL_16X), 263 - GAIN_SCALE_GAIN(64, BU27010_GSEL_64X), 264 - GAIN_SCALE_GAIN(256, BU27010_GSEL_256X), 265 - GAIN_SCALE_GAIN(1024, BU27010_GSEL_1024X), 266 - GAIN_SCALE_GAIN(4096, BU27010_GSEL_4096X), 267 - }; 268 - 269 - #define BU27008_MEAS_MODE_100MS 0x00 270 - #define BU27008_MEAS_MODE_55MS 0x01 271 - #define BU27008_MEAS_MODE_200MS 0x02 272 - #define BU27008_MEAS_MODE_400MS 0x04 273 - 274 - #define BU27010_MEAS_MODE_100MS 0x00 275 - #define BU27010_MEAS_MODE_55MS 0x03 276 - #define BU27010_MEAS_MODE_200MS 0x01 277 - #define BU27010_MEAS_MODE_400MS 0x02 278 - 279 - #define BU27008_MEAS_TIME_MAX_MS 400 280 - 281 - static const struct iio_itime_sel_mul bu27008_itimes[] = { 282 - GAIN_SCALE_ITIME_US(400000, BU27008_MEAS_MODE_400MS, 8), 283 - GAIN_SCALE_ITIME_US(200000, BU27008_MEAS_MODE_200MS, 4), 284 - GAIN_SCALE_ITIME_US(100000, BU27008_MEAS_MODE_100MS, 2), 285 - GAIN_SCALE_ITIME_US(55000, BU27008_MEAS_MODE_55MS, 1), 286 - }; 287 - 288 - static const struct iio_itime_sel_mul bu27010_itimes[] = { 289 - GAIN_SCALE_ITIME_US(400000, BU27010_MEAS_MODE_400MS, 8), 290 - GAIN_SCALE_ITIME_US(200000, BU27010_MEAS_MODE_200MS, 4), 291 - GAIN_SCALE_ITIME_US(100000, BU27010_MEAS_MODE_100MS, 2), 292 - GAIN_SCALE_ITIME_US(55000, BU27010_MEAS_MODE_55MS, 1), 293 - }; 294 - 295 - /* 296 - * All the RGBC channels share the same gain. 297 - * IR gain can be fine-tuned from the gain set for the RGBC by 2 bit, but this 298 - * would yield quite complex gain setting. Especially since not all bit 299 - * compinations are supported. And in any case setting GAIN for RGBC will 300 - * always also change the IR-gain. 301 - * 302 - * On top of this, the selector '0' which corresponds to hw-gain 1X on RGBC, 303 - * corresponds to gain 2X on IR. Rest of the selctors correspond to same gains 304 - * though. This, however, makes it not possible to use shared gain for all 305 - * RGBC and IR settings even though they are all changed at the one go. 306 - */ 307 - #define BU27008_CHAN(color, data, separate_avail) \ 308 - { \ 309 - .type = IIO_INTENSITY, \ 310 - .modified = 1, \ 311 - .channel2 = IIO_MOD_LIGHT_##color, \ 312 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 313 - BIT(IIO_CHAN_INFO_SCALE), \ 314 - .info_mask_separate_available = (separate_avail), \ 315 - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), \ 316 - .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), \ 317 - .address = BU27008_REG_##data##_LO, \ 318 - .scan_index = BU27008_##color, \ 319 - .scan_type = { \ 320 - .sign = 'u', \ 321 - .realbits = 16, \ 322 - .storagebits = 16, \ 323 - .endianness = IIO_LE, \ 324 - }, \ 325 - } 326 - 327 - /* For raw reads we always configure DATA3 for CLEAR */ 328 - static const struct iio_chan_spec bu27008_channels[] = { 329 - BU27008_CHAN(RED, DATA0, BIT(IIO_CHAN_INFO_SCALE)), 330 - BU27008_CHAN(GREEN, DATA1, BIT(IIO_CHAN_INFO_SCALE)), 331 - BU27008_CHAN(BLUE, DATA2, BIT(IIO_CHAN_INFO_SCALE)), 332 - BU27008_CHAN(CLEAR, DATA2, BIT(IIO_CHAN_INFO_SCALE)), 333 - /* 334 - * We don't allow setting scale for IR (because of shared gain bits). 335 - * Hence we don't advertise available ones either. 336 - */ 337 - BU27008_CHAN(IR, DATA3, 0), 338 - { 339 - .type = IIO_LIGHT, 340 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 341 - BIT(IIO_CHAN_INFO_SCALE), 342 - .channel = BU27008_LUX, 343 - .scan_index = BU27008_LUX, 344 - .scan_type = { 345 - .sign = 'u', 346 - .realbits = 64, 347 - .storagebits = 64, 348 - .endianness = IIO_CPU, 349 - }, 350 - }, 351 - IIO_CHAN_SOFT_TIMESTAMP(BU27008_NUM_CHANS), 352 - }; 353 - 354 - struct bu27008_data; 355 - 356 - struct bu27_chip_data { 357 - const char *name; 358 - int (*chip_init)(struct bu27008_data *data); 359 - int (*get_gain_sel)(struct bu27008_data *data, int *sel); 360 - int (*write_gain_sel)(struct bu27008_data *data, int sel); 361 - const struct regmap_config *regmap_cfg; 362 - const struct iio_gain_sel_pair *gains; 363 - const struct iio_gain_sel_pair *gains_ir; 364 - const struct iio_itime_sel_mul *itimes; 365 - int num_gains; 366 - int num_gains_ir; 367 - int num_itimes; 368 - int scale1x; 369 - 370 - int drdy_en_reg; 371 - int drdy_en_mask; 372 - int meas_en_reg; 373 - int meas_en_mask; 374 - int valid_reg; 375 - int chan_sel_reg; 376 - int chan_sel_mask; 377 - int int_time_mask; 378 - u8 part_id; 379 - }; 380 - 381 - struct bu27008_data { 382 - const struct bu27_chip_data *cd; 383 - struct regmap *regmap; 384 - struct iio_trigger *trig; 385 - struct device *dev; 386 - struct iio_gts gts; 387 - struct iio_gts gts_ir; 388 - int irq; 389 - 390 - /* 391 - * Prevent changing gain/time config when scale is read/written. 392 - * Similarly, protect the integration_time read/change sequence. 393 - * Prevent changing gain/time when data is read. 394 - */ 395 - struct mutex mutex; 396 - }; 397 - 398 - static const struct regmap_range bu27008_volatile_ranges[] = { 399 - { 400 - .range_min = BU27008_REG_SYSTEM_CONTROL, /* SWRESET */ 401 - .range_max = BU27008_REG_SYSTEM_CONTROL, 402 - }, { 403 - .range_min = BU27008_REG_MODE_CONTROL3, /* VALID */ 404 - .range_max = BU27008_REG_MODE_CONTROL3, 405 - }, { 406 - .range_min = BU27008_REG_DATA0_LO, /* DATA */ 407 - .range_max = BU27008_REG_DATA3_HI, 408 - }, 409 - }; 410 - 411 - static const struct regmap_range bu27010_volatile_ranges[] = { 412 - { 413 - .range_min = BU27010_REG_RESET, /* RSTB */ 414 - .range_max = BU27008_REG_SYSTEM_CONTROL, /* RESET */ 415 - }, { 416 - .range_min = BU27010_REG_MODE_CONTROL5, /* VALID bits */ 417 - .range_max = BU27010_REG_MODE_CONTROL5, 418 - }, { 419 - .range_min = BU27008_REG_DATA0_LO, 420 - .range_max = BU27010_REG_FIFO_DATA_HI, 421 - }, 422 - }; 423 - 424 - static const struct regmap_access_table bu27008_volatile_regs = { 425 - .yes_ranges = &bu27008_volatile_ranges[0], 426 - .n_yes_ranges = ARRAY_SIZE(bu27008_volatile_ranges), 427 - }; 428 - 429 - static const struct regmap_access_table bu27010_volatile_regs = { 430 - .yes_ranges = &bu27010_volatile_ranges[0], 431 - .n_yes_ranges = ARRAY_SIZE(bu27010_volatile_ranges), 432 - }; 433 - 434 - static const struct regmap_range bu27008_read_only_ranges[] = { 435 - { 436 - .range_min = BU27008_REG_DATA0_LO, 437 - .range_max = BU27008_REG_DATA3_HI, 438 - }, { 439 - .range_min = BU27008_REG_MANUFACTURER_ID, 440 - .range_max = BU27008_REG_MANUFACTURER_ID, 441 - }, 442 - }; 443 - 444 - static const struct regmap_range bu27010_read_only_ranges[] = { 445 - { 446 - .range_min = BU27008_REG_DATA0_LO, 447 - .range_max = BU27010_REG_FIFO_DATA_HI, 448 - }, { 449 - .range_min = BU27010_REG_MANUFACTURER_ID, 450 - .range_max = BU27010_REG_MANUFACTURER_ID, 451 - } 452 - }; 453 - 454 - static const struct regmap_access_table bu27008_ro_regs = { 455 - .no_ranges = &bu27008_read_only_ranges[0], 456 - .n_no_ranges = ARRAY_SIZE(bu27008_read_only_ranges), 457 - }; 458 - 459 - static const struct regmap_access_table bu27010_ro_regs = { 460 - .no_ranges = &bu27010_read_only_ranges[0], 461 - .n_no_ranges = ARRAY_SIZE(bu27010_read_only_ranges), 462 - }; 463 - 464 - static const struct regmap_config bu27008_regmap = { 465 - .reg_bits = 8, 466 - .val_bits = 8, 467 - .max_register = BU27008_REG_MAX, 468 - .cache_type = REGCACHE_RBTREE, 469 - .volatile_table = &bu27008_volatile_regs, 470 - .wr_table = &bu27008_ro_regs, 471 - /* 472 - * All register writes are serialized by the mutex which protects the 473 - * scale setting/getting. This is needed because scale is combined by 474 - * gain and integration time settings and we need to ensure those are 475 - * not read / written when scale is being computed. 476 - * 477 - * As a result of this serializing, we don't need regmap locking. Note, 478 - * this is not true if we add any configurations which are not 479 - * serialized by the mutex and which may need for example a protected 480 - * read-modify-write cycle (eg. regmap_update_bits()). Please, revise 481 - * this when adding features to the driver. 482 - */ 483 - .disable_locking = true, 484 - }; 485 - 486 - static const struct regmap_config bu27010_regmap = { 487 - .reg_bits = 8, 488 - .val_bits = 8, 489 - 490 - .max_register = BU27010_REG_MAX, 491 - .cache_type = REGCACHE_RBTREE, 492 - .volatile_table = &bu27010_volatile_regs, 493 - .wr_table = &bu27010_ro_regs, 494 - .disable_locking = true, 495 - }; 496 - 497 - static int bu27008_write_gain_sel(struct bu27008_data *data, int sel) 498 - { 499 - int regval; 500 - 501 - regval = FIELD_PREP(BU27008_MASK_RGBC_GAIN, sel); 502 - 503 - /* 504 - * We do always set also the LOW bits of IR-gain because othervice we 505 - * would risk resulting an invalid GAIN register value. 506 - * 507 - * We could allow setting separate gains for RGBC and IR when the 508 - * values were such that HW could support both gain settings. 509 - * Eg, when the shared bits were same for both gain values. 510 - * 511 - * This, however, has a negligible benefit compared to the increased 512 - * software complexity when we would need to go through the gains 513 - * for both channels separately when the integration time changes. 514 - * This would end up with nasty logic for computing gain values for 515 - * both channels - and rejecting them if shared bits changed. 516 - * 517 - * We should then build the logic by guessing what a user prefers. 518 - * RGBC or IR gains correctly set while other jumps to odd value? 519 - * Maybe look-up a value where both gains are somehow optimized 520 - * <what this somehow is, is ATM unknown to us>. Or maybe user would 521 - * expect us to reject changes when optimal gains can't be set to both 522 - * channels w/given integration time. At best that would result 523 - * solution that works well for a very specific subset of 524 - * configurations but causes unexpected corner-cases. 525 - * 526 - * So, we keep it simple. Always set same selector to IR and RGBC. 527 - * We disallow setting IR (as I expect that most of the users are 528 - * interested in RGBC). This way we can show the user that the scales 529 - * for RGBC and IR channels are different (1X Vs 2X with sel 0) while 530 - * still keeping the operation deterministic. 531 - */ 532 - regval |= FIELD_PREP(BU27008_MASK_IR_GAIN_LO, sel); 533 - 534 - return regmap_update_bits(data->regmap, BU27008_REG_MODE_CONTROL2, 535 - BU27008_MASK_RGBC_GAIN, regval); 536 - } 537 - 538 - static int bu27010_write_gain_sel(struct bu27008_data *data, int sel) 539 - { 540 - unsigned int regval; 541 - int ret, chan_selector; 542 - 543 - /* 544 - * Gain 'selector' is composed of two registers. Selector is 6bit value, 545 - * 4 high bits being the RGBC gain fieild in MODE_CONTROL1 register and 546 - * two low bits being the channel specific gain in MODE_CONTROL2. 547 - * 548 - * Let's take the 4 high bits of whole 6 bit selector, and prepare 549 - * the MODE_CONTROL1 value (RGBC gain part). 550 - */ 551 - regval = FIELD_PREP(BU27010_MASK_RGBC_GAIN, (sel >> 2)); 552 - 553 - ret = regmap_update_bits(data->regmap, BU27008_REG_MODE_CONTROL1, 554 - BU27010_MASK_RGBC_GAIN, regval); 555 - if (ret) 556 - return ret; 557 - 558 - /* 559 - * Two low two bits of the selector must be written for all 4 560 - * channels in the MODE_CONTROL2 register. Copy these two bits for 561 - * all channels. 562 - */ 563 - chan_selector = sel & GENMASK(1, 0); 564 - 565 - regval = FIELD_PREP(BU27010_MASK_DATA0_GAIN, chan_selector); 566 - regval |= FIELD_PREP(BU27010_MASK_DATA1_GAIN, chan_selector); 567 - regval |= FIELD_PREP(BU27010_MASK_DATA2_GAIN, chan_selector); 568 - regval |= FIELD_PREP(BU27010_MASK_DATA3_GAIN, chan_selector); 569 - 570 - return regmap_write(data->regmap, BU27008_REG_MODE_CONTROL2, regval); 571 - } 572 - 573 - static int bu27008_get_gain_sel(struct bu27008_data *data, int *sel) 574 - { 575 - int ret; 576 - 577 - /* 578 - * If we always "lock" the gain selectors for all channels to prevent 579 - * unsupported configs, then it does not matter which channel is used 580 - * we can just return selector from any of them. 581 - * 582 - * This, however is not true if we decide to support only 4X and 16X 583 - * and then individual gains for channels. Currently this is not the 584 - * case. 585 - * 586 - * If we some day decide to support individual gains, then we need to 587 - * have channel information here. 588 - */ 589 - 590 - ret = regmap_read(data->regmap, BU27008_REG_MODE_CONTROL2, sel); 591 - if (ret) 592 - return ret; 593 - 594 - *sel = FIELD_GET(BU27008_MASK_RGBC_GAIN, *sel); 595 - 596 - return 0; 597 - } 598 - 599 - static int bu27010_get_gain_sel(struct bu27008_data *data, int *sel) 600 - { 601 - int ret, tmp; 602 - 603 - /* 604 - * We always "lock" the gain selectors for all channels to prevent 605 - * unsupported configs. It does not matter which channel is used 606 - * we can just return selector from any of them. 607 - * 608 - * Read the channel0 gain. 609 - */ 610 - ret = regmap_read(data->regmap, BU27008_REG_MODE_CONTROL2, sel); 611 - if (ret) 612 - return ret; 613 - 614 - *sel = FIELD_GET(BU27010_MASK_DATA0_GAIN, *sel); 615 - 616 - /* Read the shared gain */ 617 - ret = regmap_read(data->regmap, BU27008_REG_MODE_CONTROL1, &tmp); 618 - if (ret) 619 - return ret; 620 - 621 - /* 622 - * The gain selector is made as a combination of common RGBC gain and 623 - * the channel specific gain. The channel specific gain forms the low 624 - * bits of selector and RGBC gain is appended right after it. 625 - * 626 - * Compose the selector from channel0 gain and shared RGBC gain. 627 - */ 628 - *sel |= FIELD_GET(BU27010_MASK_RGBC_GAIN, tmp) << fls(BU27010_MASK_DATA0_GAIN); 629 - 630 - return ret; 631 - } 632 - 633 - static int bu27008_chip_init(struct bu27008_data *data) 634 - { 635 - int ret; 636 - 637 - ret = regmap_write_bits(data->regmap, BU27008_REG_SYSTEM_CONTROL, 638 - BU27008_MASK_SW_RESET, BU27008_MASK_SW_RESET); 639 - if (ret) 640 - return dev_err_probe(data->dev, ret, "Sensor reset failed\n"); 641 - 642 - /* 643 - * The data-sheet does not tell how long performing the IC reset takes. 644 - * However, the data-sheet says the minimum time it takes the IC to be 645 - * able to take inputs after power is applied, is 100 uS. I'd assume 646 - * > 1 mS is enough. 647 - */ 648 - msleep(1); 649 - 650 - ret = regmap_reinit_cache(data->regmap, data->cd->regmap_cfg); 651 - if (ret) 652 - dev_err(data->dev, "Failed to reinit reg cache\n"); 653 - 654 - return ret; 655 - } 656 - 657 - static int bu27010_chip_init(struct bu27008_data *data) 658 - { 659 - int ret; 660 - 661 - ret = regmap_write_bits(data->regmap, BU27008_REG_SYSTEM_CONTROL, 662 - BU27010_MASK_SW_RESET, BU27010_MASK_SW_RESET); 663 - if (ret) 664 - return dev_err_probe(data->dev, ret, "Sensor reset failed\n"); 665 - 666 - msleep(1); 667 - 668 - /* Power ON*/ 669 - ret = regmap_write_bits(data->regmap, BU27010_REG_POWER, 670 - BU27010_MASK_POWER, BU27010_MASK_POWER); 671 - if (ret) 672 - return dev_err_probe(data->dev, ret, "Sensor power-on failed\n"); 673 - 674 - msleep(1); 675 - 676 - /* Release blocks from reset */ 677 - ret = regmap_write_bits(data->regmap, BU27010_REG_RESET, 678 - BU27010_MASK_RESET, BU27010_RESET_RELEASE); 679 - if (ret) 680 - return dev_err_probe(data->dev, ret, "Sensor powering failed\n"); 681 - 682 - msleep(1); 683 - 684 - /* 685 - * The IRQ enabling on BU27010 is done in a peculiar way. The IRQ 686 - * enabling is not a bit mask where individual IRQs could be enabled but 687 - * a field which values are: 688 - * 00 => IRQs disabled 689 - * 01 => Data-ready (RGBC/IR) 690 - * 10 => Data-ready (flicker) 691 - * 11 => Flicker FIFO 692 - * 693 - * So, only one IRQ can be enabled at a time and enabling for example 694 - * flicker FIFO would automagically disable data-ready IRQ. 695 - * 696 - * Currently the driver does not support the flicker. Hence, we can 697 - * just treat the RGBC data-ready as single bit which can be enabled / 698 - * disabled. This works for as long as the second bit in the field 699 - * stays zero. Here we ensure it gets zeroed. 700 - */ 701 - return regmap_clear_bits(data->regmap, BU27010_REG_MODE_CONTROL4, 702 - BU27010_IRQ_DIS_ALL); 703 - } 704 - 705 - static const struct bu27_chip_data bu27010_chip = { 706 - .name = "bu27010", 707 - .chip_init = bu27010_chip_init, 708 - .get_gain_sel = bu27010_get_gain_sel, 709 - .write_gain_sel = bu27010_write_gain_sel, 710 - .regmap_cfg = &bu27010_regmap, 711 - .gains = &bu27010_gains[0], 712 - .gains_ir = &bu27010_gains_ir[0], 713 - .itimes = &bu27010_itimes[0], 714 - .num_gains = ARRAY_SIZE(bu27010_gains), 715 - .num_gains_ir = ARRAY_SIZE(bu27010_gains_ir), 716 - .num_itimes = ARRAY_SIZE(bu27010_itimes), 717 - .scale1x = BU27010_SCALE_1X, 718 - .drdy_en_reg = BU27010_REG_MODE_CONTROL4, 719 - .drdy_en_mask = BU27010_DRDY_EN, 720 - .meas_en_reg = BU27010_REG_MODE_CONTROL5, 721 - .meas_en_mask = BU27010_MASK_MEAS_EN, 722 - .valid_reg = BU27010_REG_MODE_CONTROL5, 723 - .chan_sel_reg = BU27008_REG_MODE_CONTROL1, 724 - .chan_sel_mask = BU27010_MASK_CHAN_SEL, 725 - .int_time_mask = BU27010_MASK_MEAS_MODE, 726 - .part_id = BU27010_ID, 727 - }; 728 - 729 - static const struct bu27_chip_data bu27008_chip = { 730 - .name = "bu27008", 731 - .chip_init = bu27008_chip_init, 732 - .get_gain_sel = bu27008_get_gain_sel, 733 - .write_gain_sel = bu27008_write_gain_sel, 734 - .regmap_cfg = &bu27008_regmap, 735 - .gains = &bu27008_gains[0], 736 - .gains_ir = &bu27008_gains_ir[0], 737 - .itimes = &bu27008_itimes[0], 738 - .num_gains = ARRAY_SIZE(bu27008_gains), 739 - .num_gains_ir = ARRAY_SIZE(bu27008_gains_ir), 740 - .num_itimes = ARRAY_SIZE(bu27008_itimes), 741 - .scale1x = BU27008_SCALE_1X, 742 - .drdy_en_reg = BU27008_REG_MODE_CONTROL3, 743 - .drdy_en_mask = BU27008_MASK_INT_EN, 744 - .valid_reg = BU27008_REG_MODE_CONTROL3, 745 - .meas_en_reg = BU27008_REG_MODE_CONTROL3, 746 - .meas_en_mask = BU27008_MASK_MEAS_EN, 747 - .chan_sel_reg = BU27008_REG_MODE_CONTROL3, 748 - .chan_sel_mask = BU27008_MASK_CHAN_SEL, 749 - .int_time_mask = BU27008_MASK_MEAS_MODE, 750 - .part_id = BU27008_ID, 751 - }; 752 - 753 - #define BU27008_MAX_VALID_RESULT_WAIT_US 50000 754 - #define BU27008_VALID_RESULT_WAIT_QUANTA_US 1000 755 - 756 - static int bu27008_chan_read_data(struct bu27008_data *data, int reg, int *val) 757 - { 758 - int ret, valid; 759 - __le16 tmp; 760 - 761 - ret = regmap_read_poll_timeout(data->regmap, data->cd->valid_reg, 762 - valid, (valid & BU27008_MASK_VALID), 763 - BU27008_VALID_RESULT_WAIT_QUANTA_US, 764 - BU27008_MAX_VALID_RESULT_WAIT_US); 765 - if (ret) 766 - return ret; 767 - 768 - ret = regmap_bulk_read(data->regmap, reg, &tmp, sizeof(tmp)); 769 - if (ret) 770 - dev_err(data->dev, "Reading channel data failed\n"); 771 - 772 - *val = le16_to_cpu(tmp); 773 - 774 - return ret; 775 - } 776 - 777 - static int bu27008_get_gain(struct bu27008_data *data, struct iio_gts *gts, int *gain) 778 - { 779 - int ret, sel; 780 - 781 - ret = data->cd->get_gain_sel(data, &sel); 782 - if (ret) 783 - return ret; 784 - 785 - ret = iio_gts_find_gain_by_sel(gts, sel); 786 - if (ret < 0) { 787 - dev_err(data->dev, "unknown gain value 0x%x\n", sel); 788 - return ret; 789 - } 790 - 791 - *gain = ret; 792 - 793 - return 0; 794 - } 795 - 796 - static int bu27008_set_gain(struct bu27008_data *data, int gain) 797 - { 798 - int ret; 799 - 800 - ret = iio_gts_find_sel_by_gain(&data->gts, gain); 801 - if (ret < 0) 802 - return ret; 803 - 804 - return data->cd->write_gain_sel(data, ret); 805 - } 806 - 807 - static int bu27008_get_int_time_sel(struct bu27008_data *data, int *sel) 808 - { 809 - int ret, val; 810 - 811 - ret = regmap_read(data->regmap, BU27008_REG_MODE_CONTROL1, &val); 812 - if (ret) 813 - return ret; 814 - 815 - val &= data->cd->int_time_mask; 816 - val >>= ffs(data->cd->int_time_mask) - 1; 817 - 818 - *sel = val; 819 - 820 - return 0; 821 - } 822 - 823 - static int bu27008_set_int_time_sel(struct bu27008_data *data, int sel) 824 - { 825 - sel <<= ffs(data->cd->int_time_mask) - 1; 826 - 827 - return regmap_update_bits(data->regmap, BU27008_REG_MODE_CONTROL1, 828 - data->cd->int_time_mask, sel); 829 - } 830 - 831 - static int bu27008_get_int_time_us(struct bu27008_data *data) 832 - { 833 - int ret, sel; 834 - 835 - ret = bu27008_get_int_time_sel(data, &sel); 836 - if (ret) 837 - return ret; 838 - 839 - return iio_gts_find_int_time_by_sel(&data->gts, sel); 840 - } 841 - 842 - static int _bu27008_get_scale(struct bu27008_data *data, bool ir, int *val, 843 - int *val2) 844 - { 845 - struct iio_gts *gts; 846 - int gain, ret; 847 - 848 - if (ir) 849 - gts = &data->gts_ir; 850 - else 851 - gts = &data->gts; 852 - 853 - ret = bu27008_get_gain(data, gts, &gain); 854 - if (ret) 855 - return ret; 856 - 857 - ret = bu27008_get_int_time_us(data); 858 - if (ret < 0) 859 - return ret; 860 - 861 - return iio_gts_get_scale(gts, gain, ret, val, val2); 862 - } 863 - 864 - static int bu27008_get_scale(struct bu27008_data *data, bool ir, int *val, 865 - int *val2) 866 - { 867 - int ret; 868 - 869 - mutex_lock(&data->mutex); 870 - ret = _bu27008_get_scale(data, ir, val, val2); 871 - mutex_unlock(&data->mutex); 872 - 873 - return ret; 874 - } 875 - 876 - static int bu27008_set_int_time(struct bu27008_data *data, int time) 877 - { 878 - int ret; 879 - 880 - ret = iio_gts_find_sel_by_int_time(&data->gts, time); 881 - if (ret < 0) 882 - return ret; 883 - 884 - return bu27008_set_int_time_sel(data, ret); 885 - } 886 - 887 - /* Try to change the time so that the scale is maintained */ 888 - static int bu27008_try_set_int_time(struct bu27008_data *data, int int_time_new) 889 - { 890 - int ret, old_time_sel, new_time_sel, old_gain, new_gain; 891 - 892 - mutex_lock(&data->mutex); 893 - 894 - ret = bu27008_get_int_time_sel(data, &old_time_sel); 895 - if (ret < 0) 896 - goto unlock_out; 897 - 898 - if (!iio_gts_valid_time(&data->gts, int_time_new)) { 899 - dev_dbg(data->dev, "Unsupported integration time %u\n", 900 - int_time_new); 901 - 902 - ret = -EINVAL; 903 - goto unlock_out; 904 - } 905 - 906 - /* If we already use requested time, then we're done */ 907 - new_time_sel = iio_gts_find_sel_by_int_time(&data->gts, int_time_new); 908 - if (new_time_sel == old_time_sel) 909 - goto unlock_out; 910 - 911 - ret = bu27008_get_gain(data, &data->gts, &old_gain); 912 - if (ret) 913 - goto unlock_out; 914 - 915 - ret = iio_gts_find_new_gain_sel_by_old_gain_time(&data->gts, old_gain, 916 - old_time_sel, new_time_sel, &new_gain); 917 - if (ret) { 918 - int scale1, scale2; 919 - bool ok; 920 - 921 - _bu27008_get_scale(data, false, &scale1, &scale2); 922 - dev_dbg(data->dev, 923 - "Can't support time %u with current scale %u %u\n", 924 - int_time_new, scale1, scale2); 925 - 926 - if (new_gain < 0) 927 - goto unlock_out; 928 - 929 - /* 930 - * If caller requests for integration time change and we 931 - * can't support the scale - then the caller should be 932 - * prepared to 'pick up the pieces and deal with the 933 - * fact that the scale changed'. 934 - */ 935 - ret = iio_find_closest_gain_low(&data->gts, new_gain, &ok); 936 - if (!ok) 937 - dev_dbg(data->dev, "optimal gain out of range\n"); 938 - 939 - if (ret < 0) { 940 - dev_dbg(data->dev, 941 - "Total gain increase. Risk of saturation"); 942 - ret = iio_gts_get_min_gain(&data->gts); 943 - if (ret < 0) 944 - goto unlock_out; 945 - } 946 - new_gain = ret; 947 - dev_dbg(data->dev, "scale changed, new gain %u\n", new_gain); 948 - } 949 - 950 - ret = bu27008_set_gain(data, new_gain); 951 - if (ret) 952 - goto unlock_out; 953 - 954 - ret = bu27008_set_int_time(data, int_time_new); 955 - 956 - unlock_out: 957 - mutex_unlock(&data->mutex); 958 - 959 - return ret; 960 - } 961 - 962 - static int bu27008_meas_set(struct bu27008_data *data, bool enable) 963 - { 964 - if (enable) 965 - return regmap_set_bits(data->regmap, data->cd->meas_en_reg, 966 - data->cd->meas_en_mask); 967 - return regmap_clear_bits(data->regmap, data->cd->meas_en_reg, 968 - data->cd->meas_en_mask); 969 - } 970 - 971 - static int bu27008_chan_cfg(struct bu27008_data *data, 972 - struct iio_chan_spec const *chan) 973 - { 974 - int chan_sel; 975 - 976 - if (chan->scan_index == BU27008_BLUE) 977 - chan_sel = BU27008_BLUE2_CLEAR3; 978 - else 979 - chan_sel = BU27008_CLEAR2_IR3; 980 - 981 - /* 982 - * prepare bitfield for channel sel. The FIELD_PREP works only when 983 - * mask is constant. In our case the mask is assigned based on the 984 - * chip type. Hence the open-coded FIELD_PREP here. We don't bother 985 - * zeroing the irrelevant bits though - update_bits takes care of that. 986 - */ 987 - chan_sel <<= ffs(data->cd->chan_sel_mask) - 1; 988 - 989 - return regmap_update_bits(data->regmap, data->cd->chan_sel_reg, 990 - BU27008_MASK_CHAN_SEL, chan_sel); 991 - } 992 - 993 - static int bu27008_read_one(struct bu27008_data *data, struct iio_dev *idev, 994 - struct iio_chan_spec const *chan, int *val, int *val2) 995 - { 996 - int ret, int_time; 997 - 998 - ret = bu27008_chan_cfg(data, chan); 999 - if (ret) 1000 - return ret; 1001 - 1002 - ret = bu27008_meas_set(data, true); 1003 - if (ret) 1004 - return ret; 1005 - 1006 - ret = bu27008_get_int_time_us(data); 1007 - if (ret < 0) 1008 - int_time = BU27008_MEAS_TIME_MAX_MS; 1009 - else 1010 - int_time = ret / USEC_PER_MSEC; 1011 - 1012 - msleep(int_time); 1013 - 1014 - ret = bu27008_chan_read_data(data, chan->address, val); 1015 - if (!ret) 1016 - ret = IIO_VAL_INT; 1017 - 1018 - if (bu27008_meas_set(data, false)) 1019 - dev_warn(data->dev, "measurement disabling failed\n"); 1020 - 1021 - return ret; 1022 - } 1023 - 1024 - #define BU27008_LUX_DATA_RED 0 1025 - #define BU27008_LUX_DATA_GREEN 1 1026 - #define BU27008_LUX_DATA_BLUE 2 1027 - #define BU27008_LUX_DATA_IR 3 1028 - #define LUX_DATA_SIZE (BU27008_NUM_HW_CHANS * sizeof(__le16)) 1029 - 1030 - static int bu27008_read_lux_chans(struct bu27008_data *data, unsigned int time, 1031 - __le16 *chan_data) 1032 - { 1033 - int ret, chan_sel, tmpret, valid; 1034 - 1035 - chan_sel = BU27008_BLUE2_IR3 << (ffs(data->cd->chan_sel_mask) - 1); 1036 - 1037 - ret = regmap_update_bits(data->regmap, data->cd->chan_sel_reg, 1038 - data->cd->chan_sel_mask, chan_sel); 1039 - if (ret) 1040 - return ret; 1041 - 1042 - ret = bu27008_meas_set(data, true); 1043 - if (ret) 1044 - return ret; 1045 - 1046 - msleep(time / USEC_PER_MSEC); 1047 - 1048 - ret = regmap_read_poll_timeout(data->regmap, data->cd->valid_reg, 1049 - valid, (valid & BU27008_MASK_VALID), 1050 - BU27008_VALID_RESULT_WAIT_QUANTA_US, 1051 - BU27008_MAX_VALID_RESULT_WAIT_US); 1052 - if (ret) 1053 - goto out; 1054 - 1055 - ret = regmap_bulk_read(data->regmap, BU27008_REG_DATA0_LO, chan_data, 1056 - LUX_DATA_SIZE); 1057 - if (ret) 1058 - goto out; 1059 - out: 1060 - tmpret = bu27008_meas_set(data, false); 1061 - if (tmpret) 1062 - dev_warn(data->dev, "Stopping measurement failed\n"); 1063 - 1064 - return ret; 1065 - } 1066 - 1067 - /* 1068 - * Following equation for computing lux out of register values was given by 1069 - * ROHM HW colleagues; 1070 - * 1071 - * Red = RedData*1024 / Gain * 20 / meas_mode 1072 - * Green = GreenData* 1024 / Gain * 20 / meas_mode 1073 - * Blue = BlueData* 1024 / Gain * 20 / meas_mode 1074 - * IR = IrData* 1024 / Gain * 20 / meas_mode 1075 - * 1076 - * where meas_mode is the integration time in mS / 10 1077 - * 1078 - * IRratio = (IR > 0.18 * Green) ? 0 : 1 1079 - * 1080 - * Lx = max(c1*Red + c2*Green + c3*Blue,0) 1081 - * 1082 - * for 1083 - * IRratio 0: c1 = -0.00002237, c2 = 0.0003219, c3 = -0.000120371 1084 - * IRratio 1: c1 = -0.00001074, c2 = 0.000305415, c3 = -0.000129367 1085 - */ 1086 - 1087 - /* 1088 - * The max chan data is 0xffff. When we multiply it by 1024 * 20, we'll get 1089 - * 0x4FFFB000 which still fits in 32-bit integer. This won't overflow. 1090 - */ 1091 - #define NORM_CHAN_DATA_FOR_LX_CALC(chan, gain, time) (le16_to_cpu(chan) * \ 1092 - 1024 * 20 / (gain) / (time)) 1093 - static u64 bu27008_calc_nlux(struct bu27008_data *data, __le16 *lux_data, 1094 - unsigned int gain, unsigned int gain_ir, unsigned int time) 1095 - { 1096 - unsigned int red, green, blue, ir; 1097 - s64 c1, c2, c3, nlux; 1098 - 1099 - time /= 10000; 1100 - ir = NORM_CHAN_DATA_FOR_LX_CALC(lux_data[BU27008_LUX_DATA_IR], gain_ir, time); 1101 - red = NORM_CHAN_DATA_FOR_LX_CALC(lux_data[BU27008_LUX_DATA_RED], gain, time); 1102 - green = NORM_CHAN_DATA_FOR_LX_CALC(lux_data[BU27008_LUX_DATA_GREEN], gain, time); 1103 - blue = NORM_CHAN_DATA_FOR_LX_CALC(lux_data[BU27008_LUX_DATA_BLUE], gain, time); 1104 - 1105 - if ((u64)ir * 100LLU > (u64)green * 18LLU) { 1106 - c1 = -22370; 1107 - c2 = 321900; 1108 - c3 = -120371; 1109 - } else { 1110 - c1 = -10740; 1111 - c2 = 305415; 1112 - c3 = -129367; 1113 - } 1114 - nlux = c1 * red + c2 * green + c3 * blue; 1115 - 1116 - return max_t(s64, 0, nlux); 1117 - } 1118 - 1119 - static int bu27008_get_time_n_gains(struct bu27008_data *data, 1120 - unsigned int *gain, unsigned int *gain_ir, unsigned int *time) 1121 - { 1122 - int ret; 1123 - 1124 - ret = bu27008_get_gain(data, &data->gts, gain); 1125 - if (ret < 0) 1126 - return ret; 1127 - 1128 - ret = bu27008_get_gain(data, &data->gts_ir, gain_ir); 1129 - if (ret < 0) 1130 - return ret; 1131 - 1132 - ret = bu27008_get_int_time_us(data); 1133 - if (ret < 0) 1134 - return ret; 1135 - 1136 - /* Max integration time is 400000. Fits in signed int. */ 1137 - *time = ret; 1138 - 1139 - return 0; 1140 - } 1141 - 1142 - struct bu27008_buf { 1143 - __le16 chan[BU27008_NUM_HW_CHANS]; 1144 - u64 lux __aligned(8); 1145 - s64 ts __aligned(8); 1146 - }; 1147 - 1148 - static int bu27008_buffer_fill_lux(struct bu27008_data *data, 1149 - struct bu27008_buf *raw) 1150 - { 1151 - unsigned int gain, gain_ir, time; 1152 - int ret; 1153 - 1154 - ret = bu27008_get_time_n_gains(data, &gain, &gain_ir, &time); 1155 - if (ret) 1156 - return ret; 1157 - 1158 - raw->lux = bu27008_calc_nlux(data, raw->chan, gain, gain_ir, time); 1159 - 1160 - return 0; 1161 - } 1162 - 1163 - static int bu27008_read_lux(struct bu27008_data *data, struct iio_dev *idev, 1164 - struct iio_chan_spec const *chan, 1165 - int *val, int *val2) 1166 - { 1167 - __le16 lux_data[BU27008_NUM_HW_CHANS]; 1168 - unsigned int gain, gain_ir, time; 1169 - u64 nlux; 1170 - int ret; 1171 - 1172 - ret = bu27008_get_time_n_gains(data, &gain, &gain_ir, &time); 1173 - if (ret) 1174 - return ret; 1175 - 1176 - ret = bu27008_read_lux_chans(data, time, lux_data); 1177 - if (ret) 1178 - return ret; 1179 - 1180 - nlux = bu27008_calc_nlux(data, lux_data, gain, gain_ir, time); 1181 - *val = (int)nlux; 1182 - *val2 = nlux >> 32LLU; 1183 - 1184 - return IIO_VAL_INT_64; 1185 - } 1186 - 1187 - static int bu27008_read_raw(struct iio_dev *idev, 1188 - struct iio_chan_spec const *chan, 1189 - int *val, int *val2, long mask) 1190 - { 1191 - struct bu27008_data *data = iio_priv(idev); 1192 - int busy, ret; 1193 - 1194 - switch (mask) { 1195 - case IIO_CHAN_INFO_RAW: 1196 - busy = iio_device_claim_direct_mode(idev); 1197 - if (busy) 1198 - return -EBUSY; 1199 - 1200 - mutex_lock(&data->mutex); 1201 - if (chan->type == IIO_LIGHT) 1202 - ret = bu27008_read_lux(data, idev, chan, val, val2); 1203 - else 1204 - ret = bu27008_read_one(data, idev, chan, val, val2); 1205 - mutex_unlock(&data->mutex); 1206 - 1207 - iio_device_release_direct_mode(idev); 1208 - 1209 - return ret; 1210 - 1211 - case IIO_CHAN_INFO_SCALE: 1212 - if (chan->type == IIO_LIGHT) { 1213 - *val = 0; 1214 - *val2 = 1; 1215 - return IIO_VAL_INT_PLUS_NANO; 1216 - } 1217 - ret = bu27008_get_scale(data, chan->scan_index == BU27008_IR, 1218 - val, val2); 1219 - if (ret) 1220 - return ret; 1221 - 1222 - return IIO_VAL_INT_PLUS_NANO; 1223 - 1224 - case IIO_CHAN_INFO_INT_TIME: 1225 - ret = bu27008_get_int_time_us(data); 1226 - if (ret < 0) 1227 - return ret; 1228 - 1229 - *val = 0; 1230 - *val2 = ret; 1231 - 1232 - return IIO_VAL_INT_PLUS_MICRO; 1233 - 1234 - default: 1235 - return -EINVAL; 1236 - } 1237 - } 1238 - 1239 - /* Called if the new scale could not be supported with existing int-time */ 1240 - static int bu27008_try_find_new_time_gain(struct bu27008_data *data, int val, 1241 - int val2, int *gain_sel) 1242 - { 1243 - int i, ret, new_time_sel; 1244 - 1245 - for (i = 0; i < data->gts.num_itime; i++) { 1246 - new_time_sel = data->gts.itime_table[i].sel; 1247 - ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts, 1248 - new_time_sel, val, val2, gain_sel); 1249 - if (!ret) 1250 - break; 1251 - } 1252 - if (i == data->gts.num_itime) { 1253 - dev_err(data->dev, "Can't support scale %u %u\n", val, val2); 1254 - 1255 - return -EINVAL; 1256 - } 1257 - 1258 - return bu27008_set_int_time_sel(data, new_time_sel); 1259 - } 1260 - 1261 - static int bu27008_set_scale(struct bu27008_data *data, 1262 - struct iio_chan_spec const *chan, 1263 - int val, int val2) 1264 - { 1265 - int ret, gain_sel, time_sel; 1266 - 1267 - if (chan->scan_index == BU27008_IR) 1268 - return -EINVAL; 1269 - 1270 - mutex_lock(&data->mutex); 1271 - 1272 - ret = bu27008_get_int_time_sel(data, &time_sel); 1273 - if (ret < 0) 1274 - goto unlock_out; 1275 - 1276 - ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts, time_sel, 1277 - val, val2, &gain_sel); 1278 - if (ret) { 1279 - ret = bu27008_try_find_new_time_gain(data, val, val2, &gain_sel); 1280 - if (ret) 1281 - goto unlock_out; 1282 - 1283 - } 1284 - ret = data->cd->write_gain_sel(data, gain_sel); 1285 - 1286 - unlock_out: 1287 - mutex_unlock(&data->mutex); 1288 - 1289 - return ret; 1290 - } 1291 - 1292 - static int bu27008_write_raw_get_fmt(struct iio_dev *indio_dev, 1293 - struct iio_chan_spec const *chan, 1294 - long mask) 1295 - { 1296 - 1297 - switch (mask) { 1298 - case IIO_CHAN_INFO_SCALE: 1299 - return IIO_VAL_INT_PLUS_NANO; 1300 - case IIO_CHAN_INFO_INT_TIME: 1301 - return IIO_VAL_INT_PLUS_MICRO; 1302 - default: 1303 - return -EINVAL; 1304 - } 1305 - } 1306 - 1307 - static int bu27008_write_raw(struct iio_dev *idev, 1308 - struct iio_chan_spec const *chan, 1309 - int val, int val2, long mask) 1310 - { 1311 - struct bu27008_data *data = iio_priv(idev); 1312 - int ret; 1313 - 1314 - /* 1315 - * Do not allow changing scale when measurement is ongoing as doing so 1316 - * could make values in the buffer inconsistent. 1317 - */ 1318 - ret = iio_device_claim_direct_mode(idev); 1319 - if (ret) 1320 - return ret; 1321 - 1322 - switch (mask) { 1323 - case IIO_CHAN_INFO_SCALE: 1324 - ret = bu27008_set_scale(data, chan, val, val2); 1325 - break; 1326 - case IIO_CHAN_INFO_INT_TIME: 1327 - if (val) { 1328 - ret = -EINVAL; 1329 - break; 1330 - } 1331 - ret = bu27008_try_set_int_time(data, val2); 1332 - break; 1333 - default: 1334 - ret = -EINVAL; 1335 - break; 1336 - } 1337 - iio_device_release_direct_mode(idev); 1338 - 1339 - return ret; 1340 - } 1341 - 1342 - static int bu27008_read_avail(struct iio_dev *idev, 1343 - struct iio_chan_spec const *chan, const int **vals, 1344 - int *type, int *length, long mask) 1345 - { 1346 - struct bu27008_data *data = iio_priv(idev); 1347 - 1348 - switch (mask) { 1349 - case IIO_CHAN_INFO_INT_TIME: 1350 - return iio_gts_avail_times(&data->gts, vals, type, length); 1351 - case IIO_CHAN_INFO_SCALE: 1352 - if (chan->channel2 == IIO_MOD_LIGHT_IR) 1353 - return iio_gts_all_avail_scales(&data->gts_ir, vals, 1354 - type, length); 1355 - return iio_gts_all_avail_scales(&data->gts, vals, type, length); 1356 - default: 1357 - return -EINVAL; 1358 - } 1359 - } 1360 - 1361 - static int bu27008_update_scan_mode(struct iio_dev *idev, 1362 - const unsigned long *scan_mask) 1363 - { 1364 - struct bu27008_data *data = iio_priv(idev); 1365 - int chan_sel; 1366 - 1367 - /* Configure channel selection */ 1368 - if (test_bit(BU27008_BLUE, idev->active_scan_mask)) { 1369 - if (test_bit(BU27008_CLEAR, idev->active_scan_mask)) 1370 - chan_sel = BU27008_BLUE2_CLEAR3; 1371 - else 1372 - chan_sel = BU27008_BLUE2_IR3; 1373 - } else { 1374 - chan_sel = BU27008_CLEAR2_IR3; 1375 - } 1376 - 1377 - chan_sel <<= ffs(data->cd->chan_sel_mask) - 1; 1378 - 1379 - return regmap_update_bits(data->regmap, data->cd->chan_sel_reg, 1380 - data->cd->chan_sel_mask, chan_sel); 1381 - } 1382 - 1383 - static const struct iio_info bu27008_info = { 1384 - .read_raw = &bu27008_read_raw, 1385 - .write_raw = &bu27008_write_raw, 1386 - .write_raw_get_fmt = &bu27008_write_raw_get_fmt, 1387 - .read_avail = &bu27008_read_avail, 1388 - .update_scan_mode = bu27008_update_scan_mode, 1389 - .validate_trigger = iio_validate_own_trigger, 1390 - }; 1391 - 1392 - static int bu27008_trigger_set_state(struct iio_trigger *trig, bool state) 1393 - { 1394 - struct bu27008_data *data = iio_trigger_get_drvdata(trig); 1395 - int ret; 1396 - 1397 - 1398 - if (state) 1399 - ret = regmap_set_bits(data->regmap, data->cd->drdy_en_reg, 1400 - data->cd->drdy_en_mask); 1401 - else 1402 - ret = regmap_clear_bits(data->regmap, data->cd->drdy_en_reg, 1403 - data->cd->drdy_en_mask); 1404 - if (ret) 1405 - dev_err(data->dev, "Failed to set trigger state\n"); 1406 - 1407 - return ret; 1408 - } 1409 - 1410 - static void bu27008_trigger_reenable(struct iio_trigger *trig) 1411 - { 1412 - struct bu27008_data *data = iio_trigger_get_drvdata(trig); 1413 - 1414 - enable_irq(data->irq); 1415 - } 1416 - 1417 - static const struct iio_trigger_ops bu27008_trigger_ops = { 1418 - .set_trigger_state = bu27008_trigger_set_state, 1419 - .reenable = bu27008_trigger_reenable, 1420 - }; 1421 - 1422 - static irqreturn_t bu27008_trigger_handler(int irq, void *p) 1423 - { 1424 - struct iio_poll_func *pf = p; 1425 - struct iio_dev *idev = pf->indio_dev; 1426 - struct bu27008_data *data = iio_priv(idev); 1427 - struct bu27008_buf raw; 1428 - int ret, dummy; 1429 - 1430 - memset(&raw, 0, sizeof(raw)); 1431 - 1432 - /* 1433 - * After some measurements, it seems reading the 1434 - * BU27008_REG_MODE_CONTROL3 debounces the IRQ line 1435 - */ 1436 - ret = regmap_read(data->regmap, data->cd->valid_reg, &dummy); 1437 - if (ret < 0) 1438 - goto err_read; 1439 - 1440 - ret = regmap_bulk_read(data->regmap, BU27008_REG_DATA0_LO, &raw.chan, 1441 - sizeof(raw.chan)); 1442 - if (ret < 0) 1443 - goto err_read; 1444 - 1445 - if (test_bit(BU27008_LUX, idev->active_scan_mask)) { 1446 - ret = bu27008_buffer_fill_lux(data, &raw); 1447 - if (ret) 1448 - goto err_read; 1449 - } 1450 - 1451 - iio_push_to_buffers_with_timestamp(idev, &raw, pf->timestamp); 1452 - err_read: 1453 - iio_trigger_notify_done(idev->trig); 1454 - 1455 - return IRQ_HANDLED; 1456 - } 1457 - 1458 - static int bu27008_buffer_preenable(struct iio_dev *idev) 1459 - { 1460 - struct bu27008_data *data = iio_priv(idev); 1461 - 1462 - return bu27008_meas_set(data, true); 1463 - } 1464 - 1465 - static int bu27008_buffer_postdisable(struct iio_dev *idev) 1466 - { 1467 - struct bu27008_data *data = iio_priv(idev); 1468 - 1469 - return bu27008_meas_set(data, false); 1470 - } 1471 - 1472 - static const struct iio_buffer_setup_ops bu27008_buffer_ops = { 1473 - .preenable = bu27008_buffer_preenable, 1474 - .postdisable = bu27008_buffer_postdisable, 1475 - }; 1476 - 1477 - static irqreturn_t bu27008_data_rdy_poll(int irq, void *private) 1478 - { 1479 - /* 1480 - * The BU27008 keeps IRQ asserted until we read the VALID bit from 1481 - * a register. We need to keep the IRQ disabled until then. 1482 - */ 1483 - disable_irq_nosync(irq); 1484 - iio_trigger_poll(private); 1485 - 1486 - return IRQ_HANDLED; 1487 - } 1488 - 1489 - static int bu27008_setup_trigger(struct bu27008_data *data, struct iio_dev *idev) 1490 - { 1491 - struct iio_trigger *itrig; 1492 - char *name; 1493 - int ret; 1494 - 1495 - ret = devm_iio_triggered_buffer_setup(data->dev, idev, 1496 - &iio_pollfunc_store_time, 1497 - bu27008_trigger_handler, 1498 - &bu27008_buffer_ops); 1499 - if (ret) 1500 - return dev_err_probe(data->dev, ret, 1501 - "iio_triggered_buffer_setup_ext FAIL\n"); 1502 - 1503 - itrig = devm_iio_trigger_alloc(data->dev, "%sdata-rdy-dev%d", 1504 - idev->name, iio_device_id(idev)); 1505 - if (!itrig) 1506 - return -ENOMEM; 1507 - 1508 - data->trig = itrig; 1509 - 1510 - itrig->ops = &bu27008_trigger_ops; 1511 - iio_trigger_set_drvdata(itrig, data); 1512 - 1513 - name = devm_kasprintf(data->dev, GFP_KERNEL, "%s-bu27008", 1514 - dev_name(data->dev)); 1515 - 1516 - ret = devm_request_irq(data->dev, data->irq, 1517 - &bu27008_data_rdy_poll, 1518 - 0, name, itrig); 1519 - if (ret) 1520 - return dev_err_probe(data->dev, ret, "Could not request IRQ\n"); 1521 - 1522 - ret = devm_iio_trigger_register(data->dev, itrig); 1523 - if (ret) 1524 - return dev_err_probe(data->dev, ret, 1525 - "Trigger registration failed\n"); 1526 - 1527 - /* set default trigger */ 1528 - idev->trig = iio_trigger_get(itrig); 1529 - 1530 - return 0; 1531 - } 1532 - 1533 - static int bu27008_probe(struct i2c_client *i2c) 1534 - { 1535 - struct device *dev = &i2c->dev; 1536 - struct bu27008_data *data; 1537 - struct regmap *regmap; 1538 - unsigned int part_id, reg; 1539 - struct iio_dev *idev; 1540 - int ret; 1541 - 1542 - idev = devm_iio_device_alloc(dev, sizeof(*data)); 1543 - if (!idev) 1544 - return -ENOMEM; 1545 - 1546 - ret = devm_regulator_get_enable(dev, "vdd"); 1547 - if (ret) 1548 - return dev_err_probe(dev, ret, "Failed to get regulator\n"); 1549 - 1550 - data = iio_priv(idev); 1551 - 1552 - data->cd = device_get_match_data(&i2c->dev); 1553 - if (!data->cd) 1554 - return -ENODEV; 1555 - 1556 - regmap = devm_regmap_init_i2c(i2c, data->cd->regmap_cfg); 1557 - if (IS_ERR(regmap)) 1558 - return dev_err_probe(dev, PTR_ERR(regmap), 1559 - "Failed to initialize Regmap\n"); 1560 - 1561 - 1562 - ret = regmap_read(regmap, BU27008_REG_SYSTEM_CONTROL, &reg); 1563 - if (ret) 1564 - return dev_err_probe(dev, ret, "Failed to access sensor\n"); 1565 - 1566 - part_id = FIELD_GET(BU27008_MASK_PART_ID, reg); 1567 - 1568 - if (part_id != data->cd->part_id) 1569 - dev_warn(dev, "unknown device 0x%x\n", part_id); 1570 - 1571 - ret = devm_iio_init_iio_gts(dev, data->cd->scale1x, 0, data->cd->gains, 1572 - data->cd->num_gains, data->cd->itimes, 1573 - data->cd->num_itimes, &data->gts); 1574 - if (ret) 1575 - return ret; 1576 - 1577 - ret = devm_iio_init_iio_gts(dev, data->cd->scale1x, 0, data->cd->gains_ir, 1578 - data->cd->num_gains_ir, data->cd->itimes, 1579 - data->cd->num_itimes, &data->gts_ir); 1580 - if (ret) 1581 - return ret; 1582 - 1583 - mutex_init(&data->mutex); 1584 - data->regmap = regmap; 1585 - data->dev = dev; 1586 - data->irq = i2c->irq; 1587 - 1588 - idev->channels = bu27008_channels; 1589 - idev->num_channels = ARRAY_SIZE(bu27008_channels); 1590 - idev->name = data->cd->name; 1591 - idev->info = &bu27008_info; 1592 - idev->modes = INDIO_DIRECT_MODE; 1593 - idev->available_scan_masks = bu27008_scan_masks; 1594 - 1595 - ret = data->cd->chip_init(data); 1596 - if (ret) 1597 - return ret; 1598 - 1599 - if (i2c->irq) { 1600 - ret = bu27008_setup_trigger(data, idev); 1601 - if (ret) 1602 - return ret; 1603 - } else { 1604 - dev_info(dev, "No IRQ, buffered mode disabled\n"); 1605 - } 1606 - 1607 - ret = devm_iio_device_register(dev, idev); 1608 - if (ret) 1609 - return dev_err_probe(dev, ret, 1610 - "Unable to register iio device\n"); 1611 - 1612 - return 0; 1613 - } 1614 - 1615 - static const struct of_device_id bu27008_of_match[] = { 1616 - { .compatible = "rohm,bu27008", .data = &bu27008_chip }, 1617 - { .compatible = "rohm,bu27010", .data = &bu27010_chip }, 1618 - { } 1619 - }; 1620 - MODULE_DEVICE_TABLE(of, bu27008_of_match); 1621 - 1622 - static struct i2c_driver bu27008_i2c_driver = { 1623 - .driver = { 1624 - .name = "bu27008", 1625 - .of_match_table = bu27008_of_match, 1626 - .probe_type = PROBE_PREFER_ASYNCHRONOUS, 1627 - }, 1628 - .probe = bu27008_probe, 1629 - }; 1630 - module_i2c_driver(bu27008_i2c_driver); 1631 - 1632 - MODULE_DESCRIPTION("ROHM BU27008 and BU27010 colour sensor driver"); 1633 - MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); 1634 - MODULE_LICENSE("GPL"); 1635 - MODULE_IMPORT_NS("IIO_GTS_HELPER");
+26 -49
drivers/iio/light/rohm-bu27034.c
··· 7 7 8 8 #include <linux/bitfield.h> 9 9 #include <linux/bits.h> 10 + #include <linux/cleanup.h> 10 11 #include <linux/device.h> 11 12 #include <linux/i2c.h> 12 13 #include <linux/module.h> ··· 206 205 struct { 207 206 u32 mlux; 208 207 __le16 channels[BU27034_NUM_HW_DATA_CHANS]; 209 - s64 ts __aligned(8); 208 + aligned_s64 ts; 210 209 } scan; 211 210 }; 212 211 ··· 396 395 int numg = ARRAY_SIZE(gains); 397 396 int ret, int_time_old, i; 398 397 399 - mutex_lock(&data->mutex); 398 + guard(mutex)(&data->mutex); 400 399 ret = bu27034_get_int_time(data); 401 400 if (ret < 0) 402 - goto unlock_out; 401 + return ret; 403 402 404 403 int_time_old = ret; 405 404 406 405 if (!iio_gts_valid_time(&data->gts, time_us)) { 407 406 dev_err(data->dev, "Unsupported integration time %u\n", 408 407 time_us); 409 - ret = -EINVAL; 410 - 411 - goto unlock_out; 408 + return -EINVAL; 412 409 } 413 410 414 - if (time_us == int_time_old) { 415 - ret = 0; 416 - goto unlock_out; 417 - } 411 + if (time_us == int_time_old) 412 + return 0; 418 413 419 414 for (i = 0; i < numg; i++) { 420 415 ret = bu27034_get_gain(data, gains[i].chan, &gains[i].old_gain); 421 416 if (ret) 422 - goto unlock_out; 417 + return 0; 423 418 424 419 ret = iio_gts_find_new_gain_by_old_gain_time(&data->gts, 425 420 gains[i].old_gain, ··· 431 434 gains[i].chan, time_us, scale1, scale2); 432 435 433 436 if (gains[i].new_gain < 0) 434 - goto unlock_out; 437 + return ret; 435 438 436 439 /* 437 440 * If caller requests for integration time change and we ··· 452 455 "Total gain increase. Risk of saturation"); 453 456 ret = iio_gts_get_min_gain(&data->gts); 454 457 if (ret < 0) 455 - goto unlock_out; 458 + return ret; 456 459 } 457 460 dev_dbg(data->dev, "chan %u scale changed\n", 458 461 gains[i].chan); ··· 465 468 for (i = 0; i < numg; i++) { 466 469 ret = bu27034_set_gain(data, gains[i].chan, gains[i].new_gain); 467 470 if (ret) 468 - goto unlock_out; 471 + return ret; 469 472 } 470 473 471 - ret = bu27034_set_int_time(data, time_us); 472 - 473 - unlock_out: 474 - mutex_unlock(&data->mutex); 475 - 476 - return ret; 474 + return bu27034_set_int_time(data, time_us); 477 475 } 478 476 479 477 static int bu27034_set_scale(struct bu27034_data *data, int chan, ··· 484 492 return -EINVAL; 485 493 } 486 494 487 - mutex_lock(&data->mutex); 495 + guard(mutex)(&data->mutex); 488 496 ret = regmap_read(data->regmap, BU27034_REG_MODE_CONTROL1, &time_sel); 489 497 if (ret) 490 - goto unlock_out; 498 + return ret; 491 499 492 500 ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts, time_sel, 493 501 val, val2, &gain_sel); ··· 510 518 511 519 ret = bu27034_get_gain(data, gain.chan, &gain.old_gain); 512 520 if (ret) 513 - goto unlock_out; 521 + return ret; 514 522 515 523 /* 516 524 * Iterate through all the times to see if we find one which ··· 543 551 if (!found) { 544 552 dev_dbg(data->dev, 545 553 "Can't set scale maintaining other channel\n"); 546 - ret = -EINVAL; 547 - 548 - goto unlock_out; 554 + return -EINVAL; 549 555 } 550 556 551 557 ret = bu27034_set_gain(data, gain.chan, gain.new_gain); 552 558 if (ret) 553 - goto unlock_out; 559 + return ret; 554 560 555 561 ret = regmap_update_bits(data->regmap, BU27034_REG_MODE_CONTROL1, 556 562 BU27034_MASK_MEAS_MODE, new_time_sel); 557 563 if (ret) 558 - goto unlock_out; 564 + return ret; 559 565 } 560 566 561 - ret = bu27034_write_gain_sel(data, chan, gain_sel); 562 - unlock_out: 563 - mutex_unlock(&data->mutex); 564 - 565 - return ret; 567 + return bu27034_write_gain_sel(data, chan, gain_sel); 566 568 } 567 569 568 570 /* ··· 1207 1221 struct task_struct *task; 1208 1222 int ret; 1209 1223 1210 - mutex_lock(&data->mutex); 1224 + guard(mutex)(&data->mutex); 1211 1225 ret = bu27034_meas_set(data, true); 1212 1226 if (ret) 1213 - goto unlock_out; 1227 + return ret; 1214 1228 1215 1229 task = kthread_run(bu27034_buffer_thread, idev, 1216 1230 "bu27034-buffering-%u", 1217 1231 iio_device_id(idev)); 1218 - if (IS_ERR(task)) { 1219 - ret = PTR_ERR(task); 1220 - goto unlock_out; 1221 - } 1232 + if (IS_ERR(task)) 1233 + return PTR_ERR(task); 1222 1234 1223 1235 data->task = task; 1224 1236 1225 - unlock_out: 1226 - mutex_unlock(&data->mutex); 1227 - 1228 - return ret; 1237 + return 0; 1229 1238 } 1230 1239 1231 1240 static int bu27034_buffer_disable(struct iio_dev *idev) 1232 1241 { 1233 1242 struct bu27034_data *data = iio_priv(idev); 1234 - int ret; 1235 1243 1236 - mutex_lock(&data->mutex); 1244 + guard(mutex)(&data->mutex); 1237 1245 if (data->task) { 1238 1246 kthread_stop(data->task); 1239 1247 data->task = NULL; 1240 1248 } 1241 1249 1242 - ret = bu27034_meas_set(data, false); 1243 - mutex_unlock(&data->mutex); 1244 - 1245 - return ret; 1250 + return bu27034_meas_set(data, false); 1246 1251 } 1247 1252 1248 1253 static const struct iio_buffer_setup_ops bu27034_buffer_ops = {
+1 -1
drivers/iio/light/rpr0521.c
··· 203 203 struct { 204 204 __le16 channels[3]; 205 205 u8 garbage; 206 - s64 ts __aligned(8); 206 + aligned_s64 ts; 207 207 } scan; 208 208 }; 209 209
+1 -1
drivers/iio/light/st_uvis25.h
··· 30 30 /* Ensure timestamp is naturally aligned */ 31 31 struct { 32 32 u8 chan; 33 - s64 ts __aligned(8); 33 + aligned_s64 ts; 34 34 } scan; 35 35 }; 36 36
+1 -1
drivers/iio/light/tcs3414.c
··· 56 56 /* Ensure timestamp is naturally aligned */ 57 57 struct { 58 58 u16 chans[4]; 59 - s64 timestamp __aligned(8); 59 + aligned_s64 timestamp; 60 60 } scan; 61 61 }; 62 62
+1 -1
drivers/iio/light/tcs3472.c
··· 67 67 /* Ensure timestamp is naturally aligned */ 68 68 struct { 69 69 u16 chans[4]; 70 - s64 timestamp __aligned(8); 70 + aligned_s64 timestamp; 71 71 } scan; 72 72 }; 73 73
+166 -114
drivers/iio/light/veml3235.c
··· 11 11 #include <linux/err.h> 12 12 #include <linux/i2c.h> 13 13 #include <linux/iio/iio.h> 14 + #include <linux/iio/iio-gts-helper.h> 14 15 #include <linux/module.h> 15 16 #include <linux/pm_runtime.h> 16 17 #include <linux/regmap.h> ··· 36 35 struct device *dev; 37 36 struct regmap *regmap; 38 37 struct veml3235_rf rf; 38 + struct iio_gts gts; 39 39 }; 40 40 41 - static const int veml3235_it_times[][2] = { 42 - { 0, 50000 }, 43 - { 0, 100000 }, 44 - { 0, 200000 }, 45 - { 0, 400000 }, 46 - { 0, 800000 }, 41 + static const struct iio_itime_sel_mul veml3235_it_sel[] = { 42 + GAIN_SCALE_ITIME_US(50000, 0, 1), 43 + GAIN_SCALE_ITIME_US(100000, 1, 2), 44 + GAIN_SCALE_ITIME_US(200000, 2, 4), 45 + GAIN_SCALE_ITIME_US(400000, 3, 8), 46 + GAIN_SCALE_ITIME_US(800000, 4, 16), 47 47 }; 48 48 49 - static const int veml3235_scale_vals[] = { 1, 2, 4, 8 }; 49 + /* 50 + * The MSB (DG) doubles the value of the rest of the field, which leads to 51 + * two possible combinations to obtain gain = 2 and gain = 4. The gain 52 + * handling can be simplified by restricting DG = 1 to the only gain that 53 + * really requires it, gain = 8. Note that "X10" is a reserved value. 54 + */ 55 + #define VEML3235_SEL_GAIN_X1 0 56 + #define VEML3235_SEL_GAIN_X2 1 57 + #define VEML3235_SEL_GAIN_X4 3 58 + #define VEML3235_SEL_GAIN_X8 7 59 + static const struct iio_gain_sel_pair veml3235_gain_sel[] = { 60 + GAIN_SCALE_GAIN(1, VEML3235_SEL_GAIN_X1), 61 + GAIN_SCALE_GAIN(2, VEML3235_SEL_GAIN_X2), 62 + GAIN_SCALE_GAIN(4, VEML3235_SEL_GAIN_X4), 63 + GAIN_SCALE_GAIN(8, VEML3235_SEL_GAIN_X8), 64 + }; 50 65 51 66 static int veml3235_power_on(struct veml3235_data *data) 52 67 { ··· 118 101 }, 119 102 }; 120 103 104 + static const struct regmap_range veml3235_readable_ranges[] = { 105 + regmap_reg_range(VEML3235_REG_CONF, VEML3235_REG_ID), 106 + }; 107 + 108 + static const struct regmap_access_table veml3235_readable_table = { 109 + .yes_ranges = veml3235_readable_ranges, 110 + .n_yes_ranges = ARRAY_SIZE(veml3235_readable_ranges), 111 + }; 112 + 113 + static const struct regmap_range veml3235_writable_ranges[] = { 114 + regmap_reg_range(VEML3235_REG_CONF, VEML3235_REG_CONF), 115 + }; 116 + 117 + static const struct regmap_access_table veml3235_writable_table = { 118 + .yes_ranges = veml3235_writable_ranges, 119 + .n_yes_ranges = ARRAY_SIZE(veml3235_writable_ranges), 120 + }; 121 + 122 + static const struct regmap_range veml3235_volatile_ranges[] = { 123 + regmap_reg_range(VEML3235_REG_WH_DATA, VEML3235_REG_ALS_DATA), 124 + }; 125 + 126 + static const struct regmap_access_table veml3235_volatile_table = { 127 + .yes_ranges = veml3235_volatile_ranges, 128 + .n_yes_ranges = ARRAY_SIZE(veml3235_volatile_ranges), 129 + }; 130 + 121 131 static const struct regmap_config veml3235_regmap_config = { 122 132 .name = "veml3235_regmap", 123 133 .reg_bits = 8, 124 134 .val_bits = 16, 125 135 .max_register = VEML3235_REG_ID, 126 136 .val_format_endian = REGMAP_ENDIAN_LITTLE, 137 + .rd_table = &veml3235_readable_table, 138 + .wr_table = &veml3235_writable_table, 139 + .volatile_table = &veml3235_volatile_table, 140 + .cache_type = REGCACHE_RBTREE, 127 141 }; 128 142 129 143 static int veml3235_get_it(struct veml3235_data *data, int *val, int *val2) 130 144 { 131 - int ret, reg; 145 + int ret, it_idx; 132 146 133 - ret = regmap_field_read(data->rf.it, &reg); 147 + ret = regmap_field_read(data->rf.it, &it_idx); 134 148 if (ret) 135 149 return ret; 136 150 137 - switch (reg) { 138 - case 0: 139 - *val2 = 50000; 140 - break; 141 - case 1: 142 - *val2 = 100000; 143 - break; 144 - case 2: 145 - *val2 = 200000; 146 - break; 147 - case 3: 148 - *val2 = 400000; 149 - break; 150 - case 4: 151 - *val2 = 800000; 152 - break; 153 - default: 154 - return -EINVAL; 155 - } 151 + ret = iio_gts_find_int_time_by_sel(&data->gts, it_idx); 152 + if (ret < 0) 153 + return ret; 156 154 155 + *val2 = ret; 157 156 *val = 0; 158 157 159 158 return IIO_VAL_INT_PLUS_MICRO; ··· 178 145 static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2) 179 146 { 180 147 struct veml3235_data *data = iio_priv(indio_dev); 181 - int ret, new_it; 148 + int ret, gain_idx, it_idx, new_gain, prev_gain, prev_it; 149 + bool in_range; 182 150 183 - if (val) 151 + if (val || !iio_gts_valid_time(&data->gts, val2)) 184 152 return -EINVAL; 185 153 186 - switch (val2) { 187 - case 50000: 188 - new_it = 0x00; 189 - break; 190 - case 100000: 191 - new_it = 0x01; 192 - break; 193 - case 200000: 194 - new_it = 0x02; 195 - break; 196 - case 400000: 197 - new_it = 0x03; 198 - break; 199 - case 800000: 200 - new_it = 0x04; 201 - break; 202 - default: 203 - return -EINVAL; 204 - } 205 - 206 - ret = regmap_field_write(data->rf.it, new_it); 207 - if (ret) { 208 - dev_err(data->dev, 209 - "failed to update integration time: %d\n", ret); 154 + ret = regmap_field_read(data->rf.it, &it_idx); 155 + if (ret) 210 156 return ret; 211 - } 212 157 213 - return 0; 158 + ret = regmap_field_read(data->rf.gain, &gain_idx); 159 + if (ret) 160 + return ret; 161 + 162 + prev_it = iio_gts_find_int_time_by_sel(&data->gts, it_idx); 163 + if (prev_it < 0) 164 + return prev_it; 165 + 166 + if (prev_it == val2) 167 + return 0; 168 + 169 + prev_gain = iio_gts_find_gain_by_sel(&data->gts, gain_idx); 170 + if (prev_gain < 0) 171 + return prev_gain; 172 + 173 + ret = iio_gts_find_new_gain_by_gain_time_min(&data->gts, prev_gain, prev_it, 174 + val2, &new_gain, &in_range); 175 + if (ret) 176 + return ret; 177 + 178 + if (!in_range) 179 + dev_dbg(data->dev, "Optimal gain out of range\n"); 180 + 181 + ret = iio_gts_find_sel_by_int_time(&data->gts, val2); 182 + if (ret < 0) 183 + return ret; 184 + 185 + ret = regmap_field_write(data->rf.it, ret); 186 + if (ret) 187 + return ret; 188 + 189 + ret = iio_gts_find_sel_by_gain(&data->gts, new_gain); 190 + if (ret < 0) 191 + return ret; 192 + 193 + return regmap_field_write(data->rf.gain, ret); 214 194 } 215 195 216 - static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2) 196 + static int veml3235_set_scale(struct iio_dev *indio_dev, int val, int val2) 217 197 { 218 198 struct veml3235_data *data = iio_priv(indio_dev); 219 - int ret, new_gain; 199 + int ret, it_idx, gain_sel, time_sel; 220 200 221 - if (val2 != 0) 222 - return -EINVAL; 223 - 224 - switch (val) { 225 - case 1: 226 - new_gain = 0x00; 227 - break; 228 - case 2: 229 - new_gain = 0x01; 230 - break; 231 - case 4: 232 - new_gain = 0x03; 233 - break; 234 - case 8: 235 - new_gain = 0x07; 236 - break; 237 - default: 238 - return -EINVAL; 239 - } 240 - 241 - ret = regmap_field_write(data->rf.gain, new_gain); 242 - if (ret) { 243 - dev_err(data->dev, "failed to set gain: %d\n", ret); 201 + ret = regmap_field_read(data->rf.it, &it_idx); 202 + if (ret) 244 203 return ret; 245 - } 246 204 247 - return 0; 205 + ret = iio_gts_find_gain_time_sel_for_scale(&data->gts, val, val2, 206 + &gain_sel, &time_sel); 207 + if (ret) 208 + return ret; 209 + 210 + ret = regmap_field_write(data->rf.it, time_sel); 211 + if (ret) 212 + return ret; 213 + 214 + return regmap_field_write(data->rf.gain, gain_sel); 248 215 } 249 216 250 - static int veml3235_get_gain(struct veml3235_data *data, int *val) 217 + static int veml3235_get_scale(struct veml3235_data *data, int *val, int *val2) 251 218 { 252 - int ret, reg; 219 + int gain, it, reg, ret; 253 220 254 221 ret = regmap_field_read(data->rf.gain, &reg); 255 222 if (ret) { ··· 257 224 return ret; 258 225 } 259 226 260 - switch (reg & 0x03) { 261 - case 0: 262 - *val = 1; 263 - break; 264 - case 1: 265 - *val = 2; 266 - break; 267 - case 3: 268 - *val = 4; 269 - break; 270 - default: 271 - return -EINVAL; 227 + gain = iio_gts_find_gain_by_sel(&data->gts, reg); 228 + if (gain < 0) 229 + return gain; 230 + 231 + ret = regmap_field_read(data->rf.it, &reg); 232 + if (ret) { 233 + dev_err(data->dev, "failed to read integration time %d\n", ret); 234 + return ret; 272 235 } 273 236 274 - /* Double gain */ 275 - if (reg & 0x04) 276 - *val *= 2; 237 + it = iio_gts_find_int_time_by_sel(&data->gts, reg); 238 + if (it < 0) 239 + return it; 277 240 278 - return IIO_VAL_INT; 241 + ret = iio_gts_get_scale(&data->gts, gain, it, val, val2); 242 + if (ret) 243 + return ret; 244 + 245 + return IIO_VAL_INT_PLUS_NANO; 279 246 } 280 247 281 248 static int veml3235_read_raw(struct iio_dev *indio_dev, ··· 309 276 case IIO_CHAN_INFO_INT_TIME: 310 277 return veml3235_get_it(data, val, val2); 311 278 case IIO_CHAN_INFO_SCALE: 312 - return veml3235_get_gain(data, val); 279 + return veml3235_get_scale(data, val, val2); 313 280 default: 314 281 return -EINVAL; 315 282 } ··· 320 287 const int **vals, int *type, int *length, 321 288 long mask) 322 289 { 290 + struct veml3235_data *data = iio_priv(indio_dev); 291 + 323 292 switch (mask) { 324 293 case IIO_CHAN_INFO_INT_TIME: 325 - *vals = (int *)&veml3235_it_times; 326 - *length = 2 * ARRAY_SIZE(veml3235_it_times); 327 - *type = IIO_VAL_INT_PLUS_MICRO; 328 - return IIO_AVAIL_LIST; 294 + return iio_gts_avail_times(&data->gts, vals, type, length); 329 295 case IIO_CHAN_INFO_SCALE: 330 - *vals = (int *)&veml3235_scale_vals; 331 - *length = ARRAY_SIZE(veml3235_scale_vals); 332 - *type = IIO_VAL_INT; 333 - return IIO_AVAIL_LIST; 296 + return iio_gts_all_avail_scales(&data->gts, vals, type, length); 297 + default: 298 + return -EINVAL; 299 + } 300 + } 301 + 302 + static int veml3235_write_raw_get_fmt(struct iio_dev *indio_dev, 303 + struct iio_chan_spec const *chan, 304 + long mask) 305 + { 306 + switch (mask) { 307 + case IIO_CHAN_INFO_SCALE: 308 + return IIO_VAL_INT_PLUS_NANO; 309 + case IIO_CHAN_INFO_INT_TIME: 310 + return IIO_VAL_INT_PLUS_MICRO; 334 311 default: 335 312 return -EINVAL; 336 313 } ··· 354 311 case IIO_CHAN_INFO_INT_TIME: 355 312 return veml3235_set_it(indio_dev, val, val2); 356 313 case IIO_CHAN_INFO_SCALE: 357 - return veml3235_set_gain(indio_dev, val, val2); 314 + return veml3235_set_scale(indio_dev, val, val2); 358 315 } 359 316 360 317 return -EINVAL; ··· 364 321 { 365 322 int ret, reg; 366 323 367 - ret = regmap_field_read(data->rf.id, &reg); 324 + ret = regmap_field_read(data->rf.id, &reg); 368 325 if (ret) { 369 326 dev_info(data->dev, "failed to read ID\n"); 370 327 return; ··· 414 371 struct device *dev = data->dev; 415 372 int ret; 416 373 374 + ret = devm_iio_init_iio_gts(data->dev, 0, 272640000, 375 + veml3235_gain_sel, ARRAY_SIZE(veml3235_gain_sel), 376 + veml3235_it_sel, ARRAY_SIZE(veml3235_it_sel), 377 + &data->gts); 378 + if (ret) 379 + return dev_err_probe(data->dev, ret, "failed to init iio gts\n"); 380 + 417 381 /* Set gain to 1 and integration time to 100 ms */ 418 382 ret = regmap_field_write(data->rf.gain, 0x00); 419 383 if (ret) ··· 439 389 } 440 390 441 391 static const struct iio_info veml3235_info = { 442 - .read_raw = veml3235_read_raw, 443 - .read_avail = veml3235_read_avail, 392 + .read_raw = veml3235_read_raw, 393 + .read_avail = veml3235_read_avail, 444 394 .write_raw = veml3235_write_raw, 395 + .write_raw_get_fmt = veml3235_write_raw_get_fmt, 445 396 }; 446 397 447 398 static int veml3235_probe(struct i2c_client *client) ··· 544 493 MODULE_AUTHOR("Javier Carrasco <javier.carrasco.cruz@gmail.com>"); 545 494 MODULE_DESCRIPTION("VEML3235 Ambient Light Sensor"); 546 495 MODULE_LICENSE("GPL"); 496 + MODULE_IMPORT_NS("IIO_GTS_HELPER");
+76
drivers/iio/light/veml6030.c
··· 28 28 #include <linux/iio/iio.h> 29 29 #include <linux/iio/sysfs.h> 30 30 #include <linux/iio/events.h> 31 + #include <linux/iio/trigger_consumer.h> 32 + #include <linux/iio/triggered_buffer.h> 31 33 32 34 /* Device registers */ 33 35 #define VEML6030_REG_ALS_CONF 0x00 ··· 39 37 #define VEML6030_REG_ALS_DATA 0x04 40 38 #define VEML6030_REG_WH_DATA 0x05 41 39 #define VEML6030_REG_ALS_INT 0x06 40 + #define VEML6030_REG_DATA(ch) (VEML6030_REG_ALS_DATA + (ch)) 42 41 43 42 /* Bit masks for specific functionality */ 44 43 #define VEML6030_ALS_IT GENMASK(9, 6) ··· 58 55 #define VEML6035_SENS BIT(12) 59 56 #define VEML6035_INT_CHAN BIT(3) 60 57 #define VEML6035_CHAN_EN BIT(2) 58 + 59 + enum veml6030_scan { 60 + VEML6030_SCAN_ALS, 61 + VEML6030_SCAN_WH, 62 + VEML6030_SCAN_TIMESTAMP, 63 + }; 61 64 62 65 struct veml603x_chip { 63 66 const char *name; ··· 251 242 BIT(IIO_CHAN_INFO_SCALE), 252 243 .event_spec = veml6030_event_spec, 253 244 .num_event_specs = ARRAY_SIZE(veml6030_event_spec), 245 + .scan_index = VEML6030_SCAN_ALS, 246 + .scan_type = { 247 + .sign = 'u', 248 + .realbits = 16, 249 + .storagebits = 16, 250 + .endianness = IIO_CPU, 251 + }, 254 252 }, 255 253 { 256 254 .type = IIO_INTENSITY, ··· 269 253 BIT(IIO_CHAN_INFO_SCALE), 270 254 .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 271 255 BIT(IIO_CHAN_INFO_SCALE), 256 + .scan_index = VEML6030_SCAN_WH, 257 + .scan_type = { 258 + .sign = 'u', 259 + .realbits = 16, 260 + .storagebits = 16, 261 + .endianness = IIO_CPU, 262 + }, 272 263 }, 264 + IIO_CHAN_SOFT_TIMESTAMP(VEML6030_SCAN_TIMESTAMP), 273 265 }; 274 266 275 267 static const struct iio_chan_spec veml7700_channels[] = { ··· 290 266 BIT(IIO_CHAN_INFO_SCALE), 291 267 .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 292 268 BIT(IIO_CHAN_INFO_SCALE), 269 + .scan_index = VEML6030_SCAN_ALS, 270 + .scan_type = { 271 + .sign = 'u', 272 + .realbits = 16, 273 + .storagebits = 16, 274 + .endianness = IIO_CPU, 275 + }, 293 276 }, 294 277 { 295 278 .type = IIO_INTENSITY, ··· 308 277 BIT(IIO_CHAN_INFO_SCALE), 309 278 .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 310 279 BIT(IIO_CHAN_INFO_SCALE), 280 + .scan_index = VEML6030_SCAN_WH, 281 + .scan_type = { 282 + .sign = 'u', 283 + .realbits = 16, 284 + .storagebits = 16, 285 + .endianness = IIO_CPU, 286 + }, 311 287 }, 288 + IIO_CHAN_SOFT_TIMESTAMP(VEML6030_SCAN_TIMESTAMP), 312 289 }; 313 290 314 291 static const struct regmap_config veml6030_regmap_config = { ··· 928 889 return IRQ_HANDLED; 929 890 } 930 891 892 + static irqreturn_t veml6030_trigger_handler(int irq, void *p) 893 + { 894 + struct iio_poll_func *pf = p; 895 + struct iio_dev *iio = pf->indio_dev; 896 + struct veml6030_data *data = iio_priv(iio); 897 + unsigned int reg; 898 + int ch, ret, i = 0; 899 + struct { 900 + u16 chans[2]; 901 + aligned_s64 timestamp; 902 + } scan; 903 + 904 + memset(&scan, 0, sizeof(scan)); 905 + 906 + iio_for_each_active_channel(iio, ch) { 907 + ret = regmap_read(data->regmap, VEML6030_REG_DATA(ch), 908 + &reg); 909 + if (ret) 910 + goto done; 911 + 912 + scan.chans[i++] = reg; 913 + } 914 + 915 + iio_push_to_buffers_with_timestamp(iio, &scan, pf->timestamp); 916 + 917 + done: 918 + iio_trigger_notify_done(iio->trig); 919 + 920 + return IRQ_HANDLED; 921 + } 922 + 931 923 static int veml6030_set_info(struct iio_dev *indio_dev) 932 924 { 933 925 struct veml6030_data *data = iio_priv(indio_dev); ··· 1146 1076 ret = data->chip->hw_init(indio_dev, &client->dev); 1147 1077 if (ret < 0) 1148 1078 return ret; 1079 + 1080 + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, 1081 + veml6030_trigger_handler, NULL); 1082 + if (ret) 1083 + return dev_err_probe(&client->dev, ret, 1084 + "Failed to register triggered buffer"); 1149 1085 1150 1086 return devm_iio_device_register(&client->dev, indio_dev); 1151 1087 }
+1 -1
drivers/iio/magnetometer/af8133j.c
··· 360 360 s64 timestamp = iio_get_time_ns(indio_dev); 361 361 struct { 362 362 __le16 values[3]; 363 - s64 timestamp __aligned(8); 363 + aligned_s64 timestamp; 364 364 } sample; 365 365 int ret; 366 366
+1 -1
drivers/iio/magnetometer/ak8974.c
··· 197 197 /* Ensure timestamp is naturally aligned */ 198 198 struct { 199 199 __le16 channels[3]; 200 - s64 ts __aligned(8); 200 + aligned_s64 ts; 201 201 } scan; 202 202 }; 203 203
+1 -1
drivers/iio/magnetometer/ak8975.c
··· 426 426 /* Ensure natural alignment of timestamp */ 427 427 struct { 428 428 s16 channels[3]; 429 - s64 ts __aligned(8); 429 + aligned_s64 ts; 430 430 } scan; 431 431 }; 432 432
+1 -1
drivers/iio/magnetometer/bmc150_magn.c
··· 140 140 /* Ensure timestamp is naturally aligned */ 141 141 struct { 142 142 s32 chans[3]; 143 - s64 timestamp __aligned(8); 143 + aligned_s64 timestamp; 144 144 } scan; 145 145 struct iio_trigger *dready_trig; 146 146 bool dready_trigger_on;
+1 -1
drivers/iio/magnetometer/hmc5843.h
··· 44 44 struct iio_mount_matrix orientation; 45 45 struct { 46 46 __be16 chans[3]; 47 - s64 timestamp __aligned(8); 47 + aligned_s64 timestamp; 48 48 } scan; 49 49 }; 50 50
+1 -1
drivers/iio/magnetometer/mag3110.c
··· 60 60 struct { 61 61 __be16 channels[3]; 62 62 u8 temperature; 63 - s64 ts __aligned(8); 63 + aligned_s64 ts; 64 64 } scan; 65 65 }; 66 66
+1 -1
drivers/iio/magnetometer/yamaha-yas530.c
··· 236 236 */ 237 237 struct { 238 238 s32 channels[4]; 239 - s64 ts __aligned(8); 239 + aligned_s64 ts; 240 240 } scan; 241 241 }; 242 242
+46 -38
drivers/iio/multiplexer/iio-mux.c
··· 7 7 * Author: Peter Rosin <peda@axentia.se> 8 8 */ 9 9 10 + #include <linux/cleanup.h> 10 11 #include <linux/err.h> 11 12 #include <linux/iio/consumer.h> 12 13 #include <linux/iio/iio.h> ··· 238 237 return ret; 239 238 } 240 239 241 - static int mux_configure_channel(struct device *dev, struct mux *mux, 242 - u32 state, const char *label, int idx) 240 + static int mux_configure_chan_ext_info(struct device *dev, struct mux *mux, 241 + int idx, int num_ext_info) 243 242 { 244 243 struct mux_child *child = &mux->child[idx]; 245 - struct iio_chan_spec *chan = &mux->chan[idx]; 246 244 struct iio_chan_spec const *pchan = mux->parent->channel; 247 - char *page = NULL; 248 - int num_ext_info; 249 245 int i; 250 246 int ret; 251 247 252 - chan->indexed = 1; 253 - chan->output = pchan->output; 254 - chan->datasheet_name = label; 255 - chan->ext_info = mux->ext_info; 248 + char *page __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL); 249 + if (!page) 250 + return -ENOMEM; 256 251 257 - ret = iio_get_channel_type(mux->parent, &chan->type); 258 - if (ret < 0) { 259 - dev_err(dev, "failed to get parent channel type\n"); 260 - return ret; 261 - } 262 - 263 - if (iio_channel_has_info(pchan, IIO_CHAN_INFO_RAW)) 264 - chan->info_mask_separate |= BIT(IIO_CHAN_INFO_RAW); 265 - if (iio_channel_has_info(pchan, IIO_CHAN_INFO_SCALE)) 266 - chan->info_mask_separate |= BIT(IIO_CHAN_INFO_SCALE); 267 - 268 - if (iio_channel_has_available(pchan, IIO_CHAN_INFO_RAW)) 269 - chan->info_mask_separate_available |= BIT(IIO_CHAN_INFO_RAW); 270 - 271 - if (state >= mux_control_states(mux->control)) { 272 - dev_err(dev, "too many channels\n"); 273 - return -EINVAL; 274 - } 275 - 276 - chan->channel = state; 277 - 278 - num_ext_info = iio_get_channel_ext_info_count(mux->parent); 279 - if (num_ext_info) { 280 - page = devm_kzalloc(dev, PAGE_SIZE, GFP_KERNEL); 281 - if (!page) 282 - return -ENOMEM; 283 - } 284 252 child->ext_info_cache = devm_kcalloc(dev, 285 253 num_ext_info, 286 254 sizeof(*child->ext_info_cache), ··· 288 318 child->ext_info_cache[i].size = ret; 289 319 } 290 320 291 - if (page) 292 - devm_kfree(dev, page); 321 + return 0; 322 + } 323 + 324 + static int mux_configure_channel(struct device *dev, struct mux *mux, u32 state, 325 + const char *label, int idx) 326 + { 327 + struct iio_chan_spec *chan = &mux->chan[idx]; 328 + struct iio_chan_spec const *pchan = mux->parent->channel; 329 + int num_ext_info; 330 + int ret; 331 + 332 + chan->indexed = 1; 333 + chan->output = pchan->output; 334 + chan->datasheet_name = label; 335 + chan->ext_info = mux->ext_info; 336 + 337 + ret = iio_get_channel_type(mux->parent, &chan->type); 338 + if (ret < 0) { 339 + dev_err(dev, "failed to get parent channel type\n"); 340 + return ret; 341 + } 342 + 343 + if (iio_channel_has_info(pchan, IIO_CHAN_INFO_RAW)) 344 + chan->info_mask_separate |= BIT(IIO_CHAN_INFO_RAW); 345 + if (iio_channel_has_info(pchan, IIO_CHAN_INFO_SCALE)) 346 + chan->info_mask_separate |= BIT(IIO_CHAN_INFO_SCALE); 347 + 348 + if (iio_channel_has_available(pchan, IIO_CHAN_INFO_RAW)) 349 + chan->info_mask_separate_available |= BIT(IIO_CHAN_INFO_RAW); 350 + 351 + if (state >= mux_control_states(mux->control)) { 352 + dev_err(dev, "too many channels\n"); 353 + return -EINVAL; 354 + } 355 + 356 + chan->channel = state; 357 + 358 + num_ext_info = iio_get_channel_ext_info_count(mux->parent); 359 + if (num_ext_info) 360 + return mux_configure_chan_ext_info(dev, mux, idx, num_ext_info); 293 361 294 362 return 0; 295 363 }
+20 -19
drivers/iio/pressure/bmp280-core.c
··· 1002 1002 * after resetting, the device uses the complete power-on sequence so 1003 1003 * it needs to wait for the defined start-up time. 1004 1004 */ 1005 - fsleep(data->start_up_time); 1005 + fsleep(data->start_up_time_us); 1006 1006 1007 1007 ret = regmap_read(data->regmap, BMP280_REG_STATUS, &reg); 1008 1008 if (ret) ··· 1161 1161 .chip_id = bmp280_chip_ids, 1162 1162 .num_chip_id = ARRAY_SIZE(bmp280_chip_ids), 1163 1163 .regmap_config = &bmp280_regmap_config, 1164 - .start_up_time = 2000, 1164 + .start_up_time_us = 2000, 1165 1165 .channels = bmp280_channels, 1166 1166 .num_channels = ARRAY_SIZE(bmp280_channels), 1167 1167 .avail_scan_masks = bmp280_avail_scan_masks, ··· 1347 1347 .chip_id = bme280_chip_ids, 1348 1348 .num_chip_id = ARRAY_SIZE(bme280_chip_ids), 1349 1349 .regmap_config = &bme280_regmap_config, 1350 - .start_up_time = 2000, 1350 + .start_up_time_us = 2000, 1351 1351 .channels = bme280_channels, 1352 1352 .num_channels = ARRAY_SIZE(bme280_channels), 1353 1353 .avail_scan_masks = bme280_avail_scan_masks, ··· 1414 1414 return ret; 1415 1415 } 1416 1416 /* Wait for 2ms for command to be processed */ 1417 - usleep_range(data->start_up_time, data->start_up_time + 100); 1417 + fsleep(data->start_up_time_us); 1418 1418 /* Check for command processing error */ 1419 1419 ret = regmap_read(data->regmap, BMP380_REG_ERROR, &reg); 1420 1420 if (ret) { ··· 1806 1806 * formula in datasheet section 3.9.2 with an offset of ~+15% 1807 1807 * as it seen as well in table 3.9.1. 1808 1808 */ 1809 - msleep(150); 1809 + fsleep(150 * USEC_PER_MSEC); 1810 1810 1811 1811 /* Check config error flag */ 1812 1812 ret = regmap_read(data->regmap, BMP380_REG_ERROR, &tmp); ··· 1957 1957 .num_chip_id = ARRAY_SIZE(bmp380_chip_ids), 1958 1958 .regmap_config = &bmp380_regmap_config, 1959 1959 .spi_read_extra_byte = true, 1960 - .start_up_time = 2000, 1960 + .start_up_time_us = 2000, 1961 1961 .channels = bmp380_channels, 1962 1962 .num_channels = ARRAY_SIZE(bmp380_channels), 1963 1963 .avail_scan_masks = bmp280_avail_scan_masks, ··· 2006 2006 dev_err(data->dev, "failed to send reset command to device\n"); 2007 2007 return ret; 2008 2008 } 2009 - usleep_range(2000, 2500); 2009 + /* From datasheet's table 4: electrical characteristics */ 2010 + fsleep(2000); 2010 2011 2011 2012 /* Dummy read of chip_id */ 2012 2013 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, &reg); ··· 2209 2208 goto exit; 2210 2209 } 2211 2210 /* Wait standby transition time */ 2212 - usleep_range(2500, 3000); 2211 + fsleep(2500); 2213 2212 2214 2213 while (bytes >= sizeof(*dst)) { 2215 2214 addr = bmp580_nvmem_addrs[offset / sizeof(*dst)]; ··· 2275 2274 goto exit; 2276 2275 } 2277 2276 /* Wait standby transition time */ 2278 - usleep_range(2500, 3000); 2277 + fsleep(2500); 2279 2278 2280 2279 while (bytes >= sizeof(*buf)) { 2281 2280 addr = bmp580_nvmem_addrs[offset / sizeof(*buf)]; ··· 2459 2458 return ret; 2460 2459 } 2461 2460 /* From datasheet's table 4: electrical characteristics */ 2462 - usleep_range(2500, 3000); 2461 + fsleep(2500); 2463 2462 2464 2463 /* Set default DSP mode settings */ 2465 2464 reg_val = FIELD_PREP(BMP580_DSP_COMP_MASK, BMP580_DSP_PRESS_TEMP_COMP_EN) | ··· 2650 2649 .chip_id = bmp580_chip_ids, 2651 2650 .num_chip_id = ARRAY_SIZE(bmp580_chip_ids), 2652 2651 .regmap_config = &bmp580_regmap_config, 2653 - .start_up_time = 2000, 2652 + .start_up_time_us = 2000, 2654 2653 .channels = bmp580_channels, 2655 2654 .num_channels = ARRAY_SIZE(bmp580_channels), 2656 2655 .avail_scan_masks = bmp280_avail_scan_masks, ··· 2721 2720 delay_us = 2722 2721 conversion_time_max[data->oversampling_press]; 2723 2722 2724 - usleep_range(delay_us, delay_us + 1000); 2723 + fsleep(delay_us); 2725 2724 } 2726 2725 2727 2726 ret = regmap_read(data->regmap, BMP280_REG_CTRL_MEAS, &ctrl); ··· 2989 2988 .chip_id = bmp180_chip_ids, 2990 2989 .num_chip_id = ARRAY_SIZE(bmp180_chip_ids), 2991 2990 .regmap_config = &bmp180_regmap_config, 2992 - .start_up_time = 2000, 2991 + .start_up_time_us = 2000, 2993 2992 .channels = bmp280_channels, 2994 2993 .num_channels = ARRAY_SIZE(bmp280_channels), 2995 2994 .avail_scan_masks = bmp280_avail_scan_masks, ··· 3067 3066 .chip_id = bmp180_chip_ids, 3068 3067 .num_chip_id = ARRAY_SIZE(bmp180_chip_ids), 3069 3068 .regmap_config = &bmp180_regmap_config, 3070 - .start_up_time = 2000, 3069 + .start_up_time_us = 2000, 3071 3070 .channels = bmp280_channels, 3072 3071 .num_channels = ARRAY_SIZE(bmp280_channels), 3073 3072 .avail_scan_masks = bmp280_avail_scan_masks, ··· 3176 3175 data->oversampling_temp = chip_info->oversampling_temp_default; 3177 3176 data->iir_filter_coeff = chip_info->iir_filter_coeff_default; 3178 3177 data->sampling_freq = chip_info->sampling_freq_default; 3179 - data->start_up_time = chip_info->start_up_time; 3178 + data->start_up_time_us = chip_info->start_up_time_us; 3180 3179 3181 3180 /* Bring up regulators */ 3182 3181 regulator_bulk_set_supply_names(data->supplies, ··· 3202 3201 return ret; 3203 3202 3204 3203 /* Wait to make sure we started up properly */ 3205 - usleep_range(data->start_up_time, data->start_up_time + 100); 3204 + fsleep(data->start_up_time_us); 3206 3205 3207 3206 /* Bring chip out of reset if there is an assigned GPIO line */ 3208 3207 gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); ··· 3288 3287 * Set autosuspend to two orders of magnitude larger than the 3289 3288 * start-up time. 3290 3289 */ 3291 - pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10); 3290 + pm_runtime_set_autosuspend_delay(dev, data->start_up_time_us / 10); 3292 3291 pm_runtime_use_autosuspend(dev); 3293 3292 pm_runtime_put(dev); 3294 3293 ··· 3307 3306 3308 3307 data->chip_info->set_mode(data, BMP280_SLEEP); 3309 3308 3310 - fsleep(data->start_up_time); 3309 + fsleep(data->start_up_time_us); 3311 3310 return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); 3312 3311 } 3313 3312 ··· 3321 3320 if (ret) 3322 3321 return ret; 3323 3322 3324 - usleep_range(data->start_up_time, data->start_up_time + 100); 3323 + fsleep(data->start_up_time_us); 3325 3324 3326 3325 ret = data->chip_info->chip_config(data); 3327 3326 if (ret)
+4 -4
drivers/iio/pressure/bmp280.h
··· 434 434 struct bmp380_calib bmp380; 435 435 } calib; 436 436 struct regulator_bulk_data supplies[BMP280_NUM_SUPPLIES]; 437 - unsigned int start_up_time; /* in microseconds */ 437 + unsigned int start_up_time_us; 438 438 439 439 /* log of base 2 of oversampling rate */ 440 440 u8 oversampling_press; ··· 470 470 /* Sensor data buffer */ 471 471 u8 buf[BME280_BURST_READ_BYTES]; 472 472 /* Calibration data buffers */ 473 - __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2]; 474 - __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / 2]; 473 + __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / sizeof(__le16)]; 474 + __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / sizeof(__be16)]; 475 475 u8 bme280_humid_cal_buf[BME280_CONTIGUOUS_CALIB_REGS]; 476 476 u8 bmp380_cal_buf[BMP380_CALIB_REG_COUNT]; 477 477 /* Miscellaneous, endianness-aware data buffers */ ··· 490 490 491 491 const struct iio_chan_spec *channels; 492 492 int num_channels; 493 - unsigned int start_up_time; 493 + unsigned int start_up_time_us; 494 494 const unsigned long *avail_scan_masks; 495 495 496 496 const int *oversampling_temp_avail;
+1 -1
drivers/iio/pressure/hsc030pa.h
··· 58 58 s32 p_offset_dec; 59 59 struct { 60 60 __be16 chan[2]; 61 - s64 timestamp __aligned(8); 61 + aligned_s64 timestamp; 62 62 } scan; 63 63 u8 buffer[HSC_REG_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN); 64 64 };
+1 -1
drivers/iio/pressure/ms5611_core.c
··· 213 213 /* Ensure buffer elements are naturally aligned */ 214 214 struct { 215 215 s32 channels[2]; 216 - s64 ts __aligned(8); 216 + aligned_s64 ts; 217 217 } scan; 218 218 int ret; 219 219
+31 -49
drivers/iio/pressure/rohm-bm1390.c
··· 8 8 9 9 #include <linux/bitfield.h> 10 10 #include <linux/bits.h> 11 + #include <linux/cleanup.h> 11 12 #include <linux/device.h> 12 13 #include <linux/i2c.h> 13 14 #include <linux/module.h> ··· 139 138 struct bm1390_data_buf { 140 139 u32 pressure; 141 140 __be16 temp; 142 - s64 ts __aligned(8); 141 + aligned_s64 ts; 143 142 }; 144 143 145 144 /* BM1390 has FIFO for 4 pressure samples */ ··· 264 263 { 265 264 int ret, warn; 266 265 267 - mutex_lock(&data->mutex); 266 + guard(mutex)(&data->mutex); 268 267 /* 269 268 * We use 'continuous mode' even for raw read because according to the 270 269 * data-sheet an one-shot mode can't be used with IIR filter. 271 270 */ 272 271 ret = bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); 273 272 if (ret) 274 - goto unlock_out; 273 + return ret; 275 274 276 275 switch (chan->type) { 277 276 case IIO_PRESSURE: ··· 288 287 warn = bm1390_meas_set(data, BM1390_MEAS_MODE_STOP); 289 288 if (warn) 290 289 dev_warn(data->dev, "Failed to stop measurement (%d)\n", warn); 291 - unlock_out: 292 - mutex_unlock(&data->mutex); 293 290 294 - return ret; 291 + return 0; 295 292 } 296 293 297 294 static int bm1390_read_raw(struct iio_dev *idev, ··· 542 543 if (data->irq <= 0) 543 544 return -EINVAL; 544 545 545 - mutex_lock(&data->mutex); 546 - if (data->trigger_enabled) { 547 - ret = -EBUSY; 548 - goto unlock_out; 549 - } 546 + guard(mutex)(&data->mutex); 547 + 548 + if (data->trigger_enabled) 549 + return -EBUSY; 550 550 551 551 /* Update watermark to HW */ 552 552 ret = bm1390_fifo_set_wmi(data); 553 553 if (ret) 554 - goto unlock_out; 554 + return ret; 555 555 556 556 /* Enable WMI_IRQ */ 557 557 ret = regmap_set_bits(data->regmap, BM1390_REG_MODE_CTRL, 558 558 BM1390_MASK_WMI_EN); 559 559 if (ret) 560 - goto unlock_out; 560 + return ret; 561 561 562 562 /* Enable FIFO */ 563 563 ret = regmap_set_bits(data->regmap, BM1390_REG_FIFO_CTRL, 564 564 BM1390_MASK_FIFO_EN); 565 565 if (ret) 566 - goto unlock_out; 566 + return ret; 567 567 568 568 data->state = BM1390_STATE_FIFO; 569 569 570 570 data->old_timestamp = iio_get_time_ns(idev); 571 - ret = bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); 572 571 573 - unlock_out: 574 - mutex_unlock(&data->mutex); 575 - 576 - return ret; 572 + return bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); 577 573 } 578 574 579 575 static int bm1390_fifo_disable(struct iio_dev *idev) ··· 578 584 579 585 msleep(1); 580 586 581 - mutex_lock(&data->mutex); 587 + guard(mutex)(&data->mutex); 582 588 ret = bm1390_meas_set(data, BM1390_MEAS_MODE_STOP); 583 589 if (ret) 584 - goto unlock_out; 590 + return ret; 585 591 586 592 /* Disable FIFO */ 587 593 ret = regmap_clear_bits(data->regmap, BM1390_REG_FIFO_CTRL, 588 594 BM1390_MASK_FIFO_EN); 589 595 if (ret) 590 - goto unlock_out; 596 + return ret; 591 597 592 598 data->state = BM1390_STATE_SAMPLE; 593 599 594 600 /* Disable WMI_IRQ */ 595 - ret = regmap_clear_bits(data->regmap, BM1390_REG_MODE_CTRL, 601 + return regmap_clear_bits(data->regmap, BM1390_REG_MODE_CTRL, 596 602 BM1390_MASK_WMI_EN); 597 - 598 - unlock_out: 599 - mutex_unlock(&data->mutex); 600 - 601 - return ret; 602 603 } 603 604 604 605 static int bm1390_buffer_postenable(struct iio_dev *idev) ··· 677 688 { 678 689 struct iio_dev *idev = private; 679 690 struct bm1390_data *data = iio_priv(idev); 680 - int ret = IRQ_NONE; 681 691 682 - mutex_lock(&data->mutex); 692 + guard(mutex)(&data->mutex); 683 693 684 694 if (data->trigger_enabled) { 685 695 iio_trigger_poll_nested(data->trig); 686 - ret = IRQ_HANDLED; 687 - } else if (data->state == BM1390_STATE_FIFO) { 696 + return IRQ_HANDLED; 697 + } 698 + 699 + if (data->state == BM1390_STATE_FIFO) { 688 700 int ok; 689 701 690 702 ok = __bm1390_fifo_flush(idev, BM1390_FIFO_LENGTH, 691 703 data->timestamp); 692 704 if (ok > 0) 693 - ret = IRQ_HANDLED; 705 + return IRQ_HANDLED; 694 706 } 695 707 696 - mutex_unlock(&data->mutex); 697 - 698 - return ret; 708 + return IRQ_NONE; 699 709 } 700 710 701 711 static int bm1390_set_drdy_irq(struct bm1390_data *data, bool en) ··· 710 722 bool state) 711 723 { 712 724 struct bm1390_data *data = iio_trigger_get_drvdata(trig); 713 - int ret = 0; 725 + int ret; 714 726 715 - mutex_lock(&data->mutex); 727 + guard(mutex)(&data->mutex); 716 728 717 729 if (data->trigger_enabled == state) 718 - goto unlock_out; 730 + return 0; 719 731 720 732 if (data->state == BM1390_STATE_FIFO) { 721 733 dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); 722 - ret = -EBUSY; 723 - goto unlock_out; 734 + return -EBUSY; 724 735 } 725 736 726 737 data->trigger_enabled = state; ··· 727 740 if (state) { 728 741 ret = bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); 729 742 if (ret) 730 - goto unlock_out; 743 + return ret; 731 744 } else { 732 745 int dummy; 733 746 734 747 ret = bm1390_meas_set(data, BM1390_MEAS_MODE_STOP); 735 748 if (ret) 736 - goto unlock_out; 749 + return ret; 737 750 738 751 /* 739 752 * We need to read the status register in order to ACK the ··· 745 758 dev_warn(data->dev, "status read failed\n"); 746 759 } 747 760 748 - ret = bm1390_set_drdy_irq(data, state); 749 - 750 - unlock_out: 751 - mutex_unlock(&data->mutex); 752 - 753 - return ret; 761 + return bm1390_set_drdy_irq(data, state); 754 762 } 755 763 756 764 static const struct iio_trigger_ops bm1390_trigger_ops = {
+1 -1
drivers/iio/proximity/as3935.c
··· 63 63 /* Ensure timestamp is naturally aligned */ 64 64 struct { 65 65 u8 chan; 66 - s64 timestamp __aligned(8); 66 + aligned_s64 timestamp; 67 67 } scan; 68 68 u8 buf[2] __aligned(IIO_DMA_MINALIGN); 69 69 };
+1 -1
drivers/iio/proximity/aw96103.c
··· 433 433 state ? BIT(chan->channel) : 0); 434 434 } 435 435 436 - static struct iio_info iio_info = { 436 + static const struct iio_info iio_info = { 437 437 .read_raw = aw96103_read_raw, 438 438 .read_event_value = aw96103_read_event_val, 439 439 .write_event_value = aw96103_write_event_val,
+87 -8
drivers/iio/proximity/hx9023s.c
··· 14 14 #include <linux/cleanup.h> 15 15 #include <linux/device.h> 16 16 #include <linux/errno.h> 17 + #include <linux/firmware.h> 17 18 #include <linux/i2c.h> 18 19 #include <linux/interrupt.h> 19 20 #include <linux/irqreturn.h> ··· 101 100 #define HX9023S_INTERRUPT_MASK GENMASK(9, 0) 102 101 #define HX9023S_PROX_DEBOUNCE_MASK GENMASK(3, 0) 103 102 103 + #define FW_VER_OFFSET 2 104 + #define FW_REG_CNT_OFFSET 3 105 + #define FW_DATA_OFFSET 16 106 + 107 + struct hx9023s_bin { 108 + u16 reg_count; 109 + u16 fw_size; 110 + u8 fw_ver; 111 + u8 data[] __counted_by(fw_size); 112 + }; 113 + 104 114 struct hx9023s_ch_data { 105 115 s16 raw; /* Raw Data*/ 106 116 s16 lp; /* Low Pass Filter Data*/ ··· 146 134 147 135 struct { 148 136 __le16 channels[HX9023S_CH_NUM]; 149 - s64 ts __aligned(8); 137 + aligned_s64 ts; 150 138 } buffer; 151 139 152 140 /* ··· 1010 998 return 0; 1011 999 } 1012 1000 1001 + static int hx9023s_bin_load(struct hx9023s_data *data, struct hx9023s_bin *bin) 1002 + { 1003 + u8 *cfg_start = bin->data + FW_DATA_OFFSET; 1004 + u8 addr, val; 1005 + u16 i; 1006 + int ret; 1007 + 1008 + for (i = 0; i < bin->reg_count; i++) { 1009 + addr = cfg_start[i * 2]; 1010 + val = cfg_start[i * 2 + 1]; 1011 + ret = regmap_write(data->regmap, addr, val); 1012 + if (ret < 0) 1013 + return ret; 1014 + } 1015 + 1016 + return 0; 1017 + } 1018 + 1019 + static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data) 1020 + { 1021 + struct hx9023s_bin *bin __free(kfree) = 1022 + kzalloc(fw->size + sizeof(*bin), GFP_KERNEL); 1023 + if (!bin) 1024 + return -ENOMEM; 1025 + 1026 + memcpy(bin->data, fw->data, fw->size); 1027 + release_firmware(fw); 1028 + 1029 + bin->fw_size = fw->size; 1030 + bin->fw_ver = bin->data[FW_VER_OFFSET]; 1031 + bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET); 1032 + 1033 + return hx9023s_bin_load(data, bin); 1034 + } 1035 + 1036 + static void hx9023s_cfg_update(const struct firmware *fw, void *context) 1037 + { 1038 + struct hx9023s_data *data = context; 1039 + struct device *dev = regmap_get_device(data->regmap); 1040 + int ret; 1041 + 1042 + if (!fw || !fw->data) { 1043 + dev_warn(dev, "No firmware\n"); 1044 + goto no_fw; 1045 + } 1046 + 1047 + ret = hx9023s_send_cfg(fw, data); 1048 + if (ret) { 1049 + dev_warn(dev, "Firmware update failed: %d\n", ret); 1050 + goto no_fw; 1051 + } 1052 + 1053 + ret = regcache_sync(data->regmap); 1054 + if (ret) 1055 + dev_err(dev, "regcache sync failed\n"); 1056 + 1057 + return; 1058 + 1059 + no_fw: 1060 + ret = regmap_multi_reg_write(data->regmap, hx9023s_reg_init_list, 1061 + ARRAY_SIZE(hx9023s_reg_init_list)); 1062 + if (ret) { 1063 + dev_err(dev, "Error loading default configuration\n"); 1064 + return; 1065 + } 1066 + 1067 + ret = regcache_sync(data->regmap); 1068 + if (ret) 1069 + dev_err(dev, "regcache sync failed\n"); 1070 + } 1071 + 1013 1072 static int hx9023s_probe(struct i2c_client *client) 1014 1073 { 1015 1074 struct device *dev = &client->dev; ··· 1119 1036 indio_dev->modes = INDIO_DIRECT_MODE; 1120 1037 i2c_set_clientdata(client, indio_dev); 1121 1038 1122 - ret = regmap_multi_reg_write(data->regmap, hx9023s_reg_init_list, 1123 - ARRAY_SIZE(hx9023s_reg_init_list)); 1124 - if (ret) 1125 - return dev_err_probe(dev, ret, "device init failed\n"); 1126 - 1127 1039 ret = hx9023s_ch_cfg(data); 1128 1040 if (ret) 1129 1041 return dev_err_probe(dev, ret, "channel config failed\n"); 1130 1042 1131 - ret = regcache_sync(data->regmap); 1043 + ret = request_firmware_nowait(THIS_MODULE, true, "hx9023s.bin", dev, 1044 + GFP_KERNEL, data, hx9023s_cfg_update); 1132 1045 if (ret) 1133 - return dev_err_probe(dev, ret, "regcache sync failed\n"); 1046 + return dev_err_probe(dev, ret, "reg config failed\n"); 1134 1047 1135 1048 if (client->irq) { 1136 1049 ret = devm_request_threaded_irq(dev, client->irq,
+1 -1
drivers/iio/proximity/mb1232.c
··· 45 45 /* Ensure correct alignment of data to push to IIO buffer */ 46 46 struct { 47 47 s16 distance; 48 - s64 ts __aligned(8); 48 + aligned_s64 ts; 49 49 } scan; 50 50 }; 51 51
+1 -1
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
··· 47 47 /* Ensure timestamp is naturally aligned */ 48 48 struct { 49 49 u16 chan; 50 - s64 timestamp __aligned(8); 50 + aligned_s64 timestamp; 51 51 } scan; 52 52 }; 53 53
+1 -1
drivers/iio/proximity/srf08.c
··· 66 66 /* Ensure timestamp is naturally aligned */ 67 67 struct { 68 68 s16 chan; 69 - s64 timestamp __aligned(8); 69 + aligned_s64 timestamp; 70 70 } scan; 71 71 72 72 /* Sensor-Type */
+1 -1
drivers/iio/proximity/sx_common.h
··· 125 125 /* Ensure correct alignment of timestamp when present. */ 126 126 struct { 127 127 __be16 channels[SX_COMMON_MAX_NUM_CHANNELS]; 128 - s64 ts __aligned(8); 128 + aligned_s64 ts; 129 129 } buffer; 130 130 131 131 unsigned int suspend_ctrl;
+1 -1
drivers/iio/resolver/ad2s1210.c
··· 164 164 struct { 165 165 __be16 chan[2]; 166 166 /* Ensure timestamp is naturally aligned. */ 167 - s64 timestamp __aligned(8); 167 + aligned_s64 timestamp; 168 168 } scan; 169 169 /** SPI transmit buffer. */ 170 170 u8 rx[2];
+1 -1
drivers/iio/temperature/tmp006.c
··· 248 248 struct tmp006_data *data = iio_priv(indio_dev); 249 249 struct { 250 250 s16 channels[2]; 251 - s64 ts __aligned(8); 251 + aligned_s64 ts; 252 252 } scan; 253 253 s32 ret; 254 254
+48 -21
drivers/iio/trigger/stm32-timer-trigger.c
··· 38 38 { TIM15_TRGO,}, 39 39 { TIM16_OC1,}, 40 40 { TIM17_OC1,}, 41 + { }, /* timer 18 */ 42 + { }, /* timer 19 */ 43 + { TIM20_TRGO, TIM20_TRGO2, TIM20_OC1, TIM20_OC2, TIM20_OC3, }, 41 44 }; 42 45 43 46 /* List the triggers accepted by each timer */ ··· 122 119 unsigned int frequency) 123 120 { 124 121 unsigned long long prd, div; 125 - int prescaler = 0; 122 + int prescaler = 0, ret; 126 123 u32 ccer; 127 124 128 125 /* Period and prescaler values depends of clock rate */ ··· 153 150 if (ccer & TIM_CCER_CCXE) 154 151 return -EBUSY; 155 152 156 - mutex_lock(&priv->lock); 153 + guard(mutex)(&priv->lock); 157 154 if (!priv->enabled) { 158 155 priv->enabled = true; 159 - clk_enable(priv->clk); 156 + ret = clk_enable(priv->clk); 157 + if (ret) 158 + return ret; 160 159 } 161 160 162 161 regmap_write(priv->regmap, TIM_PSC, prescaler); ··· 178 173 179 174 /* Enable controller */ 180 175 regmap_set_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN); 181 - mutex_unlock(&priv->lock); 182 176 183 177 return 0; 184 178 } ··· 311 307 struct stm32_timer_trigger *priv = dev_get_drvdata(dev); 312 308 struct iio_trigger *trig = to_iio_trigger(dev); 313 309 u32 mask, shift, master_mode_max; 314 - int i; 310 + int i, ret; 315 311 316 312 if (stm32_timer_is_trgo2_name(trig->name)) { 317 313 mask = TIM_CR2_MMS2; ··· 326 322 for (i = 0; i <= master_mode_max; i++) { 327 323 if (!strncmp(master_mode_table[i], buf, 328 324 strlen(master_mode_table[i]))) { 329 - mutex_lock(&priv->lock); 325 + guard(mutex)(&priv->lock); 330 326 if (!priv->enabled) { 331 327 /* Clock should be enabled first */ 332 328 priv->enabled = true; 333 - clk_enable(priv->clk); 329 + ret = clk_enable(priv->clk); 330 + if (ret) 331 + return ret; 334 332 } 335 333 regmap_update_bits(priv->regmap, TIM_CR2, mask, 336 334 i << shift); 337 - mutex_unlock(&priv->lock); 338 335 return len; 339 336 } 340 337 } ··· 487 482 int val, int val2, long mask) 488 483 { 489 484 struct stm32_timer_trigger *priv = iio_priv(indio_dev); 485 + int ret; 490 486 491 487 switch (mask) { 492 488 case IIO_CHAN_INFO_RAW: ··· 497 491 /* fixed scale */ 498 492 return -EINVAL; 499 493 500 - case IIO_CHAN_INFO_ENABLE: 501 - mutex_lock(&priv->lock); 494 + case IIO_CHAN_INFO_ENABLE: { 495 + guard(mutex)(&priv->lock); 502 496 if (val) { 503 497 if (!priv->enabled) { 504 498 priv->enabled = true; 505 - clk_enable(priv->clk); 499 + ret = clk_enable(priv->clk); 500 + if (ret) 501 + return ret; 506 502 } 507 503 regmap_set_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN); 508 504 } else { ··· 514 506 clk_disable(priv->clk); 515 507 } 516 508 } 517 - mutex_unlock(&priv->lock); 509 + 518 510 return 0; 519 511 } 520 - 521 - return -EINVAL; 512 + default: 513 + return -EINVAL; 514 + } 522 515 } 523 516 524 517 static int stm32_counter_validate_trigger(struct iio_dev *indio_dev, ··· 611 602 { 612 603 struct stm32_timer_trigger *priv = iio_priv(indio_dev); 613 604 int sms = stm32_enable_mode2sms(mode); 605 + int ret; 614 606 615 607 if (sms < 0) 616 608 return sms; ··· 619 609 * Triggered mode sets CEN bit automatically by hardware. So, first 620 610 * enable counter clock, so it can use it. Keeps it in sync with CEN. 621 611 */ 622 - mutex_lock(&priv->lock); 623 - if (sms == 6 && !priv->enabled) { 624 - clk_enable(priv->clk); 625 - priv->enabled = true; 612 + scoped_guard(mutex, &priv->lock) { 613 + if (sms == 6 && !priv->enabled) { 614 + ret = clk_enable(priv->clk); 615 + if (ret) 616 + return ret; 617 + 618 + priv->enabled = true; 619 + } 626 620 } 627 - mutex_unlock(&priv->lock); 628 621 629 622 regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms); 630 623 ··· 794 781 return -EINVAL; 795 782 796 783 /* Create an IIO device only if we have triggers to be validated */ 797 - if (*cfg->valids_table[index]) 784 + if (cfg->valids_table && *cfg->valids_table[index]) 798 785 priv = stm32_setup_counter_device(dev); 799 786 else 800 787 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); ··· 807 794 priv->clk = ddata->clk; 808 795 priv->max_arr = ddata->max_arr; 809 796 priv->triggers = triggers_table[index]; 810 - priv->valids = cfg->valids_table[index]; 797 + if (cfg->valids_table && *cfg->valids_table[index]) 798 + priv->valids = cfg->valids_table[index]; 811 799 stm32_timer_detect_trgo2(priv); 812 800 mutex_init(&priv->lock); 813 801 ··· 900 886 .num_valids_table = ARRAY_SIZE(stm32h7_valids_table), 901 887 }; 902 888 889 + static const struct stm32_timer_trigger_cfg stm32mp25_timer_trg_cfg = { 890 + /* 891 + * valids_table not used: counter framework is now superseding the deprecated IIO 892 + * counter interface (IIO_COUNT), so don't support it. num_valids_table is only 893 + * kept here to register the IIO HW triggers. valids_table should be moved at some 894 + * point to the stm32-timer-cnt driver instead. 895 + */ 896 + .num_valids_table = ARRAY_SIZE(triggers_table), 897 + }; 898 + 903 899 static const struct of_device_id stm32_trig_of_match[] = { 904 900 { 905 901 .compatible = "st,stm32-timer-trigger", ··· 917 893 }, { 918 894 .compatible = "st,stm32h7-timer-trigger", 919 895 .data = (void *)&stm32h7_timer_trg_cfg, 896 + }, { 897 + .compatible = "st,stm32mp25-timer-trigger", 898 + .data = (void *)&stm32mp25_timer_trg_cfg, 920 899 }, 921 900 { /* end node */ }, 922 901 };
include/dt-bindings/iio/adi,ad4695.h include/dt-bindings/iio/adc/adi,ad4695.h
+7 -3
include/linux/iio/adc/ad_sigma_delta.h
··· 29 29 30 30 struct ad_sigma_delta; 31 31 struct device; 32 + struct gpio_desc; 32 33 struct iio_dev; 33 34 34 35 /** ··· 54 53 * @irq_flags: flags for the interrupt used by the triggered buffer 55 54 * @num_slots: Number of sequencer slots 56 55 * @irq_line: IRQ for reading conversions. If 0, spi->irq will be used 56 + * @num_resetclks: Number of SPI clk cycles with MOSI=1 to reset the chip. 57 57 */ 58 58 struct ad_sigma_delta_info { 59 59 int (*set_channel)(struct ad_sigma_delta *, unsigned int channel); ··· 71 69 unsigned long irq_flags; 72 70 unsigned int num_slots; 73 71 int irq_line; 72 + unsigned int num_resetclks; 74 73 }; 75 74 76 75 /** ··· 88 85 89 86 /* private: */ 90 87 struct completion completion; 88 + spinlock_t irq_lock; /* protects .irq_dis and irq en/disable state */ 91 89 bool irq_dis; 92 90 93 91 bool bus_locked; ··· 100 96 unsigned int active_slots; 101 97 unsigned int current_slot; 102 98 unsigned int num_slots; 103 - int irq_line; 99 + struct gpio_desc *rdy_gpiod; 100 + int irq_line; 104 101 bool status_appended; 105 102 /* map slots to channels in order to know what to expect from devices */ 106 103 unsigned int *slots; ··· 183 178 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg, 184 179 unsigned int size, unsigned int *val); 185 180 186 - int ad_sd_reset(struct ad_sigma_delta *sigma_delta, 187 - unsigned int reset_length); 181 + int ad_sd_reset(struct ad_sigma_delta *sigma_delta); 188 182 189 183 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, 190 184 const struct iio_chan_spec *chan, int *val);
+1 -1
include/linux/iio/buffer.h
··· 37 37 static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev, 38 38 void *data, int64_t timestamp) 39 39 { 40 - if (indio_dev->scan_timestamp) { 40 + if (ACCESS_PRIVATE(indio_dev, scan_timestamp)) { 41 41 size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1; 42 42 ((int64_t *)data)[ts_offset] = timestamp; 43 43 }
+2 -2
include/linux/iio/consumer.h
··· 418 418 * @chan: The channel being queried. 419 419 * @attr: The ext_info attribute to read. 420 420 * @buf: Where to store the attribute value. Assumed to hold 421 - * at least PAGE_SIZE bytes. 421 + * at least PAGE_SIZE bytes and to be aligned at PAGE_SIZE. 422 422 * 423 423 * Returns the number of bytes written to buf (perhaps w/o zero termination; 424 424 * it need not even be a string), or an error code. ··· 445 445 * iio_read_channel_label() - read label for a given channel 446 446 * @chan: The channel being queried. 447 447 * @buf: Where to store the attribute value. Assumed to hold 448 - * at least PAGE_SIZE bytes. 448 + * at least PAGE_SIZE bytes and to be aligned at PAGE_SIZE. 449 449 * 450 450 * Returns the number of bytes written to buf, or an error code. 451 451 */
+6
include/linux/iio/iio-gts-helper.h
··· 188 188 int iio_gts_find_gain_sel_for_scale_using_time(struct iio_gts *gts, int time_sel, 189 189 int scale_int, int scale_nano, 190 190 int *gain_sel); 191 + int iio_gts_find_gain_time_sel_for_scale(struct iio_gts *gts, int scale_int, 192 + int scale_nano, int *gain_sel, 193 + int *time_sel); 191 194 int iio_gts_get_scale(struct iio_gts *gts, int gain, int time, int *scale_int, 192 195 int *scale_nano); 193 196 int iio_gts_find_new_gain_sel_by_old_gain_time(struct iio_gts *gts, ··· 199 196 int iio_gts_find_new_gain_by_old_gain_time(struct iio_gts *gts, int old_gain, 200 197 int old_time, int new_time, 201 198 int *new_gain); 199 + int iio_gts_find_new_gain_by_gain_time_min(struct iio_gts *gts, int old_gain, 200 + int old_time, int new_time, 201 + int *new_gain, bool *in_range); 202 202 int iio_gts_avail_times(struct iio_gts *gts, const int **vals, int *type, 203 203 int *length); 204 204 int iio_gts_all_avail_scales(struct iio_gts *gts, const int **vals, int *type,
+1 -1
include/linux/iio/iio-opaque.h
··· 28 28 * @groupcounter: index of next attribute group 29 29 * @legacy_scan_el_group: attribute group for legacy scan elements attribute group 30 30 * @legacy_buffer_group: attribute group for legacy buffer attributes group 31 - * @bounce_buffer: for devices that call iio_push_to_buffers_with_timestamp_unaligned() 31 + * @bounce_buffer: for devices that call iio_push_to_buffers_with_ts_unaligned() 32 32 * @bounce_buffer_size: size of currently allocate bounce buffer 33 33 * @scan_index_timestamp: cache of the index to the timestamp 34 34 * @clock_id: timestamping clock posix identifier
+1 -1
include/linux/iio/iio.h
··· 611 611 const unsigned long *available_scan_masks; 612 612 unsigned int __private masklength; 613 613 const unsigned long *active_scan_mask; 614 - bool scan_timestamp; 614 + bool __private scan_timestamp; 615 615 struct iio_trigger *trig; 616 616 struct iio_poll_func *pollfunc; 617 617 struct iio_poll_func *pollfunc_event;
-1
include/linux/iio/imu/adis.h
··· 99 99 * @spi: Reference to SPI device which owns this ADIS IIO device 100 100 * @trig: IIO trigger object data 101 101 * @data: ADIS chip variant specific data 102 - * @burst: ADIS burst transfer information 103 102 * @burst_extra_len: Burst extra length. Should only be used by devices that can 104 103 * dynamically change their burst mode length. 105 104 * @state_lock: Lock used by the device to protect state
+6
include/linux/iio/timer/stm32-timer-trigger.h
··· 72 72 73 73 #define TIM17_OC1 "tim17_oc1" 74 74 75 + #define TIM20_OC1 "tim20_oc1" 76 + #define TIM20_OC2 "tim20_oc2" 77 + #define TIM20_OC3 "tim20_oc3" 78 + #define TIM20_TRGO "tim20_trgo" 79 + #define TIM20_TRGO2 "tim20_trgo2" 80 + 75 81 #if IS_REACHABLE(CONFIG_IIO_STM32_TIMER_TRIGGER) 76 82 bool is_stm32_timer_trigger(struct iio_trigger *trig); 77 83 #else