aiptek.c 62 KB

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