2008-07-10 04:54:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: John Rigby, <jrigby@freescale.com>
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* MPC5121ADS CPLD irq handling
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
|
|
|
|
static struct device_node *cpld_pic_node;
|
2012-02-15 05:06:50 +08:00
|
|
|
static struct irq_domain *cpld_pic_host;
|
2008-07-10 04:54:04 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bits to ignore in the misc_status register
|
|
|
|
* 0x10 touch screen pendown is hard routed to irq1
|
|
|
|
* 0x02 pci status is read from pci status register
|
|
|
|
*/
|
|
|
|
#define MISC_IGNORE 0x12
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing to ignore in pci status register
|
|
|
|
*/
|
|
|
|
#define PCI_IGNORE 0x00
|
|
|
|
|
|
|
|
struct cpld_pic {
|
|
|
|
u8 pci_mask;
|
|
|
|
u8 pci_status;
|
|
|
|
u8 route;
|
|
|
|
u8 misc_mask;
|
|
|
|
u8 misc_status;
|
|
|
|
u8 misc_control;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct cpld_pic __iomem *cpld_regs;
|
|
|
|
|
|
|
|
static void __iomem *
|
|
|
|
irq_to_pic_mask(unsigned int irq)
|
|
|
|
{
|
|
|
|
return irq <= 7 ? &cpld_regs->pci_mask : &cpld_regs->misc_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
irq_to_pic_bit(unsigned int irq)
|
|
|
|
{
|
|
|
|
return 1 << (irq & 0x7);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 21:59:11 +08:00
|
|
|
cpld_mask_irq(struct irq_data *d)
|
2008-07-10 04:54:04 +08:00
|
|
|
{
|
2011-05-04 13:02:15 +08:00
|
|
|
unsigned int cpld_irq = (unsigned int)irqd_to_hwirq(d);
|
2008-07-10 04:54:04 +08:00
|
|
|
void __iomem *pic_mask = irq_to_pic_mask(cpld_irq);
|
|
|
|
|
|
|
|
out_8(pic_mask,
|
|
|
|
in_8(pic_mask) | irq_to_pic_bit(cpld_irq));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 21:59:11 +08:00
|
|
|
cpld_unmask_irq(struct irq_data *d)
|
2008-07-10 04:54:04 +08:00
|
|
|
{
|
2011-05-04 13:02:15 +08:00
|
|
|
unsigned int cpld_irq = (unsigned int)irqd_to_hwirq(d);
|
2008-07-10 04:54:04 +08:00
|
|
|
void __iomem *pic_mask = irq_to_pic_mask(cpld_irq);
|
|
|
|
|
|
|
|
out_8(pic_mask,
|
|
|
|
in_8(pic_mask) & ~irq_to_pic_bit(cpld_irq));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irq_chip cpld_pic = {
|
2010-02-01 04:33:41 +08:00
|
|
|
.name = "CPLD PIC",
|
2011-03-07 21:59:11 +08:00
|
|
|
.irq_mask = cpld_mask_irq,
|
|
|
|
.irq_ack = cpld_mask_irq,
|
|
|
|
.irq_unmask = cpld_unmask_irq,
|
2008-07-10 04:54:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpld_pic_get_irq(int offset, u8 ignore, u8 __iomem *statusp,
|
|
|
|
u8 __iomem *maskp)
|
|
|
|
{
|
|
|
|
int cpld_irq;
|
|
|
|
u8 status = in_8(statusp);
|
|
|
|
u8 mask = in_8(maskp);
|
|
|
|
|
|
|
|
/* ignore don't cares and masked irqs */
|
|
|
|
status |= (ignore | mask);
|
|
|
|
|
|
|
|
if (status == 0xff)
|
2016-09-06 19:53:24 +08:00
|
|
|
return 0;
|
2008-07-10 04:54:04 +08:00
|
|
|
|
|
|
|
cpld_irq = ffz(status) + offset;
|
|
|
|
|
|
|
|
return irq_linear_revmap(cpld_pic_host, cpld_irq);
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:42:37 +08:00
|
|
|
static void cpld_pic_cascade(struct irq_desc *desc)
|
2008-07-10 04:54:04 +08:00
|
|
|
{
|
2015-09-14 16:11:26 +08:00
|
|
|
unsigned int irq;
|
|
|
|
|
2008-07-10 04:54:04 +08:00
|
|
|
irq = cpld_pic_get_irq(0, PCI_IGNORE, &cpld_regs->pci_status,
|
|
|
|
&cpld_regs->pci_mask);
|
2016-09-06 19:53:24 +08:00
|
|
|
if (irq) {
|
2008-07-10 04:54:04 +08:00
|
|
|
generic_handle_irq(irq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
irq = cpld_pic_get_irq(8, MISC_IGNORE, &cpld_regs->misc_status,
|
|
|
|
&cpld_regs->misc_mask);
|
2016-09-06 19:53:24 +08:00
|
|
|
if (irq) {
|
2008-07-10 04:54:04 +08:00
|
|
|
generic_handle_irq(irq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
genirq/irqdomain: Allow irq domain aliasing
It is not uncommon (at least with the ARM stuff) to have a piece
of hardware that implements different flavours of "interrupts".
A typical example of this is the GICv3 ITS, which implements
standard PCI/MSI support, but also some form of "generic MSI".
So far, the PCI/MSI domain is registered using the ITS device_node,
so that irq_find_host can return it. On the contrary, the raw MSI
domain is not registered with an device_node, making it impossible
to be looked up by another subsystem (obviously, using the same
device_node twice would only result in confusion, as it is not
defined which one irq_find_host would return).
A solution to this is to "type" domains that may be aliasing, and
to be able to lookup an device_node that matches a given type.
For this, we introduce irq_find_matching_host() as a superset
of irq_find_host:
struct irq_domain *irq_find_matching_host(struct device_node *node,
enum irq_domain_bus_token bus_token);
where bus_token is the "type" we want to match the domain against
(so far, only DOMAIN_BUS_ANY is defined). This result in some
moderately invasive changes on the PPC side (which is the only
user of the .match method).
This has otherwise no functionnal change.
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: Yijing Wang <wangyijing@huawei.com>
Cc: Ma Jun <majun258@huawei.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Duc Dang <dhdang@apm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Jason Cooper <jason@lakedaemon.net>
Link: http://lkml.kernel.org/r/1438091186-10244-2-git-send-email-marc.zyngier@arm.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2015-07-28 21:46:08 +08:00
|
|
|
cpld_pic_host_match(struct irq_domain *h, struct device_node *node,
|
|
|
|
enum irq_domain_bus_token bus_token)
|
2008-07-10 04:54:04 +08:00
|
|
|
{
|
|
|
|
return cpld_pic_node == node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-02-15 05:06:50 +08:00
|
|
|
cpld_pic_host_map(struct irq_domain *h, unsigned int virq,
|
2008-07-10 04:54:04 +08:00
|
|
|
irq_hw_number_t hw)
|
|
|
|
{
|
2011-03-25 22:43:57 +08:00
|
|
|
irq_set_status_flags(virq, IRQ_LEVEL);
|
2011-03-25 23:45:20 +08:00
|
|
|
irq_set_chip_and_handler(virq, &cpld_pic, handle_level_irq);
|
2008-07-10 04:54:04 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-27 03:24:34 +08:00
|
|
|
static const struct irq_domain_ops cpld_pic_host_ops = {
|
2008-07-10 04:54:04 +08:00
|
|
|
.match = cpld_pic_host_match,
|
|
|
|
.map = cpld_pic_host_map,
|
|
|
|
};
|
|
|
|
|
|
|
|
void __init
|
|
|
|
mpc5121_ads_cpld_map(void)
|
|
|
|
{
|
|
|
|
struct device_node *np = NULL;
|
|
|
|
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121ads-cpld-pic");
|
|
|
|
if (!np) {
|
|
|
|
printk(KERN_ERR "CPLD PIC init: can not find cpld-pic node\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpld_regs = of_iomap(np, 0);
|
|
|
|
of_node_put(np);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init
|
|
|
|
mpc5121_ads_cpld_pic_init(void)
|
|
|
|
{
|
|
|
|
unsigned int cascade_irq;
|
|
|
|
struct device_node *np = NULL;
|
|
|
|
|
|
|
|
pr_debug("cpld_ic_init\n");
|
|
|
|
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121ads-cpld-pic");
|
|
|
|
if (!np) {
|
|
|
|
printk(KERN_ERR "CPLD PIC init: can not find cpld-pic node\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cpld_regs)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
cascade_irq = irq_of_parse_and_map(np, 0);
|
2016-09-06 19:53:24 +08:00
|
|
|
if (!cascade_irq)
|
2008-07-10 04:54:04 +08:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* statically route touch screen pendown through 1
|
|
|
|
* and ignore it here
|
|
|
|
* route all others through our cascade irq
|
|
|
|
*/
|
|
|
|
out_8(&cpld_regs->route, 0xfd);
|
|
|
|
out_8(&cpld_regs->pci_mask, 0xff);
|
|
|
|
/* unmask pci ints in misc mask */
|
|
|
|
out_8(&cpld_regs->misc_mask, ~(MISC_IGNORE));
|
|
|
|
|
|
|
|
cpld_pic_node = of_node_get(np);
|
|
|
|
|
2012-02-15 05:06:54 +08:00
|
|
|
cpld_pic_host = irq_domain_add_linear(np, 16, &cpld_pic_host_ops, NULL);
|
2008-07-10 04:54:04 +08:00
|
|
|
if (!cpld_pic_host) {
|
|
|
|
printk(KERN_ERR "CPLD PIC: failed to allocate irq host!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2011-03-25 23:45:20 +08:00
|
|
|
irq_set_chained_handler(cascade_irq, cpld_pic_cascade);
|
2008-07-10 04:54:04 +08:00
|
|
|
end:
|
|
|
|
of_node_put(np);
|
|
|
|
}
|