📄 synaptics.c
字号:
hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0; } if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) && ((buf[0] ^ buf[3]) & 0x02)) { switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { default: /* * if nExtBtn is greater than 8 it should be * considered invalid and treated as 0 */ break; case 8: hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0; hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0; case 6: hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0; hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0; case 4: hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0; hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0; case 2: hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0; hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0; } } } else { hw->x = (((buf[1] & 0x1f) << 8) | buf[2]); hw->y = (((buf[4] & 0x1f) << 8) | buf[5]); hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F)); hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1)); hw->left = (buf[0] & 0x01) ? 1 : 0; hw->right = (buf[0] & 0x02) ? 1 : 0; }}/* * called for each full received packet from the touchpad */static void synaptics_process_packet(struct psmouse *psmouse){ struct input_dev *dev = &psmouse->dev; struct synaptics_data *priv = psmouse->private; struct synaptics_hw_state hw; int num_fingers; int finger_width; int i; synaptics_parse_hw_state(psmouse->packet, priv, &hw); if (hw.z > 0) { num_fingers = 1; finger_width = 5; if (SYN_CAP_EXTENDED(priv->capabilities)) { switch (hw.w) { case 0 ... 1: if (SYN_CAP_MULTIFINGER(priv->capabilities)) num_fingers = hw.w + 2; break; case 2: if (SYN_MODEL_PEN(priv->model_id)) ; /* Nothing, treat a pen as a single finger */ break; case 4 ... 15: if (SYN_CAP_PALMDETECT(priv->capabilities)) finger_width = hw.w; break; } } } else { num_fingers = 0; finger_width = 0; } /* Post events * BTN_TOUCH has to be first as mousedev relies on it when doing * absolute -> relative conversion */ if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1); if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0); if (hw.z > 0) { input_report_abs(dev, ABS_X, hw.x); input_report_abs(dev, ABS_Y, YMAX_NOMINAL + YMIN_NOMINAL - hw.y); } input_report_abs(dev, ABS_PRESSURE, hw.z); input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2); input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3); input_report_key(dev, BTN_LEFT, hw.left); input_report_key(dev, BTN_RIGHT, hw.right); if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) input_report_key(dev, BTN_MIDDLE, hw.middle); if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { input_report_key(dev, BTN_FORWARD, hw.up); input_report_key(dev, BTN_BACK, hw.down); } for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++) input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i)); input_sync(dev);}static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type){ static unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 }; static unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 }; static unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 }; static unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 }; static unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 }; if (idx < 0 || idx > 4) return 0; switch (pkt_type) { case SYN_NEWABS: case SYN_NEWABS_RELAXED: return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx]; case SYN_NEWABS_STRICT: return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx]; case SYN_OLDABS: return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx]; default: printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type); return 0; }}static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse){ int i; for (i = 0; i < 5; i++) if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) { printk(KERN_INFO "synaptics: using relaxed packet validation\n"); return SYN_NEWABS_RELAXED; } return SYN_NEWABS_STRICT;}static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs){ struct input_dev *dev = &psmouse->dev; struct synaptics_data *priv = psmouse->private; input_regs(dev, regs); if (psmouse->pktcnt >= 6) { /* Full packet received */ if (unlikely(priv->pkt_type == SYN_NEWABS)) priv->pkt_type = synaptics_detect_pkt_type(psmouse); if (psmouse->ptport && psmouse->ptport->serio.dev && synaptics_is_pt_packet(psmouse->packet)) synaptics_pass_pt_packet(&psmouse->ptport->serio, psmouse->packet); else synaptics_process_packet(psmouse); return PSMOUSE_FULL_PACKET; } return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ? PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;}/***************************************************************************** * Driver initialization/cleanup functions ****************************************************************************/static void set_input_params(struct input_dev *dev, struct synaptics_data *priv){ int i; set_bit(EV_ABS, dev->evbit); input_set_abs_params(dev, ABS_X, XMIN_NOMINAL, XMAX_NOMINAL, 0, 0); input_set_abs_params(dev, ABS_Y, YMIN_NOMINAL, YMAX_NOMINAL, 0, 0); input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); set_bit(ABS_TOOL_WIDTH, dev->absbit); set_bit(EV_KEY, dev->evbit); set_bit(BTN_TOUCH, dev->keybit); set_bit(BTN_TOOL_FINGER, dev->keybit); set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); set_bit(BTN_LEFT, dev->keybit); set_bit(BTN_RIGHT, dev->keybit); if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) set_bit(BTN_MIDDLE, dev->keybit); if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { set_bit(BTN_FORWARD, dev->keybit); set_bit(BTN_BACK, dev->keybit); } for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++) set_bit(BTN_0 + i, dev->keybit); clear_bit(EV_REL, dev->evbit); clear_bit(REL_X, dev->relbit); clear_bit(REL_Y, dev->relbit);}void synaptics_reset(struct psmouse *psmouse){ /* reset touchpad back to relative mode, gestures enabled */ synaptics_mode_cmd(psmouse, 0);}static void synaptics_disconnect(struct psmouse *psmouse){ synaptics_reset(psmouse); kfree(psmouse->private);}static int synaptics_reconnect(struct psmouse *psmouse){ struct synaptics_data *priv = psmouse->private; struct synaptics_data old_priv = *priv; if (!synaptics_detect(psmouse)) return -1; if (synaptics_query_hardware(psmouse)) { printk(KERN_ERR "Unable to query Synaptics hardware.\n"); return -1; } if (old_priv.identity != priv->identity || old_priv.model_id != priv->model_id || old_priv.capabilities != priv->capabilities || old_priv.ext_cap != priv->ext_cap) return -1; if (synaptics_set_mode(psmouse, 0)) { printk(KERN_ERR "Unable to initialize Synaptics hardware.\n"); return -1; } return 0;}int synaptics_detect(struct psmouse *psmouse){ unsigned char param[4]; param[0] = 0; psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES); psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES); psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES); psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES); psmouse_command(psmouse, param, PSMOUSE_CMD_GETINFO); return param[1] == 0x47;}int synaptics_init(struct psmouse *psmouse){ struct synaptics_data *priv; psmouse->private = priv = kmalloc(sizeof(struct synaptics_data), GFP_KERNEL); if (!priv) return -1; memset(priv, 0, sizeof(struct synaptics_data)); if (synaptics_query_hardware(psmouse)) { printk(KERN_ERR "Unable to query Synaptics hardware.\n"); goto init_fail; } if (synaptics_set_mode(psmouse, 0)) { printk(KERN_ERR "Unable to initialize Synaptics hardware.\n"); goto init_fail; } priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS; if (SYN_CAP_PASS_THROUGH(priv->capabilities)) synaptics_pt_create(psmouse); print_ident(priv); set_input_params(&psmouse->dev, priv); psmouse->protocol_handler = synaptics_process_byte; psmouse->disconnect = synaptics_disconnect; psmouse->reconnect = synaptics_reconnect; return 0; init_fail: kfree(priv); return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -