Commit 76f5f55c authored by Gergo Koteles's avatar Gergo Koteles Committed by Takashi Iwai

ALSA: hda/tas2781: add ptrs to calibration functions

Make calibration functions configurable to support different calibration
data storage modes.
Signed-off-by: default avatarGergo Koteles <soyer@irl.hu>
Link: https://lore.kernel.org/r/5859c77ffef752b8a9784713b412d815d7e2688c.1703891777.git.soyer@irl.huSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent bd968aef
...@@ -131,6 +131,9 @@ struct tasdevice_priv { ...@@ -131,6 +131,9 @@ struct tasdevice_priv {
const struct firmware *fmw, int offset); const struct firmware *fmw, int offset);
int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv, int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
struct tasdev_blk *block); 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); void tas2781_reset(struct tasdevice_priv *tas_dev);
...@@ -139,6 +142,8 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec, ...@@ -139,6 +142,8 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c); struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c);
int tasdevice_init(struct tasdevice_priv *tas_priv); int tasdevice_init(struct tasdevice_priv *tas_priv);
void tasdevice_remove(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, int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
unsigned short chn, unsigned int reg, unsigned int *value); unsigned short chn, unsigned int reg, unsigned int *value);
int tasdevice_dev_write(struct tasdevice_priv *tas_priv, int tasdevice_dev_write(struct tasdevice_priv *tas_priv,
......
...@@ -479,7 +479,7 @@ static int tas2781_save_calibration(struct tasdevice_priv *tas_priv) ...@@ -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", dev_dbg(tas_priv->dev, "%4ld-%2d-%2d, %2d:%2d:%2d\n",
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_year, tm->tm_mon, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec); tm->tm_hour, tm->tm_min, tm->tm_sec);
tas2781_apply_calib(tas_priv); tasdevice_apply_calibration(tas_priv);
} else } else
tas_priv->cali_data.total_sz = 0; tas_priv->cali_data.total_sz = 0;
...@@ -582,7 +582,7 @@ static void tasdev_fw_ready(const struct firmware *fmw, void *context) ...@@ -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 /* If calibrated data occurs error, dsp will still works with default
* calibrated data inside algo. * calibrated data inside algo.
*/ */
tas2781_save_calibration(tas_priv); tasdevice_save_calibration(tas_priv);
tasdevice_tuning_switch(tas_hda->priv, 0); tasdevice_tuning_switch(tas_hda->priv, 0);
...@@ -685,10 +685,6 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt) ...@@ -685,10 +685,6 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
const char *device_name; const char *device_name;
int ret; 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); tas_hda = devm_kzalloc(&clt->dev, sizeof(*tas_hda), GFP_KERNEL);
if (!tas_hda) if (!tas_hda)
...@@ -701,6 +697,13 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt) ...@@ -701,6 +697,13 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
if (!tas_hda->priv) if (!tas_hda->priv)
return -ENOMEM; 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; tas_hda->priv->irq_info.irq = clt->irq;
ret = tas2781_read_acpi(tas_hda->priv, device_name); ret = tas2781_read_acpi(tas_hda->priv, device_name);
if (ret) if (ret)
...@@ -767,8 +770,6 @@ static int tas2781_runtime_suspend(struct device *dev) ...@@ -767,8 +770,6 @@ static int tas2781_runtime_suspend(struct device *dev)
static int tas2781_runtime_resume(struct device *dev) static int tas2781_runtime_resume(struct device *dev)
{ {
struct tas2781_hda *tas_hda = dev_get_drvdata(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"); dev_dbg(tas_hda->dev, "Runtime Resume\n");
...@@ -779,8 +780,7 @@ static int tas2781_runtime_resume(struct device *dev) ...@@ -779,8 +780,7 @@ static int tas2781_runtime_resume(struct device *dev)
/* If calibrated data occurs error, dsp will still works with default /* If calibrated data occurs error, dsp will still works with default
* calibrated data inside algo. * calibrated data inside algo.
*/ */
if (tas_hda->priv->cali_data.total_sz > calib_data_sz) tasdevice_apply_calibration(tas_hda->priv);
tas2781_apply_calib(tas_hda->priv);
mutex_unlock(&tas_hda->priv->codec_lock); mutex_unlock(&tas_hda->priv->codec_lock);
...@@ -811,8 +811,6 @@ static int tas2781_system_suspend(struct device *dev) ...@@ -811,8 +811,6 @@ static int tas2781_system_suspend(struct device *dev)
static int tas2781_system_resume(struct device *dev) static int tas2781_system_resume(struct device *dev)
{ {
struct tas2781_hda *tas_hda = dev_get_drvdata(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; int i, ret;
dev_info(tas_hda->priv->dev, "System Resume\n"); dev_info(tas_hda->priv->dev, "System Resume\n");
...@@ -834,8 +832,7 @@ static int tas2781_system_resume(struct device *dev) ...@@ -834,8 +832,7 @@ static int tas2781_system_resume(struct device *dev)
/* If calibrated data occurs error, dsp will still work with default /* If calibrated data occurs error, dsp will still work with default
* calibrated data inside algo. * calibrated data inside algo.
*/ */
if (tas_hda->priv->cali_data.total_sz > calib_data_sz) tasdevice_apply_calibration(tas_hda->priv);
tas2781_apply_calib(tas_hda->priv);
mutex_unlock(&tas_hda->priv->codec_lock); mutex_unlock(&tas_hda->priv->codec_lock);
return 0; return 0;
......
...@@ -412,6 +412,21 @@ void tasdevice_remove(struct tasdevice_priv *tas_priv) ...@@ -412,6 +412,21 @@ void tasdevice_remove(struct tasdevice_priv *tas_priv)
} }
EXPORT_SYMBOL_GPL(tasdevice_remove); 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) static int tasdevice_clamp(int val, int max, unsigned int invert)
{ {
if (val > max) if (val > max)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment