-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from linux-surface/ipts-hid-6.1
HID based IPTS and ITHC support, 6.1 edition
- Loading branch information
Showing
47 changed files
with
3,922 additions
and
1,307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2016 Intel Corporation | ||
* Copyright (c) 2020-2023 Dorian Stoll | ||
* | ||
* Linux driver for Intel Precise Touch & Stylus | ||
*/ | ||
|
||
#include <linux/errno.h> | ||
#include <linux/types.h> | ||
|
||
#include "cmd.h" | ||
#include "context.h" | ||
#include "mei.h" | ||
#include "spec-device.h" | ||
|
||
int ipts_cmd_recv_timeout(struct ipts_context *ipts, enum ipts_command_code code, | ||
struct ipts_response *rsp, u64 timeout) | ||
{ | ||
int ret = 0; | ||
|
||
if (!ipts) | ||
return -EFAULT; | ||
|
||
if (!rsp) | ||
return -EFAULT; | ||
|
||
/* | ||
* In a response, the command code will have the most significant bit flipped to 1. | ||
* If code is passed to ipts_mei_recv as is, no messages will be received. | ||
*/ | ||
ret = ipts_mei_recv(&ipts->mei, code | IPTS_RSP_BIT, rsp, timeout); | ||
if (ret < 0) | ||
return ret; | ||
|
||
dev_dbg(ipts->dev, "Received 0x%02X with status 0x%02X\n", code, rsp->status); | ||
|
||
/* | ||
* Some devices will always return this error. | ||
* It is allowed to ignore it and to try continuing. | ||
*/ | ||
if (rsp->status == IPTS_STATUS_COMPAT_CHECK_FAIL) | ||
rsp->status = IPTS_STATUS_SUCCESS; | ||
|
||
return 0; | ||
} | ||
|
||
int ipts_cmd_send(struct ipts_context *ipts, enum ipts_command_code code, void *data, size_t size) | ||
{ | ||
struct ipts_command cmd = { 0 }; | ||
|
||
if (!ipts) | ||
return -EFAULT; | ||
|
||
cmd.cmd = code; | ||
|
||
if (data && size > 0) | ||
memcpy(cmd.payload, data, size); | ||
|
||
dev_dbg(ipts->dev, "Sending 0x%02X with %ld bytes payload\n", code, size); | ||
return ipts_mei_send(&ipts->mei, &cmd, sizeof(cmd.cmd) + size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright (c) 2016 Intel Corporation | ||
* Copyright (c) 2020-2023 Dorian Stoll | ||
* | ||
* Linux driver for Intel Precise Touch & Stylus | ||
*/ | ||
|
||
#ifndef IPTS_CMD_H | ||
#define IPTS_CMD_H | ||
|
||
#include <linux/types.h> | ||
|
||
#include "context.h" | ||
#include "spec-device.h" | ||
|
||
/* | ||
* The default timeout for receiving responses | ||
*/ | ||
#define IPTS_CMD_DEFAULT_TIMEOUT 1000 | ||
|
||
/* | ||
* ipts_cmd_recv_timeout() - Receives a response to a command. | ||
* @ipts: The IPTS driver context. | ||
* @code: The type of the command / response. | ||
* @rsp: The address that the received response will be copied to. | ||
* @timeout: How many milliseconds the function will wait at most. | ||
* | ||
* A negative timeout means to wait forever. | ||
* | ||
* Returns: 0 on success, <0 on error, -EAGAIN if no response has been received. | ||
*/ | ||
int ipts_cmd_recv_timeout(struct ipts_context *ipts, enum ipts_command_code code, | ||
struct ipts_response *rsp, u64 timeout); | ||
|
||
/* | ||
* ipts_cmd_recv() - Receives a response to a command. | ||
* @ipts: The IPTS driver context. | ||
* @code: The type of the command / response. | ||
* @rsp: The address that the received response will be copied to. | ||
* | ||
* Returns: 0 on success, <0 on error, -EAGAIN if no response has been received. | ||
*/ | ||
static inline int ipts_cmd_recv(struct ipts_context *ipts, enum ipts_command_code code, | ||
struct ipts_response *rsp) | ||
{ | ||
return ipts_cmd_recv_timeout(ipts, code, rsp, IPTS_CMD_DEFAULT_TIMEOUT); | ||
} | ||
|
||
/* | ||
* ipts_cmd_send() - Executes a command on the device. | ||
* @ipts: The IPTS driver context. | ||
* @code: The type of the command to execute. | ||
* @data: The payload containing parameters for the command. | ||
* @size: The size of the payload. | ||
* | ||
* Returns: 0 on success, <0 on error. | ||
*/ | ||
int ipts_cmd_send(struct ipts_context *ipts, enum ipts_command_code code, void *data, size_t size); | ||
|
||
#endif /* IPTS_CMD_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright (c) 2016 Intel Corporation | ||
* Copyright (c) 2020-2023 Dorian Stoll | ||
* | ||
* Linux driver for Intel Precise Touch & Stylus | ||
*/ | ||
|
||
#ifndef IPTS_CONTEXT_H | ||
#define IPTS_CONTEXT_H | ||
|
||
#include <linux/completion.h> | ||
#include <linux/device.h> | ||
#include <linux/hid.h> | ||
#include <linux/mei_cl_bus.h> | ||
#include <linux/mutex.h> | ||
#include <linux/sched.h> | ||
#include <linux/types.h> | ||
|
||
#include "mei.h" | ||
#include "resources.h" | ||
#include "spec-device.h" | ||
#include "thread.h" | ||
|
||
struct ipts_context { | ||
struct device *dev; | ||
struct ipts_mei mei; | ||
|
||
enum ipts_mode mode; | ||
|
||
/* | ||
* Prevents concurrent GET_FEATURE reports. | ||
*/ | ||
struct mutex feature_lock; | ||
struct completion feature_event; | ||
|
||
/* | ||
* These are not inside of struct ipts_resources | ||
* because they don't own the memory they point to. | ||
*/ | ||
struct ipts_buffer feature_report; | ||
struct ipts_buffer descriptor; | ||
|
||
struct hid_device *hid; | ||
struct ipts_device_info info; | ||
struct ipts_resources resources; | ||
|
||
struct ipts_thread receiver_loop; | ||
}; | ||
|
||
#endif /* IPTS_CONTEXT_H */ |
Oops, something went wrong.