Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 1 | /* |
| 2 | * TI Common Platform Interrupt Controller (cp_intc) driver |
| 3 | * |
| 4 | * Author: Steve Chen <schen@mvista.com> |
| 5 | * Copyright (C) 2008-2009, MontaVista Software, Inc. <source@mvista.com> |
| 6 | * |
| 7 | * This file is licensed under the terms of the GNU General Public License |
| 8 | * version 2. This program is licensed "as is" without any warranty of any |
| 9 | * kind, whether express or implied. |
| 10 | */ |
| 11 | |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 12 | #include <linux/export.h> |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 13 | #include <linux/init.h> |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 14 | #include <linux/irq.h> |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 15 | #include <linux/irqdomain.h> |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 16 | #include <linux/io.h> |
| 17 | |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 18 | #include <mach/common.h> |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 19 | #include <mach/cp_intc.h> |
| 20 | |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 21 | static inline unsigned int cp_intc_read(unsigned offset) |
| 22 | { |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 23 | return __raw_readl(davinci_intc_base + offset); |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static inline void cp_intc_write(unsigned long value, unsigned offset) |
| 27 | { |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 28 | __raw_writel(value, davinci_intc_base + offset); |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 29 | } |
| 30 | |
Lennert Buytenhek | 2326544 | 2010-11-29 10:27:27 +0100 | [diff] [blame] | 31 | static void cp_intc_ack_irq(struct irq_data *d) |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 32 | { |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 33 | cp_intc_write(d->hwirq, CP_INTC_SYS_STAT_IDX_CLR); |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* Disable interrupt */ |
Lennert Buytenhek | 2326544 | 2010-11-29 10:27:27 +0100 | [diff] [blame] | 37 | static void cp_intc_mask_irq(struct irq_data *d) |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 38 | { |
| 39 | /* XXX don't know why we need to disable nIRQ here... */ |
| 40 | cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_CLR); |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 41 | cp_intc_write(d->hwirq, CP_INTC_SYS_ENABLE_IDX_CLR); |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 42 | cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET); |
| 43 | } |
| 44 | |
| 45 | /* Enable interrupt */ |
Lennert Buytenhek | 2326544 | 2010-11-29 10:27:27 +0100 | [diff] [blame] | 46 | static void cp_intc_unmask_irq(struct irq_data *d) |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 47 | { |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 48 | cp_intc_write(d->hwirq, CP_INTC_SYS_ENABLE_IDX_SET); |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 49 | } |
| 50 | |
Lennert Buytenhek | 2326544 | 2010-11-29 10:27:27 +0100 | [diff] [blame] | 51 | static int cp_intc_set_irq_type(struct irq_data *d, unsigned int flow_type) |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 52 | { |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 53 | unsigned reg = BIT_WORD(d->hwirq); |
| 54 | unsigned mask = BIT_MASK(d->hwirq); |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 55 | unsigned polarity = cp_intc_read(CP_INTC_SYS_POLARITY(reg)); |
| 56 | unsigned type = cp_intc_read(CP_INTC_SYS_TYPE(reg)); |
| 57 | |
| 58 | switch (flow_type) { |
| 59 | case IRQ_TYPE_EDGE_RISING: |
| 60 | polarity |= mask; |
| 61 | type |= mask; |
| 62 | break; |
| 63 | case IRQ_TYPE_EDGE_FALLING: |
| 64 | polarity &= ~mask; |
| 65 | type |= mask; |
| 66 | break; |
| 67 | case IRQ_TYPE_LEVEL_HIGH: |
| 68 | polarity |= mask; |
| 69 | type &= ~mask; |
| 70 | break; |
| 71 | case IRQ_TYPE_LEVEL_LOW: |
| 72 | polarity &= ~mask; |
| 73 | type &= ~mask; |
| 74 | break; |
| 75 | default: |
| 76 | return -EINVAL; |
| 77 | } |
| 78 | |
| 79 | cp_intc_write(polarity, CP_INTC_SYS_POLARITY(reg)); |
| 80 | cp_intc_write(type, CP_INTC_SYS_TYPE(reg)); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Sekhar Nori | 2d3f595 | 2009-11-16 17:21:30 +0530 | [diff] [blame] | 85 | /* |
| 86 | * Faking this allows us to to work with suspend functions of |
| 87 | * generic drivers which call {enable|disable}_irq_wake for |
| 88 | * wake up interrupt sources (eg RTC on DA850). |
| 89 | */ |
Lennert Buytenhek | 2326544 | 2010-11-29 10:27:27 +0100 | [diff] [blame] | 90 | static int cp_intc_set_wake(struct irq_data *d, unsigned int on) |
Sekhar Nori | 2d3f595 | 2009-11-16 17:21:30 +0530 | [diff] [blame] | 91 | { |
| 92 | return 0; |
| 93 | } |
| 94 | |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 95 | static struct irq_chip cp_intc_irq_chip = { |
| 96 | .name = "cp_intc", |
Lennert Buytenhek | 2326544 | 2010-11-29 10:27:27 +0100 | [diff] [blame] | 97 | .irq_ack = cp_intc_ack_irq, |
| 98 | .irq_mask = cp_intc_mask_irq, |
| 99 | .irq_unmask = cp_intc_unmask_irq, |
| 100 | .irq_set_type = cp_intc_set_irq_type, |
| 101 | .irq_set_wake = cp_intc_set_wake, |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 102 | }; |
| 103 | |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 104 | static struct irq_domain *cp_intc_domain; |
| 105 | |
| 106 | static int cp_intc_host_map(struct irq_domain *h, unsigned int virq, |
| 107 | irq_hw_number_t hw) |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 108 | { |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 109 | pr_debug("cp_intc_host_map(%d, 0x%lx)\n", virq, hw); |
| 110 | |
| 111 | irq_set_chip(virq, &cp_intc_irq_chip); |
| 112 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); |
| 113 | irq_set_handler(virq, handle_edge_irq); |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static const struct irq_domain_ops cp_intc_host_ops = { |
| 118 | .map = cp_intc_host_map, |
| 119 | .xlate = irq_domain_xlate_onetwocell, |
| 120 | }; |
| 121 | |
| 122 | int __init __cp_intc_init(struct device_node *node) |
| 123 | { |
| 124 | u32 num_irq = davinci_soc_info.intc_irq_num; |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 125 | u8 *irq_prio = davinci_soc_info.intc_irq_prios; |
| 126 | u32 *host_map = davinci_soc_info.intc_host_map; |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 127 | unsigned num_reg = BITS_TO_LONGS(num_irq); |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 128 | int i, irq_base; |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 129 | |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 130 | davinci_intc_type = DAVINCI_INTC_TYPE_CP_INTC; |
| 131 | davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_8K); |
| 132 | if (WARN_ON(!davinci_intc_base)) |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 133 | return -EINVAL; |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 134 | |
| 135 | cp_intc_write(0, CP_INTC_GLOBAL_ENABLE); |
| 136 | |
| 137 | /* Disable all host interrupts */ |
| 138 | cp_intc_write(0, CP_INTC_HOST_ENABLE(0)); |
| 139 | |
| 140 | /* Disable system interrupts */ |
| 141 | for (i = 0; i < num_reg; i++) |
| 142 | cp_intc_write(~0, CP_INTC_SYS_ENABLE_CLR(i)); |
| 143 | |
| 144 | /* Set to normal mode, no nesting, no priority hold */ |
| 145 | cp_intc_write(0, CP_INTC_CTRL); |
| 146 | cp_intc_write(0, CP_INTC_HOST_CTRL); |
| 147 | |
| 148 | /* Clear system interrupt status */ |
| 149 | for (i = 0; i < num_reg; i++) |
| 150 | cp_intc_write(~0, CP_INTC_SYS_STAT_CLR(i)); |
| 151 | |
| 152 | /* Enable nIRQ (what about nFIQ?) */ |
| 153 | cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET); |
| 154 | |
| 155 | /* |
| 156 | * Priority is determined by host channel: lower channel number has |
| 157 | * higher priority i.e. channel 0 has highest priority and channel 31 |
| 158 | * had the lowest priority. |
| 159 | */ |
| 160 | num_reg = (num_irq + 3) >> 2; /* 4 channels per register */ |
| 161 | if (irq_prio) { |
| 162 | unsigned j, k; |
| 163 | u32 val; |
| 164 | |
| 165 | for (k = i = 0; i < num_reg; i++) { |
| 166 | for (val = j = 0; j < 4; j++, k++) { |
| 167 | val >>= 8; |
| 168 | if (k < num_irq) |
| 169 | val |= irq_prio[k] << 24; |
| 170 | } |
| 171 | |
| 172 | cp_intc_write(val, CP_INTC_CHAN_MAP(i)); |
| 173 | } |
| 174 | } else { |
| 175 | /* |
| 176 | * Default everything to channel 15 if priority not specified. |
| 177 | * Note that channel 0-1 are mapped to nFIQ and channels 2-31 |
| 178 | * are mapped to nIRQ. |
| 179 | */ |
| 180 | for (i = 0; i < num_reg; i++) |
| 181 | cp_intc_write(0x0f0f0f0f, CP_INTC_CHAN_MAP(i)); |
| 182 | } |
| 183 | |
Cyril Chemparathy | 449ef7f | 2010-03-25 17:43:46 -0400 | [diff] [blame] | 184 | if (host_map) |
| 185 | for (i = 0; host_map[i] != -1; i++) |
| 186 | cp_intc_write(host_map[i], CP_INTC_HOST_MAP(i)); |
| 187 | |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 188 | irq_base = irq_alloc_descs(-1, 0, num_irq, 0); |
| 189 | if (irq_base < 0) { |
| 190 | pr_warn("Couldn't allocate IRQ numbers\n"); |
| 191 | irq_base = 0; |
| 192 | } |
| 193 | |
| 194 | /* create a legacy host */ |
| 195 | cp_intc_domain = irq_domain_add_legacy(node, num_irq, |
| 196 | irq_base, 0, &cp_intc_host_ops, NULL); |
| 197 | |
| 198 | if (!cp_intc_domain) { |
| 199 | pr_err("cp_intc: failed to allocate irq host!\n"); |
| 200 | return -EINVAL; |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /* Enable global interrupt */ |
| 204 | cp_intc_write(1, CP_INTC_GLOBAL_ENABLE); |
Heiko Schocher | 07caba9 | 2012-05-30 12:18:57 +0200 | [diff] [blame^] | 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | void __init cp_intc_init(void) |
| 210 | { |
| 211 | __cp_intc_init(NULL); |
Sergei Shtylyov | 0521444 | 2009-03-11 19:49:05 +0400 | [diff] [blame] | 212 | } |