Re: Support for ALPS touchpads

2011-09-19 Thread Martin Pieuchot
On 15/09/11(Thu) 00:10, Alexandr Shadchin wrote:
 [...]
 
 Using { 0x7326, ALPS_UNSUPPORTED } is not best idea.
 
 Instead 
   if (alps-model  ALPS_UNSUPPORTED)
 use
   if (alps-model == 0)
 or even better
   #define ALPS_UNSUPPORTED 0
   ...
   if (alps-model == ALPS_UNSUPPORTED)
 
 If the device is not in alps_quirks, then it will automatically be
 ALPS_UNSUPPORTED. No need to register each device is not supported.

New version with a list of models.

Any regression with a Synaptics touchpad?


Index: pms.c
===
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.21
diff -u -p -r1.21 pms.c
--- pms.c   24 Aug 2011 15:34:25 -  1.21
+++ pms.c   19 Sep 2011 07:33:22 -
@@ -39,6 +39,12 @@
 #include dev/wscons/wsconsio.h
 #include dev/wscons/wsmousevar.h
 
+#ifdef DEBUG
+#define DPRINTF(x...)  do { printf(x); } while (0);
+#else
+#define DPRINTF(x...)
+#endif
+
 #define DEVNAME(sc)((sc)-sc_dev.dv_xname)
 
 #define WSMOUSE_BUTTON(x)  (1  ((x) - 1))
@@ -50,6 +56,7 @@ struct pms_protocol {
 #define PMS_STANDARD   0
 #define PMS_INTELLI1
 #define PMS_SYNAPTICS  2
+#define PMS_ALPS   3
u_int packetsize;
int (*enable)(struct pms_softc *);
int (*ioctl)(struct pms_softc *, u_long, caddr_t, int, struct proc *);
@@ -78,6 +85,20 @@ struct synaptics_softc {
 #define SYNAPTICS_PRESSURE 30
 };
 
+struct alps_softc {
+   int model;
+
+   int min_x, min_y;
+   int max_x, max_y;
+   int old_fin;
+
+   /* Compat mode */
+   int wsmode;
+   int old_x, old_y;
+   u_int old_buttons;
+#define ALPS_PRESSURE  40
+};
+
 struct pms_softc { /* driver status information */
struct device sc_dev;
 
@@ -98,6 +119,7 @@ struct pms_softc {   /* driver status inf
 
const struct pms_protocol *protocol;
struct synaptics_softc *synaptics;
+   struct alps_softc *alps;
 
u_char packet[8];
 
@@ -116,6 +138,33 @@ static const u_int butmap[8] = {
WSMOUSE_BUTTON(1) | WSMOUSE_BUTTON(2) | WSMOUSE_BUTTON(3)
 };
 
+static const struct alps_model {
+   int version;
+   int model;
+} alps_models[] = {
+   { 0x2021, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x2221, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x3222, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x5212, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x5321, ALPS_GLIDEPOINT },
+   { 0x5322, ALPS_GLIDEPOINT },
+   { 0x603b, ALPS_GLIDEPOINT },
+   { 0x6222, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x6321, ALPS_GLIDEPOINT },
+   { 0x6322, ALPS_GLIDEPOINT },
+   { 0x6323, ALPS_GLIDEPOINT },
+   { 0x6324, ALPS_GLIDEPOINT },
+   { 0x6325, ALPS_GLIDEPOINT },
+   { 0x6326, ALPS_GLIDEPOINT },
+   { 0x633b, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x7301, ALPS_DUALPOINT },
+   { 0x7321, ALPS_GLIDEPOINT },
+   { 0x7322, ALPS_GLIDEPOINT },
+   { 0x7325, ALPS_GLIDEPOINT },
+   { 0x7326, ALPS_UNSUPPORTED },   /* XXX Uses unknown v3 protocol */
+};
+
 intpmsprobe(struct device *, void *, void *);
 void   pmsattach(struct device *, struct device *, void *);
 intpmsactivate(struct device *, int);
@@ -150,6 +199,11 @@ intpms_sync_synaptics(struct pms_softc 
 void   pms_proc_synaptics(struct pms_softc *);
 void   pms_disable_synaptics(struct pms_softc *);
 
+intpms_enable_alps(struct pms_softc *);
+intpms_ioctl_alps(struct pms_softc *, u_long, caddr_t, int, struct proc *);
+intpms_sync_alps(struct pms_softc *, int);
+void   pms_proc_alps(struct pms_softc *);
+
 intsynaptics_set_mode(struct pms_softc *, int);
 intsynaptics_query(struct pms_softc *, int, int *);
 intsynaptics_get_hwinfo(struct pms_softc *);
@@ -160,6 +214,8 @@ int synaptics_pt_ioctl(void *, u_long, c
 intsynaptics_pt_enable(void *);
 void   synaptics_pt_disable(void *);
 
+intalps_get_hwinfo(struct pms_softc *);
+
 struct cfattach pms_ca = {
sizeof(struct pms_softc), pmsprobe, pmsattach, NULL,
pmsactivate
@@ -208,7 +264,16 @@ const struct pms_protocol pms_protocols[
pms_sync_synaptics,
pms_proc_synaptics,
pms_disable_synaptics
-   }
+   },
+   /* ALPS touchpad */
+   {
+   PMS_ALPS, 6,
+   pms_enable_alps,
+   pms_ioctl_alps,
+   pms_sync_alps,
+   pms_proc_alps,
+   NULL
+   },
 };
 
 int
@@ -483,6 +548,8 @@ pmsattach(struct device *parent, struct 
sc-protocol = pms_protocols[i];
}
 
+   DPRINTF(%s: protocol type %d\n, DEVNAME(sc), sc-protocol-type);
+
/* no interrupts until enabled */
pms_change_state(sc, PMS_STATE_DISABLED, PMS_DEV_IGNORE);
 }
@@ -965,4 +1032,238 @@ pms_disable_synaptics(struct pms_softc *
   

Re: Support for ALPS touchpads

2011-09-19 Thread Martin Pieuchot
On 19/09/11(Mon) 09:46, Martin Pieuchot wrote:
 On 15/09/11(Thu) 00:10, Alexandr Shadchin wrote:
  [...]
  
  Using { 0x7326, ALPS_UNSUPPORTED } is not best idea.
  
  Instead 
  if (alps-model  ALPS_UNSUPPORTED)
  use
  if (alps-model == 0)
  or even better
  #define ALPS_UNSUPPORTED 0
  ...
  if (alps-model == ALPS_UNSUPPORTED)
  
  If the device is not in alps_quirks, then it will automatically be
  ALPS_UNSUPPORTED. No need to register each device is not supported.
 
 New version with a list of models.
 
 Any regression with a Synaptics touchpad?

Apparently some Synaptics touchpads also respond to the ALPS query.

Updated diff below treats every device not listed in alps_models as
unsupported and should fix the regression.

Ok?

Index: pms.c
===
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.21
diff -u -p -r1.21 pms.c
--- pms.c   24 Aug 2011 15:34:25 -  1.21
+++ pms.c   19 Sep 2011 13:43:00 -
@@ -39,6 +39,12 @@
 #include dev/wscons/wsconsio.h
 #include dev/wscons/wsmousevar.h
 
+#ifdef DEBUG
+#define DPRINTF(x...)  do { printf(x); } while (0);
+#else
+#define DPRINTF(x...)
+#endif
+
 #define DEVNAME(sc)((sc)-sc_dev.dv_xname)
 
 #define WSMOUSE_BUTTON(x)  (1  ((x) - 1))
@@ -50,6 +56,7 @@ struct pms_protocol {
 #define PMS_STANDARD   0
 #define PMS_INTELLI1
 #define PMS_SYNAPTICS  2
+#define PMS_ALPS   3
u_int packetsize;
int (*enable)(struct pms_softc *);
int (*ioctl)(struct pms_softc *, u_long, caddr_t, int, struct proc *);
@@ -78,6 +85,21 @@ struct synaptics_softc {
 #define SYNAPTICS_PRESSURE 30
 };
 
+struct alps_softc {
+   int model;
+   int version;
+
+   int min_x, min_y;
+   int max_x, max_y;
+   int old_fin;
+
+   /* Compat mode */
+   int wsmode;
+   int old_x, old_y;
+   u_int old_buttons;
+#define ALPS_PRESSURE  40
+};
+
 struct pms_softc { /* driver status information */
struct device sc_dev;
 
@@ -98,6 +120,7 @@ struct pms_softc {   /* driver status inf
 
const struct pms_protocol *protocol;
struct synaptics_softc *synaptics;
+   struct alps_softc *alps;
 
u_char packet[8];
 
@@ -116,6 +139,35 @@ static const u_int butmap[8] = {
WSMOUSE_BUTTON(1) | WSMOUSE_BUTTON(2) | WSMOUSE_BUTTON(3)
 };
 
+static const struct alps_model {
+   int version;
+   int model;
+} alps_models[] = {
+   { 0x2021, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x2221, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x3222, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x5212, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x5321, ALPS_GLIDEPOINT },
+   { 0x5322, ALPS_GLIDEPOINT },
+   { 0x603b, ALPS_GLIDEPOINT },
+   { 0x6222, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x6321, ALPS_GLIDEPOINT },
+   { 0x6322, ALPS_GLIDEPOINT },
+   { 0x6323, ALPS_GLIDEPOINT },
+   { 0x6324, ALPS_GLIDEPOINT },
+   { 0x6325, ALPS_GLIDEPOINT },
+   { 0x6326, ALPS_GLIDEPOINT },
+   { 0x633b, ALPS_DUALPOINT | ALPS_PASSTHROUGH },
+   { 0x7301, ALPS_DUALPOINT },
+   { 0x7321, ALPS_GLIDEPOINT },
+   { 0x7322, ALPS_GLIDEPOINT },
+   { 0x7325, ALPS_GLIDEPOINT },
+#if 0
+   { 0x7326, 0 },  /* XXX Uses unknown v3 protocol */
+#endif
+};
+
 intpmsprobe(struct device *, void *, void *);
 void   pmsattach(struct device *, struct device *, void *);
 intpmsactivate(struct device *, int);
@@ -150,6 +202,11 @@ intpms_sync_synaptics(struct pms_softc 
 void   pms_proc_synaptics(struct pms_softc *);
 void   pms_disable_synaptics(struct pms_softc *);
 
+intpms_enable_alps(struct pms_softc *);
+intpms_ioctl_alps(struct pms_softc *, u_long, caddr_t, int, struct proc *);
+intpms_sync_alps(struct pms_softc *, int);
+void   pms_proc_alps(struct pms_softc *);
+
 intsynaptics_set_mode(struct pms_softc *, int);
 intsynaptics_query(struct pms_softc *, int, int *);
 intsynaptics_get_hwinfo(struct pms_softc *);
@@ -160,6 +217,8 @@ int synaptics_pt_ioctl(void *, u_long, c
 intsynaptics_pt_enable(void *);
 void   synaptics_pt_disable(void *);
 
+intalps_get_hwinfo(struct pms_softc *);
+
 struct cfattach pms_ca = {
sizeof(struct pms_softc), pmsprobe, pmsattach, NULL,
pmsactivate
@@ -208,7 +267,16 @@ const struct pms_protocol pms_protocols[
pms_sync_synaptics,
pms_proc_synaptics,
pms_disable_synaptics
-   }
+   },
+   /* ALPS touchpad */
+   {
+   PMS_ALPS, 6,
+   pms_enable_alps,
+   pms_ioctl_alps,
+   pms_sync_alps,
+   pms_proc_alps,
+   NULL
+   },
 };
 
 int
@@ -483,6 +551,8 @@ pmsattach(struct device *parent, struct 
sc-protocol = pms_protocols[i];
  

Re: Support for ALPS touchpads

2011-09-14 Thread Alexandr Shadchin
On Tue, Sep 06, 2011 at 02:25:47PM +0200, Martin Pieuchot wrote:
 On 04/09/11(Sun) 21:36, Martin Pieuchot wrote:
  The diff below adds support for ALPS touchpads to the pms(4) driver.
  
  I'm looking for testers with or without ALPS hardware, especially if you
  have a touchpad, to be sure it doesn't break anything.
  
  Currently, ALPS DualPoint are untested and support for special buttons
  (back, forward, etc) is missing because I don't have such hardware.
  
  I use the following synaptics(4) configuration for edge scrolling and
  simple left tapping:
  
  xinput set-prop /dev/wsmouse0 Synaptics Finger 25 30 60
  xinput set-int-prop /dev/wsmouse0 Synaptics Tap Action 8 0 0 2 3 1 0 0
  xinput set-int-prop /dev/wsmouse0 Synaptics Click Action 8 1 0 0
  xinput set-int-prop /dev/wsmouse0 Synaptics Edge Scrolling 8 1 0 0
  
  
  Compared to the previous version, I left the Y-axis translation because
  it's also needed for the COMPAT mode.
 
 New version of the diff. Recent ALPS touchpads use a totally different
 protocol and are not supported.
 
 Martin
 
 Index: pms.c
 ===
 RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
 retrieving revision 1.21
 diff -u -p -r1.21 pms.c
 --- pms.c 24 Aug 2011 15:34:25 -  1.21
 +++ pms.c 6 Sep 2011 09:19:24 -
 @@ -39,6 +39,14 @@
  #include dev/wscons/wsconsio.h
  #include dev/wscons/wsmousevar.h
  
 +#define DEBUG
 +
 +#ifdef DEBUG
 +#define DPRINTF(x...)do { printf(x); } while (0);
 +#else
 +#define DPRINTF(x...)
 +#endif
 +
  #define DEVNAME(sc)  ((sc)-sc_dev.dv_xname)
  
  #define WSMOUSE_BUTTON(x)(1  ((x) - 1))
 @@ -50,6 +58,7 @@ struct pms_protocol {
  #define PMS_STANDARD 0
  #define PMS_INTELLI  1
  #define PMS_SYNAPTICS2
 +#define PMS_ALPS 3
   u_int packetsize;
   int (*enable)(struct pms_softc *);
   int (*ioctl)(struct pms_softc *, u_long, caddr_t, int, struct proc *);
 @@ -78,6 +87,22 @@ struct synaptics_softc {
  #define SYNAPTICS_PRESSURE   30
  };
  
 +struct alps_softc {
 + int model;
 +#define ALPS_UNSUPPORTED (1  1)
 +#define ALPS_PASSTHROUGH (1  2)
 +
 + int min_x, min_y;
 + int max_x, max_y;
 + int old_fin;
 +
 + /* Compat mode */
 + int wsmode;
 + int old_x, old_y;
 + u_int old_buttons;
 +#define ALPS_PRESSURE40
 +};
 +
  struct pms_softc {   /* driver status information */
   struct device sc_dev;
  
 @@ -98,6 +123,7 @@ struct pms_softc { /* driver status inf
  
   const struct pms_protocol *protocol;
   struct synaptics_softc *synaptics;
 + struct alps_softc *alps;
  
   u_char packet[8];
  
 @@ -116,6 +142,20 @@ static const u_int butmap[8] = {
   WSMOUSE_BUTTON(1) | WSMOUSE_BUTTON(2) | WSMOUSE_BUTTON(3)
  };
  
 +static const struct alps_quirk {
 + int version;
 + int model;
 +} alps_quirks[] = {
 + { 0x2021, ALPS_PASSTHROUGH },
 + { 0x2221, ALPS_PASSTHROUGH },
 + { 0x, ALPS_PASSTHROUGH },
 + { 0x3222, ALPS_PASSTHROUGH },
 + { 0x5212, ALPS_PASSTHROUGH },
 + { 0x6222, ALPS_PASSTHROUGH },
 + { 0x633b, ALPS_PASSTHROUGH },
 + { 0x7326, ALPS_UNSUPPORTED },   /* XXX Uses unknown v3 protocol */
 +};

Using { 0x7326, ALPS_UNSUPPORTED } is not best idea.

Instead 
if (alps-model  ALPS_UNSUPPORTED)
use
if (alps-model == 0)
or even better
#define ALPS_UNSUPPORTED 0
...
if (alps-model == ALPS_UNSUPPORTED)

If the device is not in alps_quirks, then it will automatically be
ALPS_UNSUPPORTED. No need to register each device is not supported.

 +
  int  pmsprobe(struct device *, void *, void *);
  void pmsattach(struct device *, struct device *, void *);
  int  pmsactivate(struct device *, int);
 @@ -150,6 +190,11 @@ int  pms_sync_synaptics(struct pms_softc 
  void pms_proc_synaptics(struct pms_softc *);
  void pms_disable_synaptics(struct pms_softc *);
  
 +int  pms_enable_alps(struct pms_softc *);
 +int  pms_ioctl_alps(struct pms_softc *, u_long, caddr_t, int, struct proc *);
 +int  pms_sync_alps(struct pms_softc *, int);
 +void pms_proc_alps(struct pms_softc *);
 +
  int  synaptics_set_mode(struct pms_softc *, int);
  int  synaptics_query(struct pms_softc *, int, int *);
  int  synaptics_get_hwinfo(struct pms_softc *);
 @@ -160,6 +205,8 @@ int   synaptics_pt_ioctl(void *, u_long, c
  int  synaptics_pt_enable(void *);
  void synaptics_pt_disable(void *);
  
 +int  alps_get_hwinfo(struct pms_softc *);
 +
  struct cfattach pms_ca = {
   sizeof(struct pms_softc), pmsprobe, pmsattach, NULL,
   pmsactivate
 @@ -208,7 +255,16 @@ const struct pms_protocol pms_protocols[
   pms_sync_synaptics,
   pms_proc_synaptics,
   pms_disable_synaptics
 - }
 + },
 + /* ALPS touchpad */
 + {
 + PMS_ALPS, 6,
 + pms_enable_alps,
 + pms_ioctl_alps,
 + pms_sync_alps,
 +