Simon Glass | 5c01d1c | 2019-01-21 14:53:21 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Simple GPIO access from SPL. This only supports a single GPIO space, |
| 4 | * typically the SoC GPIO banks. |
| 5 | * |
| 6 | * Copyright 2018 Google LLC |
| 7 | */ |
| 8 | |
| 9 | #ifndef __SPL_GPIO_H |
| 10 | #define __SPL_GPIO_H |
| 11 | |
| 12 | #include <asm/gpio.h> |
| 13 | |
| 14 | /* |
| 15 | * The functions listed here should be implemented in the SoC GPIO driver. |
| 16 | * They correspond to the normal GPIO API (asm-generic/gpio.h). The GPIO |
| 17 | * number is encoded in an unsigned int by an SoC-specific means. Pull |
| 18 | * values are also SoC-specific. |
| 19 | * |
| 20 | * This API should only be used in TPL/SPL where GPIO access is needed but |
| 21 | * driver model is not available (yet) or adds too much overhead. |
| 22 | * |
| 23 | * The caller must supply the GPIO register base since this information is |
| 24 | * often specific to a particular SoC generation. This allows the GPIO |
| 25 | * code to be fairly generic. |
| 26 | * |
| 27 | * Only a single implementation of each of these functions can be provided. |
| 28 | * |
| 29 | * The 'gpio' value can include both a bank and a GPIO number, if desired. The |
| 30 | * encoding is SoC-specific. |
| 31 | */ |
| 32 | |
| 33 | /** |
| 34 | * spl_gpio_set_pull() - Set the pull up/down state of a GPIO |
| 35 | * |
| 36 | * @regs: Pointer to GPIO registers |
| 37 | * @gpio: GPIO to adjust (SoC-specific) |
| 38 | * @pull: Pull value (SoC-specific) |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 39 | * Return: return 0 if OK, -ve on error |
Simon Glass | 5c01d1c | 2019-01-21 14:53:21 -0700 | [diff] [blame] | 40 | */ |
| 41 | int spl_gpio_set_pull(void *regs, uint gpio, int pull); |
| 42 | |
| 43 | /** |
| 44 | * spl_gpio_output() - Set a GPIO as an output |
| 45 | * |
| 46 | * @regs: Pointer to GPIO registers |
| 47 | * @gpio: GPIO to adjust (SoC-specific) |
| 48 | * @value: 0 to set the output low, 1 to set it high |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 49 | * Return: return 0 if OK, -ve on error |
Simon Glass | 5c01d1c | 2019-01-21 14:53:21 -0700 | [diff] [blame] | 50 | */ |
| 51 | int spl_gpio_output(void *regs, uint gpio, int value); |
| 52 | |
| 53 | /** |
| 54 | * spl_gpio_input() - Set a GPIO as an input |
| 55 | * |
| 56 | * @regs: Pointer to GPIO registers |
| 57 | * @gpio: GPIO to adjust (SoC-specific) |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 58 | * Return: return 0 if OK, -ve on error |
Simon Glass | 5c01d1c | 2019-01-21 14:53:21 -0700 | [diff] [blame] | 59 | */ |
| 60 | int spl_gpio_input(void *regs, uint gpio); |
| 61 | |
| 62 | #endif /* __SPL_GPIO_H */ |