diff options
| author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-12-12 00:10:02 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-12-12 00:10:02 -0500 |
| commit | ce37954e93e9e85333577dcc22db5a4d0f4c9d5e (patch) | |
| tree | 133571eae537a4f1c304c5396668c7ec6a8e2bb7 | |
| parent | dc47ce90c3a822cd7c9e9339fe4d5f61dcb26b50 (diff) | |
| parent | 209a600623cf13a8168b2f6b83643db7825abb9a (diff) | |
Merge branch 'topic/irq' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into mfd/da9052
| -rw-r--r-- | drivers/base/regmap/Kconfig | 3 | ||||
| -rw-r--r-- | drivers/base/regmap/Makefile | 1 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-irq.c | 302 | ||||
| -rw-r--r-- | include/linux/regmap.h | 48 |
4 files changed, 354 insertions, 0 deletions
diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index 2fc6a66f39a4..0f6c7fb418e8 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig | |||
| @@ -13,3 +13,6 @@ config REGMAP_I2C | |||
| 13 | 13 | ||
| 14 | config REGMAP_SPI | 14 | config REGMAP_SPI |
| 15 | tristate | 15 | tristate |
| 16 | |||
| 17 | config REGMAP_IRQ | ||
| 18 | bool | ||
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile index 0573c8a9dacb..ce2d18a6465b 100644 --- a/drivers/base/regmap/Makefile +++ b/drivers/base/regmap/Makefile | |||
| @@ -2,3 +2,4 @@ obj-$(CONFIG_REGMAP) += regmap.o regcache.o regcache-indexed.o regcache-rbtree.o | |||
| 2 | obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o | 2 | obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o |
| 3 | obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o | 3 | obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o |
| 4 | obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o | 4 | obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o |
| 5 | obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o | ||
diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c new file mode 100644 index 000000000000..428836fc5835 --- /dev/null +++ b/drivers/base/regmap/regmap-irq.c | |||
| @@ -0,0 +1,302 @@ | |||
| 1 | /* | ||
| 2 | * regmap based irq_chip | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc | ||
| 5 | * | ||
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/export.h> | ||
| 14 | #include <linux/regmap.h> | ||
| 15 | #include <linux/irq.h> | ||
| 16 | #include <linux/interrupt.h> | ||
| 17 | #include <linux/slab.h> | ||
| 18 | |||
| 19 | #include "internal.h" | ||
| 20 | |||
| 21 | struct regmap_irq_chip_data { | ||
| 22 | struct mutex lock; | ||
| 23 | |||
| 24 | struct regmap *map; | ||
| 25 | struct regmap_irq_chip *chip; | ||
| 26 | |||
| 27 | int irq_base; | ||
| 28 | |||
| 29 | void *status_reg_buf; | ||
| 30 | unsigned int *status_buf; | ||
| 31 | unsigned int *mask_buf; | ||
| 32 | unsigned int *mask_buf_def; | ||
| 33 | }; | ||
| 34 | |||
| 35 | static inline const | ||
| 36 | struct regmap_irq *irq_to_regmap_irq(struct regmap_irq_chip_data *data, | ||
| 37 | int irq) | ||
| 38 | { | ||
| 39 | return &data->chip->irqs[irq - data->irq_base]; | ||
| 40 | } | ||
| 41 | |||
| 42 | static void regmap_irq_lock(struct irq_data *data) | ||
| 43 | { | ||
| 44 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); | ||
| 45 | |||
| 46 | mutex_lock(&d->lock); | ||
| 47 | } | ||
| 48 | |||
| 49 | static void regmap_irq_sync_unlock(struct irq_data *data) | ||
| 50 | { | ||
| 51 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); | ||
| 52 | int i, ret; | ||
| 53 | |||
| 54 | /* | ||
| 55 | * If there's been a change in the mask write it back to the | ||
| 56 | * hardware. We rely on the use of the regmap core cache to | ||
| 57 | * suppress pointless writes. | ||
| 58 | */ | ||
| 59 | for (i = 0; i < d->chip->num_regs; i++) { | ||
| 60 | ret = regmap_update_bits(d->map, d->chip->mask_base + i, | ||
| 61 | d->mask_buf_def[i], d->mask_buf[i]); | ||
| 62 | if (ret != 0) | ||
| 63 | dev_err(d->map->dev, "Failed to sync masks in %x\n", | ||
| 64 | d->chip->mask_base + i); | ||
| 65 | } | ||
| 66 | |||
| 67 | mutex_unlock(&d->lock); | ||
| 68 | } | ||
| 69 | |||
| 70 | static void regmap_irq_enable(struct irq_data *data) | ||
| 71 | { | ||
| 72 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); | ||
| 73 | const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->irq); | ||
| 74 | |||
| 75 | d->mask_buf[irq_data->reg_offset] &= ~irq_data->mask; | ||
| 76 | } | ||
| 77 | |||
| 78 | static void regmap_irq_disable(struct irq_data *data) | ||
| 79 | { | ||
| 80 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); | ||
| 81 | const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->irq); | ||
| 82 | |||
| 83 | d->mask_buf[irq_data->reg_offset] |= irq_data->mask; | ||
| 84 | } | ||
| 85 | |||
| 86 | static struct irq_chip regmap_irq_chip = { | ||
| 87 | .name = "regmap", | ||
| 88 | .irq_bus_lock = regmap_irq_lock, | ||
| 89 | .irq_bus_sync_unlock = regmap_irq_sync_unlock, | ||
| 90 | .irq_disable = regmap_irq_disable, | ||
| 91 | .irq_enable = regmap_irq_enable, | ||
| 92 | }; | ||
| 93 | |||
| 94 | static irqreturn_t regmap_irq_thread(int irq, void *d) | ||
| 95 | { | ||
| 96 | struct regmap_irq_chip_data *data = d; | ||
| 97 | struct regmap_irq_chip *chip = data->chip; | ||
| 98 | struct regmap *map = data->map; | ||
| 99 | int ret, i; | ||
| 100 | u8 *buf8 = data->status_reg_buf; | ||
| 101 | u16 *buf16 = data->status_reg_buf; | ||
| 102 | u32 *buf32 = data->status_reg_buf; | ||
| 103 | bool handled = false; | ||
| 104 | |||
| 105 | ret = regmap_bulk_read(map, chip->status_base, data->status_reg_buf, | ||
| 106 | chip->num_regs); | ||
| 107 | if (ret != 0) { | ||
| 108 | dev_err(map->dev, "Failed to read IRQ status: %d\n", ret); | ||
| 109 | return IRQ_NONE; | ||
| 110 | } | ||
| 111 | |||
| 112 | /* | ||
| 113 | * Ignore masked IRQs and ack if we need to; we ack early so | ||
| 114 | * there is no race between handling and acknowleding the | ||
| 115 | * interrupt. We assume that typically few of the interrupts | ||
| 116 | * will fire simultaneously so don't worry about overhead from | ||
| 117 | * doing a write per register. | ||
| 118 | */ | ||
| 119 | for (i = 0; i < data->chip->num_regs; i++) { | ||
| 120 | switch (map->format.val_bytes) { | ||
| 121 | case 1: | ||
| 122 | data->status_buf[i] = buf8[i]; | ||
| 123 | break; | ||
| 124 | case 2: | ||
| 125 | data->status_buf[i] = buf16[i]; | ||
| 126 | break; | ||
| 127 | case 4: | ||
| 128 | data->status_buf[i] = buf32[i]; | ||
| 129 | break; | ||
| 130 | default: | ||
| 131 | BUG(); | ||
| 132 | return IRQ_NONE; | ||
| 133 | } | ||
| 134 | |||
| 135 | data->status_buf[i] &= ~data->mask_buf[i]; | ||
| 136 | |||
| 137 | if (data->status_buf[i] && chip->ack_base) { | ||
| 138 | ret = regmap_write(map, chip->ack_base + i, | ||
| 139 | data->status_buf[i]); | ||
| 140 | if (ret != 0) | ||
| 141 | dev_err(map->dev, "Failed to ack 0x%x: %d\n", | ||
| 142 | chip->ack_base + i, ret); | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | for (i = 0; i < chip->num_irqs; i++) { | ||
| 147 | if (data->status_buf[chip->irqs[i].reg_offset] & | ||
| 148 | chip->irqs[i].mask) { | ||
| 149 | handle_nested_irq(data->irq_base + i); | ||
| 150 | handled = true; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | if (handled) | ||
| 155 | return IRQ_HANDLED; | ||
| 156 | else | ||
| 157 | return IRQ_NONE; | ||
| 158 | } | ||
| 159 | |||
| 160 | /** | ||
| 161 | * regmap_add_irq_chip(): Use standard regmap IRQ controller handling | ||
| 162 | * | ||
| 163 | * map: The regmap for the device. | ||
| 164 | * irq: The IRQ the device uses to signal interrupts | ||
| 165 | * irq_flags: The IRQF_ flags to use for the primary interrupt. | ||
| 166 | * chip: Configuration for the interrupt controller. | ||
| 167 | * data: Runtime data structure for the controller, allocated on success | ||
| 168 | * | ||
| 169 | * Returns 0 on success or an errno on failure. | ||
| 170 | * | ||
| 171 | * In | ||
