Merge tag 'ti-v2020.07-rc3' of https://gitlab.denx.de/u-boot/custodians/u-boot-ti
[oweals/u-boot.git] / arch / mips / mach-jz47xx / jz4780 / gpio.c
1 // SPDX-License-Identifier: GPL-2.0+
2
3 #include <config.h>
4 #include <common.h>
5 #include <asm/io.h>
6 #include <linux/bitops.h>
7 #include <mach/jz4780.h>
8
9 int jz47xx_gpio_get_value(unsigned int gpio)
10 {
11         void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
12         int port = gpio / 32;
13         int pin = gpio % 32;
14
15         return readl(gpio_regs + GPIO_PXPIN(port)) & BIT(pin);
16 }
17
18 void jz47xx_gpio_direction_input(unsigned int gpio)
19 {
20         void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
21         int port = gpio / 32;
22         int pin = gpio % 32;
23
24         writel(BIT(pin), gpio_regs + GPIO_PXINTC(port));
25         writel(BIT(pin), gpio_regs + GPIO_PXMASKS(port));
26         writel(BIT(pin), gpio_regs + GPIO_PXPAT1S(port));
27 }
28
29 void jz47xx_gpio_direction_output(unsigned int gpio, int value)
30 {
31         void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
32         int port = gpio / 32;
33         int pin = gpio % 32;
34
35         writel(BIT(pin), gpio_regs + GPIO_PXINTC(port));
36         writel(BIT(pin), gpio_regs + GPIO_PXMASKS(port));
37         writel(BIT(pin), gpio_regs + GPIO_PXPAT1C(port));
38         writel(BIT(pin), gpio_regs +
39                          (value ? GPIO_PXPAT0S(port) : GPIO_PXPAT0C(port)));
40 }