aiptek.c 69 KB

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