13 #include <linux/export.h>
14 #include <linux/device.h>
20 #include <linux/slab.h>
29 const struct regmap_irq_chip *
chip;
49 return &data->
chip->irqs[irq];
59 static void regmap_irq_sync_unlock(
struct irq_data *
data)
66 if (d->
chip->runtime_pm) {
67 ret = pm_runtime_get_sync(map->
dev);
69 dev_err(map->
dev,
"IRQ sync failed to resume: %d\n",
78 for (i = 0; i < d->
chip->num_regs; i++) {
79 reg = d->
chip->mask_base +
81 if (d->
chip->mask_invert)
88 dev_err(d->
map->dev,
"Failed to sync masks in %x\n",
92 if (d->
chip->runtime_pm)
93 pm_runtime_put(map->
dev);
108 static void regmap_irq_enable(
struct irq_data *data)
112 const struct regmap_irq *
irq_data = irq_to_regmap_irq(d, data->
hwirq);
117 static void regmap_irq_disable(
struct irq_data *data)
121 const struct regmap_irq *
irq_data = irq_to_regmap_irq(d, data->
hwirq);
126 static int regmap_irq_set_wake(
struct irq_data *data,
unsigned int on)
130 const struct regmap_irq *
irq_data = irq_to_regmap_irq(d, data->
hwirq);
132 if (!d->
chip->wake_base)
148 static const struct irq_chip regmap_irq_chip = {
149 .irq_bus_lock = regmap_irq_lock,
150 .irq_bus_sync_unlock = regmap_irq_sync_unlock,
151 .irq_disable = regmap_irq_disable,
152 .irq_enable = regmap_irq_enable,
153 .irq_set_wake = regmap_irq_set_wake,
156 static irqreturn_t regmap_irq_thread(
int irq,
void *d)
159 const struct regmap_irq_chip *
chip = data->
chip;
162 bool handled =
false;
165 if (chip->runtime_pm) {
166 ret = pm_runtime_get_sync(map->
dev);
168 dev_err(map->
dev,
"IRQ thread failed to resume: %d\n",
181 for (i = 0; i < data->
chip->num_regs; i++) {
187 dev_err(map->
dev,
"Failed to read IRQ status: %d\n",
189 if (chip->runtime_pm)
190 pm_runtime_put(map->
dev);
197 reg = chip->ack_base +
206 for (i = 0; i < chip->num_irqs; i++) {
207 if (data->
status_buf[chip->irqs[i].reg_offset /
214 if (chip->runtime_pm)
215 pm_runtime_put(map->
dev);
223 static int regmap_irq_map(
struct irq_domain *
h,
unsigned int virq,
230 irq_set_nested_thread(virq, 1);
237 irq_set_noprobe(virq);
244 .map = regmap_irq_map,
264 int irq_base,
const struct regmap_irq_chip *chip,
272 for (i = 0; i < chip->num_irqs; i++) {
273 if (chip->irqs[i].reg_offset % map->
reg_stride)
275 if (chip->irqs[i].reg_offset / map->
reg_stride >=
281 irq_base = irq_alloc_descs(irq_base, 0, chip->num_irqs, 0);
283 dev_warn(map->
dev,
"Failed to allocate IRQs: %d\n",
295 d->
status_buf = kzalloc(
sizeof(
unsigned int) * chip->num_regs,
300 d->
mask_buf = kzalloc(
sizeof(
unsigned int) * chip->num_regs,
305 d->
mask_buf_def = kzalloc(
sizeof(
unsigned int) * chip->num_regs,
310 if (chip->wake_base) {
311 d->
wake_buf = kzalloc(
sizeof(
unsigned int) * chip->num_regs,
319 if (!chip->wake_base) {
329 if (chip->irq_reg_stride)
336 for (i = 0; i < chip->num_irqs; i++)
338 |= chip->irqs[i].mask;
341 for (i = 0; i < chip->num_regs; i++) {
343 reg = chip->mask_base +
345 if (chip->mask_invert)
352 dev_err(map->
dev,
"Failed to set masks in 0x%x: %d\n",
360 for (i = 0; i < chip->num_regs; i++) {
362 reg = chip->wake_base +
367 dev_err(map->
dev,
"Failed to set masks in 0x%x: %d\n",
376 chip->num_irqs, irq_base, 0,
377 ®map_domain_ops, d);
381 ®map_domain_ops, d);
383 dev_err(map->
dev,
"Failed to create IRQ domain\n");
391 dev_err(map->
dev,
"Failed to request IRQ %d: %d\n", irq, ret);
455 if (!data->
chip->irqs[irq].mask)