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