Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Uwe Zeisberger | f30c226 | 2006-10-03 23:01:26 +0200 | [diff] [blame] | 2 | * linux/arch/arm/common/sa1111.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * SA1111 support |
| 5 | * |
| 6 | * Original code by John Dorsey |
| 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 | * This file contains all generic SA1111 support. |
| 13 | * |
| 14 | * All initialization functions provided here are intended to be called |
| 15 | * from machine specific code with proper arguments when required. |
| 16 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/errno.h> |
| 22 | #include <linux/ioport.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/slab.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/dma-mapping.h> |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 27 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 30 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/mach-types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/irq.h> |
| 33 | #include <asm/mach/irq.h> |
Russell King | 45e109d | 2005-11-16 18:29:51 +0000 | [diff] [blame] | 34 | #include <asm/sizes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <asm/hardware/sa1111.h> |
| 37 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 38 | /* SA1111 IRQs */ |
| 39 | #define IRQ_GPAIN0 (0) |
| 40 | #define IRQ_GPAIN1 (1) |
| 41 | #define IRQ_GPAIN2 (2) |
| 42 | #define IRQ_GPAIN3 (3) |
| 43 | #define IRQ_GPBIN0 (4) |
| 44 | #define IRQ_GPBIN1 (5) |
| 45 | #define IRQ_GPBIN2 (6) |
| 46 | #define IRQ_GPBIN3 (7) |
| 47 | #define IRQ_GPBIN4 (8) |
| 48 | #define IRQ_GPBIN5 (9) |
| 49 | #define IRQ_GPCIN0 (10) |
| 50 | #define IRQ_GPCIN1 (11) |
| 51 | #define IRQ_GPCIN2 (12) |
| 52 | #define IRQ_GPCIN3 (13) |
| 53 | #define IRQ_GPCIN4 (14) |
| 54 | #define IRQ_GPCIN5 (15) |
| 55 | #define IRQ_GPCIN6 (16) |
| 56 | #define IRQ_GPCIN7 (17) |
| 57 | #define IRQ_MSTXINT (18) |
| 58 | #define IRQ_MSRXINT (19) |
| 59 | #define IRQ_MSSTOPERRINT (20) |
| 60 | #define IRQ_TPTXINT (21) |
| 61 | #define IRQ_TPRXINT (22) |
| 62 | #define IRQ_TPSTOPERRINT (23) |
| 63 | #define SSPXMTINT (24) |
| 64 | #define SSPRCVINT (25) |
| 65 | #define SSPROR (26) |
| 66 | #define AUDXMTDMADONEA (32) |
| 67 | #define AUDRCVDMADONEA (33) |
| 68 | #define AUDXMTDMADONEB (34) |
| 69 | #define AUDRCVDMADONEB (35) |
| 70 | #define AUDTFSR (36) |
| 71 | #define AUDRFSR (37) |
| 72 | #define AUDTUR (38) |
| 73 | #define AUDROR (39) |
| 74 | #define AUDDTS (40) |
| 75 | #define AUDRDD (41) |
| 76 | #define AUDSTO (42) |
| 77 | #define IRQ_USBPWR (43) |
| 78 | #define IRQ_HCIM (44) |
| 79 | #define IRQ_HCIBUFFACC (45) |
| 80 | #define IRQ_HCIRMTWKP (46) |
| 81 | #define IRQ_NHCIMFCIR (47) |
| 82 | #define IRQ_USB_PORT_RESUME (48) |
| 83 | #define IRQ_S0_READY_NINT (49) |
| 84 | #define IRQ_S1_READY_NINT (50) |
| 85 | #define IRQ_S0_CD_VALID (51) |
| 86 | #define IRQ_S1_CD_VALID (52) |
| 87 | #define IRQ_S0_BVD1_STSCHG (53) |
| 88 | #define IRQ_S1_BVD1_STSCHG (54) |
| 89 | |
Russell King | 29c140b | 2012-02-03 19:03:31 +0000 | [diff] [blame^] | 90 | extern void sa1110_mb_enable(void); |
| 91 | extern void sa1110_mb_disable(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * We keep the following data for the overall SA1111. Note that the |
| 95 | * struct device and struct resource are "fake"; they should be supplied |
| 96 | * by the bus above us. However, in the interests of getting all SA1111 |
| 97 | * drivers converted over to the device model, we provide this as an |
| 98 | * anchor point for all the other drivers. |
| 99 | */ |
| 100 | struct sa1111 { |
| 101 | struct device *dev; |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 102 | struct clk *clk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | unsigned long phys; |
| 104 | int irq; |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 105 | int irq_base; /* base for cascaded on-chip IRQs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | spinlock_t lock; |
| 107 | void __iomem *base; |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 108 | #ifdef CONFIG_PM |
| 109 | void *saved_state; |
| 110 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /* |
| 114 | * We _really_ need to eliminate this. Its only users |
| 115 | * are the PWM and DMA checking code. |
| 116 | */ |
| 117 | static struct sa1111 *g_sa1111; |
| 118 | |
| 119 | struct sa1111_dev_info { |
| 120 | unsigned long offset; |
| 121 | unsigned long skpcr_mask; |
| 122 | unsigned int devid; |
| 123 | unsigned int irq[6]; |
| 124 | }; |
| 125 | |
| 126 | static struct sa1111_dev_info sa1111_devices[] = { |
| 127 | { |
| 128 | .offset = SA1111_USB, |
| 129 | .skpcr_mask = SKPCR_UCLKEN, |
| 130 | .devid = SA1111_DEVID_USB, |
| 131 | .irq = { |
| 132 | IRQ_USBPWR, |
| 133 | IRQ_HCIM, |
| 134 | IRQ_HCIBUFFACC, |
| 135 | IRQ_HCIRMTWKP, |
| 136 | IRQ_NHCIMFCIR, |
| 137 | IRQ_USB_PORT_RESUME |
| 138 | }, |
| 139 | }, |
| 140 | { |
| 141 | .offset = 0x0600, |
| 142 | .skpcr_mask = SKPCR_I2SCLKEN | SKPCR_L3CLKEN, |
| 143 | .devid = SA1111_DEVID_SAC, |
| 144 | .irq = { |
| 145 | AUDXMTDMADONEA, |
| 146 | AUDXMTDMADONEB, |
| 147 | AUDRCVDMADONEA, |
| 148 | AUDRCVDMADONEB |
| 149 | }, |
| 150 | }, |
| 151 | { |
| 152 | .offset = 0x0800, |
| 153 | .skpcr_mask = SKPCR_SCLKEN, |
| 154 | .devid = SA1111_DEVID_SSP, |
| 155 | }, |
| 156 | { |
| 157 | .offset = SA1111_KBD, |
| 158 | .skpcr_mask = SKPCR_PTCLKEN, |
| 159 | .devid = SA1111_DEVID_PS2, |
| 160 | .irq = { |
| 161 | IRQ_TPRXINT, |
| 162 | IRQ_TPTXINT |
| 163 | }, |
| 164 | }, |
| 165 | { |
| 166 | .offset = SA1111_MSE, |
| 167 | .skpcr_mask = SKPCR_PMCLKEN, |
| 168 | .devid = SA1111_DEVID_PS2, |
| 169 | .irq = { |
| 170 | IRQ_MSRXINT, |
| 171 | IRQ_MSTXINT |
| 172 | }, |
| 173 | }, |
| 174 | { |
| 175 | .offset = 0x1800, |
| 176 | .skpcr_mask = 0, |
| 177 | .devid = SA1111_DEVID_PCMCIA, |
| 178 | .irq = { |
| 179 | IRQ_S0_READY_NINT, |
| 180 | IRQ_S0_CD_VALID, |
| 181 | IRQ_S0_BVD1_STSCHG, |
| 182 | IRQ_S1_READY_NINT, |
| 183 | IRQ_S1_CD_VALID, |
| 184 | IRQ_S1_BVD1_STSCHG, |
| 185 | }, |
| 186 | }, |
| 187 | }; |
| 188 | |
| 189 | /* |
| 190 | * SA1111 interrupt support. Since clearing an IRQ while there are |
| 191 | * active IRQs causes the interrupt output to pulse, the upper levels |
| 192 | * will call us again if there are more interrupts to process. |
| 193 | */ |
| 194 | static void |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 195 | sa1111_irq_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | unsigned int stat0, stat1, i; |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 198 | struct sa1111 *sachip = irq_get_handler_data(irq); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 199 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 201 | stat0 = sa1111_readl(mapbase + SA1111_INTSTATCLR0); |
| 202 | stat1 = sa1111_readl(mapbase + SA1111_INTSTATCLR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 204 | sa1111_writel(stat0, mapbase + SA1111_INTSTATCLR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 206 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 208 | sa1111_writel(stat1, mapbase + SA1111_INTSTATCLR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | if (stat0 == 0 && stat1 == 0) { |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 211 | do_bad_IRQ(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return; |
| 213 | } |
| 214 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 215 | for (i = 0; stat0; i++, stat0 >>= 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | if (stat0 & 1) |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 217 | generic_handle_irq(i + sachip->irq_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 219 | for (i = 32; stat1; i++, stat1 >>= 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | if (stat1 & 1) |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 221 | generic_handle_irq(i + sachip->irq_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | /* For level-based interrupts */ |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 224 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 227 | #define SA1111_IRQMASK_LO(x) (1 << (x - sachip->irq_base)) |
| 228 | #define SA1111_IRQMASK_HI(x) (1 << (x - sachip->irq_base - 32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 230 | static void sa1111_ack_irq(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
| 232 | } |
| 233 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 234 | static void sa1111_mask_lowirq(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 236 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 237 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | unsigned long ie0; |
| 239 | |
| 240 | ie0 = sa1111_readl(mapbase + SA1111_INTEN0); |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 241 | ie0 &= ~SA1111_IRQMASK_LO(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | writel(ie0, mapbase + SA1111_INTEN0); |
| 243 | } |
| 244 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 245 | static void sa1111_unmask_lowirq(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 247 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 248 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | unsigned long ie0; |
| 250 | |
| 251 | ie0 = sa1111_readl(mapbase + SA1111_INTEN0); |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 252 | ie0 |= SA1111_IRQMASK_LO(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | sa1111_writel(ie0, mapbase + SA1111_INTEN0); |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | * Attempt to re-trigger the interrupt. The SA1111 contains a register |
| 258 | * (INTSET) which claims to do this. However, in practice no amount of |
| 259 | * manipulation of INTEN and INTSET guarantees that the interrupt will |
| 260 | * be triggered. In fact, its very difficult, if not impossible to get |
| 261 | * INTSET to re-trigger the interrupt. |
| 262 | */ |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 263 | static int sa1111_retrigger_lowirq(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 265 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 266 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 267 | unsigned int mask = SA1111_IRQMASK_LO(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | unsigned long ip0; |
| 269 | int i; |
| 270 | |
| 271 | ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); |
| 272 | for (i = 0; i < 8; i++) { |
| 273 | sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0); |
| 274 | sa1111_writel(ip0, mapbase + SA1111_INTPOL0); |
Pavel Machek | cae3998 | 2011-01-10 16:35:34 -0600 | [diff] [blame] | 275 | if (sa1111_readl(mapbase + SA1111_INTSTATCLR0) & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | break; |
| 277 | } |
| 278 | |
| 279 | if (i == 8) |
| 280 | printk(KERN_ERR "Danger Will Robinson: failed to " |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 281 | "re-trigger IRQ%d\n", d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | return i == 8 ? -1 : 0; |
| 283 | } |
| 284 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 285 | static int sa1111_type_lowirq(struct irq_data *d, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 287 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 288 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 289 | unsigned int mask = SA1111_IRQMASK_LO(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | unsigned long ip0; |
| 291 | |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 292 | if (flags == IRQ_TYPE_PROBE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | return 0; |
| 294 | |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 295 | if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | return -EINVAL; |
| 297 | |
| 298 | ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 299 | if (flags & IRQ_TYPE_EDGE_RISING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | ip0 &= ~mask; |
| 301 | else |
| 302 | ip0 |= mask; |
| 303 | sa1111_writel(ip0, mapbase + SA1111_INTPOL0); |
| 304 | sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0); |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 309 | static int sa1111_wake_lowirq(struct irq_data *d, unsigned int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 311 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 312 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 313 | unsigned int mask = SA1111_IRQMASK_LO(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | unsigned long we0; |
| 315 | |
| 316 | we0 = sa1111_readl(mapbase + SA1111_WAKEEN0); |
| 317 | if (on) |
| 318 | we0 |= mask; |
| 319 | else |
| 320 | we0 &= ~mask; |
| 321 | sa1111_writel(we0, mapbase + SA1111_WAKEEN0); |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 326 | static struct irq_chip sa1111_low_chip = { |
| 327 | .name = "SA1111-l", |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 328 | .irq_ack = sa1111_ack_irq, |
| 329 | .irq_mask = sa1111_mask_lowirq, |
| 330 | .irq_unmask = sa1111_unmask_lowirq, |
| 331 | .irq_retrigger = sa1111_retrigger_lowirq, |
| 332 | .irq_set_type = sa1111_type_lowirq, |
| 333 | .irq_set_wake = sa1111_wake_lowirq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | }; |
| 335 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 336 | static void sa1111_mask_highirq(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 338 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 339 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | unsigned long ie1; |
| 341 | |
| 342 | ie1 = sa1111_readl(mapbase + SA1111_INTEN1); |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 343 | ie1 &= ~SA1111_IRQMASK_HI(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | sa1111_writel(ie1, mapbase + SA1111_INTEN1); |
| 345 | } |
| 346 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 347 | static void sa1111_unmask_highirq(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 349 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 350 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | unsigned long ie1; |
| 352 | |
| 353 | ie1 = sa1111_readl(mapbase + SA1111_INTEN1); |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 354 | ie1 |= SA1111_IRQMASK_HI(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | sa1111_writel(ie1, mapbase + SA1111_INTEN1); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Attempt to re-trigger the interrupt. The SA1111 contains a register |
| 360 | * (INTSET) which claims to do this. However, in practice no amount of |
| 361 | * manipulation of INTEN and INTSET guarantees that the interrupt will |
| 362 | * be triggered. In fact, its very difficult, if not impossible to get |
| 363 | * INTSET to re-trigger the interrupt. |
| 364 | */ |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 365 | static int sa1111_retrigger_highirq(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 367 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 368 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 369 | unsigned int mask = SA1111_IRQMASK_HI(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | unsigned long ip1; |
| 371 | int i; |
| 372 | |
| 373 | ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); |
| 374 | for (i = 0; i < 8; i++) { |
| 375 | sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1); |
| 376 | sa1111_writel(ip1, mapbase + SA1111_INTPOL1); |
| 377 | if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask) |
| 378 | break; |
| 379 | } |
| 380 | |
| 381 | if (i == 8) |
| 382 | printk(KERN_ERR "Danger Will Robinson: failed to " |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 383 | "re-trigger IRQ%d\n", d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return i == 8 ? -1 : 0; |
| 385 | } |
| 386 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 387 | static int sa1111_type_highirq(struct irq_data *d, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 389 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 390 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 391 | unsigned int mask = SA1111_IRQMASK_HI(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | unsigned long ip1; |
| 393 | |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 394 | if (flags == IRQ_TYPE_PROBE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return 0; |
| 396 | |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 397 | if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | return -EINVAL; |
| 399 | |
| 400 | ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 401 | if (flags & IRQ_TYPE_EDGE_RISING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | ip1 &= ~mask; |
| 403 | else |
| 404 | ip1 |= mask; |
| 405 | sa1111_writel(ip1, mapbase + SA1111_INTPOL1); |
| 406 | sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1); |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 411 | static int sa1111_wake_highirq(struct irq_data *d, unsigned int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 413 | struct sa1111 *sachip = irq_data_get_irq_chip_data(d); |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 414 | void __iomem *mapbase = sachip->base + SA1111_INTC; |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 415 | unsigned int mask = SA1111_IRQMASK_HI(d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | unsigned long we1; |
| 417 | |
| 418 | we1 = sa1111_readl(mapbase + SA1111_WAKEEN1); |
| 419 | if (on) |
| 420 | we1 |= mask; |
| 421 | else |
| 422 | we1 &= ~mask; |
| 423 | sa1111_writel(we1, mapbase + SA1111_WAKEEN1); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 428 | static struct irq_chip sa1111_high_chip = { |
| 429 | .name = "SA1111-h", |
Lennert Buytenhek | 8231e74 | 2010-11-29 10:20:06 +0100 | [diff] [blame] | 430 | .irq_ack = sa1111_ack_irq, |
| 431 | .irq_mask = sa1111_mask_highirq, |
| 432 | .irq_unmask = sa1111_unmask_highirq, |
| 433 | .irq_retrigger = sa1111_retrigger_highirq, |
| 434 | .irq_set_type = sa1111_type_highirq, |
| 435 | .irq_set_wake = sa1111_wake_highirq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | static void sa1111_setup_irq(struct sa1111 *sachip) |
| 439 | { |
| 440 | void __iomem *irqbase = sachip->base + SA1111_INTC; |
| 441 | unsigned int irq; |
| 442 | |
| 443 | /* |
| 444 | * We're guaranteed that this region hasn't been taken. |
| 445 | */ |
| 446 | request_mem_region(sachip->phys + SA1111_INTC, 512, "irq"); |
| 447 | |
| 448 | /* disable all IRQs */ |
| 449 | sa1111_writel(0, irqbase + SA1111_INTEN0); |
| 450 | sa1111_writel(0, irqbase + SA1111_INTEN1); |
| 451 | sa1111_writel(0, irqbase + SA1111_WAKEEN0); |
| 452 | sa1111_writel(0, irqbase + SA1111_WAKEEN1); |
| 453 | |
| 454 | /* |
| 455 | * detect on rising edge. Note: Feb 2001 Errata for SA1111 |
| 456 | * specifies that S0ReadyInt and S1ReadyInt should be '1'. |
| 457 | */ |
| 458 | sa1111_writel(0, irqbase + SA1111_INTPOL0); |
| 459 | sa1111_writel(SA1111_IRQMASK_HI(IRQ_S0_READY_NINT) | |
| 460 | SA1111_IRQMASK_HI(IRQ_S1_READY_NINT), |
| 461 | irqbase + SA1111_INTPOL1); |
| 462 | |
| 463 | /* clear all IRQs */ |
| 464 | sa1111_writel(~0, irqbase + SA1111_INTSTATCLR0); |
| 465 | sa1111_writel(~0, irqbase + SA1111_INTSTATCLR1); |
| 466 | |
| 467 | for (irq = IRQ_GPAIN0; irq <= SSPROR; irq++) { |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 468 | irq_set_chip_and_handler(irq, &sa1111_low_chip, |
| 469 | handle_edge_irq); |
Thomas Gleixner | 9323f261 | 2011-03-24 13:29:39 +0100 | [diff] [blame] | 470 | irq_set_chip_data(irq, sachip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 472 | } |
| 473 | |
| 474 | for (irq = AUDXMTDMADONEA; irq <= IRQ_S1_BVD1_STSCHG; irq++) { |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 475 | irq_set_chip_and_handler(irq, &sa1111_high_chip, |
| 476 | handle_edge_irq); |
Thomas Gleixner | 9323f261 | 2011-03-24 13:29:39 +0100 | [diff] [blame] | 477 | irq_set_chip_data(irq, sachip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * Register SA1111 interrupt |
| 483 | */ |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 484 | irq_set_irq_type(sachip->irq, IRQ_TYPE_EDGE_RISING); |
| 485 | irq_set_handler_data(sachip->irq, sachip); |
| 486 | irq_set_chained_handler(sachip->irq, sa1111_irq_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Bring the SA1111 out of reset. This requires a set procedure: |
| 491 | * 1. nRESET asserted (by hardware) |
| 492 | * 2. CLK turned on from SA1110 |
| 493 | * 3. nRESET deasserted |
| 494 | * 4. VCO turned on, PLL_BYPASS turned off |
| 495 | * 5. Wait lock time, then assert RCLKEn |
| 496 | * 7. PCR set to allow clocking of individual functions |
| 497 | * |
| 498 | * Until we've done this, the only registers we can access are: |
| 499 | * SBI_SKCR |
| 500 | * SBI_SMCR |
| 501 | * SBI_SKID |
| 502 | */ |
| 503 | static void sa1111_wake(struct sa1111 *sachip) |
| 504 | { |
| 505 | unsigned long flags, r; |
| 506 | |
| 507 | spin_lock_irqsave(&sachip->lock, flags); |
| 508 | |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 509 | clk_enable(sachip->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | /* |
| 512 | * Turn VCO on, and disable PLL Bypass. |
| 513 | */ |
| 514 | r = sa1111_readl(sachip->base + SA1111_SKCR); |
| 515 | r &= ~SKCR_VCO_OFF; |
| 516 | sa1111_writel(r, sachip->base + SA1111_SKCR); |
| 517 | r |= SKCR_PLL_BYPASS | SKCR_OE_EN; |
| 518 | sa1111_writel(r, sachip->base + SA1111_SKCR); |
| 519 | |
| 520 | /* |
| 521 | * Wait lock time. SA1111 manual _doesn't_ |
| 522 | * specify a figure for this! We choose 100us. |
| 523 | */ |
| 524 | udelay(100); |
| 525 | |
| 526 | /* |
| 527 | * Enable RCLK. We also ensure that RDYEN is set. |
| 528 | */ |
| 529 | r |= SKCR_RCLKEN | SKCR_RDYEN; |
| 530 | sa1111_writel(r, sachip->base + SA1111_SKCR); |
| 531 | |
| 532 | /* |
| 533 | * Wait 14 RCLK cycles for the chip to finish coming out |
| 534 | * of reset. (RCLK=24MHz). This is 590ns. |
| 535 | */ |
| 536 | udelay(1); |
| 537 | |
| 538 | /* |
| 539 | * Ensure all clocks are initially off. |
| 540 | */ |
| 541 | sa1111_writel(0, sachip->base + SA1111_SKPCR); |
| 542 | |
| 543 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 544 | } |
| 545 | |
| 546 | #ifdef CONFIG_ARCH_SA1100 |
| 547 | |
| 548 | static u32 sa1111_dma_mask[] = { |
| 549 | ~0, |
| 550 | ~(1 << 20), |
| 551 | ~(1 << 23), |
| 552 | ~(1 << 24), |
| 553 | ~(1 << 25), |
| 554 | ~(1 << 20), |
| 555 | ~(1 << 20), |
| 556 | 0, |
| 557 | }; |
| 558 | |
| 559 | /* |
| 560 | * Configure the SA1111 shared memory controller. |
| 561 | */ |
| 562 | void |
| 563 | sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac, |
| 564 | unsigned int cas_latency) |
| 565 | { |
| 566 | unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC); |
| 567 | |
| 568 | if (cas_latency == 3) |
| 569 | smcr |= SMCR_CLAT; |
| 570 | |
| 571 | sa1111_writel(smcr, sachip->base + SA1111_SMCR); |
| 572 | |
| 573 | /* |
| 574 | * Now clear the bits in the DMA mask to work around the SA1111 |
| 575 | * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion |
| 576 | * Chip Specification Update, June 2000, Erratum #7). |
| 577 | */ |
| 578 | if (sachip->dev->dma_mask) |
| 579 | *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2]; |
| 580 | |
| 581 | sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2]; |
| 582 | } |
Russell King | 0703ed2 | 2011-07-04 08:32:21 +0100 | [diff] [blame] | 583 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Russell King | 0703ed2 | 2011-07-04 08:32:21 +0100 | [diff] [blame] | 585 | #ifdef CONFIG_DMABOUNCE |
| 586 | /* |
| 587 | * According to the "Intel StrongARM SA-1111 Microprocessor Companion |
| 588 | * Chip Specification Update" (June 2000), erratum #7, there is a |
| 589 | * significant bug in the SA1111 SDRAM shared memory controller. If |
| 590 | * an access to a region of memory above 1MB relative to the bank base, |
| 591 | * it is important that address bit 10 _NOT_ be asserted. Depending |
| 592 | * on the configuration of the RAM, bit 10 may correspond to one |
| 593 | * of several different (processor-relative) address bits. |
| 594 | * |
| 595 | * This routine only identifies whether or not a given DMA address |
| 596 | * is susceptible to the bug. |
| 597 | * |
| 598 | * This should only get called for sa1111_device types due to the |
| 599 | * way we configure our device dma_masks. |
| 600 | */ |
| 601 | static int sa1111_needs_bounce(struct device *dev, dma_addr_t addr, size_t size) |
| 602 | { |
| 603 | /* |
| 604 | * Section 4.6 of the "Intel StrongARM SA-1111 Development Module |
| 605 | * User's Guide" mentions that jumpers R51 and R52 control the |
| 606 | * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or |
| 607 | * SDRAM bank 1 on Neponset). The default configuration selects |
| 608 | * Assabet, so any address in bank 1 is necessarily invalid. |
| 609 | */ |
| 610 | return (machine_is_assabet() || machine_is_pfs168()) && |
| 611 | (addr >= 0xc8000000 || (addr + size) >= 0xc8000000); |
| 612 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | #endif |
| 614 | |
| 615 | static void sa1111_dev_release(struct device *_dev) |
| 616 | { |
| 617 | struct sa1111_dev *dev = SA1111_DEV(_dev); |
| 618 | |
| 619 | release_resource(&dev->res); |
| 620 | kfree(dev); |
| 621 | } |
| 622 | |
| 623 | static int |
| 624 | sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent, |
| 625 | struct sa1111_dev_info *info) |
| 626 | { |
| 627 | struct sa1111_dev *dev; |
| 628 | int ret; |
| 629 | |
Russell King | d2a02b9 | 2006-03-20 19:46:41 +0000 | [diff] [blame] | 630 | dev = kzalloc(sizeof(struct sa1111_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | if (!dev) { |
| 632 | ret = -ENOMEM; |
| 633 | goto out; |
| 634 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Kay Sievers | 3f97870 | 2008-05-30 17:42:11 +0200 | [diff] [blame] | 636 | dev_set_name(&dev->dev, "%4.4lx", info->offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | dev->devid = info->devid; |
| 638 | dev->dev.parent = sachip->dev; |
| 639 | dev->dev.bus = &sa1111_bus_type; |
| 640 | dev->dev.release = sa1111_dev_release; |
| 641 | dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask; |
| 642 | dev->res.start = sachip->phys + info->offset; |
| 643 | dev->res.end = dev->res.start + 511; |
Kay Sievers | 3f97870 | 2008-05-30 17:42:11 +0200 | [diff] [blame] | 644 | dev->res.name = dev_name(&dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | dev->res.flags = IORESOURCE_MEM; |
| 646 | dev->mapbase = sachip->base + info->offset; |
| 647 | dev->skpcr_mask = info->skpcr_mask; |
| 648 | memmove(dev->irq, info->irq, sizeof(dev->irq)); |
| 649 | |
| 650 | ret = request_resource(parent, &dev->res); |
| 651 | if (ret) { |
| 652 | printk("SA1111: failed to allocate resource for %s\n", |
| 653 | dev->res.name); |
Kay Sievers | 3f97870 | 2008-05-30 17:42:11 +0200 | [diff] [blame] | 654 | dev_set_name(&dev->dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | kfree(dev); |
| 656 | goto out; |
| 657 | } |
| 658 | |
| 659 | |
| 660 | ret = device_register(&dev->dev); |
| 661 | if (ret) { |
| 662 | release_resource(&dev->res); |
| 663 | kfree(dev); |
| 664 | goto out; |
| 665 | } |
| 666 | |
Russell King | 957cf33 | 2008-10-17 13:39:26 +0100 | [diff] [blame] | 667 | #ifdef CONFIG_DMABOUNCE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | /* |
| 669 | * If the parent device has a DMA mask associated with it, |
| 670 | * propagate it down to the children. |
| 671 | */ |
| 672 | if (sachip->dev->dma_mask) { |
| 673 | dev->dma_mask = *sachip->dev->dma_mask; |
| 674 | dev->dev.dma_mask = &dev->dma_mask; |
| 675 | |
| 676 | if (dev->dma_mask != 0xffffffffUL) { |
Russell King | 0703ed2 | 2011-07-04 08:32:21 +0100 | [diff] [blame] | 677 | ret = dmabounce_register_dev(&dev->dev, 1024, 4096, |
| 678 | sa1111_needs_bounce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | if (ret) { |
Greg Kroah-Hartman | fc3a882 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 680 | dev_err(&dev->dev, "SA1111: Failed to register" |
| 681 | " with dmabounce\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | device_unregister(&dev->dev); |
| 683 | } |
| 684 | } |
| 685 | } |
Russell King | 957cf33 | 2008-10-17 13:39:26 +0100 | [diff] [blame] | 686 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | out: |
| 689 | return ret; |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * sa1111_probe - probe for a single SA1111 chip. |
| 694 | * @phys_addr: physical address of device. |
| 695 | * |
| 696 | * Probe for a SA1111 chip. This must be called |
| 697 | * before any other SA1111-specific code. |
| 698 | * |
| 699 | * Returns: |
| 700 | * %-ENODEV device not found. |
| 701 | * %-EBUSY physical address already marked in-use. |
| 702 | * %0 successful. |
| 703 | */ |
Uwe Kleine-König | 055d196 | 2010-09-02 09:14:21 +0100 | [diff] [blame] | 704 | static int __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | __sa1111_probe(struct device *me, struct resource *mem, int irq) |
| 706 | { |
| 707 | struct sa1111 *sachip; |
| 708 | unsigned long id; |
David Brownell | 416112f | 2006-08-27 13:09:14 +0100 | [diff] [blame] | 709 | unsigned int has_devs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | int i, ret = -ENODEV; |
| 711 | |
Russell King | d2a02b9 | 2006-03-20 19:46:41 +0000 | [diff] [blame] | 712 | sachip = kzalloc(sizeof(struct sa1111), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | if (!sachip) |
| 714 | return -ENOMEM; |
| 715 | |
Ian Molton | 13f7558 | 2008-07-08 10:32:50 +0100 | [diff] [blame] | 716 | sachip->clk = clk_get(me, "SA1111_CLK"); |
Julia Lawall | 442a902 | 2008-12-13 16:37:59 +0100 | [diff] [blame] | 717 | if (IS_ERR(sachip->clk)) { |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 718 | ret = PTR_ERR(sachip->clk); |
| 719 | goto err_free; |
| 720 | } |
| 721 | |
Russell King | 72ae00c | 2011-09-22 11:41:07 +0100 | [diff] [blame] | 722 | ret = clk_prepare(sachip->clk); |
| 723 | if (ret) |
| 724 | goto err_clkput; |
| 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | spin_lock_init(&sachip->lock); |
| 727 | |
| 728 | sachip->dev = me; |
| 729 | dev_set_drvdata(sachip->dev, sachip); |
| 730 | |
| 731 | sachip->phys = mem->start; |
| 732 | sachip->irq = irq; |
| 733 | |
| 734 | /* |
| 735 | * Map the whole region. This also maps the |
| 736 | * registers for our children. |
| 737 | */ |
| 738 | sachip->base = ioremap(mem->start, PAGE_SIZE * 2); |
| 739 | if (!sachip->base) { |
| 740 | ret = -ENOMEM; |
Russell King | 72ae00c | 2011-09-22 11:41:07 +0100 | [diff] [blame] | 741 | goto err_clk_unprep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /* |
| 745 | * Probe for the chip. Only touch the SBI registers. |
| 746 | */ |
| 747 | id = sa1111_readl(sachip->base + SA1111_SKID); |
| 748 | if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { |
| 749 | printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id); |
| 750 | ret = -ENODEV; |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 751 | goto err_unmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | printk(KERN_INFO "SA1111 Microprocessor Companion Chip: " |
| 755 | "silicon revision %lx, metal revision %lx\n", |
| 756 | (id & SKID_SIREV_MASK)>>4, (id & SKID_MTREV_MASK)); |
| 757 | |
| 758 | /* |
| 759 | * We found it. Wake the chip up, and initialise. |
| 760 | */ |
| 761 | sa1111_wake(sachip); |
| 762 | |
| 763 | #ifdef CONFIG_ARCH_SA1100 |
David Brownell | 416112f | 2006-08-27 13:09:14 +0100 | [diff] [blame] | 764 | { |
| 765 | unsigned int val; |
| 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | /* |
| 768 | * The SDRAM configuration of the SA1110 and the SA1111 must |
| 769 | * match. This is very important to ensure that SA1111 accesses |
| 770 | * don't corrupt the SDRAM. Note that this ungates the SA1111's |
| 771 | * MBGNT signal, so we must have called sa1110_mb_disable() |
| 772 | * beforehand. |
| 773 | */ |
| 774 | sa1111_configure_smc(sachip, 1, |
| 775 | FExtr(MDCNFG, MDCNFG_SA1110_DRAC0), |
| 776 | FExtr(MDCNFG, MDCNFG_SA1110_TDL0)); |
| 777 | |
| 778 | /* |
| 779 | * We only need to turn on DCLK whenever we want to use the |
| 780 | * DMA. It can otherwise be held firmly in the off position. |
| 781 | * (currently, we always enable it.) |
| 782 | */ |
| 783 | val = sa1111_readl(sachip->base + SA1111_SKPCR); |
| 784 | sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR); |
| 785 | |
| 786 | /* |
| 787 | * Enable the SA1110 memory bus request and grant signals. |
| 788 | */ |
| 789 | sa1110_mb_enable(); |
David Brownell | 416112f | 2006-08-27 13:09:14 +0100 | [diff] [blame] | 790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | #endif |
| 792 | |
| 793 | /* |
| 794 | * The interrupt controller must be initialised before any |
| 795 | * other device to ensure that the interrupts are available. |
| 796 | */ |
| 797 | if (sachip->irq != NO_IRQ) |
| 798 | sa1111_setup_irq(sachip); |
| 799 | |
| 800 | g_sa1111 = sachip; |
| 801 | |
| 802 | has_devs = ~0; |
| 803 | if (machine_is_assabet() || machine_is_jornada720() || |
| 804 | machine_is_badge4()) |
| 805 | has_devs &= ~(1 << 4); |
| 806 | else |
| 807 | has_devs &= ~(1 << 1); |
| 808 | |
| 809 | for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++) |
| 810 | if (has_devs & (1 << i)) |
| 811 | sa1111_init_one_child(sachip, mem, &sa1111_devices[i]); |
| 812 | |
| 813 | return 0; |
| 814 | |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 815 | err_unmap: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | iounmap(sachip->base); |
Russell King | 72ae00c | 2011-09-22 11:41:07 +0100 | [diff] [blame] | 817 | err_clk_unprep: |
| 818 | clk_unprepare(sachip->clk); |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 819 | err_clkput: |
| 820 | clk_put(sachip->clk); |
| 821 | err_free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | kfree(sachip); |
| 823 | return ret; |
| 824 | } |
| 825 | |
Russell King | 522c37b | 2005-06-22 09:52:26 +0100 | [diff] [blame] | 826 | static int sa1111_remove_one(struct device *dev, void *data) |
| 827 | { |
| 828 | device_unregister(dev); |
| 829 | return 0; |
| 830 | } |
| 831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | static void __sa1111_remove(struct sa1111 *sachip) |
| 833 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | void __iomem *irqbase = sachip->base + SA1111_INTC; |
| 835 | |
Russell King | 522c37b | 2005-06-22 09:52:26 +0100 | [diff] [blame] | 836 | device_for_each_child(sachip->dev, NULL, sa1111_remove_one); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | /* disable all IRQs */ |
| 839 | sa1111_writel(0, irqbase + SA1111_INTEN0); |
| 840 | sa1111_writel(0, irqbase + SA1111_INTEN1); |
| 841 | sa1111_writel(0, irqbase + SA1111_WAKEEN0); |
| 842 | sa1111_writel(0, irqbase + SA1111_WAKEEN1); |
| 843 | |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 844 | clk_disable(sachip->clk); |
Russell King | 72ae00c | 2011-09-22 11:41:07 +0100 | [diff] [blame] | 845 | clk_unprepare(sachip->clk); |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | if (sachip->irq != NO_IRQ) { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 848 | irq_set_chained_handler(sachip->irq, NULL); |
| 849 | irq_set_handler_data(sachip->irq, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | release_mem_region(sachip->phys + SA1111_INTC, 512); |
| 852 | } |
| 853 | |
| 854 | iounmap(sachip->base); |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 855 | clk_put(sachip->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | kfree(sachip); |
| 857 | } |
| 858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | struct sa1111_save_data { |
| 860 | unsigned int skcr; |
| 861 | unsigned int skpcr; |
| 862 | unsigned int skcdr; |
| 863 | unsigned char skaud; |
| 864 | unsigned char skpwm0; |
| 865 | unsigned char skpwm1; |
| 866 | |
| 867 | /* |
| 868 | * Interrupt controller |
| 869 | */ |
| 870 | unsigned int intpol0; |
| 871 | unsigned int intpol1; |
| 872 | unsigned int inten0; |
| 873 | unsigned int inten1; |
| 874 | unsigned int wakepol0; |
| 875 | unsigned int wakepol1; |
| 876 | unsigned int wakeen0; |
| 877 | unsigned int wakeen1; |
| 878 | }; |
| 879 | |
| 880 | #ifdef CONFIG_PM |
| 881 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 882 | static int sa1111_suspend(struct platform_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 884 | struct sa1111 *sachip = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | struct sa1111_save_data *save; |
| 886 | unsigned long flags; |
| 887 | unsigned int val; |
| 888 | void __iomem *base; |
| 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL); |
| 891 | if (!save) |
| 892 | return -ENOMEM; |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 893 | sachip->saved_state = save; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | spin_lock_irqsave(&sachip->lock, flags); |
| 896 | |
| 897 | /* |
| 898 | * Save state. |
| 899 | */ |
| 900 | base = sachip->base; |
| 901 | save->skcr = sa1111_readl(base + SA1111_SKCR); |
| 902 | save->skpcr = sa1111_readl(base + SA1111_SKPCR); |
| 903 | save->skcdr = sa1111_readl(base + SA1111_SKCDR); |
| 904 | save->skaud = sa1111_readl(base + SA1111_SKAUD); |
| 905 | save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0); |
| 906 | save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1); |
| 907 | |
| 908 | base = sachip->base + SA1111_INTC; |
| 909 | save->intpol0 = sa1111_readl(base + SA1111_INTPOL0); |
| 910 | save->intpol1 = sa1111_readl(base + SA1111_INTPOL1); |
| 911 | save->inten0 = sa1111_readl(base + SA1111_INTEN0); |
| 912 | save->inten1 = sa1111_readl(base + SA1111_INTEN1); |
| 913 | save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0); |
| 914 | save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1); |
| 915 | save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0); |
| 916 | save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1); |
| 917 | |
| 918 | /* |
| 919 | * Disable. |
| 920 | */ |
| 921 | val = sa1111_readl(sachip->base + SA1111_SKCR); |
| 922 | sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR); |
| 923 | sa1111_writel(0, sachip->base + SA1111_SKPWM0); |
| 924 | sa1111_writel(0, sachip->base + SA1111_SKPWM1); |
| 925 | |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 926 | clk_disable(sachip->clk); |
| 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 929 | |
Russell King | 29c140b | 2012-02-03 19:03:31 +0000 | [diff] [blame^] | 930 | #ifdef CONFIG_ARCH_SA1100 |
| 931 | sa1110_mb_disable(); |
| 932 | #endif |
| 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | * sa1111_resume - Restore the SA1111 device state. |
| 939 | * @dev: device to restore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | * |
| 941 | * Restore the general state of the SA1111; clock control and |
| 942 | * interrupt controller. Other parts of the SA1111 must be |
| 943 | * restored by their respective drivers, and must be called |
| 944 | * via LDM after this function. |
| 945 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 946 | static int sa1111_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 948 | struct sa1111 *sachip = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | struct sa1111_save_data *save; |
| 950 | unsigned long flags, id; |
| 951 | void __iomem *base; |
| 952 | |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 953 | save = sachip->saved_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | if (!save) |
| 955 | return 0; |
| 956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | /* |
| 958 | * Ensure that the SA1111 is still here. |
| 959 | * FIXME: shouldn't do this here. |
| 960 | */ |
| 961 | id = sa1111_readl(sachip->base + SA1111_SKID); |
| 962 | if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { |
| 963 | __sa1111_remove(sachip); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 964 | platform_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | kfree(save); |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | /* |
| 970 | * First of all, wake up the chip. |
| 971 | */ |
| 972 | sa1111_wake(sachip); |
Marek Vašut | 3defb24 | 2010-05-26 23:53:09 +0100 | [diff] [blame] | 973 | |
Russell King | 29c140b | 2012-02-03 19:03:31 +0000 | [diff] [blame^] | 974 | #ifdef CONFIG_ARCH_SA1100 |
| 975 | /* Enable the memory bus request/grant signals */ |
| 976 | sa1110_mb_enable(); |
| 977 | #endif |
| 978 | |
Marek Vašut | 3defb24 | 2010-05-26 23:53:09 +0100 | [diff] [blame] | 979 | /* |
| 980 | * Only lock for write ops. Also, sa1111_wake must be called with |
| 981 | * released spinlock! |
| 982 | */ |
| 983 | spin_lock_irqsave(&sachip->lock, flags); |
| 984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0); |
| 986 | sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1); |
| 987 | |
| 988 | base = sachip->base; |
| 989 | sa1111_writel(save->skcr, base + SA1111_SKCR); |
| 990 | sa1111_writel(save->skpcr, base + SA1111_SKPCR); |
| 991 | sa1111_writel(save->skcdr, base + SA1111_SKCDR); |
| 992 | sa1111_writel(save->skaud, base + SA1111_SKAUD); |
| 993 | sa1111_writel(save->skpwm0, base + SA1111_SKPWM0); |
| 994 | sa1111_writel(save->skpwm1, base + SA1111_SKPWM1); |
| 995 | |
| 996 | base = sachip->base + SA1111_INTC; |
| 997 | sa1111_writel(save->intpol0, base + SA1111_INTPOL0); |
| 998 | sa1111_writel(save->intpol1, base + SA1111_INTPOL1); |
| 999 | sa1111_writel(save->inten0, base + SA1111_INTEN0); |
| 1000 | sa1111_writel(save->inten1, base + SA1111_INTEN1); |
| 1001 | sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0); |
| 1002 | sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1); |
| 1003 | sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0); |
| 1004 | sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1); |
| 1005 | |
| 1006 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 1007 | |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 1008 | sachip->saved_state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | kfree(save); |
| 1010 | |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | #else |
| 1015 | #define sa1111_suspend NULL |
| 1016 | #define sa1111_resume NULL |
| 1017 | #endif |
| 1018 | |
Kristoffer Ericson | 5d43839 | 2008-10-21 19:47:22 +0100 | [diff] [blame] | 1019 | static int __devinit sa1111_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | struct resource *mem; |
| 1022 | int irq; |
| 1023 | |
| 1024 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1025 | if (!mem) |
| 1026 | return -EINVAL; |
| 1027 | irq = platform_get_irq(pdev, 0); |
David Vrabel | 4894473 | 2006-01-19 17:56:29 +0000 | [diff] [blame] | 1028 | if (irq < 0) |
| 1029 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1031 | return __sa1111_probe(&pdev->dev, mem, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1034 | static int sa1111_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1036 | struct sa1111 *sachip = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (sachip) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 1040 | kfree(sachip->saved_state); |
| 1041 | sachip->saved_state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | #endif |
Julia Lawall | f2d2420 | 2010-07-30 17:17:28 +0200 | [diff] [blame] | 1043 | __sa1111_remove(sachip); |
| 1044 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | /* |
| 1051 | * Not sure if this should be on the system bus or not yet. |
| 1052 | * We really want some way to register a system device at |
| 1053 | * the per-machine level, and then have this driver pick |
| 1054 | * up the registered devices. |
| 1055 | * |
| 1056 | * We also need to handle the SDRAM configuration for |
| 1057 | * PXA250/SA1110 machine classes. |
| 1058 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1059 | static struct platform_driver sa1111_device_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | .probe = sa1111_probe, |
| 1061 | .remove = sa1111_remove, |
| 1062 | .suspend = sa1111_suspend, |
| 1063 | .resume = sa1111_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1064 | .driver = { |
| 1065 | .name = "sa1111", |
| 1066 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | }; |
| 1068 | |
| 1069 | /* |
| 1070 | * Get the parent device driver (us) structure |
| 1071 | * from a child function device |
| 1072 | */ |
| 1073 | static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev) |
| 1074 | { |
| 1075 | return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent); |
| 1076 | } |
| 1077 | |
| 1078 | /* |
| 1079 | * The bits in the opdiv field are non-linear. |
| 1080 | */ |
| 1081 | static unsigned char opdiv_table[] = { 1, 4, 2, 8 }; |
| 1082 | |
| 1083 | static unsigned int __sa1111_pll_clock(struct sa1111 *sachip) |
| 1084 | { |
| 1085 | unsigned int skcdr, fbdiv, ipdiv, opdiv; |
| 1086 | |
| 1087 | skcdr = sa1111_readl(sachip->base + SA1111_SKCDR); |
| 1088 | |
| 1089 | fbdiv = (skcdr & 0x007f) + 2; |
| 1090 | ipdiv = ((skcdr & 0x0f80) >> 7) + 2; |
| 1091 | opdiv = opdiv_table[(skcdr & 0x3000) >> 12]; |
| 1092 | |
| 1093 | return 3686400 * fbdiv / (ipdiv * opdiv); |
| 1094 | } |
| 1095 | |
| 1096 | /** |
| 1097 | * sa1111_pll_clock - return the current PLL clock frequency. |
| 1098 | * @sadev: SA1111 function block |
| 1099 | * |
| 1100 | * BUG: we should look at SKCR. We also blindly believe that |
| 1101 | * the chip is being fed with the 3.6864MHz clock. |
| 1102 | * |
| 1103 | * Returns the PLL clock in Hz. |
| 1104 | */ |
| 1105 | unsigned int sa1111_pll_clock(struct sa1111_dev *sadev) |
| 1106 | { |
| 1107 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1108 | |
| 1109 | return __sa1111_pll_clock(sachip); |
| 1110 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1111 | EXPORT_SYMBOL(sa1111_pll_clock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
| 1113 | /** |
| 1114 | * sa1111_select_audio_mode - select I2S or AC link mode |
| 1115 | * @sadev: SA1111 function block |
| 1116 | * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S |
| 1117 | * |
| 1118 | * Frob the SKCR to select AC Link mode or I2S mode for |
| 1119 | * the audio block. |
| 1120 | */ |
| 1121 | void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode) |
| 1122 | { |
| 1123 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1124 | unsigned long flags; |
| 1125 | unsigned int val; |
| 1126 | |
| 1127 | spin_lock_irqsave(&sachip->lock, flags); |
| 1128 | |
| 1129 | val = sa1111_readl(sachip->base + SA1111_SKCR); |
| 1130 | if (mode == SA1111_AUDIO_I2S) { |
| 1131 | val &= ~SKCR_SELAC; |
| 1132 | } else { |
| 1133 | val |= SKCR_SELAC; |
| 1134 | } |
| 1135 | sa1111_writel(val, sachip->base + SA1111_SKCR); |
| 1136 | |
| 1137 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 1138 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1139 | EXPORT_SYMBOL(sa1111_select_audio_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
| 1141 | /** |
| 1142 | * sa1111_set_audio_rate - set the audio sample rate |
| 1143 | * @sadev: SA1111 SAC function block |
| 1144 | * @rate: sample rate to select |
| 1145 | */ |
| 1146 | int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate) |
| 1147 | { |
| 1148 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1149 | unsigned int div; |
| 1150 | |
| 1151 | if (sadev->devid != SA1111_DEVID_SAC) |
| 1152 | return -EINVAL; |
| 1153 | |
| 1154 | div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate; |
| 1155 | if (div == 0) |
| 1156 | div = 1; |
| 1157 | if (div > 128) |
| 1158 | div = 128; |
| 1159 | |
| 1160 | sa1111_writel(div - 1, sachip->base + SA1111_SKAUD); |
| 1161 | |
| 1162 | return 0; |
| 1163 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1164 | EXPORT_SYMBOL(sa1111_set_audio_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
| 1166 | /** |
| 1167 | * sa1111_get_audio_rate - get the audio sample rate |
| 1168 | * @sadev: SA1111 SAC function block device |
| 1169 | */ |
| 1170 | int sa1111_get_audio_rate(struct sa1111_dev *sadev) |
| 1171 | { |
| 1172 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1173 | unsigned long div; |
| 1174 | |
| 1175 | if (sadev->devid != SA1111_DEVID_SAC) |
| 1176 | return -EINVAL; |
| 1177 | |
| 1178 | div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1; |
| 1179 | |
| 1180 | return __sa1111_pll_clock(sachip) / (256 * div); |
| 1181 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1182 | EXPORT_SYMBOL(sa1111_get_audio_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
| 1184 | void sa1111_set_io_dir(struct sa1111_dev *sadev, |
| 1185 | unsigned int bits, unsigned int dir, |
| 1186 | unsigned int sleep_dir) |
| 1187 | { |
| 1188 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1189 | unsigned long flags; |
| 1190 | unsigned int val; |
| 1191 | void __iomem *gpio = sachip->base + SA1111_GPIO; |
| 1192 | |
| 1193 | #define MODIFY_BITS(port, mask, dir) \ |
| 1194 | if (mask) { \ |
| 1195 | val = sa1111_readl(port); \ |
| 1196 | val &= ~(mask); \ |
| 1197 | val |= (dir) & (mask); \ |
| 1198 | sa1111_writel(val, port); \ |
| 1199 | } |
| 1200 | |
| 1201 | spin_lock_irqsave(&sachip->lock, flags); |
| 1202 | MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir); |
| 1203 | MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8); |
| 1204 | MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16); |
| 1205 | |
| 1206 | MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir); |
| 1207 | MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8); |
| 1208 | MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16); |
| 1209 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 1210 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1211 | EXPORT_SYMBOL(sa1111_set_io_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
| 1213 | void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) |
| 1214 | { |
| 1215 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1216 | unsigned long flags; |
| 1217 | unsigned int val; |
| 1218 | void __iomem *gpio = sachip->base + SA1111_GPIO; |
| 1219 | |
| 1220 | spin_lock_irqsave(&sachip->lock, flags); |
| 1221 | MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v); |
| 1222 | MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8); |
| 1223 | MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16); |
| 1224 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 1225 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1226 | EXPORT_SYMBOL(sa1111_set_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) |
| 1229 | { |
| 1230 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1231 | unsigned long flags; |
| 1232 | unsigned int val; |
| 1233 | void __iomem *gpio = sachip->base + SA1111_GPIO; |
| 1234 | |
| 1235 | spin_lock_irqsave(&sachip->lock, flags); |
| 1236 | MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v); |
| 1237 | MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8); |
| 1238 | MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16); |
| 1239 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 1240 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1241 | EXPORT_SYMBOL(sa1111_set_sleep_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | /* |
| 1244 | * Individual device operations. |
| 1245 | */ |
| 1246 | |
| 1247 | /** |
| 1248 | * sa1111_enable_device - enable an on-chip SA1111 function block |
| 1249 | * @sadev: SA1111 function block device to enable |
| 1250 | */ |
| 1251 | void sa1111_enable_device(struct sa1111_dev *sadev) |
| 1252 | { |
| 1253 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1254 | unsigned long flags; |
| 1255 | unsigned int val; |
| 1256 | |
| 1257 | spin_lock_irqsave(&sachip->lock, flags); |
| 1258 | val = sa1111_readl(sachip->base + SA1111_SKPCR); |
| 1259 | sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR); |
| 1260 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 1261 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1262 | EXPORT_SYMBOL(sa1111_enable_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
| 1264 | /** |
| 1265 | * sa1111_disable_device - disable an on-chip SA1111 function block |
| 1266 | * @sadev: SA1111 function block device to disable |
| 1267 | */ |
| 1268 | void sa1111_disable_device(struct sa1111_dev *sadev) |
| 1269 | { |
| 1270 | struct sa1111 *sachip = sa1111_chip_driver(sadev); |
| 1271 | unsigned long flags; |
| 1272 | unsigned int val; |
| 1273 | |
| 1274 | spin_lock_irqsave(&sachip->lock, flags); |
| 1275 | val = sa1111_readl(sachip->base + SA1111_SKPCR); |
| 1276 | sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR); |
| 1277 | spin_unlock_irqrestore(&sachip->lock, flags); |
| 1278 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1279 | EXPORT_SYMBOL(sa1111_disable_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
| 1281 | /* |
| 1282 | * SA1111 "Register Access Bus." |
| 1283 | * |
| 1284 | * We model this as a regular bus type, and hang devices directly |
| 1285 | * off this. |
| 1286 | */ |
| 1287 | static int sa1111_match(struct device *_dev, struct device_driver *_drv) |
| 1288 | { |
| 1289 | struct sa1111_dev *dev = SA1111_DEV(_dev); |
| 1290 | struct sa1111_driver *drv = SA1111_DRV(_drv); |
| 1291 | |
| 1292 | return dev->devid == drv->devid; |
| 1293 | } |
| 1294 | |
| 1295 | static int sa1111_bus_suspend(struct device *dev, pm_message_t state) |
| 1296 | { |
| 1297 | struct sa1111_dev *sadev = SA1111_DEV(dev); |
| 1298 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); |
| 1299 | int ret = 0; |
| 1300 | |
| 1301 | if (drv && drv->suspend) |
| 1302 | ret = drv->suspend(sadev, state); |
| 1303 | return ret; |
| 1304 | } |
| 1305 | |
| 1306 | static int sa1111_bus_resume(struct device *dev) |
| 1307 | { |
| 1308 | struct sa1111_dev *sadev = SA1111_DEV(dev); |
| 1309 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); |
| 1310 | int ret = 0; |
| 1311 | |
| 1312 | if (drv && drv->resume) |
| 1313 | ret = drv->resume(sadev); |
| 1314 | return ret; |
| 1315 | } |
| 1316 | |
| 1317 | static int sa1111_bus_probe(struct device *dev) |
| 1318 | { |
| 1319 | struct sa1111_dev *sadev = SA1111_DEV(dev); |
| 1320 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); |
| 1321 | int ret = -ENODEV; |
| 1322 | |
| 1323 | if (drv->probe) |
| 1324 | ret = drv->probe(sadev); |
| 1325 | return ret; |
| 1326 | } |
| 1327 | |
| 1328 | static int sa1111_bus_remove(struct device *dev) |
| 1329 | { |
| 1330 | struct sa1111_dev *sadev = SA1111_DEV(dev); |
| 1331 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); |
| 1332 | int ret = 0; |
| 1333 | |
| 1334 | if (drv->remove) |
| 1335 | ret = drv->remove(sadev); |
| 1336 | return ret; |
| 1337 | } |
| 1338 | |
| 1339 | struct bus_type sa1111_bus_type = { |
| 1340 | .name = "sa1111-rab", |
| 1341 | .match = sa1111_match, |
Russell King | 2876ba4 | 2006-01-05 14:32:32 +0000 | [diff] [blame] | 1342 | .probe = sa1111_bus_probe, |
| 1343 | .remove = sa1111_bus_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | .suspend = sa1111_bus_suspend, |
| 1345 | .resume = sa1111_bus_resume, |
| 1346 | }; |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1347 | EXPORT_SYMBOL(sa1111_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | |
| 1349 | int sa1111_driver_register(struct sa1111_driver *driver) |
| 1350 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | driver->drv.bus = &sa1111_bus_type; |
| 1352 | return driver_register(&driver->drv); |
| 1353 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1354 | EXPORT_SYMBOL(sa1111_driver_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | |
| 1356 | void sa1111_driver_unregister(struct sa1111_driver *driver) |
| 1357 | { |
| 1358 | driver_unregister(&driver->drv); |
| 1359 | } |
Hartley Sweeten | 0a4bc5e | 2009-09-29 23:49:02 +0100 | [diff] [blame] | 1360 | EXPORT_SYMBOL(sa1111_driver_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | |
| 1362 | static int __init sa1111_init(void) |
| 1363 | { |
| 1364 | int ret = bus_register(&sa1111_bus_type); |
| 1365 | if (ret == 0) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1366 | platform_driver_register(&sa1111_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | return ret; |
| 1368 | } |
| 1369 | |
| 1370 | static void __exit sa1111_exit(void) |
| 1371 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1372 | platform_driver_unregister(&sa1111_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | bus_unregister(&sa1111_bus_type); |
| 1374 | } |
| 1375 | |
Russell King | 7272438 | 2005-11-15 19:04:22 +0000 | [diff] [blame] | 1376 | subsys_initcall(sa1111_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | module_exit(sa1111_exit); |
| 1378 | |
| 1379 | MODULE_DESCRIPTION("Intel Corporation SA1111 core driver"); |
| 1380 | MODULE_LICENSE("GPL"); |