0001
0002
0003
0004
0005
0006 #ifndef __FSL_SAI_H
0007 #define __FSL_SAI_H
0008
0009 #include <sound/dmaengine_pcm.h>
0010
0011 #define FSL_SAI_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
0012 SNDRV_PCM_FMTBIT_S20_3LE |\
0013 SNDRV_PCM_FMTBIT_S24_LE |\
0014 SNDRV_PCM_FMTBIT_S32_LE |\
0015 SNDRV_PCM_FMTBIT_DSD_U8 |\
0016 SNDRV_PCM_FMTBIT_DSD_U16_LE |\
0017 SNDRV_PCM_FMTBIT_DSD_U32_LE)
0018
0019
0020 #define FSL_SAI_VERID 0x00
0021 #define FSL_SAI_PARAM 0x04
0022 #define FSL_SAI_TCSR(ofs) (0x00 + ofs)
0023 #define FSL_SAI_TCR1(ofs) (0x04 + ofs)
0024 #define FSL_SAI_TCR2(ofs) (0x08 + ofs)
0025 #define FSL_SAI_TCR3(ofs) (0x0c + ofs)
0026 #define FSL_SAI_TCR4(ofs) (0x10 + ofs)
0027 #define FSL_SAI_TCR5(ofs) (0x14 + ofs)
0028 #define FSL_SAI_TDR0 0x20
0029 #define FSL_SAI_TDR1 0x24
0030 #define FSL_SAI_TDR2 0x28
0031 #define FSL_SAI_TDR3 0x2C
0032 #define FSL_SAI_TDR4 0x30
0033 #define FSL_SAI_TDR5 0x34
0034 #define FSL_SAI_TDR6 0x38
0035 #define FSL_SAI_TDR7 0x3C
0036 #define FSL_SAI_TFR0 0x40
0037 #define FSL_SAI_TFR1 0x44
0038 #define FSL_SAI_TFR2 0x48
0039 #define FSL_SAI_TFR3 0x4C
0040 #define FSL_SAI_TFR4 0x50
0041 #define FSL_SAI_TFR5 0x54
0042 #define FSL_SAI_TFR6 0x58
0043 #define FSL_SAI_TFR7 0x5C
0044 #define FSL_SAI_TMR 0x60
0045 #define FSL_SAI_TTCTL 0x70
0046 #define FSL_SAI_TTCTN 0x74
0047 #define FSL_SAI_TBCTN 0x78
0048 #define FSL_SAI_TTCAP 0x7C
0049 #define FSL_SAI_RCSR(ofs) (0x80 + ofs)
0050 #define FSL_SAI_RCR1(ofs) (0x84 + ofs)
0051 #define FSL_SAI_RCR2(ofs) (0x88 + ofs)
0052 #define FSL_SAI_RCR3(ofs) (0x8c + ofs)
0053 #define FSL_SAI_RCR4(ofs) (0x90 + ofs)
0054 #define FSL_SAI_RCR5(ofs) (0x94 + ofs)
0055 #define FSL_SAI_RDR0 0xa0
0056 #define FSL_SAI_RDR1 0xa4
0057 #define FSL_SAI_RDR2 0xa8
0058 #define FSL_SAI_RDR3 0xac
0059 #define FSL_SAI_RDR4 0xb0
0060 #define FSL_SAI_RDR5 0xb4
0061 #define FSL_SAI_RDR6 0xb8
0062 #define FSL_SAI_RDR7 0xbc
0063 #define FSL_SAI_RFR0 0xc0
0064 #define FSL_SAI_RFR1 0xc4
0065 #define FSL_SAI_RFR2 0xc8
0066 #define FSL_SAI_RFR3 0xcc
0067 #define FSL_SAI_RFR4 0xd0
0068 #define FSL_SAI_RFR5 0xd4
0069 #define FSL_SAI_RFR6 0xd8
0070 #define FSL_SAI_RFR7 0xdc
0071 #define FSL_SAI_RMR 0xe0
0072 #define FSL_SAI_RTCTL 0xf0
0073 #define FSL_SAI_RTCTN 0xf4
0074 #define FSL_SAI_RBCTN 0xf8
0075 #define FSL_SAI_RTCAP 0xfc
0076
0077 #define FSL_SAI_MCTL 0x100
0078 #define FSL_SAI_MDIV 0x104
0079
0080 #define FSL_SAI_xCSR(tx, ofs) (tx ? FSL_SAI_TCSR(ofs) : FSL_SAI_RCSR(ofs))
0081 #define FSL_SAI_xCR1(tx, ofs) (tx ? FSL_SAI_TCR1(ofs) : FSL_SAI_RCR1(ofs))
0082 #define FSL_SAI_xCR2(tx, ofs) (tx ? FSL_SAI_TCR2(ofs) : FSL_SAI_RCR2(ofs))
0083 #define FSL_SAI_xCR3(tx, ofs) (tx ? FSL_SAI_TCR3(ofs) : FSL_SAI_RCR3(ofs))
0084 #define FSL_SAI_xCR4(tx, ofs) (tx ? FSL_SAI_TCR4(ofs) : FSL_SAI_RCR4(ofs))
0085 #define FSL_SAI_xCR5(tx, ofs) (tx ? FSL_SAI_TCR5(ofs) : FSL_SAI_RCR5(ofs))
0086 #define FSL_SAI_xDR0(tx) (tx ? FSL_SAI_TDR0 : FSL_SAI_RDR0)
0087 #define FSL_SAI_xFR0(tx) (tx ? FSL_SAI_TFR0 : FSL_SAI_RFR0)
0088 #define FSL_SAI_xMR(tx) (tx ? FSL_SAI_TMR : FSL_SAI_RMR)
0089
0090
0091 #define FSL_SAI_CSR_TERE BIT(31)
0092 #define FSL_SAI_CSR_SE BIT(30)
0093 #define FSL_SAI_CSR_FR BIT(25)
0094 #define FSL_SAI_CSR_SR BIT(24)
0095 #define FSL_SAI_CSR_xF_SHIFT 16
0096 #define FSL_SAI_CSR_xF_W_SHIFT 18
0097 #define FSL_SAI_CSR_xF_MASK (0x1f << FSL_SAI_CSR_xF_SHIFT)
0098 #define FSL_SAI_CSR_xF_W_MASK (0x7 << FSL_SAI_CSR_xF_W_SHIFT)
0099 #define FSL_SAI_CSR_WSF BIT(20)
0100 #define FSL_SAI_CSR_SEF BIT(19)
0101 #define FSL_SAI_CSR_FEF BIT(18)
0102 #define FSL_SAI_CSR_FWF BIT(17)
0103 #define FSL_SAI_CSR_FRF BIT(16)
0104 #define FSL_SAI_CSR_xIE_SHIFT 8
0105 #define FSL_SAI_CSR_xIE_MASK (0x1f << FSL_SAI_CSR_xIE_SHIFT)
0106 #define FSL_SAI_CSR_WSIE BIT(12)
0107 #define FSL_SAI_CSR_SEIE BIT(11)
0108 #define FSL_SAI_CSR_FEIE BIT(10)
0109 #define FSL_SAI_CSR_FWIE BIT(9)
0110 #define FSL_SAI_CSR_FRIE BIT(8)
0111 #define FSL_SAI_CSR_FRDE BIT(0)
0112
0113
0114 #define FSL_SAI_CR1_RFW_MASK(x) ((x) - 1)
0115
0116
0117 #define FSL_SAI_CR2_SYNC BIT(30)
0118 #define FSL_SAI_CR2_MSEL_MASK (0x3 << 26)
0119 #define FSL_SAI_CR2_MSEL_BUS 0
0120 #define FSL_SAI_CR2_MSEL_MCLK1 BIT(26)
0121 #define FSL_SAI_CR2_MSEL_MCLK2 BIT(27)
0122 #define FSL_SAI_CR2_MSEL_MCLK3 (BIT(26) | BIT(27))
0123 #define FSL_SAI_CR2_MSEL(ID) ((ID) << 26)
0124 #define FSL_SAI_CR2_BCP BIT(25)
0125 #define FSL_SAI_CR2_BCD_MSTR BIT(24)
0126 #define FSL_SAI_CR2_BYP BIT(23)
0127 #define FSL_SAI_CR2_DIV_MASK 0xff
0128
0129
0130 #define FSL_SAI_CR3_TRCE(x) ((x) << 16)
0131 #define FSL_SAI_CR3_TRCE_MASK GENMASK(23, 16)
0132 #define FSL_SAI_CR3_WDFL(x) (x)
0133 #define FSL_SAI_CR3_WDFL_MASK 0x1f
0134
0135
0136
0137 #define FSL_SAI_CR4_FCONT BIT(28)
0138 #define FSL_SAI_CR4_FCOMB_SHIFT BIT(26)
0139 #define FSL_SAI_CR4_FCOMB_SOFT BIT(27)
0140 #define FSL_SAI_CR4_FCOMB_MASK (0x3 << 26)
0141 #define FSL_SAI_CR4_FPACK_8 (0x2 << 24)
0142 #define FSL_SAI_CR4_FPACK_16 (0x3 << 24)
0143 #define FSL_SAI_CR4_FRSZ(x) (((x) - 1) << 16)
0144 #define FSL_SAI_CR4_FRSZ_MASK (0x1f << 16)
0145 #define FSL_SAI_CR4_SYWD(x) (((x) - 1) << 8)
0146 #define FSL_SAI_CR4_SYWD_MASK (0x1f << 8)
0147 #define FSL_SAI_CR4_CHMOD BIT(5)
0148 #define FSL_SAI_CR4_CHMOD_MASK BIT(5)
0149 #define FSL_SAI_CR4_MF BIT(4)
0150 #define FSL_SAI_CR4_FSE BIT(3)
0151 #define FSL_SAI_CR4_FSP BIT(1)
0152 #define FSL_SAI_CR4_FSD_MSTR BIT(0)
0153
0154
0155 #define FSL_SAI_CR5_WNW(x) (((x) - 1) << 24)
0156 #define FSL_SAI_CR5_WNW_MASK (0x1f << 24)
0157 #define FSL_SAI_CR5_W0W(x) (((x) - 1) << 16)
0158 #define FSL_SAI_CR5_W0W_MASK (0x1f << 16)
0159 #define FSL_SAI_CR5_FBT(x) ((x) << 8)
0160 #define FSL_SAI_CR5_FBT_MASK (0x1f << 8)
0161
0162
0163 #define FSL_SAI_MCTL_MCLK_EN BIT(30)
0164 #define FSL_SAI_MCTL_MSEL_MASK (0x3 << 24)
0165 #define FSL_SAI_MCTL_MSEL(ID) ((ID) << 24)
0166 #define FSL_SAI_MCTL_MSEL_BUS 0
0167 #define FSL_SAI_MCTL_MSEL_MCLK1 BIT(24)
0168 #define FSL_SAI_MCTL_MSEL_MCLK2 BIT(25)
0169 #define FSL_SAI_MCTL_MSEL_MCLK3 (BIT(24) | BIT(25))
0170 #define FSL_SAI_MCTL_DIV_EN BIT(23)
0171 #define FSL_SAI_MCTL_DIV_MASK 0xFF
0172
0173
0174 #define FSL_SAI_VERID_MAJOR_SHIFT 24
0175 #define FSL_SAI_VERID_MAJOR_MASK GENMASK(31, 24)
0176 #define FSL_SAI_VERID_MINOR_SHIFT 16
0177 #define FSL_SAI_VERID_MINOR_MASK GENMASK(23, 16)
0178 #define FSL_SAI_VERID_FEATURE_SHIFT 0
0179 #define FSL_SAI_VERID_FEATURE_MASK GENMASK(15, 0)
0180 #define FSL_SAI_VERID_EFIFO_EN BIT(0)
0181 #define FSL_SAI_VERID_TSTMP_EN BIT(1)
0182
0183
0184 #define FSL_SAI_PARAM_SPF_SHIFT 16
0185 #define FSL_SAI_PARAM_SPF_MASK GENMASK(19, 16)
0186 #define FSL_SAI_PARAM_WPF_SHIFT 8
0187 #define FSL_SAI_PARAM_WPF_MASK GENMASK(11, 8)
0188 #define FSL_SAI_PARAM_DLN_MASK GENMASK(3, 0)
0189
0190
0191 #define FSL_SAI_MDIV_MASK 0xFFFFF
0192
0193
0194 #define FSL_SAI_xTCTL_TSEN BIT(0)
0195 #define FSL_SAI_xTCTL_TSINC BIT(1)
0196 #define FSL_SAI_xTCTL_RTSC BIT(8)
0197 #define FSL_SAI_xTCTL_RBC BIT(9)
0198
0199
0200 #define FSL_SAI_DMA BIT(0)
0201 #define FSL_SAI_USE_AC97 BIT(1)
0202 #define FSL_SAI_NET BIT(2)
0203 #define FSL_SAI_TRA_SYN BIT(3)
0204 #define FSL_SAI_REC_SYN BIT(4)
0205 #define FSL_SAI_USE_I2S_SLAVE BIT(5)
0206
0207
0208 #define FSL_SAI_CLK_BUS 0
0209 #define FSL_SAI_CLK_MAST1 1
0210 #define FSL_SAI_CLK_MAST2 2
0211 #define FSL_SAI_CLK_MAST3 3
0212
0213 #define FSL_SAI_MCLK_MAX 4
0214
0215
0216 #define FSL_SAI_MAXBURST_TX 6
0217 #define FSL_SAI_MAXBURST_RX 6
0218
0219 #define PMQOS_CPU_LATENCY BIT(0)
0220
0221
0222 #define FSL_SAI_DL_NUM (8)
0223
0224 #define FSL_SAI_DL_DEFAULT (0)
0225 #define FSL_SAI_DL_I2S BIT(0)
0226 #define FSL_SAI_DL_PDM BIT(1)
0227
0228 struct fsl_sai_soc_data {
0229 bool use_imx_pcm;
0230 bool use_edma;
0231 bool mclk0_is_mclk1;
0232 unsigned int fifo_depth;
0233 unsigned int pins;
0234 unsigned int reg_offset;
0235 unsigned int flags;
0236 unsigned int max_register;
0237 };
0238
0239
0240
0241
0242
0243
0244
0245
0246 struct fsl_sai_verid {
0247 u32 version;
0248 u32 feature;
0249 };
0250
0251
0252
0253
0254
0255
0256
0257 struct fsl_sai_param {
0258 u32 slot_num;
0259 u32 fifo_depth;
0260 u32 dataline;
0261 };
0262
0263 struct fsl_sai_dl_cfg {
0264 unsigned int type;
0265 unsigned int pins[2];
0266 unsigned int mask[2];
0267 unsigned int start_off[2];
0268 unsigned int next_off[2];
0269 };
0270
0271 struct fsl_sai {
0272 struct platform_device *pdev;
0273 struct regmap *regmap;
0274 struct clk *bus_clk;
0275 struct clk *mclk_clk[FSL_SAI_MCLK_MAX];
0276 struct clk *pll8k_clk;
0277 struct clk *pll11k_clk;
0278 struct resource *res;
0279
0280 bool is_consumer_mode;
0281 bool is_lsb_first;
0282 bool is_dsp_mode;
0283 bool is_pdm_mode;
0284 bool synchronous[2];
0285 struct fsl_sai_dl_cfg *dl_cfg;
0286 unsigned int dl_cfg_cnt;
0287
0288 unsigned int mclk_id[2];
0289 unsigned int mclk_streams;
0290 unsigned int slots;
0291 unsigned int slot_width;
0292 unsigned int bclk_ratio;
0293
0294 const struct fsl_sai_soc_data *soc_data;
0295 struct snd_soc_dai_driver cpu_dai_drv;
0296 struct snd_dmaengine_dai_dma_data dma_params_rx;
0297 struct snd_dmaengine_dai_dma_data dma_params_tx;
0298 struct fsl_sai_verid verid;
0299 struct fsl_sai_param param;
0300 struct pm_qos_request pm_qos_req;
0301 struct pinctrl *pinctrl;
0302 struct pinctrl_state *pins_state;
0303 };
0304
0305 #define TX 1
0306 #define RX 0
0307
0308 #endif