Skip to contentSkip to conversation

usb/input: Add relayfs support to appletouch driver

PATCH In review Michael Hanselmann 6 participants 13 messages Dec 13, 2005 – Dec 17, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 usb/input: Add relayfs support to appletouch driver

This patch adds support for relayfs to the appletouch driver to make debugging easier.

---

Documentation/input/appletouch.txt +2 -0
diff -Npur linux-2.6.15-rc5.orig/Documentation/input/appletouch.txt linux-2.6.15-rc5/Documentation/input/appletouch.txt
@@ -77,6 +78,8 @@ full tracing (each sample is being trace
 		or
 	echo "1" > /sys/module/appletouch/parameters/debug
 
+To make debugging easier, the driver also supports the relayfs filesystem.
+
 Links:
 ------
 
drivers/usb/input/appletouch.c +65 -1

122 lines not on this page · raw message

#1 lore raw

PATCH 2/2 usb/input: Add Geyser 2 support to appletouch driver

This patch adds support for the Geyser 2 touchpads used on Post-Oct 2005 Apple PowerBooks to the appletouch driver.

---

Documentation/input/appletouch.txt +3 -2
diff -Npur linux-2.6.15-rc5.orig/Documentation/input/appletouch.txt linux-2.6.15-rc5/Documentation/input/appletouch.txt
@@ -3,7 +3,7 @@ Apple Touchpad Driver (appletouch)
 	Copyright (C) 2005 Stelian Pop <[email protected]>
 
 appletouch is a Linux kernel driver for the USB touchpad found on post
-February 2005 Apple Alu Powerbooks.
+February 2005 and October 2005 Apple Aluminium Powerbooks.
 
 This driver is derived from Johannes Berg's appletrackpad driver[1], but it has
 been improved in some areas:
@@ -13,7 +13,8 @@ been improved in some areas:
 
 Credits go to Johannes Berg for reverse-engineering the touchpad protocol,
 Frank Arnold for further improvements, and Alex Harper for some additional
-information about the inner workings of the touchpad sensors.
+information about the inner workings of the touchpad sensors. Michael
+Hanselmann added support for the October 2005 models.
 
 Usage:
 ------
drivers/usb/input/appletouch.c +140 -35

281 lines not on this page · raw message

author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Stelian Pop on v1 2/2
#2 lore raw

Re: [PATCH 2.6 2/2] usb/input: Add Geyser 2 support to appletouch driver

This patch adds support for the Geyser 2 touchpads used on post Oct 2005 Apple PowerBooks to the appletouch driver.

---
Rediffed without relayfs and made loops out of the manually unrolled assignment code.

Documentation/input/appletouch.txt +3 -2
diff -rup linux-2.6.15-rc5.orig/Documentation/input/appletouch.txt b/Documentation/input/appletouch.txt
@@ -3,7 +3,7 @@ Apple Touchpad Driver (appletouch)
 	Copyright (C) 2005 Stelian Pop <[email protected]>
 
 appletouch is a Linux kernel driver for the USB touchpad found on post
-February 2005 Apple Alu Powerbooks.
+February 2005 and October 2005 Apple Aluminium Powerbooks.
 
 This driver is derived from Johannes Berg's appletrackpad driver[1], but it has
 been improved in some areas:
@@ -13,7 +13,8 @@ been improved in some areas:
 
 Credits go to Johannes Berg for reverse-engineering the touchpad protocol,
 Frank Arnold for further improvements, and Alex Harper for some additional
-information about the inner workings of the touchpad sensors.
+information about the inner workings of the touchpad sensors. Michael
+Hanselmann added support for the October 2005 models.
 
 Usage:
 ------
drivers/usb/input/appletouch.c +109 -36

253 lines not on this page · raw message

author Acked-by Rene Nussbaumer Acked-by Johannes Berg
#4 lore raw

This patch adds support for relayfs to the appletouch driver to make debugging easier.

---
Updated to make the relayfs parameter readonly.

Documentation/input/appletouch.txt +2 -0
diff -Npur linux-2.6.15-rc5.orig/Documentation/input/appletouch.txt linux-2.6.15-rc5/Documentation/input/appletouch.txt
@@ -77,6 +78,8 @@ full tracing (each sample is being trace
 		or
 	echo "1" > /sys/module/appletouch/parameters/debug
 
+To make debugging easier, the driver also supports the relayfs filesystem.
+
 Links:
 ------
 
drivers/usb/input/appletouch.c +65 -1

122 lines not on this page · raw message

maintainer
#5 lore raw

Hi,

Quoted 8 lines · Michael Hanselmann

*
+ * Nov 2005 - Parag Warudkar
+ * o Added ability to export data via relayfs
+ *
+ * Nov/Dec 2005 - Michael Hanselmann
+ * o Compile relayfs support only if enabled in the kernel
+ * o Enable relayfs only if requested by the user
+ *

We have an SCM, not need to have a changelog in the driver.

Review

Quoted 4 lines
(quoted diff) +3 -0
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+struct rchan* rch =3D NULL;
+struct rchan_callbacks* rcb =3D NULL;

Initializing with 0/NULL adds to the size of the image for no reason.

Review

Quoted 3 lines
(quoted diff) +2 -0
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+static int relayfs =3D 0;

Same here.

Quoted 8 lines
drivers/usb/input/appletouch.c +4 -0
+module_param(relayfs, int, 0444);
+MODULE_PARM_DESC(relayfs, "Activate relayfs support");
+#endif
+
 static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
                            int *z, int *fingers)
 {

drivers/usb/input/appletouch.c static void atp_complete(struct urb* urb · line 228

Quoted 10 lines
drivers/usb/input/appletouch.c +7 -0
@@ -194,6 +219,13 @@ static void atp_complete(struct urb* urb
               goto exit;
       }
 
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+       /* "rch" is NULL if relayfs is not enabled */
+       if (rch && dev->data) {
+               relay_write(rch, dev->data, dev->urb->actual_length);
+       }
+#endif
+

Haveing ifdefs in the middle of the code is not too nice. can we please have something like this:

#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE) static inline void appletouch_relayfs_dump(...)
{
...
}
static int appletouch_relayfs_init(void)
{
...
}
static void appletouch_relayfs_exit()
{
...
}
#else
static inline void appletouch_relayfs_dump(...) { } static int appletouch_relayfs_init(void) { return 0; } static void appletouch_relayfs_exit() { }
#endif

Also, would not it be better to initialize relayfs only when device is opened because there won't be any data otehrwise?

--
Dmitry

author Acked-by Rene Nussbaumer Acked-by Johannes Berg
#6 lore raw

This patch adds support for relayfs to the appletouch driver to make debugging easier.

---

Quoted 1 line

Initializing with 0/NULL adds to the size of the image for no reason.

Does gcc automatically initialize them to that value?

Quoted 6 lines

Haveing ifdefs in the middle of the code is not too nice. can we please have something like this:
[...]

Also, would not it be better to initialize relayfs only when device is opened because there won't be any data otehrwise?

Sure, both is done in this patch:

Documentation/input/appletouch.txt +2 -0
diff -rup linux-2.6.15-rc5.orig/Documentation/input/appletouch.txt b/Documentation/input/appletouch.txt
@@ -77,6 +77,8 @@ full tracing (each sample is being trace
 		or
 	echo "1" > /sys/module/appletouch/parameters/debug
 
+To make debugging easier, the driver also supports the relayfs filesystem.
+
 Links:
 ------
 
drivers/usb/input/appletouch.c +79 -1

128 lines not on this page · raw message

#7 lore raw
Quoted 10 lines · Michael Hanselmann

This patch adds support for relayfs to the appletouch driver to make debugging easier.

---

Quoted 1 line

Initializing with 0/NULL adds to the size of the image for no reason.

Does gcc automatically initialize them to that value?

Yes, global and static variables are guaranteed to be initialized with 0.

Couple of more comments:

1. I don't think that relayfs parameter worth an entry in sysfs.
2. We should not signal error condition in appletouch_open if appletouch_relayfs_init fails - the devce is still functioning fine. Just emit a warning.
3. I must be missing something but I do not see rcb being used anywhere...

The adjusted patch is below. I am still not sure if this really should be in mainline. Was it ever used?

Signature · 153 lines
Dmitry

From: Michael Hanselmann <[email protected]>

Input: appletouch - add relayfs support

This patch adds support for relayfs to the appletouch driver to make
debugging easier.

Signed-off-by: Michael Hanselmann <[email protected]>
Acked-by: Rene Nussbaumer <[email protected]>
Acked-by: Johannes Berg <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---

 Documentation/input/appletouch.txt |    2 +
 drivers/usb/input/appletouch.c     |   61 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletion(-)

Index: work/Documentation/input/appletouch.txt
===================================================================
--- work.orig/Documentation/input/appletouch.txt
+++ work/Documentation/input/appletouch.txt
@@ -77,6 +77,8 @@ full tracing (each sample is being trace
 		or
 	echo "1" > /sys/module/appletouch/parameters/debug
 
+To make debugging easier, the driver also supports the relayfs filesystem.
+
 Links:
 ------
 
Index: work/drivers/usb/input/appletouch.c
===================================================================
--- work.orig/drivers/usb/input/appletouch.c
+++ work/drivers/usb/input/appletouch.c
@@ -6,6 +6,8 @@
  * Copyright (C) 2005      Stelian Pop ([email protected])
  * Copyright (C) 2005      Frank Arnold ([email protected])
  * Copyright (C) 2005      Peter Osterlund ([email protected])
+ * Copyright (C) 2005      Parag Warudkar ([email protected])
+ * Copyright (C) 2005      Michael Hanselmann ([email protected])
  *
  * Thanks to Alex Harper <[email protected]> for his inputs.
  *
@@ -35,6 +37,10 @@
 #include <linux/input.h>
 #include <linux/usb_input.h>
 
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+#include <linux/relayfs_fs.h>
+#endif
+
 /* Apple has powerbooks which have the keyboard with different Product IDs */
 #define APPLE_VENDOR_ID		0x05AC
 
@@ -73,6 +79,7 @@ MODULE_DEVICE_TABLE (usb, atp_table);
 
 /* maximum pressure this driver will report */
 #define ATP_PRESSURE	300
+
 /*
  * multiplication factor for the X and Y coordinates.
  * We try to keep the touchpad aspect ratio while still doing only simple
@@ -124,7 +131,7 @@ struct atp {
 		if (debug) printk(format, ##a);				\
 	} while (0)
 
-MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold");
+MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold, Parag Warudkar, Michael Hanselmann");
 MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver");
 MODULE_LICENSE("GPL");
 
@@ -132,6 +139,51 @@ static int debug = 1;
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Activate debugging output");
 
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+static int relayfs;
+module_param(relayfs, int, 0);
+MODULE_PARM_DESC(relayfs, "Activate relayfs support");
+
+static struct rchan *rch;
+
+static inline void atp_relayfs_dump(struct atp *dev)
+{
+	/* "rch" is NULL if relayfs is disabled */
+	if (rch && dev->data)
+		relay_write(rch, dev->data, dev->urb->actual_length);
+}
+
+static int appletouch_relayfs_init(void)
+{
+	if (relayfs) {
+
+		rch = relay_open("atpdata", NULL, 256, 256, NULL);
+		if (!rch) {
+			printk(KERN_WARNING
+				"appletouch: Failed to enable Relayfs.\n");
+			return -ENOMEM;
+		}
+
+		printk(KERN_INFO "appletouch: Relayfs enabled.\n");
+	}
+
+	return 0;
+}
+
+static void appletouch_relayfs_exit(void)
+{
+	if (rch) {
+		printk(KERN_INFO "appletouch: Relayfs disabled\n");
+		relay_close(rch);
+		rch = NULL;
+	}
+}
+#else
+static inline void atp_relayfs_dump(struct atp *dev) { }
+static int appletouch_relayfs_init(void) { return 0; }
+static void appletouch_relayfs_exit(void) { }
+#endif
+
 static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
 			     int *z, int *fingers)
 {
@@ -194,6 +246,8 @@ static void atp_complete(struct urb* urb
 		goto exit;
 	}
 
+	atp_relayfs_dump(dev);
+
 	/* reorder the sensors values */
 	for (i = 0; i < 8; i++) {
 		/* X values */
@@ -301,7 +355,10 @@ static int atp_open(struct input_dev *in
 	if (usb_submit_urb(dev->urb, GFP_ATOMIC))
 		return -EIO;
 
+	appletouch_relayfs_init();
+
 	dev->open = 1;
+
 	return 0;
 }
 
@@ -310,6 +367,8 @@ static void atp_close(struct input_dev *
 	struct atp *dev = input->private;
 
 	usb_kill_urb(dev->urb);
+	appletouch_relayfs_exit();
+
 	dev->open = 0;
 }
#8 lore raw
Quoted 2 lines · Dmitry Torokhov

The adjusted patch is below. I am still not sure if this really should be in mainline. Was it ever used?

That patch looks fine for me.

I would like to see it in mainline because it makes debugging and figuring out new protocols much easier. For example, Apple changed the protocol with the latest PowerBooks (see the other patch for that). Why should everyone willing to implement a new protocol rewrite this code?

#9 lore raw
In reply to Michael Hanselmann
Quoted 2 lines · Michael Hanselmann

This patch adds support for relayfs to the appletouch driver to make debugging easier.

I think I agree with previous comments regarding debug code in the driver:
It's unlikely to ever be used by more than a couple of people at very rare occasions (new hardware releases), and the barrier to using it is still high; new users need to learn how to parse the data anyway. I don't see a reason to include this in mainline.

That aside, comments on the patch below.

Quoted 24 lines

diff -rup linux-2.6.15-rc5.orig/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c

drivers/usb/input/appletouch.c +6 -0
@@ -6,6 +6,8 @@
  * Copyright (C) 2005      Stelian Pop ([email protected])
  * Copyright (C) 2005      Frank Arnold ([email protected])
  * Copyright (C) 2005      Peter Osterlund ([email protected])
+ * Copyright (C) 2005      Parag Warudkar ([email protected])
+ * Copyright (C) 2005      Michael Hanselmann ([email protected])
  *
  * Thanks to Alex Harper <[email protected]> for his inputs.
  *
@@ -35,6 +37,10 @@
 #include <linux/input.h>
 #include <linux/usb_input.h>
 
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+#include <linux/relayfs_fs.h>
+#endif
+
 /* Apple has powerbooks which have the keyboard with different Product IDs */
 #define APPLE_VENDOR_ID		0x05AC
 

drivers/usb/input/appletouch.c MODULE_DEVICE_TABLE (usb, atp_table); · line 82

Quoted 4 lines
drivers/usb/input/appletouch.c +1 -0
@@ -73,6 +79,7 @@ MODULE_DEVICE_TABLE (usb, atp_table);
 
 /* maximum pressure this driver will report */
 #define ATP_PRESSURE	300
+

Whitespace change

Quoted 14 lines
drivers/usb/input/appletouch.c +0 -0
 /*
 
  * multiplication factor for the X and Y coordinates.

* We try to keep the touchpad aspect ratio while still doing only simple

drivers/usb/input/appletouch.c +1 -1
@@ -124,7 +131,7 @@ struct atp {
 		if (debug) printk(format, ##a);				\
 	} while (0)
 
-MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold");
+MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold, Parag Warudkar, Michael Hanselmann");
 MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver");
 MODULE_LICENSE("GPL");
 

drivers/usb/input/appletouch.c static int debug = 1; · line 148

Quoted 10 lines
drivers/usb/input/appletouch.c +7 -0
@@ -132,6 +139,68 @@ static int debug = 1;
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Activate debugging output");
 
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+static int relayfs;
+module_param(relayfs, int, 0444);
+MODULE_PARM_DESC(relayfs, "Activate relayfs support");
+
+struct rchan *rch;
+struct rchan_callbacks *rcb;

static, please.

Quoted 5 lines
drivers/usb/input/appletouch.c +5 -0
+
+static inline void atp_relayfs_dump(struct atp *dev)
+{
+	/* "rch" is NULL if relayfs is disabled */
+	if (rch && dev->data) {

drivers/usb/input/appletouch.c static int debug = 1; · line 163

Quoted 10 lines
drivers/usb/input/appletouch.c +10 -0
+		relay_write(rch, dev->data, dev->urb->actual_length);
+	}
+}
+
+static int appletouch_relayfs_init(void)
+{
+	// Make sure the variables aren't initialized to some bogus value when
+	// relayfs is disabled
+	rcb = NULL;
+	rch = NULL;

Huh? BSS is initialized to 0, this is unneccessary. (Also, the comment is C++-style, please use /* */ comments.)

drivers/usb/input/appletouch.c static int debug = 1; · line 165

Quoted 2 lines
drivers/usb/input/appletouch.c +2 -0
+
+	if (relayfs) {

Please do:

	if (!relayfs)
		return 0;

To save indentation.

drivers/usb/input/appletouch.c static int debug = 1; · line 177

Quoted 12 lines
drivers/usb/input/appletouch.c +12 -0
+		rcb = kmalloc(sizeof(struct rchan_callbacks), GFP_KERNEL);
+		if (!rcb)
+			return -ENOMEM;
+
+		rcb->subbuf_start = NULL;
+		rcb->buf_mapped = NULL;
+		rcb->buf_unmapped = NULL;
+
+		rch = relay_open("atpdata", NULL, 256, 256, NULL);
+		if (!rch) {
+			kfree(rcb);
+			return -ENOMEM;

ENOMEM for a failed open? Seems odd to me.
Should you also set rcb = NULL?

Quoted 8 lines
drivers/usb/input/appletouch.c +8 -0
+		}
+
+		printk(KERN_INFO "appletouch: Relayfs enabled.\n");
+	}
+
+	return 0;
+}
+

drivers/usb/input/appletouch.c static int debug = 1; · line 195

Quoted 10 lines
drivers/usb/input/appletouch.c +10 -0
+static void appletouch_relayfs_exit(void)
+{
+	if (rch) {
+		printk(KERN_INFO "appletouch: Relayfs disabled\n");
+		relay_close(rch);
+		rch = NULL;
+	}
+	if (rcb) {
+		kfree(rcb);
+		rcb = NULL;

No need to check arguments to kfree.

Quoted 21 lines
drivers/usb/input/appletouch.c +10 -0
+	}
+}
+#else
+static inline void atp_relayfs_dump(struct atp *dev) { }
+static int appletouch_relayfs_init(void) { return 0; }
+static void appletouch_relayfs_exit(void) { }
+#endif
+
 static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
 			     int *z, int *fingers)
 {
@@ -194,6 +263,8 @@ static void atp_complete(struct urb* urb
 		goto exit;
 	}
 
+	atp_relayfs_dump(dev);
+
 	/* reorder the sensors values */
 	for (i = 0; i < 8; i++) {
 		/* X values */

drivers/usb/input/appletouch.c exit: · line 375

Quoted 8 lines
drivers/usb/input/appletouch.c +5 -0
@@ -297,6 +368,11 @@ exit:
 static int atp_open(struct input_dev *input)
 {
 	struct atp *dev = input->private;
+	int result;
+
+	result = appletouch_relayfs_init();
+	if (result < 0)
+		return result;

Sounds harsh to deny USB open just because relayfs couldn't be setup.

Actually, this way you could just make the init function not return anything; it doesn't matter if it fails or not -- life will go on.

Quoted 16 lines
drivers/usb/input/appletouch.c +2 -0
 	if (usb_submit_urb(dev->urb, GFP_ATOMIC))
 		return -EIO;
@@ -310,6 +386,8 @@ static void atp_close(struct input_dev *
 	struct atp *dev = input->private;
 
 	usb_kill_urb(dev->urb);
+	appletouch_relayfs_exit();
+
 	dev->open = 0;
 }
 

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#10 lore raw
Quoted 5 lines · Olof Johansson

I think I agree with previous comments regarding debug code in the driver:
It's unlikely to ever be used by more than a couple of people at very rare occasions (new hardware releases), and the barrier to using it is still high; new users need to learn how to parse the data anyway. I don't see a reason to include this in mainline.

Okay, based on your comments, please drop that patch. How about the one to support the Geyser 2 device? Should I do a rediff without relayfs support?

Greets,
Michael

maintainer
#11 lore raw
Quoted 2 lines · Michael Hanselmann
Quoted 1 line · Olof Johansson

I think I agree with previous comments regarding debug code in the driv=

er:

Quoted 3 lines
Quoted 3 lines

It's unlikely to ever be used by more than a couple of people at very rare occasions (new hardware releases), and the barrier to using it is still high; new users need to learn how to parse the data anyway. I don=

't

Quoted 6 lines
Quoted 1 line

see a reason to include this in mainline.

Okay, based on your comments, please drop that patch. How about the one to support the Geyser 2 device? Should I do a rediff without relayfs support?

If you could rediff it without relayfs I would add it to the input tree. Altough I am not sure if manually unrolling that loop is such a good idea. Maybe we should leave it to the compiler?

--
Dmitry

#12 lore raw
In reply to Olof Johansson

Olof Johansson <[email protected]> wrote:

Just saw this.

Quoted 5 lines · Michael Hanselmann
Quoted 4 lines

diff -rup linux-2.6.15-rc5.orig/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c

drivers/usb/input/appletouch.c +0 -0

[...]

Quoted 3 lines

drivers/usb/input/appletouch.c line 42

Quoted 3 lines
drivers/usb/input/appletouch.c +3 -0
+#if defined(CONFIG_RELAYFS_FS) || defined(CONFIG_RELAYFS_FS_MODULE)
+#include <linux/relayfs_fs.h>
+#endif

Why can't this be included regardless? If it does something that only makes sense if relayfs is in use, better have that decision inside the header file (least somebody just includes it and...).

Signature · 4 lines
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513