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