Skip to content

Commit

Permalink
Add version checking to Battery patches to fix incompatability with t…
Browse files Browse the repository at this point in the history
…he 4.5 kernel

Adding in a few kernel version checks using 4.19.0 as the basis of a ktime_t type change makes older kernels incapable of working with the new code. Reintroduced some of the old code to ensure old functionality stays when the user is below 4.19.0.
  • Loading branch information
Joshua-Dickens committed Aug 29, 2023
1 parent 2140ab8 commit a15515c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
4 changes: 3 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.6", "4.5", "4.1", "3.19", "3.18", "3.17", "3.7"]
include:
- kernel: "3.17"
compile_cflags: -fno-pie -Wno-error=format-truncation
Expand All @@ -31,6 +31,8 @@ jobs:
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
2 changes: 2 additions & 0 deletions 4.5/wacom.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ struct wacom_remote {
struct input_dev *input;
bool registered;
struct wacom_battery battery;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)

Check failure on line 169 in 4.5/wacom.h

View workflow job for this annotation

GitHub Actions / checkpatch

WARNING: LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged

Check failure on line 169 in 4.5/wacom.h

View workflow job for this annotation

GitHub Actions / checkpatch

ERROR: space required after that ',' (ctx:VxV)

Check failure on line 169 in 4.5/wacom.h

View workflow job for this annotation

GitHub Actions / checkpatch

ERROR: space required after that ',' (ctx:VxV)

Check failure on line 169 in 4.5/wacom.h

View workflow job for this annotation

GitHub Actions / checkpatch

WARNING: Comparisons should place the constant on the right side of the test
ktime_t active_time;
#endif
} remotes[WACOM_MAX_REMOTES];
};

Expand Down
23 changes: 21 additions & 2 deletions 4.5/wacom_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,7 @@ static void wacom_wireless_work(struct work_struct *work)
return;
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)

Check failure on line 2588 in 4.5/wacom_sys.c

View workflow job for this annotation

GitHub Actions / checkpatch

WARNING: LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged

Check failure on line 2588 in 4.5/wacom_sys.c

View workflow job for this annotation

GitHub Actions / checkpatch

ERROR: space required after that ',' (ctx:VxV)
static void wacom_remote_destroy_battery(struct wacom *wacom, int index)
{
struct wacom_remote *remote = wacom->remote;
Expand All @@ -2596,6 +2597,7 @@ static void wacom_remote_destroy_battery(struct wacom *wacom, int index)
remote->remotes[index].active_time = 0;
}
}
#endif

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

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,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,19,0)
remote->remotes[i].battery.battery = NULL;
#endif
wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
}
}
Expand Down Expand Up @@ -2702,9 +2712,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,19,0)
if (!remote->remotes[index].active_time)
return 0;
#endif

if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
return 0;
Expand All @@ -2721,7 +2733,9 @@ 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;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)
ktime_t kt = ktime_get();
#endif
struct wacom_remote_work_data remote_work_data;
unsigned long flags;
unsigned int count;
Expand All @@ -2747,11 +2761,16 @@ static void wacom_remote_work(struct work_struct *work)

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

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)
if (work_serial) {

if (kt - remote->remotes[i].active_time > WACOM_REMOTE_BATTERY_TIMEOUT
&& remote->remotes[i].active_time != 0)
wacom_remote_destroy_battery(wacom, i);
#else
if (remote_work_data.remote[i].connected) {
#endif

if (remote->remotes[i].serial == work_serial) {
wacom_remote_attach_battery(wacom, i);
Expand Down
10 changes: 8 additions & 2 deletions 4.5/wacom_wac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,11 @@ 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,19,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 @@ -1219,7 +1222,10 @@ static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
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];

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0)
bool connected = data[j+2];
remote_data.remote[i].connected = connected;
#endif
remote_data.remote[i].serial = serial;
}

Expand Down
6 changes: 6 additions & 0 deletions 4.5/wacom_wac.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
#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
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)
#define WACOM_REMOTE_BATTERY_TIMEOUT 21000000000ll
#endif

/* packet length for individual models */
#define WACOM_PKGLEN_BBFUN 9
Expand Down Expand Up @@ -359,6 +362,9 @@ struct hid_data {
struct wacom_remote_work_data {
struct {
u32 serial;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0)
bool connected;
#endif
} remote[WACOM_MAX_REMOTES];
};

Expand Down

0 comments on commit a15515c

Please sign in to comment.