linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michal Malý" <madcatxster@devoid-pointer.net>
To: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: dmitry.torokhov@gmail.com, jkosina@suse.cz, elias.vds@gmail.com,
	anssi.hannula@iki.fi, simon@mungewell.org,
	"Michal Malý" <madcatxster@devoid-pointer.net>
Subject: [PATCH v3 22/24] hid: Port hid-lg2ff to ff-memless-next
Date: Sat, 26 Apr 2014 13:57:59 +0200	[thread overview]
Message-ID: <1398513696-12626-23-git-send-email-madcatxster@devoid-pointer.net> (raw)
In-Reply-To: <1398513696-12626-1-git-send-email-madcatxster@devoid-pointer.net>

Port hid-lg2ff to ff-memless-next.
Clamp vibration magnitude to range <0x02; 0xfd> to prevent irregular
shaking of the vibration motors.

Signed-off-by: Elias Vanderstuyft <elias.vds@gmail.com>
---
 drivers/hid/Kconfig     |  2 +-
 drivers/hid/hid-lg2ff.c | 65 ++++++++++++++++++++++++++++++++++---------------
 2 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 97d2d8f..5e70519 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -381,7 +381,7 @@ config LOGITECH_FF
 config LOGIRUMBLEPAD2_FF
 	bool "Logitech force feedback support (variant 2)"
 	depends on HID_LOGITECH
-	select INPUT_FF_MEMLESS
+	select INPUT_FF_MEMLESS_NEXT
 	help
 	  Say Y here if you want to enable force feedback support for:
 	  - Logitech RumblePad
diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
index 0e3fb1a..6ab5327 100644
--- a/drivers/hid/hid-lg2ff.c
+++ b/drivers/hid/hid-lg2ff.c
@@ -22,42 +22,69 @@
 
 
 #include <linux/input.h>
+#include <linux/input/ff-memless-next.h>
 #include <linux/slab.h>
 #include <linux/hid.h>
 
 #include "hid-lg.h"
 
+#define FF_UPDATE_RATE 8
+
 struct lg2ff_device {
 	struct hid_report *report;
 };
 
-static int play_effect(struct input_dev *dev, void *data,
-			 struct ff_effect *effect)
+static int hid_lg2ff_start_rumble(struct hid_device *hid, struct hid_report *report,
+				const struct mlnx_rumble_force *rumble)
 {
-	struct hid_device *hid = input_get_drvdata(dev);
-	struct lg2ff_device *lg2ff = data;
 	int weak, strong;
 
-	strong = effect->u.rumble.strong_magnitude;
-	weak = effect->u.rumble.weak_magnitude;
+#define CLAMP_QUIRK(x) do { if (x < 2) x = 2; else if (x > 0xfd) x = 0xfd; } \
+			while (0)
 
-	if (weak || strong) {
-		weak = weak * 0xff / 0xffff;
-		strong = strong * 0xff / 0xffff;
+	/* Scale down from MLNX range */
+	strong = rumble->strong * 0xff / 0xffff;
+	weak = rumble->weak * 0xff / 0xffff;
+	CLAMP_QUIRK(weak);
+	CLAMP_QUIRK(strong);
 
-		lg2ff->report->field[0]->value[0] = 0x51;
-		lg2ff->report->field[0]->value[2] = weak;
-		lg2ff->report->field[0]->value[4] = strong;
-	} else {
-		lg2ff->report->field[0]->value[0] = 0xf3;
-		lg2ff->report->field[0]->value[2] = 0x00;
-		lg2ff->report->field[0]->value[4] = 0x00;
-	}
+	report->field[0]->value[0] = 0x51;
+	report->field[0]->value[2] = weak;
+	report->field[0]->value[4] = strong;
 
-	hid_hw_request(hid, lg2ff->report, HID_REQ_SET_REPORT);
+	hid_hw_request(hid, report, HID_REQ_SET_REPORT);
 	return 0;
 }
 
+static int hid_lg2ff_stop_rumble(struct hid_device *hid, struct hid_report *report)
+{
+	report->field[0]->value[0] = 0xf3;
+	report->field[0]->value[2] = 0x00;
+	report->field[0]->value[4] = 0x00;
+
+	hid_hw_request(hid, report, HID_REQ_SET_REPORT);
+	return 0;
+}
+
+static int hid_lg2ff_control(struct input_dev *dev, void *data,
+				const struct mlnx_effect_command *command)
+{
+	struct hid_device *hid = input_get_drvdata(dev);
+	struct lg2ff_device *lg2ff = data;
+
+	switch (command->cmd) {
+	case MLNX_START_RUMBLE:
+		return hid_lg2ff_start_rumble(hid, lg2ff->report, &command->u.rumble_force);
+		break;
+	case MLNX_STOP_RUMBLE:
+		return hid_lg2ff_stop_rumble(hid, lg2ff->report);
+		break;
+	default:
+		dbg_hid("Unsupported effect command");
+		return -EINVAL;
+	}
+}
+
 int lg2ff_init(struct hid_device *hid)
 {
 	struct lg2ff_device *lg2ff;
@@ -78,7 +105,7 @@ int lg2ff_init(struct hid_device *hid)
 
 	set_bit(FF_RUMBLE, dev->ffbit);
 
-	error = input_ff_create_memless(dev, lg2ff, play_effect);
+	error = input_ff_create_mlnx(dev, lg2ff, hid_lg2ff_control, FF_UPDATE_RATE);
 	if (error) {
 		kfree(lg2ff);
 		return error;
-- 
1.9.2

  parent reply	other threads:[~2014-04-26 11:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-26 11:57 [PATCH v3 00/24] input: Introduce ff-memless-next as an improved replacement for ff-memless Michal Malý
2014-04-26 11:57 ` [PATCH v3 01/24] input: Add ff-memless-next module Michal Malý
2014-04-26 13:07   ` Antonio Ospite
2014-04-26 15:04     ` Michal Malý
2014-04-26 11:57 ` [PATCH v3 02/24] input: Port arizona-haptics to ff-memless-next Michal Malý
2014-04-26 11:57 ` [PATCH v3 03/24] input: Port twl4030-vibra " Michal Malý
2014-04-26 11:57 ` [PATCH v4 04/24] input: Port twl6040-vibra " Michal Malý
2014-04-26 11:57 ` [PATCH v3 05/24] input: Port max8997_haptic " Michal Malý
2014-04-26 11:57 ` [PATCH v3 06/24] input: Port pm8xxx-vibrator " Michal Malý
2014-04-26 11:57 ` [PATCH v3 07/24] hid: Port hid-axff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 08/24] hid: Port hid-emsff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 09/24] hid: Port hid-dr " Michal Malý
2014-04-26 11:57 ` [PATCH v3 10/24] hid: Port hid-gaff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 11/24] hid: Port hid-holtekff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 12/24] hid: Port hid-lgff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 13/24] hid: Port hid-lg3ff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 14/24] hid: Port hid-pl " Michal Malý
2014-04-26 11:57 ` [PATCH v3 15/24] hid: Port hid-sjoy " Michal Malý
2014-04-26 11:57 ` [PATCH v3 16/24] hid: Port hid-sony " Michal Malý
2014-04-26 13:09   ` Antonio Ospite
2014-04-26 15:05     ` Michal Malý
2014-04-26 11:57 ` [PATCH v3 17/24] hid: Port hid-tmff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 18/24] hid: Port hid-wiimote-modules " Michal Malý
2014-04-26 11:57 ` [PATCH v3 19/24] hid: Port hid-zpff " Michal Malý
2014-04-26 11:57 ` [PATCH v3 20/24] input: Port gamecon " Michal Malý
2014-04-26 11:57 ` [PATCH v3 21/24] input: Port xpad " Michal Malý
2014-04-26 11:57 ` Michal Malý [this message]
2014-04-26 11:58 ` [PATCH v3 23/24] hid: Port hid-lg4ff " Michal Malý
2014-04-26 13:50   ` Elias Vanderstuyft
2014-04-26 11:58 ` [PATCH v3 24/24] input: Replace ff-memless with ff-memless-next Michal Malý

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398513696-12626-23-git-send-email-madcatxster@devoid-pointer.net \
    --to=madcatxster@devoid-pointer.net \
    --cc=anssi.hannula@iki.fi \
    --cc=dmitry.torokhov@gmail.com \
    --cc=elias.vds@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=simon@mungewell.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).