wacom_sys.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923
  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 = container_of(dev, struct 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 = container_of(dev, struct 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 = container_of(dev, struct 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 = container_of(dev, struct 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 = container_of(dev, struct 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 = container_of(dev, struct 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 = container_of(kobj->parent, struct device, kobj);
  954. struct hid_device *hdev = container_of(dev, struct 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 = container_of(kobj->parent, struct device, kobj);
  1048. struct hid_device *hdev = container_of(dev, struct 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. if (wacom->remote_dir)
  1141. kobject_put(wacom->remote_dir);
  1142. wacom->wacom_wac.pen_input = NULL;
  1143. wacom->wacom_wac.touch_input = NULL;
  1144. wacom->wacom_wac.pad_input = NULL;
  1145. wacom_destroy_leds(wacom);
  1146. }
  1147. static int wacom_allocate_inputs(struct wacom *wacom)
  1148. {
  1149. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1150. wacom_wac->pen_input = wacom_allocate_input(wacom);
  1151. wacom_wac->touch_input = wacom_allocate_input(wacom);
  1152. wacom_wac->pad_input = wacom_allocate_input(wacom);
  1153. if (!wacom_wac->pen_input || !wacom_wac->touch_input || !wacom_wac->pad_input) {
  1154. wacom_clean_inputs(wacom);
  1155. return -ENOMEM;
  1156. }
  1157. wacom_wac->pen_input->name = wacom_wac->pen_name;
  1158. wacom_wac->touch_input->name = wacom_wac->touch_name;
  1159. wacom_wac->pad_input->name = wacom_wac->pad_name;
  1160. return 0;
  1161. }
  1162. static int wacom_register_inputs(struct wacom *wacom)
  1163. {
  1164. struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
  1165. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  1166. int error = 0;
  1167. pen_input_dev = wacom_wac->pen_input;
  1168. touch_input_dev = wacom_wac->touch_input;
  1169. pad_input_dev = wacom_wac->pad_input;
  1170. if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
  1171. return -EINVAL;
  1172. error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
  1173. if (error) {
  1174. /* no pen in use on this interface */
  1175. input_free_device(pen_input_dev);
  1176. wacom_wac->pen_input = NULL;
  1177. pen_input_dev = NULL;
  1178. } else {
  1179. error = input_register_device(pen_input_dev);
  1180. if (error)
  1181. goto fail_register_pen_input;
  1182. wacom_wac->pen_registered = true;
  1183. }
  1184. error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
  1185. if (error) {
  1186. /* no touch in use on this interface */
  1187. input_free_device(touch_input_dev);
  1188. wacom_wac->touch_input = NULL;
  1189. touch_input_dev = NULL;
  1190. } else {
  1191. error = input_register_device(touch_input_dev);
  1192. if (error)
  1193. goto fail_register_touch_input;
  1194. wacom_wac->touch_registered = true;
  1195. }
  1196. error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
  1197. if (error) {
  1198. /* no pad in use on this interface */
  1199. input_free_device(pad_input_dev);
  1200. wacom_wac->pad_input = NULL;
  1201. pad_input_dev = NULL;
  1202. } else {
  1203. error = input_register_device(pad_input_dev);
  1204. if (error)
  1205. goto fail_register_pad_input;
  1206. wacom_wac->pad_registered = true;
  1207. error = wacom_initialize_leds(wacom);
  1208. if (error)
  1209. goto fail_leds;
  1210. error = wacom_initialize_remote(wacom);
  1211. if (error)
  1212. goto fail_remote;
  1213. }
  1214. return 0;
  1215. fail_remote:
  1216. wacom_destroy_leds(wacom);
  1217. fail_leds:
  1218. input_unregister_device(pad_input_dev);
  1219. pad_input_dev = NULL;
  1220. wacom_wac->pad_registered = false;
  1221. fail_register_pad_input:
  1222. if (touch_input_dev)
  1223. input_unregister_device(touch_input_dev);
  1224. wacom_wac->touch_input = NULL;
  1225. wacom_wac->touch_registered = false;
  1226. fail_register_touch_input:
  1227. if (pen_input_dev)
  1228. input_unregister_device(pen_input_dev);
  1229. wacom_wac->pen_input = NULL;
  1230. wacom_wac->pen_registered = false;
  1231. fail_register_pen_input:
  1232. return error;
  1233. }
  1234. /*
  1235. * Not all devices report physical dimensions from HID.
  1236. * Compute the default from hardcoded logical dimension
  1237. * and resolution before driver overwrites them.
  1238. */
  1239. static void wacom_set_default_phy(struct wacom_features *features)
  1240. {
  1241. if (features->x_resolution) {
  1242. features->x_phy = (features->x_max * 100) /
  1243. features->x_resolution;
  1244. features->y_phy = (features->y_max * 100) /
  1245. features->y_resolution;
  1246. }
  1247. }
  1248. static void wacom_calculate_res(struct wacom_features *features)
  1249. {
  1250. /* set unit to "100th of a mm" for devices not reported by HID */
  1251. if (!features->unit) {
  1252. features->unit = 0x11;
  1253. features->unitExpo = -3;
  1254. }
  1255. features->x_resolution = wacom_calc_hid_res(features->x_max,
  1256. features->x_phy,
  1257. features->unit,
  1258. features->unitExpo);
  1259. features->y_resolution = wacom_calc_hid_res(features->y_max,
  1260. features->y_phy,
  1261. features->unit,
  1262. features->unitExpo);
  1263. }
  1264. static void wacom_wireless_work(struct work_struct *work)
  1265. {
  1266. struct wacom *wacom = container_of(work, struct wacom, work);
  1267. struct usb_device *usbdev = wacom->usbdev;
  1268. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1269. struct hid_device *hdev1, *hdev2;
  1270. struct wacom *wacom1, *wacom2;
  1271. struct wacom_wac *wacom_wac1, *wacom_wac2;
  1272. int error;
  1273. /*
  1274. * Regardless if this is a disconnect or a new tablet,
  1275. * remove any existing input and battery devices.
  1276. */
  1277. wacom_destroy_battery(wacom);
  1278. /* Stylus interface */
  1279. hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
  1280. wacom1 = hid_get_drvdata(hdev1);
  1281. wacom_wac1 = &(wacom1->wacom_wac);
  1282. wacom_clean_inputs(wacom1);
  1283. /* Touch interface */
  1284. hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
  1285. wacom2 = hid_get_drvdata(hdev2);
  1286. wacom_wac2 = &(wacom2->wacom_wac);
  1287. wacom_clean_inputs(wacom2);
  1288. if (wacom_wac->pid == 0) {
  1289. hid_info(wacom->hdev, "wireless tablet disconnected\n");
  1290. wacom_wac1->shared->type = 0;
  1291. } else {
  1292. const struct hid_device_id *id = wacom_ids;
  1293. hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
  1294. wacom_wac->pid);
  1295. while (id->bus) {
  1296. if (id->vendor == USB_VENDOR_ID_WACOM &&
  1297. id->product == wacom_wac->pid)
  1298. break;
  1299. id++;
  1300. }
  1301. if (!id->bus) {
  1302. hid_info(wacom->hdev, "ignoring unknown PID.\n");
  1303. return;
  1304. }
  1305. /* Stylus interface */
  1306. wacom_wac1->features =
  1307. *((struct wacom_features *)id->driver_data);
  1308. wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PEN;
  1309. wacom_set_default_phy(&wacom_wac1->features);
  1310. wacom_calculate_res(&wacom_wac1->features);
  1311. snprintf(wacom_wac1->pen_name, WACOM_NAME_MAX, "%s (WL) Pen",
  1312. wacom_wac1->features.name);
  1313. if (wacom_wac1->features.type < BAMBOO_PEN ||
  1314. wacom_wac1->features.type > BAMBOO_PT) {
  1315. snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX, "%s (WL) Pad",
  1316. wacom_wac1->features.name);
  1317. wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PAD;
  1318. }
  1319. wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
  1320. wacom_wac1->shared->type = wacom_wac1->features.type;
  1321. wacom_wac1->pid = wacom_wac->pid;
  1322. error = wacom_allocate_inputs(wacom1) ||
  1323. wacom_register_inputs(wacom1);
  1324. if (error)
  1325. goto fail;
  1326. /* Touch interface */
  1327. if (wacom_wac1->features.touch_max ||
  1328. (wacom_wac1->features.type >= INTUOSHT &&
  1329. wacom_wac1->features.type <= BAMBOO_PT)) {
  1330. wacom_wac2->features =
  1331. *((struct wacom_features *)id->driver_data);
  1332. wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
  1333. wacom_set_default_phy(&wacom_wac2->features);
  1334. wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
  1335. wacom_calculate_res(&wacom_wac2->features);
  1336. snprintf(wacom_wac2->touch_name, WACOM_NAME_MAX,
  1337. "%s (WL) Finger",wacom_wac2->features.name);
  1338. if (wacom_wac1->features.touch_max)
  1339. wacom_wac2->features.device_type |= WACOM_DEVICETYPE_TOUCH;
  1340. if (wacom_wac1->features.type >= INTUOSHT &&
  1341. wacom_wac1->features.type <= BAMBOO_PT) {
  1342. snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
  1343. "%s (WL) Pad",wacom_wac2->features.name);
  1344. wacom_wac2->features.device_type |= WACOM_DEVICETYPE_PAD;
  1345. }
  1346. wacom_wac2->pid = wacom_wac->pid;
  1347. error = wacom_allocate_inputs(wacom2) ||
  1348. wacom_register_inputs(wacom2);
  1349. if (error)
  1350. goto fail;
  1351. if ((wacom_wac1->features.type == INTUOSHT ||
  1352. wacom_wac1->features.type == INTUOSHT2) &&
  1353. wacom_wac1->features.touch_max)
  1354. wacom_wac->shared->touch_input = wacom_wac2->touch_input;
  1355. }
  1356. error = wacom_initialize_battery(wacom);
  1357. if (error)
  1358. goto fail;
  1359. }
  1360. return;
  1361. fail:
  1362. wacom_clean_inputs(wacom1);
  1363. wacom_clean_inputs(wacom2);
  1364. return;
  1365. }
  1366. void wacom_battery_work(struct work_struct *work)
  1367. {
  1368. struct wacom *wacom = container_of(work, struct wacom, work);
  1369. if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
  1370. !wacom->battery) {
  1371. wacom_initialize_battery(wacom);
  1372. }
  1373. else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
  1374. wacom->battery) {
  1375. wacom_destroy_battery(wacom);
  1376. }
  1377. }
  1378. static size_t wacom_compute_pktlen(struct hid_device *hdev)
  1379. {
  1380. struct hid_report_enum *report_enum;
  1381. struct hid_report *report;
  1382. size_t size = 0;
  1383. report_enum = hdev->report_enum + HID_INPUT_REPORT;
  1384. list_for_each_entry(report, &report_enum->report_list, list) {
  1385. size_t report_size = hid_report_len(report);
  1386. if (report_size > size)
  1387. size = report_size;
  1388. }
  1389. return size;
  1390. }
  1391. static void wacom_update_name(struct wacom *wacom)
  1392. {
  1393. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1394. struct wacom_features *features = &wacom_wac->features;
  1395. char name[WACOM_NAME_MAX];
  1396. /* Generic devices name unspecified */
  1397. if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
  1398. if (strstr(wacom->hdev->name, "Wacom") ||
  1399. strstr(wacom->hdev->name, "wacom") ||
  1400. strstr(wacom->hdev->name, "WACOM")) {
  1401. /* name is in HID descriptor, use it */
  1402. strlcpy(name, wacom->hdev->name, sizeof(name));
  1403. /* strip out excess whitespaces */
  1404. while (1) {
  1405. char *gap = strstr(name, " ");
  1406. if (gap == NULL)
  1407. break;
  1408. /* shift everything including the terminator */
  1409. memmove(gap, gap+1, strlen(gap));
  1410. }
  1411. /* get rid of trailing whitespace */
  1412. if (name[strlen(name)-1] == ' ')
  1413. name[strlen(name)-1] = '\0';
  1414. } else {
  1415. /* no meaningful name retrieved. use product ID */
  1416. snprintf(name, sizeof(name),
  1417. "%s %X", features->name, wacom->hdev->product);
  1418. }
  1419. } else {
  1420. strlcpy(name, features->name, sizeof(name));
  1421. }
  1422. /* Append the device type to the name */
  1423. snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
  1424. "%s Pen", name);
  1425. snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
  1426. "%s Finger", name);
  1427. snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
  1428. "%s Pad", name);
  1429. }
  1430. static int wacom_probe(struct hid_device *hdev,
  1431. const struct hid_device_id *id)
  1432. {
  1433. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  1434. struct usb_device *dev = interface_to_usbdev(intf);
  1435. struct wacom *wacom;
  1436. struct wacom_wac *wacom_wac;
  1437. struct wacom_features *features;
  1438. int error;
  1439. unsigned int connect_mask = HID_CONNECT_HIDRAW;
  1440. if (!id->driver_data)
  1441. return -EINVAL;
  1442. hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
  1443. /* hid-core sets this quirk for the boot interface */
  1444. hdev->quirks &= ~HID_QUIRK_NOGET;
  1445. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  1446. if (!wacom)
  1447. return -ENOMEM;
  1448. hid_set_drvdata(hdev, wacom);
  1449. wacom->hdev = hdev;
  1450. /* ask for the report descriptor to be loaded by HID */
  1451. error = hid_parse(hdev);
  1452. if (error) {
  1453. hid_err(hdev, "parse failed\n");
  1454. goto fail_parse;
  1455. }
  1456. wacom_wac = &wacom->wacom_wac;
  1457. wacom_wac->features = *((struct wacom_features *)id->driver_data);
  1458. features = &wacom_wac->features;
  1459. features->pktlen = wacom_compute_pktlen(hdev);
  1460. if (features->pktlen > WACOM_PKGLEN_MAX) {
  1461. error = -EINVAL;
  1462. goto fail_pktlen;
  1463. }
  1464. if (features->check_for_hid_type && features->hid_type != hdev->type) {
  1465. error = -ENODEV;
  1466. goto fail_type;
  1467. }
  1468. wacom->usbdev = dev;
  1469. wacom->intf = intf;
  1470. mutex_init(&wacom->lock);
  1471. INIT_WORK(&wacom->work, wacom_wireless_work);
  1472. error = wacom_allocate_inputs(wacom);
  1473. if (error)
  1474. goto fail_allocate_inputs;
  1475. /*
  1476. * Bamboo Pad has a generic hid handling for the Pen, and we switch it
  1477. * into debug mode for the touch part.
  1478. * We ignore the other interfaces.
  1479. */
  1480. if (features->type == BAMBOO_PAD) {
  1481. if (features->pktlen == WACOM_PKGLEN_PENABLED) {
  1482. features->type = HID_GENERIC;
  1483. } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
  1484. (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
  1485. error = -ENODEV;
  1486. goto fail_shared_data;
  1487. }
  1488. }
  1489. /* set the default size in case we do not get them from hid */
  1490. wacom_set_default_phy(features);
  1491. /* Retrieve the physical and logical size for touch devices */
  1492. wacom_retrieve_hid_descriptor(hdev, features);
  1493. wacom_setup_device_quirks(wacom);
  1494. if (features->device_type == WACOM_DEVICETYPE_NONE &&
  1495. features->type != WIRELESS) {
  1496. error = features->type == HID_GENERIC ? -ENODEV : 0;
  1497. dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
  1498. hdev->name,
  1499. error ? "Ignoring" : "Assuming pen");
  1500. if (error)
  1501. goto fail_shared_data;
  1502. features->device_type |= WACOM_DEVICETYPE_PEN;
  1503. }
  1504. wacom_calculate_res(features);
  1505. wacom_update_name(wacom);
  1506. error = wacom_add_shared_data(hdev);
  1507. if (error)
  1508. goto fail_shared_data;
  1509. if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
  1510. (features->quirks & WACOM_QUIRK_BATTERY)) {
  1511. error = wacom_initialize_battery(wacom);
  1512. if (error)
  1513. goto fail_battery;
  1514. }
  1515. error = wacom_register_inputs(wacom);
  1516. if (error)
  1517. goto fail_register_inputs;
  1518. if (hdev->bus == BUS_BLUETOOTH) {
  1519. error = device_create_file(&hdev->dev, &dev_attr_speed);
  1520. if (error)
  1521. hid_warn(hdev,
  1522. "can't create sysfs speed attribute err: %d\n",
  1523. error);
  1524. }
  1525. if (features->type == HID_GENERIC)
  1526. connect_mask |= HID_CONNECT_DRIVER;
  1527. /* Regular HID work starts now */
  1528. error = hid_hw_start(hdev, connect_mask);
  1529. if (error) {
  1530. hid_err(hdev, "hw start failed\n");
  1531. goto fail_hw_start;
  1532. }
  1533. /* Note that if query fails it is not a hard failure */
  1534. wacom_query_tablet_data(hdev, features);
  1535. /* touch only Bamboo doesn't support pen */
  1536. if ((features->type == BAMBOO_TOUCH) &&
  1537. (features->device_type & WACOM_DEVICETYPE_PEN)) {
  1538. error = -ENODEV;
  1539. goto fail_hw_start;
  1540. }
  1541. /* pen only Bamboo neither support touch nor pad */
  1542. if ((features->type == BAMBOO_PEN) &&
  1543. ((features->device_type & WACOM_DEVICETYPE_TOUCH) ||
  1544. (features->device_type & WACOM_DEVICETYPE_PAD))) {
  1545. error = -ENODEV;
  1546. goto fail_hw_start;
  1547. }
  1548. if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
  1549. error = hid_hw_open(hdev);
  1550. if ((wacom_wac->features.type == INTUOSHT ||
  1551. wacom_wac->features.type == INTUOSHT2) &&
  1552. (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)) {
  1553. wacom_wac->shared->touch_input = wacom_wac->touch_input;
  1554. }
  1555. return 0;
  1556. fail_hw_start:
  1557. if (hdev->bus == BUS_BLUETOOTH)
  1558. device_remove_file(&hdev->dev, &dev_attr_speed);
  1559. fail_register_inputs:
  1560. wacom_clean_inputs(wacom);
  1561. wacom_destroy_battery(wacom);
  1562. fail_battery:
  1563. wacom_remove_shared_data(wacom);
  1564. fail_shared_data:
  1565. wacom_clean_inputs(wacom);
  1566. fail_allocate_inputs:
  1567. fail_type:
  1568. fail_pktlen:
  1569. fail_parse:
  1570. kfree(wacom);
  1571. hid_set_drvdata(hdev, NULL);
  1572. return error;
  1573. }
  1574. static void wacom_remove(struct hid_device *hdev)
  1575. {
  1576. struct wacom *wacom = hid_get_drvdata(hdev);
  1577. hid_hw_stop(hdev);
  1578. cancel_work_sync(&wacom->work);
  1579. wacom_clean_inputs(wacom);
  1580. if (hdev->bus == BUS_BLUETOOTH)
  1581. device_remove_file(&hdev->dev, &dev_attr_speed);
  1582. wacom_destroy_battery(wacom);
  1583. wacom_remove_shared_data(wacom);
  1584. hid_set_drvdata(hdev, NULL);
  1585. kfree(wacom);
  1586. }
  1587. #ifdef CONFIG_PM
  1588. static int wacom_resume(struct hid_device *hdev)
  1589. {
  1590. struct wacom *wacom = hid_get_drvdata(hdev);
  1591. struct wacom_features *features = &wacom->wacom_wac.features;
  1592. mutex_lock(&wacom->lock);
  1593. /* switch to wacom mode first */
  1594. wacom_query_tablet_data(hdev, features);
  1595. wacom_led_control(wacom);
  1596. mutex_unlock(&wacom->lock);
  1597. return 0;
  1598. }
  1599. static int wacom_reset_resume(struct hid_device *hdev)
  1600. {
  1601. return wacom_resume(hdev);
  1602. }
  1603. #endif /* CONFIG_PM */
  1604. static struct hid_driver wacom_driver = {
  1605. .name = "wacom",
  1606. .id_table = wacom_ids,
  1607. .probe = wacom_probe,
  1608. .remove = wacom_remove,
  1609. .report = wacom_wac_report,
  1610. #ifdef CONFIG_PM
  1611. .resume = wacom_resume,
  1612. .reset_resume = wacom_reset_resume,
  1613. #endif
  1614. .raw_event = wacom_raw_event,
  1615. };
  1616. module_hid_driver(wacom_driver);
  1617. MODULE_VERSION(DRIVER_VERSION);
  1618. MODULE_AUTHOR(DRIVER_AUTHOR);
  1619. MODULE_DESCRIPTION(DRIVER_DESC);
  1620. MODULE_LICENSE(DRIVER_LICENSE);