aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Cernekee <cernekee@gmail.com>2013-02-13 23:56:33 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-02-14 12:17:43 -0500
commit99df65e705503a97a5fceb30317086a091b4052d (patch)
tree64cf9740392adaf35030b2d2fc1b536e1c41eac1
parent88a803482c4165642409bab77424a27939d51500 (diff)
Input: ALPS - copy "model" info into alps_data struct
Not every type of ALPS touchpad is well-suited to table-based detection. Start moving the various alps_model_data attributes into the alps_data struct so that we don't need a unique table entry for every possible permutation of protocol version, flags, byte0/mask0, etc. Signed-off-by: Kevin Cernekee <cernekee@gmail.com> Tested-by: Dave Turvene <dturvene@dahetral.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--drivers/input/mouse/alps.c63
-rw-r--r--drivers/input/mouse/alps.h14
2 files changed, 43 insertions, 34 deletions
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index e229fa3cad96..33ee6e0b9752 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -122,10 +122,10 @@ static const struct alps_model_info alps_model_data[] = {
122 122
123/* Packet formats are described in Documentation/input/alps.txt */ 123/* Packet formats are described in Documentation/input/alps.txt */
124 124
125static bool alps_is_valid_first_byte(const struct alps_model_info *model, 125static bool alps_is_valid_first_byte(struct alps_data *priv,
126 unsigned char data) 126 unsigned char data)
127{ 127{
128 return (data & model->mask0) == model->byte0; 128 return (data & priv->mask0) == priv->byte0;
129} 129}
130 130
131static void alps_report_buttons(struct psmouse *psmouse, 131static void alps_report_buttons(struct psmouse *psmouse,
@@ -158,14 +158,13 @@ static void alps_report_buttons(struct psmouse *psmouse,
158static void alps_process_packet_v1_v2(struct psmouse *psmouse) 158static void alps_process_packet_v1_v2(struct psmouse *psmouse)
159{ 159{
160 struct alps_data *priv = psmouse->private; 160 struct alps_data *priv = psmouse->private;
161 const struct alps_model_info *model = priv->i;
162 unsigned char *packet = psmouse->packet; 161 unsigned char *packet = psmouse->packet;
163 struct input_dev *dev = psmouse->dev; 162 struct input_dev *dev = psmouse->dev;
164 struct input_dev *dev2 = priv->dev2; 163 struct input_dev *dev2 = priv->dev2;
165 int x, y, z, ges, fin, left, right, middle; 164 int x, y, z, ges, fin, left, right, middle;
166 int back = 0, forward = 0; 165 int back = 0, forward = 0;
167 166
168 if (model->proto_version == ALPS_PROTO_V1) { 167 if (priv->proto_version == ALPS_PROTO_V1) {
169 left = packet[2] & 0x10; 168 left = packet[2] & 0x10;
170 right = packet[2] & 0x08; 169 right = packet[2] & 0x08;
171 middle = 0; 170 middle = 0;
@@ -181,12 +180,12 @@ static void alps_process_packet_v1_v2(struct psmouse *psmouse)
181 z = packet[5]; 180 z = packet[5];
182 } 181 }
183 182
184 if (model->flags & ALPS_FW_BK_1) { 183 if (priv->flags & ALPS_FW_BK_1) {
185 back = packet[0] & 0x10; 184 back = packet[0] & 0x10;
186 forward = packet[2] & 4; 185 forward = packet[2] & 4;
187 } 186 }
188 187
189 if (model->flags & ALPS_FW_BK_2) { 188 if (priv->flags & ALPS_FW_BK_2) {
190 back = packet[3] & 4; 189 back = packet[3] & 4;
191 forward = packet[2] & 4; 190 forward = packet[2] & 4;
192 if ((middle = forward && back)) 191 if ((middle = forward && back))
@@ -196,7 +195,7 @@ static void alps_process_packet_v1_v2(struct psmouse *psmouse)
196 ges = packet[2] & 1; 195 ges = packet[2] & 1;
197 fin = packet[2] & 2; 196 fin = packet[2] & 2;
198 197
199 if ((model->flags & ALPS_DUALPOINT) && z == 127) { 198 if ((priv->flags & ALPS_DUALPOINT) && z == 127) {
200 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x)); 199 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
201 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y)); 200 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
202 201
@@ -239,15 +238,15 @@ static void alps_process_packet_v1_v2(struct psmouse *psmouse)
239 input_report_abs(dev, ABS_PRESSURE, z); 238 input_report_abs(dev, ABS_PRESSURE, z);
240 input_report_key(dev, BTN_TOOL_FINGER, z > 0); 239 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
241 240
242 if (model->flags & ALPS_WHEEL) 241 if (priv->flags & ALPS_WHEEL)
243 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07)); 242 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
244 243
245 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { 244 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
246 input_report_key(dev, BTN_FORWARD, forward); 245 input_report_key(dev, BTN_FORWARD, forward);
247 input_report_key(dev, BTN_BACK, back); 246 input_report_key(dev, BTN_BACK, back);
248 } 247 }
249 248
250 if (model->flags & ALPS_FOUR_BUTTONS) { 249 if (priv->flags & ALPS_FOUR_BUTTONS) {
251 input_report_key(dev, BTN_0, packet[2] & 4); 250 input_report_key(dev, BTN_0, packet[2] & 4);
252 input_report_key(dev, BTN_1, packet[0] & 0x10); 251 input_report_key(dev, BTN_1, packet[0] & 0x10);
253 input_report_key(dev, BTN_2, packet[3] & 4); 252 input_report_key(dev, BTN_2, packet[3] & 4);
@@ -699,9 +698,8 @@ static void alps_process_packet_v4(struct psmouse *psmouse)
699static void alps_process_packet(struct psmouse *psmouse) 698static void alps_process_packet(struct psmouse *psmouse)
700{ 699{
701 struct alps_data *priv = psmouse->private; 700 struct alps_data *priv = psmouse->private;
702 const struct alps_model_info *model = priv->i;
703 701
704 switch (model->proto_version) { 702 switch (priv->proto_version) {
705 case ALPS_PROTO_V1: 703 case ALPS_PROTO_V1:
706 case ALPS_PROTO_V2: 704 case ALPS_PROTO_V2:
707 alps_process_packet_v1_v2(psmouse); 705 alps_process_packet_v1_v2(psmouse);
@@ -765,7 +763,7 @@ static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
765 if (((psmouse->packet[3] | 763 if (((psmouse->packet[3] |
766 psmouse->packet[4] | 764 psmouse->packet[4] |
767 psmouse->packet[5]) & 0x80) || 765 psmouse->packet[5]) & 0x80) ||
768 (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) { 766 (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) {
769 psmouse_dbg(psmouse, 767 psmouse_dbg(psmouse,
770 "refusing packet %4ph (suspected interleaved ps/2)\n", 768 "refusing packet %4ph (suspected interleaved ps/2)\n",
771 psmouse->packet + 3); 769 psmouse->packet + 3);
@@ -844,7 +842,6 @@ static void alps_flush_packet(unsigned long data)
844static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) 842static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
845{ 843{
846 struct alps_data *priv = psmouse->private; 844 struct alps_data *priv = psmouse->private;
847 const struct alps_model_info *model = priv->i;
848 845
849 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */ 846 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
850 if (psmouse->pktcnt == 3) { 847 if (psmouse->pktcnt == 3) {
@@ -857,15 +854,15 @@ static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
857 854
858 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */ 855 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
859 856
860 if ((model->flags & ALPS_PS2_INTERLEAVED) && 857 if ((priv->flags & ALPS_PS2_INTERLEAVED) &&
861 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) { 858 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
862 return alps_handle_interleaved_ps2(psmouse); 859 return alps_handle_interleaved_ps2(psmouse);
863 } 860 }
864 861
865 if (!alps_is_valid_first_byte(model, psmouse->packet[0])) { 862 if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) {
866 psmouse_dbg(psmouse, 863 psmouse_dbg(psmouse,
867 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n", 864 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
868 psmouse->packet[0], model->mask0, model->byte0); 865 psmouse->packet[0], priv->mask0, priv->byte0);
869 return PSMOUSE_BAD_DATA; 866 return PSMOUSE_BAD_DATA;
870 } 867 }
871 868
@@ -1190,16 +1187,16 @@ static int alps_poll(struct psmouse *psmouse)
1190 unsigned char buf[sizeof(psmouse->packet)]; 1187 unsigned char buf[sizeof(psmouse->packet)];
1191 bool poll_failed; 1188 bool poll_failed;
1192 1189
1193 if (priv->i->flags & ALPS_PASS) 1190 if (priv->flags & ALPS_PASS)
1194 alps_passthrough_mode_v2(psmouse, true); 1191 alps_passthrough_mode_v2(psmouse, true);
1195 1192
1196 poll_failed = ps2_command(&psmouse->ps2dev, buf, 1193 poll_failed = ps2_command(&psmouse->ps2dev, buf,
1197 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; 1194 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
1198 1195
1199 if (priv->i->flags & ALPS_PASS) 1196 if (priv->flags & ALPS_PASS)
1200 alps_passthrough_mode_v2(psmouse, false); 1197 alps_passthrough_mode_v2(psmouse, false);
1201 1198
1202 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0) 1199 if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
1203 return -1; 1200 return -1;
1204 1201
1205 if ((psmouse->badbyte & 0xc8) == 0x08) { 1202 if ((psmouse->badbyte & 0xc8) == 0x08) {
@@ -1217,9 +1214,8 @@ static int alps_poll(struct psmouse *psmouse)
1217static int alps_hw_init_v1_v2(struct psmouse *psmouse) 1214static int alps_hw_init_v1_v2(struct psmouse *psmouse)
1218{ 1215{
1219 struct alps_data *priv = psmouse->private; 1216 struct alps_data *priv = psmouse->private;
1220 const struct alps_model_info *model = priv->i;
1221 1217
1222 if ((model->flags & ALPS_PASS) && 1218 if ((priv->flags & ALPS_PASS) &&
1223 alps_passthrough_mode_v2(psmouse, true)) { 1219 alps_passthrough_mode_v2(psmouse, true)) {
1224 return -1; 1220 return -1;
1225 } 1221 }
@@ -1234,7 +1230,7 @@ static int alps_hw_init_v1_v2(struct psmouse *psmouse)
1234 return -1; 1230 return -1;
1235 } 1231 }
1236 1232
1237 if ((model->flags & ALPS_PASS) && 1233 if ((priv->flags & ALPS_PASS) &&
1238 alps_passthrough_mode_v2(psmouse, false)) { 1234 alps_passthrough_mode_v2(psmouse, false)) {
1239 return -1; 1235 return -1;
1240 } 1236 }
@@ -1520,10 +1516,9 @@ error:
1520static int alps_hw_init(struct psmouse *psmouse) 1516static int alps_hw_init(struct psmouse *psmouse)
1521{ 1517{
1522 struct alps_data *priv = psmouse->private; 1518 struct alps_data *priv = psmouse->private;
1523 const struct alps_model_info *model = priv->i;
1524 int ret = -1; 1519 int ret = -1;
1525 1520
1526 switch (model->proto_version) { 1521 switch (priv->proto_version) {
1527 case ALPS_PROTO_V1: 1522 case ALPS_PROTO_V1:
1528 case ALPS_PROTO_V2: 1523 case ALPS_PROTO_V2:
1529 ret = alps_hw_init_v1_v2(psmouse); 1524 ret = alps_hw_init_v1_v2(psmouse);
@@ -1585,7 +1580,10 @@ int alps_init(struct psmouse *psmouse)
1585 if (!model) 1580 if (!model)
1586 goto init_fail; 1581 goto init_fail;
1587 1582
1588 priv->i = model; 1583 priv->proto_version = model->proto_version;
1584 priv->byte0 = model->byte0;
1585 priv->mask0 = model->mask0;
1586 priv->flags = model->flags;
1589 1587
1590 if (alps_hw_init(psmouse)) 1588 if (alps_hw_init(psmouse))
1591 goto init_fail; 1589 goto init_fail;
@@ -1609,7 +1607,7 @@ int alps_init(struct psmouse *psmouse)
1609 1607
1610 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); 1608 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
1611 1609
1612 switch (model->proto_version) { 1610 switch (priv->proto_version) {
1613 case ALPS_PROTO_V1: 1611 case ALPS_PROTO_V1:
1614 case ALPS_PROTO_V2: 1612 case ALPS_PROTO_V2:
1615 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0); 1613 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
@@ -1633,17 +1631,17 @@ int alps_init(struct psmouse *psmouse)
1633 1631
1634 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); 1632 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
1635 1633
1636 if (model->flags & ALPS_WHEEL) { 1634 if (priv->flags & ALPS_WHEEL) {
1637 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL); 1635 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
1638 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL); 1636 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
1639 } 1637 }
1640 1638
1641 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { 1639 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
1642 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD); 1640 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
1643 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK); 1641 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
1644 } 1642 }
1645 1643
1646 if (model->flags & ALPS_FOUR_BUTTONS) { 1644 if (priv->flags & ALPS_FOUR_BUTTONS) {
1647 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0); 1645 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
1648 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1); 1646 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
1649 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2); 1647 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
@@ -1654,7 +1652,8 @@ int alps_init(struct psmouse *psmouse)
1654 1652
1655 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys); 1653 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
1656 dev2->phys = priv->phys; 1654 dev2->phys = priv->phys;
1657 dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse"; 1655 dev2->name = (priv->flags & ALPS_DUALPOINT) ?
1656 "DualPoint Stick" : "PS/2 Mouse";
1658 dev2->id.bustype = BUS_I8042; 1657 dev2->id.bustype = BUS_I8042;
1659 dev2->id.vendor = 0x0002; 1658 dev2->id.vendor = 0x0002;
1660 dev2->id.product = PSMOUSE_ALPS; 1659 dev2->id.product = PSMOUSE_ALPS;
@@ -1673,7 +1672,7 @@ int alps_init(struct psmouse *psmouse)
1673 psmouse->poll = alps_poll; 1672 psmouse->poll = alps_poll;
1674 psmouse->disconnect = alps_disconnect; 1673 psmouse->disconnect = alps_disconnect;
1675 psmouse->reconnect = alps_reconnect; 1674 psmouse->reconnect = alps_reconnect;
1676 psmouse->pktsize = model->proto_version == ALPS_PROTO_V4 ? 8 : 6; 1675 psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
1677 1676
1678 /* We are having trouble resyncing ALPS touchpads so disable it for now */ 1677 /* We are having trouble resyncing ALPS touchpads so disable it for now */
1679 psmouse->resync_time = 0; 1678 psmouse->resync_time = 0;
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index 67be4e5fa1cd..efd0eea9f001 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -63,10 +63,15 @@ struct alps_nibble_commands {
63 * struct alps_data - private data structure for the ALPS driver 63 * struct alps_data - private data structure for the ALPS driver
64 * @dev2: "Relative" device used to report trackstick or mouse activity. 64 * @dev2: "Relative" device used to report trackstick or mouse activity.
65 * @phys: Physical path for the relative device. 65 * @phys: Physical path for the relative device.
66 * @i: Information on the detected touchpad model.
67 * @nibble_commands: Command mapping used for touchpad register accesses. 66 * @nibble_commands: Command mapping used for touchpad register accesses.
68 * @addr_command: Command used to tell the touchpad that a register address 67 * @addr_command: Command used to tell the touchpad that a register address
69 * follows. 68 * follows.
69 * @proto_version: Indicates V1/V2/V3/...
70 * @byte0: Helps figure out whether a position report packet matches the
71 * known format for this model. The first byte of the report, ANDed with
72 * mask0, should match byte0.
73 * @mask0: The mask used to check the first byte of the report.
74 * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
70 * @prev_fin: Finger bit from previous packet. 75 * @prev_fin: Finger bit from previous packet.
71 * @multi_packet: Multi-packet data in progress. 76 * @multi_packet: Multi-packet data in progress.
72 * @multi_data: Saved multi-packet data. 77 * @multi_data: Saved multi-packet data.
@@ -81,9 +86,14 @@ struct alps_nibble_commands {
81struct alps_data { 86struct alps_data {
82 struct input_dev *dev2; 87 struct input_dev *dev2;
83 char phys[32]; 88 char phys[32];
84 const struct alps_model_info *i; 89
90 /* these are autodetected when the device is identified */
85 const struct alps_nibble_commands *nibble_commands; 91 const struct alps_nibble_commands *nibble_commands;
86 int addr_command; 92 int addr_command;
93 unsigned char proto_version;
94 unsigned char byte0, mask0;
95 unsigned char flags;
96
87 int prev_fin; 97 int prev_fin;
88 int multi_packet; 98 int multi_packet;
89 unsigned char multi_data[6]; 99 unsigned char multi_data[6];