1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Finger Sensing Pad PS/2 mouse driver.
5 * Copyright (C) 2005-2007 Asia Vital Components Co., Ltd.
6 * Copyright (C) 2005-2012 Tai-hwa Liang, Sentelic Corporation.
9 #include <linux/module.h>
10 #include <linux/input.h>
11 #include <linux/input/mt.h>
12 #include <linux/ctype.h>
13 #include <linux/libps2.h>
14 #include <linux/serio.h>
15 #include <linux/jiffies.h>
16 #include <linux/slab.h>
22 * Timeout for FSP PS/2 command only (in milliseconds).
24 #define FSP_CMD_TIMEOUT 200
25 #define FSP_CMD_TIMEOUT2 30
27 #define GET_ABS_X(packet) ((packet[1] << 2) | ((packet[3] >> 2) & 0x03))
28 #define GET_ABS_Y(packet) ((packet[2] << 2) | (packet[3] & 0x03))
30 /** Driver version. */
31 static const char fsp_drv_ver
[] = "1.1.0-K";
34 * Make sure that the value being sent to FSP will not conflict with
35 * possible sample rate values.
37 static unsigned char fsp_test_swap_cmd(unsigned char reg_val
)
40 case 10: case 20: case 40: case 60: case 80: case 100: case 200:
42 * The requested value being sent to FSP matched to possible
43 * sample rates, swap the given value such that the hardware
44 * wouldn't get confused.
46 return (reg_val
>> 4) | (reg_val
<< 4);
48 return reg_val
; /* swap isn't necessary */
53 * Make sure that the value being sent to FSP will not conflict with certain
56 static unsigned char fsp_test_invert_cmd(unsigned char reg_val
)
59 case 0xe9: case 0xee: case 0xf2: case 0xff:
61 * The requested value being sent to FSP matched to certain
62 * commands, inverse the given value such that the hardware
63 * wouldn't get confused.
67 return reg_val
; /* inversion isn't necessary */
71 static int fsp_reg_read(struct psmouse
*psmouse
, int reg_addr
, int *reg_val
)
73 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
74 unsigned char param
[3];
79 * We need to shut off the device and switch it into command
80 * mode so we don't confuse our protocol handler. We don't need
81 * to do that for writes because sysfs set helper does this for
84 psmouse_deactivate(psmouse
);
86 ps2_begin_command(ps2dev
);
88 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
91 /* should return 0xfe(request for resending) */
92 ps2_sendbyte(ps2dev
, 0x66, FSP_CMD_TIMEOUT2
);
93 /* should return 0xfc(failed) */
94 ps2_sendbyte(ps2dev
, 0x88, FSP_CMD_TIMEOUT2
);
96 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
99 if ((addr
= fsp_test_invert_cmd(reg_addr
)) != reg_addr
) {
100 ps2_sendbyte(ps2dev
, 0x68, FSP_CMD_TIMEOUT2
);
101 } else if ((addr
= fsp_test_swap_cmd(reg_addr
)) != reg_addr
) {
102 /* swapping is required */
103 ps2_sendbyte(ps2dev
, 0xcc, FSP_CMD_TIMEOUT2
);
106 /* swapping isn't necessary */
107 ps2_sendbyte(ps2dev
, 0x66, FSP_CMD_TIMEOUT2
);
110 /* should return 0xfc(failed) */
111 ps2_sendbyte(ps2dev
, addr
, FSP_CMD_TIMEOUT
);
113 if (__ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
) < 0)
120 ps2_end_command(ps2dev
);
121 psmouse_activate(psmouse
);
123 "READ REG: 0x%02x is 0x%02x (rc = %d)\n",
124 reg_addr
, *reg_val
, rc
);
128 static int fsp_reg_write(struct psmouse
*psmouse
, int reg_addr
, int reg_val
)
130 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
134 ps2_begin_command(ps2dev
);
136 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
139 if ((v
= fsp_test_invert_cmd(reg_addr
)) != reg_addr
) {
140 /* inversion is required */
141 ps2_sendbyte(ps2dev
, 0x74, FSP_CMD_TIMEOUT2
);
143 if ((v
= fsp_test_swap_cmd(reg_addr
)) != reg_addr
) {
144 /* swapping is required */
145 ps2_sendbyte(ps2dev
, 0x77, FSP_CMD_TIMEOUT2
);
147 /* swapping isn't necessary */
148 ps2_sendbyte(ps2dev
, 0x55, FSP_CMD_TIMEOUT2
);
151 /* write the register address in correct order */
152 ps2_sendbyte(ps2dev
, v
, FSP_CMD_TIMEOUT2
);
154 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
157 if ((v
= fsp_test_invert_cmd(reg_val
)) != reg_val
) {
158 /* inversion is required */
159 ps2_sendbyte(ps2dev
, 0x47, FSP_CMD_TIMEOUT2
);
160 } else if ((v
= fsp_test_swap_cmd(reg_val
)) != reg_val
) {
161 /* swapping is required */
162 ps2_sendbyte(ps2dev
, 0x44, FSP_CMD_TIMEOUT2
);
164 /* swapping isn't necessary */
165 ps2_sendbyte(ps2dev
, 0x33, FSP_CMD_TIMEOUT2
);
168 /* write the register value in correct order */
169 ps2_sendbyte(ps2dev
, v
, FSP_CMD_TIMEOUT2
);
173 ps2_end_command(ps2dev
);
175 "WRITE REG: 0x%02x to 0x%02x (rc = %d)\n",
176 reg_addr
, reg_val
, rc
);
180 /* Enable register clock gating for writing certain registers */
181 static int fsp_reg_write_enable(struct psmouse
*psmouse
, bool enable
)
185 if (fsp_reg_read(psmouse
, FSP_REG_SYSCTL1
, &v
) == -1)
189 nv
= v
| FSP_BIT_EN_REG_CLK
;
191 nv
= v
& ~FSP_BIT_EN_REG_CLK
;
193 /* only write if necessary */
195 if (fsp_reg_write(psmouse
, FSP_REG_SYSCTL1
, nv
) == -1)
201 static int fsp_page_reg_read(struct psmouse
*psmouse
, int *reg_val
)
203 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
204 unsigned char param
[3];
207 psmouse_deactivate(psmouse
);
209 ps2_begin_command(ps2dev
);
211 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
214 ps2_sendbyte(ps2dev
, 0x66, FSP_CMD_TIMEOUT2
);
215 ps2_sendbyte(ps2dev
, 0x88, FSP_CMD_TIMEOUT2
);
217 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
220 ps2_sendbyte(ps2dev
, 0x83, FSP_CMD_TIMEOUT2
);
221 ps2_sendbyte(ps2dev
, 0x88, FSP_CMD_TIMEOUT2
);
223 /* get the returned result */
224 if (__ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
))
231 ps2_end_command(ps2dev
);
232 psmouse_activate(psmouse
);
234 "READ PAGE REG: 0x%02x (rc = %d)\n",
239 static int fsp_page_reg_write(struct psmouse
*psmouse
, int reg_val
)
241 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
245 ps2_begin_command(ps2dev
);
247 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
250 ps2_sendbyte(ps2dev
, 0x38, FSP_CMD_TIMEOUT2
);
251 ps2_sendbyte(ps2dev
, 0x88, FSP_CMD_TIMEOUT2
);
253 if (ps2_sendbyte(ps2dev
, 0xf3, FSP_CMD_TIMEOUT
) < 0)
256 if ((v
= fsp_test_invert_cmd(reg_val
)) != reg_val
) {
257 ps2_sendbyte(ps2dev
, 0x47, FSP_CMD_TIMEOUT2
);
258 } else if ((v
= fsp_test_swap_cmd(reg_val
)) != reg_val
) {
259 /* swapping is required */
260 ps2_sendbyte(ps2dev
, 0x44, FSP_CMD_TIMEOUT2
);
262 /* swapping isn't necessary */
263 ps2_sendbyte(ps2dev
, 0x33, FSP_CMD_TIMEOUT2
);
266 ps2_sendbyte(ps2dev
, v
, FSP_CMD_TIMEOUT2
);
270 ps2_end_command(ps2dev
);
272 "WRITE PAGE REG: to 0x%02x (rc = %d)\n",
277 static int fsp_get_version(struct psmouse
*psmouse
, int *version
)
279 if (fsp_reg_read(psmouse
, FSP_REG_VERSION
, version
))
285 static int fsp_get_revision(struct psmouse
*psmouse
, int *rev
)
287 if (fsp_reg_read(psmouse
, FSP_REG_REVISION
, rev
))
293 static int fsp_get_sn(struct psmouse
*psmouse
, int *sn
)
298 /* production number since Cx is available at: 0x0b40 ~ 0x0b42 */
299 if (fsp_page_reg_write(psmouse
, FSP_PAGE_0B
))
301 if (fsp_reg_read(psmouse
, FSP_REG_SN0
, &v0
))
303 if (fsp_reg_read(psmouse
, FSP_REG_SN1
, &v1
))
305 if (fsp_reg_read(psmouse
, FSP_REG_SN2
, &v2
))
307 *sn
= (v0
<< 16) | (v1
<< 8) | v2
;
310 fsp_page_reg_write(psmouse
, FSP_PAGE_DEFAULT
);
314 static int fsp_get_buttons(struct psmouse
*psmouse
, int *btn
)
316 static const int buttons
[] = {
317 0x16, /* Left/Middle/Right/Forward/Backward & Scroll Up/Down */
318 0x06, /* Left/Middle/Right & Scroll Up/Down/Right/Left */
319 0x04, /* Left/Middle/Right & Scroll Up/Down */
320 0x02, /* Left/Middle/Right */
324 if (fsp_reg_read(psmouse
, FSP_REG_TMOD_STATUS
, &val
) == -1)
327 *btn
= buttons
[(val
& 0x30) >> 4];
331 /* Enable on-pad command tag output */
332 static int fsp_opc_tag_enable(struct psmouse
*psmouse
, bool enable
)
337 if (fsp_reg_read(psmouse
, FSP_REG_OPC_QDOWN
, &v
) == -1) {
338 psmouse_err(psmouse
, "Unable get OPC state.\n");
343 nv
= v
| FSP_BIT_EN_OPC_TAG
;
345 nv
= v
& ~FSP_BIT_EN_OPC_TAG
;
347 /* only write if necessary */
349 fsp_reg_write_enable(psmouse
, true);
350 res
= fsp_reg_write(psmouse
, FSP_REG_OPC_QDOWN
, nv
);
351 fsp_reg_write_enable(psmouse
, false);
355 psmouse_err(psmouse
, "Unable to enable OPC tag.\n");
362 static int fsp_onpad_vscr(struct psmouse
*psmouse
, bool enable
)
364 struct fsp_data
*pad
= psmouse
->private;
367 if (fsp_reg_read(psmouse
, FSP_REG_ONPAD_CTL
, &val
))
370 pad
->vscroll
= enable
;
373 val
|= (FSP_BIT_FIX_VSCR
| FSP_BIT_ONPAD_ENABLE
);
375 val
&= ~FSP_BIT_FIX_VSCR
;
377 if (fsp_reg_write(psmouse
, FSP_REG_ONPAD_CTL
, val
))
383 static int fsp_onpad_hscr(struct psmouse
*psmouse
, bool enable
)
385 struct fsp_data
*pad
= psmouse
->private;
388 if (fsp_reg_read(psmouse
, FSP_REG_ONPAD_CTL
, &val
))
391 if (fsp_reg_read(psmouse
, FSP_REG_SYSCTL5
, &v2
))
394 pad
->hscroll
= enable
;
397 val
|= (FSP_BIT_FIX_HSCR
| FSP_BIT_ONPAD_ENABLE
);
398 v2
|= FSP_BIT_EN_MSID6
;
400 val
&= ~FSP_BIT_FIX_HSCR
;
401 v2
&= ~(FSP_BIT_EN_MSID6
| FSP_BIT_EN_MSID7
| FSP_BIT_EN_MSID8
);
404 if (fsp_reg_write(psmouse
, FSP_REG_ONPAD_CTL
, val
))
407 /* reconfigure horizontal scrolling packet output */
408 if (fsp_reg_write(psmouse
, FSP_REG_SYSCTL5
, v2
))
415 * Write device specific initial parameters.
417 * ex: 0xab 0xcd - write oxcd into register 0xab
419 static ssize_t
fsp_attr_set_setreg(struct psmouse
*psmouse
, void *data
,
420 const char *buf
, size_t count
)
422 unsigned int reg
, val
;
426 reg
= simple_strtoul(buf
, &rest
, 16);
427 if (rest
== buf
|| *rest
!= ' ' || reg
> 0xff)
430 retval
= kstrtouint(rest
+ 1, 16, &val
);
437 if (fsp_reg_write_enable(psmouse
, true))
440 retval
= fsp_reg_write(psmouse
, reg
, val
) < 0 ? -EIO
: count
;
442 fsp_reg_write_enable(psmouse
, false);
447 PSMOUSE_DEFINE_WO_ATTR(setreg
, S_IWUSR
, NULL
, fsp_attr_set_setreg
);
449 static ssize_t
fsp_attr_show_getreg(struct psmouse
*psmouse
,
450 void *data
, char *buf
)
452 struct fsp_data
*pad
= psmouse
->private;
454 return sprintf(buf
, "%02x%02x\n", pad
->last_reg
, pad
->last_val
);
458 * Read a register from device.
460 * ex: 0xab -- read content from register 0xab
462 static ssize_t
fsp_attr_set_getreg(struct psmouse
*psmouse
, void *data
,
463 const char *buf
, size_t count
)
465 struct fsp_data
*pad
= psmouse
->private;
466 unsigned int reg
, val
;
469 err
= kstrtouint(buf
, 16, ®
);
476 if (fsp_reg_read(psmouse
, reg
, &val
))
485 PSMOUSE_DEFINE_ATTR(getreg
, S_IWUSR
| S_IRUGO
, NULL
,
486 fsp_attr_show_getreg
, fsp_attr_set_getreg
);
488 static ssize_t
fsp_attr_show_pagereg(struct psmouse
*psmouse
,
489 void *data
, char *buf
)
493 if (fsp_page_reg_read(psmouse
, &val
))
496 return sprintf(buf
, "%02x\n", val
);
499 static ssize_t
fsp_attr_set_pagereg(struct psmouse
*psmouse
, void *data
,
500 const char *buf
, size_t count
)
505 err
= kstrtouint(buf
, 16, &val
);
512 if (fsp_page_reg_write(psmouse
, val
))
518 PSMOUSE_DEFINE_ATTR(page
, S_IWUSR
| S_IRUGO
, NULL
,
519 fsp_attr_show_pagereg
, fsp_attr_set_pagereg
);
521 static ssize_t
fsp_attr_show_vscroll(struct psmouse
*psmouse
,
522 void *data
, char *buf
)
524 struct fsp_data
*pad
= psmouse
->private;
526 return sprintf(buf
, "%d\n", pad
->vscroll
);
529 static ssize_t
fsp_attr_set_vscroll(struct psmouse
*psmouse
, void *data
,
530 const char *buf
, size_t count
)
535 err
= kstrtouint(buf
, 10, &val
);
542 fsp_onpad_vscr(psmouse
, val
);
547 PSMOUSE_DEFINE_ATTR(vscroll
, S_IWUSR
| S_IRUGO
, NULL
,
548 fsp_attr_show_vscroll
, fsp_attr_set_vscroll
);
550 static ssize_t
fsp_attr_show_hscroll(struct psmouse
*psmouse
,
551 void *data
, char *buf
)
553 struct fsp_data
*pad
= psmouse
->private;
555 return sprintf(buf
, "%d\n", pad
->hscroll
);
558 static ssize_t
fsp_attr_set_hscroll(struct psmouse
*psmouse
, void *data
,
559 const char *buf
, size_t count
)
564 err
= kstrtouint(buf
, 10, &val
);
571 fsp_onpad_hscr(psmouse
, val
);
576 PSMOUSE_DEFINE_ATTR(hscroll
, S_IWUSR
| S_IRUGO
, NULL
,
577 fsp_attr_show_hscroll
, fsp_attr_set_hscroll
);
579 static ssize_t
fsp_attr_show_flags(struct psmouse
*psmouse
,
580 void *data
, char *buf
)
582 struct fsp_data
*pad
= psmouse
->private;
584 return sprintf(buf
, "%c\n",
585 pad
->flags
& FSPDRV_FLAG_EN_OPC
? 'C' : 'c');
588 static ssize_t
fsp_attr_set_flags(struct psmouse
*psmouse
, void *data
,
589 const char *buf
, size_t count
)
591 struct fsp_data
*pad
= psmouse
->private;
594 for (i
= 0; i
< count
; i
++) {
597 pad
->flags
|= FSPDRV_FLAG_EN_OPC
;
600 pad
->flags
&= ~FSPDRV_FLAG_EN_OPC
;
609 PSMOUSE_DEFINE_ATTR(flags
, S_IWUSR
| S_IRUGO
, NULL
,
610 fsp_attr_show_flags
, fsp_attr_set_flags
);
612 static ssize_t
fsp_attr_show_ver(struct psmouse
*psmouse
,
613 void *data
, char *buf
)
615 return sprintf(buf
, "Sentelic FSP kernel module %s\n", fsp_drv_ver
);
618 PSMOUSE_DEFINE_RO_ATTR(ver
, S_IRUGO
, NULL
, fsp_attr_show_ver
);
620 static struct attribute
*fsp_attributes
[] = {
621 &psmouse_attr_setreg
.dattr
.attr
,
622 &psmouse_attr_getreg
.dattr
.attr
,
623 &psmouse_attr_page
.dattr
.attr
,
624 &psmouse_attr_vscroll
.dattr
.attr
,
625 &psmouse_attr_hscroll
.dattr
.attr
,
626 &psmouse_attr_flags
.dattr
.attr
,
627 &psmouse_attr_ver
.dattr
.attr
,
631 static struct attribute_group fsp_attribute_group
= {
632 .attrs
= fsp_attributes
,
636 static void fsp_packet_debug(struct psmouse
*psmouse
, unsigned char packet
[])
638 static unsigned int ps2_packet_cnt
;
639 static unsigned int ps2_last_second
;
640 unsigned int jiffies_msec
;
641 const char *packet_type
= "UNKNOWN";
642 unsigned short abs_x
= 0, abs_y
= 0;
644 /* Interpret & dump the packet data. */
645 switch (packet
[0] >> FSP_PKT_TYPE_SHIFT
) {
646 case FSP_PKT_TYPE_ABS
:
647 packet_type
= "Absolute";
648 abs_x
= GET_ABS_X(packet
);
649 abs_y
= GET_ABS_Y(packet
);
651 case FSP_PKT_TYPE_NORMAL
:
652 packet_type
= "Normal";
654 case FSP_PKT_TYPE_NOTIFY
:
655 packet_type
= "Notify";
657 case FSP_PKT_TYPE_NORMAL_OPC
:
658 packet_type
= "Normal-OPC";
663 jiffies_msec
= jiffies_to_msecs(jiffies
);
665 "%08dms %s packets: %02x, %02x, %02x, %02x; "
666 "abs_x: %d, abs_y: %d\n",
667 jiffies_msec
, packet_type
,
668 packet
[0], packet
[1], packet
[2], packet
[3], abs_x
, abs_y
);
670 if (jiffies_msec
- ps2_last_second
> 1000) {
671 psmouse_dbg(psmouse
, "PS/2 packets/sec = %d\n", ps2_packet_cnt
);
673 ps2_last_second
= jiffies_msec
;
677 static void fsp_packet_debug(struct psmouse
*psmouse
, unsigned char packet
[])
682 static void fsp_set_slot(struct input_dev
*dev
, int slot
, bool active
,
683 unsigned int x
, unsigned int y
)
685 input_mt_slot(dev
, slot
);
686 input_mt_report_slot_state(dev
, MT_TOOL_FINGER
, active
);
688 input_report_abs(dev
, ABS_MT_POSITION_X
, x
);
689 input_report_abs(dev
, ABS_MT_POSITION_Y
, y
);
693 static psmouse_ret_t
fsp_process_byte(struct psmouse
*psmouse
)
695 struct input_dev
*dev
= psmouse
->dev
;
696 struct fsp_data
*ad
= psmouse
->private;
697 unsigned char *packet
= psmouse
->packet
;
698 unsigned char button_status
= 0, lscroll
= 0, rscroll
= 0;
699 unsigned short abs_x
, abs_y
, fgrs
= 0;
701 if (psmouse
->pktcnt
< 4)
702 return PSMOUSE_GOOD_DATA
;
705 * Full packet accumulated, process it
708 fsp_packet_debug(psmouse
, packet
);
710 switch (psmouse
->packet
[0] >> FSP_PKT_TYPE_SHIFT
) {
711 case FSP_PKT_TYPE_ABS
:
713 if ((packet
[0] == 0x48 || packet
[0] == 0x49) &&
714 packet
[1] == 0 && packet
[2] == 0) {
716 * Ignore coordinate noise when finger leaving the
717 * surface, otherwise cursor may jump to upper-left
723 abs_x
= GET_ABS_X(packet
);
724 abs_y
= GET_ABS_Y(packet
);
726 if (packet
[0] & FSP_PB0_MFMC
) {
728 * MFMC packet: assume that there are two fingers on
734 if (packet
[0] & FSP_PB0_MFMC_FGR2
) {
736 if (ad
->last_mt_fgr
== 2) {
738 * workaround for buggy firmware
739 * which doesn't clear MFMC bit if
740 * the 1st finger is up
743 fsp_set_slot(dev
, 0, false, 0, 0);
747 fsp_set_slot(dev
, 1, fgrs
== 2, abs_x
, abs_y
);
750 if (ad
->last_mt_fgr
== 1) {
752 * workaround for buggy firmware
753 * which doesn't clear MFMC bit if
754 * the 2nd finger is up
757 fsp_set_slot(dev
, 1, false, 0, 0);
760 fsp_set_slot(dev
, 0, fgrs
!= 0, abs_x
, abs_y
);
764 if ((packet
[0] & (FSP_PB0_LBTN
|FSP_PB0_PHY_BTN
)) ==
766 /* On-pad click in SFAC mode should be handled
767 * by userspace. On-pad clicks in MFMC mode
768 * are real clickpad clicks, and not ignored.
770 packet
[0] &= ~FSP_PB0_LBTN
;
773 /* no multi-finger information */
776 if (abs_x
!= 0 && abs_y
!= 0)
779 fsp_set_slot(dev
, 0, fgrs
> 0, abs_x
, abs_y
);
780 fsp_set_slot(dev
, 1, false, 0, 0);
782 if (fgrs
== 1 || (fgrs
== 2 && !(packet
[0] & FSP_PB0_MFMC_FGR2
))) {
783 input_report_abs(dev
, ABS_X
, abs_x
);
784 input_report_abs(dev
, ABS_Y
, abs_y
);
786 input_report_key(dev
, BTN_LEFT
, packet
[0] & 0x01);
787 input_report_key(dev
, BTN_RIGHT
, packet
[0] & 0x02);
788 input_report_key(dev
, BTN_TOUCH
, fgrs
);
789 input_report_key(dev
, BTN_TOOL_FINGER
, fgrs
== 1);
790 input_report_key(dev
, BTN_TOOL_DOUBLETAP
, fgrs
== 2);
793 case FSP_PKT_TYPE_NORMAL_OPC
:
794 /* on-pad click, filter it if necessary */
795 if ((ad
->flags
& FSPDRV_FLAG_EN_OPC
) != FSPDRV_FLAG_EN_OPC
)
796 packet
[0] &= ~FSP_PB0_LBTN
;
799 case FSP_PKT_TYPE_NORMAL
:
801 /* special packet data translation from on-pad packets */
802 if (packet
[3] != 0) {
803 if (packet
[3] & BIT(0))
804 button_status
|= 0x01; /* wheel down */
805 if (packet
[3] & BIT(1))
806 button_status
|= 0x0f; /* wheel up */
807 if (packet
[3] & BIT(2))
808 button_status
|= BIT(4);/* horizontal left */
809 if (packet
[3] & BIT(3))
810 button_status
|= BIT(5);/* horizontal right */
811 /* push back to packet queue */
812 if (button_status
!= 0)
813 packet
[3] = button_status
;
814 rscroll
= (packet
[3] >> 4) & 1;
815 lscroll
= (packet
[3] >> 5) & 1;
818 * Processing wheel up/down and extra button events
820 input_report_rel(dev
, REL_WHEEL
,
821 (int)(packet
[3] & 8) - (int)(packet
[3] & 7));
822 input_report_rel(dev
, REL_HWHEEL
, lscroll
- rscroll
);
823 input_report_key(dev
, BTN_BACK
, lscroll
);
824 input_report_key(dev
, BTN_FORWARD
, rscroll
);
827 * Standard PS/2 Mouse
829 psmouse_report_standard_packet(dev
, packet
);
835 return PSMOUSE_FULL_PACKET
;
838 static int fsp_activate_protocol(struct psmouse
*psmouse
)
840 struct fsp_data
*pad
= psmouse
->private;
841 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
842 unsigned char param
[2];
846 * Standard procedure to enter FSP Intellimouse mode
847 * (scrolling wheel, 4th and 5th buttons)
850 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
852 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
854 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
856 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
);
857 if (param
[0] != 0x04) {
859 "Unable to enable 4 bytes packet format.\n");
863 if (pad
->ver
< FSP_VER_STL3888_C0
) {
864 /* Preparing relative coordinates output for older hardware */
865 if (fsp_reg_read(psmouse
, FSP_REG_SYSCTL5
, &val
)) {
867 "Unable to read SYSCTL5 register.\n");
871 if (fsp_get_buttons(psmouse
, &pad
->buttons
)) {
873 "Unable to retrieve number of buttons.\n");
877 val
&= ~(FSP_BIT_EN_MSID7
| FSP_BIT_EN_MSID8
| FSP_BIT_EN_AUTO_MSID8
);
878 /* Ensure we are not in absolute mode */
879 val
&= ~FSP_BIT_EN_PKT_G0
;
880 if (pad
->buttons
== 0x06) {
881 /* Left/Middle/Right & Scroll Up/Down/Right/Left */
882 val
|= FSP_BIT_EN_MSID6
;
885 if (fsp_reg_write(psmouse
, FSP_REG_SYSCTL5
, val
)) {
887 "Unable to set up required mode bits.\n");
892 * Enable OPC tags such that driver can tell the difference
893 * between on-pad and real button click
895 if (fsp_opc_tag_enable(psmouse
, true))
896 psmouse_warn(psmouse
,
897 "Failed to enable OPC tag mode.\n");
898 /* enable on-pad click by default */
899 pad
->flags
|= FSPDRV_FLAG_EN_OPC
;
901 /* Enable on-pad vertical and horizontal scrolling */
902 fsp_onpad_vscr(psmouse
, true);
903 fsp_onpad_hscr(psmouse
, true);
905 /* Enable absolute coordinates output for Cx/Dx hardware */
906 if (fsp_reg_write(psmouse
, FSP_REG_SWC1
,
907 FSP_BIT_SWC1_EN_ABS_1F
|
908 FSP_BIT_SWC1_EN_ABS_2F
|
909 FSP_BIT_SWC1_EN_FUP_OUT
|
910 FSP_BIT_SWC1_EN_ABS_CON
)) {
912 "Unable to enable absolute coordinates output.\n");
920 static int fsp_set_input_params(struct psmouse
*psmouse
)
922 struct input_dev
*dev
= psmouse
->dev
;
923 struct fsp_data
*pad
= psmouse
->private;
925 if (pad
->ver
< FSP_VER_STL3888_C0
) {
926 __set_bit(BTN_MIDDLE
, dev
->keybit
);
927 __set_bit(BTN_BACK
, dev
->keybit
);
928 __set_bit(BTN_FORWARD
, dev
->keybit
);
929 __set_bit(REL_WHEEL
, dev
->relbit
);
930 __set_bit(REL_HWHEEL
, dev
->relbit
);
933 * Hardware prior to Cx performs much better in relative mode;
934 * hence, only enable absolute coordinates output as well as
935 * multi-touch output for the newer hardware.
937 * Maximum coordinates can be computed as:
939 * number of scanlines * 64 - 57
941 * where number of X/Y scanline lines are 16/12.
943 int abs_x
= 967, abs_y
= 711;
945 __set_bit(EV_ABS
, dev
->evbit
);
946 __clear_bit(EV_REL
, dev
->evbit
);
947 __set_bit(BTN_TOUCH
, dev
->keybit
);
948 __set_bit(BTN_TOOL_FINGER
, dev
->keybit
);
949 __set_bit(BTN_TOOL_DOUBLETAP
, dev
->keybit
);
950 __set_bit(INPUT_PROP_SEMI_MT
, dev
->propbit
);
952 input_set_abs_params(dev
, ABS_X
, 0, abs_x
, 0, 0);
953 input_set_abs_params(dev
, ABS_Y
, 0, abs_y
, 0, 0);
954 input_mt_init_slots(dev
, 2, 0);
955 input_set_abs_params(dev
, ABS_MT_POSITION_X
, 0, abs_x
, 0, 0);
956 input_set_abs_params(dev
, ABS_MT_POSITION_Y
, 0, abs_y
, 0, 0);
962 int fsp_detect(struct psmouse
*psmouse
, bool set_properties
)
966 if (fsp_reg_read(psmouse
, FSP_REG_DEVICE_ID
, &id
))
972 if (set_properties
) {
973 psmouse
->vendor
= "Sentelic";
974 psmouse
->name
= "FingerSensingPad";
980 static void fsp_reset(struct psmouse
*psmouse
)
982 fsp_opc_tag_enable(psmouse
, false);
983 fsp_onpad_vscr(psmouse
, false);
984 fsp_onpad_hscr(psmouse
, false);
987 static void fsp_disconnect(struct psmouse
*psmouse
)
989 sysfs_remove_group(&psmouse
->ps2dev
.serio
->dev
.kobj
,
990 &fsp_attribute_group
);
993 kfree(psmouse
->private);
996 static int fsp_reconnect(struct psmouse
*psmouse
)
1000 if (fsp_detect(psmouse
, 0))
1003 if (fsp_get_version(psmouse
, &version
))
1006 if (fsp_activate_protocol(psmouse
))
1012 int fsp_init(struct psmouse
*psmouse
)
1014 struct fsp_data
*priv
;
1015 int ver
, rev
, sn
= 0;
1018 if (fsp_get_version(psmouse
, &ver
) ||
1019 fsp_get_revision(psmouse
, &rev
)) {
1022 if (ver
>= FSP_VER_STL3888_C0
) {
1023 /* firmware information is only available since C0 */
1024 fsp_get_sn(psmouse
, &sn
);
1027 psmouse_info(psmouse
,
1028 "Finger Sensing Pad, hw: %d.%d.%d, sn: %x, sw: %s\n",
1029 ver
>> 4, ver
& 0x0F, rev
, sn
, fsp_drv_ver
);
1031 psmouse
->private = priv
= kzalloc(sizeof(struct fsp_data
), GFP_KERNEL
);
1038 psmouse
->protocol_handler
= fsp_process_byte
;
1039 psmouse
->disconnect
= fsp_disconnect
;
1040 psmouse
->reconnect
= fsp_reconnect
;
1041 psmouse
->cleanup
= fsp_reset
;
1042 psmouse
->pktsize
= 4;
1044 error
= fsp_activate_protocol(psmouse
);
1048 /* Set up various supported input event bits */
1049 error
= fsp_set_input_params(psmouse
);
1053 error
= sysfs_create_group(&psmouse
->ps2dev
.serio
->dev
.kobj
,
1054 &fsp_attribute_group
);
1056 psmouse_err(psmouse
,
1057 "Failed to create sysfs attributes (%d)", error
);
1064 kfree(psmouse
->private);
1065 psmouse
->private = NULL
;