sst-dsp.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * Intel Smart Sound Technology (SST) Core
  3. *
  4. * Copyright (C) 2013, Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef __SOUND_SOC_SST_DSP_H
  17. #define __SOUND_SOC_SST_DSP_H
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/interrupt.h>
  21. /* SST Device IDs */
  22. #define SST_DEV_ID_LYNX_POINT 0x33C8
  23. #define SST_DEV_ID_WILDCAT_POINT 0x3438
  24. #define SST_DEV_ID_BYT 0x0F28
  25. /* Supported SST DMA Devices */
  26. #define SST_DMA_TYPE_DW 1
  27. /* autosuspend delay 5s*/
  28. #define SST_RUNTIME_SUSPEND_DELAY (5 * 1000)
  29. /* SST Shim register map
  30. * The register naming can differ between products. Some products also
  31. * contain extra functionality.
  32. */
  33. #define SST_CSR 0x00
  34. #define SST_PISR 0x08
  35. #define SST_PIMR 0x10
  36. #define SST_ISRX 0x18
  37. #define SST_ISRD 0x20
  38. #define SST_IMRX 0x28
  39. #define SST_IMRD 0x30
  40. #define SST_IPCX 0x38 /* IPC IA -> SST */
  41. #define SST_IPCD 0x40 /* IPC SST -> IA */
  42. #define SST_ISRSC 0x48
  43. #define SST_ISRLPESC 0x50
  44. #define SST_IMRSC 0x58
  45. #define SST_IMRLPESC 0x60
  46. #define SST_IPCSC 0x68
  47. #define SST_IPCLPESC 0x70
  48. #define SST_CLKCTL 0x78
  49. #define SST_CSR2 0x80
  50. #define SST_LTRC 0xE0
  51. #define SST_HMDC 0xE8
  52. #define SST_SHIM_BEGIN SST_CSR
  53. #define SST_SHIM_END SST_HDMC
  54. #define SST_DBGO 0xF0
  55. #define SST_SHIM_SIZE 0x100
  56. #define SST_PWMCTRL 0x1000
  57. /* SST Shim Register bits
  58. * The register bit naming can differ between products. Some products also
  59. * contain extra functionality.
  60. */
  61. /* CSR / CS */
  62. #define SST_CSR_RST (0x1 << 1)
  63. #define SST_CSR_SBCS0 (0x1 << 2)
  64. #define SST_CSR_SBCS1 (0x1 << 3)
  65. #define SST_CSR_DCS(x) (x << 4)
  66. #define SST_CSR_DCS_MASK (0x7 << 4)
  67. #define SST_CSR_STALL (0x1 << 10)
  68. #define SST_CSR_S0IOCS (0x1 << 21)
  69. #define SST_CSR_S1IOCS (0x1 << 23)
  70. #define SST_CSR_LPCS (0x1 << 31)
  71. #define SST_CSR_24MHZ_LPCS (SST_CSR_SBCS0 | SST_CSR_SBCS1 | SST_CSR_LPCS)
  72. #define SST_CSR_24MHZ_NO_LPCS (SST_CSR_SBCS0 | SST_CSR_SBCS1)
  73. #define SST_BYT_CSR_RST (0x1 << 0)
  74. #define SST_BYT_CSR_VECTOR_SEL (0x1 << 1)
  75. #define SST_BYT_CSR_STALL (0x1 << 2)
  76. #define SST_BYT_CSR_PWAITMODE (0x1 << 3)
  77. /* ISRX / ISC */
  78. #define SST_ISRX_BUSY (0x1 << 1)
  79. #define SST_ISRX_DONE (0x1 << 0)
  80. #define SST_BYT_ISRX_REQUEST (0x1 << 1)
  81. /* ISRD / ISD */
  82. #define SST_ISRD_BUSY (0x1 << 1)
  83. #define SST_ISRD_DONE (0x1 << 0)
  84. /* IMRX / IMC */
  85. #define SST_IMRX_BUSY (0x1 << 1)
  86. #define SST_IMRX_DONE (0x1 << 0)
  87. #define SST_BYT_IMRX_REQUEST (0x1 << 1)
  88. /* IMRD / IMD */
  89. #define SST_IMRD_DONE (0x1 << 0)
  90. #define SST_IMRD_BUSY (0x1 << 1)
  91. #define SST_IMRD_SSP0 (0x1 << 16)
  92. #define SST_IMRD_DMAC0 (0x1 << 21)
  93. #define SST_IMRD_DMAC1 (0x1 << 22)
  94. #define SST_IMRD_DMAC (SST_IMRD_DMAC0 | SST_IMRD_DMAC1)
  95. /* IPCX / IPCC */
  96. #define SST_IPCX_DONE (0x1 << 30)
  97. #define SST_IPCX_BUSY (0x1 << 31)
  98. #define SST_BYT_IPCX_DONE ((u64)0x1 << 62)
  99. #define SST_BYT_IPCX_BUSY ((u64)0x1 << 63)
  100. /* IPCD */
  101. #define SST_IPCD_DONE (0x1 << 30)
  102. #define SST_IPCD_BUSY (0x1 << 31)
  103. #define SST_BYT_IPCD_DONE ((u64)0x1 << 62)
  104. #define SST_BYT_IPCD_BUSY ((u64)0x1 << 63)
  105. /* CLKCTL */
  106. #define SST_CLKCTL_SMOS(x) (x << 24)
  107. #define SST_CLKCTL_MASK (3 << 24)
  108. #define SST_CLKCTL_DCPLCG (1 << 18)
  109. #define SST_CLKCTL_SCOE1 (1 << 17)
  110. #define SST_CLKCTL_SCOE0 (1 << 16)
  111. /* CSR2 / CS2 */
  112. #define SST_CSR2_SDFD_SSP0 (1 << 1)
  113. #define SST_CSR2_SDFD_SSP1 (1 << 2)
  114. /* LTRC */
  115. #define SST_LTRC_VAL(x) (x << 0)
  116. /* HMDC */
  117. #define SST_HMDC_HDDA0(x) (x << 0)
  118. #define SST_HMDC_HDDA1(x) (x << 7)
  119. #define SST_HMDC_HDDA_E0_CH0 1
  120. #define SST_HMDC_HDDA_E0_CH1 2
  121. #define SST_HMDC_HDDA_E0_CH2 4
  122. #define SST_HMDC_HDDA_E0_CH3 8
  123. #define SST_HMDC_HDDA_E1_CH0 SST_HMDC_HDDA1(SST_HMDC_HDDA_E0_CH0)
  124. #define SST_HMDC_HDDA_E1_CH1 SST_HMDC_HDDA1(SST_HMDC_HDDA_E0_CH1)
  125. #define SST_HMDC_HDDA_E1_CH2 SST_HMDC_HDDA1(SST_HMDC_HDDA_E0_CH2)
  126. #define SST_HMDC_HDDA_E1_CH3 SST_HMDC_HDDA1(SST_HMDC_HDDA_E0_CH3)
  127. #define SST_HMDC_HDDA_E0_ALLCH (SST_HMDC_HDDA_E0_CH0 | SST_HMDC_HDDA_E0_CH1 | \
  128. SST_HMDC_HDDA_E0_CH2 | SST_HMDC_HDDA_E0_CH3)
  129. #define SST_HMDC_HDDA_E1_ALLCH (SST_HMDC_HDDA_E1_CH0 | SST_HMDC_HDDA_E1_CH1 | \
  130. SST_HMDC_HDDA_E1_CH2 | SST_HMDC_HDDA_E1_CH3)
  131. /* SST Vendor Defined Registers and bits */
  132. #define SST_VDRTCTL0 0xa0
  133. #define SST_VDRTCTL1 0xa4
  134. #define SST_VDRTCTL2 0xa8
  135. #define SST_VDRTCTL3 0xaC
  136. /* VDRTCTL0 */
  137. #define SST_VDRTCL0_D3PGD (1 << 0)
  138. #define SST_VDRTCL0_D3SRAMPGD (1 << 1)
  139. #define SST_VDRTCL0_DSRAMPGE_SHIFT 12
  140. #define SST_VDRTCL0_DSRAMPGE_MASK (0xfffff << SST_VDRTCL0_DSRAMPGE_SHIFT)
  141. #define SST_VDRTCL0_ISRAMPGE_SHIFT 2
  142. #define SST_VDRTCL0_ISRAMPGE_MASK (0x3ff << SST_VDRTCL0_ISRAMPGE_SHIFT)
  143. /* VDRTCTL2 */
  144. #define SST_VDRTCL2_DCLCGE (1 << 1)
  145. #define SST_VDRTCL2_DTCGE (1 << 10)
  146. #define SST_VDRTCL2_APLLSE_MASK (1 << 31)
  147. /* PMCS */
  148. #define SST_PMCS 0x84
  149. #define SST_PMCS_PS_MASK 0x3
  150. struct sst_dsp;
  151. /*
  152. * SST Device.
  153. *
  154. * This structure is populated by the SST core driver.
  155. */
  156. struct sst_dsp_device {
  157. /* Mandatory fields */
  158. struct sst_ops *ops;
  159. irqreturn_t (*thread)(int irq, void *context);
  160. void *thread_context;
  161. };
  162. /*
  163. * SST Platform Data.
  164. */
  165. struct sst_pdata {
  166. /* ACPI data */
  167. u32 lpe_base;
  168. u32 lpe_size;
  169. u32 pcicfg_base;
  170. u32 pcicfg_size;
  171. u32 fw_base;
  172. u32 fw_size;
  173. int irq;
  174. /* Firmware */
  175. const struct firmware *fw;
  176. /* DMA */
  177. int resindex_dma_base; /* other fields invalid if equals to -1 */
  178. u32 dma_base;
  179. u32 dma_size;
  180. int dma_engine;
  181. struct device *dma_dev;
  182. /* DSP */
  183. u32 id;
  184. void *dsp;
  185. };
  186. #if IS_ENABLED(CONFIG_DW_DMAC_CORE)
  187. /* Initialization */
  188. struct sst_dsp *sst_dsp_new(struct device *dev,
  189. struct sst_dsp_device *sst_dev, struct sst_pdata *pdata);
  190. void sst_dsp_free(struct sst_dsp *sst);
  191. #endif
  192. /* SHIM Read / Write */
  193. void sst_dsp_shim_write(struct sst_dsp *sst, u32 offset, u32 value);
  194. u32 sst_dsp_shim_read(struct sst_dsp *sst, u32 offset);
  195. int sst_dsp_shim_update_bits(struct sst_dsp *sst, u32 offset,
  196. u32 mask, u32 value);
  197. void sst_dsp_shim_write64(struct sst_dsp *sst, u32 offset, u64 value);
  198. u64 sst_dsp_shim_read64(struct sst_dsp *sst, u32 offset);
  199. int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset,
  200. u64 mask, u64 value);
  201. void sst_dsp_shim_update_bits_forced(struct sst_dsp *sst, u32 offset,
  202. u32 mask, u32 value);
  203. /* SHIM Read / Write Unlocked for callers already holding sst lock */
  204. void sst_dsp_shim_write_unlocked(struct sst_dsp *sst, u32 offset, u32 value);
  205. u32 sst_dsp_shim_read_unlocked(struct sst_dsp *sst, u32 offset);
  206. int sst_dsp_shim_update_bits_unlocked(struct sst_dsp *sst, u32 offset,
  207. u32 mask, u32 value);
  208. void sst_dsp_shim_write64_unlocked(struct sst_dsp *sst, u32 offset, u64 value);
  209. u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset);
  210. int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset,
  211. u64 mask, u64 value);
  212. void sst_dsp_shim_update_bits_forced_unlocked(struct sst_dsp *sst, u32 offset,
  213. u32 mask, u32 value);
  214. /* Internal generic low-level SST IO functions - can be overidden */
  215. void sst_shim32_write(void __iomem *addr, u32 offset, u32 value);
  216. u32 sst_shim32_read(void __iomem *addr, u32 offset);
  217. void sst_shim32_write64(void __iomem *addr, u32 offset, u64 value);
  218. u64 sst_shim32_read64(void __iomem *addr, u32 offset);
  219. void sst_memcpy_toio_32(struct sst_dsp *sst,
  220. void __iomem *dest, void *src, size_t bytes);
  221. void sst_memcpy_fromio_32(struct sst_dsp *sst,
  222. void *dest, void __iomem *src, size_t bytes);
  223. /* DSP reset & boot */
  224. void sst_dsp_reset(struct sst_dsp *sst);
  225. int sst_dsp_boot(struct sst_dsp *sst);
  226. int sst_dsp_wake(struct sst_dsp *sst);
  227. void sst_dsp_sleep(struct sst_dsp *sst);
  228. void sst_dsp_stall(struct sst_dsp *sst);
  229. /* DMA */
  230. int sst_dsp_dma_get_channel(struct sst_dsp *dsp, int chan_id);
  231. void sst_dsp_dma_put_channel(struct sst_dsp *dsp);
  232. int sst_dsp_dma_copyfrom(struct sst_dsp *sst, dma_addr_t dest_addr,
  233. dma_addr_t src_addr, size_t size);
  234. int sst_dsp_dma_copyto(struct sst_dsp *sst, dma_addr_t dest_addr,
  235. dma_addr_t src_addr, size_t size);
  236. /* Msg IO */
  237. void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg);
  238. u32 sst_dsp_ipc_msg_rx(struct sst_dsp *dsp);
  239. /* Mailbox management */
  240. int sst_dsp_mailbox_init(struct sst_dsp *dsp, u32 inbox_offset,
  241. size_t inbox_size, u32 outbox_offset, size_t outbox_size);
  242. void sst_dsp_inbox_write(struct sst_dsp *dsp, void *message, size_t bytes);
  243. void sst_dsp_inbox_read(struct sst_dsp *dsp, void *message, size_t bytes);
  244. void sst_dsp_outbox_write(struct sst_dsp *dsp, void *message, size_t bytes);
  245. void sst_dsp_outbox_read(struct sst_dsp *dsp, void *message, size_t bytes);
  246. void sst_dsp_mailbox_dump(struct sst_dsp *dsp, size_t bytes);
  247. int sst_dsp_register_poll(struct sst_dsp *dsp, u32 offset, u32 mask,
  248. u32 expected_value, u32 timeout, char *operation);
  249. /* Debug */
  250. void sst_dsp_dump(struct sst_dsp *sst);
  251. #endif