Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3221404pxb; Mon, 25 Jan 2021 09:57:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrgKDZhfFLdAIqb9D2FWgSrlPog/5WvShTrELGAwqrjDIUNfwl+1alvj6GOFh0Y+tM5BkR X-Received: by 2002:a17:906:f144:: with SMTP id gw4mr1107197ejb.189.1611597460350; Mon, 25 Jan 2021 09:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611597460; cv=none; d=google.com; s=arc-20160816; b=OIB0sGYDqH6DCqqizKsr/6nXhKIIERoA24Wpprct1WPDeEXKhQXUDX7qtz5v7feXUU LKO+nF2v3P+x8VPUJGuFGt8TdBvudfsHu33eF5RS32HyQpIoluNHgSwI5Z/yCW4jy23R PynVDyu3V2KULazLGwV+OjM2qEWlHfRK7rbxmb6Ee1qwIhDA14fcaTFUFKxfExrNvsL5 U6Isb3vVK99asoOAjAzwsRv9sasJxyhvD+yAF8Urn27m7K9IYb/lNRr65/fIbK923em5 Re1vjhSfDlOcwYg2iJtCK1U1JMFTNOWEbwh1cuiNKDvO7W8QAHfBy3Ko7nmg0qyro3rL tHrg== 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=+9ndIBHVgUMQWuAn3AzTRhXgu7Ny3MfvfeGuhLgxrHw=; b=Vh1GIuhM8lXGvD+qo+DVKHI1K90zSBqCmJzG2e2P2PfkJGT4CrdZ3SM6YD3/LAnYu7 /8/gXoE9drt8TkuwUG+kwjTQsfCDK7Hm88HpBKQQiva3UeqvvzYwOcIfwT4+riUfrzZ9 YVSMUbEyQDZTCmI2IYzfSuj5SGkG5cmeLPEk4YyM19+eNawfjrVK4VSkGJiqecjQVBqb oJF8K1SLnWU3EEDICzaDaw21FWpE4+8LsuUVYleCwzPrC400YGhDxMAgv6bJzyeg3qWg anRbPeqOAVOJG86NB5I1q4+lr0IAcIBH241oisi/WAApO09QPBW+/0pMxsRwObGhs1tF 7roA== 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 hs42si6098285ejc.136.2021.01.25.09.57.14; Mon, 25 Jan 2021 09:57:40 -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 S1731188AbhAYRxv convert rfc822-to-8bit (ORCPT + 99 others); Mon, 25 Jan 2021 12:53:51 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:33736 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731111AbhAYRwU (ORCPT ); Mon, 25 Jan 2021 12:52:20 -0500 Received: from marcel-macbook.holtmann.net (p4ff9f11c.dip0.t-ipconnect.de [79.249.241.28]) by mail.holtmann.org (Postfix) with ESMTPSA id 8080FCECC8; Mon, 25 Jan 2021 18:58:52 +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 3/3] Bluetooth: btusb: Expose reset gpio to debugfs From: Marcel Holtmann In-Reply-To: <20210119124258.3.I7c6ae9b637f9a77f6e6f2e4256c6a0232476be43@changeid> Date: Mon, 25 Jan 2021 18:51:27 +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: <436E729B-B852-4238-AA42-6FFC2D2BE233@holtmann.org> References: <20210119204315.2611811-1-abhishekpandit@chromium.org> <20210119124258.3.I7c6ae9b637f9a77f6e6f2e4256c6a0232476be43@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, > If btusb has a reset gpio, expose it to userspace so we can toggle the > reset gpio directly. This is useful for testing and error recovery. > > Signed-off-by: Abhishek Pandit-Subedi > Reviewed-by: Miao-chen Chou > --- > > drivers/bluetooth/btusb.c | 46 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c > index 880e9cd4ee713..702be1871ed88 100644 > --- a/drivers/bluetooth/btusb.c > +++ b/drivers/bluetooth/btusb.c > @@ -6,6 +6,7 @@ > * Copyright (C) 2005-2008 Marcel Holtmann > */ > > +#include > #include > #include > #include > @@ -574,6 +575,46 @@ static void btusb_toggle_gpio(struct gpio_desc *desc, unsigned int duration) > gpiod_set_value_cansleep(desc, 0); > } > > +#ifdef CONFIG_DEBUG_FS > +static ssize_t btusb_debugfs_has_reset_gpio(struct file *file, > + char __user *user_buf, > + size_t count, loff_t *ppos) > +{ > + struct hci_dev *hdev = file->private_data; > + struct btusb_data *data = hci_get_drvdata(hdev); > + char buf[3]; > + > + buf[0] = data->reset_gpio ? 'Y' : 'N'; > + buf[1] = '\n'; > + buf[2] = '\0'; > + > + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); > +} > + > +static ssize_t btusb_debugfs_reset_gpio(struct file *file, > + const char __user *user_buf, > + size_t count, loff_t *ppos) > +{ > + struct hci_dev *hdev = file->private_data; > + struct btusb_data *data = hci_get_drvdata(hdev); > + > + if (!data->reset_gpio) > + return -EOPNOTSUPP; > + > + bt_dev_warn(hdev, "Debugfs triggering HW reset via gpio"); > + btusb_toggle_gpio(data->reset_gpio, data->reset_duration_ms); > + > + return count; > +} > + > +static const struct file_operations reset_gpio_fops = { > + .open = simple_open, > + .read = btusb_debugfs_has_reset_gpio, > + .write = btusb_debugfs_reset_gpio, > + .llseek = default_llseek, > +}; > +#endif while I am not convinced that this is the right way, I am fine doing it temporarily. However, please lets create the debugfs file only when a reset GPIO is available and skip the read callback. Only the write one should be supported since there is no point to read the status. The pure existence of the debugfs should indicate support for a HW reset. Regards Marcel