26 #include <linux/module.h>
30 #include <linux/serio.h>
32 #include <linux/slab.h>
47 #define XMIN_NOMINAL 1472
48 #define XMAX_NOMINAL 5472
49 #define YMIN_NOMINAL 1408
50 #define YMAX_NOMINAL 4448
53 #define ABS_POS_BITS 13
67 #define X_MAX_POSITIVE 8176
68 #define Y_MAX_POSITIVE 8176
79 unsigned char param[1];
92 unsigned char param[4];
102 if (param[1] != 0x47)
105 if (set_properties) {
106 psmouse->
vendor =
"Synaptics";
107 psmouse->
name =
"TouchPad";
116 synaptics_mode_cmd(psmouse, 0);
119 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
130 static int synaptics_invert_y(
int y)
151 static int synaptics_model_id(
struct psmouse *psmouse)
158 priv->
model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
166 static int synaptics_board_id(
struct psmouse *psmouse)
169 unsigned char bid[3];
173 priv->
board_id = ((bid[0] & 0xfc) << 6) | bid[1];
180 static int synaptics_firmware_id(
struct psmouse *psmouse)
183 unsigned char fwid[3];
187 priv->
firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2];
195 static int synaptics_capability(
struct psmouse *psmouse)
198 unsigned char cap[3];
202 priv->
capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
222 "device claims to have extended capabilities, but I'm not able to read them.\n");
224 priv->
ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
238 "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
240 priv->
ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
251 static int synaptics_identify(
struct psmouse *psmouse)
258 priv->
identity = (
id[0]<<16) | (
id[1]<<8) |
id[2];
268 static int synaptics_resolution(
struct psmouse *psmouse)
271 unsigned char resp[3];
277 if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
278 priv->
x_res = resp[0];
279 priv->
y_res = resp[2];
287 "device claims to have max coordinates query, but I'm not able to read it.\n");
289 priv->
x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
290 priv->
y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
298 "device claims to have min coordinates query, but I'm not able to read it.\n");
300 priv->
x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
301 priv->
y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
308 static int synaptics_query_hardware(
struct psmouse *psmouse)
310 if (synaptics_identify(psmouse))
312 if (synaptics_model_id(psmouse))
314 if (synaptics_firmware_id(psmouse))
316 if (synaptics_board_id(psmouse))
318 if (synaptics_capability(psmouse))
320 if (synaptics_resolution(psmouse))
326 static int synaptics_set_advanced_gesture_mode(
struct psmouse *psmouse)
328 static unsigned char param = 0xc8;
347 static int synaptics_set_mode(
struct psmouse *psmouse)
356 if (psmouse->
rate >= 80)
361 if (synaptics_mode_cmd(psmouse, priv->
mode))
365 synaptics_set_advanced_gesture_mode(psmouse)) {
366 psmouse_err(psmouse,
"Advanced gesture mode init failed.\n");
373 static void synaptics_set_rate(
struct psmouse *psmouse,
unsigned int rate)
385 synaptics_mode_cmd(psmouse, priv->
mode);
391 static int synaptics_pt_write(
struct serio *
serio,
unsigned char c)
393 struct psmouse *
parent = serio_get_drvdata(serio->
parent);
403 static int synaptics_pt_start(
struct serio *serio)
405 struct psmouse *parent = serio_get_drvdata(serio->
parent);
408 serio_pause_rx(parent->
ps2dev.serio);
410 serio_continue_rx(parent->
ps2dev.serio);
415 static void synaptics_pt_stop(
struct serio *serio)
417 struct psmouse *parent = serio_get_drvdata(serio->
parent);
420 serio_pause_rx(parent->
ps2dev.serio);
422 serio_continue_rx(parent->
ps2dev.serio);
425 static int synaptics_is_pt_packet(
unsigned char *
buf)
427 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
430 static void synaptics_pass_pt_packet(
struct serio *ptport,
unsigned char *
packet)
432 struct psmouse *
child = serio_get_drvdata(ptport);
444 static void synaptics_pt_activate(
struct psmouse *psmouse)
447 struct psmouse *child = serio_get_drvdata(priv->
pt_port);
456 if (synaptics_mode_cmd(psmouse, priv->
mode))
458 "failed to switch guest protocol\n");
462 static void synaptics_pt_create(
struct psmouse *psmouse)
466 serio = kzalloc(
sizeof(
struct serio),
GFP_KERNEL);
469 "not enough memory for pass-through port\n");
476 serio->
write = synaptics_pt_write;
477 serio->
start = synaptics_pt_start;
478 serio->
stop = synaptics_pt_stop;
500 static void synaptics_parse_agm(
const unsigned char buf[],
507 agm_packet_type = (buf[5] & 0x30) >> 4;
508 switch (agm_packet_type) {
512 agm->
x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
513 agm->
y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
514 agm->
z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
519 synaptics_mt_state_set(&agm->
mt_state, buf[1], buf[2], buf[4]);
530 static int synaptics_parse_hw_state(
const unsigned char buf[],
537 hw->
w = (((buf[0] & 0x30) >> 2) |
538 ((buf[0] & 0x04) >> 1) |
539 ((buf[3] & 0x04) >> 2));
541 hw->
left = (buf[0] & 0x01) ? 1 : 0;
542 hw->
right = (buf[0] & 0x02) ? 1 : 0;
550 hw->
left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
553 hw->
middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
559 hw->
up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
560 hw->
down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
566 synaptics_parse_agm(buf, priv, hw);
570 hw->
x = (((buf[3] & 0x10) << 8) |
571 ((buf[1] & 0x0f) << 8) |
573 hw->
y = (((buf[3] & 0x20) << 7) |
574 ((buf[1] & 0xf0) << 4) |
579 ((buf[0] ^ buf[3]) & 0x02)) {
602 hw->
x = (((buf[1] & 0x1f) << 8) | buf[2]);
603 hw->
y = (((buf[4] & 0x1f) << 8) | buf[5]);
605 hw->
z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
606 hw->
w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
608 hw->
left = (buf[0] & 0x01) ? 1 : 0;
609 hw->
right = (buf[0] & 0x02) ? 1 : 0;
631 static void synaptics_report_semi_mt_slot(
struct input_dev *
dev,
int slot,
642 static void synaptics_report_semi_mt_data(
struct input_dev *dev,
647 if (num_fingers >= 2) {
648 synaptics_report_semi_mt_slot(dev, 0,
true,
min(a->
x, b->
x),
650 synaptics_report_semi_mt_slot(dev, 1,
true,
max(a->
x, b->
x),
652 }
else if (num_fingers == 1) {
653 synaptics_report_semi_mt_slot(dev, 0,
true, a->
x, a->
y);
654 synaptics_report_semi_mt_slot(dev, 1,
false, 0, 0);
656 synaptics_report_semi_mt_slot(dev, 0,
false, 0, 0);
657 synaptics_report_semi_mt_slot(dev, 1,
false, 0, 0);
661 static void synaptics_report_buttons(
struct psmouse *psmouse,
664 struct input_dev *dev = psmouse->
dev;
683 static void synaptics_report_slot(
struct input_dev *dev,
int slot,
696 static void synaptics_report_mt_data(
struct psmouse *psmouse,
700 struct input_dev *dev = psmouse->
dev;
705 switch (mt_state->
count) {
707 synaptics_report_slot(dev, 0,
NULL);
708 synaptics_report_slot(dev, 1,
NULL);
711 if (mt_state->
sgm == -1) {
712 synaptics_report_slot(dev, 0,
NULL);
713 synaptics_report_slot(dev, 1,
NULL);
714 }
else if (mt_state->
sgm == 0) {
715 synaptics_report_slot(dev, 0, sgm);
716 synaptics_report_slot(dev, 1,
NULL);
718 synaptics_report_slot(dev, 0,
NULL);
719 synaptics_report_slot(dev, 1, sgm);
728 if (mt_state->
sgm != -1 &&
729 (mt_state->
sgm == old->
sgm || old->
sgm == -1))
730 synaptics_report_slot(dev, 0, sgm);
732 synaptics_report_slot(dev, 0,
NULL);
739 if (mt_state->
agm != -1 &&
740 (mt_state->
agm == old->
agm || old->
agm == -1))
741 synaptics_report_slot(dev, 1, agm);
743 synaptics_report_slot(dev, 1,
NULL);
753 synaptics_report_buttons(psmouse, sgm);
759 static void synaptics_image_sensor_0f(
struct synaptics_data *priv,
762 synaptics_mt_state_set(mt_state, 0, -1, -1);
767 static void synaptics_image_sensor_1f(
struct synaptics_data *priv,
779 synaptics_mt_state_set(mt_state, 1, 0, -1);
784 switch (old->
count) {
786 synaptics_mt_state_set(mt_state, 1, 0, -1);
816 synaptics_mt_state_set(mt_state, 1, 1, -1);
817 else if (old->
sgm == -1)
818 synaptics_mt_state_set(mt_state, 1, 0, -1);
828 synaptics_mt_state_set(mt_state, 1, -1, -1);
837 synaptics_mt_state_set(mt_state, 1, old->
agm, -1);
847 synaptics_mt_state_set(mt_state, 1, -1, -1);
858 static void synaptics_image_sensor_2f(
struct synaptics_data *priv,
863 switch (old->
count) {
865 synaptics_mt_state_set(mt_state, 2, 0, 1);
877 synaptics_mt_state_set(mt_state, 2, 0, old->
sgm);
879 synaptics_mt_state_set(mt_state, 2, 0, 1);
888 synaptics_mt_state_set(mt_state, 2, 0, 1);
905 synaptics_mt_state_set(mt_state, 2, -1, -1);
916 static void synaptics_image_sensor_3f(
struct synaptics_data *priv,
921 switch (old->
count) {
923 synaptics_mt_state_set(mt_state, 3, 0, 2);
934 synaptics_mt_state_set(mt_state, 3, 0, old->
sgm);
936 synaptics_mt_state_set(mt_state, 3, 0, 2);
951 synaptics_mt_state_set(mt_state, 3, 0, old->
agm);
966 synaptics_mt_state_set(mt_state, 3, -1, -1);
981 synaptics_mt_state_set(mt_state, 3, 0, -1);
989 synaptics_mt_state_set(mt_state, 3, 0, 2);
1004 static void synaptics_image_sensor_45f(
struct synaptics_data *priv,
1011 static void synaptics_image_sensor_process(
struct psmouse *psmouse,
1025 synaptics_image_sensor_0f(priv, &mt_state);
1026 else if (sgm->
w >= 4)
1027 synaptics_image_sensor_1f(priv, &mt_state);
1028 else if (sgm->
w == 0)
1029 synaptics_image_sensor_2f(priv, &mt_state);
1030 else if (sgm->
w == 1 && mt_state.count <= 3)
1031 synaptics_image_sensor_3f(priv, &mt_state);
1033 synaptics_image_sensor_45f(priv, &mt_state);
1036 synaptics_report_mt_data(psmouse, &mt_state, sgm);
1046 static void synaptics_process_packet(
struct psmouse *psmouse)
1048 struct input_dev *dev = psmouse->
dev;
1054 if (synaptics_parse_hw_state(psmouse->
packet, priv, &hw))
1058 synaptics_image_sensor_process(psmouse, &hw);
1065 while (priv->
scroll >= 4) {
1072 while (priv->
scroll <= -4) {
1082 if (hw.
z > 0 && hw.
x > 1) {
1089 num_fingers = hw.
w + 2;
1097 finger_width = hw.
w;
1107 synaptics_report_semi_mt_data(dev, &hw, &priv->
agm,
1114 if (hw.
z > 30) input_report_key(dev,
BTN_TOUCH, 1);
1115 if (hw.
z < 25) input_report_key(dev,
BTN_TOUCH, 0);
1117 if (num_fingers > 0) {
1118 input_report_abs(dev,
ABS_X, hw.
x);
1119 input_report_abs(dev,
ABS_Y, synaptics_invert_y(hw.
y));
1132 synaptics_report_buttons(psmouse, &hw);
1137 static int synaptics_validate_byte(
struct psmouse *psmouse,
1138 int idx,
unsigned char pkt_type)
1140 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
1141 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
1142 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
1143 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
1144 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
1145 const char *packet = psmouse->
packet;
1147 if (idx < 0 || idx > 4)
1154 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[
idx];
1157 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[
idx];
1160 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[
idx];
1163 psmouse_err(psmouse,
"unknown packet type %d\n", pkt_type);
1168 static unsigned char synaptics_detect_pkt_type(
struct psmouse *psmouse)
1172 for (i = 0; i < 5; i++)
1174 psmouse_info(psmouse,
"using relaxed packet validation\n");
1181 static psmouse_ret_t synaptics_process_byte(
struct psmouse *psmouse)
1185 if (psmouse->
pktcnt >= 6) {
1187 priv->
pkt_type = synaptics_detect_pkt_type(psmouse);
1190 synaptics_is_pt_packet(psmouse->
packet)) {
1194 synaptics_process_packet(psmouse);
1199 return synaptics_validate_byte(psmouse, psmouse->
pktcnt - 1, priv->
pkt_type) ?
1206 static void set_abs_position_params(
struct input_dev *dev,
1217 input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
1218 input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
1219 input_abs_set_res(dev, x_code, priv->
x_res);
1220 input_abs_set_res(dev, y_code, priv->
y_res);
1223 static void set_input_params(
struct input_dev *dev,
struct synaptics_data *priv)
1246 set_abs_position_params(dev, priv,
ABS_X,
ABS_Y);
1299 static ssize_t synaptics_show_disable_gesture(
struct psmouse *psmouse,
1300 void *
data,
char *buf)
1307 static ssize_t synaptics_set_disable_gesture(
struct psmouse *psmouse,
1308 void *
data,
const char *buf,
1331 if (synaptics_mode_cmd(psmouse, priv->
mode))
1338 synaptics_show_disable_gesture,
1339 synaptics_set_disable_gesture);
1341 static void synaptics_disconnect(
struct psmouse *psmouse)
1347 &psmouse_attr_disable_gesture.dattr);
1354 static int synaptics_reconnect(
struct psmouse *psmouse)
1374 }
while (error && ++retry < 3);
1380 psmouse_dbg(psmouse,
"reconnected after %d tries\n", retry);
1382 if (synaptics_query_hardware(psmouse)) {
1383 psmouse_err(psmouse,
"Unable to query device.\n");
1387 if (synaptics_set_mode(psmouse)) {
1388 psmouse_err(psmouse,
"Unable to initialize device.\n");
1397 "hardware appears to be different: id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
1408 static bool impaired_toshiba_kbc;
1411 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
1447 static bool broken_olpc_ec;
1450 #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
1468 static int __synaptics_init(
struct psmouse *psmouse,
bool absolute_mode)
1479 if (absolute_mode && broken_olpc_ec) {
1481 "OLPC XO detected, not enabling Synaptics protocol.\n");
1491 if (synaptics_query_hardware(psmouse)) {
1492 psmouse_err(psmouse,
"Unable to query device.\n");
1500 if (synaptics_set_mode(psmouse)) {
1501 psmouse_err(psmouse,
"Unable to initialize device.\n");
1508 "Touchpad model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx, board id: %lu, fw id: %lu\n",
1515 set_input_params(psmouse->
dev, priv);
1527 if (absolute_mode) {
1536 psmouse->
set_rate = synaptics_set_rate;
1538 psmouse->
reconnect = synaptics_reconnect;
1544 synaptics_pt_create(psmouse);
1551 if (psmouse->
rate >= 80 && impaired_toshiba_kbc) {
1553 "Toshiba %s detected, limiting rate to 40pps.\n",
1560 &psmouse_attr_disable_gesture.dattr);
1563 "Failed to create disable_gesture attribute (%d)",
1578 return __synaptics_init(psmouse,
true);
1583 return __synaptics_init(psmouse,
false);