2 * regmap based irq_chip
4 * Copyright 2011 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
13 #include <linux/device.h>
14 #include <linux/export.h>
15 #include <linux/interrupt.h>
16 #include <linux/irq.h>
17 #include <linux/irqdomain.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/regmap.h>
20 #include <linux/slab.h>
24 struct regmap_irq_chip_data
{
26 struct irq_chip irq_chip
;
29 const struct regmap_irq_chip
*chip
;
32 struct irq_domain
*domain
;
38 unsigned int *main_status_buf
;
39 unsigned int *status_buf
;
40 unsigned int *mask_buf
;
41 unsigned int *mask_buf_def
;
42 unsigned int *wake_buf
;
43 unsigned int *type_buf
;
44 unsigned int *type_buf_def
;
46 unsigned int irq_reg_stride
;
47 unsigned int type_reg_stride
;
53 struct regmap_irq
*irq_to_regmap_irq(struct regmap_irq_chip_data
*data
,
56 return &data
->chip
->irqs
[irq
];
59 static void regmap_irq_lock(struct irq_data
*data
)
61 struct regmap_irq_chip_data
*d
= irq_data_get_irq_chip_data(data
);
66 static int regmap_irq_update_bits(struct regmap_irq_chip_data
*d
,
67 unsigned int reg
, unsigned int mask
,
70 if (d
->chip
->mask_writeonly
)
71 return regmap_write_bits(d
->map
, reg
, mask
, val
);
73 return regmap_update_bits(d
->map
, reg
, mask
, val
);
76 static void regmap_irq_sync_unlock(struct irq_data
*data
)
78 struct regmap_irq_chip_data
*d
= irq_data_get_irq_chip_data(data
);
79 struct regmap
*map
= d
->map
;
85 if (d
->chip
->runtime_pm
) {
86 ret
= pm_runtime_get_sync(map
->dev
);
88 dev_err(map
->dev
, "IRQ sync failed to resume: %d\n",
92 if (d
->clear_status
) {
93 for (i
= 0; i
< d
->chip
->num_regs
; i
++) {
94 reg
= d
->chip
->status_base
+
95 (i
* map
->reg_stride
* d
->irq_reg_stride
);
97 ret
= regmap_read(map
, reg
, &val
);
100 "Failed to clear the interrupt status bits\n");
103 d
->clear_status
= false;
107 * If there's been a change in the mask write it back to the
108 * hardware. We rely on the use of the regmap core cache to
109 * suppress pointless writes.
111 for (i
= 0; i
< d
->chip
->num_regs
; i
++) {
112 if (!d
->chip
->mask_base
)
115 reg
= d
->chip
->mask_base
+
116 (i
* map
->reg_stride
* d
->irq_reg_stride
);
117 if (d
->chip
->mask_invert
) {
118 ret
= regmap_irq_update_bits(d
, reg
,
119 d
->mask_buf_def
[i
], ~d
->mask_buf
[i
]);
120 } else if (d
->chip
->unmask_base
) {
121 /* set mask with mask_base register */
122 ret
= regmap_irq_update_bits(d
, reg
,
123 d
->mask_buf_def
[i
], ~d
->mask_buf
[i
]);
126 "Failed to sync unmasks in %x\n",
128 unmask_offset
= d
->chip
->unmask_base
-
130 /* clear mask with unmask_base register */
131 ret
= regmap_irq_update_bits(d
,
136 ret
= regmap_irq_update_bits(d
, reg
,
137 d
->mask_buf_def
[i
], d
->mask_buf
[i
]);
140 dev_err(d
->map
->dev
, "Failed to sync masks in %x\n",
143 reg
= d
->chip
->wake_base
+
144 (i
* map
->reg_stride
* d
->irq_reg_stride
);
146 if (d
->chip
->wake_invert
)
147 ret
= regmap_irq_update_bits(d
, reg
,
151 ret
= regmap_irq_update_bits(d
, reg
,
156 "Failed to sync wakes in %x: %d\n",
160 if (!d
->chip
->init_ack_masked
)
163 * Ack all the masked interrupts unconditionally,
164 * OR if there is masked interrupt which hasn't been Acked,
165 * it'll be ignored in irq handler, then may introduce irq storm
167 if (d
->mask_buf
[i
] && (d
->chip
->ack_base
|| d
->chip
->use_ack
)) {
168 reg
= d
->chip
->ack_base
+
169 (i
* map
->reg_stride
* d
->irq_reg_stride
);
170 /* some chips ack by write 0 */
171 if (d
->chip
->ack_invert
)
172 ret
= regmap_write(map
, reg
, ~d
->mask_buf
[i
]);
174 ret
= regmap_write(map
, reg
, d
->mask_buf
[i
]);
176 dev_err(d
->map
->dev
, "Failed to ack 0x%x: %d\n",
181 /* Don't update the type bits if we're using mask bits for irq type. */
182 if (!d
->chip
->type_in_mask
) {
183 for (i
= 0; i
< d
->chip
->num_type_reg
; i
++) {
184 if (!d
->type_buf_def
[i
])
186 reg
= d
->chip
->type_base
+
187 (i
* map
->reg_stride
* d
->type_reg_stride
);
188 if (d
->chip
->type_invert
)
189 ret
= regmap_irq_update_bits(d
, reg
,
190 d
->type_buf_def
[i
], ~d
->type_buf
[i
]);
192 ret
= regmap_irq_update_bits(d
, reg
,
193 d
->type_buf_def
[i
], d
->type_buf
[i
]);
195 dev_err(d
->map
->dev
, "Failed to sync type in %x\n",
200 if (d
->chip
->runtime_pm
)
201 pm_runtime_put(map
->dev
);
203 /* If we've changed our wakeup count propagate it to the parent */
204 if (d
->wake_count
< 0)
205 for (i
= d
->wake_count
; i
< 0; i
++)
206 irq_set_irq_wake(d
->irq
, 0);
207 else if (d
->wake_count
> 0)
208 for (i
= 0; i
< d
->wake_count
; i
++)
209 irq_set_irq_wake(d
->irq
, 1);
213 mutex_unlock(&d
->lock
);
216 static void regmap_irq_enable(struct irq_data
*data
)
218 struct regmap_irq_chip_data
*d
= irq_data_get_irq_chip_data(data
);
219 struct regmap
*map
= d
->map
;
220 const struct regmap_irq
*irq_data
= irq_to_regmap_irq(d
, data
->hwirq
);
221 unsigned int mask
, type
;
223 type
= irq_data
->type
.type_falling_val
| irq_data
->type
.type_rising_val
;
226 * The type_in_mask flag means that the underlying hardware uses
227 * separate mask bits for rising and falling edge interrupts, but
228 * we want to make them into a single virtual interrupt with
231 * If the interrupt we're enabling defines the falling or rising
232 * masks then instead of using the regular mask bits for this
233 * interrupt, use the value previously written to the type buffer
234 * at the corresponding offset in regmap_irq_set_type().
236 if (d
->chip
->type_in_mask
&& type
)
237 mask
= d
->type_buf
[irq_data
->reg_offset
/ map
->reg_stride
];
239 mask
= irq_data
->mask
;
241 if (d
->chip
->clear_on_unmask
)
242 d
->clear_status
= true;
244 d
->mask_buf
[irq_data
->reg_offset
/ map
->reg_stride
] &= ~mask
;
247 static void regmap_irq_disable(struct irq_data
*data
)
249 struct regmap_irq_chip_data
*d
= irq_data_get_irq_chip_data(data
);
250 struct regmap
*map
= d
->map
;
251 const struct regmap_irq
*irq_data
= irq_to_regmap_irq(d
, data
->hwirq
);
253 d
->mask_buf
[irq_data
->reg_offset
/ map
->reg_stride
] |= irq_data
->mask
;
256 static int regmap_irq_set_type(struct irq_data
*data
, unsigned int type
)
258 struct regmap_irq_chip_data
*d
= irq_data_get_irq_chip_data(data
);
259 struct regmap
*map
= d
->map
;
260 const struct regmap_irq
*irq_data
= irq_to_regmap_irq(d
, data
->hwirq
);
262 const struct regmap_irq_type
*t
= &irq_data
->type
;
264 if ((t
->types_supported
& type
) != type
)
267 reg
= t
->type_reg_offset
/ map
->reg_stride
;
269 if (t
->type_reg_mask
)
270 d
->type_buf
[reg
] &= ~t
->type_reg_mask
;
272 d
->type_buf
[reg
] &= ~(t
->type_falling_val
|
274 t
->type_level_low_val
|
275 t
->type_level_high_val
);
277 case IRQ_TYPE_EDGE_FALLING
:
278 d
->type_buf
[reg
] |= t
->type_falling_val
;
281 case IRQ_TYPE_EDGE_RISING
:
282 d
->type_buf
[reg
] |= t
->type_rising_val
;
285 case IRQ_TYPE_EDGE_BOTH
:
286 d
->type_buf
[reg
] |= (t
->type_falling_val
|
290 case IRQ_TYPE_LEVEL_HIGH
:
291 d
->type_buf
[reg
] |= t
->type_level_high_val
;
294 case IRQ_TYPE_LEVEL_LOW
:
295 d
->type_buf
[reg
] |= t
->type_level_low_val
;
303 static int regmap_irq_set_wake(struct irq_data
*data
, unsigned int on
)
305 struct regmap_irq_chip_data
*d
= irq_data_get_irq_chip_data(data
);
306 struct regmap
*map
= d
->map
;
307 const struct regmap_irq
*irq_data
= irq_to_regmap_irq(d
, data
->hwirq
);
311 d
->wake_buf
[irq_data
->reg_offset
/ map
->reg_stride
]
316 d
->wake_buf
[irq_data
->reg_offset
/ map
->reg_stride
]
324 static const struct irq_chip regmap_irq_chip
= {
325 .irq_bus_lock
= regmap_irq_lock
,
326 .irq_bus_sync_unlock
= regmap_irq_sync_unlock
,
327 .irq_disable
= regmap_irq_disable
,
328 .irq_enable
= regmap_irq_enable
,
329 .irq_set_type
= regmap_irq_set_type
,
330 .irq_set_wake
= regmap_irq_set_wake
,
333 static inline int read_sub_irq_data(struct regmap_irq_chip_data
*data
,
336 const struct regmap_irq_chip
*chip
= data
->chip
;
337 struct regmap
*map
= data
->map
;
338 struct regmap_irq_sub_irq_map
*subreg
;
341 if (!chip
->sub_reg_offsets
) {
342 /* Assume linear mapping */
343 ret
= regmap_read(map
, chip
->status_base
+
344 (b
* map
->reg_stride
* data
->irq_reg_stride
),
345 &data
->status_buf
[b
]);
347 subreg
= &chip
->sub_reg_offsets
[b
];
348 for (i
= 0; i
< subreg
->num_regs
; i
++) {
349 unsigned int offset
= subreg
->offset
[i
];
351 ret
= regmap_read(map
, chip
->status_base
+ offset
,
352 &data
->status_buf
[offset
]);
360 static irqreturn_t
regmap_irq_thread(int irq
, void *d
)
362 struct regmap_irq_chip_data
*data
= d
;
363 const struct regmap_irq_chip
*chip
= data
->chip
;
364 struct regmap
*map
= data
->map
;
366 bool handled
= false;
369 if (chip
->handle_pre_irq
)
370 chip
->handle_pre_irq(chip
->irq_drv_data
);
372 if (chip
->runtime_pm
) {
373 ret
= pm_runtime_get_sync(map
->dev
);
375 dev_err(map
->dev
, "IRQ thread failed to resume: %d\n",
377 pm_runtime_put(map
->dev
);
383 * Read only registers with active IRQs if the chip has 'main status
384 * register'. Else read in the statuses, using a single bulk read if
385 * possible in order to reduce the I/O overheads.
388 if (chip
->num_main_regs
) {
389 unsigned int max_main_bits
;
392 size
= chip
->num_regs
* sizeof(unsigned int);
394 max_main_bits
= (chip
->num_main_status_bits
) ?
395 chip
->num_main_status_bits
: chip
->num_regs
;
396 /* Clear the status buf as we don't read all status regs */
397 memset(data
->status_buf
, 0, size
);
399 /* We could support bulk read for main status registers
400 * but I don't expect to see devices with really many main
401 * status registers so let's only support single reads for the
402 * sake of simplicity. and add bulk reads only if needed
404 for (i
= 0; i
< chip
->num_main_regs
; i
++) {
405 ret
= regmap_read(map
, chip
->main_status
+
407 * data
->irq_reg_stride
),
408 &data
->main_status_buf
[i
]);
411 "Failed to read IRQ status %d\n",
417 /* Read sub registers with active IRQs */
418 for (i
= 0; i
< chip
->num_main_regs
; i
++) {
420 const unsigned long mreg
= data
->main_status_buf
[i
];
422 for_each_set_bit(b
, &mreg
, map
->format
.val_bytes
* 8) {
423 if (i
* map
->format
.val_bytes
* 8 + b
>
426 ret
= read_sub_irq_data(data
, b
);
430 "Failed to read IRQ status %d\n",
432 if (chip
->runtime_pm
)
433 pm_runtime_put(map
->dev
);
439 } else if (!map
->use_single_read
&& map
->reg_stride
== 1 &&
440 data
->irq_reg_stride
== 1) {
442 u8
*buf8
= data
->status_reg_buf
;
443 u16
*buf16
= data
->status_reg_buf
;
444 u32
*buf32
= data
->status_reg_buf
;
446 BUG_ON(!data
->status_reg_buf
);
448 ret
= regmap_bulk_read(map
, chip
->status_base
,
449 data
->status_reg_buf
,
452 dev_err(map
->dev
, "Failed to read IRQ status: %d\n",
457 for (i
= 0; i
< data
->chip
->num_regs
; i
++) {
458 switch (map
->format
.val_bytes
) {
460 data
->status_buf
[i
] = buf8
[i
];
463 data
->status_buf
[i
] = buf16
[i
];
466 data
->status_buf
[i
] = buf32
[i
];
475 for (i
= 0; i
< data
->chip
->num_regs
; i
++) {
476 ret
= regmap_read(map
, chip
->status_base
+
478 * data
->irq_reg_stride
),
479 &data
->status_buf
[i
]);
483 "Failed to read IRQ status: %d\n",
485 if (chip
->runtime_pm
)
486 pm_runtime_put(map
->dev
);
493 * Ignore masked IRQs and ack if we need to; we ack early so
494 * there is no race between handling and acknowleding the
495 * interrupt. We assume that typically few of the interrupts
496 * will fire simultaneously so don't worry about overhead from
497 * doing a write per register.
499 for (i
= 0; i
< data
->chip
->num_regs
; i
++) {
500 data
->status_buf
[i
] &= ~data
->mask_buf
[i
];
502 if (data
->status_buf
[i
] && (chip
->ack_base
|| chip
->use_ack
)) {
503 reg
= chip
->ack_base
+
504 (i
* map
->reg_stride
* data
->irq_reg_stride
);
505 ret
= regmap_write(map
, reg
, data
->status_buf
[i
]);
507 dev_err(map
->dev
, "Failed to ack 0x%x: %d\n",
512 for (i
= 0; i
< chip
->num_irqs
; i
++) {
513 if (data
->status_buf
[chip
->irqs
[i
].reg_offset
/
514 map
->reg_stride
] & chip
->irqs
[i
].mask
) {
515 handle_nested_irq(irq_find_mapping(data
->domain
, i
));
520 if (chip
->runtime_pm
)
521 pm_runtime_put(map
->dev
);
524 if (chip
->handle_post_irq
)
525 chip
->handle_post_irq(chip
->irq_drv_data
);
533 static int regmap_irq_map(struct irq_domain
*h
, unsigned int virq
,
536 struct regmap_irq_chip_data
*data
= h
->host_data
;
538 irq_set_chip_data(virq
, data
);
539 irq_set_chip(virq
, &data
->irq_chip
);
540 irq_set_nested_thread(virq
, 1);
541 irq_set_parent(virq
, data
->irq
);
542 irq_set_noprobe(virq
);
547 static const struct irq_domain_ops regmap_domain_ops
= {
548 .map
= regmap_irq_map
,
549 .xlate
= irq_domain_xlate_onetwocell
,
553 * regmap_add_irq_chip() - Use standard regmap IRQ controller handling
555 * @map: The regmap for the device.
556 * @irq: The IRQ the device uses to signal interrupts.
557 * @irq_flags: The IRQF_ flags to use for the primary interrupt.
558 * @irq_base: Allocate at specific IRQ number if irq_base > 0.
559 * @chip: Configuration for the interrupt controller.
560 * @data: Runtime data structure for the controller, allocated on success.
562 * Returns 0 on success or an errno on failure.
564 * In order for this to be efficient the chip really should use a
565 * register cache. The chip driver is responsible for restoring the
566 * register values used by the IRQ controller over suspend and resume.
568 int regmap_add_irq_chip(struct regmap
*map
, int irq
, int irq_flags
,
569 int irq_base
, const struct regmap_irq_chip
*chip
,
570 struct regmap_irq_chip_data
**data
)
572 struct regmap_irq_chip_data
*d
;
579 if (chip
->num_regs
<= 0)
582 if (chip
->clear_on_unmask
&& (chip
->ack_base
|| chip
->use_ack
))
585 for (i
= 0; i
< chip
->num_irqs
; i
++) {
586 if (chip
->irqs
[i
].reg_offset
% map
->reg_stride
)
588 if (chip
->irqs
[i
].reg_offset
/ map
->reg_stride
>=
594 irq_base
= irq_alloc_descs(irq_base
, 0, chip
->num_irqs
, 0);
596 dev_warn(map
->dev
, "Failed to allocate IRQs: %d\n",
602 d
= kzalloc(sizeof(*d
), GFP_KERNEL
);
606 if (chip
->num_main_regs
) {
607 d
->main_status_buf
= kcalloc(chip
->num_main_regs
,
608 sizeof(unsigned int),
611 if (!d
->main_status_buf
)
615 d
->status_buf
= kcalloc(chip
->num_regs
, sizeof(unsigned int),
620 d
->mask_buf
= kcalloc(chip
->num_regs
, sizeof(unsigned int),
625 d
->mask_buf_def
= kcalloc(chip
->num_regs
, sizeof(unsigned int),
627 if (!d
->mask_buf_def
)
630 if (chip
->wake_base
) {
631 d
->wake_buf
= kcalloc(chip
->num_regs
, sizeof(unsigned int),
637 num_type_reg
= chip
->type_in_mask
? chip
->num_regs
: chip
->num_type_reg
;
639 d
->type_buf_def
= kcalloc(num_type_reg
,
640 sizeof(unsigned int), GFP_KERNEL
);
641 if (!d
->type_buf_def
)
644 d
->type_buf
= kcalloc(num_type_reg
, sizeof(unsigned int),
650 d
->irq_chip
= regmap_irq_chip
;
651 d
->irq_chip
.name
= chip
->name
;
655 d
->irq_base
= irq_base
;
657 if (chip
->irq_reg_stride
)
658 d
->irq_reg_stride
= chip
->irq_reg_stride
;
660 d
->irq_reg_stride
= 1;
662 if (chip
->type_reg_stride
)
663 d
->type_reg_stride
= chip
->type_reg_stride
;
665 d
->type_reg_stride
= 1;
667 if (!map
->use_single_read
&& map
->reg_stride
== 1 &&
668 d
->irq_reg_stride
== 1) {
669 d
->status_reg_buf
= kmalloc_array(chip
->num_regs
,
670 map
->format
.val_bytes
,
672 if (!d
->status_reg_buf
)
676 mutex_init(&d
->lock
);
678 for (i
= 0; i
< chip
->num_irqs
; i
++)
679 d
->mask_buf_def
[chip
->irqs
[i
].reg_offset
/ map
->reg_stride
]
680 |= chip
->irqs
[i
].mask
;
682 /* Mask all the interrupts by default */
683 for (i
= 0; i
< chip
->num_regs
; i
++) {
684 d
->mask_buf
[i
] = d
->mask_buf_def
[i
];
685 if (!chip
->mask_base
)
688 reg
= chip
->mask_base
+
689 (i
* map
->reg_stride
* d
->irq_reg_stride
);
690 if (chip
->mask_invert
)
691 ret
= regmap_irq_update_bits(d
, reg
,
692 d
->mask_buf
[i
], ~d
->mask_buf
[i
]);
693 else if (d
->chip
->unmask_base
) {
694 unmask_offset
= d
->chip
->unmask_base
-
696 ret
= regmap_irq_update_bits(d
,
701 ret
= regmap_irq_update_bits(d
, reg
,
702 d
->mask_buf
[i
], d
->mask_buf
[i
]);
704 dev_err(map
->dev
, "Failed to set masks in 0x%x: %d\n",
709 if (!chip
->init_ack_masked
)
712 /* Ack masked but set interrupts */
713 reg
= chip
->status_base
+
714 (i
* map
->reg_stride
* d
->irq_reg_stride
);
715 ret
= regmap_read(map
, reg
, &d
->status_buf
[i
]);
717 dev_err(map
->dev
, "Failed to read IRQ status: %d\n",
722 if (d
->status_buf
[i
] && (chip
->ack_base
|| chip
->use_ack
)) {
723 reg
= chip
->ack_base
+
724 (i
* map
->reg_stride
* d
->irq_reg_stride
);
725 if (chip
->ack_invert
)
726 ret
= regmap_write(map
, reg
,
727 ~(d
->status_buf
[i
] & d
->mask_buf
[i
]));
729 ret
= regmap_write(map
, reg
,
730 d
->status_buf
[i
] & d
->mask_buf
[i
]);
732 dev_err(map
->dev
, "Failed to ack 0x%x: %d\n",
739 /* Wake is disabled by default */
741 for (i
= 0; i
< chip
->num_regs
; i
++) {
742 d
->wake_buf
[i
] = d
->mask_buf_def
[i
];
743 reg
= chip
->wake_base
+
744 (i
* map
->reg_stride
* d
->irq_reg_stride
);
746 if (chip
->wake_invert
)
747 ret
= regmap_irq_update_bits(d
, reg
,
751 ret
= regmap_irq_update_bits(d
, reg
,
755 dev_err(map
->dev
, "Failed to set masks in 0x%x: %d\n",
762 if (chip
->num_type_reg
&& !chip
->type_in_mask
) {
763 for (i
= 0; i
< chip
->num_type_reg
; ++i
) {
764 if (!d
->type_buf_def
[i
])
767 reg
= chip
->type_base
+
768 (i
* map
->reg_stride
* d
->type_reg_stride
);
770 ret
= regmap_read(map
, reg
, &d
->type_buf_def
[i
]);
772 if (d
->chip
->type_invert
)
773 d
->type_buf_def
[i
] = ~d
->type_buf_def
[i
];
776 dev_err(map
->dev
, "Failed to get type defaults at 0x%x: %d\n",
784 d
->domain
= irq_domain_add_legacy(map
->dev
->of_node
,
785 chip
->num_irqs
, irq_base
, 0,
786 ®map_domain_ops
, d
);
788 d
->domain
= irq_domain_add_linear(map
->dev
->of_node
,
790 ®map_domain_ops
, d
);
792 dev_err(map
->dev
, "Failed to create IRQ domain\n");
797 ret
= request_threaded_irq(irq
, NULL
, regmap_irq_thread
,
798 irq_flags
| IRQF_ONESHOT
,
801 dev_err(map
->dev
, "Failed to request IRQ %d for %s: %d\n",
802 irq
, chip
->name
, ret
);
811 /* Should really dispose of the domain but... */
814 kfree(d
->type_buf_def
);
816 kfree(d
->mask_buf_def
);
818 kfree(d
->status_buf
);
819 kfree(d
->status_reg_buf
);
823 EXPORT_SYMBOL_GPL(regmap_add_irq_chip
);
826 * regmap_del_irq_chip() - Stop interrupt handling for a regmap IRQ chip
828 * @irq: Primary IRQ for the device
829 * @d: ®map_irq_chip_data allocated by regmap_add_irq_chip()
831 * This function also disposes of all mapped IRQs on the chip.
833 void regmap_del_irq_chip(int irq
, struct regmap_irq_chip_data
*d
)
843 /* Dispose all virtual irq from irq domain before removing it */
844 for (hwirq
= 0; hwirq
< d
->chip
->num_irqs
; hwirq
++) {
845 /* Ignore hwirq if holes in the IRQ list */
846 if (!d
->chip
->irqs
[hwirq
].mask
)
850 * Find the virtual irq of hwirq on chip and if it is
851 * there then dispose it
853 virq
= irq_find_mapping(d
->domain
, hwirq
);
855 irq_dispose_mapping(virq
);
858 irq_domain_remove(d
->domain
);
860 kfree(d
->type_buf_def
);
862 kfree(d
->mask_buf_def
);
864 kfree(d
->status_reg_buf
);
865 kfree(d
->status_buf
);
868 EXPORT_SYMBOL_GPL(regmap_del_irq_chip
);
870 static void devm_regmap_irq_chip_release(struct device
*dev
, void *res
)
872 struct regmap_irq_chip_data
*d
= *(struct regmap_irq_chip_data
**)res
;
874 regmap_del_irq_chip(d
->irq
, d
);
877 static int devm_regmap_irq_chip_match(struct device
*dev
, void *res
, void *data
)
880 struct regmap_irq_chip_data
**r
= res
;
890 * devm_regmap_add_irq_chip() - Resource manager regmap_add_irq_chip()
892 * @dev: The device pointer on which irq_chip belongs to.
893 * @map: The regmap for the device.
894 * @irq: The IRQ the device uses to signal interrupts
895 * @irq_flags: The IRQF_ flags to use for the primary interrupt.
896 * @irq_base: Allocate at specific IRQ number if irq_base > 0.
897 * @chip: Configuration for the interrupt controller.
898 * @data: Runtime data structure for the controller, allocated on success
900 * Returns 0 on success or an errno on failure.
902 * The ®map_irq_chip_data will be automatically released when the device is
905 int devm_regmap_add_irq_chip(struct device
*dev
, struct regmap
*map
, int irq
,
906 int irq_flags
, int irq_base
,
907 const struct regmap_irq_chip
*chip
,
908 struct regmap_irq_chip_data
**data
)
910 struct regmap_irq_chip_data
**ptr
, *d
;
913 ptr
= devres_alloc(devm_regmap_irq_chip_release
, sizeof(*ptr
),
918 ret
= regmap_add_irq_chip(map
, irq
, irq_flags
, irq_base
,
926 devres_add(dev
, ptr
);
930 EXPORT_SYMBOL_GPL(devm_regmap_add_irq_chip
);
933 * devm_regmap_del_irq_chip() - Resource managed regmap_del_irq_chip()
935 * @dev: Device for which which resource was allocated.
936 * @irq: Primary IRQ for the device.
937 * @data: ®map_irq_chip_data allocated by regmap_add_irq_chip().
939 * A resource managed version of regmap_del_irq_chip().
941 void devm_regmap_del_irq_chip(struct device
*dev
, int irq
,
942 struct regmap_irq_chip_data
*data
)
946 WARN_ON(irq
!= data
->irq
);
947 rc
= devres_release(dev
, devm_regmap_irq_chip_release
,
948 devm_regmap_irq_chip_match
, data
);
953 EXPORT_SYMBOL_GPL(devm_regmap_del_irq_chip
);
956 * regmap_irq_chip_get_base() - Retrieve interrupt base for a regmap IRQ chip
958 * @data: regmap irq controller to operate on.
960 * Useful for drivers to request their own IRQs.
962 int regmap_irq_chip_get_base(struct regmap_irq_chip_data
*data
)
964 WARN_ON(!data
->irq_base
);
965 return data
->irq_base
;
967 EXPORT_SYMBOL_GPL(regmap_irq_chip_get_base
);
970 * regmap_irq_get_virq() - Map an interrupt on a chip to a virtual IRQ
972 * @data: regmap irq controller to operate on.
973 * @irq: index of the interrupt requested in the chip IRQs.
975 * Useful for drivers to request their own IRQs.
977 int regmap_irq_get_virq(struct regmap_irq_chip_data
*data
, int irq
)
979 /* Handle holes in the IRQ list */
980 if (!data
->chip
->irqs
[irq
].mask
)
983 return irq_create_mapping(data
->domain
, irq
);
985 EXPORT_SYMBOL_GPL(regmap_irq_get_virq
);
988 * regmap_irq_get_domain() - Retrieve the irq_domain for the chip
990 * @data: regmap_irq controller to operate on.
992 * Useful for drivers to request their own IRQs and for integration
993 * with subsystems. For ease of integration NULL is accepted as a
994 * domain, allowing devices to just call this even if no domain is
997 struct irq_domain
*regmap_irq_get_domain(struct regmap_irq_chip_data
*data
)
1000 return data
->domain
;
1004 EXPORT_SYMBOL_GPL(regmap_irq_get_domain
);