@@ -71,51 +71,207 @@ static LIST_HEAD(steam_devices);
71
71
72
72
/*
73
73
* Commands that can be sent in a feature report.
74
- * Thanks to Valve for some valuable hints .
74
+ * Thanks to Valve and SDL for the names .
75
75
*/
76
- #define STEAM_CMD_SET_MAPPINGS 0x80
77
- #define STEAM_CMD_CLEAR_MAPPINGS 0x81
78
- #define STEAM_CMD_GET_MAPPINGS 0x82
79
- #define STEAM_CMD_GET_ATTRIB 0x83
80
- #define STEAM_CMD_GET_ATTRIB_LABEL 0x84
81
- #define STEAM_CMD_DEFAULT_MAPPINGS 0x85
82
- #define STEAM_CMD_FACTORY_RESET 0x86
83
- #define STEAM_CMD_WRITE_REGISTER 0x87
84
- #define STEAM_CMD_CLEAR_REGISTER 0x88
85
- #define STEAM_CMD_READ_REGISTER 0x89
86
- #define STEAM_CMD_GET_REGISTER_LABEL 0x8a
87
- #define STEAM_CMD_GET_REGISTER_MAX 0x8b
88
- #define STEAM_CMD_GET_REGISTER_DEFAULT 0x8c
89
- #define STEAM_CMD_SET_MODE 0x8d
90
- #define STEAM_CMD_DEFAULT_MOUSE 0x8e
91
- #define STEAM_CMD_FORCEFEEDBAK 0x8f
92
- #define STEAM_CMD_REQUEST_COMM_STATUS 0xb4
93
- #define STEAM_CMD_GET_SERIAL 0xae
94
- #define STEAM_CMD_HAPTIC_RUMBLE 0xeb
95
-
96
- /* Some useful register ids */
97
- #define STEAM_REG_LPAD_MODE 0x07
98
- #define STEAM_REG_RPAD_MODE 0x08
99
- #define STEAM_REG_RPAD_MARGIN 0x18
100
- #define STEAM_REG_LED 0x2d
101
- #define STEAM_REG_GYRO_MODE 0x30
102
- #define STEAM_REG_LPAD_CLICK_PRESSURE 0x34
103
- #define STEAM_REG_RPAD_CLICK_PRESSURE 0x35
104
- #define STEAM_REG_WATCHDOG_ENABLE 0x47
105
-
106
- /* Raw event identifiers */
107
- #define STEAM_EV_INPUT_DATA 0x01
108
- #define STEAM_EV_CONNECT 0x03
109
- #define STEAM_EV_BATTERY 0x04
110
- #define STEAM_EV_DECK_INPUT_DATA 0x09
76
+ enum {
77
+ ID_SET_DIGITAL_MAPPINGS = 0x80 ,
78
+ ID_CLEAR_DIGITAL_MAPPINGS = 0x81 ,
79
+ ID_GET_DIGITAL_MAPPINGS = 0x82 ,
80
+ ID_GET_ATTRIBUTES_VALUES = 0x83 ,
81
+ ID_GET_ATTRIBUTE_LABEL = 0x84 ,
82
+ ID_SET_DEFAULT_DIGITAL_MAPPINGS = 0x85 ,
83
+ ID_FACTORY_RESET = 0x86 ,
84
+ ID_SET_SETTINGS_VALUES = 0x87 ,
85
+ ID_CLEAR_SETTINGS_VALUES = 0x88 ,
86
+ ID_GET_SETTINGS_VALUES = 0x89 ,
87
+ ID_GET_SETTING_LABEL = 0x8A ,
88
+ ID_GET_SETTINGS_MAXS = 0x8B ,
89
+ ID_GET_SETTINGS_DEFAULTS = 0x8C ,
90
+ ID_SET_CONTROLLER_MODE = 0x8D ,
91
+ ID_LOAD_DEFAULT_SETTINGS = 0x8E ,
92
+ ID_TRIGGER_HAPTIC_PULSE = 0x8F ,
93
+ ID_TURN_OFF_CONTROLLER = 0x9F ,
94
+
95
+ ID_GET_DEVICE_INFO = 0xA1 ,
96
+
97
+ ID_CALIBRATE_TRACKPADS = 0xA7 ,
98
+ ID_RESERVED_0 = 0xA8 ,
99
+ ID_SET_SERIAL_NUMBER = 0xA9 ,
100
+ ID_GET_TRACKPAD_CALIBRATION = 0xAA ,
101
+ ID_GET_TRACKPAD_FACTORY_CALIBRATION = 0xAB ,
102
+ ID_GET_TRACKPAD_RAW_DATA = 0xAC ,
103
+ ID_ENABLE_PAIRING = 0xAD ,
104
+ ID_GET_STRING_ATTRIBUTE = 0xAE ,
105
+ ID_RADIO_ERASE_RECORDS = 0xAF ,
106
+ ID_RADIO_WRITE_RECORD = 0xB0 ,
107
+ ID_SET_DONGLE_SETTING = 0xB1 ,
108
+ ID_DONGLE_DISCONNECT_DEVICE = 0xB2 ,
109
+ ID_DONGLE_COMMIT_DEVICE = 0xB3 ,
110
+ ID_DONGLE_GET_WIRELESS_STATE = 0xB4 ,
111
+ ID_CALIBRATE_GYRO = 0xB5 ,
112
+ ID_PLAY_AUDIO = 0xB6 ,
113
+ ID_AUDIO_UPDATE_START = 0xB7 ,
114
+ ID_AUDIO_UPDATE_DATA = 0xB8 ,
115
+ ID_AUDIO_UPDATE_COMPLETE = 0xB9 ,
116
+ ID_GET_CHIPID = 0xBA ,
117
+
118
+ ID_CALIBRATE_JOYSTICK = 0xBF ,
119
+ ID_CALIBRATE_ANALOG_TRIGGERS = 0xC0 ,
120
+ ID_SET_AUDIO_MAPPING = 0xC1 ,
121
+ ID_CHECK_GYRO_FW_LOAD = 0xC2 ,
122
+ ID_CALIBRATE_ANALOG = 0xC3 ,
123
+ ID_DONGLE_GET_CONNECTED_SLOTS = 0xC4 ,
124
+
125
+ ID_RESET_IMU = 0xCE ,
126
+
127
+ ID_TRIGGER_HAPTIC_CMD = 0xEA ,
128
+ ID_TRIGGER_RUMBLE_CMD = 0xEB ,
129
+ };
130
+
131
+ /* Settings IDs */
132
+ enum {
133
+ /* 0 */
134
+ SETTING_MOUSE_SENSITIVITY ,
135
+ SETTING_MOUSE_ACCELERATION ,
136
+ SETTING_TRACKBALL_ROTATION_ANGLE ,
137
+ SETTING_HAPTIC_INTENSITY_UNUSED ,
138
+ SETTING_LEFT_GAMEPAD_STICK_ENABLED ,
139
+ SETTING_RIGHT_GAMEPAD_STICK_ENABLED ,
140
+ SETTING_USB_DEBUG_MODE ,
141
+ SETTING_LEFT_TRACKPAD_MODE ,
142
+ SETTING_RIGHT_TRACKPAD_MODE ,
143
+ SETTING_MOUSE_POINTER_ENABLED ,
144
+
145
+ /* 10 */
146
+ SETTING_DPAD_DEADZONE ,
147
+ SETTING_MINIMUM_MOMENTUM_VEL ,
148
+ SETTING_MOMENTUM_DECAY_AMMOUNT ,
149
+ SETTING_TRACKPAD_RELATIVE_MODE_TICKS_PER_PIXEL ,
150
+ SETTING_HAPTIC_INCREMENT ,
151
+ SETTING_DPAD_ANGLE_SIN ,
152
+ SETTING_DPAD_ANGLE_COS ,
153
+ SETTING_MOMENTUM_VERTICAL_DIVISOR ,
154
+ SETTING_MOMENTUM_MAXIMUM_VELOCITY ,
155
+ SETTING_TRACKPAD_Z_ON ,
156
+
157
+ /* 20 */
158
+ SETTING_TRACKPAD_Z_OFF ,
159
+ SETTING_SENSITIVY_SCALE_AMMOUNT ,
160
+ SETTING_LEFT_TRACKPAD_SECONDARY_MODE ,
161
+ SETTING_RIGHT_TRACKPAD_SECONDARY_MODE ,
162
+ SETTING_SMOOTH_ABSOLUTE_MOUSE ,
163
+ SETTING_STEAMBUTTON_POWEROFF_TIME ,
164
+ SETTING_UNUSED_1 ,
165
+ SETTING_TRACKPAD_OUTER_RADIUS ,
166
+ SETTING_TRACKPAD_Z_ON_LEFT ,
167
+ SETTING_TRACKPAD_Z_OFF_LEFT ,
168
+
169
+ /* 30 */
170
+ SETTING_TRACKPAD_OUTER_SPIN_VEL ,
171
+ SETTING_TRACKPAD_OUTER_SPIN_RADIUS ,
172
+ SETTING_TRACKPAD_OUTER_SPIN_HORIZONTAL_ONLY ,
173
+ SETTING_TRACKPAD_RELATIVE_MODE_DEADZONE ,
174
+ SETTING_TRACKPAD_RELATIVE_MODE_MAX_VEL ,
175
+ SETTING_TRACKPAD_RELATIVE_MODE_INVERT_Y ,
176
+ SETTING_TRACKPAD_DOUBLE_TAP_BEEP_ENABLED ,
177
+ SETTING_TRACKPAD_DOUBLE_TAP_BEEP_PERIOD ,
178
+ SETTING_TRACKPAD_DOUBLE_TAP_BEEP_COUNT ,
179
+ SETTING_TRACKPAD_OUTER_RADIUS_RELEASE_ON_TRANSITION ,
180
+
181
+ /* 40 */
182
+ SETTING_RADIAL_MODE_ANGLE ,
183
+ SETTING_HAPTIC_INTENSITY_MOUSE_MODE ,
184
+ SETTING_LEFT_DPAD_REQUIRES_CLICK ,
185
+ SETTING_RIGHT_DPAD_REQUIRES_CLICK ,
186
+ SETTING_LED_BASELINE_BRIGHTNESS ,
187
+ SETTING_LED_USER_BRIGHTNESS ,
188
+ SETTING_ENABLE_RAW_JOYSTICK ,
189
+ SETTING_ENABLE_FAST_SCAN ,
190
+ SETTING_IMU_MODE ,
191
+ SETTING_WIRELESS_PACKET_VERSION ,
192
+
193
+ /* 50 */
194
+ SETTING_SLEEP_INACTIVITY_TIMEOUT ,
195
+ SETTING_TRACKPAD_NOISE_THRESHOLD ,
196
+ SETTING_LEFT_TRACKPAD_CLICK_PRESSURE ,
197
+ SETTING_RIGHT_TRACKPAD_CLICK_PRESSURE ,
198
+ SETTING_LEFT_BUMPER_CLICK_PRESSURE ,
199
+ SETTING_RIGHT_BUMPER_CLICK_PRESSURE ,
200
+ SETTING_LEFT_GRIP_CLICK_PRESSURE ,
201
+ SETTING_RIGHT_GRIP_CLICK_PRESSURE ,
202
+ SETTING_LEFT_GRIP2_CLICK_PRESSURE ,
203
+ SETTING_RIGHT_GRIP2_CLICK_PRESSURE ,
204
+
205
+ /* 60 */
206
+ SETTING_PRESSURE_MODE ,
207
+ SETTING_CONTROLLER_TEST_MODE ,
208
+ SETTING_TRIGGER_MODE ,
209
+ SETTING_TRACKPAD_Z_THRESHOLD ,
210
+ SETTING_FRAME_RATE ,
211
+ SETTING_TRACKPAD_FILT_CTRL ,
212
+ SETTING_TRACKPAD_CLIP ,
213
+ SETTING_DEBUG_OUTPUT_SELECT ,
214
+ SETTING_TRIGGER_THRESHOLD_PERCENT ,
215
+ SETTING_TRACKPAD_FREQUENCY_HOPPING ,
216
+
217
+ /* 70 */
218
+ SETTING_HAPTICS_ENABLED ,
219
+ SETTING_STEAM_WATCHDOG_ENABLE ,
220
+ SETTING_TIMP_TOUCH_THRESHOLD_ON ,
221
+ SETTING_TIMP_TOUCH_THRESHOLD_OFF ,
222
+ SETTING_FREQ_HOPPING ,
223
+ SETTING_TEST_CONTROL ,
224
+ SETTING_HAPTIC_MASTER_GAIN_DB ,
225
+ SETTING_THUMB_TOUCH_THRESH ,
226
+ SETTING_DEVICE_POWER_STATUS ,
227
+ SETTING_HAPTIC_INTENSITY ,
228
+
229
+ /* 80 */
230
+ SETTING_STABILIZER_ENABLED ,
231
+ SETTING_TIMP_MODE_MTE ,
232
+ };
233
+
234
+ /* Input report identifiers */
235
+ enum
236
+ {
237
+ ID_CONTROLLER_STATE = 1 ,
238
+ ID_CONTROLLER_DEBUG = 2 ,
239
+ ID_CONTROLLER_WIRELESS = 3 ,
240
+ ID_CONTROLLER_STATUS = 4 ,
241
+ ID_CONTROLLER_DEBUG2 = 5 ,
242
+ ID_CONTROLLER_SECONDARY_STATE = 6 ,
243
+ ID_CONTROLLER_BLE_STATE = 7 ,
244
+ ID_CONTROLLER_DECK_STATE = 9
245
+ };
246
+
247
+ /* String attribute idenitifiers */
248
+ enum {
249
+ ATTRIB_STR_BOARD_SERIAL ,
250
+ ATTRIB_STR_UNIT_SERIAL ,
251
+ };
111
252
112
253
/* Values for GYRO_MODE (bitmask) */
113
- #define STEAM_GYRO_MODE_OFF 0x0000
114
- #define STEAM_GYRO_MODE_STEERING 0x0001
115
- #define STEAM_GYRO_MODE_TILT 0x0002
116
- #define STEAM_GYRO_MODE_SEND_ORIENTATION 0x0004
117
- #define STEAM_GYRO_MODE_SEND_RAW_ACCEL 0x0008
118
- #define STEAM_GYRO_MODE_SEND_RAW_GYRO 0x0010
254
+ enum {
255
+ SETTING_GYRO_MODE_OFF = 0 ,
256
+ SETTING_GYRO_MODE_STEERING = BIT (0 ),
257
+ SETTING_GYRO_MODE_TILT = BIT (1 ),
258
+ SETTING_GYRO_MODE_SEND_ORIENTATION = BIT (2 ),
259
+ SETTING_GYRO_MODE_SEND_RAW_ACCEL = BIT (3 ),
260
+ SETTING_GYRO_MODE_SEND_RAW_GYRO = BIT (4 ),
261
+ };
262
+
263
+ /* Trackpad modes */
264
+ enum {
265
+ TRACKPAD_ABSOLUTE_MOUSE ,
266
+ TRACKPAD_RELATIVE_MOUSE ,
267
+ TRACKPAD_DPAD_FOUR_WAY_DISCRETE ,
268
+ TRACKPAD_DPAD_FOUR_WAY_OVERLAP ,
269
+ TRACKPAD_DPAD_EIGHT_WAY ,
270
+ TRACKPAD_RADIAL_MODE ,
271
+ TRACKPAD_ABSOLUTE_DPAD ,
272
+ TRACKPAD_NONE ,
273
+ TRACKPAD_GESTURE_KEYBOARD ,
274
+ };
119
275
120
276
/* Other random constants */
121
277
#define STEAM_SERIAL_LEN 10
@@ -226,13 +382,13 @@ static inline int steam_send_report_byte(struct steam_device *steam, u8 cmd)
226
382
return steam_send_report (steam , & cmd , 1 );
227
383
}
228
384
229
- static int steam_write_registers (struct steam_device * steam ,
385
+ static int steam_write_settings (struct steam_device * steam ,
230
386
/* u8 reg, u16 val */ ...)
231
387
{
232
388
/* Send: 0x87 len (reg valLo valHi)* */
233
389
u8 reg ;
234
390
u16 val ;
235
- u8 cmd [64 ] = {STEAM_CMD_WRITE_REGISTER , 0x00 };
391
+ u8 cmd [64 ] = {ID_SET_SETTINGS_VALUES , 0x00 };
236
392
int ret ;
237
393
va_list args ;
238
394
@@ -268,7 +424,7 @@ static int steam_get_serial(struct steam_device *steam)
268
424
* Recv: 0xae 0x15 0x01 serialnumber (10 chars)
269
425
*/
270
426
int ret = 0 ;
271
- u8 cmd [] = {STEAM_CMD_GET_SERIAL , 0x15 , 0x01 };
427
+ u8 cmd [] = {ID_GET_STRING_ATTRIBUTE , 0x15 , ATTRIB_STR_UNIT_SERIAL };
272
428
u8 reply [3 + STEAM_SERIAL_LEN + 1 ];
273
429
274
430
mutex_lock (& steam -> report_mutex );
@@ -278,7 +434,7 @@ static int steam_get_serial(struct steam_device *steam)
278
434
ret = steam_recv_report (steam , reply , sizeof (reply ));
279
435
if (ret < 0 )
280
436
goto out ;
281
- if (reply [0 ] != 0xae || reply [1 ] != 0x15 || reply [2 ] != 0x01 ) {
437
+ if (reply [0 ] != ID_GET_STRING_ATTRIBUTE || reply [1 ] != 0x15 || reply [2 ] != ATTRIB_STR_UNIT_SERIAL ) {
282
438
ret = - EIO ;
283
439
goto out ;
284
440
}
@@ -298,7 +454,7 @@ static inline int steam_request_conn_status(struct steam_device *steam)
298
454
{
299
455
int ret ;
300
456
mutex_lock (& steam -> report_mutex );
301
- ret = steam_send_report_byte (steam , STEAM_CMD_REQUEST_COMM_STATUS );
457
+ ret = steam_send_report_byte (steam , ID_DONGLE_GET_WIRELESS_STATE );
302
458
mutex_unlock (& steam -> report_mutex );
303
459
return ret ;
304
460
}
@@ -308,7 +464,7 @@ static inline int steam_haptic_rumble(struct steam_device *steam,
308
464
u8 left_gain , u8 right_gain )
309
465
{
310
466
int ret ;
311
- u8 report [11 ] = {STEAM_CMD_HAPTIC_RUMBLE , 9 };
467
+ u8 report [11 ] = {ID_TRIGGER_RUMBLE_CMD , 9 };
312
468
313
469
report [3 ] = intensity & 0xFF ;
314
470
report [4 ] = intensity >> 8 ;
@@ -351,28 +507,28 @@ static void steam_set_lizard_mode(struct steam_device *steam, bool enable)
351
507
if (enable ) {
352
508
mutex_lock (& steam -> report_mutex );
353
509
/* enable esc, enter, cursors */
354
- steam_send_report_byte (steam , STEAM_CMD_DEFAULT_MAPPINGS );
355
- /* enable mouse */
356
- steam_send_report_byte (steam , STEAM_CMD_DEFAULT_MOUSE );
510
+ steam_send_report_byte (steam , ID_SET_DEFAULT_DIGITAL_MAPPINGS );
511
+ /* reset settings */
512
+ steam_send_report_byte (steam , ID_LOAD_DEFAULT_SETTINGS );
357
513
mutex_unlock (& steam -> report_mutex );
358
514
} else {
359
515
mutex_lock (& steam -> report_mutex );
360
516
/* disable esc, enter, cursor */
361
- steam_send_report_byte (steam , STEAM_CMD_CLEAR_MAPPINGS );
517
+ steam_send_report_byte (steam , ID_CLEAR_DIGITAL_MAPPINGS );
362
518
363
519
if (steam -> quirks & STEAM_QUIRK_DECK ) {
364
- steam_write_registers (steam ,
365
- STEAM_REG_LPAD_MODE , 0x07 , /* disable mouse */
366
- STEAM_REG_RPAD_MODE , 0x07 , /* disable mouse */
367
- STEAM_REG_LPAD_CLICK_PRESSURE , 0xFFFF , /* disable clicky pad */
368
- STEAM_REG_RPAD_CLICK_PRESSURE , 0xFFFF , /* disable clicky pad */
369
- STEAM_REG_WATCHDOG_ENABLE , 0 , /* disable watchdog that tests if Steam is active */
520
+ steam_write_settings (steam ,
521
+ SETTING_LEFT_TRACKPAD_MODE , TRACKPAD_NONE , /* disable mouse */
522
+ SETTING_RIGHT_TRACKPAD_MODE , TRACKPAD_NONE , /* disable mouse */
523
+ SETTING_LEFT_TRACKPAD_CLICK_PRESSURE , 0xFFFF , /* disable haptic click */
524
+ SETTING_RIGHT_TRACKPAD_CLICK_PRESSURE , 0xFFFF , /* disable haptic click */
525
+ SETTING_STEAM_WATCHDOG_ENABLE , 0 , /* disable watchdog that tests if Steam is active */
370
526
0 );
371
527
mutex_unlock (& steam -> report_mutex );
372
528
} else {
373
- steam_write_registers (steam ,
374
- STEAM_REG_LPAD_MODE , 0x07 , /* disable mouse */
375
- STEAM_REG_RPAD_MODE , 0x07 , /* disable mouse */
529
+ steam_write_settings (steam ,
530
+ SETTING_LEFT_TRACKPAD_MODE , TRACKPAD_NONE , /* disable mouse */
531
+ SETTING_RIGHT_TRACKPAD_MODE , TRACKPAD_NONE , /* disable mouse */
376
532
0 );
377
533
mutex_unlock (& steam -> report_mutex );
378
534
}
@@ -1362,7 +1518,7 @@ static int steam_raw_event(struct hid_device *hdev,
1362
1518
return 0 ;
1363
1519
1364
1520
switch (data [2 ]) {
1365
- case STEAM_EV_INPUT_DATA :
1521
+ case ID_CONTROLLER_STATE :
1366
1522
if (steam -> client_opened )
1367
1523
return 0 ;
1368
1524
rcu_read_lock ();
@@ -1371,7 +1527,7 @@ static int steam_raw_event(struct hid_device *hdev,
1371
1527
steam_do_input_event (steam , input , data );
1372
1528
rcu_read_unlock ();
1373
1529
break ;
1374
- case STEAM_EV_DECK_INPUT_DATA :
1530
+ case ID_CONTROLLER_DECK_STATE :
1375
1531
if (steam -> client_opened )
1376
1532
return 0 ;
1377
1533
rcu_read_lock ();
@@ -1380,7 +1536,7 @@ static int steam_raw_event(struct hid_device *hdev,
1380
1536
steam_do_deck_input_event (steam , input , data );
1381
1537
rcu_read_unlock ();
1382
1538
break ;
1383
- case STEAM_EV_CONNECT :
1539
+ case ID_CONTROLLER_WIRELESS :
1384
1540
/*
1385
1541
* The payload of this event is a single byte:
1386
1542
* 0x01: disconnected.
@@ -1395,7 +1551,7 @@ static int steam_raw_event(struct hid_device *hdev,
1395
1551
break ;
1396
1552
}
1397
1553
break ;
1398
- case STEAM_EV_BATTERY :
1554
+ case ID_CONTROLLER_STATUS :
1399
1555
if (steam -> quirks & STEAM_QUIRK_WIRELESS ) {
1400
1556
rcu_read_lock ();
1401
1557
battery = rcu_dereference (steam -> battery );
0 commit comments