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

Merge branch 'tsc2007' into next

Bring in TSC2007 improvements.

+286 -71
+10
drivers/input/touchscreen/Kconfig
··· 1025 1025 To compile this driver as a module, choose M here: the 1026 1026 module will be called tsc2007. 1027 1027 1028 + config TOUCHSCREEN_TSC2007_IIO 1029 + bool "IIO interface for external ADC input and temperature" 1030 + depends on TOUCHSCREEN_TSC2007 1031 + depends on IIO=y || IIO=TOUCHSCREEN_TSC2007 1032 + help 1033 + Saying Y here adds an iio interface to the tsc2007 which 1034 + provides values for the AUX input (used for e.g. battery 1035 + or ambient light monitoring), temperature and raw input 1036 + values. 1037 + 1028 1038 config TOUCHSCREEN_W90X900 1029 1039 tristate "W90P910 touchscreen driver" 1030 1040 depends on ARCH_W90X900
+2
drivers/input/touchscreen/Makefile
··· 79 79 obj-$(CONFIG_TOUCHSCREEN_TSC200X_CORE) += tsc200x-core.o 80 80 obj-$(CONFIG_TOUCHSCREEN_TSC2004) += tsc2004.o 81 81 obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o 82 + tsc2007-y := tsc2007_core.o 83 + tsc2007-$(CONFIG_TOUCHSCREEN_TSC2007_IIO) += tsc2007_iio.o 82 84 obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o 83 85 obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o 84 86 obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o
+33 -71
drivers/input/touchscreen/tsc2007.c drivers/input/touchscreen/tsc2007_core.c
··· 27 27 #include <linux/i2c.h> 28 28 #include <linux/i2c/tsc2007.h> 29 29 #include <linux/of_device.h> 30 - #include <linux/of.h> 31 30 #include <linux/of_gpio.h> 31 + #include "tsc2007.h" 32 32 33 - #define TSC2007_MEASURE_TEMP0 (0x0 << 4) 34 - #define TSC2007_MEASURE_AUX (0x2 << 4) 35 - #define TSC2007_MEASURE_TEMP1 (0x4 << 4) 36 - #define TSC2007_ACTIVATE_XN (0x8 << 4) 37 - #define TSC2007_ACTIVATE_YN (0x9 << 4) 38 - #define TSC2007_ACTIVATE_YP_XN (0xa << 4) 39 - #define TSC2007_SETUP (0xb << 4) 40 - #define TSC2007_MEASURE_X (0xc << 4) 41 - #define TSC2007_MEASURE_Y (0xd << 4) 42 - #define TSC2007_MEASURE_Z1 (0xe << 4) 43 - #define TSC2007_MEASURE_Z2 (0xf << 4) 44 - 45 - #define TSC2007_POWER_OFF_IRQ_EN (0x0 << 2) 46 - #define TSC2007_ADC_ON_IRQ_DIS0 (0x1 << 2) 47 - #define TSC2007_ADC_OFF_IRQ_EN (0x2 << 2) 48 - #define TSC2007_ADC_ON_IRQ_DIS1 (0x3 << 2) 49 - 50 - #define TSC2007_12BIT (0x0 << 1) 51 - #define TSC2007_8BIT (0x1 << 1) 52 - 53 - #define MAX_12BIT ((1 << 12) - 1) 54 - 55 - #define ADC_ON_12BIT (TSC2007_12BIT | TSC2007_ADC_ON_IRQ_DIS0) 56 - 57 - #define READ_Y (ADC_ON_12BIT | TSC2007_MEASURE_Y) 58 - #define READ_Z1 (ADC_ON_12BIT | TSC2007_MEASURE_Z1) 59 - #define READ_Z2 (ADC_ON_12BIT | TSC2007_MEASURE_Z2) 60 - #define READ_X (ADC_ON_12BIT | TSC2007_MEASURE_X) 61 - #define PWRDOWN (TSC2007_12BIT | TSC2007_POWER_OFF_IRQ_EN) 62 - 63 - struct ts_event { 64 - u16 x; 65 - u16 y; 66 - u16 z1, z2; 67 - }; 68 - 69 - struct tsc2007 { 70 - struct input_dev *input; 71 - char phys[32]; 72 - 73 - struct i2c_client *client; 74 - 75 - u16 model; 76 - u16 x_plate_ohms; 77 - u16 max_rt; 78 - unsigned long poll_period; /* in jiffies */ 79 - int fuzzx; 80 - int fuzzy; 81 - int fuzzz; 82 - 83 - unsigned gpio; 84 - int irq; 85 - 86 - wait_queue_head_t wait; 87 - bool stopped; 88 - 89 - int (*get_pendown_state)(struct device *); 90 - void (*clear_penirq)(void); 91 - }; 92 - 93 - static inline int tsc2007_xfer(struct tsc2007 *tsc, u8 cmd) 33 + int tsc2007_xfer(struct tsc2007 *tsc, u8 cmd) 94 34 { 95 35 s32 data; 96 36 u16 val; ··· 68 128 tsc2007_xfer(tsc, PWRDOWN); 69 129 } 70 130 71 - static u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc) 131 + u32 tsc2007_calculate_resistance(struct tsc2007 *tsc, struct ts_event *tc) 72 132 { 73 133 u32 rt = 0; 74 134 ··· 77 137 tc->x = 0; 78 138 79 139 if (likely(tc->x && tc->z1)) { 80 - /* compute touch pressure resistance using equation #1 */ 140 + /* compute touch resistance using equation #1 */ 81 141 rt = tc->z2 - tc->z1; 82 142 rt *= tc->x; 83 143 rt *= tsc->x_plate_ohms; ··· 88 148 return rt; 89 149 } 90 150 91 - static bool tsc2007_is_pen_down(struct tsc2007 *ts) 151 + bool tsc2007_is_pen_down(struct tsc2007 *ts) 92 152 { 93 153 /* 94 154 * NOTE: We can't rely on the pressure to determine the pen down ··· 120 180 while (!ts->stopped && tsc2007_is_pen_down(ts)) { 121 181 122 182 /* pen is down, continue with the measurement */ 123 - tsc2007_read_values(ts, &tc); 124 183 125 - rt = tsc2007_calculate_pressure(ts, &tc); 184 + mutex_lock(&ts->mlock); 185 + tsc2007_read_values(ts, &tc); 186 + mutex_unlock(&ts->mlock); 187 + 188 + rt = tsc2007_calculate_resistance(ts, &tc); 126 189 127 190 if (!rt && !ts->get_pendown_state) { 128 191 /* ··· 138 195 139 196 if (rt <= ts->max_rt) { 140 197 dev_dbg(&ts->client->dev, 141 - "DOWN point(%4d,%4d), pressure (%4u)\n", 198 + "DOWN point(%4d,%4d), resistance (%4u)\n", 142 199 tc.x, tc.y, rt); 200 + 201 + rt = ts->max_rt - rt; 143 202 144 203 input_report_key(input, BTN_TOUCH, 1); 145 204 input_report_abs(input, ABS_X, tc.x); ··· 320 375 static int tsc2007_probe(struct i2c_client *client, 321 376 const struct i2c_device_id *id) 322 377 { 323 - const struct tsc2007_platform_data *pdata = dev_get_platdata(&client->dev); 378 + const struct tsc2007_platform_data *pdata = 379 + dev_get_platdata(&client->dev); 324 380 struct tsc2007 *ts; 325 381 struct input_dev *input_dev; 326 382 int err; ··· 350 404 ts->client = client; 351 405 ts->irq = client->irq; 352 406 ts->input = input_dev; 407 + 353 408 init_waitqueue_head(&ts->wait); 409 + mutex_init(&ts->mlock); 354 410 355 411 snprintf(ts->phys, sizeof(ts->phys), 356 412 "%s/input0", dev_name(&client->dev)); ··· 366 418 367 419 input_set_drvdata(input_dev, ts); 368 420 369 - input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 370 - input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 421 + input_set_capability(input_dev, EV_KEY, BTN_TOUCH); 371 422 372 423 input_set_abs_params(input_dev, ABS_X, 0, MAX_12BIT, ts->fuzzx, 0); 373 424 input_set_abs_params(input_dev, ABS_Y, 0, MAX_12BIT, ts->fuzzy, 0); ··· 402 455 403 456 tsc2007_stop(ts); 404 457 458 + /* power down the chip (TSC2007_SETUP does not ACK on I2C) */ 459 + err = tsc2007_xfer(ts, PWRDOWN); 460 + if (err < 0) { 461 + dev_err(&client->dev, 462 + "Failed to setup chip: %d\n", err); 463 + return err; /* chip does not respond */ 464 + } 465 + 405 466 err = input_register_device(input_dev); 406 467 if (err) { 407 468 dev_err(&client->dev, 408 469 "Failed to register input device: %d\n", err); 470 + return err; 471 + } 472 + 473 + err = tsc2007_iio_configure(ts); 474 + if (err) { 475 + dev_err(&client->dev, 476 + "Failed to register with IIO: %d\n", err); 409 477 return err; 410 478 } 411 479
+101
drivers/input/touchscreen/tsc2007.h
··· 1 + 2 + /* 3 + * Copyright (c) 2008 MtekVision Co., Ltd. 4 + * Kwangwoo Lee <kwlee@mtekvision.com> 5 + * 6 + * Using code from: 7 + * - ads7846.c 8 + * Copyright (c) 2005 David Brownell 9 + * Copyright (c) 2006 Nokia Corporation 10 + * - corgi_ts.c 11 + * Copyright (C) 2004-2005 Richard Purdie 12 + * - omap_ts.[hc], ads7846.h, ts_osk.c 13 + * Copyright (C) 2002 MontaVista Software 14 + * Copyright (C) 2004 Texas Instruments 15 + * Copyright (C) 2005 Dirk Behme 16 + * 17 + * This program is free software; you can redistribute it and/or modify 18 + * it under the terms of the GNU General Public License version 2 as 19 + * published by the Free Software Foundation. 20 + */ 21 + 22 + #ifndef _TSC2007_H 23 + #define _TSC2007_H 24 + 25 + #define TSC2007_MEASURE_TEMP0 (0x0 << 4) 26 + #define TSC2007_MEASURE_AUX (0x2 << 4) 27 + #define TSC2007_MEASURE_TEMP1 (0x4 << 4) 28 + #define TSC2007_ACTIVATE_XN (0x8 << 4) 29 + #define TSC2007_ACTIVATE_YN (0x9 << 4) 30 + #define TSC2007_ACTIVATE_YP_XN (0xa << 4) 31 + #define TSC2007_SETUP (0xb << 4) 32 + #define TSC2007_MEASURE_X (0xc << 4) 33 + #define TSC2007_MEASURE_Y (0xd << 4) 34 + #define TSC2007_MEASURE_Z1 (0xe << 4) 35 + #define TSC2007_MEASURE_Z2 (0xf << 4) 36 + 37 + #define TSC2007_POWER_OFF_IRQ_EN (0x0 << 2) 38 + #define TSC2007_ADC_ON_IRQ_DIS0 (0x1 << 2) 39 + #define TSC2007_ADC_OFF_IRQ_EN (0x2 << 2) 40 + #define TSC2007_ADC_ON_IRQ_DIS1 (0x3 << 2) 41 + 42 + #define TSC2007_12BIT (0x0 << 1) 43 + #define TSC2007_8BIT (0x1 << 1) 44 + 45 + #define MAX_12BIT ((1 << 12) - 1) 46 + 47 + #define ADC_ON_12BIT (TSC2007_12BIT | TSC2007_ADC_ON_IRQ_DIS0) 48 + 49 + #define READ_Y (ADC_ON_12BIT | TSC2007_MEASURE_Y) 50 + #define READ_Z1 (ADC_ON_12BIT | TSC2007_MEASURE_Z1) 51 + #define READ_Z2 (ADC_ON_12BIT | TSC2007_MEASURE_Z2) 52 + #define READ_X (ADC_ON_12BIT | TSC2007_MEASURE_X) 53 + #define PWRDOWN (TSC2007_12BIT | TSC2007_POWER_OFF_IRQ_EN) 54 + 55 + struct ts_event { 56 + u16 x; 57 + u16 y; 58 + u16 z1, z2; 59 + }; 60 + 61 + struct tsc2007 { 62 + struct input_dev *input; 63 + char phys[32]; 64 + 65 + struct i2c_client *client; 66 + 67 + u16 model; 68 + u16 x_plate_ohms; 69 + u16 max_rt; 70 + unsigned long poll_period; /* in jiffies */ 71 + int fuzzx; 72 + int fuzzy; 73 + int fuzzz; 74 + 75 + unsigned int gpio; 76 + int irq; 77 + 78 + wait_queue_head_t wait; 79 + bool stopped; 80 + 81 + int (*get_pendown_state)(struct device *); 82 + void (*clear_penirq)(void); 83 + 84 + struct mutex mlock; 85 + }; 86 + 87 + int tsc2007_xfer(struct tsc2007 *tsc, u8 cmd); 88 + u32 tsc2007_calculate_resistance(struct tsc2007 *tsc, struct ts_event *tc); 89 + bool tsc2007_is_pen_down(struct tsc2007 *ts); 90 + 91 + #if IS_ENABLED(CONFIG_TOUCHSCREEN_TSC2007_IIO) 92 + /* defined in tsc2007_iio.c */ 93 + int tsc2007_iio_configure(struct tsc2007 *ts); 94 + #else 95 + static inline int tsc2007_iio_configure(struct tsc2007 *ts) 96 + { 97 + return 0; 98 + } 99 + #endif /* CONFIG_TOUCHSCREEN_TSC2007_IIO */ 100 + 101 + #endif /* _TSC2007_H */
+140
drivers/input/touchscreen/tsc2007_iio.c
··· 1 + /* 2 + * Copyright (c) 2016 Golden Delicious Comp. GmbH&Co. KG 3 + * Nikolaus Schaller <hns@goldelico.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + */ 9 + 10 + #include <linux/i2c.h> 11 + #include <linux/iio/iio.h> 12 + #include "tsc2007.h" 13 + 14 + struct tsc2007_iio { 15 + struct tsc2007 *ts; 16 + }; 17 + 18 + #define TSC2007_CHAN_IIO(_chan, _name, _type, _chan_info) \ 19 + { \ 20 + .datasheet_name = _name, \ 21 + .type = _type, \ 22 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 23 + BIT(_chan_info), \ 24 + .indexed = 1, \ 25 + .channel = _chan, \ 26 + } 27 + 28 + static const struct iio_chan_spec tsc2007_iio_channel[] = { 29 + TSC2007_CHAN_IIO(0, "x", IIO_VOLTAGE, IIO_CHAN_INFO_RAW), 30 + TSC2007_CHAN_IIO(1, "y", IIO_VOLTAGE, IIO_CHAN_INFO_RAW), 31 + TSC2007_CHAN_IIO(2, "z1", IIO_VOLTAGE, IIO_CHAN_INFO_RAW), 32 + TSC2007_CHAN_IIO(3, "z2", IIO_VOLTAGE, IIO_CHAN_INFO_RAW), 33 + TSC2007_CHAN_IIO(4, "adc", IIO_VOLTAGE, IIO_CHAN_INFO_RAW), 34 + TSC2007_CHAN_IIO(5, "rt", IIO_VOLTAGE, IIO_CHAN_INFO_RAW), /* Ohms? */ 35 + TSC2007_CHAN_IIO(6, "pen", IIO_PRESSURE, IIO_CHAN_INFO_RAW), 36 + TSC2007_CHAN_IIO(7, "temp0", IIO_TEMP, IIO_CHAN_INFO_RAW), 37 + TSC2007_CHAN_IIO(8, "temp1", IIO_TEMP, IIO_CHAN_INFO_RAW), 38 + }; 39 + 40 + static int tsc2007_read_raw(struct iio_dev *indio_dev, 41 + struct iio_chan_spec const *chan, 42 + int *val, int *val2, long mask) 43 + { 44 + struct tsc2007_iio *iio = iio_priv(indio_dev); 45 + struct tsc2007 *tsc = iio->ts; 46 + int adc_chan = chan->channel; 47 + int ret = 0; 48 + 49 + if (adc_chan >= ARRAY_SIZE(tsc2007_iio_channel)) 50 + return -EINVAL; 51 + 52 + if (mask != IIO_CHAN_INFO_RAW) 53 + return -EINVAL; 54 + 55 + mutex_lock(&tsc->mlock); 56 + 57 + switch (chan->channel) { 58 + case 0: 59 + *val = tsc2007_xfer(tsc, READ_X); 60 + break; 61 + case 1: 62 + *val = tsc2007_xfer(tsc, READ_Y); 63 + break; 64 + case 2: 65 + *val = tsc2007_xfer(tsc, READ_Z1); 66 + break; 67 + case 3: 68 + *val = tsc2007_xfer(tsc, READ_Z2); 69 + break; 70 + case 4: 71 + *val = tsc2007_xfer(tsc, (ADC_ON_12BIT | TSC2007_MEASURE_AUX)); 72 + break; 73 + case 5: { 74 + struct ts_event tc; 75 + 76 + tc.x = tsc2007_xfer(tsc, READ_X); 77 + tc.z1 = tsc2007_xfer(tsc, READ_Z1); 78 + tc.z2 = tsc2007_xfer(tsc, READ_Z2); 79 + *val = tsc2007_calculate_resistance(tsc, &tc); 80 + break; 81 + } 82 + case 6: 83 + *val = tsc2007_is_pen_down(tsc); 84 + break; 85 + case 7: 86 + *val = tsc2007_xfer(tsc, 87 + (ADC_ON_12BIT | TSC2007_MEASURE_TEMP0)); 88 + break; 89 + case 8: 90 + *val = tsc2007_xfer(tsc, 91 + (ADC_ON_12BIT | TSC2007_MEASURE_TEMP1)); 92 + break; 93 + } 94 + 95 + /* Prepare for next touch reading - power down ADC, enable PENIRQ */ 96 + tsc2007_xfer(tsc, PWRDOWN); 97 + 98 + mutex_unlock(&tsc->mlock); 99 + 100 + ret = IIO_VAL_INT; 101 + 102 + return ret; 103 + } 104 + 105 + static const struct iio_info tsc2007_iio_info = { 106 + .read_raw = tsc2007_read_raw, 107 + .driver_module = THIS_MODULE, 108 + }; 109 + 110 + int tsc2007_iio_configure(struct tsc2007 *ts) 111 + { 112 + struct iio_dev *indio_dev; 113 + struct tsc2007_iio *iio; 114 + int error; 115 + 116 + indio_dev = devm_iio_device_alloc(&ts->client->dev, sizeof(*iio)); 117 + if (!indio_dev) { 118 + dev_err(&ts->client->dev, "iio_device_alloc failed\n"); 119 + return -ENOMEM; 120 + } 121 + 122 + iio = iio_priv(indio_dev); 123 + iio->ts = ts; 124 + 125 + indio_dev->name = "tsc2007"; 126 + indio_dev->dev.parent = &ts->client->dev; 127 + indio_dev->info = &tsc2007_iio_info; 128 + indio_dev->modes = INDIO_DIRECT_MODE; 129 + indio_dev->channels = tsc2007_iio_channel; 130 + indio_dev->num_channels = ARRAY_SIZE(tsc2007_iio_channel); 131 + 132 + error = devm_iio_device_register(&ts->client->dev, indio_dev); 133 + if (error) { 134 + dev_err(&ts->client->dev, 135 + "iio_device_register() failed: %d\n", error); 136 + return error; 137 + } 138 + 139 + return 0; 140 + }