@@ -1308,107 +1308,112 @@ static void dualsense_output_worker(struct work_struct *work)
13081308 struct dualsense * ds = container_of (work , struct dualsense , output_worker );
13091309 struct dualsense_output_report report ;
13101310 struct dualsense_output_report_common * common ;
1311- unsigned long flags ;
13121311
13131312 dualsense_init_output_report (ds , & report , ds -> output_report_dmabuf );
13141313 common = report .common ;
13151314
1316- spin_lock_irqsave (& ds -> base .lock , flags );
1317-
1318- if (ds -> update_rumble ) {
1319- /* Select classic rumble style haptics and enable it. */
1320- common -> valid_flag0 |= DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT ;
1321- if (ds -> use_vibration_v2 )
1322- common -> valid_flag2 |= DS_OUTPUT_VALID_FLAG2_COMPATIBLE_VIBRATION2 ;
1323- else
1324- common -> valid_flag0 |= DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION ;
1325- common -> motor_left = ds -> motor_left ;
1326- common -> motor_right = ds -> motor_right ;
1327- ds -> update_rumble = false;
1328- }
1315+ scoped_guard (spinlock_irqsave , & ds -> base .lock ) {
1316+ if (ds -> update_rumble ) {
1317+ /* Select classic rumble style haptics and enable it. */
1318+ common -> valid_flag0 |= DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT ;
1319+ if (ds -> use_vibration_v2 )
1320+ common -> valid_flag2 |= DS_OUTPUT_VALID_FLAG2_COMPATIBLE_VIBRATION2 ;
1321+ else
1322+ common -> valid_flag0 |= DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION ;
1323+ common -> motor_left = ds -> motor_left ;
1324+ common -> motor_right = ds -> motor_right ;
1325+ ds -> update_rumble = false;
1326+ }
13291327
1330- if (ds -> update_lightbar ) {
1331- common -> valid_flag1 |= DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE ;
1332- common -> lightbar_red = ds -> lightbar_red ;
1333- common -> lightbar_green = ds -> lightbar_green ;
1334- common -> lightbar_blue = ds -> lightbar_blue ;
1328+ if (ds -> update_lightbar ) {
1329+ common -> valid_flag1 |= DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE ;
1330+ common -> lightbar_red = ds -> lightbar_red ;
1331+ common -> lightbar_green = ds -> lightbar_green ;
1332+ common -> lightbar_blue = ds -> lightbar_blue ;
13351333
1336- ds -> update_lightbar = false;
1337- }
1334+ ds -> update_lightbar = false;
1335+ }
13381336
1339- if (ds -> update_player_leds ) {
1340- common -> valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE ;
1341- common -> player_leds = ds -> player_leds_state ;
1337+ if (ds -> update_player_leds ) {
1338+ common -> valid_flag1 |=
1339+ DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE ;
1340+ common -> player_leds = ds -> player_leds_state ;
13421341
1343- ds -> update_player_leds = false;
1344- }
1342+ ds -> update_player_leds = false;
1343+ }
13451344
1346- if (ds -> plugged_state != ds -> prev_plugged_state ) {
1347- u8 val = ds -> plugged_state & DS_STATUS1_HP_DETECT ;
1345+ if (ds -> plugged_state != ds -> prev_plugged_state ) {
1346+ u8 val = ds -> plugged_state & DS_STATUS1_HP_DETECT ;
13481347
1349- if (val != (ds -> prev_plugged_state & DS_STATUS1_HP_DETECT )) {
1350- common -> valid_flag0 = DS_OUTPUT_VALID_FLAG0_AUDIO_CONTROL_ENABLE ;
1351- /*
1352- * _--------> Output path setup in audio_flag0
1353- * / _------> Headphone (HP) Left channel sink
1354- * | / _----> Headphone (HP) Right channel sink
1355- * | | / _--> Internal Speaker (SP) sink
1356- * | | | /
1357- * | | | | L/R - Left/Right channel source
1358- * 0 L-R X X - Unrouted (muted) channel source
1359- * 1 L-L X
1360- * 2 L-L R
1361- * 3 X-X R
1362- */
1363- if (val ) {
1364- /* Mute SP and route L+R channels to HP */
1365- common -> audio_control = 0 ;
1366- } else {
1367- /* Mute HP and route R channel to SP */
1368- common -> audio_control =
1369- FIELD_PREP (DS_OUTPUT_AUDIO_FLAGS_OUTPUT_PATH_SEL , 0x3 );
1348+ if (val != (ds -> prev_plugged_state & DS_STATUS1_HP_DETECT )) {
1349+ common -> valid_flag0 = DS_OUTPUT_VALID_FLAG0_AUDIO_CONTROL_ENABLE ;
13701350 /*
1371- * Set SP hardware volume to 100%.
1372- * Note the accepted range seems to be [0x3d..0x64]
1351+ * _--------> Output path setup in audio_flag0
1352+ * / _------> Headphone (HP) Left channel sink
1353+ * | / _----> Headphone (HP) Right channel sink
1354+ * | | / _--> Internal Speaker (SP) sink
1355+ * | | | /
1356+ * | | | | L/R - Left/Right channel source
1357+ * 0 L-R X X - Unrouted (muted) channel source
1358+ * 1 L-L X
1359+ * 2 L-L R
1360+ * 3 X-X R
13731361 */
1374- common -> valid_flag0 |= DS_OUTPUT_VALID_FLAG0_SPEAKER_VOLUME_ENABLE ;
1375- common -> speaker_volume = 0x64 ;
1376- /* Set SP preamp gain to +6dB */
1377- common -> valid_flag1 = DS_OUTPUT_VALID_FLAG1_AUDIO_CONTROL2_ENABLE ;
1378- common -> audio_control2 =
1379- FIELD_PREP (DS_OUTPUT_AUDIO_FLAGS2_SP_PREAMP_GAIN , 0x2 );
1362+ if (val ) {
1363+ /* Mute SP and route L+R channels to HP */
1364+ common -> audio_control = 0 ;
1365+ } else {
1366+ /* Mute HP and route R channel to SP */
1367+ common -> audio_control =
1368+ FIELD_PREP (DS_OUTPUT_AUDIO_FLAGS_OUTPUT_PATH_SEL ,
1369+ 0x3 );
1370+ /*
1371+ * Set SP hardware volume to 100%.
1372+ * Note the accepted range seems to be [0x3d..0x64]
1373+ */
1374+ common -> valid_flag0 |=
1375+ DS_OUTPUT_VALID_FLAG0_SPEAKER_VOLUME_ENABLE ;
1376+ common -> speaker_volume = 0x64 ;
1377+ /* Set SP preamp gain to +6dB */
1378+ common -> valid_flag1 =
1379+ DS_OUTPUT_VALID_FLAG1_AUDIO_CONTROL2_ENABLE ;
1380+ common -> audio_control2 =
1381+ FIELD_PREP (DS_OUTPUT_AUDIO_FLAGS2_SP_PREAMP_GAIN ,
1382+ 0x2 );
1383+ }
1384+
1385+ input_report_switch (ds -> jack , SW_HEADPHONE_INSERT , val );
13801386 }
13811387
1382- input_report_switch (ds -> jack , SW_HEADPHONE_INSERT , val );
1388+ val = ds -> plugged_state & DS_STATUS1_MIC_DETECT ;
1389+ if (val != (ds -> prev_plugged_state & DS_STATUS1_MIC_DETECT ))
1390+ input_report_switch (ds -> jack , SW_MICROPHONE_INSERT , val );
1391+
1392+ input_sync (ds -> jack );
1393+ ds -> prev_plugged_state = ds -> plugged_state ;
13831394 }
13841395
1385- val = ds -> plugged_state & DS_STATUS1_MIC_DETECT ;
1386- if ( val != ( ds -> prev_plugged_state & DS_STATUS1_MIC_DETECT ))
1387- input_report_switch ( ds -> jack , SW_MICROPHONE_INSERT , val ) ;
1396+ if ( ds -> update_mic_mute ) {
1397+ common -> valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE ;
1398+ common -> mute_button_led = ds -> mic_muted ;
13881399
1389- input_sync (ds -> jack );
1390- ds -> prev_plugged_state = ds -> plugged_state ;
1391- }
1392-
1393- if (ds -> update_mic_mute ) {
1394- common -> valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE ;
1395- common -> mute_button_led = ds -> mic_muted ;
1400+ if (ds -> mic_muted ) {
1401+ /* Disable microphone */
1402+ common -> valid_flag1 |=
1403+ DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE ;
1404+ common -> power_save_control |= DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE ;
1405+ } else {
1406+ /* Enable microphone */
1407+ common -> valid_flag1 |=
1408+ DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE ;
1409+ common -> power_save_control &=
1410+ ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE ;
1411+ }
13961412
1397- if (ds -> mic_muted ) {
1398- /* Disable microphone */
1399- common -> valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE ;
1400- common -> power_save_control |= DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE ;
1401- } else {
1402- /* Enable microphone */
1403- common -> valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE ;
1404- common -> power_save_control &= ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE ;
1413+ ds -> update_mic_mute = false;
14051414 }
1406-
1407- ds -> update_mic_mute = false;
14081415 }
14091416
1410- spin_unlock_irqrestore (& ds -> base .lock , flags );
1411-
14121417 dualsense_send_output_report (ds , & report );
14131418}
14141419
@@ -2264,62 +2269,59 @@ static void dualshock4_output_worker(struct work_struct *work)
22642269 struct dualshock4 * ds4 = container_of (work , struct dualshock4 , output_worker );
22652270 struct dualshock4_output_report report ;
22662271 struct dualshock4_output_report_common * common ;
2267- unsigned long flags ;
22682272
22692273 dualshock4_init_output_report (ds4 , & report , ds4 -> output_report_dmabuf );
22702274 common = report .common ;
22712275
2272- spin_lock_irqsave (& ds4 -> base .lock , flags );
2273-
2274- /*
2275- * Some 3rd party gamepads expect updates to rumble and lightbar
2276- * together, and setting one may cancel the other.
2277- *
2278- * Let's maximise compatibility by always sending rumble and lightbar
2279- * updates together, even when only one has been scheduled, resulting
2280- * in:
2281- *
2282- * ds4->valid_flag0 >= 0x03
2283- *
2284- * Hopefully this will maximise compatibility with third-party pads.
2285- *
2286- * Any further update bits, such as 0x04 for lightbar blinking, will
2287- * be or'd on top of this like before.
2288- */
2289- if (ds4 -> update_rumble || ds4 -> update_lightbar ) {
2290- ds4 -> update_rumble = true; /* 0x01 */
2291- ds4 -> update_lightbar = true; /* 0x02 */
2292- }
2276+ scoped_guard (spinlock_irqsave , & ds4 -> base .lock ) {
2277+ /*
2278+ * Some 3rd party gamepads expect updates to rumble and lightbar
2279+ * together, and setting one may cancel the other.
2280+ *
2281+ * Let's maximise compatibility by always sending rumble and lightbar
2282+ * updates together, even when only one has been scheduled, resulting
2283+ * in:
2284+ *
2285+ * ds4->valid_flag0 >= 0x03
2286+ *
2287+ * Hopefully this will maximise compatibility with third-party pads.
2288+ *
2289+ * Any further update bits, such as 0x04 for lightbar blinking, will
2290+ * be or'd on top of this like before.
2291+ */
2292+ if (ds4 -> update_rumble || ds4 -> update_lightbar ) {
2293+ ds4 -> update_rumble = true; /* 0x01 */
2294+ ds4 -> update_lightbar = true; /* 0x02 */
2295+ }
22932296
2294- if (ds4 -> update_rumble ) {
2295- /* Select classic rumble style haptics and enable it. */
2296- common -> valid_flag0 |= DS4_OUTPUT_VALID_FLAG0_MOTOR ;
2297- common -> motor_left = ds4 -> motor_left ;
2298- common -> motor_right = ds4 -> motor_right ;
2299- ds4 -> update_rumble = false;
2300- }
2297+ if (ds4 -> update_rumble ) {
2298+ /* Select classic rumble style haptics and enable it. */
2299+ common -> valid_flag0 |= DS4_OUTPUT_VALID_FLAG0_MOTOR ;
2300+ common -> motor_left = ds4 -> motor_left ;
2301+ common -> motor_right = ds4 -> motor_right ;
2302+ ds4 -> update_rumble = false;
2303+ }
23012304
2302- if (ds4 -> update_lightbar ) {
2303- common -> valid_flag0 |= DS4_OUTPUT_VALID_FLAG0_LED ;
2304- /* Compatible behavior with hid-sony, which used a dummy global LED to
2305- * allow enabling/disabling the lightbar. The global LED maps to
2306- * lightbar_enabled.
2307- */
2308- common -> lightbar_red = ds4 -> lightbar_enabled ? ds4 -> lightbar_red : 0 ;
2309- common -> lightbar_green = ds4 -> lightbar_enabled ? ds4 -> lightbar_green : 0 ;
2310- common -> lightbar_blue = ds4 -> lightbar_enabled ? ds4 -> lightbar_blue : 0 ;
2311- ds4 -> update_lightbar = false;
2312- }
2305+ if (ds4 -> update_lightbar ) {
2306+ common -> valid_flag0 |= DS4_OUTPUT_VALID_FLAG0_LED ;
2307+ /* Compatible behavior with hid-sony, which used a dummy global LED to
2308+ * allow enabling/disabling the lightbar. The global LED maps to
2309+ * lightbar_enabled.
2310+ */
2311+ common -> lightbar_red = ds4 -> lightbar_enabled ? ds4 -> lightbar_red : 0 ;
2312+ common -> lightbar_green = ds4 -> lightbar_enabled ? ds4 -> lightbar_green : 0 ;
2313+ common -> lightbar_blue = ds4 -> lightbar_enabled ? ds4 -> lightbar_blue : 0 ;
2314+ ds4 -> update_lightbar = false;
2315+ }
23132316
2314- if (ds4 -> update_lightbar_blink ) {
2315- common -> valid_flag0 |= DS4_OUTPUT_VALID_FLAG0_LED_BLINK ;
2316- common -> lightbar_blink_on = ds4 -> lightbar_blink_on ;
2317- common -> lightbar_blink_off = ds4 -> lightbar_blink_off ;
2318- ds4 -> update_lightbar_blink = false;
2317+ if (ds4 -> update_lightbar_blink ) {
2318+ common -> valid_flag0 |= DS4_OUTPUT_VALID_FLAG0_LED_BLINK ;
2319+ common -> lightbar_blink_on = ds4 -> lightbar_blink_on ;
2320+ common -> lightbar_blink_off = ds4 -> lightbar_blink_off ;
2321+ ds4 -> update_lightbar_blink = false;
2322+ }
23192323 }
23202324
2321- spin_unlock_irqrestore (& ds4 -> base .lock , flags );
2322-
23232325 /* Bluetooth packets need additional flags as well as a CRC in the last 4 bytes. */
23242326 if (report .bt ) {
23252327 u32 crc ;
0 commit comments