bridge: netfilter: fix update_pmtu crash with GRE
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / mach-pxa / viper.c
blob4b3120dbc049946b75f05b94b8f6479ca40ecdd9
1 /*
2 * linux/arch/arm/mach-pxa/viper.c
4 * Support for the Arcom VIPER SBC.
6 * Author: Ian Campbell
7 * Created: Feb 03, 2003
8 * Copyright: Arcom Control Systems
10 * Maintained by Marc Zyngier <maz@misterjones.org>
11 * <marc.zyngier@altran.com>
13 * Based on lubbock.c:
14 * Author: Nicolas Pitre
15 * Created: Jun 15, 2001
16 * Copyright: MontaVista Software Inc.
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.
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>
30 #include <linux/interrupt.h>
31 #include <linux/major.h>
32 #include <linux/module.h>
33 #include <linux/pm.h>
34 #include <linux/sched.h>
35 #include <linux/gpio.h>
36 #include <linux/i2c-gpio.h>
37 #include <linux/serial_8250.h>
38 #include <linux/smc91x.h>
39 #include <linux/pwm_backlight.h>
40 #include <linux/usb/isp116x.h>
41 #include <linux/mtd/mtd.h>
42 #include <linux/mtd/partitions.h>
43 #include <linux/mtd/physmap.h>
45 #include <mach/pxa-regs.h>
46 #include <mach/pxa2xx-regs.h>
47 #include <mach/bitfield.h>
48 #include <mach/audio.h>
49 #include <mach/pxafb.h>
50 #include <mach/mfp-pxa25x.h>
51 #include <mach/i2c.h>
52 #include <mach/viper.h>
54 #include <asm/setup.h>
55 #include <asm/mach-types.h>
56 #include <asm/irq.h>
57 #include <asm/sizes.h>
59 #include <asm/mach/arch.h>
60 #include <asm/mach/map.h>
61 #include <asm/mach/irq.h>
63 #include "generic.h"
64 #include "devices.h"
66 static unsigned int icr;
68 static void viper_icr_set_bit(unsigned int bit)
70 icr |= bit;
71 VIPER_ICR = icr;
74 static void viper_icr_clear_bit(unsigned int bit)
76 icr &= ~bit;
77 VIPER_ICR = icr;
80 /* This function is used from the pcmcia module to reset the CF */
81 void viper_cf_rst(int state)
83 if (state)
84 viper_icr_set_bit(VIPER_ICR_CF_RST);
85 else
86 viper_icr_clear_bit(VIPER_ICR_CF_RST);
88 EXPORT_SYMBOL(viper_cf_rst);
91 * The CPLD version register was not present on VIPER boards prior to
92 * v2i1. On v1 boards where the version register is not present we
93 * will just read back the previous value from the databus.
95 * Therefore we do two reads. The first time we write 0 to the
96 * (read-only) register before reading and the second time we write
97 * 0xff first. If the two reads do not match or they read back as 0xff
98 * or 0x00 then we have version 1 hardware.
100 static u8 viper_hw_version(void)
102 u8 v1, v2;
103 unsigned long flags;
105 local_irq_save(flags);
107 VIPER_VERSION = 0;
108 v1 = VIPER_VERSION;
109 VIPER_VERSION = 0xff;
110 v2 = VIPER_VERSION;
112 v1 = (v1 != v2 || v1 == 0xff) ? 0 : v1;
114 local_irq_restore(flags);
115 return v1;
118 /* CPU sysdev */
119 static int viper_cpu_suspend(struct sys_device *sysdev, pm_message_t state)
121 viper_icr_set_bit(VIPER_ICR_R_DIS);
122 return 0;
125 static int viper_cpu_resume(struct sys_device *sysdev)
127 viper_icr_clear_bit(VIPER_ICR_R_DIS);
128 return 0;
131 static struct sysdev_driver viper_cpu_sysdev_driver = {
132 .suspend = viper_cpu_suspend,
133 .resume = viper_cpu_resume,
136 static unsigned int current_voltage_divisor;
139 * If force is not true then step from existing to new divisor. If
140 * force is true then jump straight to the new divisor. Stepping is
141 * used because if the jump in voltage is too large, the VCC can dip
142 * too low and the regulator cuts out.
144 * force can be used to initialize the divisor to a know state by
145 * setting the value for the current clock speed, since we are already
146 * running at that speed we know the voltage should be pretty close so
147 * the jump won't be too large
149 static void viper_set_core_cpu_voltage(unsigned long khz, int force)
151 int i = 0;
152 unsigned int divisor = 0;
153 const char *v;
155 if (khz < 200000) {
156 v = "1.0"; divisor = 0xfff;
157 } else if (khz < 300000) {
158 v = "1.1"; divisor = 0xde5;
159 } else {
160 v = "1.3"; divisor = 0x325;
163 pr_debug("viper: setting CPU core voltage to %sV at %d.%03dMHz\n",
164 v, (int)khz / 1000, (int)khz % 1000);
166 #define STEP 0x100
167 do {
168 int step;
170 if (force)
171 step = divisor;
172 else if (current_voltage_divisor < divisor - STEP)
173 step = current_voltage_divisor + STEP;
174 else if (current_voltage_divisor > divisor + STEP)
175 step = current_voltage_divisor - STEP;
176 else
177 step = divisor;
178 force = 0;
180 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
181 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
183 for (i = 1 << 11 ; i > 0 ; i >>= 1) {
184 udelay(1);
186 gpio_set_value(VIPER_PSU_DATA_GPIO, step & i);
187 udelay(1);
189 gpio_set_value(VIPER_PSU_CLK_GPIO, 1);
190 udelay(1);
192 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
194 udelay(1);
196 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 1);
197 udelay(1);
199 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
201 current_voltage_divisor = step;
202 } while (current_voltage_divisor != divisor);
205 /* Interrupt handling */
206 static unsigned long viper_irq_enabled_mask;
207 static const int viper_isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, 9, 14, 15 };
208 static const int viper_isa_irq_map[] = {
209 0, /* ISA irq #0, invalid */
210 0, /* ISA irq #1, invalid */
211 0, /* ISA irq #2, invalid */
212 1 << 0, /* ISA irq #3 */
213 1 << 1, /* ISA irq #4 */
214 1 << 2, /* ISA irq #5 */
215 1 << 3, /* ISA irq #6 */
216 1 << 4, /* ISA irq #7 */
217 0, /* ISA irq #8, invalid */
218 1 << 8, /* ISA irq #9 */
219 1 << 5, /* ISA irq #10 */
220 1 << 6, /* ISA irq #11 */
221 1 << 7, /* ISA irq #12 */
222 0, /* ISA irq #13, invalid */
223 1 << 9, /* ISA irq #14 */
224 1 << 10, /* ISA irq #15 */
227 static inline int viper_irq_to_bitmask(unsigned int irq)
229 return viper_isa_irq_map[irq - PXA_ISA_IRQ(0)];
232 static inline int viper_bit_to_irq(int bit)
234 return viper_isa_irqs[bit] + PXA_ISA_IRQ(0);
237 static void viper_ack_irq(unsigned int irq)
239 int viper_irq = viper_irq_to_bitmask(irq);
241 if (viper_irq & 0xff)
242 VIPER_LO_IRQ_STATUS = viper_irq;
243 else
244 VIPER_HI_IRQ_STATUS = (viper_irq >> 8);
247 static void viper_mask_irq(unsigned int irq)
249 viper_irq_enabled_mask &= ~(viper_irq_to_bitmask(irq));
252 static void viper_unmask_irq(unsigned int irq)
254 viper_irq_enabled_mask |= viper_irq_to_bitmask(irq);
257 static inline unsigned long viper_irq_pending(void)
259 return (VIPER_HI_IRQ_STATUS << 8 | VIPER_LO_IRQ_STATUS) &
260 viper_irq_enabled_mask;
263 static void viper_irq_handler(unsigned int irq, struct irq_desc *desc)
265 unsigned long pending;
267 pending = viper_irq_pending();
268 do {
269 /* we're in a chained irq handler,
270 * so ack the interrupt by hand */
271 GEDR(VIPER_CPLD_GPIO) = GPIO_bit(VIPER_CPLD_GPIO);
273 if (likely(pending)) {
274 irq = viper_bit_to_irq(__ffs(pending));
275 generic_handle_irq(irq);
277 pending = viper_irq_pending();
278 } while (pending);
281 static struct irq_chip viper_irq_chip = {
282 .name = "ISA",
283 .ack = viper_ack_irq,
284 .mask = viper_mask_irq,
285 .unmask = viper_unmask_irq
288 static void __init viper_init_irq(void)
290 int level;
291 int isa_irq;
293 pxa25x_init_irq();
295 /* setup ISA IRQs */
296 for (level = 0; level < ARRAY_SIZE(viper_isa_irqs); level++) {
297 isa_irq = viper_bit_to_irq(level);
298 set_irq_chip(isa_irq, &viper_irq_chip);
299 set_irq_handler(isa_irq, handle_edge_irq);
300 set_irq_flags(isa_irq, IRQF_VALID | IRQF_PROBE);
303 set_irq_chained_handler(gpio_to_irq(VIPER_CPLD_GPIO),
304 viper_irq_handler);
305 set_irq_type(gpio_to_irq(VIPER_CPLD_GPIO), IRQ_TYPE_EDGE_BOTH);
307 #ifndef CONFIG_SERIAL_PXA
309 * 8250 doesn't support IRQ_TYPE being passed as part
310 * of the plat_serial8250_port structure...
312 set_irq_type(gpio_to_irq(VIPER_UARTA_GPIO), IRQ_TYPE_EDGE_RISING);
313 set_irq_type(gpio_to_irq(VIPER_UARTB_GPIO), IRQ_TYPE_EDGE_RISING);
314 #endif
317 /* Flat Panel */
318 static struct pxafb_mode_info fb_mode_info[] = {
320 .pixclock = 157500,
322 .xres = 320,
323 .yres = 240,
325 .bpp = 16,
327 .hsync_len = 63,
328 .left_margin = 7,
329 .right_margin = 13,
331 .vsync_len = 20,
332 .upper_margin = 0,
333 .lower_margin = 0,
335 .sync = 0,
339 static struct pxafb_mach_info fb_info = {
340 .modes = fb_mode_info,
341 .num_modes = 1,
342 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
345 static int viper_backlight_init(struct device *dev)
347 int ret;
349 /* GPIO9 and 10 control FB backlight. Initialise to off */
350 ret = gpio_request(VIPER_BCKLIGHT_EN_GPIO, "Backlight");
351 if (ret)
352 goto err_request_bckl;
354 ret = gpio_request(VIPER_LCD_EN_GPIO, "LCD");
355 if (ret)
356 goto err_request_lcd;
358 ret = gpio_direction_output(VIPER_BCKLIGHT_EN_GPIO, 0);
359 if (ret)
360 goto err_dir;
362 ret = gpio_direction_output(VIPER_LCD_EN_GPIO, 0);
363 if (ret)
364 goto err_dir;
366 return 0;
368 err_dir:
369 gpio_free(VIPER_LCD_EN_GPIO);
370 err_request_lcd:
371 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
372 err_request_bckl:
373 dev_err(dev, "Failed to setup LCD GPIOs\n");
375 return ret;
378 static int viper_backlight_notify(int brightness)
380 gpio_set_value(VIPER_LCD_EN_GPIO, !!brightness);
381 gpio_set_value(VIPER_BCKLIGHT_EN_GPIO, !!brightness);
383 return brightness;
386 static void viper_backlight_exit(struct device *dev)
388 gpio_free(VIPER_LCD_EN_GPIO);
389 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
392 static struct platform_pwm_backlight_data viper_backlight_data = {
393 .pwm_id = 0,
394 .max_brightness = 100,
395 .dft_brightness = 100,
396 .pwm_period_ns = 1000000,
397 .init = viper_backlight_init,
398 .notify = viper_backlight_notify,
399 .exit = viper_backlight_exit,
402 static struct platform_device viper_backlight_device = {
403 .name = "pwm-backlight",
404 .dev = {
405 .parent = &pxa25x_device_pwm0.dev,
406 .platform_data = &viper_backlight_data,
410 /* Ethernet */
411 static struct resource smc91x_resources[] = {
412 [0] = {
413 .name = "smc91x-regs",
414 .start = VIPER_ETH_PHYS + 0x300,
415 .end = VIPER_ETH_PHYS + 0x30f,
416 .flags = IORESOURCE_MEM,
418 [1] = {
419 .start = gpio_to_irq(VIPER_ETH_GPIO),
420 .end = gpio_to_irq(VIPER_ETH_GPIO),
421 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
423 [2] = {
424 .name = "smc91x-data32",
425 .start = VIPER_ETH_DATA_PHYS,
426 .end = VIPER_ETH_DATA_PHYS + 3,
427 .flags = IORESOURCE_MEM,
431 static struct smc91x_platdata viper_smc91x_info = {
432 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
433 .leda = RPC_LED_100_10,
434 .ledb = RPC_LED_TX_RX,
437 static struct platform_device smc91x_device = {
438 .name = "smc91x",
439 .id = -1,
440 .num_resources = ARRAY_SIZE(smc91x_resources),
441 .resource = smc91x_resources,
442 .dev = {
443 .platform_data = &viper_smc91x_info,
447 /* i2c */
448 static struct i2c_gpio_platform_data i2c_bus_data = {
449 .sda_pin = VIPER_RTC_I2C_SDA_GPIO,
450 .scl_pin = VIPER_RTC_I2C_SCL_GPIO,
451 .udelay = 10,
452 .timeout = 100,
455 static struct platform_device i2c_bus_device = {
456 .name = "i2c-gpio",
457 .id = 1, /* pxa2xx-i2c is bus 0, so start at 1 */
458 .dev = {
459 .platform_data = &i2c_bus_data,
463 static struct i2c_board_info __initdata viper_i2c_devices[] = {
465 I2C_BOARD_INFO("ds1338", 0x68),
470 * Serial configuration:
471 * You can either have the standard PXA ports driven by the PXA driver,
472 * or all the ports (PXA + 16850) driven by the 8250 driver.
473 * Choose your poison.
476 static struct resource viper_serial_resources[] = {
477 #ifndef CONFIG_SERIAL_PXA
479 .start = 0x40100000,
480 .end = 0x4010001f,
481 .flags = IORESOURCE_MEM,
484 .start = 0x40200000,
485 .end = 0x4020001f,
486 .flags = IORESOURCE_MEM,
489 .start = 0x40700000,
490 .end = 0x4070001f,
491 .flags = IORESOURCE_MEM,
494 .start = VIPER_UARTA_PHYS,
495 .end = VIPER_UARTA_PHYS + 0xf,
496 .flags = IORESOURCE_MEM,
499 .start = VIPER_UARTB_PHYS,
500 .end = VIPER_UARTB_PHYS + 0xf,
501 .flags = IORESOURCE_MEM,
503 #else
507 #endif
510 static struct plat_serial8250_port serial_platform_data[] = {
511 #ifndef CONFIG_SERIAL_PXA
512 /* Internal UARTs */
514 .membase = (void *)&FFUART,
515 .mapbase = __PREG(FFUART),
516 .irq = IRQ_FFUART,
517 .uartclk = 921600 * 16,
518 .regshift = 2,
519 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
520 .iotype = UPIO_MEM,
523 .membase = (void *)&BTUART,
524 .mapbase = __PREG(BTUART),
525 .irq = IRQ_BTUART,
526 .uartclk = 921600 * 16,
527 .regshift = 2,
528 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
529 .iotype = UPIO_MEM,
532 .membase = (void *)&STUART,
533 .mapbase = __PREG(STUART),
534 .irq = IRQ_STUART,
535 .uartclk = 921600 * 16,
536 .regshift = 2,
537 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
538 .iotype = UPIO_MEM,
540 /* External UARTs */
542 .mapbase = VIPER_UARTA_PHYS,
543 .irq = gpio_to_irq(VIPER_UARTA_GPIO),
544 .uartclk = 1843200,
545 .regshift = 1,
546 .iotype = UPIO_MEM,
547 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
548 UPF_SKIP_TEST,
551 .mapbase = VIPER_UARTB_PHYS,
552 .irq = gpio_to_irq(VIPER_UARTB_GPIO),
553 .uartclk = 1843200,
554 .regshift = 1,
555 .iotype = UPIO_MEM,
556 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
557 UPF_SKIP_TEST,
559 #endif
560 { },
563 static struct platform_device serial_device = {
564 .name = "serial8250",
565 .id = 0,
566 .dev = {
567 .platform_data = serial_platform_data,
569 .num_resources = ARRAY_SIZE(viper_serial_resources),
570 .resource = viper_serial_resources,
573 /* USB */
574 static void isp116x_delay(struct device *dev, int delay)
576 ndelay(delay);
579 static struct resource isp116x_resources[] = {
580 [0] = { /* DATA */
581 .start = VIPER_USB_PHYS + 0,
582 .end = VIPER_USB_PHYS + 1,
583 .flags = IORESOURCE_MEM,
585 [1] = { /* ADDR */
586 .start = VIPER_USB_PHYS + 2,
587 .end = VIPER_USB_PHYS + 3,
588 .flags = IORESOURCE_MEM,
590 [2] = {
591 .start = gpio_to_irq(VIPER_USB_GPIO),
592 .end = gpio_to_irq(VIPER_USB_GPIO),
593 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
597 /* (DataBusWidth16|AnalogOCEnable|DREQOutputPolarity|DownstreamPort15KRSel ) */
598 static struct isp116x_platform_data isp116x_platform_data = {
599 /* Enable internal resistors on downstream ports */
600 .sel15Kres = 1,
601 /* On-chip overcurrent protection */
602 .oc_enable = 1,
603 /* INT output polarity */
604 .int_act_high = 1,
605 /* INT edge or level triggered */
606 .int_edge_triggered = 0,
608 /* WAKEUP pin connected - NOT SUPPORTED */
609 /* .remote_wakeup_connected = 0, */
610 /* Wakeup by devices on usb bus enabled */
611 .remote_wakeup_enable = 0,
612 .delay = isp116x_delay,
615 static struct platform_device isp116x_device = {
616 .name = "isp116x-hcd",
617 .id = -1,
618 .num_resources = ARRAY_SIZE(isp116x_resources),
619 .resource = isp116x_resources,
620 .dev = {
621 .platform_data = &isp116x_platform_data,
626 /* MTD */
627 static struct resource mtd_resources[] = {
628 [0] = { /* RedBoot config + filesystem flash */
629 .start = VIPER_FLASH_PHYS,
630 .end = VIPER_FLASH_PHYS + SZ_32M - 1,
631 .flags = IORESOURCE_MEM,
633 [1] = { /* Boot flash */
634 .start = VIPER_BOOT_PHYS,
635 .end = VIPER_BOOT_PHYS + SZ_1M - 1,
636 .flags = IORESOURCE_MEM,
638 [2] = { /*
639 * SRAM size is actually 256KB, 8bits, with a sparse mapping
640 * (each byte is on a 16bit boundary).
642 .start = _VIPER_SRAM_BASE,
643 .end = _VIPER_SRAM_BASE + SZ_512K - 1,
644 .flags = IORESOURCE_MEM,
648 static struct mtd_partition viper_boot_flash_partition = {
649 .name = "RedBoot",
650 .size = SZ_1M,
651 .offset = 0,
652 .mask_flags = MTD_WRITEABLE, /* force R/O */
655 static struct physmap_flash_data viper_flash_data[] = {
656 [0] = {
657 .width = 2,
658 .parts = NULL,
659 .nr_parts = 0,
661 [1] = {
662 .width = 2,
663 .parts = &viper_boot_flash_partition,
664 .nr_parts = 1,
668 static struct platform_device viper_mtd_devices[] = {
669 [0] = {
670 .name = "physmap-flash",
671 .id = 0,
672 .dev = {
673 .platform_data = &viper_flash_data[0],
675 .resource = &mtd_resources[0],
676 .num_resources = 1,
678 [1] = {
679 .name = "physmap-flash",
680 .id = 1,
681 .dev = {
682 .platform_data = &viper_flash_data[1],
684 .resource = &mtd_resources[1],
685 .num_resources = 1,
689 static struct platform_device *viper_devs[] __initdata = {
690 &smc91x_device,
691 &i2c_bus_device,
692 &serial_device,
693 &isp116x_device,
694 &viper_mtd_devices[0],
695 &viper_mtd_devices[1],
696 &viper_backlight_device,
699 static mfp_cfg_t viper_pin_config[] __initdata = {
700 /* Chip selects */
701 GPIO15_nCS_1,
702 GPIO78_nCS_2,
703 GPIO79_nCS_3,
704 GPIO80_nCS_4,
705 GPIO33_nCS_5,
707 /* FP Backlight */
708 GPIO9_GPIO, /* VIPER_BCKLIGHT_EN_GPIO */
709 GPIO10_GPIO, /* VIPER_LCD_EN_GPIO */
710 GPIO16_PWM0_OUT,
712 /* Ethernet PHY Ready */
713 GPIO18_RDY,
715 /* Serial shutdown */
716 GPIO12_GPIO | MFP_LPM_DRIVE_HIGH, /* VIPER_UART_SHDN_GPIO */
718 /* Compact-Flash / PC104 */
719 GPIO48_nPOE,
720 GPIO49_nPWE,
721 GPIO50_nPIOR,
722 GPIO51_nPIOW,
723 GPIO52_nPCE_1,
724 GPIO53_nPCE_2,
725 GPIO54_nPSKTSEL,
726 GPIO55_nPREG,
727 GPIO56_nPWAIT,
728 GPIO57_nIOIS16,
729 GPIO8_GPIO, /* VIPER_CF_RDY_GPIO */
730 GPIO32_GPIO, /* VIPER_CF_CD_GPIO */
731 GPIO82_GPIO, /* VIPER_CF_POWER_GPIO */
733 /* Integrated UPS control */
734 GPIO20_GPIO, /* VIPER_UPS_GPIO */
736 /* Vcc regulator control */
737 GPIO6_GPIO, /* VIPER_PSU_DATA_GPIO */
738 GPIO11_GPIO, /* VIPER_PSU_CLK_GPIO */
739 GPIO19_GPIO, /* VIPER_PSU_nCS_LD_GPIO */
741 /* i2c busses */
742 GPIO26_GPIO, /* VIPER_TPM_I2C_SDA_GPIO */
743 GPIO27_GPIO, /* VIPER_TPM_I2C_SCL_GPIO */
744 GPIO83_GPIO, /* VIPER_RTC_I2C_SDA_GPIO */
745 GPIO84_GPIO, /* VIPER_RTC_I2C_SCL_GPIO */
747 /* PC/104 Interrupt */
748 GPIO1_GPIO | WAKEUP_ON_EDGE_RISE, /* VIPER_CPLD_GPIO */
751 static unsigned long viper_tpm;
753 static int __init viper_tpm_setup(char *str)
755 strict_strtoul(str, 10, &viper_tpm);
756 return 1;
759 __setup("tpm=", viper_tpm_setup);
761 static void __init viper_tpm_init(void)
763 struct platform_device *tpm_device;
764 struct i2c_gpio_platform_data i2c_tpm_data = {
765 .sda_pin = VIPER_TPM_I2C_SDA_GPIO,
766 .scl_pin = VIPER_TPM_I2C_SCL_GPIO,
767 .udelay = 10,
768 .timeout = 100,
770 char *errstr;
772 /* Allocate TPM i2c bus if requested */
773 if (!viper_tpm)
774 return;
776 tpm_device = platform_device_alloc("i2c-gpio", 2);
777 if (tpm_device) {
778 if (!platform_device_add_data(tpm_device,
779 &i2c_tpm_data,
780 sizeof(i2c_tpm_data))) {
781 if (platform_device_add(tpm_device)) {
782 errstr = "register TPM i2c bus";
783 goto error_free_tpm;
785 } else {
786 errstr = "allocate TPM i2c bus data";
787 goto error_free_tpm;
789 } else {
790 errstr = "allocate TPM i2c device";
791 goto error_tpm;
794 return;
796 error_free_tpm:
797 kfree(tpm_device);
798 error_tpm:
799 pr_err("viper: Couldn't %s, giving up\n", errstr);
802 static void __init viper_init_vcore_gpios(void)
804 if (gpio_request(VIPER_PSU_DATA_GPIO, "PSU data"))
805 goto err_request_data;
807 if (gpio_request(VIPER_PSU_CLK_GPIO, "PSU clock"))
808 goto err_request_clk;
810 if (gpio_request(VIPER_PSU_nCS_LD_GPIO, "PSU cs"))
811 goto err_request_cs;
813 if (gpio_direction_output(VIPER_PSU_DATA_GPIO, 0) ||
814 gpio_direction_output(VIPER_PSU_CLK_GPIO, 0) ||
815 gpio_direction_output(VIPER_PSU_nCS_LD_GPIO, 0))
816 goto err_dir;
818 /* c/should assume redboot set the correct level ??? */
819 viper_set_core_cpu_voltage(get_clk_frequency_khz(0), 1);
821 return;
823 err_dir:
824 gpio_free(VIPER_PSU_nCS_LD_GPIO);
825 err_request_cs:
826 gpio_free(VIPER_PSU_CLK_GPIO);
827 err_request_clk:
828 gpio_free(VIPER_PSU_DATA_GPIO);
829 err_request_data:
830 pr_err("viper: Failed to setup vcore control GPIOs\n");
833 static void __init viper_init_serial_gpio(void)
835 if (gpio_request(VIPER_UART_SHDN_GPIO, "UARTs shutdown"))
836 goto err_request;
838 if (gpio_direction_output(VIPER_UART_SHDN_GPIO, 0))
839 goto err_dir;
841 return;
843 err_dir:
844 gpio_free(VIPER_UART_SHDN_GPIO);
845 err_request:
846 pr_err("viper: Failed to setup UART shutdown GPIO\n");
849 #ifdef CONFIG_CPU_FREQ
850 static int viper_cpufreq_notifier(struct notifier_block *nb,
851 unsigned long val, void *data)
853 struct cpufreq_freqs *freq = data;
855 /* TODO: Adjust timings??? */
857 switch (val) {
858 case CPUFREQ_PRECHANGE:
859 if (freq->old < freq->new) {
860 /* we are getting faster so raise the voltage
861 * before we change freq */
862 viper_set_core_cpu_voltage(freq->new, 0);
864 break;
865 case CPUFREQ_POSTCHANGE:
866 if (freq->old > freq->new) {
867 /* we are slowing down so drop the power
868 * after we change freq */
869 viper_set_core_cpu_voltage(freq->new, 0);
871 break;
872 case CPUFREQ_RESUMECHANGE:
873 viper_set_core_cpu_voltage(freq->new, 0);
874 break;
875 default:
876 /* ignore */
877 break;
880 return 0;
883 static struct notifier_block viper_cpufreq_notifier_block = {
884 .notifier_call = viper_cpufreq_notifier
887 static void __init viper_init_cpufreq(void)
889 if (cpufreq_register_notifier(&viper_cpufreq_notifier_block,
890 CPUFREQ_TRANSITION_NOTIFIER))
891 pr_err("viper: Failed to setup cpufreq notifier\n");
893 #else
894 static inline void viper_init_cpufreq(void) {}
895 #endif
897 static void viper_power_off(void)
899 pr_notice("Shutting off UPS\n");
900 gpio_set_value(VIPER_UPS_GPIO, 1);
901 /* Spin to death... */
902 while (1);
905 static void __init viper_init(void)
907 u8 version;
909 pm_power_off = viper_power_off;
911 pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));
913 /* Wake-up serial console */
914 viper_init_serial_gpio();
916 set_pxa_fb_info(&fb_info);
918 /* v1 hardware cannot use the datacs line */
919 version = viper_hw_version();
920 if (version == 0)
921 smc91x_device.num_resources--;
923 pxa_set_i2c_info(NULL);
924 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));
926 viper_init_vcore_gpios();
927 viper_init_cpufreq();
929 sysdev_driver_register(&cpu_sysdev_class, &viper_cpu_sysdev_driver);
931 if (version) {
932 pr_info("viper: hardware v%di%d detected. "
933 "CPLD revision %d.\n",
934 VIPER_BOARD_VERSION(version),
935 VIPER_BOARD_ISSUE(version),
936 VIPER_CPLD_REVISION(version));
937 system_rev = (VIPER_BOARD_VERSION(version) << 8) |
938 (VIPER_BOARD_ISSUE(version) << 4) |
939 VIPER_CPLD_REVISION(version);
940 } else {
941 pr_info("viper: No version register.\n");
944 i2c_register_board_info(1, ARRAY_AND_SIZE(viper_i2c_devices));
946 viper_tpm_init();
947 pxa_set_ac97_info(NULL);
950 static struct map_desc viper_io_desc[] __initdata = {
952 .virtual = VIPER_CPLD_BASE,
953 .pfn = __phys_to_pfn(VIPER_CPLD_PHYS),
954 .length = 0x00300000,
955 .type = MT_DEVICE,
958 .virtual = VIPER_PC104IO_BASE,
959 .pfn = __phys_to_pfn(_PCMCIA1IO),
960 .length = 0x00800000,
961 .type = MT_DEVICE,
965 static void __init viper_map_io(void)
967 pxa_map_io();
969 iotable_init(viper_io_desc, ARRAY_SIZE(viper_io_desc));
971 PCFR |= PCFR_OPDE;
974 MACHINE_START(VIPER, "Arcom/Eurotech VIPER SBC")
975 /* Maintainer: Marc Zyngier <maz@misterjones.org> */
976 .phys_io = 0x40000000,
977 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
978 .boot_params = 0xa0000100,
979 .map_io = viper_map_io,
980 .init_irq = viper_init_irq,
981 .timer = &pxa_timer,
982 .init_machine = viper_init,
983 MACHINE_END