Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-sa1100/irq.c |
| 3 | * |
| 4 | * Copyright (C) 1999-2001 Nicolas Pitre |
| 5 | * |
| 6 | * Generic IRQ handling for the SA11x0, GPIO 11-27 IRQ demultiplexing. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
Thomas Gleixner | 119c641 | 2006-07-01 22:32:38 +0100 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
Russell King | 3169663 | 2012-06-06 11:42:36 +0100 | [diff] [blame] | 15 | #include <linux/io.h> |
Thomas Gleixner | 119c641 | 2006-07-01 22:32:38 +0100 | [diff] [blame] | 16 | #include <linux/irq.h> |
Dmitry Eremin-Solenikov | 1eca42b | 2014-11-28 15:56:54 +0100 | [diff] [blame] | 17 | #include <linux/irqdomain.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/ioport.h> |
Rafael J. Wysocki | 9053398 | 2011-04-22 22:03:03 +0200 | [diff] [blame] | 19 | #include <linux/syscore_ops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Dmitry Eremin-Solenikov | a657d7f | 2015-05-18 16:01:19 +0100 | [diff] [blame] | 21 | #include <soc/sa1100/pwer.h> |
| 22 | |
Rob Herring | f314f33 | 2012-02-24 00:06:51 +0100 | [diff] [blame] | 23 | #include <mach/irqs.h> |
Dmitry Eremin-Solenikov | affcab3 | 2014-11-28 15:55:16 +0100 | [diff] [blame] | 24 | #include <asm/exception.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "generic.h" |
| 27 | |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 28 | #define ICIP 0x00 /* IC IRQ Pending reg. */ |
| 29 | #define ICMR 0x04 /* IC Mask Reg. */ |
| 30 | #define ICLR 0x08 /* IC Level Reg. */ |
| 31 | #define ICCR 0x0C /* IC Control Reg. */ |
| 32 | #define ICFP 0x10 /* IC FIQ Pending reg. */ |
| 33 | #define ICPR 0x20 /* IC Pending Reg. */ |
| 34 | |
| 35 | static void __iomem *iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
Dmitry Eremin-Solenikov | ab71f99 | 2014-11-28 15:57:52 +0100 | [diff] [blame] | 38 | * We don't need to ACK IRQs on the SA1100 unless they're GPIOs |
| 39 | * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm. |
| 40 | */ |
| 41 | static void sa1100_mask_irq(struct irq_data *d) |
| 42 | { |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 43 | u32 reg; |
| 44 | |
| 45 | reg = readl_relaxed(iobase + ICMR); |
| 46 | reg &= ~BIT(d->hwirq); |
| 47 | writel_relaxed(reg, iobase + ICMR); |
Dmitry Eremin-Solenikov | ab71f99 | 2014-11-28 15:57:52 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void sa1100_unmask_irq(struct irq_data *d) |
| 51 | { |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 52 | u32 reg; |
| 53 | |
| 54 | reg = readl_relaxed(iobase + ICMR); |
| 55 | reg |= BIT(d->hwirq); |
| 56 | writel_relaxed(reg, iobase + ICMR); |
Dmitry Eremin-Solenikov | ab71f99 | 2014-11-28 15:57:52 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Dmitry Eremin-Solenikov | ab71f99 | 2014-11-28 15:57:52 +0100 | [diff] [blame] | 59 | static int sa1100_set_wake(struct irq_data *d, unsigned int on) |
| 60 | { |
Dmitry Eremin-Solenikov | a657d7f | 2015-05-18 16:01:19 +0100 | [diff] [blame] | 61 | return sa11x0_sc_set_wake(d->hwirq, on); |
Dmitry Eremin-Solenikov | ab71f99 | 2014-11-28 15:57:52 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static struct irq_chip sa1100_normal_chip = { |
| 65 | .name = "SC", |
| 66 | .irq_ack = sa1100_mask_irq, |
| 67 | .irq_mask = sa1100_mask_irq, |
| 68 | .irq_unmask = sa1100_unmask_irq, |
| 69 | .irq_set_wake = sa1100_set_wake, |
| 70 | }; |
| 71 | |
| 72 | static int sa1100_normal_irqdomain_map(struct irq_domain *d, |
| 73 | unsigned int irq, irq_hw_number_t hwirq) |
| 74 | { |
| 75 | irq_set_chip_and_handler(irq, &sa1100_normal_chip, |
| 76 | handle_level_irq); |
| 77 | set_irq_flags(irq, IRQF_VALID); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static struct irq_domain_ops sa1100_normal_irqdomain_ops = { |
| 83 | .map = sa1100_normal_irqdomain_map, |
| 84 | .xlate = irq_domain_xlate_onetwocell, |
| 85 | }; |
| 86 | |
| 87 | static struct irq_domain *sa1100_normal_irqdomain; |
| 88 | |
Russell King | a181099 | 2012-01-12 10:25:29 +0000 | [diff] [blame] | 89 | static struct resource irq_resource = |
| 90 | DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | static struct sa1100irq_state { |
| 93 | unsigned int saved; |
| 94 | unsigned int icmr; |
| 95 | unsigned int iclr; |
| 96 | unsigned int iccr; |
| 97 | } sa1100irq_state; |
| 98 | |
Rafael J. Wysocki | 9053398 | 2011-04-22 22:03:03 +0200 | [diff] [blame] | 99 | static int sa1100irq_suspend(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
| 101 | struct sa1100irq_state *st = &sa1100irq_state; |
| 102 | |
| 103 | st->saved = 1; |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 104 | st->icmr = readl_relaxed(iobase + ICMR); |
| 105 | st->iclr = readl_relaxed(iobase + ICLR); |
| 106 | st->iccr = readl_relaxed(iobase + ICCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * Disable all GPIO-based interrupts. |
| 110 | */ |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 111 | writel_relaxed(st->icmr & 0xfffff000, iobase + ICMR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Rafael J. Wysocki | 9053398 | 2011-04-22 22:03:03 +0200 | [diff] [blame] | 116 | static void sa1100irq_resume(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
| 118 | struct sa1100irq_state *st = &sa1100irq_state; |
| 119 | |
| 120 | if (st->saved) { |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 121 | writel_relaxed(st->iccr, iobase + ICCR); |
| 122 | writel_relaxed(st->iclr, iobase + ICLR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 124 | writel_relaxed(st->icmr, iobase + ICMR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Rafael J. Wysocki | 9053398 | 2011-04-22 22:03:03 +0200 | [diff] [blame] | 128 | static struct syscore_ops sa1100irq_syscore_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | .suspend = sa1100irq_suspend, |
| 130 | .resume = sa1100irq_resume, |
| 131 | }; |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static int __init sa1100irq_init_devicefs(void) |
| 134 | { |
Rafael J. Wysocki | 9053398 | 2011-04-22 22:03:03 +0200 | [diff] [blame] | 135 | register_syscore_ops(&sa1100irq_syscore_ops); |
| 136 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | device_initcall(sa1100irq_init_devicefs); |
| 140 | |
Dmitry Eremin-Solenikov | affcab3 | 2014-11-28 15:55:16 +0100 | [diff] [blame] | 141 | static asmlinkage void __exception_irq_entry |
| 142 | sa1100_handle_irq(struct pt_regs *regs) |
| 143 | { |
| 144 | uint32_t icip, icmr, mask; |
| 145 | |
| 146 | do { |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 147 | icip = readl_relaxed(iobase + ICIP); |
| 148 | icmr = readl_relaxed(iobase + ICMR); |
Dmitry Eremin-Solenikov | affcab3 | 2014-11-28 15:55:16 +0100 | [diff] [blame] | 149 | mask = icip & icmr; |
| 150 | |
| 151 | if (mask == 0) |
| 152 | break; |
| 153 | |
Dmitry Eremin-Solenikov | 364e386 | 2015-01-15 02:33:23 +0100 | [diff] [blame] | 154 | handle_domain_irq(sa1100_normal_irqdomain, |
| 155 | ffs(mask) - 1, regs); |
Dmitry Eremin-Solenikov | affcab3 | 2014-11-28 15:55:16 +0100 | [diff] [blame] | 156 | } while (1); |
| 157 | } |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | void __init sa1100_init_irq(void) |
| 160 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | request_resource(&iomem_resource, &irq_resource); |
| 162 | |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 163 | iobase = ioremap(irq_resource.start, SZ_64K); |
| 164 | if (WARN_ON(!iobase)) |
| 165 | return; |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* disable all IRQs */ |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 168 | writel_relaxed(0, iobase + ICMR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | /* all IRQs are IRQ, not FIQ */ |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 171 | writel_relaxed(0, iobase + ICLR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | /* |
| 174 | * Whatever the doc says, this has to be set for the wait-on-irq |
| 175 | * instruction to work... on a SA1100 rev 9 at least. |
| 176 | */ |
Dmitry Eremin-Solenikov | 60c06c4 | 2015-05-18 16:02:47 +0100 | [diff] [blame^] | 177 | writel_relaxed(1, iobase + ICCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Dmitry Eremin-Solenikov | a82be3f | 2015-01-15 02:31:48 +0100 | [diff] [blame] | 179 | sa1100_normal_irqdomain = irq_domain_add_simple(NULL, |
| 180 | 32, IRQ_GPIO0_SC, |
Dmitry Eremin-Solenikov | 8350809 | 2015-01-15 02:29:16 +0100 | [diff] [blame] | 181 | &sa1100_normal_irqdomain_ops, NULL); |
| 182 | |
Dmitry Eremin-Solenikov | affcab3 | 2014-11-28 15:55:16 +0100 | [diff] [blame] | 183 | set_handle_irq(sa1100_handle_irq); |
| 184 | |
Dmitry Baryshkov | 45528e3 | 2008-04-10 13:31:47 +0100 | [diff] [blame] | 185 | sa1100_init_gpio(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |