2 * (C) Copyright 2007-2011
3 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
4 * Tom Cubie <tangliang@allwinnertech.com>
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/arch/gpio.h>
13 void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val)
15 u32 index = GPIO_CFG_INDEX(bank_offset);
16 u32 offset = GPIO_CFG_OFFSET(bank_offset);
18 clrsetbits_le32(&pio->cfg[0] + index, 0xf << offset, val << offset);
21 void sunxi_gpio_set_cfgpin(u32 pin, u32 val)
23 u32 bank = GPIO_BANK(pin);
24 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
26 sunxi_gpio_set_cfgbank(pio, pin, val);
29 int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset)
31 u32 index = GPIO_CFG_INDEX(bank_offset);
32 u32 offset = GPIO_CFG_OFFSET(bank_offset);
35 cfg = readl(&pio->cfg[0] + index);
41 int sunxi_gpio_get_cfgpin(u32 pin)
43 u32 bank = GPIO_BANK(pin);
44 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
46 return sunxi_gpio_get_cfgbank(pio, pin);
49 int sunxi_gpio_set_drv(u32 pin, u32 val)
51 u32 bank = GPIO_BANK(pin);
52 u32 index = GPIO_DRV_INDEX(pin);
53 u32 offset = GPIO_DRV_OFFSET(pin);
54 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
56 clrsetbits_le32(&pio->drv[0] + index, 0x3 << offset, val << offset);
61 int sunxi_gpio_set_pull(u32 pin, u32 val)
63 u32 bank = GPIO_BANK(pin);
64 u32 index = GPIO_PULL_INDEX(pin);
65 u32 offset = GPIO_PULL_OFFSET(pin);
66 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
68 clrsetbits_le32(&pio->pull[0] + index, 0x3 << offset, val << offset);