Create platform_device.h to contain all the platform device details.
[deliverable/linux.git] / arch / arm / mach-sa1100 / neponset.c
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/arm/mach-sa1100/neponset.c
3 *
4 */
5#include <linux/kernel.h>
6#include <linux/init.h>
7#include <linux/ptrace.h>
8#include <linux/tty.h>
9#include <linux/ioport.h>
10#include <linux/serial_core.h>
d052d1be 11#include <linux/platform_device.h>
1da177e4
LT
12#include <linux/slab.h>
13
14#include <asm/hardware.h>
15#include <asm/mach-types.h>
16#include <asm/irq.h>
17#include <asm/mach/map.h>
18#include <asm/mach/irq.h>
19#include <asm/mach/serial_sa1100.h>
20#include <asm/arch/assabet.h>
21#include <asm/arch/neponset.h>
22#include <asm/hardware/sa1111.h>
23#include <asm/sizes.h>
24
25/*
26 * Install handler for Neponset IRQ. Note that we have to loop here
27 * since the ETHERNET and USAR IRQs are level based, and we need to
28 * ensure that the IRQ signal is deasserted before returning. This
29 * is rather unfortunate.
30 */
31static void
32neponset_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
33{
34 unsigned int irr;
35
36 while (1) {
37 struct irqdesc *d;
38
39 /*
40 * Acknowledge the parent IRQ.
41 */
42 desc->chip->ack(irq);
43
44 /*
45 * Read the interrupt reason register. Let's have all
46 * active IRQ bits high. Note: there is a typo in the
47 * Neponset user's guide for the SA1111 IRR level.
48 */
49 irr = IRR ^ (IRR_ETHERNET | IRR_USAR);
50
51 if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
52 break;
53
54 /*
55 * Since there is no individual mask, we have to
56 * mask the parent IRQ. This is safe, since we'll
57 * recheck the register for any pending IRQs.
58 */
59 if (irr & (IRR_ETHERNET | IRR_USAR)) {
60 desc->chip->mask(irq);
61
62 if (irr & IRR_ETHERNET) {
63 d = irq_desc + IRQ_NEPONSET_SMC9196;
664399e1 64 desc_handle_irq(IRQ_NEPONSET_SMC9196, d, regs);
1da177e4
LT
65 }
66
67 if (irr & IRR_USAR) {
68 d = irq_desc + IRQ_NEPONSET_USAR;
664399e1 69 desc_handle_irq(IRQ_NEPONSET_USAR, d, regs);
1da177e4
LT
70 }
71
72 desc->chip->unmask(irq);
73 }
74
75 if (irr & IRR_SA1111) {
76 d = irq_desc + IRQ_NEPONSET_SA1111;
664399e1 77 desc_handle_irq(IRQ_NEPONSET_SA1111, d, regs);
1da177e4
LT
78 }
79 }
80}
81
82static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
83{
84 u_int mdm_ctl0 = MDM_CTL_0;
85
86 if (port->mapbase == _Ser1UTCR0) {
87 if (mctrl & TIOCM_RTS)
88 mdm_ctl0 &= ~MDM_CTL0_RTS2;
89 else
90 mdm_ctl0 |= MDM_CTL0_RTS2;
91
92 if (mctrl & TIOCM_DTR)
93 mdm_ctl0 &= ~MDM_CTL0_DTR2;
94 else
95 mdm_ctl0 |= MDM_CTL0_DTR2;
96 } else if (port->mapbase == _Ser3UTCR0) {
97 if (mctrl & TIOCM_RTS)
98 mdm_ctl0 &= ~MDM_CTL0_RTS1;
99 else
100 mdm_ctl0 |= MDM_CTL0_RTS1;
101
102 if (mctrl & TIOCM_DTR)
103 mdm_ctl0 &= ~MDM_CTL0_DTR1;
104 else
105 mdm_ctl0 |= MDM_CTL0_DTR1;
106 }
107
108 MDM_CTL_0 = mdm_ctl0;
109}
110
111static u_int neponset_get_mctrl(struct uart_port *port)
112{
113 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
114 u_int mdm_ctl1 = MDM_CTL_1;
115
116 if (port->mapbase == _Ser1UTCR0) {
117 if (mdm_ctl1 & MDM_CTL1_DCD2)
118 ret &= ~TIOCM_CD;
119 if (mdm_ctl1 & MDM_CTL1_CTS2)
120 ret &= ~TIOCM_CTS;
121 if (mdm_ctl1 & MDM_CTL1_DSR2)
122 ret &= ~TIOCM_DSR;
123 } else if (port->mapbase == _Ser3UTCR0) {
124 if (mdm_ctl1 & MDM_CTL1_DCD1)
125 ret &= ~TIOCM_CD;
126 if (mdm_ctl1 & MDM_CTL1_CTS1)
127 ret &= ~TIOCM_CTS;
128 if (mdm_ctl1 & MDM_CTL1_DSR1)
129 ret &= ~TIOCM_DSR;
130 }
131
132 return ret;
133}
134
135static struct sa1100_port_fns neponset_port_fns __initdata = {
136 .set_mctrl = neponset_set_mctrl,
137 .get_mctrl = neponset_get_mctrl,
138};
139
140static int neponset_probe(struct device *dev)
141{
142 sa1100_register_uart_fns(&neponset_port_fns);
143
144 /*
145 * Install handler for GPIO25.
146 */
147 set_irq_type(IRQ_GPIO25, IRQT_RISING);
148 set_irq_chained_handler(IRQ_GPIO25, neponset_irq_handler);
149
150 /*
151 * We would set IRQ_GPIO25 to be a wake-up IRQ, but
152 * unfortunately something on the Neponset activates
153 * this IRQ on sleep (ethernet?)
154 */
155#if 0
156 enable_irq_wake(IRQ_GPIO25);
157#endif
158
159 /*
160 * Setup other Neponset IRQs. SA1111 will be done by the
161 * generic SA1111 code.
162 */
163 set_irq_handler(IRQ_NEPONSET_SMC9196, do_simple_IRQ);
164 set_irq_flags(IRQ_NEPONSET_SMC9196, IRQF_VALID | IRQF_PROBE);
165 set_irq_handler(IRQ_NEPONSET_USAR, do_simple_IRQ);
166 set_irq_flags(IRQ_NEPONSET_USAR, IRQF_VALID | IRQF_PROBE);
167
168 /*
169 * Disable GPIO 0/1 drivers so the buttons work on the module.
170 */
171 NCR_0 = NCR_GP01_OFF;
172
173 return 0;
174}
175
176#ifdef CONFIG_PM
177
178/*
179 * LDM power management.
180 */
9480e307 181static int neponset_suspend(struct device *dev, pm_message_t state)
1da177e4
LT
182{
183 /*
184 * Save state.
185 */
9480e307
RK
186 if (!dev->power.saved_state)
187 dev->power.saved_state = kmalloc(sizeof(unsigned int), GFP_KERNEL);
188 if (!dev->power.saved_state)
189 return -ENOMEM;
190
191 *(unsigned int *)dev->power.saved_state = NCR_0;
1da177e4
LT
192
193 return 0;
194}
195
9480e307 196static int neponset_resume(struct device *dev)
1da177e4 197{
9480e307
RK
198 if (dev->power.saved_state) {
199 NCR_0 = *(unsigned int *)dev->power.saved_state;
200 kfree(dev->power.saved_state);
201 dev->power.saved_state = NULL;
1da177e4
LT
202 }
203
204 return 0;
205}
206
207#else
208#define neponset_suspend NULL
209#define neponset_resume NULL
210#endif
211
212static struct device_driver neponset_device_driver = {
213 .name = "neponset",
214 .bus = &platform_bus_type,
215 .probe = neponset_probe,
216 .suspend = neponset_suspend,
217 .resume = neponset_resume,
218};
219
220static struct resource neponset_resources[] = {
221 [0] = {
222 .start = 0x10000000,
223 .end = 0x17ffffff,
224 .flags = IORESOURCE_MEM,
225 },
226};
227
228static struct platform_device neponset_device = {
229 .name = "neponset",
230 .id = 0,
231 .num_resources = ARRAY_SIZE(neponset_resources),
232 .resource = neponset_resources,
233};
234
235static struct resource sa1111_resources[] = {
236 [0] = {
237 .start = 0x40000000,
238 .end = 0x40001fff,
239 .flags = IORESOURCE_MEM,
240 },
241 [1] = {
242 .start = IRQ_NEPONSET_SA1111,
243 .end = IRQ_NEPONSET_SA1111,
244 .flags = IORESOURCE_IRQ,
245 },
246};
247
248static u64 sa1111_dmamask = 0xffffffffUL;
249
250static struct platform_device sa1111_device = {
251 .name = "sa1111",
252 .id = 0,
253 .dev = {
254 .dma_mask = &sa1111_dmamask,
255 .coherent_dma_mask = 0xffffffff,
256 },
257 .num_resources = ARRAY_SIZE(sa1111_resources),
258 .resource = sa1111_resources,
259};
260
261static struct resource smc91x_resources[] = {
262 [0] = {
263 .name = "smc91x-regs",
264 .start = SA1100_CS3_PHYS,
265 .end = SA1100_CS3_PHYS + 0x01ffffff,
266 .flags = IORESOURCE_MEM,
267 },
268 [1] = {
269 .start = IRQ_NEPONSET_SMC9196,
270 .end = IRQ_NEPONSET_SMC9196,
271 .flags = IORESOURCE_IRQ,
272 },
273 [2] = {
274 .name = "smc91x-attrib",
275 .start = SA1100_CS3_PHYS + 0x02000000,
276 .end = SA1100_CS3_PHYS + 0x03ffffff,
277 .flags = IORESOURCE_MEM,
278 },
279};
280
281static struct platform_device smc91x_device = {
282 .name = "smc91x",
283 .id = 0,
284 .num_resources = ARRAY_SIZE(smc91x_resources),
285 .resource = smc91x_resources,
286};
287
288static struct platform_device *devices[] __initdata = {
289 &neponset_device,
290 &sa1111_device,
291 &smc91x_device,
292};
293
294static int __init neponset_init(void)
295{
296 driver_register(&neponset_device_driver);
297
298 /*
299 * The Neponset is only present on the Assabet machine type.
300 */
301 if (!machine_is_assabet())
302 return -ENODEV;
303
304 /*
305 * Ensure that the memory bus request/grant signals are setup,
306 * and the grant is held in its inactive state, whether or not
307 * we actually have a Neponset attached.
308 */
309 sa1110_mb_disable();
310
311 if (!machine_has_neponset()) {
312 printk(KERN_DEBUG "Neponset expansion board not present\n");
313 return -ENODEV;
314 }
315
316 if (WHOAMI != 0x11) {
317 printk(KERN_WARNING "Neponset board detected, but "
318 "wrong ID: %02x\n", WHOAMI);
319 return -ENODEV;
320 }
321
322 return platform_add_devices(devices, ARRAY_SIZE(devices));
323}
324
325subsys_initcall(neponset_init);
326
327static struct map_desc neponset_io_desc[] __initdata = {
92519d82
DS
328 { /* System Registers */
329 .virtual = 0xf3000000,
330 .pfn = __phys_to_pfn(0x10000000),
331 .length = SZ_1M,
332 .type = MT_DEVICE
333 }, { /* SA-1111 */
334 .virtual = 0xf4000000,
335 .pfn = __phys_to_pfn(0x40000000),
336 .length = SZ_1M,
337 .type = MT_DEVICE
338 }
1da177e4
LT
339};
340
341void __init neponset_map_io(void)
342{
343 iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc));
344}
This page took 0.075989 seconds and 5 git commands to generate.