Skip to content

Commit 7801158

Browse files
committed
Merge tag 'gpio-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "The fixes pertain to a problem with initializing the Intel GPIO irqchips when adding gpiochips. Andy fixed it up elegantly by adding a hardware initialization callback to the struct gpio_irq_chip so let's use this. Tested and verified on the target hardware" * tag 'gpio-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: lynxpoint: set default handler to be handle_bad_irq() gpio: merrifield: Move hardware initialization to callback gpio: lynxpoint: Move hardware initialization to callback gpio: intel-mid: Move hardware initialization to callback gpiolib: Initialize the hardware with a callback gpio: merrifield: Restore use of irq_base
2 parents bc88f85 + 75e99bf commit 7801158

5 files changed

Lines changed: 47 additions & 11 deletions

File tree

‎drivers/gpio/gpio-intel-mid.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ static void intel_mid_irq_handler(struct irq_desc *desc)
293293
chip->irq_eoi(data);
294294
}
295295

296-
static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv)
296+
static int intel_mid_irq_init_hw(struct gpio_chip *chip)
297297
{
298+
struct intel_mid_gpio *priv = gpiochip_get_data(chip);
298299
void __iomem *reg;
299300
unsigned base;
300301

@@ -309,6 +310,8 @@ static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv)
309310
reg = gpio_reg(&priv->chip, base, GEDR);
310311
writel(~0, reg);
311312
}
313+
314+
return 0;
312315
}
313316

314317
static int __maybe_unused intel_gpio_runtime_idle(struct device *dev)
@@ -372,6 +375,7 @@ static int intel_gpio_probe(struct pci_dev *pdev,
372375

373376
girq = &priv->chip.irq;
374377
girq->chip = &intel_mid_irqchip;
378+
girq->init_hw = intel_mid_irq_init_hw;
375379
girq->parent_handler = intel_mid_irq_handler;
376380
girq->num_parents = 1;
377381
girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -384,9 +388,8 @@ static int intel_gpio_probe(struct pci_dev *pdev,
384388
girq->default_type = IRQ_TYPE_NONE;
385389
girq->handler = handle_simple_irq;
386390

387-
intel_mid_irq_init_hw(priv);
388-
389391
pci_set_drvdata(pdev, priv);
392+
390393
retval = devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv);
391394
if (retval) {
392395
dev_err(&pdev->dev, "gpiochip_add error %d\n", retval);

‎drivers/gpio/gpio-lynxpoint.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ static struct irq_chip lp_irqchip = {
294294
.flags = IRQCHIP_SKIP_SET_WAKE,
295295
};
296296

297-
static void lp_gpio_irq_init_hw(struct lp_gpio *lg)
297+
static int lp_gpio_irq_init_hw(struct gpio_chip *chip)
298298
{
299+
struct lp_gpio *lg = gpiochip_get_data(chip);
299300
unsigned long reg;
300301
unsigned base;
301302

@@ -307,6 +308,8 @@ static void lp_gpio_irq_init_hw(struct lp_gpio *lg)
307308
reg = lp_gpio_reg(&lg->chip, base, LP_INT_STAT);
308309
outl(0xffffffff, reg);
309310
}
311+
312+
return 0;
310313
}
311314

312315
static int lp_gpio_probe(struct platform_device *pdev)
@@ -364,6 +367,7 @@ static int lp_gpio_probe(struct platform_device *pdev)
364367

365368
girq = &gc->irq;
366369
girq->chip = &lp_irqchip;
370+
girq->init_hw = lp_gpio_irq_init_hw;
367371
girq->parent_handler = lp_gpio_irq_handler;
368372
girq->num_parents = 1;
369373
girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -373,9 +377,7 @@ static int lp_gpio_probe(struct platform_device *pdev)
373377
return -ENOMEM;
374378
girq->parents[0] = (unsigned)irq_rc->start;
375379
girq->default_type = IRQ_TYPE_NONE;
376-
girq->handler = handle_simple_irq;
377-
378-
lp_gpio_irq_init_hw(lg);
380+
girq->handler = handle_bad_irq;
379381
}
380382

381383
ret = devm_gpiochip_add_data(dev, gc, lg);

‎drivers/gpio/gpio-merrifield.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ static void mrfld_irq_handler(struct irq_desc *desc)
362362
chained_irq_exit(irqchip, desc);
363363
}
364364

365-
static void mrfld_irq_init_hw(struct mrfld_gpio *priv)
365+
static int mrfld_irq_init_hw(struct gpio_chip *chip)
366366
{
367+
struct mrfld_gpio *priv = gpiochip_get_data(chip);
367368
void __iomem *reg;
368369
unsigned int base;
369370

@@ -375,6 +376,8 @@ static void mrfld_irq_init_hw(struct mrfld_gpio *priv)
375376
reg = gpio_reg(&priv->chip, base, GFER);
376377
writel(0, reg);
377378
}
379+
380+
return 0;
378381
}
379382

380383
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
447450

448451
girq = &priv->chip.irq;
449452
girq->chip = &mrfld_irqchip;
453+
girq->init_hw = mrfld_irq_init_hw;
450454
girq->parent_handler = mrfld_irq_handler;
451455
girq->num_parents = 1;
452456
girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -455,11 +459,10 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id
455459
if (!girq->parents)
456460
return -ENOMEM;
457461
girq->parents[0] = pdev->irq;
462+
girq->first = irq_base;
458463
girq->default_type = IRQ_TYPE_NONE;
459464
girq->handler = handle_bad_irq;
460465

461-
mrfld_irq_init_hw(priv);
462-
463466
pci_set_drvdata(pdev, priv);
464467
retval = devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv);
465468
if (retval) {

‎drivers/gpio/gpiolib.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
8686
struct lock_class_key *lock_key,
8787
struct lock_class_key *request_key);
8888
static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
89+
static int gpiochip_irqchip_init_hw(struct gpio_chip *gpiochip);
8990
static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip);
9091
static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip);
9192

@@ -1406,6 +1407,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
14061407

14071408
machine_gpiochip_add(chip);
14081409

1410+
ret = gpiochip_irqchip_init_hw(chip);
1411+
if (ret)
1412+
goto err_remove_acpi_chip;
1413+
14091414
ret = gpiochip_irqchip_init_valid_mask(chip);
14101415
if (ret)
14111416
goto err_remove_acpi_chip;
@@ -1622,6 +1627,16 @@ static struct gpio_chip *find_chip_by_name(const char *name)
16221627
* The following is irqchip helper code for gpiochips.
16231628
*/
16241629

1630+
static int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
1631+
{
1632+
struct gpio_irq_chip *girq = &gc->irq;
1633+
1634+
if (!girq->init_hw)
1635+
return 0;
1636+
1637+
return girq->init_hw(gc);
1638+
}
1639+
16251640
static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
16261641
{
16271642
struct gpio_irq_chip *girq = &gc->irq;
@@ -2446,8 +2461,13 @@ static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
24462461
{
24472462
return 0;
24482463
}
2449-
24502464
static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) {}
2465+
2466+
static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gpiochip)
2467+
{
2468+
return 0;
2469+
}
2470+
24512471
static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip)
24522472
{
24532473
return 0;

‎include/linux/gpio/driver.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ struct gpio_irq_chip {
201201
*/
202202
bool threaded;
203203

204+
/**
205+
* @init_hw: optional routine to initialize hardware before
206+
* an IRQ chip will be added. This is quite useful when
207+
* a particular driver wants to clear IRQ related registers
208+
* in order to avoid undesired events.
209+
*/
210+
int (*init_hw)(struct gpio_chip *chip);
211+
204212
/**
205213
* @init_valid_mask: optional routine to initialize @valid_mask, to be
206214
* used if not all GPIO lines are valid interrupts. Sometimes some

0 commit comments

Comments
 (0)