gpio.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef __ASM_SANDBOX_GPIO_H
  9. #define __ASM_SANDBOX_GPIO_H
  10. /*
  11. * We use the generic interface, and add a back-channel.
  12. *
  13. * The back-channel functions are declared in this file. They should not be used
  14. * except in test code.
  15. *
  16. * Test code can, for example, call sandbox_gpio_set_value() to set the value of
  17. * a simulated GPIO. From then on, normal code in U-Boot will see this new
  18. * value when it calls gpio_get_value().
  19. *
  20. * NOTE: DO NOT use the functions in this file except in test code!
  21. */
  22. #include <asm-generic/gpio.h>
  23. /* Our own private GPIO flags, which musn't conflict with GPIOD_... */
  24. #define GPIOD_EXT_HIGH BIT(31) /* external source is high (else low) */
  25. #define GPIOD_EXT_DRIVEN BIT(30) /* external source is driven */
  26. #define GPIOD_EXT_PULL_UP BIT(29) /* GPIO has external pull-up */
  27. #define GPIOD_EXT_PULL_DOWN BIT(28) /* GPIO has external pull-down */
  28. #define GPIOD_EXT_PULL (BIT(28) | BIT(29))
  29. #define GPIOD_SANDBOX_MASK GENMASK(31, 28)
  30. /**
  31. * Return the simulated value of a GPIO (used only in sandbox test code)
  32. *
  33. * @param dev device to use
  34. * @param offset GPIO offset within bank
  35. * @return -1 on error, 0 if GPIO is low, >0 if high
  36. */
  37. int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset);
  38. /**
  39. * Set the simulated value of a GPIO (used only in sandbox test code)
  40. *
  41. * @param dev device to use
  42. * @param offset GPIO offset within bank
  43. * @param value value to set (0 for low, non-zero for high)
  44. * @return -1 on error, 0 if ok
  45. */
  46. int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value);
  47. /**
  48. * Return the simulated direction of a GPIO (used only in sandbox test code)
  49. *
  50. * @param dev device to use
  51. * @param offset GPIO offset within bank
  52. * @return -1 on error, 0 if GPIO is input, >0 if output
  53. */
  54. int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset);
  55. /**
  56. * Set the simulated direction of a GPIO (used only in sandbox test code)
  57. *
  58. * @param dev device to use
  59. * @param offset GPIO offset within bank
  60. * @param output 0 to set as input, 1 to set as output
  61. * @return -1 on error, 0 if ok
  62. */
  63. int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset,
  64. int output);
  65. /**
  66. * Return the simulated flags of a GPIO (used only in sandbox test code)
  67. *
  68. * @param dev device to use
  69. * @param offset GPIO offset within bank
  70. * @return dir_flags: bitfield accesses by GPIOD_ defines
  71. */
  72. ulong sandbox_gpio_get_flags(struct udevice *dev, unsigned int offset);
  73. /**
  74. * Set the simulated flags of a GPIO (used only in sandbox test code)
  75. *
  76. * @param dev device to use
  77. * @param offset GPIO offset within bank
  78. * @param flags bitfield accesses by GPIOD_ defines
  79. * @return -1 on error, 0 if ok
  80. */
  81. int sandbox_gpio_set_flags(struct udevice *dev, unsigned int offset,
  82. ulong flags);
  83. #endif