Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HID based IPTS and ITHC support, 6.1 edition #133

Merged
merged 4 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions drivers/hid/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1290,4 +1290,8 @@ source "drivers/hid/amd-sfh-hid/Kconfig"

source "drivers/hid/surface-hid/Kconfig"

source "drivers/hid/ipts/Kconfig"

source "drivers/hid/ithc/Kconfig"

endmenu
3 changes: 3 additions & 0 deletions drivers/hid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ obj-$(INTEL_ISH_FIRMWARE_DOWNLOADER) += intel-ish-hid/
obj-$(CONFIG_AMD_SFH_HID) += amd-sfh-hid/

obj-$(CONFIG_SURFACE_HID_CORE) += surface-hid/

obj-$(CONFIG_HID_IPTS) += ipts/
obj-$(CONFIG_HID_ITHC) += ithc/
7 changes: 2 additions & 5 deletions drivers/misc/ipts/Kconfig → drivers/hid/ipts/Kconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-or-later

config MISC_IPTS
config HID_IPTS
tristate "Intel Precise Touch & Stylus"
depends on INTEL_MEI
depends on HID
help
Say Y here if your system has a touchscreen using Intels
Precise Touch & Stylus (IPTS) technology.
Expand All @@ -11,7 +12,3 @@ config MISC_IPTS

To compile this driver as a module, choose M here: the
module will be called ipts.

Building this driver alone will not give you a working touchscreen.
It only exposed a userspace API that can be used by a daemon to
receive and process data from the touchscreen hardware.
10 changes: 6 additions & 4 deletions drivers/misc/ipts/Makefile → drivers/hid/ipts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# Makefile for the IPTS touchscreen driver
#

obj-$(CONFIG_MISC_IPTS) += ipts.o
ipts-objs := control.o
obj-$(CONFIG_HID_IPTS) += ipts.o
ipts-objs := cmd.o
ipts-objs += control.o
ipts-objs += hid.o
ipts-objs += main.o
ipts-objs += mei.o
ipts-objs += receiver.o
ipts-objs += resources.o
ipts-objs += uapi.o

ipts-objs += thread.o
62 changes: 62 additions & 0 deletions drivers/hid/ipts/cmd.c
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);
}
61 changes: 61 additions & 0 deletions drivers/hid/ipts/cmd.h
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 */
51 changes: 51 additions & 0 deletions drivers/hid/ipts/context.h
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 */
Loading