18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * mtk-base-afe.h  --  Mediatek base afe structure
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2016 MediaTek Inc.
68c2ecf20Sopenharmony_ci * Author: Garlic Tseng <garlic.tseng@mediatek.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef _MTK_BASE_AFE_H_
108c2ecf20Sopenharmony_ci#define _MTK_BASE_AFE_H_
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define MTK_STREAM_NUM (SNDRV_PCM_STREAM_LAST + 1)
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct mtk_base_memif_data {
158c2ecf20Sopenharmony_ci	int id;
168c2ecf20Sopenharmony_ci	const char *name;
178c2ecf20Sopenharmony_ci	int reg_ofs_base;
188c2ecf20Sopenharmony_ci	int reg_ofs_cur;
198c2ecf20Sopenharmony_ci	int reg_ofs_end;
208c2ecf20Sopenharmony_ci	int reg_ofs_base_msb;
218c2ecf20Sopenharmony_ci	int reg_ofs_cur_msb;
228c2ecf20Sopenharmony_ci	int reg_ofs_end_msb;
238c2ecf20Sopenharmony_ci	int fs_reg;
248c2ecf20Sopenharmony_ci	int fs_shift;
258c2ecf20Sopenharmony_ci	int fs_maskbit;
268c2ecf20Sopenharmony_ci	int mono_reg;
278c2ecf20Sopenharmony_ci	int mono_shift;
288c2ecf20Sopenharmony_ci	int mono_invert;
298c2ecf20Sopenharmony_ci	int quad_ch_reg;
308c2ecf20Sopenharmony_ci	int quad_ch_mask;
318c2ecf20Sopenharmony_ci	int quad_ch_shift;
328c2ecf20Sopenharmony_ci	int enable_reg;
338c2ecf20Sopenharmony_ci	int enable_shift;
348c2ecf20Sopenharmony_ci	int hd_reg;
358c2ecf20Sopenharmony_ci	int hd_shift;
368c2ecf20Sopenharmony_ci	int hd_align_reg;
378c2ecf20Sopenharmony_ci	int hd_align_mshift;
388c2ecf20Sopenharmony_ci	int msb_reg;
398c2ecf20Sopenharmony_ci	int msb_shift;
408c2ecf20Sopenharmony_ci	int msb2_reg;
418c2ecf20Sopenharmony_ci	int msb2_shift;
428c2ecf20Sopenharmony_ci	int agent_disable_reg;
438c2ecf20Sopenharmony_ci	int agent_disable_shift;
448c2ecf20Sopenharmony_ci	/* playback memif only */
458c2ecf20Sopenharmony_ci	int pbuf_reg;
468c2ecf20Sopenharmony_ci	int pbuf_mask;
478c2ecf20Sopenharmony_ci	int pbuf_shift;
488c2ecf20Sopenharmony_ci	int minlen_reg;
498c2ecf20Sopenharmony_ci	int minlen_mask;
508c2ecf20Sopenharmony_ci	int minlen_shift;
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct mtk_base_irq_data {
548c2ecf20Sopenharmony_ci	int id;
558c2ecf20Sopenharmony_ci	int irq_cnt_reg;
568c2ecf20Sopenharmony_ci	int irq_cnt_shift;
578c2ecf20Sopenharmony_ci	int irq_cnt_maskbit;
588c2ecf20Sopenharmony_ci	int irq_fs_reg;
598c2ecf20Sopenharmony_ci	int irq_fs_shift;
608c2ecf20Sopenharmony_ci	int irq_fs_maskbit;
618c2ecf20Sopenharmony_ci	int irq_en_reg;
628c2ecf20Sopenharmony_ci	int irq_en_shift;
638c2ecf20Sopenharmony_ci	int irq_clr_reg;
648c2ecf20Sopenharmony_ci	int irq_clr_shift;
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistruct device;
688c2ecf20Sopenharmony_cistruct list_head;
698c2ecf20Sopenharmony_cistruct mtk_base_afe_memif;
708c2ecf20Sopenharmony_cistruct mtk_base_afe_irq;
718c2ecf20Sopenharmony_cistruct mtk_base_afe_dai;
728c2ecf20Sopenharmony_cistruct regmap;
738c2ecf20Sopenharmony_cistruct snd_pcm_substream;
748c2ecf20Sopenharmony_cistruct snd_soc_dai;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct mtk_base_afe {
778c2ecf20Sopenharmony_ci	void __iomem *base_addr;
788c2ecf20Sopenharmony_ci	struct device *dev;
798c2ecf20Sopenharmony_ci	struct regmap *regmap;
808c2ecf20Sopenharmony_ci	struct mutex irq_alloc_lock; /* dynamic alloc irq lock */
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	unsigned int const *reg_back_up_list;
838c2ecf20Sopenharmony_ci	unsigned int *reg_back_up;
848c2ecf20Sopenharmony_ci	unsigned int reg_back_up_list_num;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	int (*runtime_suspend)(struct device *dev);
878c2ecf20Sopenharmony_ci	int (*runtime_resume)(struct device *dev);
888c2ecf20Sopenharmony_ci	bool suspended;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	struct mtk_base_afe_memif *memif;
918c2ecf20Sopenharmony_ci	int memif_size;
928c2ecf20Sopenharmony_ci	struct mtk_base_afe_irq *irqs;
938c2ecf20Sopenharmony_ci	int irqs_size;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	struct list_head sub_dais;
968c2ecf20Sopenharmony_ci	struct snd_soc_dai_driver *dai_drivers;
978c2ecf20Sopenharmony_ci	unsigned int num_dai_drivers;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	const struct snd_pcm_hardware *mtk_afe_hardware;
1008c2ecf20Sopenharmony_ci	int (*memif_fs)(struct snd_pcm_substream *substream,
1018c2ecf20Sopenharmony_ci			unsigned int rate);
1028c2ecf20Sopenharmony_ci	int (*irq_fs)(struct snd_pcm_substream *substream,
1038c2ecf20Sopenharmony_ci		      unsigned int rate);
1048c2ecf20Sopenharmony_ci	int (*get_dai_fs)(struct mtk_base_afe *afe,
1058c2ecf20Sopenharmony_ci			  int dai_id, unsigned int rate);
1068c2ecf20Sopenharmony_ci	int (*get_memif_pbuf_size)(struct snd_pcm_substream *substream);
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	int (*request_dram_resource)(struct device *dev);
1098c2ecf20Sopenharmony_ci	int (*release_dram_resource)(struct device *dev);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	void *platform_priv;
1128c2ecf20Sopenharmony_ci};
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistruct mtk_base_afe_memif {
1158c2ecf20Sopenharmony_ci	unsigned int phys_buf_addr;
1168c2ecf20Sopenharmony_ci	int buffer_size;
1178c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream;
1188c2ecf20Sopenharmony_ci	const struct mtk_base_memif_data *data;
1198c2ecf20Sopenharmony_ci	int irq_usage;
1208c2ecf20Sopenharmony_ci	int const_irq;
1218c2ecf20Sopenharmony_ci	unsigned char *dma_area;
1228c2ecf20Sopenharmony_ci	dma_addr_t dma_addr;
1238c2ecf20Sopenharmony_ci	size_t dma_bytes;
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistruct mtk_base_afe_irq {
1278c2ecf20Sopenharmony_ci	const struct mtk_base_irq_data *irq_data;
1288c2ecf20Sopenharmony_ci	int irq_occupyed;
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistruct mtk_base_afe_dai {
1328c2ecf20Sopenharmony_ci	struct snd_soc_dai_driver *dai_drivers;
1338c2ecf20Sopenharmony_ci	unsigned int num_dai_drivers;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	const struct snd_kcontrol_new *controls;
1368c2ecf20Sopenharmony_ci	unsigned int num_controls;
1378c2ecf20Sopenharmony_ci	const struct snd_soc_dapm_widget *dapm_widgets;
1388c2ecf20Sopenharmony_ci	unsigned int num_dapm_widgets;
1398c2ecf20Sopenharmony_ci	const struct snd_soc_dapm_route *dapm_routes;
1408c2ecf20Sopenharmony_ci	unsigned int num_dapm_routes;
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	struct list_head list;
1438c2ecf20Sopenharmony_ci};
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci#endif
1468c2ecf20Sopenharmony_ci
147