Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1181992rdg; Fri, 13 Oct 2023 12:47:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNeIKplRKaIEZ0kMhtJNUf28cKXx3vMQTKCQdQoOj2LX+wBXYnspTT0pAmEQPt0a6fr+2/ X-Received: by 2002:a17:903:1250:b0:1c9:dff1:6de7 with SMTP id u16-20020a170903125000b001c9dff16de7mr1566031plh.7.1697226440557; Fri, 13 Oct 2023 12:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697226440; cv=none; d=google.com; s=arc-20160816; b=WkS6PpgbKyI/TLiO0/m/0Jej8WXRIFX9xeRdVdKfbXhhQFONipRphus3smFDXs0JIc I6QWn9ODZoEVY4Pl0jYsnHADEqRr/8yxpZT9jnGtVoyT1s5W80SGyOBuq4/prZ5Y1jrz 5q/BbhicR9Bqzi4vH+uEYt6lUB4aKMZf3PIPLomeNqDOAxugBoAW1+1/ZKF826z7PoYP uR3eE2dVMupXVwQqUSZcGJXKaZU6GyE+njkGzLgTOh5ub0pcXgghGeeLiA/6HypYfclQ lReZHlZ7E5Yla8r/MbevIf5doDVIKoUcwO0+Xh40WHUKN3LmTgS6N8p14kxP5aw1S8SW iEew== 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=mHGY1rNgdssEAkSd/6ZBfSHP677hALKRsWOmZt1w4io=; fh=8O/T8yO2An2gDr6hpf39SWXAF9j8g22xX2o08V+kF20=; b=dOLLn9GkaqOP04eHwkx4/aBr04vYrt0du22i3uUyw9cSAJAkjo3bpbjtZ5AbcrYfoT Kk0wPXbD92IiT+S5zTu3fpfUj6gDWYfiFiIvbOBdDmR+eN3CH/aRaEgFeLWmeHIEAvNP H3t0kMsl87ZoI5lAEuzuMvrbbBZxunmWb7pW8YgBnrb7eMrKiZ+OhAgXAry55R3Yg6co JEFtW/xXh5bsFDmiNIBabdtmOH7AQWq2ah5Kur8nEL/wSr+E2dakrVlu4eIp7M5oZXLN zFKOSM5LbnEyjpjxmpu2gMVT3Uj0Q2gNn+GyGFp2aQXEK+wd8e1vNq5fov0XrvwtbpEn uJGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DRS6nwCp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z5-20020a170902ee0500b001c446b59c8dsi4860884plb.271.2023.10.13.12.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 12:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DRS6nwCp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 927908343526; Fri, 13 Oct 2023 12:47:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbjJMTrQ (ORCPT + 99 others); Fri, 13 Oct 2023 15:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjJMTrP (ORCPT ); Fri, 13 Oct 2023 15:47:15 -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 CC38995 for ; Fri, 13 Oct 2023 12:47:13 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7a6fd18abso38878717b3.1 for ; Fri, 13 Oct 2023 12:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697226433; x=1697831233; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=mHGY1rNgdssEAkSd/6ZBfSHP677hALKRsWOmZt1w4io=; b=DRS6nwCp6/z+zyQRKVbqZu8SC+ou3EPlvENHy6mmxjBNOfI2NnOuJ4HZdVR0y5i0L6 HQylAqIDPtuE9NR+6Qdv41LTgFGKrczARY38jriQxyELAEVm4QxYQRPVipO/ypx3rr+c fk0c7vKRZKaiU1JW0nwAajr6bfGExqL+1uOYTChkdxeCmznqzj2mdBq7K1QCrnJybdCP HF8IsDUdE95kYB68H9Vl73WNrEOJ5A5BuhySej9q8YxrDEEdAxe/6VAiT+hBWND48S2H lrGglvz+Tr8ik9AbFJ6ryiNHlGQUoCzZeBYO5uc9yqwWs82UlJK2Z37XiWYXSI/euimQ OaNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697226433; x=1697831233; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mHGY1rNgdssEAkSd/6ZBfSHP677hALKRsWOmZt1w4io=; b=eyvimyjvUCIhuk0csKvzjCV3Ts9ygyUkOuxwu6fe7ZBnw/rx0UlKjJ/XgfKCx7zTL7 YT5Brb6O3/xwh23XrR1Gh5TVb/L7PwRkHGWs20j5G1c5N+ehVOliJloe39Vx0B4S44kq APnMYZk8tlo3zEIMPbELklsNNzJpQGoOrn6t+o3U7/O4UutxBM5k+KMOCATTVCDmKpog DJ1IpuWNTwMySNdEryM75Q4TvteERYHdegNs9lS8Z/zai4fKKXnGpLc4juZBlnijJXAs kQ2ZrLQo35UX8SZOzi1l7vceADmy8+fK/VNqdArl5FgtLEkoBaYMDcYU1kFsDv3icjls gIug== X-Gm-Message-State: AOJu0YxTlijxis/ZKvGKc5hNLRZBdL5nFTxX6uhZapAXUVleZH40SErI Xo4wbtvPVXn1nwbtP5IZlE3YY7r/ZEy4 X-Received: from jiangzp-glinux-dev.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:38e4]) (user=jiangzp job=sendgmr) by 2002:a81:a84a:0:b0:59b:e97e:f7df with SMTP id f71-20020a81a84a000000b0059be97ef7dfmr537451ywh.2.1697226432947; Fri, 13 Oct 2023 12:47:12 -0700 (PDT) Date: Fri, 13 Oct 2023 12:47:07 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231013124707.kernel.v3.1.I6dbfc1fedddf0633b55ce7e7a10ef7f3929a9bdc@changeid> Subject: [kernel PATCH v3] 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 13 Oct 2023 12:47:19 -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 v3: - Replace deprecated macro. 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..ff4868c83cd8 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 btmtksdio_pm_ops = { + SYSTEM_SLEEP_PM_OPS(btmtksdio_system_suspend, btmtksdio_system_resume) + 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.655.g421f12c284-goog