2018-07-17 12:06:00 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-11-12 16:03:18 +08:00
|
|
|
/*
|
|
|
|
* Driver for EETI eGalax Multiple Touch Controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Freescale Semiconductor, Inc.
|
|
|
|
*
|
|
|
|
* based on max11801_ts.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* EETI eGalax serial touch screen controller is a I2C based multiple
|
|
|
|
* touch screen controller, it supports 5 point multiple touch. */
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
- auto idle mode support
|
|
|
|
*/
|
|
|
|
|
2022-09-20 12:26:07 +08:00
|
|
|
#include <linux/err.h>
|
2011-11-12 16:03:18 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/irq.h>
|
2022-09-20 12:26:07 +08:00
|
|
|
#include <linux/gpio/consumer.h>
|
2011-11-12 16:03:18 +08:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/input/mt.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mouse Mode: some panel may configure the controller to mouse mode,
|
|
|
|
* which can only report one point at a given time.
|
|
|
|
* This driver will ignore events in this mode.
|
|
|
|
*/
|
|
|
|
#define REPORT_MODE_MOUSE 0x1
|
|
|
|
/*
|
|
|
|
* Vendor Mode: this mode is used to transfer some vendor specific
|
|
|
|
* messages.
|
|
|
|
* This driver will ignore events in this mode.
|
|
|
|
*/
|
|
|
|
#define REPORT_MODE_VENDOR 0x3
|
|
|
|
/* Multiple Touch Mode */
|
|
|
|
#define REPORT_MODE_MTTOUCH 0x4
|
|
|
|
|
|
|
|
#define MAX_SUPPORT_POINTS 5
|
|
|
|
|
|
|
|
#define EVENT_VALID_OFFSET 7
|
|
|
|
#define EVENT_VALID_MASK (0x1 << EVENT_VALID_OFFSET)
|
|
|
|
#define EVENT_ID_OFFSET 2
|
|
|
|
#define EVENT_ID_MASK (0xf << EVENT_ID_OFFSET)
|
|
|
|
#define EVENT_IN_RANGE (0x1 << 1)
|
|
|
|
#define EVENT_DOWN_UP (0X1 << 0)
|
|
|
|
|
|
|
|
#define MAX_I2C_DATA_LEN 10
|
|
|
|
|
|
|
|
#define EGALAX_MAX_X 32760
|
|
|
|
#define EGALAX_MAX_Y 32760
|
|
|
|
#define EGALAX_MAX_TRIES 100
|
|
|
|
|
|
|
|
struct egalax_ts {
|
|
|
|
struct i2c_client *client;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct egalax_ts *ts = dev_id;
|
|
|
|
struct input_dev *input_dev = ts->input_dev;
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
u8 buf[MAX_I2C_DATA_LEN];
|
|
|
|
int id, ret, x, y, z;
|
|
|
|
int tries = 0;
|
|
|
|
bool down, valid;
|
|
|
|
u8 state;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = i2c_master_recv(client, buf, MAX_I2C_DATA_LEN);
|
|
|
|
} while (ret == -EAGAIN && tries++ < EGALAX_MAX_TRIES);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
|
|
if (buf[0] != REPORT_MODE_MTTOUCH) {
|
|
|
|
/* ignore mouse events and vendor events */
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = buf[1];
|
|
|
|
x = (buf[3] << 8) | buf[2];
|
|
|
|
y = (buf[5] << 8) | buf[4];
|
|
|
|
z = (buf[7] << 8) | buf[6];
|
|
|
|
|
|
|
|
valid = state & EVENT_VALID_MASK;
|
|
|
|
id = (state & EVENT_ID_MASK) >> EVENT_ID_OFFSET;
|
|
|
|
down = state & EVENT_DOWN_UP;
|
|
|
|
|
|
|
|
if (!valid || id > MAX_SUPPORT_POINTS) {
|
|
|
|
dev_dbg(&client->dev, "point invalid\n");
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_mt_slot(input_dev, id);
|
|
|
|
input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, down);
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "%s id:%d x:%d y:%d z:%d",
|
|
|
|
down ? "down" : "up", id, x, y, z);
|
|
|
|
|
|
|
|
if (down) {
|
|
|
|
input_report_abs(input_dev, ABS_MT_POSITION_X, x);
|
|
|
|
input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
|
|
|
|
input_report_abs(input_dev, ABS_MT_PRESSURE, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
input_mt_report_pointer_emulation(input_dev, true);
|
|
|
|
input_sync(input_dev);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wake up controller by an falling edge of interrupt gpio. */
|
|
|
|
static int egalax_wake_up_device(struct i2c_client *client)
|
|
|
|
{
|
2022-09-20 12:26:07 +08:00
|
|
|
struct gpio_desc *gpio;
|
2011-11-12 16:03:18 +08:00
|
|
|
int ret;
|
|
|
|
|
2022-09-20 12:26:07 +08:00
|
|
|
/* wake up controller via an falling edge on IRQ gpio. */
|
|
|
|
gpio = gpiod_get(&client->dev, "wakeup", GPIOD_OUT_HIGH);
|
|
|
|
ret = PTR_ERR_OR_ZERO(gpio);
|
|
|
|
if (ret) {
|
|
|
|
if (ret != -EPROBE_DEFER)
|
|
|
|
dev_err(&client->dev,
|
|
|
|
"failed to request wakeup gpio, cannot wake up controller: %d\n",
|
|
|
|
ret);
|
2011-11-12 16:03:18 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-09-20 12:26:07 +08:00
|
|
|
/* release the line */
|
|
|
|
gpiod_set_value_cansleep(gpio, 0);
|
2011-11-12 16:03:18 +08:00
|
|
|
|
2022-09-20 12:26:07 +08:00
|
|
|
/* controller should be woken up, return irq. */
|
|
|
|
gpiod_direction_input(gpio);
|
|
|
|
gpiod_put(gpio);
|
2011-11-12 16:03:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-24 13:38:25 +08:00
|
|
|
static int egalax_firmware_version(struct i2c_client *client)
|
2011-11-12 16:03:18 +08:00
|
|
|
{
|
|
|
|
static const u8 cmd[MAX_I2C_DATA_LEN] = { 0x03, 0x03, 0xa, 0x01, 0x41 };
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_master_send(client, cmd, MAX_I2C_DATA_LEN);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:39:33 +08:00
|
|
|
static int egalax_ts_probe(struct i2c_client *client)
|
2011-11-12 16:03:18 +08:00
|
|
|
{
|
|
|
|
struct egalax_ts *ts;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
int error;
|
|
|
|
|
2013-04-25 00:53:25 +08:00
|
|
|
ts = devm_kzalloc(&client->dev, sizeof(struct egalax_ts), GFP_KERNEL);
|
2011-11-12 16:03:18 +08:00
|
|
|
if (!ts) {
|
|
|
|
dev_err(&client->dev, "Failed to allocate memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:53:25 +08:00
|
|
|
input_dev = devm_input_allocate_device(&client->dev);
|
2011-11-12 16:03:18 +08:00
|
|
|
if (!input_dev) {
|
|
|
|
dev_err(&client->dev, "Failed to allocate memory\n");
|
2013-04-25 00:53:25 +08:00
|
|
|
return -ENOMEM;
|
2011-11-12 16:03:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ts->client = client;
|
|
|
|
ts->input_dev = input_dev;
|
|
|
|
|
|
|
|
/* controller may be in sleep, wake it up. */
|
2012-10-25 15:38:01 +08:00
|
|
|
error = egalax_wake_up_device(client);
|
2022-09-20 12:26:07 +08:00
|
|
|
if (error)
|
2013-04-25 00:53:25 +08:00
|
|
|
return error;
|
2011-11-12 16:03:18 +08:00
|
|
|
|
2013-04-25 00:53:25 +08:00
|
|
|
error = egalax_firmware_version(client);
|
|
|
|
if (error < 0) {
|
2011-11-12 16:03:18 +08:00
|
|
|
dev_err(&client->dev, "Failed to read firmware version\n");
|
2013-04-25 00:53:25 +08:00
|
|
|
return error;
|
2011-11-12 16:03:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
input_dev->name = "EETI eGalax Touch Screen";
|
|
|
|
input_dev->id.bustype = BUS_I2C;
|
|
|
|
|
|
|
|
__set_bit(EV_ABS, input_dev->evbit);
|
|
|
|
__set_bit(EV_KEY, input_dev->evbit);
|
|
|
|
__set_bit(BTN_TOUCH, input_dev->keybit);
|
|
|
|
|
|
|
|
input_set_abs_params(input_dev, ABS_X, 0, EGALAX_MAX_X, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_Y, 0, EGALAX_MAX_Y, 0, 0);
|
|
|
|
input_set_abs_params(input_dev,
|
|
|
|
ABS_MT_POSITION_X, 0, EGALAX_MAX_X, 0, 0);
|
|
|
|
input_set_abs_params(input_dev,
|
2013-05-06 10:49:49 +08:00
|
|
|
ABS_MT_POSITION_Y, 0, EGALAX_MAX_Y, 0, 0);
|
2012-08-12 04:07:55 +08:00
|
|
|
input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS, 0);
|
2011-11-12 16:03:18 +08:00
|
|
|
|
2022-09-20 12:26:08 +08:00
|
|
|
error = devm_request_threaded_irq(&client->dev, client->irq,
|
|
|
|
NULL, egalax_ts_interrupt,
|
|
|
|
IRQF_ONESHOT, "egalax_ts", ts);
|
2011-11-12 16:03:18 +08:00
|
|
|
if (error < 0) {
|
|
|
|
dev_err(&client->dev, "Failed to register interrupt\n");
|
2013-04-25 00:53:25 +08:00
|
|
|
return error;
|
2011-11-12 16:03:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
error = input_register_device(ts->input_dev);
|
|
|
|
if (error)
|
2013-04-25 00:53:25 +08:00
|
|
|
return error;
|
2011-11-12 16:03:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id egalax_ts_id[] = {
|
|
|
|
{ "egalax_ts", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, egalax_ts_id);
|
|
|
|
|
2023-01-03 02:18:16 +08:00
|
|
|
static int egalax_ts_suspend(struct device *dev)
|
2011-11-12 16:03:18 +08:00
|
|
|
{
|
|
|
|
static const u8 suspend_cmd[MAX_I2C_DATA_LEN] = {
|
|
|
|
0x3, 0x6, 0xa, 0x3, 0x36, 0x3f, 0x2, 0, 0, 0
|
|
|
|
};
|
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
int ret;
|
|
|
|
|
2018-09-18 02:08:52 +08:00
|
|
|
if (device_may_wakeup(dev))
|
|
|
|
return enable_irq_wake(client->irq);
|
|
|
|
|
2011-11-12 16:03:18 +08:00
|
|
|
ret = i2c_master_send(client, suspend_cmd, MAX_I2C_DATA_LEN);
|
|
|
|
return ret > 0 ? 0 : ret;
|
|
|
|
}
|
|
|
|
|
2023-01-03 02:18:16 +08:00
|
|
|
static int egalax_ts_resume(struct device *dev)
|
2011-11-12 16:03:18 +08:00
|
|
|
{
|
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
|
2018-09-18 02:08:52 +08:00
|
|
|
if (device_may_wakeup(dev))
|
|
|
|
return disable_irq_wake(client->irq);
|
|
|
|
|
2011-11-12 16:03:18 +08:00
|
|
|
return egalax_wake_up_device(client);
|
|
|
|
}
|
|
|
|
|
2023-01-03 02:18:16 +08:00
|
|
|
static DEFINE_SIMPLE_DEV_PM_OPS(egalax_ts_pm_ops,
|
|
|
|
egalax_ts_suspend, egalax_ts_resume);
|
2011-11-12 16:03:18 +08:00
|
|
|
|
2014-05-08 04:08:53 +08:00
|
|
|
static const struct of_device_id egalax_ts_dt_ids[] = {
|
2012-10-25 15:38:01 +08:00
|
|
|
{ .compatible = "eeti,egalax_ts" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
2015-07-31 01:39:28 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, egalax_ts_dt_ids);
|
2012-10-25 15:38:01 +08:00
|
|
|
|
2011-11-12 16:03:18 +08:00
|
|
|
static struct i2c_driver egalax_ts_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "egalax_ts",
|
2023-01-03 02:18:16 +08:00
|
|
|
.pm = pm_sleep_ptr(&egalax_ts_pm_ops),
|
2013-10-06 15:52:12 +08:00
|
|
|
.of_match_table = egalax_ts_dt_ids,
|
2011-11-12 16:03:18 +08:00
|
|
|
},
|
|
|
|
.id_table = egalax_ts_id,
|
2023-05-18 00:55:42 +08:00
|
|
|
.probe = egalax_ts_probe,
|
2011-11-12 16:03:18 +08:00
|
|
|
};
|
|
|
|
|
2012-03-17 14:05:41 +08:00
|
|
|
module_i2c_driver(egalax_ts_driver);
|
2011-11-12 16:03:18 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
|
|
|
|
MODULE_DESCRIPTION("Touchscreen driver for EETI eGalax touch controller");
|
|
|
|
MODULE_LICENSE("GPL");
|