include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / arch / arm / mach-pxa / viper.c
CommitLineData
352699a3
MZ
1/*
2 * linux/arch/arm/mach-pxa/viper.c
3 *
4 * Support for the Arcom VIPER SBC.
5 *
6 * Author: Ian Campbell
7 * Created: Feb 03, 2003
8 * Copyright: Arcom Control Systems
9 *
10 * Maintained by Marc Zyngier <maz@misterjones.org>
11 * <marc.zyngier@altran.com>
12 *
13 * Based on lubbock.c:
14 * Author: Nicolas Pitre
15 * Created: Jun 15, 2001
16 * Copyright: MontaVista Software Inc.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2 as
20 * published by the Free Software Foundation.
21 */
22
23#include <linux/types.h>
24#include <linux/memory.h>
25#include <linux/cpu.h>
26#include <linux/cpufreq.h>
27#include <linux/delay.h>
28#include <linux/fs.h>
29#include <linux/init.h>
5a0e3ad6 30#include <linux/slab.h>
352699a3
MZ
31#include <linux/interrupt.h>
32#include <linux/major.h>
33#include <linux/module.h>
34#include <linux/pm.h>
35#include <linux/sched.h>
36#include <linux/gpio.h>
37#include <linux/i2c-gpio.h>
38#include <linux/serial_8250.h>
39#include <linux/smc91x.h>
40#include <linux/pwm_backlight.h>
41#include <linux/usb/isp116x.h>
42#include <linux/mtd/mtd.h>
43#include <linux/mtd/partitions.h>
44#include <linux/mtd/physmap.h>
45
51c62982 46#include <mach/pxa25x.h>
352699a3
MZ
47#include <mach/audio.h>
48#include <mach/pxafb.h>
f0a83701 49#include <plat/i2c.h>
776abac8 50#include <mach/regs-uart.h>
c2de1c38 51#include <mach/arcom-pcmcia.h>
352699a3
MZ
52#include <mach/viper.h>
53
54#include <asm/setup.h>
55#include <asm/mach-types.h>
56#include <asm/irq.h>
57#include <asm/sizes.h>
58
59#include <asm/mach/arch.h>
60#include <asm/mach/map.h>
61#include <asm/mach/irq.h>
62
63#include "generic.h"
64#include "devices.h"
65
66static unsigned int icr;
67
68static void viper_icr_set_bit(unsigned int bit)
69{
70 icr |= bit;
71 VIPER_ICR = icr;
72}
73
74static void viper_icr_clear_bit(unsigned int bit)
75{
76 icr &= ~bit;
77 VIPER_ICR = icr;
78}
79
80/* This function is used from the pcmcia module to reset the CF */
c2de1c38 81static void viper_cf_reset(int state)
352699a3
MZ
82{
83 if (state)
84 viper_icr_set_bit(VIPER_ICR_CF_RST);
85 else
86 viper_icr_clear_bit(VIPER_ICR_CF_RST);
87}
c2de1c38
MZ
88
89static struct arcom_pcmcia_pdata viper_pcmcia_info = {
90 .cd_gpio = VIPER_CF_CD_GPIO,
91 .rdy_gpio = VIPER_CF_RDY_GPIO,
92 .pwr_gpio = VIPER_CF_POWER_GPIO,
93 .reset = viper_cf_reset,
94};
95
96static struct platform_device viper_pcmcia_device = {
97 .name = "viper-pcmcia",
98 .id = -1,
99 .dev = {
100 .platform_data = &viper_pcmcia_info,
101 },
102};
352699a3
MZ
103
104/*
105 * The CPLD version register was not present on VIPER boards prior to
106 * v2i1. On v1 boards where the version register is not present we
107 * will just read back the previous value from the databus.
108 *
109 * Therefore we do two reads. The first time we write 0 to the
110 * (read-only) register before reading and the second time we write
111 * 0xff first. If the two reads do not match or they read back as 0xff
112 * or 0x00 then we have version 1 hardware.
113 */
114static u8 viper_hw_version(void)
115{
116 u8 v1, v2;
117 unsigned long flags;
118
119 local_irq_save(flags);
120
121 VIPER_VERSION = 0;
122 v1 = VIPER_VERSION;
123 VIPER_VERSION = 0xff;
124 v2 = VIPER_VERSION;
125
126 v1 = (v1 != v2 || v1 == 0xff) ? 0 : v1;
127
128 local_irq_restore(flags);
129 return v1;
130}
131
132/* CPU sysdev */
133static int viper_cpu_suspend(struct sys_device *sysdev, pm_message_t state)
134{
135 viper_icr_set_bit(VIPER_ICR_R_DIS);
136 return 0;
137}
138
139static int viper_cpu_resume(struct sys_device *sysdev)
140{
141 viper_icr_clear_bit(VIPER_ICR_R_DIS);
142 return 0;
143}
144
145static struct sysdev_driver viper_cpu_sysdev_driver = {
146 .suspend = viper_cpu_suspend,
147 .resume = viper_cpu_resume,
148};
149
150static unsigned int current_voltage_divisor;
151
152/*
153 * If force is not true then step from existing to new divisor. If
154 * force is true then jump straight to the new divisor. Stepping is
155 * used because if the jump in voltage is too large, the VCC can dip
156 * too low and the regulator cuts out.
157 *
158 * force can be used to initialize the divisor to a know state by
159 * setting the value for the current clock speed, since we are already
160 * running at that speed we know the voltage should be pretty close so
161 * the jump won't be too large
162 */
163static void viper_set_core_cpu_voltage(unsigned long khz, int force)
164{
165 int i = 0;
166 unsigned int divisor = 0;
167 const char *v;
168
169 if (khz < 200000) {
170 v = "1.0"; divisor = 0xfff;
171 } else if (khz < 300000) {
172 v = "1.1"; divisor = 0xde5;
173 } else {
174 v = "1.3"; divisor = 0x325;
175 }
176
177 pr_debug("viper: setting CPU core voltage to %sV at %d.%03dMHz\n",
178 v, (int)khz / 1000, (int)khz % 1000);
179
180#define STEP 0x100
181 do {
182 int step;
183
184 if (force)
185 step = divisor;
186 else if (current_voltage_divisor < divisor - STEP)
187 step = current_voltage_divisor + STEP;
188 else if (current_voltage_divisor > divisor + STEP)
189 step = current_voltage_divisor - STEP;
190 else
191 step = divisor;
192 force = 0;
193
194 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
195 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
196
197 for (i = 1 << 11 ; i > 0 ; i >>= 1) {
198 udelay(1);
199
200 gpio_set_value(VIPER_PSU_DATA_GPIO, step & i);
201 udelay(1);
202
203 gpio_set_value(VIPER_PSU_CLK_GPIO, 1);
204 udelay(1);
205
206 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
207 }
208 udelay(1);
209
210 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 1);
211 udelay(1);
212
213 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
214
215 current_voltage_divisor = step;
216 } while (current_voltage_divisor != divisor);
217}
218
219/* Interrupt handling */
220static unsigned long viper_irq_enabled_mask;
a9ff8f64
MZ
221static const int viper_isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, 9, 14, 15 };
222static const int viper_isa_irq_map[] = {
223 0, /* ISA irq #0, invalid */
224 0, /* ISA irq #1, invalid */
225 0, /* ISA irq #2, invalid */
226 1 << 0, /* ISA irq #3 */
227 1 << 1, /* ISA irq #4 */
228 1 << 2, /* ISA irq #5 */
229 1 << 3, /* ISA irq #6 */
230 1 << 4, /* ISA irq #7 */
231 0, /* ISA irq #8, invalid */
232 1 << 8, /* ISA irq #9 */
233 1 << 5, /* ISA irq #10 */
234 1 << 6, /* ISA irq #11 */
235 1 << 7, /* ISA irq #12 */
236 0, /* ISA irq #13, invalid */
237 1 << 9, /* ISA irq #14 */
238 1 << 10, /* ISA irq #15 */
239};
240
241static inline int viper_irq_to_bitmask(unsigned int irq)
242{
243 return viper_isa_irq_map[irq - PXA_ISA_IRQ(0)];
244}
245
246static inline int viper_bit_to_irq(int bit)
247{
248 return viper_isa_irqs[bit] + PXA_ISA_IRQ(0);
249}
352699a3
MZ
250
251static void viper_ack_irq(unsigned int irq)
252{
a9ff8f64 253 int viper_irq = viper_irq_to_bitmask(irq);
352699a3 254
a9ff8f64
MZ
255 if (viper_irq & 0xff)
256 VIPER_LO_IRQ_STATUS = viper_irq;
352699a3 257 else
a9ff8f64 258 VIPER_HI_IRQ_STATUS = (viper_irq >> 8);
352699a3
MZ
259}
260
261static void viper_mask_irq(unsigned int irq)
262{
a9ff8f64 263 viper_irq_enabled_mask &= ~(viper_irq_to_bitmask(irq));
352699a3
MZ
264}
265
266static void viper_unmask_irq(unsigned int irq)
267{
a9ff8f64 268 viper_irq_enabled_mask |= viper_irq_to_bitmask(irq);
352699a3
MZ
269}
270
271static inline unsigned long viper_irq_pending(void)
272{
273 return (VIPER_HI_IRQ_STATUS << 8 | VIPER_LO_IRQ_STATUS) &
274 viper_irq_enabled_mask;
275}
276
277static void viper_irq_handler(unsigned int irq, struct irq_desc *desc)
278{
279 unsigned long pending;
280
281 pending = viper_irq_pending();
282 do {
a9ff8f64
MZ
283 /* we're in a chained irq handler,
284 * so ack the interrupt by hand */
669cb51c 285 desc->chip->ack(irq);
a9ff8f64 286
352699a3 287 if (likely(pending)) {
a9ff8f64 288 irq = viper_bit_to_irq(__ffs(pending));
352699a3
MZ
289 generic_handle_irq(irq);
290 }
291 pending = viper_irq_pending();
292 } while (pending);
293}
294
295static struct irq_chip viper_irq_chip = {
296 .name = "ISA",
297 .ack = viper_ack_irq,
298 .mask = viper_mask_irq,
299 .unmask = viper_unmask_irq
300};
301
302static void __init viper_init_irq(void)
303{
a9ff8f64 304 int level;
352699a3
MZ
305 int isa_irq;
306
307 pxa25x_init_irq();
308
309 /* setup ISA IRQs */
a9ff8f64
MZ
310 for (level = 0; level < ARRAY_SIZE(viper_isa_irqs); level++) {
311 isa_irq = viper_bit_to_irq(level);
352699a3
MZ
312 set_irq_chip(isa_irq, &viper_irq_chip);
313 set_irq_handler(isa_irq, handle_edge_irq);
314 set_irq_flags(isa_irq, IRQF_VALID | IRQF_PROBE);
315 }
316
317 set_irq_chained_handler(gpio_to_irq(VIPER_CPLD_GPIO),
318 viper_irq_handler);
319 set_irq_type(gpio_to_irq(VIPER_CPLD_GPIO), IRQ_TYPE_EDGE_BOTH);
352699a3
MZ
320}
321
322/* Flat Panel */
323static struct pxafb_mode_info fb_mode_info[] = {
324 {
325 .pixclock = 157500,
326
327 .xres = 320,
328 .yres = 240,
329
330 .bpp = 16,
331
332 .hsync_len = 63,
333 .left_margin = 7,
334 .right_margin = 13,
335
336 .vsync_len = 20,
337 .upper_margin = 0,
338 .lower_margin = 0,
339
340 .sync = 0,
341 },
342};
343
344static struct pxafb_mach_info fb_info = {
345 .modes = fb_mode_info,
346 .num_modes = 1,
347 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
348};
349
350static int viper_backlight_init(struct device *dev)
351{
352 int ret;
353
354 /* GPIO9 and 10 control FB backlight. Initialise to off */
355 ret = gpio_request(VIPER_BCKLIGHT_EN_GPIO, "Backlight");
356 if (ret)
357 goto err_request_bckl;
358
359 ret = gpio_request(VIPER_LCD_EN_GPIO, "LCD");
360 if (ret)
361 goto err_request_lcd;
362
363 ret = gpio_direction_output(VIPER_BCKLIGHT_EN_GPIO, 0);
364 if (ret)
365 goto err_dir;
366
367 ret = gpio_direction_output(VIPER_LCD_EN_GPIO, 0);
368 if (ret)
369 goto err_dir;
370
371 return 0;
372
373err_dir:
374 gpio_free(VIPER_LCD_EN_GPIO);
375err_request_lcd:
376 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
377err_request_bckl:
378 dev_err(dev, "Failed to setup LCD GPIOs\n");
379
380 return ret;
381}
382
2d51a521 383static int viper_backlight_notify(struct device *dev, int brightness)
352699a3
MZ
384{
385 gpio_set_value(VIPER_LCD_EN_GPIO, !!brightness);
386 gpio_set_value(VIPER_BCKLIGHT_EN_GPIO, !!brightness);
387
388 return brightness;
389}
390
391static void viper_backlight_exit(struct device *dev)
392{
393 gpio_free(VIPER_LCD_EN_GPIO);
394 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
395}
396
397static struct platform_pwm_backlight_data viper_backlight_data = {
398 .pwm_id = 0,
399 .max_brightness = 100,
400 .dft_brightness = 100,
401 .pwm_period_ns = 1000000,
402 .init = viper_backlight_init,
403 .notify = viper_backlight_notify,
404 .exit = viper_backlight_exit,
405};
406
407static struct platform_device viper_backlight_device = {
408 .name = "pwm-backlight",
409 .dev = {
410 .parent = &pxa25x_device_pwm0.dev,
411 .platform_data = &viper_backlight_data,
412 },
413};
414
415/* Ethernet */
416static struct resource smc91x_resources[] = {
417 [0] = {
418 .name = "smc91x-regs",
419 .start = VIPER_ETH_PHYS + 0x300,
420 .end = VIPER_ETH_PHYS + 0x30f,
421 .flags = IORESOURCE_MEM,
422 },
423 [1] = {
424 .start = gpio_to_irq(VIPER_ETH_GPIO),
425 .end = gpio_to_irq(VIPER_ETH_GPIO),
426 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
427 },
428 [2] = {
429 .name = "smc91x-data32",
430 .start = VIPER_ETH_DATA_PHYS,
431 .end = VIPER_ETH_DATA_PHYS + 3,
432 .flags = IORESOURCE_MEM,
433 },
434};
435
436static struct smc91x_platdata viper_smc91x_info = {
437 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
438 .leda = RPC_LED_100_10,
439 .ledb = RPC_LED_TX_RX,
440};
441
442static struct platform_device smc91x_device = {
443 .name = "smc91x",
444 .id = -1,
445 .num_resources = ARRAY_SIZE(smc91x_resources),
446 .resource = smc91x_resources,
447 .dev = {
448 .platform_data = &viper_smc91x_info,
449 },
450};
451
452/* i2c */
453static struct i2c_gpio_platform_data i2c_bus_data = {
454 .sda_pin = VIPER_RTC_I2C_SDA_GPIO,
455 .scl_pin = VIPER_RTC_I2C_SCL_GPIO,
456 .udelay = 10,
457 .timeout = 100,
458};
459
460static struct platform_device i2c_bus_device = {
461 .name = "i2c-gpio",
462 .id = 1, /* pxa2xx-i2c is bus 0, so start at 1 */
463 .dev = {
464 .platform_data = &i2c_bus_data,
465 }
466};
467
468static struct i2c_board_info __initdata viper_i2c_devices[] = {
469 {
470 I2C_BOARD_INFO("ds1338", 0x68),
471 },
472};
473
474/*
475 * Serial configuration:
476 * You can either have the standard PXA ports driven by the PXA driver,
477 * or all the ports (PXA + 16850) driven by the 8250 driver.
478 * Choose your poison.
479 */
480
481static struct resource viper_serial_resources[] = {
482#ifndef CONFIG_SERIAL_PXA
483 {
484 .start = 0x40100000,
485 .end = 0x4010001f,
486 .flags = IORESOURCE_MEM,
487 },
488 {
489 .start = 0x40200000,
490 .end = 0x4020001f,
491 .flags = IORESOURCE_MEM,
492 },
493 {
494 .start = 0x40700000,
495 .end = 0x4070001f,
496 .flags = IORESOURCE_MEM,
497 },
498 {
499 .start = VIPER_UARTA_PHYS,
500 .end = VIPER_UARTA_PHYS + 0xf,
501 .flags = IORESOURCE_MEM,
502 },
503 {
504 .start = VIPER_UARTB_PHYS,
505 .end = VIPER_UARTB_PHYS + 0xf,
506 .flags = IORESOURCE_MEM,
507 },
508#else
509 {
510 0,
511 },
512#endif
513};
514
515static struct plat_serial8250_port serial_platform_data[] = {
516#ifndef CONFIG_SERIAL_PXA
517 /* Internal UARTs */
518 {
519 .membase = (void *)&FFUART,
520 .mapbase = __PREG(FFUART),
521 .irq = IRQ_FFUART,
522 .uartclk = 921600 * 16,
523 .regshift = 2,
524 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
525 .iotype = UPIO_MEM,
526 },
527 {
528 .membase = (void *)&BTUART,
529 .mapbase = __PREG(BTUART),
530 .irq = IRQ_BTUART,
531 .uartclk = 921600 * 16,
532 .regshift = 2,
533 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
534 .iotype = UPIO_MEM,
535 },
536 {
537 .membase = (void *)&STUART,
538 .mapbase = __PREG(STUART),
539 .irq = IRQ_STUART,
540 .uartclk = 921600 * 16,
541 .regshift = 2,
542 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
543 .iotype = UPIO_MEM,
544 },
545 /* External UARTs */
546 {
547 .mapbase = VIPER_UARTA_PHYS,
548 .irq = gpio_to_irq(VIPER_UARTA_GPIO),
3fe6ccff 549 .irqflags = IRQF_TRIGGER_RISING,
352699a3
MZ
550 .uartclk = 1843200,
551 .regshift = 1,
552 .iotype = UPIO_MEM,
553 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
554 UPF_SKIP_TEST,
555 },
556 {
557 .mapbase = VIPER_UARTB_PHYS,
558 .irq = gpio_to_irq(VIPER_UARTB_GPIO),
3fe6ccff 559 .irqflags = IRQF_TRIGGER_RISING,
352699a3
MZ
560 .uartclk = 1843200,
561 .regshift = 1,
562 .iotype = UPIO_MEM,
563 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
564 UPF_SKIP_TEST,
565 },
566#endif
567 { },
568};
569
570static struct platform_device serial_device = {
571 .name = "serial8250",
572 .id = 0,
573 .dev = {
574 .platform_data = serial_platform_data,
575 },
576 .num_resources = ARRAY_SIZE(viper_serial_resources),
577 .resource = viper_serial_resources,
578};
579
580/* USB */
581static void isp116x_delay(struct device *dev, int delay)
582{
583 ndelay(delay);
584}
585
586static struct resource isp116x_resources[] = {
587 [0] = { /* DATA */
588 .start = VIPER_USB_PHYS + 0,
589 .end = VIPER_USB_PHYS + 1,
590 .flags = IORESOURCE_MEM,
591 },
592 [1] = { /* ADDR */
593 .start = VIPER_USB_PHYS + 2,
594 .end = VIPER_USB_PHYS + 3,
595 .flags = IORESOURCE_MEM,
596 },
597 [2] = {
598 .start = gpio_to_irq(VIPER_USB_GPIO),
599 .end = gpio_to_irq(VIPER_USB_GPIO),
600 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
601 },
602};
603
604/* (DataBusWidth16|AnalogOCEnable|DREQOutputPolarity|DownstreamPort15KRSel ) */
605static struct isp116x_platform_data isp116x_platform_data = {
606 /* Enable internal resistors on downstream ports */
607 .sel15Kres = 1,
608 /* On-chip overcurrent protection */
609 .oc_enable = 1,
610 /* INT output polarity */
611 .int_act_high = 1,
612 /* INT edge or level triggered */
613 .int_edge_triggered = 0,
614
615 /* WAKEUP pin connected - NOT SUPPORTED */
616 /* .remote_wakeup_connected = 0, */
617 /* Wakeup by devices on usb bus enabled */
618 .remote_wakeup_enable = 0,
619 .delay = isp116x_delay,
620};
621
622static struct platform_device isp116x_device = {
623 .name = "isp116x-hcd",
624 .id = -1,
625 .num_resources = ARRAY_SIZE(isp116x_resources),
626 .resource = isp116x_resources,
627 .dev = {
628 .platform_data = &isp116x_platform_data,
629 },
630
631};
632
633/* MTD */
634static struct resource mtd_resources[] = {
635 [0] = { /* RedBoot config + filesystem flash */
636 .start = VIPER_FLASH_PHYS,
637 .end = VIPER_FLASH_PHYS + SZ_32M - 1,
638 .flags = IORESOURCE_MEM,
639 },
640 [1] = { /* Boot flash */
641 .start = VIPER_BOOT_PHYS,
642 .end = VIPER_BOOT_PHYS + SZ_1M - 1,
643 .flags = IORESOURCE_MEM,
644 },
645 [2] = { /*
646 * SRAM size is actually 256KB, 8bits, with a sparse mapping
647 * (each byte is on a 16bit boundary).
648 */
649 .start = _VIPER_SRAM_BASE,
650 .end = _VIPER_SRAM_BASE + SZ_512K - 1,
651 .flags = IORESOURCE_MEM,
652 },
653};
654
655static struct mtd_partition viper_boot_flash_partition = {
656 .name = "RedBoot",
657 .size = SZ_1M,
658 .offset = 0,
659 .mask_flags = MTD_WRITEABLE, /* force R/O */
660};
661
662static struct physmap_flash_data viper_flash_data[] = {
663 [0] = {
664 .width = 2,
665 .parts = NULL,
666 .nr_parts = 0,
667 },
668 [1] = {
669 .width = 2,
670 .parts = &viper_boot_flash_partition,
671 .nr_parts = 1,
672 },
673};
674
675static struct platform_device viper_mtd_devices[] = {
676 [0] = {
677 .name = "physmap-flash",
678 .id = 0,
679 .dev = {
680 .platform_data = &viper_flash_data[0],
681 },
682 .resource = &mtd_resources[0],
683 .num_resources = 1,
684 },
685 [1] = {
686 .name = "physmap-flash",
687 .id = 1,
688 .dev = {
689 .platform_data = &viper_flash_data[1],
690 },
691 .resource = &mtd_resources[1],
692 .num_resources = 1,
693 },
694};
695
696static struct platform_device *viper_devs[] __initdata = {
697 &smc91x_device,
698 &i2c_bus_device,
699 &serial_device,
700 &isp116x_device,
701 &viper_mtd_devices[0],
702 &viper_mtd_devices[1],
703 &viper_backlight_device,
c2de1c38 704 &viper_pcmcia_device,
352699a3
MZ
705};
706
707static mfp_cfg_t viper_pin_config[] __initdata = {
708 /* Chip selects */
709 GPIO15_nCS_1,
710 GPIO78_nCS_2,
711 GPIO79_nCS_3,
712 GPIO80_nCS_4,
713 GPIO33_nCS_5,
714
c11b6a42
EM
715 /* AC97 */
716 GPIO28_AC97_BITCLK,
717 GPIO29_AC97_SDATA_IN_0,
718 GPIO30_AC97_SDATA_OUT,
719 GPIO31_AC97_SYNC,
720
352699a3
MZ
721 /* FP Backlight */
722 GPIO9_GPIO, /* VIPER_BCKLIGHT_EN_GPIO */
723 GPIO10_GPIO, /* VIPER_LCD_EN_GPIO */
724 GPIO16_PWM0_OUT,
725
726 /* Ethernet PHY Ready */
727 GPIO18_RDY,
728
729 /* Serial shutdown */
730 GPIO12_GPIO | MFP_LPM_DRIVE_HIGH, /* VIPER_UART_SHDN_GPIO */
731
732 /* Compact-Flash / PC104 */
733 GPIO48_nPOE,
734 GPIO49_nPWE,
735 GPIO50_nPIOR,
736 GPIO51_nPIOW,
737 GPIO52_nPCE_1,
738 GPIO53_nPCE_2,
739 GPIO54_nPSKTSEL,
740 GPIO55_nPREG,
741 GPIO56_nPWAIT,
742 GPIO57_nIOIS16,
743 GPIO8_GPIO, /* VIPER_CF_RDY_GPIO */
744 GPIO32_GPIO, /* VIPER_CF_CD_GPIO */
745 GPIO82_GPIO, /* VIPER_CF_POWER_GPIO */
746
747 /* Integrated UPS control */
748 GPIO20_GPIO, /* VIPER_UPS_GPIO */
749
750 /* Vcc regulator control */
751 GPIO6_GPIO, /* VIPER_PSU_DATA_GPIO */
752 GPIO11_GPIO, /* VIPER_PSU_CLK_GPIO */
753 GPIO19_GPIO, /* VIPER_PSU_nCS_LD_GPIO */
754
755 /* i2c busses */
756 GPIO26_GPIO, /* VIPER_TPM_I2C_SDA_GPIO */
757 GPIO27_GPIO, /* VIPER_TPM_I2C_SCL_GPIO */
758 GPIO83_GPIO, /* VIPER_RTC_I2C_SDA_GPIO */
759 GPIO84_GPIO, /* VIPER_RTC_I2C_SCL_GPIO */
760
761 /* PC/104 Interrupt */
762 GPIO1_GPIO | WAKEUP_ON_EDGE_RISE, /* VIPER_CPLD_GPIO */
763};
764
765static unsigned long viper_tpm;
766
767static int __init viper_tpm_setup(char *str)
768{
769 strict_strtoul(str, 10, &viper_tpm);
770 return 1;
771}
772
773__setup("tpm=", viper_tpm_setup);
774
775static void __init viper_tpm_init(void)
776{
777 struct platform_device *tpm_device;
778 struct i2c_gpio_platform_data i2c_tpm_data = {
779 .sda_pin = VIPER_TPM_I2C_SDA_GPIO,
780 .scl_pin = VIPER_TPM_I2C_SCL_GPIO,
781 .udelay = 10,
782 .timeout = 100,
783 };
784 char *errstr;
785
786 /* Allocate TPM i2c bus if requested */
787 if (!viper_tpm)
788 return;
789
790 tpm_device = platform_device_alloc("i2c-gpio", 2);
791 if (tpm_device) {
792 if (!platform_device_add_data(tpm_device,
793 &i2c_tpm_data,
794 sizeof(i2c_tpm_data))) {
795 if (platform_device_add(tpm_device)) {
796 errstr = "register TPM i2c bus";
797 goto error_free_tpm;
798 }
799 } else {
800 errstr = "allocate TPM i2c bus data";
801 goto error_free_tpm;
802 }
803 } else {
804 errstr = "allocate TPM i2c device";
805 goto error_tpm;
806 }
807
808 return;
809
810error_free_tpm:
811 kfree(tpm_device);
812error_tpm:
813 pr_err("viper: Couldn't %s, giving up\n", errstr);
814}
815
816static void __init viper_init_vcore_gpios(void)
817{
818 if (gpio_request(VIPER_PSU_DATA_GPIO, "PSU data"))
819 goto err_request_data;
820
821 if (gpio_request(VIPER_PSU_CLK_GPIO, "PSU clock"))
822 goto err_request_clk;
823
824 if (gpio_request(VIPER_PSU_nCS_LD_GPIO, "PSU cs"))
825 goto err_request_cs;
826
827 if (gpio_direction_output(VIPER_PSU_DATA_GPIO, 0) ||
828 gpio_direction_output(VIPER_PSU_CLK_GPIO, 0) ||
829 gpio_direction_output(VIPER_PSU_nCS_LD_GPIO, 0))
830 goto err_dir;
831
832 /* c/should assume redboot set the correct level ??? */
833 viper_set_core_cpu_voltage(get_clk_frequency_khz(0), 1);
834
835 return;
836
837err_dir:
838 gpio_free(VIPER_PSU_nCS_LD_GPIO);
839err_request_cs:
840 gpio_free(VIPER_PSU_CLK_GPIO);
841err_request_clk:
842 gpio_free(VIPER_PSU_DATA_GPIO);
843err_request_data:
844 pr_err("viper: Failed to setup vcore control GPIOs\n");
845}
846
847static void __init viper_init_serial_gpio(void)
848{
849 if (gpio_request(VIPER_UART_SHDN_GPIO, "UARTs shutdown"))
850 goto err_request;
851
852 if (gpio_direction_output(VIPER_UART_SHDN_GPIO, 0))
853 goto err_dir;
854
855 return;
856
857err_dir:
858 gpio_free(VIPER_UART_SHDN_GPIO);
859err_request:
860 pr_err("viper: Failed to setup UART shutdown GPIO\n");
861}
862
863#ifdef CONFIG_CPU_FREQ
864static int viper_cpufreq_notifier(struct notifier_block *nb,
865 unsigned long val, void *data)
866{
867 struct cpufreq_freqs *freq = data;
868
869 /* TODO: Adjust timings??? */
870
871 switch (val) {
872 case CPUFREQ_PRECHANGE:
873 if (freq->old < freq->new) {
874 /* we are getting faster so raise the voltage
875 * before we change freq */
876 viper_set_core_cpu_voltage(freq->new, 0);
877 }
878 break;
879 case CPUFREQ_POSTCHANGE:
880 if (freq->old > freq->new) {
881 /* we are slowing down so drop the power
882 * after we change freq */
883 viper_set_core_cpu_voltage(freq->new, 0);
884 }
885 break;
886 case CPUFREQ_RESUMECHANGE:
887 viper_set_core_cpu_voltage(freq->new, 0);
888 break;
889 default:
890 /* ignore */
891 break;
892 }
893
894 return 0;
895}
896
897static struct notifier_block viper_cpufreq_notifier_block = {
898 .notifier_call = viper_cpufreq_notifier
899};
900
901static void __init viper_init_cpufreq(void)
902{
903 if (cpufreq_register_notifier(&viper_cpufreq_notifier_block,
904 CPUFREQ_TRANSITION_NOTIFIER))
905 pr_err("viper: Failed to setup cpufreq notifier\n");
906}
907#else
908static inline void viper_init_cpufreq(void) {}
909#endif
910
911static void viper_power_off(void)
912{
913 pr_notice("Shutting off UPS\n");
914 gpio_set_value(VIPER_UPS_GPIO, 1);
915 /* Spin to death... */
916 while (1);
917}
918
919static void __init viper_init(void)
920{
921 u8 version;
922
923 pm_power_off = viper_power_off;
924
925 pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));
926
cc155c6f
RK
927 pxa_set_ffuart_info(NULL);
928 pxa_set_btuart_info(NULL);
929 pxa_set_stuart_info(NULL);
930
352699a3
MZ
931 /* Wake-up serial console */
932 viper_init_serial_gpio();
933
934 set_pxa_fb_info(&fb_info);
935
936 /* v1 hardware cannot use the datacs line */
937 version = viper_hw_version();
938 if (version == 0)
939 smc91x_device.num_resources--;
940
941 pxa_set_i2c_info(NULL);
942 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));
943
944 viper_init_vcore_gpios();
945 viper_init_cpufreq();
946
947 sysdev_driver_register(&cpu_sysdev_class, &viper_cpu_sysdev_driver);
948
949 if (version) {
950 pr_info("viper: hardware v%di%d detected. "
951 "CPLD revision %d.\n",
952 VIPER_BOARD_VERSION(version),
953 VIPER_BOARD_ISSUE(version),
954 VIPER_CPLD_REVISION(version));
955 system_rev = (VIPER_BOARD_VERSION(version) << 8) |
956 (VIPER_BOARD_ISSUE(version) << 4) |
957 VIPER_CPLD_REVISION(version);
958 } else {
959 pr_info("viper: No version register.\n");
960 }
961
962 i2c_register_board_info(1, ARRAY_AND_SIZE(viper_i2c_devices));
963
964 viper_tpm_init();
965 pxa_set_ac97_info(NULL);
966}
967
968static struct map_desc viper_io_desc[] __initdata = {
969 {
970 .virtual = VIPER_CPLD_BASE,
971 .pfn = __phys_to_pfn(VIPER_CPLD_PHYS),
972 .length = 0x00300000,
973 .type = MT_DEVICE,
974 },
975 {
976 .virtual = VIPER_PC104IO_BASE,
b393c696 977 .pfn = __phys_to_pfn(0x30000000),
352699a3
MZ
978 .length = 0x00800000,
979 .type = MT_DEVICE,
980 },
981};
982
983static void __init viper_map_io(void)
984{
985 pxa_map_io();
986
987 iotable_init(viper_io_desc, ARRAY_SIZE(viper_io_desc));
988
989 PCFR |= PCFR_OPDE;
990}
991
992MACHINE_START(VIPER, "Arcom/Eurotech VIPER SBC")
993 /* Maintainer: Marc Zyngier <maz@misterjones.org> */
994 .phys_io = 0x40000000,
995 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
996 .boot_params = 0xa0000100,
997 .map_io = viper_map_io,
998 .init_irq = viper_init_irq,
999 .timer = &pxa_timer,
1000 .init_machine = viper_init,
1001MACHINE_END