From patchwork Tue Jan 19 20:43:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 366291 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=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 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 C49D6C433DB for ; Tue, 19 Jan 2021 21:06:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 711F822DD3 for ; Tue, 19 Jan 2021 21:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730072AbhASVGU (ORCPT ); Tue, 19 Jan 2021 16:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730322AbhASUoE (ORCPT ); Tue, 19 Jan 2021 15:44:04 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE59BC061575 for ; Tue, 19 Jan 2021 12:43:23 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id g15so13701244pgu.9 for ; Tue, 19 Jan 2021 12:43:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eYstqhli6N+sahNXc/wERW/CDhvU6FkfRRkqcnghmTo=; b=C7Ns0cVwdNZmTCktOQ2rts/vUB6NcyHIqMIjNhWQQs1NCQ0luZ9mFeymqFF/mhg2r1 X/2meBmitakCbfg7ofTMmpjyF/voX4nlb2+St8IsynKna7jBLIVLLlJysjIyqF/wXF+3 /1tIZtXLH7xI8JFiOJG9TL769JwSwgyzo/Moc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eYstqhli6N+sahNXc/wERW/CDhvU6FkfRRkqcnghmTo=; b=teG+EEstSqs9RWEQZCR5qWarKCew2l9sQIYS7BshZO22+CmzeO/DnqdgHhSk8xmRLh WTTekczp2rj6/a8ziFvPC3NIvTWfBtOw+zpk8ELIC7ISUUBkP9b454MNuO1SWl+abhOi 9MRSMEblKjTGoPE2ITV7O1w27s1qzex4kp0FaSL8m8nuXBLXoVMWJysKXNXKD5ACn3rU S1hDVrD6vHdMjNowurDe3fH8tPspKwk6JBMkSJvFMA6qevvpNwoTyz5mSssSG34xXm7H lY7QjyUEMYpe7RJqEx8BvIA1KmgAuwIXgQXLUhSkS4/oJ3A4v+3e3PXaQriLRRElWHsi 7aog== X-Gm-Message-State: AOAM531Ns5Yo4G69Z7UU78c8h4igE+otA09R9iKy1ZCA93wBQ4ly62vt UihsfDmvZ1qRAfAhxeS2lspmAw== X-Google-Smtp-Source: ABdhPJz1DWhBscYgSOIMB518dmodW2S/xbcATN+vkDFFsTkqPLBpOHrpuJk747ZwwhUvmAOcZKEDyQ== X-Received: by 2002:a62:ae18:0:b029:1a9:ac67:3b1c with SMTP id q24-20020a62ae180000b02901a9ac673b1cmr5704029pff.29.1611089003419; Tue, 19 Jan 2021 12:43:23 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id x15sm13835pfa.80.2021.01.19.12.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 12:43:22 -0800 (PST) From: Abhishek Pandit-Subedi To: marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, mcchou@chromium.org, michaelfsun@google.com, linux-bluetooth@vger.kernel.org, apusaka@chromium.org, Abhishek Pandit-Subedi , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] Bluetooth: btusb: Refactor gpio reset Date: Tue, 19 Jan 2021 12:43:12 -0800 Message-Id: <20210119124258.1.Ide97dd8adadf50af66738852c3c68861734cca1c@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210119204315.2611811-1-abhishekpandit@chromium.org> References: <20210119204315.2611811-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Refactor gpio reset to use a common gpio reset function. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Miao-chen Chou --- drivers/bluetooth/btusb.c | 59 +++++++++++++-------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index b14102fba6018..03341e6cbf3ed 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -547,6 +547,7 @@ struct btusb_data { struct usb_endpoint_descriptor *diag_rx_ep; struct gpio_desc *reset_gpio; + unsigned int reset_duration_ms; __u8 cmdreq_type; __u8 cmdreq; @@ -566,15 +567,21 @@ struct btusb_data { unsigned cmd_timeout_cnt; }; -static void btusb_intel_cmd_timeout(struct hci_dev *hdev) +static void btusb_toggle_gpio(struct gpio_desc *desc, unsigned int duration) +{ + gpiod_set_value_cansleep(desc, 1); + msleep(duration); + gpiod_set_value_cansleep(desc, 0); +} + +static void btusb_gpio_cmd_timeout(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); - struct gpio_desc *reset_gpio = data->reset_gpio; if (++data->cmd_timeout_cnt < 5) return; - if (!reset_gpio) { + if (!data->reset_gpio) { bt_dev_err(hdev, "No way to reset. Ignoring and continuing"); return; } @@ -592,39 +599,7 @@ static void btusb_intel_cmd_timeout(struct hci_dev *hdev) } bt_dev_err(hdev, "Initiating HW reset via gpio"); - gpiod_set_value_cansleep(reset_gpio, 1); - msleep(100); - gpiod_set_value_cansleep(reset_gpio, 0); -} - -static void btusb_rtl_cmd_timeout(struct hci_dev *hdev) -{ - struct btusb_data *data = hci_get_drvdata(hdev); - struct gpio_desc *reset_gpio = data->reset_gpio; - - if (++data->cmd_timeout_cnt < 5) - return; - - if (!reset_gpio) { - bt_dev_err(hdev, "No gpio to reset Realtek device, ignoring"); - return; - } - - /* Toggle the hard reset line. The Realtek device is going to - * yank itself off the USB and then replug. The cleanup is handled - * correctly on the way out (standard USB disconnect), and the new - * device is detected cleanly and bound to the driver again like - * it should be. - */ - if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { - bt_dev_err(hdev, "last reset failed? Not resetting again"); - return; - } - - bt_dev_err(hdev, "Reset Realtek device via gpio"); - gpiod_set_value_cansleep(reset_gpio, 1); - msleep(200); - gpiod_set_value_cansleep(reset_gpio, 0); + btusb_toggle_gpio(data->reset_gpio, data->reset_duration_ms); } static void btusb_qca_cmd_timeout(struct hci_dev *hdev) @@ -4462,7 +4437,8 @@ static int btusb_probe(struct usb_interface *intf, hdev->shutdown = btusb_shutdown_intel; hdev->set_diag = btintel_set_diag_mfg; hdev->set_bdaddr = btintel_set_bdaddr; - hdev->cmd_timeout = btusb_intel_cmd_timeout; + hdev->cmd_timeout = btusb_gpio_cmd_timeout; + data->reset_duration_ms = 100; set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); @@ -4476,7 +4452,8 @@ static int btusb_probe(struct usb_interface *intf, hdev->hw_error = btintel_hw_error; hdev->set_diag = btintel_set_diag; hdev->set_bdaddr = btintel_set_bdaddr; - hdev->cmd_timeout = btusb_intel_cmd_timeout; + hdev->cmd_timeout = btusb_gpio_cmd_timeout; + data->reset_duration_ms = 100; set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); @@ -4490,7 +4467,8 @@ static int btusb_probe(struct usb_interface *intf, hdev->hw_error = btintel_hw_error; hdev->set_diag = btintel_set_diag; hdev->set_bdaddr = btintel_set_bdaddr; - hdev->cmd_timeout = btusb_intel_cmd_timeout; + hdev->cmd_timeout = btusb_gpio_cmd_timeout; + data->reset_duration_ms = 100; set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); @@ -4557,7 +4535,8 @@ static int btusb_probe(struct usb_interface *intf, (id->driver_info & BTUSB_REALTEK)) { hdev->setup = btrtl_setup_realtek; hdev->shutdown = btrtl_shutdown_realtek; - hdev->cmd_timeout = btusb_rtl_cmd_timeout; + hdev->cmd_timeout = btusb_gpio_cmd_timeout; + data->reset_duration_ms = 200; /* Realtek devices lose their updated firmware over global * suspend that means host doesn't send SET_FEATURE From patchwork Tue Jan 19 20:43:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 366292 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=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 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 D616AC433E0 for ; Tue, 19 Jan 2021 20:44:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88F562310B for ; Tue, 19 Jan 2021 20:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730379AbhASUoa (ORCPT ); Tue, 19 Jan 2021 15:44:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730331AbhASUoF (ORCPT ); Tue, 19 Jan 2021 15:44:05 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38C19C0613C1 for ; Tue, 19 Jan 2021 12:43:25 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id p15so694200pjv.3 for ; Tue, 19 Jan 2021 12:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2KPL8bz/DsmwTeTaJ4A3VI/judTjbMrQhWrVgCOV11c=; b=GTbi5NVABmar6gXKJ2rGY5w0Kaoyj6OX4eP8CdhOHzJWUoLXhcRZajGg/NE8jsrund mq55GrutSYVzE7mKJG3Vk0oF/L/8KWQqzgxAwirtgJdLbmCGvLLrOXv1NrdfazU5Ihsq dOwiEDoKR9IKQNWfMGxKvkkPwmHW/cBYIhA7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2KPL8bz/DsmwTeTaJ4A3VI/judTjbMrQhWrVgCOV11c=; b=P83UCSBsh+hxFGL/d+Tn/HabYNR6Cyr7UIYs/YEZJG6oJVOiS36PnizWjhKv9xJMMB QU99lgTciFdZoeIkLimMRhdngoM5bbR15KDwBBisV3R4jhejFTNhWdsjZFiYU1ggGj1p iEvZOILecY25pu75e/3RQJPCNwACaNBej7odKpomdiKi9SODvOy8oatZPT4ewFR0VKsO LnnULbU+vOapUZCyJt2zMuBsyt38Tkq6loLAhCirRAoGd96cMo2XA6gqRARVJVRIRmMY TQ5LzaFWhLpC+WRABljA28ijBFyDJl+dta971FhnfLOJlyEMyEwg9JZpfu6vTxNY2Qr8 5wgg== X-Gm-Message-State: AOAM530xvVIIdA0MGpPOrCnEKMLcboEQ1k4RPOxM2QqYXkS1zy8Mc0TX 21KsQM46HmF7DKqhUpkvowyCAw== X-Google-Smtp-Source: ABdhPJz71RGGjKYuVOHERmx7xaJriybr2/w8Dr7ETf2Zs6/LYn1K4HSQCGy/aYohUgYfBSWAh5n9+w== X-Received: by 2002:a17:903:1c2:b029:de:ad0a:2dbf with SMTP id e2-20020a17090301c2b02900dead0a2dbfmr6620147plh.44.1611089004824; Tue, 19 Jan 2021 12:43:24 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id x15sm13835pfa.80.2021.01.19.12.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 12:43:24 -0800 (PST) From: Abhishek Pandit-Subedi To: marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, mcchou@chromium.org, michaelfsun@google.com, linux-bluetooth@vger.kernel.org, apusaka@chromium.org, Abhishek Pandit-Subedi , Daniel Winkler , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] Bluetooth: btusb: Trigger gpio reset quicker Date: Tue, 19 Jan 2021 12:43:13 -0800 Message-Id: <20210119124258.2.I52cc5d2b62fdeb5f3c5249d41f3631ae25d8dc71@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210119204315.2611811-1-abhishekpandit@chromium.org> References: <20210119204315.2611811-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Currently, btusb will only trigger gpio reset during cmd_timeout after 5 commands fail. This number is arbitrarily large and can result in resets taking longer to occur than necessary. Reduce this number to 3, which was chosen as a recommended value by Intel (their firmware allow two commands in flight so they recommend resetting on the third failed command). Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Miao-chen Chou Reviewed-by: Daniel Winkler --- drivers/bluetooth/btusb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 03341e6cbf3ed..880e9cd4ee713 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -578,7 +578,7 @@ static void btusb_gpio_cmd_timeout(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); - if (++data->cmd_timeout_cnt < 5) + if (++data->cmd_timeout_cnt < 3) return; if (!data->reset_gpio) { From patchwork Tue Jan 19 20:43:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 367218 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=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 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 5FC51C433DB for ; Tue, 19 Jan 2021 21:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0349722DD3 for ; Tue, 19 Jan 2021 21:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730238AbhASVFH (ORCPT ); Tue, 19 Jan 2021 16:05:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbhASUo6 (ORCPT ); Tue, 19 Jan 2021 15:44:58 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A35F3C0613D3 for ; Tue, 19 Jan 2021 12:43:26 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id g3so11233906plp.2 for ; Tue, 19 Jan 2021 12:43:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wsfZjzlNzJXVW++ya1lrDyULLQkDWoVC/E0GTcKu51k=; b=ee5dAIFBSCWqkpeMwwe2Q5AQnVcdwExjk+0JJ3ZY+5vKlD4PfmYwhdrvPq/3nzGkjR LWEEGlR9t/jobNVnioo1lLPJU0fh4gTUoxxhwIfxlkvGErJrLnnpcNQjkagpKDQ+A9m8 HMxNfCi+2xn+EHNLyh2/v80Q0KfGHp1adQqA0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wsfZjzlNzJXVW++ya1lrDyULLQkDWoVC/E0GTcKu51k=; b=m34EMf74FDWtv4kepT1tQuvIdDDf57cmrG1EHT8EsGGnium+D0m/+O8lghP8zhDz4d s0+GRwiZpYCfUPqLcZRfDwHy3DKfrslJgjeDBIo20/6zNFFqJbwnbgrLnvcRPsqy810K 9wBlJ258xpipyqRd5rdsXi+aPB9NANyRT7NUZ/W+p7RhwTsH9Rufyj2wrzXdVgS1/fOm BI4L8sFB7DwXA4Q+u4+Isl+szYhHtq9aKz3hJWKDLkH4t5dZPuI5sjOIkAC/eW1FFRtt ZuuwkTHmTtC8i9SwbtqoLvpA0zzmBTmsHk6hi1Wec7hcggJFZIQFcv2qT3y9ARI9AGrt YXyQ== X-Gm-Message-State: AOAM532gWRJgi3valKj580PNNkO9GAKejxHNl+/2K7fb7rKp0kz8w5ys Lnq1toMqOfvc6h3LjrGerGgspQ== X-Google-Smtp-Source: ABdhPJydbVhkgkAOI+VFO4e2Os6eSIgJINtaIF/pQjNKUmVP045sHTczGR+2I740dosNO1DABMG8qw== X-Received: by 2002:a17:902:ec06:b029:de:67a0:989d with SMTP id l6-20020a170902ec06b02900de67a0989dmr6506516pld.53.1611089006265; Tue, 19 Jan 2021 12:43:26 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id x15sm13835pfa.80.2021.01.19.12.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 12:43:25 -0800 (PST) From: Abhishek Pandit-Subedi To: marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, mcchou@chromium.org, michaelfsun@google.com, linux-bluetooth@vger.kernel.org, apusaka@chromium.org, Abhishek Pandit-Subedi , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] Bluetooth: btusb: Expose reset gpio to debugfs Date: Tue, 19 Jan 2021 12:43:14 -0800 Message-Id: <20210119124258.3.I7c6ae9b637f9a77f6e6f2e4256c6a0232476be43@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210119204315.2611811-1-abhishekpandit@chromium.org> References: <20210119204315.2611811-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If btusb has a reset gpio, expose it to userspace so we can toggle the reset gpio directly. This is useful for testing and error recovery. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Miao-chen Chou --- drivers/bluetooth/btusb.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 880e9cd4ee713..702be1871ed88 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -6,6 +6,7 @@ * Copyright (C) 2005-2008 Marcel Holtmann */ +#include #include #include #include @@ -574,6 +575,46 @@ static void btusb_toggle_gpio(struct gpio_desc *desc, unsigned int duration) gpiod_set_value_cansleep(desc, 0); } +#ifdef CONFIG_DEBUG_FS +static ssize_t btusb_debugfs_has_reset_gpio(struct file *file, + char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct hci_dev *hdev = file->private_data; + struct btusb_data *data = hci_get_drvdata(hdev); + char buf[3]; + + buf[0] = data->reset_gpio ? 'Y' : 'N'; + buf[1] = '\n'; + buf[2] = '\0'; + + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); +} + +static ssize_t btusb_debugfs_reset_gpio(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct hci_dev *hdev = file->private_data; + struct btusb_data *data = hci_get_drvdata(hdev); + + if (!data->reset_gpio) + return -EOPNOTSUPP; + + bt_dev_warn(hdev, "Debugfs triggering HW reset via gpio"); + btusb_toggle_gpio(data->reset_gpio, data->reset_duration_ms); + + return count; +} + +static const struct file_operations reset_gpio_fops = { + .open = simple_open, + .read = btusb_debugfs_has_reset_gpio, + .write = btusb_debugfs_reset_gpio, + .llseek = default_llseek, +}; +#endif + static void btusb_gpio_cmd_timeout(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); @@ -4625,6 +4666,11 @@ static int btusb_probe(struct usb_interface *intf, if (err < 0) goto out_free_dev; +#ifdef CONFIG_DEBUG_FS + debugfs_create_file("toggle_hw_reset", 0644, hdev->debugfs, hdev, + &reset_gpio_fops); +#endif + usb_set_intfdata(intf, data); return 0;