From patchwork Fri Jul 23 11:31:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12395961 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D26F9C4320A for ; Fri, 23 Jul 2021 11:32:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B998F60EC0 for ; Fri, 23 Jul 2021 11:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234394AbhGWKvc (ORCPT ); Fri, 23 Jul 2021 06:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231703AbhGWKvb (ORCPT ); Fri, 23 Jul 2021 06:51:31 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 512C6C061575 for ; Fri, 23 Jul 2021 04:32:04 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d69-20020a25e6480000b02904f4a117bd74so1415539ybh.17 for ; Fri, 23 Jul 2021 04:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=O7I41NCtCSHX22Iy466gv23WxW0Z9akPjEALodX4ppw=; b=Hx++rDueQl1UsulcsoEfkYDvqY0p1UAf/Wu/Vh0ZUxEUddIse7HzC9JoGi2Veldo6x +uwd+/lcQoFPm9fv/osBM/ZrUpX2hslwqSno2d6TL4sYTi5KOoWxOpeXCN/lYEJU0E1s cLKbiUwrabMH47amSxMaKQexl+L+iOjo4QIU6HC6ycLLOmuzqAvIoBg4XufsB+5mHYYB t0VDXsA5KvbKfvesg2FeF90yfZl0YyTZuk76rOsmP4fgAOeSkO8DNxn7ZNqXRHu9GqNR upW2/s0Ey6kzjzwiDnXhDcdhdc3d06lEuxCksHvOEEHnb4+pGVf2IbdVvjfDTiKBqQM4 XWgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=O7I41NCtCSHX22Iy466gv23WxW0Z9akPjEALodX4ppw=; b=WY4ZLNVmq5NMAcsJY5ubT/Y5U7fnInxB1ex0Vk1a3x9n5q7jr/odBKmccf8hmvQV8k D9J6B/VhWEWVpKRzGHKFhG6uTDBV6IAait37I28nfB0B6tayGPGMZz2X+rIsPydLm4e3 5pKrgZQxxHyTMX0cF6VUrjijUwm9LRZHjCybwKnx5YArpeCIW4WmMMZOLyRlMF5bfylV r/Ov1OXupY3mkYotibCUySI8gjv7ymlEouSoWqvvUmJb+o3AhRP9y/6u3S9CLFZB6/h0 V6VE9qqIl+25jdNJ7qjJ5kcbHrqYgvtd8o1IoC1MSYBNpceFkMPO+PXqvvCRZmTOn/0k 587g== X-Gm-Message-State: AOAM530W4BewuNGsON8QrvsMJVihj6VzduFJ217pPwBYVMXZwEmnBdG3 IdEUOyaUs2ImLJ5brXAB6XAUVzHi+zUjWnhe2FKijtkiw8EVaqzw2Scr9LcOCG0OS4QTdiU0tyQ TPay/feME48uP0zIzyHoVO22GYi5/Jlk0Z/xUQ5eDrnoOtQ6IKe4f/kQJinvwGgRiJmvB5tYXK1 np X-Google-Smtp-Source: ABdhPJy2GrOZNBtTyOfCUXXeKFEqddsYzKfLrzRIgV7ajqSJmmK2qB3bOLcm4H3si2Rw35RM34tHpdtr5bok X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:ddde:33b:f989:cd76]) (user=apusaka job=sendgmr) by 2002:a25:5807:: with SMTP id m7mr5723073ybb.127.1627039923474; Fri, 23 Jul 2021 04:32:03 -0700 (PDT) Date: Fri, 23 Jul 2021 19:31:55 +0800 Message-Id: <20210723193137.v3.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag From: Archie Pusaka To: linux-bluetooth , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Abhishek Pandit-Subedi , Hilda Wu , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka Some RTL chips resets the FW on suspend, so wakeup is disabled on those chips. This patch introduces this WAKEUP_DISABLE flag so that chips that doesn't reset FW on suspend can leave the flag unset and is allowed to wake the host. This patch also left RTL8822 WAKEUP_DISABLE flag unset, therefore allowing it to wake the host, and preventing reprobing on resume. Signed-off-by: Archie Pusaka Reviewed-by: Abhishek Pandit-Subedi Reviewed-by: Hilda Wu --- Changes in v3: * Rebasing Changes in v2: * Remove unnecessary variable drivers/bluetooth/hci_h5.c | 83 +++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c index 7b985c7cd26d..fd672111a048 100644 --- a/drivers/bluetooth/hci_h5.c +++ b/drivers/bluetooth/hci_h5.c @@ -51,8 +51,9 @@ /* H5 state flags */ enum { - H5_RX_ESC, /* SLIP escape mode */ - H5_TX_ACK_REQ, /* Pending ack to send */ + H5_RX_ESC, /* SLIP escape mode */ + H5_TX_ACK_REQ, /* Pending ack to send */ + H5_WAKEUP_DISABLE, /* Device cannot wake host */ }; struct h5 { @@ -97,6 +98,10 @@ struct h5 { struct gpio_desc *device_wake_gpio; }; +enum h5_driver_info { + H5_INFO_WAKEUP_DISABLE = BIT(0), +}; + struct h5_vnd { int (*setup)(struct h5 *h5); void (*open)(struct h5 *h5); @@ -106,6 +111,11 @@ struct h5_vnd { const struct acpi_gpio_mapping *acpi_gpio_map; }; +struct h5_device_data { + uint32_t driver_info; + struct h5_vnd *vnd; +}; + static void h5_reset_rx(struct h5 *h5); static void h5_link_control(struct hci_uart *hu, const void *data, size_t len) @@ -791,6 +801,8 @@ static int h5_serdev_probe(struct serdev_device *serdev) { struct device *dev = &serdev->dev; struct h5 *h5; + const struct h5_device_data *data; + int err; h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL); if (!h5) @@ -807,20 +819,19 @@ static int h5_serdev_probe(struct serdev_device *serdev) if (!match) return -ENODEV; - h5->vnd = (const struct h5_vnd *)match->driver_data; + data = (const struct h5_device_data *)match->driver_data; + h5->vnd = data->vnd; h5->id = (char *)match->id; if (h5->vnd->acpi_gpio_map) devm_acpi_dev_add_driver_gpios(dev, h5->vnd->acpi_gpio_map); } else { - const void *data; - data = of_device_get_match_data(dev); if (!data) return -ENODEV; - h5->vnd = (const struct h5_vnd *)data; + h5->vnd = data->vnd; } @@ -833,7 +844,14 @@ static int h5_serdev_probe(struct serdev_device *serdev) if (IS_ERR(h5->device_wake_gpio)) return PTR_ERR(h5->device_wake_gpio); - return hci_uart_register_device(&h5->serdev_hu, &h5p); + err = hci_uart_register_device(&h5->serdev_hu, &h5p); + if (err) + return err; + + if (data->driver_info & H5_INFO_WAKEUP_DISABLE) + set_bit(H5_WAKEUP_DISABLE, &h5->flags); + + return 0; } static void h5_serdev_remove(struct serdev_device *serdev) @@ -921,7 +939,8 @@ static void h5_btrtl_open(struct h5 *h5) * done by the hci_suspend_notifier is not necessary; it actually causes * delays and a bunch of errors to get logged, so disable it. */ - set_bit(HCI_UART_NO_SUSPEND_NOTIFIER, &h5->hu->flags); + if (test_bit(H5_WAKEUP_DISABLE, &h5->flags)) + set_bit(HCI_UART_NO_SUSPEND_NOTIFIER, &h5->hu->flags); /* Devices always start with these fixed parameters */ serdev_device_set_flow_control(h5->hu->serdev, false); @@ -942,15 +961,18 @@ static void h5_btrtl_close(struct h5 *h5) /* Suspend/resume support. On many devices the RTL BT device loses power during * suspend/resume, causing it to lose its firmware and all state. So we simply - * turn it off on suspend and reprobe on resume. This mirrors how RTL devices - * are handled in the USB driver, where the USB_QUIRK_RESET_RESUME is used which + * turn it off on suspend and reprobe on resume. This mirrors how RTL devices + * are handled in the USB driver, where the BTUSB_WAKEUP_DISABLE is used which * also causes a reprobe on resume. */ static int h5_btrtl_suspend(struct h5 *h5) { serdev_device_set_flow_control(h5->hu->serdev, false); gpiod_set_value_cansleep(h5->device_wake_gpio, 0); - gpiod_set_value_cansleep(h5->enable_gpio, 0); + + if (test_bit(H5_WAKEUP_DISABLE, &h5->flags)) + gpiod_set_value_cansleep(h5->enable_gpio, 0); + return 0; } @@ -976,17 +998,21 @@ static void h5_btrtl_reprobe_worker(struct work_struct *work) static int h5_btrtl_resume(struct h5 *h5) { - struct h5_btrtl_reprobe *reprobe; + if (test_bit(H5_WAKEUP_DISABLE, &h5->flags)) { + struct h5_btrtl_reprobe *reprobe; - reprobe = kzalloc(sizeof(*reprobe), GFP_KERNEL); - if (!reprobe) - return -ENOMEM; + reprobe = kzalloc(sizeof(*reprobe), GFP_KERNEL); + if (!reprobe) + return -ENOMEM; - __module_get(THIS_MODULE); + __module_get(THIS_MODULE); - INIT_WORK(&reprobe->work, h5_btrtl_reprobe_worker); - reprobe->dev = get_device(&h5->hu->serdev->dev); - queue_work(system_long_wq, &reprobe->work); + INIT_WORK(&reprobe->work, h5_btrtl_reprobe_worker); + reprobe->dev = get_device(&h5->hu->serdev->dev); + queue_work(system_long_wq, &reprobe->work); + } else { + gpiod_set_value_cansleep(h5->device_wake_gpio, 1); + } return 0; } @@ -1008,13 +1034,22 @@ static struct h5_vnd rtl_vnd = { .resume = h5_btrtl_resume, .acpi_gpio_map = acpi_btrtl_gpios, }; + +static const struct h5_device_data h5_data_rtl8822cs = { + .vnd = &rtl_vnd, +}; + +static const struct h5_device_data h5_data_rtl8723bs = { + .driver_info = H5_INFO_WAKEUP_DISABLE, + .vnd = &rtl_vnd, +}; #endif #ifdef CONFIG_ACPI static const struct acpi_device_id h5_acpi_match[] = { #ifdef CONFIG_BT_HCIUART_RTL - { "OBDA0623", (kernel_ulong_t)&rtl_vnd }, - { "OBDA8723", (kernel_ulong_t)&rtl_vnd }, + { "OBDA0623", (kernel_ulong_t)&h5_data_rtl8723bs }, + { "OBDA8723", (kernel_ulong_t)&h5_data_rtl8723bs }, #endif { }, }; @@ -1028,11 +1063,11 @@ static const struct dev_pm_ops h5_serdev_pm_ops = { static const struct of_device_id rtl_bluetooth_of_match[] = { #ifdef CONFIG_BT_HCIUART_RTL { .compatible = "realtek,rtl8822cs-bt", - .data = (const void *)&rtl_vnd }, + .data = (const void *)&h5_data_rtl8822cs }, { .compatible = "realtek,rtl8723bs-bt", - .data = (const void *)&rtl_vnd }, + .data = (const void *)&h5_data_rtl8723bs }, { .compatible = "realtek,rtl8723ds-bt", - .data = (const void *)&rtl_vnd }, + .data = (const void *)&h5_data_rtl8723bs }, #endif { }, }; From patchwork Fri Jul 23 11:31:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12395963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75506C4338F for ; Fri, 23 Jul 2021 11:32:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5588160E8E for ; Fri, 23 Jul 2021 11:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234519AbhGWKvj (ORCPT ); Fri, 23 Jul 2021 06:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234488AbhGWKvi (ORCPT ); Fri, 23 Jul 2021 06:51:38 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E484DC061757 for ; Fri, 23 Jul 2021 04:32:10 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id a15-20020a170902eccfb029012b5663a1f7so1870854plh.10 for ; Fri, 23 Jul 2021 04:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1UqlY0KgIV9lGcr3KCNCk5kXAgTT0B278rOriYat9o8=; b=gQRtLTwI8nohOXOq3a88IKRKxe14x6kRa0CvzJCRTdKMX160cJAjg05T6KBrAzn/KR 2190O5AjA1BdfzyVwI+UbVGHIKZpV71M9tmI1JGNx3KuJ0CK1PMJcsuVJoOjn+c+fqX0 yG8r9ACcuFePnyT/J2FY2tK8taUdZsnNPEZw+oxoy4T1vgVSp1krNoI5nXPBF+5ifxF6 5e7FIgj7jxWAaZbm0VruvahJ21yJexsOgdzbyY6LBobcXpBSa36MAZ/lKkoA3m2pa26A mdMzBredelyJtOgWeTZkj+RRfkLCiOoHhT91uDrLEMmvp5+zOY3CvPPSY0NnzH+Hi3Vw 6lEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1UqlY0KgIV9lGcr3KCNCk5kXAgTT0B278rOriYat9o8=; b=j0C0H8xXZZkN7A/vwdS/jPedoR8YhALQ5z3Kua861+YUrgKdRx2gCPijl/7aIBxQCj zNKODKiFI3/mFeMhbtxoCjna89DbeXbgqBiUME4RHmEUq8z0rAgG56bVtoO4fSFGg3eU y19n1OUEkRf6eDw2FR0jVjWuIameRT8TxPQKwnxz3sbobj10eytDbIR+h7qFETF2EJxH 0JBfQMpgSPdXLpan9Qos66uFN/S+/i1oKGeJVPds9ri144oebLC7i0d/tyFoirOvZOBl BIg9fPbLArn6iCsNzHSIB9CeKAJJromqMfJv8rjDBbYdSP12YxCll6ErbyOxbYP28OGK g4BA== X-Gm-Message-State: AOAM530KLUb7YFsE1h0ouAxTgj+64QKBCYZ6rfDSC2rTfJQQ5nDFrY6w bkypTbqZYvirh0WnjkrEgXm1zGXR/WnB0DoTUZ9T8XWi/PHHrrDM/1zwMypNA3UZNDqak5cqqor /+qBD49msI//rNWRaa+VXNnxsz0ksx2oDOdnyR3jMC8sU3P7MaJQmxVJ+jSpuN9EhQtUQyFnfGE /4 X-Google-Smtp-Source: ABdhPJxOEDnc3AcVmn7792LuVNovHdsnYWk9IKZHI7i/4BPsFo6Fa2oYrS3WRJDK1X9sTL4l9ylgS1iz1j5s X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:ddde:33b:f989:cd76]) (user=apusaka job=sendgmr) by 2002:a05:6a00:84d:b029:329:a067:b1bf with SMTP id q13-20020a056a00084db0290329a067b1bfmr4189827pfk.47.1627039930218; Fri, 23 Jul 2021 04:32:10 -0700 (PDT) Date: Fri, 23 Jul 2021 19:31:56 +0800 In-Reply-To: <20210723193137.v3.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> Message-Id: <20210723193137.v3.2.I404c6df9cdab270223c13e867396f440dd4b499d@changeid> Mime-Version: 1.0 References: <20210723193137.v3.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled From: Archie Pusaka To: linux-bluetooth , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Abhishek Pandit-Subedi , Hilda Wu , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka For chips that doesn't reset on suspend, we need to provide the correct value of flow_control when it resumes. Therefore, store the flow control value when reading from the config file to be reused upon suspend. Signed-off-by: Archie Pusaka Reviewed-by: Abhishek Pandit-Subedi Reviewed-by: Hilda Wu --- (no changes since v1) drivers/bluetooth/hci_h5.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c index fd672111a048..cbc63b057f33 100644 --- a/drivers/bluetooth/hci_h5.c +++ b/drivers/bluetooth/hci_h5.c @@ -54,6 +54,7 @@ enum { H5_RX_ESC, /* SLIP escape mode */ H5_TX_ACK_REQ, /* Pending ack to send */ H5_WAKEUP_DISABLE, /* Device cannot wake host */ + H5_HW_FLOW_CONTROL, /* Use HW flow control */ }; struct h5 { @@ -920,6 +921,9 @@ static int h5_btrtl_setup(struct h5 *h5) serdev_device_set_baudrate(h5->hu->serdev, controller_baudrate); serdev_device_set_flow_control(h5->hu->serdev, flow_control); + if (flow_control) + set_bit(H5_HW_FLOW_CONTROL, &h5->flags); + err = btrtl_download_firmware(h5->hu->hdev, btrtl_dev); /* Give the device some time before the hci-core sends it a reset */ usleep_range(10000, 20000); @@ -1012,7 +1016,11 @@ static int h5_btrtl_resume(struct h5 *h5) queue_work(system_long_wq, &reprobe->work); } else { gpiod_set_value_cansleep(h5->device_wake_gpio, 1); + + if (test_bit(H5_HW_FLOW_CONTROL, &h5->flags)) + serdev_device_set_flow_control(h5->hu->serdev, true); } + return 0; } From patchwork Fri Jul 23 11:31:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12395965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4410C4338F for ; Fri, 23 Jul 2021 11:32:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A313F60E75 for ; Fri, 23 Jul 2021 11:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234550AbhGWKvo (ORCPT ); Fri, 23 Jul 2021 06:51:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234214AbhGWKvn (ORCPT ); Fri, 23 Jul 2021 06:51:43 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AA57C061757 for ; Fri, 23 Jul 2021 04:32:16 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id b6-20020a0cbf460000b02902dbb4e0a8f2so1653576qvj.6 for ; Fri, 23 Jul 2021 04:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wopAMfAFodufVPIjdUMCKKzBY2Yv7x4TcVUiniEv4ds=; b=nJFm0U+LLxx1CSpdg2n2/hM1YuQ1BSQx3wRINnedjPgDNlptDEDPIoBFU/mzv9LR4v Jgj36Mvy4Ec7Cbec8uam/ygQfPWXrwnGM+6cp42x0AP17UE6e45ScX1D++SSsQPv43p3 E7mcIwgeUB5elAXvfzfG8KfuQxL5+qG5yjY3KGRhpmZEW3JkYGjkH/aKohTX0vGXE21X ZPoNLqEqkNgz9qccmvc2h+ldkMEairCnBg9Bw9ARVvC/NHhLZAHuIt8biurg3Hvv+fUN nrVTUUCKyezRSHdOeAvalsGXbKCMOHdYqnl9N0Qte7M7a2ZlE74TxYn21kx+SxtiYxDf V2xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wopAMfAFodufVPIjdUMCKKzBY2Yv7x4TcVUiniEv4ds=; b=eRGm9nM6t3ObO/QwF4U/pVP20WebfyrCpkCWBHoxKSF/eao5F5VeDTyxrpfJznPIyF UpQci1QzSJN562kMGnnS+YcIQV7O0CZWer5yBWv6ThdzDktIjXwJpfet0IwaklwUBZpi 1Isx5Wth/iFhjej89fYImIveotulnpS7zFwgjriMsP5UwKI5HElA1aiSoPuNTSaZMpax oCUORfOScoO6+Ks5qk+xjpQ2EYmY+Hi5yJMNJaIPfGNeIZL2D6cGQic1naNW6/z2maRX fXqK9iOlMhN3hPguy0W0+SJyM/28IK+8Ui7oeFPFh/eqHukHkXGiQZ0I/pvv4IvLTdKf 6atA== X-Gm-Message-State: AOAM5311SIrK34JsYYdTMkAuhS9NUKR3PE5NvV472jA0++CQVnqvTaSk jzUKkyc1UCwuli9l0ekdh3P8d3piuxgMWxYAhHtL/Q+OCyxZdSGdTGRcwCzwX4F4RwElt4DOU42 lof6JsB4niLLwWv3PztqsNcKQ6Y9UOvgz5JC1AyFfx2HbzizlzjM4UgdNSasp09s7zybv+4BTSc qN X-Google-Smtp-Source: ABdhPJzzciscGeoQb/3TDTQkKv1iVFzZNg+dYYKjG3X4UaiQH6HE1XMRjwR0xZTJLi8Qf8xKe1ZjgwW1LDMy X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:ddde:33b:f989:cd76]) (user=apusaka job=sendgmr) by 2002:a05:6214:10c8:: with SMTP id r8mr4346292qvs.28.1627039935616; Fri, 23 Jul 2021 04:32:15 -0700 (PDT) Date: Fri, 23 Jul 2021 19:31:57 +0800 In-Reply-To: <20210723193137.v3.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> Message-Id: <20210723193137.v3.3.I4b323d2adf1dca62777c41de344a7d2f79b7f908@changeid> Mime-Version: 1.0 References: <20210723193137.v3.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend From: Archie Pusaka To: linux-bluetooth , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Abhishek Pandit-Subedi , Hilda Wu , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka This patch allows the controller to suspend after a short period of inactivity. Signed-off-by: Archie Pusaka Reviewed-by: Abhishek Pandit-Subedi Reviewed-by: Hilda Wu --- Changes in v3: * Reordering #include drivers/bluetooth/hci_h5.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c index cbc63b057f33..0c0dedece59c 100644 --- a/drivers/bluetooth/hci_h5.c +++ b/drivers/bluetooth/hci_h5.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,8 @@ #include "btrtl.h" #include "hci_uart.h" +#define SUSPEND_TIMEOUT_MS 6000 + #define HCI_3WIRE_ACK_PKT 0 #define HCI_3WIRE_LINK_PKT 15 @@ -584,6 +587,10 @@ static int h5_recv(struct hci_uart *hu, const void *data, int count) count -= processed; } + pm_runtime_get(&hu->serdev->dev); + pm_runtime_mark_last_busy(&hu->serdev->dev); + pm_runtime_put_autosuspend(&hu->serdev->dev); + return 0; } @@ -620,6 +627,10 @@ static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb) break; } + pm_runtime_get_sync(&hu->serdev->dev); + pm_runtime_mark_last_busy(&hu->serdev->dev); + pm_runtime_put_autosuspend(&hu->serdev->dev); + return 0; } @@ -951,6 +962,12 @@ static void h5_btrtl_open(struct h5 *h5) serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN); serdev_device_set_baudrate(h5->hu->serdev, 115200); + pm_runtime_set_active(&h5->hu->serdev->dev); + pm_runtime_use_autosuspend(&h5->hu->serdev->dev); + pm_runtime_set_autosuspend_delay(&h5->hu->serdev->dev, + SUSPEND_TIMEOUT_MS); + pm_runtime_enable(&h5->hu->serdev->dev); + /* The controller needs up to 500ms to wakeup */ gpiod_set_value_cansleep(h5->enable_gpio, 1); gpiod_set_value_cansleep(h5->device_wake_gpio, 1); @@ -959,6 +976,8 @@ static void h5_btrtl_open(struct h5 *h5) static void h5_btrtl_close(struct h5 *h5) { + pm_runtime_disable(&h5->hu->serdev->dev); + gpiod_set_value_cansleep(h5->device_wake_gpio, 0); gpiod_set_value_cansleep(h5->enable_gpio, 0); } @@ -1066,6 +1085,7 @@ MODULE_DEVICE_TABLE(acpi, h5_acpi_match); static const struct dev_pm_ops h5_serdev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(h5_serdev_suspend, h5_serdev_resume) + SET_RUNTIME_PM_OPS(h5_serdev_suspend, h5_serdev_resume, NULL) }; static const struct of_device_id rtl_bluetooth_of_match[] = {