3 * Gabriel Huau <contact@huau-gabriel.fr>
5 * SPDX-License-Identifier: GPL-2.0+
8 #include <asm/arch/s3c2440.h>
12 #define GPIO_INPUT 0x0
13 #define GPIO_OUTPUT 0x1
15 /* 0x4 means that we want DAT and not CON register */
16 #define GPIO_PORT(x) ((((x) >> 5) & 0x3) + 0x4)
17 #define GPIO_BIT(x) ((x) & 0x3f)
20 * It's how we calculate the full port address
21 * We have to get the number of the port + 1 (Port A is at 0x56000001 ...)
22 * We move it at the second digit, and finally we add 0x4 because we want
23 * to modify GPIO DAT and not CON
25 #define GPIO_FULLPORT(x) (S3C24X0_GPIO_BASE | ((GPIO_PORT(gpio) + 1) << 1))
27 int gpio_set_value(unsigned gpio, int value)
29 unsigned l = readl(GPIO_FULLPORT(gpio));
31 unsigned port = GPIO_FULLPORT(gpio);
34 * All GPIO Port have a configuration on
35 * 2 bits excepted the first GPIO (A) which
36 * have only 1 bit of configuration.
39 bit = (0x1 << GPIO_BIT(gpio));
41 bit = (0x3 << GPIO_BIT(gpio));
48 return writel(l, port);
51 int gpio_get_value(unsigned gpio)
53 unsigned l = readl(GPIO_FULLPORT(gpio));
55 if (GPIO_PORT(gpio) == 0) /* PORT A */
56 return (l >> GPIO_BIT(gpio)) & 0x1;
57 return (l >> GPIO_BIT(gpio)) & 0x3;
60 int gpio_request(unsigned gpio, const char *label)
65 int gpio_free(unsigned gpio)
70 int gpio_direction_input(unsigned gpio)
72 return writel(GPIO_INPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
75 int gpio_direction_output(unsigned gpio, int value)
77 writel(GPIO_OUTPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
78 return gpio_set_value(gpio, value);