rk3588_rstd.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2024, Rockchip, Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <drivers/delay_timer.h>
  9. #include <drivers/scmi.h>
  10. #include <lib/mmio.h>
  11. #include <platform_def.h>
  12. #include <plat_private.h>
  13. #include "rk3588_clk.h"
  14. #include <scmi_rstd.h>
  15. #include <soc.h>
  16. #define DEFAULT_RESET_DOM_ATTRIBUTE 0
  17. #define RK3588_SCMI_RESET(_id, _name, _attribute, _ops) \
  18. { \
  19. .id = _id, \
  20. .name = _name, \
  21. .attribute = _attribute, \
  22. .rstd_ops = _ops, \
  23. }
  24. static int rk3588_reset_explicit(rk_scmi_rstd_t *reset_domain,
  25. bool assert_not_deassert)
  26. {
  27. int bank = reset_domain->id / 16;
  28. int offset = reset_domain->id % 16;
  29. mmio_write_32(SCRU_BASE + CRU_SOFTRST_CON(bank),
  30. BITS_WITH_WMASK(assert_not_deassert, 0x1U, offset));
  31. return SCMI_SUCCESS;
  32. }
  33. static struct rk_scmi_rstd_ops rk3588_reset_domain_ops = {
  34. .reset_explicit = rk3588_reset_explicit,
  35. };
  36. static rk_scmi_rstd_t rk3588_reset_domain_table[] = {
  37. RK3588_SCMI_RESET(SRST_CRYPTO_CORE, "scmi_sr_cy_core", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  38. RK3588_SCMI_RESET(SRST_CRYPTO_PKA, "scmi_sr_cy_pka", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  39. RK3588_SCMI_RESET(SRST_CRYPTO_RNG, "scmi_sr_cy_rng", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  40. RK3588_SCMI_RESET(SRST_A_CRYPTO, "scmi_sr_a_cy", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  41. RK3588_SCMI_RESET(SRST_H_CRYPTO, "scmi_sr_h_cy", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  42. RK3588_SCMI_RESET(SRST_KEYLADDER_CORE, "scmi_sr_k_core", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  43. RK3588_SCMI_RESET(SRST_KEYLADDER_RNG, "scmi_sr_k_rng", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  44. RK3588_SCMI_RESET(SRST_P_OTPC_S, "scmi_sr_p_otp", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  45. RK3588_SCMI_RESET(SRST_OTPC_S, "scmi_sr_otp", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  46. RK3588_SCMI_RESET(SRST_WDT_S, "scmi_sr_wdt", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  47. RK3588_SCMI_RESET(SRST_T_WDT_S, "scmi_sr_t_wdt", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  48. RK3588_SCMI_RESET(SRST_H_BOOTROM, "scmi_sr_h_boot", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  49. RK3588_SCMI_RESET(SRST_P_KEYLADDER, "scmi_sr_p_ky", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  50. RK3588_SCMI_RESET(SRST_H_TRNG_S, "scmi_sr_h_trng", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  51. RK3588_SCMI_RESET(SRST_H_TRNG_NS, "scmi_sr_t_trng", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  52. RK3588_SCMI_RESET(SRST_D_SDMMC_BUFFER, "scmi_sr_d_sd", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  53. RK3588_SCMI_RESET(SRST_H_SDMMC, "scmi_sr_h_sd", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  54. RK3588_SCMI_RESET(SRST_H_SDMMC_BUFFER, "scmi_sr_h_sd_b", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  55. RK3588_SCMI_RESET(SRST_SDMMC, "scmi_sr_sd", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  56. RK3588_SCMI_RESET(SRST_P_TRNG_CHK, "scmi_sr_p_trng", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  57. RK3588_SCMI_RESET(SRST_TRNG_S, "scmi_sr_trng", DEFAULT_RESET_DOM_ATTRIBUTE, &rk3588_reset_domain_ops),
  58. RK3588_SCMI_RESET(SRST_INVALID, "scmi_sr_invalid", DEFAULT_RESET_DOM_ATTRIBUTE, NULL),
  59. };
  60. static rk_scmi_rstd_t *
  61. rockchip_get_reset_domain_table(int id)
  62. {
  63. rk_scmi_rstd_t *reset = rk3588_reset_domain_table;
  64. int i = 0, cnt = ARRAY_SIZE(rk3588_reset_domain_table);
  65. for (i = 0; i < cnt; i++) {
  66. if (reset->id == id)
  67. return &rk3588_reset_domain_table[i];
  68. reset++;
  69. }
  70. return &rk3588_reset_domain_table[cnt - 1];
  71. }
  72. rk_scmi_rstd_t *rockchip_scmi_get_rstd(unsigned int agent_id,
  73. unsigned int scmi_id)
  74. {
  75. return rockchip_get_reset_domain_table(scmi_id);
  76. }
  77. size_t rockchip_scmi_rstd_count(unsigned int agent_id)
  78. {
  79. return SRST_TRNG_S;
  80. }