irqchip/ls1x-cpu: Move the CPU IRQ driver from arch/mips/loongson32/common/
Subsystems (3)
PATCH RESEND v4 6/9 irqchip/ls1x-cpu: Move the CPU IRQ driver from arch/mips/loongson32/common/
--- arch/mips/include/asm/irq_cpu.h | 1 + arch/mips/loongson32/common/irq.c | 128 +------------------- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-ls1x-cpu.c | 242 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 127 deletions(-) create mode 100644 drivers/irqchip/irq-ls1x-cpu.c
arch/mips/include/asm/irq_cpu.h +1 -0
@@ -16,6 +16,7 @@extern void mips_cpu_irq_init (void );extern void rm7k_cpu_irq_init (void );extern void rm9k_cpu_irq_init (void ); +extern void ls1x_cpu_irq_init (void );#ifdef CONFIG_IRQ_DOMAIN struct device_node ;
arch/mips/loongson32/common/irq.c +1 -127
135 lines not on this page · raw message
drivers/irqchip/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_ATH79) += irq-ath79-cpu.o obj-$(CONFIG_ATH79) += irq-ath79-misc.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2836.o +obj-$(CONFIG_MACH_LOONGSON32) += irq-ls1x-cpu.o obj-$(CONFIG_ARCH_EXYNOS) += exynos-combiner.o obj-$(CONFIG_ARCH_HIP04) += irq-hip04.o obj-$(CONFIG_ARCH_MMP) += irq-mmp.o
drivers/irqchip/irq-ls1x-cpu.c new file +242 -0
242 lines not on this page · raw message
Signature · 1 line
1.9.1
Hi folks!
On Thu, May 19, 2016 at 09:44:17AM +0800, Binbin Zhou wrote:
Commit message?
Quoted 11 lines
Signed-off-by Chunbo Cui <[email protected]>Signed-off-by Binbin Zhou <[email protected]>Signed-off-by Huacai Chen <[email protected]>--- arch/mips/include/asm/irq_cpu.h | 1 + arch/mips/loongson32/common/irq.c | 128 +------------------- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-ls1x-cpu.c | 242 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 127 deletions(-) create mode 100644 drivers/irqchip/irq-ls1x-cpu.c
...
drivers/irqchip/Makefile obj-$(CONFIG_ATH79) += irq-ath79-cpu.o · line 11
Quoted 12 lines
drivers/irqchip/Makefile +1
-0@@ -5,6 +5,7 @@ obj-$(CONFIG_ATH79) += irq-ath79-cpu.o obj-$(CONFIG_ATH79) += irq-ath79-misc.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2836.o +obj-$(CONFIG_MACH_LOONGSON32) += irq-ls1x-cpu.o obj-$(CONFIG_ARCH_EXYNOS) += exynos-combiner.o obj-$(CONFIG_ARCH_HIP04) += irq-hip04.o obj-$(CONFIG_ARCH_MMP) += irq-mmp.o
This is a gentle reminder to myself to fix this file up at the end of the merge window. It's making me twitch.
Quoted 6 lines
drivers/irqchip/irq-ls1x-cpu.c new file +0
-0
drivers/irqchip/irq-ls1x-cpu.c line 8
Quoted 8 lines
drivers/irqchip/irq-ls1x-cpu.c new file +8
-0@@ -0,0 +1,242 @@ +/* +* Copyright (c) 2011 Zhang, Keguang <[email protected]> +* Copyright (c) 2016 Binbin Zhou <[email protected]> +* +* This program 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.
nit: paragraph needs to be reflowed.
Quoted 18 lines
drivers/irqchip/irq-ls1x-cpu.c new file +18
-0+*/ + +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqdomain.h> +#include <asm/irq_cpu.h> + +#include <loongson1.h> +#include <irq.h> + +#define LS1X_INTC_REG (n, x) \ + ((void __iomem *)KSEG1ADDR(LS1X_INT_REG_BASE + (n * 0x18) + (x))) + +#define LS1X_INTC_INTISR (n) LS1X_INTC_REG(n, 0x0) +#define LS1X_INTC_INTIEN (n) LS1X_INTC_REG(n, 0x4) +#define LS1X_INTC_INTSET (n) LS1X_INTC_REG(n, 0x8) +#define LS1X_INTC_INTCLR (n) LS1X_INTC_REG(n, 0xc)
drivers/irqchip/irq-ls1x-cpu.c line 36
Quoted 10 lines
drivers/irqchip/irq-ls1x-cpu.c new file +10
-0+#define LS1X_INTC_INTPOL (n) LS1X_INTC_REG(n, 0x10) +#define LS1X_INTC_INTEDGE (n) LS1X_INTC_REG(n, 0x14) + +static void ls1x_irq_ack (struct irq_data *d) +{ +unsigned int bit = (d->irq -LS1X_IRQ_BASE ) &0x1f ; +unsigned int n = (d->irq -LS1X_IRQ_BASE ) >>5 ; + +ls1x_writel (ls1x_readl (LS1X_INTC_INTCLR (n)) + | (1 << bit),LS1X_INTC_INTCLR (n));
Why can't we use the standard functions?
drivers/irqchip/irq-ls1x-cpu.c line 45
Quoted 9 lines
drivers/irqchip/irq-ls1x-cpu.c new file +9
-0+} + +static void ls1x_irq_mask (struct irq_data *d) +{ +unsigned int bit = (d->irq -LS1X_IRQ_BASE ) &0x1f ; +unsigned int n = (d->irq -LS1X_IRQ_BASE ) >>5 ; + +ls1x_writel (ls1x_readl (LS1X_INTC_INTIEN (n)) + & ~(1 << bit),LS1X_INTC_INTIEN (n));
With this, and all the statements similar to it below, we do the same calculations (LS1X_INTC_XXXXXX(n)) twice. The compiler can't optimize it because it doesn't know n ahead of time. Let's just calculate it once:
void __iomem *addr = LS1X_INTC_INTIEN((d->irq - LS1X_IRQ_BASE) >> 5); xwrite(xread(addr) & ~(1 << bit), addr);
where x{write,read}() is whatever we conclude is appropriate for this driver.
Quoted 59 lines
drivers/irqchip/irq-ls1x-cpu.c new file +59
-0+} + +static void ls1x_irq_mask_ack (struct irq_data *d) +{ +unsigned int bit = (d->irq -LS1X_IRQ_BASE ) &0x1f ; +unsigned int n = (d->irq -LS1X_IRQ_BASE ) >>5 ; + +ls1x_writel (ls1x_readl (LS1X_INTC_INTIEN (n)) + & ~(1 << bit),LS1X_INTC_INTIEN (n)); +ls1x_writel (ls1x_readl (LS1X_INTC_INTCLR (n)) + | (1 << bit),LS1X_INTC_INTCLR (n)); +} + +static void ls1x_irq_unmask (struct irq_data *d) +{ +unsigned int bit = (d->irq -LS1X_IRQ_BASE ) &0x1f ; +unsigned int n = (d->irq -LS1X_IRQ_BASE ) >>5 ; + +ls1x_writel (ls1x_readl (LS1X_INTC_INTIEN (n)) + | (1 << bit),LS1X_INTC_INTIEN (n)); +} + +static void ls1x_irq_edge_type (struct irq_data *data,unsigned int flow_type) +{ +unsigned int bit = (data->irq -LS1X_IRQ_BASE ) &0x1f ; +unsigned int n = (data->irq -LS1X_IRQ_BASE ) >>5 ; + +if (flow_type &IRQ_TYPE_EDGE_RISING ) +ls1x_writel (ls1x_readl (LS1X_INTC_INTPOL (n)) | (1 << bit), +LS1X_INTC_INTPOL (n)); +else +ls1x_writel (ls1x_readl (LS1X_INTC_INTPOL (n)) & ~(1 << bit), +LS1X_INTC_INTPOL (n)); + +ls1x_writel (ls1x_readl (LS1X_INTC_INTEDGE (n)) | (1 << bit), +LS1X_INTC_INTEDGE (n)); +ls1x_writel (ls1x_readl (LS1X_INTC_INTIEN (n)) | (1 << bit), +LS1X_INTC_INTIEN (n)); + +irq_set_handler_locked (data, handle_edge_irq); +} + +static void ls1x_irq_level_type (struct irq_data *data,unsigned int flow_type) +{ +unsigned int bit = (data->irq -LS1X_IRQ_BASE ) &0x1f ; +unsigned int n = (data->irq -LS1X_IRQ_BASE ) >>5 ; + +if (flow_type &IRQ_TYPE_LEVEL_HIGH ) +ls1x_writel (ls1x_readl (LS1X_INTC_INTPOL (n)) | (1 << bit), +LS1X_INTC_INTPOL (n)); +else if (flow_type &IRQ_TYPE_LEVEL_LOW ) +ls1x_writel (ls1x_readl (LS1X_INTC_INTPOL (n)) & ~(1 << bit), +LS1X_INTC_INTPOL (n)); + +ls1x_writel (ls1x_readl (LS1X_INTC_INTEDGE (n)) & ~(1 << bit), +LS1X_INTC_INTEDGE (n)); +ls1x_writel (ls1x_readl (LS1X_INTC_INTIEN (n)) | (1 << bit), +LS1X_INTC_INTIEN (n)); +
drivers/irqchip/irq-ls1x-cpu.c line 114
Quoted 10 lines
drivers/irqchip/irq-ls1x-cpu.c new file +10
-0+irq_set_handler_locked (data, handle_level_irq); +} + +static int ls1x_irq_set_type (struct irq_data *data,unsigned int flow_type) +{ +unsigned int bit = (data->irq -LS1X_IRQ_BASE ) &0x1f ; +unsigned int n = (data->irq -LS1X_IRQ_BASE ) >>5 ; + +if ((flow_type &IRQ_TYPE_EDGE_BOTH ) ==IRQ_TYPE_EDGE_BOTH ) { +pr_info ("ls1x irq don't support both rising and falling\n" );
Under what conditions have you encountered this? Badly written devicetree? driver?
Quoted 99 lines
drivers/irqchip/irq-ls1x-cpu.c new file +99
-0+return -1 ; + } + +ls1x_writel (ls1x_readl (LS1X_INTC_INTCLR (n)) | (1 << bit), +LS1X_INTC_INTCLR (n)); + +if (flow_type &IRQ_TYPE_EDGE_BOTH ) +ls1x_irq_edge_type (data, flow_type); +else if (flow_type &&IRQ_TYPE_LEVEL_MASK ) +ls1x_irq_level_type (data, flow_type); + +return IRQ_SET_MASK_OK ; +} + +static struct irq_chip ls1x_cpu_irq_chip = { + .name ="LS1X-INTC" , + .irq_ack = ls1x_irq_ack, + .irq_mask = ls1x_irq_mask, + .irq_mask_ack = ls1x_irq_mask_ack, + .irq_unmask = ls1x_irq_unmask, + .irq_set_type = ls1x_irq_set_type, +}; + +static void ls1x_irq_dispatch (int n) +{ +u32 int_status, irq; + +/* Get pending sources, masked by current enables */ + int_status =ls1x_readl (LS1X_INTC_INTISR (n)) & +ls1x_readl (LS1X_INTC_INTIEN (n)); + +if (int_status) { + irq =LS1X_IRQ (n,__ffs (int_status)); +do_IRQ (irq); + } +} + +asmlinkage void plat_irq_dispatch(void) +{ +unsigned int pending; + + pending =read_c0_cause () &read_c0_status () &ST0_IM ; + +if (pending &CAUSEF_IP7 ) +do_IRQ (TIMER_IRQ ); +else if (pending &CAUSEF_IP2 ) +ls1x_irq_dispatch (0 );/* INT0 */ +else if (pending &CAUSEF_IP3 ) +ls1x_irq_dispatch (1 );/* INT1 */ +else if (pending &CAUSEF_IP4 ) +ls1x_irq_dispatch (2 );/* INT2 */ +else if (pending &CAUSEF_IP5 ) +ls1x_irq_dispatch (3 );/* INT3 */ +else if (pending &CAUSEF_IP6 ) +ls1x_irq_dispatch (4 );/* INT4 */ +else +spurious_interrupt (); + +} + +struct irqaction cascade_irqaction = { + .handler = no_action, + .name ="cascade" , + .flags =IRQF_NO_THREAD , +}; + +static int ls1x_cpu_intc_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hw) +{ +int n; + +/* +* Disable interrupts and clear pending, +* setup all IRQs as high level triggered +*/ +for (n =0 ; n <4 ; n++) { +ls1x_writel (0x0 ,LS1X_INTC_INTIEN (n)); +ls1x_writel (0xffffffff ,LS1X_INTC_INTCLR (n)); +ls1x_writel (0xffffffff ,LS1X_INTC_INTPOL (n)); +/* set DMA0, DMA1 and DMA2 to edge trigger */ +ls1x_writel (n ?0x0 :0xe000 ,LS1X_INTC_INTEDGE (n)); + } + + +for (n =LS1X_IRQ_BASE ; n <LS1X_IRQS ; n++) { +irq_set_chip_and_handler (n, &ls1x_cpu_irq_chip, + handle_level_irq); + } + +setup_irq (INT0_IRQ , &cascade_irqaction); +setup_irq (INT1_IRQ , &cascade_irqaction); +setup_irq (INT2_IRQ , &cascade_irqaction); +setup_irq (INT3_IRQ , &cascade_irqaction); +setup_irq (INT4_IRQ , &cascade_irqaction); + +return 0 ; +} + +static const struct irq_domain_ops ls1x_cpu_intc_domain_ops = {
drivers/irqchip/irq-ls1x-cpu.c line 223
Quoted 10 lines
drivers/irqchip/irq-ls1x-cpu.c new file +10
-0+ .map = ls1x_cpu_intc_map, + .xlate = irq_domain_xlate_onecell, +}; + +static void __init __ls1x_irq_init (struct device_node *of_node) +{ +struct irq_domain *domain; + + domain =irq_domain_add_legacy (of_node,LS1X_IRQS ,LS1X_IRQ_BASE ,0 , + &ls1x_cpu_intc_domain_ops,NULL );
Please take a look at using _simple() or _linear().
Quoted 21 lines
drivers/irqchip/irq-ls1x-cpu.c new file +19
-0+if (!domain) +panic ("Failed to add irqdomain for MIPS CPU" ); +} + +void __init ls1x_cpu_irq_init (void ) +{ +__ls1x_irq_init (NULL ); +} + +static int __init ls1x_cpu_irq_of_init ( +struct device_node *node,struct device_node *parent) + +{ +__ls1x_irq_init (node); +return 0 ; +} + +IRQCHIP_DECLARE (ls1x_cpu_intc,"loongson-1A cpu-irq-intc" , + ls1x_cpu_irq_of_init);Signature · 1 line
1.9.1
thx,
Jason.