blob: 6abd0369aedba0125f935dc357f292d5e6850017 [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
Jiri Kosinaa635f9d2009-06-12 15:20:55 +020029#include <linux/debugfs.h>
30#include <linux/seq_file.h>
Jiri Kosinacd667ce2009-06-12 15:20:57 +020031#include <linux/sched.h>
32#include <linux/uaccess.h>
33#include <linux/poll.h>
34
Jiri Kosinac080d892007-01-25 11:43:31 +010035#include <linux/hid.h>
Adrian Bunk4330eb22007-02-21 12:57:30 +010036#include <linux/hid-debug.h>
Jiri Kosinac080d892007-01-25 11:43:31 +010037
Jiri Kosinaa635f9d2009-06-12 15:20:55 +020038static struct dentry *hid_debug_root;
39
Jiri Kosinac080d892007-01-25 11:43:31 +010040struct hid_usage_entry {
41 unsigned page;
42 unsigned usage;
Joe Perches0ce1ac32007-09-26 16:29:53 +020043 const char *description;
Jiri Kosinac080d892007-01-25 11:43:31 +010044};
45
46static const struct hid_usage_entry hid_usage_table[] = {
47 { 0, 0, "Undefined" },
48 { 1, 0, "GenericDesktop" },
49 {0, 0x01, "Pointer"},
50 {0, 0x02, "Mouse"},
51 {0, 0x04, "Joystick"},
52 {0, 0x05, "GamePad"},
53 {0, 0x06, "Keyboard"},
54 {0, 0x07, "Keypad"},
55 {0, 0x08, "MultiAxis"},
56 {0, 0x30, "X"},
57 {0, 0x31, "Y"},
58 {0, 0x32, "Z"},
59 {0, 0x33, "Rx"},
60 {0, 0x34, "Ry"},
61 {0, 0x35, "Rz"},
62 {0, 0x36, "Slider"},
63 {0, 0x37, "Dial"},
64 {0, 0x38, "Wheel"},
65 {0, 0x39, "HatSwitch"},
66 {0, 0x3a, "CountedBuffer"},
67 {0, 0x3b, "ByteCount"},
68 {0, 0x3c, "MotionWakeup"},
69 {0, 0x3d, "Start"},
70 {0, 0x3e, "Select"},
71 {0, 0x40, "Vx"},
72 {0, 0x41, "Vy"},
73 {0, 0x42, "Vz"},
74 {0, 0x43, "Vbrx"},
75 {0, 0x44, "Vbry"},
76 {0, 0x45, "Vbrz"},
77 {0, 0x46, "Vno"},
78 {0, 0x80, "SystemControl"},
79 {0, 0x81, "SystemPowerDown"},
80 {0, 0x82, "SystemSleep"},
81 {0, 0x83, "SystemWakeUp"},
82 {0, 0x84, "SystemContextMenu"},
83 {0, 0x85, "SystemMainMenu"},
84 {0, 0x86, "SystemAppMenu"},
85 {0, 0x87, "SystemMenuHelp"},
86 {0, 0x88, "SystemMenuExit"},
87 {0, 0x89, "SystemMenuSelect"},
88 {0, 0x8a, "SystemMenuRight"},
89 {0, 0x8b, "SystemMenuLeft"},
90 {0, 0x8c, "SystemMenuUp"},
91 {0, 0x8d, "SystemMenuDown"},
92 {0, 0x90, "D-PadUp"},
93 {0, 0x91, "D-PadDown"},
94 {0, 0x92, "D-PadRight"},
95 {0, 0x93, "D-PadLeft"},
96 { 2, 0, "Simulation" },
97 {0, 0xb0, "Aileron"},
98 {0, 0xb1, "AileronTrim"},
99 {0, 0xb2, "Anti-Torque"},
100 {0, 0xb3, "Autopilot"},
101 {0, 0xb4, "Chaff"},
102 {0, 0xb5, "Collective"},
103 {0, 0xb6, "DiveBrake"},
104 {0, 0xb7, "ElectronicCountermeasures"},
105 {0, 0xb8, "Elevator"},
106 {0, 0xb9, "ElevatorTrim"},
107 {0, 0xba, "Rudder"},
108 {0, 0xbb, "Throttle"},
109 {0, 0xbc, "FlightCommunications"},
110 {0, 0xbd, "FlareRelease"},
111 {0, 0xbe, "LandingGear"},
112 {0, 0xbf, "ToeBrake"},
113 { 7, 0, "Keyboard" },
114 { 8, 0, "LED" },
115 {0, 0x01, "NumLock"},
116 {0, 0x02, "CapsLock"},
117 {0, 0x03, "ScrollLock"},
118 {0, 0x04, "Compose"},
119 {0, 0x05, "Kana"},
120 {0, 0x4b, "GenericIndicator"},
121 { 9, 0, "Button" },
122 { 10, 0, "Ordinal" },
123 { 12, 0, "Consumer" },
124 {0, 0x238, "HorizontalWheel"},
125 { 13, 0, "Digitizers" },
126 {0, 0x01, "Digitizer"},
127 {0, 0x02, "Pen"},
128 {0, 0x03, "LightPen"},
129 {0, 0x04, "TouchScreen"},
130 {0, 0x05, "TouchPad"},
131 {0, 0x20, "Stylus"},
132 {0, 0x21, "Puck"},
133 {0, 0x22, "Finger"},
134 {0, 0x30, "TipPressure"},
135 {0, 0x31, "BarrelPressure"},
136 {0, 0x32, "InRange"},
137 {0, 0x33, "Touch"},
138 {0, 0x34, "UnTouch"},
139 {0, 0x35, "Tap"},
140 {0, 0x39, "TabletFunctionKey"},
141 {0, 0x3a, "ProgramChangeKey"},
142 {0, 0x3c, "Invert"},
143 {0, 0x42, "TipSwitch"},
144 {0, 0x43, "SecondaryTipSwitch"},
145 {0, 0x44, "BarrelSwitch"},
146 {0, 0x45, "Eraser"},
147 {0, 0x46, "TabletPick"},
Stephane Chatty89f536c2009-05-20 15:41:24 +0200148 {0, 0x47, "Confidence"},
149 {0, 0x48, "Width"},
150 {0, 0x49, "Height"},
151 {0, 0x51, "ContactID"},
152 {0, 0x52, "InputMode"},
153 {0, 0x53, "DeviceIndex"},
154 {0, 0x54, "ContactCount"},
155 {0, 0x55, "ContactMaximumNumber"},
Jiri Kosinac080d892007-01-25 11:43:31 +0100156 { 15, 0, "PhysicalInterfaceDevice" },
157 {0, 0x00, "Undefined"},
158 {0, 0x01, "Physical_Interface_Device"},
159 {0, 0x20, "Normal"},
160 {0, 0x21, "Set_Effect_Report"},
161 {0, 0x22, "Effect_Block_Index"},
162 {0, 0x23, "Parameter_Block_Offset"},
163 {0, 0x24, "ROM_Flag"},
164 {0, 0x25, "Effect_Type"},
165 {0, 0x26, "ET_Constant_Force"},
166 {0, 0x27, "ET_Ramp"},
167 {0, 0x28, "ET_Custom_Force_Data"},
168 {0, 0x30, "ET_Square"},
169 {0, 0x31, "ET_Sine"},
170 {0, 0x32, "ET_Triangle"},
171 {0, 0x33, "ET_Sawtooth_Up"},
172 {0, 0x34, "ET_Sawtooth_Down"},
173 {0, 0x40, "ET_Spring"},
174 {0, 0x41, "ET_Damper"},
175 {0, 0x42, "ET_Inertia"},
176 {0, 0x43, "ET_Friction"},
177 {0, 0x50, "Duration"},
178 {0, 0x51, "Sample_Period"},
179 {0, 0x52, "Gain"},
180 {0, 0x53, "Trigger_Button"},
181 {0, 0x54, "Trigger_Repeat_Interval"},
182 {0, 0x55, "Axes_Enable"},
183 {0, 0x56, "Direction_Enable"},
184 {0, 0x57, "Direction"},
185 {0, 0x58, "Type_Specific_Block_Offset"},
186 {0, 0x59, "Block_Type"},
187 {0, 0x5A, "Set_Envelope_Report"},
188 {0, 0x5B, "Attack_Level"},
189 {0, 0x5C, "Attack_Time"},
190 {0, 0x5D, "Fade_Level"},
191 {0, 0x5E, "Fade_Time"},
192 {0, 0x5F, "Set_Condition_Report"},
193 {0, 0x60, "CP_Offset"},
194 {0, 0x61, "Positive_Coefficient"},
195 {0, 0x62, "Negative_Coefficient"},
196 {0, 0x63, "Positive_Saturation"},
197 {0, 0x64, "Negative_Saturation"},
198 {0, 0x65, "Dead_Band"},
199 {0, 0x66, "Download_Force_Sample"},
200 {0, 0x67, "Isoch_Custom_Force_Enable"},
201 {0, 0x68, "Custom_Force_Data_Report"},
202 {0, 0x69, "Custom_Force_Data"},
203 {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
204 {0, 0x6B, "Set_Custom_Force_Report"},
205 {0, 0x6C, "Custom_Force_Data_Offset"},
206 {0, 0x6D, "Sample_Count"},
207 {0, 0x6E, "Set_Periodic_Report"},
208 {0, 0x6F, "Offset"},
209 {0, 0x70, "Magnitude"},
210 {0, 0x71, "Phase"},
211 {0, 0x72, "Period"},
212 {0, 0x73, "Set_Constant_Force_Report"},
213 {0, 0x74, "Set_Ramp_Force_Report"},
214 {0, 0x75, "Ramp_Start"},
215 {0, 0x76, "Ramp_End"},
216 {0, 0x77, "Effect_Operation_Report"},
217 {0, 0x78, "Effect_Operation"},
218 {0, 0x79, "Op_Effect_Start"},
219 {0, 0x7A, "Op_Effect_Start_Solo"},
220 {0, 0x7B, "Op_Effect_Stop"},
221 {0, 0x7C, "Loop_Count"},
222 {0, 0x7D, "Device_Gain_Report"},
223 {0, 0x7E, "Device_Gain"},
224 {0, 0x7F, "PID_Pool_Report"},
225 {0, 0x80, "RAM_Pool_Size"},
226 {0, 0x81, "ROM_Pool_Size"},
227 {0, 0x82, "ROM_Effect_Block_Count"},
228 {0, 0x83, "Simultaneous_Effects_Max"},
229 {0, 0x84, "Pool_Alignment"},
230 {0, 0x85, "PID_Pool_Move_Report"},
231 {0, 0x86, "Move_Source"},
232 {0, 0x87, "Move_Destination"},
233 {0, 0x88, "Move_Length"},
234 {0, 0x89, "PID_Block_Load_Report"},
235 {0, 0x8B, "Block_Load_Status"},
236 {0, 0x8C, "Block_Load_Success"},
237 {0, 0x8D, "Block_Load_Full"},
238 {0, 0x8E, "Block_Load_Error"},
239 {0, 0x8F, "Block_Handle"},
240 {0, 0x90, "PID_Block_Free_Report"},
241 {0, 0x91, "Type_Specific_Block_Handle"},
242 {0, 0x92, "PID_State_Report"},
243 {0, 0x94, "Effect_Playing"},
244 {0, 0x95, "PID_Device_Control_Report"},
245 {0, 0x96, "PID_Device_Control"},
246 {0, 0x97, "DC_Enable_Actuators"},
247 {0, 0x98, "DC_Disable_Actuators"},
248 {0, 0x99, "DC_Stop_All_Effects"},
249 {0, 0x9A, "DC_Device_Reset"},
250 {0, 0x9B, "DC_Device_Pause"},
251 {0, 0x9C, "DC_Device_Continue"},
252 {0, 0x9F, "Device_Paused"},
253 {0, 0xA0, "Actuators_Enabled"},
254 {0, 0xA4, "Safety_Switch"},
255 {0, 0xA5, "Actuator_Override_Switch"},
256 {0, 0xA6, "Actuator_Power"},
257 {0, 0xA7, "Start_Delay"},
258 {0, 0xA8, "Parameter_Block_Size"},
259 {0, 0xA9, "Device_Managed_Pool"},
260 {0, 0xAA, "Shared_Parameter_Blocks"},
261 {0, 0xAB, "Create_New_Effect_Report"},
262 {0, 0xAC, "RAM_Pool_Available"},
263 { 0x84, 0, "Power Device" },
264 { 0x84, 0x02, "PresentStatus" },
265 { 0x84, 0x03, "ChangeStatus" },
266 { 0x84, 0x04, "UPS" },
267 { 0x84, 0x05, "PowerSupply" },
268 { 0x84, 0x10, "BatterySystem" },
269 { 0x84, 0x11, "BatterySystemID" },
270 { 0x84, 0x12, "Battery" },
271 { 0x84, 0x13, "BatteryID" },
272 { 0x84, 0x14, "Charger" },
273 { 0x84, 0x15, "ChargerID" },
274 { 0x84, 0x16, "PowerConverter" },
275 { 0x84, 0x17, "PowerConverterID" },
276 { 0x84, 0x18, "OutletSystem" },
277 { 0x84, 0x19, "OutletSystemID" },
278 { 0x84, 0x1a, "Input" },
279 { 0x84, 0x1b, "InputID" },
280 { 0x84, 0x1c, "Output" },
281 { 0x84, 0x1d, "OutputID" },
282 { 0x84, 0x1e, "Flow" },
283 { 0x84, 0x1f, "FlowID" },
284 { 0x84, 0x20, "Outlet" },
285 { 0x84, 0x21, "OutletID" },
286 { 0x84, 0x22, "Gang" },
287 { 0x84, 0x24, "PowerSummary" },
288 { 0x84, 0x25, "PowerSummaryID" },
289 { 0x84, 0x30, "Voltage" },
290 { 0x84, 0x31, "Current" },
291 { 0x84, 0x32, "Frequency" },
292 { 0x84, 0x33, "ApparentPower" },
293 { 0x84, 0x35, "PercentLoad" },
294 { 0x84, 0x40, "ConfigVoltage" },
295 { 0x84, 0x41, "ConfigCurrent" },
296 { 0x84, 0x43, "ConfigApparentPower" },
297 { 0x84, 0x53, "LowVoltageTransfer" },
298 { 0x84, 0x54, "HighVoltageTransfer" },
299 { 0x84, 0x56, "DelayBeforeStartup" },
300 { 0x84, 0x57, "DelayBeforeShutdown" },
301 { 0x84, 0x58, "Test" },
302 { 0x84, 0x5a, "AudibleAlarmControl" },
303 { 0x84, 0x60, "Present" },
304 { 0x84, 0x61, "Good" },
305 { 0x84, 0x62, "InternalFailure" },
306 { 0x84, 0x65, "Overload" },
307 { 0x84, 0x66, "OverCharged" },
308 { 0x84, 0x67, "OverTemperature" },
309 { 0x84, 0x68, "ShutdownRequested" },
310 { 0x84, 0x69, "ShutdownImminent" },
311 { 0x84, 0x6b, "SwitchOn/Off" },
312 { 0x84, 0x6c, "Switchable" },
313 { 0x84, 0x6d, "Used" },
314 { 0x84, 0x6e, "Boost" },
315 { 0x84, 0x73, "CommunicationLost" },
316 { 0x84, 0xfd, "iManufacturer" },
317 { 0x84, 0xfe, "iProduct" },
318 { 0x84, 0xff, "iSerialNumber" },
319 { 0x85, 0, "Battery System" },
320 { 0x85, 0x01, "SMBBatteryMode" },
321 { 0x85, 0x02, "SMBBatteryStatus" },
322 { 0x85, 0x03, "SMBAlarmWarning" },
323 { 0x85, 0x04, "SMBChargerMode" },
324 { 0x85, 0x05, "SMBChargerStatus" },
325 { 0x85, 0x06, "SMBChargerSpecInfo" },
326 { 0x85, 0x07, "SMBSelectorState" },
327 { 0x85, 0x08, "SMBSelectorPresets" },
328 { 0x85, 0x09, "SMBSelectorInfo" },
329 { 0x85, 0x29, "RemainingCapacityLimit" },
330 { 0x85, 0x2c, "CapacityMode" },
331 { 0x85, 0x42, "BelowRemainingCapacityLimit" },
332 { 0x85, 0x44, "Charging" },
333 { 0x85, 0x45, "Discharging" },
334 { 0x85, 0x4b, "NeedReplacement" },
335 { 0x85, 0x66, "RemainingCapacity" },
336 { 0x85, 0x68, "RunTimeToEmpty" },
337 { 0x85, 0x6a, "AverageTimeToFull" },
338 { 0x85, 0x83, "DesignCapacity" },
339 { 0x85, 0x85, "ManufacturerDate" },
340 { 0x85, 0x89, "iDeviceChemistry" },
341 { 0x85, 0x8b, "Rechargable" },
342 { 0x85, 0x8f, "iOEMInformation" },
343 { 0x85, 0x8d, "CapacityGranularity1" },
344 { 0x85, 0xd0, "ACPresent" },
345 /* pages 0xff00 to 0xffff are vendor-specific */
346 { 0xffff, 0, "Vendor-specific-FF" },
347 { 0, 0, NULL }
348};
349
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200350/* Either output directly into simple seq_file, or (if f == NULL)
351 * allocate a separate buffer that will then be passed to the 'events'
352 * ringbuffer.
353 *
354 * This is because these functions can be called both for "one-shot"
355 * "rdesc" while resolving, or for blocking "events".
356 *
357 * This holds both for resolv_usage_page() and hid_resolv_usage().
358 */
359static char *resolv_usage_page(unsigned page, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100360 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200361 char *buf = NULL;
362
363 if (!f) {
364 buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
365 if (!buf)
366 return ERR_PTR(-ENOMEM);
367 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100368
369 for (p = hid_usage_table; p->description; p++)
370 if (p->page == page) {
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200371 if (!f) {
372 snprintf(buf, HID_DEBUG_BUFSIZE, "%s",
373 p->description);
374 return buf;
375 }
376 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200377 seq_printf(f, "%s", p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200378 return NULL;
379 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100380 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200381 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200382 snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200383 else
384 seq_printf(f, "%04x", page);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200385 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100386}
387
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200388char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100389 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200390 char *buf = NULL;
391 int len = 0;
Jiri Kosinac080d892007-01-25 11:43:31 +0100392
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200393 buf = resolv_usage_page(usage >> 16, f);
394 if (IS_ERR(buf)) {
395 printk(KERN_ERR "error allocating HID debug buffer\n");
396 return NULL;
397 }
Jiri Kosina58037eb2007-05-30 15:07:13 +0200398
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200399
400 if (!f) {
401 len = strlen(buf);
402 snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), ".");
403 len++;
404 }
405 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200406 seq_printf(f, ".");
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200407 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100408 for (p = hid_usage_table; p->description; p++)
409 if (p->page == (usage >> 16)) {
410 for(++p; p->description && p->usage != 0; p++)
411 if (p->usage == (usage & 0xffff)) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200412 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200413 snprintf(buf + len,
414 max(0,HID_DEBUG_BUFSIZE - len - 1),
415 "%s", p->description);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200416 else
417 seq_printf(f,
418 "%s",
419 p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200420 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100421 }
422 break;
423 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200424 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200425 snprintf(buf + len, max(0, HID_DEBUG_BUFSIZE - len - 1),
426 "%04x", usage & 0xffff);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200427 else
428 seq_printf(f, "%04x", usage & 0xffff);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200429 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100430}
431EXPORT_SYMBOL_GPL(hid_resolv_usage);
432
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200433static void tab(int n, struct seq_file *f) {
434 seq_printf(f, "%*s", n, "");
Jiri Kosinac080d892007-01-25 11:43:31 +0100435}
436
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200437void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100438 int j;
439
440 if (field->physical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200441 tab(n, f);
442 seq_printf(f, "Physical(");
443 hid_resolv_usage(field->physical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100444 }
445 if (field->logical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200446 tab(n, f);
447 seq_printf(f, "Logical(");
448 hid_resolv_usage(field->logical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100449 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200450 tab(n, f); seq_printf(f, "Usage(%d)\n", field->maxusage);
Jiri Kosinac080d892007-01-25 11:43:31 +0100451 for (j = 0; j < field->maxusage; j++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200452 tab(n+2, f); hid_resolv_usage(field->usage[j].hid, f); seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100453 }
454 if (field->logical_minimum != field->logical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200455 tab(n, f); seq_printf(f, "Logical Minimum(%d)\n", field->logical_minimum);
456 tab(n, f); seq_printf(f, "Logical Maximum(%d)\n", field->logical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100457 }
458 if (field->physical_minimum != field->physical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200459 tab(n, f); seq_printf(f, "Physical Minimum(%d)\n", field->physical_minimum);
460 tab(n, f); seq_printf(f, "Physical Maximum(%d)\n", field->physical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100461 }
462 if (field->unit_exponent) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200463 tab(n, f); seq_printf(f, "Unit Exponent(%d)\n", field->unit_exponent);
Jiri Kosinac080d892007-01-25 11:43:31 +0100464 }
465 if (field->unit) {
Joe Perches0ce1ac32007-09-26 16:29:53 +0200466 static const char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
467 static const char *units[5][8] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100468 { "None", "None", "None", "None", "None", "None", "None", "None" },
469 { "None", "Centimeter", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
470 { "None", "Radians", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
471 { "None", "Inch", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" },
472 { "None", "Degrees", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }
473 };
474
475 int i;
476 int sys;
477 __u32 data = field->unit;
478
479 /* First nibble tells us which system we're in. */
480 sys = data & 0xf;
481 data >>= 4;
482
483 if(sys > 4) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200484 tab(n, f); seq_printf(f, "Unit(Invalid)\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100485 }
486 else {
487 int earlier_unit = 0;
488
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200489 tab(n, f); seq_printf(f, "Unit(%s : ", systems[sys]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100490
491 for (i=1 ; i<sizeof(__u32)*2 ; i++) {
492 char nibble = data & 0xf;
493 data >>= 4;
494 if (nibble != 0) {
495 if(earlier_unit++ > 0)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200496 seq_printf(f, "*");
497 seq_printf(f, "%s", units[sys][i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100498 if(nibble != 1) {
499 /* This is a _signed_ nibble(!) */
500
501 int val = nibble & 0x7;
502 if(nibble & 0x08)
503 val = -((0x7 & ~val) +1);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200504 seq_printf(f, "^%d", val);
Jiri Kosinac080d892007-01-25 11:43:31 +0100505 }
506 }
507 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200508 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100509 }
510 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200511 tab(n, f); seq_printf(f, "Report Size(%u)\n", field->report_size);
512 tab(n, f); seq_printf(f, "Report Count(%u)\n", field->report_count);
513 tab(n, f); seq_printf(f, "Report Offset(%u)\n", field->report_offset);
Jiri Kosinac080d892007-01-25 11:43:31 +0100514
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200515 tab(n, f); seq_printf(f, "Flags( ");
Jiri Kosinac080d892007-01-25 11:43:31 +0100516 j = field->flags;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200517 seq_printf(f, "%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
518 seq_printf(f, "%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
519 seq_printf(f, "%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
520 seq_printf(f, "%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
521 seq_printf(f, "%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
522 seq_printf(f, "%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPreferredState " : "");
523 seq_printf(f, "%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
524 seq_printf(f, "%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
525 seq_printf(f, "%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
526 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100527}
528EXPORT_SYMBOL_GPL(hid_dump_field);
529
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200530void hid_dump_device(struct hid_device *device, struct seq_file *f)
531{
Jiri Kosinac080d892007-01-25 11:43:31 +0100532 struct hid_report_enum *report_enum;
533 struct hid_report *report;
534 struct list_head *list;
535 unsigned i,k;
Joe Perches0ce1ac32007-09-26 16:29:53 +0200536 static const char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
Jiri Kosinac080d892007-01-25 11:43:31 +0100537
538 for (i = 0; i < HID_REPORT_TYPES; i++) {
539 report_enum = device->report_enum + i;
540 list = report_enum->report_list.next;
541 while (list != &report_enum->report_list) {
542 report = (struct hid_report *) list;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200543 tab(2, f);
544 seq_printf(f, "%s", table[i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100545 if (report->id)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200546 seq_printf(f, "(%d)", report->id);
547 seq_printf(f, "[%s]", table[report->type]);
548 seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100549 for (k = 0; k < report->maxfield; k++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200550 tab(4, f);
551 seq_printf(f, "Field(%d)\n", k);
552 hid_dump_field(report->field[k], 6, f);
Jiri Kosinac080d892007-01-25 11:43:31 +0100553 }
554 list = list->next;
555 }
556 }
557}
558EXPORT_SYMBOL_GPL(hid_dump_device);
559
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200560/* enqueue string to 'events' ring buffer */
561void hid_debug_event(struct hid_device *hdev, char *buf)
562{
563 int i;
564 struct hid_debug_list *list;
Jiri Kosina58037eb2007-05-30 15:07:13 +0200565
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200566 list_for_each_entry(list, &hdev->debug_list, node) {
567 for (i = 0; i <= strlen(buf); i++)
568 list->hid_debug_buf[(list->tail + i) % (HID_DEBUG_BUFSIZE - 1)] =
569 buf[i];
570 list->tail = (list->tail + i) % (HID_DEBUG_BUFSIZE - 1);
571 }
572}
573EXPORT_SYMBOL_GPL(hid_debug_event);
574
575void hid_dump_input(struct hid_device *hdev, struct hid_usage *usage, __s32 value)
576{
577 char *buf;
578 int len;
579
580 buf = hid_resolv_usage(usage->hid, NULL);
581 if (!buf)
582 return;
583 len = strlen(buf);
584 snprintf(buf + len, HID_DEBUG_BUFSIZE - len - 1, " = %d\n", value);
585
586 hid_debug_event(hdev, buf);
587
588 kfree(buf);
589 wake_up_interruptible(&hdev->debug_wait);
590
Jiri Kosinac080d892007-01-25 11:43:31 +0100591}
592EXPORT_SYMBOL_GPL(hid_dump_input);
593
Joe Perches0ce1ac32007-09-26 16:29:53 +0200594static const char *events[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100595 [EV_SYN] = "Sync", [EV_KEY] = "Key",
596 [EV_REL] = "Relative", [EV_ABS] = "Absolute",
597 [EV_MSC] = "Misc", [EV_LED] = "LED",
598 [EV_SND] = "Sound", [EV_REP] = "Repeat",
599 [EV_FF] = "ForceFeedback", [EV_PWR] = "Power",
600 [EV_FF_STATUS] = "ForceFeedbackStatus",
601};
602
Stephane Chatty89f536c2009-05-20 15:41:24 +0200603static const char *syncs[3] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100604 [SYN_REPORT] = "Report", [SYN_CONFIG] = "Config",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200605 [SYN_MT_REPORT] = "MT Report",
Jiri Kosinac080d892007-01-25 11:43:31 +0100606};
Stephane Chatty89f536c2009-05-20 15:41:24 +0200607
Joe Perches0ce1ac32007-09-26 16:29:53 +0200608static const char *keys[KEY_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100609 [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc",
610 [KEY_1] = "1", [KEY_2] = "2",
611 [KEY_3] = "3", [KEY_4] = "4",
612 [KEY_5] = "5", [KEY_6] = "6",
613 [KEY_7] = "7", [KEY_8] = "8",
614 [KEY_9] = "9", [KEY_0] = "0",
615 [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal",
616 [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab",
617 [KEY_Q] = "Q", [KEY_W] = "W",
618 [KEY_E] = "E", [KEY_R] = "R",
619 [KEY_T] = "T", [KEY_Y] = "Y",
620 [KEY_U] = "U", [KEY_I] = "I",
621 [KEY_O] = "O", [KEY_P] = "P",
622 [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace",
623 [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl",
624 [KEY_A] = "A", [KEY_S] = "S",
625 [KEY_D] = "D", [KEY_F] = "F",
626 [KEY_G] = "G", [KEY_H] = "H",
627 [KEY_J] = "J", [KEY_K] = "K",
628 [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon",
629 [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave",
630 [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash",
631 [KEY_Z] = "Z", [KEY_X] = "X",
632 [KEY_C] = "C", [KEY_V] = "V",
633 [KEY_B] = "B", [KEY_N] = "N",
634 [KEY_M] = "M", [KEY_COMMA] = "Comma",
635 [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash",
636 [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk",
637 [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space",
638 [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1",
639 [KEY_F2] = "F2", [KEY_F3] = "F3",
640 [KEY_F4] = "F4", [KEY_F5] = "F5",
641 [KEY_F6] = "F6", [KEY_F7] = "F7",
642 [KEY_F8] = "F8", [KEY_F9] = "F9",
643 [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock",
644 [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7",
645 [KEY_KP8] = "KP8", [KEY_KP9] = "KP9",
646 [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4",
647 [KEY_KP5] = "KP5", [KEY_KP6] = "KP6",
648 [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1",
649 [KEY_KP2] = "KP2", [KEY_KP3] = "KP3",
650 [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot",
651 [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd",
652 [KEY_F11] = "F11", [KEY_F12] = "F12",
653 [KEY_RO] = "RO", [KEY_KATAKANA] = "Katakana",
654 [KEY_HIRAGANA] = "HIRAGANA", [KEY_HENKAN] = "Henkan",
655 [KEY_KATAKANAHIRAGANA] = "Katakana/Hiragana", [KEY_MUHENKAN] = "Muhenkan",
656 [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter",
657 [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash",
658 [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt",
659 [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home",
660 [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp",
661 [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right",
662 [KEY_END] = "End", [KEY_DOWN] = "Down",
663 [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert",
664 [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro",
665 [KEY_MUTE] = "Mute", [KEY_VOLUMEDOWN] = "VolumeDown",
666 [KEY_VOLUMEUP] = "VolumeUp", [KEY_POWER] = "Power",
667 [KEY_KPEQUAL] = "KPEqual", [KEY_KPPLUSMINUS] = "KPPlusMinus",
668 [KEY_PAUSE] = "Pause", [KEY_KPCOMMA] = "KPComma",
669 [KEY_HANGUEL] = "Hangeul", [KEY_HANJA] = "Hanja",
670 [KEY_YEN] = "Yen", [KEY_LEFTMETA] = "LeftMeta",
671 [KEY_RIGHTMETA] = "RightMeta", [KEY_COMPOSE] = "Compose",
672 [KEY_STOP] = "Stop", [KEY_AGAIN] = "Again",
673 [KEY_PROPS] = "Props", [KEY_UNDO] = "Undo",
674 [KEY_FRONT] = "Front", [KEY_COPY] = "Copy",
675 [KEY_OPEN] = "Open", [KEY_PASTE] = "Paste",
676 [KEY_FIND] = "Find", [KEY_CUT] = "Cut",
677 [KEY_HELP] = "Help", [KEY_MENU] = "Menu",
678 [KEY_CALC] = "Calc", [KEY_SETUP] = "Setup",
679 [KEY_SLEEP] = "Sleep", [KEY_WAKEUP] = "WakeUp",
680 [KEY_FILE] = "File", [KEY_SENDFILE] = "SendFile",
681 [KEY_DELETEFILE] = "DeleteFile", [KEY_XFER] = "X-fer",
682 [KEY_PROG1] = "Prog1", [KEY_PROG2] = "Prog2",
683 [KEY_WWW] = "WWW", [KEY_MSDOS] = "MSDOS",
684 [KEY_COFFEE] = "Coffee", [KEY_DIRECTION] = "Direction",
685 [KEY_CYCLEWINDOWS] = "CycleWindows", [KEY_MAIL] = "Mail",
686 [KEY_BOOKMARKS] = "Bookmarks", [KEY_COMPUTER] = "Computer",
687 [KEY_BACK] = "Back", [KEY_FORWARD] = "Forward",
688 [KEY_CLOSECD] = "CloseCD", [KEY_EJECTCD] = "EjectCD",
689 [KEY_EJECTCLOSECD] = "EjectCloseCD", [KEY_NEXTSONG] = "NextSong",
690 [KEY_PLAYPAUSE] = "PlayPause", [KEY_PREVIOUSSONG] = "PreviousSong",
691 [KEY_STOPCD] = "StopCD", [KEY_RECORD] = "Record",
692 [KEY_REWIND] = "Rewind", [KEY_PHONE] = "Phone",
693 [KEY_ISO] = "ISOKey", [KEY_CONFIG] = "Config",
694 [KEY_HOMEPAGE] = "HomePage", [KEY_REFRESH] = "Refresh",
695 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
696 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
697 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
698 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
699 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
700 [KEY_F14] = "F14", [KEY_F15] = "F15",
701 [KEY_F16] = "F16", [KEY_F17] = "F17",
702 [KEY_F18] = "F18", [KEY_F19] = "F19",
703 [KEY_F20] = "F20", [KEY_F21] = "F21",
704 [KEY_F22] = "F22", [KEY_F23] = "F23",
705 [KEY_F24] = "F24", [KEY_PLAYCD] = "PlayCD",
706 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
707 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend",
708 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
709 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
710 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
711 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
712 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
713 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
714 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
715 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
716 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
717 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
718 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
719 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
720 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
721 [BTN_4] = "Btn4", [BTN_5] = "Btn5",
722 [BTN_6] = "Btn6", [BTN_7] = "Btn7",
723 [BTN_8] = "Btn8", [BTN_9] = "Btn9",
724 [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn",
725 [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn",
726 [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn",
727 [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn",
728 [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn",
729 [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn",
730 [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn",
731 [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2",
732 [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4",
733 [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6",
734 [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA",
735 [BTN_B] = "BtnB", [BTN_C] = "BtnC",
736 [BTN_X] = "BtnX", [BTN_Y] = "BtnY",
737 [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL",
738 [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2",
739 [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect",
740 [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode",
741 [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR",
742 [BTN_TOOL_PEN] = "ToolPen", [BTN_TOOL_RUBBER] = "ToolRubber",
743 [BTN_TOOL_BRUSH] = "ToolBrush", [BTN_TOOL_PENCIL] = "ToolPencil",
744 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
745 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
746 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
747 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
748 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_GEAR_DOWN] = "WheelBtn",
749 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
750 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
751 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
752 [KEY_OPTION] = "Option", [KEY_INFO] = "Info",
753 [KEY_TIME] = "Time", [KEY_VENDOR] = "Vendor",
754 [KEY_ARCHIVE] = "Archive", [KEY_PROGRAM] = "Program",
755 [KEY_CHANNEL] = "Channel", [KEY_FAVORITES] = "Favorites",
756 [KEY_EPG] = "EPG", [KEY_PVR] = "PVR",
757 [KEY_MHP] = "MHP", [KEY_LANGUAGE] = "Language",
758 [KEY_TITLE] = "Title", [KEY_SUBTITLE] = "Subtitle",
759 [KEY_ANGLE] = "Angle", [KEY_ZOOM] = "Zoom",
760 [KEY_MODE] = "Mode", [KEY_KEYBOARD] = "Keyboard",
761 [KEY_SCREEN] = "Screen", [KEY_PC] = "PC",
762 [KEY_TV] = "TV", [KEY_TV2] = "TV2",
763 [KEY_VCR] = "VCR", [KEY_VCR2] = "VCR2",
764 [KEY_SAT] = "Sat", [KEY_SAT2] = "Sat2",
765 [KEY_CD] = "CD", [KEY_TAPE] = "Tape",
766 [KEY_RADIO] = "Radio", [KEY_TUNER] = "Tuner",
767 [KEY_PLAYER] = "Player", [KEY_TEXT] = "Text",
768 [KEY_DVD] = "DVD", [KEY_AUX] = "Aux",
769 [KEY_MP3] = "MP3", [KEY_AUDIO] = "Audio",
770 [KEY_VIDEO] = "Video", [KEY_DIRECTORY] = "Directory",
771 [KEY_LIST] = "List", [KEY_MEMO] = "Memo",
772 [KEY_CALENDAR] = "Calendar", [KEY_RED] = "Red",
773 [KEY_GREEN] = "Green", [KEY_YELLOW] = "Yellow",
774 [KEY_BLUE] = "Blue", [KEY_CHANNELUP] = "ChannelUp",
775 [KEY_CHANNELDOWN] = "ChannelDown", [KEY_FIRST] = "First",
776 [KEY_LAST] = "Last", [KEY_AB] = "AB",
777 [KEY_NEXT] = "Next", [KEY_RESTART] = "Restart",
778 [KEY_SLOW] = "Slow", [KEY_SHUFFLE] = "Shuffle",
779 [KEY_BREAK] = "Break", [KEY_PREVIOUS] = "Previous",
780 [KEY_DIGITS] = "Digits", [KEY_TEEN] = "TEEN",
781 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
782 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
783 [KEY_DEL_LINE] = "DeleteLine",
784 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
785 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
Jiri Kosina1fe8736d2007-08-09 13:24:11 +0200786 [KEY_DOCUMENTS] = "Documents", [KEY_SPELLCHECK] = "SpellCheck",
Khelben Blackstaffe2bca072007-10-04 10:32:03 +0200787 [KEY_LOGOFF] = "Logoff",
Jiri Kosinac080d892007-01-25 11:43:31 +0100788 [KEY_FN] = "Fn", [KEY_FN_ESC] = "Fn+ESC",
789 [KEY_FN_1] = "Fn+1", [KEY_FN_2] = "Fn+2",
790 [KEY_FN_B] = "Fn+B", [KEY_FN_D] = "Fn+D",
791 [KEY_FN_E] = "Fn+E", [KEY_FN_F] = "Fn+F",
792 [KEY_FN_S] = "Fn+S",
793 [KEY_FN_F1] = "Fn+F1", [KEY_FN_F2] = "Fn+F2",
794 [KEY_FN_F3] = "Fn+F3", [KEY_FN_F4] = "Fn+F4",
795 [KEY_FN_F5] = "Fn+F5", [KEY_FN_F6] = "Fn+F6",
796 [KEY_FN_F7] = "Fn+F7", [KEY_FN_F8] = "Fn+F8",
797 [KEY_FN_F9] = "Fn+F9", [KEY_FN_F10] = "Fn+F10",
798 [KEY_FN_F11] = "Fn+F11", [KEY_FN_F12] = "Fn+F12",
799 [KEY_KBDILLUMTOGGLE] = "KbdIlluminationToggle",
800 [KEY_KBDILLUMDOWN] = "KbdIlluminationDown",
801 [KEY_KBDILLUMUP] = "KbdIlluminationUp",
802 [KEY_SWITCHVIDEOMODE] = "SwitchVideoMode",
803};
804
Joe Perches0ce1ac32007-09-26 16:29:53 +0200805static const char *relatives[REL_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100806 [REL_X] = "X", [REL_Y] = "Y",
807 [REL_Z] = "Z", [REL_RX] = "Rx",
808 [REL_RY] = "Ry", [REL_RZ] = "Rz",
809 [REL_HWHEEL] = "HWheel", [REL_DIAL] = "Dial",
810 [REL_WHEEL] = "Wheel", [REL_MISC] = "Misc",
811};
812
Joe Perches0ce1ac32007-09-26 16:29:53 +0200813static const char *absolutes[ABS_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100814 [ABS_X] = "X", [ABS_Y] = "Y",
815 [ABS_Z] = "Z", [ABS_RX] = "Rx",
816 [ABS_RY] = "Ry", [ABS_RZ] = "Rz",
817 [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder",
818 [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas",
819 [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X",
820 [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X",
821 [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X",
822 [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X",
823 [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure",
824 [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200825 [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth",
Jiri Kosinac080d892007-01-25 11:43:31 +0100826 [ABS_VOLUME] = "Volume", [ABS_MISC] = "Misc",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200827 [ABS_MT_TOUCH_MAJOR] = "MTMajor",
828 [ABS_MT_TOUCH_MINOR] = "MTMinor",
829 [ABS_MT_WIDTH_MAJOR] = "MTMajorW",
830 [ABS_MT_WIDTH_MINOR] = "MTMinorW",
831 [ABS_MT_ORIENTATION] = "MTOrientation",
832 [ABS_MT_POSITION_X] = "MTPositionX",
833 [ABS_MT_POSITION_Y] = "MTPositionY",
834 [ABS_MT_TOOL_TYPE] = "MTToolType",
835 [ABS_MT_BLOB_ID] = "MTBlobID",
Jiri Kosinac080d892007-01-25 11:43:31 +0100836};
837
Joe Perches0ce1ac32007-09-26 16:29:53 +0200838static const char *misc[MSC_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100839 [MSC_SERIAL] = "Serial", [MSC_PULSELED] = "Pulseled",
840 [MSC_GESTURE] = "Gesture", [MSC_RAW] = "RawData"
841};
842
Joe Perches0ce1ac32007-09-26 16:29:53 +0200843static const char *leds[LED_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100844 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
845 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
846 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
847 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
848 [LED_MISC] = "Misc",
849};
850
Joe Perches0ce1ac32007-09-26 16:29:53 +0200851static const char *repeats[REP_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100852 [REP_DELAY] = "Delay", [REP_PERIOD] = "Period"
853};
854
Joe Perches0ce1ac32007-09-26 16:29:53 +0200855static const char *sounds[SND_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100856 [SND_CLICK] = "Click", [SND_BELL] = "Bell",
857 [SND_TONE] = "Tone"
858};
859
Joe Perches0ce1ac32007-09-26 16:29:53 +0200860static const char **names[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100861 [EV_SYN] = syncs, [EV_KEY] = keys,
862 [EV_REL] = relatives, [EV_ABS] = absolutes,
863 [EV_MSC] = misc, [EV_LED] = leds,
864 [EV_SND] = sounds, [EV_REP] = repeats,
865};
866
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200867void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100868
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200869 seq_printf(f, "%s.%s", events[type] ? events[type] : "?",
Jiri Kosinac080d892007-01-25 11:43:31 +0100870 names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
871}
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200872
873void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
874{
875 int i, j, k;
876 struct hid_report *report;
877 struct hid_usage *usage;
878
879 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
880 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
881 for (i = 0; i < report->maxfield; i++) {
882 for ( j = 0; j < report->field[i]->maxusage; j++) {
883 usage = report->field[i]->usage + j;
884 hid_resolv_usage(usage->hid, f);
885 seq_printf(f, " ---> ");
886 hid_resolv_event(usage->type, usage->code, f);
887 seq_printf(f, "\n");
888 }
889 }
890 }
891 }
892
893}
894
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200895
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200896static int hid_debug_rdesc_show(struct seq_file *f, void *p)
897{
898 struct hid_device *hdev = f->private;
899 int i;
900
901 /* dump HID report descriptor */
902 for (i = 0; i < hdev->rsize; i++)
903 seq_printf(f, "%02x ", hdev->rdesc[i]);
904 seq_printf(f, "\n\n");
905
906 /* dump parsed data and input mappings */
907 hid_dump_device(hdev, f);
908 seq_printf(f, "\n");
909 hid_dump_input_mapping(hdev, f);
910
911 return 0;
912}
913
914static int hid_debug_rdesc_open(struct inode *inode, struct file *file)
915{
916 return single_open(file, hid_debug_rdesc_show, inode->i_private);
917}
918
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200919static int hid_debug_events_open(struct inode *inode, struct file *file)
920{
921 int err = 0;
922 struct hid_debug_list *list;
923
924 if (!(list = kzalloc(sizeof(struct hid_debug_list), GFP_KERNEL))) {
925 err = -ENOMEM;
926 goto out;
927 }
928
929 if (!(list->hid_debug_buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_KERNEL))) {
930 err = -ENOMEM;
Julia Lawalla809dda2009-08-08 02:26:10 +0200931 kfree(list);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200932 goto out;
933 }
934 list->hdev = (struct hid_device *) inode->i_private;
935 file->private_data = list;
936 mutex_init(&list->read_mutex);
937
938 list_add_tail(&list->node, &list->hdev->debug_list);
939
940out:
941 return err;
942}
943
944static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
945 size_t count, loff_t *ppos)
946{
947 struct hid_debug_list *list = file->private_data;
948 int ret = 0, len;
949 DECLARE_WAITQUEUE(wait, current);
950
951 while (ret == 0) {
952 mutex_lock(&list->read_mutex);
953 if (list->head == list->tail) {
954 add_wait_queue(&list->hdev->debug_wait, &wait);
955 set_current_state(TASK_INTERRUPTIBLE);
956
957 while (list->head == list->tail) {
958 if (file->f_flags & O_NONBLOCK) {
959 ret = -EAGAIN;
960 break;
961 }
962 if (signal_pending(current)) {
963 ret = -ERESTARTSYS;
964 break;
965 }
966
967 if (!list->hdev || !list->hdev->debug) {
968 ret = -EIO;
969 break;
970 }
971
972 /* allow O_NONBLOCK from other threads */
973 mutex_unlock(&list->read_mutex);
974 schedule();
975 mutex_lock(&list->read_mutex);
976 set_current_state(TASK_INTERRUPTIBLE);
977 }
978
979 set_current_state(TASK_RUNNING);
980 remove_wait_queue(&list->hdev->debug_wait, &wait);
981 }
982
983 if (ret)
984 goto out;
985
986 /* pass the ringbuffer contents to userspace */
987copy_rest:
988 if (list->tail == list->head)
989 goto out;
990 if (list->tail > list->head) {
991 len = list->tail - list->head;
992
993 if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) {
994 ret = -EFAULT;
995 goto out;
996 }
997 ret += len;
998 list->head += len;
999 } else {
1000 len = HID_DEBUG_BUFSIZE - list->head;
1001
1002 if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) {
1003 ret = -EFAULT;
1004 goto out;
1005 }
1006 list->head = 0;
1007 ret += len;
1008 goto copy_rest;
1009 }
1010
1011 }
1012out:
1013 mutex_unlock(&list->read_mutex);
1014 return ret;
1015}
1016
1017static unsigned int hid_debug_events_poll(struct file *file, poll_table *wait)
1018{
1019 struct hid_debug_list *list = file->private_data;
1020
1021 poll_wait(file, &list->hdev->debug_wait, wait);
1022 if (list->head != list->tail)
1023 return POLLIN | POLLRDNORM;
1024 if (!list->hdev->debug)
1025 return POLLERR | POLLHUP;
1026 return 0;
1027}
1028
1029static int hid_debug_events_release(struct inode *inode, struct file *file)
1030{
1031 struct hid_debug_list *list = file->private_data;
1032
1033 list_del(&list->node);
1034 kfree(list->hid_debug_buf);
1035 kfree(list);
1036
1037 return 0;
1038}
1039
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001040static const struct file_operations hid_debug_rdesc_fops = {
1041 .open = hid_debug_rdesc_open,
1042 .read = seq_read,
1043 .llseek = seq_lseek,
1044 .release = single_release,
1045};
1046
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001047static const struct file_operations hid_debug_events_fops = {
1048 .owner = THIS_MODULE,
1049 .open = hid_debug_events_open,
1050 .read = hid_debug_events_read,
1051 .poll = hid_debug_events_poll,
1052 .release = hid_debug_events_release,
1053};
1054
1055
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001056void hid_debug_register(struct hid_device *hdev, const char *name)
1057{
1058 hdev->debug_dir = debugfs_create_dir(name, hid_debug_root);
1059 hdev->debug_rdesc = debugfs_create_file("rdesc", 0400,
1060 hdev->debug_dir, hdev, &hid_debug_rdesc_fops);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001061 hdev->debug_events = debugfs_create_file("events", 0400,
1062 hdev->debug_dir, hdev, &hid_debug_events_fops);
1063 hdev->debug = 1;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001064}
1065
1066void hid_debug_unregister(struct hid_device *hdev)
1067{
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001068 hdev->debug = 0;
1069 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001070 debugfs_remove(hdev->debug_rdesc);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001071 debugfs_remove(hdev->debug_events);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001072 debugfs_remove(hdev->debug_dir);
1073}
1074
1075void hid_debug_init(void)
1076{
1077 hid_debug_root = debugfs_create_dir("hid", NULL);
1078}
1079
1080void hid_debug_exit(void)
1081{
1082 debugfs_remove_recursive(hid_debug_root);
1083}
1084