aiptek.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274
  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/input.h>
  76. #include <linux/module.h>
  77. #include <linux/init.h>
  78. #include <linux/usb.h>
  79. #include <linux/sched.h>
  80. #include <asm/uaccess.h>
  81. #include <asm/unaligned.h>
  82. /*
  83. * Version Information
  84. */
  85. #define DRIVER_VERSION "v1.5 (May-15-2004)"
  86. #define DRIVER_AUTHOR "Bryan W. Headley/Chris Atenasio"
  87. #define DRIVER_DESC "Aiptek HyperPen USB Tablet Driver (Linux 2.6.x)"
  88. /*
  89. * Aiptek status packet:
  90. *
  91. * (returned as Report 1 - relative coordinates from mouse and stylus)
  92. *
  93. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  94. * byte0 0 0 0 0 0 0 0 1
  95. * byte1 0 0 0 0 0 BS2 BS Tip
  96. * byte2 X7 X6 X5 X4 X3 X2 X1 X0
  97. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  98. *
  99. * (returned as Report 2 - absolute coordinates from the stylus)
  100. *
  101. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  102. * byte0 0 0 0 0 0 0 1 0
  103. * byte1 X7 X6 X5 X4 X3 X2 X1 X0
  104. * byte2 X15 X14 X13 X12 X11 X10 X9 X8
  105. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  106. * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
  107. * byte5 * * * BS2 BS1 Tip IR DV
  108. * byte6 P7 P6 P5 P4 P3 P2 P1 P0
  109. * byte7 P15 P14 P13 P12 P11 P10 P9 P8
  110. *
  111. * (returned as Report 3 - absolute coordinates from the mouse)
  112. *
  113. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  114. * byte0 0 0 0 0 0 0 1 0
  115. * byte1 X7 X6 X5 X4 X3 X2 X1 X0
  116. * byte2 X15 X14 X13 X12 X11 X10 X9 X8
  117. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  118. * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
  119. * byte5 * * * BS2 BS1 Tip IR DV
  120. * byte6 P7 P6 P5 P4 P3 P2 P1 P0
  121. * byte7 P15 P14 P13 P12 P11 P10 P9 P8
  122. *
  123. * (returned as Report 4 - macrokeys from the stylus)
  124. *
  125. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  126. * byte0 0 0 0 0 0 1 0 0
  127. * byte1 0 0 0 BS2 BS Tip IR DV
  128. * byte2 0 0 0 0 0 0 1 0
  129. * byte3 0 0 0 K4 K3 K2 K1 K0
  130. * byte4 P7 P6 P5 P4 P3 P2 P1 P0
  131. * byte5 P15 P14 P13 P12 P11 P10 P9 P8
  132. *
  133. * (returned as Report 5 - macrokeys from the mouse)
  134. *
  135. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  136. * byte0 0 0 0 0 0 1 0 0
  137. * byte1 0 0 0 BS2 BS Tip IR DV
  138. * byte2 0 0 0 0 0 0 1 0
  139. * byte3 0 0 0 K4 K3 K2 K1 K0
  140. * byte4 P7 P6 P5 P4 P3 P2 P1 P0
  141. * byte5 P15 P14 P13 P12 P11 P10 P9 P8
  142. *
  143. * IR: In Range = Proximity on
  144. * DV = Data Valid
  145. * BS = Barrel Switch (as in, macro keys)
  146. * BS2 also referred to as Tablet Pick
  147. *
  148. * Command Summary:
  149. *
  150. * Use report_type CONTROL (3)
  151. * Use report_id 2
  152. *
  153. * Command/Data Description Return Bytes Return Value
  154. * 0x10/0x00 SwitchToMouse 0
  155. * 0x10/0x01 SwitchToTablet 0
  156. * 0x18/0x04 SetResolution 0
  157. * 0x12/0xFF AutoGainOn 0
  158. * 0x17/0x00 FilterOn 0
  159. * 0x01/0x00 GetXExtension 2 MaxX
  160. * 0x01/0x01 GetYExtension 2 MaxY
  161. * 0x02/0x00 GetModelCode 2 ModelCode = LOBYTE
  162. * 0x03/0x00 GetODMCode 2 ODMCode
  163. * 0x08/0x00 GetPressureLevels 2 =512
  164. * 0x04/0x00 GetFirmwareVersion 2 Firmware Version
  165. * 0x11/0x02 EnableMacroKeys 0
  166. *
  167. * To initialize the tablet:
  168. *
  169. * (1) Send Resolution500LPI (Command)
  170. * (2) Query for Model code (Option Report)
  171. * (3) Query for ODM code (Option Report)
  172. * (4) Query for firmware (Option Report)
  173. * (5) Query for GetXExtension (Option Report)
  174. * (6) Query for GetYExtension (Option Report)
  175. * (7) Query for GetPressureLevels (Option Report)
  176. * (8) SwitchToTablet for Absolute coordinates, or
  177. * SwitchToMouse for Relative coordinates (Command)
  178. * (9) EnableMacroKeys (Command)
  179. * (10) FilterOn (Command)
  180. * (11) AutoGainOn (Command)
  181. *
  182. * (Step 9 can be omitted, but you'll then have no function keys.)
  183. */
  184. #define USB_VENDOR_ID_AIPTEK 0x08ca
  185. #define USB_REQ_GET_REPORT 0x01
  186. #define USB_REQ_SET_REPORT 0x09
  187. /* PointerMode codes
  188. */
  189. #define AIPTEK_POINTER_ONLY_MOUSE_MODE 0
  190. #define AIPTEK_POINTER_ONLY_STYLUS_MODE 1
  191. #define AIPTEK_POINTER_EITHER_MODE 2
  192. #define AIPTEK_POINTER_ALLOW_MOUSE_MODE(a) \
  193. (a == AIPTEK_POINTER_ONLY_MOUSE_MODE || \
  194. a == AIPTEK_POINTER_EITHER_MODE)
  195. #define AIPTEK_POINTER_ALLOW_STYLUS_MODE(a) \
  196. (a == AIPTEK_POINTER_ONLY_STYLUS_MODE || \
  197. a == AIPTEK_POINTER_EITHER_MODE)
  198. /* CoordinateMode code
  199. */
  200. #define AIPTEK_COORDINATE_RELATIVE_MODE 0
  201. #define AIPTEK_COORDINATE_ABSOLUTE_MODE 1
  202. /* XTilt and YTilt values
  203. */
  204. #define AIPTEK_TILT_MIN (-128)
  205. #define AIPTEK_TILT_MAX 127
  206. #define AIPTEK_TILT_DISABLE (-10101)
  207. /* Wheel values
  208. */
  209. #define AIPTEK_WHEEL_MIN 0
  210. #define AIPTEK_WHEEL_MAX 1024
  211. #define AIPTEK_WHEEL_DISABLE (-10101)
  212. /* ToolCode values, which BTW are 0x140 .. 0x14f
  213. * We have things set up such that if TOOL_BUTTON_FIRED_BIT is
  214. * not set, we'll send one instance of AIPTEK_TOOL_BUTTON_xxx.
  215. *
  216. * Whenever the user resets the value, TOOL_BUTTON_FIRED_BIT will
  217. * get reset.
  218. */
  219. #define TOOL_BUTTON(x) ((x) & 0x14f)
  220. #define TOOL_BUTTON_FIRED(x) ((x) & 0x200)
  221. #define TOOL_BUTTON_FIRED_BIT 0x200
  222. /* toolMode codes
  223. */
  224. #define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
  225. #define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
  226. #define AIPTEK_TOOL_BUTTON_PENCIL_MODE BTN_TOOL_PENCIL
  227. #define AIPTEK_TOOL_BUTTON_BRUSH_MODE BTN_TOOL_BRUSH
  228. #define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE BTN_TOOL_AIRBRUSH
  229. #define AIPTEK_TOOL_BUTTON_ERASER_MODE BTN_TOOL_RUBBER
  230. #define AIPTEK_TOOL_BUTTON_MOUSE_MODE BTN_TOOL_MOUSE
  231. #define AIPTEK_TOOL_BUTTON_LENS_MODE BTN_TOOL_LENS
  232. /* Diagnostic message codes
  233. */
  234. #define AIPTEK_DIAGNOSTIC_NA 0
  235. #define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE 1
  236. #define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
  237. #define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
  238. /* Time to wait (in ms) to help mask hand jittering
  239. * when pressing the stylus buttons.
  240. */
  241. #define AIPTEK_JITTER_DELAY_DEFAULT 50
  242. /* Time to wait (in ms) in-between sending the tablet
  243. * a command and beginning the process of reading the return
  244. * sequence from the tablet.
  245. */
  246. #define AIPTEK_PROGRAMMABLE_DELAY_25 25
  247. #define AIPTEK_PROGRAMMABLE_DELAY_50 50
  248. #define AIPTEK_PROGRAMMABLE_DELAY_100 100
  249. #define AIPTEK_PROGRAMMABLE_DELAY_200 200
  250. #define AIPTEK_PROGRAMMABLE_DELAY_300 300
  251. #define AIPTEK_PROGRAMMABLE_DELAY_400 400
  252. #define AIPTEK_PROGRAMMABLE_DELAY_DEFAULT AIPTEK_PROGRAMMABLE_DELAY_400
  253. /* Mouse button programming
  254. */
  255. #define AIPTEK_MOUSE_LEFT_BUTTON 0x01
  256. #define AIPTEK_MOUSE_RIGHT_BUTTON 0x02
  257. #define AIPTEK_MOUSE_MIDDLE_BUTTON 0x04
  258. /* Stylus button programming
  259. */
  260. #define AIPTEK_STYLUS_LOWER_BUTTON 0x08
  261. #define AIPTEK_STYLUS_UPPER_BUTTON 0x10
  262. /* Length of incoming packet from the tablet
  263. */
  264. #define AIPTEK_PACKET_LENGTH 8
  265. /* We report in EV_MISC both the proximity and
  266. * whether the report came from the stylus, tablet mouse
  267. * or "unknown" -- Unknown when the tablet is in relative
  268. * mode, because we only get report 1's.
  269. */
  270. #define AIPTEK_REPORT_TOOL_UNKNOWN 0x10
  271. #define AIPTEK_REPORT_TOOL_STYLUS 0x20
  272. #define AIPTEK_REPORT_TOOL_MOUSE 0x40
  273. static int programmableDelay = AIPTEK_PROGRAMMABLE_DELAY_DEFAULT;
  274. static int jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
  275. struct aiptek_features {
  276. int odmCode; /* Tablet manufacturer code */
  277. int modelCode; /* Tablet model code (not unique) */
  278. int firmwareCode; /* prom/eeprom version */
  279. char usbPath[64 + 1]; /* device's physical usb path */
  280. char inputPath[64 + 1]; /* input device path */
  281. };
  282. struct aiptek_settings {
  283. int pointerMode; /* stylus-, mouse-only or either */
  284. int coordinateMode; /* absolute/relative coords */
  285. int toolMode; /* pen, pencil, brush, etc. tool */
  286. int xTilt; /* synthetic xTilt amount */
  287. int yTilt; /* synthetic yTilt amount */
  288. int wheel; /* synthetic wheel amount */
  289. int stylusButtonUpper; /* stylus upper btn delivers... */
  290. int stylusButtonLower; /* stylus lower btn delivers... */
  291. int mouseButtonLeft; /* mouse left btn delivers... */
  292. int mouseButtonMiddle; /* mouse middle btn delivers... */
  293. int mouseButtonRight; /* mouse right btn delivers... */
  294. int programmableDelay; /* delay for tablet programming */
  295. int jitterDelay; /* delay for hand jittering */
  296. };
  297. struct aiptek {
  298. struct input_dev inputdev; /* input device struct */
  299. struct usb_device *usbdev; /* usb device struct */
  300. struct urb *urb; /* urb for incoming reports */
  301. dma_addr_t data_dma; /* our dma stuffage */
  302. struct aiptek_features features; /* tablet's array of features */
  303. struct aiptek_settings curSetting; /* tablet's current programmable */
  304. struct aiptek_settings newSetting; /* ... and new param settings */
  305. unsigned int ifnum; /* interface number for IO */
  306. int diagnostic; /* tablet diagnostic codes */
  307. unsigned long eventCount; /* event count */
  308. int inDelay; /* jitter: in jitter delay? */
  309. unsigned long endDelay; /* jitter: time when delay ends */
  310. int previousJitterable; /* jitterable prev value */
  311. unsigned char *data; /* incoming packet data */
  312. };
  313. /*
  314. * Permit easy lookup of keyboard events to send, versus
  315. * the bitmap which comes from the tablet. This hides the
  316. * issue that the F_keys are not sequentially numbered.
  317. */
  318. static int macroKeyEvents[] = {
  319. KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
  320. KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
  321. KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
  322. KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
  323. KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
  324. KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
  325. };
  326. /***********************************************************************
  327. * Relative reports deliver values in 2's complement format to
  328. * deal with negative offsets.
  329. */
  330. static int aiptek_convert_from_2s_complement(unsigned char c)
  331. {
  332. int ret;
  333. unsigned char b = c;
  334. int negate = 0;
  335. if ((b & 0x80) != 0) {
  336. b = ~b;
  337. b--;
  338. negate = 1;
  339. }
  340. ret = b;
  341. ret = (negate == 1) ? -ret : ret;
  342. return ret;
  343. }
  344. /***********************************************************************
  345. * aiptek_irq can receive one of six potential reports.
  346. * The documentation for each is in the body of the function.
  347. *
  348. * The tablet reports on several attributes per invocation of
  349. * aiptek_irq. Because the Linux Input Event system allows the
  350. * transmission of ONE attribute per input_report_xxx() call,
  351. * collation has to be done on the other end to reconstitute
  352. * a complete tablet report. Further, the number of Input Event reports
  353. * submitted varies, depending on what USB report type, and circumstance.
  354. * To deal with this, EV_MSC is used to indicate an 'end-of-report'
  355. * message. This has been an undocumented convention understood by the kernel
  356. * tablet driver and clients such as gpm and XFree86's tablet drivers.
  357. *
  358. * Of the information received from the tablet, the one piece I
  359. * cannot transmit is the proximity bit (without resorting to an EV_MSC
  360. * convention above.) I therefore have taken over REL_MISC and ABS_MISC
  361. * (for relative and absolute reports, respectively) for communicating
  362. * Proximity. Why two events? I thought it interesting to know if the
  363. * Proximity event occurred while the tablet was in absolute or relative
  364. * mode.
  365. *
  366. * Other tablets use the notion of a certain minimum stylus pressure
  367. * to infer proximity. While that could have been done, that is yet
  368. * another 'by convention' behavior, the documentation for which
  369. * would be spread between two (or more) pieces of software.
  370. *
  371. * EV_MSC usage was terminated for this purpose in Linux 2.5.x, and
  372. * replaced with the input_sync() method (which emits EV_SYN.)
  373. */
  374. static void aiptek_irq(struct urb *urb, struct pt_regs *regs)
  375. {
  376. struct aiptek *aiptek = urb->context;
  377. unsigned char *data = aiptek->data;
  378. struct input_dev *inputdev = &aiptek->inputdev;
  379. int jitterable = 0;
  380. int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
  381. switch (urb->status) {
  382. case 0:
  383. /* Success */
  384. break;
  385. case -ECONNRESET:
  386. case -ENOENT:
  387. case -ESHUTDOWN:
  388. /* This urb is terminated, clean up */
  389. dbg("%s - urb shutting down with status: %d",
  390. __FUNCTION__, urb->status);
  391. return;
  392. default:
  393. dbg("%s - nonzero urb status received: %d",
  394. __FUNCTION__, urb->status);
  395. goto exit;
  396. }
  397. /* See if we are in a delay loop -- throw out report if true.
  398. */
  399. if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
  400. goto exit;
  401. }
  402. aiptek->inDelay = 0;
  403. aiptek->eventCount++;
  404. /* Report 1 delivers relative coordinates with either a stylus
  405. * or the mouse. You do not know, however, which input
  406. * tool generated the event.
  407. */
  408. if (data[0] == 1) {
  409. if (aiptek->curSetting.coordinateMode ==
  410. AIPTEK_COORDINATE_ABSOLUTE_MODE) {
  411. aiptek->diagnostic =
  412. AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
  413. } else {
  414. input_regs(inputdev, regs);
  415. x = aiptek_convert_from_2s_complement(data[2]);
  416. y = aiptek_convert_from_2s_complement(data[3]);
  417. /* jitterable keeps track of whether any button has been pressed.
  418. * We're also using it to remap the physical mouse button mask
  419. * to pseudo-settings. (We don't specifically care about it's
  420. * value after moving/transposing mouse button bitmasks, except
  421. * that a non-zero value indicates that one or more
  422. * mouse button was pressed.)
  423. */
  424. jitterable = data[5] & 0x07;
  425. left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
  426. right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
  427. middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
  428. input_report_key(inputdev, BTN_LEFT, left);
  429. input_report_key(inputdev, BTN_MIDDLE, middle);
  430. input_report_key(inputdev, BTN_RIGHT, right);
  431. input_report_rel(inputdev, REL_X, x);
  432. input_report_rel(inputdev, REL_Y, y);
  433. input_report_rel(inputdev, REL_MISC, 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
  434. /* Wheel support is in the form of a single-event
  435. * firing.
  436. */
  437. if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
  438. input_report_rel(inputdev, REL_WHEEL,
  439. aiptek->curSetting.wheel);
  440. aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
  441. }
  442. input_sync(inputdev);
  443. }
  444. }
  445. /* Report 2 is delivered only by the stylus, and delivers
  446. * absolute coordinates.
  447. */
  448. else if (data[0] == 2) {
  449. if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
  450. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
  451. } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
  452. (aiptek->curSetting.pointerMode)) {
  453. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
  454. } else {
  455. input_regs(inputdev, regs);
  456. x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
  457. y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
  458. z = le16_to_cpu(get_unaligned((__le16 *) (data + 6)));
  459. p = (data[5] & 0x01) != 0 ? 1 : 0;
  460. dv = (data[5] & 0x02) != 0 ? 1 : 0;
  461. tip = (data[5] & 0x04) != 0 ? 1 : 0;
  462. /* Use jitterable to re-arrange button masks
  463. */
  464. jitterable = data[5] & 0x18;
  465. bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
  466. pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
  467. /* dv indicates 'data valid' (e.g., the tablet is in sync
  468. * and has delivered a "correct" report) We will ignore
  469. * all 'bad' reports...
  470. */
  471. if (dv != 0) {
  472. /* If we've not already sent a tool_button_?? code, do
  473. * so now. Then set FIRED_BIT so it won't be resent unless
  474. * the user forces FIRED_BIT off.
  475. */
  476. if (TOOL_BUTTON_FIRED
  477. (aiptek->curSetting.toolMode) == 0) {
  478. input_report_key(inputdev,
  479. TOOL_BUTTON(aiptek->curSetting.toolMode),
  480. 1);
  481. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  482. }
  483. if (p != 0) {
  484. input_report_abs(inputdev, ABS_X, x);
  485. input_report_abs(inputdev, ABS_Y, y);
  486. input_report_abs(inputdev, ABS_PRESSURE, z);
  487. input_report_key(inputdev, BTN_TOUCH, tip);
  488. input_report_key(inputdev, BTN_STYLUS, bs);
  489. input_report_key(inputdev, BTN_STYLUS2, pck);
  490. if (aiptek->curSetting.xTilt !=
  491. AIPTEK_TILT_DISABLE) {
  492. input_report_abs(inputdev,
  493. ABS_TILT_X,
  494. aiptek->curSetting.xTilt);
  495. }
  496. if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
  497. input_report_abs(inputdev,
  498. ABS_TILT_Y,
  499. aiptek->curSetting.yTilt);
  500. }
  501. /* Wheel support is in the form of a single-event
  502. * firing.
  503. */
  504. if (aiptek->curSetting.wheel !=
  505. AIPTEK_WHEEL_DISABLE) {
  506. input_report_abs(inputdev,
  507. ABS_WHEEL,
  508. aiptek->curSetting.wheel);
  509. aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
  510. }
  511. }
  512. input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
  513. input_sync(inputdev);
  514. }
  515. }
  516. }
  517. /* Report 3's come from the mouse in absolute mode.
  518. */
  519. else if (data[0] == 3) {
  520. if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
  521. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
  522. } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
  523. (aiptek->curSetting.pointerMode)) {
  524. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
  525. } else {
  526. input_regs(inputdev, regs);
  527. x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
  528. y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
  529. jitterable = data[5] & 0x1c;
  530. p = (data[5] & 0x01) != 0 ? 1 : 0;
  531. dv = (data[5] & 0x02) != 0 ? 1 : 0;
  532. left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
  533. right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
  534. middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
  535. if (dv != 0) {
  536. /* If we've not already sent a tool_button_?? code, do
  537. * so now. Then set FIRED_BIT so it won't be resent unless
  538. * the user forces FIRED_BIT off.
  539. */
  540. if (TOOL_BUTTON_FIRED
  541. (aiptek->curSetting.toolMode) == 0) {
  542. input_report_key(inputdev,
  543. TOOL_BUTTON(aiptek->curSetting.toolMode),
  544. 1);
  545. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  546. }
  547. if (p != 0) {
  548. input_report_abs(inputdev, ABS_X, x);
  549. input_report_abs(inputdev, ABS_Y, y);
  550. input_report_key(inputdev, BTN_LEFT, left);
  551. input_report_key(inputdev, BTN_MIDDLE, middle);
  552. input_report_key(inputdev, BTN_RIGHT, right);
  553. /* Wheel support is in the form of a single-event
  554. * firing.
  555. */
  556. if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
  557. input_report_abs(inputdev,
  558. ABS_WHEEL,
  559. aiptek->curSetting.wheel);
  560. aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
  561. }
  562. }
  563. input_report_rel(inputdev, REL_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
  564. input_sync(inputdev);
  565. }
  566. }
  567. }
  568. /* Report 4s come from the macro keys when pressed by stylus
  569. */
  570. else if (data[0] == 4) {
  571. jitterable = data[1] & 0x18;
  572. p = (data[1] & 0x01) != 0 ? 1 : 0;
  573. dv = (data[1] & 0x02) != 0 ? 1 : 0;
  574. tip = (data[1] & 0x04) != 0 ? 1 : 0;
  575. bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
  576. pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
  577. macro = data[3];
  578. z = le16_to_cpu(get_unaligned((__le16 *) (data + 4)));
  579. if (dv != 0) {
  580. input_regs(inputdev, regs);
  581. /* If we've not already sent a tool_button_?? code, do
  582. * so now. Then set FIRED_BIT so it won't be resent unless
  583. * the user forces FIRED_BIT off.
  584. */
  585. if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
  586. input_report_key(inputdev,
  587. TOOL_BUTTON(aiptek->curSetting.toolMode),
  588. 1);
  589. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  590. }
  591. if (p != 0) {
  592. input_report_key(inputdev, BTN_TOUCH, tip);
  593. input_report_key(inputdev, BTN_STYLUS, bs);
  594. input_report_key(inputdev, BTN_STYLUS2, pck);
  595. input_report_abs(inputdev, ABS_PRESSURE, z);
  596. }
  597. /* For safety, we're sending key 'break' codes for the
  598. * neighboring macro keys.
  599. */
  600. if (macro > 0) {
  601. input_report_key(inputdev,
  602. macroKeyEvents[macro - 1], 0);
  603. }
  604. if (macro < 25) {
  605. input_report_key(inputdev,
  606. macroKeyEvents[macro + 1], 0);
  607. }
  608. input_report_key(inputdev, macroKeyEvents[macro], p);
  609. input_report_abs(inputdev, ABS_MISC,
  610. p | AIPTEK_REPORT_TOOL_STYLUS);
  611. input_sync(inputdev);
  612. }
  613. }
  614. /* Report 5s come from the macro keys when pressed by mouse
  615. */
  616. else if (data[0] == 5) {
  617. jitterable = data[1] & 0x1c;
  618. p = (data[1] & 0x01) != 0 ? 1 : 0;
  619. dv = (data[1] & 0x02) != 0 ? 1 : 0;
  620. left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
  621. right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
  622. middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
  623. macro = data[3];
  624. if (dv != 0) {
  625. input_regs(inputdev, regs);
  626. /* If we've not already sent a tool_button_?? code, do
  627. * so now. Then set FIRED_BIT so it won't be resent unless
  628. * the user forces FIRED_BIT off.
  629. */
  630. if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
  631. input_report_key(inputdev,
  632. TOOL_BUTTON(aiptek->curSetting.toolMode),
  633. 1);
  634. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  635. }
  636. if (p != 0) {
  637. input_report_key(inputdev, BTN_LEFT, left);
  638. input_report_key(inputdev, BTN_MIDDLE, middle);
  639. input_report_key(inputdev, BTN_RIGHT, right);
  640. }
  641. /* For safety, we're sending key 'break' codes for the
  642. * neighboring macro keys.
  643. */
  644. if (macro > 0) {
  645. input_report_key(inputdev,
  646. macroKeyEvents[macro - 1], 0);
  647. }
  648. if (macro < 25) {
  649. input_report_key(inputdev,
  650. macroKeyEvents[macro + 1], 0);
  651. }
  652. input_report_key(inputdev, macroKeyEvents[macro], 1);
  653. input_report_rel(inputdev, ABS_MISC,
  654. p | AIPTEK_REPORT_TOOL_MOUSE);
  655. input_sync(inputdev);
  656. }
  657. }
  658. /* We have no idea which tool can generate a report 6. Theoretically,
  659. * neither need to, having been given reports 4 & 5 for such use.
  660. * However, report 6 is the 'official-looking' report for macroKeys;
  661. * reports 4 & 5 supposively are used to support unnamed, unknown
  662. * hat switches (which just so happen to be the macroKeys.)
  663. */
  664. else if (data[0] == 6) {
  665. macro = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
  666. input_regs(inputdev, regs);
  667. if (macro > 0) {
  668. input_report_key(inputdev, macroKeyEvents[macro - 1],
  669. 0);
  670. }
  671. if (macro < 25) {
  672. input_report_key(inputdev, macroKeyEvents[macro + 1],
  673. 0);
  674. }
  675. /* If we've not already sent a tool_button_?? code, do
  676. * so now. Then set FIRED_BIT so it won't be resent unless
  677. * the user forces FIRED_BIT off.
  678. */
  679. if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
  680. input_report_key(inputdev,
  681. TOOL_BUTTON(aiptek->curSetting.
  682. toolMode), 1);
  683. aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
  684. }
  685. input_report_key(inputdev, macroKeyEvents[macro], 1);
  686. input_report_abs(inputdev, ABS_MISC,
  687. 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
  688. input_sync(inputdev);
  689. } else {
  690. dbg("Unknown report %d", data[0]);
  691. }
  692. /* Jitter may occur when the user presses a button on the stlyus
  693. * or the mouse. What we do to prevent that is wait 'x' milliseconds
  694. * following a 'jitterable' event, which should give the hand some time
  695. * stabilize itself.
  696. *
  697. * We just introduced aiptek->previousJitterable to carry forth the
  698. * notion that jitter occurs when the button state changes from on to off:
  699. * a person drawing, holding a button down is not subject to jittering.
  700. * With that in mind, changing from upper button depressed to lower button
  701. * WILL transition through a jitter delay.
  702. */
  703. if (aiptek->previousJitterable != jitterable &&
  704. aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
  705. aiptek->endDelay = jiffies +
  706. ((aiptek->curSetting.jitterDelay * HZ) / 1000);
  707. aiptek->inDelay = 1;
  708. }
  709. aiptek->previousJitterable = jitterable;
  710. exit:
  711. retval = usb_submit_urb(urb, GFP_ATOMIC);
  712. if (retval != 0) {
  713. err("%s - usb_submit_urb failed with result %d",
  714. __FUNCTION__, retval);
  715. }
  716. }
  717. /***********************************************************************
  718. * These are the USB id's known so far. We do not identify them to
  719. * specific Aiptek model numbers, because there has been overlaps,
  720. * use, and reuse of id's in existing models. Certain models have
  721. * been known to use more than one ID, indicative perhaps of
  722. * manufacturing revisions. In any event, we consider these
  723. * IDs to not be model-specific nor unique.
  724. */
  725. static const struct usb_device_id aiptek_ids[] = {
  726. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
  727. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
  728. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
  729. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
  730. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
  731. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
  732. {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
  733. {}
  734. };
  735. MODULE_DEVICE_TABLE(usb, aiptek_ids);
  736. /***********************************************************************
  737. * Open an instance of the tablet driver.
  738. */
  739. static int aiptek_open(struct input_dev *inputdev)
  740. {
  741. struct aiptek *aiptek = inputdev->private;
  742. aiptek->urb->dev = aiptek->usbdev;
  743. if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
  744. return -EIO;
  745. return 0;
  746. }
  747. /***********************************************************************
  748. * Close an instance of the tablet driver.
  749. */
  750. static void aiptek_close(struct input_dev *inputdev)
  751. {
  752. struct aiptek *aiptek = inputdev->private;
  753. usb_kill_urb(aiptek->urb);
  754. }
  755. /***********************************************************************
  756. * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
  757. * where they were known as usb_set_report and usb_get_report.
  758. */
  759. static int
  760. aiptek_set_report(struct aiptek *aiptek,
  761. unsigned char report_type,
  762. unsigned char report_id, void *buffer, int size)
  763. {
  764. return usb_control_msg(aiptek->usbdev,
  765. usb_sndctrlpipe(aiptek->usbdev, 0),
  766. USB_REQ_SET_REPORT,
  767. USB_TYPE_CLASS | USB_RECIP_INTERFACE |
  768. USB_DIR_OUT, (report_type << 8) + report_id,
  769. aiptek->ifnum, buffer, size, 5000);
  770. }
  771. static int
  772. aiptek_get_report(struct aiptek *aiptek,
  773. unsigned char report_type,
  774. unsigned char report_id, void *buffer, int size)
  775. {
  776. return usb_control_msg(aiptek->usbdev,
  777. usb_rcvctrlpipe(aiptek->usbdev, 0),
  778. USB_REQ_GET_REPORT,
  779. USB_TYPE_CLASS | USB_RECIP_INTERFACE |
  780. USB_DIR_IN, (report_type << 8) + report_id,
  781. aiptek->ifnum, buffer, size, 5000);
  782. }
  783. /***********************************************************************
  784. * Send a command to the tablet.
  785. */
  786. static int
  787. aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
  788. {
  789. const int sizeof_buf = 3 * sizeof(u8);
  790. int ret;
  791. u8 *buf;
  792. buf = kmalloc(sizeof_buf, GFP_KERNEL);
  793. if (!buf)
  794. return -ENOMEM;
  795. buf[0] = 2;
  796. buf[1] = command;
  797. buf[2] = data;
  798. if ((ret =
  799. aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
  800. dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
  801. command, data);
  802. }
  803. kfree(buf);
  804. return ret < 0 ? ret : 0;
  805. }
  806. /***********************************************************************
  807. * Retrieve information from the tablet. Querying info is defined as first
  808. * sending the {command,data} sequence as a command, followed by a wait
  809. * (aka, "programmaticDelay") and then a "read" request.
  810. */
  811. static int
  812. aiptek_query(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 (aiptek_command(aiptek, command, data) != 0) {
  824. kfree(buf);
  825. return -EIO;
  826. }
  827. msleep(aiptek->curSetting.programmableDelay);
  828. if ((ret =
  829. aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
  830. dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
  831. buf[0], buf[1], buf[2]);
  832. ret = -EIO;
  833. } else {
  834. ret = le16_to_cpu(get_unaligned((__le16 *) (buf + 1)));
  835. }
  836. kfree(buf);
  837. return ret;
  838. }
  839. /***********************************************************************
  840. * Program the tablet into either absolute or relative mode.
  841. * We also get information about the tablet's size.
  842. */
  843. static int aiptek_program_tablet(struct aiptek *aiptek)
  844. {
  845. int ret;
  846. /* Execute Resolution500LPI */
  847. if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
  848. return ret;
  849. /* Query getModelCode */
  850. if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
  851. return ret;
  852. aiptek->features.modelCode = ret & 0xff;
  853. /* Query getODMCode */
  854. if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
  855. return ret;
  856. aiptek->features.odmCode = ret;
  857. /* Query getFirmwareCode */
  858. if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
  859. return ret;
  860. aiptek->features.firmwareCode = ret;
  861. /* Query getXextension */
  862. if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
  863. return ret;
  864. aiptek->inputdev.absmin[ABS_X] = 0;
  865. aiptek->inputdev.absmax[ABS_X] = ret - 1;
  866. /* Query getYextension */
  867. if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
  868. return ret;
  869. aiptek->inputdev.absmin[ABS_Y] = 0;
  870. aiptek->inputdev.absmax[ABS_Y] = ret - 1;
  871. /* Query getPressureLevels */
  872. if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
  873. return ret;
  874. aiptek->inputdev.absmin[ABS_PRESSURE] = 0;
  875. aiptek->inputdev.absmax[ABS_PRESSURE] = ret - 1;
  876. /* Depending on whether we are in absolute or relative mode, we will
  877. * do a switchToTablet(absolute) or switchToMouse(relative) command.
  878. */
  879. if (aiptek->curSetting.coordinateMode ==
  880. AIPTEK_COORDINATE_ABSOLUTE_MODE) {
  881. /* Execute switchToTablet */
  882. if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
  883. return ret;
  884. }
  885. } else {
  886. /* Execute switchToMouse */
  887. if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
  888. return ret;
  889. }
  890. }
  891. /* Enable the macro keys */
  892. if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
  893. return ret;
  894. #if 0
  895. /* Execute FilterOn */
  896. if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
  897. return ret;
  898. #endif
  899. /* Execute AutoGainOn */
  900. if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
  901. return ret;
  902. /* Reset the eventCount, so we track events from last (re)programming
  903. */
  904. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
  905. aiptek->eventCount = 0;
  906. return 0;
  907. }
  908. /***********************************************************************
  909. * Sysfs functions. Sysfs prefers that individually-tunable parameters
  910. * exist in their separate pseudo-files. Summary data that is immutable
  911. * may exist in a singular file so long as you don't define a writeable
  912. * interface.
  913. */
  914. /***********************************************************************
  915. * support the 'size' file -- display support
  916. */
  917. static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
  918. {
  919. struct aiptek *aiptek = dev_get_drvdata(dev);
  920. if (aiptek == NULL)
  921. return 0;
  922. return snprintf(buf, PAGE_SIZE, "%dx%d\n",
  923. aiptek->inputdev.absmax[ABS_X] + 1,
  924. aiptek->inputdev.absmax[ABS_Y] + 1);
  925. }
  926. /* These structs define the sysfs files, param #1 is the name of the
  927. * file, param 2 is the file permissions, param 3 & 4 are to the
  928. * output generator and input parser routines. Absence of a routine is
  929. * permitted -- it only means can't either 'cat' the file, or send data
  930. * to it.
  931. */
  932. static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
  933. /***********************************************************************
  934. * support routines for the 'product_id' file
  935. */
  936. static ssize_t show_tabletProductId(struct device *dev, struct device_attribute *attr, char *buf)
  937. {
  938. struct aiptek *aiptek = dev_get_drvdata(dev);
  939. if (aiptek == NULL)
  940. return 0;
  941. return snprintf(buf, PAGE_SIZE, "0x%04x\n",
  942. aiptek->inputdev.id.product);
  943. }
  944. static DEVICE_ATTR(product_id, S_IRUGO, show_tabletProductId, NULL);
  945. /***********************************************************************
  946. * support routines for the 'vendor_id' file
  947. */
  948. static ssize_t show_tabletVendorId(struct device *dev, struct device_attribute *attr, char *buf)
  949. {
  950. struct aiptek *aiptek = dev_get_drvdata(dev);
  951. if (aiptek == NULL)
  952. return 0;
  953. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev.id.vendor);
  954. }
  955. static DEVICE_ATTR(vendor_id, S_IRUGO, show_tabletVendorId, NULL);
  956. /***********************************************************************
  957. * support routines for the 'vendor' file
  958. */
  959. static ssize_t show_tabletManufacturer(struct device *dev, struct device_attribute *attr, char *buf)
  960. {
  961. struct aiptek *aiptek = dev_get_drvdata(dev);
  962. int retval;
  963. if (aiptek == NULL)
  964. return 0;
  965. retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->usbdev->manufacturer);
  966. return retval;
  967. }
  968. static DEVICE_ATTR(vendor, S_IRUGO, show_tabletManufacturer, NULL);
  969. /***********************************************************************
  970. * support routines for the 'product' file
  971. */
  972. static ssize_t show_tabletProduct(struct device *dev, struct device_attribute *attr, char *buf)
  973. {
  974. struct aiptek *aiptek = dev_get_drvdata(dev);
  975. int retval;
  976. if (aiptek == NULL)
  977. return 0;
  978. retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->usbdev->product);
  979. return retval;
  980. }
  981. static DEVICE_ATTR(product, S_IRUGO, show_tabletProduct, NULL);
  982. /***********************************************************************
  983. * support routines for the 'pointer_mode' file. Note that this file
  984. * both displays current setting and allows reprogramming.
  985. */
  986. static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
  987. {
  988. struct aiptek *aiptek = dev_get_drvdata(dev);
  989. char *s;
  990. if (aiptek == NULL)
  991. return 0;
  992. switch (aiptek->curSetting.pointerMode) {
  993. case AIPTEK_POINTER_ONLY_STYLUS_MODE:
  994. s = "stylus";
  995. break;
  996. case AIPTEK_POINTER_ONLY_MOUSE_MODE:
  997. s = "mouse";
  998. break;
  999. case AIPTEK_POINTER_EITHER_MODE:
  1000. s = "either";
  1001. break;
  1002. default:
  1003. s = "unknown";
  1004. break;
  1005. }
  1006. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1007. }
  1008. static ssize_t
  1009. store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1010. {
  1011. struct aiptek *aiptek = dev_get_drvdata(dev);
  1012. if (aiptek == NULL)
  1013. return 0;
  1014. if (strcmp(buf, "stylus") == 0) {
  1015. aiptek->newSetting.pointerMode =
  1016. AIPTEK_POINTER_ONLY_STYLUS_MODE;
  1017. } else if (strcmp(buf, "mouse") == 0) {
  1018. aiptek->newSetting.pointerMode = AIPTEK_POINTER_ONLY_MOUSE_MODE;
  1019. } else if (strcmp(buf, "either") == 0) {
  1020. aiptek->newSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
  1021. }
  1022. return count;
  1023. }
  1024. static DEVICE_ATTR(pointer_mode,
  1025. S_IRUGO | S_IWUGO,
  1026. show_tabletPointerMode, store_tabletPointerMode);
  1027. /***********************************************************************
  1028. * support routines for the 'coordinate_mode' file. Note that this file
  1029. * both displays current setting and allows reprogramming.
  1030. */
  1031. static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
  1032. {
  1033. struct aiptek *aiptek = dev_get_drvdata(dev);
  1034. char *s;
  1035. if (aiptek == NULL)
  1036. return 0;
  1037. switch (aiptek->curSetting.coordinateMode) {
  1038. case AIPTEK_COORDINATE_ABSOLUTE_MODE:
  1039. s = "absolute";
  1040. break;
  1041. case AIPTEK_COORDINATE_RELATIVE_MODE:
  1042. s = "relative";
  1043. break;
  1044. default:
  1045. s = "unknown";
  1046. break;
  1047. }
  1048. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1049. }
  1050. static ssize_t
  1051. store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1052. {
  1053. struct aiptek *aiptek = dev_get_drvdata(dev);
  1054. if (aiptek == NULL)
  1055. return 0;
  1056. if (strcmp(buf, "absolute") == 0) {
  1057. aiptek->newSetting.pointerMode =
  1058. AIPTEK_COORDINATE_ABSOLUTE_MODE;
  1059. } else if (strcmp(buf, "relative") == 0) {
  1060. aiptek->newSetting.pointerMode =
  1061. AIPTEK_COORDINATE_RELATIVE_MODE;
  1062. }
  1063. return count;
  1064. }
  1065. static DEVICE_ATTR(coordinate_mode,
  1066. S_IRUGO | S_IWUGO,
  1067. show_tabletCoordinateMode, store_tabletCoordinateMode);
  1068. /***********************************************************************
  1069. * support routines for the 'tool_mode' file. Note that this file
  1070. * both displays current setting and allows reprogramming.
  1071. */
  1072. static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
  1073. {
  1074. struct aiptek *aiptek = dev_get_drvdata(dev);
  1075. char *s;
  1076. if (aiptek == NULL)
  1077. return 0;
  1078. switch (TOOL_BUTTON(aiptek->curSetting.toolMode)) {
  1079. case AIPTEK_TOOL_BUTTON_MOUSE_MODE:
  1080. s = "mouse";
  1081. break;
  1082. case AIPTEK_TOOL_BUTTON_ERASER_MODE:
  1083. s = "eraser";
  1084. break;
  1085. case AIPTEK_TOOL_BUTTON_PENCIL_MODE:
  1086. s = "pencil";
  1087. break;
  1088. case AIPTEK_TOOL_BUTTON_PEN_MODE:
  1089. s = "pen";
  1090. break;
  1091. case AIPTEK_TOOL_BUTTON_BRUSH_MODE:
  1092. s = "brush";
  1093. break;
  1094. case AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE:
  1095. s = "airbrush";
  1096. break;
  1097. case AIPTEK_TOOL_BUTTON_LENS_MODE:
  1098. s = "lens";
  1099. break;
  1100. default:
  1101. s = "unknown";
  1102. break;
  1103. }
  1104. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1105. }
  1106. static ssize_t
  1107. store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1108. {
  1109. struct aiptek *aiptek = dev_get_drvdata(dev);
  1110. if (aiptek == NULL)
  1111. return 0;
  1112. if (strcmp(buf, "mouse") == 0) {
  1113. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_MOUSE_MODE;
  1114. } else if (strcmp(buf, "eraser") == 0) {
  1115. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_ERASER_MODE;
  1116. } else if (strcmp(buf, "pencil") == 0) {
  1117. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PENCIL_MODE;
  1118. } else if (strcmp(buf, "pen") == 0) {
  1119. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
  1120. } else if (strcmp(buf, "brush") == 0) {
  1121. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_BRUSH_MODE;
  1122. } else if (strcmp(buf, "airbrush") == 0) {
  1123. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE;
  1124. } else if (strcmp(buf, "lens") == 0) {
  1125. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_LENS_MODE;
  1126. }
  1127. return count;
  1128. }
  1129. static DEVICE_ATTR(tool_mode,
  1130. S_IRUGO | S_IWUGO,
  1131. show_tabletToolMode, store_tabletToolMode);
  1132. /***********************************************************************
  1133. * support routines for the 'xtilt' file. Note that this file
  1134. * both displays current setting and allows reprogramming.
  1135. */
  1136. static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
  1137. {
  1138. struct aiptek *aiptek = dev_get_drvdata(dev);
  1139. if (aiptek == NULL)
  1140. return 0;
  1141. if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
  1142. return snprintf(buf, PAGE_SIZE, "disable\n");
  1143. } else {
  1144. return snprintf(buf, PAGE_SIZE, "%d\n",
  1145. aiptek->curSetting.xTilt);
  1146. }
  1147. }
  1148. static ssize_t
  1149. store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1150. {
  1151. struct aiptek *aiptek = dev_get_drvdata(dev);
  1152. int x;
  1153. if (aiptek == NULL)
  1154. return 0;
  1155. if (strcmp(buf, "disable") == 0) {
  1156. aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
  1157. } else {
  1158. x = (int)simple_strtol(buf, NULL, 10);
  1159. if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
  1160. aiptek->newSetting.xTilt = x;
  1161. }
  1162. }
  1163. return count;
  1164. }
  1165. static DEVICE_ATTR(xtilt,
  1166. S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
  1167. /***********************************************************************
  1168. * support routines for the 'ytilt' file. Note that this file
  1169. * both displays current setting and allows reprogramming.
  1170. */
  1171. static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
  1172. {
  1173. struct aiptek *aiptek = dev_get_drvdata(dev);
  1174. if (aiptek == NULL)
  1175. return 0;
  1176. if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
  1177. return snprintf(buf, PAGE_SIZE, "disable\n");
  1178. } else {
  1179. return snprintf(buf, PAGE_SIZE, "%d\n",
  1180. aiptek->curSetting.yTilt);
  1181. }
  1182. }
  1183. static ssize_t
  1184. store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1185. {
  1186. struct aiptek *aiptek = dev_get_drvdata(dev);
  1187. int y;
  1188. if (aiptek == NULL)
  1189. return 0;
  1190. if (strcmp(buf, "disable") == 0) {
  1191. aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
  1192. } else {
  1193. y = (int)simple_strtol(buf, NULL, 10);
  1194. if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
  1195. aiptek->newSetting.yTilt = y;
  1196. }
  1197. }
  1198. return count;
  1199. }
  1200. static DEVICE_ATTR(ytilt,
  1201. S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
  1202. /***********************************************************************
  1203. * support routines for the 'jitter' file. Note that this file
  1204. * both displays current setting and allows reprogramming.
  1205. */
  1206. static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
  1207. {
  1208. struct aiptek *aiptek = dev_get_drvdata(dev);
  1209. if (aiptek == NULL)
  1210. return 0;
  1211. return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
  1212. }
  1213. static ssize_t
  1214. store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1215. {
  1216. struct aiptek *aiptek = dev_get_drvdata(dev);
  1217. if (aiptek == NULL)
  1218. return 0;
  1219. aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
  1220. return count;
  1221. }
  1222. static DEVICE_ATTR(jitter,
  1223. S_IRUGO | S_IWUGO,
  1224. show_tabletJitterDelay, store_tabletJitterDelay);
  1225. /***********************************************************************
  1226. * support routines for the 'delay' file. Note that this file
  1227. * both displays current setting and allows reprogramming.
  1228. */
  1229. static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
  1230. {
  1231. struct aiptek *aiptek = dev_get_drvdata(dev);
  1232. if (aiptek == NULL)
  1233. return 0;
  1234. return snprintf(buf, PAGE_SIZE, "%d\n",
  1235. aiptek->curSetting.programmableDelay);
  1236. }
  1237. static ssize_t
  1238. store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1239. {
  1240. struct aiptek *aiptek = dev_get_drvdata(dev);
  1241. if (aiptek == NULL)
  1242. return 0;
  1243. aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
  1244. return count;
  1245. }
  1246. static DEVICE_ATTR(delay,
  1247. S_IRUGO | S_IWUGO,
  1248. show_tabletProgrammableDelay, store_tabletProgrammableDelay);
  1249. /***********************************************************************
  1250. * support routines for the 'input_path' file. Note that this file
  1251. * only displays current setting.
  1252. */
  1253. static ssize_t show_tabletInputDevice(struct device *dev, struct device_attribute *attr, char *buf)
  1254. {
  1255. struct aiptek *aiptek = dev_get_drvdata(dev);
  1256. if (aiptek == NULL)
  1257. return 0;
  1258. return snprintf(buf, PAGE_SIZE, "/dev/input/%s\n",
  1259. aiptek->features.inputPath);
  1260. }
  1261. static DEVICE_ATTR(input_path, S_IRUGO, show_tabletInputDevice, NULL);
  1262. /***********************************************************************
  1263. * support routines for the 'event_count' file. Note that this file
  1264. * only displays current setting.
  1265. */
  1266. static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
  1267. {
  1268. struct aiptek *aiptek = dev_get_drvdata(dev);
  1269. if (aiptek == NULL)
  1270. return 0;
  1271. return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
  1272. }
  1273. static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
  1274. /***********************************************************************
  1275. * support routines for the 'diagnostic' file. Note that this file
  1276. * only displays current setting.
  1277. */
  1278. static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
  1279. {
  1280. struct aiptek *aiptek = dev_get_drvdata(dev);
  1281. char *retMsg;
  1282. if (aiptek == NULL)
  1283. return 0;
  1284. switch (aiptek->diagnostic) {
  1285. case AIPTEK_DIAGNOSTIC_NA:
  1286. retMsg = "no errors\n";
  1287. break;
  1288. case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
  1289. retMsg = "Error: receiving relative reports\n";
  1290. break;
  1291. case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
  1292. retMsg = "Error: receiving absolute reports\n";
  1293. break;
  1294. case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
  1295. if (aiptek->curSetting.pointerMode ==
  1296. AIPTEK_POINTER_ONLY_MOUSE_MODE) {
  1297. retMsg = "Error: receiving stylus reports\n";
  1298. } else {
  1299. retMsg = "Error: receiving mouse reports\n";
  1300. }
  1301. break;
  1302. default:
  1303. return 0;
  1304. }
  1305. return snprintf(buf, PAGE_SIZE, retMsg);
  1306. }
  1307. static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
  1308. /***********************************************************************
  1309. * support routines for the 'stylus_upper' file. Note that this file
  1310. * both displays current setting and allows for setting changing.
  1311. */
  1312. static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
  1313. {
  1314. struct aiptek *aiptek = dev_get_drvdata(dev);
  1315. char *s;
  1316. if (aiptek == NULL)
  1317. return 0;
  1318. switch (aiptek->curSetting.stylusButtonUpper) {
  1319. case AIPTEK_STYLUS_UPPER_BUTTON:
  1320. s = "upper";
  1321. break;
  1322. case AIPTEK_STYLUS_LOWER_BUTTON:
  1323. s = "lower";
  1324. break;
  1325. default:
  1326. s = "unknown";
  1327. break;
  1328. }
  1329. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1330. }
  1331. static ssize_t
  1332. store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1333. {
  1334. struct aiptek *aiptek = dev_get_drvdata(dev);
  1335. if (aiptek == NULL)
  1336. return 0;
  1337. if (strcmp(buf, "upper") == 0) {
  1338. aiptek->newSetting.stylusButtonUpper =
  1339. AIPTEK_STYLUS_UPPER_BUTTON;
  1340. } else if (strcmp(buf, "lower") == 0) {
  1341. aiptek->newSetting.stylusButtonUpper =
  1342. AIPTEK_STYLUS_LOWER_BUTTON;
  1343. }
  1344. return count;
  1345. }
  1346. static DEVICE_ATTR(stylus_upper,
  1347. S_IRUGO | S_IWUGO,
  1348. show_tabletStylusUpper, store_tabletStylusUpper);
  1349. /***********************************************************************
  1350. * support routines for the 'stylus_lower' file. Note that this file
  1351. * both displays current setting and allows for setting changing.
  1352. */
  1353. static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
  1354. {
  1355. struct aiptek *aiptek = dev_get_drvdata(dev);
  1356. char *s;
  1357. if (aiptek == NULL)
  1358. return 0;
  1359. switch (aiptek->curSetting.stylusButtonLower) {
  1360. case AIPTEK_STYLUS_UPPER_BUTTON:
  1361. s = "upper";
  1362. break;
  1363. case AIPTEK_STYLUS_LOWER_BUTTON:
  1364. s = "lower";
  1365. break;
  1366. default:
  1367. s = "unknown";
  1368. break;
  1369. }
  1370. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1371. }
  1372. static ssize_t
  1373. store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1374. {
  1375. struct aiptek *aiptek = dev_get_drvdata(dev);
  1376. if (aiptek == NULL)
  1377. return 0;
  1378. if (strcmp(buf, "upper") == 0) {
  1379. aiptek->newSetting.stylusButtonLower =
  1380. AIPTEK_STYLUS_UPPER_BUTTON;
  1381. } else if (strcmp(buf, "lower") == 0) {
  1382. aiptek->newSetting.stylusButtonLower =
  1383. AIPTEK_STYLUS_LOWER_BUTTON;
  1384. }
  1385. return count;
  1386. }
  1387. static DEVICE_ATTR(stylus_lower,
  1388. S_IRUGO | S_IWUGO,
  1389. show_tabletStylusLower, store_tabletStylusLower);
  1390. /***********************************************************************
  1391. * support routines for the 'mouse_left' file. Note that this file
  1392. * both displays current setting and allows for setting changing.
  1393. */
  1394. static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
  1395. {
  1396. struct aiptek *aiptek = dev_get_drvdata(dev);
  1397. char *s;
  1398. if (aiptek == NULL)
  1399. return 0;
  1400. switch (aiptek->curSetting.mouseButtonLeft) {
  1401. case AIPTEK_MOUSE_LEFT_BUTTON:
  1402. s = "left";
  1403. break;
  1404. case AIPTEK_MOUSE_MIDDLE_BUTTON:
  1405. s = "middle";
  1406. break;
  1407. case AIPTEK_MOUSE_RIGHT_BUTTON:
  1408. s = "right";
  1409. break;
  1410. default:
  1411. s = "unknown";
  1412. break;
  1413. }
  1414. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1415. }
  1416. static ssize_t
  1417. store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1418. {
  1419. struct aiptek *aiptek = dev_get_drvdata(dev);
  1420. if (aiptek == NULL)
  1421. return 0;
  1422. if (strcmp(buf, "left") == 0) {
  1423. aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
  1424. } else if (strcmp(buf, "middle") == 0) {
  1425. aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_MIDDLE_BUTTON;
  1426. } else if (strcmp(buf, "right") == 0) {
  1427. aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_RIGHT_BUTTON;
  1428. }
  1429. return count;
  1430. }
  1431. static DEVICE_ATTR(mouse_left,
  1432. S_IRUGO | S_IWUGO,
  1433. show_tabletMouseLeft, store_tabletMouseLeft);
  1434. /***********************************************************************
  1435. * support routines for the 'mouse_middle' file. Note that this file
  1436. * both displays current setting and allows for setting changing.
  1437. */
  1438. static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
  1439. {
  1440. struct aiptek *aiptek = dev_get_drvdata(dev);
  1441. char *s;
  1442. if (aiptek == NULL)
  1443. return 0;
  1444. switch (aiptek->curSetting.mouseButtonMiddle) {
  1445. case AIPTEK_MOUSE_LEFT_BUTTON:
  1446. s = "left";
  1447. break;
  1448. case AIPTEK_MOUSE_MIDDLE_BUTTON:
  1449. s = "middle";
  1450. break;
  1451. case AIPTEK_MOUSE_RIGHT_BUTTON:
  1452. s = "right";
  1453. break;
  1454. default:
  1455. s = "unknown";
  1456. break;
  1457. }
  1458. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1459. }
  1460. static ssize_t
  1461. store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1462. {
  1463. struct aiptek *aiptek = dev_get_drvdata(dev);
  1464. if (aiptek == NULL)
  1465. return 0;
  1466. if (strcmp(buf, "left") == 0) {
  1467. aiptek->newSetting.mouseButtonMiddle = AIPTEK_MOUSE_LEFT_BUTTON;
  1468. } else if (strcmp(buf, "middle") == 0) {
  1469. aiptek->newSetting.mouseButtonMiddle =
  1470. AIPTEK_MOUSE_MIDDLE_BUTTON;
  1471. } else if (strcmp(buf, "right") == 0) {
  1472. aiptek->newSetting.mouseButtonMiddle =
  1473. AIPTEK_MOUSE_RIGHT_BUTTON;
  1474. }
  1475. return count;
  1476. }
  1477. static DEVICE_ATTR(mouse_middle,
  1478. S_IRUGO | S_IWUGO,
  1479. show_tabletMouseMiddle, store_tabletMouseMiddle);
  1480. /***********************************************************************
  1481. * support routines for the 'mouse_right' file. Note that this file
  1482. * both displays current setting and allows for setting changing.
  1483. */
  1484. static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
  1485. {
  1486. struct aiptek *aiptek = dev_get_drvdata(dev);
  1487. char *s;
  1488. if (aiptek == NULL)
  1489. return 0;
  1490. switch (aiptek->curSetting.mouseButtonRight) {
  1491. case AIPTEK_MOUSE_LEFT_BUTTON:
  1492. s = "left";
  1493. break;
  1494. case AIPTEK_MOUSE_MIDDLE_BUTTON:
  1495. s = "middle";
  1496. break;
  1497. case AIPTEK_MOUSE_RIGHT_BUTTON:
  1498. s = "right";
  1499. break;
  1500. default:
  1501. s = "unknown";
  1502. break;
  1503. }
  1504. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1505. }
  1506. static ssize_t
  1507. store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1508. {
  1509. struct aiptek *aiptek = dev_get_drvdata(dev);
  1510. if (aiptek == NULL)
  1511. return 0;
  1512. if (strcmp(buf, "left") == 0) {
  1513. aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_LEFT_BUTTON;
  1514. } else if (strcmp(buf, "middle") == 0) {
  1515. aiptek->newSetting.mouseButtonRight =
  1516. AIPTEK_MOUSE_MIDDLE_BUTTON;
  1517. } else if (strcmp(buf, "right") == 0) {
  1518. aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
  1519. }
  1520. return count;
  1521. }
  1522. static DEVICE_ATTR(mouse_right,
  1523. S_IRUGO | S_IWUGO,
  1524. show_tabletMouseRight, store_tabletMouseRight);
  1525. /***********************************************************************
  1526. * support routines for the 'wheel' file. Note that this file
  1527. * both displays current setting and allows for setting changing.
  1528. */
  1529. static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
  1530. {
  1531. struct aiptek *aiptek = dev_get_drvdata(dev);
  1532. if (aiptek == NULL)
  1533. return 0;
  1534. if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
  1535. return snprintf(buf, PAGE_SIZE, "disable\n");
  1536. } else {
  1537. return snprintf(buf, PAGE_SIZE, "%d\n",
  1538. aiptek->curSetting.wheel);
  1539. }
  1540. }
  1541. static ssize_t
  1542. store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1543. {
  1544. struct aiptek *aiptek = dev_get_drvdata(dev);
  1545. if (aiptek == NULL)
  1546. return 0;
  1547. aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
  1548. return count;
  1549. }
  1550. static DEVICE_ATTR(wheel,
  1551. S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
  1552. /***********************************************************************
  1553. * support routines for the 'execute' file. Note that this file
  1554. * both displays current setting and allows for setting changing.
  1555. */
  1556. static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
  1557. {
  1558. struct aiptek *aiptek = dev_get_drvdata(dev);
  1559. if (aiptek == NULL)
  1560. return 0;
  1561. /* There is nothing useful to display, so a one-line manual
  1562. * is in order...
  1563. */
  1564. return snprintf(buf, PAGE_SIZE,
  1565. "Write anything to this file to program your tablet.\n");
  1566. }
  1567. static ssize_t
  1568. store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1569. {
  1570. struct aiptek *aiptek = dev_get_drvdata(dev);
  1571. if (aiptek == NULL)
  1572. return 0;
  1573. /* We do not care what you write to this file. Merely the action
  1574. * of writing to this file triggers a tablet reprogramming.
  1575. */
  1576. memcpy(&aiptek->curSetting, &aiptek->newSetting,
  1577. sizeof(struct aiptek_settings));
  1578. if (aiptek_program_tablet(aiptek) < 0)
  1579. return -EIO;
  1580. return count;
  1581. }
  1582. static DEVICE_ATTR(execute,
  1583. S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
  1584. /***********************************************************************
  1585. * support routines for the 'odm_code' file. Note that this file
  1586. * only displays current setting.
  1587. */
  1588. static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
  1589. {
  1590. struct aiptek *aiptek = dev_get_drvdata(dev);
  1591. if (aiptek == NULL)
  1592. return 0;
  1593. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
  1594. }
  1595. static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
  1596. /***********************************************************************
  1597. * support routines for the 'model_code' file. Note that this file
  1598. * only displays current setting.
  1599. */
  1600. static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
  1601. {
  1602. struct aiptek *aiptek = dev_get_drvdata(dev);
  1603. if (aiptek == NULL)
  1604. return 0;
  1605. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
  1606. }
  1607. static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
  1608. /***********************************************************************
  1609. * support routines for the 'firmware_code' file. Note that this file
  1610. * only displays current setting.
  1611. */
  1612. static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
  1613. {
  1614. struct aiptek *aiptek = dev_get_drvdata(dev);
  1615. if (aiptek == NULL)
  1616. return 0;
  1617. return snprintf(buf, PAGE_SIZE, "%04x\n",
  1618. aiptek->features.firmwareCode);
  1619. }
  1620. static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
  1621. /***********************************************************************
  1622. * This routine removes all existing sysfs files managed by this device
  1623. * driver.
  1624. */
  1625. static void aiptek_delete_files(struct device *dev)
  1626. {
  1627. device_remove_file(dev, &dev_attr_size);
  1628. device_remove_file(dev, &dev_attr_product_id);
  1629. device_remove_file(dev, &dev_attr_vendor_id);
  1630. device_remove_file(dev, &dev_attr_vendor);
  1631. device_remove_file(dev, &dev_attr_product);
  1632. device_remove_file(dev, &dev_attr_pointer_mode);
  1633. device_remove_file(dev, &dev_attr_coordinate_mode);
  1634. device_remove_file(dev, &dev_attr_tool_mode);
  1635. device_remove_file(dev, &dev_attr_xtilt);
  1636. device_remove_file(dev, &dev_attr_ytilt);
  1637. device_remove_file(dev, &dev_attr_jitter);
  1638. device_remove_file(dev, &dev_attr_delay);
  1639. device_remove_file(dev, &dev_attr_input_path);
  1640. device_remove_file(dev, &dev_attr_event_count);
  1641. device_remove_file(dev, &dev_attr_diagnostic);
  1642. device_remove_file(dev, &dev_attr_odm_code);
  1643. device_remove_file(dev, &dev_attr_model_code);
  1644. device_remove_file(dev, &dev_attr_firmware_code);
  1645. device_remove_file(dev, &dev_attr_stylus_lower);
  1646. device_remove_file(dev, &dev_attr_stylus_upper);
  1647. device_remove_file(dev, &dev_attr_mouse_left);
  1648. device_remove_file(dev, &dev_attr_mouse_middle);
  1649. device_remove_file(dev, &dev_attr_mouse_right);
  1650. device_remove_file(dev, &dev_attr_wheel);
  1651. device_remove_file(dev, &dev_attr_execute);
  1652. }
  1653. /***********************************************************************
  1654. * This routine creates the sysfs files managed by this device
  1655. * driver.
  1656. */
  1657. static int aiptek_add_files(struct device *dev)
  1658. {
  1659. int ret;
  1660. if ((ret = device_create_file(dev, &dev_attr_size)) ||
  1661. (ret = device_create_file(dev, &dev_attr_product_id)) ||
  1662. (ret = device_create_file(dev, &dev_attr_vendor_id)) ||
  1663. (ret = device_create_file(dev, &dev_attr_vendor)) ||
  1664. (ret = device_create_file(dev, &dev_attr_product)) ||
  1665. (ret = device_create_file(dev, &dev_attr_pointer_mode)) ||
  1666. (ret = device_create_file(dev, &dev_attr_coordinate_mode)) ||
  1667. (ret = device_create_file(dev, &dev_attr_tool_mode)) ||
  1668. (ret = device_create_file(dev, &dev_attr_xtilt)) ||
  1669. (ret = device_create_file(dev, &dev_attr_ytilt)) ||
  1670. (ret = device_create_file(dev, &dev_attr_jitter)) ||
  1671. (ret = device_create_file(dev, &dev_attr_delay)) ||
  1672. (ret = device_create_file(dev, &dev_attr_input_path)) ||
  1673. (ret = device_create_file(dev, &dev_attr_event_count)) ||
  1674. (ret = device_create_file(dev, &dev_attr_diagnostic)) ||
  1675. (ret = device_create_file(dev, &dev_attr_odm_code)) ||
  1676. (ret = device_create_file(dev, &dev_attr_model_code)) ||
  1677. (ret = device_create_file(dev, &dev_attr_firmware_code)) ||
  1678. (ret = device_create_file(dev, &dev_attr_stylus_lower)) ||
  1679. (ret = device_create_file(dev, &dev_attr_stylus_upper)) ||
  1680. (ret = device_create_file(dev, &dev_attr_mouse_left)) ||
  1681. (ret = device_create_file(dev, &dev_attr_mouse_middle)) ||
  1682. (ret = device_create_file(dev, &dev_attr_mouse_right)) ||
  1683. (ret = device_create_file(dev, &dev_attr_wheel)) ||
  1684. (ret = device_create_file(dev, &dev_attr_execute))) {
  1685. err("aiptek: killing own sysfs device files\n");
  1686. aiptek_delete_files(dev);
  1687. }
  1688. return ret;
  1689. }
  1690. /***********************************************************************
  1691. * This routine is called when a tablet has been identified. It basically
  1692. * sets up the tablet and the driver's internal structures.
  1693. */
  1694. static int
  1695. aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1696. {
  1697. struct usb_device *usbdev = interface_to_usbdev(intf);
  1698. struct usb_endpoint_descriptor *endpoint;
  1699. struct aiptek *aiptek;
  1700. struct input_dev *inputdev;
  1701. struct input_handle *inputhandle;
  1702. struct list_head *node, *next;
  1703. char path[64 + 1];
  1704. int i;
  1705. int speeds[] = { 0,
  1706. AIPTEK_PROGRAMMABLE_DELAY_50,
  1707. AIPTEK_PROGRAMMABLE_DELAY_400,
  1708. AIPTEK_PROGRAMMABLE_DELAY_25,
  1709. AIPTEK_PROGRAMMABLE_DELAY_100,
  1710. AIPTEK_PROGRAMMABLE_DELAY_200,
  1711. AIPTEK_PROGRAMMABLE_DELAY_300
  1712. };
  1713. /* programmableDelay is where the command-line specified
  1714. * delay is kept. We make it the first element of speeds[],
  1715. * so therefore, your override speed is tried first, then the
  1716. * remainder. Note that the default value of 400ms will be tried
  1717. * if you do not specify any command line parameter.
  1718. */
  1719. speeds[0] = programmableDelay;
  1720. if ((aiptek = kmalloc(sizeof(struct aiptek), GFP_KERNEL)) == NULL)
  1721. return -ENOMEM;
  1722. memset(aiptek, 0, sizeof(struct aiptek));
  1723. aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
  1724. SLAB_ATOMIC, &aiptek->data_dma);
  1725. if (aiptek->data == NULL) {
  1726. kfree(aiptek);
  1727. return -ENOMEM;
  1728. }
  1729. aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
  1730. if (aiptek->urb == NULL) {
  1731. usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
  1732. aiptek->data_dma);
  1733. kfree(aiptek);
  1734. return -ENOMEM;
  1735. }
  1736. /* Set up the curSettings struct. Said struct contains the current
  1737. * programmable parameters. The newSetting struct contains changes
  1738. * the user makes to the settings via the sysfs interface. Those
  1739. * changes are not "committed" to curSettings until the user
  1740. * writes to the sysfs/.../execute file.
  1741. */
  1742. aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
  1743. aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
  1744. aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
  1745. aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
  1746. aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
  1747. aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
  1748. aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
  1749. aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
  1750. aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
  1751. aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
  1752. aiptek->curSetting.jitterDelay = jitterDelay;
  1753. aiptek->curSetting.programmableDelay = programmableDelay;
  1754. /* Both structs should have equivalent settings
  1755. */
  1756. memcpy(&aiptek->newSetting, &aiptek->curSetting,
  1757. sizeof(struct aiptek_settings));
  1758. /* Now program the capacities of the tablet, in terms of being
  1759. * an input device.
  1760. */
  1761. aiptek->inputdev.evbit[0] |= BIT(EV_KEY)
  1762. | BIT(EV_ABS)
  1763. | BIT(EV_REL)
  1764. | BIT(EV_MSC);
  1765. aiptek->inputdev.absbit[0] |=
  1766. (BIT(ABS_X) |
  1767. BIT(ABS_Y) |
  1768. BIT(ABS_PRESSURE) |
  1769. BIT(ABS_TILT_X) |
  1770. BIT(ABS_TILT_Y) | BIT(ABS_WHEEL) | BIT(ABS_MISC));
  1771. aiptek->inputdev.relbit[0] |=
  1772. (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC));
  1773. aiptek->inputdev.keybit[LONG(BTN_LEFT)] |=
  1774. (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE));
  1775. aiptek->inputdev.keybit[LONG(BTN_DIGI)] |=
  1776. (BIT(BTN_TOOL_PEN) |
  1777. BIT(BTN_TOOL_RUBBER) |
  1778. BIT(BTN_TOOL_PENCIL) |
  1779. BIT(BTN_TOOL_AIRBRUSH) |
  1780. BIT(BTN_TOOL_BRUSH) |
  1781. BIT(BTN_TOOL_MOUSE) |
  1782. BIT(BTN_TOOL_LENS) |
  1783. BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2));
  1784. aiptek->inputdev.mscbit[0] = BIT(MSC_SERIAL);
  1785. /* Programming the tablet macro keys needs to be done with a for loop
  1786. * as the keycodes are discontiguous.
  1787. */
  1788. for (i = 0; i < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i)
  1789. set_bit(macroKeyEvents[i], aiptek->inputdev.keybit);
  1790. /* Set up client data, pointers to open and close routines
  1791. * for the input device.
  1792. */
  1793. aiptek->inputdev.private = aiptek;
  1794. aiptek->inputdev.open = aiptek_open;
  1795. aiptek->inputdev.close = aiptek_close;
  1796. /* Determine the usb devices' physical path.
  1797. * Asketh not why we always pretend we're using "../input0",
  1798. * but I suspect this will have to be refactored one
  1799. * day if a single USB device can be a keyboard & a mouse
  1800. * & a tablet, and the inputX number actually will tell
  1801. * us something...
  1802. */
  1803. if (usb_make_path(usbdev, path, 64) > 0)
  1804. sprintf(aiptek->features.usbPath, "%s/input0", path);
  1805. /* Program the input device coordinate capacities. We do not yet
  1806. * know what maximum X, Y, and Z values are, so we're putting fake
  1807. * values in. Later, we'll ask the tablet to put in the correct
  1808. * values.
  1809. */
  1810. aiptek->inputdev.absmin[ABS_X] = 0;
  1811. aiptek->inputdev.absmax[ABS_X] = 2999;
  1812. aiptek->inputdev.absmin[ABS_Y] = 0;
  1813. aiptek->inputdev.absmax[ABS_Y] = 2249;
  1814. aiptek->inputdev.absmin[ABS_PRESSURE] = 0;
  1815. aiptek->inputdev.absmax[ABS_PRESSURE] = 511;
  1816. aiptek->inputdev.absmin[ABS_TILT_X] = AIPTEK_TILT_MIN;
  1817. aiptek->inputdev.absmax[ABS_TILT_X] = AIPTEK_TILT_MAX;
  1818. aiptek->inputdev.absmin[ABS_TILT_Y] = AIPTEK_TILT_MIN;
  1819. aiptek->inputdev.absmax[ABS_TILT_Y] = AIPTEK_TILT_MAX;
  1820. aiptek->inputdev.absmin[ABS_WHEEL] = AIPTEK_WHEEL_MIN;
  1821. aiptek->inputdev.absmax[ABS_WHEEL] = AIPTEK_WHEEL_MAX - 1;
  1822. aiptek->inputdev.absfuzz[ABS_X] = 0;
  1823. aiptek->inputdev.absfuzz[ABS_Y] = 0;
  1824. aiptek->inputdev.absfuzz[ABS_PRESSURE] = 0;
  1825. aiptek->inputdev.absfuzz[ABS_TILT_X] = 0;
  1826. aiptek->inputdev.absfuzz[ABS_TILT_Y] = 0;
  1827. aiptek->inputdev.absfuzz[ABS_WHEEL] = 0;
  1828. aiptek->inputdev.absflat[ABS_X] = 0;
  1829. aiptek->inputdev.absflat[ABS_Y] = 0;
  1830. aiptek->inputdev.absflat[ABS_PRESSURE] = 0;
  1831. aiptek->inputdev.absflat[ABS_TILT_X] = 0;
  1832. aiptek->inputdev.absflat[ABS_TILT_Y] = 0;
  1833. aiptek->inputdev.absflat[ABS_WHEEL] = 0;
  1834. aiptek->inputdev.name = "Aiptek";
  1835. aiptek->inputdev.phys = aiptek->features.usbPath;
  1836. aiptek->inputdev.id.bustype = BUS_USB;
  1837. aiptek->inputdev.id.vendor = le16_to_cpu(usbdev->descriptor.idVendor);
  1838. aiptek->inputdev.id.product = le16_to_cpu(usbdev->descriptor.idProduct);
  1839. aiptek->inputdev.id.version = le16_to_cpu(usbdev->descriptor.bcdDevice);
  1840. aiptek->inputdev.dev = &intf->dev;
  1841. aiptek->usbdev = usbdev;
  1842. aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
  1843. aiptek->inDelay = 0;
  1844. aiptek->endDelay = 0;
  1845. aiptek->previousJitterable = 0;
  1846. endpoint = &intf->altsetting[0].endpoint[0].desc;
  1847. /* Go set up our URB, which is called when the tablet receives
  1848. * input.
  1849. */
  1850. usb_fill_int_urb(aiptek->urb,
  1851. aiptek->usbdev,
  1852. usb_rcvintpipe(aiptek->usbdev,
  1853. endpoint->bEndpointAddress),
  1854. aiptek->data, 8, aiptek_irq, aiptek,
  1855. endpoint->bInterval);
  1856. aiptek->urb->transfer_dma = aiptek->data_dma;
  1857. aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1858. /* Register the tablet as an Input Device
  1859. */
  1860. input_register_device(&aiptek->inputdev);
  1861. /* We now will look for the evdev device which is mapped to
  1862. * the tablet. The partial name is kept in the link list of
  1863. * input_handles associated with this input device.
  1864. * What identifies an evdev input_handler is that it begins
  1865. * with 'event', continues with a digit, and that in turn
  1866. * is mapped to /{devfs}/input/eventN.
  1867. */
  1868. inputdev = &aiptek->inputdev;
  1869. list_for_each_safe(node, next, &inputdev->h_list) {
  1870. inputhandle = to_handle(node);
  1871. if (strncmp(inputhandle->name, "event", 5) == 0) {
  1872. strcpy(aiptek->features.inputPath, inputhandle->name);
  1873. break;
  1874. }
  1875. }
  1876. info("input: Aiptek on %s (%s)\n", path, aiptek->features.inputPath);
  1877. /* Program the tablet. This sets the tablet up in the mode
  1878. * specified in newSetting, and also queries the tablet's
  1879. * physical capacities.
  1880. *
  1881. * Sanity check: if a tablet doesn't like the slow programmatic
  1882. * delay, we often get sizes of 0x0. Let's use that as an indicator
  1883. * to try faster delays, up to 25 ms. If that logic fails, well, you'll
  1884. * have to explain to us how your tablet thinks it's 0x0, and yet that's
  1885. * not an error :-)
  1886. */
  1887. for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) {
  1888. aiptek->curSetting.programmableDelay = speeds[i];
  1889. (void)aiptek_program_tablet(aiptek);
  1890. if (aiptek->inputdev.absmax[ABS_X] > 0) {
  1891. info("input: Aiptek using %d ms programming speed\n",
  1892. aiptek->curSetting.programmableDelay);
  1893. break;
  1894. }
  1895. }
  1896. /* Associate this driver's struct with the usb interface.
  1897. */
  1898. usb_set_intfdata(intf, aiptek);
  1899. /* Set up the sysfs files
  1900. */
  1901. aiptek_add_files(&intf->dev);
  1902. /* Make sure the evdev module is loaded. Assuming evdev IS a module :-)
  1903. */
  1904. if (request_module("evdev") != 0)
  1905. info("aiptek: error loading 'evdev' module");
  1906. return 0;
  1907. }
  1908. /* Forward declaration */
  1909. static void aiptek_disconnect(struct usb_interface *intf);
  1910. static struct usb_driver aiptek_driver = {
  1911. .owner = THIS_MODULE,
  1912. .name = "aiptek",
  1913. .probe = aiptek_probe,
  1914. .disconnect = aiptek_disconnect,
  1915. .id_table = aiptek_ids,
  1916. };
  1917. /***********************************************************************
  1918. * Deal with tablet disconnecting from the system.
  1919. */
  1920. static void aiptek_disconnect(struct usb_interface *intf)
  1921. {
  1922. struct aiptek *aiptek = usb_get_intfdata(intf);
  1923. /* Disassociate driver's struct with usb interface
  1924. */
  1925. usb_set_intfdata(intf, NULL);
  1926. if (aiptek != NULL) {
  1927. /* Free & unhook everything from the system.
  1928. */
  1929. usb_kill_urb(aiptek->urb);
  1930. input_unregister_device(&aiptek->inputdev);
  1931. aiptek_delete_files(&intf->dev);
  1932. usb_free_urb(aiptek->urb);
  1933. usb_buffer_free(interface_to_usbdev(intf),
  1934. AIPTEK_PACKET_LENGTH,
  1935. aiptek->data, aiptek->data_dma);
  1936. kfree(aiptek);
  1937. }
  1938. }
  1939. static int __init aiptek_init(void)
  1940. {
  1941. int result = usb_register(&aiptek_driver);
  1942. if (result == 0) {
  1943. info(DRIVER_VERSION ": " DRIVER_AUTHOR);
  1944. info(DRIVER_DESC);
  1945. }
  1946. return result;
  1947. }
  1948. static void __exit aiptek_exit(void)
  1949. {
  1950. usb_deregister(&aiptek_driver);
  1951. }
  1952. MODULE_AUTHOR(DRIVER_AUTHOR);
  1953. MODULE_DESCRIPTION(DRIVER_DESC);
  1954. MODULE_LICENSE("GPL");
  1955. module_param(programmableDelay, int, 0);
  1956. MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
  1957. module_param(jitterDelay, int, 0);
  1958. MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
  1959. module_init(aiptek_init);
  1960. module_exit(aiptek_exit);