Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 2 | |
Felix Held | 14e3432 | 2020-11-14 00:30:21 +0100 | [diff] [blame] | 3 | #ifndef AMD_BLOCK_GPIO_BANKS_H |
| 4 | #define AMD_BLOCK_GPIO_BANKS_H |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 5 | |
Elyes HAOUAS | 553a22e | 2020-07-22 11:43:47 +0200 | [diff] [blame] | 6 | #include <types.h> |
Felix Held | 0a817eb | 2022-12-06 21:16:19 +0100 | [diff] [blame] | 7 | #include <amdblocks/gpio_defs.h> |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 8 | |
Felix Held | 298150d | 2021-07-28 17:36:46 +0200 | [diff] [blame] | 9 | typedef uint32_t gpio_t; |
| 10 | |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 11 | struct soc_amd_gpio { |
Felix Held | 298150d | 2021-07-28 17:36:46 +0200 | [diff] [blame] | 12 | gpio_t gpio; |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 13 | uint8_t function; |
| 14 | uint32_t control; |
| 15 | uint32_t flags; |
| 16 | }; |
| 17 | |
Felix Held | f363ad4 | 2021-07-31 03:59:28 +0200 | [diff] [blame] | 18 | struct soc_amd_gpio_register_save { |
| 19 | uint32_t control_value; |
| 20 | uint8_t mux_value; |
| 21 | }; |
| 22 | |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 23 | struct soc_amd_event { |
Felix Held | 298150d | 2021-07-28 17:36:46 +0200 | [diff] [blame] | 24 | gpio_t gpio; |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 25 | uint8_t event; |
| 26 | }; |
| 27 | |
Aaron Durbin | e05f4dc | 2020-08-17 16:22:09 -0600 | [diff] [blame] | 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. */ |
Felix Held | 298150d | 2021-07-28 17:36:46 +0200 | [diff] [blame] | 34 | gpio_t wake_gpios[16]; |
Aaron Durbin | e05f4dc | 2020-08-17 16:22:09 -0600 | [diff] [blame] | 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. */ |
Kyösti Mälkki | b0db813 | 2021-01-21 16:34:43 +0200 | [diff] [blame] | 40 | void gpio_add_events(void); |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 41 | |
Furquan Shaikh | af8123c | 2020-06-26 18:55:17 -0700 | [diff] [blame] | 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 | |
| 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 | |
| 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 | |
| 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 | |
Peichao Wang | 712311f | 2020-04-18 08:25:53 +0800 | [diff] [blame] | 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 |
Felix Held | 05df6ec | 2021-09-22 16:01:36 +0200 | [diff] [blame] | 70 | * the configuration from override config. GPIOs that are only specified in the |
| 71 | * override, but not in the base configuration, will be ignored. |
Peichao Wang | 712311f | 2020-04-18 08:25:53 +0800 | [diff] [blame] | 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 | |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 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 | */ |
Felix Held | 7011fa1 | 2021-09-22 16:36:12 +0200 | [diff] [blame] | 86 | void gpio_configure_pads(const struct soc_amd_gpio *gpio_list_ptr, size_t size); |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 87 | /* Return the interrupt status and clear if set. */ |
| 88 | int gpio_interrupt_status(gpio_t gpio); |
Elyes HAOUAS | e9f86c1 | 2020-02-18 19:00:32 +0100 | [diff] [blame] | 89 | /* Implemented by soc, provides table of available GPIO mapping to Gevents */ |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 90 | void soc_get_gpio_event_table(const struct soc_amd_event **table, size_t *items); |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 91 | |
Felix Held | 35cee38 | 2021-08-03 02:55:34 +0200 | [diff] [blame] | 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 | |
Grzegorz Bernacki | a0bd3e9 | 2023-05-29 11:53:38 +0000 | [diff] [blame^] | 95 | /* Overrides Kconfig GPIO number */ |
| 96 | gpio_t cr50_override_gpio(gpio_t irq); |
| 97 | |
Felix Held | 14e3432 | 2020-11-14 00:30:21 +0100 | [diff] [blame] | 98 | #endif /* AMD_BLOCK_GPIO_BANKS_H */ |