2 * arch/arm/mach-orion/gpio.c
4 * GPIO functions for Marvell Orion System On Chip
6 * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/spinlock.h>
17 #include <linux/bitops.h>
19 #include <asm/arch/orion.h>
22 static DEFINE_SPINLOCK(gpio_lock
);
23 static unsigned long gpio_valid
[BITS_TO_LONGS(GPIO_MAX
)];
24 static const char *gpio_label
[GPIO_MAX
]; /* non null for allocated GPIOs */
26 void __init
orion_gpio_set_valid_pins(u32 pins
)
32 * GENERIC_GPIO primitives
34 int gpio_direction_input(unsigned pin
)
38 if (pin
>= GPIO_MAX
|| !test_bit(pin
, gpio_valid
)) {
39 <<<<<<< HEAD
:arch
/arm
/mach
-orion
/gpio
.c
40 pr_debug("%s: invalid GPIO %d\n", __FUNCTION__
, pin
);
42 pr_debug("%s: invalid GPIO %d\n", __func__
, pin
);
43 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/arm
/mach
-orion
/gpio
.c
47 spin_lock_irqsave(&gpio_lock
, flags
);
50 * Some callers might have not used the gpio_request(),
51 * so flag this pin as requested now.
54 gpio_label
[pin
] = "?";
56 orion_setbits(GPIO_IO_CONF
, 1 << pin
);
58 spin_unlock_irqrestore(&gpio_lock
, flags
);
61 EXPORT_SYMBOL(gpio_direction_input
);
63 int gpio_direction_output(unsigned pin
, int value
)
68 if (pin
>= GPIO_MAX
|| !test_bit(pin
, gpio_valid
)) {
69 <<<<<<< HEAD
:arch
/arm
/mach
-orion
/gpio
.c
70 pr_debug("%s: invalid GPIO %d\n", __FUNCTION__
, pin
);
72 pr_debug("%s: invalid GPIO %d\n", __func__
, pin
);
73 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/arm
/mach
-orion
/gpio
.c
77 spin_lock_irqsave(&gpio_lock
, flags
);
80 * Some callers might have not used the gpio_request(),
81 * so flag this pin as requested now.
84 gpio_label
[pin
] = "?";
87 orion_clrbits(GPIO_BLINK_EN
, mask
);
89 orion_setbits(GPIO_OUT
, mask
);
91 orion_clrbits(GPIO_OUT
, mask
);
92 orion_clrbits(GPIO_IO_CONF
, mask
);
94 spin_unlock_irqrestore(&gpio_lock
, flags
);
97 EXPORT_SYMBOL(gpio_direction_output
);
99 int gpio_get_value(unsigned pin
)
101 int val
, mask
= 1 << pin
;
103 if (orion_read(GPIO_IO_CONF
) & mask
)
104 val
= orion_read(GPIO_DATA_IN
) ^ orion_read(GPIO_IN_POL
);
106 val
= orion_read(GPIO_OUT
);
110 EXPORT_SYMBOL(gpio_get_value
);
112 void gpio_set_value(unsigned pin
, int value
)
117 spin_lock_irqsave(&gpio_lock
, flags
);
119 orion_clrbits(GPIO_BLINK_EN
, mask
);
121 orion_setbits(GPIO_OUT
, mask
);
123 orion_clrbits(GPIO_OUT
, mask
);
125 spin_unlock_irqrestore(&gpio_lock
, flags
);
127 EXPORT_SYMBOL(gpio_set_value
);
129 void orion_gpio_set_blink(unsigned pin
, int blink
)
134 spin_lock_irqsave(&gpio_lock
, flags
);
136 orion_clrbits(GPIO_OUT
, mask
);
138 orion_setbits(GPIO_BLINK_EN
, mask
);
140 orion_clrbits(GPIO_BLINK_EN
, mask
);
142 spin_unlock_irqrestore(&gpio_lock
, flags
);
144 EXPORT_SYMBOL(orion_gpio_set_blink
);
146 int gpio_request(unsigned pin
, const char *label
)
151 if (pin
>= GPIO_MAX
|| !test_bit(pin
, gpio_valid
)) {
152 <<<<<<< HEAD
:arch
/arm
/mach
-orion
/gpio
.c
153 pr_debug("%s: invalid GPIO %d\n", __FUNCTION__
, pin
);
155 pr_debug("%s: invalid GPIO %d\n", __func__
, pin
);
156 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/arm
/mach
-orion
/gpio
.c
160 spin_lock_irqsave(&gpio_lock
, flags
);
162 if (gpio_label
[pin
]) {
163 pr_debug("%s: GPIO %d already used as %s\n",
164 <<<<<<< HEAD
:arch
/arm
/mach
-orion
/gpio
.c
165 __FUNCTION__
, pin
, gpio_label
[pin
]);
167 __func__
, pin
, gpio_label
[pin
]);
168 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/arm
/mach
-orion
/gpio
.c
171 gpio_label
[pin
] = label
? label
: "?";
173 spin_unlock_irqrestore(&gpio_lock
, flags
);
176 EXPORT_SYMBOL(gpio_request
);
178 void gpio_free(unsigned pin
)
180 if (pin
>= GPIO_MAX
|| !test_bit(pin
, gpio_valid
)) {
181 <<<<<<< HEAD
:arch
/arm
/mach
-orion
/gpio
.c
182 pr_debug("%s: invalid GPIO %d\n", __FUNCTION__
, pin
);
184 pr_debug("%s: invalid GPIO %d\n", __func__
, pin
);
185 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/arm
/mach
-orion
/gpio
.c
189 if (!gpio_label
[pin
])
190 <<<<<<< HEAD
:arch
/arm
/mach
-orion
/gpio
.c
191 pr_warning("%s: GPIO %d already freed\n", __FUNCTION__
, pin
);
193 pr_warning("%s: GPIO %d already freed\n", __func__
, pin
);
194 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/arm
/mach
-orion
/gpio
.c
196 gpio_label
[pin
] = NULL
;
198 EXPORT_SYMBOL(gpio_free
);
201 void gpio_display(void)
205 for (i
= 0; i
< GPIO_MAX
; i
++) {
206 printk(KERN_DEBUG
"Pin-%d: ", i
);
208 if (!test_bit(i
, gpio_valid
)) {
209 printk("non-GPIO\n");
210 } else if (!gpio_label
[i
]) {
211 printk("GPIO, free\n");
213 printk("GPIO, used by %s, ", gpio_label
[i
]);
214 if (orion_read(GPIO_IO_CONF
) & (1 << i
)) {
215 printk("input, active %s, level %s, edge %s\n",
216 ((orion_read(GPIO_IN_POL
) >> i
) & 1) ? "low" : "high",
217 ((orion_read(GPIO_LEVEL_MASK
) >> i
) & 1) ? "enabled" : "masked",
218 ((orion_read(GPIO_EDGE_MASK
) >> i
) & 1) ? "enabled" : "masked");
220 printk("output, val=%d\n", (orion_read(GPIO_OUT
) >> i
) & 1);
225 printk(KERN_DEBUG
"MPP_0_7_CTRL (0x%08x) = 0x%08x\n",
226 MPP_0_7_CTRL
, orion_read(MPP_0_7_CTRL
));
227 printk(KERN_DEBUG
"MPP_8_15_CTRL (0x%08x) = 0x%08x\n",
228 MPP_8_15_CTRL
, orion_read(MPP_8_15_CTRL
));
229 printk(KERN_DEBUG
"MPP_16_19_CTRL (0x%08x) = 0x%08x\n",
230 MPP_16_19_CTRL
, orion_read(MPP_16_19_CTRL
));
231 printk(KERN_DEBUG
"MPP_DEV_CTRL (0x%08x) = 0x%08x\n",
232 MPP_DEV_CTRL
, orion_read(MPP_DEV_CTRL
));
233 printk(KERN_DEBUG
"GPIO_OUT (0x%08x) = 0x%08x\n",
234 GPIO_OUT
, orion_read(GPIO_OUT
));
235 printk(KERN_DEBUG
"GPIO_IO_CONF (0x%08x) = 0x%08x\n",
236 GPIO_IO_CONF
, orion_read(GPIO_IO_CONF
));
237 printk(KERN_DEBUG
"GPIO_BLINK_EN (0x%08x) = 0x%08x\n",
238 GPIO_BLINK_EN
, orion_read(GPIO_BLINK_EN
));
239 printk(KERN_DEBUG
"GPIO_IN_POL (0x%08x) = 0x%08x\n",
240 GPIO_IN_POL
, orion_read(GPIO_IN_POL
));
241 printk(KERN_DEBUG
"GPIO_DATA_IN (0x%08x) = 0x%08x\n",
242 GPIO_DATA_IN
, orion_read(GPIO_DATA_IN
));
243 printk(KERN_DEBUG
"GPIO_LEVEL_MASK (0x%08x) = 0x%08x\n",
244 GPIO_LEVEL_MASK
, orion_read(GPIO_LEVEL_MASK
));
245 printk(KERN_DEBUG
"GPIO_EDGE_CAUSE (0x%08x) = 0x%08x\n",
246 GPIO_EDGE_CAUSE
, orion_read(GPIO_EDGE_CAUSE
));
247 printk(KERN_DEBUG
"GPIO_EDGE_MASK (0x%08x) = 0x%08x\n",
248 GPIO_EDGE_MASK
, orion_read(GPIO_EDGE_MASK
));