1 // SPDX-License-Identifier: GPL-2.0
3 * nvec_ps2: mouse driver for a NVIDIA compliant embedded controller
5 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
7 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
8 * Ilya Petrov <ilya.muromec@gmail.com>
9 * Marc Dietrich <marvin24@gmx.de>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/serio.h>
15 #include <linux/delay.h>
16 #include <linux/platform_device.h>
22 #define ENABLE_MOUSE 0xf4
23 #define DISABLE_MOUSE 0xf5
24 #define PSMOUSE_RST 0xff
27 #define NVEC_PHD(str, buf, len) \
28 print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
29 16, 1, buf, len, false)
31 #define NVEC_PHD(str, buf, len) do { } while (0)
42 struct serio
*ser_dev
;
43 struct notifier_block notifier
;
44 struct nvec_chip
*nvec
;
47 static struct nvec_ps2 ps2_dev
;
49 static int ps2_startstreaming(struct serio
*ser_dev
)
51 unsigned char buf
[] = { NVEC_PS2
, AUTO_RECEIVE_N
, PACKET_SIZE
};
53 return nvec_write_async(ps2_dev
.nvec
, buf
, sizeof(buf
));
56 static void ps2_stopstreaming(struct serio
*ser_dev
)
58 unsigned char buf
[] = { NVEC_PS2
, CANCEL_AUTO_RECEIVE
};
60 nvec_write_async(ps2_dev
.nvec
, buf
, sizeof(buf
));
63 static int nvec_ps2_notifier(struct notifier_block
*nb
,
64 unsigned long event_type
, void *data
)
67 unsigned char *msg
= data
;
71 for (i
= 0; i
< msg
[1]; i
++)
72 serio_interrupt(ps2_dev
.ser_dev
, msg
[2 + i
], 0);
73 NVEC_PHD("ps/2 mouse event: ", &msg
[2], msg
[1]);
78 for (i
= 0; i
< (msg
[1] - 2); i
++)
79 serio_interrupt(ps2_dev
.ser_dev
, msg
[i
+ 4], 0);
80 NVEC_PHD("ps/2 mouse reply: ", &msg
[4], msg
[1] - 2);
83 else if (msg
[1] != 2) /* !ack */
84 NVEC_PHD("unhandled mouse event: ", msg
, msg
[1] + 2);
91 static int ps2_sendcommand(struct serio
*ser_dev
, unsigned char cmd
)
93 unsigned char buf
[] = { NVEC_PS2
, SEND_COMMAND
, ENABLE_MOUSE
, 1 };
99 dev_dbg(&ser_dev
->dev
, "Sending ps2 cmd %02x\n", cmd
);
101 ret
= nvec_write_sync(ps2_dev
.nvec
, buf
, sizeof(buf
), &msg
);
105 nvec_ps2_notifier(NULL
, NVEC_PS2
, msg
->data
);
107 nvec_msg_free(ps2_dev
.nvec
, msg
);
112 static int nvec_mouse_probe(struct platform_device
*pdev
)
114 struct nvec_chip
*nvec
= dev_get_drvdata(pdev
->dev
.parent
);
115 struct serio
*ser_dev
;
117 ser_dev
= kzalloc(sizeof(*ser_dev
), GFP_KERNEL
);
121 ser_dev
->id
.type
= SERIO_8042
;
122 ser_dev
->write
= ps2_sendcommand
;
123 ser_dev
->start
= ps2_startstreaming
;
124 ser_dev
->stop
= ps2_stopstreaming
;
126 strscpy(ser_dev
->name
, "nvec mouse", sizeof(ser_dev
->name
));
127 strscpy(ser_dev
->phys
, "nvec", sizeof(ser_dev
->phys
));
129 ps2_dev
.ser_dev
= ser_dev
;
130 ps2_dev
.notifier
.notifier_call
= nvec_ps2_notifier
;
132 nvec_register_notifier(nvec
, &ps2_dev
.notifier
, 0);
134 serio_register_port(ser_dev
);
139 static void nvec_mouse_remove(struct platform_device
*pdev
)
141 struct nvec_chip
*nvec
= dev_get_drvdata(pdev
->dev
.parent
);
143 ps2_sendcommand(ps2_dev
.ser_dev
, DISABLE_MOUSE
);
144 ps2_stopstreaming(ps2_dev
.ser_dev
);
145 nvec_unregister_notifier(nvec
, &ps2_dev
.notifier
);
146 serio_unregister_port(ps2_dev
.ser_dev
);
149 #ifdef CONFIG_PM_SLEEP
150 static int nvec_mouse_suspend(struct device
*dev
)
153 ps2_sendcommand(ps2_dev
.ser_dev
, DISABLE_MOUSE
);
155 /* send cancel autoreceive */
156 ps2_stopstreaming(ps2_dev
.ser_dev
);
161 static int nvec_mouse_resume(struct device
*dev
)
163 /* start streaming */
164 ps2_startstreaming(ps2_dev
.ser_dev
);
167 ps2_sendcommand(ps2_dev
.ser_dev
, ENABLE_MOUSE
);
173 static SIMPLE_DEV_PM_OPS(nvec_mouse_pm_ops
, nvec_mouse_suspend
,
176 static struct platform_driver nvec_mouse_driver
= {
177 .probe
= nvec_mouse_probe
,
178 .remove
= nvec_mouse_remove
,
180 .name
= "nvec-mouse",
181 .pm
= &nvec_mouse_pm_ops
,
185 module_platform_driver(nvec_mouse_driver
);
187 MODULE_DESCRIPTION("NVEC mouse driver");
188 MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>");
189 MODULE_ALIAS("platform:nvec-mouse");
190 MODULE_LICENSE("GPL");