Linux Audio

Check our new training course

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