blob: 5271db5934783aad57402503e74bcd1a504da187 [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>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010033#include <linux/sched/signal.h>
Paul Gortmakerec37d322011-05-27 10:25:27 -040034#include <linux/export.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Jiri Kosinacd667ce2009-06-12 15:20:57 +020036#include <linux/uaccess.h>
37#include <linux/poll.h>
38
Jiri Kosinac080d892007-01-25 11:43:31 +010039#include <linux/hid.h>
Adrian Bunk4330eb22007-02-21 12:57:30 +010040#include <linux/hid-debug.h>
Jiri Kosinac080d892007-01-25 11:43:31 +010041
Jiri Kosinaa635f9d2009-06-12 15:20:55 +020042static struct dentry *hid_debug_root;
43
Jiri Kosinac080d892007-01-25 11:43:31 +010044struct hid_usage_entry {
45 unsigned page;
46 unsigned usage;
Joe Perches0ce1ac32007-09-26 16:29:53 +020047 const char *description;
Jiri Kosinac080d892007-01-25 11:43:31 +010048};
49
50static const struct hid_usage_entry hid_usage_table[] = {
51 { 0, 0, "Undefined" },
52 { 1, 0, "GenericDesktop" },
53 {0, 0x01, "Pointer"},
54 {0, 0x02, "Mouse"},
55 {0, 0x04, "Joystick"},
56 {0, 0x05, "GamePad"},
57 {0, 0x06, "Keyboard"},
58 {0, 0x07, "Keypad"},
59 {0, 0x08, "MultiAxis"},
60 {0, 0x30, "X"},
61 {0, 0x31, "Y"},
62 {0, 0x32, "Z"},
63 {0, 0x33, "Rx"},
64 {0, 0x34, "Ry"},
65 {0, 0x35, "Rz"},
66 {0, 0x36, "Slider"},
67 {0, 0x37, "Dial"},
68 {0, 0x38, "Wheel"},
69 {0, 0x39, "HatSwitch"},
70 {0, 0x3a, "CountedBuffer"},
71 {0, 0x3b, "ByteCount"},
72 {0, 0x3c, "MotionWakeup"},
73 {0, 0x3d, "Start"},
74 {0, 0x3e, "Select"},
75 {0, 0x40, "Vx"},
76 {0, 0x41, "Vy"},
77 {0, 0x42, "Vz"},
78 {0, 0x43, "Vbrx"},
79 {0, 0x44, "Vbry"},
80 {0, 0x45, "Vbrz"},
81 {0, 0x46, "Vno"},
82 {0, 0x80, "SystemControl"},
83 {0, 0x81, "SystemPowerDown"},
84 {0, 0x82, "SystemSleep"},
85 {0, 0x83, "SystemWakeUp"},
86 {0, 0x84, "SystemContextMenu"},
87 {0, 0x85, "SystemMainMenu"},
88 {0, 0x86, "SystemAppMenu"},
89 {0, 0x87, "SystemMenuHelp"},
90 {0, 0x88, "SystemMenuExit"},
91 {0, 0x89, "SystemMenuSelect"},
92 {0, 0x8a, "SystemMenuRight"},
93 {0, 0x8b, "SystemMenuLeft"},
94 {0, 0x8c, "SystemMenuUp"},
95 {0, 0x8d, "SystemMenuDown"},
96 {0, 0x90, "D-PadUp"},
97 {0, 0x91, "D-PadDown"},
98 {0, 0x92, "D-PadRight"},
99 {0, 0x93, "D-PadLeft"},
100 { 2, 0, "Simulation" },
101 {0, 0xb0, "Aileron"},
102 {0, 0xb1, "AileronTrim"},
103 {0, 0xb2, "Anti-Torque"},
104 {0, 0xb3, "Autopilot"},
105 {0, 0xb4, "Chaff"},
106 {0, 0xb5, "Collective"},
107 {0, 0xb6, "DiveBrake"},
108 {0, 0xb7, "ElectronicCountermeasures"},
109 {0, 0xb8, "Elevator"},
110 {0, 0xb9, "ElevatorTrim"},
111 {0, 0xba, "Rudder"},
112 {0, 0xbb, "Throttle"},
113 {0, 0xbc, "FlightCommunications"},
114 {0, 0xbd, "FlareRelease"},
115 {0, 0xbe, "LandingGear"},
116 {0, 0xbf, "ToeBrake"},
Jeremy Fitzhardinge1f591692011-11-19 12:19:00 +0100117 { 6, 0, "GenericDeviceControls" },
118 {0, 0x20, "BatteryStrength" },
119 {0, 0x21, "WirelessChannel" },
120 {0, 0x22, "WirelessID" },
121 {0, 0x23, "DiscoverWirelessControl" },
122 {0, 0x24, "SecurityCodeCharacterEntered" },
123 {0, 0x25, "SecurityCodeCharactedErased" },
124 {0, 0x26, "SecurityCodeCleared" },
Jiri Kosinac080d892007-01-25 11:43:31 +0100125 { 7, 0, "Keyboard" },
126 { 8, 0, "LED" },
127 {0, 0x01, "NumLock"},
128 {0, 0x02, "CapsLock"},
129 {0, 0x03, "ScrollLock"},
130 {0, 0x04, "Compose"},
131 {0, 0x05, "Kana"},
132 {0, 0x4b, "GenericIndicator"},
133 { 9, 0, "Button" },
134 { 10, 0, "Ordinal" },
135 { 12, 0, "Consumer" },
136 {0, 0x238, "HorizontalWheel"},
137 { 13, 0, "Digitizers" },
138 {0, 0x01, "Digitizer"},
139 {0, 0x02, "Pen"},
140 {0, 0x03, "LightPen"},
141 {0, 0x04, "TouchScreen"},
142 {0, 0x05, "TouchPad"},
Xiaolei Yu959d9732017-03-25 14:04:58 +0800143 {0, 0x0e, "DeviceConfiguration"},
Jiri Kosinac080d892007-01-25 11:43:31 +0100144 {0, 0x20, "Stylus"},
145 {0, 0x21, "Puck"},
146 {0, 0x22, "Finger"},
Xiaolei Yu959d9732017-03-25 14:04:58 +0800147 {0, 0x23, "DeviceSettings"},
Jiri Kosinac080d892007-01-25 11:43:31 +0100148 {0, 0x30, "TipPressure"},
149 {0, 0x31, "BarrelPressure"},
150 {0, 0x32, "InRange"},
151 {0, 0x33, "Touch"},
152 {0, 0x34, "UnTouch"},
153 {0, 0x35, "Tap"},
154 {0, 0x39, "TabletFunctionKey"},
155 {0, 0x3a, "ProgramChangeKey"},
156 {0, 0x3c, "Invert"},
157 {0, 0x42, "TipSwitch"},
158 {0, 0x43, "SecondaryTipSwitch"},
159 {0, 0x44, "BarrelSwitch"},
160 {0, 0x45, "Eraser"},
161 {0, 0x46, "TabletPick"},
Stephane Chatty89f536c2009-05-20 15:41:24 +0200162 {0, 0x47, "Confidence"},
163 {0, 0x48, "Width"},
164 {0, 0x49, "Height"},
165 {0, 0x51, "ContactID"},
166 {0, 0x52, "InputMode"},
167 {0, 0x53, "DeviceIndex"},
168 {0, 0x54, "ContactCount"},
169 {0, 0x55, "ContactMaximumNumber"},
Seth Forshee2c6e0272015-03-11 17:26:41 -0500170 {0, 0x59, "ButtonType"},
Ping Cheng368c9662014-06-02 17:19:52 -0700171 {0, 0x5A, "SecondaryBarrelSwitch"},
172 {0, 0x5B, "TransducerSerialNumber"},
Jiri Kosinac080d892007-01-25 11:43:31 +0100173 { 15, 0, "PhysicalInterfaceDevice" },
174 {0, 0x00, "Undefined"},
175 {0, 0x01, "Physical_Interface_Device"},
176 {0, 0x20, "Normal"},
177 {0, 0x21, "Set_Effect_Report"},
178 {0, 0x22, "Effect_Block_Index"},
179 {0, 0x23, "Parameter_Block_Offset"},
180 {0, 0x24, "ROM_Flag"},
181 {0, 0x25, "Effect_Type"},
182 {0, 0x26, "ET_Constant_Force"},
183 {0, 0x27, "ET_Ramp"},
184 {0, 0x28, "ET_Custom_Force_Data"},
185 {0, 0x30, "ET_Square"},
186 {0, 0x31, "ET_Sine"},
187 {0, 0x32, "ET_Triangle"},
188 {0, 0x33, "ET_Sawtooth_Up"},
189 {0, 0x34, "ET_Sawtooth_Down"},
190 {0, 0x40, "ET_Spring"},
191 {0, 0x41, "ET_Damper"},
192 {0, 0x42, "ET_Inertia"},
193 {0, 0x43, "ET_Friction"},
194 {0, 0x50, "Duration"},
195 {0, 0x51, "Sample_Period"},
196 {0, 0x52, "Gain"},
197 {0, 0x53, "Trigger_Button"},
198 {0, 0x54, "Trigger_Repeat_Interval"},
199 {0, 0x55, "Axes_Enable"},
200 {0, 0x56, "Direction_Enable"},
201 {0, 0x57, "Direction"},
202 {0, 0x58, "Type_Specific_Block_Offset"},
203 {0, 0x59, "Block_Type"},
204 {0, 0x5A, "Set_Envelope_Report"},
205 {0, 0x5B, "Attack_Level"},
206 {0, 0x5C, "Attack_Time"},
207 {0, 0x5D, "Fade_Level"},
208 {0, 0x5E, "Fade_Time"},
209 {0, 0x5F, "Set_Condition_Report"},
210 {0, 0x60, "CP_Offset"},
211 {0, 0x61, "Positive_Coefficient"},
212 {0, 0x62, "Negative_Coefficient"},
213 {0, 0x63, "Positive_Saturation"},
214 {0, 0x64, "Negative_Saturation"},
215 {0, 0x65, "Dead_Band"},
216 {0, 0x66, "Download_Force_Sample"},
217 {0, 0x67, "Isoch_Custom_Force_Enable"},
218 {0, 0x68, "Custom_Force_Data_Report"},
219 {0, 0x69, "Custom_Force_Data"},
220 {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
221 {0, 0x6B, "Set_Custom_Force_Report"},
222 {0, 0x6C, "Custom_Force_Data_Offset"},
223 {0, 0x6D, "Sample_Count"},
224 {0, 0x6E, "Set_Periodic_Report"},
225 {0, 0x6F, "Offset"},
226 {0, 0x70, "Magnitude"},
227 {0, 0x71, "Phase"},
228 {0, 0x72, "Period"},
229 {0, 0x73, "Set_Constant_Force_Report"},
230 {0, 0x74, "Set_Ramp_Force_Report"},
231 {0, 0x75, "Ramp_Start"},
232 {0, 0x76, "Ramp_End"},
233 {0, 0x77, "Effect_Operation_Report"},
234 {0, 0x78, "Effect_Operation"},
235 {0, 0x79, "Op_Effect_Start"},
236 {0, 0x7A, "Op_Effect_Start_Solo"},
237 {0, 0x7B, "Op_Effect_Stop"},
238 {0, 0x7C, "Loop_Count"},
239 {0, 0x7D, "Device_Gain_Report"},
240 {0, 0x7E, "Device_Gain"},
241 {0, 0x7F, "PID_Pool_Report"},
242 {0, 0x80, "RAM_Pool_Size"},
243 {0, 0x81, "ROM_Pool_Size"},
244 {0, 0x82, "ROM_Effect_Block_Count"},
245 {0, 0x83, "Simultaneous_Effects_Max"},
246 {0, 0x84, "Pool_Alignment"},
247 {0, 0x85, "PID_Pool_Move_Report"},
248 {0, 0x86, "Move_Source"},
249 {0, 0x87, "Move_Destination"},
250 {0, 0x88, "Move_Length"},
251 {0, 0x89, "PID_Block_Load_Report"},
252 {0, 0x8B, "Block_Load_Status"},
253 {0, 0x8C, "Block_Load_Success"},
254 {0, 0x8D, "Block_Load_Full"},
255 {0, 0x8E, "Block_Load_Error"},
256 {0, 0x8F, "Block_Handle"},
257 {0, 0x90, "PID_Block_Free_Report"},
258 {0, 0x91, "Type_Specific_Block_Handle"},
259 {0, 0x92, "PID_State_Report"},
260 {0, 0x94, "Effect_Playing"},
261 {0, 0x95, "PID_Device_Control_Report"},
262 {0, 0x96, "PID_Device_Control"},
263 {0, 0x97, "DC_Enable_Actuators"},
264 {0, 0x98, "DC_Disable_Actuators"},
265 {0, 0x99, "DC_Stop_All_Effects"},
266 {0, 0x9A, "DC_Device_Reset"},
267 {0, 0x9B, "DC_Device_Pause"},
268 {0, 0x9C, "DC_Device_Continue"},
269 {0, 0x9F, "Device_Paused"},
270 {0, 0xA0, "Actuators_Enabled"},
271 {0, 0xA4, "Safety_Switch"},
272 {0, 0xA5, "Actuator_Override_Switch"},
273 {0, 0xA6, "Actuator_Power"},
274 {0, 0xA7, "Start_Delay"},
275 {0, 0xA8, "Parameter_Block_Size"},
276 {0, 0xA9, "Device_Managed_Pool"},
277 {0, 0xAA, "Shared_Parameter_Blocks"},
278 {0, 0xAB, "Create_New_Effect_Report"},
279 {0, 0xAC, "RAM_Pool_Available"},
Reyad Attiyatb510d092014-05-27 02:10:59 -0500280 { 0x20, 0, "Sensor" },
281 { 0x20, 0x01, "Sensor" },
282 { 0x20, 0x10, "Biometric" },
283 { 0x20, 0x11, "BiometricHumanPresence" },
284 { 0x20, 0x12, "BiometricHumanProximity" },
285 { 0x20, 0x13, "BiometricHumanTouch" },
286 { 0x20, 0x20, "Electrical" },
287 { 0x20, 0x21, "ElectricalCapacitance" },
288 { 0x20, 0x22, "ElectricalCurrent" },
289 { 0x20, 0x23, "ElectricalPower" },
290 { 0x20, 0x24, "ElectricalInductance" },
291 { 0x20, 0x25, "ElectricalResistance" },
292 { 0x20, 0x26, "ElectricalVoltage" },
293 { 0x20, 0x27, "ElectricalPoteniometer" },
294 { 0x20, 0x28, "ElectricalFrequency" },
295 { 0x20, 0x29, "ElectricalPeriod" },
296 { 0x20, 0x30, "Environmental" },
297 { 0x20, 0x31, "EnvironmentalAtmosphericPressure" },
298 { 0x20, 0x32, "EnvironmentalHumidity" },
299 { 0x20, 0x33, "EnvironmentalTemperature" },
300 { 0x20, 0x34, "EnvironmentalWindDirection" },
301 { 0x20, 0x35, "EnvironmentalWindSpeed" },
302 { 0x20, 0x40, "Light" },
303 { 0x20, 0x41, "LightAmbientLight" },
304 { 0x20, 0x42, "LightConsumerInfrared" },
305 { 0x20, 0x50, "Location" },
306 { 0x20, 0x51, "LocationBroadcast" },
307 { 0x20, 0x52, "LocationDeadReckoning" },
308 { 0x20, 0x53, "LocationGPS" },
309 { 0x20, 0x54, "LocationLookup" },
310 { 0x20, 0x55, "LocationOther" },
311 { 0x20, 0x56, "LocationStatic" },
312 { 0x20, 0x57, "LocationTriangulation" },
313 { 0x20, 0x60, "Mechanical" },
314 { 0x20, 0x61, "MechanicalBooleanSwitch" },
315 { 0x20, 0x62, "MechanicalBooleanSwitchArray" },
316 { 0x20, 0x63, "MechanicalMultivalueSwitch" },
317 { 0x20, 0x64, "MechanicalForce" },
318 { 0x20, 0x65, "MechanicalPressure" },
319 { 0x20, 0x66, "MechanicalStrain" },
320 { 0x20, 0x67, "MechanicalWeight" },
321 { 0x20, 0x68, "MechanicalHapticVibrator" },
322 { 0x20, 0x69, "MechanicalHallEffectSwitch" },
323 { 0x20, 0x70, "Motion" },
324 { 0x20, 0x71, "MotionAccelerometer1D" },
325 { 0x20, 0x72, "MotionAccelerometer2D" },
326 { 0x20, 0x73, "MotionAccelerometer3D" },
327 { 0x20, 0x74, "MotionGyrometer1D" },
328 { 0x20, 0x75, "MotionGyrometer2D" },
329 { 0x20, 0x76, "MotionGyrometer3D" },
330 { 0x20, 0x77, "MotionMotionDetector" },
331 { 0x20, 0x78, "MotionSpeedometer" },
332 { 0x20, 0x79, "MotionAccelerometer" },
333 { 0x20, 0x7A, "MotionGyrometer" },
334 { 0x20, 0x80, "Orientation" },
335 { 0x20, 0x81, "OrientationCompass1D" },
336 { 0x20, 0x82, "OrientationCompass2D" },
337 { 0x20, 0x83, "OrientationCompass3D" },
338 { 0x20, 0x84, "OrientationInclinometer1D" },
339 { 0x20, 0x85, "OrientationInclinometer2D" },
340 { 0x20, 0x86, "OrientationInclinometer3D" },
341 { 0x20, 0x87, "OrientationDistance1D" },
342 { 0x20, 0x88, "OrientationDistance2D" },
343 { 0x20, 0x89, "OrientationDistance3D" },
344 { 0x20, 0x8A, "OrientationDeviceOrientation" },
345 { 0x20, 0x8B, "OrientationCompass" },
346 { 0x20, 0x8C, "OrientationInclinometer" },
347 { 0x20, 0x8D, "OrientationDistance" },
348 { 0x20, 0x90, "Scanner" },
349 { 0x20, 0x91, "ScannerBarcode" },
350 { 0x20, 0x91, "ScannerRFID" },
351 { 0x20, 0x91, "ScannerNFC" },
352 { 0x20, 0xA0, "Time" },
353 { 0x20, 0xA1, "TimeAlarmTimer" },
354 { 0x20, 0xA2, "TimeRealTimeClock" },
355 { 0x20, 0xE0, "Other" },
356 { 0x20, 0xE1, "OtherCustom" },
357 { 0x20, 0xE2, "OtherGeneric" },
358 { 0x20, 0xE3, "OtherGenericEnumerator" },
Jiri Kosinac080d892007-01-25 11:43:31 +0100359 { 0x84, 0, "Power Device" },
360 { 0x84, 0x02, "PresentStatus" },
361 { 0x84, 0x03, "ChangeStatus" },
362 { 0x84, 0x04, "UPS" },
363 { 0x84, 0x05, "PowerSupply" },
364 { 0x84, 0x10, "BatterySystem" },
365 { 0x84, 0x11, "BatterySystemID" },
366 { 0x84, 0x12, "Battery" },
367 { 0x84, 0x13, "BatteryID" },
368 { 0x84, 0x14, "Charger" },
369 { 0x84, 0x15, "ChargerID" },
370 { 0x84, 0x16, "PowerConverter" },
371 { 0x84, 0x17, "PowerConverterID" },
372 { 0x84, 0x18, "OutletSystem" },
373 { 0x84, 0x19, "OutletSystemID" },
374 { 0x84, 0x1a, "Input" },
375 { 0x84, 0x1b, "InputID" },
376 { 0x84, 0x1c, "Output" },
377 { 0x84, 0x1d, "OutputID" },
378 { 0x84, 0x1e, "Flow" },
379 { 0x84, 0x1f, "FlowID" },
380 { 0x84, 0x20, "Outlet" },
381 { 0x84, 0x21, "OutletID" },
382 { 0x84, 0x22, "Gang" },
383 { 0x84, 0x24, "PowerSummary" },
384 { 0x84, 0x25, "PowerSummaryID" },
385 { 0x84, 0x30, "Voltage" },
386 { 0x84, 0x31, "Current" },
387 { 0x84, 0x32, "Frequency" },
388 { 0x84, 0x33, "ApparentPower" },
389 { 0x84, 0x35, "PercentLoad" },
390 { 0x84, 0x40, "ConfigVoltage" },
391 { 0x84, 0x41, "ConfigCurrent" },
392 { 0x84, 0x43, "ConfigApparentPower" },
393 { 0x84, 0x53, "LowVoltageTransfer" },
394 { 0x84, 0x54, "HighVoltageTransfer" },
395 { 0x84, 0x56, "DelayBeforeStartup" },
396 { 0x84, 0x57, "DelayBeforeShutdown" },
397 { 0x84, 0x58, "Test" },
398 { 0x84, 0x5a, "AudibleAlarmControl" },
399 { 0x84, 0x60, "Present" },
400 { 0x84, 0x61, "Good" },
401 { 0x84, 0x62, "InternalFailure" },
402 { 0x84, 0x65, "Overload" },
403 { 0x84, 0x66, "OverCharged" },
404 { 0x84, 0x67, "OverTemperature" },
405 { 0x84, 0x68, "ShutdownRequested" },
406 { 0x84, 0x69, "ShutdownImminent" },
407 { 0x84, 0x6b, "SwitchOn/Off" },
408 { 0x84, 0x6c, "Switchable" },
409 { 0x84, 0x6d, "Used" },
410 { 0x84, 0x6e, "Boost" },
411 { 0x84, 0x73, "CommunicationLost" },
412 { 0x84, 0xfd, "iManufacturer" },
413 { 0x84, 0xfe, "iProduct" },
414 { 0x84, 0xff, "iSerialNumber" },
415 { 0x85, 0, "Battery System" },
416 { 0x85, 0x01, "SMBBatteryMode" },
417 { 0x85, 0x02, "SMBBatteryStatus" },
418 { 0x85, 0x03, "SMBAlarmWarning" },
419 { 0x85, 0x04, "SMBChargerMode" },
420 { 0x85, 0x05, "SMBChargerStatus" },
421 { 0x85, 0x06, "SMBChargerSpecInfo" },
422 { 0x85, 0x07, "SMBSelectorState" },
423 { 0x85, 0x08, "SMBSelectorPresets" },
424 { 0x85, 0x09, "SMBSelectorInfo" },
425 { 0x85, 0x29, "RemainingCapacityLimit" },
426 { 0x85, 0x2c, "CapacityMode" },
427 { 0x85, 0x42, "BelowRemainingCapacityLimit" },
428 { 0x85, 0x44, "Charging" },
429 { 0x85, 0x45, "Discharging" },
430 { 0x85, 0x4b, "NeedReplacement" },
431 { 0x85, 0x66, "RemainingCapacity" },
432 { 0x85, 0x68, "RunTimeToEmpty" },
433 { 0x85, 0x6a, "AverageTimeToFull" },
434 { 0x85, 0x83, "DesignCapacity" },
435 { 0x85, 0x85, "ManufacturerDate" },
436 { 0x85, 0x89, "iDeviceChemistry" },
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300437 { 0x85, 0x8b, "Rechargeable" },
Jiri Kosinac080d892007-01-25 11:43:31 +0100438 { 0x85, 0x8f, "iOEMInformation" },
439 { 0x85, 0x8d, "CapacityGranularity1" },
440 { 0x85, 0xd0, "ACPresent" },
441 /* pages 0xff00 to 0xffff are vendor-specific */
442 { 0xffff, 0, "Vendor-specific-FF" },
443 { 0, 0, NULL }
444};
445
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200446/* Either output directly into simple seq_file, or (if f == NULL)
447 * allocate a separate buffer that will then be passed to the 'events'
448 * ringbuffer.
449 *
450 * This is because these functions can be called both for "one-shot"
451 * "rdesc" while resolving, or for blocking "events".
452 *
453 * This holds both for resolv_usage_page() and hid_resolv_usage().
454 */
455static char *resolv_usage_page(unsigned page, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100456 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200457 char *buf = NULL;
458
459 if (!f) {
460 buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
461 if (!buf)
462 return ERR_PTR(-ENOMEM);
463 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100464
465 for (p = hid_usage_table; p->description; p++)
466 if (p->page == page) {
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200467 if (!f) {
468 snprintf(buf, HID_DEBUG_BUFSIZE, "%s",
469 p->description);
470 return buf;
471 }
472 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200473 seq_printf(f, "%s", p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200474 return NULL;
475 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100476 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200477 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200478 snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200479 else
480 seq_printf(f, "%04x", page);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200481 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100482}
483
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200484char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100485 const struct hid_usage_entry *p;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200486 char *buf = NULL;
487 int len = 0;
Jiri Kosinac080d892007-01-25 11:43:31 +0100488
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200489 buf = resolv_usage_page(usage >> 16, f);
490 if (IS_ERR(buf)) {
Joe Perches4291ee32010-12-09 19:29:03 -0800491 pr_err("error allocating HID debug buffer\n");
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200492 return NULL;
493 }
Jiri Kosina58037eb2007-05-30 15:07:13 +0200494
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200495
496 if (!f) {
497 len = strlen(buf);
498 snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), ".");
499 len++;
500 }
501 else {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200502 seq_printf(f, ".");
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200503 }
Jiri Kosinac080d892007-01-25 11:43:31 +0100504 for (p = hid_usage_table; p->description; p++)
505 if (p->page == (usage >> 16)) {
506 for(++p; p->description && p->usage != 0; p++)
507 if (p->usage == (usage & 0xffff)) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200508 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200509 snprintf(buf + len,
510 max(0,HID_DEBUG_BUFSIZE - len - 1),
511 "%s", p->description);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200512 else
513 seq_printf(f,
514 "%s",
515 p->description);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200516 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100517 }
518 break;
519 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200520 if (!f)
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200521 snprintf(buf + len, max(0, HID_DEBUG_BUFSIZE - len - 1),
522 "%04x", usage & 0xffff);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200523 else
524 seq_printf(f, "%04x", usage & 0xffff);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200525 return buf;
Jiri Kosinac080d892007-01-25 11:43:31 +0100526}
527EXPORT_SYMBOL_GPL(hid_resolv_usage);
528
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200529static void tab(int n, struct seq_file *f) {
530 seq_printf(f, "%*s", n, "");
Jiri Kosinac080d892007-01-25 11:43:31 +0100531}
532
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200533void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {
Jiri Kosinac080d892007-01-25 11:43:31 +0100534 int j;
535
536 if (field->physical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200537 tab(n, f);
538 seq_printf(f, "Physical(");
539 hid_resolv_usage(field->physical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100540 }
541 if (field->logical) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200542 tab(n, f);
543 seq_printf(f, "Logical(");
544 hid_resolv_usage(field->logical, f); seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100545 }
Jeff Brown54d33392011-08-15 16:39:02 -0700546 if (field->application) {
547 tab(n, f);
548 seq_printf(f, "Application(");
549 hid_resolv_usage(field->application, f); seq_printf(f, ")\n");
550 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200551 tab(n, f); seq_printf(f, "Usage(%d)\n", field->maxusage);
Jiri Kosinac080d892007-01-25 11:43:31 +0100552 for (j = 0; j < field->maxusage; j++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200553 tab(n+2, f); hid_resolv_usage(field->usage[j].hid, f); seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100554 }
555 if (field->logical_minimum != field->logical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200556 tab(n, f); seq_printf(f, "Logical Minimum(%d)\n", field->logical_minimum);
557 tab(n, f); seq_printf(f, "Logical Maximum(%d)\n", field->logical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100558 }
559 if (field->physical_minimum != field->physical_maximum) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200560 tab(n, f); seq_printf(f, "Physical Minimum(%d)\n", field->physical_minimum);
561 tab(n, f); seq_printf(f, "Physical Maximum(%d)\n", field->physical_maximum);
Jiri Kosinac080d892007-01-25 11:43:31 +0100562 }
563 if (field->unit_exponent) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200564 tab(n, f); seq_printf(f, "Unit Exponent(%d)\n", field->unit_exponent);
Jiri Kosinac080d892007-01-25 11:43:31 +0100565 }
566 if (field->unit) {
Joe Perches0ce1ac32007-09-26 16:29:53 +0200567 static const char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
568 static const char *units[5][8] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100569 { "None", "None", "None", "None", "None", "None", "None", "None" },
570 { "None", "Centimeter", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
571 { "None", "Radians", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
572 { "None", "Inch", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" },
573 { "None", "Degrees", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }
574 };
575
576 int i;
577 int sys;
578 __u32 data = field->unit;
579
580 /* First nibble tells us which system we're in. */
581 sys = data & 0xf;
582 data >>= 4;
583
584 if(sys > 4) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200585 tab(n, f); seq_printf(f, "Unit(Invalid)\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100586 }
587 else {
588 int earlier_unit = 0;
589
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200590 tab(n, f); seq_printf(f, "Unit(%s : ", systems[sys]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100591
592 for (i=1 ; i<sizeof(__u32)*2 ; i++) {
593 char nibble = data & 0xf;
594 data >>= 4;
595 if (nibble != 0) {
596 if(earlier_unit++ > 0)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200597 seq_printf(f, "*");
598 seq_printf(f, "%s", units[sys][i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100599 if(nibble != 1) {
600 /* This is a _signed_ nibble(!) */
601
602 int val = nibble & 0x7;
603 if(nibble & 0x08)
604 val = -((0x7 & ~val) +1);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200605 seq_printf(f, "^%d", val);
Jiri Kosinac080d892007-01-25 11:43:31 +0100606 }
607 }
608 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200609 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100610 }
611 }
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200612 tab(n, f); seq_printf(f, "Report Size(%u)\n", field->report_size);
613 tab(n, f); seq_printf(f, "Report Count(%u)\n", field->report_count);
614 tab(n, f); seq_printf(f, "Report Offset(%u)\n", field->report_offset);
Jiri Kosinac080d892007-01-25 11:43:31 +0100615
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200616 tab(n, f); seq_printf(f, "Flags( ");
Jiri Kosinac080d892007-01-25 11:43:31 +0100617 j = field->flags;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200618 seq_printf(f, "%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
619 seq_printf(f, "%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
620 seq_printf(f, "%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
621 seq_printf(f, "%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
622 seq_printf(f, "%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
623 seq_printf(f, "%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPreferredState " : "");
624 seq_printf(f, "%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
625 seq_printf(f, "%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
626 seq_printf(f, "%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
627 seq_printf(f, ")\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100628}
629EXPORT_SYMBOL_GPL(hid_dump_field);
630
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200631void hid_dump_device(struct hid_device *device, struct seq_file *f)
632{
Jiri Kosinac080d892007-01-25 11:43:31 +0100633 struct hid_report_enum *report_enum;
634 struct hid_report *report;
635 struct list_head *list;
636 unsigned i,k;
Joe Perches0ce1ac32007-09-26 16:29:53 +0200637 static const char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
Jiri Kosinac080d892007-01-25 11:43:31 +0100638
639 for (i = 0; i < HID_REPORT_TYPES; i++) {
640 report_enum = device->report_enum + i;
641 list = report_enum->report_list.next;
642 while (list != &report_enum->report_list) {
643 report = (struct hid_report *) list;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200644 tab(2, f);
645 seq_printf(f, "%s", table[i]);
Jiri Kosinac080d892007-01-25 11:43:31 +0100646 if (report->id)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200647 seq_printf(f, "(%d)", report->id);
648 seq_printf(f, "[%s]", table[report->type]);
649 seq_printf(f, "\n");
Jiri Kosinac080d892007-01-25 11:43:31 +0100650 for (k = 0; k < report->maxfield; k++) {
Jiri Kosinaa635f9d2009-06-12 15:20:55 +0200651 tab(4, f);
652 seq_printf(f, "Field(%d)\n", k);
653 hid_dump_field(report->field[k], 6, f);
Jiri Kosinac080d892007-01-25 11:43:31 +0100654 }
655 list = list->next;
656 }
657 }
658}
659EXPORT_SYMBOL_GPL(hid_dump_device);
660
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200661/* enqueue string to 'events' ring buffer */
662void hid_debug_event(struct hid_device *hdev, char *buf)
663{
Rasmus Villemoes92529622015-11-24 13:33:47 +0100664 unsigned i;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200665 struct hid_debug_list *list;
Jiri Kosina1deb9d32013-05-06 13:05:50 +0200666 unsigned long flags;
Jiri Kosina58037eb2007-05-30 15:07:13 +0200667
Jiri Kosina1deb9d32013-05-06 13:05:50 +0200668 spin_lock_irqsave(&hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200669 list_for_each_entry(list, &hdev->debug_list, node) {
Rasmus Villemoes92529622015-11-24 13:33:47 +0100670 for (i = 0; buf[i]; i++)
Bruno Prémonte639ba42010-03-15 19:00:27 +0100671 list->hid_debug_buf[(list->tail + i) % HID_DEBUG_BUFSIZE] =
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200672 buf[i];
Bruno Prémonte639ba42010-03-15 19:00:27 +0100673 list->tail = (list->tail + i) % HID_DEBUG_BUFSIZE;
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200674 }
Jiri Kosina1deb9d32013-05-06 13:05:50 +0200675 spin_unlock_irqrestore(&hdev->debug_list_lock, flags);
Chase Douglas1debfb32010-08-30 13:27:45 -0400676
677 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200678}
679EXPORT_SYMBOL_GPL(hid_debug_event);
680
Benjamin Tissoiresa5f04b92013-04-17 19:38:13 +0200681void hid_dump_report(struct hid_device *hid, int type, u8 *data,
682 int size)
683{
684 struct hid_report_enum *report_enum;
685 char *buf;
686 unsigned int i;
687
688 buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
689
690 if (!buf)
691 return;
692
693 report_enum = hid->report_enum + type;
694
695 /* dump the report */
696 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
697 "\nreport (size %u) (%snumbered) = ", size,
698 report_enum->numbered ? "" : "un");
699 hid_debug_event(hid, buf);
700
701 for (i = 0; i < size; i++) {
702 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
703 " %02x", data[i]);
704 hid_debug_event(hid, buf);
705 }
706 hid_debug_event(hid, "\n");
707 kfree(buf);
708}
709EXPORT_SYMBOL_GPL(hid_dump_report);
710
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200711void hid_dump_input(struct hid_device *hdev, struct hid_usage *usage, __s32 value)
712{
713 char *buf;
714 int len;
715
716 buf = hid_resolv_usage(usage->hid, NULL);
717 if (!buf)
718 return;
719 len = strlen(buf);
720 snprintf(buf + len, HID_DEBUG_BUFSIZE - len - 1, " = %d\n", value);
721
722 hid_debug_event(hdev, buf);
723
724 kfree(buf);
725 wake_up_interruptible(&hdev->debug_wait);
726
Jiri Kosinac080d892007-01-25 11:43:31 +0100727}
728EXPORT_SYMBOL_GPL(hid_dump_input);
729
Joe Perches0ce1ac32007-09-26 16:29:53 +0200730static const char *events[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100731 [EV_SYN] = "Sync", [EV_KEY] = "Key",
732 [EV_REL] = "Relative", [EV_ABS] = "Absolute",
733 [EV_MSC] = "Misc", [EV_LED] = "LED",
734 [EV_SND] = "Sound", [EV_REP] = "Repeat",
735 [EV_FF] = "ForceFeedback", [EV_PWR] = "Power",
736 [EV_FF_STATUS] = "ForceFeedbackStatus",
737};
738
Stephane Chatty89f536c2009-05-20 15:41:24 +0200739static const char *syncs[3] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100740 [SYN_REPORT] = "Report", [SYN_CONFIG] = "Config",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200741 [SYN_MT_REPORT] = "MT Report",
Jiri Kosinac080d892007-01-25 11:43:31 +0100742};
Stephane Chatty89f536c2009-05-20 15:41:24 +0200743
Joe Perches0ce1ac32007-09-26 16:29:53 +0200744static const char *keys[KEY_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100745 [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc",
746 [KEY_1] = "1", [KEY_2] = "2",
747 [KEY_3] = "3", [KEY_4] = "4",
748 [KEY_5] = "5", [KEY_6] = "6",
749 [KEY_7] = "7", [KEY_8] = "8",
750 [KEY_9] = "9", [KEY_0] = "0",
751 [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal",
752 [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab",
753 [KEY_Q] = "Q", [KEY_W] = "W",
754 [KEY_E] = "E", [KEY_R] = "R",
755 [KEY_T] = "T", [KEY_Y] = "Y",
756 [KEY_U] = "U", [KEY_I] = "I",
757 [KEY_O] = "O", [KEY_P] = "P",
758 [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace",
759 [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl",
760 [KEY_A] = "A", [KEY_S] = "S",
761 [KEY_D] = "D", [KEY_F] = "F",
762 [KEY_G] = "G", [KEY_H] = "H",
763 [KEY_J] = "J", [KEY_K] = "K",
764 [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon",
765 [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave",
766 [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash",
767 [KEY_Z] = "Z", [KEY_X] = "X",
768 [KEY_C] = "C", [KEY_V] = "V",
769 [KEY_B] = "B", [KEY_N] = "N",
770 [KEY_M] = "M", [KEY_COMMA] = "Comma",
771 [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash",
772 [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk",
773 [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space",
774 [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1",
775 [KEY_F2] = "F2", [KEY_F3] = "F3",
776 [KEY_F4] = "F4", [KEY_F5] = "F5",
777 [KEY_F6] = "F6", [KEY_F7] = "F7",
778 [KEY_F8] = "F8", [KEY_F9] = "F9",
779 [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock",
780 [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7",
781 [KEY_KP8] = "KP8", [KEY_KP9] = "KP9",
782 [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4",
783 [KEY_KP5] = "KP5", [KEY_KP6] = "KP6",
784 [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1",
785 [KEY_KP2] = "KP2", [KEY_KP3] = "KP3",
786 [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot",
787 [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd",
788 [KEY_F11] = "F11", [KEY_F12] = "F12",
789 [KEY_RO] = "RO", [KEY_KATAKANA] = "Katakana",
790 [KEY_HIRAGANA] = "HIRAGANA", [KEY_HENKAN] = "Henkan",
791 [KEY_KATAKANAHIRAGANA] = "Katakana/Hiragana", [KEY_MUHENKAN] = "Muhenkan",
792 [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter",
793 [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash",
794 [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt",
795 [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home",
796 [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp",
797 [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right",
798 [KEY_END] = "End", [KEY_DOWN] = "Down",
799 [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert",
800 [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro",
801 [KEY_MUTE] = "Mute", [KEY_VOLUMEDOWN] = "VolumeDown",
802 [KEY_VOLUMEUP] = "VolumeUp", [KEY_POWER] = "Power",
803 [KEY_KPEQUAL] = "KPEqual", [KEY_KPPLUSMINUS] = "KPPlusMinus",
804 [KEY_PAUSE] = "Pause", [KEY_KPCOMMA] = "KPComma",
805 [KEY_HANGUEL] = "Hangeul", [KEY_HANJA] = "Hanja",
806 [KEY_YEN] = "Yen", [KEY_LEFTMETA] = "LeftMeta",
807 [KEY_RIGHTMETA] = "RightMeta", [KEY_COMPOSE] = "Compose",
808 [KEY_STOP] = "Stop", [KEY_AGAIN] = "Again",
809 [KEY_PROPS] = "Props", [KEY_UNDO] = "Undo",
810 [KEY_FRONT] = "Front", [KEY_COPY] = "Copy",
811 [KEY_OPEN] = "Open", [KEY_PASTE] = "Paste",
812 [KEY_FIND] = "Find", [KEY_CUT] = "Cut",
813 [KEY_HELP] = "Help", [KEY_MENU] = "Menu",
814 [KEY_CALC] = "Calc", [KEY_SETUP] = "Setup",
815 [KEY_SLEEP] = "Sleep", [KEY_WAKEUP] = "WakeUp",
816 [KEY_FILE] = "File", [KEY_SENDFILE] = "SendFile",
817 [KEY_DELETEFILE] = "DeleteFile", [KEY_XFER] = "X-fer",
818 [KEY_PROG1] = "Prog1", [KEY_PROG2] = "Prog2",
819 [KEY_WWW] = "WWW", [KEY_MSDOS] = "MSDOS",
Stefan Brünse92865e2015-03-05 23:25:51 -0800820 [KEY_COFFEE] = "Coffee", [KEY_ROTATE_DISPLAY] = "RotateDisplay",
Jiri Kosinac080d892007-01-25 11:43:31 +0100821 [KEY_CYCLEWINDOWS] = "CycleWindows", [KEY_MAIL] = "Mail",
822 [KEY_BOOKMARKS] = "Bookmarks", [KEY_COMPUTER] = "Computer",
823 [KEY_BACK] = "Back", [KEY_FORWARD] = "Forward",
824 [KEY_CLOSECD] = "CloseCD", [KEY_EJECTCD] = "EjectCD",
825 [KEY_EJECTCLOSECD] = "EjectCloseCD", [KEY_NEXTSONG] = "NextSong",
826 [KEY_PLAYPAUSE] = "PlayPause", [KEY_PREVIOUSSONG] = "PreviousSong",
827 [KEY_STOPCD] = "StopCD", [KEY_RECORD] = "Record",
828 [KEY_REWIND] = "Rewind", [KEY_PHONE] = "Phone",
829 [KEY_ISO] = "ISOKey", [KEY_CONFIG] = "Config",
830 [KEY_HOMEPAGE] = "HomePage", [KEY_REFRESH] = "Refresh",
831 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
832 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
833 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
834 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
835 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
836 [KEY_F14] = "F14", [KEY_F15] = "F15",
837 [KEY_F16] = "F16", [KEY_F17] = "F17",
838 [KEY_F18] = "F18", [KEY_F19] = "F19",
839 [KEY_F20] = "F20", [KEY_F21] = "F21",
840 [KEY_F22] = "F22", [KEY_F23] = "F23",
841 [KEY_F24] = "F24", [KEY_PLAYCD] = "PlayCD",
842 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
843 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend",
844 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
845 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
846 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
847 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
848 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
849 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
850 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
851 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
852 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
853 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
854 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
Antonio Ospitea4432552013-12-17 12:52:48 +0100855 [BTN_DPAD_UP] = "BtnDPadUp", [BTN_DPAD_DOWN] = "BtnDPadDown",
856 [BTN_DPAD_LEFT] = "BtnDPadLeft", [BTN_DPAD_RIGHT] = "BtnDPadRight",
Jiri Kosinac080d892007-01-25 11:43:31 +0100857 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
858 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
859 [BTN_4] = "Btn4", [BTN_5] = "Btn5",
860 [BTN_6] = "Btn6", [BTN_7] = "Btn7",
861 [BTN_8] = "Btn8", [BTN_9] = "Btn9",
862 [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn",
863 [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn",
864 [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn",
865 [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn",
866 [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn",
867 [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn",
868 [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn",
869 [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2",
870 [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4",
871 [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6",
872 [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA",
873 [BTN_B] = "BtnB", [BTN_C] = "BtnC",
874 [BTN_X] = "BtnX", [BTN_Y] = "BtnY",
875 [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL",
876 [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2",
877 [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect",
878 [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode",
879 [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR",
880 [BTN_TOOL_PEN] = "ToolPen", [BTN_TOOL_RUBBER] = "ToolRubber",
881 [BTN_TOOL_BRUSH] = "ToolBrush", [BTN_TOOL_PENCIL] = "ToolPencil",
882 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
883 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
884 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
885 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
Antonio Ospitea4432552013-12-17 12:52:48 +0100886 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_TOOL_QUADTAP] = "ToolQuadrupleTap",
887 [BTN_GEAR_DOWN] = "WheelBtn",
Jiri Kosinac080d892007-01-25 11:43:31 +0100888 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
889 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
890 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
891 [KEY_OPTION] = "Option", [KEY_INFO] = "Info",
892 [KEY_TIME] = "Time", [KEY_VENDOR] = "Vendor",
893 [KEY_ARCHIVE] = "Archive", [KEY_PROGRAM] = "Program",
894 [KEY_CHANNEL] = "Channel", [KEY_FAVORITES] = "Favorites",
895 [KEY_EPG] = "EPG", [KEY_PVR] = "PVR",
896 [KEY_MHP] = "MHP", [KEY_LANGUAGE] = "Language",
897 [KEY_TITLE] = "Title", [KEY_SUBTITLE] = "Subtitle",
898 [KEY_ANGLE] = "Angle", [KEY_ZOOM] = "Zoom",
899 [KEY_MODE] = "Mode", [KEY_KEYBOARD] = "Keyboard",
900 [KEY_SCREEN] = "Screen", [KEY_PC] = "PC",
901 [KEY_TV] = "TV", [KEY_TV2] = "TV2",
902 [KEY_VCR] = "VCR", [KEY_VCR2] = "VCR2",
903 [KEY_SAT] = "Sat", [KEY_SAT2] = "Sat2",
904 [KEY_CD] = "CD", [KEY_TAPE] = "Tape",
905 [KEY_RADIO] = "Radio", [KEY_TUNER] = "Tuner",
906 [KEY_PLAYER] = "Player", [KEY_TEXT] = "Text",
907 [KEY_DVD] = "DVD", [KEY_AUX] = "Aux",
908 [KEY_MP3] = "MP3", [KEY_AUDIO] = "Audio",
909 [KEY_VIDEO] = "Video", [KEY_DIRECTORY] = "Directory",
910 [KEY_LIST] = "List", [KEY_MEMO] = "Memo",
911 [KEY_CALENDAR] = "Calendar", [KEY_RED] = "Red",
912 [KEY_GREEN] = "Green", [KEY_YELLOW] = "Yellow",
913 [KEY_BLUE] = "Blue", [KEY_CHANNELUP] = "ChannelUp",
914 [KEY_CHANNELDOWN] = "ChannelDown", [KEY_FIRST] = "First",
915 [KEY_LAST] = "Last", [KEY_AB] = "AB",
916 [KEY_NEXT] = "Next", [KEY_RESTART] = "Restart",
917 [KEY_SLOW] = "Slow", [KEY_SHUFFLE] = "Shuffle",
918 [KEY_BREAK] = "Break", [KEY_PREVIOUS] = "Previous",
919 [KEY_DIGITS] = "Digits", [KEY_TEEN] = "TEEN",
920 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
921 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
922 [KEY_DEL_LINE] = "DeleteLine",
923 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
924 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
Jiri Kosina1fe8736d2007-08-09 13:24:11 +0200925 [KEY_DOCUMENTS] = "Documents", [KEY_SPELLCHECK] = "SpellCheck",
Khelben Blackstaffe2bca072007-10-04 10:32:03 +0200926 [KEY_LOGOFF] = "Logoff",
Jiri Kosinac080d892007-01-25 11:43:31 +0100927 [KEY_FN] = "Fn", [KEY_FN_ESC] = "Fn+ESC",
928 [KEY_FN_1] = "Fn+1", [KEY_FN_2] = "Fn+2",
929 [KEY_FN_B] = "Fn+B", [KEY_FN_D] = "Fn+D",
930 [KEY_FN_E] = "Fn+E", [KEY_FN_F] = "Fn+F",
931 [KEY_FN_S] = "Fn+S",
932 [KEY_FN_F1] = "Fn+F1", [KEY_FN_F2] = "Fn+F2",
933 [KEY_FN_F3] = "Fn+F3", [KEY_FN_F4] = "Fn+F4",
934 [KEY_FN_F5] = "Fn+F5", [KEY_FN_F6] = "Fn+F6",
935 [KEY_FN_F7] = "Fn+F7", [KEY_FN_F8] = "Fn+F8",
936 [KEY_FN_F9] = "Fn+F9", [KEY_FN_F10] = "Fn+F10",
937 [KEY_FN_F11] = "Fn+F11", [KEY_FN_F12] = "Fn+F12",
938 [KEY_KBDILLUMTOGGLE] = "KbdIlluminationToggle",
939 [KEY_KBDILLUMDOWN] = "KbdIlluminationDown",
940 [KEY_KBDILLUMUP] = "KbdIlluminationUp",
941 [KEY_SWITCHVIDEOMODE] = "SwitchVideoMode",
Olivier Gayf362e692014-04-25 20:26:44 +0200942 [KEY_BUTTONCONFIG] = "ButtonConfig",
943 [KEY_TASKMANAGER] = "TaskManager",
944 [KEY_JOURNAL] = "Journal",
945 [KEY_CONTROLPANEL] = "ControlPanel",
946 [KEY_APPSELECT] = "AppSelect",
947 [KEY_SCREENSAVER] = "ScreenSaver",
948 [KEY_VOICECOMMAND] = "VoiceCommand",
949 [KEY_BRIGHTNESS_MIN] = "BrightnessMin",
950 [KEY_BRIGHTNESS_MAX] = "BrightnessMax",
951 [KEY_BRIGHTNESS_AUTO] = "BrightnessAuto",
Olivier Gayf9740082014-10-18 01:53:39 +0200952 [KEY_KBDINPUTASSIST_PREV] = "KbdInputAssistPrev",
953 [KEY_KBDINPUTASSIST_NEXT] = "KbdInputAssistNext",
954 [KEY_KBDINPUTASSIST_PREVGROUP] = "KbdInputAssistPrevGroup",
955 [KEY_KBDINPUTASSIST_NEXTGROUP] = "KbdInputAssistNextGroup",
956 [KEY_KBDINPUTASSIST_ACCEPT] = "KbdInputAssistAccept",
957 [KEY_KBDINPUTASSIST_CANCEL] = "KbdInputAssistCancel",
Jiri Kosinac080d892007-01-25 11:43:31 +0100958};
959
Joe Perches0ce1ac32007-09-26 16:29:53 +0200960static const char *relatives[REL_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100961 [REL_X] = "X", [REL_Y] = "Y",
962 [REL_Z] = "Z", [REL_RX] = "Rx",
963 [REL_RY] = "Ry", [REL_RZ] = "Rz",
964 [REL_HWHEEL] = "HWheel", [REL_DIAL] = "Dial",
965 [REL_WHEEL] = "Wheel", [REL_MISC] = "Misc",
966};
967
Daniel Mack81c2a3b2010-05-20 22:52:58 -0700968static const char *absolutes[ABS_CNT] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100969 [ABS_X] = "X", [ABS_Y] = "Y",
970 [ABS_Z] = "Z", [ABS_RX] = "Rx",
971 [ABS_RY] = "Ry", [ABS_RZ] = "Rz",
972 [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder",
973 [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas",
974 [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X",
975 [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X",
976 [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X",
977 [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X",
978 [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure",
979 [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200980 [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth",
Jiri Kosinac080d892007-01-25 11:43:31 +0100981 [ABS_VOLUME] = "Volume", [ABS_MISC] = "Misc",
Stephane Chatty89f536c2009-05-20 15:41:24 +0200982 [ABS_MT_TOUCH_MAJOR] = "MTMajor",
983 [ABS_MT_TOUCH_MINOR] = "MTMinor",
984 [ABS_MT_WIDTH_MAJOR] = "MTMajorW",
985 [ABS_MT_WIDTH_MINOR] = "MTMinorW",
986 [ABS_MT_ORIENTATION] = "MTOrientation",
987 [ABS_MT_POSITION_X] = "MTPositionX",
988 [ABS_MT_POSITION_Y] = "MTPositionY",
989 [ABS_MT_TOOL_TYPE] = "MTToolType",
990 [ABS_MT_BLOB_ID] = "MTBlobID",
Jiri Kosinac080d892007-01-25 11:43:31 +0100991};
992
Joe Perches0ce1ac32007-09-26 16:29:53 +0200993static const char *misc[MSC_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100994 [MSC_SERIAL] = "Serial", [MSC_PULSELED] = "Pulseled",
995 [MSC_GESTURE] = "Gesture", [MSC_RAW] = "RawData"
996};
997
Joe Perches0ce1ac32007-09-26 16:29:53 +0200998static const char *leds[LED_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +0100999 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
1000 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
1001 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
1002 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
1003 [LED_MISC] = "Misc",
1004};
1005
Joe Perches0ce1ac32007-09-26 16:29:53 +02001006static const char *repeats[REP_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +01001007 [REP_DELAY] = "Delay", [REP_PERIOD] = "Period"
1008};
1009
Joe Perches0ce1ac32007-09-26 16:29:53 +02001010static const char *sounds[SND_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +01001011 [SND_CLICK] = "Click", [SND_BELL] = "Bell",
1012 [SND_TONE] = "Tone"
1013};
1014
Joe Perches0ce1ac32007-09-26 16:29:53 +02001015static const char **names[EV_MAX + 1] = {
Jiri Kosinac080d892007-01-25 11:43:31 +01001016 [EV_SYN] = syncs, [EV_KEY] = keys,
1017 [EV_REL] = relatives, [EV_ABS] = absolutes,
1018 [EV_MSC] = misc, [EV_LED] = leds,
1019 [EV_SND] = sounds, [EV_REP] = repeats,
1020};
1021
H Hartley Sweeten62e62da2010-01-14 19:10:07 -07001022static void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f)
1023{
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001024 seq_printf(f, "%s.%s", events[type] ? events[type] : "?",
Jiri Kosinac080d892007-01-25 11:43:31 +01001025 names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
1026}
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001027
H Hartley Sweeten62e62da2010-01-14 19:10:07 -07001028static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001029{
1030 int i, j, k;
1031 struct hid_report *report;
1032 struct hid_usage *usage;
1033
1034 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
1035 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
1036 for (i = 0; i < report->maxfield; i++) {
1037 for ( j = 0; j < report->field[i]->maxusage; j++) {
1038 usage = report->field[i]->usage + j;
1039 hid_resolv_usage(usage->hid, f);
1040 seq_printf(f, " ---> ");
1041 hid_resolv_event(usage->type, usage->code, f);
1042 seq_printf(f, "\n");
1043 }
1044 }
1045 }
1046 }
1047
1048}
1049
1050static int hid_debug_rdesc_show(struct seq_file *f, void *p)
1051{
1052 struct hid_device *hdev = f->private;
Henrik Rydberg8db089d2012-08-21 20:22:44 +02001053 const __u8 *rdesc = hdev->rdesc;
1054 unsigned rsize = hdev->rsize;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001055 int i;
1056
Henrik Rydberg8db089d2012-08-21 20:22:44 +02001057 if (!rdesc) {
1058 rdesc = hdev->dev_rdesc;
1059 rsize = hdev->dev_rsize;
1060 }
1061
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001062 /* dump HID report descriptor */
Henrik Rydberg8db089d2012-08-21 20:22:44 +02001063 for (i = 0; i < rsize; i++)
1064 seq_printf(f, "%02x ", rdesc[i]);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001065 seq_printf(f, "\n\n");
1066
1067 /* dump parsed data and input mappings */
1068 hid_dump_device(hdev, f);
1069 seq_printf(f, "\n");
1070 hid_dump_input_mapping(hdev, f);
1071
1072 return 0;
1073}
1074
1075static int hid_debug_rdesc_open(struct inode *inode, struct file *file)
1076{
1077 return single_open(file, hid_debug_rdesc_show, inode->i_private);
1078}
1079
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001080static int hid_debug_events_open(struct inode *inode, struct file *file)
1081{
1082 int err = 0;
1083 struct hid_debug_list *list;
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001084 unsigned long flags;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001085
1086 if (!(list = kzalloc(sizeof(struct hid_debug_list), GFP_KERNEL))) {
1087 err = -ENOMEM;
1088 goto out;
1089 }
1090
1091 if (!(list->hid_debug_buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_KERNEL))) {
1092 err = -ENOMEM;
Julia Lawalla809dda2009-08-08 02:26:10 +02001093 kfree(list);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001094 goto out;
1095 }
1096 list->hdev = (struct hid_device *) inode->i_private;
1097 file->private_data = list;
1098 mutex_init(&list->read_mutex);
1099
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001100 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001101 list_add_tail(&list->node, &list->hdev->debug_list);
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001102 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001103
1104out:
1105 return err;
1106}
1107
1108static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
1109 size_t count, loff_t *ppos)
1110{
1111 struct hid_debug_list *list = file->private_data;
1112 int ret = 0, len;
1113 DECLARE_WAITQUEUE(wait, current);
1114
Julia Lawallca9fe152010-06-20 13:24:35 +02001115 mutex_lock(&list->read_mutex);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001116 while (ret == 0) {
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001117 if (list->head == list->tail) {
1118 add_wait_queue(&list->hdev->debug_wait, &wait);
1119 set_current_state(TASK_INTERRUPTIBLE);
1120
1121 while (list->head == list->tail) {
1122 if (file->f_flags & O_NONBLOCK) {
1123 ret = -EAGAIN;
1124 break;
1125 }
1126 if (signal_pending(current)) {
1127 ret = -ERESTARTSYS;
1128 break;
1129 }
1130
1131 if (!list->hdev || !list->hdev->debug) {
1132 ret = -EIO;
Jiri Kosina8fec02a72015-04-09 13:32:35 +02001133 set_current_state(TASK_RUNNING);
1134 goto out;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001135 }
1136
1137 /* allow O_NONBLOCK from other threads */
1138 mutex_unlock(&list->read_mutex);
1139 schedule();
1140 mutex_lock(&list->read_mutex);
1141 set_current_state(TASK_INTERRUPTIBLE);
1142 }
1143
1144 set_current_state(TASK_RUNNING);
1145 remove_wait_queue(&list->hdev->debug_wait, &wait);
1146 }
1147
1148 if (ret)
1149 goto out;
1150
1151 /* pass the ringbuffer contents to userspace */
1152copy_rest:
1153 if (list->tail == list->head)
1154 goto out;
1155 if (list->tail > list->head) {
1156 len = list->tail - list->head;
1157
1158 if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) {
1159 ret = -EFAULT;
1160 goto out;
1161 }
1162 ret += len;
1163 list->head += len;
1164 } else {
1165 len = HID_DEBUG_BUFSIZE - list->head;
1166
1167 if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) {
1168 ret = -EFAULT;
1169 goto out;
1170 }
1171 list->head = 0;
1172 ret += len;
1173 goto copy_rest;
1174 }
1175
1176 }
1177out:
1178 mutex_unlock(&list->read_mutex);
1179 return ret;
1180}
1181
1182static unsigned int hid_debug_events_poll(struct file *file, poll_table *wait)
1183{
1184 struct hid_debug_list *list = file->private_data;
1185
1186 poll_wait(file, &list->hdev->debug_wait, wait);
1187 if (list->head != list->tail)
1188 return POLLIN | POLLRDNORM;
1189 if (!list->hdev->debug)
1190 return POLLERR | POLLHUP;
1191 return 0;
1192}
1193
1194static int hid_debug_events_release(struct inode *inode, struct file *file)
1195{
1196 struct hid_debug_list *list = file->private_data;
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001197 unsigned long flags;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001198
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001199 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001200 list_del(&list->node);
Jiri Kosina1deb9d32013-05-06 13:05:50 +02001201 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001202 kfree(list->hid_debug_buf);
1203 kfree(list);
1204
1205 return 0;
1206}
1207
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001208static const struct file_operations hid_debug_rdesc_fops = {
1209 .open = hid_debug_rdesc_open,
1210 .read = seq_read,
1211 .llseek = seq_lseek,
1212 .release = single_release,
1213};
1214
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001215static const struct file_operations hid_debug_events_fops = {
1216 .owner = THIS_MODULE,
1217 .open = hid_debug_events_open,
1218 .read = hid_debug_events_read,
1219 .poll = hid_debug_events_poll,
1220 .release = hid_debug_events_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001221 .llseek = noop_llseek,
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001222};
1223
1224
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001225void hid_debug_register(struct hid_device *hdev, const char *name)
1226{
1227 hdev->debug_dir = debugfs_create_dir(name, hid_debug_root);
1228 hdev->debug_rdesc = debugfs_create_file("rdesc", 0400,
1229 hdev->debug_dir, hdev, &hid_debug_rdesc_fops);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001230 hdev->debug_events = debugfs_create_file("events", 0400,
1231 hdev->debug_dir, hdev, &hid_debug_events_fops);
1232 hdev->debug = 1;
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001233}
1234
1235void hid_debug_unregister(struct hid_device *hdev)
1236{
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001237 hdev->debug = 0;
1238 wake_up_interruptible(&hdev->debug_wait);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001239 debugfs_remove(hdev->debug_rdesc);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001240 debugfs_remove(hdev->debug_events);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001241 debugfs_remove(hdev->debug_dir);
1242}
1243
1244void hid_debug_init(void)
1245{
1246 hid_debug_root = debugfs_create_dir("hid", NULL);
1247}
1248
1249void hid_debug_exit(void)
1250{
1251 debugfs_remove_recursive(hid_debug_root);
1252}
1253