gpio.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 GPIO_DS_MASK 0x06
  19. #define GPIO_DS_SHIFT 1
  20. #define GPIO_PULL_MASK 0x18
  21. #define GPIO_PULL_SHIFT 3
  22. #define GPIO_PULL_UP 1
  23. #define GPIO_PULL_DOWN 2
  24. #define NR_GPIOS 64
  25. #define GPIO_OFFSET(gpio) \
  26. (((gpio) >> GPIO_NUM_SHIFT) << GPIO_NUM_SHIFT)
  27. #define GPIO_SHIFT(gpio) \
  28. (((gpio) & GPIO_INDEX_MASK) << GPIO_BYTE_SHIFT)
  29. enum gpio_state {
  30. LOW,
  31. HIGH
  32. };
  33. #define GPIO_DOEN 0x0
  34. #define GPIO_DOUT 0x40
  35. #define GPIO_DIN 0x80
  36. #define GPIO_EN 0xdc
  37. #define GPIO_CONFIG 0x120
  38. #define GPIO_LOW_IE 0x100
  39. #define GPIO_HIGH_IE 0x104
  40. /* Details about a GPIO bank */
  41. struct starfive_gpio_platdata {
  42. void *base;
  43. };
  44. #define SYS_IOMUX_DOEN(gpio, oen) \
  45. clrsetbits_le32(SYS_IOMUX_BASE+GPIO_OFFSET(gpio), \
  46. GPIO_DOEN_MASK << GPIO_SHIFT(gpio), \
  47. (oen) << GPIO_SHIFT(gpio))
  48. #define SYS_IOMUX_DOUT(gpio, gpo) \
  49. clrsetbits_le32(SYS_IOMUX_BASE + GPIO_DOUT + GPIO_OFFSET(gpio),\
  50. GPIO_DOUT_MASK << GPIO_SHIFT(gpio),\
  51. ((gpo) & GPIO_DOUT_MASK) << GPIO_SHIFT(gpio))
  52. #define SYS_IOMUX_DIN(gpio, gpi)\
  53. clrsetbits_le32(SYS_IOMUX_BASE + GPIO_DIN + GPIO_OFFSET(gpi),\
  54. GPIO_DIN_MASK << GPIO_SHIFT(gpi),\
  55. ((gpio+2) & GPIO_DIN_MASK) << GPIO_SHIFT(gpi))
  56. #define SYS_IOMUX_SET_DS(gpio, ds) \
  57. clrsetbits_le32(SYS_IOMUX_BASE + GPIO_CONFIG + gpio * 4, \
  58. GPIO_DS_MASK, (ds) << GPIO_DS_SHIFT)
  59. #define SYS_IOMUX_SET_PULL(gpio, pull) \
  60. clrsetbits_le32(SYS_IOMUX_BASE + GPIO_CONFIG + gpio * 4, \
  61. GPIO_PULL_MASK, (pull) << GPIO_PULL_SHIFT)
  62. #define SYS_IOMUX_COMPLEX(gpio, gpi, gpo, oen) do {\
  63. SYS_IOMUX_DOEN(gpio, oen);\
  64. SYS_IOMUX_DOUT(gpio, gpo);\
  65. SYS_IOMUX_DIN(gpio, gpi); \
  66. } while (0)
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif /* _GPIO_STARFIVE_H_ */