23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/input.h>
27 #include <linux/i2c.h>
30 #define TSC2007_MEASURE_TEMP0 (0x0 << 4)
31 #define TSC2007_MEASURE_AUX (0x2 << 4)
32 #define TSC2007_MEASURE_TEMP1 (0x4 << 4)
33 #define TSC2007_ACTIVATE_XN (0x8 << 4)
34 #define TSC2007_ACTIVATE_YN (0x9 << 4)
35 #define TSC2007_ACTIVATE_YP_XN (0xa << 4)
36 #define TSC2007_SETUP (0xb << 4)
37 #define TSC2007_MEASURE_X (0xc << 4)
38 #define TSC2007_MEASURE_Y (0xd << 4)
39 #define TSC2007_MEASURE_Z1 (0xe << 4)
40 #define TSC2007_MEASURE_Z2 (0xf << 4)
42 #define TSC2007_POWER_OFF_IRQ_EN (0x0 << 2)
43 #define TSC2007_ADC_ON_IRQ_DIS0 (0x1 << 2)
44 #define TSC2007_ADC_OFF_IRQ_EN (0x2 << 2)
45 #define TSC2007_ADC_ON_IRQ_DIS1 (0x3 << 2)
47 #define TSC2007_12BIT (0x0 << 1)
48 #define TSC2007_8BIT (0x1 << 1)
50 #define MAX_12BIT ((1 << 12) - 1)
52 #define ADC_ON_12BIT (TSC2007_12BIT | TSC2007_ADC_ON_IRQ_DIS0)
54 #define READ_Y (ADC_ON_12BIT | TSC2007_MEASURE_Y)
55 #define READ_Z1 (ADC_ON_12BIT | TSC2007_MEASURE_Z1)
56 #define READ_Z2 (ADC_ON_12BIT | TSC2007_MEASURE_Z2)
57 #define READ_X (ADC_ON_12BIT | TSC2007_MEASURE_X)
58 #define PWRDOWN (TSC2007_12BIT | TSC2007_POWER_OFF_IRQ_EN)
104 dev_dbg(&tsc->
client->dev,
"data: 0x%x, val: 0x%x\n", data, val);
112 tc->
y = tsc2007_xfer(tsc,
READ_Y);
115 tc->
x = tsc2007_xfer(tsc,
READ_X);
135 rt = tc->
z2 - tc->
z1;
139 rt = (rt + 2047) >> 12;
145 static bool tsc2007_is_pen_down(
struct tsc2007 *
ts)
174 while (!ts->
stopped && tsc2007_is_pen_down(ts)) {
177 tsc2007_read_values(ts, &tc);
179 rt = tsc2007_calculate_pressure(ts, &tc);
190 if (rt <= ts->max_rt) {
192 "DOWN point(%4d,%4d), pressure (%4u)\n",
196 input_report_abs(input,
ABS_X, tc.
x);
197 input_report_abs(input,
ABS_Y, tc.
y);
227 static irqreturn_t tsc2007_hard_irq(
int irq,
void *handle)
240 static void tsc2007_stop(
struct tsc2007 *ts)
249 static int tsc2007_open(
struct input_dev *input_dev)
251 struct tsc2007 *ts = input_get_drvdata(input_dev);
260 err = tsc2007_xfer(ts,
PWRDOWN);
269 static void tsc2007_close(
struct input_dev *input_dev)
271 struct tsc2007 *ts = input_get_drvdata(input_dev);
281 struct input_dev *input_dev;
285 dev_err(&client->
dev,
"platform data is required!\n");
289 if (!i2c_check_functionality(client->
adapter,
294 input_dev = input_allocate_device();
295 if (!ts || !input_dev) {
302 ts->
input = input_dev;
314 dev_err(&client->
dev,
"x_plate_ohms is not set up in platform data");
320 "%s/input0", dev_name(&client->
dev));
322 input_dev->name =
"TSC2007 Touchscreen";
323 input_dev->phys = ts->
phys;
324 input_dev->id.bustype =
BUS_I2C;
326 input_dev->open = tsc2007_open;
327 input_dev->close = tsc2007_close;
329 input_set_drvdata(input_dev, ts);
351 err = input_register_device(input_dev);
355 i2c_set_clientdata(client, ts);
364 input_free_device(input_dev);
371 struct tsc2007 *ts = i2c_get_clientdata(client);
379 input_unregister_device(ts->
input);
397 .id_table = tsc2007_idtable,
398 .probe = tsc2007_probe,