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.
39 #include <asm/omap_gpio.h>
41 #include <asm/errno.h>
43 static inline const struct gpio_bank *get_gpio_bank(int gpio)
45 return &omap_gpio_bank[gpio >> 5];
48 static inline int get_gpio_index(int gpio)
53 static inline int gpio_valid(int gpio)
62 static int check_gpio(int gpio)
64 if (gpio_valid(gpio) < 0) {
65 printf("ERROR : check_gpio: invalid GPIO %d\n", gpio);
71 static void _set_gpio_direction(const struct gpio_bank *bank, int gpio,
74 void *reg = bank->base;
77 switch (bank->method) {
78 case METHOD_GPIO_24XX:
92 void omap_set_gpio_direction(int gpio, int is_input)
94 const struct gpio_bank *bank;
96 if (check_gpio(gpio) < 0)
98 bank = get_gpio_bank(gpio);
99 _set_gpio_direction(bank, get_gpio_index(gpio), is_input);
102 static void _set_gpio_dataout(const struct gpio_bank *bank, int gpio,
105 void *reg = bank->base;
108 switch (bank->method) {
109 case METHOD_GPIO_24XX:
111 reg += OMAP_GPIO_SETDATAOUT;
113 reg += OMAP_GPIO_CLEARDATAOUT;
117 printf("omap3-gpio unknown bank method %s %d\n",
121 __raw_writel(l, reg);
124 void omap_set_gpio_dataout(int gpio, int enable)
126 const struct gpio_bank *bank;
128 if (check_gpio(gpio) < 0)
130 bank = get_gpio_bank(gpio);
131 _set_gpio_dataout(bank, get_gpio_index(gpio), enable);
134 int omap_get_gpio_datain(int gpio)
136 const struct gpio_bank *bank;
139 if (check_gpio(gpio) < 0)
141 bank = get_gpio_bank(gpio);
143 switch (bank->method) {
144 case METHOD_GPIO_24XX:
145 reg += OMAP_GPIO_DATAIN;
150 return (__raw_readl(reg)
151 & (1 << get_gpio_index(gpio))) != 0;
154 static void _reset_gpio(const struct gpio_bank *bank, int gpio)
156 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
159 int omap_request_gpio(int gpio)
161 if (check_gpio(gpio) < 0)
167 void omap_free_gpio(int gpio)
169 const struct gpio_bank *bank;
171 if (check_gpio(gpio) < 0)
173 bank = get_gpio_bank(gpio);
175 _reset_gpio(bank, gpio);