Version:  2.0.40 2.2.26 2.4.37 2.6.39 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15

Linux/drivers/staging/nvec/nvec_ps2.c

  1 /*
  2  * nvec_ps2: mouse driver for a NVIDIA compliant embedded controller
  3  *
  4  * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
  5  *
  6  * Authors:  Pierre-Hugues Husson <phhusson@free.fr>
  7  *           Ilya Petrov <ilya.muromec@gmail.com>
  8  *           Marc Dietrich <marvin24@gmx.de>
  9  *
 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
 12  * for more details.
 13  *
 14  */
 15 
 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>
 21 
 22 #include "nvec.h"
 23 
 24 #define PACKET_SIZE     6
 25 
 26 #define ENABLE_MOUSE    0xf4
 27 #define DISABLE_MOUSE   0xf5
 28 #define PSMOUSE_RST     0xff
 29 
 30 #ifdef NVEC_PS2_DEBUG
 31 #define NVEC_PHD(str, buf, len) \
 32         print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
 33                         16, 1, buf, len, false)
 34 #else
 35 #define NVEC_PHD(str, buf, len)
 36 #endif
 37 
 38 enum ps2_subcmds {
 39         SEND_COMMAND = 1,
 40         RECEIVE_N,
 41         AUTO_RECEIVE_N,
 42         CANCEL_AUTO_RECEIVE,
 43 };
 44 
 45 struct nvec_ps2 {
 46         struct serio *ser_dev;
 47         struct notifier_block notifier;
 48         struct nvec_chip *nvec;
 49 };
 50 
 51 static struct nvec_ps2 ps2_dev;
 52 
 53 static int ps2_startstreaming(struct serio *ser_dev)
 54 {
 55         unsigned char buf[] = { NVEC_PS2, AUTO_RECEIVE_N, PACKET_SIZE };
 56         return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
 57 }
 58 
 59 static void ps2_stopstreaming(struct serio *ser_dev)
 60 {
 61         unsigned char buf[] = { NVEC_PS2, CANCEL_AUTO_RECEIVE };
 62         nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
 63 }
 64 
 65 static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd)
 66 {
 67         unsigned char buf[] = { NVEC_PS2, SEND_COMMAND, ENABLE_MOUSE, 1 };
 68 
 69         buf[2] = cmd & 0xff;
 70 
 71         dev_dbg(&ser_dev->dev, "Sending ps2 cmd %02x\n", cmd);
 72         return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
 73 }
 74 
 75 static int nvec_ps2_notifier(struct notifier_block *nb,
 76                              unsigned long event_type, void *data)
 77 {
 78         int i;
 79         unsigned char *msg = (unsigned char *)data;
 80 
 81         switch (event_type) {
 82         case NVEC_PS2_EVT:
 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]);
 86                 return NOTIFY_STOP;
 87 
 88         case NVEC_PS2:
 89                 if (msg[2] == 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);
 93                 }
 94 
 95                 else if (msg[1] != 2) /* !ack */
 96                         NVEC_PHD("unhandled mouse event: ", msg, msg[1] + 2);
 97                 return NOTIFY_STOP;
 98         }
 99 
100         return NOTIFY_DONE;
101 }
102 
103 static int nvec_mouse_probe(struct platform_device *pdev)
104 {
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 };
108 
109         ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL);
110         if (ser_dev == NULL)
111                 return -ENOMEM;
112 
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;
117 
118         strlcpy(ser_dev->name, "nvec mouse", sizeof(ser_dev->name));
119         strlcpy(ser_dev->phys, "nvec", sizeof(ser_dev->phys));
120 
121         ps2_dev.ser_dev = ser_dev;
122         ps2_dev.notifier.notifier_call = nvec_ps2_notifier;
123         ps2_dev.nvec = nvec;
124         nvec_register_notifier(nvec, &ps2_dev.notifier, 0);
125 
126         serio_register_port(ser_dev);
127 
128         /* mouse reset */
129         nvec_write_async(nvec, mouse_reset, sizeof(mouse_reset));
130 
131         return 0;
132 }
133 
134 static int nvec_mouse_remove(struct platform_device *pdev)
135 {
136         struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
137 
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);
142 
143         return 0;
144 }
145 
146 #ifdef CONFIG_PM_SLEEP
147 static int nvec_mouse_suspend(struct device *dev)
148 {
149         /* disable mouse */
150         ps2_sendcommand(ps2_dev.ser_dev, DISABLE_MOUSE);
151 
152         /* send cancel autoreceive */
153         ps2_stopstreaming(ps2_dev.ser_dev);
154 
155         return 0;
156 }
157 
158 static int nvec_mouse_resume(struct device *dev)
159 {
160         /* start streaming */
161         ps2_startstreaming(ps2_dev.ser_dev);
162 
163         /* enable mouse */
164         ps2_sendcommand(ps2_dev.ser_dev, ENABLE_MOUSE);
165 
166         return 0;
167 }
168 #endif
169 
170 static const SIMPLE_DEV_PM_OPS(nvec_mouse_pm_ops, nvec_mouse_suspend,
171                                 nvec_mouse_resume);
172 
173 static struct platform_driver nvec_mouse_driver = {
174         .probe  = nvec_mouse_probe,
175         .remove = nvec_mouse_remove,
176         .driver = {
177                 .name = "nvec-mouse",
178                 .owner = THIS_MODULE,
179                 .pm = &nvec_mouse_pm_ops,
180         },
181 };
182 
183 module_platform_driver(nvec_mouse_driver);
184 
185 MODULE_DESCRIPTION("NVEC mouse driver");
186 MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>");
187 MODULE_ALIAS("platform:nvec-mouse");
188 MODULE_LICENSE("GPL");
189 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us