Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2570080imu; Thu, 24 Jan 2019 15:29:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN45jS6NOSqiQIzYoQdZ84A36Vg129vHNYzbAYZSfvT+5AcJyxriLnVwUyDUx9RvwjlxcqEV X-Received: by 2002:a63:504d:: with SMTP id q13mr7891967pgl.319.1548372543461; Thu, 24 Jan 2019 15:29:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548372543; cv=none; d=google.com; s=arc-20160816; b=daYE7k2v32ro1Dwnoc7Vfs+FmMCkCBv+Ljf5/Ef6dacK91CGLyEpmtKLAwe6tztjIe i5plhM2iPTxkTlcuF/uKU1kY0ofqTcjy+LzbMIMeJZbpUSquXY4aD0WXlqauhAN8iAqN 5QFOIALXVkrfLEPhlOUaixf9x74bXzE1jp4W0rEVSIFh+kM4qivpFLsDlHoqIBGMJoUA mU61xLk/nEPPaiOOGTBXNYrQ1zCaX5F1rU8LQn7iwO6eXP4+VXOWU5T4nMsTW743a6wU R6kKllwH+KElX2gDb/ijko8M+cHVHIcXh+YJDuxxf7nxwCuyHUgIZ3ttQGeVbzIViD+w TkxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=AyptAvfvM/wcW1EoZU8xDvJM9SOpx5lXxyZ/dg3vpOA=; b=fP7dSS84MIfTtu4L7zdrFBKqOkJ19/4F0z4Qv/O6i6LEuPyjcnpyRvZtyYZSwnLqAi 2oJTnzGGv3yk24jW7Msz/+ep7pkd5LzAb9etG1bMrGdNha/vbisItENlmExdPO9PXC6M sces699n0GjFcPx+ZcIRNnCXcP+ZH9ngxleFl519CX4Pt0VD1/Xd8b3KxRFgGLoqOy4d Nsi5U26PiJi/C4qhADUJ1MQ2hxnu0GpYZ155kKbgUzzQsYzSlIT0Q0U2qvTkqdnwzaHj uAV6/F7crin72rnkQkbxZJI3fBqhC/epVEwgf69V1DmkEaVkmsh4Q92py6gQknYwpcca HamA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cLMIDUAe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 93si23070814plc.2.2019.01.24.15.28.48; Thu, 24 Jan 2019 15:29:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cLMIDUAe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728481AbfAXX2c (ORCPT + 99 others); Thu, 24 Jan 2019 18:28:32 -0500 Received: from mail-ot1-f73.google.com ([209.85.210.73]:51100 "EHLO mail-ot1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728063AbfAXX2b (ORCPT ); Thu, 24 Jan 2019 18:28:31 -0500 Received: by mail-ot1-f73.google.com with SMTP id h4so2966316otg.17 for ; Thu, 24 Jan 2019 15:28:30 -0800 (PST) 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=AyptAvfvM/wcW1EoZU8xDvJM9SOpx5lXxyZ/dg3vpOA=; b=cLMIDUAeUxUTQwen6ta2KO0L/aNMWhOUpqV7A2dhQbyNN/FXERU+DtaH0fgAA7Z4qr 0zRuEQ8ZxgoEynTK+H0Dxa+tFt72i/BHUSxK+v4NXiyxMADPATUZNY5FIOZ1BKEoEaQL svKhFsx80KRknGu5UaqDkEiyjzKTjtNMkKusH7kUnTUvBkSel+FXl6p8B6H2ChZ7athf lpEjUfO40sMX7/YYBCIOZOMs0Fa4j1Kinnr/cdvE8XGV5jbEgVO2j70ViSESv2qlTkgL jkgZgbWlOGVqsQRubOrsDZmG3aIISY4ULCxaptq4ehEesvP3BBuf3hU79NNUI/OacB5O OetA== 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=AyptAvfvM/wcW1EoZU8xDvJM9SOpx5lXxyZ/dg3vpOA=; b=IuBO5WGZO4kDJrXSy/TYbur0opsxvaeFodEMrkLo50g+8jKeENnYV5pFGgnVDS2hDh PJjNEksGNSJevnPAqFRHoC4aq1oPvrf3h8l4GL0VOo1DqCDMyHAm49YoJIVHfzXQcjnX NT9cmWuEygWjuFxxn6enaD7z/J/Fpc4cySoUzDkNlhjj7bRf4gvgRx6t997aq9BSrcJA jWRQxuz8sYi05dudbimnygrHAAld1dD7e/TIomiDtiG5GWnJfGYuqyHI+10KuIk5Cmt6 Gj/xA7a+G0WhMpko1/EGJJWhOFUyag8IAVsfEk2U7HXShyEHiCxHBawDfuFa3tRPiKad omtA== X-Gm-Message-State: AJcUukeZuiUnHxbB7N4Y6Aq6XvZFz8nDqi9vVYrU/4GWCQpu88G1EXad 0gbdHQcx6IIB8C5hVccT+lZveXqDi9FR X-Received: by 2002:a9d:7f15:: with SMTP id j21mr6121444otq.71.1548372509988; Thu, 24 Jan 2019 15:28:29 -0800 (PST) Date: Thu, 24 Jan 2019 15:28:14 -0800 In-Reply-To: <20190124232814.252661-1-rajatja@google.com> Message-Id: <20190124232814.252661-4-rajatja@google.com> Mime-Version: 1.0 References: <20181117010748.24347-1-rajatja@google.com> <20190124232814.252661-1-rajatja@google.com> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog Subject: [PATCH v6 4/4] Bluetooth: btusb: Use the cmd_timeout method to reset the Intel BT chip From: Rajat Jain To: Marcel Holtmann , Johan Hedberg , Greg Kroah-Hartman , "David S. Miller" , Dmitry Torokhov , Rajat Jain , Alex Hung , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org Cc: rajatxjain@gmail.com, dtor@google.com, raghuram.hegde@intel.com, chethan.tumkur.narayan@intel.com, sukumar.ghorai@intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the platform provides it, use the reset gpio to reset the Intel BT chip, as part of cmd_timeout handling. This has been found helpful on Intel bluetooth controllers where the firmware gets stuck and the only way out is a hard reset pin provided by the platform. Signed-off-by: Rajat Jain --- v6: Move the cmd_timeout() hook assignment with other hooks, move the reset_gpio check in the timeout function. v5: Rename the hook to cmd_timeout, and wait for 5 timeouts before resetting the device. v4: Use data->flags instead of clearing the quirk in btusb_hw_reset() v3: Better error handling for gpiod_get_optional() v2: Handle the EPROBE_DEFER case. drivers/bluetooth/btusb.c | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 4761499db9ee..5de0c2e59b97 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -439,6 +440,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = { #define BTUSB_BOOTING 9 #define BTUSB_DIAG_RUNNING 10 #define BTUSB_OOB_WAKE_ENABLED 11 +#define BTUSB_HW_RESET_ACTIVE 12 struct btusb_data { struct hci_dev *hdev; @@ -476,6 +478,8 @@ struct btusb_data { struct usb_endpoint_descriptor *diag_tx_ep; struct usb_endpoint_descriptor *diag_rx_ep; + struct gpio_desc *reset_gpio; + __u8 cmdreq_type; __u8 cmdreq; @@ -489,8 +493,41 @@ struct btusb_data { int (*setup_on_usb)(struct hci_dev *hdev); int oob_wake_irq; /* irq for out-of-band wake-on-bt */ + unsigned cmd_timeout_cnt; }; + +static void btusb_intel_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 way to reset. Ignoring and continuing"); + return; + } + + /* + * Toggle the hard reset line if the platform provides one. The reset + * is going to yank the device off the USB and then replug. So doing + * once is enough. 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, "Initiating HW reset via gpio"); + gpiod_set_value(reset_gpio, 1); + mdelay(100); + gpiod_set_value(reset_gpio, 0); +} + static inline void btusb_free_frags(struct btusb_data *data) { unsigned long flags; @@ -2915,6 +2952,7 @@ static int btusb_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_endpoint_descriptor *ep_desc; + struct gpio_desc *reset_gpio; struct btusb_data *data; struct hci_dev *hdev; unsigned ifnum_base; @@ -3028,6 +3066,15 @@ static int btusb_probe(struct usb_interface *intf, SET_HCIDEV_DEV(hdev, &intf->dev); + reset_gpio = gpiod_get_optional(&data->udev->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(reset_gpio)) { + err = PTR_ERR(reset_gpio); + goto out_free_dev; + } else if (reset_gpio) { + data->reset_gpio = reset_gpio; + } + hdev->open = btusb_open; hdev->close = btusb_close; hdev->flush = btusb_flush; @@ -3082,6 +3129,7 @@ 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; 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); @@ -3094,6 +3142,7 @@ 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; 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); @@ -3226,6 +3275,8 @@ static int btusb_probe(struct usb_interface *intf, return 0; out_free_dev: + if (data->reset_gpio) + gpiod_put(data->reset_gpio); hci_free_dev(hdev); return err; } @@ -3269,6 +3320,9 @@ static void btusb_disconnect(struct usb_interface *intf) if (data->oob_wake_irq) device_init_wakeup(&data->udev->dev, false); + if (data->reset_gpio) + gpiod_put(data->reset_gpio); + hci_free_dev(hdev); } -- 2.20.1.321.g9e740568ce-goog