1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Copyright(c) 2021 MediaTek. All rights reserved. 4 * 5 * Author: Bo Pan <bo.pan@mediatek.com> 6 * YC Hung <yc.hung@mediatek.com> 7 */ 8 9 #ifndef __SOF_DRIVERS_AFE_DRV_H__ 10 #define __SOF_DRIVERS_AFE_DRV_H__ 11 12 struct mtk_base_memif_data { 13 int id; 14 const char *name; 15 int reg_ofs_base; 16 int reg_ofs_cur; 17 int reg_ofs_end; 18 int reg_ofs_base_msb; 19 int reg_ofs_cur_msb; 20 int reg_ofs_end_msb; 21 int fs_reg; 22 int fs_shift; 23 int fs_maskbit; 24 int mono_reg; 25 int mono_shift; 26 int mono_invert; 27 int quad_ch_reg; 28 int quad_ch_mask; 29 int quad_ch_shift; 30 int int_odd_flag_reg; 31 int int_odd_flag_shift; 32 int enable_reg; 33 int enable_shift; 34 int hd_reg; 35 int hd_shift; 36 int hd_align_reg; 37 int hd_align_mshift; 38 int msb_reg; 39 int msb_shift; 40 int msb2_reg; 41 int msb2_shift; 42 int agent_disable_reg; 43 int agent_disable_shift; 44 int ch_num_reg; 45 int ch_num_shift; 46 int ch_num_maskbit; 47 /* playback memif only */ 48 int pbuf_reg; 49 int pbuf_mask; 50 int pbuf_shift; 51 int minlen_reg; 52 int minlen_mask; 53 int minlen_shift; 54 }; 55 56 struct mtk_base_irq_data { 57 int id; 58 int irq_cnt_reg; 59 int irq_cnt_shift; 60 int irq_cnt_maskbit; 61 int irq_fs_reg; 62 int irq_fs_shift; 63 int irq_fs_maskbit; 64 int irq_en_reg; 65 int irq_en_shift; 66 int irq_clr_reg; 67 int irq_clr_shift; 68 int irq_ap_en_reg; 69 int irq_ap_en_shift; 70 int irq_scp_en_reg; 71 int irq_scp_en_shift; 72 }; 73 74 struct mtk_base_afe_memif { 75 unsigned int dma_addr; 76 unsigned int afe_addr; 77 unsigned int buffer_size; 78 79 const struct mtk_base_memif_data *data; 80 int irq_usage; 81 }; 82 83 struct mtk_base_afe_dai { 84 int id; 85 unsigned int channel; 86 unsigned int rate; 87 unsigned int format; 88 /* other? */ 89 }; 90 91 struct mtk_base_afe_irq { 92 const struct mtk_base_irq_data *irq_data; 93 int mask; 94 int irq_occupyed; 95 }; 96 97 struct mtk_base_afe { 98 int ref_count; 99 unsigned int base; 100 101 struct mtk_base_afe_memif *memif; 102 int memifs_size; 103 int memif_32bit_supported; 104 int memif_dl_num; 105 106 struct mtk_base_afe_irq *irqs; 107 int irqs_size; 108 109 struct mtk_base_afe_dai *dais; 110 int dais_size; 111 112 unsigned int (*afe2adsp_addr)(unsigned int addr); 113 unsigned int (*adsp2afe_addr)(unsigned int addr); 114 unsigned int (*afe_fs)(unsigned int rate, int aud_blk); 115 unsigned int (*irq_fs)(unsigned int rate); 116 117 int base_end_offset; 118 119 void *platform_priv; 120 }; 121 122 /* platform information */ 123 struct mtk_base_afe_platform { 124 unsigned int base_addr; 125 const struct mtk_base_memif_data *memif_datas; 126 int memif_size; 127 int memif_32bit_supported; 128 int memif_dl_num; 129 130 struct mtk_base_irq_data *irq_datas; 131 int irqs_size; 132 int dais_size; 133 134 int base_end_offset; 135 136 /* misc */ 137 unsigned int (*afe2adsp_addr)(unsigned int addr); 138 unsigned int (*adsp2afe_addr)(unsigned int addr); 139 unsigned int (*afe_fs)(unsigned int rate, int aud_blk); 140 unsigned int (*irq_fs)(unsigned int rate); 141 }; 142 143 extern struct mtk_base_afe_platform mtk_afe_platform; 144 145 struct mtk_base_afe *afe_get(void); 146 int afe_probe(struct mtk_base_afe *afe); 147 void afe_remove(struct mtk_base_afe *afe); 148 149 /* dai operation */ 150 int afe_dai_get_config(struct mtk_base_afe *afe, int id, unsigned int *channel, unsigned int *rate, 151 unsigned int *format); 152 int afe_dai_set_config(struct mtk_base_afe *afe, int id, unsigned int channel, unsigned int rate, 153 unsigned int format); 154 155 /* memif operation */ 156 int afe_memif_set_params(struct mtk_base_afe *afe, int id, unsigned int channel, unsigned int rate, 157 unsigned int format); 158 int afe_memif_set_addr(struct mtk_base_afe *afe, int id, unsigned int dma_addr, 159 unsigned int dma_bytes); 160 int afe_memif_set_enable(struct mtk_base_afe *afe, int id, int enable); 161 unsigned int afe_memif_get_cur_position(struct mtk_base_afe *afe, int id); 162 int afe_memif_get_direction(struct mtk_base_afe *afe, int id); 163 164 /* irq opeartion */ 165 int afe_irq_get_status(struct mtk_base_afe *afe, int id); 166 int afe_irq_clear(struct mtk_base_afe *afe, int id); 167 int afe_irq_config(struct mtk_base_afe *afe, int id, unsigned int rate, unsigned int period); 168 int afe_irq_enable(struct mtk_base_afe *afe, int id); 169 int afe_irq_disable(struct mtk_base_afe *afe, int id); 170 171 #endif /* __SOF_DRIVERS_AFE_DRV_H__ */ 172 173