1 // SPDX-License-Identifier: GPL-2.0
3 * nvec_ps2: mouse driver for a NVIDIA compliant embedded controller
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)
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 ps2_sendcommand(struct serio *ser_dev, unsigned char cmd)
65 unsigned char buf[] = { NVEC_PS2, SEND_COMMAND, ENABLE_MOUSE, 1 };
69 dev_dbg(&ser_dev->dev, "Sending ps2 cmd %02x\n", cmd);
70 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
73 static int nvec_ps2_notifier(struct notifier_block *nb,
74 unsigned long event_type, void *data)
77 unsigned char *msg = data;
81 for (i = 0; i < msg[1]; i++)
82 serio_interrupt(ps2_dev.ser_dev, msg[2 + i], 0);
83 NVEC_PHD("ps/2 mouse event: ", &msg[2], msg[1]);
88 for (i = 0; i < (msg[1] - 2); i++)
89 serio_interrupt(ps2_dev.ser_dev, msg[i + 4], 0);
90 NVEC_PHD("ps/2 mouse reply: ", &msg[4], msg[1] - 2);
93 else if (msg[1] != 2) /* !ack */
94 NVEC_PHD("unhandled mouse event: ", msg, msg[1] + 2);
101 static int nvec_mouse_probe(struct platform_device *pdev)
103 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
104 struct serio *ser_dev;
106 ser_dev = kzalloc(sizeof(*ser_dev), GFP_KERNEL);
110 ser_dev->id.type = SERIO_8042;
111 ser_dev->write = ps2_sendcommand;
112 ser_dev->start = ps2_startstreaming;
113 ser_dev->stop = ps2_stopstreaming;
115 strlcpy(ser_dev->name, "nvec mouse", sizeof(ser_dev->name));
116 strlcpy(ser_dev->phys, "nvec", sizeof(ser_dev->phys));
118 ps2_dev.ser_dev = ser_dev;
119 ps2_dev.notifier.notifier_call = nvec_ps2_notifier;
121 nvec_register_notifier(nvec, &ps2_dev.notifier, 0);
123 serio_register_port(ser_dev);
128 static int nvec_mouse_remove(struct platform_device *pdev)
130 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
132 ps2_sendcommand(ps2_dev.ser_dev, DISABLE_MOUSE);
133 ps2_stopstreaming(ps2_dev.ser_dev);
134 nvec_unregister_notifier(nvec, &ps2_dev.notifier);
135 serio_unregister_port(ps2_dev.ser_dev);
140 #ifdef CONFIG_PM_SLEEP
141 static int nvec_mouse_suspend(struct device *dev)
144 ps2_sendcommand(ps2_dev.ser_dev, DISABLE_MOUSE);
146 /* send cancel autoreceive */
147 ps2_stopstreaming(ps2_dev.ser_dev);
152 static int nvec_mouse_resume(struct device *dev)
154 /* start streaming */
155 ps2_startstreaming(ps2_dev.ser_dev);
158 ps2_sendcommand(ps2_dev.ser_dev, ENABLE_MOUSE);
164 static SIMPLE_DEV_PM_OPS(nvec_mouse_pm_ops, nvec_mouse_suspend,
167 static struct platform_driver nvec_mouse_driver = {
168 .probe = nvec_mouse_probe,
169 .remove = nvec_mouse_remove,
171 .name = "nvec-mouse",
172 .pm = &nvec_mouse_pm_ops,
176 module_platform_driver(nvec_mouse_driver);
178 MODULE_DESCRIPTION("NVEC mouse driver");
180 MODULE_ALIAS("platform:nvec-mouse");
181 MODULE_LICENSE("GPL");