2010-07-17 11:08:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
|
|
|
|
* JZ4740 platform IRQ support
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
2013-01-22 11:59:30 +00:00
|
|
|
* under the terms of the GNU General Public License as published by the
|
2010-07-17 11:08:43 +00:00
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
2015-05-24 15:11:21 +00:00
|
|
|
#include <linux/of_irq.h>
|
2010-07-17 11:08:43 +00:00
|
|
|
#include <linux/timex.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#include <asm/mach-jz4740/base.h>
|
2014-12-18 02:39:01 +00:00
|
|
|
#include <asm/mach-jz4740/irq.h>
|
|
|
|
|
|
|
|
#include "irq.h"
|
2010-07-17 11:08:43 +00:00
|
|
|
|
2015-05-24 15:11:21 +00:00
|
|
|
#include "../../drivers/irqchip/irqchip.h"
|
|
|
|
|
2015-05-24 15:11:25 +00:00
|
|
|
struct ingenic_intc_data {
|
|
|
|
void __iomem *base;
|
|
|
|
};
|
2010-07-17 11:08:43 +00:00
|
|
|
|
|
|
|
#define JZ_REG_INTC_STATUS 0x00
|
|
|
|
#define JZ_REG_INTC_MASK 0x04
|
|
|
|
#define JZ_REG_INTC_SET_MASK 0x08
|
|
|
|
#define JZ_REG_INTC_CLEAR_MASK 0x0c
|
|
|
|
#define JZ_REG_INTC_PENDING 0x10
|
|
|
|
|
2011-09-24 00:29:46 +00:00
|
|
|
static irqreturn_t jz4740_cascade(int irq, void *data)
|
2010-07-17 11:08:43 +00:00
|
|
|
{
|
2015-05-24 15:11:25 +00:00
|
|
|
struct ingenic_intc_data *intc = irq_get_handler_data(irq);
|
2011-09-24 00:29:46 +00:00
|
|
|
uint32_t irq_reg;
|
2010-07-17 11:08:43 +00:00
|
|
|
|
2015-05-24 15:11:25 +00:00
|
|
|
irq_reg = readl(intc->base + JZ_REG_INTC_PENDING);
|
2010-07-17 11:08:43 +00:00
|
|
|
|
2011-09-24 00:29:46 +00:00
|
|
|
if (irq_reg)
|
|
|
|
generic_handle_irq(__fls(irq_reg) + JZ4740_IRQ_BASE);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
2011-03-23 21:08:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-24 00:29:46 +00:00
|
|
|
static void jz4740_irq_set_mask(struct irq_chip_generic *gc, uint32_t mask)
|
2010-07-17 11:08:43 +00:00
|
|
|
{
|
2011-09-24 00:29:46 +00:00
|
|
|
struct irq_chip_regs *regs = &gc->chip_types->regs;
|
2010-07-17 11:08:43 +00:00
|
|
|
|
2011-09-24 00:29:46 +00:00
|
|
|
writel(mask, gc->reg_base + regs->enable);
|
|
|
|
writel(~mask, gc->reg_base + regs->disable);
|
2010-07-17 11:08:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-24 00:29:46 +00:00
|
|
|
void jz4740_irq_suspend(struct irq_data *data)
|
2010-07-17 11:08:43 +00:00
|
|
|
{
|
2011-09-24 00:29:46 +00:00
|
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
|
|
|
|
jz4740_irq_set_mask(gc, gc->wake_active);
|
|
|
|
}
|
2010-07-17 11:08:43 +00:00
|
|
|
|
2011-09-24 00:29:46 +00:00
|
|
|
void jz4740_irq_resume(struct irq_data *data)
|
|
|
|
{
|
|
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
|
|
|
|
jz4740_irq_set_mask(gc, gc->mask_cache);
|
2010-07-17 11:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct irqaction jz4740_cascade_action = {
|
|
|
|
.handler = jz4740_cascade,
|
|
|
|
.name = "JZ4740 cascade interrupt",
|
|
|
|
};
|
|
|
|
|
2015-05-24 15:11:21 +00:00
|
|
|
static int __init jz4740_intc_of_init(struct device_node *node,
|
|
|
|
struct device_node *parent)
|
2010-07-17 11:08:43 +00:00
|
|
|
{
|
2015-05-24 15:11:25 +00:00
|
|
|
struct ingenic_intc_data *intc;
|
2011-09-24 00:29:46 +00:00
|
|
|
struct irq_chip_generic *gc;
|
|
|
|
struct irq_chip_type *ct;
|
2015-05-24 15:11:23 +00:00
|
|
|
struct irq_domain *domain;
|
2015-05-24 15:11:25 +00:00
|
|
|
int parent_irq, err = 0;
|
|
|
|
|
|
|
|
intc = kzalloc(sizeof(*intc), GFP_KERNEL);
|
|
|
|
if (!intc) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2015-05-24 15:11:22 +00:00
|
|
|
|
|
|
|
parent_irq = irq_of_parse_and_map(node, 0);
|
2015-05-24 15:11:25 +00:00
|
|
|
if (!parent_irq) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
2011-09-24 00:29:46 +00:00
|
|
|
|
2015-05-24 15:11:25 +00:00
|
|
|
err = irq_set_handler_data(parent_irq, intc);
|
|
|
|
if (err)
|
|
|
|
goto out_unmap_irq;
|
|
|
|
|
|
|
|
intc->base = ioremap(JZ4740_INTC_BASE_ADDR, 0x14);
|
2010-07-17 11:08:43 +00:00
|
|
|
|
2011-03-23 21:08:53 +00:00
|
|
|
/* Mask all irqs */
|
2015-05-24 15:11:25 +00:00
|
|
|
writel(0xffffffff, intc->base + JZ_REG_INTC_SET_MASK);
|
2011-03-23 21:08:53 +00:00
|
|
|
|
2015-05-24 15:11:25 +00:00
|
|
|
gc = irq_alloc_generic_chip("INTC", 1, JZ4740_IRQ_BASE, intc->base,
|
2011-09-24 00:29:46 +00:00
|
|
|
handle_level_irq);
|
|
|
|
|
|
|
|
gc->wake_enabled = IRQ_MSK(32);
|
|
|
|
|
|
|
|
ct = gc->chip_types;
|
|
|
|
ct->regs.enable = JZ_REG_INTC_CLEAR_MASK;
|
|
|
|
ct->regs.disable = JZ_REG_INTC_SET_MASK;
|
|
|
|
ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
|
|
|
|
ct->chip.irq_mask = irq_gc_mask_disable_reg;
|
|
|
|
ct->chip.irq_mask_ack = irq_gc_mask_disable_reg;
|
|
|
|
ct->chip.irq_set_wake = irq_gc_set_wake;
|
|
|
|
ct->chip.irq_suspend = jz4740_irq_suspend;
|
|
|
|
ct->chip.irq_resume = jz4740_irq_resume;
|
|
|
|
|
|
|
|
irq_setup_generic_chip(gc, IRQ_MSK(32), 0, 0, IRQ_NOPROBE | IRQ_LEVEL);
|
2010-07-17 11:08:43 +00:00
|
|
|
|
2015-05-24 15:11:23 +00:00
|
|
|
domain = irq_domain_add_legacy(node, num_chips * 32, JZ4740_IRQ_BASE, 0,
|
|
|
|
&irq_domain_simple_ops, NULL);
|
|
|
|
if (!domain)
|
|
|
|
pr_warn("unable to register IRQ domain\n");
|
|
|
|
|
2015-05-24 15:11:22 +00:00
|
|
|
setup_irq(parent_irq, &jz4740_cascade_action);
|
2015-05-24 15:11:21 +00:00
|
|
|
return 0;
|
2015-05-24 15:11:25 +00:00
|
|
|
|
|
|
|
out_unmap_irq:
|
|
|
|
irq_dispose_mapping(parent_irq);
|
|
|
|
out_free:
|
|
|
|
kfree(intc);
|
|
|
|
out_err:
|
|
|
|
return err;
|
2010-07-17 11:08:43 +00:00
|
|
|
}
|
2015-05-24 15:11:21 +00:00
|
|
|
IRQCHIP_DECLARE(jz4740_intc, "ingenic,jz4740-intc", jz4740_intc_of_init);
|