From patchwork Wed Oct 11 22:39:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengping Jiang X-Patchwork-Id: 151615 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp856141vqb; Wed, 11 Oct 2023 15:40:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpnAybvifW7jONM2wAgYf6lb2w8ceHDtoqH/EHjKYI5gIXYZEKyQRVGMzAsS6DgYZP3NZi X-Received: by 2002:a17:902:f54e:b0:1c2:c60:8387 with SMTP id h14-20020a170902f54e00b001c20c608387mr25058459plf.0.1697064008072; Wed, 11 Oct 2023 15:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697064008; cv=none; d=google.com; s=arc-20160816; b=ejb/VMg/nhYvcsjbkGZ1lpiolrceCQa3+7OuEBNfgL0jUyxFBGXq/vsZXVMw8+zxFL 85FlIoGv6yqispVAcIPBnu0xGB985Fd7sExAFESQ+DUvj0K1QZC/MuRRLRwGU+CX+jEm als0bfzWILajkEMfB8b0luTX8k8gYCUIP4z5ZfgbJq8y315S730z10X8/qn+97ZzNssq VNKbLSAoG4D9150+9jho9UPi/9YZf/hsIu2Zh/D3IcnYsMasxsUtY1rGpzTduztRtUD6 2qqA53iJxi+kre6A/AWFovhQ7MvTVisAdDbDQ6piywi2fA9nH0g+0rtYou7NaK7eGpvk ozuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=szUp3IgWTq4iCJ08BNtxTyUlyqhJt469/BAgPtCRvbI=; fh=8O/T8yO2An2gDr6hpf39SWXAF9j8g22xX2o08V+kF20=; b=kuCMuOJplLSUGaHo8Ra3EOctdtQS0mPsGhYcHKedmTj7KkmuBnGsUTVKSQZAdgWLo9 fG7h5ks8hv1zUydN2/46Yufnez3zEBV7tub5tTwj/43eGwmIio7qdbkb6rzattW0iSO9 v69yo+KR2wPZdC3ouaZ0KdKvnME9ywXzC7zfMkMRg+Kid1MDBzUWJ9+G5NFUEl2BB8dR D4F9S5yMcBpCLwPrxXJB5j8BQfuVm7m6AErDb2qORrMUkdUMRwstM0daLcZBmV/M4cqy 9vdvoWD1CK64JH/EYQCzmpT7CK2DgvReXDDEMqNGYsBZw1yjdp0xVfGWMwIRpZCHnS1q ANLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tz2kkrAM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x13-20020a170902820d00b001c60c77ec1csi620453pln.511.2023.10.11.15.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tz2kkrAM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2CD6780440DA; Wed, 11 Oct 2023 15:40:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233646AbjJKWjm (ORCPT + 18 others); Wed, 11 Oct 2023 18:39:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235186AbjJKWjl (ORCPT ); Wed, 11 Oct 2023 18:39:41 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162ACAF for ; Wed, 11 Oct 2023 15:39:35 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7b53a48e5so5530667b3.1 for ; Wed, 11 Oct 2023 15:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697063974; x=1697668774; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=szUp3IgWTq4iCJ08BNtxTyUlyqhJt469/BAgPtCRvbI=; b=tz2kkrAMJrWEcNdZJ8UJ4VR8v1bAT+PuzGh51gdgEYJKxFWXDTRhR5YL5PgqBJI8Xx pikvCJi+MnNO8Kv/E9CW/ko0N12lSXlee5TBj0T2zm9YaxRZclr3605VlLCMx79tvORQ nhOU1+YHHtru4WNSSjtrBpCsjsp0KxALEF5HQOdft3id4aLi3zAJXdckiZDojV2AAVNT Vur9VoG4MxJnto30HAXMIAt5eVnGd38u2GELO4ShC7a8b3Ldu3C+CmJ0fQywA01fwaOk qhASTx+poasdLMNw2Q5Dcm29LUvQaJbC4/qlIp3THFxg+SyIIb8g+Syn/4Du6uMpDHyJ LDCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697063974; x=1697668774; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=szUp3IgWTq4iCJ08BNtxTyUlyqhJt469/BAgPtCRvbI=; b=YnvEKYrC3cG4+Yl6ajAAhpDbkwa6oqKbMfcp1909w3tyraGDQ/dcE6JIaWz2fcemt2 xgMPWz1DkDt0U3Qe0gexmsn9svihSXDRM1EvIAznfuYg8mvoJDwol86R7I9p2njJLSnv c8+w4mMF/aEmyAuKkzqSRVuJ3GFG/auhxe5dOSchgpeaZqnqCbYZntEP17cg+DTK0QOT ROilklJdNYRYWPwUolB34xszAm+2hA26GJ/cjH4M4IB8Wy5ua9uG79bUceDUj4fGNnER 56QvwqSACUmQ1ET6RBh4AhAEZ1cDZgo3Rf8kzOWi3ZT1qrQd5scDFKIYSTwdPcX1V35v Pfzg== X-Gm-Message-State: AOJu0YyShVYTlXdOMHcyrF2YFQDPzYIn29mxJ7ivAiFp4pwceuG8ZBwo L7DyhRZibJRh0j43DUz52AXipzXSzoHg X-Received: from jiangzp-glinux-dev.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:38e4]) (user=jiangzp job=sendgmr) by 2002:a81:aa4d:0:b0:59f:3cde:b33a with SMTP id z13-20020a81aa4d000000b0059f3cdeb33amr416465ywk.6.1697063974245; Wed, 11 Oct 2023 15:39:34 -0700 (PDT) Date: Wed, 11 Oct 2023 15:39:28 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231011153928.kernel.v2.1.I6dbfc1fedddf0633b55ce7e7a10ef7f3929a9bdc@changeid> Subject: [kernel PATCH v2] Bluetooth: btmtksdio: enable bluetooth wakeup in system suspend From: Zhengping Jiang To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, Zhengping Jiang , AngeloGioacchino Del Regno , Johan Hedberg , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Wed, 11 Oct 2023 15:40:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779500589078364479 X-GMAIL-MSGID: 1779500589078364479 The BTMTKSDIO_BT_WAKE_ENABLED flag is set for bluetooth interrupt during system suspend and increases wakeup count for bluetooth event. Signed-off-by: Zhengping Jiang --- Changes in v2: - Add Bluetooth prefix to patch subject - Fix warnings regarding using plain integer as NULL - Add static to btmtksdio_pm_ops Changes in v1: - Add BTMTKSDIO_BT_WAKE_ENABLED flag - Call pm_wakeup_event in btmtksdio_interrupt drivers/bluetooth/btmtksdio.c | 44 ++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index f9a3444753c2..404105e69c67 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -118,6 +118,7 @@ MODULE_DEVICE_TABLE(sdio, btmtksdio_table); #define BTMTKSDIO_FUNC_ENABLED 3 #define BTMTKSDIO_PATCH_ENABLED 4 #define BTMTKSDIO_HW_RESET_ACTIVE 5 +#define BTMTKSDIO_BT_WAKE_ENABLED 6 struct mtkbtsdio_hdr { __le16 len; @@ -554,7 +555,7 @@ static void btmtksdio_txrx_work(struct work_struct *work) sdio_claim_host(bdev->func); /* Disable interrupt */ - sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, 0); + sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, NULL); txrx_timeout = jiffies + 5 * HZ; @@ -576,7 +577,7 @@ static void btmtksdio_txrx_work(struct work_struct *work) if ((int_status & FW_MAILBOX_INT) && bdev->data->chipid == 0x7921) { sdio_writel(bdev->func, PH2DSM0R_DRIVER_OWN, - MTK_REG_PH2DSM0R, 0); + MTK_REG_PH2DSM0R, NULL); } if (int_status & FW_OWN_BACK_INT) @@ -608,7 +609,7 @@ static void btmtksdio_txrx_work(struct work_struct *work) } while (int_status || time_is_before_jiffies(txrx_timeout)); /* Enable interrupt */ - sdio_writel(bdev->func, C_INT_EN_SET, MTK_REG_CHLPCR, 0); + sdio_writel(bdev->func, C_INT_EN_SET, MTK_REG_CHLPCR, NULL); sdio_release_host(bdev->func); @@ -620,8 +621,14 @@ static void btmtksdio_interrupt(struct sdio_func *func) { struct btmtksdio_dev *bdev = sdio_get_drvdata(func); + if (test_bit(BTMTKSDIO_BT_WAKE_ENABLED, &bdev->tx_state)) { + if (bdev->hdev->suspended) + pm_wakeup_event(bdev->dev, 0); + clear_bit(BTMTKSDIO_BT_WAKE_ENABLED, &bdev->tx_state); + } + /* Disable interrupt */ - sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, 0); + sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, NULL); schedule_work(&bdev->txrx_work); } @@ -1454,6 +1461,23 @@ static int btmtksdio_runtime_suspend(struct device *dev) return err; } +static int btmtksdio_system_suspend(struct device *dev) +{ + struct sdio_func *func = dev_to_sdio_func(dev); + struct btmtksdio_dev *bdev; + + bdev = sdio_get_drvdata(func); + if (!bdev) + return 0; + + if (!test_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state)) + return 0; + + set_bit(BTMTKSDIO_BT_WAKE_ENABLED, &bdev->tx_state); + + return btmtksdio_runtime_suspend(dev); +} + static int btmtksdio_runtime_resume(struct device *dev) { struct sdio_func *func = dev_to_sdio_func(dev); @@ -1474,8 +1498,16 @@ static int btmtksdio_runtime_resume(struct device *dev) return err; } -static UNIVERSAL_DEV_PM_OPS(btmtksdio_pm_ops, btmtksdio_runtime_suspend, - btmtksdio_runtime_resume, NULL); +static int btmtksdio_system_resume(struct device *dev) +{ + return btmtksdio_runtime_resume(dev); +} + +static const struct dev_pm_ops __maybe_unused btmtksdio_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(btmtksdio_system_suspend, btmtksdio_system_resume) + SET_RUNTIME_PM_OPS(btmtksdio_runtime_suspend, btmtksdio_runtime_resume, NULL) +}; + #define BTMTKSDIO_PM_OPS (&btmtksdio_pm_ops) #else /* CONFIG_PM */ #define BTMTKSDIO_PM_OPS NULL