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 <luzmaximil...@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

Reply via email to