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 /** Driver version. */
41 static const char fsp_drv_ver[] = "1.0.0-K";
44 * Make sure that the value being sent to FSP will not conflict with
45 * possible sample rate values.
47 static unsigned char fsp_test_swap_cmd(unsigned char reg_val)
50 case 10: case 20: case 40: case 60: case 80: case 100: case 200:
52 * The requested value being sent to FSP matched to possible
53 * sample rates, swap the given value such that the hardware
54 * wouldn't get confused.
56 return (reg_val >> 4) | (reg_val << 4);
58 return reg_val; /* swap isn't necessary */
63 * Make sure that the value being sent to FSP will not conflict with certain
66 static unsigned char fsp_test_invert_cmd(unsigned char reg_val)
69 case 0xe9: case 0xee: case 0xf2: case 0xff:
71 * The requested value being sent to FSP matched to certain
72 * commands, inverse the given value such that the hardware
73 * wouldn't get confused.
77 return reg_val; /* inversion isn't necessary */
81 static int fsp_reg_read(struct psmouse *psmouse, int reg_addr, int *reg_val)
83 struct ps2dev *ps2dev = &psmouse->ps2dev;
84 unsigned char param[3];
89 * We need to shut off the device and switch it into command
90 * mode so we don't confuse our protocol handler. We don't need
91 * to do that for writes because sysfs set helper does this for
94 psmouse_deactivate(psmouse);
96 ps2_begin_command(ps2dev);
98 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
101 /* should return 0xfe(request for resending) */
102 ps2_sendbyte(ps2dev, 0x66, FSP_CMD_TIMEOUT2);
103 /* should return 0xfc(failed) */
104 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
106 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
109 if ((addr = fsp_test_invert_cmd(reg_addr)) != reg_addr) {
110 ps2_sendbyte(ps2dev, 0x68, FSP_CMD_TIMEOUT2);
111 } else if ((addr = fsp_test_swap_cmd(reg_addr)) != reg_addr) {
112 /* swapping is required */
113 ps2_sendbyte(ps2dev, 0xcc, FSP_CMD_TIMEOUT2);
116 /* swapping isn't necessary */
117 ps2_sendbyte(ps2dev, 0x66, FSP_CMD_TIMEOUT2);
120 /* should return 0xfc(failed) */
121 ps2_sendbyte(ps2dev, addr, FSP_CMD_TIMEOUT);
123 if (__ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) < 0)
130 ps2_end_command(ps2dev);
131 psmouse_activate(psmouse);
133 "READ REG: 0x%02x is 0x%02x (rc = %d)\n",
134 reg_addr, *reg_val, rc);
138 static int fsp_reg_write(struct psmouse *psmouse, int reg_addr, int reg_val)
140 struct ps2dev *ps2dev = &psmouse->ps2dev;
144 ps2_begin_command(ps2dev);
146 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
149 if ((v = fsp_test_invert_cmd(reg_addr)) != reg_addr) {
150 /* inversion is required */
151 ps2_sendbyte(ps2dev, 0x74, FSP_CMD_TIMEOUT2);
153 if ((v = fsp_test_swap_cmd(reg_addr)) != reg_addr) {
154 /* swapping is required */
155 ps2_sendbyte(ps2dev, 0x77, FSP_CMD_TIMEOUT2);
157 /* swapping isn't necessary */
158 ps2_sendbyte(ps2dev, 0x55, FSP_CMD_TIMEOUT2);
161 /* write the register address in correct order */
162 ps2_sendbyte(ps2dev, v, FSP_CMD_TIMEOUT2);
164 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
167 if ((v = fsp_test_invert_cmd(reg_val)) != reg_val) {
168 /* inversion is required */
169 ps2_sendbyte(ps2dev, 0x47, FSP_CMD_TIMEOUT2);
170 } else if ((v = fsp_test_swap_cmd(reg_val)) != reg_val) {
171 /* swapping is required */
172 ps2_sendbyte(ps2dev, 0x44, FSP_CMD_TIMEOUT2);
174 /* swapping isn't necessary */
175 ps2_sendbyte(ps2dev, 0x33, FSP_CMD_TIMEOUT2);
178 /* write the register value in correct order */
179 ps2_sendbyte(ps2dev, v, FSP_CMD_TIMEOUT2);
183 ps2_end_command(ps2dev);
185 "WRITE REG: 0x%02x to 0x%02x (rc = %d)\n",
186 reg_addr, reg_val, rc);
190 /* Enable register clock gating for writing certain registers */
191 static int fsp_reg_write_enable(struct psmouse *psmouse, bool enable)
195 if (fsp_reg_read(psmouse, FSP_REG_SYSCTL1, &v) == -1)
199 nv = v | FSP_BIT_EN_REG_CLK;
201 nv = v & ~FSP_BIT_EN_REG_CLK;
203 /* only write if necessary */
205 if (fsp_reg_write(psmouse, FSP_REG_SYSCTL1, nv) == -1)
211 static int fsp_page_reg_read(struct psmouse *psmouse, int *reg_val)
213 struct ps2dev *ps2dev = &psmouse->ps2dev;
214 unsigned char param[3];
217 psmouse_deactivate(psmouse);
219 ps2_begin_command(ps2dev);
221 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
224 ps2_sendbyte(ps2dev, 0x66, FSP_CMD_TIMEOUT2);
225 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
227 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
230 ps2_sendbyte(ps2dev, 0x83, FSP_CMD_TIMEOUT2);
231 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
233 /* get the returned result */
234 if (__ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
241 ps2_end_command(ps2dev);
242 psmouse_activate(psmouse);
244 "READ PAGE REG: 0x%02x (rc = %d)\n",
249 static int fsp_page_reg_write(struct psmouse *psmouse, int reg_val)
251 struct ps2dev *ps2dev = &psmouse->ps2dev;
255 ps2_begin_command(ps2dev);
257 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
260 ps2_sendbyte(ps2dev, 0x38, FSP_CMD_TIMEOUT2);
261 ps2_sendbyte(ps2dev, 0x88, FSP_CMD_TIMEOUT2);
263 if (ps2_sendbyte(ps2dev, 0xf3, FSP_CMD_TIMEOUT) < 0)
266 if ((v = fsp_test_invert_cmd(reg_val)) != reg_val) {
267 ps2_sendbyte(ps2dev, 0x47, FSP_CMD_TIMEOUT2);
268 } else if ((v = fsp_test_swap_cmd(reg_val)) != reg_val) {
269 /* swapping is required */
270 ps2_sendbyte(ps2dev, 0x44, FSP_CMD_TIMEOUT2);
272 /* swapping isn't necessary */
273 ps2_sendbyte(ps2dev, 0x33, FSP_CMD_TIMEOUT2);
276 ps2_sendbyte(ps2dev, v, FSP_CMD_TIMEOUT2);
280 ps2_end_command(ps2dev);
282 "WRITE PAGE REG: to 0x%02x (rc = %d)\n",
287 static int fsp_get_version(struct psmouse *psmouse, int *version)
289 if (fsp_reg_read(psmouse, FSP_REG_VERSION, version))
295 static int fsp_get_revision(struct psmouse *psmouse, int *rev)
297 if (fsp_reg_read(psmouse, FSP_REG_REVISION, rev))
303 static int fsp_get_buttons(struct psmouse *psmouse, int *btn)
305 static const int buttons[] = {
306 0x16, /* Left/Middle/Right/Forward/Backward & Scroll Up/Down */
307 0x06, /* Left/Middle/Right & Scroll Up/Down/Right/Left */
308 0x04, /* Left/Middle/Right & Scroll Up/Down */
309 0x02, /* Left/Middle/Right */
313 if (fsp_reg_read(psmouse, FSP_REG_TMOD_STATUS, &val) == -1)
316 *btn = buttons[(val & 0x30) >> 4];
320 /* Enable on-pad command tag output */
321 static int fsp_opc_tag_enable(struct psmouse *psmouse, bool enable)
326 if (fsp_reg_read(psmouse, FSP_REG_OPC_QDOWN, &v) == -1) {
327 psmouse_err(psmouse, "Unable get OPC state.\n");
332 nv = v | FSP_BIT_EN_OPC_TAG;
334 nv = v & ~FSP_BIT_EN_OPC_TAG;
336 /* only write if necessary */
338 fsp_reg_write_enable(psmouse, true);
339 res = fsp_reg_write(psmouse, FSP_REG_OPC_QDOWN, nv);
340 fsp_reg_write_enable(psmouse, false);
344 psmouse_err(psmouse, "Unable to enable OPC tag.\n");
351 static int fsp_onpad_vscr(struct psmouse *psmouse, bool enable)
353 struct fsp_data *pad = psmouse->private;
356 if (fsp_reg_read(psmouse, FSP_REG_ONPAD_CTL, &val))
359 pad->vscroll = enable;
362 val |= (FSP_BIT_FIX_VSCR | FSP_BIT_ONPAD_ENABLE);
364 val &= ~FSP_BIT_FIX_VSCR;
366 if (fsp_reg_write(psmouse, FSP_REG_ONPAD_CTL, val))
372 static int fsp_onpad_hscr(struct psmouse *psmouse, bool enable)
374 struct fsp_data *pad = psmouse->private;
377 if (fsp_reg_read(psmouse, FSP_REG_ONPAD_CTL, &val))
380 if (fsp_reg_read(psmouse, FSP_REG_SYSCTL5, &v2))
383 pad->hscroll = enable;
386 val |= (FSP_BIT_FIX_HSCR | FSP_BIT_ONPAD_ENABLE);
387 v2 |= FSP_BIT_EN_MSID6;
389 val &= ~FSP_BIT_FIX_HSCR;
390 v2 &= ~(FSP_BIT_EN_MSID6 | FSP_BIT_EN_MSID7 | FSP_BIT_EN_MSID8);
393 if (fsp_reg_write(psmouse, FSP_REG_ONPAD_CTL, val))
396 /* reconfigure horizontal scrolling packet output */
397 if (fsp_reg_write(psmouse, FSP_REG_SYSCTL5, v2))
404 * Write device specific initial parameters.
406 * ex: 0xab 0xcd - write oxcd into register 0xab
408 static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data,
409 const char *buf, size_t count)
411 unsigned long reg, val;
415 reg = simple_strtoul(buf, &rest, 16);
416 if (rest == buf || *rest != ' ' || reg > 0xff)
419 if (strict_strtoul(rest + 1, 16, &val) || val > 0xff)
422 if (fsp_reg_write_enable(psmouse, true))
425 retval = fsp_reg_write(psmouse, reg, val) < 0 ? -EIO : count;
427 fsp_reg_write_enable(psmouse, false);
432 PSMOUSE_DEFINE_WO_ATTR(setreg, S_IWUSR, NULL, fsp_attr_set_setreg);
434 static ssize_t fsp_attr_show_getreg(struct psmouse *psmouse,
435 void *data, char *buf)
437 struct fsp_data *pad = psmouse->private;
439 return sprintf(buf, "%02x%02x\n", pad->last_reg, pad->last_val);
443 * Read a register from device.
445 * ex: 0xab -- read content from register 0xab
447 static ssize_t fsp_attr_set_getreg(struct psmouse *psmouse, void *data,
448 const char *buf, size_t count)
450 struct fsp_data *pad = psmouse->private;
454 if (strict_strtoul(buf, 16, ®) || reg > 0xff)
457 if (fsp_reg_read(psmouse, reg, &val))
466 PSMOUSE_DEFINE_ATTR(getreg, S_IWUSR | S_IRUGO, NULL,
467 fsp_attr_show_getreg, fsp_attr_set_getreg);
469 static ssize_t fsp_attr_show_pagereg(struct psmouse *psmouse,
470 void *data, char *buf)
474 if (fsp_page_reg_read(psmouse, &val))
477 return sprintf(buf, "%02x\n", val);
480 static ssize_t fsp_attr_set_pagereg(struct psmouse *psmouse, void *data,
481 const char *buf, size_t count)
485 if (strict_strtoul(buf, 16, &val) || val > 0xff)
488 if (fsp_page_reg_write(psmouse, val))
494 PSMOUSE_DEFINE_ATTR(page, S_IWUSR | S_IRUGO, NULL,
495 fsp_attr_show_pagereg, fsp_attr_set_pagereg);
497 static ssize_t fsp_attr_show_vscroll(struct psmouse *psmouse,
498 void *data, char *buf)
500 struct fsp_data *pad = psmouse->private;
502 return sprintf(buf, "%d\n", pad->vscroll);
505 static ssize_t fsp_attr_set_vscroll(struct psmouse *psmouse, void *data,
506 const char *buf, size_t count)
510 if (strict_strtoul(buf, 10, &val) || val > 1)
513 fsp_onpad_vscr(psmouse, val);
518 PSMOUSE_DEFINE_ATTR(vscroll, S_IWUSR | S_IRUGO, NULL,
519 fsp_attr_show_vscroll, fsp_attr_set_vscroll);
521 static ssize_t fsp_attr_show_hscroll(struct psmouse *psmouse,
522 void *data, char *buf)
524 struct fsp_data *pad = psmouse->private;
526 return sprintf(buf, "%d\n", pad->hscroll);
529 static ssize_t fsp_attr_set_hscroll(struct psmouse *psmouse, void *data,
530 const char *buf, size_t count)
534 if (strict_strtoul(buf, 10, &val) || val > 1)
537 fsp_onpad_hscr(psmouse, val);
542 PSMOUSE_DEFINE_ATTR(hscroll, S_IWUSR | S_IRUGO, NULL,
543 fsp_attr_show_hscroll, fsp_attr_set_hscroll);
545 static ssize_t fsp_attr_show_flags(struct psmouse *psmouse,
546 void *data, char *buf)
548 struct fsp_data *pad = psmouse->private;
550 return sprintf(buf, "%c\n",
551 pad->flags & FSPDRV_FLAG_EN_OPC ? 'C' : 'c');
554 static ssize_t fsp_attr_set_flags(struct psmouse *psmouse, void *data,
555 const char *buf, size_t count)
557 struct fsp_data *pad = psmouse->private;
560 for (i = 0; i < count; i++) {
563 pad->flags |= FSPDRV_FLAG_EN_OPC;
566 pad->flags &= ~FSPDRV_FLAG_EN_OPC;
575 PSMOUSE_DEFINE_ATTR(flags, S_IWUSR | S_IRUGO, NULL,
576 fsp_attr_show_flags, fsp_attr_set_flags);
578 static ssize_t fsp_attr_show_ver(struct psmouse *psmouse,
579 void *data, char *buf)
581 return sprintf(buf, "Sentelic FSP kernel module %s\n", fsp_drv_ver);
584 PSMOUSE_DEFINE_RO_ATTR(ver, S_IRUGO, NULL, fsp_attr_show_ver);
586 static struct attribute *fsp_attributes[] = {
587 &psmouse_attr_setreg.dattr.attr,
588 &psmouse_attr_getreg.dattr.attr,
589 &psmouse_attr_page.dattr.attr,
590 &psmouse_attr_vscroll.dattr.attr,
591 &psmouse_attr_hscroll.dattr.attr,
592 &psmouse_attr_flags.dattr.attr,
593 &psmouse_attr_ver.dattr.attr,
597 static struct attribute_group fsp_attribute_group = {
598 .attrs = fsp_attributes,
602 static void fsp_packet_debug(unsigned char packet[])
604 static unsigned int ps2_packet_cnt;
605 static unsigned int ps2_last_second;
606 unsigned int jiffies_msec;
609 jiffies_msec = jiffies_to_msecs(jiffies);
611 "%08dms PS/2 packets: %02x, %02x, %02x, %02x\n",
612 jiffies_msec, packet[0], packet[1], packet[2], packet[3]);
614 if (jiffies_msec - ps2_last_second > 1000) {
615 psmouse_dbg(psmouse, "PS/2 packets/sec = %d\n", ps2_packet_cnt);
617 ps2_last_second = jiffies_msec;
621 static void fsp_packet_debug(unsigned char packet[])
626 static void fsp_set_slot(struct input_dev *dev, int slot, bool active,
627 unsigned int x, unsigned int y)
629 input_mt_slot(dev, slot);
630 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
632 input_report_abs(dev, ABS_MT_POSITION_X, x);
633 input_report_abs(dev, ABS_MT_POSITION_Y, y);
637 static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
639 struct input_dev *dev = psmouse->dev;
640 struct fsp_data *ad = psmouse->private;
641 unsigned char *packet = psmouse->packet;
642 unsigned char button_status = 0, lscroll = 0, rscroll = 0;
643 unsigned short abs_x, abs_y, fgrs = 0;
646 if (psmouse->pktcnt < 4)
647 return PSMOUSE_GOOD_DATA;
650 * Full packet accumulated, process it
653 switch (psmouse->packet[0] >> FSP_PKT_TYPE_SHIFT) {
654 case FSP_PKT_TYPE_ABS:
655 abs_x = (packet[1] << 2) | ((packet[3] >> 2) & 0x03);
656 abs_y = (packet[2] << 2) | (packet[3] & 0x03);
658 if (packet[0] & FSP_PB0_MFMC) {
660 * MFMC packet: assume that there are two fingers on
666 if (packet[0] & FSP_PB0_MFMC_FGR2) {
668 if (ad->last_mt_fgr == 2) {
670 * workaround for buggy firmware
671 * which doesn't clear MFMC bit if
672 * the 1st finger is up
675 fsp_set_slot(dev, 0, false, 0, 0);
679 fsp_set_slot(dev, 1, fgrs == 2, abs_x, abs_y);
682 if (ad->last_mt_fgr == 1) {
684 * workaround for buggy firmware
685 * which doesn't clear MFMC bit if
686 * the 2nd finger is up
689 fsp_set_slot(dev, 1, false, 0, 0);
692 fsp_set_slot(dev, 0, fgrs != 0, abs_x, abs_y);
697 /* no multi-finger information */
700 if (abs_x != 0 && abs_y != 0)
703 fsp_set_slot(dev, 0, fgrs > 0, abs_x, abs_y);
704 fsp_set_slot(dev, 1, false, 0, 0);
707 input_report_abs(dev, ABS_X, abs_x);
708 input_report_abs(dev, ABS_Y, abs_y);
710 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
711 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
712 input_report_key(dev, BTN_TOUCH, fgrs);
713 input_report_key(dev, BTN_TOOL_FINGER, fgrs == 1);
714 input_report_key(dev, BTN_TOOL_DOUBLETAP, fgrs == 2);
717 case FSP_PKT_TYPE_NORMAL_OPC:
718 /* on-pad click, filter it if necessary */
719 if ((ad->flags & FSPDRV_FLAG_EN_OPC) != FSPDRV_FLAG_EN_OPC)
720 packet[0] &= ~FSP_PB0_LBTN;
723 case FSP_PKT_TYPE_NORMAL:
725 /* special packet data translation from on-pad packets */
726 if (packet[3] != 0) {
727 if (packet[3] & BIT(0))
728 button_status |= 0x01; /* wheel down */
729 if (packet[3] & BIT(1))
730 button_status |= 0x0f; /* wheel up */
731 if (packet[3] & BIT(2))
732 button_status |= BIT(4);/* horizontal left */
733 if (packet[3] & BIT(3))
734 button_status |= BIT(5);/* horizontal right */
735 /* push back to packet queue */
736 if (button_status != 0)
737 packet[3] = button_status;
738 rscroll = (packet[3] >> 4) & 1;
739 lscroll = (packet[3] >> 5) & 1;
742 * Processing wheel up/down and extra button events
744 input_report_rel(dev, REL_WHEEL,
745 (int)(packet[3] & 8) - (int)(packet[3] & 7));
746 input_report_rel(dev, REL_HWHEEL, lscroll - rscroll);
747 input_report_key(dev, BTN_BACK, lscroll);
748 input_report_key(dev, BTN_FORWARD, rscroll);
751 * Standard PS/2 Mouse
753 input_report_key(dev, BTN_LEFT, packet[0] & 1);
754 input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
755 input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
757 rel_x = packet[1] ? (int)packet[1] - (int)((packet[0] << 4) & 0x100) : 0;
758 rel_y = packet[2] ? (int)((packet[0] << 3) & 0x100) - (int)packet[2] : 0;
760 input_report_rel(dev, REL_X, rel_x);
761 input_report_rel(dev, REL_Y, rel_y);
767 fsp_packet_debug(packet);
769 return PSMOUSE_FULL_PACKET;
772 static int fsp_activate_protocol(struct psmouse *psmouse)
774 struct fsp_data *pad = psmouse->private;
775 struct ps2dev *ps2dev = &psmouse->ps2dev;
776 unsigned char param[2];
780 * Standard procedure to enter FSP Intellimouse mode
781 * (scrolling wheel, 4th and 5th buttons)
784 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
786 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
788 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
790 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
791 if (param[0] != 0x04) {
793 "Unable to enable 4 bytes packet format.\n");
797 if (pad->ver < FSP_VER_STL3888_C0) {
798 /* Preparing relative coordinates output for older hardware */
799 if (fsp_reg_read(psmouse, FSP_REG_SYSCTL5, &val)) {
801 "Unable to read SYSCTL5 register.\n");
805 if (fsp_get_buttons(psmouse, &pad->buttons)) {
807 "Unable to retrieve number of buttons.\n");
811 val &= ~(FSP_BIT_EN_MSID7 | FSP_BIT_EN_MSID8 | FSP_BIT_EN_AUTO_MSID8);
812 /* Ensure we are not in absolute mode */
813 val &= ~FSP_BIT_EN_PKT_G0;
814 if (pad->buttons == 0x06) {
815 /* Left/Middle/Right & Scroll Up/Down/Right/Left */
816 val |= FSP_BIT_EN_MSID6;
819 if (fsp_reg_write(psmouse, FSP_REG_SYSCTL5, val)) {
821 "Unable to set up required mode bits.\n");
826 * Enable OPC tags such that driver can tell the difference
827 * between on-pad and real button click
829 if (fsp_opc_tag_enable(psmouse, true))
830 psmouse_warn(psmouse,
831 "Failed to enable OPC tag mode.\n");
832 /* enable on-pad click by default */
833 pad->flags |= FSPDRV_FLAG_EN_OPC;
835 /* Enable on-pad vertical and horizontal scrolling */
836 fsp_onpad_vscr(psmouse, true);
837 fsp_onpad_hscr(psmouse, true);
839 /* Enable absolute coordinates output for Cx/Dx hardware */
840 if (fsp_reg_write(psmouse, FSP_REG_SWC1,
841 FSP_BIT_SWC1_EN_ABS_1F |
842 FSP_BIT_SWC1_EN_ABS_2F |
843 FSP_BIT_SWC1_EN_FUP_OUT |
844 FSP_BIT_SWC1_EN_ABS_CON)) {
846 "Unable to enable absolute coordinates output.\n");
854 static int fsp_set_input_params(struct psmouse *psmouse)
856 struct input_dev *dev = psmouse->dev;
857 struct fsp_data *pad = psmouse->private;
859 if (pad->ver < FSP_VER_STL3888_C0) {
860 __set_bit(BTN_MIDDLE, dev->keybit);
861 __set_bit(BTN_BACK, dev->keybit);
862 __set_bit(BTN_FORWARD, dev->keybit);
863 __set_bit(REL_WHEEL, dev->relbit);
864 __set_bit(REL_HWHEEL, dev->relbit);
867 * Hardware prior to Cx performs much better in relative mode;
868 * hence, only enable absolute coordinates output as well as
869 * multi-touch output for the newer hardware.
871 * Maximum coordinates can be computed as:
873 * number of scanlines * 64 - 57
875 * where number of X/Y scanline lines are 16/12.
877 int abs_x = 967, abs_y = 711;
879 __set_bit(EV_ABS, dev->evbit);
880 __clear_bit(EV_REL, dev->evbit);
881 __set_bit(BTN_TOUCH, dev->keybit);
882 __set_bit(BTN_TOOL_FINGER, dev->keybit);
883 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
884 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
886 input_set_abs_params(dev, ABS_X, 0, abs_x, 0, 0);
887 input_set_abs_params(dev, ABS_Y, 0, abs_y, 0, 0);
888 input_mt_init_slots(dev, 2);
889 input_set_abs_params(dev, ABS_MT_POSITION_X, 0, abs_x, 0, 0);
890 input_set_abs_params(dev, ABS_MT_POSITION_Y, 0, abs_y, 0, 0);
896 int fsp_detect(struct psmouse *psmouse, bool set_properties)
900 if (fsp_reg_read(psmouse, FSP_REG_DEVICE_ID, &id))
906 if (set_properties) {
907 psmouse->vendor = "Sentelic";
908 psmouse->name = "FingerSensingPad";
914 static void fsp_reset(struct psmouse *psmouse)
916 fsp_opc_tag_enable(psmouse, false);
917 fsp_onpad_vscr(psmouse, false);
918 fsp_onpad_hscr(psmouse, false);
921 static void fsp_disconnect(struct psmouse *psmouse)
923 sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj,
924 &fsp_attribute_group);
927 kfree(psmouse->private);
930 static int fsp_reconnect(struct psmouse *psmouse)
934 if (fsp_detect(psmouse, 0))
937 if (fsp_get_version(psmouse, &version))
940 if (fsp_activate_protocol(psmouse))
946 int fsp_init(struct psmouse *psmouse)
948 struct fsp_data *priv;
952 if (fsp_get_version(psmouse, &ver) ||
953 fsp_get_revision(psmouse, &rev)) {
957 psmouse_info(psmouse, "Finger Sensing Pad, hw: %d.%d.%d, sw: %s\n",
958 ver >> 4, ver & 0x0F, rev, fsp_drv_ver);
960 psmouse->private = priv = kzalloc(sizeof(struct fsp_data), GFP_KERNEL);
967 psmouse->protocol_handler = fsp_process_byte;
968 psmouse->disconnect = fsp_disconnect;
969 psmouse->reconnect = fsp_reconnect;
970 psmouse->cleanup = fsp_reset;
971 psmouse->pktsize = 4;
973 error = fsp_activate_protocol(psmouse);
977 /* Set up various supported input event bits */
978 error = fsp_set_input_params(psmouse);
982 error = sysfs_create_group(&psmouse->ps2dev.serio->dev.kobj,
983 &fsp_attribute_group);
986 "Failed to create sysfs attributes (%d)", error);
993 kfree(psmouse->private);
994 psmouse->private = NULL;