aiptek.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. /*
  2. * Native support for the Aiptek HyperPen USB Tablets
  3. * (4000U/5000U/6000U/8000U/12000U)
  4. *
  5. * Copyright (c) 2001 Chris Atenasio <chris@crud.net>
  6. * Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net>
  7. *
  8. * based on wacom.c by
  9. * Vojtech Pavlik <vojtech@suse.cz>
  10. * Andreas Bach Aaen <abach@stofanet.dk>
  11. * Clifford Wolf <clifford@clifford.at>
  12. * Sam Mosel <sam.mosel@computer.org>
  13. * James E. Blair <corvus@gnu.org>
  14. * Daniel Egger <egger@suse.de>
  15. *
  16. * Many thanks to Oliver Kuechemann for his support.
  17. *
  18. * ChangeLog:
  19. * v0.1 - Initial release
  20. * v0.2 - Hack to get around fake event 28's. (Bryan W. Headley)
  21. * v0.3 - Make URB dynamic (Bryan W. Headley, Jun-8-2002)
  22. * Released to Linux 2.4.19 and 2.5.x
  23. * v0.4 - Rewrote substantial portions of the code to deal with
  24. * corrected control sequences, timing, dynamic configuration,
  25. * support of 6000U - 12000U, procfs, and macro key support
  26. * (Jan-1-2003 - Feb-5-2003, Bryan W. Headley)
  27. * v1.0 - Added support for diagnostic messages, count of messages
  28. * received from URB - Mar-8-2003, Bryan W. Headley
  29. * v1.1 - added support for tablet resolution, changed DV and proximity
  30. * some corrections - Jun-22-2003, martin schneebacher
  31. * - Added support for the sysfs interface, deprecating the
  32. * procfs interface for 2.5.x kernel. Also added support for
  33. * Wheel command. Bryan W. Headley July-15-2003.
  34. * v1.2 - Reworked jitter timer as a kernel thread.
  35. * Bryan W. Headley November-28-2003/Jan-10-2004.
  36. * v1.3 - Repaired issue of kernel thread going nuts on single-processor
  37. * machines, introduced programmableDelay as a command line
  38. * parameter. Feb 7 2004, Bryan W. Headley.
  39. * v1.4 - Re-wire jitter so it does not require a thread. Courtesy of
  40. * Rene van Paassen. Added reporting of physical pointer device
  41. * (e.g., stylus, mouse in reports 2, 3, 4, 5. We don't know
  42. * for reports 1, 6.)
  43. * what physical device reports for reports 1, 6.) Also enabled
  44. * MOUSE and LENS tool button modes. Renamed "rubber" to "eraser".
  45. * Feb 20, 2004, Bryan W. Headley.
  46. * v1.5 - Added previousJitterable, so we don't do jitter delay when the
  47. * user is holding a button down for periods of time.
  48. *
  49. * NOTE:
  50. * This kernel driver is augmented by the "Aiptek" XFree86 input
  51. * driver for your X server, as well as the Gaiptek GUI Front-end
  52. * "Tablet Manager".
  53. * These three products are highly interactive with one another,
  54. * so therefore it's easier to document them all as one subsystem.
  55. * Please visit the project's "home page", located at,
  56. * http://aiptektablet.sourceforge.net.
  57. *
  58. * This program is free software; you can redistribute it and/or modify
  59. * it under the terms of the GNU General Public License as published by
  60. * the Free Software Foundation; either version 2 of the License, or
  61. * (at your option) any later version.
  62. *
  63. * This program is distributed in the hope that it will be useful,
  64. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  66. * GNU General Public License for more details.
  67. *
  68. * You should have received a copy of the GNU General Public License
  69. * along with this program; if not, write to the Free Software
  70. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  71. */
  72. #include <linux/jiffies.h>
  73. #include <linux/kernel.h>
  74. #include <linux/slab.h>
  75. #include <linux/input.h>
  76. #include <linux/module.h>
  77. #include <linux/init.h>
  78. #include <linux/usb.h>
  79. #include <linux/sched.h>
  80. #include <asm/uaccess.h>
  81. #include <asm/unaligned.h>
  82. /*
  83. * Version Information
  84. */
  85. #define DRIVER_VERSION "v1.5 (May-15-2004)"
  86. #define DRIVER_AUTHOR "Bryan W. Headley/Chris Atenasio"
  87. #define DRIVER_DESC "Aiptek HyperPen USB Tablet Driver (Linux 2.6.x)"
  88. /*
  89. * Aiptek status packet:
  90. *
  91. * (returned as Report 1 - relative coordinates from mouse and stylus)
  92. *
  93. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  94. * byte0 0 0 0 0 0 0 0 1
  95. * byte1 0 0 0 0 0 BS2 BS Tip
  96. * byte2 X7 X6 X5 X4 X3 X2 X1 X0
  97. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  98. *
  99. * (returned as Report 2 - absolute coordinates from the stylus)
  100. *
  101. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  102. * byte0 0 0 0 0 0 0 1 0
  103. * byte1 X7 X6 X5 X4 X3 X2 X1 X0
  104. * byte2 X15 X14 X13 X12 X11 X10 X9 X8
  105. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  106. * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
  107. * byte5 * * * BS2 BS1 Tip IR DV
  108. * byte6 P7 P6 P5 P4 P3 P2 P1 P0
  109. * byte7 P15 P14 P13 P12 P11 P10 P9 P8
  110. *
  111. * (returned as Report 3 - absolute coordinates from the mouse)
  112. *
  113. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  114. * byte0 0 0 0 0 0 0 1 0
  115. * byte1 X7 X6 X5 X4 X3 X2 X1 X0
  116. * byte2 X15 X14 X13 X12 X11 X10 X9 X8
  117. * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  118. * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
  119. * byte5 * * * BS2 BS1 Tip IR DV
  120. * byte6 P7 P6 P5 P4 P3 P2 P1 P0
  121. * byte7 P15 P14 P13 P12 P11 P10 P9 P8
  122. *
  123. * (returned as Report 4 - macrokeys from the stylus)
  124. *
  125. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  126. * byte0 0 0 0 0 0 1 0 0
  127. * byte1 0 0 0 BS2 BS Tip IR DV
  128. * byte2 0 0 0 0 0 0 1 0
  129. * byte3 0 0 0 K4 K3 K2 K1 K0
  130. * byte4 P7 P6 P5 P4 P3 P2 P1 P0
  131. * byte5 P15 P14 P13 P12 P11 P10 P9 P8
  132. *
  133. * (returned as Report 5 - macrokeys from the mouse)
  134. *
  135. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
  136. * byte0 0 0 0 0 0 1 0 0
  137. * byte1 0 0 0 BS2 BS Tip IR DV
  138. * byte2 0 0 0 0 0 0 1 0
  139. * byte3 0 0 0 K4 K3 K2 K1 K0
  140. * byte4 P7 P6 P5 P4 P3 P2 P1 P0
  141. * byte5 P15 P14 P13 P12 P11 P10 P9 P8
  142. *
  143. * IR: In Range = Proximity on
  144. * DV = Data Valid
  145. * BS = Barrel Switch (as in, macro keys)
  146. * BS2 also referred to as Tablet Pick
  147. *
  148. * Command Summary:
  149. *
  150. * Use report_type CONTROL (3)
  151. * Use report_id 2
  152. *
  153. * Command/Data Description Return Bytes Return Value
  154. * 0x10/0x00 SwitchToMouse 0
  155. * 0x10/0x01 SwitchToTablet 0
  156. * 0x18/0x04 SetResolution 0
  157. * 0x12/0xFF AutoGainOn 0
  158. * 0x17/0x00 FilterOn 0
  159. * 0x01/0x00 GetXExtension 2 MaxX
  160. * 0x01/0x01 GetYExtension 2 MaxY
  161. * 0x02/0x00 GetModelCode 2 ModelCode = LOBYTE
  162. * 0x03/0x00 GetODMCode 2 ODMCode
  163. * 0x08/0x00 GetPressureLevels 2 =512
  164. * 0x04/0x00 GetFirmwareVersion 2 Firmware Version
  165. * 0x11/0x02 EnableMacroKeys 0
  166. *
  167. * To initialize the tablet:
  168. *
  169. * (1) Send Resolution500LPI (Command)
  170. * (2) Query for Model code (Option Report)
  171. * (3) Query for ODM code (Option Report)
  172. * (4) Query for firmware (Option Report)
  173. * (5) Query for GetXExtension (Option Report)
  174. * (6) Query for GetYExtension (Option Report)
  175. * (7) Query for GetPressureLevels (Option Report)
  176. * (8) SwitchToTablet for Absolute coordinates, or
  177. * SwitchToMouse for Relative coordinates (Command)
  178. * (9) EnableMacroKeys (Command)
  179. * (10) FilterOn (Command)
  180. * (11) AutoGainOn (Command)
  181. *
  182. * (Step 9 can be omitted, but you'll then have no function keys.)
  183. */
  184. #define USB_VENDOR_ID_AIPTEK 0x08ca
  185. #define USB_REQ_GET_REPORT 0x01
  186. #define USB_REQ_SET_REPORT 0x09
  187. /* PointerMode codes
  188. */
  189. #define AIPTEK_POINTER_ONLY_MOUSE_MODE 0
  190. #define AIPTEK_POINTER_ONLY_STYLUS_MODE 1
  191. #define AIPTEK_POINTER_EITHER_MODE 2
  192. #define AIPTEK_POINTER_ALLOW_MOUSE_MODE(a) \
  193. (a == AIPTEK_POINTER_ONLY_MOUSE_MODE || \
  194. a == AIPTEK_POINTER_EITHER_MODE)
  195. #define AIPTEK_POINTER_ALLOW_STYLUS_MODE(a) \
  196. (a == AIPTEK_POINTER_ONLY_STYLUS_MODE || \
  197. a == AIPTEK_POINTER_EITHER_MODE)
  198. /* CoordinateMode code
  199. */
  200. #define AIPTEK_COORDINATE_RELATIVE_MODE 0
  201. #define AIPTEK_COORDINATE_ABSOLUTE_MODE 1
  202. /* XTilt and YTilt values
  203. */
  204. #define AIPTEK_TILT_MIN (-128)
  205. #define AIPTEK_TILT_MAX 127
  206. #define AIPTEK_TILT_DISABLE (-10101)
  207. /* Wheel values
  208. */
  209. #define AIPTEK_WHEEL_MIN 0
  210. #define AIPTEK_WHEEL_MAX 1024
  211. #define AIPTEK_WHEEL_DISABLE (-10101)
  212. /* ToolCode values, which BTW are 0x140 .. 0x14f
  213. * We have things set up such that if TOOL_BUTTON_FIRED_BIT is
  214. * not set, we'll send one instance of AIPTEK_TOOL_BUTTON_xxx.
  215. *
  216. * Whenever the user resets the value, TOOL_BUTTON_FIRED_BIT will
  217. * get reset.
  218. */
  219. #define TOOL_BUTTON(x) ((x) & 0x14f)
  220. #define TOOL_BUTTON_FIRED(x) ((x) & 0x200)
  221. #define TOOL_BUTTON_FIRED_BIT 0x200
  222. /* toolMode codes
  223. */
  224. #define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
  225. #define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
  226. #define AIPTEK_TOOL_BUTTON_PENCIL_MODE BTN_TOOL_PENCIL
  227. #define AIPTEK_TOOL_BUTTON_BRUSH_MODE BTN_TOOL_BRUSH
  228. #define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE BTN_TOOL_AIRBRUSH
  229. #define AIPTEK_TOOL_BUTTON_ERASER_MODE BTN_TOOL_RUBBER
  230. #define AIPTEK_TOOL_BUTTON_MOUSE_MODE BTN_TOOL_MOUSE
  231. #define AIPTEK_TOOL_BUTTON_LENS_MODE BTN_TOOL_LENS
  232. /* Diagnostic message codes
  233. */
  234. #define AIPTEK_DIAGNOSTIC_NA 0
  235. #define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE 1
  236. #define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
  237. #define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
  238. /* Time to wait (in ms) to help mask hand jittering
  239. * when pressing the stylus buttons.
  240. */
  241. #define AIPTEK_JITTER_DELAY_DEFAULT 50
  242. /* Time to wait (in ms) in-between sending the tablet
  243. * a command and beginning the process of reading the return
  244. * sequence from the tablet.
  245. */
  246. #define AIPTEK_PROGRAMMABLE_DELAY_25 25
  247. #define AIPTEK_PROGRAMMABLE_DELAY_50 50
  248. #define AIPTEK_PROGRAMMABLE_DELAY_100 100
  249. #define AIPTEK_PROGRAMMABLE_DELAY_200 200
  250. #define AIPTEK_PROGRAMMABLE_DELAY_300 300
  251. #define AIPTEK_PROGRAMMABLE_DELAY_400 400
  252. #define AIPTEK_PROGRAMMABLE_DELAY_DEFAULT AIPTEK_PROGRAMMABLE_DELAY_400
  253. /* Mouse button programming
  254. */
  255. #define AIPTEK_MOUSE_LEFT_BUTTON 0x01
  256. #define AIPTEK_MOUSE_RIGHT_BUTTON 0x02
  257. #define AIPTEK_MOUSE_MIDDLE_BUTTON 0x04
  258. /* Stylus button programming
  259. */
  260. #define AIPTEK_STYLUS_LOWER_BUTTON 0x08
  261. #define AIPTEK_STYLUS_UPPER_BUTTON 0x10
  262. /* Length of incoming packet from the tablet
  263. */
  264. #define AIPTEK_PACKET_LENGTH 8
  265. /* We report in EV_MISC both the proximity and
  266. * whether the report came from the stylus, tablet mouse
  267. * or "unknown" -- Unknown when the tablet is in relative
  268. * mode, because we only get report 1's.
  269. */
  270. #define AIPTEK_REPORT_TOOL_UNKNOWN 0x10
  271. #define AIPTEK_REPORT_TOOL_STYLUS 0x20
  272. #define AIPTEK_REPORT_TOOL_MOUSE 0x40
  273. static int programmableDelay = AIPTEK_PROGRAMMABLE_DELAY_DEFAULT;
  274. static int jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
  275. struct aiptek_features {
  276. int odmCode; /* Tablet manufacturer code */
  277. int modelCode; /* Tablet model code (not unique) */
  278. int firmwareCode; /* prom/eeprom version */
  279. char usbPath[64 + 1]; /* device's physical usb path */
  280. char inputPath[64 + 1]; /* input device path */
  281. };
  282. struct aiptek_settings {
  283. int pointerMode; /* stylus-, mouse-only or either */
  284. int coordinateMode; /* absolute/relative coords */
  285. int toolMode; /* pen, pencil, brush, etc. tool */
  286. int xTilt; /* synthetic xTilt amount */
  287. int yTilt; /* synthetic yTilt amount */
  288. int wheel; /* synthetic wheel amount */
  289. int stylusButtonUpper; /* stylus upper btn delivers... */
  290. int stylusButtonLower; /* stylus lower btn delivers... */
  291. int mouseButtonLeft; /* mouse left btn delivers... */
  292. int mouseButtonMiddle; /* mouse middle btn delivers... */
  293. int mouseButtonRight; /* mouse right btn delivers... */
  294. int programmableDelay; /* delay for tablet programming */
  295. int jitterDelay; /* delay for hand jittering */
  296. };
  297. struct aiptek {
  298. struct input_dev inputdev; /* input device struct */
  299. struct usb_device *usbdev; /* usb device struct */
  300. struct urb *urb; /* urb for incoming reports */
  301. dma_addr_t data_dma; /* our dma stuffage */
  302. struct aiptek_features features; /* tablet's array of features */
  303. struct aiptek_settings curSetting; /* tablet's current programmable */
  304. struct aiptek_settings newSetting; /* ... and new param settings */
  305. unsigned int ifnum; /* interface number for IO */
  306. int openCount; /* module use counter */
  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. if (aiptek->openCount++ > 0) {
  744. return 0;
  745. }
  746. aiptek->urb->dev = aiptek->usbdev;
  747. if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0) {
  748. aiptek->openCount--;
  749. return -EIO;
  750. }
  751. return 0;
  752. }
  753. /***********************************************************************
  754. * Close an instance of the tablet driver.
  755. */
  756. static void aiptek_close(struct input_dev *inputdev)
  757. {
  758. struct aiptek *aiptek = inputdev->private;
  759. if (--aiptek->openCount == 0) {
  760. usb_kill_urb(aiptek->urb);
  761. }
  762. }
  763. /***********************************************************************
  764. * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
  765. * where they were known as usb_set_report and usb_get_report.
  766. */
  767. static int
  768. aiptek_set_report(struct aiptek *aiptek,
  769. unsigned char report_type,
  770. unsigned char report_id, void *buffer, int size)
  771. {
  772. return usb_control_msg(aiptek->usbdev,
  773. usb_sndctrlpipe(aiptek->usbdev, 0),
  774. USB_REQ_SET_REPORT,
  775. USB_TYPE_CLASS | USB_RECIP_INTERFACE |
  776. USB_DIR_OUT, (report_type << 8) + report_id,
  777. aiptek->ifnum, buffer, size, 5000);
  778. }
  779. static int
  780. aiptek_get_report(struct aiptek *aiptek,
  781. unsigned char report_type,
  782. unsigned char report_id, void *buffer, int size)
  783. {
  784. return usb_control_msg(aiptek->usbdev,
  785. usb_rcvctrlpipe(aiptek->usbdev, 0),
  786. USB_REQ_GET_REPORT,
  787. USB_TYPE_CLASS | USB_RECIP_INTERFACE |
  788. USB_DIR_IN, (report_type << 8) + report_id,
  789. aiptek->ifnum, buffer, size, 5000);
  790. }
  791. /***********************************************************************
  792. * Send a command to the tablet.
  793. */
  794. static int
  795. aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
  796. {
  797. const int sizeof_buf = 3 * sizeof(u8);
  798. int ret;
  799. u8 *buf;
  800. buf = kmalloc(sizeof_buf, GFP_KERNEL);
  801. if (!buf)
  802. return -ENOMEM;
  803. buf[0] = 2;
  804. buf[1] = command;
  805. buf[2] = data;
  806. if ((ret =
  807. aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
  808. dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
  809. command, data);
  810. }
  811. kfree(buf);
  812. return ret < 0 ? ret : 0;
  813. }
  814. /***********************************************************************
  815. * Retrieve information from the tablet. Querying info is defined as first
  816. * sending the {command,data} sequence as a command, followed by a wait
  817. * (aka, "programmaticDelay") and then a "read" request.
  818. */
  819. static int
  820. aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
  821. {
  822. const int sizeof_buf = 3 * sizeof(u8);
  823. int ret;
  824. u8 *buf;
  825. buf = kmalloc(sizeof_buf, GFP_KERNEL);
  826. if (!buf)
  827. return -ENOMEM;
  828. buf[0] = 2;
  829. buf[1] = command;
  830. buf[2] = data;
  831. if (aiptek_command(aiptek, command, data) != 0) {
  832. kfree(buf);
  833. return -EIO;
  834. }
  835. msleep(aiptek->curSetting.programmableDelay);
  836. if ((ret =
  837. aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
  838. dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
  839. buf[0], buf[1], buf[2]);
  840. ret = -EIO;
  841. } else {
  842. ret = le16_to_cpu(get_unaligned((__le16 *) (buf + 1)));
  843. }
  844. kfree(buf);
  845. return ret;
  846. }
  847. /***********************************************************************
  848. * Program the tablet into either absolute or relative mode.
  849. * We also get information about the tablet's size.
  850. */
  851. static int aiptek_program_tablet(struct aiptek *aiptek)
  852. {
  853. int ret;
  854. /* Execute Resolution500LPI */
  855. if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
  856. return ret;
  857. /* Query getModelCode */
  858. if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
  859. return ret;
  860. aiptek->features.modelCode = ret & 0xff;
  861. /* Query getODMCode */
  862. if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
  863. return ret;
  864. aiptek->features.odmCode = ret;
  865. /* Query getFirmwareCode */
  866. if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
  867. return ret;
  868. aiptek->features.firmwareCode = ret;
  869. /* Query getXextension */
  870. if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
  871. return ret;
  872. aiptek->inputdev.absmin[ABS_X] = 0;
  873. aiptek->inputdev.absmax[ABS_X] = ret - 1;
  874. /* Query getYextension */
  875. if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
  876. return ret;
  877. aiptek->inputdev.absmin[ABS_Y] = 0;
  878. aiptek->inputdev.absmax[ABS_Y] = ret - 1;
  879. /* Query getPressureLevels */
  880. if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
  881. return ret;
  882. aiptek->inputdev.absmin[ABS_PRESSURE] = 0;
  883. aiptek->inputdev.absmax[ABS_PRESSURE] = ret - 1;
  884. /* Depending on whether we are in absolute or relative mode, we will
  885. * do a switchToTablet(absolute) or switchToMouse(relative) command.
  886. */
  887. if (aiptek->curSetting.coordinateMode ==
  888. AIPTEK_COORDINATE_ABSOLUTE_MODE) {
  889. /* Execute switchToTablet */
  890. if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
  891. return ret;
  892. }
  893. } else {
  894. /* Execute switchToMouse */
  895. if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
  896. return ret;
  897. }
  898. }
  899. /* Enable the macro keys */
  900. if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
  901. return ret;
  902. #if 0
  903. /* Execute FilterOn */
  904. if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
  905. return ret;
  906. #endif
  907. /* Execute AutoGainOn */
  908. if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
  909. return ret;
  910. /* Reset the eventCount, so we track events from last (re)programming
  911. */
  912. aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
  913. aiptek->eventCount = 0;
  914. return 0;
  915. }
  916. /***********************************************************************
  917. * Sysfs functions. Sysfs prefers that individually-tunable parameters
  918. * exist in their separate pseudo-files. Summary data that is immutable
  919. * may exist in a singular file so long as you don't define a writeable
  920. * interface.
  921. */
  922. /***********************************************************************
  923. * support the 'size' file -- display support
  924. */
  925. static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
  926. {
  927. struct aiptek *aiptek = dev_get_drvdata(dev);
  928. if (aiptek == NULL)
  929. return 0;
  930. return snprintf(buf, PAGE_SIZE, "%dx%d\n",
  931. aiptek->inputdev.absmax[ABS_X] + 1,
  932. aiptek->inputdev.absmax[ABS_Y] + 1);
  933. }
  934. /* These structs define the sysfs files, param #1 is the name of the
  935. * file, param 2 is the file permissions, param 3 & 4 are to the
  936. * output generator and input parser routines. Absence of a routine is
  937. * permitted -- it only means can't either 'cat' the file, or send data
  938. * to it.
  939. */
  940. static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
  941. /***********************************************************************
  942. * support routines for the 'product_id' file
  943. */
  944. static ssize_t show_tabletProductId(struct device *dev, struct device_attribute *attr, char *buf)
  945. {
  946. struct aiptek *aiptek = dev_get_drvdata(dev);
  947. if (aiptek == NULL)
  948. return 0;
  949. return snprintf(buf, PAGE_SIZE, "0x%04x\n",
  950. aiptek->inputdev.id.product);
  951. }
  952. static DEVICE_ATTR(product_id, S_IRUGO, show_tabletProductId, NULL);
  953. /***********************************************************************
  954. * support routines for the 'vendor_id' file
  955. */
  956. static ssize_t show_tabletVendorId(struct device *dev, struct device_attribute *attr, char *buf)
  957. {
  958. struct aiptek *aiptek = dev_get_drvdata(dev);
  959. if (aiptek == NULL)
  960. return 0;
  961. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev.id.vendor);
  962. }
  963. static DEVICE_ATTR(vendor_id, S_IRUGO, show_tabletVendorId, NULL);
  964. /***********************************************************************
  965. * support routines for the 'vendor' file
  966. */
  967. static ssize_t show_tabletManufacturer(struct device *dev, struct device_attribute *attr, char *buf)
  968. {
  969. struct aiptek *aiptek = dev_get_drvdata(dev);
  970. int retval;
  971. if (aiptek == NULL)
  972. return 0;
  973. retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->usbdev->manufacturer);
  974. return retval;
  975. }
  976. static DEVICE_ATTR(vendor, S_IRUGO, show_tabletManufacturer, NULL);
  977. /***********************************************************************
  978. * support routines for the 'product' file
  979. */
  980. static ssize_t show_tabletProduct(struct device *dev, struct device_attribute *attr, char *buf)
  981. {
  982. struct aiptek *aiptek = dev_get_drvdata(dev);
  983. int retval;
  984. if (aiptek == NULL)
  985. return 0;
  986. retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->usbdev->product);
  987. return retval;
  988. }
  989. static DEVICE_ATTR(product, S_IRUGO, show_tabletProduct, NULL);
  990. /***********************************************************************
  991. * support routines for the 'pointer_mode' file. Note that this file
  992. * both displays current setting and allows reprogramming.
  993. */
  994. static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
  995. {
  996. struct aiptek *aiptek = dev_get_drvdata(dev);
  997. char *s;
  998. if (aiptek == NULL)
  999. return 0;
  1000. switch (aiptek->curSetting.pointerMode) {
  1001. case AIPTEK_POINTER_ONLY_STYLUS_MODE:
  1002. s = "stylus";
  1003. break;
  1004. case AIPTEK_POINTER_ONLY_MOUSE_MODE:
  1005. s = "mouse";
  1006. break;
  1007. case AIPTEK_POINTER_EITHER_MODE:
  1008. s = "either";
  1009. break;
  1010. default:
  1011. s = "unknown";
  1012. break;
  1013. }
  1014. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1015. }
  1016. static ssize_t
  1017. store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1018. {
  1019. struct aiptek *aiptek = dev_get_drvdata(dev);
  1020. if (aiptek == NULL)
  1021. return 0;
  1022. if (strcmp(buf, "stylus") == 0) {
  1023. aiptek->newSetting.pointerMode =
  1024. AIPTEK_POINTER_ONLY_STYLUS_MODE;
  1025. } else if (strcmp(buf, "mouse") == 0) {
  1026. aiptek->newSetting.pointerMode = AIPTEK_POINTER_ONLY_MOUSE_MODE;
  1027. } else if (strcmp(buf, "either") == 0) {
  1028. aiptek->newSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
  1029. }
  1030. return count;
  1031. }
  1032. static DEVICE_ATTR(pointer_mode,
  1033. S_IRUGO | S_IWUGO,
  1034. show_tabletPointerMode, store_tabletPointerMode);
  1035. /***********************************************************************
  1036. * support routines for the 'coordinate_mode' file. Note that this file
  1037. * both displays current setting and allows reprogramming.
  1038. */
  1039. static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
  1040. {
  1041. struct aiptek *aiptek = dev_get_drvdata(dev);
  1042. char *s;
  1043. if (aiptek == NULL)
  1044. return 0;
  1045. switch (aiptek->curSetting.coordinateMode) {
  1046. case AIPTEK_COORDINATE_ABSOLUTE_MODE:
  1047. s = "absolute";
  1048. break;
  1049. case AIPTEK_COORDINATE_RELATIVE_MODE:
  1050. s = "relative";
  1051. break;
  1052. default:
  1053. s = "unknown";
  1054. break;
  1055. }
  1056. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1057. }
  1058. static ssize_t
  1059. store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1060. {
  1061. struct aiptek *aiptek = dev_get_drvdata(dev);
  1062. if (aiptek == NULL)
  1063. return 0;
  1064. if (strcmp(buf, "absolute") == 0) {
  1065. aiptek->newSetting.pointerMode =
  1066. AIPTEK_COORDINATE_ABSOLUTE_MODE;
  1067. } else if (strcmp(buf, "relative") == 0) {
  1068. aiptek->newSetting.pointerMode =
  1069. AIPTEK_COORDINATE_RELATIVE_MODE;
  1070. }
  1071. return count;
  1072. }
  1073. static DEVICE_ATTR(coordinate_mode,
  1074. S_IRUGO | S_IWUGO,
  1075. show_tabletCoordinateMode, store_tabletCoordinateMode);
  1076. /***********************************************************************
  1077. * support routines for the 'tool_mode' file. Note that this file
  1078. * both displays current setting and allows reprogramming.
  1079. */
  1080. static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
  1081. {
  1082. struct aiptek *aiptek = dev_get_drvdata(dev);
  1083. char *s;
  1084. if (aiptek == NULL)
  1085. return 0;
  1086. switch (TOOL_BUTTON(aiptek->curSetting.toolMode)) {
  1087. case AIPTEK_TOOL_BUTTON_MOUSE_MODE:
  1088. s = "mouse";
  1089. break;
  1090. case AIPTEK_TOOL_BUTTON_ERASER_MODE:
  1091. s = "eraser";
  1092. break;
  1093. case AIPTEK_TOOL_BUTTON_PENCIL_MODE:
  1094. s = "pencil";
  1095. break;
  1096. case AIPTEK_TOOL_BUTTON_PEN_MODE:
  1097. s = "pen";
  1098. break;
  1099. case AIPTEK_TOOL_BUTTON_BRUSH_MODE:
  1100. s = "brush";
  1101. break;
  1102. case AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE:
  1103. s = "airbrush";
  1104. break;
  1105. case AIPTEK_TOOL_BUTTON_LENS_MODE:
  1106. s = "lens";
  1107. break;
  1108. default:
  1109. s = "unknown";
  1110. break;
  1111. }
  1112. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1113. }
  1114. static ssize_t
  1115. store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1116. {
  1117. struct aiptek *aiptek = dev_get_drvdata(dev);
  1118. if (aiptek == NULL)
  1119. return 0;
  1120. if (strcmp(buf, "mouse") == 0) {
  1121. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_MOUSE_MODE;
  1122. } else if (strcmp(buf, "eraser") == 0) {
  1123. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_ERASER_MODE;
  1124. } else if (strcmp(buf, "pencil") == 0) {
  1125. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PENCIL_MODE;
  1126. } else if (strcmp(buf, "pen") == 0) {
  1127. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
  1128. } else if (strcmp(buf, "brush") == 0) {
  1129. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_BRUSH_MODE;
  1130. } else if (strcmp(buf, "airbrush") == 0) {
  1131. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE;
  1132. } else if (strcmp(buf, "lens") == 0) {
  1133. aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_LENS_MODE;
  1134. }
  1135. return count;
  1136. }
  1137. static DEVICE_ATTR(tool_mode,
  1138. S_IRUGO | S_IWUGO,
  1139. show_tabletToolMode, store_tabletToolMode);
  1140. /***********************************************************************
  1141. * support routines for the 'xtilt' file. Note that this file
  1142. * both displays current setting and allows reprogramming.
  1143. */
  1144. static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
  1145. {
  1146. struct aiptek *aiptek = dev_get_drvdata(dev);
  1147. if (aiptek == NULL)
  1148. return 0;
  1149. if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
  1150. return snprintf(buf, PAGE_SIZE, "disable\n");
  1151. } else {
  1152. return snprintf(buf, PAGE_SIZE, "%d\n",
  1153. aiptek->curSetting.xTilt);
  1154. }
  1155. }
  1156. static ssize_t
  1157. store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1158. {
  1159. struct aiptek *aiptek = dev_get_drvdata(dev);
  1160. int x;
  1161. if (aiptek == NULL)
  1162. return 0;
  1163. if (strcmp(buf, "disable") == 0) {
  1164. aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
  1165. } else {
  1166. x = (int)simple_strtol(buf, NULL, 10);
  1167. if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
  1168. aiptek->newSetting.xTilt = x;
  1169. }
  1170. }
  1171. return count;
  1172. }
  1173. static DEVICE_ATTR(xtilt,
  1174. S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
  1175. /***********************************************************************
  1176. * support routines for the 'ytilt' file. Note that this file
  1177. * both displays current setting and allows reprogramming.
  1178. */
  1179. static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
  1180. {
  1181. struct aiptek *aiptek = dev_get_drvdata(dev);
  1182. if (aiptek == NULL)
  1183. return 0;
  1184. if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
  1185. return snprintf(buf, PAGE_SIZE, "disable\n");
  1186. } else {
  1187. return snprintf(buf, PAGE_SIZE, "%d\n",
  1188. aiptek->curSetting.yTilt);
  1189. }
  1190. }
  1191. static ssize_t
  1192. store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1193. {
  1194. struct aiptek *aiptek = dev_get_drvdata(dev);
  1195. int y;
  1196. if (aiptek == NULL)
  1197. return 0;
  1198. if (strcmp(buf, "disable") == 0) {
  1199. aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
  1200. } else {
  1201. y = (int)simple_strtol(buf, NULL, 10);
  1202. if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
  1203. aiptek->newSetting.yTilt = y;
  1204. }
  1205. }
  1206. return count;
  1207. }
  1208. static DEVICE_ATTR(ytilt,
  1209. S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
  1210. /***********************************************************************
  1211. * support routines for the 'jitter' file. Note that this file
  1212. * both displays current setting and allows reprogramming.
  1213. */
  1214. static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
  1215. {
  1216. struct aiptek *aiptek = dev_get_drvdata(dev);
  1217. if (aiptek == NULL)
  1218. return 0;
  1219. return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
  1220. }
  1221. static ssize_t
  1222. store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1223. {
  1224. struct aiptek *aiptek = dev_get_drvdata(dev);
  1225. if (aiptek == NULL)
  1226. return 0;
  1227. aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
  1228. return count;
  1229. }
  1230. static DEVICE_ATTR(jitter,
  1231. S_IRUGO | S_IWUGO,
  1232. show_tabletJitterDelay, store_tabletJitterDelay);
  1233. /***********************************************************************
  1234. * support routines for the 'delay' file. Note that this file
  1235. * both displays current setting and allows reprogramming.
  1236. */
  1237. static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
  1238. {
  1239. struct aiptek *aiptek = dev_get_drvdata(dev);
  1240. if (aiptek == NULL)
  1241. return 0;
  1242. return snprintf(buf, PAGE_SIZE, "%d\n",
  1243. aiptek->curSetting.programmableDelay);
  1244. }
  1245. static ssize_t
  1246. store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1247. {
  1248. struct aiptek *aiptek = dev_get_drvdata(dev);
  1249. if (aiptek == NULL)
  1250. return 0;
  1251. aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
  1252. return count;
  1253. }
  1254. static DEVICE_ATTR(delay,
  1255. S_IRUGO | S_IWUGO,
  1256. show_tabletProgrammableDelay, store_tabletProgrammableDelay);
  1257. /***********************************************************************
  1258. * support routines for the 'input_path' file. Note that this file
  1259. * only displays current setting.
  1260. */
  1261. static ssize_t show_tabletInputDevice(struct device *dev, struct device_attribute *attr, char *buf)
  1262. {
  1263. struct aiptek *aiptek = dev_get_drvdata(dev);
  1264. if (aiptek == NULL)
  1265. return 0;
  1266. return snprintf(buf, PAGE_SIZE, "/dev/input/%s\n",
  1267. aiptek->features.inputPath);
  1268. }
  1269. static DEVICE_ATTR(input_path, S_IRUGO, show_tabletInputDevice, NULL);
  1270. /***********************************************************************
  1271. * support routines for the 'event_count' file. Note that this file
  1272. * only displays current setting.
  1273. */
  1274. static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
  1275. {
  1276. struct aiptek *aiptek = dev_get_drvdata(dev);
  1277. if (aiptek == NULL)
  1278. return 0;
  1279. return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
  1280. }
  1281. static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
  1282. /***********************************************************************
  1283. * support routines for the 'diagnostic' file. Note that this file
  1284. * only displays current setting.
  1285. */
  1286. static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
  1287. {
  1288. struct aiptek *aiptek = dev_get_drvdata(dev);
  1289. char *retMsg;
  1290. if (aiptek == NULL)
  1291. return 0;
  1292. switch (aiptek->diagnostic) {
  1293. case AIPTEK_DIAGNOSTIC_NA:
  1294. retMsg = "no errors\n";
  1295. break;
  1296. case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
  1297. retMsg = "Error: receiving relative reports\n";
  1298. break;
  1299. case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
  1300. retMsg = "Error: receiving absolute reports\n";
  1301. break;
  1302. case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
  1303. if (aiptek->curSetting.pointerMode ==
  1304. AIPTEK_POINTER_ONLY_MOUSE_MODE) {
  1305. retMsg = "Error: receiving stylus reports\n";
  1306. } else {
  1307. retMsg = "Error: receiving mouse reports\n";
  1308. }
  1309. break;
  1310. default:
  1311. return 0;
  1312. }
  1313. return snprintf(buf, PAGE_SIZE, retMsg);
  1314. }
  1315. static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
  1316. /***********************************************************************
  1317. * support routines for the 'stylus_upper' file. Note that this file
  1318. * both displays current setting and allows for setting changing.
  1319. */
  1320. static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
  1321. {
  1322. struct aiptek *aiptek = dev_get_drvdata(dev);
  1323. char *s;
  1324. if (aiptek == NULL)
  1325. return 0;
  1326. switch (aiptek->curSetting.stylusButtonUpper) {
  1327. case AIPTEK_STYLUS_UPPER_BUTTON:
  1328. s = "upper";
  1329. break;
  1330. case AIPTEK_STYLUS_LOWER_BUTTON:
  1331. s = "lower";
  1332. break;
  1333. default:
  1334. s = "unknown";
  1335. break;
  1336. }
  1337. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1338. }
  1339. static ssize_t
  1340. store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1341. {
  1342. struct aiptek *aiptek = dev_get_drvdata(dev);
  1343. if (aiptek == NULL)
  1344. return 0;
  1345. if (strcmp(buf, "upper") == 0) {
  1346. aiptek->newSetting.stylusButtonUpper =
  1347. AIPTEK_STYLUS_UPPER_BUTTON;
  1348. } else if (strcmp(buf, "lower") == 0) {
  1349. aiptek->newSetting.stylusButtonUpper =
  1350. AIPTEK_STYLUS_LOWER_BUTTON;
  1351. }
  1352. return count;
  1353. }
  1354. static DEVICE_ATTR(stylus_upper,
  1355. S_IRUGO | S_IWUGO,
  1356. show_tabletStylusUpper, store_tabletStylusUpper);
  1357. /***********************************************************************
  1358. * support routines for the 'stylus_lower' file. Note that this file
  1359. * both displays current setting and allows for setting changing.
  1360. */
  1361. static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
  1362. {
  1363. struct aiptek *aiptek = dev_get_drvdata(dev);
  1364. char *s;
  1365. if (aiptek == NULL)
  1366. return 0;
  1367. switch (aiptek->curSetting.stylusButtonLower) {
  1368. case AIPTEK_STYLUS_UPPER_BUTTON:
  1369. s = "upper";
  1370. break;
  1371. case AIPTEK_STYLUS_LOWER_BUTTON:
  1372. s = "lower";
  1373. break;
  1374. default:
  1375. s = "unknown";
  1376. break;
  1377. }
  1378. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1379. }
  1380. static ssize_t
  1381. store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1382. {
  1383. struct aiptek *aiptek = dev_get_drvdata(dev);
  1384. if (aiptek == NULL)
  1385. return 0;
  1386. if (strcmp(buf, "upper") == 0) {
  1387. aiptek->newSetting.stylusButtonLower =
  1388. AIPTEK_STYLUS_UPPER_BUTTON;
  1389. } else if (strcmp(buf, "lower") == 0) {
  1390. aiptek->newSetting.stylusButtonLower =
  1391. AIPTEK_STYLUS_LOWER_BUTTON;
  1392. }
  1393. return count;
  1394. }
  1395. static DEVICE_ATTR(stylus_lower,
  1396. S_IRUGO | S_IWUGO,
  1397. show_tabletStylusLower, store_tabletStylusLower);
  1398. /***********************************************************************
  1399. * support routines for the 'mouse_left' file. Note that this file
  1400. * both displays current setting and allows for setting changing.
  1401. */
  1402. static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
  1403. {
  1404. struct aiptek *aiptek = dev_get_drvdata(dev);
  1405. char *s;
  1406. if (aiptek == NULL)
  1407. return 0;
  1408. switch (aiptek->curSetting.mouseButtonLeft) {
  1409. case AIPTEK_MOUSE_LEFT_BUTTON:
  1410. s = "left";
  1411. break;
  1412. case AIPTEK_MOUSE_MIDDLE_BUTTON:
  1413. s = "middle";
  1414. break;
  1415. case AIPTEK_MOUSE_RIGHT_BUTTON:
  1416. s = "right";
  1417. break;
  1418. default:
  1419. s = "unknown";
  1420. break;
  1421. }
  1422. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1423. }
  1424. static ssize_t
  1425. store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1426. {
  1427. struct aiptek *aiptek = dev_get_drvdata(dev);
  1428. if (aiptek == NULL)
  1429. return 0;
  1430. if (strcmp(buf, "left") == 0) {
  1431. aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
  1432. } else if (strcmp(buf, "middle") == 0) {
  1433. aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_MIDDLE_BUTTON;
  1434. } else if (strcmp(buf, "right") == 0) {
  1435. aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_RIGHT_BUTTON;
  1436. }
  1437. return count;
  1438. }
  1439. static DEVICE_ATTR(mouse_left,
  1440. S_IRUGO | S_IWUGO,
  1441. show_tabletMouseLeft, store_tabletMouseLeft);
  1442. /***********************************************************************
  1443. * support routines for the 'mouse_middle' file. Note that this file
  1444. * both displays current setting and allows for setting changing.
  1445. */
  1446. static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
  1447. {
  1448. struct aiptek *aiptek = dev_get_drvdata(dev);
  1449. char *s;
  1450. if (aiptek == NULL)
  1451. return 0;
  1452. switch (aiptek->curSetting.mouseButtonMiddle) {
  1453. case AIPTEK_MOUSE_LEFT_BUTTON:
  1454. s = "left";
  1455. break;
  1456. case AIPTEK_MOUSE_MIDDLE_BUTTON:
  1457. s = "middle";
  1458. break;
  1459. case AIPTEK_MOUSE_RIGHT_BUTTON:
  1460. s = "right";
  1461. break;
  1462. default:
  1463. s = "unknown";
  1464. break;
  1465. }
  1466. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1467. }
  1468. static ssize_t
  1469. store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1470. {
  1471. struct aiptek *aiptek = dev_get_drvdata(dev);
  1472. if (aiptek == NULL)
  1473. return 0;
  1474. if (strcmp(buf, "left") == 0) {
  1475. aiptek->newSetting.mouseButtonMiddle = AIPTEK_MOUSE_LEFT_BUTTON;
  1476. } else if (strcmp(buf, "middle") == 0) {
  1477. aiptek->newSetting.mouseButtonMiddle =
  1478. AIPTEK_MOUSE_MIDDLE_BUTTON;
  1479. } else if (strcmp(buf, "right") == 0) {
  1480. aiptek->newSetting.mouseButtonMiddle =
  1481. AIPTEK_MOUSE_RIGHT_BUTTON;
  1482. }
  1483. return count;
  1484. }
  1485. static DEVICE_ATTR(mouse_middle,
  1486. S_IRUGO | S_IWUGO,
  1487. show_tabletMouseMiddle, store_tabletMouseMiddle);
  1488. /***********************************************************************
  1489. * support routines for the 'mouse_right' file. Note that this file
  1490. * both displays current setting and allows for setting changing.
  1491. */
  1492. static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
  1493. {
  1494. struct aiptek *aiptek = dev_get_drvdata(dev);
  1495. char *s;
  1496. if (aiptek == NULL)
  1497. return 0;
  1498. switch (aiptek->curSetting.mouseButtonRight) {
  1499. case AIPTEK_MOUSE_LEFT_BUTTON:
  1500. s = "left";
  1501. break;
  1502. case AIPTEK_MOUSE_MIDDLE_BUTTON:
  1503. s = "middle";
  1504. break;
  1505. case AIPTEK_MOUSE_RIGHT_BUTTON:
  1506. s = "right";
  1507. break;
  1508. default:
  1509. s = "unknown";
  1510. break;
  1511. }
  1512. return snprintf(buf, PAGE_SIZE, "%s\n", s);
  1513. }
  1514. static ssize_t
  1515. store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1516. {
  1517. struct aiptek *aiptek = dev_get_drvdata(dev);
  1518. if (aiptek == NULL)
  1519. return 0;
  1520. if (strcmp(buf, "left") == 0) {
  1521. aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_LEFT_BUTTON;
  1522. } else if (strcmp(buf, "middle") == 0) {
  1523. aiptek->newSetting.mouseButtonRight =
  1524. AIPTEK_MOUSE_MIDDLE_BUTTON;
  1525. } else if (strcmp(buf, "right") == 0) {
  1526. aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
  1527. }
  1528. return count;
  1529. }
  1530. static DEVICE_ATTR(mouse_right,
  1531. S_IRUGO | S_IWUGO,
  1532. show_tabletMouseRight, store_tabletMouseRight);
  1533. /***********************************************************************
  1534. * support routines for the 'wheel' file. Note that this file
  1535. * both displays current setting and allows for setting changing.
  1536. */
  1537. static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
  1538. {
  1539. struct aiptek *aiptek = dev_get_drvdata(dev);
  1540. if (aiptek == NULL)
  1541. return 0;
  1542. if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
  1543. return snprintf(buf, PAGE_SIZE, "disable\n");
  1544. } else {
  1545. return snprintf(buf, PAGE_SIZE, "%d\n",
  1546. aiptek->curSetting.wheel);
  1547. }
  1548. }
  1549. static ssize_t
  1550. store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1551. {
  1552. struct aiptek *aiptek = dev_get_drvdata(dev);
  1553. if (aiptek == NULL)
  1554. return 0;
  1555. aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
  1556. return count;
  1557. }
  1558. static DEVICE_ATTR(wheel,
  1559. S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
  1560. /***********************************************************************
  1561. * support routines for the 'execute' file. Note that this file
  1562. * both displays current setting and allows for setting changing.
  1563. */
  1564. static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
  1565. {
  1566. struct aiptek *aiptek = dev_get_drvdata(dev);
  1567. if (aiptek == NULL)
  1568. return 0;
  1569. /* There is nothing useful to display, so a one-line manual
  1570. * is in order...
  1571. */
  1572. return snprintf(buf, PAGE_SIZE,
  1573. "Write anything to this file to program your tablet.\n");
  1574. }
  1575. static ssize_t
  1576. store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1577. {
  1578. struct aiptek *aiptek = dev_get_drvdata(dev);
  1579. if (aiptek == NULL)
  1580. return 0;
  1581. /* We do not care what you write to this file. Merely the action
  1582. * of writing to this file triggers a tablet reprogramming.
  1583. */
  1584. memcpy(&aiptek->curSetting, &aiptek->newSetting,
  1585. sizeof(struct aiptek_settings));
  1586. if (aiptek_program_tablet(aiptek) < 0)
  1587. return -EIO;
  1588. return count;
  1589. }
  1590. static DEVICE_ATTR(execute,
  1591. S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
  1592. /***********************************************************************
  1593. * support routines for the 'odm_code' file. Note that this file
  1594. * only displays current setting.
  1595. */
  1596. static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
  1597. {
  1598. struct aiptek *aiptek = dev_get_drvdata(dev);
  1599. if (aiptek == NULL)
  1600. return 0;
  1601. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
  1602. }
  1603. static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
  1604. /***********************************************************************
  1605. * support routines for the 'model_code' file. Note that this file
  1606. * only displays current setting.
  1607. */
  1608. static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
  1609. {
  1610. struct aiptek *aiptek = dev_get_drvdata(dev);
  1611. if (aiptek == NULL)
  1612. return 0;
  1613. return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
  1614. }
  1615. static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
  1616. /***********************************************************************
  1617. * support routines for the 'firmware_code' file. Note that this file
  1618. * only displays current setting.
  1619. */
  1620. static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
  1621. {
  1622. struct aiptek *aiptek = dev_get_drvdata(dev);
  1623. if (aiptek == NULL)
  1624. return 0;
  1625. return snprintf(buf, PAGE_SIZE, "%04x\n",
  1626. aiptek->features.firmwareCode);
  1627. }
  1628. static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
  1629. /***********************************************************************
  1630. * This routine removes all existing sysfs files managed by this device
  1631. * driver.
  1632. */
  1633. static void aiptek_delete_files(struct device *dev)
  1634. {
  1635. device_remove_file(dev, &dev_attr_size);
  1636. device_remove_file(dev, &dev_attr_product_id);
  1637. device_remove_file(dev, &dev_attr_vendor_id);
  1638. device_remove_file(dev, &dev_attr_vendor);
  1639. device_remove_file(dev, &dev_attr_product);
  1640. device_remove_file(dev, &dev_attr_pointer_mode);
  1641. device_remove_file(dev, &dev_attr_coordinate_mode);
  1642. device_remove_file(dev, &dev_attr_tool_mode);
  1643. device_remove_file(dev, &dev_attr_xtilt);
  1644. device_remove_file(dev, &dev_attr_ytilt);
  1645. device_remove_file(dev, &dev_attr_jitter);
  1646. device_remove_file(dev, &dev_attr_delay);
  1647. device_remove_file(dev, &dev_attr_input_path);
  1648. device_remove_file(dev, &dev_attr_event_count);
  1649. device_remove_file(dev, &dev_attr_diagnostic);
  1650. device_remove_file(dev, &dev_attr_odm_code);
  1651. device_remove_file(dev, &dev_attr_model_code);
  1652. device_remove_file(dev, &dev_attr_firmware_code);
  1653. device_remove_file(dev, &dev_attr_stylus_lower);
  1654. device_remove_file(dev, &dev_attr_stylus_upper);
  1655. device_remove_file(dev, &dev_attr_mouse_left);
  1656. device_remove_file(dev, &dev_attr_mouse_middle);
  1657. device_remove_file(dev, &dev_attr_mouse_right);
  1658. device_remove_file(dev, &dev_attr_wheel);
  1659. device_remove_file(dev, &dev_attr_execute);
  1660. }
  1661. /***********************************************************************
  1662. * This routine creates the sysfs files managed by this device
  1663. * driver.
  1664. */
  1665. static int aiptek_add_files(struct device *dev)
  1666. {
  1667. int ret;
  1668. if ((ret = device_create_file(dev, &dev_attr_size)) ||
  1669. (ret = device_create_file(dev, &dev_attr_product_id)) ||
  1670. (ret = device_create_file(dev, &dev_attr_vendor_id)) ||
  1671. (ret = device_create_file(dev, &dev_attr_vendor)) ||
  1672. (ret = device_create_file(dev, &dev_attr_product)) ||
  1673. (ret = device_create_file(dev, &dev_attr_pointer_mode)) ||
  1674. (ret = device_create_file(dev, &dev_attr_coordinate_mode)) ||
  1675. (ret = device_create_file(dev, &dev_attr_tool_mode)) ||
  1676. (ret = device_create_file(dev, &dev_attr_xtilt)) ||
  1677. (ret = device_create_file(dev, &dev_attr_ytilt)) ||
  1678. (ret = device_create_file(dev, &dev_attr_jitter)) ||
  1679. (ret = device_create_file(dev, &dev_attr_delay)) ||
  1680. (ret = device_create_file(dev, &dev_attr_input_path)) ||
  1681. (ret = device_create_file(dev, &dev_attr_event_count)) ||
  1682. (ret = device_create_file(dev, &dev_attr_diagnostic)) ||
  1683. (ret = device_create_file(dev, &dev_attr_odm_code)) ||
  1684. (ret = device_create_file(dev, &dev_attr_model_code)) ||
  1685. (ret = device_create_file(dev, &dev_attr_firmware_code)) ||
  1686. (ret = device_create_file(dev, &dev_attr_stylus_lower)) ||
  1687. (ret = device_create_file(dev, &dev_attr_stylus_upper)) ||
  1688. (ret = device_create_file(dev, &dev_attr_mouse_left)) ||
  1689. (ret = device_create_file(dev, &dev_attr_mouse_middle)) ||
  1690. (ret = device_create_file(dev, &dev_attr_mouse_right)) ||
  1691. (ret = device_create_file(dev, &dev_attr_wheel)) ||
  1692. (ret = device_create_file(dev, &dev_attr_execute))) {
  1693. err("aiptek: killing own sysfs device files\n");
  1694. aiptek_delete_files(dev);
  1695. }
  1696. return ret;
  1697. }
  1698. /***********************************************************************
  1699. * This routine is called when a tablet has been identified. It basically
  1700. * sets up the tablet and the driver's internal structures.
  1701. */
  1702. static int
  1703. aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1704. {
  1705. struct usb_device *usbdev = interface_to_usbdev(intf);
  1706. struct usb_endpoint_descriptor *endpoint;
  1707. struct aiptek *aiptek;
  1708. struct input_dev *inputdev;
  1709. struct input_handle *inputhandle;
  1710. struct list_head *node, *next;
  1711. char path[64 + 1];
  1712. int i;
  1713. int speeds[] = { 0,
  1714. AIPTEK_PROGRAMMABLE_DELAY_50,
  1715. AIPTEK_PROGRAMMABLE_DELAY_400,
  1716. AIPTEK_PROGRAMMABLE_DELAY_25,
  1717. AIPTEK_PROGRAMMABLE_DELAY_100,
  1718. AIPTEK_PROGRAMMABLE_DELAY_200,
  1719. AIPTEK_PROGRAMMABLE_DELAY_300
  1720. };
  1721. /* programmableDelay is where the command-line specified
  1722. * delay is kept. We make it the first element of speeds[],
  1723. * so therefore, your override speed is tried first, then the
  1724. * remainder. Note that the default value of 400ms will be tried
  1725. * if you do not specify any command line parameter.
  1726. */
  1727. speeds[0] = programmableDelay;
  1728. if ((aiptek = kmalloc(sizeof(struct aiptek), GFP_KERNEL)) == NULL)
  1729. return -ENOMEM;
  1730. memset(aiptek, 0, sizeof(struct aiptek));
  1731. aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
  1732. SLAB_ATOMIC, &aiptek->data_dma);
  1733. if (aiptek->data == NULL) {
  1734. kfree(aiptek);
  1735. return -ENOMEM;
  1736. }
  1737. aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
  1738. if (aiptek->urb == NULL) {
  1739. usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
  1740. aiptek->data_dma);
  1741. kfree(aiptek);
  1742. return -ENOMEM;
  1743. }
  1744. /* Set up the curSettings struct. Said struct contains the current
  1745. * programmable parameters. The newSetting struct contains changes
  1746. * the user makes to the settings via the sysfs interface. Those
  1747. * changes are not "committed" to curSettings until the user
  1748. * writes to the sysfs/.../execute file.
  1749. */
  1750. aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
  1751. aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
  1752. aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
  1753. aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
  1754. aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
  1755. aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
  1756. aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
  1757. aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
  1758. aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
  1759. aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
  1760. aiptek->curSetting.jitterDelay = jitterDelay;
  1761. aiptek->curSetting.programmableDelay = programmableDelay;
  1762. /* Both structs should have equivalent settings
  1763. */
  1764. memcpy(&aiptek->newSetting, &aiptek->curSetting,
  1765. sizeof(struct aiptek_settings));
  1766. /* Now program the capacities of the tablet, in terms of being
  1767. * an input device.
  1768. */
  1769. aiptek->inputdev.evbit[0] |= BIT(EV_KEY)
  1770. | BIT(EV_ABS)
  1771. | BIT(EV_REL)
  1772. | BIT(EV_MSC);
  1773. aiptek->inputdev.absbit[0] |=
  1774. (BIT(ABS_X) |
  1775. BIT(ABS_Y) |
  1776. BIT(ABS_PRESSURE) |
  1777. BIT(ABS_TILT_X) |
  1778. BIT(ABS_TILT_Y) | BIT(ABS_WHEEL) | BIT(ABS_MISC));
  1779. aiptek->inputdev.relbit[0] |=
  1780. (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC));
  1781. aiptek->inputdev.keybit[LONG(BTN_LEFT)] |=
  1782. (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE));
  1783. aiptek->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. aiptek->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 < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i)
  1797. set_bit(macroKeyEvents[i], aiptek->inputdev.keybit);
  1798. /* Set up client data, pointers to open and close routines
  1799. * for the input device.
  1800. */
  1801. aiptek->inputdev.private = aiptek;
  1802. aiptek->inputdev.open = aiptek_open;
  1803. aiptek->inputdev.close = aiptek_close;
  1804. /* Determine the usb devices' physical path.
  1805. * Asketh not why we always pretend we're using "../input0",
  1806. * but I suspect this will have to be refactored one
  1807. * day if a single USB device can be a keyboard & a mouse
  1808. * & a tablet, and the inputX number actually will tell
  1809. * us something...
  1810. */
  1811. if (usb_make_path(usbdev, path, 64) > 0)
  1812. sprintf(aiptek->features.usbPath, "%s/input0", path);
  1813. /* Program the input device coordinate capacities. We do not yet
  1814. * know what maximum X, Y, and Z values are, so we're putting fake
  1815. * values in. Later, we'll ask the tablet to put in the correct
  1816. * values.
  1817. */
  1818. aiptek->inputdev.absmin[ABS_X] = 0;
  1819. aiptek->inputdev.absmax[ABS_X] = 2999;
  1820. aiptek->inputdev.absmin[ABS_Y] = 0;
  1821. aiptek->inputdev.absmax[ABS_Y] = 2249;
  1822. aiptek->inputdev.absmin[ABS_PRESSURE] = 0;
  1823. aiptek->inputdev.absmax[ABS_PRESSURE] = 511;
  1824. aiptek->inputdev.absmin[ABS_TILT_X] = AIPTEK_TILT_MIN;
  1825. aiptek->inputdev.absmax[ABS_TILT_X] = AIPTEK_TILT_MAX;
  1826. aiptek->inputdev.absmin[ABS_TILT_Y] = AIPTEK_TILT_MIN;
  1827. aiptek->inputdev.absmax[ABS_TILT_Y] = AIPTEK_TILT_MAX;
  1828. aiptek->inputdev.absmin[ABS_WHEEL] = AIPTEK_WHEEL_MIN;
  1829. aiptek->inputdev.absmax[ABS_WHEEL] = AIPTEK_WHEEL_MAX - 1;
  1830. aiptek->inputdev.absfuzz[ABS_X] = 0;
  1831. aiptek->inputdev.absfuzz[ABS_Y] = 0;
  1832. aiptek->inputdev.absfuzz[ABS_PRESSURE] = 0;
  1833. aiptek->inputdev.absfuzz[ABS_TILT_X] = 0;
  1834. aiptek->inputdev.absfuzz[ABS_TILT_Y] = 0;
  1835. aiptek->inputdev.absfuzz[ABS_WHEEL] = 0;
  1836. aiptek->inputdev.absflat[ABS_X] = 0;
  1837. aiptek->inputdev.absflat[ABS_Y] = 0;
  1838. aiptek->inputdev.absflat[ABS_PRESSURE] = 0;
  1839. aiptek->inputdev.absflat[ABS_TILT_X] = 0;
  1840. aiptek->inputdev.absflat[ABS_TILT_Y] = 0;
  1841. aiptek->inputdev.absflat[ABS_WHEEL] = 0;
  1842. aiptek->inputdev.name = "Aiptek";
  1843. aiptek->inputdev.phys = aiptek->features.usbPath;
  1844. aiptek->inputdev.id.bustype = BUS_USB;
  1845. aiptek->inputdev.id.vendor = le16_to_cpu(usbdev->descriptor.idVendor);
  1846. aiptek->inputdev.id.product = le16_to_cpu(usbdev->descriptor.idProduct);
  1847. aiptek->inputdev.id.version = le16_to_cpu(usbdev->descriptor.bcdDevice);
  1848. aiptek->inputdev.dev = &intf->dev;
  1849. aiptek->usbdev = usbdev;
  1850. aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
  1851. aiptek->inDelay = 0;
  1852. aiptek->endDelay = 0;
  1853. aiptek->previousJitterable = 0;
  1854. endpoint = &intf->altsetting[0].endpoint[0].desc;
  1855. /* Go set up our URB, which is called when the tablet receives
  1856. * input.
  1857. */
  1858. usb_fill_int_urb(aiptek->urb,
  1859. aiptek->usbdev,
  1860. usb_rcvintpipe(aiptek->usbdev,
  1861. endpoint->bEndpointAddress),
  1862. aiptek->data, 8, aiptek_irq, aiptek,
  1863. endpoint->bInterval);
  1864. aiptek->urb->transfer_dma = aiptek->data_dma;
  1865. aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1866. /* Register the tablet as an Input Device
  1867. */
  1868. input_register_device(&aiptek->inputdev);
  1869. /* We now will look for the evdev device which is mapped to
  1870. * the tablet. The partial name is kept in the link list of
  1871. * input_handles associated with this input device.
  1872. * What identifies an evdev input_handler is that it begins
  1873. * with 'event', continues with a digit, and that in turn
  1874. * is mapped to /{devfs}/input/eventN.
  1875. */
  1876. inputdev = &aiptek->inputdev;
  1877. list_for_each_safe(node, next, &inputdev->h_list) {
  1878. inputhandle = to_handle(node);
  1879. if (strncmp(inputhandle->name, "event", 5) == 0) {
  1880. strcpy(aiptek->features.inputPath, inputhandle->name);
  1881. break;
  1882. }
  1883. }
  1884. info("input: Aiptek on %s (%s)\n", path, aiptek->features.inputPath);
  1885. /* Program the tablet. This sets the tablet up in the mode
  1886. * specified in newSetting, and also queries the tablet's
  1887. * physical capacities.
  1888. *
  1889. * Sanity check: if a tablet doesn't like the slow programmatic
  1890. * delay, we often get sizes of 0x0. Let's use that as an indicator
  1891. * to try faster delays, up to 25 ms. If that logic fails, well, you'll
  1892. * have to explain to us how your tablet thinks it's 0x0, and yet that's
  1893. * not an error :-)
  1894. */
  1895. for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) {
  1896. aiptek->curSetting.programmableDelay = speeds[i];
  1897. (void)aiptek_program_tablet(aiptek);
  1898. if (aiptek->inputdev.absmax[ABS_X] > 0) {
  1899. info("input: Aiptek using %d ms programming speed\n",
  1900. aiptek->curSetting.programmableDelay);
  1901. break;
  1902. }
  1903. }
  1904. /* Associate this driver's struct with the usb interface.
  1905. */
  1906. usb_set_intfdata(intf, aiptek);
  1907. /* Set up the sysfs files
  1908. */
  1909. aiptek_add_files(&intf->dev);
  1910. /* Make sure the evdev module is loaded. Assuming evdev IS a module :-)
  1911. */
  1912. if (request_module("evdev") != 0)
  1913. info("aiptek: error loading 'evdev' module");
  1914. return 0;
  1915. }
  1916. /* Forward declaration */
  1917. static void aiptek_disconnect(struct usb_interface *intf);
  1918. static struct usb_driver aiptek_driver = {
  1919. .owner = THIS_MODULE,
  1920. .name = "aiptek",
  1921. .probe = aiptek_probe,
  1922. .disconnect = aiptek_disconnect,
  1923. .id_table = aiptek_ids,
  1924. };
  1925. /***********************************************************************
  1926. * Deal with tablet disconnecting from the system.
  1927. */
  1928. static void aiptek_disconnect(struct usb_interface *intf)
  1929. {
  1930. struct aiptek *aiptek = usb_get_intfdata(intf);
  1931. /* Disassociate driver's struct with usb interface
  1932. */
  1933. usb_set_intfdata(intf, NULL);
  1934. if (aiptek != NULL) {
  1935. /* Free & unhook everything from the system.
  1936. */
  1937. usb_kill_urb(aiptek->urb);
  1938. input_unregister_device(&aiptek->inputdev);
  1939. aiptek_delete_files(&intf->dev);
  1940. usb_free_urb(aiptek->urb);
  1941. usb_buffer_free(interface_to_usbdev(intf),
  1942. AIPTEK_PACKET_LENGTH,
  1943. aiptek->data, aiptek->data_dma);
  1944. kfree(aiptek);
  1945. aiptek = NULL;
  1946. }
  1947. }
  1948. static int __init aiptek_init(void)
  1949. {
  1950. int result = usb_register(&aiptek_driver);
  1951. if (result == 0) {
  1952. info(DRIVER_VERSION ": " DRIVER_AUTHOR);
  1953. info(DRIVER_DESC);
  1954. }
  1955. return result;
  1956. }
  1957. static void __exit aiptek_exit(void)
  1958. {
  1959. usb_deregister(&aiptek_driver);
  1960. }
  1961. MODULE_AUTHOR(DRIVER_AUTHOR);
  1962. MODULE_DESCRIPTION(DRIVER_DESC);
  1963. MODULE_LICENSE("GPL");
  1964. module_param(programmableDelay, int, 0);
  1965. MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
  1966. module_param(jitterDelay, int, 0);
  1967. MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
  1968. module_init(aiptek_init);
  1969. module_exit(aiptek_exit);