]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arm/cpu/arm926ejs/nomadik/gpio.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / arm / cpu / arm926ejs / nomadik / gpio.c
CommitLineData
60cbfbfd
AR
1/*
2 * (C) Copyright 2009 Alessandro Rubini
3 *
1a459660 4 * SPDX-License-Identifier: GPL-2.0+
60cbfbfd
AR
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/gpio.h>
10
11static unsigned long gpio_base[4] = {
12 NOMADIK_GPIO0_BASE,
13 NOMADIK_GPIO1_BASE,
14 NOMADIK_GPIO2_BASE,
15 NOMADIK_GPIO3_BASE
16};
17
18enum gpio_registers {
19 GPIO_DAT = 0x00, /* data register */
20 GPIO_DATS = 0x04, /* data set */
21 GPIO_DATC = 0x08, /* data clear */
22 GPIO_PDIS = 0x0c, /* pull disable */
23 GPIO_DIR = 0x10, /* direction */
24 GPIO_DIRS = 0x14, /* direction set */
25 GPIO_DIRC = 0x18, /* direction clear */
26 GPIO_AFSLA = 0x20, /* alternate function select A */
27 GPIO_AFSLB = 0x24, /* alternate function select B */
28};
29
30static inline unsigned long gpio_to_base(int gpio)
31{
32 return gpio_base[gpio / 32];
33}
34
35static inline u32 gpio_to_bit(int gpio)
36{
37 return 1 << (gpio & 0x1f);
38}
39
40void nmk_gpio_af(int gpio, int alternate_function)
41{
42 unsigned long base = gpio_to_base(gpio);
43 u32 bit = gpio_to_bit(gpio);
44 u32 afunc, bfunc;
45
46 /* alternate function is 0..3, with one bit per register */
47 afunc = readl(base + GPIO_AFSLA) & ~bit;
48 bfunc = readl(base + GPIO_AFSLB) & ~bit;
49 if (alternate_function & 1) afunc |= bit;
50 if (alternate_function & 2) bfunc |= bit;
51 writel(afunc, base + GPIO_AFSLA);
52 writel(bfunc, base + GPIO_AFSLB);
53}
54
55void nmk_gpio_dir(int gpio, int dir)
56{
57 unsigned long base = gpio_to_base(gpio);
58 u32 bit = gpio_to_bit(gpio);
59
60 if (dir)
61 writel(bit, base + GPIO_DIRS);
62 else
63 writel(bit, base + GPIO_DIRC);
64}
65
66void nmk_gpio_set(int gpio, int val)
67{
68 unsigned long base = gpio_to_base(gpio);
69 u32 bit = gpio_to_bit(gpio);
70
71 if (val)
72 writel(bit, base + GPIO_DATS);
73 else
74 writel(bit, base + GPIO_DATC);
75}
76
77int nmk_gpio_get(int gpio)
78{
79 unsigned long base = gpio_to_base(gpio);
80 u32 bit = gpio_to_bit(gpio);
81
82 return readl(base + GPIO_DAT) & bit;
83}