Kuninori Morimoto | d613a7f | 2018-07-02 06:30:44 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * |
Kuninori Morimoto | 29a43aa | 2016-12-02 05:27:30 +0000 | [diff] [blame] | 3 | * simple_card_utils.h |
Kuninori Morimoto | abd3147 | 2016-05-31 09:00:14 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
Kuninori Morimoto | abd3147 | 2016-05-31 09:00:14 +0000 | [diff] [blame] | 6 | */ |
Kuninori Morimoto | d613a7f | 2018-07-02 06:30:44 +0000 | [diff] [blame] | 7 | |
Kuninori Morimoto | 29a43aa | 2016-12-02 05:27:30 +0000 | [diff] [blame] | 8 | #ifndef __SIMPLE_CARD_UTILS_H |
| 9 | #define __SIMPLE_CARD_UTILS_H |
Kuninori Morimoto | abd3147 | 2016-05-31 09:00:14 +0000 | [diff] [blame] | 10 | |
| 11 | #include <sound/soc.h> |
| 12 | |
Katsuhiro Suzuki | 62c2c9f | 2018-06-11 17:32:12 +0900 | [diff] [blame] | 13 | #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 Morimoto | cecdef3 | 2016-06-30 06:02:46 +0000 | [diff] [blame] | 18 | struct asoc_simple_dai { |
| 19 | const char *name; |
| 20 | unsigned int sysclk; |
Vitaly Wool | a728f56 | 2017-08-17 13:42:36 +0200 | [diff] [blame] | 21 | int clk_direction; |
Kuninori Morimoto | cecdef3 | 2016-06-30 06:02:46 +0000 | [diff] [blame] | 22 | 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 Morimoto | 13bb1cc | 2017-06-15 00:24:09 +0000 | [diff] [blame] | 29 | struct asoc_simple_card_data { |
| 30 | u32 convert_rate; |
| 31 | u32 convert_channels; |
| 32 | }; |
| 33 | |
Katsuhiro Suzuki | 62c2c9f | 2018-06-11 17:32:12 +0900 | [diff] [blame] | 34 | struct 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 Morimoto | abd3147 | 2016-05-31 09:00:14 +0000 | [diff] [blame] | 40 | int 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 Iooss | e5668ca | 2016-08-23 10:51:22 +0200 | [diff] [blame] | 45 | __printf(3, 4) |
Kuninori Morimoto | 1db3312 | 2016-07-11 23:57:14 +0000 | [diff] [blame] | 46 | int asoc_simple_card_set_dailink_name(struct device *dev, |
| 47 | struct snd_soc_dai_link *dai_link, |
| 48 | const char *fmt, ...); |
Kuninori Morimoto | fc55c9b | 2016-07-11 23:59:16 +0000 | [diff] [blame] | 49 | int asoc_simple_card_parse_card_name(struct snd_soc_card *card, |
| 50 | char *prefix); |
Kuninori Morimoto | abd3147 | 2016-05-31 09:00:14 +0000 | [diff] [blame] | 51 | |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 52 | #define asoc_simple_card_parse_clk_cpu(dev, node, dai_link, simple_dai) \ |
Kuninori Morimoto | 8e16638 | 2017-06-05 04:28:45 +0000 | [diff] [blame] | 53 | asoc_simple_card_parse_clk(dev, node, dai_link->cpu_of_node, simple_dai, \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 54 | dai_link->cpu_dai_name, NULL) |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 55 | #define asoc_simple_card_parse_clk_codec(dev, node, dai_link, simple_dai) \ |
Kuninori Morimoto | 8e16638 | 2017-06-05 04:28:45 +0000 | [diff] [blame] | 56 | asoc_simple_card_parse_clk(dev, node, dai_link->codec_of_node, simple_dai,\ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 57 | dai_link->codec_dai_name, dai_link->codecs) |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 58 | int asoc_simple_card_parse_clk(struct device *dev, |
| 59 | struct device_node *node, |
Kuninori Morimoto | bb6fc62 | 2016-08-08 05:59:56 +0000 | [diff] [blame] | 60 | struct device_node *dai_of_node, |
Kuninori Morimoto | 8e16638 | 2017-06-05 04:28:45 +0000 | [diff] [blame] | 61 | struct asoc_simple_dai *simple_dai, |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 62 | const char *dai_name, |
| 63 | struct snd_soc_dai_link_component *dlc); |
Kuninori Morimoto | 891caea | 2017-06-09 00:43:18 +0000 | [diff] [blame] | 64 | int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai); |
| 65 | void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai); |
Kuninori Morimoto | bb6fc62 | 2016-08-08 05:59:56 +0000 | [diff] [blame] | 66 | |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 67 | #define asoc_simple_card_parse_cpu(node, dai_link, \ |
| 68 | list_name, cells_name, is_single_link) \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 69 | asoc_simple_card_parse_dai(node, NULL, \ |
| 70 | &dai_link->cpu_of_node, \ |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 71 | &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 Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 73 | 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 Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 77 | #define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name) \ |
Kuninori Morimoto | 910fdca | 2019-01-21 09:32:32 +0900 | [diff] [blame] | 78 | asoc_simple_card_parse_dai(node, dai_link->platforms, \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 79 | &dai_link->platform_of_node, \ |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 80 | NULL, list_name, cells_name, NULL) |
| 81 | int asoc_simple_card_parse_dai(struct device_node *node, |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 82 | struct snd_soc_dai_link_component *dlc, |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 83 | 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 Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 89 | #define asoc_simple_card_parse_graph_cpu(ep, dai_link) \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 90 | asoc_simple_card_parse_graph_dai(ep, NULL, \ |
| 91 | &dai_link->cpu_of_node, \ |
Kuninori Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 92 | &dai_link->cpu_dai_name) |
| 93 | #define asoc_simple_card_parse_graph_codec(ep, dai_link) \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 94 | asoc_simple_card_parse_graph_dai(ep, dai_link->codecs, \ |
| 95 | &dai_link->codec_of_node, \ |
Kuninori Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 96 | &dai_link->codec_dai_name) |
| 97 | int asoc_simple_card_parse_graph_dai(struct device_node *ep, |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 98 | struct snd_soc_dai_link_component *dlc, |
Kuninori Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 99 | struct device_node **endpoint_np, |
| 100 | const char **dai_name); |
| 101 | |
Kuninori Morimoto | e68ba20 | 2017-06-14 00:34:35 +0000 | [diff] [blame] | 102 | #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 Morimoto | 21ba62f | 2016-08-09 05:48:30 +0000 | [diff] [blame] | 108 | int asoc_simple_card_init_dai(struct snd_soc_dai *dai, |
| 109 | struct asoc_simple_dai *simple_dai); |
Kuninori Morimoto | c262c9a | 2016-08-09 05:49:41 +0000 | [diff] [blame] | 110 | |
Kuninori Morimoto | fe7ed4d | 2019-01-21 16:40:59 +0900 | [diff] [blame] | 111 | void asoc_simple_card_canonicalize_platform(struct snd_soc_dai_link *dai_link); |
Kuninori Morimoto | 983cebd | 2016-08-10 02:20:19 +0000 | [diff] [blame] | 112 | void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link, |
| 113 | int is_single_links); |
Kuninori Morimoto | c262c9a | 2016-08-09 05:49:41 +0000 | [diff] [blame] | 114 | |
Kuninori Morimoto | 0f4e071 | 2016-08-10 02:21:25 +0000 | [diff] [blame] | 115 | int asoc_simple_card_clean_reference(struct snd_soc_card *card); |
| 116 | |
Kuninori Morimoto | 13bb1cc | 2017-06-15 00:24:09 +0000 | [diff] [blame] | 117 | void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data, |
| 118 | struct snd_pcm_hw_params *params); |
Kuninori Morimoto | a48bf02 | 2018-11-21 02:10:51 +0000 | [diff] [blame] | 119 | void asoc_simple_card_parse_convert(struct device *dev, |
| 120 | struct device_node *np, char *prefix, |
Kuninori Morimoto | 13bb1cc | 2017-06-15 00:24:09 +0000 | [diff] [blame] | 121 | struct asoc_simple_card_data *data); |
| 122 | |
Kuninori Morimoto | 3296d07 | 2017-06-15 00:25:02 +0000 | [diff] [blame] | 123 | int asoc_simple_card_of_parse_routing(struct snd_soc_card *card, |
Kuninori Morimoto | 33404f3 | 2018-11-21 02:11:13 +0000 | [diff] [blame] | 124 | char *prefix); |
Kuninori Morimoto | b31f11d | 2017-06-16 01:38:50 +0000 | [diff] [blame] | 125 | int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card, |
| 126 | char *prefix); |
Kuninori Morimoto | 3296d07 | 2017-06-15 00:25:02 +0000 | [diff] [blame] | 127 | |
Katsuhiro Suzuki | 62c2c9f | 2018-06-11 17:32:12 +0900 | [diff] [blame] | 128 | int asoc_simple_card_init_jack(struct snd_soc_card *card, |
| 129 | struct asoc_simple_jack *sjack, |
| 130 | int is_hp, char *prefix); |
| 131 | |
Kuninori Morimoto | 0580dde | 2019-03-20 13:54:42 +0900 | [diff] [blame^] | 132 | |
| 133 | #ifdef DEBUG |
| 134 | inline 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 | |
| 162 | inline 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 Morimoto | 29a43aa | 2016-12-02 05:27:30 +0000 | [diff] [blame] | 204 | #endif /* __SIMPLE_CARD_UTILS_H */ |