From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
To: michael@walle.cc, linus.walleij@linaro.org, brgl@bgdev.pl
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] gpio: regmap: Support a custom ->to_irq() hook
Date: Sun, 3 Jul 2022 12:10:57 +0100 [thread overview]
Message-ID: <20220703111057.23246-4-aidanmacdonald.0x0@gmail.com> (raw)
In-Reply-To: <20220703111057.23246-1-aidanmacdonald.0x0@gmail.com>
Some GPIO chips require a custom to_irq() callback for mapping
their IRQs, eg. because their interrupts come from a parent IRQ
chip where the GPIO offset doesn't map 1-to-1 with hwirq number.
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
drivers/gpio/gpio-regmap.c | 17 +++++++++++++++++
include/linux/gpio/regmap.h | 4 ++++
2 files changed, 21 insertions(+)
diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index 4bc01329fb14..d11b202e51fd 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -34,6 +34,8 @@ struct gpio_regmap {
unsigned int *reg, unsigned int *mask,
unsigned int *values);
+ int (*to_irq)(struct gpio_regmap *gpio, unsigned int offset);
+
void *driver_data;
};
@@ -193,6 +195,13 @@ static int gpio_regmap_direction_output(struct gpio_chip *chip,
return gpio_regmap_set_direction(chip, offset, true);
}
+static int gpio_regmap_to_irq(struct gpio_chip *chip, unsigned int offset)
+{
+ struct gpio_regmap *gpio = gpiochip_get_data(chip);
+
+ return gpio->to_irq(gpio, offset);
+}
+
void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio)
{
return gpio->driver_data;
@@ -242,6 +251,10 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
if (config->reg_field_xlate && config->reg_mask_xlate)
return ERR_PTR(-EINVAL);
+ /* an irq_domain will override the to_irq hook, so don't allow both */
+ if (config->irq_domain && config->to_irq)
+ return ERR_PTR(-EINVAL);
+
gpio = kzalloc(sizeof(*gpio), GFP_KERNEL);
if (!gpio)
return ERR_PTR(-ENOMEM);
@@ -253,6 +266,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
gpio->reg_stride = config->reg_stride;
gpio->reg_mask_xlate = config->reg_mask_xlate;
gpio->reg_field_xlate = config->reg_field_xlate;
+ gpio->to_irq = config->to_irq;
gpio->reg_dat_base = config->reg_dat_base;
gpio->reg_set_base = config->reg_set_base;
gpio->reg_clr_base = config->reg_clr_base;
@@ -302,6 +316,9 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
chip->direction_output = gpio_regmap_direction_output;
}
+ if (gpio->to_irq)
+ chip->to_irq = gpio_regmap_to_irq;
+
ret = gpiochip_add_data(chip, gpio);
if (ret < 0)
goto err_free_gpio;
diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
index 47acea8cca32..9755854d6747 100644
--- a/include/linux/gpio/regmap.h
+++ b/include/linux/gpio/regmap.h
@@ -45,6 +45,8 @@ struct regmap;
* to register, mask, and field values. If not given
* the default gpio_regmap_field_xlate() is used, which
* is implemented in terms of ->reg_mask_xlate.
+ * @to_irq: (Optional) hook for supporting custom IRQ mappings,
+ * behaves the same as the gpio_chip to_irq hook.
* @drvdata: (Optional) Pointer to driver specific data which is
* not used by gpio-remap but is provided "as is" to the
* driver callback(s).
@@ -102,6 +104,8 @@ struct gpio_regmap_config {
unsigned int *reg, unsigned int *mask,
unsigned int *values);
+ int (*to_irq)(struct gpio_regmap *gpio, unsigned int offset);
+
void *drvdata;
};
--
2.35.1
next prev parent reply other threads:[~2022-07-03 11:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-03 11:10 [PATCH 0/3] gpio-regmap support for register fields and other hooks Aidan MacDonald
2022-07-03 11:10 ` [PATCH 1/3] gpio: regmap: Support registers with more than one bit per GPIO Aidan MacDonald
2022-07-03 14:09 ` Andy Shevchenko
2022-07-04 16:03 ` Aidan MacDonald
2022-07-04 12:28 ` Michael Walle
2022-07-04 16:01 ` Aidan MacDonald
2022-07-04 19:46 ` Michael Walle
2022-07-06 20:46 ` Aidan MacDonald
2022-07-07 7:44 ` Michael Walle
2022-07-07 14:58 ` Aidan MacDonald
2022-07-03 11:10 ` [PATCH 2/3] gpio: regmap: Support combined GPIO and pin control drivers Aidan MacDonald
2022-07-03 14:14 ` Andy Shevchenko
2022-07-04 15:31 ` Aidan MacDonald
2022-07-03 11:10 ` Aidan MacDonald [this message]
2022-07-03 14:24 ` [PATCH 3/3] gpio: regmap: Support a custom ->to_irq() hook Andy Shevchenko
2022-07-04 16:38 ` Aidan MacDonald
2022-07-04 23:05 ` Linus Walleij
2022-07-05 11:09 ` Aidan MacDonald
2022-07-06 11:45 ` Andy Shevchenko
2022-07-06 20:53 ` Aidan MacDonald
2022-07-06 12:02 ` Linus Walleij
2022-07-06 13:50 ` Aidan MacDonald
2022-07-11 11:48 ` Linus Walleij
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=20220703111057.23246-4-aidanmacdonald.0x0@gmail.com \
--to=aidanmacdonald.0x0@gmail.com \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@walle.cc \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).