wacom_sys.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543
  1. /*
  2. * drivers/input/tablet/wacom_sys.c
  3. *
  4. * USB Wacom tablet support - system specific code
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include "wacom_wac.h"
  13. #include "wacom.h"
  14. #include <linux/input/mt.h>
  15. #define WAC_MSG_RETRIES 5
  16. #define WAC_CMD_WL_LED_CONTROL 0x03
  17. #define WAC_CMD_LED_CONTROL 0x20
  18. #define WAC_CMD_ICON_START 0x21
  19. #define WAC_CMD_ICON_XFER 0x23
  20. #define WAC_CMD_ICON_BT_XFER 0x26
  21. #define WAC_CMD_RETRIES 10
  22. #define WAC_CMD_DELETE_PAIRING 0x20
  23. #define WAC_CMD_UNPAIR_ALL 0xFF
  24. #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
  25. #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
  26. #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
  27. static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf,
  28. size_t size, unsigned int retries)
  29. {
  30. int retval;
  31. do {
  32. retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
  33. HID_REQ_GET_REPORT);
  34. } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
  35. if (retval < 0)
  36. hid_err(hdev, "wacom_get_report: ran out of retries "
  37. "(last error = %d)\n", retval);
  38. return retval;
  39. }
  40. static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
  41. size_t size, unsigned int retries)
  42. {
  43. int retval;
  44. do {
  45. retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
  46. HID_REQ_SET_REPORT);
  47. } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
  48. if (retval < 0)
  49. hid_err(hdev, "wacom_set_report: ran out of retries "
  50. "(last error = %d)\n", retval);
  51. return retval;
  52. }
  53. static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
  54. u8 *raw_data, int size)
  55. {
  56. struct wacom *wacom = hid_get_drvdata(hdev);
  57. if (size > WACOM_PKGLEN_MAX)
  58. return 1;
  59. memcpy(wacom->wacom_wac.data, raw_data, size);
  60. wacom_wac_irq(&wacom->wacom_wac, size);
  61. return 0;
  62. }
  63. static int wacom_open(struct input_dev *dev)
  64. {
  65. struct wacom *wacom = input_get_drvdata(dev);
  66. return hid_hw_open(wacom->hdev);
  67. }
  68. static void wacom_close(struct input_dev *dev)
  69. {
  70. struct wacom *wacom = input_get_drvdata(dev);
  71. /*
  72. * wacom->hdev should never be null, but surprisingly, I had the case
  73. * once while unplugging the Wacom Wireless Receiver.
  74. */
  75. if (wacom->hdev)
  76. hid_hw_close(wacom->hdev);
  77. }
  78. /*
  79. * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
  80. */
  81. static int wacom_calc_hid_res(int logical_extents, int physical_extents,
  82. unsigned unit, int exponent)
  83. {
  84. struct hid_field field = {
  85. .logical_maximum = logical_extents,
  86. .physical_maximum = physical_extents,
  87. .unit = unit,
  88. .unit_exponent = exponent,
  89. };
  90. return hidinput_calc_abs_res(&field, ABS_X);
  91. }
  92. static void wacom_feature_mapping(struct hid_device *hdev,
  93. struct hid_field *field, struct hid_usage *usage)
  94. {
  95. struct wacom *wacom = hid_get_drvdata(hdev);
  96. struct wacom_features *features = &wacom->wacom_wac.features;
  97. struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
  98. u8 *data;
  99. int ret;
  100. int n;
  101. switch (usage->hid) {
  102. case HID_DG_CONTACTMAX:
  103. /* leave touch_max as is if predefined */
  104. if (!features->touch_max) {
  105. /* read manually */
  106. data = kzalloc(2, GFP_KERNEL);
  107. if (!data)
  108. break;
  109. data[0] = field->report->id;
  110. ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
  111. data, 2, WAC_CMD_RETRIES);
  112. if (ret == 2) {
  113. features->touch_max = data[1];
  114. } else {
  115. features->touch_max = 16;
  116. hid_warn(hdev, "wacom_feature_mapping: "
  117. "could not get HID_DG_CONTACTMAX, "
  118. "defaulting to %d\n",
  119. features->touch_max);
  120. }
  121. kfree(data);
  122. }
  123. break;
  124. case HID_DG_INPUTMODE:
  125. /* Ignore if value index is out of bounds. */
  126. if (usage->usage_index >= field->report_count) {
  127. dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
  128. break;
  129. }
  130. hid_data->inputmode = field->report->id;
  131. hid_data->inputmode_index = usage->usage_index;
  132. break;
  133. case HID_UP_DIGITIZER:
  134. if (field->report->id == 0x0B &&
  135. (field->application == WACOM_HID_G9_PEN ||
  136. field->application == WACOM_HID_G11_PEN)) {
  137. wacom->wacom_wac.mode_report = field->report->id;
  138. wacom->wacom_wac.mode_value = 0;
  139. }
  140. break;
  141. case WACOM_HID_WD_DATAMODE:
  142. wacom->wacom_wac.mode_report = field->report->id;
  143. wacom->wacom_wac.mode_value = 2;
  144. break;
  145. case WACOM_HID_UP_G9:
  146. case WACOM_HID_UP_G11:
  147. if (field->report->id == 0x03 &&
  148. (field->application == WACOM_HID_G9_TOUCHSCREEN ||
  149. field->application == WACOM_HID_G11_TOUCHSCREEN)) {
  150. wacom->wacom_wac.mode_report = field->report->id;
  151. wacom->wacom_wac.mode_value = 0;
  152. }
  153. break;
  154. case WACOM_HID_WD_OFFSETLEFT:
  155. case WACOM_HID_WD_OFFSETTOP:
  156. case WACOM_HID_WD_OFFSETRIGHT:
  157. case WACOM_HID_WD_OFFSETBOTTOM:
  158. /* read manually */
  159. n = hid_report_len(field->report);
  160. data = hid_alloc_report_buf(field->report, GFP_KERNEL);
  161. if (!data)
  162. break;
  163. data[0] = field->report->id;
  164. ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
  165. data, n, WAC_CMD_RETRIES);
  166. if (ret == n) {
  167. ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT,
  168. data, n, 0);
  169. } else {
  170. hid_warn(hdev, "%s: could not retrieve sensor offsets\n",
  171. __func__);
  172. }
  173. kfree(data);
  174. break;
  175. }
  176. }
  177. /*
  178. * Interface Descriptor of wacom devices can be incomplete and
  179. * inconsistent so wacom_features table is used to store stylus
  180. * device's packet lengths, various maximum values, and tablet
  181. * resolution based on product ID's.
  182. *
  183. * For devices that contain 2 interfaces, wacom_features table is
  184. * inaccurate for the touch interface. Since the Interface Descriptor
  185. * for touch interfaces has pretty complete data, this function exists
  186. * to query tablet for this missing information instead of hard coding in
  187. * an additional table.
  188. *
  189. * A typical Interface Descriptor for a stylus will contain a
  190. * boot mouse application collection that is not of interest and this
  191. * function will ignore it.
  192. *
  193. * It also contains a digitizer application collection that also is not
  194. * of interest since any information it contains would be duplicate
  195. * of what is in wacom_features. Usually it defines a report of an array
  196. * of bytes that could be used as max length of the stylus packet returned.
  197. * If it happens to define a Digitizer-Stylus Physical Collection then
  198. * the X and Y logical values contain valid data but it is ignored.
  199. *
  200. * A typical Interface Descriptor for a touch interface will contain a
  201. * Digitizer-Finger Physical Collection which will define both logical
  202. * X/Y maximum as well as the physical size of tablet. Since touch
  203. * interfaces haven't supported pressure or distance, this is enough
  204. * information to override invalid values in the wacom_features table.
  205. *
  206. * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
  207. * data. We deal with them after returning from this function.
  208. */
  209. static void wacom_usage_mapping(struct hid_device *hdev,
  210. struct hid_field *field, struct hid_usage *usage)
  211. {
  212. struct wacom *wacom = hid_get_drvdata(hdev);
  213. struct wacom_features *features = &wacom->wacom_wac.features;
  214. bool finger = WACOM_FINGER_FIELD(field);
  215. bool pen = WACOM_PEN_FIELD(field);
  216. /*
  217. * Requiring Stylus Usage will ignore boot mouse
  218. * X/Y values and some cases of invalid Digitizer X/Y
  219. * values commonly reported.
  220. */
  221. if (pen)
  222. features->device_type |= WACOM_DEVICETYPE_PEN;
  223. else if (finger)
  224. features->device_type |= WACOM_DEVICETYPE_TOUCH;
  225. else
  226. return;
  227. /*
  228. * Bamboo models do not support HID_DG_CONTACTMAX.
  229. * And, Bamboo Pen only descriptor contains touch.
  230. */
  231. if (features->type > BAMBOO_PT) {
  232. /* ISDv4 touch devices at least supports one touch point */
  233. if (finger && !features->touch_max)
  234. features->touch_max = 1;
  235. }
  236. /*
  237. * ISDv4 devices which predate HID's adoption of the
  238. * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
  239. * position instead. We can accurately detect if a
  240. * usage with that value should be HID_DG_BARRELSWITCH2
  241. * based on the surrounding usages, which have remained
  242. * constant across generations.
  243. */
  244. if (features->type == HID_GENERIC &&
  245. usage->hid == 0x000D0000 &&
  246. field->application == HID_DG_PEN &&
  247. field->physical == HID_DG_STYLUS) {
  248. int i = usage->usage_index;
  249. if (i-4 >= 0 && i+1 < field->maxusage &&
  250. field->usage[i-4].hid == HID_DG_TIPSWITCH &&
  251. field->usage[i-3].hid == HID_DG_BARRELSWITCH &&
  252. field->usage[i-2].hid == HID_DG_ERASER &&
  253. field->usage[i-1].hid == HID_DG_INVERT &&
  254. field->usage[i+1].hid == HID_DG_INRANGE) {
  255. usage->hid = HID_DG_BARRELSWITCH2;
  256. }
  257. }
  258. switch (usage->hid) {
  259. case HID_GD_X:
  260. features->x_max = field->logical_maximum;
  261. if (finger) {
  262. features->x_phy = field->physical_maximum;
  263. if ((features->type != BAMBOO_PT) &&
  264. (features->type != BAMBOO_TOUCH)) {
  265. features->unit = field->unit;
  266. features->unitExpo = field->unit_exponent;
  267. }
  268. }
  269. break;
  270. case HID_GD_Y:
  271. features->y_max = field->logical_maximum;
  272. if (finger) {
  273. features->y_phy = field->physical_maximum;
  274. if ((features->type != BAMBOO_PT) &&
  275. (features->type != BAMBOO_TOUCH)) {
  276. features->unit = field->unit;
  277. features->unitExpo = field->unit_exponent;
  278. }
  279. }
  280. break;
  281. case HID_DG_TIPPRESSURE:
  282. if (pen)
  283. features->pressure_max = field->logical_maximum;
  284. break;
  285. }
  286. if (features->type == HID_GENERIC)
  287. wacom_wac_usage_mapping(hdev, field, usage);
  288. }
  289. static void wacom_post_parse_hid(struct hid_device *hdev,
  290. struct wacom_features *features)
  291. {
  292. struct wacom *wacom = hid_get_drvdata(hdev);
  293. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  294. if (features->type == HID_GENERIC) {
  295. /* Any last-minute generic device setup */
  296. if (features->touch_max > 1) {
  297. input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max,
  298. INPUT_MT_DIRECT);
  299. }
  300. }
  301. }
  302. static void wacom_parse_hid(struct hid_device *hdev,
  303. struct wacom_features *features)
  304. {
  305. struct hid_report_enum *rep_enum;
  306. struct hid_report *hreport;
  307. int i, j;
  308. /* check features first */
  309. rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
  310. list_for_each_entry(hreport, &rep_enum->report_list, list) {
  311. for (i = 0; i < hreport->maxfield; i++) {
  312. /* Ignore if report count is out of bounds. */
  313. if (hreport->field[i]->report_count < 1)
  314. continue;
  315. for (j = 0; j < hreport->field[i]->maxusage; j++) {
  316. wacom_feature_mapping(hdev, hreport->field[i],
  317. hreport->field[i]->usage + j);
  318. }
  319. }
  320. }
  321. /* now check the input usages */
  322. rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
  323. list_for_each_entry(hreport, &rep_enum->report_list, list) {
  324. if (!hreport->maxfield)
  325. continue;
  326. for (i = 0; i < hreport->maxfield; i++)
  327. for (j = 0; j < hreport->field[i]->maxusage; j++)
  328. wacom_usage_mapping(hdev, hreport->field[i],
  329. hreport->field[i]->usage + j);
  330. }
  331. wacom_post_parse_hid(hdev, features);
  332. }
  333. static int wacom_hid_set_device_mode(struct hid_device *hdev)
  334. {
  335. struct wacom *wacom = hid_get_drvdata(hdev);
  336. struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
  337. struct hid_report *r;
  338. struct hid_report_enum *re;
  339. if (hid_data->inputmode < 0)
  340. return 0;
  341. re = &(hdev->report_enum[HID_FEATURE_REPORT]);
  342. r = re->report_id_hash[hid_data->inputmode];
  343. if (r) {
  344. r->field[0]->value[hid_data->inputmode_index] = 2;
  345. hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
  346. }
  347. return 0;
  348. }
  349. static int wacom_set_device_mode(struct hid_device *hdev,
  350. struct wacom_wac *wacom_wac)
  351. {
  352. u8 *rep_data;
  353. struct hid_report *r;
  354. struct hid_report_enum *re;
  355. int length;
  356. int error = -ENOMEM, limit = 0;
  357. if (wacom_wac->mode_report < 0)
  358. return 0;
  359. re = &(hdev->report_enum[HID_FEATURE_REPORT]);
  360. r = re->report_id_hash[wacom_wac->mode_report];
  361. if (!r)
  362. return -EINVAL;
  363. rep_data = hid_alloc_report_buf(r, GFP_KERNEL);
  364. if (!rep_data)
  365. return -ENOMEM;
  366. length = hid_report_len(r);
  367. do {
  368. rep_data[0] = wacom_wac->mode_report;
  369. rep_data[1] = wacom_wac->mode_value;
  370. error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
  371. length, 1);
  372. if (error >= 0)
  373. error = wacom_get_report(hdev, HID_FEATURE_REPORT,
  374. rep_data, length, 1);
  375. } while (error >= 0 &&
  376. rep_data[1] != wacom_wac->mode_report &&
  377. limit++ < WAC_MSG_RETRIES);
  378. kfree(rep_data);
  379. return error < 0 ? error : 0;
  380. }
  381. static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
  382. struct wacom_features *features)
  383. {
  384. struct wacom *wacom = hid_get_drvdata(hdev);
  385. int ret;
  386. u8 rep_data[2];
  387. switch (features->type) {
  388. case GRAPHIRE_BT:
  389. rep_data[0] = 0x03;
  390. rep_data[1] = 0x00;
  391. ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
  392. 3);
  393. if (ret >= 0) {
  394. rep_data[0] = speed == 0 ? 0x05 : 0x06;
  395. rep_data[1] = 0x00;
  396. ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
  397. rep_data, 2, 3);
  398. if (ret >= 0) {
  399. wacom->wacom_wac.bt_high_speed = speed;
  400. return 0;
  401. }
  402. }
  403. /*
  404. * Note that if the raw queries fail, it's not a hard failure
  405. * and it is safe to continue
  406. */
  407. hid_warn(hdev, "failed to poke device, command %d, err %d\n",
  408. rep_data[0], ret);
  409. break;
  410. case INTUOS4WL:
  411. if (speed == 1)
  412. wacom->wacom_wac.bt_features &= ~0x20;
  413. else
  414. wacom->wacom_wac.bt_features |= 0x20;
  415. rep_data[0] = 0x03;
  416. rep_data[1] = wacom->wacom_wac.bt_features;
  417. ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
  418. 1);
  419. if (ret >= 0)
  420. wacom->wacom_wac.bt_high_speed = speed;
  421. break;
  422. }
  423. return 0;
  424. }
  425. /*
  426. * Switch the tablet into its most-capable mode. Wacom tablets are
  427. * typically configured to power-up in a mode which sends mouse-like
  428. * reports to the OS. To get absolute position, pressure data, etc.
  429. * from the tablet, it is necessary to switch the tablet out of this
  430. * mode and into one which sends the full range of tablet data.
  431. */
  432. static int wacom_query_tablet_data(struct hid_device *hdev,
  433. struct wacom_features *features)
  434. {
  435. struct wacom *wacom = hid_get_drvdata(hdev);
  436. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  437. if (hdev->bus == BUS_BLUETOOTH)
  438. return wacom_bt_query_tablet_data(hdev, 1, features);
  439. if (features->type != HID_GENERIC) {
  440. if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
  441. if (features->type > TABLETPC) {
  442. /* MT Tablet PC touch */
  443. wacom_wac->mode_report = 3;
  444. wacom_wac->mode_value = 4;
  445. } else if (features->type == WACOM_24HDT) {
  446. wacom_wac->mode_report = 18;
  447. wacom_wac->mode_value = 2;
  448. } else if (features->type == WACOM_27QHDT) {
  449. wacom_wac->mode_report = 131;
  450. wacom_wac->mode_value = 2;
  451. } else if (features->type == BAMBOO_PAD) {
  452. wacom_wac->mode_report = 2;
  453. wacom_wac->mode_value = 2;
  454. }
  455. } else if (features->device_type & WACOM_DEVICETYPE_PEN) {
  456. if (features->type <= BAMBOO_PT) {
  457. wacom_wac->mode_report = 2;
  458. wacom_wac->mode_value = 2;
  459. }
  460. }
  461. }
  462. wacom_set_device_mode(hdev, wacom_wac);
  463. if (features->type == HID_GENERIC)
  464. return wacom_hid_set_device_mode(hdev);
  465. return 0;
  466. }
  467. static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
  468. struct wacom_features *features)
  469. {
  470. struct wacom *wacom = hid_get_drvdata(hdev);
  471. struct usb_interface *intf = wacom->intf;
  472. /* default features */
  473. features->x_fuzz = 4;
  474. features->y_fuzz = 4;
  475. features->pressure_fuzz = 0;
  476. features->distance_fuzz = 1;
  477. features->tilt_fuzz = 1;
  478. /*
  479. * The wireless device HID is basic and layout conflicts with
  480. * other tablets (monitor and touch interface can look like pen).
  481. * Skip the query for this type and modify defaults based on
  482. * interface number.
  483. */
  484. if (features->type == WIRELESS) {
  485. if (intf->cur_altsetting->desc.bInterfaceNumber == 0)
  486. features->device_type = WACOM_DEVICETYPE_WL_MONITOR;
  487. else
  488. features->device_type = WACOM_DEVICETYPE_NONE;
  489. return;
  490. }
  491. wacom_parse_hid(hdev, features);
  492. }
  493. struct wacom_hdev_data {
  494. struct list_head list;
  495. struct kref kref;
  496. struct hid_device *dev;
  497. struct wacom_shared shared;
  498. };
  499. static LIST_HEAD(wacom_udev_list);
  500. static DEFINE_MUTEX(wacom_udev_list_lock);
  501. static bool compare_device_paths(struct hid_device *hdev_a,
  502. struct hid_device *hdev_b, char separator)
  503. {
  504. int n1 = strrchr(hdev_a->phys, separator) - hdev_a->phys;
  505. int n2 = strrchr(hdev_b->phys, separator) - hdev_b->phys;
  506. if (n1 != n2 || n1 <= 0 || n2 <= 0)
  507. return false;
  508. return !strncmp(hdev_a->phys, hdev_b->phys, n1);
  509. }
  510. static bool wacom_are_sibling(struct hid_device *hdev,
  511. struct hid_device *sibling)
  512. {
  513. struct wacom *wacom = hid_get_drvdata(hdev);
  514. struct wacom_features *features = &wacom->wacom_wac.features;
  515. struct wacom *sibling_wacom = hid_get_drvdata(sibling);
  516. struct wacom_features *sibling_features = &sibling_wacom->wacom_wac.features;
  517. __u32 oVid = features->oVid ? features->oVid : hdev->vendor;
  518. __u32 oPid = features->oPid ? features->oPid : hdev->product;
  519. /* The defined oVid/oPid must match that of the sibling */
  520. if (features->oVid != HID_ANY_ID && sibling->vendor != oVid)
  521. return false;
  522. if (features->oPid != HID_ANY_ID && sibling->product != oPid)
  523. return false;
  524. /*
  525. * Devices with the same VID/PID must share the same physical
  526. * device path, while those with different VID/PID must share
  527. * the same physical parent device path.
  528. */
  529. if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) {
  530. if (!compare_device_paths(hdev, sibling, '/'))
  531. return false;
  532. } else {
  533. if (!compare_device_paths(hdev, sibling, '.'))
  534. return false;
  535. }
  536. /* Skip the remaining heuristics unless you are a HID_GENERIC device */
  537. if (features->type != HID_GENERIC)
  538. return true;
  539. /*
  540. * Direct-input devices may not be siblings of indirect-input
  541. * devices.
  542. */
  543. if ((features->device_type & WACOM_DEVICETYPE_DIRECT) &&
  544. !(sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
  545. return false;
  546. /*
  547. * Indirect-input devices may not be siblings of direct-input
  548. * devices.
  549. */
  550. if (!(features->device_type & WACOM_DEVICETYPE_DIRECT) &&
  551. (sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
  552. return false;
  553. /* Pen devices may only be siblings of touch devices */
  554. if ((features->device_type & WACOM_DEVICETYPE_PEN) &&
  555. !(sibling_features->device_type & WACOM_DEVICETYPE_TOUCH))
  556. return false;
  557. /* Touch devices may only be siblings of pen devices */
  558. if ((features->device_type & WACOM_DEVICETYPE_TOUCH) &&
  559. !(sibling_features->device_type & WACOM_DEVICETYPE_PEN))
  560. return false;
  561. /*
  562. * No reason could be found for these two devices to NOT be
  563. * siblings, so there's a good chance they ARE siblings
  564. */
  565. return true;
  566. }
  567. static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
  568. {
  569. struct wacom_hdev_data *data;
  570. /* Try to find an already-probed interface from the same device */
  571. list_for_each_entry(data, &wacom_udev_list, list) {
  572. if (compare_device_paths(hdev, data->dev, '/'))
  573. return data;
  574. }
  575. /* Fallback to finding devices that appear to be "siblings" */
  576. list_for_each_entry(data, &wacom_udev_list, list) {
  577. if (wacom_are_sibling(hdev, data->dev)) {
  578. kref_get(&data->kref);
  579. return data;
  580. }
  581. }
  582. return NULL;
  583. }
  584. static void wacom_release_shared_data(struct kref *kref)
  585. {
  586. struct wacom_hdev_data *data =
  587. container_of(kref, struct wacom_hdev_data, kref);
  588. mutex_lock(&wacom_udev_list_lock);
  589. list_del(&data->list);
  590. mutex_unlock(&wacom_udev_list_lock);
  591. kfree(data);
  592. }
  593. static void wacom_remove_shared_data(void *res)
  594. {
  595. struct wacom *wacom = res;
  596. struct wacom_hdev_data *data;
  597. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  598. if (wacom_wac->shared) {
  599. data = container_of(wacom_wac->shared, struct wacom_hdev_data,
  600. shared);
  601. if (wacom_wac->shared->touch == wacom->hdev)
  602. wacom_wac->shared->touch = NULL;
  603. else if (wacom_wac->shared->pen == wacom->hdev)
  604. wacom_wac->shared->pen = NULL;
  605. kref_put(&data->kref, wacom_release_shared_data);
  606. wacom_wac->shared = NULL;
  607. }
  608. }
  609. static int wacom_add_shared_data(struct hid_device *hdev)
  610. {
  611. struct wacom *wacom = hid_get_drvdata(hdev);
  612. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  613. struct wacom_hdev_data *data;
  614. int retval = 0;
  615. mutex_lock(&wacom_udev_list_lock);
  616. data = wacom_get_hdev_data(hdev);
  617. if (!data) {
  618. data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
  619. if (!data) {
  620. retval = -ENOMEM;
  621. goto out;
  622. }
  623. kref_init(&data->kref);
  624. data->dev = hdev;
  625. list_add_tail(&data->list, &wacom_udev_list);
  626. }
  627. wacom_wac->shared = &data->shared;
  628. retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom);
  629. if (retval) {
  630. mutex_unlock(&wacom_udev_list_lock);
  631. wacom_remove_shared_data(wacom);
  632. return retval;
  633. }
  634. if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
  635. wacom_wac->shared->touch = hdev;
  636. else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
  637. wacom_wac->shared->pen = hdev;
  638. out:
  639. mutex_unlock(&wacom_udev_list_lock);
  640. return retval;
  641. }
  642. static int wacom_led_control(struct wacom *wacom)
  643. {
  644. unsigned char *buf;
  645. int retval;
  646. unsigned char report_id = WAC_CMD_LED_CONTROL;
  647. int buf_size = 9;
  648. if (!hid_get_drvdata(wacom->hdev))
  649. return -ENODEV;
  650. if (!wacom->led.groups)
  651. return -ENOTSUPP;
  652. if (wacom->wacom_wac.pid) { /* wireless connected */
  653. report_id = WAC_CMD_WL_LED_CONTROL;
  654. buf_size = 13;
  655. }
  656. buf = kzalloc(buf_size, GFP_KERNEL);
  657. if (!buf)
  658. return -ENOMEM;
  659. if (wacom->wacom_wac.features.type >= INTUOS5S &&
  660. wacom->wacom_wac.features.type <= INTUOSPL) {
  661. /*
  662. * Touch Ring and crop mark LED luminance may take on
  663. * one of four values:
  664. * 0 = Low; 1 = Medium; 2 = High; 3 = Off
  665. */
  666. int ring_led = wacom->led.groups[0].select & 0x03;
  667. int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
  668. int crop_lum = 0;
  669. unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
  670. buf[0] = report_id;
  671. if (wacom->wacom_wac.pid) {
  672. wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
  673. buf, buf_size, WAC_CMD_RETRIES);
  674. buf[0] = report_id;
  675. buf[4] = led_bits;
  676. } else
  677. buf[1] = led_bits;
  678. }
  679. else {
  680. int led = wacom->led.groups[0].select | 0x4;
  681. if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
  682. wacom->wacom_wac.features.type == WACOM_24HD)
  683. led |= (wacom->led.groups[1].select << 4) | 0x40;
  684. buf[0] = report_id;
  685. buf[1] = led;
  686. buf[2] = wacom->led.llv;
  687. buf[3] = wacom->led.hlv;
  688. buf[4] = wacom->led.img_lum;
  689. }
  690. retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
  691. WAC_CMD_RETRIES);
  692. kfree(buf);
  693. return retval;
  694. }
  695. static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
  696. const unsigned len, const void *img)
  697. {
  698. unsigned char *buf;
  699. int i, retval;
  700. const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
  701. buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
  702. if (!buf)
  703. return -ENOMEM;
  704. /* Send 'start' command */
  705. buf[0] = WAC_CMD_ICON_START;
  706. buf[1] = 1;
  707. retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
  708. WAC_CMD_RETRIES);
  709. if (retval < 0)
  710. goto out;
  711. buf[0] = xfer_id;
  712. buf[1] = button_id & 0x07;
  713. for (i = 0; i < 4; i++) {
  714. buf[2] = i;
  715. memcpy(buf + 3, img + i * chunk_len, chunk_len);
  716. retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
  717. buf, chunk_len + 3, WAC_CMD_RETRIES);
  718. if (retval < 0)
  719. break;
  720. }
  721. /* Send 'stop' */
  722. buf[0] = WAC_CMD_ICON_START;
  723. buf[1] = 0;
  724. wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
  725. WAC_CMD_RETRIES);
  726. out:
  727. kfree(buf);
  728. return retval;
  729. }
  730. static ssize_t wacom_led_select_store(struct device *dev, int set_id,
  731. const char *buf, size_t count)
  732. {
  733. struct hid_device *hdev = to_hid_device(dev);
  734. struct wacom *wacom = hid_get_drvdata(hdev);
  735. unsigned int id;
  736. int err;
  737. err = kstrtouint(buf, 10, &id);
  738. if (err)
  739. return err;
  740. mutex_lock(&wacom->lock);
  741. wacom->led.groups[set_id].select = id & 0x3;
  742. err = wacom_led_control(wacom);
  743. mutex_unlock(&wacom->lock);
  744. return err < 0 ? err : count;
  745. }
  746. #define DEVICE_LED_SELECT_ATTR(SET_ID) \
  747. static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
  748. struct device_attribute *attr, const char *buf, size_t count) \
  749. { \
  750. return wacom_led_select_store(dev, SET_ID, buf, count); \
  751. } \
  752. static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
  753. struct device_attribute *attr, char *buf) \
  754. { \
  755. struct hid_device *hdev = to_hid_device(dev);\
  756. struct wacom *wacom = hid_get_drvdata(hdev); \
  757. return scnprintf(buf, PAGE_SIZE, "%d\n", \
  758. wacom->led.groups[SET_ID].select); \
  759. } \
  760. static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
  761. wacom_led##SET_ID##_select_show, \
  762. wacom_led##SET_ID##_select_store)
  763. DEVICE_LED_SELECT_ATTR(0);
  764. DEVICE_LED_SELECT_ATTR(1);
  765. static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
  766. const char *buf, size_t count)
  767. {
  768. unsigned int value;
  769. int err;
  770. err = kstrtouint(buf, 10, &value);
  771. if (err)
  772. return err;
  773. mutex_lock(&wacom->lock);
  774. *dest = value & 0x7f;
  775. err = wacom_led_control(wacom);
  776. mutex_unlock(&wacom->lock);
  777. return err < 0 ? err : count;
  778. }
  779. #define DEVICE_LUMINANCE_ATTR(name, field) \
  780. static ssize_t wacom_##name##_luminance_store(struct device *dev, \
  781. struct device_attribute *attr, const char *buf, size_t count) \
  782. { \
  783. struct hid_device *hdev = to_hid_device(dev);\
  784. struct wacom *wacom = hid_get_drvdata(hdev); \
  785. \
  786. return wacom_luminance_store(wacom, &wacom->led.field, \
  787. buf, count); \
  788. } \
  789. static ssize_t wacom_##name##_luminance_show(struct device *dev, \
  790. struct device_attribute *attr, char *buf) \
  791. { \
  792. struct wacom *wacom = dev_get_drvdata(dev); \
  793. return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
  794. } \
  795. static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
  796. wacom_##name##_luminance_show, \
  797. wacom_##name##_luminance_store)
  798. DEVICE_LUMINANCE_ATTR(status0, llv);
  799. DEVICE_LUMINANCE_ATTR(status1, hlv);
  800. DEVICE_LUMINANCE_ATTR(buttons, img_lum);
  801. static ssize_t wacom_button_image_store(struct device *dev, int button_id,
  802. const char *buf, size_t count)
  803. {
  804. struct hid_device *hdev = to_hid_device(dev);
  805. struct wacom *wacom = hid_get_drvdata(hdev);
  806. int err;
  807. unsigned len;
  808. u8 xfer_id;
  809. if (hdev->bus == BUS_BLUETOOTH) {
  810. len = 256;
  811. xfer_id = WAC_CMD_ICON_BT_XFER;
  812. } else {
  813. len = 1024;
  814. xfer_id = WAC_CMD_ICON_XFER;
  815. }
  816. if (count != len)
  817. return -EINVAL;
  818. mutex_lock(&wacom->lock);
  819. err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
  820. mutex_unlock(&wacom->lock);
  821. return err < 0 ? err : count;
  822. }
  823. #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
  824. static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
  825. struct device_attribute *attr, const char *buf, size_t count) \
  826. { \
  827. return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
  828. } \
  829. static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
  830. NULL, wacom_btnimg##BUTTON_ID##_store)
  831. DEVICE_BTNIMG_ATTR(0);
  832. DEVICE_BTNIMG_ATTR(1);
  833. DEVICE_BTNIMG_ATTR(2);
  834. DEVICE_BTNIMG_ATTR(3);
  835. DEVICE_BTNIMG_ATTR(4);
  836. DEVICE_BTNIMG_ATTR(5);
  837. DEVICE_BTNIMG_ATTR(6);
  838. DEVICE_BTNIMG_ATTR(7);
  839. static struct attribute *cintiq_led_attrs[] = {
  840. &dev_attr_status_led0_select.attr,
  841. &dev_attr_status_led1_select.attr,
  842. NULL
  843. };
  844. static struct attribute_group cintiq_led_attr_group = {
  845. .name = "wacom_led",
  846. .attrs = cintiq_led_attrs,
  847. };
  848. static struct attribute *intuos4_led_attrs[] = {
  849. &dev_attr_status0_luminance.attr,
  850. &dev_attr_status1_luminance.attr,
  851. &dev_attr_status_led0_select.attr,
  852. &dev_attr_buttons_luminance.attr,
  853. &dev_attr_button0_rawimg.attr,
  854. &dev_attr_button1_rawimg.attr,
  855. &dev_attr_button2_rawimg.attr,
  856. &dev_attr_button3_rawimg.attr,
  857. &dev_attr_button4_rawimg.attr,
  858. &dev_attr_button5_rawimg.attr,
  859. &dev_attr_button6_rawimg.attr,
  860. &dev_attr_button7_rawimg.attr,
  861. NULL
  862. };
  863. static struct attribute_group intuos4_led_attr_group = {
  864. .name = "wacom_led",
  865. .attrs = intuos4_led_attrs,
  866. };
  867. static struct attribute *intuos5_led_attrs[] = {
  868. &dev_attr_status0_luminance.attr,
  869. &dev_attr_status_led0_select.attr,
  870. NULL
  871. };
  872. static struct attribute_group intuos5_led_attr_group = {
  873. .name = "wacom_led",
  874. .attrs = intuos5_led_attrs,
  875. };
  876. struct wacom_sysfs_group_devres {
  877. struct attribute_group *group;
  878. struct kobject *root;
  879. };
  880. static void wacom_devm_sysfs_group_release(struct device *dev, void *res)
  881. {
  882. struct wacom_sysfs_group_devres *devres = res;
  883. struct kobject *kobj = devres->root;
  884. dev_dbg(dev, "%s: dropping reference to %s\n",
  885. __func__, devres->group->name);
  886. sysfs_remove_group(kobj, devres->group);
  887. }
  888. static int __wacom_devm_sysfs_create_group(struct wacom *wacom,
  889. struct kobject *root,
  890. struct attribute_group *group)
  891. {
  892. struct wacom_sysfs_group_devres *devres;
  893. int error;
  894. devres = devres_alloc(wacom_devm_sysfs_group_release,
  895. sizeof(struct wacom_sysfs_group_devres),
  896. GFP_KERNEL);
  897. if (!devres)
  898. return -ENOMEM;
  899. devres->group = group;
  900. devres->root = root;
  901. error = sysfs_create_group(devres->root, group);
  902. if (error)
  903. return error;
  904. devres_add(&wacom->hdev->dev, devres);
  905. return 0;
  906. }
  907. static int wacom_devm_sysfs_create_group(struct wacom *wacom,
  908. struct attribute_group *group)
  909. {
  910. return __wacom_devm_sysfs_create_group(wacom, &wacom->hdev->dev.kobj,
  911. group);
  912. }
  913. enum led_brightness wacom_leds_brightness_get(struct wacom_led *led)
  914. {
  915. struct wacom *wacom = led->wacom;
  916. if (wacom->led.max_hlv)
  917. return led->hlv * LED_FULL / wacom->led.max_hlv;
  918. if (wacom->led.max_llv)
  919. return led->llv * LED_FULL / wacom->led.max_llv;
  920. /* device doesn't support brightness tuning */
  921. return LED_FULL;
  922. }
  923. static enum led_brightness __wacom_led_brightness_get(struct led_classdev *cdev)
  924. {
  925. struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
  926. struct wacom *wacom = led->wacom;
  927. if (wacom->led.groups[led->group].select != led->id)
  928. return LED_OFF;
  929. return wacom_leds_brightness_get(led);
  930. }
  931. static int wacom_led_brightness_set(struct led_classdev *cdev,
  932. enum led_brightness brightness)
  933. {
  934. struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
  935. struct wacom *wacom = led->wacom;
  936. int error;
  937. mutex_lock(&wacom->lock);
  938. if (!wacom->led.groups || (brightness == LED_OFF &&
  939. wacom->led.groups[led->group].select != led->id)) {
  940. error = 0;
  941. goto out;
  942. }
  943. led->llv = wacom->led.llv = wacom->led.max_llv * brightness / LED_FULL;
  944. led->hlv = wacom->led.hlv = wacom->led.max_hlv * brightness / LED_FULL;
  945. wacom->led.groups[led->group].select = led->id;
  946. error = wacom_led_control(wacom);
  947. out:
  948. mutex_unlock(&wacom->lock);
  949. return error;
  950. }
  951. static void wacom_led_readonly_brightness_set(struct led_classdev *cdev,
  952. enum led_brightness brightness)
  953. {
  954. }
  955. static int wacom_led_register_one(struct device *dev, struct wacom *wacom,
  956. struct wacom_led *led, unsigned int group,
  957. unsigned int id, bool read_only)
  958. {
  959. int error;
  960. char *name;
  961. name = devm_kasprintf(dev, GFP_KERNEL,
  962. "%s::wacom-%d.%d",
  963. dev_name(dev),
  964. group,
  965. id);
  966. if (!name)
  967. return -ENOMEM;
  968. if (!read_only) {
  969. led->trigger.name = name;
  970. error = devm_led_trigger_register(dev, &led->trigger);
  971. if (error) {
  972. hid_err(wacom->hdev,
  973. "failed to register LED trigger %s: %d\n",
  974. led->cdev.name, error);
  975. return error;
  976. }
  977. }
  978. led->group = group;
  979. led->id = id;
  980. led->wacom = wacom;
  981. led->llv = wacom->led.llv;
  982. led->hlv = wacom->led.hlv;
  983. led->cdev.name = name;
  984. led->cdev.max_brightness = LED_FULL;
  985. led->cdev.flags = LED_HW_PLUGGABLE;
  986. led->cdev.brightness_get = __wacom_led_brightness_get;
  987. if (!read_only) {
  988. led->cdev.brightness_set_blocking = wacom_led_brightness_set;
  989. led->cdev.default_trigger = led->cdev.name;
  990. } else {
  991. led->cdev.brightness_set = wacom_led_readonly_brightness_set;
  992. }
  993. error = devm_led_classdev_register(dev, &led->cdev);
  994. if (error) {
  995. hid_err(wacom->hdev,
  996. "failed to register LED %s: %d\n",
  997. led->cdev.name, error);
  998. led->cdev.name = NULL;
  999. return error;
  1000. }
  1001. return 0;
  1002. }
  1003. static void wacom_led_groups_release_one(void *data)
  1004. {
  1005. struct wacom_group_leds *group = data;
  1006. devres_release_group(group->dev, group);
  1007. }
  1008. static int wacom_led_groups_alloc_and_register_one(struct device *dev,
  1009. struct wacom *wacom,
  1010. int group_id, int count,
  1011. bool read_only)
  1012. {
  1013. struct wacom_led *leds;
  1014. int i, error;
  1015. if (group_id >= wacom->led.count || count <= 0)
  1016. return -EINVAL;
  1017. if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL))
  1018. return -ENOMEM;
  1019. leds = devm_kzalloc(dev, sizeof(struct wacom_led) * count, GFP_KERNEL);
  1020. if (!leds) {
  1021. error = -ENOMEM;
  1022. goto err;
  1023. }
  1024. wacom->led.groups[group_id].leds = leds;
  1025. wacom->led.groups[group_id].count = count;
  1026. for (i = 0; i < count; i++) {
  1027. error = wacom_led_register_one(dev, wacom, &leds[i],
  1028. group_id, i, read_only);
  1029. if (error)
  1030. goto err;
  1031. }
  1032. wacom->led.groups[group_id].dev = dev;
  1033. devres_close_group(dev, &wacom->led.groups[group_id]);
  1034. /*
  1035. * There is a bug (?) in devm_led_classdev_register() in which its
  1036. * increments the refcount of the parent. If the parent is an input
  1037. * device, that means the ref count never reaches 0 when
  1038. * devm_input_device_release() gets called.
  1039. * This means that the LEDs are still there after disconnect.
  1040. * Manually force the release of the group so that the leds are released
  1041. * once we are done using them.
  1042. */
  1043. error = devm_add_action_or_reset(&wacom->hdev->dev,
  1044. wacom_led_groups_release_one,
  1045. &wacom->led.groups[group_id]);
  1046. if (error)
  1047. return error;
  1048. return 0;
  1049. err:
  1050. devres_release_group(dev, &wacom->led.groups[group_id]);
  1051. return error;
  1052. }
  1053. struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group_id,
  1054. unsigned int id)
  1055. {
  1056. struct wacom_group_leds *group;
  1057. if (group_id >= wacom->led.count)
  1058. return NULL;
  1059. group = &wacom->led.groups[group_id];
  1060. if (!group->leds)
  1061. return NULL;
  1062. id %= group->count;
  1063. return &group->leds[id];
  1064. }
  1065. /**
  1066. * wacom_led_next: gives the next available led with a wacom trigger.
  1067. *
  1068. * returns the next available struct wacom_led which has its default trigger
  1069. * or the current one if none is available.
  1070. */
  1071. struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur)
  1072. {
  1073. struct wacom_led *next_led;
  1074. int group, next;
  1075. if (!wacom || !cur)
  1076. return NULL;
  1077. group = cur->group;
  1078. next = cur->id;
  1079. do {
  1080. next_led = wacom_led_find(wacom, group, ++next);
  1081. if (!next_led || next_led == cur)
  1082. return next_led;
  1083. } while (next_led->cdev.trigger != &next_led->trigger);
  1084. return next_led;
  1085. }
  1086. static void wacom_led_groups_release(void *data)
  1087. {
  1088. struct wacom *wacom = data;
  1089. wacom->led.groups = NULL;
  1090. wacom->led.count = 0;
  1091. }
  1092. static int wacom_led_groups_allocate(struct wacom *wacom, int count)
  1093. {
  1094. struct device *dev = &wacom->hdev->dev;
  1095. struct wacom_group_leds *groups;
  1096. int error;
  1097. groups = devm_kzalloc(dev, sizeof(struct wacom_group_leds) * count,
  1098. GFP_KERNEL);
  1099. if (!groups)
  1100. return -ENOMEM;
  1101. error = devm_add_action_or_reset(dev, wacom_led_groups_release, wacom);
  1102. if (error)
  1103. return error;
  1104. wacom->led.groups = groups;
  1105. wacom->led.count = count;
  1106. return 0;
  1107. }
  1108. static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count,
  1109. int led_per_group, bool read_only)
  1110. {
  1111. struct device *dev;
  1112. int i, error;
  1113. if (!wacom->wacom_wac.pad_input)
  1114. return -EINVAL;
  1115. dev = &wacom->wacom_wac.pad_input->dev;
  1116. error = wacom_led_groups_allocate(wacom, group_count);
  1117. if (error)
  1118. return error;
  1119. for (i = 0; i < group_count; i++) {
  1120. error = wacom_led_groups_alloc_and_register_one(dev, wacom, i,
  1121. led_per_group,
  1122. read_only);
  1123. if (error)
  1124. return error;
  1125. }
  1126. return 0;
  1127. }
  1128. static int wacom_initialize_leds(struct wacom *wacom)
  1129. {
  1130. int error;
  1131. if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
  1132. return 0;
  1133. /* Initialize default values */
  1134. switch (wacom->wacom_wac.features.type) {
  1135. case INTUOS4S:
  1136. case INTUOS4:
  1137. case INTUOS4WL:
  1138. case INTUOS4L:
  1139. wacom->led.llv = 10;
  1140. wacom->led.hlv = 20;
  1141. wacom->led.max_llv = 127;
  1142. wacom->led.max_hlv = 127;
  1143. wacom->led.img_lum = 10;
  1144. error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
  1145. if (error) {
  1146. hid_err(wacom->hdev,
  1147. "cannot create leds err: %d\n", error);
  1148. return error;
  1149. }
  1150. error = wacom_devm_sysfs_create_group(wacom,
  1151. &intuos4_led_attr_group);
  1152. break;
  1153. case WACOM_24HD:
  1154. case WACOM_21UX2:
  1155. wacom->led.llv = 0;
  1156. wacom->led.hlv = 0;
  1157. wacom->led.img_lum = 0;
  1158. error = wacom_leds_alloc_and_register(wacom, 2, 4, false);
  1159. if (error) {
  1160. hid_err(wacom->hdev,
  1161. "cannot create leds err: %d\n", error);
  1162. return error;
  1163. }
  1164. error = wacom_devm_sysfs_create_group(wacom,
  1165. &cintiq_led_attr_group);
  1166. break;
  1167. case INTUOS5S:
  1168. case INTUOS5:
  1169. case INTUOS5L:
  1170. case INTUOSPS:
  1171. case INTUOSPM:
  1172. case INTUOSPL:
  1173. wacom->led.llv = 32;
  1174. wacom->led.max_llv = 96;
  1175. error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
  1176. if (error) {
  1177. hid_err(wacom->hdev,
  1178. "cannot create leds err: %d\n", error);
  1179. return error;
  1180. }
  1181. error = wacom_devm_sysfs_create_group(wacom,
  1182. &intuos5_led_attr_group);
  1183. break;
  1184. case REMOTE:
  1185. wacom->led.llv = 255;
  1186. wacom->led.max_llv = 255;
  1187. error = wacom_led_groups_allocate(wacom, 5);
  1188. if (error) {
  1189. hid_err(wacom->hdev,
  1190. "cannot create leds err: %d\n", error);
  1191. return error;
  1192. }
  1193. return 0;
  1194. default:
  1195. return 0;
  1196. }
  1197. if (error) {
  1198. hid_err(wacom->hdev,
  1199. "cannot create sysfs group err: %d\n", error);
  1200. return error;
  1201. }
  1202. wacom_led_control(wacom);
  1203. return 0;
  1204. }
  1205. static enum power_supply_property wacom_battery_props[] = {
  1206. POWER_SUPPLY_PROP_MODEL_NAME,
  1207. POWER_SUPPLY_PROP_PRESENT,
  1208. POWER_SUPPLY_PROP_STATUS,
  1209. POWER_SUPPLY_PROP_SCOPE,
  1210. POWER_SUPPLY_PROP_CAPACITY
  1211. };
  1212. static int wacom_battery_get_property(struct power_supply *psy,
  1213. enum power_supply_property psp,
  1214. union power_supply_propval *val)
  1215. {
  1216. struct wacom_battery *battery = power_supply_get_drvdata(psy);
  1217. int ret = 0;
  1218. switch (psp) {
  1219. case POWER_SUPPLY_PROP_MODEL_NAME:
  1220. val->strval = battery->wacom->wacom_wac.name;
  1221. break;
  1222. case POWER_SUPPLY_PROP_PRESENT:
  1223. val->intval = battery->bat_connected;
  1224. break;
  1225. case POWER_SUPPLY_PROP_SCOPE:
  1226. val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  1227. break;
  1228. case POWER_SUPPLY_PROP_CAPACITY:
  1229. val->intval = battery->battery_capacity;
  1230. break;
  1231. case POWER_SUPPLY_PROP_STATUS:
  1232. if (battery->bat_charging)
  1233. val->intval = POWER_SUPPLY_STATUS_CHARGING;
  1234. else if (battery->battery_capacity == 100 &&
  1235. battery->ps_connected)
  1236. val->intval = POWER_SUPPLY_STATUS_FULL;
  1237. else if (battery->ps_connected)
  1238. val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
  1239. else
  1240. val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
  1241. break;
  1242. default:
  1243. ret = -EINVAL;
  1244. break;
  1245. }
  1246. return ret;
  1247. }
  1248. static int __wacom_initialize_battery(struct wacom *wacom,
  1249. struct wacom_battery *battery)
  1250. {
  1251. static atomic_t battery_no = ATOMIC_INIT(0);
  1252. struct device *dev = &wacom->hdev->dev;
  1253. struct power_supply_config psy_cfg = { .drv_data = battery, };
  1254. struct power_supply *ps_bat;
  1255. struct power_supply_desc *bat_desc = &battery->bat_desc;
  1256. unsigned long n;
  1257. int error;
  1258. if (!devres_open_group(dev, bat_desc, GFP_KERNEL))
  1259. return -ENOMEM;
  1260. battery->wacom = wacom;
  1261. n = atomic_inc_return(&battery_no) - 1;
  1262. bat_desc->properties = wacom_battery_props;
  1263. bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
  1264. bat_desc->get_property = wacom_battery_get_property;
  1265. sprintf(battery->bat_name, "wacom_battery_%ld", n);
  1266. bat_desc->name = battery->bat_name;
  1267. bat_desc->type = POWER_SUPPLY_TYPE_USB;
  1268. bat_desc->use_for_apm = 0;
  1269. ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg);
  1270. if (IS_ERR(ps_bat)) {
  1271. error = PTR_ERR(ps_bat);
  1272. goto err;
  1273. }
  1274. power_supply_powers(ps_bat, &wacom->hdev->dev);
  1275. battery->battery = ps_bat;
  1276. devres_close_group(dev, bat_desc);
  1277. return 0;
  1278. err:
  1279. devres_release_group(dev, bat_desc);
  1280. return error;
  1281. }
  1282. static int wacom_initialize_battery(struct wacom *wacom)
  1283. {
  1284. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY)
  1285. return __wacom_initialize_battery(wacom, &wacom->battery);
  1286. return 0;
  1287. }
  1288. static void wacom_destroy_battery(struct wacom *wacom)
  1289. {
  1290. if (wacom->battery.battery) {
  1291. devres_release_group(&wacom->hdev->dev,
  1292. &wacom->battery.bat_desc);
  1293. wacom->battery.battery = NULL;
  1294. }
  1295. }
  1296. static ssize_t wacom_show_speed(struct device *dev,
  1297. struct device_attribute
  1298. *attr, char *buf)
  1299. {
  1300. struct hid_device *hdev = to_hid_device(dev);
  1301. struct wacom *wacom = hid_get_drvdata(hdev);
  1302. return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
  1303. }
  1304. static ssize_t wacom_store_speed(struct device *dev,
  1305. struct device_attribute *attr,
  1306. const char *buf, size_t count)
  1307. {
  1308. struct hid_device *hdev = to_hid_device(dev);
  1309. struct wacom *wacom = hid_get_drvdata(hdev);
  1310. u8 new_speed;
  1311. if (kstrtou8(buf, 0, &new_speed))
  1312. return -EINVAL;
  1313. if (new_speed != 0 && new_speed != 1)
  1314. return -EINVAL;
  1315. wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
  1316. return count;
  1317. }
  1318. static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
  1319. wacom_show_speed, wacom_store_speed);
  1320. static ssize_t wacom_show_remote_mode(struct kobject *kobj,
  1321. struct kobj_attribute *kattr,
  1322. char *buf, int index)
  1323. {
  1324. struct device *dev = kobj_to_dev(kobj->parent);
  1325. struct hid_device *hdev = to_hid_device(dev);
  1326. struct wacom *wacom = hid_get_drvdata(hdev);
  1327. u8 mode;
  1328. mode = wacom->led.groups[index].select;
  1329. if (mode >= 0 && mode < 3)
  1330. return snprintf(buf, PAGE_SIZE, "%d\n", mode);
  1331. else
  1332. return snprintf(buf, PAGE_SIZE, "%d\n", -1);
  1333. }
  1334. #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
  1335. static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
  1336. struct kobj_attribute *kattr, char *buf) \
  1337. { \
  1338. return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
  1339. } \
  1340. static struct kobj_attribute remote##SET_ID##_mode_attr = { \
  1341. .attr = {.name = "remote_mode", \
  1342. .mode = DEV_ATTR_RO_PERM}, \
  1343. .show = wacom_show_remote##SET_ID##_mode, \
  1344. }; \
  1345. static struct attribute *remote##SET_ID##_serial_attrs[] = { \
  1346. &remote##SET_ID##_mode_attr.attr, \
  1347. NULL \
  1348. }; \
  1349. static struct attribute_group remote##SET_ID##_serial_group = { \
  1350. .name = NULL, \
  1351. .attrs = remote##SET_ID##_serial_attrs, \
  1352. }
  1353. DEVICE_EKR_ATTR_GROUP(0);
  1354. DEVICE_EKR_ATTR_GROUP(1);
  1355. DEVICE_EKR_ATTR_GROUP(2);
  1356. DEVICE_EKR_ATTR_GROUP(3);
  1357. DEVICE_EKR_ATTR_GROUP(4);
  1358. static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial,
  1359. int index)
  1360. {
  1361. int error = 0;
  1362. struct wacom_remote *remote = wacom->remote;
  1363. remote->remotes[index].group.name = devm_kasprintf(&wacom->hdev->dev,
  1364. GFP_KERNEL,
  1365. "%d", serial);
  1366. if (!remote->remotes[index].group.name)
  1367. return -ENOMEM;
  1368. error = __wacom_devm_sysfs_create_group(wacom, remote->remote_dir,
  1369. &remote->remotes[index].group);
  1370. if (error) {
  1371. remote->remotes[index].group.name = NULL;
  1372. hid_err(wacom->hdev,
  1373. "cannot create sysfs group err: %d\n", error);
  1374. return error;
  1375. }
  1376. return 0;
  1377. }
  1378. static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
  1379. {
  1380. const size_t buf_size = 2;
  1381. unsigned char *buf;
  1382. int retval;
  1383. buf = kzalloc(buf_size, GFP_KERNEL);
  1384. if (!buf)
  1385. return -ENOMEM;
  1386. buf[0] = WAC_CMD_DELETE_PAIRING;
  1387. buf[1] = selector;
  1388. retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf,
  1389. buf_size, WAC_CMD_RETRIES);
  1390. kfree(buf);
  1391. return retval;
  1392. }
  1393. static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
  1394. struct kobj_attribute *attr,
  1395. const char *buf, size_t count)
  1396. {
  1397. unsigned char selector = 0;
  1398. struct device *dev = kobj_to_dev(kobj->parent);
  1399. struct hid_device *hdev = to_hid_device(dev);
  1400. struct wacom *wacom = hid_get_drvdata(hdev);
  1401. int err;
  1402. if (!strncmp(buf, "*\n", 2)) {
  1403. selector = WAC_CMD_UNPAIR_ALL;
  1404. } else {
  1405. hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n",
  1406. buf);
  1407. return -1;
  1408. }
  1409. mutex_lock(&wacom->lock);
  1410. err = wacom_cmd_unpair_remote(wacom, selector);
  1411. mutex_unlock(&wacom->lock);
  1412. return err < 0 ? err : count;
  1413. }
  1414. static struct kobj_attribute unpair_remote_attr = {
  1415. .attr = {.name = "unpair_remote", .mode = 0200},
  1416. .store = wacom_store_unpair_remote,
  1417. };
  1418. static const struct attribute *remote_unpair_attrs[] = {
  1419. &unpair_remote_attr.attr,
  1420. NULL
  1421. };
  1422. static void wacom_remotes_destroy(void *data)
  1423. {
  1424. struct wacom *wacom = data;
  1425. struct wacom_remote *remote = wacom->remote;
  1426. if (!remote)
  1427. return;
  1428. kobject_put(remote->remote_dir);
  1429. kfifo_free(&remote->remote_fifo);
  1430. wacom->remote = NULL;
  1431. }
  1432. static int wacom_initialize_remotes(struct wacom *wacom)
  1433. {
  1434. int error = 0;
  1435. struct wacom_remote *remote;
  1436. int i;
  1437. if (wacom->wacom_wac.features.type != REMOTE)
  1438. return 0;
  1439. remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote),
  1440. GFP_KERNEL);
  1441. if (!remote)
  1442. return -ENOMEM;
  1443. wacom->remote = remote;
  1444. spin_lock_init(&remote->remote_lock);
  1445. error = kfifo_alloc(&remote->remote_fifo,
  1446. 5 * sizeof(struct wacom_remote_data),
  1447. GFP_KERNEL);
  1448. if (error) {
  1449. hid_err(wacom->hdev, "failed allocating remote_fifo\n");
  1450. return -ENOMEM;
  1451. }
  1452. remote->remotes[0].group = remote0_serial_group;
  1453. remote->remotes[1].group = remote1_serial_group;
  1454. remote->remotes[2].group = remote2_serial_group;
  1455. remote->remotes[3].group = remote3_serial_group;
  1456. remote->remotes[4].group = remote4_serial_group;
  1457. remote->remote_dir = kobject_create_and_add("wacom_remote",
  1458. &wacom->hdev->dev.kobj);
  1459. if (!remote->remote_dir)
  1460. return -ENOMEM;
  1461. error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs);
  1462. if (error) {
  1463. hid_err(wacom->hdev,
  1464. "cannot create sysfs group err: %d\n", error);
  1465. return error;
  1466. }
  1467. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  1468. wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
  1469. remote->remotes[i].serial = 0;
  1470. }
  1471. error = devm_add_action_or_reset(&wacom->hdev->dev,
  1472. wacom_remotes_destroy, wacom);
  1473. if (error)
  1474. return error;
  1475. return 0;
  1476. }
  1477. static struct input_dev *wacom_allocate_input(struct wacom *wacom)
  1478. {
  1479. struct input_dev *input_dev;
  1480. struct hid_device *hdev = wacom->hdev;
  1481. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1482. input_dev = devm_input_allocate_device(&hdev->dev);
  1483. if (!input_dev)
  1484. return NULL;
  1485. input_dev->name = wacom_wac->features.name;
  1486. input_dev->phys = hdev->phys;
  1487. input_dev->dev.parent = &hdev->dev;
  1488. input_dev->open = wacom_open;
  1489. input_dev->close = wacom_close;
  1490. input_dev->uniq = hdev->uniq;
  1491. input_dev->id.bustype = hdev->bus;
  1492. input_dev->id.vendor = hdev->vendor;
  1493. input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
  1494. input_dev->id.version = hdev->version;
  1495. input_set_drvdata(input_dev, wacom);
  1496. return input_dev;
  1497. }
  1498. static int wacom_allocate_inputs(struct wacom *wacom)
  1499. {
  1500. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1501. wacom_wac->pen_input = wacom_allocate_input(wacom);
  1502. wacom_wac->touch_input = wacom_allocate_input(wacom);
  1503. wacom_wac->pad_input = wacom_allocate_input(wacom);
  1504. if (!wacom_wac->pen_input ||
  1505. !wacom_wac->touch_input ||
  1506. !wacom_wac->pad_input)
  1507. return -ENOMEM;
  1508. wacom_wac->pen_input->name = wacom_wac->pen_name;
  1509. wacom_wac->touch_input->name = wacom_wac->touch_name;
  1510. wacom_wac->pad_input->name = wacom_wac->pad_name;
  1511. return 0;
  1512. }
  1513. static int wacom_register_inputs(struct wacom *wacom)
  1514. {
  1515. struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
  1516. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1517. int error = 0;
  1518. pen_input_dev = wacom_wac->pen_input;
  1519. touch_input_dev = wacom_wac->touch_input;
  1520. pad_input_dev = wacom_wac->pad_input;
  1521. if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
  1522. return -EINVAL;
  1523. error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
  1524. if (error) {
  1525. /* no pen in use on this interface */
  1526. input_free_device(pen_input_dev);
  1527. wacom_wac->pen_input = NULL;
  1528. pen_input_dev = NULL;
  1529. } else {
  1530. error = input_register_device(pen_input_dev);
  1531. if (error)
  1532. goto fail;
  1533. }
  1534. error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
  1535. if (error) {
  1536. /* no touch in use on this interface */
  1537. input_free_device(touch_input_dev);
  1538. wacom_wac->touch_input = NULL;
  1539. touch_input_dev = NULL;
  1540. } else {
  1541. error = input_register_device(touch_input_dev);
  1542. if (error)
  1543. goto fail;
  1544. }
  1545. error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
  1546. if (error) {
  1547. /* no pad in use on this interface */
  1548. input_free_device(pad_input_dev);
  1549. wacom_wac->pad_input = NULL;
  1550. pad_input_dev = NULL;
  1551. } else {
  1552. error = input_register_device(pad_input_dev);
  1553. if (error)
  1554. goto fail;
  1555. }
  1556. return 0;
  1557. fail:
  1558. wacom_wac->pad_input = NULL;
  1559. wacom_wac->touch_input = NULL;
  1560. wacom_wac->pen_input = NULL;
  1561. return error;
  1562. }
  1563. /*
  1564. * Not all devices report physical dimensions from HID.
  1565. * Compute the default from hardcoded logical dimension
  1566. * and resolution before driver overwrites them.
  1567. */
  1568. static void wacom_set_default_phy(struct wacom_features *features)
  1569. {
  1570. if (features->x_resolution) {
  1571. features->x_phy = (features->x_max * 100) /
  1572. features->x_resolution;
  1573. features->y_phy = (features->y_max * 100) /
  1574. features->y_resolution;
  1575. }
  1576. }
  1577. static void wacom_calculate_res(struct wacom_features *features)
  1578. {
  1579. /* set unit to "100th of a mm" for devices not reported by HID */
  1580. if (!features->unit) {
  1581. features->unit = 0x11;
  1582. features->unitExpo = -3;
  1583. }
  1584. features->x_resolution = wacom_calc_hid_res(features->x_max,
  1585. features->x_phy,
  1586. features->unit,
  1587. features->unitExpo);
  1588. features->y_resolution = wacom_calc_hid_res(features->y_max,
  1589. features->y_phy,
  1590. features->unit,
  1591. features->unitExpo);
  1592. }
  1593. void wacom_battery_work(struct work_struct *work)
  1594. {
  1595. struct wacom *wacom = container_of(work, struct wacom, battery_work);
  1596. if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
  1597. !wacom->battery.battery) {
  1598. wacom_initialize_battery(wacom);
  1599. }
  1600. else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
  1601. wacom->battery.battery) {
  1602. wacom_destroy_battery(wacom);
  1603. }
  1604. }
  1605. static size_t wacom_compute_pktlen(struct hid_device *hdev)
  1606. {
  1607. struct hid_report_enum *report_enum;
  1608. struct hid_report *report;
  1609. size_t size = 0;
  1610. report_enum = hdev->report_enum + HID_INPUT_REPORT;
  1611. list_for_each_entry(report, &report_enum->report_list, list) {
  1612. size_t report_size = hid_report_len(report);
  1613. if (report_size > size)
  1614. size = report_size;
  1615. }
  1616. return size;
  1617. }
  1618. static void wacom_update_name(struct wacom *wacom, const char *suffix)
  1619. {
  1620. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1621. struct wacom_features *features = &wacom_wac->features;
  1622. char name[WACOM_NAME_MAX];
  1623. /* Generic devices name unspecified */
  1624. if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
  1625. if (strstr(wacom->hdev->name, "Wacom") ||
  1626. strstr(wacom->hdev->name, "wacom") ||
  1627. strstr(wacom->hdev->name, "WACOM")) {
  1628. /* name is in HID descriptor, use it */
  1629. strlcpy(name, wacom->hdev->name, sizeof(name));
  1630. /* strip out excess whitespaces */
  1631. while (1) {
  1632. char *gap = strstr(name, " ");
  1633. if (gap == NULL)
  1634. break;
  1635. /* shift everything including the terminator */
  1636. memmove(gap, gap+1, strlen(gap));
  1637. }
  1638. /* strip off excessive prefixing */
  1639. if (strstr(name, "Wacom Co.,Ltd. Wacom ") == name) {
  1640. int n = strlen(name);
  1641. int x = strlen("Wacom Co.,Ltd. ");
  1642. memmove(name, name+x, n-x+1);
  1643. }
  1644. if (strstr(name, "Wacom Co., Ltd. Wacom ") == name) {
  1645. int n = strlen(name);
  1646. int x = strlen("Wacom Co., Ltd. ");
  1647. memmove(name, name+x, n-x+1);
  1648. }
  1649. /* get rid of trailing whitespace */
  1650. if (name[strlen(name)-1] == ' ')
  1651. name[strlen(name)-1] = '\0';
  1652. } else {
  1653. /* no meaningful name retrieved. use product ID */
  1654. snprintf(name, sizeof(name),
  1655. "%s %X", features->name, wacom->hdev->product);
  1656. }
  1657. } else {
  1658. strlcpy(name, features->name, sizeof(name));
  1659. }
  1660. snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s",
  1661. name, suffix);
  1662. /* Append the device type to the name */
  1663. snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
  1664. "%s%s Pen", name, suffix);
  1665. snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
  1666. "%s%s Finger", name, suffix);
  1667. snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
  1668. "%s%s Pad", name, suffix);
  1669. }
  1670. static void wacom_release_resources(struct wacom *wacom)
  1671. {
  1672. struct hid_device *hdev = wacom->hdev;
  1673. if (!wacom->resources)
  1674. return;
  1675. devres_release_group(&hdev->dev, wacom);
  1676. wacom->resources = false;
  1677. wacom->wacom_wac.pen_input = NULL;
  1678. wacom->wacom_wac.touch_input = NULL;
  1679. wacom->wacom_wac.pad_input = NULL;
  1680. }
  1681. static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
  1682. {
  1683. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1684. struct wacom_features *features = &wacom_wac->features;
  1685. struct hid_device *hdev = wacom->hdev;
  1686. int error;
  1687. unsigned int connect_mask = HID_CONNECT_HIDRAW;
  1688. features->pktlen = wacom_compute_pktlen(hdev);
  1689. if (features->pktlen > WACOM_PKGLEN_MAX)
  1690. return -EINVAL;
  1691. if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL))
  1692. return -ENOMEM;
  1693. wacom->resources = true;
  1694. error = wacom_allocate_inputs(wacom);
  1695. if (error)
  1696. goto fail;
  1697. /*
  1698. * Bamboo Pad has a generic hid handling for the Pen, and we switch it
  1699. * into debug mode for the touch part.
  1700. * We ignore the other interfaces.
  1701. */
  1702. if (features->type == BAMBOO_PAD) {
  1703. if (features->pktlen == WACOM_PKGLEN_PENABLED) {
  1704. features->type = HID_GENERIC;
  1705. } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
  1706. (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
  1707. error = -ENODEV;
  1708. goto fail;
  1709. }
  1710. }
  1711. /* set the default size in case we do not get them from hid */
  1712. wacom_set_default_phy(features);
  1713. /* Retrieve the physical and logical size for touch devices */
  1714. wacom_retrieve_hid_descriptor(hdev, features);
  1715. wacom_setup_device_quirks(wacom);
  1716. if (features->device_type == WACOM_DEVICETYPE_NONE &&
  1717. features->type != WIRELESS) {
  1718. error = features->type == HID_GENERIC ? -ENODEV : 0;
  1719. dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
  1720. hdev->name,
  1721. error ? "Ignoring" : "Assuming pen");
  1722. if (error)
  1723. goto fail;
  1724. features->device_type |= WACOM_DEVICETYPE_PEN;
  1725. }
  1726. wacom_calculate_res(features);
  1727. wacom_update_name(wacom, wireless ? " (WL)" : "");
  1728. error = wacom_add_shared_data(hdev);
  1729. if (error)
  1730. goto fail;
  1731. if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
  1732. (features->quirks & WACOM_QUIRK_BATTERY)) {
  1733. error = wacom_initialize_battery(wacom);
  1734. if (error)
  1735. goto fail;
  1736. }
  1737. error = wacom_register_inputs(wacom);
  1738. if (error)
  1739. goto fail;
  1740. if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD) {
  1741. error = wacom_initialize_leds(wacom);
  1742. if (error)
  1743. goto fail;
  1744. error = wacom_initialize_remotes(wacom);
  1745. if (error)
  1746. goto fail;
  1747. }
  1748. if (features->type == HID_GENERIC)
  1749. connect_mask |= HID_CONNECT_DRIVER;
  1750. /* Regular HID work starts now */
  1751. error = hid_hw_start(hdev, connect_mask);
  1752. if (error) {
  1753. hid_err(hdev, "hw start failed\n");
  1754. goto fail;
  1755. }
  1756. if (!wireless) {
  1757. /* Note that if query fails it is not a hard failure */
  1758. wacom_query_tablet_data(hdev, features);
  1759. }
  1760. /* touch only Bamboo doesn't support pen */
  1761. if ((features->type == BAMBOO_TOUCH) &&
  1762. (features->device_type & WACOM_DEVICETYPE_PEN)) {
  1763. error = -ENODEV;
  1764. goto fail_quirks;
  1765. }
  1766. /* pen only Bamboo neither support touch nor pad */
  1767. if ((features->type == BAMBOO_PEN) &&
  1768. ((features->device_type & WACOM_DEVICETYPE_TOUCH) ||
  1769. (features->device_type & WACOM_DEVICETYPE_PAD))) {
  1770. error = -ENODEV;
  1771. goto fail_quirks;
  1772. }
  1773. if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
  1774. error = hid_hw_open(hdev);
  1775. if ((wacom_wac->features.type == INTUOSHT ||
  1776. wacom_wac->features.type == INTUOSHT2) &&
  1777. (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)) {
  1778. wacom_wac->shared->type = wacom_wac->features.type;
  1779. wacom_wac->shared->touch_input = wacom_wac->touch_input;
  1780. }
  1781. devres_close_group(&hdev->dev, wacom);
  1782. return 0;
  1783. fail_quirks:
  1784. hid_hw_stop(hdev);
  1785. fail:
  1786. wacom_release_resources(wacom);
  1787. return error;
  1788. }
  1789. static void wacom_wireless_work(struct work_struct *work)
  1790. {
  1791. struct wacom *wacom = container_of(work, struct wacom, wireless_work);
  1792. struct usb_device *usbdev = wacom->usbdev;
  1793. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1794. struct hid_device *hdev1, *hdev2;
  1795. struct wacom *wacom1, *wacom2;
  1796. struct wacom_wac *wacom_wac1, *wacom_wac2;
  1797. int error;
  1798. /*
  1799. * Regardless if this is a disconnect or a new tablet,
  1800. * remove any existing input and battery devices.
  1801. */
  1802. wacom_destroy_battery(wacom);
  1803. /* Stylus interface */
  1804. hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
  1805. wacom1 = hid_get_drvdata(hdev1);
  1806. wacom_wac1 = &(wacom1->wacom_wac);
  1807. wacom_release_resources(wacom1);
  1808. /* Touch interface */
  1809. hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
  1810. wacom2 = hid_get_drvdata(hdev2);
  1811. wacom_wac2 = &(wacom2->wacom_wac);
  1812. wacom_release_resources(wacom2);
  1813. if (wacom_wac->pid == 0) {
  1814. hid_info(wacom->hdev, "wireless tablet disconnected\n");
  1815. } else {
  1816. const struct hid_device_id *id = wacom_ids;
  1817. hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
  1818. wacom_wac->pid);
  1819. while (id->bus) {
  1820. if (id->vendor == USB_VENDOR_ID_WACOM &&
  1821. id->product == wacom_wac->pid)
  1822. break;
  1823. id++;
  1824. }
  1825. if (!id->bus) {
  1826. hid_info(wacom->hdev, "ignoring unknown PID.\n");
  1827. return;
  1828. }
  1829. /* Stylus interface */
  1830. wacom_wac1->features =
  1831. *((struct wacom_features *)id->driver_data);
  1832. wacom_wac1->pid = wacom_wac->pid;
  1833. hid_hw_stop(hdev1);
  1834. error = wacom_parse_and_register(wacom1, true);
  1835. if (error)
  1836. goto fail;
  1837. /* Touch interface */
  1838. if (wacom_wac1->features.touch_max ||
  1839. (wacom_wac1->features.type >= INTUOSHT &&
  1840. wacom_wac1->features.type <= BAMBOO_PT)) {
  1841. wacom_wac2->features =
  1842. *((struct wacom_features *)id->driver_data);
  1843. wacom_wac2->pid = wacom_wac->pid;
  1844. hid_hw_stop(hdev2);
  1845. error = wacom_parse_and_register(wacom2, true);
  1846. if (error)
  1847. goto fail;
  1848. }
  1849. strlcpy(wacom_wac->name, wacom_wac1->name,
  1850. sizeof(wacom_wac->name));
  1851. error = wacom_initialize_battery(wacom);
  1852. if (error)
  1853. goto fail;
  1854. }
  1855. return;
  1856. fail:
  1857. wacom_release_resources(wacom1);
  1858. wacom_release_resources(wacom2);
  1859. return;
  1860. }
  1861. static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
  1862. {
  1863. struct wacom_remote *remote = wacom->remote;
  1864. u32 serial = remote->remotes[index].serial;
  1865. int i;
  1866. unsigned long flags;
  1867. spin_lock_irqsave(&remote->remote_lock, flags);
  1868. remote->remotes[index].registered = false;
  1869. spin_unlock_irqrestore(&remote->remote_lock, flags);
  1870. if (remote->remotes[index].battery.battery)
  1871. devres_release_group(&wacom->hdev->dev,
  1872. &remote->remotes[index].battery.bat_desc);
  1873. if (remote->remotes[index].group.name)
  1874. devres_release_group(&wacom->hdev->dev,
  1875. &remote->remotes[index]);
  1876. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  1877. if (remote->remotes[i].serial == serial) {
  1878. remote->remotes[i].serial = 0;
  1879. remote->remotes[i].group.name = NULL;
  1880. remote->remotes[i].registered = false;
  1881. remote->remotes[i].battery.battery = NULL;
  1882. wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
  1883. }
  1884. }
  1885. }
  1886. static int wacom_remote_create_one(struct wacom *wacom, u32 serial,
  1887. unsigned int index)
  1888. {
  1889. struct wacom_remote *remote = wacom->remote;
  1890. struct device *dev = &wacom->hdev->dev;
  1891. int error, k;
  1892. /* A remote can pair more than once with an EKR,
  1893. * check to make sure this serial isn't already paired.
  1894. */
  1895. for (k = 0; k < WACOM_MAX_REMOTES; k++) {
  1896. if (remote->remotes[k].serial == serial)
  1897. break;
  1898. }
  1899. if (k < WACOM_MAX_REMOTES) {
  1900. remote->remotes[index].serial = serial;
  1901. return 0;
  1902. }
  1903. if (!devres_open_group(dev, &remote->remotes[index], GFP_KERNEL))
  1904. return -ENOMEM;
  1905. error = wacom_remote_create_attr_group(wacom, serial, index);
  1906. if (error)
  1907. goto fail;
  1908. remote->remotes[index].input = wacom_allocate_input(wacom);
  1909. if (!remote->remotes[index].input) {
  1910. error = -ENOMEM;
  1911. goto fail;
  1912. }
  1913. remote->remotes[index].input->uniq = remote->remotes[index].group.name;
  1914. remote->remotes[index].input->name = wacom->wacom_wac.pad_name;
  1915. if (!remote->remotes[index].input->name) {
  1916. error = -EINVAL;
  1917. goto fail;
  1918. }
  1919. error = wacom_setup_pad_input_capabilities(remote->remotes[index].input,
  1920. &wacom->wacom_wac);
  1921. if (error)
  1922. goto fail;
  1923. remote->remotes[index].serial = serial;
  1924. error = input_register_device(remote->remotes[index].input);
  1925. if (error)
  1926. goto fail;
  1927. error = wacom_led_groups_alloc_and_register_one(
  1928. &remote->remotes[index].input->dev,
  1929. wacom, index, 3, true);
  1930. if (error)
  1931. goto fail;
  1932. remote->remotes[index].registered = true;
  1933. devres_close_group(dev, &remote->remotes[index]);
  1934. return 0;
  1935. fail:
  1936. devres_release_group(dev, &remote->remotes[index]);
  1937. remote->remotes[index].serial = 0;
  1938. return error;
  1939. }
  1940. static int wacom_remote_attach_battery(struct wacom *wacom, int index)
  1941. {
  1942. struct wacom_remote *remote = wacom->remote;
  1943. int error;
  1944. if (!remote->remotes[index].registered)
  1945. return 0;
  1946. if (remote->remotes[index].battery.battery)
  1947. return 0;
  1948. if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
  1949. return 0;
  1950. error = __wacom_initialize_battery(wacom,
  1951. &wacom->remote->remotes[index].battery);
  1952. if (error)
  1953. return error;
  1954. return 0;
  1955. }
  1956. static void wacom_remote_work(struct work_struct *work)
  1957. {
  1958. struct wacom *wacom = container_of(work, struct wacom, remote_work);
  1959. struct wacom_remote *remote = wacom->remote;
  1960. struct wacom_remote_data data;
  1961. unsigned long flags;
  1962. unsigned int count;
  1963. u32 serial;
  1964. int i;
  1965. spin_lock_irqsave(&remote->remote_lock, flags);
  1966. count = kfifo_out(&remote->remote_fifo, &data, sizeof(data));
  1967. if (count != sizeof(data)) {
  1968. hid_err(wacom->hdev,
  1969. "workitem triggered without status available\n");
  1970. spin_unlock_irqrestore(&remote->remote_lock, flags);
  1971. return;
  1972. }
  1973. if (!kfifo_is_empty(&remote->remote_fifo))
  1974. wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_REMOTE);
  1975. spin_unlock_irqrestore(&remote->remote_lock, flags);
  1976. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  1977. serial = data.remote[i].serial;
  1978. if (data.remote[i].connected) {
  1979. if (remote->remotes[i].serial == serial) {
  1980. wacom_remote_attach_battery(wacom, i);
  1981. continue;
  1982. }
  1983. if (remote->remotes[i].serial)
  1984. wacom_remote_destroy_one(wacom, i);
  1985. wacom_remote_create_one(wacom, serial, i);
  1986. } else if (remote->remotes[i].serial) {
  1987. wacom_remote_destroy_one(wacom, i);
  1988. }
  1989. }
  1990. }
  1991. static int wacom_probe(struct hid_device *hdev,
  1992. const struct hid_device_id *id)
  1993. {
  1994. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  1995. struct usb_device *dev = interface_to_usbdev(intf);
  1996. struct wacom *wacom;
  1997. struct wacom_wac *wacom_wac;
  1998. struct wacom_features *features;
  1999. int error;
  2000. if (!id->driver_data)
  2001. return -EINVAL;
  2002. hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
  2003. /* hid-core sets this quirk for the boot interface */
  2004. hdev->quirks &= ~HID_QUIRK_NOGET;
  2005. wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL);
  2006. if (!wacom)
  2007. return -ENOMEM;
  2008. hid_set_drvdata(hdev, wacom);
  2009. wacom->hdev = hdev;
  2010. wacom_wac = &wacom->wacom_wac;
  2011. wacom_wac->features = *((struct wacom_features *)id->driver_data);
  2012. features = &wacom_wac->features;
  2013. if (features->check_for_hid_type && features->hid_type != hdev->type) {
  2014. error = -ENODEV;
  2015. goto fail;
  2016. }
  2017. wacom_wac->hid_data.inputmode = -1;
  2018. wacom_wac->mode_report = -1;
  2019. wacom->usbdev = dev;
  2020. wacom->intf = intf;
  2021. mutex_init(&wacom->lock);
  2022. INIT_WORK(&wacom->wireless_work, wacom_wireless_work);
  2023. INIT_WORK(&wacom->battery_work, wacom_battery_work);
  2024. INIT_WORK(&wacom->remote_work, wacom_remote_work);
  2025. /* ask for the report descriptor to be loaded by HID */
  2026. error = hid_parse(hdev);
  2027. if (error) {
  2028. hid_err(hdev, "parse failed\n");
  2029. goto fail;
  2030. }
  2031. error = wacom_parse_and_register(wacom, false);
  2032. if (error)
  2033. goto fail;
  2034. if (hdev->bus == BUS_BLUETOOTH) {
  2035. error = device_create_file(&hdev->dev, &dev_attr_speed);
  2036. if (error)
  2037. hid_warn(hdev,
  2038. "can't create sysfs speed attribute err: %d\n",
  2039. error);
  2040. }
  2041. return 0;
  2042. fail:
  2043. hid_set_drvdata(hdev, NULL);
  2044. return error;
  2045. }
  2046. static void wacom_remove(struct hid_device *hdev)
  2047. {
  2048. struct wacom *wacom = hid_get_drvdata(hdev);
  2049. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2050. struct wacom_features *features = &wacom_wac->features;
  2051. if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
  2052. hid_hw_close(hdev);
  2053. hid_hw_stop(hdev);
  2054. cancel_work_sync(&wacom->wireless_work);
  2055. cancel_work_sync(&wacom->battery_work);
  2056. cancel_work_sync(&wacom->remote_work);
  2057. if (hdev->bus == BUS_BLUETOOTH)
  2058. device_remove_file(&hdev->dev, &dev_attr_speed);
  2059. hid_set_drvdata(hdev, NULL);
  2060. }
  2061. #ifdef CONFIG_PM
  2062. static int wacom_resume(struct hid_device *hdev)
  2063. {
  2064. struct wacom *wacom = hid_get_drvdata(hdev);
  2065. struct wacom_features *features = &wacom->wacom_wac.features;
  2066. mutex_lock(&wacom->lock);
  2067. /* switch to wacom mode first */
  2068. wacom_query_tablet_data(hdev, features);
  2069. wacom_led_control(wacom);
  2070. mutex_unlock(&wacom->lock);
  2071. return 0;
  2072. }
  2073. static int wacom_reset_resume(struct hid_device *hdev)
  2074. {
  2075. return wacom_resume(hdev);
  2076. }
  2077. #endif /* CONFIG_PM */
  2078. static struct hid_driver wacom_driver = {
  2079. .name = "wacom",
  2080. .id_table = wacom_ids,
  2081. .probe = wacom_probe,
  2082. .remove = wacom_remove,
  2083. .report = wacom_wac_report,
  2084. #ifdef CONFIG_PM
  2085. .resume = wacom_resume,
  2086. .reset_resume = wacom_reset_resume,
  2087. #endif
  2088. .raw_event = wacom_raw_event,
  2089. };
  2090. module_hid_driver(wacom_driver);
  2091. MODULE_VERSION(DRIVER_VERSION);
  2092. MODULE_AUTHOR(DRIVER_AUTHOR);
  2093. MODULE_DESCRIPTION(DRIVER_DESC);
  2094. MODULE_LICENSE(DRIVER_LICENSE);