ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / usb / input / hid-debug.h
1 /*
2  * $Id: hid-debug.h,v 1.8 2001/09/25 09:37:57 vojtech Exp $
3  *
4  *  (c) 1999 Andreas Gal                <gal@cs.uni-magdeburg.de>
5  *  (c) 2000-2001 Vojtech Pavlik        <vojtech@ucw.cz>
6  *
7  *  Some debug stuff for the HID parser.
8  */
9
10 /*
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  *
25  * Should you need to contact me, the author, you can do so either by
26  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
27  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
28  */
29
30 struct hid_usage_entry {
31         unsigned  page;
32         unsigned  usage;
33         char     *description;
34 };
35
36 static const struct hid_usage_entry hid_usage_table[] = {
37   {  0,      0, "Undefined" },
38   {  1,      0, "GenericDesktop" },
39     {0, 0x01, "Pointer"},
40     {0, 0x02, "Mouse"},
41     {0, 0x04, "Joystick"},
42     {0, 0x05, "GamePad"},
43     {0, 0x06, "Keyboard"},
44     {0, 0x07, "Keypad"},
45     {0, 0x08, "MultiAxis"},
46       {0, 0x30, "X"},
47       {0, 0x31, "Y"},
48       {0, 0x32, "Z"},
49       {0, 0x33, "Rx"},
50       {0, 0x34, "Ry"},
51       {0, 0x35, "Rz"},
52       {0, 0x36, "Slider"},
53       {0, 0x37, "Dial"},
54       {0, 0x38, "Wheel"},
55       {0, 0x39, "HatSwitch"},
56     {0, 0x3a, "CountedBuffer"},
57       {0, 0x3b, "ByteCount"},
58       {0, 0x3c, "MotionWakeup"},
59       {0, 0x3d, "Start"},
60       {0, 0x3e, "Select"},
61       {0, 0x40, "Vx"},
62       {0, 0x41, "Vy"},
63       {0, 0x42, "Vz"},
64       {0, 0x43, "Vbrx"},
65       {0, 0x44, "Vbry"},
66       {0, 0x45, "Vbrz"},
67       {0, 0x46, "Vno"},
68     {0, 0x80, "SystemControl"}, 
69       {0, 0x81, "SystemPowerDown"},
70       {0, 0x82, "SystemSleep"},
71       {0, 0x83, "SystemWakeUp"},
72       {0, 0x84, "SystemContextMenu"},
73       {0, 0x85, "SystemMainMenu"},
74       {0, 0x86, "SystemAppMenu"},
75       {0, 0x87, "SystemMenuHelp"},
76       {0, 0x88, "SystemMenuExit"},
77       {0, 0x89, "SystemMenuSelect"},
78       {0, 0x8a, "SystemMenuRight"},
79       {0, 0x8b, "SystemMenuLeft"},
80       {0, 0x8c, "SystemMenuUp"},
81       {0, 0x8d, "SystemMenuDown"},
82     {0, 0x90, "D-padUp"},
83     {0, 0x91, "D-padDown"},
84     {0, 0x92, "D-padRight"},
85     {0, 0x93, "D-padLeft"},
86   {  7, 0, "Keyboard" },
87   {  8, 0, "LED" },
88   {  9, 0, "Button" },
89   { 10, 0, "Ordinal" },
90   { 12, 0, "Hotkey" },
91   { 13, 0, "Digitizers" },
92     {0, 0x01, "Digitizer"},
93     {0, 0x02, "Pen"},
94     {0, 0x03, "LightPen"},
95     {0, 0x04, "TouchScreen"},
96     {0, 0x05, "TouchPad"},
97     {0, 0x20, "Stylus"},
98     {0, 0x21, "Puck"},
99     {0, 0x22, "Finger"},
100     {0, 0x30, "TipPressure"},
101     {0, 0x31, "BarrelPressure"},
102     {0, 0x32, "InRange"},
103     {0, 0x33, "Touch"},
104     {0, 0x34, "UnTouch"},
105     {0, 0x35, "Tap"},
106     {0, 0x39, "TabletFunctionKey"},
107     {0, 0x3a, "ProgramChangeKey"},
108     {0, 0x3c, "Invert"},
109     {0, 0x42, "TipSwitch"},
110     {0, 0x43, "SecondaryTipSwitch"},
111     {0, 0x44, "BarrelSwitch"},
112     {0, 0x45, "Eraser"},
113     {0, 0x46, "TabletPick"},
114   { 15, 0, "PhysicalInterfaceDevice" },
115     {0, 0x00, "Undefined"},
116     {0, 0x01, "Physical_Interface_Device"},
117       {0, 0x20, "Normal"},
118     {0, 0x21, "Set_Effect_Report"},
119       {0, 0x22, "Effect_Block_Index"},
120       {0, 0x23, "Parameter_Block_Offset"},
121       {0, 0x24, "ROM_Flag"},
122       {0, 0x25, "Effect_Type"},
123         {0, 0x26, "ET_Constant_Force"},
124         {0, 0x27, "ET_Ramp"},
125         {0, 0x28, "ET_Custom_Force_Data"},
126         {0, 0x30, "ET_Square"},
127         {0, 0x31, "ET_Sine"},
128         {0, 0x32, "ET_Triangle"},
129         {0, 0x33, "ET_Sawtooth_Up"},
130         {0, 0x34, "ET_Sawtooth_Down"},
131         {0, 0x40, "ET_Spring"},
132         {0, 0x41, "ET_Damper"},
133         {0, 0x42, "ET_Inertia"},
134         {0, 0x43, "ET_Friction"},
135       {0, 0x50, "Duration"},
136       {0, 0x51, "Sample_Period"},
137       {0, 0x52, "Gain"},
138       {0, 0x53, "Trigger_Button"},
139       {0, 0x54, "Trigger_Repeat_Interval"},
140       {0, 0x55, "Axes_Enable"},
141         {0, 0x56, "Direction_Enable"},
142       {0, 0x57, "Direction"},
143       {0, 0x58, "Type_Specific_Block_Offset"},
144         {0, 0x59, "Block_Type"},
145         {0, 0x5A, "Set_Envelope_Report"},
146           {0, 0x5B, "Attack_Level"},
147           {0, 0x5C, "Attack_Time"},
148           {0, 0x5D, "Fade_Level"},
149           {0, 0x5E, "Fade_Time"},
150         {0, 0x5F, "Set_Condition_Report"},
151         {0, 0x60, "CP_Offset"},
152         {0, 0x61, "Positive_Coefficient"},
153         {0, 0x62, "Negative_Coefficient"},
154         {0, 0x63, "Positive_Saturation"},
155         {0, 0x64, "Negative_Saturation"},
156         {0, 0x65, "Dead_Band"},
157       {0, 0x66, "Download_Force_Sample"},
158       {0, 0x67, "Isoch_Custom_Force_Enable"},
159       {0, 0x68, "Custom_Force_Data_Report"},
160         {0, 0x69, "Custom_Force_Data"},
161         {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
162       {0, 0x6B, "Set_Custom_Force_Report"},
163         {0, 0x6C, "Custom_Force_Data_Offset"},
164         {0, 0x6D, "Sample_Count"},
165       {0, 0x6E, "Set_Periodic_Report"},
166         {0, 0x6F, "Offset"},
167         {0, 0x70, "Magnitude"},
168         {0, 0x71, "Phase"},
169         {0, 0x72, "Period"},
170       {0, 0x73, "Set_Constant_Force_Report"},
171         {0, 0x74, "Set_Ramp_Force_Report"},
172         {0, 0x75, "Ramp_Start"},
173         {0, 0x76, "Ramp_End"},
174       {0, 0x77, "Effect_Operation_Report"},
175         {0, 0x78, "Effect_Operation"},
176           {0, 0x79, "Op_Effect_Start"},
177           {0, 0x7A, "Op_Effect_Start_Solo"},
178           {0, 0x7B, "Op_Effect_Stop"},
179           {0, 0x7C, "Loop_Count"},
180       {0, 0x7D, "Device_Gain_Report"},
181         {0, 0x7E, "Device_Gain"},
182     {0, 0x7F, "PID_Pool_Report"},
183       {0, 0x80, "RAM_Pool_Size"},
184       {0, 0x81, "ROM_Pool_Size"},
185       {0, 0x82, "ROM_Effect_Block_Count"},
186       {0, 0x83, "Simultaneous_Effects_Max"},
187       {0, 0x84, "Pool_Alignment"},
188     {0, 0x85, "PID_Pool_Move_Report"},
189       {0, 0x86, "Move_Source"},
190       {0, 0x87, "Move_Destination"},
191       {0, 0x88, "Move_Length"},
192     {0, 0x89, "PID_Block_Load_Report"},
193       {0, 0x8B, "Block_Load_Status"},
194       {0, 0x8C, "Block_Load_Success"},
195       {0, 0x8D, "Block_Load_Full"},
196       {0, 0x8E, "Block_Load_Error"},
197       {0, 0x8F, "Block_Handle"},
198       {0, 0x90, "PID_Block_Free_Report"},
199       {0, 0x91, "Type_Specific_Block_Handle"},
200     {0, 0x92, "PID_State_Report"},
201       {0, 0x94, "Effect_Playing"},
202       {0, 0x95, "PID_Device_Control_Report"},
203         {0, 0x96, "PID_Device_Control"},
204         {0, 0x97, "DC_Enable_Actuators"},
205         {0, 0x98, "DC_Disable_Actuators"},
206         {0, 0x99, "DC_Stop_All_Effects"},
207         {0, 0x9A, "DC_Device_Reset"},
208         {0, 0x9B, "DC_Device_Pause"},
209         {0, 0x9C, "DC_Device_Continue"},
210       {0, 0x9F, "Device_Paused"},
211       {0, 0xA0, "Actuators_Enabled"},
212       {0, 0xA4, "Safety_Switch"},
213       {0, 0xA5, "Actuator_Override_Switch"},
214       {0, 0xA6, "Actuator_Power"},
215     {0, 0xA7, "Start_Delay"},
216     {0, 0xA8, "Parameter_Block_Size"},
217     {0, 0xA9, "Device_Managed_Pool"},
218     {0, 0xAA, "Shared_Parameter_Blocks"},
219     {0, 0xAB, "Create_New_Effect_Report"},
220     {0, 0xAC, "RAM_Pool_Available"},
221   { 0x84, 0, "Power Device" },
222     { 0x84, 0x02, "PresentStatus" },
223     { 0x84, 0x03, "ChangeStatus" },
224     { 0x84, 0x04, "UPS" },
225     { 0x84, 0x05, "PowerSupply" },
226     { 0x84, 0x10, "BatterySystem" },
227     { 0x84, 0x11, "BatterySystemID" },
228     { 0x84, 0x12, "Battery" },
229     { 0x84, 0x13, "BatteryID" },
230     { 0x84, 0x14, "Charger" },
231     { 0x84, 0x15, "ChargerID" },
232     { 0x84, 0x16, "PowerConverter" },
233     { 0x84, 0x17, "PowerConverterID" },
234     { 0x84, 0x18, "OutletSystem" },
235     { 0x84, 0x19, "OutletSystemID" },
236     { 0x84, 0x1a, "Input" },
237     { 0x84, 0x1b, "InputID" },
238     { 0x84, 0x1c, "Output" },
239     { 0x84, 0x1d, "OutputID" },
240     { 0x84, 0x1e, "Flow" },
241     { 0x84, 0x1f, "FlowID" },
242     { 0x84, 0x20, "Outlet" },
243     { 0x84, 0x21, "OutletID" },
244     { 0x84, 0x22, "Gang" },
245     { 0x84, 0x24, "PowerSummary" },
246     { 0x84, 0x25, "PowerSummaryID" },
247     { 0x84, 0x30, "Voltage" },
248     { 0x84, 0x31, "Current" },
249     { 0x84, 0x32, "Frequency" },
250     { 0x84, 0x33, "ApparentPower" },
251     { 0x84, 0x35, "PercentLoad" },
252     { 0x84, 0x40, "ConfigVoltage" },
253     { 0x84, 0x41, "ConfigCurrent" },
254     { 0x84, 0x43, "ConfigApparentPower" },
255     { 0x84, 0x53, "LowVoltageTransfer" },
256     { 0x84, 0x54, "HighVoltageTransfer" },
257     { 0x84, 0x56, "DelayBeforeStartup" },
258     { 0x84, 0x57, "DelayBeforeShutdown" },
259     { 0x84, 0x58, "Test" },
260     { 0x84, 0x5a, "AudibleAlarmControl" },
261     { 0x84, 0x60, "Present" },
262     { 0x84, 0x61, "Good" },
263     { 0x84, 0x62, "InternalFailure" },
264     { 0x84, 0x65, "Overload" },
265     { 0x84, 0x66, "OverCharged" },
266     { 0x84, 0x67, "OverTemperature" },
267     { 0x84, 0x68, "ShutdownRequested" },
268     { 0x84, 0x69, "ShutdownImminent" },
269     { 0x84, 0x6b, "SwitchOn/Off" },
270     { 0x84, 0x6c, "Switchable" },
271     { 0x84, 0x6d, "Used" },
272     { 0x84, 0x6e, "Boost" },
273     { 0x84, 0x73, "CommunicationLost" },
274     { 0x84, 0xfd, "iManufacturer" },
275     { 0x84, 0xfe, "iProduct" },
276     { 0x84, 0xff, "iSerialNumber" },
277   { 0x85, 0, "Battery System" },
278     { 0x85, 0x01, "SMBBatteryMode" },
279     { 0x85, 0x02, "SMBBatteryStatus" },
280     { 0x85, 0x03, "SMBAlarmWarning" },
281     { 0x85, 0x04, "SMBChargerMode" },
282     { 0x85, 0x05, "SMBChargerStatus" },
283     { 0x85, 0x06, "SMBChargerSpecInfo" },
284     { 0x85, 0x07, "SMBSelectorState" },
285     { 0x85, 0x08, "SMBSelectorPresets" },
286     { 0x85, 0x09, "SMBSelectorInfo" },
287     { 0x85, 0x29, "RemainingCapacityLimit" },
288     { 0x85, 0x2c, "CapacityMode" },
289     { 0x85, 0x42, "BelowRemainingCapacityLimit" },
290     { 0x85, 0x44, "Charging" },
291     { 0x85, 0x45, "Discharging" },
292     { 0x85, 0x4b, "NeedReplacement" },
293     { 0x85, 0x66, "RemainingCapacity" },
294     { 0x85, 0x68, "RunTimeToEmpty" },
295     { 0x85, 0x6a, "AverageTimeToFull" },
296     { 0x85, 0x83, "DesignCapacity" },
297     { 0x85, 0x85, "ManufacturerDate" },
298     { 0x85, 0x89, "iDeviceChemistry" },
299     { 0x85, 0x8b, "Rechargable" },
300     { 0x85, 0x8f, "iOEMInformation" },
301     { 0x85, 0x8d, "CapacityGranularity1" },
302     { 0x85, 0xd0, "ACPresent" },
303   /* pages 0xff00 to 0xffff are vendor-specific */
304   { 0xffff, 0, "Vendor-specific-FF" },
305   { 0, 0, NULL }
306 };
307
308 static void resolv_usage_page(unsigned page) {
309         const struct hid_usage_entry *p;
310
311         for (p = hid_usage_table; p->description; p++)
312                 if (p->page == page) {
313                         printk("%s", p->description);
314                         return;
315                 }
316         printk("%04x", page);
317 }
318
319 static void resolv_usage(unsigned usage) {
320         const struct hid_usage_entry *p;
321
322         resolv_usage_page(usage >> 16);
323         printk(".");
324         for (p = hid_usage_table; p->description; p++)
325                 if (p->page == (usage >> 16)) {
326                         for(++p; p->description && p->page != 0; p++)
327                                 if (p->usage == (usage & 0xffff)) {
328                                         printk("%s", p->description);
329                                         return;
330                                 }
331                         break;
332                 }
333         printk("%04x", usage & 0xffff);
334 }
335
336 __inline__ static void tab(int n) {
337         while (n--) printk(" ");
338 }
339
340 static void hid_dump_field(struct hid_field *field, int n) {
341         int j;
342         
343         if (field->physical) {
344                 tab(n);
345                 printk("Physical(");
346                 resolv_usage(field->physical); printk(")\n");
347         }
348         if (field->logical) {
349                 tab(n);
350                 printk("Logical(");
351                 resolv_usage(field->logical); printk(")\n");
352         }
353         tab(n); printk("Usage(%d)\n", field->maxusage);
354         for (j = 0; j < field->maxusage; j++) {
355                 tab(n+2);resolv_usage(field->usage[j].hid); printk("\n");
356         }
357         if (field->logical_minimum != field->logical_maximum) {
358                 tab(n); printk("Logical Minimum(%d)\n", field->logical_minimum);
359                 tab(n); printk("Logical Maximum(%d)\n", field->logical_maximum);
360         }
361         if (field->physical_minimum != field->physical_maximum) {
362                 tab(n); printk("Physical Minimum(%d)\n", field->physical_minimum);
363                 tab(n); printk("Physical Maximum(%d)\n", field->physical_maximum);
364         }
365         if (field->unit_exponent) {
366                 tab(n); printk("Unit Exponent(%d)\n", field->unit_exponent);
367         }
368         if (field->unit) {
369                 char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
370                 char *units[5][8] = {
371                         { "None", "None", "None", "None", "None", "None", "None", "None" },
372                         { "None", "Centimeter", "Gram", "Seconds", "Kelvin",     "Ampere", "Candela", "None" },
373                         { "None", "Radians",    "Gram", "Seconds", "Kelvin",     "Ampere", "Candela", "None" },
374                         { "None", "Inch",       "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" },
375                         { "None", "Degrees",    "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }
376                 };
377
378                 int i;
379                 int sys;
380                 __u32 data = field->unit;
381
382                 /* First nibble tells us which system we're in. */
383                 sys = data & 0xf;
384                 data >>= 4;
385
386                 if(sys > 4) {
387                         tab(n); printk("Unit(Invalid)\n");
388                 }
389                 else {
390                         int earlier_unit = 0;
391
392                         tab(n); printk("Unit(%s : ", systems[sys]);
393
394                         for (i=1 ; i<sizeof(__u32)*2 ; i++) {
395                                 char nibble = data & 0xf;
396                                 data >>= 4;
397                                 if (nibble != 0) {
398                                         if(earlier_unit++ > 0)
399                                                 printk("*");
400                                         printk("%s", units[sys][i]);
401                                         if(nibble != 1) {
402                                                 /* This is a _signed_ nibble(!) */
403         
404                                                 int val = nibble & 0x7;
405                                                 if(nibble & 0x08)
406                                                         val = -((0x7 & ~val) +1);
407                                                 printk("^%d", val);
408                                         }
409                                 }
410                         }
411                         printk(")\n");
412                 }
413         }
414         tab(n); printk("Report Size(%u)\n", field->report_size);
415         tab(n); printk("Report Count(%u)\n", field->report_count);
416         tab(n); printk("Report Offset(%u)\n", field->report_offset);
417
418         tab(n); printk("Flags( ");
419         j = field->flags;
420         printk("%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
421         printk("%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
422         printk("%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
423         printk("%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
424         printk("%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
425         printk("%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPrefferedState " : "");
426         printk("%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
427         printk("%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
428         printk("%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
429         printk(")\n");
430 }
431
432 static void __attribute__((unused)) hid_dump_device(struct hid_device *device) {
433         struct hid_report_enum *report_enum;
434         struct hid_report *report;
435         struct list_head *list;
436         unsigned i,k;
437         static char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
438         
439         for (i = 0; i < HID_REPORT_TYPES; i++) {
440                 report_enum = device->report_enum + i;
441                 list = report_enum->report_list.next;
442                 while (list != &report_enum->report_list) {
443                         report = (struct hid_report *) list;
444                         tab(2);
445                         printk("%s", table[i]);
446                         if (report->id)
447                                 printk("(%d)", report->id);
448                         printk("[%s]", table[report->type]);
449                         printk("\n");
450                         for (k = 0; k < report->maxfield; k++) {
451                                 tab(4);
452                                 printk("Field(%d)\n", k);
453                                 hid_dump_field(report->field[k], 6);
454                         }
455                         list = list->next;
456                 }
457         }
458 }
459
460 static void __attribute__((unused)) hid_dump_input(struct hid_usage *usage, __s32 value) {
461         printk("hid-debug: input ");
462         resolv_usage(usage->hid);
463         printk(" = %d\n", value);
464 }