ALSA: hda/tas2781: add ptrs to calibration functions
authorGergo Koteles <soyer@irl.hu>
Sat, 30 Dec 2023 00:09:42 +0000 (01:09 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 2 Jan 2024 15:14:01 +0000 (16:14 +0100)
Make calibration functions configurable to support different calibration
data storage modes.

Signed-off-by: Gergo Koteles <soyer@irl.hu>
Link: https://lore.kernel.org/r/5859c77ffef752b8a9784713b412d815d7e2688c.1703891777.git.soyer@irl.hu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/tas2781.h
sound/pci/hda/tas2781_hda_i2c.c
sound/soc/codecs/tas2781-comlib.c

index a6c808b223183a1d9c149581e30ff362b194c2e0..e17ceab4fead1092498b914040fa0ef195eadfb3 100644 (file)
@@ -131,6 +131,9 @@ struct tasdevice_priv {
                const struct firmware *fmw, int offset);
        int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
                struct tasdev_blk *block);
+
+       int (*save_calibration)(struct tasdevice_priv *tas_priv);
+       void (*apply_calibration)(struct tasdevice_priv *tas_priv);
 };
 
 void tas2781_reset(struct tasdevice_priv *tas_dev);
@@ -139,6 +142,8 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
 struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c);
 int tasdevice_init(struct tasdevice_priv *tas_priv);
 void tasdevice_remove(struct tasdevice_priv *tas_priv);
+int tasdevice_save_calibration(struct tasdevice_priv *tas_priv);
+void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv);
 int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
        unsigned short chn, unsigned int reg, unsigned int *value);
 int tasdevice_dev_write(struct tasdevice_priv *tas_priv,
index c8523df4105f31d0ef3ad4cc0bbc91bf49dd0580..4b639120c9813eb8b40ba0053f3d7188cc7e8c3a 100644 (file)
@@ -479,7 +479,7 @@ static int tas2781_save_calibration(struct tasdevice_priv *tas_priv)
                dev_dbg(tas_priv->dev, "%4ld-%2d-%2d, %2d:%2d:%2d\n",
                        tm->tm_year, tm->tm_mon, tm->tm_mday,
                        tm->tm_hour, tm->tm_min, tm->tm_sec);
-               tas2781_apply_calib(tas_priv);
+               tasdevice_apply_calibration(tas_priv);
        } else
                tas_priv->cali_data.total_sz = 0;
 
@@ -582,7 +582,7 @@ static void tasdev_fw_ready(const struct firmware *fmw, void *context)
        /* If calibrated data occurs error, dsp will still works with default
         * calibrated data inside algo.
         */
-       tas2781_save_calibration(tas_priv);
+       tasdevice_save_calibration(tas_priv);
 
        tasdevice_tuning_switch(tas_hda->priv, 0);
 
@@ -685,10 +685,6 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
        const char *device_name;
        int ret;
 
-       if (strstr(dev_name(&clt->dev), "TIAS2781"))
-               device_name = "TIAS2781";
-       else
-               return -ENODEV;
 
        tas_hda = devm_kzalloc(&clt->dev, sizeof(*tas_hda), GFP_KERNEL);
        if (!tas_hda)
@@ -701,6 +697,13 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
        if (!tas_hda->priv)
                return -ENOMEM;
 
+       if (strstr(dev_name(&clt->dev), "TIAS2781")) {
+               device_name = "TIAS2781";
+               tas_hda->priv->save_calibration = tas2781_save_calibration;
+               tas_hda->priv->apply_calibration = tas2781_apply_calib;
+       } else
+               return -ENODEV;
+
        tas_hda->priv->irq_info.irq = clt->irq;
        ret = tas2781_read_acpi(tas_hda->priv, device_name);
        if (ret)
@@ -767,8 +770,6 @@ static int tas2781_runtime_suspend(struct device *dev)
 static int tas2781_runtime_resume(struct device *dev)
 {
        struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
-       unsigned long calib_data_sz =
-               tas_hda->priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE;
 
        dev_dbg(tas_hda->dev, "Runtime Resume\n");
 
@@ -779,8 +780,7 @@ static int tas2781_runtime_resume(struct device *dev)
        /* If calibrated data occurs error, dsp will still works with default
         * calibrated data inside algo.
         */
-       if (tas_hda->priv->cali_data.total_sz > calib_data_sz)
-               tas2781_apply_calib(tas_hda->priv);
+       tasdevice_apply_calibration(tas_hda->priv);
 
        mutex_unlock(&tas_hda->priv->codec_lock);
 
@@ -811,8 +811,6 @@ static int tas2781_system_suspend(struct device *dev)
 static int tas2781_system_resume(struct device *dev)
 {
        struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
-       unsigned long calib_data_sz =
-               tas_hda->priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE;
        int i, ret;
 
        dev_info(tas_hda->priv->dev, "System Resume\n");
@@ -834,8 +832,7 @@ static int tas2781_system_resume(struct device *dev)
        /* If calibrated data occurs error, dsp will still work with default
         * calibrated data inside algo.
         */
-       if (tas_hda->priv->cali_data.total_sz > calib_data_sz)
-               tas2781_apply_calib(tas_hda->priv);
+       tasdevice_apply_calibration(tas_hda->priv);
        mutex_unlock(&tas_hda->priv->codec_lock);
 
        return 0;
index 00e35169ae4950dd2d439c6d0b94d4775870f7ac..b7e56ceb1acff9f41e6a26f09e1c4395ff537553 100644 (file)
@@ -412,6 +412,21 @@ void tasdevice_remove(struct tasdevice_priv *tas_priv)
 }
 EXPORT_SYMBOL_GPL(tasdevice_remove);
 
+int tasdevice_save_calibration(struct tasdevice_priv *tas_priv)
+{
+       if (tas_priv->save_calibration)
+               return tas_priv->save_calibration(tas_priv);
+       return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(tasdevice_save_calibration);
+
+void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv)
+{
+       if (tas_priv->apply_calibration && tas_priv->cali_data.total_sz)
+               tas_priv->apply_calibration(tas_priv);
+}
+EXPORT_SYMBOL_GPL(tasdevice_apply_calibration);
+
 static int tasdevice_clamp(int val, int max, unsigned int invert)
 {
        if (val > max)