2 * (c) 1999 Andreas Gal <gal@cs.uni-magdeburg.de>
3 * (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz>
4 * (c) 2007-2009 Jiri Kosina
6 * HID debugging support
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.
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.
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
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
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/debugfs.h>
32 #include <linux/seq_file.h>
33 #include <linux/sched.h>
34 #include <linux/slab.h>
35 #include <linux/uaccess.h>
36 #include <linux/poll.h>
38 #include <linux/hid.h>
39 #include <linux/hid-debug.h>
41 static struct dentry
*hid_debug_root
;
43 struct hid_usage_entry
{
46 const char *description
;
49 static const struct hid_usage_entry hid_usage_table
[] = {
50 { 0, 0, "Undefined" },
51 { 1, 0, "GenericDesktop" },
54 {0, 0x04, "Joystick"},
56 {0, 0x06, "Keyboard"},
58 {0, 0x08, "MultiAxis"},
68 {0, 0x39, "HatSwitch"},
69 {0, 0x3a, "CountedBuffer"},
70 {0, 0x3b, "ByteCount"},
71 {0, 0x3c, "MotionWakeup"},
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"},
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"},
105 {0, 0xb5, "Collective"},
106 {0, 0xb6, "DiveBrake"},
107 {0, 0xb7, "ElectronicCountermeasures"},
108 {0, 0xb8, "Elevator"},
109 {0, 0xb9, "ElevatorTrim"},
111 {0, 0xbb, "Throttle"},
112 {0, 0xbc, "FlightCommunications"},
113 {0, 0xbd, "FlareRelease"},
114 {0, 0xbe, "LandingGear"},
115 {0, 0xbf, "ToeBrake"},
116 { 7, 0, "Keyboard" },
118 {0, 0x01, "NumLock"},
119 {0, 0x02, "CapsLock"},
120 {0, 0x03, "ScrollLock"},
121 {0, 0x04, "Compose"},
123 {0, 0x4b, "GenericIndicator"},
125 { 10, 0, "Ordinal" },
126 { 12, 0, "Consumer" },
127 {0, 0x238, "HorizontalWheel"},
128 { 13, 0, "Digitizers" },
129 {0, 0x01, "Digitizer"},
131 {0, 0x03, "LightPen"},
132 {0, 0x04, "TouchScreen"},
133 {0, 0x05, "TouchPad"},
137 {0, 0x30, "TipPressure"},
138 {0, 0x31, "BarrelPressure"},
139 {0, 0x32, "InRange"},
141 {0, 0x34, "UnTouch"},
143 {0, 0x39, "TabletFunctionKey"},
144 {0, 0x3a, "ProgramChangeKey"},
146 {0, 0x42, "TipSwitch"},
147 {0, 0x43, "SecondaryTipSwitch"},
148 {0, 0x44, "BarrelSwitch"},
150 {0, 0x46, "TabletPick"},
151 {0, 0x47, "Confidence"},
154 {0, 0x51, "ContactID"},
155 {0, 0x52, "InputMode"},
156 {0, 0x53, "DeviceIndex"},
157 {0, 0x54, "ContactCount"},
158 {0, 0x55, "ContactMaximumNumber"},
159 { 15, 0, "PhysicalInterfaceDevice" },
160 {0, 0x00, "Undefined"},
161 {0, 0x01, "Physical_Interface_Device"},
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"},
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"},
212 {0, 0x70, "Magnitude"},
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" },
344 { 0x85, 0x8b, "Rechargeable" },
345 { 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" },
353 /* Either output directly into simple seq_file, or (if f == NULL)
354 * allocate a separate buffer that will then be passed to the 'events'
357 * This is because these functions can be called both for "one-shot"
358 * "rdesc" while resolving, or for blocking "events".
360 * This holds both for resolv_usage_page() and hid_resolv_usage().
362 static char *resolv_usage_page(unsigned page
, struct seq_file
*f
) {
363 const struct hid_usage_entry
*p
;
367 buf
= kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE
, GFP_ATOMIC
);
369 return ERR_PTR(-ENOMEM
);
372 for (p
= hid_usage_table
; p
->description
; p
++)
373 if (p
->page
== page
) {
375 snprintf(buf
, HID_DEBUG_BUFSIZE
, "%s",
380 seq_printf(f
, "%s", p
->description
);
385 snprintf(buf
, HID_DEBUG_BUFSIZE
, "%04x", page
);
387 seq_printf(f
, "%04x", page
);
391 char *hid_resolv_usage(unsigned usage
, struct seq_file
*f
) {
392 const struct hid_usage_entry
*p
;
396 buf
= resolv_usage_page(usage
>> 16, f
);
398 pr_err("error allocating HID debug buffer\n");
405 snprintf(buf
+len
, max(0, HID_DEBUG_BUFSIZE
- len
), ".");
411 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)) {
417 max(0,HID_DEBUG_BUFSIZE
- len
- 1),
418 "%s", p
->description
);
428 snprintf(buf
+ len
, max(0, HID_DEBUG_BUFSIZE
- len
- 1),
429 "%04x", usage
& 0xffff);
431 seq_printf(f
, "%04x", usage
& 0xffff);
434 EXPORT_SYMBOL_GPL(hid_resolv_usage
);
436 static void tab(int n
, struct seq_file
*f
) {
437 seq_printf(f
, "%*s", n
, "");
440 void hid_dump_field(struct hid_field
*field
, int n
, struct seq_file
*f
) {
443 if (field
->physical
) {
445 seq_printf(f
, "Physical(");
446 hid_resolv_usage(field
->physical
, f
); seq_printf(f
, ")\n");
448 if (field
->logical
) {
450 seq_printf(f
, "Logical(");
451 hid_resolv_usage(field
->logical
, f
); seq_printf(f
, ")\n");
453 if (field
->application
) {
455 seq_printf(f
, "Application(");
456 hid_resolv_usage(field
->application
, f
); seq_printf(f
, ")\n");
458 tab(n
, f
); seq_printf(f
, "Usage(%d)\n", field
->maxusage
);
459 for (j
= 0; j
< field
->maxusage
; j
++) {
460 tab(n
+2, f
); hid_resolv_usage(field
->usage
[j
].hid
, f
); seq_printf(f
, "\n");
462 if (field
->logical_minimum
!= field
->logical_maximum
) {
463 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
);
466 if (field
->physical_minimum
!= field
->physical_maximum
) {
467 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
);
470 if (field
->unit_exponent
) {
471 tab(n
, f
); seq_printf(f
, "Unit Exponent(%d)\n", field
->unit_exponent
);
474 static const char *systems
[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
475 static const char *units
[5][8] = {
476 { "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" }
485 __u32 data
= field
->unit
;
487 /* First nibble tells us which system we're in. */
492 tab(n
, f
); seq_printf(f
, "Unit(Invalid)\n");
495 int earlier_unit
= 0;
497 tab(n
, f
); seq_printf(f
, "Unit(%s : ", systems
[sys
]);
499 for (i
=1 ; i
<sizeof(__u32
)*2 ; i
++) {
500 char nibble
= data
& 0xf;
503 if(earlier_unit
++ > 0)
505 seq_printf(f
, "%s", units
[sys
][i
]);
507 /* This is a _signed_ nibble(!) */
509 int val
= nibble
& 0x7;
511 val
= -((0x7 & ~val
) +1);
512 seq_printf(f
, "^%d", val
);
516 seq_printf(f
, ")\n");
519 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
);
523 tab(n
, f
); seq_printf(f
, "Flags( ");
525 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");
536 EXPORT_SYMBOL_GPL(hid_dump_field
);
538 void hid_dump_device(struct hid_device
*device
, struct seq_file
*f
)
540 struct hid_report_enum
*report_enum
;
541 struct hid_report
*report
;
542 struct list_head
*list
;
544 static const char *table
[] = {"INPUT", "OUTPUT", "FEATURE"};
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
;
552 seq_printf(f
, "%s", table
[i
]);
554 seq_printf(f
, "(%d)", report
->id
);
555 seq_printf(f
, "[%s]", table
[report
->type
]);
557 for (k
= 0; k
< report
->maxfield
; k
++) {
559 seq_printf(f
, "Field(%d)\n", k
);
560 hid_dump_field(report
->field
[k
], 6, f
);
566 EXPORT_SYMBOL_GPL(hid_dump_device
);
568 /* enqueue string to 'events' ring buffer */
569 void hid_debug_event(struct hid_device
*hdev
, char *buf
)
572 struct hid_debug_list
*list
;
574 list_for_each_entry(list
, &hdev
->debug_list
, node
) {
575 for (i
= 0; i
< strlen(buf
); i
++)
576 list
->hid_debug_buf
[(list
->tail
+ i
) % HID_DEBUG_BUFSIZE
] =
578 list
->tail
= (list
->tail
+ i
) % HID_DEBUG_BUFSIZE
;
581 wake_up_interruptible(&hdev
->debug_wait
);
583 EXPORT_SYMBOL_GPL(hid_debug_event
);
585 void hid_dump_input(struct hid_device
*hdev
, struct hid_usage
*usage
, __s32 value
)
590 buf
= hid_resolv_usage(usage
->hid
, NULL
);
594 snprintf(buf
+ len
, HID_DEBUG_BUFSIZE
- len
- 1, " = %d\n", value
);
596 hid_debug_event(hdev
, buf
);
599 wake_up_interruptible(&hdev
->debug_wait
);
602 EXPORT_SYMBOL_GPL(hid_dump_input
);
604 static const char *events
[EV_MAX
+ 1] = {
605 [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",
613 static const char *syncs
[3] = {
614 [SYN_REPORT
] = "Report", [SYN_CONFIG
] = "Config",
615 [SYN_MT_REPORT
] = "MT Report",
618 static const char *keys
[KEY_MAX
+ 1] = {
619 [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",
796 [KEY_DOCUMENTS
] = "Documents", [KEY_SPELLCHECK
] = "SpellCheck",
797 [KEY_LOGOFF
] = "Logoff",
798 [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",
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",
815 static const char *relatives
[REL_MAX
+ 1] = {
816 [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",
823 static const char *absolutes
[ABS_CNT
] = {
824 [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",
835 [ABS_TILT_Y
] = "YTilt", [ABS_TOOL_WIDTH
] = "ToolWidth",
836 [ABS_VOLUME
] = "Volume", [ABS_MISC
] = "Misc",
837 [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",
848 static const char *misc
[MSC_MAX
+ 1] = {
849 [MSC_SERIAL
] = "Serial", [MSC_PULSELED
] = "Pulseled",
850 [MSC_GESTURE
] = "Gesture", [MSC_RAW
] = "RawData"
853 static const char *leds
[LED_MAX
+ 1] = {
854 [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",
861 static const char *repeats
[REP_MAX
+ 1] = {
862 [REP_DELAY
] = "Delay", [REP_PERIOD
] = "Period"
865 static const char *sounds
[SND_MAX
+ 1] = {
866 [SND_CLICK
] = "Click", [SND_BELL
] = "Bell",
870 static const char **names
[EV_MAX
+ 1] = {
871 [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
,
877 static void hid_resolv_event(__u8 type
, __u16 code
, struct seq_file
*f
)
879 seq_printf(f
, "%s.%s", events
[type
] ? events
[type
] : "?",
880 names
[type
] ? (names
[type
][code
] ? names
[type
][code
] : "?") : "?");
883 static void hid_dump_input_mapping(struct hid_device
*hid
, struct seq_file
*f
)
886 struct hid_report
*report
;
887 struct hid_usage
*usage
;
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
);
906 static int hid_debug_rdesc_show(struct seq_file
*f
, void *p
)
908 struct hid_device
*hdev
= f
->private;
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");
916 /* dump parsed data and input mappings */
917 hid_dump_device(hdev
, f
);
919 hid_dump_input_mapping(hdev
, f
);
924 static int hid_debug_rdesc_open(struct inode
*inode
, struct file
*file
)
926 return single_open(file
, hid_debug_rdesc_show
, inode
->i_private
);
929 static int hid_debug_events_open(struct inode
*inode
, struct file
*file
)
932 struct hid_debug_list
*list
;
934 if (!(list
= kzalloc(sizeof(struct hid_debug_list
), GFP_KERNEL
))) {
939 if (!(list
->hid_debug_buf
= kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE
, GFP_KERNEL
))) {
944 list
->hdev
= (struct hid_device
*) inode
->i_private
;
945 file
->private_data
= list
;
946 mutex_init(&list
->read_mutex
);
948 list_add_tail(&list
->node
, &list
->hdev
->debug_list
);
954 static ssize_t
hid_debug_events_read(struct file
*file
, char __user
*buffer
,
955 size_t count
, loff_t
*ppos
)
957 struct hid_debug_list
*list
= file
->private_data
;
959 DECLARE_WAITQUEUE(wait
, current
);
961 mutex_lock(&list
->read_mutex
);
963 if (list
->head
== list
->tail
) {
964 add_wait_queue(&list
->hdev
->debug_wait
, &wait
);
965 set_current_state(TASK_INTERRUPTIBLE
);
967 while (list
->head
== list
->tail
) {
968 if (file
->f_flags
& O_NONBLOCK
) {
972 if (signal_pending(current
)) {
977 if (!list
->hdev
|| !list
->hdev
->debug
) {
982 /* allow O_NONBLOCK from other threads */
983 mutex_unlock(&list
->read_mutex
);
985 mutex_lock(&list
->read_mutex
);
986 set_current_state(TASK_INTERRUPTIBLE
);
989 set_current_state(TASK_RUNNING
);
990 remove_wait_queue(&list
->hdev
->debug_wait
, &wait
);
996 /* pass the ringbuffer contents to userspace */
998 if (list
->tail
== list
->head
)
1000 if (list
->tail
> list
->head
) {
1001 len
= list
->tail
- list
->head
;
1003 if (copy_to_user(buffer
+ ret
, &list
->hid_debug_buf
[list
->head
], len
)) {
1010 len
= HID_DEBUG_BUFSIZE
- list
->head
;
1012 if (copy_to_user(buffer
, &list
->hid_debug_buf
[list
->head
], len
)) {
1023 mutex_unlock(&list
->read_mutex
);
1027 static unsigned int hid_debug_events_poll(struct file
*file
, poll_table
*wait
)
1029 struct hid_debug_list
*list
= file
->private_data
;
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
;
1039 static int hid_debug_events_release(struct inode
*inode
, struct file
*file
)
1041 struct hid_debug_list
*list
= file
->private_data
;
1043 list_del(&list
->node
);
1044 kfree(list
->hid_debug_buf
);
1050 static const struct file_operations hid_debug_rdesc_fops
= {
1051 .open
= hid_debug_rdesc_open
,
1053 .llseek
= seq_lseek
,
1054 .release
= single_release
,
1057 static 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
,
1063 .llseek
= noop_llseek
,
1067 void hid_debug_register(struct hid_device
*hdev
, const char *name
)
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
);
1072 hdev
->debug_events
= debugfs_create_file("events", 0400,
1073 hdev
->debug_dir
, hdev
, &hid_debug_events_fops
);
1077 void hid_debug_unregister(struct hid_device
*hdev
)
1080 wake_up_interruptible(&hdev
->debug_wait
);
1081 debugfs_remove(hdev
->debug_rdesc
);
1082 debugfs_remove(hdev
->debug_events
);
1083 debugfs_remove(hdev
->debug_dir
);
1086 void hid_debug_init(void)
1088 hid_debug_root
= debugfs_create_dir("hid", NULL
);
1091 void hid_debug_exit(void)
1093 debugfs_remove_recursive(hid_debug_root
);