0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <linux/types.h>
0021 #include <linux/memory.h>
0022 #include <linux/cpu.h>
0023 #include <linux/cpufreq.h>
0024 #include <linux/delay.h>
0025 #include <linux/fs.h>
0026 #include <linux/init.h>
0027 #include <linux/slab.h>
0028 #include <linux/interrupt.h>
0029 #include <linux/major.h>
0030 #include <linux/module.h>
0031 #include <linux/pm.h>
0032 #include <linux/sched.h>
0033 #include <linux/gpio.h>
0034 #include <linux/jiffies.h>
0035 #include <linux/platform_data/i2c-gpio.h>
0036 #include <linux/gpio/machine.h>
0037 #include <linux/platform_data/i2c-pxa.h>
0038 #include <linux/serial_8250.h>
0039 #include <linux/smc91x.h>
0040 #include <linux/pwm.h>
0041 #include <linux/pwm_backlight.h>
0042 #include <linux/usb/isp116x.h>
0043 #include <linux/mtd/mtd.h>
0044 #include <linux/mtd/partitions.h>
0045 #include <linux/mtd/physmap.h>
0046 #include <linux/syscore_ops.h>
0047
0048 #include "pxa25x.h"
0049 #include <linux/platform_data/asoc-pxa.h>
0050 #include <linux/platform_data/video-pxafb.h>
0051 #include "regs-uart.h"
0052 #include "viper-pcmcia.h"
0053 #include "viper.h"
0054
0055 #include <asm/setup.h>
0056 #include <asm/mach-types.h>
0057 #include <asm/irq.h>
0058 #include <linux/sizes.h>
0059 #include <asm/system_info.h>
0060
0061 #include <asm/mach/arch.h>
0062 #include <asm/mach/map.h>
0063 #include <asm/mach/irq.h>
0064
0065 #include "generic.h"
0066 #include "devices.h"
0067
0068 static unsigned int icr;
0069
0070 static void viper_icr_set_bit(unsigned int bit)
0071 {
0072 icr |= bit;
0073 VIPER_ICR = icr;
0074 }
0075
0076 static void viper_icr_clear_bit(unsigned int bit)
0077 {
0078 icr &= ~bit;
0079 VIPER_ICR = icr;
0080 }
0081
0082
0083 static void viper_cf_reset(int state)
0084 {
0085 if (state)
0086 viper_icr_set_bit(VIPER_ICR_CF_RST);
0087 else
0088 viper_icr_clear_bit(VIPER_ICR_CF_RST);
0089 }
0090
0091 static struct arcom_pcmcia_pdata viper_pcmcia_info = {
0092 .cd_gpio = VIPER_CF_CD_GPIO,
0093 .rdy_gpio = VIPER_CF_RDY_GPIO,
0094 .pwr_gpio = VIPER_CF_POWER_GPIO,
0095 .reset = viper_cf_reset,
0096 };
0097
0098 static struct platform_device viper_pcmcia_device = {
0099 .name = "viper-pcmcia",
0100 .id = -1,
0101 .dev = {
0102 .platform_data = &viper_pcmcia_info,
0103 },
0104 };
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 static u8 viper_hw_version(void)
0117 {
0118 u8 v1, v2;
0119 unsigned long flags;
0120
0121 local_irq_save(flags);
0122
0123 VIPER_VERSION = 0;
0124 v1 = VIPER_VERSION;
0125 VIPER_VERSION = 0xff;
0126 v2 = VIPER_VERSION;
0127
0128 v1 = (v1 != v2 || v1 == 0xff) ? 0 : v1;
0129
0130 local_irq_restore(flags);
0131 return v1;
0132 }
0133
0134
0135 static int viper_cpu_suspend(void)
0136 {
0137 viper_icr_set_bit(VIPER_ICR_R_DIS);
0138 return 0;
0139 }
0140
0141 static void viper_cpu_resume(void)
0142 {
0143 viper_icr_clear_bit(VIPER_ICR_R_DIS);
0144 }
0145
0146 static struct syscore_ops viper_cpu_syscore_ops = {
0147 .suspend = viper_cpu_suspend,
0148 .resume = viper_cpu_resume,
0149 };
0150
0151 static unsigned int current_voltage_divisor;
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164 static void viper_set_core_cpu_voltage(unsigned long khz, int force)
0165 {
0166 int i = 0;
0167 unsigned int divisor = 0;
0168 const char *v;
0169
0170 if (khz < 200000) {
0171 v = "1.0"; divisor = 0xfff;
0172 } else if (khz < 300000) {
0173 v = "1.1"; divisor = 0xde5;
0174 } else {
0175 v = "1.3"; divisor = 0x325;
0176 }
0177
0178 pr_debug("viper: setting CPU core voltage to %sV at %d.%03dMHz\n",
0179 v, (int)khz / 1000, (int)khz % 1000);
0180
0181 #define STEP 0x100
0182 do {
0183 int step;
0184
0185 if (force)
0186 step = divisor;
0187 else if (current_voltage_divisor < divisor - STEP)
0188 step = current_voltage_divisor + STEP;
0189 else if (current_voltage_divisor > divisor + STEP)
0190 step = current_voltage_divisor - STEP;
0191 else
0192 step = divisor;
0193 force = 0;
0194
0195 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
0196 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
0197
0198 for (i = 1 << 11 ; i > 0 ; i >>= 1) {
0199 udelay(1);
0200
0201 gpio_set_value(VIPER_PSU_DATA_GPIO, step & i);
0202 udelay(1);
0203
0204 gpio_set_value(VIPER_PSU_CLK_GPIO, 1);
0205 udelay(1);
0206
0207 gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
0208 }
0209 udelay(1);
0210
0211 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 1);
0212 udelay(1);
0213
0214 gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
0215
0216 current_voltage_divisor = step;
0217 } while (current_voltage_divisor != divisor);
0218 }
0219
0220
0221 static unsigned long viper_irq_enabled_mask;
0222 static const int viper_isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, 9, 14, 15 };
0223 static const int viper_isa_irq_map[] = {
0224 0,
0225 0,
0226 0,
0227 1 << 0,
0228 1 << 1,
0229 1 << 2,
0230 1 << 3,
0231 1 << 4,
0232 0,
0233 1 << 8,
0234 1 << 5,
0235 1 << 6,
0236 1 << 7,
0237 0,
0238 1 << 9,
0239 1 << 10,
0240 };
0241
0242 static inline int viper_irq_to_bitmask(unsigned int irq)
0243 {
0244 return viper_isa_irq_map[irq - PXA_ISA_IRQ(0)];
0245 }
0246
0247 static inline int viper_bit_to_irq(int bit)
0248 {
0249 return viper_isa_irqs[bit] + PXA_ISA_IRQ(0);
0250 }
0251
0252 static void viper_ack_irq(struct irq_data *d)
0253 {
0254 int viper_irq = viper_irq_to_bitmask(d->irq);
0255
0256 if (viper_irq & 0xff)
0257 VIPER_LO_IRQ_STATUS = viper_irq;
0258 else
0259 VIPER_HI_IRQ_STATUS = (viper_irq >> 8);
0260 }
0261
0262 static void viper_mask_irq(struct irq_data *d)
0263 {
0264 viper_irq_enabled_mask &= ~(viper_irq_to_bitmask(d->irq));
0265 }
0266
0267 static void viper_unmask_irq(struct irq_data *d)
0268 {
0269 viper_irq_enabled_mask |= viper_irq_to_bitmask(d->irq);
0270 }
0271
0272 static inline unsigned long viper_irq_pending(void)
0273 {
0274 return (VIPER_HI_IRQ_STATUS << 8 | VIPER_LO_IRQ_STATUS) &
0275 viper_irq_enabled_mask;
0276 }
0277
0278 static void viper_irq_handler(struct irq_desc *desc)
0279 {
0280 unsigned int irq;
0281 unsigned long pending;
0282
0283 pending = viper_irq_pending();
0284 do {
0285
0286
0287 desc->irq_data.chip->irq_ack(&desc->irq_data);
0288
0289 if (likely(pending)) {
0290 irq = viper_bit_to_irq(__ffs(pending));
0291 generic_handle_irq(irq);
0292 }
0293 pending = viper_irq_pending();
0294 } while (pending);
0295 }
0296
0297 static struct irq_chip viper_irq_chip = {
0298 .name = "ISA",
0299 .irq_ack = viper_ack_irq,
0300 .irq_mask = viper_mask_irq,
0301 .irq_unmask = viper_unmask_irq
0302 };
0303
0304 static void __init viper_init_irq(void)
0305 {
0306 int level;
0307 int isa_irq;
0308
0309 pxa25x_init_irq();
0310
0311
0312 for (level = 0; level < ARRAY_SIZE(viper_isa_irqs); level++) {
0313 isa_irq = viper_bit_to_irq(level);
0314 irq_set_chip_and_handler(isa_irq, &viper_irq_chip,
0315 handle_edge_irq);
0316 irq_clear_status_flags(isa_irq, IRQ_NOREQUEST | IRQ_NOPROBE);
0317 }
0318
0319 irq_set_chained_handler(gpio_to_irq(VIPER_CPLD_GPIO),
0320 viper_irq_handler);
0321 irq_set_irq_type(gpio_to_irq(VIPER_CPLD_GPIO), IRQ_TYPE_EDGE_BOTH);
0322 }
0323
0324
0325 static struct pxafb_mode_info fb_mode_info[] = {
0326 {
0327 .pixclock = 157500,
0328
0329 .xres = 320,
0330 .yres = 240,
0331
0332 .bpp = 16,
0333
0334 .hsync_len = 63,
0335 .left_margin = 7,
0336 .right_margin = 13,
0337
0338 .vsync_len = 20,
0339 .upper_margin = 0,
0340 .lower_margin = 0,
0341
0342 .sync = 0,
0343 },
0344 };
0345
0346 static struct pxafb_mach_info fb_info = {
0347 .modes = fb_mode_info,
0348 .num_modes = 1,
0349 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
0350 };
0351
0352 static struct pwm_lookup viper_pwm_lookup[] = {
0353 PWM_LOOKUP("pxa25x-pwm.0", 0, "pwm-backlight.0", NULL, 1000000,
0354 PWM_POLARITY_NORMAL),
0355 };
0356
0357 static int viper_backlight_init(struct device *dev)
0358 {
0359 int ret;
0360
0361
0362 ret = gpio_request(VIPER_BCKLIGHT_EN_GPIO, "Backlight");
0363 if (ret)
0364 goto err_request_bckl;
0365
0366 ret = gpio_request(VIPER_LCD_EN_GPIO, "LCD");
0367 if (ret)
0368 goto err_request_lcd;
0369
0370 ret = gpio_direction_output(VIPER_BCKLIGHT_EN_GPIO, 0);
0371 if (ret)
0372 goto err_dir;
0373
0374 ret = gpio_direction_output(VIPER_LCD_EN_GPIO, 0);
0375 if (ret)
0376 goto err_dir;
0377
0378 return 0;
0379
0380 err_dir:
0381 gpio_free(VIPER_LCD_EN_GPIO);
0382 err_request_lcd:
0383 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
0384 err_request_bckl:
0385 dev_err(dev, "Failed to setup LCD GPIOs\n");
0386
0387 return ret;
0388 }
0389
0390 static int viper_backlight_notify(struct device *dev, int brightness)
0391 {
0392 gpio_set_value(VIPER_LCD_EN_GPIO, !!brightness);
0393 gpio_set_value(VIPER_BCKLIGHT_EN_GPIO, !!brightness);
0394
0395 return brightness;
0396 }
0397
0398 static void viper_backlight_exit(struct device *dev)
0399 {
0400 gpio_free(VIPER_LCD_EN_GPIO);
0401 gpio_free(VIPER_BCKLIGHT_EN_GPIO);
0402 }
0403
0404 static struct platform_pwm_backlight_data viper_backlight_data = {
0405 .max_brightness = 100,
0406 .dft_brightness = 100,
0407 .init = viper_backlight_init,
0408 .notify = viper_backlight_notify,
0409 .exit = viper_backlight_exit,
0410 };
0411
0412 static struct platform_device viper_backlight_device = {
0413 .name = "pwm-backlight",
0414 .dev = {
0415 .parent = &pxa25x_device_pwm0.dev,
0416 .platform_data = &viper_backlight_data,
0417 },
0418 };
0419
0420
0421 static struct resource smc91x_resources[] = {
0422 [0] = {
0423 .name = "smc91x-regs",
0424 .start = VIPER_ETH_PHYS + 0x300,
0425 .end = VIPER_ETH_PHYS + 0x30f,
0426 .flags = IORESOURCE_MEM,
0427 },
0428 [1] = {
0429 .start = PXA_GPIO_TO_IRQ(VIPER_ETH_GPIO),
0430 .end = PXA_GPIO_TO_IRQ(VIPER_ETH_GPIO),
0431 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
0432 },
0433 [2] = {
0434 .name = "smc91x-data32",
0435 .start = VIPER_ETH_DATA_PHYS,
0436 .end = VIPER_ETH_DATA_PHYS + 3,
0437 .flags = IORESOURCE_MEM,
0438 },
0439 };
0440
0441 static struct smc91x_platdata viper_smc91x_info = {
0442 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
0443 .leda = RPC_LED_100_10,
0444 .ledb = RPC_LED_TX_RX,
0445 };
0446
0447 static struct platform_device smc91x_device = {
0448 .name = "smc91x",
0449 .id = -1,
0450 .num_resources = ARRAY_SIZE(smc91x_resources),
0451 .resource = smc91x_resources,
0452 .dev = {
0453 .platform_data = &viper_smc91x_info,
0454 },
0455 };
0456
0457
0458 static struct gpiod_lookup_table viper_i2c_gpiod_table = {
0459 .dev_id = "i2c-gpio.1",
0460 .table = {
0461 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO,
0462 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
0463 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO,
0464 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
0465 },
0466 };
0467
0468 static struct i2c_gpio_platform_data i2c_bus_data = {
0469 .udelay = 10,
0470 .timeout = HZ,
0471 };
0472
0473 static struct platform_device i2c_bus_device = {
0474 .name = "i2c-gpio",
0475 .id = 1,
0476 .dev = {
0477 .platform_data = &i2c_bus_data,
0478 }
0479 };
0480
0481 static struct i2c_board_info __initdata viper_i2c_devices[] = {
0482 {
0483 I2C_BOARD_INFO("ds1338", 0x68),
0484 },
0485 };
0486
0487
0488
0489
0490
0491
0492
0493
0494 static struct resource viper_serial_resources[] = {
0495 #ifndef CONFIG_SERIAL_PXA
0496 {
0497 .start = 0x40100000,
0498 .end = 0x4010001f,
0499 .flags = IORESOURCE_MEM,
0500 },
0501 {
0502 .start = 0x40200000,
0503 .end = 0x4020001f,
0504 .flags = IORESOURCE_MEM,
0505 },
0506 {
0507 .start = 0x40700000,
0508 .end = 0x4070001f,
0509 .flags = IORESOURCE_MEM,
0510 },
0511 {
0512 .start = VIPER_UARTA_PHYS,
0513 .end = VIPER_UARTA_PHYS + 0xf,
0514 .flags = IORESOURCE_MEM,
0515 },
0516 {
0517 .start = VIPER_UARTB_PHYS,
0518 .end = VIPER_UARTB_PHYS + 0xf,
0519 .flags = IORESOURCE_MEM,
0520 },
0521 #else
0522 {
0523 0,
0524 },
0525 #endif
0526 };
0527
0528 static struct plat_serial8250_port serial_platform_data[] = {
0529 #ifndef CONFIG_SERIAL_PXA
0530
0531 {
0532 .membase = (void *)&FFUART,
0533 .mapbase = __PREG(FFUART),
0534 .irq = IRQ_FFUART,
0535 .uartclk = 921600 * 16,
0536 .regshift = 2,
0537 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
0538 .iotype = UPIO_MEM,
0539 },
0540 {
0541 .membase = (void *)&BTUART,
0542 .mapbase = __PREG(BTUART),
0543 .irq = IRQ_BTUART,
0544 .uartclk = 921600 * 16,
0545 .regshift = 2,
0546 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
0547 .iotype = UPIO_MEM,
0548 },
0549 {
0550 .membase = (void *)&STUART,
0551 .mapbase = __PREG(STUART),
0552 .irq = IRQ_STUART,
0553 .uartclk = 921600 * 16,
0554 .regshift = 2,
0555 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
0556 .iotype = UPIO_MEM,
0557 },
0558
0559 {
0560 .mapbase = VIPER_UARTA_PHYS,
0561 .irq = PXA_GPIO_TO_IRQ(VIPER_UARTA_GPIO),
0562 .irqflags = IRQF_TRIGGER_RISING,
0563 .uartclk = 1843200,
0564 .regshift = 1,
0565 .iotype = UPIO_MEM,
0566 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
0567 UPF_SKIP_TEST,
0568 },
0569 {
0570 .mapbase = VIPER_UARTB_PHYS,
0571 .irq = PXA_GPIO_TO_IRQ(VIPER_UARTB_GPIO),
0572 .irqflags = IRQF_TRIGGER_RISING,
0573 .uartclk = 1843200,
0574 .regshift = 1,
0575 .iotype = UPIO_MEM,
0576 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
0577 UPF_SKIP_TEST,
0578 },
0579 #endif
0580 { },
0581 };
0582
0583 static struct platform_device serial_device = {
0584 .name = "serial8250",
0585 .id = 0,
0586 .dev = {
0587 .platform_data = serial_platform_data,
0588 },
0589 .num_resources = ARRAY_SIZE(viper_serial_resources),
0590 .resource = viper_serial_resources,
0591 };
0592
0593
0594 static void isp116x_delay(struct device *dev, int delay)
0595 {
0596 ndelay(delay);
0597 }
0598
0599 static struct resource isp116x_resources[] = {
0600 [0] = {
0601 .start = VIPER_USB_PHYS + 0,
0602 .end = VIPER_USB_PHYS + 1,
0603 .flags = IORESOURCE_MEM,
0604 },
0605 [1] = {
0606 .start = VIPER_USB_PHYS + 2,
0607 .end = VIPER_USB_PHYS + 3,
0608 .flags = IORESOURCE_MEM,
0609 },
0610 [2] = {
0611 .start = PXA_GPIO_TO_IRQ(VIPER_USB_GPIO),
0612 .end = PXA_GPIO_TO_IRQ(VIPER_USB_GPIO),
0613 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
0614 },
0615 };
0616
0617
0618 static struct isp116x_platform_data isp116x_platform_data = {
0619
0620 .sel15Kres = 1,
0621
0622 .oc_enable = 1,
0623
0624 .int_act_high = 1,
0625
0626 .int_edge_triggered = 0,
0627
0628
0629
0630
0631 .remote_wakeup_enable = 0,
0632 .delay = isp116x_delay,
0633 };
0634
0635 static struct platform_device isp116x_device = {
0636 .name = "isp116x-hcd",
0637 .id = -1,
0638 .num_resources = ARRAY_SIZE(isp116x_resources),
0639 .resource = isp116x_resources,
0640 .dev = {
0641 .platform_data = &isp116x_platform_data,
0642 },
0643
0644 };
0645
0646
0647 static struct resource mtd_resources[] = {
0648 [0] = {
0649 .start = VIPER_FLASH_PHYS,
0650 .end = VIPER_FLASH_PHYS + SZ_32M - 1,
0651 .flags = IORESOURCE_MEM,
0652 },
0653 [1] = {
0654 .start = VIPER_BOOT_PHYS,
0655 .end = VIPER_BOOT_PHYS + SZ_1M - 1,
0656 .flags = IORESOURCE_MEM,
0657 },
0658 [2] = {
0659
0660
0661
0662 .start = _VIPER_SRAM_BASE,
0663 .end = _VIPER_SRAM_BASE + SZ_512K - 1,
0664 .flags = IORESOURCE_MEM,
0665 },
0666 };
0667
0668 static struct mtd_partition viper_boot_flash_partition = {
0669 .name = "RedBoot",
0670 .size = SZ_1M,
0671 .offset = 0,
0672 .mask_flags = MTD_WRITEABLE,
0673 };
0674
0675 static struct physmap_flash_data viper_flash_data[] = {
0676 [0] = {
0677 .width = 2,
0678 .parts = NULL,
0679 .nr_parts = 0,
0680 },
0681 [1] = {
0682 .width = 2,
0683 .parts = &viper_boot_flash_partition,
0684 .nr_parts = 1,
0685 },
0686 };
0687
0688 static struct platform_device viper_mtd_devices[] = {
0689 [0] = {
0690 .name = "physmap-flash",
0691 .id = 0,
0692 .dev = {
0693 .platform_data = &viper_flash_data[0],
0694 },
0695 .resource = &mtd_resources[0],
0696 .num_resources = 1,
0697 },
0698 [1] = {
0699 .name = "physmap-flash",
0700 .id = 1,
0701 .dev = {
0702 .platform_data = &viper_flash_data[1],
0703 },
0704 .resource = &mtd_resources[1],
0705 .num_resources = 1,
0706 },
0707 };
0708
0709 static struct platform_device *viper_devs[] __initdata = {
0710 &smc91x_device,
0711 &i2c_bus_device,
0712 &serial_device,
0713 &isp116x_device,
0714 &viper_mtd_devices[0],
0715 &viper_mtd_devices[1],
0716 &viper_backlight_device,
0717 &viper_pcmcia_device,
0718 };
0719
0720 static mfp_cfg_t viper_pin_config[] __initdata = {
0721
0722 GPIO15_nCS_1,
0723 GPIO78_nCS_2,
0724 GPIO79_nCS_3,
0725 GPIO80_nCS_4,
0726 GPIO33_nCS_5,
0727
0728
0729 GPIO28_AC97_BITCLK,
0730 GPIO29_AC97_SDATA_IN_0,
0731 GPIO30_AC97_SDATA_OUT,
0732 GPIO31_AC97_SYNC,
0733
0734
0735 GPIO9_GPIO,
0736 GPIO10_GPIO,
0737 GPIO16_PWM0_OUT,
0738
0739
0740 GPIO18_RDY,
0741
0742
0743 GPIO12_GPIO | MFP_LPM_DRIVE_HIGH,
0744
0745
0746 GPIO48_nPOE,
0747 GPIO49_nPWE,
0748 GPIO50_nPIOR,
0749 GPIO51_nPIOW,
0750 GPIO52_nPCE_1,
0751 GPIO53_nPCE_2,
0752 GPIO54_nPSKTSEL,
0753 GPIO55_nPREG,
0754 GPIO56_nPWAIT,
0755 GPIO57_nIOIS16,
0756 GPIO8_GPIO,
0757 GPIO32_GPIO,
0758 GPIO82_GPIO,
0759
0760
0761 GPIO20_GPIO,
0762
0763
0764 GPIO6_GPIO,
0765 GPIO11_GPIO,
0766 GPIO19_GPIO,
0767
0768
0769 GPIO26_GPIO,
0770 GPIO27_GPIO,
0771 GPIO83_GPIO,
0772 GPIO84_GPIO,
0773
0774
0775 GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,
0776 };
0777
0778 static unsigned long viper_tpm;
0779
0780 static int __init viper_tpm_setup(char *str)
0781 {
0782 return kstrtoul(str, 10, &viper_tpm) >= 0;
0783 }
0784
0785 __setup("tpm=", viper_tpm_setup);
0786
0787 struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = {
0788 .dev_id = "i2c-gpio.2",
0789 .table = {
0790 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO,
0791 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
0792 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO,
0793 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
0794 },
0795 };
0796
0797 static void __init viper_tpm_init(void)
0798 {
0799 struct platform_device *tpm_device;
0800 struct i2c_gpio_platform_data i2c_tpm_data = {
0801 .udelay = 10,
0802 .timeout = HZ,
0803 };
0804 char *errstr;
0805
0806
0807 if (!viper_tpm)
0808 return;
0809
0810 gpiod_add_lookup_table(&viper_tpm_i2c_gpiod_table);
0811 tpm_device = platform_device_alloc("i2c-gpio", 2);
0812 if (tpm_device) {
0813 if (!platform_device_add_data(tpm_device,
0814 &i2c_tpm_data,
0815 sizeof(i2c_tpm_data))) {
0816 if (platform_device_add(tpm_device)) {
0817 errstr = "register TPM i2c bus";
0818 goto error_free_tpm;
0819 }
0820 } else {
0821 errstr = "allocate TPM i2c bus data";
0822 goto error_free_tpm;
0823 }
0824 } else {
0825 errstr = "allocate TPM i2c device";
0826 goto error_tpm;
0827 }
0828
0829 return;
0830
0831 error_free_tpm:
0832 kfree(tpm_device);
0833 error_tpm:
0834 pr_err("viper: Couldn't %s, giving up\n", errstr);
0835 }
0836
0837 static void __init viper_init_vcore_gpios(void)
0838 {
0839 if (gpio_request(VIPER_PSU_DATA_GPIO, "PSU data"))
0840 goto err_request_data;
0841
0842 if (gpio_request(VIPER_PSU_CLK_GPIO, "PSU clock"))
0843 goto err_request_clk;
0844
0845 if (gpio_request(VIPER_PSU_nCS_LD_GPIO, "PSU cs"))
0846 goto err_request_cs;
0847
0848 if (gpio_direction_output(VIPER_PSU_DATA_GPIO, 0) ||
0849 gpio_direction_output(VIPER_PSU_CLK_GPIO, 0) ||
0850 gpio_direction_output(VIPER_PSU_nCS_LD_GPIO, 0))
0851 goto err_dir;
0852
0853
0854 viper_set_core_cpu_voltage(pxa25x_get_clk_frequency_khz(0), 1);
0855
0856 return;
0857
0858 err_dir:
0859 gpio_free(VIPER_PSU_nCS_LD_GPIO);
0860 err_request_cs:
0861 gpio_free(VIPER_PSU_CLK_GPIO);
0862 err_request_clk:
0863 gpio_free(VIPER_PSU_DATA_GPIO);
0864 err_request_data:
0865 pr_err("viper: Failed to setup vcore control GPIOs\n");
0866 }
0867
0868 static void __init viper_init_serial_gpio(void)
0869 {
0870 if (gpio_request(VIPER_UART_SHDN_GPIO, "UARTs shutdown"))
0871 goto err_request;
0872
0873 if (gpio_direction_output(VIPER_UART_SHDN_GPIO, 0))
0874 goto err_dir;
0875
0876 return;
0877
0878 err_dir:
0879 gpio_free(VIPER_UART_SHDN_GPIO);
0880 err_request:
0881 pr_err("viper: Failed to setup UART shutdown GPIO\n");
0882 }
0883
0884 #ifdef CONFIG_CPU_FREQ
0885 static int viper_cpufreq_notifier(struct notifier_block *nb,
0886 unsigned long val, void *data)
0887 {
0888 struct cpufreq_freqs *freq = data;
0889
0890
0891
0892 switch (val) {
0893 case CPUFREQ_PRECHANGE:
0894 if (freq->old < freq->new) {
0895
0896
0897 viper_set_core_cpu_voltage(freq->new, 0);
0898 }
0899 break;
0900 case CPUFREQ_POSTCHANGE:
0901 if (freq->old > freq->new) {
0902
0903
0904 viper_set_core_cpu_voltage(freq->new, 0);
0905 }
0906 break;
0907 default:
0908
0909 break;
0910 }
0911
0912 return 0;
0913 }
0914
0915 static struct notifier_block viper_cpufreq_notifier_block = {
0916 .notifier_call = viper_cpufreq_notifier
0917 };
0918
0919 static void __init viper_init_cpufreq(void)
0920 {
0921 if (cpufreq_register_notifier(&viper_cpufreq_notifier_block,
0922 CPUFREQ_TRANSITION_NOTIFIER))
0923 pr_err("viper: Failed to setup cpufreq notifier\n");
0924 }
0925 #else
0926 static inline void viper_init_cpufreq(void) {}
0927 #endif
0928
0929 static void viper_power_off(void)
0930 {
0931 pr_notice("Shutting off UPS\n");
0932 gpio_set_value(VIPER_UPS_GPIO, 1);
0933
0934 while (1);
0935 }
0936
0937 static void __init viper_init(void)
0938 {
0939 u8 version;
0940
0941 pm_power_off = viper_power_off;
0942
0943 pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));
0944
0945 pxa_set_ffuart_info(NULL);
0946 pxa_set_btuart_info(NULL);
0947 pxa_set_stuart_info(NULL);
0948
0949
0950 viper_init_serial_gpio();
0951
0952 pxa_set_fb_info(NULL, &fb_info);
0953
0954
0955 version = viper_hw_version();
0956 if (version == 0)
0957 smc91x_device.num_resources--;
0958
0959 pxa_set_i2c_info(NULL);
0960 gpiod_add_lookup_table(&viper_i2c_gpiod_table);
0961 pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup));
0962 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));
0963
0964 viper_init_vcore_gpios();
0965 viper_init_cpufreq();
0966
0967 register_syscore_ops(&viper_cpu_syscore_ops);
0968
0969 if (version) {
0970 pr_info("viper: hardware v%di%d detected. "
0971 "CPLD revision %d.\n",
0972 VIPER_BOARD_VERSION(version),
0973 VIPER_BOARD_ISSUE(version),
0974 VIPER_CPLD_REVISION(version));
0975 system_rev = (VIPER_BOARD_VERSION(version) << 8) |
0976 (VIPER_BOARD_ISSUE(version) << 4) |
0977 VIPER_CPLD_REVISION(version);
0978 } else {
0979 pr_info("viper: No version register.\n");
0980 }
0981
0982 i2c_register_board_info(1, ARRAY_AND_SIZE(viper_i2c_devices));
0983
0984 viper_tpm_init();
0985 pxa_set_ac97_info(NULL);
0986 }
0987
0988 static struct map_desc viper_io_desc[] __initdata = {
0989 {
0990 .virtual = VIPER_CPLD_BASE,
0991 .pfn = __phys_to_pfn(VIPER_CPLD_PHYS),
0992 .length = 0x00300000,
0993 .type = MT_DEVICE,
0994 },
0995 {
0996 .virtual = VIPER_PC104IO_BASE,
0997 .pfn = __phys_to_pfn(0x30000000),
0998 .length = 0x00800000,
0999 .type = MT_DEVICE,
1000 },
1001 {
1002
1003
1004
1005
1006
1007
1008 .virtual = PCI_IO_VIRT_BASE,
1009 .pfn = __phys_to_pfn(0x30000000),
1010 .length = 0x1000,
1011 .type = MT_DEVICE,
1012 },
1013 };
1014
1015 static void __init viper_map_io(void)
1016 {
1017 pxa25x_map_io();
1018
1019 iotable_init(viper_io_desc, ARRAY_SIZE(viper_io_desc));
1020
1021 PCFR |= PCFR_OPDE;
1022 }
1023
1024 MACHINE_START(VIPER, "Arcom/Eurotech VIPER SBC")
1025
1026 .atag_offset = 0x100,
1027 .map_io = viper_map_io,
1028 .nr_irqs = PXA_NR_IRQS,
1029 .init_irq = viper_init_irq,
1030 .handle_irq = pxa25x_handle_irq,
1031 .init_time = pxa_timer_init,
1032 .init_machine = viper_init,
1033 .restart = pxa_restart,
1034 MACHINE_END