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