linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Revert "pinctrl: intel: Split intel_pinctrl_add_padgroups() for better maintenance"
@ 2021-03-08 15:25 Maximilian Luz
  2021-03-08 15:35 ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Maximilian Luz @ 2021-03-08 15:25 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Maximilian Luz, Mika Westerberg, Linus Walleij, Daniel Scally,
	linux-gpio, linux-kernel

Following commit 036e126c72eb ("pinctrl: intel: Split
intel_pinctrl_add_padgroups() for better maintenance"),
gpiochip_get_desc() is broken on some Kaby Lake R devices (specifically
a Microsoft Surface Book 2), returning -EINVAL for GPIOs that in reality
should be there (they are defined in ACPI and have been accessible
previously). Due to this, gpiod_get() fails with -ENOENT.

Reverting this commit fixes that issue and the GPIOs in question are
accessible again.

Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
---

There is probably a better option than straight up reverting this, so
consider this more of a bug-report.

Regards,
Max

---
 drivers/pinctrl/intel/pinctrl-intel.c | 60 +++++++++------------------
 1 file changed, 20 insertions(+), 40 deletions(-)

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 8085782cd8f9..0fe6caf98a8a 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1331,19 +1331,34 @@ static int intel_gpio_probe(struct intel_pinctrl *pctrl, int irq)
 	return 0;
 }
 
-static int intel_pinctrl_add_padgroups_by_gpps(struct intel_pinctrl *pctrl,
-					       struct intel_community *community)
+static int intel_pinctrl_add_padgroups(struct intel_pinctrl *pctrl,
+				       struct intel_community *community)
 {
 	struct intel_padgroup *gpps;
+	unsigned int npins = community->npins;
 	unsigned int padown_num = 0;
-	size_t i, ngpps = community->ngpps;
+	size_t ngpps, i;
+
+	if (community->gpps)
+		ngpps = community->ngpps;
+	else
+		ngpps = DIV_ROUND_UP(community->npins, community->gpp_size);
 
 	gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL);
 	if (!gpps)
 		return -ENOMEM;
 
 	for (i = 0; i < ngpps; i++) {
-		gpps[i] = community->gpps[i];
+		if (community->gpps) {
+			gpps[i] = community->gpps[i];
+		} else {
+			unsigned int gpp_size = community->gpp_size;
+
+			gpps[i].reg_num = i;
+			gpps[i].base = community->pin_base + i * gpp_size;
+			gpps[i].size = min(gpp_size, npins);
+			npins -= gpps[i].size;
+		}
 
 		if (gpps[i].size > 32)
 			return -EINVAL;
@@ -1361,38 +1376,6 @@ static int intel_pinctrl_add_padgroups_by_gpps(struct intel_pinctrl *pctrl,
 				break;
 		}
 
-		gpps[i].padown_num = padown_num;
-		padown_num += DIV_ROUND_UP(gpps[i].size * 4, 32);
-	}
-
-	community->gpps = gpps;
-
-	return 0;
-}
-
-static int intel_pinctrl_add_padgroups_by_size(struct intel_pinctrl *pctrl,
-					       struct intel_community *community)
-{
-	struct intel_padgroup *gpps;
-	unsigned int npins = community->npins;
-	unsigned int padown_num = 0;
-	size_t i, ngpps = DIV_ROUND_UP(npins, community->gpp_size);
-
-	if (community->gpp_size > 32)
-		return -EINVAL;
-
-	gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL);
-	if (!gpps)
-		return -ENOMEM;
-
-	for (i = 0; i < ngpps; i++) {
-		unsigned int gpp_size = community->gpp_size;
-
-		gpps[i].reg_num = i;
-		gpps[i].base = community->pin_base + i * gpp_size;
-		gpps[i].size = min(gpp_size, npins);
-		npins -= gpps[i].size;
-
 		gpps[i].padown_num = padown_num;
 
 		/*
@@ -1529,10 +1512,7 @@ static int intel_pinctrl_probe(struct platform_device *pdev,
 		community->regs = regs;
 		community->pad_regs = regs + offset;
 
-		if (community->gpps)
-			ret = intel_pinctrl_add_padgroups_by_gpps(pctrl, community);
-		else
-			ret = intel_pinctrl_add_padgroups_by_size(pctrl, community);
+		ret = intel_pinctrl_add_padgroups(pctrl, community);
 		if (ret)
 			return ret;
 	}
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-08 16:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-08 15:25 [PATCH] Revert "pinctrl: intel: Split intel_pinctrl_add_padgroups() for better maintenance" Maximilian Luz
2021-03-08 15:35 ` Andy Shevchenko
2021-03-08 16:31   ` Andy Shevchenko
2021-03-08 16:43     ` Maximilian Luz
2021-03-08 16:46       ` Andy Shevchenko
2021-03-08 16:47         ` Maximilian Luz
2021-03-08 16:32   ` Maximilian Luz
2021-03-08 16:42     ` Andy Shevchenko
2021-03-08 16:44       ` Maximilian Luz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).