Commit a30b7ca2 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

Pull more input updates from Dmitry Torokhov:
 "An update to the tsc2005 driver that allows it to also support tsc2004
  (basically the same controller, but uses i2c instead of spi bus), and
  a couple of bug fixes"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input:
  Input: parkbd - drop bogus __init from parkbd_allocate_serio()
  Input: elantech - add Fujitsu Lifebook U745 to force crc_enabled
  Input: tsc2004 - add support for tsc2004
  Input: tsc200x-core - rename functions and variables
  Input: tsc2005 - separate SPI and core functions
parents d83763f4 bbdb5c22
* Texas Instruments tsc2005 touchscreen controller
* Texas Instruments tsc2004 and tsc2005 touchscreen controllers
Required properties:
- compatible : "ti,tsc2005"
- reg : SPI device address
- spi-max-frequency : Maximal SPI speed
- compatible : "ti,tsc2004" or "ti,tsc2005"
- reg : Device address
- interrupts : IRQ specifier
- reset-gpios : GPIO specifier
- vio-supply : Regulator specifier
- spi-max-frequency : Maximum SPI clocking speed of the device
(for tsc2005)
Optional properties:
- vio-supply : Regulator specifier
- reset-gpios : GPIO specifier for the controller reset line
- ti,x-plate-ohms : integer, resistance of the touchscreen's X plates
in ohm (defaults to 280)
- ti,esd-recovery-timeout-ms : integer, if the touchscreen does not respond after
......@@ -18,6 +19,27 @@ Optional properties:
Example:
&i2c3 {
tsc2004@48 {
compatible = "ti,tsc2004";
reg = <0x48>;
vio-supply = <&vio>;
reset-gpios = <&gpio4 8 GPIO_ACTIVE_HIGH>;
interrupts-extended = <&gpio1 27 IRQ_TYPE_EDGE_RISING>;
touchscreen-fuzz-x = <4>;
touchscreen-fuzz-y = <7>;
touchscreen-fuzz-pressure = <2>;
touchscreen-size-x = <4096>;
touchscreen-size-y = <4096>;
touchscreen-max-pressure = <2048>;
ti,x-plate-ohms = <280>;
ti,esd-recovery-timeout-ms = <8000>;
};
}
&mcspi1 {
tsc2005@0 {
compatible = "ti,tsc2005";
......
......@@ -1520,6 +1520,13 @@ static const struct dmi_system_id elantech_dmi_force_crc_enabled[] = {
DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E544"),
},
},
{
/* Fujitsu LIFEBOOK U745 does not work with crc_enabled == 0 */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK U745"),
},
},
#endif
{ }
};
......
......@@ -164,7 +164,7 @@ static int parkbd_getport(struct parport *pp)
return 0;
}
static struct serio * __init parkbd_allocate_serio(void)
static struct serio *parkbd_allocate_serio(void)
{
struct serio *serio;
......
......@@ -939,10 +939,27 @@ config TOUCHSCREEN_TSC_SERIO
To compile this driver as a module, choose M here: the
module will be called tsc40.
config TOUCHSCREEN_TSC200X_CORE
tristate
config TOUCHSCREEN_TSC2004
tristate "TSC2004 based touchscreens"
depends on I2C
select REGMAP_I2C
select TOUCHSCREEN_TSC200X_CORE
help
Say Y here if you have a TSC2004 based touchscreen.
If unsure, say N.
To compile this driver as a module, choose M here: the
module will be called tsc2004.
config TOUCHSCREEN_TSC2005
tristate "TSC2005 based touchscreens"
depends on SPI_MASTER
select REGMAP_SPI
select TOUCHSCREEN_TSC200X_CORE
help
Say Y here if you have a TSC2005 based touchscreen.
......
......@@ -69,6 +69,8 @@ obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
obj-$(CONFIG_TOUCHSCREEN_TSC_SERIO) += tsc40.o
obj-$(CONFIG_TOUCHSCREEN_TSC200X_CORE) += tsc200x-core.o
obj-$(CONFIG_TOUCHSCREEN_TSC2004) += tsc2004.o
obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o
obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o
obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
......
/*
* TSC2004 touchscreen driver
*
* Copyright (C) 2015 QWERTY Embedded Design
* Copyright (C) 2015 EMAC Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/module.h>
#include <linux/input.h>
#include <linux/of.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include "tsc200x-core.h"
static int tsc2004_cmd(struct device *dev, u8 cmd)
{
u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
s32 data;
struct i2c_client *i2c = to_i2c_client(dev);
data = i2c_smbus_write_byte(i2c, tx);
if (data < 0) {
dev_err(dev, "%s: failed, command: %x i2c error: %d\n",
__func__, cmd, data);
return data;
}
return 0;
}
static int tsc2004_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
return tsc200x_probe(&i2c->dev, i2c->irq, BUS_I2C,
devm_regmap_init_i2c(i2c, &tsc200x_regmap_config),
tsc2004_cmd);
}
static int tsc2004_remove(struct i2c_client *i2c)
{
return tsc200x_remove(&i2c->dev);
}
static const struct i2c_device_id tsc2004_idtable[] = {
{ "tsc2004", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, tsc2004_idtable);
#ifdef CONFIG_OF
static const struct of_device_id tsc2004_of_match[] = {
{ .compatible = "ti,tsc2004" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, tsc2004_of_match);
#endif
static struct i2c_driver tsc2004_driver = {
.driver = {
.name = "tsc2004",
.of_match_table = of_match_ptr(tsc2004_of_match),
.pm = &tsc200x_pm_ops,
},
.id_table = tsc2004_idtable,
.probe = tsc2004_probe,
.remove = tsc2004_remove,
};
module_i2c_driver(tsc2004_driver);
MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
MODULE_DESCRIPTION("TSC2004 Touchscreen Driver");
MODULE_LICENSE("GPL");
This diff is collapsed.
/*
* 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>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#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/spi/tsc2005.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.
* 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
* values.
* 6) tsc200x_irq_thread() reports coordinates to input layer and sets up
* tsc200x_penup_timer() to be called after TSC200X_PENUP_TIME_MS (40ms).
* 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.
*
* ESD recovery via a hardware reset is done if the TSC200X doesn't respond
* after a configurable period (in ms) of activity. If esd_timeout is 0, the
* watchdog is disabled.
*/
static const struct regmap_range tsc200x_writable_ranges[] = {
regmap_reg_range(TSC200X_REG_AUX_HIGH, TSC200X_REG_CFR2),
};
static const struct regmap_access_table tsc200x_writable_table = {
.yes_ranges = tsc200x_writable_ranges,
.n_yes_ranges = ARRAY_SIZE(tsc200x_writable_ranges),
};
const struct regmap_config tsc200x_regmap_config = {
.reg_bits = 8,
.val_bits = 16,
.reg_stride = 0x08,
.max_register = 0x78,
.read_flag_mask = TSC200X_REG_READ,
.write_flag_mask = TSC200X_REG_PND0,
.wr_table = &tsc200x_writable_table,
.use_single_rw = true,
};
EXPORT_SYMBOL_GPL(tsc200x_regmap_config);
struct tsc200x_data {
u16 x;
u16 y;
u16 z1;
u16 z2;
} __packed;
#define TSC200X_DATA_REGS 4
struct tsc200x {
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;
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 regulator *vio;
struct gpio_desc *reset_gpio;
void (*set_reset)(bool enable);
int (*tsc200x_cmd)(struct device *dev, u8 cmd);
int irq;
};
static void tsc200x_update_pen_state(struct tsc200x *ts,
int x, int y, int pressure)
{
if (pressure) {
input_report_abs(ts->idev, ABS_X, x);
input_report_abs(ts->idev, ABS_Y, y);
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);
}
static irqreturn_t tsc200x_irq_thread(int irq, void *_ts)
{
struct tsc200x *ts = _ts;
unsigned long flags;
unsigned int pressure;
struct tsc200x_data tsdata;
int error;
/* read the coordinates */
error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata,
TSC200X_DATA_REGS);
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;
spin_lock_irqsave(&ts->lock, flags);
tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure);
mod_timer(&ts->penup_timer,
jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS));
spin_unlock_irqrestore(&ts->lock, flags);
ts->last_valid_interrupt = jiffies;
out:
return IRQ_HANDLED;
}
static void tsc200x_penup_timer(unsigned long data)
{
struct tsc200x *ts = (struct tsc200x *)data;
unsigned long flags;
spin_lock_irqsave(&ts->lock, flags);
tsc200x_update_pen_state(ts, 0, 0, 0);
spin_unlock_irqrestore(&ts->lock, flags);
}
static void tsc200x_start_scan(struct tsc200x *ts)
{
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);
}
static void tsc200x_stop_scan(struct tsc200x *ts)
{
ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP);
}
static void tsc200x_set_reset(struct tsc200x *ts, bool enable)
{
if (ts->reset_gpio)
gpiod_set_value_cansleep(ts->reset_gpio, enable);
else if (ts->set_reset)
ts->set_reset(enable);
}
/* must be called with ts->mutex held */
static void __tsc200x_disable(struct tsc200x *ts)
{
tsc200x_stop_scan(ts);
disable_irq(ts->irq);
del_timer_sync(&ts->penup_timer);
cancel_delayed_work_sync(&ts->esd_work);
enable_irq(ts->irq);
}
/* must be called with ts->mutex held */
static void __tsc200x_enable(struct tsc200x *ts)
{
tsc200x_start_scan(ts);
if (ts->esd_timeout && (ts->set_reset || ts->reset_gpio)) {
ts->last_valid_interrupt = jiffies;
schedule_delayed_work(&ts->esd_work,
round_jiffies_relative(
msecs_to_jiffies(ts->esd_timeout)));
}
}
static ssize_t tsc200x_selftest_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct tsc200x *ts = dev_get_drvdata(dev);
unsigned int temp_high;
unsigned int temp_high_orig;
unsigned int temp_high_test;
bool success = true;
int error;
mutex_lock(&ts->mutex);
/*
* Test TSC200X communications via temp high register.
*/
__tsc200x_disable(ts);
error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig);
if (error) {
dev_warn(dev, "selftest failed: read error %d\n", error);
success = false;
goto out;
}
temp_high_test = (temp_high_orig - 1) & MAX_12BIT;
error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test);
if (error) {
dev_warn(dev, "selftest failed: write error %d\n", error);
success = false;
goto out;
}
error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high);
if (error) {
dev_warn(dev, "selftest failed: read error %d after write\n",
error);
success = false;
goto out;
}
if (temp_high != temp_high_test) {
dev_warn(dev, "selftest failed: %d != %d\n",
temp_high, temp_high_test);
success = false;
}
/* hardware reset */
tsc200x_set_reset(ts, false);
usleep_range(100, 500); /* only 10us required */
tsc200x_set_reset(ts, true);
if (!success)
goto out;
/* test that the reset really happened */
error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high);
if (error) {
dev_warn(dev, "selftest failed: read error %d after reset\n",
error);
success = false;
goto out;
}
if (temp_high != temp_high_orig) {
dev_warn(dev, "selftest failed after reset: %d != %d\n",
temp_high, temp_high_orig);
success = false;
}
out:
__tsc200x_enable(ts);
mutex_unlock(&ts->mutex);
return sprintf(buf, "%d\n", success);
}
static DEVICE_ATTR(selftest, S_IRUGO, tsc200x_selftest_show, NULL);
static struct attribute *tsc200x_attrs[] = {
&dev_attr_selftest.attr,
NULL
};
static umode_t tsc200x_attr_is_visible(struct kobject *kobj,
struct attribute *attr, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct tsc200x *ts = dev_get_drvdata(dev);
umode_t mode = attr->mode;
if (attr == &dev_attr_selftest.attr) {
if (!ts->set_reset && !ts->reset_gpio)
mode = 0;
}
return mode;
}
static const struct attribute_group tsc200x_attr_group = {
.is_visible = tsc200x_attr_is_visible,
.attrs = tsc200x_attrs,
};
static void tsc200x_esd_work(struct work_struct *work)
{
struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work);
int error;
unsigned int r;
if (!mutex_trylock(&ts->mutex)) {
/*
* 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.
*/
goto reschedule;
}
if (time_is_after_jiffies(ts->last_valid_interrupt +
msecs_to_jiffies(ts->esd_timeout)))
goto out;
/* 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)) {
goto out;
}
/*
* 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");
disable_irq(ts->irq);
del_timer_sync(&ts->penup_timer);
tsc200x_update_pen_state(ts, 0, 0, 0);
tsc200x_set_reset(ts, false);
usleep_range(100, 500); /* only 10us required */
tsc200x_set_reset(ts, true);
enable_irq(ts->irq);
tsc200x_start_scan(ts);
out:
mutex_unlock(&ts->mutex);
reschedule:
/* re-a