hid-sony.c 93 KB

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