Kuninori Morimoto | d573454 | 2018-07-02 06:30:28 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // ASoC simple sound card support |
| 4 | // |
| 5 | // Copyright (C) 2012 Renesas Solutions Corp. |
| 6 | // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 7 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 8 | #include <linux/clk.h> |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 9 | #include <linux/device.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 11 | #include <linux/of.h> |
Kuninori Morimoto | 42bf029 | 2019-04-04 09:52:52 +0900 | [diff] [blame] | 12 | #include <linux/of_device.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 13 | #include <linux/platform_device.h> |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 14 | #include <linux/string.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 15 | #include <sound/simple_card.h> |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 16 | #include <sound/soc-dai.h> |
| 17 | #include <sound/soc.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 18 | |
Kuninori Morimoto | 42bf029 | 2019-04-04 09:52:52 +0900 | [diff] [blame] | 19 | #define DPCM_SELECTABLE 1 |
| 20 | |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame] | 21 | #define DAI "sound-dai" |
| 22 | #define CELL "#sound-dai-cells" |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 23 | #define PREFIX "simple-audio-card," |
| 24 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 25 | static const struct snd_soc_ops simple_ops = { |
Kuninori Morimoto | f38df5b | 2019-03-20 13:55:14 +0900 | [diff] [blame] | 26 | .startup = asoc_simple_startup, |
Kuninori Morimoto | 686911b | 2019-03-20 13:55:27 +0900 | [diff] [blame] | 27 | .shutdown = asoc_simple_shutdown, |
Kuninori Morimoto | f48dcbb | 2019-03-20 13:55:39 +0900 | [diff] [blame] | 28 | .hw_params = asoc_simple_hw_params, |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 29 | }; |
| 30 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 31 | static int asoc_simple_parse_dai(struct device_node *node, |
| 32 | struct snd_soc_dai_link_component *dlc, |
| 33 | struct device_node **dai_of_node, |
| 34 | const char **dai_name, |
| 35 | int *is_single_link) |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 36 | { |
| 37 | struct of_phandle_args args; |
| 38 | int ret; |
| 39 | |
| 40 | if (!node) |
| 41 | return 0; |
| 42 | |
| 43 | /* |
| 44 | * Use snd_soc_dai_link_component instead of legacy style. |
| 45 | * It is only for codec, but cpu will be supported in the future. |
| 46 | * see |
| 47 | * soc-core.c :: snd_soc_init_multicodec() |
| 48 | */ |
| 49 | if (dlc) { |
| 50 | dai_name = &dlc->dai_name; |
| 51 | dai_of_node = &dlc->of_node; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Get node via "sound-dai = <&phandle port>" |
| 56 | * it will be used as xxx_of_node on soc_bind_dai_link() |
| 57 | */ |
| 58 | ret = of_parse_phandle_with_args(node, DAI, CELL, 0, &args); |
| 59 | if (ret) |
| 60 | return ret; |
| 61 | |
| 62 | /* Get dai->name */ |
| 63 | if (dai_name) { |
| 64 | ret = snd_soc_of_get_dai_name(node, dai_name); |
| 65 | if (ret < 0) |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | *dai_of_node = args.np; |
| 70 | |
| 71 | if (is_single_link) |
| 72 | *is_single_link = !args.args_count; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Kuninori Morimoto | cdc4447 | 2019-03-18 13:50:08 +0900 | [diff] [blame] | 77 | static void simple_parse_convert(struct device *dev, |
| 78 | struct device_node *np, |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 79 | struct asoc_simple_data *adata) |
Kuninori Morimoto | 7e5e1f8 | 2018-12-20 10:46:42 +0900 | [diff] [blame] | 80 | { |
| 81 | struct device_node *top = dev->of_node; |
| 82 | struct device_node *node = of_get_parent(np); |
| 83 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 84 | asoc_simple_parse_convert(dev, top, PREFIX, adata); |
| 85 | asoc_simple_parse_convert(dev, node, PREFIX, adata); |
| 86 | asoc_simple_parse_convert(dev, node, NULL, adata); |
| 87 | asoc_simple_parse_convert(dev, np, NULL, adata); |
Kuninori Morimoto | 7e5e1f8 | 2018-12-20 10:46:42 +0900 | [diff] [blame] | 88 | |
| 89 | of_node_put(node); |
| 90 | } |
| 91 | |
Kuninori Morimoto | d708d35 | 2019-03-18 13:50:17 +0900 | [diff] [blame] | 92 | static void simple_parse_mclk_fs(struct device_node *top, |
| 93 | struct device_node *cpu, |
| 94 | struct device_node *codec, |
| 95 | struct simple_dai_props *props, |
| 96 | char *prefix) |
| 97 | { |
| 98 | struct device_node *node = of_get_parent(cpu); |
| 99 | char prop[128]; |
| 100 | |
| 101 | snprintf(prop, sizeof(prop), "%smclk-fs", PREFIX); |
| 102 | of_property_read_u32(top, prop, &props->mclk_fs); |
| 103 | |
| 104 | snprintf(prop, sizeof(prop), "%smclk-fs", prefix); |
| 105 | of_property_read_u32(node, prop, &props->mclk_fs); |
| 106 | of_property_read_u32(cpu, prop, &props->mclk_fs); |
| 107 | of_property_read_u32(codec, prop, &props->mclk_fs); |
| 108 | |
| 109 | of_node_put(node); |
| 110 | } |
| 111 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 112 | static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 113 | struct device_node *np, |
| 114 | struct device_node *codec, |
| 115 | struct link_info *li, |
| 116 | bool is_top) |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 117 | { |
| 118 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 119 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 120 | struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 121 | struct asoc_simple_dai *dai; |
Kuninori Morimoto | cfc652a | 2018-12-14 11:35:24 +0900 | [diff] [blame] | 122 | struct snd_soc_dai_link_component *codecs = dai_link->codecs; |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 123 | struct device_node *top = dev->of_node; |
| 124 | struct device_node *node = of_get_parent(np); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 125 | char *prefix = ""; |
| 126 | int ret; |
| 127 | |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 128 | /* |
| 129 | * |CPU |Codec : turn |
| 130 | * CPU |Pass |return |
| 131 | * Codec |return|Pass |
| 132 | * np |
| 133 | */ |
| 134 | if (li->cpu == (np == codec)) |
| 135 | return 0; |
| 136 | |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 137 | dev_dbg(dev, "link_of DPCM (%pOF)\n", np); |
| 138 | |
| 139 | li->link++; |
| 140 | |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 141 | of_node_put(node); |
| 142 | |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 143 | /* For single DAI link & old style of DT node */ |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 144 | if (is_top) |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 145 | prefix = PREFIX; |
| 146 | |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 147 | if (li->cpu) { |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 148 | int is_single_links = 0; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 149 | |
| 150 | /* BE is dummy */ |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 151 | codecs->of_node = NULL; |
| 152 | codecs->dai_name = "snd-soc-dummy-dai"; |
| 153 | codecs->name = "snd-soc-dummy"; |
| 154 | |
| 155 | /* FE settings */ |
| 156 | dai_link->dynamic = 1; |
| 157 | dai_link->dpcm_merged_format = 1; |
| 158 | |
| 159 | dai = |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 160 | dai_props->cpu_dai = &priv->dais[li->dais++]; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 161 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 162 | ret = asoc_simple_parse_cpu(np, dai_link, &is_single_links); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 163 | if (ret) |
| 164 | return ret; |
| 165 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 166 | ret = asoc_simple_parse_clk_cpu(dev, np, dai_link, dai); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 167 | if (ret < 0) |
| 168 | return ret; |
| 169 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 170 | ret = asoc_simple_set_dailink_name(dev, dai_link, |
| 171 | "fe.%s", |
| 172 | dai_link->cpu_dai_name); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 173 | if (ret < 0) |
| 174 | return ret; |
| 175 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 176 | asoc_simple_canonicalize_cpu(dai_link, is_single_links); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 177 | } else { |
| 178 | struct snd_soc_codec_conf *cconf; |
| 179 | |
| 180 | /* FE is dummy */ |
| 181 | dai_link->cpu_of_node = NULL; |
| 182 | dai_link->cpu_dai_name = "snd-soc-dummy-dai"; |
| 183 | dai_link->cpu_name = "snd-soc-dummy"; |
| 184 | |
| 185 | /* BE settings */ |
| 186 | dai_link->no_pcm = 1; |
Kuninori Morimoto | 629f754 | 2019-03-20 13:56:06 +0900 | [diff] [blame] | 187 | dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 188 | |
| 189 | dai = |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 190 | dai_props->codec_dai = &priv->dais[li->dais++]; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 191 | |
| 192 | cconf = |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 193 | dai_props->codec_conf = &priv->codec_conf[li->conf++]; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 194 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 195 | ret = asoc_simple_parse_codec(np, dai_link); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 196 | if (ret < 0) |
| 197 | return ret; |
| 198 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 199 | ret = asoc_simple_parse_clk_codec(dev, np, dai_link, dai); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 200 | if (ret < 0) |
| 201 | return ret; |
| 202 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 203 | ret = asoc_simple_set_dailink_name(dev, dai_link, |
| 204 | "be.%s", |
| 205 | codecs->dai_name); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 206 | if (ret < 0) |
| 207 | return ret; |
| 208 | |
| 209 | /* check "prefix" from top node */ |
Kuninori Morimoto | cfc652a | 2018-12-14 11:35:24 +0900 | [diff] [blame] | 210 | snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node, |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 211 | PREFIX "prefix"); |
Kuninori Morimoto | cfc652a | 2018-12-14 11:35:24 +0900 | [diff] [blame] | 212 | snd_soc_of_parse_node_prefix(node, cconf, codecs->of_node, |
| 213 | "prefix"); |
| 214 | snd_soc_of_parse_node_prefix(np, cconf, codecs->of_node, |
| 215 | "prefix"); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 216 | } |
| 217 | |
Kuninori Morimoto | cdc4447 | 2019-03-18 13:50:08 +0900 | [diff] [blame] | 218 | simple_parse_convert(dev, np, &dai_props->adata); |
Kuninori Morimoto | d708d35 | 2019-03-18 13:50:17 +0900 | [diff] [blame] | 219 | simple_parse_mclk_fs(top, np, codec, dai_props, prefix); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 220 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 221 | asoc_simple_canonicalize_platform(dai_link); |
Kuninori Morimoto | fe7ed4d | 2019-01-21 16:40:59 +0900 | [diff] [blame] | 222 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 223 | ret = asoc_simple_parse_tdm(np, dai); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 224 | if (ret) |
| 225 | return ret; |
| 226 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 227 | ret = asoc_simple_parse_daifmt(dev, node, codec, |
| 228 | prefix, &dai_link->dai_fmt); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 229 | if (ret < 0) |
| 230 | return ret; |
| 231 | |
| 232 | dai_link->dpcm_playback = 1; |
| 233 | dai_link->dpcm_capture = 1; |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 234 | dai_link->ops = &simple_ops; |
Kuninori Morimoto | ad934ca | 2019-03-20 13:55:52 +0900 | [diff] [blame] | 235 | dai_link->init = asoc_simple_dai_init; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 240 | static int simple_dai_link_of(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 241 | struct device_node *np, |
| 242 | struct device_node *codec, |
| 243 | struct link_info *li, |
| 244 | bool is_top) |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 245 | { |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 246 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 247 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 248 | struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link); |
Kuninori Morimoto | 4fb7f4d | 2018-12-04 08:19:43 +0000 | [diff] [blame] | 249 | struct asoc_simple_dai *cpu_dai; |
| 250 | struct asoc_simple_dai *codec_dai; |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 251 | struct device_node *top = dev->of_node; |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 252 | struct device_node *cpu = NULL; |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 253 | struct device_node *node = NULL; |
Jun Nie | e0ae225 | 2015-04-29 18:11:07 +0800 | [diff] [blame] | 254 | struct device_node *plat = NULL; |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 255 | char prop[128]; |
| 256 | char *prefix = ""; |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame] | 257 | int ret, single_cpu; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 258 | |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 259 | /* |
| 260 | * |CPU |Codec : turn |
| 261 | * CPU |Pass |return |
| 262 | * Codec |return|return |
| 263 | * np |
| 264 | */ |
| 265 | if (!li->cpu || np == codec) |
| 266 | return 0; |
| 267 | |
| 268 | cpu = np; |
| 269 | node = of_get_parent(np); |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 270 | li->link++; |
| 271 | |
| 272 | dev_dbg(dev, "link_of (%pOF)\n", node); |
| 273 | |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 274 | /* For single DAI link & old style of DT node */ |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 275 | if (is_top) |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 276 | prefix = PREFIX; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 277 | |
Jun Nie | e0ae225 | 2015-04-29 18:11:07 +0800 | [diff] [blame] | 278 | snprintf(prop, sizeof(prop), "%splat", prefix); |
| 279 | plat = of_get_child_by_name(node, prop); |
| 280 | |
Kuninori Morimoto | 4fb7f4d | 2018-12-04 08:19:43 +0000 | [diff] [blame] | 281 | cpu_dai = |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 282 | dai_props->cpu_dai = &priv->dais[li->dais++]; |
Kuninori Morimoto | 4fb7f4d | 2018-12-04 08:19:43 +0000 | [diff] [blame] | 283 | codec_dai = |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 284 | dai_props->codec_dai = &priv->dais[li->dais++]; |
Kuninori Morimoto | 4fb7f4d | 2018-12-04 08:19:43 +0000 | [diff] [blame] | 285 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 286 | ret = asoc_simple_parse_daifmt(dev, node, codec, |
| 287 | prefix, &dai_link->dai_fmt); |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 288 | if (ret < 0) |
| 289 | goto dai_link_of_err; |
| 290 | |
Kuninori Morimoto | d708d35 | 2019-03-18 13:50:17 +0900 | [diff] [blame] | 291 | simple_parse_mclk_fs(top, cpu, codec, dai_props, prefix); |
Arnaud Pouliquen | 85a4bfd | 2015-06-05 10:19:05 +0200 | [diff] [blame] | 292 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 293 | ret = asoc_simple_parse_cpu(cpu, dai_link, &single_cpu); |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame] | 294 | if (ret < 0) |
| 295 | goto dai_link_of_err; |
| 296 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 297 | ret = asoc_simple_parse_codec(codec, dai_link); |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame] | 298 | if (ret < 0) |
| 299 | goto dai_link_of_err; |
| 300 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 301 | ret = asoc_simple_parse_platform(plat, dai_link); |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame] | 302 | if (ret < 0) |
| 303 | goto dai_link_of_err; |
| 304 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 305 | ret = asoc_simple_parse_tdm(cpu, cpu_dai); |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 306 | if (ret < 0) |
| 307 | goto dai_link_of_err; |
| 308 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 309 | ret = asoc_simple_parse_tdm(codec, codec_dai); |
Kuninori Morimoto | 5fb9cb1 | 2016-05-20 09:40:41 +0000 | [diff] [blame] | 310 | if (ret < 0) |
| 311 | goto dai_link_of_err; |
| 312 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 313 | ret = asoc_simple_parse_clk_cpu(dev, cpu, dai_link, cpu_dai); |
Kuninori Morimoto | 28abd99 | 2016-07-19 02:53:13 +0000 | [diff] [blame] | 314 | if (ret < 0) |
| 315 | goto dai_link_of_err; |
| 316 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 317 | ret = asoc_simple_parse_clk_codec(dev, codec, dai_link, codec_dai); |
Kuninori Morimoto | 28abd99 | 2016-07-19 02:53:13 +0000 | [diff] [blame] | 318 | if (ret < 0) |
| 319 | goto dai_link_of_err; |
| 320 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 321 | ret = asoc_simple_set_dailink_name(dev, dai_link, |
| 322 | "%s-%s", |
| 323 | dai_link->cpu_dai_name, |
| 324 | dai_link->codecs->dai_name); |
Kuninori Morimoto | 2e8d1c7 | 2016-07-11 23:57:34 +0000 | [diff] [blame] | 325 | if (ret < 0) |
Vishal Thanki | 31f3032 | 2015-03-03 18:59:00 +0530 | [diff] [blame] | 326 | goto dai_link_of_err; |
Vishal Thanki | 31f3032 | 2015-03-03 18:59:00 +0530 | [diff] [blame] | 327 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 328 | dai_link->ops = &simple_ops; |
Kuninori Morimoto | ad934ca | 2019-03-20 13:55:52 +0900 | [diff] [blame] | 329 | dai_link->init = asoc_simple_dai_init; |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 330 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 331 | asoc_simple_canonicalize_cpu(dai_link, single_cpu); |
| 332 | asoc_simple_canonicalize_platform(dai_link); |
Kuninori Morimoto | 179949b | 2014-08-27 20:08:06 -0700 | [diff] [blame] | 333 | |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 334 | dai_link_of_err: |
Takashi Iwai | 44662f9 | 2019-02-19 16:46:48 +0100 | [diff] [blame] | 335 | of_node_put(plat); |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 336 | of_node_put(node); |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 337 | |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 338 | return ret; |
| 339 | } |
| 340 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 341 | static int simple_for_each_link(struct asoc_simple_priv *priv, |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 342 | struct link_info *li, |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 343 | int (*func_noml)(struct asoc_simple_priv *priv, |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 344 | struct device_node *np, |
| 345 | struct device_node *codec, |
| 346 | struct link_info *li, bool is_top), |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 347 | int (*func_dpcm)(struct asoc_simple_priv *priv, |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 348 | struct device_node *np, |
| 349 | struct device_node *codec, |
| 350 | struct link_info *li, bool is_top)) |
| 351 | { |
| 352 | struct device *dev = simple_priv_to_dev(priv); |
| 353 | struct device_node *top = dev->of_node; |
| 354 | struct device_node *node; |
Kuninori Morimoto | 42bf029 | 2019-04-04 09:52:52 +0900 | [diff] [blame] | 355 | uintptr_t dpcm_selectable = (uintptr_t)of_device_get_match_data(dev); |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 356 | bool is_top = 0; |
Takashi Iwai | 0b9c9ed | 2019-02-19 16:46:49 +0100 | [diff] [blame] | 357 | int ret = 0; |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 358 | |
| 359 | /* Check if it has dai-link */ |
| 360 | node = of_get_child_by_name(top, PREFIX "dai-link"); |
| 361 | if (!node) { |
Daniel Baluta | 461d854 | 2019-02-16 10:09:42 +0000 | [diff] [blame] | 362 | node = of_node_get(top); |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 363 | is_top = 1; |
| 364 | } |
| 365 | |
| 366 | /* loop for all dai-link */ |
| 367 | do { |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 368 | struct asoc_simple_data adata; |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 369 | struct device_node *codec; |
| 370 | struct device_node *np; |
| 371 | int num = of_get_child_count(node); |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 372 | |
| 373 | /* get codec */ |
| 374 | codec = of_get_child_by_name(node, is_top ? |
| 375 | PREFIX "codec" : "codec"); |
Takashi Iwai | 0b9c9ed | 2019-02-19 16:46:49 +0100 | [diff] [blame] | 376 | if (!codec) { |
| 377 | ret = -ENODEV; |
| 378 | goto error; |
| 379 | } |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 380 | |
| 381 | of_node_put(codec); |
| 382 | |
| 383 | /* get convert-xxx property */ |
| 384 | memset(&adata, 0, sizeof(adata)); |
| 385 | for_each_child_of_node(node, np) |
Kuninori Morimoto | cdc4447 | 2019-03-18 13:50:08 +0900 | [diff] [blame] | 386 | simple_parse_convert(dev, np, &adata); |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 387 | |
| 388 | /* loop for all CPU/Codec node */ |
| 389 | for_each_child_of_node(node, np) { |
| 390 | /* |
| 391 | * It is DPCM |
| 392 | * if it has many CPUs, |
| 393 | * or has convert-xxx property |
| 394 | */ |
Kuninori Morimoto | 42bf029 | 2019-04-04 09:52:52 +0900 | [diff] [blame] | 395 | if (dpcm_selectable && |
| 396 | (num > 2 || |
| 397 | adata.convert_rate || adata.convert_channels)) |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 398 | ret = func_dpcm(priv, np, codec, li, is_top); |
| 399 | /* else normal sound */ |
| 400 | else |
| 401 | ret = func_noml(priv, np, codec, li, is_top); |
| 402 | |
Takashi Iwai | 0b9c9ed | 2019-02-19 16:46:49 +0100 | [diff] [blame] | 403 | if (ret < 0) { |
| 404 | of_node_put(np); |
| 405 | goto error; |
| 406 | } |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | node = of_get_next_child(top, node); |
| 410 | } while (!is_top && node); |
| 411 | |
Takashi Iwai | 0b9c9ed | 2019-02-19 16:46:49 +0100 | [diff] [blame] | 412 | error: |
| 413 | of_node_put(node); |
| 414 | return ret; |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 415 | } |
| 416 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 417 | static int simple_parse_aux_devs(struct device_node *node, |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 418 | struct asoc_simple_priv *priv) |
Nikita Yushchenko | 899a247 | 2016-09-26 12:56:51 +0300 | [diff] [blame] | 419 | { |
| 420 | struct device *dev = simple_priv_to_dev(priv); |
| 421 | struct device_node *aux_node; |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 422 | struct snd_soc_card *card = simple_priv_to_card(priv); |
Nikita Yushchenko | 899a247 | 2016-09-26 12:56:51 +0300 | [diff] [blame] | 423 | int i, n, len; |
| 424 | |
| 425 | if (!of_find_property(node, PREFIX "aux-devs", &len)) |
| 426 | return 0; /* Ok to have no aux-devs */ |
| 427 | |
| 428 | n = len / sizeof(__be32); |
| 429 | if (n <= 0) |
| 430 | return -EINVAL; |
| 431 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 432 | card->aux_dev = devm_kcalloc(dev, |
| 433 | n, sizeof(*card->aux_dev), GFP_KERNEL); |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 434 | if (!card->aux_dev) |
Nikita Yushchenko | 899a247 | 2016-09-26 12:56:51 +0300 | [diff] [blame] | 435 | return -ENOMEM; |
| 436 | |
| 437 | for (i = 0; i < n; i++) { |
| 438 | aux_node = of_parse_phandle(node, PREFIX "aux-devs", i); |
| 439 | if (!aux_node) |
| 440 | return -EINVAL; |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 441 | card->aux_dev[i].codec_of_node = aux_node; |
Nikita Yushchenko | 899a247 | 2016-09-26 12:56:51 +0300 | [diff] [blame] | 442 | } |
| 443 | |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 444 | card->num_aux_devs = n; |
Nikita Yushchenko | 899a247 | 2016-09-26 12:56:51 +0300 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 448 | static int simple_parse_of(struct asoc_simple_priv *priv) |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 449 | { |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 450 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 451 | struct device_node *top = dev->of_node; |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 452 | struct snd_soc_card *card = simple_priv_to_card(priv); |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 453 | struct link_info li; |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 454 | int ret; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 455 | |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 456 | if (!top) |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 457 | return -EINVAL; |
| 458 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 459 | ret = asoc_simple_parse_widgets(card, PREFIX); |
Kuninori Morimoto | fa2760dd | 2017-06-16 01:39:11 +0000 | [diff] [blame] | 460 | if (ret < 0) |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 461 | return ret; |
Xiubo Li | 9d681f5 | 2014-02-08 15:59:53 +0800 | [diff] [blame] | 462 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 463 | ret = asoc_simple_parse_routing(card, PREFIX); |
Kuninori Morimoto | 1fdb5d2 | 2017-06-15 00:25:17 +0000 | [diff] [blame] | 464 | if (ret < 0) |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 465 | return ret; |
Xiubo Li | d4c2209 | 2013-12-23 12:57:01 +0800 | [diff] [blame] | 466 | |
Paul Cercueil | 552f2d7 | 2019-04-26 04:25:50 +0200 | [diff] [blame] | 467 | ret = asoc_simple_parse_pin_switches(card, PREFIX); |
| 468 | if (ret < 0) |
| 469 | return ret; |
| 470 | |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 471 | /* Single/Muti DAI link(s) & New style of DT node */ |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 472 | memset(&li, 0, sizeof(li)); |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 473 | for (li.cpu = 1; li.cpu >= 0; li.cpu--) { |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 474 | /* |
| 475 | * Detect all CPU first, and Detect all Codec 2nd. |
| 476 | * |
| 477 | * In Normal sound case, all DAIs are detected |
| 478 | * as "CPU-Codec". |
| 479 | * |
| 480 | * In DPCM sound case, |
| 481 | * all CPUs are detected as "CPU-dummy", and |
| 482 | * all Codecs are detected as "dummy-Codec". |
| 483 | * To avoid random sub-device numbering, |
| 484 | * detect "dummy-Codec" in last; |
| 485 | */ |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 486 | ret = simple_for_each_link(priv, &li, |
| 487 | simple_dai_link_of, |
| 488 | simple_dai_link_of_dpcm); |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 489 | if (ret < 0) |
| 490 | return ret; |
| 491 | } |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 492 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 493 | ret = asoc_simple_parse_card_name(card, PREFIX); |
Nikita Yushchenko | 899a247 | 2016-09-26 12:56:51 +0300 | [diff] [blame] | 494 | if (ret < 0) |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 495 | return ret; |
Nikita Yushchenko | 899a247 | 2016-09-26 12:56:51 +0300 | [diff] [blame] | 496 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 497 | ret = simple_parse_aux_devs(top, priv); |
Kuninori Morimoto | a03b054 | 2016-08-26 03:05:16 +0000 | [diff] [blame] | 498 | |
| 499 | return ret; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 500 | } |
| 501 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 502 | static int simple_count_noml(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 503 | struct device_node *np, |
| 504 | struct device_node *codec, |
| 505 | struct link_info *li, bool is_top) |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 506 | { |
| 507 | li->dais++; /* CPU or Codec */ |
| 508 | if (np != codec) |
| 509 | li->link++; /* CPU-Codec */ |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 514 | static int simple_count_dpcm(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 515 | struct device_node *np, |
| 516 | struct device_node *codec, |
| 517 | struct link_info *li, bool is_top) |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 518 | { |
| 519 | li->dais++; /* CPU or Codec */ |
| 520 | li->link++; /* CPU-dummy or dummy-Codec */ |
| 521 | if (np == codec) |
| 522 | li->conf++; |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 527 | static void simple_get_dais_count(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 528 | struct link_info *li) |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 529 | { |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 530 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 531 | struct device_node *top = dev->of_node; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 532 | |
| 533 | /* |
| 534 | * link_num : number of links. |
| 535 | * CPU-Codec / CPU-dummy / dummy-Codec |
| 536 | * dais_num : number of DAIs |
| 537 | * ccnf_num : number of codec_conf |
| 538 | * same number for "dummy-Codec" |
| 539 | * |
| 540 | * ex1) |
| 541 | * CPU0 --- Codec0 link : 5 |
| 542 | * CPU1 --- Codec1 dais : 7 |
| 543 | * CPU2 -/ ccnf : 1 |
| 544 | * CPU3 --- Codec2 |
| 545 | * |
| 546 | * => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec |
| 547 | * => 7 DAIs = 4xCPU + 3xCodec |
| 548 | * => 1 ccnf = 1xdummy-Codec |
| 549 | * |
| 550 | * ex2) |
| 551 | * CPU0 --- Codec0 link : 5 |
| 552 | * CPU1 --- Codec1 dais : 6 |
| 553 | * CPU2 -/ ccnf : 1 |
| 554 | * CPU3 -/ |
| 555 | * |
| 556 | * => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec |
| 557 | * => 6 DAIs = 4xCPU + 2xCodec |
| 558 | * => 1 ccnf = 1xdummy-Codec |
| 559 | * |
| 560 | * ex3) |
| 561 | * CPU0 --- Codec0 link : 6 |
| 562 | * CPU1 -/ dais : 6 |
| 563 | * CPU2 --- Codec1 ccnf : 2 |
| 564 | * CPU3 -/ |
| 565 | * |
| 566 | * => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec |
| 567 | * => 6 DAIs = 4xCPU + 2xCodec |
| 568 | * => 2 ccnf = 2xdummy-Codec |
Kuninori Morimoto | 7adee60 | 2018-12-20 10:46:47 +0900 | [diff] [blame] | 569 | * |
| 570 | * ex4) |
| 571 | * CPU0 --- Codec0 (convert-rate) link : 3 |
| 572 | * CPU1 --- Codec1 dais : 4 |
| 573 | * ccnf : 1 |
| 574 | * |
| 575 | * => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec |
| 576 | * => 4 DAIs = 2xCPU + 2xCodec |
| 577 | * => 1 ccnf = 1xdummy-Codec |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 578 | */ |
| 579 | if (!top) { |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 580 | li->link = 1; |
| 581 | li->dais = 2; |
| 582 | li->conf = 0; |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 583 | return; |
| 584 | } |
| 585 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 586 | simple_for_each_link(priv, li, |
| 587 | simple_count_noml, |
| 588 | simple_count_dpcm); |
| 589 | |
Kuninori Morimoto | c39291a | 2018-12-20 10:47:28 +0900 | [diff] [blame] | 590 | dev_dbg(dev, "link %d, dais %d, ccnf %d\n", |
| 591 | li->link, li->dais, li->conf); |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 592 | } |
| 593 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 594 | static int simple_soc_probe(struct snd_soc_card *card) |
Katsuhiro Suzuki | 8d1bd11 | 2018-06-11 17:32:13 +0900 | [diff] [blame] | 595 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 596 | struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(card); |
Katsuhiro Suzuki | 8d1bd11 | 2018-06-11 17:32:13 +0900 | [diff] [blame] | 597 | int ret; |
| 598 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 599 | ret = asoc_simple_init_hp(card, &priv->hp_jack, PREFIX); |
Katsuhiro Suzuki | 8d1bd11 | 2018-06-11 17:32:13 +0900 | [diff] [blame] | 600 | if (ret < 0) |
| 601 | return ret; |
| 602 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 603 | ret = asoc_simple_init_mic(card, &priv->mic_jack, PREFIX); |
Katsuhiro Suzuki | 8d1bd11 | 2018-06-11 17:32:13 +0900 | [diff] [blame] | 604 | if (ret < 0) |
| 605 | return ret; |
| 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
Amir Goldstein | b0a821d | 2019-05-16 13:26:28 +0300 | [diff] [blame^] | 610 | static int asoc_simple_probe(struct platform_device *pdev) |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 611 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 612 | struct asoc_simple_priv *priv; |
Kuninori Morimoto | f89983e | 2012-12-25 22:52:33 -0800 | [diff] [blame] | 613 | struct device *dev = &pdev->dev; |
Kuninori Morimoto | dcee9bfe | 2017-03-15 04:43:21 +0000 | [diff] [blame] | 614 | struct device_node *np = dev->of_node; |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 615 | struct snd_soc_card *card; |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 616 | struct link_info li; |
Kuninori Morimoto | 65a5056 | 2019-03-20 13:56:26 +0900 | [diff] [blame] | 617 | int ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 618 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 619 | /* Allocate the private data and the DAI link array */ |
Kuninori Morimoto | b0133d9 | 2016-08-26 03:10:25 +0000 | [diff] [blame] | 620 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 621 | if (!priv) |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 622 | return -ENOMEM; |
| 623 | |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 624 | card = simple_priv_to_card(priv); |
| 625 | card->owner = THIS_MODULE; |
| 626 | card->dev = dev; |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 627 | card->probe = simple_soc_probe; |
Kuninori Morimoto | d947cdf | 2018-12-20 10:47:23 +0900 | [diff] [blame] | 628 | |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 629 | memset(&li, 0, sizeof(li)); |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 630 | simple_get_dais_count(priv, &li); |
Kuninori Morimoto | 17029e4 | 2018-12-20 10:46:53 +0900 | [diff] [blame] | 631 | if (!li.link || !li.dais) |
Kuninori Morimoto | da21535 | 2018-12-14 11:35:10 +0900 | [diff] [blame] | 632 | return -EINVAL; |
| 633 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 634 | ret = asoc_simple_init_priv(priv, &li); |
Kuninori Morimoto | 65a5056 | 2019-03-20 13:56:26 +0900 | [diff] [blame] | 635 | if (ret < 0) |
| 636 | return ret; |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 637 | |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 638 | if (np && of_device_is_available(np)) { |
| 639 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 640 | ret = simple_parse_of(priv); |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 641 | if (ret < 0) { |
| 642 | if (ret != -EPROBE_DEFER) |
| 643 | dev_err(dev, "parse error %d\n", ret); |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 644 | goto err; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 645 | } |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 646 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 647 | } else { |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 648 | struct asoc_simple_card_info *cinfo; |
Kuninori Morimoto | 710af91 | 2018-08-31 03:08:24 +0000 | [diff] [blame] | 649 | struct snd_soc_dai_link_component *codecs; |
Kuninori Morimoto | e58f41e | 2018-08-31 03:10:33 +0000 | [diff] [blame] | 650 | struct snd_soc_dai_link_component *platform; |
Kuninori Morimoto | 65a5056 | 2019-03-20 13:56:26 +0900 | [diff] [blame] | 651 | struct snd_soc_dai_link *dai_link = priv->dai_link; |
| 652 | struct simple_dai_props *dai_props = priv->dai_props; |
| 653 | |
Nathan Chancellor | 869858f | 2018-12-13 14:15:20 +0900 | [diff] [blame] | 654 | int dai_idx = 0; |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 655 | |
| 656 | cinfo = dev->platform_data; |
| 657 | if (!cinfo) { |
Xiubo Li | 34787d0a | 2014-01-09 17:49:40 +0800 | [diff] [blame] | 658 | dev_err(dev, "no info for asoc-simple-card\n"); |
| 659 | return -EINVAL; |
| 660 | } |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 661 | |
Nicolin Chen | 781cbeb | 2014-04-24 19:14:00 +0800 | [diff] [blame] | 662 | if (!cinfo->name || |
| 663 | !cinfo->codec_dai.name || |
| 664 | !cinfo->codec || |
| 665 | !cinfo->platform || |
Jean-Francois Moine | 7722f83 | 2014-01-15 16:51:33 +0100 | [diff] [blame] | 666 | !cinfo->cpu_dai.name) { |
| 667 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); |
| 668 | return -EINVAL; |
| 669 | } |
Jean-Francois Moine | 2bee991 | 2014-01-15 16:51:37 +0100 | [diff] [blame] | 670 | |
Nathan Chancellor | 869858f | 2018-12-13 14:15:20 +0900 | [diff] [blame] | 671 | dai_props->cpu_dai = &priv->dais[dai_idx++]; |
| 672 | dai_props->codec_dai = &priv->dais[dai_idx++]; |
| 673 | |
Kuninori Morimoto | 710af91 | 2018-08-31 03:08:24 +0000 | [diff] [blame] | 674 | codecs = dai_link->codecs; |
| 675 | codecs->name = cinfo->codec; |
| 676 | codecs->dai_name = cinfo->codec_dai.name; |
| 677 | |
Kuninori Morimoto | 910fdca | 2019-01-21 09:32:32 +0900 | [diff] [blame] | 678 | platform = dai_link->platforms; |
Kuninori Morimoto | e58f41e | 2018-08-31 03:10:33 +0000 | [diff] [blame] | 679 | platform->name = cinfo->platform; |
| 680 | |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 681 | card->name = (cinfo->card) ? cinfo->card : cinfo->name; |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 682 | dai_link->name = cinfo->name; |
| 683 | dai_link->stream_name = cinfo->name; |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 684 | dai_link->cpu_dai_name = cinfo->cpu_dai.name; |
Lars-Peter Clausen | 1efb53a | 2015-03-24 01:07:08 +0000 | [diff] [blame] | 685 | dai_link->dai_fmt = cinfo->daifmt; |
Kuninori Morimoto | ad934ca | 2019-03-20 13:55:52 +0900 | [diff] [blame] | 686 | dai_link->init = asoc_simple_dai_init; |
Kuninori Morimoto | 65a5056 | 2019-03-20 13:56:26 +0900 | [diff] [blame] | 687 | memcpy(dai_props->cpu_dai, &cinfo->cpu_dai, |
| 688 | sizeof(*dai_props->cpu_dai)); |
| 689 | memcpy(dai_props->codec_dai, &cinfo->codec_dai, |
| 690 | sizeof(*dai_props->codec_dai)); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 693 | snd_soc_card_set_drvdata(card, priv); |
Xiubo Li | ba194a4 | 2014-01-13 17:08:08 +0800 | [diff] [blame] | 694 | |
Kuninori Morimoto | 0580dde | 2019-03-20 13:54:42 +0900 | [diff] [blame] | 695 | asoc_simple_debug_info(priv); |
| 696 | |
Kuninori Morimoto | 5be5095 | 2017-03-15 04:44:00 +0000 | [diff] [blame] | 697 | ret = devm_snd_soc_register_card(dev, card); |
Kuninori Morimoto | c6d112e | 2017-05-19 00:57:21 +0000 | [diff] [blame] | 698 | if (ret < 0) |
| 699 | goto err; |
| 700 | |
| 701 | return 0; |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 702 | err: |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 703 | asoc_simple_clean_reference(card); |
Kuninori Morimoto | 387f582 | 2016-08-26 03:07:59 +0000 | [diff] [blame] | 704 | |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 705 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Amir Goldstein | b0a821d | 2019-05-16 13:26:28 +0300 | [diff] [blame^] | 708 | static int asoc_simple_remove(struct platform_device *pdev) |
Xiubo Li | e3c4a28 | 2014-09-01 14:46:52 +0800 | [diff] [blame] | 709 | { |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 710 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 711 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 712 | return asoc_simple_clean_reference(card); |
Xiubo Li | e3c4a28 | 2014-09-01 14:46:52 +0800 | [diff] [blame] | 713 | } |
| 714 | |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 715 | static const struct of_device_id simple_of_match[] = { |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 716 | { .compatible = "simple-audio-card", }, |
Kuninori Morimoto | 42bf029 | 2019-04-04 09:52:52 +0900 | [diff] [blame] | 717 | { .compatible = "simple-scu-audio-card", |
| 718 | .data = (void *)DPCM_SELECTABLE }, |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 719 | {}, |
| 720 | }; |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 721 | MODULE_DEVICE_TABLE(of, simple_of_match); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 722 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 723 | static struct platform_driver asoc_simple_card = { |
| 724 | .driver = { |
Nicolin Chen | 781cbeb | 2014-04-24 19:14:00 +0800 | [diff] [blame] | 725 | .name = "asoc-simple-card", |
Peter Ujfalusi | 7c37671 | 2016-05-09 13:38:10 +0300 | [diff] [blame] | 726 | .pm = &snd_soc_pm_ops, |
Kuninori Morimoto | 2d01a84 | 2018-12-20 10:47:34 +0900 | [diff] [blame] | 727 | .of_match_table = simple_of_match, |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 728 | }, |
Amir Goldstein | b0a821d | 2019-05-16 13:26:28 +0300 | [diff] [blame^] | 729 | .probe = asoc_simple_probe, |
| 730 | .remove = asoc_simple_remove, |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 731 | }; |
| 732 | |
| 733 | module_platform_driver(asoc_simple_card); |
| 734 | |
Fabio Estevam | c445be3 | 2013-08-23 14:35:17 -0300 | [diff] [blame] | 735 | MODULE_ALIAS("platform:asoc-simple-card"); |
Kuninori Morimoto | a1dbfd0 | 2016-08-26 03:07:28 +0000 | [diff] [blame] | 736 | MODULE_LICENSE("GPL v2"); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 737 | MODULE_DESCRIPTION("ASoC Simple Sound Card"); |
| 738 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |