staging: nvec: use dev_warn instead of printk
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / nvec / nvec_ps2.c
CommitLineData
162c7d8c
MD
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
7974035c 16#include <linux/module.h>
32890b98
MD
17#include <linux/slab.h>
18#include <linux/serio.h>
19#include <linux/delay.h>
f686e9af 20#include <linux/platform_device.h>
162c7d8c 21
32890b98
MD
22#include "nvec.h"
23
4b625c3a 24#define START_STREAMING {'\x06', '\x03', '\x06'}
162c7d8c
MD
25#define STOP_STREAMING {'\x06', '\x04'}
26#define SEND_COMMAND {'\x06', '\x01', '\xf4', '\x01'}
32890b98 27
0eedab70
MD
28#ifdef NVEC_PS2_DEBUG
29#define NVEC_PHD(str, buf, len) \
30 print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
31 16, 1, buf, len, false)
32#else
33#define NVEC_PHD(str, buf, len)
34#endif
35
162c7d8c
MD
36static const unsigned char MOUSE_RESET[] = {'\x06', '\x01', '\xff', '\x03'};
37
38struct nvec_ps2 {
32890b98
MD
39 struct serio *ser_dev;
40 struct notifier_block notifier;
41 struct nvec_chip *nvec;
42};
43
44static struct nvec_ps2 ps2_dev;
45
46static int ps2_startstreaming(struct serio *ser_dev)
47{
48 unsigned char buf[] = START_STREAMING;
ff006d12 49 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
32890b98
MD
50}
51
52static void ps2_stopstreaming(struct serio *ser_dev)
53{
54 unsigned char buf[] = STOP_STREAMING;
55 nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
56}
57
32890b98
MD
58static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd)
59{
60 unsigned char buf[] = SEND_COMMAND;
61
62 buf[2] = cmd & 0xff;
63
64 dev_dbg(&ser_dev->dev, "Sending ps2 cmd %02x\n", cmd);
ff006d12 65 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
32890b98
MD
66}
67
68static int nvec_ps2_notifier(struct notifier_block *nb,
162c7d8c 69 unsigned long event_type, void *data)
32890b98
MD
70{
71 int i;
72 unsigned char *msg = (unsigned char *)data;
73
74 switch (event_type) {
162c7d8c 75 case NVEC_PS2_EVT:
1e46e627
JAK
76 for (i = 0; i < msg[1]; i++)
77 serio_interrupt(ps2_dev.ser_dev, msg[2 + i], 0);
0eedab70 78 NVEC_PHD("ps/2 mouse event: ", &msg[2], msg[1]);
162c7d8c
MD
79 return NOTIFY_STOP;
80
81 case NVEC_PS2:
0eedab70 82 if (msg[2] == 1) {
162c7d8c
MD
83 for (i = 0; i < (msg[1] - 2); i++)
84 serio_interrupt(ps2_dev.ser_dev, msg[i + 4], 0);
0eedab70 85 NVEC_PHD("ps/2 mouse reply: ", &msg[4], msg[1] - 2);
162c7d8c
MD
86 }
87
0eedab70
MD
88 else if (msg[1] != 2) /* !ack */
89 NVEC_PHD("unhandled mouse event: ", msg, msg[1] + 2);
162c7d8c 90 return NOTIFY_STOP;
32890b98
MD
91 }
92
93 return NOTIFY_DONE;
94}
95
f686e9af 96static int __devinit nvec_mouse_probe(struct platform_device *pdev)
32890b98 97{
f686e9af 98 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
f5e3352e
MD
99 struct serio *ser_dev;
100
101 ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL);
102 if (ser_dev == NULL)
103 return -ENOMEM;
32890b98 104
36b30d61 105 ser_dev->id.type = SERIO_PS_PSTHRU;
162c7d8c 106 ser_dev->write = ps2_sendcommand;
34ba143b
MD
107 ser_dev->start = ps2_startstreaming;
108 ser_dev->stop = ps2_stopstreaming;
32890b98 109
162c7d8c
MD
110 strlcpy(ser_dev->name, "nvec mouse", sizeof(ser_dev->name));
111 strlcpy(ser_dev->phys, "nvec", sizeof(ser_dev->phys));
32890b98
MD
112
113 ps2_dev.ser_dev = ser_dev;
114 ps2_dev.notifier.notifier_call = nvec_ps2_notifier;
115 ps2_dev.nvec = nvec;
116 nvec_register_notifier(nvec, &ps2_dev.notifier, 0);
117
118 serio_register_port(ser_dev);
119
120 /* mouse reset */
162c7d8c 121 nvec_write_async(nvec, MOUSE_RESET, 4);
32890b98
MD
122
123 return 0;
124}
f686e9af 125
d1b5342c
MD
126static int nvec_mouse_suspend(struct platform_device *pdev, pm_message_t state)
127{
128 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
129
a573298b
MD
130 /* disable mouse */
131 nvec_write_async(nvec, "\x06\xf4", 2);
132
d1b5342c
MD
133 /* send cancel autoreceive */
134 nvec_write_async(nvec, "\x06\x04", 2);
135
136 return 0;
137}
138
139static int nvec_mouse_resume(struct platform_device *pdev)
140{
a573298b
MD
141 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
142
d1b5342c
MD
143 ps2_startstreaming(ps2_dev.ser_dev);
144
a573298b
MD
145 /* enable mouse */
146 nvec_write_async(nvec, "\x06\xf5", 2);
147
d1b5342c
MD
148 return 0;
149}
150
f686e9af 151static struct platform_driver nvec_mouse_driver = {
162c7d8c 152 .probe = nvec_mouse_probe,
d1b5342c
MD
153 .suspend = nvec_mouse_suspend,
154 .resume = nvec_mouse_resume,
162c7d8c
MD
155 .driver = {
156 .name = "nvec-mouse",
157 .owner = THIS_MODULE,
f686e9af
MD
158 },
159};
160
161static int __init nvec_mouse_init(void)
162{
163 return platform_driver_register(&nvec_mouse_driver);
164}
165
166module_init(nvec_mouse_init);
162c7d8c
MD
167
168MODULE_DESCRIPTION("NVEC mouse driver");
169MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>");
170MODULE_LICENSE("GPL");