Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1608236
| From | Sebastian Reichel <sre@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCHv4] mfd: cpcap: implement irq sense helper |
| Date | 2017-03-24 10:00 +0100 |
| Message-ID | <toteG-7pT-19@gated-at.bofh.it> (permalink) |
| References | <tobUv-3mq-23@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
CPCAP can sense if IRQ is currently set or not. This
functionality is required for a few subdevices, such
as the power button and usb phy modules.
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
Hi Lee,
I hope this is fine with you. I tried to come up
with a sensible macro for reg, but everything I
came up with actually reduced readability.
-- Sebastian
Changes since PATCHv3:
- add explicit extern to function definition
- use BIT macro for mask variable
- avoid magic numbers
---
drivers/mfd/motorola-cpcap.c | 28 ++++++++++++++++++++++++++++
include/linux/mfd/motorola-cpcap.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/drivers/mfd/motorola-cpcap.c b/drivers/mfd/motorola-cpcap.c
index 6aeada7d7ce5..c80997a377a1 100644
--- a/drivers/mfd/motorola-cpcap.c
+++ b/drivers/mfd/motorola-cpcap.c
@@ -23,6 +23,8 @@
#define CPCAP_NR_IRQ_REG_BANKS 6
#define CPCAP_NR_IRQ_CHIPS 3
+#define CPCAP_REGISTER_SIZE 4
+#define CPCAP_REGISTER_BITS 16
struct cpcap_ddata {
struct spi_device *spi;
@@ -32,6 +34,32 @@ struct cpcap_ddata {
struct regmap *regmap;
};
+static int cpcap_sense_irq(struct regmap *regmap, int irq)
+{
+ int regnum = irq / CPCAP_REGISTER_BITS;
+ int mask = BIT(irq % CPCAP_REGISTER_BITS);
+ int reg = CPCAP_REG_INTS1 + (regnum * CPCAP_REGISTER_SIZE);
+ int err, val;
+
+ if (reg < CPCAP_REG_INTS1 || reg > CPCAP_REG_INTS4)
+ return -EINVAL;
+
+ err = regmap_read(regmap, reg, &val);
+ if (err)
+ return err;
+
+ return !!(val & mask);
+}
+
+int cpcap_sense_virq(struct regmap *regmap, int virq)
+{
+ struct regmap_irq_chip_data *d = irq_get_chip_data(virq);
+ int base = regmap_irq_chip_get_base(d);
+
+ return cpcap_sense_irq(regmap, virq - base);
+}
+EXPORT_SYMBOL_GPL(cpcap_sense_virq);
+
static int cpcap_check_revision(struct cpcap_ddata *cpcap)
{
u16 vendor, rev;
diff --git a/include/linux/mfd/motorola-cpcap.h b/include/linux/mfd/motorola-cpcap.h
index b4031c2b2214..793aa695faa0 100644
--- a/include/linux/mfd/motorola-cpcap.h
+++ b/include/linux/mfd/motorola-cpcap.h
@@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev,
return 0;
}
+
+extern int cpcap_sense_virq(struct regmap *regmap, int virq);
--
2.11.0
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCHv3 1/2] mfd: cpcap: implement irq sense helper Sebastian Reichel <sre@kernel.org> - 2017-03-22 00:00 +0100
[PATCHv3 2/2] input: cpcap-pwrbutton: new driver Sebastian Reichel <sre@kernel.org> - 2017-03-22 00:00 +0100
Re: [PATCHv3 1/2] mfd: cpcap: implement irq sense helper Lee Jones <lee.jones@linaro.org> - 2017-03-23 15:30 +0100
[PATCHv4] mfd: cpcap: implement irq sense helper Sebastian Reichel <sre@kernel.org> - 2017-03-24 10:00 +0100
csiph-web