2 * nvec_ps2: mouse driver for a NVIDIA compliant embedded controller
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
6 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
7 * Ilya Petrov <ilya.muromec@gmail.com>
8 * Marc Dietrich <marvin24@gmx.de>
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>
24 #define START_STREAMING {'\x06', '\x03', '\x06'}
25 #define STOP_STREAMING {'\x06', '\x04'}
26 #define SEND_COMMAND {'\x06', '\x01', '\xf4', '\x01'}
29 #define NVEC_PHD(str, buf, len) \
30 print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
31 16, 1, buf, len, false)
33 #define NVEC_PHD(str, buf, len)
36 static const unsigned char MOUSE_RESET[] = {'\x06', '\x01', '\xff', '\x03'};
39 struct serio *ser_dev;
40 struct notifier_block notifier;
41 struct nvec_chip *nvec;
44 static struct nvec_ps2 ps2_dev;
46 static int ps2_startstreaming(struct serio *ser_dev)
48 unsigned char buf[] = START_STREAMING;
49 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
52 static void ps2_stopstreaming(struct serio *ser_dev)
54 unsigned char buf[] = STOP_STREAMING;
55 nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
58 static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd)
60 unsigned char buf[] = SEND_COMMAND;
64 dev_dbg(&ser_dev->dev, "Sending ps2 cmd %02x\n", cmd);
65 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
68 static int nvec_ps2_notifier(struct notifier_block *nb,
69 unsigned long event_type, void *data)
72 unsigned char *msg = (unsigned char *)data;
76 for (i = 0; i < msg[1]; i++)
77 serio_interrupt(ps2_dev.ser_dev, msg[2 + i], 0);
78 NVEC_PHD("ps/2 mouse event: ", &msg[2], msg[1]);
83 for (i = 0; i < (msg[1] - 2); i++)
84 serio_interrupt(ps2_dev.ser_dev, msg[i + 4], 0);
85 NVEC_PHD("ps/2 mouse reply: ", &msg[4], msg[1] - 2);
88 else if (msg[1] != 2) /* !ack */
89 NVEC_PHD("unhandled mouse event: ", msg, msg[1] + 2);
96 static int __devinit nvec_mouse_probe(struct platform_device *pdev)
98 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
99 struct serio *ser_dev = kzalloc(sizeof(struct serio), GFP_KERNEL);
101 ser_dev->id.type = SERIO_PS_PSTHRU;
102 ser_dev->write = ps2_sendcommand;
103 ser_dev->start = ps2_startstreaming;
104 ser_dev->stop = ps2_stopstreaming;
106 strlcpy(ser_dev->name, "nvec mouse", sizeof(ser_dev->name));
107 strlcpy(ser_dev->phys, "nvec", sizeof(ser_dev->phys));
109 ps2_dev.ser_dev = ser_dev;
110 ps2_dev.notifier.notifier_call = nvec_ps2_notifier;
112 nvec_register_notifier(nvec, &ps2_dev.notifier, 0);
114 serio_register_port(ser_dev);
117 nvec_write_async(nvec, MOUSE_RESET, 4);
122 static int nvec_mouse_suspend(struct platform_device *pdev, pm_message_t state)
124 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
127 nvec_write_async(nvec, "\x06\xf4", 2);
129 /* send cancel autoreceive */
130 nvec_write_async(nvec, "\x06\x04", 2);
135 static int nvec_mouse_resume(struct platform_device *pdev)
137 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
139 ps2_startstreaming(ps2_dev.ser_dev);
142 nvec_write_async(nvec, "\x06\xf5", 2);
147 static struct platform_driver nvec_mouse_driver = {
148 .probe = nvec_mouse_probe,
149 .suspend = nvec_mouse_suspend,
150 .resume = nvec_mouse_resume,
152 .name = "nvec-mouse",
153 .owner = THIS_MODULE,
157 static int __init nvec_mouse_init(void)
159 return platform_driver_register(&nvec_mouse_driver);
162 module_init(nvec_mouse_init);
164 MODULE_DESCRIPTION("NVEC mouse driver");
165 MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>");
166 MODULE_LICENSE("GPL");