hid.h 36 KB

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