blob: d4884e7fa9f11657ac190e68925cf5f9aa1267d0 [file] [log] [blame]
Paul Burton96c68472018-12-16 19:25:22 -03001// SPDX-License-Identifier: GPL-2.0+
2
3#include <config.h>
4#include <common.h>
5#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -06006#include <linux/bitops.h>
Paul Burton96c68472018-12-16 19:25:22 -03007#include <mach/jz4780.h>
8
9int 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
18void 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
29void 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}