RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / mach-sa1100 / neponset.c
blob73acb8de993b7f388f2c88e1917dcb7f1d96a9f3
1 /*
2 * linux/arch/arm/mach-sa1100/neponset.c
4 */
5 #include <linux/kernel.h>
6 #include <linux/init.h>
7 #include <linux/tty.h>
8 #include <linux/ioport.h>
9 #include <linux/serial_core.h>
10 #include <linux/platform_device.h>
12 #include <mach/hardware.h>
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>
18 #include <mach/assabet.h>
19 #include <mach/neponset.h>
20 #include <asm/hardware/sa1111.h>
21 #include <asm/sizes.h>
24 * Install handler for Neponset IRQ. Note that we have to loop here
25 * since the ETHERNET and USAR IRQs are level based, and we need to
26 * ensure that the IRQ signal is deasserted before returning. This
27 * is rather unfortunate.
29 static void
30 neponset_irq_handler(unsigned int irq, struct irq_desc *desc)
32 unsigned int irr;
34 while (1) {
36 * Acknowledge the parent IRQ.
38 desc->chip->ack(irq);
41 * Read the interrupt reason register. Let's have all
42 * active IRQ bits high. Note: there is a typo in the
43 * Neponset user's guide for the SA1111 IRR level.
45 irr = IRR ^ (IRR_ETHERNET | IRR_USAR);
47 if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
48 break;
51 * Since there is no individual mask, we have to
52 * mask the parent IRQ. This is safe, since we'll
53 * recheck the register for any pending IRQs.
55 if (irr & (IRR_ETHERNET | IRR_USAR)) {
56 desc->chip->mask(irq);
59 * Ack the interrupt now to prevent re-entering
60 * this neponset handler. Again, this is safe
61 * since we'll check the IRR register prior to
62 * leaving.
64 desc->chip->ack(irq);
66 if (irr & IRR_ETHERNET) {
67 generic_handle_irq(IRQ_NEPONSET_SMC9196);
70 if (irr & IRR_USAR) {
71 generic_handle_irq(IRQ_NEPONSET_USAR);
74 desc->chip->unmask(irq);
77 if (irr & IRR_SA1111) {
78 generic_handle_irq(IRQ_NEPONSET_SA1111);
83 static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
85 u_int mdm_ctl0 = MDM_CTL_0;
87 if (port->mapbase == _Ser1UTCR0) {
88 if (mctrl & TIOCM_RTS)
89 mdm_ctl0 &= ~MDM_CTL0_RTS2;
90 else
91 mdm_ctl0 |= MDM_CTL0_RTS2;
93 if (mctrl & TIOCM_DTR)
94 mdm_ctl0 &= ~MDM_CTL0_DTR2;
95 else
96 mdm_ctl0 |= MDM_CTL0_DTR2;
97 } else if (port->mapbase == _Ser3UTCR0) {
98 if (mctrl & TIOCM_RTS)
99 mdm_ctl0 &= ~MDM_CTL0_RTS1;
100 else
101 mdm_ctl0 |= MDM_CTL0_RTS1;
103 if (mctrl & TIOCM_DTR)
104 mdm_ctl0 &= ~MDM_CTL0_DTR1;
105 else
106 mdm_ctl0 |= MDM_CTL0_DTR1;
109 MDM_CTL_0 = mdm_ctl0;
112 static u_int neponset_get_mctrl(struct uart_port *port)
114 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
115 u_int mdm_ctl1 = MDM_CTL_1;
117 if (port->mapbase == _Ser1UTCR0) {
118 if (mdm_ctl1 & MDM_CTL1_DCD2)
119 ret &= ~TIOCM_CD;
120 if (mdm_ctl1 & MDM_CTL1_CTS2)
121 ret &= ~TIOCM_CTS;
122 if (mdm_ctl1 & MDM_CTL1_DSR2)
123 ret &= ~TIOCM_DSR;
124 } else if (port->mapbase == _Ser3UTCR0) {
125 if (mdm_ctl1 & MDM_CTL1_DCD1)
126 ret &= ~TIOCM_CD;
127 if (mdm_ctl1 & MDM_CTL1_CTS1)
128 ret &= ~TIOCM_CTS;
129 if (mdm_ctl1 & MDM_CTL1_DSR1)
130 ret &= ~TIOCM_DSR;
133 return ret;
136 static struct sa1100_port_fns neponset_port_fns __devinitdata = {
137 .set_mctrl = neponset_set_mctrl,
138 .get_mctrl = neponset_get_mctrl,
141 static int __devinit neponset_probe(struct platform_device *dev)
143 sa1100_register_uart_fns(&neponset_port_fns);
146 * Install handler for GPIO25.
148 set_irq_type(IRQ_GPIO25, IRQ_TYPE_EDGE_RISING);
149 set_irq_chained_handler(IRQ_GPIO25, neponset_irq_handler);
152 * We would set IRQ_GPIO25 to be a wake-up IRQ, but
153 * unfortunately something on the Neponset activates
154 * this IRQ on sleep (ethernet?)
158 * Setup other Neponset IRQs. SA1111 will be done by the
159 * generic SA1111 code.
161 set_irq_handler(IRQ_NEPONSET_SMC9196, handle_simple_irq);
162 set_irq_flags(IRQ_NEPONSET_SMC9196, IRQF_VALID | IRQF_PROBE);
163 set_irq_handler(IRQ_NEPONSET_USAR, handle_simple_irq);
164 set_irq_flags(IRQ_NEPONSET_USAR, IRQF_VALID | IRQF_PROBE);
167 * Disable GPIO 0/1 drivers so the buttons work on the module.
169 NCR_0 = NCR_GP01_OFF;
171 return 0;
174 #ifdef CONFIG_PM
177 * LDM power management.
179 static unsigned int neponset_saved_state;
181 static int neponset_suspend(struct platform_device *dev, pm_message_t state)
184 * Save state.
186 neponset_saved_state = NCR_0;
188 return 0;
191 static int neponset_resume(struct platform_device *dev)
193 NCR_0 = neponset_saved_state;
195 return 0;
198 #else
199 #define neponset_suspend NULL
200 #define neponset_resume NULL
201 #endif
203 static struct platform_driver neponset_device_driver = {
204 .probe = neponset_probe,
205 .suspend = neponset_suspend,
206 .resume = neponset_resume,
207 .driver = {
208 .name = "neponset",
212 static struct resource neponset_resources[] = {
213 [0] = {
214 .start = 0x10000000,
215 .end = 0x17ffffff,
216 .flags = IORESOURCE_MEM,
220 static struct platform_device neponset_device = {
221 .name = "neponset",
222 .id = 0,
223 .num_resources = ARRAY_SIZE(neponset_resources),
224 .resource = neponset_resources,
227 static struct resource sa1111_resources[] = {
228 [0] = {
229 .start = 0x40000000,
230 .end = 0x40001fff,
231 .flags = IORESOURCE_MEM,
233 [1] = {
234 .start = IRQ_NEPONSET_SA1111,
235 .end = IRQ_NEPONSET_SA1111,
236 .flags = IORESOURCE_IRQ,
240 static struct sa1111_platform_data sa1111_info = {
241 .irq_base = IRQ_BOARD_END,
244 static u64 sa1111_dmamask = 0xffffffffUL;
246 static struct platform_device sa1111_device = {
247 .name = "sa1111",
248 .id = 0,
249 .dev = {
250 .dma_mask = &sa1111_dmamask,
251 .coherent_dma_mask = 0xffffffff,
252 .platform_data = &sa1111_info,
254 .num_resources = ARRAY_SIZE(sa1111_resources),
255 .resource = sa1111_resources,
258 static struct resource smc91x_resources[] = {
259 [0] = {
260 .name = "smc91x-regs",
261 .start = SA1100_CS3_PHYS,
262 .end = SA1100_CS3_PHYS + 0x01ffffff,
263 .flags = IORESOURCE_MEM,
265 [1] = {
266 .start = IRQ_NEPONSET_SMC9196,
267 .end = IRQ_NEPONSET_SMC9196,
268 .flags = IORESOURCE_IRQ,
270 [2] = {
271 .name = "smc91x-attrib",
272 .start = SA1100_CS3_PHYS + 0x02000000,
273 .end = SA1100_CS3_PHYS + 0x03ffffff,
274 .flags = IORESOURCE_MEM,
278 static struct platform_device smc91x_device = {
279 .name = "smc91x",
280 .id = 0,
281 .num_resources = ARRAY_SIZE(smc91x_resources),
282 .resource = smc91x_resources,
285 static struct platform_device *devices[] __initdata = {
286 &neponset_device,
287 &sa1111_device,
288 &smc91x_device,
291 extern void sa1110_mb_disable(void);
293 static int __init neponset_init(void)
295 platform_driver_register(&neponset_device_driver);
298 * The Neponset is only present on the Assabet machine type.
300 if (!machine_is_assabet())
301 return -ENODEV;
304 * Ensure that the memory bus request/grant signals are setup,
305 * and the grant is held in its inactive state, whether or not
306 * we actually have a Neponset attached.
308 sa1110_mb_disable();
310 if (!machine_has_neponset()) {
311 printk(KERN_DEBUG "Neponset expansion board not present\n");
312 return -ENODEV;
315 if (WHOAMI != 0x11) {
316 printk(KERN_WARNING "Neponset board detected, but "
317 "wrong ID: %02x\n", WHOAMI);
318 return -ENODEV;
321 return platform_add_devices(devices, ARRAY_SIZE(devices));
324 subsys_initcall(neponset_init);
326 static struct map_desc neponset_io_desc[] __initdata = {
327 { /* System Registers */
328 .virtual = 0xf3000000,
329 .pfn = __phys_to_pfn(0x10000000),
330 .length = SZ_1M,
331 .type = MT_DEVICE
332 }, { /* SA-1111 */
333 .virtual = 0xf4000000,
334 .pfn = __phys_to_pfn(0x40000000),
335 .length = SZ_1M,
336 .type = MT_DEVICE
340 void __init neponset_map_io(void)
342 iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc));