Skip to content

Commit

Permalink
ipts: Add a generic interface for quirks
Browse files Browse the repository at this point in the history
Signed-off-by: Dorian Stoll <dorian.stoll@tmsp.io>
  • Loading branch information
StollD committed Nov 10, 2019
1 parent 40f343b commit 55e49e1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
10 changes: 5 additions & 5 deletions drivers/misc/ipts/companion.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,19 @@ int ipts_request_firmware_config(struct ipts_info *ipts,

}

bool ipts_needs_no_feedback(void)
unsigned int ipts_get_quirks(void)
{
bool ret;
unsigned int ret;

// Make sure that access to the companion is synchronized
mutex_lock(&ipts_companion_lock);

// If the companion is ignored, or doesn't exist, assume that
// the device doesn't need no_feedback enabled
// the device doesn't have any quirks
if (ipts_modparams.ignore_companion || ipts_companion == NULL)
ret = false;
ret = IPTS_QUIRK_NONE;
else
ret = ipts_companion->needs_no_feedback(ipts_companion);
ret = ipts_companion->get_quirks(ipts_companion);

mutex_unlock(&ipts_companion_lock);

Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/ipts/companion.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "ipts.h"

bool ipts_companion_available(void);
bool ipts_needs_no_feedback(void);
unsigned int ipts_get_quirks(void);

int ipts_request_firmware(const struct firmware **fw, const char *name,
struct device *device);
Expand Down
30 changes: 15 additions & 15 deletions drivers/misc/ipts/companion/ipts-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,49 @@

struct ipts_surface_data {
const char *hid;
bool no_feedback;
unsigned int quirks;
};

// Surface Book 1 / Surface Studio
static const struct ipts_surface_data ipts_surface_mshw0076 = {
.hid = "MSHW0076",
.no_feedback = true,
.quirks = IPTS_QUIRK_NO_FEEDBACK,
};

// Surface Pro 4
static const struct ipts_surface_data ipts_surface_mshw0078 = {
.hid = "MSHW0078",
.no_feedback = true,
.quirks = IPTS_QUIRK_NO_FEEDBACK,
};

// Surface Laptop 1 / 2
static const struct ipts_surface_data ipts_surface_mshw0079 = {
.hid = "MSHW0079",
.no_feedback = false,
.quirks = IPTS_QUIRK_NONE,
};

// Surface Pro 5 / 6
static const struct ipts_surface_data ipts_surface_mshw0101 = {
.hid = "MSHW0101",
.no_feedback = false,
.quirks = IPTS_QUIRK_NONE,
};

// Surface Book 2 15"
static const struct ipts_surface_data ipts_surface_mshw0102 = {
.hid = "MSHW0102",
.no_feedback = false,
.quirks = IPTS_QUIRK_NONE,
};

// Unknown, but firmware exists
static const struct ipts_surface_data ipts_surface_mshw0103 = {
.hid = "MSHW0103",
.no_feedback = false,
.quirks = IPTS_QUIRK_NONE,
};

// Surface Book 2 13"
static const struct ipts_surface_data ipts_surface_mshw0137 = {
.hid = "MSHW0137",
.no_feedback = false,
.quirks = IPTS_QUIRK_NONE,
};

/*
Expand All @@ -83,7 +83,7 @@ int ipts_surface_request_firmware(struct ipts_companion *companion,
const struct firmware **fw, const char *name,
struct device *device);

bool ipts_surface_needs_no_feedback(struct ipts_companion *companion);
unsigned int ipts_surface_get_quirks(struct ipts_companion *companion);

static struct ipts_bin_fw_info ipts_surface_vendor_kernel = {
.fw_name = "vendor_kernel.bin",
Expand Down Expand Up @@ -119,7 +119,7 @@ static struct ipts_bin_fw_info *ipts_surface_fw_config[] = {
static struct ipts_companion ipts_surface_companion = {
.firmware_request = &ipts_surface_request_firmware,
.firmware_config = ipts_surface_fw_config,
.needs_no_feedback = &ipts_surface_needs_no_feedback,
.get_quirks = &ipts_surface_get_quirks,
.name = "ipts_surface",
};

Expand All @@ -140,18 +140,18 @@ int ipts_surface_request_firmware(struct ipts_companion *companion,
return request_firmware(fw, fw_path, device);
}

bool ipts_surface_needs_no_feedback(struct ipts_companion *companion)
unsigned int ipts_surface_get_quirks(struct ipts_companion *companion)
{
struct ipts_surface_data *data;

// In case something went wrong, assume that the device doesn't
// need the no_feedback option set
// In case something went wrong, assume that the
// device doesn't have any quirks
if (companion == NULL || companion->data == NULL)
return false;
return IPTS_QUIRK_NONE;

data = (struct ipts_surface_data *)companion->data;

return data->no_feedback;
return data->quirks;
}

static int ipts_surface_probe(struct platform_device *pdev)
Expand Down
9 changes: 7 additions & 2 deletions drivers/misc/ipts/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/dmi.h>
#include <linux/firmware.h>
#include <linux/hid.h>
#include <linux/ipts.h>
#include <linux/module.h>
#include <linux/vmalloc.h>

Expand Down Expand Up @@ -444,8 +445,12 @@ static int handle_outputs(struct ipts_info *ipts, int parallel_idx)
*/
if (fb_buf) {
// A negative value means "decide by dmi table"
if (ipts_modparams.no_feedback < 0)
ipts_modparams.no_feedback = ipts_needs_no_feedback();
if (ipts_modparams.no_feedback < 0) {
if (ipts_get_quirks() & IPTS_QUIRK_NO_FEEDBACK)
ipts_modparams.no_feedback = true;
else
ipts_modparams.no_feedback = false;
}

if (ipts_modparams.no_feedback)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/ipts-companion.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <linux/ipts-binary.h>

struct ipts_companion {
bool (*needs_no_feedback)(struct ipts_companion *companion);
unsigned int (*get_quirks)(struct ipts_companion *companion);
int (*firmware_request)(struct ipts_companion *companion,
const struct firmware **fw,
const char *name, struct device *device);
Expand Down
5 changes: 5 additions & 0 deletions include/linux/ipts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
#ifndef IPTS_H
#define IPTS_H

#include <linux/bits.h>

#define MAX_IOCL_FILE_NAME_LEN 80
#define MAX_IOCL_FILE_PATH_LEN 256

#define IPTS_QUIRK_NONE 0
#define IPTS_QUIRK_NO_FEEDBACK BIT(0)

#endif // IPTS_H

0 comments on commit 55e49e1

Please sign in to comment.