13a280ed1SRyder Lee /* SPDX-License-Identifier: GPL-2.0 */ 2283b6124SGarlic Tseng /* 3283b6124SGarlic Tseng * mtk-base-afe.h -- Mediatek base afe structure 4283b6124SGarlic Tseng * 5283b6124SGarlic Tseng * Copyright (c) 2016 MediaTek Inc. 6283b6124SGarlic Tseng * Author: Garlic Tseng <garlic.tseng@mediatek.com> 7283b6124SGarlic Tseng */ 8283b6124SGarlic Tseng 9283b6124SGarlic Tseng #ifndef _MTK_BASE_AFE_H_ 10283b6124SGarlic Tseng #define _MTK_BASE_AFE_H_ 11283b6124SGarlic Tseng 12*7d40cc8eSTrevor Wu #include <linux/soc/mediatek/mtk_sip_svc.h> 13*7d40cc8eSTrevor Wu 14ab7b4ee9SRyder Lee #define MTK_STREAM_NUM (SNDRV_PCM_STREAM_LAST + 1) 15*7d40cc8eSTrevor Wu #define MTK_SIP_AUDIO_CONTROL MTK_SIP_SMC_CMD(0x517) 16*7d40cc8eSTrevor Wu 17*7d40cc8eSTrevor Wu /* SMC CALL Operations */ 18*7d40cc8eSTrevor Wu enum mtk_audio_smc_call_op { 19*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_INIT = 0, 20*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_DRAM_REQUEST, 21*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_DRAM_RELEASE, 22*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_SRAM_REQUEST, 23*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_SRAM_RELEASE, 24*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_ADSP_REQUEST, 25*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_ADSP_RELEASE, 26*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_DOMAIN_SIDEBANDS, 27*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_BTCVSD_WRITE, 28*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_BTCVSD_UPDATE_CTRL_CLEAR, 29*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_BTCVSD_UPDATE_CTRL_UNDERFLOW, 30*7d40cc8eSTrevor Wu MTK_AUDIO_SMC_OP_NUM 31*7d40cc8eSTrevor Wu }; 32ab7b4ee9SRyder Lee 33283b6124SGarlic Tseng struct mtk_base_memif_data { 34283b6124SGarlic Tseng int id; 35283b6124SGarlic Tseng const char *name; 36283b6124SGarlic Tseng int reg_ofs_base; 37283b6124SGarlic Tseng int reg_ofs_cur; 389cdf85a1SEason Yen int reg_ofs_end; 399cdf85a1SEason Yen int reg_ofs_base_msb; 409cdf85a1SEason Yen int reg_ofs_cur_msb; 419cdf85a1SEason Yen int reg_ofs_end_msb; 42283b6124SGarlic Tseng int fs_reg; 43283b6124SGarlic Tseng int fs_shift; 44283b6124SGarlic Tseng int fs_maskbit; 45283b6124SGarlic Tseng int mono_reg; 46283b6124SGarlic Tseng int mono_shift; 479cdf85a1SEason Yen int mono_invert; 489cdf85a1SEason Yen int quad_ch_reg; 499cdf85a1SEason Yen int quad_ch_mask; 509cdf85a1SEason Yen int quad_ch_shift; 51cab2b9e5STrevor Wu int int_odd_flag_reg; 52cab2b9e5STrevor Wu int int_odd_flag_shift; 53283b6124SGarlic Tseng int enable_reg; 54283b6124SGarlic Tseng int enable_shift; 55283b6124SGarlic Tseng int hd_reg; 56283b6124SGarlic Tseng int hd_shift; 579cdf85a1SEason Yen int hd_align_reg; 581628fc3fSShunli Wang int hd_align_mshift; 59283b6124SGarlic Tseng int msb_reg; 60283b6124SGarlic Tseng int msb_shift; 61cab2b9e5STrevor Wu int msb_end_reg; 62cab2b9e5STrevor Wu int msb_end_shift; 63283b6124SGarlic Tseng int agent_disable_reg; 64283b6124SGarlic Tseng int agent_disable_shift; 65cab2b9e5STrevor Wu int ch_num_reg; 66cab2b9e5STrevor Wu int ch_num_shift; 67cab2b9e5STrevor Wu int ch_num_maskbit; 689cdf85a1SEason Yen /* playback memif only */ 699cdf85a1SEason Yen int pbuf_reg; 709cdf85a1SEason Yen int pbuf_mask; 719cdf85a1SEason Yen int pbuf_shift; 729cdf85a1SEason Yen int minlen_reg; 739cdf85a1SEason Yen int minlen_mask; 749cdf85a1SEason Yen int minlen_shift; 75283b6124SGarlic Tseng }; 76283b6124SGarlic Tseng 77283b6124SGarlic Tseng struct mtk_base_irq_data { 78283b6124SGarlic Tseng int id; 79283b6124SGarlic Tseng int irq_cnt_reg; 80283b6124SGarlic Tseng int irq_cnt_shift; 81283b6124SGarlic Tseng int irq_cnt_maskbit; 82283b6124SGarlic Tseng int irq_fs_reg; 83283b6124SGarlic Tseng int irq_fs_shift; 84283b6124SGarlic Tseng int irq_fs_maskbit; 85283b6124SGarlic Tseng int irq_en_reg; 86283b6124SGarlic Tseng int irq_en_shift; 87283b6124SGarlic Tseng int irq_clr_reg; 88283b6124SGarlic Tseng int irq_clr_shift; 89cab2b9e5STrevor Wu int irq_status_shift; 90283b6124SGarlic Tseng }; 91283b6124SGarlic Tseng 92283b6124SGarlic Tseng struct device; 93f11c5db7SKaiChieh Chuang struct list_head; 94283b6124SGarlic Tseng struct mtk_base_afe_memif; 95283b6124SGarlic Tseng struct mtk_base_afe_irq; 9613be427eSKaiChieh Chuang struct mtk_base_afe_dai; 97283b6124SGarlic Tseng struct regmap; 98283b6124SGarlic Tseng struct snd_pcm_substream; 99283b6124SGarlic Tseng struct snd_soc_dai; 100283b6124SGarlic Tseng 101283b6124SGarlic Tseng struct mtk_base_afe { 102283b6124SGarlic Tseng void __iomem *base_addr; 103283b6124SGarlic Tseng struct device *dev; 104283b6124SGarlic Tseng struct regmap *regmap; 105283b6124SGarlic Tseng struct mutex irq_alloc_lock; /* dynamic alloc irq lock */ 106283b6124SGarlic Tseng 107283b6124SGarlic Tseng unsigned int const *reg_back_up_list; 108283b6124SGarlic Tseng unsigned int *reg_back_up; 109283b6124SGarlic Tseng unsigned int reg_back_up_list_num; 110283b6124SGarlic Tseng 111283b6124SGarlic Tseng int (*runtime_suspend)(struct device *dev); 112283b6124SGarlic Tseng int (*runtime_resume)(struct device *dev); 113283b6124SGarlic Tseng bool suspended; 114283b6124SGarlic Tseng 115283b6124SGarlic Tseng struct mtk_base_afe_memif *memif; 116283b6124SGarlic Tseng int memif_size; 117283b6124SGarlic Tseng struct mtk_base_afe_irq *irqs; 118283b6124SGarlic Tseng int irqs_size; 119125ab5d5SJiaxin Yu int memif_32bit_supported; 120283b6124SGarlic Tseng 121f11c5db7SKaiChieh Chuang struct list_head sub_dais; 12213be427eSKaiChieh Chuang struct snd_soc_dai_driver *dai_drivers; 12313be427eSKaiChieh Chuang unsigned int num_dai_drivers; 12413be427eSKaiChieh Chuang 125283b6124SGarlic Tseng const struct snd_pcm_hardware *mtk_afe_hardware; 126283b6124SGarlic Tseng int (*memif_fs)(struct snd_pcm_substream *substream, 127283b6124SGarlic Tseng unsigned int rate); 128283b6124SGarlic Tseng int (*irq_fs)(struct snd_pcm_substream *substream, 129283b6124SGarlic Tseng unsigned int rate); 1309cdf85a1SEason Yen int (*get_dai_fs)(struct mtk_base_afe *afe, 1319cdf85a1SEason Yen int dai_id, unsigned int rate); 1329cdf85a1SEason Yen int (*get_memif_pbuf_size)(struct snd_pcm_substream *substream); 1339cdf85a1SEason Yen 1349cdf85a1SEason Yen int (*request_dram_resource)(struct device *dev); 1359cdf85a1SEason Yen int (*release_dram_resource)(struct device *dev); 136283b6124SGarlic Tseng 137283b6124SGarlic Tseng void *platform_priv; 138283b6124SGarlic Tseng }; 139283b6124SGarlic Tseng 140283b6124SGarlic Tseng struct mtk_base_afe_memif { 141283b6124SGarlic Tseng unsigned int phys_buf_addr; 142283b6124SGarlic Tseng int buffer_size; 143283b6124SGarlic Tseng struct snd_pcm_substream *substream; 144283b6124SGarlic Tseng const struct mtk_base_memif_data *data; 145283b6124SGarlic Tseng int irq_usage; 146283b6124SGarlic Tseng int const_irq; 1479cdf85a1SEason Yen unsigned char *dma_area; 1489cdf85a1SEason Yen dma_addr_t dma_addr; 1499cdf85a1SEason Yen size_t dma_bytes; 150283b6124SGarlic Tseng }; 151283b6124SGarlic Tseng 152283b6124SGarlic Tseng struct mtk_base_afe_irq { 153283b6124SGarlic Tseng const struct mtk_base_irq_data *irq_data; 154283b6124SGarlic Tseng int irq_occupyed; 155283b6124SGarlic Tseng }; 156283b6124SGarlic Tseng 15713be427eSKaiChieh Chuang struct mtk_base_afe_dai { 15813be427eSKaiChieh Chuang struct snd_soc_dai_driver *dai_drivers; 15913be427eSKaiChieh Chuang unsigned int num_dai_drivers; 16013be427eSKaiChieh Chuang 16113be427eSKaiChieh Chuang const struct snd_kcontrol_new *controls; 16213be427eSKaiChieh Chuang unsigned int num_controls; 16313be427eSKaiChieh Chuang const struct snd_soc_dapm_widget *dapm_widgets; 16413be427eSKaiChieh Chuang unsigned int num_dapm_widgets; 16513be427eSKaiChieh Chuang const struct snd_soc_dapm_route *dapm_routes; 16613be427eSKaiChieh Chuang unsigned int num_dapm_routes; 167f11c5db7SKaiChieh Chuang 168f11c5db7SKaiChieh Chuang struct list_head list; 16913be427eSKaiChieh Chuang }; 17013be427eSKaiChieh Chuang 171283b6124SGarlic Tseng #endif 172283b6124SGarlic Tseng 173