1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2021 NXP
4  *
5  * Helper Code for GPIO controller driver
6  *
7  */
8 
9 #ifndef __DRIVERS_LS_GPIO_H
10 #define __DRIVERS_LS_GPIO_H
11 
12 #include <gpio.h>
13 #include <stdlib.h>
14 #include <tee_api_types.h>
15 #include <util.h>
16 
17 /* supported ports for GPIO controller */
18 #define MAX_GPIO_PINS U(31)
19 
20 /* map register values to LE by subtracting pin number from MAX GPIO PINS */
21 #define PIN_SHIFT(x) BIT(MAX_GPIO_PINS - (x))
22 
23 /* gpio register offsets */
24 #define GPIODIR U(0x0)  /* direction register */
25 #define GPIOODR U(0x4)  /* open drain register */
26 #define GPIODAT U(0x8)  /* data register */
27 #define GPIOIER U(0xc)  /* interrupt event register */
28 #define GPIOIMR U(0x10) /* interrupt mask register */
29 #define GPIOICR U(0x14) /* interrupt control register */
30 #define GPIOIBE U(0x18) /* input buffer enable register */
31 
32 /*
33  * struct ls_gpio_chip_data describes GPIO controller chip instance
34  * The structure contains below members:
35  * chip:		generic GPIO chip handle.
36  * gpio_base:		starting GPIO module base address managed by this GPIO
37  *			controller.
38  * gpio_controller:	GPIO controller to be used.
39  */
40 struct ls_gpio_chip_data {
41 	struct gpio_chip chip;
42 	vaddr_t gpio_base;
43 	uint8_t gpio_controller;
44 };
45 
46 /*
47  * Initialize GPIO Controller
48  * gpio_data is a pointer of type 'struct ls_gpio_chip_data'.
49  */
50 TEE_Result ls_gpio_init(struct ls_gpio_chip_data *gpio_data);
51 
52 #endif /* __DRIVERS_LS_GPIO_H */
53