diff mbox series

[2/2] Bluetooth: hci_vhci: Add force_prevent_wake entry

Message ID 20210929203855.3290899-2-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Delegated to: Marcel Holtmann
Headers show
Series [1/2] Bluetooth: hci_vhci: Add force_suspend entry | expand

Checks

Context Check Description
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS

Commit Message

Luiz Augusto von Dentz Sept. 29, 2021, 8:38 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds force_prevent_wake which can be used to force a certain state
while interacting with force_suspend.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 drivers/bluetooth/hci_vhci.c | 49 ++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

Comments

Marcel Holtmann Sept. 29, 2021, 8:49 p.m. UTC | #1
Hi Luiz,

> This adds force_prevent_wake which can be used to force a certain state
> while interacting with force_suspend.
> 
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> drivers/bluetooth/hci_vhci.c | 49 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 49 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel
diff mbox series

Patch

diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 6cc326c55a24..acf2544dbb05 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -40,6 +40,7 @@  struct vhci_data {
 	struct delayed_work open_timeout;
 
 	bool suspended;
+	bool prevent_wake;
 };
 
 static int vhci_open_dev(struct hci_dev *hdev)
@@ -94,6 +95,13 @@  static int vhci_get_codec_config_data(struct hci_dev *hdev, __u8 type,
 	return 0;
 }
 
+static bool vhci_prevent_wake(struct hci_dev *hdev)
+{
+	struct vhci_data *data = hci_get_drvdata(hdev);
+
+	return data->prevent_wake;
+}
+
 static ssize_t force_suspend_read(struct file *file, char __user *user_buf,
 				  size_t count, loff_t *ppos)
 {
@@ -141,6 +149,43 @@  static const struct file_operations force_suspend_fops = {
 	.llseek		= default_llseek,
 };
 
+static ssize_t force_prevent_wake_read(struct file *file, char __user *user_buf,
+				       size_t count, loff_t *ppos)
+{
+	struct vhci_data *data = file->private_data;
+	char buf[3];
+
+	buf[0] = data->prevent_wake ? 'Y' : 'N';
+	buf[1] = '\n';
+	buf[2] = '\0';
+	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t force_prevent_wake_write(struct file *file,
+					const char __user *user_buf,
+					size_t count, loff_t *ppos)
+{
+	struct vhci_data *data = file->private_data;
+	bool enable;
+	int err;
+
+	err = kstrtobool_from_user(user_buf, count, &enable);
+	if (err)
+		return err;
+
+	if (data->prevent_wake == enable)
+		return -EALREADY;
+
+	return count;
+}
+
+static const struct file_operations force_prevent_wake_fops = {
+	.open		= simple_open,
+	.read		= force_prevent_wake_read,
+	.write		= force_prevent_wake_write,
+	.llseek		= default_llseek,
+};
+
 static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 {
 	struct hci_dev *hdev;
@@ -182,6 +227,7 @@  static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 	hdev->send  = vhci_send_frame;
 	hdev->get_data_path_id = vhci_get_data_path_id;
 	hdev->get_codec_config_data = vhci_get_codec_config_data;
+	hdev->prevent_wake = vhci_prevent_wake;
 
 	/* bit 6 is for external configuration */
 	if (opcode & 0x40)
@@ -202,6 +248,9 @@  static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 	debugfs_create_file("force_suspend", 0644, hdev->debugfs, data,
 			    &force_suspend_fops);
 
+	debugfs_create_file("force_prevent_wake", 0644, hdev->debugfs, data,
+			    &force_prevent_wake_fops);
+
 	hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
 
 	skb_put_u8(skb, 0xff);