aboutsummaryrefslogtreecommitdiff
path: root/src/soc/nvidia/tegra
diff options
context:
space:
mode:
Diffstat (limited to 'src/soc/nvidia/tegra')
-rw-r--r--src/soc/nvidia/tegra/gpio.c31
-rw-r--r--src/soc/nvidia/tegra/gpio.h48
2 files changed, 48 insertions, 31 deletions
diff --git a/src/soc/nvidia/tegra/gpio.c b/src/soc/nvidia/tegra/gpio.c
index 17b90aa1d9..9f09f24547 100644
--- a/src/soc/nvidia/tegra/gpio.c
+++ b/src/soc/nvidia/tegra/gpio.c
@@ -47,37 +47,6 @@ void __gpio_output(gpio_t gpio, int value, u32 od)
pinmux_set_config(gpio >> GPIO_PINMUX_SHIFT, PINMUX_PULL_NONE | od);
}
-enum {
- GPIO_GPIOS_PER_PORT = 8,
- GPIO_PORTS_PER_BANK = 4,
- GPIO_BANKS = 8,
-
- GPIO_GPIOS_PER_BANK = GPIO_GPIOS_PER_PORT * GPIO_PORTS_PER_BANK,
- GPIO_GPIOS = GPIO_BANKS * GPIO_GPIOS_PER_BANK
-};
-
-struct gpio_bank {
- // Values
- u32 config[GPIO_PORTS_PER_BANK];
- u32 out_enable[GPIO_PORTS_PER_BANK];
- u32 out_value[GPIO_PORTS_PER_BANK];
- u32 in_value[GPIO_PORTS_PER_BANK];
- u32 int_status[GPIO_PORTS_PER_BANK];
- u32 int_enable[GPIO_PORTS_PER_BANK];
- u32 int_level[GPIO_PORTS_PER_BANK];
- u32 int_clear[GPIO_PORTS_PER_BANK];
-
- // Masks
- u32 config_mask[GPIO_PORTS_PER_BANK];
- u32 out_enable_mask[GPIO_PORTS_PER_BANK];
- u32 out_value_mask[GPIO_PORTS_PER_BANK];
- u32 in_value_mask[GPIO_PORTS_PER_BANK];
- u32 int_status_mask[GPIO_PORTS_PER_BANK];
- u32 int_enable_mask[GPIO_PORTS_PER_BANK];
- u32 int_level_mask[GPIO_PORTS_PER_BANK];
- u32 int_clear_mask[GPIO_PORTS_PER_BANK];
-};
-
static const struct gpio_bank *gpio_banks = (void *)TEGRA_GPIO_BASE;
static u32 gpio_read_port(int index, size_t offset)
diff --git a/src/soc/nvidia/tegra/gpio.h b/src/soc/nvidia/tegra/gpio.h
index 43f898958e..da8a4dad71 100644
--- a/src/soc/nvidia/tegra/gpio.h
+++ b/src/soc/nvidia/tegra/gpio.h
@@ -72,4 +72,52 @@ void gpio_get_int_level(gpio_t gpio, int *high_rise, int *edge, int *delta);
void gpio_set_int_clear(gpio_t gpio);
+/* Hardware definitions. */
+
+enum {
+ GPIO_GPIOS_PER_PORT = 8,
+ GPIO_PORTS_PER_BANK = 4,
+ GPIO_BANKS = 8,
+
+ GPIO_GPIOS_PER_BANK = GPIO_GPIOS_PER_PORT * GPIO_PORTS_PER_BANK,
+ GPIO_GPIOS = GPIO_BANKS * GPIO_GPIOS_PER_BANK
+};
+
+static inline int gpio_index_to_bank(int index)
+{
+ return index / GPIO_GPIOS_PER_BANK;
+}
+
+static inline int gpio_index_to_port(int index)
+{
+ return (index % GPIO_GPIOS_PER_BANK) / GPIO_PORTS_PER_BANK;
+}
+
+static inline int gpio_to_bit(int index)
+{
+ return index % GPIO_GPIOS_PER_PORT;
+}
+
+struct gpio_bank {
+ // Values
+ u32 config[GPIO_PORTS_PER_BANK];
+ u32 out_enable[GPIO_PORTS_PER_BANK];
+ u32 out_value[GPIO_PORTS_PER_BANK];
+ u32 in_value[GPIO_PORTS_PER_BANK];
+ u32 int_status[GPIO_PORTS_PER_BANK];
+ u32 int_enable[GPIO_PORTS_PER_BANK];
+ u32 int_level[GPIO_PORTS_PER_BANK];
+ u32 int_clear[GPIO_PORTS_PER_BANK];
+
+ // Masks
+ u32 config_mask[GPIO_PORTS_PER_BANK];
+ u32 out_enable_mask[GPIO_PORTS_PER_BANK];
+ u32 out_value_mask[GPIO_PORTS_PER_BANK];
+ u32 in_value_mask[GPIO_PORTS_PER_BANK];
+ u32 int_status_mask[GPIO_PORTS_PER_BANK];
+ u32 int_enable_mask[GPIO_PORTS_PER_BANK];
+ u32 int_level_mask[GPIO_PORTS_PER_BANK];
+ u32 int_clear_mask[GPIO_PORTS_PER_BANK];
+};
+
#endif /* __SOC_NVIDIA_TEGRA_GPIO_H__ */