Kuninori Morimoto | decd896 | 2018-07-02 06:31:16 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // ASoC audio graph sound card support |
| 4 | // |
| 5 | // Copyright (C) 2016 Renesas Solutions Corp. |
| 6 | // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 7 | // |
| 8 | // based on ${LINUX}/sound/soc/generic/simple-card.c |
| 9 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 10 | #include <linux/clk.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/gpio.h> |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 13 | #include <linux/gpio/consumer.h> |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/of.h> |
| 16 | #include <linux/of_device.h> |
| 17 | #include <linux/of_gpio.h> |
| 18 | #include <linux/of_graph.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/string.h> |
Sameer Pujar | e32b100 | 2020-11-02 20:40:14 +0530 | [diff] [blame] | 21 | #include <sound/graph_card.h> |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 22 | |
Kuninori Morimoto | c2c6160 | 2019-04-04 09:52:15 +0900 | [diff] [blame] | 23 | #define DPCM_SELECTABLE 1 |
| 24 | |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 25 | static int graph_outdrv_event(struct snd_soc_dapm_widget *w, |
| 26 | struct snd_kcontrol *kcontrol, |
| 27 | int event) |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 28 | { |
| 29 | struct snd_soc_dapm_context *dapm = w->dapm; |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 30 | struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(dapm->card); |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 31 | |
| 32 | switch (event) { |
| 33 | case SND_SOC_DAPM_POST_PMU: |
| 34 | gpiod_set_value_cansleep(priv->pa_gpio, 1); |
| 35 | break; |
| 36 | case SND_SOC_DAPM_PRE_PMD: |
| 37 | gpiod_set_value_cansleep(priv->pa_gpio, 0); |
| 38 | break; |
| 39 | default: |
| 40 | return -EINVAL; |
| 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 46 | static const struct snd_soc_dapm_widget graph_dapm_widgets[] = { |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 47 | SND_SOC_DAPM_OUT_DRV_E("Amplifier", SND_SOC_NOPM, |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 48 | 0, 0, NULL, 0, graph_outdrv_event, |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 49 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 52 | static const struct snd_soc_ops graph_ops = { |
Kuninori Morimoto | f38df5b | 2019-03-20 13:55:14 +0900 | [diff] [blame] | 53 | .startup = asoc_simple_startup, |
Kuninori Morimoto | 686911b | 2019-03-20 13:55:27 +0900 | [diff] [blame] | 54 | .shutdown = asoc_simple_shutdown, |
Kuninori Morimoto | f48dcbb | 2019-03-20 13:55:39 +0900 | [diff] [blame] | 55 | .hw_params = asoc_simple_hw_params, |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 58 | static int graph_get_dai_id(struct device_node *ep) |
| 59 | { |
| 60 | struct device_node *node; |
| 61 | struct device_node *endpoint; |
| 62 | struct of_endpoint info; |
| 63 | int i, id; |
Kuninori Morimoto | ec3042a | 2019-07-11 13:10:45 +0900 | [diff] [blame] | 64 | const u32 *reg; |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 65 | int ret; |
| 66 | |
| 67 | /* use driver specified DAI ID if exist */ |
| 68 | ret = snd_soc_get_dai_id(ep); |
| 69 | if (ret != -ENOTSUPP) |
| 70 | return ret; |
| 71 | |
| 72 | /* use endpoint/port reg if exist */ |
| 73 | ret = of_graph_parse_endpoint(ep, &info); |
| 74 | if (ret == 0) { |
| 75 | /* |
| 76 | * Because it will count port/endpoint if it doesn't have "reg". |
| 77 | * But, we can't judge whether it has "no reg", or "reg = <0>" |
| 78 | * only of_graph_parse_endpoint(). |
| 79 | * We need to check "reg" property |
| 80 | */ |
| 81 | if (of_get_property(ep, "reg", NULL)) |
| 82 | return info.id; |
| 83 | |
| 84 | node = of_get_parent(ep); |
Wen Yang | c152f84 | 2019-07-10 15:25:09 +0800 | [diff] [blame] | 85 | reg = of_get_property(node, "reg", NULL); |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 86 | of_node_put(node); |
Wen Yang | c152f84 | 2019-07-10 15:25:09 +0800 | [diff] [blame] | 87 | if (reg) |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 88 | return info.port; |
| 89 | } |
| 90 | node = of_graph_get_port_parent(ep); |
| 91 | |
| 92 | /* |
| 93 | * Non HDMI sound case, counting port/endpoint on its DT |
| 94 | * is enough. Let's count it. |
| 95 | */ |
| 96 | i = 0; |
| 97 | id = -1; |
| 98 | for_each_endpoint_of_node(node, endpoint) { |
| 99 | if (endpoint == ep) |
| 100 | id = i; |
| 101 | i++; |
| 102 | } |
| 103 | |
| 104 | of_node_put(node); |
| 105 | |
| 106 | if (id < 0) |
| 107 | return -ENODEV; |
| 108 | |
| 109 | return id; |
| 110 | } |
| 111 | |
Sameer Pujar | c21cbb52 | 2020-11-02 20:40:11 +0530 | [diff] [blame] | 112 | static bool soc_component_is_pcm(struct snd_soc_dai_link_component *dlc) |
| 113 | { |
| 114 | struct snd_soc_dai *dai = snd_soc_find_dai_with_mutex(dlc); |
| 115 | |
| 116 | if (dai && (dai->component->driver->pcm_construct || |
| 117 | dai->driver->pcm_new)) |
| 118 | return true; |
| 119 | |
| 120 | return false; |
| 121 | } |
| 122 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 123 | static int asoc_simple_parse_dai(struct device_node *ep, |
| 124 | struct snd_soc_dai_link_component *dlc, |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 125 | int *is_single_link) |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 126 | { |
| 127 | struct device_node *node; |
| 128 | struct of_phandle_args args; |
| 129 | int ret; |
| 130 | |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 131 | if (!ep) |
| 132 | return 0; |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 133 | |
| 134 | node = of_graph_get_port_parent(ep); |
| 135 | |
| 136 | /* Get dai->name */ |
| 137 | args.np = node; |
| 138 | args.args[0] = graph_get_dai_id(ep); |
| 139 | args.args_count = (of_graph_get_endpoint_count(node) > 1); |
| 140 | |
Kuninori Morimoto | 157ab71 | 2019-09-03 17:16:05 +0900 | [diff] [blame] | 141 | /* |
| 142 | * FIXME |
| 143 | * |
| 144 | * Here, dlc->dai_name is pointer to CPU/Codec DAI name. |
| 145 | * If user unbinded CPU or Codec driver, but not for Sound Card, |
| 146 | * dlc->dai_name is keeping unbinded CPU or Codec |
| 147 | * driver's pointer. |
| 148 | * |
| 149 | * If user re-bind CPU or Codec driver again, ALSA SoC will try |
| 150 | * to rebind Card via snd_soc_try_rebind_card(), but because of |
| 151 | * above reason, it might can't bind Sound Card. |
| 152 | * Because Sound Card is pointing to released dai_name pointer. |
| 153 | * |
| 154 | * To avoid this rebind Card issue, |
| 155 | * 1) It needs to alloc memory to keep dai_name eventhough |
| 156 | * CPU or Codec driver was unbinded, or |
| 157 | * 2) user need to rebind Sound Card everytime |
| 158 | * if he unbinded CPU or Codec. |
| 159 | */ |
Kuninori Morimoto | f107294 | 2019-06-06 13:07:35 +0900 | [diff] [blame] | 160 | ret = snd_soc_get_dai_name(&args, &dlc->dai_name); |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 161 | if (ret < 0) |
| 162 | return ret; |
| 163 | |
Kuninori Morimoto | f107294 | 2019-06-06 13:07:35 +0900 | [diff] [blame] | 164 | dlc->of_node = node; |
Kuninori Morimoto | 8f7f298 | 2019-03-20 13:56:36 +0900 | [diff] [blame] | 165 | |
| 166 | if (is_single_link) |
| 167 | *is_single_link = of_graph_get_endpoint_count(node) == 1; |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Kuninori Morimoto | d2bf008 | 2019-03-18 13:50:25 +0900 | [diff] [blame] | 172 | static void graph_parse_convert(struct device *dev, |
| 173 | struct device_node *ep, |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 174 | struct asoc_simple_data *adata) |
Kuninori Morimoto | 40dfae1 | 2018-12-20 10:45:48 +0900 | [diff] [blame] | 175 | { |
| 176 | struct device_node *top = dev->of_node; |
| 177 | struct device_node *port = of_get_parent(ep); |
| 178 | struct device_node *ports = of_get_parent(port); |
| 179 | struct device_node *node = of_graph_get_port_parent(ep); |
| 180 | |
Kuninori Morimoto | fcfd763 | 2021-04-12 08:53:00 +0900 | [diff] [blame] | 181 | asoc_simple_parse_convert(top, NULL, adata); |
Kuninori Morimoto | 6769ea1 | 2021-04-19 11:02:29 +0900 | [diff] [blame] | 182 | if (of_node_name_eq(ports, "ports")) |
| 183 | asoc_simple_parse_convert(ports, NULL, adata); |
Kuninori Morimoto | fcfd763 | 2021-04-12 08:53:00 +0900 | [diff] [blame] | 184 | asoc_simple_parse_convert(port, NULL, adata); |
| 185 | asoc_simple_parse_convert(ep, NULL, adata); |
Kuninori Morimoto | d2bf008 | 2019-03-18 13:50:25 +0900 | [diff] [blame] | 186 | |
| 187 | of_node_put(port); |
| 188 | of_node_put(ports); |
| 189 | of_node_put(node); |
Kuninori Morimoto | 40dfae1 | 2018-12-20 10:45:48 +0900 | [diff] [blame] | 190 | } |
| 191 | |
Kuninori Morimoto | 4346a74 | 2019-03-18 13:50:31 +0900 | [diff] [blame] | 192 | static void graph_parse_mclk_fs(struct device_node *top, |
| 193 | struct device_node *ep, |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 194 | struct simple_dai_props *props) |
Kuninori Morimoto | 4346a74 | 2019-03-18 13:50:31 +0900 | [diff] [blame] | 195 | { |
| 196 | struct device_node *port = of_get_parent(ep); |
| 197 | struct device_node *ports = of_get_parent(port); |
Kuninori Morimoto | 4346a74 | 2019-03-18 13:50:31 +0900 | [diff] [blame] | 198 | |
| 199 | of_property_read_u32(top, "mclk-fs", &props->mclk_fs); |
Kuninori Morimoto | 6769ea1 | 2021-04-19 11:02:29 +0900 | [diff] [blame] | 200 | if (of_node_name_eq(ports, "ports")) |
| 201 | of_property_read_u32(ports, "mclk-fs", &props->mclk_fs); |
Kuninori Morimoto | 4346a74 | 2019-03-18 13:50:31 +0900 | [diff] [blame] | 202 | of_property_read_u32(port, "mclk-fs", &props->mclk_fs); |
| 203 | of_property_read_u32(ep, "mclk-fs", &props->mclk_fs); |
| 204 | |
| 205 | of_node_put(port); |
| 206 | of_node_put(ports); |
Kuninori Morimoto | 4346a74 | 2019-03-18 13:50:31 +0900 | [diff] [blame] | 207 | } |
| 208 | |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 209 | static int graph_parse_node(struct asoc_simple_priv *priv, |
| 210 | struct device_node *ep, |
| 211 | struct link_info *li, |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 212 | int *cpu) |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 213 | { |
| 214 | struct device *dev = simple_priv_to_dev(priv); |
| 215 | struct device_node *top = dev->of_node; |
| 216 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 217 | struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link); |
| 218 | struct snd_soc_dai_link_component *dlc; |
| 219 | struct asoc_simple_dai *dai; |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 220 | int ret; |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 221 | |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 222 | if (cpu) { |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 223 | dlc = asoc_link_to_cpu(dai_link, 0); |
| 224 | dai = simple_props_to_dai_cpu(dai_props, 0); |
| 225 | } else { |
| 226 | dlc = asoc_link_to_codec(dai_link, 0); |
| 227 | dai = simple_props_to_dai_codec(dai_props, 0); |
| 228 | } |
| 229 | |
| 230 | graph_parse_mclk_fs(top, ep, dai_props); |
| 231 | |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 232 | ret = asoc_simple_parse_dai(ep, dlc, cpu); |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 233 | if (ret < 0) |
| 234 | return ret; |
| 235 | |
| 236 | ret = asoc_simple_parse_tdm(ep, dai); |
| 237 | if (ret < 0) |
| 238 | return ret; |
| 239 | |
| 240 | ret = asoc_simple_parse_clk(dev, ep, dai, dlc); |
| 241 | if (ret < 0) |
| 242 | return ret; |
| 243 | |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 244 | return 0; |
| 245 | } |
| 246 | |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 247 | static int graph_link_init(struct asoc_simple_priv *priv, |
| 248 | struct device_node *cpu_ep, |
| 249 | struct device_node *codec_ep, |
| 250 | struct link_info *li, |
| 251 | char *name) |
| 252 | { |
| 253 | struct device *dev = simple_priv_to_dev(priv); |
| 254 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 255 | int ret; |
| 256 | |
| 257 | ret = asoc_simple_parse_daifmt(dev, cpu_ep, codec_ep, |
| 258 | NULL, &dai_link->dai_fmt); |
| 259 | if (ret < 0) |
| 260 | return ret; |
| 261 | |
| 262 | dai_link->init = asoc_simple_dai_init; |
| 263 | dai_link->ops = &graph_ops; |
| 264 | if (priv->ops) |
| 265 | dai_link->ops = priv->ops; |
| 266 | |
| 267 | return asoc_simple_set_dailink_name(dev, dai_link, name); |
| 268 | } |
| 269 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 270 | static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 271 | struct device_node *cpu_ep, |
| 272 | struct device_node *codec_ep, |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 273 | struct link_info *li) |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 274 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 275 | struct device *dev = simple_priv_to_dev(priv); |
| 276 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 277 | struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link); |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 278 | struct device_node *top = dev->of_node; |
Kuninori Morimoto | 1e4771a | 2018-12-20 10:45:59 +0900 | [diff] [blame] | 279 | struct device_node *ep = li->cpu ? cpu_ep : codec_ep; |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 280 | char dai_name[64]; |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 281 | int ret; |
| 282 | |
Kuninori Morimoto | 1e4771a | 2018-12-20 10:45:59 +0900 | [diff] [blame] | 283 | dev_dbg(dev, "link_of DPCM (%pOF)\n", ep); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 284 | |
Kuninori Morimoto | 1e4771a | 2018-12-20 10:45:59 +0900 | [diff] [blame] | 285 | if (li->cpu) { |
Kuninori Morimoto | f8090ff | 2021-05-11 10:17:57 +0900 | [diff] [blame] | 286 | struct snd_soc_card *card = simple_priv_to_card(priv); |
| 287 | struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0); |
Kuninori Morimoto | 5f939f4 | 2021-08-30 09:44:44 +0900 | [diff] [blame] | 288 | struct snd_soc_dai_link_component *platforms = asoc_link_to_platform(dai_link, 0); |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 289 | int is_single_links = 0; |
Kuninori Morimoto | f8090ff | 2021-05-11 10:17:57 +0900 | [diff] [blame] | 290 | |
Kuninori Morimoto | 9764bee | 2019-10-15 11:52:52 +0900 | [diff] [blame] | 291 | /* Codec is dummy */ |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 292 | |
| 293 | /* FE settings */ |
| 294 | dai_link->dynamic = 1; |
| 295 | dai_link->dpcm_merged_format = 1; |
| 296 | |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 297 | ret = graph_parse_node(priv, cpu_ep, li, &is_single_links); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 298 | if (ret) |
Kuninori Morimoto | f8090ff | 2021-05-11 10:17:57 +0900 | [diff] [blame] | 299 | return ret; |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 300 | |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 301 | snprintf(dai_name, sizeof(dai_name), |
| 302 | "fe.%pOFP.%s", cpus->of_node, cpus->dai_name); |
Sameer Pujar | c21cbb52 | 2020-11-02 20:40:11 +0530 | [diff] [blame] | 303 | /* |
| 304 | * In BE<->BE connections it is not required to create |
| 305 | * PCM devices at CPU end of the dai link and thus 'no_pcm' |
| 306 | * flag needs to be set. It is useful when there are many |
| 307 | * BE components and some of these have to be connected to |
| 308 | * form a valid audio path. |
| 309 | * |
| 310 | * For example: FE <-> BE1 <-> BE2 <-> ... <-> BEn where |
| 311 | * there are 'n' BE components in the path. |
| 312 | */ |
Sameer Pujar | 30b428d | 2021-09-13 22:12:11 +0530 | [diff] [blame] | 313 | if (card->component_chaining && !soc_component_is_pcm(cpus)) { |
Sameer Pujar | c21cbb52 | 2020-11-02 20:40:11 +0530 | [diff] [blame] | 314 | dai_link->no_pcm = 1; |
Sameer Pujar | 30b428d | 2021-09-13 22:12:11 +0530 | [diff] [blame] | 315 | dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup; |
| 316 | } |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 317 | |
| 318 | asoc_simple_canonicalize_cpu(cpus, is_single_links); |
Kuninori Morimoto | 5f939f4 | 2021-08-30 09:44:44 +0900 | [diff] [blame] | 319 | asoc_simple_canonicalize_platform(platforms, cpus); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 320 | } else { |
Kuninori Morimoto | f8090ff | 2021-05-11 10:17:57 +0900 | [diff] [blame] | 321 | struct snd_soc_codec_conf *cconf = simple_props_to_codec_conf(dai_props, 0); |
| 322 | struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0); |
| 323 | struct device_node *port; |
| 324 | struct device_node *ports; |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 325 | |
Kuninori Morimoto | 9764bee | 2019-10-15 11:52:52 +0900 | [diff] [blame] | 326 | /* CPU is dummy */ |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 327 | |
| 328 | /* BE settings */ |
| 329 | dai_link->no_pcm = 1; |
Kuninori Morimoto | 629f754 | 2019-03-20 13:56:06 +0900 | [diff] [blame] | 330 | dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup; |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 331 | |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 332 | ret = graph_parse_node(priv, codec_ep, li, NULL); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 333 | if (ret < 0) |
Kuninori Morimoto | f8090ff | 2021-05-11 10:17:57 +0900 | [diff] [blame] | 334 | return ret; |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 335 | |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 336 | snprintf(dai_name, sizeof(dai_name), |
| 337 | "be.%pOFP.%s", codecs->of_node, codecs->dai_name); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 338 | |
| 339 | /* check "prefix" from top node */ |
Kuninori Morimoto | f8090ff | 2021-05-11 10:17:57 +0900 | [diff] [blame] | 340 | port = of_get_parent(ep); |
| 341 | ports = of_get_parent(port); |
Kuninori Morimoto | 66164a4 | 2018-12-14 11:32:43 +0900 | [diff] [blame] | 342 | snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node, |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 343 | "prefix"); |
Kuninori Morimoto | 6769ea1 | 2021-04-19 11:02:29 +0900 | [diff] [blame] | 344 | if (of_node_name_eq(ports, "ports")) |
| 345 | snd_soc_of_parse_node_prefix(ports, cconf, codecs->of_node, "prefix"); |
Kuninori Morimoto | 66164a4 | 2018-12-14 11:32:43 +0900 | [diff] [blame] | 346 | snd_soc_of_parse_node_prefix(port, cconf, codecs->of_node, |
| 347 | "prefix"); |
Kuninori Morimoto | f8090ff | 2021-05-11 10:17:57 +0900 | [diff] [blame] | 348 | |
| 349 | of_node_put(ports); |
| 350 | of_node_put(port); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 351 | } |
| 352 | |
Kuninori Morimoto | 4346a74 | 2019-03-18 13:50:31 +0900 | [diff] [blame] | 353 | graph_parse_convert(dev, ep, &dai_props->adata); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 354 | |
Pierre-Louis Bossart | 2561247 | 2020-07-07 16:04:37 -0500 | [diff] [blame] | 355 | snd_soc_dai_link_set_capabilities(dai_link); |
| 356 | |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 357 | ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name); |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 358 | |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 359 | li->link++; |
| 360 | |
Wen Yang | aa2e362 | 2019-07-10 15:25:08 +0800 | [diff] [blame] | 361 | return ret; |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 362 | } |
| 363 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 364 | static int graph_dai_link_of(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 365 | struct device_node *cpu_ep, |
| 366 | struct device_node *codec_ep, |
| 367 | struct link_info *li) |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 368 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 369 | struct device *dev = simple_priv_to_dev(priv); |
| 370 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
Kuninori Morimoto | 7ed5920 | 2021-04-14 08:20:15 +0900 | [diff] [blame] | 371 | struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0); |
| 372 | struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0); |
Kuninori Morimoto | 5f939f4 | 2021-08-30 09:44:44 +0900 | [diff] [blame] | 373 | struct snd_soc_dai_link_component *platforms = asoc_link_to_platform(dai_link, 0); |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 374 | char dai_name[64]; |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 375 | int ret, is_single_links = 0; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 376 | |
Kuninori Morimoto | 1e4771a | 2018-12-20 10:45:59 +0900 | [diff] [blame] | 377 | dev_dbg(dev, "link_of (%pOF)\n", cpu_ep); |
| 378 | |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 379 | ret = graph_parse_node(priv, cpu_ep, li, &is_single_links); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 380 | if (ret < 0) |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 381 | return ret; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 382 | |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 383 | ret = graph_parse_node(priv, codec_ep, li, NULL); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 384 | if (ret < 0) |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 385 | return ret; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 386 | |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 387 | snprintf(dai_name, sizeof(dai_name), |
| 388 | "%s-%s", cpus->dai_name, codecs->dai_name); |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 389 | |
| 390 | asoc_simple_canonicalize_cpu(cpus, is_single_links); |
Kuninori Morimoto | 5f939f4 | 2021-08-30 09:44:44 +0900 | [diff] [blame] | 391 | asoc_simple_canonicalize_platform(platforms, cpus); |
Kuninori Morimoto | 582f350 | 2021-05-11 10:18:48 +0900 | [diff] [blame] | 392 | |
Kuninori Morimoto | e51237b | 2021-04-21 14:45:43 +0900 | [diff] [blame] | 393 | ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 394 | if (ret < 0) |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 395 | return ret; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 396 | |
Kuninori Morimoto | 8859f80 | 2021-04-21 14:45:21 +0900 | [diff] [blame] | 397 | li->link++; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 398 | |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 399 | return 0; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Sameer Pujar | d09c774 | 2020-11-02 20:40:13 +0530 | [diff] [blame] | 402 | static inline bool parse_as_dpcm_link(struct asoc_simple_priv *priv, |
| 403 | struct device_node *codec_port, |
| 404 | struct asoc_simple_data *adata) |
| 405 | { |
| 406 | if (priv->force_dpcm) |
| 407 | return true; |
| 408 | |
| 409 | if (!priv->dpcm_selectable) |
| 410 | return false; |
| 411 | |
| 412 | /* |
| 413 | * It is DPCM |
| 414 | * if Codec port has many endpoints, |
| 415 | * or has convert-xxx property |
| 416 | */ |
| 417 | if ((of_get_child_count(codec_port) > 1) || |
| 418 | (adata->convert_rate || adata->convert_channels)) |
| 419 | return true; |
| 420 | |
| 421 | return false; |
| 422 | } |
| 423 | |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 424 | static int __graph_for_each_link(struct asoc_simple_priv *priv, |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 425 | struct link_info *li, |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 426 | int (*func_noml)(struct asoc_simple_priv *priv, |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 427 | struct device_node *cpu_ep, |
| 428 | struct device_node *codec_ep, |
| 429 | struct link_info *li), |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 430 | int (*func_dpcm)(struct asoc_simple_priv *priv, |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 431 | struct device_node *cpu_ep, |
| 432 | struct device_node *codec_ep, |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 433 | struct link_info *li)) |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 434 | { |
| 435 | struct of_phandle_iterator it; |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 436 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 437 | struct device_node *node = dev->of_node; |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 438 | struct device_node *cpu_port; |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 439 | struct device_node *cpu_ep; |
| 440 | struct device_node *codec_ep; |
| 441 | struct device_node *codec_port; |
| 442 | struct device_node *codec_port_old = NULL; |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 443 | struct asoc_simple_data adata; |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 444 | int rc, ret = 0; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 445 | |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 446 | /* loop for all listed CPU port */ |
| 447 | of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { |
| 448 | cpu_port = it.node; |
| 449 | cpu_ep = NULL; |
| 450 | |
| 451 | /* loop for all CPU endpoint */ |
| 452 | while (1) { |
| 453 | cpu_ep = of_get_next_child(cpu_port, cpu_ep); |
| 454 | if (!cpu_ep) |
| 455 | break; |
| 456 | |
| 457 | /* get codec */ |
| 458 | codec_ep = of_graph_get_remote_endpoint(cpu_ep); |
| 459 | codec_port = of_get_parent(codec_ep); |
| 460 | |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 461 | /* get convert-xxx property */ |
| 462 | memset(&adata, 0, sizeof(adata)); |
Kuninori Morimoto | d2bf008 | 2019-03-18 13:50:25 +0900 | [diff] [blame] | 463 | graph_parse_convert(dev, codec_ep, &adata); |
| 464 | graph_parse_convert(dev, cpu_ep, &adata); |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 465 | |
Sameer Pujar | d09c774 | 2020-11-02 20:40:13 +0530 | [diff] [blame] | 466 | /* check if link requires DPCM parsing */ |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 467 | if (parse_as_dpcm_link(priv, codec_port, &adata)) { |
| 468 | /* |
| 469 | * Codec endpoint can be NULL for pluggable audio HW. |
| 470 | * Platform DT can populate the Codec endpoint depending on the |
| 471 | * plugged HW. |
| 472 | */ |
| 473 | /* Do it all CPU endpoint, and 1st Codec endpoint */ |
| 474 | if (li->cpu || |
| 475 | ((codec_port_old != codec_port) && codec_ep)) |
| 476 | ret = func_dpcm(priv, cpu_ep, codec_ep, li); |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 477 | /* else normal sound */ |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 478 | } else { |
| 479 | if (li->cpu) |
| 480 | ret = func_noml(priv, cpu_ep, codec_ep, li); |
| 481 | } |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 482 | |
Wen Yang | 1bcc1fd | 2019-07-04 16:38:50 +0800 | [diff] [blame] | 483 | of_node_put(codec_ep); |
| 484 | of_node_put(codec_port); |
| 485 | |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 486 | if (ret < 0) |
| 487 | return ret; |
| 488 | |
| 489 | codec_port_old = codec_port; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 496 | static int graph_for_each_link(struct asoc_simple_priv *priv, |
| 497 | struct link_info *li, |
| 498 | int (*func_noml)(struct asoc_simple_priv *priv, |
| 499 | struct device_node *cpu_ep, |
| 500 | struct device_node *codec_ep, |
| 501 | struct link_info *li), |
| 502 | int (*func_dpcm)(struct asoc_simple_priv *priv, |
| 503 | struct device_node *cpu_ep, |
| 504 | struct device_node *codec_ep, |
| 505 | struct link_info *li)) |
| 506 | { |
| 507 | int ret; |
| 508 | /* |
| 509 | * Detect all CPU first, and Detect all Codec 2nd. |
| 510 | * |
| 511 | * In Normal sound case, all DAIs are detected |
| 512 | * as "CPU-Codec". |
| 513 | * |
| 514 | * In DPCM sound case, |
| 515 | * all CPUs are detected as "CPU-dummy", and |
| 516 | * all Codecs are detected as "dummy-Codec". |
| 517 | * To avoid random sub-device numbering, |
| 518 | * detect "dummy-Codec" in last; |
| 519 | */ |
| 520 | for (li->cpu = 1; li->cpu >= 0; li->cpu--) { |
| 521 | ret = __graph_for_each_link(priv, li, func_noml, func_dpcm); |
| 522 | if (ret < 0) |
| 523 | break; |
| 524 | } |
| 525 | |
| 526 | return ret; |
| 527 | } |
| 528 | |
Thierry Reding | 0f687d8 | 2021-04-16 09:11:46 +0200 | [diff] [blame] | 529 | static int graph_get_dais_count(struct asoc_simple_priv *priv, |
| 530 | struct link_info *li); |
Sameer Pujar | e32b100 | 2020-11-02 20:40:14 +0530 | [diff] [blame] | 531 | |
Sameer Pujar | 6e4ea8a | 2021-02-07 23:06:57 +0530 | [diff] [blame] | 532 | int audio_graph_parse_of(struct asoc_simple_priv *priv, struct device *dev) |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 533 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 534 | struct snd_soc_card *card = simple_priv_to_card(priv); |
Thierry Reding | ec1af6c | 2021-04-19 18:41:17 +0200 | [diff] [blame] | 535 | struct link_info *li; |
Kuninori Morimoto | fce9b90 | 2018-12-20 10:46:20 +0900 | [diff] [blame] | 536 | int ret; |
| 537 | |
Thierry Reding | ec1af6c | 2021-04-19 18:41:17 +0200 | [diff] [blame] | 538 | li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL); |
| 539 | if (!li) |
| 540 | return -ENOMEM; |
| 541 | |
Sameer Pujar | e32b100 | 2020-11-02 20:40:14 +0530 | [diff] [blame] | 542 | card->owner = THIS_MODULE; |
| 543 | card->dev = dev; |
| 544 | |
Thierry Reding | ec1af6c | 2021-04-19 18:41:17 +0200 | [diff] [blame] | 545 | ret = graph_get_dais_count(priv, li); |
Thierry Reding | 0f687d8 | 2021-04-16 09:11:46 +0200 | [diff] [blame] | 546 | if (ret < 0) |
| 547 | return ret; |
| 548 | |
Thierry Reding | ec1af6c | 2021-04-19 18:41:17 +0200 | [diff] [blame] | 549 | if (!li->link) |
Sameer Pujar | e32b100 | 2020-11-02 20:40:14 +0530 | [diff] [blame] | 550 | return -EINVAL; |
| 551 | |
Thierry Reding | ec1af6c | 2021-04-19 18:41:17 +0200 | [diff] [blame] | 552 | ret = asoc_simple_init_priv(priv, li); |
Sameer Pujar | e32b100 | 2020-11-02 20:40:14 +0530 | [diff] [blame] | 553 | if (ret < 0) |
| 554 | return ret; |
| 555 | |
| 556 | priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW); |
| 557 | if (IS_ERR(priv->pa_gpio)) { |
| 558 | ret = PTR_ERR(priv->pa_gpio); |
| 559 | dev_err(dev, "failed to get amplifier gpio: %d\n", ret); |
| 560 | return ret; |
| 561 | } |
| 562 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 563 | ret = asoc_simple_parse_widgets(card, NULL); |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 564 | if (ret < 0) |
| 565 | return ret; |
| 566 | |
Kuninori Morimoto | ad11e59 | 2019-03-20 13:56:50 +0900 | [diff] [blame] | 567 | ret = asoc_simple_parse_routing(card, NULL); |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 568 | if (ret < 0) |
| 569 | return ret; |
| 570 | |
Thierry Reding | ec1af6c | 2021-04-19 18:41:17 +0200 | [diff] [blame] | 571 | memset(li, 0, sizeof(*li)); |
| 572 | ret = graph_for_each_link(priv, li, |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 573 | graph_dai_link_of, |
| 574 | graph_dai_link_of_dpcm); |
| 575 | if (ret < 0) |
| 576 | goto err; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 577 | |
Sameer Pujar | e32b100 | 2020-11-02 20:40:14 +0530 | [diff] [blame] | 578 | ret = asoc_simple_parse_card_name(card, NULL); |
| 579 | if (ret < 0) |
| 580 | goto err; |
| 581 | |
| 582 | snd_soc_card_set_drvdata(card, priv); |
| 583 | |
| 584 | asoc_simple_debug_info(priv); |
| 585 | |
| 586 | ret = devm_snd_soc_register_card(dev, card); |
| 587 | if (ret < 0) |
| 588 | goto err; |
| 589 | |
Thierry Reding | ec1af6c | 2021-04-19 18:41:17 +0200 | [diff] [blame] | 590 | devm_kfree(dev, li); |
Sameer Pujar | e32b100 | 2020-11-02 20:40:14 +0530 | [diff] [blame] | 591 | return 0; |
| 592 | |
| 593 | err: |
| 594 | asoc_simple_clean_reference(card); |
| 595 | |
Kuninori Morimoto | 7a0299e | 2021-12-14 11:08:35 +0900 | [diff] [blame] | 596 | return dev_err_probe(dev, ret, "parse error\n"); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 597 | } |
Sameer Pujar | 6e4ea8a | 2021-02-07 23:06:57 +0530 | [diff] [blame] | 598 | EXPORT_SYMBOL_GPL(audio_graph_parse_of); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 599 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 600 | static int graph_count_noml(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 601 | struct device_node *cpu_ep, |
| 602 | struct device_node *codec_ep, |
| 603 | struct link_info *li) |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 604 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 605 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 606 | |
Thierry Reding | 343e55e | 2021-04-16 09:11:47 +0200 | [diff] [blame] | 607 | if (li->link >= SNDRV_MAX_LINKS) { |
Kuninori Morimoto | f2138aed | 2021-04-01 13:15:23 +0900 | [diff] [blame] | 608 | dev_err(dev, "too many links\n"); |
| 609 | return -EINVAL; |
| 610 | } |
| 611 | |
| 612 | li->num[li->link].cpus = 1; |
| 613 | li->num[li->link].codecs = 1; |
Kuninori Morimoto | 5f939f4 | 2021-08-30 09:44:44 +0900 | [diff] [blame] | 614 | li->num[li->link].platforms = 1; |
Kuninori Morimoto | f2138aed | 2021-04-01 13:15:23 +0900 | [diff] [blame] | 615 | |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 616 | li->link += 1; /* 1xCPU-Codec */ |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 617 | |
| 618 | dev_dbg(dev, "Count As Normal\n"); |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 623 | static int graph_count_dpcm(struct asoc_simple_priv *priv, |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 624 | struct device_node *cpu_ep, |
| 625 | struct device_node *codec_ep, |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 626 | struct link_info *li) |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 627 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 628 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 629 | |
Thierry Reding | 343e55e | 2021-04-16 09:11:47 +0200 | [diff] [blame] | 630 | if (li->link >= SNDRV_MAX_LINKS) { |
Kuninori Morimoto | f2138aed | 2021-04-01 13:15:23 +0900 | [diff] [blame] | 631 | dev_err(dev, "too many links\n"); |
| 632 | return -EINVAL; |
| 633 | } |
| 634 | |
Kuninori Morimoto | 674b943 | 2021-03-26 12:26:11 +0900 | [diff] [blame] | 635 | if (li->cpu) { |
Kuninori Morimoto | f2138aed | 2021-04-01 13:15:23 +0900 | [diff] [blame] | 636 | li->num[li->link].cpus = 1; |
Kuninori Morimoto | 5f939f4 | 2021-08-30 09:44:44 +0900 | [diff] [blame] | 637 | li->num[li->link].platforms = 1; |
Kuninori Morimoto | f2138aed | 2021-04-01 13:15:23 +0900 | [diff] [blame] | 638 | |
Kuninori Morimoto | 674b943 | 2021-03-26 12:26:11 +0900 | [diff] [blame] | 639 | li->link++; /* 1xCPU-dummy */ |
Kuninori Morimoto | e9cbcf2 | 2021-03-26 12:26:20 +0900 | [diff] [blame] | 640 | } else { |
Kuninori Morimoto | f2138aed | 2021-04-01 13:15:23 +0900 | [diff] [blame] | 641 | li->num[li->link].codecs = 1; |
Kuninori Morimoto | f2138aed | 2021-04-01 13:15:23 +0900 | [diff] [blame] | 642 | |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 643 | li->link++; /* 1xdummy-Codec */ |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | dev_dbg(dev, "Count As DPCM\n"); |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
Thierry Reding | 0f687d8 | 2021-04-16 09:11:46 +0200 | [diff] [blame] | 651 | static int graph_get_dais_count(struct asoc_simple_priv *priv, |
| 652 | struct link_info *li) |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 653 | { |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 654 | /* |
| 655 | * link_num : number of links. |
| 656 | * CPU-Codec / CPU-dummy / dummy-Codec |
| 657 | * dais_num : number of DAIs |
| 658 | * ccnf_num : number of codec_conf |
| 659 | * same number for "dummy-Codec" |
| 660 | * |
| 661 | * ex1) |
| 662 | * CPU0 --- Codec0 link : 5 |
| 663 | * CPU1 --- Codec1 dais : 7 |
| 664 | * CPU2 -/ ccnf : 1 |
| 665 | * CPU3 --- Codec2 |
| 666 | * |
| 667 | * => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec |
| 668 | * => 7 DAIs = 4xCPU + 3xCodec |
| 669 | * => 1 ccnf = 1xdummy-Codec |
| 670 | * |
| 671 | * ex2) |
| 672 | * CPU0 --- Codec0 link : 5 |
| 673 | * CPU1 --- Codec1 dais : 6 |
| 674 | * CPU2 -/ ccnf : 1 |
| 675 | * CPU3 -/ |
| 676 | * |
| 677 | * => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec |
| 678 | * => 6 DAIs = 4xCPU + 2xCodec |
| 679 | * => 1 ccnf = 1xdummy-Codec |
| 680 | * |
| 681 | * ex3) |
| 682 | * CPU0 --- Codec0 link : 6 |
| 683 | * CPU1 -/ dais : 6 |
| 684 | * CPU2 --- Codec1 ccnf : 2 |
| 685 | * CPU3 -/ |
| 686 | * |
| 687 | * => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec |
| 688 | * => 6 DAIs = 4xCPU + 2xCodec |
| 689 | * => 2 ccnf = 2xdummy-Codec |
Kuninori Morimoto | de2949f | 2018-12-20 10:45:54 +0900 | [diff] [blame] | 690 | * |
| 691 | * ex4) |
| 692 | * CPU0 --- Codec0 (convert-rate) link : 3 |
| 693 | * CPU1 --- Codec1 dais : 4 |
| 694 | * ccnf : 1 |
| 695 | * |
| 696 | * => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec |
| 697 | * => 4 DAIs = 2xCPU + 2xCodec |
| 698 | * => 1 ccnf = 1xdummy-Codec |
Kuninori Morimoto | ae3cb57 | 2018-12-14 11:32:25 +0900 | [diff] [blame] | 699 | */ |
Thierry Reding | 0f687d8 | 2021-04-16 09:11:46 +0200 | [diff] [blame] | 700 | return graph_for_each_link(priv, li, |
| 701 | graph_count_noml, |
| 702 | graph_count_dpcm); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 705 | static int graph_probe(struct platform_device *pdev) |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 706 | { |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 707 | struct asoc_simple_priv *priv; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 708 | struct device *dev = &pdev->dev; |
| 709 | struct snd_soc_card *card; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 710 | |
| 711 | /* Allocate the private data and the DAI link array */ |
| 712 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 713 | if (!priv) |
| 714 | return -ENOMEM; |
| 715 | |
Kuninori Morimoto | e59289c | 2019-03-20 13:54:59 +0900 | [diff] [blame] | 716 | card = simple_priv_to_card(priv); |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 717 | card->dapm_widgets = graph_dapm_widgets; |
| 718 | card->num_dapm_widgets = ARRAY_SIZE(graph_dapm_widgets); |
Kuninori Morimoto | 1a456b1 | 2021-04-19 11:02:19 +0900 | [diff] [blame] | 719 | card->probe = asoc_graph_card_probe; |
Kuninori Morimoto | dd98fbc | 2018-12-20 10:46:05 +0900 | [diff] [blame] | 720 | |
Sameer Pujar | d09c774 | 2020-11-02 20:40:13 +0530 | [diff] [blame] | 721 | if (of_device_get_match_data(dev)) |
| 722 | priv->dpcm_selectable = 1; |
| 723 | |
Sameer Pujar | 6e4ea8a | 2021-02-07 23:06:57 +0530 | [diff] [blame] | 724 | return audio_graph_parse_of(priv, dev); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 727 | static const struct of_device_id graph_of_match[] = { |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 728 | { .compatible = "audio-graph-card", }, |
Kuninori Morimoto | c2c6160 | 2019-04-04 09:52:15 +0900 | [diff] [blame] | 729 | { .compatible = "audio-graph-scu-card", |
| 730 | .data = (void *)DPCM_SELECTABLE }, |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 731 | {}, |
| 732 | }; |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 733 | MODULE_DEVICE_TABLE(of, graph_of_match); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 734 | |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 735 | static struct platform_driver graph_card = { |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 736 | .driver = { |
| 737 | .name = "asoc-audio-graph-card", |
Kuninori Morimoto | 7b828a3 | 2017-08-22 04:56:44 +0000 | [diff] [blame] | 738 | .pm = &snd_soc_pm_ops, |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 739 | .of_match_table = graph_of_match, |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 740 | }, |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 741 | .probe = graph_probe, |
Kuninori Morimoto | f6fcc82 | 2021-04-19 11:02:25 +0900 | [diff] [blame] | 742 | .remove = asoc_simple_remove, |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 743 | }; |
Kuninori Morimoto | 97fe6ca | 2018-12-20 10:46:33 +0900 | [diff] [blame] | 744 | module_platform_driver(graph_card); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 745 | |
| 746 | MODULE_ALIAS("platform:asoc-audio-graph-card"); |
| 747 | MODULE_LICENSE("GPL v2"); |
| 748 | MODULE_DESCRIPTION("ASoC Audio Graph Sound Card"); |
| 749 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |