mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
ASoC: cs35l41: Move cs35l41 exit hibernate function into shared code
CS35L41 HDA Driver will support hibernation using DSP firmware, move the exit hibernate function into shared code so this can be reused. Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com> Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com> Link: https://lore.kernel.org/r/20220525131638.5512-10-vitalyr@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
be1a63daff
commit
94e0bc317a
@ -881,6 +881,7 @@ void cs35l41_configure_cs_dsp(struct device *dev, struct regmap *reg, struct cs_
|
||||
int cs35l41_set_cspl_mbox_cmd(struct device *dev, struct regmap *regmap,
|
||||
enum cs35l41_cspl_mbox_cmd cmd);
|
||||
int cs35l41_write_fs_errata(struct device *dev, struct regmap *regmap);
|
||||
int cs35l41_exit_hibernate(struct device *dev, struct regmap *regmap);
|
||||
int cs35l41_init_boost(struct device *dev, struct regmap *regmap,
|
||||
struct cs35l41_hw_cfg *hw_cfg);
|
||||
bool cs35l41_safe_reset(struct regmap *regmap, enum cs35l41_boost_type b_type);
|
||||
|
@ -1321,6 +1321,66 @@ int cs35l41_write_fs_errata(struct device *dev, struct regmap *regmap)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cs35l41_write_fs_errata);
|
||||
|
||||
static void cs35l41_wait_for_pwrmgt_sts(struct device *dev, struct regmap *regmap)
|
||||
{
|
||||
const int pwrmgt_retries = 10;
|
||||
unsigned int sts;
|
||||
int i, ret;
|
||||
|
||||
for (i = 0; i < pwrmgt_retries; i++) {
|
||||
ret = regmap_read(regmap, CS35L41_PWRMGT_STS, &sts);
|
||||
if (ret)
|
||||
dev_err(dev, "Failed to read PWRMGT_STS: %d\n", ret);
|
||||
else if (!(sts & CS35L41_WR_PEND_STS_MASK))
|
||||
return;
|
||||
|
||||
udelay(20);
|
||||
}
|
||||
|
||||
dev_err(dev, "Timed out reading PWRMGT_STS\n");
|
||||
}
|
||||
|
||||
int cs35l41_exit_hibernate(struct device *dev, struct regmap *regmap)
|
||||
{
|
||||
const int wake_retries = 20;
|
||||
const int sleep_retries = 5;
|
||||
int ret, i, j;
|
||||
|
||||
for (i = 0; i < sleep_retries; i++) {
|
||||
dev_dbg(dev, "Exit hibernate\n");
|
||||
|
||||
for (j = 0; j < wake_retries; j++) {
|
||||
ret = cs35l41_set_cspl_mbox_cmd(dev, regmap,
|
||||
CSPL_MBOX_CMD_OUT_OF_HIBERNATE);
|
||||
if (!ret)
|
||||
break;
|
||||
|
||||
usleep_range(100, 200);
|
||||
}
|
||||
|
||||
if (j < wake_retries) {
|
||||
dev_dbg(dev, "Wake success at cycle: %d\n", j);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_err(dev, "Wake failed, re-enter hibernate: %d\n", ret);
|
||||
|
||||
cs35l41_wait_for_pwrmgt_sts(dev, regmap);
|
||||
regmap_write(regmap, CS35L41_WAKESRC_CTL, 0x0088);
|
||||
|
||||
cs35l41_wait_for_pwrmgt_sts(dev, regmap);
|
||||
regmap_write(regmap, CS35L41_WAKESRC_CTL, 0x0188);
|
||||
|
||||
cs35l41_wait_for_pwrmgt_sts(dev, regmap);
|
||||
regmap_write(regmap, CS35L41_PWRMGT_CTL, 0x3);
|
||||
}
|
||||
|
||||
dev_err(dev, "Timed out waking device\n");
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cs35l41_exit_hibernate);
|
||||
|
||||
MODULE_DESCRIPTION("CS35L41 library");
|
||||
MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>");
|
||||
MODULE_AUTHOR("Lucas Tanure, Cirrus Logic Inc, <tanureal@opensource.cirrus.com>");
|
||||
|
@ -1351,65 +1351,6 @@ static int __maybe_unused cs35l41_runtime_suspend(struct device *dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cs35l41_wait_for_pwrmgt_sts(struct cs35l41_private *cs35l41)
|
||||
{
|
||||
const int pwrmgt_retries = 10;
|
||||
unsigned int sts;
|
||||
int i, ret;
|
||||
|
||||
for (i = 0; i < pwrmgt_retries; i++) {
|
||||
ret = regmap_read(cs35l41->regmap, CS35L41_PWRMGT_STS, &sts);
|
||||
if (ret)
|
||||
dev_err(cs35l41->dev, "Failed to read PWRMGT_STS: %d\n", ret);
|
||||
else if (!(sts & CS35L41_WR_PEND_STS_MASK))
|
||||
return;
|
||||
|
||||
udelay(20);
|
||||
}
|
||||
|
||||
dev_err(cs35l41->dev, "Timed out reading PWRMGT_STS\n");
|
||||
}
|
||||
|
||||
static int cs35l41_exit_hibernate(struct cs35l41_private *cs35l41)
|
||||
{
|
||||
const int wake_retries = 20;
|
||||
const int sleep_retries = 5;
|
||||
int ret, i, j;
|
||||
|
||||
for (i = 0; i < sleep_retries; i++) {
|
||||
dev_dbg(cs35l41->dev, "Exit hibernate\n");
|
||||
|
||||
for (j = 0; j < wake_retries; j++) {
|
||||
ret = cs35l41_set_cspl_mbox_cmd(cs35l41->dev, cs35l41->regmap,
|
||||
CSPL_MBOX_CMD_OUT_OF_HIBERNATE);
|
||||
if (!ret)
|
||||
break;
|
||||
|
||||
usleep_range(100, 200);
|
||||
}
|
||||
|
||||
if (j < wake_retries) {
|
||||
dev_dbg(cs35l41->dev, "Wake success at cycle: %d\n", j);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_err(cs35l41->dev, "Wake failed, re-enter hibernate: %d\n", ret);
|
||||
|
||||
cs35l41_wait_for_pwrmgt_sts(cs35l41);
|
||||
regmap_write(cs35l41->regmap, CS35L41_WAKESRC_CTL, 0x0088);
|
||||
|
||||
cs35l41_wait_for_pwrmgt_sts(cs35l41);
|
||||
regmap_write(cs35l41->regmap, CS35L41_WAKESRC_CTL, 0x0188);
|
||||
|
||||
cs35l41_wait_for_pwrmgt_sts(cs35l41);
|
||||
regmap_write(cs35l41->regmap, CS35L41_PWRMGT_CTL, 0x3);
|
||||
}
|
||||
|
||||
dev_err(cs35l41->dev, "Timed out waking device\n");
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
static int __maybe_unused cs35l41_runtime_resume(struct device *dev)
|
||||
{
|
||||
struct cs35l41_private *cs35l41 = dev_get_drvdata(dev);
|
||||
@ -1422,7 +1363,7 @@ static int __maybe_unused cs35l41_runtime_resume(struct device *dev)
|
||||
|
||||
regcache_cache_only(cs35l41->regmap, false);
|
||||
|
||||
ret = cs35l41_exit_hibernate(cs35l41);
|
||||
ret = cs35l41_exit_hibernate(cs35l41->dev, cs35l41->regmap);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user