1 /*
2  * Copyright (c) 2015 Brian Swetland
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 
9 #include <lk/reg.h>
10 #include <platform/lpc43xx-gpio.h>
11 
gpio_config(unsigned nr,unsigned flags)12 inline int gpio_config(unsigned nr, unsigned flags) {
13     unsigned m = _GPIOm(nr);
14     unsigned n = _GPIOn(nr);
15     if (flags & GPIO_INPUT) {
16         writel(readl(GPIO_DIR(m)) & (~(1 << n)), GPIO_DIR(m));
17     } else {
18         writel(readl(GPIO_DIR(m)) | (1 << n), GPIO_DIR(m));
19     }
20     return 0;
21 }
22 
gpio_set(unsigned nr,unsigned on)23 inline void gpio_set(unsigned nr, unsigned on) {
24     writel(on, GPIO_WORD(nr));
25 }
26 
gpio_get(unsigned nr)27 inline int gpio_get(unsigned nr) {
28     return readl(GPIO_WORD(nr)) & 1;
29 }
30