From patchwork Thu Jul 15 14:51:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12380257 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, 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 6EA54C07E96 for ; Thu, 15 Jul 2021 14:52:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D6A1613D1 for ; Thu, 15 Jul 2021 14:52:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237787AbhGOOy7 (ORCPT ); Thu, 15 Jul 2021 10:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231745AbhGOOy7 (ORCPT ); Thu, 15 Jul 2021 10:54:59 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 274D1C061760 for ; Thu, 15 Jul 2021 07:52:06 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id q9-20020a17090a0649b029016ffc6b9665so5928478pje.1 for ; Thu, 15 Jul 2021 07:52:06 -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=GWwy3oOZ69y07SN8q1XZNqakIUZ5F4N1GJmVMzPtwBU=; b=s4NEPQdJJL5YuliIFnV+uZ+/QBjEC++tMKYMRMDKb6scPXeoaKUJ5EyYRef+UWuymL ImYQepakOf2WRLqK6Ukg0pTchGatKUJRDP8GgyAeXmlQSr6BNAabcZFkDp+4NnJDJ12q AmwHLpsLF5brM4w0eGsvqOizS4V0KDL/3QZMfNUJhHyy+/zd0qtB5R1T1ywsHo6CpY8b BGWUiPoIQZTtMG5KkyL1DBTXch4Rnj9Q9Z4cK7w1RnwyGD7OEmqRP7rXvFLeX2rPQlIV t7F4ARRtHm0NIECeG+q5HZ/xjFJf1PBOPDF0d8fTEMz+0wYARjNbqRUsYtSpYgXhRgct CuBQ== 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=GWwy3oOZ69y07SN8q1XZNqakIUZ5F4N1GJmVMzPtwBU=; b=kyu1y6db49ytTYSkQ47fXoNvQjnJXXfEB1iY0c0JMq6c9PE/KIXbahDb2xwcItl2W8 sO9OOHep17ObdKZbR1k4tpBbDixisDL8gegAOBE0kzjY9jtB+uwSzpnCYH/cZq9AK4Ch wRK6/nR1fQb9h8dWG0sGkXc11Tvn3nqOe1j2/Wm/pj7I6EwlCFyIZMwZxsPQZM63RWPX L2Ra/tZ+82PHOvJ1XkdSkP667tqty2mJtdTPsTspleHWuIzbphWjTlx7pgfAjPEWMh9R KpBfhYKdIlqxSkBsyoYKZk+8RF4T80cub4SO3bQ6UQv8pVZOroywe+hbyLZt8ipLSqYE xF3w== X-Gm-Message-State: AOAM532JYj2IWMNajoLFM4mf/VEP9jNXpWpe4POiFRB2MQy4ygSK/Gdg Qg7QtolFclo8OJ9FDvKLuGCSmMbS/xcEgVLE08DezANNhxulUWTBcICn79Y8DHvd+tBCWi5YiKU QO3R37gUxXpu+ciOGNgJA7iKsDmkF8GezCT5m8dTu8Sj3SnV+PywoqHblYbjs8RZSqTxTiMR0q+ nz X-Google-Smtp-Source: ABdhPJzQcTGTd61GeG75V03iAzEfQAhZCWzCCqnXnVQHqR0XeBdQtFRFBq+AxAG0hfF9nxz3VSh5+fRvriU6 X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:d9e1:875d:57dd:2e32]) (user=apusaka job=sendgmr) by 2002:a62:2942:0:b029:2f4:e012:fb23 with SMTP id p63-20020a6229420000b02902f4e012fb23mr5033740pfp.55.1626360725484; Thu, 15 Jul 2021 07:52:05 -0700 (PDT) Date: Thu, 15 Jul 2021 22:51:58 +0800 Message-Id: <20210715225146.v2.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2 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 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 Thu Jul 15 14:51:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12380259 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, 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 1FF8EC07E96 for ; Thu, 15 Jul 2021 14:52:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07DB161360 for ; Thu, 15 Jul 2021 14:52:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238085AbhGOOzG (ORCPT ); Thu, 15 Jul 2021 10:55:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238074AbhGOOzF (ORCPT ); Thu, 15 Jul 2021 10:55:05 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2B91C061760 for ; Thu, 15 Jul 2021 07:52:11 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id n21-20020a6563d50000b029022866cd1f17so4610430pgv.10 for ; Thu, 15 Jul 2021 07:52:11 -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=G+OSuGiOQklLZymMFCTnttGx/CFqtpqkpXlERNqy3WE=; b=gqIJh2s7wmvsRX3Dj0IG07hc4eEq80GIOGi1lQv/P7dMzkW7Ah21y7ZsWZ7/lTiymv JZC8xVnlyUXMn0OwUMK+i77E1zy28v8vFyO7q9sJIa3WD4bkekPSNnz1ddPp1yhfmeP4 s1ZXzMLYjLz1EcH7YOG1RFh1wQP1ukGPHIVmgsKX15LeECtWIRrWqDVMJPA6Gx5M4OEe gMhYV/8RbA2AZxHfytn36Uxvob46KtyhbW9tQ2xbGyxzWvHSUqQmCAsU92/4iT6r3Uiw r0PY9xhmThnJtgH5/hbwXMvTvjO7UL1wdt0U/oflGeetnn35yDe07v/ZkGU6zRSiogfj bWig== 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=G+OSuGiOQklLZymMFCTnttGx/CFqtpqkpXlERNqy3WE=; b=o9i/xmCOZrUBG8fo9qXOwhzT58VzhmYOkBtKAD6GOWSm1iz7zG3Yag1FnEitnBvkZ6 eIGU5q6z1sXS+DlQm4J0Gai9BYbY0mFL3haErLTmZIcw0wyPZ+cucZD7IhH0WL3ESUp3 Sk7DCWa+e3D3/ffyAJ9gs6eM+H5Y2KKgR/sSYVf9zAtq8fzCKM1YCEafyucFRjdHmYyF SYIKCF62f46WqTDOYDTkf3ZWYZKN5PU6bKBAuk94GMupPEKX6HsvknLERleMFH9vbsLn I1Y0vGiN3faL/iFdBZGQyp054VnwyZORyNA3f00hHcqwNwFQxa6bCEl3LIW4vyQux4+d JOMg== X-Gm-Message-State: AOAM530K4Hs5EemV2dhNHlnZegrkIZcogdx76d0dNmX4ruR9LNXiXxnl ykjXsLTZd3y5fTbeK7EUfVCCqgOqZ/snj5G2MR7ZlIfUUVT0TLaqCDS1FQ7FqJ7l+X8BjNtTlWm 4xBpq8zKpMjSo9Ovw9oVBVPhygyGOht1eAD9vdM7Ln/hNTMEH8tVrh6FgtVIIKPQC2ZcbNcpMNj mG X-Google-Smtp-Source: ABdhPJw+PADg00qqa82z+TAch21RdtQtw0XRKi81eKrrsyNFFYQ6eyyU2Vw/R45PWxlKj0Z6vuQG3XwTdoFg X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:d9e1:875d:57dd:2e32]) (user=apusaka job=sendgmr) by 2002:aa7:9e5c:0:b029:32b:4e2a:e549 with SMTP id z28-20020aa79e5c0000b029032b4e2ae549mr5136047pfq.68.1626360731307; Thu, 15 Jul 2021 07:52:11 -0700 (PDT) Date: Thu, 15 Jul 2021 22:51:59 +0800 In-Reply-To: <20210715225146.v2.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> Message-Id: <20210715225146.v2.2.I404c6df9cdab270223c13e867396f440dd4b499d@changeid> Mime-Version: 1.0 References: <20210715225146.v2.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2 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 Thu Jul 15 14:52:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12380261 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=-23.5 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, UNWANTED_LANGUAGE_BODY,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 33A22C07E96 for ; Thu, 15 Jul 2021 14:52:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1564E613D1 for ; Thu, 15 Jul 2021 14:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238128AbhGOOzK (ORCPT ); Thu, 15 Jul 2021 10:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238076AbhGOOzK (ORCPT ); Thu, 15 Jul 2021 10:55:10 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47246C06175F for ; Thu, 15 Jul 2021 07:52:17 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id v16-20020a05622a0150b029025a2609eb04so4263711qtw.17 for ; Thu, 15 Jul 2021 07:52:17 -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=QKhwAp39hW3ocoCF4aqrDutBWf5OOZ3fiizl2xE7StM=; b=ou1UBuj08Z5EqeU3Hlm6zqcnhXaOCJzYPApeTlA42TdireB/FK0ykv2krZXzFyhn7+ Rlh0rYNwzc+wlvdrFjtnDK7Gg1Uu0oIuxVaieECO4drELEvfB2+miH7/Bn+rJ+7TCqep RZuEMAsk+kN6Rd8za0fnyLe6IdVz594NrZJ8ZXtbQ/UF8wKct3aG/vv7jpntnQtjsSwq /jqH6pj1un97POXkh80co5DfUN/mNYg/UNV8KkrVMzS7KtN5+ruLVBX8b3VzMfUg07qk xADhBnLoK2liqXIIorDHve19cY+nxrtOAvulmA3scOdwVFKaJ1AErpVZGAyXT8s9ADgC T/Eg== 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=QKhwAp39hW3ocoCF4aqrDutBWf5OOZ3fiizl2xE7StM=; b=X9h4LoRo9AnMkK7eZ1HU74BM/gBJBlcWoDWlzh1qtuvt0wFdSPIzOuiztvSBA9CESx hEwj+9+hZ0jYmfu04cHvvDEkvRPEDi+UvUti1nSPfK7V4tOHwekwqwSOJiqz0w3FFt8R ko69DhCT0xxlCDt9hfxr6orqInz4qQT9tkLsGMvCDlh5NSzx9xQGYQXiP4P5pnH4eHys ncvfXrYugOd0WjrdkZwWWI7KsrHxOgOdMcV3TtFhzBqK5sXOCpiw+rguoaZ0qZPluece S37tQ7qXBFHANJiMXStKsSJZcMCUU1w5wpUBpnuqGeb1ncNbepioRTFLJ7Tp3HOvncOv K51w== X-Gm-Message-State: AOAM531/tTKLaJ2yupS+g7+1ptNEole0cSHNYfNdUu3eVwxux1yK/xYD AY3z4HYFFPldqnkz4OAVzGGMSloujNqFT5Gt/8GjswwRpyg0tWy8a5uoZA0I3sEflYUMT1CY2qm jA5nyByhjf9pvsqWuGjsY1Ci9+FaZeqDfuc4wE6kxB1vdQMdLUwWG7dneKEyjjl4ZpQ4DE26soo uO X-Google-Smtp-Source: ABdhPJxWOh0bGdoMKCzBaF7LVBpQ3LHdUwc4SOxL2qxRSI/KBLA/4pzMiqNeAqQi79/DaNr08KibnOHM9TiH X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:d9e1:875d:57dd:2e32]) (user=apusaka job=sendgmr) by 2002:a05:6214:4e2:: with SMTP id cl2mr4671805qvb.55.1626360735981; Thu, 15 Jul 2021 07:52:15 -0700 (PDT) Date: Thu, 15 Jul 2021 22:52:00 +0800 In-Reply-To: <20210715225146.v2.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> Message-Id: <20210715225146.v2.3.I4b323d2adf1dca62777c41de344a7d2f79b7f908@changeid> Mime-Version: 1.0 References: <20210715225146.v2.1.I68649745bd11a83265f1e816bf34ecc82775e95a@changeid> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2 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 --- (no changes since v1) 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..f95ec9991180 100644 --- a/drivers/bluetooth/hci_h5.c +++ b/drivers/bluetooth/hci_h5.c @@ -11,6 +11,7 @@ #include #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[] = {