Skip to content

Commit

Permalink
Disable the HID interface when the hardware is shutting down.
Browse files Browse the repository at this point in the history
  • Loading branch information
StollD committed Jul 17, 2023
1 parent 04f59cb commit 56765da
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ struct ipts_context {
struct ipts_buffer feature_report;
struct ipts_buffer descriptor;

bool hid_active;
struct hid_device *hid;

struct ipts_device_info info;
struct ipts_resources resources;

Expand Down
3 changes: 3 additions & 0 deletions src/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ int ipts_control_start(struct ipts_context *ipts)
return ret;
}

ipts_hid_enable(ipts);

ret = ipts_hid_init(ipts, info);
if (ret) {
dev_err(ipts->dev, "Failed to initialize HID device: %d\n", ret);
Expand All @@ -428,6 +430,7 @@ static int _ipts_control_stop(struct ipts_context *ipts)
if (!ipts)
return -EFAULT;

ipts_hid_disable(ipts);
dev_info(ipts->dev, "Stopping IPTS\n");

ret = ipts_receiver_stop(ipts);
Expand Down
19 changes: 19 additions & 0 deletions src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
#include "spec-data.h"
#include "spec-hid.h"

void ipts_hid_enable(struct ipts_context *ipts)
{
WRITE_ONCE(ipts->hid_active, true);
}

void ipts_hid_disable(struct ipts_context *ipts)
{
WRITE_ONCE(ipts->hid_active, false);
}

static int ipts_hid_start(struct hid_device *hid)
{
return 0;
Expand All @@ -46,6 +56,9 @@ static int ipts_hid_parse(struct hid_device *hid)
if (!ipts)
return -EFAULT;

if (!READ_ONCE(ipts->hid_active))
return -ENODEV;

if (ipts->info.intf_eds == 1)
ret = ipts_eds1_get_descriptor(ipts, &buffer, &size);
else
Expand Down Expand Up @@ -80,6 +93,9 @@ static int ipts_hid_raw_request(struct hid_device *hid, unsigned char report_id,
if (!ipts)
return -EFAULT;

if (!READ_ONCE(ipts->hid_active))
return -ENODEV;

if (ipts->info.intf_eds == 1) {
return ipts_eds1_raw_request(ipts, buffer, size, report_id, report_type,
request_type);
Expand Down Expand Up @@ -110,6 +126,9 @@ int ipts_hid_input_data(struct ipts_context *ipts, u32 buffer)
if (!ipts->hid)
return -ENODEV;

if (!READ_ONCE(ipts->hid_active))
return -ENODEV;

header = (struct ipts_data_header *)ipts->resources.data[buffer].address;

temp = ipts->resources.report.address;
Expand Down
3 changes: 3 additions & 0 deletions src/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "context.h"
#include "spec-device.h"

void ipts_hid_enable(struct ipts_context *ipts);
void ipts_hid_disable(struct ipts_context *ipts);

int ipts_hid_input_data(struct ipts_context *ipts, u32 buffer);

int ipts_hid_init(struct ipts_context *ipts, struct ipts_device_info info);
Expand Down

0 comments on commit 56765da

Please sign in to comment.