xref: /rk3399_ARM-atf/include/drivers/st/stm32_gpio.h (revision aba583498e36b166990da883dc8a8debb8eaf816)
1 /*
2  * Copyright (c) 2015-2024, STMicroelectronics - All Rights Reserved
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef STM32_GPIO_H
8 #define STM32_GPIO_H
9 
10 #include <lib/utils_def.h>
11 
12 #define GPIO_MODE_OFFSET	U(0x00)
13 #define GPIO_TYPE_OFFSET	U(0x04)
14 #define GPIO_SPEED_OFFSET	U(0x08)
15 #define GPIO_PUPD_OFFSET	U(0x0C)
16 #define GPIO_IDR_OFFSET		U(0x10)
17 #define GPIO_OD_OFFSET		U(0x14)
18 #define GPIO_BSRR_OFFSET	U(0x18)
19 #define GPIO_AFRL_OFFSET	U(0x20)
20 #define GPIO_AFRH_OFFSET	U(0x24)
21 #define GPIO_SECR_OFFSET	U(0x30)
22 
23 #define GPIO_ALT_LOWER_LIMIT	U(0x08)
24 
25 #define GPIO_PIN_(_x)		U(_x)
26 #define GPIO_PIN_MAX		GPIO_PIN_(15)
27 
28 #define GPIO_ALTERNATE_(_x)	U(_x)
29 #define GPIO_ALTERNATE_MASK	U(0x0F)
30 
31 #define GPIO_MODE_INPUT		U(0x00)
32 #define GPIO_MODE_OUTPUT	U(0x01)
33 #define GPIO_MODE_ALTERNATE	U(0x02)
34 #define GPIO_MODE_ANALOG	U(0x03)
35 #define GPIO_MODE_MASK		U(0x03)
36 
37 #define GPIO_TYPE_PUSH_PULL	U(0x00)
38 #define GPIO_TYPE_OPEN_DRAIN	U(0x01)
39 #define GPIO_TYPE_MASK		U(0x01)
40 
41 #define GPIO_SPEED_LOW		U(0x00)
42 #define GPIO_SPEED_MEDIUM	U(0x01)
43 #define GPIO_SPEED_HIGH		U(0x02)
44 #define GPIO_SPEED_VERY_HIGH	U(0x03)
45 #define GPIO_SPEED_MASK		U(0x03)
46 
47 #define GPIO_NO_PULL		U(0x00)
48 #define GPIO_PULL_UP		U(0x01)
49 #define GPIO_PULL_DOWN		U(0x02)
50 #define GPIO_PULL_MASK		U(0x03)
51 
52 #define GPIO_OD_OUTPUT_LOW	U(0x00)
53 #define GPIO_OD_OUTPUT_HIGH	U(0x01)
54 #define GPIO_OD_MASK		U(0x01)
55 
56 #ifndef __ASSEMBLER__
57 #include <stdint.h>
58 
59 int dt_set_pinctrl_config(int node);
60 void set_gpio_secure_cfg(uint32_t bank, uint32_t pin, bool secure);
61 void set_gpio_reset_cfg(uint32_t bank, uint32_t pin);
62 
63 enum gpio_level {
64 	GPIO_LEVEL_LOW,
65 	GPIO_LEVEL_HIGH
66 };
67 
68 void set_gpio_level(uint32_t bank, uint32_t pin, enum gpio_level level);
69 enum gpio_level get_gpio_level(uint32_t bank, uint32_t pin);
70 
71 void set_gpio_config(uint32_t bank, uint32_t pin, uint32_t config, uint8_t status);
72 #endif /*__ASSEMBLER__*/
73 
74 #endif /* STM32_GPIO_H */
75