mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

- Consolidate on one set of functions for the interrupt domain code to get rid of pointlessly duplicated code with only marginal different semantics. - Update the documentation accordingly and consolidate the coding style of the irqdomain header. -----BEGIN PGP SIGNATURE----- iQJHBAABCgAxFiEEQp8+kY+LLUocC4bMphj1TA10mKEFAmgzd+MTHHRnbHhAbGlu dXRyb25peC5kZQAKCRCmGPVMDXSYodTRD/0RmG5tngCbEJmTw6lPDQzRZH4OO3ja yRYlyBipemoRmvJRGjV4uHqN2QPrdOuoqMuyBO1aWcMdkpww5bAHcbgSFrlGM1lW kqtaxVMbufPiLQSGYe7OQf478CE1ykoBd5Va8whFKrtA73qEUdEMfWT0stspg780 7BlmQOemL91p7Ytf03FbDdo8tZ5Xu9uXGAulwY9FZsFtsCNyvhl7nOv5Sk8ZQtGO xHRCeunjZLWR+IaK59hdakvQybXwSnjT6jODp96nlyKABEKSPShGSPFDWd3g9px7 4911QwgnvTbcrsk6YmQEmPIOgXZzypjbnjpJr8tFpTbkVIy+6chi5cBJzXoqsUaM ylTwFcUQNvcP8yF447qb+nyPFKM5xsC07W0UpZMuJUDmhhPRtDm5pK0jpsif96GP l4aMsWe65PUmXHQqLdE89RJXAa8XQ2qspKVtNKq9DmEVgTviQ09Z9SSQIx4U0yIx w+YPde8kH2+O+YtMUn/MmfHhUP4MKya7j5zd8Bnv8wLBi7XGPPA5EKKh9I0dz9m+ X94lweNXyH+Q8U9mt2cQf8VG8Yzgk0eeC0sliJIlybwRgEgRcQbVWw0VvZUA1ySa VBlaj3SinO90FEQ0CctT51ss2mUJ/XsGCnxpiGZXfqIZzFbyD1YfZQnXJH0H67DI CqdHw22I27Mu/A== =9nLp -----END PGP SIGNATURE----- Merge tag 'irq-cleanups-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull irq cleanups from Thomas Gleixner: "A set of cleanups for the generic interrupt subsystem: - Consolidate on one set of functions for the interrupt domain code to get rid of pointlessly duplicated code with only marginal different semantics. - Update the documentation accordingly and consolidate the coding style of the irqdomain header" * tag 'irq-cleanups-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (46 commits) irqdomain: Consolidate coding style irqdomain: Fix kernel-doc and add it to Documentation Documentation: irqdomain: Update it Documentation: irq-domain.rst: Simple improvements Documentation: irq/concepts: Minor improvements Documentation: irq/concepts: Add commas and reflow irqdomain: Improve kernel-docs of functions irqdomain: Make struct irq_domain_info variables const irqdomain: Use irq_domain_instantiate()'s return value as initializers irqdomain: Drop irq_linear_revmap() pinctrl: keembay: Switch to irq_find_mapping() irqchip/armada-370-xp: Switch to irq_find_mapping() gpu: ipu-v3: Switch to irq_find_mapping() gpio: idt3243x: Switch to irq_find_mapping() sh: Switch to irq_find_mapping() powerpc: Switch to irq_find_mapping() irqdomain: Drop irq_domain_add_*() functions powerpc: Switch irq_domain_add_nomap() to use fwnode thermal: Switch to irq_domain_create_linear() soc: Switch to irq_domain_create_*() ...
183 lines
5 KiB
C
183 lines
5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* JZ47xx SoCs TCU IRQ driver
|
|
* Copyright (C) 2019 Paul Cercueil <paul@crapouillou.net>
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/irqchip.h>
|
|
#include <linux/irqchip/chained_irq.h>
|
|
#include <linux/mfd/ingenic-tcu.h>
|
|
#include <linux/mfd/syscon.h>
|
|
#include <linux/of_irq.h>
|
|
#include <linux/regmap.h>
|
|
|
|
struct ingenic_tcu {
|
|
struct regmap *map;
|
|
struct clk *clk;
|
|
struct irq_domain *domain;
|
|
unsigned int nb_parent_irqs;
|
|
u32 parent_irqs[3];
|
|
};
|
|
|
|
static void ingenic_tcu_intc_cascade(struct irq_desc *desc)
|
|
{
|
|
struct irq_chip *irq_chip = irq_data_get_irq_chip(&desc->irq_data);
|
|
struct irq_domain *domain = irq_desc_get_handler_data(desc);
|
|
struct irq_chip_generic *gc = irq_get_domain_generic_chip(domain, 0);
|
|
struct regmap *map = gc->private;
|
|
uint32_t irq_reg, irq_mask;
|
|
unsigned long bits;
|
|
unsigned int i;
|
|
|
|
regmap_read(map, TCU_REG_TFR, &irq_reg);
|
|
regmap_read(map, TCU_REG_TMR, &irq_mask);
|
|
|
|
chained_irq_enter(irq_chip, desc);
|
|
|
|
irq_reg &= ~irq_mask;
|
|
bits = irq_reg;
|
|
|
|
for_each_set_bit(i, &bits, 32)
|
|
generic_handle_domain_irq(domain, i);
|
|
|
|
chained_irq_exit(irq_chip, desc);
|
|
}
|
|
|
|
static void ingenic_tcu_gc_unmask_enable_reg(struct irq_data *d)
|
|
{
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
|
struct irq_chip_type *ct = irq_data_get_chip_type(d);
|
|
struct regmap *map = gc->private;
|
|
u32 mask = d->mask;
|
|
|
|
guard(raw_spinlock)(&gc->lock);
|
|
regmap_write(map, ct->regs.ack, mask);
|
|
regmap_write(map, ct->regs.enable, mask);
|
|
*ct->mask_cache |= mask;
|
|
}
|
|
|
|
static void ingenic_tcu_gc_mask_disable_reg(struct irq_data *d)
|
|
{
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
|
struct irq_chip_type *ct = irq_data_get_chip_type(d);
|
|
struct regmap *map = gc->private;
|
|
u32 mask = d->mask;
|
|
|
|
guard(raw_spinlock)(&gc->lock);
|
|
regmap_write(map, ct->regs.disable, mask);
|
|
*ct->mask_cache &= ~mask;
|
|
}
|
|
|
|
static void ingenic_tcu_gc_mask_disable_reg_and_ack(struct irq_data *d)
|
|
{
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
|
struct irq_chip_type *ct = irq_data_get_chip_type(d);
|
|
struct regmap *map = gc->private;
|
|
u32 mask = d->mask;
|
|
|
|
guard(raw_spinlock)(&gc->lock);
|
|
regmap_write(map, ct->regs.ack, mask);
|
|
regmap_write(map, ct->regs.disable, mask);
|
|
}
|
|
|
|
static int __init ingenic_tcu_irq_init(struct device_node *np,
|
|
struct device_node *parent)
|
|
{
|
|
struct irq_chip_generic *gc;
|
|
struct irq_chip_type *ct;
|
|
struct ingenic_tcu *tcu;
|
|
struct regmap *map;
|
|
unsigned int i;
|
|
int ret, irqs;
|
|
|
|
map = device_node_to_regmap(np);
|
|
if (IS_ERR(map))
|
|
return PTR_ERR(map);
|
|
|
|
tcu = kzalloc(sizeof(*tcu), GFP_KERNEL);
|
|
if (!tcu)
|
|
return -ENOMEM;
|
|
|
|
tcu->map = map;
|
|
|
|
irqs = of_property_count_elems_of_size(np, "interrupts", sizeof(u32));
|
|
if (irqs < 0 || irqs > ARRAY_SIZE(tcu->parent_irqs)) {
|
|
pr_crit("%s: Invalid 'interrupts' property\n", __func__);
|
|
ret = -EINVAL;
|
|
goto err_free_tcu;
|
|
}
|
|
|
|
tcu->nb_parent_irqs = irqs;
|
|
|
|
tcu->domain = irq_domain_create_linear(of_fwnode_handle(np), 32, &irq_generic_chip_ops,
|
|
NULL);
|
|
if (!tcu->domain) {
|
|
ret = -ENOMEM;
|
|
goto err_free_tcu;
|
|
}
|
|
|
|
ret = irq_alloc_domain_generic_chips(tcu->domain, 32, 1, "TCU",
|
|
handle_level_irq, 0,
|
|
IRQ_NOPROBE | IRQ_LEVEL, 0);
|
|
if (ret) {
|
|
pr_crit("%s: Invalid 'interrupts' property\n", __func__);
|
|
goto out_domain_remove;
|
|
}
|
|
|
|
gc = irq_get_domain_generic_chip(tcu->domain, 0);
|
|
ct = gc->chip_types;
|
|
|
|
gc->wake_enabled = IRQ_MSK(32);
|
|
gc->private = tcu->map;
|
|
|
|
ct->regs.disable = TCU_REG_TMSR;
|
|
ct->regs.enable = TCU_REG_TMCR;
|
|
ct->regs.ack = TCU_REG_TFCR;
|
|
ct->chip.irq_unmask = ingenic_tcu_gc_unmask_enable_reg;
|
|
ct->chip.irq_mask = ingenic_tcu_gc_mask_disable_reg;
|
|
ct->chip.irq_mask_ack = ingenic_tcu_gc_mask_disable_reg_and_ack;
|
|
ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_SKIP_SET_WAKE;
|
|
|
|
/* Mask all IRQs by default */
|
|
regmap_write(tcu->map, TCU_REG_TMSR, IRQ_MSK(32));
|
|
|
|
/*
|
|
* On JZ4740, timer 0 and timer 1 have their own interrupt line;
|
|
* timers 2-7 share one interrupt.
|
|
* On SoCs >= JZ4770, timer 5 has its own interrupt line;
|
|
* timers 0-4 and 6-7 share one single interrupt.
|
|
*
|
|
* To keep things simple, we just register the same handler to
|
|
* all parent interrupts. The handler will properly detect which
|
|
* channel fired the interrupt.
|
|
*/
|
|
for (i = 0; i < irqs; i++) {
|
|
tcu->parent_irqs[i] = irq_of_parse_and_map(np, i);
|
|
if (!tcu->parent_irqs[i]) {
|
|
ret = -EINVAL;
|
|
goto out_unmap_irqs;
|
|
}
|
|
|
|
irq_set_chained_handler_and_data(tcu->parent_irqs[i],
|
|
ingenic_tcu_intc_cascade,
|
|
tcu->domain);
|
|
}
|
|
|
|
return 0;
|
|
|
|
out_unmap_irqs:
|
|
for (; i > 0; i--)
|
|
irq_dispose_mapping(tcu->parent_irqs[i - 1]);
|
|
out_domain_remove:
|
|
irq_domain_remove(tcu->domain);
|
|
err_free_tcu:
|
|
kfree(tcu);
|
|
return ret;
|
|
}
|
|
IRQCHIP_DECLARE(jz4740_tcu_irq, "ingenic,jz4740-tcu", ingenic_tcu_irq_init);
|
|
IRQCHIP_DECLARE(jz4725b_tcu_irq, "ingenic,jz4725b-tcu", ingenic_tcu_irq_init);
|
|
IRQCHIP_DECLARE(jz4760_tcu_irq, "ingenic,jz4760-tcu", ingenic_tcu_irq_init);
|
|
IRQCHIP_DECLARE(jz4770_tcu_irq, "ingenic,jz4770-tcu", ingenic_tcu_irq_init);
|
|
IRQCHIP_DECLARE(x1000_tcu_irq, "ingenic,x1000-tcu", ingenic_tcu_irq_init);
|