Linux Input/HID development
 help / color / mirror / Atom feed
From: Roderick Colenbrander <roderick@gaikai.com>
To: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org,
	Roderick Colenbrander <roderick.colenbrander@sony.com>
Subject: [PATCH 12/13] HID: playstation: set default DualShock4 BT poll interval to 4ms.
Date: Sat, 29 Oct 2022 11:48:50 -0700	[thread overview]
Message-ID: <20221029184851.282366-13-roderick.colenbrander@sony.com> (raw)
In-Reply-To: <20221029184851.282366-1-roderick.colenbrander@sony.com>

The poll interval for DualShock4 in Bluetooth mode is adjustable
through the main output report. Configure it to 4ms, which is
similar to USB.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
---
 drivers/hid/hid-playstation.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index a2f1bd1400a2..05553d07cb1b 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -316,6 +316,17 @@ struct dualsense_output_report {
 /* Battery status within batery_status field. */
 #define DS4_BATTERY_STATUS_FULL		11
 
+/* The lower 6 bits of hw_control of the Bluetooth main output report
+ * control the interval at which Dualshock 4 reports data:
+ * 0x00 - 1ms
+ * 0x01 - 1ms
+ * 0x02 - 2ms
+ * 0x3E - 62ms
+ * 0x3F - disabled
+ */
+#define DS4_OUTPUT_HWCTL_BT_POLL_MASK	0x3F
+/* Default to 4ms poll interval, which is same as USB (not adjustable). */
+#define DS4_BT_DEFAULT_POLL_INTERVAL_MS	4
 #define DS4_OUTPUT_HWCTL_CRC32		0x40
 #define DS4_OUTPUT_HWCTL_HID		0x80
 
@@ -348,6 +359,10 @@ struct dualshock4 {
 	uint32_t prev_sensor_timestamp;
 	uint32_t sensor_timestamp_us;
 
+	/* Bluetooth poll interval */
+	bool update_bt_poll_interval;
+	uint8_t bt_poll_interval;
+
 	bool update_rumble;
 	uint8_t motor_left;
 	uint8_t motor_right;
@@ -2010,6 +2025,11 @@ static void dualshock4_output_worker(struct work_struct *work)
 		 */
 		report.bt->hw_control = DS4_OUTPUT_HWCTL_HID | DS4_OUTPUT_HWCTL_CRC32;
 
+		if (ds4->update_bt_poll_interval) {
+			report.bt->hw_control |= ds4->bt_poll_interval;
+			ds4->update_bt_poll_interval = false;
+		}
+
 		crc = crc32_le(0xFFFFFFFF, &seed, 1);
 		crc = ~crc32_le(crc, report.data, report.len - 4);
 
@@ -2241,6 +2261,13 @@ static inline void dualshock4_schedule_work(struct dualshock4 *ds4)
 	spin_unlock_irqrestore(&ds4->base.lock, flags);
 }
 
+static void dualshock4_set_bt_poll_interval(struct dualshock4 *ds4, uint8_t interval)
+{
+	ds4->bt_poll_interval = interval;
+	ds4->update_bt_poll_interval = true;
+	dualshock4_schedule_work(ds4);
+}
+
 /* Set default lightbar color based on player. */
 static void dualshock4_set_default_lightbar_colors(struct dualshock4 *ds4)
 {
@@ -2372,6 +2399,8 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev)
 			goto err;
 	}
 
+	dualshock4_set_bt_poll_interval(ds4, DS4_BT_DEFAULT_POLL_INTERVAL_MS);
+
 	ret = ps_device_set_player_id(ps_dev);
 	if (ret) {
 		hid_err(hdev, "Failed to assign player id for DualShock4: %d\n", ret);
-- 
2.37.3


  parent reply	other threads:[~2022-10-29 18:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-29 18:48 [PATCH 00/13] hid: playstation: add DualShock4 support Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 01/13] HID: playstation: initial DualShock4 USB support Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 02/13] HID: playstation: report DualShock4 hardware and firmware version Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 03/13] HID: playstation: add DualShock4 battery support Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 04/13] HID: playstation: add DualShock4 touchpad support Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 05/13] HID: playstation: add DualShock4 accelerometer and gyroscope support Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 06/13] HID: playstation: Add DualShock4 rumble support Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 07/13] HID: playstation: make LED brightness adjustable in ps_led_register Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 08/13] HID: playstation: support DualShock4 lightbar Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 09/13] HID: playstation: support DualShock4 lightbar blink Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 10/13] HID: playstation: add option to ignore CRC in ps_get_report Roderick Colenbrander
2022-10-29 18:48 ` [PATCH 11/13] HID: playstation: add DualShock4 bluetooth support Roderick Colenbrander
2022-11-14 13:33   ` Benjamin Tissoires
2022-11-14 16:53     ` Roderick Colenbrander
2022-11-14 20:14       ` Roderick Colenbrander
2022-11-15  0:05         ` Roderick Colenbrander
2022-11-15  8:26           ` Benjamin Tissoires
2022-10-29 18:48 ` Roderick Colenbrander [this message]
2022-10-29 18:48 ` [PATCH 13/13] HID: playstation: add DualShock4 dongle support Roderick Colenbrander
2022-11-11 10:08 ` [PATCH 00/13] hid: playstation: add DualShock4 support Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221029184851.282366-13-roderick.colenbrander@sony.com \
    --to=roderick@gaikai.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=roderick.colenbrander@sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox