blob: df758404ca2d11b88786b1feabb38a09938890c9 [file] [log] [blame]
Pankaj Guptab4806422020-12-09 14:02:39 +05301/*
2 * Copyright 2021 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef PLAT_GPIO_H
9#define PLAT_GPIO_H
10
11#include <endian.h>
12#include <lib/mmio.h>
13
14/* GPIO Register offset */
15#define GPIO_SEL_MASK 0x7F
16#define GPIO_BIT_MASK 0x1F
17#define GPDIR_REG_OFFSET 0x0
18#define GPDAT_REG_OFFSET 0x8
19
20#define GPIO_ID_BASE_ADDR_SHIFT 5U
21#define GPIO_BITS_PER_BASE_REG 32U
22
23#define GPIO_0 0
24#define GPIO_1 1
25#define GPIO_2 2
26#define GPIO_3 3
27
28#define GPIO_SUCCESS 0x0
29#define GPIO_FAILURE 0x1
30
31#ifdef NXP_GPIO_BE
32#define gpio_read32(a) bswap32(mmio_read_32((uintptr_t)(a)))
33#define gpio_write32(a, v) mmio_write_32((uintptr_t)(a), bswap32(v))
34#elif defined(NXP_GPIO_LE)
35#define gpio_read32(a) mmio_read_32((uintptr_t)(a))
36#define gpio_write32(a, v) mmio_write_32((uintptr_t)(a), (v))
37#else
38#error Please define GPIO register endianness
39#endif
40
41typedef struct {
42 uintptr_t gpio1_base_addr;
43 uintptr_t gpio2_base_addr;
44 uintptr_t gpio3_base_addr;
45 uintptr_t gpio4_base_addr;
46} gpio_init_info_t;
47
48void gpio_init(gpio_init_info_t *gpio_init_data);
49uint32_t *select_gpio_n_bitnum(uint32_t povdd_gpio, uint32_t *bit_num);
50int clr_gpio_bit(uint32_t *gpio_base_addr, uint32_t bit_num);
51int set_gpio_bit(uint32_t *gpio_base_addr, uint32_t bit_num);
52
53#endif /* PLAT_GPIO_H */