kvm tools, setup: Create private directory
[linux-2.6/next.git] / arch / unicore32 / kernel / gpio.c
blobcb12ec39552c0d2fd75ac466093f93bcf22cfd3f
1 /*
2 * linux/arch/unicore32/kernel/gpio.c
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
7 * Copyright (C) 2001-2010 Guan Xuetao
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 /* in FPGA, no GPIO support */
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/gpio.h>
18 #include <mach/hardware.h>
20 #ifdef CONFIG_LEDS
21 #include <linux/leds.h>
22 #include <linux/platform_device.h>
24 static const struct gpio_led puv3_gpio_leds[] = {
25 { .name = "cpuhealth", .gpio = GPO_CPU_HEALTH, .active_low = 0,
26 .default_trigger = "heartbeat", },
27 { .name = "hdd_led", .gpio = GPO_HDD_LED, .active_low = 1,
28 .default_trigger = "ide-disk", },
31 static const struct gpio_led_platform_data puv3_gpio_led_data = {
32 .num_leds = ARRAY_SIZE(puv3_gpio_leds),
33 .leds = (void *) puv3_gpio_leds,
36 static struct platform_device puv3_gpio_gpio_leds = {
37 .name = "leds-gpio",
38 .id = -1,
39 .dev = {
40 .platform_data = (void *) &puv3_gpio_led_data,
44 static int __init puv3_gpio_leds_init(void)
46 platform_device_register(&puv3_gpio_gpio_leds);
47 return 0;
50 device_initcall(puv3_gpio_leds_init);
51 #endif
53 static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)
55 return readl(GPIO_GPLR) & GPIO_GPIO(offset);
58 static void puv3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
60 if (value)
61 writel(GPIO_GPIO(offset), GPIO_GPSR);
62 else
63 writel(GPIO_GPIO(offset), GPIO_GPCR);
66 static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)
68 unsigned long flags;
70 local_irq_save(flags);
71 writel(readl(GPIO_GPDR) & ~GPIO_GPIO(offset), GPIO_GPDR);
72 local_irq_restore(flags);
73 return 0;
76 static int puv3_direction_output(struct gpio_chip *chip, unsigned offset,
77 int value)
79 unsigned long flags;
81 local_irq_save(flags);
82 puv3_gpio_set(chip, offset, value);
83 writel(readl(GPIO_GPDR) | GPIO_GPIO(offset), GPIO_GPDR);
84 local_irq_restore(flags);
85 return 0;
88 static struct gpio_chip puv3_gpio_chip = {
89 .label = "gpio",
90 .direction_input = puv3_direction_input,
91 .direction_output = puv3_direction_output,
92 .set = puv3_gpio_set,
93 .get = puv3_gpio_get,
94 .base = 0,
95 .ngpio = GPIO_MAX + 1,
98 void __init puv3_init_gpio(void)
100 writel(GPIO_DIR, GPIO_GPDR);
101 #if defined(CONFIG_PUV3_NB0916) || defined(CONFIG_PUV3_SMW0919) \
102 || defined(CONFIG_PUV3_DB0913)
103 gpio_set_value(GPO_WIFI_EN, 1);
104 gpio_set_value(GPO_HDD_LED, 1);
105 gpio_set_value(GPO_VGA_EN, 1);
106 gpio_set_value(GPO_LCD_EN, 1);
107 gpio_set_value(GPO_CAM_PWR_EN, 0);
108 gpio_set_value(GPO_LCD_VCC_EN, 1);
109 gpio_set_value(GPO_SOFT_OFF, 1);
110 gpio_set_value(GPO_BT_EN, 1);
111 gpio_set_value(GPO_FAN_ON, 0);
112 gpio_set_value(GPO_SPKR, 0);
113 gpio_set_value(GPO_CPU_HEALTH, 1);
114 gpio_set_value(GPO_LAN_SEL, 1);
116 * DO NOT modify the GPO_SET_V1 and GPO_SET_V2 in kernel
117 * gpio_set_value(GPO_SET_V1, 1);
118 * gpio_set_value(GPO_SET_V2, 1);
120 #endif
121 gpiochip_add(&puv3_gpio_chip);