1414#include <linux/regmap.h>
1515#include <linux/slab.h>
1616#include <sound/core.h>
17+ #include <sound/cs-amp-lib.h>
1718#include <sound/hda_codec.h>
1819#include <sound/tlv.h>
1920#include "cirrus_scodec.h"
@@ -547,6 +548,22 @@ static void cs35l56_hda_add_dsp_controls(struct cs35l56_hda *cs35l56)
547548 hda_cs_dsp_add_controls (& cs35l56 -> cs_dsp , & info );
548549}
549550
551+ static void cs35l56_hda_apply_calibration (struct cs35l56_hda * cs35l56 )
552+ {
553+ int ret ;
554+
555+ if (!cs35l56 -> base .cal_data_valid || cs35l56 -> base .secured )
556+ return ;
557+
558+ ret = cs_amp_write_cal_coeffs (& cs35l56 -> cs_dsp ,
559+ & cs35l56_calibration_controls ,
560+ & cs35l56 -> base .cal_data );
561+ if (ret < 0 )
562+ dev_warn (cs35l56 -> base .dev , "Failed to write calibration: %d\n" , ret );
563+ else
564+ dev_info (cs35l56 -> base .dev , "Calibration applied\n" );
565+ }
566+
550567static int cs35l56_hda_fw_load (struct cs35l56_hda * cs35l56 )
551568{
552569 const struct firmware * coeff_firmware = NULL ;
@@ -618,12 +635,8 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
618635 if (coeff_filename )
619636 dev_dbg (cs35l56 -> base .dev , "Loaded Coefficients: %s\n" , coeff_filename );
620637
621- if (!firmware_missing ) {
622- ret = cs35l56_mbox_send (& cs35l56 -> base , CS35L56_MBOX_CMD_AUDIO_REINIT );
623- if (ret )
624- goto err_powered_up ;
625- } else if (wmfw_firmware || coeff_firmware ) {
626- /* If we downloaded firmware, reset the device and wait for it to boot */
638+ /* If we downloaded firmware, reset the device and wait for it to boot */
639+ if (firmware_missing && (wmfw_firmware || coeff_firmware )) {
627640 cs35l56_system_reset (& cs35l56 -> base , false);
628641 regcache_mark_dirty (cs35l56 -> base .regmap );
629642 ret = cs35l56_wait_for_firmware_boot (& cs35l56 -> base );
@@ -646,6 +659,11 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
646659 if (ret )
647660 dev_dbg (cs35l56 -> base .dev , "%s: cs_dsp_run ret %d\n" , __func__ , ret );
648661
662+ cs35l56_hda_apply_calibration (cs35l56 );
663+ ret = cs35l56_mbox_send (& cs35l56 -> base , CS35L56_MBOX_CMD_AUDIO_REINIT );
664+ if (ret )
665+ cs_dsp_stop (& cs35l56 -> cs_dsp );
666+
649667err_powered_up :
650668 if (!cs35l56 -> base .fw_patched )
651669 cs_dsp_power_down (& cs35l56 -> cs_dsp );
@@ -953,6 +971,8 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id)
953971 goto err ;
954972 }
955973
974+ cs35l56 -> base .cal_index = cs35l56 -> index ;
975+
956976 cs35l56_init_cs_dsp (& cs35l56 -> base , & cs35l56 -> cs_dsp );
957977 cs35l56 -> cs_dsp .client_ops = & cs35l56_hda_client_ops ;
958978
@@ -990,6 +1010,10 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id)
9901010 if (ret )
9911011 goto err ;
9921012
1013+ ret = cs35l56_get_calibration (& cs35l56 -> base );
1014+ if (ret )
1015+ goto err ;
1016+
9931017 ret = cs_dsp_halo_init (& cs35l56 -> cs_dsp );
9941018 if (ret ) {
9951019 dev_err_probe (cs35l56 -> base .dev , ret , "cs_dsp_halo_init failed\n" );
@@ -1064,10 +1088,11 @@ const struct dev_pm_ops cs35l56_hda_pm_ops = {
10641088EXPORT_SYMBOL_NS_GPL (cs35l56_hda_pm_ops , SND_HDA_SCODEC_CS35L56 );
10651089
10661090MODULE_DESCRIPTION ("CS35L56 HDA Driver" );
1091+ MODULE_IMPORT_NS (FW_CS_DSP );
10671092MODULE_IMPORT_NS (SND_HDA_CIRRUS_SCODEC );
10681093MODULE_IMPORT_NS (SND_HDA_CS_DSP_CONTROLS );
10691094MODULE_IMPORT_NS (SND_SOC_CS35L56_SHARED );
1095+ MODULE_IMPORT_NS (SND_SOC_CS_AMP_LIB );
10701096MODULE_AUTHOR ("Richard Fitzgerald <rf@opensource.cirrus.com>" );
10711097MODULE_AUTHOR ("Simon Trimmer <simont@opensource.cirrus.com>" );
10721098MODULE_LICENSE ("GPL" );
1073- MODULE_IMPORT_NS (FW_CS_DSP );
0 commit comments