Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 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. |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 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 | |
Simon Glass | 44a1a5b | 2021-02-04 21:22:00 -0700 | [diff] [blame^] | 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 | |
| 29 | #define GPIOD_SANDBOX_MASK BIT(31) |
| 30 | |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 31 | /** |
| 32 | * Return the simulated value of a GPIO (used only in sandbox test code) |
| 33 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 34 | * @param dev device to use |
| 35 | * @param offset GPIO offset within bank |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 36 | * @return -1 on error, 0 if GPIO is low, >0 if high |
| 37 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 38 | int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset); |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Set the simulated value of a GPIO (used only in sandbox test code) |
| 42 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 43 | * @param dev device to use |
| 44 | * @param offset GPIO offset within bank |
| 45 | * @param value value to set (0 for low, non-zero for high) |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 46 | * @return -1 on error, 0 if ok |
| 47 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 48 | int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value); |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Return the simulated direction of a GPIO (used only in sandbox test code) |
| 52 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 53 | * @param dev device to use |
| 54 | * @param offset GPIO offset within bank |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 55 | * @return -1 on error, 0 if GPIO is input, >0 if output |
| 56 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 57 | int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset); |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Set the simulated direction of a GPIO (used only in sandbox test code) |
| 61 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 62 | * @param dev device to use |
| 63 | * @param offset GPIO offset within bank |
| 64 | * @param output 0 to set as input, 1 to set as output |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 65 | * @return -1 on error, 0 if ok |
| 66 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 67 | int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset, |
Simon Glass | b4d7070 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 68 | int output); |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 69 | |
Patrick Delaunay | 28bdaa5 | 2020-01-13 11:35:14 +0100 | [diff] [blame] | 70 | /** |
| 71 | * Return the simulated flags of a GPIO (used only in sandbox test code) |
| 72 | * |
| 73 | * @param dev device to use |
| 74 | * @param offset GPIO offset within bank |
| 75 | * @return dir_flags: bitfield accesses by GPIOD_ defines |
| 76 | */ |
Simon Glass | 3f2d575 | 2021-02-04 21:21:59 -0700 | [diff] [blame] | 77 | ulong sandbox_gpio_get_flags(struct udevice *dev, unsigned int offset); |
Patrick Delaunay | 28bdaa5 | 2020-01-13 11:35:14 +0100 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Set the simulated flags of a GPIO (used only in sandbox test code) |
| 81 | * |
| 82 | * @param dev device to use |
| 83 | * @param offset GPIO offset within bank |
Simon Glass | 3f2d575 | 2021-02-04 21:21:59 -0700 | [diff] [blame] | 84 | * @param flags bitfield accesses by GPIOD_ defines |
Patrick Delaunay | 28bdaa5 | 2020-01-13 11:35:14 +0100 | [diff] [blame] | 85 | * @return -1 on error, 0 if ok |
| 86 | */ |
Simon Glass | 3f2d575 | 2021-02-04 21:21:59 -0700 | [diff] [blame] | 87 | int sandbox_gpio_set_flags(struct udevice *dev, unsigned int offset, |
| 88 | ulong flags); |
Patrick Delaunay | 28bdaa5 | 2020-01-13 11:35:14 +0100 | [diff] [blame] | 89 | |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 90 | #endif |