Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This is the interface to the sandbox GPIO driver for test code which |
| 3 | * wants to change the GPIO values reported to U-Boot. |
| 4 | * |
| 5 | * Copyright (c) 2011 The Chromium OS Authors. |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
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 | |
| 26 | /** |
| 27 | * Return the simulated value of a GPIO (used only in sandbox test code) |
| 28 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 29 | * @param dev device to use |
| 30 | * @param offset GPIO offset within bank |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 31 | * @return -1 on error, 0 if GPIO is low, >0 if high |
| 32 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 33 | int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset); |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Set the simulated value of a GPIO (used only in sandbox test code) |
| 37 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 38 | * @param dev device to use |
| 39 | * @param offset GPIO offset within bank |
| 40 | * @param value value to set (0 for low, non-zero for high) |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 41 | * @return -1 on error, 0 if ok |
| 42 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 43 | 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] | 44 | |
| 45 | /** |
mario.six@gdsys.cc | 90937cc | 2016-05-25 15:15:23 +0200 | [diff] [blame] | 46 | * Set or reset the simulated open drain mode of a GPIO (used only in sandbox |
| 47 | * test code) |
| 48 | * |
| 49 | * @param gp GPIO number |
| 50 | * @param value value to set (0 for enabled open drain mode, non-zero for |
| 51 | * disabled) |
| 52 | * @return -1 on error, 0 if ok |
| 53 | */ |
| 54 | int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value); |
| 55 | |
| 56 | /** |
| 57 | * Return the state of the simulated open drain mode of a GPIO (used only in |
| 58 | * sandbox test code) |
| 59 | * |
| 60 | * @param gp GPIO number |
| 61 | * @return -1 on error, 0 if GPIO is input, >0 if output |
| 62 | */ |
| 63 | int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset); |
| 64 | |
| 65 | /** |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 66 | * Return the simulated direction of a GPIO (used only in sandbox test code) |
| 67 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 68 | * @param dev device to use |
| 69 | * @param offset GPIO offset within bank |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 70 | * @return -1 on error, 0 if GPIO is input, >0 if output |
| 71 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 72 | int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset); |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Set the simulated direction of a GPIO (used only in sandbox test code) |
| 76 | * |
mario.six@gdsys.cc | eeed18c | 2016-05-25 15:18:10 +0200 | [diff] [blame] | 77 | * @param dev device to use |
| 78 | * @param offset GPIO offset within bank |
| 79 | * @param output 0 to set as input, 1 to set as output |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 80 | * @return -1 on error, 0 if ok |
| 81 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 82 | int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset, |
Simon Glass | b4d7070 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 83 | int output); |
Simon Glass | b43d044 | 2012-02-15 15:51:13 -0800 | [diff] [blame] | 84 | |
| 85 | #endif |