Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'next' into for-linus

Prepare second round of input updates for 4.3 merge window.

+899 -703
+28 -6
Documentation/devicetree/bindings/input/touchscreen/tsc2005.txt
··· 1 - * Texas Instruments tsc2005 touchscreen controller 1 + * Texas Instruments tsc2004 and tsc2005 touchscreen controllers 2 2 3 3 Required properties: 4 - - compatible : "ti,tsc2005" 5 - - reg : SPI device address 6 - - spi-max-frequency : Maximal SPI speed 4 + - compatible : "ti,tsc2004" or "ti,tsc2005" 5 + - reg : Device address 7 6 - interrupts : IRQ specifier 8 - - reset-gpios : GPIO specifier 9 - - vio-supply : Regulator specifier 7 + - spi-max-frequency : Maximum SPI clocking speed of the device 8 + (for tsc2005) 10 9 11 10 Optional properties: 11 + - vio-supply : Regulator specifier 12 + - reset-gpios : GPIO specifier for the controller reset line 12 13 - ti,x-plate-ohms : integer, resistance of the touchscreen's X plates 13 14 in ohm (defaults to 280) 14 15 - ti,esd-recovery-timeout-ms : integer, if the touchscreen does not respond after ··· 18 17 - properties defined in touchscreen.txt 19 18 20 19 Example: 20 + 21 + &i2c3 { 22 + tsc2004@48 { 23 + compatible = "ti,tsc2004"; 24 + reg = <0x48>; 25 + vio-supply = <&vio>; 26 + 27 + reset-gpios = <&gpio4 8 GPIO_ACTIVE_HIGH>; 28 + interrupts-extended = <&gpio1 27 IRQ_TYPE_EDGE_RISING>; 29 + 30 + touchscreen-fuzz-x = <4>; 31 + touchscreen-fuzz-y = <7>; 32 + touchscreen-fuzz-pressure = <2>; 33 + touchscreen-size-x = <4096>; 34 + touchscreen-size-y = <4096>; 35 + touchscreen-max-pressure = <2048>; 36 + 37 + ti,x-plate-ohms = <280>; 38 + ti,esd-recovery-timeout-ms = <8000>; 39 + }; 40 + } 21 41 22 42 &mcspi1 { 23 43 tsc2005@0 {
+7
drivers/input/mouse/elantech.c
··· 1520 1520 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E544"), 1521 1521 }, 1522 1522 }, 1523 + { 1524 + /* Fujitsu LIFEBOOK U745 does not work with crc_enabled == 0 */ 1525 + .matches = { 1526 + DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 1527 + DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK U745"), 1528 + }, 1529 + }, 1523 1530 #endif 1524 1531 { } 1525 1532 };
+1 -1
drivers/input/serio/parkbd.c
··· 164 164 return 0; 165 165 } 166 166 167 - static struct serio * __init parkbd_allocate_serio(void) 167 + static struct serio *parkbd_allocate_serio(void) 168 168 { 169 169 struct serio *serio; 170 170
+17
drivers/input/touchscreen/Kconfig
··· 939 939 To compile this driver as a module, choose M here: the 940 940 module will be called tsc40. 941 941 942 + config TOUCHSCREEN_TSC200X_CORE 943 + tristate 944 + 945 + config TOUCHSCREEN_TSC2004 946 + tristate "TSC2004 based touchscreens" 947 + depends on I2C 948 + select REGMAP_I2C 949 + select TOUCHSCREEN_TSC200X_CORE 950 + help 951 + Say Y here if you have a TSC2004 based touchscreen. 952 + 953 + If unsure, say N. 954 + 955 + To compile this driver as a module, choose M here: the 956 + module will be called tsc2004. 957 + 942 958 config TOUCHSCREEN_TSC2005 943 959 tristate "TSC2005 based touchscreens" 944 960 depends on SPI_MASTER 945 961 select REGMAP_SPI 962 + select TOUCHSCREEN_TSC200X_CORE 946 963 help 947 964 Say Y here if you have a TSC2005 based touchscreen. 948 965
+2
drivers/input/touchscreen/Makefile
··· 69 69 obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 70 70 obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 71 71 obj-$(CONFIG_TOUCHSCREEN_TSC_SERIO) += tsc40.o 72 + obj-$(CONFIG_TOUCHSCREEN_TSC200X_CORE) += tsc200x-core.o 73 + obj-$(CONFIG_TOUCHSCREEN_TSC2004) += tsc2004.o 72 74 obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o 73 75 obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o 74 76 obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
+83
drivers/input/touchscreen/tsc2004.c
··· 1 + /* 2 + * TSC2004 touchscreen driver 3 + * 4 + * Copyright (C) 2015 QWERTY Embedded Design 5 + * Copyright (C) 2015 EMAC Inc. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/module.h> 19 + #include <linux/input.h> 20 + #include <linux/of.h> 21 + #include <linux/i2c.h> 22 + #include <linux/regmap.h> 23 + #include "tsc200x-core.h" 24 + 25 + static int tsc2004_cmd(struct device *dev, u8 cmd) 26 + { 27 + u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd; 28 + s32 data; 29 + struct i2c_client *i2c = to_i2c_client(dev); 30 + 31 + data = i2c_smbus_write_byte(i2c, tx); 32 + if (data < 0) { 33 + dev_err(dev, "%s: failed, command: %x i2c error: %d\n", 34 + __func__, cmd, data); 35 + return data; 36 + } 37 + 38 + return 0; 39 + } 40 + 41 + static int tsc2004_probe(struct i2c_client *i2c, 42 + const struct i2c_device_id *id) 43 + 44 + { 45 + return tsc200x_probe(&i2c->dev, i2c->irq, BUS_I2C, 46 + devm_regmap_init_i2c(i2c, &tsc200x_regmap_config), 47 + tsc2004_cmd); 48 + } 49 + 50 + static int tsc2004_remove(struct i2c_client *i2c) 51 + { 52 + return tsc200x_remove(&i2c->dev); 53 + } 54 + 55 + static const struct i2c_device_id tsc2004_idtable[] = { 56 + { "tsc2004", 0 }, 57 + { } 58 + }; 59 + MODULE_DEVICE_TABLE(i2c, tsc2004_idtable); 60 + 61 + #ifdef CONFIG_OF 62 + static const struct of_device_id tsc2004_of_match[] = { 63 + { .compatible = "ti,tsc2004" }, 64 + { /* sentinel */ } 65 + }; 66 + MODULE_DEVICE_TABLE(of, tsc2004_of_match); 67 + #endif 68 + 69 + static struct i2c_driver tsc2004_driver = { 70 + .driver = { 71 + .name = "tsc2004", 72 + .of_match_table = of_match_ptr(tsc2004_of_match), 73 + .pm = &tsc200x_pm_ops, 74 + }, 75 + .id_table = tsc2004_idtable, 76 + .probe = tsc2004_probe, 77 + .remove = tsc2004_remove, 78 + }; 79 + module_i2c_driver(tsc2004_driver); 80 + 81 + MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>"); 82 + MODULE_DESCRIPTION("TSC2004 Touchscreen Driver"); 83 + MODULE_LICENSE("GPL");
+18 -696
drivers/input/touchscreen/tsc2005.c
··· 2 2 * TSC2005 touchscreen driver 3 3 * 4 4 * Copyright (C) 2006-2010 Nokia Corporation 5 + * Copyright (C) 2015 QWERTY Embedded Design 6 + * Copyright (C) 2015 EMAC Inc. 5 7 * 6 - * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com> 7 - * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com> 8 + * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com> 8 9 * 9 10 * This program is free software; you can redistribute it and/or modify 10 11 * it under the terms of the GNU General Public License as published by ··· 16 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 17 * GNU General Public License for more details. 19 - * 20 - * You should have received a copy of the GNU General Public License 21 - * along with this program; if not, write to the Free Software 22 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 - * 24 18 */ 25 19 26 - #include <linux/kernel.h> 27 20 #include <linux/module.h> 28 21 #include <linux/input.h> 29 - #include <linux/input/touchscreen.h> 30 - #include <linux/interrupt.h> 31 - #include <linux/delay.h> 32 - #include <linux/pm.h> 33 - #include <linux/of.h> 34 22 #include <linux/spi/spi.h> 35 - #include <linux/spi/tsc2005.h> 36 - #include <linux/regulator/consumer.h> 37 23 #include <linux/regmap.h> 38 - #include <linux/gpio/consumer.h> 24 + #include "tsc200x-core.h" 39 25 40 - /* 41 - * The touchscreen interface operates as follows: 42 - * 43 - * 1) Pen is pressed against the touchscreen. 44 - * 2) TSC2005 performs AD conversion. 45 - * 3) After the conversion is done TSC2005 drives DAV line down. 46 - * 4) GPIO IRQ is received and tsc2005_irq_thread() is scheduled. 47 - * 5) tsc2005_irq_thread() queues up an spi transfer to fetch the x, y, z1, z2 48 - * values. 49 - * 6) tsc2005_irq_thread() reports coordinates to input layer and sets up 50 - * tsc2005_penup_timer() to be called after TSC2005_PENUP_TIME_MS (40ms). 51 - * 7) When the penup timer expires, there have not been touch or DAV interrupts 52 - * during the last 40ms which means the pen has been lifted. 53 - * 54 - * ESD recovery via a hardware reset is done if the TSC2005 doesn't respond 55 - * after a configurable period (in ms) of activity. If esd_timeout is 0, the 56 - * watchdog is disabled. 57 - */ 58 - 59 - /* control byte 1 */ 60 - #define TSC2005_CMD 0x80 61 - #define TSC2005_CMD_NORMAL 0x00 62 - #define TSC2005_CMD_STOP 0x01 63 - #define TSC2005_CMD_12BIT 0x04 64 - 65 - /* control byte 0 */ 66 - #define TSC2005_REG_READ 0x01 /* R/W access */ 67 - #define TSC2005_REG_PND0 0x02 /* Power Not Down Control */ 68 - #define TSC2005_REG_X (0x0 << 3) 69 - #define TSC2005_REG_Y (0x1 << 3) 70 - #define TSC2005_REG_Z1 (0x2 << 3) 71 - #define TSC2005_REG_Z2 (0x3 << 3) 72 - #define TSC2005_REG_AUX (0x4 << 3) 73 - #define TSC2005_REG_TEMP1 (0x5 << 3) 74 - #define TSC2005_REG_TEMP2 (0x6 << 3) 75 - #define TSC2005_REG_STATUS (0x7 << 3) 76 - #define TSC2005_REG_AUX_HIGH (0x8 << 3) 77 - #define TSC2005_REG_AUX_LOW (0x9 << 3) 78 - #define TSC2005_REG_TEMP_HIGH (0xA << 3) 79 - #define TSC2005_REG_TEMP_LOW (0xB << 3) 80 - #define TSC2005_REG_CFR0 (0xC << 3) 81 - #define TSC2005_REG_CFR1 (0xD << 3) 82 - #define TSC2005_REG_CFR2 (0xE << 3) 83 - #define TSC2005_REG_CONV_FUNC (0xF << 3) 84 - 85 - /* configuration register 0 */ 86 - #define TSC2005_CFR0_PRECHARGE_276US 0x0040 87 - #define TSC2005_CFR0_STABTIME_1MS 0x0300 88 - #define TSC2005_CFR0_CLOCK_1MHZ 0x1000 89 - #define TSC2005_CFR0_RESOLUTION12 0x2000 90 - #define TSC2005_CFR0_PENMODE 0x8000 91 - #define TSC2005_CFR0_INITVALUE (TSC2005_CFR0_STABTIME_1MS | \ 92 - TSC2005_CFR0_CLOCK_1MHZ | \ 93 - TSC2005_CFR0_RESOLUTION12 | \ 94 - TSC2005_CFR0_PRECHARGE_276US | \ 95 - TSC2005_CFR0_PENMODE) 96 - 97 - /* bits common to both read and write of configuration register 0 */ 98 - #define TSC2005_CFR0_RW_MASK 0x3fff 99 - 100 - /* configuration register 1 */ 101 - #define TSC2005_CFR1_BATCHDELAY_4MS 0x0003 102 - #define TSC2005_CFR1_INITVALUE TSC2005_CFR1_BATCHDELAY_4MS 103 - 104 - /* configuration register 2 */ 105 - #define TSC2005_CFR2_MAVE_Z 0x0004 106 - #define TSC2005_CFR2_MAVE_Y 0x0008 107 - #define TSC2005_CFR2_MAVE_X 0x0010 108 - #define TSC2005_CFR2_AVG_7 0x0800 109 - #define TSC2005_CFR2_MEDIUM_15 0x3000 110 - #define TSC2005_CFR2_INITVALUE (TSC2005_CFR2_MAVE_X | \ 111 - TSC2005_CFR2_MAVE_Y | \ 112 - TSC2005_CFR2_MAVE_Z | \ 113 - TSC2005_CFR2_MEDIUM_15 | \ 114 - TSC2005_CFR2_AVG_7) 115 - 116 - #define MAX_12BIT 0xfff 117 - #define TSC2005_DEF_X_FUZZ 4 118 - #define TSC2005_DEF_Y_FUZZ 8 119 - #define TSC2005_DEF_P_FUZZ 2 120 - #define TSC2005_DEF_RESISTOR 280 121 - 122 - #define TSC2005_SPI_MAX_SPEED_HZ 10000000 123 - #define TSC2005_PENUP_TIME_MS 40 124 - 125 - static const struct regmap_range tsc2005_writable_ranges[] = { 126 - regmap_reg_range(TSC2005_REG_AUX_HIGH, TSC2005_REG_CFR2), 127 - }; 128 - 129 - static const struct regmap_access_table tsc2005_writable_table = { 130 - .yes_ranges = tsc2005_writable_ranges, 131 - .n_yes_ranges = ARRAY_SIZE(tsc2005_writable_ranges), 132 - }; 133 - 134 - static struct regmap_config tsc2005_regmap_config = { 135 - .reg_bits = 8, 136 - .val_bits = 16, 137 - .reg_stride = 0x08, 138 - .max_register = 0x78, 139 - .read_flag_mask = TSC2005_REG_READ, 140 - .write_flag_mask = TSC2005_REG_PND0, 141 - .wr_table = &tsc2005_writable_table, 142 - .use_single_rw = true, 143 - }; 144 - 145 - struct tsc2005_data { 146 - u16 x; 147 - u16 y; 148 - u16 z1; 149 - u16 z2; 150 - } __packed; 151 - #define TSC2005_DATA_REGS 4 152 - 153 - struct tsc2005 { 154 - struct spi_device *spi; 155 - struct regmap *regmap; 156 - 157 - struct input_dev *idev; 158 - char phys[32]; 159 - 160 - struct mutex mutex; 161 - 162 - /* raw copy of previous x,y,z */ 163 - int in_x; 164 - int in_y; 165 - int in_z1; 166 - int in_z2; 167 - 168 - spinlock_t lock; 169 - struct timer_list penup_timer; 170 - 171 - unsigned int esd_timeout; 172 - struct delayed_work esd_work; 173 - unsigned long last_valid_interrupt; 174 - 175 - unsigned int x_plate_ohm; 176 - 177 - bool opened; 178 - bool suspended; 179 - 180 - bool pen_down; 181 - 182 - struct regulator *vio; 183 - 184 - struct gpio_desc *reset_gpio; 185 - void (*set_reset)(bool enable); 186 - }; 187 - 188 - static int tsc2005_cmd(struct tsc2005 *ts, u8 cmd) 26 + static int tsc2005_cmd(struct device *dev, u8 cmd) 189 27 { 190 - u8 tx = TSC2005_CMD | TSC2005_CMD_12BIT | cmd; 28 + u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd; 191 29 struct spi_transfer xfer = { 192 - .tx_buf = &tx, 193 - .len = 1, 194 - .bits_per_word = 8, 30 + .tx_buf = &tx, 31 + .len = 1, 32 + .bits_per_word = 8, 195 33 }; 196 34 struct spi_message msg; 35 + struct spi_device *spi = to_spi_device(dev); 197 36 int error; 198 37 199 38 spi_message_init(&msg); 200 39 spi_message_add_tail(&xfer, &msg); 201 40 202 - error = spi_sync(ts->spi, &msg); 41 + error = spi_sync(spi, &msg); 203 42 if (error) { 204 - dev_err(&ts->spi->dev, "%s: failed, command: %x, error: %d\n", 43 + dev_err(dev, "%s: failed, command: %x, spi error: %d\n", 205 44 __func__, cmd, error); 206 45 return error; 207 46 } ··· 49 208 return 0; 50 209 } 51 210 52 - static void tsc2005_update_pen_state(struct tsc2005 *ts, 53 - int x, int y, int pressure) 54 - { 55 - if (pressure) { 56 - input_report_abs(ts->idev, ABS_X, x); 57 - input_report_abs(ts->idev, ABS_Y, y); 58 - input_report_abs(ts->idev, ABS_PRESSURE, pressure); 59 - if (!ts->pen_down) { 60 - input_report_key(ts->idev, BTN_TOUCH, !!pressure); 61 - ts->pen_down = true; 62 - } 63 - } else { 64 - input_report_abs(ts->idev, ABS_PRESSURE, 0); 65 - if (ts->pen_down) { 66 - input_report_key(ts->idev, BTN_TOUCH, 0); 67 - ts->pen_down = false; 68 - } 69 - } 70 - input_sync(ts->idev); 71 - dev_dbg(&ts->spi->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, 72 - pressure); 73 - } 74 - 75 - static irqreturn_t tsc2005_irq_thread(int irq, void *_ts) 76 - { 77 - struct tsc2005 *ts = _ts; 78 - unsigned long flags; 79 - unsigned int pressure; 80 - struct tsc2005_data tsdata; 81 - int error; 82 - 83 - /* read the coordinates */ 84 - error = regmap_bulk_read(ts->regmap, TSC2005_REG_X, &tsdata, 85 - TSC2005_DATA_REGS); 86 - if (unlikely(error)) 87 - goto out; 88 - 89 - /* validate position */ 90 - if (unlikely(tsdata.x > MAX_12BIT || tsdata.y > MAX_12BIT)) 91 - goto out; 92 - 93 - /* Skip reading if the pressure components are out of range */ 94 - if (unlikely(tsdata.z1 == 0 || tsdata.z2 > MAX_12BIT)) 95 - goto out; 96 - if (unlikely(tsdata.z1 >= tsdata.z2)) 97 - goto out; 98 - 99 - /* 100 - * Skip point if this is a pen down with the exact same values as 101 - * the value before pen-up - that implies SPI fed us stale data 102 - */ 103 - if (!ts->pen_down && 104 - ts->in_x == tsdata.x && ts->in_y == tsdata.y && 105 - ts->in_z1 == tsdata.z1 && ts->in_z2 == tsdata.z2) { 106 - goto out; 107 - } 108 - 109 - /* 110 - * At this point we are happy we have a valid and useful reading. 111 - * Remember it for later comparisons. We may now begin downsampling. 112 - */ 113 - ts->in_x = tsdata.x; 114 - ts->in_y = tsdata.y; 115 - ts->in_z1 = tsdata.z1; 116 - ts->in_z2 = tsdata.z2; 117 - 118 - /* Compute touch pressure resistance using equation #1 */ 119 - pressure = tsdata.x * (tsdata.z2 - tsdata.z1) / tsdata.z1; 120 - pressure = pressure * ts->x_plate_ohm / 4096; 121 - if (unlikely(pressure > MAX_12BIT)) 122 - goto out; 123 - 124 - spin_lock_irqsave(&ts->lock, flags); 125 - 126 - tsc2005_update_pen_state(ts, tsdata.x, tsdata.y, pressure); 127 - mod_timer(&ts->penup_timer, 128 - jiffies + msecs_to_jiffies(TSC2005_PENUP_TIME_MS)); 129 - 130 - spin_unlock_irqrestore(&ts->lock, flags); 131 - 132 - ts->last_valid_interrupt = jiffies; 133 - out: 134 - return IRQ_HANDLED; 135 - } 136 - 137 - static void tsc2005_penup_timer(unsigned long data) 138 - { 139 - struct tsc2005 *ts = (struct tsc2005 *)data; 140 - unsigned long flags; 141 - 142 - spin_lock_irqsave(&ts->lock, flags); 143 - tsc2005_update_pen_state(ts, 0, 0, 0); 144 - spin_unlock_irqrestore(&ts->lock, flags); 145 - } 146 - 147 - static void tsc2005_start_scan(struct tsc2005 *ts) 148 - { 149 - regmap_write(ts->regmap, TSC2005_REG_CFR0, TSC2005_CFR0_INITVALUE); 150 - regmap_write(ts->regmap, TSC2005_REG_CFR1, TSC2005_CFR1_INITVALUE); 151 - regmap_write(ts->regmap, TSC2005_REG_CFR2, TSC2005_CFR2_INITVALUE); 152 - tsc2005_cmd(ts, TSC2005_CMD_NORMAL); 153 - } 154 - 155 - static void tsc2005_stop_scan(struct tsc2005 *ts) 156 - { 157 - tsc2005_cmd(ts, TSC2005_CMD_STOP); 158 - } 159 - 160 - static void tsc2005_set_reset(struct tsc2005 *ts, bool enable) 161 - { 162 - if (ts->reset_gpio) 163 - gpiod_set_value_cansleep(ts->reset_gpio, enable); 164 - else if (ts->set_reset) 165 - ts->set_reset(enable); 166 - } 167 - 168 - /* must be called with ts->mutex held */ 169 - static void __tsc2005_disable(struct tsc2005 *ts) 170 - { 171 - tsc2005_stop_scan(ts); 172 - 173 - disable_irq(ts->spi->irq); 174 - del_timer_sync(&ts->penup_timer); 175 - 176 - cancel_delayed_work_sync(&ts->esd_work); 177 - 178 - enable_irq(ts->spi->irq); 179 - } 180 - 181 - /* must be called with ts->mutex held */ 182 - static void __tsc2005_enable(struct tsc2005 *ts) 183 - { 184 - tsc2005_start_scan(ts); 185 - 186 - if (ts->esd_timeout && (ts->set_reset || ts->reset_gpio)) { 187 - ts->last_valid_interrupt = jiffies; 188 - schedule_delayed_work(&ts->esd_work, 189 - round_jiffies_relative( 190 - msecs_to_jiffies(ts->esd_timeout))); 191 - } 192 - 193 - } 194 - 195 - static ssize_t tsc2005_selftest_show(struct device *dev, 196 - struct device_attribute *attr, 197 - char *buf) 198 - { 199 - struct tsc2005 *ts = dev_get_drvdata(dev); 200 - unsigned int temp_high; 201 - unsigned int temp_high_orig; 202 - unsigned int temp_high_test; 203 - bool success = true; 204 - int error; 205 - 206 - mutex_lock(&ts->mutex); 207 - 208 - /* 209 - * Test TSC2005 communications via temp high register. 210 - */ 211 - __tsc2005_disable(ts); 212 - 213 - error = regmap_read(ts->regmap, TSC2005_REG_TEMP_HIGH, &temp_high_orig); 214 - if (error) { 215 - dev_warn(dev, "selftest failed: read error %d\n", error); 216 - success = false; 217 - goto out; 218 - } 219 - 220 - temp_high_test = (temp_high_orig - 1) & MAX_12BIT; 221 - 222 - error = regmap_write(ts->regmap, TSC2005_REG_TEMP_HIGH, temp_high_test); 223 - if (error) { 224 - dev_warn(dev, "selftest failed: write error %d\n", error); 225 - success = false; 226 - goto out; 227 - } 228 - 229 - error = regmap_read(ts->regmap, TSC2005_REG_TEMP_HIGH, &temp_high); 230 - if (error) { 231 - dev_warn(dev, "selftest failed: read error %d after write\n", 232 - error); 233 - success = false; 234 - goto out; 235 - } 236 - 237 - if (temp_high != temp_high_test) { 238 - dev_warn(dev, "selftest failed: %d != %d\n", 239 - temp_high, temp_high_test); 240 - success = false; 241 - } 242 - 243 - /* hardware reset */ 244 - tsc2005_set_reset(ts, false); 245 - usleep_range(100, 500); /* only 10us required */ 246 - tsc2005_set_reset(ts, true); 247 - 248 - if (!success) 249 - goto out; 250 - 251 - /* test that the reset really happened */ 252 - error = regmap_read(ts->regmap, TSC2005_REG_TEMP_HIGH, &temp_high); 253 - if (error) { 254 - dev_warn(dev, "selftest failed: read error %d after reset\n", 255 - error); 256 - success = false; 257 - goto out; 258 - } 259 - 260 - if (temp_high != temp_high_orig) { 261 - dev_warn(dev, "selftest failed after reset: %d != %d\n", 262 - temp_high, temp_high_orig); 263 - success = false; 264 - } 265 - 266 - out: 267 - __tsc2005_enable(ts); 268 - mutex_unlock(&ts->mutex); 269 - 270 - return sprintf(buf, "%d\n", success); 271 - } 272 - 273 - static DEVICE_ATTR(selftest, S_IRUGO, tsc2005_selftest_show, NULL); 274 - 275 - static struct attribute *tsc2005_attrs[] = { 276 - &dev_attr_selftest.attr, 277 - NULL 278 - }; 279 - 280 - static umode_t tsc2005_attr_is_visible(struct kobject *kobj, 281 - struct attribute *attr, int n) 282 - { 283 - struct device *dev = container_of(kobj, struct device, kobj); 284 - struct tsc2005 *ts = dev_get_drvdata(dev); 285 - umode_t mode = attr->mode; 286 - 287 - if (attr == &dev_attr_selftest.attr) { 288 - if (!ts->set_reset && !ts->reset_gpio) 289 - mode = 0; 290 - } 291 - 292 - return mode; 293 - } 294 - 295 - static const struct attribute_group tsc2005_attr_group = { 296 - .is_visible = tsc2005_attr_is_visible, 297 - .attrs = tsc2005_attrs, 298 - }; 299 - 300 - static void tsc2005_esd_work(struct work_struct *work) 301 - { 302 - struct tsc2005 *ts = container_of(work, struct tsc2005, esd_work.work); 303 - int error; 304 - unsigned int r; 305 - 306 - if (!mutex_trylock(&ts->mutex)) { 307 - /* 308 - * If the mutex is taken, it means that disable or enable is in 309 - * progress. In that case just reschedule the work. If the work 310 - * is not needed, it will be canceled by disable. 311 - */ 312 - goto reschedule; 313 - } 314 - 315 - if (time_is_after_jiffies(ts->last_valid_interrupt + 316 - msecs_to_jiffies(ts->esd_timeout))) 317 - goto out; 318 - 319 - /* We should be able to read register without disabling interrupts. */ 320 - error = regmap_read(ts->regmap, TSC2005_REG_CFR0, &r); 321 - if (!error && 322 - !((r ^ TSC2005_CFR0_INITVALUE) & TSC2005_CFR0_RW_MASK)) { 323 - goto out; 324 - } 325 - 326 - /* 327 - * If we could not read our known value from configuration register 0 328 - * then we should reset the controller as if from power-up and start 329 - * scanning again. 330 - */ 331 - dev_info(&ts->spi->dev, "TSC2005 not responding - resetting\n"); 332 - 333 - disable_irq(ts->spi->irq); 334 - del_timer_sync(&ts->penup_timer); 335 - 336 - tsc2005_update_pen_state(ts, 0, 0, 0); 337 - 338 - tsc2005_set_reset(ts, false); 339 - usleep_range(100, 500); /* only 10us required */ 340 - tsc2005_set_reset(ts, true); 341 - 342 - enable_irq(ts->spi->irq); 343 - tsc2005_start_scan(ts); 344 - 345 - out: 346 - mutex_unlock(&ts->mutex); 347 - reschedule: 348 - /* re-arm the watchdog */ 349 - schedule_delayed_work(&ts->esd_work, 350 - round_jiffies_relative( 351 - msecs_to_jiffies(ts->esd_timeout))); 352 - } 353 - 354 - static int tsc2005_open(struct input_dev *input) 355 - { 356 - struct tsc2005 *ts = input_get_drvdata(input); 357 - 358 - mutex_lock(&ts->mutex); 359 - 360 - if (!ts->suspended) 361 - __tsc2005_enable(ts); 362 - 363 - ts->opened = true; 364 - 365 - mutex_unlock(&ts->mutex); 366 - 367 - return 0; 368 - } 369 - 370 - static void tsc2005_close(struct input_dev *input) 371 - { 372 - struct tsc2005 *ts = input_get_drvdata(input); 373 - 374 - mutex_lock(&ts->mutex); 375 - 376 - if (!ts->suspended) 377 - __tsc2005_disable(ts); 378 - 379 - ts->opened = false; 380 - 381 - mutex_unlock(&ts->mutex); 382 - } 383 - 384 211 static int tsc2005_probe(struct spi_device *spi) 385 212 { 386 - const struct tsc2005_platform_data *pdata = dev_get_platdata(&spi->dev); 387 - struct device_node *np = spi->dev.of_node; 388 - 389 - struct tsc2005 *ts; 390 - struct input_dev *input_dev; 391 - unsigned int max_x = MAX_12BIT; 392 - unsigned int max_y = MAX_12BIT; 393 - unsigned int max_p = MAX_12BIT; 394 - unsigned int fudge_x = TSC2005_DEF_X_FUZZ; 395 - unsigned int fudge_y = TSC2005_DEF_Y_FUZZ; 396 - unsigned int fudge_p = TSC2005_DEF_P_FUZZ; 397 - unsigned int x_plate_ohm = TSC2005_DEF_RESISTOR; 398 - unsigned int esd_timeout; 399 213 int error; 400 - 401 - if (!np && !pdata) { 402 - dev_err(&spi->dev, "no platform data\n"); 403 - return -ENODEV; 404 - } 405 - 406 - if (spi->irq <= 0) { 407 - dev_err(&spi->dev, "no irq\n"); 408 - return -ENODEV; 409 - } 410 - 411 - if (pdata) { 412 - fudge_x = pdata->ts_x_fudge; 413 - fudge_y = pdata->ts_y_fudge; 414 - fudge_p = pdata->ts_pressure_fudge; 415 - max_x = pdata->ts_x_max; 416 - max_y = pdata->ts_y_max; 417 - max_p = pdata->ts_pressure_max; 418 - x_plate_ohm = pdata->ts_x_plate_ohm; 419 - esd_timeout = pdata->esd_timeout_ms; 420 - } else { 421 - x_plate_ohm = TSC2005_DEF_RESISTOR; 422 - of_property_read_u32(np, "ti,x-plate-ohms", &x_plate_ohm); 423 - esd_timeout = 0; 424 - of_property_read_u32(np, "ti,esd-recovery-timeout-ms", 425 - &esd_timeout); 426 - } 427 214 428 215 spi->mode = SPI_MODE_0; 429 216 spi->bits_per_word = 8; ··· 62 593 if (error) 63 594 return error; 64 595 65 - ts = devm_kzalloc(&spi->dev, sizeof(*ts), GFP_KERNEL); 66 - if (!ts) 67 - return -ENOMEM; 68 - 69 - input_dev = devm_input_allocate_device(&spi->dev); 70 - if (!input_dev) 71 - return -ENOMEM; 72 - 73 - ts->spi = spi; 74 - ts->idev = input_dev; 75 - 76 - ts->regmap = devm_regmap_init_spi(spi, &tsc2005_regmap_config); 77 - if (IS_ERR(ts->regmap)) 78 - return PTR_ERR(ts->regmap); 79 - 80 - ts->x_plate_ohm = x_plate_ohm; 81 - ts->esd_timeout = esd_timeout; 82 - 83 - ts->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", 84 - GPIOD_OUT_HIGH); 85 - if (IS_ERR(ts->reset_gpio)) { 86 - error = PTR_ERR(ts->reset_gpio); 87 - dev_err(&spi->dev, "error acquiring reset gpio: %d\n", error); 88 - return error; 89 - } 90 - 91 - ts->vio = devm_regulator_get_optional(&spi->dev, "vio"); 92 - if (IS_ERR(ts->vio)) { 93 - error = PTR_ERR(ts->vio); 94 - dev_err(&spi->dev, "vio regulator missing (%d)", error); 95 - return error; 96 - } 97 - 98 - if (!ts->reset_gpio && pdata) 99 - ts->set_reset = pdata->set_reset; 100 - 101 - mutex_init(&ts->mutex); 102 - 103 - spin_lock_init(&ts->lock); 104 - setup_timer(&ts->penup_timer, tsc2005_penup_timer, (unsigned long)ts); 105 - 106 - INIT_DELAYED_WORK(&ts->esd_work, tsc2005_esd_work); 107 - 108 - snprintf(ts->phys, sizeof(ts->phys), 109 - "%s/input-ts", dev_name(&spi->dev)); 110 - 111 - input_dev->name = "TSC2005 touchscreen"; 112 - input_dev->phys = ts->phys; 113 - input_dev->id.bustype = BUS_SPI; 114 - input_dev->dev.parent = &spi->dev; 115 - input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); 116 - input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 117 - 118 - input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0); 119 - input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0); 120 - input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0); 121 - 122 - if (np) 123 - touchscreen_parse_properties(input_dev, false); 124 - 125 - input_dev->open = tsc2005_open; 126 - input_dev->close = tsc2005_close; 127 - 128 - input_set_drvdata(input_dev, ts); 129 - 130 - /* Ensure the touchscreen is off */ 131 - tsc2005_stop_scan(ts); 132 - 133 - error = devm_request_threaded_irq(&spi->dev, spi->irq, NULL, 134 - tsc2005_irq_thread, 135 - IRQF_TRIGGER_RISING | IRQF_ONESHOT, 136 - "tsc2005", ts); 137 - if (error) { 138 - dev_err(&spi->dev, "Failed to request irq, err: %d\n", error); 139 - return error; 140 - } 141 - 142 - /* enable regulator for DT */ 143 - if (ts->vio) { 144 - error = regulator_enable(ts->vio); 145 - if (error) 146 - return error; 147 - } 148 - 149 - dev_set_drvdata(&spi->dev, ts); 150 - error = sysfs_create_group(&spi->dev.kobj, &tsc2005_attr_group); 151 - if (error) { 152 - dev_err(&spi->dev, 153 - "Failed to create sysfs attributes, err: %d\n", error); 154 - goto disable_regulator; 155 - } 156 - 157 - error = input_register_device(ts->idev); 158 - if (error) { 159 - dev_err(&spi->dev, 160 - "Failed to register input device, err: %d\n", error); 161 - goto err_remove_sysfs; 162 - } 163 - 164 - irq_set_irq_wake(spi->irq, 1); 165 - return 0; 166 - 167 - err_remove_sysfs: 168 - sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group); 169 - disable_regulator: 170 - if (ts->vio) 171 - regulator_disable(ts->vio); 172 - return error; 596 + return tsc200x_probe(&spi->dev, spi->irq, BUS_SPI, 597 + devm_regmap_init_spi(spi, &tsc200x_regmap_config), 598 + tsc2005_cmd); 173 599 } 174 600 175 601 static int tsc2005_remove(struct spi_device *spi) 176 602 { 177 - struct tsc2005 *ts = dev_get_drvdata(&spi->dev); 178 - 179 - sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group); 180 - 181 - if (ts->vio) 182 - regulator_disable(ts->vio); 183 - 184 - return 0; 603 + return tsc200x_remove(&spi->dev); 185 604 } 186 - 187 - static int __maybe_unused tsc2005_suspend(struct device *dev) 188 - { 189 - struct tsc2005 *ts = dev_get_drvdata(dev); 190 - 191 - mutex_lock(&ts->mutex); 192 - 193 - if (!ts->suspended && ts->opened) 194 - __tsc2005_disable(ts); 195 - 196 - ts->suspended = true; 197 - 198 - mutex_unlock(&ts->mutex); 199 - 200 - return 0; 201 - } 202 - 203 - static int __maybe_unused tsc2005_resume(struct device *dev) 204 - { 205 - struct tsc2005 *ts = dev_get_drvdata(dev); 206 - 207 - mutex_lock(&ts->mutex); 208 - 209 - if (ts->suspended && ts->opened) 210 - __tsc2005_enable(ts); 211 - 212 - ts->suspended = false; 213 - 214 - mutex_unlock(&ts->mutex); 215 - 216 - return 0; 217 - } 218 - 219 - static SIMPLE_DEV_PM_OPS(tsc2005_pm_ops, tsc2005_suspend, tsc2005_resume); 220 605 221 606 static struct spi_driver tsc2005_driver = { 222 607 .driver = { 223 608 .name = "tsc2005", 224 609 .owner = THIS_MODULE, 225 - .pm = &tsc2005_pm_ops, 610 + .pm = &tsc200x_pm_ops, 226 611 }, 227 612 .probe = tsc2005_probe, 228 613 .remove = tsc2005_remove, 229 614 }; 230 - 231 615 module_spi_driver(tsc2005_driver); 232 616 233 - MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>"); 617 + MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>"); 234 618 MODULE_DESCRIPTION("TSC2005 Touchscreen Driver"); 235 619 MODULE_LICENSE("GPL"); 236 620 MODULE_ALIAS("spi:tsc2005");
+665
drivers/input/touchscreen/tsc200x-core.c
··· 1 + /* 2 + * TSC2004/TSC2005 touchscreen driver core 3 + * 4 + * Copyright (C) 2006-2010 Nokia Corporation 5 + * Copyright (C) 2015 QWERTY Embedded Design 6 + * Copyright (C) 2015 EMAC Inc. 7 + * 8 + * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com> 9 + * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #include <linux/kernel.h> 23 + #include <linux/module.h> 24 + #include <linux/input.h> 25 + #include <linux/input/touchscreen.h> 26 + #include <linux/interrupt.h> 27 + #include <linux/delay.h> 28 + #include <linux/pm.h> 29 + #include <linux/of.h> 30 + #include <linux/spi/tsc2005.h> 31 + #include <linux/regulator/consumer.h> 32 + #include <linux/regmap.h> 33 + #include <linux/gpio/consumer.h> 34 + #include "tsc200x-core.h" 35 + 36 + /* 37 + * The touchscreen interface operates as follows: 38 + * 39 + * 1) Pen is pressed against the touchscreen. 40 + * 2) TSC200X performs AD conversion. 41 + * 3) After the conversion is done TSC200X drives DAV line down. 42 + * 4) GPIO IRQ is received and tsc200x_irq_thread() is scheduled. 43 + * 5) tsc200x_irq_thread() queues up a transfer to fetch the x, y, z1, z2 44 + * values. 45 + * 6) tsc200x_irq_thread() reports coordinates to input layer and sets up 46 + * tsc200x_penup_timer() to be called after TSC200X_PENUP_TIME_MS (40ms). 47 + * 7) When the penup timer expires, there have not been touch or DAV interrupts 48 + * during the last 40ms which means the pen has been lifted. 49 + * 50 + * ESD recovery via a hardware reset is done if the TSC200X doesn't respond 51 + * after a configurable period (in ms) of activity. If esd_timeout is 0, the 52 + * watchdog is disabled. 53 + */ 54 + 55 + static const struct regmap_range tsc200x_writable_ranges[] = { 56 + regmap_reg_range(TSC200X_REG_AUX_HIGH, TSC200X_REG_CFR2), 57 + }; 58 + 59 + static const struct regmap_access_table tsc200x_writable_table = { 60 + .yes_ranges = tsc200x_writable_ranges, 61 + .n_yes_ranges = ARRAY_SIZE(tsc200x_writable_ranges), 62 + }; 63 + 64 + const struct regmap_config tsc200x_regmap_config = { 65 + .reg_bits = 8, 66 + .val_bits = 16, 67 + .reg_stride = 0x08, 68 + .max_register = 0x78, 69 + .read_flag_mask = TSC200X_REG_READ, 70 + .write_flag_mask = TSC200X_REG_PND0, 71 + .wr_table = &tsc200x_writable_table, 72 + .use_single_rw = true, 73 + }; 74 + EXPORT_SYMBOL_GPL(tsc200x_regmap_config); 75 + 76 + struct tsc200x_data { 77 + u16 x; 78 + u16 y; 79 + u16 z1; 80 + u16 z2; 81 + } __packed; 82 + #define TSC200X_DATA_REGS 4 83 + 84 + struct tsc200x { 85 + struct device *dev; 86 + struct regmap *regmap; 87 + __u16 bustype; 88 + 89 + struct input_dev *idev; 90 + char phys[32]; 91 + 92 + struct mutex mutex; 93 + 94 + /* raw copy of previous x,y,z */ 95 + int in_x; 96 + int in_y; 97 + int in_z1; 98 + int in_z2; 99 + 100 + spinlock_t lock; 101 + struct timer_list penup_timer; 102 + 103 + unsigned int esd_timeout; 104 + struct delayed_work esd_work; 105 + unsigned long last_valid_interrupt; 106 + 107 + unsigned int x_plate_ohm; 108 + 109 + bool opened; 110 + bool suspended; 111 + 112 + bool pen_down; 113 + 114 + struct regulator *vio; 115 + 116 + struct gpio_desc *reset_gpio; 117 + void (*set_reset)(bool enable); 118 + int (*tsc200x_cmd)(struct device *dev, u8 cmd); 119 + int irq; 120 + }; 121 + 122 + static void tsc200x_update_pen_state(struct tsc200x *ts, 123 + int x, int y, int pressure) 124 + { 125 + if (pressure) { 126 + input_report_abs(ts->idev, ABS_X, x); 127 + input_report_abs(ts->idev, ABS_Y, y); 128 + input_report_abs(ts->idev, ABS_PRESSURE, pressure); 129 + if (!ts->pen_down) { 130 + input_report_key(ts->idev, BTN_TOUCH, !!pressure); 131 + ts->pen_down = true; 132 + } 133 + } else { 134 + input_report_abs(ts->idev, ABS_PRESSURE, 0); 135 + if (ts->pen_down) { 136 + input_report_key(ts->idev, BTN_TOUCH, 0); 137 + ts->pen_down = false; 138 + } 139 + } 140 + input_sync(ts->idev); 141 + dev_dbg(ts->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, 142 + pressure); 143 + } 144 + 145 + static irqreturn_t tsc200x_irq_thread(int irq, void *_ts) 146 + { 147 + struct tsc200x *ts = _ts; 148 + unsigned long flags; 149 + unsigned int pressure; 150 + struct tsc200x_data tsdata; 151 + int error; 152 + 153 + /* read the coordinates */ 154 + error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata, 155 + TSC200X_DATA_REGS); 156 + if (unlikely(error)) 157 + goto out; 158 + 159 + /* validate position */ 160 + if (unlikely(tsdata.x > MAX_12BIT || tsdata.y > MAX_12BIT)) 161 + goto out; 162 + 163 + /* Skip reading if the pressure components are out of range */ 164 + if (unlikely(tsdata.z1 == 0 || tsdata.z2 > MAX_12BIT)) 165 + goto out; 166 + if (unlikely(tsdata.z1 >= tsdata.z2)) 167 + goto out; 168 + 169 + /* 170 + * Skip point if this is a pen down with the exact same values as 171 + * the value before pen-up - that implies SPI fed us stale data 172 + */ 173 + if (!ts->pen_down && 174 + ts->in_x == tsdata.x && ts->in_y == tsdata.y && 175 + ts->in_z1 == tsdata.z1 && ts->in_z2 == tsdata.z2) { 176 + goto out; 177 + } 178 + 179 + /* 180 + * At this point we are happy we have a valid and useful reading. 181 + * Remember it for later comparisons. We may now begin downsampling. 182 + */ 183 + ts->in_x = tsdata.x; 184 + ts->in_y = tsdata.y; 185 + ts->in_z1 = tsdata.z1; 186 + ts->in_z2 = tsdata.z2; 187 + 188 + /* Compute touch pressure resistance using equation #1 */ 189 + pressure = tsdata.x * (tsdata.z2 - tsdata.z1) / tsdata.z1; 190 + pressure = pressure * ts->x_plate_ohm / 4096; 191 + if (unlikely(pressure > MAX_12BIT)) 192 + goto out; 193 + 194 + spin_lock_irqsave(&ts->lock, flags); 195 + 196 + tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); 197 + mod_timer(&ts->penup_timer, 198 + jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS)); 199 + 200 + spin_unlock_irqrestore(&ts->lock, flags); 201 + 202 + ts->last_valid_interrupt = jiffies; 203 + out: 204 + return IRQ_HANDLED; 205 + } 206 + 207 + static void tsc200x_penup_timer(unsigned long data) 208 + { 209 + struct tsc200x *ts = (struct tsc200x *)data; 210 + unsigned long flags; 211 + 212 + spin_lock_irqsave(&ts->lock, flags); 213 + tsc200x_update_pen_state(ts, 0, 0, 0); 214 + spin_unlock_irqrestore(&ts->lock, flags); 215 + } 216 + 217 + static void tsc200x_start_scan(struct tsc200x *ts) 218 + { 219 + regmap_write(ts->regmap, TSC200X_REG_CFR0, TSC200X_CFR0_INITVALUE); 220 + regmap_write(ts->regmap, TSC200X_REG_CFR1, TSC200X_CFR1_INITVALUE); 221 + regmap_write(ts->regmap, TSC200X_REG_CFR2, TSC200X_CFR2_INITVALUE); 222 + ts->tsc200x_cmd(ts->dev, TSC200X_CMD_NORMAL); 223 + } 224 + 225 + static void tsc200x_stop_scan(struct tsc200x *ts) 226 + { 227 + ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); 228 + } 229 + 230 + static void tsc200x_set_reset(struct tsc200x *ts, bool enable) 231 + { 232 + if (ts->reset_gpio) 233 + gpiod_set_value_cansleep(ts->reset_gpio, enable); 234 + else if (ts->set_reset) 235 + ts->set_reset(enable); 236 + } 237 + 238 + /* must be called with ts->mutex held */ 239 + static void __tsc200x_disable(struct tsc200x *ts) 240 + { 241 + tsc200x_stop_scan(ts); 242 + 243 + disable_irq(ts->irq); 244 + del_timer_sync(&ts->penup_timer); 245 + 246 + cancel_delayed_work_sync(&ts->esd_work); 247 + 248 + enable_irq(ts->irq); 249 + } 250 + 251 + /* must be called with ts->mutex held */ 252 + static void __tsc200x_enable(struct tsc200x *ts) 253 + { 254 + tsc200x_start_scan(ts); 255 + 256 + if (ts->esd_timeout && (ts->set_reset || ts->reset_gpio)) { 257 + ts->last_valid_interrupt = jiffies; 258 + schedule_delayed_work(&ts->esd_work, 259 + round_jiffies_relative( 260 + msecs_to_jiffies(ts->esd_timeout))); 261 + } 262 + } 263 + 264 + static ssize_t tsc200x_selftest_show(struct device *dev, 265 + struct device_attribute *attr, 266 + char *buf) 267 + { 268 + struct tsc200x *ts = dev_get_drvdata(dev); 269 + unsigned int temp_high; 270 + unsigned int temp_high_orig; 271 + unsigned int temp_high_test; 272 + bool success = true; 273 + int error; 274 + 275 + mutex_lock(&ts->mutex); 276 + 277 + /* 278 + * Test TSC200X communications via temp high register. 279 + */ 280 + __tsc200x_disable(ts); 281 + 282 + error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig); 283 + if (error) { 284 + dev_warn(dev, "selftest failed: read error %d\n", error); 285 + success = false; 286 + goto out; 287 + } 288 + 289 + temp_high_test = (temp_high_orig - 1) & MAX_12BIT; 290 + 291 + error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test); 292 + if (error) { 293 + dev_warn(dev, "selftest failed: write error %d\n", error); 294 + success = false; 295 + goto out; 296 + } 297 + 298 + error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); 299 + if (error) { 300 + dev_warn(dev, "selftest failed: read error %d after write\n", 301 + error); 302 + success = false; 303 + goto out; 304 + } 305 + 306 + if (temp_high != temp_high_test) { 307 + dev_warn(dev, "selftest failed: %d != %d\n", 308 + temp_high, temp_high_test); 309 + success = false; 310 + } 311 + 312 + /* hardware reset */ 313 + tsc200x_set_reset(ts, false); 314 + usleep_range(100, 500); /* only 10us required */ 315 + tsc200x_set_reset(ts, true); 316 + 317 + if (!success) 318 + goto out; 319 + 320 + /* test that the reset really happened */ 321 + error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); 322 + if (error) { 323 + dev_warn(dev, "selftest failed: read error %d after reset\n", 324 + error); 325 + success = false; 326 + goto out; 327 + } 328 + 329 + if (temp_high != temp_high_orig) { 330 + dev_warn(dev, "selftest failed after reset: %d != %d\n", 331 + temp_high, temp_high_orig); 332 + success = false; 333 + } 334 + 335 + out: 336 + __tsc200x_enable(ts); 337 + mutex_unlock(&ts->mutex); 338 + 339 + return sprintf(buf, "%d\n", success); 340 + } 341 + 342 + static DEVICE_ATTR(selftest, S_IRUGO, tsc200x_selftest_show, NULL); 343 + 344 + static struct attribute *tsc200x_attrs[] = { 345 + &dev_attr_selftest.attr, 346 + NULL 347 + }; 348 + 349 + static umode_t tsc200x_attr_is_visible(struct kobject *kobj, 350 + struct attribute *attr, int n) 351 + { 352 + struct device *dev = container_of(kobj, struct device, kobj); 353 + struct tsc200x *ts = dev_get_drvdata(dev); 354 + umode_t mode = attr->mode; 355 + 356 + if (attr == &dev_attr_selftest.attr) { 357 + if (!ts->set_reset && !ts->reset_gpio) 358 + mode = 0; 359 + } 360 + 361 + return mode; 362 + } 363 + 364 + static const struct attribute_group tsc200x_attr_group = { 365 + .is_visible = tsc200x_attr_is_visible, 366 + .attrs = tsc200x_attrs, 367 + }; 368 + 369 + static void tsc200x_esd_work(struct work_struct *work) 370 + { 371 + struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work); 372 + int error; 373 + unsigned int r; 374 + 375 + if (!mutex_trylock(&ts->mutex)) { 376 + /* 377 + * If the mutex is taken, it means that disable or enable is in 378 + * progress. In that case just reschedule the work. If the work 379 + * is not needed, it will be canceled by disable. 380 + */ 381 + goto reschedule; 382 + } 383 + 384 + if (time_is_after_jiffies(ts->last_valid_interrupt + 385 + msecs_to_jiffies(ts->esd_timeout))) 386 + goto out; 387 + 388 + /* We should be able to read register without disabling interrupts. */ 389 + error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); 390 + if (!error && 391 + !((r ^ TSC200X_CFR0_INITVALUE) & TSC200X_CFR0_RW_MASK)) { 392 + goto out; 393 + } 394 + 395 + /* 396 + * If we could not read our known value from configuration register 0 397 + * then we should reset the controller as if from power-up and start 398 + * scanning again. 399 + */ 400 + dev_info(ts->dev, "TSC200X not responding - resetting\n"); 401 + 402 + disable_irq(ts->irq); 403 + del_timer_sync(&ts->penup_timer); 404 + 405 + tsc200x_update_pen_state(ts, 0, 0, 0); 406 + 407 + tsc200x_set_reset(ts, false); 408 + usleep_range(100, 500); /* only 10us required */ 409 + tsc200x_set_reset(ts, true); 410 + 411 + enable_irq(ts->irq); 412 + tsc200x_start_scan(ts); 413 + 414 + out: 415 + mutex_unlock(&ts->mutex); 416 + reschedule: 417 + /* re-arm the watchdog */ 418 + schedule_delayed_work(&ts->esd_work, 419 + round_jiffies_relative( 420 + msecs_to_jiffies(ts->esd_timeout))); 421 + } 422 + 423 + static int tsc200x_open(struct input_dev *input) 424 + { 425 + struct tsc200x *ts = input_get_drvdata(input); 426 + 427 + mutex_lock(&ts->mutex); 428 + 429 + if (!ts->suspended) 430 + __tsc200x_enable(ts); 431 + 432 + ts->opened = true; 433 + 434 + mutex_unlock(&ts->mutex); 435 + 436 + return 0; 437 + } 438 + 439 + static void tsc200x_close(struct input_dev *input) 440 + { 441 + struct tsc200x *ts = input_get_drvdata(input); 442 + 443 + mutex_lock(&ts->mutex); 444 + 445 + if (!ts->suspended) 446 + __tsc200x_disable(ts); 447 + 448 + ts->opened = false; 449 + 450 + mutex_unlock(&ts->mutex); 451 + } 452 + 453 + int tsc200x_probe(struct device *dev, int irq, __u16 bustype, 454 + struct regmap *regmap, 455 + int (*tsc200x_cmd)(struct device *dev, u8 cmd)) 456 + { 457 + const struct tsc2005_platform_data *pdata = dev_get_platdata(dev); 458 + struct device_node *np = dev->of_node; 459 + 460 + struct tsc200x *ts; 461 + struct input_dev *input_dev; 462 + unsigned int max_x = MAX_12BIT; 463 + unsigned int max_y = MAX_12BIT; 464 + unsigned int max_p = MAX_12BIT; 465 + unsigned int fudge_x = TSC200X_DEF_X_FUZZ; 466 + unsigned int fudge_y = TSC200X_DEF_Y_FUZZ; 467 + unsigned int fudge_p = TSC200X_DEF_P_FUZZ; 468 + unsigned int x_plate_ohm = TSC200X_DEF_RESISTOR; 469 + unsigned int esd_timeout; 470 + int error; 471 + 472 + if (!np && !pdata) { 473 + dev_err(dev, "no platform data\n"); 474 + return -ENODEV; 475 + } 476 + 477 + if (irq <= 0) { 478 + dev_err(dev, "no irq\n"); 479 + return -ENODEV; 480 + } 481 + 482 + if (IS_ERR(regmap)) 483 + return PTR_ERR(regmap); 484 + 485 + if (!tsc200x_cmd) { 486 + dev_err(dev, "no cmd function\n"); 487 + return -ENODEV; 488 + } 489 + 490 + if (pdata) { 491 + fudge_x = pdata->ts_x_fudge; 492 + fudge_y = pdata->ts_y_fudge; 493 + fudge_p = pdata->ts_pressure_fudge; 494 + max_x = pdata->ts_x_max; 495 + max_y = pdata->ts_y_max; 496 + max_p = pdata->ts_pressure_max; 497 + x_plate_ohm = pdata->ts_x_plate_ohm; 498 + esd_timeout = pdata->esd_timeout_ms; 499 + } else { 500 + x_plate_ohm = TSC200X_DEF_RESISTOR; 501 + of_property_read_u32(np, "ti,x-plate-ohms", &x_plate_ohm); 502 + esd_timeout = 0; 503 + of_property_read_u32(np, "ti,esd-recovery-timeout-ms", 504 + &esd_timeout); 505 + } 506 + 507 + ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); 508 + if (!ts) 509 + return -ENOMEM; 510 + 511 + input_dev = devm_input_allocate_device(dev); 512 + if (!input_dev) 513 + return -ENOMEM; 514 + 515 + ts->irq = irq; 516 + ts->dev = dev; 517 + ts->idev = input_dev; 518 + ts->regmap = regmap; 519 + ts->tsc200x_cmd = tsc200x_cmd; 520 + ts->x_plate_ohm = x_plate_ohm; 521 + ts->esd_timeout = esd_timeout; 522 + 523 + ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 524 + if (IS_ERR(ts->reset_gpio)) { 525 + error = PTR_ERR(ts->reset_gpio); 526 + dev_err(dev, "error acquiring reset gpio: %d\n", error); 527 + return error; 528 + } 529 + 530 + ts->vio = devm_regulator_get_optional(dev, "vio"); 531 + if (IS_ERR(ts->vio)) { 532 + error = PTR_ERR(ts->vio); 533 + dev_err(dev, "vio regulator missing (%d)", error); 534 + return error; 535 + } 536 + 537 + if (!ts->reset_gpio && pdata) 538 + ts->set_reset = pdata->set_reset; 539 + 540 + mutex_init(&ts->mutex); 541 + 542 + spin_lock_init(&ts->lock); 543 + setup_timer(&ts->penup_timer, tsc200x_penup_timer, (unsigned long)ts); 544 + 545 + INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work); 546 + 547 + snprintf(ts->phys, sizeof(ts->phys), 548 + "%s/input-ts", dev_name(dev)); 549 + 550 + input_dev->name = "TSC200X touchscreen"; 551 + input_dev->phys = ts->phys; 552 + input_dev->id.bustype = bustype; 553 + input_dev->dev.parent = dev; 554 + input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); 555 + input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 556 + 557 + input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0); 558 + input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0); 559 + input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0); 560 + 561 + if (np) 562 + touchscreen_parse_properties(input_dev, false); 563 + 564 + input_dev->open = tsc200x_open; 565 + input_dev->close = tsc200x_close; 566 + 567 + input_set_drvdata(input_dev, ts); 568 + 569 + /* Ensure the touchscreen is off */ 570 + tsc200x_stop_scan(ts); 571 + 572 + error = devm_request_threaded_irq(dev, irq, NULL, 573 + tsc200x_irq_thread, 574 + IRQF_TRIGGER_RISING | IRQF_ONESHOT, 575 + "tsc200x", ts); 576 + if (error) { 577 + dev_err(dev, "Failed to request irq, err: %d\n", error); 578 + return error; 579 + } 580 + 581 + /* enable regulator for DT */ 582 + if (ts->vio) { 583 + error = regulator_enable(ts->vio); 584 + if (error) 585 + return error; 586 + } 587 + 588 + dev_set_drvdata(dev, ts); 589 + error = sysfs_create_group(&dev->kobj, &tsc200x_attr_group); 590 + if (error) { 591 + dev_err(dev, 592 + "Failed to create sysfs attributes, err: %d\n", error); 593 + goto disable_regulator; 594 + } 595 + 596 + error = input_register_device(ts->idev); 597 + if (error) { 598 + dev_err(dev, 599 + "Failed to register input device, err: %d\n", error); 600 + goto err_remove_sysfs; 601 + } 602 + 603 + irq_set_irq_wake(irq, 1); 604 + return 0; 605 + 606 + err_remove_sysfs: 607 + sysfs_remove_group(&dev->kobj, &tsc200x_attr_group); 608 + disable_regulator: 609 + if (ts->vio) 610 + regulator_disable(ts->vio); 611 + return error; 612 + } 613 + EXPORT_SYMBOL_GPL(tsc200x_probe); 614 + 615 + int tsc200x_remove(struct device *dev) 616 + { 617 + struct tsc200x *ts = dev_get_drvdata(dev); 618 + 619 + sysfs_remove_group(&dev->kobj, &tsc200x_attr_group); 620 + 621 + if (ts->vio) 622 + regulator_disable(ts->vio); 623 + 624 + return 0; 625 + } 626 + EXPORT_SYMBOL_GPL(tsc200x_remove); 627 + 628 + static int __maybe_unused tsc200x_suspend(struct device *dev) 629 + { 630 + struct tsc200x *ts = dev_get_drvdata(dev); 631 + 632 + mutex_lock(&ts->mutex); 633 + 634 + if (!ts->suspended && ts->opened) 635 + __tsc200x_disable(ts); 636 + 637 + ts->suspended = true; 638 + 639 + mutex_unlock(&ts->mutex); 640 + 641 + return 0; 642 + } 643 + 644 + static int __maybe_unused tsc200x_resume(struct device *dev) 645 + { 646 + struct tsc200x *ts = dev_get_drvdata(dev); 647 + 648 + mutex_lock(&ts->mutex); 649 + 650 + if (ts->suspended && ts->opened) 651 + __tsc200x_enable(ts); 652 + 653 + ts->suspended = false; 654 + 655 + mutex_unlock(&ts->mutex); 656 + 657 + return 0; 658 + } 659 + 660 + SIMPLE_DEV_PM_OPS(tsc200x_pm_ops, tsc200x_suspend, tsc200x_resume); 661 + EXPORT_SYMBOL_GPL(tsc200x_pm_ops); 662 + 663 + MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>"); 664 + MODULE_DESCRIPTION("TSC200x Touchscreen Driver Core"); 665 + MODULE_LICENSE("GPL");
+78
drivers/input/touchscreen/tsc200x-core.h
··· 1 + #ifndef _TSC200X_CORE_H 2 + #define _TSC200X_CORE_H 3 + 4 + /* control byte 1 */ 5 + #define TSC200X_CMD 0x80 6 + #define TSC200X_CMD_NORMAL 0x00 7 + #define TSC200X_CMD_STOP 0x01 8 + #define TSC200X_CMD_12BIT 0x04 9 + 10 + /* control byte 0 */ 11 + #define TSC200X_REG_READ 0x01 /* R/W access */ 12 + #define TSC200X_REG_PND0 0x02 /* Power Not Down Control */ 13 + #define TSC200X_REG_X (0x0 << 3) 14 + #define TSC200X_REG_Y (0x1 << 3) 15 + #define TSC200X_REG_Z1 (0x2 << 3) 16 + #define TSC200X_REG_Z2 (0x3 << 3) 17 + #define TSC200X_REG_AUX (0x4 << 3) 18 + #define TSC200X_REG_TEMP1 (0x5 << 3) 19 + #define TSC200X_REG_TEMP2 (0x6 << 3) 20 + #define TSC200X_REG_STATUS (0x7 << 3) 21 + #define TSC200X_REG_AUX_HIGH (0x8 << 3) 22 + #define TSC200X_REG_AUX_LOW (0x9 << 3) 23 + #define TSC200X_REG_TEMP_HIGH (0xA << 3) 24 + #define TSC200X_REG_TEMP_LOW (0xB << 3) 25 + #define TSC200X_REG_CFR0 (0xC << 3) 26 + #define TSC200X_REG_CFR1 (0xD << 3) 27 + #define TSC200X_REG_CFR2 (0xE << 3) 28 + #define TSC200X_REG_CONV_FUNC (0xF << 3) 29 + 30 + /* configuration register 0 */ 31 + #define TSC200X_CFR0_PRECHARGE_276US 0x0040 32 + #define TSC200X_CFR0_STABTIME_1MS 0x0300 33 + #define TSC200X_CFR0_CLOCK_1MHZ 0x1000 34 + #define TSC200X_CFR0_RESOLUTION12 0x2000 35 + #define TSC200X_CFR0_PENMODE 0x8000 36 + #define TSC200X_CFR0_INITVALUE (TSC200X_CFR0_STABTIME_1MS | \ 37 + TSC200X_CFR0_CLOCK_1MHZ | \ 38 + TSC200X_CFR0_RESOLUTION12 | \ 39 + TSC200X_CFR0_PRECHARGE_276US | \ 40 + TSC200X_CFR0_PENMODE) 41 + 42 + /* bits common to both read and write of configuration register 0 */ 43 + #define TSC200X_CFR0_RW_MASK 0x3fff 44 + 45 + /* configuration register 1 */ 46 + #define TSC200X_CFR1_BATCHDELAY_4MS 0x0003 47 + #define TSC200X_CFR1_INITVALUE TSC200X_CFR1_BATCHDELAY_4MS 48 + 49 + /* configuration register 2 */ 50 + #define TSC200X_CFR2_MAVE_Z 0x0004 51 + #define TSC200X_CFR2_MAVE_Y 0x0008 52 + #define TSC200X_CFR2_MAVE_X 0x0010 53 + #define TSC200X_CFR2_AVG_7 0x0800 54 + #define TSC200X_CFR2_MEDIUM_15 0x3000 55 + #define TSC200X_CFR2_INITVALUE (TSC200X_CFR2_MAVE_X | \ 56 + TSC200X_CFR2_MAVE_Y | \ 57 + TSC200X_CFR2_MAVE_Z | \ 58 + TSC200X_CFR2_MEDIUM_15 | \ 59 + TSC200X_CFR2_AVG_7) 60 + 61 + #define MAX_12BIT 0xfff 62 + #define TSC200X_DEF_X_FUZZ 4 63 + #define TSC200X_DEF_Y_FUZZ 8 64 + #define TSC200X_DEF_P_FUZZ 2 65 + #define TSC200X_DEF_RESISTOR 280 66 + 67 + #define TSC2005_SPI_MAX_SPEED_HZ 10000000 68 + #define TSC200X_PENUP_TIME_MS 40 69 + 70 + extern const struct regmap_config tsc200x_regmap_config; 71 + extern const struct dev_pm_ops tsc200x_pm_ops; 72 + 73 + int tsc200x_probe(struct device *dev, int irq, __u16 bustype, 74 + struct regmap *regmap, 75 + int (*tsc200x_cmd)(struct device *dev, u8 cmd)); 76 + int tsc200x_remove(struct device *dev); 77 + 78 + #endif