Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/arm/mach-sa1100/simpad.c | |
3 | */ | |
4 | ||
1da177e4 LT |
5 | #include <linux/module.h> |
6 | #include <linux/init.h> | |
7 | #include <linux/kernel.h> | |
8 | #include <linux/tty.h> | |
9 | #include <linux/proc_fs.h> | |
f314f33b | 10 | #include <linux/string.h> |
1da177e4 | 11 | #include <linux/pm.h> |
6920b5a7 | 12 | #include <linux/platform_data/sa11x0-serial.h> |
d052d1be | 13 | #include <linux/platform_device.h> |
abe06082 | 14 | #include <linux/mfd/ucb1x00.h> |
1da177e4 LT |
15 | #include <linux/mtd/mtd.h> |
16 | #include <linux/mtd/partitions.h> | |
fced80c7 | 17 | #include <linux/io.h> |
de0bc0d1 | 18 | #include <linux/gpio.h> |
1da177e4 | 19 | |
a09e64fb | 20 | #include <mach/hardware.h> |
1da177e4 LT |
21 | #include <asm/setup.h> |
22 | ||
23 | #include <asm/mach-types.h> | |
24 | #include <asm/mach/arch.h> | |
25 | #include <asm/mach/flash.h> | |
26 | #include <asm/mach/map.h> | |
a1fd844c | 27 | #include <linux/platform_data/mfd-mcp-sa11x0.h> |
a09e64fb | 28 | #include <mach/simpad.h> |
f314f33b | 29 | #include <mach/irqs.h> |
1da177e4 LT |
30 | |
31 | #include <linux/serial_core.h> | |
32 | #include <linux/ioport.h> | |
dbd406f9 JF |
33 | #include <linux/input.h> |
34 | #include <linux/gpio_keys.h> | |
d056f5a8 | 35 | #include <linux/leds.h> |
dbd406f9 | 36 | #include <linux/i2c-gpio.h> |
1da177e4 LT |
37 | |
38 | #include "generic.h" | |
39 | ||
de0bc0d1 JF |
40 | /* |
41 | * CS3 support | |
42 | */ | |
43 | ||
44 | static long cs3_shadow; | |
45 | static spinlock_t cs3_lock; | |
46 | static struct gpio_chip cs3_gpio; | |
47 | ||
48 | long simpad_get_cs3_ro(void) | |
49 | { | |
50 | return readl(CS3_BASE); | |
51 | } | |
52 | EXPORT_SYMBOL(simpad_get_cs3_ro); | |
1da177e4 | 53 | |
de0bc0d1 | 54 | long simpad_get_cs3_shadow(void) |
1da177e4 LT |
55 | { |
56 | return cs3_shadow; | |
57 | } | |
de0bc0d1 | 58 | EXPORT_SYMBOL(simpad_get_cs3_shadow); |
1da177e4 | 59 | |
de0bc0d1 | 60 | static void __simpad_write_cs3(void) |
1da177e4 | 61 | { |
de0bc0d1 | 62 | writel(cs3_shadow, CS3_BASE); |
1da177e4 LT |
63 | } |
64 | ||
de0bc0d1 | 65 | void simpad_set_cs3_bit(int value) |
1da177e4 | 66 | { |
de0bc0d1 JF |
67 | unsigned long flags; |
68 | ||
69 | spin_lock_irqsave(&cs3_lock, flags); | |
1da177e4 | 70 | cs3_shadow |= value; |
de0bc0d1 JF |
71 | __simpad_write_cs3(); |
72 | spin_unlock_irqrestore(&cs3_lock, flags); | |
1da177e4 | 73 | } |
de0bc0d1 | 74 | EXPORT_SYMBOL(simpad_set_cs3_bit); |
1da177e4 | 75 | |
de0bc0d1 | 76 | void simpad_clear_cs3_bit(int value) |
1da177e4 | 77 | { |
de0bc0d1 JF |
78 | unsigned long flags; |
79 | ||
80 | spin_lock_irqsave(&cs3_lock, flags); | |
1da177e4 | 81 | cs3_shadow &= ~value; |
de0bc0d1 JF |
82 | __simpad_write_cs3(); |
83 | spin_unlock_irqrestore(&cs3_lock, flags); | |
1da177e4 | 84 | } |
de0bc0d1 JF |
85 | EXPORT_SYMBOL(simpad_clear_cs3_bit); |
86 | ||
87 | static void cs3_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | |
88 | { | |
89 | if (offset > 15) | |
90 | return; | |
91 | if (value) | |
92 | simpad_set_cs3_bit(1 << offset); | |
93 | else | |
94 | simpad_clear_cs3_bit(1 << offset); | |
95 | }; | |
1da177e4 | 96 | |
de0bc0d1 JF |
97 | static int cs3_gpio_get(struct gpio_chip *chip, unsigned offset) |
98 | { | |
99 | if (offset > 15) | |
100 | return simpad_get_cs3_ro() & (1 << (offset - 16)); | |
101 | return simpad_get_cs3_shadow() & (1 << offset); | |
102 | }; | |
103 | ||
104 | static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | |
105 | { | |
106 | if (offset > 15) | |
107 | return 0; | |
108 | return -EINVAL; | |
109 | }; | |
110 | ||
111 | static int cs3_gpio_direction_output(struct gpio_chip *chip, unsigned offset, | |
112 | int value) | |
113 | { | |
114 | if (offset > 15) | |
115 | return -EINVAL; | |
116 | cs3_gpio_set(chip, offset, value); | |
117 | return 0; | |
118 | }; | |
1da177e4 LT |
119 | |
120 | static struct map_desc simpad_io_desc[] __initdata = { | |
92519d82 DS |
121 | { /* MQ200 */ |
122 | .virtual = 0xf2800000, | |
123 | .pfn = __phys_to_pfn(0x4b800000), | |
124 | .length = 0x00800000, | |
125 | .type = MT_DEVICE | |
de0bc0d1 | 126 | }, { /* Simpad CS3 */ |
b55056ea | 127 | .virtual = (unsigned long)CS3_BASE, |
de0bc0d1 | 128 | .pfn = __phys_to_pfn(SA1100_CS3_PHYS), |
92519d82 DS |
129 | .length = 0x00100000, |
130 | .type = MT_DEVICE | |
131 | }, | |
1da177e4 LT |
132 | }; |
133 | ||
134 | ||
135 | static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate) | |
136 | { | |
137 | if (port->mapbase == (u_int)&Ser1UTCR0) { | |
138 | if (state) | |
139 | { | |
de0bc0d1 JF |
140 | simpad_clear_cs3_bit(RS232_ON); |
141 | simpad_clear_cs3_bit(DECT_POWER_ON); | |
1da177e4 LT |
142 | }else |
143 | { | |
de0bc0d1 JF |
144 | simpad_set_cs3_bit(RS232_ON); |
145 | simpad_set_cs3_bit(DECT_POWER_ON); | |
1da177e4 LT |
146 | } |
147 | } | |
148 | } | |
149 | ||
150 | static struct sa1100_port_fns simpad_port_fns __initdata = { | |
151 | .pm = simpad_uart_pm, | |
152 | }; | |
153 | ||
154 | ||
155 | static struct mtd_partition simpad_partitions[] = { | |
156 | { | |
157 | .name = "SIMpad boot firmware", | |
158 | .size = 0x00080000, | |
159 | .offset = 0, | |
160 | .mask_flags = MTD_WRITEABLE, | |
161 | }, { | |
162 | .name = "SIMpad kernel", | |
163 | .size = 0x0010000, | |
164 | .offset = MTDPART_OFS_APPEND, | |
165 | }, { | |
166 | .name = "SIMpad root jffs2", | |
167 | .size = MTDPART_SIZ_FULL, | |
168 | .offset = MTDPART_OFS_APPEND, | |
169 | } | |
170 | }; | |
171 | ||
172 | static struct flash_platform_data simpad_flash_data = { | |
173 | .map_name = "cfi_probe", | |
174 | .parts = simpad_partitions, | |
175 | .nr_parts = ARRAY_SIZE(simpad_partitions), | |
176 | }; | |
177 | ||
178 | ||
179 | static struct resource simpad_flash_resources [] = { | |
a181099e RK |
180 | DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_16M), |
181 | DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_16M), | |
1da177e4 LT |
182 | }; |
183 | ||
abe06082 RK |
184 | static struct ucb1x00_plat_data simpad_ucb1x00_data = { |
185 | .gpio_base = SIMPAD_UCB1X00_GPIO_BASE, | |
186 | }; | |
187 | ||
323cdfc1 RK |
188 | static struct mcp_plat_data simpad_mcp_data = { |
189 | .mccr0 = MCCR0_ADM, | |
190 | .sclk_rate = 11981000, | |
abe06082 | 191 | .codec_pdata = &simpad_ucb1x00_data, |
323cdfc1 RK |
192 | }; |
193 | ||
1da177e4 LT |
194 | |
195 | ||
196 | static void __init simpad_map_io(void) | |
197 | { | |
198 | sa1100_map_io(); | |
199 | ||
200 | iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc)); | |
201 | ||
de0bc0d1 JF |
202 | /* Initialize CS3 */ |
203 | cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON | | |
204 | RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON); | |
205 | __simpad_write_cs3(); /* Spinlocks not yet initialized */ | |
1da177e4 LT |
206 | |
207 | sa1100_register_uart_fns(&simpad_port_fns); | |
208 | sa1100_register_uart(0, 3); /* serial interface */ | |
209 | sa1100_register_uart(1, 1); /* DECT */ | |
210 | ||
211 | // Reassign UART 1 pins | |
212 | GAFR |= GPIO_UART_TXD | GPIO_UART_RXD; | |
213 | GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15; | |
214 | GPDR &= ~GPIO_UART_RXD; | |
215 | PPAR |= PPAR_UPR; | |
216 | ||
217 | /* | |
218 | * Set up registers for sleep mode. | |
219 | */ | |
220 | ||
221 | ||
222 | PWER = PWER_GPIO0| PWER_RTC; | |
223 | PGSR = 0x818; | |
224 | PCFR = 0; | |
225 | PSDR = 0; | |
226 | ||
1da177e4 LT |
227 | } |
228 | ||
229 | static void simpad_power_off(void) | |
230 | { | |
de0bc0d1 JF |
231 | local_irq_disable(); |
232 | cs3_shadow = SD_MEDIAQ; | |
233 | __simpad_write_cs3(); /* Bypass spinlock here */ | |
1da177e4 LT |
234 | |
235 | /* disable internal oscillator, float CS lines */ | |
236 | PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS); | |
de0bc0d1 JF |
237 | /* enable wake-up on GPIO0 */ |
238 | PWER = GFER = GRER = PWER_GPIO0; | |
1da177e4 LT |
239 | /* |
240 | * set scratchpad to zero, just in case it is used as a | |
241 | * restart address by the bootloader. | |
242 | */ | |
243 | PSPR = 0; | |
244 | PGSR = 0; | |
245 | /* enter sleep mode */ | |
246 | PMCR = PMCR_SF; | |
247 | while(1); | |
248 | ||
249 | local_irq_enable(); /* we won't ever call it */ | |
250 | ||
251 | ||
252 | } | |
253 | ||
dbd406f9 JF |
254 | /* |
255 | * gpio_keys | |
256 | */ | |
257 | ||
258 | static struct gpio_keys_button simpad_button_table[] = { | |
259 | { KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" }, | |
260 | }; | |
261 | ||
262 | static struct gpio_keys_platform_data simpad_keys_data = { | |
263 | .buttons = simpad_button_table, | |
264 | .nbuttons = ARRAY_SIZE(simpad_button_table), | |
265 | }; | |
266 | ||
267 | static struct platform_device simpad_keys = { | |
268 | .name = "gpio-keys", | |
269 | .dev = { | |
270 | .platform_data = &simpad_keys_data, | |
271 | }, | |
272 | }; | |
273 | ||
274 | static struct gpio_keys_button simpad_polled_button_table[] = { | |
275 | { KEY_PROG1, SIMPAD_UCB1X00_GPIO_PROG1, 1, "prog1 button" }, | |
276 | { KEY_PROG2, SIMPAD_UCB1X00_GPIO_PROG2, 1, "prog2 button" }, | |
277 | { KEY_UP, SIMPAD_UCB1X00_GPIO_UP, 1, "up button" }, | |
278 | { KEY_DOWN, SIMPAD_UCB1X00_GPIO_DOWN, 1, "down button" }, | |
279 | { KEY_LEFT, SIMPAD_UCB1X00_GPIO_LEFT, 1, "left button" }, | |
280 | { KEY_RIGHT, SIMPAD_UCB1X00_GPIO_RIGHT, 1, "right button" }, | |
281 | }; | |
282 | ||
283 | static struct gpio_keys_platform_data simpad_polled_keys_data = { | |
284 | .buttons = simpad_polled_button_table, | |
285 | .nbuttons = ARRAY_SIZE(simpad_polled_button_table), | |
286 | .poll_interval = 50, | |
287 | }; | |
288 | ||
289 | static struct platform_device simpad_polled_keys = { | |
290 | .name = "gpio-keys-polled", | |
291 | .dev = { | |
292 | .platform_data = &simpad_polled_keys_data, | |
293 | }, | |
294 | }; | |
295 | ||
d056f5a8 JF |
296 | /* |
297 | * GPIO LEDs | |
298 | */ | |
299 | ||
300 | static struct gpio_led simpad_leds[] = { | |
301 | { | |
302 | .name = "simpad:power", | |
303 | .gpio = SIMPAD_CS3_LED2_ON, | |
304 | .active_low = 0, | |
305 | .default_trigger = "default-on", | |
306 | }, | |
307 | }; | |
308 | ||
309 | static struct gpio_led_platform_data simpad_led_data = { | |
310 | .num_leds = ARRAY_SIZE(simpad_leds), | |
311 | .leds = simpad_leds, | |
312 | }; | |
313 | ||
314 | static struct platform_device simpad_gpio_leds = { | |
315 | .name = "leds-gpio", | |
316 | .id = 0, | |
317 | .dev = { | |
318 | .platform_data = &simpad_led_data, | |
319 | }, | |
320 | }; | |
321 | ||
dbd406f9 JF |
322 | /* |
323 | * i2c | |
324 | */ | |
325 | static struct i2c_gpio_platform_data simpad_i2c_data = { | |
326 | .sda_pin = GPIO_GPIO21, | |
327 | .scl_pin = GPIO_GPIO25, | |
328 | .udelay = 10, | |
329 | .timeout = HZ, | |
330 | }; | |
331 | ||
332 | static struct platform_device simpad_i2c = { | |
333 | .name = "i2c-gpio", | |
334 | .id = 0, | |
335 | .dev = { | |
336 | .platform_data = &simpad_i2c_data, | |
337 | }, | |
338 | }; | |
1da177e4 LT |
339 | |
340 | /* | |
341 | * MediaQ Video Device | |
342 | */ | |
343 | static struct platform_device simpad_mq200fb = { | |
344 | .name = "simpad-mq200", | |
345 | .id = 0, | |
346 | }; | |
347 | ||
348 | static struct platform_device *devices[] __initdata = { | |
dbd406f9 JF |
349 | &simpad_keys, |
350 | &simpad_polled_keys, | |
351 | &simpad_mq200fb, | |
d056f5a8 | 352 | &simpad_gpio_leds, |
dbd406f9 | 353 | &simpad_i2c, |
1da177e4 LT |
354 | }; |
355 | ||
356 | ||
357 | ||
358 | static int __init simpad_init(void) | |
359 | { | |
360 | int ret; | |
361 | ||
de0bc0d1 JF |
362 | spin_lock_init(&cs3_lock); |
363 | ||
364 | cs3_gpio.label = "simpad_cs3"; | |
365 | cs3_gpio.base = SIMPAD_CS3_GPIO_BASE; | |
366 | cs3_gpio.ngpio = 24; | |
367 | cs3_gpio.set = cs3_gpio_set; | |
368 | cs3_gpio.get = cs3_gpio_get; | |
369 | cs3_gpio.direction_input = cs3_gpio_direction_input; | |
370 | cs3_gpio.direction_output = cs3_gpio_direction_output; | |
371 | ret = gpiochip_add(&cs3_gpio); | |
372 | if (ret) | |
373 | printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device"); | |
374 | ||
1da177e4 LT |
375 | pm_power_off = simpad_power_off; |
376 | ||
e36e26a8 | 377 | sa11x0_ppc_configure_mcp(); |
4f444e2b JF |
378 | sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources, |
379 | ARRAY_SIZE(simpad_flash_resources)); | |
380 | sa11x0_register_mcp(&simpad_mcp_data); | |
381 | ||
1da177e4 LT |
382 | ret = platform_add_devices(devices, ARRAY_SIZE(devices)); |
383 | if(ret) | |
384 | printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device"); | |
385 | ||
386 | return 0; | |
387 | } | |
388 | ||
389 | arch_initcall(simpad_init); | |
390 | ||
391 | ||
392 | MACHINE_START(SIMPAD, "Simpad") | |
e9dea0c6 | 393 | /* Maintainer: Holger Freyther */ |
17f4425d | 394 | .atag_offset = 0x100, |
e9dea0c6 | 395 | .map_io = simpad_map_io, |
f314f33b | 396 | .nr_irqs = SA1100_NR_IRQS, |
e9dea0c6 | 397 | .init_irq = sa1100_init_irq, |
7fea1ba5 | 398 | .init_late = sa11x0_init_late, |
6bb27d73 | 399 | .init_time = sa1100_timer_init, |
d9ca5839 | 400 | .restart = sa11x0_restart, |
1da177e4 | 401 | MACHINE_END |