blob: 9a243ca96e6db8fbb754b34e16e8c508ee289eab [file] [log] [blame]
Jiri Kosinac080d892007-01-25 11:43:31 +01001/*
Jiri Kosinac080d892007-01-25 11:43:31 +01002 * (c) 1999 Andreas Gal <gal@cs.uni-magdeburg.de>
3 * (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz>
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02004 * (c) 2007-2009 Jiri Kosina
Jiri Kosinac080d892007-01-25 11:43:31 +01005 *
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02006 * HID debugging support
Jiri Kosinac080d892007-01-25 11:43:31 +01007 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */
28
Joe Perches4291ee32010-12-09 19:29:03 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jiri Kosinaa635f9d2009-06-12 15:20:55 +020031#include <linux/debugfs.h>
32#include <linux/seq_file.h>
Jiri Kosinacd667ce2009-06-12 15:20:57 +020033#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Jiri Kosinacd667ce2009-06-12 15:20:57 +020035#include <linux/uaccess.h>
36#include <linux/poll.h>
37
Jiri Kosinac080d892007-01-25 11:43:31 +010038#include <linux/hid.h>
Adrian Bunk4330eb22007-02-21 12:57:30 +010039#include <linux/hid-debug.h>
Jiri Kosinac080d892007-01-25 11:43:31 +010040
Jiri Kosinaa635f9d2009-06-12 15:20:55 +020041static struct dentry *hid_debug_root;
42
Jiri Kosinac080d892007-01-25 11:43:31 +010043struct hid_usage_entry {
44 unsigned page;
45 unsigned usage;
Joe Perches0ce1ac32007-09-26 16:29:53 +020046 const char *description;
Jiri Kosinac080d892007-01-25 11:43:31 +010047};
48
49static const struct hid_usage_entry hid_usage_table[] = {
50 { 0, 0, "Undefined" },
51 { 1, 0, "GenericDesktop" },
52 {0, 0x01, "Pointer"},
53 {0, 0x02, "Mouse"},
54 {0, 0x04, "Joystick"},
55 {0, 0x05, "GamePad"},
56 {0, 0x06, "Keyboard"},
57 {0, 0x07, "Keypad"},
58 {0, 0x08, "MultiAxis"},
59 {0, 0x30, "X"},
60 {0, 0x31, "Y"},
61 {0, 0x32, "Z"},
62 {0, 0x33, "Rx"},
63 {0, 0x34, "Ry"},
64 {0, 0x35, "Rz"},
65 {0, 0x36, "Slider"},
66 {0, 0x37, "Dial"},
67 {0, 0x38, "Wheel"},
68 {0, 0x39, "HatSwitch"},
69 {0, 0x3a, "CountedBuffer"},
70 {0, 0x3b, "ByteCount"},
71 {0, 0x3c, "MotionWakeup"},
72 {0, 0x3d, "Start"},
73 {0, 0x3e, "Select"},
74 {0, 0x40, "Vx"},
75 {0, 0x41, "Vy"},
76 {0, 0x42, "Vz"},
77 {0, 0x43, "Vbrx"},
78 {0, 0x44, "Vbry"},
79 {0, 0x45, "Vbrz"},
80 {0, 0x46, "Vno"},
81 {0, 0x80, "SystemControl"},
82 {0, 0x81, "SystemPowerDown"},
83 {0, 0x82, "SystemSleep"},
84 {0, 0x83, "SystemWakeUp"},
85 {0, 0x84, "SystemContextMenu"},
86 {0, 0x85, "SystemMainMenu"},
87 {0, 0x86, "SystemAppMenu"},
88 {0, 0x87, "SystemMenuHelp"},
89 {0, 0x88, "SystemMenuExit"},
90 {0, 0x89, "SystemMenuSelect"},
91 {0, 0x8a, "SystemMenuRight"},
92 {0, 0x8b, "SystemMenuLeft"},
93 {0, 0x8c, "SystemMenuUp"},
94 {0, 0x8d, "SystemMenuDown"},
95 {0, 0x90, "D-PadUp"},
96 {0, 0x91, "D-PadDown"},
97 {0, 0x92, "D-PadRight"},
98 {0, 0x93, "D-PadLeft"},
99 { 2, 0, "Simulation" },
100 {0, 0xb0, "Aileron"},
101 {0, 0xb1, "AileronTrim"},
102 {0, 0xb2, "Anti-Torque"},
103 {0, 0xb3, "Autopilot"},
104 {0, 0xb4, "Chaff"},
105 {0, 0xb5, "Collective"},
106 {0, 0xb6, "DiveBrake"},
107 {0, 0xb7, "ElectronicCountermeasures"},
108 {0, 0xb8, "Elevator"},
109 {0, 0xb9, "ElevatorTrim"},
110 {0, 0xba, "Rudder"},
111 {0, 0xbb, "Throttle"},
112 {0, 0xbc, "FlightCommunications"},
113 {0, 0xbd, "FlareRelease"},
114 {0, 0xbe, "LandingGear"},
115 {0, 0xbf, "ToeBrake"},
116 { 7, 0, "Keyboard" },
117 { 8, 0, "LED" },
118 {0, 0x01, "NumLock"},
119 {0, 0x02, "CapsLock"},
120 {0, 0x03, "ScrollLock"},
121 {0, 0x04, "Compose"},
122 {0, 0x05, "Kana"},
123 {0, 0x4b, "GenericIndicator"},
124 { 9, 0, "Button" },
125 { 10, 0, "Ordinal" },
126 { 12, 0, "Consumer" },
127 {0, 0x238, "HorizontalWheel"},
128 { 13, 0, "Digitizers" },
129 {0, 0x01, "Digitizer"},
130 {0, 0x02, "Pen"},
131 {0, 0x03, "LightPen"},
132 {0, 0x04, "TouchScreen"},
133 {0, 0x05, "TouchPad"},
134 {0, 0x20, "Stylus"},
135 {0, 0x21, "Puck"},
136 {0, 0x22, "Finger"},
137 {0, 0x30, "TipPressure"},
138 {0, 0x31, "BarrelPressure"},
139 {0, 0x32, "InRange"},
140 {0, 0x33, "Touch"},
141 {0, 0x34, "UnTouch"},
142 {0, 0x35, "Tap"},
143 {0, 0x39, "TabletFunctionKey"},
144 {0, 0x3a, "ProgramChangeKey"},
145 {0, 0x3c, "Invert"},
146 {0, 0x42, "TipSwitch"},
147 {0, 0x43, "SecondaryTipSwitch"},
148 {0, 0x44, "BarrelSwitch"},
149 {0, 0x45, "Eraser"},
150 {0, 0x46, "TabletPick"},
Stephane Chatty89f536c2009-05-20 15:41:24 +0200151 {0, 0x47, "Confidence"},
152 {0, 0x48, "Width"},
153 {0, 0x49, "Height"},
154 {0, 0x51, "ContactID"},
155 {0, 0x52, "InputMode"},
156 {0, 0x53, "DeviceIndex"},
157 {0, 0x54, "ContactCount"},
158 {0, 0x55, "ContactMaximumNumber"},
Jiri Kosinac080d892007-01-25 11:43:31 +0100159 { 15, 0, "PhysicalInterfaceDevice" },
160 {0, 0x00, "Undefined"},
161 {0, 0x01, "Physical_Interface_Device"},
162 {0, 0x20, "Normal"},
163 {0, 0x21, "Set_Effect_Report"},
164 {0, 0x22, "Effect_Block_Index"},
165 {0, 0x23, "Parameter_Block_Offset"},
166 {0, 0x24, "ROM_Flag"},
167 {0, 0x25, "Effect_Type"},
168 {0, 0x26, "ET_Constant_Force"},
169 {0, 0x27, "ET_Ramp"},
170 {0, 0x28, "ET_Custom_Force_Data"},
171 {0, 0x30, "ET_Square"},
172 {0, 0x31, "ET_Sine"},
173 {0, 0x32, "ET_Triangle"},
174 {0, 0x33, "ET_Sawtooth_Up"},
175 {0, 0x34, "ET_Sawtooth_Down"},
176 {0, 0x40, "ET_Spring"},
177 {0, 0x41, "ET_Damper"},
178 {0, 0x42, "ET_Inertia"},
179 {0, 0x43, "ET_Friction"},
180 {0, 0x50, "Duration"},
181 {0, 0x51, "Sample_Period"},
182 {0, 0x52, "Gain"},
183 {0, 0x53, "Trigger_Button"},
184 {0, 0x54, "Trigger_Repeat_Interval"},
185 {0, 0x55, "Axes_Enable"},
186 {0, 0x56, "Direction_Enable"},
187 {0, 0x57, "Direction"},
188 {0, 0x58, "Type_Specific_Block_Offset"},
189 {0, 0x59, "Block_Type"},
190 {0, 0x5A, "Set_Envelope_Report"},
191 {0, 0x5B, "Attack_Level"},
192 {0, 0x5C, "Attack_Time"},
193 {0, 0x5D, "Fade_Level"},
194 {0, 0x5E, "Fade_Time"},
195 {0, 0x5F, "Set_Condition_Report"},
196 {0, 0x60, "CP_Offset"},
197 {0, 0x61, "Positive_Coefficient"},
198 {0, 0x62, "Negative_Coefficient"},
199 {0, 0x63, "Positive_Saturation"},
200 {0, 0x64, "Negative_Saturation"},
201 {0, 0x65, "Dead_Band"},
202 {0, 0x66, "Download_Force_Sample"},
203 {0, 0x67, "Isoch_Custom_Force_Enable"},
204 {0, 0x68, "Custom_Force_Data_Report"},
205 {0, 0x69, "Custom_Force_Data"},
206 {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
207 {0, 0x6B, "Set_Custom_Force_Report"},
208 {0, 0x6C, "Custom_Force_Data_Offset"},
209 {0, 0x6D, "Sample_Count"},
210 {0, 0x6E, "Set_Periodic_Report"},
211 {0, 0x6F, "Offset"},
212 {0, 0x70, "Magnitude"},
213 {0, 0x71, "Phase"},
214 {0, 0x72, "Period"},
215 {0, 0x73, "Set_Constant_Force_Report"},
216 {0, 0x74, "Set_Ramp_Force_Report"},
217 {0, 0x75, "Ramp_Start"},
218 {0, 0x76, "Ramp_End"},
219 {0, 0x77, "Effect_Operation_Report"},
220 {0, 0x78, "Effect_Operation"},
221 {0, 0x79, "Op_Effect_Start"},
222 {0, 0x7A, "Op_Effect_Start_Solo"},
223 {0, 0x7B, "Op_Effect_Stop"},
224 {0, 0x7C, "Loop_Count"},
225 {0, 0x7D, "Device_Gain_Report"},
226 {0, 0x7E, "Device_Gain"},
227 {0, 0x7F, "PID_Pool_Report"},
228 {0, 0x80, "RAM_Pool_Size"},
229 {0, 0x81, "ROM_Pool_Size"},
230 {0, 0x82, "ROM_Effect_Block_Count"},
231 {0, 0x83, "Simultaneous_Effects_Max"},
232 {0, 0x84, "Pool_Alignment"},
233 {0, 0x85, "PID_Pool_Move_Report"},
234 {0, 0x86, "Move_Source"},
235 {0, 0x87, "Move_Destination"},
236 {0, 0x88, "Move_Length"},
237 {0, 0x89, "PID_Block_Load_Report"},
238 {0, 0x8B, "Block_Load_Status"},
239 {0, 0x8C, "Block_Load_Success"},
240 {0, 0x8D, "Block_Load_Full"},
241 {0, 0x8E, "Block_Load_Error"},
242 {0, 0x8F, "Block_Handle"},
243 {0, 0x90, "PID_Block_Free_Report"},
244 {0, 0x91, "Type_Specific_Block_Handle"},
245 {0, 0x92, "PID_State_Report"},
246 {0, 0x94, "Effect_Playing"},
247 {0, 0x95, "PID_Device_Control_Report"},
248 {0, 0x96, "PID_Device_Control"},
249 {0, 0x97, "DC_Enable_Actuators"},
250 {0, 0x98, "DC_Disable_Actuators"},
251 {0, 0x99, "DC_Stop_All_Effects"},
252 {0, 0x9A, "DC_Device_Reset"},
253 {0, 0x9B, "DC_Device_Pause"},
254 {0, 0x9C, "DC_Device_Continue"},
255 {0, 0x9F, "Device_Paused"},
256 {0, 0xA0, "Actuators_Enabled"},
257 {0, 0xA4, "Safety_Switch"},
258 {0, 0xA5, "Actuator_Override_Switch"},
259 {0, 0xA6, "Actuator_Power"},
260 {0, 0xA7, "Start_Delay"},
261 {0, 0xA8, "Parameter_Block_Size"},
262 {0, 0xA9, "Device_Managed_Pool"},
263 {0, 0xAA, "Shared_Parameter_Blocks"},
264 {0, 0xAB, "Create_New_Effect_Report"},
265 {0, 0xAC, "RAM_Pool_Available"},
266 { 0x84, 0, "Power Device" },
267 { 0x84, 0x02, "PresentStatus" },
268 { 0x84, 0x03, "ChangeStatus" },
269 { 0x84, 0x04, "UPS" },
270 { 0x84, 0x05, "PowerSupply" },
271 { 0x84, 0x10, "BatterySystem" },
272 { 0x84, 0x11, "BatterySystemID" },
273 { 0x84, 0x12, "Battery" },
274 { 0x84, 0x13, "BatteryID" },
275 { 0x84, 0x14, "Charger" },
276 { 0x84, 0x15, "ChargerID" },
277 { 0x84, 0x16, "PowerConverter" },
278 { 0x84, 0x17, "PowerConverterID" },
279 { 0x84, 0x18, "OutletSystem" },
280 { 0x84, 0x19, "OutletSystemID" },
281 { 0x84, 0x1a, "Input" },
282 { 0x84, 0x1b, "InputID" },
283 { 0x84, 0x1c, "Output" },
284 { 0x84, 0x1d, "OutputID" },
285 { 0x84, 0x1e, "Flow" },
286 { 0x84, 0x1f, "FlowID" },
287 { 0x84, 0x20, "Outlet" },
288 { 0x84, 0x21, "OutletID" },
289 { 0x84, 0x22, "Gang" },
290 { 0x84, 0x24, "PowerSummary" },
291 { 0x84, 0x25, "PowerSummaryID" },
292 { 0x84, 0x30, "Voltage" },
293 { 0x84, 0x31, "Current" },
294 { 0x84, 0x32, "Frequency" },
295 { 0x84, 0x33, "ApparentPower" },
296 { 0x84, 0x35, "PercentLoad" },
297 { 0x84, 0x40, "ConfigVoltage" },
298 { 0x84, 0x41, "ConfigCurrent" },
299 { 0x84, 0x43, "ConfigApparentPower" },
300 { 0x84, 0x53, "LowVoltageTransfer" },
301 { 0x84, 0x54, "HighVoltageTransfer" },
302 { 0x84, 0x56, "DelayBeforeStartup" },
303 { 0x84, 0x57, "DelayBeforeShutdown" },
304 { 0x84, 0x58, "Test" },
305 { 0x84, 0x5a, "AudibleAlarmControl" },
306 { 0x84, 0x60, "Present" },
307 { 0x84, 0x61, "Good" },
308 { 0x84, 0x62, "InternalFailure" },
309 { 0x84, 0x65, "Overload" },
310 { 0x84, 0x66, "OverCharged" },
311 { 0x84, 0x67, "OverTemperature" },
312 { 0x84, 0x68, "ShutdownRequested" },
313 { 0x84, 0x69, "ShutdownImminent" },
314 { 0x84, 0x6b, "SwitchOn/Off" },
315 { 0x84, 0x6c, "Switchable" },
316 { 0x84, 0x6d, "Used" },
317 { 0x84, 0x6e, "Boost" },
318 { 0x84, 0x73, "CommunicationLost" },
319 { 0x84, 0xfd, "iManufacturer" },
320 { 0x84, 0xfe, "iProduct" },
321 { 0x84, 0xff, "iSerialNumber" },
322 { 0x85, 0, "Battery System" },
323 { 0x85, 0x01, "SMBBatteryMode" },
324 { 0x85, 0x02, "SMBBatteryStatus" },
325 { 0x85, 0x03, "SMBAlarmWarning" },
326 { 0x85, 0x04, "SMBChargerMode" },
327 { 0x85, 0x05, "SMBChargerStatus" },
328 { 0x85, 0x06, "SMBChargerSpecInfo" },
329 { 0x85, 0x07, "SMBSelectorState" },
330 { 0x85, 0x08, "SMBSelectorPresets" },
331 { 0x85, 0x09, "SMBSelectorInfo" },
332 { 0x85, 0x29, "RemainingCapacityLimit" },
333 { 0x85, 0x2c, "CapacityMode" },
334 { 0x85, 0x42, "BelowRemainingCapacityLimit" },
335 { 0x85, 0x44, "Charging" },
336 { 0x85, 0x45, "Discharging" },
337 { 0x85, 0x4b, "NeedReplacement" },
338 { 0x85, 0x66, "RemainingCapacity" },
339 { 0x85, 0x68, "RunTimeToEmpty" },
340 { 0x85, 0x6a, "AverageTimeToFull" },
341 { 0x85, 0x83, "DesignCapacity" },
342 { 0x85, 0x85, "ManufacturerDate" },
343 { 0x85, 0x89, "iDeviceChemistry" },
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300344 { 0x85, 0x8b, "Rechargeable" },
Jiri Kosinac080d892007-01-25 11:43:31 +0100345 { 0x85, 0x8f, "iOEMInformation" },
346 { 0x85, 0x8d, "CapacityGranularity1" },
347 { 0x85, 0xd0, "ACPresent" },
348 /* pages 0xff00 to 0xffff are vendor-specific */
349 { 0xffff, 0, "Vendor-specific-FF" },
350 { 0, 0, NULL }
351};
352
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200353/* Either output directly into simple seq_file, or (if f == NULL)
354 * allocate a separate buffer that will then be passed to the 'events'
355 * ringbuffer.
356 *
357 * This is because these functions can be called both for "one-shot"
358 * "rdesc" while resolving, or for blocking "events".
359 *
360 * This holds both for resolv_usage_page() and hid_resolv_usage().
361 */
362static char *resolv_usage_page(unsigned page, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100363 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200364 char *buf = NULL;
365
366 if (!f) {
367 buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
368 if (!buf)
369 return ERR_PTR(-ENOMEM);
370 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100371
372 for (p = hid_usage_table; p->description; p++)
373 if (p->page == page) {
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200374 if (!f) {
375 snprintf(buf, HID_DEBUG_BUFSIZE, "%s",
376 p->description);
377 return buf;
378 }
379 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200380 seq_printf(f, "%s", p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200381 return NULL;
382 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100383 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200384 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200385 snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200386 else
387 seq_printf(f, "%04x", page);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200388 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100389}
390
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200391char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100392 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200393 char *buf = NULL;
394 int len = 0;
Jiri Kosinac080d892007-01-25 11:43:31 +0100395
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200396 buf = resolv_usage_page(usage >> 16, f);
397 if (IS_ERR(buf)) {
Joe Perches4291ee32010-12-09 19:29:03 -0800398 pr_err("error allocating HID debug buffer\n");
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200399 return NULL;
400 }
Jiri Kosina58037eb2007-05-30 15:07:13 +0200401
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200402
403 if (!f) {
404 len = strlen(buf);
405 snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), ".");
406 len++;
407 }
408 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200409 seq_printf(f, ".");
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200410 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100411 for (p = hid_usage_table; p->description; p++)
412 if (p->page == (usage >> 16)) {
413 for(++p; p->description && p->usage != 0; p++)
414 if (p->usage == (usage & 0xffff)) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200415 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200416 snprintf(buf + len,
417 max(0,HID_DEBUG_BUFSIZE - len - 1),
418 "%s", p->description);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200419 else
420 seq_printf(f,
421 "%s",
422 p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200423 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100424 }
425 break;
426 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200427 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200428 snprintf(buf + len, max(0, HID_DEBUG_BUFSIZE - len - 1),
429 "%04x", usage & 0xffff);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200430 else
431 seq_printf(f, "%04x", usage & 0xffff);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200432 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100433}
434EXPORT_SYMBOL_GPL(hid_resolv_usage);
435
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200436static void tab(int n, struct seq_file *f) {
437 seq_printf(f, "%*s", n, "");
Jiri Kosinac080d892007-01-25 11:43:31 +0100438}
439
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200440void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100441 int j;
442
443 if (field->physical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200444 tab(n, f);
445 seq_printf(f, "Physical(");
446 hid_resolv_usage(field->physical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100447 }
448 if (field->logical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200449 tab(n, f);
450 seq_printf(f, "Logical(");
451 hid_resolv_usage(field->logical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100452 }
Jeff Brown44906412011-07-24 14:03:30 -0700453 if (field->application) {
454 tab(n, f);
455 seq_printf(f, "Application(");
456 hid_resolv_usage(field->application, f); seq_printf(f, ")\n");
457 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200458 tab(n, f); seq_printf(f, "Usage(%d)\n", field->maxusage);
Jiri Kosinac080d892007-01-25 11:43:31 +0100459 for (j = 0; j < field->maxusage; j++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200460 tab(n+2, f); hid_resolv_usage(field->usage[j].hid, f); seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100461 }
462 if (field->logical_minimum != field->logical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200463 tab(n, f); seq_printf(f, "Logical Minimum(%d)\n", field->logical_minimum);
464 tab(n, f); seq_printf(f, "Logical Maximum(%d)\n", field->logical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100465 }
466 if (field->physical_minimum != field->physical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200467 tab(n, f); seq_printf(f, "Physical Minimum(%d)\n", field->physical_minimum);
468 tab(n, f); seq_printf(f, "Physical Maximum(%d)\n", field->physical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100469 }
470 if (field->unit_exponent) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200471 tab(n, f); seq_printf(f, "Unit Exponent(%d)\n", field->unit_exponent);
Jiri Kosinac080d892007-01-25 11:43:31 +0100472 }
473 if (field->unit) {
Joe Perches0ce1ac32007-09-26 16:29:53 +0200474 static const char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
475 static const char *units[5][8] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100476 { "None", "None", "None", "None", "None", "None", "None", "None" },
477 { "None", "Centimeter", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
478 { "None", "Radians", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
479 { "None", "Inch", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" },
480 { "None", "Degrees", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }
481 };
482
483 int i;
484 int sys;
485 __u32 data = field->unit;
486
487 /* First nibble tells us which system we're in. */
488 sys = data & 0xf;
489 data >>= 4;
490
491 if(sys > 4) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200492 tab(n, f); seq_printf(f, "Unit(Invalid)\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100493 }
494 else {
495 int earlier_unit = 0;
496
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200497 tab(n, f); seq_printf(f, "Unit(%s : ", systems[sys]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100498
499 for (i=1 ; i<sizeof(__u32)*2 ; i++) {
500 char nibble = data & 0xf;
501 data >>= 4;
502 if (nibble != 0) {
503 if(earlier_unit++ > 0)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200504 seq_printf(f, "*");
505 seq_printf(f, "%s", units[sys][i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100506 if(nibble != 1) {
507 /* This is a _signed_ nibble(!) */
508
509 int val = nibble & 0x7;
510 if(nibble & 0x08)
511 val = -((0x7 & ~val) +1);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200512 seq_printf(f, "^%d", val);
Jiri Kosinac080d892007-01-25 11:43:31 +0100513 }
514 }
515 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200516 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100517 }
518 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200519 tab(n, f); seq_printf(f, "Report Size(%u)\n", field->report_size);
520 tab(n, f); seq_printf(f, "Report Count(%u)\n", field->report_count);
521 tab(n, f); seq_printf(f, "Report Offset(%u)\n", field->report_offset);
Jiri Kosinac080d892007-01-25 11:43:31 +0100522
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200523 tab(n, f); seq_printf(f, "Flags( ");
Jiri Kosinac080d892007-01-25 11:43:31 +0100524 j = field->flags;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200525 seq_printf(f, "%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
526 seq_printf(f, "%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
527 seq_printf(f, "%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
528 seq_printf(f, "%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
529 seq_printf(f, "%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
530 seq_printf(f, "%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPreferredState " : "");
531 seq_printf(f, "%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
532 seq_printf(f, "%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
533 seq_printf(f, "%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
534 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100535}
536EXPORT_SYMBOL_GPL(hid_dump_field);
537
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200538void hid_dump_device(struct hid_device *device, struct seq_file *f)
539{
Jiri Kosinac080d892007-01-25 11:43:31 +0100540 struct hid_report_enum *report_enum;
541 struct hid_report *report;
542 struct list_head *list;
543 unsigned i,k;
Joe Perches0ce1ac32007-09-26 16:29:53 +0200544 static const char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
Jiri Kosinac080d892007-01-25 11:43:31 +0100545
546 for (i = 0; i < HID_REPORT_TYPES; i++) {
547 report_enum = device->report_enum + i;
548 list = report_enum->report_list.next;
549 while (list != &report_enum->report_list) {
550 report = (struct hid_report *) list;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200551 tab(2, f);
552 seq_printf(f, "%s", table[i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100553 if (report->id)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200554 seq_printf(f, "(%d)", report->id);
555 seq_printf(f, "[%s]", table[report->type]);
556 seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100557 for (k = 0; k < report->maxfield; k++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200558 tab(4, f);
559 seq_printf(f, "Field(%d)\n", k);
560 hid_dump_field(report->field[k], 6, f);
Jiri Kosinac080d892007-01-25 11:43:31 +0100561 }
562 list = list->next;
563 }
564 }
565}
566EXPORT_SYMBOL_GPL(hid_dump_device);
567
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200568/* enqueue string to 'events' ring buffer */
569void hid_debug_event(struct hid_device *hdev, char *buf)
570{
571 int i;
572 struct hid_debug_list *list;
Jiri Kosina58037eb2007-05-30 15:07:13 +0200573
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200574 list_for_each_entry(list, &hdev->debug_list, node) {
Bruno Prémonte639ba42010-03-15 19:00:27 +0100575 for (i = 0; i < strlen(buf); i++)
576 list->hid_debug_buf[(list->tail + i) % HID_DEBUG_BUFSIZE] =
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200577 buf[i];
Bruno Prémonte639ba42010-03-15 19:00:27 +0100578 list->tail = (list->tail + i) % HID_DEBUG_BUFSIZE;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200579 }
Chase Douglas1debfb32010-08-30 13:27:45 -0400580
581 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200582}
583EXPORT_SYMBOL_GPL(hid_debug_event);
584
585void hid_dump_input(struct hid_device *hdev, struct hid_usage *usage, __s32 value)
586{
587 char *buf;
588 int len;
589
590 buf = hid_resolv_usage(usage->hid, NULL);
591 if (!buf)
592 return;
593 len = strlen(buf);
594 snprintf(buf + len, HID_DEBUG_BUFSIZE - len - 1, " = %d\n", value);
595
596 hid_debug_event(hdev, buf);
597
598 kfree(buf);
599 wake_up_interruptible(&hdev->debug_wait);
600
Jiri Kosinac080d892007-01-25 11:43:31 +0100601}
602EXPORT_SYMBOL_GPL(hid_dump_input);
603
Joe Perches0ce1ac32007-09-26 16:29:53 +0200604static const char *events[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100605 [EV_SYN] = "Sync", [EV_KEY] = "Key",
606 [EV_REL] = "Relative", [EV_ABS] = "Absolute",
607 [EV_MSC] = "Misc", [EV_LED] = "LED",
608 [EV_SND] = "Sound", [EV_REP] = "Repeat",
609 [EV_FF] = "ForceFeedback", [EV_PWR] = "Power",
610 [EV_FF_STATUS] = "ForceFeedbackStatus",
611};
612
Stephane Chatty89f536c2009-05-20 15:41:24 +0200613static const char *syncs[3] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100614 [SYN_REPORT] = "Report", [SYN_CONFIG] = "Config",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200615 [SYN_MT_REPORT] = "MT Report",
Jiri Kosinac080d892007-01-25 11:43:31 +0100616};
Stephane Chatty89f536c2009-05-20 15:41:24 +0200617
Joe Perches0ce1ac32007-09-26 16:29:53 +0200618static const char *keys[KEY_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100619 [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc",
620 [KEY_1] = "1", [KEY_2] = "2",
621 [KEY_3] = "3", [KEY_4] = "4",
622 [KEY_5] = "5", [KEY_6] = "6",
623 [KEY_7] = "7", [KEY_8] = "8",
624 [KEY_9] = "9", [KEY_0] = "0",
625 [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal",
626 [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab",
627 [KEY_Q] = "Q", [KEY_W] = "W",
628 [KEY_E] = "E", [KEY_R] = "R",
629 [KEY_T] = "T", [KEY_Y] = "Y",
630 [KEY_U] = "U", [KEY_I] = "I",
631 [KEY_O] = "O", [KEY_P] = "P",
632 [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace",
633 [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl",
634 [KEY_A] = "A", [KEY_S] = "S",
635 [KEY_D] = "D", [KEY_F] = "F",
636 [KEY_G] = "G", [KEY_H] = "H",
637 [KEY_J] = "J", [KEY_K] = "K",
638 [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon",
639 [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave",
640 [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash",
641 [KEY_Z] = "Z", [KEY_X] = "X",
642 [KEY_C] = "C", [KEY_V] = "V",
643 [KEY_B] = "B", [KEY_N] = "N",
644 [KEY_M] = "M", [KEY_COMMA] = "Comma",
645 [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash",
646 [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk",
647 [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space",
648 [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1",
649 [KEY_F2] = "F2", [KEY_F3] = "F3",
650 [KEY_F4] = "F4", [KEY_F5] = "F5",
651 [KEY_F6] = "F6", [KEY_F7] = "F7",
652 [KEY_F8] = "F8", [KEY_F9] = "F9",
653 [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock",
654 [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7",
655 [KEY_KP8] = "KP8", [KEY_KP9] = "KP9",
656 [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4",
657 [KEY_KP5] = "KP5", [KEY_KP6] = "KP6",
658 [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1",
659 [KEY_KP2] = "KP2", [KEY_KP3] = "KP3",
660 [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot",
661 [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd",
662 [KEY_F11] = "F11", [KEY_F12] = "F12",
663 [KEY_RO] = "RO", [KEY_KATAKANA] = "Katakana",
664 [KEY_HIRAGANA] = "HIRAGANA", [KEY_HENKAN] = "Henkan",
665 [KEY_KATAKANAHIRAGANA] = "Katakana/Hiragana", [KEY_MUHENKAN] = "Muhenkan",
666 [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter",
667 [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash",
668 [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt",
669 [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home",
670 [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp",
671 [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right",
672 [KEY_END] = "End", [KEY_DOWN] = "Down",
673 [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert",
674 [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro",
675 [KEY_MUTE] = "Mute", [KEY_VOLUMEDOWN] = "VolumeDown",
676 [KEY_VOLUMEUP] = "VolumeUp", [KEY_POWER] = "Power",
677 [KEY_KPEQUAL] = "KPEqual", [KEY_KPPLUSMINUS] = "KPPlusMinus",
678 [KEY_PAUSE] = "Pause", [KEY_KPCOMMA] = "KPComma",
679 [KEY_HANGUEL] = "Hangeul", [KEY_HANJA] = "Hanja",
680 [KEY_YEN] = "Yen", [KEY_LEFTMETA] = "LeftMeta",
681 [KEY_RIGHTMETA] = "RightMeta", [KEY_COMPOSE] = "Compose",
682 [KEY_STOP] = "Stop", [KEY_AGAIN] = "Again",
683 [KEY_PROPS] = "Props", [KEY_UNDO] = "Undo",
684 [KEY_FRONT] = "Front", [KEY_COPY] = "Copy",
685 [KEY_OPEN] = "Open", [KEY_PASTE] = "Paste",
686 [KEY_FIND] = "Find", [KEY_CUT] = "Cut",
687 [KEY_HELP] = "Help", [KEY_MENU] = "Menu",
688 [KEY_CALC] = "Calc", [KEY_SETUP] = "Setup",
689 [KEY_SLEEP] = "Sleep", [KEY_WAKEUP] = "WakeUp",
690 [KEY_FILE] = "File", [KEY_SENDFILE] = "SendFile",
691 [KEY_DELETEFILE] = "DeleteFile", [KEY_XFER] = "X-fer",
692 [KEY_PROG1] = "Prog1", [KEY_PROG2] = "Prog2",
693 [KEY_WWW] = "WWW", [KEY_MSDOS] = "MSDOS",
694 [KEY_COFFEE] = "Coffee", [KEY_DIRECTION] = "Direction",
695 [KEY_CYCLEWINDOWS] = "CycleWindows", [KEY_MAIL] = "Mail",
696 [KEY_BOOKMARKS] = "Bookmarks", [KEY_COMPUTER] = "Computer",
697 [KEY_BACK] = "Back", [KEY_FORWARD] = "Forward",
698 [KEY_CLOSECD] = "CloseCD", [KEY_EJECTCD] = "EjectCD",
699 [KEY_EJECTCLOSECD] = "EjectCloseCD", [KEY_NEXTSONG] = "NextSong",
700 [KEY_PLAYPAUSE] = "PlayPause", [KEY_PREVIOUSSONG] = "PreviousSong",
701 [KEY_STOPCD] = "StopCD", [KEY_RECORD] = "Record",
702 [KEY_REWIND] = "Rewind", [KEY_PHONE] = "Phone",
703 [KEY_ISO] = "ISOKey", [KEY_CONFIG] = "Config",
704 [KEY_HOMEPAGE] = "HomePage", [KEY_REFRESH] = "Refresh",
705 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
706 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
707 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
708 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
709 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
710 [KEY_F14] = "F14", [KEY_F15] = "F15",
711 [KEY_F16] = "F16", [KEY_F17] = "F17",
712 [KEY_F18] = "F18", [KEY_F19] = "F19",
713 [KEY_F20] = "F20", [KEY_F21] = "F21",
714 [KEY_F22] = "F22", [KEY_F23] = "F23",
715 [KEY_F24] = "F24", [KEY_PLAYCD] = "PlayCD",
716 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
717 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend",
718 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
719 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
720 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
721 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
722 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
723 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
724 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
725 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
726 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
727 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
728 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
729 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
730 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
731 [BTN_4] = "Btn4", [BTN_5] = "Btn5",
732 [BTN_6] = "Btn6", [BTN_7] = "Btn7",
733 [BTN_8] = "Btn8", [BTN_9] = "Btn9",
734 [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn",
735 [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn",
736 [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn",
737 [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn",
738 [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn",
739 [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn",
740 [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn",
741 [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2",
742 [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4",
743 [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6",
744 [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA",
745 [BTN_B] = "BtnB", [BTN_C] = "BtnC",
746 [BTN_X] = "BtnX", [BTN_Y] = "BtnY",
747 [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL",
748 [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2",
749 [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect",
750 [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode",
751 [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR",
752 [BTN_TOOL_PEN] = "ToolPen", [BTN_TOOL_RUBBER] = "ToolRubber",
753 [BTN_TOOL_BRUSH] = "ToolBrush", [BTN_TOOL_PENCIL] = "ToolPencil",
754 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
755 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
756 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
757 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
758 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_GEAR_DOWN] = "WheelBtn",
759 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
760 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
761 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
762 [KEY_OPTION] = "Option", [KEY_INFO] = "Info",
763 [KEY_TIME] = "Time", [KEY_VENDOR] = "Vendor",
764 [KEY_ARCHIVE] = "Archive", [KEY_PROGRAM] = "Program",
765 [KEY_CHANNEL] = "Channel", [KEY_FAVORITES] = "Favorites",
766 [KEY_EPG] = "EPG", [KEY_PVR] = "PVR",
767 [KEY_MHP] = "MHP", [KEY_LANGUAGE] = "Language",
768 [KEY_TITLE] = "Title", [KEY_SUBTITLE] = "Subtitle",
769 [KEY_ANGLE] = "Angle", [KEY_ZOOM] = "Zoom",
770 [KEY_MODE] = "Mode", [KEY_KEYBOARD] = "Keyboard",
771 [KEY_SCREEN] = "Screen", [KEY_PC] = "PC",
772 [KEY_TV] = "TV", [KEY_TV2] = "TV2",
773 [KEY_VCR] = "VCR", [KEY_VCR2] = "VCR2",
774 [KEY_SAT] = "Sat", [KEY_SAT2] = "Sat2",
775 [KEY_CD] = "CD", [KEY_TAPE] = "Tape",
776 [KEY_RADIO] = "Radio", [KEY_TUNER] = "Tuner",
777 [KEY_PLAYER] = "Player", [KEY_TEXT] = "Text",
778 [KEY_DVD] = "DVD", [KEY_AUX] = "Aux",
779 [KEY_MP3] = "MP3", [KEY_AUDIO] = "Audio",
780 [KEY_VIDEO] = "Video", [KEY_DIRECTORY] = "Directory",
781 [KEY_LIST] = "List", [KEY_MEMO] = "Memo",
782 [KEY_CALENDAR] = "Calendar", [KEY_RED] = "Red",
783 [KEY_GREEN] = "Green", [KEY_YELLOW] = "Yellow",
784 [KEY_BLUE] = "Blue", [KEY_CHANNELUP] = "ChannelUp",
785 [KEY_CHANNELDOWN] = "ChannelDown", [KEY_FIRST] = "First",
786 [KEY_LAST] = "Last", [KEY_AB] = "AB",
787 [KEY_NEXT] = "Next", [KEY_RESTART] = "Restart",
788 [KEY_SLOW] = "Slow", [KEY_SHUFFLE] = "Shuffle",
789 [KEY_BREAK] = "Break", [KEY_PREVIOUS] = "Previous",
790 [KEY_DIGITS] = "Digits", [KEY_TEEN] = "TEEN",
791 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
792 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
793 [KEY_DEL_LINE] = "DeleteLine",
794 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
795 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
Jiri Kosina1fe8736d2007-08-09 13:24:11 +0200796 [KEY_DOCUMENTS] = "Documents", [KEY_SPELLCHECK] = "SpellCheck",
Khelben Blackstaffe2bca072007-10-04 10:32:03 +0200797 [KEY_LOGOFF] = "Logoff",
Jiri Kosinac080d892007-01-25 11:43:31 +0100798 [KEY_FN] = "Fn", [KEY_FN_ESC] = "Fn+ESC",
799 [KEY_FN_1] = "Fn+1", [KEY_FN_2] = "Fn+2",
800 [KEY_FN_B] = "Fn+B", [KEY_FN_D] = "Fn+D",
801 [KEY_FN_E] = "Fn+E", [KEY_FN_F] = "Fn+F",
802 [KEY_FN_S] = "Fn+S",
803 [KEY_FN_F1] = "Fn+F1", [KEY_FN_F2] = "Fn+F2",
804 [KEY_FN_F3] = "Fn+F3", [KEY_FN_F4] = "Fn+F4",
805 [KEY_FN_F5] = "Fn+F5", [KEY_FN_F6] = "Fn+F6",
806 [KEY_FN_F7] = "Fn+F7", [KEY_FN_F8] = "Fn+F8",
807 [KEY_FN_F9] = "Fn+F9", [KEY_FN_F10] = "Fn+F10",
808 [KEY_FN_F11] = "Fn+F11", [KEY_FN_F12] = "Fn+F12",
809 [KEY_KBDILLUMTOGGLE] = "KbdIlluminationToggle",
810 [KEY_KBDILLUMDOWN] = "KbdIlluminationDown",
811 [KEY_KBDILLUMUP] = "KbdIlluminationUp",
812 [KEY_SWITCHVIDEOMODE] = "SwitchVideoMode",
813};
814
Joe Perches0ce1ac32007-09-26 16:29:53 +0200815static const char *relatives[REL_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100816 [REL_X] = "X", [REL_Y] = "Y",
817 [REL_Z] = "Z", [REL_RX] = "Rx",
818 [REL_RY] = "Ry", [REL_RZ] = "Rz",
819 [REL_HWHEEL] = "HWheel", [REL_DIAL] = "Dial",
820 [REL_WHEEL] = "Wheel", [REL_MISC] = "Misc",
821};
822
Daniel Mack81c2a3b2010-05-20 22:52:58 -0700823static const char *absolutes[ABS_CNT] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100824 [ABS_X] = "X", [ABS_Y] = "Y",
825 [ABS_Z] = "Z", [ABS_RX] = "Rx",
826 [ABS_RY] = "Ry", [ABS_RZ] = "Rz",
827 [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder",
828 [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas",
829 [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X",
830 [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X",
831 [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X",
832 [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X",
833 [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure",
834 [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200835 [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth",
Jiri Kosinac080d892007-01-25 11:43:31 +0100836 [ABS_VOLUME] = "Volume", [ABS_MISC] = "Misc",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200837 [ABS_MT_TOUCH_MAJOR] = "MTMajor",
838 [ABS_MT_TOUCH_MINOR] = "MTMinor",
839 [ABS_MT_WIDTH_MAJOR] = "MTMajorW",
840 [ABS_MT_WIDTH_MINOR] = "MTMinorW",
841 [ABS_MT_ORIENTATION] = "MTOrientation",
842 [ABS_MT_POSITION_X] = "MTPositionX",
843 [ABS_MT_POSITION_Y] = "MTPositionY",
844 [ABS_MT_TOOL_TYPE] = "MTToolType",
845 [ABS_MT_BLOB_ID] = "MTBlobID",
Jiri Kosinac080d892007-01-25 11:43:31 +0100846};
847
Joe Perches0ce1ac32007-09-26 16:29:53 +0200848static const char *misc[MSC_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100849 [MSC_SERIAL] = "Serial", [MSC_PULSELED] = "Pulseled",
850 [MSC_GESTURE] = "Gesture", [MSC_RAW] = "RawData"
851};
852
Joe Perches0ce1ac32007-09-26 16:29:53 +0200853static const char *leds[LED_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100854 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
855 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
856 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
857 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
858 [LED_MISC] = "Misc",
859};
860
Joe Perches0ce1ac32007-09-26 16:29:53 +0200861static const char *repeats[REP_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100862 [REP_DELAY] = "Delay", [REP_PERIOD] = "Period"
863};
864
Joe Perches0ce1ac32007-09-26 16:29:53 +0200865static const char *sounds[SND_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100866 [SND_CLICK] = "Click", [SND_BELL] = "Bell",
867 [SND_TONE] = "Tone"
868};
869
Joe Perches0ce1ac32007-09-26 16:29:53 +0200870static const char **names[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100871 [EV_SYN] = syncs, [EV_KEY] = keys,
872 [EV_REL] = relatives, [EV_ABS] = absolutes,
873 [EV_MSC] = misc, [EV_LED] = leds,
874 [EV_SND] = sounds, [EV_REP] = repeats,
875};
876
H Hartley Sweeten62e62da2010-01-14 19:10:07 -0700877static void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f)
878{
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200879 seq_printf(f, "%s.%s", events[type] ? events[type] : "?",
Jiri Kosinac080d892007-01-25 11:43:31 +0100880 names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
881}
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200882
H Hartley Sweeten62e62da2010-01-14 19:10:07 -0700883static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200884{
885 int i, j, k;
886 struct hid_report *report;
887 struct hid_usage *usage;
888
889 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
890 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
891 for (i = 0; i < report->maxfield; i++) {
892 for ( j = 0; j < report->field[i]->maxusage; j++) {
893 usage = report->field[i]->usage + j;
894 hid_resolv_usage(usage->hid, f);
895 seq_printf(f, " ---> ");
896 hid_resolv_event(usage->type, usage->code, f);
897 seq_printf(f, "\n");
898 }
899 }
900 }
901 }
902
903}
904
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200905
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200906static int hid_debug_rdesc_show(struct seq_file *f, void *p)
907{
908 struct hid_device *hdev = f->private;
909 int i;
910
911 /* dump HID report descriptor */
912 for (i = 0; i < hdev->rsize; i++)
913 seq_printf(f, "%02x ", hdev->rdesc[i]);
914 seq_printf(f, "\n\n");
915
916 /* dump parsed data and input mappings */
917 hid_dump_device(hdev, f);
918 seq_printf(f, "\n");
919 hid_dump_input_mapping(hdev, f);
920
921 return 0;
922}
923
924static int hid_debug_rdesc_open(struct inode *inode, struct file *file)
925{
926 return single_open(file, hid_debug_rdesc_show, inode->i_private);
927}
928
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200929static int hid_debug_events_open(struct inode *inode, struct file *file)
930{
931 int err = 0;
932 struct hid_debug_list *list;
933
934 if (!(list = kzalloc(sizeof(struct hid_debug_list), GFP_KERNEL))) {
935 err = -ENOMEM;
936 goto out;
937 }
938
939 if (!(list->hid_debug_buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_KERNEL))) {
940 err = -ENOMEM;
Julia Lawalla809dda2009-08-08 02:26:10 +0200941 kfree(list);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200942 goto out;
943 }
944 list->hdev = (struct hid_device *) inode->i_private;
945 file->private_data = list;
946 mutex_init(&list->read_mutex);
947
948 list_add_tail(&list->node, &list->hdev->debug_list);
949
950out:
951 return err;
952}
953
954static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
955 size_t count, loff_t *ppos)
956{
957 struct hid_debug_list *list = file->private_data;
958 int ret = 0, len;
959 DECLARE_WAITQUEUE(wait, current);
960
Julia Lawallca9fe152010-06-20 13:24:35 +0200961 mutex_lock(&list->read_mutex);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200962 while (ret == 0) {
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200963 if (list->head == list->tail) {
964 add_wait_queue(&list->hdev->debug_wait, &wait);
965 set_current_state(TASK_INTERRUPTIBLE);
966
967 while (list->head == list->tail) {
968 if (file->f_flags & O_NONBLOCK) {
969 ret = -EAGAIN;
970 break;
971 }
972 if (signal_pending(current)) {
973 ret = -ERESTARTSYS;
974 break;
975 }
976
977 if (!list->hdev || !list->hdev->debug) {
978 ret = -EIO;
979 break;
980 }
981
982 /* allow O_NONBLOCK from other threads */
983 mutex_unlock(&list->read_mutex);
984 schedule();
985 mutex_lock(&list->read_mutex);
986 set_current_state(TASK_INTERRUPTIBLE);
987 }
988
989 set_current_state(TASK_RUNNING);
990 remove_wait_queue(&list->hdev->debug_wait, &wait);
991 }
992
993 if (ret)
994 goto out;
995
996 /* pass the ringbuffer contents to userspace */
997copy_rest:
998 if (list->tail == list->head)
999 goto out;
1000 if (list->tail > list->head) {
1001 len = list->tail - list->head;
1002
1003 if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) {
1004 ret = -EFAULT;
1005 goto out;
1006 }
1007 ret += len;
1008 list->head += len;
1009 } else {
1010 len = HID_DEBUG_BUFSIZE - list->head;
1011
1012 if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) {
1013 ret = -EFAULT;
1014 goto out;
1015 }
1016 list->head = 0;
1017 ret += len;
1018 goto copy_rest;
1019 }
1020
1021 }
1022out:
1023 mutex_unlock(&list->read_mutex);
1024 return ret;
1025}
1026
1027static unsigned int hid_debug_events_poll(struct file *file, poll_table *wait)
1028{
1029 struct hid_debug_list *list = file->private_data;
1030
1031 poll_wait(file, &list->hdev->debug_wait, wait);
1032 if (list->head != list->tail)
1033 return POLLIN | POLLRDNORM;
1034 if (!list->hdev->debug)
1035 return POLLERR | POLLHUP;
1036 return 0;
1037}
1038
1039static int hid_debug_events_release(struct inode *inode, struct file *file)
1040{
1041 struct hid_debug_list *list = file->private_data;
1042
1043 list_del(&list->node);
1044 kfree(list->hid_debug_buf);
1045 kfree(list);
1046
1047 return 0;
1048}
1049
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001050static const struct file_operations hid_debug_rdesc_fops = {
1051 .open = hid_debug_rdesc_open,
1052 .read = seq_read,
1053 .llseek = seq_lseek,
1054 .release = single_release,
1055};
1056
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001057static const struct file_operations hid_debug_events_fops = {
1058 .owner = THIS_MODULE,
1059 .open = hid_debug_events_open,
1060 .read = hid_debug_events_read,
1061 .poll = hid_debug_events_poll,
1062 .release = hid_debug_events_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001063 .llseek = noop_llseek,
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001064};
1065
1066
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001067void hid_debug_register(struct hid_device *hdev, const char *name)
1068{
1069 hdev->debug_dir = debugfs_create_dir(name, hid_debug_root);
1070 hdev->debug_rdesc = debugfs_create_file("rdesc", 0400,
1071 hdev->debug_dir, hdev, &hid_debug_rdesc_fops);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001072 hdev->debug_events = debugfs_create_file("events", 0400,
1073 hdev->debug_dir, hdev, &hid_debug_events_fops);
1074 hdev->debug = 1;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001075}
1076
1077void hid_debug_unregister(struct hid_device *hdev)
1078{
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001079 hdev->debug = 0;
1080 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001081 debugfs_remove(hdev->debug_rdesc);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001082 debugfs_remove(hdev->debug_events);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001083 debugfs_remove(hdev->debug_dir);
1084}
1085
1086void hid_debug_init(void)
1087{
1088 hid_debug_root = debugfs_create_dir("hid", NULL);
1089}
1090
1091void hid_debug_exit(void)
1092{
1093 debugfs_remove_recursive(hid_debug_root);
1094}
1095