Skip to content

Commit 4763c08

Browse files
committed
Merge tag 'pinctrl-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl
Pull pin control fixes from Linus Walleij: - Fix glitch risks in the Intel GPIO - Fix the Intel Cherryview valid irq mask calculation. - Allocate the Intel Cherryview irqchip dynamically. - Fix the valid mask init sequency on the ST STMFX driver. * tag 'pinctrl-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl: pinctrl: stmfx: fix valid_mask init sequence pinctrl: cherryview: Allocate IRQ chip dynamic pinctrl: cherryview: Fix irq_valid_mask calculation pinctrl: intel: Avoid potential glitches if pin is in GPIO mode
2 parents 00aff68 + 63e006c commit 4763c08

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

drivers/pinctrl/intel/pinctrl-cherryview.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ struct chv_pin_context {
147147
* @pctldesc: Pin controller description
148148
* @pctldev: Pointer to the pin controller device
149149
* @chip: GPIO chip in this pin controller
150+
* @irqchip: IRQ chip in this pin controller
150151
* @regs: MMIO registers
151152
* @intr_lines: Stores mapping between 16 HW interrupt wires and GPIO
152153
* offset (in GPIO number space)
@@ -162,6 +163,7 @@ struct chv_pinctrl {
162163
struct pinctrl_desc pctldesc;
163164
struct pinctrl_dev *pctldev;
164165
struct gpio_chip chip;
166+
struct irq_chip irqchip;
165167
void __iomem *regs;
166168
unsigned intr_lines[16];
167169
const struct chv_community *community;
@@ -1466,16 +1468,6 @@ static int chv_gpio_irq_type(struct irq_data *d, unsigned int type)
14661468
return 0;
14671469
}
14681470

1469-
static struct irq_chip chv_gpio_irqchip = {
1470-
.name = "chv-gpio",
1471-
.irq_startup = chv_gpio_irq_startup,
1472-
.irq_ack = chv_gpio_irq_ack,
1473-
.irq_mask = chv_gpio_irq_mask,
1474-
.irq_unmask = chv_gpio_irq_unmask,
1475-
.irq_set_type = chv_gpio_irq_type,
1476-
.flags = IRQCHIP_SKIP_SET_WAKE,
1477-
};
1478-
14791471
static void chv_gpio_irq_handler(struct irq_desc *desc)
14801472
{
14811473
struct gpio_chip *gc = irq_desc_get_handler_data(desc);
@@ -1559,7 +1551,7 @@ static void chv_init_irq_valid_mask(struct gpio_chip *chip,
15591551
intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
15601552

15611553
if (intsel >= community->nirqs)
1562-
clear_bit(i, valid_mask);
1554+
clear_bit(desc->number, valid_mask);
15631555
}
15641556
}
15651557

@@ -1625,7 +1617,15 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq)
16251617
}
16261618
}
16271619

1628-
ret = gpiochip_irqchip_add(chip, &chv_gpio_irqchip, 0,
1620+
pctrl->irqchip.name = "chv-gpio";
1621+
pctrl->irqchip.irq_startup = chv_gpio_irq_startup;
1622+
pctrl->irqchip.irq_ack = chv_gpio_irq_ack;
1623+
pctrl->irqchip.irq_mask = chv_gpio_irq_mask;
1624+
pctrl->irqchip.irq_unmask = chv_gpio_irq_unmask;
1625+
pctrl->irqchip.irq_set_type = chv_gpio_irq_type;
1626+
pctrl->irqchip.flags = IRQCHIP_SKIP_SET_WAKE;
1627+
1628+
ret = gpiochip_irqchip_add(chip, &pctrl->irqchip, 0,
16291629
handle_bad_irq, IRQ_TYPE_NONE);
16301630
if (ret) {
16311631
dev_err(pctrl->dev, "failed to add IRQ chip\n");
@@ -1642,7 +1642,7 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq)
16421642
}
16431643
}
16441644

1645-
gpiochip_set_chained_irqchip(chip, &chv_gpio_irqchip, irq,
1645+
gpiochip_set_chained_irqchip(chip, &pctrl->irqchip, irq,
16461646
chv_gpio_irq_handler);
16471647
return 0;
16481648
}

drivers/pinctrl/intel/pinctrl-intel.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#define PADCFG0_GPIROUTNMI BIT(17)
5353
#define PADCFG0_PMODE_SHIFT 10
5454
#define PADCFG0_PMODE_MASK GENMASK(13, 10)
55+
#define PADCFG0_PMODE_GPIO 0
5556
#define PADCFG0_GPIORXDIS BIT(9)
5657
#define PADCFG0_GPIOTXDIS BIT(8)
5758
#define PADCFG0_GPIORXSTATE BIT(1)
@@ -332,7 +333,7 @@ static void intel_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
332333
cfg1 = readl(intel_get_padcfg(pctrl, pin, PADCFG1));
333334

334335
mode = (cfg0 & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT;
335-
if (!mode)
336+
if (mode == PADCFG0_PMODE_GPIO)
336337
seq_puts(s, "GPIO ");
337338
else
338339
seq_printf(s, "mode %d ", mode);
@@ -458,6 +459,11 @@ static void __intel_gpio_set_direction(void __iomem *padcfg0, bool input)
458459
writel(value, padcfg0);
459460
}
460461

462+
static int intel_gpio_get_gpio_mode(void __iomem *padcfg0)
463+
{
464+
return (readl(padcfg0) & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT;
465+
}
466+
461467
static void intel_gpio_set_gpio_mode(void __iomem *padcfg0)
462468
{
463469
u32 value;
@@ -491,7 +497,20 @@ static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
491497
}
492498

493499
padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
500+
501+
/*
502+
* If pin is already configured in GPIO mode, we assume that
503+
* firmware provides correct settings. In such case we avoid
504+
* potential glitches on the pin. Otherwise, for the pin in
505+
* alternative mode, consumer has to supply respective flags.
506+
*/
507+
if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO) {
508+
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
509+
return 0;
510+
}
511+
494512
intel_gpio_set_gpio_mode(padcfg0);
513+
495514
/* Disable TX buffer and enable RX (this will be input) */
496515
__intel_gpio_set_direction(padcfg0, true);
497516

drivers/pinctrl/pinctrl-stmfx.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -585,19 +585,6 @@ static int stmfx_pinctrl_gpio_function_enable(struct stmfx_pinctrl *pctl)
585585
return stmfx_function_enable(pctl->stmfx, func);
586586
}
587587

588-
static int stmfx_pinctrl_gpio_init_valid_mask(struct gpio_chip *gc,
589-
unsigned long *valid_mask,
590-
unsigned int ngpios)
591-
{
592-
struct stmfx_pinctrl *pctl = gpiochip_get_data(gc);
593-
u32 n;
594-
595-
for_each_clear_bit(n, &pctl->gpio_valid_mask, ngpios)
596-
clear_bit(n, valid_mask);
597-
598-
return 0;
599-
}
600-
601588
static int stmfx_pinctrl_probe(struct platform_device *pdev)
602589
{
603590
struct stmfx *stmfx = dev_get_drvdata(pdev->dev.parent);
@@ -660,7 +647,6 @@ static int stmfx_pinctrl_probe(struct platform_device *pdev)
660647
pctl->gpio_chip.ngpio = pctl->pctl_desc.npins;
661648
pctl->gpio_chip.can_sleep = true;
662649
pctl->gpio_chip.of_node = np;
663-
pctl->gpio_chip.init_valid_mask = stmfx_pinctrl_gpio_init_valid_mask;
664650

665651
ret = devm_gpiochip_add_data(pctl->dev, &pctl->gpio_chip, pctl);
666652
if (ret) {

0 commit comments

Comments
 (0)