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