hid.h 37 KB

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