2 * nvec_ps2: mouse driver for a NVIDIA compliant embedded controller
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/serio.h>
19 #include <linux/delay.h>
20 #include <linux/platform_device.h>
26 #define ENABLE_MOUSE 0xf4
27 #define DISABLE_MOUSE 0xf5
28 #define PSMOUSE_RST 0xff
31 #define NVEC_PHD(str, buf, len) \
32 print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
33 16, 1, buf, len, false)
35 #define NVEC_PHD(str, buf, len)
46 struct serio *ser_dev;
47 struct notifier_block notifier;
48 struct nvec_chip *nvec;
51 static struct nvec_ps2 ps2_dev;
53 static int ps2_startstreaming(struct serio *ser_dev)
55 unsigned char buf[] = { NVEC_PS2, AUTO_RECEIVE_N, PACKET_SIZE };
56 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
59 static void ps2_stopstreaming(struct serio *ser_dev)
61 unsigned char buf[] = { NVEC_PS2, CANCEL_AUTO_RECEIVE };
62 nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
65 static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd)
67 unsigned char buf[] = { NVEC_PS2, SEND_COMMAND, ENABLE_MOUSE, 1 };
71 dev_dbg(&ser_dev->dev, "Sending ps2 cmd %02x\n", cmd);
72 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
75 static int nvec_ps2_notifier(struct notifier_block *nb,
76 unsigned long event_type, void *data)
79 unsigned char *msg = (unsigned char *)data;
83 for (i = 0; i < msg[1]; i++)
84 serio_interrupt(ps2_dev.ser_dev, msg[2 + i], 0);
85 NVEC_PHD("ps/2 mouse event: ", &msg[2], msg[1]);
90 for (i = 0; i < (msg[1] - 2); i++)
91 serio_interrupt(ps2_dev.ser_dev, msg[i + 4], 0);
92 NVEC_PHD("ps/2 mouse reply: ", &msg[4], msg[1] - 2);
95 else if (msg[1] != 2) /* !ack */
96 NVEC_PHD("unhandled mouse event: ", msg, msg[1] + 2);
103 static int nvec_mouse_probe(struct platform_device *pdev)
105 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
106 struct serio *ser_dev;
107 char mouse_reset[] = { NVEC_PS2, SEND_COMMAND, PSMOUSE_RST, 3 };
109 ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL);
113 ser_dev->id.type = SERIO_PS_PSTHRU;
114 ser_dev->write = ps2_sendcommand;
115 ser_dev->start = ps2_startstreaming;
116 ser_dev->stop = ps2_stopstreaming;
118 strlcpy(ser_dev->name, "nvec mouse", sizeof(ser_dev->name));
119 strlcpy(ser_dev->phys, "nvec", sizeof(ser_dev->phys));
121 ps2_dev.ser_dev = ser_dev;
122 ps2_dev.notifier.notifier_call = nvec_ps2_notifier;
124 nvec_register_notifier(nvec, &ps2_dev.notifier, 0);
126 serio_register_port(ser_dev);
129 nvec_write_async(nvec, mouse_reset, sizeof(mouse_reset));
134 static int nvec_mouse_remove(struct platform_device *pdev)
136 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
138 ps2_sendcommand(ps2_dev.ser_dev, DISABLE_MOUSE);
139 ps2_stopstreaming(ps2_dev.ser_dev);
140 nvec_unregister_notifier(nvec, &ps2_dev.notifier);
141 serio_unregister_port(ps2_dev.ser_dev);
146 #ifdef CONFIG_PM_SLEEP
147 static int nvec_mouse_suspend(struct device *dev)
150 ps2_sendcommand(ps2_dev.ser_dev, DISABLE_MOUSE);
152 /* send cancel autoreceive */
153 ps2_stopstreaming(ps2_dev.ser_dev);
158 static int nvec_mouse_resume(struct device *dev)
160 /* start streaming */
161 ps2_startstreaming(ps2_dev.ser_dev);
164 ps2_sendcommand(ps2_dev.ser_dev, ENABLE_MOUSE);
170 static const SIMPLE_DEV_PM_OPS(nvec_mouse_pm_ops, nvec_mouse_suspend,
173 static struct platform_driver nvec_mouse_driver = {
174 .probe = nvec_mouse_probe,
175 .remove = nvec_mouse_remove,
177 .name = "nvec-mouse",
178 .owner = THIS_MODULE,
179 .pm = &nvec_mouse_pm_ops,
183 module_platform_driver(nvec_mouse_driver);
185 MODULE_DESCRIPTION("NVEC mouse driver");
187 MODULE_ALIAS("platform:nvec-mouse");
188 MODULE_LICENSE("GPL");