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 };
60
61 struct acp_mach_ops {
62 int (*probe)(struct snd_soc_card *card);
63 int (*configure_link)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
64 int (*configure_widgets)(struct snd_soc_card *card);
65 int (*suspend_pre)(struct snd_soc_card *card);
66 int (*resume_post)(struct snd_soc_card *card);
67 };
68
69 struct acp_card_drvdata {
70 unsigned int hs_cpu_id;
71 unsigned int amp_cpu_id;
72 unsigned int bt_cpu_id;
73 unsigned int dmic_cpu_id;
74 unsigned int hs_codec_id;
75 unsigned int amp_codec_id;
76 unsigned int bt_codec_id;
77 unsigned int dmic_codec_id;
78 unsigned int dai_fmt;
79 unsigned int platform;
80 struct clk *wclk;
81 struct clk *bclk;
82 struct acp_mach_ops ops;
83 struct snd_soc_acpi_mach *acpi_mach;
84 void *mach_priv;
85 bool soc_mclk;
86 bool tdm_mode;
87 };
88
89 int acp_sofdsp_dai_links_create(struct snd_soc_card *card);
90 int acp_legacy_dai_links_create(struct snd_soc_card *card);
91 extern const struct dmi_system_id acp_quirk_table[];
92
acp_ops_probe(struct snd_soc_card * card)93 static inline int acp_ops_probe(struct snd_soc_card *card)
94 {
95 int ret = 1;
96 struct acp_card_drvdata *priv = acp_get_drvdata(card);
97
98 if (ACP_OPS(priv, probe))
99 ret = ACP_OPS(priv, probe)(card);
100 return ret;
101 }
102
acp_ops_configure_link(struct snd_soc_card * card,struct snd_soc_dai_link * dai_link)103 static inline int acp_ops_configure_link(struct snd_soc_card *card,
104 struct snd_soc_dai_link *dai_link)
105 {
106 int ret = 1;
107 struct acp_card_drvdata *priv = acp_get_drvdata(card);
108
109 if (ACP_OPS(priv, configure_link))
110 ret = ACP_OPS(priv, configure_link)(card, dai_link);
111 return ret;
112 }
113
acp_ops_configure_widgets(struct snd_soc_card * card)114 static inline int acp_ops_configure_widgets(struct snd_soc_card *card)
115 {
116 int ret = 1;
117 struct acp_card_drvdata *priv = acp_get_drvdata(card);
118
119 if (ACP_OPS(priv, configure_widgets))
120 ret = ACP_OPS(priv, configure_widgets)(card);
121 return ret;
122 }
123
acp_ops_suspend_pre(struct snd_soc_card * card)124 static inline int acp_ops_suspend_pre(struct snd_soc_card *card)
125 {
126 int ret = 1;
127 struct acp_card_drvdata *priv = acp_get_drvdata(card);
128
129 if (ACP_OPS(priv, suspend_pre))
130 ret = ACP_OPS(priv, suspend_pre)(card);
131 return ret;
132 }
133
acp_ops_resume_post(struct snd_soc_card * card)134 static inline int acp_ops_resume_post(struct snd_soc_card *card)
135 {
136 int ret = 1;
137 struct acp_card_drvdata *priv = acp_get_drvdata(card);
138
139 if (ACP_OPS(priv, resume_post))
140 ret = ACP_OPS(priv, resume_post)(card);
141 return ret;
142 }
143
144 #endif
145