hid-sony.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469
  1. /*
  2. * HID driver for Sony / PS2 / PS3 / PS4 BD devices.
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2008 Jiri Slaby
  8. * Copyright (c) 2012 David Dillow <dave@thedillows.org>
  9. * Copyright (c) 2006-2013 Jiri Kosina
  10. * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com>
  11. * Copyright (c) 2014 Frank Praznik <frank.praznik@gmail.com>
  12. */
  13. /*
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the Free
  16. * Software Foundation; either version 2 of the License, or (at your option)
  17. * any later version.
  18. */
  19. /*
  20. * NOTE: in order for the Sony PS3 BD Remote Control to be found by
  21. * a Bluetooth host, the key combination Start+Enter has to be kept pressed
  22. * for about 7 seconds with the Bluetooth Host Controller in discovering mode.
  23. *
  24. * There will be no PIN request from the device.
  25. */
  26. #include <linux/device.h>
  27. #include <linux/hid.h>
  28. #include <linux/module.h>
  29. #include <linux/slab.h>
  30. #include <linux/leds.h>
  31. #include <linux/power_supply.h>
  32. #include <linux/spinlock.h>
  33. #include <linux/list.h>
  34. #include <linux/idr.h>
  35. #include <linux/input/mt.h>
  36. #include "hid-ids.h"
  37. #define VAIO_RDESC_CONSTANT BIT(0)
  38. #define SIXAXIS_CONTROLLER_USB BIT(1)
  39. #define SIXAXIS_CONTROLLER_BT BIT(2)
  40. #define BUZZ_CONTROLLER BIT(3)
  41. #define PS3REMOTE BIT(4)
  42. #define DUALSHOCK4_CONTROLLER_USB BIT(5)
  43. #define DUALSHOCK4_CONTROLLER_BT BIT(6)
  44. #define MOTION_CONTROLLER_USB BIT(7)
  45. #define MOTION_CONTROLLER_BT BIT(8)
  46. #define NAVIGATION_CONTROLLER_USB BIT(9)
  47. #define NAVIGATION_CONTROLLER_BT BIT(10)
  48. #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)
  49. #define MOTION_CONTROLLER (MOTION_CONTROLLER_USB | MOTION_CONTROLLER_BT)
  50. #define NAVIGATION_CONTROLLER (NAVIGATION_CONTROLLER_USB |\
  51. NAVIGATION_CONTROLLER_BT)
  52. #define DUALSHOCK4_CONTROLLER (DUALSHOCK4_CONTROLLER_USB |\
  53. DUALSHOCK4_CONTROLLER_BT)
  54. #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\
  55. DUALSHOCK4_CONTROLLER | MOTION_CONTROLLER |\
  56. NAVIGATION_CONTROLLER)
  57. #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\
  58. MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER)
  59. #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\
  60. MOTION_CONTROLLER)
  61. #define MAX_LEDS 4
  62. /*
  63. * The Sixaxis reports both digital and analog values for each button on the
  64. * controller except for Start, Select and the PS button. The controller ends
  65. * up reporting 27 axes which causes them to spill over into the multi-touch
  66. * axis values. Additionally, the controller only has 20 actual, physical axes
  67. * so there are several unused axes in between the used ones.
  68. */
  69. static __u8 sixaxis_rdesc[] = {
  70. 0x05, 0x01, /* Usage Page (Desktop), */
  71. 0x09, 0x04, /* Usage (Joystick), */
  72. 0xA1, 0x01, /* Collection (Application), */
  73. 0xA1, 0x02, /* Collection (Logical), */
  74. 0x85, 0x01, /* Report ID (1), */
  75. 0x75, 0x08, /* Report Size (8), */
  76. 0x95, 0x01, /* Report Count (1), */
  77. 0x15, 0x00, /* Logical Minimum (0), */
  78. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  79. 0x81, 0x03, /* Input (Constant, Variable), */
  80. 0x75, 0x01, /* Report Size (1), */
  81. 0x95, 0x13, /* Report Count (19), */
  82. 0x15, 0x00, /* Logical Minimum (0), */
  83. 0x25, 0x01, /* Logical Maximum (1), */
  84. 0x35, 0x00, /* Physical Minimum (0), */
  85. 0x45, 0x01, /* Physical Maximum (1), */
  86. 0x05, 0x09, /* Usage Page (Button), */
  87. 0x19, 0x01, /* Usage Minimum (01h), */
  88. 0x29, 0x13, /* Usage Maximum (13h), */
  89. 0x81, 0x02, /* Input (Variable), */
  90. 0x75, 0x01, /* Report Size (1), */
  91. 0x95, 0x0D, /* Report Count (13), */
  92. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  93. 0x81, 0x03, /* Input (Constant, Variable), */
  94. 0x15, 0x00, /* Logical Minimum (0), */
  95. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  96. 0x05, 0x01, /* Usage Page (Desktop), */
  97. 0x09, 0x01, /* Usage (Pointer), */
  98. 0xA1, 0x00, /* Collection (Physical), */
  99. 0x75, 0x08, /* Report Size (8), */
  100. 0x95, 0x04, /* Report Count (4), */
  101. 0x35, 0x00, /* Physical Minimum (0), */
  102. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  103. 0x09, 0x30, /* Usage (X), */
  104. 0x09, 0x31, /* Usage (Y), */
  105. 0x09, 0x32, /* Usage (Z), */
  106. 0x09, 0x35, /* Usage (Rz), */
  107. 0x81, 0x02, /* Input (Variable), */
  108. 0xC0, /* End Collection, */
  109. 0x05, 0x01, /* Usage Page (Desktop), */
  110. 0x95, 0x13, /* Report Count (19), */
  111. 0x09, 0x01, /* Usage (Pointer), */
  112. 0x81, 0x02, /* Input (Variable), */
  113. 0x95, 0x0C, /* Report Count (12), */
  114. 0x81, 0x01, /* Input (Constant), */
  115. 0x75, 0x10, /* Report Size (16), */
  116. 0x95, 0x04, /* Report Count (4), */
  117. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  118. 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */
  119. 0x09, 0x01, /* Usage (Pointer), */
  120. 0x81, 0x02, /* Input (Variable), */
  121. 0xC0, /* End Collection, */
  122. 0xA1, 0x02, /* Collection (Logical), */
  123. 0x85, 0x02, /* Report ID (2), */
  124. 0x75, 0x08, /* Report Size (8), */
  125. 0x95, 0x30, /* Report Count (48), */
  126. 0x09, 0x01, /* Usage (Pointer), */
  127. 0xB1, 0x02, /* Feature (Variable), */
  128. 0xC0, /* End Collection, */
  129. 0xA1, 0x02, /* Collection (Logical), */
  130. 0x85, 0xEE, /* Report ID (238), */
  131. 0x75, 0x08, /* Report Size (8), */
  132. 0x95, 0x30, /* Report Count (48), */
  133. 0x09, 0x01, /* Usage (Pointer), */
  134. 0xB1, 0x02, /* Feature (Variable), */
  135. 0xC0, /* End Collection, */
  136. 0xA1, 0x02, /* Collection (Logical), */
  137. 0x85, 0xEF, /* Report ID (239), */
  138. 0x75, 0x08, /* Report Size (8), */
  139. 0x95, 0x30, /* Report Count (48), */
  140. 0x09, 0x01, /* Usage (Pointer), */
  141. 0xB1, 0x02, /* Feature (Variable), */
  142. 0xC0, /* End Collection, */
  143. 0xC0 /* End Collection */
  144. };
  145. /* PS/3 Motion controller */
  146. static __u8 motion_rdesc[] = {
  147. 0x05, 0x01, /* Usage Page (Desktop), */
  148. 0x09, 0x04, /* Usage (Joystick), */
  149. 0xA1, 0x01, /* Collection (Application), */
  150. 0xA1, 0x02, /* Collection (Logical), */
  151. 0x85, 0x01, /* Report ID (1), */
  152. 0x75, 0x01, /* Report Size (1), */
  153. 0x95, 0x15, /* Report Count (21), */
  154. 0x15, 0x00, /* Logical Minimum (0), */
  155. 0x25, 0x01, /* Logical Maximum (1), */
  156. 0x35, 0x00, /* Physical Minimum (0), */
  157. 0x45, 0x01, /* Physical Maximum (1), */
  158. 0x05, 0x09, /* Usage Page (Button), */
  159. 0x19, 0x01, /* Usage Minimum (01h), */
  160. 0x29, 0x15, /* Usage Maximum (15h), */
  161. 0x81, 0x02, /* Input (Variable), * Buttons */
  162. 0x95, 0x0B, /* Report Count (11), */
  163. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  164. 0x81, 0x03, /* Input (Constant, Variable), * Padding */
  165. 0x15, 0x00, /* Logical Minimum (0), */
  166. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  167. 0x05, 0x01, /* Usage Page (Desktop), */
  168. 0xA1, 0x00, /* Collection (Physical), */
  169. 0x75, 0x08, /* Report Size (8), */
  170. 0x95, 0x01, /* Report Count (1), */
  171. 0x35, 0x00, /* Physical Minimum (0), */
  172. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  173. 0x09, 0x30, /* Usage (X), */
  174. 0x81, 0x02, /* Input (Variable), * Trigger */
  175. 0xC0, /* End Collection, */
  176. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  177. 0x75, 0x08, /* Report Size (8), */
  178. 0x95, 0x07, /* Report Count (7), * skip 7 bytes */
  179. 0x81, 0x02, /* Input (Variable), */
  180. 0x05, 0x01, /* Usage Page (Desktop), */
  181. 0x75, 0x10, /* Report Size (16), */
  182. 0x46, 0xFF, 0xFF, /* Physical Maximum (65535), */
  183. 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum (65535), */
  184. 0x95, 0x03, /* Report Count (3), * 3x Accels */
  185. 0x09, 0x33, /* Usage (rX), */
  186. 0x09, 0x34, /* Usage (rY), */
  187. 0x09, 0x35, /* Usage (rZ), */
  188. 0x81, 0x02, /* Input (Variable), */
  189. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  190. 0x95, 0x03, /* Report Count (3), * Skip Accels 2nd frame */
  191. 0x81, 0x02, /* Input (Variable), */
  192. 0x05, 0x01, /* Usage Page (Desktop), */
  193. 0x09, 0x01, /* Usage (Pointer), */
  194. 0x95, 0x03, /* Report Count (3), * 3x Gyros */
  195. 0x81, 0x02, /* Input (Variable), */
  196. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  197. 0x95, 0x03, /* Report Count (3), * Skip Gyros 2nd frame */
  198. 0x81, 0x02, /* Input (Variable), */
  199. 0x75, 0x0C, /* Report Size (12), */
  200. 0x46, 0xFF, 0x0F, /* Physical Maximum (4095), */
  201. 0x26, 0xFF, 0x0F, /* Logical Maximum (4095), */
  202. 0x95, 0x04, /* Report Count (4), * Skip Temp and Magnetometers */
  203. 0x81, 0x02, /* Input (Variable), */
  204. 0x75, 0x08, /* Report Size (8), */
  205. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  206. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  207. 0x95, 0x06, /* Report Count (6), * Skip Timestamp and Extension Bytes */
  208. 0x81, 0x02, /* Input (Variable), */
  209. 0x75, 0x08, /* Report Size (8), */
  210. 0x95, 0x30, /* Report Count (48), */
  211. 0x09, 0x01, /* Usage (Pointer), */
  212. 0x91, 0x02, /* Output (Variable), */
  213. 0x75, 0x08, /* Report Size (8), */
  214. 0x95, 0x30, /* Report Count (48), */
  215. 0x09, 0x01, /* Usage (Pointer), */
  216. 0xB1, 0x02, /* Feature (Variable), */
  217. 0xC0, /* End Collection, */
  218. 0xA1, 0x02, /* Collection (Logical), */
  219. 0x85, 0x02, /* Report ID (2), */
  220. 0x75, 0x08, /* Report Size (8), */
  221. 0x95, 0x30, /* Report Count (48), */
  222. 0x09, 0x01, /* Usage (Pointer), */
  223. 0xB1, 0x02, /* Feature (Variable), */
  224. 0xC0, /* End Collection, */
  225. 0xA1, 0x02, /* Collection (Logical), */
  226. 0x85, 0xEE, /* Report ID (238), */
  227. 0x75, 0x08, /* Report Size (8), */
  228. 0x95, 0x30, /* Report Count (48), */
  229. 0x09, 0x01, /* Usage (Pointer), */
  230. 0xB1, 0x02, /* Feature (Variable), */
  231. 0xC0, /* End Collection, */
  232. 0xA1, 0x02, /* Collection (Logical), */
  233. 0x85, 0xEF, /* Report ID (239), */
  234. 0x75, 0x08, /* Report Size (8), */
  235. 0x95, 0x30, /* Report Count (48), */
  236. 0x09, 0x01, /* Usage (Pointer), */
  237. 0xB1, 0x02, /* Feature (Variable), */
  238. 0xC0, /* End Collection, */
  239. 0xC0 /* End Collection */
  240. };
  241. /* PS/3 Navigation controller */
  242. static __u8 navigation_rdesc[] = {
  243. 0x05, 0x01, /* Usage Page (Desktop), */
  244. 0x09, 0x04, /* Usage (Joystik), */
  245. 0xA1, 0x01, /* Collection (Application), */
  246. 0xA1, 0x02, /* Collection (Logical), */
  247. 0x85, 0x01, /* Report ID (1), */
  248. 0x75, 0x08, /* Report Size (8), */
  249. 0x95, 0x01, /* Report Count (1), */
  250. 0x15, 0x00, /* Logical Minimum (0), */
  251. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  252. 0x81, 0x03, /* Input (Constant, Variable), */
  253. 0x75, 0x01, /* Report Size (1), */
  254. 0x95, 0x13, /* Report Count (19), */
  255. 0x15, 0x00, /* Logical Minimum (0), */
  256. 0x25, 0x01, /* Logical Maximum (1), */
  257. 0x35, 0x00, /* Physical Minimum (0), */
  258. 0x45, 0x01, /* Physical Maximum (1), */
  259. 0x05, 0x09, /* Usage Page (Button), */
  260. 0x19, 0x01, /* Usage Minimum (01h), */
  261. 0x29, 0x13, /* Usage Maximum (13h), */
  262. 0x81, 0x02, /* Input (Variable), */
  263. 0x75, 0x01, /* Report Size (1), */
  264. 0x95, 0x0D, /* Report Count (13), */
  265. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  266. 0x81, 0x03, /* Input (Constant, Variable), */
  267. 0x15, 0x00, /* Logical Minimum (0), */
  268. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  269. 0x05, 0x01, /* Usage Page (Desktop), */
  270. 0x09, 0x01, /* Usage (Pointer), */
  271. 0xA1, 0x00, /* Collection (Physical), */
  272. 0x75, 0x08, /* Report Size (8), */
  273. 0x95, 0x02, /* Report Count (2), */
  274. 0x35, 0x00, /* Physical Minimum (0), */
  275. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  276. 0x09, 0x30, /* Usage (X), */
  277. 0x09, 0x31, /* Usage (Y), */
  278. 0x81, 0x02, /* Input (Variable), */
  279. 0xC0, /* End Collection, */
  280. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  281. 0x95, 0x06, /* Report Count (6), */
  282. 0x81, 0x03, /* Input (Constant, Variable), */
  283. 0x05, 0x01, /* Usage Page (Desktop), */
  284. 0x75, 0x08, /* Report Size (8), */
  285. 0x95, 0x05, /* Report Count (5), */
  286. 0x09, 0x01, /* Usage (Pointer), */
  287. 0x81, 0x02, /* Input (Variable), */
  288. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  289. 0x95, 0x20, /* Report Count (26), */
  290. 0x81, 0x02, /* Input (Variable), */
  291. 0x75, 0x08, /* Report Size (8), */
  292. 0x95, 0x30, /* Report Count (48), */
  293. 0x09, 0x01, /* Usage (Pointer), */
  294. 0x91, 0x02, /* Output (Variable), */
  295. 0x75, 0x08, /* Report Size (8), */
  296. 0x95, 0x30, /* Report Count (48), */
  297. 0x09, 0x01, /* Usage (Pointer), */
  298. 0xB1, 0x02, /* Feature (Variable), */
  299. 0xC0, /* End Collection, */
  300. 0xA1, 0x02, /* Collection (Logical), */
  301. 0x85, 0x02, /* Report ID (2), */
  302. 0x75, 0x08, /* Report Size (8), */
  303. 0x95, 0x30, /* Report Count (48), */
  304. 0x09, 0x01, /* Usage (Pointer), */
  305. 0xB1, 0x02, /* Feature (Variable), */
  306. 0xC0, /* End Collection, */
  307. 0xA1, 0x02, /* Collection (Logical), */
  308. 0x85, 0xEE, /* Report ID (238), */
  309. 0x75, 0x08, /* Report Size (8), */
  310. 0x95, 0x30, /* Report Count (48), */
  311. 0x09, 0x01, /* Usage (Pointer), */
  312. 0xB1, 0x02, /* Feature (Variable), */
  313. 0xC0, /* End Collection, */
  314. 0xA1, 0x02, /* Collection (Logical), */
  315. 0x85, 0xEF, /* Report ID (239), */
  316. 0x75, 0x08, /* Report Size (8), */
  317. 0x95, 0x30, /* Report Count (48), */
  318. 0x09, 0x01, /* Usage (Pointer), */
  319. 0xB1, 0x02, /* Feature (Variable), */
  320. 0xC0, /* End Collection, */
  321. 0xC0 /* End Collection */
  322. };
  323. /*
  324. * The default descriptor doesn't provide mapping for the accelerometers
  325. * or orientation sensors. This fixed descriptor maps the accelerometers
  326. * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors
  327. * to usage values 0x43, 0x44 and 0x45.
  328. */
  329. static u8 dualshock4_usb_rdesc[] = {
  330. 0x05, 0x01, /* Usage Page (Desktop), */
  331. 0x09, 0x05, /* Usage (Gamepad), */
  332. 0xA1, 0x01, /* Collection (Application), */
  333. 0x85, 0x01, /* Report ID (1), */
  334. 0x09, 0x30, /* Usage (X), */
  335. 0x09, 0x31, /* Usage (Y), */
  336. 0x09, 0x32, /* Usage (Z), */
  337. 0x09, 0x35, /* Usage (Rz), */
  338. 0x15, 0x00, /* Logical Minimum (0), */
  339. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  340. 0x75, 0x08, /* Report Size (8), */
  341. 0x95, 0x04, /* Report Count (4), */
  342. 0x81, 0x02, /* Input (Variable), */
  343. 0x09, 0x39, /* Usage (Hat Switch), */
  344. 0x15, 0x00, /* Logical Minimum (0), */
  345. 0x25, 0x07, /* Logical Maximum (7), */
  346. 0x35, 0x00, /* Physical Minimum (0), */
  347. 0x46, 0x3B, 0x01, /* Physical Maximum (315), */
  348. 0x65, 0x14, /* Unit (Degrees), */
  349. 0x75, 0x04, /* Report Size (4), */
  350. 0x95, 0x01, /* Report Count (1), */
  351. 0x81, 0x42, /* Input (Variable, Null State), */
  352. 0x65, 0x00, /* Unit, */
  353. 0x05, 0x09, /* Usage Page (Button), */
  354. 0x19, 0x01, /* Usage Minimum (01h), */
  355. 0x29, 0x0E, /* Usage Maximum (0Eh), */
  356. 0x15, 0x00, /* Logical Minimum (0), */
  357. 0x25, 0x01, /* Logical Maximum (1), */
  358. 0x75, 0x01, /* Report Size (1), */
  359. 0x95, 0x0E, /* Report Count (14), */
  360. 0x81, 0x02, /* Input (Variable), */
  361. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  362. 0x09, 0x20, /* Usage (20h), */
  363. 0x75, 0x06, /* Report Size (6), */
  364. 0x95, 0x01, /* Report Count (1), */
  365. 0x15, 0x00, /* Logical Minimum (0), */
  366. 0x25, 0x3F, /* Logical Maximum (63), */
  367. 0x81, 0x02, /* Input (Variable), */
  368. 0x05, 0x01, /* Usage Page (Desktop), */
  369. 0x09, 0x33, /* Usage (Rx), */
  370. 0x09, 0x34, /* Usage (Ry), */
  371. 0x15, 0x00, /* Logical Minimum (0), */
  372. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  373. 0x75, 0x08, /* Report Size (8), */
  374. 0x95, 0x02, /* Report Count (2), */
  375. 0x81, 0x02, /* Input (Variable), */
  376. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  377. 0x09, 0x21, /* Usage (21h), */
  378. 0x95, 0x03, /* Report Count (3), */
  379. 0x81, 0x02, /* Input (Variable), */
  380. 0x05, 0x01, /* Usage Page (Desktop), */
  381. 0x19, 0x40, /* Usage Minimum (40h), */
  382. 0x29, 0x42, /* Usage Maximum (42h), */
  383. 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */
  384. 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */
  385. 0x75, 0x10, /* Report Size (16), */
  386. 0x95, 0x03, /* Report Count (3), */
  387. 0x81, 0x02, /* Input (Variable), */
  388. 0x19, 0x43, /* Usage Minimum (43h), */
  389. 0x29, 0x45, /* Usage Maximum (45h), */
  390. 0x16, 0x00, 0xE0, /* Logical Minimum (-8192), */
  391. 0x26, 0xFF, 0x1F, /* Logical Maximum (8191), */
  392. 0x95, 0x03, /* Report Count (3), */
  393. 0x81, 0x02, /* Input (Variable), */
  394. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  395. 0x09, 0x21, /* Usage (21h), */
  396. 0x15, 0x00, /* Logical Minimum (0), */
  397. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  398. 0x75, 0x08, /* Report Size (8), */
  399. 0x95, 0x27, /* Report Count (39), */
  400. 0x81, 0x02, /* Input (Variable), */
  401. 0x85, 0x05, /* Report ID (5), */
  402. 0x09, 0x22, /* Usage (22h), */
  403. 0x95, 0x1F, /* Report Count (31), */
  404. 0x91, 0x02, /* Output (Variable), */
  405. 0x85, 0x04, /* Report ID (4), */
  406. 0x09, 0x23, /* Usage (23h), */
  407. 0x95, 0x24, /* Report Count (36), */
  408. 0xB1, 0x02, /* Feature (Variable), */
  409. 0x85, 0x02, /* Report ID (2), */
  410. 0x09, 0x24, /* Usage (24h), */
  411. 0x95, 0x24, /* Report Count (36), */
  412. 0xB1, 0x02, /* Feature (Variable), */
  413. 0x85, 0x08, /* Report ID (8), */
  414. 0x09, 0x25, /* Usage (25h), */
  415. 0x95, 0x03, /* Report Count (3), */
  416. 0xB1, 0x02, /* Feature (Variable), */
  417. 0x85, 0x10, /* Report ID (16), */
  418. 0x09, 0x26, /* Usage (26h), */
  419. 0x95, 0x04, /* Report Count (4), */
  420. 0xB1, 0x02, /* Feature (Variable), */
  421. 0x85, 0x11, /* Report ID (17), */
  422. 0x09, 0x27, /* Usage (27h), */
  423. 0x95, 0x02, /* Report Count (2), */
  424. 0xB1, 0x02, /* Feature (Variable), */
  425. 0x85, 0x12, /* Report ID (18), */
  426. 0x06, 0x02, 0xFF, /* Usage Page (FF02h), */
  427. 0x09, 0x21, /* Usage (21h), */
  428. 0x95, 0x0F, /* Report Count (15), */
  429. 0xB1, 0x02, /* Feature (Variable), */
  430. 0x85, 0x13, /* Report ID (19), */
  431. 0x09, 0x22, /* Usage (22h), */
  432. 0x95, 0x16, /* Report Count (22), */
  433. 0xB1, 0x02, /* Feature (Variable), */
  434. 0x85, 0x14, /* Report ID (20), */
  435. 0x06, 0x05, 0xFF, /* Usage Page (FF05h), */
  436. 0x09, 0x20, /* Usage (20h), */
  437. 0x95, 0x10, /* Report Count (16), */
  438. 0xB1, 0x02, /* Feature (Variable), */
  439. 0x85, 0x15, /* Report ID (21), */
  440. 0x09, 0x21, /* Usage (21h), */
  441. 0x95, 0x2C, /* Report Count (44), */
  442. 0xB1, 0x02, /* Feature (Variable), */
  443. 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */
  444. 0x85, 0x80, /* Report ID (128), */
  445. 0x09, 0x20, /* Usage (20h), */
  446. 0x95, 0x06, /* Report Count (6), */
  447. 0xB1, 0x02, /* Feature (Variable), */
  448. 0x85, 0x81, /* Report ID (129), */
  449. 0x09, 0x21, /* Usage (21h), */
  450. 0x95, 0x06, /* Report Count (6), */
  451. 0xB1, 0x02, /* Feature (Variable), */
  452. 0x85, 0x82, /* Report ID (130), */
  453. 0x09, 0x22, /* Usage (22h), */
  454. 0x95, 0x05, /* Report Count (5), */
  455. 0xB1, 0x02, /* Feature (Variable), */
  456. 0x85, 0x83, /* Report ID (131), */
  457. 0x09, 0x23, /* Usage (23h), */
  458. 0x95, 0x01, /* Report Count (1), */
  459. 0xB1, 0x02, /* Feature (Variable), */
  460. 0x85, 0x84, /* Report ID (132), */
  461. 0x09, 0x24, /* Usage (24h), */
  462. 0x95, 0x04, /* Report Count (4), */
  463. 0xB1, 0x02, /* Feature (Variable), */
  464. 0x85, 0x85, /* Report ID (133), */
  465. 0x09, 0x25, /* Usage (25h), */
  466. 0x95, 0x06, /* Report Count (6), */
  467. 0xB1, 0x02, /* Feature (Variable), */
  468. 0x85, 0x86, /* Report ID (134), */
  469. 0x09, 0x26, /* Usage (26h), */
  470. 0x95, 0x06, /* Report Count (6), */
  471. 0xB1, 0x02, /* Feature (Variable), */
  472. 0x85, 0x87, /* Report ID (135), */
  473. 0x09, 0x27, /* Usage (27h), */
  474. 0x95, 0x23, /* Report Count (35), */
  475. 0xB1, 0x02, /* Feature (Variable), */
  476. 0x85, 0x88, /* Report ID (136), */
  477. 0x09, 0x28, /* Usage (28h), */
  478. 0x95, 0x22, /* Report Count (34), */
  479. 0xB1, 0x02, /* Feature (Variable), */
  480. 0x85, 0x89, /* Report ID (137), */
  481. 0x09, 0x29, /* Usage (29h), */
  482. 0x95, 0x02, /* Report Count (2), */
  483. 0xB1, 0x02, /* Feature (Variable), */
  484. 0x85, 0x90, /* Report ID (144), */
  485. 0x09, 0x30, /* Usage (30h), */
  486. 0x95, 0x05, /* Report Count (5), */
  487. 0xB1, 0x02, /* Feature (Variable), */
  488. 0x85, 0x91, /* Report ID (145), */
  489. 0x09, 0x31, /* Usage (31h), */
  490. 0x95, 0x03, /* Report Count (3), */
  491. 0xB1, 0x02, /* Feature (Variable), */
  492. 0x85, 0x92, /* Report ID (146), */
  493. 0x09, 0x32, /* Usage (32h), */
  494. 0x95, 0x03, /* Report Count (3), */
  495. 0xB1, 0x02, /* Feature (Variable), */
  496. 0x85, 0x93, /* Report ID (147), */
  497. 0x09, 0x33, /* Usage (33h), */
  498. 0x95, 0x0C, /* Report Count (12), */
  499. 0xB1, 0x02, /* Feature (Variable), */
  500. 0x85, 0xA0, /* Report ID (160), */
  501. 0x09, 0x40, /* Usage (40h), */
  502. 0x95, 0x06, /* Report Count (6), */
  503. 0xB1, 0x02, /* Feature (Variable), */
  504. 0x85, 0xA1, /* Report ID (161), */
  505. 0x09, 0x41, /* Usage (41h), */
  506. 0x95, 0x01, /* Report Count (1), */
  507. 0xB1, 0x02, /* Feature (Variable), */
  508. 0x85, 0xA2, /* Report ID (162), */
  509. 0x09, 0x42, /* Usage (42h), */
  510. 0x95, 0x01, /* Report Count (1), */
  511. 0xB1, 0x02, /* Feature (Variable), */
  512. 0x85, 0xA3, /* Report ID (163), */
  513. 0x09, 0x43, /* Usage (43h), */
  514. 0x95, 0x30, /* Report Count (48), */
  515. 0xB1, 0x02, /* Feature (Variable), */
  516. 0x85, 0xA4, /* Report ID (164), */
  517. 0x09, 0x44, /* Usage (44h), */
  518. 0x95, 0x0D, /* Report Count (13), */
  519. 0xB1, 0x02, /* Feature (Variable), */
  520. 0x85, 0xA5, /* Report ID (165), */
  521. 0x09, 0x45, /* Usage (45h), */
  522. 0x95, 0x15, /* Report Count (21), */
  523. 0xB1, 0x02, /* Feature (Variable), */
  524. 0x85, 0xA6, /* Report ID (166), */
  525. 0x09, 0x46, /* Usage (46h), */
  526. 0x95, 0x15, /* Report Count (21), */
  527. 0xB1, 0x02, /* Feature (Variable), */
  528. 0x85, 0xF0, /* Report ID (240), */
  529. 0x09, 0x47, /* Usage (47h), */
  530. 0x95, 0x3F, /* Report Count (63), */
  531. 0xB1, 0x02, /* Feature (Variable), */
  532. 0x85, 0xF1, /* Report ID (241), */
  533. 0x09, 0x48, /* Usage (48h), */
  534. 0x95, 0x3F, /* Report Count (63), */
  535. 0xB1, 0x02, /* Feature (Variable), */
  536. 0x85, 0xF2, /* Report ID (242), */
  537. 0x09, 0x49, /* Usage (49h), */
  538. 0x95, 0x0F, /* Report Count (15), */
  539. 0xB1, 0x02, /* Feature (Variable), */
  540. 0x85, 0xA7, /* Report ID (167), */
  541. 0x09, 0x4A, /* Usage (4Ah), */
  542. 0x95, 0x01, /* Report Count (1), */
  543. 0xB1, 0x02, /* Feature (Variable), */
  544. 0x85, 0xA8, /* Report ID (168), */
  545. 0x09, 0x4B, /* Usage (4Bh), */
  546. 0x95, 0x01, /* Report Count (1), */
  547. 0xB1, 0x02, /* Feature (Variable), */
  548. 0x85, 0xA9, /* Report ID (169), */
  549. 0x09, 0x4C, /* Usage (4Ch), */
  550. 0x95, 0x08, /* Report Count (8), */
  551. 0xB1, 0x02, /* Feature (Variable), */
  552. 0x85, 0xAA, /* Report ID (170), */
  553. 0x09, 0x4E, /* Usage (4Eh), */
  554. 0x95, 0x01, /* Report Count (1), */
  555. 0xB1, 0x02, /* Feature (Variable), */
  556. 0x85, 0xAB, /* Report ID (171), */
  557. 0x09, 0x4F, /* Usage (4Fh), */
  558. 0x95, 0x39, /* Report Count (57), */
  559. 0xB1, 0x02, /* Feature (Variable), */
  560. 0x85, 0xAC, /* Report ID (172), */
  561. 0x09, 0x50, /* Usage (50h), */
  562. 0x95, 0x39, /* Report Count (57), */
  563. 0xB1, 0x02, /* Feature (Variable), */
  564. 0x85, 0xAD, /* Report ID (173), */
  565. 0x09, 0x51, /* Usage (51h), */
  566. 0x95, 0x0B, /* Report Count (11), */
  567. 0xB1, 0x02, /* Feature (Variable), */
  568. 0x85, 0xAE, /* Report ID (174), */
  569. 0x09, 0x52, /* Usage (52h), */
  570. 0x95, 0x01, /* Report Count (1), */
  571. 0xB1, 0x02, /* Feature (Variable), */
  572. 0x85, 0xAF, /* Report ID (175), */
  573. 0x09, 0x53, /* Usage (53h), */
  574. 0x95, 0x02, /* Report Count (2), */
  575. 0xB1, 0x02, /* Feature (Variable), */
  576. 0x85, 0xB0, /* Report ID (176), */
  577. 0x09, 0x54, /* Usage (54h), */
  578. 0x95, 0x3F, /* Report Count (63), */
  579. 0xB1, 0x02, /* Feature (Variable), */
  580. 0xC0 /* End Collection */
  581. };
  582. /*
  583. * The default behavior of the Dualshock 4 is to send reports using report
  584. * type 1 when running over Bluetooth. However, when feature report 2 is
  585. * requested during the controller initialization it starts sending input
  586. * reports in report 17. Since report 17 is undefined in the default HID
  587. * descriptor the button and axis definitions must be moved to report 17 or
  588. * the HID layer won't process the received input.
  589. */
  590. static u8 dualshock4_bt_rdesc[] = {
  591. 0x05, 0x01, /* Usage Page (Desktop), */
  592. 0x09, 0x05, /* Usage (Gamepad), */
  593. 0xA1, 0x01, /* Collection (Application), */
  594. 0x85, 0x01, /* Report ID (1), */
  595. 0x75, 0x08, /* Report Size (8), */
  596. 0x95, 0x0A, /* Report Count (9), */
  597. 0x81, 0x02, /* Input (Variable), */
  598. 0x06, 0x04, 0xFF, /* Usage Page (FF04h), */
  599. 0x85, 0x02, /* Report ID (2), */
  600. 0x09, 0x24, /* Usage (24h), */
  601. 0x95, 0x24, /* Report Count (36), */
  602. 0xB1, 0x02, /* Feature (Variable), */
  603. 0x85, 0xA3, /* Report ID (163), */
  604. 0x09, 0x25, /* Usage (25h), */
  605. 0x95, 0x30, /* Report Count (48), */
  606. 0xB1, 0x02, /* Feature (Variable), */
  607. 0x85, 0x05, /* Report ID (5), */
  608. 0x09, 0x26, /* Usage (26h), */
  609. 0x95, 0x28, /* Report Count (40), */
  610. 0xB1, 0x02, /* Feature (Variable), */
  611. 0x85, 0x06, /* Report ID (6), */
  612. 0x09, 0x27, /* Usage (27h), */
  613. 0x95, 0x34, /* Report Count (52), */
  614. 0xB1, 0x02, /* Feature (Variable), */
  615. 0x85, 0x07, /* Report ID (7), */
  616. 0x09, 0x28, /* Usage (28h), */
  617. 0x95, 0x30, /* Report Count (48), */
  618. 0xB1, 0x02, /* Feature (Variable), */
  619. 0x85, 0x08, /* Report ID (8), */
  620. 0x09, 0x29, /* Usage (29h), */
  621. 0x95, 0x2F, /* Report Count (47), */
  622. 0xB1, 0x02, /* Feature (Variable), */
  623. 0x06, 0x03, 0xFF, /* Usage Page (FF03h), */
  624. 0x85, 0x03, /* Report ID (3), */
  625. 0x09, 0x21, /* Usage (21h), */
  626. 0x95, 0x26, /* Report Count (38), */
  627. 0xB1, 0x02, /* Feature (Variable), */
  628. 0x85, 0x04, /* Report ID (4), */
  629. 0x09, 0x22, /* Usage (22h), */
  630. 0x95, 0x2E, /* Report Count (46), */
  631. 0xB1, 0x02, /* Feature (Variable), */
  632. 0x85, 0xF0, /* Report ID (240), */
  633. 0x09, 0x47, /* Usage (47h), */
  634. 0x95, 0x3F, /* Report Count (63), */
  635. 0xB1, 0x02, /* Feature (Variable), */
  636. 0x85, 0xF1, /* Report ID (241), */
  637. 0x09, 0x48, /* Usage (48h), */
  638. 0x95, 0x3F, /* Report Count (63), */
  639. 0xB1, 0x02, /* Feature (Variable), */
  640. 0x85, 0xF2, /* Report ID (242), */
  641. 0x09, 0x49, /* Usage (49h), */
  642. 0x95, 0x0F, /* Report Count (15), */
  643. 0xB1, 0x02, /* Feature (Variable), */
  644. 0x85, 0x11, /* Report ID (17), */
  645. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  646. 0x09, 0x20, /* Usage (20h), */
  647. 0x95, 0x02, /* Report Count (2), */
  648. 0x81, 0x02, /* Input (Variable), */
  649. 0x05, 0x01, /* Usage Page (Desktop), */
  650. 0x09, 0x30, /* Usage (X), */
  651. 0x09, 0x31, /* Usage (Y), */
  652. 0x09, 0x32, /* Usage (Z), */
  653. 0x09, 0x35, /* Usage (Rz), */
  654. 0x15, 0x00, /* Logical Minimum (0), */
  655. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  656. 0x75, 0x08, /* Report Size (8), */
  657. 0x95, 0x04, /* Report Count (4), */
  658. 0x81, 0x02, /* Input (Variable), */
  659. 0x09, 0x39, /* Usage (Hat Switch), */
  660. 0x15, 0x00, /* Logical Minimum (0), */
  661. 0x25, 0x07, /* Logical Maximum (7), */
  662. 0x75, 0x04, /* Report Size (4), */
  663. 0x95, 0x01, /* Report Count (1), */
  664. 0x81, 0x42, /* Input (Variable, Null State), */
  665. 0x05, 0x09, /* Usage Page (Button), */
  666. 0x19, 0x01, /* Usage Minimum (01h), */
  667. 0x29, 0x0E, /* Usage Maximum (0Eh), */
  668. 0x15, 0x00, /* Logical Minimum (0), */
  669. 0x25, 0x01, /* Logical Maximum (1), */
  670. 0x75, 0x01, /* Report Size (1), */
  671. 0x95, 0x0E, /* Report Count (14), */
  672. 0x81, 0x02, /* Input (Variable), */
  673. 0x75, 0x06, /* Report Size (6), */
  674. 0x95, 0x01, /* Report Count (1), */
  675. 0x81, 0x01, /* Input (Constant), */
  676. 0x05, 0x01, /* Usage Page (Desktop), */
  677. 0x09, 0x33, /* Usage (Rx), */
  678. 0x09, 0x34, /* Usage (Ry), */
  679. 0x15, 0x00, /* Logical Minimum (0), */
  680. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  681. 0x75, 0x08, /* Report Size (8), */
  682. 0x95, 0x02, /* Report Count (2), */
  683. 0x81, 0x02, /* Input (Variable), */
  684. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  685. 0x09, 0x20, /* Usage (20h), */
  686. 0x95, 0x03, /* Report Count (3), */
  687. 0x81, 0x02, /* Input (Variable), */
  688. 0x05, 0x01, /* Usage Page (Desktop), */
  689. 0x19, 0x40, /* Usage Minimum (40h), */
  690. 0x29, 0x42, /* Usage Maximum (42h), */
  691. 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */
  692. 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */
  693. 0x75, 0x10, /* Report Size (16), */
  694. 0x95, 0x03, /* Report Count (3), */
  695. 0x81, 0x02, /* Input (Variable), */
  696. 0x19, 0x43, /* Usage Minimum (43h), */
  697. 0x29, 0x45, /* Usage Maximum (45h), */
  698. 0x16, 0x00, 0xE0, /* Logical Minimum (-8192), */
  699. 0x26, 0xFF, 0x1F, /* Logical Maximum (8191), */
  700. 0x95, 0x03, /* Report Count (3), */
  701. 0x81, 0x02, /* Input (Variable), */
  702. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  703. 0x09, 0x20, /* Usage (20h), */
  704. 0x15, 0x00, /* Logical Minimum (0), */
  705. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  706. 0x75, 0x08, /* Report Size (8), */
  707. 0x95, 0x31, /* Report Count (51), */
  708. 0x81, 0x02, /* Input (Variable), */
  709. 0x09, 0x21, /* Usage (21h), */
  710. 0x75, 0x08, /* Report Size (8), */
  711. 0x95, 0x4D, /* Report Count (77), */
  712. 0x91, 0x02, /* Output (Variable), */
  713. 0x85, 0x12, /* Report ID (18), */
  714. 0x09, 0x22, /* Usage (22h), */
  715. 0x95, 0x8D, /* Report Count (141), */
  716. 0x81, 0x02, /* Input (Variable), */
  717. 0x09, 0x23, /* Usage (23h), */
  718. 0x91, 0x02, /* Output (Variable), */
  719. 0x85, 0x13, /* Report ID (19), */
  720. 0x09, 0x24, /* Usage (24h), */
  721. 0x95, 0xCD, /* Report Count (205), */
  722. 0x81, 0x02, /* Input (Variable), */
  723. 0x09, 0x25, /* Usage (25h), */
  724. 0x91, 0x02, /* Output (Variable), */
  725. 0x85, 0x14, /* Report ID (20), */
  726. 0x09, 0x26, /* Usage (26h), */
  727. 0x96, 0x0D, 0x01, /* Report Count (269), */
  728. 0x81, 0x02, /* Input (Variable), */
  729. 0x09, 0x27, /* Usage (27h), */
  730. 0x91, 0x02, /* Output (Variable), */
  731. 0x85, 0x15, /* Report ID (21), */
  732. 0x09, 0x28, /* Usage (28h), */
  733. 0x96, 0x4D, 0x01, /* Report Count (333), */
  734. 0x81, 0x02, /* Input (Variable), */
  735. 0x09, 0x29, /* Usage (29h), */
  736. 0x91, 0x02, /* Output (Variable), */
  737. 0x85, 0x16, /* Report ID (22), */
  738. 0x09, 0x2A, /* Usage (2Ah), */
  739. 0x96, 0x8D, 0x01, /* Report Count (397), */
  740. 0x81, 0x02, /* Input (Variable), */
  741. 0x09, 0x2B, /* Usage (2Bh), */
  742. 0x91, 0x02, /* Output (Variable), */
  743. 0x85, 0x17, /* Report ID (23), */
  744. 0x09, 0x2C, /* Usage (2Ch), */
  745. 0x96, 0xCD, 0x01, /* Report Count (461), */
  746. 0x81, 0x02, /* Input (Variable), */
  747. 0x09, 0x2D, /* Usage (2Dh), */
  748. 0x91, 0x02, /* Output (Variable), */
  749. 0x85, 0x18, /* Report ID (24), */
  750. 0x09, 0x2E, /* Usage (2Eh), */
  751. 0x96, 0x0D, 0x02, /* Report Count (525), */
  752. 0x81, 0x02, /* Input (Variable), */
  753. 0x09, 0x2F, /* Usage (2Fh), */
  754. 0x91, 0x02, /* Output (Variable), */
  755. 0x85, 0x19, /* Report ID (25), */
  756. 0x09, 0x30, /* Usage (30h), */
  757. 0x96, 0x22, 0x02, /* Report Count (546), */
  758. 0x81, 0x02, /* Input (Variable), */
  759. 0x09, 0x31, /* Usage (31h), */
  760. 0x91, 0x02, /* Output (Variable), */
  761. 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */
  762. 0x85, 0x82, /* Report ID (130), */
  763. 0x09, 0x22, /* Usage (22h), */
  764. 0x95, 0x3F, /* Report Count (63), */
  765. 0xB1, 0x02, /* Feature (Variable), */
  766. 0x85, 0x83, /* Report ID (131), */
  767. 0x09, 0x23, /* Usage (23h), */
  768. 0xB1, 0x02, /* Feature (Variable), */
  769. 0x85, 0x84, /* Report ID (132), */
  770. 0x09, 0x24, /* Usage (24h), */
  771. 0xB1, 0x02, /* Feature (Variable), */
  772. 0x85, 0x90, /* Report ID (144), */
  773. 0x09, 0x30, /* Usage (30h), */
  774. 0xB1, 0x02, /* Feature (Variable), */
  775. 0x85, 0x91, /* Report ID (145), */
  776. 0x09, 0x31, /* Usage (31h), */
  777. 0xB1, 0x02, /* Feature (Variable), */
  778. 0x85, 0x92, /* Report ID (146), */
  779. 0x09, 0x32, /* Usage (32h), */
  780. 0xB1, 0x02, /* Feature (Variable), */
  781. 0x85, 0x93, /* Report ID (147), */
  782. 0x09, 0x33, /* Usage (33h), */
  783. 0xB1, 0x02, /* Feature (Variable), */
  784. 0x85, 0xA0, /* Report ID (160), */
  785. 0x09, 0x40, /* Usage (40h), */
  786. 0xB1, 0x02, /* Feature (Variable), */
  787. 0x85, 0xA4, /* Report ID (164), */
  788. 0x09, 0x44, /* Usage (44h), */
  789. 0xB1, 0x02, /* Feature (Variable), */
  790. 0xC0 /* End Collection */
  791. };
  792. static __u8 ps3remote_rdesc[] = {
  793. 0x05, 0x01, /* GUsagePage Generic Desktop */
  794. 0x09, 0x05, /* LUsage 0x05 [Game Pad] */
  795. 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */
  796. /* Use collection 1 for joypad buttons */
  797. 0xA1, 0x02, /* MCollection Logical (interrelated data) */
  798. /* Ignore the 1st byte, maybe it is used for a controller
  799. * number but it's not needed for correct operation */
  800. 0x75, 0x08, /* GReportSize 0x08 [8] */
  801. 0x95, 0x01, /* GReportCount 0x01 [1] */
  802. 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
  803. /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these
  804. * buttons multiple keypresses are allowed */
  805. 0x05, 0x09, /* GUsagePage Button */
  806. 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */
  807. 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */
  808. 0x14, /* GLogicalMinimum [0] */
  809. 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */
  810. 0x75, 0x01, /* GReportSize 0x01 [1] */
  811. 0x95, 0x18, /* GReportCount 0x18 [24] */
  812. 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
  813. 0xC0, /* MEndCollection */
  814. /* Use collection 2 for remote control buttons */
  815. 0xA1, 0x02, /* MCollection Logical (interrelated data) */
  816. /* 5th byte is used for remote control buttons */
  817. 0x05, 0x09, /* GUsagePage Button */
  818. 0x18, /* LUsageMinimum [No button pressed] */
  819. 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */
  820. 0x14, /* GLogicalMinimum [0] */
  821. 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */
  822. 0x75, 0x08, /* GReportSize 0x08 [8] */
  823. 0x95, 0x01, /* GReportCount 0x01 [1] */
  824. 0x80, /* MInput */
  825. /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at
  826. * 0xff and 11th is for press indication */
  827. 0x75, 0x08, /* GReportSize 0x08 [8] */
  828. 0x95, 0x06, /* GReportCount 0x06 [6] */
  829. 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
  830. /* 12th byte is for battery strength */
  831. 0x05, 0x06, /* GUsagePage Generic Device Controls */
  832. 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */
  833. 0x14, /* GLogicalMinimum [0] */
  834. 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */
  835. 0x75, 0x08, /* GReportSize 0x08 [8] */
  836. 0x95, 0x01, /* GReportCount 0x01 [1] */
  837. 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
  838. 0xC0, /* MEndCollection */
  839. 0xC0 /* MEndCollection [Game Pad] */
  840. };
  841. static const unsigned int ps3remote_keymap_joypad_buttons[] = {
  842. [0x01] = KEY_SELECT,
  843. [0x02] = BTN_THUMBL, /* L3 */
  844. [0x03] = BTN_THUMBR, /* R3 */
  845. [0x04] = BTN_START,
  846. [0x05] = KEY_UP,
  847. [0x06] = KEY_RIGHT,
  848. [0x07] = KEY_DOWN,
  849. [0x08] = KEY_LEFT,
  850. [0x09] = BTN_TL2, /* L2 */
  851. [0x0a] = BTN_TR2, /* R2 */
  852. [0x0b] = BTN_TL, /* L1 */
  853. [0x0c] = BTN_TR, /* R1 */
  854. [0x0d] = KEY_OPTION, /* options/triangle */
  855. [0x0e] = KEY_BACK, /* back/circle */
  856. [0x0f] = BTN_0, /* cross */
  857. [0x10] = KEY_SCREEN, /* view/square */
  858. [0x11] = KEY_HOMEPAGE, /* PS button */
  859. [0x14] = KEY_ENTER,
  860. };
  861. static const unsigned int ps3remote_keymap_remote_buttons[] = {
  862. [0x00] = KEY_1,
  863. [0x01] = KEY_2,
  864. [0x02] = KEY_3,
  865. [0x03] = KEY_4,
  866. [0x04] = KEY_5,
  867. [0x05] = KEY_6,
  868. [0x06] = KEY_7,
  869. [0x07] = KEY_8,
  870. [0x08] = KEY_9,
  871. [0x09] = KEY_0,
  872. [0x0e] = KEY_ESC, /* return */
  873. [0x0f] = KEY_CLEAR,
  874. [0x16] = KEY_EJECTCD,
  875. [0x1a] = KEY_MENU, /* top menu */
  876. [0x28] = KEY_TIME,
  877. [0x30] = KEY_PREVIOUS,
  878. [0x31] = KEY_NEXT,
  879. [0x32] = KEY_PLAY,
  880. [0x33] = KEY_REWIND, /* scan back */
  881. [0x34] = KEY_FORWARD, /* scan forward */
  882. [0x38] = KEY_STOP,
  883. [0x39] = KEY_PAUSE,
  884. [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */
  885. [0x60] = KEY_FRAMEBACK, /* slow/step back */
  886. [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */
  887. [0x63] = KEY_SUBTITLE,
  888. [0x64] = KEY_AUDIO,
  889. [0x65] = KEY_ANGLE,
  890. [0x70] = KEY_INFO, /* display */
  891. [0x80] = KEY_BLUE,
  892. [0x81] = KEY_RED,
  893. [0x82] = KEY_GREEN,
  894. [0x83] = KEY_YELLOW,
  895. };
  896. static const unsigned int buzz_keymap[] = {
  897. /*
  898. * The controller has 4 remote buzzers, each with one LED and 5
  899. * buttons.
  900. *
  901. * We use the mapping chosen by the controller, which is:
  902. *
  903. * Key Offset
  904. * -------------------
  905. * Buzz 1
  906. * Blue 5
  907. * Orange 4
  908. * Green 3
  909. * Yellow 2
  910. *
  911. * So, for example, the orange button on the third buzzer is mapped to
  912. * BTN_TRIGGER_HAPPY14
  913. */
  914. [ 1] = BTN_TRIGGER_HAPPY1,
  915. [ 2] = BTN_TRIGGER_HAPPY2,
  916. [ 3] = BTN_TRIGGER_HAPPY3,
  917. [ 4] = BTN_TRIGGER_HAPPY4,
  918. [ 5] = BTN_TRIGGER_HAPPY5,
  919. [ 6] = BTN_TRIGGER_HAPPY6,
  920. [ 7] = BTN_TRIGGER_HAPPY7,
  921. [ 8] = BTN_TRIGGER_HAPPY8,
  922. [ 9] = BTN_TRIGGER_HAPPY9,
  923. [10] = BTN_TRIGGER_HAPPY10,
  924. [11] = BTN_TRIGGER_HAPPY11,
  925. [12] = BTN_TRIGGER_HAPPY12,
  926. [13] = BTN_TRIGGER_HAPPY13,
  927. [14] = BTN_TRIGGER_HAPPY14,
  928. [15] = BTN_TRIGGER_HAPPY15,
  929. [16] = BTN_TRIGGER_HAPPY16,
  930. [17] = BTN_TRIGGER_HAPPY17,
  931. [18] = BTN_TRIGGER_HAPPY18,
  932. [19] = BTN_TRIGGER_HAPPY19,
  933. [20] = BTN_TRIGGER_HAPPY20,
  934. };
  935. static enum power_supply_property sony_battery_props[] = {
  936. POWER_SUPPLY_PROP_PRESENT,
  937. POWER_SUPPLY_PROP_CAPACITY,
  938. POWER_SUPPLY_PROP_SCOPE,
  939. POWER_SUPPLY_PROP_STATUS,
  940. };
  941. struct sixaxis_led {
  942. __u8 time_enabled; /* the total time the led is active (0xff means forever) */
  943. __u8 duty_length; /* how long a cycle is in deciseconds (0 means "really fast") */
  944. __u8 enabled;
  945. __u8 duty_off; /* % of duty_length the led is off (0xff means 100%) */
  946. __u8 duty_on; /* % of duty_length the led is on (0xff mean 100%) */
  947. } __packed;
  948. struct sixaxis_rumble {
  949. __u8 padding;
  950. __u8 right_duration; /* Right motor duration (0xff means forever) */
  951. __u8 right_motor_on; /* Right (small) motor on/off, only supports values of 0 or 1 (off/on) */
  952. __u8 left_duration; /* Left motor duration (0xff means forever) */
  953. __u8 left_motor_force; /* left (large) motor, supports force values from 0 to 255 */
  954. } __packed;
  955. struct sixaxis_output_report {
  956. __u8 report_id;
  957. struct sixaxis_rumble rumble;
  958. __u8 padding[4];
  959. __u8 leds_bitmap; /* bitmap of enabled LEDs: LED_1 = 0x02, LED_2 = 0x04, ... */
  960. struct sixaxis_led led[4]; /* LEDx at (4 - x) */
  961. struct sixaxis_led _reserved; /* LED5, not actually soldered */
  962. } __packed;
  963. union sixaxis_output_report_01 {
  964. struct sixaxis_output_report data;
  965. __u8 buf[36];
  966. };
  967. struct motion_output_report_02 {
  968. u8 type, zero;
  969. u8 r, g, b;
  970. u8 zero2;
  971. u8 rumble;
  972. };
  973. #define DS4_REPORT_0x02_SIZE 37
  974. #define DS4_REPORT_0x05_SIZE 32
  975. #define DS4_REPORT_0x11_SIZE 78
  976. #define DS4_REPORT_0x81_SIZE 7
  977. #define SIXAXIS_REPORT_0xF2_SIZE 17
  978. #define SIXAXIS_REPORT_0xF5_SIZE 8
  979. #define MOTION_REPORT_0x02_SIZE 49
  980. static DEFINE_SPINLOCK(sony_dev_list_lock);
  981. static LIST_HEAD(sony_device_list);
  982. static DEFINE_IDA(sony_device_id_allocator);
  983. struct sony_sc {
  984. spinlock_t lock;
  985. struct list_head list_node;
  986. struct hid_device *hdev;
  987. struct led_classdev *leds[MAX_LEDS];
  988. unsigned long quirks;
  989. struct work_struct state_worker;
  990. struct power_supply *battery;
  991. struct power_supply_desc battery_desc;
  992. int device_id;
  993. __u8 *output_report_dmabuf;
  994. #ifdef CONFIG_SONY_FF
  995. __u8 left;
  996. __u8 right;
  997. #endif
  998. __u8 mac_address[6];
  999. __u8 worker_initialized;
  1000. __u8 cable_state;
  1001. __u8 battery_charging;
  1002. __u8 battery_capacity;
  1003. __u8 led_state[MAX_LEDS];
  1004. __u8 led_delay_on[MAX_LEDS];
  1005. __u8 led_delay_off[MAX_LEDS];
  1006. __u8 led_count;
  1007. };
  1008. static __u8 *sixaxis_fixup(struct hid_device *hdev, __u8 *rdesc,
  1009. unsigned int *rsize)
  1010. {
  1011. *rsize = sizeof(sixaxis_rdesc);
  1012. return sixaxis_rdesc;
  1013. }
  1014. static u8 *motion_fixup(struct hid_device *hdev, u8 *rdesc,
  1015. unsigned int *rsize)
  1016. {
  1017. *rsize = sizeof(motion_rdesc);
  1018. return motion_rdesc;
  1019. }
  1020. static u8 *navigation_fixup(struct hid_device *hdev, u8 *rdesc,
  1021. unsigned int *rsize)
  1022. {
  1023. *rsize = sizeof(navigation_rdesc);
  1024. return navigation_rdesc;
  1025. }
  1026. static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc,
  1027. unsigned int *rsize)
  1028. {
  1029. *rsize = sizeof(ps3remote_rdesc);
  1030. return ps3remote_rdesc;
  1031. }
  1032. static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi,
  1033. struct hid_field *field, struct hid_usage *usage,
  1034. unsigned long **bit, int *max)
  1035. {
  1036. unsigned int key = usage->hid & HID_USAGE;
  1037. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
  1038. return -1;
  1039. switch (usage->collection_index) {
  1040. case 1:
  1041. if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons))
  1042. return -1;
  1043. key = ps3remote_keymap_joypad_buttons[key];
  1044. if (!key)
  1045. return -1;
  1046. break;
  1047. case 2:
  1048. if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons))
  1049. return -1;
  1050. key = ps3remote_keymap_remote_buttons[key];
  1051. if (!key)
  1052. return -1;
  1053. break;
  1054. default:
  1055. return -1;
  1056. }
  1057. hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
  1058. return 1;
  1059. }
  1060. static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  1061. unsigned int *rsize)
  1062. {
  1063. struct sony_sc *sc = hid_get_drvdata(hdev);
  1064. /*
  1065. * Some Sony RF receivers wrongly declare the mouse pointer as a
  1066. * a constant non-data variable.
  1067. */
  1068. if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 &&
  1069. /* usage page: generic desktop controls */
  1070. /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */
  1071. /* usage: mouse */
  1072. rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
  1073. /* input (usage page for x,y axes): constant, variable, relative */
  1074. rdesc[54] == 0x81 && rdesc[55] == 0x07) {
  1075. hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n");
  1076. /* input: data, variable, relative */
  1077. rdesc[55] = 0x06;
  1078. }
  1079. /*
  1080. * The default Dualshock 4 USB descriptor doesn't assign
  1081. * the gyroscope values to corresponding axes so we need a
  1082. * modified one.
  1083. */
  1084. if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && *rsize == 467) {
  1085. hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n");
  1086. rdesc = dualshock4_usb_rdesc;
  1087. *rsize = sizeof(dualshock4_usb_rdesc);
  1088. } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && *rsize == 357) {
  1089. hid_info(hdev, "Using modified Dualshock 4 Bluetooth report descriptor\n");
  1090. rdesc = dualshock4_bt_rdesc;
  1091. *rsize = sizeof(dualshock4_bt_rdesc);
  1092. }
  1093. if (sc->quirks & SIXAXIS_CONTROLLER)
  1094. return sixaxis_fixup(hdev, rdesc, rsize);
  1095. if (sc->quirks & MOTION_CONTROLLER)
  1096. return motion_fixup(hdev, rdesc, rsize);
  1097. if (sc->quirks & NAVIGATION_CONTROLLER)
  1098. return navigation_fixup(hdev, rdesc, rsize);
  1099. if (sc->quirks & PS3REMOTE)
  1100. return ps3remote_fixup(hdev, rdesc, rsize);
  1101. return rdesc;
  1102. }
  1103. static void sixaxis_parse_report(struct sony_sc *sc, __u8 *rd, int size)
  1104. {
  1105. static const __u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 };
  1106. unsigned long flags;
  1107. int offset;
  1108. __u8 cable_state, battery_capacity, battery_charging;
  1109. /*
  1110. * The sixaxis is charging if the battery value is 0xee
  1111. * and it is fully charged if the value is 0xef.
  1112. * It does not report the actual level while charging so it
  1113. * is set to 100% while charging is in progress.
  1114. */
  1115. offset = (sc->quirks & MOTION_CONTROLLER) ? 12 : 30;
  1116. if (rd[offset] >= 0xee) {
  1117. battery_capacity = 100;
  1118. battery_charging = !(rd[offset] & 0x01);
  1119. cable_state = 1;
  1120. } else {
  1121. __u8 index = rd[offset] <= 5 ? rd[offset] : 5;
  1122. battery_capacity = sixaxis_battery_capacity[index];
  1123. battery_charging = 0;
  1124. cable_state = 0;
  1125. }
  1126. spin_lock_irqsave(&sc->lock, flags);
  1127. sc->cable_state = cable_state;
  1128. sc->battery_capacity = battery_capacity;
  1129. sc->battery_charging = battery_charging;
  1130. spin_unlock_irqrestore(&sc->lock, flags);
  1131. }
  1132. static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size)
  1133. {
  1134. struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
  1135. struct hid_input, list);
  1136. struct input_dev *input_dev = hidinput->input;
  1137. unsigned long flags;
  1138. int n, offset;
  1139. __u8 cable_state, battery_capacity, battery_charging;
  1140. /*
  1141. * Battery and touchpad data starts at byte 30 in the USB report and
  1142. * 32 in Bluetooth report.
  1143. */
  1144. offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 30 : 32;
  1145. /*
  1146. * The lower 4 bits of byte 30 contain the battery level
  1147. * and the 5th bit contains the USB cable state.
  1148. */
  1149. cable_state = (rd[offset] >> 4) & 0x01;
  1150. battery_capacity = rd[offset] & 0x0F;
  1151. /*
  1152. * When a USB power source is connected the battery level ranges from
  1153. * 0 to 10, and when running on battery power it ranges from 0 to 9.
  1154. * A battery level above 10 when plugged in means charge completed.
  1155. */
  1156. if (!cable_state || battery_capacity > 10)
  1157. battery_charging = 0;
  1158. else
  1159. battery_charging = 1;
  1160. if (!cable_state)
  1161. battery_capacity++;
  1162. if (battery_capacity > 10)
  1163. battery_capacity = 10;
  1164. battery_capacity *= 10;
  1165. spin_lock_irqsave(&sc->lock, flags);
  1166. sc->cable_state = cable_state;
  1167. sc->battery_capacity = battery_capacity;
  1168. sc->battery_charging = battery_charging;
  1169. spin_unlock_irqrestore(&sc->lock, flags);
  1170. offset += 5;
  1171. /*
  1172. * The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB
  1173. * and 37 on Bluetooth.
  1174. * The first 7 bits of the first byte is a counter and bit 8 is a touch
  1175. * indicator that is 0 when pressed and 1 when not pressed.
  1176. * The next 3 bytes are two 12 bit touch coordinates, X and Y.
  1177. * The data for the second touch is in the same format and immediatly
  1178. * follows the data for the first.
  1179. */
  1180. for (n = 0; n < 2; n++) {
  1181. __u16 x, y;
  1182. x = rd[offset+1] | ((rd[offset+2] & 0xF) << 8);
  1183. y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4);
  1184. input_mt_slot(input_dev, n);
  1185. input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
  1186. !(rd[offset] >> 7));
  1187. input_report_abs(input_dev, ABS_MT_POSITION_X, x);
  1188. input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
  1189. offset += 4;
  1190. }
  1191. }
  1192. static int sony_raw_event(struct hid_device *hdev, struct hid_report *report,
  1193. __u8 *rd, int size)
  1194. {
  1195. struct sony_sc *sc = hid_get_drvdata(hdev);
  1196. /*
  1197. * Sixaxis HID report has acclerometers/gyro with MSByte first, this
  1198. * has to be BYTE_SWAPPED before passing up to joystick interface
  1199. */
  1200. if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) {
  1201. swap(rd[41], rd[42]);
  1202. swap(rd[43], rd[44]);
  1203. swap(rd[45], rd[46]);
  1204. swap(rd[47], rd[48]);
  1205. sixaxis_parse_report(sc, rd, size);
  1206. } else if ((sc->quirks & MOTION_CONTROLLER_BT) && rd[0] == 0x01 && size == 49) {
  1207. sixaxis_parse_report(sc, rd, size);
  1208. } else if ((sc->quirks & NAVIGATION_CONTROLLER) && rd[0] == 0x01 &&
  1209. size == 49) {
  1210. sixaxis_parse_report(sc, rd, size);
  1211. } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 &&
  1212. size == 64) || ((sc->quirks & DUALSHOCK4_CONTROLLER_BT)
  1213. && rd[0] == 0x11 && size == 78)) {
  1214. dualshock4_parse_report(sc, rd, size);
  1215. }
  1216. return 0;
  1217. }
  1218. static int sony_mapping(struct hid_device *hdev, struct hid_input *hi,
  1219. struct hid_field *field, struct hid_usage *usage,
  1220. unsigned long **bit, int *max)
  1221. {
  1222. struct sony_sc *sc = hid_get_drvdata(hdev);
  1223. if (sc->quirks & BUZZ_CONTROLLER) {
  1224. unsigned int key = usage->hid & HID_USAGE;
  1225. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
  1226. return -1;
  1227. switch (usage->collection_index) {
  1228. case 1:
  1229. if (key >= ARRAY_SIZE(buzz_keymap))
  1230. return -1;
  1231. key = buzz_keymap[key];
  1232. if (!key)
  1233. return -1;
  1234. break;
  1235. default:
  1236. return -1;
  1237. }
  1238. hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
  1239. return 1;
  1240. }
  1241. if (sc->quirks & PS3REMOTE)
  1242. return ps3remote_mapping(hdev, hi, field, usage, bit, max);
  1243. /* Let hid-core decide for the others */
  1244. return 0;
  1245. }
  1246. static int sony_register_touchpad(struct hid_input *hi, int touch_count,
  1247. int w, int h)
  1248. {
  1249. struct input_dev *input_dev = hi->input;
  1250. int ret;
  1251. ret = input_mt_init_slots(input_dev, touch_count, 0);
  1252. if (ret < 0)
  1253. return ret;
  1254. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, w, 0, 0);
  1255. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, h, 0, 0);
  1256. return 0;
  1257. }
  1258. static void sony_input_configured(struct hid_device *hdev,
  1259. struct hid_input *hidinput)
  1260. {
  1261. struct sony_sc *sc = hid_get_drvdata(hdev);
  1262. /*
  1263. * The Dualshock 4 touchpad supports 2 touches and has a
  1264. * resolution of 1920x942 (44.86 dots/mm).
  1265. */
  1266. if (sc->quirks & DUALSHOCK4_CONTROLLER) {
  1267. if (sony_register_touchpad(hidinput, 2, 1920, 942) != 0)
  1268. hid_err(sc->hdev,
  1269. "Unable to initialize multi-touch slots\n");
  1270. }
  1271. }
  1272. /*
  1273. * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
  1274. * to "operational". Without this, the ps3 controller will not report any
  1275. * events.
  1276. */
  1277. static int sixaxis_set_operational_usb(struct hid_device *hdev)
  1278. {
  1279. const int buf_size =
  1280. max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE);
  1281. __u8 *buf;
  1282. int ret;
  1283. buf = kmalloc(buf_size, GFP_KERNEL);
  1284. if (!buf)
  1285. return -ENOMEM;
  1286. ret = hid_hw_raw_request(hdev, 0xf2, buf, SIXAXIS_REPORT_0xF2_SIZE,
  1287. HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
  1288. if (ret < 0) {
  1289. hid_err(hdev, "can't set operational mode: step 1\n");
  1290. goto out;
  1291. }
  1292. /*
  1293. * Some compatible controllers like the Speedlink Strike FX and
  1294. * Gasia need another query plus an USB interrupt to get operational.
  1295. */
  1296. ret = hid_hw_raw_request(hdev, 0xf5, buf, SIXAXIS_REPORT_0xF5_SIZE,
  1297. HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
  1298. if (ret < 0) {
  1299. hid_err(hdev, "can't set operational mode: step 2\n");
  1300. goto out;
  1301. }
  1302. ret = hid_hw_output_report(hdev, buf, 1);
  1303. if (ret < 0)
  1304. hid_err(hdev, "can't set operational mode: step 3\n");
  1305. out:
  1306. kfree(buf);
  1307. return ret;
  1308. }
  1309. static int sixaxis_set_operational_bt(struct hid_device *hdev)
  1310. {
  1311. static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
  1312. __u8 *buf;
  1313. int ret;
  1314. buf = kmemdup(report, sizeof(report), GFP_KERNEL);
  1315. if (!buf)
  1316. return -ENOMEM;
  1317. ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
  1318. HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
  1319. kfree(buf);
  1320. return ret;
  1321. }
  1322. /*
  1323. * Requesting feature report 0x02 in Bluetooth mode changes the state of the
  1324. * controller so that it sends full input reports of type 0x11.
  1325. */
  1326. static int dualshock4_set_operational_bt(struct hid_device *hdev)
  1327. {
  1328. __u8 *buf;
  1329. int ret;
  1330. buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
  1331. if (!buf)
  1332. return -ENOMEM;
  1333. ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
  1334. HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
  1335. kfree(buf);
  1336. return ret;
  1337. }
  1338. static void sixaxis_set_leds_from_id(struct sony_sc *sc)
  1339. {
  1340. static const __u8 sixaxis_leds[10][4] = {
  1341. { 0x01, 0x00, 0x00, 0x00 },
  1342. { 0x00, 0x01, 0x00, 0x00 },
  1343. { 0x00, 0x00, 0x01, 0x00 },
  1344. { 0x00, 0x00, 0x00, 0x01 },
  1345. { 0x01, 0x00, 0x00, 0x01 },
  1346. { 0x00, 0x01, 0x00, 0x01 },
  1347. { 0x00, 0x00, 0x01, 0x01 },
  1348. { 0x01, 0x00, 0x01, 0x01 },
  1349. { 0x00, 0x01, 0x01, 0x01 },
  1350. { 0x01, 0x01, 0x01, 0x01 }
  1351. };
  1352. int id = sc->device_id;
  1353. BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(sixaxis_leds[0]));
  1354. if (id < 0)
  1355. return;
  1356. id %= 10;
  1357. memcpy(sc->led_state, sixaxis_leds[id], sizeof(sixaxis_leds[id]));
  1358. }
  1359. static void dualshock4_set_leds_from_id(struct sony_sc *sc)
  1360. {
  1361. /* The first 4 color/index entries match what the PS4 assigns */
  1362. static const __u8 color_code[7][3] = {
  1363. /* Blue */ { 0x00, 0x00, 0x01 },
  1364. /* Red */ { 0x01, 0x00, 0x00 },
  1365. /* Green */ { 0x00, 0x01, 0x00 },
  1366. /* Pink */ { 0x02, 0x00, 0x01 },
  1367. /* Orange */ { 0x02, 0x01, 0x00 },
  1368. /* Teal */ { 0x00, 0x01, 0x01 },
  1369. /* White */ { 0x01, 0x01, 0x01 }
  1370. };
  1371. int id = sc->device_id;
  1372. BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(color_code[0]));
  1373. if (id < 0)
  1374. return;
  1375. id %= 7;
  1376. memcpy(sc->led_state, color_code[id], sizeof(color_code[id]));
  1377. }
  1378. static void buzz_set_leds(struct sony_sc *sc)
  1379. {
  1380. struct hid_device *hdev = sc->hdev;
  1381. struct list_head *report_list =
  1382. &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
  1383. struct hid_report *report = list_entry(report_list->next,
  1384. struct hid_report, list);
  1385. __s32 *value = report->field[0]->value;
  1386. BUILD_BUG_ON(MAX_LEDS < 4);
  1387. value[0] = 0x00;
  1388. value[1] = sc->led_state[0] ? 0xff : 0x00;
  1389. value[2] = sc->led_state[1] ? 0xff : 0x00;
  1390. value[3] = sc->led_state[2] ? 0xff : 0x00;
  1391. value[4] = sc->led_state[3] ? 0xff : 0x00;
  1392. value[5] = 0x00;
  1393. value[6] = 0x00;
  1394. hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
  1395. }
  1396. static void sony_set_leds(struct sony_sc *sc)
  1397. {
  1398. if (!(sc->quirks & BUZZ_CONTROLLER))
  1399. schedule_work(&sc->state_worker);
  1400. else
  1401. buzz_set_leds(sc);
  1402. }
  1403. static void sony_led_set_brightness(struct led_classdev *led,
  1404. enum led_brightness value)
  1405. {
  1406. struct device *dev = led->dev->parent;
  1407. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1408. struct sony_sc *drv_data;
  1409. int n;
  1410. int force_update;
  1411. drv_data = hid_get_drvdata(hdev);
  1412. if (!drv_data) {
  1413. hid_err(hdev, "No device data\n");
  1414. return;
  1415. }
  1416. /*
  1417. * The Sixaxis on USB will override any LED settings sent to it
  1418. * and keep flashing all of the LEDs until the PS button is pressed.
  1419. * Updates, even if redundant, must be always be sent to the
  1420. * controller to avoid having to toggle the state of an LED just to
  1421. * stop the flashing later on.
  1422. */
  1423. force_update = !!(drv_data->quirks & SIXAXIS_CONTROLLER_USB);
  1424. for (n = 0; n < drv_data->led_count; n++) {
  1425. if (led == drv_data->leds[n] && (force_update ||
  1426. (value != drv_data->led_state[n] ||
  1427. drv_data->led_delay_on[n] ||
  1428. drv_data->led_delay_off[n]))) {
  1429. drv_data->led_state[n] = value;
  1430. /* Setting the brightness stops the blinking */
  1431. drv_data->led_delay_on[n] = 0;
  1432. drv_data->led_delay_off[n] = 0;
  1433. sony_set_leds(drv_data);
  1434. break;
  1435. }
  1436. }
  1437. }
  1438. static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
  1439. {
  1440. struct device *dev = led->dev->parent;
  1441. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1442. struct sony_sc *drv_data;
  1443. int n;
  1444. drv_data = hid_get_drvdata(hdev);
  1445. if (!drv_data) {
  1446. hid_err(hdev, "No device data\n");
  1447. return LED_OFF;
  1448. }
  1449. for (n = 0; n < drv_data->led_count; n++) {
  1450. if (led == drv_data->leds[n])
  1451. return drv_data->led_state[n];
  1452. }
  1453. return LED_OFF;
  1454. }
  1455. static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on,
  1456. unsigned long *delay_off)
  1457. {
  1458. struct device *dev = led->dev->parent;
  1459. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1460. struct sony_sc *drv_data = hid_get_drvdata(hdev);
  1461. int n;
  1462. __u8 new_on, new_off;
  1463. if (!drv_data) {
  1464. hid_err(hdev, "No device data\n");
  1465. return -EINVAL;
  1466. }
  1467. /* Max delay is 255 deciseconds or 2550 milliseconds */
  1468. if (*delay_on > 2550)
  1469. *delay_on = 2550;
  1470. if (*delay_off > 2550)
  1471. *delay_off = 2550;
  1472. /* Blink at 1 Hz if both values are zero */
  1473. if (!*delay_on && !*delay_off)
  1474. *delay_on = *delay_off = 500;
  1475. new_on = *delay_on / 10;
  1476. new_off = *delay_off / 10;
  1477. for (n = 0; n < drv_data->led_count; n++) {
  1478. if (led == drv_data->leds[n])
  1479. break;
  1480. }
  1481. /* This LED is not registered on this device */
  1482. if (n >= drv_data->led_count)
  1483. return -EINVAL;
  1484. /* Don't schedule work if the values didn't change */
  1485. if (new_on != drv_data->led_delay_on[n] ||
  1486. new_off != drv_data->led_delay_off[n]) {
  1487. drv_data->led_delay_on[n] = new_on;
  1488. drv_data->led_delay_off[n] = new_off;
  1489. schedule_work(&drv_data->state_worker);
  1490. }
  1491. return 0;
  1492. }
  1493. static void sony_leds_remove(struct sony_sc *sc)
  1494. {
  1495. struct led_classdev *led;
  1496. int n;
  1497. BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
  1498. for (n = 0; n < sc->led_count; n++) {
  1499. led = sc->leds[n];
  1500. sc->leds[n] = NULL;
  1501. if (!led)
  1502. continue;
  1503. led_classdev_unregister(led);
  1504. kfree(led);
  1505. }
  1506. sc->led_count = 0;
  1507. }
  1508. static int sony_leds_init(struct sony_sc *sc)
  1509. {
  1510. struct hid_device *hdev = sc->hdev;
  1511. int n, ret = 0;
  1512. int use_ds4_names;
  1513. struct led_classdev *led;
  1514. size_t name_sz;
  1515. char *name;
  1516. size_t name_len;
  1517. const char *name_fmt;
  1518. static const char * const ds4_name_str[] = { "red", "green", "blue",
  1519. "global" };
  1520. __u8 max_brightness[MAX_LEDS] = { [0 ... (MAX_LEDS - 1)] = 1 };
  1521. __u8 use_hw_blink[MAX_LEDS] = { 0 };
  1522. BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
  1523. if (sc->quirks & BUZZ_CONTROLLER) {
  1524. sc->led_count = 4;
  1525. use_ds4_names = 0;
  1526. name_len = strlen("::buzz#");
  1527. name_fmt = "%s::buzz%d";
  1528. /* Validate expected report characteristics. */
  1529. if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
  1530. return -ENODEV;
  1531. } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
  1532. dualshock4_set_leds_from_id(sc);
  1533. sc->led_state[3] = 1;
  1534. sc->led_count = 4;
  1535. memset(max_brightness, 255, 3);
  1536. use_hw_blink[3] = 1;
  1537. use_ds4_names = 1;
  1538. name_len = 0;
  1539. name_fmt = "%s:%s";
  1540. } else if (sc->quirks & MOTION_CONTROLLER) {
  1541. sc->led_count = 3;
  1542. memset(max_brightness, 255, 3);
  1543. use_ds4_names = 1;
  1544. name_len = 0;
  1545. name_fmt = "%s:%s";
  1546. } else if (sc->quirks & NAVIGATION_CONTROLLER) {
  1547. static const __u8 navigation_leds[4] = {0x01, 0x00, 0x00, 0x00};
  1548. memcpy(sc->led_state, navigation_leds, sizeof(navigation_leds));
  1549. sc->led_count = 1;
  1550. memset(use_hw_blink, 1, 4);
  1551. use_ds4_names = 0;
  1552. name_len = strlen("::sony#");
  1553. name_fmt = "%s::sony%d";
  1554. } else {
  1555. sixaxis_set_leds_from_id(sc);
  1556. sc->led_count = 4;
  1557. memset(use_hw_blink, 1, 4);
  1558. use_ds4_names = 0;
  1559. name_len = strlen("::sony#");
  1560. name_fmt = "%s::sony%d";
  1561. }
  1562. /*
  1563. * Clear LEDs as we have no way of reading their initial state. This is
  1564. * only relevant if the driver is loaded after somebody actively set the
  1565. * LEDs to on
  1566. */
  1567. sony_set_leds(sc);
  1568. name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;
  1569. for (n = 0; n < sc->led_count; n++) {
  1570. if (use_ds4_names)
  1571. name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2;
  1572. led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
  1573. if (!led) {
  1574. hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
  1575. ret = -ENOMEM;
  1576. goto error_leds;
  1577. }
  1578. name = (void *)(&led[1]);
  1579. if (use_ds4_names)
  1580. snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev),
  1581. ds4_name_str[n]);
  1582. else
  1583. snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1);
  1584. led->name = name;
  1585. led->brightness = sc->led_state[n];
  1586. led->max_brightness = max_brightness[n];
  1587. led->brightness_get = sony_led_get_brightness;
  1588. led->brightness_set = sony_led_set_brightness;
  1589. if (use_hw_blink[n])
  1590. led->blink_set = sony_led_blink_set;
  1591. sc->leds[n] = led;
  1592. ret = led_classdev_register(&hdev->dev, led);
  1593. if (ret) {
  1594. hid_err(hdev, "Failed to register LED %d\n", n);
  1595. sc->leds[n] = NULL;
  1596. kfree(led);
  1597. goto error_leds;
  1598. }
  1599. }
  1600. return ret;
  1601. error_leds:
  1602. sony_leds_remove(sc);
  1603. return ret;
  1604. }
  1605. static void sixaxis_state_worker(struct work_struct *work)
  1606. {
  1607. static const union sixaxis_output_report_01 default_report = {
  1608. .buf = {
  1609. 0x01,
  1610. 0x00, 0xff, 0x00, 0xff, 0x00,
  1611. 0x00, 0x00, 0x00, 0x00, 0x00,
  1612. 0xff, 0x27, 0x10, 0x00, 0x32,
  1613. 0xff, 0x27, 0x10, 0x00, 0x32,
  1614. 0xff, 0x27, 0x10, 0x00, 0x32,
  1615. 0xff, 0x27, 0x10, 0x00, 0x32,
  1616. 0x00, 0x00, 0x00, 0x00, 0x00
  1617. }
  1618. };
  1619. struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
  1620. struct sixaxis_output_report *report =
  1621. (struct sixaxis_output_report *)sc->output_report_dmabuf;
  1622. int n;
  1623. /* Initialize the report with default values */
  1624. memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
  1625. #ifdef CONFIG_SONY_FF
  1626. report->rumble.right_motor_on = sc->right ? 1 : 0;
  1627. report->rumble.left_motor_force = sc->left;
  1628. #endif
  1629. report->leds_bitmap |= sc->led_state[0] << 1;
  1630. report->leds_bitmap |= sc->led_state[1] << 2;
  1631. report->leds_bitmap |= sc->led_state[2] << 3;
  1632. report->leds_bitmap |= sc->led_state[3] << 4;
  1633. /* Set flag for all leds off, required for 3rd party INTEC controller */
  1634. if ((report->leds_bitmap & 0x1E) == 0)
  1635. report->leds_bitmap |= 0x20;
  1636. /*
  1637. * The LEDs in the report are indexed in reverse order to their
  1638. * corresponding light on the controller.
  1639. * Index 0 = LED 4, index 1 = LED 3, etc...
  1640. *
  1641. * In the case of both delay values being zero (blinking disabled) the
  1642. * default report values should be used or the controller LED will be
  1643. * always off.
  1644. */
  1645. for (n = 0; n < 4; n++) {
  1646. if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
  1647. report->led[3 - n].duty_off = sc->led_delay_off[n];
  1648. report->led[3 - n].duty_on = sc->led_delay_on[n];
  1649. }
  1650. }
  1651. hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
  1652. sizeof(struct sixaxis_output_report),
  1653. HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
  1654. }
  1655. static void dualshock4_state_worker(struct work_struct *work)
  1656. {
  1657. struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
  1658. struct hid_device *hdev = sc->hdev;
  1659. __u8 *buf = sc->output_report_dmabuf;
  1660. int offset;
  1661. if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
  1662. memset(buf, 0, DS4_REPORT_0x05_SIZE);
  1663. buf[0] = 0x05;
  1664. buf[1] = 0xFF;
  1665. offset = 4;
  1666. } else {
  1667. memset(buf, 0, DS4_REPORT_0x11_SIZE);
  1668. buf[0] = 0x11;
  1669. buf[1] = 0xB0;
  1670. buf[3] = 0x0F;
  1671. offset = 6;
  1672. }
  1673. #ifdef CONFIG_SONY_FF
  1674. buf[offset++] = sc->right;
  1675. buf[offset++] = sc->left;
  1676. #else
  1677. offset += 2;
  1678. #endif
  1679. /* LED 3 is the global control */
  1680. if (sc->led_state[3]) {
  1681. buf[offset++] = sc->led_state[0];
  1682. buf[offset++] = sc->led_state[1];
  1683. buf[offset++] = sc->led_state[2];
  1684. } else {
  1685. offset += 3;
  1686. }
  1687. /* If both delay values are zero the DualShock 4 disables blinking. */
  1688. buf[offset++] = sc->led_delay_on[3];
  1689. buf[offset++] = sc->led_delay_off[3];
  1690. if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
  1691. hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
  1692. else
  1693. hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
  1694. HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
  1695. }
  1696. static void motion_state_worker(struct work_struct *work)
  1697. {
  1698. struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
  1699. struct hid_device *hdev = sc->hdev;
  1700. struct motion_output_report_02 *report =
  1701. (struct motion_output_report_02 *)sc->output_report_dmabuf;
  1702. memset(report, 0, MOTION_REPORT_0x02_SIZE);
  1703. report->type = 0x02; /* set leds */
  1704. report->r = sc->led_state[0];
  1705. report->g = sc->led_state[1];
  1706. report->b = sc->led_state[2];
  1707. #ifdef CONFIG_SONY_FF
  1708. report->rumble = max(sc->right, sc->left);
  1709. #endif
  1710. hid_hw_output_report(hdev, (__u8 *)report, MOTION_REPORT_0x02_SIZE);
  1711. }
  1712. static int sony_allocate_output_report(struct sony_sc *sc)
  1713. {
  1714. if ((sc->quirks & SIXAXIS_CONTROLLER) ||
  1715. (sc->quirks & NAVIGATION_CONTROLLER))
  1716. sc->output_report_dmabuf =
  1717. kmalloc(sizeof(union sixaxis_output_report_01),
  1718. GFP_KERNEL);
  1719. else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
  1720. sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
  1721. GFP_KERNEL);
  1722. else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
  1723. sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
  1724. GFP_KERNEL);
  1725. else if (sc->quirks & MOTION_CONTROLLER)
  1726. sc->output_report_dmabuf = kmalloc(MOTION_REPORT_0x02_SIZE,
  1727. GFP_KERNEL);
  1728. else
  1729. return 0;
  1730. if (!sc->output_report_dmabuf)
  1731. return -ENOMEM;
  1732. return 0;
  1733. }
  1734. #ifdef CONFIG_SONY_FF
  1735. static int sony_play_effect(struct input_dev *dev, void *data,
  1736. struct ff_effect *effect)
  1737. {
  1738. struct hid_device *hid = input_get_drvdata(dev);
  1739. struct sony_sc *sc = hid_get_drvdata(hid);
  1740. if (effect->type != FF_RUMBLE)
  1741. return 0;
  1742. sc->left = effect->u.rumble.strong_magnitude / 256;
  1743. sc->right = effect->u.rumble.weak_magnitude / 256;
  1744. schedule_work(&sc->state_worker);
  1745. return 0;
  1746. }
  1747. static int sony_init_ff(struct sony_sc *sc)
  1748. {
  1749. struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
  1750. struct hid_input, list);
  1751. struct input_dev *input_dev = hidinput->input;
  1752. input_set_capability(input_dev, EV_FF, FF_RUMBLE);
  1753. return input_ff_create_memless(input_dev, NULL, sony_play_effect);
  1754. }
  1755. #else
  1756. static int sony_init_ff(struct sony_sc *sc)
  1757. {
  1758. return 0;
  1759. }
  1760. #endif
  1761. static int sony_battery_get_property(struct power_supply *psy,
  1762. enum power_supply_property psp,
  1763. union power_supply_propval *val)
  1764. {
  1765. struct sony_sc *sc = power_supply_get_drvdata(psy);
  1766. unsigned long flags;
  1767. int ret = 0;
  1768. u8 battery_charging, battery_capacity, cable_state;
  1769. spin_lock_irqsave(&sc->lock, flags);
  1770. battery_charging = sc->battery_charging;
  1771. battery_capacity = sc->battery_capacity;
  1772. cable_state = sc->cable_state;
  1773. spin_unlock_irqrestore(&sc->lock, flags);
  1774. switch (psp) {
  1775. case POWER_SUPPLY_PROP_PRESENT:
  1776. val->intval = 1;
  1777. break;
  1778. case POWER_SUPPLY_PROP_SCOPE:
  1779. val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  1780. break;
  1781. case POWER_SUPPLY_PROP_CAPACITY:
  1782. val->intval = battery_capacity;
  1783. break;
  1784. case POWER_SUPPLY_PROP_STATUS:
  1785. if (battery_charging)
  1786. val->intval = POWER_SUPPLY_STATUS_CHARGING;
  1787. else
  1788. if (battery_capacity == 100 && cable_state)
  1789. val->intval = POWER_SUPPLY_STATUS_FULL;
  1790. else
  1791. val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
  1792. break;
  1793. default:
  1794. ret = -EINVAL;
  1795. break;
  1796. }
  1797. return ret;
  1798. }
  1799. static int sony_battery_probe(struct sony_sc *sc)
  1800. {
  1801. struct power_supply_config psy_cfg = { .drv_data = sc, };
  1802. struct hid_device *hdev = sc->hdev;
  1803. int ret;
  1804. /*
  1805. * Set the default battery level to 100% to avoid low battery warnings
  1806. * if the battery is polled before the first device report is received.
  1807. */
  1808. sc->battery_capacity = 100;
  1809. sc->battery_desc.properties = sony_battery_props;
  1810. sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props);
  1811. sc->battery_desc.get_property = sony_battery_get_property;
  1812. sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
  1813. sc->battery_desc.use_for_apm = 0;
  1814. sc->battery_desc.name = kasprintf(GFP_KERNEL,
  1815. "sony_controller_battery_%pMR",
  1816. sc->mac_address);
  1817. if (!sc->battery_desc.name)
  1818. return -ENOMEM;
  1819. sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc,
  1820. &psy_cfg);
  1821. if (IS_ERR(sc->battery)) {
  1822. ret = PTR_ERR(sc->battery);
  1823. hid_err(hdev, "Unable to register battery device\n");
  1824. goto err_free;
  1825. }
  1826. power_supply_powers(sc->battery, &hdev->dev);
  1827. return 0;
  1828. err_free:
  1829. kfree(sc->battery_desc.name);
  1830. sc->battery_desc.name = NULL;
  1831. return ret;
  1832. }
  1833. static void sony_battery_remove(struct sony_sc *sc)
  1834. {
  1835. if (!sc->battery_desc.name)
  1836. return;
  1837. power_supply_unregister(sc->battery);
  1838. kfree(sc->battery_desc.name);
  1839. sc->battery_desc.name = NULL;
  1840. }
  1841. /*
  1842. * If a controller is plugged in via USB while already connected via Bluetooth
  1843. * it will show up as two devices. A global list of connected controllers and
  1844. * their MAC addresses is maintained to ensure that a device is only connected
  1845. * once.
  1846. */
  1847. static int sony_check_add_dev_list(struct sony_sc *sc)
  1848. {
  1849. struct sony_sc *entry;
  1850. unsigned long flags;
  1851. int ret;
  1852. spin_lock_irqsave(&sony_dev_list_lock, flags);
  1853. list_for_each_entry(entry, &sony_device_list, list_node) {
  1854. ret = memcmp(sc->mac_address, entry->mac_address,
  1855. sizeof(sc->mac_address));
  1856. if (!ret) {
  1857. ret = -EEXIST;
  1858. hid_info(sc->hdev, "controller with MAC address %pMR already connected\n",
  1859. sc->mac_address);
  1860. goto unlock;
  1861. }
  1862. }
  1863. ret = 0;
  1864. list_add(&(sc->list_node), &sony_device_list);
  1865. unlock:
  1866. spin_unlock_irqrestore(&sony_dev_list_lock, flags);
  1867. return ret;
  1868. }
  1869. static void sony_remove_dev_list(struct sony_sc *sc)
  1870. {
  1871. unsigned long flags;
  1872. if (sc->list_node.next) {
  1873. spin_lock_irqsave(&sony_dev_list_lock, flags);
  1874. list_del(&(sc->list_node));
  1875. spin_unlock_irqrestore(&sony_dev_list_lock, flags);
  1876. }
  1877. }
  1878. static int sony_get_bt_devaddr(struct sony_sc *sc)
  1879. {
  1880. int ret;
  1881. /* HIDP stores the device MAC address as a string in the uniq field. */
  1882. ret = strlen(sc->hdev->uniq);
  1883. if (ret != 17)
  1884. return -EINVAL;
  1885. ret = sscanf(sc->hdev->uniq,
  1886. "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  1887. &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3],
  1888. &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]);
  1889. if (ret != 6)
  1890. return -EINVAL;
  1891. return 0;
  1892. }
  1893. static int sony_check_add(struct sony_sc *sc)
  1894. {
  1895. __u8 *buf = NULL;
  1896. int n, ret;
  1897. if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
  1898. (sc->quirks & MOTION_CONTROLLER_BT) ||
  1899. (sc->quirks & NAVIGATION_CONTROLLER_BT) ||
  1900. (sc->quirks & SIXAXIS_CONTROLLER_BT)) {
  1901. /*
  1902. * sony_get_bt_devaddr() attempts to parse the Bluetooth MAC
  1903. * address from the uniq string where HIDP stores it.
  1904. * As uniq cannot be guaranteed to be a MAC address in all cases
  1905. * a failure of this function should not prevent the connection.
  1906. */
  1907. if (sony_get_bt_devaddr(sc) < 0) {
  1908. hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n");
  1909. return 0;
  1910. }
  1911. } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
  1912. buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
  1913. if (!buf)
  1914. return -ENOMEM;
  1915. /*
  1916. * The MAC address of a DS4 controller connected via USB can be
  1917. * retrieved with feature report 0x81. The address begins at
  1918. * offset 1.
  1919. */
  1920. ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
  1921. DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
  1922. HID_REQ_GET_REPORT);
  1923. if (ret != DS4_REPORT_0x81_SIZE) {
  1924. hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
  1925. ret = ret < 0 ? ret : -EINVAL;
  1926. goto out_free;
  1927. }
  1928. memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
  1929. } else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
  1930. (sc->quirks & NAVIGATION_CONTROLLER_USB)) {
  1931. buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
  1932. if (!buf)
  1933. return -ENOMEM;
  1934. /*
  1935. * The MAC address of a Sixaxis controller connected via USB can
  1936. * be retrieved with feature report 0xf2. The address begins at
  1937. * offset 4.
  1938. */
  1939. ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
  1940. SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
  1941. HID_REQ_GET_REPORT);
  1942. if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
  1943. hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
  1944. ret = ret < 0 ? ret : -EINVAL;
  1945. goto out_free;
  1946. }
  1947. /*
  1948. * The Sixaxis device MAC in the report is big-endian and must
  1949. * be byte-swapped.
  1950. */
  1951. for (n = 0; n < 6; n++)
  1952. sc->mac_address[5-n] = buf[4+n];
  1953. } else {
  1954. return 0;
  1955. }
  1956. ret = sony_check_add_dev_list(sc);
  1957. out_free:
  1958. kfree(buf);
  1959. return ret;
  1960. }
  1961. static int sony_set_device_id(struct sony_sc *sc)
  1962. {
  1963. int ret;
  1964. /*
  1965. * Only DualShock 4 or Sixaxis controllers get an id.
  1966. * All others are set to -1.
  1967. */
  1968. if ((sc->quirks & SIXAXIS_CONTROLLER) ||
  1969. (sc->quirks & DUALSHOCK4_CONTROLLER)) {
  1970. ret = ida_simple_get(&sony_device_id_allocator, 0, 0,
  1971. GFP_KERNEL);
  1972. if (ret < 0) {
  1973. sc->device_id = -1;
  1974. return ret;
  1975. }
  1976. sc->device_id = ret;
  1977. } else {
  1978. sc->device_id = -1;
  1979. }
  1980. return 0;
  1981. }
  1982. static void sony_release_device_id(struct sony_sc *sc)
  1983. {
  1984. if (sc->device_id >= 0) {
  1985. ida_simple_remove(&sony_device_id_allocator, sc->device_id);
  1986. sc->device_id = -1;
  1987. }
  1988. }
  1989. static inline void sony_init_work(struct sony_sc *sc,
  1990. void (*worker)(struct work_struct *))
  1991. {
  1992. if (!sc->worker_initialized)
  1993. INIT_WORK(&sc->state_worker, worker);
  1994. sc->worker_initialized = 1;
  1995. }
  1996. static inline void sony_cancel_work_sync(struct sony_sc *sc)
  1997. {
  1998. if (sc->worker_initialized)
  1999. cancel_work_sync(&sc->state_worker);
  2000. }
  2001. static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
  2002. {
  2003. int ret;
  2004. unsigned long quirks = id->driver_data;
  2005. struct sony_sc *sc;
  2006. unsigned int connect_mask = HID_CONNECT_DEFAULT;
  2007. sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
  2008. if (sc == NULL) {
  2009. hid_err(hdev, "can't alloc sony descriptor\n");
  2010. return -ENOMEM;
  2011. }
  2012. spin_lock_init(&sc->lock);
  2013. sc->quirks = quirks;
  2014. hid_set_drvdata(hdev, sc);
  2015. sc->hdev = hdev;
  2016. ret = hid_parse(hdev);
  2017. if (ret) {
  2018. hid_err(hdev, "parse failed\n");
  2019. return ret;
  2020. }
  2021. if (sc->quirks & VAIO_RDESC_CONSTANT)
  2022. connect_mask |= HID_CONNECT_HIDDEV_FORCE;
  2023. else if (sc->quirks & SIXAXIS_CONTROLLER)
  2024. connect_mask |= HID_CONNECT_HIDDEV_FORCE;
  2025. ret = hid_hw_start(hdev, connect_mask);
  2026. if (ret) {
  2027. hid_err(hdev, "hw start failed\n");
  2028. return ret;
  2029. }
  2030. ret = sony_set_device_id(sc);
  2031. if (ret < 0) {
  2032. hid_err(hdev, "failed to allocate the device id\n");
  2033. goto err_stop;
  2034. }
  2035. ret = sony_allocate_output_report(sc);
  2036. if (ret < 0) {
  2037. hid_err(hdev, "failed to allocate the output report buffer\n");
  2038. goto err_stop;
  2039. }
  2040. if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
  2041. (sc->quirks & NAVIGATION_CONTROLLER_USB)) {
  2042. /*
  2043. * The Sony Sixaxis does not handle HID Output Reports on the
  2044. * Interrupt EP like it could, so we need to force HID Output
  2045. * Reports to use HID_REQ_SET_REPORT on the Control EP.
  2046. *
  2047. * There is also another issue about HID Output Reports via USB,
  2048. * the Sixaxis does not want the report_id as part of the data
  2049. * packet, so we have to discard buf[0] when sending the actual
  2050. * control message, even for numbered reports, humpf!
  2051. */
  2052. hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
  2053. hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID;
  2054. ret = sixaxis_set_operational_usb(hdev);
  2055. sony_init_work(sc, sixaxis_state_worker);
  2056. } else if ((sc->quirks & SIXAXIS_CONTROLLER_BT) ||
  2057. (sc->quirks & NAVIGATION_CONTROLLER_BT)) {
  2058. /*
  2059. * The Sixaxis wants output reports sent on the ctrl endpoint
  2060. * when connected via Bluetooth.
  2061. */
  2062. hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
  2063. ret = sixaxis_set_operational_bt(hdev);
  2064. sony_init_work(sc, sixaxis_state_worker);
  2065. } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
  2066. if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) {
  2067. /*
  2068. * The DualShock 4 wants output reports sent on the ctrl
  2069. * endpoint when connected via Bluetooth.
  2070. */
  2071. hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
  2072. ret = dualshock4_set_operational_bt(hdev);
  2073. if (ret < 0) {
  2074. hid_err(hdev, "failed to set the Dualshock 4 operational mode\n");
  2075. goto err_stop;
  2076. }
  2077. }
  2078. sony_init_work(sc, dualshock4_state_worker);
  2079. } else if (sc->quirks & MOTION_CONTROLLER) {
  2080. sony_init_work(sc, motion_state_worker);
  2081. } else {
  2082. ret = 0;
  2083. }
  2084. if (ret < 0)
  2085. goto err_stop;
  2086. ret = sony_check_add(sc);
  2087. if (ret < 0)
  2088. goto err_stop;
  2089. if (sc->quirks & SONY_LED_SUPPORT) {
  2090. ret = sony_leds_init(sc);
  2091. if (ret < 0)
  2092. goto err_stop;
  2093. }
  2094. if (sc->quirks & SONY_BATTERY_SUPPORT) {
  2095. ret = sony_battery_probe(sc);
  2096. if (ret < 0)
  2097. goto err_stop;
  2098. /* Open the device to receive reports with battery info */
  2099. ret = hid_hw_open(hdev);
  2100. if (ret < 0) {
  2101. hid_err(hdev, "hw open failed\n");
  2102. goto err_stop;
  2103. }
  2104. }
  2105. if (sc->quirks & SONY_FF_SUPPORT) {
  2106. ret = sony_init_ff(sc);
  2107. if (ret < 0)
  2108. goto err_close;
  2109. }
  2110. return 0;
  2111. err_close:
  2112. hid_hw_close(hdev);
  2113. err_stop:
  2114. if (sc->quirks & SONY_LED_SUPPORT)
  2115. sony_leds_remove(sc);
  2116. if (sc->quirks & SONY_BATTERY_SUPPORT)
  2117. sony_battery_remove(sc);
  2118. sony_cancel_work_sync(sc);
  2119. kfree(sc->output_report_dmabuf);
  2120. sony_remove_dev_list(sc);
  2121. sony_release_device_id(sc);
  2122. hid_hw_stop(hdev);
  2123. return ret;
  2124. }
  2125. static void sony_remove(struct hid_device *hdev)
  2126. {
  2127. struct sony_sc *sc = hid_get_drvdata(hdev);
  2128. if (sc->quirks & SONY_LED_SUPPORT)
  2129. sony_leds_remove(sc);
  2130. if (sc->quirks & SONY_BATTERY_SUPPORT) {
  2131. hid_hw_close(hdev);
  2132. sony_battery_remove(sc);
  2133. }
  2134. sony_cancel_work_sync(sc);
  2135. kfree(sc->output_report_dmabuf);
  2136. sony_remove_dev_list(sc);
  2137. sony_release_device_id(sc);
  2138. hid_hw_stop(hdev);
  2139. }
  2140. static const struct hid_device_id sony_devices[] = {
  2141. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
  2142. .driver_data = SIXAXIS_CONTROLLER_USB },
  2143. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
  2144. .driver_data = NAVIGATION_CONTROLLER_USB },
  2145. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
  2146. .driver_data = NAVIGATION_CONTROLLER_BT },
  2147. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER),
  2148. .driver_data = MOTION_CONTROLLER_USB },
  2149. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER),
  2150. .driver_data = MOTION_CONTROLLER_BT },
  2151. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
  2152. .driver_data = SIXAXIS_CONTROLLER_BT },
  2153. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
  2154. .driver_data = VAIO_RDESC_CONSTANT },
  2155. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE),
  2156. .driver_data = VAIO_RDESC_CONSTANT },
  2157. /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as
  2158. * Logitech joystick from the device descriptor. */
  2159. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER),
  2160. .driver_data = BUZZ_CONTROLLER },
  2161. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER),
  2162. .driver_data = BUZZ_CONTROLLER },
  2163. /* PS3 BD Remote Control */
  2164. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE),
  2165. .driver_data = PS3REMOTE },
  2166. /* Logitech Harmony Adapter for PS3 */
  2167. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3),
  2168. .driver_data = PS3REMOTE },
  2169. /* SMK-Link PS3 BD Remote Control */
  2170. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE),
  2171. .driver_data = PS3REMOTE },
  2172. /* Sony Dualshock 4 controllers for PS4 */
  2173. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
  2174. .driver_data = DUALSHOCK4_CONTROLLER_USB },
  2175. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
  2176. .driver_data = DUALSHOCK4_CONTROLLER_BT },
  2177. { }
  2178. };
  2179. MODULE_DEVICE_TABLE(hid, sony_devices);
  2180. static struct hid_driver sony_driver = {
  2181. .name = "sony",
  2182. .id_table = sony_devices,
  2183. .input_mapping = sony_mapping,
  2184. .input_configured = sony_input_configured,
  2185. .probe = sony_probe,
  2186. .remove = sony_remove,
  2187. .report_fixup = sony_report_fixup,
  2188. .raw_event = sony_raw_event
  2189. };
  2190. static int __init sony_init(void)
  2191. {
  2192. dbg_hid("Sony:%s\n", __func__);
  2193. return hid_register_driver(&sony_driver);
  2194. }
  2195. static void __exit sony_exit(void)
  2196. {
  2197. dbg_hid("Sony:%s\n", __func__);
  2198. hid_unregister_driver(&sony_driver);
  2199. ida_destroy(&sony_device_id_allocator);
  2200. }
  2201. module_init(sony_init);
  2202. module_exit(sony_exit);
  2203. MODULE_LICENSE("GPL");