1aaf9128aSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
2da2014a2SPaul Mundt /*
3197b58e6SPaul Mundt * Hitachi UL SolutionEngine 7343 FPGA IRQ Support.
4da2014a2SPaul Mundt *
5da2014a2SPaul Mundt * Copyright (C) 2008 Yoshihiro Shimoda
6197b58e6SPaul Mundt * Copyright (C) 2012 Paul Mundt
7da2014a2SPaul Mundt *
8197b58e6SPaul Mundt * Based on linux/arch/sh/boards/se/7343/irq.c
9da2014a2SPaul Mundt * Copyright (C) 2007 Nobuhiro Iwamatsu
10da2014a2SPaul Mundt */
11197b58e6SPaul Mundt #define DRV_NAME "SE7343-FPGA"
12197b58e6SPaul Mundt #define pr_fmt(fmt) DRV_NAME ": " fmt
13197b58e6SPaul Mundt
14da2014a2SPaul Mundt #include <linux/init.h>
15da2014a2SPaul Mundt #include <linux/irq.h>
16da2014a2SPaul Mundt #include <linux/interrupt.h>
17197b58e6SPaul Mundt #include <linux/irqdomain.h>
18939a24a6SPaul Mundt #include <linux/io.h>
1987dfb311SMasahiro Yamada #include <linux/sizes.h>
20939a24a6SPaul Mundt #include <mach-se/mach/se7343.h>
21da2014a2SPaul Mundt
22197b58e6SPaul Mundt #define PA_CPLD_BASE_ADDR 0x11400000
23197b58e6SPaul Mundt #define PA_CPLD_ST_REG 0x08 /* CPLD Interrupt status register */
24197b58e6SPaul Mundt #define PA_CPLD_IMSK_REG 0x0a /* CPLD Interrupt mask register */
2553e6d8e0SPaul Mundt
26197b58e6SPaul Mundt static void __iomem *se7343_irq_regs;
27197b58e6SPaul Mundt struct irq_domain *se7343_irq_domain;
28da2014a2SPaul Mundt
se7343_irq_demux(struct irq_desc * desc)29bd0b9ac4SThomas Gleixner static void se7343_irq_demux(struct irq_desc *desc)
30da2014a2SPaul Mundt {
318228a048SJiang Liu struct irq_data *data = irq_desc_get_irq_data(desc);
32197b58e6SPaul Mundt struct irq_chip *chip = irq_data_get_irq_chip(data);
33197b58e6SPaul Mundt unsigned long mask;
34197b58e6SPaul Mundt int bit;
35da2014a2SPaul Mundt
36197b58e6SPaul Mundt chip->irq_mask_ack(data);
37da2014a2SPaul Mundt
38197b58e6SPaul Mundt mask = ioread16(se7343_irq_regs + PA_CPLD_ST_REG);
3953e6d8e0SPaul Mundt
40197b58e6SPaul Mundt for_each_set_bit(bit, &mask, SE7343_FPGA_IRQ_NR)
41*2e0e0ff4SMarc Zyngier generic_handle_domain_irq(se7343_irq_domain, bit);
42197b58e6SPaul Mundt
43197b58e6SPaul Mundt chip->irq_unmask(data);
44da2014a2SPaul Mundt }
45197b58e6SPaul Mundt
se7343_domain_init(void)46197b58e6SPaul Mundt static void __init se7343_domain_init(void)
47197b58e6SPaul Mundt {
48197b58e6SPaul Mundt int i;
49197b58e6SPaul Mundt
50197b58e6SPaul Mundt se7343_irq_domain = irq_domain_add_linear(NULL, SE7343_FPGA_IRQ_NR,
51197b58e6SPaul Mundt &irq_domain_simple_ops, NULL);
52197b58e6SPaul Mundt if (unlikely(!se7343_irq_domain)) {
53197b58e6SPaul Mundt printk("Failed to get IRQ domain\n");
54197b58e6SPaul Mundt return;
55197b58e6SPaul Mundt }
56197b58e6SPaul Mundt
57197b58e6SPaul Mundt for (i = 0; i < SE7343_FPGA_IRQ_NR; i++) {
58197b58e6SPaul Mundt int irq = irq_create_mapping(se7343_irq_domain, i);
59197b58e6SPaul Mundt
60197b58e6SPaul Mundt if (unlikely(irq == 0)) {
61197b58e6SPaul Mundt printk("Failed to allocate IRQ %d\n", i);
62197b58e6SPaul Mundt return;
63197b58e6SPaul Mundt }
64197b58e6SPaul Mundt }
65197b58e6SPaul Mundt }
66197b58e6SPaul Mundt
se7343_gc_init(void)67197b58e6SPaul Mundt static void __init se7343_gc_init(void)
68197b58e6SPaul Mundt {
69197b58e6SPaul Mundt struct irq_chip_generic *gc;
70197b58e6SPaul Mundt struct irq_chip_type *ct;
71197b58e6SPaul Mundt unsigned int irq_base;
72197b58e6SPaul Mundt
73197b58e6SPaul Mundt irq_base = irq_linear_revmap(se7343_irq_domain, 0);
74197b58e6SPaul Mundt
75197b58e6SPaul Mundt gc = irq_alloc_generic_chip(DRV_NAME, 1, irq_base, se7343_irq_regs,
76197b58e6SPaul Mundt handle_level_irq);
77197b58e6SPaul Mundt if (unlikely(!gc))
78197b58e6SPaul Mundt return;
79197b58e6SPaul Mundt
80197b58e6SPaul Mundt ct = gc->chip_types;
81197b58e6SPaul Mundt ct->chip.irq_mask = irq_gc_mask_set_bit;
82197b58e6SPaul Mundt ct->chip.irq_unmask = irq_gc_mask_clr_bit;
83197b58e6SPaul Mundt
84197b58e6SPaul Mundt ct->regs.mask = PA_CPLD_IMSK_REG;
85197b58e6SPaul Mundt
86197b58e6SPaul Mundt irq_setup_generic_chip(gc, IRQ_MSK(SE7343_FPGA_IRQ_NR),
87197b58e6SPaul Mundt IRQ_GC_INIT_MASK_CACHE,
88197b58e6SPaul Mundt IRQ_NOREQUEST | IRQ_NOPROBE, 0);
89197b58e6SPaul Mundt
90197b58e6SPaul Mundt irq_set_chained_handler(IRQ0_IRQ, se7343_irq_demux);
91197b58e6SPaul Mundt irq_set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
92197b58e6SPaul Mundt
93197b58e6SPaul Mundt irq_set_chained_handler(IRQ1_IRQ, se7343_irq_demux);
94197b58e6SPaul Mundt irq_set_irq_type(IRQ1_IRQ, IRQ_TYPE_LEVEL_LOW);
95197b58e6SPaul Mundt
96197b58e6SPaul Mundt irq_set_chained_handler(IRQ4_IRQ, se7343_irq_demux);
97197b58e6SPaul Mundt irq_set_irq_type(IRQ4_IRQ, IRQ_TYPE_LEVEL_LOW);
98197b58e6SPaul Mundt
99197b58e6SPaul Mundt irq_set_chained_handler(IRQ5_IRQ, se7343_irq_demux);
100197b58e6SPaul Mundt irq_set_irq_type(IRQ5_IRQ, IRQ_TYPE_LEVEL_LOW);
101da2014a2SPaul Mundt }
102da2014a2SPaul Mundt
103da2014a2SPaul Mundt /*
104da2014a2SPaul Mundt * Initialize IRQ setting
105da2014a2SPaul Mundt */
init_7343se_IRQ(void)106da2014a2SPaul Mundt void __init init_7343se_IRQ(void)
107da2014a2SPaul Mundt {
108197b58e6SPaul Mundt se7343_irq_regs = ioremap(PA_CPLD_BASE_ADDR, SZ_16);
109197b58e6SPaul Mundt if (unlikely(!se7343_irq_regs)) {
110197b58e6SPaul Mundt pr_err("Failed to remap CPLD\n");
11153e6d8e0SPaul Mundt return;
11253e6d8e0SPaul Mundt }
11353e6d8e0SPaul Mundt
114197b58e6SPaul Mundt /*
115197b58e6SPaul Mundt * All FPGA IRQs disabled by default
116197b58e6SPaul Mundt */
117197b58e6SPaul Mundt iowrite16(0, se7343_irq_regs + PA_CPLD_IMSK_REG);
118197b58e6SPaul Mundt
119197b58e6SPaul Mundt __raw_writew(0x2000, 0xb03fffec); /* mrshpc irq enable */
120197b58e6SPaul Mundt
121197b58e6SPaul Mundt se7343_domain_init();
122197b58e6SPaul Mundt se7343_gc_init();
123da2014a2SPaul Mundt }
124