hid.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. /*
  2. * Copyright (c) 1999 Andreas Gal
  3. * Copyright (c) 2000-2001 Vojtech Pavlik
  4. * Copyright (c) 2006-2007 Jiri Kosina
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * Should you need to contact me, the author, you can do so either by
  22. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  23. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  24. */
  25. #ifndef __HID_H
  26. #define __HID_H
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/list.h>
  30. #include <linux/mod_devicetable.h> /* hid_device_id */
  31. #include <linux/timer.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/input.h>
  34. #include <linux/semaphore.h>
  35. #include <linux/power_supply.h>
  36. #include <uapi/linux/hid.h>
  37. /*
  38. * We parse each description item into this structure. Short items data
  39. * values are expanded to 32-bit signed int, long items contain a pointer
  40. * into the data area.
  41. */
  42. struct hid_item {
  43. unsigned format;
  44. __u8 size;
  45. __u8 type;
  46. __u8 tag;
  47. union {
  48. __u8 u8;
  49. __s8 s8;
  50. __u16 u16;
  51. __s16 s16;
  52. __u32 u32;
  53. __s32 s32;
  54. __u8 *longdata;
  55. } data;
  56. };
  57. /*
  58. * HID report item format
  59. */
  60. #define HID_ITEM_FORMAT_SHORT 0
  61. #define HID_ITEM_FORMAT_LONG 1
  62. /*
  63. * Special tag indicating long items
  64. */
  65. #define HID_ITEM_TAG_LONG 15
  66. /*
  67. * HID report descriptor item type (prefix bit 2,3)
  68. */
  69. #define HID_ITEM_TYPE_MAIN 0
  70. #define HID_ITEM_TYPE_GLOBAL 1
  71. #define HID_ITEM_TYPE_LOCAL 2
  72. #define HID_ITEM_TYPE_RESERVED 3
  73. /*
  74. * HID report descriptor main item tags
  75. */
  76. #define HID_MAIN_ITEM_TAG_INPUT 8
  77. #define HID_MAIN_ITEM_TAG_OUTPUT 9
  78. #define HID_MAIN_ITEM_TAG_FEATURE 11
  79. #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
  80. #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
  81. /*
  82. * HID report descriptor main item contents
  83. */
  84. #define HID_MAIN_ITEM_CONSTANT 0x001
  85. #define HID_MAIN_ITEM_VARIABLE 0x002
  86. #define HID_MAIN_ITEM_RELATIVE 0x004
  87. #define HID_MAIN_ITEM_WRAP 0x008
  88. #define HID_MAIN_ITEM_NONLINEAR 0x010
  89. #define HID_MAIN_ITEM_NO_PREFERRED 0x020
  90. #define HID_MAIN_ITEM_NULL_STATE 0x040
  91. #define HID_MAIN_ITEM_VOLATILE 0x080
  92. #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
  93. /*
  94. * HID report descriptor collection item types
  95. */
  96. #define HID_COLLECTION_PHYSICAL 0
  97. #define HID_COLLECTION_APPLICATION 1
  98. #define HID_COLLECTION_LOGICAL 2
  99. /*
  100. * HID report descriptor global item tags
  101. */
  102. #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
  103. #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
  104. #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
  105. #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
  106. #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
  107. #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
  108. #define HID_GLOBAL_ITEM_TAG_UNIT 6
  109. #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
  110. #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
  111. #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
  112. #define HID_GLOBAL_ITEM_TAG_PUSH 10
  113. #define HID_GLOBAL_ITEM_TAG_POP 11
  114. /*
  115. * HID report descriptor local item tags
  116. */
  117. #define HID_LOCAL_ITEM_TAG_USAGE 0
  118. #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
  119. #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
  120. #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
  121. #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
  122. #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
  123. #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
  124. #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
  125. #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
  126. #define HID_LOCAL_ITEM_TAG_DELIMITER 10
  127. /*
  128. * HID usage tables
  129. */
  130. #define HID_USAGE_PAGE 0xffff0000
  131. #define HID_UP_UNDEFINED 0x00000000
  132. #define HID_UP_GENDESK 0x00010000
  133. #define HID_UP_SIMULATION 0x00020000
  134. #define HID_UP_GENDEVCTRLS 0x00060000
  135. #define HID_UP_KEYBOARD 0x00070000
  136. #define HID_UP_LED 0x00080000
  137. #define HID_UP_BUTTON 0x00090000
  138. #define HID_UP_ORDINAL 0x000a0000
  139. #define HID_UP_CONSUMER 0x000c0000
  140. #define HID_UP_DIGITIZER 0x000d0000
  141. #define HID_UP_PID 0x000f0000
  142. #define HID_UP_HPVENDOR 0xff7f0000
  143. #define HID_UP_HPVENDOR2 0xff010000
  144. #define HID_UP_MSVENDOR 0xff000000
  145. #define HID_UP_CUSTOM 0x00ff0000
  146. #define HID_UP_LOGIVENDOR 0xffbc0000
  147. #define HID_UP_SENSOR 0x00200000
  148. #define HID_USAGE 0x0000ffff
  149. #define HID_GD_POINTER 0x00010001
  150. #define HID_GD_MOUSE 0x00010002
  151. #define HID_GD_JOYSTICK 0x00010004
  152. #define HID_GD_GAMEPAD 0x00010005
  153. #define HID_GD_KEYBOARD 0x00010006
  154. #define HID_GD_KEYPAD 0x00010007
  155. #define HID_GD_MULTIAXIS 0x00010008
  156. #define HID_GD_X 0x00010030
  157. #define HID_GD_Y 0x00010031
  158. #define HID_GD_Z 0x00010032
  159. #define HID_GD_RX 0x00010033
  160. #define HID_GD_RY 0x00010034
  161. #define HID_GD_RZ 0x00010035
  162. #define HID_GD_SLIDER 0x00010036
  163. #define HID_GD_DIAL 0x00010037
  164. #define HID_GD_WHEEL 0x00010038
  165. #define HID_GD_HATSWITCH 0x00010039
  166. #define HID_GD_BUFFER 0x0001003a
  167. #define HID_GD_BYTECOUNT 0x0001003b
  168. #define HID_GD_MOTION 0x0001003c
  169. #define HID_GD_START 0x0001003d
  170. #define HID_GD_SELECT 0x0001003e
  171. #define HID_GD_VX 0x00010040
  172. #define HID_GD_VY 0x00010041
  173. #define HID_GD_VZ 0x00010042
  174. #define HID_GD_VBRX 0x00010043
  175. #define HID_GD_VBRY 0x00010044
  176. #define HID_GD_VBRZ 0x00010045
  177. #define HID_GD_VNO 0x00010046
  178. #define HID_GD_FEATURE 0x00010047
  179. #define HID_GD_SYSTEM_CONTROL 0x00010080
  180. #define HID_GD_UP 0x00010090
  181. #define HID_GD_DOWN 0x00010091
  182. #define HID_GD_RIGHT 0x00010092
  183. #define HID_GD_LEFT 0x00010093
  184. #define HID_DC_BATTERYSTRENGTH 0x00060020
  185. #define HID_CP_CONSUMER_CONTROL 0x000c0001
  186. #define HID_DG_DIGITIZER 0x000d0001
  187. #define HID_DG_PEN 0x000d0002
  188. #define HID_DG_LIGHTPEN 0x000d0003
  189. #define HID_DG_TOUCHSCREEN 0x000d0004
  190. #define HID_DG_TOUCHPAD 0x000d0005
  191. #define HID_DG_STYLUS 0x000d0020
  192. #define HID_DG_PUCK 0x000d0021
  193. #define HID_DG_FINGER 0x000d0022
  194. #define HID_DG_TIPPRESSURE 0x000d0030
  195. #define HID_DG_BARRELPRESSURE 0x000d0031
  196. #define HID_DG_INRANGE 0x000d0032
  197. #define HID_DG_TOUCH 0x000d0033
  198. #define HID_DG_UNTOUCH 0x000d0034
  199. #define HID_DG_TAP 0x000d0035
  200. #define HID_DG_TABLETFUNCTIONKEY 0x000d0039
  201. #define HID_DG_PROGRAMCHANGEKEY 0x000d003a
  202. #define HID_DG_INVERT 0x000d003c
  203. #define HID_DG_TIPSWITCH 0x000d0042
  204. #define HID_DG_TIPSWITCH2 0x000d0043
  205. #define HID_DG_BARRELSWITCH 0x000d0044
  206. #define HID_DG_ERASER 0x000d0045
  207. #define HID_DG_TABLETPICK 0x000d0046
  208. /*
  209. * as of May 20, 2009 the usages below are not yet in the official USB spec
  210. * but are being pushed by Microsft as described in their paper "Digitizer
  211. * Drivers for Windows Touch and Pen-Based Computers"
  212. */
  213. #define HID_DG_CONFIDENCE 0x000d0047
  214. #define HID_DG_WIDTH 0x000d0048
  215. #define HID_DG_HEIGHT 0x000d0049
  216. #define HID_DG_CONTACTID 0x000d0051
  217. #define HID_DG_INPUTMODE 0x000d0052
  218. #define HID_DG_DEVICEINDEX 0x000d0053
  219. #define HID_DG_CONTACTCOUNT 0x000d0054
  220. #define HID_DG_CONTACTMAX 0x000d0055
  221. /*
  222. * HID report types --- Ouch! HID spec says 1 2 3!
  223. */
  224. #define HID_INPUT_REPORT 0
  225. #define HID_OUTPUT_REPORT 1
  226. #define HID_FEATURE_REPORT 2
  227. #define HID_REPORT_TYPES 3
  228. /*
  229. * HID connect requests
  230. */
  231. #define HID_CONNECT_HIDINPUT 0x01
  232. #define HID_CONNECT_HIDINPUT_FORCE 0x02
  233. #define HID_CONNECT_HIDRAW 0x04
  234. #define HID_CONNECT_HIDDEV 0x08
  235. #define HID_CONNECT_HIDDEV_FORCE 0x10
  236. #define HID_CONNECT_FF 0x20
  237. #define HID_CONNECT_DEFAULT (HID_CONNECT_HIDINPUT|HID_CONNECT_HIDRAW| \
  238. HID_CONNECT_HIDDEV|HID_CONNECT_FF)
  239. /*
  240. * HID device quirks.
  241. */
  242. /*
  243. * Increase this if you need to configure more HID quirks at module load time
  244. */
  245. #define MAX_USBHID_BOOT_QUIRKS 4
  246. #define HID_QUIRK_INVERT 0x00000001
  247. #define HID_QUIRK_NOTOUCH 0x00000002
  248. #define HID_QUIRK_IGNORE 0x00000004
  249. #define HID_QUIRK_NOGET 0x00000008
  250. #define HID_QUIRK_HIDDEV_FORCE 0x00000010
  251. #define HID_QUIRK_BADPAD 0x00000020
  252. #define HID_QUIRK_MULTI_INPUT 0x00000040
  253. #define HID_QUIRK_HIDINPUT_FORCE 0x00000080
  254. #define HID_QUIRK_NO_EMPTY_INPUT 0x00000100
  255. #define HID_QUIRK_NO_INIT_INPUT_REPORTS 0x00000200
  256. #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000
  257. #define HID_QUIRK_SKIP_OUTPUT_REPORT_ID 0x00020000
  258. #define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP 0x00040000
  259. #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000
  260. #define HID_QUIRK_NO_INIT_REPORTS 0x20000000
  261. #define HID_QUIRK_NO_IGNORE 0x40000000
  262. #define HID_QUIRK_NO_INPUT_SYNC 0x80000000
  263. /*
  264. * HID device groups
  265. */
  266. #define HID_GROUP_GENERIC 0x0001
  267. #define HID_GROUP_MULTITOUCH 0x0002
  268. #define HID_GROUP_SENSOR_HUB 0x0003
  269. #define HID_GROUP_MULTITOUCH_WIN_8 0x0004
  270. /*
  271. * This is the global environment of the parser. This information is
  272. * persistent for main-items. The global environment can be saved and
  273. * restored with PUSH/POP statements.
  274. */
  275. struct hid_global {
  276. unsigned usage_page;
  277. __s32 logical_minimum;
  278. __s32 logical_maximum;
  279. __s32 physical_minimum;
  280. __s32 physical_maximum;
  281. __s32 unit_exponent;
  282. unsigned unit;
  283. unsigned report_id;
  284. unsigned report_size;
  285. unsigned report_count;
  286. };
  287. /*
  288. * This is the local environment. It is persistent up the next main-item.
  289. */
  290. #define HID_MAX_USAGES 12288
  291. #define HID_DEFAULT_NUM_COLLECTIONS 16
  292. struct hid_local {
  293. unsigned usage[HID_MAX_USAGES]; /* usage array */
  294. unsigned collection_index[HID_MAX_USAGES]; /* collection index array */
  295. unsigned usage_index;
  296. unsigned usage_minimum;
  297. unsigned delimiter_depth;
  298. unsigned delimiter_branch;
  299. };
  300. /*
  301. * This is the collection stack. We climb up the stack to determine
  302. * application and function of each field.
  303. */
  304. struct hid_collection {
  305. unsigned type;
  306. unsigned usage;
  307. unsigned level;
  308. };
  309. struct hid_usage {
  310. unsigned hid; /* hid usage code */
  311. unsigned collection_index; /* index into collection array */
  312. unsigned usage_index; /* index into usage array */
  313. /* hidinput data */
  314. __u16 code; /* input driver code */
  315. __u8 type; /* input driver type */
  316. __s8 hat_min; /* hat switch fun */
  317. __s8 hat_max; /* ditto */
  318. __s8 hat_dir; /* ditto */
  319. };
  320. struct hid_input;
  321. struct hid_field {
  322. unsigned physical; /* physical usage for this field */
  323. unsigned logical; /* logical usage for this field */
  324. unsigned application; /* application usage for this field */
  325. struct hid_usage *usage; /* usage table for this function */
  326. unsigned maxusage; /* maximum usage index */
  327. unsigned flags; /* main-item flags (i.e. volatile,array,constant) */
  328. unsigned report_offset; /* bit offset in the report */
  329. unsigned report_size; /* size of this field in the report */
  330. unsigned report_count; /* number of this field in the report */
  331. unsigned report_type; /* (input,output,feature) */
  332. __s32 *value; /* last known value(s) */
  333. __s32 logical_minimum;
  334. __s32 logical_maximum;
  335. __s32 physical_minimum;
  336. __s32 physical_maximum;
  337. __s32 unit_exponent;
  338. unsigned unit;
  339. struct hid_report *report; /* associated report */
  340. unsigned index; /* index into report->field[] */
  341. /* hidinput data */
  342. struct hid_input *hidinput; /* associated input structure */
  343. __u16 dpad; /* dpad input code */
  344. };
  345. #define HID_MAX_FIELDS 256
  346. struct hid_report {
  347. struct list_head list;
  348. unsigned id; /* id of this report */
  349. unsigned type; /* report type */
  350. struct hid_field *field[HID_MAX_FIELDS]; /* fields of the report */
  351. unsigned maxfield; /* maximum valid field index */
  352. unsigned size; /* size of the report (bits) */
  353. struct hid_device *device; /* associated device */
  354. };
  355. #define HID_MAX_IDS 256
  356. struct hid_report_enum {
  357. unsigned numbered;
  358. struct list_head report_list;
  359. struct hid_report *report_id_hash[HID_MAX_IDS];
  360. };
  361. #define HID_MIN_BUFFER_SIZE 64 /* make sure there is at least a packet size of space */
  362. #define HID_MAX_BUFFER_SIZE 4096 /* 4kb */
  363. #define HID_CONTROL_FIFO_SIZE 256 /* to init devices with >100 reports */
  364. #define HID_OUTPUT_FIFO_SIZE 64
  365. struct hid_control_fifo {
  366. unsigned char dir;
  367. struct hid_report *report;
  368. char *raw_report;
  369. };
  370. struct hid_output_fifo {
  371. struct hid_report *report;
  372. char *raw_report;
  373. };
  374. #define HID_CLAIMED_INPUT 1
  375. #define HID_CLAIMED_HIDDEV 2
  376. #define HID_CLAIMED_HIDRAW 4
  377. #define HID_STAT_ADDED 1
  378. #define HID_STAT_PARSED 2
  379. struct hid_input {
  380. struct list_head list;
  381. struct hid_report *report;
  382. struct input_dev *input;
  383. };
  384. enum hid_type {
  385. HID_TYPE_OTHER = 0,
  386. HID_TYPE_USBMOUSE,
  387. HID_TYPE_USBNONE
  388. };
  389. struct hid_driver;
  390. struct hid_ll_driver;
  391. struct hid_device { /* device report descriptor */
  392. __u8 *dev_rdesc;
  393. unsigned dev_rsize;
  394. __u8 *rdesc;
  395. unsigned rsize;
  396. struct hid_collection *collection; /* List of HID collections */
  397. unsigned collection_size; /* Number of allocated hid_collections */
  398. unsigned maxcollection; /* Number of parsed collections */
  399. unsigned maxapplication; /* Number of applications */
  400. __u16 bus; /* BUS ID */
  401. __u16 group; /* Report group */
  402. __u32 vendor; /* Vendor ID */
  403. __u32 product; /* Product ID */
  404. __u32 version; /* HID version */
  405. enum hid_type type; /* device type (mouse, kbd, ...) */
  406. unsigned country; /* HID country */
  407. struct hid_report_enum report_enum[HID_REPORT_TYPES];
  408. struct work_struct led_work; /* delayed LED worker */
  409. struct semaphore driver_lock; /* protects the current driver, except during input */
  410. struct semaphore driver_input_lock; /* protects the current driver */
  411. struct device dev; /* device */
  412. struct hid_driver *driver;
  413. struct hid_ll_driver *ll_driver;
  414. #ifdef CONFIG_HID_BATTERY_STRENGTH
  415. /*
  416. * Power supply information for HID devices which report
  417. * battery strength. power_supply is registered iff
  418. * battery.name is non-NULL.
  419. */
  420. struct power_supply battery;
  421. __s32 battery_min;
  422. __s32 battery_max;
  423. __s32 battery_report_type;
  424. __s32 battery_report_id;
  425. #endif
  426. unsigned int status; /* see STAT flags above */
  427. unsigned claimed; /* Claimed by hidinput, hiddev? */
  428. unsigned quirks; /* Various quirks the device can pull on us */
  429. bool io_started; /* Protected by driver_lock. If IO has started */
  430. struct list_head inputs; /* The list of inputs */
  431. void *hiddev; /* The hiddev structure */
  432. void *hidraw;
  433. int minor; /* Hiddev minor number */
  434. int open; /* is the device open by anyone? */
  435. char name[128]; /* Device name */
  436. char phys[64]; /* Device physical location */
  437. char uniq[64]; /* Device unique identifier (serial #) */
  438. void *driver_data;
  439. /* temporary hid_ff handling (until moved to the drivers) */
  440. int (*ff_init)(struct hid_device *);
  441. /* hiddev event handler */
  442. int (*hiddev_connect)(struct hid_device *, unsigned int);
  443. void (*hiddev_disconnect)(struct hid_device *);
  444. void (*hiddev_hid_event) (struct hid_device *, struct hid_field *field,
  445. struct hid_usage *, __s32);
  446. void (*hiddev_report_event) (struct hid_device *, struct hid_report *);
  447. /* debugging support via debugfs */
  448. unsigned short debug;
  449. struct dentry *debug_dir;
  450. struct dentry *debug_rdesc;
  451. struct dentry *debug_events;
  452. struct list_head debug_list;
  453. spinlock_t debug_list_lock;
  454. wait_queue_head_t debug_wait;
  455. };
  456. static inline void *hid_get_drvdata(struct hid_device *hdev)
  457. {
  458. return dev_get_drvdata(&hdev->dev);
  459. }
  460. static inline void hid_set_drvdata(struct hid_device *hdev, void *data)
  461. {
  462. dev_set_drvdata(&hdev->dev, data);
  463. }
  464. #define HID_GLOBAL_STACK_SIZE 4
  465. #define HID_COLLECTION_STACK_SIZE 4
  466. #define HID_SCAN_FLAG_MT_WIN_8 0x00000001
  467. struct hid_parser {
  468. struct hid_global global;
  469. struct hid_global global_stack[HID_GLOBAL_STACK_SIZE];
  470. unsigned global_stack_ptr;
  471. struct hid_local local;
  472. unsigned collection_stack[HID_COLLECTION_STACK_SIZE];
  473. unsigned collection_stack_ptr;
  474. struct hid_device *device;
  475. unsigned scan_flags;
  476. };
  477. struct hid_class_descriptor {
  478. __u8 bDescriptorType;
  479. __le16 wDescriptorLength;
  480. } __attribute__ ((packed));
  481. struct hid_descriptor {
  482. __u8 bLength;
  483. __u8 bDescriptorType;
  484. __le16 bcdHID;
  485. __u8 bCountryCode;
  486. __u8 bNumDescriptors;
  487. struct hid_class_descriptor desc[1];
  488. } __attribute__ ((packed));
  489. #define HID_DEVICE(b, g, ven, prod) \
  490. .bus = (b), .group = (g), .vendor = (ven), .product = (prod)
  491. #define HID_USB_DEVICE(ven, prod) \
  492. .bus = BUS_USB, .vendor = (ven), .product = (prod)
  493. #define HID_BLUETOOTH_DEVICE(ven, prod) \
  494. .bus = BUS_BLUETOOTH, .vendor = (ven), .product = (prod)
  495. #define HID_I2C_DEVICE(ven, prod) \
  496. .bus = BUS_I2C, .vendor = (ven), .product = (prod)
  497. #define HID_REPORT_ID(rep) \
  498. .report_type = (rep)
  499. #define HID_USAGE_ID(uhid, utype, ucode) \
  500. .usage_hid = (uhid), .usage_type = (utype), .usage_code = (ucode)
  501. /* we don't want to catch types and codes equal to 0 */
  502. #define HID_TERMINATOR (HID_ANY_ID - 1)
  503. struct hid_report_id {
  504. __u32 report_type;
  505. };
  506. struct hid_usage_id {
  507. __u32 usage_hid;
  508. __u32 usage_type;
  509. __u32 usage_code;
  510. };
  511. /**
  512. * struct hid_driver
  513. * @name: driver name (e.g. "Footech_bar-wheel")
  514. * @id_table: which devices is this driver for (must be non-NULL for probe
  515. * to be called)
  516. * @dyn_list: list of dynamically added device ids
  517. * @dyn_lock: lock protecting @dyn_list
  518. * @probe: new device inserted
  519. * @remove: device removed (NULL if not a hot-plug capable driver)
  520. * @report_table: on which reports to call raw_event (NULL means all)
  521. * @raw_event: if report in report_table, this hook is called (NULL means nop)
  522. * @usage_table: on which events to call event (NULL means all)
  523. * @event: if usage in usage_table, this hook is called (NULL means nop)
  524. * @report: this hook is called after parsing a report (NULL means nop)
  525. * @report_fixup: called before report descriptor parsing (NULL means nop)
  526. * @input_mapping: invoked on input registering before mapping an usage
  527. * @input_mapped: invoked on input registering after mapping an usage
  528. * @input_configured: invoked just before the device is registered
  529. * @feature_mapping: invoked on feature registering
  530. * @suspend: invoked on suspend (NULL means nop)
  531. * @resume: invoked on resume if device was not reset (NULL means nop)
  532. * @reset_resume: invoked on resume if device was reset (NULL means nop)
  533. *
  534. * probe should return -errno on error, or 0 on success. During probe,
  535. * input will not be passed to raw_event unless hid_device_io_start is
  536. * called.
  537. *
  538. * raw_event and event should return 0 on no action performed, 1 when no
  539. * further processing should be done and negative on error
  540. *
  541. * input_mapping shall return a negative value to completely ignore this usage
  542. * (e.g. doubled or invalid usage), zero to continue with parsing of this
  543. * usage by generic code (no special handling needed) or positive to skip
  544. * generic parsing (needed special handling which was done in the hook already)
  545. * input_mapped shall return negative to inform the layer that this usage
  546. * should not be considered for further processing or zero to notify that
  547. * no processing was performed and should be done in a generic manner
  548. * Both these functions may be NULL which means the same behavior as returning
  549. * zero from them.
  550. */
  551. struct hid_driver {
  552. char *name;
  553. const struct hid_device_id *id_table;
  554. struct list_head dyn_list;
  555. spinlock_t dyn_lock;
  556. int (*probe)(struct hid_device *dev, const struct hid_device_id *id);
  557. void (*remove)(struct hid_device *dev);
  558. const struct hid_report_id *report_table;
  559. int (*raw_event)(struct hid_device *hdev, struct hid_report *report,
  560. u8 *data, int size);
  561. const struct hid_usage_id *usage_table;
  562. int (*event)(struct hid_device *hdev, struct hid_field *field,
  563. struct hid_usage *usage, __s32 value);
  564. void (*report)(struct hid_device *hdev, struct hid_report *report);
  565. __u8 *(*report_fixup)(struct hid_device *hdev, __u8 *buf,
  566. unsigned int *size);
  567. int (*input_mapping)(struct hid_device *hdev,
  568. struct hid_input *hidinput, struct hid_field *field,
  569. struct hid_usage *usage, unsigned long **bit, int *max);
  570. int (*input_mapped)(struct hid_device *hdev,
  571. struct hid_input *hidinput, struct hid_field *field,
  572. struct hid_usage *usage, unsigned long **bit, int *max);
  573. void (*input_configured)(struct hid_device *hdev,
  574. struct hid_input *hidinput);
  575. void (*feature_mapping)(struct hid_device *hdev,
  576. struct hid_field *field,
  577. struct hid_usage *usage);
  578. #ifdef CONFIG_PM
  579. int (*suspend)(struct hid_device *hdev, pm_message_t message);
  580. int (*resume)(struct hid_device *hdev);
  581. int (*reset_resume)(struct hid_device *hdev);
  582. #endif
  583. /* private: */
  584. struct device_driver driver;
  585. };
  586. /**
  587. * hid_ll_driver - low level driver callbacks
  588. * @start: called on probe to start the device
  589. * @stop: called on remove
  590. * @open: called by input layer on open
  591. * @close: called by input layer on close
  592. * @parse: this method is called only once to parse the device data,
  593. * shouldn't allocate anything to not leak memory
  594. * @request: send report request to device (e.g. feature report)
  595. * @wait: wait for buffered io to complete (send/recv reports)
  596. * @raw_request: send raw report request to device (e.g. feature report)
  597. * @output_report: send output report to device
  598. * @idle: send idle request to device
  599. */
  600. struct hid_ll_driver {
  601. int (*start)(struct hid_device *hdev);
  602. void (*stop)(struct hid_device *hdev);
  603. int (*open)(struct hid_device *hdev);
  604. void (*close)(struct hid_device *hdev);
  605. int (*power)(struct hid_device *hdev, int level);
  606. int (*parse)(struct hid_device *hdev);
  607. void (*request)(struct hid_device *hdev,
  608. struct hid_report *report, int reqtype);
  609. int (*wait)(struct hid_device *hdev);
  610. int (*raw_request) (struct hid_device *hdev, unsigned char reportnum,
  611. __u8 *buf, size_t len, unsigned char rtype,
  612. int reqtype);
  613. int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len);
  614. int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype);
  615. };
  616. #define PM_HINT_FULLON 1<<5
  617. #define PM_HINT_NORMAL 1<<1
  618. /* Applications from HID Usage Tables 4/8/99 Version 1.1 */
  619. /* We ignore a few input applications that are not widely used */
  620. #define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || (a == 0x000c0001) || ((a >= 0x000d0002) && (a <= 0x000d0006)))
  621. /* HID core API */
  622. extern int hid_debug;
  623. extern bool hid_ignore(struct hid_device *);
  624. extern int hid_add_device(struct hid_device *);
  625. extern void hid_destroy_device(struct hid_device *);
  626. extern int __must_check __hid_register_driver(struct hid_driver *,
  627. struct module *, const char *mod_name);
  628. /* use a define to avoid include chaining to get THIS_MODULE & friends */
  629. #define hid_register_driver(driver) \
  630. __hid_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
  631. extern void hid_unregister_driver(struct hid_driver *);
  632. /**
  633. * module_hid_driver() - Helper macro for registering a HID driver
  634. * @__hid_driver: hid_driver struct
  635. *
  636. * Helper macro for HID drivers which do not do anything special in module
  637. * init/exit. This eliminates a lot of boilerplate. Each module may only
  638. * use this macro once, and calling it replaces module_init() and module_exit()
  639. */
  640. #define module_hid_driver(__hid_driver) \
  641. module_driver(__hid_driver, hid_register_driver, \
  642. hid_unregister_driver)
  643. extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32);
  644. extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report);
  645. extern int hidinput_connect(struct hid_device *hid, unsigned int force);
  646. extern void hidinput_disconnect(struct hid_device *);
  647. int hid_set_field(struct hid_field *, unsigned, __s32);
  648. int hid_input_report(struct hid_device *, int type, u8 *, int, int);
  649. int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field);
  650. struct hid_field *hidinput_get_led_field(struct hid_device *hid);
  651. unsigned int hidinput_count_leds(struct hid_device *hid);
  652. __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code);
  653. void hid_output_report(struct hid_report *report, __u8 *data);
  654. void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype);
  655. u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags);
  656. struct hid_device *hid_allocate_device(void);
  657. struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
  658. int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
  659. struct hid_report *hid_validate_values(struct hid_device *hid,
  660. unsigned int type, unsigned int id,
  661. unsigned int field_index,
  662. unsigned int report_counts);
  663. int hid_open_report(struct hid_device *device);
  664. int hid_check_keys_pressed(struct hid_device *hid);
  665. int hid_connect(struct hid_device *hid, unsigned int connect_mask);
  666. void hid_disconnect(struct hid_device *hid);
  667. const struct hid_device_id *hid_match_id(struct hid_device *hdev,
  668. const struct hid_device_id *id);
  669. s32 hid_snto32(__u32 value, unsigned n);
  670. /**
  671. * hid_device_io_start - enable HID input during probe, remove
  672. *
  673. * @hid - the device
  674. *
  675. * This should only be called during probe or remove and only be
  676. * called by the thread calling probe or remove. It will allow
  677. * incoming packets to be delivered to the driver.
  678. */
  679. static inline void hid_device_io_start(struct hid_device *hid) {
  680. if (hid->io_started) {
  681. dev_warn(&hid->dev, "io already started");
  682. return;
  683. }
  684. hid->io_started = true;
  685. up(&hid->driver_input_lock);
  686. }
  687. /**
  688. * hid_device_io_stop - disable HID input during probe, remove
  689. *
  690. * @hid - the device
  691. *
  692. * Should only be called after hid_device_io_start. It will prevent
  693. * incoming packets from going to the driver for the duration of
  694. * probe, remove. If called during probe, packets will still go to the
  695. * driver after probe is complete. This function should only be called
  696. * by the thread calling probe or remove.
  697. */
  698. static inline void hid_device_io_stop(struct hid_device *hid) {
  699. if (!hid->io_started) {
  700. dev_warn(&hid->dev, "io already stopped");
  701. return;
  702. }
  703. hid->io_started = false;
  704. down(&hid->driver_input_lock);
  705. }
  706. /**
  707. * hid_map_usage - map usage input bits
  708. *
  709. * @hidinput: hidinput which we are interested in
  710. * @usage: usage to fill in
  711. * @bit: pointer to input->{}bit (out parameter)
  712. * @max: maximal valid usage->code to consider later (out parameter)
  713. * @type: input event type (EV_KEY, EV_REL, ...)
  714. * @c: code which corresponds to this usage and type
  715. */
  716. static inline void hid_map_usage(struct hid_input *hidinput,
  717. struct hid_usage *usage, unsigned long **bit, int *max,
  718. __u8 type, __u16 c)
  719. {
  720. struct input_dev *input = hidinput->input;
  721. usage->type = type;
  722. usage->code = c;
  723. switch (type) {
  724. case EV_ABS:
  725. *bit = input->absbit;
  726. *max = ABS_MAX;
  727. break;
  728. case EV_REL:
  729. *bit = input->relbit;
  730. *max = REL_MAX;
  731. break;
  732. case EV_KEY:
  733. *bit = input->keybit;
  734. *max = KEY_MAX;
  735. break;
  736. case EV_LED:
  737. *bit = input->ledbit;
  738. *max = LED_MAX;
  739. break;
  740. }
  741. }
  742. /**
  743. * hid_map_usage_clear - map usage input bits and clear the input bit
  744. *
  745. * The same as hid_map_usage, except the @c bit is also cleared in supported
  746. * bits (@bit).
  747. */
  748. static inline void hid_map_usage_clear(struct hid_input *hidinput,
  749. struct hid_usage *usage, unsigned long **bit, int *max,
  750. __u8 type, __u16 c)
  751. {
  752. hid_map_usage(hidinput, usage, bit, max, type, c);
  753. clear_bit(c, *bit);
  754. }
  755. /**
  756. * hid_parse - parse HW reports
  757. *
  758. * @hdev: hid device
  759. *
  760. * Call this from probe after you set up the device (if needed). Your
  761. * report_fixup will be called (if non-NULL) after reading raw report from
  762. * device before passing it to hid layer for real parsing.
  763. */
  764. static inline int __must_check hid_parse(struct hid_device *hdev)
  765. {
  766. return hid_open_report(hdev);
  767. }
  768. /**
  769. * hid_hw_start - start underlaying HW
  770. *
  771. * @hdev: hid device
  772. * @connect_mask: which outputs to connect, see HID_CONNECT_*
  773. *
  774. * Call this in probe function *after* hid_parse. This will setup HW buffers
  775. * and start the device (if not deffered to device open). hid_hw_stop must be
  776. * called if this was successful.
  777. */
  778. static inline int __must_check hid_hw_start(struct hid_device *hdev,
  779. unsigned int connect_mask)
  780. {
  781. int ret = hdev->ll_driver->start(hdev);
  782. if (ret || !connect_mask)
  783. return ret;
  784. ret = hid_connect(hdev, connect_mask);
  785. if (ret)
  786. hdev->ll_driver->stop(hdev);
  787. return ret;
  788. }
  789. /**
  790. * hid_hw_stop - stop underlaying HW
  791. *
  792. * @hdev: hid device
  793. *
  794. * This is usually called from remove function or from probe when something
  795. * failed and hid_hw_start was called already.
  796. */
  797. static inline void hid_hw_stop(struct hid_device *hdev)
  798. {
  799. hid_disconnect(hdev);
  800. hdev->ll_driver->stop(hdev);
  801. }
  802. /**
  803. * hid_hw_open - signal underlaying HW to start delivering events
  804. *
  805. * @hdev: hid device
  806. *
  807. * Tell underlying HW to start delivering events from the device.
  808. * This function should be called sometime after successful call
  809. * to hid_hiw_start().
  810. */
  811. static inline int __must_check hid_hw_open(struct hid_device *hdev)
  812. {
  813. return hdev->ll_driver->open(hdev);
  814. }
  815. /**
  816. * hid_hw_close - signal underlaying HW to stop delivering events
  817. *
  818. * @hdev: hid device
  819. *
  820. * This function indicates that we are not interested in the events
  821. * from this device anymore. Delivery of events may or may not stop,
  822. * depending on the number of users still outstanding.
  823. */
  824. static inline void hid_hw_close(struct hid_device *hdev)
  825. {
  826. hdev->ll_driver->close(hdev);
  827. }
  828. /**
  829. * hid_hw_power - requests underlying HW to go into given power mode
  830. *
  831. * @hdev: hid device
  832. * @level: requested power level (one of %PM_HINT_* defines)
  833. *
  834. * This function requests underlying hardware to enter requested power
  835. * mode.
  836. */
  837. static inline int hid_hw_power(struct hid_device *hdev, int level)
  838. {
  839. return hdev->ll_driver->power ? hdev->ll_driver->power(hdev, level) : 0;
  840. }
  841. /**
  842. * hid_hw_request - send report request to device
  843. *
  844. * @hdev: hid device
  845. * @report: report to send
  846. * @reqtype: hid request type
  847. */
  848. static inline void hid_hw_request(struct hid_device *hdev,
  849. struct hid_report *report, int reqtype)
  850. {
  851. if (hdev->ll_driver->request)
  852. return hdev->ll_driver->request(hdev, report, reqtype);
  853. __hid_request(hdev, report, reqtype);
  854. }
  855. /**
  856. * hid_hw_raw_request - send report request to device
  857. *
  858. * @hdev: hid device
  859. * @reportnum: report ID
  860. * @buf: in/out data to transfer
  861. * @len: length of buf
  862. * @rtype: HID report type
  863. * @reqtype: HID_REQ_GET_REPORT or HID_REQ_SET_REPORT
  864. *
  865. * @return: count of data transfered, negative if error
  866. *
  867. * Same behavior as hid_hw_request, but with raw buffers instead.
  868. */
  869. static inline int hid_hw_raw_request(struct hid_device *hdev,
  870. unsigned char reportnum, __u8 *buf,
  871. size_t len, unsigned char rtype, int reqtype)
  872. {
  873. if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf)
  874. return -EINVAL;
  875. return hdev->ll_driver->raw_request(hdev, reportnum, buf, len,
  876. rtype, reqtype);
  877. }
  878. /**
  879. * hid_hw_output_report - send output report to device
  880. *
  881. * @hdev: hid device
  882. * @buf: raw data to transfer
  883. * @len: length of buf
  884. *
  885. * @return: count of data transfered, negative if error
  886. */
  887. static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf,
  888. size_t len)
  889. {
  890. if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf)
  891. return -EINVAL;
  892. if (hdev->ll_driver->output_report)
  893. return hdev->ll_driver->output_report(hdev, buf, len);
  894. return -ENOSYS;
  895. }
  896. /**
  897. * hid_hw_idle - send idle request to device
  898. *
  899. * @hdev: hid device
  900. * @report: report to control
  901. * @idle: idle state
  902. * @reqtype: hid request type
  903. */
  904. static inline int hid_hw_idle(struct hid_device *hdev, int report, int idle,
  905. int reqtype)
  906. {
  907. if (hdev->ll_driver->idle)
  908. return hdev->ll_driver->idle(hdev, report, idle, reqtype);
  909. return 0;
  910. }
  911. /**
  912. * hid_hw_wait - wait for buffered io to complete
  913. *
  914. * @hdev: hid device
  915. */
  916. static inline void hid_hw_wait(struct hid_device *hdev)
  917. {
  918. if (hdev->ll_driver->wait)
  919. hdev->ll_driver->wait(hdev);
  920. }
  921. int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
  922. int interrupt);
  923. /* HID quirks API */
  924. u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct);
  925. int usbhid_quirks_init(char **quirks_param);
  926. void usbhid_quirks_exit(void);
  927. #ifdef CONFIG_HID_PID
  928. int hid_pidff_init(struct hid_device *hid);
  929. #else
  930. #define hid_pidff_init NULL
  931. #endif
  932. #define dbg_hid(format, arg...) \
  933. do { \
  934. if (hid_debug) \
  935. printk(KERN_DEBUG "%s: " format, __FILE__, ##arg); \
  936. } while (0)
  937. #define hid_printk(level, hid, fmt, arg...) \
  938. dev_printk(level, &(hid)->dev, fmt, ##arg)
  939. #define hid_emerg(hid, fmt, arg...) \
  940. dev_emerg(&(hid)->dev, fmt, ##arg)
  941. #define hid_crit(hid, fmt, arg...) \
  942. dev_crit(&(hid)->dev, fmt, ##arg)
  943. #define hid_alert(hid, fmt, arg...) \
  944. dev_alert(&(hid)->dev, fmt, ##arg)
  945. #define hid_err(hid, fmt, arg...) \
  946. dev_err(&(hid)->dev, fmt, ##arg)
  947. #define hid_notice(hid, fmt, arg...) \
  948. dev_notice(&(hid)->dev, fmt, ##arg)
  949. #define hid_warn(hid, fmt, arg...) \
  950. dev_warn(&(hid)->dev, fmt, ##arg)
  951. #define hid_info(hid, fmt, arg...) \
  952. dev_info(&(hid)->dev, fmt, ##arg)
  953. #define hid_dbg(hid, fmt, arg...) \
  954. dev_dbg(&(hid)->dev, fmt, ##arg)
  955. #endif