1 // SPDX-License-Identifier: GPL-2.0-only
4 * h3600 atmel micro companion support, touchscreen subdevice
10 #include <asm/byteorder.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/input.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
20 #include <linux/mfd/ipaq-micro.h>
22 struct touchscreen_data {
23 struct input_dev *input;
24 struct ipaq_micro *micro;
27 static void micro_ts_receive(void *data, int len, unsigned char *msg)
29 struct touchscreen_data *ts = data;
32 input_report_abs(ts->input, ABS_X,
33 be16_to_cpup((__be16 *) &msg[2]));
34 input_report_abs(ts->input, ABS_Y,
35 be16_to_cpup((__be16 *) &msg[0]));
36 input_report_key(ts->input, BTN_TOUCH, 1);
37 input_sync(ts->input);
38 } else if (len == 0) {
39 input_report_abs(ts->input, ABS_X, 0);
40 input_report_abs(ts->input, ABS_Y, 0);
41 input_report_key(ts->input, BTN_TOUCH, 0);
42 input_sync(ts->input);
46 static void micro_ts_toggle_receive(struct touchscreen_data *ts, bool enable)
48 struct ipaq_micro *micro = ts->micro;
50 spin_lock_irq(µ->lock);
53 micro->ts = micro_ts_receive;
57 micro->ts_data = NULL;
60 spin_unlock_irq(&ts->micro->lock);
63 static int micro_ts_open(struct input_dev *input)
65 struct touchscreen_data *ts = input_get_drvdata(input);
67 micro_ts_toggle_receive(ts, true);
72 static void micro_ts_close(struct input_dev *input)
74 struct touchscreen_data *ts = input_get_drvdata(input);
76 micro_ts_toggle_receive(ts, false);
79 static int micro_ts_probe(struct platform_device *pdev)
81 struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
82 struct touchscreen_data *ts;
85 ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL);
91 ts->input = devm_input_allocate_device(&pdev->dev);
93 dev_err(&pdev->dev, "failed to allocate input device\n");
97 ts->input->name = "ipaq micro ts";
98 ts->input->open = micro_ts_open;
99 ts->input->close = micro_ts_close;
101 input_set_drvdata(ts->input, ts);
103 input_set_capability(ts->input, EV_KEY, BTN_TOUCH);
104 input_set_capability(ts->input, EV_ABS, ABS_X);
105 input_set_capability(ts->input, EV_ABS, ABS_Y);
106 input_set_abs_params(ts->input, ABS_X, 0, 1023, 0, 0);
107 input_set_abs_params(ts->input, ABS_Y, 0, 1023, 0, 0);
109 error = input_register_device(ts->input);
111 dev_err(&pdev->dev, "error registering touch input\n");
115 platform_set_drvdata(pdev, ts);
117 dev_info(&pdev->dev, "iPAQ micro touchscreen\n");
122 static int __maybe_unused micro_ts_suspend(struct device *dev)
124 struct touchscreen_data *ts = dev_get_drvdata(dev);
126 micro_ts_toggle_receive(ts, false);
131 static int __maybe_unused micro_ts_resume(struct device *dev)
133 struct touchscreen_data *ts = dev_get_drvdata(dev);
134 struct input_dev *input = ts->input;
136 mutex_lock(&input->mutex);
139 micro_ts_toggle_receive(ts, true);
141 mutex_unlock(&input->mutex);
146 static const struct dev_pm_ops micro_ts_dev_pm_ops = {
147 SET_SYSTEM_SLEEP_PM_OPS(micro_ts_suspend, micro_ts_resume)
150 static struct platform_driver micro_ts_device_driver = {
152 .name = "ipaq-micro-ts",
153 .pm = µ_ts_dev_pm_ops,
155 .probe = micro_ts_probe,
157 module_platform_driver(micro_ts_device_driver);
159 MODULE_LICENSE("GPL");
160 MODULE_DESCRIPTION("driver for iPAQ Atmel micro touchscreen");
161 MODULE_ALIAS("platform:ipaq-micro-ts");