18 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/input.h>
22 #include <linux/slab.h>
30 #define REG_IRQEOI 0x020
31 #define REG_RAWIRQSTATUS 0x024
32 #define REG_IRQSTATUS 0x028
33 #define REG_IRQENABLE 0x02C
34 #define REG_IRQWAKEUP 0x034
35 #define REG_CTRL 0x040
36 #define REG_ADCFSM 0x044
37 #define REG_CLKDIV 0x04C
39 #define REG_IDLECONFIG 0x058
40 #define REG_CHARGECONFIG 0x05C
41 #define REG_CHARGEDELAY 0x060
42 #define REG_STEPCONFIG(n) (0x64 + ((n - 1) * 8))
43 #define REG_STEPDELAY(n) (0x68 + ((n - 1) * 8))
44 #define REG_STEPCONFIG13 0x0C4
45 #define REG_STEPDELAY13 0x0C8
46 #define REG_STEPCONFIG14 0x0CC
47 #define REG_STEPDELAY14 0x0D0
48 #define REG_FIFO0CNT 0xE4
49 #define REG_FIFO1THR 0xF4
50 #define REG_FIFO0 0x100
51 #define REG_FIFO1 0x200
54 #define IRQWKUP_ENB BIT(0)
55 #define STPENB_STEPENB 0x7FFF
56 #define IRQENB_FIFO1THRES BIT(5)
57 #define IRQENB_PENUP BIT(9)
58 #define STEPCONFIG_MODE_HWSYNC 0x2
59 #define STEPCONFIG_SAMPLES_AVG (1 << 4)
60 #define STEPCONFIG_XPP (1 << 5)
61 #define STEPCONFIG_XNN (1 << 6)
62 #define STEPCONFIG_YPP (1 << 7)
63 #define STEPCONFIG_YNN (1 << 8)
64 #define STEPCONFIG_XNP (1 << 9)
65 #define STEPCONFIG_YPN (1 << 10)
66 #define STEPCONFIG_INM (1 << 18)
67 #define STEPCONFIG_INP (1 << 20)
68 #define STEPCONFIG_INP_5 (1 << 21)
69 #define STEPCONFIG_FIFO1 (1 << 26)
70 #define STEPCONFIG_OPENDLY 0xff
71 #define STEPCONFIG_Z1 (3 << 19)
72 #define STEPIDLE_INP (1 << 22)
73 #define STEPCHARGE_RFP (1 << 12)
74 #define STEPCHARGE_INM (1 << 15)
75 #define STEPCHARGE_INP (1 << 19)
76 #define STEPCHARGE_RFM (1 << 23)
77 #define STEPCHARGE_DELAY 0x1
78 #define CNTRLREG_TSCSSENB (1 << 0)
79 #define CNTRLREG_STEPID (1 << 1)
80 #define CNTRLREG_STEPCONFIGWRT (1 << 2)
81 #define CNTRLREG_4WIRE (1 << 5)
82 #define CNTRLREG_5WIRE (1 << 6)
83 #define CNTRLREG_8WIRE (3 << 5)
84 #define CNTRLREG_TSCENB (1 << 7)
85 #define ADCFSM_STEPID 0x10
87 #define SEQ_SETTLE 275
88 #define ADC_CLK 3000000
89 #define MAX_12BIT ((1 << 12) - 1)
90 #define TSCADC_DELTA_X 15
91 #define TSCADC_DELTA_Y 15
103 static unsigned int tscadc_readl(
struct tscadc *
ts,
unsigned int reg)
108 static void tscadc_writel(
struct tscadc *
tsc,
unsigned int reg,
114 static void tscadc_step_config(
struct tscadc *ts_dev)
123 switch (ts_dev->
wires) {
137 for (i = 1; i < 7; i++) {
146 switch (ts_dev->
wires) {
159 for (i = 7; i < 13; i++) {
190 unsigned int idleconfig;
198 static void tscadc_read_coordinates(
struct tscadc *ts_dev,
199 unsigned int *
x,
unsigned int *
y)
201 unsigned int fifocount = tscadc_readl(ts_dev,
REG_FIFO0CNT);
202 unsigned int prev_val_x = ~0, prev_val_y = ~0;
203 unsigned int prev_diff_x = ~0, prev_diff_y = ~0;
204 unsigned int read, diff;
215 for (i = 0; i < fifocount - 1; i++) {
216 read = tscadc_readl(ts_dev,
REG_FIFO0) & 0xfff;
217 diff =
abs(read - prev_val_x);
218 if (diff < prev_diff_x) {
224 read = tscadc_readl(ts_dev,
REG_FIFO1) & 0xfff;
225 diff =
abs(read - prev_val_y);
226 if (diff < prev_diff_y) {
237 struct input_dev *input_dev = ts_dev->
input;
238 unsigned int status, irqclr = 0;
239 unsigned int x = 0, y = 0;
240 unsigned int z1, z2, z;
245 tscadc_read_coordinates(ts_dev, &x, &y);
247 z1 = tscadc_readl(ts_dev,
REG_FIFO0) & 0xfff;
248 z2 = tscadc_readl(ts_dev,
REG_FIFO1) & 0xfff;
250 if (ts_dev->
pen_down && z1 != 0 && z2 != 0) {
260 z = (z + 2047) >> 12;
263 input_report_abs(input_dev,
ABS_X, x);
264 input_report_abs(input_dev,
ABS_Y, y);
266 input_report_key(input_dev,
BTN_TOUCH, 1);
267 input_sync(input_dev);
285 input_report_key(input_dev,
BTN_TOUCH, 0);
287 input_sync(input_dev);
311 struct input_dev *input_dev;
314 int clk_value,
ctrl, irq;
317 dev_err(&pdev->
dev,
"missing platform data.\n");
323 dev_err(&pdev->
dev,
"no memory resource defined.\n");
329 dev_err(&pdev->
dev,
"no irq ID is specified.\n");
335 input_dev = input_allocate_device();
336 if (!ts_dev || !input_dev) {
337 dev_err(&pdev->
dev,
"failed to allocate memory.\n");
342 ts_dev->
input = input_dev;
349 dev_err(&pdev->
dev,
"failed to reserve registers.\n");
356 dev_err(&pdev->
dev,
"failed to map registers.\n");
358 goto err_release_mem_region;
362 0, pdev->
dev.driver->name, ts_dev);
364 dev_err(&pdev->
dev,
"failed to allocate irq.\n");
370 dev_err(&pdev->
dev,
"failed to get TSC ick\n");
377 dev_err(&pdev->
dev,
"failed to get TSC fck\n");
379 goto err_disable_clk;
386 dev_err(&pdev->
dev,
"clock input less than min clock requirement\n");
387 goto err_disable_clk;
390 tscadc_writel(ts_dev,
REG_CLKDIV, clk_value - 1);
398 switch (ts_dev->
wires) {
409 tscadc_writel(ts_dev,
REG_CTRL, ctrl);
411 tscadc_idle_config(ts_dev);
413 tscadc_step_config(ts_dev);
417 tscadc_writel(ts_dev,
REG_CTRL, ctrl);
419 input_dev->name =
"ti-tsc-adc";
420 input_dev->dev.parent = &pdev->
dev;
430 err = input_register_device(input_dev);
432 goto err_disable_clk;
434 platform_set_drvdata(pdev, ts_dev);
444 err_release_mem_region:
447 input_free_device(input_dev);
454 struct tscadc *ts_dev = platform_get_drvdata(pdev);
459 input_unregister_device(ts_dev->
input);
470 platform_set_drvdata(pdev,
NULL);
475 .probe = tscadc_probe,