Skip to contentSkip to conversation

pinctrl: baytrail: Do not add all GPIOs to IRQ domain

PATCH Superseded Andy Shevchenko 3 participants 8 messages Jan 10, 2017 – Jan 11, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pinctrl: baytrail: Do not add all GPIOs to IRQ domain

It turns out that for some GPIO pins interrupts are bypassing standard chain.

Now the reason why some events such as touchscreen communication on ASuS T100TA does not work if we mask all the interrupts is that in order to generate either interrupts or GPEs the INTMASK register must have that particular interrupt unmasked. In case of GPEs the CPU does not trigger normal interrupt (and thus the GPIO driver does not see it) but instead it causes SCI (System Control Interrupt) to be triggered with the GPE in question set.

To make this all work as expected we add those GPIOs to the IRQ domain that can actually generate interrupts and skip others.

Fixes 3ae02c14d964 ("pinctrl: intel: set default handler to be handle_bad_irq()")
---
 drivers/pinctrl/intel/pinctrl-baytrail.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/pinctrl/intel/pinctrl-baytrail.c +8 -3
index 67e92699b84e..c123488266ce 100644
@@ -1623,6 +1623,8 @@ static void byt_gpio_irq_handler(struct irq_desc *desc)
 
 static void byt_gpio_irq_init_hw(struct byt_gpio *vg)
 {
+	struct gpio_chip *gc = &vg->chip;
+	struct device *dev = &vg->pdev->dev;
 	void __iomem *reg;
 	u32 base, value;
 	int i;
@@ -1644,10 +1646,12 @@ static void byt_gpio_irq_init_hw(struct byt_gpio *vg)
 		}
 
 		value = readl(reg);
-		if ((value & BYT_PIN_MUX) == byt_get_gpio_mux(vg, i) &&
-		    !(value & BYT_DIRECT_IRQ_EN)) {
+		if (value & BYT_DIRECT_IRQ_EN) {
+			clear_bit(i, gc->irq_valid_mask);
+			dev_dbg(dev, "excluding GPIO %d from IRQ domain\n", i);
+		} else if ((value & BYT_PIN_MUX) == byt_get_gpio_mux(vg, i)) {
 			byt_gpio_clear_triggering(vg, i);
-			dev_dbg(&vg->pdev->dev, "disabling GPIO %d\n", i);
+			dev_dbg(dev, "disabling GPIO %d\n", i);
 		}
 	}
 
@@ -1686,6 +1690,7 @@ static int byt_gpio_probe(struct byt_gpio *vg)
 	gc->can_sleep	= false;
 	gc->parent	= &vg->pdev->dev;
 	gc->ngpio	= vg->soc_data->npins;
+	gc->irq_need_valid_mask	= true;
 
 #ifdef CONFIG_PM_SLEEP
 	vg->saved_context = devm_kcalloc(&vg->pdev->dev, gc->ngpio,
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/2 pinctrl: baytrail: Convert to use devm_*()

This simplifies error handling and allows us to drop error path handlers completely.

---
 drivers/pinctrl/intel/pinctrl-baytrail.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/pinctrl/intel/pinctrl-baytrail.c +5 -12
index c123488266ce..e696a01365cb 100644
@@ -1696,7 +1696,7 @@ static int byt_gpio_probe(struct byt_gpio *vg)
 	vg->saved_context = devm_kcalloc(&vg->pdev->dev, gc->ngpio,
 				       sizeof(*vg->saved_context), GFP_KERNEL);
 #endif
-	ret = gpiochip_add_data(gc, vg);
+	ret = devm_gpiochip_add_data(&vg->pdev->dev, gc, vg);
 	if (ret) {
 		dev_err(&vg->pdev->dev, "failed adding byt-gpio chip\n");
 		return ret;
@@ -1706,7 +1706,7 @@ static int byt_gpio_probe(struct byt_gpio *vg)
 				     0, 0, vg->soc_data->npins);
 	if (ret) {
 		dev_err(&vg->pdev->dev, "failed to add GPIO pin range\n");
-		goto fail;
+		return ret;
 	}
 
 	/* set up interrupts  */
@@ -1717,7 +1717,7 @@ static int byt_gpio_probe(struct byt_gpio *vg)
 					   handle_bad_irq, IRQ_TYPE_NONE);
 		if (ret) {
 			dev_err(&vg->pdev->dev, "failed to add irqchip\n");
-			goto fail;
+			return ret;
 		}
 
 		gpiochip_set_chained_irqchip(gc, &byt_irqchip,
@@ -1726,11 +1726,6 @@ static int byt_gpio_probe(struct byt_gpio *vg)
 	}
 
 	return ret;
-
-fail:
-	gpiochip_remove(&vg->chip);
-
-	return ret;
 }
 
 static int byt_set_soc_data(struct byt_gpio *vg,
@@ -1813,7 +1808,7 @@ static int byt_pinctrl_probe(struct platform_device *pdev)
 	vg->pctl_desc.pins	= vg->soc_data->pins;
 	vg->pctl_desc.npins	= vg->soc_data->npins;
 
-	vg->pctl_dev = pinctrl_register(&vg->pctl_desc, &pdev->dev, vg);
+	vg->pctl_dev = devm_pinctrl_register(&pdev->dev, &vg->pctl_desc, vg);
 	if (IS_ERR(vg->pctl_dev)) {
 		dev_err(&pdev->dev, "failed to register pinctrl driver\n");
 		return PTR_ERR(vg->pctl_dev);
@@ -1822,10 +1817,8 @@ static int byt_pinctrl_probe(struct platform_device *pdev)
 	raw_spin_lock_init(&vg->lock);
 
 	ret = byt_gpio_probe(vg);
-	if (ret) {
-		pinctrl_unregister(vg->pctl_dev);
+	if (ret)
 		return ret;
-	}
 
 	platform_set_drvdata(pdev, vg);
 	pm_runtime_enable(&pdev->dev);
Signature · 1 line
2.11.0
#4 lore raw
In reply to Andy Shevchenko
Quoted 15 lines · Andy Shevchenko

It turns out that for some GPIO pins interrupts are bypassing standard chain.

Now the reason why some events such as touchscreen communication on ASuS
T100TA does not work if we mask all the interrupts is that in order to generate either interrupts or GPEs the INTMASK register must have that particular interrupt unmasked. In case of GPEs the CPU does not trigger
normal interrupt (and thus the GPIO driver does not see it) but instead
it causes SCI (System Control Interrupt) to be triggered with the GPE in
question set.

Quoted 3 lines

To make this all work as expected we add those GPIOs to the IRQ domain that can actually generate interrupts and skip others.

Suggested-by Mika.

Mika, please check if I wrote description clearly.

Quoted 52 lines
Fixes 3ae02c14d964 ("pinctrl: intel: set default handler to be

handle_bad_irq()")

---
 drivers/pinctrl/intel/pinctrl-baytrail.c | 11 ++++++++---

 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/pinctrl/intel/pinctrl-baytrail.c +0 -0
index 67e92699b84e..c123488266ce 100644
@@ -1623,6 +1623,8 @@ static void byt_gpio_irq_handler(struct irq_desc
 *desc)


 static void byt_gpio_irq_init_hw(struct byt_gpio *vg) {

drivers/pinctrl/intel/pinctrl-baytrail.c +2 -0
+	struct gpio_chip *gc = &vg->chip;
+	struct device *dev = &vg->pdev->dev;

  void __iomem *reg;
  u32 base, value;
  int i;

drivers/pinctrl/intel/pinctrl-baytrail.c +0 -0
@@ -1644,10 +1646,12 @@ static void byt_gpio_irq_init_hw(struct
 byt_gpio *vg)
  		}


  value = readl(reg);

drivers/pinctrl/intel/pinctrl-baytrail.c +0 -1
-		if ((value & BYT_PIN_MUX) == byt_get_gpio_mux(vg, i)

&&

drivers/pinctrl/intel/pinctrl-baytrail.c +3 -1
-		    !(value & BYT_DIRECT_IRQ_EN)) {
+		if (value & BYT_DIRECT_IRQ_EN) {
+			clear_bit(i, gc->irq_valid_mask);
+			dev_dbg(dev, "excluding GPIO %d from IRQ

domain\n", i);

drivers/pinctrl/intel/pinctrl-baytrail.c +1 -0
+		} else if ((value & BYT_PIN_MUX) ==

byt_get_gpio_mux(vg, i)) { byt_gpio_clear_triggering(vg, i);

drivers/pinctrl/intel/pinctrl-baytrail.c +0 -1
-			dev_dbg(&vg->pdev->dev, "disabling GPIO

%d\n", i);

drivers/pinctrl/intel/pinctrl-baytrail.c +1 -0
+			dev_dbg(dev, "disabling GPIO %d\n", i);

  }
  }

drivers/pinctrl/intel/pinctrl-baytrail.c +1 -0
@@ -1686,6 +1690,7 @@ static int byt_gpio_probe(struct byt_gpio *vg)
  	gc->can_sleep	= false;
  	gc->parent	= &vg->pdev->dev;
  	gc->ngpio	= vg->soc_data->npins;
+	gc->irq_need_valid_mask	= true;


 #ifdef CONFIG_PM_SLEEP
  vg->saved_context = devm_kcalloc(&vg->pdev->dev, gc->ngpio,

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
maintainer
#5 lore raw
In reply to Andy Shevchenko
Quoted 11 lines · Andy Shevchenko

It turns out that for some GPIO pins interrupts are bypassing standard chain.

Now the reason why some events such as touchscreen communication on ASuS T100TA does not work if we mask all the interrupts is that in order to generate either interrupts or GPEs the INTMASK register must have that particular interrupt unmasked. In case of GPEs the CPU does not trigger normal interrupt (and thus the GPIO driver does not see it) but instead it causes SCI (System Control Interrupt) to be triggered with the GPE in question set.

Quoted 2 lines

To make this all work as expected we add those GPIOs to the IRQ domain that can actually generate interrupts and skip others.

Actually what happens is that when DIRECT_IRQ_EN is set, the pin is routed directly to the IO-APIC bypassing the GPIO driver completely. However, the mask register is still used to determine if the pin is supposed to generate IRQ or not.

So with commit 3ae02c14d964 the IRQ core masks all IRQs (because of handle_bad_irq()) the pin connected to the touchscreen gets masked as well and hence no interrupts.

This has nothing to do with GPEs, though.

The fix itself looks good to me.

Quoted 46 lines
Fixes 3ae02c14d964 ("pinctrl: intel: set default handler to be handle_bad_irq()")
---
 drivers/pinctrl/intel/pinctrl-baytrail.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/pinctrl/intel/pinctrl-baytrail.c +8 -3
index 67e92699b84e..c123488266ce 100644
@@ -1623,6 +1623,8 @@ static void byt_gpio_irq_handler(struct irq_desc *desc)
 
 static void byt_gpio_irq_init_hw(struct byt_gpio *vg)
 {
+	struct gpio_chip *gc = &vg->chip;
+	struct device *dev = &vg->pdev->dev;
 	void __iomem *reg;
 	u32 base, value;
 	int i;
@@ -1644,10 +1646,12 @@ static void byt_gpio_irq_init_hw(struct byt_gpio *vg)
 		}
 
 		value = readl(reg);
-		if ((value & BYT_PIN_MUX) == byt_get_gpio_mux(vg, i) &&
-		    !(value & BYT_DIRECT_IRQ_EN)) {
+		if (value & BYT_DIRECT_IRQ_EN) {
+			clear_bit(i, gc->irq_valid_mask);
+			dev_dbg(dev, "excluding GPIO %d from IRQ domain\n", i);
+		} else if ((value & BYT_PIN_MUX) == byt_get_gpio_mux(vg, i)) {
 			byt_gpio_clear_triggering(vg, i);
-			dev_dbg(&vg->pdev->dev, "disabling GPIO %d\n", i);
+			dev_dbg(dev, "disabling GPIO %d\n", i);
 		}
 	}
 
@@ -1686,6 +1690,7 @@ static int byt_gpio_probe(struct byt_gpio *vg)
 	gc->can_sleep	= false;
 	gc->parent	= &vg->pdev->dev;
 	gc->ngpio	= vg->soc_data->npins;
+	gc->irq_need_valid_mask	= true;
 
 #ifdef CONFIG_PM_SLEEP
 	vg->saved_context = devm_kcalloc(&vg->pdev->dev, gc->ngpio,
Signature · 1 line
2.11.0
#6 lore raw
Quoted 20 lines · Mika Westerberg
Quoted 11 lines · Andy Shevchenko

It turns out that for some GPIO pins interrupts are bypassing standard chain.

Now the reason why some events such as touchscreen communication on ASuS T100TA does not work if we mask all the interrupts is that in order to generate either interrupts or GPEs the INTMASK register must have that particular interrupt unmasked. In case of GPEs the CPU does not trigger normal interrupt (and thus the GPIO driver does not see it) but instead it causes SCI (System Control Interrupt) to be triggered with the GPE in question set.

Quoted 2 lines

To make this all work as expected we add those GPIOs to the IRQ domain that can actually generate interrupts and skip others.

Actually what happens is that when DIRECT_IRQ_EN is set, the pin is routed directly to the IO-APIC bypassing the GPIO driver completely. However, the mask register is still used to determine if the pin is supposed to generate IRQ or not.

Quoted 7 lines

So with commit 3ae02c14d964 the IRQ core masks all IRQs (because of handle_bad_irq()) the pin connected to the touchscreen gets masked as well and hence no interrupts.

This has nothing to do with GPEs, though.

The fix itself looks good to me.

So I guess I wait for a commit with updates commit message and then apply that for fixes?

Yours,
Linus Walleij

#7 lore raw
Quoted 34 lines · Linus Walleij
Quoted 32 lines · Mika Westerberg
Quoted 18 lines · Andy Shevchenko

It turns out that for some GPIO pins interrupts are bypassing standard
chain.

Now the reason why some events such as touchscreen communication on ASuS
T100TA does not work if we mask all the interrupts is that in order to
generate either interrupts or GPEs the INTMASK register must have that
particular interrupt unmasked. In case of GPEs the CPU does not trigger
normal interrupt (and thus the GPIO driver does not see it) but instead
it causes SCI (System Control Interrupt) to be triggered with the GPE in
question set.

Quoted 2 lines

To make this all work as expected we add those GPIOs to the IRQ domain that can actually generate interrupts and skip others.

Actually what happens is that when DIRECT_IRQ_EN is set, the pin is routed directly to the IO-APIC bypassing the GPIO driver completely. However, the mask register is still used to determine if the pin is supposed to generate IRQ or not.

So with commit 3ae02c14d964 the IRQ core masks all IRQs (because of handle_bad_irq()) the pin connected to the touchscreen gets masked as
well and hence no interrupts.

Quoted 6 lines
Quoted 3 lines

This has nothing to do with GPEs, though.

The fix itself looks good to me.

So I guess I wait for a commit with updates commit message and then apply that for fixes?

Correct, I'm doing it right now. Takes time to do and to test of course.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy