1
2
3
4
5
6
7#include <common.h>
8#include <asm/io.h>
9#include "vct.h"
10
11
12
13
14
15
16
17#define GPIO_MODULE(pin) ((pin) >> 5)
18
19
20
21
22
23#define MASK(pin) (1 << ((pin) & 0x1F))
24#define BASE_ADDR(mod) module_base[mod]
25
26
27
28
29
30static u32 module_base[] = {
31 GPIO1_BASE,
32 GPIO2_BASE
33};
34
35static void clrsetbits(u32 addr, u32 and_mask, u32 or_mask)
36{
37 reg_write(addr, (reg_read(addr) & ~and_mask) | or_mask);
38}
39
40int vct_gpio_dir(int pin, int dir)
41{
42 u32 gpio_base;
43
44 gpio_base = BASE_ADDR(GPIO_MODULE(pin));
45
46 if (dir == 0)
47 clrsetbits(GPIO_SWPORTA_DDR(gpio_base), MASK(pin), 0);
48 else
49 clrsetbits(GPIO_SWPORTA_DDR(gpio_base), 0, MASK(pin));
50
51 return 0;
52}
53
54void vct_gpio_set(int pin, int val)
55{
56 u32 gpio_base;
57
58 gpio_base = BASE_ADDR(GPIO_MODULE(pin));
59
60 if (val == 0)
61 clrsetbits(GPIO_SWPORTA_DR(gpio_base), MASK(pin), 0);
62 else
63 clrsetbits(GPIO_SWPORTA_DR(gpio_base), 0, MASK(pin));
64}
65
66int vct_gpio_get(int pin)
67{
68 u32 gpio_base;
69 u32 value;
70
71 gpio_base = BASE_ADDR(GPIO_MODULE(pin));
72 value = reg_read(GPIO_EXT_PORTA(gpio_base));
73
74 return ((value & MASK(pin)) ? 1 : 0);
75}
76