Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: simple-card-utils.c: share asoc_graph_parse_dai()

Current Audio Graph Card/Card2 implements asoc_simple_parse_dai()
on each driver, but these are same function.
This patch share it as asoc_graph_parse_dai().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87o7lihpvy.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Kuninori Morimoto and committed by
Mark Brown
fed4be31 fd01a151

+110 -212
+3
include/sound/simple_card_utils.h
··· 195 195 196 196 int asoc_graph_card_probe(struct snd_soc_card *card); 197 197 int asoc_graph_is_ports0(struct device_node *port); 198 + int asoc_graph_parse_dai(struct device_node *ep, 199 + struct snd_soc_dai_link_component *dlc, 200 + int *is_single_link); 198 201 199 202 #ifdef DEBUG 200 203 static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
+1 -106
sound/soc/generic/audio-graph-card.c
··· 55 55 .hw_params = asoc_simple_hw_params, 56 56 }; 57 57 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; 64 - const u32 *reg; 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_property_present(ep, "reg")) 82 - return info.id; 83 - 84 - node = of_get_parent(ep); 85 - reg = of_get_property(node, "reg", NULL); 86 - of_node_put(node); 87 - if (reg) 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 - 112 58 static bool soc_component_is_pcm(struct snd_soc_dai_link_component *dlc) 113 59 { 114 60 struct snd_soc_dai *dai = snd_soc_find_dai_with_mutex(dlc); ··· 64 118 return true; 65 119 66 120 return false; 67 - } 68 - 69 - static int asoc_simple_parse_dai(struct device_node *ep, 70 - struct snd_soc_dai_link_component *dlc, 71 - int *is_single_link) 72 - { 73 - struct device_node *node; 74 - struct of_phandle_args args; 75 - int ret; 76 - 77 - if (!ep) 78 - return 0; 79 - 80 - node = of_graph_get_port_parent(ep); 81 - 82 - /* Get dai->name */ 83 - args.np = node; 84 - args.args[0] = graph_get_dai_id(ep); 85 - args.args_count = (of_graph_get_endpoint_count(node) > 1); 86 - 87 - /* 88 - * FIXME 89 - * 90 - * Here, dlc->dai_name is pointer to CPU/Codec DAI name. 91 - * If user unbinded CPU or Codec driver, but not for Sound Card, 92 - * dlc->dai_name is keeping unbinded CPU or Codec 93 - * driver's pointer. 94 - * 95 - * If user re-bind CPU or Codec driver again, ALSA SoC will try 96 - * to rebind Card via snd_soc_try_rebind_card(), but because of 97 - * above reason, it might can't bind Sound Card. 98 - * Because Sound Card is pointing to released dai_name pointer. 99 - * 100 - * To avoid this rebind Card issue, 101 - * 1) It needs to alloc memory to keep dai_name eventhough 102 - * CPU or Codec driver was unbinded, or 103 - * 2) user need to rebind Sound Card everytime 104 - * if he unbinded CPU or Codec. 105 - */ 106 - ret = snd_soc_get_dai_name(&args, &dlc->dai_name); 107 - if (ret < 0) { 108 - of_node_put(node); 109 - return ret; 110 - } 111 - 112 - dlc->of_node = node; 113 - 114 - if (is_single_link) 115 - *is_single_link = of_graph_get_endpoint_count(node) == 1; 116 - 117 - return 0; 118 121 } 119 122 120 123 static void graph_parse_convert(struct device *dev, ··· 126 231 127 232 graph_parse_mclk_fs(top, ep, dai_props); 128 233 129 - ret = asoc_simple_parse_dai(ep, dlc, cpu); 234 + ret = asoc_graph_parse_dai(ep, dlc, cpu); 130 235 if (ret < 0) 131 236 return ret; 132 237
+1 -106
sound/soc/generic/audio-graph-card2.c
··· 353 353 .hw_params = asoc_simple_hw_params, 354 354 }; 355 355 356 - static int graph_get_dai_id(struct device_node *ep) 357 - { 358 - struct device_node *node; 359 - struct device_node *endpoint; 360 - struct of_endpoint info; 361 - int i, id; 362 - const u32 *reg; 363 - int ret; 364 - 365 - /* use driver specified DAI ID if exist */ 366 - ret = snd_soc_get_dai_id(ep); 367 - if (ret != -ENOTSUPP) 368 - return ret; 369 - 370 - /* use endpoint/port reg if exist */ 371 - ret = of_graph_parse_endpoint(ep, &info); 372 - if (ret == 0) { 373 - /* 374 - * Because it will count port/endpoint if it doesn't have "reg". 375 - * But, we can't judge whether it has "no reg", or "reg = <0>" 376 - * only of_graph_parse_endpoint(). 377 - * We need to check "reg" property 378 - */ 379 - if (of_property_present(ep, "reg")) 380 - return info.id; 381 - 382 - node = of_get_parent(ep); 383 - reg = of_get_property(node, "reg", NULL); 384 - of_node_put(node); 385 - if (reg) 386 - return info.port; 387 - } 388 - node = of_graph_get_port_parent(ep); 389 - 390 - /* 391 - * Non HDMI sound case, counting port/endpoint on its DT 392 - * is enough. Let's count it. 393 - */ 394 - i = 0; 395 - id = -1; 396 - for_each_endpoint_of_node(node, endpoint) { 397 - if (endpoint == ep) 398 - id = i; 399 - i++; 400 - } 401 - 402 - of_node_put(node); 403 - 404 - if (id < 0) 405 - return -ENODEV; 406 - 407 - return id; 408 - } 409 - 410 - static int asoc_simple_parse_dai(struct device_node *ep, 411 - struct snd_soc_dai_link_component *dlc, 412 - int *is_single_link) 413 - { 414 - struct device_node *node; 415 - struct of_phandle_args args; 416 - int ret; 417 - 418 - if (!ep) 419 - return 0; 420 - 421 - node = of_graph_get_port_parent(ep); 422 - 423 - /* Get dai->name */ 424 - args.np = node; 425 - args.args[0] = graph_get_dai_id(ep); 426 - args.args_count = (of_graph_get_endpoint_count(node) > 1); 427 - 428 - /* 429 - * FIXME 430 - * 431 - * Here, dlc->dai_name is pointer to CPU/Codec DAI name. 432 - * If user unbinded CPU or Codec driver, but not for Sound Card, 433 - * dlc->dai_name is keeping unbinded CPU or Codec 434 - * driver's pointer. 435 - * 436 - * If user re-bind CPU or Codec driver again, ALSA SoC will try 437 - * to rebind Card via snd_soc_try_rebind_card(), but because of 438 - * above reason, it might can't bind Sound Card. 439 - * Because Sound Card is pointing to released dai_name pointer. 440 - * 441 - * To avoid this rebind Card issue, 442 - * 1) It needs to alloc memory to keep dai_name eventhough 443 - * CPU or Codec driver was unbinded, or 444 - * 2) user need to rebind Sound Card everytime 445 - * if he unbinded CPU or Codec. 446 - */ 447 - ret = snd_soc_get_dai_name(&args, &dlc->dai_name); 448 - if (ret < 0) { 449 - of_node_put(node); 450 - return ret; 451 - } 452 - 453 - dlc->of_node = node; 454 - 455 - if (is_single_link) 456 - *is_single_link = of_graph_get_endpoint_count(node) == 1; 457 - 458 - return 0; 459 - } 460 - 461 356 static void graph_parse_convert(struct device_node *ep, 462 357 struct simple_dai_props *props) 463 358 { ··· 407 512 408 513 graph_parse_mclk_fs(ep, dai_props); 409 514 410 - ret = asoc_simple_parse_dai(ep, dlc, &is_single_links); 515 + ret = asoc_graph_parse_dai(ep, dlc, &is_single_links); 411 516 if (ret < 0) 412 517 return ret; 413 518
+105
sound/soc/generic/simple-card-utils.c
··· 1019 1019 } 1020 1020 EXPORT_SYMBOL_GPL(asoc_graph_is_ports0); 1021 1021 1022 + static int graph_get_dai_id(struct device_node *ep) 1023 + { 1024 + struct device_node *node; 1025 + struct device_node *endpoint; 1026 + struct of_endpoint info; 1027 + int i, id; 1028 + int ret; 1029 + 1030 + /* use driver specified DAI ID if exist */ 1031 + ret = snd_soc_get_dai_id(ep); 1032 + if (ret != -ENOTSUPP) 1033 + return ret; 1034 + 1035 + /* use endpoint/port reg if exist */ 1036 + ret = of_graph_parse_endpoint(ep, &info); 1037 + if (ret == 0) { 1038 + /* 1039 + * Because it will count port/endpoint if it doesn't have "reg". 1040 + * But, we can't judge whether it has "no reg", or "reg = <0>" 1041 + * only of_graph_parse_endpoint(). 1042 + * We need to check "reg" property 1043 + */ 1044 + if (of_property_present(ep, "reg")) 1045 + return info.id; 1046 + 1047 + node = of_get_parent(ep); 1048 + ret = of_property_present(node, "reg"); 1049 + of_node_put(node); 1050 + if (ret) 1051 + return info.port; 1052 + } 1053 + node = of_graph_get_port_parent(ep); 1054 + 1055 + /* 1056 + * Non HDMI sound case, counting port/endpoint on its DT 1057 + * is enough. Let's count it. 1058 + */ 1059 + i = 0; 1060 + id = -1; 1061 + for_each_endpoint_of_node(node, endpoint) { 1062 + if (endpoint == ep) 1063 + id = i; 1064 + i++; 1065 + } 1066 + 1067 + of_node_put(node); 1068 + 1069 + if (id < 0) 1070 + return -ENODEV; 1071 + 1072 + return id; 1073 + } 1074 + 1075 + int asoc_graph_parse_dai(struct device_node *ep, 1076 + struct snd_soc_dai_link_component *dlc, 1077 + int *is_single_link) 1078 + { 1079 + struct device_node *node; 1080 + struct of_phandle_args args = {}; 1081 + int ret; 1082 + 1083 + if (!ep) 1084 + return 0; 1085 + 1086 + node = of_graph_get_port_parent(ep); 1087 + 1088 + /* Get dai->name */ 1089 + args.np = node; 1090 + args.args[0] = graph_get_dai_id(ep); 1091 + args.args_count = (of_graph_get_endpoint_count(node) > 1); 1092 + 1093 + /* 1094 + * FIXME 1095 + * 1096 + * Here, dlc->dai_name is pointer to CPU/Codec DAI name. 1097 + * If user unbinded CPU or Codec driver, but not for Sound Card, 1098 + * dlc->dai_name is keeping unbinded CPU or Codec 1099 + * driver's pointer. 1100 + * 1101 + * If user re-bind CPU or Codec driver again, ALSA SoC will try 1102 + * to rebind Card via snd_soc_try_rebind_card(), but because of 1103 + * above reason, it might can't bind Sound Card. 1104 + * Because Sound Card is pointing to released dai_name pointer. 1105 + * 1106 + * To avoid this rebind Card issue, 1107 + * 1) It needs to alloc memory to keep dai_name eventhough 1108 + * CPU or Codec driver was unbinded, or 1109 + * 2) user need to rebind Sound Card everytime 1110 + * if he unbinded CPU or Codec. 1111 + */ 1112 + ret = snd_soc_get_dai_name(&args, &dlc->dai_name); 1113 + if (ret < 0) { 1114 + of_node_put(node); 1115 + return ret; 1116 + } 1117 + 1118 + dlc->of_node = node; 1119 + 1120 + if (is_single_link) 1121 + *is_single_link = of_graph_get_endpoint_count(node) == 1; 1122 + 1123 + return 0; 1124 + } 1125 + EXPORT_SYMBOL_GPL(asoc_graph_parse_dai); 1126 + 1022 1127 /* Module information */ 1023 1128 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); 1024 1129 MODULE_DESCRIPTION("ALSA SoC Simple Card Utils");