psmouse-base.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  1. /*
  2. * PS/2 mouse driver
  3. *
  4. * Copyright (c) 1999-2002 Vojtech Pavlik
  5. * Copyright (c) 2003-2004 Dmitry Torokhov
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published by
  10. * the Free Software Foundation.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #define psmouse_fmt(fmt) fmt
  14. #include <linux/delay.h>
  15. #include <linux/module.h>
  16. #include <linux/slab.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/input.h>
  19. #include <linux/serio.h>
  20. #include <linux/init.h>
  21. #include <linux/libps2.h>
  22. #include <linux/mutex.h>
  23. #include "psmouse.h"
  24. #include "synaptics.h"
  25. #include "logips2pp.h"
  26. #include "alps.h"
  27. #include "hgpk.h"
  28. #include "lifebook.h"
  29. #include "trackpoint.h"
  30. #include "touchkit_ps2.h"
  31. #include "elantech.h"
  32. #include "sentelic.h"
  33. #include "cypress_ps2.h"
  34. #include "focaltech.h"
  35. #define DRIVER_DESC "PS/2 mouse driver"
  36. MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
  37. MODULE_DESCRIPTION(DRIVER_DESC);
  38. MODULE_LICENSE("GPL");
  39. static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
  40. static int psmouse_set_maxproto(const char *val, const struct kernel_param *);
  41. static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp);
  42. static struct kernel_param_ops param_ops_proto_abbrev = {
  43. .set = psmouse_set_maxproto,
  44. .get = psmouse_get_maxproto,
  45. };
  46. #define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
  47. module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
  48. MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
  49. static unsigned int psmouse_resolution = 200;
  50. module_param_named(resolution, psmouse_resolution, uint, 0644);
  51. MODULE_PARM_DESC(resolution, "Resolution, in dpi.");
  52. static unsigned int psmouse_rate = 100;
  53. module_param_named(rate, psmouse_rate, uint, 0644);
  54. MODULE_PARM_DESC(rate, "Report rate, in reports per second.");
  55. static bool psmouse_smartscroll = 1;
  56. module_param_named(smartscroll, psmouse_smartscroll, bool, 0644);
  57. MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
  58. static unsigned int psmouse_resetafter = 5;
  59. module_param_named(resetafter, psmouse_resetafter, uint, 0644);
  60. MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
  61. static unsigned int psmouse_resync_time;
  62. module_param_named(resync_time, psmouse_resync_time, uint, 0644);
  63. MODULE_PARM_DESC(resync_time, "How long can mouse stay idle before forcing resync (in seconds, 0 = never).");
  64. PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO,
  65. NULL,
  66. psmouse_attr_show_protocol, psmouse_attr_set_protocol);
  67. PSMOUSE_DEFINE_ATTR(rate, S_IWUSR | S_IRUGO,
  68. (void *) offsetof(struct psmouse, rate),
  69. psmouse_show_int_attr, psmouse_attr_set_rate);
  70. PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO,
  71. (void *) offsetof(struct psmouse, resolution),
  72. psmouse_show_int_attr, psmouse_attr_set_resolution);
  73. PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO,
  74. (void *) offsetof(struct psmouse, resetafter),
  75. psmouse_show_int_attr, psmouse_set_int_attr);
  76. PSMOUSE_DEFINE_ATTR(resync_time, S_IWUSR | S_IRUGO,
  77. (void *) offsetof(struct psmouse, resync_time),
  78. psmouse_show_int_attr, psmouse_set_int_attr);
  79. static struct attribute *psmouse_attributes[] = {
  80. &psmouse_attr_protocol.dattr.attr,
  81. &psmouse_attr_rate.dattr.attr,
  82. &psmouse_attr_resolution.dattr.attr,
  83. &psmouse_attr_resetafter.dattr.attr,
  84. &psmouse_attr_resync_time.dattr.attr,
  85. NULL
  86. };
  87. static struct attribute_group psmouse_attribute_group = {
  88. .attrs = psmouse_attributes,
  89. };
  90. /*
  91. * psmouse_mutex protects all operations changing state of mouse
  92. * (connecting, disconnecting, changing rate or resolution via
  93. * sysfs). We could use a per-device semaphore but since there
  94. * rarely more than one PS/2 mouse connected and since semaphore
  95. * is taken in "slow" paths it is not worth it.
  96. */
  97. static DEFINE_MUTEX(psmouse_mutex);
  98. static struct workqueue_struct *kpsmoused_wq;
  99. struct psmouse_protocol {
  100. enum psmouse_type type;
  101. bool maxproto;
  102. bool ignore_parity; /* Protocol should ignore parity errors from KBC */
  103. const char *name;
  104. const char *alias;
  105. int (*detect)(struct psmouse *, bool);
  106. int (*init)(struct psmouse *);
  107. };
  108. /*
  109. * psmouse_process_byte() analyzes the PS/2 data stream and reports
  110. * relevant events to the input module once full packet has arrived.
  111. */
  112. psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
  113. {
  114. struct input_dev *dev = psmouse->dev;
  115. unsigned char *packet = psmouse->packet;
  116. if (psmouse->pktcnt < psmouse->pktsize)
  117. return PSMOUSE_GOOD_DATA;
  118. /*
  119. * Full packet accumulated, process it
  120. */
  121. /*
  122. * Scroll wheel on IntelliMice, scroll buttons on NetMice
  123. */
  124. if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS)
  125. input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
  126. /*
  127. * Scroll wheel and buttons on IntelliMouse Explorer
  128. */
  129. if (psmouse->type == PSMOUSE_IMEX) {
  130. switch (packet[3] & 0xC0) {
  131. case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */
  132. input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
  133. break;
  134. case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */
  135. input_report_rel(dev, REL_HWHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
  136. break;
  137. case 0x00:
  138. case 0xC0:
  139. input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7));
  140. input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1);
  141. input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1);
  142. break;
  143. }
  144. }
  145. /*
  146. * Extra buttons on Genius NewNet 3D
  147. */
  148. if (psmouse->type == PSMOUSE_GENPS) {
  149. input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1);
  150. input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1);
  151. }
  152. /*
  153. * Extra button on ThinkingMouse
  154. */
  155. if (psmouse->type == PSMOUSE_THINKPS) {
  156. input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1);
  157. /* Without this bit of weirdness moving up gives wildly high Y changes. */
  158. packet[1] |= (packet[0] & 0x40) << 1;
  159. }
  160. /*
  161. * Cortron PS2 Trackball reports SIDE button on the 4th bit of the first
  162. * byte.
  163. */
  164. if (psmouse->type == PSMOUSE_CORTRON) {
  165. input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1);
  166. packet[0] |= 0x08;
  167. }
  168. /*
  169. * Generic PS/2 Mouse
  170. */
  171. input_report_key(dev, BTN_LEFT, packet[0] & 1);
  172. input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
  173. input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
  174. input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
  175. input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
  176. input_sync(dev);
  177. return PSMOUSE_FULL_PACKET;
  178. }
  179. void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
  180. unsigned long delay)
  181. {
  182. queue_delayed_work(kpsmoused_wq, work, delay);
  183. }
  184. /*
  185. * __psmouse_set_state() sets new psmouse state and resets all flags.
  186. */
  187. static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
  188. {
  189. psmouse->state = new_state;
  190. psmouse->pktcnt = psmouse->out_of_sync_cnt = 0;
  191. psmouse->ps2dev.flags = 0;
  192. psmouse->last = jiffies;
  193. }
  194. /*
  195. * psmouse_set_state() sets new psmouse state and resets all flags and
  196. * counters while holding serio lock so fighting with interrupt handler
  197. * is not a concern.
  198. */
  199. void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
  200. {
  201. serio_pause_rx(psmouse->ps2dev.serio);
  202. __psmouse_set_state(psmouse, new_state);
  203. serio_continue_rx(psmouse->ps2dev.serio);
  204. }
  205. /*
  206. * psmouse_handle_byte() processes one byte of the input data stream
  207. * by calling corresponding protocol handler.
  208. */
  209. static int psmouse_handle_byte(struct psmouse *psmouse)
  210. {
  211. psmouse_ret_t rc = psmouse->protocol_handler(psmouse);
  212. switch (rc) {
  213. case PSMOUSE_BAD_DATA:
  214. if (psmouse->state == PSMOUSE_ACTIVATED) {
  215. psmouse_warn(psmouse,
  216. "%s at %s lost sync at byte %d\n",
  217. psmouse->name, psmouse->phys,
  218. psmouse->pktcnt);
  219. if (++psmouse->out_of_sync_cnt == psmouse->resetafter) {
  220. __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
  221. psmouse_notice(psmouse,
  222. "issuing reconnect request\n");
  223. serio_reconnect(psmouse->ps2dev.serio);
  224. return -1;
  225. }
  226. }
  227. psmouse->pktcnt = 0;
  228. break;
  229. case PSMOUSE_FULL_PACKET:
  230. psmouse->pktcnt = 0;
  231. if (psmouse->out_of_sync_cnt) {
  232. psmouse->out_of_sync_cnt = 0;
  233. psmouse_notice(psmouse,
  234. "%s at %s - driver resynced.\n",
  235. psmouse->name, psmouse->phys);
  236. }
  237. break;
  238. case PSMOUSE_GOOD_DATA:
  239. break;
  240. }
  241. return 0;
  242. }
  243. /*
  244. * psmouse_interrupt() handles incoming characters, either passing them
  245. * for normal processing or gathering them as command response.
  246. */
  247. static irqreturn_t psmouse_interrupt(struct serio *serio,
  248. unsigned char data, unsigned int flags)
  249. {
  250. struct psmouse *psmouse = serio_get_drvdata(serio);
  251. if (psmouse->state == PSMOUSE_IGNORE)
  252. goto out;
  253. if (unlikely((flags & SERIO_TIMEOUT) ||
  254. ((flags & SERIO_PARITY) && !psmouse->ignore_parity))) {
  255. if (psmouse->state == PSMOUSE_ACTIVATED)
  256. psmouse_warn(psmouse,
  257. "bad data from KBC -%s%s\n",
  258. flags & SERIO_TIMEOUT ? " timeout" : "",
  259. flags & SERIO_PARITY ? " bad parity" : "");
  260. ps2_cmd_aborted(&psmouse->ps2dev);
  261. goto out;
  262. }
  263. if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK))
  264. if (ps2_handle_ack(&psmouse->ps2dev, data))
  265. goto out;
  266. if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_CMD))
  267. if (ps2_handle_response(&psmouse->ps2dev, data))
  268. goto out;
  269. if (psmouse->state <= PSMOUSE_RESYNCING)
  270. goto out;
  271. if (psmouse->state == PSMOUSE_ACTIVATED &&
  272. psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) {
  273. psmouse_info(psmouse, "%s at %s lost synchronization, throwing %d bytes away.\n",
  274. psmouse->name, psmouse->phys, psmouse->pktcnt);
  275. psmouse->badbyte = psmouse->packet[0];
  276. __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
  277. psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
  278. goto out;
  279. }
  280. psmouse->packet[psmouse->pktcnt++] = data;
  281. /*
  282. * Check if this is a new device announcement (0xAA 0x00)
  283. */
  284. if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) {
  285. if (psmouse->pktcnt == 1) {
  286. psmouse->last = jiffies;
  287. goto out;
  288. }
  289. if (psmouse->packet[1] == PSMOUSE_RET_ID ||
  290. (psmouse->type == PSMOUSE_HGPK &&
  291. psmouse->packet[1] == PSMOUSE_RET_BAT)) {
  292. __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
  293. serio_reconnect(serio);
  294. goto out;
  295. }
  296. /*
  297. * Not a new device, try processing first byte normally
  298. */
  299. psmouse->pktcnt = 1;
  300. if (psmouse_handle_byte(psmouse))
  301. goto out;
  302. psmouse->packet[psmouse->pktcnt++] = data;
  303. }
  304. /*
  305. * See if we need to force resync because mouse was idle for too long
  306. */
  307. if (psmouse->state == PSMOUSE_ACTIVATED &&
  308. psmouse->pktcnt == 1 && psmouse->resync_time &&
  309. time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) {
  310. psmouse->badbyte = psmouse->packet[0];
  311. __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
  312. psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
  313. goto out;
  314. }
  315. psmouse->last = jiffies;
  316. psmouse_handle_byte(psmouse);
  317. out:
  318. return IRQ_HANDLED;
  319. }
  320. /*
  321. * psmouse_sliced_command() sends an extended PS/2 command to the mouse
  322. * using sliced syntax, understood by advanced devices, such as Logitech
  323. * or Synaptics touchpads. The command is encoded as:
  324. * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu
  325. * is the command.
  326. */
  327. int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command)
  328. {
  329. int i;
  330. if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
  331. return -1;
  332. for (i = 6; i >= 0; i -= 2) {
  333. unsigned char d = (command >> i) & 3;
  334. if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES))
  335. return -1;
  336. }
  337. return 0;
  338. }
  339. /*
  340. * psmouse_reset() resets the mouse into power-on state.
  341. */
  342. int psmouse_reset(struct psmouse *psmouse)
  343. {
  344. unsigned char param[2];
  345. if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT))
  346. return -1;
  347. if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID)
  348. return -1;
  349. return 0;
  350. }
  351. /*
  352. * Here we set the mouse resolution.
  353. */
  354. void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
  355. {
  356. static const unsigned char params[] = { 0, 1, 2, 2, 3 };
  357. unsigned char p;
  358. if (resolution == 0 || resolution > 200)
  359. resolution = 200;
  360. p = params[resolution / 50];
  361. ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
  362. psmouse->resolution = 25 << p;
  363. }
  364. /*
  365. * Here we set the mouse report rate.
  366. */
  367. static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
  368. {
  369. static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
  370. unsigned char r;
  371. int i = 0;
  372. while (rates[i] > rate) i++;
  373. r = rates[i];
  374. ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
  375. psmouse->rate = r;
  376. }
  377. /*
  378. * Here we set the mouse scaling.
  379. */
  380. static void psmouse_set_scale(struct psmouse *psmouse, enum psmouse_scale scale)
  381. {
  382. ps2_command(&psmouse->ps2dev, NULL,
  383. scale == PSMOUSE_SCALE21 ? PSMOUSE_CMD_SETSCALE21 :
  384. PSMOUSE_CMD_SETSCALE11);
  385. }
  386. /*
  387. * psmouse_poll() - default poll handler. Everyone except for ALPS uses it.
  388. */
  389. static int psmouse_poll(struct psmouse *psmouse)
  390. {
  391. return ps2_command(&psmouse->ps2dev, psmouse->packet,
  392. PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
  393. }
  394. static bool psmouse_check_pnp_id(const char *id, const char * const ids[])
  395. {
  396. int i;
  397. for (i = 0; ids[i]; i++)
  398. if (!strcasecmp(id, ids[i]))
  399. return true;
  400. return false;
  401. }
  402. /*
  403. * psmouse_matches_pnp_id - check if psmouse matches one of the passed in ids.
  404. */
  405. bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[])
  406. {
  407. struct serio *serio = psmouse->ps2dev.serio;
  408. char *p, *fw_id_copy, *save_ptr;
  409. bool found = false;
  410. if (strncmp(serio->firmware_id, "PNP: ", 5))
  411. return false;
  412. fw_id_copy = kstrndup(&serio->firmware_id[5],
  413. sizeof(serio->firmware_id) - 5,
  414. GFP_KERNEL);
  415. if (!fw_id_copy)
  416. return false;
  417. save_ptr = fw_id_copy;
  418. while ((p = strsep(&fw_id_copy, " ")) != NULL) {
  419. if (psmouse_check_pnp_id(p, ids)) {
  420. found = true;
  421. break;
  422. }
  423. }
  424. kfree(save_ptr);
  425. return found;
  426. }
  427. /*
  428. * Genius NetMouse magic init.
  429. */
  430. static int genius_detect(struct psmouse *psmouse, bool set_properties)
  431. {
  432. struct ps2dev *ps2dev = &psmouse->ps2dev;
  433. unsigned char param[4];
  434. param[0] = 3;
  435. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  436. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
  437. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
  438. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
  439. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
  440. if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55)
  441. return -1;
  442. if (set_properties) {
  443. __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
  444. __set_bit(BTN_EXTRA, psmouse->dev->keybit);
  445. __set_bit(BTN_SIDE, psmouse->dev->keybit);
  446. __set_bit(REL_WHEEL, psmouse->dev->relbit);
  447. psmouse->vendor = "Genius";
  448. psmouse->name = "Mouse";
  449. psmouse->pktsize = 4;
  450. }
  451. return 0;
  452. }
  453. /*
  454. * IntelliMouse magic init.
  455. */
  456. static int intellimouse_detect(struct psmouse *psmouse, bool set_properties)
  457. {
  458. struct ps2dev *ps2dev = &psmouse->ps2dev;
  459. unsigned char param[2];
  460. param[0] = 200;
  461. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  462. param[0] = 100;
  463. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  464. param[0] = 80;
  465. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  466. ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
  467. if (param[0] != 3)
  468. return -1;
  469. if (set_properties) {
  470. __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
  471. __set_bit(REL_WHEEL, psmouse->dev->relbit);
  472. if (!psmouse->vendor)
  473. psmouse->vendor = "Generic";
  474. if (!psmouse->name)
  475. psmouse->name = "Wheel Mouse";
  476. psmouse->pktsize = 4;
  477. }
  478. return 0;
  479. }
  480. /*
  481. * Try IntelliMouse/Explorer magic init.
  482. */
  483. static int im_explorer_detect(struct psmouse *psmouse, bool set_properties)
  484. {
  485. struct ps2dev *ps2dev = &psmouse->ps2dev;
  486. unsigned char param[2];
  487. intellimouse_detect(psmouse, 0);
  488. param[0] = 200;
  489. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  490. param[0] = 200;
  491. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  492. param[0] = 80;
  493. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  494. ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
  495. if (param[0] != 4)
  496. return -1;
  497. /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */
  498. param[0] = 200;
  499. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  500. param[0] = 80;
  501. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  502. param[0] = 40;
  503. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  504. if (set_properties) {
  505. __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
  506. __set_bit(REL_WHEEL, psmouse->dev->relbit);
  507. __set_bit(REL_HWHEEL, psmouse->dev->relbit);
  508. __set_bit(BTN_SIDE, psmouse->dev->keybit);
  509. __set_bit(BTN_EXTRA, psmouse->dev->keybit);
  510. if (!psmouse->vendor)
  511. psmouse->vendor = "Generic";
  512. if (!psmouse->name)
  513. psmouse->name = "Explorer Mouse";
  514. psmouse->pktsize = 4;
  515. }
  516. return 0;
  517. }
  518. /*
  519. * Kensington ThinkingMouse / ExpertMouse magic init.
  520. */
  521. static int thinking_detect(struct psmouse *psmouse, bool set_properties)
  522. {
  523. struct ps2dev *ps2dev = &psmouse->ps2dev;
  524. unsigned char param[2];
  525. static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
  526. int i;
  527. param[0] = 10;
  528. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  529. param[0] = 0;
  530. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  531. for (i = 0; i < ARRAY_SIZE(seq); i++) {
  532. param[0] = seq[i];
  533. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
  534. }
  535. ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
  536. if (param[0] != 2)
  537. return -1;
  538. if (set_properties) {
  539. __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
  540. __set_bit(BTN_EXTRA, psmouse->dev->keybit);
  541. psmouse->vendor = "Kensington";
  542. psmouse->name = "ThinkingMouse";
  543. }
  544. return 0;
  545. }
  546. /*
  547. * Bare PS/2 protocol "detection". Always succeeds.
  548. */
  549. static int ps2bare_detect(struct psmouse *psmouse, bool set_properties)
  550. {
  551. if (set_properties) {
  552. if (!psmouse->vendor)
  553. psmouse->vendor = "Generic";
  554. if (!psmouse->name)
  555. psmouse->name = "Mouse";
  556. /*
  557. * We have no way of figuring true number of buttons so let's
  558. * assume that the device has 3.
  559. */
  560. __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
  561. }
  562. return 0;
  563. }
  564. /*
  565. * Cortron PS/2 protocol detection. There's no special way to detect it, so it
  566. * must be forced by sysfs protocol writing.
  567. */
  568. static int cortron_detect(struct psmouse *psmouse, bool set_properties)
  569. {
  570. if (set_properties) {
  571. psmouse->vendor = "Cortron";
  572. psmouse->name = "PS/2 Trackball";
  573. __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
  574. __set_bit(BTN_SIDE, psmouse->dev->keybit);
  575. }
  576. return 0;
  577. }
  578. /*
  579. * Apply default settings to the psmouse structure. Most of them will
  580. * be overridden by individual protocol initialization routines.
  581. */
  582. static void psmouse_apply_defaults(struct psmouse *psmouse)
  583. {
  584. struct input_dev *input_dev = psmouse->dev;
  585. memset(input_dev->evbit, 0, sizeof(input_dev->evbit));
  586. memset(input_dev->keybit, 0, sizeof(input_dev->keybit));
  587. memset(input_dev->relbit, 0, sizeof(input_dev->relbit));
  588. memset(input_dev->absbit, 0, sizeof(input_dev->absbit));
  589. memset(input_dev->mscbit, 0, sizeof(input_dev->mscbit));
  590. __set_bit(EV_KEY, input_dev->evbit);
  591. __set_bit(EV_REL, input_dev->evbit);
  592. __set_bit(BTN_LEFT, input_dev->keybit);
  593. __set_bit(BTN_RIGHT, input_dev->keybit);
  594. __set_bit(REL_X, input_dev->relbit);
  595. __set_bit(REL_Y, input_dev->relbit);
  596. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  597. psmouse->set_rate = psmouse_set_rate;
  598. psmouse->set_resolution = psmouse_set_resolution;
  599. psmouse->set_scale = psmouse_set_scale;
  600. psmouse->poll = psmouse_poll;
  601. psmouse->protocol_handler = psmouse_process_byte;
  602. psmouse->pktsize = 3;
  603. psmouse->reconnect = NULL;
  604. psmouse->disconnect = NULL;
  605. psmouse->cleanup = NULL;
  606. psmouse->pt_activate = NULL;
  607. psmouse->pt_deactivate = NULL;
  608. }
  609. /*
  610. * Apply default settings to the psmouse structure and call specified
  611. * protocol detection or initialization routine.
  612. */
  613. static int psmouse_do_detect(int (*detect)(struct psmouse *psmouse,
  614. bool set_properties),
  615. struct psmouse *psmouse, bool set_properties)
  616. {
  617. if (set_properties)
  618. psmouse_apply_defaults(psmouse);
  619. return detect(psmouse, set_properties);
  620. }
  621. /*
  622. * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
  623. * the mouse may have.
  624. */
  625. static int psmouse_extensions(struct psmouse *psmouse,
  626. unsigned int max_proto, bool set_properties)
  627. {
  628. bool synaptics_hardware = false;
  629. /* Always check for focaltech, this is safe as it uses pnp-id matching */
  630. if (psmouse_do_detect(focaltech_detect, psmouse, set_properties) == 0) {
  631. if (max_proto > PSMOUSE_IMEX) {
  632. if (!set_properties || focaltech_init(psmouse) == 0) {
  633. if (IS_ENABLED(CONFIG_MOUSE_PS2_FOCALTECH))
  634. return PSMOUSE_FOCALTECH;
  635. /*
  636. * Note that we need to also restrict
  637. * psmouse_max_proto so that psmouse_initialize()
  638. * does not try to reset rate and resolution,
  639. * because even that upsets the device.
  640. */
  641. psmouse_max_proto = PSMOUSE_PS2;
  642. return PSMOUSE_PS2;
  643. }
  644. }
  645. }
  646. /*
  647. * We always check for lifebook because it does not disturb mouse
  648. * (it only checks DMI information).
  649. */
  650. if (psmouse_do_detect(lifebook_detect, psmouse, set_properties) == 0) {
  651. if (max_proto > PSMOUSE_IMEX) {
  652. if (!set_properties || lifebook_init(psmouse) == 0)
  653. return PSMOUSE_LIFEBOOK;
  654. }
  655. }
  656. /*
  657. * Try Kensington ThinkingMouse (we try first, because synaptics probe
  658. * upsets the thinkingmouse).
  659. */
  660. if (max_proto > PSMOUSE_IMEX &&
  661. psmouse_do_detect(thinking_detect, psmouse, set_properties) == 0) {
  662. return PSMOUSE_THINKPS;
  663. }
  664. /*
  665. * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol
  666. * support is disabled in config - we need to know if it is synaptics so we
  667. * can reset it properly after probing for intellimouse.
  668. */
  669. if (max_proto > PSMOUSE_PS2 &&
  670. psmouse_do_detect(synaptics_detect, psmouse, set_properties) == 0) {
  671. synaptics_hardware = true;
  672. if (max_proto > PSMOUSE_IMEX) {
  673. /*
  674. * Try activating protocol, but check if support is enabled first, since
  675. * we try detecting Synaptics even when protocol is disabled.
  676. */
  677. if (IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS) &&
  678. (!set_properties || synaptics_init(psmouse) == 0)) {
  679. return PSMOUSE_SYNAPTICS;
  680. }
  681. /*
  682. * Some Synaptics touchpads can emulate extended protocols (like IMPS/2).
  683. * Unfortunately Logitech/Genius probes confuse some firmware versions so
  684. * we'll have to skip them.
  685. */
  686. max_proto = PSMOUSE_IMEX;
  687. }
  688. /*
  689. * Make sure that touchpad is in relative mode, gestures (taps) are enabled
  690. */
  691. synaptics_reset(psmouse);
  692. }
  693. /*
  694. * Try Cypress Trackpad.
  695. * Must try it before Finger Sensing Pad because Finger Sensing Pad probe
  696. * upsets some modules of Cypress Trackpads.
  697. */
  698. if (max_proto > PSMOUSE_IMEX &&
  699. cypress_detect(psmouse, set_properties) == 0) {
  700. if (IS_ENABLED(CONFIG_MOUSE_PS2_CYPRESS)) {
  701. if (cypress_init(psmouse) == 0)
  702. return PSMOUSE_CYPRESS;
  703. /*
  704. * Finger Sensing Pad probe upsets some modules of
  705. * Cypress Trackpad, must avoid Finger Sensing Pad
  706. * probe if Cypress Trackpad device detected.
  707. */
  708. return PSMOUSE_PS2;
  709. }
  710. max_proto = PSMOUSE_IMEX;
  711. }
  712. /*
  713. * Try ALPS TouchPad
  714. */
  715. if (max_proto > PSMOUSE_IMEX) {
  716. ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
  717. if (psmouse_do_detect(alps_detect,
  718. psmouse, set_properties) == 0) {
  719. if (!set_properties || alps_init(psmouse) == 0)
  720. return PSMOUSE_ALPS;
  721. /*
  722. * Init failed, try basic relative protocols
  723. */
  724. max_proto = PSMOUSE_IMEX;
  725. }
  726. }
  727. /*
  728. * Try OLPC HGPK touchpad.
  729. */
  730. if (max_proto > PSMOUSE_IMEX &&
  731. psmouse_do_detect(hgpk_detect, psmouse, set_properties) == 0) {
  732. if (!set_properties || hgpk_init(psmouse) == 0)
  733. return PSMOUSE_HGPK;
  734. /*
  735. * Init failed, try basic relative protocols
  736. */
  737. max_proto = PSMOUSE_IMEX;
  738. }
  739. /*
  740. * Try Elantech touchpad.
  741. */
  742. if (max_proto > PSMOUSE_IMEX &&
  743. psmouse_do_detect(elantech_detect, psmouse, set_properties) == 0) {
  744. if (!set_properties || elantech_init(psmouse) == 0)
  745. return PSMOUSE_ELANTECH;
  746. /*
  747. * Init failed, try basic relative protocols
  748. */
  749. max_proto = PSMOUSE_IMEX;
  750. }
  751. if (max_proto > PSMOUSE_IMEX) {
  752. if (psmouse_do_detect(genius_detect,
  753. psmouse, set_properties) == 0)
  754. return PSMOUSE_GENPS;
  755. if (psmouse_do_detect(ps2pp_init,
  756. psmouse, set_properties) == 0)
  757. return PSMOUSE_PS2PP;
  758. if (psmouse_do_detect(trackpoint_detect,
  759. psmouse, set_properties) == 0)
  760. return PSMOUSE_TRACKPOINT;
  761. if (psmouse_do_detect(touchkit_ps2_detect,
  762. psmouse, set_properties) == 0)
  763. return PSMOUSE_TOUCHKIT_PS2;
  764. }
  765. /*
  766. * Try Finger Sensing Pad. We do it here because its probe upsets
  767. * Trackpoint devices (causing TP_READ_ID command to time out).
  768. */
  769. if (max_proto > PSMOUSE_IMEX) {
  770. if (psmouse_do_detect(fsp_detect,
  771. psmouse, set_properties) == 0) {
  772. if (!set_properties || fsp_init(psmouse) == 0)
  773. return PSMOUSE_FSP;
  774. /*
  775. * Init failed, try basic relative protocols
  776. */
  777. max_proto = PSMOUSE_IMEX;
  778. }
  779. }
  780. /*
  781. * Reset to defaults in case the device got confused by extended
  782. * protocol probes. Note that we follow up with full reset because
  783. * some mice put themselves to sleep when they see PSMOUSE_RESET_DIS.
  784. */
  785. ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
  786. psmouse_reset(psmouse);
  787. if (max_proto >= PSMOUSE_IMEX &&
  788. psmouse_do_detect(im_explorer_detect,
  789. psmouse, set_properties) == 0) {
  790. return PSMOUSE_IMEX;
  791. }
  792. if (max_proto >= PSMOUSE_IMPS &&
  793. psmouse_do_detect(intellimouse_detect,
  794. psmouse, set_properties) == 0) {
  795. return PSMOUSE_IMPS;
  796. }
  797. /*
  798. * Okay, all failed, we have a standard mouse here. The number of the buttons
  799. * is still a question, though. We assume 3.
  800. */
  801. psmouse_do_detect(ps2bare_detect, psmouse, set_properties);
  802. if (synaptics_hardware) {
  803. /*
  804. * We detected Synaptics hardware but it did not respond to IMPS/2 probes.
  805. * We need to reset the touchpad because if there is a track point on the
  806. * pass through port it could get disabled while probing for protocol
  807. * extensions.
  808. */
  809. psmouse_reset(psmouse);
  810. }
  811. return PSMOUSE_PS2;
  812. }
  813. static const struct psmouse_protocol psmouse_protocols[] = {
  814. {
  815. .type = PSMOUSE_PS2,
  816. .name = "PS/2",
  817. .alias = "bare",
  818. .maxproto = true,
  819. .ignore_parity = true,
  820. .detect = ps2bare_detect,
  821. },
  822. #ifdef CONFIG_MOUSE_PS2_LOGIPS2PP
  823. {
  824. .type = PSMOUSE_PS2PP,
  825. .name = "PS2++",
  826. .alias = "logitech",
  827. .detect = ps2pp_init,
  828. },
  829. #endif
  830. {
  831. .type = PSMOUSE_THINKPS,
  832. .name = "ThinkPS/2",
  833. .alias = "thinkps",
  834. .detect = thinking_detect,
  835. },
  836. #ifdef CONFIG_MOUSE_PS2_CYPRESS
  837. {
  838. .type = PSMOUSE_CYPRESS,
  839. .name = "CyPS/2",
  840. .alias = "cypress",
  841. .detect = cypress_detect,
  842. .init = cypress_init,
  843. },
  844. #endif
  845. {
  846. .type = PSMOUSE_GENPS,
  847. .name = "GenPS/2",
  848. .alias = "genius",
  849. .detect = genius_detect,
  850. },
  851. {
  852. .type = PSMOUSE_IMPS,
  853. .name = "ImPS/2",
  854. .alias = "imps",
  855. .maxproto = true,
  856. .ignore_parity = true,
  857. .detect = intellimouse_detect,
  858. },
  859. {
  860. .type = PSMOUSE_IMEX,
  861. .name = "ImExPS/2",
  862. .alias = "exps",
  863. .maxproto = true,
  864. .ignore_parity = true,
  865. .detect = im_explorer_detect,
  866. },
  867. #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
  868. {
  869. .type = PSMOUSE_SYNAPTICS,
  870. .name = "SynPS/2",
  871. .alias = "synaptics",
  872. .detect = synaptics_detect,
  873. .init = synaptics_init,
  874. },
  875. {
  876. .type = PSMOUSE_SYNAPTICS_RELATIVE,
  877. .name = "SynRelPS/2",
  878. .alias = "synaptics-relative",
  879. .detect = synaptics_detect,
  880. .init = synaptics_init_relative,
  881. },
  882. #endif
  883. #ifdef CONFIG_MOUSE_PS2_ALPS
  884. {
  885. .type = PSMOUSE_ALPS,
  886. .name = "AlpsPS/2",
  887. .alias = "alps",
  888. .detect = alps_detect,
  889. .init = alps_init,
  890. },
  891. #endif
  892. #ifdef CONFIG_MOUSE_PS2_LIFEBOOK
  893. {
  894. .type = PSMOUSE_LIFEBOOK,
  895. .name = "LBPS/2",
  896. .alias = "lifebook",
  897. .init = lifebook_init,
  898. },
  899. #endif
  900. #ifdef CONFIG_MOUSE_PS2_TRACKPOINT
  901. {
  902. .type = PSMOUSE_TRACKPOINT,
  903. .name = "TPPS/2",
  904. .alias = "trackpoint",
  905. .detect = trackpoint_detect,
  906. },
  907. #endif
  908. #ifdef CONFIG_MOUSE_PS2_TOUCHKIT
  909. {
  910. .type = PSMOUSE_TOUCHKIT_PS2,
  911. .name = "touchkitPS/2",
  912. .alias = "touchkit",
  913. .detect = touchkit_ps2_detect,
  914. },
  915. #endif
  916. #ifdef CONFIG_MOUSE_PS2_OLPC
  917. {
  918. .type = PSMOUSE_HGPK,
  919. .name = "OLPC HGPK",
  920. .alias = "hgpk",
  921. .detect = hgpk_detect,
  922. },
  923. #endif
  924. #ifdef CONFIG_MOUSE_PS2_ELANTECH
  925. {
  926. .type = PSMOUSE_ELANTECH,
  927. .name = "ETPS/2",
  928. .alias = "elantech",
  929. .detect = elantech_detect,
  930. .init = elantech_init,
  931. },
  932. #endif
  933. #ifdef CONFIG_MOUSE_PS2_SENTELIC
  934. {
  935. .type = PSMOUSE_FSP,
  936. .name = "FSPPS/2",
  937. .alias = "fsp",
  938. .detect = fsp_detect,
  939. .init = fsp_init,
  940. },
  941. #endif
  942. {
  943. .type = PSMOUSE_CORTRON,
  944. .name = "CortronPS/2",
  945. .alias = "cortps",
  946. .detect = cortron_detect,
  947. },
  948. #ifdef CONFIG_MOUSE_PS2_FOCALTECH
  949. {
  950. .type = PSMOUSE_FOCALTECH,
  951. .name = "FocalTechPS/2",
  952. .alias = "focaltech",
  953. .detect = focaltech_detect,
  954. .init = focaltech_init,
  955. },
  956. #endif
  957. {
  958. .type = PSMOUSE_AUTO,
  959. .name = "auto",
  960. .alias = "any",
  961. .maxproto = true,
  962. },
  963. };
  964. static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
  965. {
  966. int i;
  967. for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++)
  968. if (psmouse_protocols[i].type == type)
  969. return &psmouse_protocols[i];
  970. WARN_ON(1);
  971. return &psmouse_protocols[0];
  972. }
  973. static const struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len)
  974. {
  975. const struct psmouse_protocol *p;
  976. int i;
  977. for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) {
  978. p = &psmouse_protocols[i];
  979. if ((strlen(p->name) == len && !strncmp(p->name, name, len)) ||
  980. (strlen(p->alias) == len && !strncmp(p->alias, name, len)))
  981. return &psmouse_protocols[i];
  982. }
  983. return NULL;
  984. }
  985. /*
  986. * psmouse_probe() probes for a PS/2 mouse.
  987. */
  988. static int psmouse_probe(struct psmouse *psmouse)
  989. {
  990. struct ps2dev *ps2dev = &psmouse->ps2dev;
  991. unsigned char param[2];
  992. /*
  993. * First, we check if it's a mouse. It should send 0x00 or 0x03
  994. * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer.
  995. * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and subsequent
  996. * ID queries, probably due to a firmware bug.
  997. */
  998. param[0] = 0xa5;
  999. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
  1000. return -1;
  1001. if (param[0] != 0x00 && param[0] != 0x03 &&
  1002. param[0] != 0x04 && param[0] != 0xff)
  1003. return -1;
  1004. /*
  1005. * Then we reset and disable the mouse so that it doesn't generate events.
  1006. */
  1007. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS))
  1008. psmouse_warn(psmouse, "Failed to reset mouse on %s\n",
  1009. ps2dev->serio->phys);
  1010. return 0;
  1011. }
  1012. /*
  1013. * psmouse_initialize() initializes the mouse to a sane state.
  1014. */
  1015. static void psmouse_initialize(struct psmouse *psmouse)
  1016. {
  1017. /*
  1018. * We set the mouse report rate, resolution and scaling.
  1019. */
  1020. if (psmouse_max_proto != PSMOUSE_PS2) {
  1021. psmouse->set_rate(psmouse, psmouse->rate);
  1022. psmouse->set_resolution(psmouse, psmouse->resolution);
  1023. psmouse->set_scale(psmouse, PSMOUSE_SCALE11);
  1024. }
  1025. }
  1026. /*
  1027. * psmouse_activate() enables the mouse so that we get motion reports from it.
  1028. */
  1029. int psmouse_activate(struct psmouse *psmouse)
  1030. {
  1031. if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
  1032. psmouse_warn(psmouse, "Failed to enable mouse on %s\n",
  1033. psmouse->ps2dev.serio->phys);
  1034. return -1;
  1035. }
  1036. psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
  1037. return 0;
  1038. }
  1039. /*
  1040. * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion
  1041. * reports from it unless we explicitly request it.
  1042. */
  1043. int psmouse_deactivate(struct psmouse *psmouse)
  1044. {
  1045. if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) {
  1046. psmouse_warn(psmouse, "Failed to deactivate mouse on %s\n",
  1047. psmouse->ps2dev.serio->phys);
  1048. return -1;
  1049. }
  1050. psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
  1051. return 0;
  1052. }
  1053. /*
  1054. * psmouse_resync() attempts to re-validate current protocol.
  1055. */
  1056. static void psmouse_resync(struct work_struct *work)
  1057. {
  1058. struct psmouse *parent = NULL, *psmouse =
  1059. container_of(work, struct psmouse, resync_work.work);
  1060. struct serio *serio = psmouse->ps2dev.serio;
  1061. psmouse_ret_t rc = PSMOUSE_GOOD_DATA;
  1062. bool failed = false, enabled = false;
  1063. int i;
  1064. mutex_lock(&psmouse_mutex);
  1065. if (psmouse->state != PSMOUSE_RESYNCING)
  1066. goto out;
  1067. if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
  1068. parent = serio_get_drvdata(serio->parent);
  1069. psmouse_deactivate(parent);
  1070. }
  1071. /*
  1072. * Some mice don't ACK commands sent while they are in the middle of
  1073. * transmitting motion packet. To avoid delay we use ps2_sendbyte()
  1074. * instead of ps2_command() which would wait for 200ms for an ACK
  1075. * that may never come.
  1076. * As an additional quirk ALPS touchpads may not only forget to ACK
  1077. * disable command but will stop reporting taps, so if we see that
  1078. * mouse at least once ACKs disable we will do full reconnect if ACK
  1079. * is missing.
  1080. */
  1081. psmouse->num_resyncs++;
  1082. if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) {
  1083. if (psmouse->num_resyncs < 3 || psmouse->acks_disable_command)
  1084. failed = true;
  1085. } else
  1086. psmouse->acks_disable_command = true;
  1087. /*
  1088. * Poll the mouse. If it was reset the packet will be shorter than
  1089. * psmouse->pktsize and ps2_command will fail. We do not expect and
  1090. * do not handle scenario when mouse "upgrades" its protocol while
  1091. * disconnected since it would require additional delay. If we ever
  1092. * see a mouse that does it we'll adjust the code.
  1093. */
  1094. if (!failed) {
  1095. if (psmouse->poll(psmouse))
  1096. failed = true;
  1097. else {
  1098. psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
  1099. for (i = 0; i < psmouse->pktsize; i++) {
  1100. psmouse->pktcnt++;
  1101. rc = psmouse->protocol_handler(psmouse);
  1102. if (rc != PSMOUSE_GOOD_DATA)
  1103. break;
  1104. }
  1105. if (rc != PSMOUSE_FULL_PACKET)
  1106. failed = true;
  1107. psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
  1108. }
  1109. }
  1110. /*
  1111. * Now try to enable mouse. We try to do that even if poll failed and also
  1112. * repeat our attempts 5 times, otherwise we may be left out with disabled
  1113. * mouse.
  1114. */
  1115. for (i = 0; i < 5; i++) {
  1116. if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
  1117. enabled = true;
  1118. break;
  1119. }
  1120. msleep(200);
  1121. }
  1122. if (!enabled) {
  1123. psmouse_warn(psmouse, "failed to re-enable mouse on %s\n",
  1124. psmouse->ps2dev.serio->phys);
  1125. failed = true;
  1126. }
  1127. if (failed) {
  1128. psmouse_set_state(psmouse, PSMOUSE_IGNORE);
  1129. psmouse_info(psmouse,
  1130. "resync failed, issuing reconnect request\n");
  1131. serio_reconnect(serio);
  1132. } else
  1133. psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
  1134. if (parent)
  1135. psmouse_activate(parent);
  1136. out:
  1137. mutex_unlock(&psmouse_mutex);
  1138. }
  1139. /*
  1140. * psmouse_cleanup() resets the mouse into power-on state.
  1141. */
  1142. static void psmouse_cleanup(struct serio *serio)
  1143. {
  1144. struct psmouse *psmouse = serio_get_drvdata(serio);
  1145. struct psmouse *parent = NULL;
  1146. mutex_lock(&psmouse_mutex);
  1147. if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
  1148. parent = serio_get_drvdata(serio->parent);
  1149. psmouse_deactivate(parent);
  1150. }
  1151. psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
  1152. /*
  1153. * Disable stream mode so cleanup routine can proceed undisturbed.
  1154. */
  1155. if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE))
  1156. psmouse_warn(psmouse, "Failed to disable mouse on %s\n",
  1157. psmouse->ps2dev.serio->phys);
  1158. if (psmouse->cleanup)
  1159. psmouse->cleanup(psmouse);
  1160. /*
  1161. * Reset the mouse to defaults (bare PS/2 protocol).
  1162. */
  1163. ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
  1164. /*
  1165. * Some boxes, such as HP nx7400, get terribly confused if mouse
  1166. * is not fully enabled before suspending/shutting down.
  1167. */
  1168. ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
  1169. if (parent) {
  1170. if (parent->pt_deactivate)
  1171. parent->pt_deactivate(parent);
  1172. psmouse_activate(parent);
  1173. }
  1174. mutex_unlock(&psmouse_mutex);
  1175. }
  1176. /*
  1177. * psmouse_disconnect() closes and frees.
  1178. */
  1179. static void psmouse_disconnect(struct serio *serio)
  1180. {
  1181. struct psmouse *psmouse, *parent = NULL;
  1182. psmouse = serio_get_drvdata(serio);
  1183. sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group);
  1184. mutex_lock(&psmouse_mutex);
  1185. psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
  1186. /* make sure we don't have a resync in progress */
  1187. mutex_unlock(&psmouse_mutex);
  1188. flush_workqueue(kpsmoused_wq);
  1189. mutex_lock(&psmouse_mutex);
  1190. if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
  1191. parent = serio_get_drvdata(serio->parent);
  1192. psmouse_deactivate(parent);
  1193. }
  1194. if (psmouse->disconnect)
  1195. psmouse->disconnect(psmouse);
  1196. if (parent && parent->pt_deactivate)
  1197. parent->pt_deactivate(parent);
  1198. psmouse_set_state(psmouse, PSMOUSE_IGNORE);
  1199. serio_close(serio);
  1200. serio_set_drvdata(serio, NULL);
  1201. input_unregister_device(psmouse->dev);
  1202. kfree(psmouse);
  1203. if (parent)
  1204. psmouse_activate(parent);
  1205. mutex_unlock(&psmouse_mutex);
  1206. }
  1207. static int psmouse_switch_protocol(struct psmouse *psmouse,
  1208. const struct psmouse_protocol *proto)
  1209. {
  1210. const struct psmouse_protocol *selected_proto;
  1211. struct input_dev *input_dev = psmouse->dev;
  1212. input_dev->dev.parent = &psmouse->ps2dev.serio->dev;
  1213. if (proto && (proto->detect || proto->init)) {
  1214. psmouse_apply_defaults(psmouse);
  1215. if (proto->detect && proto->detect(psmouse, true) < 0)
  1216. return -1;
  1217. if (proto->init && proto->init(psmouse) < 0)
  1218. return -1;
  1219. psmouse->type = proto->type;
  1220. selected_proto = proto;
  1221. } else {
  1222. psmouse->type = psmouse_extensions(psmouse,
  1223. psmouse_max_proto, true);
  1224. selected_proto = psmouse_protocol_by_type(psmouse->type);
  1225. }
  1226. psmouse->ignore_parity = selected_proto->ignore_parity;
  1227. /*
  1228. * If mouse's packet size is 3 there is no point in polling the
  1229. * device in hopes to detect protocol reset - we won't get less
  1230. * than 3 bytes response anyhow.
  1231. */
  1232. if (psmouse->pktsize == 3)
  1233. psmouse->resync_time = 0;
  1234. /*
  1235. * Some smart KVMs fake response to POLL command returning just
  1236. * 3 bytes and messing up our resync logic, so if initial poll
  1237. * fails we won't try polling the device anymore. Hopefully
  1238. * such KVM will maintain initially selected protocol.
  1239. */
  1240. if (psmouse->resync_time && psmouse->poll(psmouse))
  1241. psmouse->resync_time = 0;
  1242. snprintf(psmouse->devname, sizeof(psmouse->devname), "%s %s %s",
  1243. selected_proto->name, psmouse->vendor, psmouse->name);
  1244. input_dev->name = psmouse->devname;
  1245. input_dev->phys = psmouse->phys;
  1246. input_dev->id.bustype = BUS_I8042;
  1247. input_dev->id.vendor = 0x0002;
  1248. input_dev->id.product = psmouse->type;
  1249. input_dev->id.version = psmouse->model;
  1250. return 0;
  1251. }
  1252. /*
  1253. * psmouse_connect() is a callback from the serio module when
  1254. * an unhandled serio port is found.
  1255. */
  1256. static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
  1257. {
  1258. struct psmouse *psmouse, *parent = NULL;
  1259. struct input_dev *input_dev;
  1260. int retval = 0, error = -ENOMEM;
  1261. mutex_lock(&psmouse_mutex);
  1262. /*
  1263. * If this is a pass-through port deactivate parent so the device
  1264. * connected to this port can be successfully identified
  1265. */
  1266. if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
  1267. parent = serio_get_drvdata(serio->parent);
  1268. psmouse_deactivate(parent);
  1269. }
  1270. psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
  1271. input_dev = input_allocate_device();
  1272. if (!psmouse || !input_dev)
  1273. goto err_free;
  1274. ps2_init(&psmouse->ps2dev, serio);
  1275. INIT_DELAYED_WORK(&psmouse->resync_work, psmouse_resync);
  1276. psmouse->dev = input_dev;
  1277. snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys);
  1278. psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
  1279. serio_set_drvdata(serio, psmouse);
  1280. error = serio_open(serio, drv);
  1281. if (error)
  1282. goto err_clear_drvdata;
  1283. if (psmouse_probe(psmouse) < 0) {
  1284. error = -ENODEV;
  1285. goto err_close_serio;
  1286. }
  1287. psmouse->rate = psmouse_rate;
  1288. psmouse->resolution = psmouse_resolution;
  1289. psmouse->resetafter = psmouse_resetafter;
  1290. psmouse->resync_time = parent ? 0 : psmouse_resync_time;
  1291. psmouse->smartscroll = psmouse_smartscroll;
  1292. psmouse_switch_protocol(psmouse, NULL);
  1293. psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
  1294. psmouse_initialize(psmouse);
  1295. error = input_register_device(psmouse->dev);
  1296. if (error)
  1297. goto err_protocol_disconnect;
  1298. if (parent && parent->pt_activate)
  1299. parent->pt_activate(parent);
  1300. error = sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
  1301. if (error)
  1302. goto err_pt_deactivate;
  1303. psmouse_activate(psmouse);
  1304. out:
  1305. /* If this is a pass-through port the parent needs to be re-activated */
  1306. if (parent)
  1307. psmouse_activate(parent);
  1308. mutex_unlock(&psmouse_mutex);
  1309. return retval;
  1310. err_pt_deactivate:
  1311. if (parent && parent->pt_deactivate)
  1312. parent->pt_deactivate(parent);
  1313. input_unregister_device(psmouse->dev);
  1314. input_dev = NULL; /* so we don't try to free it below */
  1315. err_protocol_disconnect:
  1316. if (psmouse->disconnect)
  1317. psmouse->disconnect(psmouse);
  1318. psmouse_set_state(psmouse, PSMOUSE_IGNORE);
  1319. err_close_serio:
  1320. serio_close(serio);
  1321. err_clear_drvdata:
  1322. serio_set_drvdata(serio, NULL);
  1323. err_free:
  1324. input_free_device(input_dev);
  1325. kfree(psmouse);
  1326. retval = error;
  1327. goto out;
  1328. }
  1329. static int psmouse_reconnect(struct serio *serio)
  1330. {
  1331. struct psmouse *psmouse = serio_get_drvdata(serio);
  1332. struct psmouse *parent = NULL;
  1333. unsigned char type;
  1334. int rc = -1;
  1335. mutex_lock(&psmouse_mutex);
  1336. if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
  1337. parent = serio_get_drvdata(serio->parent);
  1338. psmouse_deactivate(parent);
  1339. }
  1340. psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
  1341. if (psmouse->reconnect) {
  1342. if (psmouse->reconnect(psmouse))
  1343. goto out;
  1344. } else {
  1345. psmouse_reset(psmouse);
  1346. if (psmouse_probe(psmouse) < 0)
  1347. goto out;
  1348. type = psmouse_extensions(psmouse, psmouse_max_proto, false);
  1349. if (psmouse->type != type)
  1350. goto out;
  1351. }
  1352. /*
  1353. * OK, the device type (and capabilities) match the old one,
  1354. * we can continue using it, complete initialization
  1355. */
  1356. psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
  1357. psmouse_initialize(psmouse);
  1358. if (parent && parent->pt_activate)
  1359. parent->pt_activate(parent);
  1360. psmouse_activate(psmouse);
  1361. rc = 0;
  1362. out:
  1363. /* If this is a pass-through port the parent waits to be activated */
  1364. if (parent)
  1365. psmouse_activate(parent);
  1366. mutex_unlock(&psmouse_mutex);
  1367. return rc;
  1368. }
  1369. static struct serio_device_id psmouse_serio_ids[] = {
  1370. {
  1371. .type = SERIO_8042,
  1372. .proto = SERIO_ANY,
  1373. .id = SERIO_ANY,
  1374. .extra = SERIO_ANY,
  1375. },
  1376. {
  1377. .type = SERIO_PS_PSTHRU,
  1378. .proto = SERIO_ANY,
  1379. .id = SERIO_ANY,
  1380. .extra = SERIO_ANY,
  1381. },
  1382. { 0 }
  1383. };
  1384. MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
  1385. static struct serio_driver psmouse_drv = {
  1386. .driver = {
  1387. .name = "psmouse",
  1388. },
  1389. .description = DRIVER_DESC,
  1390. .id_table = psmouse_serio_ids,
  1391. .interrupt = psmouse_interrupt,
  1392. .connect = psmouse_connect,
  1393. .reconnect = psmouse_reconnect,
  1394. .disconnect = psmouse_disconnect,
  1395. .cleanup = psmouse_cleanup,
  1396. };
  1397. ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *devattr,
  1398. char *buf)
  1399. {
  1400. struct serio *serio = to_serio_port(dev);
  1401. struct psmouse_attribute *attr = to_psmouse_attr(devattr);
  1402. struct psmouse *psmouse;
  1403. psmouse = serio_get_drvdata(serio);
  1404. return attr->show(psmouse, attr->data, buf);
  1405. }
  1406. ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *devattr,
  1407. const char *buf, size_t count)
  1408. {
  1409. struct serio *serio = to_serio_port(dev);
  1410. struct psmouse_attribute *attr = to_psmouse_attr(devattr);
  1411. struct psmouse *psmouse, *parent = NULL;
  1412. int retval;
  1413. retval = mutex_lock_interruptible(&psmouse_mutex);
  1414. if (retval)
  1415. goto out;
  1416. psmouse = serio_get_drvdata(serio);
  1417. if (attr->protect) {
  1418. if (psmouse->state == PSMOUSE_IGNORE) {
  1419. retval = -ENODEV;
  1420. goto out_unlock;
  1421. }
  1422. if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
  1423. parent = serio_get_drvdata(serio->parent);
  1424. psmouse_deactivate(parent);
  1425. }
  1426. psmouse_deactivate(psmouse);
  1427. }
  1428. retval = attr->set(psmouse, attr->data, buf, count);
  1429. if (attr->protect) {
  1430. if (retval != -ENODEV)
  1431. psmouse_activate(psmouse);
  1432. if (parent)
  1433. psmouse_activate(parent);
  1434. }
  1435. out_unlock:
  1436. mutex_unlock(&psmouse_mutex);
  1437. out:
  1438. return retval;
  1439. }
  1440. static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf)
  1441. {
  1442. unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
  1443. return sprintf(buf, "%u\n", *field);
  1444. }
  1445. static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
  1446. {
  1447. unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
  1448. unsigned int value;
  1449. int err;
  1450. err = kstrtouint(buf, 10, &value);
  1451. if (err)
  1452. return err;
  1453. *field = value;
  1454. return count;
  1455. }
  1456. static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, void *data, char *buf)
  1457. {
  1458. return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
  1459. }
  1460. static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, const char *buf, size_t count)
  1461. {
  1462. struct serio *serio = psmouse->ps2dev.serio;
  1463. struct psmouse *parent = NULL;
  1464. struct input_dev *old_dev, *new_dev;
  1465. const struct psmouse_protocol *proto, *old_proto;
  1466. int error;
  1467. int retry = 0;
  1468. proto = psmouse_protocol_by_name(buf, count);
  1469. if (!proto)
  1470. return -EINVAL;
  1471. if (psmouse->type == proto->type)
  1472. return count;
  1473. new_dev = input_allocate_device();
  1474. if (!new_dev)
  1475. return -ENOMEM;
  1476. while (!list_empty(&serio->children)) {
  1477. if (++retry > 3) {
  1478. psmouse_warn(psmouse,
  1479. "failed to destroy children ports, protocol change aborted.\n");
  1480. input_free_device(new_dev);
  1481. return -EIO;
  1482. }
  1483. mutex_unlock(&psmouse_mutex);
  1484. serio_unregister_child_port(serio);
  1485. mutex_lock(&psmouse_mutex);
  1486. if (serio->drv != &psmouse_drv) {
  1487. input_free_device(new_dev);
  1488. return -ENODEV;
  1489. }
  1490. if (psmouse->type == proto->type) {
  1491. input_free_device(new_dev);
  1492. return count; /* switched by other thread */
  1493. }
  1494. }
  1495. if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
  1496. parent = serio_get_drvdata(serio->parent);
  1497. if (parent->pt_deactivate)
  1498. parent->pt_deactivate(parent);
  1499. }
  1500. old_dev = psmouse->dev;
  1501. old_proto = psmouse_protocol_by_type(psmouse->type);
  1502. if (psmouse->disconnect)
  1503. psmouse->disconnect(psmouse);
  1504. psmouse_set_state(psmouse, PSMOUSE_IGNORE);
  1505. psmouse->dev = new_dev;
  1506. psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
  1507. if (psmouse_switch_protocol(psmouse, proto) < 0) {
  1508. psmouse_reset(psmouse);
  1509. /* default to PSMOUSE_PS2 */
  1510. psmouse_switch_protocol(psmouse, &psmouse_protocols[0]);
  1511. }
  1512. psmouse_initialize(psmouse);
  1513. psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
  1514. error = input_register_device(psmouse->dev);
  1515. if (error) {
  1516. if (psmouse->disconnect)
  1517. psmouse->disconnect(psmouse);
  1518. psmouse_set_state(psmouse, PSMOUSE_IGNORE);
  1519. input_free_device(new_dev);
  1520. psmouse->dev = old_dev;
  1521. psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
  1522. psmouse_switch_protocol(psmouse, old_proto);
  1523. psmouse_initialize(psmouse);
  1524. psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
  1525. return error;
  1526. }
  1527. input_unregister_device(old_dev);
  1528. if (parent && parent->pt_activate)
  1529. parent->pt_activate(parent);
  1530. return count;
  1531. }
  1532. static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
  1533. {
  1534. unsigned int value;
  1535. int err;
  1536. err = kstrtouint(buf, 10, &value);
  1537. if (err)
  1538. return err;
  1539. psmouse->set_rate(psmouse, value);
  1540. return count;
  1541. }
  1542. static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
  1543. {
  1544. unsigned int value;
  1545. int err;
  1546. err = kstrtouint(buf, 10, &value);
  1547. if (err)
  1548. return err;
  1549. psmouse->set_resolution(psmouse, value);
  1550. return count;
  1551. }
  1552. static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp)
  1553. {
  1554. const struct psmouse_protocol *proto;
  1555. if (!val)
  1556. return -EINVAL;
  1557. proto = psmouse_protocol_by_name(val, strlen(val));
  1558. if (!proto || !proto->maxproto)
  1559. return -EINVAL;
  1560. *((unsigned int *)kp->arg) = proto->type;
  1561. return 0;
  1562. }
  1563. static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp)
  1564. {
  1565. int type = *((unsigned int *)kp->arg);
  1566. return sprintf(buffer, "%s", psmouse_protocol_by_type(type)->name);
  1567. }
  1568. static int __init psmouse_init(void)
  1569. {
  1570. int err;
  1571. lifebook_module_init();
  1572. synaptics_module_init();
  1573. hgpk_module_init();
  1574. kpsmoused_wq = create_singlethread_workqueue("kpsmoused");
  1575. if (!kpsmoused_wq) {
  1576. pr_err("failed to create kpsmoused workqueue\n");
  1577. return -ENOMEM;
  1578. }
  1579. err = serio_register_driver(&psmouse_drv);
  1580. if (err)
  1581. destroy_workqueue(kpsmoused_wq);
  1582. return err;
  1583. }
  1584. static void __exit psmouse_exit(void)
  1585. {
  1586. serio_unregister_driver(&psmouse_drv);
  1587. destroy_workqueue(kpsmoused_wq);
  1588. }
  1589. module_init(psmouse_init);
  1590. module_exit(psmouse_exit);