aiptek.c 69 KB

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