17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/input.h>
20 #include <linux/slab.h>
25 #include <mach/board.h>
30 #define ATMEL_TSADCC_CR 0x00
31 #define ATMEL_TSADCC_SWRST (1 << 0)
32 #define ATMEL_TSADCC_START (1 << 1)
34 #define ATMEL_TSADCC_MR 0x04
35 #define ATMEL_TSADCC_TSAMOD (3 << 0)
36 #define ATMEL_TSADCC_TSAMOD_ADC_ONLY_MODE (0x0)
37 #define ATMEL_TSADCC_TSAMOD_TS_ONLY_MODE (0x1)
38 #define ATMEL_TSADCC_LOWRES (1 << 4)
39 #define ATMEL_TSADCC_SLEEP (1 << 5)
40 #define ATMEL_TSADCC_PENDET (1 << 6)
41 #define ATMEL_TSADCC_PRES (1 << 7)
42 #define ATMEL_TSADCC_PRESCAL (0x3f << 8)
43 #define ATMEL_TSADCC_EPRESCAL (0xff << 8)
44 #define ATMEL_TSADCC_STARTUP (0x7f << 16)
45 #define ATMEL_TSADCC_SHTIM (0xf << 24)
46 #define ATMEL_TSADCC_PENDBC (0xf << 28)
48 #define ATMEL_TSADCC_TRGR 0x08
49 #define ATMEL_TSADCC_TRGMOD (7 << 0)
50 #define ATMEL_TSADCC_TRGMOD_NONE (0 << 0)
51 #define ATMEL_TSADCC_TRGMOD_EXT_RISING (1 << 0)
52 #define ATMEL_TSADCC_TRGMOD_EXT_FALLING (2 << 0)
53 #define ATMEL_TSADCC_TRGMOD_EXT_ANY (3 << 0)
54 #define ATMEL_TSADCC_TRGMOD_PENDET (4 << 0)
55 #define ATMEL_TSADCC_TRGMOD_PERIOD (5 << 0)
56 #define ATMEL_TSADCC_TRGMOD_CONTINUOUS (6 << 0)
57 #define ATMEL_TSADCC_TRGPER (0xffff << 16)
59 #define ATMEL_TSADCC_TSR 0x0C
60 #define ATMEL_TSADCC_TSFREQ (0xf << 0)
61 #define ATMEL_TSADCC_TSSHTIM (0xf << 24)
63 #define ATMEL_TSADCC_CHER 0x10
64 #define ATMEL_TSADCC_CHDR 0x14
65 #define ATMEL_TSADCC_CHSR 0x18
66 #define ATMEL_TSADCC_CH(n) (1 << (n))
68 #define ATMEL_TSADCC_SR 0x1C
69 #define ATMEL_TSADCC_EOC(n) (1 << ((n)+0))
70 #define ATMEL_TSADCC_OVRE(n) (1 << ((n)+8))
71 #define ATMEL_TSADCC_DRDY (1 << 16)
72 #define ATMEL_TSADCC_GOVRE (1 << 17)
73 #define ATMEL_TSADCC_ENDRX (1 << 18)
74 #define ATMEL_TSADCC_RXBUFF (1 << 19)
75 #define ATMEL_TSADCC_PENCNT (1 << 20)
76 #define ATMEL_TSADCC_NOCNT (1 << 21)
78 #define ATMEL_TSADCC_LCDR 0x20
79 #define ATMEL_TSADCC_DATA (0x3ff << 0)
81 #define ATMEL_TSADCC_IER 0x24
82 #define ATMEL_TSADCC_IDR 0x28
83 #define ATMEL_TSADCC_IMR 0x2C
84 #define ATMEL_TSADCC_CDR0 0x30
85 #define ATMEL_TSADCC_CDR1 0x34
86 #define ATMEL_TSADCC_CDR2 0x38
87 #define ATMEL_TSADCC_CDR3 0x3C
88 #define ATMEL_TSADCC_CDR4 0x40
89 #define ATMEL_TSADCC_CDR5 0x44
91 #define ATMEL_TSADCC_XPOS 0x50
92 #define ATMEL_TSADCC_Z1DAT 0x54
93 #define ATMEL_TSADCC_Z2DAT 0x58
95 #define PRESCALER_VAL(x) ((x) >> 8)
97 #define ADC_DEFAULT_CLOCK 100000
111 #define atmel_tsadcc_read(reg) __raw_readl(tsc_base + (reg))
112 #define atmel_tsadcc_write(reg, val) __raw_writel((val), tsc_base + (reg))
117 struct input_dev *input_dev = ts_dev->
input;
135 input_report_key(input_dev,
BTN_TOUCH, 0);
137 input_sync(input_dev);
160 input_report_key(input_dev,
BTN_TOUCH, 1);
161 input_sync(input_dev);
183 struct input_dev *input_dev;
192 dev_err(&pdev->
dev,
"no mmio resource defined.\n");
199 dev_err(&pdev->
dev,
"failed to allocate memory.\n");
202 platform_set_drvdata(pdev, ts_dev);
204 input_dev = input_allocate_device();
206 dev_err(&pdev->
dev,
"failed to allocate input device.\n");
212 if (ts_dev->
irq < 0) {
213 dev_err(&pdev->
dev,
"no irq ID is designated.\n");
219 "atmel tsadcc regs")) {
220 dev_err(&pdev->
dev,
"resources is unavailable.\n");
227 dev_err(&pdev->
dev,
"failed to map registers.\n");
229 goto err_release_mem;
233 pdev->
dev.driver->name, ts_dev);
235 dev_err(&pdev->
dev,
"failed to allocate irq.\n");
240 if (IS_ERR(ts_dev->
clk)) {
241 dev_err(&pdev->
dev,
"failed to get ts_clk\n");
242 err = PTR_ERR(ts_dev->
clk);
246 ts_dev->
input = input_dev;
250 "%s/input0", dev_name(&pdev->
dev));
252 input_dev->name =
"atmel touch screen controller";
253 input_dev->phys = ts_dev->
phys;
254 input_dev->dev.parent = &pdev->
dev;
257 input_set_abs_params(input_dev,
ABS_X, 0, 0x3FF, 0, 0);
258 input_set_abs_params(input_dev,
ABS_Y, 0, 0x3FF, 0, 0);
266 dev_info(&pdev->
dev,
"Master clock is set at: %d Hz\n", prsc);
274 prsc = (prsc / (2 * pdata->
adc_clock)) - 1;
285 dev_info(&pdev->
dev,
"Prescaler is set at: %d\n", prsc);
304 err = input_register_device(input_dev);
320 input_free_device(input_dev);
333 input_unregister_device(ts_dev->
input);
348 .probe = atmel_tsadcc_probe,
351 .name =
"atmel_tsadcc",