ASoC: hdac_hdmi: Add PM support for HDMI
authorSubhransu S. Prusty <subhransu.s.prusty@intel.com>
Tue, 10 Nov 2015 13:12:07 +0000 (18:42 +0530)
committerMark Brown <broonie@kernel.org>
Sat, 21 Nov 2015 13:58:19 +0000 (13:58 +0000)
Power up/down the AFG node during runtime resume/suspend.

Signed-off-by: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/hdac_hdmi.c

index d37d688fa40a24fee1ab9aa235947770393525f1..45dfc4f608e5dfa5019b3f8cad5f4ba2a5e636e1 100644 (file)
@@ -60,6 +60,13 @@ struct hdac_hdmi_priv {
        struct hdac_hdmi_dai_pin_map dai_map[3];
 };
 
+static inline struct hdac_ext_device *to_hda_ext_device(struct device *dev)
+{
+       struct hdac_device *hdac = container_of(dev, struct hdac_device, dev);
+
+       return container_of(hdac, struct hdac_ext_device, hdac);
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdac, struct hdac_hdmi_cvt *cvt)
 {
@@ -250,11 +257,28 @@ static int hdmi_codec_probe(struct snd_soc_codec *codec)
        /* Imp: Store the card pointer in hda_codec */
        edev->card = dapm->card->snd_card;
 
+       /*
+        * hdac_device core already sets the state to active and calls
+        * get_noresume. So enable runtime and set the device to suspend.
+        */
+       pm_runtime_enable(&edev->hdac.dev);
+       pm_runtime_put(&edev->hdac.dev);
+       pm_runtime_suspend(&edev->hdac.dev);
+
+       return 0;
+}
+
+static int hdmi_codec_remove(struct snd_soc_codec *codec)
+{
+       struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
+
+       pm_runtime_disable(&edev->hdac.dev);
        return 0;
 }
 
 static struct snd_soc_codec_driver hdmi_hda_codec = {
        .probe          = hdmi_codec_probe,
+       .remove         = hdmi_codec_remove,
        .idle_bias_off  = true,
 };
 
@@ -307,6 +331,45 @@ static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int hdac_hdmi_runtime_suspend(struct device *dev)
+{
+       struct hdac_ext_device *edev = to_hda_ext_device(dev);
+       struct hdac_device *hdac = &edev->hdac;
+
+       dev_dbg(dev, "Enter: %s\n", __func__);
+
+       /* Power down afg */
+       if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D3))
+               snd_hdac_codec_write(hdac, hdac->afg, 0,
+                       AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
+
+       return 0;
+}
+
+static int hdac_hdmi_runtime_resume(struct device *dev)
+{
+       struct hdac_ext_device *edev = to_hda_ext_device(dev);
+       struct hdac_device *hdac = &edev->hdac;
+
+       dev_dbg(dev, "Enter: %s\n", __func__);
+
+       /* Power up afg */
+       if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D0))
+               snd_hdac_codec_write(hdac, hdac->afg, 0,
+                       AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
+
+       return 0;
+}
+#else
+#define hdac_hdmi_runtime_suspend NULL
+#define hdac_hdmi_runtime_resume NULL
+#endif
+
+static const struct dev_pm_ops hdac_hdmi_pm = {
+       SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
+};
+
 static const struct hda_device_id hdmi_list[] = {
        HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
        {}
@@ -318,6 +381,7 @@ static struct hdac_ext_driver hdmi_driver = {
        . hdac = {
                .driver = {
                        .name   = "HDMI HDA Codec",
+                       .pm = &hdac_hdmi_pm,
                },
                .id_table       = hdmi_list,
        },