Skip to contentSkip to conversation

PATCH 2.6.11-rc4]: IBM TrackPoint configuration support

PATCH Stephen Evanchik 3 participants 5 messages Feb 14, 2005 – Feb 16, 2005 Input drivers

lore
Share & tools
lore
#0 lore raw

Here is the latest IBM TrackPoint patch. I believe I made all of the necessary changes in this release including the removal of the middle-to-scroll functionality. One item I didn't address was a comment about checking the return code of ps2_command ..

I looked at other usages and it wasn't clear to me how to actually implement something that is sane. In some places an error causes a return out of the function and in others the return value is ignored. Should I check each return value or the first ?

Any comments are greatly appreciated. I have tested this on my T23 as well as a T40 and T42p ..

Stephen

drivers/input/mouse/Makefile +1 -1
diff -uNr a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
@@ -14,4 +14,4 @@
 obj-$(CONFIG_MOUSE_SERIAL)	+= sermouse.o
 obj-$(CONFIG_MOUSE_VSXXXAA)	+= vsxxxaa.o
 
-psmouse-objs  := psmouse-base.o alps.o logips2pp.o synaptics.o
+psmouse-objs  := psmouse-base.o alps.o logips2pp.o synaptics.o trackpoint.o

diff -uNr a/drivers/input/mouse/psmouse-base.c
b/drivers/input/mouse/psmouse-base.c

drivers/input/mouse/psmouse-base.c +11 -0
@@ -23,6 +23,7 @@
 #include "psmouse.h"
 #include "synaptics.h"
 #include "logips2pp.h"
+#include "trackpoint.h"
 #include "alps.h"
 
 #define DRIVER_DESC	"PS/2 mouse driver"
@@ -482,6 +483,16 @@
 		return PSMOUSE_IMPS;
 
 /*
+ * Try to initialize the IBM TrackPoint
+ */
+	if (max_proto > PSMOUSE_PS2 && trackpoint_init(psmouse) == 0) {
+		psmouse->vendor = "IBM";
+		psmouse->name = "TrackPoint";
+ 
+		return PSMOUSE_PS2;
+	}
+
+/*
  * Okay, all failed, we have a standard mouse here. The number of the buttons
  * is still a question, though. We assume 3.
  */
drivers/input/mouse/trackpoint.c +54 -0

54 lines not on this page · raw message

*psmouse, char *buf) \
+ { \
+ struct trackpoint_data *tp = psmouse->private; \
+ return sprintf(buf, "%lu\n", (unsigned long)tp->_item); \
+ }
+
+#define MAKE_ATTR_WRITE(_item, command) \
+ static ssize_t psmouse_attr_set_##_item(struct psmouse
*psmouse, const char *buf, size_t count) \
+ { \
+ char *rest; \

+                unsigned long value; \
+                struct trackpoint_data *tp = psmouse->private; \
+                value = simple_strtoul(buf, &rest, 10); \

+ if(*rest) \
+ return -EINVAL; \
+ tp->_item = value; \
+ trackpoint_write(&psmouse->ps2dev, command, tp->_item); \
+ return count; \
+ }
+
+#define MAKE_ATTR_TOGGLE(_item, command, mask) \
+ static ssize_t psmouse_attr_set_##_item(struct psmouse
*psmouse, const char *buf, size_t count) \
+ { \

+                unsigned char toggle; \
+                struct trackpoint_data *tp = psmouse->private; \
+                toggle = (buf[0] == '1') ? 1 : 0; \
+                if( toggle != tp->_item) { \

+ tp->_item = toggle; \
+ trackpoint_toggle_bit(&psmouse->ps2dev,
command, mask); \
+ } \
+ return count; \
+ }
+
+
+/*
+ * Device IO: read, write and toggle bit
+ */
+static void trackpoint_command(struct ps2dev *ps2dev, unsigned char cmd) +{
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, cmd));
+}
+
+static void trackpoint_read(struct ps2dev *ps2dev, unsigned char loc, unsigned char *results)
+{
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc));
+}
+
+static void trackpoint_write(struct ps2dev *ps2dev, unsigned char loc, unsigned char val)
+{
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val));
+}
+
+static int trackpoint_toggle_bit(struct ps2dev *ps2dev, unsigned char loc, unsigned char mask)
+{
+ /* Bad things will happen if the loc param isn't in this range */
+ if(loc < 0x20 || loc >= 0x2F)
+ return -1;
+
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask));
+
+ return 0;
+}
+
+
+MAKE_ATTR_WRITE(sensitivity, TP_SENS); +MAKE_ATTR_READ(sensitivity);
+
+MAKE_ATTR_WRITE(speed, TP_SPEED);
+MAKE_ATTR_READ(speed);
+
+MAKE_ATTR_WRITE(inertia, TP_INERTIA); +MAKE_ATTR_READ(inertia);
+
+MAKE_ATTR_WRITE(reach, TP_REACH);
+MAKE_ATTR_READ(reach);
+
+MAKE_ATTR_WRITE(draghys, TP_DRAGHYS); +MAKE_ATTR_READ(draghys);
+
+MAKE_ATTR_WRITE(mindrag, TP_MINDRAG); +MAKE_ATTR_READ(mindrag);
+
+MAKE_ATTR_WRITE(thresh, TP_THRESH);
+MAKE_ATTR_READ(thresh);
+
+MAKE_ATTR_WRITE(upthresh, TP_UP_THRESH); +MAKE_ATTR_READ(upthresh);
+
+MAKE_ATTR_WRITE(ztime, TP_Z_TIME);
+MAKE_ATTR_READ(ztime);
+
+MAKE_ATTR_WRITE(jenks, TP_JENKS_CURV); +MAKE_ATTR_READ(jenks);
+
+MAKE_ATTR_TOGGLE(ptson, TP_TOGGLE_PTSON, TP_MASK_PTSON); +MAKE_ATTR_READ(ptson);
+
+MAKE_ATTR_TOGGLE(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK); +MAKE_ATTR_READ(skipback);
+
+MAKE_ATTR_TOGGLE(mb, TP_TOGGLE_MB, TP_MASK_MB); +MAKE_ATTR_READ(mb);
+
+MAKE_ATTR_TOGGLE(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); +MAKE_ATTR_READ(ext_dev);
+
+/* MAKE_ATTR_WRITE( ) for Soft Transparent mode */
+static ssize_t psmouse_attr_set_transparent(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned char command;
+
+ struct trackpoint_data *tp = psmouse->private;
+
+ tp->transparent = (buf[0] == '1') ? 1 : 0;
+
+ command = (tp->transparent) ? TP_SET_SOFT_TRANS : TP_CANCEL_SOFT_TRANS;
+
+ trackpoint_command(&psmouse->ps2dev, command);
+
+ return count;
+}
+
+MAKE_ATTR_READ(transparent);
+
+
+void trackpoint_disconnect(struct psmouse *psmouse)
+{
+ struct serio *serio = psmouse->ps2dev.serio;
+
+ device_remove_file(&serio->dev, &psmouse_attr_sensitivity);
+ device_remove_file(&serio->dev, &psmouse_attr_speed);
+ device_remove_file(&serio->dev, &psmouse_attr_inertia);
+ device_remove_file(&serio->dev, &psmouse_attr_reach);
+ device_remove_file(&serio->dev, &psmouse_attr_draghys);
+ device_remove_file(&serio->dev, &psmouse_attr_mindrag);
+ device_remove_file(&serio->dev, &psmouse_attr_thresh);
+ device_remove_file(&serio->dev, &psmouse_attr_upthresh);
+ device_remove_file(&serio->dev, &psmouse_attr_ztime);
+ device_remove_file(&serio->dev, &psmouse_attr_jenks);
+ device_remove_file(&serio->dev, &psmouse_attr_ptson);
+ device_remove_file(&serio->dev, &psmouse_attr_skipback);
+ device_remove_file(&serio->dev, &psmouse_attr_mb);
+ device_remove_file(&serio->dev, &psmouse_attr_ext_dev);
+ device_remove_file(&serio->dev, &psmouse_attr_transparent);
+
+ kfree(psmouse->private);
+
+ psmouse->private = NULL;
+}
+
+int trackpoint_sync(struct psmouse *psmouse)
+{
+ unsigned char toggle;
+ struct trackpoint_data *tp = psmouse->private;
+
+
+ /* Push the config to the device */
+
+ trackpoint_write(&psmouse->ps2dev, TP_SENS, tp->sensitivity);
+ trackpoint_write(&psmouse->ps2dev, TP_INERTIA, tp->inertia);
+ trackpoint_write(&psmouse->ps2dev, TP_SPEED, tp->speed);
+
+ trackpoint_write(&psmouse->ps2dev, TP_REACH, tp->reach);
+ trackpoint_write(&psmouse->ps2dev, TP_DRAGHYS, tp->draghys);
+ trackpoint_write(&psmouse->ps2dev, TP_MINDRAG, tp->mindrag);
+
+ trackpoint_write(&psmouse->ps2dev, TP_THRESH, tp->thresh);
+ trackpoint_write(&psmouse->ps2dev, TP_UP_THRESH, tp->upthresh);
+
+ trackpoint_write(&psmouse->ps2dev, TP_Z_TIME, tp->ztime);
+ trackpoint_write(&psmouse->ps2dev, TP_JENKS_CURV, tp->jenks);
+
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_PTSON, &toggle);
+ if(((toggle & TP_MASK_PTSON) == TP_MASK_PTSON)!= tp->ptson)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_PTSON, TP_MASK_PTSON);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_MB, &toggle);
+ if(((toggle & TP_MASK_MB) == TP_MASK_MB) != tp->mb)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_MB, TP_MASK_MB);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, &toggle);
+ if(((toggle & TP_MASK_TWOHAND) == TP_MASK_TWOHAND) != tp->twohand)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, TP_MASK_TWOHAND);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, &toggle);
+ if(((toggle & TP_MASK_SKIPBACK) == TP_MASK_SKIPBACK) != tp->skipback)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK,
TP_MASK_SKIPBACK);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_MB, &toggle);
+ if(((toggle & TP_MASK_MB) == TP_MASK_MB) != tp->mb)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_MB, TP_MASK_MB);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, &toggle);
+ if(((toggle & TP_MASK_SOURCE_TAG) == TP_MASK_SOURCE_TAG) != tp->source_tag)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG,
TP_MASK_SOURCE_TAG);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, &toggle);
+ if(((toggle & TP_MASK_EXT_DEV) == TP_MASK_EXT_DEV) != tp->skipback)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV);
+
+
+
+ return 0;
+}
+
+static void trackpoint_defaults(struct trackpoint_data *tp) +{
+ tp->ptson = TP_DEF_PTSON;
+ tp->sensitivity = TP_DEF_SENS;
+ tp->speed = TP_DEF_SPEED;
+ tp->reach = TP_DEF_REACH;
+
+ tp->draghys = TP_DEF_DRAGHYS;
+ tp->mindrag = TP_DEF_MINDRAG;
+
+ tp->thresh = TP_DEF_THRESH;
+ tp->upthresh = TP_DEF_UP_THRESH;
+
+ tp->ztime = TP_DEF_Z_TIME;
+ tp->jenks = TP_DEF_JENKS_CURV;
+
+ tp->mb = TP_DEF_MB;
+
+ tp->inertia = TP_DEF_INERTIA;
+ tp->skipback = TP_DEF_SKIPBACK;
+ tp->ext_dev = TP_DEF_EXT_DEV;
+}
+
+
+
+int trackpoint_init(struct psmouse *psmouse)
+{
+ unsigned char param[2];
+ struct trackpoint_data *priv;
+
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ struct serio *serio = ps2dev->serio;
+
+ param[0] = param[1] = 0;
+
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_DISABLE_EXT));
+
+ ps2_command(ps2dev, param, MAKE_PS2_CMD(0, 2, TP_READ_ID));
+
+ if(param[0] != TP_MAGIC_IDENT)
+ return -1;
+
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_ENABLE_EXT));
+
+ psmouse->private = priv = kmalloc(sizeof(struct trackpoint_data), GFP_KERNEL);
+
+ if(!priv)
+ return -1;
+
+ memset(priv, 0, sizeof(struct trackpoint_data));
+
+ priv->firmware_id = param[1];
+ trackpoint_defaults(priv);
+
+ trackpoint_sync(psmouse);
+
+ psmouse->reconnect = trackpoint_init;
+ psmouse->disconnect = trackpoint_disconnect;
+
+ device_create_file(&serio->dev, &psmouse_attr_sensitivity);
+ device_create_file(&serio->dev, &psmouse_attr_speed);
+ device_create_file(&serio->dev, &psmouse_attr_inertia);
+ device_create_file(&serio->dev, &psmouse_attr_reach);
+ device_create_file(&serio->dev, &psmouse_attr_draghys);
+ device_create_file(&serio->dev, &psmouse_attr_mindrag);
+ device_create_file(&serio->dev, &psmouse_attr_thresh);
+ device_create_file(&serio->dev, &psmouse_attr_upthresh);
+ device_create_file(&serio->dev, &psmouse_attr_ztime);
+ device_create_file(&serio->dev, &psmouse_attr_jenks);
+ device_create_file(&serio->dev, &psmouse_attr_ptson);
+ device_create_file(&serio->dev, &psmouse_attr_skipback);
+ device_create_file(&serio->dev, &psmouse_attr_mb);
+ device_create_file(&serio->dev, &psmouse_attr_ext_dev);
+ device_create_file(&serio->dev, &psmouse_attr_transparent);
+
+ printk(KERN_INFO "IBM TrackPoint firmware: 0x%02X\n", param[1]);
+
+ return 0;
+}
+

drivers/input/mouse/trackpoint.h +83 -0

83 lines not on this page · raw message

Transparency */
+#define TP_TOGGLE_TWOHAND (0x2D) /* Two handed */
+#define TP_TOGGLE_STICKY_TWO (0x2D) /* Sticky two handed */
+#define TP_TOGGLE_SKIPBACK (0x2D) /* Suppress movement */
+ /* after drag release */
+#define TP_TOGGLE_EXT_DEV (0x23) /* Toggle external device */
+#define TP_TOGGLE_SOURCE_TAG (0x20) /* Bit 3 of the first packet
will be set to
+ to the origin of the packet (external or TP) */
+
+/*
+ * Various makses for registers
+ * XOR'd to current contents for new value
+ */
+#define TP_MASK_PTSON (0x01)
+#define TP_MASK_SKIPBACK (0x08)
+#define TP_MASK_TWOHAND (0x01)
+#define TP_MASK_STICKY_TWO (0x04)
+#define TP_MASK_HARD_TRANS (0x80)
+#define TP_MASK_BURST (0x80)
+#define TP_MASK_MB (0x01)
+#define TP_MASK_DRIFT (0x80)
+#define TP_MASK_EXT_DEV (0x02)
+#define TP_MASK_SOURCE_TAG (0x80)
+
+/* Power on Self Test Results */
+#define TP_POR_SUCCESS (0x3B)
+
+/*
+ * Default power on values
+ */
+#define TP_DEF_SENS (0x80)
+#define TP_DEF_INERTIA (0x06)
+#define TP_DEF_SPEED (0x61)
+#define TP_DEF_REACH (0x0A)
+
+#define TP_DEF_DRAGHYS (0xFF)
+#define TP_DEF_MINDRAG (0x14)
+

+#define TP_DEF_THRESH     (0x08)
+#define TP_DEF_UP_THRESH  (0xFF)
+#define TP_DEF_Z_TIME     (0x26)

+#define TP_DEF_JENKS_CURV (0x87)
+
+/* Toggles */
+#define TP_DEF_MB (0x00)
+#define TP_DEF_PTSON (0x00)
+#define TP_DEF_SKIPBACK (0x00)
+#define TP_DEF_EXT_DEV (0x01)
+
+#define MAKE_PS2_CMD(params, results, cmd) ((params<<12) | (results<<8) | (cmd))
+
+
+
+struct trackpoint_data
+{
+ unsigned char firmware_id;
+
+ unsigned char sensitivity, speed, inertia, reach;
+ unsigned char draghys, mindrag;
+ unsigned char thresh, upthresh;
+ unsigned char ztime, jenks;
+
+ unsigned char ptson; /* Press to Select */
+ unsigned char twohand, skipback;
+ unsigned char mb;
+
+ unsigned char ext_dev;
+ unsigned char transparent;
+ unsigned char source_tag;
+
+};
+
+extern int trackpoint_init (struct psmouse *psmouse); +
+#endif /* _TRACKPOINT_H */

#1 lore raw
Quoted 9 lines · Stephen Evanchik

Here is the latest IBM TrackPoint patch. I believe I made all of the necessary changes in this release including the removal of the middle-to-scroll functionality. One item I didn't address was a comment about checking the return code of ps2_command ..

I looked at other usages and it wasn't clear to me how to actually implement something that is sane. In some places an error causes a return out of the function and in others the return value is ignored. Should I check each return value or the first ?

I would check all 3 ps2_command calls in trackpoint_init and leave the rest as is.

One more thing - I'd like to see more descriptive names of sysfs attributes, for example I'd change "ptson" to "press_to_select", "mb" to "middle_btn", etc.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 11 lines · Dmitry Torokhov
Quoted 9 lines · Stephen Evanchik

Here is the latest IBM TrackPoint patch. I believe I made all of the necessary changes in this release including the removal of the middle-to-scroll functionality. One item I didn't address was a comment about checking the return code of ps2_command ..

I looked at other usages and it wasn't clear to me how to actually implement something that is sane. In some places an error causes a return out of the function and in others the return value is ignored. Should I check each return value or the first ?

Quoted 6 lines

I would check all 3 ps2_command calls in trackpoint_init and leave the rest as is.

One more thing - I'd like to see more descriptive names of sysfs attributes, for example I'd change "ptson" to "press_to_select", "mb" to "middle_btn", etc.

Stephen, if you fix the above, and send me the patch, I'll merge it, there isn't any other problem with it.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#3 lore raw
Quoted 2 lines · Vojtech Pavlik

Stephen, if you fix the above, and send me the patch, I'll merge it, there isn't any other problem with it.

Ok, more descriptive names, I noticed that psmouse->disconnect wasn't being called when my laptop suspended so I made the reconnect function sync the in memory configuration with what is actually on the device.

Also, I removed the external port disable commands in trackpoint_init -- they didn't seem to do anything on my T23.

Stephen

drivers/input/mouse/Makefile +1 -1
diff -uNr a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
@@ -14,4 +14,4 @@
 obj-$(CONFIG_MOUSE_SERIAL)	+= sermouse.o
 obj-$(CONFIG_MOUSE_VSXXXAA)	+= vsxxxaa.o
 
-psmouse-objs  := psmouse-base.o alps.o logips2pp.o synaptics.o
+psmouse-objs  := psmouse-base.o alps.o logips2pp.o synaptics.o trackpoint.o

diff -uNr a/drivers/input/mouse/psmouse-base.c
b/drivers/input/mouse/psmouse-base.c

drivers/input/mouse/psmouse-base.c +11 -0
@@ -23,6 +23,7 @@
 #include "psmouse.h"
 #include "synaptics.h"
 #include "logips2pp.h"
+#include "trackpoint.h"
 #include "alps.h"
 
 #define DRIVER_DESC	"PS/2 mouse driver"
@@ -482,6 +483,16 @@
 		return PSMOUSE_IMPS;
 
 /*
+ * Try to initialize the IBM TrackPoint
+ */
+	if (max_proto > PSMOUSE_PS2 && trackpoint_init(psmouse) == 0) {
+		psmouse->vendor = "IBM";
+		psmouse->name = "TrackPoint";
+ 
+		return PSMOUSE_PS2;
+	}
+
+/*
  * Okay, all failed, we have a standard mouse here. The number of the buttons
  * is still a question, though. We assume 3.
  */
drivers/input/mouse/trackpoint.c +54 -0

54 lines not on this page · raw message

*psmouse, char *buf) \
+ { \
+ struct trackpoint_data *tp = psmouse->private; \
+ return sprintf(buf, "%lu\n", (unsigned long)tp->_item); \
+ }
+
+#define MAKE_ATTR_WRITE(_item, command) \
+ static ssize_t psmouse_attr_set_##_item(struct psmouse
*psmouse, const char *buf, size_t count) \
+ { \
+ char *rest; \

+                unsigned long value; \
+                struct trackpoint_data *tp = psmouse->private; \
+                value = simple_strtoul(buf, &rest, 10); \

+ if(*rest) \
+ return -EINVAL; \
+ tp->_item = value; \
+ trackpoint_write(&psmouse->ps2dev, command, tp->_item); \
+ return count; \
+ }
+
+#define MAKE_ATTR_TOGGLE(_item, command, mask) \
+ static ssize_t psmouse_attr_set_##_item(struct psmouse
*psmouse, const char *buf, size_t count) \
+ { \

+                unsigned char toggle; \
+                struct trackpoint_data *tp = psmouse->private; \
+                toggle = (buf[0] == '1') ? 1 : 0; \
+                if( toggle != tp->_item) { \

+ tp->_item = toggle; \
+ trackpoint_toggle_bit(&psmouse->ps2dev,
command, mask); \
+ } \
+ return count; \
+ }
+
+
+/*
+ * Device IO: read, write and toggle bit
+ */
+static void trackpoint_command(struct ps2dev *ps2dev, unsigned char cmd) +{
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, cmd));
+}
+
+static void trackpoint_read(struct ps2dev *ps2dev, unsigned char loc, unsigned char *results)
+{
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc));
+}
+
+static void trackpoint_write(struct ps2dev *ps2dev, unsigned char loc, unsigned char val)
+{
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val));
+}
+
+static int trackpoint_toggle_bit(struct ps2dev *ps2dev, unsigned char loc, unsigned char mask)
+{
+ /* Bad things will happen if the loc param isn't in this range */
+ if(loc < 0x20 || loc >= 0x2F)
+ return -1;
+
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc));
+ ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask));
+
+ return 0;
+}
+
+
+MAKE_ATTR_WRITE(sensitivity, TP_SENS); +MAKE_ATTR_READ(sensitivity);
+
+MAKE_ATTR_WRITE(speed, TP_SPEED);
+MAKE_ATTR_READ(speed);
+
+MAKE_ATTR_WRITE(inertia, TP_INERTIA); +MAKE_ATTR_READ(inertia);
+
+MAKE_ATTR_WRITE(reach, TP_REACH);
+MAKE_ATTR_READ(reach);
+
+MAKE_ATTR_WRITE(draghys, TP_DRAGHYS); +MAKE_ATTR_READ(draghys);
+
+MAKE_ATTR_WRITE(mindrag, TP_MINDRAG); +MAKE_ATTR_READ(mindrag);
+
+MAKE_ATTR_WRITE(thresh, TP_THRESH);
+MAKE_ATTR_READ(thresh);
+
+MAKE_ATTR_WRITE(upthresh, TP_UP_THRESH); +MAKE_ATTR_READ(upthresh);
+
+MAKE_ATTR_WRITE(ztime, TP_Z_TIME);
+MAKE_ATTR_READ(ztime);
+
+MAKE_ATTR_WRITE(jenks, TP_JENKS_CURV); +MAKE_ATTR_READ(jenks);
+
+MAKE_ATTR_TOGGLE(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON); +MAKE_ATTR_READ(press_to_select);
+
+MAKE_ATTR_TOGGLE(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK); +MAKE_ATTR_READ(skipback);
+
+MAKE_ATTR_TOGGLE(middle_btn_disable, TP_TOGGLE_MB, TP_MASK_MB); +MAKE_ATTR_READ(middle_btn_disable);
+
+MAKE_ATTR_TOGGLE(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); +MAKE_ATTR_READ(ext_dev);
+
+/* MAKE_ATTR_WRITE( ) for Soft Transparent mode */
+static ssize_t psmouse_attr_set_transparent(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned char command;
+
+ struct trackpoint_data *tp = psmouse->private;
+
+ tp->transparent = (buf[0] == '1') ? 1 : 0;
+
+ command = (tp->transparent) ? TP_SET_SOFT_TRANS : TP_CANCEL_SOFT_TRANS;
+
+ trackpoint_command(&psmouse->ps2dev, command);
+
+ return count;
+}
+
+MAKE_ATTR_READ(transparent);
+
+
+static void trackpoint_disconnect(struct psmouse *psmouse) +{
+ struct serio *serio = psmouse->ps2dev.serio;
+
+ device_remove_file(&serio->dev, &psmouse_attr_sensitivity);
+ device_remove_file(&serio->dev, &psmouse_attr_speed);
+ device_remove_file(&serio->dev, &psmouse_attr_inertia);
+ device_remove_file(&serio->dev, &psmouse_attr_reach);
+ device_remove_file(&serio->dev, &psmouse_attr_draghys);
+ device_remove_file(&serio->dev, &psmouse_attr_mindrag);
+ device_remove_file(&serio->dev, &psmouse_attr_thresh);
+ device_remove_file(&serio->dev, &psmouse_attr_upthresh);
+ device_remove_file(&serio->dev, &psmouse_attr_ztime);
+ device_remove_file(&serio->dev, &psmouse_attr_jenks);
+ device_remove_file(&serio->dev, &psmouse_attr_press_to_select);
+ device_remove_file(&serio->dev, &psmouse_attr_skipback);
+ device_remove_file(&serio->dev, &psmouse_attr_middle_btn_disable);
+ device_remove_file(&serio->dev, &psmouse_attr_ext_dev);
+ device_remove_file(&serio->dev, &psmouse_attr_transparent);
+
+ kfree(psmouse->private);
+
+ psmouse->private = NULL;
+}
+
+static int trackpoint_sync(struct psmouse *psmouse)
+{
+ unsigned char toggle;
+ struct trackpoint_data *tp = psmouse->private;
+
+
+ /* Push the config to the device */
+
+ trackpoint_write(&psmouse->ps2dev, TP_SENS, tp->sensitivity);
+ trackpoint_write(&psmouse->ps2dev, TP_INERTIA, tp->inertia);
+ trackpoint_write(&psmouse->ps2dev, TP_SPEED, tp->speed);
+
+ trackpoint_write(&psmouse->ps2dev, TP_REACH, tp->reach);
+ trackpoint_write(&psmouse->ps2dev, TP_DRAGHYS, tp->draghys);
+ trackpoint_write(&psmouse->ps2dev, TP_MINDRAG, tp->mindrag);
+
+ trackpoint_write(&psmouse->ps2dev, TP_THRESH, tp->thresh);
+ trackpoint_write(&psmouse->ps2dev, TP_UP_THRESH, tp->upthresh);
+
+ trackpoint_write(&psmouse->ps2dev, TP_Z_TIME, tp->ztime);
+ trackpoint_write(&psmouse->ps2dev, TP_JENKS_CURV, tp->jenks);
+
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_PTSON, &toggle);
+ if(((toggle & TP_MASK_PTSON) == TP_MASK_PTSON)!= tp->press_to_select)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_PTSON, TP_MASK_PTSON);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_MB, &toggle);
+ if(((toggle & TP_MASK_MB) == TP_MASK_MB) != tp->middle_btn_disable)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_MB, TP_MASK_MB);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, &toggle);
+ if(((toggle & TP_MASK_TWOHAND) == TP_MASK_TWOHAND) != tp->twohand)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, TP_MASK_TWOHAND);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, &toggle);
+ if(((toggle & TP_MASK_SKIPBACK) == TP_MASK_SKIPBACK) != tp->skipback)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK,
TP_MASK_SKIPBACK);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_MB, &toggle);
+ if(((toggle & TP_MASK_MB) == TP_MASK_MB) != tp->middle_btn_disable)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_MB, TP_MASK_MB);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, &toggle);
+ if(((toggle & TP_MASK_SOURCE_TAG) == TP_MASK_SOURCE_TAG) != tp->source_tag)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG,
TP_MASK_SOURCE_TAG);
+
+ trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, &toggle);
+ if(((toggle & TP_MASK_EXT_DEV) == TP_MASK_EXT_DEV) != tp->skipback)
+ trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV);
+
+
+
+ return 0;
+}
+
+static void trackpoint_defaults(struct trackpoint_data *tp) +{
+ tp->press_to_select = TP_DEF_PTSON;
+ tp->sensitivity = TP_DEF_SENS;
+ tp->speed = TP_DEF_SPEED;
+ tp->reach = TP_DEF_REACH;
+
+ tp->draghys = TP_DEF_DRAGHYS;
+ tp->mindrag = TP_DEF_MINDRAG;
+
+ tp->thresh = TP_DEF_THRESH;
+ tp->upthresh = TP_DEF_UP_THRESH;
+
+ tp->ztime = TP_DEF_Z_TIME;
+ tp->jenks = TP_DEF_JENKS_CURV;
+
+ tp->middle_btn_disable = TP_DEF_MB;
+
+ tp->inertia = TP_DEF_INERTIA;
+ tp->skipback = TP_DEF_SKIPBACK;
+ tp->ext_dev = TP_DEF_EXT_DEV;
+}
+
+
+
+int trackpoint_init(struct psmouse *psmouse)
+{
+ unsigned char param[2];
+ struct trackpoint_data *priv;
+
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ struct serio *serio = ps2dev->serio;
+
+ param[0] = param[1] = 0;
+
+ if(ps2_command(ps2dev, param, MAKE_PS2_CMD(0, 2, TP_READ_ID)))
+ return -1;
+
+ if(param[0] != TP_MAGIC_IDENT)
+ return -1;
+
+ psmouse->private = priv = kmalloc(sizeof(struct trackpoint_data), GFP_KERNEL);
+
+ if(!priv)
+ return -1;
+
+ memset(priv, 0, sizeof(struct trackpoint_data));
+
+ priv->firmware_id = param[1];
+ trackpoint_defaults(priv);
+
+ trackpoint_sync(psmouse);
+
+ psmouse->reconnect = trackpoint_sync;
+ psmouse->disconnect = trackpoint_disconnect;
+
+ device_create_file(&serio->dev, &psmouse_attr_sensitivity);
+ device_create_file(&serio->dev, &psmouse_attr_speed);
+ device_create_file(&serio->dev, &psmouse_attr_inertia);
+ device_create_file(&serio->dev, &psmouse_attr_reach);
+ device_create_file(&serio->dev, &psmouse_attr_draghys);
+ device_create_file(&serio->dev, &psmouse_attr_mindrag);
+ device_create_file(&serio->dev, &psmouse_attr_thresh);
+ device_create_file(&serio->dev, &psmouse_attr_upthresh);
+ device_create_file(&serio->dev, &psmouse_attr_ztime);
+ device_create_file(&serio->dev, &psmouse_attr_jenks);
+ device_create_file(&serio->dev, &psmouse_attr_press_to_select);
+ device_create_file(&serio->dev, &psmouse_attr_skipback);
+ device_create_file(&serio->dev, &psmouse_attr_middle_btn_disable);
+ device_create_file(&serio->dev, &psmouse_attr_ext_dev);
+ device_create_file(&serio->dev, &psmouse_attr_transparent);
+
+ printk(KERN_INFO "IBM TrackPoint firmware: 0x%02X\n", param[1]);
+
+ return 0;
+}
+

drivers/input/mouse/trackpoint.h +83 -0

83 lines not on this page · raw message

Transparency */
+#define TP_TOGGLE_TWOHAND (0x2D) /* Two handed */
+#define TP_TOGGLE_STICKY_TWO (0x2D) /* Sticky two handed */
+#define TP_TOGGLE_SKIPBACK (0x2D) /* Suppress movement */
+ /* after drag release */
+#define TP_TOGGLE_EXT_DEV (0x23) /* Toggle external device */
+#define TP_TOGGLE_SOURCE_TAG (0x20) /* Bit 3 of the first packet
will be set to
+ to the origin of the packet (external or TP) */
+
+/*
+ * Various makses for registers
+ * XOR'd to current contents for new value
+ */
+#define TP_MASK_PTSON (0x01)
+#define TP_MASK_SKIPBACK (0x08)
+#define TP_MASK_TWOHAND (0x01)
+#define TP_MASK_STICKY_TWO (0x04)
+#define TP_MASK_HARD_TRANS (0x80)
+#define TP_MASK_BURST (0x80)
+#define TP_MASK_MB (0x01)
+#define TP_MASK_DRIFT (0x80)
+#define TP_MASK_EXT_DEV (0x02)
+#define TP_MASK_SOURCE_TAG (0x80)
+
+/* Power on Self Test Results */
+#define TP_POR_SUCCESS (0x3B)
+
+/*
+ * Default power on values
+ */
+#define TP_DEF_SENS (0x80)
+#define TP_DEF_INERTIA (0x06)
+#define TP_DEF_SPEED (0x61)
+#define TP_DEF_REACH (0x0A)
+
+#define TP_DEF_DRAGHYS (0xFF)
+#define TP_DEF_MINDRAG (0x14)
+

+#define TP_DEF_THRESH     (0x08)
+#define TP_DEF_UP_THRESH  (0xFF)
+#define TP_DEF_Z_TIME     (0x26)

+#define TP_DEF_JENKS_CURV (0x87)
+
+/* Toggles */
+#define TP_DEF_MB (0x00)
+#define TP_DEF_PTSON (0x00)
+#define TP_DEF_SKIPBACK (0x00)
+#define TP_DEF_EXT_DEV (0x01)
+
+#define MAKE_PS2_CMD(params, results, cmd) ((params<<12) | (results<<8) | (cmd))
+
+
+
+struct trackpoint_data
+{
+ unsigned char firmware_id;
+
+ unsigned char sensitivity, speed, inertia, reach;
+ unsigned char draghys, mindrag;
+ unsigned char thresh, upthresh;
+ unsigned char ztime, jenks;
+
+ unsigned char press_to_select;
+ unsigned char twohand, skipback;
+ unsigned char middle_btn_disable;
+
+ unsigned char ext_dev;
+ unsigned char transparent;
+ unsigned char source_tag;
+
+};
+
+extern int trackpoint_init (struct psmouse *psmouse); +
+#endif /* _TRACKPOINT_H */

#4 lore raw

Hi,

sorry, couple of more things (and I promise I will shut up ;))

drivers/input/mouse/psmouse-base.c line 493

Quoted 9 lines

/*
+ * Try to initialize the IBM TrackPoint
+ */

drivers/input/mouse/psmouse-base.c +6 -0
+	if (max_proto > PSMOUSE_PS2 && trackpoint_init(psmouse) == 0) {
+		psmouse->vendor = "IBM";
+		psmouse->name = "TrackPoint";
+ 
+		return PSMOUSE_PS2;
+	}

I would like you to change the code so that psmouse structure only changed when set_properties is set. Probably moving these into trackpoint_init is a good idea since _init should not override psmouse->private unless told to do so. It is important when the device was not identified as a trackpoint but later (let's say after resume) it is - in this case generic reconnect will cause psmouse_extensions with set_properties = 0 to verify protocol and we dont' want to change anything in psmouse to give the original disconnect handler change to clean up properly.

Thinking about it some more I am pretty sure that you need a special protocol number for the trackpoint, because protocol number is used by psmouse_reconnect to check whether reconnect can be done or rescan is needed. You can reuse the standard protocol handler, but you need the new number. This way if trackpad was not identified as such first time around, but is identified on reconnect psmouse-base would notice that it is a new type of device and schedule reconnect and will proper cleanup/initialization.

Does this make sense?

Quoted 4 lines
(quoted diff) +3 -0
+
+#define MAKE_ATTR_WRITE(_item, command) \
+        static ssize_t psmouse_attr_set_##_item(struct psmouse

*psmouse, const char *buf, size_t count) \

It looks like the patch got mangled on it's way, please check your mail client.

Review

Quoted 5 lines
(quoted diff) +5 -0
+        { \
+		char *rest; \
+                unsigned long value; \
+                struct trackpoint_data *tp = psmouse->private; \
+                value = simple_strtoul(buf, &rest, 10); \

Whitespace damage (tabs vs. spaces). Also there are some trailing whitespace. If you are using vi I find the following helpful to highlight the problem spots:

set listchars=tab:\|-
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/

Signature · 1 line
Dmitry