OMAP3: PM: Ensure MUSB block can idle when driver not loaded
[linux-ginger.git] / arch / arm / mach-pxa / viper.c
blobdd031cc418478301458edbafa01fd93f0abde4c5
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/pxa25x.h>
46 #include <mach/audio.h>
47 #include <mach/pxafb.h>
48 #include <mach/i2c.h>
49 #include <mach/regs-uart.h>
50 #include <mach/viper.h>
52 #include <asm/setup.h>
53 #include <asm/mach-types.h>
54 #include <asm/irq.h>
55 #include <asm/sizes.h>
57 #include <asm/mach/arch.h>
58 #include <asm/mach/map.h>
59 #include <asm/mach/irq.h>
61 #include "generic.h"
62 #include "devices.h"
64 static unsigned int icr;
66 static void viper_icr_set_bit(unsigned int bit)
68 icr |= bit;
69 VIPER_ICR = icr;
72 static void viper_icr_clear_bit(unsigned int bit)
74 icr &= ~bit;
75 VIPER_ICR = icr;
78 /* This function is used from the pcmcia module to reset the CF */
79 void viper_cf_rst(int state)
81 if (state)
82 viper_icr_set_bit(VIPER_ICR_CF_RST);
83 else
84 viper_icr_clear_bit(VIPER_ICR_CF_RST);
86 EXPORT_SYMBOL(viper_cf_rst);
89 * The CPLD version register was not present on VIPER boards prior to
90 * v2i1. On v1 boards where the version register is not present we
91 * will just read back the previous value from the databus.
93 * Therefore we do two reads. The first time we write 0 to the
94 * (read-only) register before reading and the second time we write
95 * 0xff first. If the two reads do not match or they read back as 0xff
96 * or 0x00 then we have version 1 hardware.
98 static u8 viper_hw_version(void)
100 u8 v1, v2;
101 unsigned long flags;
103 local_irq_save(flags);
105 VIPER_VERSION = 0;
106 v1 = VIPER_VERSION;
107 VIPER_VERSION = 0xff;
108 v2 = VIPER_VERSION;
110 v1 = (v1 != v2 || v1 == 0xff) ? 0 : v1;
112 local_irq_restore(flags);
113 return v1;
116 /* CPU sysdev */
117 static int viper_cpu_suspend(struct sys_device *sysdev, pm_message_t state)
119 viper_icr_set_bit(VIPER_ICR_R_DIS);
120 return 0;
123 static int viper_cpu_resume(struct sys_device *sysdev)
125 viper_icr_clear_bit(VIPER_ICR_R_DIS);
126 return 0;
129 static struct sysdev_driver viper_cpu_sysdev_driver = {
130 .suspend = viper_cpu_suspend,
131 .resume = viper_cpu_resume,
134 static unsigned int current_voltage_divisor;
137 * If force is not true then step from existing to new divisor. If
138 * force is true then jump straight to the new divisor. Stepping is
139 * used because if the jump in voltage is too large, the VCC can dip
140 * too low and the regulator cuts out.
142 * force can be used to initialize the divisor to a know state by
143 * setting the value for the current clock speed, since we are already
144 * running at that speed we know the voltage should be pretty close so
145 * the jump won't be too large
147 static void viper_set_core_cpu_voltage(unsigned long khz, int force)
149 int i = 0;
150 unsigned int divisor = 0;
151 const char *v;
153 if (khz < 200000) {
154 v = "1.0"; divisor = 0xfff;
155 } else if (khz < 300000) {
156 v = "1.1"; divisor = 0xde5;
157 } else {
158 v = "1.3"; divisor = 0x325;
161 pr_debug("viper: setting CPU core voltage to %sV at %d.%03dMHz\n",
162 v, (int)khz / 1000, (int)khz % 1000);
164 #define STEP 0x100
165 do {
166 int step;
168 if (force)
169 step = divisor;
170 else if (current_voltage_divisor < divisor - STEP)
171 step = current_voltage_divisor + STEP;
172 else if (current_voltage_divisor > divisor + STEP)
173 step = current_voltage_divisor - STEP;
174 else
175 step = divisor;
176 force = 0;
178 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
179 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
181 for (i = 1 << 11 ; i > 0 ; i >>= 1) {
182 udelay(1);
184 gpio_set_value(VIPER_PSU_DATA_GPIO, step & i);
185 udelay(1);
187 gpio_set_value(VIPER_PSU_CLK_GPIO, 1);
188 udelay(1);
190 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
192 udelay(1);
194 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 1);
195 udelay(1);
197 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
199 current_voltage_divisor = step;
200 } while (current_voltage_divisor != divisor);
203 /* Interrupt handling */
204 static unsigned long viper_irq_enabled_mask;
205 static const int viper_isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, 9, 14, 15 };
206 static const int viper_isa_irq_map[] = {
207 0, /* ISA irq #0, invalid */
208 0, /* ISA irq #1, invalid */
209 0, /* ISA irq #2, invalid */
210 1 << 0, /* ISA irq #3 */
211 1 << 1, /* ISA irq #4 */
212 1 << 2, /* ISA irq #5 */
213 1 << 3, /* ISA irq #6 */
214 1 << 4, /* ISA irq #7 */
215 0, /* ISA irq #8, invalid */
216 1 << 8, /* ISA irq #9 */
217 1 << 5, /* ISA irq #10 */
218 1 << 6, /* ISA irq #11 */
219 1 << 7, /* ISA irq #12 */
220 0, /* ISA irq #13, invalid */
221 1 << 9, /* ISA irq #14 */
222 1 << 10, /* ISA irq #15 */
225 static inline int viper_irq_to_bitmask(unsigned int irq)
227 return viper_isa_irq_map[irq - PXA_ISA_IRQ(0)];
230 static inline int viper_bit_to_irq(int bit)
232 return viper_isa_irqs[bit] + PXA_ISA_IRQ(0);
235 static void viper_ack_irq(unsigned int irq)
237 int viper_irq = viper_irq_to_bitmask(irq);
239 if (viper_irq & 0xff)
240 VIPER_LO_IRQ_STATUS = viper_irq;
241 else
242 VIPER_HI_IRQ_STATUS = (viper_irq >> 8);
245 static void viper_mask_irq(unsigned int irq)
247 viper_irq_enabled_mask &= ~(viper_irq_to_bitmask(irq));
250 static void viper_unmask_irq(unsigned int irq)
252 viper_irq_enabled_mask |= viper_irq_to_bitmask(irq);
255 static inline unsigned long viper_irq_pending(void)
257 return (VIPER_HI_IRQ_STATUS << 8 | VIPER_LO_IRQ_STATUS) &
258 viper_irq_enabled_mask;
261 static void viper_irq_handler(unsigned int irq, struct irq_desc *desc)
263 unsigned long pending;
265 pending = viper_irq_pending();
266 do {
267 /* we're in a chained irq handler,
268 * so ack the interrupt by hand */
269 GEDR(VIPER_CPLD_GPIO) = GPIO_bit(VIPER_CPLD_GPIO);
271 if (likely(pending)) {
272 irq = viper_bit_to_irq(__ffs(pending));
273 generic_handle_irq(irq);
275 pending = viper_irq_pending();
276 } while (pending);
279 static struct irq_chip viper_irq_chip = {
280 .name = "ISA",
281 .ack = viper_ack_irq,
282 .mask = viper_mask_irq,
283 .unmask = viper_unmask_irq
286 static void __init viper_init_irq(void)
288 int level;
289 int isa_irq;
291 pxa25x_init_irq();
293 /* setup ISA IRQs */
294 for (level = 0; level < ARRAY_SIZE(viper_isa_irqs); level++) {
295 isa_irq = viper_bit_to_irq(level);
296 set_irq_chip(isa_irq, &viper_irq_chip);
297 set_irq_handler(isa_irq, handle_edge_irq);
298 set_irq_flags(isa_irq, IRQF_VALID | IRQF_PROBE);
301 set_irq_chained_handler(gpio_to_irq(VIPER_CPLD_GPIO),
302 viper_irq_handler);
303 set_irq_type(gpio_to_irq(VIPER_CPLD_GPIO), IRQ_TYPE_EDGE_BOTH);
305 #ifndef CONFIG_SERIAL_PXA
307 * 8250 doesn't support IRQ_TYPE being passed as part
308 * of the plat_serial8250_port structure...
310 set_irq_type(gpio_to_irq(VIPER_UARTA_GPIO), IRQ_TYPE_EDGE_RISING);
311 set_irq_type(gpio_to_irq(VIPER_UARTB_GPIO), IRQ_TYPE_EDGE_RISING);
312 #endif
315 /* Flat Panel */
316 static struct pxafb_mode_info fb_mode_info[] = {
318 .pixclock = 157500,
320 .xres = 320,
321 .yres = 240,
323 .bpp = 16,
325 .hsync_len = 63,
326 .left_margin = 7,
327 .right_margin = 13,
329 .vsync_len = 20,
330 .upper_margin = 0,
331 .lower_margin = 0,
333 .sync = 0,
337 static struct pxafb_mach_info fb_info = {
338 .modes = fb_mode_info,
339 .num_modes = 1,
340 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
343 static int viper_backlight_init(struct device *dev)
345 int ret;
347 /* GPIO9 and 10 control FB backlight. Initialise to off */
348 ret = gpio_request(VIPER_BCKLIGHT_EN_GPIO, "Backlight");
349 if (ret)
350 goto err_request_bckl;
352 ret = gpio_request(VIPER_LCD_EN_GPIO, "LCD");
353 if (ret)
354 goto err_request_lcd;
356 ret = gpio_direction_output(VIPER_BCKLIGHT_EN_GPIO, 0);
357 if (ret)
358 goto err_dir;
360 ret = gpio_direction_output(VIPER_LCD_EN_GPIO, 0);
361 if (ret)
362 goto err_dir;
364 return 0;
366 err_dir:
367 gpio_free(VIPER_LCD_EN_GPIO);
368 err_request_lcd:
369 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
370 err_request_bckl:
371 dev_err(dev, "Failed to setup LCD GPIOs\n");
373 return ret;
376 static int viper_backlight_notify(int brightness)
378 gpio_set_value(VIPER_LCD_EN_GPIO, !!brightness);
379 gpio_set_value(VIPER_BCKLIGHT_EN_GPIO, !!brightness);
381 return brightness;
384 static void viper_backlight_exit(struct device *dev)
386 gpio_free(VIPER_LCD_EN_GPIO);
387 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
390 static struct platform_pwm_backlight_data viper_backlight_data = {
391 .pwm_id = 0,
392 .max_brightness = 100,
393 .dft_brightness = 100,
394 .pwm_period_ns = 1000000,
395 .init = viper_backlight_init,
396 .notify = viper_backlight_notify,
397 .exit = viper_backlight_exit,
400 static struct platform_device viper_backlight_device = {
401 .name = "pwm-backlight",
402 .dev = {
403 .parent = &pxa25x_device_pwm0.dev,
404 .platform_data = &viper_backlight_data,
408 /* Ethernet */
409 static struct resource smc91x_resources[] = {
410 [0] = {
411 .name = "smc91x-regs",
412 .start = VIPER_ETH_PHYS + 0x300,
413 .end = VIPER_ETH_PHYS + 0x30f,
414 .flags = IORESOURCE_MEM,
416 [1] = {
417 .start = gpio_to_irq(VIPER_ETH_GPIO),
418 .end = gpio_to_irq(VIPER_ETH_GPIO),
419 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
421 [2] = {
422 .name = "smc91x-data32",
423 .start = VIPER_ETH_DATA_PHYS,
424 .end = VIPER_ETH_DATA_PHYS + 3,
425 .flags = IORESOURCE_MEM,
429 static struct smc91x_platdata viper_smc91x_info = {
430 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
431 .leda = RPC_LED_100_10,
432 .ledb = RPC_LED_TX_RX,
435 static struct platform_device smc91x_device = {
436 .name = "smc91x",
437 .id = -1,
438 .num_resources = ARRAY_SIZE(smc91x_resources),
439 .resource = smc91x_resources,
440 .dev = {
441 .platform_data = &viper_smc91x_info,
445 /* i2c */
446 static struct i2c_gpio_platform_data i2c_bus_data = {
447 .sda_pin = VIPER_RTC_I2C_SDA_GPIO,
448 .scl_pin = VIPER_RTC_I2C_SCL_GPIO,
449 .udelay = 10,
450 .timeout = 100,
453 static struct platform_device i2c_bus_device = {
454 .name = "i2c-gpio",
455 .id = 1, /* pxa2xx-i2c is bus 0, so start at 1 */
456 .dev = {
457 .platform_data = &i2c_bus_data,
461 static struct i2c_board_info __initdata viper_i2c_devices[] = {
463 I2C_BOARD_INFO("ds1338", 0x68),
468 * Serial configuration:
469 * You can either have the standard PXA ports driven by the PXA driver,
470 * or all the ports (PXA + 16850) driven by the 8250 driver.
471 * Choose your poison.
474 static struct resource viper_serial_resources[] = {
475 #ifndef CONFIG_SERIAL_PXA
477 .start = 0x40100000,
478 .end = 0x4010001f,
479 .flags = IORESOURCE_MEM,
482 .start = 0x40200000,
483 .end = 0x4020001f,
484 .flags = IORESOURCE_MEM,
487 .start = 0x40700000,
488 .end = 0x4070001f,
489 .flags = IORESOURCE_MEM,
492 .start = VIPER_UARTA_PHYS,
493 .end = VIPER_UARTA_PHYS + 0xf,
494 .flags = IORESOURCE_MEM,
497 .start = VIPER_UARTB_PHYS,
498 .end = VIPER_UARTB_PHYS + 0xf,
499 .flags = IORESOURCE_MEM,
501 #else
505 #endif
508 static struct plat_serial8250_port serial_platform_data[] = {
509 #ifndef CONFIG_SERIAL_PXA
510 /* Internal UARTs */
512 .membase = (void *)&FFUART,
513 .mapbase = __PREG(FFUART),
514 .irq = IRQ_FFUART,
515 .uartclk = 921600 * 16,
516 .regshift = 2,
517 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
518 .iotype = UPIO_MEM,
521 .membase = (void *)&BTUART,
522 .mapbase = __PREG(BTUART),
523 .irq = IRQ_BTUART,
524 .uartclk = 921600 * 16,
525 .regshift = 2,
526 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
527 .iotype = UPIO_MEM,
530 .membase = (void *)&STUART,
531 .mapbase = __PREG(STUART),
532 .irq = IRQ_STUART,
533 .uartclk = 921600 * 16,
534 .regshift = 2,
535 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
536 .iotype = UPIO_MEM,
538 /* External UARTs */
540 .mapbase = VIPER_UARTA_PHYS,
541 .irq = gpio_to_irq(VIPER_UARTA_GPIO),
542 .uartclk = 1843200,
543 .regshift = 1,
544 .iotype = UPIO_MEM,
545 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
546 UPF_SKIP_TEST,
549 .mapbase = VIPER_UARTB_PHYS,
550 .irq = gpio_to_irq(VIPER_UARTB_GPIO),
551 .uartclk = 1843200,
552 .regshift = 1,
553 .iotype = UPIO_MEM,
554 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
555 UPF_SKIP_TEST,
557 #endif
558 { },
561 static struct platform_device serial_device = {
562 .name = "serial8250",
563 .id = 0,
564 .dev = {
565 .platform_data = serial_platform_data,
567 .num_resources = ARRAY_SIZE(viper_serial_resources),
568 .resource = viper_serial_resources,
571 /* USB */
572 static void isp116x_delay(struct device *dev, int delay)
574 ndelay(delay);
577 static struct resource isp116x_resources[] = {
578 [0] = { /* DATA */
579 .start = VIPER_USB_PHYS + 0,
580 .end = VIPER_USB_PHYS + 1,
581 .flags = IORESOURCE_MEM,
583 [1] = { /* ADDR */
584 .start = VIPER_USB_PHYS + 2,
585 .end = VIPER_USB_PHYS + 3,
586 .flags = IORESOURCE_MEM,
588 [2] = {
589 .start = gpio_to_irq(VIPER_USB_GPIO),
590 .end = gpio_to_irq(VIPER_USB_GPIO),
591 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
595 /* (DataBusWidth16|AnalogOCEnable|DREQOutputPolarity|DownstreamPort15KRSel ) */
596 static struct isp116x_platform_data isp116x_platform_data = {
597 /* Enable internal resistors on downstream ports */
598 .sel15Kres = 1,
599 /* On-chip overcurrent protection */
600 .oc_enable = 1,
601 /* INT output polarity */
602 .int_act_high = 1,
603 /* INT edge or level triggered */
604 .int_edge_triggered = 0,
606 /* WAKEUP pin connected - NOT SUPPORTED */
607 /* .remote_wakeup_connected = 0, */
608 /* Wakeup by devices on usb bus enabled */
609 .remote_wakeup_enable = 0,
610 .delay = isp116x_delay,
613 static struct platform_device isp116x_device = {
614 .name = "isp116x-hcd",
615 .id = -1,
616 .num_resources = ARRAY_SIZE(isp116x_resources),
617 .resource = isp116x_resources,
618 .dev = {
619 .platform_data = &isp116x_platform_data,
624 /* MTD */
625 static struct resource mtd_resources[] = {
626 [0] = { /* RedBoot config + filesystem flash */
627 .start = VIPER_FLASH_PHYS,
628 .end = VIPER_FLASH_PHYS + SZ_32M - 1,
629 .flags = IORESOURCE_MEM,
631 [1] = { /* Boot flash */
632 .start = VIPER_BOOT_PHYS,
633 .end = VIPER_BOOT_PHYS + SZ_1M - 1,
634 .flags = IORESOURCE_MEM,
636 [2] = { /*
637 * SRAM size is actually 256KB, 8bits, with a sparse mapping
638 * (each byte is on a 16bit boundary).
640 .start = _VIPER_SRAM_BASE,
641 .end = _VIPER_SRAM_BASE + SZ_512K - 1,
642 .flags = IORESOURCE_MEM,
646 static struct mtd_partition viper_boot_flash_partition = {
647 .name = "RedBoot",
648 .size = SZ_1M,
649 .offset = 0,
650 .mask_flags = MTD_WRITEABLE, /* force R/O */
653 static struct physmap_flash_data viper_flash_data[] = {
654 [0] = {
655 .width = 2,
656 .parts = NULL,
657 .nr_parts = 0,
659 [1] = {
660 .width = 2,
661 .parts = &viper_boot_flash_partition,
662 .nr_parts = 1,
666 static struct platform_device viper_mtd_devices[] = {
667 [0] = {
668 .name = "physmap-flash",
669 .id = 0,
670 .dev = {
671 .platform_data = &viper_flash_data[0],
673 .resource = &mtd_resources[0],
674 .num_resources = 1,
676 [1] = {
677 .name = "physmap-flash",
678 .id = 1,
679 .dev = {
680 .platform_data = &viper_flash_data[1],
682 .resource = &mtd_resources[1],
683 .num_resources = 1,
687 static struct platform_device *viper_devs[] __initdata = {
688 &smc91x_device,
689 &i2c_bus_device,
690 &serial_device,
691 &isp116x_device,
692 &viper_mtd_devices[0],
693 &viper_mtd_devices[1],
694 &viper_backlight_device,
697 static mfp_cfg_t viper_pin_config[] __initdata = {
698 /* Chip selects */
699 GPIO15_nCS_1,
700 GPIO78_nCS_2,
701 GPIO79_nCS_3,
702 GPIO80_nCS_4,
703 GPIO33_nCS_5,
705 /* FP Backlight */
706 GPIO9_GPIO, /* VIPER_BCKLIGHT_EN_GPIO */
707 GPIO10_GPIO, /* VIPER_LCD_EN_GPIO */
708 GPIO16_PWM0_OUT,
710 /* Ethernet PHY Ready */
711 GPIO18_RDY,
713 /* Serial shutdown */
714 GPIO12_GPIO | MFP_LPM_DRIVE_HIGH, /* VIPER_UART_SHDN_GPIO */
716 /* Compact-Flash / PC104 */
717 GPIO48_nPOE,
718 GPIO49_nPWE,
719 GPIO50_nPIOR,
720 GPIO51_nPIOW,
721 GPIO52_nPCE_1,
722 GPIO53_nPCE_2,
723 GPIO54_nPSKTSEL,
724 GPIO55_nPREG,
725 GPIO56_nPWAIT,
726 GPIO57_nIOIS16,
727 GPIO8_GPIO, /* VIPER_CF_RDY_GPIO */
728 GPIO32_GPIO, /* VIPER_CF_CD_GPIO */
729 GPIO82_GPIO, /* VIPER_CF_POWER_GPIO */
731 /* Integrated UPS control */
732 GPIO20_GPIO, /* VIPER_UPS_GPIO */
734 /* Vcc regulator control */
735 GPIO6_GPIO, /* VIPER_PSU_DATA_GPIO */
736 GPIO11_GPIO, /* VIPER_PSU_CLK_GPIO */
737 GPIO19_GPIO, /* VIPER_PSU_nCS_LD_GPIO */
739 /* i2c busses */
740 GPIO26_GPIO, /* VIPER_TPM_I2C_SDA_GPIO */
741 GPIO27_GPIO, /* VIPER_TPM_I2C_SCL_GPIO */
742 GPIO83_GPIO, /* VIPER_RTC_I2C_SDA_GPIO */
743 GPIO84_GPIO, /* VIPER_RTC_I2C_SCL_GPIO */
745 /* PC/104 Interrupt */
746 GPIO1_GPIO | WAKEUP_ON_EDGE_RISE, /* VIPER_CPLD_GPIO */
749 static unsigned long viper_tpm;
751 static int __init viper_tpm_setup(char *str)
753 strict_strtoul(str, 10, &viper_tpm);
754 return 1;
757 __setup("tpm=", viper_tpm_setup);
759 static void __init viper_tpm_init(void)
761 struct platform_device *tpm_device;
762 struct i2c_gpio_platform_data i2c_tpm_data = {
763 .sda_pin = VIPER_TPM_I2C_SDA_GPIO,
764 .scl_pin = VIPER_TPM_I2C_SCL_GPIO,
765 .udelay = 10,
766 .timeout = 100,
768 char *errstr;
770 /* Allocate TPM i2c bus if requested */
771 if (!viper_tpm)
772 return;
774 tpm_device = platform_device_alloc("i2c-gpio", 2);
775 if (tpm_device) {
776 if (!platform_device_add_data(tpm_device,
777 &i2c_tpm_data,
778 sizeof(i2c_tpm_data))) {
779 if (platform_device_add(tpm_device)) {
780 errstr = "register TPM i2c bus";
781 goto error_free_tpm;
783 } else {
784 errstr = "allocate TPM i2c bus data";
785 goto error_free_tpm;
787 } else {
788 errstr = "allocate TPM i2c device";
789 goto error_tpm;
792 return;
794 error_free_tpm:
795 kfree(tpm_device);
796 error_tpm:
797 pr_err("viper: Couldn't %s, giving up\n", errstr);
800 static void __init viper_init_vcore_gpios(void)
802 if (gpio_request(VIPER_PSU_DATA_GPIO, "PSU data"))
803 goto err_request_data;
805 if (gpio_request(VIPER_PSU_CLK_GPIO, "PSU clock"))
806 goto err_request_clk;
808 if (gpio_request(VIPER_PSU_nCS_LD_GPIO, "PSU cs"))
809 goto err_request_cs;
811 if (gpio_direction_output(VIPER_PSU_DATA_GPIO, 0) ||
812 gpio_direction_output(VIPER_PSU_CLK_GPIO, 0) ||
813 gpio_direction_output(VIPER_PSU_nCS_LD_GPIO, 0))
814 goto err_dir;
816 /* c/should assume redboot set the correct level ??? */
817 viper_set_core_cpu_voltage(get_clk_frequency_khz(0), 1);
819 return;
821 err_dir:
822 gpio_free(VIPER_PSU_nCS_LD_GPIO);
823 err_request_cs:
824 gpio_free(VIPER_PSU_CLK_GPIO);
825 err_request_clk:
826 gpio_free(VIPER_PSU_DATA_GPIO);
827 err_request_data:
828 pr_err("viper: Failed to setup vcore control GPIOs\n");
831 static void __init viper_init_serial_gpio(void)
833 if (gpio_request(VIPER_UART_SHDN_GPIO, "UARTs shutdown"))
834 goto err_request;
836 if (gpio_direction_output(VIPER_UART_SHDN_GPIO, 0))
837 goto err_dir;
839 return;
841 err_dir:
842 gpio_free(VIPER_UART_SHDN_GPIO);
843 err_request:
844 pr_err("viper: Failed to setup UART shutdown GPIO\n");
847 #ifdef CONFIG_CPU_FREQ
848 static int viper_cpufreq_notifier(struct notifier_block *nb,
849 unsigned long val, void *data)
851 struct cpufreq_freqs *freq = data;
853 /* TODO: Adjust timings??? */
855 switch (val) {
856 case CPUFREQ_PRECHANGE:
857 if (freq->old < freq->new) {
858 /* we are getting faster so raise the voltage
859 * before we change freq */
860 viper_set_core_cpu_voltage(freq->new, 0);
862 break;
863 case CPUFREQ_POSTCHANGE:
864 if (freq->old > freq->new) {
865 /* we are slowing down so drop the power
866 * after we change freq */
867 viper_set_core_cpu_voltage(freq->new, 0);
869 break;
870 case CPUFREQ_RESUMECHANGE:
871 viper_set_core_cpu_voltage(freq->new, 0);
872 break;
873 default:
874 /* ignore */
875 break;
878 return 0;
881 static struct notifier_block viper_cpufreq_notifier_block = {
882 .notifier_call = viper_cpufreq_notifier
885 static void __init viper_init_cpufreq(void)
887 if (cpufreq_register_notifier(&viper_cpufreq_notifier_block,
888 CPUFREQ_TRANSITION_NOTIFIER))
889 pr_err("viper: Failed to setup cpufreq notifier\n");
891 #else
892 static inline void viper_init_cpufreq(void) {}
893 #endif
895 static void viper_power_off(void)
897 pr_notice("Shutting off UPS\n");
898 gpio_set_value(VIPER_UPS_GPIO, 1);
899 /* Spin to death... */
900 while (1);
903 static void __init viper_init(void)
905 u8 version;
907 pm_power_off = viper_power_off;
909 pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));
911 /* Wake-up serial console */
912 viper_init_serial_gpio();
914 set_pxa_fb_info(&fb_info);
916 /* v1 hardware cannot use the datacs line */
917 version = viper_hw_version();
918 if (version == 0)
919 smc91x_device.num_resources--;
921 pxa_set_i2c_info(NULL);
922 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));
924 viper_init_vcore_gpios();
925 viper_init_cpufreq();
927 sysdev_driver_register(&cpu_sysdev_class, &viper_cpu_sysdev_driver);
929 if (version) {
930 pr_info("viper: hardware v%di%d detected. "
931 "CPLD revision %d.\n",
932 VIPER_BOARD_VERSION(version),
933 VIPER_BOARD_ISSUE(version),
934 VIPER_CPLD_REVISION(version));
935 system_rev = (VIPER_BOARD_VERSION(version) << 8) |
936 (VIPER_BOARD_ISSUE(version) << 4) |
937 VIPER_CPLD_REVISION(version);
938 } else {
939 pr_info("viper: No version register.\n");
942 i2c_register_board_info(1, ARRAY_AND_SIZE(viper_i2c_devices));
944 viper_tpm_init();
945 pxa_set_ac97_info(NULL);
948 static struct map_desc viper_io_desc[] __initdata = {
950 .virtual = VIPER_CPLD_BASE,
951 .pfn = __phys_to_pfn(VIPER_CPLD_PHYS),
952 .length = 0x00300000,
953 .type = MT_DEVICE,
956 .virtual = VIPER_PC104IO_BASE,
957 .pfn = __phys_to_pfn(0x30000000),
958 .length = 0x00800000,
959 .type = MT_DEVICE,
963 static void __init viper_map_io(void)
965 pxa_map_io();
967 iotable_init(viper_io_desc, ARRAY_SIZE(viper_io_desc));
969 PCFR |= PCFR_OPDE;
972 MACHINE_START(VIPER, "Arcom/Eurotech VIPER SBC")
973 /* Maintainer: Marc Zyngier <maz@misterjones.org> */
974 .phys_io = 0x40000000,
975 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
976 .boot_params = 0xa0000100,
977 .map_io = viper_map_io,
978 .init_irq = viper_init_irq,
979 .timer = &pxa_timer,
980 .init_machine = viper_init,
981 MACHINE_END