1 /* 2 * Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef I2S_HI35XX_H 17 #define I2S_HI35XX_H 18 19 #include "i2s_if.h" 20 #include "los_vm_zone.h" 21 #include "hdf_base.h" 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif /* __cplusplus */ 27 #endif /* __cplusplus */ 28 29 #ifdef I2S_PRINTK_OPEN 30 #define I2S_PRINT_LOG_DBG(fmt, arg...) printk("[HDF]-[I2S]:" fmt "\r\n", ##arg) 31 #define I2S_PRINT_LOG_ERR(fmt, arg...) printk("[HDF]-[I2S]:" fmt "\r\n", ##arg) 32 #else 33 #define I2S_PRINT_LOG_DBG(fmt, arg...) HDF_LOGD_WRAPPER("[HDF]-[I2S]:" fmt "\r\n", ##arg) 34 #define I2S_PRINT_LOG_ERR(fmt, arg...) HDF_LOGE_WRAPPER("[HDF]-[I2S]:" fmt "\r\n", ##arg) 35 #endif 36 37 #define I2S_PRINT_DATA_LOG_DBG(fmt, arg...) HDF_LOGD_WRAPPER(fmt, ##arg) 38 39 #define I2S_AIAO_BUSNUM 0 40 #define I2S_AUDIO_CODEC_BUSNUM 1 41 42 #define I2S_AIAO_SAMPLE_PRECISION_24 24 43 #define I2S_AIAO_SAMPLE_PRECISION_16 16 44 45 #define AUDIO_CODEC_BASE_ADDR 0x113C0000 46 #define ACODEC_MAX_REG_SIZE 0x1000 47 48 #define CRG_BASE_ADDR 0x12010000 49 #define PERI_CRG103 (CRG_BASE_ADDR + 0x019c) 50 #define AIAO_PLL_CKEN (0x1 << 3) 51 #define AIAO_PLL_CKEN_SHIFT 3 52 #define AIAO_CKEN (0x1 << 1) 53 #define AIAO_CKEN_SHIFT 1 54 55 #define I2S_DUMPER_NAME_PREFIX "i2s_dumper_" 56 #define I2S_DUMPER_NAME_LEN 64 57 #define I2S_DUMPER_DATAS_REGISTER_SIZE 10 58 59 typedef enum { 60 ACODEC_ADC_MODESEL_6144 = 0x0, 61 ACODEC_ADC_MODESEL_4096 = 0x1, 62 ACODEC_ADC_MODESEL_BUTT = 0xff, 63 } AcodecAdcModeSel; 64 65 enum I2sHi35xxAiaoFsclkDiv { 66 AIAO_FSCLK_DIV_16 = 16, /* aiao_fsclk_div [6:4] 000 */ 67 AIAO_FSCLK_DIV_32 = 32, /* aiao_fsclk_div [6:4] 001 */ 68 AIAO_FSCLK_DIV_48 = 48, /* aiao_fsclk_div [6:4] 010 */ 69 AIAO_FSCLK_DIV_64 = 64, /* aiao_fsclk_div [6:4] 011 */ 70 AIAO_FSCLK_DIV_128 = 128, /* aiao_fsclk_div [6:4] 100 */ 71 AIAO_FSCLK_DIV_256 = 256, /* aiao_fsclk_div [6:4] 101 */ 72 AIAO_FSCLK_DIV_8 = 8, /* aiao_fsclk_div [6:4] 110 */ 73 }; 74 75 enum I2sHi35xxAiaoBclkDiv { 76 AIAO_BCLK_DIV_4 = 4, /* aiao_bclk_div [3:0] 0011 */ 77 AIAO_BCLK_DIV_8 = 8, /* aiao_bclk_div [3:0] 0101 */ 78 }; 79 80 /**< REG I2S_CFG_CFG1_00 CFG*/ 81 struct I2sCfgCfg100 { 82 uint8_t aiaoSrstReq; /**< bit 9, aiao_srst_req RX0 channel reset */ 83 uint8_t aiaoCken; /**< bit 8, aiao_cken MCLK/BCLK/WS clk gate */ 84 uint8_t aiaoFsclkDiv; /**< bit [6:4] aiao_fsclk_div, fs=xxx*BCLK */ 85 uint8_t aiaoBclkDiv; /**< bit [3:0], aiao_bclk_div,MCLK=xxx*BCLK */ 86 }; 87 88 /**< REG RX_IF_ATTR1 CFG*/ 89 struct RxIfAttr1Info { 90 uint32_t rxSdSourceSel; /**< bit [23:20], rx_sd_source_sel, normal work val = 0x1000 */ 91 uint8_t rxTrackmode; /**< bit [18:16], rx_trackmode, if mode=I2S, channel control */ 92 uint8_t rxSdOffset; /**< bit [15:8], rx_sd_offset, 0x1 STD/ 0x0LSB */ 93 uint8_t rxChNum; /**< bit [6:4], rx_ch_num, rx channel num */ 94 uint8_t rxI2sPrecision; /**< bit [3:2], rx_i2s_precision, date sample precision config bit */ 95 uint8_t rxMode; /**< bit [1:0], rx_mode, 00--I2S 01--PCM */ 96 }; 97 98 struct RxBuffInfo { 99 uint32_t saddr; /**< REG RX_BUFF_SADDR CFG*/ 100 uint32_t size; /**< REG RX_BUFF_SIZE CFG*/ 101 uint32_t wptrAddr; /**< REG RX_BUFF_WPTR CFG*/ 102 uint32_t rptrAddr; /**< REG RX_BUFF_RPTR CFG*/ 103 uint32_t intEna; /**< REG RX_INT_ENA CFG*/ 104 uint32_t dspCtrl; /**< REG RX_DSP_CTRL CFG*/ 105 uint32_t transSize; /**< REG RX_TRANS_SIZE CFG*/ 106 }; 107 108 struct I2sConfigInfo { 109 uint8_t i2sPadEnable; 110 uint8_t audioEnable; 111 uint32_t PERICRG103; 112 uint32_t I2sCfgCfg000; 113 uint32_t mclk; /**< KHZ */ 114 uint32_t bclk; /**< KHZ */ 115 struct I2sCfgCfg100 regCfg100; 116 struct RxIfAttr1Info regRxIfAttr1; 117 volatile unsigned char *phyBase; 118 volatile unsigned char *regBase; 119 enum I2sWriteChannel writeChannel; 120 enum I2sSampleRate sampleRate; 121 enum I2sWordWidth width; 122 enum I2sChannelIfMode channelIfMode; 123 enum I2sChannelMode channelMode; 124 enum I2sProtocolType type; 125 uint8_t samplePrecision; 126 uint16_t i2slFsSel; 127 DMA_ADDR_T rxData; 128 uint8_t *rxVirData; 129 uint32_t rxWptr; 130 uint32_t rxRptr; 131 uint32_t rxSize; 132 uint32_t rxTransSize; 133 DMA_ADDR_T txData; 134 uint8_t *txVirData; 135 uint32_t txWptr; 136 uint32_t txRptr; 137 uint32_t txSize; 138 uint32_t txTransSize; 139 volatile unsigned char *codecAddr; 140 volatile unsigned char *crg103Addr; 141 bool isplay; 142 bool txEn; 143 uint32_t busNum; 144 struct PlatformDumper *dumper; 145 char *dumperName; 146 }; 147 148 int32_t Hi35xxI2sRegWrite(uint32_t value, volatile unsigned char *addr); 149 uint32_t Hi35xxI2sRegRead(volatile unsigned char *addr); 150 151 #ifdef __cplusplus 152 #if __cplusplus 153 } 154 #endif /* __cplusplus */ 155 #endif /* __cplusplus */ 156 #endif /* I2S_HI35XX_H */ 157