Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1125738rdg; Wed, 11 Oct 2023 15:39:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlYlAUyC2JfA4+KltyFxllM8EByyIObQ3c1ENyIZRwZrgHU1rtEkcoTIP2Z35j8cyVL34R X-Received: by 2002:a17:902:ce8d:b0:1b9:e913:b585 with SMTP id f13-20020a170902ce8d00b001b9e913b585mr18086510plg.13.1697063987045; Wed, 11 Oct 2023 15:39:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063987; cv=none; d=google.com; s=arc-20160816; b=KrknFrr5Kcig+BOUySVT7EZkByeNb6bMF4Zi1sBA9z+OaQWJrXTRQlDv0XRvbEpMr+ uVUJZQ6q787aPxunIr8ndp3PtaVZprOQucY3aQnSNcAo/LRWMeFhfShW3WBTcee7QItB vJO1xXjc6gUKPfnEr8Noe3FD2xxF1l9Fn8xV12e/UTLcFSlbL4Js2zVCHI8Iv2lzQFh8 TeY70SgFc03NFH6FOZLljPIU2NM6vbMUcGcFQT78BEfFKxvsG1JVitwYmE1PLisdpD2h ya4uEy6+Ex9+qat+3hqd6MHU5/H5Em3WlQ9ZbyDosRI3Z9vr+DUKgKQbAx65k0eysWgr DlQw== 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=dDW4jZp3vxpXaIaYA727UOtSyUarACUv04TSxZTyQeh9+Qw7/HJxHrW44q/tOEqJj1 xbHh9vE8QTM7ukBm65g+xskls9Ka1hkqar0RRje5VbC42MuZKaYYuyEAfGwwdyjezApx 2yzIOXj5aQmfW4/j+ZkMIng6zf4cbDu5XI7BXhiH13N8yNVa4eFdezF/hNx/XgBg//Wz u+Ovq57i2qA4lLhGXUIpqte1bgl4TBtGWMDW23Cs2Xc4jxHOWI2YngK+4WoweiyP6hNH T+vG66jeUvnMGM5wOk+z+6YeaYP+vJaw16WQ0sONJZh9cEdWB2X8nksQifiYDe/zWWSr +xUg== 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-bluetooth-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id b7-20020a170903228700b001c73f81b24asi347153plh.521.2023.10.11.15.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:39:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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-bluetooth-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-bluetooth-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 1098080440CD; Wed, 11 Oct 2023 15:39:43 -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 S235187AbjJKWjm (ORCPT + 99 others); Wed, 11 Oct 2023 18:39:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbjJKWjl (ORCPT ); Wed, 11 Oct 2023 18:39:41 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 231F4B8 for ; Wed, 11 Oct 2023 15:39:35 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a21c283542so5379147b3.3 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=uyWoQwYWIFNckB4rFIwjMWpLoadkfkgv+QwRbbDOzJW501IZsco91u+lxryBbhGCSQ hHFMUpDctECIMDRe3jdKFkipcqSTolbAtwCqMPw2PhAZ+7XjFmGMhiZOaHydgYYu8KG5 yn0DzfMUXu3DoCkZdn26BNE37eftiiI9unyrzspa3I/S01ZvpDBi9ajtx2qdJvmIpC+e JdB9d5K5OPl19+qCS1ZnQY1m3++6viXlMtfMFkM8HxBl7ogAtoexdBw1GOq0RvcOPu6Z YXxBN0HvMt5H+MAH2h/n3TqmknZjZt2E53p/MeYPqohOi0TZw9aAW5pNhTMoqfnPBArM 4kcQ== X-Gm-Message-State: AOJu0YzLDyUEYON9SlA1hrWZ5Ms470sCY/W8FbIqWMRPW6gfPuMXog+E 9SinXtxy4bx96itWLvGO18yPOtM9f1h5Gnn8JzqCMYn0XsHC0omHvbiJXeW7VHksPuNNP/xTWyU qC3T3xYqVMl550Pr37P0EQUfEXQSKspnvQLITfgk6peBEs5FJDCcb3dQ9CQP5oY/sb/oPKOtsZF NB 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 Content-Type: text/plain; charset="UTF-8" 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-bluetooth@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:39:43 -0700 (PDT) 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 -- 2.42.0.609.gbb76f46606-goog