Skip to contentSkip to conversation

iio: adc: ad4130: zero-initialize clock init data

PATCH In review Cosmin Tanislav 3 participants 5 messages Feb 7, 2024 – Feb 10, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 iio: adc: ad4130: zero-initialize clock init data

The clk_init_data struct does not have all its members initialized, causing issues when trying to expose the internal clock on the CLK pin.

Fix this by zero-initializing the clk_init_data struct.

Fixes 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")
---
 drivers/iio/adc/ad4130.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad4130.c +1 -1
index 53e19a863198..c7df499f9775 100644
@@ -1794,7 +1794,7 @@ static int ad4130_setup_int_clk(struct ad4130_state *st)
 {
 	struct device *dev = &st->spi->dev;
 	struct device_node *of_node = dev_of_node(dev);
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	const char *clk_name;
 	int ret;
 
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 iio: adc: ad4130: only set GPIO_CTRL if pin is unused

Currently, GPIO_CTRL bits are set even if the pins are used for measurements.

GPIO_CTRL bits should only be set if the pin is not used for other functionality.

Fix this by only setting the GPIO_CTRL bits if the pin has no other function.

Fixes 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")
---
 drivers/iio/adc/ad4130.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/iio/adc/ad4130.c +7 -3
index c7df499f9775..febb64e67955 100644
@@ -1864,10 +1864,14 @@ static int ad4130_setup(struct iio_dev *indio_dev)
 		return ret;
 
 	/*
-	 * Configure all GPIOs for output. If configured, the interrupt function
-	 * of P2 takes priority over the GPIO out function.
+	 * Configure unused GPIOs for output. If configured, the interrupt
+	 * function of P2 takes priority over the GPIO out function.
 	 */
-	val =  AD4130_IO_CONTROL_GPIO_CTRL_MASK;
+	val = 0;
+	for (i = 0; i < AD4130_MAX_GPIOS; i++)
+		if (st->pins_fn[i + AD4130_AIN2_P1] == AD4130_PIN_FN_NONE)
+			val |= FIELD_PREP(AD4130_IO_CONTROL_GPIO_CTRL_MASK, BIT(i));
+
 	val |= FIELD_PREP(AD4130_IO_CONTROL_INT_PIN_SEL_MASK, st->int_pin_sel);
 
 	ret = regmap_write(st->regmap, AD4130_IO_CONTROL_REG, val);
Signature · 1 line
2.43.0
Reviewed-by Nuno Sa on v1 2/2
#2 lore raw

Re: [PATCH 2/2] iio: adc: ad4130: only set GPIO_CTRL if pin is unused

Quoted 6 lines · Cosmin Tanislav

Currently, GPIO_CTRL bits are set even if the pins are used for measurements.

GPIO_CTRL bits should only be set if the pin is not used for other functionality.

Quoted 6 lines

Fix this by only setting the GPIO_CTRL bits if the pin has no other function.

Fixes 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")

---

Quoted 28 lines

 drivers/iio/adc/ad4130.c | 10 +++++++---

 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/iio/adc/ad4130.c +0 -0
index c7df499f9775..febb64e67955 100644
@@ -1864,10 +1864,14 @@ static int ad4130_setup(struct iio_dev *indio_dev)
  		return ret;


  /*

drivers/iio/adc/ad4130.c +0 -1
-	 * Configure all GPIOs for output. If configured, the interrupt

function

drivers/iio/adc/ad4130.c +2 -1
-	 * of P2 takes priority over the GPIO out function.
+	 * Configure unused GPIOs for output. If configured, the interrupt
+	 * function of P2 takes priority over the GPIO out function.

  */

drivers/iio/adc/ad4130.c +4 -1
-	val =  AD4130_IO_CONTROL_GPIO_CTRL_MASK;
+	val = 0;
+	for (i = 0; i < AD4130_MAX_GPIOS; i++)
+		if (st->pins_fn[i + AD4130_AIN2_P1] == AD4130_PIN_FN_NONE)
+			val |= FIELD_PREP(AD4130_IO_CONTROL_GPIO_CTRL_MASK,

BIT(i));
+
  val |= FIELD_PREP(AD4130_IO_CONTROL_INT_PIN_SEL_MASK, st-

Quoted 1 line

int_pin_sel);


  ret = regmap_write(st->regmap, AD4130_IO_CONTROL_REG, val);

Reviewed-by Nuno Sa on v1 1/2
#3 lore raw
In reply to Cosmin Tanislav
Quoted 9 lines · Cosmin Tanislav

The clk_init_data struct does not have all its members initialized, causing issues when trying to expose the internal clock on the CLK pin.

Fix this by zero-initializing the clk_init_data struct.

Fixes 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")

---

Quoted 16 lines

 drivers/iio/adc/ad4130.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad4130.c +1 -1
index 53e19a863198..c7df499f9775 100644
@@ -1794,7 +1794,7 @@ static int ad4130_setup_int_clk(struct ad4130_state *st)
  {
  	struct device *dev = &st->spi->dev;
  	struct device_node *of_node = dev_of_node(dev);
-	struct clk_init_data init;
+	struct clk_init_data init = {};
  	const char *clk_name;
  	int ret;

maintainer
#4 lore raw
Quoted 5 lines · On Thu, 08 Feb 2024 09:15:08 +0100 Nuno Sá <[email protected]> wrote:
Quoted 4 lines · Cosmin Tanislav

The clk_init_data struct does not have all its members initialized, causing issues when trying to expose the internal clock on the CLK pin.

Quoted 7 lines
Quoted 5 lines

Fix this by zero-initializing the clk_init_data struct.

Fixes 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")

---

Both applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

Quoted 18 lines
Quoted 17 lines

 drivers/iio/adc/ad4130.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad4130.c +1 -1
index 53e19a863198..c7df499f9775 100644
@@ -1794,7 +1794,7 @@ static int ad4130_setup_int_clk(struct ad4130_state *st)
  {
  	struct device *dev = &st->spi->dev;
  	struct device_node *of_node = dev_of_node(dev);
-	struct clk_init_data init;
+	struct clk_init_data init = {};
  	const char *clk_name;
  	int ret;