Skip to contentSkip to conversation

Add ff-memless-next and make hid-lg4ff use it

PATCH Superseded Michal Malý 3 participants 12 messages Feb 4, 2014 – Feb 20, 2014 2 messages not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add ff-memless-next and make hid-lg4ff use it

Hi everybody,

this patch series is a result of my work to improve FFB support for memoryless devices. ff-memless-next is an improvement over the currently available ff-memless which is well suited for joypads but cannot handle more advanced devices such as racing wheels properly. As I have explained in one of RFCs regarding ff-memless-next, the extent of changes makes implementing ff-memless-next as a patch to ff-memless unfeasible. As of now there is a total of 27 drivers using ff-memless (including lg4ff) - a lot of them joypads. I do not have access to any FFB joypad at the moment so I cannot implement the functionality required to handle joypads properly - namely FF_RUMBLE and emulation of FF_PERIODIC through FF_RUMBLE.
The plan is to implement the missing functionality and replace ff-memless completely in the future.

Second part of this series ports lg4ff driver over to ff-memless-next. The immediate benefit of this is support of all periodic effects and ramp effect.

Michal M.

Michal Malý (5):
INPUT: Add ff-memless-next module
HID: Port hid-lg4ff to ff-memless-next
HID: Add support for periodic effects in hid-lg4ff
HID: Add support for ramp effect in hid-lg4ff
INPUT: Remove the note that no driver currently uses ff-memless-next from KConfig

 Documentation/input/ff-memless-next.txt | 149 ++++++
 drivers/hid/Kconfig                     |   2 +-
 drivers/hid/hid-lg4ff.c                 |  93 ++--
 drivers/input/Kconfig                   |  11 +
 drivers/input/Makefile                  |   2 +
 drivers/input/ff-memless-next.c         | 793 ++++++++++++++++++++++++++++++++
 include/linux/input/ff-memless-next.h   |  31 ++
 7 files changed, 1045 insertions(+), 36 deletions(-)

--
1.8.5.3

--
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

PATCH 1/5 Add ff-memless-next

Introduce ff-memless-next module as a possible future replacement for ff-memless.

---
 Documentation/input/ff-memless-next.txt | 149 ++++++
 drivers/input/Kconfig                   |  12 +
 drivers/input/Makefile                  |   2 +
 drivers/input/ff-memless-next.c         | 793 ++++++++++++++++++++++++++++++++
 include/linux/input/ff-memless-next.h   |  31 ++
 5 files changed, 987 insertions(+)
 create mode 100644 Documentation/input/ff-memless-next.txt
 create mode 100644 drivers/input/ff-memless-next.c
 create mode 100644 include/linux/input/ff-memless-next.h
Documentation/input/ff-memless-next.txt new file +149 -0
new file mode 100644
index 0000000..699dc04
@@ -0,0 +1,149 @@
+"ff-memless-next" force feedback module for memoryless devices.
+By Michal Malý <[email protected]> on 2013/12/21
+----------------------------------------------------------------------------
+
+1. Introduction
+~~~~~~~~~~~~~~~
+This document describes basic working principles of the "ff-memless-next"
+module and its purpose. This document also contains a summary
+of the "ff-memless-next" API and brief instructions on how to use it to write
+a hardware-specific backend with "ff-memless-next". Some specifics
+of ff-memless-next that might be of interest for userspace developers
+are also discussed.
+
+2. Basic principles of ff-memless-next
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+A lot of commonly used force feedback devices do not have a memory of their
+own. This means that it is not possible to upload a force feedback effect
+to such a device and let the device's CPU handle the playback. Instead,
+the device relies solely on its driver to tell it what force to generate.
+"ff-memless-next" was written to serve in this capacity. Its purpose is to
+calculate the overall force the device should apply and pass the result to
+a hardware-specific backend which then submits the appropriate command to
+the device.
+
+"ff-memless-next" differentiates between two types of force feedback effects,
+"combinable" and "uncombinable".
+"Combinable" effects are effects that generate a force of a given
+magnitude and direction. The magnitude can change in time according to the
+envelope of the effect and its waveform; the latter applies only to periodic
+effects. Force generated by "combinable" effect does not depend on the position
+of the device. Forces generated by each "combinable" effect that is active
+are periodically recalculated as needed and superposed into one overall force.
+"Combinable" effects are FF_CONSTANT, FF_PERIODIC and FF_RAMP.
+
+"Uncombinable" effects generate a force that depends on the position of
+the device. "ff-memless-next" assumes that the device takes care of processing
+such an effect. However, a device might have a limit on how many "uncombinable"
+effects can be active at once and this limit might be lower than the maximum
+effect count set in "ff-memless-next". "ff-memless-next" allows a
+hardware-specific driver to check whether the device is able to play
+an "uncombinable" effect. Error is reported back to userspace if the device
+cannot play the effect. The hardware-specific driver may choose not to
+perform this check in which case the userspace will have no way of knowing
+whether an "uncombinable" effect is really being played or not.
+"Uncombinable" effects are FF_DAMPER, FF_FRICTION, FF_INERTIA and FF_SPRING.
+
+FF_CUSTOM is currently not handled by "ff-memless-next".
+
+3. API provided by "ff-memless-next"
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+"ff-memless-next" provides an API for developers of hardware-specific
+drivers. In order to use the API, the hardware-specific driver should
+include <linux/input/ff-memless-next.h>
+Functions and structs defined by this API are:
+
+int input_ff_create_mlnx(struct input_dev *dev, void *data,
+			 int(*control_effect)(struct input_dev *, void *, const struct mlnx_effect_command *),
+			 const u16 update_rate)
+- Any hardware-specific driver that wants to use "ff-memless-next" must call
+this function. The function takes care of creating and registering a force
+feedback device within the kernel. It also initializes resources needed by
+"ff-memless-next" to handle a new device. No other initialization steps are necessary.
+	Parameters:
+	* dev - pointer to valid struct input_dev
+	* data - pointer to custom data the hardware-specific backend
+		 might need to pass to the control_effect() callback function
+		 (discussed later). * data will be freed automatically by
+		 "ff-memless-next" upon device's destruction.
+	* control_effect - A callback function. "ff-memless-next" will call
+			   this function when it is done processing effects.
+			   Implementation of control_effect() in the
+			   hardware-specific driver should create an appropriate
+			   command and submit it to the device.
+			   This function is called with dev->event_lock
+			   spinlock held.
+	update_rate - Rate in milliseconds at which envelopes and periodic
+		      effects are recalculated. Minimum value is limited by the
+		      kernel timer resolution and changes with value of
+		      CONFIG_HZ.
+
+struct mlnx_effect_command
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+- This struct is passed to the hardware-specific backend in
+the control_effect() function. See "ff-memless-next.h" for details.
+
+enum mlnx_commands
+^^^^^^^^^^^^^^^^^^
+- Types of commands generated by ff-memless-next
+	MLNX_START_COMBINED - Start or update "combinable" effect
+	MLNX_STOP_COMBINED - Stop "combinable" effect. In most cases this means
+			     to set the force to zero.
+	MLNX_UPLOAD_UNCOMB - Check if the device can accept and play
+			     "uncombinable" effect.
+			     Hardware-specific driver should return 0
+			     on success.
+	MLNX_START_UNCOMB - Start playback of "uncombinable" effect.
+	MLNX_STOP_UNCOMB - Stop playback of "uncombinable" effect.
+
+struct mlnx_simple_force
+^^^^^^^^^^^^^^^^^^^^^^^^
+	x - overall force along X axis
+	y - overall force along Y axis
+
+struct mlnx_uncomb_effect
+^^^^^^^^^^^^^^^^^^^^^^^^^
+- Information about "uncombinable" effect.
+	id - internal ID of the effect
+	* effect - pointer to the internal copy of the effect kept by
+		   "ff-memless-next". This pointer will remain valid until
+		   the effect is removed.
+
+Sample implementation of a dummy driver that uses "ff-memless-next" is
+available at "git://prifuk.cz/ff-dummy-device". Link to the source will
+be kept up to date.
+
+Direction of the effect's force translates to Cartesian coordinates system
+as follows:
+  Direction = 0: Down
+  Direction (0; 16384): 3rd quadrant
+  Direction = 16384: Left
+  Direction (16385; 32768): 2nd quadrant
+  Direction = 32768: Up
+  Direction (32769; 49152): 1st quadrant
+  Direction = 49152: Right
+  Direction (49153; 65535) :4th quadrant
+  Direction = 65565: Down
+
+4. Specifics of "ff-memless-next" for userspace developers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+None of the persons involved in development or testing of "ff-memless-next"
+is aware of any reference force feedback specifications. "ff-memless-next"
+tries to adhere to Microsoft's DirectInput specifications because we
+believe that is what most developers have experience with.
+
+- Waveforms of periodic effects do not start at the origin, but as follows:
+	SAW_UP: At minimum
+	SAW_DOWN: At maximum
+	SQUARE: At maximum
+	TRIANGLE: At maximum
+	SINE: At origin
+
+- Updating periodic effects:
+	- All periodic effects are restarted when their parameters are updated.
+
+- Updating effects of finite duration:
+	- Once an effect of finite length finishes playing, it is considered
+	  stopped. Only effects that are playing can be updated on the fly.
+	  Therefore effects of finite duration can be updated only until
+	  they finish playing.
drivers/input/Kconfig +12 -0
index a11ff74..4371a12 100644
@@ -77,6 +77,18 @@ config INPUT_MATRIXKMAP
 	  To compile this driver as a module, choose M here: the
 	  module will be called matrix-keymap.
 
+config INPUT_FF_MEMLESS_NEXT
+	tristate "New version of support for memoryless force feedback devices"
+	help
+	  Say Y here if you want to enable support for various memoryless
+	  force feedback devices (as of now there is no hardware-specific
+	  driver that supports this).
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ff-memless-next.
+
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
drivers/input/Makefile +2 -0
index 5ca3f63..269a22d 100644
@@ -16,6 +16,8 @@ obj-$(CONFIG_INPUT_MOUSEDEV)	+= mousedev.o
 obj-$(CONFIG_INPUT_JOYDEV)	+= joydev.o
 obj-$(CONFIG_INPUT_EVDEV)	+= evdev.o
 obj-$(CONFIG_INPUT_EVBUG)	+= evbug.o
+obj-$(CONFIG_INPUT_MATRIXKMAP)	+= matrix-keymap.o
+obj-$(CONFIG_INPUT_FF_MEMLESS_NEXT)	+= ff-memless-next.o
 
 obj-$(CONFIG_INPUT_KEYBOARD)	+= keyboard/
 obj-$(CONFIG_INPUT_MOUSE)	+= mouse/
drivers/input/ff-memless-next.c new file +793 -0

793 lines not on this page · raw message

include/linux/input/ff-memless-next.h new file +31 -0
new file mode 100644
index 0000000..f2fb080
@@ -0,0 +1,31 @@
+#include <linux/input.h>
+
+enum mlnx_commands {
+	MLNX_START_COMBINED,
+	MLNX_STOP_COMBINED,
+	MLNX_START_UNCOMB,
+	MLNX_STOP_UNCOMB,
+	MLNX_UPLOAD_UNCOMB
+};
+
+struct mlnx_simple_force {
+	const s32 x;
+	const s32 y;
+};
+
+struct mlnx_uncomb_effect {
+	const int id;
+	const struct ff_effect *effect;
+};
+
+struct mlnx_effect_command {
+	const enum mlnx_commands cmd;
+	union {
+		const struct mlnx_simple_force simple_force;
+		const struct mlnx_uncomb_effect uncomb;
+	} u;
+};
+
+int input_ff_create_mlnx(struct input_dev *dev, void *data,
+			 int(*control_effect)(struct input_dev *, void *, const struct mlnx_effect_command *),
+			 const u16 update_rate);
Signature · 7 lines
1.8.5.3


--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH 2/5 Port hid-lg4ff to ff-memless-next

Port hid-lg4ff to ff-memless-next.

---
 drivers/hid/Kconfig     |  2 +-
 drivers/hid/hid-lg4ff.c | 86 +++++++++++++++++++++++++++++--------------------
 2 files changed, 52 insertions(+), 36 deletions(-)
drivers/hid/Kconfig +1 -1
index 34e2d39..31c4b43 100644
@@ -389,7 +389,7 @@ config LOGIG940_FF
 config LOGIWHEELS_FF
 	bool "Logitech wheels configuration and force feedback support"
 	depends on HID_LOGITECH
-	select INPUT_FF_MEMLESS
+	select INPUT_FF_MEMLESS_NEXT
 	default LOGITECH_FF
 	help
 	  Say Y here if you want to enable force feedback and range setting
drivers/hid/hid-lg4ff.c +51 -35

117 lines not on this page · raw message

Signature · 1 line
1.8.5.3
#3 lore raw

PATCH 3/5 Add support for periodic effects in hid-lg4ff

Add support for periodic effects in hid-lg4ff

---
 drivers/hid/hid-lg4ff.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/hid/hid-lg4ff.c +6 -0
index f236b9f..c82b02c 100644
@@ -71,6 +71,12 @@ struct lg4ff_device_entry {
 
 static const signed short lg4ff_wheel_effects[] = {
 	FF_CONSTANT,
+	FF_PERIODIC,
+	FF_SQUARE,
+	FF_TRIANGLE,
+	FF_SINE,
+	FF_SAW_UP,
+	FF_SAW_DOWN,
 	FF_AUTOCENTER,
 	-1
 };
Signature · 7 lines
1.8.5.3


--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH 4/5 Add support for ramp effect in hid-lg4ff

Add support for ramp effect in hid-lg4ff

---
 drivers/hid/hid-lg4ff.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/hid-lg4ff.c +1 -0
index c82b02c..75245cc 100644
@@ -71,6 +71,7 @@ struct lg4ff_device_entry {
 
 static const signed short lg4ff_wheel_effects[] = {
 	FF_CONSTANT,
+	FF_RAMP,
 	FF_PERIODIC,
 	FF_SQUARE,
 	FF_TRIANGLE,
Signature · 7 lines
1.8.5.3


--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

PATCH 5/5 Remove the note that no driver currently uses ff-memless-next

Remove the note that no driver currently uses ff-memless-next

---
 drivers/input/Kconfig | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/Kconfig +1 -2
index 4371a12..ba05100 100644
@@ -81,8 +81,7 @@ config INPUT_FF_MEMLESS_NEXT
 	tristate "New version of support for memoryless force feedback devices"
 	help
 	  Say Y here if you want to enable support for various memoryless
-	  force feedback devices (as of now there is no hardware-specific
-	  driver that supports this).
+	  force feedback devices.
 
 	  If unsure, say N.
 
Signature · 7 lines
1.8.5.3


--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

Re: [PATCH 2/5] Port hid-lg4ff to ff-memless-next

In reply to a message not in the archive

Hi,

I have simply taken what we have right now and ported it over to ff-mlnx. I believe that any improvements based on the previous investigation should go into another series because we most certainly don't want to introduce any regressions.

Michal

#8 lore raw

Re: [PATCH 2/5] Port hid-lg4ff to ff-memless-next

Quoted 8 lines · On Wednesday 05 of February 2014 00:54:45 Michal Malý wrote:

Hi,

I have simply taken what we have right now and ported it over to ff-mlnx. I believe that any improvements based on the previous investigation should go into another series because we most certainly don't want to introduce any regressions.

Michal

Ahh... please disregard this. 2/5 should have the same fix for zero force as we have right now - it should effectively stop the effect when the force is zero.

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [PATCH 2/5] Port hid-lg4ff to ff-memless-next

Quoted 5 lines

Ahh... please disregard this. 2/5 should have the same fix for zero force as
we have right now - it should effectively stop the effect when the force is zero.

Hi,
We need to think carefully on this as a '+10' combined with '-10' force will result in '0'; however we do not want to deactivate the wheel (no-resistance mode) as this will result in 'ticking' on the wheel as force transitions through 0.... ideally we'd need to know that there are no forces set.

I'll attempt to build these patches this week and give them a test, Simon.

#11 lore raw

Re: [PATCH 2/5] Port hid-lg4ff to ff-memless-next

In reply to a message not in the archive
Quoted 14 lines · On Wednesday 05 of February 2014 09:41:16 you wrote:
Quoted 6 lines · On Wed, Feb 5, 2014 at 1:08 AM, <[email protected]> wrote:
Quoted 5 lines

Ahh... please disregard this. 2/5 should have the same fix for zero force
as
we have right now - it should effectively stop the effect when the force is zero.

Quoted 6 lines

Hi,
We need to think carefully on this as a '+10' combined with '-10' force will result in '0'; however we do not want to deactivate the wheel (no-resistance mode) as this will result in 'ticking' on the wheel as force transitions through 0.... ideally we'd need to know that there are no forces set.

Quoted 4 lines

No problem Simon, this is thought about:
If forces are active, and they cancel out, hid_lg4ff_start_combined is called with 0 force (scaled_x = 0x80), instead of hid_lg4ff_stop_combined as you assumed.

Okay, so to set things straight: I should modify to patch to send 0x13 when the effect is fully stopped and use 0x11 0x80 to only zeroize the force when the overall force is zero? My DFP doesn't differentiate between these states so I cannot tell what is the right thing to do.

Michal

#12 lore raw

Re: [PATCH 2/5] Port hid-lg4ff to ff-memless-next

Quoted 11 lines · Michal Malý
Quoted 10 lines
Quoted 5 lines

We need to think carefully on this as a '+10' combined with '-10' force will result in '0'; however we do not want to deactivate the wheel (no-resistance mode) as this will result in 'ticking' on the wheel as force transitions through 0.... ideally we'd need to know that there are no forces set.

No problem Simon, this is thought about:
If forces are active, and they cancel out, hid_lg4ff_start_combined is called with 0 force (scaled_x = 0x80), instead of hid_lg4ff_stop_combined as you assumed.

Quoted 4 lines

Okay, so to set things straight: I should modify to patch to send 0x13 when the effect is fully stopped and use 0x11 0x80 to only zeroize the force when the overall force is zero? My DFP doesn't differentiate between these states so I cannot tell what is the right thing to do.

Has there been any conclusion to this, please?

Signature · 6 lines
Jiri Kosina
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

Re: [PATCH 2/5] Port hid-lg4ff to ff-memless-next

Quoted 15 lines · On Thursday 20 of February 2014 16:16:52 Jiri Kosina wrote:
Quoted 14 lines · Michal Malý
Quoted 13 lines
Quoted 7 lines

We need to think carefully on this as a '+10' combined with '-10' force
will result in '0'; however we do not want to deactivate the wheel (no-resistance mode) as this will result in 'ticking' on the wheel as force transitions through 0.... ideally we'd need to know that there are
no forces set.

No problem Simon, this is thought about:
If forces are active, and they cancel out, hid_lg4ff_start_combined is called with 0 force (scaled_x = 0x80), instead of hid_lg4ff_stop_combined
as you assumed.

Quoted 7 lines
Quoted 5 lines

Okay, so to set things straight: I should modify to patch to send 0x13 when
the effect is fully stopped and use 0x11 0x80 to only zeroize the force when the overall force is zero? My DFP doesn't differentiate between these states so I cannot tell what is the right thing to do.

Has there been any conclusion to this, please?

Yes the has and the necessary fix is already in place in my working copy along with another few fixed to the ff-memless-next. Do you consider our approach sane and viable for mainlining? I've already explained to Joe Perches why I propose ff-memless-next as a separate module rather than a patch to ff-memless we have now. Unless anybody has any objections I'll check in with the rest of the guys and submit a hopefully final version within a day or two.

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html