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 asoc_simple_init_hp(card, sjack, prefix) \
15 asoc_simple_init_jack(card, sjack, 1, prefix, NULL)
16 #define asoc_simple_init_mic(card, sjack, prefix) \
17 asoc_simple_init_jack(card, sjack, 0, prefix, NULL)
19 struct asoc_simple_dai {
25 unsigned int tx_slot_mask;
26 unsigned int rx_slot_mask;
30 struct asoc_simple_data {
35 struct asoc_simple_jack {
36 struct snd_soc_jack jack;
37 struct snd_soc_jack_pin pin;
38 struct snd_soc_jack_gpio gpio;
47 struct 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;
52 struct snd_soc_dai_link_component *cpus;
53 struct snd_soc_dai_link_component *codecs;
54 struct snd_soc_dai_link_component *platforms;
55 struct asoc_simple_data adata;
56 struct snd_soc_codec_conf *codec_conf;
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;
64 struct snd_soc_dai_link_component *dlcs;
65 struct snd_soc_dai_link_component dummy;
66 struct snd_soc_codec_conf *codec_conf;
67 struct gpio_desc *pa_gpio;
68 const struct snd_soc_ops *ops;
69 unsigned int dpcm_selectable:1;
70 unsigned int force_dpcm:1;
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))
78 int link; /* number of link */
79 int cpu; /* turn for CPU / Codec */
80 struct prop_nums num[SNDRV_MINOR_DEVICES];
83 int asoc_simple_parse_daifmt(struct device *dev,
84 struct device_node *node,
85 struct device_node *codec,
87 unsigned int *retfmt);
89 int asoc_simple_set_dailink_name(struct device *dev,
90 struct snd_soc_dai_link *dai_link,
91 const char *fmt, ...);
92 int asoc_simple_parse_card_name(struct snd_soc_card *card,
95 #define asoc_simple_parse_clk_cpu(dev, node, dai_link, simple_dai) \
96 asoc_simple_parse_clk(dev, node, simple_dai, dai_link->cpus)
97 #define asoc_simple_parse_clk_codec(dev, node, dai_link, simple_dai) \
98 asoc_simple_parse_clk(dev, node, simple_dai, dai_link->codecs)
99 int asoc_simple_parse_clk(struct device *dev,
100 struct device_node *node,
101 struct asoc_simple_dai *simple_dai,
102 struct snd_soc_dai_link_component *dlc);
103 int asoc_simple_startup(struct snd_pcm_substream *substream);
104 void asoc_simple_shutdown(struct snd_pcm_substream *substream);
105 int asoc_simple_hw_params(struct snd_pcm_substream *substream,
106 struct snd_pcm_hw_params *params);
107 int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd);
108 int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
109 struct snd_pcm_hw_params *params);
111 #define asoc_simple_parse_cpu(node, dai_link, is_single_link) \
112 asoc_simple_parse_dai(node, dai_link->cpus, is_single_link)
113 #define asoc_simple_parse_codec(node, dai_link) \
114 asoc_simple_parse_dai(node, dai_link->codecs, NULL)
115 #define asoc_simple_parse_platform(node, dai_link) \
116 asoc_simple_parse_dai(node, dai_link->platforms, NULL)
118 #define asoc_simple_parse_tdm(np, dai) \
119 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
120 &(dai)->rx_slot_mask, \
124 void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link);
125 void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
126 int is_single_links);
128 int asoc_simple_clean_reference(struct snd_soc_card *card);
130 void asoc_simple_convert_fixup(struct asoc_simple_data *data,
131 struct snd_pcm_hw_params *params);
132 void asoc_simple_parse_convert(struct device *dev,
133 struct device_node *np, char *prefix,
134 struct asoc_simple_data *data);
136 int asoc_simple_parse_routing(struct snd_soc_card *card,
138 int asoc_simple_parse_widgets(struct snd_soc_card *card,
140 int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
143 int asoc_simple_init_jack(struct snd_soc_card *card,
144 struct asoc_simple_jack *sjack,
145 int is_hp, char *prefix, char *pin);
146 int asoc_simple_init_priv(struct asoc_simple_priv *priv,
147 struct link_info *li);
150 static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
152 struct asoc_simple_dai *dai)
154 struct device *dev = simple_priv_to_dev(priv);
156 /* dai might be NULL */
161 dev_dbg(dev, "%s dai name = %s\n",
164 dev_dbg(dev, "%s sysclk = %d\n",
167 dev_dbg(dev, "%s direction = %s\n",
168 name, dai->clk_direction ? "OUT" : "IN");
171 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
173 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
174 if (dai->tx_slot_mask)
175 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
176 if (dai->rx_slot_mask)
177 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
179 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
182 static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
184 struct snd_soc_card *card = simple_priv_to_card(priv);
185 struct device *dev = simple_priv_to_dev(priv);
190 dev_dbg(dev, "Card Name: %s\n", card->name);
192 for (i = 0; i < card->num_links; i++) {
193 struct simple_dai_props *props = simple_priv_to_props(priv, i);
194 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
196 dev_dbg(dev, "DAI%d\n", i);
198 asoc_simple_debug_dai(priv, "cpu", props->cpu_dai);
199 asoc_simple_debug_dai(priv, "codec", props->codec_dai);
202 dev_dbg(dev, "dai name = %s\n", link->name);
204 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
206 if (props->adata.convert_rate)
207 dev_dbg(dev, "convert_rate = %d\n",
208 props->adata.convert_rate);
209 if (props->adata.convert_channels)
210 dev_dbg(dev, "convert_channels = %d\n",
211 props->adata.convert_channels);
212 if (props->codec_conf && props->codec_conf->name_prefix)
213 dev_dbg(dev, "name prefix = %s\n",
214 props->codec_conf->name_prefix);
216 dev_dbg(dev, "mclk-fs = %d\n",
221 #define asoc_simple_debug_info(priv)
224 #endif /* __SIMPLE_CARD_UTILS_H */