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
)
418 reg
= simple_strtoul(buf
, &rest
, 16);
419 if (rest
== buf
|| *rest
!= ' ' || reg
> 0xff)
422 retval
= kstrtoint(rest
+ 1, 16, &val
);
429 if (fsp_reg_write_enable(psmouse
, true))
432 retval
= fsp_reg_write(psmouse
, reg
, val
) < 0 ? -EIO
: count
;
434 fsp_reg_write_enable(psmouse
, false);
439 PSMOUSE_DEFINE_WO_ATTR(setreg
, S_IWUSR
, NULL
, fsp_attr_set_setreg
);
441 static ssize_t
fsp_attr_show_getreg(struct psmouse
*psmouse
,
442 void *data
, char *buf
)
444 struct fsp_data
*pad
= psmouse
->private;
446 return sprintf(buf
, "%02x%02x\n", pad
->last_reg
, pad
->last_val
);
450 * Read a register from device.
452 * ex: 0xab -- read content from register 0xab
454 static ssize_t
fsp_attr_set_getreg(struct psmouse
*psmouse
, void *data
,
455 const char *buf
, size_t count
)
457 struct fsp_data
*pad
= psmouse
->private;
460 err
= kstrtoint(buf
, 16, ®
);
467 if (fsp_reg_read(psmouse
, reg
, &val
))
476 PSMOUSE_DEFINE_ATTR(getreg
, S_IWUSR
| S_IRUGO
, NULL
,
477 fsp_attr_show_getreg
, fsp_attr_set_getreg
);
479 static ssize_t
fsp_attr_show_pagereg(struct psmouse
*psmouse
,
480 void *data
, char *buf
)
484 if (fsp_page_reg_read(psmouse
, &val
))
487 return sprintf(buf
, "%02x\n", val
);
490 static ssize_t
fsp_attr_set_pagereg(struct psmouse
*psmouse
, void *data
,
491 const char *buf
, size_t count
)
495 err
= kstrtoint(buf
, 16, &val
);
502 if (fsp_page_reg_write(psmouse
, val
))
508 PSMOUSE_DEFINE_ATTR(page
, S_IWUSR
| S_IRUGO
, NULL
,
509 fsp_attr_show_pagereg
, fsp_attr_set_pagereg
);
511 static ssize_t
fsp_attr_show_vscroll(struct psmouse
*psmouse
,
512 void *data
, char *buf
)
514 struct fsp_data
*pad
= psmouse
->private;
516 return sprintf(buf
, "%d\n", pad
->vscroll
);
519 static ssize_t
fsp_attr_set_vscroll(struct psmouse
*psmouse
, void *data
,
520 const char *buf
, size_t count
)
525 err
= kstrtouint(buf
, 10, &val
);
532 fsp_onpad_vscr(psmouse
, val
);
537 PSMOUSE_DEFINE_ATTR(vscroll
, S_IWUSR
| S_IRUGO
, NULL
,
538 fsp_attr_show_vscroll
, fsp_attr_set_vscroll
);
540 static ssize_t
fsp_attr_show_hscroll(struct psmouse
*psmouse
,
541 void *data
, char *buf
)
543 struct fsp_data
*pad
= psmouse
->private;
545 return sprintf(buf
, "%d\n", pad
->hscroll
);
548 static ssize_t
fsp_attr_set_hscroll(struct psmouse
*psmouse
, void *data
,
549 const char *buf
, size_t count
)
554 err
= kstrtouint(buf
, 10, &val
);
561 fsp_onpad_hscr(psmouse
, val
);
566 PSMOUSE_DEFINE_ATTR(hscroll
, S_IWUSR
| S_IRUGO
, NULL
,
567 fsp_attr_show_hscroll
, fsp_attr_set_hscroll
);
569 static ssize_t
fsp_attr_show_flags(struct psmouse
*psmouse
,
570 void *data
, char *buf
)
572 struct fsp_data
*pad
= psmouse
->private;
574 return sprintf(buf
, "%c\n",
575 pad
->flags
& FSPDRV_FLAG_EN_OPC
? 'C' : 'c');
578 static ssize_t
fsp_attr_set_flags(struct psmouse
*psmouse
, void *data
,
579 const char *buf
, size_t count
)
581 struct fsp_data
*pad
= psmouse
->private;
584 for (i
= 0; i
< count
; i
++) {
587 pad
->flags
|= FSPDRV_FLAG_EN_OPC
;
590 pad
->flags
&= ~FSPDRV_FLAG_EN_OPC
;
599 PSMOUSE_DEFINE_ATTR(flags
, S_IWUSR
| S_IRUGO
, NULL
,
600 fsp_attr_show_flags
, fsp_attr_set_flags
);
602 static ssize_t
fsp_attr_show_ver(struct psmouse
*psmouse
,
603 void *data
, char *buf
)
605 return sprintf(buf
, "Sentelic FSP kernel module %s\n", fsp_drv_ver
);
608 PSMOUSE_DEFINE_RO_ATTR(ver
, S_IRUGO
, NULL
, fsp_attr_show_ver
);
610 static struct attribute
*fsp_attributes
[] = {
611 &psmouse_attr_setreg
.dattr
.attr
,
612 &psmouse_attr_getreg
.dattr
.attr
,
613 &psmouse_attr_page
.dattr
.attr
,
614 &psmouse_attr_vscroll
.dattr
.attr
,
615 &psmouse_attr_hscroll
.dattr
.attr
,
616 &psmouse_attr_flags
.dattr
.attr
,
617 &psmouse_attr_ver
.dattr
.attr
,
621 static struct attribute_group fsp_attribute_group
= {
622 .attrs
= fsp_attributes
,
626 static void fsp_packet_debug(struct psmouse
*psmouse
, unsigned char packet
[])
628 static unsigned int ps2_packet_cnt
;
629 static unsigned int ps2_last_second
;
630 unsigned int jiffies_msec
;
631 const char *packet_type
= "UNKNOWN";
632 unsigned short abs_x
= 0, abs_y
= 0;
634 /* Interpret & dump the packet data. */
635 switch (packet
[0] >> FSP_PKT_TYPE_SHIFT
) {
636 case FSP_PKT_TYPE_ABS
:
637 packet_type
= "Absolute";
638 abs_x
= GET_ABS_X(packet
);
639 abs_y
= GET_ABS_Y(packet
);
641 case FSP_PKT_TYPE_NORMAL
:
642 packet_type
= "Normal";
644 case FSP_PKT_TYPE_NOTIFY
:
645 packet_type
= "Notify";
647 case FSP_PKT_TYPE_NORMAL_OPC
:
648 packet_type
= "Normal-OPC";
653 jiffies_msec
= jiffies_to_msecs(jiffies
);
655 "%08dms %s packets: %02x, %02x, %02x, %02x; "
656 "abs_x: %d, abs_y: %d\n",
657 jiffies_msec
, packet_type
,
658 packet
[0], packet
[1], packet
[2], packet
[3], abs_x
, abs_y
);
660 if (jiffies_msec
- ps2_last_second
> 1000) {
661 psmouse_dbg(psmouse
, "PS/2 packets/sec = %d\n", ps2_packet_cnt
);
663 ps2_last_second
= jiffies_msec
;
667 static void fsp_packet_debug(struct psmouse
*psmouse
, unsigned char packet
[])
672 static void fsp_set_slot(struct input_dev
*dev
, int slot
, bool active
,
673 unsigned int x
, unsigned int y
)
675 input_mt_slot(dev
, slot
);
676 input_mt_report_slot_state(dev
, MT_TOOL_FINGER
, active
);
678 input_report_abs(dev
, ABS_MT_POSITION_X
, x
);
679 input_report_abs(dev
, ABS_MT_POSITION_Y
, y
);
683 static psmouse_ret_t
fsp_process_byte(struct psmouse
*psmouse
)
685 struct input_dev
*dev
= psmouse
->dev
;
686 struct fsp_data
*ad
= psmouse
->private;
687 unsigned char *packet
= psmouse
->packet
;
688 unsigned char button_status
= 0, lscroll
= 0, rscroll
= 0;
689 unsigned short abs_x
, abs_y
, fgrs
= 0;
692 if (psmouse
->pktcnt
< 4)
693 return PSMOUSE_GOOD_DATA
;
696 * Full packet accumulated, process it
699 fsp_packet_debug(psmouse
, packet
);
701 switch (psmouse
->packet
[0] >> FSP_PKT_TYPE_SHIFT
) {
702 case FSP_PKT_TYPE_ABS
:
703 abs_x
= GET_ABS_X(packet
);
704 abs_y
= GET_ABS_Y(packet
);
706 if (packet
[0] & FSP_PB0_MFMC
) {
708 * MFMC packet: assume that there are two fingers on
714 if (packet
[0] & FSP_PB0_MFMC_FGR2
) {
716 if (ad
->last_mt_fgr
== 2) {
718 * workaround for buggy firmware
719 * which doesn't clear MFMC bit if
720 * the 1st finger is up
723 fsp_set_slot(dev
, 0, false, 0, 0);
727 fsp_set_slot(dev
, 1, fgrs
== 2, abs_x
, abs_y
);
730 if (ad
->last_mt_fgr
== 1) {
732 * workaround for buggy firmware
733 * which doesn't clear MFMC bit if
734 * the 2nd finger is up
737 fsp_set_slot(dev
, 1, false, 0, 0);
740 fsp_set_slot(dev
, 0, fgrs
!= 0, abs_x
, abs_y
);
744 if ((packet
[0] & (FSP_PB0_LBTN
|FSP_PB0_PHY_BTN
)) ==
746 /* On-pad click in SFAC mode should be handled
747 * by userspace. On-pad clicks in MFMC mode
748 * are real clickpad clicks, and not ignored.
750 packet
[0] &= ~FSP_PB0_LBTN
;
753 /* no multi-finger information */
756 if (abs_x
!= 0 && abs_y
!= 0)
759 fsp_set_slot(dev
, 0, fgrs
> 0, abs_x
, abs_y
);
760 fsp_set_slot(dev
, 1, false, 0, 0);
762 if (fgrs
== 1 || (fgrs
== 2 && !(packet
[0] & FSP_PB0_MFMC_FGR2
))) {
763 input_report_abs(dev
, ABS_X
, abs_x
);
764 input_report_abs(dev
, ABS_Y
, abs_y
);
766 input_report_key(dev
, BTN_LEFT
, packet
[0] & 0x01);
767 input_report_key(dev
, BTN_RIGHT
, packet
[0] & 0x02);
768 input_report_key(dev
, BTN_TOUCH
, fgrs
);
769 input_report_key(dev
, BTN_TOOL_FINGER
, fgrs
== 1);
770 input_report_key(dev
, BTN_TOOL_DOUBLETAP
, fgrs
== 2);
773 case FSP_PKT_TYPE_NORMAL_OPC
:
774 /* on-pad click, filter it if necessary */
775 if ((ad
->flags
& FSPDRV_FLAG_EN_OPC
) != FSPDRV_FLAG_EN_OPC
)
776 packet
[0] &= ~FSP_PB0_LBTN
;
779 case FSP_PKT_TYPE_NORMAL
:
781 /* special packet data translation from on-pad packets */
782 if (packet
[3] != 0) {
783 if (packet
[3] & BIT(0))
784 button_status
|= 0x01; /* wheel down */
785 if (packet
[3] & BIT(1))
786 button_status
|= 0x0f; /* wheel up */
787 if (packet
[3] & BIT(2))
788 button_status
|= BIT(4);/* horizontal left */
789 if (packet
[3] & BIT(3))
790 button_status
|= BIT(5);/* horizontal right */
791 /* push back to packet queue */
792 if (button_status
!= 0)
793 packet
[3] = button_status
;
794 rscroll
= (packet
[3] >> 4) & 1;
795 lscroll
= (packet
[3] >> 5) & 1;
798 * Processing wheel up/down and extra button events
800 input_report_rel(dev
, REL_WHEEL
,
801 (int)(packet
[3] & 8) - (int)(packet
[3] & 7));
802 input_report_rel(dev
, REL_HWHEEL
, lscroll
- rscroll
);
803 input_report_key(dev
, BTN_BACK
, lscroll
);
804 input_report_key(dev
, BTN_FORWARD
, rscroll
);
807 * Standard PS/2 Mouse
809 input_report_key(dev
, BTN_LEFT
, packet
[0] & 1);
810 input_report_key(dev
, BTN_MIDDLE
, (packet
[0] >> 2) & 1);
811 input_report_key(dev
, BTN_RIGHT
, (packet
[0] >> 1) & 1);
813 rel_x
= packet
[1] ? (int)packet
[1] - (int)((packet
[0] << 4) & 0x100) : 0;
814 rel_y
= packet
[2] ? (int)((packet
[0] << 3) & 0x100) - (int)packet
[2] : 0;
816 input_report_rel(dev
, REL_X
, rel_x
);
817 input_report_rel(dev
, REL_Y
, rel_y
);
823 return PSMOUSE_FULL_PACKET
;
826 static int fsp_activate_protocol(struct psmouse
*psmouse
)
828 struct fsp_data
*pad
= psmouse
->private;
829 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
830 unsigned char param
[2];
834 * Standard procedure to enter FSP Intellimouse mode
835 * (scrolling wheel, 4th and 5th buttons)
838 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
840 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
842 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
844 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
);
845 if (param
[0] != 0x04) {
847 "Unable to enable 4 bytes packet format.\n");
851 if (pad
->ver
< FSP_VER_STL3888_C0
) {
852 /* Preparing relative coordinates output for older hardware */
853 if (fsp_reg_read(psmouse
, FSP_REG_SYSCTL5
, &val
)) {
855 "Unable to read SYSCTL5 register.\n");
859 if (fsp_get_buttons(psmouse
, &pad
->buttons
)) {
861 "Unable to retrieve number of buttons.\n");
865 val
&= ~(FSP_BIT_EN_MSID7
| FSP_BIT_EN_MSID8
| FSP_BIT_EN_AUTO_MSID8
);
866 /* Ensure we are not in absolute mode */
867 val
&= ~FSP_BIT_EN_PKT_G0
;
868 if (pad
->buttons
== 0x06) {
869 /* Left/Middle/Right & Scroll Up/Down/Right/Left */
870 val
|= FSP_BIT_EN_MSID6
;
873 if (fsp_reg_write(psmouse
, FSP_REG_SYSCTL5
, val
)) {
875 "Unable to set up required mode bits.\n");
880 * Enable OPC tags such that driver can tell the difference
881 * between on-pad and real button click
883 if (fsp_opc_tag_enable(psmouse
, true))
884 psmouse_warn(psmouse
,
885 "Failed to enable OPC tag mode.\n");
886 /* enable on-pad click by default */
887 pad
->flags
|= FSPDRV_FLAG_EN_OPC
;
889 /* Enable on-pad vertical and horizontal scrolling */
890 fsp_onpad_vscr(psmouse
, true);
891 fsp_onpad_hscr(psmouse
, true);
893 /* Enable absolute coordinates output for Cx/Dx hardware */
894 if (fsp_reg_write(psmouse
, FSP_REG_SWC1
,
895 FSP_BIT_SWC1_EN_ABS_1F
|
896 FSP_BIT_SWC1_EN_ABS_2F
|
897 FSP_BIT_SWC1_EN_FUP_OUT
|
898 FSP_BIT_SWC1_EN_ABS_CON
)) {
900 "Unable to enable absolute coordinates output.\n");
908 static int fsp_set_input_params(struct psmouse
*psmouse
)
910 struct input_dev
*dev
= psmouse
->dev
;
911 struct fsp_data
*pad
= psmouse
->private;
913 if (pad
->ver
< FSP_VER_STL3888_C0
) {
914 __set_bit(BTN_MIDDLE
, dev
->keybit
);
915 __set_bit(BTN_BACK
, dev
->keybit
);
916 __set_bit(BTN_FORWARD
, dev
->keybit
);
917 __set_bit(REL_WHEEL
, dev
->relbit
);
918 __set_bit(REL_HWHEEL
, dev
->relbit
);
921 * Hardware prior to Cx performs much better in relative mode;
922 * hence, only enable absolute coordinates output as well as
923 * multi-touch output for the newer hardware.
925 * Maximum coordinates can be computed as:
927 * number of scanlines * 64 - 57
929 * where number of X/Y scanline lines are 16/12.
931 int abs_x
= 967, abs_y
= 711;
933 __set_bit(EV_ABS
, dev
->evbit
);
934 __clear_bit(EV_REL
, dev
->evbit
);
935 __set_bit(BTN_TOUCH
, dev
->keybit
);
936 __set_bit(BTN_TOOL_FINGER
, dev
->keybit
);
937 __set_bit(BTN_TOOL_DOUBLETAP
, dev
->keybit
);
938 __set_bit(INPUT_PROP_SEMI_MT
, dev
->propbit
);
940 input_set_abs_params(dev
, ABS_X
, 0, abs_x
, 0, 0);
941 input_set_abs_params(dev
, ABS_Y
, 0, abs_y
, 0, 0);
942 input_mt_init_slots(dev
, 2);
943 input_set_abs_params(dev
, ABS_MT_POSITION_X
, 0, abs_x
, 0, 0);
944 input_set_abs_params(dev
, ABS_MT_POSITION_Y
, 0, abs_y
, 0, 0);
950 int fsp_detect(struct psmouse
*psmouse
, bool set_properties
)
954 if (fsp_reg_read(psmouse
, FSP_REG_DEVICE_ID
, &id
))
960 if (set_properties
) {
961 psmouse
->vendor
= "Sentelic";
962 psmouse
->name
= "FingerSensingPad";
968 static void fsp_reset(struct psmouse
*psmouse
)
970 fsp_opc_tag_enable(psmouse
, false);
971 fsp_onpad_vscr(psmouse
, false);
972 fsp_onpad_hscr(psmouse
, false);
975 static void fsp_disconnect(struct psmouse
*psmouse
)
977 sysfs_remove_group(&psmouse
->ps2dev
.serio
->dev
.kobj
,
978 &fsp_attribute_group
);
981 kfree(psmouse
->private);
984 static int fsp_reconnect(struct psmouse
*psmouse
)
988 if (fsp_detect(psmouse
, 0))
991 if (fsp_get_version(psmouse
, &version
))
994 if (fsp_activate_protocol(psmouse
))
1000 int fsp_init(struct psmouse
*psmouse
)
1002 struct fsp_data
*priv
;
1006 if (fsp_get_version(psmouse
, &ver
) ||
1007 fsp_get_revision(psmouse
, &rev
)) {
1011 psmouse_info(psmouse
, "Finger Sensing Pad, hw: %d.%d.%d, sw: %s\n",
1012 ver
>> 4, ver
& 0x0F, rev
, fsp_drv_ver
);
1014 psmouse
->private = priv
= kzalloc(sizeof(struct fsp_data
), GFP_KERNEL
);
1021 psmouse
->protocol_handler
= fsp_process_byte
;
1022 psmouse
->disconnect
= fsp_disconnect
;
1023 psmouse
->reconnect
= fsp_reconnect
;
1024 psmouse
->cleanup
= fsp_reset
;
1025 psmouse
->pktsize
= 4;
1027 error
= fsp_activate_protocol(psmouse
);
1031 /* Set up various supported input event bits */
1032 error
= fsp_set_input_params(psmouse
);
1036 error
= sysfs_create_group(&psmouse
->ps2dev
.serio
->dev
.kobj
,
1037 &fsp_attribute_group
);
1039 psmouse_err(psmouse
,
1040 "Failed to create sysfs attributes (%d)", error
);
1047 kfree(psmouse
->private);
1048 psmouse
->private = NULL
;