From: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
To: "Lee Jones" <lee@kernel.org>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Kamel Bouhara" <kamel.bouhara@bootlin.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
"Michael Walle" <mwalle@kernel.org>,
"Mark Brown" <broonie@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-input@vger.kernel.org,
linux-pwm@vger.kernel.org, andriy.shevchenko@intel.com,
"Grégory Clement" <gregory.clement@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Mathieu Dubois-Briand" <mathieu.dubois-briand@bootlin.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v6 06/12] regmap: irq: Add support for chips without separate IRQ status
Date: Wed, 09 Apr 2025 16:55:53 +0200 [thread overview]
Message-ID: <20250409-mdb-max7360-support-v6-6-7a2535876e39@bootlin.com> (raw)
In-Reply-To: <20250409-mdb-max7360-support-v6-0-7a2535876e39@bootlin.com>
Some GPIO chips allow to rise an IRQ on GPIO level changes but do not
provide an IRQ status for each separate line: only the current gpio
level can be retrieved.
Add support for these chips, emulating IRQ status by comparing GPIO
levels with the levels during the previous interrupt.
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/regmap/regmap-irq.c | 95 +++++++++++++++++++++++++++-------------
include/linux/regmap.h | 3 ++
2 files changed, 68 insertions(+), 30 deletions(-)
diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 14f5fcc3ec1d..b4a72750ff6d 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -6,6 +6,7 @@
//
// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+#include <linux/array_size.h>
#include <linux/device.h>
#include <linux/export.h>
#include <linux/interrupt.h>
@@ -33,6 +34,7 @@ struct regmap_irq_chip_data {
void *status_reg_buf;
unsigned int *main_status_buf;
unsigned int *status_buf;
+ unsigned int *prev_status_buf;
unsigned int *mask_buf;
unsigned int *mask_buf_def;
unsigned int *wake_buf;
@@ -332,27 +334,13 @@ static inline int read_sub_irq_data(struct regmap_irq_chip_data *data,
return ret;
}
-static irqreturn_t regmap_irq_thread(int irq, void *d)
+static int read_irq_data(struct regmap_irq_chip_data *data)
{
- struct regmap_irq_chip_data *data = d;
const struct regmap_irq_chip *chip = data->chip;
struct regmap *map = data->map;
int ret, i;
- bool handled = false;
u32 reg;
- if (chip->handle_pre_irq)
- chip->handle_pre_irq(chip->irq_drv_data);
-
- if (chip->runtime_pm) {
- ret = pm_runtime_get_sync(map->dev);
- if (ret < 0) {
- dev_err(map->dev, "IRQ thread failed to resume: %d\n",
- ret);
- goto exit;
- }
- }
-
/*
* Read only registers with active IRQs if the chip has 'main status
* register'. Else read in the statuses, using a single bulk read if
@@ -379,10 +367,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
reg = data->get_irq_reg(data, chip->main_status, i);
ret = regmap_read(map, reg, &data->main_status_buf[i]);
if (ret) {
- dev_err(map->dev,
- "Failed to read IRQ status %d\n",
- ret);
- goto exit;
+ dev_err(map->dev, "Failed to read IRQ status %d\n", ret);
+ return ret;
}
}
@@ -398,10 +384,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
ret = read_sub_irq_data(data, b);
if (ret != 0) {
- dev_err(map->dev,
- "Failed to read IRQ status %d\n",
- ret);
- goto exit;
+ dev_err(map->dev, "Failed to read IRQ status %d\n", ret);
+ return ret;
}
}
@@ -418,9 +402,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
data->status_reg_buf,
chip->num_regs);
if (ret != 0) {
- dev_err(map->dev, "Failed to read IRQ status: %d\n",
- ret);
- goto exit;
+ dev_err(map->dev, "Failed to read IRQ status: %d\n", ret);
+ return ret;
}
for (i = 0; i < data->chip->num_regs; i++) {
@@ -446,10 +429,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
ret = regmap_read(map, reg, &data->status_buf[i]);
if (ret != 0) {
- dev_err(map->dev,
- "Failed to read IRQ status: %d\n",
- ret);
- goto exit;
+ dev_err(map->dev, "Failed to read IRQ status: %d\n", ret);
+ return ret;
}
}
}
@@ -458,6 +439,42 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
for (i = 0; i < data->chip->num_regs; i++)
data->status_buf[i] = ~data->status_buf[i];
+ return 0;
+}
+
+static irqreturn_t regmap_irq_thread(int irq, void *d)
+{
+ struct regmap_irq_chip_data *data = d;
+ const struct regmap_irq_chip *chip = data->chip;
+ struct regmap *map = data->map;
+ int ret, i;
+ bool handled = false;
+ u32 reg;
+
+ if (chip->handle_pre_irq)
+ chip->handle_pre_irq(chip->irq_drv_data);
+
+ if (chip->runtime_pm) {
+ ret = pm_runtime_get_sync(map->dev);
+ if (ret < 0) {
+ dev_err(map->dev, "IRQ thread failed to resume: %d\n", ret);
+ goto exit;
+ }
+ }
+
+ ret = read_irq_data(data);
+ if (ret < 0)
+ goto exit;
+
+ if (chip->status_is_level) {
+ for (i = 0; i < data->chip->num_regs; i++) {
+ unsigned int val = data->status_buf[i];
+
+ data->status_buf[i] ^= data->prev_status_buf[i];
+ data->prev_status_buf[i] = val;
+ }
+ }
+
/*
* Ignore masked IRQs and ack if we need to; we ack early so
* there is no race between handling and acknowledging the
@@ -704,6 +721,13 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
if (!d->status_buf)
goto err_alloc;
+ if (chip->status_is_level) {
+ d->prev_status_buf = kcalloc(chip->num_regs, sizeof(*d->prev_status_buf),
+ GFP_KERNEL);
+ if (!d->prev_status_buf)
+ goto err_alloc;
+ }
+
d->mask_buf = kcalloc(chip->num_regs, sizeof(*d->mask_buf),
GFP_KERNEL);
if (!d->mask_buf)
@@ -880,6 +904,15 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
}
}
+ /* Store current levels */
+ if (chip->status_is_level) {
+ ret = read_irq_data(d);
+ if (ret < 0)
+ goto err_alloc;
+
+ memcpy(d->prev_status_buf, d->status_buf, array_size(d->prev_status_buf));
+ }
+
ret = regmap_irq_create_domain(fwnode, irq_base, chip, d);
if (ret)
goto err_alloc;
@@ -907,6 +940,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
kfree(d->mask_buf);
kfree(d->main_status_buf);
kfree(d->status_buf);
+ kfree(d->prev_status_buf);
kfree(d->status_reg_buf);
if (d->config_buf) {
for (i = 0; i < chip->num_config_bases; i++)
@@ -984,6 +1018,7 @@ void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *d)
kfree(d->main_status_buf);
kfree(d->status_reg_buf);
kfree(d->status_buf);
+ kfree(d->prev_status_buf);
if (d->config_buf) {
for (i = 0; i < d->chip->num_config_bases; i++)
kfree(d->config_buf[i]);
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index d17c5ea3d55d..02b83f5499b8 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1641,6 +1641,8 @@ struct regmap_irq_chip_data;
* @ack_invert: Inverted ack register: cleared bits for ack.
* @clear_ack: Use this to set 1 and 0 or vice-versa to clear interrupts.
* @status_invert: Inverted status register: cleared bits are active interrupts.
+ * @status_is_level: Status register is actuall signal level: Xor status
+ * register with previous value to get active interrupts.
* @wake_invert: Inverted wake register: cleared bits are wake enabled.
* @type_in_mask: Use the mask registers for controlling irq type. Use this if
* the hardware provides separate bits for rising/falling edge
@@ -1704,6 +1706,7 @@ struct regmap_irq_chip {
unsigned int ack_invert:1;
unsigned int clear_ack:1;
unsigned int status_invert:1;
+ unsigned int status_is_level:1;
unsigned int wake_invert:1;
unsigned int type_in_mask:1;
unsigned int clear_on_unmask:1;
--
2.39.5
next prev parent reply other threads:[~2025-04-09 14:56 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 14:55 [PATCH v6 00/12] Add support for MAX7360 Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 01/12] dt-bindings: mfd: gpio: Add MAX7360 Mathieu Dubois-Briand
2025-04-09 15:22 ` [External] : " ALOK TIWARI
2025-04-10 7:55 ` Lee Jones
2025-04-10 8:19 ` Mathieu Dubois-Briand
2025-04-09 20:58 ` Dmitry Torokhov
2025-04-10 8:22 ` Mathieu Dubois-Briand
2025-04-11 16:05 ` Rob Herring (Arm)
2025-04-15 11:24 ` Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 02/12] mfd: Add max7360 support mathieu.dubois-briand
2025-04-17 18:16 ` Andy Shevchenko
2025-04-18 15:39 ` Mathieu Dubois-Briand
2025-04-18 15:52 ` Christophe JAILLET
2025-04-18 16:20 ` Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 03/12] pinctrl: Add MAX7360 pinctrl driver Mathieu Dubois-Briand
2025-04-09 15:03 ` Mathieu Dubois-Briand
2025-04-09 16:32 ` Andy Shevchenko
2025-04-10 8:37 ` Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 04/12] pwm: max7360: Add MAX7360 PWM support mathieu.dubois-briand
2025-04-09 17:00 ` Andy Shevchenko
2025-04-10 8:48 ` Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 05/12] regmap: irq: Remove unreachable goto Mathieu Dubois-Briand
2025-04-09 15:19 ` Mark Brown
2025-04-09 15:21 ` Mark Brown
2025-04-10 8:53 ` Mathieu Dubois-Briand
2025-04-09 15:38 ` Andy Shevchenko
2025-04-09 15:46 ` Mark Brown
2025-04-09 16:00 ` Andy Shevchenko
2025-04-09 16:32 ` Mark Brown
2025-04-09 16:45 ` Andy Shevchenko
2025-04-09 17:16 ` Dmitry Torokhov
2025-04-10 18:43 ` Andy Shevchenko
2025-04-09 15:56 ` Andy Shevchenko
2025-04-19 10:38 ` Uwe Kleine-König
2025-04-23 12:41 ` Mathieu Dubois-Briand
2025-04-23 12:42 ` Mark Brown
2025-04-09 15:40 ` Andy Shevchenko
2025-04-09 14:55 ` Mathieu Dubois-Briand [this message]
2025-04-09 14:55 ` [PATCH v6 07/12] gpio: regmap: Allow to allocate regmap-irq device Mathieu Dubois-Briand
2025-04-09 16:39 ` Andy Shevchenko
2025-04-10 9:03 ` Mathieu Dubois-Briand
2025-04-14 10:29 ` Andy Shevchenko
2025-04-09 14:55 ` [PATCH v6 08/12] gpio: regmap: Allow to provide init_valid_mask callback Mathieu Dubois-Briand
2025-04-09 17:02 ` Andy Shevchenko
2025-04-10 10:03 ` Mathieu Dubois-Briand
2025-04-15 22:15 ` Linus Walleij
2025-04-09 14:55 ` [PATCH v6 09/12] gpio: max7360: Add MAX7360 gpio support Mathieu Dubois-Briand
2025-04-17 12:41 ` Bartosz Golaszewski
2025-04-17 18:13 ` Andy Shevchenko
2025-04-18 15:26 ` Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 10/12] input: keyboard: Add support for MAX7360 keypad Mathieu Dubois-Briand
2025-04-09 18:40 ` Dmitry Torokhov
2025-04-10 11:29 ` Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 11/12] input: misc: Add support for MAX7360 rotary Mathieu Dubois-Briand
2025-04-09 19:17 ` Dmitry Torokhov
2025-04-10 11:36 ` Mathieu Dubois-Briand
2025-04-09 14:55 ` [PATCH v6 12/12] MAINTAINERS: Add entry on MAX7360 driver Mathieu Dubois-Briand
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=20250409-mdb-max7360-support-v6-6-7a2535876e39@bootlin.com \
--to=mathieu.dubois-briand@bootlin.com \
--cc=andriy.shevchenko@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=gregory.clement@bootlin.com \
--cc=kamel.bouhara@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=mwalle@kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=ukleinek@kernel.org \
/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).