Lines Matching +full:calib +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright 2023 - 2024 Texas Instruments, Inc.
7 // Author: Shenghao Ding <shenghao-ding@ti.com>
26 #include <sound/tas2781-tlv.h>
104 if (tas_priv->ndev < TASDEVICE_MAX_CHANNELS &&
105 sb->slave_address != tas_priv->global_addr) {
106 tas_priv->tasdevice[tas_priv->ndev].dev_addr =
107 (unsigned int)sb->slave_address;
108 tas_priv->ndev++;
117 { "speakerid-gpios", &speakerid_gpios, 1 },
130 adev = acpi_dev_get_first_match_dev(hid, NULL, -1);
132 dev_err(p->dev,
134 return -ENODEV;
140 dev_err(p->dev, "Failed to get ACPI resource.\n");
145 dev_err(p->dev, "Failed to get SUBSYS ID.\n");
152 ret = devm_acpi_dev_add_driver_gpios(p->dev,
155 dev_err(p->dev, "Failed to add driver gpio %d.\n",
157 p->speaker_id = devm_gpiod_get(p->dev, "speakerid", GPIOD_IN);
158 if (IS_ERR(p->speaker_id)) {
159 dev_err(p->dev, "Failed to get Speaker id.\n");
160 ret = PTR_ERR(p->speaker_id);
164 p->speaker_id = NULL;
168 strscpy(p->dev_name, hid, sizeof(p->dev_name));
175 dev_err(p->dev, "read acpi error, ret: %d\n", ret);
186 dev_dbg(tas_hda->dev, "%s: action = %d\n", __func__, action);
190 mutex_lock(&tas_hda->priv->codec_lock);
191 tasdevice_tuning_switch(tas_hda->priv, 0);
192 tas_hda->priv->playback_started = true;
193 mutex_unlock(&tas_hda->priv->codec_lock);
196 mutex_lock(&tas_hda->priv->codec_lock);
197 tasdevice_tuning_switch(tas_hda->priv, 1);
198 tas_hda->priv->playback_started = false;
199 mutex_unlock(&tas_hda->priv->codec_lock);
214 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
215 uinfo->count = 1;
216 uinfo->value.integer.min = 0;
217 uinfo->value.integer.max = tas_priv->rcabin.ncfgs - 1;
227 mutex_lock(&tas_priv->codec_lock);
229 ucontrol->value.integer.value[0] = tas_priv->rcabin.profile_cfg_id;
231 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d\n",
232 __func__, kcontrol->id.name, tas_priv->rcabin.profile_cfg_id);
234 mutex_unlock(&tas_priv->codec_lock);
243 int nr_profile = ucontrol->value.integer.value[0];
244 int max = tas_priv->rcabin.ncfgs - 1;
249 mutex_lock(&tas_priv->codec_lock);
251 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d -> %d\n",
252 __func__, kcontrol->id.name,
253 tas_priv->rcabin.profile_cfg_id, val);
255 if (tas_priv->rcabin.profile_cfg_id != val) {
256 tas_priv->rcabin.profile_cfg_id = val;
260 mutex_unlock(&tas_priv->codec_lock);
269 struct tasdevice_fw *tas_fw = tas_priv->fmw;
271 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
272 uinfo->count = 1;
273 uinfo->value.integer.min = 0;
274 uinfo->value.integer.max = tas_fw->nr_programs - 1;
283 struct tasdevice_fw *tas_fw = tas_priv->fmw;
285 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
286 uinfo->count = 1;
287 uinfo->value.integer.min = 0;
288 uinfo->value.integer.max = tas_fw->nr_configurations - 1;
298 mutex_lock(&tas_priv->codec_lock);
300 ucontrol->value.integer.value[0] = tas_priv->cur_prog;
302 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d\n",
303 __func__, kcontrol->id.name, tas_priv->cur_prog);
305 mutex_unlock(&tas_priv->codec_lock);
314 struct tasdevice_fw *tas_fw = tas_priv->fmw;
315 int nr_program = ucontrol->value.integer.value[0];
316 int max = tas_fw->nr_programs - 1;
321 mutex_lock(&tas_priv->codec_lock);
323 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d -> %d\n",
324 __func__, kcontrol->id.name, tas_priv->cur_prog, val);
326 if (tas_priv->cur_prog != val) {
327 tas_priv->cur_prog = val;
331 mutex_unlock(&tas_priv->codec_lock);
341 mutex_lock(&tas_priv->codec_lock);
343 ucontrol->value.integer.value[0] = tas_priv->cur_conf;
345 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d\n",
346 __func__, kcontrol->id.name, tas_priv->cur_conf);
348 mutex_unlock(&tas_priv->codec_lock);
357 struct tasdevice_fw *tas_fw = tas_priv->fmw;
358 int nr_config = ucontrol->value.integer.value[0];
359 int max = tas_fw->nr_configurations - 1;
364 mutex_lock(&tas_priv->codec_lock);
366 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d -> %d\n",
367 __func__, kcontrol->id.name, tas_priv->cur_conf, val);
369 if (tas_priv->cur_conf != val) {
370 tas_priv->cur_conf = val;
374 mutex_unlock(&tas_priv->codec_lock);
384 (struct soc_mixer_control *)kcontrol->private_value;
387 mutex_lock(&tas_priv->codec_lock);
391 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %ld\n",
392 __func__, kcontrol->id.name, ucontrol->value.integer.value[0]);
394 mutex_unlock(&tas_priv->codec_lock);
404 (struct soc_mixer_control *)kcontrol->private_value;
407 mutex_lock(&tas_priv->codec_lock);
409 dev_dbg(tas_priv->dev, "%s: kcontrol %s: -> %ld\n",
410 __func__, kcontrol->id.name, ucontrol->value.integer.value[0]);
415 mutex_unlock(&tas_priv->codec_lock);
425 mutex_lock(&tas_priv->codec_lock);
427 ucontrol->value.integer.value[0] = (int)tas_priv->force_fwload_status;
428 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d\n",
429 __func__, kcontrol->id.name, tas_priv->force_fwload_status);
431 mutex_unlock(&tas_priv->codec_lock);
440 bool change, val = (bool)ucontrol->value.integer.value[0];
442 mutex_lock(&tas_priv->codec_lock);
444 dev_dbg(tas_priv->dev, "%s: kcontrol %s: %d -> %d\n",
445 __func__, kcontrol->id.name,
446 tas_priv->force_fwload_status, val);
448 if (tas_priv->force_fwload_status == val)
452 tas_priv->force_fwload_status = val;
455 mutex_unlock(&tas_priv->codec_lock);
498 for (int i = 0; i < tas_priv->ndev; i++) {
501 *(uint32_t *)&tas_priv->cali_data.data[offset]);
505 dev_err(tas_priv->dev,
506 "Error writing calib regs\n");
529 tas_priv->cali_data.data = devm_kzalloc(tas_priv->dev,
531 if (!tas_priv->cali_data.data)
532 return -ENOMEM;
534 for (int i = 0; i < tas_priv->ndev; ++i) {
538 &tas_priv->cali_data.data[offset]);
541 dev_warn(tas_priv->dev,
543 return -EINVAL;
549 tas_priv->cali_data.total_sz = offset;
567 for (i = 0; i < tas_priv->ndev; i++) {
570 *(uint32_t *)&tas_priv->cali_data.data[offset]);
575 dev_err(tas_priv->dev,
576 "chn %d calib %d bulk_wr err = %d\n",
593 struct tm *tm = &tas_priv->tm;
599 if (tas_priv->catlog_id == LENOVO)
603 tas_priv->cali_data.total_sz = 0;
606 &tas_priv->cali_data.total_sz, tas_priv->cali_data.data);
609 tas_priv->cali_data.data = devm_kzalloc(tas_priv->dev,
610 tas_priv->cali_data.total_sz, GFP_KERNEL);
611 if (!tas_priv->cali_data.data)
612 return -ENOMEM;
615 &tas_priv->cali_data.total_sz,
616 tas_priv->cali_data.data);
619 return -EINVAL;
621 tmp_val = (unsigned int *)tas_priv->cali_data.data;
623 crc = crc32(~0, tas_priv->cali_data.data, 84) ^ ~0;
624 dev_dbg(tas_priv->dev, "cali crc 0x%08x PK tmp_val 0x%08x\n",
629 dev_dbg(tas_priv->dev, "%4ld-%2d-%2d, %2d:%2d:%2d\n",
630 tm->tm_year, tm->tm_mon, tm->tm_mday,
631 tm->tm_hour, tm->tm_min, tm->tm_sec);
634 tas_priv->cali_data.total_sz = 0;
641 struct hda_codec *codec = tas_hda->priv->codec;
643 snd_ctl_remove(codec->card, tas_hda->dsp_prog_ctl);
644 snd_ctl_remove(codec->card, tas_hda->dsp_conf_ctl);
646 for (int i = ARRAY_SIZE(tas_hda->snd_ctls) - 1; i >= 0; i--)
647 snd_ctl_remove(codec->card, tas_hda->snd_ctls[i]);
649 snd_ctl_remove(codec->card, tas_hda->prof_ctl);
655 struct tas2781_hda *tas_hda = dev_get_drvdata(tas_priv->dev);
656 struct hda_codec *codec = tas_priv->codec;
659 pm_runtime_get_sync(tas_priv->dev);
660 mutex_lock(&tas_priv->codec_lock);
666 tas_hda->prof_ctl = snd_ctl_new1(&tas2781_prof_ctrl, tas_priv);
667 ret = snd_ctl_add(codec->card, tas_hda->prof_ctl);
669 dev_err(tas_priv->dev,
676 tas_hda->snd_ctls[i] = snd_ctl_new1(&tas2781_snd_controls[i],
678 ret = snd_ctl_add(codec->card, tas_hda->snd_ctls[i]);
680 dev_err(tas_priv->dev,
689 tas_priv->fw_state = TASDEVICE_DSP_FW_PENDING;
690 if (tas_priv->speaker_id != NULL) {
692 spk_id = gpiod_get_value(tas_priv->speaker_id);
695 dev_dbg(tas_priv->dev, "Wrong spk_id = %d\n", spk_id);
698 snprintf(tas_priv->coef_binaryname,
699 sizeof(tas_priv->coef_binaryname),
701 lower_16_bits(codec->core.subsystem_id),
704 snprintf(tas_priv->coef_binaryname,
705 sizeof(tas_priv->coef_binaryname),
707 lower_16_bits(codec->core.subsystem_id));
711 dev_err(tas_priv->dev, "dspfw load %s error\n",
712 tas_priv->coef_binaryname);
713 tas_priv->fw_state = TASDEVICE_DSP_FW_FAIL;
717 tas_hda->dsp_prog_ctl = snd_ctl_new1(&tas2781_dsp_prog_ctrl,
719 ret = snd_ctl_add(codec->card, tas_hda->dsp_prog_ctl);
721 dev_err(tas_priv->dev,
727 tas_hda->dsp_conf_ctl = snd_ctl_new1(&tas2781_dsp_conf_ctrl,
729 ret = snd_ctl_add(codec->card, tas_hda->dsp_conf_ctl);
731 dev_err(tas_priv->dev,
737 tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK;
739 if (tas_priv->fmw->nr_programs > 0)
740 tas_priv->cur_prog = 0;
741 if (tas_priv->fmw->nr_configurations > 0)
742 tas_priv->cur_conf = 0;
749 tasdevice_tuning_switch(tas_hda->priv, 0);
750 tas_hda->priv->playback_started = true;
753 mutex_unlock(&tas_hda->priv->codec_lock);
756 pm_runtime_mark_last_busy(tas_hda->dev);
757 pm_runtime_put_autosuspend(tas_hda->dev);
770 comp = hda_component_from_index(parent, tas_hda->priv->index);
772 return -EINVAL;
774 if (comp->dev)
775 return -EBUSY;
777 codec = parent->codec;
778 subid = codec->core.subsystem_id >> 16;
782 tas_hda->priv->catlog_id = LENOVO;
785 tas_hda->priv->catlog_id = OTHERS;
791 comp->dev = dev;
793 strscpy(comp->name, dev_name(dev), sizeof(comp->name));
795 ret = tascodec_init(tas_hda->priv, codec, THIS_MODULE, tasdev_fw_ready);
797 comp->playback_hook = tas2781_hda_playback_hook;
812 comp = hda_component_from_index(parent, tas_hda->priv->index);
813 if (comp && (comp->dev == dev)) {
814 comp->dev = NULL;
815 memset(comp->name, 0, sizeof(comp->name));
816 comp->playback_hook = NULL;
821 tasdevice_config_info_remove(tas_hda->priv);
822 tasdevice_dsp_remove(tas_hda->priv);
824 tas_hda->priv->fw_state = TASDEVICE_DSP_FW_PENDING;
836 component_del(tas_hda->dev, &tas2781_hda_comp_ops);
838 pm_runtime_get_sync(tas_hda->dev);
839 pm_runtime_disable(tas_hda->dev);
841 pm_runtime_put_noidle(tas_hda->dev);
843 tasdevice_remove(tas_hda->priv);
853 tas_hda = devm_kzalloc(&clt->dev, sizeof(*tas_hda), GFP_KERNEL);
855 return -ENOMEM;
857 dev_set_drvdata(&clt->dev, tas_hda);
858 tas_hda->dev = &clt->dev;
860 tas_hda->priv = tasdevice_kzalloc(clt);
861 if (!tas_hda->priv)
862 return -ENOMEM;
864 if (strstr(dev_name(&clt->dev), "TIAS2781")) {
866 tas_hda->priv->save_calibration = tas2781_save_calibration;
867 tas_hda->priv->apply_calibration = tas2781_apply_calib;
868 tas_hda->priv->global_addr = TAS2781_GLOBAL_ADDR;
869 } else if (strstr(dev_name(&clt->dev), "INT8866")) {
871 tas_hda->priv->save_calibration = tas2563_save_calibration;
872 tas_hda->priv->apply_calibration = tas2563_apply_calib;
873 tas_hda->priv->global_addr = TAS2563_GLOBAL_ADDR;
875 return -ENODEV;
877 tas_hda->priv->irq = clt->irq;
878 ret = tas2781_read_acpi(tas_hda->priv, device_name);
880 return dev_err_probe(tas_hda->dev, ret,
883 ret = tasdevice_init(tas_hda->priv);
887 pm_runtime_set_autosuspend_delay(tas_hda->dev, 3000);
888 pm_runtime_use_autosuspend(tas_hda->dev);
889 pm_runtime_mark_last_busy(tas_hda->dev);
890 pm_runtime_set_active(tas_hda->dev);
891 pm_runtime_enable(tas_hda->dev);
893 tasdevice_reset(tas_hda->priv);
895 ret = component_add(tas_hda->dev, &tas2781_hda_comp_ops);
897 dev_err(tas_hda->dev, "Register component failed: %d\n", ret);
898 pm_runtime_disable(tas_hda->dev);
903 tas2781_hda_remove(&clt->dev);
909 tas2781_hda_remove(&clt->dev);
916 dev_dbg(tas_hda->dev, "Runtime Suspend\n");
918 mutex_lock(&tas_hda->priv->codec_lock);
923 if (tas_hda->priv->playback_started) {
924 tasdevice_tuning_switch(tas_hda->priv, 1);
925 tas_hda->priv->playback_started = false;
928 mutex_unlock(&tas_hda->priv->codec_lock);
937 dev_dbg(tas_hda->dev, "Runtime Resume\n");
939 mutex_lock(&tas_hda->priv->codec_lock);
941 tasdevice_prmg_load(tas_hda->priv, tas_hda->priv->cur_prog);
946 tasdevice_apply_calibration(tas_hda->priv);
948 mutex_unlock(&tas_hda->priv->codec_lock);
957 dev_dbg(tas_hda->priv->dev, "System Suspend\n");
959 mutex_lock(&tas_hda->priv->codec_lock);
962 if (tas_hda->priv->playback_started)
963 tasdevice_tuning_switch(tas_hda->priv, 1);
965 mutex_unlock(&tas_hda->priv->codec_lock);
979 dev_dbg(tas_hda->priv->dev, "System Resume\n");
981 mutex_lock(&tas_hda->priv->codec_lock);
983 for (i = 0; i < tas_hda->priv->ndev; i++) {
984 tas_hda->priv->tasdevice[i].cur_book = -1;
985 tas_hda->priv->tasdevice[i].cur_prog = -1;
986 tas_hda->priv->tasdevice[i].cur_conf = -1;
988 tasdevice_reset(tas_hda->priv);
989 tasdevice_prmg_load(tas_hda->priv, tas_hda->priv->cur_prog);
994 tasdevice_apply_calibration(tas_hda->priv);
996 if (tas_hda->priv->playback_started)
997 tasdevice_tuning_switch(tas_hda->priv, 0);
999 mutex_unlock(&tas_hda->priv->codec_lock);
1010 { "tas2781-hda" },
1023 .name = "tas2781-hda",
1034 MODULE_AUTHOR("Shenghao Ding, TI, <shenghao-ding@ti.com>");