From nobody Thu Oct 2 03:27:31 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11F59260575; Mon, 22 Sep 2025 21:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758576661; cv=none; b=B0BYkZ+ewpG5wVZirUegN8StZy/26sCOEI9S0EiSgj54hqPfeA4saDmprG7zy+t/ELaeTHqzArstlZLUNVxZinD9I993C80nixKdja8+VmUjS0806qY9xeeDYKD4S04gqWOzflIwZS1oDA2ZTGPJwogVUhNaTAv9lvx66Xx15jA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758576661; c=relaxed/simple; bh=PNvJrOTdJfeVmDWRL8Cv7MvmoQ3mbxUgxxgcOdoaGtg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m7Fe7uUVc8CxBTggZFv6SbAaVJBlmJNDid0hmEftrrFwWcr3SZ0n13jBoNfwGAPQdnQgwkNQhXrqcJayY2wEvGdn/gNdhRCuKrUfokPYcknXuhYkm+l8s7g5jp5jL/yOzRyZpdMPiTTpl9bUT+uH/3W/smNTpOnxb3lckSgJGdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=MTwIUsl7; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="MTwIUsl7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1758576658; bh=PNvJrOTdJfeVmDWRL8Cv7MvmoQ3mbxUgxxgcOdoaGtg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MTwIUsl7gfPHx9cXRUNKEoiafhsq754HYDFS1oKmPQTHz/+dm18fq+JsS7qAHl4ZU Ytqsqa3cXgCftahNBaUxUOdE2AK3h0dassvmRPPDeH/up4KKxCBcodgtyd82/HfG00 kLQnI3WsTl0kC0JWbo6sjheX7bLj1cvr8jao6i1bKR3t14QRSoFZc6RrVGtGtzljAG 6McqrYnpzOcNOu9Ud0y0Aku/bJ3wdJHHwgk26JWdQMSOUxlPMpbZK9I2HIbaSv5uxn rdI7stR7z9BEeSkl6XMlwFL7oD7soV3XCJ97jQKRE5B9qYsgYQvKHkX2Wlr7cXZ25d KNyxHj98gPsLA== Received: from localhost (unknown [82.79.138.60]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with UTF8SMTPSA id 0D0D917E10B7; Mon, 22 Sep 2025 23:30:58 +0200 (CEST) From: Cristian Ciocaltea Date: Tue, 23 Sep 2025 00:29:40 +0300 Subject: [PATCH 1/3] HID: playstation: Update SP preamp gain comment line Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250923-ps5-hid-fixes-v1-1-4b994c54e512@collabora.com> References: <20250923-ps5-hid-fixes-v1-0-4b994c54e512@collabora.com> In-Reply-To: <20250923-ps5-hid-fixes-v1-0-4b994c54e512@collabora.com> To: Roderick Colenbrander , Jiri Kosina , Benjamin Tissoires Cc: kernel@collabora.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 Adjusting speaker pre-amp gain to 0x2 indicates +6dB, hence update the related comment line accordingly. Suggested-by: Roderick Colenbrander Signed-off-by: Cristian Ciocaltea --- drivers/hid/hid-playstation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index d2bee1a314b1b4697378d8472d3f65df5d2cf790..e03ab8a92bca9416787caceb468= 2be253efe54a2 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -1372,7 +1372,7 @@ static void dualsense_output_worker(struct work_struc= t *work) */ common->valid_flag0 |=3D DS_OUTPUT_VALID_FLAG0_SPEAKER_VOLUME_ENABLE; common->speaker_volume =3D 0x64; - /* Set SP preamp gain to ~30% */ + /* Set SP preamp gain to +6dB */ common->valid_flag1 =3D DS_OUTPUT_VALID_FLAG1_AUDIO_CONTROL2_ENABLE; common->audio_control2 =3D FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS2_SP_PREAMP_GAIN, 0x2); --=20 2.51.0 From nobody Thu Oct 2 03:27:31 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B574D26A0BD; Mon, 22 Sep 2025 21:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758576662; cv=none; b=kVp1sJzTKCVGIbXzYWZT5pdkqtKsrPPzZjAE4C6dZqesBlyM5/Cz0JfeQlGw1m6DScv/JknWicEp2cDjpbjAXN2oEb6au/J2Ra4PK4DUMc94xeq1myDNXJNSkwihMd+M0VOLBNLGA7H5TFpyNZJ23n1c+HqBoou+F3GCsZtxg94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758576662; c=relaxed/simple; bh=oNbcqTZ43yhtoO7bFrpbdi7x+RN6hiRQ9jNRuQrG9b8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MLLFVCtVvsPPakLfnRRamE0zfLpajBZw7z18D6d1Cyrrph0tHYG3wVZrGk5f3crDk8U8UONlMZq9Nj77NMHvdV50J5+qciLVQQGnWcpdp6tb4tZXF9Ej48UnETyws8w9IpTrCAajtCAxMeIixDONk4Vs0f03Cl37lrvBP3kFax4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=JReZdjMM; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="JReZdjMM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1758576659; bh=oNbcqTZ43yhtoO7bFrpbdi7x+RN6hiRQ9jNRuQrG9b8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JReZdjMMbVxkZZvCRCMEkaBSyqYqH7UjkHrIF6c76ZdCG9pW6tel4W96AZSVjI1hN c+QC2wxg3+VVN3MDE/hEt46ZEVVxqFpkQxla/Lrz/4zXg9eQ1jjU3bEQY0Ba2od7yb OOYNiA79YDw68/Uz87G71MDCagSdHVMmVr86t5Ah2EIljxXlFM3BAPOaEa4/Y1XWKS ctNX6dgRqjx0lP36F+Qa/hzduCPGrmVh9ZoT71kmZG2S3E+OQ3foyjQ3UfCV3ID6Fq r/k5iKfAZVkesaCTnHOgqFCzcH+/gkigjSlozStU4ufIOVlVMs7OGK0XkyqOdZ+AvO OZE7VN3md7jmA== Received: from localhost (unknown [82.79.138.60]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with UTF8SMTPSA id D72E217E12A7; Mon, 22 Sep 2025 23:30:58 +0200 (CEST) From: Cristian Ciocaltea Date: Tue, 23 Sep 2025 00:29:41 +0300 Subject: [PATCH 2/3] HID: playstation: Silence sparse warnings for locking context imbalances Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250923-ps5-hid-fixes-v1-2-4b994c54e512@collabora.com> References: <20250923-ps5-hid-fixes-v1-0-4b994c54e512@collabora.com> In-Reply-To: <20250923-ps5-hid-fixes-v1-0-4b994c54e512@collabora.com> To: Roderick Colenbrander , Jiri Kosina , Benjamin Tissoires Cc: kernel@collabora.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 It seems sparse has some difficulties with guard() handling or when mixing it with scoped_guard(), as it shows a bunch lock related warnings: hid-playstation.c:1230:32: warning: context imbalance in 'dualsense_playe= r_led_set_brightness' - wrong count at exit hid-playstation.c:1414:12: warning: context imbalance in 'dualsense_parse= _report' - wrong count at exit hid-playstation.c:1615:12: warning: context imbalance in 'dualsense_play_= effect' - different lock contexts for basic block hid-playstation.c:1668:13: warning: context imbalance in 'dualsense_set_l= ightbar' - wrong count at exit hid-playstation.c:1680:13: warning: context imbalance in 'dualsense_set_p= layer_leds' - wrong count at exit hid-playstation.c:2185:33: warning: context imbalance in 'dualshock4_led_= set_blink' - wrong count at exit hid-playstation.c:2226:33: warning: context imbalance in 'dualshock4_led_= set_brightness' - wrong count at exit hid-playstation.c:2596:12: warning: context imbalance in 'dualshock4_play= _effect' - different lock contexts for basic block hid-playstation.c:2634:13: warning: context imbalance in 'dualshock4_set_= bt_poll_interval' - wrong count at exit hid-playstation.c:2642:13: warning: context imbalance in 'dualshock4_set_= default_lightbar_colors' - wrong count at exit Silent them by switching from guard() to scoped_guard() in {dualsense|dualshock4}_schedule_work(). Reported-by: Benjamin Tissoires Suggested-by: Benjamin Tissoires Signed-off-by: Cristian Ciocaltea --- drivers/hid/hid-playstation.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index e03ab8a92bca9416787caceb4682be253efe54a2..87038dacebe7bae72621e3a14df= c39693a316782 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -1274,9 +1274,10 @@ static void dualsense_init_output_report(struct dual= sense *ds, =20 static inline void dualsense_schedule_work(struct dualsense *ds) { - guard(spinlock_irqsave)(&ds->base.lock); - if (ds->output_worker_initialized) - schedule_work(&ds->output_worker); + /* Using scoped_guard() instead of guard() to make sparse happy */ + scoped_guard(spinlock_irqsave, &ds->base.lock) + if (ds->output_worker_initialized) + schedule_work(&ds->output_worker); } =20 /* @@ -2626,9 +2627,10 @@ static void dualshock4_remove(struct ps_device *ps_d= ev) =20 static inline void dualshock4_schedule_work(struct dualshock4 *ds4) { - guard(spinlock_irqsave)(&ds4->base.lock); - if (ds4->output_worker_initialized) - schedule_work(&ds4->output_worker); + /* Using scoped_guard() instead of guard() to make sparse happy */ + scoped_guard(spinlock_irqsave, &ds4->base.lock) + if (ds4->output_worker_initialized) + schedule_work(&ds4->output_worker); } =20 static void dualshock4_set_bt_poll_interval(struct dualshock4 *ds4, u8 int= erval) --=20 2.51.0 From nobody Thu Oct 2 03:27:31 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 243C02F6587; Mon, 22 Sep 2025 21:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758576664; cv=none; b=pOmLg+9p6BPtxRkCmhGE2MWtdr/nZSYHGhJCbmNvTtknRlnqfcSwvONiLZYh5xesd4xRZh55vrUtIsGM/AK3y4gWwQobGVlU/wxoS7FAPCqhqsMo9810Bia1GTX2wyrpB0eAyoSAWzs5DhcWyuxrkA+6dDdPpsjbtXb9RxWdlsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758576664; c=relaxed/simple; bh=WvIs+scmNhRFPjzD8+VFafd8InaoaA8XRwVjTYApbHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XNtpDtpbEcO8rXVm1rk7aVc55rM7btYVQ4hT+c12DC94DWRygv2PWWQePfwCAyiu7wS2oh1Zl+V+ibjNka2GYGmImjPv2HIEJmUKH6s0UQ8+Zortc/n0kYjrdKfyJ8QFI/DOcPr7b0IC6O3tnd+TtYCbrfxAh/xHx5m9OSr0m6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=RvXtD3z+; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="RvXtD3z+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1758576660; bh=WvIs+scmNhRFPjzD8+VFafd8InaoaA8XRwVjTYApbHI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RvXtD3z+rz1dZOYKsT1rS/tXjlKy1y2EwQJgvOOskDY2Ch4gErUZhJEAxo9uvPkqJ x4dq+5U3OP546JcQG4rzMIXHMWGWjUUhATE47D6Mu8k3Uc4myeB5XAxdDtvPc5y2Th nqWdo6Rs5z90QQN4wdPB49/We/pjpC5aNsh5kU0ws4/wVzyRHo3060U3WOuLt2N5x9 xTTqqRo5qBz7yUcnXm97rpH2LPUXl4RA6QGXLQbn2eowykZUp5wbJSB0+h5U4ZdGx1 b144ppnbQlxlT496vz3ygp1KA/QQVvs2tA31C0ROio2solWUc3hB55rbLjw6VznYfk 3R3ayDeY2VSKQ== Received: from localhost (unknown [82.79.138.60]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with UTF8SMTPSA id 15B6117E12D4; Mon, 22 Sep 2025 23:31:00 +0200 (CEST) From: Cristian Ciocaltea Date: Tue, 23 Sep 2025 00:29:42 +0300 Subject: [PATCH 3/3] HID: playstation: Switch to scoped_guard() in {dualsense|dualshock4}_output_worker() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250923-ps5-hid-fixes-v1-3-4b994c54e512@collabora.com> References: <20250923-ps5-hid-fixes-v1-0-4b994c54e512@collabora.com> In-Reply-To: <20250923-ps5-hid-fixes-v1-0-4b994c54e512@collabora.com> To: Roderick Colenbrander , Jiri Kosina , Benjamin Tissoires Cc: kernel@collabora.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 Those functions were initially excepted from using the scoped_guard() infrastructure as they contain too many long statements, while adding yet another level of indentation seemed to lower readability without bringing an immediate benefit. However, consistency should be more important, hence do the switch and get rid of the remaining explicit acquires & releases of the spinlocks. Signed-off-by: Cristian Ciocaltea --- drivers/hid/hid-playstation.c | 256 +++++++++++++++++++++-----------------= ---- 1 file changed, 129 insertions(+), 127 deletions(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 87038dacebe7bae72621e3a14dfc39693a316782..63f6eb9030d13cb9d0253022a1f= 1c195676e34e8 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -1308,107 +1308,112 @@ static void dualsense_output_worker(struct work_s= truct *work) struct dualsense *ds =3D container_of(work, struct dualsense, output_work= er); struct dualsense_output_report report; struct dualsense_output_report_common *common; - unsigned long flags; =20 dualsense_init_output_report(ds, &report, ds->output_report_dmabuf); common =3D report.common; =20 - spin_lock_irqsave(&ds->base.lock, flags); - - if (ds->update_rumble) { - /* Select classic rumble style haptics and enable it. */ - common->valid_flag0 |=3D DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT; - if (ds->use_vibration_v2) - common->valid_flag2 |=3D DS_OUTPUT_VALID_FLAG2_COMPATIBLE_VIBRATION2; - else - common->valid_flag0 |=3D DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION; - common->motor_left =3D ds->motor_left; - common->motor_right =3D ds->motor_right; - ds->update_rumble =3D false; - } + scoped_guard(spinlock_irqsave, &ds->base.lock) { + if (ds->update_rumble) { + /* Select classic rumble style haptics and enable it. */ + common->valid_flag0 |=3D DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT; + if (ds->use_vibration_v2) + common->valid_flag2 |=3D DS_OUTPUT_VALID_FLAG2_COMPATIBLE_VIBRATION2; + else + common->valid_flag0 |=3D DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION; + common->motor_left =3D ds->motor_left; + common->motor_right =3D ds->motor_right; + ds->update_rumble =3D false; + } =20 - if (ds->update_lightbar) { - common->valid_flag1 |=3D DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE; - common->lightbar_red =3D ds->lightbar_red; - common->lightbar_green =3D ds->lightbar_green; - common->lightbar_blue =3D ds->lightbar_blue; + if (ds->update_lightbar) { + common->valid_flag1 |=3D DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE; + common->lightbar_red =3D ds->lightbar_red; + common->lightbar_green =3D ds->lightbar_green; + common->lightbar_blue =3D ds->lightbar_blue; =20 - ds->update_lightbar =3D false; - } + ds->update_lightbar =3D false; + } =20 - if (ds->update_player_leds) { - common->valid_flag1 |=3D DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_= ENABLE; - common->player_leds =3D ds->player_leds_state; + if (ds->update_player_leds) { + common->valid_flag1 |=3D + DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE; + common->player_leds =3D ds->player_leds_state; =20 - ds->update_player_leds =3D false; - } + ds->update_player_leds =3D false; + } =20 - if (ds->plugged_state !=3D ds->prev_plugged_state) { - u8 val =3D ds->plugged_state & DS_STATUS1_HP_DETECT; + if (ds->plugged_state !=3D ds->prev_plugged_state) { + u8 val =3D ds->plugged_state & DS_STATUS1_HP_DETECT; =20 - if (val !=3D (ds->prev_plugged_state & DS_STATUS1_HP_DETECT)) { - common->valid_flag0 =3D DS_OUTPUT_VALID_FLAG0_AUDIO_CONTROL_ENABLE; - /* - * _--------> Output path setup in audio_flag0 - * / _------> Headphone (HP) Left channel sink - * | / _----> Headphone (HP) Right channel sink - * | | / _--> Internal Speaker (SP) sink - * | | | / - * | | | | L/R - Left/Right channel source - * 0 L-R X X - Unrouted (muted) channel source - * 1 L-L X - * 2 L-L R - * 3 X-X R - */ - if (val) { - /* Mute SP and route L+R channels to HP */ - common->audio_control =3D 0; - } else { - /* Mute HP and route R channel to SP */ - common->audio_control =3D - FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS_OUTPUT_PATH_SEL, 0x3); + if (val !=3D (ds->prev_plugged_state & DS_STATUS1_HP_DETECT)) { + common->valid_flag0 =3D DS_OUTPUT_VALID_FLAG0_AUDIO_CONTROL_ENABLE; /* - * Set SP hardware volume to 100%. - * Note the accepted range seems to be [0x3d..0x64] + * _--------> Output path setup in audio_flag0 + * / _------> Headphone (HP) Left channel sink + * | / _----> Headphone (HP) Right channel sink + * | | / _--> Internal Speaker (SP) sink + * | | | / + * | | | | L/R - Left/Right channel source + * 0 L-R X X - Unrouted (muted) channel source + * 1 L-L X + * 2 L-L R + * 3 X-X R */ - common->valid_flag0 |=3D DS_OUTPUT_VALID_FLAG0_SPEAKER_VOLUME_ENABLE; - common->speaker_volume =3D 0x64; - /* Set SP preamp gain to +6dB */ - common->valid_flag1 =3D DS_OUTPUT_VALID_FLAG1_AUDIO_CONTROL2_ENABLE; - common->audio_control2 =3D - FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS2_SP_PREAMP_GAIN, 0x2); + if (val) { + /* Mute SP and route L+R channels to HP */ + common->audio_control =3D 0; + } else { + /* Mute HP and route R channel to SP */ + common->audio_control =3D + FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS_OUTPUT_PATH_SEL, + 0x3); + /* + * Set SP hardware volume to 100%. + * Note the accepted range seems to be [0x3d..0x64] + */ + common->valid_flag0 |=3D + DS_OUTPUT_VALID_FLAG0_SPEAKER_VOLUME_ENABLE; + common->speaker_volume =3D 0x64; + /* Set SP preamp gain to +6dB */ + common->valid_flag1 =3D + DS_OUTPUT_VALID_FLAG1_AUDIO_CONTROL2_ENABLE; + common->audio_control2 =3D + FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS2_SP_PREAMP_GAIN, + 0x2); + } + + input_report_switch(ds->jack, SW_HEADPHONE_INSERT, val); } =20 - input_report_switch(ds->jack, SW_HEADPHONE_INSERT, val); + val =3D ds->plugged_state & DS_STATUS1_MIC_DETECT; + if (val !=3D (ds->prev_plugged_state & DS_STATUS1_MIC_DETECT)) + input_report_switch(ds->jack, SW_MICROPHONE_INSERT, val); + + input_sync(ds->jack); + ds->prev_plugged_state =3D ds->plugged_state; } =20 - val =3D ds->plugged_state & DS_STATUS1_MIC_DETECT; - if (val !=3D (ds->prev_plugged_state & DS_STATUS1_MIC_DETECT)) - input_report_switch(ds->jack, SW_MICROPHONE_INSERT, val); + if (ds->update_mic_mute) { + common->valid_flag1 |=3D DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENA= BLE; + common->mute_button_led =3D ds->mic_muted; =20 - input_sync(ds->jack); - ds->prev_plugged_state =3D ds->plugged_state; - } - - if (ds->update_mic_mute) { - common->valid_flag1 |=3D DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENAB= LE; - common->mute_button_led =3D ds->mic_muted; + if (ds->mic_muted) { + /* Disable microphone */ + common->valid_flag1 |=3D + DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE; + common->power_save_control |=3D DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE; + } else { + /* Enable microphone */ + common->valid_flag1 |=3D + DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE; + common->power_save_control &=3D + ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE; + } =20 - if (ds->mic_muted) { - /* Disable microphone */ - common->valid_flag1 |=3D DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABL= E; - common->power_save_control |=3D DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE; - } else { - /* Enable microphone */ - common->valid_flag1 |=3D DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABL= E; - common->power_save_control &=3D ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE; + ds->update_mic_mute =3D false; } - - ds->update_mic_mute =3D false; } =20 - spin_unlock_irqrestore(&ds->base.lock, flags); - dualsense_send_output_report(ds, &report); } =20 @@ -2264,62 +2269,59 @@ static void dualshock4_output_worker(struct work_st= ruct *work) struct dualshock4 *ds4 =3D container_of(work, struct dualshock4, output_w= orker); struct dualshock4_output_report report; struct dualshock4_output_report_common *common; - unsigned long flags; =20 dualshock4_init_output_report(ds4, &report, ds4->output_report_dmabuf); common =3D report.common; =20 - spin_lock_irqsave(&ds4->base.lock, flags); - - /* - * Some 3rd party gamepads expect updates to rumble and lightbar - * together, and setting one may cancel the other. - * - * Let's maximise compatibility by always sending rumble and lightbar - * updates together, even when only one has been scheduled, resulting - * in: - * - * ds4->valid_flag0 >=3D 0x03 - * - * Hopefully this will maximise compatibility with third-party pads. - * - * Any further update bits, such as 0x04 for lightbar blinking, will - * be or'd on top of this like before. - */ - if (ds4->update_rumble || ds4->update_lightbar) { - ds4->update_rumble =3D true; /* 0x01 */ - ds4->update_lightbar =3D true; /* 0x02 */ - } + scoped_guard(spinlock_irqsave, &ds4->base.lock) { + /* + * Some 3rd party gamepads expect updates to rumble and lightbar + * together, and setting one may cancel the other. + * + * Let's maximise compatibility by always sending rumble and lightbar + * updates together, even when only one has been scheduled, resulting + * in: + * + * ds4->valid_flag0 >=3D 0x03 + * + * Hopefully this will maximise compatibility with third-party pads. + * + * Any further update bits, such as 0x04 for lightbar blinking, will + * be or'd on top of this like before. + */ + if (ds4->update_rumble || ds4->update_lightbar) { + ds4->update_rumble =3D true; /* 0x01 */ + ds4->update_lightbar =3D true; /* 0x02 */ + } =20 - if (ds4->update_rumble) { - /* Select classic rumble style haptics and enable it. */ - common->valid_flag0 |=3D DS4_OUTPUT_VALID_FLAG0_MOTOR; - common->motor_left =3D ds4->motor_left; - common->motor_right =3D ds4->motor_right; - ds4->update_rumble =3D false; - } + if (ds4->update_rumble) { + /* Select classic rumble style haptics and enable it. */ + common->valid_flag0 |=3D DS4_OUTPUT_VALID_FLAG0_MOTOR; + common->motor_left =3D ds4->motor_left; + common->motor_right =3D ds4->motor_right; + ds4->update_rumble =3D false; + } =20 - if (ds4->update_lightbar) { - common->valid_flag0 |=3D DS4_OUTPUT_VALID_FLAG0_LED; - /* Compatible behavior with hid-sony, which used a dummy global LED to - * allow enabling/disabling the lightbar. The global LED maps to - * lightbar_enabled. - */ - common->lightbar_red =3D ds4->lightbar_enabled ? ds4->lightbar_red : 0; - common->lightbar_green =3D ds4->lightbar_enabled ? ds4->lightbar_green := 0; - common->lightbar_blue =3D ds4->lightbar_enabled ? ds4->lightbar_blue : 0; - ds4->update_lightbar =3D false; - } + if (ds4->update_lightbar) { + common->valid_flag0 |=3D DS4_OUTPUT_VALID_FLAG0_LED; + /* Compatible behavior with hid-sony, which used a dummy global LED to + * allow enabling/disabling the lightbar. The global LED maps to + * lightbar_enabled. + */ + common->lightbar_red =3D ds4->lightbar_enabled ? ds4->lightbar_red : 0; + common->lightbar_green =3D ds4->lightbar_enabled ? ds4->lightbar_green = : 0; + common->lightbar_blue =3D ds4->lightbar_enabled ? ds4->lightbar_blue : = 0; + ds4->update_lightbar =3D false; + } =20 - if (ds4->update_lightbar_blink) { - common->valid_flag0 |=3D DS4_OUTPUT_VALID_FLAG0_LED_BLINK; - common->lightbar_blink_on =3D ds4->lightbar_blink_on; - common->lightbar_blink_off =3D ds4->lightbar_blink_off; - ds4->update_lightbar_blink =3D false; + if (ds4->update_lightbar_blink) { + common->valid_flag0 |=3D DS4_OUTPUT_VALID_FLAG0_LED_BLINK; + common->lightbar_blink_on =3D ds4->lightbar_blink_on; + common->lightbar_blink_off =3D ds4->lightbar_blink_off; + ds4->update_lightbar_blink =3D false; + } } =20 - spin_unlock_irqrestore(&ds4->base.lock, flags); - /* Bluetooth packets need additional flags as well as a CRC in the last 4= bytes. */ if (report.bt) { u32 crc; --=20 2.51.0