aiptek.c 69 KB

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