0001
0002
0003
0004
0005
0006 #include <linux/interrupt.h>
0007 #include <linux/module.h>
0008 #include <linux/of.h>
0009 #include <linux/irqdomain.h>
0010 #include <linux/irqchip.h>
0011 #include <asm/irq.h>
0012
0013 #define NR_EXCEPTIONS 16
0014
0015 struct bcr_irq_arcv2 {
0016 #ifdef CONFIG_CPU_BIG_ENDIAN
0017 unsigned int pad:3, firq:1, prio:4, exts:8, irqs:8, ver:8;
0018 #else
0019 unsigned int ver:8, irqs:8, exts:8, prio:4, firq:1, pad:3;
0020 #endif
0021 };
0022
0023
0024
0025
0026
0027
0028
0029 void arc_init_IRQ(void)
0030 {
0031 unsigned int tmp, irq_prio, i;
0032 struct bcr_irq_arcv2 irq_bcr;
0033
0034 struct aux_irq_ctrl {
0035 #ifdef CONFIG_CPU_BIG_ENDIAN
0036 unsigned int res3:18, save_idx_regs:1, res2:1,
0037 save_u_to_u:1, save_lp_regs:1, save_blink:1,
0038 res:4, save_nr_gpr_pairs:5;
0039 #else
0040 unsigned int save_nr_gpr_pairs:5, res:4,
0041 save_blink:1, save_lp_regs:1, save_u_to_u:1,
0042 res2:1, save_idx_regs:1, res3:18;
0043 #endif
0044 } ictrl;
0045
0046 *(unsigned int *)&ictrl = 0;
0047
0048 #ifndef CONFIG_ARC_IRQ_NO_AUTOSAVE
0049 ictrl.save_nr_gpr_pairs = 6;
0050 ictrl.save_blink = 1;
0051 ictrl.save_lp_regs = 1;
0052 ictrl.save_u_to_u = 0;
0053 ictrl.save_idx_regs = 1;
0054 #endif
0055
0056 WRITE_AUX(AUX_IRQ_CTRL, ictrl);
0057
0058
0059
0060
0061
0062
0063
0064
0065 READ_BCR(ARC_REG_IRQ_BCR, irq_bcr);
0066
0067 irq_prio = irq_bcr.prio;
0068 pr_info("archs-intc\t: %d priority levels (default %d)%s\n",
0069 irq_prio + 1, ARCV2_IRQ_DEF_PRIO,
0070 irq_bcr.firq ? " FIRQ (not used)":"");
0071
0072
0073
0074
0075
0076
0077
0078
0079 for (i = NR_EXCEPTIONS; i < irq_bcr.irqs + NR_EXCEPTIONS; i++) {
0080 write_aux_reg(AUX_IRQ_SELECT, i);
0081 write_aux_reg(AUX_IRQ_PRIORITY, ARCV2_IRQ_DEF_PRIO);
0082
0083
0084
0085
0086
0087
0088 if (i < FIRST_EXT_IRQ)
0089 write_aux_reg(AUX_IRQ_ENABLE, 0);
0090 }
0091
0092
0093 tmp = read_aux_reg(ARC_REG_STATUS32);
0094 tmp |= ARCV2_IRQ_DEF_PRIO << 1;
0095 tmp &= ~STATUS_IE_MASK;
0096 asm volatile("kflag %0 \n"::"r"(tmp));
0097 }
0098
0099 static void arcv2_irq_mask(struct irq_data *data)
0100 {
0101 write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
0102 write_aux_reg(AUX_IRQ_ENABLE, 0);
0103 }
0104
0105 static void arcv2_irq_unmask(struct irq_data *data)
0106 {
0107 write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
0108 write_aux_reg(AUX_IRQ_ENABLE, 1);
0109 }
0110
0111 void arcv2_irq_enable(struct irq_data *data)
0112 {
0113
0114 write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
0115 write_aux_reg(AUX_IRQ_PRIORITY, ARCV2_IRQ_DEF_PRIO);
0116
0117
0118
0119
0120
0121
0122 write_aux_reg(AUX_IRQ_ENABLE, 1);
0123 }
0124
0125 static struct irq_chip arcv2_irq_chip = {
0126 .name = "ARCv2 core Intc",
0127 .irq_mask = arcv2_irq_mask,
0128 .irq_unmask = arcv2_irq_unmask,
0129 .irq_enable = arcv2_irq_enable
0130 };
0131
0132 static int arcv2_irq_map(struct irq_domain *d, unsigned int irq,
0133 irq_hw_number_t hw)
0134 {
0135
0136
0137
0138
0139 if (hw < FIRST_EXT_IRQ) {
0140
0141
0142
0143
0144
0145 irq_set_percpu_devid(irq);
0146 irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_percpu_irq);
0147 } else {
0148 irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_level_irq);
0149 }
0150
0151 return 0;
0152 }
0153
0154 static const struct irq_domain_ops arcv2_irq_ops = {
0155 .xlate = irq_domain_xlate_onecell,
0156 .map = arcv2_irq_map,
0157 };
0158
0159
0160 static int __init
0161 init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
0162 {
0163 struct irq_domain *root_domain;
0164 struct bcr_irq_arcv2 irq_bcr;
0165 unsigned int nr_cpu_irqs;
0166
0167 READ_BCR(ARC_REG_IRQ_BCR, irq_bcr);
0168 nr_cpu_irqs = irq_bcr.irqs + NR_EXCEPTIONS;
0169
0170 if (parent)
0171 panic("DeviceTree incore intc not a root irq controller\n");
0172
0173 root_domain = irq_domain_add_linear(intc, nr_cpu_irqs, &arcv2_irq_ops, NULL);
0174 if (!root_domain)
0175 panic("root irq domain not avail\n");
0176
0177
0178
0179
0180
0181 irq_set_default_host(root_domain);
0182
0183 #ifdef CONFIG_SMP
0184 irq_create_mapping(root_domain, IPI_IRQ);
0185 #endif
0186 irq_create_mapping(root_domain, SOFTIRQ_IRQ);
0187
0188 return 0;
0189 }
0190
0191 IRQCHIP_DECLARE(arc_intc, "snps,archs-intc", init_onchip_IRQ);