Commit dce6006f authored by Alexandr Shadchin's avatar Alexandr Shadchin Committed by Peter Hutterer

Rewrite mechanisn to detect Protocol and Device

Made SetDeviceAndProtocol() does not depend on the protocols,
it will make it easier to add new backend.

New behavior SetDeviceAndProtocol:
1) If not set Device or Protocol, then try AutoDevProbe
2) Otherwise, look for the appropriate protocol (Device and Protocol must be set)
Signed-off-by: default avatarAlexandr Shadchin <Alexandr.Shadchin@gmail.com>
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent ae19da12
......@@ -220,17 +220,11 @@ ALPSReadHwState(InputInfoPtr pInfo,
return TRUE;
}
static Bool
ALPSAutoDevProbe(InputInfoPtr pInfo)
{
return FALSE;
}
struct SynapticsProtocolOperations alps_proto_operations = {
NULL,
NULL,
ALPSQueryHardware,
ALPSReadHwState,
ALPSAutoDevProbe,
NULL,
NULL
};
......@@ -660,17 +660,11 @@ PS2ReadHwState(InputInfoPtr pInfo,
return PS2ReadHwStateProto(pInfo, &psaux_proto_operations, comm, hwRet);
}
static Bool
PS2AutoDevProbe(InputInfoPtr pInfo)
{
return FALSE;
}
struct SynapticsProtocolOperations psaux_proto_operations = {
NULL,
PS2DeviceOffHook,
PS2QueryHardware,
PS2ReadHwState,
PS2AutoDevProbe,
NULL,
NULL
};
......@@ -162,16 +162,11 @@ PSMReadHwState(InputInfoPtr pInfo,
return PS2ReadHwStateProto(pInfo, &psm_proto_operations, comm, hwRet);
}
static Bool PSMAutoDevProbe(InputInfoPtr pInfo)
{
return FALSE;
}
struct SynapticsProtocolOperations psm_proto_operations = {
NULL,
NULL,
PSMQueryHardware,
PSMReadHwState,
PSMAutoDevProbe,
NULL,
NULL
};
......@@ -136,6 +136,21 @@ void InitDeviceProperties(InputInfoPtr pInfo);
int SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
BOOL checkonly);
const static struct {
const char *name;
struct SynapticsProtocolOperations *proto_ops;
} protocols[] = {
#ifdef BUILD_EVENTCOMM
{"event", &event_proto_operations},
#endif
#ifdef BUILD_PSMCOMM
{"psm", &psm_proto_operations},
#endif
{"psaux", &psaux_proto_operations},
{"alps", &alps_proto_operations},
{NULL, NULL}
};
InputDriverRec SYNAPTICS = {
1,
"synaptics",
......@@ -235,61 +250,24 @@ SanitizeDimensions(InputInfoPtr pInfo)
static void
SetDeviceAndProtocol(InputInfoPtr pInfo)
{
char *str_par, *device;
SynapticsPrivate *priv = pInfo->private;
enum SynapticsProtocol proto = SYN_PROTO_PSAUX;
char *proto, *device;
int i;
proto = xf86SetStrOption(pInfo->options, "Protocol", NULL);
device = xf86SetStrOption(pInfo->options, "Device", NULL);
if (!device) {
device = xf86SetStrOption(pInfo->options, "Path", NULL);
if (device) {
pInfo->options =
xf86ReplaceStrOption(pInfo->options, "Device", device);
}
}
if (device && strstr(device, "/dev/input/event")) {
#ifdef BUILD_EVENTCOMM
proto = SYN_PROTO_EVENT;
#endif
} else {
str_par = xf86FindOptionValue(pInfo->options, "Protocol");
if (str_par && !strcmp(str_par, "psaux")) {
/* Already set up */
#ifdef BUILD_EVENTCOMM
} else if (str_par && !strcmp(str_par, "event")) {
proto = SYN_PROTO_EVENT;
#endif /* BUILD_EVENTCOMM */
#ifdef BUILD_PSMCOMM
} else if (str_par && !strcmp(str_par, "psm")) {
proto = SYN_PROTO_PSM;
#endif /* BUILD_PSMCOMM */
} else if (str_par && !strcmp(str_par, "alps")) {
proto = SYN_PROTO_ALPS;
} else { /* default to auto-dev */
#ifdef BUILD_EVENTCOMM
if (!device && event_proto_operations.AutoDevProbe(pInfo))
proto = SYN_PROTO_EVENT;
#endif
}
}
switch (proto) {
case SYN_PROTO_PSAUX:
priv->proto_ops = &psaux_proto_operations;
break;
#ifdef BUILD_EVENTCOMM
case SYN_PROTO_EVENT:
priv->proto_ops = &event_proto_operations;
break;
#endif /* BUILD_EVENTCOMM */
#ifdef BUILD_PSMCOMM
case SYN_PROTO_PSM:
priv->proto_ops = &psm_proto_operations;
break;
#endif /* BUILD_PSMCOMM */
case SYN_PROTO_ALPS:
priv->proto_ops = &alps_proto_operations;
break;
for (i = 0; protocols[i].name; i++) {
if ((!device || !proto) &&
protocols[i].proto_ops->AutoDevProbe &&
protocols[i].proto_ops->AutoDevProbe(pInfo))
break;
else if (proto && !strcmp(proto, protocols[i].name))
break;
}
free(proto);
free(device);
priv->proto_ops = protocols[i].proto_ops;
}
/*
......@@ -714,6 +692,10 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
/* may change pInfo->options */
SetDeviceAndProtocol(pInfo);
if (priv->proto_ops == NULL) {
xf86Msg(X_ERROR, "Synaptics driver unable to detect protocol\n");
goto SetupProc_fail;
}
/* open the touchpad device */
pInfo->fd = xf86OpenSerial(pInfo->options);
......
......@@ -67,17 +67,6 @@ struct CommData {
Bool threeFingers;
};
enum SynapticsProtocol {
SYN_PROTO_PSAUX, /* Raw psaux device */
#ifdef BUILD_EVENTCOMM
SYN_PROTO_EVENT, /* Linux kernel event interface */
#endif /* BUILD_EVENTCOMM */
#ifdef BUILD_PSMCOMM
SYN_PROTO_PSM, /* FreeBSD psm driver */
#endif /* BUILD_PSMCOMM */
SYN_PROTO_ALPS /* ALPS touchpad protocol */
};
struct _SynapticsParameters;
struct SynapticsProtocolOperations {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment