tegra: Turn GPIO wrappers into macros to make them easier to write
The GPIO wrappers are already pretty nice, but you still end up writing everything twice since you need to specify the pinmux register: gpio_output(GPIO_Q2, PINMUX_GPIO_Q2, 1); Calculating the pinmux index from the GPIO isn't easy, but luckily the enums use a similar naming scheme. This patch changes the wrapper functions to macros that generate the corresponding pinmux name automatically. BUG=None TEST=Made sure code with GPIO macros compiles, twiddled some output GPIOs to confirm that they work. Change-Id: Id23855c5aec5f87b4201f22bac32503e72f83392 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/172731 Reviewed-by: Ronald Minnich <rminnich@chromium.org>
This commit is contained in:
parent
61bedbf0f8
commit
94550fdfa5
3 changed files with 17 additions and 22 deletions
|
|
@ -26,7 +26,7 @@
|
|||
#include "gpio.h"
|
||||
#include "pinmux.h"
|
||||
|
||||
static void gpio_input_common(int gpio_index, int pinmux_index, u32 pull)
|
||||
void __gpio_input(int gpio_index, int pinmux_index, u32 pull)
|
||||
{
|
||||
u32 pinmux_config = PINMUX_INPUT_ENABLE | PINMUX_TRISTATE | pull;
|
||||
|
||||
|
|
@ -36,22 +36,7 @@ static void gpio_input_common(int gpio_index, int pinmux_index, u32 pull)
|
|||
pinmux_set_config(pinmux_index, pinmux_config);
|
||||
}
|
||||
|
||||
void gpio_input(int gpio_index, int pinmux_index)
|
||||
{
|
||||
gpio_input_common(gpio_index, pinmux_index, PINMUX_PULL_NONE);
|
||||
}
|
||||
|
||||
void gpio_input_pullup(int gpio_index, int pinmux_index)
|
||||
{
|
||||
gpio_input_common(gpio_index, pinmux_index, PINMUX_PULL_UP);
|
||||
}
|
||||
|
||||
void gpio_input_pulldown(int gpio_index, int pinmux_index)
|
||||
{
|
||||
gpio_input_common(gpio_index, pinmux_index, PINMUX_PULL_DOWN);
|
||||
}
|
||||
|
||||
void gpio_output(int gpio_index, int pinmux_index, int value)
|
||||
void __gpio_output(int gpio_index, int pinmux_index, int value)
|
||||
{
|
||||
/* TODO: Set OPEN_DRAIN based on what pin it is? */
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,20 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Higher level functions for common GPIO configurations. */
|
||||
/* Higher level function wrappers for common GPIO configurations. */
|
||||
|
||||
void gpio_input(int gpio_index, int pinmux_index);
|
||||
void gpio_input_pullup(int gpio_index, int pinmux_index);
|
||||
void gpio_input_pulldown(int gpio_index, int pinmux_index);
|
||||
void gpio_output(int gpio_index, int pinmux_index, int value);
|
||||
#define gpio_input(gpio_enum) __gpio_input(gpio_enum, \
|
||||
PINMUX_##gpio_enum, PINMUX_PULL_NONE)
|
||||
#define gpio_input_pulldown(gpio_enum) __gpio_input(gpio_enum, \
|
||||
PINMUX_##gpio_enum, PINMUX_PULL_DOWN)
|
||||
#define gpio_input_pullup(gpio_enum) __gpio_input(gpio_enum, \
|
||||
PINMUX_##gpio_enum, PINMUX_PULL_UP)
|
||||
|
||||
#define gpio_output(gpio_enum, value) __gpio_output(gpio_enum, \
|
||||
PINMUX_##gpio_enum, value)
|
||||
|
||||
void __gpio_input(int gpio_index, int pinmux_index, u32 pull);
|
||||
void __gpio_output(int gpio_index, int pinmux_index, int value);
|
||||
|
||||
/* Functions to modify specific GPIO control values. */
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
#include <soc/nvidia/tegra/gpio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "pinmux.h" /* for pinmux constants in GPIO macros */
|
||||
|
||||
/* GPIO index constants. */
|
||||
|
||||
#define GPIO_PORT_CONSTANTS(port) \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue