From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: hp_pin was NULL value Date: Tue, 29 Jan 2019 14:22:45 +0100 Message-ID: References: <6FAB7C47BCF00940BB0999A99BE3547A18420E8B@RTITMBSV02.realtek.com.tw> <6FAB7C47BCF00940BB0999A99BE3547A18420EBD@RTITMBSV02.realtek.com.tw> <6FAB7C47BCF00940BB0999A99BE3547A184210B1@RTITMBSV02.realtek.com.tw> <6FAB7C47BCF00940BB0999A99BE3547A184210E5@RTITMBSV02.realtek.com.tw> <6FAB7C47BCF00940BB0999A99BE3547A184210FC@RTITMBSV02.realtek.com.tw> <6FAB7C47BCF00940BB0999A99BE3547A1842112F@RTITMBSV02.realtek.com.tw> <6FAB7C47BCF00940BB0999A99BE3547A18DB7442@RTITMBSVM07.realtek.com.tw> <6FAB7C47BCF00940BB0999A99BE3547A18DB7463@RTITMBSVM07.realtek.com.tw> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Tue_Jan_29_14:22:45_2019-1" Return-path: Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 6E3C126749A for ; Tue, 29 Jan 2019 14:22:46 +0100 (CET) In-Reply-To: <6FAB7C47BCF00940BB0999A99BE3547A18DB7463@RTITMBSVM07.realtek.com.tw> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Kailang Cc: " (alsa-devel@alsa-project.org)" List-Id: alsa-devel@alsa-project.org --Multipart_Tue_Jan_29_14:22:45_2019-1 Content-Type: text/plain; charset=US-ASCII On Tue, 29 Jan 2019 09:39:56 +0100, Kailang wrote: > > Hi Takashi, > > So I think put it under alc269 parser. Maybe it is the quickly method. > > err = alc269_parse_auto_config(codec); > if (err < 0) > goto error; > + ..... > + ..... Not really... The init sequence needs to be applied in two different places: once in the init callback, and another in the resume callback but only for the hibernation restore. The patches below are applied on top of yours, and this should make things working. The first one lets the HD-audio core recording the currently processed PM event, and the second one evaluates it and applies the missing init sequence also for the hibernation resume. This isn't quite sexy, but it has the minimal change in the codec driver side. If this requirement is more common, we can think of splitting / reorganizing the codec callbacks to be more directly called from the device pm ops. thanks, Takashi --Multipart_Tue_Jan_29_14:22:45_2019-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="0001-ALSA-hda-Record-the-current-power-state-before-suspe.patch" Content-Transfer-Encoding: 7bit >>From 8028c19c7349737bfb002265b75af75c87d7c7a4 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 29 Jan 2019 14:03:33 +0100 Subject: [PATCH 1/2] ALSA: hda - Record the current power state before suspend/resume calls Currently we deal with single codec and suspend codec callbacks for all S3, S4 and runtime PM handling. But it turned out that we want distinguish the call patterns sometimes, e.g. for applying some init sequence only at probing and restoring from hibernate. This patch slightly modifies the common PM callbacks for HD-audio codec and stores the currently processed PM event in power_state of the codec's device.power field, which is currently unused. The codec callback can take a look at this event value and judges which purpose it's being called. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index e4704f5729d3..43bcc6f1ea8c 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -2917,6 +2917,7 @@ static void hda_call_codec_resume(struct hda_codec *codec) hda_jackpoll_work(&codec->jackpoll_work.work); else snd_hda_jack_report_sync(codec); + dev->power.power_state = PMSG_ON; snd_hdac_leave_pm(&codec->core); } @@ -2947,10 +2948,42 @@ static int hda_codec_runtime_resume(struct device *dev) } #endif /* CONFIG_PM */ +#ifdef CONFIG_PM_SLEEP +static int hda_codec_pm_suspend(struct device *dev) +{ + dev->power.power_state = PMSG_SUSPEND; + return pm_runtime_force_suspend(dev); +} + +static int hda_codec_pm_resume(struct device *dev) +{ + dev->power.power_state = PMSG_RESUME; + return pm_runtime_force_suspend(dev); +} + +static int hda_codec_pm_thaw(struct device *dev) +{ + dev->power.power_state = PMSG_THAW; + return pm_runtime_force_resume(dev); +} + +static int hda_codec_pm_restore(struct device *dev) +{ + dev->power.power_state = PMSG_RESTORE; + return pm_runtime_force_resume(dev); +} +#endif /* CONFIG_PM_SLEEP */ + /* referred in hda_bind.c */ const struct dev_pm_ops hda_codec_driver_pm = { - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, - pm_runtime_force_resume) +#ifdef CONFIG_PM_SLEEP + .suspend = hda_codec_pm_suspend, + .resume = hda_codec_pm_resume, + .freeze = hda_codec_pm_freeze, + .thaw = hda_codec_pm_thaw, + .poweroff = hda_codec_pm_suspend, + .restore = hda_codec_pm_restore, +#endif /* CONFIG_PM_SLEEP */ SET_RUNTIME_PM_OPS(hda_codec_runtime_suspend, hda_codec_runtime_resume, NULL) }; -- 2.16.4 --Multipart_Tue_Jan_29_14:22:45_2019-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="0002-ALSA-hda-realtek-Apply-ALC294-hp-init-also-for-S4-re.patch" Content-Transfer-Encoding: 7bit >>From 259f064043a264d6b45b3e9738947a24814d9ab0 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 29 Jan 2019 14:14:51 +0100 Subject: [PATCH 2/2] ALSA: hda/realtek - Apply ALC294 hp init also for S4 resume The init sequence for ALC294 headphone stuff is needed not only for the boot up time but also for the resume from hibernation, where the device is switched from the boot kernel without sound driver to the suspended image. Since we record the PM event in the device power_state field, we can now recognize the call pattern and apply the sequence conditionally. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_realtek.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 4139aced63f8..e9dc9408d9bc 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -3408,7 +3408,9 @@ static void alc294_init(struct hda_codec *codec) { struct alc_spec *spec = codec->spec; - if (!spec->done_hp_init) { + /* required only at boot or S4 resume time */ + if (!spec->done_hp_init || + codec->core.dev.power.power_state.event == PM_EVENT_RESTORE) { alc294_hp_init(codec); spec->done_hp_init = true; } -- 2.16.4 --Multipart_Tue_Jan_29_14:22:45_2019-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --Multipart_Tue_Jan_29_14:22:45_2019-1--