hid-debug.c 41 KB

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