blob: 3cafa1d28fedd1ee59840409b4c93965c60cc611 [file] [log] [blame]
Jiri Kosinac080d892007-01-25 11:43:31 +01001/*
Jiri Kosinac080d892007-01-25 11:43:31 +01002 * (c) 1999 Andreas Gal <gal@cs.uni-magdeburg.de>
3 * (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz>
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02004 * (c) 2007-2009 Jiri Kosina
Jiri Kosinac080d892007-01-25 11:43:31 +01005 *
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02006 * HID debugging support
Jiri Kosinac080d892007-01-25 11:43:31 +01007 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */
28
Joe Perches4291ee32010-12-09 19:29:03 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jiri Kosinaa635f9d2009-06-12 15:20:55 +020031#include <linux/debugfs.h>
32#include <linux/seq_file.h>
Vladis Dronov64a9f5f2019-01-29 11:58:35 +010033#include <linux/kfifo.h>
Jiri Kosinacd667ce2009-06-12 15:20:57 +020034#include <linux/sched.h>
Paul Gortmakerec37d322011-05-27 10:25:27 -040035#include <linux/export.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Jiri Kosinacd667ce2009-06-12 15:20:57 +020037#include <linux/uaccess.h>
38#include <linux/poll.h>
39
Jiri Kosinac080d892007-01-25 11:43:31 +010040#include <linux/hid.h>
Adrian Bunk4330eb22007-02-21 12:57:30 +010041#include <linux/hid-debug.h>
Jiri Kosinac080d892007-01-25 11:43:31 +010042
Jiri Kosinaa635f9d2009-06-12 15:20:55 +020043static struct dentry *hid_debug_root;
44
Jiri Kosinac080d892007-01-25 11:43:31 +010045struct hid_usage_entry {
46 unsigned page;
47 unsigned usage;
Joe Perches0ce1ac32007-09-26 16:29:53 +020048 const char *description;
Jiri Kosinac080d892007-01-25 11:43:31 +010049};
50
51static const struct hid_usage_entry hid_usage_table[] = {
52 { 0, 0, "Undefined" },
53 { 1, 0, "GenericDesktop" },
54 {0, 0x01, "Pointer"},
55 {0, 0x02, "Mouse"},
56 {0, 0x04, "Joystick"},
57 {0, 0x05, "GamePad"},
58 {0, 0x06, "Keyboard"},
59 {0, 0x07, "Keypad"},
60 {0, 0x08, "MultiAxis"},
61 {0, 0x30, "X"},
62 {0, 0x31, "Y"},
63 {0, 0x32, "Z"},
64 {0, 0x33, "Rx"},
65 {0, 0x34, "Ry"},
66 {0, 0x35, "Rz"},
67 {0, 0x36, "Slider"},
68 {0, 0x37, "Dial"},
69 {0, 0x38, "Wheel"},
70 {0, 0x39, "HatSwitch"},
71 {0, 0x3a, "CountedBuffer"},
72 {0, 0x3b, "ByteCount"},
73 {0, 0x3c, "MotionWakeup"},
74 {0, 0x3d, "Start"},
75 {0, 0x3e, "Select"},
76 {0, 0x40, "Vx"},
77 {0, 0x41, "Vy"},
78 {0, 0x42, "Vz"},
79 {0, 0x43, "Vbrx"},
80 {0, 0x44, "Vbry"},
81 {0, 0x45, "Vbrz"},
82 {0, 0x46, "Vno"},
83 {0, 0x80, "SystemControl"},
84 {0, 0x81, "SystemPowerDown"},
85 {0, 0x82, "SystemSleep"},
86 {0, 0x83, "SystemWakeUp"},
87 {0, 0x84, "SystemContextMenu"},
88 {0, 0x85, "SystemMainMenu"},
89 {0, 0x86, "SystemAppMenu"},
90 {0, 0x87, "SystemMenuHelp"},
91 {0, 0x88, "SystemMenuExit"},
92 {0, 0x89, "SystemMenuSelect"},
93 {0, 0x8a, "SystemMenuRight"},
94 {0, 0x8b, "SystemMenuLeft"},
95 {0, 0x8c, "SystemMenuUp"},
96 {0, 0x8d, "SystemMenuDown"},
97 {0, 0x90, "D-PadUp"},
98 {0, 0x91, "D-PadDown"},
99 {0, 0x92, "D-PadRight"},
100 {0, 0x93, "D-PadLeft"},
101 { 2, 0, "Simulation" },
102 {0, 0xb0, "Aileron"},
103 {0, 0xb1, "AileronTrim"},
104 {0, 0xb2, "Anti-Torque"},
105 {0, 0xb3, "Autopilot"},
106 {0, 0xb4, "Chaff"},
107 {0, 0xb5, "Collective"},
108 {0, 0xb6, "DiveBrake"},
109 {0, 0xb7, "ElectronicCountermeasures"},
110 {0, 0xb8, "Elevator"},
111 {0, 0xb9, "ElevatorTrim"},
112 {0, 0xba, "Rudder"},
113 {0, 0xbb, "Throttle"},
114 {0, 0xbc, "FlightCommunications"},
115 {0, 0xbd, "FlareRelease"},
116 {0, 0xbe, "LandingGear"},
117 {0, 0xbf, "ToeBrake"},
Jeremy Fitzhardinge1f591692011-11-19 12:19:00 +0100118 { 6, 0, "GenericDeviceControls" },
119 {0, 0x20, "BatteryStrength" },
120 {0, 0x21, "WirelessChannel" },
121 {0, 0x22, "WirelessID" },
122 {0, 0x23, "DiscoverWirelessControl" },
123 {0, 0x24, "SecurityCodeCharacterEntered" },
124 {0, 0x25, "SecurityCodeCharactedErased" },
125 {0, 0x26, "SecurityCodeCleared" },
Jiri Kosinac080d892007-01-25 11:43:31 +0100126 { 7, 0, "Keyboard" },
127 { 8, 0, "LED" },
128 {0, 0x01, "NumLock"},
129 {0, 0x02, "CapsLock"},
130 {0, 0x03, "ScrollLock"},
131 {0, 0x04, "Compose"},
132 {0, 0x05, "Kana"},
133 {0, 0x4b, "GenericIndicator"},
134 { 9, 0, "Button" },
135 { 10, 0, "Ordinal" },
136 { 12, 0, "Consumer" },
137 {0, 0x238, "HorizontalWheel"},
138 { 13, 0, "Digitizers" },
139 {0, 0x01, "Digitizer"},
140 {0, 0x02, "Pen"},
141 {0, 0x03, "LightPen"},
142 {0, 0x04, "TouchScreen"},
143 {0, 0x05, "TouchPad"},
144 {0, 0x20, "Stylus"},
145 {0, 0x21, "Puck"},
146 {0, 0x22, "Finger"},
147 {0, 0x30, "TipPressure"},
148 {0, 0x31, "BarrelPressure"},
149 {0, 0x32, "InRange"},
150 {0, 0x33, "Touch"},
151 {0, 0x34, "UnTouch"},
152 {0, 0x35, "Tap"},
153 {0, 0x39, "TabletFunctionKey"},
154 {0, 0x3a, "ProgramChangeKey"},
155 {0, 0x3c, "Invert"},
156 {0, 0x42, "TipSwitch"},
157 {0, 0x43, "SecondaryTipSwitch"},
158 {0, 0x44, "BarrelSwitch"},
159 {0, 0x45, "Eraser"},
160 {0, 0x46, "TabletPick"},
Stephane Chatty89f536c2009-05-20 15:41:24 +0200161 {0, 0x47, "Confidence"},
162 {0, 0x48, "Width"},
163 {0, 0x49, "Height"},
164 {0, 0x51, "ContactID"},
165 {0, 0x52, "InputMode"},
166 {0, 0x53, "DeviceIndex"},
167 {0, 0x54, "ContactCount"},
168 {0, 0x55, "ContactMaximumNumber"},
Seth Forshee2c6e0272015-03-11 17:26:41 -0500169 {0, 0x59, "ButtonType"},
Ping Cheng368c9662014-06-02 17:19:52 -0700170 {0, 0x5A, "SecondaryBarrelSwitch"},
171 {0, 0x5B, "TransducerSerialNumber"},
Jiri Kosinac080d892007-01-25 11:43:31 +0100172 { 15, 0, "PhysicalInterfaceDevice" },
173 {0, 0x00, "Undefined"},
174 {0, 0x01, "Physical_Interface_Device"},
175 {0, 0x20, "Normal"},
176 {0, 0x21, "Set_Effect_Report"},
177 {0, 0x22, "Effect_Block_Index"},
178 {0, 0x23, "Parameter_Block_Offset"},
179 {0, 0x24, "ROM_Flag"},
180 {0, 0x25, "Effect_Type"},
181 {0, 0x26, "ET_Constant_Force"},
182 {0, 0x27, "ET_Ramp"},
183 {0, 0x28, "ET_Custom_Force_Data"},
184 {0, 0x30, "ET_Square"},
185 {0, 0x31, "ET_Sine"},
186 {0, 0x32, "ET_Triangle"},
187 {0, 0x33, "ET_Sawtooth_Up"},
188 {0, 0x34, "ET_Sawtooth_Down"},
189 {0, 0x40, "ET_Spring"},
190 {0, 0x41, "ET_Damper"},
191 {0, 0x42, "ET_Inertia"},
192 {0, 0x43, "ET_Friction"},
193 {0, 0x50, "Duration"},
194 {0, 0x51, "Sample_Period"},
195 {0, 0x52, "Gain"},
196 {0, 0x53, "Trigger_Button"},
197 {0, 0x54, "Trigger_Repeat_Interval"},
198 {0, 0x55, "Axes_Enable"},
199 {0, 0x56, "Direction_Enable"},
200 {0, 0x57, "Direction"},
201 {0, 0x58, "Type_Specific_Block_Offset"},
202 {0, 0x59, "Block_Type"},
203 {0, 0x5A, "Set_Envelope_Report"},
204 {0, 0x5B, "Attack_Level"},
205 {0, 0x5C, "Attack_Time"},
206 {0, 0x5D, "Fade_Level"},
207 {0, 0x5E, "Fade_Time"},
208 {0, 0x5F, "Set_Condition_Report"},
209 {0, 0x60, "CP_Offset"},
210 {0, 0x61, "Positive_Coefficient"},
211 {0, 0x62, "Negative_Coefficient"},
212 {0, 0x63, "Positive_Saturation"},
213 {0, 0x64, "Negative_Saturation"},
214 {0, 0x65, "Dead_Band"},
215 {0, 0x66, "Download_Force_Sample"},
216 {0, 0x67, "Isoch_Custom_Force_Enable"},
217 {0, 0x68, "Custom_Force_Data_Report"},
218 {0, 0x69, "Custom_Force_Data"},
219 {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
220 {0, 0x6B, "Set_Custom_Force_Report"},
221 {0, 0x6C, "Custom_Force_Data_Offset"},
222 {0, 0x6D, "Sample_Count"},
223 {0, 0x6E, "Set_Periodic_Report"},
224 {0, 0x6F, "Offset"},
225 {0, 0x70, "Magnitude"},
226 {0, 0x71, "Phase"},
227 {0, 0x72, "Period"},
228 {0, 0x73, "Set_Constant_Force_Report"},
229 {0, 0x74, "Set_Ramp_Force_Report"},
230 {0, 0x75, "Ramp_Start"},
231 {0, 0x76, "Ramp_End"},
232 {0, 0x77, "Effect_Operation_Report"},
233 {0, 0x78, "Effect_Operation"},
234 {0, 0x79, "Op_Effect_Start"},
235 {0, 0x7A, "Op_Effect_Start_Solo"},
236 {0, 0x7B, "Op_Effect_Stop"},
237 {0, 0x7C, "Loop_Count"},
238 {0, 0x7D, "Device_Gain_Report"},
239 {0, 0x7E, "Device_Gain"},
240 {0, 0x7F, "PID_Pool_Report"},
241 {0, 0x80, "RAM_Pool_Size"},
242 {0, 0x81, "ROM_Pool_Size"},
243 {0, 0x82, "ROM_Effect_Block_Count"},
244 {0, 0x83, "Simultaneous_Effects_Max"},
245 {0, 0x84, "Pool_Alignment"},
246 {0, 0x85, "PID_Pool_Move_Report"},
247 {0, 0x86, "Move_Source"},
248 {0, 0x87, "Move_Destination"},
249 {0, 0x88, "Move_Length"},
250 {0, 0x89, "PID_Block_Load_Report"},
251 {0, 0x8B, "Block_Load_Status"},
252 {0, 0x8C, "Block_Load_Success"},
253 {0, 0x8D, "Block_Load_Full"},
254 {0, 0x8E, "Block_Load_Error"},
255 {0, 0x8F, "Block_Handle"},
256 {0, 0x90, "PID_Block_Free_Report"},
257 {0, 0x91, "Type_Specific_Block_Handle"},
258 {0, 0x92, "PID_State_Report"},
259 {0, 0x94, "Effect_Playing"},
260 {0, 0x95, "PID_Device_Control_Report"},
261 {0, 0x96, "PID_Device_Control"},
262 {0, 0x97, "DC_Enable_Actuators"},
263 {0, 0x98, "DC_Disable_Actuators"},
264 {0, 0x99, "DC_Stop_All_Effects"},
265 {0, 0x9A, "DC_Device_Reset"},
266 {0, 0x9B, "DC_Device_Pause"},
267 {0, 0x9C, "DC_Device_Continue"},
268 {0, 0x9F, "Device_Paused"},
269 {0, 0xA0, "Actuators_Enabled"},
270 {0, 0xA4, "Safety_Switch"},
271 {0, 0xA5, "Actuator_Override_Switch"},
272 {0, 0xA6, "Actuator_Power"},
273 {0, 0xA7, "Start_Delay"},
274 {0, 0xA8, "Parameter_Block_Size"},
275 {0, 0xA9, "Device_Managed_Pool"},
276 {0, 0xAA, "Shared_Parameter_Blocks"},
277 {0, 0xAB, "Create_New_Effect_Report"},
278 {0, 0xAC, "RAM_Pool_Available"},
Reyad Attiyatb510d092014-05-27 02:10:59 -0500279 { 0x20, 0, "Sensor" },
280 { 0x20, 0x01, "Sensor" },
281 { 0x20, 0x10, "Biometric" },
282 { 0x20, 0x11, "BiometricHumanPresence" },
283 { 0x20, 0x12, "BiometricHumanProximity" },
284 { 0x20, 0x13, "BiometricHumanTouch" },
285 { 0x20, 0x20, "Electrical" },
286 { 0x20, 0x21, "ElectricalCapacitance" },
287 { 0x20, 0x22, "ElectricalCurrent" },
288 { 0x20, 0x23, "ElectricalPower" },
289 { 0x20, 0x24, "ElectricalInductance" },
290 { 0x20, 0x25, "ElectricalResistance" },
291 { 0x20, 0x26, "ElectricalVoltage" },
292 { 0x20, 0x27, "ElectricalPoteniometer" },
293 { 0x20, 0x28, "ElectricalFrequency" },
294 { 0x20, 0x29, "ElectricalPeriod" },
295 { 0x20, 0x30, "Environmental" },
296 { 0x20, 0x31, "EnvironmentalAtmosphericPressure" },
297 { 0x20, 0x32, "EnvironmentalHumidity" },
298 { 0x20, 0x33, "EnvironmentalTemperature" },
299 { 0x20, 0x34, "EnvironmentalWindDirection" },
300 { 0x20, 0x35, "EnvironmentalWindSpeed" },
301 { 0x20, 0x40, "Light" },
302 { 0x20, 0x41, "LightAmbientLight" },
303 { 0x20, 0x42, "LightConsumerInfrared" },
304 { 0x20, 0x50, "Location" },
305 { 0x20, 0x51, "LocationBroadcast" },
306 { 0x20, 0x52, "LocationDeadReckoning" },
307 { 0x20, 0x53, "LocationGPS" },
308 { 0x20, 0x54, "LocationLookup" },
309 { 0x20, 0x55, "LocationOther" },
310 { 0x20, 0x56, "LocationStatic" },
311 { 0x20, 0x57, "LocationTriangulation" },
312 { 0x20, 0x60, "Mechanical" },
313 { 0x20, 0x61, "MechanicalBooleanSwitch" },
314 { 0x20, 0x62, "MechanicalBooleanSwitchArray" },
315 { 0x20, 0x63, "MechanicalMultivalueSwitch" },
316 { 0x20, 0x64, "MechanicalForce" },
317 { 0x20, 0x65, "MechanicalPressure" },
318 { 0x20, 0x66, "MechanicalStrain" },
319 { 0x20, 0x67, "MechanicalWeight" },
320 { 0x20, 0x68, "MechanicalHapticVibrator" },
321 { 0x20, 0x69, "MechanicalHallEffectSwitch" },
322 { 0x20, 0x70, "Motion" },
323 { 0x20, 0x71, "MotionAccelerometer1D" },
324 { 0x20, 0x72, "MotionAccelerometer2D" },
325 { 0x20, 0x73, "MotionAccelerometer3D" },
326 { 0x20, 0x74, "MotionGyrometer1D" },
327 { 0x20, 0x75, "MotionGyrometer2D" },
328 { 0x20, 0x76, "MotionGyrometer3D" },
329 { 0x20, 0x77, "MotionMotionDetector" },
330 { 0x20, 0x78, "MotionSpeedometer" },
331 { 0x20, 0x79, "MotionAccelerometer" },
332 { 0x20, 0x7A, "MotionGyrometer" },
333 { 0x20, 0x80, "Orientation" },
334 { 0x20, 0x81, "OrientationCompass1D" },
335 { 0x20, 0x82, "OrientationCompass2D" },
336 { 0x20, 0x83, "OrientationCompass3D" },
337 { 0x20, 0x84, "OrientationInclinometer1D" },
338 { 0x20, 0x85, "OrientationInclinometer2D" },
339 { 0x20, 0x86, "OrientationInclinometer3D" },
340 { 0x20, 0x87, "OrientationDistance1D" },
341 { 0x20, 0x88, "OrientationDistance2D" },
342 { 0x20, 0x89, "OrientationDistance3D" },
343 { 0x20, 0x8A, "OrientationDeviceOrientation" },
344 { 0x20, 0x8B, "OrientationCompass" },
345 { 0x20, 0x8C, "OrientationInclinometer" },
346 { 0x20, 0x8D, "OrientationDistance" },
347 { 0x20, 0x90, "Scanner" },
348 { 0x20, 0x91, "ScannerBarcode" },
349 { 0x20, 0x91, "ScannerRFID" },
350 { 0x20, 0x91, "ScannerNFC" },
351 { 0x20, 0xA0, "Time" },
352 { 0x20, 0xA1, "TimeAlarmTimer" },
353 { 0x20, 0xA2, "TimeRealTimeClock" },
354 { 0x20, 0xE0, "Other" },
355 { 0x20, 0xE1, "OtherCustom" },
356 { 0x20, 0xE2, "OtherGeneric" },
357 { 0x20, 0xE3, "OtherGenericEnumerator" },
Jiri Kosinac080d892007-01-25 11:43:31 +0100358 { 0x84, 0, "Power Device" },
359 { 0x84, 0x02, "PresentStatus" },
360 { 0x84, 0x03, "ChangeStatus" },
361 { 0x84, 0x04, "UPS" },
362 { 0x84, 0x05, "PowerSupply" },
363 { 0x84, 0x10, "BatterySystem" },
364 { 0x84, 0x11, "BatterySystemID" },
365 { 0x84, 0x12, "Battery" },
366 { 0x84, 0x13, "BatteryID" },
367 { 0x84, 0x14, "Charger" },
368 { 0x84, 0x15, "ChargerID" },
369 { 0x84, 0x16, "PowerConverter" },
370 { 0x84, 0x17, "PowerConverterID" },
371 { 0x84, 0x18, "OutletSystem" },
372 { 0x84, 0x19, "OutletSystemID" },
373 { 0x84, 0x1a, "Input" },
374 { 0x84, 0x1b, "InputID" },
375 { 0x84, 0x1c, "Output" },
376 { 0x84, 0x1d, "OutputID" },
377 { 0x84, 0x1e, "Flow" },
378 { 0x84, 0x1f, "FlowID" },
379 { 0x84, 0x20, "Outlet" },
380 { 0x84, 0x21, "OutletID" },
381 { 0x84, 0x22, "Gang" },
382 { 0x84, 0x24, "PowerSummary" },
383 { 0x84, 0x25, "PowerSummaryID" },
384 { 0x84, 0x30, "Voltage" },
385 { 0x84, 0x31, "Current" },
386 { 0x84, 0x32, "Frequency" },
387 { 0x84, 0x33, "ApparentPower" },
388 { 0x84, 0x35, "PercentLoad" },
389 { 0x84, 0x40, "ConfigVoltage" },
390 { 0x84, 0x41, "ConfigCurrent" },
391 { 0x84, 0x43, "ConfigApparentPower" },
392 { 0x84, 0x53, "LowVoltageTransfer" },
393 { 0x84, 0x54, "HighVoltageTransfer" },
394 { 0x84, 0x56, "DelayBeforeStartup" },
395 { 0x84, 0x57, "DelayBeforeShutdown" },
396 { 0x84, 0x58, "Test" },
397 { 0x84, 0x5a, "AudibleAlarmControl" },
398 { 0x84, 0x60, "Present" },
399 { 0x84, 0x61, "Good" },
400 { 0x84, 0x62, "InternalFailure" },
401 { 0x84, 0x65, "Overload" },
402 { 0x84, 0x66, "OverCharged" },
403 { 0x84, 0x67, "OverTemperature" },
404 { 0x84, 0x68, "ShutdownRequested" },
405 { 0x84, 0x69, "ShutdownImminent" },
406 { 0x84, 0x6b, "SwitchOn/Off" },
407 { 0x84, 0x6c, "Switchable" },
408 { 0x84, 0x6d, "Used" },
409 { 0x84, 0x6e, "Boost" },
410 { 0x84, 0x73, "CommunicationLost" },
411 { 0x84, 0xfd, "iManufacturer" },
412 { 0x84, 0xfe, "iProduct" },
413 { 0x84, 0xff, "iSerialNumber" },
414 { 0x85, 0, "Battery System" },
415 { 0x85, 0x01, "SMBBatteryMode" },
416 { 0x85, 0x02, "SMBBatteryStatus" },
417 { 0x85, 0x03, "SMBAlarmWarning" },
418 { 0x85, 0x04, "SMBChargerMode" },
419 { 0x85, 0x05, "SMBChargerStatus" },
420 { 0x85, 0x06, "SMBChargerSpecInfo" },
421 { 0x85, 0x07, "SMBSelectorState" },
422 { 0x85, 0x08, "SMBSelectorPresets" },
423 { 0x85, 0x09, "SMBSelectorInfo" },
424 { 0x85, 0x29, "RemainingCapacityLimit" },
425 { 0x85, 0x2c, "CapacityMode" },
426 { 0x85, 0x42, "BelowRemainingCapacityLimit" },
427 { 0x85, 0x44, "Charging" },
428 { 0x85, 0x45, "Discharging" },
429 { 0x85, 0x4b, "NeedReplacement" },
430 { 0x85, 0x66, "RemainingCapacity" },
431 { 0x85, 0x68, "RunTimeToEmpty" },
432 { 0x85, 0x6a, "AverageTimeToFull" },
433 { 0x85, 0x83, "DesignCapacity" },
434 { 0x85, 0x85, "ManufacturerDate" },
435 { 0x85, 0x89, "iDeviceChemistry" },
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300436 { 0x85, 0x8b, "Rechargeable" },
Jiri Kosinac080d892007-01-25 11:43:31 +0100437 { 0x85, 0x8f, "iOEMInformation" },
438 { 0x85, 0x8d, "CapacityGranularity1" },
439 { 0x85, 0xd0, "ACPresent" },
440 /* pages 0xff00 to 0xffff are vendor-specific */
441 { 0xffff, 0, "Vendor-specific-FF" },
442 { 0, 0, NULL }
443};
444
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200445/* Either output directly into simple seq_file, or (if f == NULL)
446 * allocate a separate buffer that will then be passed to the 'events'
447 * ringbuffer.
448 *
449 * This is because these functions can be called both for "one-shot"
450 * "rdesc" while resolving, or for blocking "events".
451 *
452 * This holds both for resolv_usage_page() and hid_resolv_usage().
453 */
454static char *resolv_usage_page(unsigned page, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100455 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200456 char *buf = NULL;
457
458 if (!f) {
Vladis Dronov64a9f5f2019-01-29 11:58:35 +0100459 buf = kzalloc(HID_DEBUG_BUFSIZE, GFP_ATOMIC);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200460 if (!buf)
461 return ERR_PTR(-ENOMEM);
462 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100463
464 for (p = hid_usage_table; p->description; p++)
465 if (p->page == page) {
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200466 if (!f) {
467 snprintf(buf, HID_DEBUG_BUFSIZE, "%s",
468 p->description);
469 return buf;
470 }
471 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200472 seq_printf(f, "%s", p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200473 return NULL;
474 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100475 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200476 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200477 snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200478 else
479 seq_printf(f, "%04x", page);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200480 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100481}
482
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200483char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100484 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200485 char *buf = NULL;
486 int len = 0;
Jiri Kosinac080d892007-01-25 11:43:31 +0100487
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200488 buf = resolv_usage_page(usage >> 16, f);
489 if (IS_ERR(buf)) {
Joe Perches4291ee32010-12-09 19:29:03 -0800490 pr_err("error allocating HID debug buffer\n");
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200491 return NULL;
492 }
Jiri Kosina58037eb2007-05-30 15:07:13 +0200493
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200494
495 if (!f) {
496 len = strlen(buf);
497 snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), ".");
498 len++;
499 }
500 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200501 seq_printf(f, ".");
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200502 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100503 for (p = hid_usage_table; p->description; p++)
504 if (p->page == (usage >> 16)) {
505 for(++p; p->description && p->usage != 0; p++)
506 if (p->usage == (usage & 0xffff)) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200507 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200508 snprintf(buf + len,
509 max(0,HID_DEBUG_BUFSIZE - len - 1),
510 "%s", p->description);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200511 else
512 seq_printf(f,
513 "%s",
514 p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200515 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100516 }
517 break;
518 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200519 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200520 snprintf(buf + len, max(0, HID_DEBUG_BUFSIZE - len - 1),
521 "%04x", usage & 0xffff);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200522 else
523 seq_printf(f, "%04x", usage & 0xffff);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200524 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100525}
526EXPORT_SYMBOL_GPL(hid_resolv_usage);
527
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200528static void tab(int n, struct seq_file *f) {
529 seq_printf(f, "%*s", n, "");
Jiri Kosinac080d892007-01-25 11:43:31 +0100530}
531
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200532void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100533 int j;
534
535 if (field->physical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200536 tab(n, f);
537 seq_printf(f, "Physical(");
538 hid_resolv_usage(field->physical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100539 }
540 if (field->logical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200541 tab(n, f);
542 seq_printf(f, "Logical(");
543 hid_resolv_usage(field->logical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100544 }
Jeff Brown54d33392011-08-15 16:39:02 -0700545 if (field->application) {
546 tab(n, f);
547 seq_printf(f, "Application(");
548 hid_resolv_usage(field->application, f); seq_printf(f, ")\n");
549 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200550 tab(n, f); seq_printf(f, "Usage(%d)\n", field->maxusage);
Jiri Kosinac080d892007-01-25 11:43:31 +0100551 for (j = 0; j < field->maxusage; j++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200552 tab(n+2, f); hid_resolv_usage(field->usage[j].hid, f); seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100553 }
554 if (field->logical_minimum != field->logical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200555 tab(n, f); seq_printf(f, "Logical Minimum(%d)\n", field->logical_minimum);
556 tab(n, f); seq_printf(f, "Logical Maximum(%d)\n", field->logical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100557 }
558 if (field->physical_minimum != field->physical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200559 tab(n, f); seq_printf(f, "Physical Minimum(%d)\n", field->physical_minimum);
560 tab(n, f); seq_printf(f, "Physical Maximum(%d)\n", field->physical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100561 }
562 if (field->unit_exponent) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200563 tab(n, f); seq_printf(f, "Unit Exponent(%d)\n", field->unit_exponent);
Jiri Kosinac080d892007-01-25 11:43:31 +0100564 }
565 if (field->unit) {
Joe Perches0ce1ac32007-09-26 16:29:53 +0200566 static const char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
567 static const char *units[5][8] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100568 { "None", "None", "None", "None", "None", "None", "None", "None" },
569 { "None", "Centimeter", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
570 { "None", "Radians", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
571 { "None", "Inch", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" },
572 { "None", "Degrees", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }
573 };
574
575 int i;
576 int sys;
577 __u32 data = field->unit;
578
579 /* First nibble tells us which system we're in. */
580 sys = data & 0xf;
581 data >>= 4;
582
583 if(sys > 4) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200584 tab(n, f); seq_printf(f, "Unit(Invalid)\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100585 }
586 else {
587 int earlier_unit = 0;
588
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200589 tab(n, f); seq_printf(f, "Unit(%s : ", systems[sys]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100590
591 for (i=1 ; i<sizeof(__u32)*2 ; i++) {
592 char nibble = data & 0xf;
593 data >>= 4;
594 if (nibble != 0) {
595 if(earlier_unit++ > 0)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200596 seq_printf(f, "*");
597 seq_printf(f, "%s", units[sys][i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100598 if(nibble != 1) {
599 /* This is a _signed_ nibble(!) */
600
601 int val = nibble & 0x7;
602 if(nibble & 0x08)
603 val = -((0x7 & ~val) +1);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200604 seq_printf(f, "^%d", val);
Jiri Kosinac080d892007-01-25 11:43:31 +0100605 }
606 }
607 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200608 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100609 }
610 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200611 tab(n, f); seq_printf(f, "Report Size(%u)\n", field->report_size);
612 tab(n, f); seq_printf(f, "Report Count(%u)\n", field->report_count);
613 tab(n, f); seq_printf(f, "Report Offset(%u)\n", field->report_offset);
Jiri Kosinac080d892007-01-25 11:43:31 +0100614
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200615 tab(n, f); seq_printf(f, "Flags( ");
Jiri Kosinac080d892007-01-25 11:43:31 +0100616 j = field->flags;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200617 seq_printf(f, "%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
618 seq_printf(f, "%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
619 seq_printf(f, "%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
620 seq_printf(f, "%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
621 seq_printf(f, "%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
622 seq_printf(f, "%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPreferredState " : "");
623 seq_printf(f, "%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
624 seq_printf(f, "%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
625 seq_printf(f, "%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
626 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100627}
628EXPORT_SYMBOL_GPL(hid_dump_field);
629
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200630void hid_dump_device(struct hid_device *device, struct seq_file *f)
631{
Jiri Kosinac080d892007-01-25 11:43:31 +0100632 struct hid_report_enum *report_enum;
633 struct hid_report *report;
634 struct list_head *list;
635 unsigned i,k;
Joe Perches0ce1ac32007-09-26 16:29:53 +0200636 static const char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
Jiri Kosinac080d892007-01-25 11:43:31 +0100637
638 for (i = 0; i < HID_REPORT_TYPES; i++) {
639 report_enum = device->report_enum + i;
640 list = report_enum->report_list.next;
641 while (list != &report_enum->report_list) {
642 report = (struct hid_report *) list;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200643 tab(2, f);
644 seq_printf(f, "%s", table[i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100645 if (report->id)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200646 seq_printf(f, "(%d)", report->id);
647 seq_printf(f, "[%s]", table[report->type]);
648 seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100649 for (k = 0; k < report->maxfield; k++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200650 tab(4, f);
651 seq_printf(f, "Field(%d)\n", k);
652 hid_dump_field(report->field[k], 6, f);
Jiri Kosinac080d892007-01-25 11:43:31 +0100653 }
654 list = list->next;
655 }
656 }
657}
658EXPORT_SYMBOL_GPL(hid_dump_device);
659
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200660/* enqueue string to 'events' ring buffer */
661void hid_debug_event(struct hid_device *hdev, char *buf)
662{
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200663 struct hid_debug_list *list;
Jiri Kosina1deb9d32013-05-06 13:05:50 +0200664 unsigned long flags;
Jiri Kosina58037eb2007-05-30 15:07:13 +0200665
Jiri Kosina1deb9d32013-05-06 13:05:50 +0200666 spin_lock_irqsave(&hdev->debug_list_lock, flags);
Vladis Dronov64a9f5f2019-01-29 11:58:35 +0100667 list_for_each_entry(list, &hdev->debug_list, node)
668 kfifo_in(&list->hid_debug_fifo, buf, strlen(buf));
Jiri Kosina1deb9d32013-05-06 13:05:50 +0200669 spin_unlock_irqrestore(&hdev->debug_list_lock, flags);
Chase Douglas1debfb32010-08-30 13:27:45 -0400670
671 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200672}
673EXPORT_SYMBOL_GPL(hid_debug_event);
674
Benjamin Tissoiresa5f04b92013-04-17 19:38:13 +0200675void hid_dump_report(struct hid_device *hid, int type, u8 *data,
676 int size)
677{
678 struct hid_report_enum *report_enum;
679 char *buf;
680 unsigned int i;
681
682 buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
683
684 if (!buf)
685 return;
686
687 report_enum = hid->report_enum + type;
688
689 /* dump the report */
690 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
691 "\nreport (size %u) (%snumbered) = ", size,
692 report_enum->numbered ? "" : "un");
693 hid_debug_event(hid, buf);
694
695 for (i = 0; i < size; i++) {
696 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
697 " %02x", data[i]);
698 hid_debug_event(hid, buf);
699 }
700 hid_debug_event(hid, "\n");
701 kfree(buf);
702}
703EXPORT_SYMBOL_GPL(hid_dump_report);
704
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200705void hid_dump_input(struct hid_device *hdev, struct hid_usage *usage, __s32 value)
706{
707 char *buf;
708 int len;
709
710 buf = hid_resolv_usage(usage->hid, NULL);
711 if (!buf)
712 return;
713 len = strlen(buf);
714 snprintf(buf + len, HID_DEBUG_BUFSIZE - len - 1, " = %d\n", value);
715
716 hid_debug_event(hdev, buf);
717
718 kfree(buf);
Vladis Dronov64a9f5f2019-01-29 11:58:35 +0100719 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinac080d892007-01-25 11:43:31 +0100720}
721EXPORT_SYMBOL_GPL(hid_dump_input);
722
Joe Perches0ce1ac32007-09-26 16:29:53 +0200723static const char *events[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100724 [EV_SYN] = "Sync", [EV_KEY] = "Key",
725 [EV_REL] = "Relative", [EV_ABS] = "Absolute",
726 [EV_MSC] = "Misc", [EV_LED] = "LED",
727 [EV_SND] = "Sound", [EV_REP] = "Repeat",
728 [EV_FF] = "ForceFeedback", [EV_PWR] = "Power",
729 [EV_FF_STATUS] = "ForceFeedbackStatus",
730};
731
Stephane Chatty89f536c2009-05-20 15:41:24 +0200732static const char *syncs[3] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100733 [SYN_REPORT] = "Report", [SYN_CONFIG] = "Config",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200734 [SYN_MT_REPORT] = "MT Report",
Jiri Kosinac080d892007-01-25 11:43:31 +0100735};
Stephane Chatty89f536c2009-05-20 15:41:24 +0200736
Joe Perches0ce1ac32007-09-26 16:29:53 +0200737static const char *keys[KEY_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100738 [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc",
739 [KEY_1] = "1", [KEY_2] = "2",
740 [KEY_3] = "3", [KEY_4] = "4",
741 [KEY_5] = "5", [KEY_6] = "6",
742 [KEY_7] = "7", [KEY_8] = "8",
743 [KEY_9] = "9", [KEY_0] = "0",
744 [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal",
745 [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab",
746 [KEY_Q] = "Q", [KEY_W] = "W",
747 [KEY_E] = "E", [KEY_R] = "R",
748 [KEY_T] = "T", [KEY_Y] = "Y",
749 [KEY_U] = "U", [KEY_I] = "I",
750 [KEY_O] = "O", [KEY_P] = "P",
751 [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace",
752 [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl",
753 [KEY_A] = "A", [KEY_S] = "S",
754 [KEY_D] = "D", [KEY_F] = "F",
755 [KEY_G] = "G", [KEY_H] = "H",
756 [KEY_J] = "J", [KEY_K] = "K",
757 [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon",
758 [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave",
759 [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash",
760 [KEY_Z] = "Z", [KEY_X] = "X",
761 [KEY_C] = "C", [KEY_V] = "V",
762 [KEY_B] = "B", [KEY_N] = "N",
763 [KEY_M] = "M", [KEY_COMMA] = "Comma",
764 [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash",
765 [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk",
766 [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space",
767 [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1",
768 [KEY_F2] = "F2", [KEY_F3] = "F3",
769 [KEY_F4] = "F4", [KEY_F5] = "F5",
770 [KEY_F6] = "F6", [KEY_F7] = "F7",
771 [KEY_F8] = "F8", [KEY_F9] = "F9",
772 [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock",
773 [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7",
774 [KEY_KP8] = "KP8", [KEY_KP9] = "KP9",
775 [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4",
776 [KEY_KP5] = "KP5", [KEY_KP6] = "KP6",
777 [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1",
778 [KEY_KP2] = "KP2", [KEY_KP3] = "KP3",
779 [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot",
780 [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd",
781 [KEY_F11] = "F11", [KEY_F12] = "F12",
782 [KEY_RO] = "RO", [KEY_KATAKANA] = "Katakana",
783 [KEY_HIRAGANA] = "HIRAGANA", [KEY_HENKAN] = "Henkan",
784 [KEY_KATAKANAHIRAGANA] = "Katakana/Hiragana", [KEY_MUHENKAN] = "Muhenkan",
785 [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter",
786 [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash",
787 [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt",
788 [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home",
789 [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp",
790 [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right",
791 [KEY_END] = "End", [KEY_DOWN] = "Down",
792 [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert",
793 [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro",
794 [KEY_MUTE] = "Mute", [KEY_VOLUMEDOWN] = "VolumeDown",
795 [KEY_VOLUMEUP] = "VolumeUp", [KEY_POWER] = "Power",
796 [KEY_KPEQUAL] = "KPEqual", [KEY_KPPLUSMINUS] = "KPPlusMinus",
797 [KEY_PAUSE] = "Pause", [KEY_KPCOMMA] = "KPComma",
798 [KEY_HANGUEL] = "Hangeul", [KEY_HANJA] = "Hanja",
799 [KEY_YEN] = "Yen", [KEY_LEFTMETA] = "LeftMeta",
800 [KEY_RIGHTMETA] = "RightMeta", [KEY_COMPOSE] = "Compose",
801 [KEY_STOP] = "Stop", [KEY_AGAIN] = "Again",
802 [KEY_PROPS] = "Props", [KEY_UNDO] = "Undo",
803 [KEY_FRONT] = "Front", [KEY_COPY] = "Copy",
804 [KEY_OPEN] = "Open", [KEY_PASTE] = "Paste",
805 [KEY_FIND] = "Find", [KEY_CUT] = "Cut",
806 [KEY_HELP] = "Help", [KEY_MENU] = "Menu",
807 [KEY_CALC] = "Calc", [KEY_SETUP] = "Setup",
808 [KEY_SLEEP] = "Sleep", [KEY_WAKEUP] = "WakeUp",
809 [KEY_FILE] = "File", [KEY_SENDFILE] = "SendFile",
810 [KEY_DELETEFILE] = "DeleteFile", [KEY_XFER] = "X-fer",
811 [KEY_PROG1] = "Prog1", [KEY_PROG2] = "Prog2",
812 [KEY_WWW] = "WWW", [KEY_MSDOS] = "MSDOS",
Stefan Brünse92865e2015-03-05 23:25:51 -0800813 [KEY_COFFEE] = "Coffee", [KEY_ROTATE_DISPLAY] = "RotateDisplay",
Jiri Kosinac080d892007-01-25 11:43:31 +0100814 [KEY_CYCLEWINDOWS] = "CycleWindows", [KEY_MAIL] = "Mail",
815 [KEY_BOOKMARKS] = "Bookmarks", [KEY_COMPUTER] = "Computer",
816 [KEY_BACK] = "Back", [KEY_FORWARD] = "Forward",
817 [KEY_CLOSECD] = "CloseCD", [KEY_EJECTCD] = "EjectCD",
818 [KEY_EJECTCLOSECD] = "EjectCloseCD", [KEY_NEXTSONG] = "NextSong",
819 [KEY_PLAYPAUSE] = "PlayPause", [KEY_PREVIOUSSONG] = "PreviousSong",
820 [KEY_STOPCD] = "StopCD", [KEY_RECORD] = "Record",
821 [KEY_REWIND] = "Rewind", [KEY_PHONE] = "Phone",
822 [KEY_ISO] = "ISOKey", [KEY_CONFIG] = "Config",
823 [KEY_HOMEPAGE] = "HomePage", [KEY_REFRESH] = "Refresh",
824 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
825 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
826 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
827 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
828 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
829 [KEY_F14] = "F14", [KEY_F15] = "F15",
830 [KEY_F16] = "F16", [KEY_F17] = "F17",
831 [KEY_F18] = "F18", [KEY_F19] = "F19",
832 [KEY_F20] = "F20", [KEY_F21] = "F21",
833 [KEY_F22] = "F22", [KEY_F23] = "F23",
834 [KEY_F24] = "F24", [KEY_PLAYCD] = "PlayCD",
835 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
836 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend",
837 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
838 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
839 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
840 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
841 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
842 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
843 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
844 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
845 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
846 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
847 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
Antonio Ospitea4432552013-12-17 12:52:48 +0100848 [BTN_DPAD_UP] = "BtnDPadUp", [BTN_DPAD_DOWN] = "BtnDPadDown",
849 [BTN_DPAD_LEFT] = "BtnDPadLeft", [BTN_DPAD_RIGHT] = "BtnDPadRight",
Jiri Kosinac080d892007-01-25 11:43:31 +0100850 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
851 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
852 [BTN_4] = "Btn4", [BTN_5] = "Btn5",
853 [BTN_6] = "Btn6", [BTN_7] = "Btn7",
854 [BTN_8] = "Btn8", [BTN_9] = "Btn9",
855 [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn",
856 [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn",
857 [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn",
858 [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn",
859 [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn",
860 [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn",
861 [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn",
862 [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2",
863 [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4",
864 [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6",
865 [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA",
866 [BTN_B] = "BtnB", [BTN_C] = "BtnC",
867 [BTN_X] = "BtnX", [BTN_Y] = "BtnY",
868 [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL",
869 [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2",
870 [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect",
871 [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode",
872 [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR",
873 [BTN_TOOL_PEN] = "ToolPen", [BTN_TOOL_RUBBER] = "ToolRubber",
874 [BTN_TOOL_BRUSH] = "ToolBrush", [BTN_TOOL_PENCIL] = "ToolPencil",
875 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
876 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
877 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
878 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
Antonio Ospitea4432552013-12-17 12:52:48 +0100879 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_TOOL_QUADTAP] = "ToolQuadrupleTap",
880 [BTN_GEAR_DOWN] = "WheelBtn",
Jiri Kosinac080d892007-01-25 11:43:31 +0100881 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
882 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
883 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
884 [KEY_OPTION] = "Option", [KEY_INFO] = "Info",
885 [KEY_TIME] = "Time", [KEY_VENDOR] = "Vendor",
886 [KEY_ARCHIVE] = "Archive", [KEY_PROGRAM] = "Program",
887 [KEY_CHANNEL] = "Channel", [KEY_FAVORITES] = "Favorites",
888 [KEY_EPG] = "EPG", [KEY_PVR] = "PVR",
889 [KEY_MHP] = "MHP", [KEY_LANGUAGE] = "Language",
890 [KEY_TITLE] = "Title", [KEY_SUBTITLE] = "Subtitle",
891 [KEY_ANGLE] = "Angle", [KEY_ZOOM] = "Zoom",
892 [KEY_MODE] = "Mode", [KEY_KEYBOARD] = "Keyboard",
893 [KEY_SCREEN] = "Screen", [KEY_PC] = "PC",
894 [KEY_TV] = "TV", [KEY_TV2] = "TV2",
895 [KEY_VCR] = "VCR", [KEY_VCR2] = "VCR2",
896 [KEY_SAT] = "Sat", [KEY_SAT2] = "Sat2",
897 [KEY_CD] = "CD", [KEY_TAPE] = "Tape",
898 [KEY_RADIO] = "Radio", [KEY_TUNER] = "Tuner",
899 [KEY_PLAYER] = "Player", [KEY_TEXT] = "Text",
900 [KEY_DVD] = "DVD", [KEY_AUX] = "Aux",
901 [KEY_MP3] = "MP3", [KEY_AUDIO] = "Audio",
902 [KEY_VIDEO] = "Video", [KEY_DIRECTORY] = "Directory",
903 [KEY_LIST] = "List", [KEY_MEMO] = "Memo",
904 [KEY_CALENDAR] = "Calendar", [KEY_RED] = "Red",
905 [KEY_GREEN] = "Green", [KEY_YELLOW] = "Yellow",
906 [KEY_BLUE] = "Blue", [KEY_CHANNELUP] = "ChannelUp",
907 [KEY_CHANNELDOWN] = "ChannelDown", [KEY_FIRST] = "First",
908 [KEY_LAST] = "Last", [KEY_AB] = "AB",
909 [KEY_NEXT] = "Next", [KEY_RESTART] = "Restart",
910 [KEY_SLOW] = "Slow", [KEY_SHUFFLE] = "Shuffle",
911 [KEY_BREAK] = "Break", [KEY_PREVIOUS] = "Previous",
912 [KEY_DIGITS] = "Digits", [KEY_TEEN] = "TEEN",
913 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
914 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
915 [KEY_DEL_LINE] = "DeleteLine",
916 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
917 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
Jiri Kosina1fe8736d2007-08-09 13:24:11 +0200918 [KEY_DOCUMENTS] = "Documents", [KEY_SPELLCHECK] = "SpellCheck",
Khelben Blackstaffe2bca072007-10-04 10:32:03 +0200919 [KEY_LOGOFF] = "Logoff",
Jiri Kosinac080d892007-01-25 11:43:31 +0100920 [KEY_FN] = "Fn", [KEY_FN_ESC] = "Fn+ESC",
921 [KEY_FN_1] = "Fn+1", [KEY_FN_2] = "Fn+2",
922 [KEY_FN_B] = "Fn+B", [KEY_FN_D] = "Fn+D",
923 [KEY_FN_E] = "Fn+E", [KEY_FN_F] = "Fn+F",
924 [KEY_FN_S] = "Fn+S",
925 [KEY_FN_F1] = "Fn+F1", [KEY_FN_F2] = "Fn+F2",
926 [KEY_FN_F3] = "Fn+F3", [KEY_FN_F4] = "Fn+F4",
927 [KEY_FN_F5] = "Fn+F5", [KEY_FN_F6] = "Fn+F6",
928 [KEY_FN_F7] = "Fn+F7", [KEY_FN_F8] = "Fn+F8",
929 [KEY_FN_F9] = "Fn+F9", [KEY_FN_F10] = "Fn+F10",
930 [KEY_FN_F11] = "Fn+F11", [KEY_FN_F12] = "Fn+F12",
931 [KEY_KBDILLUMTOGGLE] = "KbdIlluminationToggle",
932 [KEY_KBDILLUMDOWN] = "KbdIlluminationDown",
933 [KEY_KBDILLUMUP] = "KbdIlluminationUp",
934 [KEY_SWITCHVIDEOMODE] = "SwitchVideoMode",
Olivier Gayf362e692014-04-25 20:26:44 +0200935 [KEY_BUTTONCONFIG] = "ButtonConfig",
936 [KEY_TASKMANAGER] = "TaskManager",
937 [KEY_JOURNAL] = "Journal",
938 [KEY_CONTROLPANEL] = "ControlPanel",
939 [KEY_APPSELECT] = "AppSelect",
940 [KEY_SCREENSAVER] = "ScreenSaver",
941 [KEY_VOICECOMMAND] = "VoiceCommand",
942 [KEY_BRIGHTNESS_MIN] = "BrightnessMin",
943 [KEY_BRIGHTNESS_MAX] = "BrightnessMax",
944 [KEY_BRIGHTNESS_AUTO] = "BrightnessAuto",
Olivier Gayf9740082014-10-18 01:53:39 +0200945 [KEY_KBDINPUTASSIST_PREV] = "KbdInputAssistPrev",
946 [KEY_KBDINPUTASSIST_NEXT] = "KbdInputAssistNext",
947 [KEY_KBDINPUTASSIST_PREVGROUP] = "KbdInputAssistPrevGroup",
948 [KEY_KBDINPUTASSIST_NEXTGROUP] = "KbdInputAssistNextGroup",
949 [KEY_KBDINPUTASSIST_ACCEPT] = "KbdInputAssistAccept",
950 [KEY_KBDINPUTASSIST_CANCEL] = "KbdInputAssistCancel",
Jiri Kosinac080d892007-01-25 11:43:31 +0100951};
952
Joe Perches0ce1ac32007-09-26 16:29:53 +0200953static const char *relatives[REL_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100954 [REL_X] = "X", [REL_Y] = "Y",
955 [REL_Z] = "Z", [REL_RX] = "Rx",
956 [REL_RY] = "Ry", [REL_RZ] = "Rz",
957 [REL_HWHEEL] = "HWheel", [REL_DIAL] = "Dial",
958 [REL_WHEEL] = "Wheel", [REL_MISC] = "Misc",
959};
960
Daniel Mack81c2a3b2010-05-20 22:52:58 -0700961static const char *absolutes[ABS_CNT] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100962 [ABS_X] = "X", [ABS_Y] = "Y",
963 [ABS_Z] = "Z", [ABS_RX] = "Rx",
964 [ABS_RY] = "Ry", [ABS_RZ] = "Rz",
965 [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder",
966 [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas",
967 [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X",
968 [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X",
969 [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X",
970 [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X",
971 [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure",
972 [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200973 [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth",
Jiri Kosinac080d892007-01-25 11:43:31 +0100974 [ABS_VOLUME] = "Volume", [ABS_MISC] = "Misc",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200975 [ABS_MT_TOUCH_MAJOR] = "MTMajor",
976 [ABS_MT_TOUCH_MINOR] = "MTMinor",
977 [ABS_MT_WIDTH_MAJOR] = "MTMajorW",
978 [ABS_MT_WIDTH_MINOR] = "MTMinorW",
979 [ABS_MT_ORIENTATION] = "MTOrientation",
980 [ABS_MT_POSITION_X] = "MTPositionX",
981 [ABS_MT_POSITION_Y] = "MTPositionY",
982 [ABS_MT_TOOL_TYPE] = "MTToolType",
983 [ABS_MT_BLOB_ID] = "MTBlobID",
Jiri Kosinac080d892007-01-25 11:43:31 +0100984};
985
Joe Perches0ce1ac32007-09-26 16:29:53 +0200986static const char *misc[MSC_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100987 [MSC_SERIAL] = "Serial", [MSC_PULSELED] = "Pulseled",
988 [MSC_GESTURE] = "Gesture", [MSC_RAW] = "RawData"
989};
990
Joe Perches0ce1ac32007-09-26 16:29:53 +0200991static const char *leds[LED_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100992 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
993 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
994 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
995 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
996 [LED_MISC] = "Misc",
997};
998
Joe Perches0ce1ac32007-09-26 16:29:53 +0200999static const char *repeats[REP_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +01001000 [REP_DELAY] = "Delay", [REP_PERIOD] = "Period"
1001};
1002
Joe Perches0ce1ac32007-09-26 16:29:53 +02001003static const char *sounds[SND_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +01001004 [SND_CLICK] = "Click", [SND_BELL] = "Bell",
1005 [SND_TONE] = "Tone"
1006};
1007
Joe Perches0ce1ac32007-09-26 16:29:53 +02001008static const char **names[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +01001009 [EV_SYN] = syncs, [EV_KEY] = keys,
1010 [EV_REL] = relatives, [EV_ABS] = absolutes,
1011 [EV_MSC] = misc, [EV_LED] = leds,
1012 [EV_SND] = sounds, [EV_REP] = repeats,
1013};
1014
H Hartley Sweeten62e62da2010-01-14 19:10:07 -07001015static void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f)
1016{
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001017 seq_printf(f, "%s.%s", events[type] ? events[type] : "?",
Jiri Kosinac080d892007-01-25 11:43:31 +01001018 names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
1019}
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001020
H Hartley Sweeten62e62da2010-01-14 19:10:07 -07001021static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001022{
1023 int i, j, k;
1024 struct hid_report *report;
1025 struct hid_usage *usage;
1026
1027 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
1028 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
1029 for (i = 0; i < report->maxfield; i++) {
1030 for ( j = 0; j < report->field[i]->maxusage; j++) {
1031 usage = report->field[i]->usage + j;
1032 hid_resolv_usage(usage->hid, f);
1033 seq_printf(f, " ---> ");
1034 hid_resolv_event(usage->type, usage->code, f);
1035 seq_printf(f, "\n");
1036 }
1037 }
1038 }
1039 }
1040
1041}
1042
1043static int hid_debug_rdesc_show(struct seq_file *f, void *p)
1044{
1045 struct hid_device *hdev = f->private;
Henrik Rydberg8db089d2012-08-21 20:22:44 +02001046 const __u8 *rdesc = hdev->rdesc;
1047 unsigned rsize = hdev->rsize;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001048 int i;
1049
Henrik Rydberg8db089d2012-08-21 20:22:44 +02001050 if (!rdesc) {
1051 rdesc = hdev->dev_rdesc;
1052 rsize = hdev->dev_rsize;
1053 }
1054
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001055 /* dump HID report descriptor */
Henrik Rydberg8db089d2012-08-21 20:22:44 +02001056 for (i = 0; i < rsize; i++)
1057 seq_printf(f, "%02x ", rdesc[i]);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001058 seq_printf(f, "\n\n");
1059
1060 /* dump parsed data and input mappings */
He, Boee3d9ab2019-03-14 02:28:21 +00001061 if (down_interruptible(&hdev->driver_input_lock))
1062 return 0;
1063
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001064 hid_dump_device(hdev, f);
1065 seq_printf(f, "\n");
1066 hid_dump_input_mapping(hdev, f);
1067
He, Boee3d9ab2019-03-14 02:28:21 +00001068 up(&hdev->driver_input_lock);
1069
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001070 return 0;
1071}
1072
1073static int hid_debug_rdesc_open(struct inode *inode, struct file *file)
1074{
1075 return single_open(file, hid_debug_rdesc_show, inode->i_private);
1076}
1077
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001078static int hid_debug_events_open(struct inode *inode, struct file *file)
1079{
1080 int err = 0;
1081 struct hid_debug_list *list;
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001082 unsigned long flags;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001083
1084 if (!(list = kzalloc(sizeof(struct hid_debug_list), GFP_KERNEL))) {
1085 err = -ENOMEM;
1086 goto out;
1087 }
1088
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001089 err = kfifo_alloc(&list->hid_debug_fifo, HID_DEBUG_FIFOSIZE, GFP_KERNEL);
1090 if (err) {
Julia Lawalla809dda2009-08-08 02:26:10 +02001091 kfree(list);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001092 goto out;
1093 }
1094 list->hdev = (struct hid_device *) inode->i_private;
1095 file->private_data = list;
1096 mutex_init(&list->read_mutex);
1097
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001098 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001099 list_add_tail(&list->node, &list->hdev->debug_list);
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001100 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001101
1102out:
1103 return err;
1104}
1105
1106static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
1107 size_t count, loff_t *ppos)
1108{
1109 struct hid_debug_list *list = file->private_data;
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001110 int ret = 0, copied;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001111 DECLARE_WAITQUEUE(wait, current);
1112
Julia Lawallca9fe152010-06-20 13:24:35 +02001113 mutex_lock(&list->read_mutex);
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001114 if (kfifo_is_empty(&list->hid_debug_fifo)) {
1115 add_wait_queue(&list->hdev->debug_wait, &wait);
1116 set_current_state(TASK_INTERRUPTIBLE);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001117
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001118 while (kfifo_is_empty(&list->hid_debug_fifo)) {
1119 if (file->f_flags & O_NONBLOCK) {
1120 ret = -EAGAIN;
1121 break;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001122 }
1123
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001124 if (signal_pending(current)) {
1125 ret = -ERESTARTSYS;
1126 break;
1127 }
1128
1129 /* if list->hdev is NULL we cannot remove_wait_queue().
1130 * if list->hdev->debug is 0 then hid_debug_unregister()
1131 * was already called and list->hdev is being destroyed.
1132 * if we add remove_wait_queue() here we can hit a race.
1133 */
1134 if (!list->hdev || !list->hdev->debug) {
1135 ret = -EIO;
1136 set_current_state(TASK_RUNNING);
1137 goto out;
1138 }
1139
1140 /* allow O_NONBLOCK from other threads */
1141 mutex_unlock(&list->read_mutex);
1142 schedule();
1143 mutex_lock(&list->read_mutex);
1144 set_current_state(TASK_INTERRUPTIBLE);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001145 }
1146
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001147 __set_current_state(TASK_RUNNING);
1148 remove_wait_queue(&list->hdev->debug_wait, &wait);
1149
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001150 if (ret)
1151 goto out;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001152 }
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001153
1154 /* pass the fifo content to userspace, locking is not needed with only
1155 * one concurrent reader and one concurrent writer
1156 */
1157 ret = kfifo_to_user(&list->hid_debug_fifo, buffer, count, &copied);
1158 if (ret)
1159 goto out;
1160 ret = copied;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001161out:
1162 mutex_unlock(&list->read_mutex);
1163 return ret;
1164}
1165
1166static unsigned int hid_debug_events_poll(struct file *file, poll_table *wait)
1167{
1168 struct hid_debug_list *list = file->private_data;
1169
1170 poll_wait(file, &list->hdev->debug_wait, wait);
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001171 if (!kfifo_is_empty(&list->hid_debug_fifo))
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001172 return POLLIN | POLLRDNORM;
1173 if (!list->hdev->debug)
1174 return POLLERR | POLLHUP;
1175 return 0;
1176}
1177
1178static int hid_debug_events_release(struct inode *inode, struct file *file)
1179{
1180 struct hid_debug_list *list = file->private_data;
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001181 unsigned long flags;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001182
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001183 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001184 list_del(&list->node);
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001185 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
Vladis Dronov64a9f5f2019-01-29 11:58:35 +01001186 kfifo_free(&list->hid_debug_fifo);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001187 kfree(list);
1188
1189 return 0;
1190}
1191
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001192static const struct file_operations hid_debug_rdesc_fops = {
1193 .open = hid_debug_rdesc_open,
1194 .read = seq_read,
1195 .llseek = seq_lseek,
1196 .release = single_release,
1197};
1198
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001199static const struct file_operations hid_debug_events_fops = {
1200 .owner = THIS_MODULE,
1201 .open = hid_debug_events_open,
1202 .read = hid_debug_events_read,
1203 .poll = hid_debug_events_poll,
1204 .release = hid_debug_events_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001205 .llseek = noop_llseek,
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001206};
1207
1208
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001209void hid_debug_register(struct hid_device *hdev, const char *name)
1210{
1211 hdev->debug_dir = debugfs_create_dir(name, hid_debug_root);
1212 hdev->debug_rdesc = debugfs_create_file("rdesc", 0400,
1213 hdev->debug_dir, hdev, &hid_debug_rdesc_fops);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001214 hdev->debug_events = debugfs_create_file("events", 0400,
1215 hdev->debug_dir, hdev, &hid_debug_events_fops);
1216 hdev->debug = 1;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001217}
1218
1219void hid_debug_unregister(struct hid_device *hdev)
1220{
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001221 hdev->debug = 0;
1222 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001223 debugfs_remove(hdev->debug_rdesc);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001224 debugfs_remove(hdev->debug_events);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001225 debugfs_remove(hdev->debug_dir);
1226}
1227
1228void hid_debug_init(void)
1229{
1230 hid_debug_root = debugfs_create_dir("hid", NULL);
1231}
1232
1233void hid_debug_exit(void)
1234{
1235 debugfs_remove_recursive(hid_debug_root);
1236}