Skip to content

Commit d1bfdf8

Browse files
raagjadavandy-shev
authored andcommitted
pinctrl: intel: refine ->irq_set_type() hook
Refine ->irq_set_type() hook and improve its readability by: - Reducing scope of spinlock by moving unneeded operations out of it. - Dropping redundant PADCFG0_RXEVCFG_SHIFT and including it directly into PADCFG0_RXEVCFG_* definitions. - Utilizing temporary variables for common operations. - Simplifying if-else-if chain. Signed-off-by: Raag Jadav <raag.jadav@intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent e95433c commit d1bfdf8

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

drivers/pinctrl/intel/pinctrl-intel.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@
5555

5656
/* Offset from pad_regs */
5757
#define PADCFG0 0x000
58-
#define PADCFG0_RXEVCFG_SHIFT 25
5958
#define PADCFG0_RXEVCFG_MASK GENMASK(26, 25)
60-
#define PADCFG0_RXEVCFG_LEVEL 0
61-
#define PADCFG0_RXEVCFG_EDGE 1
62-
#define PADCFG0_RXEVCFG_DISABLED 2
63-
#define PADCFG0_RXEVCFG_EDGE_BOTH 3
59+
#define PADCFG0_RXEVCFG_LEVEL (0 << 25)
60+
#define PADCFG0_RXEVCFG_EDGE (1 << 25)
61+
#define PADCFG0_RXEVCFG_DISABLED (2 << 25)
62+
#define PADCFG0_RXEVCFG_EDGE_BOTH (3 << 25)
6463
#define PADCFG0_PREGFRXSEL BIT(24)
6564
#define PADCFG0_RXINV BIT(23)
6665
#define PADCFG0_GPIROUTIOXAPIC BIT(20)
@@ -1127,9 +1126,9 @@ static int intel_gpio_irq_type(struct irq_data *d, unsigned int type)
11271126
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
11281127
struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
11291128
unsigned int pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), NULL, NULL);
1129+
u32 rxevcfg, rxinv, value;
11301130
unsigned long flags;
11311131
void __iomem *reg;
1132-
u32 value;
11331132

11341133
reg = intel_get_padcfg(pctrl, pin, PADCFG0);
11351134
if (!reg)
@@ -1145,28 +1144,32 @@ static int intel_gpio_irq_type(struct irq_data *d, unsigned int type)
11451144
return -EPERM;
11461145
}
11471146

1148-
raw_spin_lock_irqsave(&pctrl->lock, flags);
1149-
1150-
intel_gpio_set_gpio_mode(reg);
1151-
1152-
value = readl(reg);
1153-
1154-
value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV);
1155-
11561147
if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) {
1157-
value |= PADCFG0_RXEVCFG_EDGE_BOTH << PADCFG0_RXEVCFG_SHIFT;
1148+
rxevcfg = PADCFG0_RXEVCFG_EDGE_BOTH;
11581149
} else if (type & IRQ_TYPE_EDGE_FALLING) {
1159-
value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT;
1160-
value |= PADCFG0_RXINV;
1150+
rxevcfg = PADCFG0_RXEVCFG_EDGE;
11611151
} else if (type & IRQ_TYPE_EDGE_RISING) {
1162-
value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT;
1152+
rxevcfg = PADCFG0_RXEVCFG_EDGE;
11631153
} else if (type & IRQ_TYPE_LEVEL_MASK) {
1164-
if (type & IRQ_TYPE_LEVEL_LOW)
1165-
value |= PADCFG0_RXINV;
1154+
rxevcfg = PADCFG0_RXEVCFG_LEVEL;
11661155
} else {
1167-
value |= PADCFG0_RXEVCFG_DISABLED << PADCFG0_RXEVCFG_SHIFT;
1156+
rxevcfg = PADCFG0_RXEVCFG_DISABLED;
11681157
}
11691158

1159+
if (type == IRQ_TYPE_EDGE_FALLING || type == IRQ_TYPE_LEVEL_LOW)
1160+
rxinv = PADCFG0_RXINV;
1161+
else
1162+
rxinv = 0;
1163+
1164+
raw_spin_lock_irqsave(&pctrl->lock, flags);
1165+
1166+
intel_gpio_set_gpio_mode(reg);
1167+
1168+
value = readl(reg);
1169+
1170+
value = (value & ~PADCFG0_RXEVCFG_MASK) | rxevcfg;
1171+
value = (value & ~PADCFG0_RXINV) | rxinv;
1172+
11701173
writel(value, reg);
11711174

11721175
if (type & IRQ_TYPE_EDGE_BOTH)

0 commit comments

Comments
 (0)