Lines Matching +full:multiple +full:- +full:amp

1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright (C) 2022 - 2025 Texas Instruments Incorporated
9 // algo coefficient setting for one, two, or even multiple
12 // Author: Shenghao Ding <shenghao-ding@ti.com>
13 // Author: Kevin Lu <kevin-lu@ti.com>
31 #include <sound/tas2781-comlib-i2c.h>
33 #include <sound/tas2x20-tlv.h>
34 #include <sound/tas2563-tlv.h>
35 #include <sound/tas2781-tlv.h>
36 #include <sound/tas5825-tlv.h>
153 * tas2781_digital_getvol - get the volum control
158 * tas2781 contains book and page two-level register map, especially
169 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_digital_getvol()
180 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_digital_putvol()
191 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_amp_getvol()
203 (struct soc_mixer_control *)kcontrol->private_value; in tas2781_amp_putvol()
215 ucontrol->value.integer.value[0] = (int)tas_priv->force_fwload_status; in tasdev_force_fwload_get()
216 dev_dbg(tas_priv->dev, "%s : Force FWload %s\n", __func__, in tasdev_force_fwload_get()
217 tas_priv->force_fwload_status ? "ON" : "OFF"); in tasdev_force_fwload_get()
228 bool change, val = (bool)ucontrol->value.integer.value[0]; in tasdev_force_fwload_put()
230 if (tas_priv->force_fwload_status == val) in tasdev_force_fwload_put()
234 tas_priv->force_fwload_status = val; in tasdev_force_fwload_put()
236 dev_dbg(tas_priv->dev, "%s : Force FWload %s\n", __func__, in tasdev_force_fwload_put()
237 tas_priv->force_fwload_status ? "ON" : "OFF"); in tasdev_force_fwload_put()
248 (struct soc_bytes_ext *) kcontrol->private_value; in tasdev_cali_data_get()
249 struct calidata *cali_data = &priv->cali_data; in tasdev_cali_data_get()
250 struct cali_reg *p = &cali_data->cali_reg_array; in tasdev_cali_data_get()
251 unsigned char *dst = ucontrol->value.bytes.data; in tasdev_cali_data_get()
252 unsigned char *data = cali_data->data; in tasdev_cali_data_get()
257 guard(mutex)(&priv->codec_lock); in tasdev_cali_data_get()
258 if (!priv->is_user_space_calidata) in tasdev_cali_data_get()
259 return -1; in tasdev_cali_data_get()
261 if (!p->r0_reg) in tasdev_cali_data_get()
262 return -1; in tasdev_cali_data_get()
264 dst[i++] = bytes_ext->max; in tasdev_cali_data_get()
267 dst[i++] = TASDEVICE_BOOK_ID(p->r0_reg); in tasdev_cali_data_get()
268 dst[i++] = TASDEVICE_PAGE_ID(p->r0_reg); in tasdev_cali_data_get()
269 dst[i++] = TASDEVICE_PAGE_REG(p->r0_reg); in tasdev_cali_data_get()
271 dst[i++] = TASDEVICE_BOOK_ID(p->r0_low_reg); in tasdev_cali_data_get()
272 dst[i++] = TASDEVICE_PAGE_ID(p->r0_low_reg); in tasdev_cali_data_get()
273 dst[i++] = TASDEVICE_PAGE_REG(p->r0_low_reg); in tasdev_cali_data_get()
275 dst[i++] = TASDEVICE_BOOK_ID(p->invr0_reg); in tasdev_cali_data_get()
276 dst[i++] = TASDEVICE_PAGE_ID(p->invr0_reg); in tasdev_cali_data_get()
277 dst[i++] = TASDEVICE_PAGE_REG(p->invr0_reg); in tasdev_cali_data_get()
279 dst[i++] = TASDEVICE_BOOK_ID(p->pow_reg); in tasdev_cali_data_get()
280 dst[i++] = TASDEVICE_PAGE_ID(p->pow_reg); in tasdev_cali_data_get()
281 dst[i++] = TASDEVICE_PAGE_REG(p->pow_reg); in tasdev_cali_data_get()
283 dst[i++] = TASDEVICE_BOOK_ID(p->tlimit_reg); in tasdev_cali_data_get()
284 dst[i++] = TASDEVICE_PAGE_ID(p->tlimit_reg); in tasdev_cali_data_get()
285 dst[i++] = TASDEVICE_PAGE_REG(p->tlimit_reg); in tasdev_cali_data_get()
287 for (j = 0, k = 0; j < priv->ndev; j++) { in tasdev_cali_data_get()
292 dev_err(priv->dev, "chn %d device %u not match\n", in tasdev_cali_data_get()
297 rc = tasdevice_dev_bulk_read(priv, j, p->r0_reg, &dst[i], 4); in tasdev_cali_data_get()
299 dev_err(priv->dev, "chn %d r0_reg bulk_rd err = %d\n", in tasdev_cali_data_get()
307 dev_dbg(priv->dev, "chn %d r0_data is not same\n", j); in tasdev_cali_data_get()
310 rc = tasdevice_dev_bulk_read(priv, j, p->r0_low_reg, in tasdev_cali_data_get()
313 dev_err(priv->dev, "chn %d r0_low bulk_rd err = %d\n", in tasdev_cali_data_get()
321 dev_dbg(priv->dev, "chn %d r0_low is not same\n", j); in tasdev_cali_data_get()
324 rc = tasdevice_dev_bulk_read(priv, j, p->invr0_reg, in tasdev_cali_data_get()
327 dev_err(priv->dev, "chn %d invr0 bulk_rd err = %d\n", in tasdev_cali_data_get()
335 dev_dbg(priv->dev, "chn %d invr0 is not same\n", j); in tasdev_cali_data_get()
338 rc = tasdevice_dev_bulk_read(priv, j, p->pow_reg, &dst[i], 4); in tasdev_cali_data_get()
340 dev_err(priv->dev, "chn %d pow_reg bulk_rd err = %d\n", in tasdev_cali_data_get()
348 dev_dbg(priv->dev, "chn %d pow_reg is not same\n", j); in tasdev_cali_data_get()
351 rc = tasdevice_dev_bulk_read(priv, j, p->tlimit_reg, in tasdev_cali_data_get()
354 dev_err(priv->dev, "chn %d tlimit bulk_rd err = %d\n", in tasdev_cali_data_get()
359 dev_dbg(priv->dev, "chn %d tlimit is not same\n", j); in tasdev_cali_data_get()
369 struct i2c_client *clt = (struct i2c_client *)tas_priv->client; in calib_data_get()
370 struct tasdevice *tasdev = tas_priv->tasdevice; in calib_data_get()
371 int rc = -1; in calib_data_get()
374 for (i = 0; i < tas_priv->ndev; i++) { in calib_data_get()
375 if (clt->addr == tasdev[i].dev_addr) { in calib_data_get()
406 struct tasdevice *tasdev = tas_priv->tasdevice; in sngl_calib_start()
426 if (!tas_priv->dspbin_typ) { in sngl_calib_start()
438 if (tas_priv->dspbin_typ == TASDEV_ALPHA) in sngl_calib_start()
439 tasdevice_dev_bulk_read(tas_priv, i, t->reg, t->val, 4); in sngl_calib_start()
442 for (j = 0; j < sum - 4; j++) { in sngl_calib_start()
453 if (tas_priv->dspbin_typ == TASDEV_ALPHA) { in sngl_calib_start()
469 if (tas_priv->dspbin_typ == TASDEV_ALPHA) { in sngl_calib_start()
475 tasdevice_dev_bulk_read(tas_priv, i, t->reg, val, 4); in sngl_calib_start()
485 (struct soc_bytes_ext *) kcontrol->private_value; in tas2781_calib_start_put()
486 unsigned char *dat = ucontrol->value.bytes.data; in tas2781_calib_start_put()
490 guard(mutex)(&priv->codec_lock); in tas2781_calib_start_put()
491 if (priv->chip_id != TAS2781 || bytes_ext->max != dat[0] || in tas2781_calib_start_put()
493 dev_err(priv->dev, "%s: package fmt or chipid incorrect\n", in tas2781_calib_start_put()
504 for (i = 0; i < priv->ndev; i++) { in tas2781_calib_start_put()
508 dev_err(priv->dev, "%s:no cal-setting for dev %d\n", in tas2781_calib_start_put()
522 for (i = 0; i < priv->ndev; i++) { in tas2781_calib_stop_put()
523 struct tasdevice *tasdev = priv->tasdevice; in tas2781_calib_stop_put()
546 if (priv->dspbin_typ == TASDEV_ALPHA) in tas2781_calib_stop_put()
547 tasdevice_dev_bulk_write(priv, i, t->reg, t->val, 4); in tas2781_calib_stop_put()
560 guard(mutex)(&tas_priv->codec_lock); in tas2563_calib_start_put()
561 if (tas_priv->chip_id != TAS2563) in tas2563_calib_start_put()
562 return -1; in tas2563_calib_start_put()
564 for (i = 0; i < tas_priv->ndev; i++) { in tas2563_calib_start_put()
565 struct tasdevice *tasdev = tas_priv->tasdevice; in tas2563_calib_start_put()
598 for (i = 0; i < tas_priv->ndev; i++) { in tas2563_calib_stop_put()
599 struct tasdevice *tasdev = tas_priv->tasdevice; in tas2563_calib_stop_put()
622 guard(mutex)(&priv->codec_lock); in tasdev_calib_stop_put()
623 if (priv->chip_id == TAS2563) in tasdev_calib_stop_put()
637 (struct soc_bytes_ext *) kcontrol->private_value; in tasdev_cali_data_put()
638 struct calidata *cali_data = &priv->cali_data; in tasdev_cali_data_put()
639 struct cali_reg *p = &cali_data->cali_reg_array; in tasdev_cali_data_put()
640 unsigned char *src = ucontrol->value.bytes.data; in tasdev_cali_data_put()
641 unsigned char *dst = cali_data->data; in tasdev_cali_data_put()
645 guard(mutex)(&priv->codec_lock); in tasdev_cali_data_put()
646 if (src[0] != bytes_ext->max || src[1] != 'r') { in tasdev_cali_data_put()
647 dev_err(priv->dev, "%s: pkg fmt invalid\n", __func__); in tasdev_cali_data_put()
650 for (j = 0; j < priv->ndev; j++) { in tasdev_cali_data_put()
652 dev_err(priv->dev, "%s: pkg fmt invalid\n", __func__); in tasdev_cali_data_put()
657 priv->is_user_space_calidata = true; in tasdev_cali_data_put()
659 if (priv->dspbin_typ == TASDEV_BASIC) { in tasdev_cali_data_put()
660 p->r0_reg = TASDEVICE_REG(src[i], src[i + 1], src[i + 2]); in tasdev_cali_data_put()
662 p->r0_low_reg = TASDEVICE_REG(src[i], src[i + 1], src[i + 2]); in tasdev_cali_data_put()
664 p->invr0_reg = TASDEVICE_REG(src[i], src[i + 1], src[i + 2]); in tasdev_cali_data_put()
666 p->pow_reg = TASDEVICE_REG(src[i], src[i + 1], src[i + 2]); in tasdev_cali_data_put()
668 p->tlimit_reg = TASDEVICE_REG(src[i], src[i + 1], src[i + 2]); in tasdev_cali_data_put()
674 memcpy(dst, &src[i], cali_data->total_sz); in tasdev_cali_data_put()
683 struct i2c_client *clt = (struct i2c_client *)tas_priv->client; in tas2781_latch_reg_get()
685 (struct soc_bytes_ext *) kcontrol->private_value; in tas2781_latch_reg_get()
686 struct tasdevice *tasdev = tas_priv->tasdevice; in tas2781_latch_reg_get()
687 unsigned char *dst = ucontrol->value.bytes.data; in tas2781_latch_reg_get()
688 int i, val, rc = -1; in tas2781_latch_reg_get()
690 dst[0] = bytes_ext->max; in tas2781_latch_reg_get()
691 guard(mutex)(&tas_priv->codec_lock); in tas2781_latch_reg_get()
692 for (i = 0; i < tas_priv->ndev; i++) { in tas2781_latch_reg_get()
693 if (clt->addr == tasdev[i].dev_addr) { in tas2781_latch_reg_get()
699 dev_err(tas_priv->dev, "%s, get value error\n", in tas2781_latch_reg_get()
717 (struct soc_bytes_ext *) kcontrol->private_value; in tasdev_tf_data_get()
718 unsigned char *dst = ucontrol->value.bytes.data; in tasdev_tf_data_get()
721 if (tas_priv->chip_id == TAS2781) { in tasdev_tf_data_get()
722 struct tasdevice_fw *tas_fmw = tas_priv->fmw; in tasdev_tf_data_get()
723 struct fct_param_address *p = &(tas_fmw->fct_par_addr); in tasdev_tf_data_get()
726 if (tas_priv->dspbin_typ) in tasdev_tf_data_get()
727 reg = TASDEVICE_REG(p->tf_reg[0], p->tf_reg[1], in tasdev_tf_data_get()
728 p->tf_reg[2]); in tasdev_tf_data_get()
733 guard(mutex)(&tas_priv->codec_lock); in tasdev_tf_data_get()
734 dst[0] = bytes_ext->max; in tasdev_tf_data_get()
744 (struct soc_bytes_ext *) kcontrol->private_value; in tasdev_re_data_get()
745 unsigned char *dst = ucontrol->value.bytes.data; in tasdev_re_data_get()
748 if (tas_priv->chip_id == TAS2781) { in tasdev_re_data_get()
749 struct tasdevice_fw *tas_fmw = tas_priv->fmw; in tasdev_re_data_get()
750 struct fct_param_address *p = &(tas_fmw->fct_par_addr); in tasdev_re_data_get()
752 if (tas_priv->dspbin_typ) in tasdev_re_data_get()
753 reg = TASDEVICE_REG(p->r0_reg[0], p->r0_reg[1], in tasdev_re_data_get()
754 p->r0_reg[2]); in tasdev_re_data_get()
759 guard(mutex)(&tas_priv->codec_lock); in tasdev_re_data_get()
760 dst[0] = bytes_ext->max; in tasdev_re_data_get()
769 struct calidata *cali_data = &tas_priv->cali_data; in tasdev_r0_data_get()
771 (struct soc_bytes_ext *) kcontrol->private_value; in tasdev_r0_data_get()
772 unsigned char *dst = ucontrol->value.bytes.data; in tasdev_r0_data_get()
775 guard(mutex)(&tas_priv->codec_lock); in tasdev_r0_data_get()
777 if (tas_priv->chip_id == TAS2563) in tasdev_r0_data_get()
779 else if (cali_data->cali_reg_array.r0_reg) in tasdev_r0_data_get()
780 reg = cali_data->cali_reg_array.r0_reg; in tasdev_r0_data_get()
782 return -1; in tasdev_r0_data_get()
783 dst[0] = bytes_ext->max; in tasdev_r0_data_get()
792 struct tasdevice_fw *tas_fmw = tas_priv->fmw; in tasdev_XMA1_data_get()
793 struct fct_param_address *p = &(tas_fmw->fct_par_addr); in tasdev_XMA1_data_get()
795 (struct soc_bytes_ext *) kcontrol->private_value; in tasdev_XMA1_data_get()
796 unsigned char *dst = ucontrol->value.bytes.data; in tasdev_XMA1_data_get()
799 if (tas_priv->dspbin_typ) in tasdev_XMA1_data_get()
800 reg = TASDEVICE_REG(p->a1_reg[0], p->a1_reg[1], p->a1_reg[2]); in tasdev_XMA1_data_get()
802 guard(mutex)(&tas_priv->codec_lock); in tasdev_XMA1_data_get()
803 dst[0] = bytes_ext->max; in tasdev_XMA1_data_get()
812 struct tasdevice_fw *tas_fmw = tas_priv->fmw; in tasdev_XMA2_data_get()
813 struct fct_param_address *p = &(tas_fmw->fct_par_addr); in tasdev_XMA2_data_get()
815 (struct soc_bytes_ext *) kcontrol->private_value; in tasdev_XMA2_data_get()
816 unsigned char *dst = ucontrol->value.bytes.data; in tasdev_XMA2_data_get()
819 if (tas_priv->dspbin_typ) in tasdev_XMA2_data_get()
820 reg = TASDEVICE_REG(p->a2_reg[0], p->a2_reg[1], p->a2_reg[2]); in tasdev_XMA2_data_get()
822 guard(mutex)(&tas_priv->codec_lock); in tasdev_XMA2_data_get()
823 dst[0] = bytes_ext->max; in tasdev_XMA2_data_get()
839 (struct soc_mixer_control *)kcontrol->private_value; in tasdevice_digital_gain_get()
842 unsigned int l = 0, r = mc->max; in tasdevice_digital_gain_get()
844 unsigned int reg = mc->reg; in tasdevice_digital_gain_get()
848 mutex_lock(&tas_dev->codec_lock); in tasdevice_digital_gain_get()
852 dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__); in tasdevice_digital_gain_get()
860 ar_mid = get_unaligned_be32(tas_dev->dvc_tlv_table[mid]); in tasdevice_digital_gain_get()
867 ar_l = get_unaligned_be32(tas_dev->dvc_tlv_table[l]); in tasdevice_digital_gain_get()
868 ar_r = get_unaligned_be32(tas_dev->dvc_tlv_table[r]); in tasdevice_digital_gain_get()
871 ucontrol->value.integer.value[0] = in tasdevice_digital_gain_get()
872 abs(target - ar_l) <= abs(target - ar_r) ? l : r; in tasdevice_digital_gain_get()
874 mutex_unlock(&tas_dev->codec_lock); in tasdevice_digital_gain_get()
883 (struct soc_mixer_control *)kcontrol->private_value; in tasdevice_digital_gain_put()
886 int vol = ucontrol->value.integer.value[0]; in tasdevice_digital_gain_put()
887 int status = 0, max = mc->max, rc = 1; in tasdevice_digital_gain_put()
889 unsigned int reg = mc->reg; in tasdevice_digital_gain_put()
894 mutex_lock(&tas_dev->codec_lock); in tasdevice_digital_gain_put()
898 dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__); in tasdevice_digital_gain_put()
899 rc = -1; in tasdevice_digital_gain_put()
904 volwr = get_unaligned_be32(tas_dev->dvc_tlv_table[vol]); in tasdevice_digital_gain_put()
911 for (i = 0; i < tas_dev->ndev; i++) { in tasdevice_digital_gain_put()
913 (unsigned char *)tas_dev->dvc_tlv_table[vol], 4); in tasdevice_digital_gain_put()
915 dev_err(tas_dev->dev, in tasdevice_digital_gain_put()
923 rc = -1; in tasdevice_digital_gain_put()
925 mutex_unlock(&tas_dev->codec_lock); in tasdevice_digital_gain_put()
932 SND_SOC_BYTES_EXT("Amp TF Data", 6, tasdev_tf_data_get, NULL),
933 SND_SOC_BYTES_EXT("Amp RE Data", 6, tasdev_re_data_get, NULL),
934 SND_SOC_BYTES_EXT("Amp R0 Data", 6, tasdev_r0_data_get, NULL),
935 SND_SOC_BYTES_EXT("Amp XMA1 Data", 6, tasdev_XMA1_data_get, NULL),
936 SND_SOC_BYTES_EXT("Amp XMA2 Data", 6, tasdev_XMA2_data_get, NULL),
944 0, 0, ARRAY_SIZE(tas2x20_dvc_table) - 1, 0,
968 SND_SOC_BYTES_EXT("Amp Latch Data", 3, tas2781_latch_reg_get, NULL),
973 0, ARRAY_SIZE(tas2563_dvc_table) - 1, 0,
990 if (tas_priv->rcabin.profile_cfg_id != in tasdevice_set_profile_id()
991 ucontrol->value.integer.value[0]) { in tasdevice_set_profile_id()
992 tas_priv->rcabin.profile_cfg_id = in tasdevice_set_profile_id()
993 ucontrol->value.integer.value[0]; in tasdevice_set_profile_id()
1006 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tasdevice_info_active_num()
1007 uinfo->count = 1; in tasdevice_info_active_num()
1008 uinfo->value.integer.min = 0; in tasdevice_info_active_num()
1009 uinfo->value.integer.max = tas_priv->ndev - 1; in tasdevice_info_active_num()
1017 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tasdevice_info_chip_id()
1018 uinfo->count = 1; in tasdevice_info_chip_id()
1019 uinfo->value.integer.min = TAS2020; in tasdevice_info_chip_id()
1020 uinfo->value.integer.max = TAS_OTHERS; in tasdevice_info_chip_id()
1030 struct tasdevice_fw *tas_fw = tas_priv->fmw; in tasdevice_info_programs()
1032 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tasdevice_info_programs()
1033 uinfo->count = 1; in tasdevice_info_programs()
1034 uinfo->value.integer.min = 0; in tasdevice_info_programs()
1035 uinfo->value.integer.max = (int)tas_fw->nr_programs; in tasdevice_info_programs()
1045 struct tasdevice_fw *tas_fw = tas_priv->fmw; in tasdevice_info_configurations()
1047 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tasdevice_info_configurations()
1048 uinfo->count = 1; in tasdevice_info_configurations()
1049 uinfo->value.integer.min = 0; in tasdevice_info_configurations()
1050 uinfo->value.integer.max = (int)tas_fw->nr_configurations - 1; in tasdevice_info_configurations()
1061 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tasdevice_info_profile()
1062 uinfo->count = 1; in tasdevice_info_profile()
1063 uinfo->value.integer.min = 0; in tasdevice_info_profile()
1064 uinfo->value.integer.max = tas_priv->rcabin.ncfgs - 1; in tasdevice_info_profile()
1075 ucontrol->value.integer.value[0] = tas_priv->rcabin.profile_cfg_id; in tasdevice_get_profile_id()
1086 ucontrol->value.integer.value[0] = tas_priv->chip_id; in tasdevice_get_chip_id()
1099 prof_ctrls = devm_kcalloc(tas_priv->dev, nr_controls, in tasdevice_create_control()
1102 ret = -ENOMEM; in tasdevice_create_control()
1107 name = devm_kstrdup(tas_priv->dev, "Speaker Profile Id", GFP_KERNEL); in tasdevice_create_control()
1109 ret = -ENOMEM; in tasdevice_create_control()
1119 ret = snd_soc_add_component_controls(tas_priv->codec, in tasdevice_create_control()
1132 ucontrol->value.integer.value[0] = tas_priv->cur_prog; in tasdevice_program_get()
1142 unsigned int nr_program = ucontrol->value.integer.value[0]; in tasdevice_program_put()
1145 if (tas_priv->cur_prog != nr_program) { in tasdevice_program_put()
1146 tas_priv->cur_prog = nr_program; in tasdevice_program_put()
1160 ucontrol->value.integer.value[0] = tas_priv->cur_conf; in tasdevice_configuration_get()
1171 unsigned int nr_configuration = ucontrol->value.integer.value[0]; in tasdevice_configuration_put()
1174 if (tas_priv->cur_conf != nr_configuration) { in tasdevice_configuration_put()
1175 tas_priv->cur_conf = nr_configuration; in tasdevice_configuration_put()
1187 struct i2c_client *clt = (struct i2c_client *)tas_priv->client; in tasdevice_active_num_get()
1188 struct tasdevice *tasdev = tas_priv->tasdevice; in tasdevice_active_num_get()
1191 for (i = 0; i < tas_priv->ndev; i++) { in tasdevice_active_num_get()
1192 if (clt->addr == tasdev[i].dev_addr) { in tasdevice_active_num_get()
1193 ucontrol->value.integer.value[0] = i; in tasdevice_active_num_get()
1198 return -1; in tasdevice_active_num_get()
1206 int dev_id = ucontrol->value.integer.value[0]; in tasdevice_active_num_put()
1207 int max = tas_priv->ndev - 1; in tasdevice_active_num_put()
1211 guard(mutex)(&tas_priv->codec_lock); in tasdevice_active_num_put()
1226 dsp_ctrls = devm_kcalloc(tas_priv->dev, nr_controls, in tasdevice_dsp_create_ctrls()
1229 return -ENOMEM; in tasdevice_dsp_create_ctrls()
1232 prog_name = devm_kstrdup(tas_priv->dev, "Speaker Program Id", in tasdevice_dsp_create_ctrls()
1235 return -ENOMEM; in tasdevice_dsp_create_ctrls()
1244 conf_name = devm_kstrdup(tas_priv->dev, "Speaker Config Id", in tasdevice_dsp_create_ctrls()
1247 return -ENOMEM; in tasdevice_dsp_create_ctrls()
1256 active_dev_num = devm_kstrdup(tas_priv->dev, "Activate Tasdevice Num", in tasdevice_dsp_create_ctrls()
1259 return -ENOMEM; in tasdevice_dsp_create_ctrls()
1268 chip_id = devm_kstrdup(tas_priv->dev, "Tasdevice Chip Id", GFP_KERNEL); in tasdevice_dsp_create_ctrls()
1270 return -ENOMEM; in tasdevice_dsp_create_ctrls()
1278 fw_load = devm_kstrdup(tas_priv->dev, "Speaker Force Firmware Load", in tasdevice_dsp_create_ctrls()
1281 return -ENOMEM; in tasdevice_dsp_create_ctrls()
1291 return snd_soc_add_component_controls(tas_priv->codec, dsp_ctrls, in tasdevice_dsp_create_ctrls()
1304 reg = TASDEVICE_REG(t->thr[0], t->thr[1], t->thr[2]); in cali_reg_update()
1307 reg = TASDEVICE_REG(t->plt_flg[0], t->plt_flg[1], in cali_reg_update()
1308 t->plt_flg[2]); in cali_reg_update()
1311 reg = TASDEVICE_REG(t->sin_gn[0], t->sin_gn[1], in cali_reg_update()
1312 t->sin_gn[2]); in cali_reg_update()
1315 reg = TASDEVICE_REG(t->sin_gn[0], t->sin_gn[1], in cali_reg_update()
1316 t->sin_gn[2]); in cali_reg_update()
1330 p->is_locked = false; in alpa_cali_update()
1331 p->reg = TASDEVICE_REG(t->thr2[0], t->thr2[1], t->thr2[2]); in alpa_cali_update()
1332 p->val_len = 4; in alpa_cali_update()
1337 struct calidata *cali_data = &priv->cali_data; in tasdevice_create_cali_ctrls()
1338 struct tasdevice *tasdev = priv->tasdevice; in tasdevice_create_cali_ctrls()
1339 struct tasdevice_fw *fmw = priv->fmw; in tasdevice_create_cali_ctrls()
1346 rc = snd_soc_add_component_controls(priv->codec, in tasdevice_create_cali_ctrls()
1349 dev_err(priv->dev, "%s: Add cali controls err rc = %d", in tasdevice_create_cali_ctrls()
1354 if (priv->chip_id == TAS2781) { in tasdevice_create_cali_ctrls()
1355 struct fct_param_address *t = &(fmw->fct_par_addr); in tasdevice_create_cali_ctrls()
1359 for (i = 0; i < priv->ndev; i++) { in tasdevice_create_cali_ctrls()
1366 return -ENOMEM; in tasdevice_create_cali_ctrls()
1367 if (priv->dspbin_typ) { in tasdevice_create_cali_ctrls()
1369 if (priv->dspbin_typ == TASDEV_ALPHA) { in tasdevice_create_cali_ctrls()
1378 for (i = 0; i < priv->ndev; i++) { in tasdevice_create_cali_ctrls()
1383 return -ENOMEM; in tasdevice_create_cali_ctrls()
1387 rc = snd_soc_add_component_controls(priv->codec, cali_ctrls, nctrls); in tasdevice_create_cali_ctrls()
1389 dev_err(priv->dev, "%s: Add chip cali ctrls err rc = %d", in tasdevice_create_cali_ctrls()
1396 if (priv->chip_id == TAS2781) in tasdevice_create_cali_ctrls()
1405 cali_ctrls = devm_kcalloc(priv->dev, nctrls, in tasdevice_create_cali_ctrls()
1408 return -ENOMEM; in tasdevice_create_cali_ctrls()
1410 ext_cali_data = devm_kzalloc(priv->dev, sizeof(*ext_cali_data), in tasdevice_create_cali_ctrls()
1413 return -ENOMEM; in tasdevice_create_cali_ctrls()
1415 cali_name = devm_kstrdup(priv->dev, "Speaker Calibrated Data", in tasdevice_create_cali_ctrls()
1418 return -ENOMEM; in tasdevice_create_cali_ctrls()
1420 cali_data->cali_dat_sz_per_dev = 20; in tasdevice_create_cali_ctrls()
1426 * for (i = 0; i < Device-Sum; i++) { in tasdevice_create_cali_ctrls()
1431 ext_cali_data->max = priv->ndev * in tasdevice_create_cali_ctrls()
1432 (cali_data->cali_dat_sz_per_dev + 1) + 1 + 15 + 1; in tasdevice_create_cali_ctrls()
1433 priv->cali_data.total_sz = priv->ndev * in tasdevice_create_cali_ctrls()
1434 (cali_data->cali_dat_sz_per_dev + 1); in tasdevice_create_cali_ctrls()
1443 cali_data->data = devm_kzalloc(priv->dev, cali_data->total_sz, in tasdevice_create_cali_ctrls()
1445 if (!cali_data->data) in tasdevice_create_cali_ctrls()
1446 return -ENOMEM; in tasdevice_create_cali_ctrls()
1448 if (priv->chip_id == TAS2781) { in tasdevice_create_cali_ctrls()
1452 ext_cali_start = devm_kzalloc(priv->dev, in tasdevice_create_cali_ctrls()
1455 return -ENOMEM; in tasdevice_create_cali_ctrls()
1457 cali_start_name = devm_kstrdup(priv->dev, in tasdevice_create_cali_ctrls()
1460 return -ENOMEM; in tasdevice_create_cali_ctrls()
1467 * for (i = 0; i < Device-Sum; i++) { in tasdevice_create_cali_ctrls()
1472 ext_cali_start->max = 14 + priv->ndev * 9; in tasdevice_create_cali_ctrls()
1482 return snd_soc_add_component_controls(priv->codec, cali_ctrls, in tasdevice_create_cali_ctrls()
1508 struct snd_soc_component *comp = file->private_data; in acoustic_ctl_read()
1510 struct acoustic_data *p = &tas_priv->acou_data; in acoustic_ctl_read()
1511 int ret = -1; in acoustic_ctl_read()
1513 if (p->id == 'r' && p->len == count && count <= sizeof(*p)) in acoustic_ctl_read()
1514 ret = simple_read_from_buffer(to, count, ppos, p, p->len); in acoustic_ctl_read()
1516 dev_err(tas_priv->dev, "Not ready for get.\n"); in acoustic_ctl_read()
1523 struct snd_soc_component *comp = file->private_data; in acoustic_ctl_write()
1525 struct acoustic_data *p = &priv->acou_data; in acoustic_ctl_write()
1530 int ret = -1; in acoustic_ctl_write()
1533 dev_err(priv->dev, "count(%u) is larger than max(%u).\n", in acoustic_ctl_write()
1543 dev_err(priv->dev, "pkg(%u), max(%u), count(%u) mismatch.\n", in acoustic_ctl_write()
1556 len = src[0] - 6; in acoustic_ctl_write()
1559 dev_err(priv->dev, "%s Wrong code %02x.\n", __func__, src[1]); in acoustic_ctl_write()
1565 dev_err(priv->dev, "pkg fmt invalid %02x.\n", len); in acoustic_ctl_write()
1570 for (j = 0; j < priv->ndev; j++) in acoustic_ctl_write()
1571 if (src[2] == priv->tasdevice[j].dev_addr) { in acoustic_ctl_write()
1575 if (j >= priv->ndev) { in acoustic_ctl_write()
1576 dev_err(priv->dev, "no such device 0x%02x.\n", src[2]); in acoustic_ctl_write()
1583 guard(mutex)(&priv->codec_lock); in acoustic_ctl_write()
1592 struct acoustic_data *p = &priv->acou_data; in acoustic_ctl_write()
1597 p->data, len); in acoustic_ctl_write()
1600 p->data[0] = val; in acoustic_ctl_write()
1602 p->len = len + 6; in acoustic_ctl_write()
1606 dev_err(priv->dev, "i2c communication error.\n"); in acoustic_ctl_write()
1626 struct snd_soc_component *comp = tas_priv->codec; in tasdevice_fw_ready()
1627 struct dentry *debugfs_root = comp->debugfs_root; in tasdevice_fw_ready()
1633 mutex_lock(&tas_priv->codec_lock); in tasdevice_fw_ready()
1645 * The baseline is the RCA-only case, and then the code attempts to in tasdevice_fw_ready()
1649 tas_priv->fw_state = TASDEVICE_RCA_FW_OK; in tasdevice_fw_ready()
1651 switch (tas_priv->chip_id) { in tasdevice_fw_ready()
1662 if (tas_priv->name_prefix) in tasdevice_fw_ready()
1663 scnprintf(tas_priv->coef_binaryname, 64, "%s-%s_coef.bin", in tasdevice_fw_ready()
1664 tas_priv->name_prefix, tas_priv->dev_name); in tasdevice_fw_ready()
1666 scnprintf(tas_priv->coef_binaryname, 64, "%s_coef.bin", in tasdevice_fw_ready()
1667 tas_priv->dev_name); in tasdevice_fw_ready()
1670 dev_err(tas_priv->dev, "dspfw load %s error\n", in tasdevice_fw_ready()
1671 tas_priv->coef_binaryname); in tasdevice_fw_ready()
1676 * If no dsp-related kcontrol created, the dsp resource will be freed. in tasdevice_fw_ready()
1680 dev_err(tas_priv->dev, "dsp controls error\n"); in tasdevice_fw_ready()
1683 tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK; in tasdevice_fw_ready()
1686 if (tas_priv->chip_id < TAS5802) { in tasdevice_fw_ready()
1689 dev_err(tas_priv->dev, "cali controls error\n"); in tasdevice_fw_ready()
1695 for (i = 0; i < tas_priv->ndev; i++) { in tasdevice_fw_ready()
1696 if (tas_priv->name_prefix) in tasdevice_fw_ready()
1697 scnprintf(tas_priv->cal_binaryname[i], 64, in tasdevice_fw_ready()
1698 "%s-%s_cal_0x%02x.bin", in tasdevice_fw_ready()
1699 tas_priv->name_prefix, in tasdevice_fw_ready()
1700 tas_priv->dev_name, in tasdevice_fw_ready()
1701 tas_priv->tasdevice[i].dev_addr); in tasdevice_fw_ready()
1703 scnprintf(tas_priv->cal_binaryname[i], 64, in tasdevice_fw_ready()
1705 tas_priv->dev_name, in tasdevice_fw_ready()
1706 tas_priv->tasdevice[i].dev_addr); in tasdevice_fw_ready()
1708 tas_priv->cal_binaryname[i], i); in tasdevice_fw_ready()
1710 dev_err(tas_priv->dev, in tasdevice_fw_ready()
1712 __func__, tas_priv->cal_binaryname[i]); in tasdevice_fw_ready()
1717 tas_priv->cur_prog = 0; in tasdevice_fw_ready()
1720 if (tas_priv->rcabin.init_profile_id >= 0) in tasdevice_fw_ready()
1722 tas_priv->rcabin.init_profile_id, in tasdevice_fw_ready()
1726 if (tas_priv->name_prefix) in tasdevice_fw_ready()
1727 acoustic_debugfs_node = devm_kasprintf(tas_priv->dev, in tasdevice_fw_ready()
1728 GFP_KERNEL, "%s_acoustic_ctl", tas_priv->name_prefix); in tasdevice_fw_ready()
1730 acoustic_debugfs_node = devm_kstrdup(tas_priv->dev, in tasdevice_fw_ready()
1736 if (tas_priv->fw_state == TASDEVICE_RCA_FW_OK) { in tasdevice_fw_ready()
1737 switch (tas_priv->chip_id) { in tasdevice_fw_ready()
1753 mutex_unlock(&tas_priv->codec_lock); in tasdevice_fw_ready()
1760 struct snd_soc_component *codec = snd_soc_dapm_to_component(w->dapm); in tasdevice_dapm_event()
1765 mutex_lock(&tas_priv->codec_lock); in tasdevice_dapm_event()
1770 mutex_unlock(&tas_priv->codec_lock); in tasdevice_dapm_event()
1794 struct snd_soc_component *codec = dai->component; in tasdevice_startup()
1797 switch (tas_priv->fw_state) { in tasdevice_startup()
1802 return -EINVAL; in tasdevice_startup()
1820 dev_err(tas_priv->dev, "%s: incorrect sample rate = %u\n", in tasdevice_hw_params()
1822 return -EINVAL; in tasdevice_hw_params()
1833 dev_err(tas_priv->dev, "%s: incorrect slot width = %u\n", in tasdevice_hw_params()
1835 return -EINVAL; in tasdevice_hw_params()
1840 dev_err(tas_priv->dev, "%s: incorrect bclk rate = %d\n", in tasdevice_hw_params()
1853 tas_priv->sysclk = freq; in tasdevice_set_dai_sysclk()
1894 switch (tas_priv->chip_id) { in tasdevice_codec_probe()
1905 tas_priv->dvc_tlv_table = tas2x20_dvc_table; in tasdevice_codec_probe()
1926 tas_priv->dvc_tlv_table = tas2563_dvc_table; in tasdevice_codec_probe()
1932 dev_err(tas_priv->dev, "%s: Add control err rc = %d", in tasdevice_codec_probe()
1937 tas_priv->name_prefix = codec->name_prefix; in tasdevice_codec_probe()
1944 struct tasdevice *tasdev = tas_priv->tasdevice; in tasdevice_deinit()
1947 for (i = 0; i < tas_priv->ndev; i++) in tasdevice_deinit()
1953 tas_priv->fw_state = TASDEVICE_DSP_FW_PENDING; in tasdevice_deinit()
1977 struct i2c_client *client = (struct i2c_client *)tas_priv->client; in tasdevice_parse_dt()
1982 if (tas_priv->isacpi) { in tasdevice_parse_dt()
1983 ndev = device_property_read_u32_array(&client->dev, in tasdevice_parse_dt()
1984 "ti,audio-slots", NULL, 0); in tasdevice_parse_dt()
1987 dev_addrs[0] = client->addr; in tasdevice_parse_dt()
1991 rc = device_property_read_u32_array(&client->dev, in tasdevice_parse_dt()
1992 "ti,audio-slots", dev_addrs, ndev); in tasdevice_parse_dt()
1995 dev_addrs[0] = client->addr; in tasdevice_parse_dt()
1999 tas_priv->irq = in tasdevice_parse_dt()
2000 acpi_dev_gpio_irq_get(ACPI_COMPANION(&client->dev), 0); in tasdevice_parse_dt()
2002 struct device_node *np = tas_priv->dev->of_node; in tasdevice_parse_dt()
2011 tas_priv->irq = of_irq_get(np, 0); in tasdevice_parse_dt()
2014 dev_addrs[0] = client->addr; in tasdevice_parse_dt()
2016 tas_priv->ndev = ndev; in tasdevice_parse_dt()
2018 tas_priv->tasdevice[i].dev_addr = dev_addrs[i]; in tasdevice_parse_dt()
2020 tas_priv->reset = devm_gpiod_get_optional(&client->dev, in tasdevice_parse_dt()
2022 if (IS_ERR(tas_priv->reset)) in tasdevice_parse_dt()
2023 dev_err(tas_priv->dev, "%s Can't get reset GPIO\n", in tasdevice_parse_dt()
2026 strscpy(tas_priv->dev_name, tasdevice_id[tas_priv->chip_id].name, in tasdevice_parse_dt()
2027 sizeof(tas_priv->dev_name)); in tasdevice_parse_dt()
2038 return -ENOMEM; in tasdevice_i2c_probe()
2040 dev_set_drvdata(&i2c->dev, tas_priv); in tasdevice_i2c_probe()
2042 if (ACPI_HANDLE(&i2c->dev)) { in tasdevice_i2c_probe()
2043 acpi_id = acpi_match_device(i2c->dev.driver->acpi_match_table, in tasdevice_i2c_probe()
2044 &i2c->dev); in tasdevice_i2c_probe()
2046 dev_err(&i2c->dev, "No driver data\n"); in tasdevice_i2c_probe()
2047 ret = -EINVAL; in tasdevice_i2c_probe()
2050 tas_priv->chip_id = acpi_id->driver_data; in tasdevice_i2c_probe()
2051 tas_priv->isacpi = true; in tasdevice_i2c_probe()
2053 tas_priv->chip_id = (uintptr_t)i2c_get_match_data(i2c); in tasdevice_i2c_probe()
2054 tas_priv->isacpi = false; in tasdevice_i2c_probe()
2065 ret = devm_snd_soc_register_component(tas_priv->dev, in tasdevice_i2c_probe()
2069 dev_err(tas_priv->dev, "%s: codec register error:0x%08x\n", in tasdevice_i2c_probe()
2115 .name = "tasdev-codec",
2128 MODULE_AUTHOR("Shenghao Ding <shenghao-ding@ti.com>");
2129 MODULE_AUTHOR("Kevin Lu <kevin-lu@ti.com>");