Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3667361rdb; Wed, 13 Sep 2023 21:20:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPzTqOjnphFyA+rNLnzwu0UC4dUTt4+ju/H6rEPfqmr8aAc2KY0xsz+1u1WRzjbp/aPYEz X-Received: by 2002:a17:902:da92:b0:1bb:b226:52b1 with SMTP id j18-20020a170902da9200b001bbb22652b1mr5111294plx.17.1694665233416; Wed, 13 Sep 2023 21:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694665233; cv=none; d=google.com; s=arc-20160816; b=nNeg0A3MpxHscDcwjpt9dqffMaASFxWpiC0EXGXZb57MTbICB5V/3oRvKO65Jp3CTL 0CxRr+aheMLBh/nIv/qLEZmkYSR5gwTQZb0ss3D1EriZgjZCggpeC0MNHg6siS3FPj9c RVuY12d2iwL8wJRIF6hB8he90+A4KphitSieoCR+E8hPlmpQM+m/F1Abd7dBTkWXNhBL rXGgAVVlGSXz3xV2xG0KMJWnqvCoyHUZQwNCurQJU7IRnTlJJgPR36uxtQyMSc+92Slt lMlj0QHKS5xUxuvDZNry21twGJbLj1iXY3s/CbdB57jLdY6Uiah7mywZ33GL1wtdm/lo 2mLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Lho36GEnh8mwb5BIYDn31SsZ6Q3vPfyCON6SNIWmCYQ=; fh=ysEtad20VAKEbrGTZfnSJZVwtWCLTeikzHd2HyPuQ5c=; b=wh4BHt91nzzw58dzFTgv4Zdseap8dq9RYTM+ucj+w8h1f0BKMwNRXe51kRlReEvBe+ nmc5Y6ew4ov2jKAOs/A1Hf9hgfI+3pyRGD0uEJp39jZ9QyiIITZp79ouN9ltZefwEYvH Nuj+V8/9Xo7ttop8NZYIXkXqqovk9i+WbYddJblOZGu5uUKNBxCjz70E2KSaVLAMQnY4 PhZI8A18tAk9UPdHA2gpIHEV+yUmAXDJyWs/nhd60IQwanDuRxJ8xCvcWIw4Zeh9GtTy zvKmzf7Hh966ZI1/uHHCU/yE5FDkHjVdqoVksl/ZCp4sikXkIB7VRZ1g3RiIXfdH5lDn 1wMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=dBRTykUi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id z13-20020a1709027e8d00b001ab1ba2572csi501116pla.240.2023.09.13.21.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 21:20:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=dBRTykUi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 68E348029C7A; Wed, 13 Sep 2023 21:19:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233209AbjINETJ (ORCPT + 99 others); Thu, 14 Sep 2023 00:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231181AbjINETH (ORCPT ); Thu, 14 Sep 2023 00:19:07 -0400 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97C86E59; Wed, 13 Sep 2023 21:19:03 -0700 (PDT) Received: from localhost.localdomain (unknown [10.101.196.174]) (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-canonical-1.canonical.com (Postfix) with ESMTPSA id 7A0373F6F2; Thu, 14 Sep 2023 04:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1694665138; bh=Lho36GEnh8mwb5BIYDn31SsZ6Q3vPfyCON6SNIWmCYQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dBRTykUioqWAd85z8o+AfXFmSNSD0l75GzfeUEVBQWs1w2O+Yo/dIRTF5SZsgm7zB 6s4g4sFkQfEcLqZvKVhSczCOaRtvpr708jyct1V1IPYdOekNlQRYRklhTWsOAVmg4t aC49r0WowkziorTkwEMfPZmWIVQnDqJ41EutUAydsyd/ucooUTGLd1BwICjQ9iO+Pu C7HKha4R5vhK0aeoE98/tfPo9M0Y3nliQRTHYAWs4d6N/FyPJhrPuTW/ww3GpmzeGC Oa9t9x+YuX1L00yCccnoekXd2KnrmnPfxoQ88bRCgG5QFT+YH0nX9exbjdGv2ypAd2 4zW9CIOH1DYrQ== From: Kai-Heng Feng To: srinivas.pandruvada@linux.intel.com, jikos@kernel.org, benjamin.tissoires@redhat.com Cc: linux-pm@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng , Jian Hui Lee , Even Xu , Zhang Lixu , Najumon Ba , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: intel-ish-hid: ipc: Rework EHL OOB wakeup Date: Thu, 14 Sep 2023 12:18:05 +0800 Message-Id: <20230914041806.816741-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 13 Sep 2023 21:19:13 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email System cannot suspend more than 255 times because the driver doesn't have corresponding acpi_disable_gpe() for acpi_enable_gpe(), so the GPE refcount overflows. Since PCI core and ACPI core already handles PCI PME wake and GPE wake when the device has wakeup capability, use device_init_wakeup() to let them do the wakeup setting work. Also add a shutdown callback which uses pci_prepare_to_sleep() to let PCI and ACPI set OOB wakeup for S5. Fixes: 2e23a70edabe ("HID: intel-ish-hid: ipc: finish power flow for EHL OOB") Cc: Jian Hui Lee Signed-off-by: Kai-Heng Feng --- drivers/hid/intel-ish-hid/ipc/pci-ish.c | 59 +++++++------------------ 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c index 55cb25038e63..65e7eeb2fa64 100644 --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c @@ -119,42 +119,6 @@ static inline bool ish_should_leave_d0i3(struct pci_dev *pdev) return !pm_resume_via_firmware() || pdev->device == CHV_DEVICE_ID; } -static int enable_gpe(struct device *dev) -{ -#ifdef CONFIG_ACPI - acpi_status acpi_sts; - struct acpi_device *adev; - struct acpi_device_wakeup *wakeup; - - adev = ACPI_COMPANION(dev); - if (!adev) { - dev_err(dev, "get acpi handle failed\n"); - return -ENODEV; - } - wakeup = &adev->wakeup; - - acpi_sts = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number); - if (ACPI_FAILURE(acpi_sts)) { - dev_err(dev, "enable ose_gpe failed\n"); - return -EIO; - } - - return 0; -#else - return -ENODEV; -#endif -} - -static void enable_pme_wake(struct pci_dev *pdev) -{ - if ((pci_pme_capable(pdev, PCI_D0) || - pci_pme_capable(pdev, PCI_D3hot) || - pci_pme_capable(pdev, PCI_D3cold)) && !enable_gpe(&pdev->dev)) { - pci_pme_active(pdev, true); - dev_dbg(&pdev->dev, "ish ipc driver pme wake enabled\n"); - } -} - /** * ish_probe() - PCI driver probe callback * @pdev: pci device @@ -225,7 +189,7 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* Enable PME for EHL */ if (pdev->device == EHL_Ax_DEVICE_ID) - enable_pme_wake(pdev); + device_init_wakeup(dev, true); ret = ish_init(ishtp); if (ret) @@ -248,6 +212,19 @@ static void ish_remove(struct pci_dev *pdev) ish_device_disable(ishtp_dev); } + +/** + * ish_shutdown() - PCI driver shutdown callback + * @pdev: pci device + * + * This function sets up wakeup for S5 + */ +static void ish_shutdown(struct pci_dev *pdev) +{ + if (pdev->device == EHL_Ax_DEVICE_ID) + pci_prepare_to_sleep(pdev); +} + static struct device __maybe_unused *ish_resume_device; /* 50ms to get resume response */ @@ -370,13 +347,6 @@ static int __maybe_unused ish_resume(struct device *device) struct pci_dev *pdev = to_pci_dev(device); struct ishtp_device *dev = pci_get_drvdata(pdev); - /* add this to finish power flow for EHL */ - if (dev->pdev->device == EHL_Ax_DEVICE_ID) { - pci_set_power_state(pdev, PCI_D0); - enable_pme_wake(pdev); - dev_dbg(dev->devc, "set power state to D0 for ehl\n"); - } - ish_resume_device = device; dev->resume_flag = 1; @@ -392,6 +362,7 @@ static struct pci_driver ish_driver = { .id_table = ish_pci_tbl, .probe = ish_probe, .remove = ish_remove, + .shutdown = ish_shutdown, .driver.pm = &ish_pm_ops, }; -- 2.34.1