From: Roderick Colenbrander <roderick@gaikai.com>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org, Chris Ye <lzye@google.com>,
Roderick Colenbrander <roderick.colenbrander@sony.com>
Subject: [PATCH 12/13] HID: playstation: DualSense set LEDs to default player id.
Date: Fri, 18 Dec 2020 22:23:35 -0800 [thread overview]
Message-ID: <20201219062336.72568-13-roderick@gaikai.com> (raw)
In-Reply-To: <20201219062336.72568-1-roderick@gaikai.com>
From: Roderick Colenbrander <roderick.colenbrander@sony.com>
Add a ID allocator to assign player ids to ps_device instances.
Utilize the player id to set a default color on the DualSense its
player LED strip.
Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
---
drivers/hid/hid-playstation.c | 58 +++++++++++++++++++++++++++++++++--
1 file changed, 56 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 384449e3095d..a55375ac79a9 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -20,12 +20,16 @@
static DEFINE_MUTEX(ps_devices_lock);
static LIST_HEAD(ps_devices_list);
+static DEFINE_IDA(ps_player_id_allocator);
+
/* Base class for playstation devices. */
struct ps_device {
struct list_head list;
struct hid_device *hdev;
spinlock_t lock;
+ uint32_t player_id;
+
struct power_supply_desc battery_desc;
struct power_supply *battery;
uint8_t battery_capacity;
@@ -288,6 +292,24 @@ static int ps_devices_list_remove(struct ps_device *dev)
return 0;
}
+static int ps_device_set_player_id(struct ps_device *dev)
+{
+ int ret = ida_alloc(&ps_player_id_allocator, GFP_KERNEL);
+
+ if (ret < 0)
+ return ret;
+
+ dev->player_id = ret;
+ return 0;
+}
+
+static void ps_device_release_player_id(struct ps_device *dev)
+{
+ ida_free(&ps_player_id_allocator, dev->player_id);
+
+ dev->player_id = -1;
+}
+
static struct input_dev *ps_allocate_input_dev(struct hid_device *hdev, const char *name_suffix)
{
struct input_dev *input_dev;
@@ -837,8 +859,8 @@ static void dualsense_output_worker(struct work_struct *work)
}
if (ds->update_player_leds) {
- r->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE;
- r->player_leds = ds->player_leds_state;
+ common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE;
+ common->player_leds = ds->player_leds_state;
ds->update_player_leds = false;
}
@@ -1084,6 +1106,28 @@ static int dualsense_reset_leds(struct dualsense *ds)
return 0;
}
+static void dualsense_set_player_leds(struct dualsense *ds)
+{
+ /* The DualSense controller has a row of 5 LEDs used for player ids.
+ * Behavior on the PlayStation 5 console is to center the player id
+ * across the LEDs, so e.g. player 1 would be "--x--" with x being 'on'.
+ * Follow a similar mapping here.
+ */
+ int player_ids[5] = {
+ BIT(2),
+ BIT(3) | BIT(1),
+ BIT(4) | BIT(2) | BIT(0),
+ BIT(4) | BIT(3) | BIT(1) | BIT(0),
+ BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0)
+ };
+
+ uint8_t player_id = ds->base.player_id % 5;
+
+ ds->update_player_leds = true;
+ ds->player_leds_state = player_ids[player_id];
+ schedule_work(&ds->output_worker);
+}
+
static struct ps_device *dualsense_create(struct hid_device *hdev)
{
struct dualsense *ds;
@@ -1188,6 +1232,15 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
goto err;
}
+ ret = ps_device_set_player_id((struct ps_device *)ds);
+ if (ret < 0) {
+ hid_err(hdev, "Failed to assign player id for DualSense\n");
+ goto err;
+ }
+
+ /* Set player LEDs to our player id. */
+ dualsense_set_player_leds(ds);
+
return (struct ps_device *)ds;
err:
@@ -1256,6 +1309,7 @@ static void ps_remove(struct hid_device *hdev)
struct ps_device *dev = hid_get_drvdata(hdev);
ps_devices_list_remove(dev);
+ ps_device_release_player_id(dev);
hid_hw_close(hdev);
hid_hw_stop(hdev);
--
2.26.2
next prev parent reply other threads:[~2020-12-19 6:25 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-19 6:23 [PATCH 00/13] HID: new driver for PS5 'DualSense' controller Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 01/13] HID: playstation: initial DualSense USB support Roderick Colenbrander
2020-12-27 16:23 ` Barnabás Pőcze
2020-12-27 23:04 ` Roderick Colenbrander
2020-12-29 19:12 ` Barnabás Pőcze
2020-12-31 0:08 ` Barnabás Pőcze
2020-12-31 1:08 ` Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 02/13] HID: playstation: use DualSense MAC address as unique identifier Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 03/13] HID: playstation: add DualSense battery support Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 04/13] HID: playstation: add DualSense touchpad support Roderick Colenbrander
2020-12-26 2:14 ` Samuel Čavoj
2020-12-26 22:27 ` Roderick Colenbrander
2020-12-29 19:49 ` Barnabás Pőcze
2020-12-29 21:44 ` Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 05/13] HID: playstation: add DualSense accelerometer and gyroscope support Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 06/13] HID: playstation: track devices in list Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 07/13] HID: playstation: add DualSense Bluetooth support Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 08/13] HID: playstation: add DualSense classic rumble support Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 09/13] HID: playstation: add DualSense lightbar support Roderick Colenbrander
2020-12-27 14:41 ` Barnabás Pőcze
2020-12-28 21:26 ` Roderick Colenbrander
2020-12-29 18:59 ` Barnabás Pőcze
2020-12-29 19:54 ` Roderick Colenbrander
2020-12-29 20:22 ` Barnabás Pőcze
2020-12-19 6:23 ` [PATCH 10/13] HID: playstation: add microphone mute support for DualSense Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 11/13] HID: playstation: add DualSense player LEDs support Roderick Colenbrander
2020-12-26 19:27 ` Samuel Čavoj
2020-12-26 23:07 ` Roderick Colenbrander
2020-12-27 14:27 ` Barnabás Pőcze
2020-12-28 22:02 ` Roderick Colenbrander
2020-12-29 18:49 ` Barnabás Pőcze
2020-12-19 6:23 ` Roderick Colenbrander [this message]
2020-12-27 0:08 ` [PATCH 12/13] HID: playstation: DualSense set LEDs to default player id Samuel Čavoj
2020-12-27 23:07 ` Roderick Colenbrander
2020-12-19 6:23 ` [PATCH 13/13] HID: playstation: report DualSense hardware and firmware version Roderick Colenbrander
2020-12-27 17:06 ` Barnabás Pőcze
2020-12-27 22:21 ` Roderick Colenbrander
2020-12-27 22:27 ` Roderick Colenbrander
2020-12-27 22:37 ` Barnabás Pőcze
2020-12-28 22:45 ` Roderick Colenbrander
2020-12-29 15:10 ` Barnabás Pőcze
2020-12-19 8:38 ` [PATCH 00/13] HID: new driver for PS5 'DualSense' controller Bastien Nocera
2020-12-19 22:39 ` Roderick.Colenbrander
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=20201219062336.72568-13-roderick@gaikai.com \
--to=roderick@gaikai.com \
--cc=benjamin.tissoires@redhat.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=lzye@google.com \
--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;
as well as URLs for NNTP newsgroup(s).