1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef POWERPC_ASM_MPC85XX_GPIO_H_
21#define POWERPC_ASM_MPC85XX_GPIO_H_
22
23# include <asm/immap_85xx.h>
24
25
26
27
28
29
30
31
32
33static inline void mpc85xx_gpio_set(unsigned int mask,
34 unsigned int dir, unsigned int val)
35{
36 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR + 0xc00);
37
38
39 dir &= mask;
40 val &= mask;
41
42
43 dir |= (in_be32(&gpio->gpdir) & ~mask);
44 val |= (in_be32(&gpio->gpdat) & ~mask);
45
46
47
48
49
50
51 out_be32(&gpio->gpdat, val);
52 out_be32(&gpio->gpdir, dir);
53}
54
55static inline void mpc85xx_gpio_set_in(unsigned int gpios)
56{
57 mpc85xx_gpio_set(gpios, 0x00000000, 0x00000000);
58}
59
60static inline void mpc85xx_gpio_set_low(unsigned int gpios)
61{
62 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0x00000000);
63}
64
65static inline void mpc85xx_gpio_set_high(unsigned int gpios)
66{
67 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0xFFFFFFFF);
68}
69
70static inline unsigned int mpc85xx_gpio_get(unsigned int mask)
71{
72 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR + 0xc00);
73
74
75 return in_be32(&gpio->gpdat) & mask;
76}
77
78
79
80
81
82static inline int gpio_request(unsigned gpio, const char *label)
83{
84
85 return 0;
86}
87
88static inline void gpio_free(unsigned gpio)
89{
90
91}
92
93static inline int gpio_direction_input(unsigned gpio)
94{
95 mpc85xx_gpio_set_in(1U << gpio);
96 return 0;
97}
98
99static inline int gpio_direction_output(unsigned gpio, int value)
100{
101 mpc85xx_gpio_set_low(1U << gpio);
102 return 0;
103}
104
105static inline int gpio_get_value(unsigned gpio)
106{
107 return !!mpc85xx_gpio_get(1U << gpio);
108}
109
110static inline void gpio_set_value(unsigned gpio, int value)
111{
112 if (value)
113 mpc85xx_gpio_set_high(1U << gpio);
114 else
115 mpc85xx_gpio_set_low(1U << gpio);
116}
117
118static inline int gpio_is_valid(int gpio)
119{
120 return (gpio >= 0) && (gpio < 32);
121}
122
123#endif
124