aiptek.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  1. /*
  2. * Native support for the Aiptek HyperPen USB Tablets
  3. * (4000U/5000U/6000U/8000U/12000U)
  4. *
  5. * Copyright (c) 2001 Chris Atenasio <chris@crud.net>
  6. * Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net>
  7. *
  8. * based on wacom.c by
  9. * Vojtech Pavlik <vojtech@suse.cz>
  10. * Andreas Bach Aaen <abach@stofanet.dk>
  11. * Clifford Wolf <clifford@clifford.at>
  12. * Sam Mosel <sam.mosel@computer.org>
  13. * James E. Blair <corvus@gnu.org>
  14. * Daniel Egger <egger@suse.de>
  15. *
  16. * Many thanks to Oliver Kuechemann for his support.
  17. *
  18. * ChangeLog:
  19. * v0.1 - Initial release
  20. * v0.2 - Hack to get around fake event 28's. (Bryan W. Headley)
  21. * v0.3 - Make URB dynamic (Bryan W. Headley, Jun-8-2002)
  22. * Released to Linux 2.4.19 and 2.5.x
  23. * v0.4 - Rewrote substantial portions of the code to deal with
  24. * corrected control sequences, timing, dynamic configuration,
  25. * support of 6000U - 12000U, procfs, and macro key support
  26. * (Jan-1-2003 - Feb-5-2003, Bryan W. Headley)
  27. * v1.0 - Added support for diagnostic messages, count of messages
  28. * received from URB - Mar-8-2003, Bryan W. Headley
  29. * v1.1 - added support for tablet resolution, changed DV and proximity
  30. * some corrections - Jun-22-2003, martin schneebacher
  31. * - Added support for the sysfs interface, deprecating the
  32. * procfs interface for 2.5.x kernel. Also added support for
  33. * Wheel command. Bryan W. Headley July-15-2003.
  34. * v1.2 - Reworked jitter timer as a kernel thread.
  35. * Bryan W. Headley November-28-2003/Jan-10-2004.
  36. * v1.3 - Repaired issue of kernel thread going nuts on single-processor
  37. * machines, introduced programmableDelay as a command line
  38. * parameter. Feb 7 2004, Bryan W. Headley.
  39. * v1.4 - Re-wire jitter so it does not require a thread. Courtesy of
  40. * Rene van Paassen. Added reporting of physical pointer device
  41. * (e.g., stylus, mouse in reports 2, 3, 4, 5. We don't know
  42. * for reports 1, 6.)
  43. * what physical device reports for reports 1, 6.) Also enabled
  44. * MOUSE and LENS tool button modes. Renamed "rubber" to "eraser".
  45. * Feb 20, 2004, Bryan W. Headley.
  46. * v1.5 - Added previousJitterable, so we don't do jitter delay when the
  47. * user is holding a button down for periods of time.
  48. *
  49. * NOTE:
  50. * This kernel driver is augmented by the "Aiptek" XFree86 input
  51. * driver for your X server, as well as the Gaiptek GUI Front-end
  52. * "Tablet Manager".
  53. * These three products are highly interactive with one another,
  54. * so therefore it's easier to document them all as one subsystem.
  55. * Please visit the project's "home page", located at,
  56. * http://aiptektablet.sourceforge.net.
  57. *
  58. * This program is free software; you can redistribute it and/or modify
  59. * it under the terms of the GNU General Public License as published by
  60. * the Free Software Foundation; either version 2 of the License, or
  61. * (at your option) any later version.
  62. *
  63. * This program is distributed in the hope that it will be useful,
  64. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  66. * GNU General Public License for more details.
  67. *
  68. * You should have received a copy of the GNU General Public License
  69. * along with this program; if not, write to the Free Software
  70. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  71. */
  72. #include <linux/jiffies.h>
  73. #include <linux/kernel.h>
  74. #include <linux/slab.h>
  75. #include <linux/module.h>
  76. #include <linux/init.h>
  77. #include <linux/usb/input.h>
  78. #include <asm/uaccess.h>
  79. #include <asm/unaligned.h>
  80. /*
  81. * Version Information
  82. */
  83. #define DRIVER_VERSION "v1.5 (May-15-2004)"
  84. #define DRIVER_AUTHOR "Bryan W. Headley/Chris Atenasio"
  85. #define DRIVER_DESC "Aiptek HyperPen USB Tablet Driver (Linux 2.6.x)"
  86. /*
  87. * Aiptek status packet:
  88. *
  89. * (returned as Report 1 - relative coordinates from mouse and stylus)
  90. *
  91. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  92. * byte0 0 0 0 0 0 0 0 1
  93. * byte1 0 0 0 0 0 BS2 BS Tip
  94. * byte2 X7 X6 X5 X4 X3 X2 X1 X0
  95. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  96. *
  97. * (returned as Report 2 - absolute coordinates from the stylus)
  98. *
  99. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  100. * byte0 0 0 0 0 0 0 1 0
  101. * byte1 X7 X6 X5 X4 X3 X2 X1 X0
  102. * byte2 X15 X14 X13 X12 X11 X10 X9 X8
  103. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  104. * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
  105. * byte5 * * * BS2 BS1 Tip IR DV
  106. * byte6 P7 P6 P5 P4 P3 P2 P1 P0
  107. * byte7 P15 P14 P13 P12 P11 P10 P9 P8
  108. *
  109. * (returned as Report 3 - absolute coordinates from the mouse)
  110. *
  111. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  112. * byte0 0 0 0 0 0 0 1 1
  113. * byte1 X7 X6 X5 X4 X3 X2 X1 X0
  114. * byte2 X15 X14 X13 X12 X11 X10 X9 X8
  115. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  116. * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
  117. * byte5 * * * BS2 BS1 Tip IR DV
  118. * byte6 P7 P6 P5 P4 P3 P2 P1 P0
  119. * byte7 P15 P14 P13 P12 P11 P10 P9 P8
  120. *
  121. * (returned as Report 4 - macrokeys from the stylus)
  122. *
  123. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  124. * byte0 0 0 0 0 0 1 0 0
  125. * byte1 0 0 0 BS2 BS Tip IR DV
  126. * byte2 0 0 0 0 0 0 1 0
  127. * byte3 0 0 0 K4 K3 K2 K1 K0
  128. * byte4 P7 P6 P5 P4 P3 P2 P1 P0
  129. * byte5 P15 P14 P13 P12 P11 P10 P9 P8
  130. *
  131. * (returned as Report 5 - macrokeys from the mouse)
  132. *
  133. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  134. * byte0 0 0 0 0 0 1 0 1
  135. * byte1 0 0 0 BS2 BS Tip IR DV
  136. * byte2 0 0 0 0 0 0 1 0
  137. * byte3 0 0 0 K4 K3 K2 K1 K0
  138. * byte4 P7 P6 P5 P4 P3 P2 P1 P0
  139. * byte5 P15 P14 P13 P12 P11 P10 P9 P8
  140. *
  141. * IR: In Range = Proximity on
  142. * DV = Data Valid
  143. * BS = Barrel Switch (as in, macro keys)
  144. * BS2 also referred to as Tablet Pick
  145. *
  146. * Command Summary:
  147. *
  148. * Use report_type CONTROL (3)
  149. * Use report_id 2
  150. *
  151. * Command/Data Description Return Bytes Return Value
  152. * 0x10/0x00 SwitchToMouse 0
  153. * 0x10/0x01 SwitchToTablet 0
  154. * 0x18/0x04 SetResolution 0
  155. * 0x12/0xFF AutoGainOn 0
  156. * 0x17/0x00 FilterOn 0
  157. * 0x01/0x00 GetXExtension 2 MaxX
  158. * 0x01/0x01 GetYExtension 2 MaxY
  159. * 0x02/0x00 GetModelCode 2 ModelCode = LOBYTE
  160. * 0x03/0x00 GetODMCode 2 ODMCode
  161. * 0x08/0x00 GetPressureLevels 2 =512
  162. * 0x04/0x00 GetFirmwareVersion 2 Firmware Version
  163. * 0x11/0x02 EnableMacroKeys 0
  164. *
  165. * To initialize the tablet:
  166. *
  167. * (1) Send Resolution500LPI (Command)
  168. * (2) Query for Model code (Option Report)
  169. * (3) Query for ODM code (Option Report)
  170. * (4) Query for firmware (Option Report)
  171. * (5) Query for GetXExtension (Option Report)
  172. * (6) Query for GetYExtension (Option Report)
  173. * (7) Query for GetPressureLevels (Option Report)
  174. * (8) SwitchToTablet for Absolute coordinates, or
  175. * SwitchToMouse for Relative coordinates (Command)
  176. * (9) EnableMacroKeys (Command)
  177. * (10) FilterOn (Command)
  178. * (11) AutoGainOn (Command)
  179. *
  180. * (Step 9 can be omitted, but you'll then have no function keys.)
  181. */
  182. #define USB_VENDOR_ID_AIPTEK 0x08ca
  183. #define USB_REQ_GET_REPORT 0x01
  184. #define USB_REQ_SET_REPORT 0x09
  185. /* PointerMode codes
  186. */
  187. #define AIPTEK_POINTER_ONLY_MOUSE_MODE 0
  188. #define AIPTEK_POINTER_ONLY_STYLUS_MODE 1
  189. #define AIPTEK_POINTER_EITHER_MODE 2
  190. #define AIPTEK_POINTER_ALLOW_MOUSE_MODE(a) \
  191. (a == AIPTEK_POINTER_ONLY_MOUSE_MODE || \
  192. a == AIPTEK_POINTER_EITHER_MODE)
  193. #define AIPTEK_POINTER_ALLOW_STYLUS_MODE(a) \
  194. (a == AIPTEK_POINTER_ONLY_STYLUS_MODE || \
  195. a == AIPTEK_POINTER_EITHER_MODE)
  196. /* CoordinateMode code
  197. */
  198. #define AIPTEK_COORDINATE_RELATIVE_MODE 0
  199. #define AIPTEK_COORDINATE_ABSOLUTE_MODE 1
  200. /* XTilt and YTilt values
  201. */
  202. #define AIPTEK_TILT_MIN (-128)
  203. #define AIPTEK_TILT_MAX 127
  204. #define AIPTEK_TILT_DISABLE (-10101)
  205. /* Wheel values
  206. */
  207. #define AIPTEK_WHEEL_MIN 0
  208. #define AIPTEK_WHEEL_MAX 1024
  209. #define AIPTEK_WHEEL_DISABLE (-10101)
  210. /* ToolCode values, which BTW are 0x140 .. 0x14f
  211. * We have things set up such that if TOOL_BUTTON_FIRED_BIT is
  212. * not set, we'll send one instance of AIPTEK_TOOL_BUTTON_xxx.
  213. *
  214. * Whenever the user resets the value, TOOL_BUTTON_FIRED_BIT will
  215. * get reset.
  216. */
  217. #define TOOL_BUTTON(x) ((x) & 0x14f)
  218. #define TOOL_BUTTON_FIRED(x) ((x) & 0x200)
  219. #define TOOL_BUTTON_FIRED_BIT 0x200
  220. /* toolMode codes
  221. */
  222. #define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
  223. #define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
  224. #define AIPTEK_TOOL_BUTTON_PENCIL_MODE BTN_TOOL_PENCIL
  225. #define AIPTEK_TOOL_BUTTON_BRUSH_MODE BTN_TOOL_BRUSH
  226. #define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE BTN_TOOL_AIRBRUSH
  227. #define AIPTEK_TOOL_BUTTON_ERASER_MODE BTN_TOOL_RUBBER
  228. #define AIPTEK_TOOL_BUTTON_MOUSE_MODE BTN_TOOL_MOUSE
  229. #define AIPTEK_TOOL_BUTTON_LENS_MODE BTN_TOOL_LENS
  230. /* Diagnostic message codes
  231. */
  232. #define AIPTEK_DIAGNOSTIC_NA 0
  233. #define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE 1
  234. #define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
  235. #define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
  236. /* Time to wait (in ms) to help mask hand jittering
  237. * when pressing the stylus buttons.
  238. */
  239. #define AIPTEK_JITTER_DELAY_DEFAULT 50
  240. /* Time to wait (in ms) in-between sending the tablet
  241. * a command and beginning the process of reading the return
  242. * sequence from the tablet.
  243. */
  244. #define AIPTEK_PROGRAMMABLE_DELAY_25 25
  245. #define AIPTEK_PROGRAMMABLE_DELAY_50 50
  246. #define AIPTEK_PROGRAMMABLE_DELAY_100 100
  247. #define AIPTEK_PROGRAMMABLE_DELAY_200 200
  248. #define AIPTEK_PROGRAMMABLE_DELAY_300 300
  249. #define AIPTEK_PROGRAMMABLE_DELAY_400 400
  250. #define AIPTEK_PROGRAMMABLE_DELAY_DEFAULT AIPTEK_PROGRAMMABLE_DELAY_400
  251. /* Mouse button programming
  252. */
  253. #define AIPTEK_MOUSE_LEFT_BUTTON 0x04
  254. #define AIPTEK_MOUSE_RIGHT_BUTTON 0x08
  255. #define AIPTEK_MOUSE_MIDDLE_BUTTON 0x10
  256. /* Stylus button programming
  257. */
  258. #define AIPTEK_STYLUS_LOWER_BUTTON 0x08
  259. #define AIPTEK_STYLUS_UPPER_BUTTON 0x10
  260. /* Length of incoming packet from the tablet
  261. */
  262. #define AIPTEK_PACKET_LENGTH 8
  263. /* We report in EV_MISC both the proximity and
  264. * whether the report came from the stylus, tablet mouse
  265. * or "unknown" -- Unknown when the tablet is in relative
  266. * mode, because we only get report 1's.
  267. */
  268. #define AIPTEK_REPORT_TOOL_UNKNOWN 0x10
  269. #define AIPTEK_REPORT_TOOL_STYLUS 0x20
  270. #define AIPTEK_REPORT_TOOL_MOUSE 0x40
  271. static int programmableDelay = AIPTEK_PROGRAMMABLE_DELAY_DEFAULT;
  272. static int jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
  273. struct aiptek_features {
  274. int odmCode; /* Tablet manufacturer code */
  275. int modelCode; /* Tablet model code (not unique) */
  276. int firmwareCode; /* prom/eeprom version */
  277. char usbPath[64 + 1]; /* device's physical usb path */
  278. };
  279. struct aiptek_settings {
  280. int pointerMode; /* stylus-, mouse-only or either */
  281. int coordinateMode; /* absolute/relative coords */
  282. int toolMode; /* pen, pencil, brush, etc. tool */
  283. int xTilt; /* synthetic xTilt amount */
  284. int yTilt; /* synthetic yTilt amount */
  285. int wheel; /* synthetic wheel amount */
  286. int stylusButtonUpper; /* stylus upper btn delivers... */
  287. int stylusButtonLower; /* stylus lower btn delivers... */
  288. int mouseButtonLeft; /* mouse left btn delivers... */
  289. int mouseButtonMiddle; /* mouse middle btn delivers... */
  290. int mouseButtonRight; /* mouse right btn delivers... */
  291. int programmableDelay; /* delay for tablet programming */
  292. int jitterDelay; /* delay for hand jittering */
  293. };
  294. struct aiptek {
  295. struct input_dev *inputdev; /* input device struct */
  296. struct usb_device *usbdev; /* usb device struct */
  297. struct urb *urb; /* urb for incoming reports */
  298. dma_addr_t data_dma; /* our dma stuffage */
  299. struct aiptek_features features; /* tablet's array of features */
  300. struct aiptek_settings curSetting; /* tablet's current programmable */
  301. struct aiptek_settings newSetting; /* ... and new param settings */
  302. unsigned int ifnum; /* interface number for IO */
  303. int diagnostic; /* tablet diagnostic codes */
  304. unsigned long eventCount; /* event count */
  305. int inDelay; /* jitter: in jitter delay? */
  306. unsigned long endDelay; /* jitter: time when delay ends */
  307. int previousJitterable; /* jitterable prev value */
  308. unsigned char *data; /* incoming packet data */
  309. };
  310. static const int eventTypes[] = {
  311. EV_KEY, EV_ABS, EV_REL, EV_MSC,
  312. };
  313. static const int absEvents[] = {
  314. ABS_X, ABS_Y, ABS_PRESSURE, ABS_TILT_X, ABS_TILT_Y,
  315. ABS_WHEEL, ABS_MISC,
  316. };
  317. static const int relEvents[] = {
  318. REL_X, REL_Y, REL_WHEEL,
  319. };
  320. static const int buttonEvents[] = {
  321. BTN_LEFT, BTN_RIGHT, BTN_MIDDLE,
  322. BTN_TOOL_PEN, BTN_TOOL_RUBBER, BTN_TOOL_PENCIL, BTN_TOOL_AIRBRUSH,
  323. BTN_TOOL_BRUSH, BTN_TOOL_MOUSE, BTN_TOOL_LENS, BTN_TOUCH,
  324. BTN_STYLUS, BTN_STYLUS2,
  325. };
  326. /*
  327. * Permit easy lookup of keyboard events to send, versus
  328. * the bitmap which comes from the tablet. This hides the
  329. * issue that the F_keys are not sequentially numbered.
  330. */
  331. static const int macroKeyEvents[] = {
  332. KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
  333. KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
  334. KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
  335. KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
  336. KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
  337. KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
  338. };
  339. /***********************************************************************
  340. * Map values to strings and back. Every map shoudl have the following
  341. * as its last element: { NULL, AIPTEK_INVALID_VALUE }.
  342. */
  343. #define AIPTEK_INVALID_VALUE -1
  344. struct aiptek_map {
  345. const char *string;
  346. int value;
  347. };
  348. static int map_str_to_val(const struct aiptek_map *map, const char *str, size_t count)
  349. {
  350. const struct aiptek_map *p;
  351. for (p = map; p->string; p++)
  352. if (!strncmp(str, p->string, count))
  353. return p->value;
  354. return AIPTEK_INVALID_VALUE;
  355. }
  356. static const char *map_val_to_str(const struct aiptek_map *map, int val)
  357. {
  358. const struct aiptek_map *p;
  359. for (p = map; p->value != AIPTEK_INVALID_VALUE; p++)
  360. if (val == p->value)
  361. return p->string;
  362. return "unknown";
  363. }
  364. /***********************************************************************
  365. * aiptek_irq can receive one of six potential reports.
  366. * The documentation for each is in the body of the function.
  367. *
  368. * The tablet reports on several attributes per invocation of
  369. * aiptek_irq. Because the Linux Input Event system allows the
  370. * transmission of ONE attribute per input_report_xxx() call,
  371. * collation has to be done on the other end to reconstitute
  372. * a complete tablet report. Further, the number of Input Event reports
  373. * submitted varies, depending on what USB report type, and circumstance.
  374. * To deal with this, EV_MSC is used to indicate an 'end-of-report'
  375. * message. This has been an undocumented convention understood by the kernel
  376. * tablet driver and clients such as gpm and XFree86's tablet drivers.
  377. *
  378. * Of the information received from the tablet, the one piece I
  379. * cannot transmit is the proximity bit (without resorting to an EV_MSC
  380. * convention above.) I therefore have taken over REL_MISC and ABS_MISC
  381. * (for relative and absolute reports, respectively) for communicating
  382. * Proximity. Why two events? I thought it interesting to know if the
  383. * Proximity event occurred while the tablet was in absolute or relative
  384. * mode.
  385. *
  386. * Other tablets use the notion of a certain minimum stylus pressure
  387. * to infer proximity. While that could have been done, that is yet
  388. * another 'by convention' behavior, the documentation for which
  389. * would be spread between two (or more) pieces of software.
  390. *
  391. * EV_MSC usage was terminated for this purpose in Linux 2.5.x, and
  392. * replaced with the input_sync() method (which emits EV_SYN.)
  393. */
  394. static void aiptek_irq(struct urb *urb)
  395. {
  396. struct aiptek *aiptek = urb->context;
  397. unsigned char *data = aiptek->data;
  398. struct input_dev *inputdev = aiptek->inputdev;
  399. int jitterable = 0;
  400. int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
  401. switch (urb->status) {
  402. case 0:
  403. /* Success */
  404. break;
  405. case -ECONNRESET:
  406. case -ENOENT:
  407. case -ESHUTDOWN:
  408. /* This urb is terminated, clean up */
  409. dbg("%s - urb shutting down with status: %d",
  410. __FUNCTION__, urb->status);
  411. return;
  412. default:
  413. dbg("%s - nonzero urb status received: %d",
  414. __FUNCTION__, urb->status);
  415. goto exit;
  416. }
  417. /* See if we are in a delay loop -- throw out report if true.
  418. */
  419. if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
  420. goto exit;
  421. }
  422. aiptek->inDelay = 0;
  423. aiptek->eventCount++;
  424. /* Report 1 delivers relative coordinates with either a stylus
  425. * or the mouse. You do not know, however, which input
  426. * tool generated the event.
  427. */
  428. if (data[0] == 1) {
  429. if (aiptek->curSetting.coordinateMode ==
  430. AIPTEK_COORDINATE_ABSOLUTE_MODE) {
  431. aiptek->diagnostic =
  432. AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
  433. } else {
  434. x = (signed char) data[2];
  435. y = (signed char) data[3];
  436. /* jitterable keeps track of whether any button has been pressed.
  437. * We're also using it to remap the physical mouse button mask
  438. * to pseudo-settings. (We don't specifically care about it's
  439. * value after moving/transposing mouse button bitmasks, except
  440. * that a non-zero value indicates that one or more
  441. * mouse button was pressed.)
  442. */
  443. jitterable = data[1] & 0x07;
  444. left = (data[1] & aiptek->curSetting.mouseButtonLeft >> 2) != 0 ? 1 : 0;
  445. right = (data[1] & aiptek->curSetting.mouseButtonRight >> 2) != 0 ? 1 : 0;
  446. middle = (data[1] & aiptek->curSetting.mouseButtonMiddle >> 2) != 0 ? 1 : 0;
  447. input_report_key(inputdev, BTN_LEFT, left);
  448. input_report_key(inputdev, BTN_MIDDLE, middle);
  449. input_report_key(inputdev, BTN_RIGHT, right);
  450. input_report_abs(inputdev, ABS_MISC,
  451. 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
  452. input_report_rel(inputdev, REL_X, x);
  453. input_report_rel(inputdev, REL_Y, y);
  454. /* Wheel support is in the form of a single-event
  455. * firing.
  456. */
  457. if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
  458. input_report_rel(inputdev, REL_WHEEL,
  459. aiptek->curSetting.wheel);
  460. aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
  461. }
  462. input_sync(inputdev);
  463. }
  464. }
  465. /* Report 2 is delivered only by the stylus, and delivers
  466. * absolute coordinates.
  467. */
  468. else if (data[0] == 2) {
  469. if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
  470. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
  471. } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
  472. (aiptek->curSetting.pointerMode)) {
  473. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
  474. } else {
  475. x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
  476. y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
  477. z = le16_to_cpu(get_unaligned((__le16 *) (data + 6)));
  478. dv = (data[5] & 0x01) != 0 ? 1 : 0;
  479. p = (data[5] & 0x02) != 0 ? 1 : 0;
  480. tip = (data[5] & 0x04) != 0 ? 1 : 0;
  481. /* Use jitterable to re-arrange button masks
  482. */
  483. jitterable = data[5] & 0x18;
  484. bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
  485. pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
  486. /* dv indicates 'data valid' (e.g., the tablet is in sync
  487. * and has delivered a "correct" report) We will ignore
  488. * all 'bad' reports...
  489. */
  490. if (dv != 0) {
  491. /* If we've not already sent a tool_button_?? code, do
  492. * so now. Then set FIRED_BIT so it won't be resent unless
  493. * the user forces FIRED_BIT off.
  494. */
  495. if (TOOL_BUTTON_FIRED
  496. (aiptek->curSetting.toolMode) == 0) {
  497. input_report_key(inputdev,
  498. TOOL_BUTTON(aiptek->curSetting.toolMode),
  499. 1);
  500. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  501. }
  502. if (p != 0) {
  503. input_report_abs(inputdev, ABS_X, x);
  504. input_report_abs(inputdev, ABS_Y, y);
  505. input_report_abs(inputdev, ABS_PRESSURE, z);
  506. input_report_key(inputdev, BTN_TOUCH, tip);
  507. input_report_key(inputdev, BTN_STYLUS, bs);
  508. input_report_key(inputdev, BTN_STYLUS2, pck);
  509. if (aiptek->curSetting.xTilt !=
  510. AIPTEK_TILT_DISABLE) {
  511. input_report_abs(inputdev,
  512. ABS_TILT_X,
  513. aiptek->curSetting.xTilt);
  514. }
  515. if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
  516. input_report_abs(inputdev,
  517. ABS_TILT_Y,
  518. aiptek->curSetting.yTilt);
  519. }
  520. /* Wheel support is in the form of a single-event
  521. * firing.
  522. */
  523. if (aiptek->curSetting.wheel !=
  524. AIPTEK_WHEEL_DISABLE) {
  525. input_report_abs(inputdev,
  526. ABS_WHEEL,
  527. aiptek->curSetting.wheel);
  528. aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
  529. }
  530. }
  531. input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
  532. input_sync(inputdev);
  533. }
  534. }
  535. }
  536. /* Report 3's come from the mouse in absolute mode.
  537. */
  538. else if (data[0] == 3) {
  539. if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
  540. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
  541. } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
  542. (aiptek->curSetting.pointerMode)) {
  543. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
  544. } else {
  545. x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
  546. y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
  547. jitterable = data[5] & 0x1c;
  548. dv = (data[5] & 0x01) != 0 ? 1 : 0;
  549. p = (data[5] & 0x02) != 0 ? 1 : 0;
  550. left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
  551. right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
  552. middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
  553. if (dv != 0) {
  554. /* If we've not already sent a tool_button_?? code, do
  555. * so now. Then set FIRED_BIT so it won't be resent unless
  556. * the user forces FIRED_BIT off.
  557. */
  558. if (TOOL_BUTTON_FIRED
  559. (aiptek->curSetting.toolMode) == 0) {
  560. input_report_key(inputdev,
  561. TOOL_BUTTON(aiptek->curSetting.toolMode),
  562. 1);
  563. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  564. }
  565. if (p != 0) {
  566. input_report_abs(inputdev, ABS_X, x);
  567. input_report_abs(inputdev, ABS_Y, y);
  568. input_report_key(inputdev, BTN_LEFT, left);
  569. input_report_key(inputdev, BTN_MIDDLE, middle);
  570. input_report_key(inputdev, BTN_RIGHT, right);
  571. /* Wheel support is in the form of a single-event
  572. * firing.
  573. */
  574. if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
  575. input_report_abs(inputdev,
  576. ABS_WHEEL,
  577. aiptek->curSetting.wheel);
  578. aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
  579. }
  580. }
  581. input_report_rel(inputdev, REL_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
  582. input_sync(inputdev);
  583. }
  584. }
  585. }
  586. /* Report 4s come from the macro keys when pressed by stylus
  587. */
  588. else if (data[0] == 4) {
  589. jitterable = data[1] & 0x18;
  590. dv = (data[1] & 0x01) != 0 ? 1 : 0;
  591. p = (data[1] & 0x02) != 0 ? 1 : 0;
  592. tip = (data[1] & 0x04) != 0 ? 1 : 0;
  593. bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
  594. pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
  595. macro = data[3];
  596. z = le16_to_cpu(get_unaligned((__le16 *) (data + 4)));
  597. if (dv != 0) {
  598. /* If we've not already sent a tool_button_?? code, do
  599. * so now. Then set FIRED_BIT so it won't be resent unless
  600. * the user forces FIRED_BIT off.
  601. */
  602. if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
  603. input_report_key(inputdev,
  604. TOOL_BUTTON(aiptek->curSetting.toolMode),
  605. 1);
  606. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  607. }
  608. if (p != 0) {
  609. input_report_key(inputdev, BTN_TOUCH, tip);
  610. input_report_key(inputdev, BTN_STYLUS, bs);
  611. input_report_key(inputdev, BTN_STYLUS2, pck);
  612. input_report_abs(inputdev, ABS_PRESSURE, z);
  613. }
  614. /* For safety, we're sending key 'break' codes for the
  615. * neighboring macro keys.
  616. */
  617. if (macro > 0) {
  618. input_report_key(inputdev,
  619. macroKeyEvents[macro - 1], 0);
  620. }
  621. if (macro < 25) {
  622. input_report_key(inputdev,
  623. macroKeyEvents[macro + 1], 0);
  624. }
  625. input_report_key(inputdev, macroKeyEvents[macro], p);
  626. input_report_abs(inputdev, ABS_MISC,
  627. p | AIPTEK_REPORT_TOOL_STYLUS);
  628. input_sync(inputdev);
  629. }
  630. }
  631. /* Report 5s come from the macro keys when pressed by mouse
  632. */
  633. else if (data[0] == 5) {
  634. jitterable = data[1] & 0x1c;
  635. dv = (data[1] & 0x01) != 0 ? 1 : 0;
  636. p = (data[1] & 0x02) != 0 ? 1 : 0;
  637. left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
  638. right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
  639. middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
  640. macro = data[3];
  641. if (dv != 0) {
  642. /* If we've not already sent a tool_button_?? code, do
  643. * so now. Then set FIRED_BIT so it won't be resent unless
  644. * the user forces FIRED_BIT off.
  645. */
  646. if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
  647. input_report_key(inputdev,
  648. TOOL_BUTTON(aiptek->curSetting.toolMode),
  649. 1);
  650. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  651. }
  652. if (p != 0) {
  653. input_report_key(inputdev, BTN_LEFT, left);
  654. input_report_key(inputdev, BTN_MIDDLE, middle);
  655. input_report_key(inputdev, BTN_RIGHT, right);
  656. }
  657. /* For safety, we're sending key 'break' codes for the
  658. * neighboring macro keys.
  659. */
  660. if (macro > 0) {
  661. input_report_key(inputdev,
  662. macroKeyEvents[macro - 1], 0);
  663. }
  664. if (macro < 25) {
  665. input_report_key(inputdev,
  666. macroKeyEvents[macro + 1], 0);
  667. }
  668. input_report_key(inputdev, macroKeyEvents[macro], 1);
  669. input_report_rel(inputdev, ABS_MISC,
  670. p | AIPTEK_REPORT_TOOL_MOUSE);
  671. input_sync(inputdev);
  672. }
  673. }
  674. /* We have no idea which tool can generate a report 6. Theoretically,
  675. * neither need to, having been given reports 4 & 5 for such use.
  676. * However, report 6 is the 'official-looking' report for macroKeys;
  677. * reports 4 & 5 supposively are used to support unnamed, unknown
  678. * hat switches (which just so happen to be the macroKeys.)
  679. */
  680. else if (data[0] == 6) {
  681. macro = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
  682. if (macro > 0) {
  683. input_report_key(inputdev, macroKeyEvents[macro - 1],
  684. 0);
  685. }
  686. if (macro < 25) {
  687. input_report_key(inputdev, macroKeyEvents[macro + 1],
  688. 0);
  689. }
  690. /* If we've not already sent a tool_button_?? code, do
  691. * so now. Then set FIRED_BIT so it won't be resent unless
  692. * the user forces FIRED_BIT off.
  693. */
  694. if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
  695. input_report_key(inputdev,
  696. TOOL_BUTTON(aiptek->curSetting.
  697. toolMode), 1);
  698. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  699. }
  700. input_report_key(inputdev, macroKeyEvents[macro], 1);
  701. input_report_abs(inputdev, ABS_MISC,
  702. 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
  703. input_sync(inputdev);
  704. } else {
  705. dbg("Unknown report %d", data[0]);
  706. }
  707. /* Jitter may occur when the user presses a button on the stlyus
  708. * or the mouse. What we do to prevent that is wait 'x' milliseconds
  709. * following a 'jitterable' event, which should give the hand some time
  710. * stabilize itself.
  711. *
  712. * We just introduced aiptek->previousJitterable to carry forth the
  713. * notion that jitter occurs when the button state changes from on to off:
  714. * a person drawing, holding a button down is not subject to jittering.
  715. * With that in mind, changing from upper button depressed to lower button
  716. * WILL transition through a jitter delay.
  717. */
  718. if (aiptek->previousJitterable != jitterable &&
  719. aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
  720. aiptek->endDelay = jiffies +
  721. ((aiptek->curSetting.jitterDelay * HZ) / 1000);
  722. aiptek->inDelay = 1;
  723. }
  724. aiptek->previousJitterable = jitterable;
  725. exit:
  726. retval = usb_submit_urb(urb, GFP_ATOMIC);
  727. if (retval != 0) {
  728. err("%s - usb_submit_urb failed with result %d",
  729. __FUNCTION__, retval);
  730. }
  731. }
  732. /***********************************************************************
  733. * These are the USB id's known so far. We do not identify them to
  734. * specific Aiptek model numbers, because there has been overlaps,
  735. * use, and reuse of id's in existing models. Certain models have
  736. * been known to use more than one ID, indicative perhaps of
  737. * manufacturing revisions. In any event, we consider these
  738. * IDs to not be model-specific nor unique.
  739. */
  740. static const struct usb_device_id aiptek_ids[] = {
  741. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
  742. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
  743. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
  744. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
  745. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
  746. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
  747. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
  748. {}
  749. };
  750. MODULE_DEVICE_TABLE(usb, aiptek_ids);
  751. /***********************************************************************
  752. * Open an instance of the tablet driver.
  753. */
  754. static int aiptek_open(struct input_dev *inputdev)
  755. {
  756. struct aiptek *aiptek = input_get_drvdata(inputdev);
  757. aiptek->urb->dev = aiptek->usbdev;
  758. if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
  759. return -EIO;
  760. return 0;
  761. }
  762. /***********************************************************************
  763. * Close an instance of the tablet driver.
  764. */
  765. static void aiptek_close(struct input_dev *inputdev)
  766. {
  767. struct aiptek *aiptek = input_get_drvdata(inputdev);
  768. usb_kill_urb(aiptek->urb);
  769. }
  770. /***********************************************************************
  771. * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
  772. * where they were known as usb_set_report and usb_get_report.
  773. */
  774. static int
  775. aiptek_set_report(struct aiptek *aiptek,
  776. unsigned char report_type,
  777. unsigned char report_id, void *buffer, int size)
  778. {
  779. return usb_control_msg(aiptek->usbdev,
  780. usb_sndctrlpipe(aiptek->usbdev, 0),
  781. USB_REQ_SET_REPORT,
  782. USB_TYPE_CLASS | USB_RECIP_INTERFACE |
  783. USB_DIR_OUT, (report_type << 8) + report_id,
  784. aiptek->ifnum, buffer, size, 5000);
  785. }
  786. static int
  787. aiptek_get_report(struct aiptek *aiptek,
  788. unsigned char report_type,
  789. unsigned char report_id, void *buffer, int size)
  790. {
  791. return usb_control_msg(aiptek->usbdev,
  792. usb_rcvctrlpipe(aiptek->usbdev, 0),
  793. USB_REQ_GET_REPORT,
  794. USB_TYPE_CLASS | USB_RECIP_INTERFACE |
  795. USB_DIR_IN, (report_type << 8) + report_id,
  796. aiptek->ifnum, buffer, size, 5000);
  797. }
  798. /***********************************************************************
  799. * Send a command to the tablet.
  800. */
  801. static int
  802. aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
  803. {
  804. const int sizeof_buf = 3 * sizeof(u8);
  805. int ret;
  806. u8 *buf;
  807. buf = kmalloc(sizeof_buf, GFP_KERNEL);
  808. if (!buf)
  809. return -ENOMEM;
  810. buf[0] = 2;
  811. buf[1] = command;
  812. buf[2] = data;
  813. if ((ret =
  814. aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
  815. dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
  816. command, data);
  817. }
  818. kfree(buf);
  819. return ret < 0 ? ret : 0;
  820. }
  821. /***********************************************************************
  822. * Retrieve information from the tablet. Querying info is defined as first
  823. * sending the {command,data} sequence as a command, followed by a wait
  824. * (aka, "programmaticDelay") and then a "read" request.
  825. */
  826. static int
  827. aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
  828. {
  829. const int sizeof_buf = 3 * sizeof(u8);
  830. int ret;
  831. u8 *buf;
  832. buf = kmalloc(sizeof_buf, GFP_KERNEL);
  833. if (!buf)
  834. return -ENOMEM;
  835. buf[0] = 2;
  836. buf[1] = command;
  837. buf[2] = data;
  838. if (aiptek_command(aiptek, command, data) != 0) {
  839. kfree(buf);
  840. return -EIO;
  841. }
  842. msleep(aiptek->curSetting.programmableDelay);
  843. if ((ret =
  844. aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
  845. dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
  846. buf[0], buf[1], buf[2]);
  847. ret = -EIO;
  848. } else {
  849. ret = le16_to_cpu(get_unaligned((__le16 *) (buf + 1)));
  850. }
  851. kfree(buf);
  852. return ret;
  853. }
  854. /***********************************************************************
  855. * Program the tablet into either absolute or relative mode.
  856. * We also get information about the tablet's size.
  857. */
  858. static int aiptek_program_tablet(struct aiptek *aiptek)
  859. {
  860. int ret;
  861. /* Execute Resolution500LPI */
  862. if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
  863. return ret;
  864. /* Query getModelCode */
  865. if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
  866. return ret;
  867. aiptek->features.modelCode = ret & 0xff;
  868. /* Query getODMCode */
  869. if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
  870. return ret;
  871. aiptek->features.odmCode = ret;
  872. /* Query getFirmwareCode */
  873. if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
  874. return ret;
  875. aiptek->features.firmwareCode = ret;
  876. /* Query getXextension */
  877. if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
  878. return ret;
  879. aiptek->inputdev->absmin[ABS_X] = 0;
  880. aiptek->inputdev->absmax[ABS_X] = ret - 1;
  881. /* Query getYextension */
  882. if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
  883. return ret;
  884. aiptek->inputdev->absmin[ABS_Y] = 0;
  885. aiptek->inputdev->absmax[ABS_Y] = ret - 1;
  886. /* Query getPressureLevels */
  887. if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
  888. return ret;
  889. aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
  890. aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
  891. /* Depending on whether we are in absolute or relative mode, we will
  892. * do a switchToTablet(absolute) or switchToMouse(relative) command.
  893. */
  894. if (aiptek->curSetting.coordinateMode ==
  895. AIPTEK_COORDINATE_ABSOLUTE_MODE) {
  896. /* Execute switchToTablet */
  897. if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
  898. return ret;
  899. }
  900. } else {
  901. /* Execute switchToMouse */
  902. if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
  903. return ret;
  904. }
  905. }
  906. /* Enable the macro keys */
  907. if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
  908. return ret;
  909. #if 0
  910. /* Execute FilterOn */
  911. if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
  912. return ret;
  913. #endif
  914. /* Execute AutoGainOn */
  915. if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
  916. return ret;
  917. /* Reset the eventCount, so we track events from last (re)programming
  918. */
  919. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
  920. aiptek->eventCount = 0;
  921. return 0;
  922. }
  923. /***********************************************************************
  924. * Sysfs functions. Sysfs prefers that individually-tunable parameters
  925. * exist in their separate pseudo-files. Summary data that is immutable
  926. * may exist in a singular file so long as you don't define a writeable
  927. * interface.
  928. */
  929. /***********************************************************************
  930. * support the 'size' file -- display support
  931. */
  932. static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
  933. {
  934. struct aiptek *aiptek = dev_get_drvdata(dev);
  935. return snprintf(buf, PAGE_SIZE, "%dx%d\n",
  936. aiptek->inputdev->absmax[ABS_X] + 1,
  937. aiptek->inputdev->absmax[ABS_Y] + 1);
  938. }
  939. /* These structs define the sysfs files, param #1 is the name of the
  940. * file, param 2 is the file permissions, param 3 & 4 are to the
  941. * output generator and input parser routines. Absence of a routine is
  942. * permitted -- it only means can't either 'cat' the file, or send data
  943. * to it.
  944. */
  945. static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
  946. /***********************************************************************
  947. * support routines for the 'pointer_mode' file. Note that this file
  948. * both displays current setting and allows reprogramming.
  949. */
  950. static struct aiptek_map pointer_mode_map[] = {
  951. { "stylus", AIPTEK_POINTER_ONLY_STYLUS_MODE },
  952. { "mouse", AIPTEK_POINTER_ONLY_MOUSE_MODE },
  953. { "either", AIPTEK_POINTER_EITHER_MODE },
  954. { NULL, AIPTEK_INVALID_VALUE }
  955. };
  956. static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
  957. {
  958. struct aiptek *aiptek = dev_get_drvdata(dev);
  959. return snprintf(buf, PAGE_SIZE, "%s\n",
  960. map_val_to_str(pointer_mode_map,
  961. aiptek->curSetting.pointerMode));
  962. }
  963. static ssize_t
  964. store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  965. {
  966. struct aiptek *aiptek = dev_get_drvdata(dev);
  967. int new_mode = map_str_to_val(pointer_mode_map, buf, count);
  968. if (new_mode == AIPTEK_INVALID_VALUE)
  969. return -EINVAL;
  970. aiptek->newSetting.pointerMode = new_mode;
  971. return count;
  972. }
  973. static DEVICE_ATTR(pointer_mode,
  974. S_IRUGO | S_IWUGO,
  975. show_tabletPointerMode, store_tabletPointerMode);
  976. /***********************************************************************
  977. * support routines for the 'coordinate_mode' file. Note that this file
  978. * both displays current setting and allows reprogramming.
  979. */
  980. static struct aiptek_map coordinate_mode_map[] = {
  981. { "absolute", AIPTEK_COORDINATE_ABSOLUTE_MODE },
  982. { "relative", AIPTEK_COORDINATE_RELATIVE_MODE },
  983. { NULL, AIPTEK_INVALID_VALUE }
  984. };
  985. static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
  986. {
  987. struct aiptek *aiptek = dev_get_drvdata(dev);
  988. return snprintf(buf, PAGE_SIZE, "%s\n",
  989. map_val_to_str(coordinate_mode_map,
  990. aiptek->curSetting.coordinateMode));
  991. }
  992. static ssize_t
  993. store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  994. {
  995. struct aiptek *aiptek = dev_get_drvdata(dev);
  996. int new_mode = map_str_to_val(coordinate_mode_map, buf, count);
  997. if (new_mode == AIPTEK_INVALID_VALUE)
  998. return -EINVAL;
  999. aiptek->newSetting.coordinateMode = new_mode;
  1000. return count;
  1001. }
  1002. static DEVICE_ATTR(coordinate_mode,
  1003. S_IRUGO | S_IWUGO,
  1004. show_tabletCoordinateMode, store_tabletCoordinateMode);
  1005. /***********************************************************************
  1006. * support routines for the 'tool_mode' file. Note that this file
  1007. * both displays current setting and allows reprogramming.
  1008. */
  1009. static struct aiptek_map tool_mode_map[] = {
  1010. { "mouse", AIPTEK_TOOL_BUTTON_MOUSE_MODE },
  1011. { "eraser", AIPTEK_TOOL_BUTTON_ERASER_MODE },
  1012. { "pencil", AIPTEK_TOOL_BUTTON_PENCIL_MODE },
  1013. { "pen", AIPTEK_TOOL_BUTTON_PEN_MODE },
  1014. { "brush", AIPTEK_TOOL_BUTTON_BRUSH_MODE },
  1015. { "airbrush", AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE },
  1016. { "lens", AIPTEK_TOOL_BUTTON_LENS_MODE },
  1017. { NULL, AIPTEK_INVALID_VALUE }
  1018. };
  1019. static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
  1020. {
  1021. struct aiptek *aiptek = dev_get_drvdata(dev);
  1022. return snprintf(buf, PAGE_SIZE, "%s\n",
  1023. map_val_to_str(tool_mode_map,
  1024. aiptek->curSetting.toolMode));
  1025. }
  1026. static ssize_t
  1027. store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1028. {
  1029. struct aiptek *aiptek = dev_get_drvdata(dev);
  1030. int new_mode = map_str_to_val(tool_mode_map, buf, count);
  1031. if (new_mode == AIPTEK_INVALID_VALUE)
  1032. return -EINVAL;
  1033. aiptek->newSetting.toolMode = new_mode;
  1034. return count;
  1035. }
  1036. static DEVICE_ATTR(tool_mode,
  1037. S_IRUGO | S_IWUGO,
  1038. show_tabletToolMode, store_tabletToolMode);
  1039. /***********************************************************************
  1040. * support routines for the 'xtilt' file. Note that this file
  1041. * both displays current setting and allows reprogramming.
  1042. */
  1043. static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
  1044. {
  1045. struct aiptek *aiptek = dev_get_drvdata(dev);
  1046. if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
  1047. return snprintf(buf, PAGE_SIZE, "disable\n");
  1048. } else {
  1049. return snprintf(buf, PAGE_SIZE, "%d\n",
  1050. aiptek->curSetting.xTilt);
  1051. }
  1052. }
  1053. static ssize_t
  1054. store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1055. {
  1056. struct aiptek *aiptek = dev_get_drvdata(dev);
  1057. int x;
  1058. if (strcmp(buf, "disable") == 0) {
  1059. aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
  1060. } else {
  1061. x = (int)simple_strtol(buf, NULL, 10);
  1062. if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
  1063. aiptek->newSetting.xTilt = x;
  1064. }
  1065. }
  1066. return count;
  1067. }
  1068. static DEVICE_ATTR(xtilt,
  1069. S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
  1070. /***********************************************************************
  1071. * support routines for the 'ytilt' file. Note that this file
  1072. * both displays current setting and allows reprogramming.
  1073. */
  1074. static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
  1075. {
  1076. struct aiptek *aiptek = dev_get_drvdata(dev);
  1077. if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
  1078. return snprintf(buf, PAGE_SIZE, "disable\n");
  1079. } else {
  1080. return snprintf(buf, PAGE_SIZE, "%d\n",
  1081. aiptek->curSetting.yTilt);
  1082. }
  1083. }
  1084. static ssize_t
  1085. store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1086. {
  1087. struct aiptek *aiptek = dev_get_drvdata(dev);
  1088. int y;
  1089. if (strcmp(buf, "disable") == 0) {
  1090. aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
  1091. } else {
  1092. y = (int)simple_strtol(buf, NULL, 10);
  1093. if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
  1094. aiptek->newSetting.yTilt = y;
  1095. }
  1096. }
  1097. return count;
  1098. }
  1099. static DEVICE_ATTR(ytilt,
  1100. S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
  1101. /***********************************************************************
  1102. * support routines for the 'jitter' file. Note that this file
  1103. * both displays current setting and allows reprogramming.
  1104. */
  1105. static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
  1106. {
  1107. struct aiptek *aiptek = dev_get_drvdata(dev);
  1108. return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
  1109. }
  1110. static ssize_t
  1111. store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1112. {
  1113. struct aiptek *aiptek = dev_get_drvdata(dev);
  1114. aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
  1115. return count;
  1116. }
  1117. static DEVICE_ATTR(jitter,
  1118. S_IRUGO | S_IWUGO,
  1119. show_tabletJitterDelay, store_tabletJitterDelay);
  1120. /***********************************************************************
  1121. * support routines for the 'delay' file. Note that this file
  1122. * both displays current setting and allows reprogramming.
  1123. */
  1124. static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
  1125. {
  1126. struct aiptek *aiptek = dev_get_drvdata(dev);
  1127. return snprintf(buf, PAGE_SIZE, "%d\n",
  1128. aiptek->curSetting.programmableDelay);
  1129. }
  1130. static ssize_t
  1131. store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1132. {
  1133. struct aiptek *aiptek = dev_get_drvdata(dev);
  1134. aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
  1135. return count;
  1136. }
  1137. static DEVICE_ATTR(delay,
  1138. S_IRUGO | S_IWUGO,
  1139. show_tabletProgrammableDelay, store_tabletProgrammableDelay);
  1140. /***********************************************************************
  1141. * support routines for the 'event_count' file. Note that this file
  1142. * only displays current setting.
  1143. */
  1144. static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
  1145. {
  1146. struct aiptek *aiptek = dev_get_drvdata(dev);
  1147. return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
  1148. }
  1149. static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
  1150. /***********************************************************************
  1151. * support routines for the 'diagnostic' file. Note that this file
  1152. * only displays current setting.
  1153. */
  1154. static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
  1155. {
  1156. struct aiptek *aiptek = dev_get_drvdata(dev);
  1157. char *retMsg;
  1158. switch (aiptek->diagnostic) {
  1159. case AIPTEK_DIAGNOSTIC_NA:
  1160. retMsg = "no errors\n";
  1161. break;
  1162. case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
  1163. retMsg = "Error: receiving relative reports\n";
  1164. break;
  1165. case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
  1166. retMsg = "Error: receiving absolute reports\n";
  1167. break;
  1168. case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
  1169. if (aiptek->curSetting.pointerMode ==
  1170. AIPTEK_POINTER_ONLY_MOUSE_MODE) {
  1171. retMsg = "Error: receiving stylus reports\n";
  1172. } else {
  1173. retMsg = "Error: receiving mouse reports\n";
  1174. }
  1175. break;
  1176. default:
  1177. return 0;
  1178. }
  1179. return snprintf(buf, PAGE_SIZE, retMsg);
  1180. }
  1181. static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
  1182. /***********************************************************************
  1183. * support routines for the 'stylus_upper' file. Note that this file
  1184. * both displays current setting and allows for setting changing.
  1185. */
  1186. static struct aiptek_map stylus_button_map[] = {
  1187. { "upper", AIPTEK_STYLUS_UPPER_BUTTON },
  1188. { "lower", AIPTEK_STYLUS_LOWER_BUTTON },
  1189. { NULL, AIPTEK_INVALID_VALUE }
  1190. };
  1191. static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
  1192. {
  1193. struct aiptek *aiptek = dev_get_drvdata(dev);
  1194. return snprintf(buf, PAGE_SIZE, "%s\n",
  1195. map_val_to_str(stylus_button_map,
  1196. aiptek->curSetting.stylusButtonUpper));
  1197. }
  1198. static ssize_t
  1199. store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1200. {
  1201. struct aiptek *aiptek = dev_get_drvdata(dev);
  1202. int new_button = map_str_to_val(stylus_button_map, buf, count);
  1203. if (new_button == AIPTEK_INVALID_VALUE)
  1204. return -EINVAL;
  1205. aiptek->newSetting.stylusButtonUpper = new_button;
  1206. return count;
  1207. }
  1208. static DEVICE_ATTR(stylus_upper,
  1209. S_IRUGO | S_IWUGO,
  1210. show_tabletStylusUpper, store_tabletStylusUpper);
  1211. /***********************************************************************
  1212. * support routines for the 'stylus_lower' file. Note that this file
  1213. * both displays current setting and allows for setting changing.
  1214. */
  1215. static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
  1216. {
  1217. struct aiptek *aiptek = dev_get_drvdata(dev);
  1218. return snprintf(buf, PAGE_SIZE, "%s\n",
  1219. map_val_to_str(stylus_button_map,
  1220. aiptek->curSetting.stylusButtonLower));
  1221. }
  1222. static ssize_t
  1223. store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1224. {
  1225. struct aiptek *aiptek = dev_get_drvdata(dev);
  1226. int new_button = map_str_to_val(stylus_button_map, buf, count);
  1227. if (new_button == AIPTEK_INVALID_VALUE)
  1228. return -EINVAL;
  1229. aiptek->newSetting.stylusButtonLower = new_button;
  1230. return count;
  1231. }
  1232. static DEVICE_ATTR(stylus_lower,
  1233. S_IRUGO | S_IWUGO,
  1234. show_tabletStylusLower, store_tabletStylusLower);
  1235. /***********************************************************************
  1236. * support routines for the 'mouse_left' file. Note that this file
  1237. * both displays current setting and allows for setting changing.
  1238. */
  1239. static struct aiptek_map mouse_button_map[] = {
  1240. { "left", AIPTEK_MOUSE_LEFT_BUTTON },
  1241. { "middle", AIPTEK_MOUSE_MIDDLE_BUTTON },
  1242. { "right", AIPTEK_MOUSE_RIGHT_BUTTON },
  1243. { NULL, AIPTEK_INVALID_VALUE }
  1244. };
  1245. static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
  1246. {
  1247. struct aiptek *aiptek = dev_get_drvdata(dev);
  1248. return snprintf(buf, PAGE_SIZE, "%s\n",
  1249. map_val_to_str(mouse_button_map,
  1250. aiptek->curSetting.mouseButtonLeft));
  1251. }
  1252. static ssize_t
  1253. store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1254. {
  1255. struct aiptek *aiptek = dev_get_drvdata(dev);
  1256. int new_button = map_str_to_val(mouse_button_map, buf, count);
  1257. if (new_button == AIPTEK_INVALID_VALUE)
  1258. return -EINVAL;
  1259. aiptek->newSetting.mouseButtonLeft = new_button;
  1260. return count;
  1261. }
  1262. static DEVICE_ATTR(mouse_left,
  1263. S_IRUGO | S_IWUGO,
  1264. show_tabletMouseLeft, store_tabletMouseLeft);
  1265. /***********************************************************************
  1266. * support routines for the 'mouse_middle' file. Note that this file
  1267. * both displays current setting and allows for setting changing.
  1268. */
  1269. static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
  1270. {
  1271. struct aiptek *aiptek = dev_get_drvdata(dev);
  1272. return snprintf(buf, PAGE_SIZE, "%s\n",
  1273. map_val_to_str(mouse_button_map,
  1274. aiptek->curSetting.mouseButtonMiddle));
  1275. }
  1276. static ssize_t
  1277. store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1278. {
  1279. struct aiptek *aiptek = dev_get_drvdata(dev);
  1280. int new_button = map_str_to_val(mouse_button_map, buf, count);
  1281. if (new_button == AIPTEK_INVALID_VALUE)
  1282. return -EINVAL;
  1283. aiptek->newSetting.mouseButtonMiddle = new_button;
  1284. return count;
  1285. }
  1286. static DEVICE_ATTR(mouse_middle,
  1287. S_IRUGO | S_IWUGO,
  1288. show_tabletMouseMiddle, store_tabletMouseMiddle);
  1289. /***********************************************************************
  1290. * support routines for the 'mouse_right' file. Note that this file
  1291. * both displays current setting and allows for setting changing.
  1292. */
  1293. static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
  1294. {
  1295. struct aiptek *aiptek = dev_get_drvdata(dev);
  1296. return snprintf(buf, PAGE_SIZE, "%s\n",
  1297. map_val_to_str(mouse_button_map,
  1298. aiptek->curSetting.mouseButtonRight));
  1299. }
  1300. static ssize_t
  1301. store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1302. {
  1303. struct aiptek *aiptek = dev_get_drvdata(dev);
  1304. int new_button = map_str_to_val(mouse_button_map, buf, count);
  1305. if (new_button == AIPTEK_INVALID_VALUE)
  1306. return -EINVAL;
  1307. aiptek->newSetting.mouseButtonRight = new_button;
  1308. return count;
  1309. }
  1310. static DEVICE_ATTR(mouse_right,
  1311. S_IRUGO | S_IWUGO,
  1312. show_tabletMouseRight, store_tabletMouseRight);
  1313. /***********************************************************************
  1314. * support routines for the 'wheel' file. Note that this file
  1315. * both displays current setting and allows for setting changing.
  1316. */
  1317. static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
  1318. {
  1319. struct aiptek *aiptek = dev_get_drvdata(dev);
  1320. if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
  1321. return snprintf(buf, PAGE_SIZE, "disable\n");
  1322. } else {
  1323. return snprintf(buf, PAGE_SIZE, "%d\n",
  1324. aiptek->curSetting.wheel);
  1325. }
  1326. }
  1327. static ssize_t
  1328. store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1329. {
  1330. struct aiptek *aiptek = dev_get_drvdata(dev);
  1331. aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
  1332. return count;
  1333. }
  1334. static DEVICE_ATTR(wheel,
  1335. S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
  1336. /***********************************************************************
  1337. * support routines for the 'execute' file. Note that this file
  1338. * both displays current setting and allows for setting changing.
  1339. */
  1340. static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
  1341. {
  1342. /* There is nothing useful to display, so a one-line manual
  1343. * is in order...
  1344. */
  1345. return snprintf(buf, PAGE_SIZE,
  1346. "Write anything to this file to program your tablet.\n");
  1347. }
  1348. static ssize_t
  1349. store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1350. {
  1351. struct aiptek *aiptek = dev_get_drvdata(dev);
  1352. /* We do not care what you write to this file. Merely the action
  1353. * of writing to this file triggers a tablet reprogramming.
  1354. */
  1355. memcpy(&aiptek->curSetting, &aiptek->newSetting,
  1356. sizeof(struct aiptek_settings));
  1357. if (aiptek_program_tablet(aiptek) < 0)
  1358. return -EIO;
  1359. return count;
  1360. }
  1361. static DEVICE_ATTR(execute,
  1362. S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
  1363. /***********************************************************************
  1364. * support routines for the 'odm_code' file. Note that this file
  1365. * only displays current setting.
  1366. */
  1367. static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
  1368. {
  1369. struct aiptek *aiptek = dev_get_drvdata(dev);
  1370. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
  1371. }
  1372. static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
  1373. /***********************************************************************
  1374. * support routines for the 'model_code' file. Note that this file
  1375. * only displays current setting.
  1376. */
  1377. static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
  1378. {
  1379. struct aiptek *aiptek = dev_get_drvdata(dev);
  1380. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
  1381. }
  1382. static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
  1383. /***********************************************************************
  1384. * support routines for the 'firmware_code' file. Note that this file
  1385. * only displays current setting.
  1386. */
  1387. static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
  1388. {
  1389. struct aiptek *aiptek = dev_get_drvdata(dev);
  1390. return snprintf(buf, PAGE_SIZE, "%04x\n",
  1391. aiptek->features.firmwareCode);
  1392. }
  1393. static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
  1394. static struct attribute *aiptek_attributes[] = {
  1395. &dev_attr_size.attr,
  1396. &dev_attr_pointer_mode.attr,
  1397. &dev_attr_coordinate_mode.attr,
  1398. &dev_attr_tool_mode.attr,
  1399. &dev_attr_xtilt.attr,
  1400. &dev_attr_ytilt.attr,
  1401. &dev_attr_jitter.attr,
  1402. &dev_attr_delay.attr,
  1403. &dev_attr_event_count.attr,
  1404. &dev_attr_diagnostic.attr,
  1405. &dev_attr_odm_code.attr,
  1406. &dev_attr_model_code.attr,
  1407. &dev_attr_firmware_code.attr,
  1408. &dev_attr_stylus_lower.attr,
  1409. &dev_attr_stylus_upper.attr,
  1410. &dev_attr_mouse_left.attr,
  1411. &dev_attr_mouse_middle.attr,
  1412. &dev_attr_mouse_right.attr,
  1413. &dev_attr_wheel.attr,
  1414. &dev_attr_execute.attr,
  1415. NULL
  1416. };
  1417. static struct attribute_group aiptek_attribute_group = {
  1418. .attrs = aiptek_attributes,
  1419. };
  1420. /***********************************************************************
  1421. * This routine is called when a tablet has been identified. It basically
  1422. * sets up the tablet and the driver's internal structures.
  1423. */
  1424. static int
  1425. aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1426. {
  1427. struct usb_device *usbdev = interface_to_usbdev(intf);
  1428. struct usb_endpoint_descriptor *endpoint;
  1429. struct aiptek *aiptek;
  1430. struct input_dev *inputdev;
  1431. int i;
  1432. int speeds[] = { 0,
  1433. AIPTEK_PROGRAMMABLE_DELAY_50,
  1434. AIPTEK_PROGRAMMABLE_DELAY_400,
  1435. AIPTEK_PROGRAMMABLE_DELAY_25,
  1436. AIPTEK_PROGRAMMABLE_DELAY_100,
  1437. AIPTEK_PROGRAMMABLE_DELAY_200,
  1438. AIPTEK_PROGRAMMABLE_DELAY_300
  1439. };
  1440. int err = -ENOMEM;
  1441. /* programmableDelay is where the command-line specified
  1442. * delay is kept. We make it the first element of speeds[],
  1443. * so therefore, your override speed is tried first, then the
  1444. * remainder. Note that the default value of 400ms will be tried
  1445. * if you do not specify any command line parameter.
  1446. */
  1447. speeds[0] = programmableDelay;
  1448. aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL);
  1449. inputdev = input_allocate_device();
  1450. if (!aiptek || !inputdev)
  1451. goto fail1;
  1452. aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
  1453. GFP_ATOMIC, &aiptek->data_dma);
  1454. if (!aiptek->data)
  1455. goto fail1;
  1456. aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
  1457. if (!aiptek->urb)
  1458. goto fail2;
  1459. aiptek->inputdev = inputdev;
  1460. aiptek->usbdev = usbdev;
  1461. aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
  1462. aiptek->inDelay = 0;
  1463. aiptek->endDelay = 0;
  1464. aiptek->previousJitterable = 0;
  1465. /* Set up the curSettings struct. Said struct contains the current
  1466. * programmable parameters. The newSetting struct contains changes
  1467. * the user makes to the settings via the sysfs interface. Those
  1468. * changes are not "committed" to curSettings until the user
  1469. * writes to the sysfs/.../execute file.
  1470. */
  1471. aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
  1472. aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
  1473. aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
  1474. aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
  1475. aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
  1476. aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
  1477. aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
  1478. aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
  1479. aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
  1480. aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
  1481. aiptek->curSetting.jitterDelay = jitterDelay;
  1482. aiptek->curSetting.programmableDelay = programmableDelay;
  1483. /* Both structs should have equivalent settings
  1484. */
  1485. aiptek->newSetting = aiptek->curSetting;
  1486. /* Determine the usb devices' physical path.
  1487. * Asketh not why we always pretend we're using "../input0",
  1488. * but I suspect this will have to be refactored one
  1489. * day if a single USB device can be a keyboard & a mouse
  1490. * & a tablet, and the inputX number actually will tell
  1491. * us something...
  1492. */
  1493. usb_make_path(usbdev, aiptek->features.usbPath,
  1494. sizeof(aiptek->features.usbPath));
  1495. strlcat(aiptek->features.usbPath, "/input0",
  1496. sizeof(aiptek->features.usbPath));
  1497. /* Set up client data, pointers to open and close routines
  1498. * for the input device.
  1499. */
  1500. inputdev->name = "Aiptek";
  1501. inputdev->phys = aiptek->features.usbPath;
  1502. usb_to_input_id(usbdev, &inputdev->id);
  1503. inputdev->dev.parent = &intf->dev;
  1504. input_set_drvdata(inputdev, aiptek);
  1505. inputdev->open = aiptek_open;
  1506. inputdev->close = aiptek_close;
  1507. /* Now program the capacities of the tablet, in terms of being
  1508. * an input device.
  1509. */
  1510. for (i = 0; i < ARRAY_SIZE(eventTypes); ++i)
  1511. __set_bit(eventTypes[i], inputdev->evbit);
  1512. for (i = 0; i < ARRAY_SIZE(absEvents); ++i)
  1513. __set_bit(absEvents[i], inputdev->absbit);
  1514. for (i = 0; i < ARRAY_SIZE(relEvents); ++i)
  1515. __set_bit(relEvents[i], inputdev->relbit);
  1516. __set_bit(MSC_SERIAL, inputdev->mscbit);
  1517. /* Set up key and button codes */
  1518. for (i = 0; i < ARRAY_SIZE(buttonEvents); ++i)
  1519. __set_bit(buttonEvents[i], inputdev->keybit);
  1520. for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i)
  1521. __set_bit(macroKeyEvents[i], inputdev->keybit);
  1522. /*
  1523. * Program the input device coordinate capacities. We do not yet
  1524. * know what maximum X, Y, and Z values are, so we're putting fake
  1525. * values in. Later, we'll ask the tablet to put in the correct
  1526. * values.
  1527. */
  1528. input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0);
  1529. input_set_abs_params(inputdev, ABS_Y, 0, 2249, 0, 0);
  1530. input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0);
  1531. input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
  1532. input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
  1533. input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
  1534. endpoint = &intf->altsetting[0].endpoint[0].desc;
  1535. /* Go set up our URB, which is called when the tablet receives
  1536. * input.
  1537. */
  1538. usb_fill_int_urb(aiptek->urb,
  1539. aiptek->usbdev,
  1540. usb_rcvintpipe(aiptek->usbdev,
  1541. endpoint->bEndpointAddress),
  1542. aiptek->data, 8, aiptek_irq, aiptek,
  1543. endpoint->bInterval);
  1544. aiptek->urb->transfer_dma = aiptek->data_dma;
  1545. aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1546. /* Program the tablet. This sets the tablet up in the mode
  1547. * specified in newSetting, and also queries the tablet's
  1548. * physical capacities.
  1549. *
  1550. * Sanity check: if a tablet doesn't like the slow programmatic
  1551. * delay, we often get sizes of 0x0. Let's use that as an indicator
  1552. * to try faster delays, up to 25 ms. If that logic fails, well, you'll
  1553. * have to explain to us how your tablet thinks it's 0x0, and yet that's
  1554. * not an error :-)
  1555. */
  1556. for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
  1557. aiptek->curSetting.programmableDelay = speeds[i];
  1558. (void)aiptek_program_tablet(aiptek);
  1559. if (aiptek->inputdev->absmax[ABS_X] > 0) {
  1560. info("input: Aiptek using %d ms programming speed\n",
  1561. aiptek->curSetting.programmableDelay);
  1562. break;
  1563. }
  1564. }
  1565. /* Associate this driver's struct with the usb interface.
  1566. */
  1567. usb_set_intfdata(intf, aiptek);
  1568. /* Set up the sysfs files
  1569. */
  1570. err = sysfs_create_group(&intf->dev.kobj, &aiptek_attribute_group);
  1571. if (err)
  1572. goto fail3;
  1573. /* Register the tablet as an Input Device
  1574. */
  1575. err = input_register_device(aiptek->inputdev);
  1576. if (err)
  1577. goto fail4;
  1578. return 0;
  1579. fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
  1580. fail3: usb_free_urb(aiptek->urb);
  1581. fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
  1582. aiptek->data_dma);
  1583. fail1: usb_set_intfdata(intf, NULL);
  1584. input_free_device(inputdev);
  1585. kfree(aiptek);
  1586. return err;
  1587. }
  1588. /***********************************************************************
  1589. * Deal with tablet disconnecting from the system.
  1590. */
  1591. static void aiptek_disconnect(struct usb_interface *intf)
  1592. {
  1593. struct aiptek *aiptek = usb_get_intfdata(intf);
  1594. /* Disassociate driver's struct with usb interface
  1595. */
  1596. usb_set_intfdata(intf, NULL);
  1597. if (aiptek != NULL) {
  1598. /* Free & unhook everything from the system.
  1599. */
  1600. usb_kill_urb(aiptek->urb);
  1601. input_unregister_device(aiptek->inputdev);
  1602. sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
  1603. usb_free_urb(aiptek->urb);
  1604. usb_buffer_free(interface_to_usbdev(intf),
  1605. AIPTEK_PACKET_LENGTH,
  1606. aiptek->data, aiptek->data_dma);
  1607. kfree(aiptek);
  1608. }
  1609. }
  1610. static struct usb_driver aiptek_driver = {
  1611. .name = "aiptek",
  1612. .probe = aiptek_probe,
  1613. .disconnect = aiptek_disconnect,
  1614. .id_table = aiptek_ids,
  1615. };
  1616. static int __init aiptek_init(void)
  1617. {
  1618. int result = usb_register(&aiptek_driver);
  1619. if (result == 0) {
  1620. info(DRIVER_VERSION ": " DRIVER_AUTHOR);
  1621. info(DRIVER_DESC);
  1622. }
  1623. return result;
  1624. }
  1625. static void __exit aiptek_exit(void)
  1626. {
  1627. usb_deregister(&aiptek_driver);
  1628. }
  1629. MODULE_AUTHOR(DRIVER_AUTHOR);
  1630. MODULE_DESCRIPTION(DRIVER_DESC);
  1631. MODULE_LICENSE("GPL");
  1632. module_param(programmableDelay, int, 0);
  1633. MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
  1634. module_param(jitterDelay, int, 0);
  1635. MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
  1636. module_init(aiptek_init);
  1637. module_exit(aiptek_exit);