+ joydevc-automatic-re-calibration.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     joydev.c automatic re-calibration
has been added to the -mm tree.  Its filename is
     joydevc-automatic-re-calibration.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: joydev.c automatic re-calibration
From: "Renato Golin" <rengolin@xxxxxxxxx>

Add the automatic recalibration feature without spoiling previously
calibrated devices.  It's a fix for those joysticks that report faulty
range, specially Saitek Cyborg Evo Force.

File: drivers/input/joydev.c
Fix:

- extracted code from joydev_connect to method
  joydev_calculate_correction to be able to call it from both joydev_event
  upon recalibration and joydev_connect during first connection.

- on joydev_connect check ranges and zero calibration if found out of range

- on joydev_event, every time found out of range, update min/max and
  recalculate the correction

Cc: Dmitry Torokhov <dtor@xxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 drivers/input/joydev.c |   41 +++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff -puN drivers/input/joydev.c~joydevc-automatic-re-calibration drivers/input/joydev.c
--- a/drivers/input/joydev.c~joydevc-automatic-re-calibration
+++ a/drivers/input/joydev.c
@@ -52,6 +52,8 @@ struct joydev {
 	__u8 absmap[ABS_MAX + 1];
 	__u8 abspam[ABS_MAX + 1];
 	__s16 abs[ABS_MAX + 1];
+	__s16 absmin[ABS_MAX + 1];
+	__s16 absmax[ABS_MAX + 1];
 };
 
 struct joydev_client {
@@ -66,6 +68,19 @@ struct joydev_client {
 
 static struct joydev *joydev_table[JOYDEV_MINORS];
 
+static void joydev_calculate_correction(int min, int max, int axis, struct joydev *joydev)
+{
+	int t, j = joydev->abspam[axis];
+	int flat = joydev->handle.dev->absflat[j];
+
+	joydev->corr[axis].coef[0] = (max + min) / 2 - flat;
+	joydev->corr[axis].coef[1] = (max + min) / 2 + flat;
+	if (!(t = ((max - min) / 2 - 2 * flat)))
+		return;
+	joydev->corr[axis].coef[2] = (1 << 29) / t;
+	joydev->corr[axis].coef[3] = (1 << 29) / t;
+}
+
 static int joydev_correct(int value, struct js_corr *corr)
 {
 	switch (corr->type) {
@@ -102,6 +117,14 @@ static void joydev_event(struct input_ha
 		case EV_ABS:
 			event.type = JS_EVENT_AXIS;
 			event.number = joydev->absmap[code];
+			/* recalibration if needed */
+			if (value < joydev->absmin[code]) {
+				joydev->absmin[code] = value;
+				joydev_calculate_correction(value, joydev->absmax[code], code, joydev);
+			} else if (value > joydev->absmax[code]) {
+				joydev->absmax[code] = value;
+				joydev_calculate_correction(joydev->absmin[code], value, code, joydev);
+			}
 			event.value = joydev_correct(value, joydev->corr + event.number);
 			if (event.value == joydev->abs[event.number])
 				return;
@@ -483,7 +506,7 @@ static int joydev_connect(struct input_h
 	struct joydev *joydev;
 	struct class_device *cdev;
 	dev_t devt;
-	int i, j, t, minor;
+	int i, j, minor;
 	int error;
 
 	for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++);
@@ -530,19 +553,21 @@ static int joydev_connect(struct input_h
 
 	for (i = 0; i < joydev->nabs; i++) {
 		j = joydev->abspam[i];
-		if (dev->absmax[j] == dev->absmin[j]) {
+		joydev->absmin[i] = dev->absmin[j];
+		joydev->absmax[i] = dev->absmax[j];
+		if (joydev->absmax[i] == joydev->absmin[i]) {
 			joydev->corr[i].type = JS_CORR_NONE;
 			joydev->abs[i] = dev->abs[j];
 			continue;
 		}
 		joydev->corr[i].type = JS_CORR_BROKEN;
 		joydev->corr[i].prec = dev->absfuzz[j];
-		joydev->corr[i].coef[0] = (dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j];
-		joydev->corr[i].coef[1] = (dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j];
-		if (!(t = ((dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j])))
-			continue;
-		joydev->corr[i].coef[2] = (1 << 29) / t;
-		joydev->corr[i].coef[3] = (1 << 29) / t;
+
+		if (dev->abs[j] > joydev->absmax[i] || dev->abs[j] < joydev->absmin[i]) {
+			printk("Joydev: Bad axis range, recalibrating automatically\n");
+			joydev_calculate_correction(0, 0, i, joydev);
+		} else
+			joydev_calculate_correction(joydev->absmin[i], joydev->absmax[i], i, joydev);
 
 		joydev->abs[i] = joydev_correct(dev->abs[j], joydev->corr + i);
 	}
_

Patches currently in -mm which might be from rengolin@xxxxxxxxx are

joydevc-automatic-re-calibration.patch

-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux