Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  Force feedback support for SmartJoy PLUS PS2->USB adapter
  4 *
  5 *  Copyright (c) 2009 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
  6 *
  7 *  Based of hid-pl.c and hid-gaff.c
  8 *   Copyright (c) 2007, 2009 Anssi Hannula <anssi.hannula@gmail.com>
  9 *   Copyright (c) 2008 Lukasz Lubojanski <lukasz@lubojanski.info>
 10 */
 11
 12/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 13 */
 14
 15/* #define DEBUG */
 16
 17#include <linux/input.h>
 18#include <linux/slab.h>
 
 19#include <linux/hid.h>
 20#include <linux/module.h>
 21#include "hid-ids.h"
 22
 23#ifdef CONFIG_SMARTJOYPLUS_FF
 
 24
 25struct sjoyff_device {
 26	struct hid_report *report;
 27};
 28
 29static int hid_sjoyff_play(struct input_dev *dev, void *data,
 30			 struct ff_effect *effect)
 31{
 32	struct hid_device *hid = input_get_drvdata(dev);
 33	struct sjoyff_device *sjoyff = data;
 34	u32 left, right;
 35
 36	left = effect->u.rumble.strong_magnitude;
 37	right = effect->u.rumble.weak_magnitude;
 38	dev_dbg(&dev->dev, "called with 0x%08x 0x%08x\n", left, right);
 39
 40	left = left * 0xff / 0xffff;
 41	right = (right != 0); /* on/off only */
 42
 43	sjoyff->report->field[0]->value[1] = right;
 44	sjoyff->report->field[0]->value[2] = left;
 45	dev_dbg(&dev->dev, "running with 0x%02x 0x%02x\n", left, right);
 46	hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT);
 47
 48	return 0;
 49}
 50
 51static int sjoyff_init(struct hid_device *hid)
 52{
 53	struct sjoyff_device *sjoyff;
 54	struct hid_report *report;
 55	struct hid_input *hidinput;
 
 56	struct list_head *report_list =
 57			&hid->report_enum[HID_OUTPUT_REPORT].report_list;
 58	struct list_head *report_ptr = report_list;
 59	struct input_dev *dev;
 60	int error;
 61
 62	if (list_empty(report_list)) {
 63		hid_err(hid, "no output reports found\n");
 64		return -ENODEV;
 65	}
 66
 67	list_for_each_entry(hidinput, &hid->inputs, list) {
 68		report_ptr = report_ptr->next;
 
 
 
 
 
 
 
 
 
 
 69
 70		if (report_ptr == report_list) {
 71			hid_err(hid, "required output report is missing\n");
 72			return -ENODEV;
 73		}
 74
 75		report = list_entry(report_ptr, 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 < 3) {
 82			hid_err(hid, "not enough values in the field\n");
 83			return -ENODEV;
 84		}
 85
 86		sjoyff = kzalloc(sizeof(struct sjoyff_device), GFP_KERNEL);
 87		if (!sjoyff)
 88			return -ENOMEM;
 89
 90		dev = hidinput->input;
 91
 92		set_bit(FF_RUMBLE, dev->ffbit);
 93
 94		error = input_ff_create_memless(dev, sjoyff, hid_sjoyff_play);
 95		if (error) {
 96			kfree(sjoyff);
 97			return error;
 98		}
 99
100		sjoyff->report = report;
101		sjoyff->report->field[0]->value[0] = 0x01;
102		sjoyff->report->field[0]->value[1] = 0x00;
103		sjoyff->report->field[0]->value[2] = 0x00;
104		hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT);
105	}
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107	hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n");
108
109	return 0;
110}
111#else
112static inline int sjoyff_init(struct hid_device *hid)
113{
114	return 0;
115}
116#endif
117
118static int sjoy_probe(struct hid_device *hdev, const struct hid_device_id *id)
119{
120	int ret;
121
122	hdev->quirks |= id->driver_data;
123
124	ret = hid_parse(hdev);
125	if (ret) {
126		hid_err(hdev, "parse failed\n");
127		goto err;
128	}
129
130	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
131	if (ret) {
132		hid_err(hdev, "hw start failed\n");
133		goto err;
134	}
135
136	sjoyff_init(hdev);
137
138	return 0;
139err:
140	return ret;
141}
142
143static const struct hid_device_id sjoy_devices[] = {
144	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO),
145		.driver_data = HID_QUIRK_NOGET },
146	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO),
147		.driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET |
148			       HID_QUIRK_SKIP_OUTPUT_REPORTS },
149	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO),
150		.driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET |
151			       HID_QUIRK_SKIP_OUTPUT_REPORTS },
152	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
153	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
154	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD),
155		.driver_data = HID_QUIRK_MULTI_INPUT |
156			       HID_QUIRK_SKIP_OUTPUT_REPORTS },
157	{ HID_USB_DEVICE(USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII),
158		.driver_data = HID_QUIRK_MULTI_INPUT |
159			       HID_QUIRK_SKIP_OUTPUT_REPORTS },
160	{ }
161};
162MODULE_DEVICE_TABLE(hid, sjoy_devices);
163
164static struct hid_driver sjoy_driver = {
165	.name = "smartjoyplus",
166	.id_table = sjoy_devices,
167	.probe = sjoy_probe,
168};
169module_hid_driver(sjoy_driver);
170
 
 
 
 
 
 
 
 
 
 
 
 
171MODULE_LICENSE("GPL");
172MODULE_AUTHOR("Jussi Kivilinna");
173
v3.1
 
  1/*
  2 *  Force feedback support for SmartJoy PLUS PS2->USB adapter
  3 *
  4 *  Copyright (c) 2009 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
  5 *
  6 *  Based of hid-pl.c and hid-gaff.c
  7 *   Copyright (c) 2007, 2009 Anssi Hannula <anssi.hannula@gmail.com>
  8 *   Copyright (c) 2008 Lukasz Lubojanski <lukasz@lubojanski.info>
  9 */
 10
 11/*
 12 * This program is free software; you can redistribute it and/or modify
 13 * it under the terms of the GNU General Public License as published by
 14 * the Free Software Foundation; either version 2 of the License, or
 15 * (at your option) any later version.
 16 *
 17 * This program is distributed in the hope that it will be useful,
 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20 * GNU General Public License for more details.
 21 *
 22 * You should have received a copy of the GNU General Public License
 23 * along with this program; if not, write to the Free Software
 24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 25 */
 26
 27/* #define DEBUG */
 28
 29#include <linux/input.h>
 30#include <linux/slab.h>
 31#include <linux/usb.h>
 32#include <linux/hid.h>
 
 33#include "hid-ids.h"
 34
 35#ifdef CONFIG_SMARTJOYPLUS_FF
 36#include "usbhid/usbhid.h"
 37
 38struct sjoyff_device {
 39	struct hid_report *report;
 40};
 41
 42static int hid_sjoyff_play(struct input_dev *dev, void *data,
 43			 struct ff_effect *effect)
 44{
 45	struct hid_device *hid = input_get_drvdata(dev);
 46	struct sjoyff_device *sjoyff = data;
 47	u32 left, right;
 48
 49	left = effect->u.rumble.strong_magnitude;
 50	right = effect->u.rumble.weak_magnitude;
 51	dev_dbg(&dev->dev, "called with 0x%08x 0x%08x\n", left, right);
 52
 53	left = left * 0xff / 0xffff;
 54	right = (right != 0); /* on/off only */
 55
 56	sjoyff->report->field[0]->value[1] = right;
 57	sjoyff->report->field[0]->value[2] = left;
 58	dev_dbg(&dev->dev, "running with 0x%02x 0x%02x\n", left, right);
 59	usbhid_submit_report(hid, sjoyff->report, USB_DIR_OUT);
 60
 61	return 0;
 62}
 63
 64static int sjoyff_init(struct hid_device *hid)
 65{
 66	struct sjoyff_device *sjoyff;
 67	struct hid_report *report;
 68	struct hid_input *hidinput = list_entry(hid->inputs.next,
 69						struct hid_input, list);
 70	struct list_head *report_list =
 71			&hid->report_enum[HID_OUTPUT_REPORT].report_list;
 72	struct list_head *report_ptr = report_list;
 73	struct input_dev *dev;
 74	int error;
 75
 76	if (list_empty(report_list)) {
 77		hid_err(hid, "no output reports found\n");
 78		return -ENODEV;
 79	}
 80
 81	report_ptr = report_ptr->next;
 82
 83	if (report_ptr == report_list) {
 84		hid_err(hid, "required output report is missing\n");
 85		return -ENODEV;
 86	}
 87
 88	report = list_entry(report_ptr, struct hid_report, list);
 89	if (report->maxfield < 1) {
 90		hid_err(hid, "no fields in the report\n");
 91		return -ENODEV;
 92	}
 93
 94	if (report->field[0]->report_count < 3) {
 95		hid_err(hid, "not enough values in the field\n");
 96		return -ENODEV;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 97	}
 98
 99	sjoyff = kzalloc(sizeof(struct sjoyff_device), GFP_KERNEL);
100	if (!sjoyff)
101		return -ENOMEM;
102
103	dev = hidinput->input;
104
105	set_bit(FF_RUMBLE, dev->ffbit);
106
107	error = input_ff_create_memless(dev, sjoyff, hid_sjoyff_play);
108	if (error) {
109		kfree(sjoyff);
110		return error;
111	}
112
113	sjoyff->report = report;
114	sjoyff->report->field[0]->value[0] = 0x01;
115	sjoyff->report->field[0]->value[1] = 0x00;
116	sjoyff->report->field[0]->value[2] = 0x00;
117	usbhid_submit_report(hid, sjoyff->report, USB_DIR_OUT);
118
119	hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n");
120
121	return 0;
122}
123#else
124static inline int sjoyff_init(struct hid_device *hid)
125{
126	return 0;
127}
128#endif
129
130static int sjoy_probe(struct hid_device *hdev, const struct hid_device_id *id)
131{
132	int ret;
133
 
 
134	ret = hid_parse(hdev);
135	if (ret) {
136		hid_err(hdev, "parse failed\n");
137		goto err;
138	}
139
140	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
141	if (ret) {
142		hid_err(hdev, "hw start failed\n");
143		goto err;
144	}
145
146	sjoyff_init(hdev);
147
148	return 0;
149err:
150	return ret;
151}
152
153static const struct hid_device_id sjoy_devices[] = {
 
 
 
 
 
 
 
 
154	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
 
 
 
 
 
 
 
155	{ }
156};
157MODULE_DEVICE_TABLE(hid, sjoy_devices);
158
159static struct hid_driver sjoy_driver = {
160	.name = "smartjoyplus",
161	.id_table = sjoy_devices,
162	.probe = sjoy_probe,
163};
 
164
165static int __init sjoy_init(void)
166{
167	return hid_register_driver(&sjoy_driver);
168}
169
170static void __exit sjoy_exit(void)
171{
172	hid_unregister_driver(&sjoy_driver);
173}
174
175module_init(sjoy_init);
176module_exit(sjoy_exit);
177MODULE_LICENSE("GPL");
178MODULE_AUTHOR("Jussi Kivilinna");
179