blob: 59223baa7c1df6f6899a06ce4d0ccc49d52e42f8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/neponset.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 */
Russell King9590e892012-01-24 22:36:47 +00004#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/ioport.h>
Russell Kingced8d212012-01-24 22:22:18 +00007#include <linux/irq.h>
Russell King92e617d2012-01-24 22:13:00 +00008#include <linux/kernel.h>
Russell Kingae14c2e2012-01-24 22:10:02 +00009#include <linux/module.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010010#include <linux/platform_device.h>
Russell King51f93392012-01-24 23:29:47 +000011#include <linux/pm.h>
Russell King92e617d2012-01-24 22:13:00 +000012#include <linux/serial_core.h>
Russell Kingae14c2e2012-01-24 22:10:02 +000013#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/mach/map.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/mach/serial_sa1100.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/hardware/sa1111.h>
19#include <asm/sizes.h>
20
Russell King92e617d2012-01-24 22:13:00 +000021#include <mach/hardware.h>
22#include <mach/assabet.h>
23#include <mach/neponset.h>
24
Russell Kingced8d212012-01-24 22:22:18 +000025#define NEP_IRQ_SMC91X 0
26#define NEP_IRQ_USAR 1
27#define NEP_IRQ_SA1111 2
28#define NEP_IRQ_NR 3
29
Russell Kingae14c2e2012-01-24 22:10:02 +000030struct neponset_drvdata {
Russell King9590e892012-01-24 22:36:47 +000031 struct platform_device *sa1111;
32 struct platform_device *smc91x;
Russell Kingced8d212012-01-24 22:22:18 +000033 unsigned irq_base;
Russell Kingae14c2e2012-01-24 22:10:02 +000034#ifdef CONFIG_PM_SLEEP
35 u32 ncr0;
36 u32 mdm_ctl_0;
37#endif
38};
39
Russell King6ad1b612012-01-16 09:31:47 +000040void neponset_ncr_frob(unsigned int mask, unsigned int val)
41{
42 unsigned long flags;
43
44 local_irq_save(flags);
45 NCR_0 = (NCR_0 & ~mask) | val;
46 local_irq_restore(flags);
47}
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
50{
51 u_int mdm_ctl0 = MDM_CTL_0;
52
53 if (port->mapbase == _Ser1UTCR0) {
54 if (mctrl & TIOCM_RTS)
55 mdm_ctl0 &= ~MDM_CTL0_RTS2;
56 else
57 mdm_ctl0 |= MDM_CTL0_RTS2;
58
59 if (mctrl & TIOCM_DTR)
60 mdm_ctl0 &= ~MDM_CTL0_DTR2;
61 else
62 mdm_ctl0 |= MDM_CTL0_DTR2;
63 } else if (port->mapbase == _Ser3UTCR0) {
64 if (mctrl & TIOCM_RTS)
65 mdm_ctl0 &= ~MDM_CTL0_RTS1;
66 else
67 mdm_ctl0 |= MDM_CTL0_RTS1;
68
69 if (mctrl & TIOCM_DTR)
70 mdm_ctl0 &= ~MDM_CTL0_DTR1;
71 else
72 mdm_ctl0 |= MDM_CTL0_DTR1;
73 }
74
75 MDM_CTL_0 = mdm_ctl0;
76}
77
78static u_int neponset_get_mctrl(struct uart_port *port)
79{
80 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
81 u_int mdm_ctl1 = MDM_CTL_1;
82
83 if (port->mapbase == _Ser1UTCR0) {
84 if (mdm_ctl1 & MDM_CTL1_DCD2)
85 ret &= ~TIOCM_CD;
86 if (mdm_ctl1 & MDM_CTL1_CTS2)
87 ret &= ~TIOCM_CTS;
88 if (mdm_ctl1 & MDM_CTL1_DSR2)
89 ret &= ~TIOCM_DSR;
90 } else if (port->mapbase == _Ser3UTCR0) {
91 if (mdm_ctl1 & MDM_CTL1_DCD1)
92 ret &= ~TIOCM_CD;
93 if (mdm_ctl1 & MDM_CTL1_CTS1)
94 ret &= ~TIOCM_CTS;
95 if (mdm_ctl1 & MDM_CTL1_DSR1)
96 ret &= ~TIOCM_DSR;
97 }
98
99 return ret;
100}
101
Russell Kingcdea4602007-05-30 17:48:45 +0100102static struct sa1100_port_fns neponset_port_fns __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 .set_mctrl = neponset_set_mctrl,
104 .get_mctrl = neponset_get_mctrl,
105};
106
Russell King71045522012-01-16 00:17:41 +0000107/*
Russell King92e617d2012-01-24 22:13:00 +0000108 * Install handler for Neponset IRQ. Note that we have to loop here
109 * since the ETHERNET and USAR IRQs are level based, and we need to
110 * ensure that the IRQ signal is deasserted before returning. This
111 * is rather unfortunate.
112 */
Russell Kingced8d212012-01-24 22:22:18 +0000113static void neponset_irq_handler(unsigned int irq, struct irq_desc *desc)
Russell King92e617d2012-01-24 22:13:00 +0000114{
Russell Kingced8d212012-01-24 22:22:18 +0000115 struct neponset_drvdata *d = irq_desc_get_handler_data(desc);
Russell King92e617d2012-01-24 22:13:00 +0000116 unsigned int irr;
117
118 while (1) {
119 /*
120 * Acknowledge the parent IRQ.
121 */
122 desc->irq_data.chip->irq_ack(&desc->irq_data);
123
124 /*
125 * Read the interrupt reason register. Let's have all
126 * active IRQ bits high. Note: there is a typo in the
127 * Neponset user's guide for the SA1111 IRR level.
128 */
129 irr = IRR ^ (IRR_ETHERNET | IRR_USAR);
130
131 if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
132 break;
133
134 /*
135 * Since there is no individual mask, we have to
136 * mask the parent IRQ. This is safe, since we'll
137 * recheck the register for any pending IRQs.
138 */
139 if (irr & (IRR_ETHERNET | IRR_USAR)) {
140 desc->irq_data.chip->irq_mask(&desc->irq_data);
141
142 /*
143 * Ack the interrupt now to prevent re-entering
144 * this neponset handler. Again, this is safe
145 * since we'll check the IRR register prior to
146 * leaving.
147 */
148 desc->irq_data.chip->irq_ack(&desc->irq_data);
149
Russell Kingced8d212012-01-24 22:22:18 +0000150 if (irr & IRR_ETHERNET)
151 generic_handle_irq(d->irq_base + NEP_IRQ_SMC91X);
Russell King92e617d2012-01-24 22:13:00 +0000152
Russell Kingced8d212012-01-24 22:22:18 +0000153 if (irr & IRR_USAR)
154 generic_handle_irq(d->irq_base + NEP_IRQ_USAR);
Russell King92e617d2012-01-24 22:13:00 +0000155
156 desc->irq_data.chip->irq_unmask(&desc->irq_data);
157 }
158
Russell Kingced8d212012-01-24 22:22:18 +0000159 if (irr & IRR_SA1111)
160 generic_handle_irq(d->irq_base + NEP_IRQ_SA1111);
Russell King92e617d2012-01-24 22:13:00 +0000161 }
162}
163
Russell Kingced8d212012-01-24 22:22:18 +0000164/* Yes, we really do not have any kind of masking or unmasking */
Russell King71045522012-01-16 00:17:41 +0000165static void nochip_noop(struct irq_data *irq)
166{
167}
168
169static struct irq_chip nochip = {
170 .name = "neponset",
171 .irq_ack = nochip_noop,
172 .irq_mask = nochip_noop,
173 .irq_unmask = nochip_noop,
174};
175
Russell King92e617d2012-01-24 22:13:00 +0000176static struct sa1111_platform_data sa1111_info = {
177 .irq_base = IRQ_BOARD_END,
178};
179
Russell Kingcdea4602007-05-30 17:48:45 +0100180static int __devinit neponset_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Russell Kingae14c2e2012-01-24 22:10:02 +0000182 struct neponset_drvdata *d;
Russell Kingd2e539a2012-01-24 23:17:37 +0000183 struct resource *sa1111_res, *smc91x_res;
Russell Kingced8d212012-01-24 22:22:18 +0000184 struct resource sa1111_resources[] = {
185 DEFINE_RES_MEM(0x40000000, SZ_8K),
186 { .flags = IORESOURCE_IRQ },
187 };
Russell King9590e892012-01-24 22:36:47 +0000188 struct platform_device_info sa1111_devinfo = {
189 .parent = &dev->dev,
190 .name = "sa1111",
191 .id = 0,
192 .res = sa1111_resources,
193 .num_res = ARRAY_SIZE(sa1111_resources),
194 .data = &sa1111_info,
195 .size_data = sizeof(sa1111_info),
196 .dma_mask = 0xffffffffUL,
197 };
Russell Kingced8d212012-01-24 22:22:18 +0000198 struct resource smc91x_resources[] = {
199 DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS,
200 0x02000000, "smc91x-regs"),
201 DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS + 0x02000000,
202 0x02000000, "smc91x-attrib"),
203 { .flags = IORESOURCE_IRQ },
204 };
Russell King9590e892012-01-24 22:36:47 +0000205 struct platform_device_info smc91x_devinfo = {
206 .parent = &dev->dev,
207 .name = "smc91x",
208 .id = 0,
209 .res = smc91x_resources,
210 .num_res = ARRAY_SIZE(smc91x_resources),
211 };
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000212 int ret, irq;
213
214 irq = ret = platform_get_irq(dev, 0);
215 if (ret < 0)
216 goto err_alloc;
Russell Kingae14c2e2012-01-24 22:10:02 +0000217
Russell Kingd2e539a2012-01-24 23:17:37 +0000218 smc91x_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
219 sa1111_res = platform_get_resource(dev, IORESOURCE_MEM, 2);
220 if (!smc91x_res || !sa1111_res) {
221 ret = -ENXIO;
222 goto err_alloc;
223 }
224
Russell Kingae14c2e2012-01-24 22:10:02 +0000225 d = kzalloc(sizeof(*d), GFP_KERNEL);
226 if (!d) {
227 ret = -ENOMEM;
228 goto err_alloc;
229 }
230
Russell Kingced8d212012-01-24 22:22:18 +0000231 ret = irq_alloc_descs(-1, IRQ_BOARD_START, NEP_IRQ_NR, -1);
232 if (ret <= 0) {
233 dev_err(&dev->dev, "unable to allocate %u irqs: %d\n",
234 NEP_IRQ_NR, ret);
235 if (ret == 0)
236 ret = -ENOMEM;
237 goto err_irq_alloc;
238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Russell Kingced8d212012-01-24 22:22:18 +0000240 d->irq_base = ret;
241
242 irq_set_chip_and_handler(d->irq_base + NEP_IRQ_SMC91X, &nochip,
243 handle_simple_irq);
244 set_irq_flags(d->irq_base + NEP_IRQ_SMC91X, IRQF_VALID | IRQF_PROBE);
245 irq_set_chip_and_handler(d->irq_base + NEP_IRQ_USAR, &nochip,
246 handle_simple_irq);
247 set_irq_flags(d->irq_base + NEP_IRQ_USAR, IRQF_VALID | IRQF_PROBE);
248 irq_set_chip(d->irq_base + NEP_IRQ_SA1111, &nochip);
249
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000250 irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
251 irq_set_handler_data(irq, d);
252 irq_set_chained_handler(irq, neponset_irq_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 /*
Russell Kingced8d212012-01-24 22:22:18 +0000255 * We would set IRQ_GPIO25 to be a wake-up IRQ, but unfortunately
256 * something on the Neponset activates this IRQ on sleep (eth?)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 */
258#if 0
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000259 enable_irq_wake(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#endif
261
Russell Kingced8d212012-01-24 22:22:18 +0000262 dev_info(&dev->dev, "Neponset daughter board, providing IRQ%u-%u\n",
263 d->irq_base, d->irq_base + NEP_IRQ_NR - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Russell Kingced8d212012-01-24 22:22:18 +0000265 sa1100_register_uart_fns(&neponset_port_fns);
266
267 /* Disable GPIO 0/1 drivers so the buttons work on the Assabet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 NCR_0 = NCR_GP01_OFF;
269
Russell Kingd2e539a2012-01-24 23:17:37 +0000270 sa1111_resources[0].parent = sa1111_res;
Russell Kingced8d212012-01-24 22:22:18 +0000271 sa1111_resources[1].start = d->irq_base + NEP_IRQ_SA1111;
272 sa1111_resources[1].end = d->irq_base + NEP_IRQ_SA1111;
Russell King9590e892012-01-24 22:36:47 +0000273 d->sa1111 = platform_device_register_full(&sa1111_devinfo);
Russell Kingced8d212012-01-24 22:22:18 +0000274
Russell Kingd2e539a2012-01-24 23:17:37 +0000275 smc91x_resources[0].parent = smc91x_res;
276 smc91x_resources[1].parent = smc91x_res;
Russell Kingced8d212012-01-24 22:22:18 +0000277 smc91x_resources[2].start = d->irq_base + NEP_IRQ_SMC91X;
278 smc91x_resources[2].end = d->irq_base + NEP_IRQ_SMC91X;
Russell King9590e892012-01-24 22:36:47 +0000279 d->smc91x = platform_device_register_full(&smc91x_devinfo);
280
Russell Kingae14c2e2012-01-24 22:10:02 +0000281 platform_set_drvdata(dev, d);
282
283 return 0;
284
Russell Kingced8d212012-01-24 22:22:18 +0000285 err_irq_alloc:
286 kfree(d);
Russell Kingae14c2e2012-01-24 22:10:02 +0000287 err_alloc:
288 return ret;
289}
290
291static int __devexit neponset_remove(struct platform_device *dev)
292{
293 struct neponset_drvdata *d = platform_get_drvdata(dev);
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000294 int irq = platform_get_irq(dev, 0);
Russell Kingae14c2e2012-01-24 22:10:02 +0000295
Russell King9590e892012-01-24 22:36:47 +0000296 if (!IS_ERR(d->sa1111))
297 platform_device_unregister(d->sa1111);
298 if (!IS_ERR(d->smc91x))
299 platform_device_unregister(d->smc91x);
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000300 irq_set_chained_handler(irq, NULL);
Russell Kingced8d212012-01-24 22:22:18 +0000301 irq_free_descs(d->irq_base, NEP_IRQ_NR);
Russell Kingae14c2e2012-01-24 22:10:02 +0000302 kfree(d);
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 return 0;
305}
306
Russell King51f93392012-01-24 23:29:47 +0000307#ifdef CONFIG_PM_SLEEP
308static int neponset_suspend(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Russell King51f93392012-01-24 23:29:47 +0000310 struct neponset_drvdata *d = dev_get_drvdata(dev);
Russell Kingae14c2e2012-01-24 22:10:02 +0000311
312 d->ncr0 = NCR_0;
313 d->mdm_ctl_0 = MDM_CTL_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 return 0;
316}
317
Russell King51f93392012-01-24 23:29:47 +0000318static int neponset_resume(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Russell King51f93392012-01-24 23:29:47 +0000320 struct neponset_drvdata *d = dev_get_drvdata(dev);
Russell Kingae14c2e2012-01-24 22:10:02 +0000321
322 NCR_0 = d->ncr0;
323 MDM_CTL_0 = d->mdm_ctl_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 return 0;
326}
327
Russell King51f93392012-01-24 23:29:47 +0000328static const struct dev_pm_ops neponset_pm_ops = {
329 .suspend_noirq = neponset_suspend,
330 .resume_noirq = neponset_resume,
331 .freeze_noirq = neponset_suspend,
332 .restore_noirq = neponset_resume,
333};
334#define PM_OPS &neponset_pm_ops
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#else
Russell King51f93392012-01-24 23:29:47 +0000336#define PM_OPS NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337#endif
338
Russell King3ae5eae2005-11-09 22:32:44 +0000339static struct platform_driver neponset_device_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 .probe = neponset_probe,
Russell Kingae14c2e2012-01-24 22:10:02 +0000341 .remove = __devexit_p(neponset_remove),
Russell King3ae5eae2005-11-09 22:32:44 +0000342 .driver = {
343 .name = "neponset",
Russell King398e58d2012-01-24 23:33:28 +0000344 .owner = THIS_MODULE,
Russell King51f93392012-01-24 23:29:47 +0000345 .pm = PM_OPS,
Russell King3ae5eae2005-11-09 22:32:44 +0000346 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347};
348
349static struct resource neponset_resources[] = {
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000350 DEFINE_RES_MEM(0x10000000, 0x08000000),
Russell Kingd2e539a2012-01-24 23:17:37 +0000351 DEFINE_RES_MEM(0x18000000, 0x04000000),
352 DEFINE_RES_MEM(0x40000000, SZ_8K),
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000353 DEFINE_RES_IRQ(IRQ_GPIO25),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
356static struct platform_device neponset_device = {
357 .name = "neponset",
358 .id = 0,
359 .num_resources = ARRAY_SIZE(neponset_resources),
360 .resource = neponset_resources,
361};
362
Russell Kingcdcb81f2007-07-20 10:32:46 +0100363extern void sa1110_mb_disable(void);
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365static int __init neponset_init(void)
366{
Russell King3ae5eae2005-11-09 22:32:44 +0000367 platform_driver_register(&neponset_device_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 /*
370 * The Neponset is only present on the Assabet machine type.
371 */
372 if (!machine_is_assabet())
373 return -ENODEV;
374
375 /*
376 * Ensure that the memory bus request/grant signals are setup,
377 * and the grant is held in its inactive state, whether or not
378 * we actually have a Neponset attached.
379 */
380 sa1110_mb_disable();
381
382 if (!machine_has_neponset()) {
383 printk(KERN_DEBUG "Neponset expansion board not present\n");
384 return -ENODEV;
385 }
386
387 if (WHOAMI != 0x11) {
388 printk(KERN_WARNING "Neponset board detected, but "
389 "wrong ID: %02x\n", WHOAMI);
390 return -ENODEV;
391 }
392
Russell King9590e892012-01-24 22:36:47 +0000393 return platform_device_register(&neponset_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
396subsys_initcall(neponset_init);
397
398static struct map_desc neponset_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100399 { /* System Registers */
400 .virtual = 0xf3000000,
401 .pfn = __phys_to_pfn(0x10000000),
402 .length = SZ_1M,
403 .type = MT_DEVICE
404 }, { /* SA-1111 */
405 .virtual = 0xf4000000,
406 .pfn = __phys_to_pfn(0x40000000),
407 .length = SZ_1M,
408 .type = MT_DEVICE
409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410};
411
412void __init neponset_map_io(void)
413{
414 iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc));
415}