ASoC: simple-card-utils: care multi DAI at asoc_simple_clean_reference()
[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
cecdef36
KM
19struct asoc_simple_dai {
20 const char *name;
21 unsigned int sysclk;
a728f560 22 int clk_direction;
cecdef36
KM
23 int slots;
24 int slot_width;
25 unsigned int tx_slot_mask;
26 unsigned int rx_slot_mask;
27 struct clk *clk;
28};
29
ad11e59f 30struct asoc_simple_data {
13bb1cc0
KM
31 u32 convert_rate;
32 u32 convert_channels;
33};
34
62c2c9fc
KS
35struct asoc_simple_jack {
36 struct snd_soc_jack jack;
37 struct snd_soc_jack_pin pin;
38 struct snd_soc_jack_gpio gpio;
39};
40
f2138aed
KM
41struct prop_nums {
42 int cpus;
43 int codecs;
44 int platforms;
45};
46
e59289cd
KM
47struct asoc_simple_priv {
48 struct snd_soc_card snd_card;
49 struct simple_dai_props {
50 struct asoc_simple_dai *cpu_dai;
51 struct asoc_simple_dai *codec_dai;
050c7950
KM
52 struct snd_soc_dai_link_component *cpus;
53 struct snd_soc_dai_link_component *codecs;
54 struct snd_soc_dai_link_component *platforms;
ad11e59f 55 struct asoc_simple_data adata;
e59289cd 56 struct snd_soc_codec_conf *codec_conf;
f2138aed 57 struct prop_nums num;
e59289cd
KM
58 unsigned int mclk_fs;
59 } *dai_props;
60 struct asoc_simple_jack hp_jack;
61 struct asoc_simple_jack mic_jack;
62 struct snd_soc_dai_link *dai_link;
63 struct asoc_simple_dai *dais;
050c7950 64 struct snd_soc_dai_link_component *dlcs;
205eb17e 65 struct snd_soc_dai_link_component dummy;
e59289cd
KM
66 struct snd_soc_codec_conf *codec_conf;
67 struct gpio_desc *pa_gpio;
d09c774f
SP
68 const struct snd_soc_ops *ops;
69 unsigned int dpcm_selectable:1;
70 unsigned int force_dpcm:1;
e59289cd
KM
71};
72#define simple_priv_to_card(priv) (&(priv)->snd_card)
73#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
74#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
75#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
76
fafc05aa
KM
77#define for_each_prop_dlc_cpus(props, i, cpu) \
78 for ((i) = 0; \
79 ((i) < (props)->num.cpus) && ((cpu) = &(props)->cpus[i]); \
80 (i)++)
81#define for_each_prop_dlc_codecs(props, i, codec) \
82 for ((i) = 0; \
83 ((i) < (props)->num.codecs) && ((codec) = &(props)->codecs[i]); \
84 (i)++)
85#define for_each_prop_dlc_platforms(props, i, platform) \
86 for ((i) = 0; \
87 ((i) < (props)->num.platforms) && ((platform) = &(props)->platforms[i]); \
88 (i)++)
89#define for_each_prop_codec_conf(props, i, conf) \
90 for ((i) = 0; \
91 ((i) < (props)->num.codecs) && \
92 (props)->codec_conf && \
93 ((conf) = &(props)->codec_conf[i]); \
94 (i)++)
95
96#define for_each_prop_dai_cpu(props, i, cpu) \
97 for ((i) = 0; \
98 ((i) < (props)->num.cpus) && ((cpu) = &(props)->cpu_dai[i]); \
99 (i)++)
100#define for_each_prop_dai_codec(props, i, codec) \
101 for ((i) = 0; \
102 ((i) < (props)->num.codecs) && ((codec) = &(props)->codec_dai[i]); \
103 (i)++)
104
65a5056b 105struct link_info {
65a5056b 106 int link; /* number of link */
65a5056b 107 int cpu; /* turn for CPU / Codec */
f2138aed 108 struct prop_nums num[SNDRV_MINOR_DEVICES];
65a5056b
KM
109};
110
ad11e59f
KM
111int asoc_simple_parse_daifmt(struct device *dev,
112 struct device_node *node,
113 struct device_node *codec,
114 char *prefix,
115 unsigned int *retfmt);
e5668cae 116__printf(3, 4)
ad11e59f
KM
117int asoc_simple_set_dailink_name(struct device *dev,
118 struct snd_soc_dai_link *dai_link,
119 const char *fmt, ...);
120int asoc_simple_parse_card_name(struct snd_soc_card *card,
121 char *prefix);
122
ad11e59f
KM
123int asoc_simple_parse_clk(struct device *dev,
124 struct device_node *node,
ad11e59f 125 struct asoc_simple_dai *simple_dai,
ad11e59f 126 struct snd_soc_dai_link_component *dlc);
f38df5bf 127int asoc_simple_startup(struct snd_pcm_substream *substream);
686911b4 128void asoc_simple_shutdown(struct snd_pcm_substream *substream);
f48dcbb6
KM
129int asoc_simple_hw_params(struct snd_pcm_substream *substream,
130 struct snd_pcm_hw_params *params);
ad934ca8 131int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd);
629f7544
KM
132int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
133 struct snd_pcm_hw_params *params);
bb6fc620 134
ad11e59f 135#define asoc_simple_parse_tdm(np, dai) \
e68ba207
KM
136 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
137 &(dai)->rx_slot_mask, \
138 &(dai)->slots, \
139 &(dai)->slot_width);
140
ad11e59f
KM
141void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link);
142void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
983cebd6 143 int is_single_links);
c262c9ab 144
ad11e59f 145int asoc_simple_clean_reference(struct snd_soc_card *card);
0f4e0711 146
ad11e59f 147void asoc_simple_convert_fixup(struct asoc_simple_data *data,
13bb1cc0 148 struct snd_pcm_hw_params *params);
ad11e59f
KM
149void asoc_simple_parse_convert(struct device *dev,
150 struct device_node *np, char *prefix,
151 struct asoc_simple_data *data);
13bb1cc0 152
ad11e59f 153int asoc_simple_parse_routing(struct snd_soc_card *card,
33404f3f 154 char *prefix);
ad11e59f 155int asoc_simple_parse_widgets(struct snd_soc_card *card,
b31f11d0 156 char *prefix);
90194281
PC
157int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
158 char *prefix);
3296d078 159
ad11e59f 160int asoc_simple_init_jack(struct snd_soc_card *card,
62c2c9fc 161 struct asoc_simple_jack *sjack,
764aafdb 162 int is_hp, char *prefix, char *pin);
ad11e59f 163int asoc_simple_init_priv(struct asoc_simple_priv *priv,
65a5056b 164 struct link_info *li);
0580dde5
KM
165
166#ifdef DEBUG
af621959
DB
167static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
168 char *name,
169 struct asoc_simple_dai *dai)
0580dde5
KM
170{
171 struct device *dev = simple_priv_to_dev(priv);
172
52db6685
KM
173 /* dai might be NULL */
174 if (!dai)
175 return;
176
0580dde5
KM
177 if (dai->name)
178 dev_dbg(dev, "%s dai name = %s\n",
179 name, dai->name);
180 if (dai->sysclk)
181 dev_dbg(dev, "%s sysclk = %d\n",
182 name, dai->sysclk);
183
184 dev_dbg(dev, "%s direction = %s\n",
185 name, dai->clk_direction ? "OUT" : "IN");
186
187 if (dai->slots)
188 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
189 if (dai->slot_width)
190 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
191 if (dai->tx_slot_mask)
192 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
193 if (dai->rx_slot_mask)
194 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
195 if (dai->clk)
196 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
197}
198
af621959 199static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
0580dde5
KM
200{
201 struct snd_soc_card *card = simple_priv_to_card(priv);
202 struct device *dev = simple_priv_to_dev(priv);
203
204 int i;
205
206 if (card->name)
207 dev_dbg(dev, "Card Name: %s\n", card->name);
208
209 for (i = 0; i < card->num_links; i++) {
210 struct simple_dai_props *props = simple_priv_to_props(priv, i);
211 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
fafc05aa
KM
212 struct asoc_simple_dai *dai;
213 struct snd_soc_codec_conf *cnf;
214 int j;
0580dde5
KM
215
216 dev_dbg(dev, "DAI%d\n", i);
217
fafc05aa
KM
218 for_each_prop_dai_cpu(props, j, dai)
219 asoc_simple_debug_dai(priv, "cpu", dai);
220 for_each_prop_dai_codec(props, j, dai)
221 asoc_simple_debug_dai(priv, "codec", dai);
0580dde5
KM
222
223 if (link->name)
224 dev_dbg(dev, "dai name = %s\n", link->name);
225
226 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
227
228 if (props->adata.convert_rate)
229 dev_dbg(dev, "convert_rate = %d\n",
230 props->adata.convert_rate);
231 if (props->adata.convert_channels)
232 dev_dbg(dev, "convert_channels = %d\n",
233 props->adata.convert_channels);
fafc05aa
KM
234 for_each_prop_codec_conf(props, j, cnf)
235 if (cnf->name_prefix)
236 dev_dbg(dev, "name prefix = %s\n", cnf->name_prefix);
0580dde5
KM
237 if (props->mclk_fs)
238 dev_dbg(dev, "mclk-fs = %d\n",
239 props->mclk_fs);
240 }
241}
242#else
243#define asoc_simple_debug_info(priv)
244#endif /* DEBUG */
245
29a43aa9 246#endif /* __SIMPLE_CARD_UTILS_H */