11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * ALPS touchpad PS/2 mouse driver 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au> 5963f626dSPeter Osterlund * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com> 61da177e4SLinus Torvalds * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru> 71da177e4SLinus Torvalds * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> 81d9f2626SSebastian Kapfer * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net> 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * ALPS detection, tap switching and status querying info is taken from 111da177e4SLinus Torvalds * tpconfig utility (by C. Scott Ananian and Bruce Kall). 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 141da177e4SLinus Torvalds * under the terms of the GNU General Public License version 2 as published by 151da177e4SLinus Torvalds * the Free Software Foundation. 161da177e4SLinus Torvalds */ 171da177e4SLinus Torvalds 185a0e3ad6STejun Heo #include <linux/slab.h> 191da177e4SLinus Torvalds #include <linux/input.h> 2001ce661fSSeth Forshee #include <linux/input/mt.h> 211da177e4SLinus Torvalds #include <linux/serio.h> 221da177e4SLinus Torvalds #include <linux/libps2.h> 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds #include "psmouse.h" 251da177e4SLinus Torvalds #include "alps.h" 261da177e4SLinus Torvalds 2725bded7cSSeth Forshee /* 2825bded7cSSeth Forshee * Definitions for ALPS version 3 and 4 command mode protocol 2925bded7cSSeth Forshee */ 3025bded7cSSeth Forshee #define ALPS_CMD_NIBBLE_10 0x01f2 3125bded7cSSeth Forshee 32cd401204SKevin Cernekee #define ALPS_REG_BASE_RUSHMORE 0xc2c0 33cd401204SKevin Cernekee #define ALPS_REG_BASE_PINNACLE 0x0000 34cd401204SKevin Cernekee 3525bded7cSSeth Forshee static const struct alps_nibble_commands alps_v3_nibble_commands[] = { 3625bded7cSSeth Forshee { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */ 3725bded7cSSeth Forshee { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */ 3825bded7cSSeth Forshee { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */ 3925bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */ 4025bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */ 4125bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */ 4225bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */ 4325bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */ 4425bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */ 4525bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */ 4625bded7cSSeth Forshee { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */ 4725bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x00 }, /* b */ 4825bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x01 }, /* c */ 4925bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x02 }, /* d */ 5025bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x03 }, /* e */ 5125bded7cSSeth Forshee { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */ 5225bded7cSSeth Forshee }; 5325bded7cSSeth Forshee 5425bded7cSSeth Forshee static const struct alps_nibble_commands alps_v4_nibble_commands[] = { 5525bded7cSSeth Forshee { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */ 5625bded7cSSeth Forshee { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */ 5725bded7cSSeth Forshee { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */ 5825bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */ 5925bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */ 6025bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */ 6125bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */ 6225bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */ 6325bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */ 6425bded7cSSeth Forshee { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */ 6525bded7cSSeth Forshee { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */ 6625bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x00 }, /* b */ 6725bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x01 }, /* c */ 6825bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x02 }, /* d */ 6925bded7cSSeth Forshee { PSMOUSE_CMD_SETRES, 0x03 }, /* e */ 7025bded7cSSeth Forshee { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */ 7125bded7cSSeth Forshee }; 7225bded7cSSeth Forshee 7395f75e91SYunkang Tang static const struct alps_nibble_commands alps_v6_nibble_commands[] = { 7495f75e91SYunkang Tang { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */ 7595f75e91SYunkang Tang { PSMOUSE_CMD_SETRATE, 0x0a }, /* 1 */ 7695f75e91SYunkang Tang { PSMOUSE_CMD_SETRATE, 0x14 }, /* 2 */ 7795f75e91SYunkang Tang { PSMOUSE_CMD_SETRATE, 0x28 }, /* 3 */ 7895f75e91SYunkang Tang { PSMOUSE_CMD_SETRATE, 0x3c }, /* 4 */ 7995f75e91SYunkang Tang { PSMOUSE_CMD_SETRATE, 0x50 }, /* 5 */ 8095f75e91SYunkang Tang { PSMOUSE_CMD_SETRATE, 0x64 }, /* 6 */ 8195f75e91SYunkang Tang { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 7 */ 8295f75e91SYunkang Tang { PSMOUSE_CMD_GETID, 0x00 }, /* 8 */ 8395f75e91SYunkang Tang { PSMOUSE_CMD_GETINFO, 0x00 }, /* 9 */ 8495f75e91SYunkang Tang { PSMOUSE_CMD_SETRES, 0x00 }, /* a */ 8595f75e91SYunkang Tang { PSMOUSE_CMD_SETRES, 0x01 }, /* b */ 8695f75e91SYunkang Tang { PSMOUSE_CMD_SETRES, 0x02 }, /* c */ 8795f75e91SYunkang Tang { PSMOUSE_CMD_SETRES, 0x03 }, /* d */ 8895f75e91SYunkang Tang { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* e */ 8995f75e91SYunkang Tang { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */ 9095f75e91SYunkang Tang }; 9195f75e91SYunkang Tang 9225bded7cSSeth Forshee 9371bb21b6SMaxim Levitsky #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */ 9471bb21b6SMaxim Levitsky #define ALPS_PASS 0x04 /* device has a pass-through port */ 9571bb21b6SMaxim Levitsky 9671bb21b6SMaxim Levitsky #define ALPS_WHEEL 0x08 /* hardware wheel present */ 9771bb21b6SMaxim Levitsky #define ALPS_FW_BK_1 0x10 /* front & back buttons present */ 9871bb21b6SMaxim Levitsky #define ALPS_FW_BK_2 0x20 /* front & back buttons present */ 9971bb21b6SMaxim Levitsky #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */ 1001d9f2626SSebastian Kapfer #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with 1011d9f2626SSebastian Kapfer 6-byte ALPS packet */ 10240e8f53bSHans de Goede #define ALPS_IS_RUSHMORE 0x100 /* device is a rushmore */ 1033808843cSYunkang Tang #define ALPS_BUTTONPAD 0x200 /* device is a clickpad */ 1041da177e4SLinus Torvalds 105e38de678SHelge Deller static const struct alps_model_info alps_model_data[] = { 10625bded7cSSeth Forshee { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */ 10725bded7cSSeth Forshee { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */ 10825bded7cSSeth Forshee { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, 10925bded7cSSeth Forshee { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, 11025bded7cSSeth Forshee { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */ 11125bded7cSSeth Forshee { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, 11225bded7cSSeth Forshee { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, 11325bded7cSSeth Forshee { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */ 11425bded7cSSeth Forshee { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */ 11525bded7cSSeth Forshee { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */ 11625bded7cSSeth Forshee { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, 11725bded7cSSeth Forshee { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */ 11825bded7cSSeth Forshee { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */ 11925bded7cSSeth Forshee { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, 12025bded7cSSeth Forshee { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */ 12125bded7cSSeth Forshee { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ 12225bded7cSSeth Forshee { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, 12325bded7cSSeth Forshee { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ 1241d9f2626SSebastian Kapfer /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ 12525bded7cSSeth Forshee { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, 1261d9f2626SSebastian Kapfer ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, 12795f75e91SYunkang Tang { { 0x73, 0x00, 0x14 }, 0x00, ALPS_PROTO_V6, 0xff, 0xff, ALPS_DUALPOINT }, /* Dell XT2 */ 12825bded7cSSeth Forshee { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */ 12925bded7cSSeth Forshee { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, 130eb8bff85SThomas Bächler ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */ 13125bded7cSSeth Forshee { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 }, 1321da177e4SLinus Torvalds }; 1331da177e4SLinus Torvalds 13424af5cb9SKevin Cernekee static void alps_set_abs_params_st(struct alps_data *priv, 13524af5cb9SKevin Cernekee struct input_dev *dev1); 13624af5cb9SKevin Cernekee static void alps_set_abs_params_mt(struct alps_data *priv, 13724af5cb9SKevin Cernekee struct input_dev *dev1); 13824af5cb9SKevin Cernekee 1391da177e4SLinus Torvalds /* 1401da177e4SLinus Torvalds * XXX - this entry is suspicious. First byte has zero lower nibble, 1411da177e4SLinus Torvalds * which is what a normal mouse would report. Also, the value 0x0e 1421da177e4SLinus Torvalds * isn't valid per PS/2 spec. 1431da177e4SLinus Torvalds */ 1441da177e4SLinus Torvalds 145d4b347b2SSeth Forshee /* Packet formats are described in Documentation/input/alps.txt */ 1461da177e4SLinus Torvalds 14799df65e7SKevin Cernekee static bool alps_is_valid_first_byte(struct alps_data *priv, 1481d9f2626SSebastian Kapfer unsigned char data) 1491d9f2626SSebastian Kapfer { 15099df65e7SKevin Cernekee return (data & priv->mask0) == priv->byte0; 1511d9f2626SSebastian Kapfer } 1521d9f2626SSebastian Kapfer 1531d9f2626SSebastian Kapfer static void alps_report_buttons(struct psmouse *psmouse, 1541d9f2626SSebastian Kapfer struct input_dev *dev1, struct input_dev *dev2, 1551d9f2626SSebastian Kapfer int left, int right, int middle) 1561d9f2626SSebastian Kapfer { 1571d9f2626SSebastian Kapfer struct input_dev *dev; 1581d9f2626SSebastian Kapfer 1591d9f2626SSebastian Kapfer /* 1601d9f2626SSebastian Kapfer * If shared button has already been reported on the 1611d9f2626SSebastian Kapfer * other device (dev2) then this event should be also 1621d9f2626SSebastian Kapfer * sent through that device. 1631d9f2626SSebastian Kapfer */ 1641d9f2626SSebastian Kapfer dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1; 1651d9f2626SSebastian Kapfer input_report_key(dev, BTN_LEFT, left); 1661d9f2626SSebastian Kapfer 1671d9f2626SSebastian Kapfer dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1; 1681d9f2626SSebastian Kapfer input_report_key(dev, BTN_RIGHT, right); 1691d9f2626SSebastian Kapfer 1701d9f2626SSebastian Kapfer dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1; 1711d9f2626SSebastian Kapfer input_report_key(dev, BTN_MIDDLE, middle); 1721d9f2626SSebastian Kapfer 1731d9f2626SSebastian Kapfer /* 1741d9f2626SSebastian Kapfer * Sync the _other_ device now, we'll do the first 1751d9f2626SSebastian Kapfer * device later once we report the rest of the events. 1761d9f2626SSebastian Kapfer */ 1771d9f2626SSebastian Kapfer input_sync(dev2); 1781d9f2626SSebastian Kapfer } 1791d9f2626SSebastian Kapfer 18025bded7cSSeth Forshee static void alps_process_packet_v1_v2(struct psmouse *psmouse) 1811da177e4SLinus Torvalds { 1821da177e4SLinus Torvalds struct alps_data *priv = psmouse->private; 1831da177e4SLinus Torvalds unsigned char *packet = psmouse->packet; 1842e5b636bSDmitry Torokhov struct input_dev *dev = psmouse->dev; 1852e5b636bSDmitry Torokhov struct input_dev *dev2 = priv->dev2; 1861da177e4SLinus Torvalds int x, y, z, ges, fin, left, right, middle; 187c30b4c10SIvan Casado Ruiz int back = 0, forward = 0; 1881da177e4SLinus Torvalds 18999df65e7SKevin Cernekee if (priv->proto_version == ALPS_PROTO_V1) { 190d2f4012fSYotam Medini left = packet[2] & 0x10; 191d2f4012fSYotam Medini right = packet[2] & 0x08; 1921da177e4SLinus Torvalds middle = 0; 1931da177e4SLinus Torvalds x = packet[1] | ((packet[0] & 0x07) << 7); 1941da177e4SLinus Torvalds y = packet[4] | ((packet[3] & 0x07) << 7); 1951da177e4SLinus Torvalds z = packet[5]; 1961da177e4SLinus Torvalds } else { 1971da177e4SLinus Torvalds left = packet[3] & 1; 1981da177e4SLinus Torvalds right = packet[3] & 2; 1991da177e4SLinus Torvalds middle = packet[3] & 4; 2001da177e4SLinus Torvalds x = packet[1] | ((packet[2] & 0x78) << (7 - 3)); 2011da177e4SLinus Torvalds y = packet[4] | ((packet[3] & 0x70) << (7 - 4)); 2021da177e4SLinus Torvalds z = packet[5]; 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds 20599df65e7SKevin Cernekee if (priv->flags & ALPS_FW_BK_1) { 2063c00bb96SLaszlo Kajan back = packet[0] & 0x10; 2073c00bb96SLaszlo Kajan forward = packet[2] & 4; 208c30b4c10SIvan Casado Ruiz } 209c30b4c10SIvan Casado Ruiz 21099df65e7SKevin Cernekee if (priv->flags & ALPS_FW_BK_2) { 211c30b4c10SIvan Casado Ruiz back = packet[3] & 4; 212c30b4c10SIvan Casado Ruiz forward = packet[2] & 4; 213c30b4c10SIvan Casado Ruiz if ((middle = forward && back)) 214c30b4c10SIvan Casado Ruiz forward = back = 0; 215c30b4c10SIvan Casado Ruiz } 216c30b4c10SIvan Casado Ruiz 2171da177e4SLinus Torvalds ges = packet[2] & 1; 2181da177e4SLinus Torvalds fin = packet[2] & 2; 2191da177e4SLinus Torvalds 22099df65e7SKevin Cernekee if ((priv->flags & ALPS_DUALPOINT) && z == 127) { 2211da177e4SLinus Torvalds input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x)); 2221da177e4SLinus Torvalds input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y)); 223d7ed5d88SUlrich Dangel 2241d9f2626SSebastian Kapfer alps_report_buttons(psmouse, dev2, dev, left, right, middle); 225d7ed5d88SUlrich Dangel 2261da177e4SLinus Torvalds input_sync(dev2); 2271da177e4SLinus Torvalds return; 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds 2301d9f2626SSebastian Kapfer alps_report_buttons(psmouse, dev, dev2, left, right, middle); 231d7ed5d88SUlrich Dangel 2321da177e4SLinus Torvalds /* Convert hardware tap to a reasonable Z value */ 23371bb21b6SMaxim Levitsky if (ges && !fin) 23471bb21b6SMaxim Levitsky z = 40; 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds /* 2371da177e4SLinus Torvalds * A "tap and drag" operation is reported by the hardware as a transition 2381da177e4SLinus Torvalds * from (!fin && ges) to (fin && ges). This should be translated to the 2391da177e4SLinus Torvalds * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually. 2401da177e4SLinus Torvalds */ 2411da177e4SLinus Torvalds if (ges && fin && !priv->prev_fin) { 2421da177e4SLinus Torvalds input_report_abs(dev, ABS_X, x); 2431da177e4SLinus Torvalds input_report_abs(dev, ABS_Y, y); 2441da177e4SLinus Torvalds input_report_abs(dev, ABS_PRESSURE, 0); 2451da177e4SLinus Torvalds input_report_key(dev, BTN_TOOL_FINGER, 0); 2461da177e4SLinus Torvalds input_sync(dev); 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds priv->prev_fin = fin; 2491da177e4SLinus Torvalds 25071bb21b6SMaxim Levitsky if (z > 30) 25171bb21b6SMaxim Levitsky input_report_key(dev, BTN_TOUCH, 1); 25271bb21b6SMaxim Levitsky if (z < 25) 25371bb21b6SMaxim Levitsky input_report_key(dev, BTN_TOUCH, 0); 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds if (z > 0) { 2561da177e4SLinus Torvalds input_report_abs(dev, ABS_X, x); 2571da177e4SLinus Torvalds input_report_abs(dev, ABS_Y, y); 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds input_report_abs(dev, ABS_PRESSURE, z); 2611da177e4SLinus Torvalds input_report_key(dev, BTN_TOOL_FINGER, z > 0); 2621da177e4SLinus Torvalds 26399df65e7SKevin Cernekee if (priv->flags & ALPS_WHEEL) 264e6c047b9SVojtech Pavlik input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07)); 2651da177e4SLinus Torvalds 26699df65e7SKevin Cernekee if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { 267c30b4c10SIvan Casado Ruiz input_report_key(dev, BTN_FORWARD, forward); 268c30b4c10SIvan Casado Ruiz input_report_key(dev, BTN_BACK, back); 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds 27199df65e7SKevin Cernekee if (priv->flags & ALPS_FOUR_BUTTONS) { 27271bb21b6SMaxim Levitsky input_report_key(dev, BTN_0, packet[2] & 4); 27371bb21b6SMaxim Levitsky input_report_key(dev, BTN_1, packet[0] & 0x10); 27471bb21b6SMaxim Levitsky input_report_key(dev, BTN_2, packet[3] & 4); 27571bb21b6SMaxim Levitsky input_report_key(dev, BTN_3, packet[0] & 0x20); 27671bb21b6SMaxim Levitsky } 27771bb21b6SMaxim Levitsky 2781da177e4SLinus Torvalds input_sync(dev); 2791da177e4SLinus Torvalds } 2801da177e4SLinus Torvalds 28101ce661fSSeth Forshee /* 282ee65d4b3SYunkang Tang * Process bitmap data for V5 protocols. Return value is null. 283ee65d4b3SYunkang Tang * 284ee65d4b3SYunkang Tang * The bitmaps don't have enough data to track fingers, so this function 285ee65d4b3SYunkang Tang * only generates points representing a bounding box of at most two contacts. 28602d04254SHans de Goede * These two points are returned in fields->mt. 287ee65d4b3SYunkang Tang */ 288ee65d4b3SYunkang Tang static void alps_process_bitmap_dolphin(struct alps_data *priv, 28902d04254SHans de Goede struct alps_fields *fields) 290ee65d4b3SYunkang Tang { 291ee65d4b3SYunkang Tang int box_middle_x, box_middle_y; 292ee65d4b3SYunkang Tang unsigned int x_map, y_map; 293ee65d4b3SYunkang Tang unsigned char start_bit, end_bit; 294ee65d4b3SYunkang Tang unsigned char x_msb, x_lsb, y_msb, y_lsb; 295ee65d4b3SYunkang Tang 296ee65d4b3SYunkang Tang x_map = fields->x_map; 297ee65d4b3SYunkang Tang y_map = fields->y_map; 298ee65d4b3SYunkang Tang 299ee65d4b3SYunkang Tang if (!x_map || !y_map) 300ee65d4b3SYunkang Tang return; 301ee65d4b3SYunkang Tang 302ee65d4b3SYunkang Tang /* Get Most-significant and Least-significant bit */ 303ee65d4b3SYunkang Tang x_msb = fls(x_map); 304ee65d4b3SYunkang Tang x_lsb = ffs(x_map); 305ee65d4b3SYunkang Tang y_msb = fls(y_map); 306ee65d4b3SYunkang Tang y_lsb = ffs(y_map); 307ee65d4b3SYunkang Tang 308ee65d4b3SYunkang Tang /* Most-significant bit should never exceed max sensor line number */ 309ee65d4b3SYunkang Tang if (x_msb > priv->x_bits || y_msb > priv->y_bits) 310ee65d4b3SYunkang Tang return; 311ee65d4b3SYunkang Tang 312ee65d4b3SYunkang Tang if (fields->fingers > 1) { 313ee65d4b3SYunkang Tang start_bit = priv->x_bits - x_msb; 314ee65d4b3SYunkang Tang end_bit = priv->x_bits - x_lsb; 315ee65d4b3SYunkang Tang box_middle_x = (priv->x_max * (start_bit + end_bit)) / 316ee65d4b3SYunkang Tang (2 * (priv->x_bits - 1)); 317ee65d4b3SYunkang Tang 318ee65d4b3SYunkang Tang start_bit = y_lsb - 1; 319ee65d4b3SYunkang Tang end_bit = y_msb - 1; 320ee65d4b3SYunkang Tang box_middle_y = (priv->y_max * (start_bit + end_bit)) / 321ee65d4b3SYunkang Tang (2 * (priv->y_bits - 1)); 32202d04254SHans de Goede fields->mt[0] = fields->st; 32302d04254SHans de Goede fields->mt[1].x = 2 * box_middle_x - fields->mt[0].x; 32402d04254SHans de Goede fields->mt[1].y = 2 * box_middle_y - fields->mt[0].y; 325ee65d4b3SYunkang Tang } 326ee65d4b3SYunkang Tang } 327ee65d4b3SYunkang Tang 328036e6c7bSHans de Goede static void alps_get_bitmap_points(unsigned int map, 329036e6c7bSHans de Goede struct alps_bitmap_point *low, 330036e6c7bSHans de Goede struct alps_bitmap_point *high, 331036e6c7bSHans de Goede int *fingers) 332036e6c7bSHans de Goede { 333036e6c7bSHans de Goede struct alps_bitmap_point *point; 334036e6c7bSHans de Goede int i, bit, prev_bit = 0; 335036e6c7bSHans de Goede 336036e6c7bSHans de Goede point = low; 337036e6c7bSHans de Goede for (i = 0; map != 0; i++, map >>= 1) { 338036e6c7bSHans de Goede bit = map & 1; 339036e6c7bSHans de Goede if (bit) { 340036e6c7bSHans de Goede if (!prev_bit) { 341036e6c7bSHans de Goede point->start_bit = i; 342105affbfSHans de Goede point->num_bits = 0; 343036e6c7bSHans de Goede (*fingers)++; 344036e6c7bSHans de Goede } 345036e6c7bSHans de Goede point->num_bits++; 346036e6c7bSHans de Goede } else { 347036e6c7bSHans de Goede if (prev_bit) 348036e6c7bSHans de Goede point = high; 349036e6c7bSHans de Goede } 350036e6c7bSHans de Goede prev_bit = bit; 351036e6c7bSHans de Goede } 352036e6c7bSHans de Goede } 353036e6c7bSHans de Goede 354ee65d4b3SYunkang Tang /* 35501ce661fSSeth Forshee * Process bitmap data from v3 and v4 protocols. Returns the number of 35601ce661fSSeth Forshee * fingers detected. A return value of 0 means at least one of the 35701ce661fSSeth Forshee * bitmaps was empty. 35801ce661fSSeth Forshee * 35901ce661fSSeth Forshee * The bitmaps don't have enough data to track fingers, so this function 36001ce661fSSeth Forshee * only generates points representing a bounding box of all contacts. 36102d04254SHans de Goede * These points are returned in fields->mt when the return value 36201ce661fSSeth Forshee * is greater than 0. 36301ce661fSSeth Forshee */ 3647a9f73e7SKevin Cernekee static int alps_process_bitmap(struct alps_data *priv, 36502d04254SHans de Goede struct alps_fields *fields) 36601ce661fSSeth Forshee { 367036e6c7bSHans de Goede int i, fingers_x = 0, fingers_y = 0, fingers; 36801ce661fSSeth Forshee struct alps_bitmap_point x_low = {0,}, x_high = {0,}; 36901ce661fSSeth Forshee struct alps_bitmap_point y_low = {0,}, y_high = {0,}; 37001ce661fSSeth Forshee 37102d04254SHans de Goede if (!fields->x_map || !fields->y_map) 37201ce661fSSeth Forshee return 0; 37301ce661fSSeth Forshee 37402d04254SHans de Goede alps_get_bitmap_points(fields->x_map, &x_low, &x_high, &fingers_x); 37502d04254SHans de Goede alps_get_bitmap_points(fields->y_map, &y_low, &y_high, &fingers_y); 37601ce661fSSeth Forshee 37701ce661fSSeth Forshee /* 37801ce661fSSeth Forshee * Fingers can overlap, so we use the maximum count of fingers 37901ce661fSSeth Forshee * on either axis as the finger count. 38001ce661fSSeth Forshee */ 38101ce661fSSeth Forshee fingers = max(fingers_x, fingers_y); 38201ce661fSSeth Forshee 38301ce661fSSeth Forshee /* 38420bea68bSHans de Goede * If an axis reports only a single contact, we have overlapping or 38520bea68bSHans de Goede * adjacent fingers. Divide the single contact between the two points. 38601ce661fSSeth Forshee */ 38701ce661fSSeth Forshee if (fingers_x == 1) { 38828835f45SHans de Goede i = (x_low.num_bits - 1) / 2; 38901ce661fSSeth Forshee x_low.num_bits = x_low.num_bits - i; 39001ce661fSSeth Forshee x_high.start_bit = x_low.start_bit + i; 39101ce661fSSeth Forshee x_high.num_bits = max(i, 1); 39220bea68bSHans de Goede } 39320bea68bSHans de Goede if (fingers_y == 1) { 39428835f45SHans de Goede i = (y_low.num_bits - 1) / 2; 39501ce661fSSeth Forshee y_low.num_bits = y_low.num_bits - i; 39601ce661fSSeth Forshee y_high.start_bit = y_low.start_bit + i; 39701ce661fSSeth Forshee y_high.num_bits = max(i, 1); 39801ce661fSSeth Forshee } 39901ce661fSSeth Forshee 40002d04254SHans de Goede fields->mt[0].x = 40102d04254SHans de Goede (priv->x_max * (2 * x_low.start_bit + x_low.num_bits - 1)) / 4027a9f73e7SKevin Cernekee (2 * (priv->x_bits - 1)); 40302d04254SHans de Goede fields->mt[0].y = 40402d04254SHans de Goede (priv->y_max * (2 * y_low.start_bit + y_low.num_bits - 1)) / 4057a9f73e7SKevin Cernekee (2 * (priv->y_bits - 1)); 40601ce661fSSeth Forshee 40702d04254SHans de Goede fields->mt[1].x = 40802d04254SHans de Goede (priv->x_max * (2 * x_high.start_bit + x_high.num_bits - 1)) / 4097a9f73e7SKevin Cernekee (2 * (priv->x_bits - 1)); 41002d04254SHans de Goede fields->mt[1].y = 41102d04254SHans de Goede (priv->y_max * (2 * y_high.start_bit + y_high.num_bits - 1)) / 4127a9f73e7SKevin Cernekee (2 * (priv->y_bits - 1)); 41301ce661fSSeth Forshee 41440e8f53bSHans de Goede /* y-bitmap order is reversed, except on rushmore */ 41540e8f53bSHans de Goede if (!(priv->flags & ALPS_IS_RUSHMORE)) { 41602d04254SHans de Goede fields->mt[0].y = priv->y_max - fields->mt[0].y; 41702d04254SHans de Goede fields->mt[1].y = priv->y_max - fields->mt[1].y; 41840e8f53bSHans de Goede } 41940e8f53bSHans de Goede 42001ce661fSSeth Forshee return fingers; 42101ce661fSSeth Forshee } 42201ce661fSSeth Forshee 423cdf333efSHans de Goede static void alps_set_slot(struct input_dev *dev, int slot, int x, int y) 42401ce661fSSeth Forshee { 42501ce661fSSeth Forshee input_mt_slot(dev, slot); 426cdf333efSHans de Goede input_mt_report_slot_state(dev, MT_TOOL_FINGER, true); 42701ce661fSSeth Forshee input_report_abs(dev, ABS_MT_POSITION_X, x); 42801ce661fSSeth Forshee input_report_abs(dev, ABS_MT_POSITION_Y, y); 42901ce661fSSeth Forshee } 43001ce661fSSeth Forshee 431cdf333efSHans de Goede static void alps_report_mt_data(struct psmouse *psmouse, int n) 43201ce661fSSeth Forshee { 43302d04254SHans de Goede struct alps_data *priv = psmouse->private; 43402d04254SHans de Goede struct input_dev *dev = psmouse->dev; 43502d04254SHans de Goede struct alps_fields *f = &priv->f; 436cdf333efSHans de Goede int i, slot[MAX_TOUCHES]; 43702d04254SHans de Goede 438cdf333efSHans de Goede input_mt_assign_slots(dev, slot, f->mt, n); 439cdf333efSHans de Goede for (i = 0; i < n; i++) 440cdf333efSHans de Goede alps_set_slot(dev, slot[i], f->mt[i].x, f->mt[i].y); 441cdf333efSHans de Goede 442cdf333efSHans de Goede input_mt_sync_frame(dev); 44301ce661fSSeth Forshee } 44401ce661fSSeth Forshee 44568c21870SHans de Goede static void alps_report_semi_mt_data(struct psmouse *psmouse, int fingers) 44668c21870SHans de Goede { 44768c21870SHans de Goede struct alps_data *priv = psmouse->private; 44868c21870SHans de Goede struct input_dev *dev = psmouse->dev; 44968c21870SHans de Goede struct alps_fields *f = &priv->f; 45068c21870SHans de Goede 45168c21870SHans de Goede /* Use st data when we don't have mt data */ 45268c21870SHans de Goede if (fingers < 2) { 45368c21870SHans de Goede f->mt[0].x = f->st.x; 45468c21870SHans de Goede f->mt[0].y = f->st.y; 45568c21870SHans de Goede fingers = f->pressure > 0 ? 1 : 0; 45668c21870SHans de Goede } 45768c21870SHans de Goede 45899d9996cSHans de Goede alps_report_mt_data(psmouse, (fingers <= 2) ? fingers : 2); 45968c21870SHans de Goede 46068c21870SHans de Goede input_mt_report_finger_count(dev, fingers); 46168c21870SHans de Goede 46268c21870SHans de Goede input_report_key(dev, BTN_LEFT, f->left); 46368c21870SHans de Goede input_report_key(dev, BTN_RIGHT, f->right); 46468c21870SHans de Goede input_report_key(dev, BTN_MIDDLE, f->middle); 46568c21870SHans de Goede 46668c21870SHans de Goede input_report_abs(dev, ABS_PRESSURE, f->pressure); 46768c21870SHans de Goede 46868c21870SHans de Goede input_sync(dev); 46968c21870SHans de Goede } 47068c21870SHans de Goede 47125bded7cSSeth Forshee static void alps_process_trackstick_packet_v3(struct psmouse *psmouse) 47225bded7cSSeth Forshee { 47325bded7cSSeth Forshee struct alps_data *priv = psmouse->private; 47425bded7cSSeth Forshee unsigned char *packet = psmouse->packet; 47525bded7cSSeth Forshee struct input_dev *dev = priv->dev2; 47625bded7cSSeth Forshee int x, y, z, left, right, middle; 47725bded7cSSeth Forshee 47825bded7cSSeth Forshee /* Sanity check packet */ 47925bded7cSSeth Forshee if (!(packet[0] & 0x40)) { 48025bded7cSSeth Forshee psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n"); 48125bded7cSSeth Forshee return; 48225bded7cSSeth Forshee } 48325bded7cSSeth Forshee 48425bded7cSSeth Forshee /* 48525bded7cSSeth Forshee * There's a special packet that seems to indicate the end 48625bded7cSSeth Forshee * of a stream of trackstick data. Filter these out. 48725bded7cSSeth Forshee */ 48825bded7cSSeth Forshee if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f) 48925bded7cSSeth Forshee return; 49025bded7cSSeth Forshee 49125bded7cSSeth Forshee x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f)); 49225bded7cSSeth Forshee y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f)); 49325bded7cSSeth Forshee z = (packet[4] & 0x7c) >> 2; 49425bded7cSSeth Forshee 49525bded7cSSeth Forshee /* 49625bded7cSSeth Forshee * The x and y values tend to be quite large, and when used 49725bded7cSSeth Forshee * alone the trackstick is difficult to use. Scale them down 49825bded7cSSeth Forshee * to compensate. 49925bded7cSSeth Forshee */ 50025bded7cSSeth Forshee x /= 8; 50125bded7cSSeth Forshee y /= 8; 50225bded7cSSeth Forshee 50325bded7cSSeth Forshee input_report_rel(dev, REL_X, x); 50425bded7cSSeth Forshee input_report_rel(dev, REL_Y, -y); 50525bded7cSSeth Forshee 50625bded7cSSeth Forshee /* 50725bded7cSSeth Forshee * Most ALPS models report the trackstick buttons in the touchpad 50825bded7cSSeth Forshee * packets, but a few report them here. No reliable way has been 50925bded7cSSeth Forshee * found to differentiate between the models upfront, so we enable 51025bded7cSSeth Forshee * the quirk in response to seeing a button press in the trackstick 51125bded7cSSeth Forshee * packet. 51225bded7cSSeth Forshee */ 51325bded7cSSeth Forshee left = packet[3] & 0x01; 51425bded7cSSeth Forshee right = packet[3] & 0x02; 51525bded7cSSeth Forshee middle = packet[3] & 0x04; 51625bded7cSSeth Forshee 51725bded7cSSeth Forshee if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) && 51825bded7cSSeth Forshee (left || right || middle)) 51925bded7cSSeth Forshee priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS; 52025bded7cSSeth Forshee 52125bded7cSSeth Forshee if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) { 52225bded7cSSeth Forshee input_report_key(dev, BTN_LEFT, left); 52325bded7cSSeth Forshee input_report_key(dev, BTN_RIGHT, right); 52425bded7cSSeth Forshee input_report_key(dev, BTN_MIDDLE, middle); 52525bded7cSSeth Forshee } 52625bded7cSSeth Forshee 52725bded7cSSeth Forshee input_sync(dev); 52825bded7cSSeth Forshee return; 52925bded7cSSeth Forshee } 53025bded7cSSeth Forshee 531f85e5001SKevin Cernekee static void alps_decode_buttons_v3(struct alps_fields *f, unsigned char *p) 532f85e5001SKevin Cernekee { 533f85e5001SKevin Cernekee f->left = !!(p[3] & 0x01); 534f85e5001SKevin Cernekee f->right = !!(p[3] & 0x02); 535f85e5001SKevin Cernekee f->middle = !!(p[3] & 0x04); 536f85e5001SKevin Cernekee 537f85e5001SKevin Cernekee f->ts_left = !!(p[3] & 0x10); 538f85e5001SKevin Cernekee f->ts_right = !!(p[3] & 0x20); 539f85e5001SKevin Cernekee f->ts_middle = !!(p[3] & 0x40); 540f85e5001SKevin Cernekee } 541f85e5001SKevin Cernekee 54238c11eaaSHans de Goede static int alps_decode_pinnacle(struct alps_fields *f, unsigned char *p, 543ee65d4b3SYunkang Tang struct psmouse *psmouse) 544f85e5001SKevin Cernekee { 545f85e5001SKevin Cernekee f->first_mp = !!(p[4] & 0x40); 546f85e5001SKevin Cernekee f->is_mp = !!(p[0] & 0x40); 547f85e5001SKevin Cernekee 548f85e5001SKevin Cernekee f->fingers = (p[5] & 0x3) + 1; 549f85e5001SKevin Cernekee f->x_map = ((p[4] & 0x7e) << 8) | 550f85e5001SKevin Cernekee ((p[1] & 0x7f) << 2) | 551f85e5001SKevin Cernekee ((p[0] & 0x30) >> 4); 552f85e5001SKevin Cernekee f->y_map = ((p[3] & 0x70) << 4) | 553f85e5001SKevin Cernekee ((p[2] & 0x7f) << 1) | 554f85e5001SKevin Cernekee (p[4] & 0x01); 555f85e5001SKevin Cernekee 55602d04254SHans de Goede f->st.x = ((p[1] & 0x7f) << 4) | ((p[4] & 0x30) >> 2) | 557f85e5001SKevin Cernekee ((p[0] & 0x30) >> 4); 55802d04254SHans de Goede f->st.y = ((p[2] & 0x7f) << 4) | (p[4] & 0x0f); 55902d04254SHans de Goede f->pressure = p[5] & 0x7f; 560f85e5001SKevin Cernekee 561f85e5001SKevin Cernekee alps_decode_buttons_v3(f, p); 56238c11eaaSHans de Goede 56338c11eaaSHans de Goede return 0; 564f85e5001SKevin Cernekee } 565f85e5001SKevin Cernekee 56638c11eaaSHans de Goede static int alps_decode_rushmore(struct alps_fields *f, unsigned char *p, 567ee65d4b3SYunkang Tang struct psmouse *psmouse) 5681302bac3SKevin Cernekee { 569ee65d4b3SYunkang Tang alps_decode_pinnacle(f, p, psmouse); 5701302bac3SKevin Cernekee 571f105e34aSYunkang Tang /* Rushmore's packet decode has a bit difference with Pinnacle's */ 572f105e34aSYunkang Tang f->is_mp = !!(p[5] & 0x40); 573f105e34aSYunkang Tang f->fingers = max((p[5] & 0x3), ((p[5] >> 2) & 0x3)) + 1; 5741302bac3SKevin Cernekee f->x_map |= (p[5] & 0x10) << 11; 5751302bac3SKevin Cernekee f->y_map |= (p[5] & 0x20) << 6; 57638c11eaaSHans de Goede 57738c11eaaSHans de Goede return 0; 5781302bac3SKevin Cernekee } 5791302bac3SKevin Cernekee 58038c11eaaSHans de Goede static int alps_decode_dolphin(struct alps_fields *f, unsigned char *p, 581ee65d4b3SYunkang Tang struct psmouse *psmouse) 58275af9e56SDave Turvene { 583ee65d4b3SYunkang Tang u64 palm_data = 0; 584ee65d4b3SYunkang Tang struct alps_data *priv = psmouse->private; 585ee65d4b3SYunkang Tang 58675af9e56SDave Turvene f->first_mp = !!(p[0] & 0x02); 58775af9e56SDave Turvene f->is_mp = !!(p[0] & 0x20); 58875af9e56SDave Turvene 589ee65d4b3SYunkang Tang if (!f->is_mp) { 59002d04254SHans de Goede f->st.x = ((p[1] & 0x7f) | ((p[4] & 0x0f) << 7)); 59102d04254SHans de Goede f->st.y = ((p[2] & 0x7f) | ((p[4] & 0xf0) << 3)); 59202d04254SHans de Goede f->pressure = (p[0] & 4) ? 0 : p[5] & 0x7f; 59375af9e56SDave Turvene alps_decode_buttons_v3(f, p); 594ee65d4b3SYunkang Tang } else { 595ee65d4b3SYunkang Tang f->fingers = ((p[0] & 0x6) >> 1 | 596ee65d4b3SYunkang Tang (p[0] & 0x10) >> 2); 597ee65d4b3SYunkang Tang 598ee65d4b3SYunkang Tang palm_data = (p[1] & 0x7f) | 599ee65d4b3SYunkang Tang ((p[2] & 0x7f) << 7) | 600ee65d4b3SYunkang Tang ((p[4] & 0x7f) << 14) | 601ee65d4b3SYunkang Tang ((p[5] & 0x7f) << 21) | 602ee65d4b3SYunkang Tang ((p[3] & 0x07) << 28) | 603ee65d4b3SYunkang Tang (((u64)p[3] & 0x70) << 27) | 604ee65d4b3SYunkang Tang (((u64)p[0] & 0x01) << 34); 605ee65d4b3SYunkang Tang 606ee65d4b3SYunkang Tang /* Y-profile is stored in P(0) to p(n-1), n = y_bits; */ 607ee65d4b3SYunkang Tang f->y_map = palm_data & (BIT(priv->y_bits) - 1); 608ee65d4b3SYunkang Tang 609ee65d4b3SYunkang Tang /* X-profile is stored in p(n) to p(n+m-1), m = x_bits; */ 610ee65d4b3SYunkang Tang f->x_map = (palm_data >> priv->y_bits) & 611ee65d4b3SYunkang Tang (BIT(priv->x_bits) - 1); 612ee65d4b3SYunkang Tang } 61338c11eaaSHans de Goede 61438c11eaaSHans de Goede return 0; 61575af9e56SDave Turvene } 61675af9e56SDave Turvene 617ee65d4b3SYunkang Tang static void alps_process_touchpad_packet_v3_v5(struct psmouse *psmouse) 61825bded7cSSeth Forshee { 61925bded7cSSeth Forshee struct alps_data *priv = psmouse->private; 62025bded7cSSeth Forshee unsigned char *packet = psmouse->packet; 62125bded7cSSeth Forshee struct input_dev *dev2 = priv->dev2; 62202d04254SHans de Goede struct alps_fields *f = &priv->f; 62302d04254SHans de Goede int fingers = 0; 624f85e5001SKevin Cernekee 62502d04254SHans de Goede memset(f, 0, sizeof(*f)); 62602d04254SHans de Goede 62702d04254SHans de Goede priv->decode_fields(f, packet, psmouse); 62825bded7cSSeth Forshee 62925bded7cSSeth Forshee /* 63001ce661fSSeth Forshee * There's no single feature of touchpad position and bitmap packets 63101ce661fSSeth Forshee * that can be used to distinguish between them. We rely on the fact 63201ce661fSSeth Forshee * that a bitmap packet should always follow a position packet with 63301ce661fSSeth Forshee * bit 6 of packet[4] set. 63425bded7cSSeth Forshee */ 63525bded7cSSeth Forshee if (priv->multi_packet) { 63625bded7cSSeth Forshee /* 63725bded7cSSeth Forshee * Sometimes a position packet will indicate a multi-packet 63825bded7cSSeth Forshee * sequence, but then what follows is another position 63925bded7cSSeth Forshee * packet. Check for this, and when it happens process the 64025bded7cSSeth Forshee * position packet as usual. 64125bded7cSSeth Forshee */ 64202d04254SHans de Goede if (f->is_mp) { 64302d04254SHans de Goede fingers = f->fingers; 644ee65d4b3SYunkang Tang if (priv->proto_version == ALPS_PROTO_V3) { 64502d04254SHans de Goede if (alps_process_bitmap(priv, f) == 0) 64620bea68bSHans de Goede fingers = 0; /* Use st data */ 64701ce661fSSeth Forshee 64801ce661fSSeth Forshee /* Now process position packet */ 64902d04254SHans de Goede priv->decode_fields(f, priv->multi_data, 650ee65d4b3SYunkang Tang psmouse); 651ee65d4b3SYunkang Tang } else { 652ee65d4b3SYunkang Tang /* 653ee65d4b3SYunkang Tang * Because Dolphin uses position packet's 654ee65d4b3SYunkang Tang * coordinate data as Pt1 and uses it to 655ee65d4b3SYunkang Tang * calculate Pt2, so we need to do position 656ee65d4b3SYunkang Tang * packet decode first. 657ee65d4b3SYunkang Tang */ 65802d04254SHans de Goede priv->decode_fields(f, priv->multi_data, 659ee65d4b3SYunkang Tang psmouse); 660ee65d4b3SYunkang Tang 661ee65d4b3SYunkang Tang /* 662ee65d4b3SYunkang Tang * Since Dolphin's finger number is reliable, 663ee65d4b3SYunkang Tang * there is no need to compare with bmap_fn. 664ee65d4b3SYunkang Tang */ 66502d04254SHans de Goede alps_process_bitmap_dolphin(priv, f); 666ee65d4b3SYunkang Tang } 66701ce661fSSeth Forshee } else { 66801ce661fSSeth Forshee priv->multi_packet = 0; 66925bded7cSSeth Forshee } 67025bded7cSSeth Forshee } 67125bded7cSSeth Forshee 67201ce661fSSeth Forshee /* 67301ce661fSSeth Forshee * Bit 6 of byte 0 is not usually set in position packets. The only 67401ce661fSSeth Forshee * times it seems to be set is in situations where the data is 67501ce661fSSeth Forshee * suspect anyway, e.g. a palm resting flat on the touchpad. Given 67601ce661fSSeth Forshee * this combined with the fact that this bit is useful for filtering 67701ce661fSSeth Forshee * out misidentified bitmap packets, we reject anything with this 67801ce661fSSeth Forshee * bit set. 67901ce661fSSeth Forshee */ 68002d04254SHans de Goede if (f->is_mp) 68101ce661fSSeth Forshee return; 68201ce661fSSeth Forshee 68302d04254SHans de Goede if (!priv->multi_packet && f->first_mp) { 68425bded7cSSeth Forshee priv->multi_packet = 1; 68501ce661fSSeth Forshee memcpy(priv->multi_data, packet, sizeof(priv->multi_data)); 68601ce661fSSeth Forshee return; 68701ce661fSSeth Forshee } 68801ce661fSSeth Forshee 68925bded7cSSeth Forshee priv->multi_packet = 0; 69025bded7cSSeth Forshee 69125bded7cSSeth Forshee /* 69225bded7cSSeth Forshee * Sometimes the hardware sends a single packet with z = 0 69325bded7cSSeth Forshee * in the middle of a stream. Real releases generate packets 69425bded7cSSeth Forshee * with x, y, and z all zero, so these seem to be flukes. 69525bded7cSSeth Forshee * Ignore them. 69625bded7cSSeth Forshee */ 69702d04254SHans de Goede if (f->st.x && f->st.y && !f->pressure) 69825bded7cSSeth Forshee return; 69925bded7cSSeth Forshee 70068c21870SHans de Goede alps_report_semi_mt_data(psmouse, fingers); 70125bded7cSSeth Forshee 70225bded7cSSeth Forshee if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) { 70302d04254SHans de Goede input_report_key(dev2, BTN_LEFT, f->ts_left); 70402d04254SHans de Goede input_report_key(dev2, BTN_RIGHT, f->ts_right); 70502d04254SHans de Goede input_report_key(dev2, BTN_MIDDLE, f->ts_middle); 70625bded7cSSeth Forshee input_sync(dev2); 70725bded7cSSeth Forshee } 70825bded7cSSeth Forshee } 70925bded7cSSeth Forshee 71025bded7cSSeth Forshee static void alps_process_packet_v3(struct psmouse *psmouse) 71125bded7cSSeth Forshee { 71225bded7cSSeth Forshee unsigned char *packet = psmouse->packet; 71325bded7cSSeth Forshee 71425bded7cSSeth Forshee /* 71525bded7cSSeth Forshee * v3 protocol packets come in three types, two representing 71625bded7cSSeth Forshee * touchpad data and one representing trackstick data. 71725bded7cSSeth Forshee * Trackstick packets seem to be distinguished by always 71825bded7cSSeth Forshee * having 0x3f in the last byte. This value has never been 71925bded7cSSeth Forshee * observed in the last byte of either of the other types 72025bded7cSSeth Forshee * of packets. 72125bded7cSSeth Forshee */ 72225bded7cSSeth Forshee if (packet[5] == 0x3f) { 72325bded7cSSeth Forshee alps_process_trackstick_packet_v3(psmouse); 72425bded7cSSeth Forshee return; 72525bded7cSSeth Forshee } 72625bded7cSSeth Forshee 727ee65d4b3SYunkang Tang alps_process_touchpad_packet_v3_v5(psmouse); 72825bded7cSSeth Forshee } 72925bded7cSSeth Forshee 73095f75e91SYunkang Tang static void alps_process_packet_v6(struct psmouse *psmouse) 73195f75e91SYunkang Tang { 73295f75e91SYunkang Tang struct alps_data *priv = psmouse->private; 73395f75e91SYunkang Tang unsigned char *packet = psmouse->packet; 73495f75e91SYunkang Tang struct input_dev *dev = psmouse->dev; 73595f75e91SYunkang Tang struct input_dev *dev2 = priv->dev2; 73695f75e91SYunkang Tang int x, y, z, left, right, middle; 73795f75e91SYunkang Tang 73895f75e91SYunkang Tang /* 73995f75e91SYunkang Tang * We can use Byte5 to distinguish if the packet is from Touchpad 74095f75e91SYunkang Tang * or Trackpoint. 74195f75e91SYunkang Tang * Touchpad: 0 - 0x7E 74295f75e91SYunkang Tang * Trackpoint: 0x7F 74395f75e91SYunkang Tang */ 74495f75e91SYunkang Tang if (packet[5] == 0x7F) { 74595f75e91SYunkang Tang /* It should be a DualPoint when received Trackpoint packet */ 74695f75e91SYunkang Tang if (!(priv->flags & ALPS_DUALPOINT)) 74795f75e91SYunkang Tang return; 74895f75e91SYunkang Tang 74995f75e91SYunkang Tang /* Trackpoint packet */ 75095f75e91SYunkang Tang x = packet[1] | ((packet[3] & 0x20) << 2); 75195f75e91SYunkang Tang y = packet[2] | ((packet[3] & 0x40) << 1); 75295f75e91SYunkang Tang z = packet[4]; 75395f75e91SYunkang Tang left = packet[3] & 0x01; 75495f75e91SYunkang Tang right = packet[3] & 0x02; 75595f75e91SYunkang Tang middle = packet[3] & 0x04; 75695f75e91SYunkang Tang 75795f75e91SYunkang Tang /* To prevent the cursor jump when finger lifted */ 75895f75e91SYunkang Tang if (x == 0x7F && y == 0x7F && z == 0x7F) 75995f75e91SYunkang Tang x = y = z = 0; 76095f75e91SYunkang Tang 76195f75e91SYunkang Tang /* Divide 4 since trackpoint's speed is too fast */ 76295f75e91SYunkang Tang input_report_rel(dev2, REL_X, (char)x / 4); 76395f75e91SYunkang Tang input_report_rel(dev2, REL_Y, -((char)y / 4)); 76495f75e91SYunkang Tang 76595f75e91SYunkang Tang input_report_key(dev2, BTN_LEFT, left); 76695f75e91SYunkang Tang input_report_key(dev2, BTN_RIGHT, right); 76795f75e91SYunkang Tang input_report_key(dev2, BTN_MIDDLE, middle); 76895f75e91SYunkang Tang 76995f75e91SYunkang Tang input_sync(dev2); 77095f75e91SYunkang Tang return; 77195f75e91SYunkang Tang } 77295f75e91SYunkang Tang 77395f75e91SYunkang Tang /* Touchpad packet */ 77495f75e91SYunkang Tang x = packet[1] | ((packet[3] & 0x78) << 4); 77595f75e91SYunkang Tang y = packet[2] | ((packet[4] & 0x78) << 4); 77695f75e91SYunkang Tang z = packet[5]; 77795f75e91SYunkang Tang left = packet[3] & 0x01; 77895f75e91SYunkang Tang right = packet[3] & 0x02; 77995f75e91SYunkang Tang 78095f75e91SYunkang Tang if (z > 30) 78195f75e91SYunkang Tang input_report_key(dev, BTN_TOUCH, 1); 78295f75e91SYunkang Tang if (z < 25) 78395f75e91SYunkang Tang input_report_key(dev, BTN_TOUCH, 0); 78495f75e91SYunkang Tang 78595f75e91SYunkang Tang if (z > 0) { 78695f75e91SYunkang Tang input_report_abs(dev, ABS_X, x); 78795f75e91SYunkang Tang input_report_abs(dev, ABS_Y, y); 78895f75e91SYunkang Tang } 78995f75e91SYunkang Tang 79095f75e91SYunkang Tang input_report_abs(dev, ABS_PRESSURE, z); 79195f75e91SYunkang Tang input_report_key(dev, BTN_TOOL_FINGER, z > 0); 79295f75e91SYunkang Tang 79395f75e91SYunkang Tang /* v6 touchpad does not have middle button */ 79495f75e91SYunkang Tang input_report_key(dev, BTN_LEFT, left); 79595f75e91SYunkang Tang input_report_key(dev, BTN_RIGHT, right); 79695f75e91SYunkang Tang 79795f75e91SYunkang Tang input_sync(dev); 79895f75e91SYunkang Tang } 79995f75e91SYunkang Tang 80025bded7cSSeth Forshee static void alps_process_packet_v4(struct psmouse *psmouse) 80125bded7cSSeth Forshee { 8023b7e09faSGeorge Pantalos struct alps_data *priv = psmouse->private; 80325bded7cSSeth Forshee unsigned char *packet = psmouse->packet; 80402d04254SHans de Goede struct alps_fields *f = &priv->f; 80568c21870SHans de Goede int offset; 8063b7e09faSGeorge Pantalos 8073b7e09faSGeorge Pantalos /* 8083b7e09faSGeorge Pantalos * v4 has a 6-byte encoding for bitmap data, but this data is 8093b7e09faSGeorge Pantalos * broken up between 3 normal packets. Use priv->multi_packet to 8103b7e09faSGeorge Pantalos * track our position in the bitmap packet. 8113b7e09faSGeorge Pantalos */ 8123b7e09faSGeorge Pantalos if (packet[6] & 0x40) { 8133b7e09faSGeorge Pantalos /* sync, reset position */ 8143b7e09faSGeorge Pantalos priv->multi_packet = 0; 8153b7e09faSGeorge Pantalos } 8163b7e09faSGeorge Pantalos 8173b7e09faSGeorge Pantalos if (WARN_ON_ONCE(priv->multi_packet > 2)) 8183b7e09faSGeorge Pantalos return; 8193b7e09faSGeorge Pantalos 8203b7e09faSGeorge Pantalos offset = 2 * priv->multi_packet; 8213b7e09faSGeorge Pantalos priv->multi_data[offset] = packet[6]; 8223b7e09faSGeorge Pantalos priv->multi_data[offset + 1] = packet[7]; 8233b7e09faSGeorge Pantalos 8243b7e09faSGeorge Pantalos if (++priv->multi_packet > 2) { 8253b7e09faSGeorge Pantalos priv->multi_packet = 0; 8263b7e09faSGeorge Pantalos 82702d04254SHans de Goede f->x_map = ((priv->multi_data[2] & 0x1f) << 10) | 8283b7e09faSGeorge Pantalos ((priv->multi_data[3] & 0x60) << 3) | 8293b7e09faSGeorge Pantalos ((priv->multi_data[0] & 0x3f) << 2) | 8303b7e09faSGeorge Pantalos ((priv->multi_data[1] & 0x60) >> 5); 83102d04254SHans de Goede f->y_map = ((priv->multi_data[5] & 0x01) << 10) | 8323b7e09faSGeorge Pantalos ((priv->multi_data[3] & 0x1f) << 5) | 8333b7e09faSGeorge Pantalos (priv->multi_data[1] & 0x1f); 8343b7e09faSGeorge Pantalos 83502d04254SHans de Goede f->fingers = alps_process_bitmap(priv, f); 8363b7e09faSGeorge Pantalos } 83725bded7cSSeth Forshee 83802d04254SHans de Goede f->left = packet[4] & 0x01; 83902d04254SHans de Goede f->right = packet[4] & 0x02; 84025bded7cSSeth Forshee 84102d04254SHans de Goede f->st.x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) | 84225bded7cSSeth Forshee ((packet[0] & 0x30) >> 4); 84302d04254SHans de Goede f->st.y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f); 84402d04254SHans de Goede f->pressure = packet[5] & 0x7f; 84525bded7cSSeth Forshee 84668c21870SHans de Goede alps_report_semi_mt_data(psmouse, f->fingers); 84725bded7cSSeth Forshee } 84825bded7cSSeth Forshee 8493808843cSYunkang Tang static bool alps_is_valid_package_v7(struct psmouse *psmouse) 8503808843cSYunkang Tang { 8513808843cSYunkang Tang switch (psmouse->pktcnt) { 8523808843cSYunkang Tang case 3: 8533808843cSYunkang Tang return (psmouse->packet[2] & 0x40) == 0x40; 8543808843cSYunkang Tang case 4: 8553808843cSYunkang Tang return (psmouse->packet[3] & 0x48) == 0x48; 8563808843cSYunkang Tang case 6: 8573808843cSYunkang Tang return (psmouse->packet[5] & 0x40) == 0x00; 8583808843cSYunkang Tang } 8593808843cSYunkang Tang return true; 8603808843cSYunkang Tang } 8613808843cSYunkang Tang 8623808843cSYunkang Tang static unsigned char alps_get_packet_id_v7(char *byte) 8633808843cSYunkang Tang { 8643808843cSYunkang Tang unsigned char packet_id; 8653808843cSYunkang Tang 8663808843cSYunkang Tang if (byte[4] & 0x40) 8673808843cSYunkang Tang packet_id = V7_PACKET_ID_TWO; 8683808843cSYunkang Tang else if (byte[4] & 0x01) 8693808843cSYunkang Tang packet_id = V7_PACKET_ID_MULTI; 8703808843cSYunkang Tang else if ((byte[0] & 0x10) && !(byte[4] & 0x43)) 8713808843cSYunkang Tang packet_id = V7_PACKET_ID_NEW; 8723808843cSYunkang Tang else if (byte[1] == 0x00 && byte[4] == 0x00) 8733808843cSYunkang Tang packet_id = V7_PACKET_ID_IDLE; 8743808843cSYunkang Tang else 8753808843cSYunkang Tang packet_id = V7_PACKET_ID_UNKNOWN; 8763808843cSYunkang Tang 8773808843cSYunkang Tang return packet_id; 8783808843cSYunkang Tang } 8793808843cSYunkang Tang 8803808843cSYunkang Tang static void alps_get_finger_coordinate_v7(struct input_mt_pos *mt, 8813808843cSYunkang Tang unsigned char *pkt, 8823808843cSYunkang Tang unsigned char pkt_id) 8833808843cSYunkang Tang { 8843808843cSYunkang Tang mt[0].x = ((pkt[2] & 0x80) << 4); 8853808843cSYunkang Tang mt[0].x |= ((pkt[2] & 0x3F) << 5); 8863808843cSYunkang Tang mt[0].x |= ((pkt[3] & 0x30) >> 1); 8873808843cSYunkang Tang mt[0].x |= (pkt[3] & 0x07); 8883808843cSYunkang Tang mt[0].y = (pkt[1] << 3) | (pkt[0] & 0x07); 8893808843cSYunkang Tang 8903808843cSYunkang Tang mt[1].x = ((pkt[3] & 0x80) << 4); 8913808843cSYunkang Tang mt[1].x |= ((pkt[4] & 0x80) << 3); 8923808843cSYunkang Tang mt[1].x |= ((pkt[4] & 0x3F) << 4); 8933808843cSYunkang Tang mt[1].y = ((pkt[5] & 0x80) << 3); 8943808843cSYunkang Tang mt[1].y |= ((pkt[5] & 0x3F) << 4); 8953808843cSYunkang Tang 8963808843cSYunkang Tang switch (pkt_id) { 8973808843cSYunkang Tang case V7_PACKET_ID_TWO: 8983808843cSYunkang Tang mt[1].x &= ~0x000F; 8993808843cSYunkang Tang mt[1].y |= 0x000F; 9003808843cSYunkang Tang break; 9013808843cSYunkang Tang 9023808843cSYunkang Tang case V7_PACKET_ID_MULTI: 9033808843cSYunkang Tang mt[1].x &= ~0x003F; 9043808843cSYunkang Tang mt[1].y &= ~0x0020; 9053808843cSYunkang Tang mt[1].y |= ((pkt[4] & 0x02) << 4); 9063808843cSYunkang Tang mt[1].y |= 0x001F; 9073808843cSYunkang Tang break; 9083808843cSYunkang Tang 9093808843cSYunkang Tang case V7_PACKET_ID_NEW: 9103808843cSYunkang Tang mt[1].x &= ~0x003F; 9113808843cSYunkang Tang mt[1].x |= (pkt[0] & 0x20); 9123808843cSYunkang Tang mt[1].y |= 0x000F; 9133808843cSYunkang Tang break; 9143808843cSYunkang Tang } 9153808843cSYunkang Tang 9163808843cSYunkang Tang mt[0].y = 0x7FF - mt[0].y; 9173808843cSYunkang Tang mt[1].y = 0x7FF - mt[1].y; 9183808843cSYunkang Tang } 9193808843cSYunkang Tang 9203808843cSYunkang Tang static int alps_get_mt_count(struct input_mt_pos *mt) 9213808843cSYunkang Tang { 9223808843cSYunkang Tang int i; 9233808843cSYunkang Tang 9243808843cSYunkang Tang for (i = 0; i < MAX_TOUCHES && mt[i].x != 0 && mt[i].y != 0; i++) 9253808843cSYunkang Tang /* empty */; 9263808843cSYunkang Tang 9273808843cSYunkang Tang return i; 9283808843cSYunkang Tang } 9293808843cSYunkang Tang 9303808843cSYunkang Tang static int alps_decode_packet_v7(struct alps_fields *f, 9313808843cSYunkang Tang unsigned char *p, 9323808843cSYunkang Tang struct psmouse *psmouse) 9333808843cSYunkang Tang { 9343808843cSYunkang Tang unsigned char pkt_id; 9353808843cSYunkang Tang 9363808843cSYunkang Tang pkt_id = alps_get_packet_id_v7(p); 9373808843cSYunkang Tang if (pkt_id == V7_PACKET_ID_IDLE) 9383808843cSYunkang Tang return 0; 9393808843cSYunkang Tang if (pkt_id == V7_PACKET_ID_UNKNOWN) 9403808843cSYunkang Tang return -1; 9413808843cSYunkang Tang 9423808843cSYunkang Tang alps_get_finger_coordinate_v7(f->mt, p, pkt_id); 9433808843cSYunkang Tang 9443808843cSYunkang Tang if (pkt_id == V7_PACKET_ID_TWO || pkt_id == V7_PACKET_ID_MULTI) { 9453808843cSYunkang Tang f->left = (p[0] & 0x80) >> 7; 9463808843cSYunkang Tang f->right = (p[0] & 0x20) >> 5; 9473808843cSYunkang Tang f->middle = (p[0] & 0x10) >> 4; 9483808843cSYunkang Tang } 9493808843cSYunkang Tang 9503808843cSYunkang Tang if (pkt_id == V7_PACKET_ID_TWO) 9513808843cSYunkang Tang f->fingers = alps_get_mt_count(f->mt); 9523808843cSYunkang Tang else if (pkt_id == V7_PACKET_ID_MULTI) 9533808843cSYunkang Tang f->fingers = 3 + (p[5] & 0x03); 9543808843cSYunkang Tang 9553808843cSYunkang Tang return 0; 9563808843cSYunkang Tang } 9573808843cSYunkang Tang 9583808843cSYunkang Tang static void alps_process_trackstick_packet_v7(struct psmouse *psmouse) 9593808843cSYunkang Tang { 9603808843cSYunkang Tang struct alps_data *priv = psmouse->private; 9613808843cSYunkang Tang unsigned char *packet = psmouse->packet; 9623808843cSYunkang Tang struct input_dev *dev2 = priv->dev2; 9633808843cSYunkang Tang int x, y, z, left, right, middle; 9643808843cSYunkang Tang 9653808843cSYunkang Tang /* 9663808843cSYunkang Tang * b7 b6 b5 b4 b3 b2 b1 b0 9673808843cSYunkang Tang * Byte0 0 1 0 0 1 0 0 0 9683808843cSYunkang Tang * Byte1 1 1 * * 1 M R L 9693808843cSYunkang Tang * Byte2 X7 1 X5 X4 X3 X2 X1 X0 9703808843cSYunkang Tang * Byte3 Z6 1 Y6 X6 1 Y2 Y1 Y0 9713808843cSYunkang Tang * Byte4 Y7 0 Y5 Y4 Y3 1 1 0 9723808843cSYunkang Tang * Byte5 T&P 0 Z5 Z4 Z3 Z2 Z1 Z0 9733808843cSYunkang Tang * M / R / L: Middle / Right / Left button 9743808843cSYunkang Tang */ 9753808843cSYunkang Tang 9763808843cSYunkang Tang x = ((packet[2] & 0xbf)) | ((packet[3] & 0x10) << 2); 9773808843cSYunkang Tang y = (packet[3] & 0x07) | (packet[4] & 0xb8) | 9783808843cSYunkang Tang ((packet[3] & 0x20) << 1); 9793808843cSYunkang Tang z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1); 9803808843cSYunkang Tang 9813808843cSYunkang Tang left = (packet[1] & 0x01); 9823808843cSYunkang Tang right = (packet[1] & 0x02) >> 1; 9833808843cSYunkang Tang middle = (packet[1] & 0x04) >> 2; 9843808843cSYunkang Tang 9853808843cSYunkang Tang /* Divide 2 since trackpoint's speed is too fast */ 9863808843cSYunkang Tang input_report_rel(dev2, REL_X, (char)x / 2); 9873808843cSYunkang Tang input_report_rel(dev2, REL_Y, -((char)y / 2)); 9883808843cSYunkang Tang 9893808843cSYunkang Tang input_report_key(dev2, BTN_LEFT, left); 9903808843cSYunkang Tang input_report_key(dev2, BTN_RIGHT, right); 9913808843cSYunkang Tang input_report_key(dev2, BTN_MIDDLE, middle); 9923808843cSYunkang Tang 9933808843cSYunkang Tang input_sync(dev2); 9943808843cSYunkang Tang } 9953808843cSYunkang Tang 9963808843cSYunkang Tang static void alps_process_touchpad_packet_v7(struct psmouse *psmouse) 9973808843cSYunkang Tang { 9983808843cSYunkang Tang struct alps_data *priv = psmouse->private; 9993808843cSYunkang Tang struct input_dev *dev = psmouse->dev; 10003808843cSYunkang Tang struct alps_fields *f = &priv->f; 10013808843cSYunkang Tang 10023808843cSYunkang Tang memset(f, 0, sizeof(*f)); 10033808843cSYunkang Tang 10043808843cSYunkang Tang if (priv->decode_fields(f, psmouse->packet, psmouse)) 10053808843cSYunkang Tang return; 10063808843cSYunkang Tang 10073808843cSYunkang Tang alps_report_mt_data(psmouse, alps_get_mt_count(f->mt)); 10083808843cSYunkang Tang 10093808843cSYunkang Tang input_mt_report_finger_count(dev, f->fingers); 10103808843cSYunkang Tang 10113808843cSYunkang Tang input_report_key(dev, BTN_LEFT, f->left); 10123808843cSYunkang Tang input_report_key(dev, BTN_RIGHT, f->right); 10133808843cSYunkang Tang input_report_key(dev, BTN_MIDDLE, f->middle); 10143808843cSYunkang Tang 10153808843cSYunkang Tang input_sync(dev); 10163808843cSYunkang Tang } 10173808843cSYunkang Tang 10183808843cSYunkang Tang static void alps_process_packet_v7(struct psmouse *psmouse) 10193808843cSYunkang Tang { 10203808843cSYunkang Tang unsigned char *packet = psmouse->packet; 10213808843cSYunkang Tang 10223808843cSYunkang Tang if (packet[0] == 0x48 && (packet[4] & 0x47) == 0x06) 10233808843cSYunkang Tang alps_process_trackstick_packet_v7(psmouse); 10243808843cSYunkang Tang else 10253808843cSYunkang Tang alps_process_touchpad_packet_v7(psmouse); 10263808843cSYunkang Tang } 10273808843cSYunkang Tang 10281d9f2626SSebastian Kapfer static void alps_report_bare_ps2_packet(struct psmouse *psmouse, 10291d9f2626SSebastian Kapfer unsigned char packet[], 10301d9f2626SSebastian Kapfer bool report_buttons) 10311d9f2626SSebastian Kapfer { 10321d9f2626SSebastian Kapfer struct alps_data *priv = psmouse->private; 10331d9f2626SSebastian Kapfer struct input_dev *dev2 = priv->dev2; 10341d9f2626SSebastian Kapfer 10351d9f2626SSebastian Kapfer if (report_buttons) 10361d9f2626SSebastian Kapfer alps_report_buttons(psmouse, dev2, psmouse->dev, 10371d9f2626SSebastian Kapfer packet[0] & 1, packet[0] & 2, packet[0] & 4); 10381d9f2626SSebastian Kapfer 10391d9f2626SSebastian Kapfer input_report_rel(dev2, REL_X, 10401d9f2626SSebastian Kapfer packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0); 10411d9f2626SSebastian Kapfer input_report_rel(dev2, REL_Y, 10421d9f2626SSebastian Kapfer packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0); 10431d9f2626SSebastian Kapfer 10441d9f2626SSebastian Kapfer input_sync(dev2); 10451d9f2626SSebastian Kapfer } 10461d9f2626SSebastian Kapfer 10471d9f2626SSebastian Kapfer static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse) 10481da177e4SLinus Torvalds { 10491da177e4SLinus Torvalds struct alps_data *priv = psmouse->private; 10501da177e4SLinus Torvalds 10511d9f2626SSebastian Kapfer if (psmouse->pktcnt < 6) 10521d9f2626SSebastian Kapfer return PSMOUSE_GOOD_DATA; 10531d9f2626SSebastian Kapfer 10541d9f2626SSebastian Kapfer if (psmouse->pktcnt == 6) { 10551d9f2626SSebastian Kapfer /* 10561d9f2626SSebastian Kapfer * Start a timer to flush the packet if it ends up last 10571d9f2626SSebastian Kapfer * 6-byte packet in the stream. Timer needs to fire 10581d9f2626SSebastian Kapfer * psmouse core times out itself. 20 ms should be enough 10591d9f2626SSebastian Kapfer * to decide if we are getting more data or not. 10601d9f2626SSebastian Kapfer */ 10611d9f2626SSebastian Kapfer mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20)); 10621d9f2626SSebastian Kapfer return PSMOUSE_GOOD_DATA; 10631d9f2626SSebastian Kapfer } 10641d9f2626SSebastian Kapfer 10651d9f2626SSebastian Kapfer del_timer(&priv->timer); 10661d9f2626SSebastian Kapfer 10671d9f2626SSebastian Kapfer if (psmouse->packet[6] & 0x80) { 10681d9f2626SSebastian Kapfer 10691d9f2626SSebastian Kapfer /* 10701d9f2626SSebastian Kapfer * Highest bit is set - that means we either had 10711d9f2626SSebastian Kapfer * complete ALPS packet and this is start of the 10721d9f2626SSebastian Kapfer * next packet or we got garbage. 10731d9f2626SSebastian Kapfer */ 10741d9f2626SSebastian Kapfer 10751d9f2626SSebastian Kapfer if (((psmouse->packet[3] | 10761d9f2626SSebastian Kapfer psmouse->packet[4] | 10771d9f2626SSebastian Kapfer psmouse->packet[5]) & 0x80) || 107899df65e7SKevin Cernekee (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) { 1079b5d21704SDmitry Torokhov psmouse_dbg(psmouse, 10803b112923SAndy Shevchenko "refusing packet %4ph (suspected interleaved ps/2)\n", 10813b112923SAndy Shevchenko psmouse->packet + 3); 10821d9f2626SSebastian Kapfer return PSMOUSE_BAD_DATA; 10831d9f2626SSebastian Kapfer } 10841d9f2626SSebastian Kapfer 108524af5cb9SKevin Cernekee priv->process_packet(psmouse); 10861d9f2626SSebastian Kapfer 10871d9f2626SSebastian Kapfer /* Continue with the next packet */ 10881d9f2626SSebastian Kapfer psmouse->packet[0] = psmouse->packet[6]; 10891d9f2626SSebastian Kapfer psmouse->pktcnt = 1; 10901d9f2626SSebastian Kapfer 10911d9f2626SSebastian Kapfer } else { 10921d9f2626SSebastian Kapfer 10931d9f2626SSebastian Kapfer /* 10941d9f2626SSebastian Kapfer * High bit is 0 - that means that we indeed got a PS/2 10951d9f2626SSebastian Kapfer * packet in the middle of ALPS packet. 10961d9f2626SSebastian Kapfer * 10971d9f2626SSebastian Kapfer * There is also possibility that we got 6-byte ALPS 10981d9f2626SSebastian Kapfer * packet followed by 3-byte packet from trackpoint. We 10991d9f2626SSebastian Kapfer * can not distinguish between these 2 scenarios but 1100b5d21704SDmitry Torokhov * because the latter is unlikely to happen in course of 11011d9f2626SSebastian Kapfer * normal operation (user would need to press all 11021d9f2626SSebastian Kapfer * buttons on the pad and start moving trackpoint 11031d9f2626SSebastian Kapfer * without touching the pad surface) we assume former. 11041d9f2626SSebastian Kapfer * Even if we are wrong the wost thing that would happen 11051d9f2626SSebastian Kapfer * the cursor would jump but we should not get protocol 1106b5d21704SDmitry Torokhov * de-synchronization. 11071d9f2626SSebastian Kapfer */ 11081d9f2626SSebastian Kapfer 11091d9f2626SSebastian Kapfer alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3], 11101d9f2626SSebastian Kapfer false); 11111d9f2626SSebastian Kapfer 11121d9f2626SSebastian Kapfer /* 11131d9f2626SSebastian Kapfer * Continue with the standard ALPS protocol handling, 11141d9f2626SSebastian Kapfer * but make sure we won't process it as an interleaved 11151d9f2626SSebastian Kapfer * packet again, which may happen if all buttons are 11161d9f2626SSebastian Kapfer * pressed. To avoid this let's reset the 4th bit which 11171d9f2626SSebastian Kapfer * is normally 1. 11181d9f2626SSebastian Kapfer */ 11191d9f2626SSebastian Kapfer psmouse->packet[3] = psmouse->packet[6] & 0xf7; 11201d9f2626SSebastian Kapfer psmouse->pktcnt = 4; 11211d9f2626SSebastian Kapfer } 11221d9f2626SSebastian Kapfer 11231d9f2626SSebastian Kapfer return PSMOUSE_GOOD_DATA; 11241d9f2626SSebastian Kapfer } 11251d9f2626SSebastian Kapfer 11261d9f2626SSebastian Kapfer static void alps_flush_packet(unsigned long data) 11271d9f2626SSebastian Kapfer { 11281d9f2626SSebastian Kapfer struct psmouse *psmouse = (struct psmouse *)data; 112924af5cb9SKevin Cernekee struct alps_data *priv = psmouse->private; 11301d9f2626SSebastian Kapfer 11311d9f2626SSebastian Kapfer serio_pause_rx(psmouse->ps2dev.serio); 11321d9f2626SSebastian Kapfer 1133b46615feSSeth Forshee if (psmouse->pktcnt == psmouse->pktsize) { 11341d9f2626SSebastian Kapfer 11351d9f2626SSebastian Kapfer /* 11361d9f2626SSebastian Kapfer * We did not any more data in reasonable amount of time. 11371d9f2626SSebastian Kapfer * Validate the last 3 bytes and process as a standard 11381d9f2626SSebastian Kapfer * ALPS packet. 11391d9f2626SSebastian Kapfer */ 11401d9f2626SSebastian Kapfer if ((psmouse->packet[3] | 11411d9f2626SSebastian Kapfer psmouse->packet[4] | 11421d9f2626SSebastian Kapfer psmouse->packet[5]) & 0x80) { 1143b5d21704SDmitry Torokhov psmouse_dbg(psmouse, 11443b112923SAndy Shevchenko "refusing packet %3ph (suspected interleaved ps/2)\n", 11453b112923SAndy Shevchenko psmouse->packet + 3); 11461d9f2626SSebastian Kapfer } else { 114724af5cb9SKevin Cernekee priv->process_packet(psmouse); 11481d9f2626SSebastian Kapfer } 11491d9f2626SSebastian Kapfer psmouse->pktcnt = 0; 11501d9f2626SSebastian Kapfer } 11511d9f2626SSebastian Kapfer 11521d9f2626SSebastian Kapfer serio_continue_rx(psmouse->ps2dev.serio); 11531d9f2626SSebastian Kapfer } 11541d9f2626SSebastian Kapfer 11551d9f2626SSebastian Kapfer static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) 11561d9f2626SSebastian Kapfer { 11571d9f2626SSebastian Kapfer struct alps_data *priv = psmouse->private; 11581d9f2626SSebastian Kapfer 11591da177e4SLinus Torvalds if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */ 11601da177e4SLinus Torvalds if (psmouse->pktcnt == 3) { 11611d9f2626SSebastian Kapfer alps_report_bare_ps2_packet(psmouse, psmouse->packet, 11621d9f2626SSebastian Kapfer true); 11631da177e4SLinus Torvalds return PSMOUSE_FULL_PACKET; 11641da177e4SLinus Torvalds } 11651da177e4SLinus Torvalds return PSMOUSE_GOOD_DATA; 11661da177e4SLinus Torvalds } 11671da177e4SLinus Torvalds 11681d9f2626SSebastian Kapfer /* Check for PS/2 packet stuffed in the middle of ALPS packet. */ 11691d9f2626SSebastian Kapfer 117099df65e7SKevin Cernekee if ((priv->flags & ALPS_PS2_INTERLEAVED) && 11711d9f2626SSebastian Kapfer psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) { 11721d9f2626SSebastian Kapfer return alps_handle_interleaved_ps2(psmouse); 11731d9f2626SSebastian Kapfer } 11741d9f2626SSebastian Kapfer 117599df65e7SKevin Cernekee if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) { 1176b5d21704SDmitry Torokhov psmouse_dbg(psmouse, 1177b5d21704SDmitry Torokhov "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n", 117899df65e7SKevin Cernekee psmouse->packet[0], priv->mask0, priv->byte0); 11791da177e4SLinus Torvalds return PSMOUSE_BAD_DATA; 11801d9f2626SSebastian Kapfer } 11811da177e4SLinus Torvalds 1182b46615feSSeth Forshee /* Bytes 2 - pktsize should have 0 in the highest bit */ 118395f75e91SYunkang Tang if ((priv->proto_version < ALPS_PROTO_V5) && 118475af9e56SDave Turvene psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize && 11851d9f2626SSebastian Kapfer (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { 1186b5d21704SDmitry Torokhov psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", 1187b5d21704SDmitry Torokhov psmouse->pktcnt - 1, 1188b5d21704SDmitry Torokhov psmouse->packet[psmouse->pktcnt - 1]); 11891da177e4SLinus Torvalds return PSMOUSE_BAD_DATA; 11901d9f2626SSebastian Kapfer } 11911da177e4SLinus Torvalds 11923808843cSYunkang Tang if (priv->proto_version == ALPS_PROTO_V7 && 11933808843cSYunkang Tang !alps_is_valid_package_v7(psmouse)) { 11943808843cSYunkang Tang psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", 11953808843cSYunkang Tang psmouse->pktcnt - 1, 11963808843cSYunkang Tang psmouse->packet[psmouse->pktcnt - 1]); 11973808843cSYunkang Tang return PSMOUSE_BAD_DATA; 11983808843cSYunkang Tang } 11993808843cSYunkang Tang 1200b46615feSSeth Forshee if (psmouse->pktcnt == psmouse->pktsize) { 120124af5cb9SKevin Cernekee priv->process_packet(psmouse); 12021da177e4SLinus Torvalds return PSMOUSE_FULL_PACKET; 12031da177e4SLinus Torvalds } 12041da177e4SLinus Torvalds 12051da177e4SLinus Torvalds return PSMOUSE_GOOD_DATA; 12061da177e4SLinus Torvalds } 12071da177e4SLinus Torvalds 120825bded7cSSeth Forshee static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble) 120925bded7cSSeth Forshee { 121025bded7cSSeth Forshee struct ps2dev *ps2dev = &psmouse->ps2dev; 121125bded7cSSeth Forshee struct alps_data *priv = psmouse->private; 121225bded7cSSeth Forshee int command; 121325bded7cSSeth Forshee unsigned char *param; 121425bded7cSSeth Forshee unsigned char dummy[4]; 121525bded7cSSeth Forshee 121625bded7cSSeth Forshee BUG_ON(nibble > 0xf); 121725bded7cSSeth Forshee 121825bded7cSSeth Forshee command = priv->nibble_commands[nibble].command; 121925bded7cSSeth Forshee param = (command & 0x0f00) ? 122025bded7cSSeth Forshee dummy : (unsigned char *)&priv->nibble_commands[nibble].data; 122125bded7cSSeth Forshee 122225bded7cSSeth Forshee if (ps2_command(ps2dev, param, command)) 122325bded7cSSeth Forshee return -1; 122425bded7cSSeth Forshee 122525bded7cSSeth Forshee return 0; 122625bded7cSSeth Forshee } 122725bded7cSSeth Forshee 122825bded7cSSeth Forshee static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr) 122925bded7cSSeth Forshee { 123025bded7cSSeth Forshee struct ps2dev *ps2dev = &psmouse->ps2dev; 123125bded7cSSeth Forshee struct alps_data *priv = psmouse->private; 123225bded7cSSeth Forshee int i, nibble; 123325bded7cSSeth Forshee 123425bded7cSSeth Forshee if (ps2_command(ps2dev, NULL, priv->addr_command)) 123525bded7cSSeth Forshee return -1; 123625bded7cSSeth Forshee 123725bded7cSSeth Forshee for (i = 12; i >= 0; i -= 4) { 123825bded7cSSeth Forshee nibble = (addr >> i) & 0xf; 123925bded7cSSeth Forshee if (alps_command_mode_send_nibble(psmouse, nibble)) 124025bded7cSSeth Forshee return -1; 124125bded7cSSeth Forshee } 124225bded7cSSeth Forshee 124325bded7cSSeth Forshee return 0; 124425bded7cSSeth Forshee } 124525bded7cSSeth Forshee 124625bded7cSSeth Forshee static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr) 124725bded7cSSeth Forshee { 124825bded7cSSeth Forshee struct ps2dev *ps2dev = &psmouse->ps2dev; 124925bded7cSSeth Forshee unsigned char param[4]; 125025bded7cSSeth Forshee 125125bded7cSSeth Forshee if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) 125225bded7cSSeth Forshee return -1; 125325bded7cSSeth Forshee 125425bded7cSSeth Forshee /* 125525bded7cSSeth Forshee * The address being read is returned in the first two bytes 125625bded7cSSeth Forshee * of the result. Check that this address matches the expected 125725bded7cSSeth Forshee * address. 125825bded7cSSeth Forshee */ 125925bded7cSSeth Forshee if (addr != ((param[0] << 8) | param[1])) 126025bded7cSSeth Forshee return -1; 126125bded7cSSeth Forshee 126225bded7cSSeth Forshee return param[2]; 126325bded7cSSeth Forshee } 126425bded7cSSeth Forshee 126525bded7cSSeth Forshee static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr) 126625bded7cSSeth Forshee { 126725bded7cSSeth Forshee if (alps_command_mode_set_addr(psmouse, addr)) 126825bded7cSSeth Forshee return -1; 126925bded7cSSeth Forshee return __alps_command_mode_read_reg(psmouse, addr); 127025bded7cSSeth Forshee } 127125bded7cSSeth Forshee 127225bded7cSSeth Forshee static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value) 127325bded7cSSeth Forshee { 127425bded7cSSeth Forshee if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf)) 127525bded7cSSeth Forshee return -1; 127625bded7cSSeth Forshee if (alps_command_mode_send_nibble(psmouse, value & 0xf)) 127725bded7cSSeth Forshee return -1; 127825bded7cSSeth Forshee return 0; 127925bded7cSSeth Forshee } 128025bded7cSSeth Forshee 128125bded7cSSeth Forshee static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr, 128225bded7cSSeth Forshee u8 value) 128325bded7cSSeth Forshee { 128425bded7cSSeth Forshee if (alps_command_mode_set_addr(psmouse, addr)) 128525bded7cSSeth Forshee return -1; 128625bded7cSSeth Forshee return __alps_command_mode_write_reg(psmouse, value); 128725bded7cSSeth Forshee } 128825bded7cSSeth Forshee 128924ba9707SKevin Cernekee static int alps_rpt_cmd(struct psmouse *psmouse, int init_command, 129024ba9707SKevin Cernekee int repeated_command, unsigned char *param) 129124ba9707SKevin Cernekee { 129224ba9707SKevin Cernekee struct ps2dev *ps2dev = &psmouse->ps2dev; 129324ba9707SKevin Cernekee 129424ba9707SKevin Cernekee param[0] = 0; 129524ba9707SKevin Cernekee if (init_command && ps2_command(ps2dev, param, init_command)) 129624ba9707SKevin Cernekee return -EIO; 129724ba9707SKevin Cernekee 129824ba9707SKevin Cernekee if (ps2_command(ps2dev, NULL, repeated_command) || 129924ba9707SKevin Cernekee ps2_command(ps2dev, NULL, repeated_command) || 130024ba9707SKevin Cernekee ps2_command(ps2dev, NULL, repeated_command)) 130124ba9707SKevin Cernekee return -EIO; 130224ba9707SKevin Cernekee 130324ba9707SKevin Cernekee param[0] = param[1] = param[2] = 0xff; 130424ba9707SKevin Cernekee if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) 130524ba9707SKevin Cernekee return -EIO; 130624ba9707SKevin Cernekee 130739fbe585SDmitry Torokhov psmouse_dbg(psmouse, "%2.2X report: %3ph\n", 130839fbe585SDmitry Torokhov repeated_command, param); 130924ba9707SKevin Cernekee return 0; 131024ba9707SKevin Cernekee } 131124ba9707SKevin Cernekee 13123808843cSYunkang Tang static bool alps_check_valid_firmware_id(unsigned char id[]) 13133808843cSYunkang Tang { 13143808843cSYunkang Tang if (id[0] == 0x73) 13153808843cSYunkang Tang return true; 13163808843cSYunkang Tang 13173808843cSYunkang Tang if (id[0] == 0x88 && 13183808843cSYunkang Tang (id[1] == 0x07 || 13193808843cSYunkang Tang id[1] == 0x08 || 13203808843cSYunkang Tang (id[1] & 0xf0) == 0xb0 || 13213808843cSYunkang Tang (id[1] & 0xf0) == 0xc0)) { 13223808843cSYunkang Tang return true; 13233808843cSYunkang Tang } 13243808843cSYunkang Tang 13253808843cSYunkang Tang return false; 13263808843cSYunkang Tang } 13273808843cSYunkang Tang 1328d18e53fcSKevin Cernekee static int alps_enter_command_mode(struct psmouse *psmouse) 132925bded7cSSeth Forshee { 133025bded7cSSeth Forshee unsigned char param[4]; 133125bded7cSSeth Forshee 133224ba9707SKevin Cernekee if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) { 133325bded7cSSeth Forshee psmouse_err(psmouse, "failed to enter command mode\n"); 133425bded7cSSeth Forshee return -1; 133525bded7cSSeth Forshee } 133625bded7cSSeth Forshee 13373808843cSYunkang Tang if (!alps_check_valid_firmware_id(param)) { 133825bded7cSSeth Forshee psmouse_dbg(psmouse, 133924ba9707SKevin Cernekee "unknown response while entering command mode\n"); 134025bded7cSSeth Forshee return -1; 134125bded7cSSeth Forshee } 134225bded7cSSeth Forshee return 0; 134325bded7cSSeth Forshee } 134425bded7cSSeth Forshee 134525bded7cSSeth Forshee static inline int alps_exit_command_mode(struct psmouse *psmouse) 134625bded7cSSeth Forshee { 134725bded7cSSeth Forshee struct ps2dev *ps2dev = &psmouse->ps2dev; 134825bded7cSSeth Forshee if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) 134925bded7cSSeth Forshee return -1; 135025bded7cSSeth Forshee return 0; 135125bded7cSSeth Forshee } 135225bded7cSSeth Forshee 13531da177e4SLinus Torvalds /* 13541da177e4SLinus Torvalds * For DualPoint devices select the device that should respond to 13551da177e4SLinus Torvalds * subsequent commands. It looks like glidepad is behind stickpointer, 13561da177e4SLinus Torvalds * I'd thought it would be other way around... 13571da177e4SLinus Torvalds */ 135825bded7cSSeth Forshee static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable) 13591da177e4SLinus Torvalds { 13601da177e4SLinus Torvalds struct ps2dev *ps2dev = &psmouse->ps2dev; 13611da177e4SLinus Torvalds int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; 13621da177e4SLinus Torvalds 13631da177e4SLinus Torvalds if (ps2_command(ps2dev, NULL, cmd) || 13641da177e4SLinus Torvalds ps2_command(ps2dev, NULL, cmd) || 13651da177e4SLinus Torvalds ps2_command(ps2dev, NULL, cmd) || 13661da177e4SLinus Torvalds ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE)) 13671da177e4SLinus Torvalds return -1; 13681da177e4SLinus Torvalds 13691da177e4SLinus Torvalds /* we may get 3 more bytes, just ignore them */ 1370c611763dSDmitry Torokhov ps2_drain(ps2dev, 3, 100); 13711da177e4SLinus Torvalds 13721da177e4SLinus Torvalds return 0; 13731da177e4SLinus Torvalds } 13741da177e4SLinus Torvalds 137525bded7cSSeth Forshee static int alps_absolute_mode_v1_v2(struct psmouse *psmouse) 13761da177e4SLinus Torvalds { 13771da177e4SLinus Torvalds struct ps2dev *ps2dev = &psmouse->ps2dev; 13781da177e4SLinus Torvalds 13791da177e4SLinus Torvalds /* Try ALPS magic knock - 4 disable before enable */ 13801da177e4SLinus Torvalds if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 13811da177e4SLinus Torvalds ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 13821da177e4SLinus Torvalds ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 13831da177e4SLinus Torvalds ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 13841da177e4SLinus Torvalds ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) 13851da177e4SLinus Torvalds return -1; 13861da177e4SLinus Torvalds 13871da177e4SLinus Torvalds /* 13881da177e4SLinus Torvalds * Switch mouse to poll (remote) mode so motion data will not 13891da177e4SLinus Torvalds * get in our way 13901da177e4SLinus Torvalds */ 13911da177e4SLinus Torvalds return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL); 13921da177e4SLinus Torvalds } 13931da177e4SLinus Torvalds 139495f75e91SYunkang Tang static int alps_monitor_mode_send_word(struct psmouse *psmouse, u16 word) 139595f75e91SYunkang Tang { 139695f75e91SYunkang Tang int i, nibble; 139795f75e91SYunkang Tang 139895f75e91SYunkang Tang /* 139995f75e91SYunkang Tang * b0-b11 are valid bits, send sequence is inverse. 140095f75e91SYunkang Tang * e.g. when word = 0x0123, nibble send sequence is 3, 2, 1 140195f75e91SYunkang Tang */ 140295f75e91SYunkang Tang for (i = 0; i <= 8; i += 4) { 140395f75e91SYunkang Tang nibble = (word >> i) & 0xf; 140495f75e91SYunkang Tang if (alps_command_mode_send_nibble(psmouse, nibble)) 140595f75e91SYunkang Tang return -1; 140695f75e91SYunkang Tang } 140795f75e91SYunkang Tang 140895f75e91SYunkang Tang return 0; 140995f75e91SYunkang Tang } 141095f75e91SYunkang Tang 141195f75e91SYunkang Tang static int alps_monitor_mode_write_reg(struct psmouse *psmouse, 141295f75e91SYunkang Tang u16 addr, u16 value) 141395f75e91SYunkang Tang { 141495f75e91SYunkang Tang struct ps2dev *ps2dev = &psmouse->ps2dev; 141595f75e91SYunkang Tang 141695f75e91SYunkang Tang /* 0x0A0 is the command to write the word */ 141795f75e91SYunkang Tang if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE) || 141895f75e91SYunkang Tang alps_monitor_mode_send_word(psmouse, 0x0A0) || 141995f75e91SYunkang Tang alps_monitor_mode_send_word(psmouse, addr) || 142095f75e91SYunkang Tang alps_monitor_mode_send_word(psmouse, value) || 142195f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE)) 142295f75e91SYunkang Tang return -1; 142395f75e91SYunkang Tang 142495f75e91SYunkang Tang return 0; 142595f75e91SYunkang Tang } 142695f75e91SYunkang Tang 142795f75e91SYunkang Tang static int alps_monitor_mode(struct psmouse *psmouse, bool enable) 142895f75e91SYunkang Tang { 142995f75e91SYunkang Tang struct ps2dev *ps2dev = &psmouse->ps2dev; 143095f75e91SYunkang Tang 143195f75e91SYunkang Tang if (enable) { 143295f75e91SYunkang Tang /* EC E9 F5 F5 E7 E6 E7 E9 to enter monitor mode */ 143395f75e91SYunkang Tang if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || 143495f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO) || 143595f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 143695f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 143795f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || 143895f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || 143995f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || 144095f75e91SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO)) 144195f75e91SYunkang Tang return -1; 144295f75e91SYunkang Tang } else { 144395f75e91SYunkang Tang /* EC to exit monitor mode */ 144495f75e91SYunkang Tang if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP)) 144595f75e91SYunkang Tang return -1; 144695f75e91SYunkang Tang } 144795f75e91SYunkang Tang 144895f75e91SYunkang Tang return 0; 144995f75e91SYunkang Tang } 145095f75e91SYunkang Tang 145195f75e91SYunkang Tang static int alps_absolute_mode_v6(struct psmouse *psmouse) 145295f75e91SYunkang Tang { 145395f75e91SYunkang Tang u16 reg_val = 0x181; 145495f75e91SYunkang Tang int ret = -1; 145595f75e91SYunkang Tang 145695f75e91SYunkang Tang /* enter monitor mode, to write the register */ 145795f75e91SYunkang Tang if (alps_monitor_mode(psmouse, true)) 145895f75e91SYunkang Tang return -1; 145995f75e91SYunkang Tang 146095f75e91SYunkang Tang ret = alps_monitor_mode_write_reg(psmouse, 0x000, reg_val); 146195f75e91SYunkang Tang 146295f75e91SYunkang Tang if (alps_monitor_mode(psmouse, false)) 146395f75e91SYunkang Tang ret = -1; 146495f75e91SYunkang Tang 146595f75e91SYunkang Tang return ret; 146695f75e91SYunkang Tang } 146795f75e91SYunkang Tang 14681da177e4SLinus Torvalds static int alps_get_status(struct psmouse *psmouse, char *param) 14691da177e4SLinus Torvalds { 14701da177e4SLinus Torvalds /* Get status: 0xF5 0xF5 0xF5 0xE9 */ 147124ba9707SKevin Cernekee if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param)) 14721da177e4SLinus Torvalds return -1; 14731da177e4SLinus Torvalds 14741da177e4SLinus Torvalds return 0; 14751da177e4SLinus Torvalds } 14761da177e4SLinus Torvalds 14771da177e4SLinus Torvalds /* 14781da177e4SLinus Torvalds * Turn touchpad tapping on or off. The sequences are: 14791da177e4SLinus Torvalds * 0xE9 0xF5 0xF5 0xF3 0x0A to enable, 14801da177e4SLinus Torvalds * 0xE9 0xF5 0xF5 0xE8 0x00 to disable. 14811da177e4SLinus Torvalds * My guess that 0xE9 (GetInfo) is here as a sync point. 14821da177e4SLinus Torvalds * For models that also have stickpointer (DualPoints) its tapping 14831da177e4SLinus Torvalds * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but 14841da177e4SLinus Torvalds * we don't fiddle with it. 14851da177e4SLinus Torvalds */ 14861da177e4SLinus Torvalds static int alps_tap_mode(struct psmouse *psmouse, int enable) 14871da177e4SLinus Torvalds { 14881da177e4SLinus Torvalds struct ps2dev *ps2dev = &psmouse->ps2dev; 14891da177e4SLinus Torvalds int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES; 14901da177e4SLinus Torvalds unsigned char tap_arg = enable ? 0x0A : 0x00; 14911da177e4SLinus Torvalds unsigned char param[4]; 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) || 14941da177e4SLinus Torvalds ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 14951da177e4SLinus Torvalds ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 14961da177e4SLinus Torvalds ps2_command(ps2dev, &tap_arg, cmd)) 14971da177e4SLinus Torvalds return -1; 14981da177e4SLinus Torvalds 14991da177e4SLinus Torvalds if (alps_get_status(psmouse, param)) 15001da177e4SLinus Torvalds return -1; 15011da177e4SLinus Torvalds 15021da177e4SLinus Torvalds return 0; 15031da177e4SLinus Torvalds } 15041da177e4SLinus Torvalds 1505f0d5c6f4SDmitry Torokhov /* 1506f0d5c6f4SDmitry Torokhov * alps_poll() - poll the touchpad for current motion packet. 1507f0d5c6f4SDmitry Torokhov * Used in resync. 1508f0d5c6f4SDmitry Torokhov */ 1509f0d5c6f4SDmitry Torokhov static int alps_poll(struct psmouse *psmouse) 1510f0d5c6f4SDmitry Torokhov { 1511f0d5c6f4SDmitry Torokhov struct alps_data *priv = psmouse->private; 1512b46615feSSeth Forshee unsigned char buf[sizeof(psmouse->packet)]; 1513b7802c5cSDmitry Torokhov bool poll_failed; 1514f0d5c6f4SDmitry Torokhov 151599df65e7SKevin Cernekee if (priv->flags & ALPS_PASS) 151625bded7cSSeth Forshee alps_passthrough_mode_v2(psmouse, true); 1517f0d5c6f4SDmitry Torokhov 1518f0d5c6f4SDmitry Torokhov poll_failed = ps2_command(&psmouse->ps2dev, buf, 1519f0d5c6f4SDmitry Torokhov PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; 1520f0d5c6f4SDmitry Torokhov 152199df65e7SKevin Cernekee if (priv->flags & ALPS_PASS) 152225bded7cSSeth Forshee alps_passthrough_mode_v2(psmouse, false); 1523f0d5c6f4SDmitry Torokhov 152499df65e7SKevin Cernekee if (poll_failed || (buf[0] & priv->mask0) != priv->byte0) 1525f0d5c6f4SDmitry Torokhov return -1; 1526f0d5c6f4SDmitry Torokhov 1527f0d5c6f4SDmitry Torokhov if ((psmouse->badbyte & 0xc8) == 0x08) { 1528f0d5c6f4SDmitry Torokhov /* 1529f0d5c6f4SDmitry Torokhov * Poll the track stick ... 1530f0d5c6f4SDmitry Torokhov */ 1531f0d5c6f4SDmitry Torokhov if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8))) 1532f0d5c6f4SDmitry Torokhov return -1; 1533f0d5c6f4SDmitry Torokhov } 1534f0d5c6f4SDmitry Torokhov 1535f0d5c6f4SDmitry Torokhov memcpy(psmouse->packet, buf, sizeof(buf)); 1536f0d5c6f4SDmitry Torokhov return 0; 1537f0d5c6f4SDmitry Torokhov } 1538f0d5c6f4SDmitry Torokhov 153925bded7cSSeth Forshee static int alps_hw_init_v1_v2(struct psmouse *psmouse) 15401da177e4SLinus Torvalds { 15411da177e4SLinus Torvalds struct alps_data *priv = psmouse->private; 15421da177e4SLinus Torvalds 154399df65e7SKevin Cernekee if ((priv->flags & ALPS_PASS) && 154425bded7cSSeth Forshee alps_passthrough_mode_v2(psmouse, true)) { 15451da177e4SLinus Torvalds return -1; 1546b7802c5cSDmitry Torokhov } 15471da177e4SLinus Torvalds 1548b7802c5cSDmitry Torokhov if (alps_tap_mode(psmouse, true)) { 1549b5d21704SDmitry Torokhov psmouse_warn(psmouse, "Failed to enable hardware tapping\n"); 15501da177e4SLinus Torvalds return -1; 1551963f626dSPeter Osterlund } 15521da177e4SLinus Torvalds 155325bded7cSSeth Forshee if (alps_absolute_mode_v1_v2(psmouse)) { 1554b5d21704SDmitry Torokhov psmouse_err(psmouse, "Failed to enable absolute mode\n"); 15551da177e4SLinus Torvalds return -1; 15561da177e4SLinus Torvalds } 15571da177e4SLinus Torvalds 155899df65e7SKevin Cernekee if ((priv->flags & ALPS_PASS) && 155925bded7cSSeth Forshee alps_passthrough_mode_v2(psmouse, false)) { 15601da177e4SLinus Torvalds return -1; 1561b7802c5cSDmitry Torokhov } 15621da177e4SLinus Torvalds 15631e0c5b12SDmitry Torokhov /* ALPS needs stream mode, otherwise it won't report any data */ 15641e0c5b12SDmitry Torokhov if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) { 1565b5d21704SDmitry Torokhov psmouse_err(psmouse, "Failed to enable stream mode\n"); 15661e0c5b12SDmitry Torokhov return -1; 15671e0c5b12SDmitry Torokhov } 15681e0c5b12SDmitry Torokhov 15691e0c5b12SDmitry Torokhov return 0; 15701e0c5b12SDmitry Torokhov } 15711e0c5b12SDmitry Torokhov 157295f75e91SYunkang Tang static int alps_hw_init_v6(struct psmouse *psmouse) 157395f75e91SYunkang Tang { 157495f75e91SYunkang Tang unsigned char param[2] = {0xC8, 0x14}; 157595f75e91SYunkang Tang 157695f75e91SYunkang Tang /* Enter passthrough mode to let trackpoint enter 6byte raw mode */ 157795f75e91SYunkang Tang if (alps_passthrough_mode_v2(psmouse, true)) 157895f75e91SYunkang Tang return -1; 157995f75e91SYunkang Tang 158095f75e91SYunkang Tang if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || 158195f75e91SYunkang Tang ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || 158295f75e91SYunkang Tang ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || 158395f75e91SYunkang Tang ps2_command(&psmouse->ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || 158495f75e91SYunkang Tang ps2_command(&psmouse->ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE)) 158595f75e91SYunkang Tang return -1; 158695f75e91SYunkang Tang 158795f75e91SYunkang Tang if (alps_passthrough_mode_v2(psmouse, false)) 158895f75e91SYunkang Tang return -1; 158995f75e91SYunkang Tang 159095f75e91SYunkang Tang if (alps_absolute_mode_v6(psmouse)) { 159195f75e91SYunkang Tang psmouse_err(psmouse, "Failed to enable absolute mode\n"); 159295f75e91SYunkang Tang return -1; 159395f75e91SYunkang Tang } 159495f75e91SYunkang Tang 159595f75e91SYunkang Tang return 0; 159695f75e91SYunkang Tang } 159795f75e91SYunkang Tang 159825bded7cSSeth Forshee /* 1599cd401204SKevin Cernekee * Enable or disable passthrough mode to the trackstick. 160025bded7cSSeth Forshee */ 1601cd401204SKevin Cernekee static int alps_passthrough_mode_v3(struct psmouse *psmouse, 1602cd401204SKevin Cernekee int reg_base, bool enable) 160325bded7cSSeth Forshee { 1604cd401204SKevin Cernekee int reg_val, ret = -1; 160525bded7cSSeth Forshee 1606d18e53fcSKevin Cernekee if (alps_enter_command_mode(psmouse)) 160725bded7cSSeth Forshee return -1; 160825bded7cSSeth Forshee 1609cd401204SKevin Cernekee reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x0008); 1610cd401204SKevin Cernekee if (reg_val == -1) 1611cd401204SKevin Cernekee goto error; 1612cd401204SKevin Cernekee 161325bded7cSSeth Forshee if (enable) 161425bded7cSSeth Forshee reg_val |= 0x01; 161525bded7cSSeth Forshee else 161625bded7cSSeth Forshee reg_val &= ~0x01; 161725bded7cSSeth Forshee 1618cd401204SKevin Cernekee ret = __alps_command_mode_write_reg(psmouse, reg_val); 161925bded7cSSeth Forshee 1620cd401204SKevin Cernekee error: 1621cd401204SKevin Cernekee if (alps_exit_command_mode(psmouse)) 1622cd401204SKevin Cernekee ret = -1; 1623cd401204SKevin Cernekee return ret; 162425bded7cSSeth Forshee } 162525bded7cSSeth Forshee 162625bded7cSSeth Forshee /* Must be in command mode when calling this function */ 162725bded7cSSeth Forshee static int alps_absolute_mode_v3(struct psmouse *psmouse) 162825bded7cSSeth Forshee { 162925bded7cSSeth Forshee int reg_val; 163025bded7cSSeth Forshee 163125bded7cSSeth Forshee reg_val = alps_command_mode_read_reg(psmouse, 0x0004); 163225bded7cSSeth Forshee if (reg_val == -1) 163325bded7cSSeth Forshee return -1; 163425bded7cSSeth Forshee 163525bded7cSSeth Forshee reg_val |= 0x06; 163625bded7cSSeth Forshee if (__alps_command_mode_write_reg(psmouse, reg_val)) 163725bded7cSSeth Forshee return -1; 163825bded7cSSeth Forshee 163925bded7cSSeth Forshee return 0; 164025bded7cSSeth Forshee } 164125bded7cSSeth Forshee 1642cd401204SKevin Cernekee static int alps_probe_trackstick_v3(struct psmouse *psmouse, int reg_base) 164325bded7cSSeth Forshee { 1644cd401204SKevin Cernekee int ret = -EIO, reg_val; 164525bded7cSSeth Forshee 1646d18e53fcSKevin Cernekee if (alps_enter_command_mode(psmouse)) 164725bded7cSSeth Forshee goto error; 164825bded7cSSeth Forshee 1649cd401204SKevin Cernekee reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08); 165025bded7cSSeth Forshee if (reg_val == -1) 165125bded7cSSeth Forshee goto error; 1652cd401204SKevin Cernekee 1653cd401204SKevin Cernekee /* bit 7: trackstick is present */ 1654cd401204SKevin Cernekee ret = reg_val & 0x80 ? 0 : -ENODEV; 1655cd401204SKevin Cernekee 1656cd401204SKevin Cernekee error: 1657cd401204SKevin Cernekee alps_exit_command_mode(psmouse); 1658cd401204SKevin Cernekee return ret; 1659cd401204SKevin Cernekee } 1660cd401204SKevin Cernekee 1661cd401204SKevin Cernekee static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base) 1662cd401204SKevin Cernekee { 1663cd401204SKevin Cernekee struct ps2dev *ps2dev = &psmouse->ps2dev; 1664cd401204SKevin Cernekee int ret = 0; 1665cd401204SKevin Cernekee unsigned char param[4]; 1666cd401204SKevin Cernekee 1667cd401204SKevin Cernekee if (alps_passthrough_mode_v3(psmouse, reg_base, true)) 1668cd401204SKevin Cernekee return -EIO; 166925bded7cSSeth Forshee 167025bded7cSSeth Forshee /* 167125bded7cSSeth Forshee * E7 report for the trackstick 167225bded7cSSeth Forshee * 167325bded7cSSeth Forshee * There have been reports of failures to seem to trace back 167425bded7cSSeth Forshee * to the above trackstick check failing. When these occur 167525bded7cSSeth Forshee * this E7 report fails, so when that happens we continue 167625bded7cSSeth Forshee * with the assumption that there isn't a trackstick after 167725bded7cSSeth Forshee * all. 167825bded7cSSeth Forshee */ 1679cd401204SKevin Cernekee if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_SETSCALE21, param)) { 168025bded7cSSeth Forshee psmouse_warn(psmouse, "trackstick E7 report failed\n"); 1681cd401204SKevin Cernekee ret = -ENODEV; 168225bded7cSSeth Forshee } else { 168339fbe585SDmitry Torokhov psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param); 168425bded7cSSeth Forshee 168525bded7cSSeth Forshee /* 168625bded7cSSeth Forshee * Not sure what this does, but it is absolutely 168725bded7cSSeth Forshee * essential. Without it, the touchpad does not 168825bded7cSSeth Forshee * work at all and the trackstick just emits normal 168925bded7cSSeth Forshee * PS/2 packets. 169025bded7cSSeth Forshee */ 169125bded7cSSeth Forshee if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || 169225bded7cSSeth Forshee ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || 169325bded7cSSeth Forshee ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || 169425bded7cSSeth Forshee alps_command_mode_send_nibble(psmouse, 0x9) || 169525bded7cSSeth Forshee alps_command_mode_send_nibble(psmouse, 0x4)) { 169625bded7cSSeth Forshee psmouse_err(psmouse, 169725bded7cSSeth Forshee "Error sending magic E6 sequence\n"); 1698cd401204SKevin Cernekee ret = -EIO; 169925bded7cSSeth Forshee goto error; 170025bded7cSSeth Forshee } 170125bded7cSSeth Forshee 1702cd401204SKevin Cernekee /* 1703cd401204SKevin Cernekee * This ensures the trackstick packets are in the format 1704cd401204SKevin Cernekee * supported by this driver. If bit 1 isn't set the packet 1705cd401204SKevin Cernekee * format is different. 1706cd401204SKevin Cernekee */ 1707d18e53fcSKevin Cernekee if (alps_enter_command_mode(psmouse) || 1708cd401204SKevin Cernekee alps_command_mode_write_reg(psmouse, 1709cd401204SKevin Cernekee reg_base + 0x08, 0x82) || 1710cd401204SKevin Cernekee alps_exit_command_mode(psmouse)) 1711cd401204SKevin Cernekee ret = -EIO; 1712cd401204SKevin Cernekee } 1713cd401204SKevin Cernekee 1714cd401204SKevin Cernekee error: 1715cd401204SKevin Cernekee if (alps_passthrough_mode_v3(psmouse, reg_base, false)) 1716cd401204SKevin Cernekee ret = -EIO; 1717cd401204SKevin Cernekee 1718cd401204SKevin Cernekee return ret; 1719cd401204SKevin Cernekee } 1720cd401204SKevin Cernekee 1721cd401204SKevin Cernekee static int alps_hw_init_v3(struct psmouse *psmouse) 1722cd401204SKevin Cernekee { 1723cd401204SKevin Cernekee struct ps2dev *ps2dev = &psmouse->ps2dev; 1724cd401204SKevin Cernekee int reg_val; 1725cd401204SKevin Cernekee unsigned char param[4]; 1726cd401204SKevin Cernekee 1727cd401204SKevin Cernekee reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE); 1728cd401204SKevin Cernekee if (reg_val == -EIO) 1729cd401204SKevin Cernekee goto error; 173039fbe585SDmitry Torokhov 1731cd401204SKevin Cernekee if (reg_val == 0 && 1732cd401204SKevin Cernekee alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO) 1733cd401204SKevin Cernekee goto error; 1734cd401204SKevin Cernekee 1735d18e53fcSKevin Cernekee if (alps_enter_command_mode(psmouse) || 1736cd401204SKevin Cernekee alps_absolute_mode_v3(psmouse)) { 173725bded7cSSeth Forshee psmouse_err(psmouse, "Failed to enter absolute mode\n"); 173825bded7cSSeth Forshee goto error; 173925bded7cSSeth Forshee } 174025bded7cSSeth Forshee 174125bded7cSSeth Forshee reg_val = alps_command_mode_read_reg(psmouse, 0x0006); 174225bded7cSSeth Forshee if (reg_val == -1) 174325bded7cSSeth Forshee goto error; 174425bded7cSSeth Forshee if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) 174525bded7cSSeth Forshee goto error; 174625bded7cSSeth Forshee 174725bded7cSSeth Forshee reg_val = alps_command_mode_read_reg(psmouse, 0x0007); 174825bded7cSSeth Forshee if (reg_val == -1) 174925bded7cSSeth Forshee goto error; 175025bded7cSSeth Forshee if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) 175125bded7cSSeth Forshee goto error; 175225bded7cSSeth Forshee 175325bded7cSSeth Forshee if (alps_command_mode_read_reg(psmouse, 0x0144) == -1) 175425bded7cSSeth Forshee goto error; 175525bded7cSSeth Forshee if (__alps_command_mode_write_reg(psmouse, 0x04)) 175625bded7cSSeth Forshee goto error; 175725bded7cSSeth Forshee 175825bded7cSSeth Forshee if (alps_command_mode_read_reg(psmouse, 0x0159) == -1) 175925bded7cSSeth Forshee goto error; 176025bded7cSSeth Forshee if (__alps_command_mode_write_reg(psmouse, 0x03)) 176125bded7cSSeth Forshee goto error; 176225bded7cSSeth Forshee 176325bded7cSSeth Forshee if (alps_command_mode_read_reg(psmouse, 0x0163) == -1) 176425bded7cSSeth Forshee goto error; 176525bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03)) 176625bded7cSSeth Forshee goto error; 176725bded7cSSeth Forshee 176825bded7cSSeth Forshee if (alps_command_mode_read_reg(psmouse, 0x0162) == -1) 176925bded7cSSeth Forshee goto error; 177025bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04)) 177125bded7cSSeth Forshee goto error; 177225bded7cSSeth Forshee 177325bded7cSSeth Forshee alps_exit_command_mode(psmouse); 177425bded7cSSeth Forshee 177525bded7cSSeth Forshee /* Set rate and enable data reporting */ 177625bded7cSSeth Forshee param[0] = 0x64; 177725bded7cSSeth Forshee if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || 177825bded7cSSeth Forshee ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { 177925bded7cSSeth Forshee psmouse_err(psmouse, "Failed to enable data reporting\n"); 178025bded7cSSeth Forshee return -1; 178125bded7cSSeth Forshee } 178225bded7cSSeth Forshee 178325bded7cSSeth Forshee return 0; 178425bded7cSSeth Forshee 178525bded7cSSeth Forshee error: 178625bded7cSSeth Forshee /* 178725bded7cSSeth Forshee * Leaving the touchpad in command mode will essentially render 178825bded7cSSeth Forshee * it unusable until the machine reboots, so exit it here just 178925bded7cSSeth Forshee * to be safe 179025bded7cSSeth Forshee */ 179125bded7cSSeth Forshee alps_exit_command_mode(psmouse); 179225bded7cSSeth Forshee return -1; 179325bded7cSSeth Forshee } 179425bded7cSSeth Forshee 1795f3f33c67SHans de Goede static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch) 1796f3f33c67SHans de Goede { 1797f3f33c67SHans de Goede int reg, x_pitch, y_pitch, x_electrode, y_electrode, x_phys, y_phys; 1798f3f33c67SHans de Goede struct alps_data *priv = psmouse->private; 1799f3f33c67SHans de Goede 1800f3f33c67SHans de Goede reg = alps_command_mode_read_reg(psmouse, reg_pitch); 1801f3f33c67SHans de Goede if (reg < 0) 1802f3f33c67SHans de Goede return reg; 1803f3f33c67SHans de Goede 1804f3f33c67SHans de Goede x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */ 1805f3f33c67SHans de Goede x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */ 1806f3f33c67SHans de Goede 1807f3f33c67SHans de Goede y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */ 1808f3f33c67SHans de Goede y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */ 1809f3f33c67SHans de Goede 1810f3f33c67SHans de Goede reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1); 1811f3f33c67SHans de Goede if (reg < 0) 1812f3f33c67SHans de Goede return reg; 1813f3f33c67SHans de Goede 1814f3f33c67SHans de Goede x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */ 1815f3f33c67SHans de Goede x_electrode = 17 + x_electrode; 1816f3f33c67SHans de Goede 1817f3f33c67SHans de Goede y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */ 1818f3f33c67SHans de Goede y_electrode = 13 + y_electrode; 1819f3f33c67SHans de Goede 1820f3f33c67SHans de Goede x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */ 1821f3f33c67SHans de Goede y_phys = y_pitch * (y_electrode - 1); /* In 0.1 mm units */ 1822f3f33c67SHans de Goede 1823f3f33c67SHans de Goede priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */ 1824f3f33c67SHans de Goede priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */ 1825f3f33c67SHans de Goede 1826f3f33c67SHans de Goede psmouse_dbg(psmouse, 1827f3f33c67SHans de Goede "pitch %dx%d num-electrodes %dx%d physical size %dx%d mm res %dx%d\n", 1828f3f33c67SHans de Goede x_pitch, y_pitch, x_electrode, y_electrode, 1829f3f33c67SHans de Goede x_phys / 10, y_phys / 10, priv->x_res, priv->y_res); 1830f3f33c67SHans de Goede 1831f3f33c67SHans de Goede return 0; 1832f3f33c67SHans de Goede } 1833f3f33c67SHans de Goede 18341302bac3SKevin Cernekee static int alps_hw_init_rushmore_v3(struct psmouse *psmouse) 18351302bac3SKevin Cernekee { 1836cd401204SKevin Cernekee struct alps_data *priv = psmouse->private; 18371302bac3SKevin Cernekee struct ps2dev *ps2dev = &psmouse->ps2dev; 18381302bac3SKevin Cernekee int reg_val, ret = -1; 18391302bac3SKevin Cernekee 1840cd401204SKevin Cernekee if (priv->flags & ALPS_DUALPOINT) { 1841cd401204SKevin Cernekee reg_val = alps_setup_trackstick_v3(psmouse, 1842cd401204SKevin Cernekee ALPS_REG_BASE_RUSHMORE); 1843cd401204SKevin Cernekee if (reg_val == -EIO) 1844cd401204SKevin Cernekee goto error; 1845cd401204SKevin Cernekee if (reg_val == -ENODEV) 1846cd401204SKevin Cernekee priv->flags &= ~ALPS_DUALPOINT; 1847cd401204SKevin Cernekee } 1848cd401204SKevin Cernekee 1849d18e53fcSKevin Cernekee if (alps_enter_command_mode(psmouse) || 18501302bac3SKevin Cernekee alps_command_mode_read_reg(psmouse, 0xc2d9) == -1 || 18511302bac3SKevin Cernekee alps_command_mode_write_reg(psmouse, 0xc2cb, 0x00)) 18521302bac3SKevin Cernekee goto error; 18531302bac3SKevin Cernekee 1854f3f33c67SHans de Goede if (alps_get_v3_v7_resolution(psmouse, 0xc2da)) 1855f3f33c67SHans de Goede goto error; 1856f3f33c67SHans de Goede 18571302bac3SKevin Cernekee reg_val = alps_command_mode_read_reg(psmouse, 0xc2c6); 18581302bac3SKevin Cernekee if (reg_val == -1) 18591302bac3SKevin Cernekee goto error; 18601302bac3SKevin Cernekee if (__alps_command_mode_write_reg(psmouse, reg_val & 0xfd)) 18611302bac3SKevin Cernekee goto error; 18621302bac3SKevin Cernekee 18631302bac3SKevin Cernekee if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64)) 18641302bac3SKevin Cernekee goto error; 18651302bac3SKevin Cernekee 18661302bac3SKevin Cernekee /* enter absolute mode */ 18671302bac3SKevin Cernekee reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4); 18681302bac3SKevin Cernekee if (reg_val == -1) 18691302bac3SKevin Cernekee goto error; 18701302bac3SKevin Cernekee if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02)) 18711302bac3SKevin Cernekee goto error; 18721302bac3SKevin Cernekee 18731302bac3SKevin Cernekee alps_exit_command_mode(psmouse); 18741302bac3SKevin Cernekee return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE); 18751302bac3SKevin Cernekee 18761302bac3SKevin Cernekee error: 18771302bac3SKevin Cernekee alps_exit_command_mode(psmouse); 18781302bac3SKevin Cernekee return ret; 18791302bac3SKevin Cernekee } 18801302bac3SKevin Cernekee 188125bded7cSSeth Forshee /* Must be in command mode when calling this function */ 188225bded7cSSeth Forshee static int alps_absolute_mode_v4(struct psmouse *psmouse) 188325bded7cSSeth Forshee { 188425bded7cSSeth Forshee int reg_val; 188525bded7cSSeth Forshee 188625bded7cSSeth Forshee reg_val = alps_command_mode_read_reg(psmouse, 0x0004); 188725bded7cSSeth Forshee if (reg_val == -1) 188825bded7cSSeth Forshee return -1; 188925bded7cSSeth Forshee 189025bded7cSSeth Forshee reg_val |= 0x02; 189125bded7cSSeth Forshee if (__alps_command_mode_write_reg(psmouse, reg_val)) 189225bded7cSSeth Forshee return -1; 189325bded7cSSeth Forshee 189425bded7cSSeth Forshee return 0; 189525bded7cSSeth Forshee } 189625bded7cSSeth Forshee 189725bded7cSSeth Forshee static int alps_hw_init_v4(struct psmouse *psmouse) 189825bded7cSSeth Forshee { 189925bded7cSSeth Forshee struct ps2dev *ps2dev = &psmouse->ps2dev; 190025bded7cSSeth Forshee unsigned char param[4]; 190125bded7cSSeth Forshee 1902d18e53fcSKevin Cernekee if (alps_enter_command_mode(psmouse)) 190325bded7cSSeth Forshee goto error; 190425bded7cSSeth Forshee 190525bded7cSSeth Forshee if (alps_absolute_mode_v4(psmouse)) { 190625bded7cSSeth Forshee psmouse_err(psmouse, "Failed to enter absolute mode\n"); 190725bded7cSSeth Forshee goto error; 190825bded7cSSeth Forshee } 190925bded7cSSeth Forshee 191025bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c)) 191125bded7cSSeth Forshee goto error; 191225bded7cSSeth Forshee 191325bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03)) 191425bded7cSSeth Forshee goto error; 191525bded7cSSeth Forshee 191625bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03)) 191725bded7cSSeth Forshee goto error; 191825bded7cSSeth Forshee 191925bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15)) 192025bded7cSSeth Forshee goto error; 192125bded7cSSeth Forshee 192225bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01)) 192325bded7cSSeth Forshee goto error; 192425bded7cSSeth Forshee 192525bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03)) 192625bded7cSSeth Forshee goto error; 192725bded7cSSeth Forshee 192825bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03)) 192925bded7cSSeth Forshee goto error; 193025bded7cSSeth Forshee 193125bded7cSSeth Forshee if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03)) 193225bded7cSSeth Forshee goto error; 193325bded7cSSeth Forshee 193425bded7cSSeth Forshee alps_exit_command_mode(psmouse); 193525bded7cSSeth Forshee 193625bded7cSSeth Forshee /* 193725bded7cSSeth Forshee * This sequence changes the output from a 9-byte to an 193825bded7cSSeth Forshee * 8-byte format. All the same data seems to be present, 193925bded7cSSeth Forshee * just in a more compact format. 194025bded7cSSeth Forshee */ 194125bded7cSSeth Forshee param[0] = 0xc8; 194225bded7cSSeth Forshee param[1] = 0x64; 194325bded7cSSeth Forshee param[2] = 0x50; 194425bded7cSSeth Forshee if (ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || 194525bded7cSSeth Forshee ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE) || 194625bded7cSSeth Forshee ps2_command(ps2dev, ¶m[2], PSMOUSE_CMD_SETRATE) || 194725bded7cSSeth Forshee ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) 194825bded7cSSeth Forshee return -1; 194925bded7cSSeth Forshee 195025bded7cSSeth Forshee /* Set rate and enable data reporting */ 195125bded7cSSeth Forshee param[0] = 0x64; 195225bded7cSSeth Forshee if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || 195325bded7cSSeth Forshee ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { 195425bded7cSSeth Forshee psmouse_err(psmouse, "Failed to enable data reporting\n"); 195525bded7cSSeth Forshee return -1; 195625bded7cSSeth Forshee } 195725bded7cSSeth Forshee 195825bded7cSSeth Forshee return 0; 195925bded7cSSeth Forshee 196025bded7cSSeth Forshee error: 196125bded7cSSeth Forshee /* 196225bded7cSSeth Forshee * Leaving the touchpad in command mode will essentially render 196325bded7cSSeth Forshee * it unusable until the machine reboots, so exit it here just 196425bded7cSSeth Forshee * to be safe 196525bded7cSSeth Forshee */ 196625bded7cSSeth Forshee alps_exit_command_mode(psmouse); 196725bded7cSSeth Forshee return -1; 196825bded7cSSeth Forshee } 196925bded7cSSeth Forshee 1970ee65d4b3SYunkang Tang static int alps_dolphin_get_device_area(struct psmouse *psmouse, 1971ee65d4b3SYunkang Tang struct alps_data *priv) 1972ee65d4b3SYunkang Tang { 1973ee65d4b3SYunkang Tang struct ps2dev *ps2dev = &psmouse->ps2dev; 1974ee65d4b3SYunkang Tang unsigned char param[4] = {0}; 1975ee65d4b3SYunkang Tang int num_x_electrode, num_y_electrode; 1976ee65d4b3SYunkang Tang 1977ee65d4b3SYunkang Tang if (alps_enter_command_mode(psmouse)) 1978ee65d4b3SYunkang Tang return -1; 1979ee65d4b3SYunkang Tang 1980ee65d4b3SYunkang Tang param[0] = 0x0a; 1981ee65d4b3SYunkang Tang if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || 1982ee65d4b3SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) || 1983ee65d4b3SYunkang Tang ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) || 1984ee65d4b3SYunkang Tang ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || 1985ee65d4b3SYunkang Tang ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE)) 1986ee65d4b3SYunkang Tang return -1; 1987ee65d4b3SYunkang Tang 1988ee65d4b3SYunkang Tang if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) 1989ee65d4b3SYunkang Tang return -1; 1990ee65d4b3SYunkang Tang 1991ee65d4b3SYunkang Tang /* 1992ee65d4b3SYunkang Tang * Dolphin's sensor line number is not fixed. It can be calculated 1993ee65d4b3SYunkang Tang * by adding the device's register value with DOLPHIN_PROFILE_X/YOFFSET. 1994ee65d4b3SYunkang Tang * Further more, we can get device's x_max and y_max by multiplying 1995ee65d4b3SYunkang Tang * sensor line number with DOLPHIN_COUNT_PER_ELECTRODE. 1996ee65d4b3SYunkang Tang * 1997ee65d4b3SYunkang Tang * e.g. When we get register's sensor_x = 11 & sensor_y = 8, 1998ee65d4b3SYunkang Tang * real sensor line number X = 11 + 8 = 19, and 1999ee65d4b3SYunkang Tang * real sensor line number Y = 8 + 1 = 9. 2000ee65d4b3SYunkang Tang * So, x_max = (19 - 1) * 64 = 1152, and 2001ee65d4b3SYunkang Tang * y_max = (9 - 1) * 64 = 512. 2002ee65d4b3SYunkang Tang */ 2003ee65d4b3SYunkang Tang num_x_electrode = DOLPHIN_PROFILE_XOFFSET + (param[2] & 0x0F); 2004ee65d4b3SYunkang Tang num_y_electrode = DOLPHIN_PROFILE_YOFFSET + ((param[2] >> 4) & 0x0F); 2005ee65d4b3SYunkang Tang priv->x_bits = num_x_electrode; 2006ee65d4b3SYunkang Tang priv->y_bits = num_y_electrode; 2007ee65d4b3SYunkang Tang priv->x_max = (num_x_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE; 2008ee65d4b3SYunkang Tang priv->y_max = (num_y_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE; 2009ee65d4b3SYunkang Tang 2010ee65d4b3SYunkang Tang if (alps_exit_command_mode(psmouse)) 2011ee65d4b3SYunkang Tang return -1; 2012ee65d4b3SYunkang Tang 2013ee65d4b3SYunkang Tang return 0; 2014ee65d4b3SYunkang Tang } 2015ee65d4b3SYunkang Tang 201675af9e56SDave Turvene static int alps_hw_init_dolphin_v1(struct psmouse *psmouse) 201775af9e56SDave Turvene { 201875af9e56SDave Turvene struct ps2dev *ps2dev = &psmouse->ps2dev; 201975af9e56SDave Turvene unsigned char param[2]; 202075af9e56SDave Turvene 202175af9e56SDave Turvene /* This is dolphin "v1" as empirically defined by florin9doi */ 202275af9e56SDave Turvene param[0] = 0x64; 202375af9e56SDave Turvene param[1] = 0x28; 202475af9e56SDave Turvene 202575af9e56SDave Turvene if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) || 202675af9e56SDave Turvene ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || 202775af9e56SDave Turvene ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE)) 202875af9e56SDave Turvene return -1; 202975af9e56SDave Turvene 203075af9e56SDave Turvene return 0; 203175af9e56SDave Turvene } 203275af9e56SDave Turvene 20333808843cSYunkang Tang static int alps_hw_init_v7(struct psmouse *psmouse) 20343808843cSYunkang Tang { 20353808843cSYunkang Tang struct ps2dev *ps2dev = &psmouse->ps2dev; 20363808843cSYunkang Tang int reg_val, ret = -1; 20373808843cSYunkang Tang 20383808843cSYunkang Tang if (alps_enter_command_mode(psmouse) || 20393808843cSYunkang Tang alps_command_mode_read_reg(psmouse, 0xc2d9) == -1) 20403808843cSYunkang Tang goto error; 20413808843cSYunkang Tang 2042f3f33c67SHans de Goede if (alps_get_v3_v7_resolution(psmouse, 0xc397)) 2043f3f33c67SHans de Goede goto error; 2044f3f33c67SHans de Goede 20453808843cSYunkang Tang if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64)) 20463808843cSYunkang Tang goto error; 20473808843cSYunkang Tang 20483808843cSYunkang Tang reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4); 20493808843cSYunkang Tang if (reg_val == -1) 20503808843cSYunkang Tang goto error; 20513808843cSYunkang Tang if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02)) 20523808843cSYunkang Tang goto error; 20533808843cSYunkang Tang 20543808843cSYunkang Tang alps_exit_command_mode(psmouse); 20553808843cSYunkang Tang return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE); 20563808843cSYunkang Tang 20573808843cSYunkang Tang error: 20583808843cSYunkang Tang alps_exit_command_mode(psmouse); 20593808843cSYunkang Tang return ret; 20603808843cSYunkang Tang } 20613808843cSYunkang Tang 206224af5cb9SKevin Cernekee static void alps_set_defaults(struct alps_data *priv) 206325bded7cSSeth Forshee { 2064f673ceb1SKevin Cernekee priv->byte0 = 0x8f; 2065f673ceb1SKevin Cernekee priv->mask0 = 0x8f; 2066f673ceb1SKevin Cernekee priv->flags = ALPS_DUALPOINT; 2067f673ceb1SKevin Cernekee 20687a9f73e7SKevin Cernekee priv->x_max = 2000; 20697a9f73e7SKevin Cernekee priv->y_max = 1400; 20707a9f73e7SKevin Cernekee priv->x_bits = 15; 20717a9f73e7SKevin Cernekee priv->y_bits = 11; 20727a9f73e7SKevin Cernekee 207399df65e7SKevin Cernekee switch (priv->proto_version) { 207425bded7cSSeth Forshee case ALPS_PROTO_V1: 207525bded7cSSeth Forshee case ALPS_PROTO_V2: 207624af5cb9SKevin Cernekee priv->hw_init = alps_hw_init_v1_v2; 207724af5cb9SKevin Cernekee priv->process_packet = alps_process_packet_v1_v2; 207824af5cb9SKevin Cernekee priv->set_abs_params = alps_set_abs_params_st; 207995f75e91SYunkang Tang priv->x_max = 1023; 208095f75e91SYunkang Tang priv->y_max = 767; 208125bded7cSSeth Forshee break; 208225bded7cSSeth Forshee case ALPS_PROTO_V3: 208324af5cb9SKevin Cernekee priv->hw_init = alps_hw_init_v3; 208424af5cb9SKevin Cernekee priv->process_packet = alps_process_packet_v3; 208524af5cb9SKevin Cernekee priv->set_abs_params = alps_set_abs_params_mt; 2086f85e5001SKevin Cernekee priv->decode_fields = alps_decode_pinnacle; 208750e8b216SKevin Cernekee priv->nibble_commands = alps_v3_nibble_commands; 208850e8b216SKevin Cernekee priv->addr_command = PSMOUSE_CMD_RESET_WRAP; 208925bded7cSSeth Forshee break; 209025bded7cSSeth Forshee case ALPS_PROTO_V4: 209124af5cb9SKevin Cernekee priv->hw_init = alps_hw_init_v4; 209224af5cb9SKevin Cernekee priv->process_packet = alps_process_packet_v4; 209324af5cb9SKevin Cernekee priv->set_abs_params = alps_set_abs_params_mt; 209450e8b216SKevin Cernekee priv->nibble_commands = alps_v4_nibble_commands; 209550e8b216SKevin Cernekee priv->addr_command = PSMOUSE_CMD_DISABLE; 209625bded7cSSeth Forshee break; 209775af9e56SDave Turvene case ALPS_PROTO_V5: 209875af9e56SDave Turvene priv->hw_init = alps_hw_init_dolphin_v1; 2099ee65d4b3SYunkang Tang priv->process_packet = alps_process_touchpad_packet_v3_v5; 210075af9e56SDave Turvene priv->decode_fields = alps_decode_dolphin; 210175af9e56SDave Turvene priv->set_abs_params = alps_set_abs_params_mt; 210275af9e56SDave Turvene priv->nibble_commands = alps_v3_nibble_commands; 210375af9e56SDave Turvene priv->addr_command = PSMOUSE_CMD_RESET_WRAP; 210475af9e56SDave Turvene priv->byte0 = 0xc8; 2105ee65d4b3SYunkang Tang priv->mask0 = 0xd8; 210675af9e56SDave Turvene priv->flags = 0; 210775af9e56SDave Turvene priv->x_max = 1360; 210875af9e56SDave Turvene priv->y_max = 660; 210975af9e56SDave Turvene priv->x_bits = 23; 211075af9e56SDave Turvene priv->y_bits = 12; 211175af9e56SDave Turvene break; 211295f75e91SYunkang Tang case ALPS_PROTO_V6: 211395f75e91SYunkang Tang priv->hw_init = alps_hw_init_v6; 211495f75e91SYunkang Tang priv->process_packet = alps_process_packet_v6; 211595f75e91SYunkang Tang priv->set_abs_params = alps_set_abs_params_st; 211695f75e91SYunkang Tang priv->nibble_commands = alps_v6_nibble_commands; 211795f75e91SYunkang Tang priv->x_max = 2047; 211895f75e91SYunkang Tang priv->y_max = 1535; 211995f75e91SYunkang Tang break; 21203808843cSYunkang Tang case ALPS_PROTO_V7: 21213808843cSYunkang Tang priv->hw_init = alps_hw_init_v7; 21223808843cSYunkang Tang priv->process_packet = alps_process_packet_v7; 21233808843cSYunkang Tang priv->decode_fields = alps_decode_packet_v7; 21243808843cSYunkang Tang priv->set_abs_params = alps_set_abs_params_mt; 21253808843cSYunkang Tang priv->nibble_commands = alps_v3_nibble_commands; 21263808843cSYunkang Tang priv->addr_command = PSMOUSE_CMD_RESET_WRAP; 21273808843cSYunkang Tang priv->x_max = 0xfff; 21283808843cSYunkang Tang priv->y_max = 0x7ff; 21293808843cSYunkang Tang priv->byte0 = 0x48; 21303808843cSYunkang Tang priv->mask0 = 0x48; 21313808843cSYunkang Tang 21323808843cSYunkang Tang if (priv->fw_ver[1] != 0xba) 21333808843cSYunkang Tang priv->flags |= ALPS_BUTTONPAD; 21343808843cSYunkang Tang break; 213525bded7cSSeth Forshee } 213625bded7cSSeth Forshee } 213725bded7cSSeth Forshee 2138b5d6b851SKevin Cernekee static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv, 2139b5d6b851SKevin Cernekee unsigned char *e7, unsigned char *ec) 21402e992cc0SKevin Cernekee { 2141b5d6b851SKevin Cernekee const struct alps_model_info *model; 21422e992cc0SKevin Cernekee int i; 21432e992cc0SKevin Cernekee 2144b5d6b851SKevin Cernekee for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) { 2145b5d6b851SKevin Cernekee model = &alps_model_data[i]; 2146b5d6b851SKevin Cernekee 2147b5d6b851SKevin Cernekee if (!memcmp(e7, model->signature, sizeof(model->signature)) && 2148b5d6b851SKevin Cernekee (!model->command_mode_resp || 2149b5d6b851SKevin Cernekee model->command_mode_resp == ec[2])) { 2150b5d6b851SKevin Cernekee 2151b5d6b851SKevin Cernekee priv->proto_version = model->proto_version; 215224af5cb9SKevin Cernekee alps_set_defaults(priv); 215324af5cb9SKevin Cernekee 2154b5d6b851SKevin Cernekee priv->flags = model->flags; 2155b5d6b851SKevin Cernekee priv->byte0 = model->byte0; 2156b5d6b851SKevin Cernekee priv->mask0 = model->mask0; 2157b5d6b851SKevin Cernekee 2158b5d6b851SKevin Cernekee return 0; 2159b5d6b851SKevin Cernekee } 2160b5d6b851SKevin Cernekee } 2161b5d6b851SKevin Cernekee 2162b5d6b851SKevin Cernekee return -EINVAL; 2163b5d6b851SKevin Cernekee } 2164b5d6b851SKevin Cernekee 2165b5d6b851SKevin Cernekee static int alps_identify(struct psmouse *psmouse, struct alps_data *priv) 2166b5d6b851SKevin Cernekee { 2167b5d6b851SKevin Cernekee unsigned char e6[4], e7[4], ec[4]; 2168b5d6b851SKevin Cernekee 21692e992cc0SKevin Cernekee /* 21702e992cc0SKevin Cernekee * First try "E6 report". 21712e992cc0SKevin Cernekee * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed. 21722e992cc0SKevin Cernekee * The bits 0-2 of the first byte will be 1s if some buttons are 21732e992cc0SKevin Cernekee * pressed. 21742e992cc0SKevin Cernekee */ 2175b5d6b851SKevin Cernekee if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, 2176b5d6b851SKevin Cernekee PSMOUSE_CMD_SETSCALE11, e6)) 2177b5d6b851SKevin Cernekee return -EIO; 21782e992cc0SKevin Cernekee 2179b5d6b851SKevin Cernekee if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100)) 2180b5d6b851SKevin Cernekee return -EINVAL; 21812e992cc0SKevin Cernekee 21822e992cc0SKevin Cernekee /* 2183b5d6b851SKevin Cernekee * Now get the "E7" and "EC" reports. These will uniquely identify 2184b5d6b851SKevin Cernekee * most ALPS touchpads. 21852e992cc0SKevin Cernekee */ 2186b5d6b851SKevin Cernekee if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, 2187b5d6b851SKevin Cernekee PSMOUSE_CMD_SETSCALE21, e7) || 2188b5d6b851SKevin Cernekee alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, 2189b5d6b851SKevin Cernekee PSMOUSE_CMD_RESET_WRAP, ec) || 2190b5d6b851SKevin Cernekee alps_exit_command_mode(psmouse)) 2191b5d6b851SKevin Cernekee return -EIO; 21922e992cc0SKevin Cernekee 2193c0cd17f6SHans de Goede /* Save the Firmware version */ 2194c0cd17f6SHans de Goede memcpy(priv->fw_ver, ec, 3); 2195c0cd17f6SHans de Goede 2196f673ceb1SKevin Cernekee if (alps_match_table(psmouse, priv, e7, ec) == 0) { 2197b5d6b851SKevin Cernekee return 0; 219875af9e56SDave Turvene } else if (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 && 2199ee65d4b3SYunkang Tang ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)) { 220075af9e56SDave Turvene priv->proto_version = ALPS_PROTO_V5; 220175af9e56SDave Turvene alps_set_defaults(priv); 2202ee65d4b3SYunkang Tang if (alps_dolphin_get_device_area(psmouse, priv)) 2203ee65d4b3SYunkang Tang return -EIO; 2204ee65d4b3SYunkang Tang else 220575af9e56SDave Turvene return 0; 22063808843cSYunkang Tang } else if (ec[0] == 0x88 && 22073808843cSYunkang Tang ((ec[1] & 0xf0) == 0xb0 || (ec[1] & 0xf0) == 0xc0)) { 22083808843cSYunkang Tang priv->proto_version = ALPS_PROTO_V7; 22093808843cSYunkang Tang alps_set_defaults(priv); 22103808843cSYunkang Tang 22113808843cSYunkang Tang return 0; 22121302bac3SKevin Cernekee } else if (ec[0] == 0x88 && ec[1] == 0x08) { 22131302bac3SKevin Cernekee priv->proto_version = ALPS_PROTO_V3; 22141302bac3SKevin Cernekee alps_set_defaults(priv); 22151302bac3SKevin Cernekee 22161302bac3SKevin Cernekee priv->hw_init = alps_hw_init_rushmore_v3; 22171302bac3SKevin Cernekee priv->decode_fields = alps_decode_rushmore; 22181302bac3SKevin Cernekee priv->x_bits = 16; 22191302bac3SKevin Cernekee priv->y_bits = 12; 222040e8f53bSHans de Goede priv->flags |= ALPS_IS_RUSHMORE; 22211302bac3SKevin Cernekee 2222cd401204SKevin Cernekee /* hack to make addr_command, nibble_command available */ 2223cd401204SKevin Cernekee psmouse->private = priv; 2224cd401204SKevin Cernekee 2225cd401204SKevin Cernekee if (alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_RUSHMORE)) 2226cd401204SKevin Cernekee priv->flags &= ~ALPS_DUALPOINT; 2227cd401204SKevin Cernekee 22281302bac3SKevin Cernekee return 0; 2229f673ceb1SKevin Cernekee } else if (ec[0] == 0x88 && ec[1] == 0x07 && 2230f673ceb1SKevin Cernekee ec[2] >= 0x90 && ec[2] <= 0x9d) { 2231f673ceb1SKevin Cernekee priv->proto_version = ALPS_PROTO_V3; 2232f673ceb1SKevin Cernekee alps_set_defaults(priv); 2233f673ceb1SKevin Cernekee 2234f673ceb1SKevin Cernekee return 0; 2235f673ceb1SKevin Cernekee } 22362e992cc0SKevin Cernekee 2237a9e06219SDmitry Torokhov psmouse_dbg(psmouse, 2238a9e06219SDmitry Torokhov "Likely not an ALPS touchpad: E7=%3ph, EC=%3ph\n", e7, ec); 22392e992cc0SKevin Cernekee 2240b5d6b851SKevin Cernekee return -EINVAL; 22412e992cc0SKevin Cernekee } 22422e992cc0SKevin Cernekee 22431e0c5b12SDmitry Torokhov static int alps_reconnect(struct psmouse *psmouse) 22441e0c5b12SDmitry Torokhov { 2245b5d6b851SKevin Cernekee struct alps_data *priv = psmouse->private; 224671bb21b6SMaxim Levitsky 22471e0c5b12SDmitry Torokhov psmouse_reset(psmouse); 22481e0c5b12SDmitry Torokhov 2249b5d6b851SKevin Cernekee if (alps_identify(psmouse, priv) < 0) 22501e0c5b12SDmitry Torokhov return -1; 22511e0c5b12SDmitry Torokhov 225224af5cb9SKevin Cernekee return priv->hw_init(psmouse); 22531da177e4SLinus Torvalds } 22541da177e4SLinus Torvalds 22551da177e4SLinus Torvalds static void alps_disconnect(struct psmouse *psmouse) 22561da177e4SLinus Torvalds { 22571da177e4SLinus Torvalds struct alps_data *priv = psmouse->private; 22582e5b636bSDmitry Torokhov 22591da177e4SLinus Torvalds psmouse_reset(psmouse); 22601d9f2626SSebastian Kapfer del_timer_sync(&priv->timer); 22612e5b636bSDmitry Torokhov input_unregister_device(priv->dev2); 22621da177e4SLinus Torvalds kfree(priv); 22631da177e4SLinus Torvalds } 22641da177e4SLinus Torvalds 226524af5cb9SKevin Cernekee static void alps_set_abs_params_st(struct alps_data *priv, 226624af5cb9SKevin Cernekee struct input_dev *dev1) 226724af5cb9SKevin Cernekee { 226895f75e91SYunkang Tang input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0); 226995f75e91SYunkang Tang input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0); 227024af5cb9SKevin Cernekee } 227124af5cb9SKevin Cernekee 227224af5cb9SKevin Cernekee static void alps_set_abs_params_mt(struct alps_data *priv, 227324af5cb9SKevin Cernekee struct input_dev *dev1) 227424af5cb9SKevin Cernekee { 22757a9f73e7SKevin Cernekee input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0); 22767a9f73e7SKevin Cernekee input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0); 227724af5cb9SKevin Cernekee 2278f3f33c67SHans de Goede input_abs_set_res(dev1, ABS_MT_POSITION_X, priv->x_res); 2279f3f33c67SHans de Goede input_abs_set_res(dev1, ABS_MT_POSITION_Y, priv->y_res); 2280f3f33c67SHans de Goede 2281cdf333efSHans de Goede input_mt_init_slots(dev1, MAX_TOUCHES, INPUT_MT_POINTER | 2282cdf333efSHans de Goede INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK | INPUT_MT_SEMI_MT); 2283cdf333efSHans de Goede 228424af5cb9SKevin Cernekee set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit); 228524af5cb9SKevin Cernekee set_bit(BTN_TOOL_QUADTAP, dev1->keybit); 22863808843cSYunkang Tang 22873808843cSYunkang Tang /* V7 is real multi-touch */ 22883808843cSYunkang Tang if (priv->proto_version == ALPS_PROTO_V7) 22893808843cSYunkang Tang clear_bit(INPUT_PROP_SEMI_MT, dev1->propbit); 229024af5cb9SKevin Cernekee } 229124af5cb9SKevin Cernekee 22921da177e4SLinus Torvalds int alps_init(struct psmouse *psmouse) 22931da177e4SLinus Torvalds { 22941da177e4SLinus Torvalds struct alps_data *priv; 22952e5b636bSDmitry Torokhov struct input_dev *dev1 = psmouse->dev, *dev2; 22961da177e4SLinus Torvalds 2297f42649e8SDmitry Torokhov priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL); 22982e5b636bSDmitry Torokhov dev2 = input_allocate_device(); 22992e5b636bSDmitry Torokhov if (!priv || !dev2) 23001da177e4SLinus Torvalds goto init_fail; 23012e5b636bSDmitry Torokhov 23022e5b636bSDmitry Torokhov priv->dev2 = dev2; 23031d9f2626SSebastian Kapfer setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse); 23041d9f2626SSebastian Kapfer 23051e0c5b12SDmitry Torokhov psmouse->private = priv; 23061da177e4SLinus Torvalds 230725bded7cSSeth Forshee psmouse_reset(psmouse); 230825bded7cSSeth Forshee 2309b5d6b851SKevin Cernekee if (alps_identify(psmouse, priv) < 0) 231071bb21b6SMaxim Levitsky goto init_fail; 231171bb21b6SMaxim Levitsky 231224af5cb9SKevin Cernekee if (priv->hw_init(psmouse)) 23131da177e4SLinus Torvalds goto init_fail; 23141da177e4SLinus Torvalds 23157105d2eaSDmitry Torokhov /* 23167105d2eaSDmitry Torokhov * Undo part of setup done for us by psmouse core since touchpad 23177105d2eaSDmitry Torokhov * is not a relative device. 23187105d2eaSDmitry Torokhov */ 23197105d2eaSDmitry Torokhov __clear_bit(EV_REL, dev1->evbit); 23207105d2eaSDmitry Torokhov __clear_bit(REL_X, dev1->relbit); 23217105d2eaSDmitry Torokhov __clear_bit(REL_Y, dev1->relbit); 23227105d2eaSDmitry Torokhov 23237105d2eaSDmitry Torokhov /* 23247105d2eaSDmitry Torokhov * Now set up our capabilities. 23257105d2eaSDmitry Torokhov */ 23267b19ada2SJiri Slaby dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY); 23277b19ada2SJiri Slaby dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH); 23287b19ada2SJiri Slaby dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER); 232971bb21b6SMaxim Levitsky dev1->keybit[BIT_WORD(BTN_LEFT)] |= 233071bb21b6SMaxim Levitsky BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); 23311da177e4SLinus Torvalds 23327b19ada2SJiri Slaby dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); 233325bded7cSSeth Forshee 233424af5cb9SKevin Cernekee priv->set_abs_params(priv, dev1); 23353808843cSYunkang Tang /* No pressure on V7 */ 23363808843cSYunkang Tang if (priv->proto_version != ALPS_PROTO_V7) 23372e5b636bSDmitry Torokhov input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); 23381da177e4SLinus Torvalds 233999df65e7SKevin Cernekee if (priv->flags & ALPS_WHEEL) { 23407b19ada2SJiri Slaby dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL); 23417b19ada2SJiri Slaby dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL); 23421da177e4SLinus Torvalds } 23431da177e4SLinus Torvalds 234499df65e7SKevin Cernekee if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { 23457b19ada2SJiri Slaby dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD); 23467b19ada2SJiri Slaby dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK); 23471da177e4SLinus Torvalds } 23481da177e4SLinus Torvalds 234999df65e7SKevin Cernekee if (priv->flags & ALPS_FOUR_BUTTONS) { 235071bb21b6SMaxim Levitsky dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0); 235171bb21b6SMaxim Levitsky dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1); 235271bb21b6SMaxim Levitsky dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2); 235371bb21b6SMaxim Levitsky dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3); 23543808843cSYunkang Tang } else if (priv->flags & ALPS_BUTTONPAD) { 23553808843cSYunkang Tang set_bit(INPUT_PROP_BUTTONPAD, dev1->propbit); 23563808843cSYunkang Tang clear_bit(BTN_RIGHT, dev1->keybit); 235771bb21b6SMaxim Levitsky } else { 235871bb21b6SMaxim Levitsky dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE); 235971bb21b6SMaxim Levitsky } 236071bb21b6SMaxim Levitsky 236108ffce45SDmitry Torokhov snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys); 23622e5b636bSDmitry Torokhov dev2->phys = priv->phys; 236399df65e7SKevin Cernekee dev2->name = (priv->flags & ALPS_DUALPOINT) ? 23649354f263SYunkang Tang "DualPoint Stick" : "ALPS PS/2 Device"; 23652e5b636bSDmitry Torokhov dev2->id.bustype = BUS_I8042; 23662e5b636bSDmitry Torokhov dev2->id.vendor = 0x0002; 23672e5b636bSDmitry Torokhov dev2->id.product = PSMOUSE_ALPS; 23682e5b636bSDmitry Torokhov dev2->id.version = 0x0000; 23691db3a345SDmitry Torokhov dev2->dev.parent = &psmouse->ps2dev.serio->dev; 23701da177e4SLinus Torvalds 23717b19ada2SJiri Slaby dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 237271bb21b6SMaxim Levitsky dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 237371bb21b6SMaxim Levitsky dev2->keybit[BIT_WORD(BTN_LEFT)] = 237471bb21b6SMaxim Levitsky BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); 23751da177e4SLinus Torvalds 237601d4cd5cSHans de Goede __set_bit(INPUT_PROP_POINTER, dev2->propbit); 23777611392fSHans de Goede if (priv->flags & ALPS_DUALPOINT) 23787611392fSHans de Goede __set_bit(INPUT_PROP_POINTING_STICK, dev2->propbit); 23797611392fSHans de Goede 2380f42649e8SDmitry Torokhov if (input_register_device(priv->dev2)) 2381f42649e8SDmitry Torokhov goto init_fail; 23821da177e4SLinus Torvalds 23831da177e4SLinus Torvalds psmouse->protocol_handler = alps_process_byte; 2384f0d5c6f4SDmitry Torokhov psmouse->poll = alps_poll; 23851da177e4SLinus Torvalds psmouse->disconnect = alps_disconnect; 23861da177e4SLinus Torvalds psmouse->reconnect = alps_reconnect; 238799df65e7SKevin Cernekee psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6; 23881da177e4SLinus Torvalds 2389f0d5c6f4SDmitry Torokhov /* We are having trouble resyncing ALPS touchpads so disable it for now */ 2390f0d5c6f4SDmitry Torokhov psmouse->resync_time = 0; 2391f0d5c6f4SDmitry Torokhov 23921da177e4SLinus Torvalds return 0; 23931da177e4SLinus Torvalds 23941da177e4SLinus Torvalds init_fail: 2395f42649e8SDmitry Torokhov psmouse_reset(psmouse); 23962e5b636bSDmitry Torokhov input_free_device(dev2); 23971da177e4SLinus Torvalds kfree(priv); 23981e0c5b12SDmitry Torokhov psmouse->private = NULL; 23991da177e4SLinus Torvalds return -1; 24001da177e4SLinus Torvalds } 24011da177e4SLinus Torvalds 2402b7802c5cSDmitry Torokhov int alps_detect(struct psmouse *psmouse, bool set_properties) 24031da177e4SLinus Torvalds { 2404b5d6b851SKevin Cernekee struct alps_data dummy; 24051da177e4SLinus Torvalds 2406b5d6b851SKevin Cernekee if (alps_identify(psmouse, &dummy) < 0) 24071da177e4SLinus Torvalds return -1; 24081da177e4SLinus Torvalds 24091da177e4SLinus Torvalds if (set_properties) { 24101da177e4SLinus Torvalds psmouse->vendor = "ALPS"; 2411b5d6b851SKevin Cernekee psmouse->name = dummy.flags & ALPS_DUALPOINT ? 2412968ac842SDmitry Torokhov "DualPoint TouchPad" : "GlidePoint"; 2413b5d6b851SKevin Cernekee psmouse->model = dummy.proto_version << 8; 24141da177e4SLinus Torvalds } 24151da177e4SLinus Torvalds return 0; 24161da177e4SLinus Torvalds } 24171da177e4SLinus Torvalds 2418