Linux Audio

Check our new training course

Loading...
v3.1
  1/*
  2 *  Force feedback support for EMS Trio Linker Plus II
  3 *
  4 *  Copyright (c) 2010 Ignaz Forster <ignaz.forster@gmx.de>
  5 */
  6
  7/*
  8 * This program is free software; you can redistribute it and/or modify
  9 * it under the terms of the GNU General Public License as published by
 10 * the Free Software Foundation; either version 2 of the License, or
 11 * (at your option) any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 21 */
 22
 23
 24#include <linux/hid.h>
 25#include <linux/input.h>
 26#include <linux/usb.h>
 
 27
 28#include "hid-ids.h"
 29#include "usbhid/usbhid.h"
 30
 31struct emsff_device {
 32	struct hid_report *report;
 33};
 34
 35static int emsff_play(struct input_dev *dev, void *data,
 36			 struct ff_effect *effect)
 37{
 38	struct hid_device *hid = input_get_drvdata(dev);
 39	struct emsff_device *emsff = data;
 40	int weak, strong;
 41
 42	weak = effect->u.rumble.weak_magnitude;
 43	strong = effect->u.rumble.strong_magnitude;
 44
 45	dbg_hid("called with 0x%04x 0x%04x\n", strong, weak);
 46
 47	weak = weak * 0xff / 0xffff;
 48	strong = strong * 0xff / 0xffff;
 49
 50	emsff->report->field[0]->value[1] = weak;
 51	emsff->report->field[0]->value[2] = strong;
 52
 53	dbg_hid("running with 0x%02x 0x%02x\n", strong, weak);
 54	usbhid_submit_report(hid, emsff->report, USB_DIR_OUT);
 55
 56	return 0;
 57}
 58
 59static int emsff_init(struct hid_device *hid)
 60{
 61	struct emsff_device *emsff;
 62	struct hid_report *report;
 63	struct hid_input *hidinput = list_first_entry(&hid->inputs,
 64						struct hid_input, list);
 65	struct list_head *report_list =
 66			&hid->report_enum[HID_OUTPUT_REPORT].report_list;
 67	struct input_dev *dev = hidinput->input;
 68	int error;
 69
 70	if (list_empty(report_list)) {
 71		hid_err(hid, "no output reports found\n");
 72		return -ENODEV;
 73	}
 74
 75	report = list_first_entry(report_list, struct hid_report, list);
 76	if (report->maxfield < 1) {
 77		hid_err(hid, "no fields in the report\n");
 78		return -ENODEV;
 79	}
 80
 81	if (report->field[0]->report_count < 7) {
 82		hid_err(hid, "not enough values in the field\n");
 83		return -ENODEV;
 84	}
 85
 86	emsff = kzalloc(sizeof(struct emsff_device), GFP_KERNEL);
 87	if (!emsff)
 88		return -ENOMEM;
 89
 90	set_bit(FF_RUMBLE, dev->ffbit);
 91
 92	error = input_ff_create_memless(dev, emsff, emsff_play);
 93	if (error) {
 94		kfree(emsff);
 95		return error;
 96	}
 97
 98	emsff->report = report;
 99	emsff->report->field[0]->value[0] = 0x01;
100	emsff->report->field[0]->value[1] = 0x00;
101	emsff->report->field[0]->value[2] = 0x00;
102	emsff->report->field[0]->value[3] = 0x00;
103	emsff->report->field[0]->value[4] = 0x00;
104	emsff->report->field[0]->value[5] = 0x00;
105	emsff->report->field[0]->value[6] = 0x00;
106	usbhid_submit_report(hid, emsff->report, USB_DIR_OUT);
107
108	hid_info(hid, "force feedback for EMS based devices by Ignaz Forster <ignaz.forster@gmx.de>\n");
109
110	return 0;
111}
112
113static int ems_probe(struct hid_device *hdev, const struct hid_device_id *id)
114{
115	int ret;
116
117	ret = hid_parse(hdev);
118	if (ret) {
119		hid_err(hdev, "parse failed\n");
120		goto err;
121	}
122
123	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
124	if (ret) {
125		hid_err(hdev, "hw start failed\n");
126		goto err;
127	}
128
129	ret = emsff_init(hdev);
130	if (ret) {
131		dev_err(&hdev->dev, "force feedback init failed\n");
132		hid_hw_stop(hdev);
133		goto err;
134	}
135
136	return 0;
137err:
138	return ret;
139}
140
141static const struct hid_device_id ems_devices[] = {
142	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, 0x118) },
143	{ }
144};
145MODULE_DEVICE_TABLE(hid, ems_devices);
146
147static struct hid_driver ems_driver = {
148	.name = "hkems",
149	.id_table = ems_devices,
150	.probe = ems_probe,
151};
152
153static int ems_init(void)
154{
155	return hid_register_driver(&ems_driver);
156}
157
158static void ems_exit(void)
159{
160	hid_unregister_driver(&ems_driver);
161}
162
163module_init(ems_init);
164module_exit(ems_exit);
165MODULE_LICENSE("GPL");
166
v3.5.6
  1/*
  2 *  Force feedback support for EMS Trio Linker Plus II
  3 *
  4 *  Copyright (c) 2010 Ignaz Forster <ignaz.forster@gmx.de>
  5 */
  6
  7/*
  8 * This program is free software; you can redistribute it and/or modify
  9 * it under the terms of the GNU General Public License as published by
 10 * the Free Software Foundation; either version 2 of the License, or
 11 * (at your option) any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 21 */
 22
 23
 24#include <linux/hid.h>
 25#include <linux/input.h>
 26#include <linux/usb.h>
 27#include <linux/module.h>
 28
 29#include "hid-ids.h"
 30#include "usbhid/usbhid.h"
 31
 32struct emsff_device {
 33	struct hid_report *report;
 34};
 35
 36static int emsff_play(struct input_dev *dev, void *data,
 37			 struct ff_effect *effect)
 38{
 39	struct hid_device *hid = input_get_drvdata(dev);
 40	struct emsff_device *emsff = data;
 41	int weak, strong;
 42
 43	weak = effect->u.rumble.weak_magnitude;
 44	strong = effect->u.rumble.strong_magnitude;
 45
 46	dbg_hid("called with 0x%04x 0x%04x\n", strong, weak);
 47
 48	weak = weak * 0xff / 0xffff;
 49	strong = strong * 0xff / 0xffff;
 50
 51	emsff->report->field[0]->value[1] = weak;
 52	emsff->report->field[0]->value[2] = strong;
 53
 54	dbg_hid("running with 0x%02x 0x%02x\n", strong, weak);
 55	usbhid_submit_report(hid, emsff->report, USB_DIR_OUT);
 56
 57	return 0;
 58}
 59
 60static int emsff_init(struct hid_device *hid)
 61{
 62	struct emsff_device *emsff;
 63	struct hid_report *report;
 64	struct hid_input *hidinput = list_first_entry(&hid->inputs,
 65						struct hid_input, list);
 66	struct list_head *report_list =
 67			&hid->report_enum[HID_OUTPUT_REPORT].report_list;
 68	struct input_dev *dev = hidinput->input;
 69	int error;
 70
 71	if (list_empty(report_list)) {
 72		hid_err(hid, "no output reports found\n");
 73		return -ENODEV;
 74	}
 75
 76	report = list_first_entry(report_list, struct hid_report, list);
 77	if (report->maxfield < 1) {
 78		hid_err(hid, "no fields in the report\n");
 79		return -ENODEV;
 80	}
 81
 82	if (report->field[0]->report_count < 7) {
 83		hid_err(hid, "not enough values in the field\n");
 84		return -ENODEV;
 85	}
 86
 87	emsff = kzalloc(sizeof(struct emsff_device), GFP_KERNEL);
 88	if (!emsff)
 89		return -ENOMEM;
 90
 91	set_bit(FF_RUMBLE, dev->ffbit);
 92
 93	error = input_ff_create_memless(dev, emsff, emsff_play);
 94	if (error) {
 95		kfree(emsff);
 96		return error;
 97	}
 98
 99	emsff->report = report;
100	emsff->report->field[0]->value[0] = 0x01;
101	emsff->report->field[0]->value[1] = 0x00;
102	emsff->report->field[0]->value[2] = 0x00;
103	emsff->report->field[0]->value[3] = 0x00;
104	emsff->report->field[0]->value[4] = 0x00;
105	emsff->report->field[0]->value[5] = 0x00;
106	emsff->report->field[0]->value[6] = 0x00;
107	usbhid_submit_report(hid, emsff->report, USB_DIR_OUT);
108
109	hid_info(hid, "force feedback for EMS based devices by Ignaz Forster <ignaz.forster@gmx.de>\n");
110
111	return 0;
112}
113
114static int ems_probe(struct hid_device *hdev, const struct hid_device_id *id)
115{
116	int ret;
117
118	ret = hid_parse(hdev);
119	if (ret) {
120		hid_err(hdev, "parse failed\n");
121		goto err;
122	}
123
124	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
125	if (ret) {
126		hid_err(hdev, "hw start failed\n");
127		goto err;
128	}
129
130	ret = emsff_init(hdev);
131	if (ret) {
132		dev_err(&hdev->dev, "force feedback init failed\n");
133		hid_hw_stop(hdev);
134		goto err;
135	}
136
137	return 0;
138err:
139	return ret;
140}
141
142static const struct hid_device_id ems_devices[] = {
143	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
144	{ }
145};
146MODULE_DEVICE_TABLE(hid, ems_devices);
147
148static struct hid_driver ems_driver = {
149	.name = "hkems",
150	.id_table = ems_devices,
151	.probe = ems_probe,
152};
153
154static int ems_init(void)
155{
156	return hid_register_driver(&ems_driver);
157}
158
159static void ems_exit(void)
160{
161	hid_unregister_driver(&ems_driver);
162}
163
164module_init(ems_init);
165module_exit(ems_exit);
166MODULE_LICENSE("GPL");
167