1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * mtk-base-afe.h  --  Mediatek base afe structure
4  *
5  * Copyright (c) 2016 MediaTek Inc.
6  * Author: Garlic Tseng <garlic.tseng@mediatek.com>
7  */
8 
9 #ifndef _MTK_BASE_AFE_H_
10 #define _MTK_BASE_AFE_H_
11 
12 #define MTK_STREAM_NUM (SNDRV_PCM_STREAM_LAST + 1)
13 
14 struct mtk_base_memif_data {
15 	int id;
16 	const char *name;
17 	int reg_ofs_base;
18 	int reg_ofs_cur;
19 	int fs_reg;
20 	int fs_shift;
21 	int fs_maskbit;
22 	int mono_reg;
23 	int mono_shift;
24 	int enable_reg;
25 	int enable_shift;
26 	int hd_reg;
27 	int hd_shift;
28 	int msb_reg;
29 	int msb_shift;
30 	int agent_disable_reg;
31 	int agent_disable_shift;
32 };
33 
34 struct mtk_base_irq_data {
35 	int id;
36 	int irq_cnt_reg;
37 	int irq_cnt_shift;
38 	int irq_cnt_maskbit;
39 	int irq_fs_reg;
40 	int irq_fs_shift;
41 	int irq_fs_maskbit;
42 	int irq_en_reg;
43 	int irq_en_shift;
44 	int irq_clr_reg;
45 	int irq_clr_shift;
46 };
47 
48 struct device;
49 struct mtk_base_afe_memif;
50 struct mtk_base_afe_irq;
51 struct mtk_base_afe_dai;
52 struct regmap;
53 struct snd_pcm_substream;
54 struct snd_soc_dai;
55 
56 struct mtk_base_afe {
57 	void __iomem *base_addr;
58 	struct device *dev;
59 	struct regmap *regmap;
60 	struct mutex irq_alloc_lock; /* dynamic alloc irq lock */
61 
62 	unsigned int const *reg_back_up_list;
63 	unsigned int *reg_back_up;
64 	unsigned int reg_back_up_list_num;
65 
66 	int (*runtime_suspend)(struct device *dev);
67 	int (*runtime_resume)(struct device *dev);
68 	bool suspended;
69 
70 	struct mtk_base_afe_memif *memif;
71 	int memif_size;
72 	struct mtk_base_afe_irq *irqs;
73 	int irqs_size;
74 
75 	struct mtk_base_afe_dai *sub_dais;
76 	int num_sub_dais;
77 	struct snd_soc_dai_driver *dai_drivers;
78 	unsigned int num_dai_drivers;
79 
80 	const struct snd_pcm_hardware *mtk_afe_hardware;
81 	int (*memif_fs)(struct snd_pcm_substream *substream,
82 			unsigned int rate);
83 	int (*irq_fs)(struct snd_pcm_substream *substream,
84 		      unsigned int rate);
85 
86 	void *platform_priv;
87 };
88 
89 struct mtk_base_afe_memif {
90 	unsigned int phys_buf_addr;
91 	int buffer_size;
92 	struct snd_pcm_substream *substream;
93 	const struct mtk_base_memif_data *data;
94 	int irq_usage;
95 	int const_irq;
96 };
97 
98 struct mtk_base_afe_irq {
99 	const struct mtk_base_irq_data *irq_data;
100 	int irq_occupyed;
101 };
102 
103 struct mtk_base_afe_dai {
104 	struct snd_soc_dai_driver *dai_drivers;
105 	unsigned int num_dai_drivers;
106 
107 	const struct snd_kcontrol_new *controls;
108 	unsigned int num_controls;
109 	const struct snd_soc_dapm_widget *dapm_widgets;
110 	unsigned int num_dapm_widgets;
111 	const struct snd_soc_dapm_route *dapm_routes;
112 	unsigned int num_dapm_routes;
113 };
114 
115 #endif
116 
117