2 * linux/arch/arm/mach-sa1100/simpad.c
5 #include <linux/module.h>
6 #include <linux/init.h>
7 #include <linux/kernel.h>
9 #include <linux/proc_fs.h>
10 #include <linux/string.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
16 #include <linux/gpio.h>
19 #include <mach/hardware.h>
20 #include <asm/setup.h>
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>
28 #include <mach/simpad.h>
30 #include <linux/serial_core.h>
31 #include <linux/ioport.h>
32 #include <linux/input.h>
33 #include <linux/gpio_keys.h>
34 #include <linux/leds.h>
35 #include <linux/i2c-gpio.h>
43 static long cs3_shadow;
44 static spinlock_t cs3_lock;
45 static struct gpio_chip cs3_gpio;
47 long simpad_get_cs3_ro(void)
49 return readl(CS3_BASE);
51 EXPORT_SYMBOL(simpad_get_cs3_ro);
53 long simpad_get_cs3_shadow(void)
57 EXPORT_SYMBOL(simpad_get_cs3_shadow);
59 static void __simpad_write_cs3(void)
61 writel(cs3_shadow, CS3_BASE);
64 void simpad_set_cs3_bit(int value)
68 spin_lock_irqsave(&cs3_lock, flags);
71 spin_unlock_irqrestore(&cs3_lock, flags);
73 EXPORT_SYMBOL(simpad_set_cs3_bit);
75 void simpad_clear_cs3_bit(int value)
79 spin_lock_irqsave(&cs3_lock, flags);
82 spin_unlock_irqrestore(&cs3_lock, flags);
84 EXPORT_SYMBOL(simpad_clear_cs3_bit);
86 static void cs3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
91 simpad_set_cs3_bit(1 << offset);
93 simpad_clear_cs3_bit(1 << offset);
96 static int cs3_gpio_get(struct gpio_chip *chip, unsigned offset)
99 return simpad_get_cs3_ro() & (1 << (offset - 16));
100 return simpad_get_cs3_shadow() & (1 << offset);
103 static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
110 static int cs3_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
115 cs3_gpio_set(chip, offset, value);
119 static struct map_desc simpad_io_desc[] __initdata = {
121 .virtual = 0xf2800000,
122 .pfn = __phys_to_pfn(0x4b800000),
123 .length = 0x00800000,
125 }, { /* Simpad CS3 */
127 .pfn = __phys_to_pfn(SA1100_CS3_PHYS),
128 .length = 0x00100000,
134 static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
136 if (port->mapbase == (u_int)&Ser1UTCR0) {
139 simpad_clear_cs3_bit(RS232_ON);
140 simpad_clear_cs3_bit(DECT_POWER_ON);
143 simpad_set_cs3_bit(RS232_ON);
144 simpad_set_cs3_bit(DECT_POWER_ON);
149 static struct sa1100_port_fns simpad_port_fns __initdata = {
150 .pm = simpad_uart_pm,
154 static struct mtd_partition simpad_partitions[] = {
156 .name = "SIMpad boot firmware",
159 .mask_flags = MTD_WRITEABLE,
161 .name = "SIMpad kernel",
163 .offset = MTDPART_OFS_APPEND,
165 .name = "SIMpad root jffs2",
166 .size = MTDPART_SIZ_FULL,
167 .offset = MTDPART_OFS_APPEND,
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),
178 static struct resource simpad_flash_resources [] = {
179 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_16M),
180 DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_16M),
183 static struct mcp_plat_data simpad_mcp_data = {
185 .sclk_rate = 11981000,
186 .gpio_base = SIMPAD_UCB1X00_GPIO_BASE,
191 static void __init simpad_map_io(void)
195 iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
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 */
202 sa1100_register_uart_fns(&simpad_port_fns);
203 sa1100_register_uart(0, 3); /* serial interface */
204 sa1100_register_uart(1, 1); /* DECT */
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;
213 * Set up registers for sleep mode.
217 PWER = PWER_GPIO0| PWER_RTC;
224 static void simpad_power_off(void)
227 cs3_shadow = SD_MEDIAQ;
228 __simpad_write_cs3(); /* Bypass spinlock here */
230 /* disable internal oscillator, float CS lines */
231 PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
232 /* enable wake-up on GPIO0 */
233 PWER = GFER = GRER = PWER_GPIO0;
235 * set scratchpad to zero, just in case it is used as a
236 * restart address by the bootloader.
240 /* enter sleep mode */
244 local_irq_enable(); /* we won't ever call it */
253 static struct gpio_keys_button simpad_button_table[] = {
254 { KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" },
257 static struct gpio_keys_platform_data simpad_keys_data = {
258 .buttons = simpad_button_table,
259 .nbuttons = ARRAY_SIZE(simpad_button_table),
262 static struct platform_device simpad_keys = {
265 .platform_data = &simpad_keys_data,
269 static 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" },
278 static struct gpio_keys_platform_data simpad_polled_keys_data = {
279 .buttons = simpad_polled_button_table,
280 .nbuttons = ARRAY_SIZE(simpad_polled_button_table),
284 static struct platform_device simpad_polled_keys = {
285 .name = "gpio-keys-polled",
287 .platform_data = &simpad_polled_keys_data,
295 static struct gpio_led simpad_leds[] = {
297 .name = "simpad:power",
298 .gpio = SIMPAD_CS3_LED2_ON,
300 .default_trigger = "default-on",
304 static struct gpio_led_platform_data simpad_led_data = {
305 .num_leds = ARRAY_SIZE(simpad_leds),
309 static struct platform_device simpad_gpio_leds = {
313 .platform_data = &simpad_led_data,
320 static struct i2c_gpio_platform_data simpad_i2c_data = {
321 .sda_pin = GPIO_GPIO21,
322 .scl_pin = GPIO_GPIO25,
327 static struct platform_device simpad_i2c = {
331 .platform_data = &simpad_i2c_data,
336 * MediaQ Video Device
338 static struct platform_device simpad_mq200fb = {
339 .name = "simpad-mq200",
343 static struct platform_device *devices[] __initdata = {
353 static int __init simpad_init(void)
357 spin_lock_init(&cs3_lock);
359 cs3_gpio.label = "simpad_cs3";
360 cs3_gpio.base = SIMPAD_CS3_GPIO_BASE;
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);
368 printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
370 pm_power_off = simpad_power_off;
372 sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
373 ARRAY_SIZE(simpad_flash_resources));
374 sa11x0_register_mcp(&simpad_mcp_data);
376 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
378 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
383 arch_initcall(simpad_init);
386 MACHINE_START(SIMPAD, "Simpad")
387 /* Maintainer: Holger Freyther */
388 .atag_offset = 0x100,
389 .map_io = simpad_map_io,
390 .init_irq = sa1100_init_irq,
391 .timer = &sa1100_timer,
392 .restart = sa11x0_restart,