Lines Matching +full:e +full:- +full:book

1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright 2024 - 2025 Texas Instruments, Inc.
32 #include <sound/tas2781-tlv.h>
73 .reg_shift = -1,
86 * In our TAS2781 SPI mode, if read from other book (not book 0), in tasdevice_spi_dev_read()
87 * or read from page number larger than 1 in book 0, one more byte in tasdevice_spi_dev_read()
100 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_spi_dev_read()
112 * In our TAS2781 SPI mode, if read from other book (not book 0), in tasdevice_spi_dev_bulk_read()
113 * or read from page number larger than 1 in book 0, one more byte in tasdevice_spi_dev_bulk_read()
126 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_spi_dev_bulk_read()
143 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_spi_dev_update_bits()
150 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_spi_dev_update_bits()
156 unsigned short chn, int book) in tasdevice_spi_change_chn_book() argument
160 if (chn == p->index) { in tasdevice_spi_change_chn_book()
161 struct tasdevice *tasdev = &p->tasdevice[chn]; in tasdevice_spi_change_chn_book()
162 struct regmap *map = p->regmap; in tasdevice_spi_change_chn_book()
164 if (tasdev->cur_book != book) { in tasdevice_spi_change_chn_book()
165 ret = regmap_write(map, TASDEVICE_BOOKCTL_REG, book); in tasdevice_spi_change_chn_book()
167 dev_err(p->dev, "%s, E=%d\n", __func__, ret); in tasdevice_spi_change_chn_book()
169 tasdev->cur_book = book; in tasdevice_spi_change_chn_book()
172 ret = -EXDEV; in tasdevice_spi_change_chn_book()
173 dev_dbg(p->dev, "Not error, %s ignore channel(%d)\n", in tasdevice_spi_change_chn_book()
184 if (tas_dev->reset) { in tas2781_spi_reset()
185 gpiod_set_value_cansleep(tas_dev->reset, 0); in tas2781_spi_reset()
187 gpiod_set_value_cansleep(tas_dev->reset, 1); in tas2781_spi_reset()
189 ret = tasdevice_dev_write(tas_dev, tas_dev->index, in tas2781_spi_reset()
192 dev_err(tas_dev->dev, "dev sw-reset fail, %d\n", ret); in tas2781_spi_reset()
209 guard(mutex)(&tas_priv->codec_lock); in tascodec_spi_init()
211 scnprintf(tas_priv->rca_binaryname, in tascodec_spi_init()
212 sizeof(tas_priv->rca_binaryname), "%sRCA%d.bin", in tascodec_spi_init()
213 tas_priv->dev_name, tas_priv->ndev); in tascodec_spi_init()
214 crc8_populate_msb(tas_priv->crc8_lkp_tbl, TASDEVICE_CRC8_POLYNOMIAL); in tascodec_spi_init()
215 tas_priv->codec = codec; in tascodec_spi_init()
217 tas_priv->rca_binaryname, tas_priv->dev, GFP_KERNEL, tas_priv, in tascodec_spi_init()
220 dev_err(tas_priv->dev, "request_firmware_nowait err:0x%08x\n", in tascodec_spi_init()
228 tas_priv->tasdevice[tas_priv->index].cur_book = -1; in tasdevice_spi_init()
229 tas_priv->tasdevice[tas_priv->index].cur_conf = -1; in tasdevice_spi_init()
230 tas_priv->tasdevice[tas_priv->index].cur_prog = -1; in tasdevice_spi_init()
232 tas_priv->isspi = true; in tasdevice_spi_init()
234 tas_priv->update_bits = tasdevice_spi_dev_update_bits; in tasdevice_spi_init()
235 tas_priv->change_chn_book = tasdevice_spi_change_chn_book; in tasdevice_spi_init()
236 tas_priv->dev_read = tasdevice_spi_dev_read; in tasdevice_spi_init()
237 tas_priv->dev_bulk_read = tasdevice_spi_dev_bulk_read; in tasdevice_spi_init()
239 mutex_init(&tas_priv->codec_lock); in tasdevice_spi_init()
245 unsigned int invert = mc->invert; in tasdevice_spi_amp_putvol()
247 int max = mc->max; in tasdevice_spi_amp_putvol()
251 mask <<= mc->shift; in tasdevice_spi_amp_putvol()
252 val = clamp(invert ? max - ucontrol->value.integer.value[0] : in tasdevice_spi_amp_putvol()
253 ucontrol->value.integer.value[0], 0, max); in tasdevice_spi_amp_putvol()
255 ret = tasdevice_spi_dev_update_bits(tas_priv, tas_priv->index, in tasdevice_spi_amp_putvol()
256 mc->reg, mask, (unsigned int)(val << mc->shift)); in tasdevice_spi_amp_putvol()
258 dev_err(tas_priv->dev, "set AMP vol error in dev %d\n", in tasdevice_spi_amp_putvol()
259 tas_priv->index); in tasdevice_spi_amp_putvol()
267 unsigned int invert = mc->invert; in tasdevice_spi_amp_getvol()
269 int max = mc->max; in tasdevice_spi_amp_getvol()
272 ret = tasdevice_spi_dev_read(tas_priv, tas_priv->index, mc->reg, &val); in tasdevice_spi_amp_getvol()
274 dev_err(tas_priv->dev, "%s, get AMP vol error\n", __func__); in tasdevice_spi_amp_getvol()
279 mask <<= mc->shift; in tasdevice_spi_amp_getvol()
280 val = (val & mask) >> mc->shift; in tasdevice_spi_amp_getvol()
281 val = clamp(invert ? max - val : val, 0, max); in tasdevice_spi_amp_getvol()
282 ucontrol->value.integer.value[0] = val; in tasdevice_spi_amp_getvol()
290 unsigned int invert = mc->invert; in tasdevice_spi_digital_putvol()
291 int max = mc->max; in tasdevice_spi_digital_putvol()
294 val = clamp(invert ? max - ucontrol->value.integer.value[0] : in tasdevice_spi_digital_putvol()
295 ucontrol->value.integer.value[0], 0, max); in tasdevice_spi_digital_putvol()
296 ret = tasdevice_dev_write(p, p->index, mc->reg, (unsigned int)val); in tasdevice_spi_digital_putvol()
298 dev_err(p->dev, "set digital vol err in dev %d\n", p->index); in tasdevice_spi_digital_putvol()
306 unsigned int invert = mc->invert; in tasdevice_spi_digital_getvol()
307 int max = mc->max; in tasdevice_spi_digital_getvol()
310 ret = tasdevice_spi_dev_read(p, p->index, mc->reg, &val); in tasdevice_spi_digital_getvol()
312 dev_err(p->dev, "%s, get digital vol err\n", __func__); in tasdevice_spi_digital_getvol()
316 val = clamp(invert ? max - val : val, 0, max); in tasdevice_spi_digital_getvol()
317 ucontrol->value.integer.value[0] = val; in tasdevice_spi_digital_getvol()
325 struct tasdevice_priv *p = tas_hda->priv; in tas2781_read_acpi()
333 adev = acpi_dev_get_first_match_dev(hid, NULL, -1); in tas2781_read_acpi()
335 dev_err(p->dev, "Failed to find ACPI device: %s\n", hid); in tas2781_read_acpi()
336 return -ENODEV; in tas2781_read_acpi()
339 strscpy(p->dev_name, hid, sizeof(p->dev_name)); in tas2781_read_acpi()
343 property = "ti,dev-index"; in tas2781_read_acpi()
346 ret = -EINVAL; in tas2781_read_acpi()
349 p->ndev = nval = ret; in tas2781_read_acpi()
355 p->index = U8_MAX; in tas2781_read_acpi()
358 p->index = i; in tas2781_read_acpi()
362 if (p->index == U8_MAX) { in tas2781_read_acpi()
363 dev_dbg(p->dev, "No index found in %s\n", property); in tas2781_read_acpi()
364 ret = -ENODEV; in tas2781_read_acpi()
368 if (p->index == 0) { in tas2781_read_acpi()
370 p->reset = devm_gpiod_get_index_optional(physdev, "reset", in tas2781_read_acpi()
371 p->index, GPIOD_OUT_LOW); in tas2781_read_acpi()
372 if (IS_ERR(p->reset)) { in tas2781_read_acpi()
373 ret = PTR_ERR(p->reset); in tas2781_read_acpi()
374 dev_err_probe(p->dev, ret, "Failed on reset GPIO\n"); in tas2781_read_acpi()
382 dev_err(p->dev, "read acpi error, ret: %d\n", ret); in tas2781_read_acpi()
392 struct tasdevice_priv *tas_priv = tas_hda->priv; in tas2781_hda_playback_hook()
396 guard(mutex)(&tas_priv->codec_lock); in tas2781_hda_playback_hook()
397 if (tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK) in tas2781_hda_playback_hook()
398 tasdevice_tuning_switch(tas_hda->priv, 0); in tas2781_hda_playback_hook()
400 guard(mutex)(&tas_priv->codec_lock); in tas2781_hda_playback_hook()
401 if (tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK) in tas2781_hda_playback_hook()
408 * tas2781_digital_getvol - get the volum control
414 * tas2781 contains book and page two-level register map, especially
415 * book switching will set the register BXXP00R7F, after switching to the
416 * correct book, then leverage the mechanism for paging to access the
426 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_digital_getvol()
428 guard(mutex)(&tas_priv->codec_lock); in tas2781_digital_getvol()
437 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_amp_getvol()
439 guard(mutex)(&tas_priv->codec_lock); in tas2781_amp_getvol()
448 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_digital_putvol()
450 guard(mutex)(&tas_priv->codec_lock); in tas2781_digital_putvol()
459 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_amp_putvol()
461 guard(mutex)(&tas_priv->codec_lock); in tas2781_amp_putvol()
470 ucontrol->value.integer.value[0] = (int)tas_priv->force_fwload_status; in tas2781_force_fwload_get()
471 dev_dbg(tas_priv->dev, "%s : Force FWload %s\n", __func__, in tas2781_force_fwload_get()
472 str_on_off(tas_priv->force_fwload_status)); in tas2781_force_fwload_get()
481 bool change, val = (bool)ucontrol->value.integer.value[0]; in tas2781_force_fwload_put()
483 if (tas_priv->force_fwload_status == val) { in tas2781_force_fwload_put()
487 tas_priv->force_fwload_status = val; in tas2781_force_fwload_put()
489 dev_dbg(tas_priv->dev, "%s : Force FWload %s\n", __func__, in tas2781_force_fwload_put()
490 str_on_off(tas_priv->force_fwload_status)); in tas2781_force_fwload_put()
532 struct hda_codec *codec = tas_hda->priv->codec; in tas2781_hda_remove_controls()
533 struct tas2781_hda_spi_priv *h_priv = tas_hda->hda_priv; in tas2781_hda_remove_controls()
535 snd_ctl_remove(codec->card, tas_hda->dsp_prog_ctl); in tas2781_hda_remove_controls()
537 snd_ctl_remove(codec->card, tas_hda->dsp_conf_ctl); in tas2781_hda_remove_controls()
539 for (int i = ARRAY_SIZE(h_priv->snd_ctls) - 1; i >= 0; i--) in tas2781_hda_remove_controls()
540 snd_ctl_remove(codec->card, h_priv->snd_ctls[i]); in tas2781_hda_remove_controls()
542 snd_ctl_remove(codec->card, tas_hda->prof_ctl); in tas2781_hda_remove_controls()
547 struct tasdevice_priv *p = h->priv; in tas2781_hda_spi_prf_ctl()
548 struct hda_codec *c = p->codec; in tas2781_hda_spi_prf_ctl()
552 snprintf(name, sizeof(name), "Speaker-%d Profile Id", p->index); in tas2781_hda_spi_prf_ctl()
554 h->prof_ctl = snd_ctl_new1(&tas2781_prof_ctl, p); in tas2781_hda_spi_prf_ctl()
555 rc = snd_ctl_add(c->card, h->prof_ctl); in tas2781_hda_spi_prf_ctl()
557 dev_err(p->dev, "Failed to add KControl: %s, rc = %d\n", in tas2781_hda_spi_prf_ctl()
564 struct tas2781_hda_spi_priv *h_priv = h->hda_priv; in tas2781_hda_spi_snd_ctls()
565 struct tasdevice_priv *p = h->priv; in tas2781_hda_spi_snd_ctls()
566 struct hda_codec *c = p->codec; in tas2781_hda_spi_snd_ctls()
571 snprintf(name, sizeof(name), "Speaker-%d Analog Volume", p->index); in tas2781_hda_spi_snd_ctls()
573 h_priv->snd_ctls[i] = snd_ctl_new1(&tas2781_snd_ctls[i], p); in tas2781_hda_spi_snd_ctls()
574 rc = snd_ctl_add(c->card, h_priv->snd_ctls[i]); in tas2781_hda_spi_snd_ctls()
576 dev_err(p->dev, "Failed to add KControl: %s, rc = %d\n", in tas2781_hda_spi_snd_ctls()
581 snprintf(name, sizeof(name), "Speaker-%d Digital Volume", p->index); in tas2781_hda_spi_snd_ctls()
583 h_priv->snd_ctls[i] = snd_ctl_new1(&tas2781_snd_ctls[i], p); in tas2781_hda_spi_snd_ctls()
584 rc = snd_ctl_add(c->card, h_priv->snd_ctls[i]); in tas2781_hda_spi_snd_ctls()
586 dev_err(p->dev, "Failed to add KControl: %s, rc = %d\n", in tas2781_hda_spi_snd_ctls()
591 snprintf(name, sizeof(name), "Froce Speaker-%d FW Load", p->index); in tas2781_hda_spi_snd_ctls()
593 h_priv->snd_ctls[i] = snd_ctl_new1(&tas2781_snd_ctls[i], p); in tas2781_hda_spi_snd_ctls()
594 rc = snd_ctl_add(c->card, h_priv->snd_ctls[i]); in tas2781_hda_spi_snd_ctls()
596 dev_err(p->dev, "Failed to add KControl: %s, rc = %d\n", in tas2781_hda_spi_snd_ctls()
604 struct tasdevice_priv *p = h->priv; in tas2781_hda_spi_dsp_ctls()
605 struct hda_codec *c = p->codec; in tas2781_hda_spi_dsp_ctls()
610 snprintf(name, sizeof(name), "Speaker-%d Program Id", p->index); in tas2781_hda_spi_dsp_ctls()
612 h->dsp_prog_ctl = snd_ctl_new1(&tas2781_dsp_ctls[i], p); in tas2781_hda_spi_dsp_ctls()
613 rc = snd_ctl_add(c->card, h->dsp_prog_ctl); in tas2781_hda_spi_dsp_ctls()
615 dev_err(p->dev, "Failed to add KControl: %s, rc = %d\n", in tas2781_hda_spi_dsp_ctls()
620 snprintf(name, sizeof(name), "Speaker-%d Config Id", p->index); in tas2781_hda_spi_dsp_ctls()
622 h->dsp_conf_ctl = snd_ctl_new1(&tas2781_dsp_ctls[i], p); in tas2781_hda_spi_dsp_ctls()
623 rc = snd_ctl_add(c->card, h->dsp_conf_ctl); in tas2781_hda_spi_dsp_ctls()
625 dev_err(p->dev, "Failed to add KControl: %s, rc = %d\n", in tas2781_hda_spi_dsp_ctls()
635 struct tas2781_hda *tas_hda = dev_get_drvdata(tas_priv->dev); in tasdev_fw_ready()
636 struct hda_codec *codec = tas_priv->codec; in tasdev_fw_ready()
639 pm_runtime_get_sync(tas_priv->dev); in tasdev_fw_ready()
640 guard(mutex)(&tas_priv->codec_lock); in tasdev_fw_ready()
657 tas_priv->fw_state = TASDEVICE_DSP_FW_PENDING; in tasdev_fw_ready()
658 scnprintf(tas_priv->coef_binaryname, 64, "TAS2XXX%04X-%01d.bin", in tasdev_fw_ready()
659 lower_16_bits(codec->core.subsystem_id), tas_priv->index); in tasdev_fw_ready()
662 dev_err(tas_priv->dev, "dspfw load %s error\n", in tasdev_fw_ready()
663 tas_priv->coef_binaryname); in tasdev_fw_ready()
664 tas_priv->fw_state = TASDEVICE_DSP_FW_FAIL; in tasdev_fw_ready()
673 tas_priv->rcabin.profile_cfg_id = 0; in tasdev_fw_ready()
675 tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK; in tasdev_fw_ready()
676 ret = tasdevice_spi_dev_read(tas_priv, tas_priv->index, in tasdev_fw_ready()
684 dev_err(tas_priv->dev, "FW download failed = %d\n", in tasdev_fw_ready()
688 tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK; in tasdev_fw_ready()
690 if (tas_priv->fmw->nr_programs > 0) in tasdev_fw_ready()
691 tas_priv->tasdevice[tas_priv->index].cur_prog = 0; in tasdev_fw_ready()
692 if (tas_priv->fmw->nr_configurations > 0) in tasdev_fw_ready()
693 tas_priv->tasdevice[tas_priv->index].cur_conf = 0; in tasdev_fw_ready()
702 pm_runtime_put_autosuspend(tas_hda->priv->dev); in tasdev_fw_ready()
714 comp = hda_component_from_index(parent, tas_hda->priv->index); in tas2781_hda_bind()
716 return -EINVAL; in tas2781_hda_bind()
718 if (comp->dev) in tas2781_hda_bind()
719 return -EBUSY; in tas2781_hda_bind()
721 codec = parent->codec; in tas2781_hda_bind()
725 comp->dev = dev; in tas2781_hda_bind()
727 strscpy(comp->name, dev_name(dev), sizeof(comp->name)); in tas2781_hda_bind()
729 ret = tascodec_spi_init(tas_hda->priv, codec, THIS_MODULE, in tas2781_hda_bind()
732 comp->playback_hook = tas2781_hda_playback_hook; in tas2781_hda_bind()
744 struct tasdevice_priv *tas_priv = tas_hda->priv; in tas2781_hda_unbind()
747 comp = hda_component_from_index(parent, tas_priv->index); in tas2781_hda_unbind()
748 if (comp && (comp->dev == dev)) { in tas2781_hda_unbind()
749 comp->dev = NULL; in tas2781_hda_unbind()
750 memset(comp->name, 0, sizeof(comp->name)); in tas2781_hda_unbind()
751 comp->playback_hook = NULL; in tas2781_hda_unbind()
759 tas_hda->priv->fw_state = TASDEVICE_DSP_FW_PENDING; in tas2781_hda_unbind()
775 tas_hda = devm_kzalloc(&spi->dev, sizeof(*tas_hda), GFP_KERNEL); in tas2781_hda_spi_probe()
777 return -ENOMEM; in tas2781_hda_spi_probe()
779 hda_priv = devm_kzalloc(&spi->dev, sizeof(*hda_priv), GFP_KERNEL); in tas2781_hda_spi_probe()
781 return -ENOMEM; in tas2781_hda_spi_probe()
783 tas_hda->hda_priv = hda_priv; in tas2781_hda_spi_probe()
784 spi->max_speed_hz = TAS2781_SPI_MAX_FREQ; in tas2781_hda_spi_probe()
786 tas_priv = devm_kzalloc(&spi->dev, sizeof(*tas_priv), GFP_KERNEL); in tas2781_hda_spi_probe()
788 return -ENOMEM; in tas2781_hda_spi_probe()
789 tas_priv->dev = &spi->dev; in tas2781_hda_spi_probe()
790 tas_hda->priv = tas_priv; in tas2781_hda_spi_probe()
791 tas_priv->regmap = devm_regmap_init_spi(spi, &tasdevice_regmap); in tas2781_hda_spi_probe()
792 if (IS_ERR(tas_priv->regmap)) { in tas2781_hda_spi_probe()
793 ret = PTR_ERR(tas_priv->regmap); in tas2781_hda_spi_probe()
794 dev_err(tas_priv->dev, "Failed to allocate regmap: %d\n", in tas2781_hda_spi_probe()
798 if (strstr(dev_name(&spi->dev), "TXNW2781")) { in tas2781_hda_spi_probe()
801 dev_err(tas_priv->dev, "Unmatched spi dev %s\n", in tas2781_hda_spi_probe()
802 dev_name(&spi->dev)); in tas2781_hda_spi_probe()
803 return -ENODEV; in tas2781_hda_spi_probe()
806 tas_priv->irq = spi->irq; in tas2781_hda_spi_probe()
807 dev_set_drvdata(&spi->dev, tas_hda); in tas2781_hda_spi_probe()
811 return dev_err_probe(tas_priv->dev, ret, in tas2781_hda_spi_probe()
816 pm_runtime_set_autosuspend_delay(tas_priv->dev, 3000); in tas2781_hda_spi_probe()
817 pm_runtime_use_autosuspend(tas_priv->dev); in tas2781_hda_spi_probe()
818 pm_runtime_set_active(tas_priv->dev); in tas2781_hda_spi_probe()
819 pm_runtime_get_noresume(tas_priv->dev); in tas2781_hda_spi_probe()
820 pm_runtime_enable(tas_priv->dev); in tas2781_hda_spi_probe()
822 pm_runtime_put_autosuspend(tas_priv->dev); in tas2781_hda_spi_probe()
824 ret = component_add(tas_priv->dev, &tas2781_hda_comp_ops); in tas2781_hda_spi_probe()
826 dev_err(tas_priv->dev, "Register component fail: %d\n", ret); in tas2781_hda_spi_probe()
827 pm_runtime_disable(tas_priv->dev); in tas2781_hda_spi_probe()
828 tas2781_hda_remove(&spi->dev, &tas2781_hda_comp_ops); in tas2781_hda_spi_probe()
836 tas2781_hda_remove(&spi->dev, &tas2781_hda_comp_ops); in tas2781_hda_spi_remove()
842 struct tasdevice_priv *tas_priv = tas_hda->priv; in tas2781_runtime_suspend()
844 guard(mutex)(&tas_priv->codec_lock); in tas2781_runtime_suspend()
846 if (tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK in tas2781_runtime_suspend()
847 && tas_priv->playback_started) in tas2781_runtime_suspend()
850 tas_priv->tasdevice[tas_priv->index].cur_book = -1; in tas2781_runtime_suspend()
851 tas_priv->tasdevice[tas_priv->index].cur_conf = -1; in tas2781_runtime_suspend()
859 struct tasdevice_priv *tas_priv = tas_hda->priv; in tas2781_runtime_resume()
861 guard(mutex)(&tas_priv->codec_lock); in tas2781_runtime_resume()
863 if (tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK in tas2781_runtime_resume()
864 && tas_priv->playback_started) in tas2781_runtime_resume()
873 struct tasdevice_priv *tas_priv = tas_hda->priv; in tas2781_system_suspend()
881 if (tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK in tas2781_system_suspend()
882 && tas_priv->playback_started) in tas2781_system_suspend()
891 struct tasdevice_priv *tas_priv = tas_hda->priv; in tas2781_system_resume()
898 guard(mutex)(&tas_priv->codec_lock); in tas2781_system_resume()
899 ret = tas_priv->dev_read(tas_priv, tas_priv->index, in tas2781_system_resume()
905 tas_priv->tasdevice[tas_priv->index].cur_book = -1; in tas2781_system_resume()
906 tas_priv->tasdevice[tas_priv->index].cur_conf = -1; in tas2781_system_resume()
907 tas_priv->tasdevice[tas_priv->index].cur_prog = -1; in tas2781_system_resume()
911 dev_err(tas_priv->dev, in tas2781_system_resume()
915 tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK; in tas2781_system_resume()
917 if (tas_priv->playback_started) in tas2781_system_resume()
930 { "tas2781-hda", },
942 .name = "tas2781-hda",