[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210119124258.3.I7c6ae9b637f9a77f6e6f2e4256c6a0232476be43@changeid>
Date: Tue, 19 Jan 2021 12:43:14 -0800
From: Abhishek Pandit-Subedi <abhishekpandit@...omium.org>
To: marcel@...tmann.org
Cc: chromeos-bluetooth-upstreaming@...omium.org, mcchou@...omium.org,
michaelfsun@...gle.com, linux-bluetooth@...r.kernel.org,
apusaka@...omium.org,
Abhishek Pandit-Subedi <abhishekpandit@...omium.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Luiz Augusto von Dentz <luiz.dentz@...il.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH 3/3] Bluetooth: btusb: Expose reset gpio to debugfs
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 <abhishekpandit@...omium.org>
Reviewed-by: Miao-chen Chou <mcchou@...omium.org>
---
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 <marcel@...tmann.org>
*/
+#include <linux/debugfs.h>
#include <linux/dmi.h>
#include <linux/module.h>
#include <linux/usb.h>
@@ -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
+
static void btusb_gpio_cmd_timeout(struct hci_dev *hdev)
{
struct btusb_data *data = hci_get_drvdata(hdev);
@@ -4625,6 +4666,11 @@ static int btusb_probe(struct usb_interface *intf,
if (err < 0)
goto out_free_dev;
+#ifdef CONFIG_DEBUG_FS
+ debugfs_create_file("toggle_hw_reset", 0644, hdev->debugfs, hdev,
+ &reset_gpio_fops);
+#endif
+
usb_set_intfdata(intf, data);
return 0;
--
2.30.0.284.gd98b1dd5eaa7-goog
Powered by blists - more mailing lists