blob: 0199ad0bbcd04af8cbfcaeb57c795169ca763d94 [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 Morimotoabd31472016-05-31 09:00:14 +000040int asoc_simple_card_parse_daifmt(struct device *dev,
41 struct device_node *node,
42 struct device_node *codec,
43 char *prefix,
44 unsigned int *retfmt);
Nicolas Ioosse5668ca2016-08-23 10:51:22 +020045__printf(3, 4)
Kuninori Morimoto1db33122016-07-11 23:57:14 +000046int asoc_simple_card_set_dailink_name(struct device *dev,
47 struct snd_soc_dai_link *dai_link,
48 const char *fmt, ...);
Kuninori Morimotofc55c9b2016-07-11 23:59:16 +000049int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
50 char *prefix);
Kuninori Morimotoabd31472016-05-31 09:00:14 +000051
Kuninori Morimotoe984fd62017-01-23 07:29:42 +000052#define asoc_simple_card_parse_clk_cpu(dev, node, dai_link, simple_dai) \
Kuninori Morimoto8e166382017-06-05 04:28:45 +000053 asoc_simple_card_parse_clk(dev, node, dai_link->cpu_of_node, simple_dai, \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000054 dai_link->cpu_dai_name, NULL)
Kuninori Morimotoe984fd62017-01-23 07:29:42 +000055#define asoc_simple_card_parse_clk_codec(dev, node, dai_link, simple_dai) \
Kuninori Morimoto8e166382017-06-05 04:28:45 +000056 asoc_simple_card_parse_clk(dev, node, dai_link->codec_of_node, simple_dai,\
Kuninori Morimotoe664de62018-08-31 03:08:09 +000057 dai_link->codec_dai_name, dai_link->codecs)
Kuninori Morimotoe984fd62017-01-23 07:29:42 +000058int asoc_simple_card_parse_clk(struct device *dev,
59 struct device_node *node,
Kuninori Morimotobb6fc622016-08-08 05:59:56 +000060 struct device_node *dai_of_node,
Kuninori Morimoto8e166382017-06-05 04:28:45 +000061 struct asoc_simple_dai *simple_dai,
Kuninori Morimotoe664de62018-08-31 03:08:09 +000062 const char *dai_name,
63 struct snd_soc_dai_link_component *dlc);
Kuninori Morimoto891caea2017-06-09 00:43:18 +000064int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai);
65void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai);
Kuninori Morimotobb6fc622016-08-08 05:59:56 +000066
Kuninori Morimotoae30a692016-08-08 06:01:43 +000067#define asoc_simple_card_parse_cpu(node, dai_link, \
68 list_name, cells_name, is_single_link) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000069 asoc_simple_card_parse_dai(node, NULL, \
70 &dai_link->cpu_of_node, \
Kuninori Morimotoae30a692016-08-08 06:01:43 +000071 &dai_link->cpu_dai_name, list_name, cells_name, is_single_link)
72#define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000073 asoc_simple_card_parse_dai(node, dai_link->codecs, \
74 &dai_link->codec_of_node, \
75 &dai_link->codec_dai_name, \
76 list_name, cells_name, NULL)
Kuninori Morimotoae30a692016-08-08 06:01:43 +000077#define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name) \
Kuninori Morimoto910fdca2019-01-21 09:32:32 +090078 asoc_simple_card_parse_dai(node, dai_link->platforms, \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000079 &dai_link->platform_of_node, \
Kuninori Morimotoae30a692016-08-08 06:01:43 +000080 NULL, list_name, cells_name, NULL)
81int asoc_simple_card_parse_dai(struct device_node *node,
Kuninori Morimotoe664de62018-08-31 03:08:09 +000082 struct snd_soc_dai_link_component *dlc,
Kuninori Morimotoae30a692016-08-08 06:01:43 +000083 struct device_node **endpoint_np,
84 const char **dai_name,
85 const char *list_name,
86 const char *cells_name,
87 int *is_single_links);
88
Kuninori Morimoto16893332017-04-20 01:35:18 +000089#define asoc_simple_card_parse_graph_cpu(ep, dai_link) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000090 asoc_simple_card_parse_graph_dai(ep, NULL, \
91 &dai_link->cpu_of_node, \
Kuninori Morimoto16893332017-04-20 01:35:18 +000092 &dai_link->cpu_dai_name)
93#define asoc_simple_card_parse_graph_codec(ep, dai_link) \
Kuninori Morimotoe664de62018-08-31 03:08:09 +000094 asoc_simple_card_parse_graph_dai(ep, dai_link->codecs, \
95 &dai_link->codec_of_node, \
Kuninori Morimoto16893332017-04-20 01:35:18 +000096 &dai_link->codec_dai_name)
97int asoc_simple_card_parse_graph_dai(struct device_node *ep,
Kuninori Morimotoe664de62018-08-31 03:08:09 +000098 struct snd_soc_dai_link_component *dlc,
Kuninori Morimoto16893332017-04-20 01:35:18 +000099 struct device_node **endpoint_np,
100 const char **dai_name);
101
Kuninori Morimotoe68ba202017-06-14 00:34:35 +0000102#define asoc_simple_card_of_parse_tdm(np, dai) \
103 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
104 &(dai)->rx_slot_mask, \
105 &(dai)->slots, \
106 &(dai)->slot_width);
107
Kuninori Morimoto21ba62f2016-08-09 05:48:30 +0000108int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
109 struct asoc_simple_dai *simple_dai);
Kuninori Morimotoc262c9a2016-08-09 05:49:41 +0000110
Kuninori Morimotofe7ed4d2019-01-21 16:40:59 +0900111void asoc_simple_card_canonicalize_platform(struct snd_soc_dai_link *dai_link);
Kuninori Morimoto983cebd2016-08-10 02:20:19 +0000112void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
113 int is_single_links);
Kuninori Morimotoc262c9a2016-08-09 05:49:41 +0000114
Kuninori Morimoto0f4e0712016-08-10 02:21:25 +0000115int asoc_simple_card_clean_reference(struct snd_soc_card *card);
116
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +0000117void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
118 struct snd_pcm_hw_params *params);
Kuninori Morimotoa48bf022018-11-21 02:10:51 +0000119void asoc_simple_card_parse_convert(struct device *dev,
120 struct device_node *np, char *prefix,
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +0000121 struct asoc_simple_card_data *data);
122
Kuninori Morimoto3296d072017-06-15 00:25:02 +0000123int asoc_simple_card_of_parse_routing(struct snd_soc_card *card,
Kuninori Morimoto33404f32018-11-21 02:11:13 +0000124 char *prefix);
Kuninori Morimotob31f11d2017-06-16 01:38:50 +0000125int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card,
126 char *prefix);
Kuninori Morimoto3296d072017-06-15 00:25:02 +0000127
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +0900128int asoc_simple_card_init_jack(struct snd_soc_card *card,
129 struct asoc_simple_jack *sjack,
130 int is_hp, char *prefix);
131
Kuninori Morimoto0580dde2019-03-20 13:54:42 +0900132
133#ifdef DEBUG
134inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
135 char *name,
136 struct asoc_simple_dai *dai)
137{
138 struct device *dev = simple_priv_to_dev(priv);
139
140 if (dai->name)
141 dev_dbg(dev, "%s dai name = %s\n",
142 name, dai->name);
143 if (dai->sysclk)
144 dev_dbg(dev, "%s sysclk = %d\n",
145 name, dai->sysclk);
146
147 dev_dbg(dev, "%s direction = %s\n",
148 name, dai->clk_direction ? "OUT" : "IN");
149
150 if (dai->slots)
151 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
152 if (dai->slot_width)
153 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
154 if (dai->tx_slot_mask)
155 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
156 if (dai->rx_slot_mask)
157 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
158 if (dai->clk)
159 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
160}
161
162inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
163{
164 struct snd_soc_card *card = simple_priv_to_card(priv);
165 struct device *dev = simple_priv_to_dev(priv);
166
167 int i;
168
169 if (card->name)
170 dev_dbg(dev, "Card Name: %s\n", card->name);
171
172 for (i = 0; i < card->num_links; i++) {
173 struct simple_dai_props *props = simple_priv_to_props(priv, i);
174 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
175
176 dev_dbg(dev, "DAI%d\n", i);
177
178 asoc_simple_debug_dai(priv, "cpu", props->cpu_dai);
179 asoc_simple_debug_dai(priv, "codec", props->codec_dai);
180
181 if (link->name)
182 dev_dbg(dev, "dai name = %s\n", link->name);
183
184 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
185
186 if (props->adata.convert_rate)
187 dev_dbg(dev, "convert_rate = %d\n",
188 props->adata.convert_rate);
189 if (props->adata.convert_channels)
190 dev_dbg(dev, "convert_channels = %d\n",
191 props->adata.convert_channels);
192 if (props->codec_conf && props->codec_conf->name_prefix)
193 dev_dbg(dev, "name prefix = %s\n",
194 props->codec_conf->name_prefix);
195 if (props->mclk_fs)
196 dev_dbg(dev, "mclk-fs = %d\n",
197 props->mclk_fs);
198 }
199}
200#else
201#define asoc_simple_debug_info(priv)
202#endif /* DEBUG */
203
Kuninori Morimoto29a43aa2016-12-02 05:27:30 +0000204#endif /* __SIMPLE_CARD_UTILS_H */