3 * Gabriel Huau <contact@huau-gabriel.fr>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <asm/arch/s3c2440.h>
28 #define GPIO_INPUT 0x0
29 #define GPIO_OUTPUT 0x1
31 /* 0x4 means that we want DAT and not CON register */
32 #define GPIO_PORT(x) ((((x) >> 5) & 0x3) + 0x4)
33 #define GPIO_BIT(x) ((x) & 0x3f)
36 * It's how we calculate the full port address
37 * We have to get the number of the port + 1 (Port A is at 0x56000001 ...)
38 * We move it at the second digit, and finally we add 0x4 because we want
39 * to modify GPIO DAT and not CON
41 #define GPIO_FULLPORT(x) (S3C24X0_GPIO_BASE | ((GPIO_PORT(gpio) + 1) << 1))
43 int gpio_set_value(unsigned gpio, int value)
45 unsigned l = readl(GPIO_FULLPORT(gpio));
47 unsigned port = GPIO_FULLPORT(gpio);
50 * All GPIO Port have a configuration on
51 * 2 bits excepted the first GPIO (A) which
52 * have only 1 bit of configuration.
55 bit = (0x1 << GPIO_BIT(gpio));
57 bit = (0x3 << GPIO_BIT(gpio));
64 return writel(l, port);
67 int gpio_get_value(unsigned gpio)
69 unsigned l = readl(GPIO_FULLPORT(gpio));
71 if (GPIO_PORT(gpio) == 0) /* PORT A */
72 return (l >> GPIO_BIT(gpio)) & 0x1;
73 return (l >> GPIO_BIT(gpio)) & 0x3;
76 int gpio_request(unsigned gpio, const char *label)
81 int gpio_free(unsigned gpio)
86 int gpio_direction_input(unsigned gpio)
88 return writel(GPIO_INPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
91 int gpio_direction_output(unsigned gpio, int value)
93 writel(GPIO_OUTPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
94 return gpio_set_value(gpio, value);