misc_dfx.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2021 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <common/debug.h>
  8. #include <lib/mmio.h>
  9. #include "dfx.h"
  10. #include <mvebu_def.h>
  11. #include <mvebu.h>
  12. #include <errno.h>
  13. /* #define DEBUG_DFX */
  14. #ifdef DEBUG_DFX
  15. #define debug(format...) NOTICE(format)
  16. #else
  17. #define debug(format, arg...)
  18. #endif
  19. #define SAR_BASE (MVEBU_REGS_BASE + 0x6F8200)
  20. #define SAR_SIZE 0x4
  21. #define AP_DEV_ID_STATUS_REG (MVEBU_REGS_BASE + 0x6F8240)
  22. #define JTAG_DEV_ID_STATUS_REG (MVEBU_REGS_BASE + 0x6F8244)
  23. #define EFUSE_CTRL (MVEBU_REGS_BASE + 0x6F8008)
  24. #define EFUSE_LD_BASE (MVEBU_REGS_BASE + 0x6F8F00)
  25. #define EFUSE_LD_SIZE 0x1C
  26. #define EFUSE_HD_BASE (MVEBU_REGS_BASE + 0x6F9000)
  27. #define EFUSE_HD_SIZE 0x3F8
  28. /* AP806 CPU DFS register mapping*/
  29. #define AP806_CA72MP2_0_PLL_CR_0_BASE (MVEBU_REGS_BASE + 0x6F8278)
  30. #define AP806_CA72MP2_0_PLL_CR_1_BASE (MVEBU_REGS_BASE + 0x6F8280)
  31. #define AP806_CA72MP2_0_PLL_CR_2_BASE (MVEBU_REGS_BASE + 0x6F8284)
  32. #define AP806_CA72MP2_0_PLL_SR_BASE (MVEBU_REGS_BASE + 0x6F8C94)
  33. /* AP807 CPU DFS register mapping */
  34. #define AP807_DEVICE_GENERAL_CR_10_BASE (MVEBU_REGS_BASE + 0x6F8278)
  35. #define AP807_DEVICE_GENERAL_CR_11_BASE (MVEBU_REGS_BASE + 0x6F827C)
  36. #define AP807_DEVICE_GENERAL_STATUS_6_BASE (MVEBU_REGS_BASE + 0x6F8C98)
  37. #ifdef MVEBU_SOC_AP807
  38. #define CLUSTER_OFFSET 0x8
  39. #define CLK_DIVIDER_REG AP807_DEVICE_GENERAL_CR_10_BASE
  40. #define CLK_FORCE_REG AP807_DEVICE_GENERAL_CR_11_BASE
  41. #define CLK_RATIO_REG AP807_DEVICE_GENERAL_CR_11_BASE
  42. #define CLK_RATIO_STATE_REG AP807_DEVICE_GENERAL_STATUS_6_BASE
  43. #else
  44. #define CLUSTER_OFFSET 0x14
  45. #define CLK_DIVIDER_REG AP806_CA72MP2_0_PLL_CR_0_BASE
  46. #define CLK_FORCE_REG AP806_CA72MP2_0_PLL_CR_1_BASE
  47. #define CLK_RATIO_REG AP806_CA72MP2_0_PLL_CR_2_BASE
  48. #define CLK_RATIO_STATE_REG AP806_CA72MP2_0_PLL_SR_BASE
  49. #endif /* MVEBU_SOC_AP807 */
  50. static _Bool is_valid(u_register_t addr)
  51. {
  52. switch (addr) {
  53. case AP_DEV_ID_STATUS_REG:
  54. case JTAG_DEV_ID_STATUS_REG:
  55. case SAR_BASE ... (SAR_BASE + SAR_SIZE):
  56. case EFUSE_LD_BASE ... (EFUSE_LD_BASE + EFUSE_LD_SIZE):
  57. case EFUSE_HD_BASE ... (EFUSE_HD_BASE + EFUSE_HD_SIZE):
  58. case EFUSE_CTRL:
  59. /* cpu-clk related registers */
  60. case CLK_DIVIDER_REG:
  61. case CLK_DIVIDER_REG + CLUSTER_OFFSET:
  62. case CLK_FORCE_REG:
  63. case CLK_FORCE_REG + CLUSTER_OFFSET:
  64. #ifndef MVEBU_SOC_AP807
  65. case CLK_RATIO_REG:
  66. case CLK_RATIO_REG + CLUSTER_OFFSET:
  67. #endif
  68. case CLK_RATIO_STATE_REG:
  69. case CLK_RATIO_STATE_REG + CLUSTER_OFFSET:
  70. return true;
  71. default:
  72. return false;
  73. }
  74. }
  75. static int armada_dfx_sread(u_register_t *read, u_register_t addr)
  76. {
  77. if (!is_valid(addr))
  78. return -EINVAL;
  79. *read = mmio_read_32(addr);
  80. return 0;
  81. }
  82. static int armada_dfx_swrite(u_register_t addr, u_register_t val)
  83. {
  84. if (!is_valid(addr))
  85. return -EINVAL;
  86. mmio_write_32(addr, val);
  87. return 0;
  88. }
  89. int mvebu_dfx_misc_handle(u_register_t func, u_register_t *read,
  90. u_register_t addr, u_register_t val)
  91. {
  92. debug_enter();
  93. debug("func %ld, addr 0x%lx, val 0x%lx\n", func, addr, val);
  94. switch (func) {
  95. case MV_SIP_DFX_SREAD:
  96. return armada_dfx_sread(read, addr);
  97. case MV_SIP_DFX_SWRITE:
  98. return armada_dfx_swrite(addr, val);
  99. default:
  100. ERROR("unsupported dfx misc sub-func\n");
  101. return -EINVAL;
  102. }
  103. debug_exit();
  104. return 0;
  105. }