Skip to content

Commit b4c495f

Browse files
brgllinusw
authored andcommitted
gpio: mockup: use irq_sim
Shrink the driver by removing the code dealing with dummy interrupts and replacing it with calls to the irq_sim API. Signed-off-by: Bartosz Golaszewski <[email protected]> Acked-by: Jonathan Cameron <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 4342ec5 commit b4c495f

File tree

2 files changed

+8
-71
lines changed

2 files changed

+8
-71
lines changed

drivers/gpio/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ config GPIO_MOCKUP
311311
depends on GPIOLIB && SYSFS
312312
select GPIO_SYSFS
313313
select GPIOLIB_IRQCHIP
314-
select IRQ_WORK
314+
select IRQ_SIM
315315
help
316316
This enables GPIO Testing driver, which provides a way to test GPIO
317317
subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS

drivers/gpio/gpio-mockup.c

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <linux/slab.h>
2121
#include <linux/interrupt.h>
2222
#include <linux/irq.h>
23-
#include <linux/irq_work.h>
23+
#include <linux/irq_sim.h>
2424
#include <linux/debugfs.h>
2525
#include <linux/uaccess.h>
2626

@@ -47,18 +47,12 @@ enum {
4747
struct gpio_mockup_line_status {
4848
int dir;
4949
bool value;
50-
bool irq_enabled;
51-
};
52-
53-
struct gpio_mockup_irq_context {
54-
struct irq_work work;
55-
int irq;
5650
};
5751

5852
struct gpio_mockup_chip {
5953
struct gpio_chip gc;
6054
struct gpio_mockup_line_status *lines;
61-
struct gpio_mockup_irq_context irq_ctx;
55+
struct irq_sim irqsim;
6256
struct dentry *dbg_dir;
6357
};
6458

@@ -144,65 +138,11 @@ static int gpio_mockup_name_lines(struct device *dev,
144138
return 0;
145139
}
146140

147-
static int gpio_mockup_to_irq(struct gpio_chip *chip, unsigned int offset)
148-
{
149-
return chip->irq_base + offset;
150-
}
151-
152-
static void gpio_mockup_irqmask(struct irq_data *data)
141+
static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset)
153142
{
154-
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
155143
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
156144

157-
chip->lines[data->irq - gc->irq_base].irq_enabled = false;
158-
}
159-
160-
static void gpio_mockup_irqunmask(struct irq_data *data)
161-
{
162-
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
163-
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
164-
165-
chip->lines[data->irq - gc->irq_base].irq_enabled = true;
166-
}
167-
168-
static struct irq_chip gpio_mockup_irqchip = {
169-
.name = GPIO_MOCKUP_NAME,
170-
.irq_mask = gpio_mockup_irqmask,
171-
.irq_unmask = gpio_mockup_irqunmask,
172-
};
173-
174-
static void gpio_mockup_handle_irq(struct irq_work *work)
175-
{
176-
struct gpio_mockup_irq_context *irq_ctx;
177-
178-
irq_ctx = container_of(work, struct gpio_mockup_irq_context, work);
179-
handle_simple_irq(irq_to_desc(irq_ctx->irq));
180-
}
181-
182-
static int gpio_mockup_irqchip_setup(struct device *dev,
183-
struct gpio_mockup_chip *chip)
184-
{
185-
struct gpio_chip *gc = &chip->gc;
186-
int irq_base, i;
187-
188-
irq_base = devm_irq_alloc_descs(dev, -1, 0, gc->ngpio, 0);
189-
if (irq_base < 0)
190-
return irq_base;
191-
192-
gc->irq_base = irq_base;
193-
gc->irqchip = &gpio_mockup_irqchip;
194-
195-
for (i = 0; i < gc->ngpio; i++) {
196-
irq_set_chip(irq_base + i, gc->irqchip);
197-
irq_set_chip_data(irq_base + i, gc);
198-
irq_set_handler(irq_base + i, &handle_simple_irq);
199-
irq_modify_status(irq_base + i,
200-
IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE);
201-
}
202-
203-
init_irq_work(&chip->irq_ctx.work, gpio_mockup_handle_irq);
204-
205-
return 0;
145+
return irq_sim_irqnum(&chip->irqsim, offset);
206146
}
207147

208148
static ssize_t gpio_mockup_event_write(struct file *file,
@@ -228,11 +168,8 @@ static ssize_t gpio_mockup_event_write(struct file *file,
228168
chip = priv->chip;
229169
gc = &chip->gc;
230170

231-
if (chip->lines[priv->offset].irq_enabled) {
232-
gpiod_set_value_cansleep(desc, val);
233-
priv->chip->irq_ctx.irq = gc->irq_base + priv->offset;
234-
irq_work_queue(&priv->chip->irq_ctx.work);
235-
}
171+
gpiod_set_value_cansleep(desc, val);
172+
irq_sim_fire(&chip->irqsim, priv->offset);
236173

237174
return size;
238175
}
@@ -319,7 +256,7 @@ static int gpio_mockup_add(struct device *dev,
319256
return ret;
320257
}
321258

322-
ret = gpio_mockup_irqchip_setup(dev, chip);
259+
ret = devm_irq_sim_init(dev, &chip->irqsim, gc->ngpio);
323260
if (ret)
324261
return ret;
325262

0 commit comments

Comments
 (0)