]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/gpio/omap_gpio.c
2 * Copyright (c) 2009 Wind River Systems, Inc.
3 * Tom Rix <Tom.Rix@windriver.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * This work is derived from the linux 2.6.27 kernel source
21 * To fetch, use the kernel repository
22 * git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
23 * Use the v2.6.27 tag.
25 * Below is the original's header including its copyright
27 * linux/arch/arm/plat-omap/gpio.c
29 * Support functions for OMAP GPIO
31 * Copyright (C) 2003-2005 Nokia Corporation
32 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
34 * This program is free software; you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License version 2 as
36 * published by the Free Software Foundation.
41 #include <asm/errno.h>
43 #define OMAP_GPIO_DIR_OUT 0
44 #define OMAP_GPIO_DIR_IN 1
46 static inline const struct gpio_bank
*get_gpio_bank(int gpio
)
48 return &omap_gpio_bank
[gpio
>> 5];
51 static inline int get_gpio_index(int gpio
)
56 static inline int gpio_valid(int gpio
)
65 static int check_gpio(int gpio
)
67 if (gpio_valid(gpio
) < 0) {
68 printf("ERROR : check_gpio: invalid GPIO %d\n", gpio
);
74 static void _set_gpio_direction(const struct gpio_bank
*bank
, int gpio
,
77 void *reg
= bank
->base
;
80 switch (bank
->method
) {
81 case METHOD_GPIO_24XX
:
96 * Get the direction of the GPIO by reading the GPIO_OE register
97 * corresponding to the specified bank.
99 static int _get_gpio_direction(const struct gpio_bank
*bank
, int gpio
)
101 void *reg
= bank
->base
;
104 switch (bank
->method
) {
105 case METHOD_GPIO_24XX
:
112 v
= __raw_readl(reg
);
115 return OMAP_GPIO_DIR_IN
;
117 return OMAP_GPIO_DIR_OUT
;
120 static void _set_gpio_dataout(const struct gpio_bank
*bank
, int gpio
,
123 void *reg
= bank
->base
;
126 switch (bank
->method
) {
127 case METHOD_GPIO_24XX
:
129 reg
+= OMAP_GPIO_SETDATAOUT
;
131 reg
+= OMAP_GPIO_CLEARDATAOUT
;
135 printf("omap3-gpio unknown bank method %s %d\n",
139 __raw_writel(l
, reg
);
143 * Set value of the specified gpio
145 int gpio_set_value(unsigned gpio
, int value
)
147 const struct gpio_bank
*bank
;
149 if (check_gpio(gpio
) < 0)
151 bank
= get_gpio_bank(gpio
);
152 _set_gpio_dataout(bank
, get_gpio_index(gpio
), value
);
158 * Get value of the specified gpio
160 int gpio_get_value(unsigned gpio
)
162 const struct gpio_bank
*bank
;
166 if (check_gpio(gpio
) < 0)
168 bank
= get_gpio_bank(gpio
);
170 switch (bank
->method
) {
171 case METHOD_GPIO_24XX
:
172 input
= _get_gpio_direction(bank
, get_gpio_index(gpio
));
174 case OMAP_GPIO_DIR_IN
:
175 reg
+= OMAP_GPIO_DATAIN
;
177 case OMAP_GPIO_DIR_OUT
:
178 reg
+= OMAP_GPIO_DATAOUT
;
187 return (__raw_readl(reg
)
188 & (1 << get_gpio_index(gpio
))) != 0;
192 * Set gpio direction as input
194 int gpio_direction_input(unsigned gpio
)
196 const struct gpio_bank
*bank
;
198 if (check_gpio(gpio
) < 0)
201 bank
= get_gpio_bank(gpio
);
202 _set_gpio_direction(bank
, get_gpio_index(gpio
), 1);
208 * Set gpio direction as output
210 int gpio_direction_output(unsigned gpio
, int value
)
212 const struct gpio_bank
*bank
;
214 if (check_gpio(gpio
) < 0)
217 bank
= get_gpio_bank(gpio
);
218 _set_gpio_dataout(bank
, get_gpio_index(gpio
), value
);
219 _set_gpio_direction(bank
, get_gpio_index(gpio
), 0);
225 * Request a gpio before using it.
227 * NOTE: Argument 'label' is unused.
229 int gpio_request(unsigned gpio
, const char *label
)
231 if (check_gpio(gpio
) < 0)
238 * Reset and free the gpio after using it.
240 int gpio_free(unsigned gpio
)