Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp267217ybe; Wed, 4 Sep 2019 19:40:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+jH86DYQ+Owkw/vEayqmoV6AdWARt0161wDrwJacJJ7PkE1/wWA5fbvCrRWACS9cOLhme X-Received: by 2002:a17:902:8f81:: with SMTP id z1mr974388plo.110.1567651227405; Wed, 04 Sep 2019 19:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567651227; cv=none; d=google.com; s=arc-20160816; b=NM8kEfFuxJmewTc+gC48YA3U6qfwjTjRO388qQfgB7tGRdlk/XgllcKtXXFoqcOHgy damprLej+lXqf3k0l3s/PgQiFX5fmYyprUj1GeceVb346lfnbmHAcbEaa6RKrxof4LXH K9t4Zm7o71w9mouH9kXDMIf763dsns9DWptyty9NpCX7gEovG2BT6q8AzxumzlGFS75G LzPBRameSJUlTbTwMzFyLOU2ILmWert3JDA22p36GvSDCe8OPlKmj6+GB1QG1lVW7f8E 0sZrcS5lghAkMvZS0hCEt6+YhfOqzcTvSS/z/f1I+BMvR+eZ/FU214+8jmvqjipSC7yq Ry7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:authenticated-by; bh=LLhvcNmetPnOVA5AlH9lcS3bQRg8d5Fb8p1UD3d3SMQ=; b=febz5WPLd9ZeBr5XFj1mFWlAdlJzFnfhUXdsWgsbAYSNcZMXBg1eM5iDLtqEIo+J+K asWkviVrQ1BoDtMoMd9EM3wAzQFxgffN8UDPsLp1KJWVY4stS0B71a5Jmr5ewsKpg90w TVQgo7a4AQj2HiVdJv54MYhAOF8EG63OYleykV6P7wLmUBKv9bOgjgk5bm9QZMd5onUN gj75/PlAq7msnR41rv3C7miK6YuKf/HLOdXodCzcy+o+fCEAAUrmiHW+mBsDhx1lfnRs FNWt4DgsgC9DiQXaYzG8E1hyTQzhXQs/mu52vn15t8W5RmhkMAKoYbPhNvHfp+Vb7GH6 H/xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si466289pgv.503.2019.09.04.19.39.53; Wed, 04 Sep 2019 19:40:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730518AbfIECiy (ORCPT + 99 others); Wed, 4 Sep 2019 22:38:54 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:53172 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbfIECiy (ORCPT ); Wed, 4 Sep 2019 22:38:54 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID x852cXBX027863, This message is accepted by code: ctloc85258 Received: from RS-CAS02.realsil.com.cn (doc.realsil.com.cn[172.29.17.3](maybeforged)) by rtits2.realtek.com.tw (8.15.2/2.57/5.78) with ESMTPS id x852cXBX027863 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 5 Sep 2019 10:38:39 +0800 Received: from laptop-alex (172.29.36.155) by RS-CAS02.realsil.com.cn (172.29.17.3) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 5 Sep 2019 10:36:48 +0800 Date: Thu, 5 Sep 2019 10:36:31 +0800 From: Alex Lu To: Marcel Holtmann CC: Johan Hedberg , , , Max Chou Subject: [PATCH v2] Bluetooth: btusb: Use cmd_timeout to reset Realtek device Message-ID: <20190905023631.GA29398@laptop-alex> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Originating-IP: [172.29.36.155] Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Alex Lu Realtek Bluetooth controller provides a BT_DIS reset pin for hardware reset of it. The cmd_timeout is helpful on Realtek bluetooth controller where the firmware gets stuck. Signed-off-by: Alex Lu --- Changes in v2 - Provide a dedicated btusb_rtl_cmd_timeout in case of Realtek hardware drivers/bluetooth/btusb.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 31d3febed187..4ac012df5666 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -524,6 +524,36 @@ static void btusb_intel_cmd_timeout(struct hci_dev *hdev) 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, 0); + msleep(200); + gpiod_set_value_cansleep(reset_gpio, 1); +} + static inline void btusb_free_frags(struct btusb_data *data) { unsigned long flags; @@ -3783,6 +3813,7 @@ static int btusb_probe(struct usb_interface *intf, if (id->driver_info & BTUSB_REALTEK) { hdev->setup = btrtl_setup_realtek; hdev->shutdown = btrtl_shutdown_realtek; + hdev->cmd_timeout = btusb_rtl_cmd_timeout; /* Realtek devices lose their updated firmware over global * suspend that means host doesn't send SET_FEATURE -- 2.21.0