blob: cdb9d197c092429af79f4aa72a794fbe5231b37b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/simpad.c
3 */
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#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>
Russell Kingd052d1b2005-10-29 19:07:23 +010012#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/mtd/mtd.h>
14#include <linux/mtd/partitions.h>
Russell Kingfced80c2008-09-06 12:10:45 +010015#include <linux/io.h>
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010016#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#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>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/mcp.h>
28#include <mach/simpad.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include <linux/serial_core.h>
31#include <linux/ioport.h>
Jochen Friedrichdbd406f2011-08-18 21:51:06 +010032#include <linux/input.h>
33#include <linux/gpio_keys.h>
Jochen Friedrichd056f5a2011-08-18 21:51:39 +010034#include <linux/leds.h>
Jochen Friedrichdbd406f2011-08-18 21:51:06 +010035#include <linux/i2c-gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include "generic.h"
38
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010039/*
40 * CS3 support
41 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010043static long cs3_shadow;
44static spinlock_t cs3_lock;
45static struct gpio_chip cs3_gpio;
46
47long simpad_get_cs3_ro(void)
48{
49 return readl(CS3_BASE);
50}
51EXPORT_SYMBOL(simpad_get_cs3_ro);
52
53long simpad_get_cs3_shadow(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 return cs3_shadow;
56}
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010057EXPORT_SYMBOL(simpad_get_cs3_shadow);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010059static void __simpad_write_cs3(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010061 writel(cs3_shadow, CS3_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010064void simpad_set_cs3_bit(int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010066 unsigned long flags;
67
68 spin_lock_irqsave(&cs3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 cs3_shadow |= value;
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010070 __simpad_write_cs3();
71 spin_unlock_irqrestore(&cs3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010073EXPORT_SYMBOL(simpad_set_cs3_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010075void simpad_clear_cs3_bit(int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010077 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010079 spin_lock_irqsave(&cs3_lock, flags);
80 cs3_shadow &= ~value;
81 __simpad_write_cs3();
82 spin_unlock_irqrestore(&cs3_lock, flags);
83}
84EXPORT_SYMBOL(simpad_clear_cs3_bit);
85
86static 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};
95
96static 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
103static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
104{
105 if (offset > 15)
106 return 0;
107 return -EINVAL;
108};
109
110static 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};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119static struct map_desc simpad_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100120 { /* MQ200 */
121 .virtual = 0xf2800000,
122 .pfn = __phys_to_pfn(0x4b800000),
123 .length = 0x00800000,
124 .type = MT_DEVICE
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100125 }, { /* Simpad CS3 */
126 .virtual = CS3_BASE,
127 .pfn = __phys_to_pfn(SA1100_CS3_PHYS),
Deepak Saxena92519d82005-10-28 15:19:04 +0100128 .length = 0x00100000,
129 .type = MT_DEVICE
130 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
133
134static 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 {
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100139 simpad_clear_cs3_bit(RS232_ON);
140 simpad_clear_cs3_bit(DECT_POWER_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }else
142 {
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100143 simpad_set_cs3_bit(RS232_ON);
144 simpad_set_cs3_bit(DECT_POWER_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
146 }
147}
148
149static struct sa1100_port_fns simpad_port_fns __initdata = {
150 .pm = simpad_uart_pm,
151};
152
153
154static 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
171static 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
178static struct resource simpad_flash_resources [] = {
Russell Kinga1810992012-01-12 10:25:29 +0000179 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_16M),
180 DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_16M),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181};
182
Russell King323cdfc2005-08-18 10:10:46 +0100183static struct mcp_plat_data simpad_mcp_data = {
184 .mccr0 = MCCR0_ADM,
185 .sclk_rate = 11981000,
Russell King65f2e752012-01-20 17:38:58 +0000186 .gpio_base = SIMPAD_UCB1X00_GPIO_BASE,
Russell King323cdfc2005-08-18 10:10:46 +0100187};
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190
191static void __init simpad_map_io(void)
192{
193 sa1100_map_io();
194
195 iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
196
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100197 /* Initialize CS3 */
198 cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON |
199 RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
200 __simpad_write_cs3(); /* Spinlocks not yet initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 sa1100_register_uart_fns(&simpad_port_fns);
203 sa1100_register_uart(0, 3); /* serial interface */
204 sa1100_register_uart(1, 1); /* DECT */
205
206 // Reassign UART 1 pins
207 GAFR |= GPIO_UART_TXD | GPIO_UART_RXD;
208 GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15;
209 GPDR &= ~GPIO_UART_RXD;
210 PPAR |= PPAR_UPR;
211
212 /*
213 * Set up registers for sleep mode.
214 */
215
216
217 PWER = PWER_GPIO0| PWER_RTC;
218 PGSR = 0x818;
219 PCFR = 0;
220 PSDR = 0;
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
224static void simpad_power_off(void)
225{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100226 local_irq_disable();
227 cs3_shadow = SD_MEDIAQ;
228 __simpad_write_cs3(); /* Bypass spinlock here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 /* disable internal oscillator, float CS lines */
231 PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100232 /* enable wake-up on GPIO0 */
233 PWER = GFER = GRER = PWER_GPIO0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 /*
235 * set scratchpad to zero, just in case it is used as a
236 * restart address by the bootloader.
237 */
238 PSPR = 0;
239 PGSR = 0;
240 /* enter sleep mode */
241 PMCR = PMCR_SF;
242 while(1);
243
244 local_irq_enable(); /* we won't ever call it */
245
246
247}
248
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100249/*
250 * gpio_keys
251*/
252
253static struct gpio_keys_button simpad_button_table[] = {
254 { KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" },
255};
256
257static struct gpio_keys_platform_data simpad_keys_data = {
258 .buttons = simpad_button_table,
259 .nbuttons = ARRAY_SIZE(simpad_button_table),
260};
261
262static struct platform_device simpad_keys = {
263 .name = "gpio-keys",
264 .dev = {
265 .platform_data = &simpad_keys_data,
266 },
267};
268
269static struct gpio_keys_button simpad_polled_button_table[] = {
270 { KEY_PROG1, SIMPAD_UCB1X00_GPIO_PROG1, 1, "prog1 button" },
271 { KEY_PROG2, SIMPAD_UCB1X00_GPIO_PROG2, 1, "prog2 button" },
272 { KEY_UP, SIMPAD_UCB1X00_GPIO_UP, 1, "up button" },
273 { KEY_DOWN, SIMPAD_UCB1X00_GPIO_DOWN, 1, "down button" },
274 { KEY_LEFT, SIMPAD_UCB1X00_GPIO_LEFT, 1, "left button" },
275 { KEY_RIGHT, SIMPAD_UCB1X00_GPIO_RIGHT, 1, "right button" },
276};
277
278static struct gpio_keys_platform_data simpad_polled_keys_data = {
279 .buttons = simpad_polled_button_table,
280 .nbuttons = ARRAY_SIZE(simpad_polled_button_table),
281 .poll_interval = 50,
282};
283
284static struct platform_device simpad_polled_keys = {
285 .name = "gpio-keys-polled",
286 .dev = {
287 .platform_data = &simpad_polled_keys_data,
288 },
289};
290
291/*
Jochen Friedrichd056f5a2011-08-18 21:51:39 +0100292 * GPIO LEDs
293 */
294
295static struct gpio_led simpad_leds[] = {
296 {
297 .name = "simpad:power",
298 .gpio = SIMPAD_CS3_LED2_ON,
299 .active_low = 0,
300 .default_trigger = "default-on",
301 },
302};
303
304static struct gpio_led_platform_data simpad_led_data = {
305 .num_leds = ARRAY_SIZE(simpad_leds),
306 .leds = simpad_leds,
307};
308
309static struct platform_device simpad_gpio_leds = {
310 .name = "leds-gpio",
311 .id = 0,
312 .dev = {
313 .platform_data = &simpad_led_data,
314 },
315};
316
317/*
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100318 * i2c
319 */
320static struct i2c_gpio_platform_data simpad_i2c_data = {
321 .sda_pin = GPIO_GPIO21,
322 .scl_pin = GPIO_GPIO25,
323 .udelay = 10,
324 .timeout = HZ,
325};
326
327static struct platform_device simpad_i2c = {
328 .name = "i2c-gpio",
329 .id = 0,
330 .dev = {
331 .platform_data = &simpad_i2c_data,
332 },
333};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335/*
336 * MediaQ Video Device
337 */
338static struct platform_device simpad_mq200fb = {
339 .name = "simpad-mq200",
340 .id = 0,
341};
342
343static struct platform_device *devices[] __initdata = {
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100344 &simpad_keys,
345 &simpad_polled_keys,
346 &simpad_mq200fb,
Jochen Friedrichd056f5a2011-08-18 21:51:39 +0100347 &simpad_gpio_leds,
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100348 &simpad_i2c,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349};
350
351
352
353static int __init simpad_init(void)
354{
355 int ret;
356
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100357 spin_lock_init(&cs3_lock);
358
359 cs3_gpio.label = "simpad_cs3";
360 cs3_gpio.base = SIMPAD_CS3_GPIO_BASE;
361 cs3_gpio.ngpio = 24;
362 cs3_gpio.set = cs3_gpio_set;
363 cs3_gpio.get = cs3_gpio_get;
364 cs3_gpio.direction_input = cs3_gpio_direction_input;
365 cs3_gpio.direction_output = cs3_gpio_direction_output;
366 ret = gpiochip_add(&cs3_gpio);
367 if (ret)
368 printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 pm_power_off = simpad_power_off;
371
Jochen Friedrich4f444e22011-01-03 12:09:05 +0100372 sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
373 ARRAY_SIZE(simpad_flash_resources));
374 sa11x0_register_mcp(&simpad_mcp_data);
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
377 if(ret)
378 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
379
380 return 0;
381}
382
383arch_initcall(simpad_init);
384
385
386MACHINE_START(SIMPAD, "Simpad")
Russell Kinge9dea0c2005-07-03 17:38:58 +0100387 /* Maintainer: Holger Freyther */
Nicolas Pitre17f44252011-07-05 22:38:17 -0400388 .atag_offset = 0x100,
Russell Kinge9dea0c2005-07-03 17:38:58 +0100389 .map_io = simpad_map_io,
390 .init_irq = sa1100_init_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 .timer = &sa1100_timer,
Russell Kingd9ca5832011-11-05 10:28:50 +0000392 .restart = sa11x0_restart,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393MACHINE_END