Skip to contentSkip to conversation

hid: add force feedback support for SmartJoy PLUS PS2/USB adapter

PATCH Superseded Jussi Kivilinna 8 participants 14 messages May 8, 2009 – Jun 2, 2009 2 messages not in the archive HID

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hid: add force feedback support for SmartJoy PLUS PS2/USB adapter

This driver adds force feedback support for SmartJoy PLUS PS2/USB adapter. I made this driver one device spesific instead of making generic 'wisegroup-ff' because I have another Wisegroup PS2/USB adapter that doesn't work same way as SmartJoy PLUS. If another device that is compatible pops up, this driver could be then renamed to something more generic.

---

 drivers/hid/Kconfig      |    8 ++
 drivers/hid/Makefile     |    1 
 drivers/hid/hid-core.c   |    3 +
 drivers/hid/hid-ids.h    |    1 
 drivers/hid/hid-sjoyff.c |  175 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 188 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hid/hid-sjoyff.c
drivers/hid/Kconfig +8 -0
index 7e67dcb..d473956 100644
@@ -256,6 +256,14 @@ config GREENASIA_FF
 	(like MANTA Warrior MM816 and SpeedLink Strike2 SL-6635) or adapter
 	and want to enable force feedback support for it.
 
+config SMARTJOYPLUS_FF
+	tristate "SmartJoy PLUS PS2/USB adapter force feedback support"
+	depends on USB_HID
+	select INPUT_FF_MEMLESS
+	---help---
+	Say Y here if you have a SmartJoy PLUS PS2/USB adapter and want to
+	enable force feedback support for it.
+
 config HID_TOPSEED
 	tristate "TopSeed Cyberlink remote control support" if EMBEDDED
 	depends on USB_HID
drivers/hid/Makefile +1 -0
index 1f7cb0f..d86c4f1 100644
@@ -37,6 +37,7 @@ obj-$(CONFIG_HID_SAMSUNG)	+= hid-samsung.o
 obj-$(CONFIG_HID_SONY)		+= hid-sony.o
 obj-$(CONFIG_HID_SUNPLUS)	+= hid-sunplus.o
 obj-$(CONFIG_GREENASIA_FF)	+= hid-gaff.o
+obj-$(CONFIG_SMARTJOYPLUS_FF)	+= hid-sjoyff.o
 obj-$(CONFIG_THRUSTMASTER_FF)	+= hid-tmff.o
 obj-$(CONFIG_HID_TOPSEED)	+= hid-topseed.o
 obj-$(CONFIG_ZEROPLUS_FF)	+= hid-zpff.o
drivers/hid/hid-core.c +3 -0
index 8551693..8a215d4 100644
@@ -1312,6 +1312,9 @@ static const struct hid_device_id hid_blacklist[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
+#if defined(CONFIG_SMARTJOYPLUS_FF) || defined(CONFIG_SMARTJOYPLUS_FF_MODULE)
+	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
+#endif
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
 
drivers/hid/hid-ids.h +1 -0
index aa1b995..61950e2 100644
@@ -411,6 +411,7 @@
 #define USB_VENDOR_ID_WACOM		0x056a
 
 #define USB_VENDOR_ID_WISEGROUP		0x0925
+#define USB_DEVICE_ID_SMARTJOY_PLUS	0x0005
 #define USB_DEVICE_ID_1_PHIDGETSERVO_20	0x8101
 #define USB_DEVICE_ID_4_PHIDGETSERVO_20	0x8104
 #define USB_DEVICE_ID_8_8_4_IF_KIT	0x8201
drivers/hid/hid-sjoyff.c new file +175 -0

175 lines not on this page · raw message

#1 lore raw

Am Freitag, 8. Mai 2009 09:46:36 schrieb Jussi Kivilinna:

Quoted 7 lines

+static int sj_probe(struct hid_device *hdev, const struct hid_device_id *id) +{
+       int ret;

drivers/hid/hid-sjoyff.c new file +4 -0
+
+       ret = hid_parse(hdev);
+       if (ret) {
+               dev_err(&hdev->dev, "parse failed\n");

drivers/hid/hid-sjoyff.c line 141

Quoted 10 lines
drivers/hid/hid-sjoyff.c new file +10 -0
+               goto err;
+       }
+
+       ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
+       if (ret) {
+               dev_err(&hdev->dev, "hw start failed\n");
+               goto err;
+       }
+
+       sjoyff_init(hdev);

Do you really want to ignore errors this returns?

Regards
Oliver

#3 lore raw
In reply to a message not in the archive

Quoting "Oliver Neukum" <[email protected]>:

Quoted 21 lines

Am Freitag, 8. Mai 2009 09:46:36 schrieb Jussi Kivilinna:

Quoted 7 lines

+static int sj_probe(struct hid_device *hdev, const struct hid_device_id *id) +{
+       int ret;

drivers/hid/hid-sjoyff.c new file +4 -0
+
+       ret = hid_parse(hdev);
+       if (ret) {
+               dev_err(&hdev->dev, "parse failed\n");

drivers/hid/hid-sjoyff.c line 141

Quoted 10 lines
drivers/hid/hid-sjoyff.c new file +10 -0
+               goto err;
+       }
+
+       ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
+       if (ret) {
+               dev_err(&hdev->dev, "hw start failed\n");
+               goto err;
+       }
+
+       sjoyff_init(hdev);

Do you really want to ignore errors this returns?

Quoted 3 lines

Regards
Oliver

It's done same in hid-pl.c & hid-gaff.c which I used base for this driver. I'd say yes, ignoring return sjoyff_init is ok. If ff-setup fails adapter will still be usable (but without ff). This is actually what happened when I tried this driver with other Wisegroup adapter.

-Jussi

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

#4 lore raw
In reply to Jussi Kivilinna
Quoted 6 lines · Jussi Kivilinna

This driver adds force feedback support for SmartJoy PLUS PS2/USB adapter. I made this driver one device spesific instead of making generic 'wisegroup-ff' because I have another Wisegroup PS2/USB adapter that doesn't work same way as SmartJoy PLUS. If another device that is compatible pops up, this driver could be then renamed to something more generic.

Thanks for writing the driver!

drivers/hid/hid-core.c static const struct hid_device_id hid_blacklist[] = { · line 1319

Quoted 11 lines
drivers/hid/hid-core.c +3 -0
@@ -1312,6 +1312,9 @@ static const struct hid_device_id hid_blacklist[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
+#if defined(CONFIG_SMARTJOYPLUS_FF) || defined(CONFIG_SMARTJOYPLUS_FF_MODULE)
+	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
+#endif
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },

Hmm, this isn't really compatible with what we have for other drivers, we require the config option to be turned on in order to have support (i.e. we include them into hid_blacklist unconditionally).

Otherwise the driver looks OK.

Jiri, what do you think?

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#5 lore raw
Quoted 11 lines · Jiri Kosina
Quoted 6 lines · Jussi Kivilinna

This driver adds force feedback support for SmartJoy PLUS PS2/USB adapter. I made this driver one device spesific instead of making generic 'wisegroup-ff' because I have another Wisegroup PS2/USB adapter that doesn't work same way as SmartJoy PLUS. If another device that is compatible pops up, this driver could be then renamed to something more generic.

Thanks for writing the driver!

Quoted 15 lines

drivers/hid/hid-core.c static const struct hid_device_id hid_blacklist[] = { · line 1319

Quoted 11 lines
drivers/hid/hid-core.c +3 -0
@@ -1312,6 +1312,9 @@ static const struct hid_device_id hid_blacklist[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
+#if defined(CONFIG_SMARTJOYPLUS_FF) || defined(CONFIG_SMARTJOYPLUS_FF_MODULE)
+	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
+#endif
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },

Hmm, this isn't really compatible with what we have for other drivers, we require the config option to be turned on in order to have support (i.e. we include them into hid_blacklist unconditionally).

Strictly speaking, it depends on whether the device is able to be managed by the generic layer or not. And it seems it can; this driver adds only a FF support. If we disabled the FF support in the config and the #if macro wasn't there, we would lose the device completely even though it can be handled by the core, without FF though.

So I think, in this particular case, it is OK to have the conditional line in there.

Or maybe better, to not taint the core code by such a bloat, leave conditonal only the part of the driver which takes care of FF. The rest of the driver (only the init/deinit) would be left as unable-to-disable if !EMBEDDED, like other drivers.

I mean, two Kconfig entries, driver and FF support, driver is built always if !EMBEDDED, FF is optional and dependent on the driver. CONFIG_SMARTJOYPLUS_FF is then around sjoyff_init and *_play.

Here comes some of my comments to the rest:

+#define debug(format, arg...) pr_debug("hid-sjoyff: " format "\n" , ## arg)

Define pr_fmt instead of this.

+static int hid_sjoyff_play(struct input_dev *dev, void *data,
+ struct ff_effect *effect)
+{
+ struct hid_device *hid = input_get_drvdata(dev);
+ struct sjoyff_device *sjoyff = data;
+ u32 left, right;
+
+ left = effect->u.rumble.strong_magnitude;
+ right = effect->u.rumble.weak_magnitude;
+ debug("called with 0x%08x 0x%08x", left, right);
+
+ left = left * 0xff / 0xffff;

Confused here, * ff / ffff, what's the point? Is there any difference with left /= 0xff?

Thanks for the driver.

#7 lore raw
In reply to a message not in the archive
Quoted 5 lines · Jiri Slaby

Strictly speaking, it depends on whether the device is able to be managed by the generic layer or not. And it seems it can; this driver adds only a FF support. If we disabled the FF support in the config and the #if macro wasn't there, we would lose the device completely even though it can be handled by the core, without FF though.

That was exactly my point, yes.

Quoted 2 lines

So I think, in this particular case, it is OK to have the conditional line in there.

Actually this should be the case at least for

- all drivers which implement only force feedback features
- all drivers which only add additional key mappings

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

So I think, in this particular case, it is OK to have the conditional line in there.

Actually this should be the case at least for

- all drivers which implement only force feedback features
- all drivers which only add additional key mappings

Yeah, this is correct point and it looks very scary. Let me think about it.

#11 lore raw
In reply to a message not in the archive

Quoting "Jiri Slaby" <[email protected]>:

Quoted 30 lines · Jiri Kosina
Quoted 20 lines · Jussi Kivilinna
Quoted 7 lines

This driver adds force feedback support for SmartJoy PLUS PS2/USB adapter. I made this driver one device spesific instead of making generic 'wisegroup-ff' because I have another Wisegroup PS2/USB adapter that doesn't work same way as SmartJoy PLUS. If another device that is compatible pops up, this driver could be then renamed to something more generic.

Thanks for writing the driver!

Quoted 9 lines
drivers/hid/hid-core.c +1 -0
@@ -1312,6 +1312,9 @@ static const struct hid_device_id hid_blacklist[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED,  
 USB_DEVICE_ID_TOPSEED_CYBERLINK) },
+#if defined(CONFIG_SMARTJOYPLUS_FF) ||  
 defined(CONFIG_SMARTJOYPLUS_FF_MODULE)
Quoted 8 lines
Quoted 4 lines
drivers/hid/hid-core.c +2 -0
+	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
+#endif
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },

{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },

Hmm, this isn't really compatible with what we have for other drivers, we require the config option to be turned on in order to have support (i.e. we include them into hid_blacklist unconditionally).

Quoted 6 lines

Strictly speaking, it depends on whether the device is able to be managed by the generic layer or not. And it seems it can; this driver adds only a FF support. If we disabled the FF support in the config and the #if macro wasn't there, we would lose the device completely even though it can be handled by the core, without FF though.

Yes, it works with generic layer. This problem exists with some other FF drivers as well, devices would work without FF support.

Quoted 12 lines

So I think, in this particular case, it is OK to have the conditional line in there.

Or maybe better, to not taint the core code by such a bloat, leave conditonal only the part of the driver which takes care of FF. The rest of the driver (only the init/deinit) would be left as unable-to-disable if !EMBEDDED, like other drivers.

I mean, two Kconfig entries, driver and FF support, driver is built always if !EMBEDDED, FF is optional and dependent on the driver. CONFIG_SMARTJOYPLUS_FF is then around sjoyff_init and *_play.

Ok, the same way as hid-pl.c?

I think hid-gaff.c/drff.c/tmff.c should do this as well.

Quoted 21 lines

Here comes some of my comments to the rest:

+#define debug(format, arg...) pr_debug("hid-sjoyff: " format "\n" , ## arg)

Define pr_fmt instead of this.

drivers/hid/hid-sjoyff.c new file +12 -0
+static int hid_sjoyff_play(struct input_dev *dev, void *data,
+			 struct ff_effect *effect)
+{
+	struct hid_device *hid = input_get_drvdata(dev);
+	struct sjoyff_device *sjoyff = data;
+	u32 left, right;
+
+	left = effect->u.rumble.strong_magnitude;
+	right = effect->u.rumble.weak_magnitude;
+	debug("called with 0x%08x 0x%08x", left, right);
+
+	left = left * 0xff / 0xffff;
Quoted 2 lines

Confused here, * ff / ffff, what's the point? Is there any difference with left /= 0xff?

It would actually be "left /= 0x101", and not as informative as "0xff / 0xffff".

Quoted 4 lines

Thanks for the driver.

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

#12 lore raw
In reply to Jiri Slaby
Quoted 5 lines · Jiri Slaby

Here comes some of my comments to the rest:

+#define debug(format, arg...) pr_debug("hid-sjoyff: " format "\n" , ## arg)

Define pr_fmt instead of this.

No, please use dev_dbg() instead of creating a new macro.

thanks,

greg k-h

#13 lore raw
Quoted 8 lines · Greg KH
Quoted 5 lines · Jiri Slaby

Here comes some of my comments to the rest:

+#define debug(format, arg...) pr_debug("hid-sjoyff: " format "\n" , ## arg)

Define pr_fmt instead of this.

No, please use dev_dbg() instead of creating a new macro.

No, unfortunately there is no struct device available in the two functions he uses this macro in.

It should look like

#define pr_fmt(fmt) "hid-sjoyff: " fmt "\n"

and then use pr_debug as usual.

In other places he correctly uses dev_* stuff.

Thanks.

#14 lore raw
Quoted 13 lines · Jiri Slaby
Quoted 8 lines · Greg KH
Quoted 5 lines · Jiri Slaby

Here comes some of my comments to the rest:

+#define debug(format, arg...) pr_debug("hid-sjoyff: " format "\n" , ## arg)

Define pr_fmt instead of this.

No, please use dev_dbg() instead of creating a new macro.

No, unfortunately there is no struct device available in the two functions he uses this macro in.

Quoted 7 lines

It should look like

#define pr_fmt(fmt) "hid-sjoyff: " fmt "\n"

and then use pr_debug as usual.

In other places he correctly uses dev_* stuff.

Oh, ok, yes, that's correct, sorry for not looking closer.

greg k-h

#15 lore raw
Quoted 16 lines · Greg KH
Quoted 15 lines · Jiri Slaby
Quoted 8 lines · Greg KH
Quoted 5 lines · Jiri Slaby

Here comes some of my comments to the rest:

+#define debug(format, arg...) pr_debug("hid-sjoyff: " format "\n" , ## arg)

Define pr_fmt instead of this.

No, please use dev_dbg() instead of creating a new macro.

No, unfortunately there is no struct device available in the two functions he uses this macro in.

It should look like

Quoted 7 lines
Quoted 5 lines

#define pr_fmt(fmt) "hid-sjoyff: " fmt "\n"

and then use pr_debug as usual.

In other places he correctly uses dev_* stuff.

Oh, ok, yes, that's correct, sorry for not looking closer.

Oh my, that's me, who was wrong, sorry. The play has struct device available, indeed. -ETOOFEWCOFFEIN

Jussi: please fix that up by using dev_dbg without any prefixes or so.

#9 lore raw
In reply to Jiri Slaby
Quoted 10 lines · Jiri Slaby
Quoted 7 lines · Jiri Kosina
Quoted 2 lines

So I think, in this particular case, it is OK to have the conditional line in there.

Actually this should be the case at least for

- all drivers which implement only force feedback features
- all drivers which only add additional key mappings

Yeah, this is correct point and it looks very scary. Let me think about it.

Hmm, if we could do something like plugins, which would just add some functionality without unbinding a device form a generic driver, it would be good.

Plugins would be the same as drivers, except ll_driver won't be stopped and generic would still drive the device. It means plugins can't have report_fixup defined.

We would need to introduce hid_disconnect, call it on register_driver, do the additional mapping, mask out FF connect bit or whatever other operation the plugin needs. This would be performed the same way as it is currently, except plugin probe won't call parse and hw_start, but only connect with proper flags.

This will cover most of current drivers and hence we might eliminate almost all blacklisted entries (except the ones for drivers with report_fixup).

Caveats:
* events come even when stopped: drop (or hold) events until inputs are connected again
* complexity: added complexity, slowdown in initialization and handling
* "start-stop-start" on bootup: each bootup will start with generic, disconnect inputs (a plugin came), connect inputs by a plugin
* plugins removal: we need to go through stop-start again
* anything I don't see?

Ideas, comments, improvements?

#10 lore raw
Quoted 3 lines · Jiri Slaby

This will cover most of current drivers and hence we might eliminate almost all blacklisted entries (except the ones for drivers with report_fixup).

Which is OK, as usually they wouldn't work at all anyway without fixed report descriptor (or will be behaving in unexpected bogus way). The other features (force feedback and missing mappings) are not that crucial anyway.

Plus, my longer-term intention is to move all the special mapping into HAL.

Quoted 3 lines

Caveats:
* events come even when stopped: drop (or hold) events until inputs are connected again

By this you mean the short window start-stop-start during bootup, or something else?

Quoted 1 line

* complexity: added complexity, slowdown in initialization and handling

The slowdown shouldn't really be problem in case of HID, the devices themselves are usually pretty slow.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs