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