qos_common.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2017-2019, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef QOS_COMMON_H
  7. #define QOS_COMMON_H
  8. #define RCAR_REF_DEFAULT 0U
  9. /* define used for get_refperiod. */
  10. /* REFPERIOD_CYCLE need smaller than QOSWT_WTSET0_CYCLEs */
  11. /* refere to plat/renesas/rcar/ddr/ddr_a/ddr_init_e3.h for E3. */
  12. #if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF default */
  13. #define REFPERIOD_CYCLE /* unit:ns */ \
  14. ((126 * BASE_SUB_SLOT_NUM * 1000U) / 400)
  15. #else /* REF option */
  16. #define REFPERIOD_CYCLE /* unit:ns */ \
  17. ((252 * BASE_SUB_SLOT_NUM * 1000U) / 400)
  18. #endif
  19. #if (RCAR_LSI == RCAR_E3)
  20. /* define used for E3 */
  21. #if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 3.9usec */
  22. #define SUB_SLOT_CYCLE_E3 0xAFU /* 175 */
  23. #else /* REF 7.8usec */
  24. #define SUB_SLOT_CYCLE_E3 0x15EU /* 350 */
  25. #endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
  26. #define OPERATING_FREQ_E3 266U /* MHz */
  27. #define SL_INIT_SSLOTCLK_E3 (SUB_SLOT_CYCLE_E3 - 1U)
  28. #endif
  29. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N)
  30. /* define used for M3N */
  31. #if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
  32. #define SUB_SLOT_CYCLE_M3N 0x7EU /* 126 */
  33. #else /* REF 3.9usec */
  34. #define SUB_SLOT_CYCLE_M3N 0xFCU /* 252 */
  35. #endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
  36. #define SL_INIT_SSLOTCLK_M3N (SUB_SLOT_CYCLE_M3N - 1U)
  37. #define QOSWT_WTSET0_CYCLE_M3N /* unit:ns */ \
  38. ((SUB_SLOT_CYCLE_M3N * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
  39. #endif
  40. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3)
  41. /* define used for H3 */
  42. #if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
  43. #define SUB_SLOT_CYCLE_H3_20 0x7EU /* 126 */
  44. #else /* REF 3.9usec */
  45. #define SUB_SLOT_CYCLE_H3_20 0xFCU /* 252 */
  46. #endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
  47. #define SL_INIT_SSLOTCLK_H3_20 (SUB_SLOT_CYCLE_H3_20 - 1U)
  48. #define QOSWT_WTSET0_CYCLE_H3_20 /* unit:ns */ \
  49. ((SUB_SLOT_CYCLE_H3_20 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
  50. /* define used for H3 Cut 30 */
  51. #define SUB_SLOT_CYCLE_H3_30 (SUB_SLOT_CYCLE_H3_20) /* same as H3 Cut 20 */
  52. #define SL_INIT_SSLOTCLK_H3_30 (SUB_SLOT_CYCLE_H3_30 - 1U)
  53. #define QOSWT_WTSET0_CYCLE_H3_30 /* unit:ns */ \
  54. ((SUB_SLOT_CYCLE_H3_30 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
  55. #endif
  56. #if (RCAR_LSI == RCAR_H3N)
  57. /* define used for H3N */
  58. #if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
  59. #define SUB_SLOT_CYCLE_H3N 0x7EU /* 126 */
  60. #else /* REF 3.9usec */
  61. #define SUB_SLOT_CYCLE_H3N 0xFCU /* 252 */
  62. #endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
  63. #define SL_INIT_SSLOTCLK_H3N (SUB_SLOT_CYCLE_H3N - 1U)
  64. #define QOSWT_WTSET0_CYCLE_H3N /* unit:ns */ \
  65. ((SUB_SLOT_CYCLE_H3N * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
  66. #endif
  67. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3)
  68. /* define used for M3 */
  69. #if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
  70. #define SUB_SLOT_CYCLE_M3_11 0x7EU /* 126 */
  71. #define SUB_SLOT_CYCLE_M3_30 0x7EU /* 126 */
  72. #else /* REF 3.9usec */
  73. #define SUB_SLOT_CYCLE_M3_11 0xFCU /* 252 */
  74. #define SUB_SLOT_CYCLE_M3_30 0xFCU /* 252 */
  75. #endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
  76. #define SL_INIT_SSLOTCLK_M3_11 (SUB_SLOT_CYCLE_M3_11 - 1U)
  77. #define SL_INIT_SSLOTCLK_M3_30 (SUB_SLOT_CYCLE_M3_30 - 1U)
  78. #define QOSWT_WTSET0_CYCLE_M3_11 /* unit:ns */ \
  79. ((SUB_SLOT_CYCLE_M3_11 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
  80. #define QOSWT_WTSET0_CYCLE_M3_30 /* unit:ns */ \
  81. ((SUB_SLOT_CYCLE_M3_30 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
  82. #endif
  83. #define OPERATING_FREQ 400U /* MHz */
  84. #define BASE_SUB_SLOT_NUM 0x6U
  85. #define SUB_SLOT_CYCLE 0x7EU /* 126 */
  86. #define QOSWT_WTSET0_CYCLE /* unit:ns */ \
  87. ((SUB_SLOT_CYCLE * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
  88. #define SL_INIT_REFFSSLOT (0x3U << 24U)
  89. #define SL_INIT_SLOTSSLOT ((BASE_SUB_SLOT_NUM - 1U) << 16U)
  90. #define SL_INIT_SSLOTCLK (SUB_SLOT_CYCLE - 1U)
  91. static inline void io_write_32(uintptr_t addr, uint32_t value)
  92. {
  93. *(volatile uint32_t *)addr = value;
  94. }
  95. static inline uint32_t io_read_32(uintptr_t addr)
  96. {
  97. return *(volatile uint32_t *)addr;
  98. }
  99. static inline void io_write_64(uintptr_t addr, uint64_t value)
  100. {
  101. *(volatile uint64_t *)addr = value;
  102. }
  103. typedef struct {
  104. uintptr_t addr;
  105. uint64_t value;
  106. } mstat_slot_t;
  107. struct rcar_gen3_dbsc_qos_settings {
  108. uint32_t reg;
  109. uint32_t val;
  110. };
  111. extern uint32_t qos_init_ddr_ch;
  112. extern uint8_t qos_init_ddr_phyvalid;
  113. void rcar_qos_dbsc_setting(struct rcar_gen3_dbsc_qos_settings *qos,
  114. unsigned int qos_size, bool dbsc_wren);
  115. #endif /* QOS_COMMON_H */