|
29 | 29 | #define TQMX86_GPIIC 3 /* GPI Interrupt Configuration Register */
|
30 | 30 | #define TQMX86_GPIIS 4 /* GPI Interrupt Status Register */
|
31 | 31 |
|
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) |
37 | 36 | */
|
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)) |
41 | 42 | /* Stored in irq_type with GPII bits */
|
42 | 43 | #define TQMX86_INT_UNMASKED BIT(2)
|
43 | 44 |
|
| 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 | + |
44 | 48 | struct tqmx86_gpio_data {
|
45 | 49 | struct gpio_chip chip;
|
46 | 50 | void __iomem *io_base;
|
@@ -115,20 +119,20 @@ static int tqmx86_gpio_get_direction(struct gpio_chip *chip,
|
115 | 119 | static void tqmx86_gpio_irq_config(struct tqmx86_gpio_data *gpio, int offset)
|
116 | 120 | __must_hold(&gpio->spinlock)
|
117 | 121 | {
|
118 |
| - u8 type = TQMX86_GPII_NONE, gpiic; |
| 122 | + u8 type = TQMX86_INT_TRIG_NONE, gpiic; |
119 | 123 |
|
120 | 124 | 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; |
122 | 126 |
|
123 |
| - if (type == TQMX86_INT_BOTH) |
| 127 | + if (type == TQMX86_INT_TRIG_BOTH) |
124 | 128 | 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; |
127 | 131 | }
|
128 | 132 |
|
129 | 133 | 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); |
132 | 136 | tqmx86_gpio_write(gpio, gpiic, TQMX86_GPIIC);
|
133 | 137 | }
|
134 | 138 |
|
@@ -173,20 +177,20 @@ static int tqmx86_gpio_irq_set_type(struct irq_data *data, unsigned int type)
|
173 | 177 |
|
174 | 178 | switch (edge_type) {
|
175 | 179 | case IRQ_TYPE_EDGE_RISING:
|
176 |
| - new_type = TQMX86_GPII_RISING; |
| 180 | + new_type = TQMX86_INT_TRIG_RISING; |
177 | 181 | break;
|
178 | 182 | case IRQ_TYPE_EDGE_FALLING:
|
179 |
| - new_type = TQMX86_GPII_FALLING; |
| 183 | + new_type = TQMX86_INT_TRIG_FALLING; |
180 | 184 | break;
|
181 | 185 | case IRQ_TYPE_EDGE_BOTH:
|
182 |
| - new_type = TQMX86_INT_BOTH; |
| 186 | + new_type = TQMX86_INT_TRIG_BOTH; |
183 | 187 | break;
|
184 | 188 | default:
|
185 | 189 | return -EINVAL; /* not supported */
|
186 | 190 | }
|
187 | 191 |
|
188 | 192 | raw_spin_lock_irqsave(&gpio->spinlock, flags);
|
189 |
| - gpio->irq_type[offset] &= ~TQMX86_GPII_MASK; |
| 193 | + gpio->irq_type[offset] &= ~TQMX86_INT_TRIG_MASK; |
190 | 194 | gpio->irq_type[offset] |= new_type;
|
191 | 195 | tqmx86_gpio_irq_config(gpio, offset);
|
192 | 196 | raw_spin_unlock_irqrestore(&gpio->spinlock, flags);
|
@@ -232,7 +236,7 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
|
232 | 236 | * reading the input and setting the trigger, we will have a new
|
233 | 237 | * interrupt pending.
|
234 | 238 | */
|
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) |
236 | 240 | tqmx86_gpio_irq_config(gpio, i);
|
237 | 241 | }
|
238 | 242 | raw_spin_unlock_irqrestore(&gpio->spinlock, flags);
|
|
0 commit comments