Skip to content

Commit 2a485c8

Browse files
tq-schiffermBartosz Golaszewski
authored andcommitted
gpio: tqmx86: add macros for interrupt configuration
Consistently use TQMX86_INT_* flags for irq_type values. The TQMX86_GPII_CONFIG macro is used to convert from TQMX86_INT_TRIG_* flags to GPII register values. Bit patterns for TQMX86_INT_* are chosen to make this conversion as simple as possible. No functional change intended. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Link: https://lore.kernel.org/r/26c01bce589aedb794c19ea7ccd85f6143532e48.1734001247.git.matthias.schiffer@ew.tq-group.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 934bacb commit 2a485c8

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

drivers/gpio/gpio-tqmx86.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@
2929
#define TQMX86_GPIIC 3 /* GPI Interrupt Configuration Register */
3030
#define TQMX86_GPIIS 4 /* GPI Interrupt Status Register */
3131

32-
#define TQMX86_GPII_NONE 0
33-
#define TQMX86_GPII_FALLING BIT(0)
34-
#define TQMX86_GPII_RISING BIT(1)
35-
/* Stored in irq_type as a trigger type, but not actually valid as a register
36-
* value, so the name doesn't use "GPII"
32+
/*
33+
* NONE, FALLING and RISING use the same bit patterns that can be programmed to
34+
* the GPII register (after passing them to the TQMX86_GPII_ macros to shift
35+
* them to the right position)
3736
*/
38-
#define TQMX86_INT_BOTH (BIT(0) | BIT(1))
39-
#define TQMX86_GPII_MASK (BIT(0) | BIT(1))
40-
#define TQMX86_GPII_BITS 2
37+
#define TQMX86_INT_TRIG_NONE 0
38+
#define TQMX86_INT_TRIG_FALLING BIT(0)
39+
#define TQMX86_INT_TRIG_RISING BIT(1)
40+
#define TQMX86_INT_TRIG_BOTH (BIT(0) | BIT(1))
41+
#define TQMX86_INT_TRIG_MASK (BIT(0) | BIT(1))
4142
/* Stored in irq_type with GPII bits */
4243
#define TQMX86_INT_UNMASKED BIT(2)
4344

45+
#define TQMX86_GPIIC_CONFIG(i, v) ((v) << (2 * (i)))
46+
#define TQMX86_GPIIC_MASK(i) TQMX86_GPIIC_CONFIG(i, TQMX86_INT_TRIG_MASK)
47+
4448
struct tqmx86_gpio_data {
4549
struct gpio_chip chip;
4650
void __iomem *io_base;
@@ -115,20 +119,20 @@ static int tqmx86_gpio_get_direction(struct gpio_chip *chip,
115119
static void tqmx86_gpio_irq_config(struct tqmx86_gpio_data *gpio, int offset)
116120
__must_hold(&gpio->spinlock)
117121
{
118-
u8 type = TQMX86_GPII_NONE, gpiic;
122+
u8 type = TQMX86_INT_TRIG_NONE, gpiic;
119123

120124
if (gpio->irq_type[offset] & TQMX86_INT_UNMASKED) {
121-
type = gpio->irq_type[offset] & TQMX86_GPII_MASK;
125+
type = gpio->irq_type[offset] & TQMX86_INT_TRIG_MASK;
122126

123-
if (type == TQMX86_INT_BOTH)
127+
if (type == TQMX86_INT_TRIG_BOTH)
124128
type = tqmx86_gpio_get(&gpio->chip, offset + TQMX86_NGPO)
125-
? TQMX86_GPII_FALLING
126-
: TQMX86_GPII_RISING;
129+
? TQMX86_INT_TRIG_FALLING
130+
: TQMX86_INT_TRIG_RISING;
127131
}
128132

129133
gpiic = tqmx86_gpio_read(gpio, TQMX86_GPIIC);
130-
gpiic &= ~(TQMX86_GPII_MASK << (offset * TQMX86_GPII_BITS));
131-
gpiic |= type << (offset * TQMX86_GPII_BITS);
134+
gpiic &= ~TQMX86_GPIIC_MASK(offset);
135+
gpiic |= TQMX86_GPIIC_CONFIG(offset, type);
132136
tqmx86_gpio_write(gpio, gpiic, TQMX86_GPIIC);
133137
}
134138

@@ -173,20 +177,20 @@ static int tqmx86_gpio_irq_set_type(struct irq_data *data, unsigned int type)
173177

174178
switch (edge_type) {
175179
case IRQ_TYPE_EDGE_RISING:
176-
new_type = TQMX86_GPII_RISING;
180+
new_type = TQMX86_INT_TRIG_RISING;
177181
break;
178182
case IRQ_TYPE_EDGE_FALLING:
179-
new_type = TQMX86_GPII_FALLING;
183+
new_type = TQMX86_INT_TRIG_FALLING;
180184
break;
181185
case IRQ_TYPE_EDGE_BOTH:
182-
new_type = TQMX86_INT_BOTH;
186+
new_type = TQMX86_INT_TRIG_BOTH;
183187
break;
184188
default:
185189
return -EINVAL; /* not supported */
186190
}
187191

188192
raw_spin_lock_irqsave(&gpio->spinlock, flags);
189-
gpio->irq_type[offset] &= ~TQMX86_GPII_MASK;
193+
gpio->irq_type[offset] &= ~TQMX86_INT_TRIG_MASK;
190194
gpio->irq_type[offset] |= new_type;
191195
tqmx86_gpio_irq_config(gpio, offset);
192196
raw_spin_unlock_irqrestore(&gpio->spinlock, flags);
@@ -232,7 +236,7 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
232236
* reading the input and setting the trigger, we will have a new
233237
* interrupt pending.
234238
*/
235-
if ((gpio->irq_type[i] & TQMX86_GPII_MASK) == TQMX86_INT_BOTH)
239+
if ((gpio->irq_type[i] & TQMX86_INT_TRIG_MASK) == TQMX86_INT_TRIG_BOTH)
236240
tqmx86_gpio_irq_config(gpio, i);
237241
}
238242
raw_spin_unlock_irqrestore(&gpio->spinlock, flags);

0 commit comments

Comments
 (0)