mtk_common.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2019 MediaTek Inc.
  4. */
  5. #ifndef __RPROC_MTK_COMMON_H
  6. #define __RPROC_MTK_COMMON_H
  7. #include <linux/interrupt.h>
  8. #include <linux/kernel.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/remoteproc.h>
  11. #include <linux/remoteproc/mtk_scp.h>
  12. #define MT8183_SW_RSTN 0x0
  13. #define MT8183_SW_RSTN_BIT BIT(0)
  14. #define MT8183_SCP_TO_HOST 0x1C
  15. #define MT8183_SCP_IPC_INT_BIT BIT(0)
  16. #define MT8183_SCP_WDT_INT_BIT BIT(8)
  17. #define MT8183_HOST_TO_SCP 0x28
  18. #define MT8183_HOST_IPC_INT_BIT BIT(0)
  19. #define MT8183_WDT_CFG 0x84
  20. #define MT8183_SCP_CLK_SW_SEL 0x4000
  21. #define MT8183_SCP_CLK_DIV_SEL 0x4024
  22. #define MT8183_SCP_SRAM_PDN 0x402C
  23. #define MT8183_SCP_L1_SRAM_PD 0x4080
  24. #define MT8183_SCP_TCM_TAIL_SRAM_PD 0x4094
  25. #define MT8183_SCP_CACHE_SEL(x) (0x14000 + (x) * 0x3000)
  26. #define MT8183_SCP_CACHE_CON MT8183_SCP_CACHE_SEL(0)
  27. #define MT8183_SCP_DCACHE_CON MT8183_SCP_CACHE_SEL(1)
  28. #define MT8183_SCP_CACHESIZE_8KB BIT(8)
  29. #define MT8183_SCP_CACHE_CON_WAYEN BIT(10)
  30. #define MT8186_SCP_L1_SRAM_PD_P1 0x40B0
  31. #define MT8186_SCP_L1_SRAM_PD_p2 0x40B4
  32. #define MT8192_L2TCM_SRAM_PD_0 0x10C0
  33. #define MT8192_L2TCM_SRAM_PD_1 0x10C4
  34. #define MT8192_L2TCM_SRAM_PD_2 0x10C8
  35. #define MT8192_L1TCM_SRAM_PDN 0x102C
  36. #define MT8192_CPU0_SRAM_PD 0x1080
  37. #define MT8192_SCP2APMCU_IPC_SET 0x4080
  38. #define MT8192_SCP2APMCU_IPC_CLR 0x4084
  39. #define MT8192_SCP_IPC_INT_BIT BIT(0)
  40. #define MT8192_SCP2SPM_IPC_CLR 0x4094
  41. #define MT8192_GIPC_IN_SET 0x4098
  42. #define MT8192_HOST_IPC_INT_BIT BIT(0)
  43. #define MT8195_CORE1_HOST_IPC_INT_BIT BIT(4)
  44. #define MT8192_CORE0_SW_RSTN_CLR 0x10000
  45. #define MT8192_CORE0_SW_RSTN_SET 0x10004
  46. #define MT8192_CORE0_MEM_ATT_PREDEF 0x10008
  47. #define MT8192_CORE0_WDT_IRQ 0x10030
  48. #define MT8192_CORE0_WDT_CFG 0x10034
  49. #define MT8195_SYS_STATUS 0x4004
  50. #define MT8195_CORE0_WDT BIT(16)
  51. #define MT8195_CORE1_WDT BIT(17)
  52. #define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS GENMASK(7, 4)
  53. #define MT8195_CPU1_SRAM_PD 0x1084
  54. #define MT8195_SSHUB2APMCU_IPC_SET 0x4088
  55. #define MT8195_SSHUB2APMCU_IPC_CLR 0x408C
  56. #define MT8195_CORE1_SW_RSTN_CLR 0x20000
  57. #define MT8195_CORE1_SW_RSTN_SET 0x20004
  58. #define MT8195_CORE1_MEM_ATT_PREDEF 0x20008
  59. #define MT8195_CORE1_WDT_IRQ 0x20030
  60. #define MT8195_CORE1_WDT_CFG 0x20034
  61. #define MT8195_SEC_CTRL 0x85000
  62. #define MT8195_CORE_OFFSET_ENABLE_D BIT(13)
  63. #define MT8195_CORE_OFFSET_ENABLE_I BIT(12)
  64. #define MT8195_L2TCM_OFFSET_RANGE_0_LOW 0x850b0
  65. #define MT8195_L2TCM_OFFSET_RANGE_0_HIGH 0x850b4
  66. #define MT8195_L2TCM_OFFSET 0x850d0
  67. #define SCP_FW_VER_LEN 32
  68. struct scp_run {
  69. u32 signaled;
  70. s8 fw_ver[SCP_FW_VER_LEN];
  71. u32 dec_capability;
  72. u32 enc_capability;
  73. wait_queue_head_t wq;
  74. };
  75. struct scp_ipi_desc {
  76. /* For protecting handler. */
  77. struct mutex lock;
  78. scp_ipi_handler_t handler;
  79. void *priv;
  80. };
  81. struct mtk_scp;
  82. struct mtk_scp_sizes_data {
  83. size_t max_dram_size;
  84. size_t ipi_share_buffer_size;
  85. };
  86. struct mtk_scp_of_data {
  87. int (*scp_clk_get)(struct mtk_scp *scp);
  88. int (*scp_before_load)(struct mtk_scp *scp);
  89. void (*scp_irq_handler)(struct mtk_scp *scp);
  90. void (*scp_reset_assert)(struct mtk_scp *scp);
  91. void (*scp_reset_deassert)(struct mtk_scp *scp);
  92. void (*scp_stop)(struct mtk_scp *scp);
  93. void *(*scp_da_to_va)(struct mtk_scp *scp, u64 da, size_t len);
  94. u32 host_to_scp_reg;
  95. u32 host_to_scp_int_bit;
  96. size_t ipi_buf_offset;
  97. const struct mtk_scp_sizes_data *scp_sizes;
  98. };
  99. struct mtk_scp_of_cluster {
  100. void __iomem *reg_base;
  101. void __iomem *l1tcm_base;
  102. size_t l1tcm_size;
  103. phys_addr_t l1tcm_phys;
  104. struct list_head mtk_scp_list;
  105. /* Prevent concurrent operations of this structure and L2TCM power control. */
  106. struct mutex cluster_lock;
  107. u32 l2tcm_refcnt;
  108. };
  109. struct mtk_scp {
  110. struct device *dev;
  111. struct rproc *rproc;
  112. struct clk *clk;
  113. void __iomem *sram_base;
  114. size_t sram_size;
  115. phys_addr_t sram_phys;
  116. const struct mtk_scp_of_data *data;
  117. struct mtk_share_obj __iomem *recv_buf;
  118. struct mtk_share_obj __iomem *send_buf;
  119. struct scp_run run;
  120. /* To prevent multiple ipi_send run concurrently. */
  121. struct mutex send_lock;
  122. struct scp_ipi_desc ipi_desc[SCP_IPI_MAX];
  123. bool ipi_id_ack[SCP_IPI_MAX];
  124. wait_queue_head_t ack_wq;
  125. u8 *share_buf;
  126. void *cpu_addr;
  127. dma_addr_t dma_addr;
  128. struct rproc_subdev *rpmsg_subdev;
  129. struct list_head elem;
  130. struct mtk_scp_of_cluster *cluster;
  131. };
  132. /**
  133. * struct mtk_share_obj - SRAM buffer shared with AP and SCP
  134. *
  135. * @id: IPI id
  136. * @len: share buffer length
  137. * @share_buf: share buffer data
  138. */
  139. struct mtk_share_obj {
  140. u32 id;
  141. u32 len;
  142. u8 *share_buf;
  143. };
  144. void scp_memcpy_aligned(void __iomem *dst, const void *src, unsigned int len);
  145. void scp_ipi_lock(struct mtk_scp *scp, u32 id);
  146. void scp_ipi_unlock(struct mtk_scp *scp, u32 id);
  147. #endif