Merge tag 'perf-tools-for-v6.4-3-2023-05-06' of git://git.kernel.org/pub/scm/linux...
[linux-block.git] / include / sound / simple_card_utils.h
CommitLineData
d613a7f4
KM
1/* SPDX-License-Identifier: GPL-2.0
2 *
29a43aa9 3 * simple_card_utils.h
abd3147e
KM
4 *
5 * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
abd3147e 6 */
d613a7f4 7
29a43aa9
KM
8#ifndef __SIMPLE_CARD_UTILS_H
9#define __SIMPLE_CARD_UTILS_H
abd3147e 10
4bbee14d 11#include <linux/clk.h>
abd3147e
KM
12#include <sound/soc.h>
13
ad11e59f 14#define asoc_simple_init_hp(card, sjack, prefix) \
764aafdb 15 asoc_simple_init_jack(card, sjack, 1, prefix, NULL)
ad11e59f 16#define asoc_simple_init_mic(card, sjack, prefix) \
764aafdb 17 asoc_simple_init_jack(card, sjack, 0, prefix, NULL)
62c2c9fc 18
1e974e5b
RF
19struct asoc_simple_tdm_width_map {
20 u8 sample_bits;
21 u8 slot_count;
22 u16 slot_width;
23};
24
cecdef36
KM
25struct asoc_simple_dai {
26 const char *name;
27 unsigned int sysclk;
a728f560 28 int clk_direction;
cecdef36
KM
29 int slots;
30 int slot_width;
31 unsigned int tx_slot_mask;
32 unsigned int rx_slot_mask;
33 struct clk *clk;
5ca2ab45 34 bool clk_fixed;
1e974e5b
RF
35 struct asoc_simple_tdm_width_map *tdm_width_map;
36 int n_tdm_widths;
cecdef36
KM
37};
38
ad11e59f 39struct asoc_simple_data {
13bb1cc0
KM
40 u32 convert_rate;
41 u32 convert_channels;
047a0536 42 const char *convert_sample_format;
13bb1cc0
KM
43};
44
62c2c9fc
KS
45struct asoc_simple_jack {
46 struct snd_soc_jack jack;
47 struct snd_soc_jack_pin pin;
48 struct snd_soc_jack_gpio gpio;
49};
50
f2138aed
KM
51struct prop_nums {
52 int cpus;
53 int codecs;
54 int platforms;
55};
56
e59289cd
KM
57struct asoc_simple_priv {
58 struct snd_soc_card snd_card;
59 struct simple_dai_props {
60 struct asoc_simple_dai *cpu_dai;
61 struct asoc_simple_dai *codec_dai;
050c7950
KM
62 struct snd_soc_dai_link_component *cpus;
63 struct snd_soc_dai_link_component *codecs;
64 struct snd_soc_dai_link_component *platforms;
ad11e59f 65 struct asoc_simple_data adata;
e59289cd 66 struct snd_soc_codec_conf *codec_conf;
f2138aed 67 struct prop_nums num;
e59289cd
KM
68 unsigned int mclk_fs;
69 } *dai_props;
70 struct asoc_simple_jack hp_jack;
71 struct asoc_simple_jack mic_jack;
9b271207 72 struct snd_soc_jack *aux_jacks;
e59289cd
KM
73 struct snd_soc_dai_link *dai_link;
74 struct asoc_simple_dai *dais;
050c7950 75 struct snd_soc_dai_link_component *dlcs;
205eb17e 76 struct snd_soc_dai_link_component dummy;
e59289cd
KM
77 struct snd_soc_codec_conf *codec_conf;
78 struct gpio_desc *pa_gpio;
d09c774f
SP
79 const struct snd_soc_ops *ops;
80 unsigned int dpcm_selectable:1;
81 unsigned int force_dpcm:1;
e59289cd
KM
82};
83#define simple_priv_to_card(priv) (&(priv)->snd_card)
84#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
85#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
86#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
87
9830d3e9
KM
88#define simple_props_to_dlc_cpu(props, i) ((props)->cpus + i)
89#define simple_props_to_dlc_codec(props, i) ((props)->codecs + i)
90#define simple_props_to_dlc_platform(props, i) ((props)->platforms + i)
91
92#define simple_props_to_dai_cpu(props, i) ((props)->cpu_dai + i)
93#define simple_props_to_dai_codec(props, i) ((props)->codec_dai + i)
94#define simple_props_to_codec_conf(props, i) ((props)->codec_conf + i)
95
fafc05aa
KM
96#define for_each_prop_dlc_cpus(props, i, cpu) \
97 for ((i) = 0; \
9830d3e9
KM
98 ((i) < (props)->num.cpus) && \
99 ((cpu) = simple_props_to_dlc_cpu(props, i)); \
fafc05aa 100 (i)++)
9830d3e9 101#define for_each_prop_dlc_codecs(props, i, codec) \
fafc05aa 102 for ((i) = 0; \
9830d3e9
KM
103 ((i) < (props)->num.codecs) && \
104 ((codec) = simple_props_to_dlc_codec(props, i)); \
fafc05aa
KM
105 (i)++)
106#define for_each_prop_dlc_platforms(props, i, platform) \
107 for ((i) = 0; \
9830d3e9
KM
108 ((i) < (props)->num.platforms) && \
109 ((platform) = simple_props_to_dlc_platform(props, i)); \
fafc05aa
KM
110 (i)++)
111#define for_each_prop_codec_conf(props, i, conf) \
112 for ((i) = 0; \
113 ((i) < (props)->num.codecs) && \
114 (props)->codec_conf && \
9830d3e9 115 ((conf) = simple_props_to_codec_conf(props, i)); \
fafc05aa
KM
116 (i)++)
117
118#define for_each_prop_dai_cpu(props, i, cpu) \
119 for ((i) = 0; \
9830d3e9
KM
120 ((i) < (props)->num.cpus) && \
121 ((cpu) = simple_props_to_dai_cpu(props, i)); \
fafc05aa
KM
122 (i)++)
123#define for_each_prop_dai_codec(props, i, codec) \
124 for ((i) = 0; \
9830d3e9
KM
125 ((i) < (props)->num.codecs) && \
126 ((codec) = simple_props_to_dai_codec(props, i)); \
fafc05aa
KM
127 (i)++)
128
7a226f2e 129#define SNDRV_MAX_LINKS 512
343e55e7 130
65a5056b 131struct link_info {
65a5056b 132 int link; /* number of link */
65a5056b 133 int cpu; /* turn for CPU / Codec */
343e55e7 134 struct prop_nums num[SNDRV_MAX_LINKS];
65a5056b
KM
135};
136
ad11e59f
KM
137int asoc_simple_parse_daifmt(struct device *dev,
138 struct device_node *node,
139 struct device_node *codec,
140 char *prefix,
141 unsigned int *retfmt);
1e974e5b
RF
142int asoc_simple_parse_tdm_width_map(struct device *dev, struct device_node *np,
143 struct asoc_simple_dai *dai);
144
e5668cae 145__printf(3, 4)
ad11e59f
KM
146int asoc_simple_set_dailink_name(struct device *dev,
147 struct snd_soc_dai_link *dai_link,
148 const char *fmt, ...);
149int asoc_simple_parse_card_name(struct snd_soc_card *card,
150 char *prefix);
151
ad11e59f
KM
152int asoc_simple_parse_clk(struct device *dev,
153 struct device_node *node,
ad11e59f 154 struct asoc_simple_dai *simple_dai,
ad11e59f 155 struct snd_soc_dai_link_component *dlc);
f38df5bf 156int asoc_simple_startup(struct snd_pcm_substream *substream);
686911b4 157void asoc_simple_shutdown(struct snd_pcm_substream *substream);
f48dcbb6
KM
158int asoc_simple_hw_params(struct snd_pcm_substream *substream,
159 struct snd_pcm_hw_params *params);
ad934ca8 160int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd);
629f7544
KM
161int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
162 struct snd_pcm_hw_params *params);
bb6fc620 163
ad11e59f 164#define asoc_simple_parse_tdm(np, dai) \
e68ba207
KM
165 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
166 &(dai)->rx_slot_mask, \
167 &(dai)->slots, \
168 &(dai)->slot_width);
169
c826ec03
KM
170void asoc_simple_canonicalize_platform(struct snd_soc_dai_link_component *platforms,
171 struct snd_soc_dai_link_component *cpus);
172void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link_component *cpus,
173 int is_single_links);
c262c9ab 174
e6f08af6 175void asoc_simple_clean_reference(struct snd_soc_card *card);
0f4e0711 176
fcfd763b 177void asoc_simple_parse_convert(struct device_node *np, char *prefix,
ad11e59f 178 struct asoc_simple_data *data);
32def55d 179bool asoc_simple_is_convert_required(const struct asoc_simple_data *data);
13bb1cc0 180
ad11e59f 181int asoc_simple_parse_routing(struct snd_soc_card *card,
33404f3f 182 char *prefix);
ad11e59f 183int asoc_simple_parse_widgets(struct snd_soc_card *card,
b31f11d0 184 char *prefix);
90194281
PC
185int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
186 char *prefix);
3296d078 187
ad11e59f 188int asoc_simple_init_jack(struct snd_soc_card *card,
62c2c9fc 189 struct asoc_simple_jack *sjack,
764aafdb 190 int is_hp, char *prefix, char *pin);
9b271207
AR
191int asoc_simple_init_aux_jacks(struct asoc_simple_priv *priv,
192 char *prefix);
ad11e59f 193int asoc_simple_init_priv(struct asoc_simple_priv *priv,
65a5056b 194 struct link_info *li);
f6fcc820 195int asoc_simple_remove(struct platform_device *pdev);
0580dde5 196
1a456b1c 197int asoc_graph_card_probe(struct snd_soc_card *card);
92939252 198int asoc_graph_is_ports0(struct device_node *port);
1a456b1c 199
0580dde5 200#ifdef DEBUG
af621959
DB
201static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
202 char *name,
203 struct asoc_simple_dai *dai)
0580dde5
KM
204{
205 struct device *dev = simple_priv_to_dev(priv);
206
52db6685
KM
207 /* dai might be NULL */
208 if (!dai)
209 return;
210
0580dde5
KM
211 if (dai->name)
212 dev_dbg(dev, "%s dai name = %s\n",
213 name, dai->name);
0580dde5
KM
214
215 if (dai->slots)
216 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
217 if (dai->slot_width)
218 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
219 if (dai->tx_slot_mask)
220 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
221 if (dai->rx_slot_mask)
222 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
223 if (dai->clk)
224 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
33cd6b19
KM
225 if (dai->sysclk)
226 dev_dbg(dev, "%s sysclk = %dHz\n",
227 name, dai->sysclk);
228 if (dai->clk || dai->sysclk)
229 dev_dbg(dev, "%s direction = %s\n",
230 name, dai->clk_direction ? "OUT" : "IN");
0580dde5
KM
231}
232
af621959 233static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
0580dde5
KM
234{
235 struct snd_soc_card *card = simple_priv_to_card(priv);
236 struct device *dev = simple_priv_to_dev(priv);
237
238 int i;
239
240 if (card->name)
241 dev_dbg(dev, "Card Name: %s\n", card->name);
242
243 for (i = 0; i < card->num_links; i++) {
244 struct simple_dai_props *props = simple_priv_to_props(priv, i);
245 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
fafc05aa
KM
246 struct asoc_simple_dai *dai;
247 struct snd_soc_codec_conf *cnf;
248 int j;
0580dde5
KM
249
250 dev_dbg(dev, "DAI%d\n", i);
251
40d8cbe7 252 dev_dbg(dev, "cpu num = %d\n", link->num_cpus);
fafc05aa
KM
253 for_each_prop_dai_cpu(props, j, dai)
254 asoc_simple_debug_dai(priv, "cpu", dai);
40d8cbe7 255 dev_dbg(dev, "codec num = %d\n", link->num_codecs);
fafc05aa
KM
256 for_each_prop_dai_codec(props, j, dai)
257 asoc_simple_debug_dai(priv, "codec", dai);
0580dde5
KM
258
259 if (link->name)
260 dev_dbg(dev, "dai name = %s\n", link->name);
ac813c62
KM
261 if (link->dai_fmt)
262 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
0580dde5 263 if (props->adata.convert_rate)
3919249e 264 dev_dbg(dev, "convert_rate = %d\n", props->adata.convert_rate);
0580dde5 265 if (props->adata.convert_channels)
3919249e 266 dev_dbg(dev, "convert_channels = %d\n", props->adata.convert_channels);
fafc05aa
KM
267 for_each_prop_codec_conf(props, j, cnf)
268 if (cnf->name_prefix)
269 dev_dbg(dev, "name prefix = %s\n", cnf->name_prefix);
0580dde5 270 if (props->mclk_fs)
3919249e 271 dev_dbg(dev, "mclk-fs = %d\n", props->mclk_fs);
0580dde5
KM
272 }
273}
274#else
275#define asoc_simple_debug_info(priv)
276#endif /* DEBUG */
277
29a43aa9 278#endif /* __SIMPLE_CARD_UTILS_H */