]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - drivers/gpio/kw_gpio.c
2 * arch/arm/plat-orion/gpio.c
4 * Marvell Orion SoC GPIO handling.
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 * Based on (mostly copied from) plat-orion based Linux 2.6 kernel driver.
27 * Removed orion_gpiochip struct and kernel level irq handling.
29 * Dieter Kiermaier dk-arm-linux@gmx.de
33 #include <asm/bitops.h>
34 #include <asm/arch/kirkwood.h>
35 #include <asm/arch/gpio.h>
37 static unsigned long gpio_valid_input
[BITS_TO_LONGS(GPIO_MAX
)];
38 static unsigned long gpio_valid_output
[BITS_TO_LONGS(GPIO_MAX
)];
40 void __set_direction(unsigned pin
, int input
)
44 u
= readl(GPIO_IO_CONF(pin
));
48 u
&= ~(1 << (pin
& 31));
49 writel(u
, GPIO_IO_CONF(pin
));
51 u
= readl(GPIO_IO_CONF(pin
));
54 void __set_level(unsigned pin
, int high
)
58 u
= readl(GPIO_OUT(pin
));
62 u
&= ~(1 << (pin
& 31));
63 writel(u
, GPIO_OUT(pin
));
66 void __set_blinking(unsigned pin
, int blink
)
70 u
= readl(GPIO_BLINK_EN(pin
));
74 u
&= ~(1 << (pin
& 31));
75 writel(u
, GPIO_BLINK_EN(pin
));
78 int kw_gpio_is_valid(unsigned pin
, int mode
)
81 if ((mode
& GPIO_INPUT_OK
) && !test_bit(pin
, gpio_valid_input
))
84 if ((mode
& GPIO_OUTPUT_OK
) && !test_bit(pin
, gpio_valid_output
))
90 printf("%s: invalid GPIO %d\n", __func__
, pin
);
94 void kw_gpio_set_valid(unsigned pin
, int mode
)
97 mode
= GPIO_INPUT_OK
| GPIO_OUTPUT_OK
;
98 if (mode
& GPIO_INPUT_OK
)
99 __set_bit(pin
, gpio_valid_input
);
101 __clear_bit(pin
, gpio_valid_input
);
102 if (mode
& GPIO_OUTPUT_OK
)
103 __set_bit(pin
, gpio_valid_output
);
105 __clear_bit(pin
, gpio_valid_output
);
108 * GENERIC_GPIO primitives.
110 int kw_gpio_direction_input(unsigned pin
)
112 if (!kw_gpio_is_valid(pin
, GPIO_INPUT_OK
))
115 /* Configure GPIO direction. */
116 __set_direction(pin
, 1);
121 int kw_gpio_direction_output(unsigned pin
, int value
)
123 if (kw_gpio_is_valid(pin
, GPIO_OUTPUT_OK
) != 0)
125 printf("%s: invalid GPIO %d\n", __func__
, pin
);
129 __set_blinking(pin
, 0);
131 /* Configure GPIO output value. */
132 __set_level(pin
, value
);
134 /* Configure GPIO direction. */
135 __set_direction(pin
, 0);
140 int kw_gpio_get_value(unsigned pin
)
144 if (readl(GPIO_IO_CONF(pin
)) & (1 << (pin
& 31)))
145 val
= readl(GPIO_DATA_IN(pin
)) ^ readl(GPIO_IN_POL(pin
));
147 val
= readl(GPIO_OUT(pin
));
149 return (val
>> (pin
& 31)) & 1;
152 void kw_gpio_set_value(unsigned pin
, int value
)
154 /* Configure GPIO output value. */
155 __set_level(pin
, value
);
158 void kw_gpio_set_blink(unsigned pin
, int blink
)
160 /* Set output value to zero. */
164 __set_blinking(pin
, blink
);