blob: 967a48454f6bd34e33507de11aa4fabd30065214 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/neponset.c
3 *
4 */
5#include <linux/kernel.h>
6#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/tty.h>
8#include <linux/ioport.h>
9#include <linux/serial_core.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010010#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/slab.h>
12
13#include <asm/hardware.h>
14#include <asm/mach-types.h>
15#include <asm/irq.h>
16#include <asm/mach/map.h>
17#include <asm/mach/irq.h>
18#include <asm/mach/serial_sa1100.h>
19#include <asm/arch/assabet.h>
20#include <asm/arch/neponset.h>
21#include <asm/hardware/sa1111.h>
22#include <asm/sizes.h>
23
24/*
25 * Install handler for Neponset IRQ. Note that we have to loop here
26 * since the ETHERNET and USAR IRQs are level based, and we need to
27 * ensure that the IRQ signal is deasserted before returning. This
28 * is rather unfortunate.
29 */
30static void
Russell King10dd5ce2006-11-23 11:41:32 +000031neponset_irq_handler(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
33 unsigned int irr;
34
35 while (1) {
Russell King10dd5ce2006-11-23 11:41:32 +000036 struct irq_desc *d;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 /*
39 * Acknowledge the parent IRQ.
40 */
41 desc->chip->ack(irq);
42
43 /*
44 * Read the interrupt reason register. Let's have all
45 * active IRQ bits high. Note: there is a typo in the
46 * Neponset user's guide for the SA1111 IRR level.
47 */
48 irr = IRR ^ (IRR_ETHERNET | IRR_USAR);
49
50 if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
51 break;
52
53 /*
54 * Since there is no individual mask, we have to
55 * mask the parent IRQ. This is safe, since we'll
56 * recheck the register for any pending IRQs.
57 */
58 if (irr & (IRR_ETHERNET | IRR_USAR)) {
59 desc->chip->mask(irq);
60
Russell Kingd782f332006-06-08 17:59:31 +010061 /*
62 * Ack the interrupt now to prevent re-entering
63 * this neponset handler. Again, this is safe
64 * since we'll check the IRR register prior to
65 * leaving.
66 */
67 desc->chip->ack(irq);
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 if (irr & IRR_ETHERNET) {
70 d = irq_desc + IRQ_NEPONSET_SMC9196;
Linus Torvalds0cd61b62006-10-06 10:53:39 -070071 desc_handle_irq(IRQ_NEPONSET_SMC9196, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
73
74 if (irr & IRR_USAR) {
75 d = irq_desc + IRQ_NEPONSET_USAR;
Linus Torvalds0cd61b62006-10-06 10:53:39 -070076 desc_handle_irq(IRQ_NEPONSET_USAR, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
78
79 desc->chip->unmask(irq);
80 }
81
82 if (irr & IRR_SA1111) {
83 d = irq_desc + IRQ_NEPONSET_SA1111;
Linus Torvalds0cd61b62006-10-06 10:53:39 -070084 desc_handle_irq(IRQ_NEPONSET_SA1111, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86 }
87}
88
89static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
90{
91 u_int mdm_ctl0 = MDM_CTL_0;
92
93 if (port->mapbase == _Ser1UTCR0) {
94 if (mctrl & TIOCM_RTS)
95 mdm_ctl0 &= ~MDM_CTL0_RTS2;
96 else
97 mdm_ctl0 |= MDM_CTL0_RTS2;
98
99 if (mctrl & TIOCM_DTR)
100 mdm_ctl0 &= ~MDM_CTL0_DTR2;
101 else
102 mdm_ctl0 |= MDM_CTL0_DTR2;
103 } else if (port->mapbase == _Ser3UTCR0) {
104 if (mctrl & TIOCM_RTS)
105 mdm_ctl0 &= ~MDM_CTL0_RTS1;
106 else
107 mdm_ctl0 |= MDM_CTL0_RTS1;
108
109 if (mctrl & TIOCM_DTR)
110 mdm_ctl0 &= ~MDM_CTL0_DTR1;
111 else
112 mdm_ctl0 |= MDM_CTL0_DTR1;
113 }
114
115 MDM_CTL_0 = mdm_ctl0;
116}
117
118static u_int neponset_get_mctrl(struct uart_port *port)
119{
120 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
121 u_int mdm_ctl1 = MDM_CTL_1;
122
123 if (port->mapbase == _Ser1UTCR0) {
124 if (mdm_ctl1 & MDM_CTL1_DCD2)
125 ret &= ~TIOCM_CD;
126 if (mdm_ctl1 & MDM_CTL1_CTS2)
127 ret &= ~TIOCM_CTS;
128 if (mdm_ctl1 & MDM_CTL1_DSR2)
129 ret &= ~TIOCM_DSR;
130 } else if (port->mapbase == _Ser3UTCR0) {
131 if (mdm_ctl1 & MDM_CTL1_DCD1)
132 ret &= ~TIOCM_CD;
133 if (mdm_ctl1 & MDM_CTL1_CTS1)
134 ret &= ~TIOCM_CTS;
135 if (mdm_ctl1 & MDM_CTL1_DSR1)
136 ret &= ~TIOCM_DSR;
137 }
138
139 return ret;
140}
141
Russell Kingcdea4602007-05-30 17:48:45 +0100142static struct sa1100_port_fns neponset_port_fns __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 .set_mctrl = neponset_set_mctrl,
144 .get_mctrl = neponset_get_mctrl,
145};
146
Russell Kingcdea4602007-05-30 17:48:45 +0100147static int __devinit neponset_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 sa1100_register_uart_fns(&neponset_port_fns);
150
151 /*
152 * Install handler for GPIO25.
153 */
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100154 set_irq_type(IRQ_GPIO25, IRQ_TYPE_EDGE_RISING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 set_irq_chained_handler(IRQ_GPIO25, neponset_irq_handler);
156
157 /*
158 * We would set IRQ_GPIO25 to be a wake-up IRQ, but
159 * unfortunately something on the Neponset activates
160 * this IRQ on sleep (ethernet?)
161 */
162#if 0
163 enable_irq_wake(IRQ_GPIO25);
164#endif
165
166 /*
167 * Setup other Neponset IRQs. SA1111 will be done by the
168 * generic SA1111 code.
169 */
Russell King10dd5ce2006-11-23 11:41:32 +0000170 set_irq_handler(IRQ_NEPONSET_SMC9196, handle_simple_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 set_irq_flags(IRQ_NEPONSET_SMC9196, IRQF_VALID | IRQF_PROBE);
Russell King10dd5ce2006-11-23 11:41:32 +0000172 set_irq_handler(IRQ_NEPONSET_USAR, handle_simple_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 set_irq_flags(IRQ_NEPONSET_USAR, IRQF_VALID | IRQF_PROBE);
174
175 /*
176 * Disable GPIO 0/1 drivers so the buttons work on the module.
177 */
178 NCR_0 = NCR_GP01_OFF;
179
180 return 0;
181}
182
183#ifdef CONFIG_PM
184
185/*
186 * LDM power management.
187 */
Rafael J. Wysocki93160c62007-07-09 11:39:19 -0700188static unsigned int neponset_saved_state;
189
Russell King3ae5eae2005-11-09 22:32:44 +0000190static int neponset_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 /*
193 * Save state.
194 */
Rafael J. Wysocki93160c62007-07-09 11:39:19 -0700195 neponset_saved_state = NCR_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 return 0;
198}
199
Russell King3ae5eae2005-11-09 22:32:44 +0000200static int neponset_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Rafael J. Wysocki93160c62007-07-09 11:39:19 -0700202 NCR_0 = neponset_saved_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 return 0;
205}
206
207#else
208#define neponset_suspend NULL
209#define neponset_resume NULL
210#endif
211
Russell King3ae5eae2005-11-09 22:32:44 +0000212static struct platform_driver neponset_device_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 .probe = neponset_probe,
214 .suspend = neponset_suspend,
215 .resume = neponset_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000216 .driver = {
217 .name = "neponset",
218 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
221static struct resource neponset_resources[] = {
222 [0] = {
223 .start = 0x10000000,
224 .end = 0x17ffffff,
225 .flags = IORESOURCE_MEM,
226 },
227};
228
229static struct platform_device neponset_device = {
230 .name = "neponset",
231 .id = 0,
232 .num_resources = ARRAY_SIZE(neponset_resources),
233 .resource = neponset_resources,
234};
235
236static struct resource sa1111_resources[] = {
237 [0] = {
238 .start = 0x40000000,
239 .end = 0x40001fff,
240 .flags = IORESOURCE_MEM,
241 },
242 [1] = {
243 .start = IRQ_NEPONSET_SA1111,
244 .end = IRQ_NEPONSET_SA1111,
245 .flags = IORESOURCE_IRQ,
246 },
247};
248
249static u64 sa1111_dmamask = 0xffffffffUL;
250
251static struct platform_device sa1111_device = {
252 .name = "sa1111",
253 .id = 0,
254 .dev = {
255 .dma_mask = &sa1111_dmamask,
256 .coherent_dma_mask = 0xffffffff,
257 },
258 .num_resources = ARRAY_SIZE(sa1111_resources),
259 .resource = sa1111_resources,
260};
261
262static struct resource smc91x_resources[] = {
263 [0] = {
264 .name = "smc91x-regs",
265 .start = SA1100_CS3_PHYS,
266 .end = SA1100_CS3_PHYS + 0x01ffffff,
267 .flags = IORESOURCE_MEM,
268 },
269 [1] = {
270 .start = IRQ_NEPONSET_SMC9196,
271 .end = IRQ_NEPONSET_SMC9196,
272 .flags = IORESOURCE_IRQ,
273 },
274 [2] = {
275 .name = "smc91x-attrib",
276 .start = SA1100_CS3_PHYS + 0x02000000,
277 .end = SA1100_CS3_PHYS + 0x03ffffff,
278 .flags = IORESOURCE_MEM,
279 },
280};
281
282static struct platform_device smc91x_device = {
283 .name = "smc91x",
284 .id = 0,
285 .num_resources = ARRAY_SIZE(smc91x_resources),
286 .resource = smc91x_resources,
287};
288
289static struct platform_device *devices[] __initdata = {
290 &neponset_device,
291 &sa1111_device,
292 &smc91x_device,
293};
294
Russell Kingcdcb81f2007-07-20 10:32:46 +0100295extern void sa1110_mb_disable(void);
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static int __init neponset_init(void)
298{
Russell King3ae5eae2005-11-09 22:32:44 +0000299 platform_driver_register(&neponset_device_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 /*
302 * The Neponset is only present on the Assabet machine type.
303 */
304 if (!machine_is_assabet())
305 return -ENODEV;
306
307 /*
308 * Ensure that the memory bus request/grant signals are setup,
309 * and the grant is held in its inactive state, whether or not
310 * we actually have a Neponset attached.
311 */
312 sa1110_mb_disable();
313
314 if (!machine_has_neponset()) {
315 printk(KERN_DEBUG "Neponset expansion board not present\n");
316 return -ENODEV;
317 }
318
319 if (WHOAMI != 0x11) {
320 printk(KERN_WARNING "Neponset board detected, but "
321 "wrong ID: %02x\n", WHOAMI);
322 return -ENODEV;
323 }
324
325 return platform_add_devices(devices, ARRAY_SIZE(devices));
326}
327
328subsys_initcall(neponset_init);
329
330static struct map_desc neponset_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100331 { /* System Registers */
332 .virtual = 0xf3000000,
333 .pfn = __phys_to_pfn(0x10000000),
334 .length = SZ_1M,
335 .type = MT_DEVICE
336 }, { /* SA-1111 */
337 .virtual = 0xf4000000,
338 .pfn = __phys_to_pfn(0x40000000),
339 .length = SZ_1M,
340 .type = MT_DEVICE
341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342};
343
344void __init neponset_map_io(void)
345{
346 iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc));
347}