Skip to content

Commit 7b92509

Browse files
author
Bartosz Golaszewski
committed
gpio: sysfs: emit chardev line-state events on edge store
In order to emit line-state events on edge changes in sysfs, update the EDGE flags in the descriptor in gpio_sysfs_request_irq() and emit the event on a successful store. Reviewed-by: Kent Gibson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 5a7119e commit 7b92509

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/gpio/gpiolib-sysfs.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ static int gpio_sysfs_request_irq(struct device *dev, unsigned char flags)
179179
return -ENODEV;
180180

181181
irq_flags = IRQF_SHARED;
182-
if (flags & GPIO_IRQF_TRIGGER_FALLING)
182+
if (flags & GPIO_IRQF_TRIGGER_FALLING) {
183183
irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
184184
IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
185-
if (flags & GPIO_IRQF_TRIGGER_RISING)
185+
set_bit(FLAG_EDGE_FALLING, &desc->flags);
186+
}
187+
if (flags & GPIO_IRQF_TRIGGER_RISING) {
186188
irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
187189
IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
190+
set_bit(FLAG_EDGE_RISING, &desc->flags);
191+
}
188192

189193
/*
190194
* FIXME: This should be done in the irq_request_resources callback
@@ -210,6 +214,8 @@ static int gpio_sysfs_request_irq(struct device *dev, unsigned char flags)
210214
err_unlock:
211215
gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc));
212216
err_put_kn:
217+
clear_bit(FLAG_EDGE_RISING, &desc->flags);
218+
clear_bit(FLAG_EDGE_FALLING, &desc->flags);
213219
sysfs_put(data->value_kn);
214220

215221
return ret;
@@ -231,6 +237,8 @@ static void gpio_sysfs_free_irq(struct device *dev)
231237
data->irq_flags = 0;
232238
free_irq(data->irq, data);
233239
gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc));
240+
clear_bit(FLAG_EDGE_RISING, &desc->flags);
241+
clear_bit(FLAG_EDGE_FALLING, &desc->flags);
234242
sysfs_put(data->value_kn);
235243
}
236244

@@ -282,6 +290,8 @@ static ssize_t edge_store(struct device *dev,
282290
if (status)
283291
return status;
284292

293+
gpiod_line_state_notify(data->desc, GPIO_V2_LINE_CHANGED_CONFIG);
294+
285295
return size;
286296
}
287297
static DEVICE_ATTR_RW(edge);

0 commit comments

Comments
 (0)