Merge tag 'mailbox-v6.2' of git://git.linaro.org/landing-teams/working/fujitsu/integr...
[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;
72 struct snd_soc_dai_link *dai_link;
73 struct asoc_simple_dai *dais;
050c7950 74 struct snd_soc_dai_link_component *dlcs;
205eb17e 75 struct snd_soc_dai_link_component dummy;
e59289cd
KM
76 struct snd_soc_codec_conf *codec_conf;
77 struct gpio_desc *pa_gpio;
d09c774f
SP
78 const struct snd_soc_ops *ops;
79 unsigned int dpcm_selectable:1;
80 unsigned int force_dpcm:1;
e59289cd
KM
81};
82#define simple_priv_to_card(priv) (&(priv)->snd_card)
83#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
84#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
85#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
86
9830d3e9
KM
87#define simple_props_to_dlc_cpu(props, i) ((props)->cpus + i)
88#define simple_props_to_dlc_codec(props, i) ((props)->codecs + i)
89#define simple_props_to_dlc_platform(props, i) ((props)->platforms + i)
90
91#define simple_props_to_dai_cpu(props, i) ((props)->cpu_dai + i)
92#define simple_props_to_dai_codec(props, i) ((props)->codec_dai + i)
93#define simple_props_to_codec_conf(props, i) ((props)->codec_conf + i)
94
fafc05aa
KM
95#define for_each_prop_dlc_cpus(props, i, cpu) \
96 for ((i) = 0; \
9830d3e9
KM
97 ((i) < (props)->num.cpus) && \
98 ((cpu) = simple_props_to_dlc_cpu(props, i)); \
fafc05aa 99 (i)++)
9830d3e9 100#define for_each_prop_dlc_codecs(props, i, codec) \
fafc05aa 101 for ((i) = 0; \
9830d3e9
KM
102 ((i) < (props)->num.codecs) && \
103 ((codec) = simple_props_to_dlc_codec(props, i)); \
fafc05aa
KM
104 (i)++)
105#define for_each_prop_dlc_platforms(props, i, platform) \
106 for ((i) = 0; \
9830d3e9
KM
107 ((i) < (props)->num.platforms) && \
108 ((platform) = simple_props_to_dlc_platform(props, i)); \
fafc05aa
KM
109 (i)++)
110#define for_each_prop_codec_conf(props, i, conf) \
111 for ((i) = 0; \
112 ((i) < (props)->num.codecs) && \
113 (props)->codec_conf && \
9830d3e9 114 ((conf) = simple_props_to_codec_conf(props, i)); \
fafc05aa
KM
115 (i)++)
116
117#define for_each_prop_dai_cpu(props, i, cpu) \
118 for ((i) = 0; \
9830d3e9
KM
119 ((i) < (props)->num.cpus) && \
120 ((cpu) = simple_props_to_dai_cpu(props, i)); \
fafc05aa
KM
121 (i)++)
122#define for_each_prop_dai_codec(props, i, codec) \
123 for ((i) = 0; \
9830d3e9
KM
124 ((i) < (props)->num.codecs) && \
125 ((codec) = simple_props_to_dai_codec(props, i)); \
fafc05aa
KM
126 (i)++)
127
7a226f2e 128#define SNDRV_MAX_LINKS 512
343e55e7 129
65a5056b 130struct link_info {
65a5056b 131 int link; /* number of link */
65a5056b 132 int cpu; /* turn for CPU / Codec */
343e55e7 133 struct prop_nums num[SNDRV_MAX_LINKS];
65a5056b
KM
134};
135
ad11e59f
KM
136int asoc_simple_parse_daifmt(struct device *dev,
137 struct device_node *node,
138 struct device_node *codec,
139 char *prefix,
140 unsigned int *retfmt);
1e974e5b
RF
141int asoc_simple_parse_tdm_width_map(struct device *dev, struct device_node *np,
142 struct asoc_simple_dai *dai);
143
e5668cae 144__printf(3, 4)
ad11e59f
KM
145int asoc_simple_set_dailink_name(struct device *dev,
146 struct snd_soc_dai_link *dai_link,
147 const char *fmt, ...);
148int asoc_simple_parse_card_name(struct snd_soc_card *card,
149 char *prefix);
150
ad11e59f
KM
151int asoc_simple_parse_clk(struct device *dev,
152 struct device_node *node,
ad11e59f 153 struct asoc_simple_dai *simple_dai,
ad11e59f 154 struct snd_soc_dai_link_component *dlc);
f38df5bf 155int asoc_simple_startup(struct snd_pcm_substream *substream);
686911b4 156void asoc_simple_shutdown(struct snd_pcm_substream *substream);
f48dcbb6
KM
157int asoc_simple_hw_params(struct snd_pcm_substream *substream,
158 struct snd_pcm_hw_params *params);
ad934ca8 159int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd);
629f7544
KM
160int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
161 struct snd_pcm_hw_params *params);
bb6fc620 162
ad11e59f 163#define asoc_simple_parse_tdm(np, dai) \
e68ba207
KM
164 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
165 &(dai)->rx_slot_mask, \
166 &(dai)->slots, \
167 &(dai)->slot_width);
168
c826ec03
KM
169void asoc_simple_canonicalize_platform(struct snd_soc_dai_link_component *platforms,
170 struct snd_soc_dai_link_component *cpus);
171void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link_component *cpus,
172 int is_single_links);
c262c9ab 173
e6f08af6 174void asoc_simple_clean_reference(struct snd_soc_card *card);
0f4e0711 175
fcfd763b 176void asoc_simple_parse_convert(struct device_node *np, char *prefix,
ad11e59f 177 struct asoc_simple_data *data);
32def55d 178bool asoc_simple_is_convert_required(const struct asoc_simple_data *data);
13bb1cc0 179
ad11e59f 180int asoc_simple_parse_routing(struct snd_soc_card *card,
33404f3f 181 char *prefix);
ad11e59f 182int asoc_simple_parse_widgets(struct snd_soc_card *card,
b31f11d0 183 char *prefix);
90194281
PC
184int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
185 char *prefix);
3296d078 186
ad11e59f 187int asoc_simple_init_jack(struct snd_soc_card *card,
62c2c9fc 188 struct asoc_simple_jack *sjack,
764aafdb 189 int is_hp, char *prefix, char *pin);
ad11e59f 190int asoc_simple_init_priv(struct asoc_simple_priv *priv,
65a5056b 191 struct link_info *li);
f6fcc820 192int asoc_simple_remove(struct platform_device *pdev);
0580dde5 193
1a456b1c 194int asoc_graph_card_probe(struct snd_soc_card *card);
92939252 195int asoc_graph_is_ports0(struct device_node *port);
1a456b1c 196
0580dde5 197#ifdef DEBUG
af621959
DB
198static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
199 char *name,
200 struct asoc_simple_dai *dai)
0580dde5
KM
201{
202 struct device *dev = simple_priv_to_dev(priv);
203
52db6685
KM
204 /* dai might be NULL */
205 if (!dai)
206 return;
207
0580dde5
KM
208 if (dai->name)
209 dev_dbg(dev, "%s dai name = %s\n",
210 name, dai->name);
0580dde5
KM
211
212 if (dai->slots)
213 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
214 if (dai->slot_width)
215 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
216 if (dai->tx_slot_mask)
217 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
218 if (dai->rx_slot_mask)
219 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
220 if (dai->clk)
221 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
33cd6b19
KM
222 if (dai->sysclk)
223 dev_dbg(dev, "%s sysclk = %dHz\n",
224 name, dai->sysclk);
225 if (dai->clk || dai->sysclk)
226 dev_dbg(dev, "%s direction = %s\n",
227 name, dai->clk_direction ? "OUT" : "IN");
0580dde5
KM
228}
229
af621959 230static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
0580dde5
KM
231{
232 struct snd_soc_card *card = simple_priv_to_card(priv);
233 struct device *dev = simple_priv_to_dev(priv);
234
235 int i;
236
237 if (card->name)
238 dev_dbg(dev, "Card Name: %s\n", card->name);
239
240 for (i = 0; i < card->num_links; i++) {
241 struct simple_dai_props *props = simple_priv_to_props(priv, i);
242 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
fafc05aa
KM
243 struct asoc_simple_dai *dai;
244 struct snd_soc_codec_conf *cnf;
245 int j;
0580dde5
KM
246
247 dev_dbg(dev, "DAI%d\n", i);
248
40d8cbe7 249 dev_dbg(dev, "cpu num = %d\n", link->num_cpus);
fafc05aa
KM
250 for_each_prop_dai_cpu(props, j, dai)
251 asoc_simple_debug_dai(priv, "cpu", dai);
40d8cbe7 252 dev_dbg(dev, "codec num = %d\n", link->num_codecs);
fafc05aa
KM
253 for_each_prop_dai_codec(props, j, dai)
254 asoc_simple_debug_dai(priv, "codec", dai);
0580dde5
KM
255
256 if (link->name)
257 dev_dbg(dev, "dai name = %s\n", link->name);
ac813c62
KM
258 if (link->dai_fmt)
259 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
0580dde5 260 if (props->adata.convert_rate)
3919249e 261 dev_dbg(dev, "convert_rate = %d\n", props->adata.convert_rate);
0580dde5 262 if (props->adata.convert_channels)
3919249e 263 dev_dbg(dev, "convert_channels = %d\n", props->adata.convert_channels);
fafc05aa
KM
264 for_each_prop_codec_conf(props, j, cnf)
265 if (cnf->name_prefix)
266 dev_dbg(dev, "name prefix = %s\n", cnf->name_prefix);
0580dde5 267 if (props->mclk_fs)
3919249e 268 dev_dbg(dev, "mclk-fs = %d\n", props->mclk_fs);
0580dde5
KM
269 }
270}
271#else
272#define asoc_simple_debug_info(priv)
273#endif /* DEBUG */
274
29a43aa9 275#endif /* __SIMPLE_CARD_UTILS_H */