From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> 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@xxxxxxxxx> --- drivers/bluetooth/hci_vhci.c | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index 52f9106faeae..60a408a49828 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -137,6 +137,51 @@ static const struct file_operations force_suspend_fops = { .llseek = default_llseek, }; +static bool prevent_wake; + +static ssize_t force_prevent_wake_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + char buf[3]; + + buf[0] = prevent_wake ? 'Y' : 'N'; + buf[1] = '\n'; + buf[2] = '\0'; + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); +} + +static bool hci_debugfs_prevent_wake(struct hci_dev *hdev) +{ + return prevent_wake; +} + +static ssize_t force_prevent_wake_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct hci_dev *hdev = file->private_data; + bool enable; + int err; + + err = kstrtobool_from_user(user_buf, count, &enable); + if (err) + return err; + + if (prevent_wake == enable) + return -EALREADY; + + hdev->prevent_wake = hci_debugfs_prevent_wake; + + 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; @@ -198,6 +243,9 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode) debugfs_create_file("force_suspend", 0644, hdev->debugfs, hdev, &force_suspend_fops); + debugfs_create_file("force_prevent_wake", 0644, hdev->debugfs, hdev, + &force_prevent_wake_fops); + hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; skb_put_u8(skb, 0xff); -- 2.31.1