blob: 22b7fa9126dc0328dfe055fa65f5bfdaa34609cf [file] [log] [blame]
Gabe Black08d5a892013-10-03 04:35:01 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Gabe Black08d5a892013-10-03 04:35:01 -070014 */
15
16#ifndef __SOC_NVIDIA_TEGRA_GPIO_H__
17#define __SOC_NVIDIA_TEGRA_GPIO_H__
18
19#include <stdint.h>
20
Gabe Blackd40be112013-10-09 23:45:07 -070021#include "pinmux.h"
Gabe Black08d5a892013-10-03 04:35:01 -070022
Julius Wernereaa9c452014-09-24 15:40:49 -070023typedef u32 gpio_t;
24
Gabe Blackd40be112013-10-09 23:45:07 -070025#define GPIO_PINMUX_SHIFT 16
26#define GPIO(name) ((gpio_t)(GPIO_##name##_INDEX | \
27 (PINMUX_GPIO_##name << GPIO_PINMUX_SHIFT)))
28
Gabe Black08d5a892013-10-03 04:35:01 -070029/* Functions to modify specific GPIO control values. */
30
31enum gpio_mode {
32 GPIO_MODE_SPIO = 0,
33 GPIO_MODE_GPIO = 1
34};
Gabe Blackd40be112013-10-09 23:45:07 -070035void gpio_set_mode(gpio_t gpio, enum gpio_mode);
36int gpio_get_mode(gpio_t gpio);
Gabe Black08d5a892013-10-03 04:35:01 -070037
38// Lock a GPIO with extreme caution since they can't be unlocked.
Gabe Blackd40be112013-10-09 23:45:07 -070039void gpio_set_lock(gpio_t gpio);
40int gpio_get_lock(gpio_t gpio);
Gabe Black08d5a892013-10-03 04:35:01 -070041
Gabe Blackd40be112013-10-09 23:45:07 -070042void gpio_set_out_enable(gpio_t gpio, int enable);
43int gpio_get_out_enable(gpio_t gpio);
Gabe Black08d5a892013-10-03 04:35:01 -070044
Gabe Blackd40be112013-10-09 23:45:07 -070045int gpio_get_out_value(gpio_t gpio);
Gabe Black08d5a892013-10-03 04:35:01 -070046
Gabe Blackd40be112013-10-09 23:45:07 -070047int gpio_get_int_status(gpio_t gpio);
Gabe Black08d5a892013-10-03 04:35:01 -070048
Gabe Blackd40be112013-10-09 23:45:07 -070049void gpio_set_int_enable(gpio_t gpio, int enable);
50int gpio_get_int_enable(gpio_t gpio);
Gabe Black08d5a892013-10-03 04:35:01 -070051
Gabe Blackd40be112013-10-09 23:45:07 -070052void gpio_set_int_level(gpio_t gpio, int high_rise, int edge, int delta);
53void gpio_get_int_level(gpio_t gpio, int *high_rise, int *edge, int *delta);
Gabe Black08d5a892013-10-03 04:35:01 -070054
Gabe Blackd40be112013-10-09 23:45:07 -070055void gpio_set_int_clear(gpio_t gpio);
Gabe Black08d5a892013-10-03 04:35:01 -070056
Julius Wernereaa9c452014-09-24 15:40:49 -070057void gpio_output_open_drain(gpio_t gpio, int value);
58
Aaron Durbin401b3b62014-07-31 14:54:12 -050059/* Hardware definitions. */
60
61enum {
62 GPIO_GPIOS_PER_PORT = 8,
63 GPIO_PORTS_PER_BANK = 4,
64 GPIO_BANKS = 8,
65
66 GPIO_GPIOS_PER_BANK = GPIO_GPIOS_PER_PORT * GPIO_PORTS_PER_BANK,
67 GPIO_GPIOS = GPIO_BANKS * GPIO_GPIOS_PER_BANK
68};
69
70static inline int gpio_index_to_bank(int index)
71{
72 return index / GPIO_GPIOS_PER_BANK;
73}
74
75static inline int gpio_index_to_port(int index)
76{
Aaron Durbin2f3a7fb2014-08-04 15:40:50 -050077 return (index % GPIO_GPIOS_PER_BANK) / GPIO_GPIOS_PER_PORT;
Aaron Durbin401b3b62014-07-31 14:54:12 -050078}
79
80static inline int gpio_to_bit(int index)
81{
82 return index % GPIO_GPIOS_PER_PORT;
83}
84
85struct gpio_bank {
86 // Values
87 u32 config[GPIO_PORTS_PER_BANK];
88 u32 out_enable[GPIO_PORTS_PER_BANK];
89 u32 out_value[GPIO_PORTS_PER_BANK];
90 u32 in_value[GPIO_PORTS_PER_BANK];
91 u32 int_status[GPIO_PORTS_PER_BANK];
92 u32 int_enable[GPIO_PORTS_PER_BANK];
93 u32 int_level[GPIO_PORTS_PER_BANK];
94 u32 int_clear[GPIO_PORTS_PER_BANK];
95
96 // Masks
97 u32 config_mask[GPIO_PORTS_PER_BANK];
98 u32 out_enable_mask[GPIO_PORTS_PER_BANK];
99 u32 out_value_mask[GPIO_PORTS_PER_BANK];
100 u32 in_value_mask[GPIO_PORTS_PER_BANK];
101 u32 int_status_mask[GPIO_PORTS_PER_BANK];
102 u32 int_enable_mask[GPIO_PORTS_PER_BANK];
103 u32 int_level_mask[GPIO_PORTS_PER_BANK];
104 u32 int_clear_mask[GPIO_PORTS_PER_BANK];
105};
106
Gabe Black08d5a892013-10-03 04:35:01 -0700107#endif /* __SOC_NVIDIA_TEGRA_GPIO_H__ */