blob: 0dd4c7bf60161e7272ccbab332445b0bf8296f65 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass8d30fcd2012-02-15 15:51:13 -08002/*
3 * This is the interface to the sandbox GPIO driver for test code which
4 * wants to change the GPIO values reported to U-Boot.
5 *
6 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass8d30fcd2012-02-15 15:51:13 -08007 */
8
9#ifndef __ASM_SANDBOX_GPIO_H
10#define __ASM_SANDBOX_GPIO_H
11
12/*
13 * We use the generic interface, and add a back-channel.
14 *
15 * The back-channel functions are declared in this file. They should not be used
16 * except in test code.
17 *
18 * Test code can, for example, call sandbox_gpio_set_value() to set the value of
19 * a simulated GPIO. From then on, normal code in U-Boot will see this new
20 * value when it calls gpio_get_value().
21 *
22 * NOTE: DO NOT use the functions in this file except in test code!
23 */
24#include <asm-generic/gpio.h>
25
Simon Glass1f212af2021-02-04 21:22:00 -070026/* Our own private GPIO flags, which musn't conflict with GPIOD_... */
27#define GPIOD_EXT_HIGH BIT(31) /* external source is high (else low) */
Simon Glassd638a182021-02-04 21:22:07 -070028#define GPIOD_EXT_DRIVEN BIT(30) /* external source is driven */
Simon Glass8a45b222021-02-04 21:22:09 -070029#define GPIOD_EXT_PULL_UP BIT(29) /* GPIO has external pull-up */
30#define GPIOD_EXT_PULL_DOWN BIT(28) /* GPIO has external pull-down */
Simon Glass1f212af2021-02-04 21:22:00 -070031
Simon Glass8a45b222021-02-04 21:22:09 -070032#define GPIOD_EXT_PULL (BIT(28) | BIT(29))
33#define GPIOD_SANDBOX_MASK GENMASK(31, 28)
Simon Glass1f212af2021-02-04 21:22:00 -070034
Simon Glass8d30fcd2012-02-15 15:51:13 -080035/**
36 * Return the simulated value of a GPIO (used only in sandbox test code)
37 *
mario.six@gdsys.cc21047b32016-05-25 15:18:10 +020038 * @param dev device to use
39 * @param offset GPIO offset within bank
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010040 * Return: -1 on error, 0 if GPIO is low, >0 if high
Simon Glass8d30fcd2012-02-15 15:51:13 -080041 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020042int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset);
Simon Glass8d30fcd2012-02-15 15:51:13 -080043
44/**
45 * Set the simulated value of a GPIO (used only in sandbox test code)
46 *
mario.six@gdsys.cc21047b32016-05-25 15:18:10 +020047 * @param dev device to use
48 * @param offset GPIO offset within bank
49 * @param value value to set (0 for low, non-zero for high)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010050 * Return: -1 on error, 0 if ok
Simon Glass8d30fcd2012-02-15 15:51:13 -080051 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020052int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value);
Simon Glass8d30fcd2012-02-15 15:51:13 -080053
54/**
55 * Return the simulated direction of a GPIO (used only in sandbox test code)
56 *
mario.six@gdsys.cc21047b32016-05-25 15:18:10 +020057 * @param dev device to use
58 * @param offset GPIO offset within bank
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010059 * Return: -1 on error, 0 if GPIO is input, >0 if output
Simon Glass8d30fcd2012-02-15 15:51:13 -080060 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020061int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset);
Simon Glass8d30fcd2012-02-15 15:51:13 -080062
63/**
64 * Set the simulated direction of a GPIO (used only in sandbox test code)
65 *
mario.six@gdsys.cc21047b32016-05-25 15:18:10 +020066 * @param dev device to use
67 * @param offset GPIO offset within bank
Wolfgang Denk0cf207e2021-09-27 17:42:39 +020068 * @param output 0 to set as input, 1 to set as output
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010069 * Return: -1 on error, 0 if ok
Simon Glass8d30fcd2012-02-15 15:51:13 -080070 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020071int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset,
Simon Glasse2d8a712014-02-26 15:59:25 -070072 int output);
Simon Glass8d30fcd2012-02-15 15:51:13 -080073
Patrick Delaunayff526652020-01-13 11:35:14 +010074/**
75 * Return the simulated flags of a GPIO (used only in sandbox test code)
76 *
77 * @param dev device to use
78 * @param offset GPIO offset within bank
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010079 * Return: dir_flags: bitfield accesses by GPIOD_ defines
Patrick Delaunayff526652020-01-13 11:35:14 +010080 */
Simon Glassa03a0aa2021-02-04 21:21:59 -070081ulong sandbox_gpio_get_flags(struct udevice *dev, unsigned int offset);
Patrick Delaunayff526652020-01-13 11:35:14 +010082
83/**
84 * Set the simulated flags of a GPIO (used only in sandbox test code)
85 *
86 * @param dev device to use
87 * @param offset GPIO offset within bank
Simon Glassa03a0aa2021-02-04 21:21:59 -070088 * @param flags bitfield accesses by GPIOD_ defines
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010089 * Return: -1 on error, 0 if ok
Patrick Delaunayff526652020-01-13 11:35:14 +010090 */
Simon Glassa03a0aa2021-02-04 21:21:59 -070091int sandbox_gpio_set_flags(struct udevice *dev, unsigned int offset,
92 ulong flags);
Patrick Delaunayff526652020-01-13 11:35:14 +010093
Simon Glass8d30fcd2012-02-15 15:51:13 -080094#endif