blob: d1f17172dce25ca3dc81d58e76be441ef58133c3 [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 Morimoto868cdb42018-08-31 03:10:20 +000078 asoc_simple_card_parse_dai(node, dai_link->platform, \
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
111int asoc_simple_card_canonicalize_dailink(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,
124 char *prefix,
125 int optional);
Kuninori Morimotob31f11d2017-06-16 01:38:50 +0000126int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card,
127 char *prefix);
Kuninori Morimoto3296d072017-06-15 00:25:02 +0000128
Katsuhiro Suzuki62c2c9f2018-06-11 17:32:12 +0900129int asoc_simple_card_init_jack(struct snd_soc_card *card,
130 struct asoc_simple_jack *sjack,
131 int is_hp, char *prefix);
132
Kuninori Morimoto29a43aa2016-12-02 05:27:30 +0000133#endif /* __SIMPLE_CARD_UTILS_H */