aiptek.c 70 KB

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