Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3138252pxb; Mon, 25 Jan 2021 07:56:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnxgr9WqCwzFrvsQxZH9jn+TwDTn1ArXol67X8JSoNCnOrFxHm8myulHa47a7/MmQq+3Y9 X-Received: by 2002:a50:fa86:: with SMTP id w6mr1019334edr.98.1611590199796; Mon, 25 Jan 2021 07:56:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611590199; cv=none; d=google.com; s=arc-20160816; b=vnLLEX00NnrEbo+z243vyt6J4z7Nz8yrXm/z56XtI2sVNmgVFYf7A525L6B5m0IdBV Gv9a+UYiRsOLdXOvJ1e2NIsIbiOHub77hKAmS9QNmCKeTFeys+fyAYgeFlUE9yzF1zcs B4jBTSPwBfKSMQ1XL72gTqFPM42FJtehOKrq9gtCdJKXv7cv+BGYvy4/vAwp/0IwTjwu 8F2rS2Fa94bncM7bzh85HIKwlD+zgAKZLQVidCy0o4HFORzfk/LyMh4KoNMzjQc9zIxf IGb9lZ0qPpYH+GVsyWrXdokfs22zZ43DNHKU5RWgv7qUryVdeiDSVGUQCRansjn9JmRB dRAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=a/4Jbh98e9SYvydPJNBqZrryFMNk1Nw41CoOc99qkPk=; b=qeXYvB5dUbThqM++YW9Bl0kqzm9Rlxy8VDpOxjUNvXdAeEsp6QGnrNV9Jr6Xvh3TmC t5sv1zl5yLsAsttg/c+A6e2yvUkgLt/OWi7oqIlPrwf3fXNF41des/Cc0o6oti4grt5D s//l3NCDUP9nC29ZBViTJq/kZ0QNFbtYIGaYGQm5zxf/B06BankN1HixEYrUxSnHfYt+ soehCZ3EGM+MwNQaaolq3SWr71VBT77R57unji4s9SDui2Laq8ms2UBIlvgQsX25+3ae TdcKvnBwf29BSgMihnA1yBq0zLlFrT2XCSD0KXTVY8nTZi1eLNrUffjM3dHlJmMdDpas rDeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si3461442edv.513.2021.01.25.07.56.14; Mon, 25 Jan 2021 07:56:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729808AbhAYPvl convert rfc822-to-8bit (ORCPT + 99 others); Mon, 25 Jan 2021 10:51:41 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:49980 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730511AbhAYPvh (ORCPT ); Mon, 25 Jan 2021 10:51:37 -0500 Received: from marcel-macbook.holtmann.net (p4ff9f11c.dip0.t-ipconnect.de [79.249.241.28]) by mail.holtmann.org (Postfix) with ESMTPSA id A0251CECCE; Mon, 25 Jan 2021 16:26:56 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Subject: Re: [PATCH 1/3] Bluetooth: btusb: Refactor gpio reset From: Marcel Holtmann In-Reply-To: <20210119124258.1.Ide97dd8adadf50af66738852c3c68861734cca1c@changeid> Date: Mon, 25 Jan 2021 16:19:31 +0100 Cc: CrosBT Upstreaming , Miao-chen Chou , michaelfsun@google.com, Bluetooth Kernel Mailing List , Archie Pusaka , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8BIT Message-Id: References: <20210119204315.2611811-1-abhishekpandit@chromium.org> <20210119124258.1.Ide97dd8adadf50af66738852c3c68861734cca1c@changeid> To: Abhishek Pandit-Subedi X-Mailer: Apple Mail (2.3654.40.0.2.32) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Abhishek, > 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); > } You need to explain why this patch is correct. You are removing more code here. And there is an extra check in case of Realtek and a large comment. Regards Marcel