1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (c) 1999 Andreas Gal <gal@cs.uni-magdeburg.de>
4 * (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz>
5 * (c) 2007-2009 Jiri Kosina
7 * HID debugging support
12 * Should you need to contact me, the author, you can do so either by
13 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
14 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/debugfs.h>
20 #include <linux/seq_file.h>
21 #include <linux/kfifo.h>
22 #include <linux/sched/signal.h>
23 #include <linux/export.h>
24 #include <linux/slab.h>
25 #include <linux/uaccess.h>
26 #include <linux/poll.h>
28 #include <linux/hid.h>
29 #include <linux/hid-debug.h>
31 static struct dentry *hid_debug_root;
33 struct hid_usage_entry {
36 const char *description;
39 static const struct hid_usage_entry hid_usage_table[] = {
40 { 0, 0, "Undefined" },
41 { 1, 0, "GenericDesktop" },
44 {0, 0x04, "Joystick"},
46 {0, 0x06, "Keyboard"},
48 {0, 0x08, "MultiAxis"},
58 {0, 0x39, "HatSwitch"},
59 {0, 0x3a, "CountedBuffer"},
60 {0, 0x3b, "ByteCount"},
61 {0, 0x3c, "MotionWakeup"},
71 {0, 0x80, "SystemControl"},
72 {0, 0x81, "SystemPowerDown"},
73 {0, 0x82, "SystemSleep"},
74 {0, 0x83, "SystemWakeUp"},
75 {0, 0x84, "SystemContextMenu"},
76 {0, 0x85, "SystemMainMenu"},
77 {0, 0x86, "SystemAppMenu"},
78 {0, 0x87, "SystemMenuHelp"},
79 {0, 0x88, "SystemMenuExit"},
80 {0, 0x89, "SystemMenuSelect"},
81 {0, 0x8a, "SystemMenuRight"},
82 {0, 0x8b, "SystemMenuLeft"},
83 {0, 0x8c, "SystemMenuUp"},
84 {0, 0x8d, "SystemMenuDown"},
86 {0, 0x91, "D-PadDown"},
87 {0, 0x92, "D-PadRight"},
88 {0, 0x93, "D-PadLeft"},
89 { 2, 0, "Simulation" },
91 {0, 0xb1, "AileronTrim"},
92 {0, 0xb2, "Anti-Torque"},
93 {0, 0xb3, "Autopilot"},
95 {0, 0xb5, "Collective"},
96 {0, 0xb6, "DiveBrake"},
97 {0, 0xb7, "ElectronicCountermeasures"},
98 {0, 0xb8, "Elevator"},
99 {0, 0xb9, "ElevatorTrim"},
101 {0, 0xbb, "Throttle"},
102 {0, 0xbc, "FlightCommunications"},
103 {0, 0xbd, "FlareRelease"},
104 {0, 0xbe, "LandingGear"},
105 {0, 0xbf, "ToeBrake"},
106 { 6, 0, "GenericDeviceControls" },
107 {0, 0x20, "BatteryStrength" },
108 {0, 0x21, "WirelessChannel" },
109 {0, 0x22, "WirelessID" },
110 {0, 0x23, "DiscoverWirelessControl" },
111 {0, 0x24, "SecurityCodeCharacterEntered" },
112 {0, 0x25, "SecurityCodeCharactedErased" },
113 {0, 0x26, "SecurityCodeCleared" },
114 { 7, 0, "Keyboard" },
116 {0, 0x01, "NumLock"},
117 {0, 0x02, "CapsLock"},
118 {0, 0x03, "ScrollLock"},
119 {0, 0x04, "Compose"},
121 {0, 0x4b, "GenericIndicator"},
123 { 10, 0, "Ordinal" },
124 { 12, 0, "Consumer" },
125 {0, 0x003, "ProgrammableButtons"},
126 {0, 0x238, "HorizontalWheel"},
127 { 13, 0, "Digitizers" },
128 {0, 0x01, "Digitizer"},
130 {0, 0x03, "LightPen"},
131 {0, 0x04, "TouchScreen"},
132 {0, 0x05, "TouchPad"},
133 {0, 0x0e, "DeviceConfiguration"},
137 {0, 0x23, "DeviceSettings"},
138 {0, 0x30, "TipPressure"},
139 {0, 0x31, "BarrelPressure"},
140 {0, 0x32, "InRange"},
142 {0, 0x34, "UnTouch"},
144 {0, 0x39, "TabletFunctionKey"},
145 {0, 0x3a, "ProgramChangeKey"},
147 {0, 0x42, "TipSwitch"},
148 {0, 0x43, "SecondaryTipSwitch"},
149 {0, 0x44, "BarrelSwitch"},
151 {0, 0x46, "TabletPick"},
152 {0, 0x47, "Confidence"},
155 {0, 0x51, "ContactID"},
156 {0, 0x52, "InputMode"},
157 {0, 0x53, "DeviceIndex"},
158 {0, 0x54, "ContactCount"},
159 {0, 0x55, "ContactMaximumNumber"},
160 {0, 0x59, "ButtonType"},
161 {0, 0x5A, "SecondaryBarrelSwitch"},
162 {0, 0x5B, "TransducerSerialNumber"},
163 { 15, 0, "PhysicalInterfaceDevice" },
164 {0, 0x00, "Undefined"},
165 {0, 0x01, "Physical_Interface_Device"},
167 {0, 0x21, "Set_Effect_Report"},
168 {0, 0x22, "Effect_Block_Index"},
169 {0, 0x23, "Parameter_Block_Offset"},
170 {0, 0x24, "ROM_Flag"},
171 {0, 0x25, "Effect_Type"},
172 {0, 0x26, "ET_Constant_Force"},
173 {0, 0x27, "ET_Ramp"},
174 {0, 0x28, "ET_Custom_Force_Data"},
175 {0, 0x30, "ET_Square"},
176 {0, 0x31, "ET_Sine"},
177 {0, 0x32, "ET_Triangle"},
178 {0, 0x33, "ET_Sawtooth_Up"},
179 {0, 0x34, "ET_Sawtooth_Down"},
180 {0, 0x40, "ET_Spring"},
181 {0, 0x41, "ET_Damper"},
182 {0, 0x42, "ET_Inertia"},
183 {0, 0x43, "ET_Friction"},
184 {0, 0x50, "Duration"},
185 {0, 0x51, "Sample_Period"},
187 {0, 0x53, "Trigger_Button"},
188 {0, 0x54, "Trigger_Repeat_Interval"},
189 {0, 0x55, "Axes_Enable"},
190 {0, 0x56, "Direction_Enable"},
191 {0, 0x57, "Direction"},
192 {0, 0x58, "Type_Specific_Block_Offset"},
193 {0, 0x59, "Block_Type"},
194 {0, 0x5A, "Set_Envelope_Report"},
195 {0, 0x5B, "Attack_Level"},
196 {0, 0x5C, "Attack_Time"},
197 {0, 0x5D, "Fade_Level"},
198 {0, 0x5E, "Fade_Time"},
199 {0, 0x5F, "Set_Condition_Report"},
200 {0, 0x60, "CP_Offset"},
201 {0, 0x61, "Positive_Coefficient"},
202 {0, 0x62, "Negative_Coefficient"},
203 {0, 0x63, "Positive_Saturation"},
204 {0, 0x64, "Negative_Saturation"},
205 {0, 0x65, "Dead_Band"},
206 {0, 0x66, "Download_Force_Sample"},
207 {0, 0x67, "Isoch_Custom_Force_Enable"},
208 {0, 0x68, "Custom_Force_Data_Report"},
209 {0, 0x69, "Custom_Force_Data"},
210 {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
211 {0, 0x6B, "Set_Custom_Force_Report"},
212 {0, 0x6C, "Custom_Force_Data_Offset"},
213 {0, 0x6D, "Sample_Count"},
214 {0, 0x6E, "Set_Periodic_Report"},
216 {0, 0x70, "Magnitude"},
219 {0, 0x73, "Set_Constant_Force_Report"},
220 {0, 0x74, "Set_Ramp_Force_Report"},
221 {0, 0x75, "Ramp_Start"},
222 {0, 0x76, "Ramp_End"},
223 {0, 0x77, "Effect_Operation_Report"},
224 {0, 0x78, "Effect_Operation"},
225 {0, 0x79, "Op_Effect_Start"},
226 {0, 0x7A, "Op_Effect_Start_Solo"},
227 {0, 0x7B, "Op_Effect_Stop"},
228 {0, 0x7C, "Loop_Count"},
229 {0, 0x7D, "Device_Gain_Report"},
230 {0, 0x7E, "Device_Gain"},
231 {0, 0x7F, "PID_Pool_Report"},
232 {0, 0x80, "RAM_Pool_Size"},
233 {0, 0x81, "ROM_Pool_Size"},
234 {0, 0x82, "ROM_Effect_Block_Count"},
235 {0, 0x83, "Simultaneous_Effects_Max"},
236 {0, 0x84, "Pool_Alignment"},
237 {0, 0x85, "PID_Pool_Move_Report"},
238 {0, 0x86, "Move_Source"},
239 {0, 0x87, "Move_Destination"},
240 {0, 0x88, "Move_Length"},
241 {0, 0x89, "PID_Block_Load_Report"},
242 {0, 0x8B, "Block_Load_Status"},
243 {0, 0x8C, "Block_Load_Success"},
244 {0, 0x8D, "Block_Load_Full"},
245 {0, 0x8E, "Block_Load_Error"},
246 {0, 0x8F, "Block_Handle"},
247 {0, 0x90, "PID_Block_Free_Report"},
248 {0, 0x91, "Type_Specific_Block_Handle"},
249 {0, 0x92, "PID_State_Report"},
250 {0, 0x94, "Effect_Playing"},
251 {0, 0x95, "PID_Device_Control_Report"},
252 {0, 0x96, "PID_Device_Control"},
253 {0, 0x97, "DC_Enable_Actuators"},
254 {0, 0x98, "DC_Disable_Actuators"},
255 {0, 0x99, "DC_Stop_All_Effects"},
256 {0, 0x9A, "DC_Device_Reset"},
257 {0, 0x9B, "DC_Device_Pause"},
258 {0, 0x9C, "DC_Device_Continue"},
259 {0, 0x9F, "Device_Paused"},
260 {0, 0xA0, "Actuators_Enabled"},
261 {0, 0xA4, "Safety_Switch"},
262 {0, 0xA5, "Actuator_Override_Switch"},
263 {0, 0xA6, "Actuator_Power"},
264 {0, 0xA7, "Start_Delay"},
265 {0, 0xA8, "Parameter_Block_Size"},
266 {0, 0xA9, "Device_Managed_Pool"},
267 {0, 0xAA, "Shared_Parameter_Blocks"},
268 {0, 0xAB, "Create_New_Effect_Report"},
269 {0, 0xAC, "RAM_Pool_Available"},
270 { 0x20, 0, "Sensor" },
271 { 0x20, 0x01, "Sensor" },
272 { 0x20, 0x10, "Biometric" },
273 { 0x20, 0x11, "BiometricHumanPresence" },
274 { 0x20, 0x12, "BiometricHumanProximity" },
275 { 0x20, 0x13, "BiometricHumanTouch" },
276 { 0x20, 0x20, "Electrical" },
277 { 0x20, 0x21, "ElectricalCapacitance" },
278 { 0x20, 0x22, "ElectricalCurrent" },
279 { 0x20, 0x23, "ElectricalPower" },
280 { 0x20, 0x24, "ElectricalInductance" },
281 { 0x20, 0x25, "ElectricalResistance" },
282 { 0x20, 0x26, "ElectricalVoltage" },
283 { 0x20, 0x27, "ElectricalPoteniometer" },
284 { 0x20, 0x28, "ElectricalFrequency" },
285 { 0x20, 0x29, "ElectricalPeriod" },
286 { 0x20, 0x30, "Environmental" },
287 { 0x20, 0x31, "EnvironmentalAtmosphericPressure" },
288 { 0x20, 0x32, "EnvironmentalHumidity" },
289 { 0x20, 0x33, "EnvironmentalTemperature" },
290 { 0x20, 0x34, "EnvironmentalWindDirection" },
291 { 0x20, 0x35, "EnvironmentalWindSpeed" },
292 { 0x20, 0x40, "Light" },
293 { 0x20, 0x41, "LightAmbientLight" },
294 { 0x20, 0x42, "LightConsumerInfrared" },
295 { 0x20, 0x50, "Location" },
296 { 0x20, 0x51, "LocationBroadcast" },
297 { 0x20, 0x52, "LocationDeadReckoning" },
298 { 0x20, 0x53, "LocationGPS" },
299 { 0x20, 0x54, "LocationLookup" },
300 { 0x20, 0x55, "LocationOther" },
301 { 0x20, 0x56, "LocationStatic" },
302 { 0x20, 0x57, "LocationTriangulation" },
303 { 0x20, 0x60, "Mechanical" },
304 { 0x20, 0x61, "MechanicalBooleanSwitch" },
305 { 0x20, 0x62, "MechanicalBooleanSwitchArray" },
306 { 0x20, 0x63, "MechanicalMultivalueSwitch" },
307 { 0x20, 0x64, "MechanicalForce" },
308 { 0x20, 0x65, "MechanicalPressure" },
309 { 0x20, 0x66, "MechanicalStrain" },
310 { 0x20, 0x67, "MechanicalWeight" },
311 { 0x20, 0x68, "MechanicalHapticVibrator" },
312 { 0x20, 0x69, "MechanicalHallEffectSwitch" },
313 { 0x20, 0x70, "Motion" },
314 { 0x20, 0x71, "MotionAccelerometer1D" },
315 { 0x20, 0x72, "MotionAccelerometer2D" },
316 { 0x20, 0x73, "MotionAccelerometer3D" },
317 { 0x20, 0x74, "MotionGyrometer1D" },
318 { 0x20, 0x75, "MotionGyrometer2D" },
319 { 0x20, 0x76, "MotionGyrometer3D" },
320 { 0x20, 0x77, "MotionMotionDetector" },
321 { 0x20, 0x78, "MotionSpeedometer" },
322 { 0x20, 0x79, "MotionAccelerometer" },
323 { 0x20, 0x7A, "MotionGyrometer" },
324 { 0x20, 0x80, "Orientation" },
325 { 0x20, 0x81, "OrientationCompass1D" },
326 { 0x20, 0x82, "OrientationCompass2D" },
327 { 0x20, 0x83, "OrientationCompass3D" },
328 { 0x20, 0x84, "OrientationInclinometer1D" },
329 { 0x20, 0x85, "OrientationInclinometer2D" },
330 { 0x20, 0x86, "OrientationInclinometer3D" },
331 { 0x20, 0x87, "OrientationDistance1D" },
332 { 0x20, 0x88, "OrientationDistance2D" },
333 { 0x20, 0x89, "OrientationDistance3D" },
334 { 0x20, 0x8A, "OrientationDeviceOrientation" },
335 { 0x20, 0x8B, "OrientationCompass" },
336 { 0x20, 0x8C, "OrientationInclinometer" },
337 { 0x20, 0x8D, "OrientationDistance" },
338 { 0x20, 0x90, "Scanner" },
339 { 0x20, 0x91, "ScannerBarcode" },
340 { 0x20, 0x91, "ScannerRFID" },
341 { 0x20, 0x91, "ScannerNFC" },
342 { 0x20, 0xA0, "Time" },
343 { 0x20, 0xA1, "TimeAlarmTimer" },
344 { 0x20, 0xA2, "TimeRealTimeClock" },
345 { 0x20, 0xE0, "Other" },
346 { 0x20, 0xE1, "OtherCustom" },
347 { 0x20, 0xE2, "OtherGeneric" },
348 { 0x20, 0xE3, "OtherGenericEnumerator" },
349 { 0x84, 0, "Power Device" },
350 { 0x84, 0x02, "PresentStatus" },
351 { 0x84, 0x03, "ChangeStatus" },
352 { 0x84, 0x04, "UPS" },
353 { 0x84, 0x05, "PowerSupply" },
354 { 0x84, 0x10, "BatterySystem" },
355 { 0x84, 0x11, "BatterySystemID" },
356 { 0x84, 0x12, "Battery" },
357 { 0x84, 0x13, "BatteryID" },
358 { 0x84, 0x14, "Charger" },
359 { 0x84, 0x15, "ChargerID" },
360 { 0x84, 0x16, "PowerConverter" },
361 { 0x84, 0x17, "PowerConverterID" },
362 { 0x84, 0x18, "OutletSystem" },
363 { 0x84, 0x19, "OutletSystemID" },
364 { 0x84, 0x1a, "Input" },
365 { 0x84, 0x1b, "InputID" },
366 { 0x84, 0x1c, "Output" },
367 { 0x84, 0x1d, "OutputID" },
368 { 0x84, 0x1e, "Flow" },
369 { 0x84, 0x1f, "FlowID" },
370 { 0x84, 0x20, "Outlet" },
371 { 0x84, 0x21, "OutletID" },
372 { 0x84, 0x22, "Gang" },
373 { 0x84, 0x24, "PowerSummary" },
374 { 0x84, 0x25, "PowerSummaryID" },
375 { 0x84, 0x30, "Voltage" },
376 { 0x84, 0x31, "Current" },
377 { 0x84, 0x32, "Frequency" },
378 { 0x84, 0x33, "ApparentPower" },
379 { 0x84, 0x35, "PercentLoad" },
380 { 0x84, 0x40, "ConfigVoltage" },
381 { 0x84, 0x41, "ConfigCurrent" },
382 { 0x84, 0x43, "ConfigApparentPower" },
383 { 0x84, 0x53, "LowVoltageTransfer" },
384 { 0x84, 0x54, "HighVoltageTransfer" },
385 { 0x84, 0x56, "DelayBeforeStartup" },
386 { 0x84, 0x57, "DelayBeforeShutdown" },
387 { 0x84, 0x58, "Test" },
388 { 0x84, 0x5a, "AudibleAlarmControl" },
389 { 0x84, 0x60, "Present" },
390 { 0x84, 0x61, "Good" },
391 { 0x84, 0x62, "InternalFailure" },
392 { 0x84, 0x65, "Overload" },
393 { 0x84, 0x66, "OverCharged" },
394 { 0x84, 0x67, "OverTemperature" },
395 { 0x84, 0x68, "ShutdownRequested" },
396 { 0x84, 0x69, "ShutdownImminent" },
397 { 0x84, 0x6b, "SwitchOn/Off" },
398 { 0x84, 0x6c, "Switchable" },
399 { 0x84, 0x6d, "Used" },
400 { 0x84, 0x6e, "Boost" },
401 { 0x84, 0x73, "CommunicationLost" },
402 { 0x84, 0xfd, "iManufacturer" },
403 { 0x84, 0xfe, "iProduct" },
404 { 0x84, 0xff, "iSerialNumber" },
405 { 0x85, 0, "Battery System" },
406 { 0x85, 0x01, "SMBBatteryMode" },
407 { 0x85, 0x02, "SMBBatteryStatus" },
408 { 0x85, 0x03, "SMBAlarmWarning" },
409 { 0x85, 0x04, "SMBChargerMode" },
410 { 0x85, 0x05, "SMBChargerStatus" },
411 { 0x85, 0x06, "SMBChargerSpecInfo" },
412 { 0x85, 0x07, "SMBSelectorState" },
413 { 0x85, 0x08, "SMBSelectorPresets" },
414 { 0x85, 0x09, "SMBSelectorInfo" },
415 { 0x85, 0x29, "RemainingCapacityLimit" },
416 { 0x85, 0x2c, "CapacityMode" },
417 { 0x85, 0x42, "BelowRemainingCapacityLimit" },
418 { 0x85, 0x44, "Charging" },
419 { 0x85, 0x45, "Discharging" },
420 { 0x85, 0x4b, "NeedReplacement" },
421 { 0x85, 0x65, "AbsoluteStateOfCharge" },
422 { 0x85, 0x66, "RemainingCapacity" },
423 { 0x85, 0x68, "RunTimeToEmpty" },
424 { 0x85, 0x6a, "AverageTimeToFull" },
425 { 0x85, 0x83, "DesignCapacity" },
426 { 0x85, 0x85, "ManufacturerDate" },
427 { 0x85, 0x89, "iDeviceChemistry" },
428 { 0x85, 0x8b, "Rechargeable" },
429 { 0x85, 0x8f, "iOEMInformation" },
430 { 0x85, 0x8d, "CapacityGranularity1" },
431 { 0x85, 0xd0, "ACPresent" },
432 /* pages 0xff00 to 0xffff are vendor-specific */
433 { 0xffff, 0, "Vendor-specific-FF" },
437 /* Either output directly into simple seq_file, or (if f == NULL)
438 * allocate a separate buffer that will then be passed to the 'events'
441 * This is because these functions can be called both for "one-shot"
442 * "rdesc" while resolving, or for blocking "events".
444 * This holds both for resolv_usage_page() and hid_resolv_usage().
446 static char *resolv_usage_page(unsigned page, struct seq_file *f) {
447 const struct hid_usage_entry *p;
451 buf = kzalloc(HID_DEBUG_BUFSIZE, GFP_ATOMIC);
453 return ERR_PTR(-ENOMEM);
456 for (p = hid_usage_table; p->description; p++)
457 if (p->page == page) {
459 snprintf(buf, HID_DEBUG_BUFSIZE, "%s",
464 seq_printf(f, "%s", p->description);
469 snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page);
471 seq_printf(f, "%04x", page);
475 char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
476 const struct hid_usage_entry *p;
480 buf = resolv_usage_page(usage >> 16, f);
482 pr_err("error allocating HID debug buffer\n");
489 snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), ".");
495 for (p = hid_usage_table; p->description; p++)
496 if (p->page == (usage >> 16)) {
497 for(++p; p->description && p->usage != 0; p++)
498 if (p->usage == (usage & 0xffff)) {
501 max(0,HID_DEBUG_BUFSIZE - len - 1),
502 "%s", p->description);
512 snprintf(buf + len, max(0, HID_DEBUG_BUFSIZE - len - 1),
513 "%04x", usage & 0xffff);
515 seq_printf(f, "%04x", usage & 0xffff);
518 EXPORT_SYMBOL_GPL(hid_resolv_usage);
520 static void tab(int n, struct seq_file *f) {
521 seq_printf(f, "%*s", n, "");
524 void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {
527 if (field->physical) {
529 seq_printf(f, "Physical(");
530 hid_resolv_usage(field->physical, f); seq_printf(f, ")\n");
532 if (field->logical) {
534 seq_printf(f, "Logical(");
535 hid_resolv_usage(field->logical, f); seq_printf(f, ")\n");
537 if (field->application) {
539 seq_printf(f, "Application(");
540 hid_resolv_usage(field->application, f); seq_printf(f, ")\n");
542 tab(n, f); seq_printf(f, "Usage(%d)\n", field->maxusage);
543 for (j = 0; j < field->maxusage; j++) {
544 tab(n+2, f); hid_resolv_usage(field->usage[j].hid, f); seq_printf(f, "\n");
546 if (field->logical_minimum != field->logical_maximum) {
547 tab(n, f); seq_printf(f, "Logical Minimum(%d)\n", field->logical_minimum);
548 tab(n, f); seq_printf(f, "Logical Maximum(%d)\n", field->logical_maximum);
550 if (field->physical_minimum != field->physical_maximum) {
551 tab(n, f); seq_printf(f, "Physical Minimum(%d)\n", field->physical_minimum);
552 tab(n, f); seq_printf(f, "Physical Maximum(%d)\n", field->physical_maximum);
554 if (field->unit_exponent) {
555 tab(n, f); seq_printf(f, "Unit Exponent(%d)\n", field->unit_exponent);
558 static const char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
559 static const char *units[5][8] = {
560 { "None", "None", "None", "None", "None", "None", "None", "None" },
561 { "None", "Centimeter", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
562 { "None", "Radians", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
563 { "None", "Inch", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" },
564 { "None", "Degrees", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }
569 __u32 data = field->unit;
571 /* First nibble tells us which system we're in. */
576 tab(n, f); seq_printf(f, "Unit(Invalid)\n");
579 int earlier_unit = 0;
581 tab(n, f); seq_printf(f, "Unit(%s : ", systems[sys]);
583 for (i=1 ; i<sizeof(__u32)*2 ; i++) {
584 char nibble = data & 0xf;
587 if(earlier_unit++ > 0)
589 seq_printf(f, "%s", units[sys][i]);
591 /* This is a _signed_ nibble(!) */
593 int val = nibble & 0x7;
595 val = -((0x7 & ~val) +1);
596 seq_printf(f, "^%d", val);
600 seq_printf(f, ")\n");
603 tab(n, f); seq_printf(f, "Report Size(%u)\n", field->report_size);
604 tab(n, f); seq_printf(f, "Report Count(%u)\n", field->report_count);
605 tab(n, f); seq_printf(f, "Report Offset(%u)\n", field->report_offset);
607 tab(n, f); seq_printf(f, "Flags( ");
609 seq_printf(f, "%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
610 seq_printf(f, "%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
611 seq_printf(f, "%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
612 seq_printf(f, "%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
613 seq_printf(f, "%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
614 seq_printf(f, "%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPreferredState " : "");
615 seq_printf(f, "%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
616 seq_printf(f, "%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
617 seq_printf(f, "%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
618 seq_printf(f, ")\n");
620 EXPORT_SYMBOL_GPL(hid_dump_field);
622 void hid_dump_device(struct hid_device *device, struct seq_file *f)
624 struct hid_report_enum *report_enum;
625 struct hid_report *report;
626 struct list_head *list;
628 static const char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
630 for (i = 0; i < HID_REPORT_TYPES; i++) {
631 report_enum = device->report_enum + i;
632 list = report_enum->report_list.next;
633 while (list != &report_enum->report_list) {
634 report = (struct hid_report *) list;
636 seq_printf(f, "%s", table[i]);
638 seq_printf(f, "(%d)", report->id);
639 seq_printf(f, "[%s]", table[report->type]);
641 for (k = 0; k < report->maxfield; k++) {
643 seq_printf(f, "Field(%d)\n", k);
644 hid_dump_field(report->field[k], 6, f);
650 EXPORT_SYMBOL_GPL(hid_dump_device);
652 /* enqueue string to 'events' ring buffer */
653 void hid_debug_event(struct hid_device *hdev, char *buf)
655 struct hid_debug_list *list;
658 spin_lock_irqsave(&hdev->debug_list_lock, flags);
659 list_for_each_entry(list, &hdev->debug_list, node)
660 kfifo_in(&list->hid_debug_fifo, buf, strlen(buf));
661 spin_unlock_irqrestore(&hdev->debug_list_lock, flags);
663 wake_up_interruptible(&hdev->debug_wait);
665 EXPORT_SYMBOL_GPL(hid_debug_event);
667 void hid_dump_report(struct hid_device *hid, int type, u8 *data,
670 struct hid_report_enum *report_enum;
674 buf = kmalloc(HID_DEBUG_BUFSIZE, GFP_ATOMIC);
679 report_enum = hid->report_enum + type;
681 /* dump the report */
682 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
683 "\nreport (size %u) (%snumbered) = ", size,
684 report_enum->numbered ? "" : "un");
685 hid_debug_event(hid, buf);
687 for (i = 0; i < size; i++) {
688 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
690 hid_debug_event(hid, buf);
692 hid_debug_event(hid, "\n");
695 EXPORT_SYMBOL_GPL(hid_dump_report);
697 void hid_dump_input(struct hid_device *hdev, struct hid_usage *usage, __s32 value)
702 buf = hid_resolv_usage(usage->hid, NULL);
706 snprintf(buf + len, HID_DEBUG_BUFSIZE - len - 1, " = %d\n", value);
708 hid_debug_event(hdev, buf);
711 wake_up_interruptible(&hdev->debug_wait);
713 EXPORT_SYMBOL_GPL(hid_dump_input);
715 static const char *events[EV_MAX + 1] = {
716 [EV_SYN] = "Sync", [EV_KEY] = "Key",
717 [EV_REL] = "Relative", [EV_ABS] = "Absolute",
718 [EV_MSC] = "Misc", [EV_LED] = "LED",
719 [EV_SND] = "Sound", [EV_REP] = "Repeat",
720 [EV_FF] = "ForceFeedback", [EV_PWR] = "Power",
721 [EV_FF_STATUS] = "ForceFeedbackStatus",
724 static const char *syncs[3] = {
725 [SYN_REPORT] = "Report", [SYN_CONFIG] = "Config",
726 [SYN_MT_REPORT] = "MT Report",
729 static const char *keys[KEY_MAX + 1] = {
730 [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc",
731 [KEY_1] = "1", [KEY_2] = "2",
732 [KEY_3] = "3", [KEY_4] = "4",
733 [KEY_5] = "5", [KEY_6] = "6",
734 [KEY_7] = "7", [KEY_8] = "8",
735 [KEY_9] = "9", [KEY_0] = "0",
736 [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal",
737 [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab",
738 [KEY_Q] = "Q", [KEY_W] = "W",
739 [KEY_E] = "E", [KEY_R] = "R",
740 [KEY_T] = "T", [KEY_Y] = "Y",
741 [KEY_U] = "U", [KEY_I] = "I",
742 [KEY_O] = "O", [KEY_P] = "P",
743 [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace",
744 [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl",
745 [KEY_A] = "A", [KEY_S] = "S",
746 [KEY_D] = "D", [KEY_F] = "F",
747 [KEY_G] = "G", [KEY_H] = "H",
748 [KEY_J] = "J", [KEY_K] = "K",
749 [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon",
750 [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave",
751 [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash",
752 [KEY_Z] = "Z", [KEY_X] = "X",
753 [KEY_C] = "C", [KEY_V] = "V",
754 [KEY_B] = "B", [KEY_N] = "N",
755 [KEY_M] = "M", [KEY_COMMA] = "Comma",
756 [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash",
757 [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk",
758 [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space",
759 [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1",
760 [KEY_F2] = "F2", [KEY_F3] = "F3",
761 [KEY_F4] = "F4", [KEY_F5] = "F5",
762 [KEY_F6] = "F6", [KEY_F7] = "F7",
763 [KEY_F8] = "F8", [KEY_F9] = "F9",
764 [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock",
765 [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7",
766 [KEY_KP8] = "KP8", [KEY_KP9] = "KP9",
767 [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4",
768 [KEY_KP5] = "KP5", [KEY_KP6] = "KP6",
769 [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1",
770 [KEY_KP2] = "KP2", [KEY_KP3] = "KP3",
771 [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot",
772 [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd",
773 [KEY_F11] = "F11", [KEY_F12] = "F12",
774 [KEY_RO] = "RO", [KEY_KATAKANA] = "Katakana",
775 [KEY_HIRAGANA] = "HIRAGANA", [KEY_HENKAN] = "Henkan",
776 [KEY_KATAKANAHIRAGANA] = "Katakana/Hiragana", [KEY_MUHENKAN] = "Muhenkan",
777 [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter",
778 [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash",
779 [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt",
780 [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home",
781 [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp",
782 [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right",
783 [KEY_END] = "End", [KEY_DOWN] = "Down",
784 [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert",
785 [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro",
786 [KEY_MUTE] = "Mute", [KEY_VOLUMEDOWN] = "VolumeDown",
787 [KEY_VOLUMEUP] = "VolumeUp", [KEY_POWER] = "Power",
788 [KEY_KPEQUAL] = "KPEqual", [KEY_KPPLUSMINUS] = "KPPlusMinus",
789 [KEY_PAUSE] = "Pause", [KEY_KPCOMMA] = "KPComma",
790 [KEY_HANGUEL] = "Hangeul", [KEY_HANJA] = "Hanja",
791 [KEY_YEN] = "Yen", [KEY_LEFTMETA] = "LeftMeta",
792 [KEY_RIGHTMETA] = "RightMeta", [KEY_COMPOSE] = "Compose",
793 [KEY_STOP] = "Stop", [KEY_AGAIN] = "Again",
794 [KEY_PROPS] = "Props", [KEY_UNDO] = "Undo",
795 [KEY_FRONT] = "Front", [KEY_COPY] = "Copy",
796 [KEY_OPEN] = "Open", [KEY_PASTE] = "Paste",
797 [KEY_FIND] = "Find", [KEY_CUT] = "Cut",
798 [KEY_HELP] = "Help", [KEY_MENU] = "Menu",
799 [KEY_CALC] = "Calc", [KEY_SETUP] = "Setup",
800 [KEY_SLEEP] = "Sleep", [KEY_WAKEUP] = "WakeUp",
801 [KEY_FILE] = "File", [KEY_SENDFILE] = "SendFile",
802 [KEY_DELETEFILE] = "DeleteFile", [KEY_XFER] = "X-fer",
803 [KEY_PROG1] = "Prog1", [KEY_PROG2] = "Prog2",
804 [KEY_WWW] = "WWW", [KEY_MSDOS] = "MSDOS",
805 [KEY_COFFEE] = "Coffee", [KEY_ROTATE_DISPLAY] = "RotateDisplay",
806 [KEY_CYCLEWINDOWS] = "CycleWindows", [KEY_MAIL] = "Mail",
807 [KEY_BOOKMARKS] = "Bookmarks", [KEY_COMPUTER] = "Computer",
808 [KEY_BACK] = "Back", [KEY_FORWARD] = "Forward",
809 [KEY_CLOSECD] = "CloseCD", [KEY_EJECTCD] = "EjectCD",
810 [KEY_EJECTCLOSECD] = "EjectCloseCD", [KEY_NEXTSONG] = "NextSong",
811 [KEY_PLAYPAUSE] = "PlayPause", [KEY_PREVIOUSSONG] = "PreviousSong",
812 [KEY_STOPCD] = "StopCD", [KEY_RECORD] = "Record",
813 [KEY_REWIND] = "Rewind", [KEY_PHONE] = "Phone",
814 [KEY_ISO] = "ISOKey", [KEY_CONFIG] = "Config",
815 [KEY_HOMEPAGE] = "HomePage", [KEY_REFRESH] = "Refresh",
816 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
817 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
818 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
819 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
820 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
821 [KEY_F14] = "F14", [KEY_F15] = "F15",
822 [KEY_F16] = "F16", [KEY_F17] = "F17",
823 [KEY_F18] = "F18", [KEY_F19] = "F19",
824 [KEY_F20] = "F20", [KEY_F21] = "F21",
825 [KEY_F22] = "F22", [KEY_F23] = "F23",
826 [KEY_F24] = "F24", [KEY_PLAYCD] = "PlayCD",
827 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
828 [KEY_PROG4] = "Prog4",
829 [KEY_ALL_APPLICATIONS] = "AllApplications",
830 [KEY_SUSPEND] = "Suspend",
831 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
832 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
833 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
834 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
835 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
836 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
837 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
838 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
839 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
840 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
841 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
842 [BTN_DPAD_UP] = "BtnDPadUp", [BTN_DPAD_DOWN] = "BtnDPadDown",
843 [BTN_DPAD_LEFT] = "BtnDPadLeft", [BTN_DPAD_RIGHT] = "BtnDPadRight",
844 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
845 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
846 [BTN_4] = "Btn4", [BTN_5] = "Btn5",
847 [BTN_6] = "Btn6", [BTN_7] = "Btn7",
848 [BTN_8] = "Btn8", [BTN_9] = "Btn9",
849 [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn",
850 [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn",
851 [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn",
852 [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn",
853 [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn",
854 [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn",
855 [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn",
856 [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2",
857 [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4",
858 [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6",
859 [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA",
860 [BTN_B] = "BtnB", [BTN_C] = "BtnC",
861 [BTN_X] = "BtnX", [BTN_Y] = "BtnY",
862 [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL",
863 [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2",
864 [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect",
865 [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode",
866 [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR",
867 [BTN_TOOL_PEN] = "ToolPen", [BTN_TOOL_RUBBER] = "ToolRubber",
868 [BTN_TOOL_BRUSH] = "ToolBrush", [BTN_TOOL_PENCIL] = "ToolPencil",
869 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
870 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
871 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
872 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
873 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_TOOL_QUADTAP] = "ToolQuadrupleTap",
874 [BTN_GEAR_DOWN] = "WheelBtn",
875 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
876 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
877 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
878 [KEY_OPTION] = "Option", [KEY_INFO] = "Info",
879 [KEY_TIME] = "Time", [KEY_VENDOR] = "Vendor",
880 [KEY_ARCHIVE] = "Archive", [KEY_PROGRAM] = "Program",
881 [KEY_CHANNEL] = "Channel", [KEY_FAVORITES] = "Favorites",
882 [KEY_EPG] = "EPG", [KEY_PVR] = "PVR",
883 [KEY_MHP] = "MHP", [KEY_LANGUAGE] = "Language",
884 [KEY_TITLE] = "Title", [KEY_SUBTITLE] = "Subtitle",
885 [KEY_ANGLE] = "Angle", [KEY_ZOOM] = "Zoom",
886 [KEY_MODE] = "Mode", [KEY_KEYBOARD] = "Keyboard",
887 [KEY_SCREEN] = "Screen", [KEY_PC] = "PC",
888 [KEY_TV] = "TV", [KEY_TV2] = "TV2",
889 [KEY_VCR] = "VCR", [KEY_VCR2] = "VCR2",
890 [KEY_SAT] = "Sat", [KEY_SAT2] = "Sat2",
891 [KEY_CD] = "CD", [KEY_TAPE] = "Tape",
892 [KEY_RADIO] = "Radio", [KEY_TUNER] = "Tuner",
893 [KEY_PLAYER] = "Player", [KEY_TEXT] = "Text",
894 [KEY_DVD] = "DVD", [KEY_AUX] = "Aux",
895 [KEY_MP3] = "MP3", [KEY_AUDIO] = "Audio",
896 [KEY_VIDEO] = "Video", [KEY_DIRECTORY] = "Directory",
897 [KEY_LIST] = "List", [KEY_MEMO] = "Memo",
898 [KEY_CALENDAR] = "Calendar", [KEY_RED] = "Red",
899 [KEY_GREEN] = "Green", [KEY_YELLOW] = "Yellow",
900 [KEY_BLUE] = "Blue", [KEY_CHANNELUP] = "ChannelUp",
901 [KEY_CHANNELDOWN] = "ChannelDown", [KEY_FIRST] = "First",
902 [KEY_LAST] = "Last", [KEY_AB] = "AB",
903 [KEY_NEXT] = "Next", [KEY_RESTART] = "Restart",
904 [KEY_SLOW] = "Slow", [KEY_SHUFFLE] = "Shuffle",
905 [KEY_BREAK] = "Break", [KEY_PREVIOUS] = "Previous",
906 [KEY_DIGITS] = "Digits", [KEY_TEEN] = "TEEN",
907 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
908 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
909 [KEY_DEL_LINE] = "DeleteLine",
910 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
911 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
912 [KEY_DOCUMENTS] = "Documents", [KEY_SPELLCHECK] = "SpellCheck",
913 [KEY_LOGOFF] = "Logoff",
914 [KEY_FN] = "Fn", [KEY_FN_ESC] = "Fn+ESC",
915 [KEY_FN_1] = "Fn+1", [KEY_FN_2] = "Fn+2",
916 [KEY_FN_B] = "Fn+B", [KEY_FN_D] = "Fn+D",
917 [KEY_FN_E] = "Fn+E", [KEY_FN_F] = "Fn+F",
919 [KEY_FN_F1] = "Fn+F1", [KEY_FN_F2] = "Fn+F2",
920 [KEY_FN_F3] = "Fn+F3", [KEY_FN_F4] = "Fn+F4",
921 [KEY_FN_F5] = "Fn+F5", [KEY_FN_F6] = "Fn+F6",
922 [KEY_FN_F7] = "Fn+F7", [KEY_FN_F8] = "Fn+F8",
923 [KEY_FN_F9] = "Fn+F9", [KEY_FN_F10] = "Fn+F10",
924 [KEY_FN_F11] = "Fn+F11", [KEY_FN_F12] = "Fn+F12",
925 [KEY_KBDILLUMTOGGLE] = "KbdIlluminationToggle",
926 [KEY_KBDILLUMDOWN] = "KbdIlluminationDown",
927 [KEY_KBDILLUMUP] = "KbdIlluminationUp",
928 [KEY_SWITCHVIDEOMODE] = "SwitchVideoMode",
929 [KEY_BUTTONCONFIG] = "ButtonConfig",
930 [KEY_TASKMANAGER] = "TaskManager",
931 [KEY_JOURNAL] = "Journal",
932 [KEY_CONTROLPANEL] = "ControlPanel",
933 [KEY_APPSELECT] = "AppSelect",
934 [KEY_SCREENSAVER] = "ScreenSaver",
935 [KEY_VOICECOMMAND] = "VoiceCommand",
936 [KEY_ASSISTANT] = "Assistant",
937 [KEY_KBD_LAYOUT_NEXT] = "KbdLayoutNext",
938 [KEY_EMOJI_PICKER] = "EmojiPicker",
939 [KEY_DICTATE] = "Dictate",
940 [KEY_BRIGHTNESS_MIN] = "BrightnessMin",
941 [KEY_BRIGHTNESS_MAX] = "BrightnessMax",
942 [KEY_BRIGHTNESS_AUTO] = "BrightnessAuto",
943 [KEY_KBDINPUTASSIST_PREV] = "KbdInputAssistPrev",
944 [KEY_KBDINPUTASSIST_NEXT] = "KbdInputAssistNext",
945 [KEY_KBDINPUTASSIST_PREVGROUP] = "KbdInputAssistPrevGroup",
946 [KEY_KBDINPUTASSIST_NEXTGROUP] = "KbdInputAssistNextGroup",
947 [KEY_KBDINPUTASSIST_ACCEPT] = "KbdInputAssistAccept",
948 [KEY_KBDINPUTASSIST_CANCEL] = "KbdInputAssistCancel",
949 [KEY_MACRO1] = "Macro1", [KEY_MACRO2] = "Macro2", [KEY_MACRO3] = "Macro3",
950 [KEY_MACRO4] = "Macro4", [KEY_MACRO5] = "Macro5", [KEY_MACRO6] = "Macro6",
951 [KEY_MACRO7] = "Macro7", [KEY_MACRO8] = "Macro8", [KEY_MACRO9] = "Macro9",
952 [KEY_MACRO10] = "Macro10", [KEY_MACRO11] = "Macro11", [KEY_MACRO12] = "Macro12",
953 [KEY_MACRO13] = "Macro13", [KEY_MACRO14] = "Macro14", [KEY_MACRO15] = "Macro15",
954 [KEY_MACRO16] = "Macro16", [KEY_MACRO17] = "Macro17", [KEY_MACRO18] = "Macro18",
955 [KEY_MACRO19] = "Macro19", [KEY_MACRO20] = "Macro20", [KEY_MACRO21] = "Macro21",
956 [KEY_MACRO22] = "Macro22", [KEY_MACRO23] = "Macro23", [KEY_MACRO24] = "Macro24",
957 [KEY_MACRO25] = "Macro25", [KEY_MACRO26] = "Macro26", [KEY_MACRO27] = "Macro27",
958 [KEY_MACRO28] = "Macro28", [KEY_MACRO29] = "Macro29", [KEY_MACRO30] = "Macro30",
961 static const char *relatives[REL_MAX + 1] = {
962 [REL_X] = "X", [REL_Y] = "Y",
963 [REL_Z] = "Z", [REL_RX] = "Rx",
964 [REL_RY] = "Ry", [REL_RZ] = "Rz",
965 [REL_HWHEEL] = "HWheel", [REL_DIAL] = "Dial",
966 [REL_WHEEL] = "Wheel", [REL_MISC] = "Misc",
969 static const char *absolutes[ABS_CNT] = {
970 [ABS_X] = "X", [ABS_Y] = "Y",
971 [ABS_Z] = "Z", [ABS_RX] = "Rx",
972 [ABS_RY] = "Ry", [ABS_RZ] = "Rz",
973 [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder",
974 [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas",
975 [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X",
976 [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X",
977 [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X",
978 [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X",
979 [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure",
980 [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt",
981 [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth",
982 [ABS_VOLUME] = "Volume", [ABS_MISC] = "Misc",
983 [ABS_MT_TOUCH_MAJOR] = "MTMajor",
984 [ABS_MT_TOUCH_MINOR] = "MTMinor",
985 [ABS_MT_WIDTH_MAJOR] = "MTMajorW",
986 [ABS_MT_WIDTH_MINOR] = "MTMinorW",
987 [ABS_MT_ORIENTATION] = "MTOrientation",
988 [ABS_MT_POSITION_X] = "MTPositionX",
989 [ABS_MT_POSITION_Y] = "MTPositionY",
990 [ABS_MT_TOOL_TYPE] = "MTToolType",
991 [ABS_MT_BLOB_ID] = "MTBlobID",
994 static const char *misc[MSC_MAX + 1] = {
995 [MSC_SERIAL] = "Serial", [MSC_PULSELED] = "Pulseled",
996 [MSC_GESTURE] = "Gesture", [MSC_RAW] = "RawData"
999 static const char *leds[LED_MAX + 1] = {
1000 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
1001 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
1002 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
1003 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
1004 [LED_MISC] = "Misc",
1007 static const char *repeats[REP_MAX + 1] = {
1008 [REP_DELAY] = "Delay", [REP_PERIOD] = "Period"
1011 static const char *sounds[SND_MAX + 1] = {
1012 [SND_CLICK] = "Click", [SND_BELL] = "Bell",
1016 static const char **names[EV_MAX + 1] = {
1017 [EV_SYN] = syncs, [EV_KEY] = keys,
1018 [EV_REL] = relatives, [EV_ABS] = absolutes,
1019 [EV_MSC] = misc, [EV_LED] = leds,
1020 [EV_SND] = sounds, [EV_REP] = repeats,
1023 static void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f)
1025 seq_printf(f, "%s.%s", events[type] ? events[type] : "?",
1026 names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
1029 static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
1032 struct hid_report *report;
1033 struct hid_usage *usage;
1035 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
1036 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
1037 for (i = 0; i < report->maxfield; i++) {
1038 for ( j = 0; j < report->field[i]->maxusage; j++) {
1039 usage = report->field[i]->usage + j;
1040 hid_resolv_usage(usage->hid, f);
1041 seq_printf(f, " ---> ");
1042 hid_resolv_event(usage->type, usage->code, f);
1043 seq_printf(f, "\n");
1051 static int hid_debug_rdesc_show(struct seq_file *f, void *p)
1053 struct hid_device *hdev = f->private;
1054 const __u8 *rdesc = hdev->rdesc;
1055 unsigned rsize = hdev->rsize;
1059 rdesc = hdev->dev_rdesc;
1060 rsize = hdev->dev_rsize;
1063 /* dump HID report descriptor */
1064 for (i = 0; i < rsize; i++)
1065 seq_printf(f, "%02x ", rdesc[i]);
1066 seq_printf(f, "\n\n");
1068 /* dump parsed data and input mappings */
1069 if (down_interruptible(&hdev->driver_input_lock))
1072 hid_dump_device(hdev, f);
1073 seq_printf(f, "\n");
1074 hid_dump_input_mapping(hdev, f);
1076 up(&hdev->driver_input_lock);
1081 static int hid_debug_events_open(struct inode *inode, struct file *file)
1084 struct hid_debug_list *list;
1085 unsigned long flags;
1087 if (!(list = kzalloc(sizeof(struct hid_debug_list), GFP_KERNEL))) {
1092 err = kfifo_alloc(&list->hid_debug_fifo, HID_DEBUG_FIFOSIZE, GFP_KERNEL);
1097 list->hdev = (struct hid_device *) inode->i_private;
1098 file->private_data = list;
1099 mutex_init(&list->read_mutex);
1101 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
1102 list_add_tail(&list->node, &list->hdev->debug_list);
1103 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
1109 static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
1110 size_t count, loff_t *ppos)
1112 struct hid_debug_list *list = file->private_data;
1113 int ret = 0, copied;
1114 DECLARE_WAITQUEUE(wait, current);
1116 mutex_lock(&list->read_mutex);
1117 if (kfifo_is_empty(&list->hid_debug_fifo)) {
1118 add_wait_queue(&list->hdev->debug_wait, &wait);
1119 set_current_state(TASK_INTERRUPTIBLE);
1121 while (kfifo_is_empty(&list->hid_debug_fifo)) {
1122 if (signal_pending(current)) {
1127 /* if list->hdev is NULL we cannot remove_wait_queue().
1128 * if list->hdev->debug is 0 then hid_debug_unregister()
1129 * was already called and list->hdev is being destroyed.
1130 * if we add remove_wait_queue() here we can hit a race.
1132 if (!list->hdev || !list->hdev->debug) {
1134 set_current_state(TASK_RUNNING);
1138 if (file->f_flags & O_NONBLOCK) {
1143 /* allow O_NONBLOCK from other threads */
1144 mutex_unlock(&list->read_mutex);
1146 mutex_lock(&list->read_mutex);
1147 set_current_state(TASK_INTERRUPTIBLE);
1150 __set_current_state(TASK_RUNNING);
1151 remove_wait_queue(&list->hdev->debug_wait, &wait);
1157 /* pass the fifo content to userspace, locking is not needed with only
1158 * one concurrent reader and one concurrent writer
1160 ret = kfifo_to_user(&list->hid_debug_fifo, buffer, count, &copied);
1165 mutex_unlock(&list->read_mutex);
1169 static __poll_t hid_debug_events_poll(struct file *file, poll_table *wait)
1171 struct hid_debug_list *list = file->private_data;
1173 poll_wait(file, &list->hdev->debug_wait, wait);
1174 if (!kfifo_is_empty(&list->hid_debug_fifo))
1175 return EPOLLIN | EPOLLRDNORM;
1176 if (!list->hdev->debug)
1177 return EPOLLERR | EPOLLHUP;
1181 static int hid_debug_events_release(struct inode *inode, struct file *file)
1183 struct hid_debug_list *list = file->private_data;
1184 unsigned long flags;
1186 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
1187 list_del(&list->node);
1188 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
1189 kfifo_free(&list->hid_debug_fifo);
1195 DEFINE_SHOW_ATTRIBUTE(hid_debug_rdesc);
1197 static const struct file_operations hid_debug_events_fops = {
1198 .owner = THIS_MODULE,
1199 .open = hid_debug_events_open,
1200 .read = hid_debug_events_read,
1201 .poll = hid_debug_events_poll,
1202 .release = hid_debug_events_release,
1203 .llseek = noop_llseek,
1207 void hid_debug_register(struct hid_device *hdev, const char *name)
1209 hdev->debug_dir = debugfs_create_dir(name, hid_debug_root);
1210 hdev->debug_rdesc = debugfs_create_file("rdesc", 0400,
1211 hdev->debug_dir, hdev, &hid_debug_rdesc_fops);
1212 hdev->debug_events = debugfs_create_file("events", 0400,
1213 hdev->debug_dir, hdev, &hid_debug_events_fops);
1217 void hid_debug_unregister(struct hid_device *hdev)
1220 wake_up_interruptible(&hdev->debug_wait);
1221 debugfs_remove(hdev->debug_rdesc);
1222 debugfs_remove(hdev->debug_events);
1223 debugfs_remove(hdev->debug_dir);
1226 void hid_debug_init(void)
1228 hid_debug_root = debugfs_create_dir("hid", NULL);
1231 void hid_debug_exit(void)
1233 debugfs_remove_recursive(hid_debug_root);