soc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef SOC_H
  7. #define SOC_H
  8. enum plls_id {
  9. APLL_ID = 0,
  10. DPLL_ID,
  11. CPLL_ID,
  12. GPLL_ID,
  13. NPLL_ID,
  14. END_PLL_ID,
  15. };
  16. #define CYCL_24M_CNT_US(us) (24 * (us))
  17. #define CYCL_24M_CNT_MS(ms) ((ms) * CYCL_24M_CNT_US(1000))
  18. /*****************************************************************************
  19. * grf regs
  20. *****************************************************************************/
  21. #define GRF_UOC0_CON0 0x320
  22. #define GRF_UOC1_CON0 0x334
  23. #define GRF_UOC2_CON0 0x348
  24. #define GRF_SIDDQ BIT(13)
  25. /*****************************************************************************
  26. * cru reg, offset
  27. *****************************************************************************/
  28. #define CRU_SOFTRST_CON 0x1b8
  29. #define CRU_SOFTRSTS_CON(n) (CRU_SOFTRST_CON + ((n) * 4))
  30. #define CRU_SOFTRSTS_CON_CNT 11
  31. #define RST_DMA1_MSK 0x4
  32. #define RST_DMA2_MSK 0x1
  33. #define CRU_CLKSEL_CON 0x60
  34. #define CRU_CLKSELS_CON(i) (CRU_CLKSEL_CON + ((i) * 4))
  35. #define CRU_CLKSELS_CON_CNT 42
  36. #define CRU_CLKGATE_CON 0x160
  37. #define CRU_CLKGATES_CON(i) (CRU_CLKGATE_CON + ((i) * 4))
  38. #define CRU_CLKGATES_CON_CNT 18
  39. #define CRU_GLB_SRST_FST 0x1b0
  40. #define CRU_GLB_SRST_SND 0x1b4
  41. #define CRU_GLB_RST_CON 0x1f0
  42. #define CRU_CONS_GATEID(i) (16 * (i))
  43. #define GATE_ID(reg, bit) (((reg) * 16) + (bit))
  44. #define PMU_RST_MASK 0x3
  45. #define PMU_RST_BY_FIRST_SFT (0 << 2)
  46. #define PMU_RST_BY_SECOND_SFT (1 << 2)
  47. #define PMU_RST_NOT_BY_SFT (2 << 2)
  48. /***************************************************************************
  49. * pll
  50. ***************************************************************************/
  51. #define PLL_CON_COUNT 4
  52. #define PLL_CONS(id, i) ((id) * 0x10 + ((i) * 4))
  53. #define PLL_PWR_DN_MSK BIT(1)
  54. #define PLL_PWR_DN REG_WMSK_BITS(1, 1, 0x1)
  55. #define PLL_PWR_ON REG_WMSK_BITS(0, 1, 0x1)
  56. #define PLL_RESET REG_WMSK_BITS(1, 5, 0x1)
  57. #define PLL_RESET_RESUME REG_WMSK_BITS(0, 5, 0x1)
  58. #define PLL_BYPASS_MSK BIT(0)
  59. #define PLL_BYPASS_W_MSK (PLL_BYPASS_MSK << 16)
  60. #define PLL_BYPASS REG_WMSK_BITS(1, 0, 0x1)
  61. #define PLL_NO_BYPASS REG_WMSK_BITS(0, 0, 0x1)
  62. #define PLL_MODE_CON 0x50
  63. struct deepsleep_data_s {
  64. uint32_t pll_con[END_PLL_ID][PLL_CON_COUNT];
  65. uint32_t pll_mode;
  66. uint32_t cru_sel_con[CRU_CLKSELS_CON_CNT];
  67. uint32_t cru_gate_con[CRU_CLKGATES_CON_CNT];
  68. };
  69. #define REG_W_MSK(bits_shift, msk) \
  70. ((msk) << ((bits_shift) + 16))
  71. #define REG_VAL_CLRBITS(val, bits_shift, msk) \
  72. ((val) & (~((msk) << bits_shift)))
  73. #define REG_SET_BITS(bits, bits_shift, msk) \
  74. (((bits) & (msk)) << (bits_shift))
  75. #define REG_WMSK_BITS(bits, bits_shift, msk) \
  76. (REG_W_MSK(bits_shift, msk) | \
  77. REG_SET_BITS(bits, bits_shift, msk))
  78. #define REG_SOC_WMSK 0xffff0000
  79. #define regs_update_bit_set(addr, shift) \
  80. regs_update_bits((addr), 0x1, 0x1, (shift))
  81. #define regs_update_bit_clr(addr, shift) \
  82. regs_update_bits((addr), 0x0, 0x1, (shift))
  83. void regs_update_bits(uintptr_t addr, uint32_t val,
  84. uint32_t mask, uint32_t shift);
  85. void clk_plls_suspend(void);
  86. void clk_plls_resume(void);
  87. void clk_gate_con_save(void);
  88. void clk_gate_con_disable(void);
  89. void clk_gate_con_restore(void);
  90. void clk_sel_con_save(void);
  91. void clk_sel_con_restore(void);
  92. #endif /* SOC_H */