blob: b026f78ca50785a198e68295496093d1ab67a06b [file] [log] [blame]
Ian Campbellfe1b4db2014-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
Simon Glassbf388912014-10-30 20:25:47 -060013void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val)
Ian Campbellfe1b4db2014-05-05 11:52:24 +010014{
Simon Glassbf388912014-10-30 20:25:47 -060015 u32 index = GPIO_CFG_INDEX(bank_offset);
16 u32 offset = GPIO_CFG_OFFSET(bank_offset);
Ian Campbellfe1b4db2014-05-05 11:52:24 +010017
18 clrsetbits_le32(&pio->cfg[0] + index, 0xf << offset, val << offset);
Ian Campbellfe1b4db2014-05-05 11:52:24 +010019}
20
Simon Glassbf388912014-10-30 20:25:47 -060021void sunxi_gpio_set_cfgpin(u32 pin, u32 val)
Ian Campbellfe1b4db2014-05-05 11:52:24 +010022{
Ian Campbellfe1b4db2014-05-05 11:52:24 +010023 u32 bank = GPIO_BANK(pin);
Ian Campbellfe1b4db2014-05-05 11:52:24 +010024 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
25
Simon Glassbf388912014-10-30 20:25:47 -060026 sunxi_gpio_set_cfgbank(pio, pin, val);
27}
28
29int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset)
30{
31 u32 index = GPIO_CFG_INDEX(bank_offset);
32 u32 offset = GPIO_CFG_OFFSET(bank_offset);
33 u32 cfg;
34
Ian Campbellfe1b4db2014-05-05 11:52:24 +010035 cfg = readl(&pio->cfg[0] + index);
36 cfg >>= offset;
37
38 return cfg & 0xf;
39}
40
Simon Glassbf388912014-10-30 20:25:47 -060041int sunxi_gpio_get_cfgpin(u32 pin)
42{
43 u32 bank = GPIO_BANK(pin);
44 struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
45
46 return sunxi_gpio_get_cfgbank(pio, pin);
47}
48
Ian Campbellfe1b4db2014-05-05 11:52:24 +010049int sunxi_gpio_set_drv(u32 pin, u32 val)
50{
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);
55
56 clrsetbits_le32(&pio->drv[0] + index, 0x3 << offset, val << offset);
57
58 return 0;
59}
60
61int sunxi_gpio_set_pull(u32 pin, u32 val)
62{
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);
67
68 clrsetbits_le32(&pio->pull[0] + index, 0x3 << offset, val << offset);
69
70 return 0;
71}