From patchwork Fri Nov 26 04:06:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1559944 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=OsRZZFOh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J0h5x2V74z9t4b for ; Fri, 26 Nov 2021 15:07:15 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mqSVq-0002GL-K9; Fri, 26 Nov 2021 04:07:02 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mqSVn-0002ES-2v for kernel-team@lists.ubuntu.com; Fri, 26 Nov 2021 04:06:59 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id DF95D3F1BF for ; Fri, 26 Nov 2021 04:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1637899618; bh=TzGp+uu7G154khZOqnBJDBfkuC5hG2hhkF2ubI/aQYc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OsRZZFOhLATyVl9N0m0oPou/PAgmGM+2fAhx2dvG6QGyxdQv1CsgP057yX4FPiNDp pzZnyOd8Gl+jcEH7eoZEe4IrcXP1AQyEZM+U/7CUqW6S6ShGD5yFWKJ25egwN+sjrs QJVKGtbJEswpujKGNCqUXB3jdnuZ5AbUa/+H8xOYyPdodBBfxgQNMLm43r66ccdjV2 GbHPPfZ4NcdaUoWNJmlNpsy8hnXCIEJV1Ql4UdUj0wI8ZPBGiCA5+0qiqZJOTtcMNZ TwcVfVZ2TEK8mKeDKOOULZSUUNEh8bk7KKETYTVeG3aClOESHI6HFChtUe89PVZwVK n3+CBAjs9sJBg== Received: by mail-pj1-f69.google.com with SMTP id g14-20020a17090a578e00b001a79264411cso2636150pji.3 for ; Thu, 25 Nov 2021 20:06:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TzGp+uu7G154khZOqnBJDBfkuC5hG2hhkF2ubI/aQYc=; b=QqHog/1+s3pyZvmGjdQF8VKMlshoMeqASXS8yuDkZH6DshiVS9/zIc2JT+N3UhDHts gxydAxPsbIPCiWc2pIgVQ54J9HO0ZOQVpaFf3igGpzduJliXW/WdJj3zLIzNr7Le/jY6 VYd5KxxjgYuy0/lxLdxdyFZ/hc06Ed3ixZjw0tc02K0Gz/6oNxAxXzF1md/9RCbxtDfR TT4cxHRd+mwlxhsS/RdgkXW1IP8h9yrSqVo5/hZuOcrprByikBEuZIMWmFiPwGn6i2XF dj7Uyn+nR12hSQlzpHQBoISFDJy5m9o2P4nLjIHXqP7lDCJMdvA5Mt/nc6Fp1GlHBlJu 7epQ== X-Gm-Message-State: AOAM531CvSs9AzpSPgnyAAB+n6I1OHuX+bAYQhGYnQUEHcsAe/l6nJdE +LLhGe0ThdmuNTf8QJH8owc5sTHNwP1ToOB9ZExtvWVbyifQUpTfaNvqwKWKOXZ4GzuPYd8RQvz bpiQ/xF1RHeN1ppsYt1cPetMUQ5ya7y8U5umo/NW2UA== X-Received: by 2002:a17:90a:fe0a:: with SMTP id ck10mr12748098pjb.216.1637899617153; Thu, 25 Nov 2021 20:06:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJybgxvk/D03xmanJzjUljWgqkHRYLUhRP1/JHbBSgxaWHnDK2LZZKbvwOyRXdhPXKzX/5B+NA== X-Received: by 2002:a17:90a:fe0a:: with SMTP id ck10mr12748056pjb.216.1637899616690; Thu, 25 Nov 2021 20:06:56 -0800 (PST) Received: from localhost.localdomain (111-240-133-170.dynamic-ip.hinet.net. [111.240.133.170]) by smtp.gmail.com with ESMTPSA id h3sm5320157pfc.204.2021.11.25.20.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 20:06:56 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/1][SRU][OEM-5.13/OEM-5.14] UBUNTU: SAUCE: ALSA: hda/cs8409: Schedule delayed work for jack detect on resume Date: Fri, 26 Nov 2021 12:06:50 +0800 Message-Id: <20211126040650.49068-2-chris.chiu@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211126040650.49068-1-chris.chiu@canonical.com> References: <20211126040650.49068-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stefan Binding BugLink: https://bugs.launchpad.net/bugs/1952385 CS42L42 runs jack detect on resume, however this requires unsol events, and unsol events are ignored whilst the power state is not set to ON. The power state is set to ON only after the resume finishes. Schedule a delayed work timer to run jack detect after the resume call finishes. Signed-off-by: Stefan Binding Signed-off-by: Vitaly Rodionov Signed-off-by: Chris Chiu --- sound/pci/hda/patch_cs8409.c | 79 +++++++++++++++++++++++++++++------- sound/pci/hda/patch_cs8409.h | 1 + 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/sound/pci/hda/patch_cs8409.c b/sound/pci/hda/patch_cs8409.c index 31ff11ab868e..88213e95f0b3 100644 --- a/sound/pci/hda/patch_cs8409.c +++ b/sound/pci/hda/patch_cs8409.c @@ -634,6 +634,30 @@ static void cs42l42_run_jack_detect(struct sub_codec *cs42l42) cs8409_i2c_write(cs42l42, 0x1120, 0xc0); } +static void cs42l42_run_jack_detect_all(struct hda_codec *codec) +{ + struct cs8409_spec *spec = codec->spec; + struct sub_codec *cs42l42; + int i; + + for (i = 0; i < spec->num_scodecs; i++) { + cs42l42 = spec->scodecs[i]; + cs42l42_enable_jack_detect(cs42l42); + if (!cs42l42->hp_jack_in) + cs42l42_run_jack_detect(cs42l42); + } +} + +/* + * cs42l42_jack_detect_worker - Worker that retries jack detect + */ +static void cs42l42_jack_detect_worker(struct work_struct *work) +{ + struct cs8409_spec *spec = container_of(work, struct cs8409_spec, jack_detect_work.work); + + cs42l42_run_jack_detect_all(spec->codec); +} + static int cs42l42_handle_tip_sense(struct sub_codec *cs42l42, unsigned int reg_ts_status) { int status_changed = 0; @@ -749,8 +773,6 @@ static void cs42l42_resume(struct sub_codec *cs42l42) if (cs42l42->full_scale_vol) cs8409_i2c_write(cs42l42, 0x2001, 0x01); - - cs42l42_enable_jack_detect(cs42l42); } #ifdef CONFIG_PM @@ -800,6 +822,7 @@ static void cs8409_free(struct hda_codec *codec) /* Cancel i2c clock disable timer, and disable clock if left enabled */ cancel_delayed_work_sync(&spec->i2c_clk_work); + cancel_delayed_work_sync(&spec->jack_detect_work); cs8409_disable_i2c_clock(codec); snd_hda_gen_free(codec); @@ -863,6 +886,7 @@ static int cs8409_cs42l42_suspend(struct hda_codec *codec) /* Cancel i2c clock disable timer, and disable clock if left enabled */ cancel_delayed_work_sync(&spec->i2c_clk_work); + cancel_delayed_work_sync(&spec->jack_detect_work); cs8409_disable_i2c_clock(codec); snd_hda_shutup_pins(codec); @@ -970,6 +994,8 @@ void cs8409_cs42l42_fixups(struct hda_codec *codec, const struct hda_fixup *fix, spec->scodecs[CS8409_CODEC0]->codec = codec; codec->patch_ops = cs8409_cs42l42_patch_ops; + INIT_DELAYED_WORK(&spec->jack_detect_work, cs42l42_jack_detect_worker); + spec->gen.suppress_auto_mute = 1; spec->gen.no_primary_hp = 1; spec->gen.suppress_vmaster = 1; @@ -1029,9 +1055,16 @@ void cs8409_cs42l42_fixups(struct hda_codec *codec, const struct hda_fixup *fix, case HDA_FIXUP_ACT_INIT: cs8409_cs42l42_hw_init(codec); spec->init_done = 1; - if (spec->init_done && spec->build_ctrl_done - && !spec->scodecs[CS8409_CODEC0]->hp_jack_in) - cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]); + if (spec->init_done && spec->build_ctrl_done) { + /* No point in running jack detect until we have fully resumed */ + if (codec->core.dev.power.power_state.event != PM_EVENT_ON) { + codec_warn(codec, "Not ready to detect jack, deferring...\n"); + schedule_delayed_work(&spec->jack_detect_work, msecs_to_jiffies(25)); + return; + } else { + cs42l42_run_jack_detect_all(codec); + } + } break; case HDA_FIXUP_ACT_BUILD: spec->build_ctrl_done = 1; @@ -1040,9 +1073,16 @@ void cs8409_cs42l42_fixups(struct hda_codec *codec, const struct hda_fixup *fix, * been already plugged in. * Run immediately after init. */ - if (spec->init_done && spec->build_ctrl_done - && !spec->scodecs[CS8409_CODEC0]->hp_jack_in) - cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]); + if (spec->init_done && spec->build_ctrl_done) { + /* No point in running jack detect until we have fully resumed */ + if (codec->core.dev.power.power_state.event != PM_EVENT_ON) { + codec_warn(codec, "Not ready to detect jack, deferring...\n"); + schedule_delayed_work(&spec->jack_detect_work, msecs_to_jiffies(25)); + return; + } else { + cs42l42_run_jack_detect_all(codec); + } + } break; default: break; @@ -1178,7 +1218,6 @@ void dolphin_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int ac { struct cs8409_spec *spec = codec->spec; struct snd_kcontrol_new *kctrl; - int i; switch (action) { case HDA_FIXUP_ACT_PRE_PROBE: @@ -1193,6 +1232,8 @@ void dolphin_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int ac spec->scodecs[CS8409_CODEC1]->codec = codec; spec->num_scodecs = 2; + INIT_DELAYED_WORK(&spec->jack_detect_work, cs42l42_jack_detect_worker); + codec->patch_ops = cs8409_dolphin_patch_ops; /* GPIO 1,5 out, 0,4 in */ @@ -1237,9 +1278,13 @@ void dolphin_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int ac dolphin_hw_init(codec); spec->init_done = 1; if (spec->init_done && spec->build_ctrl_done) { - for (i = 0; i < spec->num_scodecs; i++) { - if (!spec->scodecs[i]->hp_jack_in) - cs42l42_run_jack_detect(spec->scodecs[i]); + /* No point in running jack detect until we have fully resumed */ + if (codec->core.dev.power.power_state.event != PM_EVENT_ON) { + codec_warn(codec, "Not ready to detect jack, deferring...\n"); + schedule_delayed_work(&spec->jack_detect_work, msecs_to_jiffies(25)); + return; + } else { + cs42l42_run_jack_detect_all(codec); } } break; @@ -1251,9 +1296,13 @@ void dolphin_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int ac * Run immediately after init. */ if (spec->init_done && spec->build_ctrl_done) { - for (i = 0; i < spec->num_scodecs; i++) { - if (!spec->scodecs[i]->hp_jack_in) - cs42l42_run_jack_detect(spec->scodecs[i]); + /* No point in running jack detect until we have fully resumed */ + if (codec->core.dev.power.power_state.event != PM_EVENT_ON) { + codec_warn(codec, "Not ready to detect jack, deferring...\n"); + schedule_delayed_work(&spec->jack_detect_work, msecs_to_jiffies(25)); + return; + } else { + cs42l42_run_jack_detect_all(codec); } } break; diff --git a/sound/pci/hda/patch_cs8409.h b/sound/pci/hda/patch_cs8409.h index ade2b838590c..632d3ec8322d 100644 --- a/sound/pci/hda/patch_cs8409.h +++ b/sound/pci/hda/patch_cs8409.h @@ -330,6 +330,7 @@ struct cs8409_spec { unsigned int i2c_clck_enabled; unsigned int dev_addr; struct delayed_work i2c_clk_work; + struct delayed_work jack_detect_work; unsigned int playback_started:1; unsigned int capture_started:1;