Commit cdcdb008 authored by Mark Brown's avatar Mark Brown

Untested TAS2562 power setting fixes

Merge series from Martin Povišer <povik+lin@cutebit.org>:

The tas2562 driver does the same thing with the setting of PWR_CTRL
field as the tas2764/tas2770 drivers were doing.
Link: https://lore.kernel.org/alsa-devel/20220808141246.5749-1-povik+lin@cutebit.org/T/#t
Link: https://lore.kernel.org/alsa-devel/20220825140241.53963-1-povik+lin@cutebit.org/T/#t

These are blindly written patches without testing since I don't have
the hardware. (I even tried TI's formal sample request program but
was refused there. CCing @ti.com addresses I found on other series
recently submitted.)
parents 5176ee64 2848d34c
...@@ -54,6 +54,8 @@ struct tas2562_data { ...@@ -54,6 +54,8 @@ struct tas2562_data {
int i_sense_slot; int i_sense_slot;
int volume_lvl; int volume_lvl;
int model_id; int model_id;
bool dac_powered;
bool unmuted;
}; };
enum tas256x_model { enum tas256x_model {
...@@ -63,39 +65,6 @@ enum tas256x_model { ...@@ -63,39 +65,6 @@ enum tas256x_model {
TAS2110, TAS2110,
}; };
static int tas2562_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level)
{
struct tas2562_data *tas2562 =
snd_soc_component_get_drvdata(component);
switch (level) {
case SND_SOC_BIAS_ON:
snd_soc_component_update_bits(component,
TAS2562_PWR_CTRL,
TAS2562_MODE_MASK, TAS2562_ACTIVE);
break;
case SND_SOC_BIAS_STANDBY:
case SND_SOC_BIAS_PREPARE:
snd_soc_component_update_bits(component,
TAS2562_PWR_CTRL,
TAS2562_MODE_MASK, TAS2562_MUTE);
break;
case SND_SOC_BIAS_OFF:
snd_soc_component_update_bits(component,
TAS2562_PWR_CTRL,
TAS2562_MODE_MASK, TAS2562_SHUTDOWN);
break;
default:
dev_err(tas2562->dev,
"wrong power level setting %d\n", level);
return -EINVAL;
}
return 0;
}
static int tas2562_set_samplerate(struct tas2562_data *tas2562, int samplerate) static int tas2562_set_samplerate(struct tas2562_data *tas2562, int samplerate)
{ {
int samp_rate; int samp_rate;
...@@ -384,30 +353,43 @@ static int tas2562_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) ...@@ -384,30 +353,43 @@ static int tas2562_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
return 0; return 0;
} }
static int tas2562_update_pwr_ctrl(struct tas2562_data *tas2562)
{
struct snd_soc_component *component = tas2562->component;
unsigned int val;
int ret;
if (tas2562->dac_powered)
val = tas2562->unmuted ?
TAS2562_ACTIVE : TAS2562_MUTE;
else
val = TAS2562_SHUTDOWN;
ret = snd_soc_component_update_bits(component, TAS2562_PWR_CTRL,
TAS2562_MODE_MASK, val);
if (ret < 0)
return ret;
return 0;
}
static int tas2562_mute(struct snd_soc_dai *dai, int mute, int direction) static int tas2562_mute(struct snd_soc_dai *dai, int mute, int direction)
{ {
struct snd_soc_component *component = dai->component; struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(dai->component);
return snd_soc_component_update_bits(component, TAS2562_PWR_CTRL, tas2562->unmuted = !mute;
TAS2562_MODE_MASK, return tas2562_update_pwr_ctrl(tas2562);
mute ? TAS2562_MUTE : 0);
} }
static int tas2562_codec_probe(struct snd_soc_component *component) static int tas2562_codec_probe(struct snd_soc_component *component)
{ {
struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(component); struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(component);
int ret;
tas2562->component = component; tas2562->component = component;
if (tas2562->sdz_gpio) if (tas2562->sdz_gpio)
gpiod_set_value_cansleep(tas2562->sdz_gpio, 1); gpiod_set_value_cansleep(tas2562->sdz_gpio, 1);
ret = snd_soc_component_update_bits(component, TAS2562_PWR_CTRL,
TAS2562_MODE_MASK, TAS2562_MUTE);
if (ret < 0)
return ret;
return 0; return 0;
} }
...@@ -461,30 +443,18 @@ static int tas2562_dac_event(struct snd_soc_dapm_widget *w, ...@@ -461,30 +443,18 @@ static int tas2562_dac_event(struct snd_soc_dapm_widget *w,
switch (event) { switch (event) {
case SND_SOC_DAPM_POST_PMU: case SND_SOC_DAPM_POST_PMU:
ret = snd_soc_component_update_bits(component, tas2562->dac_powered = true;
TAS2562_PWR_CTRL, ret = tas2562_update_pwr_ctrl(tas2562);
TAS2562_MODE_MASK,
TAS2562_MUTE);
if (ret)
goto end;
break; break;
case SND_SOC_DAPM_PRE_PMD: case SND_SOC_DAPM_PRE_PMD:
ret = snd_soc_component_update_bits(component, tas2562->dac_powered = false;
TAS2562_PWR_CTRL, ret = tas2562_update_pwr_ctrl(tas2562);
TAS2562_MODE_MASK,
TAS2562_SHUTDOWN);
if (ret)
goto end;
break; break;
default: default:
dev_err(tas2562->dev, "Not supported evevt\n"); dev_err(tas2562->dev, "Not supported evevt\n");
return -EINVAL; return -EINVAL;
} }
end:
if (ret < 0)
return ret;
return 0; return 0;
} }
...@@ -579,7 +549,6 @@ static const struct snd_soc_component_driver soc_component_dev_tas2110 = { ...@@ -579,7 +549,6 @@ static const struct snd_soc_component_driver soc_component_dev_tas2110 = {
.probe = tas2562_codec_probe, .probe = tas2562_codec_probe,
.suspend = tas2562_suspend, .suspend = tas2562_suspend,
.resume = tas2562_resume, .resume = tas2562_resume,
.set_bias_level = tas2562_set_bias_level,
.controls = tas2562_snd_controls, .controls = tas2562_snd_controls,
.num_controls = ARRAY_SIZE(tas2562_snd_controls), .num_controls = ARRAY_SIZE(tas2562_snd_controls),
.dapm_widgets = tas2110_dapm_widgets, .dapm_widgets = tas2110_dapm_widgets,
...@@ -618,7 +587,6 @@ static const struct snd_soc_component_driver soc_component_dev_tas2562 = { ...@@ -618,7 +587,6 @@ static const struct snd_soc_component_driver soc_component_dev_tas2562 = {
.probe = tas2562_codec_probe, .probe = tas2562_codec_probe,
.suspend = tas2562_suspend, .suspend = tas2562_suspend,
.resume = tas2562_resume, .resume = tas2562_resume,
.set_bias_level = tas2562_set_bias_level,
.controls = tas2562_snd_controls, .controls = tas2562_snd_controls,
.num_controls = ARRAY_SIZE(tas2562_snd_controls), .num_controls = ARRAY_SIZE(tas2562_snd_controls),
.dapm_widgets = tas2562_dapm_widgets, .dapm_widgets = tas2562_dapm_widgets,
......
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