Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1735197ybe; Tue, 3 Sep 2019 02:42:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzI88J2P7UKUzQZd67CadX1tat7kAxQ+D6U6Az5BbwzeIZZ69tnkIIa+Iaol6Pkm9XMP8M X-Received: by 2002:a17:90a:8911:: with SMTP id u17mr8582921pjn.128.1567503732431; Tue, 03 Sep 2019 02:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567503732; cv=none; d=google.com; s=arc-20160816; b=FGc8dwX1qmZpmC1puFex5HvQw2y9SjMPJQAbP41yGgPZuDoOItpROEgBtkvqxT79Dj sUoBFuVClGkrw4+/NNUrueWVX9fr2bPdZFmSwYGoHn17hiuy7VkhxNzZ9lBR/0lb3n1m edBgz6SiOe8D1nDvTKQgg8tkWc1SDKJqoqDzUVBml+VxHDpguEo30yMj+ban0QsDtuUX ufOHlleVUdo0GdruflUEydfkr/u2GYwzhPy+MxyD30JBP92JCb1ibQspyP6sw9oHFF17 hN8CUtKcrwp/bO1/ddx31W9GkOGSN0BbZwvNdL8ufl6TDi32NHsoc4tyiyuRd3Hl5ClN Pcvg== 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=OhrN/0QHBLUswYon5OZvG40wsVNJ7T83kfSB0dAucNo=; b=qunZWICZG1OApqxzfgZvZFReV+OHMGP2X/HVF+kmnz2tmXgiKffuRgfuqJKdX6TChy eMrtD2ooC+B/vf2DL0S90dWT+KDwrAQcrmTg78VsCwwiIEPdMXe8TTvIRn2+SpYiaWFR 1dbkOFQRpIRruwW+9coOrQzPSdytFQrlpKSqZMXfoQMEN3OfsW/Trq2fnWaLB1Q7JR9o HB0DVk1WyeYzAmaryHIK7ZBjtzXX7robNuzP23QRWzVnoWanOqLW0EvL1oo8lCSu2qsX Umd9ncJqATo35qr07ZO34dhSjvFTBbGznRmlIGAZ51dqI+Og6zaWXTuYlZ9aLNhrqxsc eaUQ== 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 f128si13967293pgc.55.2019.09.03.02.41.45; Tue, 03 Sep 2019 02:42:12 -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 S1728438AbfICJle (ORCPT + 99 others); Tue, 3 Sep 2019 05:41:34 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:43746 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726631AbfICJld (ORCPT ); Tue, 3 Sep 2019 05:41:33 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID x839fLmN001132, 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 x839fLmN001132 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 3 Sep 2019 17:41:22 +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; Tue, 3 Sep 2019 17:41:20 +0800 Date: Tue, 3 Sep 2019 17:41:03 +0800 From: Alex Lu To: Marcel Holtmann CC: Johan Hedberg , , , Max Chou Subject: [PATCH] Bluetooth: btusb: Use cmd_timeout to reset Realtek device Message-ID: <20190903094103.GA10714@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 --- drivers/bluetooth/btusb.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 31d3febed187..a626de3a3f4c 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -489,16 +489,19 @@ 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; + unsigned int cmd_timeout_cnt; + unsigned int cmd_timeout_max; + unsigned int reset_msecs; + int reset_gpio_value; }; -static void btusb_intel_cmd_timeout(struct hci_dev *hdev) +static void btusb_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) + if (++data->cmd_timeout_cnt < data->cmd_timeout_max) return; if (!reset_gpio) { @@ -519,9 +522,9 @@ 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); + gpiod_set_value_cansleep(reset_gpio, data->reset_gpio_value); + msleep(data->reset_msecs); + gpiod_set_value_cansleep(reset_gpio, !data->reset_gpio_value); } static inline void btusb_free_frags(struct btusb_data *data) @@ -3723,7 +3726,10 @@ 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_cmd_timeout; + data->cmd_timeout_max = 5; + data->reset_msecs = 100; + data->reset_gpio_value = 1; 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); @@ -3737,7 +3743,10 @@ 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_cmd_timeout; + data->cmd_timeout_max = 5; + data->reset_msecs = 100; + data->reset_gpio_value = 1; 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); @@ -3783,6 +3792,10 @@ 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_cmd_timeout; + data->cmd_timeout_max = 5; + data->reset_msecs = 200; + data->reset_gpio_value = 0; /* Realtek devices lose their updated firmware over global * suspend that means host doesn't send SET_FEATURE -- 2.21.0