hid.h 39 KB

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