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 | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame^] | 40 | struct 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 Morimoto | abd3147 | 2016-05-31 09:00:14 +0000 | [diff] [blame] | 63 | int 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 Iooss | e5668ca | 2016-08-23 10:51:22 +0200 | [diff] [blame] | 68 | __printf(3, 4) |
Kuninori Morimoto | 1db3312 | 2016-07-11 23:57:14 +0000 | [diff] [blame] | 69 | int asoc_simple_card_set_dailink_name(struct device *dev, |
| 70 | struct snd_soc_dai_link *dai_link, |
| 71 | const char *fmt, ...); |
Kuninori Morimoto | fc55c9b | 2016-07-11 23:59:16 +0000 | [diff] [blame] | 72 | int asoc_simple_card_parse_card_name(struct snd_soc_card *card, |
| 73 | char *prefix); |
Kuninori Morimoto | abd3147 | 2016-05-31 09:00:14 +0000 | [diff] [blame] | 74 | |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 75 | #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] | 76 | 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] | 77 | dai_link->cpu_dai_name, NULL) |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 78 | #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] | 79 | 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] | 80 | dai_link->codec_dai_name, dai_link->codecs) |
Kuninori Morimoto | e984fd6 | 2017-01-23 07:29:42 +0000 | [diff] [blame] | 81 | int asoc_simple_card_parse_clk(struct device *dev, |
| 82 | struct device_node *node, |
Kuninori Morimoto | bb6fc62 | 2016-08-08 05:59:56 +0000 | [diff] [blame] | 83 | struct device_node *dai_of_node, |
Kuninori Morimoto | 8e16638 | 2017-06-05 04:28:45 +0000 | [diff] [blame] | 84 | struct asoc_simple_dai *simple_dai, |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 85 | const char *dai_name, |
| 86 | struct snd_soc_dai_link_component *dlc); |
Kuninori Morimoto | 891caea | 2017-06-09 00:43:18 +0000 | [diff] [blame] | 87 | int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai); |
| 88 | void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai); |
Kuninori Morimoto | bb6fc62 | 2016-08-08 05:59:56 +0000 | [diff] [blame] | 89 | |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 90 | #define asoc_simple_card_parse_cpu(node, dai_link, \ |
| 91 | list_name, cells_name, is_single_link) \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 92 | asoc_simple_card_parse_dai(node, NULL, \ |
| 93 | &dai_link->cpu_of_node, \ |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 94 | &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 Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 96 | 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 Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 100 | #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] | 101 | asoc_simple_card_parse_dai(node, dai_link->platforms, \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 102 | &dai_link->platform_of_node, \ |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 103 | NULL, list_name, cells_name, NULL) |
| 104 | int asoc_simple_card_parse_dai(struct device_node *node, |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 105 | struct snd_soc_dai_link_component *dlc, |
Kuninori Morimoto | ae30a69 | 2016-08-08 06:01:43 +0000 | [diff] [blame] | 106 | 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 Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 112 | #define asoc_simple_card_parse_graph_cpu(ep, dai_link) \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 113 | asoc_simple_card_parse_graph_dai(ep, NULL, \ |
| 114 | &dai_link->cpu_of_node, \ |
Kuninori Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 115 | &dai_link->cpu_dai_name) |
| 116 | #define asoc_simple_card_parse_graph_codec(ep, dai_link) \ |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 117 | asoc_simple_card_parse_graph_dai(ep, dai_link->codecs, \ |
| 118 | &dai_link->codec_of_node, \ |
Kuninori Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 119 | &dai_link->codec_dai_name) |
| 120 | int asoc_simple_card_parse_graph_dai(struct device_node *ep, |
Kuninori Morimoto | e664de6 | 2018-08-31 03:08:09 +0000 | [diff] [blame] | 121 | struct snd_soc_dai_link_component *dlc, |
Kuninori Morimoto | 1689333 | 2017-04-20 01:35:18 +0000 | [diff] [blame] | 122 | struct device_node **endpoint_np, |
| 123 | const char **dai_name); |
| 124 | |
Kuninori Morimoto | e68ba20 | 2017-06-14 00:34:35 +0000 | [diff] [blame] | 125 | #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 Morimoto | 21ba62f | 2016-08-09 05:48:30 +0000 | [diff] [blame] | 131 | int asoc_simple_card_init_dai(struct snd_soc_dai *dai, |
| 132 | struct asoc_simple_dai *simple_dai); |
Kuninori Morimoto | c262c9a | 2016-08-09 05:49:41 +0000 | [diff] [blame] | 133 | |
Kuninori Morimoto | fe7ed4d | 2019-01-21 16:40:59 +0900 | [diff] [blame] | 134 | 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] | 135 | void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link, |
| 136 | int is_single_links); |
Kuninori Morimoto | c262c9a | 2016-08-09 05:49:41 +0000 | [diff] [blame] | 137 | |
Kuninori Morimoto | 0f4e071 | 2016-08-10 02:21:25 +0000 | [diff] [blame] | 138 | int asoc_simple_card_clean_reference(struct snd_soc_card *card); |
| 139 | |
Kuninori Morimoto | 13bb1cc | 2017-06-15 00:24:09 +0000 | [diff] [blame] | 140 | void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data, |
| 141 | struct snd_pcm_hw_params *params); |
Kuninori Morimoto | a48bf02 | 2018-11-21 02:10:51 +0000 | [diff] [blame] | 142 | void asoc_simple_card_parse_convert(struct device *dev, |
| 143 | struct device_node *np, char *prefix, |
Kuninori Morimoto | 13bb1cc | 2017-06-15 00:24:09 +0000 | [diff] [blame] | 144 | struct asoc_simple_card_data *data); |
| 145 | |
Kuninori Morimoto | 3296d07 | 2017-06-15 00:25:02 +0000 | [diff] [blame] | 146 | int asoc_simple_card_of_parse_routing(struct snd_soc_card *card, |
Kuninori Morimoto | 33404f3 | 2018-11-21 02:11:13 +0000 | [diff] [blame] | 147 | char *prefix); |
Kuninori Morimoto | b31f11d | 2017-06-16 01:38:50 +0000 | [diff] [blame] | 148 | int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card, |
| 149 | char *prefix); |
Kuninori Morimoto | 3296d07 | 2017-06-15 00:25:02 +0000 | [diff] [blame] | 150 | |
Katsuhiro Suzuki | 62c2c9f | 2018-06-11 17:32:12 +0900 | [diff] [blame] | 151 | int asoc_simple_card_init_jack(struct snd_soc_card *card, |
| 152 | struct asoc_simple_jack *sjack, |
| 153 | int is_hp, char *prefix); |
| 154 | |
Kuninori Morimoto | 0580dde | 2019-03-20 13:54:42 +0900 | [diff] [blame] | 155 | |
| 156 | #ifdef DEBUG |
| 157 | inline 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 | |
| 185 | inline 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 Morimoto | 29a43aa | 2016-12-02 05:27:30 +0000 | [diff] [blame] | 227 | #endif /* __SIMPLE_CARD_UTILS_H */ |