[PATCH synaptics 2/4] Add a Debug Level property for run-time debugging

Peter Hutterer peter.hutterer at who-t.net
Tue Mar 13 22:06:56 PDT 2012


And fix the current DBG macro to also print the function name.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 include/synaptics-properties.h |    5 +++
 man/synaptics.man              |   12 +++++++-
 src/properties.c               |   14 +++++++++
 src/ps2comm.c                  |   25 ++++++++-------
 src/synaptics.c                |   63 +++++++++++++++++++++------------------
 src/synapticsstr.h             |   12 ++++++--
 tools/synclient.c              |    1 +
 7 files changed, 87 insertions(+), 45 deletions(-)

diff --git a/include/synaptics-properties.h b/include/synaptics-properties.h
index 8c20a0c..a379b40 100644
--- a/include/synaptics-properties.h
+++ b/include/synaptics-properties.h
@@ -164,4 +164,9 @@
 /* 32 Bit Integer, 2 values, horizontal hysteresis, vertical hysteresis */
 #define SYNAPTICS_PROP_NOISE_CANCELLATION "Synaptics Noise Cancellation"
 
+/* 8 Bit integer, 1 value [0..10], maximum debug verbosity level to print to log */
+#ifdef DEBUG
+#define SYNAPTICS_PROP_DEBUG_LEVEL "Synaptics Debug Level"
+#endif
+
 #endif /* _SYNAPTICS_PROPERTIES_H_ */
diff --git a/man/synaptics.man b/man/synaptics.man
index 23862e3..18c7035 100644
--- a/man/synaptics.man
+++ b/man/synaptics.man
@@ -533,7 +533,13 @@ or middle click action is performed.
 The use of soft button areas is disabled by setting all the values for the area
 to 0. Property: "Synaptics Soft Button Areas"
 .
-
+.TP
+.BI "Option \*qDebugLevel\*q \*q" integer \*q
+This option is only available if the driver was built with debugging
+enabled. Accepts a value of 0 (no debug messages) to 10 (all debug
+messages), any debug messages with less or equal verbosity are printed to
+the log. Property: "Synaptics Debug Level"
+.
 .SH CONFIGURATION DETAILS
 .SS Area handling
 The LeftEdge, RightEdge, TopEdge and BottomEdge parameters are used to
@@ -963,6 +969,10 @@ right button, two-finger detection, three-finger detection, pressure detection,
 .BI "Synaptics Pad Resolution"
 32 bit unsigned, 2 values (read-only), vertical, horizontal in units/millimeter.
 
+.TP 7
+.BI "Synaptics Debug Level"
+8 bit unsigned, 1 value [0..1], debug message verbosity.
+
 .SH "NOTES"
 Configuration through
 .I InputClass
diff --git a/src/properties.c b/src/properties.c
index 783b516..021621e 100644
--- a/src/properties.c
+++ b/src/properties.c
@@ -96,6 +96,7 @@ Atom prop_softbutton_areas      = 0;
 Atom prop_noise_cancellation    = 0;
 Atom prop_product_id            = 0;
 Atom prop_device_node           = 0;
+Atom prop_debug                 = 0;
 
 static Atom
 InitTypedAtom(DeviceIntPtr dev, char *name, Atom type, int format, int nvalues,
@@ -344,6 +345,11 @@ InitDeviceProperties(InputInfoPtr pInfo)
         XISetDevicePropertyDeletable(pInfo->dev, prop_device_node, FALSE);
     }
 
+#ifdef DEBUG
+    values[0] = priv->debug_level;
+    prop_debug = InitAtom(pInfo->dev, SYNAPTICS_PROP_DEBUG_LEVEL, 8, 1, values);
+#endif
+
 }
 
 int
@@ -767,6 +773,14 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
             return BadValue;
         para->hyst_x = hyst[0];
         para->hyst_y = hyst[1];
+#ifdef DEBUG
+    } else if (property == prop_debug)
+    {
+        if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER)
+            return BadMatch;
+
+        priv->debug_level = max(min(*(INT8*)prop->data, 10), 0);
+#endif
     } else if (property == prop_product_id || property == prop_device_node)
         return BadValue; /* read-only */
 
diff --git a/src/ps2comm.c b/src/ps2comm.c
index 63022c0..df53604 100644
--- a/src/ps2comm.c
+++ b/src/ps2comm.c
@@ -426,28 +426,28 @@ PS2QueryHardware(InputInfoPtr pInfo)
  * Decide if the current packet stored in priv->protoBuf is valid.
  */
 static Bool
-ps2_packet_ok(struct PS2SynapticsHwInfo *synhw, struct CommData *comm)
+ps2_packet_ok(SynapticsPrivate *priv, struct PS2SynapticsHwInfo *synhw, struct CommData *comm)
 {
     unsigned char *buf = comm->protoBuf;
     int newabs = SYN_MODEL_NEWABS(synhw);
 
     if (newabs ? ((buf[0] & 0xC0) != 0x80) : ((buf[0] & 0xC0) != 0xC0)) {
-	DBG(4, "Synaptics driver lost sync at 1st byte\n");
+	DBG(priv, 4, "Synaptics driver lost sync at 1st byte\n");
 	return FALSE;
     }
 
     if (!newabs && ((buf[1] & 0x60) != 0x00)) {
-	DBG(4, "Synaptics driver lost sync at 2nd byte\n");
+	DBG(priv, 4, "Synaptics driver lost sync at 2nd byte\n");
 	return FALSE;
     }
 
     if ((newabs ? ((buf[3] & 0xC0) != 0xC0) : ((buf[3] & 0xC0) != 0x80))) {
-	DBG(4, "Synaptics driver lost sync at 4th byte\n");
+	DBG(priv, 4, "Synaptics driver lost sync at 4th byte\n");
 	return FALSE;
     }
 
     if (!newabs && ((buf[4] & 0x60) != 0x00)) {
-	DBG(4, "Synaptics driver lost sync at 5th byte\n");
+	DBG(priv, 4, "Synaptics driver lost sync at 5th byte\n");
 	return FALSE;
     }
 
@@ -462,6 +462,7 @@ ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
     int count = 0;
     int c;
     unsigned char u;
+    SynapticsPrivate *priv = pInfo->private;
 
     while ((c = XisbRead(comm->buffer)) >= 0) {
 	u = (unsigned char)c;
@@ -469,10 +470,10 @@ ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
 	/* test if there is a reset sequence received */
 	if ((c == 0x00) && (comm->lastByte == 0xAA)) {
 	    if (xf86WaitForInput(pInfo->fd, 50000) == 0) {
-		DBG(7, "Reset received\n");
+		DBG(priv, 7, "Reset received\n");
 		proto_ops->QueryHardware(pInfo);
 	    } else
-		DBG(3, "faked reset received\n");
+		DBG(priv, 3, "faked reset received\n");
 	}
 	comm->lastByte = u;
 
@@ -487,7 +488,7 @@ ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
 	/* Check that we have a valid packet. If not, we are out of sync,
 	   so we throw away the first byte in the packet.*/
 	if (comm->protoBufTail >= 6) {
-	    if (!ps2_packet_ok(synhw, comm)) {
+	    if (!ps2_packet_ok(priv, synhw, comm)) {
 		int i;
 		for (i = 0; i < comm->protoBufTail - 1; i++)
 		    comm->protoBuf[i] = comm->protoBuf[i + 1];
@@ -495,7 +496,7 @@ ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
 		comm->outOfSync++;
 		if (comm->outOfSync > MAX_UNSYNC_PACKETS) {
 		    comm->outOfSync = 0;
-		    DBG(3, "Synaptics synchronization lost too long -> reset touchpad.\n");
+		    DBG(priv, 3, "Synaptics synchronization lost too long -> reset touchpad.\n");
 		    proto_ops->QueryHardware(pInfo); /* including a reset */
 		    continue;
 		}
@@ -505,7 +506,7 @@ ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
 	if (comm->protoBufTail >= 6) { /* Full packet received */
 	    if (comm->outOfSync > 0) {
 		comm->outOfSync = 0;
-		DBG(4, "Synaptics driver resynced.\n");
+		DBG(priv, 4, "Synaptics driver resynced.\n");
 	    }
 	    comm->protoBufTail = 0;
 	    return TRUE;
@@ -548,7 +549,7 @@ PS2ReadHwStateProto(InputInfoPtr pInfo,
 	hw->multi[i] = FALSE;
 
     if (newabs) {			    /* newer protos...*/
-	DBG(7, "using new protocols\n");
+	DBG(priv, 7, "using new protocols\n");
 	hw->x = (((buf[3] & 0x10) << 8) |
 		 ((buf[1] & 0x0f) << 8) |
 		 buf[4]);
@@ -598,7 +599,7 @@ PS2ReadHwStateProto(InputInfoPtr pInfo,
 	    }
 	}
     } else {			    /* old proto...*/
-	DBG(7, "using old protocol\n");
+	DBG(priv, 7, "using old protocol\n");
 	hw->x = (((buf[1] & 0x1F) << 8) |
 		 buf[2]);
 	hw->y = (((buf[4] & 0x1F) << 8) |
diff --git a/src/synaptics.c b/src/synaptics.c
index 09afb7c..1d280ca 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -854,6 +854,10 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
     if (!priv)
 	return BadAlloc;
 
+#ifdef DEBUG
+    priv->debug_level = xf86SetIntOption(pInfo->options, "DebugLevel", 0);
+#endif
+
     pInfo->type_name               = XI_TOUCHPAD;
     pInfo->device_control          = DeviceControl;
     pInfo->read_input              = ReadInput;
@@ -1011,7 +1015,7 @@ DeviceOn(DeviceIntPtr dev)
     InputInfoPtr pInfo = dev->public.devicePrivate;
     SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
 
-    DBG(3, "Synaptics DeviceOn called\n");
+    DBG(priv, 3, "Synaptics DeviceOn called\n");
 
     pInfo->fd = xf86OpenSerial(pInfo->options);
     if (pInfo->fd == -1) {
@@ -1055,7 +1059,7 @@ DeviceOff(DeviceIntPtr dev)
     SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
     Bool rc = Success;
 
-    DBG(3, "Synaptics DeviceOff called\n");
+    DBG(priv, 3, "Synaptics DeviceOff called\n");
 
     if (pInfo->fd != -1) {
 	TimerCancel(priv->timer);
@@ -1239,7 +1243,7 @@ DeviceInit(DeviceIntPtr dev)
     InitAxesLabels(axes_labels, num_axes, priv);
     InitButtonLabels(btn_labels, SYN_MAX_BUTTONS);
 
-    DBG(3, "Synaptics DeviceInit called\n");
+    DBG(priv, 3, "Synaptics DeviceInit called\n");
 
     for (i = 0; i <= SYN_MAX_BUTTONS; i++)
 	map[i] = i;
@@ -1776,33 +1780,33 @@ SelectTapButton(SynapticsPrivate *priv, edge_type edge)
     default:
 	switch (edge) {
 	case RIGHT_TOP_EDGE:
-	    DBG(7, "right top edge\n");
+	    DBG(priv, 7, "right top edge\n");
 	    tap = RT_TAP;
 	    break;
 	case RIGHT_BOTTOM_EDGE:
-	    DBG(7, "right bottom edge\n");
+	    DBG(priv, 7, "right bottom edge\n");
 	    tap = RB_TAP;
 	    break;
 	case LEFT_TOP_EDGE:
-	    DBG(7, "left top edge\n");
+	    DBG(priv, 7, "left top edge\n");
 	    tap = LT_TAP;
 	    break;
 	case LEFT_BOTTOM_EDGE:
-	    DBG(7, "left bottom edge\n");
+	    DBG(priv, 7, "left bottom edge\n");
 	    tap = LB_TAP;
 	    break;
 	default:
-	    DBG(7, "no edge\n");
+	    DBG(priv, 7, "no edge\n");
 	    tap = F1_TAP;
 	    break;
 	}
 	break;
     case 2:
-	DBG(7, "two finger tap\n");
+	DBG(priv, 7, "two finger tap\n");
 	tap = F2_TAP;
 	break;
     case 3:
-	DBG(7, "three finger tap\n");
+	DBG(priv, 7, "three finger tap\n");
 	tap = F3_TAP;
 	break;
     }
@@ -1815,7 +1819,7 @@ static void
 SetTapState(SynapticsPrivate *priv, enum TapState tap_state, CARD32 millis)
 {
     SynapticsParameters *para = &priv->synpara;
-    DBG(7, "SetTapState - %d -> %d (millis:%d)\n", priv->tap_state, tap_state, millis);
+    DBG(priv, 7, "SetTapState - %d -> %d (millis:%d)\n", priv->tap_state, tap_state, millis);
     switch (tap_state) {
     case TS_START:
 	priv->tap_button_state = TBS_BUTTON_UP;
@@ -1855,7 +1859,7 @@ SetTapState(SynapticsPrivate *priv, enum TapState tap_state, CARD32 millis)
 static void
 SetMovingState(SynapticsPrivate *priv, enum MovingState moving_state, CARD32 millis)
 {
-    DBG(7, "SetMovingState - %d -> %d center at %d/%d (millis:%d)\n", priv->moving_state,
+    DBG(priv, 7, "SetMovingState - %d -> %d center at %d/%d (millis:%d)\n", priv->moving_state,
 		  moving_state,priv->hwState->x, priv->hwState->y, millis);
 
     if (moving_state == MS_TRACKSTICK) {
@@ -2385,7 +2389,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		priv->circ_scroll_on = TRUE;
 		priv->circ_scroll_vert = TRUE;
 		priv->scroll.last_a = angle(priv, hw->x, hw->y);
-		DBG(7, "circular scroll detected on edge\n");
+		DBG(priv, 7, "circular scroll detected on edge\n");
 	    }
 	}
     }
@@ -2397,14 +2401,14 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		    priv->vert_scroll_twofinger_on = TRUE;
 		    priv->vert_scroll_edge_on = FALSE;
 		    priv->scroll.last_y = hw->y;
-		    DBG(7, "vert two-finger scroll detected\n");
+		    DBG(priv, 7, "vert two-finger scroll detected\n");
 		}
 		if (!priv->horiz_scroll_twofinger_on &&
 		    (para->scroll_twofinger_horiz) && (para->scroll_dist_horiz != 0)) {
 		    priv->horiz_scroll_twofinger_on = TRUE;
 		    priv->horiz_scroll_edge_on = FALSE;
 		    priv->scroll.last_x = hw->x;
-		    DBG(7, "horiz two-finger scroll detected\n");
+		    DBG(priv, 7, "horiz two-finger scroll detected\n");
 		}
 	    }
 	}
@@ -2414,13 +2418,13 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		    (edge & RIGHT_EDGE)) {
 		    priv->vert_scroll_edge_on = TRUE;
 		    priv->scroll.last_y = hw->y;
-		    DBG(7, "vert edge scroll detected on right edge\n");
+		    DBG(priv, 7, "vert edge scroll detected on right edge\n");
 		}
 		if ((para->scroll_edge_horiz) && (para->scroll_dist_horiz != 0) &&
 		    (edge & BOTTOM_EDGE)) {
 		    priv->horiz_scroll_edge_on = TRUE;
 		    priv->scroll.last_x = hw->x;
-		    DBG(7, "horiz edge scroll detected on bottom edge\n");
+		    DBG(priv, 7, "horiz edge scroll detected on bottom edge\n");
 		}
 	    }
 	}
@@ -2436,27 +2440,27 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 
 	if (priv->circ_scroll_on && !finger) {
 	    /* circular scroll locks in until finger is raised */
-	    DBG(7, "cicular scroll off\n");
+	    DBG(priv, 7, "cicular scroll off\n");
 	    priv->circ_scroll_on = FALSE;
 	}
 
 	if (!finger || hw->numFingers != 2) {
 	    if (priv->vert_scroll_twofinger_on) {
-		DBG(7, "vert two-finger scroll off\n");
+		DBG(priv, 7, "vert two-finger scroll off\n");
 		priv->vert_scroll_twofinger_on = FALSE;
 	    }
 	    if (priv->horiz_scroll_twofinger_on) {
-		DBG(7, "horiz two-finger scroll off\n");
+		DBG(priv, 7, "horiz two-finger scroll off\n");
 		priv->horiz_scroll_twofinger_on = FALSE;
 	    }
 	}
 
 	if (priv->vert_scroll_edge_on && (!(edge & RIGHT_EDGE) || !finger)) {
-	    DBG(7, "vert edge scroll off\n");
+	    DBG(priv, 7, "vert edge scroll off\n");
 	    priv->vert_scroll_edge_on = FALSE;
 	}
 	if (priv->horiz_scroll_edge_on && (!(edge & BOTTOM_EDGE) || !finger)) {
-	    DBG(7, "horiz edge scroll off\n");
+	    DBG(priv, 7, "horiz edge scroll off\n");
 	    priv->horiz_scroll_edge_on = FALSE;
 	}
 	/* If we were corner edge scrolling (coasting),
@@ -2466,7 +2470,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		((edge & RIGHT_EDGE)  && (edge & (TOP_EDGE | BOTTOM_EDGE))) ||
 		((edge & BOTTOM_EDGE) && (edge & (LEFT_EDGE | RIGHT_EDGE))) ;
 	    if (!is_in_corner || !finger) {
-		DBG(7, "corner edge scroll off\n");
+		DBG(priv, 7, "corner edge scroll off\n");
 		stop_coasting(priv);
 	    }
 	}
@@ -2495,7 +2499,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		/* FYI: We can generate multiple start_coasting requests if
 		 * we're in the corner, but we were moving so slowly when we
 		 * got here that we didn't actually start coasting. */
-		DBG(7, "corner edge scroll on\n");
+		DBG(priv, 7, "corner edge scroll on\n");
 		start_coasting(priv, hw, TRUE, FALSE, FALSE);
 	    }
 	} else if (para->circular_scrolling) {
@@ -2503,7 +2507,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 	    priv->circ_scroll_on = TRUE;
 	    priv->circ_scroll_vert = TRUE;
 	    priv->scroll.last_a = angle(priv, hw->x, hw->y);
-	    DBG(7, "switching to circular scrolling\n");
+	    DBG(priv, 7, "switching to circular scrolling\n");
 	}
     }
     /* Same treatment for horizontal scrolling */
@@ -2514,7 +2518,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 		/* FYI: We can generate multiple start_coasting requests if
 		 * we're in the corner, but we were moving so slowly when we
 		 * got here that we didn't actually start coasting. */
-		DBG(7, "corner edge scroll on\n");
+		DBG(priv, 7, "corner edge scroll on\n");
 		start_coasting(priv, hw, FALSE, TRUE, FALSE);
 	    }
 	} else if (para->circular_scrolling) {
@@ -2522,7 +2526,7 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 	    priv->circ_scroll_on = TRUE;
 	    priv->circ_scroll_vert = FALSE;
 	    priv->scroll.last_a = angle(priv, hw->x, hw->y);
-	    DBG(7, "switching to circular scrolling\n");
+	    DBG(priv, 7, "switching to circular scrolling\n");
 	}
     }
 
@@ -3242,7 +3246,8 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
 static int
 ControlProc(InputInfoPtr pInfo, xDeviceCtl * control)
 {
-    DBG(3, "Control Proc called\n");
+    SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
+    DBG(priv, 3, "Control Proc called\n");
     return Success;
 }
 
@@ -3253,7 +3258,7 @@ SwitchMode(ClientPtr client, DeviceIntPtr dev, int mode)
     InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate;
     SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
 
-    DBG(3, "SwitchMode called\n");
+    DBG(priv, 3, "SwitchMode called\n");
 
     switch (mode) {
     case Absolute:
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index fcefc46..fa7356e 100644
--- a/src/synapticsstr.h
+++ b/src/synapticsstr.h
@@ -30,10 +30,15 @@
 #endif
 
 #ifdef DEBUG
-#define DBG(verb, ...) \
-    xf86MsgVerb(X_INFO, verb, __VA_ARGS__)
+#define DBG(priv, verb, ...) \
+    do { \
+        if (priv->debug_level >= verb) { \
+            xf86Msg(X_INFO, "%d %s: ", verb, __func__); \
+            xf86Msg(X_NONE, __VA_ARGS__); \
+        } \
+    }  while (0)
 #else
-#define DBG(verb, msg, ...) /* */
+#define DBG(priv, verb, msg, ...) /* */
 #endif
 
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
@@ -291,6 +296,7 @@ struct _SynapticsPrivateRec
     int *open_slots;                    /* Array of currently open touch slots */
     int num_active_touches;             /* Number of active touches on device */
 #endif
+    int debug_level;                        /* debug verbosity */
 };
 
 #endif /* _SYNAPTICSSTR_H_ */
diff --git a/tools/synclient.c b/tools/synclient.c
index 942312a..2c3e8ca 100644
--- a/tools/synclient.c
+++ b/tools/synclient.c
@@ -154,6 +154,7 @@ static struct Parameter params[] = {
     {"MiddleButtonAreaRight", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS,	32,	5},
     {"MiddleButtonAreaTop",   PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS,	32,	6},
     {"MiddleButtonAreaBottom", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS,	32,	7},
+    {"DebugLevel",            PT_INT, 0, 10, SYNAPTICS_PROP_DEBUG_LEVEL,	8,	0},
     { NULL, 0, 0, 0, 0 }
 };
 
-- 
1.7.7.6



More information about the xorg-devel mailing list