1 /* SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8 #ifndef __SIMPLE_CARD_UTILS_H
9 #define __SIMPLE_CARD_UTILS_H
11 #include <linux/clk.h>
12 #include <sound/soc.h>
14 #define simple_util_init_hp(card, sjack, prefix) \
15 simple_util_init_jack(card, sjack, 1, prefix, NULL)
16 #define simple_util_init_mic(card, sjack, prefix) \
17 simple_util_init_jack(card, sjack, 0, prefix, NULL)
19 struct simple_util_tdm_width_map {
25 struct simple_util_dai {
31 unsigned int tx_slot_mask;
32 unsigned int rx_slot_mask;
35 struct simple_util_tdm_width_map *tdm_width_map;
39 struct simple_util_data {
42 const char *convert_sample_format;
45 struct simple_util_jack {
46 struct snd_soc_jack jack;
47 struct snd_soc_jack_pin pin;
48 struct snd_soc_jack_gpio gpio;
57 struct simple_util_priv {
58 struct snd_soc_card snd_card;
59 struct simple_dai_props {
60 struct simple_util_dai *cpu_dai;
61 struct simple_util_dai *codec_dai;
62 struct simple_util_data adata;
63 struct snd_soc_codec_conf *codec_conf;
67 struct simple_util_jack hp_jack;
68 struct simple_util_jack mic_jack;
69 struct snd_soc_jack *aux_jacks;
70 struct snd_soc_dai_link *dai_link;
71 struct simple_util_dai *dais;
72 struct snd_soc_dai_link_component *dlcs;
73 struct snd_soc_codec_conf *codec_conf;
74 struct gpio_desc *pa_gpio;
75 const struct snd_soc_ops *ops;
76 unsigned int dpcm_selectable:1;
77 unsigned int force_dpcm:1;
79 #define simple_priv_to_card(priv) (&(priv)->snd_card)
80 #define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
81 #define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
82 #define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
84 #define simple_props_to_dlc_cpu(props, i) ((props)->cpus + i)
85 #define simple_props_to_dlc_codec(props, i) ((props)->codecs + i)
86 #define simple_props_to_dlc_platform(props, i) ((props)->platforms + i)
88 #define simple_props_to_dai_cpu(props, i) ((props)->cpu_dai + i)
89 #define simple_props_to_dai_codec(props, i) ((props)->codec_dai + i)
90 #define simple_props_to_codec_conf(props, i) ((props)->codec_conf + i)
92 #define for_each_prop_dlc_cpus(props, i, cpu) \
94 ((i) < (props)->num.cpus) && \
95 ((cpu) = simple_props_to_dlc_cpu(props, i)); \
97 #define for_each_prop_dlc_codecs(props, i, codec) \
99 ((i) < (props)->num.codecs) && \
100 ((codec) = simple_props_to_dlc_codec(props, i)); \
102 #define for_each_prop_dlc_platforms(props, i, platform) \
104 ((i) < (props)->num.platforms) && \
105 ((platform) = simple_props_to_dlc_platform(props, i)); \
107 #define for_each_prop_codec_conf(props, i, conf) \
109 ((i) < (props)->num.codecs) && \
110 (props)->codec_conf && \
111 ((conf) = simple_props_to_codec_conf(props, i)); \
114 #define for_each_prop_dai_cpu(props, i, cpu) \
116 ((i) < (props)->num.cpus) && \
117 ((cpu) = simple_props_to_dai_cpu(props, i)); \
119 #define for_each_prop_dai_codec(props, i, codec) \
121 ((i) < (props)->num.codecs) && \
122 ((codec) = simple_props_to_dai_codec(props, i)); \
125 #define SNDRV_MAX_LINKS 512
128 int link; /* number of link */
129 int cpu; /* turn for CPU / Codec */
130 struct prop_nums num[SNDRV_MAX_LINKS];
133 int simple_util_parse_daifmt(struct device *dev,
134 struct device_node *node,
135 struct device_node *codec,
137 unsigned int *retfmt);
138 int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np,
139 struct simple_util_dai *dai);
142 int simple_util_set_dailink_name(struct device *dev,
143 struct snd_soc_dai_link *dai_link,
144 const char *fmt, ...);
145 int simple_util_parse_card_name(struct snd_soc_card *card,
148 int simple_util_parse_clk(struct device *dev,
149 struct device_node *node,
150 struct simple_util_dai *simple_dai,
151 struct snd_soc_dai_link_component *dlc);
152 int simple_util_startup(struct snd_pcm_substream *substream);
153 void simple_util_shutdown(struct snd_pcm_substream *substream);
154 int simple_util_hw_params(struct snd_pcm_substream *substream,
155 struct snd_pcm_hw_params *params);
156 int simple_util_dai_init(struct snd_soc_pcm_runtime *rtd);
157 int simple_util_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
158 struct snd_pcm_hw_params *params);
160 #define simple_util_parse_tdm(np, dai) \
161 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
162 &(dai)->rx_slot_mask, \
166 void simple_util_canonicalize_platform(struct snd_soc_dai_link_component *platforms,
167 struct snd_soc_dai_link_component *cpus);
168 void simple_util_canonicalize_cpu(struct snd_soc_dai_link_component *cpus,
169 int is_single_links);
171 void simple_util_clean_reference(struct snd_soc_card *card);
173 void simple_util_parse_convert(struct device_node *np, char *prefix,
174 struct simple_util_data *data);
175 bool simple_util_is_convert_required(const struct simple_util_data *data);
177 int simple_util_parse_routing(struct snd_soc_card *card,
179 int simple_util_parse_widgets(struct snd_soc_card *card,
181 int simple_util_parse_pin_switches(struct snd_soc_card *card,
184 int simple_util_init_jack(struct snd_soc_card *card,
185 struct simple_util_jack *sjack,
186 int is_hp, char *prefix, char *pin);
187 int simple_util_init_aux_jacks(struct simple_util_priv *priv,
189 int simple_util_init_priv(struct simple_util_priv *priv,
190 struct link_info *li);
191 void simple_util_remove(struct platform_device *pdev);
193 int graph_util_card_probe(struct snd_soc_card *card);
194 int graph_util_is_ports0(struct device_node *port);
195 int graph_util_parse_dai(struct device *dev, struct device_node *ep,
196 struct snd_soc_dai_link_component *dlc, int *is_single_link);
199 static inline void simple_util_debug_dai(struct simple_util_priv *priv,
201 struct simple_util_dai *dai)
203 struct device *dev = simple_priv_to_dev(priv);
205 /* dai might be NULL */
210 dev_dbg(dev, "%s dai name = %s\n",
214 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
216 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
217 if (dai->tx_slot_mask)
218 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
219 if (dai->rx_slot_mask)
220 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
222 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
224 dev_dbg(dev, "%s sysclk = %dHz\n",
226 if (dai->clk || dai->sysclk)
227 dev_dbg(dev, "%s direction = %s\n",
228 name, dai->clk_direction ? "OUT" : "IN");
231 static inline void simple_util_debug_info(struct simple_util_priv *priv)
233 struct snd_soc_card *card = simple_priv_to_card(priv);
234 struct device *dev = simple_priv_to_dev(priv);
239 dev_dbg(dev, "Card Name: %s\n", card->name);
241 for (i = 0; i < card->num_links; i++) {
242 struct simple_dai_props *props = simple_priv_to_props(priv, i);
243 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
244 struct simple_util_dai *dai;
245 struct snd_soc_codec_conf *cnf;
248 dev_dbg(dev, "DAI%d\n", i);
250 dev_dbg(dev, "cpu num = %d\n", link->num_cpus);
251 for_each_prop_dai_cpu(props, j, dai)
252 simple_util_debug_dai(priv, "cpu", dai);
253 dev_dbg(dev, "codec num = %d\n", link->num_codecs);
254 for_each_prop_dai_codec(props, j, dai)
255 simple_util_debug_dai(priv, "codec", dai);
258 dev_dbg(dev, "dai name = %s\n", link->name);
260 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
261 if (props->adata.convert_rate)
262 dev_dbg(dev, "convert_rate = %d\n", props->adata.convert_rate);
263 if (props->adata.convert_channels)
264 dev_dbg(dev, "convert_channels = %d\n", props->adata.convert_channels);
265 for_each_prop_codec_conf(props, j, cnf)
266 if (cnf->name_prefix)
267 dev_dbg(dev, "name prefix = %s\n", cnf->name_prefix);
269 dev_dbg(dev, "mclk-fs = %d\n", props->mclk_fs);
273 #define simple_util_debug_info(priv)
276 #endif /* __SIMPLE_CARD_UTILS_H */