hwmon: add support for JEDEC JC 42.4 compliant temperature sensors
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / hid / hid-axff.c
blobf42ee140738a219a7cb8e1ef1d8565aca214f718
1 /*
2 * Force feedback support for ACRUX game controllers
4 * From what I have gathered, these devices are mass produced in China
5 * by several vendors. They often share the same design as the original
6 * Xbox 360 controller.
8 * 1a34:0802 "ACRUX USB GAMEPAD 8116"
9 * - tested with a EXEQ EQ-PCU-02090 game controller.
11 * Copyright (c) 2010 Sergei Kolzun <x0r@dv-life.ru>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <linux/input.h>
31 #include <linux/slab.h>
32 #include <linux/usb.h>
33 #include <linux/hid.h>
35 #include "hid-ids.h"
36 #include "usbhid/usbhid.h"
38 struct axff_device {
39 struct hid_report *report;
42 static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
44 struct hid_device *hid = input_get_drvdata(dev);
45 struct axff_device *axff = data;
46 int left, right;
48 left = effect->u.rumble.strong_magnitude;
49 right = effect->u.rumble.weak_magnitude;
51 dbg_hid("called with 0x%04x 0x%04x", left, right);
53 left = left * 0xff / 0xffff;
54 right = right * 0xff / 0xffff;
56 axff->report->field[0]->value[0] = left;
57 axff->report->field[1]->value[0] = right;
58 axff->report->field[2]->value[0] = left;
59 axff->report->field[3]->value[0] = right;
60 dbg_hid("running with 0x%02x 0x%02x", left, right);
61 usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
63 return 0;
66 static int axff_init(struct hid_device *hid)
68 struct axff_device *axff;
69 struct hid_report *report;
70 struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
71 struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
72 struct input_dev *dev = hidinput->input;
73 int error;
75 if (list_empty(report_list)) {
76 dev_err(&hid->dev, "no output reports found\n");
77 return -ENODEV;
80 report = list_first_entry(report_list, struct hid_report, list);
82 if (report->maxfield < 4) {
83 dev_err(&hid->dev, "no fields in the report: %d\n", report->maxfield);
84 return -ENODEV;
87 axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
88 if (!axff)
89 return -ENOMEM;
91 set_bit(FF_RUMBLE, dev->ffbit);
93 error = input_ff_create_memless(dev, axff, axff_play);
94 if (error)
95 goto err_free_mem;
97 axff->report = report;
98 axff->report->field[0]->value[0] = 0x00;
99 axff->report->field[1]->value[0] = 0x00;
100 axff->report->field[2]->value[0] = 0x00;
101 axff->report->field[3]->value[0] = 0x00;
102 usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
104 dev_info(&hid->dev, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n");
106 return 0;
108 err_free_mem:
109 kfree(axff);
110 return error;
113 static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
115 int error;
117 dev_dbg(&hdev->dev, "ACRUX HID hardware probe...");
119 error = hid_parse(hdev);
120 if (error) {
121 dev_err(&hdev->dev, "parse failed\n");
122 return error;
125 error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
126 if (error) {
127 dev_err(&hdev->dev, "hw start failed\n");
128 return error;
131 error = axff_init(hdev);
132 if (error) {
134 * Do not fail device initialization completely as device
135 * may still be partially operable, just warn.
137 dev_warn(&hdev->dev,
138 "Failed to enable force feedback support, error: %d\n",
139 error);
142 return 0;
145 static const struct hid_device_id ax_devices[] = {
146 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
149 MODULE_DEVICE_TABLE(hid, ax_devices);
151 static struct hid_driver ax_driver = {
152 .name = "acrux",
153 .id_table = ax_devices,
154 .probe = ax_probe,
157 static int __init ax_init(void)
159 return hid_register_driver(&ax_driver);
162 static void __exit ax_exit(void)
164 hid_unregister_driver(&ax_driver);
167 module_init(ax_init);
168 module_exit(ax_exit);
170 MODULE_AUTHOR("Sergei Kolzun");
171 MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers");
172 MODULE_LICENSE("GPL");