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