From patchwork Sun Dec 31 16:33:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13507262 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A79BA7476 for ; Sun, 31 Dec 2023 16:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B/vG1kiL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704040413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WcPKqcziUFTnDsajzis9/eBZaXJtJhW3QMCvWtQiRmQ=; b=B/vG1kiLXGuKPs5nfeMAx5DbkH6ll2lUSHBBrw1gBMhAYFmpkiqoFOH2FQBpqjMnlrz75k BAtsamguKqaGFABCYiIGZ41Q5VOkHcy9ZLMYq6seO5zVckc9mTbpEOXF6pTSulneQXmLxG tIhdRs36jpYMtMn7rR7mgwd4/AHMPDE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-PiKVBY25PA2gJtUn5B_ChA-1; Sun, 31 Dec 2023 11:33:29 -0500 X-MC-Unique: PiKVBY25PA2gJtUn5B_ChA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 552FF101A52A; Sun, 31 Dec 2023 16:33:29 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D7FDC15E6C; Sun, 31 Dec 2023 16:33:27 +0000 (UTC) From: Hans de Goede To: Johannes Stezenbach , Takashi Iwai , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, x86@kernel.org Subject: [PATCH 1/4] platform/x86: pmc_atom: Annotate d3_sts register bit defines Date: Sun, 31 Dec 2023 17:33:19 +0100 Message-ID: <20231231163322.9492-2-hdegoede@redhat.com> In-Reply-To: <20231231163322.9492-1-hdegoede@redhat.com> References: <20231231163322.9492-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 The include/linux/platform_data/x86/pmc_atom.h d3_sts register bit defines are named after how these bits are used on Bay Trail devices. On Cherry Trail (CHT) devices some of these bits have a different meaning according to the datasheet. At a comment to the defines for bits which have a different meaning on Cherry Trail devices. Signed-off-by: Hans de Goede --- include/linux/platform_data/x86/pmc_atom.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/platform_data/x86/pmc_atom.h b/include/linux/platform_data/x86/pmc_atom.h index b8a701c77fd0..5eec0e22acdf 100644 --- a/include/linux/platform_data/x86/pmc_atom.h +++ b/include/linux/platform_data/x86/pmc_atom.h @@ -104,14 +104,14 @@ #define BIT_SCC_SDIO BIT(9) #define BIT_SCC_SDCARD BIT(10) #define BIT_SCC_MIPI BIT(11) -#define BIT_HDA BIT(12) +#define BIT_HDA BIT(12) /* CHT datasheet: reserved */ #define BIT_LPE BIT(13) #define BIT_OTG BIT(14) -#define BIT_USH BIT(15) -#define BIT_GBE BIT(16) -#define BIT_SATA BIT(17) -#define BIT_USB_EHCI BIT(18) -#define BIT_SEC BIT(19) +#define BIT_USH BIT(15) /* CHT datasheet: reserved */ +#define BIT_GBE BIT(16) /* CHT datasheet: reserved */ +#define BIT_SATA BIT(17) /* CHT datasheet: reserved */ +#define BIT_USB_EHCI BIT(18) /* CHT datasheet: XHCI! */ +#define BIT_SEC BIT(19) /* BYT datasheet: reserved */ #define BIT_PCIE_PORT0 BIT(20) #define BIT_PCIE_PORT1 BIT(21) #define BIT_PCIE_PORT2 BIT(22) From patchwork Sun Dec 31 16:33:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13507263 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 413188484 for ; Sun, 31 Dec 2023 16:33:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h4gvyPqy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704040415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jy2ggSLvM5SLvy+vAKZJKvRDZmKa5xq023novpbhPp8=; b=h4gvyPqytTOv36FxkEzj85n0nHIQG7lG0q141JtAjCSDZX2TpxpCfmVrXuAFEqlUPXXbsu EHp+pCYXTD3eTOcdBOT58FU99rfwmTtNiRUsRm5LWdhiy5wI1tiN5fO6KVwAXaRpLA3whx MC55UvaRgZItjLfbPocqzPLL+yZ2WkA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-262-fXi_7uczOw2xuK73ljNHSw-1; Sun, 31 Dec 2023 11:33:31 -0500 X-MC-Unique: fXi_7uczOw2xuK73ljNHSw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 121ED185A783; Sun, 31 Dec 2023 16:33:31 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86E85C15A0C; Sun, 31 Dec 2023 16:33:29 +0000 (UTC) From: Hans de Goede To: Johannes Stezenbach , Takashi Iwai , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, x86@kernel.org Subject: [PATCH 2/4] platform/x86: pmc_atom: Check state of PMC managed devices on s2idle Date: Sun, 31 Dec 2023 17:33:20 +0100 Message-ID: <20231231163322.9492-3-hdegoede@redhat.com> In-Reply-To: <20231231163322.9492-1-hdegoede@redhat.com> References: <20231231163322.9492-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 From: Johannes Stezenbach This is a port of "pm: Add pm suspend debug notifier for South IPs" from the latte-l-oss branch of: from https://github.com/MiCode/Xiaomi_Kernel_OpenSource latte-l-oss With the new acpi_s2idle_dev_ops and acpi_register_lps0_dev() functionality this can now finally be ported to the mainline kernel without requiring adding non-upstreamable hooks into the cpu_idle driver mechanism. This adds a check that all hardware blocks in the South complex (controlled by PMC) are in a state that allows the SoC to enter S0i3 and prints an error message for any device in D0. Note the pmc_atom code is enabled by CONFIG_X86_INTEL_LPSS which already depends on ACPI. Signed-off-by: Johannes Stezenbach Signed-off-by: Takashi Iwai [hdegoede: Use acpi_s2idle_dev_ops, ignore fused off blocks, PMIC I2C] Signed-off-by: Hans de Goede --- drivers/platform/x86/pmc_atom.c | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/platform/x86/pmc_atom.c b/drivers/platform/x86/pmc_atom.c index 93a6414c6611..e14d489fa6f9 100644 --- a/drivers/platform/x86/pmc_atom.c +++ b/drivers/platform/x86/pmc_atom.c @@ -6,6 +6,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include struct pmc_bit_map { const char *name; @@ -448,6 +450,67 @@ static int pmc_setup_clks(struct pci_dev *pdev, void __iomem *pmc_regmap, return 0; } +#ifdef CONFIG_SUSPEND +static void pmc_dev_state_check(u32 sts, const struct pmc_bit_map *sts_map, + u32 fd, const struct pmc_bit_map *fd_map, + u32 sts_possible_false_pos) +{ + int index; + + for (index = 0; sts_map[index].name; index++) { + if (!(fd_map[index].bit_mask & fd) && + !(sts_map[index].bit_mask & sts)) { + if (sts_map[index].bit_mask & sts_possible_false_pos) + pm_pr_dbg("pmc_atom: %s is in D0 prior to s2idle\n", + sts_map[index].name); + else + pr_err("pmc_atom: %s is in D0 prior to s2idle\n", + sts_map[index].name); + } + } +} + +static void pmc_s2idle_check(void) +{ + struct pmc_dev *pmc = &pmc_device; + const struct pmc_reg_map *m = pmc->map; + u32 func_dis, func_dis_2; + u32 d3_sts_0, d3_sts_1; + u32 false_pos_sts_0, false_pos_sts_1; + + func_dis = pmc_reg_read(pmc, PMC_FUNC_DIS); + func_dis_2 = pmc_reg_read(pmc, PMC_FUNC_DIS_2); + d3_sts_0 = pmc_reg_read(pmc, PMC_D3_STS_0); + d3_sts_1 = pmc_reg_read(pmc, PMC_D3_STS_1); + + /* + * Some blocks are not used on lower-featured versions of the SoC and + * always report D0, add these to false_pos mask to log at debug lvl. + */ + if (m->d3_sts_1 == byt_d3_sts_1_map) { + /* BYT */ + false_pos_sts_0 = BIT_GBE | BIT_SATA | BIT_PCIE_PORT0 | + BIT_PCIE_PORT1 | BIT_PCIE_PORT2 | BIT_PCIE_PORT3 | + BIT_LPSS2_F5_I2C5; + false_pos_sts_1 = BIT_SMB | BIT_USH_SS_PHY | BIT_DFX; + } else { + /* CHT */ + false_pos_sts_0 = BIT_GBE | BIT_SATA | BIT_LPSS2_F7_I2C7; + false_pos_sts_1 = BIT_SMB | BIT_STS_ISH; + } + + /* Low part */ + pmc_dev_state_check(d3_sts_0, m->d3_sts_0, func_dis, m->func_dis, false_pos_sts_0); + + /* High part */ + pmc_dev_state_check(d3_sts_1, m->d3_sts_1, func_dis_2, m->func_dis_2, false_pos_sts_1); +} + +static struct acpi_s2idle_dev_ops pmc_s2idle_ops = { + .check = pmc_s2idle_check, +}; +#endif + static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent) { struct pmc_dev *pmc = &pmc_device; @@ -485,6 +548,10 @@ static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent) dev_warn(&pdev->dev, "platform clocks register failed: %d\n", ret); +#ifdef CONFIG_SUSPEND + acpi_register_lps0_dev(&pmc_s2idle_ops); +#endif + pmc->init = true; return ret; } From patchwork Sun Dec 31 16:33:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13507264 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22B4D8484 for ; Sun, 31 Dec 2023 16:33:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dCqoSd2T" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704040417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=543pdg4531ECC9zNmaAP/X0vwyC4F12wBQA0D68vE0k=; b=dCqoSd2TzdaAzMqnh4NLH20RNGy0sGwyVRGyIo7fdY1/shECGYorFZIXw9QMnJNWMt24Q7 ziBes2b59AigBTX8FdFwyS5RkC8ak49y52Khs0ehszrsP5UYKWUifkwhbSoe5samHuwqgS 34hzijJ8Ey8kY3sost9XhjqO4/rCTHc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-zORWLyCdMGa31qFs5Gb_BA-1; Sun, 31 Dec 2023 11:33:33 -0500 X-MC-Unique: zORWLyCdMGa31qFs5Gb_BA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id F23F81C07540; Sun, 31 Dec 2023 16:33:32 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42A73C15968; Sun, 31 Dec 2023 16:33:31 +0000 (UTC) From: Hans de Goede To: Johannes Stezenbach , Takashi Iwai , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, x86@kernel.org Subject: [PATCH 3/4] platform/x86: pmc_atom: Check state of PMC clocks on s2idle Date: Sun, 31 Dec 2023 17:33:21 +0100 Message-ID: <20231231163322.9492-4-hdegoede@redhat.com> In-Reply-To: <20231231163322.9492-1-hdegoede@redhat.com> References: <20231231163322.9492-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Extend the s2idle check with checking that none of the PMC clocks is in the forced on state. If one of the clocks is in forced on state then S0i3 cannot be reached. Signed-off-by: Hans de Goede --- drivers/platform/x86/pmc_atom.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/platform/x86/pmc_atom.c b/drivers/platform/x86/pmc_atom.c index e14d489fa6f9..375010ef61ae 100644 --- a/drivers/platform/x86/pmc_atom.c +++ b/drivers/platform/x86/pmc_atom.c @@ -20,6 +20,14 @@ #include #include +#define PMC_CLK_CTL_OFFSET 0x60 +#define PMC_CLK_NUM 6 +#define PMC_CLK_CTL_GATED_ON_D3 0x0 +#define PMC_CLK_CTL_FORCE_ON 0x1 +#define PMC_CLK_CTL_FORCE_OFF 0x2 +#define PMC_CLK_CTL_RESERVED 0x3 +#define PMC_MASK_CLK_CTL GENMASK(1, 0) + struct pmc_bit_map { const char *name; u32 bit_mask; @@ -477,6 +485,7 @@ static void pmc_s2idle_check(void) u32 func_dis, func_dis_2; u32 d3_sts_0, d3_sts_1; u32 false_pos_sts_0, false_pos_sts_1; + int i; func_dis = pmc_reg_read(pmc, PMC_FUNC_DIS); func_dis_2 = pmc_reg_read(pmc, PMC_FUNC_DIS_2); @@ -504,6 +513,16 @@ static void pmc_s2idle_check(void) /* High part */ pmc_dev_state_check(d3_sts_1, m->d3_sts_1, func_dis_2, m->func_dis_2, false_pos_sts_1); + + /* Check PMC clocks */ + for (i = 0; i < PMC_CLK_NUM; i++) { + u32 ctl = pmc_reg_read(pmc, PMC_CLK_CTL_OFFSET + 4 * i); + + if ((ctl & PMC_MASK_CLK_CTL) != PMC_CLK_CTL_FORCE_ON) + continue; + + pr_err("pmc_atom: clk %d is ON prior to freeze (ctl %08x)\n", i, ctl); + } } static struct acpi_s2idle_dev_ops pmc_s2idle_ops = { From patchwork Sun Dec 31 16:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13507265 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4AA58483 for ; Sun, 31 Dec 2023 16:33:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g2sCNH+F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704040418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hpArVQLj57Rr7iXvC+/YVZTaR/YLrYEeueGBuC4mDP8=; b=g2sCNH+FiOzBjPPKEvFT9XzDf64DrjAcwLywJrG2lD5379rkHXoM7v3azNDy/nYUfe4lKw SItLWP1ewqESBhD2eksSkHRWC+1Vj644WXqOcFu1vqKKtf3T4IDRqyUmXzpahz7fPcb+yI 8p1aTIcisyoTwZ4P6l/1N8XM6xrn93s= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-l1YFIPYNNPaSKYzZwngfig-1; Sun, 31 Dec 2023 11:33:35 -0500 X-MC-Unique: l1YFIPYNNPaSKYzZwngfig-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id B43852824760; Sun, 31 Dec 2023 16:33:34 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F60DC15E6C; Sun, 31 Dec 2023 16:33:33 +0000 (UTC) From: Hans de Goede To: Johannes Stezenbach , Takashi Iwai , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, x86@kernel.org Subject: [PATCH 4/4] x86/platform/atom: Check state of Punit managed devices on s2idle Date: Sun, 31 Dec 2023 17:33:22 +0100 Message-ID: <20231231163322.9492-5-hdegoede@redhat.com> In-Reply-To: <20231231163322.9492-1-hdegoede@redhat.com> References: <20231231163322.9492-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 From: Johannes Stezenbach This is a port of "pm: Add pm suspend debug notifier for North IPs" from the latte-l-oss branch of: from https://github.com/MiCode/Xiaomi_Kernel_OpenSource latte-l-oss With the new acpi_s2idle_dev_ops and acpi_register_lps0_dev() functionality this can now finally be ported to the mainline kernel without requiring adding non-upstreamable hooks into the cpu_idle driver mechanism. This adds a check that all hardware blocks in the North complex (controlled by Punit) are in a state that allows the SoC to enter S0i3 and prints an error message for any device in D0. Signed-off-by: Johannes Stezenbach Signed-off-by: Takashi Iwai [hdegoede: Use acpi_s2idle_dev_ops] Signed-off-by: Hans de Goede --- arch/x86/platform/atom/punit_atom_debug.c | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/arch/x86/platform/atom/punit_atom_debug.c b/arch/x86/platform/atom/punit_atom_debug.c index f8ed5f66cd20..efa4b188300d 100644 --- a/arch/x86/platform/atom/punit_atom_debug.c +++ b/arch/x86/platform/atom/punit_atom_debug.c @@ -7,6 +7,9 @@ * Copyright (c) 2015, Intel Corporation. */ +#define pr_fmt(fmt) "punit_atom: " fmt + +#include #include #include #include @@ -102,10 +105,12 @@ static int punit_dev_state_show(struct seq_file *seq_file, void *unused) } DEFINE_SHOW_ATTRIBUTE(punit_dev_state); +static const struct punit_device *punit_dev; static struct dentry *punit_dbg_file; static void punit_dbgfs_register(struct punit_device *punit_device) { + punit_dev = punit_device; punit_dbg_file = debugfs_create_dir("punit_atom", NULL); debugfs_create_file("dev_power_state", 0444, punit_dbg_file, @@ -117,6 +122,35 @@ static void punit_dbgfs_unregister(void) debugfs_remove_recursive(punit_dbg_file); } +#if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND) +static void punit_s2idle_check(void) +{ + const struct punit_device *punit_devp; + u32 punit_pwr_status, dstate; + int status; + + for (punit_devp = punit_dev; punit_devp->name; punit_devp++) { + /* Skip MIO this is on till the very last moment */ + if (punit_devp->reg == MIO_SS_PM) + continue; + + status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, + punit_devp->reg, &punit_pwr_status); + if (status) { + pr_err("%s read failed\n", punit_devp->name); + } else { + dstate = (punit_pwr_status >> punit_devp->sss_pos) & 3; + if (!dstate) + pr_err("%s is in D0 prior to s2idle\n", punit_devp->name); + } + } +} + +static struct acpi_s2idle_dev_ops punit_s2idle_ops = { + .check = punit_s2idle_check, +}; +#endif + #define X86_MATCH(model, data) \ X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, INTEL_FAM6_##model, \ X86_FEATURE_MWAIT, data) @@ -138,12 +172,18 @@ static int __init punit_atom_debug_init(void) return -ENODEV; punit_dbgfs_register((struct punit_device *)id->driver_data); +#if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND) + acpi_register_lps0_dev(&punit_s2idle_ops); +#endif return 0; } static void __exit punit_atom_debug_exit(void) { +#if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND) + acpi_unregister_lps0_dev(&punit_s2idle_ops); +#endif punit_dbgfs_unregister(); }