Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1 | /* |
Simon Wood | 6401380 | 2012-04-21 05:41:16 -0700 | [diff] [blame] | 2 | * Force feedback support for Logitech Gaming Wheels |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 3 | * |
Simon Wood | 6401380 | 2012-04-21 05:41:16 -0700 | [diff] [blame] | 4 | * Including G27, G25, DFP, DFGT, FFEX, Momo, Momo2 & |
| 5 | * Speed Force Wireless (WiiWheel) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 6 | * |
| 7 | * Copyright (c) 2010 Simon Wood <simon@mungewell.org> |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/usb.h> |
| 29 | #include <linux/hid.h> |
| 30 | |
| 31 | #include "usbhid/usbhid.h" |
| 32 | #include "hid-lg.h" |
Michal Malý | a54dc779 | 2015-02-18 17:59:22 +0100 | [diff] [blame^] | 33 | #include "hid-lg4ff.h" |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 34 | #include "hid-ids.h" |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 35 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 36 | #define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) |
| 37 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 38 | #define LG4FF_MMODE_IS_MULTIMODE 0 |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 39 | #define LG4FF_MMODE_SWITCHED 1 |
| 40 | #define LG4FF_MMODE_NOT_MULTIMODE 2 |
| 41 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 42 | #define LG4FF_MODE_NATIVE_IDX 0 |
| 43 | #define LG4FF_MODE_DFEX_IDX 1 |
| 44 | #define LG4FF_MODE_DFP_IDX 2 |
| 45 | #define LG4FF_MODE_G25_IDX 3 |
| 46 | #define LG4FF_MODE_DFGT_IDX 4 |
| 47 | #define LG4FF_MODE_G27_IDX 5 |
| 48 | #define LG4FF_MODE_MAX_IDX 6 |
| 49 | |
| 50 | #define LG4FF_MODE_NATIVE BIT(LG4FF_MODE_NATIVE_IDX) |
| 51 | #define LG4FF_MODE_DFEX BIT(LG4FF_MODE_DFEX_IDX) |
| 52 | #define LG4FF_MODE_DFP BIT(LG4FF_MODE_DFP_IDX) |
| 53 | #define LG4FF_MODE_G25 BIT(LG4FF_MODE_G25_IDX) |
| 54 | #define LG4FF_MODE_DFGT BIT(LG4FF_MODE_DFGT_IDX) |
| 55 | #define LG4FF_MODE_G27 BIT(LG4FF_MODE_G27_IDX) |
| 56 | |
| 57 | #define LG4FF_DFEX_TAG "DF-EX" |
| 58 | #define LG4FF_DFEX_NAME "Driving Force / Formula EX" |
| 59 | #define LG4FF_DFP_TAG "DFP" |
| 60 | #define LG4FF_DFP_NAME "Driving Force Pro" |
| 61 | #define LG4FF_G25_TAG "G25" |
| 62 | #define LG4FF_G25_NAME "G25 Racing Wheel" |
| 63 | #define LG4FF_G27_TAG "G27" |
| 64 | #define LG4FF_G27_NAME "G27 Racing Wheel" |
| 65 | #define LG4FF_DFGT_TAG "DFGT" |
| 66 | #define LG4FF_DFGT_NAME "Driving Force GT" |
| 67 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 68 | #define LG4FF_FFEX_REV_MAJ 0x21 |
| 69 | #define LG4FF_FFEX_REV_MIN 0x00 |
| 70 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 71 | static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range); |
| 72 | static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 73 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 74 | struct lg4ff_device_entry { |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 75 | __u32 product_id; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 76 | __u16 range; |
| 77 | __u16 min_range; |
| 78 | __u16 max_range; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 79 | #ifdef CONFIG_LEDS_CLASS |
| 80 | __u8 led_state; |
| 81 | struct led_classdev *led[5]; |
| 82 | #endif |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 83 | u32 alternate_modes; |
| 84 | const char *real_tag; |
| 85 | const char *real_name; |
| 86 | u16 real_product_id; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 87 | struct list_head list; |
| 88 | void (*set_range)(struct hid_device *hid, u16 range); |
| 89 | }; |
| 90 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 91 | static const signed short lg4ff_wheel_effects[] = { |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 92 | FF_CONSTANT, |
| 93 | FF_AUTOCENTER, |
| 94 | -1 |
| 95 | }; |
| 96 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 97 | struct lg4ff_wheel { |
| 98 | const __u32 product_id; |
| 99 | const signed short *ff_effects; |
| 100 | const __u16 min_range; |
| 101 | const __u16 max_range; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 102 | void (*set_range)(struct hid_device *hid, u16 range); |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 105 | struct lg4ff_compat_mode_switch { |
| 106 | const __u8 cmd_count; /* Number of commands to send */ |
| 107 | const __u8 cmd[]; |
| 108 | }; |
| 109 | |
| 110 | struct lg4ff_wheel_ident_info { |
| 111 | const u16 mask; |
| 112 | const u16 result; |
| 113 | const u16 real_product_id; |
| 114 | }; |
| 115 | |
| 116 | struct lg4ff_wheel_ident_checklist { |
| 117 | const u32 count; |
| 118 | const struct lg4ff_wheel_ident_info *models[]; |
| 119 | }; |
| 120 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 121 | struct lg4ff_multimode_wheel { |
| 122 | const u16 product_id; |
| 123 | const u32 alternate_modes; |
| 124 | const char *real_tag; |
| 125 | const char *real_name; |
| 126 | }; |
| 127 | |
| 128 | struct lg4ff_alternate_mode { |
| 129 | const u16 product_id; |
| 130 | const char *tag; |
| 131 | const char *name; |
| 132 | }; |
| 133 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 134 | static const struct lg4ff_wheel lg4ff_devices[] = { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 135 | {USB_DEVICE_ID_LOGITECH_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, |
| 136 | {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, |
| 137 | {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_dfp}, |
| 138 | {USB_DEVICE_ID_LOGITECH_G25_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_g25}, |
| 139 | {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_g25}, |
| 140 | {USB_DEVICE_ID_LOGITECH_G27_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_g25}, |
| 141 | {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2, lg4ff_wheel_effects, 40, 270, NULL}, |
| 142 | {USB_DEVICE_ID_LOGITECH_WII_WHEEL, lg4ff_wheel_effects, 40, 270, NULL} |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 145 | static const struct lg4ff_multimode_wheel lg4ff_multimode_wheels[] = { |
| 146 | {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, |
| 147 | LG4FF_MODE_NATIVE | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 148 | LG4FF_DFP_TAG, LG4FF_DFP_NAME}, |
| 149 | {USB_DEVICE_ID_LOGITECH_G25_WHEEL, |
| 150 | LG4FF_MODE_NATIVE | LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 151 | LG4FF_G25_TAG, LG4FF_G25_NAME}, |
| 152 | {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, |
| 153 | LG4FF_MODE_NATIVE | LG4FF_MODE_DFGT | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 154 | LG4FF_DFGT_TAG, LG4FF_DFGT_NAME}, |
| 155 | {USB_DEVICE_ID_LOGITECH_G27_WHEEL, |
| 156 | LG4FF_MODE_NATIVE | LG4FF_MODE_G27 | LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 157 | LG4FF_G27_TAG, LG4FF_G27_NAME}, |
| 158 | }; |
| 159 | |
| 160 | static const struct lg4ff_alternate_mode lg4ff_alternate_modes[] = { |
| 161 | [LG4FF_MODE_NATIVE_IDX] = {0, "native", ""}, |
| 162 | [LG4FF_MODE_DFEX_IDX] = {USB_DEVICE_ID_LOGITECH_WHEEL, LG4FF_DFEX_TAG, LG4FF_DFEX_NAME}, |
| 163 | [LG4FF_MODE_DFP_IDX] = {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, LG4FF_DFP_TAG, LG4FF_DFP_NAME}, |
| 164 | [LG4FF_MODE_G25_IDX] = {USB_DEVICE_ID_LOGITECH_G25_WHEEL, LG4FF_G25_TAG, LG4FF_G25_NAME}, |
| 165 | [LG4FF_MODE_DFGT_IDX] = {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, LG4FF_DFGT_TAG, LG4FF_DFGT_NAME}, |
| 166 | [LG4FF_MODE_G27_IDX] = {USB_DEVICE_ID_LOGITECH_G27_WHEEL, LG4FF_G27_TAG, LG4FF_G27_NAME} |
| 167 | }; |
| 168 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 169 | /* Multimode wheel identificators */ |
| 170 | static const struct lg4ff_wheel_ident_info lg4ff_dfp_ident_info = { |
| 171 | 0xf000, |
| 172 | 0x1000, |
| 173 | USB_DEVICE_ID_LOGITECH_DFP_WHEEL |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 174 | }; |
| 175 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 176 | static const struct lg4ff_wheel_ident_info lg4ff_g25_ident_info = { |
| 177 | 0xff00, |
| 178 | 0x1200, |
| 179 | USB_DEVICE_ID_LOGITECH_G25_WHEEL |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 180 | }; |
| 181 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 182 | static const struct lg4ff_wheel_ident_info lg4ff_g27_ident_info = { |
| 183 | 0xfff0, |
| 184 | 0x1230, |
| 185 | USB_DEVICE_ID_LOGITECH_G27_WHEEL |
| 186 | }; |
| 187 | |
| 188 | static const struct lg4ff_wheel_ident_info lg4ff_dfgt_ident_info = { |
| 189 | 0xff00, |
| 190 | 0x1300, |
| 191 | USB_DEVICE_ID_LOGITECH_DFGT_WHEEL |
| 192 | }; |
| 193 | |
| 194 | /* Multimode wheel identification checklists */ |
| 195 | static const struct lg4ff_wheel_ident_checklist lg4ff_main_checklist = { |
| 196 | 4, |
| 197 | {&lg4ff_dfgt_ident_info, |
| 198 | &lg4ff_g27_ident_info, |
| 199 | &lg4ff_g25_ident_info, |
| 200 | &lg4ff_dfp_ident_info} |
| 201 | }; |
| 202 | |
| 203 | /* Compatibility mode switching commands */ |
| 204 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_dfp = { |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 205 | 1, |
| 206 | {0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 207 | }; |
| 208 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 209 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_dfgt = { |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 210 | 2, |
| 211 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1st command */ |
| 212 | 0xf8, 0x09, 0x03, 0x01, 0x00, 0x00, 0x00} /* 2nd command */ |
| 213 | }; |
| 214 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 215 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_g25 = { |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 216 | 1, |
| 217 | {0xf8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 218 | }; |
| 219 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 220 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_g27 = { |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 221 | 2, |
| 222 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1st command */ |
| 223 | 0xf8, 0x09, 0x04, 0x01, 0x00, 0x00, 0x00} /* 2nd command */ |
| 224 | }; |
| 225 | |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 226 | /* Recalculates X axis value accordingly to currently selected range */ |
| 227 | static __s32 lg4ff_adjust_dfp_x_axis(__s32 value, __u16 range) |
| 228 | { |
| 229 | __u16 max_range; |
| 230 | __s32 new_value; |
| 231 | |
| 232 | if (range == 900) |
| 233 | return value; |
| 234 | else if (range == 200) |
| 235 | return value; |
| 236 | else if (range < 200) |
| 237 | max_range = 200; |
| 238 | else |
| 239 | max_range = 900; |
| 240 | |
| 241 | new_value = 8192 + mult_frac(value - 8192, max_range, range); |
| 242 | if (new_value < 0) |
| 243 | return 0; |
| 244 | else if (new_value > 16383) |
| 245 | return 16383; |
| 246 | else |
| 247 | return new_value; |
| 248 | } |
| 249 | |
| 250 | int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field, |
| 251 | struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data) |
| 252 | { |
| 253 | struct lg4ff_device_entry *entry = drv_data->device_props; |
| 254 | __s32 new_value = 0; |
| 255 | |
| 256 | if (!entry) { |
| 257 | hid_err(hid, "Device properties not found"); |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | switch (entry->product_id) { |
| 262 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 263 | switch (usage->code) { |
| 264 | case ABS_X: |
| 265 | new_value = lg4ff_adjust_dfp_x_axis(value, entry->range); |
| 266 | input_event(field->hidinput->input, usage->type, usage->code, new_value); |
| 267 | return 1; |
| 268 | default: |
| 269 | return 0; |
| 270 | } |
| 271 | default: |
| 272 | return 0; |
| 273 | } |
| 274 | } |
| 275 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 276 | static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *effect) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 277 | { |
| 278 | struct hid_device *hid = input_get_drvdata(dev); |
| 279 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 280 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 281 | __s32 *value = report->field[0]->value; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 282 | int x; |
| 283 | |
Michal Malý | a80fe5d | 2012-09-24 01:13:17 +0200 | [diff] [blame] | 284 | #define CLAMP(x) do { if (x < 0) x = 0; else if (x > 0xff) x = 0xff; } while (0) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 285 | |
| 286 | switch (effect->type) { |
| 287 | case FF_CONSTANT: |
| 288 | x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ |
| 289 | CLAMP(x); |
Simon Wood | 56930e7 | 2013-11-06 12:30:42 -0700 | [diff] [blame] | 290 | |
| 291 | if (x == 0x80) { |
| 292 | /* De-activate force in slot-1*/ |
| 293 | value[0] = 0x13; |
| 294 | value[1] = 0x00; |
| 295 | value[2] = 0x00; |
| 296 | value[3] = 0x00; |
| 297 | value[4] = 0x00; |
| 298 | value[5] = 0x00; |
| 299 | value[6] = 0x00; |
| 300 | |
| 301 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
| 302 | return 0; |
| 303 | } |
| 304 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 305 | value[0] = 0x11; /* Slot 1 */ |
| 306 | value[1] = 0x08; |
| 307 | value[2] = x; |
| 308 | value[3] = 0x80; |
| 309 | value[4] = 0x00; |
| 310 | value[5] = 0x00; |
| 311 | value[6] = 0x00; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 312 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 313 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 314 | break; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 319 | /* Sends default autocentering command compatible with |
| 320 | * all wheels except Formula Force EX */ |
| 321 | static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitude) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 322 | { |
| 323 | struct hid_device *hid = input_get_drvdata(dev); |
| 324 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 325 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 326 | __s32 *value = report->field[0]->value; |
Simon Wood | f8c2315 | 2013-11-06 12:30:40 -0700 | [diff] [blame] | 327 | __u32 expand_a, expand_b; |
Simon Wood | 1859762 | 2013-11-06 12:30:44 -0700 | [diff] [blame] | 328 | struct lg4ff_device_entry *entry; |
| 329 | struct lg_drv_data *drv_data; |
| 330 | |
| 331 | drv_data = hid_get_drvdata(hid); |
| 332 | if (!drv_data) { |
| 333 | hid_err(hid, "Private driver data not found!\n"); |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | entry = drv_data->device_props; |
| 338 | if (!entry) { |
| 339 | hid_err(hid, "Device properties not found!\n"); |
| 340 | return; |
| 341 | } |
Simon Wood | f8c2315 | 2013-11-06 12:30:40 -0700 | [diff] [blame] | 342 | |
Simon Wood | d2c02da | 2013-11-06 12:30:41 -0700 | [diff] [blame] | 343 | /* De-activate Auto-Center */ |
| 344 | if (magnitude == 0) { |
| 345 | value[0] = 0xf5; |
| 346 | value[1] = 0x00; |
| 347 | value[2] = 0x00; |
| 348 | value[3] = 0x00; |
| 349 | value[4] = 0x00; |
| 350 | value[5] = 0x00; |
| 351 | value[6] = 0x00; |
| 352 | |
| 353 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
| 354 | return; |
| 355 | } |
| 356 | |
Simon Wood | f8c2315 | 2013-11-06 12:30:40 -0700 | [diff] [blame] | 357 | if (magnitude <= 0xaaaa) { |
| 358 | expand_a = 0x0c * magnitude; |
| 359 | expand_b = 0x80 * magnitude; |
| 360 | } else { |
| 361 | expand_a = (0x0c * 0xaaaa) + 0x06 * (magnitude - 0xaaaa); |
| 362 | expand_b = (0x80 * 0xaaaa) + 0xff * (magnitude - 0xaaaa); |
| 363 | } |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 364 | |
Simon Wood | 1859762 | 2013-11-06 12:30:44 -0700 | [diff] [blame] | 365 | /* Adjust for non-MOMO wheels */ |
| 366 | switch (entry->product_id) { |
| 367 | case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL: |
| 368 | case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2: |
| 369 | break; |
| 370 | default: |
| 371 | expand_a = expand_a >> 1; |
| 372 | break; |
| 373 | } |
| 374 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 375 | value[0] = 0xfe; |
| 376 | value[1] = 0x0d; |
Simon Wood | f8c2315 | 2013-11-06 12:30:40 -0700 | [diff] [blame] | 377 | value[2] = expand_a / 0xaaaa; |
| 378 | value[3] = expand_a / 0xaaaa; |
| 379 | value[4] = expand_b / 0xaaaa; |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 380 | value[5] = 0x00; |
| 381 | value[6] = 0x00; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 382 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 383 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Simon Wood | d2c02da | 2013-11-06 12:30:41 -0700 | [diff] [blame] | 384 | |
| 385 | /* Activate Auto-Center */ |
| 386 | value[0] = 0x14; |
| 387 | value[1] = 0x00; |
| 388 | value[2] = 0x00; |
| 389 | value[3] = 0x00; |
| 390 | value[4] = 0x00; |
| 391 | value[5] = 0x00; |
| 392 | value[6] = 0x00; |
| 393 | |
| 394 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 395 | } |
| 396 | |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 397 | /* Sends autocentering command compatible with Formula Force EX */ |
| 398 | static void hid_lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude) |
| 399 | { |
| 400 | struct hid_device *hid = input_get_drvdata(dev); |
| 401 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 402 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 403 | __s32 *value = report->field[0]->value; |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 404 | magnitude = magnitude * 90 / 65535; |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 405 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 406 | value[0] = 0xfe; |
| 407 | value[1] = 0x03; |
| 408 | value[2] = magnitude >> 14; |
| 409 | value[3] = magnitude >> 14; |
| 410 | value[4] = magnitude; |
| 411 | value[5] = 0x00; |
| 412 | value[6] = 0x00; |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 413 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 414 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 415 | } |
| 416 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 417 | /* Sends command to set range compatible with G25/G27/Driving Force GT */ |
| 418 | static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range) |
| 419 | { |
| 420 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 421 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 422 | __s32 *value = report->field[0]->value; |
| 423 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 424 | dbg_hid("G25/G27/DFGT: setting range to %u\n", range); |
| 425 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 426 | value[0] = 0xf8; |
| 427 | value[1] = 0x81; |
| 428 | value[2] = range & 0x00ff; |
| 429 | value[3] = (range & 0xff00) >> 8; |
| 430 | value[4] = 0x00; |
| 431 | value[5] = 0x00; |
| 432 | value[6] = 0x00; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 433 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 434 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* Sends commands to set range compatible with Driving Force Pro wheel */ |
| 438 | static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range) |
| 439 | { |
| 440 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 441 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
| 442 | int start_left, start_right, full_range; |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 443 | __s32 *value = report->field[0]->value; |
| 444 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 445 | dbg_hid("Driving Force Pro: setting range to %u\n", range); |
| 446 | |
| 447 | /* Prepare "coarse" limit command */ |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 448 | value[0] = 0xf8; |
Michal Malý | a80fe5d | 2012-09-24 01:13:17 +0200 | [diff] [blame] | 449 | value[1] = 0x00; /* Set later */ |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 450 | value[2] = 0x00; |
| 451 | value[3] = 0x00; |
| 452 | value[4] = 0x00; |
| 453 | value[5] = 0x00; |
| 454 | value[6] = 0x00; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 455 | |
| 456 | if (range > 200) { |
| 457 | report->field[0]->value[1] = 0x03; |
| 458 | full_range = 900; |
| 459 | } else { |
| 460 | report->field[0]->value[1] = 0x02; |
| 461 | full_range = 200; |
| 462 | } |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 463 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 464 | |
| 465 | /* Prepare "fine" limit command */ |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 466 | value[0] = 0x81; |
| 467 | value[1] = 0x0b; |
| 468 | value[2] = 0x00; |
| 469 | value[3] = 0x00; |
| 470 | value[4] = 0x00; |
| 471 | value[5] = 0x00; |
| 472 | value[6] = 0x00; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 473 | |
| 474 | if (range == 200 || range == 900) { /* Do not apply any fine limit */ |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 475 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | |
| 479 | /* Construct fine limit command */ |
| 480 | start_left = (((full_range - range + 1) * 2047) / full_range); |
| 481 | start_right = 0xfff - start_left; |
| 482 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 483 | value[2] = start_left >> 4; |
| 484 | value[3] = start_right >> 4; |
| 485 | value[4] = 0xff; |
| 486 | value[5] = (start_right & 0xe) << 4 | (start_left & 0xe); |
| 487 | value[6] = 0xff; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 488 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 489 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 492 | static int lg4ff_switch_compatibility_mode(struct hid_device *hid, const struct lg4ff_compat_mode_switch *s) |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 493 | { |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 494 | struct usb_device *usbdev = hid_to_usb_dev(hid); |
| 495 | struct usbhid_device *usbhid = hid->driver_data; |
| 496 | u8 i; |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 497 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 498 | for (i = 0; i < s->cmd_count; i++) { |
| 499 | int xferd, ret; |
| 500 | u8 data[7]; |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 501 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 502 | memcpy(data, s->cmd + (7*i), 7); |
| 503 | ret = usb_interrupt_msg(usbdev, usbhid->urbout->pipe, data, 7, &xferd, USB_CTRL_SET_TIMEOUT); |
| 504 | if (ret) |
| 505 | return ret; |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 506 | } |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 507 | return 0; |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 508 | } |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 509 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 510 | static ssize_t lg4ff_alternate_modes_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 511 | { |
| 512 | struct hid_device *hid = to_hid_device(dev); |
| 513 | struct lg4ff_device_entry *entry; |
| 514 | struct lg_drv_data *drv_data; |
| 515 | ssize_t count = 0; |
| 516 | int i; |
| 517 | |
| 518 | drv_data = hid_get_drvdata(hid); |
| 519 | if (!drv_data) { |
| 520 | hid_err(hid, "Private driver data not found!\n"); |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | entry = drv_data->device_props; |
| 525 | if (!entry) { |
| 526 | hid_err(hid, "Device properties not found!\n"); |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | if (!entry->real_name) { |
| 531 | hid_err(hid, "NULL pointer to string\n"); |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | for (i = 0; i < LG4FF_MODE_MAX_IDX; i++) { |
| 536 | if (entry->alternate_modes & BIT(i)) { |
| 537 | /* Print tag and full name */ |
| 538 | count += scnprintf(buf + count, PAGE_SIZE - count, "%s: %s", |
| 539 | lg4ff_alternate_modes[i].tag, |
| 540 | !lg4ff_alternate_modes[i].product_id ? entry->real_name : lg4ff_alternate_modes[i].name); |
| 541 | if (count >= PAGE_SIZE - 1) |
| 542 | return count; |
| 543 | |
| 544 | /* Mark the currently active mode with an asterisk */ |
| 545 | if (lg4ff_alternate_modes[i].product_id == entry->product_id || |
| 546 | (lg4ff_alternate_modes[i].product_id == 0 && entry->product_id == entry->real_product_id)) |
| 547 | count += scnprintf(buf + count, PAGE_SIZE - count, " *\n"); |
| 548 | else |
| 549 | count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 550 | |
| 551 | if (count >= PAGE_SIZE - 1) |
| 552 | return count; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | return count; |
| 557 | } |
| 558 | |
| 559 | static ssize_t lg4ff_alternate_modes_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 560 | { |
| 561 | return -ENOSYS; |
| 562 | } |
| 563 | static DEVICE_ATTR(alternate_modes, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, lg4ff_alternate_modes_show, lg4ff_alternate_modes_store); |
| 564 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 565 | /* Read current range and display it in terminal */ |
Vivien Didelot | 2f1cec3 | 2015-01-19 02:03:26 -0500 | [diff] [blame] | 566 | static ssize_t range_show(struct device *dev, struct device_attribute *attr, |
| 567 | char *buf) |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 568 | { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 569 | struct hid_device *hid = to_hid_device(dev); |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 570 | struct lg4ff_device_entry *entry; |
| 571 | struct lg_drv_data *drv_data; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 572 | size_t count; |
| 573 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 574 | drv_data = hid_get_drvdata(hid); |
| 575 | if (!drv_data) { |
| 576 | hid_err(hid, "Private driver data not found!\n"); |
| 577 | return 0; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 578 | } |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 579 | |
| 580 | entry = drv_data->device_props; |
| 581 | if (!entry) { |
| 582 | hid_err(hid, "Device properties not found!\n"); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | count = scnprintf(buf, PAGE_SIZE, "%u\n", entry->range); |
| 587 | return count; |
| 588 | } |
| 589 | |
| 590 | /* Set range to user specified value, call appropriate function |
| 591 | * according to the type of the wheel */ |
Vivien Didelot | 2f1cec3 | 2015-01-19 02:03:26 -0500 | [diff] [blame] | 592 | static ssize_t range_store(struct device *dev, struct device_attribute *attr, |
| 593 | const char *buf, size_t count) |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 594 | { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 595 | struct hid_device *hid = to_hid_device(dev); |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 596 | struct lg4ff_device_entry *entry; |
| 597 | struct lg_drv_data *drv_data; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 598 | __u16 range = simple_strtoul(buf, NULL, 10); |
| 599 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 600 | drv_data = hid_get_drvdata(hid); |
| 601 | if (!drv_data) { |
| 602 | hid_err(hid, "Private driver data not found!\n"); |
Simon Wood | 29ff665 | 2014-08-14 20:43:01 -0600 | [diff] [blame] | 603 | return -EINVAL; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 604 | } |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 605 | |
| 606 | entry = drv_data->device_props; |
| 607 | if (!entry) { |
| 608 | hid_err(hid, "Device properties not found!\n"); |
Simon Wood | 29ff665 | 2014-08-14 20:43:01 -0600 | [diff] [blame] | 609 | return -EINVAL; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | if (range == 0) |
| 613 | range = entry->max_range; |
| 614 | |
| 615 | /* Check if the wheel supports range setting |
| 616 | * and that the range is within limits for the wheel */ |
| 617 | if (entry->set_range != NULL && range >= entry->min_range && range <= entry->max_range) { |
| 618 | entry->set_range(hid, range); |
| 619 | entry->range = range; |
| 620 | } |
| 621 | |
| 622 | return count; |
| 623 | } |
Vivien Didelot | 2f1cec3 | 2015-01-19 02:03:26 -0500 | [diff] [blame] | 624 | static DEVICE_ATTR_RW(range); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 625 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 626 | static ssize_t lg4ff_real_id_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 627 | { |
| 628 | struct hid_device *hid = to_hid_device(dev); |
| 629 | struct lg4ff_device_entry *entry; |
| 630 | struct lg_drv_data *drv_data; |
| 631 | size_t count; |
| 632 | |
| 633 | drv_data = hid_get_drvdata(hid); |
| 634 | if (!drv_data) { |
| 635 | hid_err(hid, "Private driver data not found!\n"); |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | entry = drv_data->device_props; |
| 640 | if (!entry) { |
| 641 | hid_err(hid, "Device properties not found!\n"); |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | if (!entry->real_tag || !entry->real_name) { |
| 646 | hid_err(hid, "NULL pointer to string\n"); |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | count = scnprintf(buf, PAGE_SIZE, "%s: %s\n", entry->real_tag, entry->real_name); |
| 651 | return count; |
| 652 | } |
| 653 | |
| 654 | static ssize_t lg4ff_real_id_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 655 | { |
| 656 | /* Real ID is a read-only value */ |
| 657 | return -EPERM; |
| 658 | } |
| 659 | static DEVICE_ATTR(real_id, S_IRUGO, lg4ff_real_id_show, lg4ff_real_id_store); |
| 660 | |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 661 | #ifdef CONFIG_LEDS_CLASS |
| 662 | static void lg4ff_set_leds(struct hid_device *hid, __u8 leds) |
| 663 | { |
| 664 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 665 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 666 | __s32 *value = report->field[0]->value; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 667 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 668 | value[0] = 0xf8; |
| 669 | value[1] = 0x12; |
| 670 | value[2] = leds; |
| 671 | value[3] = 0x00; |
| 672 | value[4] = 0x00; |
| 673 | value[5] = 0x00; |
| 674 | value[6] = 0x00; |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 675 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | static void lg4ff_led_set_brightness(struct led_classdev *led_cdev, |
| 679 | enum led_brightness value) |
| 680 | { |
| 681 | struct device *dev = led_cdev->dev->parent; |
| 682 | struct hid_device *hid = container_of(dev, struct hid_device, dev); |
Axel Lin | 4629fd1 | 2012-09-13 14:09:33 +0800 | [diff] [blame] | 683 | struct lg_drv_data *drv_data = hid_get_drvdata(hid); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 684 | struct lg4ff_device_entry *entry; |
| 685 | int i, state = 0; |
| 686 | |
| 687 | if (!drv_data) { |
| 688 | hid_err(hid, "Device data not found."); |
| 689 | return; |
| 690 | } |
| 691 | |
| 692 | entry = (struct lg4ff_device_entry *)drv_data->device_props; |
| 693 | |
| 694 | if (!entry) { |
| 695 | hid_err(hid, "Device properties not found."); |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | for (i = 0; i < 5; i++) { |
| 700 | if (led_cdev != entry->led[i]) |
| 701 | continue; |
| 702 | state = (entry->led_state >> i) & 1; |
| 703 | if (value == LED_OFF && state) { |
| 704 | entry->led_state &= ~(1 << i); |
| 705 | lg4ff_set_leds(hid, entry->led_state); |
| 706 | } else if (value != LED_OFF && !state) { |
| 707 | entry->led_state |= 1 << i; |
| 708 | lg4ff_set_leds(hid, entry->led_state); |
| 709 | } |
| 710 | break; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cdev) |
| 715 | { |
| 716 | struct device *dev = led_cdev->dev->parent; |
| 717 | struct hid_device *hid = container_of(dev, struct hid_device, dev); |
Axel Lin | 4629fd1 | 2012-09-13 14:09:33 +0800 | [diff] [blame] | 718 | struct lg_drv_data *drv_data = hid_get_drvdata(hid); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 719 | struct lg4ff_device_entry *entry; |
| 720 | int i, value = 0; |
| 721 | |
| 722 | if (!drv_data) { |
| 723 | hid_err(hid, "Device data not found."); |
| 724 | return LED_OFF; |
| 725 | } |
| 726 | |
| 727 | entry = (struct lg4ff_device_entry *)drv_data->device_props; |
| 728 | |
| 729 | if (!entry) { |
| 730 | hid_err(hid, "Device properties not found."); |
| 731 | return LED_OFF; |
| 732 | } |
| 733 | |
| 734 | for (i = 0; i < 5; i++) |
| 735 | if (led_cdev == entry->led[i]) { |
| 736 | value = (entry->led_state >> i) & 1; |
| 737 | break; |
| 738 | } |
| 739 | |
| 740 | return value ? LED_FULL : LED_OFF; |
| 741 | } |
| 742 | #endif |
| 743 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 744 | static u16 lg4ff_identify_multimode_wheel(struct hid_device *hid, const u16 reported_product_id, const u16 bcdDevice) |
| 745 | { |
| 746 | const struct lg4ff_wheel_ident_checklist *checklist; |
| 747 | int i, from_idx, to_idx; |
| 748 | |
| 749 | switch (reported_product_id) { |
| 750 | case USB_DEVICE_ID_LOGITECH_WHEEL: |
| 751 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 752 | checklist = &lg4ff_main_checklist; |
| 753 | from_idx = 0; |
| 754 | to_idx = checklist->count - 1; |
| 755 | break; |
| 756 | case USB_DEVICE_ID_LOGITECH_G25_WHEEL: |
| 757 | checklist = &lg4ff_main_checklist; |
| 758 | from_idx = 0; |
| 759 | to_idx = checklist->count - 2; /* End identity check at G25 */ |
| 760 | break; |
| 761 | case USB_DEVICE_ID_LOGITECH_G27_WHEEL: |
| 762 | checklist = &lg4ff_main_checklist; |
| 763 | from_idx = 1; /* Start identity check at G27 */ |
| 764 | to_idx = checklist->count - 3; /* End identity check at G27 */ |
| 765 | break; |
| 766 | case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL: |
| 767 | checklist = &lg4ff_main_checklist; |
| 768 | from_idx = 0; |
| 769 | to_idx = checklist->count - 4; /* End identity check at DFGT */ |
| 770 | break; |
| 771 | default: |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | for (i = from_idx; i <= to_idx; i++) { |
| 776 | const u16 mask = checklist->models[i]->mask; |
| 777 | const u16 result = checklist->models[i]->result; |
| 778 | const u16 real_product_id = checklist->models[i]->real_product_id; |
| 779 | |
| 780 | if ((bcdDevice & mask) == result) { |
| 781 | dbg_hid("Found wheel with real PID %X whose reported PID is %X\n", real_product_id, reported_product_id); |
| 782 | return real_product_id; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | /* No match found. This is an unknown wheel model, do not touch it */ |
| 787 | dbg_hid("Wheel with bcdDevice %X was not recognized as multimode wheel, leaving in its current mode\n", bcdDevice); |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | static int lg4ff_handle_multimode_wheel(struct hid_device *hid, u16 *real_product_id, const u16 bcdDevice) |
| 792 | { |
| 793 | const u16 reported_product_id = hid->product; |
| 794 | int ret; |
| 795 | |
| 796 | *real_product_id = lg4ff_identify_multimode_wheel(hid, reported_product_id, bcdDevice); |
| 797 | /* Probed wheel is not a multimode wheel */ |
| 798 | if (!*real_product_id) { |
| 799 | *real_product_id = reported_product_id; |
| 800 | dbg_hid("Wheel is not a multimode wheel\n"); |
| 801 | return LG4FF_MMODE_NOT_MULTIMODE; |
| 802 | } |
| 803 | |
| 804 | /* Switch from "Driving Force" mode to native mode automatically. |
| 805 | * Otherwise keep the wheel in its current mode */ |
| 806 | if (reported_product_id == USB_DEVICE_ID_LOGITECH_WHEEL && |
Michal Malý | a54dc779 | 2015-02-18 17:59:22 +0100 | [diff] [blame^] | 807 | reported_product_id != *real_product_id && |
| 808 | !lg4ff_no_autoswitch) { |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 809 | const struct lg4ff_compat_mode_switch *s; |
| 810 | |
| 811 | switch (*real_product_id) { |
| 812 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 813 | s = &lg4ff_mode_switch_dfp; |
| 814 | break; |
| 815 | case USB_DEVICE_ID_LOGITECH_G25_WHEEL: |
| 816 | s = &lg4ff_mode_switch_g25; |
| 817 | break; |
| 818 | case USB_DEVICE_ID_LOGITECH_G27_WHEEL: |
| 819 | s = &lg4ff_mode_switch_g27; |
| 820 | break; |
| 821 | case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL: |
| 822 | s = &lg4ff_mode_switch_dfgt; |
| 823 | break; |
| 824 | default: |
| 825 | hid_err(hid, "Invalid product id %X\n", *real_product_id); |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 826 | return LG4FF_MMODE_NOT_MULTIMODE; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | ret = lg4ff_switch_compatibility_mode(hid, s); |
| 830 | if (ret) { |
| 831 | /* Wheel could not have been switched to native mode, |
| 832 | * leave it in "Driving Force" mode and continue */ |
| 833 | hid_err(hid, "Unable to switch wheel mode, errno %d\n", ret); |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 834 | return LG4FF_MMODE_IS_MULTIMODE; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 835 | } |
| 836 | return LG4FF_MMODE_SWITCHED; |
| 837 | } |
| 838 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 839 | return LG4FF_MMODE_IS_MULTIMODE; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 843 | int lg4ff_init(struct hid_device *hid) |
| 844 | { |
| 845 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 846 | struct input_dev *dev = hidinput->input; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 847 | const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor); |
| 848 | const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 849 | struct lg4ff_device_entry *entry; |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 850 | struct lg_drv_data *drv_data; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 851 | int error, i, j; |
| 852 | int mmode_ret, mmode_idx = -1; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 853 | u16 real_product_id; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 854 | |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 855 | /* Check that the report looks ok */ |
Kees Cook | 0fb6bd0 | 2013-09-11 21:56:54 +0200 | [diff] [blame] | 856 | if (!hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7)) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 857 | return -1; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 858 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 859 | /* Check if a multimode wheel has been connected and |
| 860 | * handle it appropriately */ |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 861 | mmode_ret = lg4ff_handle_multimode_wheel(hid, &real_product_id, bcdDevice); |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 862 | |
| 863 | /* Wheel has been told to switch to native mode. There is no point in going on |
| 864 | * with the initialization as the wheel will do a USB reset when it switches mode |
| 865 | */ |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 866 | if (mmode_ret == LG4FF_MMODE_SWITCHED) |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 867 | return 0; |
| 868 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 869 | /* Check what wheel has been connected */ |
| 870 | for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) { |
| 871 | if (hid->product == lg4ff_devices[i].product_id) { |
| 872 | dbg_hid("Found compatible device, product ID %04X\n", lg4ff_devices[i].product_id); |
| 873 | break; |
| 874 | } |
| 875 | } |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 876 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 877 | if (i == ARRAY_SIZE(lg4ff_devices)) { |
| 878 | hid_err(hid, "Device is not supported by lg4ff driver. If you think it should be, consider reporting a bug to" |
| 879 | "LKML, Simon Wood <simon@mungewell.org> or Michal Maly <madcatxster@gmail.com>\n"); |
| 880 | return -1; |
| 881 | } |
| 882 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 883 | if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) { |
| 884 | for (mmode_idx = 0; mmode_idx < ARRAY_SIZE(lg4ff_multimode_wheels); mmode_idx++) { |
| 885 | if (real_product_id == lg4ff_multimode_wheels[mmode_idx].product_id) |
| 886 | break; |
| 887 | } |
| 888 | |
| 889 | if (mmode_idx == ARRAY_SIZE(lg4ff_multimode_wheels)) { |
| 890 | hid_err(hid, "Device product ID %X is not listed as a multimode wheel", real_product_id); |
| 891 | return -1; |
| 892 | } |
| 893 | } |
| 894 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 895 | /* Set supported force feedback capabilities */ |
| 896 | for (j = 0; lg4ff_devices[i].ff_effects[j] >= 0; j++) |
| 897 | set_bit(lg4ff_devices[i].ff_effects[j], dev->ffbit); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 898 | |
| 899 | error = input_ff_create_memless(dev, NULL, hid_lg4ff_play); |
| 900 | |
| 901 | if (error) |
| 902 | return error; |
| 903 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 904 | /* Get private driver data */ |
| 905 | drv_data = hid_get_drvdata(hid); |
| 906 | if (!drv_data) { |
| 907 | hid_err(hid, "Cannot add device, private driver data not allocated\n"); |
| 908 | return -1; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 909 | } |
| 910 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 911 | /* Initialize device properties */ |
Thomas Meyer | 8383c6b | 2011-11-08 20:14:14 +0100 | [diff] [blame] | 912 | entry = kzalloc(sizeof(struct lg4ff_device_entry), GFP_KERNEL); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 913 | if (!entry) { |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 914 | hid_err(hid, "Cannot add device, insufficient memory to allocate device properties.\n"); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 915 | return -ENOMEM; |
| 916 | } |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 917 | drv_data->device_props = entry; |
| 918 | |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 919 | entry->product_id = lg4ff_devices[i].product_id; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 920 | entry->real_product_id = real_product_id; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 921 | entry->min_range = lg4ff_devices[i].min_range; |
| 922 | entry->max_range = lg4ff_devices[i].max_range; |
| 923 | entry->set_range = lg4ff_devices[i].set_range; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 924 | if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) { |
| 925 | BUG_ON(mmode_idx == -1); |
| 926 | entry->alternate_modes = lg4ff_multimode_wheels[mmode_idx].alternate_modes; |
| 927 | entry->real_tag = lg4ff_multimode_wheels[mmode_idx].real_tag; |
| 928 | entry->real_name = lg4ff_multimode_wheels[mmode_idx].real_name; |
| 929 | } |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 930 | |
Simon Wood | 114a55c | 2013-11-06 12:30:43 -0700 | [diff] [blame] | 931 | /* Check if autocentering is available and |
| 932 | * set the centering force to zero by default */ |
| 933 | if (test_bit(FF_AUTOCENTER, dev->ffbit)) { |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 934 | /* Formula Force EX expects different autocentering command */ |
| 935 | if ((bcdDevice >> 8) == LG4FF_FFEX_REV_MAJ && |
| 936 | (bcdDevice & 0xff) == LG4FF_FFEX_REV_MIN) |
Simon Wood | 114a55c | 2013-11-06 12:30:43 -0700 | [diff] [blame] | 937 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex; |
| 938 | else |
| 939 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default; |
| 940 | |
| 941 | dev->ff->set_autocenter(dev, 0); |
| 942 | } |
| 943 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 944 | /* Create sysfs interface */ |
| 945 | error = device_create_file(&hid->dev, &dev_attr_range); |
| 946 | if (error) |
| 947 | return error; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 948 | if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) { |
| 949 | error = device_create_file(&hid->dev, &dev_attr_real_id); |
| 950 | if (error) |
| 951 | return error; |
| 952 | error = device_create_file(&hid->dev, &dev_attr_alternate_modes); |
| 953 | if (error) |
| 954 | return error; |
| 955 | } |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 956 | dbg_hid("sysfs interface created\n"); |
| 957 | |
| 958 | /* Set the maximum range to start with */ |
| 959 | entry->range = entry->max_range; |
| 960 | if (entry->set_range != NULL) |
| 961 | entry->set_range(hid, entry->range); |
| 962 | |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 963 | #ifdef CONFIG_LEDS_CLASS |
| 964 | /* register led subsystem - G27 only */ |
| 965 | entry->led_state = 0; |
| 966 | for (j = 0; j < 5; j++) |
| 967 | entry->led[j] = NULL; |
| 968 | |
| 969 | if (lg4ff_devices[i].product_id == USB_DEVICE_ID_LOGITECH_G27_WHEEL) { |
| 970 | struct led_classdev *led; |
| 971 | size_t name_sz; |
| 972 | char *name; |
| 973 | |
| 974 | lg4ff_set_leds(hid, 0); |
| 975 | |
| 976 | name_sz = strlen(dev_name(&hid->dev)) + 8; |
| 977 | |
| 978 | for (j = 0; j < 5; j++) { |
| 979 | led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL); |
| 980 | if (!led) { |
| 981 | hid_err(hid, "can't allocate memory for LED %d\n", j); |
| 982 | goto err; |
| 983 | } |
| 984 | |
| 985 | name = (void *)(&led[1]); |
| 986 | snprintf(name, name_sz, "%s::RPM%d", dev_name(&hid->dev), j+1); |
| 987 | led->name = name; |
| 988 | led->brightness = 0; |
| 989 | led->max_brightness = 1; |
| 990 | led->brightness_get = lg4ff_led_get_brightness; |
| 991 | led->brightness_set = lg4ff_led_set_brightness; |
| 992 | |
| 993 | entry->led[j] = led; |
| 994 | error = led_classdev_register(&hid->dev, led); |
| 995 | |
| 996 | if (error) { |
| 997 | hid_err(hid, "failed to register LED %d. Aborting.\n", j); |
| 998 | err: |
| 999 | /* Deregister LEDs (if any) */ |
| 1000 | for (j = 0; j < 5; j++) { |
| 1001 | led = entry->led[j]; |
| 1002 | entry->led[j] = NULL; |
| 1003 | if (!led) |
| 1004 | continue; |
| 1005 | led_classdev_unregister(led); |
| 1006 | kfree(led); |
| 1007 | } |
| 1008 | goto out; /* Let the driver continue without LEDs */ |
| 1009 | } |
| 1010 | } |
| 1011 | } |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1012 | out: |
Jiri Kosina | c6e6dc8 | 2012-04-23 21:08:15 +0200 | [diff] [blame] | 1013 | #endif |
Simon Wood | 6401380 | 2012-04-21 05:41:16 -0700 | [diff] [blame] | 1014 | hid_info(hid, "Force feedback support for Logitech Gaming Wheels\n"); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1015 | return 0; |
| 1016 | } |
| 1017 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1018 | int lg4ff_deinit(struct hid_device *hid) |
| 1019 | { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1020 | struct lg4ff_device_entry *entry; |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1021 | struct lg_drv_data *drv_data; |
| 1022 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1023 | drv_data = hid_get_drvdata(hid); |
| 1024 | if (!drv_data) { |
| 1025 | hid_err(hid, "Error while deinitializing device, no private driver data.\n"); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1026 | return -1; |
| 1027 | } |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1028 | entry = drv_data->device_props; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1029 | if (!entry) |
| 1030 | goto out; /* Nothing more to do */ |
| 1031 | |
| 1032 | device_remove_file(&hid->dev, &dev_attr_range); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1033 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1034 | /* Multimode devices will have at least the "MODE_NATIVE" bit set */ |
| 1035 | if (entry->alternate_modes) { |
| 1036 | device_remove_file(&hid->dev, &dev_attr_real_id); |
| 1037 | device_remove_file(&hid->dev, &dev_attr_alternate_modes); |
| 1038 | } |
| 1039 | |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1040 | #ifdef CONFIG_LEDS_CLASS |
| 1041 | { |
| 1042 | int j; |
| 1043 | struct led_classdev *led; |
| 1044 | |
| 1045 | /* Deregister LEDs (if any) */ |
| 1046 | for (j = 0; j < 5; j++) { |
| 1047 | |
| 1048 | led = entry->led[j]; |
| 1049 | entry->led[j] = NULL; |
| 1050 | if (!led) |
| 1051 | continue; |
| 1052 | led_classdev_unregister(led); |
| 1053 | kfree(led); |
| 1054 | } |
| 1055 | } |
| 1056 | #endif |
| 1057 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1058 | /* Deallocate memory */ |
| 1059 | kfree(entry); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1060 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1061 | out: |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1062 | dbg_hid("Device successfully unregistered\n"); |
| 1063 | return 0; |
| 1064 | } |