blob: 2a9e1e2223f0f3c0a2aa3e2c1308d7c35b5dc69a [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 Kingbab50a32012-01-26 11:50:23 +000030extern void sa1110_mb_disable(void);
31
Russell Kingae14c2e2012-01-24 22:10:02 +000032struct neponset_drvdata {
Russell King9590e892012-01-24 22:36:47 +000033 struct platform_device *sa1111;
34 struct platform_device *smc91x;
Russell Kingced8d212012-01-24 22:22:18 +000035 unsigned irq_base;
Russell Kingae14c2e2012-01-24 22:10:02 +000036#ifdef CONFIG_PM_SLEEP
37 u32 ncr0;
38 u32 mdm_ctl_0;
39#endif
40};
41
Russell King6ad1b612012-01-16 09:31:47 +000042void neponset_ncr_frob(unsigned int mask, unsigned int val)
43{
44 unsigned long flags;
45
46 local_irq_save(flags);
47 NCR_0 = (NCR_0 & ~mask) | val;
48 local_irq_restore(flags);
49}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
52{
53 u_int mdm_ctl0 = MDM_CTL_0;
54
55 if (port->mapbase == _Ser1UTCR0) {
56 if (mctrl & TIOCM_RTS)
57 mdm_ctl0 &= ~MDM_CTL0_RTS2;
58 else
59 mdm_ctl0 |= MDM_CTL0_RTS2;
60
61 if (mctrl & TIOCM_DTR)
62 mdm_ctl0 &= ~MDM_CTL0_DTR2;
63 else
64 mdm_ctl0 |= MDM_CTL0_DTR2;
65 } else if (port->mapbase == _Ser3UTCR0) {
66 if (mctrl & TIOCM_RTS)
67 mdm_ctl0 &= ~MDM_CTL0_RTS1;
68 else
69 mdm_ctl0 |= MDM_CTL0_RTS1;
70
71 if (mctrl & TIOCM_DTR)
72 mdm_ctl0 &= ~MDM_CTL0_DTR1;
73 else
74 mdm_ctl0 |= MDM_CTL0_DTR1;
75 }
76
77 MDM_CTL_0 = mdm_ctl0;
78}
79
80static u_int neponset_get_mctrl(struct uart_port *port)
81{
82 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
83 u_int mdm_ctl1 = MDM_CTL_1;
84
85 if (port->mapbase == _Ser1UTCR0) {
86 if (mdm_ctl1 & MDM_CTL1_DCD2)
87 ret &= ~TIOCM_CD;
88 if (mdm_ctl1 & MDM_CTL1_CTS2)
89 ret &= ~TIOCM_CTS;
90 if (mdm_ctl1 & MDM_CTL1_DSR2)
91 ret &= ~TIOCM_DSR;
92 } else if (port->mapbase == _Ser3UTCR0) {
93 if (mdm_ctl1 & MDM_CTL1_DCD1)
94 ret &= ~TIOCM_CD;
95 if (mdm_ctl1 & MDM_CTL1_CTS1)
96 ret &= ~TIOCM_CTS;
97 if (mdm_ctl1 & MDM_CTL1_DSR1)
98 ret &= ~TIOCM_DSR;
99 }
100
101 return ret;
102}
103
Russell Kingcdea4602007-05-30 17:48:45 +0100104static struct sa1100_port_fns neponset_port_fns __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .set_mctrl = neponset_set_mctrl,
106 .get_mctrl = neponset_get_mctrl,
107};
108
Russell King71045522012-01-16 00:17:41 +0000109/*
Russell King92e617d2012-01-24 22:13:00 +0000110 * Install handler for Neponset IRQ. Note that we have to loop here
111 * since the ETHERNET and USAR IRQs are level based, and we need to
112 * ensure that the IRQ signal is deasserted before returning. This
113 * is rather unfortunate.
114 */
Russell Kingced8d212012-01-24 22:22:18 +0000115static void neponset_irq_handler(unsigned int irq, struct irq_desc *desc)
Russell King92e617d2012-01-24 22:13:00 +0000116{
Russell Kingced8d212012-01-24 22:22:18 +0000117 struct neponset_drvdata *d = irq_desc_get_handler_data(desc);
Russell King92e617d2012-01-24 22:13:00 +0000118 unsigned int irr;
119
120 while (1) {
121 /*
122 * Acknowledge the parent IRQ.
123 */
124 desc->irq_data.chip->irq_ack(&desc->irq_data);
125
126 /*
127 * Read the interrupt reason register. Let's have all
128 * active IRQ bits high. Note: there is a typo in the
129 * Neponset user's guide for the SA1111 IRR level.
130 */
131 irr = IRR ^ (IRR_ETHERNET | IRR_USAR);
132
133 if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
134 break;
135
136 /*
137 * Since there is no individual mask, we have to
138 * mask the parent IRQ. This is safe, since we'll
139 * recheck the register for any pending IRQs.
140 */
141 if (irr & (IRR_ETHERNET | IRR_USAR)) {
142 desc->irq_data.chip->irq_mask(&desc->irq_data);
143
144 /*
145 * Ack the interrupt now to prevent re-entering
146 * this neponset handler. Again, this is safe
147 * since we'll check the IRR register prior to
148 * leaving.
149 */
150 desc->irq_data.chip->irq_ack(&desc->irq_data);
151
Russell Kingced8d212012-01-24 22:22:18 +0000152 if (irr & IRR_ETHERNET)
153 generic_handle_irq(d->irq_base + NEP_IRQ_SMC91X);
Russell King92e617d2012-01-24 22:13:00 +0000154
Russell Kingced8d212012-01-24 22:22:18 +0000155 if (irr & IRR_USAR)
156 generic_handle_irq(d->irq_base + NEP_IRQ_USAR);
Russell King92e617d2012-01-24 22:13:00 +0000157
158 desc->irq_data.chip->irq_unmask(&desc->irq_data);
159 }
160
Russell Kingced8d212012-01-24 22:22:18 +0000161 if (irr & IRR_SA1111)
162 generic_handle_irq(d->irq_base + NEP_IRQ_SA1111);
Russell King92e617d2012-01-24 22:13:00 +0000163 }
164}
165
Russell Kingced8d212012-01-24 22:22:18 +0000166/* Yes, we really do not have any kind of masking or unmasking */
Russell King71045522012-01-16 00:17:41 +0000167static void nochip_noop(struct irq_data *irq)
168{
169}
170
171static struct irq_chip nochip = {
172 .name = "neponset",
173 .irq_ack = nochip_noop,
174 .irq_mask = nochip_noop,
175 .irq_unmask = nochip_noop,
176};
177
Russell King92e617d2012-01-24 22:13:00 +0000178static struct sa1111_platform_data sa1111_info = {
179 .irq_base = IRQ_BOARD_END,
180};
181
Russell Kingcdea4602007-05-30 17:48:45 +0100182static int __devinit neponset_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Russell Kingae14c2e2012-01-24 22:10:02 +0000184 struct neponset_drvdata *d;
Russell Kingd2e539a2012-01-24 23:17:37 +0000185 struct resource *sa1111_res, *smc91x_res;
Russell Kingced8d212012-01-24 22:22:18 +0000186 struct resource sa1111_resources[] = {
187 DEFINE_RES_MEM(0x40000000, SZ_8K),
188 { .flags = IORESOURCE_IRQ },
189 };
Russell King9590e892012-01-24 22:36:47 +0000190 struct platform_device_info sa1111_devinfo = {
191 .parent = &dev->dev,
192 .name = "sa1111",
193 .id = 0,
194 .res = sa1111_resources,
195 .num_res = ARRAY_SIZE(sa1111_resources),
196 .data = &sa1111_info,
197 .size_data = sizeof(sa1111_info),
198 .dma_mask = 0xffffffffUL,
199 };
Russell Kingced8d212012-01-24 22:22:18 +0000200 struct resource smc91x_resources[] = {
201 DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS,
202 0x02000000, "smc91x-regs"),
203 DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS + 0x02000000,
204 0x02000000, "smc91x-attrib"),
205 { .flags = IORESOURCE_IRQ },
206 };
Russell King9590e892012-01-24 22:36:47 +0000207 struct platform_device_info smc91x_devinfo = {
208 .parent = &dev->dev,
209 .name = "smc91x",
210 .id = 0,
211 .res = smc91x_resources,
212 .num_res = ARRAY_SIZE(smc91x_resources),
213 };
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000214 int ret, irq;
215
216 irq = ret = platform_get_irq(dev, 0);
217 if (ret < 0)
218 goto err_alloc;
Russell Kingae14c2e2012-01-24 22:10:02 +0000219
Russell Kingd2e539a2012-01-24 23:17:37 +0000220 smc91x_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
221 sa1111_res = platform_get_resource(dev, IORESOURCE_MEM, 2);
222 if (!smc91x_res || !sa1111_res) {
223 ret = -ENXIO;
224 goto err_alloc;
225 }
226
Russell Kingbab50a32012-01-26 11:50:23 +0000227 if (WHOAMI != 0x11) {
228 dev_warn(&dev->dev, "Neponset board detected, but wrong ID: %02x\n",
229 WHOAMI);
230 ret = -ENODEV;
231 goto err_alloc;
232 }
233
Russell Kingae14c2e2012-01-24 22:10:02 +0000234 d = kzalloc(sizeof(*d), GFP_KERNEL);
235 if (!d) {
236 ret = -ENOMEM;
237 goto err_alloc;
238 }
239
Russell Kingced8d212012-01-24 22:22:18 +0000240 ret = irq_alloc_descs(-1, IRQ_BOARD_START, NEP_IRQ_NR, -1);
241 if (ret <= 0) {
242 dev_err(&dev->dev, "unable to allocate %u irqs: %d\n",
243 NEP_IRQ_NR, ret);
244 if (ret == 0)
245 ret = -ENOMEM;
246 goto err_irq_alloc;
247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Russell Kingced8d212012-01-24 22:22:18 +0000249 d->irq_base = ret;
250
251 irq_set_chip_and_handler(d->irq_base + NEP_IRQ_SMC91X, &nochip,
252 handle_simple_irq);
253 set_irq_flags(d->irq_base + NEP_IRQ_SMC91X, IRQF_VALID | IRQF_PROBE);
254 irq_set_chip_and_handler(d->irq_base + NEP_IRQ_USAR, &nochip,
255 handle_simple_irq);
256 set_irq_flags(d->irq_base + NEP_IRQ_USAR, IRQF_VALID | IRQF_PROBE);
257 irq_set_chip(d->irq_base + NEP_IRQ_SA1111, &nochip);
258
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000259 irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
260 irq_set_handler_data(irq, d);
261 irq_set_chained_handler(irq, neponset_irq_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 /*
Russell Kingced8d212012-01-24 22:22:18 +0000264 * We would set IRQ_GPIO25 to be a wake-up IRQ, but unfortunately
265 * something on the Neponset activates this IRQ on sleep (eth?)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 */
267#if 0
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000268 enable_irq_wake(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#endif
270
Russell Kingced8d212012-01-24 22:22:18 +0000271 dev_info(&dev->dev, "Neponset daughter board, providing IRQ%u-%u\n",
272 d->irq_base, d->irq_base + NEP_IRQ_NR - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Russell Kingced8d212012-01-24 22:22:18 +0000274 sa1100_register_uart_fns(&neponset_port_fns);
275
Russell Kingbab50a32012-01-26 11:50:23 +0000276 /* Ensure that the memory bus request/grant signals are setup */
277 sa1110_mb_disable();
278
Russell Kingced8d212012-01-24 22:22:18 +0000279 /* Disable GPIO 0/1 drivers so the buttons work on the Assabet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 NCR_0 = NCR_GP01_OFF;
281
Russell Kingd2e539a2012-01-24 23:17:37 +0000282 sa1111_resources[0].parent = sa1111_res;
Russell Kingced8d212012-01-24 22:22:18 +0000283 sa1111_resources[1].start = d->irq_base + NEP_IRQ_SA1111;
284 sa1111_resources[1].end = d->irq_base + NEP_IRQ_SA1111;
Russell King9590e892012-01-24 22:36:47 +0000285 d->sa1111 = platform_device_register_full(&sa1111_devinfo);
Russell Kingced8d212012-01-24 22:22:18 +0000286
Russell Kingd2e539a2012-01-24 23:17:37 +0000287 smc91x_resources[0].parent = smc91x_res;
288 smc91x_resources[1].parent = smc91x_res;
Russell Kingced8d212012-01-24 22:22:18 +0000289 smc91x_resources[2].start = d->irq_base + NEP_IRQ_SMC91X;
290 smc91x_resources[2].end = d->irq_base + NEP_IRQ_SMC91X;
Russell King9590e892012-01-24 22:36:47 +0000291 d->smc91x = platform_device_register_full(&smc91x_devinfo);
292
Russell Kingae14c2e2012-01-24 22:10:02 +0000293 platform_set_drvdata(dev, d);
294
295 return 0;
296
Russell Kingced8d212012-01-24 22:22:18 +0000297 err_irq_alloc:
298 kfree(d);
Russell Kingae14c2e2012-01-24 22:10:02 +0000299 err_alloc:
300 return ret;
301}
302
303static int __devexit neponset_remove(struct platform_device *dev)
304{
305 struct neponset_drvdata *d = platform_get_drvdata(dev);
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000306 int irq = platform_get_irq(dev, 0);
Russell Kingae14c2e2012-01-24 22:10:02 +0000307
Russell King9590e892012-01-24 22:36:47 +0000308 if (!IS_ERR(d->sa1111))
309 platform_device_unregister(d->sa1111);
310 if (!IS_ERR(d->smc91x))
311 platform_device_unregister(d->smc91x);
Russell Kingb6bdfcf2012-01-24 23:05:08 +0000312 irq_set_chained_handler(irq, NULL);
Russell Kingced8d212012-01-24 22:22:18 +0000313 irq_free_descs(d->irq_base, NEP_IRQ_NR);
Russell Kingae14c2e2012-01-24 22:10:02 +0000314 kfree(d);
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return 0;
317}
318
Russell King51f93392012-01-24 23:29:47 +0000319#ifdef CONFIG_PM_SLEEP
320static int neponset_suspend(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Russell King51f93392012-01-24 23:29:47 +0000322 struct neponset_drvdata *d = dev_get_drvdata(dev);
Russell Kingae14c2e2012-01-24 22:10:02 +0000323
324 d->ncr0 = NCR_0;
325 d->mdm_ctl_0 = MDM_CTL_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 return 0;
328}
329
Russell King51f93392012-01-24 23:29:47 +0000330static int neponset_resume(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Russell King51f93392012-01-24 23:29:47 +0000332 struct neponset_drvdata *d = dev_get_drvdata(dev);
Russell Kingae14c2e2012-01-24 22:10:02 +0000333
334 NCR_0 = d->ncr0;
335 MDM_CTL_0 = d->mdm_ctl_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 return 0;
338}
339
Russell King51f93392012-01-24 23:29:47 +0000340static const struct dev_pm_ops neponset_pm_ops = {
341 .suspend_noirq = neponset_suspend,
342 .resume_noirq = neponset_resume,
343 .freeze_noirq = neponset_suspend,
344 .restore_noirq = neponset_resume,
345};
346#define PM_OPS &neponset_pm_ops
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347#else
Russell King51f93392012-01-24 23:29:47 +0000348#define PM_OPS NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#endif
350
Russell King3ae5eae2005-11-09 22:32:44 +0000351static struct platform_driver neponset_device_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 .probe = neponset_probe,
Russell Kingae14c2e2012-01-24 22:10:02 +0000353 .remove = __devexit_p(neponset_remove),
Russell King3ae5eae2005-11-09 22:32:44 +0000354 .driver = {
355 .name = "neponset",
Russell King398e58d2012-01-24 23:33:28 +0000356 .owner = THIS_MODULE,
Russell King51f93392012-01-24 23:29:47 +0000357 .pm = PM_OPS,
Russell King3ae5eae2005-11-09 22:32:44 +0000358 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359};
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361static int __init neponset_init(void)
362{
Russell Kingbab50a32012-01-26 11:50:23 +0000363 return platform_driver_register(&neponset_device_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
366subsys_initcall(neponset_init);
367
368static struct map_desc neponset_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100369 { /* System Registers */
370 .virtual = 0xf3000000,
371 .pfn = __phys_to_pfn(0x10000000),
372 .length = SZ_1M,
373 .type = MT_DEVICE
374 }, { /* SA-1111 */
375 .virtual = 0xf4000000,
376 .pfn = __phys_to_pfn(0x40000000),
377 .length = SZ_1M,
378 .type = MT_DEVICE
379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380};
381
382void __init neponset_map_io(void)
383{
384 iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc));
385}