in irq-ls1x.c [103:191]
static int __init ls1x_intc_of_init(struct device_node *node,
struct device_node *parent)
{
struct irq_chip_generic *gc;
struct irq_chip_type *ct;
struct ls1x_intc_priv *priv;
int parent_irq, err = 0;
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->intc_base = of_iomap(node, 0);
if (!priv->intc_base) {
err = -ENODEV;
goto out_free_priv;
}
parent_irq = irq_of_parse_and_map(node, 0);
if (!parent_irq) {
pr_err("ls1x-irq: unable to get parent irq\n");
err = -ENODEV;
goto out_iounmap;
}
/* Set up an IRQ domain */
priv->domain = irq_domain_add_linear(node, 32, &irq_generic_chip_ops,
NULL);
if (!priv->domain) {
pr_err("ls1x-irq: cannot add IRQ domain\n");
err = -ENOMEM;
goto out_iounmap;
}
err = irq_alloc_domain_generic_chips(priv->domain, 32, 2,
node->full_name, handle_level_irq,
IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN, 0,
IRQ_GC_INIT_MASK_CACHE);
if (err) {
pr_err("ls1x-irq: unable to register IRQ domain\n");
goto out_free_domain;
}
/* Mask all irqs */
writel(0x0, priv->intc_base + LS_REG_INTC_EN);
/* Ack all irqs */
writel(0xffffffff, priv->intc_base + LS_REG_INTC_CLR);
/* Set all irqs to high level triggered */
writel(0xffffffff, priv->intc_base + LS_REG_INTC_POL);
gc = irq_get_domain_generic_chip(priv->domain, 0);
gc->reg_base = priv->intc_base;
ct = gc->chip_types;
ct[0].type = IRQ_TYPE_LEVEL_MASK;
ct[0].regs.mask = LS_REG_INTC_EN;
ct[0].regs.ack = LS_REG_INTC_CLR;
ct[0].chip.irq_unmask = irq_gc_mask_set_bit;
ct[0].chip.irq_mask = irq_gc_mask_clr_bit;
ct[0].chip.irq_ack = irq_gc_ack_set_bit;
ct[0].chip.irq_set_type = ls_intc_set_type;
ct[0].handler = handle_level_irq;
ct[1].type = IRQ_TYPE_EDGE_BOTH;
ct[1].regs.mask = LS_REG_INTC_EN;
ct[1].regs.ack = LS_REG_INTC_CLR;
ct[1].chip.irq_unmask = irq_gc_mask_set_bit;
ct[1].chip.irq_mask = irq_gc_mask_clr_bit;
ct[1].chip.irq_ack = irq_gc_ack_set_bit;
ct[1].chip.irq_set_type = ls_intc_set_type;
ct[1].handler = handle_edge_irq;
irq_set_chained_handler_and_data(parent_irq,
ls1x_chained_handle_irq, priv);
return 0;
out_free_domain:
irq_domain_remove(priv->domain);
out_iounmap:
iounmap(priv->intc_base);
out_free_priv:
kfree(priv);
return err;
}