intel-gpio for 5.4-2
Hi Linux GPIO maintainers,
Small set of urgent fixes against Intel GPIO drivers that have been recently converted to use GPIO core for instantiation of IRQ chip. No conflicts observed with fixes branch of GPIO tree as of today.
Thanks,
With Best Regards,
Andy Shevchenko
The following changes since commit 54ecb8f7028c5eb3d740bb82b0f1d90f2df63c5c:
Linux 5.4-rc1 (2019-09-30 10:35:40 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel.git tags/intel-gpio-v5.4-2
for you to fetch changes up to 6ed26a5326f6da6e1950b8476173df51a92a96be:
gpio: lynxpoint: set default handler to be handle_bad_irq() (2019-10-09 19:00:13 +0300)
----------------------------------------------------------------
intel-gpio for v5.4-2
The conversion to use of GPIO core to instantiate IRQ chip produced several issues among the drivers. Here is the set of fixes to:
* initialize hardware before IRQ chip will be added
* initialize hardware without NULL pointer dereference
* assign IRQ base
The following is an automated git shortlog grouped by driver:
gpiolib:
- Initialize the hardware with a callback
intel-mid:
- Move hardware initialization to callback
lynxpoint:
- set default handler to be handle_bad_irq()
- Move hardware initialization to callback
merrifield:
- Move hardware initialization to callback
- Restore use of irq_base
----------------------------------------------------------------
Andy Shevchenko (6):
gpio: merrifield: Restore use of irq_base
gpiolib: Initialize the hardware with a callback
gpio: intel-mid: Move hardware initialization to callback
gpio: lynxpoint: Move hardware initialization to callback
gpio: merrifield: Move hardware initialization to callback
gpio: lynxpoint: set default handler to be handle_bad_irq()
drivers/gpio/gpio-intel-mid.c | 9 ++++++--- drivers/gpio/gpio-lynxpoint.c | 10 ++++++---- drivers/gpio/gpio-merrifield.c | 9 ++++++--- drivers/gpio/gpiolib.c | 22 +++++++++++++++++++++- include/linux/gpio/driver.h | 8 ++++++++ 5 files changed, 47 insertions(+), 11 deletions(-)
PATCH 1/5 gpio: merrifield: Restore use of irq_base
During conversion to internal IRQ chip initialization the commit
8f86a5b4ad67 ("gpio: merrifield: Pass irqchip when adding gpiochip")
lost the irq_base assignment.
drivers/gpio/gpio-merrifield.c: In function ‘mrfld_gpio_probe’:drivers/gpio/gpio-merrifield.c:405:17: warning: variable ‘irq_base’ set but not used [-Wunused-but-set-variable]
Assign the girq->first to it.
--- drivers/gpio/gpio-merrifield.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpio-merrifield.c +1 -0
@@ -455,6 +455,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *idif (!girq->parents)return -ENOMEM ; girq->parents[0 ] = pdev->irq; + girq->first = irq_base; girq->default_type =IRQ_TYPE_NONE ; girq->handler = handle_bad_irq;
Signature · 1 line
2.23.0
Re: [PATCH 1/5] gpio: merrifield: Restore use of irq_base
Op 09-10-19 om 18:50 schreef Andy Shevchenko:
Quoted 11 lines
During conversion to internal IRQ chip initialization the commit
8f86a5b4ad67("gpio: merrifield: Pass irqchip when adding gpiochip")
lost theirq_baseassignment.
drivers/gpio/gpio-merrifield.c: In function ‘mrfld_gpio_probe’:drivers/gpio/gpio-merrifield.c:405:17: warning: variable ‘irq_base’ set but not used [-Wunused-but-set-variable]Assign the
girq->firstto it.Fixes 8f86a5b4ad67 ("gpio: merrifield: Pass irqchip when adding gpiochip")Signed-off-by Andy Shevchenko <[email protected]>
Fixes boot when applied 5.4-rc2
Quoted 17 lines
--- drivers/gpio/gpio-merrifield.c | 1 + 1 file changed, 1 insertion(+)drivers/gpio/gpio-merrifield.c +1
-0@@ -455,6 +455,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *idif (!girq->parents)return -ENOMEM ; girq->parents[0 ] = pdev->irq; + girq->first = irq_base; girq->default_type =IRQ_TYPE_NONE ; girq->handler = handle_bad_irq;
PATCH 2/5 gpiolib: Initialize the hardware with a callback
In reply to Andy ShevchenkoAfter changing the drivers to use GPIO core to add an IRQ chip it appears that some of them requires a hardware initialization before adding the IRQ chip.
Add an optional callback ->init_hw() to allow that drivers to initialize hardware if needed.
This change is a part of the fix NULL pointer dereference brought to the several drivers recently.
--- drivers/gpio/gpiolib.c | 22 +++++++++++++++++++++- include/linux/gpio/driver.h | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +21 -1
@@ -86,6 +86,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,struct lock_class_key *lock_key, struct lock_class_key *request_key);static void gpiochip_irqchip_remove (struct gpio_chip *gpiochip); +static int gpiochip_irqchip_init_hw (struct gpio_chip *gpiochip);static int gpiochip_irqchip_init_valid_mask (struct gpio_chip *gpiochip);static void gpiochip_irqchip_free_valid_mask (struct gpio_chip *gpiochip);
@@ -1406,6 +1407,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,machine_gpiochip_add (chip); + ret =gpiochip_irqchip_init_hw (chip); +if (ret) + goto err_remove_acpi_chip; + ret =gpiochip_irqchip_init_valid_mask (chip);if (ret) goto err_remove_acpi_chip;
@@ -1622,6 +1627,16 @@ static struct gpio_chip *find_chip_by_name(const char *name)* The following is irqchip helper code for gpiochips. */ +static int gpiochip_irqchip_init_hw (struct gpio_chip *gc) +{ +struct gpio_irq_chip *girq = &gc->irq; + +if (!girq->init_hw) +return 0 ; + +return girq->init_hw (gc); +} +static int gpiochip_irqchip_init_valid_mask (struct gpio_chip *gc) {struct gpio_irq_chip *girq = &gc->irq;
@@ -2446,8 +2461,13 @@ static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip, {return 0 ; } -static void gpiochip_irqchip_remove (struct gpio_chip *gpiochip) {} + +static inline int gpiochip_irqchip_init_hw (struct gpio_chip *gpiochip) +{ +return 0 ; +} +static inline int gpiochip_irqchip_init_valid_mask (struct gpio_chip *gpiochip) {return 0 ;
include/linux/gpio/driver.h +8 -0
@@ -201,6 +201,14 @@ struct gpio_irq_chip {*/ bool threaded; +/** +* @init_hw: optional routine to initialize hardware before +* an IRQ chip will be added. This is quite useful when +* a particular driver wants to clear IRQ related registers +* in order to avoid undesired events. +*/ +int (*init_hw)(struct gpio_chip *chip); +/** * @init_valid_mask: optional routine to initialize @valid_mask, to be * used if not all GPIO lines are valid interrupts. Sometimes some
Signature · 1 line
2.23.0
Re: [PATCH 2/5] gpiolib: Initialize the hardware with a callback
Hi,
Quoted 4 lines · Andy Shevchenko
After changing the drivers to use GPIO core to add an IRQ chip it appears that some of them requires a hardware initialization before adding the IRQ chip.
Quoted 8 lines
Add an optional callback ->init_hw() to allow that drivers to initialize hardware if needed.
This change is a part of the fix NULL pointer dereference brought to the several drivers recently.
Cc Hans de Goede <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Hmm, IIRC Linus Walleij already added a callback for initializing the mask before the irchip gets initialized which is basically intended for what you want this callback for I think ?
Regards.
Hans
Quoted 80 lines
--- drivers/gpio/gpiolib.c | 22 +++++++++++++++++++++- include/linux/gpio/driver.h | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)drivers/gpio/gpiolib.c +21
-1@@ -86,6 +86,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,struct lock_class_key *lock_key, struct lock_class_key *request_key);static void gpiochip_irqchip_remove (struct gpio_chip *gpiochip); +static int gpiochip_irqchip_init_hw (struct gpio_chip *gpiochip);static int gpiochip_irqchip_init_valid_mask (struct gpio_chip *gpiochip);static void gpiochip_irqchip_free_valid_mask (struct gpio_chip *gpiochip);@@ -1406,6 +1407,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,machine_gpiochip_add (chip); + ret =gpiochip_irqchip_init_hw (chip); +if (ret) + goto err_remove_acpi_chip; + ret =gpiochip_irqchip_init_valid_mask (chip);if (ret) goto err_remove_acpi_chip;@@ -1622,6 +1627,16 @@ static struct gpio_chip *find_chip_by_name(const char *name)* The following is irqchip helper code for gpiochips. */ +static int gpiochip_irqchip_init_hw (struct gpio_chip *gc) +{ +struct gpio_irq_chip *girq = &gc->irq; + +if (!girq->init_hw) +return 0 ; + +return girq->init_hw (gc); +} +static int gpiochip_irqchip_init_valid_mask (struct gpio_chip *gc) {struct gpio_irq_chip *girq = &gc->irq;@@ -2446,8 +2461,13 @@ static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip, {return 0 ; } -static void gpiochip_irqchip_remove (struct gpio_chip *gpiochip) {} + +static inline int gpiochip_irqchip_init_hw (struct gpio_chip *gpiochip) +{ +return 0 ; +} +static inline int gpiochip_irqchip_init_valid_mask (struct gpio_chip *gpiochip) {return 0 ;include/linux/gpio/driver.h +8
-0@@ -201,6 +201,14 @@ struct gpio_irq_chip {*/ bool threaded; +/** +* @init_hw: optional routine to initialize hardware before +* an IRQ chip will be added. This is quite useful when +* a particular driver wants to clear IRQ related registers +* in order to avoid undesired events. +*/ +int (*init_hw)(struct gpio_chip *chip); +/** * @init_valid_mask: optional routine to initialize @valid_mask, to be * used if not all GPIO lines are valid interrupts. Sometimes some
Re: [PATCH 2/5] gpiolib: Initialize the hardware with a callback
Quoted 11 lines · Hans de Goede
Quoted 10 lines · Andy Shevchenko
After changing the drivers to use GPIO core to add an IRQ chip it appears that some of them requires a hardware initialization before adding the IRQ chip.
Add an optional callback ->init_hw() to allow that drivers to initialize hardware if needed.
This change is a part of the fix NULL pointer dereference brought to the several drivers recently.
Quoted 6 lines
Quoted 2 lines
Cc Hans de Goede <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Hmm, IIRC Linus Walleij already added a callback for initializing the mask before the irchip gets initialized which is basically intended for what you want this callback for I think ?
This is not about the mask, it's about hardware to be prepared before enabling. Also init_valid_mask() will allocate memory which won't be needed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/5] gpiolib: Initialize the hardware with a callback
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Hans de Goede
Quoted 12 lines · Andy Shevchenko
After changing the drivers to use GPIO core to add an IRQ chip it appears that some of them requires a hardware initialization before adding the IRQ chip.
Add an optional callback ->init_hw() to allow that drivers to initialize hardware if needed.
This change is a part of the fix NULL pointer dereference brought to the several drivers recently.
Cc Hans de Goede <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 6 lines
Quoted 3 lines
Hmm, IIRC Linus Walleij already added a callback for initializing the mask before the irchip gets initialized which is basically intended for what you want this callback for I think ?
This is not about the mask, it's about hardware to be prepared before enabling. Also
init_valid_mask()will allocate memory which won't be needed.
If you think this is not a proper approach, we have to revert all three patches now (*) and think about better solution.
*) They broke the boot on all affected machines.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/5] gpiolib: Initialize the hardware with a callback
Hi,
Quoted 20 lines · Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 17 lines · Hans de Goede
Quoted 4 lines · Andy Shevchenko
After changing the drivers to use GPIO core to add an IRQ chip it appears that some of them requires a hardware initialization before adding the IRQ chip.
Quoted 8 lines
Add an optional callback ->init_hw() to allow that drivers to initialize hardware if needed.
This change is a part of the fix NULL pointer dereference brought to the several drivers recently.
Cc Hans de Goede <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Hmm, IIRC Linus Walleij already added a callback for initializing the mask before the irchip gets initialized which is basically intended for what you want this callback for I think ?
Quoted 5 lines
Quoted 2 lines
This is not about the mask, it's about hardware to be prepared before enabling. Also
init_valid_mask()will allocate memory which won't be needed.If you think this is not a proper approach, we have to revert all three patches now (*) and think about better solution.
If this is not about the valid-mask then this approach is probably fine, sorry for the confusion. Lets wait and see what Linus Walleij has to say.
Regards,
Hans
Re: [PATCH 2/5] gpiolib: Initialize the hardware with a callback
In reply to Andy ShevchenkoQuoted 4 lines · Andy Shevchenko
After changing the drivers to use GPIO core to add an IRQ chip it appears that some of them requires a hardware initialization before adding the IRQ chip.
Quoted 8 lines
Add an optional callback ->init_hw() to allow that drivers to initialize hardware if needed.
This change is a part of the fix NULL pointer dereference brought to the several drivers recently.
Cc Hans de Goede <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Ouch!
But a very nice fix.
I will pull in the series.
Thanks for fixing this up so nicely Andy!
Yours,
Linus Walleij
PATCH 3/5 gpio: intel-mid: Move hardware initialization to callback
In reply to Andy ShevchenkoThe driver wants to initialize related registers before IRQ chip will be added. That's why move it to a corresponding callback. It also fixes the NULL pointer dereference.
--- drivers/gpio/gpio-intel-mid.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-intel-mid.c +6 -3
@@ -293,8 +293,9 @@ static void intel_mid_irq_handler(struct irq_desc *desc) chip->irq_eoi (data); } -static void intel_mid_irq_init_hw (struct intel_mid_gpio *priv) +static int intel_mid_irq_init_hw (struct gpio_chip *chip) { +struct intel_mid_gpio *priv =gpiochip_get_data (chip);void __iomem *reg;unsigned base;
@@ -309,6 +310,8 @@ static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv) reg =gpio_reg (&priv->chip, base,GEDR );writel (~0 , reg); } + +return 0 ; }static int __maybe_unused intel_gpio_runtime_idle (struct device *dev)
@@ -372,6 +375,7 @@ static int intel_gpio_probe(struct pci_dev *pdev, girq = &priv->chip.irq; girq->chip = &intel_mid_irqchip; + girq->init_hw = intel_mid_irq_init_hw; girq->parent_handler = intel_mid_irq_handler; girq->num_parents =1 ; girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -384,9 +388,8 @@ static int intel_gpio_probe(struct pci_dev *pdev, girq->default_type =IRQ_TYPE_NONE ; girq->handler = handle_simple_irq; -intel_mid_irq_init_hw (priv); -pci_set_drvdata (pdev, priv); + retval =devm_gpiochip_add_data (&pdev->dev, &priv->chip, priv);if (retval) {dev_err (&pdev->dev,"gpiochip_add error %d\n" , retval);
Signature · 1 line
2.23.0
PATCH 4/5 gpio: lynxpoint: Move hardware initialization to callback
In reply to Andy ShevchenkoThe driver wants to initialize related registers before IRQ chip will be added. That's why move it to a corresponding callback. It also fixes the NULL pointer dereference.
--- drivers/gpio/gpio-lynxpoint.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpio/gpio-lynxpoint.c +5 -3
@@ -294,8 +294,9 @@ static struct irq_chip lp_irqchip = { .flags = IRQCHIP_SKIP_SET_WAKE, }; -static void lp_gpio_irq_init_hw (struct lp_gpio *lg) +static int lp_gpio_irq_init_hw (struct gpio_chip *chip) { +struct lp_gpio *lg =gpiochip_get_data (chip);unsigned long reg;unsigned base;
@@ -307,6 +308,8 @@ static void lp_gpio_irq_init_hw(struct lp_gpio *lg) reg =lp_gpio_reg (&lg->chip, base,LP_INT_STAT );outl (0xffffffff , reg); } + +return 0 ; }static int lp_gpio_probe (struct platform_device *pdev)
@@ -364,6 +367,7 @@ static int lp_gpio_probe(struct platform_device *pdev) girq = &gc->irq; girq->chip = &lp_irqchip; + girq->init_hw = lp_gpio_irq_init_hw; girq->parent_handler = lp_gpio_irq_handler; girq->num_parents =1 ; girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -374,8 +378,6 @@ static int lp_gpio_probe(struct platform_device *pdev) girq->parents[0 ] = (unsigned )irq_rc->start; girq->default_type =IRQ_TYPE_NONE ; girq->handler = handle_simple_irq; - -lp_gpio_irq_init_hw (lg); } ret =devm_gpiochip_add_data (dev, gc, lg);
Signature · 1 line
2.23.0
PATCH 5/5 gpio: merrifield: Move hardware initialization to callback
In reply to Andy ShevchenkoThe driver wants to initialize related registers before IRQ chip will be added. That's why move it to a corresponding callback. It also fixes the NULL pointer dereference.
--- drivers/gpio/gpio-merrifield.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpio/gpio-merrifield.c +5 -3
@@ -362,8 +362,9 @@ static void mrfld_irq_handler(struct irq_desc *desc)chained_irq_exit (irqchip, desc); } -static void mrfld_irq_init_hw (struct mrfld_gpio *priv) +static int mrfld_irq_init_hw (struct gpio_chip *chip) { +struct mrfld_gpio *priv =gpiochip_get_data (chip);void __iomem *reg;unsigned int base;
@@ -375,6 +376,8 @@ static void mrfld_irq_init_hw(struct mrfld_gpio *priv) reg =gpio_reg (&priv->chip, base,GFER );writel (0 , reg); } + +return 0 ; }static const char *mrfld_gpio_get_pinctrl_dev_name (struct mrfld_gpio *priv)
@@ -447,6 +450,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id girq = &priv->chip.irq; girq->chip = &mrfld_irqchip; + girq->init_hw = mrfld_irq_init_hw; girq->parent_handler = mrfld_irq_handler; girq->num_parents =1 ; girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -459,8 +463,6 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id girq->default_type =IRQ_TYPE_NONE ; girq->handler = handle_bad_irq; -mrfld_irq_init_hw (priv); -pci_set_drvdata (pdev, priv); retval =devm_gpiochip_add_data (&pdev->dev, &priv->chip, priv);if (retval) {
Signature · 1 line
2.23.0
Re: [PATCH 5/5] gpio: merrifield: Move hardware initialization to callback
Op 09-10-19 om 18:50 schreef Andy Shevchenko:
Quoted 6 lines
The driver wants to initialize related registers before IRQ chip will be added. That's why move it to a corresponding callback. It also fixes the NULL pointer dereference.
Fixes 8f86a5b4ad67 ("gpio: merrifield: Pass irqchip when adding gpiochip")Signed-off-by Andy Shevchenko <[email protected]>
Fixes boot when applied to 5.4-rc2
Quoted 46 lines
--- drivers/gpio/gpio-merrifield.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/gpio/gpio-merrifield.c +5
-3@@ -362,8 +362,9 @@ static void mrfld_irq_handler(struct irq_desc *desc)chained_irq_exit (irqchip, desc); } -static void mrfld_irq_init_hw (struct mrfld_gpio *priv) +static int mrfld_irq_init_hw (struct gpio_chip *chip) { +struct mrfld_gpio *priv =gpiochip_get_data (chip);void __iomem *reg;unsigned int base;@@ -375,6 +376,8 @@ static void mrfld_irq_init_hw(struct mrfld_gpio *priv) reg =gpio_reg (&priv->chip, base,GFER );writel (0 , reg); } + +return 0 ; }static const char *mrfld_gpio_get_pinctrl_dev_name (struct mrfld_gpio *priv)@@ -447,6 +450,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id girq = &priv->chip.irq; girq->chip = &mrfld_irqchip; + girq->init_hw = mrfld_irq_init_hw; girq->parent_handler = mrfld_irq_handler; girq->num_parents =1 ; girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,@@ -459,8 +463,6 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id girq->default_type =IRQ_TYPE_NONE ; girq->handler = handle_bad_irq; -mrfld_irq_init_hw (priv); -pci_set_drvdata (pdev, priv); retval =devm_gpiochip_add_data (&pdev->dev, &priv->chip, priv);if (retval) {
Quoted 3 lines · Andy Shevchenko
Small set of urgent fixes against Intel GPIO drivers that have been recently converted to use GPIO core for instantiation of IRQ chip. No conflicts observed with fixes branch of GPIO tree as of today.
Thanks Andy, I pulled this in so hopefully -next works, I will have to rebase on v5.4-rc2 next week before sending this so will re-sign-off at that point.
Yours,
Linus Walleij
Quoted 10 lines · Linus Walleij
Quoted 3 lines · Andy Shevchenko
Small set of urgent fixes against Intel GPIO drivers that have been recently converted to use GPIO core for instantiation of IRQ chip. No conflicts observed with fixes branch of GPIO tree as of today.
Thanks Andy, I pulled this in so hopefully -next works, I will have to rebase on v5.4-rc2 next week before sending this so will re-sign-off at that point.
Thank you, Linus!
I guess you meant v5.4-rc3?
Signature · 2 lines
With Best Regards, Andy Shevchenko