Skip to content

Commit

Permalink
Merge pull request #391 from linuxwacom/for-6.6
Browse files Browse the repository at this point in the history
For 6.6
  • Loading branch information
Joshua-Dickens authored Aug 31, 2023
2 parents 950f0f1 + e905eb1 commit f67bffb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
kernel: ["6.3", "5.10", "4.14", "4.6", "4.5", "4.1", "3.19", "3.18", "3.17"]
kernel: ["6.3", "5.10", "4.19", "4.14", "4.10", "4.6", "4.5", "4.2", "4.1", "3.19", "3.18", "3.17"]
include:
- kernel: "3.17"
compile_cflags: -fno-pie -Wno-error=format-truncation
Expand All @@ -23,14 +23,22 @@ jobs:
- kernel: "4.1"
compile_cflags: -fno-pie -Wno-error=format-truncation
prepare_cflags: -fno-pie -no-pie
- kernel: "4.2"
compile_cflags: -fno-pie -Wno-error=format-truncation
prepare_cflags: -fno-pie -no-pie
- kernel: "4.5"
compile_cflags: -fno-pie -Wno-error=format-truncation -Wno-error=pointer-sign
prepare_cflags: -fno-pie -no-pie
- kernel: "4.6"
compile_cflags: -fno-pie -Wno-error=format-truncation -Wno-error=pointer-sign
prepare_cflags: -fno-pie -no-pie
- kernel: "4.10"
compile_cflags: -fno-pie -Wno-error=format-truncation -Wno-error=pointer-sign
prepare_cflags: -fno-pie -no-pie
- kernel: "4.14"
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
- kernel: "4.19"
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
- kernel: "5.10"
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
- kernel: "6.3"
Expand Down
3 changes: 3 additions & 0 deletions 4.5/wacom.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ struct wacom_remote {
struct input_dev *input;
bool registered;
struct wacom_battery battery;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
ktime_t active_time;
#endif
} remotes[WACOM_MAX_REMOTES];
};

Expand Down
53 changes: 44 additions & 9 deletions 4.5/wacom_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ static int wacom_initialize_remotes(struct wacom *wacom)
spin_lock_init(&remote->remote_lock);

error = kfifo_alloc(&remote->remote_fifo,
5 * sizeof(struct wacom_remote_data),
5 * sizeof(struct wacom_remote_work_data),
GFP_KERNEL);
if (error) {
hid_err(wacom->hdev, "failed allocating remote_fifo\n");
Expand Down Expand Up @@ -2585,6 +2585,20 @@ static void wacom_wireless_work(struct work_struct *work)
return;
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
static void wacom_remote_destroy_battery(struct wacom *wacom, int index)
{
struct wacom_remote *remote = wacom->remote;

if (remote->remotes[index].battery.battery) {
devres_release_group(&wacom->hdev->dev,
&remote->remotes[index].battery.bat_desc);
remote->remotes[index].battery.battery = NULL;
remote->remotes[index].active_time = 0;
}
}
#endif

static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
{
struct wacom_remote *remote = wacom->remote;
Expand All @@ -2599,17 +2613,23 @@ static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
remote->remotes[i].registered = false;
spin_unlock_irqrestore(&remote->remote_lock, flags);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
wacom_remote_destroy_battery(wacom, i);
#else
if (remote->remotes[i].battery.battery)
devres_release_group(&wacom->hdev->dev,
&remote->remotes[i].battery.bat_desc);
#endif

if (remote->remotes[i].group.name)
devres_release_group(&wacom->hdev->dev,
&remote->remotes[i]);

remote->remotes[i].serial = 0;
remote->remotes[i].group.name = NULL;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
remote->remotes[i].battery.battery = NULL;
#endif
wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
}
}
Expand Down Expand Up @@ -2694,6 +2714,11 @@ static int wacom_remote_attach_battery(struct wacom *wacom, int index)
if (remote->remotes[index].battery.battery)
return 0;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
if (!remote->remotes[index].active_time)
return 0;
#endif

if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
return 0;

Expand All @@ -2709,17 +2734,21 @@ static void wacom_remote_work(struct work_struct *work)
{
struct wacom *wacom = container_of(work, struct wacom, remote_work);
struct wacom_remote *remote = wacom->remote;
struct wacom_remote_data data;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
ktime_t kt = ktime_get();
#endif
struct wacom_remote_work_data remote_work_data;
unsigned long flags;
unsigned int count;
u32 serial;
u32 work_serial;
int i;

spin_lock_irqsave(&remote->remote_lock, flags);

count = kfifo_out(&remote->remote_fifo, &data, sizeof(data));
count = kfifo_out(&remote->remote_fifo, &remote_work_data,
sizeof(remote_work_data));

if (count != sizeof(data)) {
if (count != sizeof(remote_work_data)) {
hid_err(wacom->hdev,
"workitem triggered without status available\n");
spin_unlock_irqrestore(&remote->remote_lock, flags);
Expand All @@ -2732,18 +2761,24 @@ static void wacom_remote_work(struct work_struct *work)
spin_unlock_irqrestore(&remote->remote_lock, flags);

for (i = 0; i < WACOM_MAX_REMOTES; i++) {
serial = data.remote[i].serial;
if (data.remote[i].connected) {
work_serial = remote_work_data.remote[i].serial;
if (work_serial) {

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
if (kt - remote->remotes[i].active_time > WACOM_REMOTE_BATTERY_TIMEOUT
&& remote->remotes[i].active_time != 0)
wacom_remote_destroy_battery(wacom, i);
#endif

if (remote->remotes[i].serial == serial) {
if (remote->remotes[i].serial == work_serial) {
wacom_remote_attach_battery(wacom, i);
continue;
}

if (remote->remotes[i].serial)
wacom_remote_destroy_one(wacom, i);

wacom_remote_create_one(wacom, serial, i);
wacom_remote_create_one(wacom, work_serial, i);

} else if (remote->remotes[i].serial) {
wacom_remote_destroy_one(wacom, i);
Expand Down
9 changes: 5 additions & 4 deletions 4.5/wacom_wac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
if (index < 0 || !remote->remotes[index].registered)
goto out;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
remote->remotes[i].active_time = ktime_get();
#endif
input = remote->remotes[index].input;

input_report_key(input, BTN_0, (data[9] & 0x01));
Expand Down Expand Up @@ -1206,22 +1209,20 @@ static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
unsigned char *data = wacom_wac->data;
struct wacom_remote *remote = wacom->remote;
struct wacom_remote_data remote_data;
struct wacom_remote_work_data remote_data;
unsigned long flags;
int i, ret;

if (data[0] != WACOM_REPORT_DEVICE_LIST)
return;

memset(&remote_data, 0, sizeof(struct wacom_remote_data));
memset(&remote_data, 0, sizeof(struct wacom_remote_work_data));

for (i = 0; i < WACOM_MAX_REMOTES; i++) {
int j = i * 6;
int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
bool connected = data[j+2];

remote_data.remote[i].serial = serial;
remote_data.remote[i].connected = connected;
}

spin_lock_irqsave(&remote->remote_lock, flags);
Expand Down
5 changes: 3 additions & 2 deletions 4.5/wacom_wac.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include <linux/types.h>
#include <linux/hid.h>
#include <linux/kfifo.h>
#include <linux/version.h>

/* maximum packet length for USB/BT devices */
#define WACOM_PKGLEN_MAX 361

#define WACOM_NAME_MAX 64
#define WACOM_MAX_REMOTES 5
#define WACOM_STATUS_UNKNOWN 255
#define WACOM_REMOTE_BATTERY_TIMEOUT 21000000000ll

/* packet length for individual models */
#define WACOM_PKGLEN_BBFUN 9
Expand Down Expand Up @@ -355,10 +357,9 @@ struct hid_data {
#endif
};

struct wacom_remote_data {
struct wacom_remote_work_data {
struct {
u32 serial;
bool connected;
} remote[WACOM_MAX_REMOTES];
};

Expand Down

0 comments on commit f67bffb

Please sign in to comment.