2 * Finger Sensing Pad PS/2 mouse driver.
4 * Copyright (C) 2005-2007 Asia Vital Components Co., Ltd.
5 * Copyright (C) 2005-2012 Tai-hwa Liang, Sentelic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/input.h>
24 #include <linux/input/mt.h>
25 #include <linux/ctype.h>
26 #include <linux/libps2.h>
27 #include <linux/serio.h>
28 #include <linux/jiffies.h>
29 #include <linux/slab.h>
35 * Timeout for FSP PS/2 command only (in milliseconds).
37 #define FSP_CMD_TIMEOUT 200
38 #define FSP_CMD_TIMEOUT2 30
40 #define GET_ABS_X(packet) ((packet[1] << 2) | ((packet[3] >> 2) & 0x03))
41 #define GET_ABS_Y(packet) ((packet[2] << 2) | (packet[3] & 0x03))
43 /** Driver version. */
44 static const char fsp_drv_ver[] = "1.0.0-K";
47 * Make sure that the value being sent to FSP will not conflict with
48 * possible sample rate values.
50 static unsigned char fsp_test_swap_cmd(unsigned char reg_val)
53 case 10: case 20: case 40: case 60: case 80: case 100: case 200:
55 * The requested value being sent to FSP matched to possible
56 * sample rates, swap the given value such that the hardware
57 * wouldn't get confused.
59 return (reg_val >> 4) | (reg_val << 4);
61 return reg_val; /* swap isn't necessary */
66 * Make sure that the value being sent to FSP will not conflict with certain
69 static unsigned char fsp_test_invert_cmd(unsigned char reg_val)
72 case 0xe9: case 0xee: case 0xf2: case 0xff:
74 * The requested value being sent to FSP matched to certain
75 * commands, inverse the given value such that the hardware
76 * wouldn't get confused.
80 return reg_val; /* inversion isn't necessary */
84 static int fsp_reg_read(struct psmouse *psmouse, int reg_addr, int *reg_val)
86 struct ps2dev *ps2dev = &psmouse->ps2dev;
87 unsigned char param[3];
92 * We need to shut off the device and switch it into command
93 * mode so we don't confuse our protocol handler. We don't need
94 * to do that for writes because sysfs set helper does this for
97 psmouse_deactivate(psmouse);
99 ps2_begin_command(ps2dev);
101 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
104 /* should return 0xfe(request for resending) */
105 ps2_sendbyte(ps2dev, 0x66, FSP_CMD_TIMEOUT2);
106 /* should return 0xfc(failed) */
107 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
109 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
112 if ((addr = fsp_test_invert_cmd(reg_addr)) != reg_addr) {
113 ps2_sendbyte(ps2dev, 0x68, FSP_CMD_TIMEOUT2);
114 } else if ((addr = fsp_test_swap_cmd(reg_addr)) != reg_addr) {
115 /* swapping is required */
116 ps2_sendbyte(ps2dev, 0xcc, FSP_CMD_TIMEOUT2);
119 /* swapping isn't necessary */
120 ps2_sendbyte(ps2dev, 0x66, FSP_CMD_TIMEOUT2);
123 /* should return 0xfc(failed) */
124 ps2_sendbyte(ps2dev, addr, FSP_CMD_TIMEOUT);
126 if (__ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) < 0)
133 ps2_end_command(ps2dev);
134 psmouse_activate(psmouse);
136 "READ REG: 0x%02x is 0x%02x (rc = %d)\n",
137 reg_addr, *reg_val, rc);
141 static int fsp_reg_write(struct psmouse *psmouse, int reg_addr, int reg_val)
143 struct ps2dev *ps2dev = &psmouse->ps2dev;
147 ps2_begin_command(ps2dev);
149 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
152 if ((v = fsp_test_invert_cmd(reg_addr)) != reg_addr) {
153 /* inversion is required */
154 ps2_sendbyte(ps2dev, 0x74, FSP_CMD_TIMEOUT2);
156 if ((v = fsp_test_swap_cmd(reg_addr)) != reg_addr) {
157 /* swapping is required */
158 ps2_sendbyte(ps2dev, 0x77, FSP_CMD_TIMEOUT2);
160 /* swapping isn't necessary */
161 ps2_sendbyte(ps2dev, 0x55, FSP_CMD_TIMEOUT2);
164 /* write the register address in correct order */
165 ps2_sendbyte(ps2dev, v, FSP_CMD_TIMEOUT2);
167 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
170 if ((v = fsp_test_invert_cmd(reg_val)) != reg_val) {
171 /* inversion is required */
172 ps2_sendbyte(ps2dev, 0x47, FSP_CMD_TIMEOUT2);
173 } else if ((v = fsp_test_swap_cmd(reg_val)) != reg_val) {
174 /* swapping is required */
175 ps2_sendbyte(ps2dev, 0x44, FSP_CMD_TIMEOUT2);
177 /* swapping isn't necessary */
178 ps2_sendbyte(ps2dev, 0x33, FSP_CMD_TIMEOUT2);
181 /* write the register value in correct order */
182 ps2_sendbyte(ps2dev, v, FSP_CMD_TIMEOUT2);
186 ps2_end_command(ps2dev);
188 "WRITE REG: 0x%02x to 0x%02x (rc = %d)\n",
189 reg_addr, reg_val, rc);
193 /* Enable register clock gating for writing certain registers */
194 static int fsp_reg_write_enable(struct psmouse *psmouse, bool enable)
198 if (fsp_reg_read(psmouse, FSP_REG_SYSCTL1, &v) == -1)
202 nv = v | FSP_BIT_EN_REG_CLK;
204 nv = v & ~FSP_BIT_EN_REG_CLK;
206 /* only write if necessary */
208 if (fsp_reg_write(psmouse, FSP_REG_SYSCTL1, nv) == -1)
214 static int fsp_page_reg_read(struct psmouse *psmouse, int *reg_val)
216 struct ps2dev *ps2dev = &psmouse->ps2dev;
217 unsigned char param[3];
220 psmouse_deactivate(psmouse);
222 ps2_begin_command(ps2dev);
224 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
227 ps2_sendbyte(ps2dev, 0x66, FSP_CMD_TIMEOUT2);
228 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
230 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
233 ps2_sendbyte(ps2dev, 0x83, FSP_CMD_TIMEOUT2);
234 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
236 /* get the returned result */
237 if (__ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
244 ps2_end_command(ps2dev);
245 psmouse_activate(psmouse);
247 "READ PAGE REG: 0x%02x (rc = %d)\n",
252 static int fsp_page_reg_write(struct psmouse *psmouse, int reg_val)
254 struct ps2dev *ps2dev = &psmouse->ps2dev;
258 ps2_begin_command(ps2dev);
260 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
263 ps2_sendbyte(ps2dev, 0x38, FSP_CMD_TIMEOUT2);
264 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
266 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
269 if ((v = fsp_test_invert_cmd(reg_val)) != reg_val) {
270 ps2_sendbyte(ps2dev, 0x47, FSP_CMD_TIMEOUT2);
271 } else if ((v = fsp_test_swap_cmd(reg_val)) != reg_val) {
272 /* swapping is required */
273 ps2_sendbyte(ps2dev, 0x44, FSP_CMD_TIMEOUT2);
275 /* swapping isn't necessary */
276 ps2_sendbyte(ps2dev, 0x33, FSP_CMD_TIMEOUT2);
279 ps2_sendbyte(ps2dev, v, FSP_CMD_TIMEOUT2);
283 ps2_end_command(ps2dev);
285 "WRITE PAGE REG: to 0x%02x (rc = %d)\n",
290 static int fsp_get_version(struct psmouse *psmouse, int *version)
292 if (fsp_reg_read(psmouse, FSP_REG_VERSION, version))
298 static int fsp_get_revision(struct psmouse *psmouse, int *rev)
300 if (fsp_reg_read(psmouse, FSP_REG_REVISION, rev))
306 static int fsp_get_buttons(struct psmouse *psmouse, int *btn)
308 static const int buttons[] = {
309 0x16, /* Left/Middle/Right/Forward/Backward & Scroll Up/Down */
310 0x06, /* Left/Middle/Right & Scroll Up/Down/Right/Left */
311 0x04, /* Left/Middle/Right & Scroll Up/Down */
312 0x02, /* Left/Middle/Right */
316 if (fsp_reg_read(psmouse, FSP_REG_TMOD_STATUS, &val) == -1)
319 *btn = buttons[(val & 0x30) >> 4];
323 /* Enable on-pad command tag output */
324 static int fsp_opc_tag_enable(struct psmouse *psmouse, bool enable)
329 if (fsp_reg_read(psmouse, FSP_REG_OPC_QDOWN, &v) == -1) {
330 psmouse_err(psmouse, "Unable get OPC state.\n");
335 nv = v | FSP_BIT_EN_OPC_TAG;
337 nv = v & ~FSP_BIT_EN_OPC_TAG;
339 /* only write if necessary */
341 fsp_reg_write_enable(psmouse, true);
342 res = fsp_reg_write(psmouse, FSP_REG_OPC_QDOWN, nv);
343 fsp_reg_write_enable(psmouse, false);
347 psmouse_err(psmouse, "Unable to enable OPC tag.\n");
354 static int fsp_onpad_vscr(struct psmouse *psmouse, bool enable)
356 struct fsp_data *pad = psmouse->private;
359 if (fsp_reg_read(psmouse, FSP_REG_ONPAD_CTL, &val))
362 pad->vscroll = enable;
365 val |= (FSP_BIT_FIX_VSCR | FSP_BIT_ONPAD_ENABLE);
367 val &= ~FSP_BIT_FIX_VSCR;
369 if (fsp_reg_write(psmouse, FSP_REG_ONPAD_CTL, val))
375 static int fsp_onpad_hscr(struct psmouse *psmouse, bool enable)
377 struct fsp_data *pad = psmouse->private;
380 if (fsp_reg_read(psmouse, FSP_REG_ONPAD_CTL, &val))
383 if (fsp_reg_read(psmouse, FSP_REG_SYSCTL5, &v2))
386 pad->hscroll = enable;
389 val |= (FSP_BIT_FIX_HSCR | FSP_BIT_ONPAD_ENABLE);
390 v2 |= FSP_BIT_EN_MSID6;
392 val &= ~FSP_BIT_FIX_HSCR;
393 v2 &= ~(FSP_BIT_EN_MSID6 | FSP_BIT_EN_MSID7 | FSP_BIT_EN_MSID8);
396 if (fsp_reg_write(psmouse, FSP_REG_ONPAD_CTL, val))
399 /* reconfigure horizontal scrolling packet output */
400 if (fsp_reg_write(psmouse, FSP_REG_SYSCTL5, v2))
407 * Write device specific initial parameters.
409 * ex: 0xab 0xcd - write oxcd into register 0xab
411 static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data,
412 const char *buf, size_t count)
414 unsigned long reg, val;
418 reg = simple_strtoul(buf, &rest, 16);
419 if (rest == buf || *rest != ' ' || reg > 0xff)
422 if (strict_strtoul(rest + 1, 16, &val) || val > 0xff)
425 if (fsp_reg_write_enable(psmouse, true))
428 retval = fsp_reg_write(psmouse, reg, val) < 0 ? -EIO : count;
430 fsp_reg_write_enable(psmouse, false);
435 PSMOUSE_DEFINE_WO_ATTR(setreg, S_IWUSR, NULL, fsp_attr_set_setreg);
437 static ssize_t fsp_attr_show_getreg(struct psmouse *psmouse,
438 void *data, char *buf)
440 struct fsp_data *pad = psmouse->private;
442 return sprintf(buf, "%02x%02x\n", pad->last_reg, pad->last_val);
446 * Read a register from device.
448 * ex: 0xab -- read content from register 0xab
450 static ssize_t fsp_attr_set_getreg(struct psmouse *psmouse, void *data,
451 const char *buf, size_t count)
453 struct fsp_data *pad = psmouse->private;
457 if (strict_strtoul(buf, 16, ®) || reg > 0xff)
460 if (fsp_reg_read(psmouse, reg, &val))
469 PSMOUSE_DEFINE_ATTR(getreg, S_IWUSR | S_IRUGO, NULL,
470 fsp_attr_show_getreg, fsp_attr_set_getreg);
472 static ssize_t fsp_attr_show_pagereg(struct psmouse *psmouse,
473 void *data, char *buf)
477 if (fsp_page_reg_read(psmouse, &val))
480 return sprintf(buf, "%02x\n", val);
483 static ssize_t fsp_attr_set_pagereg(struct psmouse *psmouse, void *data,
484 const char *buf, size_t count)
488 if (strict_strtoul(buf, 16, &val) || val > 0xff)
491 if (fsp_page_reg_write(psmouse, val))
497 PSMOUSE_DEFINE_ATTR(page, S_IWUSR | S_IRUGO, NULL,
498 fsp_attr_show_pagereg, fsp_attr_set_pagereg);
500 static ssize_t fsp_attr_show_vscroll(struct psmouse *psmouse,
501 void *data, char *buf)
503 struct fsp_data *pad = psmouse->private;
505 return sprintf(buf, "%d\n", pad->vscroll);
508 static ssize_t fsp_attr_set_vscroll(struct psmouse *psmouse, void *data,
509 const char *buf, size_t count)
513 if (strict_strtoul(buf, 10, &val) || val > 1)
516 fsp_onpad_vscr(psmouse, val);
521 PSMOUSE_DEFINE_ATTR(vscroll, S_IWUSR | S_IRUGO, NULL,
522 fsp_attr_show_vscroll, fsp_attr_set_vscroll);
524 static ssize_t fsp_attr_show_hscroll(struct psmouse *psmouse,
525 void *data, char *buf)
527 struct fsp_data *pad = psmouse->private;
529 return sprintf(buf, "%d\n", pad->hscroll);
532 static ssize_t fsp_attr_set_hscroll(struct psmouse *psmouse, void *data,
533 const char *buf, size_t count)
537 if (strict_strtoul(buf, 10, &val) || val > 1)
540 fsp_onpad_hscr(psmouse, val);
545 PSMOUSE_DEFINE_ATTR(hscroll, S_IWUSR | S_IRUGO, NULL,
546 fsp_attr_show_hscroll, fsp_attr_set_hscroll);
548 static ssize_t fsp_attr_show_flags(struct psmouse *psmouse,
549 void *data, char *buf)
551 struct fsp_data *pad = psmouse->private;
553 return sprintf(buf, "%c\n",
554 pad->flags & FSPDRV_FLAG_EN_OPC ? 'C' : 'c');
557 static ssize_t fsp_attr_set_flags(struct psmouse *psmouse, void *data,
558 const char *buf, size_t count)
560 struct fsp_data *pad = psmouse->private;
563 for (i = 0; i < count; i++) {
566 pad->flags |= FSPDRV_FLAG_EN_OPC;
569 pad->flags &= ~FSPDRV_FLAG_EN_OPC;
578 PSMOUSE_DEFINE_ATTR(flags, S_IWUSR | S_IRUGO, NULL,
579 fsp_attr_show_flags, fsp_attr_set_flags);
581 static ssize_t fsp_attr_show_ver(struct psmouse *psmouse,
582 void *data, char *buf)
584 return sprintf(buf, "Sentelic FSP kernel module %s\n", fsp_drv_ver);
587 PSMOUSE_DEFINE_RO_ATTR(ver, S_IRUGO, NULL, fsp_attr_show_ver);
589 static struct attribute *fsp_attributes[] = {
590 &psmouse_attr_setreg.dattr.attr,
591 &psmouse_attr_getreg.dattr.attr,
592 &psmouse_attr_page.dattr.attr,
593 &psmouse_attr_vscroll.dattr.attr,
594 &psmouse_attr_hscroll.dattr.attr,
595 &psmouse_attr_flags.dattr.attr,
596 &psmouse_attr_ver.dattr.attr,
600 static struct attribute_group fsp_attribute_group = {
601 .attrs = fsp_attributes,
605 static void fsp_packet_debug(struct psmouse *psmouse, unsigned char packet[])
607 static unsigned int ps2_packet_cnt;
608 static unsigned int ps2_last_second;
609 unsigned int jiffies_msec;
610 const char *packet_type = "UNKNOWN";
611 unsigned short abs_x = 0, abs_y = 0;
613 /* Interpret & dump the packet data. */
614 switch (packet[0] >> FSP_PKT_TYPE_SHIFT) {
615 case FSP_PKT_TYPE_ABS:
616 packet_type = "Absolute";
617 abs_x = GET_ABS_X(packet);
618 abs_y = GET_ABS_Y(packet);
620 case FSP_PKT_TYPE_NORMAL:
621 packet_type = "Normal";
623 case FSP_PKT_TYPE_NOTIFY:
624 packet_type = "Notify";
626 case FSP_PKT_TYPE_NORMAL_OPC:
627 packet_type = "Normal-OPC";
632 jiffies_msec = jiffies_to_msecs(jiffies);
634 "%08dms %s packets: %02x, %02x, %02x, %02x; "
635 "abs_x: %d, abs_y: %d\n",
636 jiffies_msec, packet_type,
637 packet[0], packet[1], packet[2], packet[3], abs_x, abs_y);
639 if (jiffies_msec - ps2_last_second > 1000) {
640 psmouse_dbg(psmouse, "PS/2 packets/sec = %d\n", ps2_packet_cnt);
642 ps2_last_second = jiffies_msec;
646 static void fsp_packet_debug(struct psmouse *psmouse, unsigned char packet[])
651 static void fsp_set_slot(struct input_dev *dev, int slot, bool active,
652 unsigned int x, unsigned int y)
654 input_mt_slot(dev, slot);
655 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
657 input_report_abs(dev, ABS_MT_POSITION_X, x);
658 input_report_abs(dev, ABS_MT_POSITION_Y, y);
662 static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
664 struct input_dev *dev = psmouse->dev;
665 struct fsp_data *ad = psmouse->private;
666 unsigned char *packet = psmouse->packet;
667 unsigned char button_status = 0, lscroll = 0, rscroll = 0;
668 unsigned short abs_x, abs_y, fgrs = 0;
671 if (psmouse->pktcnt < 4)
672 return PSMOUSE_GOOD_DATA;
675 * Full packet accumulated, process it
678 fsp_packet_debug(psmouse, packet);
680 switch (psmouse->packet[0] >> FSP_PKT_TYPE_SHIFT) {
681 case FSP_PKT_TYPE_ABS:
682 abs_x = GET_ABS_X(packet);
683 abs_y = GET_ABS_Y(packet);
685 if (packet[0] & FSP_PB0_MFMC) {
687 * MFMC packet: assume that there are two fingers on
693 if (packet[0] & FSP_PB0_MFMC_FGR2) {
695 if (ad->last_mt_fgr == 2) {
697 * workaround for buggy firmware
698 * which doesn't clear MFMC bit if
699 * the 1st finger is up
702 fsp_set_slot(dev, 0, false, 0, 0);
706 fsp_set_slot(dev, 1, fgrs == 2, abs_x, abs_y);
709 if (ad->last_mt_fgr == 1) {
711 * workaround for buggy firmware
712 * which doesn't clear MFMC bit if
713 * the 2nd finger is up
716 fsp_set_slot(dev, 1, false, 0, 0);
719 fsp_set_slot(dev, 0, fgrs != 0, abs_x, abs_y);
724 /* no multi-finger information */
727 if (abs_x != 0 && abs_y != 0)
730 fsp_set_slot(dev, 0, fgrs > 0, abs_x, abs_y);
731 fsp_set_slot(dev, 1, false, 0, 0);
734 input_report_abs(dev, ABS_X, abs_x);
735 input_report_abs(dev, ABS_Y, abs_y);
737 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
738 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
739 input_report_key(dev, BTN_TOUCH, fgrs);
740 input_report_key(dev, BTN_TOOL_FINGER, fgrs == 1);
741 input_report_key(dev, BTN_TOOL_DOUBLETAP, fgrs == 2);
744 case FSP_PKT_TYPE_NORMAL_OPC:
745 /* on-pad click, filter it if necessary */
746 if ((ad->flags & FSPDRV_FLAG_EN_OPC) != FSPDRV_FLAG_EN_OPC)
747 packet[0] &= ~FSP_PB0_LBTN;
750 case FSP_PKT_TYPE_NORMAL:
752 /* special packet data translation from on-pad packets */
753 if (packet[3] != 0) {
754 if (packet[3] & BIT(0))
755 button_status |= 0x01; /* wheel down */
756 if (packet[3] & BIT(1))
757 button_status |= 0x0f; /* wheel up */
758 if (packet[3] & BIT(2))
759 button_status |= BIT(4);/* horizontal left */
760 if (packet[3] & BIT(3))
761 button_status |= BIT(5);/* horizontal right */
762 /* push back to packet queue */
763 if (button_status != 0)
764 packet[3] = button_status;
765 rscroll = (packet[3] >> 4) & 1;
766 lscroll = (packet[3] >> 5) & 1;
769 * Processing wheel up/down and extra button events
771 input_report_rel(dev, REL_WHEEL,
772 (int)(packet[3] & 8) - (int)(packet[3] & 7));
773 input_report_rel(dev, REL_HWHEEL, lscroll - rscroll);
774 input_report_key(dev, BTN_BACK, lscroll);
775 input_report_key(dev, BTN_FORWARD, rscroll);
778 * Standard PS/2 Mouse
780 input_report_key(dev, BTN_LEFT, packet[0] & 1);
781 input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
782 input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
784 rel_x = packet[1] ? (int)packet[1] - (int)((packet[0] << 4) & 0x100) : 0;
785 rel_y = packet[2] ? (int)((packet[0] << 3) & 0x100) - (int)packet[2] : 0;
787 input_report_rel(dev, REL_X, rel_x);
788 input_report_rel(dev, REL_Y, rel_y);
794 return PSMOUSE_FULL_PACKET;
797 static int fsp_activate_protocol(struct psmouse *psmouse)
799 struct fsp_data *pad = psmouse->private;
800 struct ps2dev *ps2dev = &psmouse->ps2dev;
801 unsigned char param[2];
805 * Standard procedure to enter FSP Intellimouse mode
806 * (scrolling wheel, 4th and 5th buttons)
809 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
811 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
813 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
815 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
816 if (param[0] != 0x04) {
818 "Unable to enable 4 bytes packet format.\n");
822 if (pad->ver < FSP_VER_STL3888_C0) {
823 /* Preparing relative coordinates output for older hardware */
824 if (fsp_reg_read(psmouse, FSP_REG_SYSCTL5, &val)) {
826 "Unable to read SYSCTL5 register.\n");
830 if (fsp_get_buttons(psmouse, &pad->buttons)) {
832 "Unable to retrieve number of buttons.\n");
836 val &= ~(FSP_BIT_EN_MSID7 | FSP_BIT_EN_MSID8 | FSP_BIT_EN_AUTO_MSID8);
837 /* Ensure we are not in absolute mode */
838 val &= ~FSP_BIT_EN_PKT_G0;
839 if (pad->buttons == 0x06) {
840 /* Left/Middle/Right & Scroll Up/Down/Right/Left */
841 val |= FSP_BIT_EN_MSID6;
844 if (fsp_reg_write(psmouse, FSP_REG_SYSCTL5, val)) {
846 "Unable to set up required mode bits.\n");
851 * Enable OPC tags such that driver can tell the difference
852 * between on-pad and real button click
854 if (fsp_opc_tag_enable(psmouse, true))
855 psmouse_warn(psmouse,
856 "Failed to enable OPC tag mode.\n");
857 /* enable on-pad click by default */
858 pad->flags |= FSPDRV_FLAG_EN_OPC;
860 /* Enable on-pad vertical and horizontal scrolling */
861 fsp_onpad_vscr(psmouse, true);
862 fsp_onpad_hscr(psmouse, true);
864 /* Enable absolute coordinates output for Cx/Dx hardware */
865 if (fsp_reg_write(psmouse, FSP_REG_SWC1,
866 FSP_BIT_SWC1_EN_ABS_1F |
867 FSP_BIT_SWC1_EN_ABS_2F |
868 FSP_BIT_SWC1_EN_FUP_OUT |
869 FSP_BIT_SWC1_EN_ABS_CON)) {
871 "Unable to enable absolute coordinates output.\n");
879 static int fsp_set_input_params(struct psmouse *psmouse)
881 struct input_dev *dev = psmouse->dev;
882 struct fsp_data *pad = psmouse->private;
884 if (pad->ver < FSP_VER_STL3888_C0) {
885 __set_bit(BTN_MIDDLE, dev->keybit);
886 __set_bit(BTN_BACK, dev->keybit);
887 __set_bit(BTN_FORWARD, dev->keybit);
888 __set_bit(REL_WHEEL, dev->relbit);
889 __set_bit(REL_HWHEEL, dev->relbit);
892 * Hardware prior to Cx performs much better in relative mode;
893 * hence, only enable absolute coordinates output as well as
894 * multi-touch output for the newer hardware.
896 * Maximum coordinates can be computed as:
898 * number of scanlines * 64 - 57
900 * where number of X/Y scanline lines are 16/12.
902 int abs_x = 967, abs_y = 711;
904 __set_bit(EV_ABS, dev->evbit);
905 __clear_bit(EV_REL, dev->evbit);
906 __set_bit(BTN_TOUCH, dev->keybit);
907 __set_bit(BTN_TOOL_FINGER, dev->keybit);
908 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
909 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
911 input_set_abs_params(dev, ABS_X, 0, abs_x, 0, 0);
912 input_set_abs_params(dev, ABS_Y, 0, abs_y, 0, 0);
913 input_mt_init_slots(dev, 2);
914 input_set_abs_params(dev, ABS_MT_POSITION_X, 0, abs_x, 0, 0);
915 input_set_abs_params(dev, ABS_MT_POSITION_Y, 0, abs_y, 0, 0);
921 int fsp_detect(struct psmouse *psmouse, bool set_properties)
925 if (fsp_reg_read(psmouse, FSP_REG_DEVICE_ID, &id))
931 if (set_properties) {
932 psmouse->vendor = "Sentelic";
933 psmouse->name = "FingerSensingPad";
939 static void fsp_reset(struct psmouse *psmouse)
941 fsp_opc_tag_enable(psmouse, false);
942 fsp_onpad_vscr(psmouse, false);
943 fsp_onpad_hscr(psmouse, false);
946 static void fsp_disconnect(struct psmouse *psmouse)
948 sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj,
949 &fsp_attribute_group);
952 kfree(psmouse->private);
955 static int fsp_reconnect(struct psmouse *psmouse)
959 if (fsp_detect(psmouse, 0))
962 if (fsp_get_version(psmouse, &version))
965 if (fsp_activate_protocol(psmouse))
971 int fsp_init(struct psmouse *psmouse)
973 struct fsp_data *priv;
977 if (fsp_get_version(psmouse, &ver) ||
978 fsp_get_revision(psmouse, &rev)) {
982 psmouse_info(psmouse, "Finger Sensing Pad, hw: %d.%d.%d, sw: %s\n",
983 ver >> 4, ver & 0x0F, rev, fsp_drv_ver);
985 psmouse->private = priv = kzalloc(sizeof(struct fsp_data), GFP_KERNEL);
992 psmouse->protocol_handler = fsp_process_byte;
993 psmouse->disconnect = fsp_disconnect;
994 psmouse->reconnect = fsp_reconnect;
995 psmouse->cleanup = fsp_reset;
996 psmouse->pktsize = 4;
998 error = fsp_activate_protocol(psmouse);
1002 /* Set up various supported input event bits */
1003 error = fsp_set_input_params(psmouse);
1007 error = sysfs_create_group(&psmouse->ps2dev.serio->dev.kobj,
1008 &fsp_attribute_group);
1010 psmouse_err(psmouse,
1011 "Failed to create sysfs attributes (%d)", error);
1018 kfree(psmouse->private);
1019 psmouse->private = NULL;