1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
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.
7 */
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
26/* Our own private GPIO flags, which musn't conflict with GPIOD_... */
27#define GPIOD_EXT_HIGH		BIT(31)	/* external source is high (else low) */
28#define GPIOD_EXT_DRIVEN	BIT(30)	/* external source is driven */
29#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 */
31
32#define GPIOD_EXT_PULL		(BIT(28) | BIT(29))
33#define GPIOD_SANDBOX_MASK	GENMASK(31, 28)
34
35/**
36 * Return the simulated value of a GPIO (used only in sandbox test code)
37 *
38 * @param dev		device to use
39 * @param offset	GPIO offset within bank
40 * Return: -1 on error, 0 if GPIO is low, >0 if high
41 */
42int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset);
43
44/**
45 * Set the simulated value of a GPIO (used only in sandbox test code)
46 *
47 * @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)
50 * Return: -1 on error, 0 if ok
51 */
52int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value);
53
54/**
55 * Return the simulated direction of a GPIO (used only in sandbox test code)
56 *
57 * @param dev		device to use
58 * @param offset	GPIO offset within bank
59 * Return: -1 on error, 0 if GPIO is input, >0 if output
60 */
61int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset);
62
63/**
64 * Set the simulated direction of a GPIO (used only in sandbox test code)
65 *
66 * @param dev		device to use
67 * @param offset	GPIO offset within bank
68 * @param output	0 to set as input, 1 to set as output
69 * Return: -1 on error, 0 if ok
70 */
71int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset,
72			       int output);
73
74/**
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
79 * Return: dir_flags: bitfield accesses by GPIOD_ defines
80 */
81ulong sandbox_gpio_get_flags(struct udevice *dev, unsigned int offset);
82
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
88 * @param flags		bitfield accesses by GPIOD_ defines
89 * Return: -1 on error, 0 if ok
90 */
91int sandbox_gpio_set_flags(struct udevice *dev, unsigned int offset,
92			   ulong flags);
93
94#endif
95