Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * HD-audio controller (Azalia) registers and helpers
0004  *
0005  * For traditional reasons, we still use azx_ prefix here
0006  */
0007 
0008 #ifndef __SOUND_HDA_REGISTER_H
0009 #define __SOUND_HDA_REGISTER_H
0010 
0011 #include <linux/io.h>
0012 #include <sound/hdaudio.h>
0013 
0014 #define AZX_REG_GCAP            0x00
0015 #define   AZX_GCAP_64OK     (1 << 0)   /* 64bit address support */
0016 #define   AZX_GCAP_NSDO     (3 << 1)   /* # of serial data out signals */
0017 #define   AZX_GCAP_BSS      (31 << 3)  /* # of bidirectional streams */
0018 #define   AZX_GCAP_ISS      (15 << 8)  /* # of input streams */
0019 #define   AZX_GCAP_OSS      (15 << 12) /* # of output streams */
0020 #define AZX_REG_VMIN            0x02
0021 #define AZX_REG_VMAJ            0x03
0022 #define AZX_REG_OUTPAY          0x04
0023 #define AZX_REG_INPAY           0x06
0024 #define AZX_REG_GCTL            0x08
0025 #define   AZX_GCTL_RESET    (1 << 0)   /* controller reset */
0026 #define   AZX_GCTL_FCNTRL   (1 << 1)   /* flush control */
0027 #define   AZX_GCTL_UNSOL    (1 << 8)   /* accept unsol. response enable */
0028 #define AZX_REG_WAKEEN          0x0c
0029 #define AZX_REG_STATESTS        0x0e
0030 #define AZX_REG_GSTS            0x10
0031 #define   AZX_GSTS_FSTS     (1 << 1)   /* flush status */
0032 #define AZX_REG_GCAP2           0x12
0033 #define AZX_REG_LLCH            0x14
0034 #define AZX_REG_OUTSTRMPAY      0x18
0035 #define AZX_REG_INSTRMPAY       0x1A
0036 #define AZX_REG_INTCTL          0x20
0037 #define AZX_REG_INTSTS          0x24
0038 #define AZX_REG_WALLCLK         0x30    /* 24Mhz source */
0039 #define AZX_REG_OLD_SSYNC       0x34    /* SSYNC for old ICH */
0040 #define AZX_REG_SSYNC           0x38
0041 #define AZX_REG_CORBLBASE       0x40
0042 #define AZX_REG_CORBUBASE       0x44
0043 #define AZX_REG_CORBWP          0x48
0044 #define AZX_REG_CORBRP          0x4a
0045 #define   AZX_CORBRP_RST    (1 << 15)  /* read pointer reset */
0046 #define AZX_REG_CORBCTL         0x4c
0047 #define   AZX_CORBCTL_RUN   (1 << 1)   /* enable DMA */
0048 #define   AZX_CORBCTL_CMEIE (1 << 0)   /* enable memory error irq */
0049 #define AZX_REG_CORBSTS         0x4d
0050 #define   AZX_CORBSTS_CMEI  (1 << 0)   /* memory error indication */
0051 #define AZX_REG_CORBSIZE        0x4e
0052 
0053 #define AZX_REG_RIRBLBASE       0x50
0054 #define AZX_REG_RIRBUBASE       0x54
0055 #define AZX_REG_RIRBWP          0x58
0056 #define   AZX_RIRBWP_RST    (1 << 15)  /* write pointer reset */
0057 #define AZX_REG_RINTCNT         0x5a
0058 #define AZX_REG_RIRBCTL         0x5c
0059 #define   AZX_RBCTL_IRQ_EN  (1 << 0)   /* enable IRQ */
0060 #define   AZX_RBCTL_DMA_EN  (1 << 1)   /* enable DMA */
0061 #define   AZX_RBCTL_OVERRUN_EN  (1 << 2)   /* enable overrun irq */
0062 #define AZX_REG_RIRBSTS         0x5d
0063 #define   AZX_RBSTS_IRQ     (1 << 0)   /* response irq */
0064 #define   AZX_RBSTS_OVERRUN (1 << 2)   /* overrun irq */
0065 #define AZX_REG_RIRBSIZE        0x5e
0066 
0067 #define AZX_REG_IC          0x60
0068 #define AZX_REG_IR          0x64
0069 #define AZX_REG_IRS         0x68
0070 #define   AZX_IRS_VALID     (1<<1)
0071 #define   AZX_IRS_BUSY      (1<<0)
0072 
0073 #define AZX_REG_DPLBASE         0x70
0074 #define AZX_REG_DPUBASE         0x74
0075 #define   AZX_DPLBASE_ENABLE    0x1 /* Enable position buffer */
0076 
0077 /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
0078 enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
0079 
0080 /* stream register offsets from stream base */
0081 #define AZX_REG_SD_CTL          0x00
0082 #define AZX_REG_SD_CTL_3B       0x02 /* 3rd byte of SD_CTL register */
0083 #define AZX_REG_SD_STS          0x03
0084 #define AZX_REG_SD_LPIB         0x04
0085 #define AZX_REG_SD_CBL          0x08
0086 #define AZX_REG_SD_LVI          0x0c
0087 #define AZX_REG_SD_FIFOW        0x0e
0088 #define AZX_REG_SD_FIFOSIZE     0x10
0089 #define AZX_REG_SD_FORMAT       0x12
0090 #define AZX_REG_SD_FIFOL        0x14
0091 #define AZX_REG_SD_BDLPL        0x18
0092 #define AZX_REG_SD_BDLPU        0x1c
0093 
0094 /* GTS registers */
0095 #define AZX_REG_LLCH            0x14
0096 
0097 #define AZX_REG_GTS_BASE        0x520
0098 
0099 #define AZX_REG_GTSCC   (AZX_REG_GTS_BASE + 0x00)
0100 #define AZX_REG_WALFCC  (AZX_REG_GTS_BASE + 0x04)
0101 #define AZX_REG_TSCCL   (AZX_REG_GTS_BASE + 0x08)
0102 #define AZX_REG_TSCCU   (AZX_REG_GTS_BASE + 0x0C)
0103 #define AZX_REG_LLPFOC  (AZX_REG_GTS_BASE + 0x14)
0104 #define AZX_REG_LLPCL   (AZX_REG_GTS_BASE + 0x18)
0105 #define AZX_REG_LLPCU   (AZX_REG_GTS_BASE + 0x1C)
0106 
0107 /* Haswell/Broadwell display HD-A controller Extended Mode registers */
0108 #define AZX_REG_HSW_EM4         0x100c
0109 #define AZX_REG_HSW_EM5         0x1010
0110 
0111 /* Skylake/Broxton vendor-specific registers */
0112 #define AZX_REG_VS_EM1          0x1000
0113 #define AZX_REG_VS_INRC         0x1004
0114 #define AZX_REG_VS_OUTRC        0x1008
0115 #define AZX_REG_VS_FIFOTRK      0x100C
0116 #define AZX_REG_VS_FIFOTRK2     0x1010
0117 #define AZX_REG_VS_EM2          0x1030
0118 #define AZX_REG_VS_EM3L         0x1038
0119 #define AZX_REG_VS_EM3U         0x103C
0120 #define AZX_REG_VS_EM4L         0x1040
0121 #define AZX_REG_VS_EM4U         0x1044
0122 #define AZX_REG_VS_LTRP         0x1048
0123 #define AZX_REG_VS_D0I3C        0x104A
0124 #define AZX_REG_VS_PCE          0x104B
0125 #define AZX_REG_VS_L2MAGC       0x1050
0126 #define AZX_REG_VS_L2LAHPT      0x1054
0127 #define AZX_REG_VS_SDXDPIB_XBASE    0x1084
0128 #define AZX_REG_VS_SDXDPIB_XINTERVAL    0x20
0129 #define AZX_REG_VS_SDXEFIFOS_XBASE  0x1094
0130 #define AZX_REG_VS_SDXEFIFOS_XINTERVAL  0x20
0131 
0132 /* PCI space */
0133 #define AZX_PCIREG_TCSEL        0x44
0134 
0135 /*
0136  * other constants
0137  */
0138 
0139 /* max number of fragments - we may use more if allocating more pages for BDL */
0140 #define BDL_SIZE        4096
0141 #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
0142 #define AZX_MAX_FRAG        32
0143 /*
0144  * max buffer size - artificial 4MB limit per stream to avoid big allocations
0145  * In theory it can be really big, but as it is per stream on systems with many streams memory could
0146  * be quickly saturated if userspace requests maximum buffer size for each of them.
0147  */
0148 #define AZX_MAX_BUF_SIZE    (4*1024*1024)
0149 
0150 /* RIRB int mask: overrun[2], response[0] */
0151 #define RIRB_INT_RESPONSE   0x01
0152 #define RIRB_INT_OVERRUN    0x04
0153 #define RIRB_INT_MASK       0x05
0154 
0155 /* STATESTS int mask: S3,SD2,SD1,SD0 */
0156 #define STATESTS_INT_MASK   ((1 << HDA_MAX_CODECS) - 1)
0157 
0158 /* SD_CTL bits */
0159 #define SD_CTL_STREAM_RESET 0x01    /* stream reset bit */
0160 #define SD_CTL_DMA_START    0x02    /* stream DMA start bit */
0161 #define SD_CTL_STRIPE       (3 << 16)   /* stripe control */
0162 #define SD_CTL_TRAFFIC_PRIO (1 << 18)   /* traffic priority */
0163 #define SD_CTL_DIR      (1 << 19)   /* bi-directional stream */
0164 #define SD_CTL_STREAM_TAG_MASK  (0xf << 20)
0165 #define SD_CTL_STREAM_TAG_SHIFT 20
0166 
0167 /* SD_CTL and SD_STS */
0168 #define SD_INT_DESC_ERR     0x10    /* descriptor error interrupt */
0169 #define SD_INT_FIFO_ERR     0x08    /* FIFO error interrupt */
0170 #define SD_INT_COMPLETE     0x04    /* completion interrupt */
0171 #define SD_INT_MASK     (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
0172                  SD_INT_COMPLETE)
0173 #define SD_CTL_STRIPE_MASK  0x3 /* stripe control mask */
0174 
0175 /* SD_STS */
0176 #define SD_STS_FIFO_READY   0x20    /* FIFO ready */
0177 
0178 /* INTCTL and INTSTS */
0179 #define AZX_INT_ALL_STREAM  0xff       /* all stream interrupts */
0180 #define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
0181 #define AZX_INT_GLOBAL_EN   0x80000000 /* global interrupt enable bit */
0182 
0183 /* below are so far hardcoded - should read registers in future */
0184 #define AZX_MAX_CORB_ENTRIES    256
0185 #define AZX_MAX_RIRB_ENTRIES    256
0186 
0187 /* Capability header  Structure */
0188 #define AZX_REG_CAP_HDR         0x0
0189 #define AZX_CAP_HDR_VER_OFF     28
0190 #define AZX_CAP_HDR_VER_MASK        (0xF << AZX_CAP_HDR_VER_OFF)
0191 #define AZX_CAP_HDR_ID_OFF      16
0192 #define AZX_CAP_HDR_ID_MASK     (0xFFF << AZX_CAP_HDR_ID_OFF)
0193 #define AZX_CAP_HDR_NXT_PTR_MASK    0xFFFF
0194 
0195 /* registers of Software Position Based FIFO Capability Structure */
0196 #define AZX_SPB_CAP_ID          0x4
0197 #define AZX_REG_SPB_BASE_ADDR       0x700
0198 #define AZX_REG_SPB_SPBFCH      0x00
0199 #define AZX_REG_SPB_SPBFCCTL        0x04
0200 /* Base used to calculate the iterating register offset */
0201 #define AZX_SPB_BASE            0x08
0202 /* Interval used to calculate the iterating register offset */
0203 #define AZX_SPB_INTERVAL        0x08
0204 /* SPIB base */
0205 #define AZX_SPB_SPIB            0x00
0206 /* SPIB MAXFIFO base*/
0207 #define AZX_SPB_MAXFIFO         0x04
0208 
0209 /* registers of Global Time Synchronization Capability Structure */
0210 #define AZX_GTS_CAP_ID          0x1
0211 #define AZX_REG_GTS_GTSCH       0x00
0212 #define AZX_REG_GTS_GTSCD       0x04
0213 #define AZX_REG_GTS_GTSCTLAC        0x0C
0214 #define AZX_GTS_BASE            0x20
0215 #define AZX_GTS_INTERVAL        0x20
0216 
0217 /* registers for Processing Pipe Capability Structure */
0218 #define AZX_PP_CAP_ID           0x3
0219 #define AZX_REG_PP_PPCH         0x10
0220 #define AZX_REG_PP_PPCTL        0x04
0221 #define AZX_PPCTL_PIE           (1<<31)
0222 #define AZX_PPCTL_GPROCEN       (1<<30)
0223 /* _X_ = dma engine # and cannot * exceed 29 (per spec max 30 dma engines) */
0224 #define AZX_PPCTL_PROCEN(_X_)       (1<<(_X_))
0225 
0226 #define AZX_REG_PP_PPSTS        0x08
0227 
0228 #define AZX_PPHC_BASE           0x10
0229 #define AZX_PPHC_INTERVAL       0x10
0230 
0231 #define AZX_REG_PPHCLLPL        0x0
0232 #define AZX_REG_PPHCLLPU        0x4
0233 #define AZX_REG_PPHCLDPL        0x8
0234 #define AZX_REG_PPHCLDPU        0xC
0235 
0236 #define AZX_PPLC_BASE           0x10
0237 #define AZX_PPLC_MULTI          0x10
0238 #define AZX_PPLC_INTERVAL       0x10
0239 
0240 #define AZX_REG_PPLCCTL         0x0
0241 #define AZX_PPLCCTL_STRM_BITS       4
0242 #define AZX_PPLCCTL_STRM_SHIFT      20
0243 #define AZX_REG_MASK(bit_num, offset) \
0244     (((1 << (bit_num)) - 1) << (offset))
0245 #define AZX_PPLCCTL_STRM_MASK \
0246     AZX_REG_MASK(AZX_PPLCCTL_STRM_BITS, AZX_PPLCCTL_STRM_SHIFT)
0247 #define AZX_PPLCCTL_RUN         (1<<1)
0248 #define AZX_PPLCCTL_STRST       (1<<0)
0249 
0250 #define AZX_REG_PPLCFMT         0x4
0251 #define AZX_REG_PPLCLLPL        0x8
0252 #define AZX_REG_PPLCLLPU        0xC
0253 
0254 /* registers for Multiple Links Capability Structure */
0255 #define AZX_ML_CAP_ID           0x2
0256 #define AZX_REG_ML_MLCH         0x00
0257 #define AZX_REG_ML_MLCD         0x04
0258 #define AZX_ML_BASE         0x40
0259 #define AZX_ML_INTERVAL         0x40
0260 
0261 #define AZX_REG_ML_LCAP         0x00
0262 #define AZX_REG_ML_LCTL         0x04
0263 #define AZX_REG_ML_LOSIDV       0x08
0264 #define AZX_REG_ML_LSDIID       0x0C
0265 #define AZX_REG_ML_LPSOO        0x10
0266 #define AZX_REG_ML_LPSIO        0x12
0267 #define AZX_REG_ML_LWALFC       0x18
0268 #define AZX_REG_ML_LOUTPAY      0x20
0269 #define AZX_REG_ML_LINPAY       0x30
0270 
0271 /* bit0 is reserved, with BIT(1) mapping to stream1 */
0272 #define ML_LOSIDV_STREAM_MASK       0xFFFE
0273 
0274 #define ML_LCTL_SCF_MASK            0xF
0275 #define AZX_MLCTL_SPA               (0x1 << 16)
0276 #define AZX_MLCTL_CPA               (0x1 << 23)
0277 #define AZX_MLCTL_SPA_SHIFT         16
0278 #define AZX_MLCTL_CPA_SHIFT         23
0279 
0280 /* registers for DMA Resume Capability Structure */
0281 #define AZX_DRSM_CAP_ID         0x5
0282 #define AZX_REG_DRSM_CTL        0x4
0283 /* Base used to calculate the iterating register offset */
0284 #define AZX_DRSM_BASE           0x08
0285 /* Interval used to calculate the iterating register offset */
0286 #define AZX_DRSM_INTERVAL       0x08
0287 
0288 /* Global time synchronization registers */
0289 #define GTSCC_TSCCD_MASK        0x80000000
0290 #define GTSCC_TSCCD_SHIFT       BIT(31)
0291 #define GTSCC_TSCCI_MASK        0x20
0292 #define GTSCC_CDMAS_DMA_DIR_SHIFT   4
0293 
0294 #define WALFCC_CIF_MASK         0x1FF
0295 #define WALFCC_FN_SHIFT         9
0296 #define HDA_CLK_CYCLES_PER_FRAME    512
0297 
0298 /*
0299  * An error occurs near frame "rollover". The clocks in frame value indicates
0300  * whether this error may have occurred. Here we use the value of 10. Please
0301  * see the errata for the right number [<10]
0302  */
0303 #define HDA_MAX_CYCLE_VALUE     499
0304 #define HDA_MAX_CYCLE_OFFSET        10
0305 #define HDA_MAX_CYCLE_READ_RETRY    10
0306 
0307 #define TSCCU_CCU_SHIFT         32
0308 #define LLPC_CCU_SHIFT          32
0309 
0310 
0311 /*
0312  * helpers to read the stream position
0313  */
0314 static inline unsigned int
0315 snd_hdac_stream_get_pos_lpib(struct hdac_stream *stream)
0316 {
0317     return snd_hdac_stream_readl(stream, SD_LPIB);
0318 }
0319 
0320 static inline unsigned int
0321 snd_hdac_stream_get_pos_posbuf(struct hdac_stream *stream)
0322 {
0323     return le32_to_cpu(*stream->posbuf);
0324 }
0325 
0326 #endif /* __SOUND_HDA_REGISTER_H */