22 #include <linux/module.h>
23 #include <linux/input.h>
25 #include <linux/ctype.h>
27 #include <linux/serio.h>
29 #include <linux/slab.h>
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))
44 static const char fsp_drv_ver[] =
"1.1.0-K";
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:
59 return (reg_val >> 4) | (reg_val << 4);
69 static unsigned char fsp_test_invert_cmd(
unsigned char reg_val)
72 case 0xe9:
case 0xee:
case 0xf2:
case 0xff:
87 unsigned char param[3];
112 if ((addr = fsp_test_invert_cmd(reg_addr)) != reg_addr) {
114 }
else if ((addr = fsp_test_swap_cmd(reg_addr)) != reg_addr) {
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;
152 if ((v = fsp_test_invert_cmd(reg_addr)) != reg_addr) {
156 if ((v = fsp_test_swap_cmd(reg_addr)) != reg_addr) {
170 if ((v = fsp_test_invert_cmd(reg_val)) != reg_val) {
173 }
else if ((v = fsp_test_swap_cmd(reg_val)) != reg_val) {
188 "WRITE REG: 0x%02x to 0x%02x (rc = %d)\n",
189 reg_addr, reg_val, rc);
194 static int fsp_reg_write_enable(
struct psmouse *psmouse,
bool enable)
214 static int fsp_page_reg_read(
struct psmouse *psmouse,
int *reg_val)
216 struct ps2dev *ps2dev = &psmouse->
ps2dev;
217 unsigned char param[3];
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;
269 if ((v = fsp_test_invert_cmd(reg_val)) != reg_val) {
271 }
else if ((v = fsp_test_swap_cmd(reg_val)) != reg_val) {
285 "WRITE PAGE REG: to 0x%02x (rc = %d)\n",
290 static int fsp_get_version(
struct psmouse *psmouse,
int *
version)
298 static int fsp_get_revision(
struct psmouse *psmouse,
int *
rev)
306 static int fsp_get_sn(
struct psmouse *psmouse,
int *
sn)
320 *sn = (v0 << 16) | (v1 << 8) |
v2;
327 static int fsp_get_buttons(
struct psmouse *psmouse,
int *btn)
340 *btn = buttons[(val & 0x30) >> 4];
345 static int fsp_opc_tag_enable(
struct psmouse *psmouse,
bool enable)
362 fsp_reg_write_enable(psmouse,
true);
364 fsp_reg_write_enable(psmouse,
false);
368 psmouse_err(psmouse,
"Unable to enable OPC tag.\n");
375 static int fsp_onpad_vscr(
struct psmouse *psmouse,
bool enable)
396 static int fsp_onpad_hscr(
struct psmouse *psmouse,
bool enable)
398 struct fsp_data *pad = psmouse->
private;
432 static ssize_t fsp_attr_set_setreg(
struct psmouse *psmouse,
void *
data,
440 if (rest == buf || *rest !=
' ' || reg > 0xff)
450 if (fsp_reg_write_enable(psmouse,
true))
453 retval = fsp_reg_write(psmouse, reg, val) < 0 ? -
EIO :
count;
455 fsp_reg_write_enable(psmouse,
false);
462 static ssize_t fsp_attr_show_getreg(
struct psmouse *psmouse,
463 void *data,
char *buf)
465 struct fsp_data *pad = psmouse->
private;
467 return sprintf(buf,
"%02x%02x\n", pad->last_reg, pad->last_val);
475 static ssize_t fsp_attr_set_getreg(
struct psmouse *psmouse,
void *data,
476 const char *buf,
size_t count)
478 struct fsp_data *pad = psmouse->
private;
488 if (fsp_reg_read(psmouse, reg, &val))
498 fsp_attr_show_getreg, fsp_attr_set_getreg);
500 static ssize_t fsp_attr_show_pagereg(
struct psmouse *psmouse,
501 void *data,
char *buf)
505 if (fsp_page_reg_read(psmouse, &val))
508 return sprintf(buf,
"%02x\n", val);
511 static ssize_t fsp_attr_set_pagereg(
struct psmouse *psmouse,
void *data,
512 const char *buf,
size_t count)
523 if (fsp_page_reg_write(psmouse, val))
530 fsp_attr_show_pagereg, fsp_attr_set_pagereg);
532 static ssize_t fsp_attr_show_vscroll(
struct psmouse *psmouse,
533 void *data,
char *buf)
535 struct fsp_data *pad = psmouse->
private;
537 return sprintf(buf,
"%d\n", pad->vscroll);
540 static ssize_t fsp_attr_set_vscroll(
struct psmouse *psmouse,
void *data,
541 const char *buf,
size_t count)
553 fsp_onpad_vscr(psmouse, val);
559 fsp_attr_show_vscroll, fsp_attr_set_vscroll);
561 static ssize_t fsp_attr_show_hscroll(
struct psmouse *psmouse,
562 void *data,
char *buf)
564 struct fsp_data *pad = psmouse->
private;
566 return sprintf(buf,
"%d\n", pad->hscroll);
569 static ssize_t fsp_attr_set_hscroll(
struct psmouse *psmouse,
void *data,
570 const char *buf,
size_t count)
582 fsp_onpad_hscr(psmouse, val);
588 fsp_attr_show_hscroll, fsp_attr_set_hscroll);
590 static ssize_t fsp_attr_show_flags(
struct psmouse *psmouse,
591 void *data,
char *buf)
593 struct fsp_data *pad = psmouse->
private;
596 pad->flags & FSPDRV_FLAG_EN_OPC ?
'C' :
'c');
599 static ssize_t fsp_attr_set_flags(
struct psmouse *psmouse,
void *data,
600 const char *buf,
size_t count)
602 struct fsp_data *pad = psmouse->
private;
605 for (i = 0; i <
count; i++) {
608 pad->flags |= FSPDRV_FLAG_EN_OPC;
611 pad->flags &= ~FSPDRV_FLAG_EN_OPC;
621 fsp_attr_show_flags, fsp_attr_set_flags);
623 static ssize_t fsp_attr_show_ver(
struct psmouse *psmouse,
624 void *data,
char *buf)
626 return sprintf(buf,
"Sentelic FSP kernel module %s\n", fsp_drv_ver);
631 static struct attribute *fsp_attributes[] = {
632 &psmouse_attr_setreg.dattr.attr,
633 &psmouse_attr_getreg.dattr.attr,
634 &psmouse_attr_page.dattr.attr,
635 &psmouse_attr_vscroll.dattr.attr,
636 &psmouse_attr_hscroll.dattr.attr,
637 &psmouse_attr_flags.dattr.attr,
638 &psmouse_attr_ver.dattr.attr,
643 .attrs = fsp_attributes,
647 static void fsp_packet_debug(
struct psmouse *psmouse,
unsigned char packet[])
649 static unsigned int ps2_packet_cnt;
650 static unsigned int ps2_last_second;
651 unsigned int jiffies_msec;
658 packet_type =
"Absolute";
663 packet_type =
"Normal";
666 packet_type =
"Notify";
669 packet_type =
"Normal-OPC";
676 "%08dms %s packets: %02x, %02x, %02x, %02x; "
677 "abs_x: %d, abs_y: %d\n",
678 jiffies_msec, packet_type,
679 packet[0], packet[1], packet[2], packet[3], abs_x,
abs_y);
681 if (jiffies_msec - ps2_last_second > 1000) {
682 psmouse_dbg(psmouse,
"PS/2 packets/sec = %d\n", ps2_packet_cnt);
684 ps2_last_second = jiffies_msec;
688 static void fsp_packet_debug(
struct psmouse *psmouse,
unsigned char packet[])
693 static void fsp_set_slot(
struct input_dev *
dev,
int slot,
bool active,
694 unsigned int x,
unsigned int y)
704 static psmouse_ret_t fsp_process_byte(
struct psmouse *psmouse)
706 struct input_dev *dev = psmouse->
dev;
707 struct fsp_data *ad = psmouse->
private;
708 unsigned char *packet = psmouse->
packet;
709 unsigned char button_status = 0, lscroll = 0, rscroll = 0;
720 fsp_packet_debug(psmouse, packet);
725 if ((packet[0] == 0x48 || packet[0] == 0x49) &&
726 packet[1] == 0 && packet[2] == 0) {
748 if (ad->last_mt_fgr == 2) {
755 fsp_set_slot(dev, 0,
false, 0, 0);
759 fsp_set_slot(dev, 1, fgrs == 2, abs_x, abs_y);
762 if (ad->last_mt_fgr == 1) {
769 fsp_set_slot(dev, 1,
false, 0, 0);
772 fsp_set_slot(dev, 0, fgrs != 0, abs_x, abs_y);
788 if (abs_x != 0 && abs_y != 0)
791 fsp_set_slot(dev, 0, fgrs > 0, abs_x, abs_y);
792 fsp_set_slot(dev, 1,
false, 0, 0);
795 input_report_abs(dev,
ABS_X, abs_x);
796 input_report_abs(dev,
ABS_Y, abs_y);
798 input_report_key(dev,
BTN_LEFT, packet[0] & 0x01);
799 input_report_key(dev,
BTN_RIGHT, packet[0] & 0x02);
807 if ((ad->flags & FSPDRV_FLAG_EN_OPC) != FSPDRV_FLAG_EN_OPC)
814 if (packet[3] != 0) {
815 if (packet[3] &
BIT(0))
816 button_status |= 0x01;
817 if (packet[3] &
BIT(1))
818 button_status |= 0x0f;
819 if (packet[3] &
BIT(2))
820 button_status |=
BIT(4);
821 if (packet[3] &
BIT(3))
822 button_status |=
BIT(5);
824 if (button_status != 0)
825 packet[3] = button_status;
826 rscroll = (packet[3] >> 4) & 1;
827 lscroll = (packet[3] >> 5) & 1;
833 (
int)(packet[3] & 8) - (
int)(packet[3] & 7));
834 input_report_rel(dev,
REL_HWHEEL, lscroll - rscroll);
835 input_report_key(dev,
BTN_BACK, lscroll);
841 input_report_key(dev,
BTN_LEFT, packet[0] & 1);
842 input_report_key(dev,
BTN_MIDDLE, (packet[0] >> 2) & 1);
843 input_report_key(dev,
BTN_RIGHT, (packet[0] >> 1) & 1);
845 rel_x = packet[1] ? (
int)packet[1] - (
int)((packet[0] << 4) & 0x100) : 0;
846 rel_y = packet[2] ? (
int)((packet[0] << 3) & 0x100) - (
int)packet[2] : 0;
848 input_report_rel(dev,
REL_X, rel_x);
849 input_report_rel(dev,
REL_Y, rel_y);
858 static
int fsp_activate_protocol(
struct psmouse *psmouse)
860 struct fsp_data *pad = psmouse->private;
861 struct ps2dev *ps2dev = &psmouse->ps2dev;
862 unsigned char param[2];
877 if (param[0] != 0x04) {
879 "Unable to enable 4 bytes packet format.\n");
887 "Unable to read SYSCTL5 register.\n");
891 if (fsp_get_buttons(psmouse, &pad->buttons)) {
893 "Unable to retrieve number of buttons.\n");
900 if (pad->buttons == 0x06) {
907 "Unable to set up required mode bits.\n");
915 if (fsp_opc_tag_enable(psmouse,
true))
917 "Failed to enable OPC tag mode.\n");
919 pad->flags |= FSPDRV_FLAG_EN_OPC;
922 fsp_onpad_vscr(psmouse,
true);
923 fsp_onpad_hscr(psmouse,
true);
932 "Unable to enable absolute coordinates output.\n");
940 static int fsp_set_input_params(
struct psmouse *psmouse)
942 struct input_dev *dev = psmouse->
dev;
943 struct fsp_data *pad = psmouse->
private;
963 int abs_x = 967, abs_y = 711;
972 input_set_abs_params(dev,
ABS_X, 0, abs_x, 0, 0);
973 input_set_abs_params(dev,
ABS_Y, 0, abs_y, 0, 0);
992 if (set_properties) {
993 psmouse->
vendor =
"Sentelic";
994 psmouse->
name =
"FingerSensingPad";
1000 static void fsp_reset(
struct psmouse *psmouse)
1002 fsp_opc_tag_enable(psmouse,
false);
1003 fsp_onpad_vscr(psmouse,
false);
1004 fsp_onpad_hscr(psmouse,
false);
1007 static void fsp_disconnect(
struct psmouse *psmouse)
1010 &fsp_attribute_group);
1016 static int fsp_reconnect(
struct psmouse *psmouse)
1023 if (fsp_get_version(psmouse, &version))
1026 if (fsp_activate_protocol(psmouse))
1034 struct fsp_data *
priv;
1038 if (fsp_get_version(psmouse, &ver) ||
1039 fsp_get_revision(psmouse, &rev)) {
1044 fsp_get_sn(psmouse, &sn);
1048 "Finger Sensing Pad, hw: %d.%d.%d, sn: %x, sw: %s\n",
1049 ver >> 4, ver & 0x0F, rev, sn, fsp_drv_ver);
1064 error = fsp_activate_protocol(psmouse);
1069 error = fsp_set_input_params(psmouse);
1074 &fsp_attribute_group);
1077 "Failed to create sysfs attributes (%d)", error);