gpio.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2022-2023 StarFive Technology Co., Ltd.
  4. * Author: yanhong <yanhong.wang@starfivetech.com>
  5. *
  6. */
  7. #ifndef _GPIO_STARFIVE_H_
  8. #define _GPIO_STARFIVE_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif /* __cplusplus */
  12. #define GPIO_NUM_SHIFT 2 /*one dword include 4 gpios*/
  13. #define GPIO_BYTE_SHIFT 3
  14. #define GPIO_INDEX_MASK 0x3
  15. #define GPIO_DOEN_MASK 0x3f
  16. #define GPIO_DOUT_MASK 0x7f
  17. #define GPIO_DIN_MASK 0x7f
  18. #define NR_GPIOS 64
  19. #define GPIO_OFFSET(gpio) \
  20. (((gpio) >> GPIO_NUM_SHIFT) << GPIO_NUM_SHIFT)
  21. #define GPIO_SHIFT(gpio) \
  22. (((gpio) & GPIO_INDEX_MASK) << GPIO_BYTE_SHIFT)
  23. enum gpio_state {
  24. LOW,
  25. HIGH
  26. };
  27. #define GPIO_DOEN 0x0
  28. #define GPIO_DOUT 0x40
  29. #define GPIO_DIN 0x80
  30. #define GPIO_EN 0xdc
  31. #define GPIO_LOW_IE 0x100
  32. #define GPIO_HIGH_IE 0x104
  33. /* Details about a GPIO bank */
  34. struct starfive_gpio_platdata {
  35. void *base;
  36. };
  37. #define SYS_IOMUX_DOEN(gpio, oen) \
  38. clrsetbits_le32(SYS_IOMUX_BASE+GPIO_OFFSET(gpio), \
  39. GPIO_DOEN_MASK << GPIO_SHIFT(gpio), \
  40. (oen) << GPIO_SHIFT(gpio))
  41. #define SYS_IOMUX_DOUT(gpio, gpo) \
  42. clrsetbits_le32(SYS_IOMUX_BASE + GPIO_DOUT + GPIO_OFFSET(gpio),\
  43. GPIO_DOUT_MASK << GPIO_SHIFT(gpio),\
  44. ((gpo) & GPIO_DOUT_MASK) << GPIO_SHIFT(gpio))
  45. #define SYS_IOMUX_DIN(gpio, gpi)\
  46. clrsetbits_le32(SYS_IOMUX_BASE + GPIO_DIN + GPIO_OFFSET(gpi),\
  47. GPIO_DIN_MASK << GPIO_SHIFT(gpi),\
  48. ((gpio+2) & GPIO_DIN_MASK) << GPIO_SHIFT(gpi))
  49. #define SYS_IOMUX_COMPLEX(gpio, gpi, gpo, oen) do {\
  50. SYS_IOMUX_DOEN(gpio, oen);\
  51. SYS_IOMUX_DOUT(gpio, gpo);\
  52. SYS_IOMUX_DIN(gpio, gpi); \
  53. } while (0)
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif /* _GPIO_STARFIVE_H_ */