blob: c0161ec17572324ca401d61f839a7ae62bf8174a [file] [log] [blame]
Kuninori Morimotod613a7f2018-07-02 06:30:44 +00001/* SPDX-License-Identifier: GPL-2.0
2 *
Kuninori Morimoto29a43aa2016-12-02 05:27:30 +00003 * simple_card_utils.h
Kuninori Morimotoabd31472016-05-31 09:00:14 +00004 *
5 * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Kuninori Morimotoabd31472016-05-31 09:00:14 +00006 */
Kuninori Morimotod613a7f2018-07-02 06:30:44 +00007
Kuninori Morimoto29a43aa2016-12-02 05:27:30 +00008#ifndef __SIMPLE_CARD_UTILS_H
9#define __SIMPLE_CARD_UTILS_H
Kuninori Morimotoabd31472016-05-31 09:00:14 +000010
11#include <sound/soc.h>
12
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +090013#define asoc_simple_card_init_hp(card, sjack, prefix) \
14 asoc_simple_card_init_jack(card, sjack, 1, prefix)
15#define asoc_simple_card_init_mic(card, sjack, prefix) \
16 asoc_simple_card_init_jack(card, sjack, 0, prefix)
17
Kuninori Morimotocecdef32016-06-30 06:02:46 +000018struct asoc_simple_dai {
19 const char *name;
20 unsigned int sysclk;
Vitaly Woola728f562017-08-17 13:42:36 +020021 int clk_direction;
Kuninori Morimotocecdef32016-06-30 06:02:46 +000022 int slots;
23 int slot_width;
24 unsigned int tx_slot_mask;
25 unsigned int rx_slot_mask;
26 struct clk *clk;
27};
28
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +000029struct asoc_simple_card_data {
30 u32 convert_rate;
31 u32 convert_channels;
32};
33
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +090034struct asoc_simple_jack {
35 struct snd_soc_jack jack;
36 struct snd_soc_jack_pin pin;
37 struct snd_soc_jack_gpio gpio;
38};
39
Kuninori Morimotoe59289c2019-03-20 13:54:59 +090040struct asoc_simple_priv {
41 struct snd_soc_card snd_card;
42 struct simple_dai_props {
43 struct asoc_simple_dai *cpu_dai;
44 struct asoc_simple_dai *codec_dai;
45 struct snd_soc_dai_link_component codecs; /* single codec */
46 struct snd_soc_dai_link_component platforms;
47 struct asoc_simple_card_data adata;
48 struct snd_soc_codec_conf *codec_conf;
49 unsigned int mclk_fs;
50 } *dai_props;
51 struct asoc_simple_jack hp_jack;
52 struct asoc_simple_jack mic_jack;
53 struct snd_soc_dai_link *dai_link;
54 struct asoc_simple_dai *dais;
55 struct snd_soc_codec_conf *codec_conf;
56 struct gpio_desc *pa_gpio;
57};
58#define simple_priv_to_card(priv) (&(priv)->snd_card)
59#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
60#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
61#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
62
Kuninori Morimotoabd31472016-05-31 09:00:14 +000063int asoc_simple_card_parse_daifmt(struct device *dev,
64 struct device_node *node,
65 struct device_node *codec,
66 char *prefix,
67 unsigned int *retfmt);
Nicolas Ioosse5668ca2016-08-23 10:51:22 +020068__printf(3, 4)
Kuninori Morimoto1db33122016-07-11 23:57:14 +000069int asoc_simple_card_set_dailink_name(struct device *dev,
70 struct snd_soc_dai_link *dai_link,
71 const char *fmt, ...);
Kuninori Morimotofc55c9b2016-07-11 23:59:16 +000072int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
73 char *prefix);
Kuninori Morimotoabd31472016-05-31 09:00:14 +000074
Kuninori Morimotoe984fd62017-01-23 07:29:42 +000075#define asoc_simple_card_parse_clk_cpu(dev, node, dai_link, simple_dai) \
Kuninori Morimoto8e166382017-06-05 04:28:45 +000076 asoc_simple_card_parse_clk(dev, node, dai_link->cpu_of_node, simple_dai, \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000077 dai_link->cpu_dai_name, NULL)
Kuninori Morimotoe984fd62017-01-23 07:29:42 +000078#define asoc_simple_card_parse_clk_codec(dev, node, dai_link, simple_dai) \
Kuninori Morimoto8e166382017-06-05 04:28:45 +000079 asoc_simple_card_parse_clk(dev, node, dai_link->codec_of_node, simple_dai,\
Kuninori Morimotoe664de62018-08-31 03:08:09 +000080 dai_link->codec_dai_name, dai_link->codecs)
Kuninori Morimotoe984fd62017-01-23 07:29:42 +000081int asoc_simple_card_parse_clk(struct device *dev,
82 struct device_node *node,
Kuninori Morimotobb6fc622016-08-08 05:59:56 +000083 struct device_node *dai_of_node,
Kuninori Morimoto8e166382017-06-05 04:28:45 +000084 struct asoc_simple_dai *simple_dai,
Kuninori Morimotoe664de62018-08-31 03:08:09 +000085 const char *dai_name,
86 struct snd_soc_dai_link_component *dlc);
Kuninori Morimoto891caea2017-06-09 00:43:18 +000087int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai);
88void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai);
Kuninori Morimotobb6fc622016-08-08 05:59:56 +000089
Kuninori Morimotoae30a692016-08-08 06:01:43 +000090#define asoc_simple_card_parse_cpu(node, dai_link, \
91 list_name, cells_name, is_single_link) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000092 asoc_simple_card_parse_dai(node, NULL, \
93 &dai_link->cpu_of_node, \
Kuninori Morimotoae30a692016-08-08 06:01:43 +000094 &dai_link->cpu_dai_name, list_name, cells_name, is_single_link)
95#define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000096 asoc_simple_card_parse_dai(node, dai_link->codecs, \
97 &dai_link->codec_of_node, \
98 &dai_link->codec_dai_name, \
99 list_name, cells_name, NULL)
Kuninori Morimotoae30a692016-08-08 06:01:43 +0000100#define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name) \
Kuninori Morimoto910fdca2019-01-21 09:32:32 +0900101 asoc_simple_card_parse_dai(node, dai_link->platforms, \
Kuninori Morimotoe664de62018-08-31 03:08:09 +0000102 &dai_link->platform_of_node, \
Kuninori Morimotoae30a692016-08-08 06:01:43 +0000103 NULL, list_name, cells_name, NULL)
104int asoc_simple_card_parse_dai(struct device_node *node,
Kuninori Morimotoe664de62018-08-31 03:08:09 +0000105 struct snd_soc_dai_link_component *dlc,
Kuninori Morimotoae30a692016-08-08 06:01:43 +0000106 struct device_node **endpoint_np,
107 const char **dai_name,
108 const char *list_name,
109 const char *cells_name,
110 int *is_single_links);
111
Kuninori Morimoto16893332017-04-20 01:35:18 +0000112#define asoc_simple_card_parse_graph_cpu(ep, dai_link) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +0000113 asoc_simple_card_parse_graph_dai(ep, NULL, \
114 &dai_link->cpu_of_node, \
Kuninori Morimoto16893332017-04-20 01:35:18 +0000115 &dai_link->cpu_dai_name)
116#define asoc_simple_card_parse_graph_codec(ep, dai_link) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +0000117 asoc_simple_card_parse_graph_dai(ep, dai_link->codecs, \
118 &dai_link->codec_of_node, \
Kuninori Morimoto16893332017-04-20 01:35:18 +0000119 &dai_link->codec_dai_name)
120int asoc_simple_card_parse_graph_dai(struct device_node *ep,
Kuninori Morimotoe664de62018-08-31 03:08:09 +0000121 struct snd_soc_dai_link_component *dlc,
Kuninori Morimoto16893332017-04-20 01:35:18 +0000122 struct device_node **endpoint_np,
123 const char **dai_name);
124
Kuninori Morimotoe68ba202017-06-14 00:34:35 +0000125#define asoc_simple_card_of_parse_tdm(np, dai) \
126 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
127 &(dai)->rx_slot_mask, \
128 &(dai)->slots, \
129 &(dai)->slot_width);
130
Kuninori Morimoto21ba62f2016-08-09 05:48:30 +0000131int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
132 struct asoc_simple_dai *simple_dai);
Kuninori Morimotoc262c9a2016-08-09 05:49:41 +0000133
Kuninori Morimotofe7ed4d2019-01-21 16:40:59 +0900134void asoc_simple_card_canonicalize_platform(struct snd_soc_dai_link *dai_link);
Kuninori Morimoto983cebd2016-08-10 02:20:19 +0000135void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
136 int is_single_links);
Kuninori Morimotoc262c9a2016-08-09 05:49:41 +0000137
Kuninori Morimoto0f4e0712016-08-10 02:21:25 +0000138int asoc_simple_card_clean_reference(struct snd_soc_card *card);
139
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +0000140void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
141 struct snd_pcm_hw_params *params);
Kuninori Morimotoa48bf022018-11-21 02:10:51 +0000142void asoc_simple_card_parse_convert(struct device *dev,
143 struct device_node *np, char *prefix,
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +0000144 struct asoc_simple_card_data *data);
145
Kuninori Morimoto3296d072017-06-15 00:25:02 +0000146int asoc_simple_card_of_parse_routing(struct snd_soc_card *card,
Kuninori Morimoto33404f32018-11-21 02:11:13 +0000147 char *prefix);
Kuninori Morimotob31f11d2017-06-16 01:38:50 +0000148int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card,
149 char *prefix);
Kuninori Morimoto3296d072017-06-15 00:25:02 +0000150
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +0900151int asoc_simple_card_init_jack(struct snd_soc_card *card,
152 struct asoc_simple_jack *sjack,
153 int is_hp, char *prefix);
154
Kuninori Morimoto0580dde2019-03-20 13:54:42 +0900155
156#ifdef DEBUG
157inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
158 char *name,
159 struct asoc_simple_dai *dai)
160{
161 struct device *dev = simple_priv_to_dev(priv);
162
163 if (dai->name)
164 dev_dbg(dev, "%s dai name = %s\n",
165 name, dai->name);
166 if (dai->sysclk)
167 dev_dbg(dev, "%s sysclk = %d\n",
168 name, dai->sysclk);
169
170 dev_dbg(dev, "%s direction = %s\n",
171 name, dai->clk_direction ? "OUT" : "IN");
172
173 if (dai->slots)
174 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
175 if (dai->slot_width)
176 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
177 if (dai->tx_slot_mask)
178 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
179 if (dai->rx_slot_mask)
180 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
181 if (dai->clk)
182 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
183}
184
185inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
186{
187 struct snd_soc_card *card = simple_priv_to_card(priv);
188 struct device *dev = simple_priv_to_dev(priv);
189
190 int i;
191
192 if (card->name)
193 dev_dbg(dev, "Card Name: %s\n", card->name);
194
195 for (i = 0; i < card->num_links; i++) {
196 struct simple_dai_props *props = simple_priv_to_props(priv, i);
197 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
198
199 dev_dbg(dev, "DAI%d\n", i);
200
201 asoc_simple_debug_dai(priv, "cpu", props->cpu_dai);
202 asoc_simple_debug_dai(priv, "codec", props->codec_dai);
203
204 if (link->name)
205 dev_dbg(dev, "dai name = %s\n", link->name);
206
207 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
208
209 if (props->adata.convert_rate)
210 dev_dbg(dev, "convert_rate = %d\n",
211 props->adata.convert_rate);
212 if (props->adata.convert_channels)
213 dev_dbg(dev, "convert_channels = %d\n",
214 props->adata.convert_channels);
215 if (props->codec_conf && props->codec_conf->name_prefix)
216 dev_dbg(dev, "name prefix = %s\n",
217 props->codec_conf->name_prefix);
218 if (props->mclk_fs)
219 dev_dbg(dev, "mclk-fs = %d\n",
220 props->mclk_fs);
221 }
222}
223#else
224#define asoc_simple_debug_info(priv)
225#endif /* DEBUG */
226
Kuninori Morimoto29a43aa2016-12-02 05:27:30 +0000227#endif /* __SIMPLE_CARD_UTILS_H */