hda_register.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * HD-audio controller (Azalia) registers and helpers
  4. *
  5. * For traditional reasons, we still use azx_ prefix here
  6. */
  7. #ifndef __SOUND_HDA_REGISTER_H
  8. #define __SOUND_HDA_REGISTER_H
  9. #include <linux/io.h>
  10. #include <sound/hdaudio.h>
  11. #define AZX_REG_GCAP 0x00
  12. #define AZX_GCAP_64OK (1 << 0) /* 64bit address support */
  13. #define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */
  14. #define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */
  15. #define AZX_GCAP_ISS (15 << 8) /* # of input streams */
  16. #define AZX_GCAP_OSS (15 << 12) /* # of output streams */
  17. #define AZX_REG_VMIN 0x02
  18. #define AZX_REG_VMAJ 0x03
  19. #define AZX_REG_OUTPAY 0x04
  20. #define AZX_REG_INPAY 0x06
  21. #define AZX_REG_GCTL 0x08
  22. #define AZX_GCTL_RESET (1 << 0) /* controller reset */
  23. #define AZX_GCTL_FCNTRL (1 << 1) /* flush control */
  24. #define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
  25. #define AZX_REG_WAKEEN 0x0c
  26. #define AZX_REG_STATESTS 0x0e
  27. #define AZX_REG_GSTS 0x10
  28. #define AZX_GSTS_FSTS (1 << 1) /* flush status */
  29. #define AZX_REG_GCAP2 0x12
  30. #define AZX_REG_LLCH 0x14
  31. #define AZX_REG_OUTSTRMPAY 0x18
  32. #define AZX_REG_INSTRMPAY 0x1A
  33. #define AZX_REG_INTCTL 0x20
  34. #define AZX_REG_INTSTS 0x24
  35. #define AZX_REG_WALLCLK 0x30 /* 24Mhz source */
  36. #define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
  37. #define AZX_REG_SSYNC 0x38
  38. #define AZX_REG_CORBLBASE 0x40
  39. #define AZX_REG_CORBUBASE 0x44
  40. #define AZX_REG_CORBWP 0x48
  41. #define AZX_REG_CORBRP 0x4a
  42. #define AZX_CORBRP_RST (1 << 15) /* read pointer reset */
  43. #define AZX_REG_CORBCTL 0x4c
  44. #define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */
  45. #define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
  46. #define AZX_REG_CORBSTS 0x4d
  47. #define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */
  48. #define AZX_REG_CORBSIZE 0x4e
  49. #define AZX_REG_RIRBLBASE 0x50
  50. #define AZX_REG_RIRBUBASE 0x54
  51. #define AZX_REG_RIRBWP 0x58
  52. #define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */
  53. #define AZX_REG_RINTCNT 0x5a
  54. #define AZX_REG_RIRBCTL 0x5c
  55. #define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
  56. #define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */
  57. #define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
  58. #define AZX_REG_RIRBSTS 0x5d
  59. #define AZX_RBSTS_IRQ (1 << 0) /* response irq */
  60. #define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */
  61. #define AZX_REG_RIRBSIZE 0x5e
  62. #define AZX_REG_IC 0x60
  63. #define AZX_REG_IR 0x64
  64. #define AZX_REG_IRS 0x68
  65. #define AZX_IRS_VALID (1<<1)
  66. #define AZX_IRS_BUSY (1<<0)
  67. #define AZX_REG_DPLBASE 0x70
  68. #define AZX_REG_DPUBASE 0x74
  69. #define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */
  70. /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  71. enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
  72. /* stream register offsets from stream base */
  73. #define AZX_REG_SD_CTL 0x00
  74. #define AZX_REG_SD_STS 0x03
  75. #define AZX_REG_SD_LPIB 0x04
  76. #define AZX_REG_SD_CBL 0x08
  77. #define AZX_REG_SD_LVI 0x0c
  78. #define AZX_REG_SD_FIFOW 0x0e
  79. #define AZX_REG_SD_FIFOSIZE 0x10
  80. #define AZX_REG_SD_FORMAT 0x12
  81. #define AZX_REG_SD_FIFOL 0x14
  82. #define AZX_REG_SD_BDLPL 0x18
  83. #define AZX_REG_SD_BDLPU 0x1c
  84. /* GTS registers */
  85. #define AZX_REG_LLCH 0x14
  86. #define AZX_REG_GTS_BASE 0x520
  87. #define AZX_REG_GTSCC (AZX_REG_GTS_BASE + 0x00)
  88. #define AZX_REG_WALFCC (AZX_REG_GTS_BASE + 0x04)
  89. #define AZX_REG_TSCCL (AZX_REG_GTS_BASE + 0x08)
  90. #define AZX_REG_TSCCU (AZX_REG_GTS_BASE + 0x0C)
  91. #define AZX_REG_LLPFOC (AZX_REG_GTS_BASE + 0x14)
  92. #define AZX_REG_LLPCL (AZX_REG_GTS_BASE + 0x18)
  93. #define AZX_REG_LLPCU (AZX_REG_GTS_BASE + 0x1C)
  94. /* Haswell/Broadwell display HD-A controller Extended Mode registers */
  95. #define AZX_REG_HSW_EM4 0x100c
  96. #define AZX_REG_HSW_EM5 0x1010
  97. /* Skylake/Broxton vendor-specific registers */
  98. #define AZX_REG_VS_EM1 0x1000
  99. #define AZX_REG_VS_INRC 0x1004
  100. #define AZX_REG_VS_OUTRC 0x1008
  101. #define AZX_REG_VS_FIFOTRK 0x100C
  102. #define AZX_REG_VS_FIFOTRK2 0x1010
  103. #define AZX_REG_VS_EM2 0x1030
  104. #define AZX_REG_VS_EM3L 0x1038
  105. #define AZX_REG_VS_EM3U 0x103C
  106. #define AZX_REG_VS_EM4L 0x1040
  107. #define AZX_REG_VS_EM4U 0x1044
  108. #define AZX_REG_VS_LTRC 0x1048
  109. #define AZX_REG_VS_D0I3C 0x104A
  110. #define AZX_REG_VS_PCE 0x104B
  111. #define AZX_REG_VS_L2MAGC 0x1050
  112. #define AZX_REG_VS_L2LAHPT 0x1054
  113. #define AZX_REG_VS_SDXDPIB_XBASE 0x1084
  114. #define AZX_REG_VS_SDXDPIB_XINTERVAL 0x20
  115. #define AZX_REG_VS_SDXEFIFOS_XBASE 0x1094
  116. #define AZX_REG_VS_SDXEFIFOS_XINTERVAL 0x20
  117. /* PCI space */
  118. #define AZX_PCIREG_TCSEL 0x44
  119. /*
  120. * other constants
  121. */
  122. /* max number of fragments - we may use more if allocating more pages for BDL */
  123. #define BDL_SIZE 4096
  124. #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  125. #define AZX_MAX_FRAG 32
  126. /* max buffer size - no h/w limit, you can increase as you like */
  127. #define AZX_MAX_BUF_SIZE (1024*1024*1024)
  128. /* RIRB int mask: overrun[2], response[0] */
  129. #define RIRB_INT_RESPONSE 0x01
  130. #define RIRB_INT_OVERRUN 0x04
  131. #define RIRB_INT_MASK 0x05
  132. /* STATESTS int mask: S3,SD2,SD1,SD0 */
  133. #define STATESTS_INT_MASK ((1 << HDA_MAX_CODECS) - 1)
  134. /* SD_CTL bits */
  135. #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
  136. #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
  137. #define SD_CTL_STRIPE (3 << 16) /* stripe control */
  138. #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
  139. #define SD_CTL_DIR (1 << 19) /* bi-directional stream */
  140. #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
  141. #define SD_CTL_STREAM_TAG_SHIFT 20
  142. /* SD_CTL and SD_STS */
  143. #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
  144. #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  145. #define SD_INT_COMPLETE 0x04 /* completion interrupt */
  146. #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
  147. SD_INT_COMPLETE)
  148. /* SD_STS */
  149. #define SD_STS_FIFO_READY 0x20 /* FIFO ready */
  150. /* INTCTL and INTSTS */
  151. #define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */
  152. #define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
  153. #define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
  154. /* below are so far hardcoded - should read registers in future */
  155. #define AZX_MAX_CORB_ENTRIES 256
  156. #define AZX_MAX_RIRB_ENTRIES 256
  157. /* Capability header Structure */
  158. #define AZX_REG_CAP_HDR 0x0
  159. #define AZX_CAP_HDR_VER_OFF 28
  160. #define AZX_CAP_HDR_VER_MASK (0xF << AZX_CAP_HDR_VER_OFF)
  161. #define AZX_CAP_HDR_ID_OFF 16
  162. #define AZX_CAP_HDR_ID_MASK (0xFFF << AZX_CAP_HDR_ID_OFF)
  163. #define AZX_CAP_HDR_NXT_PTR_MASK 0xFFFF
  164. /* registers of Software Position Based FIFO Capability Structure */
  165. #define AZX_SPB_CAP_ID 0x4
  166. #define AZX_REG_SPB_BASE_ADDR 0x700
  167. #define AZX_REG_SPB_SPBFCH 0x00
  168. #define AZX_REG_SPB_SPBFCCTL 0x04
  169. /* Base used to calculate the iterating register offset */
  170. #define AZX_SPB_BASE 0x08
  171. /* Interval used to calculate the iterating register offset */
  172. #define AZX_SPB_INTERVAL 0x08
  173. /* SPIB base */
  174. #define AZX_SPB_SPIB 0x00
  175. /* SPIB MAXFIFO base*/
  176. #define AZX_SPB_MAXFIFO 0x04
  177. /* registers of Global Time Synchronization Capability Structure */
  178. #define AZX_GTS_CAP_ID 0x1
  179. #define AZX_REG_GTS_GTSCH 0x00
  180. #define AZX_REG_GTS_GTSCD 0x04
  181. #define AZX_REG_GTS_GTSCTLAC 0x0C
  182. #define AZX_GTS_BASE 0x20
  183. #define AZX_GTS_INTERVAL 0x20
  184. /* registers for Processing Pipe Capability Structure */
  185. #define AZX_PP_CAP_ID 0x3
  186. #define AZX_REG_PP_PPCH 0x10
  187. #define AZX_REG_PP_PPCTL 0x04
  188. #define AZX_PPCTL_PIE (1<<31)
  189. #define AZX_PPCTL_GPROCEN (1<<30)
  190. /* _X_ = dma engine # and cannot * exceed 29 (per spec max 30 dma engines) */
  191. #define AZX_PPCTL_PROCEN(_X_) (1<<(_X_))
  192. #define AZX_REG_PP_PPSTS 0x08
  193. #define AZX_PPHC_BASE 0x10
  194. #define AZX_PPHC_INTERVAL 0x10
  195. #define AZX_REG_PPHCLLPL 0x0
  196. #define AZX_REG_PPHCLLPU 0x4
  197. #define AZX_REG_PPHCLDPL 0x8
  198. #define AZX_REG_PPHCLDPU 0xC
  199. #define AZX_PPLC_BASE 0x10
  200. #define AZX_PPLC_MULTI 0x10
  201. #define AZX_PPLC_INTERVAL 0x10
  202. #define AZX_REG_PPLCCTL 0x0
  203. #define AZX_PPLCCTL_STRM_BITS 4
  204. #define AZX_PPLCCTL_STRM_SHIFT 20
  205. #define AZX_REG_MASK(bit_num, offset) \
  206. (((1 << (bit_num)) - 1) << (offset))
  207. #define AZX_PPLCCTL_STRM_MASK \
  208. AZX_REG_MASK(AZX_PPLCCTL_STRM_BITS, AZX_PPLCCTL_STRM_SHIFT)
  209. #define AZX_PPLCCTL_RUN (1<<1)
  210. #define AZX_PPLCCTL_STRST (1<<0)
  211. #define AZX_REG_PPLCFMT 0x4
  212. #define AZX_REG_PPLCLLPL 0x8
  213. #define AZX_REG_PPLCLLPU 0xC
  214. /* registers for Multiple Links Capability Structure */
  215. #define AZX_ML_CAP_ID 0x2
  216. #define AZX_REG_ML_MLCH 0x00
  217. #define AZX_REG_ML_MLCD 0x04
  218. #define AZX_ML_BASE 0x40
  219. #define AZX_ML_INTERVAL 0x40
  220. #define AZX_REG_ML_LCAP 0x00
  221. #define AZX_REG_ML_LCTL 0x04
  222. #define AZX_REG_ML_LOSIDV 0x08
  223. #define AZX_REG_ML_LSDIID 0x0C
  224. #define AZX_REG_ML_LPSOO 0x10
  225. #define AZX_REG_ML_LPSIO 0x12
  226. #define AZX_REG_ML_LWALFC 0x18
  227. #define AZX_REG_ML_LOUTPAY 0x20
  228. #define AZX_REG_ML_LINPAY 0x30
  229. #define ML_LCTL_SCF_MASK 0xF
  230. #define AZX_MLCTL_SPA (0x1 << 16)
  231. #define AZX_MLCTL_CPA (0x1 << 23)
  232. #define AZX_MLCTL_SPA_SHIFT 16
  233. #define AZX_MLCTL_CPA_SHIFT 23
  234. /* registers for DMA Resume Capability Structure */
  235. #define AZX_DRSM_CAP_ID 0x5
  236. #define AZX_REG_DRSM_CTL 0x4
  237. /* Base used to calculate the iterating register offset */
  238. #define AZX_DRSM_BASE 0x08
  239. /* Interval used to calculate the iterating register offset */
  240. #define AZX_DRSM_INTERVAL 0x08
  241. /* Global time synchronization registers */
  242. #define GTSCC_TSCCD_MASK 0x80000000
  243. #define GTSCC_TSCCD_SHIFT BIT(31)
  244. #define GTSCC_TSCCI_MASK 0x20
  245. #define GTSCC_CDMAS_DMA_DIR_SHIFT 4
  246. #define WALFCC_CIF_MASK 0x1FF
  247. #define WALFCC_FN_SHIFT 9
  248. #define HDA_CLK_CYCLES_PER_FRAME 512
  249. /*
  250. * An error occurs near frame "rollover". The clocks in frame value indicates
  251. * whether this error may have occurred. Here we use the value of 10. Please
  252. * see the errata for the right number [<10]
  253. */
  254. #define HDA_MAX_CYCLE_VALUE 499
  255. #define HDA_MAX_CYCLE_OFFSET 10
  256. #define HDA_MAX_CYCLE_READ_RETRY 10
  257. #define TSCCU_CCU_SHIFT 32
  258. #define LLPC_CCU_SHIFT 32
  259. /*
  260. * helpers to read the stream position
  261. */
  262. static inline unsigned int
  263. snd_hdac_stream_get_pos_lpib(struct hdac_stream *stream)
  264. {
  265. return snd_hdac_stream_readl(stream, SD_LPIB);
  266. }
  267. static inline unsigned int
  268. snd_hdac_stream_get_pos_posbuf(struct hdac_stream *stream)
  269. {
  270. return le32_to_cpu(*stream->posbuf);
  271. }
  272. #endif /* __SOUND_HDA_REGISTER_H */