2019-05-26 23:55:06 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-11-02 18:45:51 -07:00
|
|
|
/*
|
|
|
|
* TSC2004/TSC2005 touchscreen driver core
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2010 Nokia Corporation
|
|
|
|
* Copyright (C) 2015 QWERTY Embedded Design
|
|
|
|
* Copyright (C) 2015 EMAC Inc.
|
|
|
|
*
|
|
|
|
* Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
|
|
|
|
* based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/input/touchscreen.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include "tsc200x-core.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The touchscreen interface operates as follows:
|
|
|
|
*
|
|
|
|
* 1) Pen is pressed against the touchscreen.
|
2015-11-02 18:51:49 -07:00
|
|
|
* 2) TSC200X performs AD conversion.
|
|
|
|
* 3) After the conversion is done TSC200X drives DAV line down.
|
|
|
|
* 4) GPIO IRQ is received and tsc200x_irq_thread() is scheduled.
|
|
|
|
* 5) tsc200x_irq_thread() queues up a transfer to fetch the x, y, z1, z2
|
2015-11-02 18:45:51 -07:00
|
|
|
* values.
|
2015-11-02 18:51:49 -07:00
|
|
|
* 6) tsc200x_irq_thread() reports coordinates to input layer and sets up
|
|
|
|
* tsc200x_penup_timer() to be called after TSC200X_PENUP_TIME_MS (40ms).
|
2015-11-02 18:45:51 -07:00
|
|
|
* 7) When the penup timer expires, there have not been touch or DAV interrupts
|
|
|
|
* during the last 40ms which means the pen has been lifted.
|
|
|
|
*
|
2015-11-02 18:51:49 -07:00
|
|
|
* ESD recovery via a hardware reset is done if the TSC200X doesn't respond
|
2015-11-02 18:45:51 -07:00
|
|
|
* after a configurable period (in ms) of activity. If esd_timeout is 0, the
|
|
|
|
* watchdog is disabled.
|
|
|
|
*/
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static const struct regmap_range tsc200x_writable_ranges[] = {
|
|
|
|
regmap_reg_range(TSC200X_REG_AUX_HIGH, TSC200X_REG_CFR2),
|
2015-11-02 18:45:51 -07:00
|
|
|
};
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static const struct regmap_access_table tsc200x_writable_table = {
|
|
|
|
.yes_ranges = tsc200x_writable_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(tsc200x_writable_ranges),
|
2015-11-02 18:45:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct regmap_config tsc200x_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 16,
|
|
|
|
.reg_stride = 0x08,
|
|
|
|
.max_register = 0x78,
|
2015-11-02 18:51:49 -07:00
|
|
|
.read_flag_mask = TSC200X_REG_READ,
|
|
|
|
.write_flag_mask = TSC200X_REG_PND0,
|
|
|
|
.wr_table = &tsc200x_writable_table,
|
2018-09-01 09:50:41 -07:00
|
|
|
.use_single_read = true,
|
|
|
|
.use_single_write = true,
|
2015-11-02 18:45:51 -07:00
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(tsc200x_regmap_config);
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x_data {
|
2015-11-02 18:45:51 -07:00
|
|
|
u16 x;
|
|
|
|
u16 y;
|
|
|
|
u16 z1;
|
|
|
|
u16 z2;
|
|
|
|
} __packed;
|
2015-11-02 18:51:49 -07:00
|
|
|
#define TSC200X_DATA_REGS 4
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x {
|
2015-11-02 18:45:51 -07:00
|
|
|
struct device *dev;
|
|
|
|
struct regmap *regmap;
|
|
|
|
__u16 bustype;
|
|
|
|
|
|
|
|
struct input_dev *idev;
|
|
|
|
char phys[32];
|
|
|
|
|
|
|
|
struct mutex mutex;
|
|
|
|
|
|
|
|
/* raw copy of previous x,y,z */
|
|
|
|
int in_x;
|
|
|
|
int in_y;
|
|
|
|
int in_z1;
|
|
|
|
int in_z2;
|
|
|
|
|
2022-02-09 17:59:12 -07:00
|
|
|
struct touchscreen_properties prop;
|
|
|
|
|
2015-11-02 18:45:51 -07:00
|
|
|
spinlock_t lock;
|
|
|
|
struct timer_list penup_timer;
|
|
|
|
|
|
|
|
unsigned int esd_timeout;
|
|
|
|
struct delayed_work esd_work;
|
|
|
|
unsigned long last_valid_interrupt;
|
|
|
|
|
|
|
|
unsigned int x_plate_ohm;
|
|
|
|
|
|
|
|
bool opened;
|
|
|
|
bool suspended;
|
|
|
|
|
|
|
|
bool pen_down;
|
|
|
|
|
|
|
|
struct gpio_desc *reset_gpio;
|
|
|
|
int (*tsc200x_cmd)(struct device *dev, u8 cmd);
|
2024-07-11 10:27:15 -07:00
|
|
|
|
2015-11-02 18:45:51 -07:00
|
|
|
int irq;
|
2024-07-11 10:27:15 -07:00
|
|
|
bool wake_irq_enabled;
|
2015-11-02 18:45:51 -07:00
|
|
|
};
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static void tsc200x_update_pen_state(struct tsc200x *ts,
|
2015-11-02 18:45:51 -07:00
|
|
|
int x, int y, int pressure)
|
|
|
|
{
|
|
|
|
if (pressure) {
|
2022-02-09 17:59:12 -07:00
|
|
|
touchscreen_report_pos(ts->idev, &ts->prop, x, y, false);
|
2015-11-02 18:45:51 -07:00
|
|
|
input_report_abs(ts->idev, ABS_PRESSURE, pressure);
|
|
|
|
if (!ts->pen_down) {
|
|
|
|
input_report_key(ts->idev, BTN_TOUCH, !!pressure);
|
|
|
|
ts->pen_down = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
input_report_abs(ts->idev, ABS_PRESSURE, 0);
|
|
|
|
if (ts->pen_down) {
|
|
|
|
input_report_key(ts->idev, BTN_TOUCH, 0);
|
|
|
|
ts->pen_down = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
input_sync(ts->idev);
|
|
|
|
dev_dbg(ts->dev, "point(%4d,%4d), pressure (%4d)\n", x, y,
|
|
|
|
pressure);
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static irqreturn_t tsc200x_irq_thread(int irq, void *_ts)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts = _ts;
|
2015-11-02 18:45:51 -07:00
|
|
|
unsigned int pressure;
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x_data tsdata;
|
2015-11-02 18:45:51 -07:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/* read the coordinates */
|
2015-11-02 18:51:49 -07:00
|
|
|
error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata,
|
|
|
|
TSC200X_DATA_REGS);
|
2015-11-02 18:45:51 -07:00
|
|
|
if (unlikely(error))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* validate position */
|
|
|
|
if (unlikely(tsdata.x > MAX_12BIT || tsdata.y > MAX_12BIT))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Skip reading if the pressure components are out of range */
|
|
|
|
if (unlikely(tsdata.z1 == 0 || tsdata.z2 > MAX_12BIT))
|
|
|
|
goto out;
|
|
|
|
if (unlikely(tsdata.z1 >= tsdata.z2))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip point if this is a pen down with the exact same values as
|
|
|
|
* the value before pen-up - that implies SPI fed us stale data
|
|
|
|
*/
|
|
|
|
if (!ts->pen_down &&
|
|
|
|
ts->in_x == tsdata.x && ts->in_y == tsdata.y &&
|
|
|
|
ts->in_z1 == tsdata.z1 && ts->in_z2 == tsdata.z2) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point we are happy we have a valid and useful reading.
|
|
|
|
* Remember it for later comparisons. We may now begin downsampling.
|
|
|
|
*/
|
|
|
|
ts->in_x = tsdata.x;
|
|
|
|
ts->in_y = tsdata.y;
|
|
|
|
ts->in_z1 = tsdata.z1;
|
|
|
|
ts->in_z2 = tsdata.z2;
|
|
|
|
|
|
|
|
/* Compute touch pressure resistance using equation #1 */
|
|
|
|
pressure = tsdata.x * (tsdata.z2 - tsdata.z1) / tsdata.z1;
|
|
|
|
pressure = pressure * ts->x_plate_ohm / 4096;
|
|
|
|
if (unlikely(pressure > MAX_12BIT))
|
|
|
|
goto out;
|
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
scoped_guard(spinlock_irqsave, &ts->lock) {
|
|
|
|
tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure);
|
|
|
|
mod_timer(&ts->penup_timer,
|
|
|
|
jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS));
|
|
|
|
}
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
ts->last_valid_interrupt = jiffies;
|
|
|
|
out:
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2017-10-24 09:44:48 -07:00
|
|
|
static void tsc200x_penup_timer(struct timer_list *t)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2017-10-24 09:44:48 -07:00
|
|
|
struct tsc200x *ts = from_timer(ts, t, penup_timer);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
guard(spinlock_irqsave)(&ts->lock);
|
2015-11-02 18:51:49 -07:00
|
|
|
tsc200x_update_pen_state(ts, 0, 0, 0);
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static void tsc200x_start_scan(struct tsc200x *ts)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
regmap_write(ts->regmap, TSC200X_REG_CFR0, TSC200X_CFR0_INITVALUE);
|
|
|
|
regmap_write(ts->regmap, TSC200X_REG_CFR1, TSC200X_CFR1_INITVALUE);
|
|
|
|
regmap_write(ts->regmap, TSC200X_REG_CFR2, TSC200X_CFR2_INITVALUE);
|
|
|
|
ts->tsc200x_cmd(ts->dev, TSC200X_CMD_NORMAL);
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static void tsc200x_stop_scan(struct tsc200x *ts)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP);
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2017-02-10 16:18:07 -07:00
|
|
|
static void tsc200x_reset(struct tsc200x *ts)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2017-02-10 16:18:07 -07:00
|
|
|
if (ts->reset_gpio) {
|
|
|
|
gpiod_set_value_cansleep(ts->reset_gpio, 1);
|
|
|
|
usleep_range(100, 500); /* only 10us required */
|
|
|
|
gpiod_set_value_cansleep(ts->reset_gpio, 0);
|
|
|
|
}
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with ts->mutex held */
|
2015-11-02 18:51:49 -07:00
|
|
|
static void __tsc200x_disable(struct tsc200x *ts)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
tsc200x_stop_scan(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
guard(disable_irq)(&ts->irq);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
del_timer_sync(&ts->penup_timer);
|
2015-11-02 18:45:51 -07:00
|
|
|
cancel_delayed_work_sync(&ts->esd_work);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with ts->mutex held */
|
2015-11-02 18:51:49 -07:00
|
|
|
static void __tsc200x_enable(struct tsc200x *ts)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
tsc200x_start_scan(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2017-02-10 16:18:07 -07:00
|
|
|
if (ts->esd_timeout && ts->reset_gpio) {
|
2015-11-02 18:45:51 -07:00
|
|
|
ts->last_valid_interrupt = jiffies;
|
|
|
|
schedule_delayed_work(&ts->esd_work,
|
|
|
|
round_jiffies_relative(
|
|
|
|
msecs_to_jiffies(ts->esd_timeout)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
/*
|
|
|
|
* Test TSC200X communications via temp high register.
|
|
|
|
*/
|
|
|
|
static int tsc200x_do_selftest(struct tsc200x *ts)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
|
|
|
unsigned int temp_high_orig;
|
|
|
|
unsigned int temp_high_test;
|
2024-07-11 10:27:17 -07:00
|
|
|
unsigned int temp_high;
|
2015-11-02 18:45:51 -07:00
|
|
|
int error;
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig);
|
2015-11-02 18:45:51 -07:00
|
|
|
if (error) {
|
2024-07-11 10:27:17 -07:00
|
|
|
dev_warn(ts->dev, "selftest failed: read error %d\n", error);
|
|
|
|
return error;
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
temp_high_test = (temp_high_orig - 1) & MAX_12BIT;
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test);
|
2015-11-02 18:45:51 -07:00
|
|
|
if (error) {
|
2024-07-11 10:27:17 -07:00
|
|
|
dev_warn(ts->dev, "selftest failed: write error %d\n", error);
|
|
|
|
return error;
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high);
|
2015-11-02 18:45:51 -07:00
|
|
|
if (error) {
|
2024-07-11 10:27:17 -07:00
|
|
|
dev_warn(ts->dev,
|
|
|
|
"selftest failed: read error %d after write\n", error);
|
|
|
|
return error;
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* hardware reset */
|
2017-02-10 16:18:07 -07:00
|
|
|
tsc200x_reset(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
if (temp_high != temp_high_test) {
|
|
|
|
dev_warn(ts->dev, "selftest failed: %d != %d\n",
|
|
|
|
temp_high, temp_high_test);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
/* test that the reset really happened */
|
2015-11-02 18:51:49 -07:00
|
|
|
error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high);
|
2015-11-02 18:45:51 -07:00
|
|
|
if (error) {
|
2024-07-11 10:27:17 -07:00
|
|
|
dev_warn(ts->dev,
|
|
|
|
"selftest failed: read error %d after reset\n", error);
|
|
|
|
return error;
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (temp_high != temp_high_orig) {
|
2024-07-11 10:27:17 -07:00
|
|
|
dev_warn(ts->dev, "selftest failed after reset: %d != %d\n",
|
2015-11-02 18:45:51 -07:00
|
|
|
temp_high, temp_high_orig);
|
2024-07-11 10:27:17 -07:00
|
|
|
return -EINVAL;
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
static ssize_t tsc200x_selftest_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct tsc200x *ts = dev_get_drvdata(dev);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
scoped_guard(mutex, &ts->mutex) {
|
|
|
|
__tsc200x_disable(ts);
|
|
|
|
|
|
|
|
error = tsc200x_do_selftest(ts);
|
|
|
|
|
|
|
|
__tsc200x_enable(ts);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", !error);
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static DEVICE_ATTR(selftest, S_IRUGO, tsc200x_selftest_show, NULL);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static struct attribute *tsc200x_attrs[] = {
|
2015-11-02 18:45:51 -07:00
|
|
|
&dev_attr_selftest.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static umode_t tsc200x_attr_is_visible(struct kobject *kobj,
|
2015-11-02 18:45:51 -07:00
|
|
|
struct attribute *attr, int n)
|
|
|
|
{
|
2021-06-19 22:12:43 -07:00
|
|
|
struct device *dev = kobj_to_dev(kobj);
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts = dev_get_drvdata(dev);
|
2015-11-02 18:45:51 -07:00
|
|
|
umode_t mode = attr->mode;
|
|
|
|
|
|
|
|
if (attr == &dev_attr_selftest.attr) {
|
2017-02-10 16:18:07 -07:00
|
|
|
if (!ts->reset_gpio)
|
2015-11-02 18:45:51 -07:00
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static const struct attribute_group tsc200x_attr_group = {
|
|
|
|
.is_visible = tsc200x_attr_is_visible,
|
|
|
|
.attrs = tsc200x_attrs,
|
2015-11-02 18:45:51 -07:00
|
|
|
};
|
|
|
|
|
2023-07-28 17:51:30 -07:00
|
|
|
const struct attribute_group *tsc200x_groups[] = {
|
|
|
|
&tsc200x_attr_group,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(tsc200x_groups);
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static void tsc200x_esd_work(struct work_struct *work)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work);
|
2015-11-02 18:45:51 -07:00
|
|
|
int error;
|
|
|
|
unsigned int r;
|
|
|
|
|
|
|
|
/*
|
2024-07-11 10:27:17 -07:00
|
|
|
* If the mutex is taken, it means that disable or enable is in
|
|
|
|
* progress. In that case just reschedule the work. If the work
|
|
|
|
* is not needed, it will be canceled by disable.
|
2015-11-02 18:45:51 -07:00
|
|
|
*/
|
2024-07-11 10:27:17 -07:00
|
|
|
scoped_guard(mutex_try, &ts->mutex) {
|
|
|
|
if (time_is_after_jiffies(ts->last_valid_interrupt +
|
|
|
|
msecs_to_jiffies(ts->esd_timeout)))
|
|
|
|
break;
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
/*
|
|
|
|
* We should be able to read register without disabling
|
|
|
|
* interrupts.
|
|
|
|
*/
|
|
|
|
error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r);
|
|
|
|
if (!error &&
|
|
|
|
!((r ^ TSC200X_CFR0_INITVALUE) & TSC200X_CFR0_RW_MASK)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
/*
|
|
|
|
* If we could not read our known value from configuration
|
|
|
|
* register 0 then we should reset the controller as if from
|
|
|
|
* power-up and start scanning again.
|
|
|
|
*/
|
|
|
|
dev_info(ts->dev, "TSC200X not responding - resetting\n");
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
scoped_guard(disable_irq, &ts->irq) {
|
|
|
|
del_timer_sync(&ts->penup_timer);
|
|
|
|
tsc200x_update_pen_state(ts, 0, 0, 0);
|
|
|
|
tsc200x_reset(ts);
|
|
|
|
}
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
tsc200x_start_scan(ts);
|
|
|
|
}
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
/* re-arm the watchdog */
|
|
|
|
schedule_delayed_work(&ts->esd_work,
|
|
|
|
round_jiffies_relative(
|
|
|
|
msecs_to_jiffies(ts->esd_timeout)));
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static int tsc200x_open(struct input_dev *input)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts = input_get_drvdata(input);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
guard(mutex)(&ts->mutex);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
if (!ts->suspended)
|
2015-11-02 18:51:49 -07:00
|
|
|
__tsc200x_enable(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
ts->opened = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
static void tsc200x_close(struct input_dev *input)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts = input_get_drvdata(input);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
guard(mutex)(&ts->mutex);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
if (!ts->suspended)
|
2015-11-02 18:51:49 -07:00
|
|
|
__tsc200x_disable(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
ts->opened = false;
|
|
|
|
}
|
|
|
|
|
2016-07-20 10:02:07 -07:00
|
|
|
int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
|
2015-11-02 18:45:51 -07:00
|
|
|
struct regmap *regmap,
|
|
|
|
int (*tsc200x_cmd)(struct device *dev, u8 cmd))
|
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts;
|
2015-11-02 18:45:51 -07:00
|
|
|
struct input_dev *input_dev;
|
2017-02-10 16:18:07 -07:00
|
|
|
u32 x_plate_ohm;
|
|
|
|
u32 esd_timeout;
|
2015-11-02 18:45:51 -07:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (irq <= 0) {
|
|
|
|
dev_err(dev, "no irq\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
|
|
|
|
|
|
|
if (!tsc200x_cmd) {
|
|
|
|
dev_err(dev, "no cmd function\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
|
|
|
|
if (!ts)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
input_dev = devm_input_allocate_device(dev);
|
|
|
|
if (!input_dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ts->irq = irq;
|
|
|
|
ts->dev = dev;
|
|
|
|
ts->idev = input_dev;
|
|
|
|
ts->regmap = regmap;
|
|
|
|
ts->tsc200x_cmd = tsc200x_cmd;
|
2017-02-10 16:18:07 -07:00
|
|
|
|
|
|
|
error = device_property_read_u32(dev, "ti,x-plate-ohms", &x_plate_ohm);
|
|
|
|
ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm;
|
|
|
|
|
|
|
|
error = device_property_read_u32(dev, "ti,esd-recovery-timeout-ms",
|
|
|
|
&esd_timeout);
|
|
|
|
ts->esd_timeout = error ? 0 : esd_timeout;
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
mutex_init(&ts->mutex);
|
|
|
|
|
|
|
|
spin_lock_init(&ts->lock);
|
2017-10-24 09:44:48 -07:00
|
|
|
timer_setup(&ts->penup_timer, tsc200x_penup_timer, 0);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
snprintf(ts->phys, sizeof(ts->phys),
|
|
|
|
"%s/input-ts", dev_name(dev));
|
|
|
|
|
2016-07-20 10:02:07 -07:00
|
|
|
if (tsc_id->product == 2004) {
|
|
|
|
input_dev->name = "TSC200X touchscreen";
|
|
|
|
} else {
|
|
|
|
input_dev->name = devm_kasprintf(dev, GFP_KERNEL,
|
|
|
|
"TSC%04d touchscreen",
|
|
|
|
tsc_id->product);
|
|
|
|
if (!input_dev->name)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:45:51 -07:00
|
|
|
input_dev->phys = ts->phys;
|
2016-07-20 10:02:07 -07:00
|
|
|
input_dev->id = *tsc_id;
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2015-11-02 18:51:49 -07:00
|
|
|
input_dev->open = tsc200x_open;
|
|
|
|
input_dev->close = tsc200x_close;
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
input_set_drvdata(input_dev, ts);
|
|
|
|
|
2017-11-07 17:20:49 -07:00
|
|
|
__set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
|
2017-02-10 16:18:07 -07:00
|
|
|
input_set_capability(input_dev, EV_KEY, BTN_TOUCH);
|
|
|
|
|
|
|
|
input_set_abs_params(input_dev, ABS_X,
|
|
|
|
0, MAX_12BIT, TSC200X_DEF_X_FUZZ, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_Y,
|
|
|
|
0, MAX_12BIT, TSC200X_DEF_Y_FUZZ, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_PRESSURE,
|
|
|
|
0, MAX_12BIT, TSC200X_DEF_P_FUZZ, 0);
|
|
|
|
|
2022-02-09 17:59:12 -07:00
|
|
|
touchscreen_parse_properties(input_dev, false, &ts->prop);
|
2017-02-10 16:18:07 -07:00
|
|
|
|
2024-07-11 10:27:14 -07:00
|
|
|
ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
|
|
|
|
error = PTR_ERR_OR_ZERO(ts->reset_gpio);
|
|
|
|
if (error) {
|
|
|
|
dev_err(dev, "error acquiring reset gpio: %d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = devm_regulator_get_enable(dev, "vio");
|
|
|
|
if (error) {
|
|
|
|
dev_err(dev, "error acquiring vio regulator: %d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsc200x_reset(ts);
|
|
|
|
|
2015-11-02 18:45:51 -07:00
|
|
|
/* Ensure the touchscreen is off */
|
2015-11-02 18:51:49 -07:00
|
|
|
tsc200x_stop_scan(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:13 -07:00
|
|
|
error = devm_request_threaded_irq(dev, irq, NULL, tsc200x_irq_thread,
|
|
|
|
IRQF_ONESHOT, "tsc200x", ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
if (error) {
|
|
|
|
dev_err(dev, "Failed to request irq, err: %d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, ts);
|
|
|
|
|
|
|
|
error = input_register_device(ts->idev);
|
|
|
|
if (error) {
|
|
|
|
dev_err(dev,
|
|
|
|
"Failed to register input device, err: %d\n", error);
|
2024-07-11 10:27:12 -07:00
|
|
|
return error;
|
2015-11-02 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2024-07-11 10:27:16 -07:00
|
|
|
device_init_wakeup(dev,
|
|
|
|
device_property_read_bool(dev, "wakeup-source"));
|
2024-07-11 10:27:15 -07:00
|
|
|
|
2015-11-02 18:45:51 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tsc200x_probe);
|
|
|
|
|
2023-01-14 10:16:13 -07:00
|
|
|
static int tsc200x_suspend(struct device *dev)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts = dev_get_drvdata(dev);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
guard(mutex)(&ts->mutex);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
if (!ts->suspended && ts->opened)
|
2015-11-02 18:51:49 -07:00
|
|
|
__tsc200x_disable(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
ts->suspended = true;
|
|
|
|
|
2024-07-11 10:27:15 -07:00
|
|
|
if (device_may_wakeup(dev))
|
|
|
|
ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0;
|
|
|
|
|
2015-11-02 18:45:51 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-14 10:16:13 -07:00
|
|
|
static int tsc200x_resume(struct device *dev)
|
2015-11-02 18:45:51 -07:00
|
|
|
{
|
2015-11-02 18:51:49 -07:00
|
|
|
struct tsc200x *ts = dev_get_drvdata(dev);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:17 -07:00
|
|
|
guard(mutex)(&ts->mutex);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
2024-07-11 10:27:15 -07:00
|
|
|
if (ts->wake_irq_enabled) {
|
|
|
|
disable_irq_wake(ts->irq);
|
|
|
|
ts->wake_irq_enabled = false;
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:45:51 -07:00
|
|
|
if (ts->suspended && ts->opened)
|
2015-11-02 18:51:49 -07:00
|
|
|
__tsc200x_enable(ts);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
ts->suspended = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-14 10:16:13 -07:00
|
|
|
EXPORT_GPL_SIMPLE_DEV_PM_OPS(tsc200x_pm_ops, tsc200x_suspend, tsc200x_resume);
|
2015-11-02 18:45:51 -07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>");
|
2015-11-02 18:51:49 -07:00
|
|
|
MODULE_DESCRIPTION("TSC200x Touchscreen Driver Core");
|
2015-11-02 18:45:51 -07:00
|
|
|
MODULE_LICENSE("GPL");
|