[v1,1/3] pinctrl: intel: Introduce intel_restore_padcfg() helper
diff mbox series

Message ID 20191014084348.42489-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series
  • [v1,1/3] pinctrl: intel: Introduce intel_restore_padcfg() helper
Related show

Commit Message

Andy Shevchenko Oct. 14, 2019, 8:43 a.m. UTC
Deduplicate restoring PADCFGx registers by using a common helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/intel/pinctrl-intel.c | 51 +++++++++++++--------------
 1 file changed, 24 insertions(+), 27 deletions(-)

Comments

Mika Westerberg Oct. 21, 2019, 12:24 p.m. UTC | #1
On Mon, Oct 14, 2019 at 11:43:46AM +0300, Andy Shevchenko wrote:
> Deduplicate restoring PADCFGx registers by using a common helper.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pinctrl/intel/pinctrl-intel.c | 51 +++++++++++++--------------
>  1 file changed, 24 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
> index bc013599a9a3..18467e2efe99 100644
> --- a/drivers/pinctrl/intel/pinctrl-intel.c
> +++ b/drivers/pinctrl/intel/pinctrl-intel.c
> @@ -1588,6 +1588,27 @@ intel_gpio_update_pad_mode(void __iomem *hostown, u32 mask, u32 value)
>  	return curr;
>  }
>  
> +static void intel_restore_padcfg(struct intel_pinctrl *pctrl, unsigned int pin,
> +				 unsigned int reg, u32 value)
> +{
> +	struct device *dev = pctrl->dev;
> +	unsigned int n = reg / sizeof(u32);
> +	void __iomem *padcfg;
> +	u32 mask = (reg == PADCFG0) ? PADCFG0_GPIORXSTATE : 0;
> +	u32 val;

Looks better if you order them like:

	u32 mask = (reg == PADCFG0) ? PADCFG0_GPIORXSTATE : 0;
	unsigned int n = reg / sizeof(u32);
	struct device *dev = pctrl->dev;
	void __iomem *padcfg;
	u32 val;

Patch
diff mbox series

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index bc013599a9a3..18467e2efe99 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1588,6 +1588,27 @@  intel_gpio_update_pad_mode(void __iomem *hostown, u32 mask, u32 value)
 	return curr;
 }
 
+static void intel_restore_padcfg(struct intel_pinctrl *pctrl, unsigned int pin,
+				 unsigned int reg, u32 value)
+{
+	struct device *dev = pctrl->dev;
+	unsigned int n = reg / sizeof(u32);
+	void __iomem *padcfg;
+	u32 mask = (reg == PADCFG0) ? PADCFG0_GPIORXSTATE : 0;
+	u32 val;
+
+	padcfg = intel_get_padcfg(pctrl, pin, reg);
+	if (!padcfg)
+		return;
+
+	val = readl(padcfg) & ~mask;
+	if (val == value)
+		return;
+
+	writel(value, padcfg);
+	dev_dbg(dev, "restored pin %u padcfg%u %#08x\n", pin, n, readl(padcfg));
+}
+
 int intel_pinctrl_resume_noirq(struct device *dev)
 {
 	struct intel_pinctrl *pctrl = dev_get_drvdata(dev);
@@ -1601,37 +1622,13 @@  int intel_pinctrl_resume_noirq(struct device *dev)
 	pads = pctrl->context.pads;
 	for (i = 0; i < pctrl->soc->npins; i++) {
 		const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i];
-		void __iomem *padcfg;
-		u32 val;
 
 		if (!intel_pinctrl_should_save(pctrl, desc->number))
 			continue;
 
-		padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG0);
-		val = readl(padcfg) & ~PADCFG0_GPIORXSTATE;
-		if (val != pads[i].padcfg0) {
-			writel(pads[i].padcfg0, padcfg);
-			dev_dbg(dev, "restored pin %u padcfg0 %#08x\n",
-				desc->number, readl(padcfg));
-		}
-
-		padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG1);
-		val = readl(padcfg);
-		if (val != pads[i].padcfg1) {
-			writel(pads[i].padcfg1, padcfg);
-			dev_dbg(dev, "restored pin %u padcfg1 %#08x\n",
-				desc->number, readl(padcfg));
-		}
-
-		padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG2);
-		if (padcfg) {
-			val = readl(padcfg);
-			if (val != pads[i].padcfg2) {
-				writel(pads[i].padcfg2, padcfg);
-				dev_dbg(dev, "restored pin %u padcfg2 %#08x\n",
-					desc->number, readl(padcfg));
-			}
-		}
+		intel_restore_padcfg(pctrl, desc->number, PADCFG0, pads[i].padcfg0);
+		intel_restore_padcfg(pctrl, desc->number, PADCFG1, pads[i].padcfg1);
+		intel_restore_padcfg(pctrl, desc->number, PADCFG2, pads[i].padcfg2);
 	}
 
 	communities = pctrl->context.communities;