blob: 33b83ea4cc3fad3e2f2e11905d036a7123b6cb26 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassb43d0442012-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 Glassb43d0442012-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 Glass44a1a5b2021-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 Glass59356522021-02-04 21:22:07 -070028#define GPIOD_EXT_DRIVEN BIT(30) /* external source is driven */
Simon Glass44a1a5b2021-02-04 21:22:00 -070029
Simon Glass59356522021-02-04 21:22:07 -070030#define GPIOD_SANDBOX_MASK GENMASK(31, 30)
Simon Glass44a1a5b2021-02-04 21:22:00 -070031
Simon Glassb43d0442012-02-15 15:51:13 -080032/**
33 * Return the simulated value of a GPIO (used only in sandbox test code)
34 *
mario.six@gdsys.cceeed18c2016-05-25 15:18:10 +020035 * @param dev device to use
36 * @param offset GPIO offset within bank
Simon Glassb43d0442012-02-15 15:51:13 -080037 * @return -1 on error, 0 if GPIO is low, >0 if high
38 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +020039int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset);
Simon Glassb43d0442012-02-15 15:51:13 -080040
41/**
42 * Set the simulated value of a GPIO (used only in sandbox test code)
43 *
mario.six@gdsys.cceeed18c2016-05-25 15:18:10 +020044 * @param dev device to use
45 * @param offset GPIO offset within bank
46 * @param value value to set (0 for low, non-zero for high)
Simon Glassb43d0442012-02-15 15:51:13 -080047 * @return -1 on error, 0 if ok
48 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +020049int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value);
Simon Glassb43d0442012-02-15 15:51:13 -080050
51/**
52 * Return the simulated direction of a GPIO (used only in sandbox test code)
53 *
mario.six@gdsys.cceeed18c2016-05-25 15:18:10 +020054 * @param dev device to use
55 * @param offset GPIO offset within bank
Simon Glassb43d0442012-02-15 15:51:13 -080056 * @return -1 on error, 0 if GPIO is input, >0 if output
57 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +020058int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset);
Simon Glassb43d0442012-02-15 15:51:13 -080059
60/**
61 * Set the simulated direction of a GPIO (used only in sandbox test code)
62 *
mario.six@gdsys.cceeed18c2016-05-25 15:18:10 +020063 * @param dev device to use
64 * @param offset GPIO offset within bank
65 * @param output 0 to set as input, 1 to set as output
Simon Glassb43d0442012-02-15 15:51:13 -080066 * @return -1 on error, 0 if ok
67 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +020068int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset,
Simon Glassb4d70702014-02-26 15:59:25 -070069 int output);
Simon Glassb43d0442012-02-15 15:51:13 -080070
Patrick Delaunay28bdaa52020-01-13 11:35:14 +010071/**
72 * Return the simulated flags of a GPIO (used only in sandbox test code)
73 *
74 * @param dev device to use
75 * @param offset GPIO offset within bank
76 * @return dir_flags: bitfield accesses by GPIOD_ defines
77 */
Simon Glass3f2d5752021-02-04 21:21:59 -070078ulong sandbox_gpio_get_flags(struct udevice *dev, unsigned int offset);
Patrick Delaunay28bdaa52020-01-13 11:35:14 +010079
80/**
81 * Set the simulated flags of a GPIO (used only in sandbox test code)
82 *
83 * @param dev device to use
84 * @param offset GPIO offset within bank
Simon Glass3f2d5752021-02-04 21:21:59 -070085 * @param flags bitfield accesses by GPIOD_ defines
Patrick Delaunay28bdaa52020-01-13 11:35:14 +010086 * @return -1 on error, 0 if ok
87 */
Simon Glass3f2d5752021-02-04 21:21:59 -070088int sandbox_gpio_set_flags(struct udevice *dev, unsigned int offset,
89 ulong flags);
Patrick Delaunay28bdaa52020-01-13 11:35:14 +010090
Simon Glassb43d0442012-02-15 15:51:13 -080091#endif