Skip to content

Commit 0ccf314

Browse files
tq-schiffermBartosz Golaszewski
authored andcommitted
gpio: tqmx86: consistently refer to IRQs by hwirq numbers
On currently supported variants of the TQMx86 GPIO controller, only GPIOs 4-7 have IRQ support; in the interrupt status and config registers, position 0 therefore corresponds to GPIO 4, position 1 to GPIO 5, etc. This was made even more confusing by sometimes using the term "offset" to refer to GPIO numbers (which are equavalent to hwirq numbers), and sometimes to bit positions in the hardware registers. With this change, the whole driver consistently uses hwirq numbers (== GPIO numbers) when referring to the IRQs, and only the two pieces of code that interact with the hardware registers (tqmx86_gpio_irq_config() and tqmx86_gpio_irq_handler()) deal with bit positions. Space for hwirq numbers 0-3 is reserved in the irq_type array, but remains unused for existing (COM Express) TQMx86 variants; support for TQMx86 variants that support IRQs on all GPIO lines will be added in the future. No functional change intended. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Link: https://lore.kernel.org/r/94b78f4a9500bb71e66c0f7d3b084fec5cfe42ca.1734001247.git.matthias.schiffer@ew.tq-group.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 2a485c8 commit 0ccf314

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

drivers/gpio/gpio-tqmx86.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct tqmx86_gpio_data {
5252
/* Lock must be held for accessing output and irq_type fields */
5353
raw_spinlock_t spinlock;
5454
DECLARE_BITMAP(output, TQMX86_NGPIO);
55-
u8 irq_type[TQMX86_NGPI];
55+
u8 irq_type[TQMX86_NGPIO];
5656
};
5757

5858
static u8 tqmx86_gpio_read(struct tqmx86_gpio_data *gd, unsigned int reg)
@@ -116,61 +116,59 @@ static int tqmx86_gpio_get_direction(struct gpio_chip *chip,
116116
return GPIO_LINE_DIRECTION_OUT;
117117
}
118118

119-
static void tqmx86_gpio_irq_config(struct tqmx86_gpio_data *gpio, int offset)
119+
static void tqmx86_gpio_irq_config(struct tqmx86_gpio_data *gpio, int hwirq)
120120
__must_hold(&gpio->spinlock)
121121
{
122122
u8 type = TQMX86_INT_TRIG_NONE, gpiic;
123+
int gpiic_irq = hwirq - TQMX86_NGPO;
123124

124-
if (gpio->irq_type[offset] & TQMX86_INT_UNMASKED) {
125-
type = gpio->irq_type[offset] & TQMX86_INT_TRIG_MASK;
125+
if (gpio->irq_type[hwirq] & TQMX86_INT_UNMASKED) {
126+
type = gpio->irq_type[hwirq] & TQMX86_INT_TRIG_MASK;
126127

127128
if (type == TQMX86_INT_TRIG_BOTH)
128-
type = tqmx86_gpio_get(&gpio->chip, offset + TQMX86_NGPO)
129+
type = tqmx86_gpio_get(&gpio->chip, hwirq)
129130
? TQMX86_INT_TRIG_FALLING
130131
: TQMX86_INT_TRIG_RISING;
131132
}
132133

133134
gpiic = tqmx86_gpio_read(gpio, TQMX86_GPIIC);
134-
gpiic &= ~TQMX86_GPIIC_MASK(offset);
135-
gpiic |= TQMX86_GPIIC_CONFIG(offset, type);
135+
gpiic &= ~TQMX86_GPIIC_MASK(gpiic_irq);
136+
gpiic |= TQMX86_GPIIC_CONFIG(gpiic_irq, type);
136137
tqmx86_gpio_write(gpio, gpiic, TQMX86_GPIIC);
137138
}
138139

139140
static void tqmx86_gpio_irq_mask(struct irq_data *data)
140141
{
141-
unsigned int offset = (data->hwirq - TQMX86_NGPO);
142142
struct tqmx86_gpio_data *gpio = gpiochip_get_data(
143143
irq_data_get_irq_chip_data(data));
144144
unsigned long flags;
145145

146146
raw_spin_lock_irqsave(&gpio->spinlock, flags);
147-
gpio->irq_type[offset] &= ~TQMX86_INT_UNMASKED;
148-
tqmx86_gpio_irq_config(gpio, offset);
147+
gpio->irq_type[data->hwirq] &= ~TQMX86_INT_UNMASKED;
148+
tqmx86_gpio_irq_config(gpio, data->hwirq);
149149
raw_spin_unlock_irqrestore(&gpio->spinlock, flags);
150150

151151
gpiochip_disable_irq(&gpio->chip, irqd_to_hwirq(data));
152152
}
153153

154154
static void tqmx86_gpio_irq_unmask(struct irq_data *data)
155155
{
156-
unsigned int offset = (data->hwirq - TQMX86_NGPO);
157156
struct tqmx86_gpio_data *gpio = gpiochip_get_data(
158157
irq_data_get_irq_chip_data(data));
159158
unsigned long flags;
160159

161160
gpiochip_enable_irq(&gpio->chip, irqd_to_hwirq(data));
162161

163162
raw_spin_lock_irqsave(&gpio->spinlock, flags);
164-
gpio->irq_type[offset] |= TQMX86_INT_UNMASKED;
165-
tqmx86_gpio_irq_config(gpio, offset);
163+
gpio->irq_type[data->hwirq] |= TQMX86_INT_UNMASKED;
164+
tqmx86_gpio_irq_config(gpio, data->hwirq);
166165
raw_spin_unlock_irqrestore(&gpio->spinlock, flags);
167166
}
168167

169168
static int tqmx86_gpio_irq_set_type(struct irq_data *data, unsigned int type)
170169
{
171170
struct tqmx86_gpio_data *gpio = gpiochip_get_data(
172171
irq_data_get_irq_chip_data(data));
173-
unsigned int offset = (data->hwirq - TQMX86_NGPO);
174172
unsigned int edge_type = type & IRQF_TRIGGER_MASK;
175173
unsigned long flags;
176174
u8 new_type;
@@ -190,9 +188,9 @@ static int tqmx86_gpio_irq_set_type(struct irq_data *data, unsigned int type)
190188
}
191189

192190
raw_spin_lock_irqsave(&gpio->spinlock, flags);
193-
gpio->irq_type[offset] &= ~TQMX86_INT_TRIG_MASK;
194-
gpio->irq_type[offset] |= new_type;
195-
tqmx86_gpio_irq_config(gpio, offset);
191+
gpio->irq_type[data->hwirq] &= ~TQMX86_INT_TRIG_MASK;
192+
gpio->irq_type[data->hwirq] |= new_type;
193+
tqmx86_gpio_irq_config(gpio, data->hwirq);
196194
raw_spin_unlock_irqrestore(&gpio->spinlock, flags);
197195

198196
return 0;
@@ -204,7 +202,7 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
204202
struct tqmx86_gpio_data *gpio = gpiochip_get_data(chip);
205203
struct irq_chip *irq_chip = irq_desc_get_chip(desc);
206204
unsigned long irq_bits, flags;
207-
int i;
205+
int i, hwirq;
208206
u8 irq_status;
209207

210208
chained_irq_enter(irq_chip, desc);
@@ -216,6 +214,8 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
216214

217215
raw_spin_lock_irqsave(&gpio->spinlock, flags);
218216
for_each_set_bit(i, &irq_bits, TQMX86_NGPI) {
217+
hwirq = i + TQMX86_NGPO;
218+
219219
/*
220220
* Edge-both triggers are implemented by flipping the edge
221221
* trigger after each interrupt, as the controller only supports
@@ -236,8 +236,8 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
236236
* reading the input and setting the trigger, we will have a new
237237
* interrupt pending.
238238
*/
239-
if ((gpio->irq_type[i] & TQMX86_INT_TRIG_MASK) == TQMX86_INT_TRIG_BOTH)
240-
tqmx86_gpio_irq_config(gpio, i);
239+
if ((gpio->irq_type[hwirq] & TQMX86_INT_TRIG_MASK) == TQMX86_INT_TRIG_BOTH)
240+
tqmx86_gpio_irq_config(gpio, hwirq);
241241
}
242242
raw_spin_unlock_irqrestore(&gpio->spinlock, flags);
243243

0 commit comments

Comments
 (0)