47 #include <linux/kernel.h>
48 #include <linux/module.h>
49 #include <linux/slab.h>
50 #include <linux/input.h>
51 #include <linux/serio.h>
54 #define DRIVER_DESC "RC transmitter with 5-byte Zhen Hua protocol joystick driver"
63 #define ZHENHUA_MAX_LENGTH 5
70 struct input_dev *
dev;
78 static int zhenhua_bitreverse(
int x)
80 x = ((x & 0xaa) >> 1) | ((x & 0x55) << 1);
81 x = ((x & 0xcc) >> 2) | ((x & 0x33) << 2);
82 x = ((x & 0xf0) >> 4) | ((x & 0x0f) << 4);
93 struct input_dev *
dev = zhenhua->
dev;
96 input_report_abs(dev,
ABS_Y, data[1]);
97 input_report_abs(dev,
ABS_X, data[2]);
98 input_report_abs(dev,
ABS_RZ, data[3]);
99 input_report_abs(dev,
ABS_Z, data[4]);
120 else if (zhenhua->
idx == 0)
124 zhenhua->
data[zhenhua->
idx++] = zhenhua_bitreverse(data);
127 zhenhua_process_packet(zhenhua);
138 static void zhenhua_disconnect(
struct serio *serio)
140 struct zhenhua *zhenhua = serio_get_drvdata(serio);
143 serio_set_drvdata(serio,
NULL);
144 input_unregister_device(zhenhua->
dev);
154 static int zhenhua_connect(
struct serio *serio,
struct serio_driver *drv)
156 struct zhenhua *zhenhua;
157 struct input_dev *input_dev;
160 zhenhua = kzalloc(
sizeof(
struct zhenhua),
GFP_KERNEL);
161 input_dev = input_allocate_device();
162 if (!zhenhua || !input_dev)
165 zhenhua->
dev = input_dev;
168 input_dev->name =
"Zhen Hua 5-byte device";
169 input_dev->phys = zhenhua->
phys;
172 input_dev->id.product = 0x0001;
173 input_dev->id.version = 0x0100;
174 input_dev->dev.parent = &serio->
dev;
177 input_set_abs_params(input_dev,
ABS_X, 50, 200, 0, 0);
178 input_set_abs_params(input_dev,
ABS_Y, 50, 200, 0, 0);
179 input_set_abs_params(input_dev,
ABS_Z, 50, 200, 0, 0);
180 input_set_abs_params(input_dev,
ABS_RZ, 50, 200, 0, 0);
182 serio_set_drvdata(serio, zhenhua);
188 err = input_register_device(zhenhua->
dev);
195 fail2: serio_set_drvdata(serio,
NULL);
196 fail1: input_free_device(input_dev);
222 .id_table = zhenhua_serio_ids,
223 .interrupt = zhenhua_interrupt,
224 .connect = zhenhua_connect,
225 .disconnect = zhenhua_disconnect,