Skip to content

Commit d9253c6

Browse files
marcanjannau
authored andcommitted
ASoC: tas2764: Add SDZ regulator
Multiple amps can be connected to the same SDZ GPIO. Using raw GPIOs for this breaks, as there is no concept of refcounting/sharing. In order to model these platforms, introduce support for an SDZ "regulator". This allows us to represent the SDZ GPIO as a simple regulator-fixed, and then the regulator core takes care of refcounting so that all codecs are only powered down once all the driver instances are in the suspend state. Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 04db5f6 commit d9253c6

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

sound/soc/codecs/tas2764.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct tas2764_priv {
3636
struct snd_soc_component *component;
3737
struct gpio_desc *reset_gpio;
3838
struct gpio_desc *sdz_gpio;
39+
struct regulator *sdz_reg;
3940
struct regmap *regmap;
4041
struct device *dev;
4142
int irq;
@@ -159,6 +160,8 @@ static int tas2764_codec_suspend(struct snd_soc_component *component)
159160
if (tas2764->sdz_gpio)
160161
gpiod_set_value_cansleep(tas2764->sdz_gpio, 0);
161162

163+
regulator_disable(tas2764->sdz_reg);
164+
162165
regcache_cache_only(tas2764->regmap, true);
163166
regcache_mark_dirty(tas2764->regmap);
164167

@@ -170,19 +173,26 @@ static int tas2764_codec_resume(struct snd_soc_component *component)
170173
struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
171174
int ret;
172175

176+
ret = regulator_enable(tas2764->sdz_reg);
177+
178+
if (ret) {
179+
dev_err(tas2764->dev, "Failed to enable regulator\n");
180+
return ret;
181+
}
182+
173183
if (tas2764->sdz_gpio) {
174184
gpiod_set_value_cansleep(tas2764->sdz_gpio, 1);
175-
usleep_range(1000, 2000);
176185
}
177186

178-
ret = tas2764_update_pwr_ctrl(tas2764);
187+
usleep_range(1000, 2000);
179188

189+
regcache_cache_only(tas2764->regmap, false);
190+
191+
ret = regcache_sync(tas2764->regmap);
180192
if (ret < 0)
181193
return ret;
182194

183-
regcache_cache_only(tas2764->regmap, false);
184-
185-
return regcache_sync(tas2764->regmap);
195+
return tas2764_update_pwr_ctrl(tas2764);
186196
}
187197
#else
188198
#define tas2764_codec_suspend NULL
@@ -215,7 +225,7 @@ static const struct snd_soc_dapm_widget tas2764_dapm_widgets[] = {
215225
SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
216226
SND_SOC_DAPM_OUTPUT("OUT"),
217227
SND_SOC_DAPM_SIGGEN("VMON"),
218-
SND_SOC_DAPM_SIGGEN("IMON")
228+
SND_SOC_DAPM_SIGGEN("IMON"),
219229
};
220230

221231
static const struct snd_soc_dapm_route tas2764_audio_map[] = {
@@ -634,11 +644,18 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
634644

635645
tas2764->component = component;
636646

647+
ret = regulator_enable(tas2764->sdz_reg);
648+
if (ret != 0) {
649+
dev_err(tas2764->dev, "Failed to enable regulator: %d\n", ret);
650+
return ret;
651+
}
652+
637653
if (tas2764->sdz_gpio) {
638654
gpiod_set_value_cansleep(tas2764->sdz_gpio, 1);
639-
usleep_range(1000, 2000);
640655
}
641656

657+
usleep_range(1000, 2000);
658+
642659
tas2764_reset(tas2764);
643660
regmap_reinit_cache(tas2764->regmap, &tas2764_i2c_regmap);
644661

@@ -710,6 +727,9 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
710727

711728
static void tas2764_codec_remove(struct snd_soc_component *component)
712729
{
730+
struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
731+
732+
regulator_disable(tas2764->sdz_reg);
713733
sysfs_remove_groups(&component->dev->kobj, tas2764_sysfs_groups);
714734
}
715735

@@ -812,6 +832,11 @@ static int tas2764_parse_dt(struct device *dev, struct tas2764_priv *tas2764)
812832
{
813833
int ret = 0;
814834

835+
tas2764->sdz_reg = devm_regulator_get(dev, "SDZ");
836+
if (IS_ERR(tas2764->sdz_reg))
837+
return dev_err_probe(dev, PTR_ERR(tas2764->sdz_reg),
838+
"Failed to get SDZ supply\n");
839+
815840
tas2764->reset_gpio = devm_gpiod_get_optional(tas2764->dev, "reset",
816841
GPIOD_OUT_HIGH);
817842
if (IS_ERR(tas2764->reset_gpio)) {

0 commit comments

Comments
 (0)