Skip to contentSkip to conversation

pinctrl: intel: Reuse for_each_requested_gpio*() macros

PATCH In review Andy Shevchenko 5 participants 9 messages Jun 15, 2020 – Jun 17, 2020

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

v3 cover pinctrl: intel: Reuse for_each_requested_gpio*() macros

This is part of previously sent clean up / fixes series against Intel pin control drivers. This piece replaces home grown alternatives to generic (*) for_each_requested_gpio*() helpers.

(*) Mika suggested to document for_each_requested_gpio*() helper, and I decided that it may be useful to GPIO and pin control subsystems in general, so, thus it has dependency to [1] submitted recently.

[1]: https://lore.kernel.org/linux-gpio/[email protected]/T/#t

Andy Shevchenko (3):
pinctrl: intel: Make use of for_each_requested_gpio_in_range()
pinctrl: lynxpoint: Make use of for_each_requested_gpio()
pinctrl: lynxpoint: Introduce helpers to enable or disable input

 drivers/pinctrl/intel/pinctrl-intel.c     | 21 ++++++------------
 drivers/pinctrl/intel/pinctrl-lynxpoint.c | 26 +++++++++++++++--------
 2 files changed, 23 insertions(+), 24 deletions(-)
Signature · 1 line
2.27.0.rc2
#1 lore raw

PATCH v3 1/3 pinctrl: intel: Make use of for_each_requested_gpio_in_range()

Make use of for_each_requested_gpio_in_range() instead of home grown analogue.

---
 drivers/pinctrl/intel/pinctrl-intel.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/pinctrl/intel/pinctrl-intel.c +6 -15
index 35c88fcb75a2..b64997b303e0 100644
@@ -1628,19 +1628,6 @@ static void intel_gpio_irq_init(struct intel_pinctrl *pctrl)
 	}
 }
 
-static u32
-intel_gpio_is_requested(struct gpio_chip *chip, int base, unsigned int size)
-{
-	u32 requested = 0;
-	unsigned int i;
-
-	for (i = 0; i < size; i++)
-		if (gpiochip_is_requested(chip, base + i))
-			requested |= BIT(i);
-
-	return requested;
-}
-
 static bool intel_gpio_update_reg(void __iomem *reg, u32 mask, u32 value)
 {
 	u32 curr, updated;
@@ -1661,12 +1648,16 @@ static void intel_restore_hostown(struct intel_pinctrl *pctrl, unsigned int c,
 	const struct intel_community *community = &pctrl->communities[c];
 	const struct intel_padgroup *padgrp = &community->gpps[gpp];
 	struct device *dev = pctrl->dev;
-	u32 requested;
+	const char *dummy;
+	u32 requested = 0;
+	unsigned int i;
 
 	if (padgrp->gpio_base == INTEL_GPIO_BASE_NOMAP)
 		return;
 
-	requested = intel_gpio_is_requested(&pctrl->chip, padgrp->gpio_base, padgrp->size);
+	for_each_requested_gpio_in_range(&pctrl->chip, i, padgrp->gpio_base, padgrp->size, dummy)
+		requested |= BIT(i);
+
 	if (!intel_gpio_update_reg(base + gpp * 4, requested, saved))
 		return;
 
Signature · 1 line
2.27.0.rc2
#2 lore raw

Re: [PATCH v3 1/3] pinctrl: intel: Make use of for_each_requested_gpio_in_range()

I love your patch! Yet something to improve:

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on pinctrl/devel]
[also build test ERROR on v5.8-rc1 next-20200615]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/pinctrl-intel-Reuse-for_each_requested_gpio-macros/20200615-231832
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
config: x86_64-rhel-7.6 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

drivers/pinctrl/intel/pinctrl-intel.c: In function 'intel_restore_hostown':

>> drivers/pinctrl/intel/pinctrl-intel.c:1601:2: error: implicit declaration of function 'for_each_requested_gpio_in_range' [-Werror=implicit-function-declaration]
1601 |  for_each_requested_gpio_in_range(&pctrl->chip, i, padgrp->gpio_base, padgrp->size, dummy)
|  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/pinctrl/intel/pinctrl-intel.c:1601:91: error: expected ';' before 'requested'
1601 |  for_each_requested_gpio_in_range(&pctrl->chip, i, padgrp->gpio_base, padgrp->size, dummy)
|                                                                                           ^
|                                                                                           ;

1602 | requested |= BIT(i);
| ~~~~~~~~~
cc1: some warnings being treated as errors

vim +/for_each_requested_gpio_in_range +1601 drivers/pinctrl/intel/pinctrl-intel.c

1587
1588 static void intel_restore_hostown(struct intel_pinctrl *pctrl, unsigned int c,
1589 void __iomem *base, unsigned int gpp, u32 saved)
1590 {
1591 const struct intel_community *community = &pctrl->communities[c];
1592 const struct intel_padgroup *padgrp = &community->gpps[gpp];
1593 struct device *dev = pctrl->dev;
1594 const char *dummy;
1595 u32 requested = 0;
1596 unsigned int i;
1597
1598 if (padgrp->gpio_base == INTEL_GPIO_BASE_NOMAP)
1599 return;
1600

> 1601		for_each_requested_gpio_in_range(&pctrl->chip, i, padgrp->gpio_base, padgrp->size, dummy)

1602 requested |= BIT(i);
1603
1604 if (!intel_gpio_update_reg(base + gpp * 4, requested, saved))
1605 return;
1606
1607 dev_dbg(dev, "restored hostown %u/%u %#08x\n", c, gpp, readl(base + gpp * 4));
1608 }
1609

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw

Re: [PATCH v3 1/3] pinctrl: intel: Make use of for_each_requested_gpio_in_range()

Quoted 10 lines · kernel test robot

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on pinctrl/devel]
[also build test ERROR on v5.8-rc1 next-20200615]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

Is there a way to tell kbuild bot to use another patch series (by link to lore?) that should be used as a base?
In any case this series has such links in a cover letter. Can kbuild bot parse it (perhaps some special tag, like BaseLink: is needed)?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [kbuild-all] Re: [PATCH v3 1/3] pinctrl: intel: Make use of for_each_requested_gpio_in_range()

Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · kernel test robot

Hi Andy,

I love your patch! Yet something to improve:

Quoted 8 lines
Quoted 5 lines

[auto build test ERROR on pinctrl/devel]
[also build test ERROR on v5.8-rc1 next-20200615]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

Is there a way to tell kbuild bot to use another patch series (by link to lore?) that should be used as a base?

Hi Andy, currently we recommend to use --base option to deduce the base commit, and bot will read this information to find a better tree as base that contains the base commit.

Quoted 2 lines

In any case this series has such links in a cover letter. Can kbuild bot parse it (perhaps some special tag, like BaseLink: is needed)?

We haven't support other way yet. With --base option, we will parse the extra information added by --base.

Quoted 8 lines
Signature · 6 lines
-- 
With Best Regards,
Andy Shevchenko
_______________________________________________
kbuild-all mailing list -- kbuild-all(a)lists.01.org
To unsubscribe send an email to kbuild-all-leave(a)lists.01.org
#5 lore raw

PATCH v3 2/3 pinctrl: lynxpoint: Make use of for_each_requested_gpio()

In reply to Andy Shevchenko

Make use of for_each_requested_gpio() instead of home grown analogue.

---
 drivers/pinctrl/intel/pinctrl-lynxpoint.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/pinctrl/intel/pinctrl-lynxpoint.c +6 -5
index a45b8f2182fd..2a3af998b91c 100644
@@ -919,16 +919,17 @@ static int lp_gpio_runtime_resume(struct device *dev)
 static int lp_gpio_resume(struct device *dev)
 {
 	struct intel_pinctrl *lg = dev_get_drvdata(dev);
+	struct gpio_chip *chip = &lg->chip;
+	const char *dummy;
 	void __iomem *reg;
 	int i;
 
 	/* on some hardware suspend clears input sensing, re-enable it here */
-	for (i = 0; i < lg->chip.ngpio; i++) {
-		if (gpiochip_is_requested(&lg->chip, i) != NULL) {
-			reg = lp_gpio_reg(&lg->chip, i, LP_CONFIG2);
-			iowrite32(ioread32(reg) & ~GPINDIS_BIT, reg);
-		}
+	for_each_requested_gpio(chip, i, dummy) {
+		reg = lp_gpio_reg(chip, i, LP_CONFIG2);
+		iowrite32(ioread32(reg) & ~GPINDIS_BIT, reg);
 	}
+
 	return 0;
 }
 
Signature · 1 line
2.27.0.rc2
#6 lore raw

Re: [PATCH v3 2/3] pinctrl: lynxpoint: Make use of for_each_requested_gpio()

I love your patch! Yet something to improve:

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on pinctrl/devel]
[also build test ERROR on v5.8-rc1 next-20200615]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/pinctrl-intel-Reuse-for_each_requested_gpio-macros/20200615-231832
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 487ca07fcc75d52755c9fe2ee05bcb3b6eeeec44)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/pinctrl/intel/pinctrl-lynxpoint.c:928:2: error: implicit declaration of function 'for_each_requested_gpio' [-Werror,-Wimplicit-function-declaration]
for_each_requested_gpio(chip, i, dummy) {
^
>> drivers/pinctrl/intel/pinctrl-lynxpoint.c:928:41: error: expected ';' after expression

for_each_requested_gpio(chip, i, dummy) {
^
;
2 errors generated.

vim +/for_each_requested_gpio +928 drivers/pinctrl/intel/pinctrl-lynxpoint.c

918
919 static int lp_gpio_resume(struct device *dev)
920 {
921 struct intel_pinctrl *lg = dev_get_drvdata(dev);
922 struct gpio_chip *chip = &lg->chip;
923 const char *dummy;
924 void __iomem *reg;
925 int i;
926
927 /* on some hardware suspend clears input sensing, re-enable it here */

 > 928		for_each_requested_gpio(chip, i, dummy) {

929 reg = lp_gpio_reg(chip, i, LP_CONFIG2);
930 iowrite32(ioread32(reg) & ~GPINDIS_BIT, reg);
931 }
932
933 return 0;
934 }
935

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#7 lore raw

PATCH v3 3/3 pinctrl: lynxpoint: Introduce helpers to enable or disable input

In reply to Andy Shevchenko

Introduce couple of helpers to enable or disable input. i.e. lp_gpio_enable_input() and lp_gpio_disable_input().

---
 drivers/pinctrl/intel/pinctrl-lynxpoint.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/pinctrl/intel/pinctrl-lynxpoint.c +14 -7
index 2a3af998b91c..003d795528e8 100644
@@ -386,6 +386,16 @@ static int lp_pinmux_set_mux(struct pinctrl_dev *pctldev,
 	return 0;
 }
 
+static void lp_gpio_enable_input(void __iomem *reg)
+{
+	iowrite32(ioread32(reg) & ~GPINDIS_BIT, reg);
+}
+
+static void lp_gpio_disable_input(void __iomem *reg)
+{
+	iowrite32(ioread32(reg) | GPINDIS_BIT, reg);
+}
+
 static int lp_gpio_request_enable(struct pinctrl_dev *pctldev,
 				  struct pinctrl_gpio_range *range,
 				  unsigned int pin)
@@ -411,7 +421,7 @@ static int lp_gpio_request_enable(struct pinctrl_dev *pctldev,
 	}
 
 	/* Enable input sensing */
-	iowrite32(ioread32(conf2) & ~GPINDIS_BIT, conf2);
+	lp_gpio_enable_input(conf2);
 
 	raw_spin_unlock_irqrestore(&lg->lock, flags);
 
@@ -429,7 +439,7 @@ static void lp_gpio_disable_free(struct pinctrl_dev *pctldev,
 	raw_spin_lock_irqsave(&lg->lock, flags);
 
 	/* Disable input sensing */
-	iowrite32(ioread32(conf2) | GPINDIS_BIT, conf2);
+	lp_gpio_disable_input(conf2);
 
 	raw_spin_unlock_irqrestore(&lg->lock, flags);
 
@@ -921,14 +931,11 @@ static int lp_gpio_resume(struct device *dev)
 	struct intel_pinctrl *lg = dev_get_drvdata(dev);
 	struct gpio_chip *chip = &lg->chip;
 	const char *dummy;
-	void __iomem *reg;
 	int i;
 
 	/* on some hardware suspend clears input sensing, re-enable it here */
-	for_each_requested_gpio(chip, i, dummy) {
-		reg = lp_gpio_reg(chip, i, LP_CONFIG2);
-		iowrite32(ioread32(reg) & ~GPINDIS_BIT, reg);
-	}
+	for_each_requested_gpio(chip, i, dummy)
+		lp_gpio_enable_input(lp_gpio_reg(chip, i, LP_CONFIG2));
 
 	return 0;
 }
Signature · 1 line
2.27.0.rc2
maintainer Acked-by on the v3 series
#8 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

This is part of previously sent clean up / fixes series against Intel pin control drivers. This piece replaces home grown alternatives to generic (*) for_each_requested_gpio*() helpers.

(*) Mika suggested to document for_each_requested_gpio*() helper, and I decided that it may be useful to GPIO and pin control subsystems in general, so, thus it has dependency to [1] submitted recently.

Quoted 6 lines

[1]: https://lore.kernel.org/linux-gpio/[email protected]/T/#t

Andy Shevchenko (3):
pinctrl: intel: Make use of for_each_requested_gpio_in_range()
pinctrl: lynxpoint: Make use of for_each_requested_gpio()
pinctrl: lynxpoint: Introduce helpers to enable or disable input

Looks good,