hid-sony.c 74 KB

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