Merge tag 'drm-for-v4.8-zpos' of git://people.freedesktop.org/~airlied/linux
[deliverable/linux.git] / arch / unicore32 / kernel / gpio.c
CommitLineData
752bcb4d
G
1/*
2 * linux/arch/unicore32/kernel/gpio.c
3 *
4 * Code specific to PKUnity SoC and UniCore ISA
5 *
6 * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
7 * Copyright (C) 2001-2010 Guan Xuetao
8 *
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.
12 */
13/* in FPGA, no GPIO support */
14
15#include <linux/init.h>
16#include <linux/module.h>
fd19f534
LW
17#include <linux/gpio/driver.h>
18/* FIXME: needed for gpio_set_value() - convert to use descriptors or hogs */
752bcb4d
G
19#include <linux/gpio.h>
20#include <mach/hardware.h>
21
22#ifdef CONFIG_LEDS
23#include <linux/leds.h>
24#include <linux/platform_device.h>
25
26static 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,
fed758f6 30 .default_trigger = "disk-activity", },
752bcb4d
G
31};
32
33static const struct gpio_led_platform_data puv3_gpio_led_data = {
34 .num_leds = ARRAY_SIZE(puv3_gpio_leds),
35 .leds = (void *) puv3_gpio_leds,
36};
37
38static struct platform_device puv3_gpio_gpio_leds = {
39 .name = "leds-gpio",
40 .id = -1,
41 .dev = {
42 .platform_data = (void *) &puv3_gpio_led_data,
43 }
44};
45
46static int __init puv3_gpio_leds_init(void)
47{
48 platform_device_register(&puv3_gpio_gpio_leds);
49 return 0;
50}
51
52device_initcall(puv3_gpio_leds_init);
53#endif
54
55static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)
56{
a80bb4c9 57 return !!(readl(GPIO_GPLR) & GPIO_GPIO(offset));
752bcb4d
G
58}
59
60static void puv3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
61{
62 if (value)
e5abf78b 63 writel(GPIO_GPIO(offset), GPIO_GPSR);
752bcb4d 64 else
e5abf78b 65 writel(GPIO_GPIO(offset), GPIO_GPCR);
752bcb4d
G
66}
67
68static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)
69{
70 unsigned long flags;
71
72 local_irq_save(flags);
e5abf78b 73 writel(readl(GPIO_GPDR) & ~GPIO_GPIO(offset), GPIO_GPDR);
752bcb4d
G
74 local_irq_restore(flags);
75 return 0;
76}
77
78static int puv3_direction_output(struct gpio_chip *chip, unsigned offset,
79 int value)
80{
81 unsigned long flags;
82
83 local_irq_save(flags);
84 puv3_gpio_set(chip, offset, value);
e5abf78b 85 writel(readl(GPIO_GPDR) | GPIO_GPIO(offset), GPIO_GPDR);
752bcb4d
G
86 local_irq_restore(flags);
87 return 0;
88}
89
90static 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,
98};
99
100void __init puv3_init_gpio(void)
101{
e5abf78b 102 writel(GPIO_DIR, GPIO_GPDR);
752bcb4d
G
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);
117/*
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);
121 */
122#endif
fd19f534 123 gpiochip_add_data(&puv3_gpio_chip, NULL);
752bcb4d 124}
This page took 0.311846 seconds and 5 git commands to generate.