blob: b33261a6485ad9813cb4533d9208a509e4cdc2d5 [file] [log] [blame]
Simon Glassbc9e7d42019-01-21 14:53:21 -07001/* 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 Schuchardt47b4c022022-01-19 18:05:50 +010039 * Return: return 0 if OK, -ve on error
Simon Glassbc9e7d42019-01-21 14:53:21 -070040 */
41int 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 Schuchardt47b4c022022-01-19 18:05:50 +010049 * Return: return 0 if OK, -ve on error
Simon Glassbc9e7d42019-01-21 14:53:21 -070050 */
51int 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 Schuchardt47b4c022022-01-19 18:05:50 +010058 * Return: return 0 if OK, -ve on error
Simon Glassbc9e7d42019-01-21 14:53:21 -070059 */
60int spl_gpio_input(void *regs, uint gpio);
61
Svyatoslav Ryhelbd7326a2024-08-09 21:10:31 +030062/**
63 * spl_gpio_get_value() - Get GPIO value
64 *
65 * @regs: Pointer to GPIO registers
66 * @gpio: GPIO to adjust (SoC-specific)
67 * Return: return GPIO value if OK, -ve on error
68 */
69int spl_gpio_get_value(void *regs, uint gpio);
70
71/**
72 * spl_gpio_set_value() - Set value on GPIO
73 *
74 * @regs: Pointer to GPIO registers
75 * @gpio: GPIO to adjust (SoC-specific)
76 * @value: 0 to set the output low, 1 to set it high
77 * Return: return 0 if OK, -ve on error
78 */
79int spl_gpio_set_value(void *regs, uint gpio, int value);
80
Simon Glassbc9e7d42019-01-21 14:53:21 -070081#endif /* __SPL_GPIO_H */