1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /*
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
7 *
8 * Author: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
9 */
10 #ifndef __ACP_MACH_H
11 #define __ACP_MACH_H
12
13 #include <sound/core.h>
14 #include <sound/jack.h>
15 #include <sound/pcm_params.h>
16 #include <sound/soc-dapm.h>
17 #include <linux/input.h>
18 #include <linux/module.h>
19 #include <sound/soc.h>
20
21 #define TDM_CHANNELS 8
22
23 #define ACP_OPS(priv, cb) ((priv)->ops.cb)
24
25 #define acp_get_drvdata(card) ((struct acp_card_drvdata *)(card)->drvdata)
26
27 enum be_id {
28 HEADSET_BE_ID = 0,
29 AMP_BE_ID,
30 DMIC_BE_ID,
31 BT_BE_ID,
32 };
33
34 enum cpu_endpoints {
35 NONE = 0,
36 I2S_HS,
37 I2S_SP,
38 I2S_BT,
39 DMIC,
40 };
41
42 enum codec_endpoints {
43 DUMMY = 0,
44 RT5682,
45 RT1019,
46 MAX98360A,
47 RT5682S,
48 NAU8825,
49 NAU8821,
50 MAX98388,
51 ES83XX,
52 };
53
54 enum platform_end_point {
55 RENOIR = 0,
56 REMBRANDT,
57 ACP63,
58 ACP70,
59 ACP71,
60 };
61
62 struct acp_mach_ops {
63 int (*probe)(struct snd_soc_card *card);
64 int (*configure_link)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
65 int (*configure_widgets)(struct snd_soc_card *card);
66 int (*suspend_pre)(struct snd_soc_card *card);
67 int (*resume_post)(struct snd_soc_card *card);
68 };
69
70 struct acp_card_drvdata {
71 unsigned int hs_cpu_id;
72 unsigned int amp_cpu_id;
73 unsigned int bt_cpu_id;
74 unsigned int dmic_cpu_id;
75 unsigned int hs_codec_id;
76 unsigned int amp_codec_id;
77 unsigned int bt_codec_id;
78 unsigned int dmic_codec_id;
79 unsigned int dai_fmt;
80 unsigned int platform;
81 struct clk *wclk;
82 struct clk *bclk;
83 struct acp_mach_ops ops;
84 struct snd_soc_acpi_mach *acpi_mach;
85 void *mach_priv;
86 bool soc_mclk;
87 bool tdm_mode;
88 };
89
90 int acp_sofdsp_dai_links_create(struct snd_soc_card *card);
91 int acp_legacy_dai_links_create(struct snd_soc_card *card);
92 extern const struct dmi_system_id acp_quirk_table[];
93
acp_ops_probe(struct snd_soc_card * card)94 static inline int acp_ops_probe(struct snd_soc_card *card)
95 {
96 int ret = 1;
97 struct acp_card_drvdata *priv = acp_get_drvdata(card);
98
99 if (ACP_OPS(priv, probe))
100 ret = ACP_OPS(priv, probe)(card);
101 return ret;
102 }
103
acp_ops_configure_link(struct snd_soc_card * card,struct snd_soc_dai_link * dai_link)104 static inline int acp_ops_configure_link(struct snd_soc_card *card,
105 struct snd_soc_dai_link *dai_link)
106 {
107 int ret = 1;
108 struct acp_card_drvdata *priv = acp_get_drvdata(card);
109
110 if (ACP_OPS(priv, configure_link))
111 ret = ACP_OPS(priv, configure_link)(card, dai_link);
112 return ret;
113 }
114
acp_ops_configure_widgets(struct snd_soc_card * card)115 static inline int acp_ops_configure_widgets(struct snd_soc_card *card)
116 {
117 int ret = 1;
118 struct acp_card_drvdata *priv = acp_get_drvdata(card);
119
120 if (ACP_OPS(priv, configure_widgets))
121 ret = ACP_OPS(priv, configure_widgets)(card);
122 return ret;
123 }
124
acp_ops_suspend_pre(struct snd_soc_card * card)125 static inline int acp_ops_suspend_pre(struct snd_soc_card *card)
126 {
127 int ret = 1;
128 struct acp_card_drvdata *priv = acp_get_drvdata(card);
129
130 if (ACP_OPS(priv, suspend_pre))
131 ret = ACP_OPS(priv, suspend_pre)(card);
132 return ret;
133 }
134
acp_ops_resume_post(struct snd_soc_card * card)135 static inline int acp_ops_resume_post(struct snd_soc_card *card)
136 {
137 int ret = 1;
138 struct acp_card_drvdata *priv = acp_get_drvdata(card);
139
140 if (ACP_OPS(priv, resume_post))
141 ret = ACP_OPS(priv, resume_post)(card);
142 return ret;
143 }
144
145 #endif
146