aspeed_gpio.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * ASPEED GPIO Controller
  3. *
  4. * Copyright (C) 2017-2018 IBM Corp.
  5. *
  6. * This code is licensed under the GPL version 2 or later. See
  7. * the COPYING file in the top-level directory.
  8. */
  9. #ifndef ASPEED_GPIO_H
  10. #define ASPEED_GPIO_H
  11. #include "hw/sysbus.h"
  12. #include "qom/object.h"
  13. #define TYPE_ASPEED_GPIO "aspeed.gpio"
  14. OBJECT_DECLARE_TYPE(AspeedGPIOState, AspeedGPIOClass, ASPEED_GPIO)
  15. #define ASPEED_GPIO_MAX_NR_SETS 8
  16. #define ASPEED_GPIOS_PER_SET 32
  17. #define ASPEED_REGS_PER_BANK 14
  18. #define ASPEED_GPIO_MAX_NR_REGS (ASPEED_REGS_PER_BANK * ASPEED_GPIO_MAX_NR_SETS)
  19. #define ASPEED_GROUPS_PER_SET 4
  20. #define ASPEED_GPIO_NR_DEBOUNCE_REGS 3
  21. #define ASPEED_CHARS_PER_GROUP_LABEL 4
  22. typedef struct GPIOSets GPIOSets;
  23. typedef struct GPIOSetProperties {
  24. uint32_t input;
  25. uint32_t output;
  26. char group_label[ASPEED_GROUPS_PER_SET][ASPEED_CHARS_PER_GROUP_LABEL];
  27. } GPIOSetProperties;
  28. enum GPIORegType {
  29. gpio_not_a_reg,
  30. gpio_reg_data_value,
  31. gpio_reg_direction,
  32. gpio_reg_int_enable,
  33. gpio_reg_int_sens_0,
  34. gpio_reg_int_sens_1,
  35. gpio_reg_int_sens_2,
  36. gpio_reg_int_status,
  37. gpio_reg_reset_tolerant,
  38. gpio_reg_debounce_1,
  39. gpio_reg_debounce_2,
  40. gpio_reg_cmd_source_0,
  41. gpio_reg_cmd_source_1,
  42. gpio_reg_data_read,
  43. gpio_reg_input_mask,
  44. };
  45. /* GPIO index mode */
  46. enum GPIORegIndexType {
  47. gpio_reg_idx_data = 0,
  48. gpio_reg_idx_direction,
  49. gpio_reg_idx_interrupt,
  50. gpio_reg_idx_debounce,
  51. gpio_reg_idx_tolerance,
  52. gpio_reg_idx_cmd_src,
  53. gpio_reg_idx_input_mask,
  54. gpio_reg_idx_reserved,
  55. gpio_reg_idx_new_w_cmd_src,
  56. gpio_reg_idx_new_r_cmd_src,
  57. };
  58. typedef struct AspeedGPIOReg {
  59. uint16_t set_idx;
  60. enum GPIORegType type;
  61. } AspeedGPIOReg;
  62. struct AspeedGPIOClass {
  63. SysBusDevice parent_obj;
  64. const GPIOSetProperties *props;
  65. uint32_t nr_gpio_pins;
  66. uint32_t nr_gpio_sets;
  67. const AspeedGPIOReg *reg_table;
  68. unsigned reg_table_count;
  69. uint64_t mem_size;
  70. const MemoryRegionOps *reg_ops;
  71. };
  72. struct AspeedGPIOState {
  73. /* <private> */
  74. SysBusDevice parent;
  75. /*< public >*/
  76. MemoryRegion iomem;
  77. int pending;
  78. qemu_irq irq;
  79. qemu_irq gpios[ASPEED_GPIO_MAX_NR_SETS][ASPEED_GPIOS_PER_SET];
  80. /* Parallel GPIO Registers */
  81. uint32_t debounce_regs[ASPEED_GPIO_NR_DEBOUNCE_REGS];
  82. struct GPIOSets {
  83. uint32_t data_value; /* Reflects pin values */
  84. uint32_t data_read; /* Contains last value written to data value */
  85. uint32_t direction;
  86. uint32_t int_enable;
  87. uint32_t int_sens_0;
  88. uint32_t int_sens_1;
  89. uint32_t int_sens_2;
  90. uint32_t int_status;
  91. uint32_t reset_tol;
  92. uint32_t cmd_source_0;
  93. uint32_t cmd_source_1;
  94. uint32_t debounce_1;
  95. uint32_t debounce_2;
  96. uint32_t input_mask;
  97. } sets[ASPEED_GPIO_MAX_NR_SETS];
  98. };
  99. #endif /* ASPEED_GPIO_H */