Commit 427ee206 authored by Stephen Just's avatar Stephen Just Committed by Dmitry Torokhov

Input: surface3_spi - Prepare to add support for Surface Pen

Surface Pens can be supported by handling a second report type. Prepare
for this change.
Signed-off-by: default avatarStephen Just <stephenjust@gmail.com>
Reviewed-and-tested-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent c95d6d96
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#define SURFACE3_PACKET_SIZE 264 #define SURFACE3_PACKET_SIZE 264
#define SURFACE3_REPORT_TOUCH 0xd2
struct surface3_ts_data { struct surface3_ts_data {
struct spi_device *spi; struct spi_device *spi;
struct gpio_desc *gpiod_rst[2]; struct gpio_desc *gpiod_rst[2];
...@@ -83,19 +85,10 @@ static void surface3_spi_report_touch(struct surface3_ts_data *ts_data, ...@@ -83,19 +85,10 @@ static void surface3_spi_report_touch(struct surface3_ts_data *ts_data,
} }
} }
static void surface3_spi_process(struct surface3_ts_data *ts_data) static void surface3_spi_process_touch(struct surface3_ts_data *ts_data, u8 *data)
{ {
const char header[] = {0xff, 0xff, 0xff, 0xff, 0xa5, 0x5a, 0xe7, 0x7e,
0x01, 0xd2, 0x00, 0x80, 0x01, 0x03, 0x03};
u8 *data = ts_data->rd_buf;
u16 timestamp; u16 timestamp;
unsigned int i; unsigned int i;
if (memcmp(header, data, sizeof(header)))
dev_err(&ts_data->spi->dev,
"%s header error: %*ph, ignoring...\n",
__func__, (int)sizeof(header), data);
timestamp = get_unaligned_le16(&data[15]); timestamp = get_unaligned_le16(&data[15]);
for (i = 0; i < 13; i++) { for (i = 0; i < 13; i++) {
...@@ -120,6 +113,26 @@ static void surface3_spi_process(struct surface3_ts_data *ts_data) ...@@ -120,6 +113,26 @@ static void surface3_spi_process(struct surface3_ts_data *ts_data)
input_sync(ts_data->input_dev); input_sync(ts_data->input_dev);
} }
static void surface3_spi_process(struct surface3_ts_data *ts_data)
{
const char header[] = {
0xff, 0xff, 0xff, 0xff, 0xa5, 0x5a, 0xe7, 0x7e, 0x01
};
u8 *data = ts_data->rd_buf;
if (memcmp(header, data, sizeof(header)))
dev_err(&ts_data->spi->dev,
"%s header error: %*ph, ignoring...\n",
__func__, (int)sizeof(header), data);
if (data[9] == SURFACE3_REPORT_TOUCH)
surface3_spi_process_touch(ts_data, data);
else
dev_err(&ts_data->spi->dev,
"%s unknown packet type: %x, ignoring...\n",
__func__, data[9]);
}
static irqreturn_t surface3_spi_irq_handler(int irq, void *dev_id) static irqreturn_t surface3_spi_irq_handler(int irq, void *dev_id)
{ {
struct surface3_ts_data *data = dev_id; struct surface3_ts_data *data = dev_id;
...@@ -175,7 +188,7 @@ static int surface3_spi_get_gpio_config(struct surface3_ts_data *data) ...@@ -175,7 +188,7 @@ static int surface3_spi_get_gpio_config(struct surface3_ts_data *data)
return 0; return 0;
} }
static int surface3_spi_create_input(struct surface3_ts_data *data) static int surface3_spi_create_touch_input(struct surface3_ts_data *data)
{ {
struct input_dev *input; struct input_dev *input;
int error; int error;
...@@ -198,7 +211,7 @@ static int surface3_spi_create_input(struct surface3_ts_data *data) ...@@ -198,7 +211,7 @@ static int surface3_spi_create_input(struct surface3_ts_data *data)
input->phys = "input/ts"; input->phys = "input/ts";
input->id.bustype = BUS_SPI; input->id.bustype = BUS_SPI;
input->id.vendor = 0x045e; /* Microsoft */ input->id.vendor = 0x045e; /* Microsoft */
input->id.product = 0x0000; input->id.product = 0x0001;
input->id.version = 0x0000; input->id.version = 0x0000;
error = input_register_device(input); error = input_register_device(input);
...@@ -238,7 +251,7 @@ static int surface3_spi_probe(struct spi_device *spi) ...@@ -238,7 +251,7 @@ static int surface3_spi_probe(struct spi_device *spi)
surface3_spi_power(data, false); surface3_spi_power(data, false);
surface3_spi_power(data, true); surface3_spi_power(data, true);
error = surface3_spi_create_input(data); error = surface3_spi_create_touch_input(data);
if (error) if (error)
return error; return error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment