Blame view

arch/arm/mach-sa1100/neponset.c 7.48 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
  /*
   * linux/arch/arm/mach-sa1100/neponset.c
   *
   */
  #include <linux/kernel.h>
  #include <linux/init.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
  #include <linux/tty.h>
  #include <linux/ioport.h>
  #include <linux/serial_core.h>
d052d1bef   Russell King   Create platform_d...
10
  #include <linux/platform_device.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11

a09e64fbc   Russell King   [ARM] Move includ...
12
  #include <mach/hardware.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
15
16
17
  #include <asm/mach-types.h>
  #include <asm/irq.h>
  #include <asm/mach/map.h>
  #include <asm/mach/irq.h>
  #include <asm/mach/serial_sa1100.h>
a09e64fbc   Russell King   [ARM] Move includ...
18
19
  #include <mach/assabet.h>
  #include <mach/neponset.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
22
23
24
25
26
27
28
29
  #include <asm/hardware/sa1111.h>
  #include <asm/sizes.h>
  
  /*
   * Install handler for Neponset IRQ.  Note that we have to loop here
   * since the ETHERNET and USAR IRQs are level based, and we need to
   * ensure that the IRQ signal is deasserted before returning.  This
   * is rather unfortunate.
   */
  static void
10dd5ce28   Russell King   [ARM] Remove comp...
30
  neponset_irq_handler(unsigned int irq, struct irq_desc *desc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
  {
  	unsigned int irr;
  
  	while (1) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
37
  		/*
  		 * Acknowledge the parent IRQ.
  		 */
c4e8964e4   Lennert Buytenhek   ARM: sa1100: irq_...
38
  		desc->irq_data.chip->irq_ack(&desc->irq_data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  
  		/*
  		 * Read the interrupt reason register.  Let's have all
  		 * active IRQ bits high.  Note: there is a typo in the
  		 * Neponset user's guide for the SA1111 IRR level.
  		 */
  		irr = IRR ^ (IRR_ETHERNET | IRR_USAR);
  
  		if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
  			break;
  
  		/*
  		 * Since there is no individual mask, we have to
  		 * mask the parent IRQ.  This is safe, since we'll
  		 * recheck the register for any pending IRQs.
  		 */
  		if (irr & (IRR_ETHERNET | IRR_USAR)) {
c4e8964e4   Lennert Buytenhek   ARM: sa1100: irq_...
56
  			desc->irq_data.chip->irq_mask(&desc->irq_data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57

d782f33df   Russell King   [ARM] Fix Neponse...
58
59
60
61
62
63
  			/*
  			 * Ack the interrupt now to prevent re-entering
  			 * this neponset handler.  Again, this is safe
  			 * since we'll check the IRR register prior to
  			 * leaving.
  			 */
c4e8964e4   Lennert Buytenhek   ARM: sa1100: irq_...
64
  			desc->irq_data.chip->irq_ack(&desc->irq_data);
d782f33df   Russell King   [ARM] Fix Neponse...
65

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
  			if (irr & IRR_ETHERNET) {
d8aa0251f   Dmitry Eremin-Solenikov   [ARM] 5298/1: Dro...
67
  				generic_handle_irq(IRQ_NEPONSET_SMC9196);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
69
70
  			}
  
  			if (irr & IRR_USAR) {
d8aa0251f   Dmitry Eremin-Solenikov   [ARM] 5298/1: Dro...
71
  				generic_handle_irq(IRQ_NEPONSET_USAR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  			}
c4e8964e4   Lennert Buytenhek   ARM: sa1100: irq_...
73
  			desc->irq_data.chip->irq_unmask(&desc->irq_data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
75
76
  		}
  
  		if (irr & IRR_SA1111) {
d8aa0251f   Dmitry Eremin-Solenikov   [ARM] 5298/1: Dro...
77
  			generic_handle_irq(IRQ_NEPONSET_SA1111);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  		}
  	}
  }
  
  static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
  {
  	u_int mdm_ctl0 = MDM_CTL_0;
  
  	if (port->mapbase == _Ser1UTCR0) {
  		if (mctrl & TIOCM_RTS)
  			mdm_ctl0 &= ~MDM_CTL0_RTS2;
  		else
  			mdm_ctl0 |= MDM_CTL0_RTS2;
  
  		if (mctrl & TIOCM_DTR)
  			mdm_ctl0 &= ~MDM_CTL0_DTR2;
  		else
  			mdm_ctl0 |= MDM_CTL0_DTR2;
  	} else if (port->mapbase == _Ser3UTCR0) {
  		if (mctrl & TIOCM_RTS)
  			mdm_ctl0 &= ~MDM_CTL0_RTS1;
  		else
  			mdm_ctl0 |= MDM_CTL0_RTS1;
  
  		if (mctrl & TIOCM_DTR)
  			mdm_ctl0 &= ~MDM_CTL0_DTR1;
  		else
  			mdm_ctl0 |= MDM_CTL0_DTR1;
  	}
  
  	MDM_CTL_0 = mdm_ctl0;
  }
  
  static u_int neponset_get_mctrl(struct uart_port *port)
  {
  	u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  	u_int mdm_ctl1 = MDM_CTL_1;
  
  	if (port->mapbase == _Ser1UTCR0) {
  		if (mdm_ctl1 & MDM_CTL1_DCD2)
  			ret &= ~TIOCM_CD;
  		if (mdm_ctl1 & MDM_CTL1_CTS2)
  			ret &= ~TIOCM_CTS;
  		if (mdm_ctl1 & MDM_CTL1_DSR2)
  			ret &= ~TIOCM_DSR;
  	} else if (port->mapbase == _Ser3UTCR0) {
  		if (mdm_ctl1 & MDM_CTL1_DCD1)
  			ret &= ~TIOCM_CD;
  		if (mdm_ctl1 & MDM_CTL1_CTS1)
  			ret &= ~TIOCM_CTS;
  		if (mdm_ctl1 & MDM_CTL1_DSR1)
  			ret &= ~TIOCM_DSR;
  	}
  
  	return ret;
  }
cdea46064   Russell King   [ARM] Fix some se...
134
  static struct sa1100_port_fns neponset_port_fns __devinitdata = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
137
  	.set_mctrl	= neponset_set_mctrl,
  	.get_mctrl	= neponset_get_mctrl,
  };
cdea46064   Russell King   [ARM] Fix some se...
138
  static int __devinit neponset_probe(struct platform_device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
140
141
142
143
144
  {
  	sa1100_register_uart_fns(&neponset_port_fns);
  
  	/*
  	 * Install handler for GPIO25.
  	 */
6845664a6   Thomas Gleixner   arm: Cleanup the ...
145
146
  	irq_set_irq_type(IRQ_GPIO25, IRQ_TYPE_EDGE_RISING);
  	irq_set_chained_handler(IRQ_GPIO25, neponset_irq_handler);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  
  	/*
  	 * We would set IRQ_GPIO25 to be a wake-up IRQ, but
  	 * unfortunately something on the Neponset activates
  	 * this IRQ on sleep (ethernet?)
  	 */
  #if 0
  	enable_irq_wake(IRQ_GPIO25);
  #endif
  
  	/*
  	 * Setup other Neponset IRQs.  SA1111 will be done by the
  	 * generic SA1111 code.
  	 */
6845664a6   Thomas Gleixner   arm: Cleanup the ...
161
  	irq_set_handler(IRQ_NEPONSET_SMC9196, handle_simple_irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
  	set_irq_flags(IRQ_NEPONSET_SMC9196, IRQF_VALID | IRQF_PROBE);
6845664a6   Thomas Gleixner   arm: Cleanup the ...
163
  	irq_set_handler(IRQ_NEPONSET_USAR, handle_simple_irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  	set_irq_flags(IRQ_NEPONSET_USAR, IRQF_VALID | IRQF_PROBE);
  
  	/*
  	 * Disable GPIO 0/1 drivers so the buttons work on the module.
  	 */
  	NCR_0 = NCR_GP01_OFF;
  
  	return 0;
  }
  
  #ifdef CONFIG_PM
  
  /*
   * LDM power management.
   */
93160c639   Rafael J. Wysocki   PM: do not use sa...
179
  static unsigned int neponset_saved_state;
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
180
  static int neponset_suspend(struct platform_device *dev, pm_message_t state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
181
182
183
184
  {
  	/*
  	 * Save state.
  	 */
93160c639   Rafael J. Wysocki   PM: do not use sa...
185
  	neponset_saved_state = NCR_0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
187
188
  
  	return 0;
  }
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
189
  static int neponset_resume(struct platform_device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
  {
93160c639   Rafael J. Wysocki   PM: do not use sa...
191
  	NCR_0 = neponset_saved_state;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
192
193
194
195
196
197
198
199
  
  	return 0;
  }
  
  #else
  #define neponset_suspend NULL
  #define neponset_resume  NULL
  #endif
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
200
  static struct platform_driver neponset_device_driver = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201
202
203
  	.probe		= neponset_probe,
  	.suspend	= neponset_suspend,
  	.resume		= neponset_resume,
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
204
205
206
  	.driver		= {
  		.name	= "neponset",
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
  };
  
  static struct resource neponset_resources[] = {
  	[0] = {
  		.start	= 0x10000000,
  		.end	= 0x17ffffff,
  		.flags	= IORESOURCE_MEM,
  	},
  };
  
  static struct platform_device neponset_device = {
  	.name		= "neponset",
  	.id		= 0,
  	.num_resources	= ARRAY_SIZE(neponset_resources),
  	.resource	= neponset_resources,
  };
  
  static struct resource sa1111_resources[] = {
  	[0] = {
  		.start	= 0x40000000,
  		.end	= 0x40001fff,
  		.flags	= IORESOURCE_MEM,
  	},
  	[1] = {
  		.start	= IRQ_NEPONSET_SA1111,
  		.end	= IRQ_NEPONSET_SA1111,
  		.flags	= IORESOURCE_IRQ,
  	},
  };
19851c58e   Eric Miao   [ARM] sa1111: all...
236
237
238
  static struct sa1111_platform_data sa1111_info = {
  	.irq_base	= IRQ_BOARD_END,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
241
242
243
244
245
246
  static u64 sa1111_dmamask = 0xffffffffUL;
  
  static struct platform_device sa1111_device = {
  	.name		= "sa1111",
  	.id		= 0,
  	.dev		= {
  		.dma_mask = &sa1111_dmamask,
  		.coherent_dma_mask = 0xffffffff,
19851c58e   Eric Miao   [ARM] sa1111: all...
247
  		.platform_data = &sa1111_info,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
  	},
  	.num_resources	= ARRAY_SIZE(sa1111_resources),
  	.resource	= sa1111_resources,
  };
  
  static struct resource smc91x_resources[] = {
  	[0] = {
  		.name	= "smc91x-regs",
  		.start	= SA1100_CS3_PHYS,
  		.end	= SA1100_CS3_PHYS + 0x01ffffff,
  		.flags	= IORESOURCE_MEM,
  	},
  	[1] = {
  		.start	= IRQ_NEPONSET_SMC9196,
  		.end	= IRQ_NEPONSET_SMC9196,
  		.flags	= IORESOURCE_IRQ,
  	},
  	[2] = {
  		.name	= "smc91x-attrib",
  		.start	= SA1100_CS3_PHYS + 0x02000000,
  		.end	= SA1100_CS3_PHYS + 0x03ffffff,
  		.flags	= IORESOURCE_MEM,
  	},
  };
  
  static struct platform_device smc91x_device = {
  	.name		= "smc91x",
  	.id		= 0,
  	.num_resources	= ARRAY_SIZE(smc91x_resources),
  	.resource	= smc91x_resources,
  };
  
  static struct platform_device *devices[] __initdata = {
  	&neponset_device,
  	&sa1111_device,
  	&smc91x_device,
  };
cdcb81f7d   Russell King   [ARM] Allow nepon...
285
  extern void sa1110_mb_disable(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
287
  static int __init neponset_init(void)
  {
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
288
  	platform_driver_register(&neponset_device_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  
  	/*
  	 * The Neponset is only present on the Assabet machine type.
  	 */
  	if (!machine_is_assabet())
  		return -ENODEV;
  
  	/*
  	 * Ensure that the memory bus request/grant signals are setup,
  	 * and the grant is held in its inactive state, whether or not
  	 * we actually have a Neponset attached.
  	 */
  	sa1110_mb_disable();
  
  	if (!machine_has_neponset()) {
  		printk(KERN_DEBUG "Neponset expansion board not present
  ");
  		return -ENODEV;
  	}
  
  	if (WHOAMI != 0x11) {
  		printk(KERN_WARNING "Neponset board detected, but "
  			"wrong ID: %02x
  ", WHOAMI);
  		return -ENODEV;
  	}
  
  	return platform_add_devices(devices, ARRAY_SIZE(devices));
  }
  
  subsys_initcall(neponset_init);
  
  static struct map_desc neponset_io_desc[] __initdata = {
92519d828   Deepak Saxena   [ARM] 2992/1: Rep...
322
323
324
325
326
327
328
329
330
331
332
  	{	/* System Registers */
  		.virtual	=  0xf3000000,
  		.pfn		= __phys_to_pfn(0x10000000),
  		.length		= SZ_1M,
  		.type		= MT_DEVICE
  	}, {	/* SA-1111 */
  		.virtual	=  0xf4000000,
  		.pfn		= __phys_to_pfn(0x40000000),
  		.length		= SZ_1M,
  		.type		= MT_DEVICE
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333
334
335
336
337
338
  };
  
  void __init neponset_map_io(void)
  {
  	iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc));
  }