Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp50271imu; Fri, 16 Nov 2018 17:09:28 -0800 (PST) X-Google-Smtp-Source: AJdET5fjgTAY+ye/Is2RitgThfVaodQ1aJbDrKo6gTOwOF0bW2VOTDpGrFTJDqIlvn+rT7pn74Mf X-Received: by 2002:a63:1e5c:: with SMTP id p28mr12131819pgm.376.1542416968851; Fri, 16 Nov 2018 17:09:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542416968; cv=none; d=google.com; s=arc-20160816; b=uBdUB8hMlsXA5dmOI+pSb/TrB3WaiMKA84lbXL+eRV1GFtDv5etuvAx9rGRLK5tNgi 4JJBS/5fR5gGOiVvmh+iMO9qHqXAt9ALCwCjkeJ6fpGrdzPYg8JuPdzMoDxRcT+i20y6 pI+51L3E27Ao6EhLBVw43aI4MR540vz/t/I1SKUpQqMm7vJTpL86MXpOV7qe49Sk/4tH f9GD3RzMruz4euU7FeKeURjs1JL/qttdyrgIja8nUJyH73ygSKZPCDSYoiViaDzrFLu+ 7ljKIT2/Yfl0IVN8S9LUQFNwlfnRNL6kLPexizWYuD5jvwrvsBqBcltBcXCL3Q0/3ky1 eSYQ== 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=9Bz/gCkqSI0CecCt2g4/WTM1AOdDeQtvlngMweYYdmw=; b=TOicvp5c4qwnR89B2K6abh0s715SnORct3nPvpAvTlElYOANgsPoOWKvO0+LXI3p6H wfHoNiHoImv2hnEtvdcv/TSR1Welk+LB08ifee2/VvanrMFX+0445jj0wFdva210Gzir Yt//L2NNbAXZjxXzyUTGaT/8QxtZwfAKug0CsEYYnP0vY9RaUwRKIEXstrSYmN0D612s Nd96tljLuiRe+X7aDX3x6VtKW0XzeZDl/BE3KBT4NGUoBJNeJd//vv5a+b0E52jTc5KP dJOvVpyZP7gXeDQbH55jQ5feZkJFwFDlyopYi4u76WrLUm8hnXblF9wSHRdiGMBrMnTb r/IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nlgihIct; 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 c190-v6si778161pfa.0.2018.11.16.17.09.14; Fri, 16 Nov 2018 17:09:28 -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=nlgihIct; 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 S1731168AbeKQLXF (ORCPT + 99 others); Sat, 17 Nov 2018 06:23:05 -0500 Received: from mail-qk1-f202.google.com ([209.85.222.202]:37917 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731090AbeKQLXB (ORCPT ); Sat, 17 Nov 2018 06:23:01 -0500 Received: by mail-qk1-f202.google.com with SMTP id l7-v6so55655284qkd.5 for ; Fri, 16 Nov 2018 17:08:19 -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=9Bz/gCkqSI0CecCt2g4/WTM1AOdDeQtvlngMweYYdmw=; b=nlgihIctGCne0mtlEThgsyUWNHtbhJpNh7Z49gDzmEhVdo/LQZm/OA/XsS3egMZ8FK G4chD8RmD72ekB+dcMRvjugvKGX0znbKqtkm69Ne0nKmGG0+0cLvlLb+Enzkwktv78+r +rqn5i+5tKs9Y5IvgtzuOQgqQQXY6NtRE96pr5NYtSMjsUhVH7giRhp+p/r0D/UgHkuI vV96C+IVoEiXhIZBO4pMTLfRRduH1miJBg8vIgkNV1t3KiQ5JXBYEgz/5qYYs+hL1djj eblAGBCjApClh1JtV7aC+fpNL04w0O72N+v3E9BigjIkCNoqPjyc/GFnZZY9imJxjIyi gF8g== 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=9Bz/gCkqSI0CecCt2g4/WTM1AOdDeQtvlngMweYYdmw=; b=JKii2yEaWyVevX+3luspmk+4IcUZEHNRf5YSwAthBQdse1yi2WZEWX8qNQXbQJ4B3B 3laErAozJevJ6TUdGmgfFsFEpQJ83+Y14QjikScTey25ef2l9zU++K3RGS6NMtt3GZQF sXh32AVD14igPSU8xmV4LLuBOT3WYa0DsC6tj7yKLcJsGkVY3ZZ5uPKzdnTZ63+ShehK ZGTBw0TxDxfwk03bvmC+/c++6hslSk4iJUswUkEP2Krj7Lc37g4Ug3pQVVKQcQWn9Q81 OgAkfbevGMJ49KjiPtTufDKjsmawAfxXFJqAvfXgpehUXRNAZvUbguvWfoxOGrGxPGbs X5Lg== X-Gm-Message-State: AA+aEWZ/ERnrc2QxmVmLbrhWaKR7YLnXPDQZVGvBbBMNrnZjxponv/4f Do7o0hP0JoOnuV+iCyoNDt6j8CMrXrHY X-Received: by 2002:a37:fcd:: with SMTP id 74mr5130365qkp.11.1542416899291; Fri, 16 Nov 2018 17:08:19 -0800 (PST) Date: Fri, 16 Nov 2018 17:07:48 -0800 In-Reply-To: <20181117010748.24347-1-rajatja@google.com> Message-Id: <20181117010748.24347-6-rajatja@google.com> Mime-Version: 1.0 References: <20181117010748.24347-1-rajatja@google.com> X-Mailer: git-send-email 2.19.1.1215.g8438c0b245-goog Subject: [PATCH 5/5] Bluetooth: btusb: Use the hw_reset method to allow resetting the 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 BT chip (requested by the HCI core if needed). This has been found helpful on some of 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 --- drivers/bluetooth/btusb.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index e8e148480c91..8aad02d9e211 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -475,6 +476,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; @@ -490,6 +493,28 @@ struct btusb_data { int oob_wake_irq; /* irq for out-of-band wake-on-bt */ }; + +static void btusb_hw_reset(struct hci_dev *hdev) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + struct gpio_desc *reset_gpio = data->reset_gpio; + + /* + * 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 (reset_gpio) { + bt_dev_dbg(hdev, "%s: Initiating HW reset via gpio", __func__); + clear_bit(HCI_QUIRK_HW_RESET_ON_TIMEOUT, &hdev->quirks); + 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; @@ -3030,6 +3055,11 @@ static int btusb_probe(struct usb_interface *intf, SET_HCIDEV_DEV(hdev, &intf->dev); + data->reset_gpio = gpiod_get_optional(&data->udev->dev, "reset", + GPIOD_OUT_LOW); + if (data->reset_gpio) + hdev->hw_reset = btusb_hw_reset; + hdev->open = btusb_open; hdev->close = btusb_close; hdev->flush = btusb_flush; @@ -3085,6 +3115,7 @@ static int btusb_probe(struct usb_interface *intf, 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); + set_bit(HCI_QUIRK_HW_RESET_ON_TIMEOUT, &hdev->quirks); if (id->driver_info & BTUSB_INTEL) { hdev->setup = btusb_setup_intel; @@ -3225,6 +3256,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; } @@ -3268,6 +3301,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.19.1.1215.g8438c0b245-goog