[PATCH v2 2/2] staging: iio: cdc: ad7746: use dt for capacitive channel setup.

2021-04-18 Thread Lucas Stankus
Ditch platform_data fields in favor of device tree properties for
configuring EXCA and EXCB output pins and setting the capacitive channel
excitation level.

As this covers all current use cases for the platform_data struct, remove
ad7746.h header file since it's no longer needed.

Signed-off-by: Lucas Stankus 
---

Changes in v2:
Previously this change set was composed of two patches, but it lead to
regressions between the two. Merging them avoids the unwanted behaviour
without having to deal with the special cases.

 drivers/staging/iio/cdc/ad7746.c | 42 +++-
 drivers/staging/iio/cdc/ad7746.h | 28 -
 2 files changed, 19 insertions(+), 51 deletions(-)
 delete mode 100644 drivers/staging/iio/cdc/ad7746.h

diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index dfd71e99e872..c0e84c1cf4f1 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -18,8 +18,6 @@
 #include 
 #include 
 
-#include "ad7746.h"
-
 /*
  * AD7746 Register Definition
  */
@@ -66,7 +64,7 @@
 #define AD7746_EXCSETUP_NEXCB  BIT(4)
 #define AD7746_EXCSETUP_EXCA   BIT(3)
 #define AD7746_EXCSETUP_NEXCA  BIT(2)
-#define AD7746_EXCSETUP_EXCLVL(x)  (((x) & 0x3) << 0)
+#define AD7746_EXCSETUP_EXCLVL(x)  (((x) >> 7) & 0x3)
 
 /* Config Register Bit Designations (AD7746_REG_CFG) */
 #define AD7746_CONF_VTFS_SHIFT 6
@@ -676,10 +674,11 @@ static const struct iio_info ad7746_info = {
 static int ad7746_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
-   struct ad7746_platform_data *pdata = client->dev.platform_data;
+   struct device *dev = >dev;
struct ad7746_chip_info *chip;
struct iio_dev *indio_dev;
unsigned char regval = 0;
+   unsigned int vdd_permille;
int ret = 0;
 
indio_dev = devm_iio_device_alloc(>dev, sizeof(*chip));
@@ -703,28 +702,25 @@ static int ad7746_probe(struct i2c_client *client,
indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
 
-   if (pdata) {
-   if (pdata->exca_en) {
-   if (pdata->exca_inv_en)
-   regval |= AD7746_EXCSETUP_NEXCA;
-   else
-   regval |= AD7746_EXCSETUP_EXCA;
-   }
-
-   if (pdata->excb_en) {
-   if (pdata->excb_inv_en)
-   regval |= AD7746_EXCSETUP_NEXCB;
-   else
-   regval |= AD7746_EXCSETUP_EXCB;
-   }
+   if (device_property_read_bool(dev, "adi,exca-output-en")) {
+   if (device_property_read_bool(dev, "adi,exca-output-invert"))
+   regval |= AD7746_EXCSETUP_NEXCA;
+   else
+   regval |= AD7746_EXCSETUP_EXCA;
+   }
 
-   regval |= AD7746_EXCSETUP_EXCLVL(pdata->exclvl);
-   } else {
-   dev_warn(>dev, "No platform data? using default\n");
-   regval = AD7746_EXCSETUP_EXCA | AD7746_EXCSETUP_EXCB |
-   AD7746_EXCSETUP_EXCLVL(3);
+   if (device_property_read_bool(dev, "adi,excb-output-en")) {
+   if (device_property_read_bool(dev, "adi,excb-output-invert"))
+   regval |= AD7746_EXCSETUP_NEXCB;
+   else
+   regval |= AD7746_EXCSETUP_EXCB;
}
 
+   ret = device_property_read_u32(dev, "adi,excitation-vdd-permille",
+  _permille);
+   if (!ret)
+   regval |= AD7746_EXCSETUP_EXCLVL(vdd_permille);
+
ret = i2c_smbus_write_byte_data(chip->client,
AD7746_REG_EXC_SETUP, regval);
if (ret < 0)
diff --git a/drivers/staging/iio/cdc/ad7746.h b/drivers/staging/iio/cdc/ad7746.h
deleted file mode 100644
index 8bdbd732dbbd..
--- a/drivers/staging/iio/cdc/ad7746.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * AD7746 capacitive sensor driver supporting AD7745, AD7746 and AD7747
- *
- * Copyright 2011 Analog Devices Inc.
- */
-
-#ifndef IIO_CDC_AD7746_H_
-#define IIO_CDC_AD7746_H_
-
-/*
- * TODO: struct ad7746_platform_data needs to go into include/linux/iio
- */
-
-#define AD7466_EXCLVL_00 /* +-VDD/8 */
-#define AD7466_EXCLVL_11 /* +-VDD/4 */
-#define AD7466_EXCLVL_22 /* +-VDD * 3/8 */
-#define AD7466_EXCLVL_33 /* +-VDD/2 */
-
-struct ad7746_platform_data {
-   unsigned char exclvl;   /*Excitation Voltage Level */
-   bool exca_en;   /* enables EXCA pin as the excitation output */
-   bool exca_inv_en;   /* enables /

[PATCH v2 1/2] dt-bindings: staging: iio: cdc: ad7746: add binding documentation for AD7746

2021-04-18 Thread Lucas Stankus
Add device tree binding documentation for AD7746 cdc in YAML format.

Signed-off-by: Lucas Stankus 
---

A minor note about the adi,excitation-vdd-permille property. Jonathan
suggested the name to be adi,excitation-vdd-milicent, but I was unsure of
the milicent naming. With a quick search I found out that the common way to
call a thousandth is 'per mille'[1], but I didn't find any use of it in the
kernel documentation. Any thoughts about it?

[1] https://en.wikipedia.org/wiki/Per_mille

 .../bindings/iio/cdc/adi,ad7746.yaml  | 73 +++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml

diff --git a/Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml 
b/Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml
new file mode 100644
index ..a2a7eee674ba
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/cdc/adi,ad7746.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AD7746 24-Bit Capacitance-to-Digital Converter with Temperature Sensor
+
+maintainers:
+  - Michael Hennerich 
+
+description: |
+  AD7746 24-Bit Capacitance-to-Digital Converter with Temperature Sensor
+
+  Specifications about the part can be found at:
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7291.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,ad7745
+  - adi,ad7746
+  - adi,ad7747
+
+  reg:
+maxItems: 1
+
+  adi,excitation-vdd-permille:
+description: |
+  Set VDD per mille to be used as the excitation voltage.
+$ref: /schemas/types.yaml#/definitions/uint32
+enum: [125, 250, 375, 500]
+
+  adi,exca-output-en:
+description: Enables the EXCA pin as the excitation output.
+type: boolean
+
+  adi,exca-output-invert:
+description: Inverts the excitation output in the EXCA pin.
+type: boolean
+
+  adi,excb-output-en:
+description: Enables the EXCB pin as the excitation output.
+type: boolean
+
+  adi,excb-output-invert:
+description: Inverts the excitation output in the EXCB pin.
+type: boolean
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+
+  ad7746: cdc@48 {
+compatible = "adi,ad7746";
+reg = <0x48>;
+adi,excitation-vdd-permille = <125>;
+
+adi,exca-output-en;
+adi,exca-output-invert;
+adi,excb-output-en;
+adi,excb-output-invert;
+  };
+};
+...
-- 
2.31.1



[PATCH v2 0/2] staging: iio: cdc: ad7746: add dt properties for capacitive channel setup

2021-04-18 Thread Lucas Stankus
This patch series aims to replace the platform_struct for the ad7746 driver
in favor of device tree bindings, creating the dt-bindings documentation in
the process.

Since the header file was only used to define the struct and the excitation
level values, it was possible to remove the file entirely.

Changelog v1 -> v2:
- Correctly set I2C device address on the device tree documentation.
- Change EXCA and EXCB dt properties from u32 enum to boolean.
- Update capacitive excitation dt property to enumerate possible per mille
  values instead of using indexed voltage levels.
- Merge last two patches to avoid special handling of remaining
  platform_data properties.

Lucas Stankus (2):
  dt-bindings: staging: iio: cdc: ad7746: add binding documentation for
AD7746
  staging: iio: cdc: ad7746: use dt for capacitive channel setup.

 .../bindings/iio/cdc/adi,ad7746.yaml  | 73 +++
 drivers/staging/iio/cdc/ad7746.c  | 42 +--
 drivers/staging/iio/cdc/ad7746.h  | 28 ---
 3 files changed, 92 insertions(+), 51 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml
 delete mode 100644 drivers/staging/iio/cdc/ad7746.h

-- 
2.31.1



[PATCH 3/3] staging: iio: cdc: ad7746: use dt binding to set the excitation level

2021-04-09 Thread Lucas Stankus
Set device excitation level using properties from device tree binding
instead of using platform_data.
As this replaces the last instance where the platform_data struct was
used, remove ad7746.h header file since it's no longer needed.

Signed-off-by: Lucas Stankus 
---
 drivers/staging/iio/cdc/ad7746.c | 16 ++--
 drivers/staging/iio/cdc/ad7746.h | 24 
 2 files changed, 6 insertions(+), 34 deletions(-)
 delete mode 100644 drivers/staging/iio/cdc/ad7746.h

diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index 63041b164dbe..3c75d147c3dd 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -18,8 +18,6 @@
 #include 
 #include 
 
-#include "ad7746.h"
-
 /*
  * AD7746 Register Definition
  */
@@ -676,11 +674,10 @@ static const struct iio_info ad7746_info = {
 static int ad7746_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
-   struct ad7746_platform_data *pdata = client->dev.platform_data;
struct device_node *np = client->dev.of_node;
struct ad7746_chip_info *chip;
struct iio_dev *indio_dev;
-   unsigned int exca_en, excb_en;
+   unsigned int exca_en, excb_en, exclvl;
unsigned char regval = 0;
int ret = 0;
 
@@ -721,12 +718,11 @@ static int ad7746_probe(struct i2c_client *client,
regval |= AD7746_EXCSETUP_NEXCB;
}
 
-   if (pdata) {
-   regval |= AD7746_EXCSETUP_EXCLVL(pdata->exclvl);
-   } else {
-   dev_warn(>dev, "No platform data? using default\n");
-   regval = AD7746_EXCSETUP_EXCLVL(3);
-   }
+   ret = of_property_read_u32(np, "adi,excitation-voltage-level", );
+   if (!ret)
+   regval |= AD7746_EXCSETUP_EXCLVL(exclvl);
+   else
+   regval |= AD7746_EXCSETUP_EXCLVL(3);
 
ret = i2c_smbus_write_byte_data(chip->client,
AD7746_REG_EXC_SETUP, regval);
diff --git a/drivers/staging/iio/cdc/ad7746.h b/drivers/staging/iio/cdc/ad7746.h
deleted file mode 100644
index 6cae4ecf779e..
--- a/drivers/staging/iio/cdc/ad7746.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * AD7746 capacitive sensor driver supporting AD7745, AD7746 and AD7747
- *
- * Copyright 2011 Analog Devices Inc.
- */
-
-#ifndef IIO_CDC_AD7746_H_
-#define IIO_CDC_AD7746_H_
-
-/*
- * TODO: struct ad7746_platform_data needs to go into include/linux/iio
- */
-
-#define AD7466_EXCLVL_00 /* +-VDD/8 */
-#define AD7466_EXCLVL_11 /* +-VDD/4 */
-#define AD7466_EXCLVL_22 /* +-VDD * 3/8 */
-#define AD7466_EXCLVL_33 /* +-VDD/2 */
-
-struct ad7746_platform_data {
-   unsigned char exclvl;   /*Excitation Voltage Level */
-};
-
-#endif /* IIO_CDC_AD7746_H_ */
-- 
2.31.1



[PATCH 1/3] dt-bindings: staging: iio: cdc: ad7746: add binding documentation for AD7746

2021-04-09 Thread Lucas Stankus
Add device tree binding documentation for AD7746 cdc in YAML format.

Signed-off-by: Lucas Stankus 
---
 .../bindings/iio/cdc/adi,ad7746.yaml  | 79 +++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml

diff --git a/Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml 
b/Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml
new file mode 100644
index ..5de86f4374e1
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/cdc/adi,ad7746.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AD7746 24-Bit Capacitance-to-Digital Converter with Temperature Sensor
+
+maintainers:
+  - Michael Hennerich 
+
+description: |
+  AD7746 24-Bit Capacitance-to-Digital Converter with Temperature Sensor
+
+  Specifications about the part can be found at:
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7291.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,ad7745
+  - adi,ad7746
+  - adi,ad7747
+
+  reg:
+description: |
+  Physiscal address of the EXC set-up register.
+maxItems: 1
+
+  adi,excitation-voltage-level:
+description: |
+  Select the reference excitation voltage level used by the device.
+  With VDD being the power supply voltage, valid values are:
+  0: +-VDD / 8
+  1: +-VDD / 4
+  2: +-VDD * 3 / 8
+  3: +-VDD / 2
+  If left empty option 3 is selected.
+$ref: /schemas/types.yaml#/definitions/uint32
+enum: [0, 1, 2, 3]
+
+  adi,exca-output:
+description: |
+  Sets the excitation output in the exca pin.
+  Valid values are:
+  0: Disables output in the EXCA pin.
+  1: Enables EXCA pin as the excitation output.
+  2: Enables EXCA pin as the inverted excitation output.
+  If left empty the output is disabled.
+$ref: /schemas/types.yaml#/definitions/uint32
+enum: [0, 1, 2]
+
+  adi,excb-output:
+description: |
+  Analoguos to the adi,exca-output for the EXCB pin.
+$ref: /schemas/types.yaml#/definitions/uint32
+enum: [0, 1, 2]
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+
+  ad7746: cdc@0 {
+compatible = "adi,ad7746";
+reg = <0>;
+adi,excitation-voltage-level = <3>;
+adi,exca-output = <0>;
+adi,excb-output = <0>;
+  };
+};
+...
-- 
2.31.1



[PATCH 2/3] staging: iio: cdc: ad7746: use dt bindings to set the EXCx pins output

2021-04-09 Thread Lucas Stankus
Ditch platform_data fields in favor of device tree properties for
configuring EXCA and EXCB output.
This also removes the fields from the platform_data struct, since they're
not used anymore.

Signed-off-by: Lucas Stankus 
---
 drivers/staging/iio/cdc/ad7746.c | 33 +---
 drivers/staging/iio/cdc/ad7746.h |  4 
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index dfd71e99e872..63041b164dbe 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -677,8 +677,10 @@ static int ad7746_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
struct ad7746_platform_data *pdata = client->dev.platform_data;
+   struct device_node *np = client->dev.of_node;
struct ad7746_chip_info *chip;
struct iio_dev *indio_dev;
+   unsigned int exca_en, excb_en;
unsigned char regval = 0;
int ret = 0;
 
@@ -703,26 +705,27 @@ static int ad7746_probe(struct i2c_client *client,
indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
 
-   if (pdata) {
-   if (pdata->exca_en) {
-   if (pdata->exca_inv_en)
-   regval |= AD7746_EXCSETUP_NEXCA;
-   else
-   regval |= AD7746_EXCSETUP_EXCA;
-   }
+   ret = of_property_read_u32(np, "adi,exca-output", _en);
+   if (!ret && exca_en) {
+   if (exca_en == 1)
+   regval |= AD7746_EXCSETUP_EXCA;
+   else
+   regval |= AD7746_EXCSETUP_NEXCA;
+   }
 
-   if (pdata->excb_en) {
-   if (pdata->excb_inv_en)
-   regval |= AD7746_EXCSETUP_NEXCB;
-   else
-   regval |= AD7746_EXCSETUP_EXCB;
-   }
+   ret = of_property_read_u32(np, "adi,excb-output", _en);
+   if (!ret && excb_en) {
+   if (excb_en == 1)
+   regval |= AD7746_EXCSETUP_EXCB;
+   else
+   regval |= AD7746_EXCSETUP_NEXCB;
+   }
 
+   if (pdata) {
regval |= AD7746_EXCSETUP_EXCLVL(pdata->exclvl);
} else {
dev_warn(>dev, "No platform data? using default\n");
-   regval = AD7746_EXCSETUP_EXCA | AD7746_EXCSETUP_EXCB |
-   AD7746_EXCSETUP_EXCLVL(3);
+   regval = AD7746_EXCSETUP_EXCLVL(3);
}
 
ret = i2c_smbus_write_byte_data(chip->client,
diff --git a/drivers/staging/iio/cdc/ad7746.h b/drivers/staging/iio/cdc/ad7746.h
index 8bdbd732dbbd..6cae4ecf779e 100644
--- a/drivers/staging/iio/cdc/ad7746.h
+++ b/drivers/staging/iio/cdc/ad7746.h
@@ -19,10 +19,6 @@
 
 struct ad7746_platform_data {
unsigned char exclvl;   /*Excitation Voltage Level */
-   bool exca_en;   /* enables EXCA pin as the excitation output */
-   bool exca_inv_en;   /* enables /EXCA pin as the excitation output */
-   bool excb_en;   /* enables EXCB pin as the excitation output */
-   bool excb_inv_en;   /* enables /EXCB pin as the excitation output */
 };
 
 #endif /* IIO_CDC_AD7746_H_ */
-- 
2.31.1



[PATCH 0/3] staging: iio: cdc: ad7746: remove platform_data in favor of device tree bindings

2021-04-09 Thread Lucas Stankus
This patch series aims to replace the platform_struct for the ad7746 driver
in favor of device tree bindings, creating the dt-bindings documentation in
the process.

Since the header file was only used to define the struct and the excitation
level values, it was possible to remove the file entirely.

Lucas Stankus (3):
  dt-bindings: staging: iio: cdc: ad7746: add binding documentation for
AD7746
  staging: iio: cdc: ad7746: use dt bindings to set the EXCx pins output
  staging: iio: cdc: ad7746: use dt binding to set the excitation level

 .../bindings/iio/cdc/adi,ad7746.yaml  | 79 +++
 drivers/staging/iio/cdc/ad7746.c  | 43 +-
 drivers/staging/iio/cdc/ad7746.h  | 28 ---
 3 files changed, 100 insertions(+), 50 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/cdc/adi,ad7746.yaml
 delete mode 100644 drivers/staging/iio/cdc/ad7746.h

-- 
2.31.1



[PATCH 3/3] iio: adc: ad7923: register device with devm_iio_device_register

2021-03-28 Thread Lucas Stankus
Registers the device using the devm variant.
This is the final step of converting the ad7923 to only use devm routines,
meaning that the ad7923_remove() function is no longer needed to release
resources on device detach.

Signed-off-by: Lucas Stankus 
---
 drivers/iio/adc/ad7923.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index d07eaf3111ed..f7af2f194789 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -356,16 +356,7 @@ static int ad7923_probe(struct spi_device *spi)
if (ret)
return ret;
 
-   return iio_device_register(indio_dev);
-}
-
-static int ad7923_remove(struct spi_device *spi)
-{
-   struct iio_dev *indio_dev = spi_get_drvdata(spi);
-
-   iio_device_unregister(indio_dev);
-
-   return 0;
+   return devm_iio_device_register(>dev, indio_dev);
 }
 
 static const struct spi_device_id ad7923_id[] = {
@@ -398,7 +389,6 @@ static struct spi_driver ad7923_driver = {
.of_match_table = ad7923_of_match,
},
.probe  = ad7923_probe,
-   .remove = ad7923_remove,
.id_table   = ad7923_id,
 };
 module_spi_driver(ad7923_driver);
-- 
2.31.0



[PATCH 2/3] iio: adc: ad7923: use device-managed function for triggered buffer

2021-03-28 Thread Lucas Stankus
Converts the iio_triggered_buffer_setup() call to its device-managed
counterpart.
With this, the error handling routine in the ad7923_probe() function
becomes unnecessary as well as the iio_triggered_buffer_cleanup() call.

Signed-off-by: Lucas Stankus 
---
 drivers/iio/adc/ad7923.c | 15 +++
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index 3418ef6f0857..d07eaf3111ed 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -351,20 +351,12 @@ static int ad7923_probe(struct spi_device *spi)
if (ret)
return ret;
 
-   ret = iio_triggered_buffer_setup(indio_dev, NULL,
-_trigger_handler, NULL);
+   ret = devm_iio_triggered_buffer_setup(>dev, indio_dev, NULL,
+ _trigger_handler, NULL);
if (ret)
return ret;
 
-   ret = iio_device_register(indio_dev);
-   if (ret)
-   goto error_cleanup_ring;
-
-   return 0;
-
-error_cleanup_ring:
-   iio_triggered_buffer_cleanup(indio_dev);
-   return ret;
+   return iio_device_register(indio_dev);
 }
 
 static int ad7923_remove(struct spi_device *spi)
@@ -372,7 +364,6 @@ static int ad7923_remove(struct spi_device *spi)
struct iio_dev *indio_dev = spi_get_drvdata(spi);
 
iio_device_unregister(indio_dev);
-   iio_triggered_buffer_cleanup(indio_dev);
 
return 0;
 }
-- 
2.31.0



[PATCH 1/3] iio: adc: ad7923: use devm_add_action_or_reset for regulator disable

2021-03-28 Thread Lucas Stankus
Adds a device-managed action to handle disabling the driver's regulator on
device detach.
This slightly simplifies deinitialization and enables further conversion of
the driver to device-managed routines without breaking the init order.

Signed-off-by: Lucas Stankus 
---
 drivers/iio/adc/ad7923.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index a2cc96658054..3418ef6f0857 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -293,6 +293,13 @@ static const struct iio_info ad7923_info = {
.update_scan_mode = ad7923_update_scan_mode,
 };
 
+static void ad7923_regulator_disable(void *data)
+{
+   struct ad7923_state *st = data;
+
+   regulator_disable(st->reg);
+}
+
 static int ad7923_probe(struct spi_device *spi)
 {
struct ad7923_state *st;
@@ -340,10 +347,14 @@ static int ad7923_probe(struct spi_device *spi)
if (ret)
return ret;
 
+   ret = devm_add_action_or_reset(>dev, ad7923_regulator_disable, st);
+   if (ret)
+   return ret;
+
ret = iio_triggered_buffer_setup(indio_dev, NULL,
 _trigger_handler, NULL);
if (ret)
-   goto error_disable_reg;
+   return ret;
 
ret = iio_device_register(indio_dev);
if (ret)
@@ -353,20 +364,15 @@ static int ad7923_probe(struct spi_device *spi)
 
 error_cleanup_ring:
iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
-   regulator_disable(st->reg);
-
return ret;
 }
 
 static int ad7923_remove(struct spi_device *spi)
 {
struct iio_dev *indio_dev = spi_get_drvdata(spi);
-   struct ad7923_state *st = iio_priv(indio_dev);
 
iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
-   regulator_disable(st->reg);
 
return 0;
 }
-- 
2.31.0



[PATCH 0/3] iio: adc: ad7923: convert driver resources routines to device-managed counterparts

2021-03-28 Thread Lucas Stankus
Following the initiative proposed by Alexandru, this patch series aims
to convert the ad7923 to use only device-managed routines.

Part of the driver was already using devm_ functions, so it was possible
to convert the remainder of it without much hassle.

With that, the deregistration function was no longer necessary and could
be entirely removed from the driver.

Lucas Stankus (3):
  iio: adc: ad7923: use devm_add_action_or_reset for regulator disable
  iio: adc: ad7923: use device-managed function for triggered buffer
  iio: adc: ad7923: register device with devm_iio_device_register

 drivers/iio/adc/ad7923.c | 39 +--
 1 file changed, 13 insertions(+), 26 deletions(-)

-- 
2.31.0



[PATCH v3] kunit: Match parenthesis alignment to improve code readability

2021-03-12 Thread Lucas Stankus
Tidy up code by fixing the following checkpatch warnings:
CHECK: Alignment should match open parenthesis
CHECK: Lines should not end with a '('

Signed-off-by: Lucas Stankus 
Reviewed-by: Brendan Higgins 
---

Changelog v2 -> v3:
Reword subject line

 lib/kunit/assert.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index e0ec7d6fed6f..acfbf86bddd6 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -25,7 +25,7 @@ void kunit_base_assert_format(const struct kunit_assert 
*assert,
}
 
string_stream_add(stream, "%s FAILED at %s:%d\n",
-expect_or_assert, assert->file, assert->line);
+ expect_or_assert, assert->file, assert->line);
 }
 EXPORT_SYMBOL_GPL(kunit_base_assert_format);
 
@@ -48,8 +48,9 @@ EXPORT_SYMBOL_GPL(kunit_fail_assert_format);
 void kunit_unary_assert_format(const struct kunit_assert *assert,
   struct string_stream *stream)
 {
-   struct kunit_unary_assert *unary_assert = container_of(
-   assert, struct kunit_unary_assert, assert);
+   struct kunit_unary_assert *unary_assert;
+
+   unary_assert = container_of(assert, struct kunit_unary_assert, assert);
 
kunit_base_assert_format(assert, stream);
if (unary_assert->expected_true)
@@ -67,8 +68,10 @@ EXPORT_SYMBOL_GPL(kunit_unary_assert_format);
 void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
 struct string_stream *stream)
 {
-   struct kunit_ptr_not_err_assert *ptr_assert = container_of(
-   assert, struct kunit_ptr_not_err_assert, assert);
+   struct kunit_ptr_not_err_assert *ptr_assert;
+
+   ptr_assert = container_of(assert, struct kunit_ptr_not_err_assert,
+ assert);
 
kunit_base_assert_format(assert, stream);
if (!ptr_assert->value) {
@@ -111,8 +114,10 @@ static bool is_literal(struct kunit *test, const char 
*text, long long value,
 void kunit_binary_assert_format(const struct kunit_assert *assert,
struct string_stream *stream)
 {
-   struct kunit_binary_assert *binary_assert = container_of(
-   assert, struct kunit_binary_assert, assert);
+   struct kunit_binary_assert *binary_assert;
+
+   binary_assert = container_of(assert, struct kunit_binary_assert,
+assert);
 
kunit_base_assert_format(assert, stream);
string_stream_add(stream,
@@ -137,8 +142,10 @@ EXPORT_SYMBOL_GPL(kunit_binary_assert_format);
 void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
struct string_stream *stream)
 {
-   struct kunit_binary_ptr_assert *binary_assert = container_of(
-   assert, struct kunit_binary_ptr_assert, assert);
+   struct kunit_binary_ptr_assert *binary_assert;
+
+   binary_assert = container_of(assert, struct kunit_binary_ptr_assert,
+assert);
 
kunit_base_assert_format(assert, stream);
string_stream_add(stream,
@@ -159,8 +166,10 @@ EXPORT_SYMBOL_GPL(kunit_binary_ptr_assert_format);
 void kunit_binary_str_assert_format(const struct kunit_assert *assert,
struct string_stream *stream)
 {
-   struct kunit_binary_str_assert *binary_assert = container_of(
-   assert, struct kunit_binary_str_assert, assert);
+   struct kunit_binary_str_assert *binary_assert;
+
+   binary_assert = container_of(assert, struct kunit_binary_str_assert,
+assert);
 
kunit_base_assert_format(assert, stream);
string_stream_add(stream,
-- 
2.30.2



Re: [PATCH v2] kunit: fix checkpatch warning

2021-03-03 Thread Lucas Stankus
On Wed, Mar 03, 2021 at 12:56:05PM -0800, Brendan Higgins wrote:
> Did you change anything other than fixing the Signed-off-by that Shuah
> requested?

No, I only fixed the Signed-off-by warning.

> Generally when you make a small change after receiving a Reviewed-by
> (especially one so small as here), you are supposed to include the
> Reviewed-by with the other git commit message footers directly below
> the "Signed-off-by". Please remember to do so in the future.
> 
> Also, when you make a change to a patch and send out a subsequent
> revision, it is best practice to make note explaining the changes you
> made since the last revision in the "comment section" [1] of the
> git-diff, right after the three dashes and before the change log as
> you can see in this example [2] (note that everything after
> "Signed-off-by: David Gow \n ---" and before
> "tools/testing/kunit/configs/broken_on_uml.config | 2 ++" is discarded
> by git am).

Sorry for the incovenience regarding best practices, I'll keep that
noted for further contributions.


[PATCH v2] kunit: fix checkpatch warning

2021-03-03 Thread Lucas Stankus
Tidy up code by fixing the following checkpatch warnings:
CHECK: Alignment should match open parenthesis
CHECK: Lines should not end with a '('

Signed-off-by: Lucas Stankus 
---
Change log v1 -> v2
fixed signed-off-by tag
 lib/kunit/assert.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index e0ec7d6fed6f..acfbf86bddd6 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -25,7 +25,7 @@ void kunit_base_assert_format(const struct kunit_assert 
*assert,
}
 
string_stream_add(stream, "%s FAILED at %s:%d\n",
-expect_or_assert, assert->file, assert->line);
+ expect_or_assert, assert->file, assert->line);
 }
 EXPORT_SYMBOL_GPL(kunit_base_assert_format);
 
@@ -48,8 +48,9 @@ EXPORT_SYMBOL_GPL(kunit_fail_assert_format);
 void kunit_unary_assert_format(const struct kunit_assert *assert,
   struct string_stream *stream)
 {
-   struct kunit_unary_assert *unary_assert = container_of(
-   assert, struct kunit_unary_assert, assert);
+   struct kunit_unary_assert *unary_assert;
+
+   unary_assert = container_of(assert, struct kunit_unary_assert, assert);
 
kunit_base_assert_format(assert, stream);
if (unary_assert->expected_true)
@@ -67,8 +68,10 @@ EXPORT_SYMBOL_GPL(kunit_unary_assert_format);
 void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
 struct string_stream *stream)
 {
-   struct kunit_ptr_not_err_assert *ptr_assert = container_of(
-   assert, struct kunit_ptr_not_err_assert, assert);
+   struct kunit_ptr_not_err_assert *ptr_assert;
+
+   ptr_assert = container_of(assert, struct kunit_ptr_not_err_assert,
+ assert);
 
kunit_base_assert_format(assert, stream);
if (!ptr_assert->value) {
@@ -111,8 +114,10 @@ static bool is_literal(struct kunit *test, const char 
*text, long long value,
 void kunit_binary_assert_format(const struct kunit_assert *assert,
struct string_stream *stream)
 {
-   struct kunit_binary_assert *binary_assert = container_of(
-   assert, struct kunit_binary_assert, assert);
+   struct kunit_binary_assert *binary_assert;
+
+   binary_assert = container_of(assert, struct kunit_binary_assert,
+assert);
 
kunit_base_assert_format(assert, stream);
string_stream_add(stream,
@@ -137,8 +142,10 @@ EXPORT_SYMBOL_GPL(kunit_binary_assert_format);
 void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
struct string_stream *stream)
 {
-   struct kunit_binary_ptr_assert *binary_assert = container_of(
-   assert, struct kunit_binary_ptr_assert, assert);
+   struct kunit_binary_ptr_assert *binary_assert;
+
+   binary_assert = container_of(assert, struct kunit_binary_ptr_assert,
+assert);
 
kunit_base_assert_format(assert, stream);
string_stream_add(stream,
@@ -159,8 +166,10 @@ EXPORT_SYMBOL_GPL(kunit_binary_ptr_assert_format);
 void kunit_binary_str_assert_format(const struct kunit_assert *assert,
struct string_stream *stream)
 {
-   struct kunit_binary_str_assert *binary_assert = container_of(
-   assert, struct kunit_binary_str_assert, assert);
+   struct kunit_binary_str_assert *binary_assert;
+
+   binary_assert = container_of(assert, struct kunit_binary_str_assert,
+assert);
 
kunit_base_assert_format(assert, stream);
string_stream_add(stream,
-- 
2.30.1