wacom_sys.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  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 WAC_REMOTE_SERIAL_MAX_STRLEN 9
  25. #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
  26. #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
  27. #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
  28. static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf,
  29. size_t size, unsigned int retries)
  30. {
  31. int retval;
  32. do {
  33. retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
  34. HID_REQ_GET_REPORT);
  35. } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
  36. if (retval < 0)
  37. hid_err(hdev, "wacom_get_report: ran out of retries "
  38. "(last error = %d)\n", retval);
  39. return retval;
  40. }
  41. static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
  42. size_t size, unsigned int retries)
  43. {
  44. int retval;
  45. do {
  46. retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
  47. HID_REQ_SET_REPORT);
  48. } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
  49. if (retval < 0)
  50. hid_err(hdev, "wacom_set_report: ran out of retries "
  51. "(last error = %d)\n", retval);
  52. return retval;
  53. }
  54. static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
  55. u8 *raw_data, int size)
  56. {
  57. struct wacom *wacom = hid_get_drvdata(hdev);
  58. if (size > WACOM_PKGLEN_MAX)
  59. return 1;
  60. memcpy(wacom->wacom_wac.data, raw_data, size);
  61. wacom_wac_irq(&wacom->wacom_wac, size);
  62. return 0;
  63. }
  64. static int wacom_open(struct input_dev *dev)
  65. {
  66. struct wacom *wacom = input_get_drvdata(dev);
  67. return hid_hw_open(wacom->hdev);
  68. }
  69. static void wacom_close(struct input_dev *dev)
  70. {
  71. struct wacom *wacom = input_get_drvdata(dev);
  72. hid_hw_close(wacom->hdev);
  73. }
  74. /*
  75. * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
  76. */
  77. static int wacom_calc_hid_res(int logical_extents, int physical_extents,
  78. unsigned unit, int exponent)
  79. {
  80. struct hid_field field = {
  81. .logical_maximum = logical_extents,
  82. .physical_maximum = physical_extents,
  83. .unit = unit,
  84. .unit_exponent = exponent,
  85. };
  86. return hidinput_calc_abs_res(&field, ABS_X);
  87. }
  88. static void wacom_feature_mapping(struct hid_device *hdev,
  89. struct hid_field *field, struct hid_usage *usage)
  90. {
  91. struct wacom *wacom = hid_get_drvdata(hdev);
  92. struct wacom_features *features = &wacom->wacom_wac.features;
  93. struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
  94. u8 *data;
  95. int ret;
  96. switch (usage->hid) {
  97. case HID_DG_CONTACTMAX:
  98. /* leave touch_max as is if predefined */
  99. if (!features->touch_max) {
  100. /* read manually */
  101. data = kzalloc(2, GFP_KERNEL);
  102. if (!data)
  103. break;
  104. data[0] = field->report->id;
  105. ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
  106. data, 2, WAC_CMD_RETRIES);
  107. if (ret == 2) {
  108. features->touch_max = data[1];
  109. } else {
  110. features->touch_max = 16;
  111. hid_warn(hdev, "wacom_feature_mapping: "
  112. "could not get HID_DG_CONTACTMAX, "
  113. "defaulting to %d\n",
  114. features->touch_max);
  115. }
  116. kfree(data);
  117. }
  118. break;
  119. case HID_DG_INPUTMODE:
  120. /* Ignore if value index is out of bounds. */
  121. if (usage->usage_index >= field->report_count) {
  122. dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
  123. break;
  124. }
  125. hid_data->inputmode = field->report->id;
  126. hid_data->inputmode_index = usage->usage_index;
  127. break;
  128. }
  129. }
  130. /*
  131. * Interface Descriptor of wacom devices can be incomplete and
  132. * inconsistent so wacom_features table is used to store stylus
  133. * device's packet lengths, various maximum values, and tablet
  134. * resolution based on product ID's.
  135. *
  136. * For devices that contain 2 interfaces, wacom_features table is
  137. * inaccurate for the touch interface. Since the Interface Descriptor
  138. * for touch interfaces has pretty complete data, this function exists
  139. * to query tablet for this missing information instead of hard coding in
  140. * an additional table.
  141. *
  142. * A typical Interface Descriptor for a stylus will contain a
  143. * boot mouse application collection that is not of interest and this
  144. * function will ignore it.
  145. *
  146. * It also contains a digitizer application collection that also is not
  147. * of interest since any information it contains would be duplicate
  148. * of what is in wacom_features. Usually it defines a report of an array
  149. * of bytes that could be used as max length of the stylus packet returned.
  150. * If it happens to define a Digitizer-Stylus Physical Collection then
  151. * the X and Y logical values contain valid data but it is ignored.
  152. *
  153. * A typical Interface Descriptor for a touch interface will contain a
  154. * Digitizer-Finger Physical Collection which will define both logical
  155. * X/Y maximum as well as the physical size of tablet. Since touch
  156. * interfaces haven't supported pressure or distance, this is enough
  157. * information to override invalid values in the wacom_features table.
  158. *
  159. * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
  160. * data. We deal with them after returning from this function.
  161. */
  162. static void wacom_usage_mapping(struct hid_device *hdev,
  163. struct hid_field *field, struct hid_usage *usage)
  164. {
  165. struct wacom *wacom = hid_get_drvdata(hdev);
  166. struct wacom_features *features = &wacom->wacom_wac.features;
  167. bool finger = WACOM_FINGER_FIELD(field);
  168. bool pen = WACOM_PEN_FIELD(field);
  169. /*
  170. * Requiring Stylus Usage will ignore boot mouse
  171. * X/Y values and some cases of invalid Digitizer X/Y
  172. * values commonly reported.
  173. */
  174. if (pen)
  175. features->device_type |= WACOM_DEVICETYPE_PEN;
  176. else if (finger)
  177. features->device_type |= WACOM_DEVICETYPE_TOUCH;
  178. else
  179. return;
  180. /*
  181. * Bamboo models do not support HID_DG_CONTACTMAX.
  182. * And, Bamboo Pen only descriptor contains touch.
  183. */
  184. if (features->type > BAMBOO_PT) {
  185. /* ISDv4 touch devices at least supports one touch point */
  186. if (finger && !features->touch_max)
  187. features->touch_max = 1;
  188. }
  189. switch (usage->hid) {
  190. case HID_GD_X:
  191. features->x_max = field->logical_maximum;
  192. if (finger) {
  193. features->x_phy = field->physical_maximum;
  194. if ((features->type != BAMBOO_PT) &&
  195. (features->type != BAMBOO_TOUCH)) {
  196. features->unit = field->unit;
  197. features->unitExpo = field->unit_exponent;
  198. }
  199. }
  200. break;
  201. case HID_GD_Y:
  202. features->y_max = field->logical_maximum;
  203. if (finger) {
  204. features->y_phy = field->physical_maximum;
  205. if ((features->type != BAMBOO_PT) &&
  206. (features->type != BAMBOO_TOUCH)) {
  207. features->unit = field->unit;
  208. features->unitExpo = field->unit_exponent;
  209. }
  210. }
  211. break;
  212. case HID_DG_TIPPRESSURE:
  213. if (pen)
  214. features->pressure_max = field->logical_maximum;
  215. break;
  216. }
  217. if (features->type == HID_GENERIC)
  218. wacom_wac_usage_mapping(hdev, field, usage);
  219. }
  220. static void wacom_post_parse_hid(struct hid_device *hdev,
  221. struct wacom_features *features)
  222. {
  223. struct wacom *wacom = hid_get_drvdata(hdev);
  224. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  225. if (features->type == HID_GENERIC) {
  226. /* Any last-minute generic device setup */
  227. if (features->touch_max > 1) {
  228. input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max,
  229. INPUT_MT_DIRECT);
  230. }
  231. }
  232. }
  233. static void wacom_parse_hid(struct hid_device *hdev,
  234. struct wacom_features *features)
  235. {
  236. struct hid_report_enum *rep_enum;
  237. struct hid_report *hreport;
  238. int i, j;
  239. /* check features first */
  240. rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
  241. list_for_each_entry(hreport, &rep_enum->report_list, list) {
  242. for (i = 0; i < hreport->maxfield; i++) {
  243. /* Ignore if report count is out of bounds. */
  244. if (hreport->field[i]->report_count < 1)
  245. continue;
  246. for (j = 0; j < hreport->field[i]->maxusage; j++) {
  247. wacom_feature_mapping(hdev, hreport->field[i],
  248. hreport->field[i]->usage + j);
  249. }
  250. }
  251. }
  252. /* now check the input usages */
  253. rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
  254. list_for_each_entry(hreport, &rep_enum->report_list, list) {
  255. if (!hreport->maxfield)
  256. continue;
  257. for (i = 0; i < hreport->maxfield; i++)
  258. for (j = 0; j < hreport->field[i]->maxusage; j++)
  259. wacom_usage_mapping(hdev, hreport->field[i],
  260. hreport->field[i]->usage + j);
  261. }
  262. wacom_post_parse_hid(hdev, features);
  263. }
  264. static int wacom_hid_set_device_mode(struct hid_device *hdev)
  265. {
  266. struct wacom *wacom = hid_get_drvdata(hdev);
  267. struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
  268. struct hid_report *r;
  269. struct hid_report_enum *re;
  270. if (hid_data->inputmode < 0)
  271. return 0;
  272. re = &(hdev->report_enum[HID_FEATURE_REPORT]);
  273. r = re->report_id_hash[hid_data->inputmode];
  274. if (r) {
  275. r->field[0]->value[hid_data->inputmode_index] = 2;
  276. hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
  277. }
  278. return 0;
  279. }
  280. static int wacom_set_device_mode(struct hid_device *hdev, int report_id,
  281. int length, int mode)
  282. {
  283. unsigned char *rep_data;
  284. int error = -ENOMEM, limit = 0;
  285. rep_data = kzalloc(length, GFP_KERNEL);
  286. if (!rep_data)
  287. return error;
  288. do {
  289. rep_data[0] = report_id;
  290. rep_data[1] = mode;
  291. error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
  292. length, 1);
  293. if (error >= 0)
  294. error = wacom_get_report(hdev, HID_FEATURE_REPORT,
  295. rep_data, length, 1);
  296. } while (error >= 0 && rep_data[1] != mode && limit++ < WAC_MSG_RETRIES);
  297. kfree(rep_data);
  298. return error < 0 ? error : 0;
  299. }
  300. static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
  301. struct wacom_features *features)
  302. {
  303. struct wacom *wacom = hid_get_drvdata(hdev);
  304. int ret;
  305. u8 rep_data[2];
  306. switch (features->type) {
  307. case GRAPHIRE_BT:
  308. rep_data[0] = 0x03;
  309. rep_data[1] = 0x00;
  310. ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
  311. 3);
  312. if (ret >= 0) {
  313. rep_data[0] = speed == 0 ? 0x05 : 0x06;
  314. rep_data[1] = 0x00;
  315. ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
  316. rep_data, 2, 3);
  317. if (ret >= 0) {
  318. wacom->wacom_wac.bt_high_speed = speed;
  319. return 0;
  320. }
  321. }
  322. /*
  323. * Note that if the raw queries fail, it's not a hard failure
  324. * and it is safe to continue
  325. */
  326. hid_warn(hdev, "failed to poke device, command %d, err %d\n",
  327. rep_data[0], ret);
  328. break;
  329. case INTUOS4WL:
  330. if (speed == 1)
  331. wacom->wacom_wac.bt_features &= ~0x20;
  332. else
  333. wacom->wacom_wac.bt_features |= 0x20;
  334. rep_data[0] = 0x03;
  335. rep_data[1] = wacom->wacom_wac.bt_features;
  336. ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
  337. 1);
  338. if (ret >= 0)
  339. wacom->wacom_wac.bt_high_speed = speed;
  340. break;
  341. }
  342. return 0;
  343. }
  344. /*
  345. * Switch the tablet into its most-capable mode. Wacom tablets are
  346. * typically configured to power-up in a mode which sends mouse-like
  347. * reports to the OS. To get absolute position, pressure data, etc.
  348. * from the tablet, it is necessary to switch the tablet out of this
  349. * mode and into one which sends the full range of tablet data.
  350. */
  351. static int wacom_query_tablet_data(struct hid_device *hdev,
  352. struct wacom_features *features)
  353. {
  354. if (hdev->bus == BUS_BLUETOOTH)
  355. return wacom_bt_query_tablet_data(hdev, 1, features);
  356. if (features->type == HID_GENERIC)
  357. return wacom_hid_set_device_mode(hdev);
  358. if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
  359. if (features->type > TABLETPC) {
  360. /* MT Tablet PC touch */
  361. return wacom_set_device_mode(hdev, 3, 4, 4);
  362. }
  363. else if (features->type == WACOM_24HDT) {
  364. return wacom_set_device_mode(hdev, 18, 3, 2);
  365. }
  366. else if (features->type == WACOM_27QHDT) {
  367. return wacom_set_device_mode(hdev, 131, 3, 2);
  368. }
  369. else if (features->type == BAMBOO_PAD) {
  370. return wacom_set_device_mode(hdev, 2, 2, 2);
  371. }
  372. } else if (features->device_type & WACOM_DEVICETYPE_PEN) {
  373. if (features->type <= BAMBOO_PT) {
  374. return wacom_set_device_mode(hdev, 2, 2, 2);
  375. }
  376. }
  377. return 0;
  378. }
  379. static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
  380. struct wacom_features *features)
  381. {
  382. struct wacom *wacom = hid_get_drvdata(hdev);
  383. struct usb_interface *intf = wacom->intf;
  384. /* default features */
  385. features->x_fuzz = 4;
  386. features->y_fuzz = 4;
  387. features->pressure_fuzz = 0;
  388. features->distance_fuzz = 0;
  389. /*
  390. * The wireless device HID is basic and layout conflicts with
  391. * other tablets (monitor and touch interface can look like pen).
  392. * Skip the query for this type and modify defaults based on
  393. * interface number.
  394. */
  395. if (features->type == WIRELESS) {
  396. if (intf->cur_altsetting->desc.bInterfaceNumber == 0)
  397. features->device_type = WACOM_DEVICETYPE_WL_MONITOR;
  398. else
  399. features->device_type = WACOM_DEVICETYPE_NONE;
  400. return;
  401. }
  402. wacom_parse_hid(hdev, features);
  403. }
  404. struct wacom_hdev_data {
  405. struct list_head list;
  406. struct kref kref;
  407. struct hid_device *dev;
  408. struct wacom_shared shared;
  409. };
  410. static LIST_HEAD(wacom_udev_list);
  411. static DEFINE_MUTEX(wacom_udev_list_lock);
  412. static bool wacom_are_sibling(struct hid_device *hdev,
  413. struct hid_device *sibling)
  414. {
  415. struct wacom *wacom = hid_get_drvdata(hdev);
  416. struct wacom_features *features = &wacom->wacom_wac.features;
  417. int vid = features->oVid;
  418. int pid = features->oPid;
  419. int n1,n2;
  420. if (vid == 0 && pid == 0) {
  421. vid = hdev->vendor;
  422. pid = hdev->product;
  423. }
  424. if (vid != sibling->vendor || pid != sibling->product)
  425. return false;
  426. /* Compare the physical path. */
  427. n1 = strrchr(hdev->phys, '.') - hdev->phys;
  428. n2 = strrchr(sibling->phys, '.') - sibling->phys;
  429. if (n1 != n2 || n1 <= 0 || n2 <= 0)
  430. return false;
  431. return !strncmp(hdev->phys, sibling->phys, n1);
  432. }
  433. static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
  434. {
  435. struct wacom_hdev_data *data;
  436. list_for_each_entry(data, &wacom_udev_list, list) {
  437. if (wacom_are_sibling(hdev, data->dev)) {
  438. kref_get(&data->kref);
  439. return data;
  440. }
  441. }
  442. return NULL;
  443. }
  444. static int wacom_add_shared_data(struct hid_device *hdev)
  445. {
  446. struct wacom *wacom = hid_get_drvdata(hdev);
  447. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  448. struct wacom_hdev_data *data;
  449. int retval = 0;
  450. mutex_lock(&wacom_udev_list_lock);
  451. data = wacom_get_hdev_data(hdev);
  452. if (!data) {
  453. data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
  454. if (!data) {
  455. retval = -ENOMEM;
  456. goto out;
  457. }
  458. kref_init(&data->kref);
  459. data->dev = hdev;
  460. list_add_tail(&data->list, &wacom_udev_list);
  461. }
  462. wacom_wac->shared = &data->shared;
  463. if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
  464. wacom_wac->shared->touch = hdev;
  465. else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
  466. wacom_wac->shared->pen = hdev;
  467. out:
  468. mutex_unlock(&wacom_udev_list_lock);
  469. return retval;
  470. }
  471. static void wacom_release_shared_data(struct kref *kref)
  472. {
  473. struct wacom_hdev_data *data =
  474. container_of(kref, struct wacom_hdev_data, kref);
  475. mutex_lock(&wacom_udev_list_lock);
  476. list_del(&data->list);
  477. mutex_unlock(&wacom_udev_list_lock);
  478. kfree(data);
  479. }
  480. static void wacom_remove_shared_data(struct wacom *wacom)
  481. {
  482. struct wacom_hdev_data *data;
  483. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  484. if (wacom_wac->shared) {
  485. data = container_of(wacom_wac->shared, struct wacom_hdev_data,
  486. shared);
  487. if (wacom_wac->shared->touch == wacom->hdev)
  488. wacom_wac->shared->touch = NULL;
  489. else if (wacom_wac->shared->pen == wacom->hdev)
  490. wacom_wac->shared->pen = NULL;
  491. kref_put(&data->kref, wacom_release_shared_data);
  492. wacom_wac->shared = NULL;
  493. }
  494. }
  495. static int wacom_led_control(struct wacom *wacom)
  496. {
  497. unsigned char *buf;
  498. int retval;
  499. unsigned char report_id = WAC_CMD_LED_CONTROL;
  500. int buf_size = 9;
  501. if (wacom->wacom_wac.pid) { /* wireless connected */
  502. report_id = WAC_CMD_WL_LED_CONTROL;
  503. buf_size = 13;
  504. }
  505. buf = kzalloc(buf_size, GFP_KERNEL);
  506. if (!buf)
  507. return -ENOMEM;
  508. if (wacom->wacom_wac.features.type >= INTUOS5S &&
  509. wacom->wacom_wac.features.type <= INTUOSPL) {
  510. /*
  511. * Touch Ring and crop mark LED luminance may take on
  512. * one of four values:
  513. * 0 = Low; 1 = Medium; 2 = High; 3 = Off
  514. */
  515. int ring_led = wacom->led.select[0] & 0x03;
  516. int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
  517. int crop_lum = 0;
  518. unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
  519. buf[0] = report_id;
  520. if (wacom->wacom_wac.pid) {
  521. wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
  522. buf, buf_size, WAC_CMD_RETRIES);
  523. buf[0] = report_id;
  524. buf[4] = led_bits;
  525. } else
  526. buf[1] = led_bits;
  527. }
  528. else {
  529. int led = wacom->led.select[0] | 0x4;
  530. if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
  531. wacom->wacom_wac.features.type == WACOM_24HD)
  532. led |= (wacom->led.select[1] << 4) | 0x40;
  533. buf[0] = report_id;
  534. buf[1] = led;
  535. buf[2] = wacom->led.llv;
  536. buf[3] = wacom->led.hlv;
  537. buf[4] = wacom->led.img_lum;
  538. }
  539. retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
  540. WAC_CMD_RETRIES);
  541. kfree(buf);
  542. return retval;
  543. }
  544. static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
  545. const unsigned len, const void *img)
  546. {
  547. unsigned char *buf;
  548. int i, retval;
  549. const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
  550. buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
  551. if (!buf)
  552. return -ENOMEM;
  553. /* Send 'start' command */
  554. buf[0] = WAC_CMD_ICON_START;
  555. buf[1] = 1;
  556. retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
  557. WAC_CMD_RETRIES);
  558. if (retval < 0)
  559. goto out;
  560. buf[0] = xfer_id;
  561. buf[1] = button_id & 0x07;
  562. for (i = 0; i < 4; i++) {
  563. buf[2] = i;
  564. memcpy(buf + 3, img + i * chunk_len, chunk_len);
  565. retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
  566. buf, chunk_len + 3, WAC_CMD_RETRIES);
  567. if (retval < 0)
  568. break;
  569. }
  570. /* Send 'stop' */
  571. buf[0] = WAC_CMD_ICON_START;
  572. buf[1] = 0;
  573. wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
  574. WAC_CMD_RETRIES);
  575. out:
  576. kfree(buf);
  577. return retval;
  578. }
  579. static ssize_t wacom_led_select_store(struct device *dev, int set_id,
  580. const char *buf, size_t count)
  581. {
  582. struct hid_device *hdev = to_hid_device(dev);
  583. struct wacom *wacom = hid_get_drvdata(hdev);
  584. unsigned int id;
  585. int err;
  586. err = kstrtouint(buf, 10, &id);
  587. if (err)
  588. return err;
  589. mutex_lock(&wacom->lock);
  590. wacom->led.select[set_id] = id & 0x3;
  591. err = wacom_led_control(wacom);
  592. mutex_unlock(&wacom->lock);
  593. return err < 0 ? err : count;
  594. }
  595. #define DEVICE_LED_SELECT_ATTR(SET_ID) \
  596. static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
  597. struct device_attribute *attr, const char *buf, size_t count) \
  598. { \
  599. return wacom_led_select_store(dev, SET_ID, buf, count); \
  600. } \
  601. static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
  602. struct device_attribute *attr, char *buf) \
  603. { \
  604. struct hid_device *hdev = to_hid_device(dev);\
  605. struct wacom *wacom = hid_get_drvdata(hdev); \
  606. return scnprintf(buf, PAGE_SIZE, "%d\n", \
  607. wacom->led.select[SET_ID]); \
  608. } \
  609. static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
  610. wacom_led##SET_ID##_select_show, \
  611. wacom_led##SET_ID##_select_store)
  612. DEVICE_LED_SELECT_ATTR(0);
  613. DEVICE_LED_SELECT_ATTR(1);
  614. static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
  615. const char *buf, size_t count)
  616. {
  617. unsigned int value;
  618. int err;
  619. err = kstrtouint(buf, 10, &value);
  620. if (err)
  621. return err;
  622. mutex_lock(&wacom->lock);
  623. *dest = value & 0x7f;
  624. err = wacom_led_control(wacom);
  625. mutex_unlock(&wacom->lock);
  626. return err < 0 ? err : count;
  627. }
  628. #define DEVICE_LUMINANCE_ATTR(name, field) \
  629. static ssize_t wacom_##name##_luminance_store(struct device *dev, \
  630. struct device_attribute *attr, const char *buf, size_t count) \
  631. { \
  632. struct hid_device *hdev = to_hid_device(dev);\
  633. struct wacom *wacom = hid_get_drvdata(hdev); \
  634. \
  635. return wacom_luminance_store(wacom, &wacom->led.field, \
  636. buf, count); \
  637. } \
  638. static ssize_t wacom_##name##_luminance_show(struct device *dev, \
  639. struct device_attribute *attr, char *buf) \
  640. { \
  641. struct wacom *wacom = dev_get_drvdata(dev); \
  642. return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
  643. } \
  644. static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
  645. wacom_##name##_luminance_show, \
  646. wacom_##name##_luminance_store)
  647. DEVICE_LUMINANCE_ATTR(status0, llv);
  648. DEVICE_LUMINANCE_ATTR(status1, hlv);
  649. DEVICE_LUMINANCE_ATTR(buttons, img_lum);
  650. static ssize_t wacom_button_image_store(struct device *dev, int button_id,
  651. const char *buf, size_t count)
  652. {
  653. struct hid_device *hdev = to_hid_device(dev);
  654. struct wacom *wacom = hid_get_drvdata(hdev);
  655. int err;
  656. unsigned len;
  657. u8 xfer_id;
  658. if (hdev->bus == BUS_BLUETOOTH) {
  659. len = 256;
  660. xfer_id = WAC_CMD_ICON_BT_XFER;
  661. } else {
  662. len = 1024;
  663. xfer_id = WAC_CMD_ICON_XFER;
  664. }
  665. if (count != len)
  666. return -EINVAL;
  667. mutex_lock(&wacom->lock);
  668. err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
  669. mutex_unlock(&wacom->lock);
  670. return err < 0 ? err : count;
  671. }
  672. #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
  673. static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
  674. struct device_attribute *attr, const char *buf, size_t count) \
  675. { \
  676. return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
  677. } \
  678. static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
  679. NULL, wacom_btnimg##BUTTON_ID##_store)
  680. DEVICE_BTNIMG_ATTR(0);
  681. DEVICE_BTNIMG_ATTR(1);
  682. DEVICE_BTNIMG_ATTR(2);
  683. DEVICE_BTNIMG_ATTR(3);
  684. DEVICE_BTNIMG_ATTR(4);
  685. DEVICE_BTNIMG_ATTR(5);
  686. DEVICE_BTNIMG_ATTR(6);
  687. DEVICE_BTNIMG_ATTR(7);
  688. static struct attribute *cintiq_led_attrs[] = {
  689. &dev_attr_status_led0_select.attr,
  690. &dev_attr_status_led1_select.attr,
  691. NULL
  692. };
  693. static struct attribute_group cintiq_led_attr_group = {
  694. .name = "wacom_led",
  695. .attrs = cintiq_led_attrs,
  696. };
  697. static struct attribute *intuos4_led_attrs[] = {
  698. &dev_attr_status0_luminance.attr,
  699. &dev_attr_status1_luminance.attr,
  700. &dev_attr_status_led0_select.attr,
  701. &dev_attr_buttons_luminance.attr,
  702. &dev_attr_button0_rawimg.attr,
  703. &dev_attr_button1_rawimg.attr,
  704. &dev_attr_button2_rawimg.attr,
  705. &dev_attr_button3_rawimg.attr,
  706. &dev_attr_button4_rawimg.attr,
  707. &dev_attr_button5_rawimg.attr,
  708. &dev_attr_button6_rawimg.attr,
  709. &dev_attr_button7_rawimg.attr,
  710. NULL
  711. };
  712. static struct attribute_group intuos4_led_attr_group = {
  713. .name = "wacom_led",
  714. .attrs = intuos4_led_attrs,
  715. };
  716. static struct attribute *intuos5_led_attrs[] = {
  717. &dev_attr_status0_luminance.attr,
  718. &dev_attr_status_led0_select.attr,
  719. NULL
  720. };
  721. static struct attribute_group intuos5_led_attr_group = {
  722. .name = "wacom_led",
  723. .attrs = intuos5_led_attrs,
  724. };
  725. static int wacom_initialize_leds(struct wacom *wacom)
  726. {
  727. int error;
  728. if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
  729. return 0;
  730. /* Initialize default values */
  731. switch (wacom->wacom_wac.features.type) {
  732. case INTUOS4S:
  733. case INTUOS4:
  734. case INTUOS4WL:
  735. case INTUOS4L:
  736. wacom->led.select[0] = 0;
  737. wacom->led.select[1] = 0;
  738. wacom->led.llv = 10;
  739. wacom->led.hlv = 20;
  740. wacom->led.img_lum = 10;
  741. error = sysfs_create_group(&wacom->hdev->dev.kobj,
  742. &intuos4_led_attr_group);
  743. break;
  744. case WACOM_24HD:
  745. case WACOM_21UX2:
  746. wacom->led.select[0] = 0;
  747. wacom->led.select[1] = 0;
  748. wacom->led.llv = 0;
  749. wacom->led.hlv = 0;
  750. wacom->led.img_lum = 0;
  751. error = sysfs_create_group(&wacom->hdev->dev.kobj,
  752. &cintiq_led_attr_group);
  753. break;
  754. case INTUOS5S:
  755. case INTUOS5:
  756. case INTUOS5L:
  757. case INTUOSPS:
  758. case INTUOSPM:
  759. case INTUOSPL:
  760. wacom->led.select[0] = 0;
  761. wacom->led.select[1] = 0;
  762. wacom->led.llv = 32;
  763. wacom->led.hlv = 0;
  764. wacom->led.img_lum = 0;
  765. error = sysfs_create_group(&wacom->hdev->dev.kobj,
  766. &intuos5_led_attr_group);
  767. break;
  768. default:
  769. return 0;
  770. }
  771. if (error) {
  772. hid_err(wacom->hdev,
  773. "cannot create sysfs group err: %d\n", error);
  774. return error;
  775. }
  776. wacom_led_control(wacom);
  777. wacom->led_initialized = true;
  778. return 0;
  779. }
  780. static void wacom_destroy_leds(struct wacom *wacom)
  781. {
  782. if (!wacom->led_initialized)
  783. return;
  784. if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
  785. return;
  786. wacom->led_initialized = false;
  787. switch (wacom->wacom_wac.features.type) {
  788. case INTUOS4S:
  789. case INTUOS4:
  790. case INTUOS4WL:
  791. case INTUOS4L:
  792. sysfs_remove_group(&wacom->hdev->dev.kobj,
  793. &intuos4_led_attr_group);
  794. break;
  795. case WACOM_24HD:
  796. case WACOM_21UX2:
  797. sysfs_remove_group(&wacom->hdev->dev.kobj,
  798. &cintiq_led_attr_group);
  799. break;
  800. case INTUOS5S:
  801. case INTUOS5:
  802. case INTUOS5L:
  803. case INTUOSPS:
  804. case INTUOSPM:
  805. case INTUOSPL:
  806. sysfs_remove_group(&wacom->hdev->dev.kobj,
  807. &intuos5_led_attr_group);
  808. break;
  809. }
  810. }
  811. static enum power_supply_property wacom_battery_props[] = {
  812. POWER_SUPPLY_PROP_PRESENT,
  813. POWER_SUPPLY_PROP_STATUS,
  814. POWER_SUPPLY_PROP_SCOPE,
  815. POWER_SUPPLY_PROP_CAPACITY
  816. };
  817. static enum power_supply_property wacom_ac_props[] = {
  818. POWER_SUPPLY_PROP_PRESENT,
  819. POWER_SUPPLY_PROP_ONLINE,
  820. POWER_SUPPLY_PROP_SCOPE,
  821. };
  822. static int wacom_battery_get_property(struct power_supply *psy,
  823. enum power_supply_property psp,
  824. union power_supply_propval *val)
  825. {
  826. struct wacom *wacom = power_supply_get_drvdata(psy);
  827. int ret = 0;
  828. switch (psp) {
  829. case POWER_SUPPLY_PROP_PRESENT:
  830. val->intval = wacom->wacom_wac.bat_connected;
  831. break;
  832. case POWER_SUPPLY_PROP_SCOPE:
  833. val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  834. break;
  835. case POWER_SUPPLY_PROP_CAPACITY:
  836. val->intval =
  837. wacom->wacom_wac.battery_capacity;
  838. break;
  839. case POWER_SUPPLY_PROP_STATUS:
  840. if (wacom->wacom_wac.bat_charging)
  841. val->intval = POWER_SUPPLY_STATUS_CHARGING;
  842. else if (wacom->wacom_wac.battery_capacity == 100 &&
  843. wacom->wacom_wac.ps_connected)
  844. val->intval = POWER_SUPPLY_STATUS_FULL;
  845. else if (wacom->wacom_wac.ps_connected)
  846. val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
  847. else
  848. val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
  849. break;
  850. default:
  851. ret = -EINVAL;
  852. break;
  853. }
  854. return ret;
  855. }
  856. static int wacom_ac_get_property(struct power_supply *psy,
  857. enum power_supply_property psp,
  858. union power_supply_propval *val)
  859. {
  860. struct wacom *wacom = power_supply_get_drvdata(psy);
  861. int ret = 0;
  862. switch (psp) {
  863. case POWER_SUPPLY_PROP_PRESENT:
  864. /* fall through */
  865. case POWER_SUPPLY_PROP_ONLINE:
  866. val->intval = wacom->wacom_wac.ps_connected;
  867. break;
  868. case POWER_SUPPLY_PROP_SCOPE:
  869. val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  870. break;
  871. default:
  872. ret = -EINVAL;
  873. break;
  874. }
  875. return ret;
  876. }
  877. static int wacom_initialize_battery(struct wacom *wacom)
  878. {
  879. static atomic_t battery_no = ATOMIC_INIT(0);
  880. struct power_supply_config psy_cfg = { .drv_data = wacom, };
  881. unsigned long n;
  882. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
  883. struct power_supply_desc *bat_desc = &wacom->battery_desc;
  884. struct power_supply_desc *ac_desc = &wacom->ac_desc;
  885. n = atomic_inc_return(&battery_no) - 1;
  886. bat_desc->properties = wacom_battery_props;
  887. bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
  888. bat_desc->get_property = wacom_battery_get_property;
  889. sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
  890. bat_desc->name = wacom->wacom_wac.bat_name;
  891. bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
  892. bat_desc->use_for_apm = 0;
  893. ac_desc->properties = wacom_ac_props;
  894. ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props);
  895. ac_desc->get_property = wacom_ac_get_property;
  896. sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
  897. ac_desc->name = wacom->wacom_wac.ac_name;
  898. ac_desc->type = POWER_SUPPLY_TYPE_MAINS;
  899. ac_desc->use_for_apm = 0;
  900. wacom->battery = power_supply_register(&wacom->hdev->dev,
  901. &wacom->battery_desc, &psy_cfg);
  902. if (IS_ERR(wacom->battery))
  903. return PTR_ERR(wacom->battery);
  904. power_supply_powers(wacom->battery, &wacom->hdev->dev);
  905. wacom->ac = power_supply_register(&wacom->hdev->dev,
  906. &wacom->ac_desc,
  907. &psy_cfg);
  908. if (IS_ERR(wacom->ac)) {
  909. power_supply_unregister(wacom->battery);
  910. return PTR_ERR(wacom->ac);
  911. }
  912. power_supply_powers(wacom->ac, &wacom->hdev->dev);
  913. }
  914. return 0;
  915. }
  916. static void wacom_destroy_battery(struct wacom *wacom)
  917. {
  918. if (wacom->battery) {
  919. power_supply_unregister(wacom->battery);
  920. wacom->battery = NULL;
  921. power_supply_unregister(wacom->ac);
  922. wacom->ac = NULL;
  923. }
  924. }
  925. static ssize_t wacom_show_speed(struct device *dev,
  926. struct device_attribute
  927. *attr, char *buf)
  928. {
  929. struct hid_device *hdev = to_hid_device(dev);
  930. struct wacom *wacom = hid_get_drvdata(hdev);
  931. return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
  932. }
  933. static ssize_t wacom_store_speed(struct device *dev,
  934. struct device_attribute *attr,
  935. const char *buf, size_t count)
  936. {
  937. struct hid_device *hdev = to_hid_device(dev);
  938. struct wacom *wacom = hid_get_drvdata(hdev);
  939. u8 new_speed;
  940. if (kstrtou8(buf, 0, &new_speed))
  941. return -EINVAL;
  942. if (new_speed != 0 && new_speed != 1)
  943. return -EINVAL;
  944. wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
  945. return count;
  946. }
  947. static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
  948. wacom_show_speed, wacom_store_speed);
  949. static ssize_t wacom_show_remote_mode(struct kobject *kobj,
  950. struct kobj_attribute *kattr,
  951. char *buf, int index)
  952. {
  953. struct device *dev = kobj_to_dev(kobj->parent);
  954. struct hid_device *hdev = to_hid_device(dev);
  955. struct wacom *wacom = hid_get_drvdata(hdev);
  956. u8 mode;
  957. mode = wacom->led.select[index];
  958. if (mode >= 0 && mode < 3)
  959. return snprintf(buf, PAGE_SIZE, "%d\n", mode);
  960. else
  961. return snprintf(buf, PAGE_SIZE, "%d\n", -1);
  962. }
  963. #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
  964. static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
  965. struct kobj_attribute *kattr, char *buf) \
  966. { \
  967. return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
  968. } \
  969. static struct kobj_attribute remote##SET_ID##_mode_attr = { \
  970. .attr = {.name = "remote_mode", \
  971. .mode = DEV_ATTR_RO_PERM}, \
  972. .show = wacom_show_remote##SET_ID##_mode, \
  973. }; \
  974. static struct attribute *remote##SET_ID##_serial_attrs[] = { \
  975. &remote##SET_ID##_mode_attr.attr, \
  976. NULL \
  977. }; \
  978. static struct attribute_group remote##SET_ID##_serial_group = { \
  979. .name = NULL, \
  980. .attrs = remote##SET_ID##_serial_attrs, \
  981. }
  982. DEVICE_EKR_ATTR_GROUP(0);
  983. DEVICE_EKR_ATTR_GROUP(1);
  984. DEVICE_EKR_ATTR_GROUP(2);
  985. DEVICE_EKR_ATTR_GROUP(3);
  986. DEVICE_EKR_ATTR_GROUP(4);
  987. int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int index)
  988. {
  989. int error = 0;
  990. char *buf;
  991. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  992. wacom_wac->serial[index] = serial;
  993. buf = kzalloc(WAC_REMOTE_SERIAL_MAX_STRLEN, GFP_KERNEL);
  994. if (!buf)
  995. return -ENOMEM;
  996. snprintf(buf, WAC_REMOTE_SERIAL_MAX_STRLEN, "%d", serial);
  997. wacom->remote_group[index].name = buf;
  998. error = sysfs_create_group(wacom->remote_dir,
  999. &wacom->remote_group[index]);
  1000. if (error) {
  1001. hid_err(wacom->hdev,
  1002. "cannot create sysfs group err: %d\n", error);
  1003. kobject_put(wacom->remote_dir);
  1004. return error;
  1005. }
  1006. return 0;
  1007. }
  1008. void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial)
  1009. {
  1010. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1011. int i;
  1012. if (!serial)
  1013. return;
  1014. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  1015. if (wacom_wac->serial[i] == serial) {
  1016. wacom_wac->serial[i] = 0;
  1017. wacom->led.select[i] = WACOM_STATUS_UNKNOWN;
  1018. if (wacom->remote_group[i].name) {
  1019. sysfs_remove_group(wacom->remote_dir,
  1020. &wacom->remote_group[i]);
  1021. kfree(wacom->remote_group[i].name);
  1022. wacom->remote_group[i].name = NULL;
  1023. }
  1024. }
  1025. }
  1026. }
  1027. static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
  1028. {
  1029. const size_t buf_size = 2;
  1030. unsigned char *buf;
  1031. int retval;
  1032. buf = kzalloc(buf_size, GFP_KERNEL);
  1033. if (!buf)
  1034. return -ENOMEM;
  1035. buf[0] = WAC_CMD_DELETE_PAIRING;
  1036. buf[1] = selector;
  1037. retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf,
  1038. buf_size, WAC_CMD_RETRIES);
  1039. kfree(buf);
  1040. return retval;
  1041. }
  1042. static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
  1043. struct kobj_attribute *attr,
  1044. const char *buf, size_t count)
  1045. {
  1046. unsigned char selector = 0;
  1047. struct device *dev = kobj_to_dev(kobj->parent);
  1048. struct hid_device *hdev = to_hid_device(dev);
  1049. struct wacom *wacom = hid_get_drvdata(hdev);
  1050. int err;
  1051. if (!strncmp(buf, "*\n", 2)) {
  1052. selector = WAC_CMD_UNPAIR_ALL;
  1053. } else {
  1054. hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n",
  1055. buf);
  1056. return -1;
  1057. }
  1058. mutex_lock(&wacom->lock);
  1059. err = wacom_cmd_unpair_remote(wacom, selector);
  1060. mutex_unlock(&wacom->lock);
  1061. return err < 0 ? err : count;
  1062. }
  1063. static struct kobj_attribute unpair_remote_attr = {
  1064. .attr = {.name = "unpair_remote", .mode = 0200},
  1065. .store = wacom_store_unpair_remote,
  1066. };
  1067. static const struct attribute *remote_unpair_attrs[] = {
  1068. &unpair_remote_attr.attr,
  1069. NULL
  1070. };
  1071. static int wacom_initialize_remote(struct wacom *wacom)
  1072. {
  1073. int error = 0;
  1074. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1075. int i;
  1076. if (wacom->wacom_wac.features.type != REMOTE)
  1077. return 0;
  1078. wacom->remote_group[0] = remote0_serial_group;
  1079. wacom->remote_group[1] = remote1_serial_group;
  1080. wacom->remote_group[2] = remote2_serial_group;
  1081. wacom->remote_group[3] = remote3_serial_group;
  1082. wacom->remote_group[4] = remote4_serial_group;
  1083. wacom->remote_dir = kobject_create_and_add("wacom_remote",
  1084. &wacom->hdev->dev.kobj);
  1085. if (!wacom->remote_dir)
  1086. return -ENOMEM;
  1087. error = sysfs_create_files(wacom->remote_dir, remote_unpair_attrs);
  1088. if (error) {
  1089. hid_err(wacom->hdev,
  1090. "cannot create sysfs group err: %d\n", error);
  1091. return error;
  1092. }
  1093. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  1094. wacom->led.select[i] = WACOM_STATUS_UNKNOWN;
  1095. wacom_wac->serial[i] = 0;
  1096. }
  1097. return 0;
  1098. }
  1099. static struct input_dev *wacom_allocate_input(struct wacom *wacom)
  1100. {
  1101. struct input_dev *input_dev;
  1102. struct hid_device *hdev = wacom->hdev;
  1103. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1104. input_dev = input_allocate_device();
  1105. if (!input_dev)
  1106. return NULL;
  1107. input_dev->name = wacom_wac->features.name;
  1108. input_dev->phys = hdev->phys;
  1109. input_dev->dev.parent = &hdev->dev;
  1110. input_dev->open = wacom_open;
  1111. input_dev->close = wacom_close;
  1112. input_dev->uniq = hdev->uniq;
  1113. input_dev->id.bustype = hdev->bus;
  1114. input_dev->id.vendor = hdev->vendor;
  1115. input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
  1116. input_dev->id.version = hdev->version;
  1117. input_set_drvdata(input_dev, wacom);
  1118. return input_dev;
  1119. }
  1120. static void wacom_clean_inputs(struct wacom *wacom)
  1121. {
  1122. if (wacom->wacom_wac.pen_input) {
  1123. if (wacom->wacom_wac.pen_registered)
  1124. input_unregister_device(wacom->wacom_wac.pen_input);
  1125. else
  1126. input_free_device(wacom->wacom_wac.pen_input);
  1127. }
  1128. if (wacom->wacom_wac.touch_input) {
  1129. if (wacom->wacom_wac.touch_registered)
  1130. input_unregister_device(wacom->wacom_wac.touch_input);
  1131. else
  1132. input_free_device(wacom->wacom_wac.touch_input);
  1133. }
  1134. if (wacom->wacom_wac.pad_input) {
  1135. if (wacom->wacom_wac.pad_registered)
  1136. input_unregister_device(wacom->wacom_wac.pad_input);
  1137. else
  1138. input_free_device(wacom->wacom_wac.pad_input);
  1139. }
  1140. kobject_put(wacom->remote_dir);
  1141. wacom->wacom_wac.pen_input = NULL;
  1142. wacom->wacom_wac.touch_input = NULL;
  1143. wacom->wacom_wac.pad_input = NULL;
  1144. wacom->wacom_wac.pen_registered = false;
  1145. wacom->wacom_wac.touch_registered = false;
  1146. wacom->wacom_wac.pad_registered = false;
  1147. wacom_destroy_leds(wacom);
  1148. }
  1149. static int wacom_allocate_inputs(struct wacom *wacom)
  1150. {
  1151. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1152. wacom_wac->pen_input = wacom_allocate_input(wacom);
  1153. wacom_wac->touch_input = wacom_allocate_input(wacom);
  1154. wacom_wac->pad_input = wacom_allocate_input(wacom);
  1155. if (!wacom_wac->pen_input || !wacom_wac->touch_input || !wacom_wac->pad_input) {
  1156. wacom_clean_inputs(wacom);
  1157. return -ENOMEM;
  1158. }
  1159. wacom_wac->pen_input->name = wacom_wac->pen_name;
  1160. wacom_wac->touch_input->name = wacom_wac->touch_name;
  1161. wacom_wac->pad_input->name = wacom_wac->pad_name;
  1162. return 0;
  1163. }
  1164. static int wacom_register_inputs(struct wacom *wacom)
  1165. {
  1166. struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
  1167. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1168. int error = 0;
  1169. pen_input_dev = wacom_wac->pen_input;
  1170. touch_input_dev = wacom_wac->touch_input;
  1171. pad_input_dev = wacom_wac->pad_input;
  1172. if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
  1173. return -EINVAL;
  1174. error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
  1175. if (error) {
  1176. /* no pen in use on this interface */
  1177. input_free_device(pen_input_dev);
  1178. wacom_wac->pen_input = NULL;
  1179. pen_input_dev = NULL;
  1180. } else {
  1181. error = input_register_device(pen_input_dev);
  1182. if (error)
  1183. goto fail_register_pen_input;
  1184. wacom_wac->pen_registered = true;
  1185. }
  1186. error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
  1187. if (error) {
  1188. /* no touch in use on this interface */
  1189. input_free_device(touch_input_dev);
  1190. wacom_wac->touch_input = NULL;
  1191. touch_input_dev = NULL;
  1192. } else {
  1193. error = input_register_device(touch_input_dev);
  1194. if (error)
  1195. goto fail_register_touch_input;
  1196. wacom_wac->touch_registered = true;
  1197. }
  1198. error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
  1199. if (error) {
  1200. /* no pad in use on this interface */
  1201. input_free_device(pad_input_dev);
  1202. wacom_wac->pad_input = NULL;
  1203. pad_input_dev = NULL;
  1204. } else {
  1205. error = input_register_device(pad_input_dev);
  1206. if (error)
  1207. goto fail_register_pad_input;
  1208. wacom_wac->pad_registered = true;
  1209. error = wacom_initialize_leds(wacom);
  1210. if (error)
  1211. goto fail_leds;
  1212. error = wacom_initialize_remote(wacom);
  1213. if (error)
  1214. goto fail_remote;
  1215. }
  1216. return 0;
  1217. fail_remote:
  1218. wacom_destroy_leds(wacom);
  1219. fail_leds:
  1220. input_unregister_device(pad_input_dev);
  1221. pad_input_dev = NULL;
  1222. wacom_wac->pad_registered = false;
  1223. fail_register_pad_input:
  1224. if (touch_input_dev)
  1225. input_unregister_device(touch_input_dev);
  1226. wacom_wac->touch_input = NULL;
  1227. wacom_wac->touch_registered = false;
  1228. fail_register_touch_input:
  1229. if (pen_input_dev)
  1230. input_unregister_device(pen_input_dev);
  1231. wacom_wac->pen_input = NULL;
  1232. wacom_wac->pen_registered = false;
  1233. fail_register_pen_input:
  1234. return error;
  1235. }
  1236. /*
  1237. * Not all devices report physical dimensions from HID.
  1238. * Compute the default from hardcoded logical dimension
  1239. * and resolution before driver overwrites them.
  1240. */
  1241. static void wacom_set_default_phy(struct wacom_features *features)
  1242. {
  1243. if (features->x_resolution) {
  1244. features->x_phy = (features->x_max * 100) /
  1245. features->x_resolution;
  1246. features->y_phy = (features->y_max * 100) /
  1247. features->y_resolution;
  1248. }
  1249. }
  1250. static void wacom_calculate_res(struct wacom_features *features)
  1251. {
  1252. /* set unit to "100th of a mm" for devices not reported by HID */
  1253. if (!features->unit) {
  1254. features->unit = 0x11;
  1255. features->unitExpo = -3;
  1256. }
  1257. features->x_resolution = wacom_calc_hid_res(features->x_max,
  1258. features->x_phy,
  1259. features->unit,
  1260. features->unitExpo);
  1261. features->y_resolution = wacom_calc_hid_res(features->y_max,
  1262. features->y_phy,
  1263. features->unit,
  1264. features->unitExpo);
  1265. }
  1266. void wacom_battery_work(struct work_struct *work)
  1267. {
  1268. struct wacom *wacom = container_of(work, struct wacom, work);
  1269. if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
  1270. !wacom->battery) {
  1271. wacom_initialize_battery(wacom);
  1272. }
  1273. else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
  1274. wacom->battery) {
  1275. wacom_destroy_battery(wacom);
  1276. }
  1277. }
  1278. static size_t wacom_compute_pktlen(struct hid_device *hdev)
  1279. {
  1280. struct hid_report_enum *report_enum;
  1281. struct hid_report *report;
  1282. size_t size = 0;
  1283. report_enum = hdev->report_enum + HID_INPUT_REPORT;
  1284. list_for_each_entry(report, &report_enum->report_list, list) {
  1285. size_t report_size = hid_report_len(report);
  1286. if (report_size > size)
  1287. size = report_size;
  1288. }
  1289. return size;
  1290. }
  1291. static void wacom_update_name(struct wacom *wacom, const char *suffix)
  1292. {
  1293. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1294. struct wacom_features *features = &wacom_wac->features;
  1295. char name[WACOM_NAME_MAX];
  1296. /* Generic devices name unspecified */
  1297. if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
  1298. if (strstr(wacom->hdev->name, "Wacom") ||
  1299. strstr(wacom->hdev->name, "wacom") ||
  1300. strstr(wacom->hdev->name, "WACOM")) {
  1301. /* name is in HID descriptor, use it */
  1302. strlcpy(name, wacom->hdev->name, sizeof(name));
  1303. /* strip out excess whitespaces */
  1304. while (1) {
  1305. char *gap = strstr(name, " ");
  1306. if (gap == NULL)
  1307. break;
  1308. /* shift everything including the terminator */
  1309. memmove(gap, gap+1, strlen(gap));
  1310. }
  1311. /* get rid of trailing whitespace */
  1312. if (name[strlen(name)-1] == ' ')
  1313. name[strlen(name)-1] = '\0';
  1314. } else {
  1315. /* no meaningful name retrieved. use product ID */
  1316. snprintf(name, sizeof(name),
  1317. "%s %X", features->name, wacom->hdev->product);
  1318. }
  1319. } else {
  1320. strlcpy(name, features->name, sizeof(name));
  1321. }
  1322. /* Append the device type to the name */
  1323. snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
  1324. "%s%s Pen", name, suffix);
  1325. snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
  1326. "%s%s Finger", name, suffix);
  1327. snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
  1328. "%s%s Pad", name, suffix);
  1329. }
  1330. static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
  1331. {
  1332. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1333. struct wacom_features *features = &wacom_wac->features;
  1334. struct hid_device *hdev = wacom->hdev;
  1335. int error;
  1336. unsigned int connect_mask = HID_CONNECT_HIDRAW;
  1337. features->pktlen = wacom_compute_pktlen(hdev);
  1338. if (features->pktlen > WACOM_PKGLEN_MAX)
  1339. return -EINVAL;
  1340. error = wacom_allocate_inputs(wacom);
  1341. if (error)
  1342. return error;
  1343. /*
  1344. * Bamboo Pad has a generic hid handling for the Pen, and we switch it
  1345. * into debug mode for the touch part.
  1346. * We ignore the other interfaces.
  1347. */
  1348. if (features->type == BAMBOO_PAD) {
  1349. if (features->pktlen == WACOM_PKGLEN_PENABLED) {
  1350. features->type = HID_GENERIC;
  1351. } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
  1352. (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
  1353. error = -ENODEV;
  1354. goto fail_allocate_inputs;
  1355. }
  1356. }
  1357. /* set the default size in case we do not get them from hid */
  1358. wacom_set_default_phy(features);
  1359. /* Retrieve the physical and logical size for touch devices */
  1360. wacom_retrieve_hid_descriptor(hdev, features);
  1361. wacom_setup_device_quirks(wacom);
  1362. if (features->device_type == WACOM_DEVICETYPE_NONE &&
  1363. features->type != WIRELESS) {
  1364. error = features->type == HID_GENERIC ? -ENODEV : 0;
  1365. dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
  1366. hdev->name,
  1367. error ? "Ignoring" : "Assuming pen");
  1368. if (error)
  1369. goto fail_parsed;
  1370. features->device_type |= WACOM_DEVICETYPE_PEN;
  1371. }
  1372. wacom_calculate_res(features);
  1373. wacom_update_name(wacom, wireless ? " (WL)" : "");
  1374. error = wacom_add_shared_data(hdev);
  1375. if (error)
  1376. goto fail_shared_data;
  1377. if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
  1378. (features->quirks & WACOM_QUIRK_BATTERY)) {
  1379. error = wacom_initialize_battery(wacom);
  1380. if (error)
  1381. goto fail_battery;
  1382. }
  1383. error = wacom_register_inputs(wacom);
  1384. if (error)
  1385. goto fail_register_inputs;
  1386. if (features->type == HID_GENERIC)
  1387. connect_mask |= HID_CONNECT_DRIVER;
  1388. /* Regular HID work starts now */
  1389. error = hid_hw_start(hdev, connect_mask);
  1390. if (error) {
  1391. hid_err(hdev, "hw start failed\n");
  1392. goto fail_hw_start;
  1393. }
  1394. if (!wireless) {
  1395. /* Note that if query fails it is not a hard failure */
  1396. wacom_query_tablet_data(hdev, features);
  1397. }
  1398. /* touch only Bamboo doesn't support pen */
  1399. if ((features->type == BAMBOO_TOUCH) &&
  1400. (features->device_type & WACOM_DEVICETYPE_PEN)) {
  1401. error = -ENODEV;
  1402. goto fail_hw_start;
  1403. }
  1404. /* pen only Bamboo neither support touch nor pad */
  1405. if ((features->type == BAMBOO_PEN) &&
  1406. ((features->device_type & WACOM_DEVICETYPE_TOUCH) ||
  1407. (features->device_type & WACOM_DEVICETYPE_PAD))) {
  1408. error = -ENODEV;
  1409. goto fail_hw_start;
  1410. }
  1411. if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
  1412. error = hid_hw_open(hdev);
  1413. if ((wacom_wac->features.type == INTUOSHT ||
  1414. wacom_wac->features.type == INTUOSHT2) &&
  1415. (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)) {
  1416. wacom_wac->shared->touch_input = wacom_wac->touch_input;
  1417. }
  1418. return 0;
  1419. fail_hw_start:
  1420. hid_hw_stop(hdev);
  1421. fail_register_inputs:
  1422. wacom_clean_inputs(wacom);
  1423. wacom_destroy_battery(wacom);
  1424. fail_battery:
  1425. wacom_remove_shared_data(wacom);
  1426. fail_shared_data:
  1427. fail_parsed:
  1428. fail_allocate_inputs:
  1429. wacom_clean_inputs(wacom);
  1430. return error;
  1431. }
  1432. static void wacom_wireless_work(struct work_struct *work)
  1433. {
  1434. struct wacom *wacom = container_of(work, struct wacom, work);
  1435. struct usb_device *usbdev = wacom->usbdev;
  1436. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1437. struct hid_device *hdev1, *hdev2;
  1438. struct wacom *wacom1, *wacom2;
  1439. struct wacom_wac *wacom_wac1, *wacom_wac2;
  1440. int error;
  1441. /*
  1442. * Regardless if this is a disconnect or a new tablet,
  1443. * remove any existing input and battery devices.
  1444. */
  1445. wacom_destroy_battery(wacom);
  1446. /* Stylus interface */
  1447. hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
  1448. wacom1 = hid_get_drvdata(hdev1);
  1449. wacom_wac1 = &(wacom1->wacom_wac);
  1450. wacom_clean_inputs(wacom1);
  1451. /* Touch interface */
  1452. hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
  1453. wacom2 = hid_get_drvdata(hdev2);
  1454. wacom_wac2 = &(wacom2->wacom_wac);
  1455. wacom_clean_inputs(wacom2);
  1456. if (wacom_wac->pid == 0) {
  1457. hid_info(wacom->hdev, "wireless tablet disconnected\n");
  1458. wacom_wac1->shared->type = 0;
  1459. } else {
  1460. const struct hid_device_id *id = wacom_ids;
  1461. hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
  1462. wacom_wac->pid);
  1463. while (id->bus) {
  1464. if (id->vendor == USB_VENDOR_ID_WACOM &&
  1465. id->product == wacom_wac->pid)
  1466. break;
  1467. id++;
  1468. }
  1469. if (!id->bus) {
  1470. hid_info(wacom->hdev, "ignoring unknown PID.\n");
  1471. return;
  1472. }
  1473. /* Stylus interface */
  1474. wacom_wac1->features =
  1475. *((struct wacom_features *)id->driver_data);
  1476. wacom_wac1->pid = wacom_wac->pid;
  1477. hid_hw_stop(hdev1);
  1478. error = wacom_parse_and_register(wacom1, true);
  1479. if (error)
  1480. goto fail;
  1481. /* Touch interface */
  1482. if (wacom_wac1->features.touch_max ||
  1483. (wacom_wac1->features.type >= INTUOSHT &&
  1484. wacom_wac1->features.type <= BAMBOO_PT)) {
  1485. wacom_wac2->features =
  1486. *((struct wacom_features *)id->driver_data);
  1487. wacom_wac2->pid = wacom_wac->pid;
  1488. hid_hw_stop(hdev2);
  1489. error = wacom_parse_and_register(wacom2, true);
  1490. if (error)
  1491. goto fail;
  1492. }
  1493. error = wacom_initialize_battery(wacom);
  1494. if (error)
  1495. goto fail;
  1496. }
  1497. return;
  1498. fail:
  1499. wacom_clean_inputs(wacom1);
  1500. wacom_clean_inputs(wacom2);
  1501. return;
  1502. }
  1503. static int wacom_probe(struct hid_device *hdev,
  1504. const struct hid_device_id *id)
  1505. {
  1506. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  1507. struct usb_device *dev = interface_to_usbdev(intf);
  1508. struct wacom *wacom;
  1509. struct wacom_wac *wacom_wac;
  1510. struct wacom_features *features;
  1511. int error;
  1512. if (!id->driver_data)
  1513. return -EINVAL;
  1514. hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
  1515. /* hid-core sets this quirk for the boot interface */
  1516. hdev->quirks &= ~HID_QUIRK_NOGET;
  1517. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  1518. if (!wacom)
  1519. return -ENOMEM;
  1520. hid_set_drvdata(hdev, wacom);
  1521. wacom->hdev = hdev;
  1522. wacom_wac = &wacom->wacom_wac;
  1523. wacom_wac->features = *((struct wacom_features *)id->driver_data);
  1524. features = &wacom_wac->features;
  1525. if (features->check_for_hid_type && features->hid_type != hdev->type) {
  1526. error = -ENODEV;
  1527. goto fail_type;
  1528. }
  1529. wacom->usbdev = dev;
  1530. wacom->intf = intf;
  1531. mutex_init(&wacom->lock);
  1532. INIT_WORK(&wacom->work, wacom_wireless_work);
  1533. /* ask for the report descriptor to be loaded by HID */
  1534. error = hid_parse(hdev);
  1535. if (error) {
  1536. hid_err(hdev, "parse failed\n");
  1537. goto fail_parse;
  1538. }
  1539. error = wacom_parse_and_register(wacom, false);
  1540. if (error)
  1541. goto fail_parse;
  1542. if (hdev->bus == BUS_BLUETOOTH) {
  1543. error = device_create_file(&hdev->dev, &dev_attr_speed);
  1544. if (error)
  1545. hid_warn(hdev,
  1546. "can't create sysfs speed attribute err: %d\n",
  1547. error);
  1548. }
  1549. return 0;
  1550. fail_type:
  1551. fail_parse:
  1552. kfree(wacom);
  1553. hid_set_drvdata(hdev, NULL);
  1554. return error;
  1555. }
  1556. static void wacom_remove(struct hid_device *hdev)
  1557. {
  1558. struct wacom *wacom = hid_get_drvdata(hdev);
  1559. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1560. struct wacom_features *features = &wacom_wac->features;
  1561. if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
  1562. hid_hw_close(hdev);
  1563. hid_hw_stop(hdev);
  1564. cancel_work_sync(&wacom->work);
  1565. wacom_clean_inputs(wacom);
  1566. if (hdev->bus == BUS_BLUETOOTH)
  1567. device_remove_file(&hdev->dev, &dev_attr_speed);
  1568. wacom_destroy_battery(wacom);
  1569. wacom_remove_shared_data(wacom);
  1570. hid_set_drvdata(hdev, NULL);
  1571. kfree(wacom);
  1572. }
  1573. #ifdef CONFIG_PM
  1574. static int wacom_resume(struct hid_device *hdev)
  1575. {
  1576. struct wacom *wacom = hid_get_drvdata(hdev);
  1577. struct wacom_features *features = &wacom->wacom_wac.features;
  1578. mutex_lock(&wacom->lock);
  1579. /* switch to wacom mode first */
  1580. wacom_query_tablet_data(hdev, features);
  1581. wacom_led_control(wacom);
  1582. mutex_unlock(&wacom->lock);
  1583. return 0;
  1584. }
  1585. static int wacom_reset_resume(struct hid_device *hdev)
  1586. {
  1587. return wacom_resume(hdev);
  1588. }
  1589. #endif /* CONFIG_PM */
  1590. static struct hid_driver wacom_driver = {
  1591. .name = "wacom",
  1592. .id_table = wacom_ids,
  1593. .probe = wacom_probe,
  1594. .remove = wacom_remove,
  1595. .report = wacom_wac_report,
  1596. #ifdef CONFIG_PM
  1597. .resume = wacom_resume,
  1598. .reset_resume = wacom_reset_resume,
  1599. #endif
  1600. .raw_event = wacom_raw_event,
  1601. };
  1602. module_hid_driver(wacom_driver);
  1603. MODULE_VERSION(DRIVER_VERSION);
  1604. MODULE_AUTHOR(DRIVER_AUTHOR);
  1605. MODULE_DESCRIPTION(DRIVER_DESC);
  1606. MODULE_LICENSE(DRIVER_LICENSE);