[PATCH 2/2] regmap-irq: support different type of irq register

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


* Interrupt-masked vs Interrupt-enabled
Commonly the interrupt register is masked when the bit of IRQ register is set.
But in some device like TI LP8788, the interrupt is enabled when the bit is 1.

This patch supports the interrupt-enabled type.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@xxxxxx>
---
 drivers/base/regmap/regmap-irq.c |   42 ++++++++++++++++++++++++++++++++++---
 include/linux/regmap.h           |    9 ++++++++
 2 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index ed36ea2..cb44918 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -94,7 +94,16 @@ static void regmap_irq_enable(struct irq_data *data)
 	struct regmap *map = d->map;
 	const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->hwirq);
 
-	d->val_buf[irq_data->reg_offset / map->reg_stride] &= ~irq_data->mask;
+	switch (d->chip->irq_type) {
+	case REGIRQ_MASKED:
+		d->val_buf[irq_data->reg_offset / map->reg_stride] &= ~irq_data->mask;
+		break;
+	case REGIRQ_ENABLED:
+		d->val_buf[irq_data->reg_offset / map->reg_stride] |= irq_data->mask;
+		break;
+	default:
+		break;
+	}
 }
 
 static void regmap_irq_disable(struct irq_data *data)
@@ -103,7 +112,16 @@ static void regmap_irq_disable(struct irq_data *data)
 	struct regmap *map = d->map;
 	const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->hwirq);
 
-	d->val_buf[irq_data->reg_offset / map->reg_stride] |= irq_data->mask;
+	switch (d->chip->irq_type) {
+	case REGIRQ_MASKED:
+		d->val_buf[irq_data->reg_offset / map->reg_stride] |= irq_data->mask;
+		break;
+	case REGIRQ_ENABLED:
+		d->val_buf[irq_data->reg_offset / map->reg_stride] &= ~irq_data->mask;
+		break;
+	default:
+		break;
+	}
 }
 
 static int regmap_irq_set_wake(struct irq_data *data, unsigned int on)
@@ -163,7 +181,18 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 			return IRQ_NONE;
 		}
 
-		data->status_buf[i] &= ~data->mask_buf[i];
+		switch (data->chip->irq_type) {
+		case REGIRQ_MASKED:
+			data->status_buf[i] &= ~data->mask_buf[i];
+			break;
+		case REGIRQ_ENABLED:
+			data->status_buf[i] &= data->mask_buf[i];
+			break;
+		default:
+			dev_err(map->dev, "Invalid irq register type: %d\n",
+					data->chip->irq_type);
+			return IRQ_NONE;
+		}
 
 		if (data->status_buf[i] && chip->ack_base) {
 			ret = regmap_write(map, chip->ack_base +
@@ -238,6 +267,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
 	struct regmap_irq_chip_data *d;
 	int i;
 	int ret = -ENOMEM;
+	unsigned int val;
 
 	for (i = 0; i < chip->num_irqs; i++) {
 		if (chip->irqs[i].reg_offset % map->reg_stride)
@@ -302,9 +332,13 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
 
 	/* Mask all the interrupts by default */
 	for (i = 0; i < chip->num_regs; i++) {
+		val = d->mask_buf[i];
+		if (chip->irq_type == REGIRQ_ENABLED)
+			val = ~d->mask_buf[i];
+
 		ret = regmap_write(map, chip->mask_base + (i * map->reg_stride
 				   * d->irq_reg_stride),
-				   d->mask_buf[i]);
+				   val);
 		if (ret != 0) {
 			dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
 				chip->mask_base + (i * map->reg_stride), ret);
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 7f7e00d..e0094db 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -30,6 +30,12 @@ enum regcache_type {
 	REGCACHE_COMPRESSED
 };
 
+/* Interrupt register type : masked or enabled */
+enum regirq_type {
+	REGIRQ_MASKED,	/* interrupt is masked when the bit is set */
+	REGIRQ_ENABLED,	/* interrupt is enabled when the bit is set */
+};
+
 /**
  * Default value for a register.  We use an array of structs rather
  * than a simple array as many modern devices have very sparse
@@ -290,6 +296,7 @@ struct regmap_irq {
  * @irqs:        Descriptors for individual IRQs.  Interrupt numbers are
  *               assigned based on the index in the array of the interrupt.
  * @num_irqs:    Number of descriptors.
+ * @irq_type:    Interrupt register type. masked or enabled
  */
 struct regmap_irq_chip {
 	const char *name;
@@ -304,6 +311,8 @@ struct regmap_irq_chip {
 
 	const struct regmap_irq *irqs;
 	int num_irqs;
+
+	enum regirq_type irq_type;
 };
 
 struct regmap_irq_chip_data;
-- 
1.7.2.5


Best Regards,
Milo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[Other Archives]     [Linux Kernel Newbies]     [Linux Driver Development]     [Linux Kbuild]     [Fedora Kernel]     [Linux Kernel Testers]     [Linux SH]     [Linux Omap]     [Linux Tape]     [Linux Input]     [Linux Kernel Janitors]     [Linux Kernel Packagers]     [Linux Doc]     [Linux Man Pages]     [Linux API]     [Linux Memory Management]     [Linux Modules]     [Linux Standards]     [Kernel Announce]     [Netdev]     [Git]     [Linux PCI]     Linux CAN Development     [Linux I2C]     [Linux RDMA]     [Linux NUMA]     [Netfilter]     [Netfilter Devel]     [SELinux]     [Bugtraq]     [FIO]     [Linux Perf Users]     [Linux Serial]     [Linux PPP]     [Linux ISDN]     [Linux Next]     [Kernel Stable Commits]     [Linux Tip Commits]     [Kernel MM Commits]     [Linux Security Module]     [AutoFS]     [Filesystem Development]     [Ext3 Filesystem]     [Linux bcache]     [Ext4 Filesystem]     [Linux BTRFS]     [Linux CEPH Filesystem]     [Linux XFS]     [XFS]     [Linux NFS]     [Linux CIFS]     [Ecryptfs]     [Linux NILFS]     [Linux Cachefs]     [Reiser FS]     [Initramfs]     [Linux FB Devel]     [Linux OpenGL]     [DRI Devel]     [Fastboot]     [Linux RT Users]     [Linux RT Stable]     [eCos]     [Corosync]     [Linux Clusters]     [LVS Devel]     [Hot Plug]     [Linux Virtualization]     [KVM]     [KVM PPC]     [KVM ia64]     [Linux Containers]     [Linux Hexagon]     [Linux Cgroups]     [Util Linux]     [Wireless]     [Linux Bluetooth]     [Bluez Devel]     [Ethernet Bridging]     [Embedded Linux]     [Barebox]     [Linux MMC]     [Linux IIO]     [Sparse]     [Smatch]     [Linux Arch]     [x86 Platform Driver]     [Linux ACPI]     [Linux IBM ACPI]     [LM Sensors]     [CPU Freq]     [Linux Power Management]     [Linmodems]     [Linux DCCP]     [Linux SCTP]     [ALSA Devel]     [Linux USB]     [Linux PA RISC]     [Linux Samsung SOC]     [MIPS Linux]     [IBM S/390 Linux]     [ARM Linux]     [ARM Kernel]     [ARM MSM]     [Tegra Devel]     [Sparc Linux]     [Linux Security]     [Linux Sound]     [Linux Media]     [Video 4 Linux]     [Linux IRDA Users]     [Linux for the blind]     [Linux RAID]     [Linux ATA RAID]     [Device Mapper]     [Linux SCSI]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Linux IDE]     [Linux SMP]     [Linux AXP]     [Linux Alpha]     [Linux M68K]     [Linux ia64]     [Linux 8086]     [Linux x86_64]     [Linux Config]     [Linux Apps]     [Linux MSDOS]     [Linux X.25]     [Linux Crypto]     [DM Crypt]     [Linux Trace Users]     [Linux Btrace]     [Linux Watchdog]     [Utrace Devel]     [Linux C Programming]     [Linux Assembly]     [Dash]     [DWARVES]     [Hail Devel]     [Linux Kernel Debugger]     [Linux gcc]     [Gcc Help]     [X.Org]     [Wine]

Add to Google Powered by Linux

[Older Kernel Discussion]     [Yosemite National Park Forum]     [Large Format Photos]     [Gimp]     [Yosemite Photos]     [Stuff]