hid-debug.c 35 KB

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