1*cd71b1d5SPaul Burton // SPDX-License-Identifier: GPL-2.0+ 2*cd71b1d5SPaul Burton 3*cd71b1d5SPaul Burton #include <config.h> 4*cd71b1d5SPaul Burton #include <common.h> 5*cd71b1d5SPaul Burton #include <asm/io.h> 6*cd71b1d5SPaul Burton #include <mach/jz4780.h> 7*cd71b1d5SPaul Burton jz47xx_gpio_get_value(unsigned int gpio)8*cd71b1d5SPaul Burtonint jz47xx_gpio_get_value(unsigned int gpio) 9*cd71b1d5SPaul Burton { 10*cd71b1d5SPaul Burton void __iomem *gpio_regs = (void __iomem *)GPIO_BASE; 11*cd71b1d5SPaul Burton int port = gpio / 32; 12*cd71b1d5SPaul Burton int pin = gpio % 32; 13*cd71b1d5SPaul Burton 14*cd71b1d5SPaul Burton return readl(gpio_regs + GPIO_PXPIN(port)) & BIT(pin); 15*cd71b1d5SPaul Burton } 16*cd71b1d5SPaul Burton jz47xx_gpio_direction_input(unsigned int gpio)17*cd71b1d5SPaul Burtonvoid jz47xx_gpio_direction_input(unsigned int gpio) 18*cd71b1d5SPaul Burton { 19*cd71b1d5SPaul Burton void __iomem *gpio_regs = (void __iomem *)GPIO_BASE; 20*cd71b1d5SPaul Burton int port = gpio / 32; 21*cd71b1d5SPaul Burton int pin = gpio % 32; 22*cd71b1d5SPaul Burton 23*cd71b1d5SPaul Burton writel(BIT(pin), gpio_regs + GPIO_PXINTC(port)); 24*cd71b1d5SPaul Burton writel(BIT(pin), gpio_regs + GPIO_PXMASKS(port)); 25*cd71b1d5SPaul Burton writel(BIT(pin), gpio_regs + GPIO_PXPAT1S(port)); 26*cd71b1d5SPaul Burton } 27*cd71b1d5SPaul Burton jz47xx_gpio_direction_output(unsigned int gpio,int value)28*cd71b1d5SPaul Burtonvoid jz47xx_gpio_direction_output(unsigned int gpio, int value) 29*cd71b1d5SPaul Burton { 30*cd71b1d5SPaul Burton void __iomem *gpio_regs = (void __iomem *)GPIO_BASE; 31*cd71b1d5SPaul Burton int port = gpio / 32; 32*cd71b1d5SPaul Burton int pin = gpio % 32; 33*cd71b1d5SPaul Burton 34*cd71b1d5SPaul Burton writel(BIT(pin), gpio_regs + GPIO_PXINTC(port)); 35*cd71b1d5SPaul Burton writel(BIT(pin), gpio_regs + GPIO_PXMASKS(port)); 36*cd71b1d5SPaul Burton writel(BIT(pin), gpio_regs + GPIO_PXPAT1C(port)); 37*cd71b1d5SPaul Burton writel(BIT(pin), gpio_regs + 38*cd71b1d5SPaul Burton (value ? GPIO_PXPAT0S(port) : GPIO_PXPAT0C(port))); 39*cd71b1d5SPaul Burton } 40