hid-debug.c 36 KB

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