16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/input.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
23 #define MC13783_TS_NAME "mc13783-ts"
25 #define DEFAULT_SAMPLE_TOLERANCE 300
30 "If the minimal and maximal value read out for one axis (out "
31 "of three) differ by this value (default: "
33 "is supposed to be wrong and is discarded. Set to 0 to "
34 "disable this check.");
62 #define sort3(a0, a1, a2) ({ \
74 int x0, x1, x2, y0, y1, y2;
81 x0 = priv->
sample[0] & 0xfff;
82 x1 = priv->
sample[1] & 0xfff;
83 x2 = priv->
sample[2] & 0xfff;
84 y0 = priv->
sample[3] & 0xfff;
85 y1 = (priv->
sample[0] >> 12) & 0xfff;
86 y2 = (priv->
sample[1] >> 12) & 0xfff;
87 cr0 = (priv->
sample[2] >> 12) & 0xfff;
88 cr1 = (priv->
sample[3] >> 12) & 0xfff;
91 "x: (% 4d,% 4d,% 4d) y: (% 4d, % 4d,% 4d) cr: (% 4d, % 4d)\n",
92 x0, x1, x2, y0, y1, y2, cr0, cr1);
97 cr0 = (cr0 +
cr1) / 2;
99 if (!cr0 || !sample_tolerance ||
100 (x2 - x0 < sample_tolerance &&
101 y2 - y0 < sample_tolerance)) {
104 input_report_abs(idev,
ABS_X, x1);
105 input_report_abs(idev,
ABS_Y, y1);
107 dev_dbg(&idev->dev,
"report (%d, %d, %d)\n",
108 x1, y1, 0x1000 - cr0);
111 dev_dbg(&idev->dev,
"report release\n");
114 cr0 ? 0x1000 - cr0 : cr0);
118 dev_dbg(&idev->dev,
"discard event\n");
132 mc13783_ts_report_sample(priv);
135 static int mc13783_ts_open(
struct input_dev *
dev)
158 static void mc13783_ts_close(
struct input_dev *dev)
174 struct input_dev *
idev;
178 idev = input_allocate_device();
185 priv->
touch = dev_get_platdata(&pdev->
dev);
187 dev_err(&pdev->
dev,
"missing platform data\n");
201 idev->dev.parent = &pdev->
dev;
205 input_set_abs_params(idev,
ABS_X, 0, 0xfff, 0, 0);
206 input_set_abs_params(idev,
ABS_Y, 0, 0xfff, 0, 0);
207 input_set_abs_params(idev,
ABS_PRESSURE, 0, 0xfff, 0, 0);
209 idev->open = mc13783_ts_open;
210 idev->close = mc13783_ts_close;
212 input_set_drvdata(idev, priv);
214 ret = input_register_device(priv->
idev);
217 "register input device failed with %d\n", ret);
221 platform_set_drvdata(pdev, priv);
227 input_free_device(idev);
236 platform_set_drvdata(pdev,
NULL);
239 input_unregister_device(priv->
idev);
253 static int __init mc13783_ts_init(
void)
259 static void __exit mc13783_ts_exit(
void)