Skip to contentSkip to conversation

dt-binding: iio: add NPCM ADC reset support

PATCH Applied Tomer Maimon 2 participants 4 messages Feb 3, 2020 – Feb 9, 2020

Subsystems (3)
lore
Share & tools
lore

Tomer Maimon

author maintainer
#0 lore raw

PATCH v2 1/2 dt-binding: iio: add NPCM ADC reset support

Add NPCM ADC reset binding documentation.

---
 Documentation/devicetree/bindings/iio/adc/nuvoton,npcm-adc.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iio/adc/nuvoton,npcm-adc.txt +2 -0
index eb939fe77836..ef8eeec1a997 100644
@@ -6,6 +6,7 @@ Required properties:
 - compatible: "nuvoton,npcm750-adc" for the NPCM7XX BMC.
 - reg: specifies physical base address and size of the registers.
 - interrupts: Contain the ADC interrupt with flags for falling edge.
+- resets : phandle to the reset control for this device.
 
 Optional properties:
 - clocks: phandle of ADC reference clock, in case the clock is not
@@ -21,4 +22,5 @@ adc: adc@f000c000 {
 	reg = <0xf000c000 0x8>;
 	interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
 	clocks = <&clk NPCM7XX_CLK_ADC>;
+	resets = <&rstc NPCM7XX_RESET_IPSRST1 NPCM7XX_RESET_ADC>;
 };
Signature · 1 line
2.22.0
author maintainer
#1 lore raw

PATCH v2 2/2 iio: adc: modify NPCM reset support

Modify NPCM ADC reset support from
direct register access to reset controller support.

please make sure to modify NPCM adc device tree parameters as described at nuvoton,npcm-adc.txt document for using this change.

---
 drivers/iio/adc/npcm_adc.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/iio/adc/npcm_adc.c +9 -21
index a6170a37ebe8..83bad2d5575d 100644
@@ -14,6 +14,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/spinlock.h>
 #include <linux/uaccess.h>
+#include <linux/reset.h>
 
 struct npcm_adc {
 	bool int_status;
@@ -23,13 +24,9 @@ struct npcm_adc {
 	struct clk *adc_clk;
 	wait_queue_head_t wq;
 	struct regulator *vref;
-	struct regmap *rst_regmap;
+	struct reset_control *reset;
 };
 
-/* NPCM7xx reset module */
-#define NPCM7XX_IPSRST1_OFFSET		0x020
-#define NPCM7XX_IPSRST1_ADC_RST		BIT(27)
-
 /* ADC registers */
 #define NPCM_ADCCON	 0x00
 #define NPCM_ADCDATA	 0x04
@@ -106,13 +103,11 @@ static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel)
 					       msecs_to_jiffies(10));
 	if (ret == 0) {
 		regtemp = ioread32(info->regs + NPCM_ADCCON);
-		if ((regtemp & NPCM_ADCCON_ADC_CONV) && info->rst_regmap) {
+		if (regtemp & NPCM_ADCCON_ADC_CONV) {
 			/* if conversion failed - reset ADC module */
-			regmap_write(info->rst_regmap, NPCM7XX_IPSRST1_OFFSET,
-				     NPCM7XX_IPSRST1_ADC_RST);
+			reset_control_assert(info->reset);
 			msleep(100);
-			regmap_write(info->rst_regmap, NPCM7XX_IPSRST1_OFFSET,
-				     0x0);
+			reset_control_deassert(info->reset);
 			msleep(100);
 
 			/* Enable ADC and start conversion module */
@@ -186,7 +181,6 @@ static int npcm_adc_probe(struct platform_device *pdev)
 	struct npcm_adc *info;
 	struct iio_dev *indio_dev;
 	struct device *dev = &pdev->dev;
-	struct device_node *np = pdev->dev.of_node;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
 	if (!indio_dev)
@@ -199,6 +193,10 @@ static int npcm_adc_probe(struct platform_device *pdev)
 	if (IS_ERR(info->regs))
 		return PTR_ERR(info->regs);
 
+	info->reset = devm_reset_control_get(&pdev->dev, NULL);
+	if (IS_ERR(info->reset))
+		return PTR_ERR(info->reset);
+
 	info->adc_clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(info->adc_clk)) {
 		dev_warn(&pdev->dev, "ADC clock failed: can't read clk\n");
@@ -211,16 +209,6 @@ static int npcm_adc_probe(struct platform_device *pdev)
 	div = div >> NPCM_ADCCON_DIV_SHIFT;
 	info->adc_sample_hz = clk_get_rate(info->adc_clk) / ((div + 1) * 2);
 
-	if (of_device_is_compatible(np, "nuvoton,npcm750-adc")) {
-		info->rst_regmap = syscon_regmap_lookup_by_compatible
-			("nuvoton,npcm750-rst");
-		if (IS_ERR(info->rst_regmap)) {
-			dev_err(&pdev->dev, "Failed to find nuvoton,npcm750-rst\n");
-			ret = PTR_ERR(info->rst_regmap);
-			goto err_disable_clk;
-		}
-	}
-
 	irq = platform_get_irq(pdev, 0);
 	if (irq <= 0) {
 		ret = -EINVAL;
Signature · 1 line
2.22.0
maintainer Applied
#2 lore raw

Re: [PATCH v2 2/2] iio: adc: modify NPCM reset support

Quoted 8 lines · On Mon, 3 Feb 2020 17:09:17 +0200 Tomer Maimon <[email protected]> wrote:

Modify NPCM ADC reset support from
direct register access to reset controller support.

please make sure to modify NPCM adc device tree parameters as described at nuvoton,npcm-adc.txt document for using this change.

Applied. I added a note for anyone browsing the tree in future to say that we know this is a breaking change, but in this case close ecosystem etc so it's fine..

I don't want others to point at your patch when I tell them no for similar changes in more generic parts!

Thanks,

Jonathan

Quoted 84 lines
---
 drivers/iio/adc/npcm_adc.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/iio/adc/npcm_adc.c +9 -21
index a6170a37ebe8..83bad2d5575d 100644
@@ -14,6 +14,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/spinlock.h>
 #include <linux/uaccess.h>
+#include <linux/reset.h>
 
 struct npcm_adc {
 	bool int_status;
@@ -23,13 +24,9 @@ struct npcm_adc {
 	struct clk *adc_clk;
 	wait_queue_head_t wq;
 	struct regulator *vref;
-	struct regmap *rst_regmap;
+	struct reset_control *reset;
 };
 
-/* NPCM7xx reset module */
-#define NPCM7XX_IPSRST1_OFFSET		0x020
-#define NPCM7XX_IPSRST1_ADC_RST		BIT(27)
-
 /* ADC registers */
 #define NPCM_ADCCON	 0x00
 #define NPCM_ADCDATA	 0x04
@@ -106,13 +103,11 @@ static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel)
 					       msecs_to_jiffies(10));
 	if (ret == 0) {
 		regtemp = ioread32(info->regs + NPCM_ADCCON);
-		if ((regtemp & NPCM_ADCCON_ADC_CONV) && info->rst_regmap) {
+		if (regtemp & NPCM_ADCCON_ADC_CONV) {
 			/* if conversion failed - reset ADC module */
-			regmap_write(info->rst_regmap, NPCM7XX_IPSRST1_OFFSET,
-				     NPCM7XX_IPSRST1_ADC_RST);
+			reset_control_assert(info->reset);
 			msleep(100);
-			regmap_write(info->rst_regmap, NPCM7XX_IPSRST1_OFFSET,
-				     0x0);
+			reset_control_deassert(info->reset);
 			msleep(100);
 
 			/* Enable ADC and start conversion module */
@@ -186,7 +181,6 @@ static int npcm_adc_probe(struct platform_device *pdev)
 	struct npcm_adc *info;
 	struct iio_dev *indio_dev;
 	struct device *dev = &pdev->dev;
-	struct device_node *np = pdev->dev.of_node;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
 	if (!indio_dev)
@@ -199,6 +193,10 @@ static int npcm_adc_probe(struct platform_device *pdev)
 	if (IS_ERR(info->regs))
 		return PTR_ERR(info->regs);
 
+	info->reset = devm_reset_control_get(&pdev->dev, NULL);
+	if (IS_ERR(info->reset))
+		return PTR_ERR(info->reset);
+
 	info->adc_clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(info->adc_clk)) {
 		dev_warn(&pdev->dev, "ADC clock failed: can't read clk\n");
@@ -211,16 +209,6 @@ static int npcm_adc_probe(struct platform_device *pdev)
 	div = div >> NPCM_ADCCON_DIV_SHIFT;
 	info->adc_sample_hz = clk_get_rate(info->adc_clk) / ((div + 1) * 2);
 
-	if (of_device_is_compatible(np, "nuvoton,npcm750-adc")) {
-		info->rst_regmap = syscon_regmap_lookup_by_compatible
-			("nuvoton,npcm750-rst");
-		if (IS_ERR(info->rst_regmap)) {
-			dev_err(&pdev->dev, "Failed to find nuvoton,npcm750-rst\n");
-			ret = PTR_ERR(info->rst_regmap);
-			goto err_disable_clk;
-		}
-	}
-
 	irq = platform_get_irq(pdev, 0);
 	if (irq <= 0) {
 		ret = -EINVAL;
author maintainer
#3 lore raw

Re: [PATCH v2 2/2] iio: adc: modify NPCM reset support

Great!

Thanks a lot Jonathan

Quoted 117 lines · Jonathan Cameron
Quoted 8 lines · On Mon, 3 Feb 2020 17:09:17 +0200 Tomer Maimon <[email protected]> wrote:

Modify NPCM ADC reset support from
direct register access to reset controller support.

please make sure to modify NPCM adc device tree parameters as described at nuvoton,npcm-adc.txt document for using this change.

Applied. I added a note for anyone browsing the tree in future to say that we know this is a breaking change, but in this case close ecosystem etc so it's fine..

I don't want others to point at your patch when I tell them no for similar changes in more generic parts!

Thanks,

Jonathan

drivers/iio/adc/npcm_adc.c static int npcm_adc_read(struct npcm_adc *info,

Quoted 32 lines
---
 drivers/iio/adc/npcm_adc.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/iio/adc/npcm_adc.c +2 -5
index a6170a37ebe8..83bad2d5575d 100644
@@ -14,6 +14,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/spinlock.h>
 #include <linux/uaccess.h>
+#include <linux/reset.h>
 
 struct npcm_adc {
      bool int_status;
@@ -23,13 +24,9 @@ struct npcm_adc {
      struct clk *adc_clk;
      wait_queue_head_t wq;
      struct regulator *vref;
-     struct regmap *rst_regmap;
+     struct reset_control *reset;
 };
 
-/* NPCM7xx reset module */
-#define NPCM7XX_IPSRST1_OFFSET               0x020
-#define NPCM7XX_IPSRST1_ADC_RST              BIT(27)
-
 /* ADC registers */
 #define NPCM_ADCCON   0x00
 #define NPCM_ADCDATA  0x04
@@ -106,13 +103,11 @@ static int npcm_adc_read(struct npcm_adc *info,

int *val, u8 channel)

drivers/iio/adc/npcm_adc.c static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel)

Quoted 7 lines
drivers/iio/adc/npcm_adc.c +1 -2
                                             msecs_to_jiffies(10));
      if (ret == 0) {
              regtemp = ioread32(info->regs + NPCM_ADCCON);
-             if ((regtemp & NPCM_ADCCON_ADC_CONV) && info->rst_regmap) {
+             if (regtemp & NPCM_ADCCON_ADC_CONV) {
                      /* if conversion failed - reset ADC module */
-                     regmap_write(info->rst_regmap,

NPCM7XX_IPSRST1_OFFSET,

drivers/iio/adc/npcm_adc.c static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel)

Quoted 4 lines
drivers/iio/adc/npcm_adc.c +1 -2
-                                  NPCM7XX_IPSRST1_ADC_RST);
+                     reset_control_assert(info->reset);
                      msleep(100);
-                     regmap_write(info->rst_regmap,

NPCM7XX_IPSRST1_OFFSET,

drivers/iio/adc/npcm_adc.c static int npcm_adc_probe(struct platform_device

Quoted 6 lines
drivers/iio/adc/npcm_adc.c +1 -1
-                                  0x0);
+                     reset_control_deassert(info->reset);
                      msleep(100);
 
                      /* Enable ADC and start conversion module */
@@ -186,7 +181,6 @@ static int npcm_adc_probe(struct platform_device

*pdev)

drivers/iio/adc/npcm_adc.c static int npcm_adc_probe(struct platform_device

Quoted 8 lines
drivers/iio/adc/npcm_adc.c +0 -1
      struct npcm_adc *info;
      struct iio_dev *indio_dev;
      struct device *dev = &pdev->dev;
-     struct device_node *np = pdev->dev.of_node;
 
      indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
      if (!indio_dev)
@@ -199,6 +193,10 @@ static int npcm_adc_probe(struct platform_device

*pdev)

drivers/iio/adc/npcm_adc.c static int npcm_adc_probe(struct platform_device

Quoted 11 lines
drivers/iio/adc/npcm_adc.c +4 -0
      if (IS_ERR(info->regs))
              return PTR_ERR(info->regs);
 
+     info->reset = devm_reset_control_get(&pdev->dev, NULL);
+     if (IS_ERR(info->reset))
+             return PTR_ERR(info->reset);
+
      info->adc_clk = devm_clk_get(&pdev->dev, NULL);
      if (IS_ERR(info->adc_clk)) {
              dev_warn(&pdev->dev, "ADC clock failed: can't read clk\n");
@@ -211,16 +209,6 @@ static int npcm_adc_probe(struct platform_device

*pdev)

drivers/iio/adc/npcm_adc.c static int npcm_adc_probe(struct platform_device · line 210

Quoted 2 lines
drivers/iio/adc/npcm_adc.c +0 -0
      div = div >> NPCM_ADCCON_DIV_SHIFT;
      info->adc_sample_hz = clk_get_rate(info->adc_clk) / ((div + 1) *

2);

drivers/iio/adc/npcm_adc.c static int npcm_adc_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/iio/adc/npcm_adc.c +0 -5
-     if (of_device_is_compatible(np, "nuvoton,npcm750-adc")) {
-             info->rst_regmap = syscon_regmap_lookup_by_compatible
-                     ("nuvoton,npcm750-rst");
-             if (IS_ERR(info->rst_regmap)) {
-                     dev_err(&pdev->dev, "Failed to find

nuvoton,npcm750-rst\n");

Quoted 8 lines
drivers/iio/adc/npcm_adc.c +0 -5
-                     ret = PTR_ERR(info->rst_regmap);
-                     goto err_disable_clk;
-             }
-     }
-
      irq = platform_get_irq(pdev, 0);
      if (irq <= 0) {
              ret = -EINVAL;