Lines Matching +full:jack +full:- +full:det +full:- +full:rate
1 // SPDX-License-Identifier: GPL-2.0
3 // simple-card-utils.c
7 #include <dt-bindings/sound/audio-graph.h>
14 #include <sound/jack.h>
21 int val = -EINVAL; in simple_util_get_sample_fmt()
35 if (!strcmp(data->convert_sample_format, in simple_util_get_sample_fmt()
71 /* sampling rate convert */ in simple_util_parse_convert()
72 snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-rate"); in simple_util_parse_convert()
73 of_property_read_u32(np, prop, &data->convert_rate); in simple_util_parse_convert()
76 snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-channels"); in simple_util_parse_convert()
77 of_property_read_u32(np, prop, &data->convert_channels); in simple_util_parse_convert()
80 snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-sample-format"); in simple_util_parse_convert()
81 of_property_read_string(np, prop, &data->convert_sample_format); in simple_util_parse_convert()
86 * simple_util_is_convert_required() - Query if HW param conversion was requested
90 * any "convert-xxx" properties.
94 return data->convert_rate || in simple_util_is_convert_required()
95 data->convert_channels || in simple_util_is_convert_required()
96 data->convert_sample_format; in simple_util_is_convert_required()
115 * No dai-link level and master setting was not found from in simple_util_parse_daifmt()
142 if (!of_property_read_bool(np, "dai-tdm-slot-width-map")) in simple_util_parse_tdm_width_map()
145 n = of_property_count_elems_of_size(np, "dai-tdm-slot-width-map", sizeof(u32)); in simple_util_parse_tdm_width_map()
147 dev_err(dev, "Invalid number of cells for dai-tdm-slot-width-map\n"); in simple_util_parse_tdm_width_map()
148 return -EINVAL; in simple_util_parse_tdm_width_map()
151 dai->tdm_width_map = devm_kcalloc(dev, n, sizeof(*dai->tdm_width_map), GFP_KERNEL); in simple_util_parse_tdm_width_map()
152 if (!dai->tdm_width_map) in simple_util_parse_tdm_width_map()
153 return -ENOMEM; in simple_util_parse_tdm_width_map()
158 return -ENOMEM; in simple_util_parse_tdm_width_map()
160 ret = of_property_read_u32_array(np, "dai-tdm-slot-width-map", array_values, n); in simple_util_parse_tdm_width_map()
162 dev_err(dev, "Could not read dai-tdm-slot-width-map: %d\n", ret); in simple_util_parse_tdm_width_map()
168 dai->tdm_width_map[i].sample_bits = *p++; in simple_util_parse_tdm_width_map()
169 dai->tdm_width_map[i].slot_width = *p++; in simple_util_parse_tdm_width_map()
170 dai->tdm_width_map[i].slot_count = *p++; in simple_util_parse_tdm_width_map()
173 dai->n_tdm_widths = i; in simple_util_parse_tdm_width_map()
185 int ret = -ENOMEM; in simple_util_set_dailink_name()
194 dai_link->name = name; in simple_util_set_dailink_name()
195 dai_link->stream_name = name; in simple_util_set_dailink_name()
212 if (ret < 0 || !card->name) { in simple_util_parse_card_name()
221 if (!card->name && card->dai_link) in simple_util_parse_card_name()
222 card->name = card->dai_link->name; in simple_util_parse_card_name()
231 return clk_prepare_enable(dai->clk); in simple_clk_enable()
239 clk_disable_unprepare(dai->clk); in simple_clk_disable()
251 * Parse dai->sysclk come from "clocks = <&xxx>" in simple_util_parse_clk()
253 * or "system-clock-frequency = <xxx>" in simple_util_parse_clk()
257 simple_dai->clk_fixed = of_property_read_bool( in simple_util_parse_clk()
258 node, "system-clock-fixed"); in simple_util_parse_clk()
260 simple_dai->sysclk = clk_get_rate(clk); in simple_util_parse_clk()
262 simple_dai->clk = clk; in simple_util_parse_clk()
263 } else if (!of_property_read_u32(node, "system-clock-frequency", &val)) { in simple_util_parse_clk()
264 simple_dai->sysclk = val; in simple_util_parse_clk()
265 simple_dai->clk_fixed = true; in simple_util_parse_clk()
267 clk = devm_get_clk_from_child(dev, dlc->of_node, NULL); in simple_util_parse_clk()
269 simple_dai->sysclk = clk_get_rate(clk); in simple_util_parse_clk()
272 if (of_property_read_bool(node, "system-clock-direction-out")) in simple_util_parse_clk()
273 simple_dai->clk_direction = SND_SOC_CLOCK_OUT; in simple_util_parse_clk()
283 if (dai->clk_fixed) { in simple_check_fixed_sysclk()
284 if (*fixed_sysclk && *fixed_sysclk != dai->sysclk) { in simple_check_fixed_sysclk()
286 *fixed_sysclk, dai->sysclk); in simple_check_fixed_sysclk()
287 return -EINVAL; in simple_check_fixed_sysclk()
289 *fixed_sysclk = dai->sysclk; in simple_check_fixed_sysclk()
298 struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card); in simple_util_startup()
299 struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num); in simple_util_startup()
309 ret = simple_check_fixed_sysclk(rtd->dev, dai, &fixed_sysclk); in simple_util_startup()
318 ret = simple_check_fixed_sysclk(rtd->dev, dai, &fixed_sysclk); in simple_util_startup()
323 if (fixed_sysclk && props->mclk_fs) { in simple_util_startup()
324 unsigned int fixed_rate = fixed_sysclk / props->mclk_fs; in simple_util_startup()
326 if (fixed_sysclk % props->mclk_fs) { in simple_util_startup()
327 dev_err(rtd->dev, "fixed sysclk %u not divisible by mclk_fs %u\n", in simple_util_startup()
328 fixed_sysclk, props->mclk_fs); in simple_util_startup()
329 ret = -EINVAL; in simple_util_startup()
332 ret = snd_pcm_hw_constraint_minmax(substream->runtime, SNDRV_PCM_HW_PARAM_RATE, in simple_util_startup()
359 struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card); in simple_util_shutdown()
360 struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num); in simple_util_shutdown()
367 if (props->mclk_fs && !dai->clk_fixed && !snd_soc_dai_active(cpu_dai)) in simple_util_shutdown()
376 if (props->mclk_fs && !dai->clk_fixed && !snd_soc_dai_active(codec_dai)) in simple_util_shutdown()
387 unsigned long rate) in simple_set_clk_rate() argument
392 if (simple_dai->clk_fixed && rate != simple_dai->sysclk) { in simple_set_clk_rate()
393 dev_err(dev, "dai %s invalid clock rate %lu\n", simple_dai->name, rate); in simple_set_clk_rate()
394 return -EINVAL; in simple_set_clk_rate()
397 if (!simple_dai->clk) in simple_set_clk_rate()
400 if (clk_get_rate(simple_dai->clk) == rate) in simple_set_clk_rate()
403 return clk_set_rate(simple_dai->clk, rate); in simple_set_clk_rate()
414 if (!simple_dai || !simple_dai->tdm_width_map) in simple_set_tdm()
417 slot_width = simple_dai->slot_width; in simple_set_tdm()
418 slot_count = simple_dai->slots; in simple_set_tdm()
423 for (i = 0; i < simple_dai->n_tdm_widths; ++i) { in simple_set_tdm()
424 if (simple_dai->tdm_width_map[i].sample_bits == sample_bits) { in simple_set_tdm()
425 slot_width = simple_dai->tdm_width_map[i].slot_width; in simple_set_tdm()
426 slot_count = simple_dai->tdm_width_map[i].slot_count; in simple_set_tdm()
432 simple_dai->tx_slot_mask, in simple_set_tdm()
433 simple_dai->rx_slot_mask, in simple_set_tdm()
436 if (ret && ret != -ENOTSUPP) { in simple_set_tdm()
437 dev_err(dai->dev, "simple-card: set_tdm_slot error: %d\n", ret); in simple_set_tdm()
450 struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card); in simple_util_hw_params()
451 struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num); in simple_util_hw_params()
455 if (props->mclk_fs) in simple_util_hw_params()
456 mclk_fs = props->mclk_fs; in simple_util_hw_params()
463 ret = simple_set_clk_rate(rtd->dev, pdai, mclk); in simple_util_hw_params()
469 ret = simple_set_clk_rate(rtd->dev, pdai, mclk); in simple_util_hw_params()
481 if (ret && ret != -ENOTSUPP) in simple_util_hw_params()
487 if (ret && ret != -ENOTSUPP) in simple_util_hw_params()
493 if (ret && ret != -ENOTSUPP) in simple_util_hw_params()
519 struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card); in simple_util_be_hw_params_fixup()
520 struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num); in simple_util_be_hw_params_fixup()
521 struct simple_util_data *data = &dai_props->adata; in simple_util_be_hw_params_fixup()
522 struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); in simple_util_be_hw_params_fixup() local
525 if (data->convert_rate) in simple_util_be_hw_params_fixup()
526 rate->min = in simple_util_be_hw_params_fixup()
527 rate->max = data->convert_rate; in simple_util_be_hw_params_fixup()
529 if (data->convert_channels) in simple_util_be_hw_params_fixup()
530 channels->min = in simple_util_be_hw_params_fixup()
531 channels->max = data->convert_channels; in simple_util_be_hw_params_fixup()
533 if (data->convert_sample_format) in simple_util_be_hw_params_fixup()
547 if (simple_dai->sysclk) { in simple_init_dai()
548 ret = snd_soc_dai_set_sysclk(dai, 0, simple_dai->sysclk, in simple_init_dai()
549 simple_dai->clk_direction); in simple_init_dai()
550 if (ret && ret != -ENOTSUPP) { in simple_init_dai()
551 dev_err(dai->dev, "simple-card: set_sysclk error\n"); in simple_init_dai()
556 if (simple_dai->slots) { in simple_init_dai()
558 simple_dai->tx_slot_mask, in simple_init_dai()
559 simple_dai->rx_slot_mask, in simple_init_dai()
560 simple_dai->slots, in simple_init_dai()
561 simple_dai->slot_width); in simple_init_dai()
562 if (ret && ret != -ENOTSUPP) { in simple_init_dai()
563 dev_err(dai->dev, "simple-card: set_tdm_slot error\n"); in simple_init_dai()
573 return component->driver->endianness; in simple_component_is_codec()
579 struct snd_soc_dai_link *dai_link = rtd->dai_link; in simple_init_for_codec2codec()
586 if (dai_link->c2c_params) in simple_init_for_codec2codec()
590 if (dai_link->no_pcm) in simple_init_for_codec2codec()
607 dev_err(rtd->dev, "simple-card: no valid dai_link params\n"); in simple_init_for_codec2codec()
611 c2c_params = devm_kzalloc(rtd->dev, sizeof(*c2c_params), GFP_KERNEL); in simple_init_for_codec2codec()
613 return -ENOMEM; in simple_init_for_codec2codec()
615 c2c_params->formats = hw.formats; in simple_init_for_codec2codec()
616 c2c_params->rates = hw.rates; in simple_init_for_codec2codec()
617 c2c_params->rate_min = hw.rate_min; in simple_init_for_codec2codec()
618 c2c_params->rate_max = hw.rate_max; in simple_init_for_codec2codec()
619 c2c_params->channels_min = hw.channels_min; in simple_init_for_codec2codec()
620 c2c_params->channels_max = hw.channels_max; in simple_init_for_codec2codec()
622 dai_link->c2c_params = c2c_params; in simple_init_for_codec2codec()
623 dai_link->num_c2c_params = 1; in simple_init_for_codec2codec()
630 struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card); in simple_util_dai_init()
631 struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num); in simple_util_dai_init()
660 * Some CPU might be using soc-generic-dmaengine-pcm. This means CPU and Platform in simple_util_canonicalize_platform()
661 * are different Component, but are sharing same component->dev. in simple_util_canonicalize_platform()
665 * simple-card.c :: simple_count_noml() in simple_util_canonicalize_platform()
667 if (!platforms->of_node) in simple_util_canonicalize_platform()
685 cpus->dai_name = NULL; in simple_util_canonicalize_cpu()
698 of_node_put(cpu->of_node); in simple_util_clean_reference()
700 of_node_put(codec->of_node); in simple_util_clean_reference()
708 struct device_node *node = card->dev->of_node; in simple_util_parse_routing()
726 struct device_node *node = card->dev->of_node; in simple_util_parse_widgets()
750 snprintf(prop, sizeof(prop), "%s%s", prefix, "pin-switches"); in simple_util_parse_pin_switches()
761 struct device *dev = card->dev; in simple_util_init_jack()
773 snprintf(prop, sizeof(prop), "%shp-det", prefix); in simple_util_init_jack()
778 snprintf(prop, sizeof(prop), "%smic-det", prefix); in simple_util_init_jack()
779 pin_name = pin ? pin : "Mic Jack"; in simple_util_init_jack()
794 sjack->pin.pin = pin_name; in simple_util_init_jack()
795 sjack->pin.mask = mask; in simple_util_init_jack()
797 sjack->gpio.name = gpio_name; in simple_util_init_jack()
798 sjack->gpio.report = mask; in simple_util_init_jack()
799 sjack->gpio.desc = desc; in simple_util_init_jack()
800 sjack->gpio.debounce_time = 150; in simple_util_init_jack()
802 snd_soc_card_jack_new_pins(card, pin_name, mask, &sjack->jack, in simple_util_init_jack()
803 &sjack->pin, 1); in simple_util_init_jack()
805 snd_soc_jack_add_gpios(&sjack->jack, 1, &sjack->gpio); in simple_util_init_jack()
821 if (priv->aux_jacks) in simple_util_init_aux_jacks()
832 priv->aux_jacks = devm_kcalloc(card->dev, num, in simple_util_init_aux_jacks()
834 if (!priv->aux_jacks) in simple_util_init_aux_jacks()
835 return -ENOMEM; in simple_util_init_aux_jacks()
839 struct snd_soc_jack *jack; in simple_util_init_aux_jacks() local
848 /* create jack */ in simple_util_init_aux_jacks()
849 jack = &(priv->aux_jacks[found_jack_index++]); in simple_util_init_aux_jacks()
850 snprintf(id, sizeof(id), "%s-jack", component->name); in simple_util_init_aux_jacks()
851 ret = snd_soc_card_jack_new(card, id, type, jack); in simple_util_init_aux_jacks()
855 (void)snd_soc_component_set_jack(component, jack, NULL); in simple_util_init_aux_jacks()
873 dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL); in simple_util_init_priv()
874 dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL); in simple_util_init_priv()
876 return -ENOMEM; in simple_util_init_priv()
882 for (i = 0; i < li->link; i++) { in simple_util_init_priv()
883 int cc = li->num[i].cpus + li->num[i].codecs; in simple_util_init_priv()
886 dlc_num += cc + li->num[i].platforms; in simple_util_init_priv()
888 if (!li->num[i].cpus) in simple_util_init_priv()
889 cnf_num += li->num[i].codecs; in simple_util_init_priv()
895 return -ENOMEM; in simple_util_init_priv()
900 return -ENOMEM; in simple_util_init_priv()
904 li->link, dai_num, cnf_num); in simple_util_init_priv()
906 priv->dai_props = dai_props; in simple_util_init_priv()
907 priv->dai_link = dai_link; in simple_util_init_priv()
908 priv->dais = dais; in simple_util_init_priv()
909 priv->dlcs = dlcs; in simple_util_init_priv()
910 priv->codec_conf = cconf; in simple_util_init_priv()
912 card->dai_link = priv->dai_link; in simple_util_init_priv()
913 card->num_links = li->link; in simple_util_init_priv()
914 card->codec_conf = cconf; in simple_util_init_priv()
915 card->num_configs = cnf_num; in simple_util_init_priv()
917 for (i = 0; i < li->link; i++) { in simple_util_init_priv()
918 if (li->num[i].cpus) { in simple_util_init_priv()
922 dai_link[i].num_cpus = li->num[i].cpus; in simple_util_init_priv()
925 dlcs += li->num[i].cpus; in simple_util_init_priv()
926 dais += li->num[i].cpus; in simple_util_init_priv()
934 if (li->num[i].codecs) { in simple_util_init_priv()
938 dai_link[i].num_codecs = li->num[i].codecs; in simple_util_init_priv()
941 dlcs += li->num[i].codecs; in simple_util_init_priv()
942 dais += li->num[i].codecs; in simple_util_init_priv()
944 if (!li->num[i].cpus) { in simple_util_init_priv()
947 cconf += li->num[i].codecs; in simple_util_init_priv()
956 if (li->num[i].platforms) { in simple_util_init_priv()
960 dai_link[i].num_platforms = li->num[i].platforms; in simple_util_init_priv()
962 dlcs += li->num[i].platforms; in simple_util_init_priv()
988 ret = simple_util_init_hp(card, &priv->hp_jack, NULL); in graph_util_card_probe()
992 ret = simple_util_init_mic(card, &priv->mic_jack, NULL); in graph_util_card_probe()
1038 if (ret != -ENOTSUPP) in graph_get_dai_id()
1066 id = -1; in graph_get_dai_id()
1076 return -ENODEV; in graph_get_dai_id()
1100 dlc->dai_name = snd_soc_dai_name_get(dai); in graph_util_parse_dai()
1101 dlc->dai_args = snd_soc_copy_dai_args(dev, &args); in graph_util_parse_dai()
1102 if (!dlc->dai_args) in graph_util_parse_dai()
1103 return -ENOMEM; in graph_util_parse_dai()
1108 /* Get dai->name */ in graph_util_parse_dai()
1116 * Here, dlc->dai_name is pointer to CPU/Codec DAI name. in graph_util_parse_dai()
1118 * dlc->dai_name is keeping unbinded CPU or Codec in graph_util_parse_dai()
1121 * If user re-bind CPU or Codec driver again, ALSA SoC will try in graph_util_parse_dai()
1149 bool is_playback_only = of_property_read_bool(np, "playback-only"); in graph_util_parse_link_direction()
1150 bool is_capture_only = of_property_read_bool(np, "capture-only"); in graph_util_parse_link_direction()
1204 * #include <dt-bindings/sound/audio-graph.h> in graph_util_parse_trigger_order()
1206 * link-trigger-order = <SND_SOC_TRIGGER_LINK in graph_util_parse_trigger_order()
1211 order = __graph_util_parse_trigger_order(priv, np, "link-trigger-order"); in graph_util_parse_trigger_order()
1217 order = __graph_util_parse_trigger_order(priv, np, "link-trigger-order-start"); in graph_util_parse_trigger_order()
1221 order = __graph_util_parse_trigger_order(priv, np, "link-trigger-order-stop"); in graph_util_parse_trigger_order()