Skip to content

Commit 76f5f55

Browse files
soyersoyertiwai
authored andcommitted
ALSA: hda/tas2781: add ptrs to calibration functions
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>
1 parent bd968ae commit 76f5f55

3 files changed

Lines changed: 31 additions & 14 deletions

File tree

include/sound/tas2781.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ struct tasdevice_priv {
131131
const struct firmware *fmw, int offset);
132132
int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
133133
struct tasdev_blk *block);
134+
135+
int (*save_calibration)(struct tasdevice_priv *tas_priv);
136+
void (*apply_calibration)(struct tasdevice_priv *tas_priv);
134137
};
135138

136139
void tas2781_reset(struct tasdevice_priv *tas_dev);
@@ -139,6 +142,8 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
139142
struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c);
140143
int tasdevice_init(struct tasdevice_priv *tas_priv);
141144
void tasdevice_remove(struct tasdevice_priv *tas_priv);
145+
int tasdevice_save_calibration(struct tasdevice_priv *tas_priv);
146+
void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv);
142147
int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
143148
unsigned short chn, unsigned int reg, unsigned int *value);
144149
int tasdevice_dev_write(struct tasdevice_priv *tas_priv,

sound/pci/hda/tas2781_hda_i2c.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int tas2781_save_calibration(struct tasdevice_priv *tas_priv)
479479
dev_dbg(tas_priv->dev, "%4ld-%2d-%2d, %2d:%2d:%2d\n",
480480
tm->tm_year, tm->tm_mon, tm->tm_mday,
481481
tm->tm_hour, tm->tm_min, tm->tm_sec);
482-
tas2781_apply_calib(tas_priv);
482+
tasdevice_apply_calibration(tas_priv);
483483
} else
484484
tas_priv->cali_data.total_sz = 0;
485485

@@ -582,7 +582,7 @@ static void tasdev_fw_ready(const struct firmware *fmw, void *context)
582582
/* If calibrated data occurs error, dsp will still works with default
583583
* calibrated data inside algo.
584584
*/
585-
tas2781_save_calibration(tas_priv);
585+
tasdevice_save_calibration(tas_priv);
586586

587587
tasdevice_tuning_switch(tas_hda->priv, 0);
588588

@@ -685,10 +685,6 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
685685
const char *device_name;
686686
int ret;
687687

688-
if (strstr(dev_name(&clt->dev), "TIAS2781"))
689-
device_name = "TIAS2781";
690-
else
691-
return -ENODEV;
692688

693689
tas_hda = devm_kzalloc(&clt->dev, sizeof(*tas_hda), GFP_KERNEL);
694690
if (!tas_hda)
@@ -701,6 +697,13 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
701697
if (!tas_hda->priv)
702698
return -ENOMEM;
703699

700+
if (strstr(dev_name(&clt->dev), "TIAS2781")) {
701+
device_name = "TIAS2781";
702+
tas_hda->priv->save_calibration = tas2781_save_calibration;
703+
tas_hda->priv->apply_calibration = tas2781_apply_calib;
704+
} else
705+
return -ENODEV;
706+
704707
tas_hda->priv->irq_info.irq = clt->irq;
705708
ret = tas2781_read_acpi(tas_hda->priv, device_name);
706709
if (ret)
@@ -767,8 +770,6 @@ static int tas2781_runtime_suspend(struct device *dev)
767770
static int tas2781_runtime_resume(struct device *dev)
768771
{
769772
struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
770-
unsigned long calib_data_sz =
771-
tas_hda->priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE;
772773

773774
dev_dbg(tas_hda->dev, "Runtime Resume\n");
774775

@@ -779,8 +780,7 @@ static int tas2781_runtime_resume(struct device *dev)
779780
/* If calibrated data occurs error, dsp will still works with default
780781
* calibrated data inside algo.
781782
*/
782-
if (tas_hda->priv->cali_data.total_sz > calib_data_sz)
783-
tas2781_apply_calib(tas_hda->priv);
783+
tasdevice_apply_calibration(tas_hda->priv);
784784

785785
mutex_unlock(&tas_hda->priv->codec_lock);
786786

@@ -811,8 +811,6 @@ static int tas2781_system_suspend(struct device *dev)
811811
static int tas2781_system_resume(struct device *dev)
812812
{
813813
struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
814-
unsigned long calib_data_sz =
815-
tas_hda->priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE;
816814
int i, ret;
817815

818816
dev_info(tas_hda->priv->dev, "System Resume\n");
@@ -834,8 +832,7 @@ static int tas2781_system_resume(struct device *dev)
834832
/* If calibrated data occurs error, dsp will still work with default
835833
* calibrated data inside algo.
836834
*/
837-
if (tas_hda->priv->cali_data.total_sz > calib_data_sz)
838-
tas2781_apply_calib(tas_hda->priv);
835+
tasdevice_apply_calibration(tas_hda->priv);
839836
mutex_unlock(&tas_hda->priv->codec_lock);
840837

841838
return 0;

sound/soc/codecs/tas2781-comlib.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,21 @@ void tasdevice_remove(struct tasdevice_priv *tas_priv)
412412
}
413413
EXPORT_SYMBOL_GPL(tasdevice_remove);
414414

415+
int tasdevice_save_calibration(struct tasdevice_priv *tas_priv)
416+
{
417+
if (tas_priv->save_calibration)
418+
return tas_priv->save_calibration(tas_priv);
419+
return -EINVAL;
420+
}
421+
EXPORT_SYMBOL_GPL(tasdevice_save_calibration);
422+
423+
void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv)
424+
{
425+
if (tas_priv->apply_calibration && tas_priv->cali_data.total_sz)
426+
tas_priv->apply_calibration(tas_priv);
427+
}
428+
EXPORT_SYMBOL_GPL(tasdevice_apply_calibration);
429+
415430
static int tasdevice_clamp(int val, int max, unsigned int invert)
416431
{
417432
if (val > max)

0 commit comments

Comments
 (0)