From patchwork Thu Aug 19 06:14:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1518447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 4GqvfJ1dZfz9t0T; Thu, 19 Aug 2021 16:16:08 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mGbLQ-0000ot-48; Thu, 19 Aug 2021 06:16:04 +0000 Received: from mail-pg1-f173.google.com ([209.85.215.173]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mGbKv-0000Jj-9U for kernel-team@lists.ubuntu.com; Thu, 19 Aug 2021 06:15:33 +0000 Received: by mail-pg1-f173.google.com with SMTP id c17so4887777pgc.0 for ; Wed, 18 Aug 2021 23:15:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y2X0Rp9+wyJWoAWmj+O9bygVgRkVUeZzML1UsbLFeNk=; b=YSSfabqfKyD5wUPqR8jn3KyNWhq5JdisivrayrzgDl21Dmsb8vK0gSx/W8v993o+gJ 22zOlpwZeJ8wJksNYfFbduOB7nySaL9AW/kIMv7N48z3XhsCAOoLvUEg52c97qXNlMlp v+YURx244NH5I959aq+9tT5uJu9gKvP8FxIQuff7cmKm0Y0Ud6/Hm7bu/PqF1owFvenu xkPBkIZB0E9NWu9Tx5idnIssxTUaq3YCrKk5C5VbHwKtJuYRjHQfvl1Lj/9hY83PRaNt iLs74b1SO+GQMvaXCpkG0jJm7QszNDPKpdEk0ekQ2jWpV3OVR6DLUVYzUMFvm1AgoT/s W7Uw== X-Gm-Message-State: AOAM532ugTUG/3hihOKdoYR+AqXA73reZR4EBEzHzGJZbHmCVMHmoWjj MpHPIfqa/CMRnC0QEzQUaYWBTHT32OhtTA== X-Google-Smtp-Source: ABdhPJyRRcDLTNjEYl8n8eE25f7O9B4BnwUBp8nAF6+vRa10t5zV1W8j20YyHp3WG234iAwZpMasBg== X-Received: by 2002:a63:4c0e:: with SMTP id z14mr12658966pga.427.1629353722475; Wed, 18 Aug 2021 23:15:22 -0700 (PDT) Received: from localhost (114-47-140-65.dynamic-ip.hinet.net. [114.47.140.65]) by smtp.gmail.com with ESMTPSA id j6sm1797237pfn.107.2021.08.18.23.15.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 23:15:22 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 29/30][SRU][OEM-5.13][I][U] UBUNTU: SAUCE: ALSA: hda/cs8409: Prevent pops and clicks during reboot Date: Thu, 19 Aug 2021 14:14:25 +0800 Message-Id: <20210819061427.900601-30-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210819061427.900601-1-vicamo.yang@canonical.com> References: <20210819061427.900601-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.173; envelope-from=vicamo@gmail.com; helo=mail-pg1-f173.google.com 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/1939541 During reboot, when the CS42L42 powers down, pops and clicks may occur due to the codec not being shutdown gracefully. This can be fixed by going through the suspend sequence, which shuts down the codec cleanly inside the reboot_notify hook, which is called on reboot. Signed-off-by: Stefan Binding Signed-off-by: Vitaly Rodionov (cherry picked from https://lore.kernel.org/lkml/20210812183433.6330-2-vitalyr@opensource.cirrus.com) Signed-off-by: You-Sheng Yang --- sound/pci/hda/patch_cs8409.c | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/sound/pci/hda/patch_cs8409.c b/sound/pci/hda/patch_cs8409.c index 9db16b6292f4..f51fc4a1545a 100644 --- a/sound/pci/hda/patch_cs8409.c +++ b/sound/pci/hda/patch_cs8409.c @@ -753,7 +753,6 @@ static void cs42l42_resume(struct sub_codec *cs42l42) cs42l42_enable_jack_detect(cs42l42); } -#ifdef CONFIG_PM static void cs42l42_suspend(struct sub_codec *cs42l42) { struct hda_codec *codec = cs42l42->codec; @@ -773,6 +772,9 @@ static void cs42l42_suspend(struct sub_codec *cs42l42) { 0x1101, 0xFF }, }; + if (cs42l42->suspended) + return; + cs8409_i2c_bulk_write(cs42l42, cs42l42_pwr_down_seq, ARRAY_SIZE(cs42l42_pwr_down_seq)); if (read_poll_timeout(cs8409_i2c_read, reg_cdc_status, @@ -790,7 +792,6 @@ static void cs42l42_suspend(struct sub_codec *cs42l42) gpio_data &= ~cs42l42->reset_gpio; snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, gpio_data); } -#endif static void cs8409_free(struct hda_codec *codec) { @@ -803,6 +804,33 @@ static void cs8409_free(struct hda_codec *codec) snd_hda_gen_free(codec); } +/* Manage PDREF, when transition to D3hot */ +static int cs8409_cs42l42_suspend(struct hda_codec *codec) +{ + struct cs8409_spec *spec = codec->spec; + int i; + + cs8409_enable_ur(codec, 0); + + for (i = 0; i < spec->num_scodecs; i++) + cs42l42_suspend(spec->scodecs[i]); + + /* Cancel i2c clock disable timer, and disable clock if left enabled */ + cancel_delayed_work_sync(&spec->i2c_clk_work); + cs8409_disable_i2c_clock(codec); + + snd_hda_shutup_pins(codec); + + return 0; +} + +static void cs8409_reboot_notify(struct hda_codec *codec) +{ + cs8409_cs42l42_suspend(codec); + snd_hda_gen_reboot_notify(codec); + codec->patch_ops.free(codec); +} + /****************************************************************************** * BULLSEYE / WARLOCK / CYBORG Specific Functions * CS8409/CS42L42 @@ -845,28 +873,6 @@ static void cs8409_cs42l42_jack_unsol_event(struct hda_codec *codec, unsigned in } } -#ifdef CONFIG_PM -/* Manage PDREF, when transition to D3hot */ -static int cs8409_cs42l42_suspend(struct hda_codec *codec) -{ - struct cs8409_spec *spec = codec->spec; - int i; - - cs8409_enable_ur(codec, 0); - - for (i = 0; i < spec->num_scodecs; i++) - cs42l42_suspend(spec->scodecs[i]); - - /* Cancel i2c clock disable timer, and disable clock if left enabled */ - cancel_delayed_work_sync(&spec->i2c_clk_work); - cs8409_disable_i2c_clock(codec); - - snd_hda_shutup_pins(codec); - - return 0; -} -#endif - /* Vendor specific HW configuration * PLL, ASP, I2C, SPI, GPIOs, DMIC etc... */ @@ -910,6 +916,7 @@ static const struct hda_codec_ops cs8409_cs42l42_patch_ops = { .init = cs8409_init, .free = cs8409_free, .unsol_event = cs8409_cs42l42_jack_unsol_event, + .reboot_notify = cs8409_reboot_notify, #ifdef CONFIG_PM .suspend = cs8409_cs42l42_suspend, #endif @@ -1121,6 +1128,7 @@ static const struct hda_codec_ops cs8409_dolphin_patch_ops = { .init = cs8409_init, .free = cs8409_free, .unsol_event = dolphin_jack_unsol_event, + .reboot_notify = cs8409_reboot_notify, #ifdef CONFIG_PM .suspend = cs8409_cs42l42_suspend, #endif