blob: 6c4857d72379479705d83dc38e8a4224bafd5a36 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marshall Dawson251d3052019-05-02 17:27:57 -06002
Felix Held14e34322020-11-14 00:30:21 +01003#ifndef AMD_BLOCK_GPIO_BANKS_H
4#define AMD_BLOCK_GPIO_BANKS_H
Marshall Dawson251d3052019-05-02 17:27:57 -06005
Elyes HAOUAS553a22e2020-07-22 11:43:47 +02006#include <types.h>
Felix Held0a817eb2022-12-06 21:16:19 +01007#include <amdblocks/gpio_defs.h>
Marshall Dawson251d3052019-05-02 17:27:57 -06008
Felix Held298150d2021-07-28 17:36:46 +02009typedef uint32_t gpio_t;
10
Marshall Dawson251d3052019-05-02 17:27:57 -060011struct soc_amd_gpio {
Felix Held298150d2021-07-28 17:36:46 +020012 gpio_t gpio;
Marshall Dawson251d3052019-05-02 17:27:57 -060013 uint8_t function;
14 uint32_t control;
15 uint32_t flags;
16};
17
Felix Heldf363ad42021-07-31 03:59:28 +020018struct soc_amd_gpio_register_save {
19 uint32_t control_value;
20 uint8_t mux_value;
21};
22
Marshall Dawson251d3052019-05-02 17:27:57 -060023struct soc_amd_event {
Felix Held298150d2021-07-28 17:36:46 +020024 gpio_t gpio;
Marshall Dawson251d3052019-05-02 17:27:57 -060025 uint8_t event;
26};
27
Aaron Durbine05f4dc2020-08-17 16:22:09 -060028struct 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 Held298150d2021-07-28 17:36:46 +020034 gpio_t wake_gpios[16];
Aaron Durbine05f4dc2020-08-17 16:22:09 -060035};
36
37/* Fill gpio_wake_state object for future event reporting. */
38void gpio_fill_wake_state(struct gpio_wake_state *state);
39/* Add gpio events to the eventlog. */
Kyösti Mälkkib0db8132021-01-21 16:34:43 +020040void gpio_add_events(void);
Marshall Dawson251d3052019-05-02 17:27:57 -060041
Furquan Shaikhaf8123c2020-06-26 18:55:17 -070042static 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
47static 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
52static 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
57static 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 Wang712311f2020-04-18 08:25:53 +080062/*
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 Held05df6ec2021-09-22 16:01:36 +020070 * the configuration from override config. GPIOs that are only specified in the
71 * override, but not in the base configuration, will be ignored.
Peichao Wang712311f2020-04-18 08:25:53 +080072 */
73void 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 Dawson251d3052019-05-02 17:27:57 -060078/**
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 Held7011fa12021-09-22 16:36:12 +020086void gpio_configure_pads(const struct soc_amd_gpio *gpio_list_ptr, size_t size);
Marshall Dawson251d3052019-05-02 17:27:57 -060087/* Return the interrupt status and clear if set. */
88int gpio_interrupt_status(gpio_t gpio);
Elyes HAOUASe9f86c12020-02-18 19:00:32 +010089/* Implemented by soc, provides table of available GPIO mapping to Gevents */
Marshall Dawson251d3052019-05-02 17:27:57 -060090void soc_get_gpio_event_table(const struct soc_amd_event **table, size_t *items);
Marshall Dawson251d3052019-05-02 17:27:57 -060091
Felix Held35cee382021-08-03 02:55:34 +020092void gpio_save_pin_registers(gpio_t gpio, struct soc_amd_gpio_register_save *save);
93void gpio_restore_pin_registers(gpio_t gpio, struct soc_amd_gpio_register_save *save);
94
Grzegorz Bernackia0bd3e92023-05-29 11:53:38 +000095/* Overrides Kconfig GPIO number */
96gpio_t cr50_override_gpio(gpio_t irq);
97
Felix Held14e34322020-11-14 00:30:21 +010098#endif /* AMD_BLOCK_GPIO_BANKS_H */