Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-sa1100/neponset.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | */ |
Russell King | 9590e898 | 2012-01-24 22:36:47 +0000 | [diff] [blame] | 4 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/ioport.h> |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 7 | #include <linux/irq.h> |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 8 | #include <linux/kernel.h> |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 9 | #include <linux/module.h> |
Russell King | 6920b5a | 2012-09-21 10:18:58 +0100 | [diff] [blame] | 10 | #include <linux/platform_data/sa11x0-serial.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 11 | #include <linux/platform_device.h> |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 12 | #include <linux/pm.h> |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 13 | #include <linux/serial_core.h> |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 14 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/mach-types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/mach/map.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/hardware/sa1111.h> |
| 19 | #include <asm/sizes.h> |
| 20 | |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 21 | #include <mach/hardware.h> |
| 22 | #include <mach/assabet.h> |
| 23 | #include <mach/neponset.h> |
Rob Herring | f314f33 | 2012-02-24 00:06:51 +0100 | [diff] [blame] | 24 | #include <mach/irqs.h> |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 25 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 26 | #define NEP_IRQ_SMC91X 0 |
| 27 | #define NEP_IRQ_USAR 1 |
| 28 | #define NEP_IRQ_SA1111 2 |
| 29 | #define NEP_IRQ_NR 3 |
| 30 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 31 | #define WHOAMI 0x00 |
| 32 | #define LEDS 0x10 |
| 33 | #define SWPK 0x20 |
| 34 | #define IRR 0x24 |
| 35 | #define KP_Y_IN 0x80 |
| 36 | #define KP_X_OUT 0x90 |
| 37 | #define NCR_0 0xa0 |
| 38 | #define MDM_CTL_0 0xb0 |
| 39 | #define MDM_CTL_1 0xb4 |
| 40 | #define AUD_CTL 0xc0 |
| 41 | |
| 42 | #define IRR_ETHERNET (1 << 0) |
| 43 | #define IRR_USAR (1 << 1) |
| 44 | #define IRR_SA1111 (1 << 2) |
| 45 | |
| 46 | #define MDM_CTL0_RTS1 (1 << 0) |
| 47 | #define MDM_CTL0_DTR1 (1 << 1) |
| 48 | #define MDM_CTL0_RTS2 (1 << 2) |
| 49 | #define MDM_CTL0_DTR2 (1 << 3) |
| 50 | |
| 51 | #define MDM_CTL1_CTS1 (1 << 0) |
| 52 | #define MDM_CTL1_DSR1 (1 << 1) |
| 53 | #define MDM_CTL1_DCD1 (1 << 2) |
| 54 | #define MDM_CTL1_CTS2 (1 << 3) |
| 55 | #define MDM_CTL1_DSR2 (1 << 4) |
| 56 | #define MDM_CTL1_DCD2 (1 << 5) |
| 57 | |
| 58 | #define AUD_SEL_1341 (1 << 0) |
| 59 | #define AUD_MUTE_1341 (1 << 1) |
| 60 | |
Russell King | bab50a3 | 2012-01-26 11:50:23 +0000 | [diff] [blame] | 61 | extern void sa1110_mb_disable(void); |
| 62 | |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 63 | struct neponset_drvdata { |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 64 | void __iomem *base; |
Russell King | 9590e898 | 2012-01-24 22:36:47 +0000 | [diff] [blame] | 65 | struct platform_device *sa1111; |
| 66 | struct platform_device *smc91x; |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 67 | unsigned irq_base; |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 68 | #ifdef CONFIG_PM_SLEEP |
| 69 | u32 ncr0; |
| 70 | u32 mdm_ctl_0; |
| 71 | #endif |
| 72 | }; |
| 73 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 74 | static void __iomem *nep_base; |
| 75 | |
Russell King | 6ad1b61 | 2012-01-16 09:31:47 +0000 | [diff] [blame] | 76 | void neponset_ncr_frob(unsigned int mask, unsigned int val) |
| 77 | { |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 78 | void __iomem *base = nep_base; |
Russell King | 6ad1b61 | 2012-01-16 09:31:47 +0000 | [diff] [blame] | 79 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 80 | if (base) { |
| 81 | unsigned long flags; |
| 82 | unsigned v; |
| 83 | |
| 84 | local_irq_save(flags); |
| 85 | v = readb_relaxed(base + NCR_0); |
| 86 | writeb_relaxed((v & ~mask) | val, base + NCR_0); |
| 87 | local_irq_restore(flags); |
| 88 | } else { |
| 89 | WARN(1, "nep_base unset\n"); |
| 90 | } |
Russell King | 6ad1b61 | 2012-01-16 09:31:47 +0000 | [diff] [blame] | 91 | } |
Russell King | ef0c148 | 2012-05-25 08:41:53 +0100 | [diff] [blame] | 92 | EXPORT_SYMBOL(neponset_ncr_frob); |
Russell King | 6ad1b61 | 2012-01-16 09:31:47 +0000 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | static void neponset_set_mctrl(struct uart_port *port, u_int mctrl) |
| 95 | { |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 96 | void __iomem *base = nep_base; |
| 97 | u_int mdm_ctl0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 99 | if (!base) |
| 100 | return; |
| 101 | |
| 102 | mdm_ctl0 = readb_relaxed(base + MDM_CTL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | if (port->mapbase == _Ser1UTCR0) { |
| 104 | if (mctrl & TIOCM_RTS) |
| 105 | mdm_ctl0 &= ~MDM_CTL0_RTS2; |
| 106 | else |
| 107 | mdm_ctl0 |= MDM_CTL0_RTS2; |
| 108 | |
| 109 | if (mctrl & TIOCM_DTR) |
| 110 | mdm_ctl0 &= ~MDM_CTL0_DTR2; |
| 111 | else |
| 112 | mdm_ctl0 |= MDM_CTL0_DTR2; |
| 113 | } else if (port->mapbase == _Ser3UTCR0) { |
| 114 | if (mctrl & TIOCM_RTS) |
| 115 | mdm_ctl0 &= ~MDM_CTL0_RTS1; |
| 116 | else |
| 117 | mdm_ctl0 |= MDM_CTL0_RTS1; |
| 118 | |
| 119 | if (mctrl & TIOCM_DTR) |
| 120 | mdm_ctl0 &= ~MDM_CTL0_DTR1; |
| 121 | else |
| 122 | mdm_ctl0 |= MDM_CTL0_DTR1; |
| 123 | } |
| 124 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 125 | writeb_relaxed(mdm_ctl0, base + MDM_CTL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static u_int neponset_get_mctrl(struct uart_port *port) |
| 129 | { |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 130 | void __iomem *base = nep_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR; |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 132 | u_int mdm_ctl1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 134 | if (!base) |
| 135 | return ret; |
| 136 | |
| 137 | mdm_ctl1 = readb_relaxed(base + MDM_CTL_1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | if (port->mapbase == _Ser1UTCR0) { |
| 139 | if (mdm_ctl1 & MDM_CTL1_DCD2) |
| 140 | ret &= ~TIOCM_CD; |
| 141 | if (mdm_ctl1 & MDM_CTL1_CTS2) |
| 142 | ret &= ~TIOCM_CTS; |
| 143 | if (mdm_ctl1 & MDM_CTL1_DSR2) |
| 144 | ret &= ~TIOCM_DSR; |
| 145 | } else if (port->mapbase == _Ser3UTCR0) { |
| 146 | if (mdm_ctl1 & MDM_CTL1_DCD1) |
| 147 | ret &= ~TIOCM_CD; |
| 148 | if (mdm_ctl1 & MDM_CTL1_CTS1) |
| 149 | ret &= ~TIOCM_CTS; |
| 150 | if (mdm_ctl1 & MDM_CTL1_DSR1) |
| 151 | ret &= ~TIOCM_DSR; |
| 152 | } |
| 153 | |
| 154 | return ret; |
| 155 | } |
| 156 | |
Russell King | cdea460 | 2007-05-30 17:48:45 +0100 | [diff] [blame] | 157 | static struct sa1100_port_fns neponset_port_fns __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | .set_mctrl = neponset_set_mctrl, |
| 159 | .get_mctrl = neponset_get_mctrl, |
| 160 | }; |
| 161 | |
Russell King | 7104552 | 2012-01-16 00:17:41 +0000 | [diff] [blame] | 162 | /* |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 163 | * Install handler for Neponset IRQ. Note that we have to loop here |
| 164 | * since the ETHERNET and USAR IRQs are level based, and we need to |
| 165 | * ensure that the IRQ signal is deasserted before returning. This |
| 166 | * is rather unfortunate. |
| 167 | */ |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 168 | static void neponset_irq_handler(unsigned int irq, struct irq_desc *desc) |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 169 | { |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 170 | struct neponset_drvdata *d = irq_desc_get_handler_data(desc); |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 171 | unsigned int irr; |
| 172 | |
| 173 | while (1) { |
| 174 | /* |
| 175 | * Acknowledge the parent IRQ. |
| 176 | */ |
| 177 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
| 178 | |
| 179 | /* |
| 180 | * Read the interrupt reason register. Let's have all |
| 181 | * active IRQ bits high. Note: there is a typo in the |
| 182 | * Neponset user's guide for the SA1111 IRR level. |
| 183 | */ |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 184 | irr = readb_relaxed(d->base + IRR); |
| 185 | irr ^= IRR_ETHERNET | IRR_USAR; |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 186 | |
| 187 | if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0) |
| 188 | break; |
| 189 | |
| 190 | /* |
| 191 | * Since there is no individual mask, we have to |
| 192 | * mask the parent IRQ. This is safe, since we'll |
| 193 | * recheck the register for any pending IRQs. |
| 194 | */ |
| 195 | if (irr & (IRR_ETHERNET | IRR_USAR)) { |
| 196 | desc->irq_data.chip->irq_mask(&desc->irq_data); |
| 197 | |
| 198 | /* |
| 199 | * Ack the interrupt now to prevent re-entering |
| 200 | * this neponset handler. Again, this is safe |
| 201 | * since we'll check the IRR register prior to |
| 202 | * leaving. |
| 203 | */ |
| 204 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
| 205 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 206 | if (irr & IRR_ETHERNET) |
| 207 | generic_handle_irq(d->irq_base + NEP_IRQ_SMC91X); |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 208 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 209 | if (irr & IRR_USAR) |
| 210 | generic_handle_irq(d->irq_base + NEP_IRQ_USAR); |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 211 | |
| 212 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
| 213 | } |
| 214 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 215 | if (irr & IRR_SA1111) |
| 216 | generic_handle_irq(d->irq_base + NEP_IRQ_SA1111); |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 220 | /* Yes, we really do not have any kind of masking or unmasking */ |
Russell King | 7104552 | 2012-01-16 00:17:41 +0000 | [diff] [blame] | 221 | static void nochip_noop(struct irq_data *irq) |
| 222 | { |
| 223 | } |
| 224 | |
| 225 | static struct irq_chip nochip = { |
| 226 | .name = "neponset", |
| 227 | .irq_ack = nochip_noop, |
| 228 | .irq_mask = nochip_noop, |
| 229 | .irq_unmask = nochip_noop, |
| 230 | }; |
| 231 | |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 232 | static struct sa1111_platform_data sa1111_info = { |
Russell King | 07be45f | 2012-01-26 13:34:21 +0000 | [diff] [blame] | 233 | .disable_devs = SA1111_DEVID_PS2_MSE, |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 234 | }; |
| 235 | |
Russell King | cdea460 | 2007-05-30 17:48:45 +0100 | [diff] [blame] | 236 | static int __devinit neponset_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 238 | struct neponset_drvdata *d; |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 239 | struct resource *nep_res, *sa1111_res, *smc91x_res; |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 240 | struct resource sa1111_resources[] = { |
| 241 | DEFINE_RES_MEM(0x40000000, SZ_8K), |
| 242 | { .flags = IORESOURCE_IRQ }, |
| 243 | }; |
Russell King | 9590e898 | 2012-01-24 22:36:47 +0000 | [diff] [blame] | 244 | struct platform_device_info sa1111_devinfo = { |
| 245 | .parent = &dev->dev, |
| 246 | .name = "sa1111", |
| 247 | .id = 0, |
| 248 | .res = sa1111_resources, |
| 249 | .num_res = ARRAY_SIZE(sa1111_resources), |
| 250 | .data = &sa1111_info, |
| 251 | .size_data = sizeof(sa1111_info), |
| 252 | .dma_mask = 0xffffffffUL, |
| 253 | }; |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 254 | struct resource smc91x_resources[] = { |
| 255 | DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS, |
| 256 | 0x02000000, "smc91x-regs"), |
| 257 | DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS + 0x02000000, |
| 258 | 0x02000000, "smc91x-attrib"), |
| 259 | { .flags = IORESOURCE_IRQ }, |
| 260 | }; |
Russell King | 9590e898 | 2012-01-24 22:36:47 +0000 | [diff] [blame] | 261 | struct platform_device_info smc91x_devinfo = { |
| 262 | .parent = &dev->dev, |
| 263 | .name = "smc91x", |
| 264 | .id = 0, |
| 265 | .res = smc91x_resources, |
| 266 | .num_res = ARRAY_SIZE(smc91x_resources), |
| 267 | }; |
Russell King | b6bdfcf | 2012-01-24 23:05:08 +0000 | [diff] [blame] | 268 | int ret, irq; |
| 269 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 270 | if (nep_base) |
| 271 | return -EBUSY; |
| 272 | |
Russell King | b6bdfcf | 2012-01-24 23:05:08 +0000 | [diff] [blame] | 273 | irq = ret = platform_get_irq(dev, 0); |
| 274 | if (ret < 0) |
| 275 | goto err_alloc; |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 276 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 277 | nep_res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
Russell King | d2e539a | 2012-01-24 23:17:37 +0000 | [diff] [blame] | 278 | smc91x_res = platform_get_resource(dev, IORESOURCE_MEM, 1); |
| 279 | sa1111_res = platform_get_resource(dev, IORESOURCE_MEM, 2); |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 280 | if (!nep_res || !smc91x_res || !sa1111_res) { |
Russell King | d2e539a | 2012-01-24 23:17:37 +0000 | [diff] [blame] | 281 | ret = -ENXIO; |
| 282 | goto err_alloc; |
| 283 | } |
| 284 | |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 285 | d = kzalloc(sizeof(*d), GFP_KERNEL); |
| 286 | if (!d) { |
| 287 | ret = -ENOMEM; |
| 288 | goto err_alloc; |
| 289 | } |
| 290 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 291 | d->base = ioremap(nep_res->start, SZ_4K); |
| 292 | if (!d->base) { |
| 293 | ret = -ENOMEM; |
| 294 | goto err_ioremap; |
| 295 | } |
| 296 | |
| 297 | if (readb_relaxed(d->base + WHOAMI) != 0x11) { |
| 298 | dev_warn(&dev->dev, "Neponset board detected, but wrong ID: %02x\n", |
| 299 | readb_relaxed(d->base + WHOAMI)); |
| 300 | ret = -ENODEV; |
| 301 | goto err_id; |
| 302 | } |
| 303 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 304 | ret = irq_alloc_descs(-1, IRQ_BOARD_START, NEP_IRQ_NR, -1); |
| 305 | if (ret <= 0) { |
| 306 | dev_err(&dev->dev, "unable to allocate %u irqs: %d\n", |
| 307 | NEP_IRQ_NR, ret); |
| 308 | if (ret == 0) |
| 309 | ret = -ENOMEM; |
| 310 | goto err_irq_alloc; |
| 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 313 | d->irq_base = ret; |
| 314 | |
| 315 | irq_set_chip_and_handler(d->irq_base + NEP_IRQ_SMC91X, &nochip, |
| 316 | handle_simple_irq); |
| 317 | set_irq_flags(d->irq_base + NEP_IRQ_SMC91X, IRQF_VALID | IRQF_PROBE); |
| 318 | irq_set_chip_and_handler(d->irq_base + NEP_IRQ_USAR, &nochip, |
| 319 | handle_simple_irq); |
| 320 | set_irq_flags(d->irq_base + NEP_IRQ_USAR, IRQF_VALID | IRQF_PROBE); |
| 321 | irq_set_chip(d->irq_base + NEP_IRQ_SA1111, &nochip); |
| 322 | |
Russell King | b6bdfcf | 2012-01-24 23:05:08 +0000 | [diff] [blame] | 323 | irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING); |
| 324 | irq_set_handler_data(irq, d); |
| 325 | irq_set_chained_handler(irq, neponset_irq_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | /* |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 328 | * We would set IRQ_GPIO25 to be a wake-up IRQ, but unfortunately |
| 329 | * something on the Neponset activates this IRQ on sleep (eth?) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | */ |
| 331 | #if 0 |
Russell King | b6bdfcf | 2012-01-24 23:05:08 +0000 | [diff] [blame] | 332 | enable_irq_wake(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | #endif |
| 334 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 335 | dev_info(&dev->dev, "Neponset daughter board, providing IRQ%u-%u\n", |
| 336 | d->irq_base, d->irq_base + NEP_IRQ_NR - 1); |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 337 | nep_base = d->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 339 | sa1100_register_uart_fns(&neponset_port_fns); |
| 340 | |
Russell King | bab50a3 | 2012-01-26 11:50:23 +0000 | [diff] [blame] | 341 | /* Ensure that the memory bus request/grant signals are setup */ |
| 342 | sa1110_mb_disable(); |
| 343 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 344 | /* Disable GPIO 0/1 drivers so the buttons work on the Assabet */ |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 345 | writeb_relaxed(NCR_GP01_OFF, d->base + NCR_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Russell King | d2e539a | 2012-01-24 23:17:37 +0000 | [diff] [blame] | 347 | sa1111_resources[0].parent = sa1111_res; |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 348 | sa1111_resources[1].start = d->irq_base + NEP_IRQ_SA1111; |
| 349 | sa1111_resources[1].end = d->irq_base + NEP_IRQ_SA1111; |
Russell King | 9590e898 | 2012-01-24 22:36:47 +0000 | [diff] [blame] | 350 | d->sa1111 = platform_device_register_full(&sa1111_devinfo); |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 351 | |
Russell King | d2e539a | 2012-01-24 23:17:37 +0000 | [diff] [blame] | 352 | smc91x_resources[0].parent = smc91x_res; |
| 353 | smc91x_resources[1].parent = smc91x_res; |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 354 | smc91x_resources[2].start = d->irq_base + NEP_IRQ_SMC91X; |
| 355 | smc91x_resources[2].end = d->irq_base + NEP_IRQ_SMC91X; |
Russell King | 9590e898 | 2012-01-24 22:36:47 +0000 | [diff] [blame] | 356 | d->smc91x = platform_device_register_full(&smc91x_devinfo); |
| 357 | |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 358 | platform_set_drvdata(dev, d); |
| 359 | |
| 360 | return 0; |
| 361 | |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 362 | err_irq_alloc: |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 363 | err_id: |
| 364 | iounmap(d->base); |
| 365 | err_ioremap: |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 366 | kfree(d); |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 367 | err_alloc: |
| 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | static int __devexit neponset_remove(struct platform_device *dev) |
| 372 | { |
| 373 | struct neponset_drvdata *d = platform_get_drvdata(dev); |
Russell King | b6bdfcf | 2012-01-24 23:05:08 +0000 | [diff] [blame] | 374 | int irq = platform_get_irq(dev, 0); |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 375 | |
Russell King | 9590e898 | 2012-01-24 22:36:47 +0000 | [diff] [blame] | 376 | if (!IS_ERR(d->sa1111)) |
| 377 | platform_device_unregister(d->sa1111); |
| 378 | if (!IS_ERR(d->smc91x)) |
| 379 | platform_device_unregister(d->smc91x); |
Russell King | b6bdfcf | 2012-01-24 23:05:08 +0000 | [diff] [blame] | 380 | irq_set_chained_handler(irq, NULL); |
Russell King | ced8d21 | 2012-01-24 22:22:18 +0000 | [diff] [blame] | 381 | irq_free_descs(d->irq_base, NEP_IRQ_NR); |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 382 | nep_base = NULL; |
| 383 | iounmap(d->base); |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 384 | kfree(d); |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | return 0; |
| 387 | } |
| 388 | |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 389 | #ifdef CONFIG_PM_SLEEP |
| 390 | static int neponset_suspend(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 392 | struct neponset_drvdata *d = dev_get_drvdata(dev); |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 393 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 394 | d->ncr0 = readb_relaxed(d->base + NCR_0); |
| 395 | d->mdm_ctl_0 = readb_relaxed(d->base + MDM_CTL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 400 | static int neponset_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 402 | struct neponset_drvdata *d = dev_get_drvdata(dev); |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 403 | |
Russell King | f942b0f | 2012-01-29 11:19:06 +0000 | [diff] [blame] | 404 | writeb_relaxed(d->ncr0, d->base + NCR_0); |
| 405 | writeb_relaxed(d->mdm_ctl_0, d->base + MDM_CTL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 410 | static const struct dev_pm_ops neponset_pm_ops = { |
| 411 | .suspend_noirq = neponset_suspend, |
| 412 | .resume_noirq = neponset_resume, |
| 413 | .freeze_noirq = neponset_suspend, |
| 414 | .restore_noirq = neponset_resume, |
| 415 | }; |
| 416 | #define PM_OPS &neponset_pm_ops |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | #else |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 418 | #define PM_OPS NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | #endif |
| 420 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 421 | static struct platform_driver neponset_device_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | .probe = neponset_probe, |
Russell King | ae14c2e | 2012-01-24 22:10:02 +0000 | [diff] [blame] | 423 | .remove = __devexit_p(neponset_remove), |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 424 | .driver = { |
| 425 | .name = "neponset", |
Russell King | 398e58d | 2012-01-24 23:33:28 +0000 | [diff] [blame] | 426 | .owner = THIS_MODULE, |
Russell King | 51f9339 | 2012-01-24 23:29:47 +0000 | [diff] [blame] | 427 | .pm = PM_OPS, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 428 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | }; |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | static int __init neponset_init(void) |
| 432 | { |
Russell King | bab50a3 | 2012-01-26 11:50:23 +0000 | [diff] [blame] | 433 | return platform_driver_register(&neponset_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | subsys_initcall(neponset_init); |