blob: bbdd1542d6f130a5efdf44378bde5e950d0f61b0 [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
Daniel Baluta4bbee142019-10-09 18:36:14 +030011#include <linux/clk.h>
Kuninori Morimotoabd31472016-05-31 09:00:14 +000012#include <sound/soc.h>
13
Kuninori Morimotoad11e592019-03-20 13:56:50 +090014#define asoc_simple_init_hp(card, sjack, prefix) \
15 asoc_simple_init_jack(card, sjack, 1, prefix)
16#define asoc_simple_init_mic(card, sjack, prefix) \
17 asoc_simple_init_jack(card, sjack, 0, prefix)
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +090018
Kuninori Morimotocecdef32016-06-30 06:02:46 +000019struct asoc_simple_dai {
20 const char *name;
21 unsigned int sysclk;
Vitaly Woola728f562017-08-17 13:42:36 +020022 int clk_direction;
Kuninori Morimotocecdef32016-06-30 06:02:46 +000023 int slots;
24 int slot_width;
25 unsigned int tx_slot_mask;
26 unsigned int rx_slot_mask;
27 struct clk *clk;
28};
29
Kuninori Morimotoad11e592019-03-20 13:56:50 +090030struct asoc_simple_data {
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +000031 u32 convert_rate;
32 u32 convert_channels;
33};
34
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +090035struct asoc_simple_jack {
36 struct snd_soc_jack jack;
37 struct snd_soc_jack_pin pin;
38 struct snd_soc_jack_gpio gpio;
39};
40
Kuninori Morimotoe59289c2019-03-20 13:54:59 +090041struct asoc_simple_priv {
42 struct snd_soc_card snd_card;
43 struct simple_dai_props {
44 struct asoc_simple_dai *cpu_dai;
45 struct asoc_simple_dai *codec_dai;
Kuninori Morimotof1072942019-06-06 13:07:35 +090046 struct snd_soc_dai_link_component cpus; /* single cpu */
Kuninori Morimotoe59289c2019-03-20 13:54:59 +090047 struct snd_soc_dai_link_component codecs; /* single codec */
48 struct snd_soc_dai_link_component platforms;
Kuninori Morimotoad11e592019-03-20 13:56:50 +090049 struct asoc_simple_data adata;
Kuninori Morimotoe59289c2019-03-20 13:54:59 +090050 struct snd_soc_codec_conf *codec_conf;
51 unsigned int mclk_fs;
52 } *dai_props;
53 struct asoc_simple_jack hp_jack;
54 struct asoc_simple_jack mic_jack;
55 struct snd_soc_dai_link *dai_link;
56 struct asoc_simple_dai *dais;
57 struct snd_soc_codec_conf *codec_conf;
58 struct gpio_desc *pa_gpio;
59};
60#define simple_priv_to_card(priv) (&(priv)->snd_card)
61#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
62#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
63#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
64
Kuninori Morimoto65a50562019-03-20 13:56:26 +090065struct link_info {
66 int dais; /* number of dai */
67 int link; /* number of link */
68 int conf; /* number of codec_conf */
69 int cpu; /* turn for CPU / Codec */
70};
71
Kuninori Morimotoad11e592019-03-20 13:56:50 +090072int asoc_simple_parse_daifmt(struct device *dev,
73 struct device_node *node,
74 struct device_node *codec,
75 char *prefix,
76 unsigned int *retfmt);
Nicolas Ioosse5668ca2016-08-23 10:51:22 +020077__printf(3, 4)
Kuninori Morimotoad11e592019-03-20 13:56:50 +090078int asoc_simple_set_dailink_name(struct device *dev,
79 struct snd_soc_dai_link *dai_link,
80 const char *fmt, ...);
81int asoc_simple_parse_card_name(struct snd_soc_card *card,
82 char *prefix);
Kuninori Morimotoabd31472016-05-31 09:00:14 +000083
Kuninori Morimotoad11e592019-03-20 13:56:50 +090084#define asoc_simple_parse_clk_cpu(dev, node, dai_link, simple_dai) \
Kuninori Morimotof1072942019-06-06 13:07:35 +090085 asoc_simple_parse_clk(dev, node, simple_dai, dai_link->cpus)
Kuninori Morimotoad11e592019-03-20 13:56:50 +090086#define asoc_simple_parse_clk_codec(dev, node, dai_link, simple_dai) \
Kuninori Morimotof1072942019-06-06 13:07:35 +090087 asoc_simple_parse_clk(dev, node, simple_dai, dai_link->codecs)
Kuninori Morimotoad11e592019-03-20 13:56:50 +090088int asoc_simple_parse_clk(struct device *dev,
89 struct device_node *node,
Kuninori Morimotoad11e592019-03-20 13:56:50 +090090 struct asoc_simple_dai *simple_dai,
Kuninori Morimotoad11e592019-03-20 13:56:50 +090091 struct snd_soc_dai_link_component *dlc);
Kuninori Morimotof38df5b2019-03-20 13:55:14 +090092int asoc_simple_startup(struct snd_pcm_substream *substream);
Kuninori Morimoto686911b2019-03-20 13:55:27 +090093void asoc_simple_shutdown(struct snd_pcm_substream *substream);
Kuninori Morimotof48dcbb2019-03-20 13:55:39 +090094int asoc_simple_hw_params(struct snd_pcm_substream *substream,
95 struct snd_pcm_hw_params *params);
Kuninori Morimotoad934ca2019-03-20 13:55:52 +090096int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd);
Kuninori Morimoto629f7542019-03-20 13:56:06 +090097int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
98 struct snd_pcm_hw_params *params);
Kuninori Morimotobb6fc622016-08-08 05:59:56 +000099
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900100#define asoc_simple_parse_cpu(node, dai_link, is_single_link) \
Kuninori Morimotof1072942019-06-06 13:07:35 +0900101 asoc_simple_parse_dai(node, dai_link->cpus, is_single_link)
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900102#define asoc_simple_parse_codec(node, dai_link) \
Kuninori Morimotof1072942019-06-06 13:07:35 +0900103 asoc_simple_parse_dai(node, dai_link->codecs, NULL)
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900104#define asoc_simple_parse_platform(node, dai_link) \
Kuninori Morimotof1072942019-06-06 13:07:35 +0900105 asoc_simple_parse_dai(node, dai_link->platforms, NULL)
Kuninori Morimoto16893332017-04-20 01:35:18 +0000106
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900107#define asoc_simple_parse_tdm(np, dai) \
Kuninori Morimotoe68ba202017-06-14 00:34:35 +0000108 snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
109 &(dai)->rx_slot_mask, \
110 &(dai)->slots, \
111 &(dai)->slot_width);
112
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900113void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link);
114void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
Kuninori Morimoto983cebd2016-08-10 02:20:19 +0000115 int is_single_links);
Kuninori Morimotoc262c9a2016-08-09 05:49:41 +0000116
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900117int asoc_simple_clean_reference(struct snd_soc_card *card);
Kuninori Morimoto0f4e0712016-08-10 02:21:25 +0000118
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900119void asoc_simple_convert_fixup(struct asoc_simple_data *data,
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +0000120 struct snd_pcm_hw_params *params);
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900121void asoc_simple_parse_convert(struct device *dev,
122 struct device_node *np, char *prefix,
123 struct asoc_simple_data *data);
Kuninori Morimoto13bb1cc2017-06-15 00:24:09 +0000124
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900125int asoc_simple_parse_routing(struct snd_soc_card *card,
Kuninori Morimoto33404f32018-11-21 02:11:13 +0000126 char *prefix);
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900127int asoc_simple_parse_widgets(struct snd_soc_card *card,
Kuninori Morimotob31f11d2017-06-16 01:38:50 +0000128 char *prefix);
Paul Cercueil90194282019-04-26 04:25:49 +0200129int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
130 char *prefix);
Kuninori Morimoto3296d072017-06-15 00:25:02 +0000131
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900132int asoc_simple_init_jack(struct snd_soc_card *card,
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +0900133 struct asoc_simple_jack *sjack,
134 int is_hp, char *prefix);
Kuninori Morimotoad11e592019-03-20 13:56:50 +0900135int asoc_simple_init_priv(struct asoc_simple_priv *priv,
Kuninori Morimoto65a50562019-03-20 13:56:26 +0900136 struct link_info *li);
Kuninori Morimoto0580dde2019-03-20 13:54:42 +0900137
138#ifdef DEBUG
Daniel Balutaaf6219592019-10-09 18:36:15 +0300139static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
140 char *name,
141 struct asoc_simple_dai *dai)
Kuninori Morimoto0580dde2019-03-20 13:54:42 +0900142{
143 struct device *dev = simple_priv_to_dev(priv);
144
Kuninori Morimoto52db6682019-07-10 16:59:55 +0900145 /* dai might be NULL */
146 if (!dai)
147 return;
148
Kuninori Morimoto0580dde2019-03-20 13:54:42 +0900149 if (dai->name)
150 dev_dbg(dev, "%s dai name = %s\n",
151 name, dai->name);
152 if (dai->sysclk)
153 dev_dbg(dev, "%s sysclk = %d\n",
154 name, dai->sysclk);
155
156 dev_dbg(dev, "%s direction = %s\n",
157 name, dai->clk_direction ? "OUT" : "IN");
158
159 if (dai->slots)
160 dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
161 if (dai->slot_width)
162 dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
163 if (dai->tx_slot_mask)
164 dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
165 if (dai->rx_slot_mask)
166 dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
167 if (dai->clk)
168 dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
169}
170
Daniel Balutaaf6219592019-10-09 18:36:15 +0300171static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
Kuninori Morimoto0580dde2019-03-20 13:54:42 +0900172{
173 struct snd_soc_card *card = simple_priv_to_card(priv);
174 struct device *dev = simple_priv_to_dev(priv);
175
176 int i;
177
178 if (card->name)
179 dev_dbg(dev, "Card Name: %s\n", card->name);
180
181 for (i = 0; i < card->num_links; i++) {
182 struct simple_dai_props *props = simple_priv_to_props(priv, i);
183 struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
184
185 dev_dbg(dev, "DAI%d\n", i);
186
187 asoc_simple_debug_dai(priv, "cpu", props->cpu_dai);
188 asoc_simple_debug_dai(priv, "codec", props->codec_dai);
189
190 if (link->name)
191 dev_dbg(dev, "dai name = %s\n", link->name);
192
193 dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
194
195 if (props->adata.convert_rate)
196 dev_dbg(dev, "convert_rate = %d\n",
197 props->adata.convert_rate);
198 if (props->adata.convert_channels)
199 dev_dbg(dev, "convert_channels = %d\n",
200 props->adata.convert_channels);
201 if (props->codec_conf && props->codec_conf->name_prefix)
202 dev_dbg(dev, "name prefix = %s\n",
203 props->codec_conf->name_prefix);
204 if (props->mclk_fs)
205 dev_dbg(dev, "mclk-fs = %d\n",
206 props->mclk_fs);
207 }
208}
209#else
210#define asoc_simple_debug_info(priv)
211#endif /* DEBUG */
212
Kuninori Morimoto29a43aa2016-12-02 05:27:30 +0000213#endif /* __SIMPLE_CARD_UTILS_H */