usb: ohci-at91: use descriptor-based gpio APIs correctly
[linux/fpc-iii.git] / arch / unicore32 / kernel / gpio.c
blobbf164bb4dba2776ccc4ca771e263b8e89a1360e8
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/driver.h>
18 /* FIXME: needed for gpio_set_value() - convert to use descriptors or hogs */
19 #include <linux/gpio.h>
20 #include <mach/hardware.h>
22 #ifdef CONFIG_LEDS
23 #include <linux/leds.h>
24 #include <linux/platform_device.h>
26 static const struct gpio_led puv3_gpio_leds[] = {
27 { .name = "cpuhealth", .gpio = GPO_CPU_HEALTH, .active_low = 0,
28 .default_trigger = "heartbeat", },
29 { .name = "hdd_led", .gpio = GPO_HDD_LED, .active_low = 1,
30 .default_trigger = "disk-activity", },
33 static const struct gpio_led_platform_data puv3_gpio_led_data = {
34 .num_leds = ARRAY_SIZE(puv3_gpio_leds),
35 .leds = (void *) puv3_gpio_leds,
38 static struct platform_device puv3_gpio_gpio_leds = {
39 .name = "leds-gpio",
40 .id = -1,
41 .dev = {
42 .platform_data = (void *) &puv3_gpio_led_data,
46 static int __init puv3_gpio_leds_init(void)
48 platform_device_register(&puv3_gpio_gpio_leds);
49 return 0;
52 device_initcall(puv3_gpio_leds_init);
53 #endif
55 static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)
57 return !!(readl(GPIO_GPLR) & GPIO_GPIO(offset));
60 static void puv3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
62 if (value)
63 writel(GPIO_GPIO(offset), GPIO_GPSR);
64 else
65 writel(GPIO_GPIO(offset), GPIO_GPCR);
68 static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)
70 unsigned long flags;
72 local_irq_save(flags);
73 writel(readl(GPIO_GPDR) & ~GPIO_GPIO(offset), GPIO_GPDR);
74 local_irq_restore(flags);
75 return 0;
78 static int puv3_direction_output(struct gpio_chip *chip, unsigned offset,
79 int value)
81 unsigned long flags;
83 local_irq_save(flags);
84 puv3_gpio_set(chip, offset, value);
85 writel(readl(GPIO_GPDR) | GPIO_GPIO(offset), GPIO_GPDR);
86 local_irq_restore(flags);
87 return 0;
90 static struct gpio_chip puv3_gpio_chip = {
91 .label = "gpio",
92 .direction_input = puv3_direction_input,
93 .direction_output = puv3_direction_output,
94 .set = puv3_gpio_set,
95 .get = puv3_gpio_get,
96 .base = 0,
97 .ngpio = GPIO_MAX + 1,
100 void __init puv3_init_gpio(void)
102 writel(GPIO_DIR, GPIO_GPDR);
103 #if defined(CONFIG_PUV3_NB0916) || defined(CONFIG_PUV3_SMW0919) \
104 || defined(CONFIG_PUV3_DB0913)
105 gpio_set_value(GPO_WIFI_EN, 1);
106 gpio_set_value(GPO_HDD_LED, 1);
107 gpio_set_value(GPO_VGA_EN, 1);
108 gpio_set_value(GPO_LCD_EN, 1);
109 gpio_set_value(GPO_CAM_PWR_EN, 0);
110 gpio_set_value(GPO_LCD_VCC_EN, 1);
111 gpio_set_value(GPO_SOFT_OFF, 1);
112 gpio_set_value(GPO_BT_EN, 1);
113 gpio_set_value(GPO_FAN_ON, 0);
114 gpio_set_value(GPO_SPKR, 0);
115 gpio_set_value(GPO_CPU_HEALTH, 1);
116 gpio_set_value(GPO_LAN_SEL, 1);
118 * DO NOT modify the GPO_SET_V1 and GPO_SET_V2 in kernel
119 * gpio_set_value(GPO_SET_V1, 1);
120 * gpio_set_value(GPO_SET_V2, 1);
122 #endif
123 gpiochip_add_data(&puv3_gpio_chip, NULL);