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

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

Jonathan writes:

IIO new device support, features and minor fixes for 5.20

Several on-running cleanup efforts dominate this time, plus the DMA
safety alignment issue identified due to improved understanding of
the restrictions as a result of Catalin Marinas' efforts in that area.

One immutable branch in here due to MFD and SPMI elements needed for
the qcom-rradc driver.

Device support
* bmi088
- Add support for bmi085 (accelerometer part of IMU)
- Add support for bmi090l (accelerometer part of IMU)
* mcp4922
- Add support for single channel device MCP4921
* rzg2l-adc
- Add compatible and minor tweaks to support RZ/G2UL ADC
* sca3300
- Add support for scl3300 including refactoring driver to support
multiple device types and cleanup noticed whilst working on driver.
* spmi-rradc
- New driver for Qualcomm SPMI Round Robin ADC including necessary
additional utility functions in SPMI core and related MFD driver.
* ti-dac55781
- Add compatible for DAC121C081 which is very similar to existing parts.

Features
* core
- Warn on iio_trigger_get() on an unregistered IIO trigger.
* bma400
- Triggered buffer support
- Activity and step counting
- Misc driver improvements such as devm and header ordering
* cm32181
- Add PM support.
* cros_ec
- Sensor location support
* sx9324
- Add precharge resistor setting
- Add internal compensation resistor setting
- Add CS idle/sleep mode.
* sx9360
- Add precharge resistor setting
* vl53l0x
- Handle reset GPIO, regulator and relax handling of irq type.

Cleanup and minor fixes:

Treewide changes
- Cleanup of error handling in remove functions in many drivers.
- Update dt-binding maintainers for a number of ADI bindings.
- Several sets of conversion of drivers from device tree specific to
generic device properties. Includes fixing up various related
header and Kconfig issues.
- Drop include of of.h from iio.h and fix up drivers that need to include
it directly.
- More moves of clusters of drivers into appropriate IIO_XXX namespaces.
- Tree wide fix of a long running bug around DMA safety requirements.
IIO was using __cacheline_aligned to pad iio_priv() structures. This
worked for a long time by coincidence, but correct alignment is
ARCH_KMALLOC_MINALIGN. As there is activity around this area, introduce
an IIO local IIO_DMA_MINALIGN to allow for changing it in one place rather
than every driver in future. Note, there have been no reports of this
bug in the wild, and it may not happen on any platforms supported by
upstream, so no rush to backport these fixes.

Other cleanup
* core
- Switch to ida_alloc()/free()
- Drop unused iio_get_time_res()
- Octal permissions and DEVICE_ATTR_* macros.
- Cleanup bared unsigned usage.
* MAINTAINERS
- Add include/dt-bindings/iio/ to the main IIO entry.
* ad5380
- Comment syntax fix.
* ad74413r
- Call to for_each_set_bit_from(), with from value as 0 replaced.
* ad7768-1
- Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core.
* adxl345
- Fix wrong address in dt-binding example.
* adxl367
- Drop extra update of FIFO watermark.
* at91-sama5d2
- Limit requested watermark to the hwfifo size.
* bmg160, bme680
- Typos
* cio-dac
- Switch to iomap rather than direct use of ioports
* kxsd9
- Replace CONFIG_PM guards with new PM macros that let the compiler
cleanly remove the unused code and structures when !CONFIG_PM
* lsm6dsx
- Use new pm_sleep_ptr() and EXPORT_SIMPLE_DEV_PM_OPS(). Then move
to Namespace.
* meson_saradc - general cleanup.
- Avoid attaching resources to iio_dev->dev
- Use same struct device for all error messages
- Convert to dev_err_probe() and use local struct device *dev to
reduce code complexity.
- Use devm_clk_get_optional() instead of hand rolling.
- Use regmap_read_poll_timeout() instead of hand rolling.
* mma7660
- Drop ACPI_PTR() use that is unhelpful.
* mpu3050
- Stop exporting symbols not used outside of module
- Switch to new DEFINE_RUNTIME_DEV_PM_OPS() macro and move to Namespace.
* ping
- Typo fix
* qcom-spmi-rradc
- Typo fix
* sc27xx
- Convert to generic struct u32_fract
* srf08
- Drop a redundant check on !val
* st_lsm6dsx
- Limit the requested watermark to the hwfifo size.
* stm32-adc
- Use generic_handle_domain_irq() instead of opencoding.
- Fix handling of ADC disable.
* stm32-dac
- Use str_enabled_disable() instead of open coding.
* stx104
- Switch to iomap rather than direct use of ioports
* tsc2046
- Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core.
* tsl2563
- Replace flush_scheduled_work() with cancel_delayed_work_sync()
- Replace cancel_delayed_work() with cancel_delayed_work_sync()
* vl53l0x
- Make the VDD regulator optional by allowing a dummy regulator.

* tag 'iio-for-5.20a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (244 commits)
iio: adc: xilinx-xadc: Drop duplicate NULL check in xadc_parse_dt()
iio: adc: xilinx-xadc: Make use of device properties
iio: light: cm32181: Add PM support
iio: adc: ad778-1: do not explicity set INDIO_BUFFER_TRIGGERED mode
iio: adc: ti-tsc2046: do not explicity set INDIO_BUFFER_TRIGGERED mode
iio: adc: stm32-adc: disable adc before calibration
iio: adc: stm32-adc: make safe adc disable
iio: dac: ad5380: align '*' each line and drop unneeded blank line
iio: adc: qcom-spmi-rradc: Fix spelling mistake "coherrency" -> "coherency"
iio: Don't use bare "unsigned"
dt-bindings: iio: dac: mcp4922: expand for mcp4921 support
iio: dac: mcp4922: add support to mcp4921
iio: chemical: sps30: Move symbol exports into IIO_SPS30 namespace
iio: pressure: bmp280: Move symbol exports to IIO_BMP280 namespace
iio: imu: bmi160: Move exported symbols to IIO_BMI160 namespace
iio: adc: stm32-adc: Use generic_handle_domain_irq()
proximity: vl53l0x: Make VDD regulator actually optional
MAINTAINERS: add include/dt-bindings/iio to IIO SUBSYSTEM AND DRIVERS
dt-bindings: iio/accel: Fix adi,adxl345/6 example I2C address
iio: gyro: bmg160: Fix typo in comment
...

+3298 -920
+5
Documentation/ABI/testing/sysfs-bus-iio
··· 79 79 * "accel-base" 80 80 * "accel-display" 81 81 82 + For devices where an accelerometer is housed in the swivel camera subassembly 83 + (for AR application), the following standardized label is used: 84 + 85 + * "accel-camera" 86 + 82 87 What: /sys/bus/iio/devices/iio:deviceX/current_timestamp_clock 83 88 KernelVersion: 4.5 84 89 Contact: linux-iio@vger.kernel.org
+1 -1
Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
··· 7 7 title: ADIS16240 Programmable Impact Sensor and Recorder driver 8 8 9 9 maintainers: 10 - - Alexandru Ardelean <alexandru.ardelean@analog.com> 10 + - Alexandru Tachici <alexandru.tachici@analog.com> 11 11 12 12 description: | 13 13 ADIS16240 Programmable Impact Sensor and Recorder driver that supports
+1 -1
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml
··· 55 55 /* Example for a I2C device node */ 56 56 accelerometer@2a { 57 57 compatible = "adi,adxl345"; 58 - reg = <0x53>; 58 + reg = <0x2a>; 59 59 interrupt-parent = <&gpio0>; 60 60 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 61 61 };
+2
Documentation/devicetree/bindings/iio/accel/bosch,bmi088.yaml
··· 17 17 properties: 18 18 compatible: 19 19 enum: 20 + - bosch,bmi085-accel 20 21 - bosch,bmi088-accel 22 + - bosch,bmi090l-accel 21 23 22 24 reg: 23 25 maxItems: 1
+1
Documentation/devicetree/bindings/iio/accel/murata,sca3300.yaml
··· 17 17 compatible: 18 18 enum: 19 19 - murata,sca3300 20 + - murata,scl3300 20 21 21 22 reg: 22 23 maxItems: 1
-1
Documentation/devicetree/bindings/iio/adc/adi,ad9467.yaml
··· 8 8 9 9 maintainers: 10 10 - Michael Hennerich <michael.hennerich@analog.com> 11 - - Alexandru Ardelean <alexandru.ardelean@analog.com> 12 11 13 12 description: | 14 13 The AD9467 and the parts similar with it, are high-speed analog-to-digital
-1
Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
··· 8 8 9 9 maintainers: 10 10 - Michael Hennerich <michael.hennerich@analog.com> 11 - - Alexandru Ardelean <alexandru.ardelean@analog.com> 12 11 13 12 description: | 14 13 Analog Devices Generic AXI ADC IP core for interfacing an ADC device
+51
Documentation/devicetree/bindings/iio/adc/qcom,spmi-rradc.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/qcom,spmi-rradc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Qualcomm's SPMI PMIC Round Robin ADC 8 + 9 + maintainers: 10 + - Caleb Connolly <caleb.connolly@linaro.org> 11 + 12 + description: | 13 + The Qualcomm SPMI Round Robin ADC (RRADC) provides interface to clients to 14 + read the voltage, current and temperature for supported peripherals such as 15 + the battery thermistor die temperature, charger temperature, USB and DC input 16 + voltage / current and battery ID resistor. 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - qcom,pmi8998-rradc 22 + - qcom,pm660-rradc 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + qcom,batt-id-delay-ms: 28 + description: Sets the hardware settling time for the battery ID resistor. 29 + enum: [0, 1, 4, 12, 20, 40, 60, 80] 30 + 31 + "#io-channel-cells": 32 + const: 1 33 + 34 + required: 35 + - compatible 36 + - reg 37 + 38 + additionalProperties: false 39 + 40 + examples: 41 + - | 42 + pmic { 43 + #address-cells = <1>; 44 + #size-cells = <0>; 45 + 46 + pmic_rradc: adc@4500 { 47 + compatible = "qcom,pmi8998-rradc"; 48 + reg = <0x4500>; 49 + #io-channel-cells = <1>; 50 + }; 51 + };
+24 -4
Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml
··· 19 19 compatible: 20 20 items: 21 21 - enum: 22 + - renesas,r9a07g043-adc # RZ/G2UL 22 23 - renesas,r9a07g044-adc # RZ/G2L 23 24 - renesas,r9a07g054-adc # RZ/V2L 24 25 - const: renesas,rzg2l-adc ··· 77 76 properties: 78 77 reg: 79 78 description: | 80 - The channel number. It can have up to 8 channels numbered from 0 to 7. 81 - items: 82 - - minimum: 0 83 - maximum: 7 79 + The channel number. 84 80 85 81 required: 86 82 - reg 87 83 88 84 additionalProperties: false 85 + 86 + allOf: 87 + - if: 88 + properties: 89 + compatible: 90 + contains: 91 + const: renesas,r9a07g043-adc 92 + then: 93 + patternProperties: 94 + "^channel@[2-7]$": false 95 + "^channel@[0-1]$": 96 + properties: 97 + reg: 98 + minimum: 0 99 + maximum: 1 100 + else: 101 + patternProperties: 102 + "^channel@[0-7]$": 103 + properties: 104 + reg: 105 + minimum: 0 106 + maximum: 7 89 107 90 108 additionalProperties: false 91 109
+1 -1
Documentation/devicetree/bindings/iio/dac/adi,ad5770r.yaml
··· 8 8 title: Analog Devices AD5770R DAC device driver 9 9 10 10 maintainers: 11 - - Mircea Caprioru <mircea.caprioru@analog.com> 11 + - Alexandru Tachici <alexandru.tachici@analog.com> 12 12 13 13 description: | 14 14 Bindings for the Analog Devices AD5770R current DAC device. Datasheet can be
+1
Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml
··· 15 15 enum: 16 16 - microchip,mcp4902 17 17 - microchip,mcp4912 18 + - microchip,mcp4921 18 19 - microchip,mcp4922 19 20 20 21 reg:
+1
Documentation/devicetree/bindings/iio/dac/ti,dac5571.yaml
··· 21 21 - ti,dac5573 22 22 - ti,dac6573 23 23 - ti,dac7573 24 + - ti,dac121c081 24 25 25 26 reg: 26 27 maxItems: 1
+1 -1
Documentation/devicetree/bindings/iio/imu/adi,adis16480.yaml
··· 7 7 title: Analog Devices ADIS16480 and similar IMUs 8 8 9 9 maintainers: 10 - - Alexandru Ardelean <alexandru.ardelean@analog.com> 10 + - Alexandru Tachici <alexandru.tachici@analog.com> 11 11 12 12 properties: 13 13 compatible:
+39
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml
··· 126 126 UINT_MAX (4294967295) represents infinite. Other values 127 127 represent 1-1/N. 128 128 129 + semtech,cs-idle-sleep: 130 + description: 131 + State of CS pins during sleep mode and idle time. 132 + enum: 133 + - hi-z 134 + - gnd 135 + - vdd 136 + 137 + semtech,int-comp-resistor: 138 + description: 139 + Internal resistor setting for compensation. 140 + enum: 141 + - lowest 142 + - low 143 + - high 144 + - highest 145 + 146 + semtech,input-precharge-resistor-ohms: 147 + default: 4000 148 + multipleOf: 2000 149 + minimum: 0 150 + maximum: 30000 151 + description: 152 + Pre-charge input resistance in Ohm. 153 + 154 + semtech,input-analog-gain: 155 + $ref: /schemas/types.yaml#/definitions/uint32 156 + minimum: 0 157 + maximum: 3 158 + description: | 159 + Defines the input antenna analog gain 160 + 0: x1.247 161 + 1: x1 (default) 162 + 2: x0.768 163 + 3: x0.552 164 + 129 165 required: 130 166 - compatible 131 167 - reg ··· 193 157 semtech,ph01-proxraw-strength = <2>; 194 158 semtech,ph23-proxraw-strength = <2>; 195 159 semtech,avg-pos-strength = <64>; 160 + semtech,int-comp-resistor = "lowest"; 161 + semtech,input-precharge-resistor-ohms = <2000>; 162 + semtech,cs-idle-sleep = "gnd"; 196 163 }; 197 164 };
+9
Documentation/devicetree/bindings/iio/proximity/semtech,sx9360.yaml
··· 61 61 UINT_MAX (4294967295) represents infinite. Other values 62 62 represent 1-1/N. 63 63 64 + semtech,input-precharge-resistor-ohms: 65 + default: 0 66 + multipleOf: 2000 67 + minimum: 0 68 + maximum: 30000 69 + description: 70 + Pre-charge input resistance in Ohm. 71 + 64 72 required: 65 73 - compatible 66 74 - reg ··· 93 85 semtech,resolution = <256>; 94 86 semtech,proxraw-strength = <2>; 95 87 semtech,avg-pos-strength = <64>; 88 + semtech,input-precharge-resistor-ohms = <4000>; 96 89 }; 97 90 };
+5
Documentation/devicetree/bindings/iio/proximity/st,vl53l0x.yaml
··· 19 19 interrupts: 20 20 maxItems: 1 21 21 22 + reset-gpios: 23 + maxItems: 1 24 + 25 + vdd-supply: true 26 + 22 27 required: 23 28 - compatible 24 29 - reg
+1
MAINTAINERS
··· 9724 9724 F: Documentation/devicetree/bindings/iio/ 9725 9725 F: drivers/iio/ 9726 9726 F: drivers/staging/iio/ 9727 + F: include/dt-bindings/iio/ 9727 9728 F: include/linux/iio/ 9728 9729 F: tools/iio/ 9729 9730
+2
drivers/iio/accel/Kconfig
··· 204 204 config BMA400 205 205 tristate "Bosch BMA400 3-Axis Accelerometer Driver" 206 206 select REGMAP 207 + select IIO_BUFFER 208 + select IIO_TRIGGERED_BUFFER 207 209 select BMA400_I2C if I2C 208 210 select BMA400_SPI if SPI 209 211 help
+1 -1
drivers/iio/accel/adxl313_core.c
··· 46 46 struct adxl313_data { 47 47 struct regmap *regmap; 48 48 struct mutex lock; /* lock to protect transf_buf */ 49 - __le16 transf_buf ____cacheline_aligned; 49 + __le16 transf_buf __aligned(IIO_DMA_MINALIGN); 50 50 }; 51 51 52 52 static const int adxl313_odr_freqs[][2] = {
+1 -1
drivers/iio/accel/adxl355_core.c
··· 177 177 u8 buf[14]; 178 178 s64 ts; 179 179 } buffer; 180 - } ____cacheline_aligned; 180 + } __aligned(IIO_DMA_MINALIGN); 181 181 }; 182 182 183 183 static int adxl355_set_op_mode(struct adxl355_data *data,
+10 -38
drivers/iio/accel/adxl367.c
··· 179 179 unsigned int fifo_set_size; 180 180 unsigned int fifo_watermark; 181 181 182 - __be16 fifo_buf[ADXL367_FIFO_SIZE] ____cacheline_aligned; 182 + __be16 fifo_buf[ADXL367_FIFO_SIZE] __aligned(IIO_DMA_MINALIGN); 183 183 __be16 sample_buf; 184 184 u8 act_threshold_buf[2]; 185 185 u8 inact_time_buf[2]; ··· 447 447 fifo_format)); 448 448 } 449 449 450 - static int adxl367_set_fifo_samples(struct adxl367_state *st, 451 - unsigned int fifo_watermark, 452 - unsigned int fifo_set_size) 450 + static int adxl367_set_fifo_watermark(struct adxl367_state *st, 451 + unsigned int fifo_watermark) 453 452 { 454 - unsigned int fifo_samples = fifo_watermark * fifo_set_size; 453 + unsigned int fifo_samples = fifo_watermark * st->fifo_set_size; 455 454 unsigned int fifo_samples_h, fifo_samples_l; 456 455 int ret; 457 456 458 457 if (fifo_samples > ADXL367_FIFO_MAX_WATERMARK) 459 458 fifo_samples = ADXL367_FIFO_MAX_WATERMARK; 460 459 461 - if (fifo_set_size == 0) 462 - return 0; 463 - 464 - fifo_samples /= fifo_set_size; 460 + fifo_samples /= st->fifo_set_size; 465 461 466 462 fifo_samples_h = FIELD_PREP(ADXL367_SAMPLES_H_MASK, 467 463 FIELD_GET(ADXL367_SAMPLES_VAL_H_MASK, ··· 471 475 if (ret) 472 476 return ret; 473 477 474 - return regmap_update_bits(st->regmap, ADXL367_REG_FIFO_SAMPLES, 475 - ADXL367_SAMPLES_L_MASK, fifo_samples_l); 476 - } 477 - 478 - static int adxl367_set_fifo_set_size(struct adxl367_state *st, 479 - unsigned int fifo_set_size) 480 - { 481 - int ret; 482 - 483 - ret = adxl367_set_fifo_samples(st, st->fifo_watermark, fifo_set_size); 484 - if (ret) 485 - return ret; 486 - 487 - st->fifo_set_size = fifo_set_size; 488 - 489 - return 0; 490 - } 491 - 492 - static int adxl367_set_fifo_watermark(struct adxl367_state *st, 493 - unsigned int fifo_watermark) 494 - { 495 - int ret; 496 - 497 - ret = adxl367_set_fifo_samples(st, fifo_watermark, st->fifo_set_size); 478 + ret = regmap_update_bits(st->regmap, ADXL367_REG_FIFO_SAMPLES, 479 + ADXL367_SAMPLES_L_MASK, fifo_samples_l); 498 480 if (ret) 499 481 return ret; 500 482 ··· 1250 1276 { 1251 1277 struct adxl367_state *st = iio_priv(indio_dev); 1252 1278 enum adxl367_fifo_format fifo_format; 1253 - unsigned int fifo_set_size; 1254 1279 int ret; 1255 1280 1256 1281 if (!adxl367_find_mask_fifo_format(active_scan_mask, &fifo_format)) 1257 1282 return -EINVAL; 1258 - 1259 - fifo_set_size = bitmap_weight(active_scan_mask, indio_dev->masklength); 1260 1283 1261 1284 mutex_lock(&st->lock); 1262 1285 ··· 1265 1294 if (ret) 1266 1295 goto out; 1267 1296 1268 - ret = adxl367_set_fifo_set_size(st, fifo_set_size); 1297 + ret = adxl367_set_measure_en(st, true); 1269 1298 if (ret) 1270 1299 goto out; 1271 1300 1272 - ret = adxl367_set_measure_en(st, true); 1301 + st->fifo_set_size = bitmap_weight(active_scan_mask, 1302 + indio_dev->masklength); 1273 1303 1274 1304 out: 1275 1305 mutex_unlock(&st->lock);
+5 -3
drivers/iio/accel/adxl367_spi.c
··· 9 9 #include <linux/regmap.h> 10 10 #include <linux/spi/spi.h> 11 11 12 + #include <linux/iio/iio.h> 13 + 12 14 #include "adxl367.h" 13 15 14 16 #define ADXL367_SPI_WRITE_COMMAND 0x0A ··· 30 28 struct spi_transfer fifo_xfer[2]; 31 29 32 30 /* 33 - * DMA (thus cache coherency maintenance) requires the 34 - * transfer buffers to live in their own cache lines. 31 + * DMA (thus cache coherency maintenance) may require the 32 + * transfer buffers live in their own cache lines. 35 33 */ 36 - u8 reg_write_tx_buf[1] ____cacheline_aligned; 34 + u8 reg_write_tx_buf[1] __aligned(IIO_DMA_MINALIGN); 37 35 u8 reg_read_tx_buf[2]; 38 36 u8 fifo_tx_buf[1]; 39 37 };
+1 -1
drivers/iio/accel/bma220_spi.c
··· 67 67 /* Ensure timestamp is naturally aligned. */ 68 68 s64 timestamp __aligned(8); 69 69 } scan; 70 - u8 tx_buf[2] ____cacheline_aligned; 70 + u8 tx_buf[2] __aligned(IIO_DMA_MINALIGN); 71 71 }; 72 72 73 73 static const struct iio_chan_spec bma220_channels[] = {
+45 -5
drivers/iio/accel/bma400.h
··· 39 39 #define BMA400_INT_STAT0_REG 0x0e 40 40 #define BMA400_INT_STAT1_REG 0x0f 41 41 #define BMA400_INT_STAT2_REG 0x10 42 + #define BMA400_INT12_MAP_REG 0x23 42 43 43 44 /* Temperature register */ 44 45 #define BMA400_TEMP_DATA_REG 0x11 ··· 54 53 #define BMA400_STEP_CNT1_REG 0x16 55 54 #define BMA400_STEP_CNT3_REG 0x17 56 55 #define BMA400_STEP_STAT_REG 0x18 56 + #define BMA400_STEP_INT_MSK BIT(0) 57 + #define BMA400_STEP_RAW_LEN 0x03 58 + #define BMA400_STEP_STAT_MASK GENMASK(9, 8) 57 59 58 60 /* 59 61 * Read-write configuration registers ··· 65 61 #define BMA400_ACC_CONFIG1_REG 0x1a 66 62 #define BMA400_ACC_CONFIG2_REG 0x1b 67 63 #define BMA400_CMD_REG 0x7e 64 + 65 + /* Interrupt registers */ 66 + #define BMA400_INT_CONFIG0_REG 0x1f 67 + #define BMA400_INT_CONFIG1_REG 0x20 68 + #define BMA400_INT1_MAP_REG 0x21 69 + #define BMA400_INT_IO_CTRL_REG 0x24 70 + #define BMA400_INT_DRDY_MSK BIT(7) 68 71 69 72 /* Chip ID of BMA 400 devices found in the chip ID register. */ 70 73 #define BMA400_ID_REG_VAL 0x90 ··· 94 83 #define BMA400_ACC_ODR_MIN_WHOLE_HZ 25 95 84 #define BMA400_ACC_ODR_MIN_HZ 12 96 85 97 - #define BMA400_SCALE_MIN 38357 98 - #define BMA400_SCALE_MAX 306864 86 + /* Generic interrupts register */ 87 + #define BMA400_GEN1INT_CONFIG0 0x3f 88 + #define BMA400_GEN2INT_CONFIG0 0x4A 89 + #define BMA400_GEN_CONFIG1_OFF 0x01 90 + #define BMA400_GEN_CONFIG2_OFF 0x02 91 + #define BMA400_GEN_CONFIG3_OFF 0x03 92 + #define BMA400_GEN_CONFIG31_OFF 0x04 93 + #define BMA400_INT_GEN1_MSK BIT(2) 94 + #define BMA400_INT_GEN2_MSK BIT(3) 95 + #define BMA400_GEN_HYST_MSK GENMASK(1, 0) 96 + 97 + /* 98 + * BMA400_SCALE_MIN macro value represents m/s^2 for 1 LSB before 99 + * converting to micro values for +-2g range. 100 + * 101 + * For +-2g - 1 LSB = 0.976562 milli g = 0.009576 m/s^2 102 + * For +-4g - 1 LSB = 1.953125 milli g = 0.019153 m/s^2 103 + * For +-16g - 1 LSB = 7.8125 milli g = 0.076614 m/s^2 104 + * 105 + * The raw value which is used to select the different ranges is determined 106 + * by the first bit set position from the scale value, so BMA400_SCALE_MIN 107 + * should be odd. 108 + * 109 + * Scale values for +-2g, +-4g, +-8g and +-16g are populated into bma400_scales 110 + * array by left shifting BMA400_SCALE_MIN. 111 + * e.g.: 112 + * To select +-2g = 9577 << 0 = raw value to write is 0. 113 + * To select +-8g = 9577 << 2 = raw value to write is 2. 114 + * To select +-16g = 9577 << 3 = raw value to write is 3. 115 + */ 116 + #define BMA400_SCALE_MIN 9577 117 + #define BMA400_SCALE_MAX 76617 99 118 100 119 #define BMA400_NUM_REGULATORS 2 101 120 #define BMA400_VDD_REGULATOR 0 ··· 133 92 134 93 extern const struct regmap_config bma400_regmap_config; 135 94 136 - int bma400_probe(struct device *dev, struct regmap *regmap, const char *name); 137 - 138 - void bma400_remove(struct device *dev); 95 + int bma400_probe(struct device *dev, struct regmap *regmap, int irq, 96 + const char *name); 139 97 140 98 #endif
+667 -49
drivers/iio/accel/bma400_core.c
··· 11 11 * - Create channel for sensor time 12 12 */ 13 13 14 + #include <linux/bitfield.h> 14 15 #include <linux/bitops.h> 15 16 #include <linux/device.h> 16 - #include <linux/iio/iio.h> 17 - #include <linux/iio/sysfs.h> 18 17 #include <linux/kernel.h> 19 18 #include <linux/module.h> 20 19 #include <linux/mutex.h> 21 20 #include <linux/regmap.h> 22 21 #include <linux/regulator/consumer.h> 22 + #include <linux/slab.h> 23 + 24 + #include <asm/unaligned.h> 25 + 26 + #include <linux/iio/iio.h> 27 + #include <linux/iio/buffer.h> 28 + #include <linux/iio/events.h> 29 + #include <linux/iio/trigger.h> 30 + #include <linux/iio/trigger_consumer.h> 31 + #include <linux/iio/triggered_buffer.h> 23 32 24 33 #include "bma400.h" 25 34 ··· 55 46 POWER_MODE_INVALID = 0x03, 56 47 }; 57 48 49 + enum bma400_scan { 50 + BMA400_ACCL_X, 51 + BMA400_ACCL_Y, 52 + BMA400_ACCL_Z, 53 + BMA400_TEMP, 54 + }; 55 + 58 56 struct bma400_sample_freq { 59 57 int hz; 60 58 int uhz; 59 + }; 60 + 61 + enum bma400_activity { 62 + BMA400_STILL, 63 + BMA400_WALKING, 64 + BMA400_RUNNING, 61 65 }; 62 66 63 67 struct bma400_data { ··· 83 61 struct bma400_sample_freq sample_freq; 84 62 int oversampling_ratio; 85 63 int scale; 64 + struct iio_trigger *trig; 65 + int steps_enabled; 66 + bool step_event_en; 67 + bool activity_event_en; 68 + unsigned int generic_event_en; 69 + /* Correct time stamp alignment */ 70 + struct { 71 + __le16 buff[3]; 72 + u8 temperature; 73 + s64 ts __aligned(8); 74 + } buffer __aligned(IIO_DMA_MINALIGN); 75 + __le16 status; 76 + __be16 duration; 86 77 }; 87 78 88 79 static bool bma400_is_writable_reg(struct device *dev, unsigned int reg) ··· 187 152 { } 188 153 }; 189 154 190 - #define BMA400_ACC_CHANNEL(_axis) { \ 155 + static const struct iio_event_spec bma400_step_detect_event = { 156 + .type = IIO_EV_TYPE_CHANGE, 157 + .dir = IIO_EV_DIR_NONE, 158 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 159 + }; 160 + 161 + static const struct iio_event_spec bma400_activity_event = { 162 + .type = IIO_EV_TYPE_CHANGE, 163 + .dir = IIO_EV_DIR_NONE, 164 + .mask_shared_by_type = BIT(IIO_EV_INFO_ENABLE), 165 + }; 166 + 167 + static const struct iio_event_spec bma400_accel_event[] = { 168 + { 169 + .type = IIO_EV_TYPE_MAG, 170 + .dir = IIO_EV_DIR_FALLING, 171 + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 172 + BIT(IIO_EV_INFO_PERIOD) | 173 + BIT(IIO_EV_INFO_HYSTERESIS) | 174 + BIT(IIO_EV_INFO_ENABLE), 175 + }, 176 + { 177 + .type = IIO_EV_TYPE_MAG, 178 + .dir = IIO_EV_DIR_RISING, 179 + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 180 + BIT(IIO_EV_INFO_PERIOD) | 181 + BIT(IIO_EV_INFO_HYSTERESIS) | 182 + BIT(IIO_EV_INFO_ENABLE), 183 + }, 184 + }; 185 + 186 + #define BMA400_ACC_CHANNEL(_index, _axis) { \ 191 187 .type = IIO_ACCEL, \ 192 188 .modified = 1, \ 193 189 .channel2 = IIO_MOD_##_axis, \ ··· 230 164 BIT(IIO_CHAN_INFO_SCALE) | \ 231 165 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 232 166 .ext_info = bma400_ext_info, \ 167 + .scan_index = _index, \ 168 + .scan_type = { \ 169 + .sign = 's', \ 170 + .realbits = 12, \ 171 + .storagebits = 16, \ 172 + .endianness = IIO_LE, \ 173 + }, \ 174 + .event_spec = bma400_accel_event, \ 175 + .num_event_specs = ARRAY_SIZE(bma400_accel_event) \ 176 + } 177 + 178 + #define BMA400_ACTIVITY_CHANNEL(_chan2) { \ 179 + .type = IIO_ACTIVITY, \ 180 + .modified = 1, \ 181 + .channel2 = _chan2, \ 182 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 183 + .scan_index = -1, /* No buffer support */ \ 184 + .event_spec = &bma400_activity_event, \ 185 + .num_event_specs = 1, \ 233 186 } 234 187 235 188 static const struct iio_chan_spec bma400_channels[] = { 236 - BMA400_ACC_CHANNEL(X), 237 - BMA400_ACC_CHANNEL(Y), 238 - BMA400_ACC_CHANNEL(Z), 189 + BMA400_ACC_CHANNEL(0, X), 190 + BMA400_ACC_CHANNEL(1, Y), 191 + BMA400_ACC_CHANNEL(2, Z), 239 192 { 240 193 .type = IIO_TEMP, 241 194 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 242 195 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), 196 + .scan_index = 3, 197 + .scan_type = { 198 + .sign = 's', 199 + .realbits = 8, 200 + .storagebits = 8, 201 + .endianness = IIO_LE, 202 + }, 243 203 }, 204 + { 205 + .type = IIO_STEPS, 206 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 207 + BIT(IIO_CHAN_INFO_ENABLE), 208 + .scan_index = -1, /* No buffer support */ 209 + .event_spec = &bma400_step_detect_event, 210 + .num_event_specs = 1, 211 + }, 212 + BMA400_ACTIVITY_CHANNEL(IIO_MOD_STILL), 213 + BMA400_ACTIVITY_CHANNEL(IIO_MOD_WALKING), 214 + BMA400_ACTIVITY_CHANNEL(IIO_MOD_RUNNING), 215 + IIO_CHAN_SOFT_TIMESTAMP(4), 244 216 }; 245 217 246 218 static int bma400_get_temp_reg(struct bma400_data *data, int *val, int *val2) ··· 646 542 return 0; 647 543 } 648 544 545 + static int bma400_enable_steps(struct bma400_data *data, int val) 546 + { 547 + int ret; 548 + 549 + if (data->steps_enabled == val) 550 + return 0; 551 + 552 + ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG1_REG, 553 + BMA400_STEP_INT_MSK, 554 + FIELD_PREP(BMA400_STEP_INT_MSK, val ? 1 : 0)); 555 + if (ret) 556 + return ret; 557 + data->steps_enabled = val; 558 + return ret; 559 + } 560 + 561 + static int bma400_get_steps_reg(struct bma400_data *data, int *val) 562 + { 563 + u8 *steps_raw; 564 + int ret; 565 + 566 + steps_raw = kmalloc(BMA400_STEP_RAW_LEN, GFP_KERNEL); 567 + if (!steps_raw) 568 + return -ENOMEM; 569 + 570 + ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG, 571 + steps_raw, BMA400_STEP_RAW_LEN); 572 + if (ret) 573 + return ret; 574 + *val = get_unaligned_le24(steps_raw); 575 + kfree(steps_raw); 576 + return IIO_VAL_INT; 577 + } 578 + 649 579 static void bma400_init_tables(void) 650 580 { 651 581 int raw; ··· 698 560 } 699 561 } 700 562 563 + static void bma400_regulators_disable(void *data_ptr) 564 + { 565 + struct bma400_data *data = data_ptr; 566 + 567 + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 568 + } 569 + 570 + static void bma400_power_disable(void *data_ptr) 571 + { 572 + struct bma400_data *data = data_ptr; 573 + int ret; 574 + 575 + mutex_lock(&data->mutex); 576 + ret = bma400_set_power_mode(data, POWER_MODE_SLEEP); 577 + mutex_unlock(&data->mutex); 578 + if (ret) 579 + dev_warn(data->dev, "Failed to put device into sleep mode (%pe)\n", 580 + ERR_PTR(ret)); 581 + } 582 + 583 + static enum iio_modifier bma400_act_to_mod(enum bma400_activity activity) 584 + { 585 + switch (activity) { 586 + case BMA400_STILL: 587 + return IIO_MOD_STILL; 588 + case BMA400_WALKING: 589 + return IIO_MOD_WALKING; 590 + case BMA400_RUNNING: 591 + return IIO_MOD_RUNNING; 592 + default: 593 + return IIO_NO_MOD; 594 + } 595 + } 596 + 701 597 static int bma400_init(struct bma400_data *data) 702 598 { 703 599 unsigned int val; ··· 741 569 ret = regmap_read(data->regmap, BMA400_CHIP_ID_REG, &val); 742 570 if (ret) { 743 571 dev_err(data->dev, "Failed to read chip id register\n"); 744 - goto out; 572 + return ret; 745 573 } 746 574 747 575 if (val != BMA400_ID_REG_VAL) { 748 576 dev_err(data->dev, "Chip ID mismatch\n"); 749 - ret = -ENODEV; 750 - goto out; 577 + return -ENODEV; 751 578 } 752 579 753 580 data->regulators[BMA400_VDD_REGULATOR].supply = "vdd"; ··· 760 589 "Failed to get regulators: %d\n", 761 590 ret); 762 591 763 - goto out; 592 + return ret; 764 593 } 765 594 ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), 766 595 data->regulators); 767 596 if (ret) { 768 597 dev_err(data->dev, "Failed to enable regulators: %d\n", 769 598 ret); 770 - goto out; 599 + return ret; 771 600 } 601 + 602 + ret = devm_add_action_or_reset(data->dev, bma400_regulators_disable, data); 603 + if (ret) 604 + return ret; 772 605 773 606 ret = bma400_get_power_mode(data); 774 607 if (ret) { 775 608 dev_err(data->dev, "Failed to get the initial power-mode\n"); 776 - goto err_reg_disable; 609 + return ret; 777 610 } 778 611 779 612 if (data->power_mode != POWER_MODE_NORMAL) { 780 613 ret = bma400_set_power_mode(data, POWER_MODE_NORMAL); 781 614 if (ret) { 782 615 dev_err(data->dev, "Failed to wake up the device\n"); 783 - goto err_reg_disable; 616 + return ret; 784 617 } 785 618 /* 786 619 * TODO: The datasheet waits 1500us here in the example, but ··· 793 618 usleep_range(1500, 2000); 794 619 } 795 620 621 + ret = devm_add_action_or_reset(data->dev, bma400_power_disable, data); 622 + if (ret) 623 + return ret; 624 + 796 625 bma400_init_tables(); 797 626 798 627 ret = bma400_get_accel_output_data_rate(data); 799 628 if (ret) 800 - goto err_reg_disable; 629 + return ret; 801 630 802 631 ret = bma400_get_accel_oversampling_ratio(data); 803 632 if (ret) 804 - goto err_reg_disable; 633 + return ret; 805 634 806 635 ret = bma400_get_accel_scale(data); 807 636 if (ret) 808 - goto err_reg_disable; 637 + return ret; 809 638 639 + /* Configure INT1 pin to open drain */ 640 + ret = regmap_write(data->regmap, BMA400_INT_IO_CTRL_REG, 0x06); 641 + if (ret) 642 + return ret; 810 643 /* 811 644 * Once the interrupt engine is supported we might use the 812 645 * data_src_reg, but for now ensure this is set to the ··· 822 639 * channel. 823 640 */ 824 641 return regmap_write(data->regmap, BMA400_ACC_CONFIG2_REG, 0x00); 825 - 826 - err_reg_disable: 827 - regulator_bulk_disable(ARRAY_SIZE(data->regulators), 828 - data->regulators); 829 - out: 830 - return ret; 831 642 } 832 643 833 644 static int bma400_read_raw(struct iio_dev *indio_dev, ··· 829 652 int *val2, long mask) 830 653 { 831 654 struct bma400_data *data = iio_priv(indio_dev); 655 + unsigned int activity; 832 656 int ret; 833 657 834 658 switch (mask) { 835 659 case IIO_CHAN_INFO_PROCESSED: 836 - mutex_lock(&data->mutex); 837 - ret = bma400_get_temp_reg(data, val, val2); 838 - mutex_unlock(&data->mutex); 839 - return ret; 660 + switch (chan->type) { 661 + case IIO_TEMP: 662 + mutex_lock(&data->mutex); 663 + ret = bma400_get_temp_reg(data, val, val2); 664 + mutex_unlock(&data->mutex); 665 + return ret; 666 + case IIO_STEPS: 667 + return bma400_get_steps_reg(data, val); 668 + case IIO_ACTIVITY: 669 + ret = regmap_read(data->regmap, BMA400_STEP_STAT_REG, 670 + &activity); 671 + if (ret) 672 + return ret; 673 + /* 674 + * The device does not support confidence value levels, 675 + * so we will always have 100% for current activity and 676 + * 0% for the others. 677 + */ 678 + if (chan->channel2 == bma400_act_to_mod(activity)) 679 + *val = 100; 680 + else 681 + *val = 0; 682 + return IIO_VAL_INT; 683 + default: 684 + return -EINVAL; 685 + } 840 686 case IIO_CHAN_INFO_RAW: 841 687 mutex_lock(&data->mutex); 842 688 ret = bma400_get_accel_reg(data, chan, val); ··· 899 699 return -EINVAL; 900 700 901 701 *val = data->oversampling_ratio; 702 + return IIO_VAL_INT; 703 + case IIO_CHAN_INFO_ENABLE: 704 + *val = data->steps_enabled; 902 705 return IIO_VAL_INT; 903 706 default: 904 707 return -EINVAL; ··· 968 765 ret = bma400_set_accel_oversampling_ratio(data, val); 969 766 mutex_unlock(&data->mutex); 970 767 return ret; 768 + case IIO_CHAN_INFO_ENABLE: 769 + mutex_lock(&data->mutex); 770 + ret = bma400_enable_steps(data, val); 771 + mutex_unlock(&data->mutex); 772 + return ret; 971 773 default: 972 774 return -EINVAL; 973 775 } ··· 989 781 return IIO_VAL_INT_PLUS_MICRO; 990 782 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 991 783 return IIO_VAL_INT; 784 + case IIO_CHAN_INFO_ENABLE: 785 + return IIO_VAL_INT; 992 786 default: 993 787 return -EINVAL; 994 788 } 995 789 } 790 + 791 + static int bma400_read_event_config(struct iio_dev *indio_dev, 792 + const struct iio_chan_spec *chan, 793 + enum iio_event_type type, 794 + enum iio_event_direction dir) 795 + { 796 + struct bma400_data *data = iio_priv(indio_dev); 797 + 798 + switch (chan->type) { 799 + case IIO_ACCEL: 800 + switch (dir) { 801 + case IIO_EV_DIR_RISING: 802 + return FIELD_GET(BMA400_INT_GEN1_MSK, 803 + data->generic_event_en); 804 + case IIO_EV_DIR_FALLING: 805 + return FIELD_GET(BMA400_INT_GEN2_MSK, 806 + data->generic_event_en); 807 + default: 808 + return -EINVAL; 809 + } 810 + case IIO_STEPS: 811 + return data->step_event_en; 812 + case IIO_ACTIVITY: 813 + return data->activity_event_en; 814 + default: 815 + return -EINVAL; 816 + } 817 + } 818 + 819 + static int bma400_steps_event_enable(struct bma400_data *data, int state) 820 + { 821 + int ret; 822 + 823 + ret = bma400_enable_steps(data, 1); 824 + if (ret) 825 + return ret; 826 + 827 + ret = regmap_update_bits(data->regmap, BMA400_INT12_MAP_REG, 828 + BMA400_STEP_INT_MSK, 829 + FIELD_PREP(BMA400_STEP_INT_MSK, 830 + state)); 831 + if (ret) 832 + return ret; 833 + data->step_event_en = state; 834 + return 0; 835 + } 836 + 837 + static int bma400_activity_event_en(struct bma400_data *data, 838 + enum iio_event_direction dir, 839 + int state) 840 + { 841 + int ret, reg, msk, value, field_value; 842 + 843 + switch (dir) { 844 + case IIO_EV_DIR_RISING: 845 + reg = BMA400_GEN1INT_CONFIG0; 846 + msk = BMA400_INT_GEN1_MSK; 847 + value = 2; 848 + set_mask_bits(&field_value, BMA400_INT_GEN1_MSK, 849 + FIELD_PREP(BMA400_INT_GEN1_MSK, state)); 850 + break; 851 + case IIO_EV_DIR_FALLING: 852 + reg = BMA400_GEN2INT_CONFIG0; 853 + msk = BMA400_INT_GEN2_MSK; 854 + value = 0; 855 + set_mask_bits(&field_value, BMA400_INT_GEN2_MSK, 856 + FIELD_PREP(BMA400_INT_GEN2_MSK, state)); 857 + break; 858 + default: 859 + return -EINVAL; 860 + } 861 + 862 + /* Enabling all axis for interrupt evaluation */ 863 + ret = regmap_write(data->regmap, reg, 0xF8); 864 + if (ret) 865 + return ret; 866 + 867 + /* OR combination of all axis for interrupt evaluation */ 868 + ret = regmap_write(data->regmap, reg + BMA400_GEN_CONFIG1_OFF, value); 869 + if (ret) 870 + return ret; 871 + 872 + /* Initial value to avoid interrupts while enabling*/ 873 + ret = regmap_write(data->regmap, reg + BMA400_GEN_CONFIG2_OFF, 0x0A); 874 + if (ret) 875 + return ret; 876 + 877 + /* Initial duration value to avoid interrupts while enabling*/ 878 + ret = regmap_write(data->regmap, reg + BMA400_GEN_CONFIG31_OFF, 0x0F); 879 + if (ret) 880 + return ret; 881 + 882 + ret = regmap_update_bits(data->regmap, BMA400_INT1_MAP_REG, msk, 883 + field_value); 884 + if (ret) 885 + return ret; 886 + 887 + ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG0_REG, msk, 888 + field_value); 889 + if (ret) 890 + return ret; 891 + 892 + set_mask_bits(&data->generic_event_en, msk, field_value); 893 + return 0; 894 + } 895 + 896 + static int bma400_write_event_config(struct iio_dev *indio_dev, 897 + const struct iio_chan_spec *chan, 898 + enum iio_event_type type, 899 + enum iio_event_direction dir, int state) 900 + { 901 + struct bma400_data *data = iio_priv(indio_dev); 902 + int ret; 903 + 904 + switch (chan->type) { 905 + case IIO_ACCEL: 906 + mutex_lock(&data->mutex); 907 + ret = bma400_activity_event_en(data, dir, state); 908 + mutex_unlock(&data->mutex); 909 + return ret; 910 + case IIO_STEPS: 911 + mutex_lock(&data->mutex); 912 + ret = bma400_steps_event_enable(data, state); 913 + mutex_unlock(&data->mutex); 914 + return ret; 915 + case IIO_ACTIVITY: 916 + mutex_lock(&data->mutex); 917 + if (!data->step_event_en) { 918 + ret = bma400_steps_event_enable(data, true); 919 + if (ret) { 920 + mutex_unlock(&data->mutex); 921 + return ret; 922 + } 923 + } 924 + data->activity_event_en = state; 925 + mutex_unlock(&data->mutex); 926 + return 0; 927 + default: 928 + return -EINVAL; 929 + } 930 + } 931 + 932 + static int get_gen_config_reg(enum iio_event_direction dir) 933 + { 934 + switch (dir) { 935 + case IIO_EV_DIR_FALLING: 936 + return BMA400_GEN2INT_CONFIG0; 937 + case IIO_EV_DIR_RISING: 938 + return BMA400_GEN1INT_CONFIG0; 939 + default: 940 + return -EINVAL; 941 + } 942 + } 943 + 944 + static int bma400_read_event_value(struct iio_dev *indio_dev, 945 + const struct iio_chan_spec *chan, 946 + enum iio_event_type type, 947 + enum iio_event_direction dir, 948 + enum iio_event_info info, 949 + int *val, int *val2) 950 + { 951 + struct bma400_data *data = iio_priv(indio_dev); 952 + int ret, reg; 953 + 954 + switch (chan->type) { 955 + case IIO_ACCEL: 956 + reg = get_gen_config_reg(dir); 957 + if (reg < 0) 958 + return -EINVAL; 959 + 960 + *val2 = 0; 961 + switch (info) { 962 + case IIO_EV_INFO_VALUE: 963 + ret = regmap_read(data->regmap, 964 + reg + BMA400_GEN_CONFIG2_OFF, 965 + val); 966 + if (ret) 967 + return ret; 968 + return IIO_VAL_INT; 969 + case IIO_EV_INFO_PERIOD: 970 + mutex_lock(&data->mutex); 971 + ret = regmap_bulk_read(data->regmap, 972 + reg + BMA400_GEN_CONFIG3_OFF, 973 + &data->duration, 974 + sizeof(data->duration)); 975 + if (ret) { 976 + mutex_unlock(&data->mutex); 977 + return ret; 978 + } 979 + *val = be16_to_cpu(data->duration); 980 + mutex_unlock(&data->mutex); 981 + return IIO_VAL_INT; 982 + case IIO_EV_INFO_HYSTERESIS: 983 + ret = regmap_read(data->regmap, reg, val); 984 + if (ret) 985 + return ret; 986 + *val = FIELD_GET(BMA400_GEN_HYST_MSK, *val); 987 + return IIO_VAL_INT; 988 + default: 989 + return -EINVAL; 990 + } 991 + default: 992 + return -EINVAL; 993 + } 994 + } 995 + 996 + static int bma400_write_event_value(struct iio_dev *indio_dev, 997 + const struct iio_chan_spec *chan, 998 + enum iio_event_type type, 999 + enum iio_event_direction dir, 1000 + enum iio_event_info info, 1001 + int val, int val2) 1002 + { 1003 + struct bma400_data *data = iio_priv(indio_dev); 1004 + int reg, ret; 1005 + 1006 + switch (chan->type) { 1007 + case IIO_ACCEL: 1008 + reg = get_gen_config_reg(dir); 1009 + if (reg < 0) 1010 + return -EINVAL; 1011 + 1012 + switch (info) { 1013 + case IIO_EV_INFO_VALUE: 1014 + if (val < 1 || val > 255) 1015 + return -EINVAL; 1016 + 1017 + return regmap_write(data->regmap, 1018 + reg + BMA400_GEN_CONFIG2_OFF, 1019 + val); 1020 + case IIO_EV_INFO_PERIOD: 1021 + if (val < 1 || val > 65535) 1022 + return -EINVAL; 1023 + 1024 + mutex_lock(&data->mutex); 1025 + put_unaligned_be16(val, &data->duration); 1026 + ret = regmap_bulk_write(data->regmap, 1027 + reg + BMA400_GEN_CONFIG3_OFF, 1028 + &data->duration, 1029 + sizeof(data->duration)); 1030 + mutex_unlock(&data->mutex); 1031 + return ret; 1032 + case IIO_EV_INFO_HYSTERESIS: 1033 + if (val < 0 || val > 3) 1034 + return -EINVAL; 1035 + 1036 + return regmap_update_bits(data->regmap, reg, 1037 + BMA400_GEN_HYST_MSK, 1038 + FIELD_PREP(BMA400_GEN_HYST_MSK, 1039 + val)); 1040 + default: 1041 + return -EINVAL; 1042 + } 1043 + default: 1044 + return -EINVAL; 1045 + } 1046 + } 1047 + 1048 + static int bma400_data_rdy_trigger_set_state(struct iio_trigger *trig, 1049 + bool state) 1050 + { 1051 + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 1052 + struct bma400_data *data = iio_priv(indio_dev); 1053 + int ret; 1054 + 1055 + ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG0_REG, 1056 + BMA400_INT_DRDY_MSK, 1057 + FIELD_PREP(BMA400_INT_DRDY_MSK, state)); 1058 + if (ret) 1059 + return ret; 1060 + 1061 + return regmap_update_bits(data->regmap, BMA400_INT1_MAP_REG, 1062 + BMA400_INT_DRDY_MSK, 1063 + FIELD_PREP(BMA400_INT_DRDY_MSK, state)); 1064 + } 1065 + 1066 + static const unsigned long bma400_avail_scan_masks[] = { 1067 + BIT(BMA400_ACCL_X) | BIT(BMA400_ACCL_Y) | BIT(BMA400_ACCL_Z), 1068 + BIT(BMA400_ACCL_X) | BIT(BMA400_ACCL_Y) | BIT(BMA400_ACCL_Z) 1069 + | BIT(BMA400_TEMP), 1070 + 0 1071 + }; 996 1072 997 1073 static const struct iio_info bma400_info = { 998 1074 .read_raw = bma400_read_raw, 999 1075 .read_avail = bma400_read_avail, 1000 1076 .write_raw = bma400_write_raw, 1001 1077 .write_raw_get_fmt = bma400_write_raw_get_fmt, 1078 + .read_event_config = bma400_read_event_config, 1079 + .write_event_config = bma400_write_event_config, 1080 + .write_event_value = bma400_write_event_value, 1081 + .read_event_value = bma400_read_event_value, 1002 1082 }; 1003 1083 1004 - int bma400_probe(struct device *dev, struct regmap *regmap, const char *name) 1084 + static const struct iio_trigger_ops bma400_trigger_ops = { 1085 + .set_trigger_state = &bma400_data_rdy_trigger_set_state, 1086 + .validate_device = &iio_trigger_validate_own_device, 1087 + }; 1088 + 1089 + static irqreturn_t bma400_trigger_handler(int irq, void *p) 1090 + { 1091 + struct iio_poll_func *pf = p; 1092 + struct iio_dev *indio_dev = pf->indio_dev; 1093 + struct bma400_data *data = iio_priv(indio_dev); 1094 + int ret, temp; 1095 + 1096 + /* Lock to protect the data->buffer */ 1097 + mutex_lock(&data->mutex); 1098 + 1099 + /* bulk read six registers, with the base being the LSB register */ 1100 + ret = regmap_bulk_read(data->regmap, BMA400_X_AXIS_LSB_REG, 1101 + &data->buffer.buff, sizeof(data->buffer.buff)); 1102 + if (ret) 1103 + goto unlock_err; 1104 + 1105 + if (test_bit(BMA400_TEMP, indio_dev->active_scan_mask)) { 1106 + ret = regmap_read(data->regmap, BMA400_TEMP_DATA_REG, &temp); 1107 + if (ret) 1108 + goto unlock_err; 1109 + 1110 + data->buffer.temperature = temp; 1111 + } 1112 + 1113 + iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, 1114 + iio_get_time_ns(indio_dev)); 1115 + 1116 + mutex_unlock(&data->mutex); 1117 + iio_trigger_notify_done(indio_dev->trig); 1118 + return IRQ_HANDLED; 1119 + 1120 + unlock_err: 1121 + mutex_unlock(&data->mutex); 1122 + return IRQ_NONE; 1123 + } 1124 + 1125 + static irqreturn_t bma400_interrupt(int irq, void *private) 1126 + { 1127 + struct iio_dev *indio_dev = private; 1128 + struct bma400_data *data = iio_priv(indio_dev); 1129 + s64 timestamp = iio_get_time_ns(indio_dev); 1130 + unsigned int act, ev_dir = IIO_EV_DIR_NONE; 1131 + int ret; 1132 + 1133 + /* Lock to protect the data->status */ 1134 + mutex_lock(&data->mutex); 1135 + ret = regmap_bulk_read(data->regmap, BMA400_INT_STAT0_REG, 1136 + &data->status, 1137 + sizeof(data->status)); 1138 + /* 1139 + * if none of the bit is set in the status register then it is 1140 + * spurious interrupt. 1141 + */ 1142 + if (ret || !data->status) 1143 + goto unlock_err; 1144 + 1145 + if (FIELD_GET(BMA400_INT_GEN1_MSK, le16_to_cpu(data->status))) 1146 + ev_dir = IIO_EV_DIR_RISING; 1147 + 1148 + if (FIELD_GET(BMA400_INT_GEN2_MSK, le16_to_cpu(data->status))) 1149 + ev_dir = IIO_EV_DIR_FALLING; 1150 + 1151 + if (ev_dir != IIO_EV_DIR_NONE) { 1152 + iio_push_event(indio_dev, 1153 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, 1154 + IIO_MOD_X_OR_Y_OR_Z, 1155 + IIO_EV_TYPE_MAG, ev_dir), 1156 + timestamp); 1157 + } 1158 + 1159 + if (FIELD_GET(BMA400_STEP_STAT_MASK, le16_to_cpu(data->status))) { 1160 + iio_push_event(indio_dev, 1161 + IIO_MOD_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD, 1162 + IIO_EV_TYPE_CHANGE, 1163 + IIO_EV_DIR_NONE), 1164 + timestamp); 1165 + 1166 + if (data->activity_event_en) { 1167 + ret = regmap_read(data->regmap, BMA400_STEP_STAT_REG, 1168 + &act); 1169 + if (ret) 1170 + goto unlock_err; 1171 + 1172 + iio_push_event(indio_dev, 1173 + IIO_MOD_EVENT_CODE(IIO_ACTIVITY, 0, 1174 + bma400_act_to_mod(act), 1175 + IIO_EV_TYPE_CHANGE, 1176 + IIO_EV_DIR_NONE), 1177 + timestamp); 1178 + } 1179 + } 1180 + 1181 + if (FIELD_GET(BMA400_INT_DRDY_MSK, le16_to_cpu(data->status))) { 1182 + mutex_unlock(&data->mutex); 1183 + iio_trigger_poll_chained(data->trig); 1184 + return IRQ_HANDLED; 1185 + } 1186 + 1187 + mutex_unlock(&data->mutex); 1188 + return IRQ_HANDLED; 1189 + 1190 + unlock_err: 1191 + mutex_unlock(&data->mutex); 1192 + return IRQ_NONE; 1193 + } 1194 + 1195 + int bma400_probe(struct device *dev, struct regmap *regmap, int irq, 1196 + const char *name) 1005 1197 { 1006 1198 struct iio_dev *indio_dev; 1007 1199 struct bma400_data *data; ··· 1428 820 indio_dev->info = &bma400_info; 1429 821 indio_dev->channels = bma400_channels; 1430 822 indio_dev->num_channels = ARRAY_SIZE(bma400_channels); 823 + indio_dev->available_scan_masks = bma400_avail_scan_masks; 1431 824 indio_dev->modes = INDIO_DIRECT_MODE; 1432 825 1433 - dev_set_drvdata(dev, indio_dev); 826 + if (irq > 0) { 827 + data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 828 + indio_dev->name, 829 + iio_device_id(indio_dev)); 830 + if (!data->trig) 831 + return -ENOMEM; 1434 832 1435 - return iio_device_register(indio_dev); 833 + data->trig->ops = &bma400_trigger_ops; 834 + iio_trigger_set_drvdata(data->trig, indio_dev); 835 + 836 + ret = devm_iio_trigger_register(data->dev, data->trig); 837 + if (ret) 838 + return dev_err_probe(data->dev, ret, 839 + "iio trigger register fail\n"); 840 + 841 + indio_dev->trig = iio_trigger_get(data->trig); 842 + ret = devm_request_threaded_irq(dev, irq, NULL, 843 + &bma400_interrupt, 844 + IRQF_TRIGGER_RISING | IRQF_ONESHOT, 845 + indio_dev->name, indio_dev); 846 + if (ret) 847 + return dev_err_probe(data->dev, ret, 848 + "request irq %d failed\n", irq); 849 + } 850 + 851 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, 852 + &bma400_trigger_handler, NULL); 853 + if (ret) 854 + return dev_err_probe(data->dev, ret, 855 + "iio triggered buffer setup failed\n"); 856 + 857 + return devm_iio_device_register(dev, indio_dev); 1436 858 } 1437 859 EXPORT_SYMBOL_NS(bma400_probe, IIO_BMA400); 1438 - 1439 - void bma400_remove(struct device *dev) 1440 - { 1441 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 1442 - struct bma400_data *data = iio_priv(indio_dev); 1443 - int ret; 1444 - 1445 - mutex_lock(&data->mutex); 1446 - ret = bma400_set_power_mode(data, POWER_MODE_SLEEP); 1447 - mutex_unlock(&data->mutex); 1448 - 1449 - if (ret) 1450 - dev_warn(dev, "Failed to put device into sleep mode (%pe)\n", ERR_PTR(ret)); 1451 - 1452 - regulator_bulk_disable(ARRAY_SIZE(data->regulators), 1453 - data->regulators); 1454 - 1455 - iio_device_unregister(indio_dev); 1456 - } 1457 - EXPORT_SYMBOL_NS(bma400_remove, IIO_BMA400); 1458 860 1459 861 MODULE_AUTHOR("Dan Robertson <dan@dlrobertson.com>"); 1460 862 MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor core");
+1 -9
drivers/iio/accel/bma400_i2c.c
··· 24 24 return PTR_ERR(regmap); 25 25 } 26 26 27 - return bma400_probe(&client->dev, regmap, id->name); 28 - } 29 - 30 - static int bma400_i2c_remove(struct i2c_client *client) 31 - { 32 - bma400_remove(&client->dev); 33 - 34 - return 0; 27 + return bma400_probe(&client->dev, regmap, client->irq, id->name); 35 28 } 36 29 37 30 static const struct i2c_device_id bma400_i2c_ids[] = { ··· 45 52 .of_match_table = bma400_of_i2c_match, 46 53 }, 47 54 .probe = bma400_i2c_probe, 48 - .remove = bma400_i2c_remove, 49 55 .id_table = bma400_i2c_ids, 50 56 }; 51 57
+1 -7
drivers/iio/accel/bma400_spi.c
··· 84 84 if (ret) 85 85 dev_err(&spi->dev, "Failed to read chip id register\n"); 86 86 87 - return bma400_probe(&spi->dev, regmap, id->name); 88 - } 89 - 90 - static void bma400_spi_remove(struct spi_device *spi) 91 - { 92 - bma400_remove(&spi->dev); 87 + return bma400_probe(&spi->dev, regmap, spi->irq, id->name); 93 88 } 94 89 95 90 static const struct spi_device_id bma400_spi_ids[] = { ··· 105 110 .of_match_table = bma400_of_spi_match, 106 111 }, 107 112 .probe = bma400_spi_probe, 108 - .remove = bma400_spi_remove, 109 113 .id_table = bma400_spi_ids, 110 114 }; 111 115
+78 -21
drivers/iio/accel/bmi088-accel-core.c
··· 6 6 * Copyright (c) 2018-2021, Topic Embedded Products 7 7 */ 8 8 9 + #include <linux/bitfield.h> 9 10 #include <linux/delay.h> 10 11 #include <linux/iio/iio.h> 11 12 #include <linux/iio/sysfs.h> ··· 74 73 #define BMI088_ACCEL_FIFO_MODE_FIFO 0x40 75 74 #define BMI088_ACCEL_FIFO_MODE_STREAM 0x80 76 75 76 + #define BMIO088_ACCEL_ACC_RANGE_MSK GENMASK(1, 0) 77 + 77 78 enum bmi088_accel_axis { 78 79 AXIS_X, 79 80 AXIS_Y, ··· 122 119 u8 chip_id; 123 120 const struct iio_chan_spec *channels; 124 121 int num_channels; 122 + const int scale_table[4][2]; 125 123 }; 126 124 127 125 struct bmi088_accel_data { 128 126 struct regmap *regmap; 129 127 const struct bmi088_accel_chip_info *chip_info; 130 - u8 buffer[2] ____cacheline_aligned; /* shared DMA safe buffer */ 128 + u8 buffer[2] __aligned(IIO_DMA_MINALIGN); /* shared DMA safe buffer */ 131 129 }; 132 130 133 131 static const struct regmap_range bmi088_volatile_ranges[] = { ··· 240 236 BMI088_ACCEL_MODE_ODR_MASK, regval); 241 237 } 242 238 239 + static int bmi088_accel_set_scale(struct bmi088_accel_data *data, int val, int val2) 240 + { 241 + unsigned int i; 242 + 243 + for (i = 0; i < 4; i++) 244 + if (val == data->chip_info->scale_table[i][0] && 245 + val2 == data->chip_info->scale_table[i][1]) 246 + break; 247 + 248 + if (i == 4) 249 + return -EINVAL; 250 + 251 + return regmap_write(data->regmap, BMI088_ACCEL_REG_ACC_RANGE, i); 252 + } 253 + 243 254 static int bmi088_accel_get_temp(struct bmi088_accel_data *data, int *val) 244 255 { 245 256 int ret; ··· 299 280 struct bmi088_accel_data *data = iio_priv(indio_dev); 300 281 struct device *dev = regmap_get_device(data->regmap); 301 282 int ret; 283 + int reg; 302 284 303 285 switch (mask) { 304 286 case IIO_CHAN_INFO_RAW: ··· 350 330 return ret; 351 331 352 332 ret = regmap_read(data->regmap, 353 - BMI088_ACCEL_REG_ACC_RANGE, val); 333 + BMI088_ACCEL_REG_ACC_RANGE, &reg); 354 334 if (ret) 355 335 goto out_read_raw_pm_put; 356 336 357 - *val2 = 15 - (*val & 0x3); 358 - *val = 3 * 980; 359 - ret = IIO_VAL_FRACTIONAL_LOG2; 337 + reg = FIELD_GET(BMIO088_ACCEL_ACC_RANGE_MSK, reg); 338 + *val = data->chip_info->scale_table[reg][0]; 339 + *val2 = data->chip_info->scale_table[reg][1]; 340 + ret = IIO_VAL_INT_PLUS_MICRO; 360 341 361 342 goto out_read_raw_pm_put; 362 343 default: ··· 388 367 const int **vals, int *type, int *length, 389 368 long mask) 390 369 { 370 + struct bmi088_accel_data *data = iio_priv(indio_dev); 371 + 391 372 switch (mask) { 373 + case IIO_CHAN_INFO_SCALE: 374 + *vals = (const int *)data->chip_info->scale_table; 375 + *length = 8; 376 + *type = IIO_VAL_INT_PLUS_MICRO; 377 + return IIO_AVAIL_LIST; 392 378 case IIO_CHAN_INFO_SAMP_FREQ: 393 379 *type = IIO_VAL_INT_PLUS_MICRO; 394 380 *vals = bmi088_sample_freqs; ··· 415 387 int ret; 416 388 417 389 switch (mask) { 390 + case IIO_CHAN_INFO_SCALE: 391 + ret = pm_runtime_resume_and_get(dev); 392 + if (ret) 393 + return ret; 394 + 395 + ret = bmi088_accel_set_scale(data, val, val2); 396 + pm_runtime_mark_last_busy(dev); 397 + pm_runtime_put_autosuspend(dev); 398 + return ret; 418 399 case IIO_CHAN_INFO_SAMP_FREQ: 419 400 ret = pm_runtime_resume_and_get(dev); 420 401 if (ret) ··· 445 408 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 446 409 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 447 410 BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 448 - .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 411 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 412 + BIT(IIO_CHAN_INFO_SCALE), \ 449 413 .scan_index = AXIS_##_axis, \ 450 414 } 451 415 ··· 465 427 }; 466 428 467 429 static const struct bmi088_accel_chip_info bmi088_accel_chip_info_tbl[] = { 468 - [0] = { 469 - .name = "bmi088a", 430 + [BOSCH_BMI085] = { 431 + .name = "bmi085-accel", 432 + .chip_id = 0x1F, 433 + .channels = bmi088_accel_channels, 434 + .num_channels = ARRAY_SIZE(bmi088_accel_channels), 435 + .scale_table = {{0, 598}, {0, 1196}, {0, 2393}, {0, 4785}}, 436 + }, 437 + [BOSCH_BMI088] = { 438 + .name = "bmi088-accel", 470 439 .chip_id = 0x1E, 471 440 .channels = bmi088_accel_channels, 472 441 .num_channels = ARRAY_SIZE(bmi088_accel_channels), 442 + .scale_table = {{0, 897}, {0, 1794}, {0, 3589}, {0, 7178}}, 443 + }, 444 + [BOSCH_BMI090L] = { 445 + .name = "bmi090l-accel", 446 + .chip_id = 0x1A, 447 + .channels = bmi088_accel_channels, 448 + .num_channels = ARRAY_SIZE(bmi088_accel_channels), 449 + .scale_table = {{0, 897}, {0, 1794}, {0, 3589}, {0, 7178}}, 473 450 }, 474 451 }; 475 452 ··· 499 446 0 500 447 }; 501 448 502 - static int bmi088_accel_chip_init(struct bmi088_accel_data *data) 449 + static int bmi088_accel_chip_init(struct bmi088_accel_data *data, enum bmi_device_type type) 503 450 { 504 451 struct device *dev = regmap_get_device(data->regmap); 505 452 int ret, i; 506 453 unsigned int val; 454 + 455 + if (type >= BOSCH_UNKNOWN) 456 + return -ENODEV; 507 457 508 458 /* Do a dummy read to enable SPI interface, won't harm I2C */ 509 459 regmap_read(data->regmap, BMI088_ACCEL_REG_INT_STATUS, &val); ··· 533 477 } 534 478 535 479 /* Validate chip ID */ 536 - for (i = 0; i < ARRAY_SIZE(bmi088_accel_chip_info_tbl); i++) { 537 - if (bmi088_accel_chip_info_tbl[i].chip_id == val) { 538 - data->chip_info = &bmi088_accel_chip_info_tbl[i]; 480 + for (i = 0; i < ARRAY_SIZE(bmi088_accel_chip_info_tbl); i++) 481 + if (bmi088_accel_chip_info_tbl[i].chip_id == val) 539 482 break; 540 - } 541 - } 542 - if (i == ARRAY_SIZE(bmi088_accel_chip_info_tbl)) { 543 - dev_err(dev, "Invalid chip %x\n", val); 544 - return -ENODEV; 545 - } 483 + 484 + if (i == ARRAY_SIZE(bmi088_accel_chip_info_tbl)) 485 + data->chip_info = &bmi088_accel_chip_info_tbl[type]; 486 + else 487 + data->chip_info = &bmi088_accel_chip_info_tbl[i]; 488 + 489 + if (i != type) 490 + dev_warn(dev, "unexpected chip id 0x%X\n", val); 546 491 547 492 return 0; 548 493 } 549 494 550 495 int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, 551 - int irq, const char *name, bool block_supported) 496 + int irq, enum bmi_device_type type) 552 497 { 553 498 struct bmi088_accel_data *data; 554 499 struct iio_dev *indio_dev; ··· 564 507 565 508 data->regmap = regmap; 566 509 567 - ret = bmi088_accel_chip_init(data); 510 + ret = bmi088_accel_chip_init(data, type); 568 511 if (ret) 569 512 return ret; 570 513 571 514 indio_dev->channels = data->chip_info->channels; 572 515 indio_dev->num_channels = data->chip_info->num_channels; 573 - indio_dev->name = name ? name : data->chip_info->name; 516 + indio_dev->name = data->chip_info->name; 574 517 indio_dev->available_scan_masks = bmi088_accel_scan_masks; 575 518 indio_dev->modes = INDIO_DIRECT_MODE; 576 519 indio_dev->info = &bmi088_accel_info;
+14 -3
drivers/iio/accel/bmi088-accel-spi.c
··· 52 52 return PTR_ERR(regmap); 53 53 } 54 54 55 - return bmi088_accel_core_probe(&spi->dev, regmap, spi->irq, id->name, 56 - true); 55 + return bmi088_accel_core_probe(&spi->dev, regmap, spi->irq, 56 + id->driver_data); 57 57 } 58 58 59 59 static void bmi088_accel_remove(struct spi_device *spi) ··· 61 61 bmi088_accel_core_remove(&spi->dev); 62 62 } 63 63 64 + static const struct of_device_id bmi088_of_match[] = { 65 + { .compatible = "bosch,bmi085-accel" }, 66 + { .compatible = "bosch,bmi088-accel" }, 67 + { .compatible = "bosch,bmi090l-accel" }, 68 + {} 69 + }; 70 + MODULE_DEVICE_TABLE(of, bmi088_of_match); 71 + 64 72 static const struct spi_device_id bmi088_accel_id[] = { 65 - {"bmi088-accel", }, 73 + {"bmi085-accel", BOSCH_BMI085}, 74 + {"bmi088-accel", BOSCH_BMI088}, 75 + {"bmi090l-accel", BOSCH_BMI090L}, 66 76 {} 67 77 }; 68 78 MODULE_DEVICE_TABLE(spi, bmi088_accel_id); ··· 81 71 .driver = { 82 72 .name = "bmi088_accel_spi", 83 73 .pm = &bmi088_accel_pm_ops, 74 + .of_match_table = bmi088_of_match, 84 75 }, 85 76 .probe = bmi088_accel_probe, 86 77 .remove = bmi088_accel_remove,
+8 -1
drivers/iio/accel/bmi088-accel.h
··· 8 8 9 9 struct device; 10 10 11 + enum bmi_device_type { 12 + BOSCH_BMI085, 13 + BOSCH_BMI088, 14 + BOSCH_BMI090L, 15 + BOSCH_UNKNOWN, 16 + }; 17 + 11 18 extern const struct regmap_config bmi088_regmap_conf; 12 19 extern const struct dev_pm_ops bmi088_accel_pm_ops; 13 20 14 21 int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, 15 - const char *name, bool block_supported); 22 + enum bmi_device_type type); 16 23 void bmi088_accel_core_remove(struct device *dev); 17 24 18 25 #endif /* BMI088_ACCEL_H */
+1 -1
drivers/iio/accel/cros_ec_accel_legacy.c
··· 230 230 indio_dev->channels = cros_ec_accel_legacy_channels; 231 231 indio_dev->num_channels = ARRAY_SIZE(cros_ec_accel_legacy_channels); 232 232 /* The lid sensor needs to be presented inverted. */ 233 - if (state->loc == MOTIONSENSE_LOC_LID) { 233 + if (!strcmp(indio_dev->label, "accel-display")) { 234 234 state->sign[CROS_EC_SENSOR_X] = -1; 235 235 state->sign[CROS_EC_SENSOR_Z] = -1; 236 236 }
+1 -1
drivers/iio/accel/kxsd9-i2c.c
··· 55 55 .driver = { 56 56 .name = "kxsd9", 57 57 .of_match_table = kxsd9_of_match, 58 - .pm = &kxsd9_dev_pm_ops, 58 + .pm = pm_ptr(&kxsd9_dev_pm_ops), 59 59 }, 60 60 .probe = kxsd9_i2c_probe, 61 61 .remove = kxsd9_i2c_remove,
+1 -1
drivers/iio/accel/kxsd9-spi.c
··· 52 52 static struct spi_driver kxsd9_spi_driver = { 53 53 .driver = { 54 54 .name = "kxsd9", 55 - .pm = &kxsd9_dev_pm_ops, 55 + .pm = pm_ptr(&kxsd9_dev_pm_ops), 56 56 .of_match_table = kxsd9_of_match, 57 57 }, 58 58 .probe = kxsd9_spi_probe,
+2 -9
drivers/iio/accel/kxsd9.c
··· 492 492 } 493 493 EXPORT_SYMBOL_NS(kxsd9_common_remove, IIO_KXSD9); 494 494 495 - #ifdef CONFIG_PM 496 495 static int kxsd9_runtime_suspend(struct device *dev) 497 496 { 498 497 struct iio_dev *indio_dev = dev_get_drvdata(dev); ··· 507 508 508 509 return kxsd9_power_up(st); 509 510 } 510 - #endif /* CONFIG_PM */ 511 511 512 - const struct dev_pm_ops kxsd9_dev_pm_ops = { 513 - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 514 - pm_runtime_force_resume) 515 - SET_RUNTIME_PM_OPS(kxsd9_runtime_suspend, 516 - kxsd9_runtime_resume, NULL) 517 - }; 518 - EXPORT_SYMBOL_NS(kxsd9_dev_pm_ops, IIO_KXSD9); 512 + EXPORT_NS_RUNTIME_DEV_PM_OPS(kxsd9_dev_pm_ops, kxsd9_runtime_suspend, 513 + kxsd9_runtime_resume, NULL, IIO_KXSD9); 519 514 520 515 MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 521 516 MODULE_DESCRIPTION("Kionix KXSD9 driver");
+3 -1
drivers/iio/accel/mc3230.c
··· 157 157 158 158 iio_device_unregister(indio_dev); 159 159 160 - return mc3230_set_opcon(iio_priv(indio_dev), MC3230_MODE_OPCON_STANDBY); 160 + mc3230_set_opcon(iio_priv(indio_dev), MC3230_MODE_OPCON_STANDBY); 161 + 162 + return 0; 161 163 } 162 164 163 165 static int mc3230_suspend(struct device *dev)
+3 -3
drivers/iio/accel/mma7660.c
··· 7 7 * IIO driver for Freescale MMA7660FC; 7-bit I2C address: 0x4c. 8 8 */ 9 9 10 - #include <linux/acpi.h> 11 10 #include <linux/i2c.h> 11 + #include <linux/mod_devicetable.h> 12 12 #include <linux/module.h> 13 13 #include <linux/iio/iio.h> 14 14 #include <linux/iio/sysfs.h> ··· 255 255 }; 256 256 MODULE_DEVICE_TABLE(of, mma7660_of_match); 257 257 258 - static const struct acpi_device_id __maybe_unused mma7660_acpi_id[] = { 258 + static const struct acpi_device_id mma7660_acpi_id[] = { 259 259 {"MMA7660", 0}, 260 260 {} 261 261 }; ··· 267 267 .name = "mma7660", 268 268 .pm = pm_sleep_ptr(&mma7660_pm_ops), 269 269 .of_match_table = mma7660_of_match, 270 - .acpi_match_table = ACPI_PTR(mma7660_acpi_id), 270 + .acpi_match_table = mma7660_acpi_id, 271 271 }, 272 272 .probe = mma7660_probe, 273 273 .remove = mma7660_remove,
+3 -3
drivers/iio/accel/sca3000.c
··· 167 167 int mo_det_use_count; 168 168 struct mutex lock; 169 169 /* Can these share a cacheline ? */ 170 - u8 rx[384] ____cacheline_aligned; 171 - u8 tx[6] ____cacheline_aligned; 170 + u8 rx[384] __aligned(IIO_DMA_MINALIGN); 171 + u8 tx[6] __aligned(IIO_DMA_MINALIGN); 172 172 }; 173 173 174 174 /** ··· 424 424 * sca3000_print_rev() - sysfs interface to read the chip revision number 425 425 * @indio_dev: Device instance specific generic IIO data. 426 426 * Driver specific device instance data can be obtained via 427 - * via iio_priv(indio_dev) 427 + * iio_priv(indio_dev) 428 428 */ 429 429 static int sca3000_print_rev(struct iio_dev *indio_dev) 430 430 {
+269 -56
drivers/iio/accel/sca3300.c
··· 38 38 /* Device ID */ 39 39 #define SCA3300_REG_WHOAMI 0x10 40 40 #define SCA3300_WHOAMI_ID 0x51 41 + #define SCL3300_WHOAMI_ID 0xC1 41 42 42 43 /* Device return status and mask */ 43 44 #define SCA3300_VALUE_RS_ERROR 0x3 44 45 #define SCA3300_MASK_RS_STATUS GENMASK(1, 0) 46 + 47 + #define SCL3300_REG_ANG_CTRL 0x0C 48 + #define SCL3300_ANG_ENABLE 0x1F 45 49 46 50 enum sca3300_scan_indexes { 47 51 SCA3300_ACC_X = 0, ··· 53 49 SCA3300_ACC_Z, 54 50 SCA3300_TEMP, 55 51 SCA3300_TIMESTAMP, 52 + SCA3300_INCLI_X, 53 + SCA3300_INCLI_Y, 54 + SCA3300_INCLI_Z, 56 55 }; 57 56 58 57 #define SCA3300_ACCEL_CHANNEL(index, reg, axis) { \ ··· 79 72 }, \ 80 73 } 81 74 75 + #define SCA3300_INCLI_CHANNEL(index, reg, axis) { \ 76 + .type = IIO_INCLI, \ 77 + .address = reg, \ 78 + .modified = 1, \ 79 + .channel2 = IIO_MOD_##axis, \ 80 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 81 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 82 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), \ 83 + .scan_index = index, \ 84 + .scan_type = { \ 85 + .sign = 's', \ 86 + .realbits = 16, \ 87 + .storagebits = 16, \ 88 + .endianness = IIO_CPU, \ 89 + }, \ 90 + } 91 + 92 + #define SCA3300_TEMP_CHANNEL(index, reg) { \ 93 + .type = IIO_TEMP, \ 94 + .address = reg, \ 95 + .scan_index = index, \ 96 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 97 + .scan_type = { \ 98 + .sign = 's', \ 99 + .realbits = 16, \ 100 + .storagebits = 16, \ 101 + .endianness = IIO_CPU, \ 102 + }, \ 103 + } 104 + 82 105 static const struct iio_chan_spec sca3300_channels[] = { 83 106 SCA3300_ACCEL_CHANNEL(SCA3300_ACC_X, 0x1, X), 84 107 SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Y, 0x2, Y), 85 108 SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Z, 0x3, Z), 86 - { 87 - .type = IIO_TEMP, 88 - .address = 0x5, 89 - .scan_index = SCA3300_TEMP, 90 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 91 - .scan_type = { 92 - .sign = 's', 93 - .realbits = 16, 94 - .storagebits = 16, 95 - .endianness = IIO_CPU, 96 - }, 97 - }, 109 + SCA3300_TEMP_CHANNEL(SCA3300_TEMP, 0x05), 98 110 IIO_CHAN_SOFT_TIMESTAMP(4), 99 111 }; 100 112 101 - static const int sca3300_lp_freq[] = {70, 70, 70, 10}; 102 - static const int sca3300_accel_scale[][2] = {{0, 370}, {0, 741}, {0, 185}, {0, 185}}; 113 + static const int sca3300_lp_freq[] = {70, 10}; 114 + static const int sca3300_lp_freq_map[] = {0, 0, 0, 1}; 115 + 116 + static const int scl3300_lp_freq[] = {40, 70, 10}; 117 + static const int scl3300_lp_freq_map[] = {0, 1, 2}; 118 + 119 + static const int sca3300_accel_scale[][2] = {{0, 370}, {0, 741}, {0, 185}}; 120 + static const int sca3300_accel_scale_map[] = {0, 1, 2, 2}; 121 + 122 + static const int scl3300_accel_scale[][2] = {{0, 167}, {0, 333}, {0, 83}}; 123 + static const int scl3300_accel_scale_map[] = {0, 1, 2}; 124 + 125 + static const int scl3300_incli_scale[][2] = {{0, 5495}}; 126 + static const int scl3300_incli_scale_map[] = {0, 0, 0}; 127 + 128 + static const int sca3300_avail_modes_map[] = {0, 1, 2, 3}; 129 + static const int scl3300_avail_modes_map[] = {0, 1, 3}; 130 + 131 + static const struct iio_chan_spec scl3300_channels[] = { 132 + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_X, 0x1, X), 133 + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Y, 0x2, Y), 134 + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Z, 0x3, Z), 135 + SCA3300_TEMP_CHANNEL(SCA3300_TEMP, 0x05), 136 + IIO_CHAN_SOFT_TIMESTAMP(4), 137 + SCA3300_INCLI_CHANNEL(SCA3300_INCLI_X, 0x09, X), 138 + SCA3300_INCLI_CHANNEL(SCA3300_INCLI_Y, 0x0A, Y), 139 + SCA3300_INCLI_CHANNEL(SCA3300_INCLI_Z, 0x0B, Z), 140 + }; 103 141 104 142 static const unsigned long sca3300_scan_masks[] = { 105 143 BIT(SCA3300_ACC_X) | BIT(SCA3300_ACC_Y) | BIT(SCA3300_ACC_Z) | ··· 152 100 0 153 101 }; 154 102 103 + static const unsigned long scl3300_scan_masks[] = { 104 + BIT(SCA3300_ACC_X) | BIT(SCA3300_ACC_Y) | BIT(SCA3300_ACC_Z) | 105 + BIT(SCA3300_TEMP) | 106 + BIT(SCA3300_INCLI_X) | BIT(SCA3300_INCLI_Y) | BIT(SCA3300_INCLI_Z), 107 + 0 108 + }; 109 + 110 + struct sca3300_chip_info { 111 + const char *name; 112 + const unsigned long *scan_masks; 113 + const struct iio_chan_spec *channels; 114 + u8 num_channels; 115 + u8 num_accel_scales; 116 + const int (*accel_scale)[2]; 117 + const int *accel_scale_map; 118 + const int (*incli_scale)[2]; 119 + const int *incli_scale_map; 120 + u8 num_incli_scales; 121 + u8 num_freqs; 122 + const int *freq_table; 123 + const int *freq_map; 124 + const int *avail_modes_table; 125 + u8 num_avail_modes; 126 + u8 chip_id; 127 + bool angle_supported; 128 + }; 129 + 155 130 /** 156 131 * struct sca3300_data - device data 157 132 * @spi: SPI device structure 158 133 * @lock: Data buffer lock 134 + * @chip: Sensor chip specific information 159 135 * @scan: Triggered buffer. Four channel 16-bit data + 64-bit timestamp 160 136 * @txbuf: Transmit buffer 161 137 * @rxbuf: Receive buffer ··· 191 111 struct sca3300_data { 192 112 struct spi_device *spi; 193 113 struct mutex lock; 114 + const struct sca3300_chip_info *chip; 194 115 struct { 195 116 s16 channels[4]; 196 117 s64 ts __aligned(sizeof(s64)); 197 118 } scan; 198 - u8 txbuf[4] ____cacheline_aligned; 119 + u8 txbuf[4] __aligned(IIO_DMA_MINALIGN); 199 120 u8 rxbuf[4]; 121 + }; 122 + 123 + static const struct sca3300_chip_info sca3300_chip_tbl[] = { 124 + { 125 + .name = "sca3300", 126 + .scan_masks = sca3300_scan_masks, 127 + .channels = sca3300_channels, 128 + .num_channels = ARRAY_SIZE(sca3300_channels), 129 + .num_accel_scales = ARRAY_SIZE(sca3300_accel_scale)*2, 130 + .accel_scale = sca3300_accel_scale, 131 + .accel_scale_map = sca3300_accel_scale_map, 132 + .num_freqs = ARRAY_SIZE(sca3300_lp_freq), 133 + .freq_table = sca3300_lp_freq, 134 + .freq_map = sca3300_lp_freq_map, 135 + .avail_modes_table = sca3300_avail_modes_map, 136 + .num_avail_modes = 4, 137 + .chip_id = SCA3300_WHOAMI_ID, 138 + .angle_supported = false, 139 + }, 140 + { 141 + .name = "scl3300", 142 + .scan_masks = scl3300_scan_masks, 143 + .channels = scl3300_channels, 144 + .num_channels = ARRAY_SIZE(scl3300_channels), 145 + .num_accel_scales = ARRAY_SIZE(scl3300_accel_scale)*2, 146 + .accel_scale = scl3300_accel_scale, 147 + .accel_scale_map = scl3300_accel_scale_map, 148 + .incli_scale = scl3300_incli_scale, 149 + .incli_scale_map = scl3300_incli_scale_map, 150 + .num_incli_scales = ARRAY_SIZE(scl3300_incli_scale)*2, 151 + .num_freqs = ARRAY_SIZE(scl3300_lp_freq), 152 + .freq_table = scl3300_lp_freq, 153 + .freq_map = scl3300_lp_freq_map, 154 + .avail_modes_table = scl3300_avail_modes_map, 155 + .num_avail_modes = 3, 156 + .chip_id = SCL3300_WHOAMI_ID, 157 + .angle_supported = true, 158 + }, 200 159 }; 201 160 202 161 DECLARE_CRC8_TABLE(sca3300_crc_table); ··· 344 225 return sca3300_error_handler(sca_data); 345 226 } 346 227 228 + static int sca3300_set_op_mode(struct sca3300_data *sca_data, int index) 229 + { 230 + if ((index < 0) || (index >= sca_data->chip->num_avail_modes)) 231 + return -EINVAL; 232 + 233 + return sca3300_write_reg(sca_data, SCA3300_REG_MODE, 234 + sca_data->chip->avail_modes_table[index]); 235 + } 236 + 237 + static int sca3300_get_op_mode(struct sca3300_data *sca_data, int *index) 238 + { 239 + int reg_val; 240 + int ret; 241 + int i; 242 + 243 + ret = sca3300_read_reg(sca_data, SCA3300_REG_MODE, &reg_val); 244 + if (ret) 245 + return ret; 246 + 247 + for (i = 0; i < sca_data->chip->num_avail_modes; i++) { 248 + if (sca_data->chip->avail_modes_table[i] == reg_val) 249 + break; 250 + } 251 + if (i == sca_data->chip->num_avail_modes) 252 + return -EINVAL; 253 + 254 + *index = i; 255 + return 0; 256 + } 257 + 258 + static int sca3300_set_frequency(struct sca3300_data *data, int val) 259 + { 260 + const struct sca3300_chip_info *chip = data->chip; 261 + unsigned int index; 262 + int *opmode_scale; 263 + int *new_scale; 264 + unsigned int i; 265 + 266 + if (sca3300_get_op_mode(data, &index)) 267 + return -EINVAL; 268 + 269 + /* 270 + * Find a mode in which the requested sampling frequency is available 271 + * and the scaling currently set is retained. 272 + */ 273 + opmode_scale = (int *)chip->accel_scale[chip->accel_scale_map[index]]; 274 + for (i = 0; i < chip->num_avail_modes; i++) { 275 + new_scale = (int *)chip->accel_scale[chip->accel_scale_map[i]]; 276 + if ((val == chip->freq_table[chip->freq_map[i]]) && 277 + (opmode_scale[1] == new_scale[1]) && 278 + (opmode_scale[0] == new_scale[0])) 279 + break; 280 + } 281 + if (i == chip->num_avail_modes) 282 + return -EINVAL; 283 + 284 + return sca3300_set_op_mode(data, i); 285 + } 286 + 347 287 static int sca3300_write_raw(struct iio_dev *indio_dev, 348 288 struct iio_chan_spec const *chan, 349 289 int val, int val2, long mask) 350 290 { 351 291 struct sca3300_data *data = iio_priv(indio_dev); 352 - int reg_val; 353 - int ret; 292 + int index; 354 293 int i; 355 294 356 295 switch (mask) { 357 296 case IIO_CHAN_INFO_SCALE: 358 - if (val) 297 + if (chan->type != IIO_ACCEL) 359 298 return -EINVAL; 360 - 361 - for (i = 0; i < ARRAY_SIZE(sca3300_accel_scale); i++) { 362 - if (val2 == sca3300_accel_scale[i][1]) 363 - return sca3300_write_reg(data, SCA3300_REG_MODE, i); 299 + /* 300 + * Letting scale take priority over sampling frequency. 301 + * That makes sense given we can only ever end up increasing 302 + * the sampling frequency which is unlikely to be a problem. 303 + */ 304 + for (i = 0; i < data->chip->num_avail_modes; i++) { 305 + index = data->chip->accel_scale_map[i]; 306 + if ((val == data->chip->accel_scale[index][0]) && 307 + (val2 == data->chip->accel_scale[index][1])) 308 + return sca3300_set_op_mode(data, i); 364 309 } 365 310 return -EINVAL; 366 - 367 311 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 368 - ret = sca3300_read_reg(data, SCA3300_REG_MODE, &reg_val); 369 - if (ret) 370 - return ret; 371 - /* freq. change is possible only for mode 3 and 4 */ 372 - if (reg_val == 2 && val == sca3300_lp_freq[3]) 373 - return sca3300_write_reg(data, SCA3300_REG_MODE, 3); 374 - if (reg_val == 3 && val == sca3300_lp_freq[2]) 375 - return sca3300_write_reg(data, SCA3300_REG_MODE, 2); 376 - return -EINVAL; 312 + return sca3300_set_frequency(data, val); 377 313 default: 378 314 return -EINVAL; 379 315 } ··· 439 265 int *val, int *val2, long mask) 440 266 { 441 267 struct sca3300_data *data = iio_priv(indio_dev); 268 + int index; 442 269 int ret; 443 - int reg_val; 444 270 445 271 switch (mask) { 446 272 case IIO_CHAN_INFO_RAW: ··· 449 275 return ret; 450 276 return IIO_VAL_INT; 451 277 case IIO_CHAN_INFO_SCALE: 452 - ret = sca3300_read_reg(data, SCA3300_REG_MODE, &reg_val); 278 + ret = sca3300_get_op_mode(data, &index); 453 279 if (ret) 454 280 return ret; 455 - *val = 0; 456 - *val2 = sca3300_accel_scale[reg_val][1]; 457 - return IIO_VAL_INT_PLUS_MICRO; 281 + switch (chan->type) { 282 + case IIO_INCLI: 283 + index = data->chip->incli_scale_map[index]; 284 + *val = data->chip->incli_scale[index][0]; 285 + *val2 = data->chip->incli_scale[index][1]; 286 + return IIO_VAL_INT_PLUS_MICRO; 287 + case IIO_ACCEL: 288 + index = data->chip->accel_scale_map[index]; 289 + *val = data->chip->accel_scale[index][0]; 290 + *val2 = data->chip->accel_scale[index][1]; 291 + return IIO_VAL_INT_PLUS_MICRO; 292 + default: 293 + return -EINVAL; 294 + } 458 295 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 459 - ret = sca3300_read_reg(data, SCA3300_REG_MODE, &reg_val); 296 + ret = sca3300_get_op_mode(data, &index); 460 297 if (ret) 461 298 return ret; 462 - *val = sca3300_lp_freq[reg_val]; 299 + index = data->chip->freq_map[index]; 300 + *val = data->chip->freq_table[index]; 463 301 return IIO_VAL_INT; 464 302 default: 465 303 return -EINVAL; ··· 515 329 { 516 330 int value = 0; 517 331 int ret; 332 + int i; 518 333 519 334 ret = sca3300_write_reg(sca_data, SCA3300_REG_MODE, 520 335 SCA3300_MODE_SW_RESET); ··· 524 337 525 338 /* 526 339 * Wait 1ms after SW-reset command. 527 - * Wait 15ms for settling of signal paths. 340 + * Wait for the settling of signal paths, 341 + * 15ms for SCA3300 and 25ms for SCL3300, 528 342 */ 529 - usleep_range(16e3, 50e3); 343 + usleep_range(26e3, 50e3); 530 344 531 345 ret = sca3300_read_reg(sca_data, SCA3300_REG_WHOAMI, &value); 532 346 if (ret) 533 347 return ret; 534 348 535 - if (value != SCA3300_WHOAMI_ID) { 536 - dev_err(&sca_data->spi->dev, 537 - "device id not expected value, %d != %u\n", 538 - value, SCA3300_WHOAMI_ID); 349 + for (i = 0; i < ARRAY_SIZE(sca3300_chip_tbl); i++) { 350 + if (sca3300_chip_tbl[i].chip_id == value) 351 + break; 352 + } 353 + if (i == ARRAY_SIZE(sca3300_chip_tbl)) { 354 + dev_err(&sca_data->spi->dev, "unknown chip id %x\n", value); 539 355 return -ENODEV; 540 356 } 357 + 358 + sca_data->chip = &sca3300_chip_tbl[i]; 359 + 360 + if (sca_data->chip->angle_supported) { 361 + ret = sca3300_write_reg(sca_data, SCL3300_REG_ANG_CTRL, 362 + SCL3300_ANG_ENABLE); 363 + if (ret) 364 + return ret; 365 + } 366 + 541 367 return 0; 542 368 } 543 369 ··· 582 382 const int **vals, int *type, int *length, 583 383 long mask) 584 384 { 385 + struct sca3300_data *data = iio_priv(indio_dev); 585 386 switch (mask) { 586 387 case IIO_CHAN_INFO_SCALE: 587 - *vals = (const int *)sca3300_accel_scale; 588 - *length = ARRAY_SIZE(sca3300_accel_scale) * 2 - 2; 589 - *type = IIO_VAL_INT_PLUS_MICRO; 590 - return IIO_AVAIL_LIST; 388 + switch (chan->type) { 389 + case IIO_INCLI: 390 + *vals = (const int *)data->chip->incli_scale; 391 + *length = data->chip->num_incli_scales; 392 + *type = IIO_VAL_INT_PLUS_MICRO; 393 + return IIO_AVAIL_LIST; 394 + case IIO_ACCEL: 395 + *vals = (const int *)data->chip->accel_scale; 396 + *length = data->chip->num_accel_scales; 397 + *type = IIO_VAL_INT_PLUS_MICRO; 398 + return IIO_AVAIL_LIST; 399 + default: 400 + return -EINVAL; 401 + } 591 402 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 592 - *vals = &sca3300_lp_freq[2]; 593 - *length = 2; 403 + *vals = (const int *)data->chip->freq_table; 404 + *length = data->chip->num_freqs; 594 405 *type = IIO_VAL_INT; 595 406 return IIO_AVAIL_LIST; 596 407 default: ··· 633 422 crc8_populate_msb(sca3300_crc_table, SCA3300_CRC8_POLYNOMIAL); 634 423 635 424 indio_dev->info = &sca3300_info; 636 - indio_dev->name = SCA3300_ALIAS; 637 - indio_dev->modes = INDIO_DIRECT_MODE; 638 - indio_dev->channels = sca3300_channels; 639 - indio_dev->num_channels = ARRAY_SIZE(sca3300_channels); 640 - indio_dev->available_scan_masks = sca3300_scan_masks; 641 425 642 426 ret = sca3300_init(sca_data, indio_dev); 643 427 if (ret) { 644 428 dev_err(&spi->dev, "failed to init device, error: %d\n", ret); 645 429 return ret; 646 430 } 431 + 432 + indio_dev->name = sca_data->chip->name; 433 + indio_dev->modes = INDIO_DIRECT_MODE; 434 + indio_dev->channels = sca_data->chip->channels; 435 + indio_dev->num_channels = sca_data->chip->num_channels; 436 + indio_dev->available_scan_masks = sca_data->chip->scan_masks; 647 437 648 438 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, 649 439 iio_pollfunc_store_time, ··· 666 454 667 455 static const struct of_device_id sca3300_dt_ids[] = { 668 456 { .compatible = "murata,sca3300"}, 457 + { .compatible = "murata,scl3300"}, 669 458 {} 670 459 }; 671 460 MODULE_DEVICE_TABLE(of, sca3300_dt_ids);
+3 -1
drivers/iio/accel/stk8312.c
··· 608 608 if (data->dready_trig) 609 609 iio_trigger_unregister(data->dready_trig); 610 610 611 - return stk8312_set_mode(data, STK8312_MODE_STANDBY); 611 + stk8312_set_mode(data, STK8312_MODE_STANDBY); 612 + 613 + return 0; 612 614 } 613 615 614 616 static int stk8312_suspend(struct device *dev)
+3 -1
drivers/iio/accel/stk8ba50.c
··· 501 501 if (data->dready_trig) 502 502 iio_trigger_unregister(data->dready_trig); 503 503 504 - return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 504 + stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 505 + 506 + return 0; 505 507 } 506 508 507 509 static int stk8ba50_suspend(struct device *dev)
+13 -4
drivers/iio/adc/Kconfig
··· 417 417 418 418 config ENVELOPE_DETECTOR 419 419 tristate "Envelope detector using a DAC and a comparator" 420 - depends on OF 421 420 help 422 421 Say yes here to build support for an envelope detector using a DAC 423 422 and a comparator. ··· 562 563 config LPC18XX_ADC 563 564 tristate "NXP LPC18xx ADC driver" 564 565 depends on ARCH_LPC18XX || COMPILE_TEST 565 - depends on OF && HAS_IOMEM 566 + depends on HAS_IOMEM 566 567 help 567 568 Say yes here to build support for NXP LPC18XX ADC. 568 569 ··· 822 823 To compile this driver as a module, choose M here: the module 823 824 will be called qcom-pm8xxx-xoadc. 824 825 826 + config QCOM_SPMI_RRADC 827 + tristate "Qualcomm SPMI RRADC" 828 + depends on MFD_SPMI_PMIC 829 + help 830 + This is for the PMIC Round Robin ADC driver. 831 + 832 + This driver exposes the battery ID resistor, battery thermal, PMIC die 833 + temperature, charger USB in and DC in voltage and current. 834 + 835 + To compile this driver as a module, choose M here: the module will 836 + be called qcom-qpmi-rradc. 837 + 825 838 config QCOM_SPMI_IADC 826 839 tristate "Qualcomm SPMI PMIC current ADC" 827 840 depends on SPMI ··· 952 941 953 942 config SD_ADC_MODULATOR 954 943 tristate "Generic sigma delta modulator" 955 - depends on OF 956 944 select IIO_BUFFER 957 945 select IIO_TRIGGERED_BUFFER 958 946 help ··· 1269 1259 1270 1260 config VF610_ADC 1271 1261 tristate "Freescale vf610 ADC driver" 1272 - depends on OF 1273 1262 depends on HAS_IOMEM 1274 1263 select IIO_BUFFER 1275 1264 select IIO_TRIGGERED_BUFFER
+1
drivers/iio/adc/Makefile
··· 78 78 obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o 79 79 obj-$(CONFIG_QCOM_SPMI_ADC5) += qcom-spmi-adc5.o 80 80 obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o 81 + obj-$(CONFIG_QCOM_SPMI_RRADC) += qcom-spmi-rradc.o 81 82 obj-$(CONFIG_QCOM_VADC_COMMON) += qcom-vadc-common.o 82 83 obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o 83 84 obj-$(CONFIG_QCOM_PM8XXX_XOADC) += qcom-pm8xxx-xoadc.o
+2 -2
drivers/iio/adc/ad7266.c
··· 37 37 struct gpio_desc *gpios[3]; 38 38 39 39 /* 40 - * DMA (thus cache coherency maintenance) requires the 40 + * DMA (thus cache coherency maintenance) may require the 41 41 * transfer buffers to live in their own cache lines. 42 42 * The buffer needs to be large enough to hold two samples (4 bytes) and 43 43 * the naturally aligned timestamp (8 bytes). ··· 45 45 struct { 46 46 __be16 sample[2]; 47 47 s64 timestamp; 48 - } data ____cacheline_aligned; 48 + } data __aligned(IIO_DMA_MINALIGN); 49 49 }; 50 50 51 51 static int ad7266_wakeup(struct ad7266_state *st)
+1 -1
drivers/iio/adc/ad7280a.c
··· 183 183 unsigned char cb_mask[AD7280A_MAX_CHAIN]; 184 184 struct mutex lock; /* protect sensor state */ 185 185 186 - __be32 tx ____cacheline_aligned; 186 + __be32 tx __aligned(IIO_DMA_MINALIGN); 187 187 __be32 rx; 188 188 }; 189 189
+1 -1
drivers/iio/adc/ad7292.c
··· 80 80 struct regulator *reg; 81 81 unsigned short vref_mv; 82 82 83 - __be16 d16 ____cacheline_aligned; 83 + __be16 d16 __aligned(IIO_DMA_MINALIGN); 84 84 u8 d8[2]; 85 85 }; 86 86
+1 -1
drivers/iio/adc/ad7298.c
··· 49 49 * DMA (thus cache coherency maintenance) requires the 50 50 * transfer buffers to live in their own cache lines. 51 51 */ 52 - __be16 rx_buf[12] ____cacheline_aligned; 52 + __be16 rx_buf[12] __aligned(IIO_DMA_MINALIGN); 53 53 __be16 tx_buf[2]; 54 54 }; 55 55
+2 -3
drivers/iio/adc/ad7476.c
··· 44 44 struct spi_transfer xfer; 45 45 struct spi_message msg; 46 46 /* 47 - * DMA (thus cache coherency maintenance) requires the 47 + * DMA (thus cache coherency maintenance) may require the 48 48 * transfer buffers to live in their own cache lines. 49 49 * Make the buffer large enough for one 16 bit sample and one 64 bit 50 50 * aligned 64 bit timestamp. 51 51 */ 52 - unsigned char data[ALIGN(2, sizeof(s64)) + sizeof(s64)] 53 - ____cacheline_aligned; 52 + unsigned char data[ALIGN(2, sizeof(s64)) + sizeof(s64)] __aligned(IIO_DMA_MINALIGN); 54 53 }; 55 54 56 55 enum ad7476_supported_device_ids {
+1
drivers/iio/adc/ad7606.c
··· 12 12 #include <linux/interrupt.h> 13 13 #include <linux/kernel.h> 14 14 #include <linux/module.h> 15 + #include <linux/property.h> 15 16 #include <linux/regulator/consumer.h> 16 17 #include <linux/sched.h> 17 18 #include <linux/slab.h>
+2 -2
drivers/iio/adc/ad7606.h
··· 116 116 struct completion completion; 117 117 118 118 /* 119 - * DMA (thus cache coherency maintenance) requires the 119 + * DMA (thus cache coherency maintenance) may require the 120 120 * transfer buffers to live in their own cache lines. 121 121 * 16 * 16-bit samples + 64-bit timestamp 122 122 */ 123 - unsigned short data[20] ____cacheline_aligned; 123 + unsigned short data[20] __aligned(IIO_DMA_MINALIGN); 124 124 __be16 d16[2]; 125 125 }; 126 126
+1
drivers/iio/adc/ad7606_par.c
··· 5 5 * Copyright 2011 Analog Devices Inc. 6 6 */ 7 7 8 + #include <linux/mod_devicetable.h> 8 9 #include <linux/module.h> 9 10 #include <linux/platform_device.h> 10 11 #include <linux/types.h>
+2 -3
drivers/iio/adc/ad7766.c
··· 45 45 struct spi_message msg; 46 46 47 47 /* 48 - * DMA (thus cache coherency maintenance) requires the 48 + * DMA (thus cache coherency maintenance) may require the 49 49 * transfer buffers to live in their own cache lines. 50 50 * Make the buffer large enough for one 24 bit sample and one 64 bit 51 51 * aligned 64 bit timestamp. 52 52 */ 53 - unsigned char data[ALIGN(3, sizeof(s64)) + sizeof(s64)] 54 - ____cacheline_aligned; 53 + unsigned char data[ALIGN(3, sizeof(s64)) + sizeof(s64)] __aligned(IIO_DMA_MINALIGN); 55 54 }; 56 55 57 56 /*
+3 -3
drivers/iio/adc/ad7768-1.c
··· 163 163 struct gpio_desc *gpio_sync_in; 164 164 const char *labels[ARRAY_SIZE(ad7768_channels)]; 165 165 /* 166 - * DMA (thus cache coherency maintenance) requires the 166 + * DMA (thus cache coherency maintenance) may require the 167 167 * transfer buffers to live in their own cache lines. 168 168 */ 169 169 union { ··· 173 173 } scan; 174 174 __be32 d32; 175 175 u8 d8[2]; 176 - } data ____cacheline_aligned; 176 + } data __aligned(IIO_DMA_MINALIGN); 177 177 }; 178 178 179 179 static int ad7768_spi_reg_read(struct ad7768_state *st, unsigned int addr, ··· 620 620 indio_dev->num_channels = ARRAY_SIZE(ad7768_channels); 621 621 indio_dev->name = spi_get_device_id(spi)->name; 622 622 indio_dev->info = &ad7768_info; 623 - indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED; 623 + indio_dev->modes = INDIO_DIRECT_MODE; 624 624 625 625 ret = ad7768_setup(st); 626 626 if (ret < 0) {
+2 -3
drivers/iio/adc/ad7887.c
··· 66 66 unsigned char tx_cmd_buf[4]; 67 67 68 68 /* 69 - * DMA (thus cache coherency maintenance) requires the 69 + * DMA (thus cache coherency maintenance) may require the 70 70 * transfer buffers to live in their own cache lines. 71 71 * Buffer needs to be large enough to hold two 16 bit samples and a 72 72 * 64 bit aligned 64 bit timestamp. 73 73 */ 74 - unsigned char data[ALIGN(4, sizeof(s64)) + sizeof(s64)] 75 - ____cacheline_aligned; 74 + unsigned char data[ALIGN(4, sizeof(s64)) + sizeof(s64)] __aligned(IIO_DMA_MINALIGN); 76 75 }; 77 76 78 77 enum ad7887_supported_device_ids {
+2 -2
drivers/iio/adc/ad7923.c
··· 57 57 unsigned int settings; 58 58 59 59 /* 60 - * DMA (thus cache coherency maintenance) requires the 60 + * DMA (thus cache coherency maintenance) may require the 61 61 * transfer buffers to live in their own cache lines. 62 62 * Ensure rx_buf can be directly used in iio_push_to_buffers_with_timetamp 63 63 * Length = 8 channels + 4 extra for 8 byte timestamp 64 64 */ 65 - __be16 rx_buf[12] ____cacheline_aligned; 65 + __be16 rx_buf[12] __aligned(IIO_DMA_MINALIGN); 66 66 __be16 tx_buf[4]; 67 67 }; 68 68
+1 -1
drivers/iio/adc/ad7949.c
··· 86 86 u8 resolution; 87 87 u16 cfg; 88 88 unsigned int current_channel; 89 - u16 buffer ____cacheline_aligned; 89 + u16 buffer __aligned(IIO_DMA_MINALIGN); 90 90 __be16 buf8b; 91 91 }; 92 92
+1
drivers/iio/adc/ad9467.c
··· 474 474 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); 475 475 MODULE_DESCRIPTION("Analog Devices AD9467 ADC driver"); 476 476 MODULE_LICENSE("GPL v2"); 477 + MODULE_IMPORT_NS(IIO_ADI_AXI);
+6 -5
drivers/iio/adc/adi-axi-adc.c
··· 84 84 { 85 85 struct adi_axi_adc_client *cl = conv_to_client(conv); 86 86 87 - return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN); 87 + return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client), 88 + IIO_DMA_MINALIGN); 88 89 } 89 - EXPORT_SYMBOL_GPL(adi_axi_adc_conv_priv); 90 + EXPORT_SYMBOL_NS_GPL(adi_axi_adc_conv_priv, IIO_ADI_AXI); 90 91 91 92 static void adi_axi_adc_write(struct adi_axi_adc_state *st, 92 93 unsigned int reg, ··· 170 169 struct adi_axi_adc_client *cl; 171 170 size_t alloc_size; 172 171 173 - alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN); 172 + alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_DMA_MINALIGN); 174 173 if (sizeof_priv) 175 - alloc_size += ALIGN(sizeof_priv, IIO_ALIGN); 174 + alloc_size += ALIGN(sizeof_priv, IIO_DMA_MINALIGN); 176 175 177 176 cl = kzalloc(alloc_size, GFP_KERNEL); 178 177 if (!cl) ··· 225 224 226 225 return conv; 227 226 } 228 - EXPORT_SYMBOL_GPL(devm_adi_axi_adc_conv_register); 227 + EXPORT_SYMBOL_NS_GPL(devm_adi_axi_adc_conv_register, IIO_ADI_AXI); 229 228 230 229 static ssize_t in_voltage_scale_available_show(struct device *dev, 231 230 struct device_attribute *attr,
+1 -1
drivers/iio/adc/at91-sama5d2_adc.c
··· 1752 1752 int ret; 1753 1753 1754 1754 if (val > AT91_HWFIFO_MAX_SIZE) 1755 - return -EINVAL; 1755 + val = AT91_HWFIFO_MAX_SIZE; 1756 1756 1757 1757 if (!st->selected_trig->hw_trig) { 1758 1758 dev_dbg(&indio_dev->dev, "we need hw trigger for DMA\n");
+2
drivers/iio/adc/berlin2-adc.c
··· 15 15 #include <linux/iio/machine.h> 16 16 #include <linux/interrupt.h> 17 17 #include <linux/kernel.h> 18 + #include <linux/mod_devicetable.h> 18 19 #include <linux/module.h> 20 + #include <linux/of.h> 19 21 #include <linux/platform_device.h> 20 22 #include <linux/slab.h> 21 23 #include <linux/mfd/syscon.h>
+1 -1
drivers/iio/adc/hi8435.c
··· 49 49 50 50 unsigned threshold_lo[2]; /* GND-Open and Supply-Open thresholds */ 51 51 unsigned threshold_hi[2]; /* GND-Open and Supply-Open thresholds */ 52 - u8 reg_buffer[3] ____cacheline_aligned; 52 + u8 reg_buffer[3] __aligned(IIO_DMA_MINALIGN); 53 53 }; 54 54 55 55 static int hi8435_readb(struct hi8435_priv *priv, u8 reg, u8 *val)
+1
drivers/iio/adc/imx7d_adc.c
··· 11 11 #include <linux/interrupt.h> 12 12 #include <linux/io.h> 13 13 #include <linux/kernel.h> 14 + #include <linux/mod_devicetable.h> 14 15 #include <linux/module.h> 15 16 #include <linux/platform_device.h> 16 17 #include <linux/regulator/consumer.h>
+1
drivers/iio/adc/imx8qxp-adc.c
··· 19 19 #include <linux/interrupt.h> 20 20 #include <linux/io.h> 21 21 #include <linux/kernel.h> 22 + #include <linux/mod_devicetable.h> 22 23 #include <linux/module.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/pm_runtime.h>
+8 -2
drivers/iio/adc/ina2xx-adc.c
··· 1038 1038 { 1039 1039 struct iio_dev *indio_dev = i2c_get_clientdata(client); 1040 1040 struct ina2xx_chip_info *chip = iio_priv(indio_dev); 1041 + int ret; 1041 1042 1042 1043 iio_device_unregister(indio_dev); 1043 1044 1044 1045 /* Powerdown */ 1045 - return regmap_update_bits(chip->regmap, INA2XX_CONFIG, 1046 - INA2XX_MODE_MASK, 0); 1046 + ret = regmap_update_bits(chip->regmap, INA2XX_CONFIG, 1047 + INA2XX_MODE_MASK, 0); 1048 + if (ret) 1049 + dev_warn(&client->dev, "Failed to power down device (%pe)\n", 1050 + ERR_PTR(ret)); 1051 + 1052 + return 0; 1047 1053 } 1048 1054 1049 1055 static const struct i2c_device_id ina2xx_id[] = {
+2
drivers/iio/adc/ingenic-adc.c
··· 17 17 #include <linux/module.h> 18 18 #include <linux/mod_devicetable.h> 19 19 #include <linux/mutex.h> 20 + #include <linux/of.h> 20 21 #include <linux/platform_device.h> 22 + #include <linux/property.h> 21 23 22 24 #define JZ_ADC_REG_ENABLE 0x00 23 25 #define JZ_ADC_REG_CFG 0x04
+1
drivers/iio/adc/intel_mrfld_adc.c
··· 15 15 #include <linux/interrupt.h> 16 16 #include <linux/mfd/intel_soc_pmic.h> 17 17 #include <linux/mfd/intel_soc_pmic_mrfld.h> 18 + #include <linux/mod_devicetable.h> 18 19 #include <linux/module.h> 19 20 #include <linux/mutex.h> 20 21 #include <linux/platform_device.h>
+1 -2
drivers/iio/adc/lpc18xx_adc.c
··· 17 17 #include <linux/iio/driver.h> 18 18 #include <linux/io.h> 19 19 #include <linux/iopoll.h> 20 + #include <linux/mod_devicetable.h> 20 21 #include <linux/module.h> 21 22 #include <linux/mutex.h> 22 - #include <linux/of.h> 23 - #include <linux/of_device.h> 24 23 #include <linux/platform_device.h> 25 24 #include <linux/regulator/consumer.h> 26 25
+2 -2
drivers/iio/adc/ltc2496.c
··· 24 24 struct spi_device *spi; 25 25 26 26 /* 27 - * DMA (thus cache coherency maintenance) requires the 27 + * DMA (thus cache coherency maintenance) may require the 28 28 * transfer buffers to live in their own cache lines. 29 29 */ 30 - unsigned char rxbuf[3] ____cacheline_aligned; 30 + unsigned char rxbuf[3] __aligned(IIO_DMA_MINALIGN); 31 31 unsigned char txbuf[3]; 32 32 }; 33 33
+2 -2
drivers/iio/adc/ltc2497.c
··· 20 20 struct ltc2497core_driverdata common_ddata; 21 21 struct i2c_client *client; 22 22 /* 23 - * DMA (thus cache coherency maintenance) requires the 23 + * DMA (thus cache coherency maintenance) may require the 24 24 * transfer buffers to live in their own cache lines. 25 25 */ 26 - __be32 buf ____cacheline_aligned; 26 + __be32 buf __aligned(IIO_DMA_MINALIGN); 27 27 }; 28 28 29 29 static int ltc2497_result_and_measure(struct ltc2497core_driverdata *ddata,
+1 -1
drivers/iio/adc/max1027.c
··· 272 272 struct mutex lock; 273 273 struct completion complete; 274 274 275 - u8 reg ____cacheline_aligned; 275 + u8 reg __aligned(IIO_DMA_MINALIGN); 276 276 }; 277 277 278 278 static int max1027_wait_eoc(struct iio_dev *indio_dev)
+2 -2
drivers/iio/adc/max11100.c
··· 33 33 struct spi_device *spi; 34 34 35 35 /* 36 - * DMA (thus cache coherency maintenance) requires the 36 + * DMA (thus cache coherency maintenance) may require the 37 37 * transfer buffers to live in their own cache lines. 38 38 */ 39 - u8 buffer[3] ____cacheline_aligned; 39 + u8 buffer[3] __aligned(IIO_DMA_MINALIGN); 40 40 }; 41 41 42 42 static const struct iio_chan_spec max11100_channels[] = {
+1 -1
drivers/iio/adc/max1118.c
··· 42 42 s64 ts __aligned(8); 43 43 } scan; 44 44 45 - u8 data ____cacheline_aligned; 45 + u8 data __aligned(IIO_DMA_MINALIGN); 46 46 }; 47 47 48 48 #define MAX1118_CHANNEL(ch) \
+1 -1
drivers/iio/adc/max1241.c
··· 26 26 struct regulator *vref; 27 27 struct gpio_desc *shutdown; 28 28 29 - __be16 data ____cacheline_aligned; 29 + __be16 data __aligned(IIO_DMA_MINALIGN); 30 30 }; 31 31 32 32 static const struct iio_chan_spec max1241_channels[] = {
+1 -1
drivers/iio/adc/mcp320x.c
··· 92 92 struct mutex lock; 93 93 const struct mcp320x_chip_info *chip_info; 94 94 95 - u8 tx_buf ____cacheline_aligned; 95 + u8 tx_buf __aligned(IIO_DMA_MINALIGN); 96 96 u8 rx_buf[4]; 97 97 }; 98 98
+68 -109
drivers/iio/adc/meson_saradc.c
··· 322 322 static int meson_sar_adc_wait_busy_clear(struct iio_dev *indio_dev) 323 323 { 324 324 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 325 - int regval, timeout = 10000; 325 + int val; 326 326 327 327 /* 328 328 * NOTE: we need a small delay before reading the status, otherwise 329 329 * the sample engine may not have started internally (which would 330 330 * seem to us that sampling is already finished). 331 331 */ 332 - do { 333 - udelay(1); 334 - regmap_read(priv->regmap, MESON_SAR_ADC_REG0, &regval); 335 - } while (FIELD_GET(MESON_SAR_ADC_REG0_BUSY_MASK, regval) && timeout--); 336 - 337 - if (timeout < 0) 338 - return -ETIMEDOUT; 339 - 340 - return 0; 332 + udelay(1); 333 + return regmap_read_poll_timeout_atomic(priv->regmap, MESON_SAR_ADC_REG0, val, 334 + !FIELD_GET(MESON_SAR_ADC_REG0_BUSY_MASK, val), 335 + 1, 10000); 341 336 } 342 337 343 338 static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev, ··· 340 345 int *val) 341 346 { 342 347 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 348 + struct device *dev = indio_dev->dev.parent; 343 349 int regval, fifo_chan, fifo_val, count; 344 350 345 351 if (!wait_for_completion_timeout(&priv->done, ··· 349 353 350 354 count = meson_sar_adc_get_fifo_count(indio_dev); 351 355 if (count != 1) { 352 - dev_err(&indio_dev->dev, 353 - "ADC FIFO has %d element(s) instead of one\n", count); 356 + dev_err(dev, "ADC FIFO has %d element(s) instead of one\n", count); 354 357 return -EINVAL; 355 358 } 356 359 357 360 regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, &regval); 358 361 fifo_chan = FIELD_GET(MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK, regval); 359 362 if (fifo_chan != chan->address) { 360 - dev_err(&indio_dev->dev, 361 - "ADC FIFO entry belongs to channel %d instead of %lu\n", 363 + dev_err(dev, "ADC FIFO entry belongs to channel %d instead of %lu\n", 362 364 fifo_chan, chan->address); 363 365 return -EINVAL; 364 366 } ··· 484 490 static int meson_sar_adc_lock(struct iio_dev *indio_dev) 485 491 { 486 492 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 487 - int val, timeout = 10000; 493 + int val, ret; 488 494 489 495 mutex_lock(&indio_dev->mlock); 490 496 ··· 494 500 MESON_SAR_ADC_DELAY_KERNEL_BUSY, 495 501 MESON_SAR_ADC_DELAY_KERNEL_BUSY); 496 502 503 + udelay(1); 504 + 497 505 /* 498 506 * wait until BL30 releases it's lock (so we can use the SAR 499 507 * ADC) 500 508 */ 501 - do { 502 - udelay(1); 503 - regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val); 504 - } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--); 505 - 506 - if (timeout < 0) { 509 + ret = regmap_read_poll_timeout_atomic(priv->regmap, MESON_SAR_ADC_DELAY, val, 510 + !(val & MESON_SAR_ADC_DELAY_BL30_BUSY), 511 + 1, 10000); 512 + if (ret) { 507 513 mutex_unlock(&indio_dev->mlock); 508 - return -ETIMEDOUT; 514 + return ret; 509 515 } 510 516 } 511 517 ··· 544 550 int *val) 545 551 { 546 552 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 553 + struct device *dev = indio_dev->dev.parent; 547 554 int ret; 548 555 549 556 if (chan->type == IIO_TEMP && !priv->temperature_sensor_calibrated) ··· 568 573 meson_sar_adc_unlock(indio_dev); 569 574 570 575 if (ret) { 571 - dev_warn(indio_dev->dev.parent, 572 - "failed to read sample for channel %lu: %d\n", 576 + dev_warn(dev, "failed to read sample for channel %lu: %d\n", 573 577 chan->address, ret); 574 578 return ret; 575 579 } ··· 581 587 int *val, int *val2, long mask) 582 588 { 583 589 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 590 + struct device *dev = indio_dev->dev.parent; 584 591 int ret; 585 592 586 593 switch (mask) { ··· 598 603 if (chan->type == IIO_VOLTAGE) { 599 604 ret = regulator_get_voltage(priv->vref); 600 605 if (ret < 0) { 601 - dev_err(indio_dev->dev.parent, 602 - "failed to get vref voltage: %d\n", 603 - ret); 606 + dev_err(dev, "failed to get vref voltage: %d\n", ret); 604 607 return ret; 605 608 } 606 609 ··· 643 650 void __iomem *base) 644 651 { 645 652 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 653 + struct device *dev = indio_dev->dev.parent; 646 654 struct clk_init_data init; 647 655 const char *clk_parents[1]; 648 656 649 - init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_div", 650 - dev_name(indio_dev->dev.parent)); 657 + init.name = devm_kasprintf(dev, GFP_KERNEL, "%s#adc_div", dev_name(dev)); 651 658 if (!init.name) 652 659 return -ENOMEM; 653 660 ··· 663 670 priv->clk_div.hw.init = &init; 664 671 priv->clk_div.flags = 0; 665 672 666 - priv->adc_div_clk = devm_clk_register(&indio_dev->dev, 667 - &priv->clk_div.hw); 673 + priv->adc_div_clk = devm_clk_register(dev, &priv->clk_div.hw); 668 674 if (WARN_ON(IS_ERR(priv->adc_div_clk))) 669 675 return PTR_ERR(priv->adc_div_clk); 670 676 671 - init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_en", 672 - dev_name(indio_dev->dev.parent)); 677 + init.name = devm_kasprintf(dev, GFP_KERNEL, "%s#adc_en", dev_name(dev)); 673 678 if (!init.name) 674 679 return -ENOMEM; 675 680 ··· 681 690 priv->clk_gate.bit_idx = __ffs(MESON_SAR_ADC_REG3_CLK_EN); 682 691 priv->clk_gate.hw.init = &init; 683 692 684 - priv->adc_clk = devm_clk_register(&indio_dev->dev, &priv->clk_gate.hw); 693 + priv->adc_clk = devm_clk_register(dev, &priv->clk_gate.hw); 685 694 if (WARN_ON(IS_ERR(priv->adc_clk))) 686 695 return PTR_ERR(priv->adc_clk); 687 696 ··· 692 701 { 693 702 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 694 703 u8 *buf, trimming_bits, trimming_mask, upper_adc_val; 704 + struct device *dev = indio_dev->dev.parent; 695 705 struct nvmem_cell *temperature_calib; 696 706 size_t read_len; 697 707 int ret; 698 708 699 - temperature_calib = devm_nvmem_cell_get(indio_dev->dev.parent, 700 - "temperature_calib"); 709 + temperature_calib = devm_nvmem_cell_get(dev, "temperature_calib"); 701 710 if (IS_ERR(temperature_calib)) { 702 711 ret = PTR_ERR(temperature_calib); 703 712 ··· 708 717 if (ret == -ENODEV) 709 718 return 0; 710 719 711 - return dev_err_probe(indio_dev->dev.parent, ret, 712 - "failed to get temperature_calib cell\n"); 720 + return dev_err_probe(dev, ret, "failed to get temperature_calib cell\n"); 713 721 } 714 722 715 - priv->tsc_regmap = 716 - syscon_regmap_lookup_by_phandle(indio_dev->dev.parent->of_node, 717 - "amlogic,hhi-sysctrl"); 718 - if (IS_ERR(priv->tsc_regmap)) { 719 - dev_err(indio_dev->dev.parent, 720 - "failed to get amlogic,hhi-sysctrl regmap\n"); 721 - return PTR_ERR(priv->tsc_regmap); 722 - } 723 + priv->tsc_regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "amlogic,hhi-sysctrl"); 724 + if (IS_ERR(priv->tsc_regmap)) 725 + return dev_err_probe(dev, PTR_ERR(priv->tsc_regmap), 726 + "failed to get amlogic,hhi-sysctrl regmap\n"); 723 727 724 728 read_len = MESON_SAR_ADC_EFUSE_BYTES; 725 729 buf = nvmem_cell_read(temperature_calib, &read_len); 726 - if (IS_ERR(buf)) { 727 - dev_err(indio_dev->dev.parent, 728 - "failed to read temperature_calib cell\n"); 729 - return PTR_ERR(buf); 730 - } else if (read_len != MESON_SAR_ADC_EFUSE_BYTES) { 730 + if (IS_ERR(buf)) 731 + return dev_err_probe(dev, PTR_ERR(buf), "failed to read temperature_calib cell\n"); 732 + if (read_len != MESON_SAR_ADC_EFUSE_BYTES) { 731 733 kfree(buf); 732 - dev_err(indio_dev->dev.parent, 733 - "invalid read size of temperature_calib cell\n"); 734 - return -EINVAL; 734 + return dev_err_probe(dev, -EINVAL, "invalid read size of temperature_calib cell\n"); 735 735 } 736 736 737 737 trimming_bits = priv->param->temperature_trimming_bits; ··· 747 765 static int meson_sar_adc_init(struct iio_dev *indio_dev) 748 766 { 749 767 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 768 + struct device *dev = indio_dev->dev.parent; 750 769 int regval, i, ret; 751 770 752 771 /* ··· 871 888 } 872 889 873 890 ret = clk_set_parent(priv->adc_sel_clk, priv->clkin); 874 - if (ret) { 875 - dev_err(indio_dev->dev.parent, 876 - "failed to set adc parent to clkin\n"); 877 - return ret; 878 - } 891 + if (ret) 892 + return dev_err_probe(dev, ret, "failed to set adc parent to clkin\n"); 879 893 880 894 ret = clk_set_rate(priv->adc_clk, priv->param->clock_rate); 881 - if (ret) { 882 - dev_err(indio_dev->dev.parent, 883 - "failed to set adc clock rate\n"); 884 - return ret; 885 - } 895 + if (ret) 896 + return dev_err_probe(dev, ret, "failed to set adc clock rate\n"); 886 897 887 898 return 0; 888 899 } ··· 899 922 static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev) 900 923 { 901 924 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 925 + struct device *dev = indio_dev->dev.parent; 902 926 int ret; 903 927 u32 regval; 904 928 ··· 909 931 910 932 ret = regulator_enable(priv->vref); 911 933 if (ret < 0) { 912 - dev_err(indio_dev->dev.parent, 913 - "failed to enable vref regulator\n"); 934 + dev_err(dev, "failed to enable vref regulator\n"); 914 935 goto err_vref; 915 936 } 916 937 917 938 ret = clk_prepare_enable(priv->core_clk); 918 939 if (ret) { 919 - dev_err(indio_dev->dev.parent, "failed to enable core clk\n"); 940 + dev_err(dev, "failed to enable core clk\n"); 920 941 goto err_core_clk; 921 942 } 922 943 ··· 933 956 934 957 ret = clk_prepare_enable(priv->adc_clk); 935 958 if (ret) { 936 - dev_err(indio_dev->dev.parent, "failed to enable adc clk\n"); 959 + dev_err(dev, "failed to enable adc clk\n"); 937 960 goto err_adc_clk; 938 961 } 939 962 ··· 1163 1186 { 1164 1187 const struct meson_sar_adc_data *match_data; 1165 1188 struct meson_sar_adc_priv *priv; 1189 + struct device *dev = &pdev->dev; 1166 1190 struct iio_dev *indio_dev; 1167 1191 void __iomem *base; 1168 1192 int irq, ret; 1169 1193 1170 - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv)); 1171 - if (!indio_dev) { 1172 - dev_err(&pdev->dev, "failed allocating iio device\n"); 1173 - return -ENOMEM; 1174 - } 1194 + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 1195 + if (!indio_dev) 1196 + return dev_err_probe(dev, -ENOMEM, "failed allocating iio device\n"); 1175 1197 1176 1198 priv = iio_priv(indio_dev); 1177 1199 init_completion(&priv->done); 1178 1200 1179 - match_data = of_device_get_match_data(&pdev->dev); 1180 - if (!match_data) { 1181 - dev_err(&pdev->dev, "failed to get match data\n"); 1182 - return -ENODEV; 1183 - } 1201 + match_data = of_device_get_match_data(dev); 1202 + if (!match_data) 1203 + return dev_err_probe(dev, -ENODEV, "failed to get match data\n"); 1184 1204 1185 1205 priv->param = match_data->param; 1186 1206 ··· 1189 1215 if (IS_ERR(base)) 1190 1216 return PTR_ERR(base); 1191 1217 1192 - priv->regmap = devm_regmap_init_mmio(&pdev->dev, base, 1193 - priv->param->regmap_config); 1218 + priv->regmap = devm_regmap_init_mmio(dev, base, priv->param->regmap_config); 1194 1219 if (IS_ERR(priv->regmap)) 1195 1220 return PTR_ERR(priv->regmap); 1196 1221 1197 - irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 1222 + irq = irq_of_parse_and_map(dev->of_node, 0); 1198 1223 if (!irq) 1199 1224 return -EINVAL; 1200 1225 1201 - ret = devm_request_irq(&pdev->dev, irq, meson_sar_adc_irq, IRQF_SHARED, 1202 - dev_name(&pdev->dev), indio_dev); 1226 + ret = devm_request_irq(dev, irq, meson_sar_adc_irq, IRQF_SHARED, dev_name(dev), indio_dev); 1203 1227 if (ret) 1204 1228 return ret; 1205 1229 1206 - priv->clkin = devm_clk_get(&pdev->dev, "clkin"); 1230 + priv->clkin = devm_clk_get(dev, "clkin"); 1207 1231 if (IS_ERR(priv->clkin)) 1208 - return dev_err_probe(&pdev->dev, PTR_ERR(priv->clkin), 1209 - "failed to get clkin\n"); 1232 + return dev_err_probe(dev, PTR_ERR(priv->clkin), "failed to get clkin\n"); 1210 1233 1211 - priv->core_clk = devm_clk_get(&pdev->dev, "core"); 1234 + priv->core_clk = devm_clk_get(dev, "core"); 1212 1235 if (IS_ERR(priv->core_clk)) 1213 - return dev_err_probe(&pdev->dev, PTR_ERR(priv->core_clk), 1214 - "failed to get core clk\n"); 1236 + return dev_err_probe(dev, PTR_ERR(priv->core_clk), "failed to get core clk\n"); 1215 1237 1216 - priv->adc_clk = devm_clk_get(&pdev->dev, "adc_clk"); 1217 - if (IS_ERR(priv->adc_clk)) { 1218 - if (PTR_ERR(priv->adc_clk) == -ENOENT) 1219 - priv->adc_clk = NULL; 1220 - else 1221 - return dev_err_probe(&pdev->dev, PTR_ERR(priv->adc_clk), 1222 - "failed to get adc clk\n"); 1223 - } 1238 + priv->adc_clk = devm_clk_get_optional(dev, "adc_clk"); 1239 + if (IS_ERR(priv->adc_clk)) 1240 + return dev_err_probe(dev, PTR_ERR(priv->adc_clk), "failed to get adc clk\n"); 1224 1241 1225 - priv->adc_sel_clk = devm_clk_get(&pdev->dev, "adc_sel"); 1226 - if (IS_ERR(priv->adc_sel_clk)) { 1227 - if (PTR_ERR(priv->adc_sel_clk) == -ENOENT) 1228 - priv->adc_sel_clk = NULL; 1229 - else 1230 - return dev_err_probe(&pdev->dev, PTR_ERR(priv->adc_sel_clk), 1231 - "failed to get adc_sel clk\n"); 1232 - } 1242 + priv->adc_sel_clk = devm_clk_get_optional(dev, "adc_sel"); 1243 + if (IS_ERR(priv->adc_sel_clk)) 1244 + return dev_err_probe(dev, PTR_ERR(priv->adc_sel_clk), "failed to get adc_sel clk\n"); 1233 1245 1234 1246 /* on pre-GXBB SoCs the SAR ADC itself provides the ADC clock: */ 1235 1247 if (!priv->adc_clk) { ··· 1224 1264 return ret; 1225 1265 } 1226 1266 1227 - priv->vref = devm_regulator_get(&pdev->dev, "vref"); 1267 + priv->vref = devm_regulator_get(dev, "vref"); 1228 1268 if (IS_ERR(priv->vref)) 1229 - return dev_err_probe(&pdev->dev, PTR_ERR(priv->vref), 1230 - "failed to get vref regulator\n"); 1269 + return dev_err_probe(dev, PTR_ERR(priv->vref), "failed to get vref regulator\n"); 1231 1270 1232 1271 priv->calibscale = MILLION; 1233 1272 ··· 1256 1297 1257 1298 ret = meson_sar_adc_calib(indio_dev); 1258 1299 if (ret) 1259 - dev_warn(&pdev->dev, "calibration failed\n"); 1300 + dev_warn(dev, "calibration failed\n"); 1260 1301 1261 1302 platform_set_drvdata(pdev, indio_dev); 1262 1303
+1
drivers/iio/adc/mp2629_adc.c
··· 11 11 #include <linux/iio/iio.h> 12 12 #include <linux/iio/machine.h> 13 13 #include <linux/mfd/mp2629.h> 14 + #include <linux/mod_devicetable.h> 14 15 #include <linux/module.h> 15 16 #include <linux/mutex.h> 16 17 #include <linux/platform_device.h>
+1
drivers/iio/adc/mt6360-adc.c
··· 5 5 #include <linux/irq.h> 6 6 #include <linux/kernel.h> 7 7 #include <linux/ktime.h> 8 + #include <linux/mod_devicetable.h> 8 9 #include <linux/module.h> 9 10 #include <linux/mutex.h> 10 11 #include <linux/platform_device.h>
+5 -11
drivers/iio/adc/nau7802.c
··· 8 8 #include <linux/delay.h> 9 9 #include <linux/i2c.h> 10 10 #include <linux/interrupt.h> 11 + #include <linux/mod_devicetable.h> 11 12 #include <linux/module.h> 13 + #include <linux/property.h> 12 14 #include <linux/wait.h> 13 15 #include <linux/log2.h> 14 - #include <linux/of.h> 15 16 16 17 #include <linux/iio/iio.h> 17 18 #include <linux/iio/sysfs.h> ··· 408 407 .attrs = &nau7802_attribute_group, 409 408 }; 410 409 411 - static int nau7802_probe(struct i2c_client *client, 412 - const struct i2c_device_id *id) 410 + static int nau7802_probe(struct i2c_client *client) 413 411 { 414 412 struct iio_dev *indio_dev; 415 413 struct nau7802_state *st; 416 - struct device_node *np = client->dev.of_node; 417 414 int i, ret; 418 415 u8 data; 419 416 u32 tmp = 0; 420 - 421 - if (!client->dev.of_node) { 422 - dev_err(&client->dev, "No device tree node available.\n"); 423 - return -EINVAL; 424 - } 425 417 426 418 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); 427 419 if (indio_dev == NULL) ··· 451 457 if (!(ret & NAU7802_PUCTRL_PUR_BIT)) 452 458 return ret; 453 459 454 - of_property_read_u32(np, "nuvoton,vldo", &tmp); 460 + device_property_read_u32(&client->dev, "nuvoton,vldo", &tmp); 455 461 st->vref_mv = tmp; 456 462 457 463 data = NAU7802_PUCTRL_PUD_BIT | NAU7802_PUCTRL_PUA_BIT | ··· 544 550 MODULE_DEVICE_TABLE(of, nau7802_dt_ids); 545 551 546 552 static struct i2c_driver nau7802_driver = { 547 - .probe = nau7802_probe, 553 + .probe_new = nau7802_probe, 548 554 .id_table = nau7802_i2c_id, 549 555 .driver = { 550 556 .name = "nau7802",
+1
drivers/iio/adc/npcm_adc.c
··· 8 8 #include <linux/iio/iio.h> 9 9 #include <linux/interrupt.h> 10 10 #include <linux/kernel.h> 11 + #include <linux/mod_devicetable.h> 11 12 #include <linux/module.h> 12 13 #include <linux/platform_device.h> 13 14 #include <linux/regmap.h>
+1022
drivers/iio/adc/qcom-spmi-rradc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (c) 2016-2017, 2019, The Linux Foundation. All rights reserved. 4 + * Copyright (c) 2022 Linaro Limited. 5 + * Author: Caleb Connolly <caleb.connolly@linaro.org> 6 + * 7 + * This driver is for the Round Robin ADC found in the pmi8998 and pm660 PMICs. 8 + */ 9 + 10 + #include <linux/bitfield.h> 11 + #include <linux/delay.h> 12 + #include <linux/kernel.h> 13 + #include <linux/math64.h> 14 + #include <linux/module.h> 15 + #include <linux/mod_devicetable.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/property.h> 18 + #include <linux/regmap.h> 19 + #include <linux/spmi.h> 20 + #include <linux/types.h> 21 + #include <linux/units.h> 22 + 23 + #include <asm/unaligned.h> 24 + 25 + #include <linux/iio/iio.h> 26 + #include <linux/iio/types.h> 27 + 28 + #include <soc/qcom/qcom-spmi-pmic.h> 29 + 30 + #define DRIVER_NAME "qcom-spmi-rradc" 31 + 32 + #define RR_ADC_EN_CTL 0x46 33 + #define RR_ADC_SKIN_TEMP_LSB 0x50 34 + #define RR_ADC_SKIN_TEMP_MSB 0x51 35 + #define RR_ADC_CTL 0x52 36 + #define RR_ADC_CTL_CONTINUOUS_SEL BIT(3) 37 + #define RR_ADC_LOG 0x53 38 + #define RR_ADC_LOG_CLR_CTRL BIT(0) 39 + 40 + #define RR_ADC_FAKE_BATT_LOW_LSB 0x58 41 + #define RR_ADC_FAKE_BATT_LOW_MSB 0x59 42 + #define RR_ADC_FAKE_BATT_HIGH_LSB 0x5A 43 + #define RR_ADC_FAKE_BATT_HIGH_MSB 0x5B 44 + 45 + #define RR_ADC_BATT_ID_CTRL 0x60 46 + #define RR_ADC_BATT_ID_CTRL_CHANNEL_CONV BIT(0) 47 + #define RR_ADC_BATT_ID_TRIGGER 0x61 48 + #define RR_ADC_BATT_ID_STS 0x62 49 + #define RR_ADC_BATT_ID_CFG 0x63 50 + #define BATT_ID_SETTLE_MASK GENMASK(7, 5) 51 + #define RR_ADC_BATT_ID_5_LSB 0x66 52 + #define RR_ADC_BATT_ID_5_MSB 0x67 53 + #define RR_ADC_BATT_ID_15_LSB 0x68 54 + #define RR_ADC_BATT_ID_15_MSB 0x69 55 + #define RR_ADC_BATT_ID_150_LSB 0x6A 56 + #define RR_ADC_BATT_ID_150_MSB 0x6B 57 + 58 + #define RR_ADC_BATT_THERM_CTRL 0x70 59 + #define RR_ADC_BATT_THERM_TRIGGER 0x71 60 + #define RR_ADC_BATT_THERM_STS 0x72 61 + #define RR_ADC_BATT_THERM_CFG 0x73 62 + #define RR_ADC_BATT_THERM_LSB 0x74 63 + #define RR_ADC_BATT_THERM_MSB 0x75 64 + #define RR_ADC_BATT_THERM_FREQ 0x76 65 + 66 + #define RR_ADC_AUX_THERM_CTRL 0x80 67 + #define RR_ADC_AUX_THERM_TRIGGER 0x81 68 + #define RR_ADC_AUX_THERM_STS 0x82 69 + #define RR_ADC_AUX_THERM_CFG 0x83 70 + #define RR_ADC_AUX_THERM_LSB 0x84 71 + #define RR_ADC_AUX_THERM_MSB 0x85 72 + 73 + #define RR_ADC_SKIN_HOT 0x86 74 + #define RR_ADC_SKIN_TOO_HOT 0x87 75 + 76 + #define RR_ADC_AUX_THERM_C1 0x88 77 + #define RR_ADC_AUX_THERM_C2 0x89 78 + #define RR_ADC_AUX_THERM_C3 0x8A 79 + #define RR_ADC_AUX_THERM_HALF_RANGE 0x8B 80 + 81 + #define RR_ADC_USB_IN_V_CTRL 0x90 82 + #define RR_ADC_USB_IN_V_TRIGGER 0x91 83 + #define RR_ADC_USB_IN_V_STS 0x92 84 + #define RR_ADC_USB_IN_V_LSB 0x94 85 + #define RR_ADC_USB_IN_V_MSB 0x95 86 + #define RR_ADC_USB_IN_I_CTRL 0x98 87 + #define RR_ADC_USB_IN_I_TRIGGER 0x99 88 + #define RR_ADC_USB_IN_I_STS 0x9A 89 + #define RR_ADC_USB_IN_I_LSB 0x9C 90 + #define RR_ADC_USB_IN_I_MSB 0x9D 91 + 92 + #define RR_ADC_DC_IN_V_CTRL 0xA0 93 + #define RR_ADC_DC_IN_V_TRIGGER 0xA1 94 + #define RR_ADC_DC_IN_V_STS 0xA2 95 + #define RR_ADC_DC_IN_V_LSB 0xA4 96 + #define RR_ADC_DC_IN_V_MSB 0xA5 97 + #define RR_ADC_DC_IN_I_CTRL 0xA8 98 + #define RR_ADC_DC_IN_I_TRIGGER 0xA9 99 + #define RR_ADC_DC_IN_I_STS 0xAA 100 + #define RR_ADC_DC_IN_I_LSB 0xAC 101 + #define RR_ADC_DC_IN_I_MSB 0xAD 102 + 103 + #define RR_ADC_PMI_DIE_TEMP_CTRL 0xB0 104 + #define RR_ADC_PMI_DIE_TEMP_TRIGGER 0xB1 105 + #define RR_ADC_PMI_DIE_TEMP_STS 0xB2 106 + #define RR_ADC_PMI_DIE_TEMP_CFG 0xB3 107 + #define RR_ADC_PMI_DIE_TEMP_LSB 0xB4 108 + #define RR_ADC_PMI_DIE_TEMP_MSB 0xB5 109 + 110 + #define RR_ADC_CHARGER_TEMP_CTRL 0xB8 111 + #define RR_ADC_CHARGER_TEMP_TRIGGER 0xB9 112 + #define RR_ADC_CHARGER_TEMP_STS 0xBA 113 + #define RR_ADC_CHARGER_TEMP_CFG 0xBB 114 + #define RR_ADC_CHARGER_TEMP_LSB 0xBC 115 + #define RR_ADC_CHARGER_TEMP_MSB 0xBD 116 + #define RR_ADC_CHARGER_HOT 0xBE 117 + #define RR_ADC_CHARGER_TOO_HOT 0xBF 118 + 119 + #define RR_ADC_GPIO_CTRL 0xC0 120 + #define RR_ADC_GPIO_TRIGGER 0xC1 121 + #define RR_ADC_GPIO_STS 0xC2 122 + #define RR_ADC_GPIO_LSB 0xC4 123 + #define RR_ADC_GPIO_MSB 0xC5 124 + 125 + #define RR_ADC_ATEST_CTRL 0xC8 126 + #define RR_ADC_ATEST_TRIGGER 0xC9 127 + #define RR_ADC_ATEST_STS 0xCA 128 + #define RR_ADC_ATEST_LSB 0xCC 129 + #define RR_ADC_ATEST_MSB 0xCD 130 + #define RR_ADC_SEC_ACCESS 0xD0 131 + 132 + #define RR_ADC_PERPH_RESET_CTL2 0xD9 133 + #define RR_ADC_PERPH_RESET_CTL3 0xDA 134 + #define RR_ADC_PERPH_RESET_CTL4 0xDB 135 + #define RR_ADC_INT_TEST1 0xE0 136 + #define RR_ADC_INT_TEST_VAL 0xE1 137 + 138 + #define RR_ADC_TM_TRIGGER_CTRLS 0xE2 139 + #define RR_ADC_TM_ADC_CTRLS 0xE3 140 + #define RR_ADC_TM_CNL_CTRL 0xE4 141 + #define RR_ADC_TM_BATT_ID_CTRL 0xE5 142 + #define RR_ADC_TM_THERM_CTRL 0xE6 143 + #define RR_ADC_TM_CONV_STS 0xE7 144 + #define RR_ADC_TM_ADC_READ_LSB 0xE8 145 + #define RR_ADC_TM_ADC_READ_MSB 0xE9 146 + #define RR_ADC_TM_ATEST_MUX_1 0xEA 147 + #define RR_ADC_TM_ATEST_MUX_2 0xEB 148 + #define RR_ADC_TM_REFERENCES 0xED 149 + #define RR_ADC_TM_MISC_CTL 0xEE 150 + #define RR_ADC_TM_RR_CTRL 0xEF 151 + 152 + #define RR_ADC_TRIGGER_EVERY_CYCLE BIT(7) 153 + #define RR_ADC_TRIGGER_CTL BIT(0) 154 + 155 + #define RR_ADC_BATT_ID_RANGE 820 156 + 157 + #define RR_ADC_BITS 10 158 + #define RR_ADC_CHAN_MSB (1 << RR_ADC_BITS) 159 + #define RR_ADC_FS_VOLTAGE_MV 2500 160 + 161 + /* BATT_THERM 0.25K/LSB */ 162 + #define RR_ADC_BATT_THERM_LSB_K 4 163 + 164 + #define RR_ADC_TEMP_FS_VOLTAGE_NUM 5000000 165 + #define RR_ADC_TEMP_FS_VOLTAGE_DEN 3 166 + #define RR_ADC_DIE_TEMP_OFFSET 601400 167 + #define RR_ADC_DIE_TEMP_SLOPE 2 168 + #define RR_ADC_DIE_TEMP_OFFSET_MILLI_DEGC 25000 169 + 170 + #define RR_ADC_CHG_TEMP_GF_OFFSET_UV 1303168 171 + #define RR_ADC_CHG_TEMP_GF_SLOPE_UV_PER_C 3784 172 + #define RR_ADC_CHG_TEMP_SMIC_OFFSET_UV 1338433 173 + #define RR_ADC_CHG_TEMP_SMIC_SLOPE_UV_PER_C 3655 174 + #define RR_ADC_CHG_TEMP_660_GF_OFFSET_UV 1309001 175 + #define RR_ADC_CHG_TEMP_660_GF_SLOPE_UV_PER_C 3403 176 + #define RR_ADC_CHG_TEMP_660_SMIC_OFFSET_UV 1295898 177 + #define RR_ADC_CHG_TEMP_660_SMIC_SLOPE_UV_PER_C 3596 178 + #define RR_ADC_CHG_TEMP_660_MGNA_OFFSET_UV 1314779 179 + #define RR_ADC_CHG_TEMP_660_MGNA_SLOPE_UV_PER_C 3496 180 + #define RR_ADC_CHG_TEMP_OFFSET_MILLI_DEGC 25000 181 + #define RR_ADC_CHG_THRESHOLD_SCALE 4 182 + 183 + #define RR_ADC_VOLT_INPUT_FACTOR 8 184 + #define RR_ADC_CURR_INPUT_FACTOR 2000 185 + #define RR_ADC_CURR_USBIN_INPUT_FACTOR_MIL 1886 186 + #define RR_ADC_CURR_USBIN_660_FACTOR_MIL 9 187 + #define RR_ADC_CURR_USBIN_660_UV_VAL 579500 188 + 189 + #define RR_ADC_GPIO_FS_RANGE 5000 190 + #define RR_ADC_COHERENT_CHECK_RETRY 5 191 + #define RR_ADC_CHAN_MAX_CONTINUOUS_BUFFER_LEN 16 192 + 193 + #define RR_ADC_STS_CHANNEL_READING_MASK GENMASK(1, 0) 194 + #define RR_ADC_STS_CHANNEL_STS BIT(1) 195 + 196 + #define RR_ADC_TP_REV_VERSION1 21 197 + #define RR_ADC_TP_REV_VERSION2 29 198 + #define RR_ADC_TP_REV_VERSION3 32 199 + 200 + #define RRADC_BATT_ID_DELAY_MAX 8 201 + 202 + enum rradc_channel_id { 203 + RR_ADC_BATT_ID = 0, 204 + RR_ADC_BATT_THERM, 205 + RR_ADC_SKIN_TEMP, 206 + RR_ADC_USBIN_I, 207 + RR_ADC_USBIN_V, 208 + RR_ADC_DCIN_I, 209 + RR_ADC_DCIN_V, 210 + RR_ADC_DIE_TEMP, 211 + RR_ADC_CHG_TEMP, 212 + RR_ADC_GPIO, 213 + RR_ADC_CHAN_MAX 214 + }; 215 + 216 + struct rradc_chip; 217 + 218 + /** 219 + * struct rradc_channel - rradc channel data 220 + * @label: channel label 221 + * @lsb: Channel least significant byte 222 + * @status: Channel status address 223 + * @size: number of bytes to read 224 + * @trigger_addr: Trigger address, trigger is only used on some channels 225 + * @trigger_mask: Trigger mask 226 + * @scale_fn: Post process callback for channels which can't be exposed 227 + * as offset + scale. 228 + */ 229 + struct rradc_channel { 230 + const char *label; 231 + u8 lsb; 232 + u8 status; 233 + int size; 234 + int trigger_addr; 235 + int trigger_mask; 236 + int (*scale_fn)(struct rradc_chip *chip, u16 adc_code, int *result); 237 + }; 238 + 239 + struct rradc_chip { 240 + struct device *dev; 241 + const struct qcom_spmi_pmic *pmic; 242 + /* 243 + * Lock held while doing channel conversion 244 + * involving multiple register read/writes 245 + */ 246 + struct mutex conversion_lock; 247 + struct regmap *regmap; 248 + u32 base; 249 + int batt_id_delay; 250 + u16 batt_id_data; 251 + }; 252 + 253 + static const int batt_id_delays[] = { 0, 1, 4, 12, 20, 40, 60, 80 }; 254 + static const struct rradc_channel rradc_chans[RR_ADC_CHAN_MAX]; 255 + static const struct iio_chan_spec rradc_iio_chans[RR_ADC_CHAN_MAX]; 256 + 257 + static int rradc_read(struct rradc_chip *chip, u16 addr, __le16 *buf, int len) 258 + { 259 + int ret, retry_cnt = 0; 260 + __le16 data_check[RR_ADC_CHAN_MAX_CONTINUOUS_BUFFER_LEN / 2]; 261 + 262 + if (len > RR_ADC_CHAN_MAX_CONTINUOUS_BUFFER_LEN) { 263 + dev_err(chip->dev, 264 + "Can't read more than %d bytes, but asked to read %d bytes.\n", 265 + RR_ADC_CHAN_MAX_CONTINUOUS_BUFFER_LEN, len); 266 + return -EINVAL; 267 + } 268 + 269 + while (retry_cnt < RR_ADC_COHERENT_CHECK_RETRY) { 270 + ret = regmap_bulk_read(chip->regmap, chip->base + addr, buf, 271 + len); 272 + if (ret < 0) { 273 + dev_err(chip->dev, "rr_adc reg 0x%x failed :%d\n", addr, 274 + ret); 275 + return ret; 276 + } 277 + 278 + ret = regmap_bulk_read(chip->regmap, chip->base + addr, 279 + data_check, len); 280 + if (ret < 0) { 281 + dev_err(chip->dev, "rr_adc reg 0x%x failed :%d\n", addr, 282 + ret); 283 + return ret; 284 + } 285 + 286 + if (memcmp(buf, data_check, len) != 0) { 287 + retry_cnt++; 288 + dev_dbg(chip->dev, 289 + "coherent read error, retry_cnt:%d\n", 290 + retry_cnt); 291 + continue; 292 + } 293 + 294 + break; 295 + } 296 + 297 + if (retry_cnt == RR_ADC_COHERENT_CHECK_RETRY) 298 + dev_err(chip->dev, "Retry exceeded for coherency check\n"); 299 + 300 + return ret; 301 + } 302 + 303 + static int rradc_get_fab_coeff(struct rradc_chip *chip, int64_t *offset, 304 + int64_t *slope) 305 + { 306 + if (chip->pmic->subtype == PM660_SUBTYPE) { 307 + switch (chip->pmic->fab_id) { 308 + case PM660_FAB_ID_GF: 309 + *offset = RR_ADC_CHG_TEMP_660_GF_OFFSET_UV; 310 + *slope = RR_ADC_CHG_TEMP_660_GF_SLOPE_UV_PER_C; 311 + return 0; 312 + case PM660_FAB_ID_TSMC: 313 + *offset = RR_ADC_CHG_TEMP_660_SMIC_OFFSET_UV; 314 + *slope = RR_ADC_CHG_TEMP_660_SMIC_SLOPE_UV_PER_C; 315 + return 0; 316 + default: 317 + *offset = RR_ADC_CHG_TEMP_660_MGNA_OFFSET_UV; 318 + *slope = RR_ADC_CHG_TEMP_660_MGNA_SLOPE_UV_PER_C; 319 + } 320 + } else if (chip->pmic->subtype == PMI8998_SUBTYPE) { 321 + switch (chip->pmic->fab_id) { 322 + case PMI8998_FAB_ID_GF: 323 + *offset = RR_ADC_CHG_TEMP_GF_OFFSET_UV; 324 + *slope = RR_ADC_CHG_TEMP_GF_SLOPE_UV_PER_C; 325 + return 0; 326 + case PMI8998_FAB_ID_SMIC: 327 + *offset = RR_ADC_CHG_TEMP_SMIC_OFFSET_UV; 328 + *slope = RR_ADC_CHG_TEMP_SMIC_SLOPE_UV_PER_C; 329 + return 0; 330 + default: 331 + return -EINVAL; 332 + } 333 + } 334 + 335 + return -EINVAL; 336 + } 337 + 338 + /* 339 + * These functions explicitly cast int64_t to int. 340 + * They will never overflow, as the values are small enough. 341 + */ 342 + static int rradc_post_process_batt_id(struct rradc_chip *chip, u16 adc_code, 343 + int *result_ohms) 344 + { 345 + uint32_t current_value; 346 + int64_t r_id; 347 + 348 + current_value = chip->batt_id_data; 349 + r_id = ((int64_t)adc_code * RR_ADC_FS_VOLTAGE_MV); 350 + r_id = div64_s64(r_id, (RR_ADC_CHAN_MSB * current_value)); 351 + *result_ohms = (int)(r_id * MILLI); 352 + 353 + return 0; 354 + } 355 + 356 + static int rradc_enable_continuous_mode(struct rradc_chip *chip) 357 + { 358 + int ret; 359 + 360 + /* Clear channel log */ 361 + ret = regmap_update_bits(chip->regmap, chip->base + RR_ADC_LOG, 362 + RR_ADC_LOG_CLR_CTRL, RR_ADC_LOG_CLR_CTRL); 363 + if (ret < 0) { 364 + dev_err(chip->dev, "log ctrl update to clear failed:%d\n", ret); 365 + return ret; 366 + } 367 + 368 + ret = regmap_update_bits(chip->regmap, chip->base + RR_ADC_LOG, 369 + RR_ADC_LOG_CLR_CTRL, 0); 370 + if (ret < 0) { 371 + dev_err(chip->dev, "log ctrl update to not clear failed:%d\n", 372 + ret); 373 + return ret; 374 + } 375 + 376 + /* Switch to continuous mode */ 377 + ret = regmap_update_bits(chip->regmap, chip->base + RR_ADC_CTL, 378 + RR_ADC_CTL_CONTINUOUS_SEL, 379 + RR_ADC_CTL_CONTINUOUS_SEL); 380 + if (ret < 0) 381 + dev_err(chip->dev, "Update to continuous mode failed:%d\n", 382 + ret); 383 + 384 + return ret; 385 + } 386 + 387 + static int rradc_disable_continuous_mode(struct rradc_chip *chip) 388 + { 389 + int ret; 390 + 391 + /* Switch to non continuous mode */ 392 + ret = regmap_update_bits(chip->regmap, chip->base + RR_ADC_CTL, 393 + RR_ADC_CTL_CONTINUOUS_SEL, 0); 394 + if (ret < 0) 395 + dev_err(chip->dev, "Update to non-continuous mode failed:%d\n", 396 + ret); 397 + 398 + return ret; 399 + } 400 + 401 + static bool rradc_is_ready(struct rradc_chip *chip, 402 + enum rradc_channel_id chan_address) 403 + { 404 + const struct rradc_channel *chan = &rradc_chans[chan_address]; 405 + int ret; 406 + unsigned int status, mask; 407 + 408 + /* BATT_ID STS bit does not get set initially */ 409 + switch (chan_address) { 410 + case RR_ADC_BATT_ID: 411 + mask = RR_ADC_STS_CHANNEL_STS; 412 + break; 413 + default: 414 + mask = RR_ADC_STS_CHANNEL_READING_MASK; 415 + break; 416 + } 417 + 418 + ret = regmap_read(chip->regmap, chip->base + chan->status, &status); 419 + if (ret < 0 || !(status & mask)) 420 + return false; 421 + 422 + return true; 423 + } 424 + 425 + static int rradc_read_status_in_cont_mode(struct rradc_chip *chip, 426 + enum rradc_channel_id chan_address) 427 + { 428 + const struct rradc_channel *chan = &rradc_chans[chan_address]; 429 + const struct iio_chan_spec *iio_chan = &rradc_iio_chans[chan_address]; 430 + int ret, i; 431 + 432 + if (chan->trigger_mask == 0) { 433 + dev_err(chip->dev, "Channel doesn't have a trigger mask\n"); 434 + return -EINVAL; 435 + } 436 + 437 + ret = regmap_update_bits(chip->regmap, chip->base + chan->trigger_addr, 438 + chan->trigger_mask, chan->trigger_mask); 439 + if (ret < 0) { 440 + dev_err(chip->dev, 441 + "Failed to apply trigger for channel '%s' ret=%d\n", 442 + iio_chan->extend_name, ret); 443 + return ret; 444 + } 445 + 446 + ret = rradc_enable_continuous_mode(chip); 447 + if (ret < 0) { 448 + dev_err(chip->dev, "Failed to switch to continuous mode\n"); 449 + goto disable_trigger; 450 + } 451 + 452 + /* 453 + * The wait/sleep values were found through trial and error, 454 + * this is mostly for the battery ID channel which takes some 455 + * time to settle. 456 + */ 457 + for (i = 0; i < 5; i++) { 458 + if (rradc_is_ready(chip, chan_address)) 459 + break; 460 + usleep_range(50000, 50000 + 500); 461 + } 462 + 463 + if (i == 5) { 464 + dev_err(chip->dev, "Channel '%s' is not ready\n", 465 + iio_chan->extend_name); 466 + ret = -ETIMEDOUT; 467 + } 468 + 469 + rradc_disable_continuous_mode(chip); 470 + 471 + disable_trigger: 472 + regmap_update_bits(chip->regmap, chip->base + chan->trigger_addr, 473 + chan->trigger_mask, 0); 474 + 475 + return ret; 476 + } 477 + 478 + static int rradc_prepare_batt_id_conversion(struct rradc_chip *chip, 479 + enum rradc_channel_id chan_address, 480 + u16 *data) 481 + { 482 + int ret; 483 + 484 + ret = regmap_update_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_CTRL, 485 + RR_ADC_BATT_ID_CTRL_CHANNEL_CONV, 486 + RR_ADC_BATT_ID_CTRL_CHANNEL_CONV); 487 + if (ret < 0) { 488 + dev_err(chip->dev, "Enabling BATT ID channel failed:%d\n", ret); 489 + return ret; 490 + } 491 + 492 + ret = regmap_update_bits(chip->regmap, 493 + chip->base + RR_ADC_BATT_ID_TRIGGER, 494 + RR_ADC_TRIGGER_CTL, RR_ADC_TRIGGER_CTL); 495 + if (ret < 0) { 496 + dev_err(chip->dev, "BATT_ID trigger set failed:%d\n", ret); 497 + goto out_disable_batt_id; 498 + } 499 + 500 + ret = rradc_read_status_in_cont_mode(chip, chan_address); 501 + 502 + /* Reset registers back to default values */ 503 + regmap_update_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_TRIGGER, 504 + RR_ADC_TRIGGER_CTL, 0); 505 + 506 + out_disable_batt_id: 507 + regmap_update_bits(chip->regmap, chip->base + RR_ADC_BATT_ID_CTRL, 508 + RR_ADC_BATT_ID_CTRL_CHANNEL_CONV, 0); 509 + 510 + return ret; 511 + } 512 + 513 + static int rradc_do_conversion(struct rradc_chip *chip, 514 + enum rradc_channel_id chan_address, u16 *data) 515 + { 516 + const struct rradc_channel *chan = &rradc_chans[chan_address]; 517 + const struct iio_chan_spec *iio_chan = &rradc_iio_chans[chan_address]; 518 + int ret; 519 + __le16 buf[3]; 520 + 521 + mutex_lock(&chip->conversion_lock); 522 + 523 + switch (chan_address) { 524 + case RR_ADC_BATT_ID: 525 + ret = rradc_prepare_batt_id_conversion(chip, chan_address, data); 526 + if (ret < 0) { 527 + dev_err(chip->dev, "Battery ID conversion failed:%d\n", 528 + ret); 529 + goto unlock_out; 530 + } 531 + break; 532 + 533 + case RR_ADC_USBIN_V: 534 + case RR_ADC_DIE_TEMP: 535 + ret = rradc_read_status_in_cont_mode(chip, chan_address); 536 + if (ret < 0) { 537 + dev_err(chip->dev, 538 + "Error reading in continuous mode:%d\n", ret); 539 + goto unlock_out; 540 + } 541 + break; 542 + default: 543 + if (!rradc_is_ready(chip, chan_address)) { 544 + /* 545 + * Usually this means the channel isn't attached, for example 546 + * the in_voltage_usbin_v_input channel will not be ready if 547 + * no USB cable is attached 548 + */ 549 + dev_dbg(chip->dev, "channel '%s' is not ready\n", 550 + iio_chan->extend_name); 551 + ret = -ENODATA; 552 + goto unlock_out; 553 + } 554 + break; 555 + } 556 + 557 + ret = rradc_read(chip, chan->lsb, buf, chan->size); 558 + if (ret) { 559 + dev_err(chip->dev, "read data failed\n"); 560 + goto unlock_out; 561 + } 562 + 563 + /* 564 + * For the battery ID we read the register for every ID ADC and then 565 + * see which one is actually connected. 566 + */ 567 + if (chan_address == RR_ADC_BATT_ID) { 568 + u16 batt_id_150 = le16_to_cpu(buf[2]); 569 + u16 batt_id_15 = le16_to_cpu(buf[1]); 570 + u16 batt_id_5 = le16_to_cpu(buf[0]); 571 + 572 + if (!batt_id_150 && !batt_id_15 && !batt_id_5) { 573 + dev_err(chip->dev, 574 + "Invalid batt_id values with all zeros\n"); 575 + ret = -EINVAL; 576 + goto unlock_out; 577 + } 578 + 579 + if (batt_id_150 <= RR_ADC_BATT_ID_RANGE) { 580 + *data = batt_id_150; 581 + chip->batt_id_data = 150; 582 + } else if (batt_id_15 <= RR_ADC_BATT_ID_RANGE) { 583 + *data = batt_id_15; 584 + chip->batt_id_data = 15; 585 + } else { 586 + *data = batt_id_5; 587 + chip->batt_id_data = 5; 588 + } 589 + } else { 590 + /* 591 + * All of the other channels are either 1 or 2 bytes. 592 + * We can rely on the second byte being 0 for 1-byte channels. 593 + */ 594 + *data = le16_to_cpu(buf[0]); 595 + } 596 + 597 + unlock_out: 598 + mutex_unlock(&chip->conversion_lock); 599 + 600 + return ret; 601 + } 602 + 603 + static int rradc_read_scale(struct rradc_chip *chip, int chan_address, int *val, 604 + int *val2) 605 + { 606 + int64_t fab_offset, fab_slope; 607 + int ret; 608 + 609 + ret = rradc_get_fab_coeff(chip, &fab_offset, &fab_slope); 610 + if (ret < 0) { 611 + dev_err(chip->dev, "Unable to get fab id coefficients\n"); 612 + return -EINVAL; 613 + } 614 + 615 + switch (chan_address) { 616 + case RR_ADC_SKIN_TEMP: 617 + *val = MILLI; 618 + *val2 = RR_ADC_BATT_THERM_LSB_K; 619 + return IIO_VAL_FRACTIONAL; 620 + case RR_ADC_USBIN_I: 621 + *val = RR_ADC_CURR_USBIN_INPUT_FACTOR_MIL * 622 + RR_ADC_FS_VOLTAGE_MV; 623 + *val2 = RR_ADC_CHAN_MSB; 624 + return IIO_VAL_FRACTIONAL; 625 + case RR_ADC_DCIN_I: 626 + *val = RR_ADC_CURR_INPUT_FACTOR * RR_ADC_FS_VOLTAGE_MV; 627 + *val2 = RR_ADC_CHAN_MSB; 628 + return IIO_VAL_FRACTIONAL; 629 + case RR_ADC_USBIN_V: 630 + case RR_ADC_DCIN_V: 631 + *val = RR_ADC_VOLT_INPUT_FACTOR * RR_ADC_FS_VOLTAGE_MV * MILLI; 632 + *val2 = RR_ADC_CHAN_MSB; 633 + return IIO_VAL_FRACTIONAL; 634 + case RR_ADC_GPIO: 635 + *val = RR_ADC_GPIO_FS_RANGE; 636 + *val2 = RR_ADC_CHAN_MSB; 637 + return IIO_VAL_FRACTIONAL; 638 + case RR_ADC_CHG_TEMP: 639 + /* 640 + * We divide val2 by MILLI instead of multiplying val 641 + * to avoid an integer overflow. 642 + */ 643 + *val = -RR_ADC_TEMP_FS_VOLTAGE_NUM; 644 + *val2 = div64_s64(RR_ADC_TEMP_FS_VOLTAGE_DEN * RR_ADC_CHAN_MSB * 645 + fab_slope, 646 + MILLI); 647 + 648 + return IIO_VAL_FRACTIONAL; 649 + case RR_ADC_DIE_TEMP: 650 + *val = RR_ADC_TEMP_FS_VOLTAGE_NUM; 651 + *val2 = RR_ADC_TEMP_FS_VOLTAGE_DEN * RR_ADC_CHAN_MSB * 652 + RR_ADC_DIE_TEMP_SLOPE; 653 + 654 + return IIO_VAL_FRACTIONAL; 655 + default: 656 + return -EINVAL; 657 + } 658 + } 659 + 660 + static int rradc_read_offset(struct rradc_chip *chip, int chan_address, int *val) 661 + { 662 + int64_t fab_offset, fab_slope; 663 + int64_t offset1, offset2; 664 + int ret; 665 + 666 + switch (chan_address) { 667 + case RR_ADC_SKIN_TEMP: 668 + /* 669 + * Offset from kelvin to degC, divided by the 670 + * scale factor (250). We lose some precision here. 671 + * 273150 / 250 = 1092.6 672 + */ 673 + *val = div64_s64(ABSOLUTE_ZERO_MILLICELSIUS, 674 + (MILLI / RR_ADC_BATT_THERM_LSB_K)); 675 + return IIO_VAL_INT; 676 + case RR_ADC_CHG_TEMP: 677 + ret = rradc_get_fab_coeff(chip, &fab_offset, &fab_slope); 678 + if (ret < 0) { 679 + dev_err(chip->dev, 680 + "Unable to get fab id coefficients\n"); 681 + return -EINVAL; 682 + } 683 + offset1 = -(fab_offset * RR_ADC_TEMP_FS_VOLTAGE_DEN * 684 + RR_ADC_CHAN_MSB); 685 + offset1 += (int64_t)RR_ADC_TEMP_FS_VOLTAGE_NUM / 2ULL; 686 + offset1 = div64_s64(offset1, 687 + (int64_t)(RR_ADC_TEMP_FS_VOLTAGE_NUM)); 688 + 689 + offset2 = (int64_t)RR_ADC_CHG_TEMP_OFFSET_MILLI_DEGC * 690 + RR_ADC_TEMP_FS_VOLTAGE_DEN * RR_ADC_CHAN_MSB * 691 + (int64_t)fab_slope; 692 + offset2 += ((int64_t)MILLI * RR_ADC_TEMP_FS_VOLTAGE_NUM) / 2; 693 + offset2 = div64_s64( 694 + offset2, ((int64_t)MILLI * RR_ADC_TEMP_FS_VOLTAGE_NUM)); 695 + 696 + /* 697 + * The -1 is to compensate for lost precision. 698 + * It should actually be -0.7906976744186046. 699 + * This works out to every value being off 700 + * by about +0.091 degrees C after applying offset and scale. 701 + */ 702 + *val = (int)(offset1 - offset2 - 1); 703 + return IIO_VAL_INT; 704 + case RR_ADC_DIE_TEMP: 705 + offset1 = -RR_ADC_DIE_TEMP_OFFSET * 706 + (int64_t)RR_ADC_TEMP_FS_VOLTAGE_DEN * 707 + (int64_t)RR_ADC_CHAN_MSB; 708 + offset1 = div64_s64(offset1, RR_ADC_TEMP_FS_VOLTAGE_NUM); 709 + 710 + offset2 = -(int64_t)RR_ADC_CHG_TEMP_OFFSET_MILLI_DEGC * 711 + RR_ADC_TEMP_FS_VOLTAGE_DEN * RR_ADC_CHAN_MSB * 712 + RR_ADC_DIE_TEMP_SLOPE; 713 + offset2 = div64_s64(offset2, 714 + ((int64_t)RR_ADC_TEMP_FS_VOLTAGE_NUM)); 715 + 716 + /* 717 + * The result is -339, it should be -338.69789, this results 718 + * in the calculated die temp being off by 719 + * -0.004 - -0.0175 degrees C 720 + */ 721 + *val = (int)(offset1 - offset2); 722 + return IIO_VAL_INT; 723 + default: 724 + break; 725 + } 726 + return -EINVAL; 727 + } 728 + 729 + static int rradc_read_raw(struct iio_dev *indio_dev, 730 + struct iio_chan_spec const *chan_spec, int *val, 731 + int *val2, long mask) 732 + { 733 + struct rradc_chip *chip = iio_priv(indio_dev); 734 + const struct rradc_channel *chan; 735 + int ret; 736 + u16 adc_code; 737 + 738 + if (chan_spec->address >= RR_ADC_CHAN_MAX) { 739 + dev_err(chip->dev, "Invalid channel index:%lu\n", 740 + chan_spec->address); 741 + return -EINVAL; 742 + } 743 + 744 + switch (mask) { 745 + case IIO_CHAN_INFO_SCALE: 746 + return rradc_read_scale(chip, chan_spec->address, val, val2); 747 + case IIO_CHAN_INFO_OFFSET: 748 + return rradc_read_offset(chip, chan_spec->address, val); 749 + case IIO_CHAN_INFO_RAW: 750 + ret = rradc_do_conversion(chip, chan_spec->address, &adc_code); 751 + if (ret < 0) 752 + return ret; 753 + 754 + *val = adc_code; 755 + return IIO_VAL_INT; 756 + case IIO_CHAN_INFO_PROCESSED: 757 + chan = &rradc_chans[chan_spec->address]; 758 + if (!chan->scale_fn) 759 + return -EINVAL; 760 + ret = rradc_do_conversion(chip, chan_spec->address, &adc_code); 761 + if (ret < 0) 762 + return ret; 763 + 764 + *val = chan->scale_fn(chip, adc_code, val); 765 + return IIO_VAL_INT; 766 + default: 767 + return -EINVAL; 768 + } 769 + } 770 + 771 + static int rradc_read_label(struct iio_dev *indio_dev, 772 + struct iio_chan_spec const *chan, char *label) 773 + { 774 + return snprintf(label, PAGE_SIZE, "%s\n", 775 + rradc_chans[chan->address].label); 776 + } 777 + 778 + static const struct iio_info rradc_info = { 779 + .read_raw = rradc_read_raw, 780 + .read_label = rradc_read_label, 781 + }; 782 + 783 + static const struct rradc_channel rradc_chans[RR_ADC_CHAN_MAX] = { 784 + { 785 + .label = "batt_id", 786 + .scale_fn = rradc_post_process_batt_id, 787 + .lsb = RR_ADC_BATT_ID_5_LSB, 788 + .status = RR_ADC_BATT_ID_STS, 789 + .size = 6, 790 + .trigger_addr = RR_ADC_BATT_ID_TRIGGER, 791 + .trigger_mask = BIT(0), 792 + }, { 793 + .label = "batt", 794 + .lsb = RR_ADC_BATT_THERM_LSB, 795 + .status = RR_ADC_BATT_THERM_STS, 796 + .size = 2, 797 + .trigger_addr = RR_ADC_BATT_THERM_TRIGGER, 798 + }, { 799 + .label = "pmi8998_skin", 800 + .lsb = RR_ADC_SKIN_TEMP_LSB, 801 + .status = RR_ADC_AUX_THERM_STS, 802 + .size = 2, 803 + .trigger_addr = RR_ADC_AUX_THERM_TRIGGER, 804 + }, { 805 + .label = "usbin_i", 806 + .lsb = RR_ADC_USB_IN_I_LSB, 807 + .status = RR_ADC_USB_IN_I_STS, 808 + .size = 2, 809 + .trigger_addr = RR_ADC_USB_IN_I_TRIGGER, 810 + }, { 811 + .label = "usbin_v", 812 + .lsb = RR_ADC_USB_IN_V_LSB, 813 + .status = RR_ADC_USB_IN_V_STS, 814 + .size = 2, 815 + .trigger_addr = RR_ADC_USB_IN_V_TRIGGER, 816 + .trigger_mask = BIT(7), 817 + }, { 818 + .label = "dcin_i", 819 + .lsb = RR_ADC_DC_IN_I_LSB, 820 + .status = RR_ADC_DC_IN_I_STS, 821 + .size = 2, 822 + .trigger_addr = RR_ADC_DC_IN_I_TRIGGER, 823 + }, { 824 + .label = "dcin_v", 825 + .lsb = RR_ADC_DC_IN_V_LSB, 826 + .status = RR_ADC_DC_IN_V_STS, 827 + .size = 2, 828 + .trigger_addr = RR_ADC_DC_IN_V_TRIGGER, 829 + }, { 830 + .label = "pmi8998_die", 831 + .lsb = RR_ADC_PMI_DIE_TEMP_LSB, 832 + .status = RR_ADC_PMI_DIE_TEMP_STS, 833 + .size = 2, 834 + .trigger_addr = RR_ADC_PMI_DIE_TEMP_TRIGGER, 835 + .trigger_mask = RR_ADC_TRIGGER_EVERY_CYCLE, 836 + }, { 837 + .label = "chg", 838 + .lsb = RR_ADC_CHARGER_TEMP_LSB, 839 + .status = RR_ADC_CHARGER_TEMP_STS, 840 + .size = 2, 841 + .trigger_addr = RR_ADC_CHARGER_TEMP_TRIGGER, 842 + }, { 843 + .label = "gpio", 844 + .lsb = RR_ADC_GPIO_LSB, 845 + .status = RR_ADC_GPIO_STS, 846 + .size = 2, 847 + .trigger_addr = RR_ADC_GPIO_TRIGGER, 848 + }, 849 + }; 850 + 851 + static const struct iio_chan_spec rradc_iio_chans[RR_ADC_CHAN_MAX] = { 852 + { 853 + .type = IIO_RESISTANCE, 854 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 855 + .address = RR_ADC_BATT_ID, 856 + .channel = 0, 857 + .indexed = 1, 858 + }, { 859 + .type = IIO_TEMP, 860 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 861 + .address = RR_ADC_BATT_THERM, 862 + .channel = 0, 863 + .indexed = 1, 864 + }, { 865 + .type = IIO_TEMP, 866 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 867 + BIT(IIO_CHAN_INFO_SCALE) | 868 + BIT(IIO_CHAN_INFO_OFFSET), 869 + .address = RR_ADC_SKIN_TEMP, 870 + .channel = 1, 871 + .indexed = 1, 872 + }, { 873 + .type = IIO_CURRENT, 874 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 875 + BIT(IIO_CHAN_INFO_SCALE), 876 + .address = RR_ADC_USBIN_I, 877 + .channel = 0, 878 + .indexed = 1, 879 + }, { 880 + .type = IIO_VOLTAGE, 881 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 882 + BIT(IIO_CHAN_INFO_SCALE), 883 + .address = RR_ADC_USBIN_V, 884 + .channel = 0, 885 + .indexed = 1, 886 + }, { 887 + .type = IIO_CURRENT, 888 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 889 + BIT(IIO_CHAN_INFO_SCALE), 890 + .address = RR_ADC_DCIN_I, 891 + .channel = 1, 892 + .indexed = 1, 893 + }, { 894 + .type = IIO_VOLTAGE, 895 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 896 + BIT(IIO_CHAN_INFO_SCALE), 897 + .address = RR_ADC_DCIN_V, 898 + .channel = 1, 899 + .indexed = 1, 900 + }, { 901 + .type = IIO_TEMP, 902 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 903 + BIT(IIO_CHAN_INFO_SCALE) | 904 + BIT(IIO_CHAN_INFO_OFFSET), 905 + .address = RR_ADC_DIE_TEMP, 906 + .channel = 2, 907 + .indexed = 1, 908 + }, { 909 + .type = IIO_TEMP, 910 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 911 + BIT(IIO_CHAN_INFO_OFFSET) | 912 + BIT(IIO_CHAN_INFO_SCALE), 913 + .address = RR_ADC_CHG_TEMP, 914 + .channel = 3, 915 + .indexed = 1, 916 + }, { 917 + .type = IIO_VOLTAGE, 918 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 919 + BIT(IIO_CHAN_INFO_SCALE), 920 + .address = RR_ADC_GPIO, 921 + .channel = 2, 922 + .indexed = 1, 923 + }, 924 + }; 925 + 926 + static int rradc_probe(struct platform_device *pdev) 927 + { 928 + struct device *dev = &pdev->dev; 929 + struct iio_dev *indio_dev; 930 + struct rradc_chip *chip; 931 + int ret, i, batt_id_delay; 932 + 933 + indio_dev = devm_iio_device_alloc(dev, sizeof(*chip)); 934 + if (!indio_dev) 935 + return -ENOMEM; 936 + 937 + chip = iio_priv(indio_dev); 938 + chip->regmap = dev_get_regmap(pdev->dev.parent, NULL); 939 + if (!chip->regmap) { 940 + dev_err(dev, "Couldn't get parent's regmap\n"); 941 + return -EINVAL; 942 + } 943 + 944 + chip->dev = dev; 945 + mutex_init(&chip->conversion_lock); 946 + 947 + ret = device_property_read_u32(dev, "reg", &chip->base); 948 + if (ret < 0) { 949 + dev_err(chip->dev, "Couldn't find reg address, ret = %d\n", 950 + ret); 951 + return ret; 952 + } 953 + 954 + batt_id_delay = -1; 955 + ret = device_property_read_u32(dev, "qcom,batt-id-delay-ms", 956 + &batt_id_delay); 957 + if (!ret) { 958 + for (i = 0; i < RRADC_BATT_ID_DELAY_MAX; i++) { 959 + if (batt_id_delay == batt_id_delays[i]) 960 + break; 961 + } 962 + if (i == RRADC_BATT_ID_DELAY_MAX) 963 + batt_id_delay = -1; 964 + } 965 + 966 + if (batt_id_delay >= 0) { 967 + batt_id_delay = FIELD_PREP(BATT_ID_SETTLE_MASK, batt_id_delay); 968 + ret = regmap_update_bits(chip->regmap, 969 + chip->base + RR_ADC_BATT_ID_CFG, 970 + batt_id_delay, batt_id_delay); 971 + if (ret < 0) { 972 + dev_err(chip->dev, 973 + "BATT_ID settling time config failed:%d\n", 974 + ret); 975 + } 976 + } 977 + 978 + /* Get the PMIC revision, we need it to handle some varying coefficients */ 979 + chip->pmic = qcom_pmic_get(chip->dev); 980 + if (IS_ERR(chip->pmic)) { 981 + dev_err(chip->dev, "Unable to get reference to PMIC device\n"); 982 + return PTR_ERR(chip->pmic); 983 + } 984 + 985 + switch (chip->pmic->subtype) { 986 + case PMI8998_SUBTYPE: 987 + indio_dev->name = "pmi8998-rradc"; 988 + break; 989 + case PM660_SUBTYPE: 990 + indio_dev->name = "pm660-rradc"; 991 + break; 992 + default: 993 + indio_dev->name = DRIVER_NAME; 994 + break; 995 + } 996 + indio_dev->modes = INDIO_DIRECT_MODE; 997 + indio_dev->info = &rradc_info; 998 + indio_dev->channels = rradc_iio_chans; 999 + indio_dev->num_channels = ARRAY_SIZE(rradc_iio_chans); 1000 + 1001 + return devm_iio_device_register(dev, indio_dev); 1002 + } 1003 + 1004 + static const struct of_device_id rradc_match_table[] = { 1005 + { .compatible = "qcom,pm660-rradc" }, 1006 + { .compatible = "qcom,pmi8998-rradc" }, 1007 + {} 1008 + }; 1009 + MODULE_DEVICE_TABLE(of, rradc_match_table); 1010 + 1011 + static struct platform_driver rradc_driver = { 1012 + .driver = { 1013 + .name = DRIVER_NAME, 1014 + .of_match_table = rradc_match_table, 1015 + }, 1016 + .probe = rradc_probe, 1017 + }; 1018 + module_platform_driver(rradc_driver); 1019 + 1020 + MODULE_DESCRIPTION("QCOM SPMI PMIC RR ADC driver"); 1021 + MODULE_AUTHOR("Caleb Connolly <caleb.connolly@linaro.org>"); 1022 + MODULE_LICENSE("GPL");
+1 -3
drivers/iio/adc/rzg2l_adc.c
··· 18 18 #include <linux/module.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/pm_runtime.h> 21 + #include <linux/property.h> 21 22 #include <linux/reset.h> 22 23 23 24 #define DRIVER_NAME "rzg2l-adc" ··· 261 260 const struct iio_chan_spec *chan, 262 261 char *label) 263 262 { 264 - if (chan->channel >= RZG2L_ADC_MAX_CHANNELS) 265 - return -EINVAL; 266 - 267 263 return sysfs_emit(label, "%s\n", rzg2l_adc_channel_name[chan->channel]); 268 264 } 269 265
+7 -8
drivers/iio/adc/sc27xx_adc.c
··· 579 579 return ret; 580 580 } 581 581 582 - static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, 583 - int channel, int scale, 584 - u32 *div_numerator, u32 *div_denominator) 582 + static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, int channel, int scale, 583 + struct u32_fract *fract) 585 584 { 586 585 u32 ratio; 587 586 588 587 ratio = data->var_data->get_ratio(channel, scale); 589 - *div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET; 590 - *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK; 588 + fract->numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET; 589 + fract->denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK; 591 590 } 592 591 593 592 static int adc_to_volt(struct sc27xx_adc_linear_graph *graph, ··· 614 615 static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel, 615 616 int scale, int raw_adc) 616 617 { 617 - u32 numerator, denominator; 618 + struct u32_fract fract; 618 619 u32 volt; 619 620 620 621 /* ··· 636 637 break; 637 638 } 638 639 639 - sc27xx_adc_volt_ratio(data, channel, scale, &numerator, &denominator); 640 + sc27xx_adc_volt_ratio(data, channel, scale, &fract); 640 641 641 - return DIV_ROUND_CLOSEST(volt * denominator, numerator); 642 + return DIV_ROUND_CLOSEST(volt * fract.denominator, fract.numerator); 642 643 } 643 644 644 645 static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data,
+1 -1
drivers/iio/adc/stm32-adc-core.c
··· 358 358 if ((status & priv->cfg->regs->eoc_msk[i] && 359 359 stm32_adc_eoc_enabled(priv, i)) || 360 360 (status & priv->cfg->regs->ovr_msk[i])) 361 - generic_handle_irq(irq_find_mapping(priv->domain, i)); 361 + generic_handle_domain_irq(priv->domain, i); 362 362 } 363 363 364 364 chained_irq_exit(chip, desc);
+6
drivers/iio/adc/stm32-adc.c
··· 876 876 int ret; 877 877 u32 val; 878 878 879 + if (!(stm32_adc_readl(adc, STM32H7_ADC_CR) & STM32H7_ADEN)) 880 + return; 881 + 879 882 /* Disable ADC and wait until it's effectively disabled */ 880 883 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADDIS); 881 884 ret = stm32_adc_readl_poll_timeout(STM32H7_ADC_CR, val, ··· 1018 1015 1019 1016 if (adc->cal.calibrated) 1020 1017 return true; 1018 + 1019 + /* ADC must be disabled for calibration */ 1020 + stm32h7_adc_disable(indio_dev); 1021 1021 1022 1022 /* 1023 1023 * Select calibration mode:
+29 -27
drivers/iio/adc/stx104.c
··· 51 51 */ 52 52 struct stx104_iio { 53 53 unsigned int chan_out_states[STX104_NUM_OUT_CHAN]; 54 - unsigned int base; 54 + void __iomem *base; 55 55 }; 56 56 57 57 /** ··· 64 64 struct stx104_gpio { 65 65 struct gpio_chip chip; 66 66 spinlock_t lock; 67 - unsigned int base; 67 + void __iomem *base; 68 68 unsigned int out_state; 69 69 }; 70 70 ··· 79 79 switch (mask) { 80 80 case IIO_CHAN_INFO_HARDWAREGAIN: 81 81 /* get gain configuration */ 82 - adc_config = inb(priv->base + 11); 82 + adc_config = ioread8(priv->base + 11); 83 83 gain = adc_config & 0x3; 84 84 85 85 *val = 1 << gain; ··· 91 91 } 92 92 93 93 /* select ADC channel */ 94 - outb(chan->channel | (chan->channel << 4), priv->base + 2); 94 + iowrite8(chan->channel | (chan->channel << 4), priv->base + 2); 95 95 96 96 /* trigger ADC sample capture and wait for completion */ 97 - outb(0, priv->base); 98 - while (inb(priv->base + 8) & BIT(7)); 97 + iowrite8(0, priv->base); 98 + while (ioread8(priv->base + 8) & BIT(7)); 99 99 100 - *val = inw(priv->base); 100 + *val = ioread16(priv->base); 101 101 return IIO_VAL_INT; 102 102 case IIO_CHAN_INFO_OFFSET: 103 103 /* get ADC bipolar/unipolar configuration */ 104 - adc_config = inb(priv->base + 11); 104 + adc_config = ioread8(priv->base + 11); 105 105 adbu = !(adc_config & BIT(2)); 106 106 107 107 *val = -32768 * adbu; 108 108 return IIO_VAL_INT; 109 109 case IIO_CHAN_INFO_SCALE: 110 110 /* get ADC bipolar/unipolar and gain configuration */ 111 - adc_config = inb(priv->base + 11); 111 + adc_config = ioread8(priv->base + 11); 112 112 adbu = !(adc_config & BIT(2)); 113 113 gain = adc_config & 0x3; 114 114 ··· 130 130 /* Only four gain states (x1, x2, x4, x8) */ 131 131 switch (val) { 132 132 case 1: 133 - outb(0, priv->base + 11); 133 + iowrite8(0, priv->base + 11); 134 134 break; 135 135 case 2: 136 - outb(1, priv->base + 11); 136 + iowrite8(1, priv->base + 11); 137 137 break; 138 138 case 4: 139 - outb(2, priv->base + 11); 139 + iowrite8(2, priv->base + 11); 140 140 break; 141 141 case 8: 142 - outb(3, priv->base + 11); 142 + iowrite8(3, priv->base + 11); 143 143 break; 144 144 default: 145 145 return -EINVAL; ··· 153 153 return -EINVAL; 154 154 155 155 priv->chan_out_states[chan->channel] = val; 156 - outw(val, priv->base + 4 + 2 * chan->channel); 156 + iowrite16(val, priv->base + 4 + 2 * chan->channel); 157 157 158 158 return 0; 159 159 } ··· 222 222 if (offset >= 4) 223 223 return -EINVAL; 224 224 225 - return !!(inb(stx104gpio->base) & BIT(offset)); 225 + return !!(ioread8(stx104gpio->base) & BIT(offset)); 226 226 } 227 227 228 228 static int stx104_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, ··· 230 230 { 231 231 struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip); 232 232 233 - *bits = inb(stx104gpio->base); 233 + *bits = ioread8(stx104gpio->base); 234 234 235 235 return 0; 236 236 } ··· 252 252 else 253 253 stx104gpio->out_state &= ~mask; 254 254 255 - outb(stx104gpio->out_state, stx104gpio->base); 255 + iowrite8(stx104gpio->out_state, stx104gpio->base); 256 256 257 257 spin_unlock_irqrestore(&stx104gpio->lock, flags); 258 258 } ··· 279 279 280 280 stx104gpio->out_state &= ~*mask; 281 281 stx104gpio->out_state |= *mask & *bits; 282 - outb(stx104gpio->out_state, stx104gpio->base); 282 + iowrite8(stx104gpio->out_state, stx104gpio->base); 283 283 284 284 spin_unlock_irqrestore(&stx104gpio->lock, flags); 285 285 } ··· 306 306 return -EBUSY; 307 307 } 308 308 309 + priv = iio_priv(indio_dev); 310 + priv->base = devm_ioport_map(dev, base[id], STX104_EXTENT); 311 + if (!priv->base) 312 + return -ENOMEM; 313 + 309 314 indio_dev->info = &stx104_info; 310 315 indio_dev->modes = INDIO_DIRECT_MODE; 311 316 312 317 /* determine if differential inputs */ 313 - if (inb(base[id] + 8) & BIT(5)) { 318 + if (ioread8(priv->base + 8) & BIT(5)) { 314 319 indio_dev->num_channels = ARRAY_SIZE(stx104_channels_diff); 315 320 indio_dev->channels = stx104_channels_diff; 316 321 } else { ··· 325 320 326 321 indio_dev->name = dev_name(dev); 327 322 328 - priv = iio_priv(indio_dev); 329 - priv->base = base[id]; 330 - 331 323 /* configure device for software trigger operation */ 332 - outb(0, base[id] + 9); 324 + iowrite8(0, priv->base + 9); 333 325 334 326 /* initialize gain setting to x1 */ 335 - outb(0, base[id] + 11); 327 + iowrite8(0, priv->base + 11); 336 328 337 329 /* initialize DAC output to 0V */ 338 - outw(0, base[id] + 4); 339 - outw(0, base[id] + 6); 330 + iowrite16(0, priv->base + 4); 331 + iowrite16(0, priv->base + 6); 340 332 341 333 stx104gpio->chip.label = dev_name(dev); 342 334 stx104gpio->chip.parent = dev; ··· 348 346 stx104gpio->chip.get_multiple = stx104_gpio_get_multiple; 349 347 stx104gpio->chip.set = stx104_gpio_set; 350 348 stx104gpio->chip.set_multiple = stx104_gpio_set_multiple; 351 - stx104gpio->base = base[id] + 3; 349 + stx104gpio->base = priv->base + 3; 352 350 stx104gpio->out_state = 0x0; 353 351 354 352 spin_lock_init(&stx104gpio->lock);
+1 -1
drivers/iio/adc/ti-adc0832.c
··· 36 36 */ 37 37 u8 data[24] __aligned(8); 38 38 39 - u8 tx_buf[2] ____cacheline_aligned; 39 + u8 tx_buf[2] __aligned(IIO_DMA_MINALIGN); 40 40 u8 rx_buf[2]; 41 41 }; 42 42
+2 -2
drivers/iio/adc/ti-adc084s021.c
··· 32 32 s64 ts __aligned(8); 33 33 } scan; 34 34 /* 35 - * DMA (thus cache coherency maintenance) requires the 35 + * DMA (thus cache coherency maintenance) may require the 36 36 * transfer buffers to live in their own cache line. 37 37 */ 38 - u16 tx_buf[4] ____cacheline_aligned; 38 + u16 tx_buf[4] __aligned(IIO_DMA_MINALIGN); 39 39 __be16 rx_buf[5]; /* First 16-bits are trash */ 40 40 }; 41 41
+2 -2
drivers/iio/adc/ti-adc108s102.c
··· 77 77 * tx_buf: 8 channel read commands, plus 1 dummy command 78 78 * rx_buf: 1 dummy response, 8 channel responses 79 79 */ 80 - __be16 rx_buf[9] ____cacheline_aligned; 81 - __be16 tx_buf[9] ____cacheline_aligned; 80 + __be16 rx_buf[9] __aligned(IIO_DMA_MINALIGN); 81 + __be16 tx_buf[9] __aligned(IIO_DMA_MINALIGN); 82 82 }; 83 83 84 84 #define ADC108S102_V_CHAN(index) \
+1 -1
drivers/iio/adc/ti-adc12138.c
··· 55 55 */ 56 56 __be16 data[20] __aligned(8); 57 57 58 - u8 tx_buf[2] ____cacheline_aligned; 58 + u8 tx_buf[2] __aligned(IIO_DMA_MINALIGN); 59 59 u8 rx_buf[2]; 60 60 }; 61 61
+1 -1
drivers/iio/adc/ti-adc128s052.c
··· 29 29 struct regulator *reg; 30 30 struct mutex lock; 31 31 32 - u8 buffer[2] ____cacheline_aligned; 32 + u8 buffer[2] __aligned(IIO_DMA_MINALIGN); 33 33 }; 34 34 35 35 static int adc128_adc_conversion(struct adc128 *adc, u8 channel)
+1 -1
drivers/iio/adc/ti-adc161s626.c
··· 71 71 u8 read_size; 72 72 u8 shift; 73 73 74 - u8 buffer[16] ____cacheline_aligned; 74 + u8 buffer[16] __aligned(IIO_DMA_MINALIGN); 75 75 }; 76 76 77 77 static int ti_adc_read_measurement(struct ti_adc_data *data,
+7 -1
drivers/iio/adc/ti-ads1015.c
··· 1098 1098 { 1099 1099 struct iio_dev *indio_dev = i2c_get_clientdata(client); 1100 1100 struct ads1015_data *data = iio_priv(indio_dev); 1101 + int ret; 1101 1102 1102 1103 iio_device_unregister(indio_dev); 1103 1104 ··· 1106 1105 pm_runtime_set_suspended(&client->dev); 1107 1106 1108 1107 /* power down single shot mode */ 1109 - return ads1015_set_conv_mode(data, ADS1015_SINGLESHOT); 1108 + ret = ads1015_set_conv_mode(data, ADS1015_SINGLESHOT); 1109 + if (ret) 1110 + dev_warn(&client->dev, "Failed to power down (%pe)\n", 1111 + ERR_PTR(ret)); 1112 + 1113 + return 0; 1110 1114 } 1111 1115 1112 1116 #ifdef CONFIG_PM
+1 -1
drivers/iio/adc/ti-ads124s08.c
··· 106 106 * timestamp is maintained. 107 107 */ 108 108 u32 buffer[ADS124S08_MAX_CHANNELS + sizeof(s64)/sizeof(u32)] __aligned(8); 109 - u8 data[5] ____cacheline_aligned; 109 + u8 data[5] __aligned(IIO_DMA_MINALIGN); 110 110 }; 111 111 112 112 #define ADS124S08_CHAN(index) \
+1 -1
drivers/iio/adc/ti-ads131e08.c
··· 105 105 s64 ts __aligned(8); 106 106 } tmp_buf; 107 107 108 - u8 tx_buf[3] ____cacheline_aligned; 108 + u8 tx_buf[3] __aligned(IIO_DMA_MINALIGN); 109 109 /* 110 110 * Add extra one padding byte to be able to access the last channel 111 111 * value using u32 pointer
+2 -2
drivers/iio/adc/ti-ads7950.c
··· 102 102 unsigned int gpio_cmd_settings_bitmask; 103 103 104 104 /* 105 - * DMA (thus cache coherency maintenance) requires the 105 + * DMA (thus cache coherency maintenance) may require the 106 106 * transfer buffers to live in their own cache lines. 107 107 */ 108 108 u16 rx_buf[TI_ADS7950_MAX_CHAN + 2 + TI_ADS7950_TIMESTAMP_SIZE] 109 - ____cacheline_aligned; 109 + __aligned(IIO_DMA_MINALIGN); 110 110 u16 tx_buf[TI_ADS7950_MAX_CHAN + 2]; 111 111 u16 single_tx; 112 112 u16 single_rx;
+1 -1
drivers/iio/adc/ti-ads8344.c
··· 28 28 */ 29 29 struct mutex lock; 30 30 31 - u8 tx_buf ____cacheline_aligned; 31 + u8 tx_buf __aligned(IIO_DMA_MINALIGN); 32 32 u8 rx_buf[3]; 33 33 }; 34 34
+1 -1
drivers/iio/adc/ti-ads8688.c
··· 71 71 union { 72 72 __be32 d32; 73 73 u8 d8[4]; 74 - } data[2] ____cacheline_aligned; 74 + } data[2] __aligned(IIO_DMA_MINALIGN); 75 75 }; 76 76 77 77 enum ads8688_id {
+2 -2
drivers/iio/adc/ti-tlc4541.c
··· 37 37 struct spi_message scan_single_msg; 38 38 39 39 /* 40 - * DMA (thus cache coherency maintenance) requires the 40 + * DMA (thus cache coherency maintenance) may require the 41 41 * transfer buffers to live in their own cache lines. 42 42 * 2 bytes data + 6 bytes padding + 8 bytes timestamp when 43 43 * call iio_push_to_buffers_with_timestamp. 44 44 */ 45 - __be16 rx_buf[8] ____cacheline_aligned; 45 + __be16 rx_buf[8] __aligned(IIO_DMA_MINALIGN); 46 46 }; 47 47 48 48 struct tlc4541_chip_info {
+1 -1
drivers/iio/adc/ti-tsc2046.c
··· 776 776 priv->spi = spi; 777 777 778 778 indio_dev->name = TI_TSC2046_NAME; 779 - indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED; 779 + indio_dev->modes = INDIO_DIRECT_MODE; 780 780 indio_dev->channels = dcfg->channels; 781 781 indio_dev->num_channels = dcfg->num_channels; 782 782 indio_dev->info = &tsc2046_adc_info;
+6 -9
drivers/iio/adc/vf610_adc.c
··· 5 5 * Copyright 2013 Freescale Semiconductor, Inc. 6 6 */ 7 7 8 + #include <linux/mod_devicetable.h> 8 9 #include <linux/module.h> 10 + #include <linux/property.h> 9 11 #include <linux/platform_device.h> 10 12 #include <linux/interrupt.h> 11 13 #include <linux/delay.h> ··· 16 14 #include <linux/io.h> 17 15 #include <linux/clk.h> 18 16 #include <linux/completion.h> 19 - #include <linux/of.h> 20 - #include <linux/of_irq.h> 21 17 #include <linux/regulator/consumer.h> 22 - #include <linux/of_platform.h> 23 18 #include <linux/err.h> 24 19 25 20 #include <linux/iio/iio.h> ··· 798 799 799 800 static int vf610_adc_probe(struct platform_device *pdev) 800 801 { 802 + struct device *dev = &pdev->dev; 801 803 struct vf610_adc *info; 802 804 struct iio_dev *indio_dev; 803 805 int irq; ··· 846 846 847 847 info->vref_uv = regulator_get_voltage(info->vref); 848 848 849 - of_property_read_u32_array(pdev->dev.of_node, "fsl,adck-max-frequency", 850 - info->max_adck_rate, 3); 849 + device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3); 851 850 852 - ret = of_property_read_u32(pdev->dev.of_node, "min-sample-time", 853 - &info->adc_feature.default_sample_time); 854 - if (ret) 855 - info->adc_feature.default_sample_time = DEFAULT_SAMPLE_TIME; 851 + info->adc_feature.default_sample_time = DEFAULT_SAMPLE_TIME; 852 + device_property_read_u32(dev, "min-sample-time", &info->adc_feature.default_sample_time); 856 853 857 854 platform_set_drvdata(pdev, indio_dev); 858 855
+33 -42
drivers/iio/adc/xilinx-xadc-core.c
··· 17 17 #include <linux/interrupt.h> 18 18 #include <linux/io.h> 19 19 #include <linux/kernel.h> 20 + #include <linux/mod_devicetable.h> 20 21 #include <linux/module.h> 21 - #include <linux/of.h> 22 22 #include <linux/overflow.h> 23 23 #include <linux/platform_device.h> 24 + #include <linux/property.h> 24 25 #include <linux/slab.h> 25 26 #include <linux/sysfs.h> 26 27 ··· 1183 1182 }; 1184 1183 MODULE_DEVICE_TABLE(of, xadc_of_match_table); 1185 1184 1186 - static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, 1187 - unsigned int *conf, int irq) 1185 + static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq) 1188 1186 { 1189 1187 struct device *dev = indio_dev->dev.parent; 1190 1188 struct xadc *xadc = iio_priv(indio_dev); 1191 1189 const struct iio_chan_spec *channel_templates; 1192 1190 struct iio_chan_spec *channels, *chan; 1193 - struct device_node *chan_node, *child; 1191 + struct fwnode_handle *chan_node, *child; 1194 1192 unsigned int max_channels; 1195 1193 unsigned int num_channels; 1196 1194 const char *external_mux; ··· 1200 1200 1201 1201 *conf = 0; 1202 1202 1203 - ret = of_property_read_string(np, "xlnx,external-mux", &external_mux); 1203 + ret = device_property_read_string(dev, "xlnx,external-mux", &external_mux); 1204 1204 if (ret < 0 || strcasecmp(external_mux, "none") == 0) 1205 1205 xadc->external_mux_mode = XADC_EXTERNAL_MUX_NONE; 1206 1206 else if (strcasecmp(external_mux, "single") == 0) ··· 1211 1211 return -EINVAL; 1212 1212 1213 1213 if (xadc->external_mux_mode != XADC_EXTERNAL_MUX_NONE) { 1214 - ret = of_property_read_u32(np, "xlnx,external-mux-channel", 1215 - &ext_mux_chan); 1214 + ret = device_property_read_u32(dev, "xlnx,external-mux-channel", &ext_mux_chan); 1216 1215 if (ret < 0) 1217 1216 return ret; 1218 1217 ··· 1246 1247 num_channels = 9; 1247 1248 chan = &channels[9]; 1248 1249 1249 - chan_node = of_get_child_by_name(np, "xlnx,channels"); 1250 - if (chan_node) { 1251 - for_each_child_of_node(chan_node, child) { 1252 - if (num_channels >= max_channels) { 1253 - of_node_put(child); 1254 - break; 1255 - } 1256 - 1257 - ret = of_property_read_u32(child, "reg", &reg); 1258 - if (ret || reg > 16) 1259 - continue; 1260 - 1261 - if (of_property_read_bool(child, "xlnx,bipolar")) 1262 - chan->scan_type.sign = 's'; 1263 - 1264 - if (reg == 0) { 1265 - chan->scan_index = 11; 1266 - chan->address = XADC_REG_VPVN; 1267 - } else { 1268 - chan->scan_index = 15 + reg; 1269 - chan->address = XADC_REG_VAUX(reg - 1); 1270 - } 1271 - num_channels++; 1272 - chan++; 1250 + chan_node = device_get_named_child_node(dev, "xlnx,channels"); 1251 + fwnode_for_each_child_node(chan_node, child) { 1252 + if (num_channels >= max_channels) { 1253 + fwnode_handle_put(child); 1254 + break; 1273 1255 } 1256 + 1257 + ret = fwnode_property_read_u32(child, "reg", &reg); 1258 + if (ret || reg > 16) 1259 + continue; 1260 + 1261 + if (fwnode_property_read_bool(child, "xlnx,bipolar")) 1262 + chan->scan_type.sign = 's'; 1263 + 1264 + if (reg == 0) { 1265 + chan->scan_index = 11; 1266 + chan->address = XADC_REG_VPVN; 1267 + } else { 1268 + chan->scan_index = 15 + reg; 1269 + chan->address = XADC_REG_VAUX(reg - 1); 1270 + } 1271 + num_channels++; 1272 + chan++; 1274 1273 } 1275 - of_node_put(chan_node); 1274 + fwnode_handle_put(chan_node); 1276 1275 1277 1276 /* No IRQ => no events */ 1278 1277 if (irq <= 0) { ··· 1313 1316 static int xadc_probe(struct platform_device *pdev) 1314 1317 { 1315 1318 struct device *dev = &pdev->dev; 1316 - const struct of_device_id *id; 1317 1319 const struct xadc_ops *ops; 1318 1320 struct iio_dev *indio_dev; 1319 1321 unsigned int bipolar_mask; ··· 1322 1326 int irq; 1323 1327 int i; 1324 1328 1325 - if (!dev->of_node) 1326 - return -ENODEV; 1327 - 1328 - id = of_match_node(xadc_of_match_table, dev->of_node); 1329 - if (!id) 1329 + ops = device_get_match_data(dev); 1330 + if (!ops) 1330 1331 return -EINVAL; 1331 - 1332 - ops = id->data; 1333 1332 1334 1333 irq = platform_get_irq_optional(pdev, 0); 1335 1334 if (irq < 0 && ··· 1336 1345 return -ENOMEM; 1337 1346 1338 1347 xadc = iio_priv(indio_dev); 1339 - xadc->ops = id->data; 1348 + xadc->ops = ops; 1340 1349 init_completion(&xadc->completion); 1341 1350 mutex_init(&xadc->mutex); 1342 1351 spin_lock_init(&xadc->lock); ··· 1350 1359 indio_dev->modes = INDIO_DIRECT_MODE; 1351 1360 indio_dev->info = &xadc_info; 1352 1361 1353 - ret = xadc_parse_dt(indio_dev, dev->of_node, &conf0, irq); 1362 + ret = xadc_parse_dt(indio_dev, &conf0, irq); 1354 1363 if (ret) 1355 1364 return ret; 1356 1365
+6 -6
drivers/iio/addac/ad74413r.c
··· 77 77 struct spi_transfer adc_samples_xfer[AD74413R_CHANNEL_MAX + 1]; 78 78 79 79 /* 80 - * DMA (thus cache coherency maintenance) requires the 80 + * DMA (thus cache coherency maintenance) may require the 81 81 * transfer buffers to live in their own cache lines. 82 82 */ 83 83 struct { 84 84 u8 rx_buf[AD74413R_FRAME_SIZE * AD74413R_CHANNEL_MAX]; 85 85 s64 timestamp; 86 - } adc_samples_buf ____cacheline_aligned; 86 + } adc_samples_buf __aligned(IIO_DMA_MINALIGN); 87 87 88 88 u8 adc_samples_tx_buf[AD74413R_FRAME_SIZE * AD74413R_CHANNEL_MAX]; 89 89 u8 reg_tx_buf[AD74413R_FRAME_SIZE]; ··· 284 284 struct ad74413r_state *st = gpiochip_get_data(chip); 285 285 unsigned long real_mask = 0; 286 286 unsigned long real_bits = 0; 287 - unsigned int offset = 0; 287 + unsigned int offset; 288 288 int ret; 289 289 290 - for_each_set_bit_from(offset, mask, chip->ngpio) { 290 + for_each_set_bit(offset, mask, chip->ngpio) { 291 291 unsigned int real_offset = st->gpo_gpio_offsets[offset]; 292 292 293 293 ret = ad74413r_set_gpo_config(st, real_offset, ··· 325 325 unsigned long *bits) 326 326 { 327 327 struct ad74413r_state *st = gpiochip_get_data(chip); 328 - unsigned int offset = 0; 328 + unsigned int offset; 329 329 unsigned int val; 330 330 int ret; 331 331 ··· 333 333 if (ret) 334 334 return ret; 335 335 336 - for_each_set_bit_from(offset, mask, chip->ngpio) { 336 + for_each_set_bit(offset, mask, chip->ngpio) { 337 337 unsigned int real_offset = st->comp_gpio_offsets[offset]; 338 338 339 339 __assign_bit(offset, bits, val & BIT(real_offset));
+2 -2
drivers/iio/amplifiers/ad8366.c
··· 45 45 enum ad8366_type type; 46 46 struct ad8366_info *info; 47 47 /* 48 - * DMA (thus cache coherency maintenance) requires the 48 + * DMA (thus cache coherency maintenance) may require the 49 49 * transfer buffers to live in their own cache lines. 50 50 */ 51 - unsigned char data[2] ____cacheline_aligned; 51 + unsigned char data[2] __aligned(IIO_DMA_MINALIGN); 52 52 }; 53 53 54 54 static struct ad8366_info ad8366_infos[] = {
+7 -1
drivers/iio/chemical/atlas-sensor.c
··· 726 726 { 727 727 struct iio_dev *indio_dev = i2c_get_clientdata(client); 728 728 struct atlas_data *data = iio_priv(indio_dev); 729 + int ret; 729 730 730 731 iio_device_unregister(indio_dev); 731 732 iio_triggered_buffer_cleanup(indio_dev); ··· 735 734 pm_runtime_disable(&client->dev); 736 735 pm_runtime_set_suspended(&client->dev); 737 736 738 - return atlas_set_powermode(data, 0); 737 + ret = atlas_set_powermode(data, 0); 738 + if (ret) 739 + dev_err(&client->dev, "Failed to power down device (%pe)\n", 740 + ERR_PTR(ret)); 741 + 742 + return 0; 739 743 } 740 744 741 745 static int atlas_runtime_suspend(struct device *dev)
+1 -1
drivers/iio/chemical/bme680_core.c
··· 638 638 comp_temp = bme680_compensate_temp(data, adc_temp); 639 639 /* 640 640 * val might be NULL if we're called by the read_press/read_humid 641 - * routine which is callled to get t_fine value used in 641 + * routine which is called to get t_fine value used in 642 642 * compensate_press/compensate_humid to get compensated 643 643 * pressure/humidity readings. 644 644 */
+8 -2
drivers/iio/chemical/ccs811.c
··· 536 536 { 537 537 struct iio_dev *indio_dev = i2c_get_clientdata(client); 538 538 struct ccs811_data *data = iio_priv(indio_dev); 539 + int ret; 539 540 540 541 iio_device_unregister(indio_dev); 541 542 iio_triggered_buffer_cleanup(indio_dev); 542 543 if (data->drdy_trig) 543 544 iio_trigger_unregister(data->drdy_trig); 544 545 545 - return i2c_smbus_write_byte_data(client, CCS811_MEAS_MODE, 546 - CCS811_MODE_IDLE); 546 + ret = i2c_smbus_write_byte_data(client, CCS811_MEAS_MODE, 547 + CCS811_MODE_IDLE); 548 + if (ret) 549 + dev_warn(&client->dev, "Failed to power down device (%pe)\n", 550 + ERR_PTR(ret)); 551 + 552 + return 0; 547 553 } 548 554 549 555 static const struct i2c_device_id ccs811_id[] = {
+1 -1
drivers/iio/chemical/sps30.c
··· 372 372 373 373 return devm_iio_device_register(dev, indio_dev); 374 374 } 375 - EXPORT_SYMBOL_GPL(sps30_probe); 375 + EXPORT_SYMBOL_NS_GPL(sps30_probe, IIO_SPS30); 376 376 377 377 MODULE_AUTHOR("Tomasz Duszynski <tduszyns@gmail.com>"); 378 378 MODULE_DESCRIPTION("Sensirion SPS30 particulate matter sensor driver");
+1
drivers/iio/chemical/sps30_i2c.c
··· 256 256 MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>"); 257 257 MODULE_DESCRIPTION("Sensirion SPS30 particulate matter sensor i2c driver"); 258 258 MODULE_LICENSE("GPL v2"); 259 + MODULE_IMPORT_NS(IIO_SPS30);
+1
drivers/iio/chemical/sps30_serial.c
··· 429 429 MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>"); 430 430 MODULE_DESCRIPTION("Sensirion SPS30 particulate matter sensor serial driver"); 431 431 MODULE_LICENSE("GPL v2"); 432 + MODULE_IMPORT_NS(IIO_SPS30);
+1
drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
··· 20 20 #include <linux/iio/triggered_buffer.h> 21 21 #include <linux/iio/trigger_consumer.h> 22 22 #include <linux/kernel.h> 23 + #include <linux/mod_devicetable.h> 23 24 #include <linux/module.h> 24 25 #include <linux/platform_data/cros_ec_commands.h> 25 26 #include <linux/platform_device.h>
+1
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
··· 16 16 #include <linux/iio/trigger_consumer.h> 17 17 #include <linux/iio/triggered_buffer.h> 18 18 #include <linux/kernel.h> 19 + #include <linux/mod_devicetable.h> 19 20 #include <linux/module.h> 20 21 #include <linux/platform_data/cros_ec_commands.h> 21 22 #include <linux/platform_data/cros_ec_proto.h>
+9 -21
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
··· 29 29 */ 30 30 #define CROS_EC_FIFO_SIZE (2048 * 2 / 3) 31 31 32 - static char *cros_ec_loc[] = { 33 - [MOTIONSENSE_LOC_BASE] = "base", 34 - [MOTIONSENSE_LOC_LID] = "lid", 35 - [MOTIONSENSE_LOC_MAX] = "unknown", 36 - }; 37 - 38 32 static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev, 39 33 u16 cmd_offset, u16 cmd, u32 *mask) 40 34 { ··· 281 287 indio_dev->name = pdev->name; 282 288 283 289 if (physical_device) { 290 + enum motionsensor_location loc; 291 + 284 292 state->param.cmd = MOTIONSENSE_CMD_INFO; 285 293 state->param.info.sensor_num = sensor_platform->sensor_num; 286 294 ret = cros_ec_motion_send_host_cmd(state, 0); ··· 291 295 return ret; 292 296 } 293 297 state->type = state->resp->info.type; 294 - state->loc = state->resp->info.location; 298 + loc = state->resp->info.location; 299 + if (loc == MOTIONSENSE_LOC_BASE) 300 + indio_dev->label = "accel-base"; 301 + else if (loc == MOTIONSENSE_LOC_LID) 302 + indio_dev->label = "accel-display"; 303 + else if (loc == MOTIONSENSE_LOC_CAMERA) 304 + indio_dev->label = "accel-camera"; 295 305 296 306 /* Set sign vector, only used for backward compatibility. */ 297 307 memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS); ··· 444 442 return snprintf(buf, PAGE_SIZE, "%d\n", st->param.info.sensor_num); 445 443 } 446 444 447 - static ssize_t cros_ec_sensors_loc(struct iio_dev *indio_dev, 448 - uintptr_t private, const struct iio_chan_spec *chan, 449 - char *buf) 450 - { 451 - struct cros_ec_sensors_core_state *st = iio_priv(indio_dev); 452 - 453 - return snprintf(buf, PAGE_SIZE, "%s\n", cros_ec_loc[st->loc]); 454 - } 455 - 456 445 const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[] = { 457 446 { 458 447 .name = "calibrate", ··· 454 461 .name = "id", 455 462 .shared = IIO_SHARED_BY_ALL, 456 463 .read = cros_ec_sensors_id 457 - }, 458 - { 459 - .name = "location", 460 - .shared = IIO_SHARED_BY_ALL, 461 - .read = cros_ec_sensors_loc 462 464 }, 463 465 { }, 464 466 };
+1 -2
drivers/iio/common/ssp_sensors/ssp.h
··· 221 221 struct iio_dev *sensor_devs[SSP_SENSOR_MAX]; 222 222 atomic_t enable_refcount; 223 223 224 - __le16 header_buffer[SSP_HEADER_BUFFER_SIZE / sizeof(__le16)] 225 - ____cacheline_aligned; 224 + __le16 header_buffer[SSP_HEADER_BUFFER_SIZE / sizeof(__le16)] __aligned(IIO_DMA_MINALIGN); 226 225 }; 227 226 228 227 void ssp_clean_pending_list(struct ssp_data *data);
+1 -1
drivers/iio/dac/Kconfig
··· 416 416 help 417 417 Driver for the Texas Instruments 418 418 DAC5571, DAC6571, DAC7571, DAC5574, DAC6574, DAC7574, DAC5573, 419 - DAC6573, DAC7573, DAC8571, DAC8574. 419 + DAC6573, DAC7573, DAC8571, DAC8574, DAC121C081. 420 420 421 421 If compiled as a module, it will be called ti-dac5571. 422 422
+2 -2
drivers/iio/dac/ad5064.c
··· 115 115 struct mutex lock; 116 116 117 117 /* 118 - * DMA (thus cache coherency maintenance) requires the 118 + * DMA (thus cache coherency maintenance) may require the 119 119 * transfer buffers to live in their own cache lines. 120 120 */ 121 121 union { 122 122 u8 i2c[3]; 123 123 __be32 spi; 124 - } data ____cacheline_aligned; 124 + } data __aligned(IIO_DMA_MINALIGN); 125 125 }; 126 126 127 127 enum ad5064_type {
+2 -2
drivers/iio/dac/ad5360.c
··· 79 79 struct mutex lock; 80 80 81 81 /* 82 - * DMA (thus cache coherency maintenance) requires the 82 + * DMA (thus cache coherency maintenance) may require the 83 83 * transfer buffers to live in their own cache lines. 84 84 */ 85 85 union { 86 86 __be32 d32; 87 87 u8 d8[4]; 88 - } data[2] ____cacheline_aligned; 88 + } data[2] __aligned(IIO_DMA_MINALIGN); 89 89 }; 90 90 91 91 enum ad5360_type {
+1 -3
drivers/iio/dac/ad5380.c
··· 36 36 * @channel_template: channel specification template 37 37 * @num_channels: number of channels 38 38 * @int_vref: internal vref in uV 39 - */ 40 - 39 + */ 41 40 struct ad5380_chip_info { 42 41 struct iio_chan_spec channel_template; 43 42 unsigned int num_channels; ··· 52 53 * @pwr_down: whether the chip is currently in power down mode 53 54 * @lock: lock to protect the data buffer during regmap ops 54 55 */ 55 - 56 56 struct ad5380_state { 57 57 struct regmap *regmap; 58 58 const struct ad5380_chip_info *chip_info;
+2 -2
drivers/iio/dac/ad5421.c
··· 72 72 struct mutex lock; 73 73 74 74 /* 75 - * DMA (thus cache coherency maintenance) requires the 75 + * DMA (thus cache coherency maintenance) may require the 76 76 * transfer buffers to live in their own cache lines. 77 77 */ 78 78 union { 79 79 __be32 d32; 80 80 u8 d8[4]; 81 - } data[2] ____cacheline_aligned; 81 + } data[2] __aligned(IIO_DMA_MINALIGN); 82 82 }; 83 83 84 84 static const struct iio_event_spec ad5421_current_event[] = {
+2 -2
drivers/iio/dac/ad5449.c
··· 68 68 uint16_t dac_cache[AD5449_MAX_CHANNELS]; 69 69 70 70 /* 71 - * DMA (thus cache coherency maintenance) requires the 71 + * DMA (thus cache coherency maintenance) may require the 72 72 * transfer buffers to live in their own cache lines. 73 73 */ 74 - __be16 data[2] ____cacheline_aligned; 74 + __be16 data[2] __aligned(IIO_DMA_MINALIGN); 75 75 }; 76 76 77 77 enum ad5449_type {
+1 -1
drivers/iio/dac/ad5504.c
··· 54 54 unsigned pwr_down_mask; 55 55 unsigned pwr_down_mode; 56 56 57 - __be16 data[2] ____cacheline_aligned; 57 + __be16 data[2] __aligned(IIO_DMA_MINALIGN); 58 58 }; 59 59 60 60 /*
+1 -1
drivers/iio/dac/ad5592r-base.c
··· 603 603 604 604 st->reg = devm_regulator_get_optional(dev, "vref"); 605 605 if (IS_ERR(st->reg)) { 606 - if ((PTR_ERR(st->reg) != -ENODEV) && dev->of_node) 606 + if ((PTR_ERR(st->reg) != -ENODEV) && dev_fwnode(dev)) 607 607 return PTR_ERR(st->reg); 608 608 609 609 st->reg = NULL;
+3 -1
drivers/iio/dac/ad5592r-base.h
··· 14 14 #include <linux/mutex.h> 15 15 #include <linux/gpio/driver.h> 16 16 17 + #include <linux/iio/iio.h> 18 + 17 19 struct device; 18 20 struct ad5592r_state; 19 21 ··· 67 65 u8 gpio_in; 68 66 u8 gpio_val; 69 67 70 - __be16 spi_msg ____cacheline_aligned; 68 + __be16 spi_msg __aligned(IIO_DMA_MINALIGN); 71 69 __be16 spi_msg_nop; 72 70 }; 73 71
+4 -2
drivers/iio/dac/ad5686.h
··· 13 13 #include <linux/mutex.h> 14 14 #include <linux/kernel.h> 15 15 16 + #include <linux/iio/iio.h> 17 + 16 18 #define AD5310_CMD(x) ((x) << 12) 17 19 18 20 #define AD5683_DATA(x) ((x) << 4) ··· 139 137 struct mutex lock; 140 138 141 139 /* 142 - * DMA (thus cache coherency maintenance) requires the 140 + * DMA (thus cache coherency maintenance) may require the 143 141 * transfer buffers to live in their own cache lines. 144 142 */ 145 143 ··· 147 145 __be32 d32; 148 146 __be16 d16; 149 147 u8 d8[4]; 150 - } data[3] ____cacheline_aligned; 148 + } data[3] __aligned(IIO_DMA_MINALIGN); 151 149 }; 152 150 153 151
+2 -2
drivers/iio/dac/ad5755.c
··· 189 189 struct mutex lock; 190 190 191 191 /* 192 - * DMA (thus cache coherency maintenance) requires the 192 + * DMA (thus cache coherency maintenance) may require the 193 193 * transfer buffers to live in their own cache lines. 194 194 */ 195 195 196 196 union { 197 197 __be32 d32; 198 198 u8 d8[4]; 199 - } data[2] ____cacheline_aligned; 199 + } data[2] __aligned(IIO_DMA_MINALIGN); 200 200 }; 201 201 202 202 enum ad5755_type {
+2 -2
drivers/iio/dac/ad5761.c
··· 70 70 enum ad5761_voltage_range range; 71 71 72 72 /* 73 - * DMA (thus cache coherency maintenance) requires the 73 + * DMA (thus cache coherency maintenance) may require the 74 74 * transfer buffers to live in their own cache lines. 75 75 */ 76 76 union { 77 77 __be32 d32; 78 78 u8 d8[4]; 79 - } data[3] ____cacheline_aligned; 79 + } data[3] __aligned(IIO_DMA_MINALIGN); 80 80 }; 81 81 82 82 static const struct ad5761_range_params ad5761_range_params[] = {
+2 -2
drivers/iio/dac/ad5764.c
··· 56 56 struct mutex lock; 57 57 58 58 /* 59 - * DMA (thus cache coherency maintenance) requires the 59 + * DMA (thus cache coherency maintenance) may require the 60 60 * transfer buffers to live in their own cache lines. 61 61 */ 62 62 union { 63 63 __be32 d32; 64 64 u8 d8[4]; 65 - } data[2] ____cacheline_aligned; 65 + } data[2] __aligned(IIO_DMA_MINALIGN); 66 66 }; 67 67 68 68 enum ad5764_type {
+1 -1
drivers/iio/dac/ad5766.c
··· 123 123 u32 d32; 124 124 u16 w16[2]; 125 125 u8 b8[4]; 126 - } data[3] ____cacheline_aligned; 126 + } data[3] __aligned(IIO_DMA_MINALIGN); 127 127 }; 128 128 129 129 struct ad5766_span_tbl {
+1 -1
drivers/iio/dac/ad5770r.c
··· 140 140 bool ch_pwr_down[AD5770R_MAX_CHANNELS]; 141 141 bool internal_ref; 142 142 bool external_res; 143 - u8 transf_buf[2] ____cacheline_aligned; 143 + u8 transf_buf[2] __aligned(IIO_DMA_MINALIGN); 144 144 }; 145 145 146 146 static const struct regmap_config ad5770r_spi_regmap_config = {
+1 -1
drivers/iio/dac/ad5791.c
··· 95 95 union { 96 96 __be32 d32; 97 97 u8 d8[4]; 98 - } data[3] ____cacheline_aligned; 98 + } data[3] __aligned(IIO_DMA_MINALIGN); 99 99 }; 100 100 101 101 enum ad5791_supported_device_ids {
+1 -1
drivers/iio/dac/ad7293.c
··· 144 144 struct regulator *reg_avdd; 145 145 struct regulator *reg_vdrive; 146 146 u8 page_select; 147 - u8 data[3] ____cacheline_aligned; 147 + u8 data[3] __aligned(IIO_DMA_MINALIGN); 148 148 }; 149 149 150 150 static int ad7293_page_select(struct ad7293_state *st, unsigned int reg)
+2 -2
drivers/iio/dac/ad7303.c
··· 44 44 45 45 struct mutex lock; 46 46 /* 47 - * DMA (thus cache coherency maintenance) requires the 47 + * DMA (thus cache coherency maintenance) may require the 48 48 * transfer buffers to live in their own cache lines. 49 49 */ 50 - __be16 data ____cacheline_aligned; 50 + __be16 data __aligned(IIO_DMA_MINALIGN); 51 51 }; 52 52 53 53 static int ad7303_write(struct ad7303_state *st, unsigned int chan,
+1 -1
drivers/iio/dac/ad8801.c
··· 26 26 struct regulator *vrefh_reg; 27 27 struct regulator *vrefl_reg; 28 28 29 - __be16 data ____cacheline_aligned; 29 + __be16 data __aligned(IIO_DMA_MINALIGN); 30 30 }; 31 31 32 32 static int ad8801_spi_write(struct ad8801_state *state,
+8 -6
drivers/iio/dac/cio-dac.c
··· 41 41 */ 42 42 struct cio_dac_iio { 43 43 int chan_out_states[CIO_DAC_NUM_CHAN]; 44 - unsigned int base; 44 + void __iomem *base; 45 45 }; 46 46 47 47 static int cio_dac_read_raw(struct iio_dev *indio_dev, ··· 71 71 return -EINVAL; 72 72 73 73 priv->chan_out_states[chan->channel] = val; 74 - outw(val, priv->base + chan_addr_offset); 74 + iowrite16(val, priv->base + chan_addr_offset); 75 75 76 76 return 0; 77 77 } ··· 105 105 return -EBUSY; 106 106 } 107 107 108 + priv = iio_priv(indio_dev); 109 + priv->base = devm_ioport_map(dev, base[id], CIO_DAC_EXTENT); 110 + if (!priv->base) 111 + return -ENOMEM; 112 + 108 113 indio_dev->info = &cio_dac_info; 109 114 indio_dev->modes = INDIO_DIRECT_MODE; 110 115 indio_dev->channels = cio_dac_channels; 111 116 indio_dev->num_channels = CIO_DAC_NUM_CHAN; 112 117 indio_dev->name = dev_name(dev); 113 118 114 - priv = iio_priv(indio_dev); 115 - priv->base = base[id]; 116 - 117 119 /* initialize DAC outputs to 0V */ 118 120 for (i = 0; i < 32; i += 2) 119 - outw(0, base[id] + i); 121 + iowrite16(0, priv->base + i); 120 122 121 123 return devm_iio_device_register(dev, indio_dev); 122 124 }
+2 -2
drivers/iio/dac/ltc2688.c
··· 91 91 struct mutex lock; 92 92 int vref; 93 93 /* 94 - * DMA (thus cache coherency maintenance) requires the 94 + * DMA (thus cache coherency maintenance) may require the 95 95 * transfer buffers to live in their own cache lines. 96 96 */ 97 - u8 tx_data[6] ____cacheline_aligned; 97 + u8 tx_data[6] __aligned(IIO_DMA_MINALIGN); 98 98 u8 rx_data[3]; 99 99 }; 100 100
+10 -3
drivers/iio/dac/mcp4922.c
··· 17 17 #include <linux/bitops.h> 18 18 19 19 #define MCP4922_NUM_CHANNELS 2 20 + #define MCP4921_NUM_CHANNELS 1 20 21 21 22 enum mcp4922_supported_device_ids { 22 23 ID_MCP4902, 23 24 ID_MCP4912, 25 + ID_MCP4921, 24 26 ID_MCP4922, 25 27 }; 26 28 ··· 31 29 unsigned int value[MCP4922_NUM_CHANNELS]; 32 30 unsigned int vref_mv; 33 31 struct regulator *vref_reg; 34 - u8 mosi[2] ____cacheline_aligned; 32 + u8 mosi[2] __aligned(IIO_DMA_MINALIGN); 35 33 }; 36 34 37 35 #define MCP4922_CHAN(chan, bits) { \ ··· 107 105 } 108 106 } 109 107 110 - static const struct iio_chan_spec mcp4922_channels[3][MCP4922_NUM_CHANNELS] = { 108 + static const struct iio_chan_spec mcp4922_channels[4][MCP4922_NUM_CHANNELS] = { 111 109 [ID_MCP4902] = { MCP4922_CHAN(0, 8), MCP4922_CHAN(1, 8) }, 112 110 [ID_MCP4912] = { MCP4922_CHAN(0, 10), MCP4922_CHAN(1, 10) }, 111 + [ID_MCP4921] = { MCP4922_CHAN(0, 12), {} }, 113 112 [ID_MCP4922] = { MCP4922_CHAN(0, 12), MCP4922_CHAN(1, 12) }, 114 113 }; 115 114 ··· 157 154 indio_dev->info = &mcp4922_info; 158 155 indio_dev->modes = INDIO_DIRECT_MODE; 159 156 indio_dev->channels = mcp4922_channels[id->driver_data]; 160 - indio_dev->num_channels = MCP4922_NUM_CHANNELS; 157 + if (id->driver_data == ID_MCP4921) 158 + indio_dev->num_channels = MCP4921_NUM_CHANNELS; 159 + else 160 + indio_dev->num_channels = MCP4922_NUM_CHANNELS; 161 161 indio_dev->name = id->name; 162 162 163 163 ret = iio_device_register(indio_dev); ··· 191 185 static const struct spi_device_id mcp4922_id[] = { 192 186 {"mcp4902", ID_MCP4902}, 193 187 {"mcp4912", ID_MCP4912}, 188 + {"mcp4921", ID_MCP4921}, 194 189 {"mcp4922", ID_MCP4922}, 195 190 {} 196 191 };
+4 -2
drivers/iio/dac/stm32-dac.c
··· 12 12 #include <linux/iio/iio.h> 13 13 #include <linux/kernel.h> 14 14 #include <linux/module.h> 15 + #include <linux/mod_devicetable.h> 16 + #include <linux/of.h> 15 17 #include <linux/platform_device.h> 16 18 #include <linux/pm_runtime.h> 19 + #include <linux/string_helpers.h> 17 20 18 21 #include "stm32-dac-core.h" 19 22 ··· 82 79 ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en); 83 80 mutex_unlock(&dac->lock); 84 81 if (ret < 0) { 85 - dev_err(&indio_dev->dev, "%s failed\n", en ? 86 - "Enable" : "Disable"); 82 + dev_err(&indio_dev->dev, "%s failed\n", str_enable_disable(en)); 87 83 goto err_put_pm; 88 84 } 89 85
+1 -1
drivers/iio/dac/ti-dac082s085.c
··· 55 55 bool powerdown; 56 56 u8 powerdown_mode; 57 57 u8 resolution; 58 - u8 buf[2] ____cacheline_aligned; 58 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 59 59 }; 60 60 61 61 #define WRITE_NOT_UPDATE(chan) (0x00 | (chan) << 6)
+4 -1
drivers/iio/dac/ti-dac5571.c
··· 13 13 * https://www.ti.com/lit/ds/symlink/dac5573.pdf 14 14 * https://www.ti.com/lit/ds/symlink/dac6573.pdf 15 15 * https://www.ti.com/lit/ds/symlink/dac7573.pdf 16 + * https://www.ti.com/lit/ds/symlink/dac121c081.pdf 16 17 */ 17 18 18 19 #include <linux/iio/iio.h> ··· 53 52 struct dac5571_spec const *spec; 54 53 int (*dac5571_cmd)(struct dac5571_data *data, int channel, u16 val); 55 54 int (*dac5571_pwrdwn)(struct dac5571_data *data, int channel, u8 pwrdwn); 56 - u8 buf[3] ____cacheline_aligned; 55 + u8 buf[3] __aligned(IIO_DMA_MINALIGN); 57 56 }; 58 57 59 58 #define DAC5571_POWERDOWN(mode) ((mode) + 1) ··· 403 402 {.compatible = "ti,dac5573", .data = (void *)quad_8bit}, 404 403 {.compatible = "ti,dac6573", .data = (void *)quad_10bit}, 405 404 {.compatible = "ti,dac7573", .data = (void *)quad_12bit}, 405 + {.compatible = "ti,dac121c081", .data = (void *)single_12bit}, 406 406 {} 407 407 }; 408 408 MODULE_DEVICE_TABLE(of, dac5571_of_id); ··· 418 416 {"dac5573", quad_8bit}, 419 417 {"dac6573", quad_10bit}, 420 418 {"dac7573", quad_12bit}, 419 + {"dac121c081", single_12bit}, 421 420 {} 422 421 }; 423 422 MODULE_DEVICE_TABLE(i2c, dac5571_id);
+1 -1
drivers/iio/dac/ti-dac7311.c
··· 52 52 bool powerdown; 53 53 u8 powerdown_mode; 54 54 u8 resolution; 55 - u8 buf[2] ____cacheline_aligned; 55 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 56 56 }; 57 57 58 58 static u8 ti_dac_get_power(struct ti_dac_chip *ti_dac, bool powerdown)
+2 -2
drivers/iio/dac/ti-dac7612.c
··· 31 31 struct mutex lock; 32 32 33 33 /* 34 - * DMA (thus cache coherency maintenance) requires the 34 + * DMA (thus cache coherency maintenance) may require the 35 35 * transfer buffers to live in their own cache lines. 36 36 */ 37 - uint8_t data[2] ____cacheline_aligned; 37 + uint8_t data[2] __aligned(IIO_DMA_MINALIGN); 38 38 }; 39 39 40 40 static int dac7612_cmd_single(struct dac7612 *priv, int channel, u16 val)
+1
drivers/iio/dac/vf610_dac.c
··· 10 10 #include <linux/interrupt.h> 11 11 #include <linux/io.h> 12 12 #include <linux/kernel.h> 13 + #include <linux/mod_devicetable.h> 13 14 #include <linux/module.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/regulator/consumer.h>
+3 -3
drivers/iio/frequency/ad9523.c
··· 287 287 struct mutex lock; 288 288 289 289 /* 290 - * DMA (thus cache coherency maintenance) requires the 291 - * transfer buffers to live in their own cache lines. 290 + * DMA (thus cache coherency maintenance) may require that 291 + * transfer buffers live in their own cache lines. 292 292 */ 293 293 union { 294 294 __be32 d32; 295 295 u8 d8[4]; 296 - } data[2] ____cacheline_aligned; 296 + } data[2] __aligned(IIO_DMA_MINALIGN); 297 297 }; 298 298 299 299 static int ad9523_read(struct iio_dev *indio_dev, unsigned int addr)
+3 -3
drivers/iio/frequency/adf4350.c
··· 56 56 */ 57 57 struct mutex lock; 58 58 /* 59 - * DMA (thus cache coherency maintenance) requires the 60 - * transfer buffers to live in their own cache lines. 59 + * DMA (thus cache coherency maintenance) may require that 60 + * transfer buffers live in their own cache lines. 61 61 */ 62 - __be32 val ____cacheline_aligned; 62 + __be32 val __aligned(IIO_DMA_MINALIGN); 63 63 }; 64 64 65 65 static struct adf4350_platform_data default_pdata = {
+1 -1
drivers/iio/frequency/adf4371.c
··· 175 175 unsigned int mod2; 176 176 unsigned int rf_div_sel; 177 177 unsigned int ref_div_factor; 178 - u8 buf[10] ____cacheline_aligned; 178 + u8 buf[10] __aligned(IIO_DMA_MINALIGN); 179 179 }; 180 180 181 181 static unsigned long long adf4371_pll_fract_n_get_rate(struct adf4371_state *st,
+1 -1
drivers/iio/frequency/admv1013.c
··· 100 100 unsigned int input_mode; 101 101 unsigned int quad_se_mode; 102 102 bool det_en; 103 - u8 data[3] ____cacheline_aligned; 103 + u8 data[3] __aligned(IIO_DMA_MINALIGN); 104 104 }; 105 105 106 106 static int __admv1013_spi_read(struct admv1013_state *st, unsigned int reg,
+1 -1
drivers/iio/frequency/admv1014.c
··· 127 127 unsigned int quad_se_mode; 128 128 unsigned int p1db_comp; 129 129 bool det_en; 130 - u8 data[3] ____cacheline_aligned; 130 + u8 data[3] __aligned(IIO_DMA_MINALIGN); 131 131 }; 132 132 133 133 static const int mixer_vgate_table[] = {106, 107, 108, 110, 111, 112, 113, 114,
+1 -1
drivers/iio/frequency/admv4420.c
··· 113 113 struct admv4420_n_counter n_counter; 114 114 enum admv4420_mux_sel mux_sel; 115 115 struct mutex lock; 116 - u8 transf_buf[4] ____cacheline_aligned; 116 + u8 transf_buf[4] __aligned(IIO_DMA_MINALIGN); 117 117 }; 118 118 119 119 static const struct regmap_config admv4420_regmap_config = {
+1 -1
drivers/iio/frequency/adrf6780.c
··· 86 86 bool uc_bias_en; 87 87 bool lo_sideband; 88 88 bool vdet_out_en; 89 - u8 data[3] ____cacheline_aligned; 89 + u8 data[3] __aligned(IIO_DMA_MINALIGN); 90 90 }; 91 91 92 92 static int __adrf6780_spi_read(struct adrf6780_state *st, unsigned int reg,
+1 -1
drivers/iio/gyro/adis16080.c
··· 45 45 const struct adis16080_chip_info *info; 46 46 struct mutex lock; 47 47 48 - __be16 buf ____cacheline_aligned; 48 + __be16 buf __aligned(IIO_DMA_MINALIGN); 49 49 }; 50 50 51 51 static int adis16080_read_sample(struct iio_dev *indio_dev,
+1 -1
drivers/iio/gyro/adis16130.c
··· 41 41 struct adis16130_state { 42 42 struct spi_device *us; 43 43 struct mutex buf_lock; 44 - u8 buf[4] ____cacheline_aligned; 44 + u8 buf[4] __aligned(IIO_DMA_MINALIGN); 45 45 }; 46 46 47 47 static int adis16130_spi_read(struct iio_dev *indio_dev, u8 reg_addr, u32 *val)
+1 -1
drivers/iio/gyro/adxrs450.c
··· 73 73 struct adxrs450_state { 74 74 struct spi_device *us; 75 75 struct mutex buf_lock; 76 - __be32 tx ____cacheline_aligned; 76 + __be32 tx __aligned(IIO_DMA_MINALIGN); 77 77 __be32 rx; 78 78 79 79 };
+1 -1
drivers/iio/gyro/bmg160_core.c
··· 766 766 return 0; 767 767 } 768 768 /* 769 - * We will expect the enable and disable to do operation in 769 + * We will expect the enable and disable to do operation 770 770 * in reverse order. This will happen here anyway as our 771 771 * resume operation uses sync mode runtime pm calls, the 772 772 * suspend operation will be delayed by autosuspend delay
+3 -3
drivers/iio/gyro/fxas21002c_core.c
··· 150 150 struct regulator *vddio; 151 151 152 152 /* 153 - * DMA (thus cache coherency maintenance) requires the 154 - * transfer buffers to live in their own cache lines. 153 + * DMA (thus cache coherency maintenance) may require the 154 + * transfer buffers live in their own cache lines. 155 155 */ 156 - s16 buffer[8] ____cacheline_aligned; 156 + s16 buffer[8] __aligned(IIO_DMA_MINALIGN); 157 157 }; 158 158 159 159 enum fxas21002c_channel_index {
+2 -12
drivers/iio/gyro/mpu3050-core.c
··· 1262 1262 1263 1263 return ret; 1264 1264 } 1265 - EXPORT_SYMBOL(mpu3050_common_probe); 1266 1265 1267 1266 void mpu3050_common_remove(struct device *dev) 1268 1267 { ··· 1277 1278 iio_device_unregister(indio_dev); 1278 1279 mpu3050_power_down(mpu3050); 1279 1280 } 1280 - EXPORT_SYMBOL(mpu3050_common_remove); 1281 1281 1282 - #ifdef CONFIG_PM 1283 1282 static int mpu3050_runtime_suspend(struct device *dev) 1284 1283 { 1285 1284 return mpu3050_power_down(iio_priv(dev_get_drvdata(dev))); ··· 1287 1290 { 1288 1291 return mpu3050_power_up(iio_priv(dev_get_drvdata(dev))); 1289 1292 } 1290 - #endif /* CONFIG_PM */ 1291 1293 1292 - const struct dev_pm_ops mpu3050_dev_pm_ops = { 1293 - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 1294 - pm_runtime_force_resume) 1295 - SET_RUNTIME_PM_OPS(mpu3050_runtime_suspend, 1296 - mpu3050_runtime_resume, NULL) 1297 - }; 1298 - EXPORT_SYMBOL(mpu3050_dev_pm_ops); 1299 - 1294 + DEFINE_RUNTIME_DEV_PM_OPS(mpu3050_dev_pm_ops, mpu3050_runtime_suspend, 1295 + mpu3050_runtime_resume, NULL); 1300 1296 MODULE_AUTHOR("Linus Walleij"); 1301 1297 MODULE_DESCRIPTION("MPU3050 gyroscope driver"); 1302 1298 MODULE_LICENSE("GPL");
+1 -1
drivers/iio/gyro/mpu3050-i2c.c
··· 116 116 .driver = { 117 117 .of_match_table = mpu3050_i2c_of_match, 118 118 .name = "mpu3050-i2c", 119 - .pm = &mpu3050_dev_pm_ops, 119 + .pm = pm_ptr(&mpu3050_dev_pm_ops), 120 120 }, 121 121 }; 122 122 module_i2c_driver(mpu3050_i2c_driver);
+1 -3
drivers/iio/health/afe4404.c
··· 591 591 iio_trigger_unregister(afe->trig); 592 592 593 593 ret = regulator_disable(afe->regulator); 594 - if (ret) { 594 + if (ret) 595 595 dev_err(afe->dev, "Unable to disable regulator\n"); 596 - return ret; 597 - } 598 596 599 597 return 0; 600 598 }
+1
drivers/iio/humidity/hts221_buffer.c
··· 11 11 #include <linux/device.h> 12 12 #include <linux/interrupt.h> 13 13 #include <linux/irqreturn.h> 14 + #include <linux/property.h> 14 15 #include <linux/regmap.h> 15 16 #include <linux/bitfield.h> 16 17
+5 -7
drivers/iio/humidity/hts221_core.c
··· 668 668 669 669 return devm_iio_device_register(hw->dev, iio_dev); 670 670 } 671 - EXPORT_SYMBOL(hts221_probe); 671 + EXPORT_SYMBOL_NS(hts221_probe, IIO_HTS221); 672 672 673 - static int __maybe_unused hts221_suspend(struct device *dev) 673 + static int hts221_suspend(struct device *dev) 674 674 { 675 675 struct iio_dev *iio_dev = dev_get_drvdata(dev); 676 676 struct hts221_hw *hw = iio_priv(iio_dev); ··· 680 680 FIELD_PREP(HTS221_ENABLE_MASK, false)); 681 681 } 682 682 683 - static int __maybe_unused hts221_resume(struct device *dev) 683 + static int hts221_resume(struct device *dev) 684 684 { 685 685 struct iio_dev *iio_dev = dev_get_drvdata(dev); 686 686 struct hts221_hw *hw = iio_priv(iio_dev); ··· 694 694 return err; 695 695 } 696 696 697 - const struct dev_pm_ops hts221_pm_ops = { 698 - SET_SYSTEM_SLEEP_PM_OPS(hts221_suspend, hts221_resume) 699 - }; 700 - EXPORT_SYMBOL(hts221_pm_ops); 697 + EXPORT_NS_SIMPLE_DEV_PM_OPS(hts221_pm_ops, hts221_suspend, hts221_resume, 698 + IIO_HTS221); 701 699 702 700 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 703 701 MODULE_DESCRIPTION("STMicroelectronics hts221 sensor driver");
+2 -1
drivers/iio/humidity/hts221_i2c.c
··· 62 62 static struct i2c_driver hts221_driver = { 63 63 .driver = { 64 64 .name = "hts221_i2c", 65 - .pm = &hts221_pm_ops, 65 + .pm = pm_sleep_ptr(&hts221_pm_ops), 66 66 .of_match_table = hts221_i2c_of_match, 67 67 .acpi_match_table = ACPI_PTR(hts221_acpi_match), 68 68 }, ··· 74 74 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 75 75 MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver"); 76 76 MODULE_LICENSE("GPL v2"); 77 + MODULE_IMPORT_NS(IIO_HTS221);
+2 -1
drivers/iio/humidity/hts221_spi.c
··· 55 55 static struct spi_driver hts221_driver = { 56 56 .driver = { 57 57 .name = "hts221_spi", 58 - .pm = &hts221_pm_ops, 58 + .pm = pm_sleep_ptr(&hts221_pm_ops), 59 59 .of_match_table = hts221_spi_of_match, 60 60 }, 61 61 .probe = hts221_spi_probe, ··· 66 66 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 67 67 MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver"); 68 68 MODULE_LICENSE("GPL v2"); 69 + MODULE_IMPORT_NS(IIO_HTS221);
+3 -3
drivers/iio/imu/bmi160/bmi160_core.c
··· 143 143 .reg_bits = 8, 144 144 .val_bits = 8, 145 145 }; 146 - EXPORT_SYMBOL(bmi160_regmap_config); 146 + EXPORT_SYMBOL_NS(bmi160_regmap_config, IIO_BMI160); 147 147 148 148 struct bmi160_regs { 149 149 u8 data; /* LSB byte register for X-axis */ ··· 633 633 BMI160_DRDY_INT_EN, enable_bit, 634 634 BMI160_NORMAL_WRITE_USLEEP); 635 635 } 636 - EXPORT_SYMBOL(bmi160_enable_irq); 636 + EXPORT_SYMBOL_NS(bmi160_enable_irq, IIO_BMI160); 637 637 638 638 static int bmi160_get_irq(struct fwnode_handle *fwnode, enum bmi160_int_pin *pin) 639 639 { ··· 884 884 885 885 return devm_iio_device_register(dev, indio_dev); 886 886 } 887 - EXPORT_SYMBOL_GPL(bmi160_core_probe); 887 + EXPORT_SYMBOL_NS_GPL(bmi160_core_probe, IIO_BMI160); 888 888 889 889 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); 890 890 MODULE_DESCRIPTION("Bosch BMI160 driver");
+1
drivers/iio/imu/bmi160/bmi160_i2c.c
··· 68 68 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); 69 69 MODULE_DESCRIPTION("BMI160 I2C driver"); 70 70 MODULE_LICENSE("GPL v2"); 71 + MODULE_IMPORT_NS(IIO_BMI160);
+1
drivers/iio/imu/bmi160/bmi160_spi.c
··· 65 65 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com"); 66 66 MODULE_DESCRIPTION("Bosch BMI160 SPI driver"); 67 67 MODULE_LICENSE("GPL v2"); 68 + MODULE_IMPORT_NS(IIO_BMI160);
+1 -1
drivers/iio/imu/fxos8700_core.c
··· 167 167 struct fxos8700_data { 168 168 struct regmap *regmap; 169 169 struct iio_trigger *trig; 170 - __be16 buf[FXOS8700_DATA_BUF_SIZE] ____cacheline_aligned; 170 + __be16 buf[FXOS8700_DATA_BUF_SIZE] __aligned(IIO_DMA_MINALIGN); 171 171 }; 172 172 173 173 /* Regmap info */
+1 -1
drivers/iio/imu/inv_icm42600/inv_icm42600.h
··· 141 141 struct inv_icm42600_suspended suspended; 142 142 struct iio_dev *indio_gyro; 143 143 struct iio_dev *indio_accel; 144 - uint8_t buffer[2] ____cacheline_aligned; 144 + uint8_t buffer[2] __aligned(IIO_DMA_MINALIGN); 145 145 struct inv_icm42600_fifo fifo; 146 146 struct { 147 147 int64_t gyro;
+1 -1
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h
··· 39 39 size_t accel; 40 40 size_t total; 41 41 } nb; 42 - uint8_t data[2080] ____cacheline_aligned; 42 + uint8_t data[2080] __aligned(IIO_DMA_MINALIGN); 43 43 }; 44 44 45 45 /* FIFO data packet */
+1 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 204 204 s32 magn_raw_to_gauss[3]; 205 205 struct iio_mount_matrix magn_orient; 206 206 unsigned int suspended_sensors; 207 - u8 data[INV_MPU6050_OUTPUT_DATA_SIZE] ____cacheline_aligned; 207 + u8 data[INV_MPU6050_OUTPUT_DATA_SIZE] __aligned(IIO_DMA_MINALIGN); 208 208 }; 209 209 210 210 /*register and associated bit definition*/
+7 -9
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 54 54 #include <linux/iio/sysfs.h> 55 55 #include <linux/interrupt.h> 56 56 #include <linux/irq.h> 57 + #include <linux/minmax.h> 57 58 #include <linux/pm.h> 58 59 #include <linux/property.h> 59 60 #include <linux/regmap.h> ··· 1616 1615 struct st_lsm6dsx_hw *hw = sensor->hw; 1617 1616 int err; 1618 1617 1619 - if (val < 1 || val > hw->settings->fifo_ops.max_size) 1620 - return -EINVAL; 1618 + val = clamp_val(val, 1, hw->settings->fifo_ops.max_size); 1621 1619 1622 1620 mutex_lock(&hw->conf_lock); 1623 1621 ··· 2289 2289 2290 2290 return 0; 2291 2291 } 2292 - EXPORT_SYMBOL(st_lsm6dsx_probe); 2292 + EXPORT_SYMBOL_NS(st_lsm6dsx_probe, IIO_LSM6DSX); 2293 2293 2294 - static int __maybe_unused st_lsm6dsx_suspend(struct device *dev) 2294 + static int st_lsm6dsx_suspend(struct device *dev) 2295 2295 { 2296 2296 struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2297 2297 struct st_lsm6dsx_sensor *sensor; ··· 2330 2330 return err; 2331 2331 } 2332 2332 2333 - static int __maybe_unused st_lsm6dsx_resume(struct device *dev) 2333 + static int st_lsm6dsx_resume(struct device *dev) 2334 2334 { 2335 2335 struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2336 2336 struct st_lsm6dsx_sensor *sensor; ··· 2366 2366 return err; 2367 2367 } 2368 2368 2369 - const struct dev_pm_ops st_lsm6dsx_pm_ops = { 2370 - SET_SYSTEM_SLEEP_PM_OPS(st_lsm6dsx_suspend, st_lsm6dsx_resume) 2371 - }; 2372 - EXPORT_SYMBOL(st_lsm6dsx_pm_ops); 2369 + EXPORT_NS_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops, st_lsm6dsx_suspend, 2370 + st_lsm6dsx_resume, IIO_LSM6DSX); 2373 2371 2374 2372 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 2375 2373 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+2 -1
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
··· 134 134 static struct i2c_driver st_lsm6dsx_driver = { 135 135 .driver = { 136 136 .name = "st_lsm6dsx_i2c", 137 - .pm = &st_lsm6dsx_pm_ops, 137 + .pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops), 138 138 .of_match_table = st_lsm6dsx_i2c_of_match, 139 139 }, 140 140 .probe = st_lsm6dsx_i2c_probe, ··· 146 146 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 147 147 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver"); 148 148 MODULE_LICENSE("GPL v2"); 149 + MODULE_IMPORT_NS(IIO_LSM6DSX);
+3 -2
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c
··· 6 6 */ 7 7 8 8 #include <linux/kernel.h> 9 + #include <linux/mod_devicetable.h> 9 10 #include <linux/module.h> 10 11 #include <linux/i3c/device.h> 11 12 #include <linux/i3c/master.h> 12 13 #include <linux/slab.h> 13 - #include <linux/of.h> 14 14 #include <linux/regmap.h> 15 15 16 16 #include "st_lsm6dsx.h" ··· 44 44 static struct i3c_driver st_lsm6dsx_driver = { 45 45 .driver = { 46 46 .name = "st_lsm6dsx_i3c", 47 - .pm = &st_lsm6dsx_pm_ops, 47 + .pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops), 48 48 }, 49 49 .probe = st_lsm6dsx_i3c_probe, 50 50 .id_table = st_lsm6dsx_i3c_ids, ··· 54 54 MODULE_AUTHOR("Vitor Soares <vitor.soares@synopsys.com>"); 55 55 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i3c driver"); 56 56 MODULE_LICENSE("GPL v2"); 57 + MODULE_IMPORT_NS(IIO_LSM6DSX);
+2 -1
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
··· 134 134 static struct spi_driver st_lsm6dsx_driver = { 135 135 .driver = { 136 136 .name = "st_lsm6dsx_spi", 137 - .pm = &st_lsm6dsx_pm_ops, 137 + .pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops), 138 138 .of_match_table = st_lsm6dsx_spi_of_match, 139 139 }, 140 140 .probe = st_lsm6dsx_spi_probe, ··· 146 146 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 147 147 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver"); 148 148 MODULE_LICENSE("GPL v2"); 149 + MODULE_IMPORT_NS(IIO_LSM6DSX);
+26 -40
drivers/iio/industrialio-buffer.c
··· 630 630 return ret; 631 631 } 632 632 633 - static ssize_t iio_buffer_read_length(struct device *dev, 634 - struct device_attribute *attr, 635 - char *buf) 633 + static ssize_t length_show(struct device *dev, struct device_attribute *attr, 634 + char *buf) 636 635 { 637 636 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 638 637 639 638 return sysfs_emit(buf, "%d\n", buffer->length); 640 639 } 641 640 642 - static ssize_t iio_buffer_write_length(struct device *dev, 643 - struct device_attribute *attr, 644 - const char *buf, size_t len) 641 + static ssize_t length_store(struct device *dev, struct device_attribute *attr, 642 + const char *buf, size_t len) 645 643 { 646 644 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 647 645 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; ··· 670 672 return ret ? ret : len; 671 673 } 672 674 673 - static ssize_t iio_buffer_show_enable(struct device *dev, 674 - struct device_attribute *attr, 675 - char *buf) 675 + static ssize_t enable_show(struct device *dev, struct device_attribute *attr, 676 + char *buf) 676 677 { 677 678 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 678 679 ··· 702 705 static int iio_compute_scan_bytes(struct iio_dev *indio_dev, 703 706 const unsigned long *mask, bool timestamp) 704 707 { 705 - unsigned bytes = 0; 708 + unsigned int bytes = 0; 706 709 int length, i, largest = 0; 707 710 708 711 /* How much space will the demuxed element take? */ ··· 931 934 * @l: list head used for management 932 935 */ 933 936 struct iio_demux_table { 934 - unsigned from; 935 - unsigned to; 936 - unsigned length; 937 + unsigned int from; 938 + unsigned int to; 939 + unsigned int length; 937 940 struct list_head l; 938 941 }; 939 942 ··· 971 974 struct iio_buffer *buffer) 972 975 { 973 976 int ret, in_ind = -1, out_ind, length; 974 - unsigned in_loc = 0, out_loc = 0; 977 + unsigned int in_loc = 0, out_loc = 0; 975 978 struct iio_demux_table *p = NULL; 976 979 977 980 /* Clear out any old demux */ ··· 1289 1292 iio_buffer_deactivate_all(indio_dev); 1290 1293 } 1291 1294 1292 - static ssize_t iio_buffer_store_enable(struct device *dev, 1293 - struct device_attribute *attr, 1294 - const char *buf, 1295 - size_t len) 1295 + static ssize_t enable_store(struct device *dev, struct device_attribute *attr, 1296 + const char *buf, size_t len) 1296 1297 { 1297 1298 int ret; 1298 1299 bool requested_state; ··· 1320 1325 return (ret < 0) ? ret : len; 1321 1326 } 1322 1327 1323 - static ssize_t iio_buffer_show_watermark(struct device *dev, 1324 - struct device_attribute *attr, 1325 - char *buf) 1328 + static ssize_t watermark_show(struct device *dev, struct device_attribute *attr, 1329 + char *buf) 1326 1330 { 1327 1331 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 1328 1332 1329 1333 return sysfs_emit(buf, "%u\n", buffer->watermark); 1330 1334 } 1331 1335 1332 - static ssize_t iio_buffer_store_watermark(struct device *dev, 1333 - struct device_attribute *attr, 1334 - const char *buf, 1335 - size_t len) 1336 + static ssize_t watermark_store(struct device *dev, 1337 + struct device_attribute *attr, 1338 + const char *buf, size_t len) 1336 1339 { 1337 1340 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1338 1341 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; ··· 1362 1369 return ret ? ret : len; 1363 1370 } 1364 1371 1365 - static ssize_t iio_dma_show_data_available(struct device *dev, 1366 - struct device_attribute *attr, 1367 - char *buf) 1372 + static ssize_t data_available_show(struct device *dev, 1373 + struct device_attribute *attr, char *buf) 1368 1374 { 1369 1375 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 1370 1376 ··· 1386 1394 } 1387 1395 } 1388 1396 1389 - static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length, 1390 - iio_buffer_write_length); 1391 - static struct device_attribute dev_attr_length_ro = __ATTR(length, 1392 - S_IRUGO, iio_buffer_read_length, NULL); 1393 - static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, 1394 - iio_buffer_show_enable, iio_buffer_store_enable); 1395 - static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR, 1396 - iio_buffer_show_watermark, iio_buffer_store_watermark); 1397 - static struct device_attribute dev_attr_watermark_ro = __ATTR(watermark, 1398 - S_IRUGO, iio_buffer_show_watermark, NULL); 1399 - static DEVICE_ATTR(data_available, S_IRUGO, 1400 - iio_dma_show_data_available, NULL); 1397 + static DEVICE_ATTR_RW(length); 1398 + static struct device_attribute dev_attr_length_ro = __ATTR_RO(length); 1399 + static DEVICE_ATTR_RW(enable); 1400 + static DEVICE_ATTR_RW(watermark); 1401 + static struct device_attribute dev_attr_watermark_ro = __ATTR_RO(watermark); 1402 + static DEVICE_ATTR_RO(data_available); 1401 1403 static DEVICE_ATTR_RO(direction); 1402 1404 1403 1405 /*
+22 -48
drivers/iio/industrialio-core.c
··· 334 334 } 335 335 EXPORT_SYMBOL(iio_get_time_ns); 336 336 337 - /** 338 - * iio_get_time_res() - utility function to get time stamp clock resolution in 339 - * nano seconds. 340 - * @indio_dev: device 341 - */ 342 - unsigned int iio_get_time_res(const struct iio_dev *indio_dev) 343 - { 344 - switch (iio_device_get_clock(indio_dev)) { 345 - case CLOCK_REALTIME: 346 - case CLOCK_MONOTONIC: 347 - case CLOCK_MONOTONIC_RAW: 348 - case CLOCK_BOOTTIME: 349 - case CLOCK_TAI: 350 - return hrtimer_resolution; 351 - case CLOCK_REALTIME_COARSE: 352 - case CLOCK_MONOTONIC_COARSE: 353 - return LOW_RES_NSEC; 354 - default: 355 - BUG(); 356 - } 357 - } 358 - EXPORT_SYMBOL(iio_get_time_res); 359 - 360 337 static int __init iio_init(void) 361 338 { 362 339 int ret; ··· 375 398 { 376 399 struct iio_dev *indio_dev = file->private_data; 377 400 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 378 - unsigned val = 0; 401 + unsigned int val = 0; 379 402 int ret; 380 403 381 404 if (*ppos > 0) ··· 405 428 { 406 429 struct iio_dev *indio_dev = file->private_data; 407 430 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 408 - unsigned reg, val; 431 + unsigned int reg, val; 409 432 char buf[80]; 410 433 int ret; 411 434 ··· 1104 1127 dev_attr->attr.name = name; 1105 1128 1106 1129 if (readfunc) { 1107 - dev_attr->attr.mode |= S_IRUGO; 1130 + dev_attr->attr.mode |= 0444; 1108 1131 dev_attr->show = readfunc; 1109 1132 } 1110 1133 1111 1134 if (writefunc) { 1112 - dev_attr->attr.mode |= S_IWUSR; 1135 + dev_attr->attr.mode |= 0200; 1113 1136 dev_attr->store = writefunc; 1114 1137 } 1115 1138 ··· 1383 1406 } 1384 1407 } 1385 1408 1386 - static ssize_t iio_show_dev_name(struct device *dev, 1387 - struct device_attribute *attr, 1388 - char *buf) 1409 + static ssize_t name_show(struct device *dev, struct device_attribute *attr, 1410 + char *buf) 1389 1411 { 1390 1412 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1391 1413 return sysfs_emit(buf, "%s\n", indio_dev->name); 1392 1414 } 1393 1415 1394 - static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL); 1416 + static DEVICE_ATTR_RO(name); 1395 1417 1396 - static ssize_t iio_show_dev_label(struct device *dev, 1397 - struct device_attribute *attr, 1398 - char *buf) 1418 + static ssize_t label_show(struct device *dev, struct device_attribute *attr, 1419 + char *buf) 1399 1420 { 1400 1421 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1401 1422 return sysfs_emit(buf, "%s\n", indio_dev->label); 1402 1423 } 1403 1424 1404 - static DEVICE_ATTR(label, S_IRUGO, iio_show_dev_label, NULL); 1425 + static DEVICE_ATTR_RO(label); 1405 1426 1406 - static ssize_t iio_show_timestamp_clock(struct device *dev, 1407 - struct device_attribute *attr, 1408 - char *buf) 1427 + static ssize_t current_timestamp_clock_show(struct device *dev, 1428 + struct device_attribute *attr, 1429 + char *buf) 1409 1430 { 1410 1431 const struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1411 1432 const clockid_t clk = iio_device_get_clock(indio_dev); ··· 1447 1472 return sz; 1448 1473 } 1449 1474 1450 - static ssize_t iio_store_timestamp_clock(struct device *dev, 1451 - struct device_attribute *attr, 1452 - const char *buf, size_t len) 1475 + static ssize_t current_timestamp_clock_store(struct device *dev, 1476 + struct device_attribute *attr, 1477 + const char *buf, size_t len) 1453 1478 { 1454 1479 clockid_t clk; 1455 1480 int ret; ··· 1497 1522 return 0; 1498 1523 } 1499 1524 1500 - static DEVICE_ATTR(current_timestamp_clock, S_IRUGO | S_IWUSR, 1501 - iio_show_timestamp_clock, iio_store_timestamp_clock); 1525 + static DEVICE_ATTR_RW(current_timestamp_clock); 1502 1526 1503 1527 static int iio_device_register_sysfs(struct iio_dev *indio_dev) 1504 1528 { ··· 1605 1631 1606 1632 iio_device_detach_buffers(indio_dev); 1607 1633 1608 - ida_simple_remove(&iio_ida, iio_dev_opaque->id); 1634 + ida_free(&iio_ida, iio_dev_opaque->id); 1609 1635 kfree(iio_dev_opaque); 1610 1636 } 1611 1637 ··· 1627 1653 1628 1654 alloc_size = sizeof(struct iio_dev_opaque); 1629 1655 if (sizeof_priv) { 1630 - alloc_size = ALIGN(alloc_size, IIO_ALIGN); 1656 + alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN); 1631 1657 alloc_size += sizeof_priv; 1632 1658 } 1633 1659 ··· 1637 1663 1638 1664 indio_dev = &iio_dev_opaque->indio_dev; 1639 1665 indio_dev->priv = (char *)iio_dev_opaque + 1640 - ALIGN(sizeof(struct iio_dev_opaque), IIO_ALIGN); 1666 + ALIGN(sizeof(struct iio_dev_opaque), IIO_DMA_MINALIGN); 1641 1667 1642 1668 indio_dev->dev.parent = parent; 1643 1669 indio_dev->dev.type = &iio_device_type; ··· 1647 1673 mutex_init(&iio_dev_opaque->info_exist_lock); 1648 1674 INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list); 1649 1675 1650 - iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL); 1676 + iio_dev_opaque->id = ida_alloc(&iio_ida, GFP_KERNEL); 1651 1677 if (iio_dev_opaque->id < 0) { 1652 1678 /* cannot use a dev_err as the name isn't available */ 1653 1679 pr_err("failed to get device id\n"); ··· 1656 1682 } 1657 1683 1658 1684 if (dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id)) { 1659 - ida_simple_remove(&iio_ida, iio_dev_opaque->id); 1685 + ida_free(&iio_ida, iio_dev_opaque->id); 1660 1686 kfree(iio_dev_opaque); 1661 1687 return NULL; 1662 1688 }
+1 -1
drivers/iio/industrialio-sw-device.c
··· 27 27 28 28 static 29 29 struct iio_sw_device_type *__iio_find_sw_device_type(const char *name, 30 - unsigned len) 30 + unsigned int len) 31 31 { 32 32 struct iio_sw_device_type *d = NULL, *iter; 33 33
+1 -1
drivers/iio/industrialio-sw-trigger.c
··· 27 27 28 28 static 29 29 struct iio_sw_trigger_type *__iio_find_sw_trigger_type(const char *name, 30 - unsigned len) 30 + unsigned int len) 31 31 { 32 32 struct iio_sw_trigger_type *t = NULL, *iter; 33 33
+17 -20
drivers/iio/industrialio-trigger.c
··· 37 37 static DEFINE_MUTEX(iio_trigger_list_lock); 38 38 39 39 /** 40 - * iio_trigger_read_name() - retrieve useful identifying name 40 + * name_show() - retrieve useful identifying name 41 41 * @dev: device associated with the iio_trigger 42 42 * @attr: pointer to the device_attribute structure that is 43 43 * being processed ··· 46 46 * Return: a negative number on failure or the number of written 47 47 * characters on success. 48 48 */ 49 - static ssize_t iio_trigger_read_name(struct device *dev, 50 - struct device_attribute *attr, 51 - char *buf) 49 + static ssize_t name_show(struct device *dev, struct device_attribute *attr, 50 + char *buf) 52 51 { 53 52 struct iio_trigger *trig = to_iio_trigger(dev); 54 53 return sysfs_emit(buf, "%s\n", trig->name); 55 54 } 56 55 57 - static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL); 56 + static DEVICE_ATTR_RO(name); 58 57 59 58 static struct attribute *iio_trig_dev_attrs[] = { 60 59 &dev_attr_name.attr, ··· 70 71 71 72 trig_info->owner = this_mod; 72 73 73 - trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL); 74 + trig_info->id = ida_alloc(&iio_trigger_ida, GFP_KERNEL); 74 75 if (trig_info->id < 0) 75 76 return trig_info->id; 76 77 ··· 97 98 mutex_unlock(&iio_trigger_list_lock); 98 99 device_del(&trig_info->dev); 99 100 error_unregister_id: 100 - ida_simple_remove(&iio_trigger_ida, trig_info->id); 101 + ida_free(&iio_trigger_ida, trig_info->id); 101 102 return ret; 102 103 } 103 104 EXPORT_SYMBOL(__iio_trigger_register); ··· 108 109 list_del(&trig_info->list); 109 110 mutex_unlock(&iio_trigger_list_lock); 110 111 111 - ida_simple_remove(&iio_trigger_ida, trig_info->id); 112 + ida_free(&iio_trigger_ida, trig_info->id); 112 113 /* Possible issue in here */ 113 114 device_del(&trig_info->dev); 114 115 } ··· 394 395 EXPORT_SYMBOL_GPL(iio_dealloc_pollfunc); 395 396 396 397 /** 397 - * iio_trigger_read_current() - trigger consumer sysfs query current trigger 398 + * current_trigger_show() - trigger consumer sysfs query current trigger 398 399 * @dev: device associated with an industrial I/O device 399 400 * @attr: pointer to the device_attribute structure that 400 401 * is being processed ··· 406 407 * Return: a negative number on failure, the number of characters written 407 408 * on success or 0 if no trigger is available 408 409 */ 409 - static ssize_t iio_trigger_read_current(struct device *dev, 410 - struct device_attribute *attr, 411 - char *buf) 410 + static ssize_t current_trigger_show(struct device *dev, 411 + struct device_attribute *attr, char *buf) 412 412 { 413 413 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 414 414 ··· 417 419 } 418 420 419 421 /** 420 - * iio_trigger_write_current() - trigger consumer sysfs set current trigger 422 + * current_trigger_store() - trigger consumer sysfs set current trigger 421 423 * @dev: device associated with an industrial I/O device 422 424 * @attr: device attribute that is being processed 423 425 * @buf: string buffer that holds the name of the trigger ··· 430 432 * Return: negative error code on failure or length of the buffer 431 433 * on success 432 434 */ 433 - static ssize_t iio_trigger_write_current(struct device *dev, 434 - struct device_attribute *attr, 435 - const char *buf, 436 - size_t len) 435 + static ssize_t current_trigger_store(struct device *dev, 436 + struct device_attribute *attr, 437 + const char *buf, size_t len) 437 438 { 438 439 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 439 440 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); ··· 491 494 return ret; 492 495 } 493 496 494 - static DEVICE_ATTR(current_trigger, S_IRUGO | S_IWUSR, 495 - iio_trigger_read_current, 496 - iio_trigger_write_current); 497 + static DEVICE_ATTR_RW(current_trigger); 497 498 498 499 static struct attribute *iio_trigger_consumer_attrs[] = { 499 500 &dev_attr_current_trigger.attr, ··· 575 580 trig->name = kvasprintf(GFP_KERNEL, fmt, vargs); 576 581 if (trig->name == NULL) 577 582 goto free_descs; 583 + 584 + INIT_LIST_HEAD(&trig->list); 578 585 579 586 trig->subirq_chip.name = trig->name; 580 587 trig->subirq_chip.irq_mask = &iio_trig_subirqmask;
+3 -4
drivers/iio/light/bh1780.c
··· 213 213 pm_runtime_put_noidle(&client->dev); 214 214 pm_runtime_disable(&client->dev); 215 215 ret = bh1780_write(bh1780, BH1780_REG_CONTROL, BH1780_POFF); 216 - if (ret < 0) { 217 - dev_err(&client->dev, "failed to power off\n"); 218 - return ret; 219 - } 216 + if (ret < 0) 217 + dev_err(&client->dev, "failed to power off (%pe)\n", 218 + ERR_PTR(ret)); 220 219 221 220 return 0; 222 221 }
+22
drivers/iio/light/cm32181.c
··· 460 460 return PTR_ERR(client); 461 461 } 462 462 463 + i2c_set_clientdata(client, indio_dev); 464 + 463 465 cm32181 = iio_priv(indio_dev); 464 466 cm32181->client = client; 465 467 cm32181->dev = dev; ··· 488 486 return 0; 489 487 } 490 488 489 + static int cm32181_suspend(struct device *dev) 490 + { 491 + struct i2c_client *client = to_i2c_client(dev); 492 + 493 + return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD, 494 + CM32181_CMD_ALS_DISABLE); 495 + } 496 + 497 + static int cm32181_resume(struct device *dev) 498 + { 499 + struct i2c_client *client = to_i2c_client(dev); 500 + struct cm32181_chip *cm32181 = iio_priv(dev_get_drvdata(dev)); 501 + 502 + return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD, 503 + cm32181->conf_regs[CM32181_REG_ADDR_CMD]); 504 + } 505 + 506 + DEFINE_SIMPLE_DEV_PM_OPS(cm32181_pm_ops, cm32181_suspend, cm32181_resume); 507 + 491 508 static const struct of_device_id cm32181_of_match[] = { 492 509 { .compatible = "capella,cm3218" }, 493 510 { .compatible = "capella,cm32181" }, ··· 527 506 .name = "cm32181", 528 507 .acpi_match_table = ACPI_PTR(cm32181_acpi_match), 529 508 .of_match_table = cm32181_of_match, 509 + .pm = pm_sleep_ptr(&cm32181_pm_ops), 530 510 }, 531 511 .probe_new = cm32181_probe, 532 512 };
+1 -2
drivers/iio/light/cros_ec_light_prox.c
··· 14 14 #include <linux/iio/triggered_buffer.h> 15 15 #include <linux/iio/trigger_consumer.h> 16 16 #include <linux/kernel.h> 17 + #include <linux/mod_devicetable.h> 17 18 #include <linux/module.h> 18 19 #include <linux/platform_data/cros_ec_commands.h> 19 20 #include <linux/platform_data/cros_ec_proto.h> ··· 189 188 190 189 indio_dev->info = &cros_ec_light_prox_info; 191 190 state = iio_priv(indio_dev); 192 - state->core.type = state->core.resp->info.type; 193 - state->core.loc = state->core.resp->info.location; 194 191 channel = state->channels; 195 192 196 193 /* Common part */
+3 -1
drivers/iio/light/isl29028.c
··· 646 646 pm_runtime_disable(&client->dev); 647 647 pm_runtime_set_suspended(&client->dev); 648 648 649 - return isl29028_clear_configure_reg(chip); 649 + isl29028_clear_configure_reg(chip); 650 + 651 + return 0; 650 652 } 651 653 652 654 static int __maybe_unused isl29028_suspend(struct device *dev)
+3 -1
drivers/iio/light/jsa1212.c
··· 380 380 381 381 iio_device_unregister(indio_dev); 382 382 383 - return jsa1212_power_off(data); 383 + jsa1212_power_off(data); 384 + 385 + return 0; 384 386 } 385 387 386 388 static int jsa1212_suspend(struct device *dev)
+1 -2
drivers/iio/light/opt3001.c
··· 808 808 if (ret < 0) { 809 809 dev_err(opt->dev, "failed to read register %02x\n", 810 810 OPT3001_CONFIGURATION); 811 - return ret; 811 + return 0; 812 812 } 813 813 814 814 reg = ret; ··· 819 819 if (ret < 0) { 820 820 dev_err(opt->dev, "failed to write register %02x\n", 821 821 OPT3001_CONFIGURATION); 822 - return ret; 823 822 } 824 823 825 824 return 0;
+7 -1
drivers/iio/light/pa12203001.c
··· 397 397 static int pa12203001_remove(struct i2c_client *client) 398 398 { 399 399 struct iio_dev *indio_dev = i2c_get_clientdata(client); 400 + int ret; 400 401 401 402 iio_device_unregister(indio_dev); 402 403 403 404 pm_runtime_disable(&client->dev); 404 405 pm_runtime_set_suspended(&client->dev); 405 406 406 - return pa12203001_power_chip(indio_dev, PA12203001_CHIP_DISABLE); 407 + ret = pa12203001_power_chip(indio_dev, PA12203001_CHIP_DISABLE); 408 + if (ret) 409 + dev_warn(&client->dev, "Failed to power down (%pe)\n", 410 + ERR_PTR(ret)); 411 + 412 + return 0; 407 413 } 408 414 409 415 #if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM)
+3 -1
drivers/iio/light/stk3310.c
··· 654 654 struct iio_dev *indio_dev = i2c_get_clientdata(client); 655 655 656 656 iio_device_unregister(indio_dev); 657 - return stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY); 657 + stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY); 658 + 659 + return 0; 658 660 } 659 661 660 662 static int stk3310_suspend(struct device *dev)
+3 -4
drivers/iio/light/tsl2563.c
··· 310 310 goto out; 311 311 312 312 if (!chip->int_enabled) { 313 - cancel_delayed_work(&chip->poweroff_work); 313 + cancel_delayed_work_sync(&chip->poweroff_work); 314 314 315 315 if (!tsl2563_get_power(chip)) { 316 316 ret = tsl2563_set_power(chip, 1); ··· 638 638 chip->intr &= ~0x30; 639 639 chip->intr |= 0x10; 640 640 /* ensure the chip is actually on */ 641 - cancel_delayed_work(&chip->poweroff_work); 641 + cancel_delayed_work_sync(&chip->poweroff_work); 642 642 if (!tsl2563_get_power(chip)) { 643 643 ret = tsl2563_set_power(chip, 1); 644 644 if (ret) ··· 803 803 804 804 iio_device_unregister(indio_dev); 805 805 if (!chip->int_enabled) 806 - cancel_delayed_work(&chip->poweroff_work); 806 + cancel_delayed_work_sync(&chip->poweroff_work); 807 807 /* Ensure that interrupts are disabled - then flush any bottom halves */ 808 808 chip->intr &= ~0x30; 809 809 i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, 810 810 chip->intr); 811 - flush_scheduled_work(); 812 811 tsl2563_set_power(chip, 0); 813 812 814 813 return 0;
+3 -1
drivers/iio/light/tsl2583.c
··· 883 883 pm_runtime_disable(&client->dev); 884 884 pm_runtime_set_suspended(&client->dev); 885 885 886 - return tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF); 886 + tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF); 887 + 888 + return 0; 887 889 } 888 890 889 891 static int __maybe_unused tsl2583_suspend(struct device *dev)
+7 -1
drivers/iio/light/us5182d.c
··· 907 907 static int us5182d_remove(struct i2c_client *client) 908 908 { 909 909 struct us5182d_data *data = iio_priv(i2c_get_clientdata(client)); 910 + int ret; 910 911 911 912 iio_device_unregister(i2c_get_clientdata(client)); 912 913 913 914 pm_runtime_disable(&client->dev); 914 915 pm_runtime_set_suspended(&client->dev); 915 916 916 - return us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN); 917 + ret = us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN); 918 + if (ret) 919 + dev_warn(&client->dev, "Failed to shut down (%pe)\n", 920 + ERR_PTR(ret)); 921 + 922 + return 0; 917 923 } 918 924 919 925 #if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM)
+7 -1
drivers/iio/light/vcnl4000.c
··· 1115 1115 { 1116 1116 struct iio_dev *indio_dev = i2c_get_clientdata(client); 1117 1117 struct vcnl4000_data *data = iio_priv(indio_dev); 1118 + int ret; 1118 1119 1119 1120 pm_runtime_dont_use_autosuspend(&client->dev); 1120 1121 pm_runtime_disable(&client->dev); 1121 1122 iio_device_unregister(indio_dev); 1122 1123 pm_runtime_set_suspended(&client->dev); 1123 1124 1124 - return data->chip_spec->set_power_state(data, false); 1125 + ret = data->chip_spec->set_power_state(data, false); 1126 + if (ret) 1127 + dev_warn(&client->dev, "Failed to power down (%pe)\n", 1128 + ERR_PTR(ret)); 1129 + 1130 + return 0; 1125 1131 } 1126 1132 1127 1133 static int __maybe_unused vcnl4000_runtime_suspend(struct device *dev)
+8 -2
drivers/iio/light/vcnl4035.c
··· 604 604 static int vcnl4035_remove(struct i2c_client *client) 605 605 { 606 606 struct iio_dev *indio_dev = i2c_get_clientdata(client); 607 + int ret; 607 608 608 609 pm_runtime_dont_use_autosuspend(&client->dev); 609 610 pm_runtime_disable(&client->dev); 610 611 iio_device_unregister(indio_dev); 611 612 pm_runtime_set_suspended(&client->dev); 612 613 613 - return vcnl4035_set_als_power_state(iio_priv(indio_dev), 614 - VCNL4035_MODE_ALS_DISABLE); 614 + ret = vcnl4035_set_als_power_state(iio_priv(indio_dev), 615 + VCNL4035_MODE_ALS_DISABLE); 616 + if (ret) 617 + dev_warn(&client->dev, "Failed to put device into standby (%pe)\n", 618 + ERR_PTR(ret)); 619 + 620 + return 0; 615 621 } 616 622 617 623 static int __maybe_unused vcnl4035_runtime_suspend(struct device *dev)
+1 -2
drivers/iio/magnetometer/bmc150_magn.c
··· 985 985 } 986 986 EXPORT_SYMBOL_NS(bmc150_magn_probe, IIO_BMC150_MAGN); 987 987 988 - int bmc150_magn_remove(struct device *dev) 988 + void bmc150_magn_remove(struct device *dev) 989 989 { 990 990 struct iio_dev *indio_dev = dev_get_drvdata(dev); 991 991 struct bmc150_magn_data *data = iio_priv(indio_dev); ··· 1008 1008 mutex_unlock(&data->mutex); 1009 1009 1010 1010 regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 1011 - return 0; 1012 1011 } 1013 1012 EXPORT_SYMBOL_NS(bmc150_magn_remove, IIO_BMC150_MAGN); 1014 1013
+1 -1
drivers/iio/magnetometer/bmc150_magn.h
··· 7 7 8 8 int bmc150_magn_probe(struct device *dev, struct regmap *regmap, int irq, 9 9 const char *name); 10 - int bmc150_magn_remove(struct device *dev); 10 + void bmc150_magn_remove(struct device *dev); 11 11 12 12 #endif /* _BMC150_MAGN_H_ */
+3 -1
drivers/iio/magnetometer/bmc150_magn_i2c.c
··· 36 36 37 37 static int bmc150_magn_i2c_remove(struct i2c_client *client) 38 38 { 39 - return bmc150_magn_remove(&client->dev); 39 + bmc150_magn_remove(&client->dev); 40 + 41 + return 0; 40 42 } 41 43 42 44 static const struct acpi_device_id bmc150_magn_acpi_match[] = {
+2 -2
drivers/iio/potentiometer/ad5110.c
··· 63 63 struct mutex lock; 64 64 const struct ad5110_cfg *cfg; 65 65 /* 66 - * DMA (thus cache coherency maintenance) requires the 66 + * DMA (thus cache coherency maintenance) may require the 67 67 * transfer buffers to live in their own cache lines. 68 68 */ 69 - u8 buf[2] ____cacheline_aligned; 69 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 70 70 }; 71 71 72 72 static const struct iio_chan_spec ad5110_channels[] = {
+1 -1
drivers/iio/potentiometer/ad5272.c
··· 50 50 struct i2c_client *client; 51 51 struct mutex lock; 52 52 const struct ad5272_cfg *cfg; 53 - u8 buf[2] ____cacheline_aligned; 53 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 54 54 }; 55 55 56 56 static const struct iio_chan_spec ad5272_channel = {
+1 -1
drivers/iio/potentiometer/max5481.c
··· 44 44 struct max5481_data { 45 45 struct spi_device *spi; 46 46 const struct max5481_cfg *cfg; 47 - u8 msg[3] ____cacheline_aligned; 47 + u8 msg[3] __aligned(IIO_DMA_MINALIGN); 48 48 }; 49 49 50 50 #define MAX5481_CHANNEL { \
+1 -1
drivers/iio/potentiometer/mcp41010.c
··· 60 60 const struct mcp41010_cfg *cfg; 61 61 struct mutex lock; /* Protect write sequences */ 62 62 unsigned int value[MCP41010_MAX_WIPERS]; /* Cache wiper values */ 63 - u8 buf[2] ____cacheline_aligned; 63 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 64 64 }; 65 65 66 66 #define MCP41010_CHANNEL(ch) { \
+1 -1
drivers/iio/potentiometer/mcp4131.c
··· 129 129 struct spi_device *spi; 130 130 const struct mcp4131_cfg *cfg; 131 131 struct mutex lock; 132 - u8 buf[2] ____cacheline_aligned; 132 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 133 133 }; 134 134 135 135 #define MCP4131_CHANNEL(ch) { \
+1 -1
drivers/iio/pressure/bmp280-core.c
··· 1136 1136 1137 1137 return devm_iio_device_register(dev, indio_dev); 1138 1138 } 1139 - EXPORT_SYMBOL(bmp280_common_probe); 1139 + EXPORT_SYMBOL_NS(bmp280_common_probe, IIO_BMP280); 1140 1140 1141 1141 static int bmp280_runtime_suspend(struct device *dev) 1142 1142 {
+1
drivers/iio/pressure/bmp280-i2c.c
··· 68 68 MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>"); 69 69 MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor"); 70 70 MODULE_LICENSE("GPL v2"); 71 + MODULE_IMPORT_NS(IIO_BMP280);
+2 -2
drivers/iio/pressure/bmp280-regmap.c
··· 39 39 .writeable_reg = bmp180_is_writeable_reg, 40 40 .volatile_reg = bmp180_is_volatile_reg, 41 41 }; 42 - EXPORT_SYMBOL(bmp180_regmap_config); 42 + EXPORT_SYMBOL_NS(bmp180_regmap_config, IIO_BMP280); 43 43 44 44 static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) 45 45 { ··· 82 82 .writeable_reg = bmp280_is_writeable_reg, 83 83 .volatile_reg = bmp280_is_volatile_reg, 84 84 }; 85 - EXPORT_SYMBOL(bmp280_regmap_config); 85 + EXPORT_SYMBOL_NS(bmp280_regmap_config, IIO_BMP280);
+1
drivers/iio/pressure/bmp280-spi.c
··· 118 118 119 119 MODULE_DESCRIPTION("BMP280 SPI bus driver"); 120 120 MODULE_LICENSE("GPL"); 121 + MODULE_IMPORT_NS(IIO_BMP280);
+1 -2
drivers/iio/pressure/cros_ec_baro.c
··· 14 14 #include <linux/iio/triggered_buffer.h> 15 15 #include <linux/iio/trigger_consumer.h> 16 16 #include <linux/kernel.h> 17 + #include <linux/mod_devicetable.h> 17 18 #include <linux/module.h> 18 19 #include <linux/slab.h> 19 20 #include <linux/platform_data/cros_ec_commands.h> ··· 146 145 147 146 indio_dev->info = &cros_ec_baro_info; 148 147 state = iio_priv(indio_dev); 149 - state->core.type = state->core.resp->info.type; 150 - state->core.loc = state->core.resp->info.location; 151 148 channel = state->channels; 152 149 /* Common part */ 153 150 channel->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
+1 -1
drivers/iio/pressure/dlhl60d.c
··· 47 47 struct dlh_info info; 48 48 bool use_interrupt; 49 49 struct completion completion; 50 - u8 rx_buf[DLH_NUM_READ_BYTES] ____cacheline_aligned; 50 + u8 rx_buf[DLH_NUM_READ_BYTES]; 51 51 }; 52 52 53 53 static struct dlh_info dlh_info_tbl[] = {
+1 -1
drivers/iio/proximity/as3935.c
··· 65 65 u8 chan; 66 66 s64 timestamp __aligned(8); 67 67 } scan; 68 - u8 buf[2] ____cacheline_aligned; 68 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 69 69 }; 70 70 71 71 static const struct iio_chan_spec as3935_channels[] = {
+1 -1
drivers/iio/proximity/ping.c
··· 173 173 174 174 /* 175 175 * read error code of laser ping sensor and give users chance to 176 - * figure out error by using dynamic debuggging 176 + * figure out error by using dynamic debugging 177 177 */ 178 178 if (data->cfg->laserping_error) { 179 179 if ((time_ns > 12500000) && (time_ns <= 13500000)) {
+4 -7
drivers/iio/proximity/srf04.c
··· 37 37 #include <linux/err.h> 38 38 #include <linux/gpio/consumer.h> 39 39 #include <linux/kernel.h> 40 + #include <linux/mod_devicetable.h> 40 41 #include <linux/module.h> 41 - #include <linux/of.h> 42 - #include <linux/of_device.h> 43 42 #include <linux/platform_device.h> 44 43 #include <linux/property.h> 45 44 #include <linux/sched.h> ··· 260 261 261 262 data = iio_priv(indio_dev); 262 263 data->dev = dev; 263 - data->cfg = of_match_device(of_srf04_match, dev)->data; 264 + data->cfg = device_get_match_data(dev); 264 265 265 266 mutex_init(&data->lock); 266 267 init_completion(&data->rising); ··· 288 289 return PTR_ERR(data->gpiod_power); 289 290 } 290 291 if (data->gpiod_power) { 291 - 292 - if (of_property_read_u32(dev->of_node, "startup-time-ms", 293 - &data->startup_time_ms)) 294 - data->startup_time_ms = 100; 292 + data->startup_time_ms = 100; 293 + device_property_read_u32(dev, "startup-time-ms", &data->startup_time_ms); 295 294 dev_dbg(dev, "using power gpio: startup-time-ms=%d\n", 296 295 data->startup_time_ms); 297 296 }
+1 -1
drivers/iio/proximity/srf08.c
··· 354 354 return -EINVAL; 355 355 356 356 for (i = 0; i < data->chip_info->num_sensitivity_avail; i++) 357 - if (val && (val == data->chip_info->sensitivity_avail[i])) { 357 + if (val == data->chip_info->sensitivity_avail[i]) { 358 358 regval = i; 359 359 break; 360 360 }
+73 -3
drivers/iio/proximity/sx9324.c
··· 52 52 #define SX9324_REG_CLK_SPRD 0x15 53 53 54 54 #define SX9324_REG_AFE_CTRL0 0x20 55 + #define SX9324_REG_AFE_CTRL0_RINT_SHIFT 6 56 + #define SX9324_REG_AFE_CTRL0_RINT_MASK \ 57 + GENMASK(SX9324_REG_AFE_CTRL0_RINT_SHIFT + 1, \ 58 + SX9324_REG_AFE_CTRL0_RINT_SHIFT) 59 + #define SX9324_REG_AFE_CTRL0_RINT_LOWEST 0x00 60 + #define SX9324_REG_AFE_CTRL0_CSIDLE_SHIFT 4 61 + #define SX9324_REG_AFE_CTRL0_CSIDLE_MASK \ 62 + GENMASK(SX9324_REG_AFE_CTRL0_CSIDLE_SHIFT + 1, \ 63 + SX9324_REG_AFE_CTRL0_CSIDLE_SHIFT) 64 + #define SX9324_REG_AFE_CTRL0_RINT_LOWEST 0x00 55 65 #define SX9324_REG_AFE_CTRL1 0x21 56 66 #define SX9324_REG_AFE_CTRL2 0x22 57 67 #define SX9324_REG_AFE_CTRL3 0x23 ··· 82 72 #define SX9324_REG_AFE_CTRL8 0x2c 83 73 #define SX9324_REG_AFE_CTRL8_RESERVED 0x10 84 74 #define SX9324_REG_AFE_CTRL8_RESFILTIN_4KOHM 0x02 75 + #define SX9324_REG_AFE_CTRL8_RESFILTIN_MASK GENMASK(3, 0) 85 76 #define SX9324_REG_AFE_CTRL9 0x2d 77 + #define SX9324_REG_AFE_CTRL9_AGAIN_MASK GENMASK(3, 0) 86 78 #define SX9324_REG_AFE_CTRL9_AGAIN_1 0x08 87 79 88 80 #define SX9324_REG_PROX_CTRL0 0x30 ··· 105 93 #define SX9324_REG_PROX_CTRL4_AVGNEGFILT_MASK GENMASK(5, 3) 106 94 #define SX9324_REG_PROX_CTRL4_AVGNEG_FILT_2 0x08 107 95 #define SX9324_REG_PROX_CTRL4_AVGPOSFILT_MASK GENMASK(2, 0) 108 - #define SX9324_REG_PROX_CTRL3_AVGPOS_FILT_256 0x04 96 + #define SX9324_REG_PROX_CTRL4_AVGPOS_FILT_256 0x04 109 97 #define SX9324_REG_PROX_CTRL5 0x35 110 98 #define SX9324_REG_PROX_CTRL5_HYST_MASK GENMASK(5, 4) 111 99 #define SX9324_REG_PROX_CTRL5_CLOSE_DEBOUNCE_MASK GENMASK(3, 2) ··· 794 782 */ 795 783 { SX9324_REG_GNRL_CTRL1, SX9324_REG_GNRL_CTRL1_PAUSECTRL }, 796 784 797 - { SX9324_REG_AFE_CTRL0, 0x00 }, 785 + { SX9324_REG_AFE_CTRL0, SX9324_REG_AFE_CTRL0_RINT_LOWEST }, 798 786 { SX9324_REG_AFE_CTRL3, 0x00 }, 799 787 { SX9324_REG_AFE_CTRL4, SX9324_REG_AFE_CTRL4_FREQ_83_33HZ | 800 788 SX9324_REG_AFE_CTRL4_RES_100 }, ··· 822 810 { SX9324_REG_PROX_CTRL3, SX9324_REG_PROX_CTRL3_AVGDEB_2SAMPLES | 823 811 SX9324_REG_PROX_CTRL3_AVGPOS_THRESH_16K }, 824 812 { SX9324_REG_PROX_CTRL4, SX9324_REG_PROX_CTRL4_AVGNEG_FILT_2 | 825 - SX9324_REG_PROX_CTRL3_AVGPOS_FILT_256 }, 813 + SX9324_REG_PROX_CTRL4_AVGPOS_FILT_256 }, 826 814 { SX9324_REG_PROX_CTRL5, 0x00 }, 827 815 { SX9324_REG_PROX_CTRL6, SX9324_REG_PROX_CTRL6_PROXTHRESH_32 }, 828 816 { SX9324_REG_PROX_CTRL7, SX9324_REG_PROX_CTRL6_PROXTHRESH_32 }, ··· 875 863 sx9324_get_default_reg(struct device *dev, int idx, 876 864 struct sx_common_reg_default *reg_def) 877 865 { 866 + static const char * const sx9324_rints[] = { "lowest", "low", "high", 867 + "highest" }; 868 + static const char * const sx9324_csidle[] = { "hi-z", "hi-z", "gnd", 869 + "vdd" }; 878 870 #define SX9324_PIN_DEF "semtech,ph0-pin" 879 871 #define SX9324_RESOLUTION_DEF "semtech,ph01-resolution" 880 872 #define SX9324_PROXRAW_DEF "semtech,ph01-proxraw-strength" ··· 886 870 char prop[] = SX9324_PROXRAW_DEF; 887 871 u32 start = 0, raw = 0, pos = 0; 888 872 int ret, count, ph, pin; 873 + const char *res; 889 874 890 875 memcpy(reg_def, &sx9324_default_regs[idx], sizeof(*reg_def)); 891 876 switch (reg_def->reg) { ··· 910 893 SX9324_REG_AFE_PH0_PIN_MASK(pin); 911 894 reg_def->def = raw; 912 895 break; 896 + case SX9324_REG_AFE_CTRL0: 897 + ret = device_property_read_string(dev, 898 + "semtech,cs-idle-sleep", &res); 899 + if (!ret) 900 + ret = match_string(sx9324_csidle, ARRAY_SIZE(sx9324_csidle), res); 901 + if (ret >= 0) { 902 + reg_def->def &= ~SX9324_REG_AFE_CTRL0_CSIDLE_MASK; 903 + reg_def->def |= ret << SX9324_REG_AFE_CTRL0_CSIDLE_SHIFT; 904 + } 905 + 906 + ret = device_property_read_string(dev, 907 + "semtech,int-comp-resistor", &res); 908 + if (ret) 909 + break; 910 + ret = match_string(sx9324_rints, ARRAY_SIZE(sx9324_rints), res); 911 + if (ret < 0) 912 + break; 913 + reg_def->def &= ~SX9324_REG_AFE_CTRL0_RINT_MASK; 914 + reg_def->def |= ret << SX9324_REG_AFE_CTRL0_RINT_SHIFT; 915 + break; 913 916 case SX9324_REG_AFE_CTRL4: 914 917 case SX9324_REG_AFE_CTRL7: 915 918 if (reg_def->reg == SX9324_REG_AFE_CTRL4) ··· 949 912 reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL4_RESOLUTION_MASK, 950 913 raw); 951 914 break; 915 + case SX9324_REG_AFE_CTRL8: 916 + ret = device_property_read_u32(dev, 917 + "semtech,input-precharge-resistor-ohms", 918 + &raw); 919 + if (ret) 920 + break; 921 + 922 + reg_def->def &= ~SX9324_REG_AFE_CTRL8_RESFILTIN_MASK; 923 + reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL8_RESFILTIN_MASK, 924 + raw / 2000); 925 + break; 926 + 927 + case SX9324_REG_AFE_CTRL9: 928 + ret = device_property_read_u32(dev, 929 + "semtech,input-analog-gain", &raw); 930 + if (ret) 931 + break; 932 + /* 933 + * The analog gain has the following setting: 934 + * +---------+----------------+----------------+ 935 + * | dt(raw) | physical value | register value | 936 + * +---------+----------------+----------------+ 937 + * | 0 | x1.247 | 6 | 938 + * | 1 | x1 | 8 | 939 + * | 2 | x0.768 | 11 | 940 + * | 3 | x0.552 | 15 | 941 + * +---------+----------------+----------------+ 942 + */ 943 + reg_def->def &= ~SX9324_REG_AFE_CTRL9_AGAIN_MASK; 944 + reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL9_AGAIN_MASK, 945 + 6 + raw * (raw + 3) / 2); 946 + break; 947 + 952 948 case SX9324_REG_ADV_CTRL5: 953 949 ret = device_property_read_u32(dev, "semtech,startup-sensor", 954 950 &start);
+14 -1
drivers/iio/proximity/sx9360.c
··· 51 51 #define SX9360_REG_GNRL_REG_2_FREQ(_r) (SX9360_FOSC_HZ / ((_r) * 8192)) 52 52 53 53 #define SX9360_REG_AFE_CTRL1 0x21 54 + #define SX9360_REG_AFE_CTRL1_RESFILTIN_MASK GENMASK(3, 0) 55 + #define SX9360_REG_AFE_CTRL1_RESFILTIN_0OHMS 0 54 56 #define SX9360_REG_AFE_PARAM0_PHR 0x22 55 57 #define SX9360_REG_AFE_PARAM1_PHR 0x23 56 58 #define SX9360_REG_AFE_PARAM0_PHM 0x24 ··· 673 671 { SX9360_REG_GNRL_CTRL1, 0x00 }, 674 672 { SX9360_REG_GNRL_CTRL2, SX9360_REG_GNRL_CTRL2_PERIOD_102MS }, 675 673 676 - { SX9360_REG_AFE_CTRL1, 0x00 }, 674 + { SX9360_REG_AFE_CTRL1, SX9360_REG_AFE_CTRL1_RESFILTIN_0OHMS }, 677 675 { SX9360_REG_AFE_PARAM0_PHR, SX9360_REG_AFE_PARAM0_RSVD | 678 676 SX9360_REG_AFE_PARAM0_RESOLUTION_128 }, 679 677 { SX9360_REG_AFE_PARAM1_PHR, SX9360_REG_AFE_PARAM1_AGAIN_PHM_6PF | ··· 724 722 725 723 memcpy(reg_def, &sx9360_default_regs[idx], sizeof(*reg_def)); 726 724 switch (reg_def->reg) { 725 + case SX9360_REG_AFE_CTRL1: 726 + ret = device_property_read_u32(dev, 727 + "semtech,input-precharge-resistor-ohms", 728 + &raw); 729 + if (ret) 730 + break; 731 + 732 + reg_def->def &= ~SX9360_REG_AFE_CTRL1_RESFILTIN_MASK; 733 + reg_def->def |= FIELD_PREP(SX9360_REG_AFE_CTRL1_RESFILTIN_MASK, 734 + raw / 2000); 735 + break; 727 736 case SX9360_REG_AFE_PARAM0_PHR: 728 737 case SX9360_REG_AFE_PARAM0_PHM: 729 738 ret = device_property_read_u32(dev, "semtech,resolution", &raw);
+2 -2
drivers/iio/proximity/vcnl3020.c
··· 71 71 * @dev: vcnl3020 device. 72 72 * @rev: revision id. 73 73 * @lock: lock for protecting access to device hardware registers. 74 - * @buf: DMA safe __be16 buffer. 74 + * @buf: __be16 buffer. 75 75 */ 76 76 struct vcnl3020_data { 77 77 struct regmap *regmap; 78 78 struct device *dev; 79 79 u8 rev; 80 80 struct mutex lock; 81 - __be16 buf ____cacheline_aligned; 81 + __be16 buf; 82 82 }; 83 83 84 84 /**
+54 -1
drivers/iio/proximity/vl53l0x-i2c.c
··· 15 15 */ 16 16 17 17 #include <linux/delay.h> 18 + #include <linux/gpio/consumer.h> 18 19 #include <linux/i2c.h> 20 + #include <linux/irq.h> 19 21 #include <linux/interrupt.h> 20 22 #include <linux/module.h> 21 23 ··· 44 42 struct vl53l0x_data { 45 43 struct i2c_client *client; 46 44 struct completion completion; 45 + struct regulator *vdd_supply; 46 + struct gpio_desc *reset_gpio; 47 47 }; 48 48 49 49 static irqreturn_t vl53l0x_handle_irq(int irq, void *priv) ··· 61 57 static int vl53l0x_configure_irq(struct i2c_client *client, 62 58 struct iio_dev *indio_dev) 63 59 { 60 + int irq_flags = irq_get_trigger_type(client->irq); 64 61 struct vl53l0x_data *data = iio_priv(indio_dev); 65 62 int ret; 66 63 64 + if (!irq_flags) 65 + irq_flags = IRQF_TRIGGER_FALLING; 66 + 67 67 ret = devm_request_irq(&client->dev, client->irq, vl53l0x_handle_irq, 68 - IRQF_TRIGGER_FALLING, indio_dev->name, indio_dev); 68 + irq_flags, indio_dev->name, indio_dev); 69 69 if (ret) { 70 70 dev_err(&client->dev, "devm_request_irq error: %d\n", ret); 71 71 return ret; ··· 194 186 .read_raw = vl53l0x_read_raw, 195 187 }; 196 188 189 + static void vl53l0x_power_off(void *_data) 190 + { 191 + struct vl53l0x_data *data = _data; 192 + 193 + gpiod_set_value_cansleep(data->reset_gpio, 1); 194 + 195 + regulator_disable(data->vdd_supply); 196 + } 197 + 198 + static int vl53l0x_power_on(struct vl53l0x_data *data) 199 + { 200 + int ret; 201 + 202 + ret = regulator_enable(data->vdd_supply); 203 + if (ret) 204 + return ret; 205 + 206 + gpiod_set_value_cansleep(data->reset_gpio, 0); 207 + 208 + usleep_range(3200, 5000); 209 + 210 + return 0; 211 + } 212 + 197 213 static int vl53l0x_probe(struct i2c_client *client) 198 214 { 199 215 struct vl53l0x_data *data; 200 216 struct iio_dev *indio_dev; 217 + int error; 201 218 202 219 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 203 220 if (!indio_dev) ··· 236 203 I2C_FUNC_SMBUS_READ_I2C_BLOCK | 237 204 I2C_FUNC_SMBUS_BYTE_DATA)) 238 205 return -EOPNOTSUPP; 206 + 207 + data->vdd_supply = devm_regulator_get(&client->dev, "vdd"); 208 + if (IS_ERR(data->vdd_supply)) 209 + return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply), 210 + "Unable to get VDD regulator\n"); 211 + 212 + data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); 213 + if (IS_ERR(data->reset_gpio)) 214 + return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio), 215 + "Cannot get reset GPIO\n"); 216 + 217 + error = vl53l0x_power_on(data); 218 + if (error) 219 + return dev_err_probe(&client->dev, error, 220 + "Failed to power on the chip\n"); 221 + 222 + error = devm_add_action_or_reset(&client->dev, vl53l0x_power_off, data); 223 + if (error) 224 + return dev_err_probe(&client->dev, error, 225 + "Failed to install poweroff action\n"); 239 226 240 227 indio_dev->name = "vl53l0x"; 241 228 indio_dev->info = &vl53l0x_info;
+1 -1
drivers/iio/resolver/ad2s1200.c
··· 41 41 struct spi_device *sdev; 42 42 struct gpio_desc *sample; 43 43 struct gpio_desc *rdvel; 44 - __be16 rx ____cacheline_aligned; 44 + __be16 rx __aligned(IIO_DMA_MINALIGN); 45 45 }; 46 46 47 47 static int ad2s1200_read_raw(struct iio_dev *indio_dev,
+1 -1
drivers/iio/resolver/ad2s90.c
··· 24 24 struct ad2s90_state { 25 25 struct mutex lock; /* lock to protect rx buffer */ 26 26 struct spi_device *sdev; 27 - u8 rx[2] ____cacheline_aligned; 27 + u8 rx[2] __aligned(IIO_DMA_MINALIGN); 28 28 }; 29 29 30 30 static int ad2s90_read_raw(struct iio_dev *indio_dev,
+2 -2
drivers/iio/temperature/ltc2983.c
··· 204 204 u8 num_channels; 205 205 u8 iio_channels; 206 206 /* 207 - * DMA (thus cache coherency maintenance) requires the 207 + * DMA (thus cache coherency maintenance) may require the 208 208 * transfer buffers to live in their own cache lines. 209 209 * Holds the converted temperature 210 210 */ 211 - __be32 temp ____cacheline_aligned; 211 + __be32 temp __aligned(IIO_DMA_MINALIGN); 212 212 }; 213 213 214 214 struct ltc2983_sensor {
+1 -1
drivers/iio/temperature/max31865.c
··· 55 55 struct mutex lock; 56 56 bool filter_50hz; 57 57 bool three_wire; 58 - u8 buf[2] ____cacheline_aligned; 58 + u8 buf[2] __aligned(IIO_DMA_MINALIGN); 59 59 }; 60 60 61 61 static int max31865_read(struct max31865_data *data, u8 reg,
+1 -1
drivers/iio/temperature/maxim_thermocouple.c
··· 122 122 struct spi_device *spi; 123 123 const struct maxim_thermocouple_chip *chip; 124 124 125 - u8 buffer[16] ____cacheline_aligned; 125 + u8 buffer[16] __aligned(IIO_DMA_MINALIGN); 126 126 char tc_type; 127 127 }; 128 128
+3 -1
drivers/iio/trigger/stm32-lptimer-trigger.c
··· 11 11 12 12 #include <linux/iio/timer/stm32-lptim-trigger.h> 13 13 #include <linux/mfd/stm32-lptimer.h> 14 + #include <linux/mod_devicetable.h> 14 15 #include <linux/module.h> 15 16 #include <linux/platform_device.h> 17 + #include <linux/property.h> 16 18 17 19 /* List Low-Power Timer triggers */ 18 20 static const char * const stm32_lptim_triggers[] = { ··· 79 77 if (!priv) 80 78 return -ENOMEM; 81 79 82 - if (of_property_read_u32(pdev->dev.of_node, "reg", &index)) 80 + if (device_property_read_u32(&pdev->dev, "reg", &index)) 83 81 return -EINVAL; 84 82 85 83 if (index >= ARRAY_SIZE(stm32_lptim_triggers))
+187 -95
drivers/mfd/qcom-spmi-pmic.c
··· 3 3 * Copyright (c) 2014, The Linux Foundation. All rights reserved. 4 4 */ 5 5 6 + #include <linux/device.h> 7 + #include <linux/errno.h> 8 + #include <linux/gfp.h> 6 9 #include <linux/kernel.h> 7 10 #include <linux/module.h> 8 11 #include <linux/spmi.h> 12 + #include <linux/types.h> 9 13 #include <linux/regmap.h> 10 14 #include <linux/of_platform.h> 15 + #include <soc/qcom/qcom-spmi-pmic.h> 11 16 12 17 #define PMIC_REV2 0x101 13 18 #define PMIC_REV3 0x102 14 19 #define PMIC_REV4 0x103 15 20 #define PMIC_TYPE 0x104 16 21 #define PMIC_SUBTYPE 0x105 22 + #define PMIC_FAB_ID 0x1f2 17 23 18 24 #define PMIC_TYPE_VALUE 0x51 19 25 20 - #define COMMON_SUBTYPE 0x00 21 - #define PM8941_SUBTYPE 0x01 22 - #define PM8841_SUBTYPE 0x02 23 - #define PM8019_SUBTYPE 0x03 24 - #define PM8226_SUBTYPE 0x04 25 - #define PM8110_SUBTYPE 0x05 26 - #define PMA8084_SUBTYPE 0x06 27 - #define PMI8962_SUBTYPE 0x07 28 - #define PMD9635_SUBTYPE 0x08 29 - #define PM8994_SUBTYPE 0x09 30 - #define PMI8994_SUBTYPE 0x0a 31 - #define PM8916_SUBTYPE 0x0b 32 - #define PM8004_SUBTYPE 0x0c 33 - #define PM8909_SUBTYPE 0x0d 34 - #define PM8028_SUBTYPE 0x0e 35 - #define PM8901_SUBTYPE 0x0f 36 - #define PM8950_SUBTYPE 0x10 37 - #define PMI8950_SUBTYPE 0x11 38 - #define PM8998_SUBTYPE 0x14 39 - #define PMI8998_SUBTYPE 0x15 40 - #define PM8005_SUBTYPE 0x18 41 - #define PM660L_SUBTYPE 0x1A 42 - #define PM660_SUBTYPE 0x1B 43 - #define PM8150_SUBTYPE 0x1E 44 - #define PM8150L_SUBTYPE 0x1f 45 - #define PM8150B_SUBTYPE 0x20 46 - #define PMK8002_SUBTYPE 0x21 47 - #define PM8009_SUBTYPE 0x24 48 - #define PM8150C_SUBTYPE 0x26 49 - #define SMB2351_SUBTYPE 0x29 26 + #define PMIC_REV4_V2 0x02 27 + 28 + struct qcom_spmi_dev { 29 + int num_usids; 30 + struct qcom_spmi_pmic pmic; 31 + }; 32 + 33 + #define N_USIDS(n) ((void *)n) 50 34 51 35 static const struct of_device_id pmic_spmi_id_table[] = { 52 - { .compatible = "qcom,pm660", .data = (void *)PM660_SUBTYPE }, 53 - { .compatible = "qcom,pm660l", .data = (void *)PM660L_SUBTYPE }, 54 - { .compatible = "qcom,pm8004", .data = (void *)PM8004_SUBTYPE }, 55 - { .compatible = "qcom,pm8005", .data = (void *)PM8005_SUBTYPE }, 56 - { .compatible = "qcom,pm8019", .data = (void *)PM8019_SUBTYPE }, 57 - { .compatible = "qcom,pm8028", .data = (void *)PM8028_SUBTYPE }, 58 - { .compatible = "qcom,pm8110", .data = (void *)PM8110_SUBTYPE }, 59 - { .compatible = "qcom,pm8150", .data = (void *)PM8150_SUBTYPE }, 60 - { .compatible = "qcom,pm8150b", .data = (void *)PM8150B_SUBTYPE }, 61 - { .compatible = "qcom,pm8150c", .data = (void *)PM8150C_SUBTYPE }, 62 - { .compatible = "qcom,pm8150l", .data = (void *)PM8150L_SUBTYPE }, 63 - { .compatible = "qcom,pm8226", .data = (void *)PM8226_SUBTYPE }, 64 - { .compatible = "qcom,pm8841", .data = (void *)PM8841_SUBTYPE }, 65 - { .compatible = "qcom,pm8901", .data = (void *)PM8901_SUBTYPE }, 66 - { .compatible = "qcom,pm8909", .data = (void *)PM8909_SUBTYPE }, 67 - { .compatible = "qcom,pm8916", .data = (void *)PM8916_SUBTYPE }, 68 - { .compatible = "qcom,pm8941", .data = (void *)PM8941_SUBTYPE }, 69 - { .compatible = "qcom,pm8950", .data = (void *)PM8950_SUBTYPE }, 70 - { .compatible = "qcom,pm8994", .data = (void *)PM8994_SUBTYPE }, 71 - { .compatible = "qcom,pm8998", .data = (void *)PM8998_SUBTYPE }, 72 - { .compatible = "qcom,pma8084", .data = (void *)PMA8084_SUBTYPE }, 73 - { .compatible = "qcom,pmd9635", .data = (void *)PMD9635_SUBTYPE }, 74 - { .compatible = "qcom,pmi8950", .data = (void *)PMI8950_SUBTYPE }, 75 - { .compatible = "qcom,pmi8962", .data = (void *)PMI8962_SUBTYPE }, 76 - { .compatible = "qcom,pmi8994", .data = (void *)PMI8994_SUBTYPE }, 77 - { .compatible = "qcom,pmi8998", .data = (void *)PMI8998_SUBTYPE }, 78 - { .compatible = "qcom,pmk8002", .data = (void *)PMK8002_SUBTYPE }, 79 - { .compatible = "qcom,smb2351", .data = (void *)SMB2351_SUBTYPE }, 80 - { .compatible = "qcom,spmi-pmic", .data = (void *)COMMON_SUBTYPE }, 36 + { .compatible = "qcom,pm660", .data = N_USIDS(2) }, 37 + { .compatible = "qcom,pm660l", .data = N_USIDS(2) }, 38 + { .compatible = "qcom,pm8004", .data = N_USIDS(2) }, 39 + { .compatible = "qcom,pm8005", .data = N_USIDS(2) }, 40 + { .compatible = "qcom,pm8019", .data = N_USIDS(2) }, 41 + { .compatible = "qcom,pm8028", .data = N_USIDS(2) }, 42 + { .compatible = "qcom,pm8110", .data = N_USIDS(2) }, 43 + { .compatible = "qcom,pm8150", .data = N_USIDS(2) }, 44 + { .compatible = "qcom,pm8150b", .data = N_USIDS(2) }, 45 + { .compatible = "qcom,pm8150c", .data = N_USIDS(2) }, 46 + { .compatible = "qcom,pm8150l", .data = N_USIDS(2) }, 47 + { .compatible = "qcom,pm8226", .data = N_USIDS(2) }, 48 + { .compatible = "qcom,pm8841", .data = N_USIDS(2) }, 49 + { .compatible = "qcom,pm8901", .data = N_USIDS(2) }, 50 + { .compatible = "qcom,pm8909", .data = N_USIDS(2) }, 51 + { .compatible = "qcom,pm8916", .data = N_USIDS(2) }, 52 + { .compatible = "qcom,pm8941", .data = N_USIDS(2) }, 53 + { .compatible = "qcom,pm8950", .data = N_USIDS(2) }, 54 + { .compatible = "qcom,pm8994", .data = N_USIDS(2) }, 55 + { .compatible = "qcom,pm8998", .data = N_USIDS(2) }, 56 + { .compatible = "qcom,pma8084", .data = N_USIDS(2) }, 57 + { .compatible = "qcom,pmd9635", .data = N_USIDS(2) }, 58 + { .compatible = "qcom,pmi8950", .data = N_USIDS(2) }, 59 + { .compatible = "qcom,pmi8962", .data = N_USIDS(2) }, 60 + { .compatible = "qcom,pmi8994", .data = N_USIDS(2) }, 61 + { .compatible = "qcom,pmi8998", .data = N_USIDS(2) }, 62 + { .compatible = "qcom,pmk8002", .data = N_USIDS(2) }, 63 + { .compatible = "qcom,smb2351", .data = N_USIDS(2) }, 64 + { .compatible = "qcom,spmi-pmic", .data = N_USIDS(1) }, 81 65 { } 82 66 }; 83 67 84 - static void pmic_spmi_show_revid(struct regmap *map, struct device *dev) 68 + /* 69 + * A PMIC can be represented by multiple SPMI devices, but 70 + * only the base PMIC device will contain a reference to 71 + * the revision information. 72 + * 73 + * This function takes a pointer to a pmic device and 74 + * returns a pointer to the base PMIC device. 75 + * 76 + * This only supports PMICs with 1 or 2 USIDs. 77 + */ 78 + static struct spmi_device *qcom_pmic_get_base_usid(struct device *dev) 85 79 { 86 - unsigned int rev2, minor, major, type, subtype; 87 - const char *name = "unknown"; 88 - int ret, i; 80 + struct spmi_device *sdev; 81 + struct qcom_spmi_dev *ctx; 82 + struct device_node *spmi_bus; 83 + struct device_node *other_usid = NULL; 84 + int function_parent_usid, ret; 85 + u32 pmic_addr; 89 86 90 - ret = regmap_read(map, PMIC_TYPE, &type); 87 + sdev = to_spmi_device(dev); 88 + ctx = dev_get_drvdata(&sdev->dev); 89 + 90 + /* 91 + * Quick return if the function device is already in the base 92 + * USID. This will always be hit for PMICs with only 1 USID. 93 + */ 94 + if (sdev->usid % ctx->num_usids == 0) 95 + return sdev; 96 + 97 + function_parent_usid = sdev->usid; 98 + 99 + /* 100 + * Walk through the list of PMICs until we find the sibling USID. 101 + * The goal is to find the first USID which is less than the 102 + * number of USIDs in the PMIC array, e.g. for a PMIC with 2 USIDs 103 + * where the function device is under USID 3, we want to find the 104 + * device for USID 2. 105 + */ 106 + spmi_bus = of_get_parent(sdev->dev.of_node); 107 + do { 108 + other_usid = of_get_next_child(spmi_bus, other_usid); 109 + 110 + ret = of_property_read_u32_index(other_usid, "reg", 0, &pmic_addr); 111 + if (ret) 112 + return ERR_PTR(ret); 113 + 114 + sdev = spmi_device_from_of(other_usid); 115 + if (pmic_addr == function_parent_usid - (ctx->num_usids - 1)) { 116 + if (!sdev) 117 + /* 118 + * If the base USID for this PMIC hasn't probed yet 119 + * but the secondary USID has, then we need to defer 120 + * the function driver so that it will attempt to 121 + * probe again when the base USID is ready. 122 + */ 123 + return ERR_PTR(-EPROBE_DEFER); 124 + return sdev; 125 + } 126 + } while (other_usid->sibling); 127 + 128 + return ERR_PTR(-ENODATA); 129 + } 130 + 131 + static int pmic_spmi_load_revid(struct regmap *map, struct device *dev, 132 + struct qcom_spmi_pmic *pmic) 133 + { 134 + int ret; 135 + 136 + ret = regmap_read(map, PMIC_TYPE, &pmic->type); 91 137 if (ret < 0) 92 - return; 138 + return ret; 93 139 94 - if (type != PMIC_TYPE_VALUE) 95 - return; 140 + if (pmic->type != PMIC_TYPE_VALUE) 141 + return ret; 96 142 97 - ret = regmap_read(map, PMIC_SUBTYPE, &subtype); 143 + ret = regmap_read(map, PMIC_SUBTYPE, &pmic->subtype); 98 144 if (ret < 0) 99 - return; 145 + return ret; 100 146 101 - for (i = 0; i < ARRAY_SIZE(pmic_spmi_id_table); i++) { 102 - if (subtype == (unsigned long)pmic_spmi_id_table[i].data) 103 - break; 147 + pmic->name = of_match_device(pmic_spmi_id_table, dev)->compatible; 148 + 149 + ret = regmap_read(map, PMIC_REV2, &pmic->rev2); 150 + if (ret < 0) 151 + return ret; 152 + 153 + ret = regmap_read(map, PMIC_REV3, &pmic->minor); 154 + if (ret < 0) 155 + return ret; 156 + 157 + ret = regmap_read(map, PMIC_REV4, &pmic->major); 158 + if (ret < 0) 159 + return ret; 160 + 161 + if (pmic->subtype == PMI8998_SUBTYPE || pmic->subtype == PM660_SUBTYPE) { 162 + ret = regmap_read(map, PMIC_FAB_ID, &pmic->fab_id); 163 + if (ret < 0) 164 + return ret; 104 165 } 105 - 106 - if (i != ARRAY_SIZE(pmic_spmi_id_table)) 107 - name = pmic_spmi_id_table[i].compatible; 108 - 109 - ret = regmap_read(map, PMIC_REV2, &rev2); 110 - if (ret < 0) 111 - return; 112 - 113 - ret = regmap_read(map, PMIC_REV3, &minor); 114 - if (ret < 0) 115 - return; 116 - 117 - ret = regmap_read(map, PMIC_REV4, &major); 118 - if (ret < 0) 119 - return; 120 166 121 167 /* 122 168 * In early versions of PM8941 and PM8226, the major revision number ··· 170 124 * Increment the major revision number here if the chip is an early 171 125 * version of PM8941 or PM8226. 172 126 */ 173 - if ((subtype == PM8941_SUBTYPE || subtype == PM8226_SUBTYPE) && 174 - major < 0x02) 175 - major++; 127 + if ((pmic->subtype == PM8941_SUBTYPE || pmic->subtype == PM8226_SUBTYPE) && 128 + pmic->major < PMIC_REV4_V2) 129 + pmic->major++; 176 130 177 - if (subtype == PM8110_SUBTYPE) 178 - minor = rev2; 131 + if (pmic->subtype == PM8110_SUBTYPE) 132 + pmic->minor = pmic->rev2; 179 133 180 - dev_dbg(dev, "%x: %s v%d.%d\n", subtype, name, major, minor); 134 + dev_dbg(dev, "%x: %s v%d.%d\n", 135 + pmic->subtype, pmic->name, pmic->major, pmic->minor); 136 + 137 + return 0; 181 138 } 139 + 140 + /** 141 + * qcom_pmic_get() - Get a pointer to the base PMIC device 142 + * 143 + * This function takes a struct device for a driver which is a child of a PMIC. 144 + * And locates the PMIC revision information for it. 145 + * 146 + * @dev: the pmic function device 147 + * @return: the struct qcom_spmi_pmic* pointer associated with the function device 148 + */ 149 + const struct qcom_spmi_pmic *qcom_pmic_get(struct device *dev) 150 + { 151 + struct spmi_device *sdev; 152 + struct qcom_spmi_dev *spmi; 153 + 154 + /* 155 + * Make sure the device is actually a child of a PMIC 156 + */ 157 + if (!of_match_device(pmic_spmi_id_table, dev->parent)) 158 + return ERR_PTR(-EINVAL); 159 + 160 + sdev = qcom_pmic_get_base_usid(dev->parent); 161 + 162 + if (IS_ERR(sdev)) 163 + return ERR_CAST(sdev); 164 + 165 + spmi = dev_get_drvdata(&sdev->dev); 166 + 167 + return &spmi->pmic; 168 + } 169 + EXPORT_SYMBOL(qcom_pmic_get); 182 170 183 171 static const struct regmap_config spmi_regmap_config = { 184 172 .reg_bits = 16, ··· 224 144 static int pmic_spmi_probe(struct spmi_device *sdev) 225 145 { 226 146 struct regmap *regmap; 147 + struct qcom_spmi_dev *ctx; 148 + int ret; 227 149 228 150 regmap = devm_regmap_init_spmi_ext(sdev, &spmi_regmap_config); 229 151 if (IS_ERR(regmap)) 230 152 return PTR_ERR(regmap); 231 153 154 + ctx = devm_kzalloc(&sdev->dev, sizeof(*ctx), GFP_KERNEL); 155 + if (!ctx) 156 + return -ENOMEM; 157 + 158 + ctx->num_usids = (uintptr_t)of_device_get_match_data(&sdev->dev); 159 + 232 160 /* Only the first slave id for a PMIC contains this information */ 233 - if (sdev->usid % 2 == 0) 234 - pmic_spmi_show_revid(regmap, &sdev->dev); 161 + if (sdev->usid % ctx->num_usids == 0) { 162 + ret = pmic_spmi_load_revid(regmap, &sdev->dev, &ctx->pmic); 163 + if (ret < 0) 164 + return ret; 165 + } 166 + spmi_device_set_drvdata(sdev, ctx); 235 167 236 168 return devm_of_platform_populate(&sdev->dev); 237 169 }
+17
drivers/spmi/spmi.c
··· 387 387 }; 388 388 389 389 /** 390 + * spmi_device_from_of() - get the associated SPMI device from a device node 391 + * 392 + * @np: device node 393 + * 394 + * Returns the struct spmi_device associated with a device node or NULL. 395 + */ 396 + struct spmi_device *spmi_device_from_of(struct device_node *np) 397 + { 398 + struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np); 399 + 400 + if (dev) 401 + return to_spmi_device(dev); 402 + return NULL; 403 + } 404 + EXPORT_SYMBOL_GPL(spmi_device_from_of); 405 + 406 + /** 390 407 * spmi_controller_alloc() - Allocate a new SPMI device 391 408 * @ctrl: associated controller 392 409 *
-2
include/linux/iio/common/cros_ec_sensors_core.h
··· 41 41 * @param: motion sensor parameters structure 42 42 * @resp: motion sensor response structure 43 43 * @type: type of motion sensor 44 - * @loc: location where the motion sensor is placed 45 44 * @range_updated: True if the range of the sensor has been 46 45 * updated. 47 46 * @curr_range: If updated, the current range value. ··· 66 67 struct ec_response_motion_sense *resp; 67 68 68 69 enum motionsensor_type type; 69 - enum motionsensor_location loc; 70 70 71 71 bool range_updated; 72 72 int curr_range;
+10 -4
include/linux/iio/iio.h
··· 9 9 10 10 #include <linux/device.h> 11 11 #include <linux/cdev.h> 12 + #include <linux/slab.h> 12 13 #include <linux/iio/types.h> 13 - #include <linux/of.h> 14 14 /* IIO TODO LIST */ 15 15 /* 16 16 * Provide means of adjusting timer accuracy. 17 17 * Currently assumes nano seconds. 18 18 */ 19 + 20 + struct of_phandle_args; 19 21 20 22 enum iio_shared_by { 21 23 IIO_SEPARATE, ··· 315 313 } 316 314 317 315 s64 iio_get_time_ns(const struct iio_dev *indio_dev); 318 - unsigned int iio_get_time_res(const struct iio_dev *indio_dev); 319 316 320 317 /* 321 318 * Device operating modes ··· 710 709 return dev_get_drvdata(&indio_dev->dev); 711 710 } 712 711 713 - /* Can we make this smaller? */ 714 - #define IIO_ALIGN L1_CACHE_BYTES 712 + /* 713 + * Used to ensure the iio_priv() structure is aligned to allow that structure 714 + * to in turn include IIO_DMA_MINALIGN'd elements such as buffers which 715 + * must not share cachelines with the rest of the structure, thus making 716 + * them safe for use with non-coherent DMA. 717 + */ 718 + #define IIO_DMA_MINALIGN ARCH_KMALLOC_MINALIGN 715 719 struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv); 716 720 717 721 /* The information at the returned address is guaranteed to be cacheline aligned */
+5
include/linux/iio/trigger.h
··· 93 93 static inline struct iio_trigger *iio_trigger_get(struct iio_trigger *trig) 94 94 { 95 95 get_device(&trig->dev); 96 + 97 + WARN_ONCE(list_empty(&trig->list), 98 + "Getting non-registered iio trigger %s is prohibited\n", 99 + trig->name); 100 + 96 101 __module_get(trig->owner); 97 102 98 103 return trig;
+3
include/linux/spmi.h
··· 164 164 module_driver(__spmi_driver, spmi_driver_register, \ 165 165 spmi_driver_unregister) 166 166 167 + struct device_node; 168 + 169 + struct spmi_device *spmi_device_from_of(struct device_node *np); 167 170 int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf); 168 171 int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, 169 172 size_t len);
+61
include/soc/qcom/qcom-spmi-pmic.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* Copyright (c) 2022 Linaro. All rights reserved. 3 + * Author: Caleb Connolly <caleb.connolly@linaro.org> 4 + */ 5 + 6 + #ifndef __QCOM_SPMI_PMIC_H__ 7 + #define __QCOM_SPMI_PMIC_H__ 8 + 9 + #include <linux/device.h> 10 + 11 + #define COMMON_SUBTYPE 0x00 12 + #define PM8941_SUBTYPE 0x01 13 + #define PM8841_SUBTYPE 0x02 14 + #define PM8019_SUBTYPE 0x03 15 + #define PM8226_SUBTYPE 0x04 16 + #define PM8110_SUBTYPE 0x05 17 + #define PMA8084_SUBTYPE 0x06 18 + #define PMI8962_SUBTYPE 0x07 19 + #define PMD9635_SUBTYPE 0x08 20 + #define PM8994_SUBTYPE 0x09 21 + #define PMI8994_SUBTYPE 0x0a 22 + #define PM8916_SUBTYPE 0x0b 23 + #define PM8004_SUBTYPE 0x0c 24 + #define PM8909_SUBTYPE 0x0d 25 + #define PM8028_SUBTYPE 0x0e 26 + #define PM8901_SUBTYPE 0x0f 27 + #define PM8950_SUBTYPE 0x10 28 + #define PMI8950_SUBTYPE 0x11 29 + #define PM8998_SUBTYPE 0x14 30 + #define PMI8998_SUBTYPE 0x15 31 + #define PM8005_SUBTYPE 0x18 32 + #define PM660L_SUBTYPE 0x1A 33 + #define PM660_SUBTYPE 0x1B 34 + #define PM8150_SUBTYPE 0x1E 35 + #define PM8150L_SUBTYPE 0x1f 36 + #define PM8150B_SUBTYPE 0x20 37 + #define PMK8002_SUBTYPE 0x21 38 + #define PM8009_SUBTYPE 0x24 39 + #define PM8150C_SUBTYPE 0x26 40 + #define SMB2351_SUBTYPE 0x29 41 + 42 + #define PMI8998_FAB_ID_SMIC 0x11 43 + #define PMI8998_FAB_ID_GF 0x30 44 + 45 + #define PM660_FAB_ID_GF 0x0 46 + #define PM660_FAB_ID_TSMC 0x2 47 + #define PM660_FAB_ID_MX 0x3 48 + 49 + struct qcom_spmi_pmic { 50 + unsigned int type; 51 + unsigned int subtype; 52 + unsigned int major; 53 + unsigned int minor; 54 + unsigned int rev2; 55 + unsigned int fab_id; 56 + const char *name; 57 + }; 58 + 59 + const struct qcom_spmi_pmic *qcom_pmic_get(struct device *dev); 60 + 61 + #endif /* __QCOM_SPMI_PMIC_H__ */