1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <common.h>
28#include <asm/arch/hardware.h>
29#include <asm/gpio.h>
30#include <asm/io.h>
31#include <errno.h>
32
33static int gpio_direction(unsigned gpio,
34 enum gpio_direction direction)
35{
36 struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
37 u32 val;
38
39 val = readl(®s->gpiodir);
40
41 if (direction == GPIO_DIRECTION_OUT)
42 val |= 1 << gpio;
43 else
44 val &= ~(1 << gpio);
45
46 writel(val, ®s->gpiodir);
47
48 return 0;
49}
50
51int gpio_set_value(unsigned gpio, int value)
52{
53 struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
54
55 writel(1 << gpio, ®s->gpiodata[DATA_REG_ADDR(gpio)]);
56
57 return 0;
58}
59
60int gpio_get_value(unsigned gpio)
61{
62 struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
63 u32 val;
64
65 val = readl(®s->gpiodata[DATA_REG_ADDR(gpio)]);
66
67 return !!val;
68}
69
70int gpio_request(unsigned gpio, const char *label)
71{
72 if (gpio >= SPEAR_GPIO_COUNT)
73 return -EINVAL;
74
75 return 0;
76}
77
78int gpio_free(unsigned gpio)
79{
80 return 0;
81}
82
83void gpio_toggle_value(unsigned gpio)
84{
85 gpio_set_value(gpio, !gpio_get_value(gpio));
86}
87
88int gpio_direction_input(unsigned gpio)
89{
90 return gpio_direction(gpio, GPIO_DIRECTION_IN);
91}
92
93int gpio_direction_output(unsigned gpio, int value)
94{
95 int ret = gpio_direction(gpio, GPIO_DIRECTION_OUT);
96
97 if (ret < 0)
98 return ret;
99
100 gpio_set_value(gpio, value);
101 return 0;
102}
103