blob: 1f2843fcac4577ebcfa45212b27c9238399e7347 [file] [log] [blame]
Ian Campbellb2765ec2014-05-05 11:52:24 +01001/*
2 * (C) Copyright 2007-2011
3 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
4 * Tom Cubie <tangliang@allwinnertech.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <asm/io.h>
11#include <asm/arch/gpio.h>
12
13int sunxi_gpio_set_cfgpin(u32 pin, u32 val)
14{
15 u32 bank = GPIO_BANK(pin);
16 u32 index = GPIO_CFG_INDEX(pin);
17 u32 offset = GPIO_CFG_OFFSET(pin);
18 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
19
20 clrsetbits_le32(&pio->cfg[0] + index, 0xf << offset, val << offset);
21
22 return 0;
23}
24
25int sunxi_gpio_get_cfgpin(u32 pin)
26{
27 u32 cfg;
28 u32 bank = GPIO_BANK(pin);
29 u32 index = GPIO_CFG_INDEX(pin);
30 u32 offset = GPIO_CFG_OFFSET(pin);
31 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
32
33 cfg = readl(&pio->cfg[0] + index);
34 cfg >>= offset;
35
36 return cfg & 0xf;
37}
38
39int sunxi_gpio_set_drv(u32 pin, u32 val)
40{
41 u32 bank = GPIO_BANK(pin);
42 u32 index = GPIO_DRV_INDEX(pin);
43 u32 offset = GPIO_DRV_OFFSET(pin);
44 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
45
46 clrsetbits_le32(&pio->drv[0] + index, 0x3 << offset, val << offset);
47
48 return 0;
49}
50
51int sunxi_gpio_set_pull(u32 pin, u32 val)
52{
53 u32 bank = GPIO_BANK(pin);
54 u32 index = GPIO_PULL_INDEX(pin);
55 u32 offset = GPIO_PULL_OFFSET(pin);
56 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
57
58 clrsetbits_le32(&pio->pull[0] + index, 0x3 << offset, val << offset);
59
60 return 0;
61}