1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * This is the interface to the sandbox GPIO driver for test code which 3*4882a593Smuzhiyun * wants to change the GPIO values reported to U-Boot. 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (c) 2011 The Chromium OS Authors. 6*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+ 7*4882a593Smuzhiyun */ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun #ifndef __ASM_SANDBOX_GPIO_H 10*4882a593Smuzhiyun #define __ASM_SANDBOX_GPIO_H 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun /* 13*4882a593Smuzhiyun * We use the generic interface, and add a back-channel. 14*4882a593Smuzhiyun * 15*4882a593Smuzhiyun * The back-channel functions are declared in this file. They should not be used 16*4882a593Smuzhiyun * except in test code. 17*4882a593Smuzhiyun * 18*4882a593Smuzhiyun * Test code can, for example, call sandbox_gpio_set_value() to set the value of 19*4882a593Smuzhiyun * a simulated GPIO. From then on, normal code in U-Boot will see this new 20*4882a593Smuzhiyun * value when it calls gpio_get_value(). 21*4882a593Smuzhiyun * 22*4882a593Smuzhiyun * NOTE: DO NOT use the functions in this file except in test code! 23*4882a593Smuzhiyun */ 24*4882a593Smuzhiyun #include <asm-generic/gpio.h> 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun /** 27*4882a593Smuzhiyun * Return the simulated value of a GPIO (used only in sandbox test code) 28*4882a593Smuzhiyun * 29*4882a593Smuzhiyun * @param dev device to use 30*4882a593Smuzhiyun * @param offset GPIO offset within bank 31*4882a593Smuzhiyun * @return -1 on error, 0 if GPIO is low, >0 if high 32*4882a593Smuzhiyun */ 33*4882a593Smuzhiyun int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset); 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /** 36*4882a593Smuzhiyun * Set the simulated value of a GPIO (used only in sandbox test code) 37*4882a593Smuzhiyun * 38*4882a593Smuzhiyun * @param dev device to use 39*4882a593Smuzhiyun * @param offset GPIO offset within bank 40*4882a593Smuzhiyun * @param value value to set (0 for low, non-zero for high) 41*4882a593Smuzhiyun * @return -1 on error, 0 if ok 42*4882a593Smuzhiyun */ 43*4882a593Smuzhiyun int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value); 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun /** 46*4882a593Smuzhiyun * Set or reset the simulated open drain mode of a GPIO (used only in sandbox 47*4882a593Smuzhiyun * test code) 48*4882a593Smuzhiyun * 49*4882a593Smuzhiyun * @param gp GPIO number 50*4882a593Smuzhiyun * @param value value to set (0 for enabled open drain mode, non-zero for 51*4882a593Smuzhiyun * disabled) 52*4882a593Smuzhiyun * @return -1 on error, 0 if ok 53*4882a593Smuzhiyun */ 54*4882a593Smuzhiyun int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value); 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun /** 57*4882a593Smuzhiyun * Return the state of the simulated open drain mode of a GPIO (used only in 58*4882a593Smuzhiyun * sandbox test code) 59*4882a593Smuzhiyun * 60*4882a593Smuzhiyun * @param gp GPIO number 61*4882a593Smuzhiyun * @return -1 on error, 0 if GPIO is input, >0 if output 62*4882a593Smuzhiyun */ 63*4882a593Smuzhiyun int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset); 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun /** 66*4882a593Smuzhiyun * Return the simulated direction of a GPIO (used only in sandbox test code) 67*4882a593Smuzhiyun * 68*4882a593Smuzhiyun * @param dev device to use 69*4882a593Smuzhiyun * @param offset GPIO offset within bank 70*4882a593Smuzhiyun * @return -1 on error, 0 if GPIO is input, >0 if output 71*4882a593Smuzhiyun */ 72*4882a593Smuzhiyun int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset); 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun /** 75*4882a593Smuzhiyun * Set the simulated direction of a GPIO (used only in sandbox test code) 76*4882a593Smuzhiyun * 77*4882a593Smuzhiyun * @param dev device to use 78*4882a593Smuzhiyun * @param offset GPIO offset within bank 79*4882a593Smuzhiyun * @param output 0 to set as input, 1 to set as output 80*4882a593Smuzhiyun * @return -1 on error, 0 if ok 81*4882a593Smuzhiyun */ 82*4882a593Smuzhiyun int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset, 83*4882a593Smuzhiyun int output); 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun #endif 86