From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH 2/2] gpio: sim: lock GPIOs as interrupts when they are requested
Date: Wed, 12 Jun 2024 13:52:26 +0200 [thread overview]
Message-ID: <20240612115231.26703-3-brgl@bgdev.pl> (raw)
In-Reply-To: <20240612115231.26703-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Use the notifier exposed by the interrupt simulator to be notified about
interrupts associated with simulated GPIO pins being requested or
released and lock/unlock them as interrupts accordingly.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-sim.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 2ed5cbe7c8a8..b5526f09b22b 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -53,6 +53,7 @@ struct gpio_sim_chip {
struct irq_domain *irq_sim;
struct mutex lock;
const struct attribute_group **attr_groups;
+ struct notifier_block nb;
};
struct gpio_sim_attribute {
@@ -227,6 +228,24 @@ static void gpio_sim_free(struct gpio_chip *gc, unsigned int offset)
}
}
+static int gpio_sim_irq_domain_notify(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct gpio_sim_chip *chip = container_of(nb, struct gpio_sim_chip, nb);
+ irq_hw_number_t *offset = data;
+
+ switch (action) {
+ case IRQ_SIM_DOMAIN_IRQ_REQUESTED:
+ gpiochip_lock_as_irq(&chip->gc, *offset);
+ return NOTIFY_OK;
+ case IRQ_SIM_DOMAIN_IRQ_RELEASED:
+ gpiochip_unlock_as_irq(&chip->gc, *offset);
+ return NOTIFY_OK;
+ }
+
+ return NOTIFY_DONE;
+}
+
static void gpio_sim_dbg_show(struct seq_file *seq, struct gpio_chip *gc)
{
struct gpio_sim_chip *chip = gpiochip_get_data(gc);
@@ -322,13 +341,15 @@ static void gpio_sim_put_device(void *data)
put_device(dev);
}
-static void gpio_sim_dispose_mappings(void *data)
+static void gpio_sim_teardown_irq_sim(void *data)
{
struct gpio_sim_chip *chip = data;
unsigned int i;
for (i = 0; i < chip->gc.ngpio; i++)
irq_dispose_mapping(irq_find_mapping(chip->irq_sim, i));
+
+ irq_sim_domain_unregister_notifier(chip->irq_sim, &chip->nb);
}
static void gpio_sim_sysfs_remove(void *data)
@@ -454,7 +475,12 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
if (IS_ERR(chip->irq_sim))
return PTR_ERR(chip->irq_sim);
- ret = devm_add_action_or_reset(dev, gpio_sim_dispose_mappings, chip);
+ chip->nb.notifier_call = gpio_sim_irq_domain_notify;
+ ret = irq_sim_domain_register_notifier(chip->irq_sim, &chip->nb);
+ if (ret)
+ return ret;
+
+ ret = devm_add_action_or_reset(dev, gpio_sim_teardown_irq_sim, chip);
if (ret)
return ret;
--
2.40.1
prev parent reply other threads:[~2024-06-12 11:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-12 11:52 [PATCH 0/2] gpio: sim: lock simulated GPIOs as interrupts Bartosz Golaszewski
2024-06-12 11:52 ` [PATCH 1/2] genirq/irq_sim: add a notifier for irqchip events Bartosz Golaszewski
2024-06-21 15:40 ` Thomas Gleixner
2024-06-21 15:59 ` Bartosz Golaszewski
2024-06-21 16:16 ` Thomas Gleixner
2024-06-12 11:52 ` Bartosz Golaszewski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240612115231.26703-3-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=bartosz.golaszewski@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.