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