Skip to content

Commit c378b51

Browse files
committed
Input: psmouse - factor out common protocol probing code
In preparation of limiting protocols that we try on pass-through ports, let's rework initialization code and factor common code into psmouse_try_protocol() that accepts protocol type (instead of detec() function pointer) and can, for most protocols, perform both detection and initialization. Note that this removes option of forcing Lifebook protocol on devices that are not recognized by lifebook_detect() as having the hardware, but I do not recall anyone using this option. Reviewed-by: Hans de Goede <[email protected]> Tested-by: Marcin Sochacki <[email protected]> Tested-by: Till <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 5fa75cf commit c378b51

File tree

1 file changed

+86
-78
lines changed

1 file changed

+86
-78
lines changed

drivers/input/mouse/psmouse-base.c

Lines changed: 86 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ static const struct psmouse_protocol psmouse_protocols[] = {
767767
.type = PSMOUSE_LIFEBOOK,
768768
.name = "LBPS/2",
769769
.alias = "lifebook",
770+
.detect = lifebook_detect,
770771
.init = lifebook_init,
771772
},
772773
#endif
@@ -844,14 +845,25 @@ static const struct psmouse_protocol psmouse_protocols[] = {
844845
},
845846
};
846847

847-
static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
848+
static const struct psmouse_protocol *__psmouse_protocol_by_type(enum psmouse_type type)
848849
{
849850
int i;
850851

851852
for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++)
852853
if (psmouse_protocols[i].type == type)
853854
return &psmouse_protocols[i];
854855

856+
return NULL;
857+
}
858+
859+
static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
860+
{
861+
const struct psmouse_protocol *proto;
862+
863+
proto = __psmouse_protocol_by_type(type);
864+
if (proto)
865+
return proto;
866+
855867
WARN_ON(1);
856868
return &psmouse_protocols[0];
857869
}
@@ -910,18 +922,37 @@ static void psmouse_apply_defaults(struct psmouse *psmouse)
910922
psmouse->pt_deactivate = NULL;
911923
}
912924

913-
/*
914-
* Apply default settings to the psmouse structure and call specified
915-
* protocol detection or initialization routine.
916-
*/
917-
static int psmouse_do_detect(int (*detect)(struct psmouse *psmouse,
918-
bool set_properties),
919-
struct psmouse *psmouse, bool set_properties)
925+
static bool psmouse_try_protocol(struct psmouse *psmouse,
926+
enum psmouse_type type,
927+
unsigned int *max_proto,
928+
bool set_properties, bool init_allowed)
920929
{
930+
const struct psmouse_protocol *proto;
931+
932+
proto = __psmouse_protocol_by_type(type);
933+
if (!proto)
934+
return false;
935+
921936
if (set_properties)
922937
psmouse_apply_defaults(psmouse);
923938

924-
return detect(psmouse, set_properties);
939+
if (proto->detect(psmouse, set_properties) != 0)
940+
return false;
941+
942+
if (set_properties && proto->init && init_allowed) {
943+
if (proto->init(psmouse) != 0) {
944+
/*
945+
* We detected device, but init failed. Adjust
946+
* max_proto so we only try standard protocols.
947+
*/
948+
if (*max_proto > PSMOUSE_IMEX)
949+
*max_proto = PSMOUSE_IMEX;
950+
951+
return false;
952+
}
953+
}
954+
955+
return true;
925956
}
926957

927958
/*
@@ -937,12 +968,12 @@ static int psmouse_extensions(struct psmouse *psmouse,
937968
* Always check for focaltech, this is safe as it uses pnp-id
938969
* matching.
939970
*/
940-
if (psmouse_do_detect(focaltech_detect, psmouse, set_properties) == 0) {
941-
if (max_proto > PSMOUSE_IMEX) {
942-
if (IS_ENABLED(CONFIG_MOUSE_PS2_FOCALTECH) &&
943-
(!set_properties || focaltech_init(psmouse) == 0)) {
944-
return PSMOUSE_FOCALTECH;
945-
}
971+
if (psmouse_try_protocol(psmouse, PSMOUSE_FOCALTECH,
972+
&max_proto, set_properties, false)) {
973+
if (max_proto > PSMOUSE_IMEX &&
974+
IS_ENABLED(CONFIG_MOUSE_PS2_FOCALTECH) &&
975+
(!set_properties || focaltech_init(psmouse) == 0)) {
976+
return PSMOUSE_FOCALTECH;
946977
}
947978
/*
948979
* Restrict psmouse_max_proto so that psmouse_initialize()
@@ -959,26 +990,21 @@ static int psmouse_extensions(struct psmouse *psmouse,
959990
* We always check for LifeBook because it does not disturb mouse
960991
* (it only checks DMI information).
961992
*/
962-
if (psmouse_do_detect(lifebook_detect, psmouse, set_properties) == 0) {
963-
if (max_proto > PSMOUSE_IMEX) {
964-
if (!set_properties || lifebook_init(psmouse) == 0)
965-
return PSMOUSE_LIFEBOOK;
966-
}
967-
}
993+
if (psmouse_try_protocol(psmouse, PSMOUSE_LIFEBOOK, &max_proto,
994+
set_properties, max_proto > PSMOUSE_IMEX))
995+
return PSMOUSE_LIFEBOOK;
968996

969-
if (psmouse_do_detect(vmmouse_detect, psmouse, set_properties) == 0) {
970-
if (max_proto > PSMOUSE_IMEX) {
971-
if (!set_properties || vmmouse_init(psmouse) == 0)
972-
return PSMOUSE_VMMOUSE;
973-
}
974-
}
997+
if (psmouse_try_protocol(psmouse, PSMOUSE_VMMOUSE, &max_proto,
998+
set_properties, max_proto > PSMOUSE_IMEX))
999+
return PSMOUSE_VMMOUSE;
9751000

9761001
/*
9771002
* Try Kensington ThinkingMouse (we try first, because Synaptics
9781003
* probe upsets the ThinkingMouse).
9791004
*/
9801005
if (max_proto > PSMOUSE_IMEX &&
981-
psmouse_do_detect(thinking_detect, psmouse, set_properties) == 0) {
1006+
psmouse_try_protocol(psmouse, PSMOUSE_THINKPS, &max_proto,
1007+
set_properties, true)) {
9821008
return PSMOUSE_THINKPS;
9831009
}
9841010

@@ -989,7 +1015,8 @@ static int psmouse_extensions(struct psmouse *psmouse,
9891015
* probing for IntelliMouse.
9901016
*/
9911017
if (max_proto > PSMOUSE_PS2 &&
992-
psmouse_do_detect(synaptics_detect, psmouse, set_properties) == 0) {
1018+
psmouse_try_protocol(psmouse, PSMOUSE_SYNAPTICS, &max_proto,
1019+
set_properties, false)) {
9931020
synaptics_hardware = true;
9941021

9951022
if (max_proto > PSMOUSE_IMEX) {
@@ -1025,79 +1052,59 @@ static int psmouse_extensions(struct psmouse *psmouse,
10251052
* Trackpads.
10261053
*/
10271054
if (max_proto > PSMOUSE_IMEX &&
1028-
psmouse_do_detect(cypress_detect, psmouse, set_properties) == 0) {
1029-
if (!set_properties || cypress_init(psmouse) == 0)
1030-
return PSMOUSE_CYPRESS;
1031-
1032-
/*
1033-
* Finger Sensing Pad probe upsets some modules of
1034-
* Cypress Trackpad, must avoid Finger Sensing Pad
1035-
* probe if Cypress Trackpad device detected.
1036-
*/
1037-
max_proto = PSMOUSE_IMEX;
1055+
psmouse_try_protocol(psmouse, PSMOUSE_CYPRESS, &max_proto,
1056+
set_properties, true)) {
1057+
return PSMOUSE_CYPRESS;
10381058
}
10391059

10401060
/* Try ALPS TouchPad */
10411061
if (max_proto > PSMOUSE_IMEX) {
10421062
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
1043-
if (psmouse_do_detect(alps_detect,
1044-
psmouse, set_properties) == 0) {
1045-
if (!set_properties || alps_init(psmouse) == 0)
1046-
return PSMOUSE_ALPS;
1047-
1048-
/* Init failed, try basic relative protocols */
1049-
max_proto = PSMOUSE_IMEX;
1050-
}
1063+
if (psmouse_try_protocol(psmouse, PSMOUSE_ALPS,
1064+
&max_proto, set_properties, true))
1065+
return PSMOUSE_ALPS;
10511066
}
10521067

10531068
/* Try OLPC HGPK touchpad */
10541069
if (max_proto > PSMOUSE_IMEX &&
1055-
psmouse_do_detect(hgpk_detect, psmouse, set_properties) == 0) {
1056-
if (!set_properties || hgpk_init(psmouse) == 0)
1057-
return PSMOUSE_HGPK;
1058-
/* Init failed, try basic relative protocols */
1059-
max_proto = PSMOUSE_IMEX;
1070+
psmouse_try_protocol(psmouse, PSMOUSE_HGPK, &max_proto,
1071+
set_properties, true)) {
1072+
return PSMOUSE_HGPK;
10601073
}
10611074

10621075
/* Try Elantech touchpad */
10631076
if (max_proto > PSMOUSE_IMEX &&
1064-
psmouse_do_detect(elantech_detect, psmouse, set_properties) == 0) {
1065-
if (!set_properties || elantech_init(psmouse) == 0)
1066-
return PSMOUSE_ELANTECH;
1067-
/* Init failed, try basic relative protocols */
1068-
max_proto = PSMOUSE_IMEX;
1077+
psmouse_try_protocol(psmouse, PSMOUSE_ELANTECH,
1078+
&max_proto, set_properties, true)) {
1079+
return PSMOUSE_ELANTECH;
10691080
}
10701081

10711082
if (max_proto > PSMOUSE_IMEX) {
1072-
if (psmouse_do_detect(genius_detect,
1073-
psmouse, set_properties) == 0)
1083+
if (psmouse_try_protocol(psmouse, PSMOUSE_GENPS,
1084+
&max_proto, set_properties, true))
10741085
return PSMOUSE_GENPS;
10751086

1076-
if (psmouse_do_detect(ps2pp_init,
1077-
psmouse, set_properties) == 0)
1087+
if (psmouse_try_protocol(psmouse, PSMOUSE_PS2PP,
1088+
&max_proto, set_properties, true))
10781089
return PSMOUSE_PS2PP;
10791090

1080-
if (psmouse_do_detect(trackpoint_detect,
1081-
psmouse, set_properties) == 0)
1091+
if (psmouse_try_protocol(psmouse, PSMOUSE_TRACKPOINT,
1092+
&max_proto, set_properties, true))
10821093
return PSMOUSE_TRACKPOINT;
10831094

1084-
if (psmouse_do_detect(touchkit_ps2_detect,
1085-
psmouse, set_properties) == 0)
1095+
if (psmouse_try_protocol(psmouse, PSMOUSE_TOUCHKIT_PS2,
1096+
&max_proto, set_properties, true))
10861097
return PSMOUSE_TOUCHKIT_PS2;
10871098
}
10881099

10891100
/*
10901101
* Try Finger Sensing Pad. We do it here because its probe upsets
10911102
* Trackpoint devices (causing TP_READ_ID command to time out).
10921103
*/
1093-
if (max_proto > PSMOUSE_IMEX) {
1094-
if (psmouse_do_detect(fsp_detect,
1095-
psmouse, set_properties) == 0) {
1096-
if (!set_properties || fsp_init(psmouse) == 0)
1097-
return PSMOUSE_FSP;
1098-
/* Init failed, try basic relative protocols */
1099-
max_proto = PSMOUSE_IMEX;
1100-
}
1104+
if (max_proto > PSMOUSE_IMEX &&
1105+
psmouse_try_protocol(psmouse, PSMOUSE_FSP,
1106+
&max_proto, set_properties, true)) {
1107+
return PSMOUSE_FSP;
11011108
}
11021109

11031110
/*
@@ -1109,22 +1116,23 @@ static int psmouse_extensions(struct psmouse *psmouse,
11091116
psmouse_reset(psmouse);
11101117

11111118
if (max_proto >= PSMOUSE_IMEX &&
1112-
psmouse_do_detect(im_explorer_detect,
1113-
psmouse, set_properties) == 0) {
1119+
psmouse_try_protocol(psmouse, PSMOUSE_IMEX,
1120+
&max_proto, set_properties, true)) {
11141121
return PSMOUSE_IMEX;
11151122
}
11161123

11171124
if (max_proto >= PSMOUSE_IMPS &&
1118-
psmouse_do_detect(intellimouse_detect,
1119-
psmouse, set_properties) == 0) {
1125+
psmouse_try_protocol(psmouse, PSMOUSE_IMPS,
1126+
&max_proto, set_properties, true)) {
11201127
return PSMOUSE_IMPS;
11211128
}
11221129

11231130
/*
11241131
* Okay, all failed, we have a standard mouse here. The number of
11251132
* the buttons is still a question, though. We assume 3.
11261133
*/
1127-
psmouse_do_detect(ps2bare_detect, psmouse, set_properties);
1134+
psmouse_try_protocol(psmouse, PSMOUSE_PS2,
1135+
&max_proto, set_properties, true);
11281136

11291137
if (synaptics_hardware) {
11301138
/*

0 commit comments

Comments
 (0)