reset sound after suspend to memory (deep sleep)
#9
Sorry... life got in the way.  I really should get that set of patches bundled up for submission, I just haven't been liking computers much lately and have been avoiding them as much as possible outside work.

My set of patches isn't very good, I'm certain it's not entirely correct. but it does work (mostly).



Code:
diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index b303ebbd5..d9e33214a 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -32,6 +32,8 @@ static const unsigned int supported_mclk_lrck_ratios[] = {
256, 384, 400, 512, 768, 1024
};

+#define ES8316_CONFIG_REGISTERS 0x50
+
struct es8316_priv {
struct mutex lock;
struct clk *mclk;
@@ -43,6 +45,7 @@ struct es8316_priv {
unsigned int allowed_rates[NR_SUPPORTED_MCLK_LRCK_RATIOS];
struct snd_pcm_hw_constraint_list sysclk_constraints;
bool jd_inverted;
+ uint8_t config_save[ES8316_CONFIG_REGISTERS];
};

/*
@@ -708,11 +711,39 @@ static int es8316_set_jack(struct snd_soc_component *component,
return 0;
}

+static void dump_es8316_config(struct snd_soc_component *component) {
+ int i;
+ uint32_t val;
+
+ for (i = 0; i <= 0x4F; i++) {
+ printk(KERN_INFO "es8316[%02x]: %x\n", i, snd_soc_component_read32(component, i));
+ }
+}
+
+static void save_es8316_config(struct snd_soc_component *component, struct es8316_priv *es8316) {
+ int i;
+
+ for (i = 0; i < ES8316_CONFIG_REGISTERS; i++) {
+ es8316->config_save[i] = (uint8_t)snd_soc_component_read32(component, i);
+ }
+}
+
+static void restore_es8316_config(struct snd_soc_component *component, struct es8316_priv *es8316) {
+ int i;
+
+ for (i = 0; i < ES8316_CONFIG_REGISTERS; i++) {
+ snd_soc_component_write(component, i, es8316->config_save[i]);
+ }
+}
+
+
static int es8316_probe(struct snd_soc_component *component)
{
struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
int ret;

+ printk(KERN_INFO "es8316_probe\n");
+
es8316->component = component;

es8316->mclk = devm_clk_get_optional(component->dev, "mclk");
@@ -748,9 +779,33 @@ static int es8316_probe(struct snd_soc_component *component)
*/
snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR, 0x32);

+ dump_es8316_config(component);
+
+ return 0;
+}
+
+static int es8316_suspend(struct snd_soc_component *component)
+{
+ struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
+
+ printk(KERN_INFO "In es8316_suspend\n");
+ dump_es8316_config(component);
+ save_es8316_config(component, es8316);
return 0;
}

+static int es8316_resume(struct snd_soc_component *component)
+{
+ struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
+ printk(KERN_INFO "In es8316_resume\n");
+
+ restore_es8316_config(component, es8316);
+ dump_es8316_config(component);
+
+ return 0;
+}
+
+
static void es8316_remove(struct snd_soc_component *component)
{
struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
@@ -761,6 +816,8 @@ static void es8316_remove(struct snd_soc_component *component)
static const struct snd_soc_component_driver soc_component_dev_es8316 = {
.probe = es8316_probe,
.remove = es8316_remove,
+ .suspend = es8316_suspend,
+ .resume = es8316_resume,
.set_jack = es8316_set_jack,
.controls = es8316_snd_controls,
.num_controls = ARRAY_SIZE(es8316_snd_controls),
@@ -797,11 +854,15 @@ static int es8316_i2c_probe(struct i2c_client *i2c_client,
struct es8316_priv *es8316;
int ret;

+ printk(KERN_INFO "es8316_i2c_probe\n");
+
es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv),
      GFP_KERNEL);
if (es8316 == NULL)
return -ENOMEM;

+ printk(KERN_INFO "i2c_probe es8316 = %llx\n", (uint64_t)es8316);
+
i2c_set_clientdata(i2c_client, es8316);

es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap);
@@ -845,11 +906,57 @@ static const struct acpi_device_id es8316_acpi_match[] = {
};
MODULE_DEVICE_TABLE(acpi, es8316_acpi_match);

+static int es8316_i2c_suspend(struct device *dev) {
+
+ printk(KERN_INFO "es8316_i2c_suspend\n");
+
+ return 0;
+}
+
+static int es8316_i2c_resume(struct device *dev) {
+ struct es8316_priv *es8316 = dev_get_drvdata(dev);
+ int ret;
+
+ printk(KERN_INFO "es8316_i2c_resume\n");
+
+ printk(KERN_INFO "i2c_resume es8316 = %llx\n", (uint64_t)es8316);
+
+ //es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap);
+ //if (IS_ERR(es8316->regmap))
+ // return PTR_ERR(es8316->regmap);
+
+ //es8316->irq = i2c_client->irq;
+ //mutex_init(&es8316->lock);
+
+ ret = devm_request_threaded_irq(dev, es8316->irq, NULL, es8316_irq,
+ IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+ "es8316", es8316);
+ if (ret == 0) {
+ /* Gets re-enabled by es8316_set_jack() */
+ disable_irq(es8316->irq);
+ } else {
+ dev_warn(dev, "Failed to get IRQ %d: %d\n", es8316->irq, ret);
+ es8316->irq = -ENXIO;
+ }
+
+ //return devm_snd_soc_register_component(&i2c_client->dev,
+ //       &soc_component_dev_es8316,
+ //       &es8316_dai, 1);
+ return 0;
+}
+
+
+const struct dev_pm_ops es8316_pm_ops = {
+        SET_SYSTEM_SLEEP_PM_OPS(es8316_i2c_suspend, es8316_i2c_resume)
+};
+
+
static struct i2c_driver es8316_i2c_driver = {
.driver = {
.name = "es8316",
.acpi_match_table = ACPI_PTR(es8316_acpi_match),
.of_match_table = of_match_ptr(es8316_of_match),
+ .pm = &es8316_pm_ops,
},
.probe = es8316_i2c_probe,
.id_table = es8316_i2c_id,
  Reply


Messages In This Thread
RE: reset sound after suspend to memory (deep sleep) - by Syonyk - 03-11-2021, 08:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sleep and external display - Are there any options? chris88233 7 1,736 09-04-2023, 09:03 PM
Last Post: wdt
  PineBook Pro seems to go to deep sleep, but doesn't wake up pogo 11 5,287 08-31-2023, 04:20 PM
Last Post: TRS-80
  Rkvdec memory leak? Abhinav 2 843 06-02-2023, 08:55 AM
Last Post: Abhinav
  Sound on Armbian Bram 1 902 04-01-2023, 03:16 PM
Last Post: TRS-80
  Suspend/Resume Broken with Bootloader on SPI Flash xp19375 2 1,170 03-24-2023, 04:25 PM
Last Post: srs5694
  With the help of a friend, I installed a beautiful deep os distribution, but I won't wangyukunshan 0 607 03-03-2023, 10:56 PM
Last Post: wangyukunshan
  Hibernation and Speaker Sound Issues, First Month of PBP kebab 7 2,990 11-02-2022, 02:33 PM
Last Post: kebab
  Resume from suspend not working after flashing Tow-Boot to SPI xp19375 3 1,978 10-31-2022, 10:14 AM
Last Post: wdt
  Loud distorted speaker sound when connecting to power supply myself600 2 1,203 09-21-2022, 12:11 PM
Last Post: myself600
  How to make manjaro sleep or hibernate? KDE? regretfulpineuser 0 988 06-20-2022, 12:56 AM
Last Post: regretfulpineuser

Forum Jump:


Users browsing this thread: 1 Guest(s)