xref: /aosp_15_r20/external/coreboot/src/soc/amd/common/block/include/amdblocks/gpio.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef AMD_BLOCK_GPIO_BANKS_H
4 #define AMD_BLOCK_GPIO_BANKS_H
5 
6 #include <types.h>
7 #include <amdblocks/gpio_defs.h>
8 
9 typedef uint32_t gpio_t;
10 
11 struct soc_amd_gpio {
12 	gpio_t gpio;
13 	uint8_t function;
14 	uint32_t control;
15 	uint32_t flags;
16 };
17 
18 struct soc_amd_gpio_register_save {
19 	uint32_t control_value;
20 	uint8_t mux_value;
21 };
22 
23 struct soc_amd_event {
24 	gpio_t gpio;
25 	uint8_t event;
26 };
27 
28 struct gpio_wake_state {
29 	uint32_t control_switch;
30 	uint32_t wake_stat[2];
31 	/* Number of wake_gpio with a valid setting. */
32 	uint32_t num_valid_wake_gpios;
33 	/* GPIO index number that caused a wake. */
34 	gpio_t wake_gpios[16];
35 };
36 
37 /* Fill gpio_wake_state object for future event reporting. */
38 void gpio_fill_wake_state(struct gpio_wake_state *state);
39 /* Add gpio events to the eventlog. */
40 void gpio_add_events(void);
41 
is_gpio_event_level_triggered(uint32_t flags)42 static inline bool is_gpio_event_level_triggered(uint32_t flags)
43 {
44 	return (flags & GPIO_FLAG_EVENT_TRIGGER_MASK) == GPIO_FLAG_EVENT_TRIGGER_LEVEL;
45 }
46 
is_gpio_event_edge_triggered(uint32_t flags)47 static inline bool is_gpio_event_edge_triggered(uint32_t flags)
48 {
49 	return (flags & GPIO_FLAG_EVENT_TRIGGER_MASK) == GPIO_FLAG_EVENT_TRIGGER_EDGE;
50 }
51 
is_gpio_event_active_high(uint32_t flags)52 static inline bool is_gpio_event_active_high(uint32_t flags)
53 {
54 	return (flags & GPIO_FLAG_EVENT_ACTIVE_MASK) == GPIO_FLAG_EVENT_ACTIVE_HIGH;
55 }
56 
is_gpio_event_active_low(uint32_t flags)57 static inline bool is_gpio_event_active_low(uint32_t flags)
58 {
59 	return (flags & GPIO_FLAG_EVENT_ACTIVE_MASK) == GPIO_FLAG_EVENT_ACTIVE_LOW;
60 }
61 
62 /*
63  * gpio_configure_pads_with_override accepts as input two GPIO tables:
64  * 1. Base config
65  * 2. Override config
66  *
67  * This function configures raw pads in base config and applies override in
68  * override config if any. Thus, for every GPIO_x in base config, this function
69  * looks up the GPIO in override config and if it is present there, then applies
70  * the configuration from override config. GPIOs that are only specified in the
71  * override, but not in the base configuration, will be ignored.
72  */
73 void gpio_configure_pads_with_override(const struct soc_amd_gpio *base_cfg,
74 					size_t base_num_pads,
75 					const struct soc_amd_gpio *override_cfg,
76 					size_t override_num_pads);
77 
78 /**
79  * @brief program a particular set of GPIO
80  *
81  * @param gpio_list_ptr = pointer to array of gpio configurations
82  * @param size = number of entries in array
83  *
84  * @return none
85  */
86 void gpio_configure_pads(const struct soc_amd_gpio *gpio_list_ptr, size_t size);
87 /* Return the interrupt status and clear if set. */
88 int gpio_interrupt_status(gpio_t gpio);
89 /* Implemented by soc, provides table of available GPIO mapping to Gevents */
90 void soc_get_gpio_event_table(const struct soc_amd_event **table, size_t *items);
91 
92 void gpio_save_pin_registers(gpio_t gpio, struct soc_amd_gpio_register_save *save);
93 void gpio_restore_pin_registers(gpio_t gpio, struct soc_amd_gpio_register_save *save);
94 
95 /* Overrides Kconfig GPIO number */
96 gpio_t cr50_override_gpio(gpio_t irq);
97 
98 #endif /* AMD_BLOCK_GPIO_BANKS_H */
99