Lines Matching +full:comp +full:- +full:disable

1 // SPDX-License-Identifier: GPL-2.0-only
17 #include <sound/cs-amp-lib.h>
30 * ASP1_DOUT_HIZ_CONTROL = Hi-Z during unused timeslots
35 * Override any Windows-specific mixer settings applied by the firmware.
56 flush_work(&cs35l56->dsp_work);
66 pm_runtime_get_sync(cs35l56->base.dev);
67 ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_PLAY);
70 ret = regmap_read_poll_timeout(cs35l56->base.regmap,
76 dev_warn(cs35l56->base.dev, "PS0 wait failed: %d\n", ret);
78 regmap_set_bits(cs35l56->base.regmap, CS35L56_ASP1_ENABLES1,
80 cs35l56->asp_tx_mask);
81 cs35l56->playing = true;
86 cs35l56->playing = false;
87 cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_PAUSE);
88 regmap_clear_bits(cs35l56->base.regmap, CS35L56_ASP1_ENABLES1,
93 pm_runtime_mark_last_busy(cs35l56->base.dev);
94 pm_runtime_put_autosuspend(cs35l56->base.dev);
101 dev_dbg(cs35l56->base.dev, "%s()%d: action: %d\n", __func__, __LINE__, action);
105 if (cs35l56->playing)
109 if (cs35l56->suspended) {
110 cs35l56->playing = true;
117 if (!cs35l56->playing)
131 if (cs35l56->cs_dsp.booted)
132 cs_dsp_stop(&cs35l56->cs_dsp);
134 return cs35l56_runtime_suspend_common(&cs35l56->base);
142 ret = cs35l56_runtime_resume_common(&cs35l56->base, false);
146 if (cs35l56->cs_dsp.booted) {
147 ret = cs_dsp_run(&cs35l56->cs_dsp);
149 dev_dbg(cs35l56->base.dev, "%s: cs_dsp_run ret %d\n", __func__, ret);
157 cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_ALLOW_AUTO_HIBERNATE);
158 regmap_write(cs35l56->base.regmap, CS35L56_DSP_VIRTUAL1_MBOX_1,
161 regcache_cache_only(cs35l56->base.regmap, true);
169 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
170 uinfo->count = 1;
171 uinfo->value.enumerated.items = CS35L56_NUM_INPUT_SRC;
172 if (uinfo->value.enumerated.item >= CS35L56_NUM_INPUT_SRC)
173 uinfo->value.enumerated.item = CS35L56_NUM_INPUT_SRC - 1;
174 strscpy(uinfo->value.enumerated.name, cs35l56_tx_input_texts[uinfo->value.enumerated.item],
175 sizeof(uinfo->value.enumerated.name));
183 struct cs35l56_hda *cs35l56 = (struct cs35l56_hda *)kcontrol->private_data;
189 regmap_read(cs35l56->base.regmap, kcontrol->private_value, &reg_val);
194 ucontrol->value.enumerated.item[0] = i;
205 struct cs35l56_hda *cs35l56 = (struct cs35l56_hda *)kcontrol->private_data;
206 unsigned int item = ucontrol->value.enumerated.item[0];
210 return -EINVAL;
214 regmap_update_bits_check(cs35l56->base.regmap, kcontrol->private_value,
224 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
225 uinfo->count = 1;
226 uinfo->value.integer.min = CS35L56_MAIN_POSTURE_MIN;
227 uinfo->value.integer.max = CS35L56_MAIN_POSTURE_MAX;
234 struct cs35l56_hda *cs35l56 = (struct cs35l56_hda *)kcontrol->private_data;
240 ret = regmap_read(cs35l56->base.regmap, CS35L56_MAIN_POSTURE_NUMBER, &pos);
244 ucontrol->value.integer.value[0] = pos;
252 struct cs35l56_hda *cs35l56 = (struct cs35l56_hda *)kcontrol->private_data;
253 unsigned long pos = ucontrol->value.integer.value[0];
259 return -EINVAL;
263 ret = regmap_update_bits_check(cs35l56->base.regmap,
283 static const DECLARE_TLV_DB_SCALE(cs35l56_hda_vol_tlv, -10000, 25, 0);
288 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
289 uinfo->count = 1;
290 uinfo->value.integer.step = 1;
291 uinfo->value.integer.min = 0;
292 uinfo->value.integer.max = CS35L56_MAIN_RENDER_USER_VOLUME_MAX -
301 struct cs35l56_hda *cs35l56 = (struct cs35l56_hda *)kcontrol->private_data;
308 ret = regmap_read(cs35l56->base.regmap, CS35L56_MAIN_RENDER_USER_VOLUME, &raw_vol);
317 vol |= ~((int)(BIT(CS35L56_MAIN_RENDER_USER_VOLUME_SIGNBIT) - 1));
319 ucontrol->value.integer.value[0] = vol - CS35L56_MAIN_RENDER_USER_VOLUME_MIN;
327 struct cs35l56_hda *cs35l56 = (struct cs35l56_hda *)kcontrol->private_data;
328 long vol = ucontrol->value.integer.value[0];
333 if ((vol < 0) || (vol > (CS35L56_MAIN_RENDER_USER_VOLUME_MAX -
335 return -EINVAL;
342 ret = regmap_update_bits_check(cs35l56->base.regmap,
364 snprintf(name, sizeof(name), "%s Posture Number", cs35l56->amp_name);
366 cs35l56->posture_ctl = snd_ctl_new1(&ctl_template, cs35l56);
367 if (snd_ctl_add(cs35l56->codec->card, cs35l56->posture_ctl))
368 dev_err(cs35l56->base.dev, "Failed to add KControl: %s\n", ctl_template.name);
375 BUILD_BUG_ON(ARRAY_SIZE(cs35l56->mixer_ctl) != ARRAY_SIZE(cs35l56_hda_mixer_controls));
378 snprintf(name, sizeof(name), "%s %s", cs35l56->amp_name,
381 cs35l56->mixer_ctl[i] = snd_ctl_new1(&ctl_template, cs35l56);
382 if (snd_ctl_add(cs35l56->codec->card, cs35l56->mixer_ctl[i])) {
383 dev_err(cs35l56->base.dev, "Failed to add KControl: %s\n",
393 snprintf(name, sizeof(name), "%s Speaker Playback Volume", cs35l56->amp_name);
395 cs35l56->volume_ctl = snd_ctl_new1(&ctl_template, cs35l56);
396 if (snd_ctl_add(cs35l56->codec->card, cs35l56->volume_ctl))
397 dev_err(cs35l56->base.dev, "Failed to add KControl: %s\n", ctl_template.name);
404 for (i = ARRAY_SIZE(cs35l56->mixer_ctl) - 1; i >= 0; i--)
405 snd_ctl_remove(cs35l56->codec->card, cs35l56->mixer_ctl[i]);
407 snd_ctl_remove(cs35l56->codec->card, cs35l56->posture_ctl);
408 snd_ctl_remove(cs35l56->codec->card, cs35l56->volume_ctl);
425 *filename = kasprintf(GFP_KERNEL, "%s-%s-%s.%s", base_name,
428 *filename = kasprintf(GFP_KERNEL, "%s-%s.%s", base_name,
434 return -ENOMEM;
437 * Make sure that filename is lower-case and any non alpha-numeric
447 *s = '-';
451 ret = firmware_request_nowarn(firmware, *filename, cs35l56->base.dev);
453 dev_dbg(cs35l56->base.dev, "Failed to request '%s'\n", *filename);
459 dev_dbg(cs35l56->base.dev, "Found '%s'\n", *filename);
471 const char *system_name = cs35l56->system_name;
472 const char *amp_name = cs35l56->amp_name;
478 "cirrus/cs35l%02x-%02x%s-%06x-dsp1-misc",
479 cs35l56->base.type,
480 cs35l56->base.rev,
481 cs35l56->base.secured ? "-s" : "",
485 "cirrus/cs35l%02x-%02x%s-dsp1-misc",
486 cs35l56->base.type,
487 cs35l56->base.rev,
488 cs35l56->base.secured ? "-s" : "");
517 * Check for system-specific bin files without wmfw before
562 if (!cs35l56->base.cal_data_valid || cs35l56->base.secured)
565 ret = cs_amp_write_cal_coeffs(&cs35l56->cs_dsp,
567 &cs35l56->base.cal_data);
569 dev_warn(cs35l56->base.dev, "Failed to write calibration: %d\n", ret);
571 dev_info(cs35l56->base.dev, "Calibration applied\n");
585 * Prepare for a new DSP power-up. If the DSP has had firmware
589 if (cs35l56->base.fw_patched)
590 cs_dsp_power_down(&cs35l56->cs_dsp);
592 cs35l56->base.fw_patched = false;
594 ret = pm_runtime_resume_and_get(cs35l56->base.dev);
596 dev_err(cs35l56->base.dev, "Failed to resume and get %d\n", ret);
602 * from the built-in ROM. If not, the wmfw/bin must be for the
605 ret = cs35l56_read_prot_status(&cs35l56->base, &firmware_missing, &preloaded_fw_ver);
621 dev_err(cs35l56->base.dev, ".bin file required but not found\n");
625 mutex_lock(&cs35l56->base.irq_lock);
634 ret = cs35l56_firmware_shutdown(&cs35l56->base);
639 ret = cs_dsp_power_up(&cs35l56->cs_dsp, wmfw_firmware, wmfw_filename,
642 dev_dbg(cs35l56->base.dev, "%s: cs_dsp_power_up ret %d\n", __func__, ret);
647 dev_dbg(cs35l56->base.dev, "Loaded WMFW Firmware: %s\n", wmfw_filename);
650 dev_dbg(cs35l56->base.dev, "Loaded Coefficients: %s\n", coeff_filename);
654 cs35l56_system_reset(&cs35l56->base, false);
655 regcache_mark_dirty(cs35l56->base.regmap);
656 ret = cs35l56_wait_for_firmware_boot(&cs35l56->base);
660 regcache_cache_only(cs35l56->base.regmap, false);
663 /* Disable auto-hibernate so that runtime_pm has control */
664 ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_PREVENT_AUTO_HIBERNATE);
668 regcache_sync(cs35l56->base.regmap);
670 regmap_clear_bits(cs35l56->base.regmap, CS35L56_PROTECTION_STATUS,
672 cs35l56->base.fw_patched = true;
674 ret = cs_dsp_run(&cs35l56->cs_dsp);
676 dev_dbg(cs35l56->base.dev, "%s: cs_dsp_run ret %d\n", __func__, ret);
679 ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT);
681 cs_dsp_stop(&cs35l56->cs_dsp);
684 if (!cs35l56->base.fw_patched)
685 cs_dsp_power_down(&cs35l56->cs_dsp);
687 mutex_unlock(&cs35l56->base.irq_lock);
692 pm_runtime_put(cs35l56->base.dev);
706 struct hda_component *comp;
708 comp = hda_component_from_index(parent, cs35l56->index);
709 if (!comp)
710 return -EINVAL;
712 if (comp->dev)
713 return -EBUSY;
715 comp->dev = dev;
716 cs35l56->codec = parent->codec;
717 strscpy(comp->name, dev_name(dev), sizeof(comp->name));
718 comp->playback_hook = cs35l56_hda_playback_hook;
720 queue_work(system_long_wq, &cs35l56->dsp_work);
725 cs35l56->debugfs_root = debugfs_create_dir(dev_name(cs35l56->base.dev), sound_debugfs_root);
726 cs_dsp_init_debugfs(&cs35l56->cs_dsp, cs35l56->debugfs_root);
729 dev_dbg(cs35l56->base.dev, "Bound\n");
738 struct hda_component *comp;
740 cancel_work_sync(&cs35l56->dsp_work);
745 cs_dsp_cleanup_debugfs(&cs35l56->cs_dsp);
746 debugfs_remove_recursive(cs35l56->debugfs_root);
749 if (cs35l56->base.fw_patched)
750 cs_dsp_power_down(&cs35l56->cs_dsp);
752 comp = hda_component_from_index(parent, cs35l56->index);
753 if (comp && (comp->dev == dev))
754 memset(comp, 0, sizeof(*comp));
756 cs35l56->codec = NULL;
758 dev_dbg(cs35l56->base.dev, "Unbound\n");
772 if (cs35l56->playing)
775 cs35l56->suspended = true;
783 if (cs35l56->base.irq)
784 disable_irq(cs35l56->base.irq);
797 if (cs35l56->base.reset_gpio) {
798 gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);
809 /* Handlers are now disabled so the parent IRQ can safely be re-enabled. */
810 if (cs35l56->base.irq)
811 enable_irq(cs35l56->base.irq);
827 if (cs35l56->base.irq)
828 disable_irq(cs35l56->base.irq);
837 /* Ensure a spec-compliant RESET pulse. */
838 if (cs35l56->base.reset_gpio) {
839 gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);
843 gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 1);
855 /* Undo pm_runtime_force_suspend() before re-enabling the irq */
857 if (cs35l56->base.irq)
858 enable_irq(cs35l56->base.irq);
863 cs35l56->suspended = false;
865 if (!cs35l56->codec)
868 ret = cs35l56_is_fw_reload_needed(&cs35l56->base);
869 dev_dbg(cs35l56->base.dev, "fw_reload_needed: %d\n", ret);
871 queue_work(system_long_wq, &cs35l56->dsp_work);
873 if (cs35l56->playing)
890 * the serial-multi-instantiate driver, so lookup the node by HID
892 if (!ACPI_COMPANION(cs35l56->base.dev)) {
894 adev = acpi_dev_get_first_match_dev(hid_string, NULL, -1);
896 dev_err(cs35l56->base.dev, "Failed to find an ACPI device for %s\n",
897 dev_name(cs35l56->base.dev));
898 return -ENODEV;
900 ACPI_COMPANION_SET(cs35l56->base.dev, adev);
903 property = "cirrus,dev-index";
904 ret = device_property_count_u32(cs35l56->base.dev, property);
909 ret = -EINVAL;
914 ret = device_property_read_u32_array(cs35l56->base.dev, property, values, nval);
918 cs35l56->index = -1;
921 cs35l56->index = i;
929 if (cs35l56->index == -1) {
930 dev_dbg(cs35l56->base.dev, "No index found in %s\n", property);
931 ret = -ENODEV;
935 sub = acpi_get_subsystem_id(ACPI_HANDLE(cs35l56->base.dev));
938 dev_info(cs35l56->base.dev,
942 ret = cirrus_scodec_get_speaker_id(cs35l56->base.dev, cs35l56->index, nval, -1);
943 if (ret == -ENOENT) {
944 cs35l56->system_name = sub;
946 cs35l56->system_name = kasprintf(GFP_KERNEL, "%s-spkid%d", sub, ret);
948 if (!cs35l56->system_name)
949 return -ENOMEM;
955 cs35l56->base.reset_gpio = devm_gpiod_get_index_optional(cs35l56->base.dev,
957 cs35l56->index,
959 if (IS_ERR(cs35l56->base.reset_gpio)) {
960 ret = PTR_ERR(cs35l56->base.reset_gpio);
966 if (ret != -EBUSY)
967 return dev_err_probe(cs35l56->base.dev, ret, "Failed to get reset GPIO\n");
969 dev_info(cs35l56->base.dev, "Reset GPIO busy, assume shared reset\n");
970 cs35l56->base.reset_gpio = NULL;
976 if (ret != -ENODEV)
977 dev_err(cs35l56->base.dev, "Failed property %s: %d\n", property, ret);
986 mutex_init(&cs35l56->base.irq_lock);
987 dev_set_drvdata(cs35l56->base.dev, cs35l56);
989 INIT_WORK(&cs35l56->dsp_work, cs35l56_hda_dsp_work);
995 cs35l56->amp_name = devm_kasprintf(cs35l56->base.dev, GFP_KERNEL, "AMP%d",
996 cs35l56->index + 1);
997 if (!cs35l56->amp_name) {
998 ret = -ENOMEM;
1002 cs35l56->base.cal_index = -1;
1004 cs35l56_init_cs_dsp(&cs35l56->base, &cs35l56->cs_dsp);
1005 cs35l56->cs_dsp.client_ops = &cs35l56_hda_client_ops;
1007 if (cs35l56->base.reset_gpio) {
1008 dev_dbg(cs35l56->base.dev, "Hard reset\n");
1014 gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);
1016 gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 1);
1019 ret = cs35l56_hw_init(&cs35l56->base);
1024 cs35l56_system_reset(&cs35l56->base, false);
1025 ret = cs35l56_wait_for_firmware_boot(&cs35l56->base);
1029 regcache_cache_only(cs35l56->base.regmap, false);
1031 ret = cs35l56_set_patch(&cs35l56->base);
1035 regcache_mark_dirty(cs35l56->base.regmap);
1036 regcache_sync(cs35l56->base.regmap);
1038 /* Disable auto-hibernate so that runtime_pm has control */
1039 ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_PREVENT_AUTO_HIBERNATE);
1043 ret = cs35l56_get_calibration(&cs35l56->base);
1047 ret = cs_dsp_halo_init(&cs35l56->cs_dsp);
1049 dev_err_probe(cs35l56->base.dev, ret, "cs_dsp_halo_init failed\n");
1053 dev_info(cs35l56->base.dev, "DSP system name: '%s', amp name: '%s'\n",
1054 cs35l56->system_name, cs35l56->amp_name);
1056 regmap_multi_reg_write(cs35l56->base.regmap, cs35l56_hda_dai_config,
1063 cs35l56->asp_tx_mask = BIT(cs35l56->index);
1065 pm_runtime_set_autosuspend_delay(cs35l56->base.dev, 3000);
1066 pm_runtime_use_autosuspend(cs35l56->base.dev);
1067 pm_runtime_set_active(cs35l56->base.dev);
1068 pm_runtime_mark_last_busy(cs35l56->base.dev);
1069 pm_runtime_enable(cs35l56->base.dev);
1071 cs35l56->base.init_done = true;
1073 ret = component_add(cs35l56->base.dev, &cs35l56_hda_comp_ops);
1075 dev_err(cs35l56->base.dev, "Register component failed: %d\n", ret);
1082 pm_runtime_disable(cs35l56->base.dev);
1083 cs_dsp_remove(&cs35l56->cs_dsp);
1085 gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);
1095 component_del(cs35l56->base.dev, &cs35l56_hda_comp_ops);
1097 pm_runtime_dont_use_autosuspend(cs35l56->base.dev);
1098 pm_runtime_get_sync(cs35l56->base.dev);
1099 pm_runtime_disable(cs35l56->base.dev);
1101 cs_dsp_remove(&cs35l56->cs_dsp);
1103 kfree(cs35l56->system_name);
1104 pm_runtime_put_noidle(cs35l56->base.dev);
1106 gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);