Release 4.12 drivers/hid/hid-tmff.c
  
  
  
/*
 * Force feedback support for various HID compliant devices by ThrustMaster:
 *    ThrustMaster FireStorm Dual Power 2
 * and possibly others whose device ids haven't been added.
 *
 *  Modified to support ThrustMaster devices by Zinx Verituse
 *  on 2003-01-25 from the Logitech force feedback driver,
 *  which is by Johann Deneux.
 *
 *  Copyright (c) 2003 Zinx Verituse <zinx@epicsol.org>
 *  Copyright (c) 2002 Johann Deneux
 */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
#include <linux/hid.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/module.h>
#include "hid-ids.h"
static const signed short ff_rumble[] = {
	FF_RUMBLE,
	-1
};
static const signed short ff_joystick[] = {
	FF_CONSTANT,
	-1
};
#ifdef CONFIG_THRUSTMASTER_FF
/* Usages for thrustmaster devices I know about */
#define THRUSTMASTER_USAGE_FF	(HID_UP_GENDESK | 0xbb)
struct tmff_device {
	
struct hid_report *report;
	
struct hid_field *ff_field;
};
/* Changes values from 0 to 0xffff into values from minimum to maximum */
static inline int tmff_scale_u16(unsigned int in, int minimum, int maximum)
{
	int ret;
	ret = (in * (maximum - minimum) / 0xffff) + minimum;
	if (ret < minimum)
		return minimum;
	if (ret > maximum)
		return maximum;
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Anssi Hannula | 46 | 80.70% | 1 | 33.33% | 
| Zinx Verituse | 10 | 17.54% | 1 | 33.33% | 
| Jiri Slaby | 1 | 1.75% | 1 | 33.33% | 
| Total | 57 | 100.00% | 3 | 100.00% | 
/* Changes values from -0x80 to 0x7f into values from minimum to maximum */
static inline int tmff_scale_s8(int in, int minimum, int maximum)
{
	int ret;
	ret = (((in + 0x80) * (maximum - minimum)) / 0xff) + minimum;
	if (ret < minimum)
		return minimum;
	if (ret > maximum)
		return maximum;
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dmitry Torokhov | 61 | 98.39% | 1 | 50.00% | 
| Jiri Slaby | 1 | 1.61% | 1 | 50.00% | 
| Total | 62 | 100.00% | 2 | 100.00% | 
static int tmff_play(struct input_dev *dev, void *data,
		struct ff_effect *effect)
{
	struct hid_device *hid = input_get_drvdata(dev);
	struct tmff_device *tmff = data;
	struct hid_field *ff_field = tmff->ff_field;
	int x, y;
	int left, right;	/* Rumbling */
	switch (effect->type) {
	case FF_CONSTANT:
		x = tmff_scale_s8(effect->u.ramp.start_level,
					ff_field->logical_minimum,
					ff_field->logical_maximum);
		y = tmff_scale_s8(effect->u.ramp.end_level,
					ff_field->logical_minimum,
					ff_field->logical_maximum);
		dbg_hid("(x, y)=(%04x, %04x)\n", x, y);
		ff_field->value[0] = x;
		ff_field->value[1] = y;
		hid_hw_request(hid, tmff->report, HID_REQ_SET_REPORT);
		break;
	case FF_RUMBLE:
		left = tmff_scale_u16(effect->u.rumble.weak_magnitude,
					ff_field->logical_minimum,
					ff_field->logical_maximum);
		right = tmff_scale_u16(effect->u.rumble.strong_magnitude,
					ff_field->logical_minimum,
					ff_field->logical_maximum);
		dbg_hid("(left,right)=(%08x, %08x)\n", left, right);
		ff_field->value[0] = left;
		ff_field->value[1] = right;
		hid_hw_request(hid, tmff->report, HID_REQ_SET_REPORT);
		break;
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dmitry Torokhov | 122 | 51.69% | 2 | 28.57% | 
| Anssi Hannula | 83 | 35.17% | 1 | 14.29% | 
| Zinx Verituse | 20 | 8.47% | 1 | 14.29% | 
| Jiri Slaby | 5 | 2.12% | 1 | 14.29% | 
| Benjamin Tissoires | 4 | 1.69% | 1 | 14.29% | 
| Jiri Kosina | 2 | 0.85% | 1 | 14.29% | 
| Total | 236 | 100.00% | 7 | 100.00% | 
static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
{
	struct tmff_device *tmff;
	struct hid_report *report;
	struct list_head *report_list;
	struct hid_input *hidinput = list_entry(hid->inputs.next,
							struct hid_input, list);
	struct input_dev *input_dev = hidinput->input;
	int error;
	int i;
	tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
	if (!tmff)
		return -ENOMEM;
	/* Find the report to use */
	report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
	list_for_each_entry(report, report_list, list) {
		int fieldnum;
		for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) {
			struct hid_field *field = report->field[fieldnum];
			if (field->maxusage <= 0)
				continue;
			switch (field->usage[0].hid) {
			case THRUSTMASTER_USAGE_FF:
				if (field->report_count < 2) {
					hid_warn(hid, "ignoring FF field with report_count < 2\n");
					continue;
				}
				if (field->logical_maximum ==
						field->logical_minimum) {
					hid_warn(hid, "ignoring FF field with logical_maximum == logical_minimum\n");
					continue;
				}
				if (tmff->report && tmff->report != report) {
					hid_warn(hid, "ignoring FF field in other report\n");
					continue;
				}
				if (tmff->ff_field && tmff->ff_field != field) {
					hid_warn(hid, "ignoring duplicate FF field\n");
					continue;
				}
				tmff->report = report;
				tmff->ff_field = field;
				for (i = 0; ff_bits[i] >= 0; i++)
					set_bit(ff_bits[i], input_dev->ffbit);
				break;
			default:
				hid_warn(hid, "ignoring unknown output usage %08x\n",
					 field->usage[0].hid);
				continue;
			}
		}
	}
	if (!tmff->report) {
		hid_err(hid, "can't find FF field in output reports\n");
		error = -ENODEV;
		goto fail;
	}
	error = input_ff_create_memless(input_dev, tmff, tmff_play);
	if (error)
		goto fail;
	hid_info(hid, "force feedback for ThrustMaster devices by Zinx Verituse <zinx@epicsol.org>\n");
	return 0;
fail:
	kfree(tmff);
	return error;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Zinx Verituse | 202 | 54.45% | 2 | 18.18% | 
| Dmitry Torokhov | 66 | 17.79% | 2 | 18.18% | 
| Anssi Hannula | 25 | 6.74% | 1 | 9.09% | 
| Jiri Slaby | 24 | 6.47% | 2 | 18.18% | 
| Li Zefan | 23 | 6.20% | 1 | 9.09% | 
| Benjamin Collins | 17 | 4.58% | 1 | 9.09% | 
| Joe Perches | 13 | 3.50% | 1 | 9.09% | 
| Oliver Neukum | 1 | 0.27% | 1 | 9.09% | 
| Total | 371 | 100.00% | 11 | 100.00% | 
#else
static inline int tmff_init(struct hid_device *hid, const signed short *ff_bits)
{
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jiri Kosina | 21 | 100.00% | 1 | 100.00% | 
| Total | 21 | 100.00% | 1 | 100.00% | 
#endif
static int tm_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
	int ret;
	ret = hid_parse(hdev);
	if (ret) {
		hid_err(hdev, "parse failed\n");
		goto err;
	}
	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
	if (ret) {
		hid_err(hdev, "hw start failed\n");
		goto err;
	}
	tmff_init(hdev, (void *)id->driver_data);
	return 0;
err:
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Jiri Slaby | 90 | 97.83% | 1 | 50.00% | 
| Joe Perches | 2 | 2.17% | 1 | 50.00% | 
| Total | 92 | 100.00% | 2 | 100.00% | 
static const struct hid_device_id tm_devices[] = {
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300),
		.driver_data = (unsigned long)ff_rumble },
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304),   /* FireStorm Dual Power 2 (and 3) */
		.driver_data = (unsigned long)ff_rumble },
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323),   /* Dual Trigger 3-in-1 (PC Mode) */
		.driver_data = (unsigned long)ff_rumble },
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324),   /* Dual Trigger 3-in-1 (PS3 Mode) */
		.driver_data = (unsigned long)ff_rumble },
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651),	/* FGT Rumble Force Wheel */
		.driver_data = (unsigned long)ff_rumble },
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653),	/* RGT Force Feedback CLUTCH Raging Wheel */
		.driver_data = (unsigned long)ff_joystick },
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654),	/* FGT Force Feedback Wheel */
		.driver_data = (unsigned long)ff_joystick },
	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a),	/* F430 Force Feedback Wheel */
		.driver_data = (unsigned long)ff_joystick },
	{ }
};
MODULE_DEVICE_TABLE(hid, tm_devices);
static struct hid_driver tm_driver = {
	.name = "thrustmaster",
	.id_table = tm_devices,
	.probe = tm_probe,
};
module_hid_driver(tm_driver);
MODULE_LICENSE("GPL");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Dmitry Torokhov | 279 | 25.04% | 3 | 14.29% | 
| Zinx Verituse | 252 | 22.62% | 2 | 9.52% | 
| Jiri Slaby | 248 | 22.26% | 2 | 9.52% | 
| Anssi Hannula | 155 | 13.91% | 1 | 4.76% | 
| Ruben Aos Garralda | 39 | 3.50% | 1 | 4.76% | 
| Jiri Kosina | 35 | 3.14% | 2 | 9.52% | 
| Li Zefan | 23 | 2.06% | 1 | 4.76% | 
| Markus Rathgeb | 19 | 1.71% | 1 | 4.76% | 
| Simon Wood | 19 | 1.71% | 1 | 4.76% | 
| Benjamin Collins | 17 | 1.53% | 1 | 4.76% | 
| Joe Perches | 15 | 1.35% | 1 | 4.76% | 
| Benjamin Tissoires | 4 | 0.36% | 1 | 4.76% | 
| Tejun Heo | 3 | 0.27% | 1 | 4.76% | 
| Paul Gortmaker | 3 | 0.27% | 1 | 4.76% | 
| H Hartley Sweeten | 2 | 0.18% | 1 | 4.76% | 
| Oliver Neukum | 1 | 0.09% | 1 | 4.76% | 
| Total | 1114 | 100.00% | 21 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.