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

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

Jonathan writes:

Second set of IIO new device support, features and cleanups for the 4.21 cycle.

Staging graduation
* ad2s90
- Driver for this resolver to digital chip.

New drivers and device support.
* ad5686
- Add support for ad5310r DAC and associated fix in value read back.
* exynos-adc
- Support for S5PV210 which is slightly different from other parts.
* mcp41010
- Driver supporting MCP41010, MCP41050, MCP41100, MCP42010, MCP42050 and
MCP42100 microchip potentiometers.

New ACPI ids.
* ak8975
- AKM9911 ACPI HID.
* kxcjk-1013
- KXJ2109 ACPI HID.
- KIOX010A ACPI HID.

New features
* ad5933
- Explicit DT binding.
* ad2s90
- Explicit DT binding including dropping spi setup that is done via dt
in favour of verifying the settings form DT.
* adt7316
- Explicit DT binding and support for gpio, irq_flags etc.
* stm32-adc
- Runtime power management.

Minor fixes and cleanups
* core
- Protect against missing info structure.
* ad2s90
- SPDX
- Add documentation fo the mutex.
* ad7280a
- Check allocation failure.
- Fix an accidental replacement of an error return.
* adt7316
- Switch some variables to be local and rename for consistency with other
drivers.
- Revert a false handling of 0 as an error introduced earlier this cycle.
* bmi160
- Use devm functions throughout probe() to avoid need for remove().
* hid-sensor-hub
- White space cleanup.
* hts221
- MAINTAINERS entry.
* lis302
- Use generic name in the DT binding doc.
* Messon-saradc
- Check for allocation error.
- Fix some presented clock names that break clk debugfs.
* qcom-spmi-adc
- A fix for initialization of the prescale property. Came late in the
cycle, so merge window is probably the best route for this.
* st_lsm6dsx
- Allow for variable read length to support wider range of slave devices.

* tag 'iio-for-4.21b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (37 commits)
iio: adc: qcom-spmi-adc5: Initialize prescale properly
dt-bindings: iio: adc: exynos-adc: Add S5PV210 variant
iio: adc: Allow selection of Exynos ADC on S5PV210
iio: adc: exynos-adc: Add S5PV210 variant
iio: bmi160: use all devm functions in probe
iio: dac: ad5686: fix bit shift read register
iio:dac:ad5686: Add AD5310R support
Revert "Staging: iio: adt7316: Add an extra check for 'ret' equals to 0"
dt-bindings: iio: accel: use a generic node name for lis302
iio: core: check 'info' value before registering the device
staging: iio: adc: ad7280a: fix overwrite of the returned value
staging: iio: adc: ad7280a: check for devm_kasprint() failure
iio: humidity: hts221: add entry in MAINTAINERS file
iio: magnetometer: ak8975: Add the "AKM9911" ACPI HID
staging:iio:ad2s90: Move out of staging
staging:iio:ad2s90: Add comment to device state mutex
staging:iio:ad2s90: Replace license text w/ SPDX identifier
dt-bindings:iio:resolver: Add docs for ad2s90
staging:iio:ad2s90: Add max frequency check at probe
staging:iio:ad2s90: Remove spi setup that should be done via dt
...

+852 -298
+2 -2
Documentation/devicetree/bindings/iio/accel/lis302.txt
··· 64 64 65 65 Example for a SPI device node: 66 66 67 - lis302@0 { 67 + accelerometer@0 { 68 68 compatible = "st,lis302dl-spi"; 69 69 reg = <0>; 70 70 spi-max-frequency = <1000000>; ··· 89 89 90 90 Example for a I2C device node: 91 91 92 - lis331dlh: lis331dlh@18 { 92 + lis331dlh: accelerometer@18 { 93 93 compatible = "st,lis331dlh", "st,lis3lv02d"; 94 94 reg = <0x18>; 95 95 Vdd-supply = <&lis3_reg>;
+3 -1
Documentation/devicetree/bindings/iio/adc/samsung,exynos-adc.txt
··· 11 11 12 12 Required properties: 13 13 - compatible: Must be "samsung,exynos-adc-v1" 14 - for exynos4412/5250 and s5pv210 controllers. 14 + for exynos4412/5250 controllers. 15 15 Must be "samsung,exynos-adc-v2" for 16 16 future controllers. 17 17 Must be "samsung,exynos3250-adc" for ··· 28 28 the ADC in s3c2443 and compatibles 29 29 Must be "samsung,s3c6410-adc" for 30 30 the ADC in s3c6410 and compatibles 31 + Must be "samsung,s5pv210-adc" for 32 + the ADC in s5pv210 and compatibles 31 33 - reg: List of ADC register address range 32 34 - The base address and range of ADC register 33 35 - The base address and range of ADC_PHY register (every
+28
Documentation/devicetree/bindings/iio/potentiometer/mcp41010.txt
··· 1 + * Microchip MCP41010/41050/41100/42010/42050/42100 Digital Potentiometer 2 + 3 + Datasheet publicly available at: 4 + http://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf 5 + 6 + The node for this driver must be a child node of a SPI controller, hence 7 + all mandatory properties described in 8 + 9 + Documentation/devicetree/bindings/spi/spi-bus.txt 10 + 11 + must be specified. 12 + 13 + Required properties: 14 + - compatible: Must be one of the following, depending on the 15 + model: 16 + "microchip,mcp41010" 17 + "microchip,mcp41050" 18 + "microchip,mcp41100" 19 + "microchip,mcp42010" 20 + "microchip,mcp42050" 21 + "microchip,mcp42100" 22 + 23 + Example: 24 + potentiometer@0 { 25 + compatible = "microchip,mcp41010"; 26 + reg = <0>; 27 + spi-max-frequency = <500000>; 28 + };
+31
Documentation/devicetree/bindings/iio/resolver/ad2s90.txt
··· 1 + Analog Devices AD2S90 Resolver-to-Digital Converter 2 + 3 + https://www.analog.com/en/products/ad2s90.html 4 + 5 + Required properties: 6 + - compatible: should be "adi,ad2s90" 7 + - reg: SPI chip select number for the device 8 + - spi-max-frequency: set maximum clock frequency, must be 830000 9 + - spi-cpol and spi-cpha: 10 + Either SPI mode (0,0) or (1,1) must be used, so specify none or both of 11 + spi-cpha, spi-cpol. 12 + 13 + See for more details: 14 + Documentation/devicetree/bindings/spi/spi-bus.txt 15 + 16 + Note about max frequency: 17 + Chip's max frequency, as specified in its datasheet, is 2Mhz. But a 600ns 18 + delay is expected between the application of a logic LO to CS and the 19 + application of SCLK, as also specified. And since the delay is not 20 + implemented in the spi code, to satisfy it, SCLK's period should be at most 21 + 2 * 600ns, so the max frequency should be 1 / (2 * 6e-7), which gives 22 + roughly 830000Hz. 23 + 24 + Example: 25 + resolver@0 { 26 + compatible = "adi,ad2s90"; 27 + reg = <0>; 28 + spi-max-frequency = <830000>; 29 + spi-cpol; 30 + spi-cpha; 31 + };
+8
MAINTAINERS
··· 6866 6866 S: Maintained 6867 6867 F: drivers/input/touchscreen/htcpen.c 6868 6868 6869 + HTS221 TEMPERATURE-HUMIDITY IIO DRIVER 6870 + M: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> 6871 + L: linux-iio@vger.kernel.org 6872 + W: http://www.st.com/ 6873 + S: Maintained 6874 + F: drivers/iio/humidity/hts221* 6875 + F: Documentation/devicetree/bindings/iio/humidity/hts221.txt 6876 + 6869 6877 HUAWEI ETHERNET DRIVER 6870 6878 M: Aviad Krawczyk <aviad.krawczyk@huawei.com> 6871 6879 L: netdev@vger.kernel.org
+2
drivers/iio/accel/kxcjk-1013.c
··· 1491 1491 {"KXCJ9000", KXCJ91008}, 1492 1492 {"KIOX0009", KXTJ21009}, 1493 1493 {"KIOX000A", KXCJ91008}, 1494 + {"KIOX010A", KXCJ91008}, /* KXCJ91008 inside the display of a 2-in-1 */ 1494 1495 {"KXTJ1009", KXTJ21009}, 1496 + {"KXJ2109", KXTJ21009}, 1495 1497 {"SMO8500", KXCJ91008}, 1496 1498 { }, 1497 1499 };
+1 -1
drivers/iio/adc/Kconfig
··· 295 295 296 296 config EXYNOS_ADC 297 297 tristate "Exynos ADC driver support" 298 - depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST) 298 + depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || ARCH_S5PV210 || (OF && COMPILE_TEST) 299 299 depends on HAS_IOMEM 300 300 help 301 301 Core support for the ADC block found in the Samsung EXYNOS series
+14
drivers/iio/adc/exynos_adc.c
··· 115 115 #define MAX_ADC_V2_CHANNELS 10 116 116 #define MAX_ADC_V1_CHANNELS 8 117 117 #define MAX_EXYNOS3250_ADC_CHANNELS 2 118 + #define MAX_S5PV210_ADC_CHANNELS 10 118 119 119 120 /* Bit definitions common for ADC_V1 and ADC_V2 */ 120 121 #define ADC_CON_EN_START (1u << 0) ··· 276 275 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ 277 276 .needs_adc_phy = true, 278 277 .phy_offset = EXYNOS_ADCV1_PHY_OFFSET, 278 + 279 + .init_hw = exynos_adc_v1_init_hw, 280 + .exit_hw = exynos_adc_v1_exit_hw, 281 + .clear_irq = exynos_adc_v1_clear_irq, 282 + .start_conv = exynos_adc_v1_start_conv, 283 + }; 284 + 285 + static const struct exynos_adc_data exynos_adc_s5pv210_data = { 286 + .num_channels = MAX_S5PV210_ADC_CHANNELS, 287 + .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ 279 288 280 289 .init_hw = exynos_adc_v1_init_hw, 281 290 .exit_hw = exynos_adc_v1_exit_hw, ··· 489 478 }, { 490 479 .compatible = "samsung,s3c6410-adc", 491 480 .data = &exynos_adc_s3c64xx_data, 481 + }, { 482 + .compatible = "samsung,s5pv210-adc", 483 + .data = &exynos_adc_s5pv210_data, 492 484 }, { 493 485 .compatible = "samsung,exynos-adc-v1", 494 486 .data = &exynos_adc_v1_data,
+10 -4
drivers/iio/adc/meson_saradc.c
··· 656 656 struct clk_init_data init; 657 657 const char *clk_parents[1]; 658 658 659 - init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_div", 660 - indio_dev->dev.of_node); 659 + init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_div", 660 + dev_name(indio_dev->dev.parent)); 661 + if (!init.name) 662 + return -ENOMEM; 663 + 661 664 init.flags = 0; 662 665 init.ops = &clk_divider_ops; 663 666 clk_parents[0] = __clk_get_name(priv->clkin); ··· 678 675 if (WARN_ON(IS_ERR(priv->adc_div_clk))) 679 676 return PTR_ERR(priv->adc_div_clk); 680 677 681 - init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_en", 682 - indio_dev->dev.of_node); 678 + init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_en", 679 + dev_name(indio_dev->dev.parent)); 680 + if (!init.name) 681 + return -ENOMEM; 682 + 683 683 init.flags = CLK_SET_RATE_PARENT; 684 684 init.ops = &clk_gate_ops; 685 685 clk_parents[0] = __clk_get_name(priv->adc_div_clk);
+31 -27
drivers/iio/adc/qcom-spmi-adc5.c
··· 423 423 enum vadc_scale_fn_type scale_fn_type; 424 424 }; 425 425 426 + /* In these definitions, _pre refers to an index into adc5_prescale_ratios. */ 426 427 #define ADC5_CHAN(_dname, _type, _mask, _pre, _scale) \ 427 428 { \ 428 429 .datasheet_name = _dname, \ ··· 444 443 _pre, _scale) \ 445 444 446 445 static const struct adc5_channels adc5_chans_pmic[ADC5_MAX_CHANNEL] = { 447 - [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 1, 446 + [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 0, 448 447 SCALE_HW_CALIB_DEFAULT) 449 - [ADC5_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 1, 448 + [ADC5_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 0, 450 449 SCALE_HW_CALIB_DEFAULT) 451 - [ADC5_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 3, 450 + [ADC5_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 1, 452 451 SCALE_HW_CALIB_DEFAULT) 453 - [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 3, 452 + [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 1, 454 453 SCALE_HW_CALIB_DEFAULT) 455 - [ADC5_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 1, 454 + [ADC5_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 0, 456 455 SCALE_HW_CALIB_PMIC_THERM) 457 - [ADC5_USB_IN_I] = ADC5_CHAN_VOLT("usb_in_i_uv", 1, 456 + [ADC5_USB_IN_I] = ADC5_CHAN_VOLT("usb_in_i_uv", 0, 458 457 SCALE_HW_CALIB_DEFAULT) 459 - [ADC5_USB_IN_V_16] = ADC5_CHAN_VOLT("usb_in_v_div_16", 16, 458 + [ADC5_USB_IN_V_16] = ADC5_CHAN_VOLT("usb_in_v_div_16", 8, 460 459 SCALE_HW_CALIB_DEFAULT) 461 - [ADC5_CHG_TEMP] = ADC5_CHAN_TEMP("chg_temp", 1, 460 + [ADC5_CHG_TEMP] = ADC5_CHAN_TEMP("chg_temp", 0, 462 461 SCALE_HW_CALIB_PM5_CHG_TEMP) 463 462 /* Charger prescales SBUx and MID_CHG to fit within 1.8V upper unit */ 464 - [ADC5_SBUx] = ADC5_CHAN_VOLT("chg_sbux", 3, 463 + [ADC5_SBUx] = ADC5_CHAN_VOLT("chg_sbux", 1, 465 464 SCALE_HW_CALIB_DEFAULT) 466 - [ADC5_MID_CHG_DIV6] = ADC5_CHAN_VOLT("chg_mid_chg", 6, 465 + [ADC5_MID_CHG_DIV6] = ADC5_CHAN_VOLT("chg_mid_chg", 3, 467 466 SCALE_HW_CALIB_DEFAULT) 468 - [ADC5_XO_THERM_100K_PU] = ADC5_CHAN_TEMP("xo_therm", 1, 467 + [ADC5_XO_THERM_100K_PU] = ADC5_CHAN_TEMP("xo_therm", 0, 469 468 SCALE_HW_CALIB_XOTHERM) 470 - [ADC5_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_100k_pu", 1, 469 + [ADC5_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_100k_pu", 0, 471 470 SCALE_HW_CALIB_THERM_100K_PULLUP) 472 - [ADC5_AMUX_THM2_100K_PU] = ADC5_CHAN_TEMP("amux_thm2_100k_pu", 1, 471 + [ADC5_AMUX_THM2_100K_PU] = ADC5_CHAN_TEMP("amux_thm2_100k_pu", 0, 473 472 SCALE_HW_CALIB_THERM_100K_PULLUP) 474 - [ADC5_AMUX_THM3_100K_PU] = ADC5_CHAN_TEMP("amux_thm3_100k_pu", 1, 473 + [ADC5_AMUX_THM3_100K_PU] = ADC5_CHAN_TEMP("amux_thm3_100k_pu", 0, 475 474 SCALE_HW_CALIB_THERM_100K_PULLUP) 476 - [ADC5_AMUX_THM2] = ADC5_CHAN_TEMP("amux_thm2", 1, 475 + [ADC5_AMUX_THM2] = ADC5_CHAN_TEMP("amux_thm2", 0, 477 476 SCALE_HW_CALIB_PM5_SMB_TEMP) 478 477 }; 479 478 480 479 static const struct adc5_channels adc5_chans_rev2[ADC5_MAX_CHANNEL] = { 481 - [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 1, 480 + [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 0, 482 481 SCALE_HW_CALIB_DEFAULT) 483 - [ADC5_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 1, 482 + [ADC5_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 0, 484 483 SCALE_HW_CALIB_DEFAULT) 485 - [ADC5_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 3, 484 + [ADC5_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 1, 486 485 SCALE_HW_CALIB_DEFAULT) 487 - [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 3, 486 + [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 1, 488 487 SCALE_HW_CALIB_DEFAULT) 489 - [ADC5_VCOIN] = ADC5_CHAN_VOLT("vcoin", 3, 488 + [ADC5_VCOIN] = ADC5_CHAN_VOLT("vcoin", 1, 490 489 SCALE_HW_CALIB_DEFAULT) 491 - [ADC5_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 1, 490 + [ADC5_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 0, 492 491 SCALE_HW_CALIB_PMIC_THERM) 493 - [ADC5_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_100k_pu", 1, 492 + [ADC5_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_100k_pu", 0, 494 493 SCALE_HW_CALIB_THERM_100K_PULLUP) 495 - [ADC5_AMUX_THM2_100K_PU] = ADC5_CHAN_TEMP("amux_thm2_100k_pu", 1, 494 + [ADC5_AMUX_THM2_100K_PU] = ADC5_CHAN_TEMP("amux_thm2_100k_pu", 0, 496 495 SCALE_HW_CALIB_THERM_100K_PULLUP) 497 - [ADC5_AMUX_THM3_100K_PU] = ADC5_CHAN_TEMP("amux_thm3_100k_pu", 1, 496 + [ADC5_AMUX_THM3_100K_PU] = ADC5_CHAN_TEMP("amux_thm3_100k_pu", 0, 498 497 SCALE_HW_CALIB_THERM_100K_PULLUP) 499 - [ADC5_AMUX_THM4_100K_PU] = ADC5_CHAN_TEMP("amux_thm4_100k_pu", 1, 498 + [ADC5_AMUX_THM4_100K_PU] = ADC5_CHAN_TEMP("amux_thm4_100k_pu", 0, 500 499 SCALE_HW_CALIB_THERM_100K_PULLUP) 501 - [ADC5_AMUX_THM5_100K_PU] = ADC5_CHAN_TEMP("amux_thm5_100k_pu", 1, 500 + [ADC5_AMUX_THM5_100K_PU] = ADC5_CHAN_TEMP("amux_thm5_100k_pu", 0, 502 501 SCALE_HW_CALIB_THERM_100K_PULLUP) 503 - [ADC5_XO_THERM_100K_PU] = ADC5_CHAN_TEMP("xo_therm_100k_pu", 1, 502 + [ADC5_XO_THERM_100K_PU] = ADC5_CHAN_TEMP("xo_therm_100k_pu", 0, 504 503 SCALE_HW_CALIB_THERM_100K_PULLUP) 505 504 }; 506 505 ··· 559 558 return ret; 560 559 } 561 560 prop->prescale = ret; 561 + } else { 562 + prop->prescale = 563 + adc->data->adc_chans[prop->channel].prescale_index; 562 564 } 563 565 564 566 ret = of_property_read_u32(node, "qcom,hw-settle-time", &value);
+126 -56
drivers/iio/adc/stm32-adc-core.c
··· 16 16 #include <linux/irqdomain.h> 17 17 #include <linux/module.h> 18 18 #include <linux/of_device.h> 19 + #include <linux/pm_runtime.h> 19 20 #include <linux/regulator/consumer.h> 20 21 #include <linux/slab.h> 21 22 ··· 49 48 #define STM32H7_CKMODE_SHIFT 16 50 49 #define STM32H7_CKMODE_MASK GENMASK(17, 16) 51 50 51 + #define STM32_ADC_CORE_SLEEP_DELAY_MS 2000 52 + 52 53 /** 53 54 * stm32_adc_common_regs - stm32 common registers, compatible dependent data 54 55 * @csr: common status register offset 56 + * @ccr: common control register offset 55 57 * @eoc1: adc1 end of conversion flag in @csr 56 58 * @eoc2: adc2 end of conversion flag in @csr 57 59 * @eoc3: adc3 end of conversion flag in @csr 58 60 */ 59 61 struct stm32_adc_common_regs { 60 62 u32 csr; 63 + u32 ccr; 61 64 u32 eoc1_msk; 62 65 u32 eoc2_msk; 63 66 u32 eoc3_msk; ··· 90 85 * @vref: regulator reference 91 86 * @cfg: compatible configuration data 92 87 * @common: common data for all ADC instances 88 + * @ccr_bak: backup CCR in low power mode 93 89 */ 94 90 struct stm32_adc_priv { 95 91 int irq[STM32_ADC_MAX_ADCS]; ··· 100 94 struct regulator *vref; 101 95 const struct stm32_adc_priv_cfg *cfg; 102 96 struct stm32_adc_common common; 97 + u32 ccr_bak; 103 98 }; 104 99 105 100 static struct stm32_adc_priv *to_stm32_adc_priv(struct stm32_adc_common *com) ··· 272 265 /* STM32F4 common registers definitions */ 273 266 static const struct stm32_adc_common_regs stm32f4_adc_common_regs = { 274 267 .csr = STM32F4_ADC_CSR, 268 + .ccr = STM32F4_ADC_CCR, 275 269 .eoc1_msk = STM32F4_EOC1, 276 270 .eoc2_msk = STM32F4_EOC2, 277 271 .eoc3_msk = STM32F4_EOC3, ··· 281 273 /* STM32H7 common registers definitions */ 282 274 static const struct stm32_adc_common_regs stm32h7_adc_common_regs = { 283 275 .csr = STM32H7_ADC_CSR, 276 + .ccr = STM32H7_ADC_CCR, 284 277 .eoc1_msk = STM32H7_EOC_MST, 285 278 .eoc2_msk = STM32H7_EOC_SLV, 286 279 }; ··· 388 379 } 389 380 } 390 381 382 + static int stm32_adc_core_hw_start(struct device *dev) 383 + { 384 + struct stm32_adc_common *common = dev_get_drvdata(dev); 385 + struct stm32_adc_priv *priv = to_stm32_adc_priv(common); 386 + int ret; 387 + 388 + ret = regulator_enable(priv->vref); 389 + if (ret < 0) { 390 + dev_err(dev, "vref enable failed\n"); 391 + return ret; 392 + } 393 + 394 + if (priv->bclk) { 395 + ret = clk_prepare_enable(priv->bclk); 396 + if (ret < 0) { 397 + dev_err(dev, "bus clk enable failed\n"); 398 + goto err_regulator_disable; 399 + } 400 + } 401 + 402 + if (priv->aclk) { 403 + ret = clk_prepare_enable(priv->aclk); 404 + if (ret < 0) { 405 + dev_err(dev, "adc clk enable failed\n"); 406 + goto err_bclk_disable; 407 + } 408 + } 409 + 410 + writel_relaxed(priv->ccr_bak, priv->common.base + priv->cfg->regs->ccr); 411 + 412 + return 0; 413 + 414 + err_bclk_disable: 415 + if (priv->bclk) 416 + clk_disable_unprepare(priv->bclk); 417 + err_regulator_disable: 418 + regulator_disable(priv->vref); 419 + 420 + return ret; 421 + } 422 + 423 + static void stm32_adc_core_hw_stop(struct device *dev) 424 + { 425 + struct stm32_adc_common *common = dev_get_drvdata(dev); 426 + struct stm32_adc_priv *priv = to_stm32_adc_priv(common); 427 + 428 + /* Backup CCR that may be lost (depends on power state to achieve) */ 429 + priv->ccr_bak = readl_relaxed(priv->common.base + priv->cfg->regs->ccr); 430 + if (priv->aclk) 431 + clk_disable_unprepare(priv->aclk); 432 + if (priv->bclk) 433 + clk_disable_unprepare(priv->bclk); 434 + regulator_disable(priv->vref); 435 + } 436 + 391 437 static int stm32_adc_probe(struct platform_device *pdev) 392 438 { 393 439 struct stm32_adc_priv *priv; ··· 457 393 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 458 394 if (!priv) 459 395 return -ENOMEM; 396 + platform_set_drvdata(pdev, &priv->common); 460 397 461 398 priv->cfg = (const struct stm32_adc_priv_cfg *) 462 399 of_match_device(dev->driver->of_match_table, dev)->data; ··· 475 410 return ret; 476 411 } 477 412 478 - ret = regulator_enable(priv->vref); 479 - if (ret < 0) { 480 - dev_err(&pdev->dev, "vref enable failed\n"); 481 - return ret; 482 - } 483 - 484 - ret = regulator_get_voltage(priv->vref); 485 - if (ret < 0) { 486 - dev_err(&pdev->dev, "vref get voltage failed, %d\n", ret); 487 - goto err_regulator_disable; 488 - } 489 - priv->common.vref_mv = ret / 1000; 490 - dev_dbg(&pdev->dev, "vref+=%dmV\n", priv->common.vref_mv); 491 - 492 413 priv->aclk = devm_clk_get(&pdev->dev, "adc"); 493 414 if (IS_ERR(priv->aclk)) { 494 415 ret = PTR_ERR(priv->aclk); 495 - if (ret == -ENOENT) { 496 - priv->aclk = NULL; 497 - } else { 416 + if (ret != -ENOENT) { 498 417 dev_err(&pdev->dev, "Can't get 'adc' clock\n"); 499 - goto err_regulator_disable; 418 + return ret; 500 419 } 501 - } 502 - 503 - if (priv->aclk) { 504 - ret = clk_prepare_enable(priv->aclk); 505 - if (ret < 0) { 506 - dev_err(&pdev->dev, "adc clk enable failed\n"); 507 - goto err_regulator_disable; 508 - } 420 + priv->aclk = NULL; 509 421 } 510 422 511 423 priv->bclk = devm_clk_get(&pdev->dev, "bus"); 512 424 if (IS_ERR(priv->bclk)) { 513 425 ret = PTR_ERR(priv->bclk); 514 - if (ret == -ENOENT) { 515 - priv->bclk = NULL; 516 - } else { 426 + if (ret != -ENOENT) { 517 427 dev_err(&pdev->dev, "Can't get 'bus' clock\n"); 518 - goto err_aclk_disable; 428 + return ret; 519 429 } 430 + priv->bclk = NULL; 520 431 } 521 432 522 - if (priv->bclk) { 523 - ret = clk_prepare_enable(priv->bclk); 524 - if (ret < 0) { 525 - dev_err(&pdev->dev, "adc clk enable failed\n"); 526 - goto err_aclk_disable; 527 - } 433 + pm_runtime_get_noresume(dev); 434 + pm_runtime_set_active(dev); 435 + pm_runtime_set_autosuspend_delay(dev, STM32_ADC_CORE_SLEEP_DELAY_MS); 436 + pm_runtime_use_autosuspend(dev); 437 + pm_runtime_enable(dev); 438 + 439 + ret = stm32_adc_core_hw_start(dev); 440 + if (ret) 441 + goto err_pm_stop; 442 + 443 + ret = regulator_get_voltage(priv->vref); 444 + if (ret < 0) { 445 + dev_err(&pdev->dev, "vref get voltage failed, %d\n", ret); 446 + goto err_hw_stop; 528 447 } 448 + priv->common.vref_mv = ret / 1000; 449 + dev_dbg(&pdev->dev, "vref+=%dmV\n", priv->common.vref_mv); 529 450 530 451 ret = priv->cfg->clk_sel(pdev, priv); 531 452 if (ret < 0) 532 - goto err_bclk_disable; 453 + goto err_hw_stop; 533 454 534 455 ret = stm32_adc_irq_probe(pdev, priv); 535 456 if (ret < 0) 536 - goto err_bclk_disable; 537 - 538 - platform_set_drvdata(pdev, &priv->common); 457 + goto err_hw_stop; 539 458 540 459 ret = of_platform_populate(np, NULL, NULL, &pdev->dev); 541 460 if (ret < 0) { ··· 527 478 goto err_irq_remove; 528 479 } 529 480 481 + pm_runtime_mark_last_busy(dev); 482 + pm_runtime_put_autosuspend(dev); 483 + 530 484 return 0; 531 485 532 486 err_irq_remove: 533 487 stm32_adc_irq_remove(pdev, priv); 534 - 535 - err_bclk_disable: 536 - if (priv->bclk) 537 - clk_disable_unprepare(priv->bclk); 538 - 539 - err_aclk_disable: 540 - if (priv->aclk) 541 - clk_disable_unprepare(priv->aclk); 542 - 543 - err_regulator_disable: 544 - regulator_disable(priv->vref); 488 + err_hw_stop: 489 + stm32_adc_core_hw_stop(dev); 490 + err_pm_stop: 491 + pm_runtime_disable(dev); 492 + pm_runtime_set_suspended(dev); 493 + pm_runtime_put_noidle(dev); 545 494 546 495 return ret; 547 496 } ··· 549 502 struct stm32_adc_common *common = platform_get_drvdata(pdev); 550 503 struct stm32_adc_priv *priv = to_stm32_adc_priv(common); 551 504 505 + pm_runtime_get_sync(&pdev->dev); 552 506 of_platform_depopulate(&pdev->dev); 553 507 stm32_adc_irq_remove(pdev, priv); 554 - if (priv->bclk) 555 - clk_disable_unprepare(priv->bclk); 556 - if (priv->aclk) 557 - clk_disable_unprepare(priv->aclk); 558 - regulator_disable(priv->vref); 508 + stm32_adc_core_hw_stop(&pdev->dev); 509 + pm_runtime_disable(&pdev->dev); 510 + pm_runtime_set_suspended(&pdev->dev); 511 + pm_runtime_put_noidle(&pdev->dev); 559 512 560 513 return 0; 561 514 } 515 + 516 + #if defined(CONFIG_PM) 517 + static int stm32_adc_core_runtime_suspend(struct device *dev) 518 + { 519 + stm32_adc_core_hw_stop(dev); 520 + 521 + return 0; 522 + } 523 + 524 + static int stm32_adc_core_runtime_resume(struct device *dev) 525 + { 526 + return stm32_adc_core_hw_start(dev); 527 + } 528 + #endif 529 + 530 + static const struct dev_pm_ops stm32_adc_core_pm_ops = { 531 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 532 + pm_runtime_force_resume) 533 + SET_RUNTIME_PM_OPS(stm32_adc_core_runtime_suspend, 534 + stm32_adc_core_runtime_resume, 535 + NULL) 536 + }; 562 537 563 538 static const struct stm32_adc_priv_cfg stm32f4_adc_priv_cfg = { 564 539 .regs = &stm32f4_adc_common_regs, ··· 621 552 .driver = { 622 553 .name = "stm32-adc-core", 623 554 .of_match_table = stm32_adc_of_match, 555 + .pm = &stm32_adc_core_pm_ops, 624 556 }, 625 557 }; 626 558 module_platform_driver(stm32_adc_driver);
+217 -86
drivers/iio/adc/stm32-adc.c
··· 22 22 #include <linux/iopoll.h> 23 23 #include <linux/module.h> 24 24 #include <linux/platform_device.h> 25 + #include <linux/pm_runtime.h> 25 26 #include <linux/of.h> 26 27 #include <linux/of_device.h> 27 28 ··· 149 148 #define STM32_ADC_MAX_SMP 7 /* SMPx range is [0..7] */ 150 149 #define STM32_ADC_TIMEOUT_US 100000 151 150 #define STM32_ADC_TIMEOUT (msecs_to_jiffies(STM32_ADC_TIMEOUT_US / 1000)) 151 + #define STM32_ADC_HW_STOP_DELAY_MS 100 152 152 153 153 #define STM32_DMA_BUFFER_SIZE PAGE_SIZE 154 154 ··· 201 199 * @calfact_s: Calibration offset for single ended channels 202 200 * @calfact_d: Calibration offset in differential 203 201 * @lincalfact: Linearity calibration factor 202 + * @calibrated: Indicates calibration status 204 203 */ 205 204 struct stm32_adc_calib { 206 205 u32 calfact_s; 207 206 u32 calfact_d; 208 207 u32 lincalfact[STM32H7_LINCALFACT_NUM]; 208 + bool calibrated; 209 209 }; 210 210 211 211 /** ··· 255 251 * @trigs: external trigger sources 256 252 * @clk_required: clock is required 257 253 * @has_vregready: vregready status flag presence 258 - * @selfcalib: optional routine for self-calibration 259 254 * @prepare: optional prepare routine (power-up, enable) 260 255 * @start_conv: routine to start conversions 261 256 * @stop_conv: routine to stop conversions ··· 267 264 struct stm32_adc_trig_info *trigs; 268 265 bool clk_required; 269 266 bool has_vregready; 270 - int (*selfcalib)(struct stm32_adc *); 271 267 int (*prepare)(struct stm32_adc *); 272 268 void (*start_conv)(struct stm32_adc *, bool dma); 273 269 void (*stop_conv)(struct stm32_adc *); ··· 625 623 stm32_adc_writel(adc, res->reg, val); 626 624 } 627 625 626 + static int stm32_adc_hw_stop(struct device *dev) 627 + { 628 + struct stm32_adc *adc = dev_get_drvdata(dev); 629 + 630 + if (adc->cfg->unprepare) 631 + adc->cfg->unprepare(adc); 632 + 633 + if (adc->clk) 634 + clk_disable_unprepare(adc->clk); 635 + 636 + return 0; 637 + } 638 + 639 + static int stm32_adc_hw_start(struct device *dev) 640 + { 641 + struct stm32_adc *adc = dev_get_drvdata(dev); 642 + int ret; 643 + 644 + if (adc->clk) { 645 + ret = clk_prepare_enable(adc->clk); 646 + if (ret) 647 + return ret; 648 + } 649 + 650 + stm32_adc_set_res(adc); 651 + 652 + if (adc->cfg->prepare) { 653 + ret = adc->cfg->prepare(adc); 654 + if (ret) 655 + goto err_clk_dis; 656 + } 657 + 658 + return 0; 659 + 660 + err_clk_dis: 661 + if (adc->clk) 662 + clk_disable_unprepare(adc->clk); 663 + 664 + return ret; 665 + } 666 + 628 667 /** 629 668 * stm32f4_adc_start_conv() - Start conversions for regular channels. 630 669 * @adc: stm32 adc instance ··· 820 777 /** 821 778 * stm32h7_adc_read_selfcalib() - read calibration shadow regs, save result 822 779 * @adc: stm32 adc instance 780 + * Note: Must be called once ADC is enabled, so LINCALRDYW[1..6] are writable 823 781 */ 824 782 static int stm32h7_adc_read_selfcalib(struct stm32_adc *adc) 825 783 { 826 784 struct iio_dev *indio_dev = iio_priv_to_dev(adc); 827 785 int i, ret; 828 786 u32 lincalrdyw_mask, val; 829 - 830 - /* Enable adc so LINCALRDYW1..6 bits are writable */ 831 - ret = stm32h7_adc_enable(adc); 832 - if (ret) 833 - return ret; 834 787 835 788 /* Read linearity calibration */ 836 789 lincalrdyw_mask = STM32H7_LINCALRDYW6; ··· 840 801 100, STM32_ADC_TIMEOUT_US); 841 802 if (ret) { 842 803 dev_err(&indio_dev->dev, "Failed to read calfact\n"); 843 - goto disable; 804 + return ret; 844 805 } 845 806 846 807 val = stm32_adc_readl(adc, STM32H7_ADC_CALFACT2); ··· 856 817 adc->cal.calfact_s >>= STM32H7_CALFACT_S_SHIFT; 857 818 adc->cal.calfact_d = (val & STM32H7_CALFACT_D_MASK); 858 819 adc->cal.calfact_d >>= STM32H7_CALFACT_D_SHIFT; 820 + adc->cal.calibrated = true; 859 821 860 - disable: 861 - stm32h7_adc_disable(adc); 862 - 863 - return ret; 822 + return 0; 864 823 } 865 824 866 825 /** ··· 935 898 #define STM32H7_ADC_CALIB_TIMEOUT_US 100000 936 899 937 900 /** 938 - * stm32h7_adc_selfcalib() - Procedure to calibrate ADC (from power down) 901 + * stm32h7_adc_selfcalib() - Procedure to calibrate ADC 939 902 * @adc: stm32 adc instance 940 - * Exit from power down, calibrate ADC, then return to power down. 903 + * Note: Must be called once ADC is out of power down. 941 904 */ 942 905 static int stm32h7_adc_selfcalib(struct stm32_adc *adc) 943 906 { ··· 945 908 int ret; 946 909 u32 val; 947 910 948 - ret = stm32h7_adc_exit_pwr_down(adc); 949 - if (ret) 950 - return ret; 911 + if (adc->cal.calibrated) 912 + return true; 951 913 952 914 /* 953 915 * Select calibration mode: ··· 963 927 STM32H7_ADC_CALIB_TIMEOUT_US); 964 928 if (ret) { 965 929 dev_err(&indio_dev->dev, "calibration failed\n"); 966 - goto pwr_dwn; 930 + goto out; 967 931 } 968 932 969 933 /* ··· 980 944 STM32H7_ADC_CALIB_TIMEOUT_US); 981 945 if (ret) { 982 946 dev_err(&indio_dev->dev, "calibration failed\n"); 983 - goto pwr_dwn; 947 + goto out; 984 948 } 985 949 950 + out: 986 951 stm32_adc_clr_bits(adc, STM32H7_ADC_CR, 987 952 STM32H7_ADCALDIF | STM32H7_ADCALLIN); 988 - 989 - /* Read calibration result for future reference */ 990 - ret = stm32h7_adc_read_selfcalib(adc); 991 - 992 - pwr_dwn: 993 - stm32h7_adc_enter_pwr_down(adc); 994 953 995 954 return ret; 996 955 } ··· 1003 972 */ 1004 973 static int stm32h7_adc_prepare(struct stm32_adc *adc) 1005 974 { 1006 - int ret; 975 + int calib, ret; 1007 976 1008 977 ret = stm32h7_adc_exit_pwr_down(adc); 1009 978 if (ret) 1010 979 return ret; 980 + 981 + ret = stm32h7_adc_selfcalib(adc); 982 + if (ret < 0) 983 + goto pwr_dwn; 984 + calib = ret; 1011 985 1012 986 stm32_adc_writel(adc, STM32H7_ADC_DIFSEL, adc->difsel); 1013 987 ··· 1020 984 if (ret) 1021 985 goto pwr_dwn; 1022 986 1023 - ret = stm32h7_adc_restore_selfcalib(adc); 987 + /* Either restore or read calibration result for future reference */ 988 + if (calib) 989 + ret = stm32h7_adc_restore_selfcalib(adc); 990 + else 991 + ret = stm32h7_adc_read_selfcalib(adc); 1024 992 if (ret) 1025 993 goto disable; 1026 994 ··· 1214 1174 int *res) 1215 1175 { 1216 1176 struct stm32_adc *adc = iio_priv(indio_dev); 1177 + struct device *dev = indio_dev->dev.parent; 1217 1178 const struct stm32_adc_regspec *regs = adc->cfg->regs; 1218 1179 long timeout; 1219 1180 u32 val; ··· 1224 1183 1225 1184 adc->bufi = 0; 1226 1185 1227 - if (adc->cfg->prepare) { 1228 - ret = adc->cfg->prepare(adc); 1229 - if (ret) 1230 - return ret; 1186 + ret = pm_runtime_get_sync(dev); 1187 + if (ret < 0) { 1188 + pm_runtime_put_noidle(dev); 1189 + return ret; 1231 1190 } 1232 1191 1233 1192 /* Apply sampling time settings */ ··· 1265 1224 1266 1225 stm32_adc_conv_irq_disable(adc); 1267 1226 1268 - if (adc->cfg->unprepare) 1269 - adc->cfg->unprepare(adc); 1227 + pm_runtime_mark_last_busy(dev); 1228 + pm_runtime_put_autosuspend(dev); 1270 1229 1271 1230 return ret; 1272 1231 } ··· 1374 1333 const unsigned long *scan_mask) 1375 1334 { 1376 1335 struct stm32_adc *adc = iio_priv(indio_dev); 1336 + struct device *dev = indio_dev->dev.parent; 1377 1337 int ret; 1338 + 1339 + ret = pm_runtime_get_sync(dev); 1340 + if (ret < 0) { 1341 + pm_runtime_put_noidle(dev); 1342 + return ret; 1343 + } 1378 1344 1379 1345 adc->num_conv = bitmap_weight(scan_mask, indio_dev->masklength); 1380 1346 1381 1347 ret = stm32_adc_conf_scan_seq(indio_dev, scan_mask); 1382 - if (ret) 1383 - return ret; 1348 + pm_runtime_mark_last_busy(dev); 1349 + pm_runtime_put_autosuspend(dev); 1384 1350 1385 - return 0; 1351 + return ret; 1386 1352 } 1387 1353 1388 1354 static int stm32_adc_of_xlate(struct iio_dev *indio_dev, ··· 1419 1371 unsigned *readval) 1420 1372 { 1421 1373 struct stm32_adc *adc = iio_priv(indio_dev); 1374 + struct device *dev = indio_dev->dev.parent; 1375 + int ret; 1376 + 1377 + ret = pm_runtime_get_sync(dev); 1378 + if (ret < 0) { 1379 + pm_runtime_put_noidle(dev); 1380 + return ret; 1381 + } 1422 1382 1423 1383 if (!readval) 1424 1384 stm32_adc_writel(adc, reg, writeval); 1425 1385 else 1426 1386 *readval = stm32_adc_readl(adc, reg); 1387 + 1388 + pm_runtime_mark_last_busy(dev); 1389 + pm_runtime_put_autosuspend(dev); 1427 1390 1428 1391 return 0; 1429 1392 } ··· 1518 1459 return 0; 1519 1460 } 1520 1461 1521 - static int stm32_adc_buffer_postenable(struct iio_dev *indio_dev) 1462 + static int __stm32_adc_buffer_postenable(struct iio_dev *indio_dev) 1522 1463 { 1523 1464 struct stm32_adc *adc = iio_priv(indio_dev); 1465 + struct device *dev = indio_dev->dev.parent; 1524 1466 int ret; 1525 1467 1526 - if (adc->cfg->prepare) { 1527 - ret = adc->cfg->prepare(adc); 1528 - if (ret) 1529 - return ret; 1468 + ret = pm_runtime_get_sync(dev); 1469 + if (ret < 0) { 1470 + pm_runtime_put_noidle(dev); 1471 + return ret; 1530 1472 } 1531 1473 1532 1474 ret = stm32_adc_set_trig(indio_dev, indio_dev->trig); 1533 1475 if (ret) { 1534 1476 dev_err(&indio_dev->dev, "Can't set trigger\n"); 1535 - goto err_unprepare; 1477 + goto err_pm_put; 1536 1478 } 1537 1479 1538 1480 ret = stm32_adc_dma_start(indio_dev); ··· 1541 1481 dev_err(&indio_dev->dev, "Can't start dma\n"); 1542 1482 goto err_clr_trig; 1543 1483 } 1544 - 1545 - ret = iio_triggered_buffer_postenable(indio_dev); 1546 - if (ret < 0) 1547 - goto err_stop_dma; 1548 1484 1549 1485 /* Reset adc buffer index */ 1550 1486 adc->bufi = 0; ··· 1552 1496 1553 1497 return 0; 1554 1498 1555 - err_stop_dma: 1556 - if (adc->dma_chan) 1557 - dmaengine_terminate_all(adc->dma_chan); 1558 1499 err_clr_trig: 1559 1500 stm32_adc_set_trig(indio_dev, NULL); 1560 - err_unprepare: 1561 - if (adc->cfg->unprepare) 1562 - adc->cfg->unprepare(adc); 1501 + err_pm_put: 1502 + pm_runtime_mark_last_busy(dev); 1503 + pm_runtime_put_autosuspend(dev); 1563 1504 1564 1505 return ret; 1565 1506 } 1566 1507 1567 - static int stm32_adc_buffer_predisable(struct iio_dev *indio_dev) 1508 + static int stm32_adc_buffer_postenable(struct iio_dev *indio_dev) 1509 + { 1510 + int ret; 1511 + 1512 + ret = iio_triggered_buffer_postenable(indio_dev); 1513 + if (ret < 0) 1514 + return ret; 1515 + 1516 + ret = __stm32_adc_buffer_postenable(indio_dev); 1517 + if (ret < 0) 1518 + iio_triggered_buffer_predisable(indio_dev); 1519 + 1520 + return ret; 1521 + } 1522 + 1523 + static void __stm32_adc_buffer_predisable(struct iio_dev *indio_dev) 1568 1524 { 1569 1525 struct stm32_adc *adc = iio_priv(indio_dev); 1570 - int ret; 1526 + struct device *dev = indio_dev->dev.parent; 1571 1527 1572 1528 adc->cfg->stop_conv(adc); 1573 1529 if (!adc->dma_chan) 1574 1530 stm32_adc_conv_irq_disable(adc); 1575 - 1576 - ret = iio_triggered_buffer_predisable(indio_dev); 1577 - if (ret < 0) 1578 - dev_err(&indio_dev->dev, "predisable failed\n"); 1579 1531 1580 1532 if (adc->dma_chan) 1581 1533 dmaengine_terminate_all(adc->dma_chan); ··· 1591 1527 if (stm32_adc_set_trig(indio_dev, NULL)) 1592 1528 dev_err(&indio_dev->dev, "Can't clear trigger\n"); 1593 1529 1594 - if (adc->cfg->unprepare) 1595 - adc->cfg->unprepare(adc); 1530 + pm_runtime_mark_last_busy(dev); 1531 + pm_runtime_put_autosuspend(dev); 1532 + } 1533 + 1534 + static int stm32_adc_buffer_predisable(struct iio_dev *indio_dev) 1535 + { 1536 + int ret; 1537 + 1538 + __stm32_adc_buffer_predisable(indio_dev); 1539 + 1540 + ret = iio_triggered_buffer_predisable(indio_dev); 1541 + if (ret < 0) 1542 + dev_err(&indio_dev->dev, "predisable failed\n"); 1596 1543 1597 1544 return ret; 1598 1545 } ··· 1942 1867 } 1943 1868 } 1944 1869 1945 - if (adc->clk) { 1946 - ret = clk_prepare_enable(adc->clk); 1947 - if (ret < 0) { 1948 - dev_err(&pdev->dev, "clk enable failed\n"); 1949 - return ret; 1950 - } 1951 - } 1952 - 1953 1870 ret = stm32_adc_of_get_resolution(indio_dev); 1954 1871 if (ret < 0) 1955 - goto err_clk_disable; 1956 - stm32_adc_set_res(adc); 1957 - 1958 - if (adc->cfg->selfcalib) { 1959 - ret = adc->cfg->selfcalib(adc); 1960 - if (ret) 1961 - goto err_clk_disable; 1962 - } 1872 + return ret; 1963 1873 1964 1874 ret = stm32_adc_chan_of_init(indio_dev); 1965 1875 if (ret < 0) 1966 - goto err_clk_disable; 1876 + return ret; 1967 1877 1968 1878 ret = stm32_adc_dma_request(indio_dev); 1969 1879 if (ret < 0) 1970 - goto err_clk_disable; 1880 + return ret; 1971 1881 1972 1882 ret = iio_triggered_buffer_setup(indio_dev, 1973 1883 &iio_pollfunc_store_time, ··· 1963 1903 goto err_dma_disable; 1964 1904 } 1965 1905 1906 + /* Get stm32-adc-core PM online */ 1907 + pm_runtime_get_noresume(dev); 1908 + pm_runtime_set_active(dev); 1909 + pm_runtime_set_autosuspend_delay(dev, STM32_ADC_HW_STOP_DELAY_MS); 1910 + pm_runtime_use_autosuspend(dev); 1911 + pm_runtime_enable(dev); 1912 + 1913 + ret = stm32_adc_hw_start(dev); 1914 + if (ret) 1915 + goto err_buffer_cleanup; 1916 + 1966 1917 ret = iio_device_register(indio_dev); 1967 1918 if (ret) { 1968 1919 dev_err(&pdev->dev, "iio dev register failed\n"); 1969 - goto err_buffer_cleanup; 1920 + goto err_hw_stop; 1970 1921 } 1922 + 1923 + pm_runtime_mark_last_busy(dev); 1924 + pm_runtime_put_autosuspend(dev); 1971 1925 1972 1926 return 0; 1973 1927 1928 + err_hw_stop: 1929 + stm32_adc_hw_stop(dev); 1930 + 1974 1931 err_buffer_cleanup: 1932 + pm_runtime_disable(dev); 1933 + pm_runtime_set_suspended(dev); 1934 + pm_runtime_put_noidle(dev); 1975 1935 iio_triggered_buffer_cleanup(indio_dev); 1976 1936 1977 1937 err_dma_disable: ··· 2001 1921 adc->rx_buf, adc->rx_dma_buf); 2002 1922 dma_release_channel(adc->dma_chan); 2003 1923 } 2004 - err_clk_disable: 2005 - if (adc->clk) 2006 - clk_disable_unprepare(adc->clk); 2007 1924 2008 1925 return ret; 2009 1926 } ··· 2010 1933 struct stm32_adc *adc = platform_get_drvdata(pdev); 2011 1934 struct iio_dev *indio_dev = iio_priv_to_dev(adc); 2012 1935 1936 + pm_runtime_get_sync(&pdev->dev); 2013 1937 iio_device_unregister(indio_dev); 1938 + stm32_adc_hw_stop(&pdev->dev); 1939 + pm_runtime_disable(&pdev->dev); 1940 + pm_runtime_set_suspended(&pdev->dev); 1941 + pm_runtime_put_noidle(&pdev->dev); 2014 1942 iio_triggered_buffer_cleanup(indio_dev); 2015 1943 if (adc->dma_chan) { 2016 1944 dma_free_coherent(adc->dma_chan->device->dev, ··· 2023 1941 adc->rx_buf, adc->rx_dma_buf); 2024 1942 dma_release_channel(adc->dma_chan); 2025 1943 } 2026 - if (adc->clk) 2027 - clk_disable_unprepare(adc->clk); 2028 1944 2029 1945 return 0; 2030 1946 } 1947 + 1948 + #if defined(CONFIG_PM_SLEEP) 1949 + static int stm32_adc_suspend(struct device *dev) 1950 + { 1951 + struct stm32_adc *adc = dev_get_drvdata(dev); 1952 + struct iio_dev *indio_dev = iio_priv_to_dev(adc); 1953 + 1954 + if (iio_buffer_enabled(indio_dev)) 1955 + __stm32_adc_buffer_predisable(indio_dev); 1956 + 1957 + return pm_runtime_force_suspend(dev); 1958 + } 1959 + 1960 + static int stm32_adc_resume(struct device *dev) 1961 + { 1962 + struct stm32_adc *adc = dev_get_drvdata(dev); 1963 + struct iio_dev *indio_dev = iio_priv_to_dev(adc); 1964 + int ret; 1965 + 1966 + ret = pm_runtime_force_resume(dev); 1967 + if (ret < 0) 1968 + return ret; 1969 + 1970 + if (!iio_buffer_enabled(indio_dev)) 1971 + return 0; 1972 + 1973 + ret = stm32_adc_update_scan_mode(indio_dev, 1974 + indio_dev->active_scan_mask); 1975 + if (ret < 0) 1976 + return ret; 1977 + 1978 + return __stm32_adc_buffer_postenable(indio_dev); 1979 + } 1980 + #endif 1981 + 1982 + #if defined(CONFIG_PM) 1983 + static int stm32_adc_runtime_suspend(struct device *dev) 1984 + { 1985 + return stm32_adc_hw_stop(dev); 1986 + } 1987 + 1988 + static int stm32_adc_runtime_resume(struct device *dev) 1989 + { 1990 + return stm32_adc_hw_start(dev); 1991 + } 1992 + #endif 1993 + 1994 + static const struct dev_pm_ops stm32_adc_pm_ops = { 1995 + SET_SYSTEM_SLEEP_PM_OPS(stm32_adc_suspend, stm32_adc_resume) 1996 + SET_RUNTIME_PM_OPS(stm32_adc_runtime_suspend, stm32_adc_runtime_resume, 1997 + NULL) 1998 + }; 2031 1999 2032 2000 static const struct stm32_adc_cfg stm32f4_adc_cfg = { 2033 2001 .regs = &stm32f4_adc_regspec, ··· 2093 1961 .regs = &stm32h7_adc_regspec, 2094 1962 .adc_info = &stm32h7_adc_info, 2095 1963 .trigs = stm32h7_adc_trigs, 2096 - .selfcalib = stm32h7_adc_selfcalib, 2097 1964 .start_conv = stm32h7_adc_start_conv, 2098 1965 .stop_conv = stm32h7_adc_stop_conv, 2099 1966 .prepare = stm32h7_adc_prepare, ··· 2105 1974 .adc_info = &stm32h7_adc_info, 2106 1975 .trigs = stm32h7_adc_trigs, 2107 1976 .has_vregready = true, 2108 - .selfcalib = stm32h7_adc_selfcalib, 2109 1977 .start_conv = stm32h7_adc_start_conv, 2110 1978 .stop_conv = stm32h7_adc_stop_conv, 2111 1979 .prepare = stm32h7_adc_prepare, ··· 2126 1996 .driver = { 2127 1997 .name = "stm32-adc", 2128 1998 .of_match_table = stm32_adc_of_match, 1999 + .pm = &stm32_adc_pm_ops, 2129 2000 }, 2130 2001 }; 2131 2002 module_platform_driver(stm32_adc_driver);
+1 -1
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
··· 336 336 scale1 = scale1 % pow_10(8 - i); 337 337 } 338 338 *val0 += res; 339 - *val1 = scale1 * pow_10(exp); 339 + *val1 = scale1 * pow_10(exp); 340 340 } else if (exp < 0) { 341 341 exp = abs(exp); 342 342 if (exp > 9) {
+18 -3
drivers/iio/dac/ad5686-spi.c
··· 19 19 u8 tx_len, *buf; 20 20 21 21 switch (st->chip_info->regmap_type) { 22 + case AD5310_REGMAP: 23 + st->data[0].d16 = cpu_to_be16(AD5310_CMD(cmd) | 24 + val); 25 + buf = &st->data[0].d8[0]; 26 + tx_len = 2; 27 + break; 22 28 case AD5683_REGMAP: 23 29 st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | 24 30 AD5683_DATA(val)); ··· 62 56 u8 cmd = 0; 63 57 int ret; 64 58 65 - if (st->chip_info->regmap_type == AD5686_REGMAP) 66 - cmd = AD5686_CMD_READBACK_ENABLE; 67 - else if (st->chip_info->regmap_type == AD5683_REGMAP) 59 + switch (st->chip_info->regmap_type) { 60 + case AD5310_REGMAP: 61 + return -ENOTSUPP; 62 + case AD5683_REGMAP: 68 63 cmd = AD5686_CMD_READBACK_ENABLE_V2; 64 + break; 65 + case AD5686_REGMAP: 66 + cmd = AD5686_CMD_READBACK_ENABLE; 67 + break; 68 + default: 69 + return -EINVAL; 70 + } 69 71 70 72 st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | 71 73 AD5686_ADDR(addr)); ··· 100 86 } 101 87 102 88 static const struct spi_device_id ad5686_spi_id[] = { 89 + {"ad5310r", ID_AD5310R}, 103 90 {"ad5672r", ID_AD5672R}, 104 91 {"ad5676", ID_AD5676}, 105 92 {"ad5676r", ID_AD5676R},
+18 -1
drivers/iio/dac/ad5686.c
··· 83 83 st->pwr_down_mask &= ~(0x3 << (chan->channel * 2)); 84 84 85 85 switch (st->chip_info->regmap_type) { 86 + case AD5310_REGMAP: 87 + shift = 9; 88 + ref_bit_msk = AD5310_REF_BIT_MSK; 89 + break; 86 90 case AD5683_REGMAP: 87 91 shift = 13; 88 92 ref_bit_msk = AD5683_REF_BIT_MSK; ··· 128 124 mutex_unlock(&indio_dev->mlock); 129 125 if (ret < 0) 130 126 return ret; 131 - *val = ret; 127 + *val = (ret >> chan->scan_type.shift) & 128 + GENMASK(chan->scan_type.realbits - 1, 0); 132 129 return IIO_VAL_INT; 133 130 case IIO_CHAN_INFO_SCALE: 134 131 *val = st->vref_mv; ··· 226 221 AD5868_CHANNEL(7, 7, bits, _shift), \ 227 222 } 228 223 224 + DECLARE_AD5693_CHANNELS(ad5310r_channels, 10, 2); 229 225 DECLARE_AD5693_CHANNELS(ad5311r_channels, 10, 6); 230 226 DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4); 231 227 DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0); ··· 238 232 DECLARE_AD5693_CHANNELS(ad5691r_channels, 12, 4); 239 233 240 234 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = { 235 + [ID_AD5310R] = { 236 + .channels = ad5310r_channels, 237 + .int_vref_mv = 2500, 238 + .num_channels = 1, 239 + .regmap_type = AD5310_REGMAP, 240 + }, 241 241 [ID_AD5311R] = { 242 242 .channels = ad5311r_channels, 243 243 .int_vref_mv = 2500, ··· 431 419 indio_dev->num_channels = st->chip_info->num_channels; 432 420 433 421 switch (st->chip_info->regmap_type) { 422 + case AD5310_REGMAP: 423 + cmd = AD5686_CMD_CONTROL_REG; 424 + ref_bit_msk = AD5310_REF_BIT_MSK; 425 + st->use_internal_vref = !voltage_uv; 426 + break; 434 427 case AD5683_REGMAP: 435 428 cmd = AD5686_CMD_CONTROL_REG; 436 429 ref_bit_msk = AD5683_REF_BIT_MSK;
+7
drivers/iio/dac/ad5686.h
··· 13 13 #include <linux/mutex.h> 14 14 #include <linux/kernel.h> 15 15 16 + #define AD5310_CMD(x) ((x) << 12) 17 + 16 18 #define AD5683_DATA(x) ((x) << 4) 19 + 17 20 #define AD5686_ADDR(x) ((x) << 16) 18 21 #define AD5686_CMD(x) ((x) << 20) 19 22 ··· 41 38 42 39 #define AD5686_CMD_CONTROL_REG 0x4 43 40 #define AD5686_CMD_READBACK_ENABLE_V2 0x5 41 + 42 + #define AD5310_REF_BIT_MSK BIT(8) 44 43 #define AD5683_REF_BIT_MSK BIT(12) 45 44 #define AD5693_REF_BIT_MSK BIT(12) 46 45 ··· 50 45 * ad5686_supported_device_ids: 51 46 */ 52 47 enum ad5686_supported_device_ids { 48 + ID_AD5310R, 53 49 ID_AD5311R, 54 50 ID_AD5671R, 55 51 ID_AD5672R, ··· 78 72 }; 79 73 80 74 enum ad5686_regmap_type { 75 + AD5310_REGMAP, 81 76 AD5683_REGMAP, 82 77 AD5686_REGMAP, 83 78 AD5693_REGMAP
-1
drivers/iio/imu/bmi160/bmi160.h
··· 6 6 7 7 int bmi160_core_probe(struct device *dev, struct regmap *regmap, 8 8 const char *name, bool use_spi); 9 - void bmi160_core_remove(struct device *dev); 10 9 11 10 #endif /* BMI160_H_ */
+14 -24
drivers/iio/imu/bmi160/bmi160_core.c
··· 542 542 return 0; 543 543 } 544 544 545 - static void bmi160_chip_uninit(struct bmi160_data *data) 545 + static void bmi160_chip_uninit(void *data) 546 546 { 547 - bmi160_set_mode(data, BMI160_GYRO, false); 548 - bmi160_set_mode(data, BMI160_ACCEL, false); 547 + struct bmi160_data *bmi_data = data; 548 + 549 + bmi160_set_mode(bmi_data, BMI160_GYRO, false); 550 + bmi160_set_mode(bmi_data, BMI160_ACCEL, false); 549 551 } 550 552 551 553 int bmi160_core_probe(struct device *dev, struct regmap *regmap, ··· 569 567 if (ret < 0) 570 568 return ret; 571 569 570 + ret = devm_add_action_or_reset(dev, bmi160_chip_uninit, data); 571 + if (ret < 0) 572 + return ret; 573 + 572 574 if (!name && ACPI_HANDLE(dev)) 573 575 name = bmi160_match_acpi_device(dev); 574 576 ··· 583 577 indio_dev->modes = INDIO_DIRECT_MODE; 584 578 indio_dev->info = &bmi160_info; 585 579 586 - ret = iio_triggered_buffer_setup(indio_dev, NULL, 587 - bmi160_trigger_handler, NULL); 580 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, 581 + bmi160_trigger_handler, NULL); 588 582 if (ret < 0) 589 - goto uninit; 583 + return ret; 590 584 591 - ret = iio_device_register(indio_dev); 585 + ret = devm_iio_device_register(dev, indio_dev); 592 586 if (ret < 0) 593 - goto buffer_cleanup; 587 + return ret; 594 588 595 589 return 0; 596 - buffer_cleanup: 597 - iio_triggered_buffer_cleanup(indio_dev); 598 - uninit: 599 - bmi160_chip_uninit(data); 600 - return ret; 601 590 } 602 591 EXPORT_SYMBOL_GPL(bmi160_core_probe); 603 - 604 - void bmi160_core_remove(struct device *dev) 605 - { 606 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 607 - struct bmi160_data *data = iio_priv(indio_dev); 608 - 609 - iio_device_unregister(indio_dev); 610 - iio_triggered_buffer_cleanup(indio_dev); 611 - bmi160_chip_uninit(data); 612 - } 613 - EXPORT_SYMBOL_GPL(bmi160_core_remove); 614 592 615 593 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com"); 616 594 MODULE_DESCRIPTION("Bosch BMI160 driver");
-8
drivers/iio/imu/bmi160/bmi160_i2c.c
··· 38 38 return bmi160_core_probe(&client->dev, regmap, name, false); 39 39 } 40 40 41 - static int bmi160_i2c_remove(struct i2c_client *client) 42 - { 43 - bmi160_core_remove(&client->dev); 44 - 45 - return 0; 46 - } 47 - 48 41 static const struct i2c_device_id bmi160_i2c_id[] = { 49 42 {"bmi160", 0}, 50 43 {} ··· 65 72 .of_match_table = of_match_ptr(bmi160_of_match), 66 73 }, 67 74 .probe = bmi160_i2c_probe, 68 - .remove = bmi160_i2c_remove, 69 75 .id_table = bmi160_i2c_id, 70 76 }; 71 77 module_i2c_driver(bmi160_i2c_driver);
-8
drivers/iio/imu/bmi160/bmi160_spi.c
··· 29 29 return bmi160_core_probe(&spi->dev, regmap, id->name, true); 30 30 } 31 31 32 - static int bmi160_spi_remove(struct spi_device *spi) 33 - { 34 - bmi160_core_remove(&spi->dev); 35 - 36 - return 0; 37 - } 38 - 39 32 static const struct spi_device_id bmi160_spi_id[] = { 40 33 {"bmi160", 0}, 41 34 {} ··· 51 58 52 59 static struct spi_driver bmi160_spi_driver = { 53 60 .probe = bmi160_spi_probe, 54 - .remove = bmi160_spi_remove, 55 61 .id_table = bmi160_spi_id, 56 62 .driver = { 57 63 .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
+8 -6
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
··· 432 432 struct iio_chan_spec const *ch, 433 433 int *val) 434 434 { 435 - int err, delay, len = ch->scan_type.realbits >> 3; 436 - __le16 data; 435 + int err, delay, len; 436 + u8 data[4]; 437 437 438 438 err = st_lsm6dsx_shub_set_enable(sensor, true); 439 439 if (err < 0) ··· 442 442 delay = 1000000 / sensor->odr; 443 443 usleep_range(delay, 2 * delay); 444 444 445 - err = st_lsm6dsx_shub_read(sensor, ch->address, (u8 *)&data, len); 446 - if (err < 0) 447 - return err; 445 + len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3); 446 + err = st_lsm6dsx_shub_read(sensor, ch->address, data, len); 448 447 449 448 st_lsm6dsx_shub_set_enable(sensor, false); 450 449 450 + if (err < 0) 451 + return err; 452 + 451 453 switch (len) { 452 454 case 2: 453 - *val = (s16)le16_to_cpu(data); 455 + *val = (s16)le16_to_cpu(*((__le16 *)data)); 454 456 break; 455 457 default: 456 458 return -EINVAL;
+3
drivers/iio/industrialio-core.c
··· 1671 1671 if (ret < 0) 1672 1672 return ret; 1673 1673 1674 + if (!indio_dev->info) 1675 + return -EINVAL; 1676 + 1674 1677 /* configure elements for the chrdev */ 1675 1678 indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id); 1676 1679
+1
drivers/iio/magnetometer/ak8975.c
··· 790 790 {"INVN6500", AK8963}, 791 791 {"AK009911", AK09911}, 792 792 {"AK09911", AK09911}, 793 + {"AKM9911", AK09911}, 793 794 {"AK09912", AK09912}, 794 795 { }, 795 796 };
+12
drivers/iio/potentiometer/Kconfig
··· 90 90 To compile this driver as a module, choose M here: the 91 91 module will be called mcp4531. 92 92 93 + config MCP41010 94 + tristate "Microchip MCP41xxx/MCP42xxx Digital Potentiometer driver" 95 + depends on SPI 96 + help 97 + Say yes here to build support for the Microchip 98 + MCP41010, MCP41050, MCP41100, 99 + MCP42010, MCP42050, MCP42100 100 + digital potentiometer chips. 101 + 102 + To compile this driver as a module, choose M here: the 103 + module will be called mcp41010. 104 + 93 105 config TPL0102 94 106 tristate "Texas Instruments digital potentiometer driver" 95 107 depends on I2C
+1
drivers/iio/potentiometer/Makefile
··· 11 11 obj-$(CONFIG_MCP4018) += mcp4018.o 12 12 obj-$(CONFIG_MCP4131) += mcp4131.o 13 13 obj-$(CONFIG_MCP4531) += mcp4531.o 14 + obj-$(CONFIG_MCP41010) += mcp41010.o 14 15 obj-$(CONFIG_TPL0102) += tpl0102.o
+203
drivers/iio/potentiometer/mcp41010.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Industrial I/O driver for Microchip digital potentiometers 4 + * 5 + * Copyright (c) 2018 Chris Coffey <cmc@babblebit.net> 6 + * Based on: Slawomir Stepien's code from mcp4131.c 7 + * 8 + * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf 9 + * 10 + * DEVID #Wipers #Positions Resistance (kOhm) 11 + * mcp41010 1 256 10 12 + * mcp41050 1 256 50 13 + * mcp41100 1 256 100 14 + * mcp42010 2 256 10 15 + * mcp42050 2 256 50 16 + * mcp42100 2 256 100 17 + */ 18 + 19 + #include <linux/cache.h> 20 + #include <linux/err.h> 21 + #include <linux/iio/iio.h> 22 + #include <linux/iio/types.h> 23 + #include <linux/module.h> 24 + #include <linux/mutex.h> 25 + #include <linux/of.h> 26 + #include <linux/of_device.h> 27 + #include <linux/spi/spi.h> 28 + 29 + #define MCP41010_MAX_WIPERS 2 30 + #define MCP41010_WRITE BIT(4) 31 + #define MCP41010_WIPER_MAX 255 32 + #define MCP41010_WIPER_CHANNEL BIT(0) 33 + 34 + struct mcp41010_cfg { 35 + char name[16]; 36 + int wipers; 37 + int kohms; 38 + }; 39 + 40 + enum mcp41010_type { 41 + MCP41010, 42 + MCP41050, 43 + MCP41100, 44 + MCP42010, 45 + MCP42050, 46 + MCP42100, 47 + }; 48 + 49 + static const struct mcp41010_cfg mcp41010_cfg[] = { 50 + [MCP41010] = { .name = "mcp41010", .wipers = 1, .kohms = 10, }, 51 + [MCP41050] = { .name = "mcp41050", .wipers = 1, .kohms = 50, }, 52 + [MCP41100] = { .name = "mcp41100", .wipers = 1, .kohms = 100, }, 53 + [MCP42010] = { .name = "mcp42010", .wipers = 2, .kohms = 10, }, 54 + [MCP42050] = { .name = "mcp42050", .wipers = 2, .kohms = 50, }, 55 + [MCP42100] = { .name = "mcp42100", .wipers = 2, .kohms = 100, }, 56 + }; 57 + 58 + struct mcp41010_data { 59 + struct spi_device *spi; 60 + const struct mcp41010_cfg *cfg; 61 + struct mutex lock; /* Protect write sequences */ 62 + unsigned int value[MCP41010_MAX_WIPERS]; /* Cache wiper values */ 63 + u8 buf[2] ____cacheline_aligned; 64 + }; 65 + 66 + #define MCP41010_CHANNEL(ch) { \ 67 + .type = IIO_RESISTANCE, \ 68 + .indexed = 1, \ 69 + .output = 1, \ 70 + .channel = (ch), \ 71 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 72 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 73 + } 74 + 75 + static const struct iio_chan_spec mcp41010_channels[] = { 76 + MCP41010_CHANNEL(0), 77 + MCP41010_CHANNEL(1), 78 + }; 79 + 80 + static int mcp41010_read_raw(struct iio_dev *indio_dev, 81 + struct iio_chan_spec const *chan, 82 + int *val, int *val2, long mask) 83 + { 84 + struct mcp41010_data *data = iio_priv(indio_dev); 85 + int channel = chan->channel; 86 + 87 + switch (mask) { 88 + case IIO_CHAN_INFO_RAW: 89 + *val = data->value[channel]; 90 + return IIO_VAL_INT; 91 + 92 + case IIO_CHAN_INFO_SCALE: 93 + *val = 1000 * data->cfg->kohms; 94 + *val2 = MCP41010_WIPER_MAX; 95 + return IIO_VAL_FRACTIONAL; 96 + } 97 + 98 + return -EINVAL; 99 + } 100 + 101 + static int mcp41010_write_raw(struct iio_dev *indio_dev, 102 + struct iio_chan_spec const *chan, 103 + int val, int val2, long mask) 104 + { 105 + int err; 106 + struct mcp41010_data *data = iio_priv(indio_dev); 107 + int channel = chan->channel; 108 + 109 + if (mask != IIO_CHAN_INFO_RAW) 110 + return -EINVAL; 111 + 112 + if (val > MCP41010_WIPER_MAX || val < 0) 113 + return -EINVAL; 114 + 115 + mutex_lock(&data->lock); 116 + 117 + data->buf[0] = MCP41010_WIPER_CHANNEL << channel; 118 + data->buf[0] |= MCP41010_WRITE; 119 + data->buf[1] = val & 0xff; 120 + 121 + err = spi_write(data->spi, data->buf, sizeof(data->buf)); 122 + if (!err) 123 + data->value[channel] = val; 124 + 125 + mutex_unlock(&data->lock); 126 + 127 + return err; 128 + } 129 + 130 + static const struct iio_info mcp41010_info = { 131 + .read_raw = mcp41010_read_raw, 132 + .write_raw = mcp41010_write_raw, 133 + }; 134 + 135 + static int mcp41010_probe(struct spi_device *spi) 136 + { 137 + int err; 138 + struct device *dev = &spi->dev; 139 + struct mcp41010_data *data; 140 + struct iio_dev *indio_dev; 141 + 142 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 143 + if (!indio_dev) 144 + return -ENOMEM; 145 + 146 + data = iio_priv(indio_dev); 147 + spi_set_drvdata(spi, indio_dev); 148 + data->spi = spi; 149 + data->cfg = of_device_get_match_data(&spi->dev); 150 + if (!data->cfg) 151 + data->cfg = &mcp41010_cfg[spi_get_device_id(spi)->driver_data]; 152 + 153 + mutex_init(&data->lock); 154 + 155 + indio_dev->dev.parent = dev; 156 + indio_dev->info = &mcp41010_info; 157 + indio_dev->channels = mcp41010_channels; 158 + indio_dev->num_channels = data->cfg->wipers; 159 + indio_dev->name = data->cfg->name; 160 + 161 + err = devm_iio_device_register(dev, indio_dev); 162 + if (err) 163 + dev_info(&spi->dev, "Unable to register %s\n", indio_dev->name); 164 + 165 + return err; 166 + } 167 + 168 + static const struct of_device_id mcp41010_match[] = { 169 + { .compatible = "microchip,mcp41010", .data = &mcp41010_cfg[MCP41010] }, 170 + { .compatible = "microchip,mcp41050", .data = &mcp41010_cfg[MCP41050] }, 171 + { .compatible = "microchip,mcp41100", .data = &mcp41010_cfg[MCP41100] }, 172 + { .compatible = "microchip,mcp42010", .data = &mcp41010_cfg[MCP42010] }, 173 + { .compatible = "microchip,mcp42050", .data = &mcp41010_cfg[MCP42050] }, 174 + { .compatible = "microchip,mcp42100", .data = &mcp41010_cfg[MCP42100] }, 175 + {} 176 + }; 177 + MODULE_DEVICE_TABLE(of, mcp41010_match); 178 + 179 + static const struct spi_device_id mcp41010_id[] = { 180 + { "mcp41010", MCP41010 }, 181 + { "mcp41050", MCP41050 }, 182 + { "mcp41100", MCP41100 }, 183 + { "mcp42010", MCP42010 }, 184 + { "mcp42050", MCP42050 }, 185 + { "mcp42100", MCP42100 }, 186 + {} 187 + }; 188 + MODULE_DEVICE_TABLE(spi, mcp41010_id); 189 + 190 + static struct spi_driver mcp41010_driver = { 191 + .driver = { 192 + .name = "mcp41010", 193 + .of_match_table = mcp41010_match, 194 + }, 195 + .probe = mcp41010_probe, 196 + .id_table = mcp41010_id, 197 + }; 198 + 199 + module_spi_driver(mcp41010_driver); 200 + 201 + MODULE_AUTHOR("Chris Coffey <cmc@babblebit.net>"); 202 + MODULE_DESCRIPTION("MCP41010 digital potentiometer"); 203 + MODULE_LICENSE("GPL v2");
+10
drivers/iio/resolver/Kconfig
··· 3 3 # 4 4 menu "Resolver to digital converters" 5 5 6 + config AD2S90 7 + tristate "Analog Devices ad2s90 driver" 8 + depends on SPI 9 + help 10 + Say yes here to build support for Analog Devices spi resolver 11 + to digital converters, ad2s90, provides direct access via sysfs. 12 + 13 + To compile this driver as a module, choose M here: the 14 + module will be called ad2s90. 15 + 6 16 config AD2S1200 7 17 tristate "Analog Devices ad2s1200/ad2s1205 driver" 8 18 depends on SPI
+1
drivers/iio/resolver/Makefile
··· 2 2 # Makefile for Resolver/Synchro drivers 3 3 # 4 4 5 + obj-$(CONFIG_AD2S90) += ad2s90.o 5 6 obj-$(CONFIG_AD2S1200) += ad2s1200.o
+25 -26
drivers/staging/iio/adc/ad7280a.c
··· 561 561 { 562 562 int dev, ch, cnt; 563 563 unsigned int index; 564 + struct iio_dev_attr *iio_attr; 564 565 565 566 st->iio_attr = devm_kcalloc(&st->spi->dev, 2, sizeof(*st->iio_attr) * 566 567 (st->slave_num + 1) * AD7280A_CELLS_PER_DEV, ··· 572 571 for (dev = 0, cnt = 0; dev <= st->slave_num; dev++) 573 572 for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6; 574 573 ch++, cnt++) { 574 + iio_attr = &st->iio_attr[cnt]; 575 575 index = dev * AD7280A_CELLS_PER_DEV + ch; 576 - st->iio_attr[cnt].address = 577 - ad7280a_devaddr(dev) << 8 | ch; 578 - st->iio_attr[cnt].dev_attr.attr.mode = 579 - 0644; 580 - st->iio_attr[cnt].dev_attr.show = 581 - ad7280_show_balance_sw; 582 - st->iio_attr[cnt].dev_attr.store = 583 - ad7280_store_balance_sw; 584 - st->iio_attr[cnt].dev_attr.attr.name = 576 + iio_attr->address = ad7280a_devaddr(dev) << 8 | ch; 577 + iio_attr->dev_attr.attr.mode = 0644; 578 + iio_attr->dev_attr.show = ad7280_show_balance_sw; 579 + iio_attr->dev_attr.store = ad7280_store_balance_sw; 580 + iio_attr->dev_attr.attr.name = 585 581 devm_kasprintf(&st->spi->dev, GFP_KERNEL, 586 582 "in%d-in%d_balance_switch_en", 587 583 index, index + 1); 588 - ad7280_attributes[cnt] = 589 - &st->iio_attr[cnt].dev_attr.attr; 584 + if (!iio_attr->dev_attr.attr.name) 585 + return -ENOMEM; 586 + 587 + ad7280_attributes[cnt] = &iio_attr->dev_attr.attr; 590 588 cnt++; 591 - st->iio_attr[cnt].address = 592 - ad7280a_devaddr(dev) << 8 | 589 + iio_attr = &st->iio_attr[cnt]; 590 + iio_attr->address = ad7280a_devaddr(dev) << 8 | 593 591 (AD7280A_CB1_TIMER + ch); 594 - st->iio_attr[cnt].dev_attr.attr.mode = 595 - 0644; 596 - st->iio_attr[cnt].dev_attr.show = 597 - ad7280_show_balance_timer; 598 - st->iio_attr[cnt].dev_attr.store = 599 - ad7280_store_balance_timer; 600 - st->iio_attr[cnt].dev_attr.attr.name = 592 + iio_attr->dev_attr.attr.mode = 0644; 593 + iio_attr->dev_attr.show = ad7280_show_balance_timer; 594 + iio_attr->dev_attr.store = ad7280_store_balance_timer; 595 + iio_attr->dev_attr.attr.name = 601 596 devm_kasprintf(&st->spi->dev, GFP_KERNEL, 602 597 "in%d-in%d_balance_timer", 603 598 index, index + 1); 604 - ad7280_attributes[cnt] = 605 - &st->iio_attr[cnt].dev_attr.attr; 599 + if (!iio_attr->dev_attr.attr.name) 600 + return -ENOMEM; 601 + 602 + ad7280_attributes[cnt] = &iio_attr->dev_attr.attr; 606 603 } 607 604 608 605 ad7280_attributes[cnt] = NULL; ··· 879 880 if (ret < 0) 880 881 return ret; 881 882 882 - ret = devm_add_action_or_reset(&spi->dev, ad7280_sw_power_down, st); 883 - if (ret) 884 - return ret; 885 - 886 883 st->slave_num = ret; 887 884 st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH; 888 885 st->cell_threshhigh = 0xFF; 889 886 st->aux_threshhigh = 0xFF; 887 + 888 + ret = devm_add_action_or_reset(&spi->dev, ad7280_sw_power_down, st); 889 + if (ret) 890 + return ret; 890 891 891 892 /* 892 893 * Total Conversion Time = ((tACQ + tCONV) *
+13 -5
drivers/staging/iio/addac/adt7316-i2c.c
··· 30 30 } 31 31 32 32 ret = i2c_smbus_read_byte(client); 33 - 34 - if (!ret) 35 - return -EIO; 36 - 37 33 if (ret < 0) { 38 34 dev_err(&cl->dev, "I2C read error\n"); 39 35 return ret; ··· 100 104 struct adt7316_bus bus = { 101 105 .client = client, 102 106 .irq = client->irq, 103 - .irq_flags = IRQF_TRIGGER_LOW, 104 107 .read = adt7316_i2c_read, 105 108 .write = adt7316_i2c_write, 106 109 .multi_read = adt7316_i2c_multi_read, ··· 121 126 122 127 MODULE_DEVICE_TABLE(i2c, adt7316_i2c_id); 123 128 129 + static const struct of_device_id adt7316_of_match[] = { 130 + { .compatible = "adi,adt7316" }, 131 + { .compatible = "adi,adt7317" }, 132 + { .compatible = "adi,adt7318" }, 133 + { .compatible = "adi,adt7516" }, 134 + { .compatible = "adi,adt7517" }, 135 + { .compatible = "adi,adt7519" }, 136 + { }, 137 + }; 138 + 139 + MODULE_DEVICE_TABLE(of, adt7316_of_match); 140 + 124 141 static struct i2c_driver adt7316_driver = { 125 142 .driver = { 126 143 .name = "adt7316", 144 + .of_match_table = adt7316_of_match, 127 145 .pm = ADT7316_PM_OPS, 128 146 }, 129 147 .probe = adt7316_i2c_probe,
-1
drivers/staging/iio/addac/adt7316-spi.c
··· 94 94 struct adt7316_bus bus = { 95 95 .client = spi_dev, 96 96 .irq = spi_dev->irq, 97 - .irq_flags = IRQF_TRIGGER_LOW, 98 97 .read = adt7316_spi_read, 99 98 .write = adt7316_spi_write, 100 99 .multi_read = adt7316_spi_multi_read,
+14 -8
drivers/staging/iio/addac/adt7316.c
··· 177 177 178 178 struct adt7316_chip_info { 179 179 struct adt7316_bus bus; 180 - u16 ldac_pin; 180 + struct gpio_desc *ldac_pin; 181 181 u16 int_mask; /* 0x2f */ 182 182 u8 config1; 183 183 u8 config2; ··· 950 950 if (ret) 951 951 return -EIO; 952 952 } else { 953 - gpio_set_value(chip->ldac_pin, 0); 954 - gpio_set_value(chip->ldac_pin, 1); 953 + gpiod_set_value(chip->ldac_pin, 0); 954 + gpiod_set_value(chip->ldac_pin, 1); 955 955 } 956 956 957 957 return len; ··· 2104 2104 struct adt7316_chip_info *chip; 2105 2105 struct iio_dev *indio_dev; 2106 2106 unsigned short *adt7316_platform_data = dev->platform_data; 2107 + int irq_type = IRQF_TRIGGER_LOW; 2107 2108 int ret = 0; 2108 2109 2109 2110 indio_dev = devm_iio_device_alloc(dev, sizeof(*chip)); ··· 2123 2122 else 2124 2123 return -ENODEV; 2125 2124 2126 - chip->ldac_pin = adt7316_platform_data[1]; 2125 + chip->ldac_pin = devm_gpiod_get_optional(dev, "adi,ldac", GPIOD_OUT_LOW); 2126 + if (IS_ERR(chip->ldac_pin)) { 2127 + ret = PTR_ERR(chip->ldac_pin); 2128 + dev_err(dev, "Failed to request ldac GPIO: %d\n", ret); 2129 + return ret; 2130 + } 2131 + 2127 2132 if (chip->ldac_pin) { 2128 2133 chip->config3 |= ADT7316_DA_EN_VIA_DAC_LDCA; 2129 2134 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) ··· 2149 2142 2150 2143 if (chip->bus.irq > 0) { 2151 2144 if (adt7316_platform_data[0]) 2152 - chip->bus.irq_flags = adt7316_platform_data[0]; 2145 + irq_type = adt7316_platform_data[0]; 2153 2146 2154 2147 ret = devm_request_threaded_irq(dev, chip->bus.irq, 2155 2148 NULL, 2156 2149 adt7316_event_handler, 2157 - chip->bus.irq_flags | 2158 - IRQF_ONESHOT, 2150 + irq_type | IRQF_ONESHOT, 2159 2151 indio_dev->name, 2160 2152 indio_dev); 2161 2153 if (ret) 2162 2154 return ret; 2163 2155 2164 - if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH) 2156 + if (irq_type & IRQF_TRIGGER_HIGH) 2165 2157 chip->config1 |= ADT7316_INT_POLARITY; 2166 2158 } 2167 2159
-1
drivers/staging/iio/addac/adt7316.h
··· 17 17 struct adt7316_bus { 18 18 void *client; 19 19 int irq; 20 - int irq_flags; 21 20 int (*read)(void *client, u8 reg, u8 *data); 22 21 int (*write)(void *client, u8 reg, u8 val); 23 22 int (*multi_read)(void *client, u8 first_reg, u8 count, u8 *data);
+9
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 786 786 787 787 MODULE_DEVICE_TABLE(i2c, ad5933_id); 788 788 789 + static const struct of_device_id ad5933_of_match[] = { 790 + { .compatible = "adi,ad5933" }, 791 + { .compatible = "adi,ad5934" }, 792 + { }, 793 + }; 794 + 795 + MODULE_DEVICE_TABLE(of, ad5933_of_match); 796 + 789 797 static struct i2c_driver ad5933_driver = { 790 798 .driver = { 791 799 .name = "ad5933", 800 + .of_match_table = ad5933_of_match, 792 801 }, 793 802 .probe = ad5933_probe, 794 803 .remove = ad5933_remove,
-10
drivers/staging/iio/resolver/Kconfig
··· 3 3 # 4 4 menu "Resolver to digital converters" 5 5 6 - config AD2S90 7 - tristate "Analog Devices ad2s90 driver" 8 - depends on SPI 9 - help 10 - Say yes here to build support for Analog Devices spi resolver 11 - to digital converters, ad2s90, provides direct access via sysfs. 12 - 13 - To compile this driver as a module, choose M here: the 14 - module will be called ad2s90. 15 - 16 6 config AD2S1210 17 7 tristate "Analog Devices ad2s1210 driver" 18 8 depends on SPI
-1
drivers/staging/iio/resolver/Makefile
··· 2 2 # Makefile for Resolver/Synchro drivers 3 3 # 4 4 5 - obj-$(CONFIG_AD2S90) += ad2s90.o 6 5 obj-$(CONFIG_AD2S1210) += ad2s1210.o
+21 -17
drivers/staging/iio/resolver/ad2s90.c drivers/iio/resolver/ad2s90.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * ad2s90.c simple support for the ADI Resolver to Digital Converters: AD2S90 3 4 * 4 5 * Copyright (c) 2010-2010 Analog Devices Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - * 10 6 */ 11 7 #include <linux/types.h> 12 8 #include <linux/mutex.h> ··· 15 19 #include <linux/iio/iio.h> 16 20 #include <linux/iio/sysfs.h> 17 21 22 + /* 23 + * Although chip's max frequency is 2Mhz, it needs 600ns between CS and the 24 + * first falling edge of SCLK, so frequency should be at most 1 / (2 * 6e-7) 25 + */ 26 + #define AD2S90_MAX_SPI_FREQ_HZ 830000 27 + 18 28 struct ad2s90_state { 19 - struct mutex lock; 29 + struct mutex lock; /* lock to protect rx buffer */ 20 30 struct spi_device *sdev; 21 31 u8 rx[2] ____cacheline_aligned; 22 32 }; ··· 79 77 { 80 78 struct iio_dev *indio_dev; 81 79 struct ad2s90_state *st; 82 - int ret; 80 + 81 + if (spi->max_speed_hz > AD2S90_MAX_SPI_FREQ_HZ) { 82 + dev_err(&spi->dev, "SPI CLK, %d Hz exceeds %d Hz\n", 83 + spi->max_speed_hz, AD2S90_MAX_SPI_FREQ_HZ); 84 + return -EINVAL; 85 + } 83 86 84 87 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 85 88 if (!indio_dev) ··· 101 94 indio_dev->num_channels = 1; 102 95 indio_dev->name = spi_get_device_id(spi)->name; 103 96 104 - /* need 600ns between CS and the first falling edge of SCLK */ 105 - spi->max_speed_hz = 830000; 106 - spi->mode = SPI_MODE_3; 107 - ret = spi_setup(spi); 108 - 109 - if (ret < 0) { 110 - dev_err(&spi->dev, "spi_setup failed!\n"); 111 - return ret; 112 - } 113 - 114 97 return devm_iio_device_register(indio_dev->dev.parent, indio_dev); 115 98 } 99 + 100 + static const struct of_device_id ad2s90_of_match[] = { 101 + { .compatible = "adi,ad2s90", }, 102 + {} 103 + }; 104 + MODULE_DEVICE_TABLE(of, ad2s90_of_match); 116 105 117 106 static const struct spi_device_id ad2s90_id[] = { 118 107 { "ad2s90" }, ··· 119 116 static struct spi_driver ad2s90_driver = { 120 117 .driver = { 121 118 .name = "ad2s90", 119 + .of_match_table = ad2s90_of_match, 122 120 }, 123 121 .probe = ad2s90_probe, 124 122 .id_table = ad2s90_id,