diff mbox series

[2/2] gpio: mockup: use irq_sim_fire_edge()

Message ID 20181120134032.31645-3-brgl@bgdev.pl
State New
Headers show
Series [1/2] irq/irq_sim: provide irq_sim_fire_edge() | expand

Commit Message

Bartosz Golaszewski Nov. 20, 2018, 1:40 p.m. UTC
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We now have a specialized variant of irq_sim_fire() - use it in
gpio-mockup so that we only generate events of types that were
requested with the LINEEVENT ioctl().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-mockup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Uwe Kleine-König Dec. 3, 2018, 11:09 a.m. UTC | #1
On Tue, Nov 20, 2018 at 02:40:32PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> We now have a specialized variant of irq_sim_fire() - use it in
> gpio-mockup so that we only generate events of types that were
> requested with the LINEEVENT ioctl().
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/gpio/gpio-mockup.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
> index a4c054cf9c5f..18563d2c7876 100644
> --- a/drivers/gpio/gpio-mockup.c
> +++ b/drivers/gpio/gpio-mockup.c
> @@ -199,7 +199,7 @@ static ssize_t gpio_mockup_event_write(struct file *file,
>  	struct gpio_mockup_chip *chip;
>  	struct seq_file *sfile;
>  	struct gpio_desc *desc;
> -	int rv, val;
> +	int rv, val, edge;
>  
>  	rv = kstrtoint_from_user(usr_buf, size, 0, &val);
>  	if (rv)
> @@ -213,7 +213,8 @@ static ssize_t gpio_mockup_event_write(struct file *file,
>  	chip = priv->chip;
>  
>  	gpiod_set_value_cansleep(desc, val);
> -	irq_sim_fire(&chip->irqsim, priv->offset);
> +	edge = val == 0 ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
> +	irq_sim_fire_edge(&chip->irqsim, priv->offset, edge);

If I write 0 twice into the debugfs file, does it fire two irqs or only
one? I think it fires two but only one would be the right behaviour?!

Best regards
Uwe
Uwe Kleine-König Dec. 11, 2018, 2:15 p.m. UTC | #2
Hello Bartosz,

On Mon, Dec 03, 2018 at 12:09:16PM +0100, Uwe Kleine-König wrote:
> On Tue, Nov 20, 2018 at 02:40:32PM +0100, Bartosz Golaszewski wrote:
> > @@ -213,7 +213,8 @@ static ssize_t gpio_mockup_event_write(struct file *file,
> >  	chip = priv->chip;
> >  
> >  	gpiod_set_value_cansleep(desc, val);
> > -	irq_sim_fire(&chip->irqsim, priv->offset);
> > +	edge = val == 0 ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
> > +	irq_sim_fire_edge(&chip->irqsim, priv->offset, edge);
> 
> If I write 0 twice into the debugfs file, does it fire two irqs or only
> one? I think it fires two but only one would be the right behaviour?!

If you still think that patch 1 of this series is the way to go, I think
this objection is still valid. Then you need to check the state of the
line by at least calling (something like) .get_value to determine if the
previous value was different.

Best regards
Uwe
Bartosz Golaszewski Dec. 11, 2018, 3:38 p.m. UTC | #3
wt., 11 gru 2018 o 15:15 Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> napisał(a):
>
> Hello Bartosz,
>
> On Mon, Dec 03, 2018 at 12:09:16PM +0100, Uwe Kleine-König wrote:
> > On Tue, Nov 20, 2018 at 02:40:32PM +0100, Bartosz Golaszewski wrote:
> > > @@ -213,7 +213,8 @@ static ssize_t gpio_mockup_event_write(struct file *file,
> > >     chip = priv->chip;
> > >
> > >     gpiod_set_value_cansleep(desc, val);
> > > -   irq_sim_fire(&chip->irqsim, priv->offset);
> > > +   edge = val == 0 ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
> > > +   irq_sim_fire_edge(&chip->irqsim, priv->offset, edge);
> >
> > If I write 0 twice into the debugfs file, does it fire two irqs or only
> > one? I think it fires two but only one would be the right behaviour?!
>
> If you still think that patch 1 of this series is the way to go, I think
> this objection is still valid. Then you need to check the state of the
> line by at least calling (something like) .get_value to determine if the
> previous value was different.
>

Hi Uwe,

I've already started working on a series improving the entire concept.
I've taken some of your suggestions into account.

Since we're already at rc-6 I'd like to get those upstream despite
there being some disagreements to keep the userspace intact.

For now it will generate two falling edge interrupts when you write 0 twice.

Bart
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index a4c054cf9c5f..18563d2c7876 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -199,7 +199,7 @@  static ssize_t gpio_mockup_event_write(struct file *file,
 	struct gpio_mockup_chip *chip;
 	struct seq_file *sfile;
 	struct gpio_desc *desc;
-	int rv, val;
+	int rv, val, edge;
 
 	rv = kstrtoint_from_user(usr_buf, size, 0, &val);
 	if (rv)
@@ -213,7 +213,8 @@  static ssize_t gpio_mockup_event_write(struct file *file,
 	chip = priv->chip;
 
 	gpiod_set_value_cansleep(desc, val);
-	irq_sim_fire(&chip->irqsim, priv->offset);
+	edge = val == 0 ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
+	irq_sim_fire_edge(&chip->irqsim, priv->offset, edge);
 
 	return size;
 }