mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-11 07:24:46 +00:00
drivers: tegra_gpio: add early SPL functions
In some cases access to GPIOs is needed so early that DM is not ready even nearly. These functions are exactly for this case. Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
This commit is contained in:
parent
d7c98f2030
commit
2ff444d07d
2 changed files with 69 additions and 0 deletions
|
@ -257,6 +257,56 @@ static const struct dm_gpio_ops gpio_tegra_ops = {
|
|||
.xlate = tegra_gpio_xlate,
|
||||
};
|
||||
|
||||
/*
|
||||
* SPL GPIO functions.
|
||||
*/
|
||||
int spl_gpio_output(void *regs, uint gpio, int value)
|
||||
{
|
||||
/* Configure GPIO output value. */
|
||||
set_level(gpio, value);
|
||||
|
||||
/* Configure GPIO direction as output. */
|
||||
set_direction(gpio, DIRECTION_OUTPUT);
|
||||
|
||||
/* Enable the pin as a GPIO */
|
||||
set_config(gpio, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spl_gpio_input(void *regs, uint gpio)
|
||||
{
|
||||
/* Configure GPIO direction as input. */
|
||||
set_direction(gpio, DIRECTION_INPUT);
|
||||
|
||||
/* Enable the pin as a GPIO */
|
||||
set_config(gpio, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spl_gpio_get_value(void *regs, uint gpio)
|
||||
{
|
||||
struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
|
||||
struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(gpio)];
|
||||
int val;
|
||||
|
||||
if (get_direction(gpio) == DIRECTION_INPUT)
|
||||
val = readl(&bank->gpio_in[GPIO_PORT(gpio)]);
|
||||
else
|
||||
val = readl(&bank->gpio_out[GPIO_PORT(gpio)]);
|
||||
|
||||
return (val >> GPIO_BIT(gpio)) & 1;
|
||||
}
|
||||
|
||||
int spl_gpio_set_value(void *regs, uint gpio, int value)
|
||||
{
|
||||
/* Configure GPIO output value. */
|
||||
set_level(gpio, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of a GPIO port
|
||||
*
|
||||
|
|
|
@ -59,4 +59,23 @@ int spl_gpio_output(void *regs, uint gpio, int value);
|
|||
*/
|
||||
int spl_gpio_input(void *regs, uint gpio);
|
||||
|
||||
/**
|
||||
* spl_gpio_get_value() - Get GPIO value
|
||||
*
|
||||
* @regs: Pointer to GPIO registers
|
||||
* @gpio: GPIO to adjust (SoC-specific)
|
||||
* Return: return GPIO value if OK, -ve on error
|
||||
*/
|
||||
int spl_gpio_get_value(void *regs, uint gpio);
|
||||
|
||||
/**
|
||||
* spl_gpio_set_value() - Set value on GPIO
|
||||
*
|
||||
* @regs: Pointer to GPIO registers
|
||||
* @gpio: GPIO to adjust (SoC-specific)
|
||||
* @value: 0 to set the output low, 1 to set it high
|
||||
* Return: return 0 if OK, -ve on error
|
||||
*/
|
||||
int spl_gpio_set_value(void *regs, uint gpio, int value);
|
||||
|
||||
#endif /* __SPL_GPIO_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue