1 // SPDX-License-Identifier: GPL-2.0-only
3 * Fujitsu serial touchscreen driver
5 * Copyright (c) Dmitry Torokhov <dtor@mail.ru>
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/input.h>
14 #include <linux/serio.h>
16 #define DRIVER_DESC "Fujitsu serial touchscreen driver"
18 MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
19 MODULE_DESCRIPTION(DRIVER_DESC
);
20 MODULE_LICENSE("GPL");
22 #define FUJITSU_LENGTH 5
25 * Per-touchscreen data.
28 struct input_dev
*dev
;
31 unsigned char data
[FUJITSU_LENGTH
];
36 * Decode serial data (5 bytes per packet)
39 * Where C is 1 while in calibration mode (which we don't use)
40 * R is 1 when no coordinate corection was done.
43 static irqreturn_t
fujitsu_interrupt(struct serio
*serio
,
44 unsigned char data
, unsigned int flags
)
46 struct fujitsu
*fujitsu
= serio_get_drvdata(serio
);
47 struct input_dev
*dev
= fujitsu
->dev
;
49 if (fujitsu
->idx
== 0) {
50 /* resync skip until start of frame */
51 if ((data
& 0xf0) != 0x80)
54 /* resync skip garbage */
61 fujitsu
->data
[fujitsu
->idx
++] = data
;
62 if (fujitsu
->idx
== FUJITSU_LENGTH
) {
63 input_report_abs(dev
, ABS_X
,
64 (fujitsu
->data
[2] << 7) | fujitsu
->data
[1]);
65 input_report_abs(dev
, ABS_Y
,
66 (fujitsu
->data
[4] << 7) | fujitsu
->data
[3]);
67 input_report_key(dev
, BTN_TOUCH
,
68 (fujitsu
->data
[0] & 0x03) != 2);
77 * fujitsu_disconnect() is the opposite of fujitsu_connect()
79 static void fujitsu_disconnect(struct serio
*serio
)
81 struct fujitsu
*fujitsu
= serio_get_drvdata(serio
);
83 input_get_device(fujitsu
->dev
);
84 input_unregister_device(fujitsu
->dev
);
86 serio_set_drvdata(serio
, NULL
);
87 input_put_device(fujitsu
->dev
);
92 * fujitsu_connect() is the routine that is called when someone adds a
93 * new serio device that supports the Fujitsu protocol and registers it
96 static int fujitsu_connect(struct serio
*serio
, struct serio_driver
*drv
)
98 struct fujitsu
*fujitsu
;
99 struct input_dev
*input_dev
;
102 fujitsu
= kzalloc(sizeof(struct fujitsu
), GFP_KERNEL
);
103 input_dev
= input_allocate_device();
104 if (!fujitsu
|| !input_dev
) {
109 fujitsu
->serio
= serio
;
110 fujitsu
->dev
= input_dev
;
111 snprintf(fujitsu
->phys
, sizeof(fujitsu
->phys
),
112 "%s/input0", serio
->phys
);
114 input_dev
->name
= "Fujitsu Serial Touchscreen";
115 input_dev
->phys
= fujitsu
->phys
;
116 input_dev
->id
.bustype
= BUS_RS232
;
117 input_dev
->id
.vendor
= SERIO_FUJITSU
;
118 input_dev
->id
.product
= 0;
119 input_dev
->id
.version
= 0x0100;
120 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
121 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
123 input_set_abs_params(input_dev
, ABS_X
, 0, 4096, 0, 0);
124 input_set_abs_params(input_dev
, ABS_Y
, 0, 4096, 0, 0);
125 serio_set_drvdata(serio
, fujitsu
);
127 err
= serio_open(serio
, drv
);
131 err
= input_register_device(fujitsu
->dev
);
140 serio_set_drvdata(serio
, NULL
);
142 input_free_device(input_dev
);
148 * The serio driver structure.
150 static const struct serio_device_id fujitsu_serio_ids
[] = {
153 .proto
= SERIO_FUJITSU
,
160 MODULE_DEVICE_TABLE(serio
, fujitsu_serio_ids
);
162 static struct serio_driver fujitsu_drv
= {
164 .name
= "fujitsu_ts",
166 .description
= DRIVER_DESC
,
167 .id_table
= fujitsu_serio_ids
,
168 .interrupt
= fujitsu_interrupt
,
169 .connect
= fujitsu_connect
,
170 .disconnect
= fujitsu_disconnect
,
173 module_serio_driver(fujitsu_drv
);