@@ -1669,6 +1669,7 @@ static void hidpp_touchpad_raw_xy_event(struct hidpp_device *hidpp_dev,
1669
1669
1670
1670
#define HIDPP_FF_EFFECTID_NONE -1
1671
1671
#define HIDPP_FF_EFFECTID_AUTOCENTER -2
1672
+ #define HIDPP_AUTOCENTER_PARAMS_LENGTH 18
1672
1673
1673
1674
#define HIDPP_FF_MAX_PARAMS 20
1674
1675
#define HIDPP_FF_RESERVED_SLOTS 1
@@ -2009,7 +2010,7 @@ static int hidpp_ff_erase_effect(struct input_dev *dev, int effect_id)
2009
2010
static void hidpp_ff_set_autocenter (struct input_dev * dev , u16 magnitude )
2010
2011
{
2011
2012
struct hidpp_ff_private_data * data = dev -> ff -> private ;
2012
- u8 params [18 ];
2013
+ u8 params [HIDPP_AUTOCENTER_PARAMS_LENGTH ];
2013
2014
2014
2015
dbg_hid ("Setting autocenter to %d.\n" , magnitude );
2015
2016
@@ -2081,17 +2082,16 @@ static void hidpp_ff_destroy(struct ff_device *ff)
2081
2082
kfree (data -> effect_ids );
2082
2083
}
2083
2084
2084
- static int hidpp_ff_init (struct hidpp_device * hidpp , u8 feature_index )
2085
+ static int hidpp_ff_init (struct hidpp_device * hidpp ,
2086
+ struct hidpp_ff_private_data * data )
2085
2087
{
2086
2088
struct hid_device * hid = hidpp -> hid_dev ;
2087
2089
struct hid_input * hidinput ;
2088
2090
struct input_dev * dev ;
2089
2091
const struct usb_device_descriptor * udesc = & (hid_to_usb_dev (hid )-> descriptor );
2090
2092
const u16 bcdDevice = le16_to_cpu (udesc -> bcdDevice );
2091
2093
struct ff_device * ff ;
2092
- struct hidpp_report response ;
2093
- struct hidpp_ff_private_data * data ;
2094
- int error , j , num_slots ;
2094
+ int error , j , num_slots = data -> num_effects ;
2095
2095
u8 version ;
2096
2096
2097
2097
if (list_empty (& hid -> inputs )) {
@@ -2116,27 +2116,17 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
2116
2116
for (j = 0 ; hidpp_ff_effects_v2 [j ] >= 0 ; j ++ )
2117
2117
set_bit (hidpp_ff_effects_v2 [j ], dev -> ffbit );
2118
2118
2119
- /* Read number of slots available in device */
2120
- error = hidpp_send_fap_command_sync (hidpp , feature_index ,
2121
- HIDPP_FF_GET_INFO , NULL , 0 , & response );
2122
- if (error ) {
2123
- if (error < 0 )
2124
- return error ;
2125
- hid_err (hidpp -> hid_dev , "%s: received protocol error 0x%02x\n" ,
2126
- __func__ , error );
2127
- return - EPROTO ;
2128
- }
2129
-
2130
- num_slots = response .fap .params [0 ] - HIDPP_FF_RESERVED_SLOTS ;
2131
-
2132
2119
error = input_ff_create (dev , num_slots );
2133
2120
2134
2121
if (error ) {
2135
2122
hid_err (dev , "Failed to create FF device!\n" );
2136
2123
return error ;
2137
2124
}
2138
-
2139
- data = kzalloc (sizeof (* data ), GFP_KERNEL );
2125
+ /*
2126
+ * Create a copy of passed data, so we can transfer memory
2127
+ * ownership to FF core
2128
+ */
2129
+ data = kmemdup (data , sizeof (* data ), GFP_KERNEL );
2140
2130
if (!data )
2141
2131
return - ENOMEM ;
2142
2132
data -> effect_ids = kcalloc (num_slots , sizeof (int ), GFP_KERNEL );
@@ -2152,10 +2142,7 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
2152
2142
}
2153
2143
2154
2144
data -> hidpp = hidpp ;
2155
- data -> feature_index = feature_index ;
2156
2145
data -> version = version ;
2157
- data -> slot_autocenter = 0 ;
2158
- data -> num_effects = num_slots ;
2159
2146
for (j = 0 ; j < num_slots ; j ++ )
2160
2147
data -> effect_ids [j ] = -1 ;
2161
2148
@@ -2169,37 +2156,14 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
2169
2156
ff -> set_autocenter = hidpp_ff_set_autocenter ;
2170
2157
ff -> destroy = hidpp_ff_destroy ;
2171
2158
2172
-
2173
- /* reset all forces */
2174
- error = hidpp_send_fap_command_sync (hidpp , feature_index ,
2175
- HIDPP_FF_RESET_ALL , NULL , 0 , & response );
2176
-
2177
- /* Read current Range */
2178
- error = hidpp_send_fap_command_sync (hidpp , feature_index ,
2179
- HIDPP_FF_GET_APERTURE , NULL , 0 , & response );
2180
- if (error )
2181
- hid_warn (hidpp -> hid_dev , "Failed to read range from device!\n" );
2182
- data -> range = error ? 900 : get_unaligned_be16 (& response .fap .params [0 ]);
2183
-
2184
2159
/* Create sysfs interface */
2185
2160
error = device_create_file (& (hidpp -> hid_dev -> dev ), & dev_attr_range );
2186
2161
if (error )
2187
2162
hid_warn (hidpp -> hid_dev , "Unable to create sysfs interface for \"range\", errno %d!\n" , error );
2188
2163
2189
- /* Read the current gain values */
2190
- error = hidpp_send_fap_command_sync (hidpp , feature_index ,
2191
- HIDPP_FF_GET_GLOBAL_GAINS , NULL , 0 , & response );
2192
- if (error )
2193
- hid_warn (hidpp -> hid_dev , "Failed to read gain values from device!\n" );
2194
- data -> gain = error ? 0xffff : get_unaligned_be16 (& response .fap .params [0 ]);
2195
- /* ignore boost value at response.fap.params[2] */
2196
-
2197
2164
/* init the hardware command queue */
2198
2165
atomic_set (& data -> workqueue_size , 0 );
2199
2166
2200
- /* initialize with zero autocenter to get wheel in usable state */
2201
- hidpp_ff_set_autocenter (dev , 0 );
2202
-
2203
2167
hid_info (hid , "Force feedback support loaded (firmware release %d).\n" ,
2204
2168
version );
2205
2169
@@ -2732,24 +2696,93 @@ static int k400_connect(struct hid_device *hdev, bool connected)
2732
2696
2733
2697
#define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
2734
2698
2735
- static int g920_get_config (struct hidpp_device * hidpp )
2699
+ static int g920_ff_set_autocenter (struct hidpp_device * hidpp ,
2700
+ struct hidpp_ff_private_data * data )
2736
2701
{
2702
+ struct hidpp_report response ;
2703
+ u8 params [HIDPP_AUTOCENTER_PARAMS_LENGTH ] = {
2704
+ [1 ] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART ,
2705
+ };
2706
+ int ret ;
2707
+
2708
+ /* initialize with zero autocenter to get wheel in usable state */
2709
+
2710
+ dbg_hid ("Setting autocenter to 0.\n" );
2711
+ ret = hidpp_send_fap_command_sync (hidpp , data -> feature_index ,
2712
+ HIDPP_FF_DOWNLOAD_EFFECT ,
2713
+ params , ARRAY_SIZE (params ),
2714
+ & response );
2715
+ if (ret )
2716
+ hid_warn (hidpp -> hid_dev , "Failed to autocenter device!\n" );
2717
+ else
2718
+ data -> slot_autocenter = response .fap .params [0 ];
2719
+
2720
+ return ret ;
2721
+ }
2722
+
2723
+ static int g920_get_config (struct hidpp_device * hidpp ,
2724
+ struct hidpp_ff_private_data * data )
2725
+ {
2726
+ struct hidpp_report response ;
2737
2727
u8 feature_type ;
2738
- u8 feature_index ;
2739
2728
int ret ;
2740
2729
2730
+ memset (data , 0 , sizeof (* data ));
2731
+
2741
2732
/* Find feature and store for later use */
2742
2733
ret = hidpp_root_get_feature (hidpp , HIDPP_PAGE_G920_FORCE_FEEDBACK ,
2743
- & feature_index , & feature_type );
2734
+ & data -> feature_index , & feature_type );
2744
2735
if (ret )
2745
2736
return ret ;
2746
2737
2747
- ret = hidpp_ff_init (hidpp , feature_index );
2738
+ /* Read number of slots available in device */
2739
+ ret = hidpp_send_fap_command_sync (hidpp , data -> feature_index ,
2740
+ HIDPP_FF_GET_INFO ,
2741
+ NULL , 0 ,
2742
+ & response );
2743
+ if (ret ) {
2744
+ if (ret < 0 )
2745
+ return ret ;
2746
+ hid_err (hidpp -> hid_dev ,
2747
+ "%s: received protocol error 0x%02x\n" , __func__ , ret );
2748
+ return - EPROTO ;
2749
+ }
2750
+
2751
+ data -> num_effects = response .fap .params [0 ] - HIDPP_FF_RESERVED_SLOTS ;
2752
+
2753
+ /* reset all forces */
2754
+ ret = hidpp_send_fap_command_sync (hidpp , data -> feature_index ,
2755
+ HIDPP_FF_RESET_ALL ,
2756
+ NULL , 0 ,
2757
+ & response );
2748
2758
if (ret )
2749
- hid_warn (hidpp -> hid_dev , "Unable to initialize force feedback support, errno %d\n" ,
2750
- ret );
2759
+ hid_warn (hidpp -> hid_dev , "Failed to reset all forces!\n" );
2751
2760
2752
- return 0 ;
2761
+ ret = hidpp_send_fap_command_sync (hidpp , data -> feature_index ,
2762
+ HIDPP_FF_GET_APERTURE ,
2763
+ NULL , 0 ,
2764
+ & response );
2765
+ if (ret ) {
2766
+ hid_warn (hidpp -> hid_dev ,
2767
+ "Failed to read range from device!\n" );
2768
+ }
2769
+ data -> range = ret ?
2770
+ 900 : get_unaligned_be16 (& response .fap .params [0 ]);
2771
+
2772
+ /* Read the current gain values */
2773
+ ret = hidpp_send_fap_command_sync (hidpp , data -> feature_index ,
2774
+ HIDPP_FF_GET_GLOBAL_GAINS ,
2775
+ NULL , 0 ,
2776
+ & response );
2777
+ if (ret )
2778
+ hid_warn (hidpp -> hid_dev ,
2779
+ "Failed to read gain values from device!\n" );
2780
+ data -> gain = ret ?
2781
+ 0xffff : get_unaligned_be16 (& response .fap .params [0 ]);
2782
+
2783
+ /* ignore boost value at response.fap.params[2] */
2784
+
2785
+ return g920_ff_set_autocenter (hidpp , data );
2753
2786
}
2754
2787
2755
2788
/* -------------------------------------------------------------------------- */
@@ -3512,6 +3545,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
3512
3545
int ret ;
3513
3546
bool connected ;
3514
3547
unsigned int connect_mask = HID_CONNECT_DEFAULT ;
3548
+ struct hidpp_ff_private_data data ;
3515
3549
3516
3550
/* report_fixup needs drvdata to be set before we call hid_parse */
3517
3551
hidpp = devm_kzalloc (& hdev -> dev , sizeof (* hidpp ), GFP_KERNEL );
@@ -3621,7 +3655,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
3621
3655
if (ret )
3622
3656
goto hid_hw_init_fail ;
3623
3657
} else if (connected && (hidpp -> quirks & HIDPP_QUIRK_CLASS_G920 )) {
3624
- ret = g920_get_config (hidpp );
3658
+ ret = g920_get_config (hidpp , & data );
3625
3659
if (ret )
3626
3660
goto hid_hw_init_fail ;
3627
3661
}
@@ -3643,6 +3677,14 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
3643
3677
goto hid_hw_start_fail ;
3644
3678
}
3645
3679
3680
+ if (hidpp -> quirks & HIDPP_QUIRK_CLASS_G920 ) {
3681
+ ret = hidpp_ff_init (hidpp , & data );
3682
+ if (ret )
3683
+ hid_warn (hidpp -> hid_dev ,
3684
+ "Unable to initialize force feedback support, errno %d\n" ,
3685
+ ret );
3686
+ }
3687
+
3646
3688
return ret ;
3647
3689
3648
3690
hid_hw_init_fail :
0 commit comments