Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-sa1100/neponset.c |
| 3 | * |
| 4 | */ |
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 | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 7 | #include <linux/kernel.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 8 | #include <linux/platform_device.h> |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 9 | #include <linux/serial_core.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/mach-types.h> |
| 12 | #include <asm/irq.h> |
| 13 | #include <asm/mach/map.h> |
| 14 | #include <asm/mach/irq.h> |
| 15 | #include <asm/mach/serial_sa1100.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/hardware/sa1111.h> |
| 17 | #include <asm/sizes.h> |
| 18 | |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 19 | #include <mach/hardware.h> |
| 20 | #include <mach/assabet.h> |
| 21 | #include <mach/neponset.h> |
| 22 | |
Russell King | 6ad1b61 | 2012-01-16 09:31:47 +0000 | [diff] [blame] | 23 | void neponset_ncr_frob(unsigned int mask, unsigned int val) |
| 24 | { |
| 25 | unsigned long flags; |
| 26 | |
| 27 | local_irq_save(flags); |
| 28 | NCR_0 = (NCR_0 & ~mask) | val; |
| 29 | local_irq_restore(flags); |
| 30 | } |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static void neponset_set_mctrl(struct uart_port *port, u_int mctrl) |
| 33 | { |
| 34 | u_int mdm_ctl0 = MDM_CTL_0; |
| 35 | |
| 36 | if (port->mapbase == _Ser1UTCR0) { |
| 37 | if (mctrl & TIOCM_RTS) |
| 38 | mdm_ctl0 &= ~MDM_CTL0_RTS2; |
| 39 | else |
| 40 | mdm_ctl0 |= MDM_CTL0_RTS2; |
| 41 | |
| 42 | if (mctrl & TIOCM_DTR) |
| 43 | mdm_ctl0 &= ~MDM_CTL0_DTR2; |
| 44 | else |
| 45 | mdm_ctl0 |= MDM_CTL0_DTR2; |
| 46 | } else if (port->mapbase == _Ser3UTCR0) { |
| 47 | if (mctrl & TIOCM_RTS) |
| 48 | mdm_ctl0 &= ~MDM_CTL0_RTS1; |
| 49 | else |
| 50 | mdm_ctl0 |= MDM_CTL0_RTS1; |
| 51 | |
| 52 | if (mctrl & TIOCM_DTR) |
| 53 | mdm_ctl0 &= ~MDM_CTL0_DTR1; |
| 54 | else |
| 55 | mdm_ctl0 |= MDM_CTL0_DTR1; |
| 56 | } |
| 57 | |
| 58 | MDM_CTL_0 = mdm_ctl0; |
| 59 | } |
| 60 | |
| 61 | static u_int neponset_get_mctrl(struct uart_port *port) |
| 62 | { |
| 63 | u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR; |
| 64 | u_int mdm_ctl1 = MDM_CTL_1; |
| 65 | |
| 66 | if (port->mapbase == _Ser1UTCR0) { |
| 67 | if (mdm_ctl1 & MDM_CTL1_DCD2) |
| 68 | ret &= ~TIOCM_CD; |
| 69 | if (mdm_ctl1 & MDM_CTL1_CTS2) |
| 70 | ret &= ~TIOCM_CTS; |
| 71 | if (mdm_ctl1 & MDM_CTL1_DSR2) |
| 72 | ret &= ~TIOCM_DSR; |
| 73 | } else if (port->mapbase == _Ser3UTCR0) { |
| 74 | if (mdm_ctl1 & MDM_CTL1_DCD1) |
| 75 | ret &= ~TIOCM_CD; |
| 76 | if (mdm_ctl1 & MDM_CTL1_CTS1) |
| 77 | ret &= ~TIOCM_CTS; |
| 78 | if (mdm_ctl1 & MDM_CTL1_DSR1) |
| 79 | ret &= ~TIOCM_DSR; |
| 80 | } |
| 81 | |
| 82 | return ret; |
| 83 | } |
| 84 | |
Russell King | cdea460 | 2007-05-30 17:48:45 +0100 | [diff] [blame] | 85 | static struct sa1100_port_fns neponset_port_fns __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | .set_mctrl = neponset_set_mctrl, |
| 87 | .get_mctrl = neponset_get_mctrl, |
| 88 | }; |
| 89 | |
Russell King | 7104552 | 2012-01-16 00:17:41 +0000 | [diff] [blame] | 90 | /* |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 91 | * Install handler for Neponset IRQ. Note that we have to loop here |
| 92 | * since the ETHERNET and USAR IRQs are level based, and we need to |
| 93 | * ensure that the IRQ signal is deasserted before returning. This |
| 94 | * is rather unfortunate. |
| 95 | */ |
| 96 | static void |
| 97 | neponset_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 98 | { |
| 99 | unsigned int irr; |
| 100 | |
| 101 | while (1) { |
| 102 | /* |
| 103 | * Acknowledge the parent IRQ. |
| 104 | */ |
| 105 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
| 106 | |
| 107 | /* |
| 108 | * Read the interrupt reason register. Let's have all |
| 109 | * active IRQ bits high. Note: there is a typo in the |
| 110 | * Neponset user's guide for the SA1111 IRR level. |
| 111 | */ |
| 112 | irr = IRR ^ (IRR_ETHERNET | IRR_USAR); |
| 113 | |
| 114 | if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0) |
| 115 | break; |
| 116 | |
| 117 | /* |
| 118 | * Since there is no individual mask, we have to |
| 119 | * mask the parent IRQ. This is safe, since we'll |
| 120 | * recheck the register for any pending IRQs. |
| 121 | */ |
| 122 | if (irr & (IRR_ETHERNET | IRR_USAR)) { |
| 123 | desc->irq_data.chip->irq_mask(&desc->irq_data); |
| 124 | |
| 125 | /* |
| 126 | * Ack the interrupt now to prevent re-entering |
| 127 | * this neponset handler. Again, this is safe |
| 128 | * since we'll check the IRR register prior to |
| 129 | * leaving. |
| 130 | */ |
| 131 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
| 132 | |
| 133 | if (irr & IRR_ETHERNET) { |
| 134 | generic_handle_irq(IRQ_NEPONSET_SMC9196); |
| 135 | } |
| 136 | |
| 137 | if (irr & IRR_USAR) { |
| 138 | generic_handle_irq(IRQ_NEPONSET_USAR); |
| 139 | } |
| 140 | |
| 141 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
| 142 | } |
| 143 | |
| 144 | if (irr & IRR_SA1111) { |
| 145 | generic_handle_irq(IRQ_NEPONSET_SA1111); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /* |
Russell King | 7104552 | 2012-01-16 00:17:41 +0000 | [diff] [blame] | 151 | * Yes, we really do not have any kind of masking or unmasking |
| 152 | */ |
| 153 | static void nochip_noop(struct irq_data *irq) |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | static struct irq_chip nochip = { |
| 158 | .name = "neponset", |
| 159 | .irq_ack = nochip_noop, |
| 160 | .irq_mask = nochip_noop, |
| 161 | .irq_unmask = nochip_noop, |
| 162 | }; |
| 163 | |
Russell King | 92e617d | 2012-01-24 22:13:00 +0000 | [diff] [blame] | 164 | static struct resource sa1111_resources[] = { |
| 165 | [0] = DEFINE_RES_MEM(0x40000000, SZ_8K), |
| 166 | [1] = DEFINE_RES_IRQ(IRQ_NEPONSET_SA1111), |
| 167 | }; |
| 168 | |
| 169 | static struct sa1111_platform_data sa1111_info = { |
| 170 | .irq_base = IRQ_BOARD_END, |
| 171 | }; |
| 172 | |
| 173 | static u64 sa1111_dmamask = 0xffffffffUL; |
| 174 | |
| 175 | static struct platform_device sa1111_device = { |
| 176 | .name = "sa1111", |
| 177 | .id = 0, |
| 178 | .dev = { |
| 179 | .dma_mask = &sa1111_dmamask, |
| 180 | .coherent_dma_mask = 0xffffffff, |
| 181 | .platform_data = &sa1111_info, |
| 182 | }, |
| 183 | .num_resources = ARRAY_SIZE(sa1111_resources), |
| 184 | .resource = sa1111_resources, |
| 185 | }; |
| 186 | |
| 187 | static struct resource smc91x_resources[] = { |
| 188 | [0] = DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS, 0x02000000, "smc91x-regs"), |
| 189 | [1] = DEFINE_RES_IRQ(IRQ_NEPONSET_SMC9196), |
| 190 | [2] = DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS + 0x02000000, |
| 191 | 0x02000000, "smc91x-attrib"), |
| 192 | }; |
| 193 | |
| 194 | static struct platform_device smc91x_device = { |
| 195 | .name = "smc91x", |
| 196 | .id = 0, |
| 197 | .num_resources = ARRAY_SIZE(smc91x_resources), |
| 198 | .resource = smc91x_resources, |
| 199 | }; |
| 200 | |
Russell King | cdea460 | 2007-05-30 17:48:45 +0100 | [diff] [blame] | 201 | static int __devinit neponset_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
| 203 | sa1100_register_uart_fns(&neponset_port_fns); |
| 204 | |
| 205 | /* |
| 206 | * Install handler for GPIO25. |
| 207 | */ |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 208 | irq_set_irq_type(IRQ_GPIO25, IRQ_TYPE_EDGE_RISING); |
| 209 | irq_set_chained_handler(IRQ_GPIO25, neponset_irq_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * We would set IRQ_GPIO25 to be a wake-up IRQ, but |
| 213 | * unfortunately something on the Neponset activates |
| 214 | * this IRQ on sleep (ethernet?) |
| 215 | */ |
| 216 | #if 0 |
| 217 | enable_irq_wake(IRQ_GPIO25); |
| 218 | #endif |
| 219 | |
| 220 | /* |
| 221 | * Setup other Neponset IRQs. SA1111 will be done by the |
| 222 | * generic SA1111 code. |
| 223 | */ |
Russell King | 7104552 | 2012-01-16 00:17:41 +0000 | [diff] [blame] | 224 | irq_set_chip_and_handler(IRQ_NEPONSET_SMC9196, &nochip, |
| 225 | handle_simple_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | set_irq_flags(IRQ_NEPONSET_SMC9196, IRQF_VALID | IRQF_PROBE); |
Russell King | 7104552 | 2012-01-16 00:17:41 +0000 | [diff] [blame] | 227 | irq_set_chip_and_handler(IRQ_NEPONSET_USAR, &nochip, |
| 228 | handle_simple_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | set_irq_flags(IRQ_NEPONSET_USAR, IRQF_VALID | IRQF_PROBE); |
Russell King | 7104552 | 2012-01-16 00:17:41 +0000 | [diff] [blame] | 230 | irq_set_chip(IRQ_NEPONSET_SA1111, &nochip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | /* |
| 233 | * Disable GPIO 0/1 drivers so the buttons work on the module. |
| 234 | */ |
| 235 | NCR_0 = NCR_GP01_OFF; |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | #ifdef CONFIG_PM |
| 241 | |
| 242 | /* |
| 243 | * LDM power management. |
| 244 | */ |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 245 | static unsigned int neponset_saved_state; |
| 246 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 247 | static int neponset_suspend(struct platform_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
| 249 | /* |
| 250 | * Save state. |
| 251 | */ |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 252 | neponset_saved_state = NCR_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 257 | static int neponset_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 259 | NCR_0 = neponset_saved_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | #else |
| 265 | #define neponset_suspend NULL |
| 266 | #define neponset_resume NULL |
| 267 | #endif |
| 268 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 269 | static struct platform_driver neponset_device_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | .probe = neponset_probe, |
| 271 | .suspend = neponset_suspend, |
| 272 | .resume = neponset_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 273 | .driver = { |
| 274 | .name = "neponset", |
Russell King | 398e58d | 2012-01-24 23:33:28 +0000 | [diff] [blame^] | 275 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 276 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | static struct resource neponset_resources[] = { |
Russell King | a181099 | 2012-01-12 10:25:29 +0000 | [diff] [blame] | 280 | [0] = DEFINE_RES_MEM(0x10000000, 0x08000000), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | static struct platform_device neponset_device = { |
| 284 | .name = "neponset", |
| 285 | .id = 0, |
| 286 | .num_resources = ARRAY_SIZE(neponset_resources), |
| 287 | .resource = neponset_resources, |
| 288 | }; |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | static struct platform_device *devices[] __initdata = { |
| 291 | &neponset_device, |
| 292 | &sa1111_device, |
| 293 | &smc91x_device, |
| 294 | }; |
| 295 | |
Russell King | cdcb81f | 2007-07-20 10:32:46 +0100 | [diff] [blame] | 296 | extern void sa1110_mb_disable(void); |
| 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | static int __init neponset_init(void) |
| 299 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 300 | platform_driver_register(&neponset_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * The Neponset is only present on the Assabet machine type. |
| 304 | */ |
| 305 | if (!machine_is_assabet()) |
| 306 | return -ENODEV; |
| 307 | |
| 308 | /* |
| 309 | * Ensure that the memory bus request/grant signals are setup, |
| 310 | * and the grant is held in its inactive state, whether or not |
| 311 | * we actually have a Neponset attached. |
| 312 | */ |
| 313 | sa1110_mb_disable(); |
| 314 | |
| 315 | if (!machine_has_neponset()) { |
| 316 | printk(KERN_DEBUG "Neponset expansion board not present\n"); |
| 317 | return -ENODEV; |
| 318 | } |
| 319 | |
| 320 | if (WHOAMI != 0x11) { |
| 321 | printk(KERN_WARNING "Neponset board detected, but " |
| 322 | "wrong ID: %02x\n", WHOAMI); |
| 323 | return -ENODEV; |
| 324 | } |
| 325 | |
| 326 | return platform_add_devices(devices, ARRAY_SIZE(devices)); |
| 327 | } |
| 328 | |
| 329 | subsys_initcall(neponset_init); |
| 330 | |
| 331 | static struct map_desc neponset_io_desc[] __initdata = { |
Deepak Saxena | 92519d8 | 2005-10-28 15:19:04 +0100 | [diff] [blame] | 332 | { /* System Registers */ |
| 333 | .virtual = 0xf3000000, |
| 334 | .pfn = __phys_to_pfn(0x10000000), |
| 335 | .length = SZ_1M, |
| 336 | .type = MT_DEVICE |
| 337 | }, { /* SA-1111 */ |
| 338 | .virtual = 0xf4000000, |
| 339 | .pfn = __phys_to_pfn(0x40000000), |
| 340 | .length = SZ_1M, |
| 341 | .type = MT_DEVICE |
| 342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | void __init neponset_map_io(void) |
| 346 | { |
| 347 | iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc)); |
| 348 | } |