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ý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 71 | static void lg4ff_set_range_dfp(struct hid_device *hid, u16 range); |
| 72 | static void 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ý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 74 | struct lg4ff_wheel_data { |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 75 | u32 product_id; |
| 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 |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 80 | u8 led_state; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 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ý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 87 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 88 | void (*set_range)(struct hid_device *hid, u16 range); |
| 89 | }; |
| 90 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 91 | struct lg4ff_device_entry { |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 92 | spinlock_t report_lock; /* Protect output HID report */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 93 | struct lg4ff_wheel_data wdata; |
| 94 | }; |
| 95 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 96 | static const signed short lg4ff_wheel_effects[] = { |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 97 | FF_CONSTANT, |
| 98 | FF_AUTOCENTER, |
| 99 | -1 |
| 100 | }; |
| 101 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 102 | struct lg4ff_wheel { |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 103 | const u32 product_id; |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 104 | const signed short *ff_effects; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 105 | const u16 min_range; |
| 106 | const u16 max_range; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 107 | void (*set_range)(struct hid_device *hid, u16 range); |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 108 | }; |
| 109 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 110 | struct lg4ff_compat_mode_switch { |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 111 | const u8 cmd_count; /* Number of commands to send */ |
| 112 | const u8 cmd[]; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct lg4ff_wheel_ident_info { |
| 116 | const u16 mask; |
| 117 | const u16 result; |
| 118 | const u16 real_product_id; |
| 119 | }; |
| 120 | |
| 121 | struct lg4ff_wheel_ident_checklist { |
| 122 | const u32 count; |
| 123 | const struct lg4ff_wheel_ident_info *models[]; |
| 124 | }; |
| 125 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 126 | struct lg4ff_multimode_wheel { |
| 127 | const u16 product_id; |
| 128 | const u32 alternate_modes; |
| 129 | const char *real_tag; |
| 130 | const char *real_name; |
| 131 | }; |
| 132 | |
| 133 | struct lg4ff_alternate_mode { |
| 134 | const u16 product_id; |
| 135 | const char *tag; |
| 136 | const char *name; |
| 137 | }; |
| 138 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 139 | static const struct lg4ff_wheel lg4ff_devices[] = { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 140 | {USB_DEVICE_ID_LOGITECH_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, |
| 141 | {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 142 | {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, lg4ff_wheel_effects, 40, 900, lg4ff_set_range_dfp}, |
| 143 | {USB_DEVICE_ID_LOGITECH_G25_WHEEL, lg4ff_wheel_effects, 40, 900, lg4ff_set_range_g25}, |
| 144 | {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, lg4ff_wheel_effects, 40, 900, lg4ff_set_range_g25}, |
| 145 | {USB_DEVICE_ID_LOGITECH_G27_WHEEL, lg4ff_wheel_effects, 40, 900, lg4ff_set_range_g25}, |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 146 | {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2, lg4ff_wheel_effects, 40, 270, NULL}, |
| 147 | {USB_DEVICE_ID_LOGITECH_WII_WHEEL, lg4ff_wheel_effects, 40, 270, NULL} |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 150 | static const struct lg4ff_multimode_wheel lg4ff_multimode_wheels[] = { |
| 151 | {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, |
| 152 | LG4FF_MODE_NATIVE | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 153 | LG4FF_DFP_TAG, LG4FF_DFP_NAME}, |
| 154 | {USB_DEVICE_ID_LOGITECH_G25_WHEEL, |
| 155 | LG4FF_MODE_NATIVE | LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 156 | LG4FF_G25_TAG, LG4FF_G25_NAME}, |
| 157 | {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, |
| 158 | LG4FF_MODE_NATIVE | LG4FF_MODE_DFGT | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 159 | LG4FF_DFGT_TAG, LG4FF_DFGT_NAME}, |
| 160 | {USB_DEVICE_ID_LOGITECH_G27_WHEEL, |
| 161 | LG4FF_MODE_NATIVE | LG4FF_MODE_G27 | LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX, |
| 162 | LG4FF_G27_TAG, LG4FF_G27_NAME}, |
| 163 | }; |
| 164 | |
| 165 | static const struct lg4ff_alternate_mode lg4ff_alternate_modes[] = { |
| 166 | [LG4FF_MODE_NATIVE_IDX] = {0, "native", ""}, |
| 167 | [LG4FF_MODE_DFEX_IDX] = {USB_DEVICE_ID_LOGITECH_WHEEL, LG4FF_DFEX_TAG, LG4FF_DFEX_NAME}, |
| 168 | [LG4FF_MODE_DFP_IDX] = {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, LG4FF_DFP_TAG, LG4FF_DFP_NAME}, |
| 169 | [LG4FF_MODE_G25_IDX] = {USB_DEVICE_ID_LOGITECH_G25_WHEEL, LG4FF_G25_TAG, LG4FF_G25_NAME}, |
| 170 | [LG4FF_MODE_DFGT_IDX] = {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, LG4FF_DFGT_TAG, LG4FF_DFGT_NAME}, |
| 171 | [LG4FF_MODE_G27_IDX] = {USB_DEVICE_ID_LOGITECH_G27_WHEEL, LG4FF_G27_TAG, LG4FF_G27_NAME} |
| 172 | }; |
| 173 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 174 | /* Multimode wheel identificators */ |
| 175 | static const struct lg4ff_wheel_ident_info lg4ff_dfp_ident_info = { |
| 176 | 0xf000, |
| 177 | 0x1000, |
| 178 | USB_DEVICE_ID_LOGITECH_DFP_WHEEL |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 181 | static const struct lg4ff_wheel_ident_info lg4ff_g25_ident_info = { |
| 182 | 0xff00, |
| 183 | 0x1200, |
| 184 | USB_DEVICE_ID_LOGITECH_G25_WHEEL |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 185 | }; |
| 186 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 187 | static const struct lg4ff_wheel_ident_info lg4ff_g27_ident_info = { |
| 188 | 0xfff0, |
| 189 | 0x1230, |
| 190 | USB_DEVICE_ID_LOGITECH_G27_WHEEL |
| 191 | }; |
| 192 | |
| 193 | static const struct lg4ff_wheel_ident_info lg4ff_dfgt_ident_info = { |
| 194 | 0xff00, |
| 195 | 0x1300, |
| 196 | USB_DEVICE_ID_LOGITECH_DFGT_WHEEL |
| 197 | }; |
| 198 | |
| 199 | /* Multimode wheel identification checklists */ |
| 200 | static const struct lg4ff_wheel_ident_checklist lg4ff_main_checklist = { |
| 201 | 4, |
| 202 | {&lg4ff_dfgt_ident_info, |
| 203 | &lg4ff_g27_ident_info, |
| 204 | &lg4ff_g25_ident_info, |
| 205 | &lg4ff_dfp_ident_info} |
| 206 | }; |
| 207 | |
| 208 | /* Compatibility mode switching commands */ |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 209 | /* EXT_CMD9 - Understood by G27 and DFGT */ |
| 210 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_dfex = { |
| 211 | 2, |
| 212 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */ |
| 213 | 0xf8, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00} /* Switch mode to DF-EX with detach */ |
| 214 | }; |
| 215 | |
| 216 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_dfp = { |
| 217 | 2, |
| 218 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */ |
| 219 | 0xf8, 0x09, 0x01, 0x01, 0x00, 0x00, 0x00} /* Switch mode to DFP with detach */ |
| 220 | }; |
| 221 | |
| 222 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_g25 = { |
| 223 | 2, |
| 224 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */ |
| 225 | 0xf8, 0x09, 0x02, 0x01, 0x00, 0x00, 0x00} /* Switch mode to G25 with detach */ |
| 226 | }; |
| 227 | |
| 228 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_dfgt = { |
| 229 | 2, |
| 230 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */ |
| 231 | 0xf8, 0x09, 0x03, 0x01, 0x00, 0x00, 0x00} /* Switch mode to DFGT with detach */ |
| 232 | }; |
| 233 | |
| 234 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_g27 = { |
| 235 | 2, |
| 236 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */ |
| 237 | 0xf8, 0x09, 0x04, 0x01, 0x00, 0x00, 0x00} /* Switch mode to G27 with detach */ |
| 238 | }; |
| 239 | |
| 240 | /* EXT_CMD1 - Understood by DFP, G25, G27 and DFGT */ |
| 241 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext01_dfp = { |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 242 | 1, |
| 243 | {0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 244 | }; |
| 245 | |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 246 | /* EXT_CMD16 - Understood by G25 and G27 */ |
| 247 | static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext16_g25 = { |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 248 | 1, |
| 249 | {0xf8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 250 | }; |
| 251 | |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 252 | /* Recalculates X axis value accordingly to currently selected range */ |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 253 | static s32 lg4ff_adjust_dfp_x_axis(s32 value, u16 range) |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 254 | { |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 255 | u16 max_range; |
| 256 | s32 new_value; |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 257 | |
| 258 | if (range == 900) |
| 259 | return value; |
| 260 | else if (range == 200) |
| 261 | return value; |
| 262 | else if (range < 200) |
| 263 | max_range = 200; |
| 264 | else |
| 265 | max_range = 900; |
| 266 | |
| 267 | new_value = 8192 + mult_frac(value - 8192, max_range, range); |
| 268 | if (new_value < 0) |
| 269 | return 0; |
| 270 | else if (new_value > 16383) |
| 271 | return 16383; |
| 272 | else |
| 273 | return new_value; |
| 274 | } |
| 275 | |
| 276 | int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field, |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 277 | struct hid_usage *usage, s32 value, struct lg_drv_data *drv_data) |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 278 | { |
| 279 | struct lg4ff_device_entry *entry = drv_data->device_props; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 280 | s32 new_value = 0; |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 281 | |
| 282 | if (!entry) { |
| 283 | hid_err(hid, "Device properties not found"); |
| 284 | return 0; |
| 285 | } |
| 286 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 287 | switch (entry->wdata.product_id) { |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 288 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 289 | switch (usage->code) { |
| 290 | case ABS_X: |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 291 | new_value = lg4ff_adjust_dfp_x_axis(value, entry->wdata.range); |
Michal Malý | 2b24a96 | 2012-09-23 22:41:08 +0200 | [diff] [blame] | 292 | input_event(field->hidinput->input, usage->type, usage->code, new_value); |
| 293 | return 1; |
| 294 | default: |
| 295 | return 0; |
| 296 | } |
| 297 | default: |
| 298 | return 0; |
| 299 | } |
| 300 | } |
| 301 | |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 302 | static int lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *effect) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 303 | { |
| 304 | struct hid_device *hid = input_get_drvdata(dev); |
| 305 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 306 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 307 | struct lg4ff_device_entry *entry; |
| 308 | struct lg_drv_data *drv_data; |
| 309 | unsigned long flags; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 310 | s32 *value = report->field[0]->value; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 311 | int x; |
| 312 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 313 | drv_data = hid_get_drvdata(hid); |
| 314 | if (!drv_data) { |
| 315 | hid_err(hid, "Private driver data not found!\n"); |
| 316 | return -EINVAL; |
| 317 | } |
| 318 | |
| 319 | entry = drv_data->device_props; |
| 320 | if (!entry) { |
| 321 | hid_err(hid, "Device properties not found!\n"); |
| 322 | return -EINVAL; |
| 323 | } |
| 324 | |
Michal Malý | a80fe5d | 2012-09-24 01:13:17 +0200 | [diff] [blame] | 325 | #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] | 326 | |
| 327 | switch (effect->type) { |
| 328 | case FF_CONSTANT: |
| 329 | x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ |
| 330 | CLAMP(x); |
Simon Wood | 56930e7 | 2013-11-06 12:30:42 -0700 | [diff] [blame] | 331 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 332 | spin_lock_irqsave(&entry->report_lock, flags); |
Simon Wood | 56930e7 | 2013-11-06 12:30:42 -0700 | [diff] [blame] | 333 | if (x == 0x80) { |
| 334 | /* De-activate force in slot-1*/ |
| 335 | value[0] = 0x13; |
| 336 | value[1] = 0x00; |
| 337 | value[2] = 0x00; |
| 338 | value[3] = 0x00; |
| 339 | value[4] = 0x00; |
| 340 | value[5] = 0x00; |
| 341 | value[6] = 0x00; |
| 342 | |
| 343 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 344 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Simon Wood | 56930e7 | 2013-11-06 12:30:42 -0700 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 348 | value[0] = 0x11; /* Slot 1 */ |
| 349 | value[1] = 0x08; |
| 350 | value[2] = x; |
| 351 | value[3] = 0x80; |
| 352 | value[4] = 0x00; |
| 353 | value[5] = 0x00; |
| 354 | value[6] = 0x00; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 355 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 356 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 357 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | return 0; |
| 361 | } |
| 362 | |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 363 | /* Sends default autocentering command compatible with |
| 364 | * all wheels except Formula Force EX */ |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 365 | static void lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitude) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 366 | { |
| 367 | struct hid_device *hid = input_get_drvdata(dev); |
| 368 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 369 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 370 | s32 *value = report->field[0]->value; |
| 371 | u32 expand_a, expand_b; |
Simon Wood | 1859762 | 2013-11-06 12:30:44 -0700 | [diff] [blame] | 372 | struct lg4ff_device_entry *entry; |
| 373 | struct lg_drv_data *drv_data; |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 374 | unsigned long flags; |
Simon Wood | 1859762 | 2013-11-06 12:30:44 -0700 | [diff] [blame] | 375 | |
| 376 | drv_data = hid_get_drvdata(hid); |
| 377 | if (!drv_data) { |
| 378 | hid_err(hid, "Private driver data not found!\n"); |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | entry = drv_data->device_props; |
| 383 | if (!entry) { |
| 384 | hid_err(hid, "Device properties not found!\n"); |
| 385 | return; |
| 386 | } |
Simon Wood | f8c2315 | 2013-11-06 12:30:40 -0700 | [diff] [blame] | 387 | |
Simon Wood | d2c02da | 2013-11-06 12:30:41 -0700 | [diff] [blame] | 388 | /* De-activate Auto-Center */ |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 389 | spin_lock_irqsave(&entry->report_lock, flags); |
Simon Wood | d2c02da | 2013-11-06 12:30:41 -0700 | [diff] [blame] | 390 | if (magnitude == 0) { |
| 391 | value[0] = 0xf5; |
| 392 | value[1] = 0x00; |
| 393 | value[2] = 0x00; |
| 394 | value[3] = 0x00; |
| 395 | value[4] = 0x00; |
| 396 | value[5] = 0x00; |
| 397 | value[6] = 0x00; |
| 398 | |
| 399 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 400 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Simon Wood | d2c02da | 2013-11-06 12:30:41 -0700 | [diff] [blame] | 401 | return; |
| 402 | } |
| 403 | |
Simon Wood | f8c2315 | 2013-11-06 12:30:40 -0700 | [diff] [blame] | 404 | if (magnitude <= 0xaaaa) { |
| 405 | expand_a = 0x0c * magnitude; |
| 406 | expand_b = 0x80 * magnitude; |
| 407 | } else { |
| 408 | expand_a = (0x0c * 0xaaaa) + 0x06 * (magnitude - 0xaaaa); |
| 409 | expand_b = (0x80 * 0xaaaa) + 0xff * (magnitude - 0xaaaa); |
| 410 | } |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 411 | |
Simon Wood | 1859762 | 2013-11-06 12:30:44 -0700 | [diff] [blame] | 412 | /* Adjust for non-MOMO wheels */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 413 | switch (entry->wdata.product_id) { |
Simon Wood | 1859762 | 2013-11-06 12:30:44 -0700 | [diff] [blame] | 414 | case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL: |
| 415 | case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2: |
| 416 | break; |
| 417 | default: |
| 418 | expand_a = expand_a >> 1; |
| 419 | break; |
| 420 | } |
| 421 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 422 | value[0] = 0xfe; |
| 423 | value[1] = 0x0d; |
Simon Wood | f8c2315 | 2013-11-06 12:30:40 -0700 | [diff] [blame] | 424 | value[2] = expand_a / 0xaaaa; |
| 425 | value[3] = expand_a / 0xaaaa; |
| 426 | value[4] = expand_b / 0xaaaa; |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 427 | value[5] = 0x00; |
| 428 | value[6] = 0x00; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 429 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 430 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Simon Wood | d2c02da | 2013-11-06 12:30:41 -0700 | [diff] [blame] | 431 | |
| 432 | /* Activate Auto-Center */ |
| 433 | value[0] = 0x14; |
| 434 | value[1] = 0x00; |
| 435 | value[2] = 0x00; |
| 436 | value[3] = 0x00; |
| 437 | value[4] = 0x00; |
| 438 | value[5] = 0x00; |
| 439 | value[6] = 0x00; |
| 440 | |
| 441 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 442 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 445 | /* Sends autocentering command compatible with Formula Force EX */ |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 446 | static void lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude) |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 447 | { |
| 448 | struct hid_device *hid = input_get_drvdata(dev); |
| 449 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 450 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 451 | struct lg4ff_device_entry *entry; |
| 452 | struct lg_drv_data *drv_data; |
| 453 | unsigned long flags; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 454 | s32 *value = report->field[0]->value; |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 455 | magnitude = magnitude * 90 / 65535; |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 456 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 457 | drv_data = hid_get_drvdata(hid); |
| 458 | if (!drv_data) { |
| 459 | hid_err(hid, "Private driver data not found!\n"); |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | entry = drv_data->device_props; |
| 464 | if (!entry) { |
| 465 | hid_err(hid, "Device properties not found!\n"); |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | spin_lock_irqsave(&entry->report_lock, flags); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 470 | value[0] = 0xfe; |
| 471 | value[1] = 0x03; |
| 472 | value[2] = magnitude >> 14; |
| 473 | value[3] = magnitude >> 14; |
| 474 | value[4] = magnitude; |
| 475 | value[5] = 0x00; |
| 476 | value[6] = 0x00; |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 477 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 478 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 479 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Michal Malý | 6e2de8e | 2011-08-04 16:22:07 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 482 | /* Sends command to set range compatible with G25/G27/Driving Force GT */ |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 483 | static void lg4ff_set_range_g25(struct hid_device *hid, u16 range) |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 484 | { |
| 485 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 486 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 487 | struct lg4ff_device_entry *entry; |
| 488 | struct lg_drv_data *drv_data; |
| 489 | unsigned long flags; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 490 | s32 *value = report->field[0]->value; |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 491 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 492 | drv_data = hid_get_drvdata(hid); |
| 493 | if (!drv_data) { |
| 494 | hid_err(hid, "Private driver data not found!\n"); |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | entry = drv_data->device_props; |
| 499 | if (!entry) { |
| 500 | hid_err(hid, "Device properties not found!\n"); |
| 501 | return; |
| 502 | } |
| 503 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 504 | dbg_hid("G25/G27/DFGT: setting range to %u\n", range); |
| 505 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 506 | spin_lock_irqsave(&entry->report_lock, flags); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 507 | value[0] = 0xf8; |
| 508 | value[1] = 0x81; |
| 509 | value[2] = range & 0x00ff; |
| 510 | value[3] = (range & 0xff00) >> 8; |
| 511 | value[4] = 0x00; |
| 512 | value[5] = 0x00; |
| 513 | value[6] = 0x00; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 514 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 515 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 516 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | /* Sends commands to set range compatible with Driving Force Pro wheel */ |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 520 | static void lg4ff_set_range_dfp(struct hid_device *hid, u16 range) |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 521 | { |
| 522 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 523 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
| 524 | int start_left, start_right, full_range; |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 525 | struct lg4ff_device_entry *entry; |
| 526 | struct lg_drv_data *drv_data; |
| 527 | unsigned long flags; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 528 | s32 *value = report->field[0]->value; |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 529 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 530 | drv_data = hid_get_drvdata(hid); |
| 531 | if (!drv_data) { |
| 532 | hid_err(hid, "Private driver data not found!\n"); |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | entry = drv_data->device_props; |
| 537 | if (!entry) { |
| 538 | hid_err(hid, "Device properties not found!\n"); |
| 539 | return; |
| 540 | } |
| 541 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 542 | dbg_hid("Driving Force Pro: setting range to %u\n", range); |
| 543 | |
| 544 | /* Prepare "coarse" limit command */ |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 545 | spin_lock_irqsave(&entry->report_lock, flags); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 546 | value[0] = 0xf8; |
Michal Malý | a80fe5d | 2012-09-24 01:13:17 +0200 | [diff] [blame] | 547 | value[1] = 0x00; /* Set later */ |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 548 | value[2] = 0x00; |
| 549 | value[3] = 0x00; |
| 550 | value[4] = 0x00; |
| 551 | value[5] = 0x00; |
| 552 | value[6] = 0x00; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 553 | |
| 554 | if (range > 200) { |
| 555 | report->field[0]->value[1] = 0x03; |
| 556 | full_range = 900; |
| 557 | } else { |
| 558 | report->field[0]->value[1] = 0x02; |
| 559 | full_range = 200; |
| 560 | } |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 561 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 562 | |
| 563 | /* Prepare "fine" limit command */ |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 564 | value[0] = 0x81; |
| 565 | value[1] = 0x0b; |
| 566 | value[2] = 0x00; |
| 567 | value[3] = 0x00; |
| 568 | value[4] = 0x00; |
| 569 | value[5] = 0x00; |
| 570 | value[6] = 0x00; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 571 | |
| 572 | if (range == 200 || range == 900) { /* Do not apply any fine limit */ |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 573 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 574 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 575 | return; |
| 576 | } |
| 577 | |
| 578 | /* Construct fine limit command */ |
| 579 | start_left = (((full_range - range + 1) * 2047) / full_range); |
| 580 | start_right = 0xfff - start_left; |
| 581 | |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 582 | value[2] = start_left >> 4; |
| 583 | value[3] = start_right >> 4; |
| 584 | value[4] = 0xff; |
| 585 | value[5] = (start_right & 0xe) << 4 | (start_left & 0xe); |
| 586 | value[6] = 0xff; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 587 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 588 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 589 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 590 | } |
| 591 | |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 592 | static const struct lg4ff_compat_mode_switch *lg4ff_get_mode_switch_command(const u16 real_product_id, const u16 target_product_id) |
| 593 | { |
| 594 | switch (real_product_id) { |
| 595 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 596 | switch (target_product_id) { |
| 597 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 598 | return &lg4ff_mode_switch_ext01_dfp; |
| 599 | /* DFP can only be switched to its native mode */ |
| 600 | default: |
| 601 | return NULL; |
| 602 | } |
| 603 | break; |
| 604 | case USB_DEVICE_ID_LOGITECH_G25_WHEEL: |
| 605 | switch (target_product_id) { |
| 606 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 607 | return &lg4ff_mode_switch_ext01_dfp; |
| 608 | case USB_DEVICE_ID_LOGITECH_G25_WHEEL: |
| 609 | return &lg4ff_mode_switch_ext16_g25; |
| 610 | /* G25 can only be switched to DFP mode or its native mode */ |
| 611 | default: |
| 612 | return NULL; |
| 613 | } |
| 614 | break; |
| 615 | case USB_DEVICE_ID_LOGITECH_G27_WHEEL: |
| 616 | switch (target_product_id) { |
| 617 | case USB_DEVICE_ID_LOGITECH_WHEEL: |
| 618 | return &lg4ff_mode_switch_ext09_dfex; |
| 619 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 620 | return &lg4ff_mode_switch_ext09_dfp; |
| 621 | case USB_DEVICE_ID_LOGITECH_G25_WHEEL: |
| 622 | return &lg4ff_mode_switch_ext09_g25; |
| 623 | case USB_DEVICE_ID_LOGITECH_G27_WHEEL: |
| 624 | return &lg4ff_mode_switch_ext09_g27; |
| 625 | /* G27 can only be switched to DF-EX, DFP, G25 or its native mode */ |
| 626 | default: |
| 627 | return NULL; |
| 628 | } |
| 629 | break; |
| 630 | case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL: |
| 631 | switch (target_product_id) { |
| 632 | case USB_DEVICE_ID_LOGITECH_WHEEL: |
| 633 | return &lg4ff_mode_switch_ext09_dfex; |
| 634 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 635 | return &lg4ff_mode_switch_ext09_dfp; |
| 636 | case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL: |
| 637 | return &lg4ff_mode_switch_ext09_dfgt; |
| 638 | /* DFGT can only be switched to DF-EX, DFP or its native mode */ |
| 639 | default: |
| 640 | return NULL; |
| 641 | } |
| 642 | break; |
| 643 | /* No other wheels have multiple modes */ |
| 644 | default: |
| 645 | return NULL; |
| 646 | } |
| 647 | } |
| 648 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 649 | 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] | 650 | { |
Michal Malý | c1740d1 | 2015-02-18 22:49:33 +0100 | [diff] [blame] | 651 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 652 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 653 | struct lg4ff_device_entry *entry; |
| 654 | struct lg_drv_data *drv_data; |
| 655 | unsigned long flags; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 656 | s32 *value = report->field[0]->value; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 657 | u8 i; |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 658 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 659 | drv_data = hid_get_drvdata(hid); |
| 660 | if (!drv_data) { |
| 661 | hid_err(hid, "Private driver data not found!\n"); |
| 662 | return -EINVAL; |
| 663 | } |
| 664 | |
| 665 | entry = drv_data->device_props; |
| 666 | if (!entry) { |
| 667 | hid_err(hid, "Device properties not found!\n"); |
| 668 | return -EINVAL; |
| 669 | } |
| 670 | |
| 671 | spin_lock_irqsave(&entry->report_lock, flags); |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 672 | for (i = 0; i < s->cmd_count; i++) { |
Michal Malý | c1740d1 | 2015-02-18 22:49:33 +0100 | [diff] [blame] | 673 | u8 j; |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 674 | |
Michal Malý | c1740d1 | 2015-02-18 22:49:33 +0100 | [diff] [blame] | 675 | for (j = 0; j < 7; j++) |
| 676 | value[j] = s->cmd[j + (7*i)]; |
| 677 | |
| 678 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 679 | } |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 680 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Michal Malý | c1740d1 | 2015-02-18 22:49:33 +0100 | [diff] [blame] | 681 | hid_hw_wait(hid); |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 682 | return 0; |
Michal Malý | 96440c8 | 2011-08-04 16:18:11 +0200 | [diff] [blame] | 683 | } |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 684 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 685 | static ssize_t lg4ff_alternate_modes_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 686 | { |
| 687 | struct hid_device *hid = to_hid_device(dev); |
| 688 | struct lg4ff_device_entry *entry; |
| 689 | struct lg_drv_data *drv_data; |
| 690 | ssize_t count = 0; |
| 691 | int i; |
| 692 | |
| 693 | drv_data = hid_get_drvdata(hid); |
| 694 | if (!drv_data) { |
| 695 | hid_err(hid, "Private driver data not found!\n"); |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | entry = drv_data->device_props; |
| 700 | if (!entry) { |
| 701 | hid_err(hid, "Device properties not found!\n"); |
| 702 | return 0; |
| 703 | } |
| 704 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 705 | if (!entry->wdata.real_name) { |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 706 | hid_err(hid, "NULL pointer to string\n"); |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | for (i = 0; i < LG4FF_MODE_MAX_IDX; i++) { |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 711 | if (entry->wdata.alternate_modes & BIT(i)) { |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 712 | /* Print tag and full name */ |
| 713 | count += scnprintf(buf + count, PAGE_SIZE - count, "%s: %s", |
| 714 | lg4ff_alternate_modes[i].tag, |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 715 | !lg4ff_alternate_modes[i].product_id ? entry->wdata.real_name : lg4ff_alternate_modes[i].name); |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 716 | if (count >= PAGE_SIZE - 1) |
| 717 | return count; |
| 718 | |
| 719 | /* Mark the currently active mode with an asterisk */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 720 | if (lg4ff_alternate_modes[i].product_id == entry->wdata.product_id || |
| 721 | (lg4ff_alternate_modes[i].product_id == 0 && entry->wdata.product_id == entry->wdata.real_product_id)) |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 722 | count += scnprintf(buf + count, PAGE_SIZE - count, " *\n"); |
| 723 | else |
| 724 | count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 725 | |
| 726 | if (count >= PAGE_SIZE - 1) |
| 727 | return count; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | return count; |
| 732 | } |
| 733 | |
| 734 | static ssize_t lg4ff_alternate_modes_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 735 | { |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 736 | struct hid_device *hid = to_hid_device(dev); |
| 737 | struct lg4ff_device_entry *entry; |
| 738 | struct lg_drv_data *drv_data; |
| 739 | const struct lg4ff_compat_mode_switch *s; |
| 740 | u16 target_product_id = 0; |
| 741 | int i, ret; |
| 742 | char *lbuf; |
| 743 | |
| 744 | drv_data = hid_get_drvdata(hid); |
| 745 | if (!drv_data) { |
| 746 | hid_err(hid, "Private driver data not found!\n"); |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
| 750 | entry = drv_data->device_props; |
| 751 | if (!entry) { |
| 752 | hid_err(hid, "Device properties not found!\n"); |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | |
| 756 | /* Allow \n at the end of the input parameter */ |
| 757 | lbuf = kasprintf(GFP_KERNEL, "%s", buf); |
| 758 | if (!lbuf) |
| 759 | return -ENOMEM; |
| 760 | |
| 761 | i = strlen(lbuf); |
| 762 | if (lbuf[i-1] == '\n') { |
| 763 | if (i == 1) { |
| 764 | kfree(lbuf); |
| 765 | return -EINVAL; |
| 766 | } |
| 767 | lbuf[i-1] = '\0'; |
| 768 | } |
| 769 | |
| 770 | for (i = 0; i < LG4FF_MODE_MAX_IDX; i++) { |
| 771 | const u16 mode_product_id = lg4ff_alternate_modes[i].product_id; |
| 772 | const char *tag = lg4ff_alternate_modes[i].tag; |
| 773 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 774 | if (entry->wdata.alternate_modes & BIT(i)) { |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 775 | if (!strcmp(tag, lbuf)) { |
| 776 | if (!mode_product_id) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 777 | target_product_id = entry->wdata.real_product_id; |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 778 | else |
| 779 | target_product_id = mode_product_id; |
| 780 | break; |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | if (i == LG4FF_MODE_MAX_IDX) { |
| 786 | hid_info(hid, "Requested mode \"%s\" is not supported by the device\n", lbuf); |
| 787 | kfree(lbuf); |
| 788 | return -EINVAL; |
| 789 | } |
| 790 | kfree(lbuf); /* Not needed anymore */ |
| 791 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 792 | if (target_product_id == entry->wdata.product_id) /* Nothing to do */ |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 793 | return count; |
| 794 | |
| 795 | /* Automatic switching has to be disabled for the switch to DF-EX mode to work correctly */ |
| 796 | if (target_product_id == USB_DEVICE_ID_LOGITECH_WHEEL && !lg4ff_no_autoswitch) { |
| 797 | hid_info(hid, "\"%s\" cannot be switched to \"DF-EX\" mode. Load the \"hid_logitech\" module with \"lg4ff_no_autoswitch=1\" parameter set and try again\n", |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 798 | entry->wdata.real_name); |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 799 | return -EINVAL; |
| 800 | } |
| 801 | |
| 802 | /* Take care of hardware limitations */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 803 | if ((entry->wdata.real_product_id == USB_DEVICE_ID_LOGITECH_DFP_WHEEL || entry->wdata.real_product_id == USB_DEVICE_ID_LOGITECH_G25_WHEEL) && |
| 804 | entry->wdata.product_id > target_product_id) { |
| 805 | hid_info(hid, "\"%s\" cannot be switched back into \"%s\" mode\n", entry->wdata.real_name, lg4ff_alternate_modes[i].name); |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 806 | return -EINVAL; |
| 807 | } |
| 808 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 809 | s = lg4ff_get_mode_switch_command(entry->wdata.real_product_id, target_product_id); |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 810 | if (!s) { |
| 811 | hid_err(hid, "Invalid target product ID %X\n", target_product_id); |
| 812 | return -EINVAL; |
| 813 | } |
| 814 | |
| 815 | ret = lg4ff_switch_compatibility_mode(hid, s); |
| 816 | return (ret == 0 ? count : ret); |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 817 | } |
| 818 | static DEVICE_ATTR(alternate_modes, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, lg4ff_alternate_modes_show, lg4ff_alternate_modes_store); |
| 819 | |
Michal Malý | fbf85e2 | 2015-04-08 22:56:41 +0200 | [diff] [blame] | 820 | /* Export the currently set range of the wheel */ |
| 821 | static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *attr, |
| 822 | char *buf) |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 823 | { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 824 | struct hid_device *hid = to_hid_device(dev); |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 825 | struct lg4ff_device_entry *entry; |
| 826 | struct lg_drv_data *drv_data; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 827 | size_t count; |
| 828 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 829 | drv_data = hid_get_drvdata(hid); |
| 830 | if (!drv_data) { |
| 831 | hid_err(hid, "Private driver data not found!\n"); |
| 832 | return 0; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 833 | } |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 834 | |
| 835 | entry = drv_data->device_props; |
| 836 | if (!entry) { |
| 837 | hid_err(hid, "Device properties not found!\n"); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 838 | return 0; |
| 839 | } |
| 840 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 841 | count = scnprintf(buf, PAGE_SIZE, "%u\n", entry->wdata.range); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 842 | return count; |
| 843 | } |
| 844 | |
| 845 | /* Set range to user specified value, call appropriate function |
| 846 | * according to the type of the wheel */ |
Michal Malý | fbf85e2 | 2015-04-08 22:56:41 +0200 | [diff] [blame] | 847 | static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *attr, |
| 848 | const char *buf, size_t count) |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 849 | { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 850 | struct hid_device *hid = to_hid_device(dev); |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 851 | struct lg4ff_device_entry *entry; |
| 852 | struct lg_drv_data *drv_data; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 853 | u16 range = simple_strtoul(buf, NULL, 10); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 854 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 855 | drv_data = hid_get_drvdata(hid); |
| 856 | if (!drv_data) { |
| 857 | hid_err(hid, "Private driver data not found!\n"); |
Simon Wood | 29ff665 | 2014-08-14 20:43:01 -0600 | [diff] [blame] | 858 | return -EINVAL; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 859 | } |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 860 | |
| 861 | entry = drv_data->device_props; |
| 862 | if (!entry) { |
| 863 | hid_err(hid, "Device properties not found!\n"); |
Simon Wood | 29ff665 | 2014-08-14 20:43:01 -0600 | [diff] [blame] | 864 | return -EINVAL; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | if (range == 0) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 868 | range = entry->wdata.max_range; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 869 | |
| 870 | /* Check if the wheel supports range setting |
| 871 | * and that the range is within limits for the wheel */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 872 | if (entry->wdata.set_range && range >= entry->wdata.min_range && range <= entry->wdata.max_range) { |
| 873 | entry->wdata.set_range(hid, range); |
| 874 | entry->wdata.range = range; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | return count; |
| 878 | } |
Michal Malý | fbf85e2 | 2015-04-08 22:56:41 +0200 | [diff] [blame] | 879 | static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, lg4ff_range_show, lg4ff_range_store); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 880 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 881 | static ssize_t lg4ff_real_id_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 882 | { |
| 883 | struct hid_device *hid = to_hid_device(dev); |
| 884 | struct lg4ff_device_entry *entry; |
| 885 | struct lg_drv_data *drv_data; |
| 886 | size_t count; |
| 887 | |
| 888 | drv_data = hid_get_drvdata(hid); |
| 889 | if (!drv_data) { |
| 890 | hid_err(hid, "Private driver data not found!\n"); |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | entry = drv_data->device_props; |
| 895 | if (!entry) { |
| 896 | hid_err(hid, "Device properties not found!\n"); |
| 897 | return 0; |
| 898 | } |
| 899 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 900 | if (!entry->wdata.real_tag || !entry->wdata.real_name) { |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 901 | hid_err(hid, "NULL pointer to string\n"); |
| 902 | return 0; |
| 903 | } |
| 904 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 905 | count = scnprintf(buf, PAGE_SIZE, "%s: %s\n", entry->wdata.real_tag, entry->wdata.real_name); |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 906 | return count; |
| 907 | } |
| 908 | |
| 909 | static ssize_t lg4ff_real_id_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 910 | { |
| 911 | /* Real ID is a read-only value */ |
| 912 | return -EPERM; |
| 913 | } |
| 914 | static DEVICE_ATTR(real_id, S_IRUGO, lg4ff_real_id_show, lg4ff_real_id_store); |
| 915 | |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 916 | #ifdef CONFIG_LEDS_CLASS |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 917 | static void lg4ff_set_leds(struct hid_device *hid, u8 leds) |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 918 | { |
| 919 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 920 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 921 | struct lg_drv_data *drv_data; |
| 922 | struct lg4ff_device_entry *entry; |
| 923 | unsigned long flags; |
Michal Malý | 2a552c3 | 2015-04-08 22:56:39 +0200 | [diff] [blame] | 924 | s32 *value = report->field[0]->value; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 925 | |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 926 | drv_data = hid_get_drvdata(hid); |
| 927 | if (!drv_data) { |
| 928 | hid_err(hid, "Private driver data not found!\n"); |
| 929 | return; |
| 930 | } |
| 931 | |
| 932 | entry = drv_data->device_props; |
| 933 | if (!entry) { |
| 934 | hid_err(hid, "Device properties not found!\n"); |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | spin_lock_irqsave(&entry->report_lock, flags); |
Michal Malý | 74479ba | 2012-09-24 01:09:30 +0200 | [diff] [blame] | 939 | value[0] = 0xf8; |
| 940 | value[1] = 0x12; |
| 941 | value[2] = leds; |
| 942 | value[3] = 0x00; |
| 943 | value[4] = 0x00; |
| 944 | value[5] = 0x00; |
| 945 | value[6] = 0x00; |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 946 | hid_hw_request(hid, report, HID_REQ_SET_REPORT); |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 947 | spin_unlock_irqrestore(&entry->report_lock, flags); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | static void lg4ff_led_set_brightness(struct led_classdev *led_cdev, |
| 951 | enum led_brightness value) |
| 952 | { |
| 953 | struct device *dev = led_cdev->dev->parent; |
| 954 | struct hid_device *hid = container_of(dev, struct hid_device, dev); |
Axel Lin | 4629fd1 | 2012-09-13 14:09:33 +0800 | [diff] [blame] | 955 | struct lg_drv_data *drv_data = hid_get_drvdata(hid); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 956 | struct lg4ff_device_entry *entry; |
| 957 | int i, state = 0; |
| 958 | |
| 959 | if (!drv_data) { |
| 960 | hid_err(hid, "Device data not found."); |
| 961 | return; |
| 962 | } |
| 963 | |
Michal Malý | 371a1d9 | 2015-04-08 22:56:43 +0200 | [diff] [blame] | 964 | entry = drv_data->device_props; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 965 | |
| 966 | if (!entry) { |
| 967 | hid_err(hid, "Device properties not found."); |
| 968 | return; |
| 969 | } |
| 970 | |
| 971 | for (i = 0; i < 5; i++) { |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 972 | if (led_cdev != entry->wdata.led[i]) |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 973 | continue; |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 974 | state = (entry->wdata.led_state >> i) & 1; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 975 | if (value == LED_OFF && state) { |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 976 | entry->wdata.led_state &= ~(1 << i); |
| 977 | lg4ff_set_leds(hid, entry->wdata.led_state); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 978 | } else if (value != LED_OFF && !state) { |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 979 | entry->wdata.led_state |= 1 << i; |
| 980 | lg4ff_set_leds(hid, entry->wdata.led_state); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 981 | } |
| 982 | break; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cdev) |
| 987 | { |
| 988 | struct device *dev = led_cdev->dev->parent; |
| 989 | struct hid_device *hid = container_of(dev, struct hid_device, dev); |
Axel Lin | 4629fd1 | 2012-09-13 14:09:33 +0800 | [diff] [blame] | 990 | struct lg_drv_data *drv_data = hid_get_drvdata(hid); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 991 | struct lg4ff_device_entry *entry; |
| 992 | int i, value = 0; |
| 993 | |
| 994 | if (!drv_data) { |
| 995 | hid_err(hid, "Device data not found."); |
| 996 | return LED_OFF; |
| 997 | } |
| 998 | |
Michal Malý | 371a1d9 | 2015-04-08 22:56:43 +0200 | [diff] [blame] | 999 | entry = drv_data->device_props; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1000 | |
| 1001 | if (!entry) { |
| 1002 | hid_err(hid, "Device properties not found."); |
| 1003 | return LED_OFF; |
| 1004 | } |
| 1005 | |
| 1006 | for (i = 0; i < 5; i++) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1007 | if (led_cdev == entry->wdata.led[i]) { |
| 1008 | value = (entry->wdata.led_state >> i) & 1; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1009 | break; |
| 1010 | } |
| 1011 | |
| 1012 | return value ? LED_FULL : LED_OFF; |
| 1013 | } |
| 1014 | #endif |
| 1015 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1016 | static u16 lg4ff_identify_multimode_wheel(struct hid_device *hid, const u16 reported_product_id, const u16 bcdDevice) |
| 1017 | { |
| 1018 | const struct lg4ff_wheel_ident_checklist *checklist; |
| 1019 | int i, from_idx, to_idx; |
| 1020 | |
| 1021 | switch (reported_product_id) { |
| 1022 | case USB_DEVICE_ID_LOGITECH_WHEEL: |
| 1023 | case USB_DEVICE_ID_LOGITECH_DFP_WHEEL: |
| 1024 | checklist = &lg4ff_main_checklist; |
| 1025 | from_idx = 0; |
| 1026 | to_idx = checklist->count - 1; |
| 1027 | break; |
| 1028 | case USB_DEVICE_ID_LOGITECH_G25_WHEEL: |
| 1029 | checklist = &lg4ff_main_checklist; |
| 1030 | from_idx = 0; |
| 1031 | to_idx = checklist->count - 2; /* End identity check at G25 */ |
| 1032 | break; |
| 1033 | case USB_DEVICE_ID_LOGITECH_G27_WHEEL: |
| 1034 | checklist = &lg4ff_main_checklist; |
| 1035 | from_idx = 1; /* Start identity check at G27 */ |
| 1036 | to_idx = checklist->count - 3; /* End identity check at G27 */ |
| 1037 | break; |
| 1038 | case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL: |
| 1039 | checklist = &lg4ff_main_checklist; |
| 1040 | from_idx = 0; |
| 1041 | to_idx = checklist->count - 4; /* End identity check at DFGT */ |
| 1042 | break; |
| 1043 | default: |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
| 1047 | for (i = from_idx; i <= to_idx; i++) { |
| 1048 | const u16 mask = checklist->models[i]->mask; |
| 1049 | const u16 result = checklist->models[i]->result; |
| 1050 | const u16 real_product_id = checklist->models[i]->real_product_id; |
| 1051 | |
| 1052 | if ((bcdDevice & mask) == result) { |
| 1053 | dbg_hid("Found wheel with real PID %X whose reported PID is %X\n", real_product_id, reported_product_id); |
| 1054 | return real_product_id; |
| 1055 | } |
| 1056 | } |
| 1057 | |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 1058 | /* No match found. This is either Driving Force or an unknown |
| 1059 | * wheel model, do not touch it */ |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1060 | dbg_hid("Wheel with bcdDevice %X was not recognized as multimode wheel, leaving in its current mode\n", bcdDevice); |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| 1064 | static int lg4ff_handle_multimode_wheel(struct hid_device *hid, u16 *real_product_id, const u16 bcdDevice) |
| 1065 | { |
| 1066 | const u16 reported_product_id = hid->product; |
| 1067 | int ret; |
| 1068 | |
| 1069 | *real_product_id = lg4ff_identify_multimode_wheel(hid, reported_product_id, bcdDevice); |
| 1070 | /* Probed wheel is not a multimode wheel */ |
| 1071 | if (!*real_product_id) { |
| 1072 | *real_product_id = reported_product_id; |
| 1073 | dbg_hid("Wheel is not a multimode wheel\n"); |
| 1074 | return LG4FF_MMODE_NOT_MULTIMODE; |
| 1075 | } |
| 1076 | |
| 1077 | /* Switch from "Driving Force" mode to native mode automatically. |
| 1078 | * Otherwise keep the wheel in its current mode */ |
| 1079 | if (reported_product_id == USB_DEVICE_ID_LOGITECH_WHEEL && |
Michal Malý | a54dc779 | 2015-02-18 17:59:22 +0100 | [diff] [blame] | 1080 | reported_product_id != *real_product_id && |
| 1081 | !lg4ff_no_autoswitch) { |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 1082 | const struct lg4ff_compat_mode_switch *s = lg4ff_get_mode_switch_command(*real_product_id, *real_product_id); |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1083 | |
Michal Malý | f31a2de | 2015-02-18 17:59:23 +0100 | [diff] [blame] | 1084 | if (!s) { |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1085 | hid_err(hid, "Invalid product id %X\n", *real_product_id); |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1086 | return LG4FF_MMODE_NOT_MULTIMODE; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | ret = lg4ff_switch_compatibility_mode(hid, s); |
| 1090 | if (ret) { |
| 1091 | /* Wheel could not have been switched to native mode, |
| 1092 | * leave it in "Driving Force" mode and continue */ |
| 1093 | hid_err(hid, "Unable to switch wheel mode, errno %d\n", ret); |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1094 | return LG4FF_MMODE_IS_MULTIMODE; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1095 | } |
| 1096 | return LG4FF_MMODE_SWITCHED; |
| 1097 | } |
| 1098 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1099 | return LG4FF_MMODE_IS_MULTIMODE; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1103 | int lg4ff_init(struct hid_device *hid) |
| 1104 | { |
| 1105 | 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] | 1106 | struct input_dev *dev = hidinput->input; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1107 | const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor); |
| 1108 | const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1109 | struct lg4ff_device_entry *entry; |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1110 | struct lg_drv_data *drv_data; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1111 | int error, i, j; |
| 1112 | int mmode_ret, mmode_idx = -1; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1113 | u16 real_product_id; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1114 | |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1115 | /* Check that the report looks ok */ |
Kees Cook | 0fb6bd0 | 2013-09-11 21:56:54 +0200 | [diff] [blame] | 1116 | if (!hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7)) |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1117 | return -1; |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1118 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1119 | drv_data = hid_get_drvdata(hid); |
| 1120 | if (!drv_data) { |
| 1121 | hid_err(hid, "Cannot add device, private driver data not allocated\n"); |
| 1122 | return -1; |
| 1123 | } |
| 1124 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
| 1125 | if (!entry) |
| 1126 | return -ENOMEM; |
Michal Malý | c918fe7 | 2015-04-08 22:56:48 +0200 | [diff] [blame^] | 1127 | spin_lock_init(&entry->report_lock); |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1128 | drv_data->device_props = entry; |
| 1129 | |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1130 | /* Check if a multimode wheel has been connected and |
| 1131 | * handle it appropriately */ |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1132 | mmode_ret = lg4ff_handle_multimode_wheel(hid, &real_product_id, bcdDevice); |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1133 | |
| 1134 | /* Wheel has been told to switch to native mode. There is no point in going on |
| 1135 | * with the initialization as the wheel will do a USB reset when it switches mode |
| 1136 | */ |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1137 | if (mmode_ret == LG4FF_MMODE_SWITCHED) |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1138 | return 0; |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1139 | else if (mmode_ret < 0) { |
| 1140 | hid_err(hid, "Unable to switch device mode during initialization, errno %d\n", mmode_ret); |
| 1141 | error = mmode_ret; |
| 1142 | goto err_init; |
| 1143 | } |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1144 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 1145 | /* Check what wheel has been connected */ |
| 1146 | for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) { |
| 1147 | if (hid->product == lg4ff_devices[i].product_id) { |
| 1148 | dbg_hid("Found compatible device, product ID %04X\n", lg4ff_devices[i].product_id); |
| 1149 | break; |
| 1150 | } |
| 1151 | } |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1152 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 1153 | if (i == ARRAY_SIZE(lg4ff_devices)) { |
Michal Malý | 9c2a6bd | 2015-04-08 22:56:44 +0200 | [diff] [blame] | 1154 | hid_err(hid, "This device is flagged to be handled by the lg4ff module but this module does not know how to handle it. " |
| 1155 | "Please report this as a bug to LKML, Simon Wood <simon@mungewell.org> or " |
| 1156 | "Michal Maly <madcatxster@devoid-pointer.net>\n"); |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1157 | error = -1; |
| 1158 | goto err_init; |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 1159 | } |
| 1160 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1161 | if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) { |
| 1162 | for (mmode_idx = 0; mmode_idx < ARRAY_SIZE(lg4ff_multimode_wheels); mmode_idx++) { |
| 1163 | if (real_product_id == lg4ff_multimode_wheels[mmode_idx].product_id) |
| 1164 | break; |
| 1165 | } |
| 1166 | |
| 1167 | if (mmode_idx == ARRAY_SIZE(lg4ff_multimode_wheels)) { |
| 1168 | hid_err(hid, "Device product ID %X is not listed as a multimode wheel", real_product_id); |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1169 | error = -1; |
| 1170 | goto err_init; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
Michal Malý | 7362cd2 | 2011-08-04 16:16:09 +0200 | [diff] [blame] | 1174 | /* Set supported force feedback capabilities */ |
| 1175 | for (j = 0; lg4ff_devices[i].ff_effects[j] >= 0; j++) |
| 1176 | set_bit(lg4ff_devices[i].ff_effects[j], dev->ffbit); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1177 | |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 1178 | error = input_ff_create_memless(dev, NULL, lg4ff_play); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1179 | |
| 1180 | if (error) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1181 | goto err_init; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1182 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1183 | entry->wdata.product_id = lg4ff_devices[i].product_id; |
| 1184 | entry->wdata.real_product_id = real_product_id; |
| 1185 | entry->wdata.min_range = lg4ff_devices[i].min_range; |
| 1186 | entry->wdata.max_range = lg4ff_devices[i].max_range; |
| 1187 | entry->wdata.set_range = lg4ff_devices[i].set_range; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1188 | if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) { |
| 1189 | BUG_ON(mmode_idx == -1); |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1190 | entry->wdata.alternate_modes = lg4ff_multimode_wheels[mmode_idx].alternate_modes; |
| 1191 | entry->wdata.real_tag = lg4ff_multimode_wheels[mmode_idx].real_tag; |
| 1192 | entry->wdata.real_name = lg4ff_multimode_wheels[mmode_idx].real_name; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1193 | } |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1194 | |
Simon Wood | 114a55c | 2013-11-06 12:30:43 -0700 | [diff] [blame] | 1195 | /* Check if autocentering is available and |
| 1196 | * set the centering force to zero by default */ |
| 1197 | if (test_bit(FF_AUTOCENTER, dev->ffbit)) { |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1198 | /* Formula Force EX expects different autocentering command */ |
| 1199 | if ((bcdDevice >> 8) == LG4FF_FFEX_REV_MAJ && |
| 1200 | (bcdDevice & 0xff) == LG4FF_FFEX_REV_MIN) |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 1201 | dev->ff->set_autocenter = lg4ff_set_autocenter_ffex; |
Simon Wood | 114a55c | 2013-11-06 12:30:43 -0700 | [diff] [blame] | 1202 | else |
Michal Malý | d0afd84 | 2015-04-08 22:56:40 +0200 | [diff] [blame] | 1203 | dev->ff->set_autocenter = lg4ff_set_autocenter_default; |
Simon Wood | 114a55c | 2013-11-06 12:30:43 -0700 | [diff] [blame] | 1204 | |
| 1205 | dev->ff->set_autocenter(dev, 0); |
| 1206 | } |
| 1207 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1208 | /* Create sysfs interface */ |
| 1209 | error = device_create_file(&hid->dev, &dev_attr_range); |
| 1210 | if (error) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1211 | goto err_init; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1212 | if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) { |
| 1213 | error = device_create_file(&hid->dev, &dev_attr_real_id); |
| 1214 | if (error) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1215 | goto err_init; |
| 1216 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1217 | error = device_create_file(&hid->dev, &dev_attr_alternate_modes); |
| 1218 | if (error) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1219 | goto err_init; |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1220 | } |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1221 | dbg_hid("sysfs interface created\n"); |
| 1222 | |
| 1223 | /* Set the maximum range to start with */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1224 | entry->wdata.range = entry->wdata.max_range; |
| 1225 | if (entry->wdata.set_range) |
| 1226 | entry->wdata.set_range(hid, entry->wdata.range); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1227 | |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1228 | #ifdef CONFIG_LEDS_CLASS |
| 1229 | /* register led subsystem - G27 only */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1230 | entry->wdata.led_state = 0; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1231 | for (j = 0; j < 5; j++) |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1232 | entry->wdata.led[j] = NULL; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1233 | |
| 1234 | if (lg4ff_devices[i].product_id == USB_DEVICE_ID_LOGITECH_G27_WHEEL) { |
| 1235 | struct led_classdev *led; |
| 1236 | size_t name_sz; |
| 1237 | char *name; |
| 1238 | |
| 1239 | lg4ff_set_leds(hid, 0); |
| 1240 | |
| 1241 | name_sz = strlen(dev_name(&hid->dev)) + 8; |
| 1242 | |
| 1243 | for (j = 0; j < 5; j++) { |
| 1244 | led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL); |
| 1245 | if (!led) { |
| 1246 | hid_err(hid, "can't allocate memory for LED %d\n", j); |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1247 | goto err_leds; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | name = (void *)(&led[1]); |
| 1251 | snprintf(name, name_sz, "%s::RPM%d", dev_name(&hid->dev), j+1); |
| 1252 | led->name = name; |
| 1253 | led->brightness = 0; |
| 1254 | led->max_brightness = 1; |
| 1255 | led->brightness_get = lg4ff_led_get_brightness; |
| 1256 | led->brightness_set = lg4ff_led_set_brightness; |
| 1257 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1258 | entry->wdata.led[j] = led; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1259 | error = led_classdev_register(&hid->dev, led); |
| 1260 | |
| 1261 | if (error) { |
| 1262 | hid_err(hid, "failed to register LED %d. Aborting.\n", j); |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1263 | err_leds: |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1264 | /* Deregister LEDs (if any) */ |
| 1265 | for (j = 0; j < 5; j++) { |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1266 | led = entry->wdata.led[j]; |
| 1267 | entry->wdata.led[j] = NULL; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1268 | if (!led) |
| 1269 | continue; |
| 1270 | led_classdev_unregister(led); |
| 1271 | kfree(led); |
| 1272 | } |
| 1273 | goto out; /* Let the driver continue without LEDs */ |
| 1274 | } |
| 1275 | } |
| 1276 | } |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1277 | out: |
Jiri Kosina | c6e6dc8 | 2012-04-23 21:08:15 +0200 | [diff] [blame] | 1278 | #endif |
Simon Wood | 6401380 | 2012-04-21 05:41:16 -0700 | [diff] [blame] | 1279 | hid_info(hid, "Force feedback support for Logitech Gaming Wheels\n"); |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1280 | return 0; |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1281 | |
| 1282 | err_init: |
| 1283 | drv_data->device_props = NULL; |
| 1284 | kfree(entry); |
| 1285 | return error; |
Simon Wood | 32c88cb | 2010-09-22 13:19:42 +0200 | [diff] [blame] | 1286 | } |
| 1287 | |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1288 | int lg4ff_deinit(struct hid_device *hid) |
| 1289 | { |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1290 | struct lg4ff_device_entry *entry; |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1291 | struct lg_drv_data *drv_data; |
| 1292 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1293 | drv_data = hid_get_drvdata(hid); |
| 1294 | if (!drv_data) { |
| 1295 | hid_err(hid, "Error while deinitializing device, no private driver data.\n"); |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1296 | return -1; |
| 1297 | } |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1298 | entry = drv_data->device_props; |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1299 | if (!entry) |
| 1300 | goto out; /* Nothing more to do */ |
| 1301 | |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1302 | /* Multimode devices will have at least the "MODE_NATIVE" bit set */ |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1303 | if (entry->wdata.alternate_modes) { |
Michal Malý | b96d23e | 2015-02-18 17:59:21 +0100 | [diff] [blame] | 1304 | device_remove_file(&hid->dev, &dev_attr_real_id); |
| 1305 | device_remove_file(&hid->dev, &dev_attr_alternate_modes); |
| 1306 | } |
| 1307 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1308 | device_remove_file(&hid->dev, &dev_attr_range); |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1309 | #ifdef CONFIG_LEDS_CLASS |
| 1310 | { |
| 1311 | int j; |
| 1312 | struct led_classdev *led; |
| 1313 | |
| 1314 | /* Deregister LEDs (if any) */ |
| 1315 | for (j = 0; j < 5; j++) { |
| 1316 | |
Michal Malý | 72529c6 | 2015-04-08 22:56:46 +0200 | [diff] [blame] | 1317 | led = entry->wdata.led[j]; |
| 1318 | entry->wdata.led[j] = NULL; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1319 | if (!led) |
| 1320 | continue; |
| 1321 | led_classdev_unregister(led); |
| 1322 | kfree(led); |
| 1323 | } |
| 1324 | } |
| 1325 | #endif |
Michal Malý | b211a63 | 2015-04-08 22:56:47 +0200 | [diff] [blame] | 1326 | hid_hw_stop(hid); |
| 1327 | drv_data->device_props = NULL; |
Simon Wood | 22bcefd | 2012-04-21 05:41:15 -0700 | [diff] [blame] | 1328 | |
Michal Malý | 3b6b17b | 2012-04-09 09:08:49 +0200 | [diff] [blame] | 1329 | kfree(entry); |
Michal Malý | e7c2344 | 2015-02-18 17:59:20 +0100 | [diff] [blame] | 1330 | out: |
Michal Malý | 30bb75d | 2011-08-04 16:20:40 +0200 | [diff] [blame] | 1331 | dbg_hid("Device successfully unregistered\n"); |
| 1332 | return 0; |
| 1333 | } |