blob: 81506562ee26e6514138b79d09964a544ef779e9 [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>
Russell Kingabe06082012-01-20 22:13:52 +000013#include <linux/mfd/ucb1x00.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/mtd/mtd.h>
15#include <linux/mtd/partitions.h>
Russell Kingfced80c2008-09-06 12:10:45 +010016#include <linux/io.h>
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010017#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010020#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#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>
27#include <asm/mach/serial_sa1100.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/mcp.h>
29#include <mach/simpad.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <linux/serial_core.h>
32#include <linux/ioport.h>
Jochen Friedrichdbd406f2011-08-18 21:51:06 +010033#include <linux/input.h>
34#include <linux/gpio_keys.h>
Jochen Friedrichd056f5a2011-08-18 21:51:39 +010035#include <linux/leds.h>
Jochen Friedrichdbd406f2011-08-18 21:51:06 +010036#include <linux/i2c-gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include "generic.h"
39
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010040/*
41 * CS3 support
42 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010044static long cs3_shadow;
45static spinlock_t cs3_lock;
46static struct gpio_chip cs3_gpio;
47
48long simpad_get_cs3_ro(void)
49{
50 return readl(CS3_BASE);
51}
52EXPORT_SYMBOL(simpad_get_cs3_ro);
53
54long simpad_get_cs3_shadow(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 return cs3_shadow;
57}
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010058EXPORT_SYMBOL(simpad_get_cs3_shadow);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010060static void __simpad_write_cs3(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010062 writel(cs3_shadow, CS3_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010065void simpad_set_cs3_bit(int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010067 unsigned long flags;
68
69 spin_lock_irqsave(&cs3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 cs3_shadow |= value;
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010071 __simpad_write_cs3();
72 spin_unlock_irqrestore(&cs3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010074EXPORT_SYMBOL(simpad_set_cs3_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010076void simpad_clear_cs3_bit(int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010078 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +010080 spin_lock_irqsave(&cs3_lock, flags);
81 cs3_shadow &= ~value;
82 __simpad_write_cs3();
83 spin_unlock_irqrestore(&cs3_lock, flags);
84}
85EXPORT_SYMBOL(simpad_clear_cs3_bit);
86
87static 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};
96
97static 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
104static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
105{
106 if (offset > 15)
107 return 0;
108 return -EINVAL;
109};
110
111static 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};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120static struct map_desc simpad_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100121 { /* MQ200 */
122 .virtual = 0xf2800000,
123 .pfn = __phys_to_pfn(0x4b800000),
124 .length = 0x00800000,
125 .type = MT_DEVICE
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100126 }, { /* Simpad CS3 */
127 .virtual = CS3_BASE,
128 .pfn = __phys_to_pfn(SA1100_CS3_PHYS),
Deepak Saxena92519d82005-10-28 15:19:04 +0100129 .length = 0x00100000,
130 .type = MT_DEVICE
131 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132};
133
134
135static 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 {
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100140 simpad_clear_cs3_bit(RS232_ON);
141 simpad_clear_cs3_bit(DECT_POWER_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }else
143 {
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100144 simpad_set_cs3_bit(RS232_ON);
145 simpad_set_cs3_bit(DECT_POWER_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147 }
148}
149
150static struct sa1100_port_fns simpad_port_fns __initdata = {
151 .pm = simpad_uart_pm,
152};
153
154
155static 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
172static 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
179static struct resource simpad_flash_resources [] = {
180 {
181 .start = SA1100_CS0_PHYS,
182 .end = SA1100_CS0_PHYS + SZ_16M -1,
183 .flags = IORESOURCE_MEM,
184 }, {
185 .start = SA1100_CS1_PHYS,
186 .end = SA1100_CS1_PHYS + SZ_16M -1,
187 .flags = IORESOURCE_MEM,
188 }
189};
190
Russell Kingabe06082012-01-20 22:13:52 +0000191static struct ucb1x00_plat_data simpad_ucb1x00_data = {
192 .gpio_base = SIMPAD_UCB1X00_GPIO_BASE,
193};
194
Russell King323cdfc2005-08-18 10:10:46 +0100195static struct mcp_plat_data simpad_mcp_data = {
196 .mccr0 = MCCR0_ADM,
197 .sclk_rate = 11981000,
Russell Kingabe06082012-01-20 22:13:52 +0000198 .codec_pdata = &simpad_ucb1x00_data,
Russell King323cdfc2005-08-18 10:10:46 +0100199};
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202
203static void __init simpad_map_io(void)
204{
205 sa1100_map_io();
206
207 iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
208
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100209 /* Initialize CS3 */
210 cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON |
211 RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
212 __simpad_write_cs3(); /* Spinlocks not yet initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 sa1100_register_uart_fns(&simpad_port_fns);
215 sa1100_register_uart(0, 3); /* serial interface */
216 sa1100_register_uart(1, 1); /* DECT */
217
218 // Reassign UART 1 pins
219 GAFR |= GPIO_UART_TXD | GPIO_UART_RXD;
220 GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15;
221 GPDR &= ~GPIO_UART_RXD;
222 PPAR |= PPAR_UPR;
223
224 /*
225 * Set up registers for sleep mode.
226 */
227
228
229 PWER = PWER_GPIO0| PWER_RTC;
230 PGSR = 0x818;
231 PCFR = 0;
232 PSDR = 0;
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
236static void simpad_power_off(void)
237{
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100238 local_irq_disable();
239 cs3_shadow = SD_MEDIAQ;
240 __simpad_write_cs3(); /* Bypass spinlock here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 /* disable internal oscillator, float CS lines */
243 PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100244 /* enable wake-up on GPIO0 */
245 PWER = GFER = GRER = PWER_GPIO0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /*
247 * set scratchpad to zero, just in case it is used as a
248 * restart address by the bootloader.
249 */
250 PSPR = 0;
251 PGSR = 0;
252 /* enter sleep mode */
253 PMCR = PMCR_SF;
254 while(1);
255
256 local_irq_enable(); /* we won't ever call it */
257
258
259}
260
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100261/*
262 * gpio_keys
263*/
264
265static struct gpio_keys_button simpad_button_table[] = {
266 { KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" },
267};
268
269static struct gpio_keys_platform_data simpad_keys_data = {
270 .buttons = simpad_button_table,
271 .nbuttons = ARRAY_SIZE(simpad_button_table),
272};
273
274static struct platform_device simpad_keys = {
275 .name = "gpio-keys",
276 .dev = {
277 .platform_data = &simpad_keys_data,
278 },
279};
280
281static struct gpio_keys_button simpad_polled_button_table[] = {
282 { KEY_PROG1, SIMPAD_UCB1X00_GPIO_PROG1, 1, "prog1 button" },
283 { KEY_PROG2, SIMPAD_UCB1X00_GPIO_PROG2, 1, "prog2 button" },
284 { KEY_UP, SIMPAD_UCB1X00_GPIO_UP, 1, "up button" },
285 { KEY_DOWN, SIMPAD_UCB1X00_GPIO_DOWN, 1, "down button" },
286 { KEY_LEFT, SIMPAD_UCB1X00_GPIO_LEFT, 1, "left button" },
287 { KEY_RIGHT, SIMPAD_UCB1X00_GPIO_RIGHT, 1, "right button" },
288};
289
290static struct gpio_keys_platform_data simpad_polled_keys_data = {
291 .buttons = simpad_polled_button_table,
292 .nbuttons = ARRAY_SIZE(simpad_polled_button_table),
293 .poll_interval = 50,
294};
295
296static struct platform_device simpad_polled_keys = {
297 .name = "gpio-keys-polled",
298 .dev = {
299 .platform_data = &simpad_polled_keys_data,
300 },
301};
302
303/*
Jochen Friedrichd056f5a2011-08-18 21:51:39 +0100304 * GPIO LEDs
305 */
306
307static struct gpio_led simpad_leds[] = {
308 {
309 .name = "simpad:power",
310 .gpio = SIMPAD_CS3_LED2_ON,
311 .active_low = 0,
312 .default_trigger = "default-on",
313 },
314};
315
316static struct gpio_led_platform_data simpad_led_data = {
317 .num_leds = ARRAY_SIZE(simpad_leds),
318 .leds = simpad_leds,
319};
320
321static struct platform_device simpad_gpio_leds = {
322 .name = "leds-gpio",
323 .id = 0,
324 .dev = {
325 .platform_data = &simpad_led_data,
326 },
327};
328
329/*
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100330 * i2c
331 */
332static struct i2c_gpio_platform_data simpad_i2c_data = {
333 .sda_pin = GPIO_GPIO21,
334 .scl_pin = GPIO_GPIO25,
335 .udelay = 10,
336 .timeout = HZ,
337};
338
339static struct platform_device simpad_i2c = {
340 .name = "i2c-gpio",
341 .id = 0,
342 .dev = {
343 .platform_data = &simpad_i2c_data,
344 },
345};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347/*
348 * MediaQ Video Device
349 */
350static struct platform_device simpad_mq200fb = {
351 .name = "simpad-mq200",
352 .id = 0,
353};
354
355static struct platform_device *devices[] __initdata = {
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100356 &simpad_keys,
357 &simpad_polled_keys,
358 &simpad_mq200fb,
Jochen Friedrichd056f5a2011-08-18 21:51:39 +0100359 &simpad_gpio_leds,
Jochen Friedrichdbd406f2011-08-18 21:51:06 +0100360 &simpad_i2c,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361};
362
363
364
365static int __init simpad_init(void)
366{
367 int ret;
368
Jochen Friedrichde0bc0d2011-08-18 21:50:31 +0100369 spin_lock_init(&cs3_lock);
370
371 cs3_gpio.label = "simpad_cs3";
372 cs3_gpio.base = SIMPAD_CS3_GPIO_BASE;
373 cs3_gpio.ngpio = 24;
374 cs3_gpio.set = cs3_gpio_set;
375 cs3_gpio.get = cs3_gpio_get;
376 cs3_gpio.direction_input = cs3_gpio_direction_input;
377 cs3_gpio.direction_output = cs3_gpio_direction_output;
378 ret = gpiochip_add(&cs3_gpio);
379 if (ret)
380 printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 pm_power_off = simpad_power_off;
383
Russell Kinge36e26a2012-01-20 22:24:07 +0000384 sa11x0_ppc_configure_mcp();
Jochen Friedrich4f444e22011-01-03 12:09:05 +0100385 sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
386 ARRAY_SIZE(simpad_flash_resources));
387 sa11x0_register_mcp(&simpad_mcp_data);
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
390 if(ret)
391 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
392
393 return 0;
394}
395
396arch_initcall(simpad_init);
397
398
399MACHINE_START(SIMPAD, "Simpad")
Russell Kinge9dea0c2005-07-03 17:38:58 +0100400 /* Maintainer: Holger Freyther */
Nicolas Pitre17f44252011-07-05 22:38:17 -0400401 .atag_offset = 0x100,
Russell Kinge9dea0c2005-07-03 17:38:58 +0100402 .map_io = simpad_map_io,
403 .init_irq = sa1100_init_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .timer = &sa1100_timer,
Russell Kingd9ca5832011-11-05 10:28:50 +0000405 .restart = sa11x0_restart,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406MACHINE_END