All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] HID: playstation: revert LED class exposure
@ 2021-02-17 17:31 Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 01/11] Revert "HID: playstation: fix unused variable in ps_battery_get_property." Benjamin Tissoires
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

[sending those patches on behalf of Roderick]

There is a current thread on LED LKML which basically means that
we have to revert the LED class exposure until things are settled.

I am sending here the full series that will end up in linux-next.
But with some git magic, the final PR to Linus will not have the
reverts in it, just the plain patches.

I am queuing in for-5.12/playstation patches 1 to 6 immediately
(the reverts).

I am also queuing in for-5.12/playstation-v2 patches 7 and 8 on
top of 51151098d7ab8 immediately. Those 2 patches have already
been reviewed the usual process.

I am waiting 1 day for others to chime in regarding patches 9 to
11 before applying them to for-5.12/playstation-v2. They are
basically the same patches that were already reviewed on the
linux-input LKML, but without the LED class bits.

With all that, we should have more room to discuss the exposure
of the LEDs to userspace through the LED class.

Roderick, I made small adjustments compared to the series you sent
me privately:
- added the 2 missing reverts/re-add, so I can have clean merges
  for our for-next branch,
- re-ordered the `if (ds->update_rumble)` block in
  `dualsense_output_worker()` to match was was in linux-next
- removed an extra new line to match the current linux-next tree.

Cheers,
Benjamin

Benjamin Tissoires (2):
  Revert "HID: playstation: fix unused variable in
    ps_battery_get_property."
  Revert "HID: playstation: report DualSense hardware and firmware
    version."

Roderick Colenbrander (9):
  Revert "HID: playstation: DualSense set LEDs to default player id."
  Revert "HID: playstation: add DualSense player LEDs support."
  Revert "HID: playstation: add microphone mute support for DualSense."
  Revert "HID: playstation: add DualSense lightbar support"
  HID: playstation: report DualSense hardware and firmware version.
  HID: playstation: fix unused variable in ps_battery_get_property.
  HID: playstation: add initial DualSense lightbar support.
  HID: playstation: add microphone mute support for DualSense.
  HID: playstation: add DualSense player LED support.

 drivers/hid/Kconfig           |   3 -
 drivers/hid/hid-playstation.c | 177 +++-------------------------------
 2 files changed, 12 insertions(+), 168 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 01/11] Revert "HID: playstation: fix unused variable in ps_battery_get_property."
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 02/11] Revert "HID: playstation: report DualSense hardware and firmware version." Benjamin Tissoires
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

This reverts commit 3847d15b41ce ("HID: playstation: fix unused variable
in ps_battery_get_property.")

There is currently an ongoing discussion on linux-leds LKML,
and so to give us more room, we need to revert those related
LEDs patches from linux-next.

To have a cleaner merge with the new version, we also revert
all patches on top of the LED ones.

This is not a big deal, they are still not pushed to Linus.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 408b651174cf..cc93c16cc822 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -391,7 +391,7 @@ static int ps_battery_get_property(struct power_supply *psy,
 	uint8_t battery_capacity;
 	int battery_status;
 	unsigned long flags;
-	int ret = 0;
+	int ret;
 
 	spin_lock_irqsave(&dev->lock, flags);
 	battery_capacity = dev->battery_capacity;
@@ -416,7 +416,7 @@ static int ps_battery_get_property(struct power_supply *psy,
 		break;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int ps_device_register_battery(struct ps_device *dev)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 02/11] Revert "HID: playstation: report DualSense hardware and firmware version."
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 01/11] Revert "HID: playstation: fix unused variable in ps_battery_get_property." Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 03/11] Revert "HID: playstation: DualSense set LEDs to default player id." Benjamin Tissoires
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

This reverts commit 1f902f8636e4 ("HID: playstation: report DualSense
hardware and firmware version.")

There is currently an ongoing discussion on linux-leds LKML,
and so to give us more room, we need to revert those related
LEDs patches from linux-next.

To have a cleaner merge with the new version, we also revert
all patches on top of the LED ones.

This is not a big deal, they are still not pushed to Linus.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 81 -----------------------------------
 1 file changed, 81 deletions(-)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index cc93c16cc822..973c1fe61e8a 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -41,8 +41,6 @@ struct ps_device {
 	int battery_status;
 
 	uint8_t mac_address[6]; /* Note: stored in little endian order. */
-	uint32_t hw_version;
-	uint32_t fw_version;
 
 	int (*parse_report)(struct ps_device *dev, struct hid_report *report, u8 *data, int size);
 };
@@ -79,8 +77,6 @@ struct ps_led_info {
 #define DS_FEATURE_REPORT_CALIBRATION_SIZE	41
 #define DS_FEATURE_REPORT_PAIRING_INFO		0x09
 #define DS_FEATURE_REPORT_PAIRING_INFO_SIZE	20
-#define DS_FEATURE_REPORT_FIRMWARE_INFO		0x20
-#define DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE	64
 
 /* Button masks for DualSense input report. */
 #define DS_BUTTONS0_HAT_SWITCH	GENMASK(3, 0)
@@ -665,40 +661,6 @@ static struct input_dev *ps_touchpad_create(struct hid_device *hdev, int width,
 	return touchpad;
 }
 
-static ssize_t firmware_version_show(struct device *dev,
-				struct device_attribute
-				*attr, char *buf)
-{
-	struct hid_device *hdev = to_hid_device(dev);
-	struct ps_device *ps_dev = hid_get_drvdata(hdev);
-
-	return sysfs_emit(buf, "0x%08x\n", ps_dev->fw_version);
-}
-
-static DEVICE_ATTR_RO(firmware_version);
-
-static ssize_t hardware_version_show(struct device *dev,
-				struct device_attribute
-				*attr, char *buf)
-{
-	struct hid_device *hdev = to_hid_device(dev);
-	struct ps_device *ps_dev = hid_get_drvdata(hdev);
-
-	return sysfs_emit(buf, "0x%08x\n", ps_dev->hw_version);
-}
-
-static DEVICE_ATTR_RO(hardware_version);
-
-static struct attribute *ps_device_attributes[] = {
-	&dev_attr_firmware_version.attr,
-	&dev_attr_hardware_version.attr,
-	NULL
-};
-
-static const struct attribute_group ps_device_attribute_group = {
-	.attrs = ps_device_attributes,
-};
-
 static int dualsense_get_calibration_data(struct dualsense *ds)
 {
 	short gyro_pitch_bias, gyro_pitch_plus, gyro_pitch_minus;
@@ -789,30 +751,6 @@ static int dualsense_get_calibration_data(struct dualsense *ds)
 	return ret;
 }
 
-static int dualsense_get_firmware_info(struct dualsense *ds)
-{
-	uint8_t *buf;
-	int ret;
-
-	buf = kzalloc(DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_FIRMWARE_INFO, buf,
-			DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE);
-	if (ret) {
-		hid_err(ds->base.hdev, "Failed to retrieve DualSense firmware info: %d\n", ret);
-		goto err_free;
-	}
-
-	ds->base.hw_version = get_unaligned_le32(&buf[24]);
-	ds->base.fw_version = get_unaligned_le32(&buf[28]);
-
-err_free:
-	kfree(buf);
-	return ret;
-}
-
 static int dualsense_get_mac_address(struct dualsense *ds)
 {
 	uint8_t *buf;
@@ -1314,12 +1252,6 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	}
 	snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds->base.mac_address);
 
-	ret = dualsense_get_firmware_info(ds);
-	if (ret) {
-		hid_err(hdev, "Failed to get firmware info from DualSense\n");
-		return ERR_PTR(ret);
-	}
-
 	ret = ps_devices_list_add(ps_dev);
 	if (ret)
 		return ERR_PTR(ret);
@@ -1387,13 +1319,6 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	/* Set player LEDs to our player id. */
 	dualsense_set_player_leds(ds);
 
-	/*
-	 * Reporting hardware and firmware is important as there are frequent updates, which
-	 * can change behavior.
-	 */
-	hid_info(hdev, "Registered DualSense controller hw_version=0x%08x fw_version=0x%08x\n",
-			ds->base.hw_version, ds->base.fw_version);
-
 	return &ds->base;
 
 err:
@@ -1444,12 +1369,6 @@ static int ps_probe(struct hid_device *hdev, const struct hid_device_id *id)
 		}
 	}
 
-	ret = devm_device_add_group(&hdev->dev, &ps_device_attribute_group);
-	if (ret) {
-		hid_err(hdev, "Failed to register sysfs nodes.\n");
-		goto err_close;
-	}
-
 	return ret;
 
 err_close:
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 03/11] Revert "HID: playstation: DualSense set LEDs to default player id."
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 01/11] Revert "HID: playstation: fix unused variable in ps_battery_get_property." Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 02/11] Revert "HID: playstation: report DualSense hardware and firmware version." Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 04/11] Revert "HID: playstation: add DualSense player LEDs support." Benjamin Tissoires
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

This reverts commit 05afe02ac24f ("HID: playstation: DualSense
set LEDs to default player id.")

There is currently an ongoing discussion on linux-leds LKML,
and so to give us more room, we need to revert those related
patches from linux-next.

This is not a big deal, they are still not pushed to Linus.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 70 +----------------------------------
 1 file changed, 1 insertion(+), 69 deletions(-)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 973c1fe61e8a..2d96785c397d 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -9,7 +9,6 @@
 #include <linux/crc32.h>
 #include <linux/device.h>
 #include <linux/hid.h>
-#include <linux/idr.h>
 #include <linux/input/mt.h>
 #include <linux/leds.h>
 #include <linux/led-class-multicolor.h>
@@ -23,8 +22,6 @@
 static DEFINE_MUTEX(ps_devices_lock);
 static LIST_HEAD(ps_devices_list);
 
-static DEFINE_IDA(ps_player_id_allocator);
-
 #define HID_PLAYSTATION_VERSION_PATCH 0x8000
 
 /* Base class for playstation devices. */
@@ -33,8 +30,6 @@ struct ps_device {
 	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;
@@ -326,24 +321,6 @@ 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 = U32_MAX;
-}
-
 static struct input_dev *ps_allocate_input_dev(struct hid_device *hdev, const char *name_suffix)
 {
 	struct input_dev *input_dev;
@@ -1179,29 +1156,6 @@ 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.
-	 */
-	static const 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 % ARRAY_SIZE(player_ids);
-
-	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;
@@ -1310,15 +1264,6 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 			goto err;
 	}
 
-	ret = ps_device_set_player_id(ps_dev);
-	if (ret) {
-		hid_err(hdev, "Failed to assign player id for DualSense: %d\n", ret);
-		goto err;
-	}
-
-	/* Set player LEDs to our player id. */
-	dualsense_set_player_leds(ds);
-
 	return &ds->base;
 
 err:
@@ -1383,7 +1328,6 @@ 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);
@@ -1404,19 +1348,7 @@ static struct hid_driver ps_driver = {
 	.raw_event	= ps_raw_event,
 };
 
-static int __init ps_init(void)
-{
-	return hid_register_driver(&ps_driver);
-}
-
-static void __exit ps_exit(void)
-{
-	hid_unregister_driver(&ps_driver);
-	ida_destroy(&ps_player_id_allocator);
-}
-
-module_init(ps_init);
-module_exit(ps_exit);
+module_hid_driver(ps_driver);
 
 MODULE_AUTHOR("Sony Interactive Entertainment");
 MODULE_DESCRIPTION("HID Driver for PlayStation peripherals.");
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 04/11] Revert "HID: playstation: add DualSense player LEDs support."
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (2 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 03/11] Revert "HID: playstation: DualSense set LEDs to default player id." Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 05/11] Revert "HID: playstation: add microphone mute support for DualSense." Benjamin Tissoires
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

This reverts commit c240f0cb88ec ("HID: playstation: add
DualSense player LEDs support.")

There is currently an ongoing discussion on linux-leds LKML,
and so to give us more room, we need to revert those related
patches from linux-next.

This is not a big deal, they are still not pushed to Linus.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 60 +----------------------------------
 1 file changed, 1 insertion(+), 59 deletions(-)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 2d96785c397d..c436ac8f7a6f 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -112,7 +112,6 @@ struct ps_led_info {
 #define DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE BIT(1)
 #define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE BIT(2)
 #define DS_OUTPUT_VALID_FLAG1_RELEASE_LEDS BIT(3)
-#define DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE BIT(4)
 #define DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE BIT(1)
 #define DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE BIT(4)
 #define DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT BIT(1)
@@ -158,11 +157,6 @@ struct dualsense {
 	bool last_btn_mic_state;
 	struct led_classdev mute_led;
 
-	/* Player leds */
-	bool update_player_leds;
-	uint8_t player_leds_state;
-	struct led_classdev player_leds[5];
-
 	struct work_struct output_worker;
 	void *output_report_dmabuf;
 	uint8_t output_seq; /* Sequence number for output report. */
@@ -784,35 +778,6 @@ static void dualsense_mute_led_set_brightness(struct led_classdev *led, enum led
 
 }
 
-static enum led_brightness dualsense_player_led_get_brightness(struct led_classdev *led)
-{
-	struct hid_device *hdev = to_hid_device(led->dev->parent);
-	struct dualsense *ds = hid_get_drvdata(hdev);
-
-	return !!(ds->player_leds_state & BIT(led - ds->player_leds));
-}
-
-static void dualsense_player_led_set_brightness(struct led_classdev *led, enum led_brightness value)
-{
-	struct hid_device *hdev = to_hid_device(led->dev->parent);
-	struct dualsense *ds = hid_get_drvdata(hdev);
-	unsigned long flags;
-	unsigned int led_index;
-
-	spin_lock_irqsave(&ds->base.lock, flags);
-
-	led_index = led - ds->player_leds;
-	if (value == LED_OFF)
-		ds->player_leds_state &= ~BIT(led_index);
-	else
-		ds->player_leds_state |= BIT(led_index);
-
-	ds->update_player_leds = true;
-	spin_unlock_irqrestore(&ds->base.lock, flags);
-
-	schedule_work(&ds->output_worker);
-}
-
 static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp,
 		void *buf)
 {
@@ -905,13 +870,6 @@ static void dualsense_output_worker(struct work_struct *work)
 		ds->update_lightbar = false;
 	}
 
-	if (ds->update_player_leds) {
-		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE;
-		common->player_leds = ds->player_leds_state;
-
-		ds->update_player_leds = false;
-	}
-
 	if (ds->update_mic_mute) {
 		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE;
 		common->mute_button_led = ds->mic_muted;
@@ -1161,20 +1119,12 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	struct dualsense *ds;
 	struct ps_device *ps_dev;
 	uint8_t max_output_report_size;
-	int i, ret;
+	int ret;
 
 	static const struct ps_led_info mute_led_info = {
 		"micmute", dualsense_mute_led_get_brightness, dualsense_mute_led_set_brightness
 	};
 
-	static const struct ps_led_info player_leds_info[] = {
-		{ "led1", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness },
-		{ "led2", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness },
-		{ "led3", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness },
-		{ "led4", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness },
-		{ "led5", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness }
-	};
-
 	ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return ERR_PTR(-ENOMEM);
@@ -1256,14 +1206,6 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	if (ret)
 		goto err;
 
-	for (i = 0; i < ARRAY_SIZE(player_leds_info); i++) {
-		const struct ps_led_info *led_info = &player_leds_info[i];
-
-		ret = ps_led_register(ps_dev, &ds->player_leds[i], led_info);
-		if (ret < 0)
-			goto err;
-	}
-
 	return &ds->base;
 
 err:
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 05/11] Revert "HID: playstation: add microphone mute support for DualSense."
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (3 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 04/11] Revert "HID: playstation: add DualSense player LEDs support." Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 06/11] Revert "HID: playstation: add DualSense lightbar support" Benjamin Tissoires
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

This reverts commit d5f7af85a537 ("HID: playstation: add microphone
mute support for DualSense.")

There is currently an ongoing discussion on linux-leds LKML,
and so to give us more room, we need to revert those related
patches from linux-next.

This is not a big deal, they are still not pushed to Linus.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/Kconfig           |  2 -
 drivers/hid/hid-playstation.c | 99 -----------------------------------
 2 files changed, 101 deletions(-)

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index aee51d776b4f..e7f17e78ff14 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -857,8 +857,6 @@ config HID_PLAYSTATION
 	tristate "PlayStation HID Driver"
 	depends on HID
 	select CRC32
-	select NEW_LEDS
-	select LEDS_CLASS
 	select LEDS_CLASS_MULTICOLOR
 	select POWER_SUPPLY
 	help
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index c436ac8f7a6f..97c1118ba78f 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -10,7 +10,6 @@
 #include <linux/device.h>
 #include <linux/hid.h>
 #include <linux/input/mt.h>
-#include <linux/leds.h>
 #include <linux/led-class-multicolor.h>
 #include <linux/module.h>
 
@@ -48,12 +47,6 @@ struct ps_calibration_data {
 	int sens_denom;
 };
 
-struct ps_led_info {
-	const char *name;
-	enum led_brightness (*brightness_get)(struct led_classdev *cdev);
-	void (*brightness_set)(struct led_classdev *cdev, enum led_brightness);
-};
-
 /* Seed values for DualShock4 / DualSense CRC32 for different report types. */
 #define PS_INPUT_CRC32_SEED	0xA1
 #define PS_OUTPUT_CRC32_SEED	0xA2
@@ -89,7 +82,6 @@ struct ps_led_info {
 #define DS_BUTTONS1_R3		BIT(7)
 #define DS_BUTTONS2_PS_HOME	BIT(0)
 #define DS_BUTTONS2_TOUCHPAD	BIT(1)
-#define DS_BUTTONS2_MIC_MUTE	BIT(2)
 
 /* Status field of DualSense input report. */
 #define DS_STATUS_BATTERY_CAPACITY	GENMASK(3, 0)
@@ -108,12 +100,9 @@ struct ps_led_info {
 /* Flags for DualSense output report. */
 #define DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION BIT(0)
 #define DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT BIT(1)
-#define DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE BIT(0)
-#define DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE BIT(1)
 #define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE BIT(2)
 #define DS_OUTPUT_VALID_FLAG1_RELEASE_LEDS BIT(3)
 #define DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE BIT(1)
-#define DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE BIT(4)
 #define DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT BIT(1)
 
 /* DualSense hardware limits */
@@ -151,12 +140,6 @@ struct dualsense {
 	uint8_t lightbar_green;
 	uint8_t lightbar_blue;
 
-	/* Microphone */
-	bool update_mic_mute;
-	bool mic_muted;
-	bool last_btn_mic_state;
-	struct led_classdev mute_led;
-
 	struct work_struct output_worker;
 	void *output_report_dmabuf;
 	uint8_t output_seq; /* Sequence number for output report. */
@@ -502,32 +485,6 @@ static int ps_get_report(struct hid_device *hdev, uint8_t report_id, uint8_t *bu
 	return 0;
 }
 
-static int ps_led_register(struct ps_device *ps_dev, struct led_classdev *led,
-		const struct ps_led_info *led_info)
-{
-	int ret;
-
-	led->name = devm_kasprintf(&ps_dev->hdev->dev, GFP_KERNEL,
-			"playstation::%pMR::%s", ps_dev->mac_address, led_info->name);
-
-	if (!led->name)
-		return -ENOMEM;
-
-	led->brightness = 0;
-	led->max_brightness = 1;
-	led->flags = LED_CORE_SUSPENDRESUME;
-	led->brightness_get = led_info->brightness_get;
-	led->brightness_set = led_info->brightness_set;
-
-	ret = devm_led_classdev_register(&ps_dev->hdev->dev, led);
-	if (ret) {
-		hid_err(ps_dev->hdev, "Failed to register LED %s: %d\n", led_info->name, ret);
-		return ret;
-	}
-
-	return 0;
-}
-
 /* Register a DualSense/DualShock4 RGB lightbar represented by a multicolor LED. */
 static int ps_lightbar_register(struct ps_device *ps_dev, struct led_classdev_mc *lightbar_mc_dev,
 	int (*brightness_set)(struct led_classdev *, enum led_brightness))
@@ -765,19 +722,6 @@ static int dualsense_lightbar_set_brightness(struct led_classdev *cdev,
 	return 0;
 }
 
-static enum led_brightness dualsense_mute_led_get_brightness(struct led_classdev *led)
-{
-	struct dualsense *ds = container_of(led, struct dualsense, mute_led);
-
-	return ds->mic_muted;
-}
-
-/* The mute LED is treated as read-only. This set call prevents ENOTSUP errors e.g. on unload. */
-static void dualsense_mute_led_set_brightness(struct led_classdev *led, enum led_brightness value)
-{
-
-}
-
 static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp,
 		void *buf)
 {
@@ -870,23 +814,6 @@ static void dualsense_output_worker(struct work_struct *work)
 		ds->update_lightbar = false;
 	}
 
-	if (ds->update_mic_mute) {
-		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE;
-		common->mute_button_led = ds->mic_muted;
-
-		if (ds->mic_muted) {
-			/* Disable microphone */
-			common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
-			common->power_save_control |= DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE;
-		} else {
-			/* Enable microphone */
-			common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
-			common->power_save_control &= ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE;
-		}
-
-		ds->update_mic_mute = false;
-	}
-
 	spin_unlock_irqrestore(&ds->base.lock, flags);
 
 	dualsense_send_output_report(ds, &report);
@@ -901,7 +828,6 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
 	uint8_t battery_data, battery_capacity, charging_status, value;
 	int battery_status;
 	uint32_t sensor_timestamp;
-	bool btn_mic_state;
 	unsigned long flags;
 	int i;
 
@@ -957,23 +883,6 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
 	input_report_key(ds->gamepad, BTN_MODE,   ds_report->buttons[2] & DS_BUTTONS2_PS_HOME);
 	input_sync(ds->gamepad);
 
-	/*
-	 * The DualSense has an internal microphone, which can be muted through a mute button
-	 * on the device. The driver is expected to read the button state and program the device
-	 * to mute/unmute audio at the hardware level.
-	 */
-	btn_mic_state = !!(ds_report->buttons[2] & DS_BUTTONS2_MIC_MUTE);
-	if (btn_mic_state && !ds->last_btn_mic_state) {
-		spin_lock_irqsave(&ps_dev->lock, flags);
-		ds->update_mic_mute = true;
-		ds->mic_muted = !ds->mic_muted; /* toggle */
-		spin_unlock_irqrestore(&ps_dev->lock, flags);
-
-		/* Schedule updating of microphone state at hardware level. */
-		schedule_work(&ds->output_worker);
-	}
-	ds->last_btn_mic_state = btn_mic_state;
-
 	/* Parse and calibrate gyroscope data. */
 	for (i = 0; i < ARRAY_SIZE(ds_report->gyro); i++) {
 		int raw_data = (short)le16_to_cpu(ds_report->gyro[i]);
@@ -1121,10 +1030,6 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	uint8_t max_output_report_size;
 	int ret;
 
-	static const struct ps_led_info mute_led_info = {
-		"micmute", dualsense_mute_led_get_brightness, dualsense_mute_led_set_brightness
-	};
-
 	ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return ERR_PTR(-ENOMEM);
@@ -1202,10 +1107,6 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	if (ret)
 		goto err;
 
-	ret = ps_led_register(ps_dev, &ds->mute_led, &mute_led_info);
-	if (ret)
-		goto err;
-
 	return &ds->base;
 
 err:
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 06/11] Revert "HID: playstation: add DualSense lightbar support"
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (4 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 05/11] Revert "HID: playstation: add microphone mute support for DualSense." Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 07/11] HID: playstation: report DualSense hardware and firmware version Benjamin Tissoires
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

This reverts commit ebbe998a4a52 ("HID: playstation: add
DualSense lightbar support")

There is currently an ongoing discussion on linux-leds LKML,
and so to give us more room, we need to revert those related
patches from linux-next.

This is not a big deal, they are still not pushed to Linus.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/Kconfig           |   1 -
 drivers/hid/hid-playstation.c | 118 ----------------------------------
 2 files changed, 119 deletions(-)

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index e7f17e78ff14..7ae9eef6ca64 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -857,7 +857,6 @@ config HID_PLAYSTATION
 	tristate "PlayStation HID Driver"
 	depends on HID
 	select CRC32
-	select LEDS_CLASS_MULTICOLOR
 	select POWER_SUPPLY
 	help
 	  Provides support for Sony PS5 controllers including support for
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 97c1118ba78f..64193fdeaa0d 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -10,7 +10,6 @@
 #include <linux/device.h>
 #include <linux/hid.h>
 #include <linux/input/mt.h>
-#include <linux/led-class-multicolor.h>
 #include <linux/module.h>
 
 #include <asm/unaligned.h>
@@ -100,10 +99,6 @@ struct ps_calibration_data {
 /* Flags for DualSense output report. */
 #define DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION BIT(0)
 #define DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT BIT(1)
-#define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE BIT(2)
-#define DS_OUTPUT_VALID_FLAG1_RELEASE_LEDS BIT(3)
-#define DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE BIT(1)
-#define DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT BIT(1)
 
 /* DualSense hardware limits */
 #define DS_ACC_RES_PER_G	8192
@@ -133,13 +128,6 @@ struct dualsense {
 	uint8_t motor_left;
 	uint8_t motor_right;
 
-	/* RGB lightbar */
-	struct led_classdev_mc lightbar;
-	bool update_lightbar;
-	uint8_t lightbar_red;
-	uint8_t lightbar_green;
-	uint8_t lightbar_blue;
-
 	struct work_struct output_worker;
 	void *output_report_dmabuf;
 	uint8_t output_seq; /* Sequence number for output report. */
@@ -485,45 +473,6 @@ static int ps_get_report(struct hid_device *hdev, uint8_t report_id, uint8_t *bu
 	return 0;
 }
 
-/* Register a DualSense/DualShock4 RGB lightbar represented by a multicolor LED. */
-static int ps_lightbar_register(struct ps_device *ps_dev, struct led_classdev_mc *lightbar_mc_dev,
-	int (*brightness_set)(struct led_classdev *, enum led_brightness))
-{
-	struct hid_device *hdev = ps_dev->hdev;
-	struct mc_subled *mc_led_info;
-	struct led_classdev *led_cdev;
-	int ret;
-
-	mc_led_info = devm_kmalloc_array(&hdev->dev, 3, sizeof(*mc_led_info),
-					 GFP_KERNEL | __GFP_ZERO);
-	if (!mc_led_info)
-		return -ENOMEM;
-
-	mc_led_info[0].color_index = LED_COLOR_ID_RED;
-	mc_led_info[1].color_index = LED_COLOR_ID_GREEN;
-	mc_led_info[2].color_index = LED_COLOR_ID_BLUE;
-
-	lightbar_mc_dev->subled_info = mc_led_info;
-	lightbar_mc_dev->num_colors = 3;
-
-	led_cdev = &lightbar_mc_dev->led_cdev;
-	led_cdev->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "playstation::%pMR::rgb",
-			ps_dev->mac_address);
-	if (!led_cdev->name)
-		return -ENOMEM;
-	led_cdev->brightness = 255;
-	led_cdev->max_brightness = 255;
-	led_cdev->brightness_set_blocking = brightness_set;
-
-	ret = devm_led_classdev_multicolor_register(&hdev->dev, lightbar_mc_dev);
-	if (ret < 0) {
-		hid_err(hdev, "Cannot register multicolor LED device\n");
-		return ret;
-	}
-
-	return 0;
-}
-
 static struct input_dev *ps_sensors_create(struct hid_device *hdev, int accel_range, int accel_res,
 		int gyro_range, int gyro_res)
 {
@@ -702,26 +651,6 @@ static int dualsense_get_mac_address(struct dualsense *ds)
 	return ret;
 }
 
-static int dualsense_lightbar_set_brightness(struct led_classdev *cdev,
-	enum led_brightness brightness)
-{
-	struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev);
-	struct dualsense *ds = container_of(mc_cdev, struct dualsense, lightbar);
-	unsigned long flags;
-
-	led_mc_calc_color_components(mc_cdev, brightness);
-
-	spin_lock_irqsave(&ds->base.lock, flags);
-	ds->update_lightbar = true;
-	ds->lightbar_red = mc_cdev->subled_info[0].brightness;
-	ds->lightbar_green = mc_cdev->subled_info[1].brightness;
-	ds->lightbar_blue = mc_cdev->subled_info[2].brightness;
-	spin_unlock_irqrestore(&ds->base.lock, flags);
-
-	schedule_work(&ds->output_worker);
-	return 0;
-}
-
 static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp,
 		void *buf)
 {
@@ -805,15 +734,6 @@ static void dualsense_output_worker(struct work_struct *work)
 		ds->update_rumble = false;
 	}
 
-	if (ds->update_lightbar) {
-		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE;
-		common->lightbar_red = ds->lightbar_red;
-		common->lightbar_green = ds->lightbar_green;
-		common->lightbar_blue = ds->lightbar_blue;
-
-		ds->update_lightbar = false;
-	}
-
 	spin_unlock_irqrestore(&ds->base.lock, flags);
 
 	dualsense_send_output_report(ds, &report);
@@ -998,31 +918,6 @@ static int dualsense_play_effect(struct input_dev *dev, void *data, struct ff_ef
 	return 0;
 }
 
-static int dualsense_reset_leds(struct dualsense *ds)
-{
-	struct dualsense_output_report report;
-	uint8_t *buf;
-
-	buf = kzalloc(sizeof(struct dualsense_output_report_bt), GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	dualsense_init_output_report(ds, &report, buf);
-	/*
-	 * On Bluetooth the DualSense outputs an animation on the lightbar
-	 * during startup and maintains a color afterwards. We need to explicitly
-	 * reconfigure the lightbar before we can do any programming later on.
-	 * In USB the lightbar is not on by default, but redoing the setup there
-	 * doesn't hurt.
-	 */
-	report.common->valid_flag2 = DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE;
-	report.common->lightbar_setup = DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT; /* Fade light out. */
-	dualsense_send_output_report(ds, &report);
-
-	kfree(buf);
-	return 0;
-}
-
 static struct ps_device *dualsense_create(struct hid_device *hdev)
 {
 	struct dualsense *ds;
@@ -1094,19 +989,6 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	if (ret)
 		goto err;
 
-	/*
-	 * The hardware may have control over the LEDs (e.g. in Bluetooth on startup).
-	 * Reset the LEDs (lightbar, mute, player leds), so we can control them
-	 * from software.
-	 */
-	ret = dualsense_reset_leds(ds);
-	if (ret)
-		goto err;
-
-	ret = ps_lightbar_register(ps_dev, &ds->lightbar, dualsense_lightbar_set_brightness);
-	if (ret)
-		goto err;
-
 	return &ds->base;
 
 err:
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 07/11] HID: playstation: report DualSense hardware and firmware version.
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (5 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 06/11] Revert "HID: playstation: add DualSense lightbar support" Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 08/11] HID: playstation: fix unused variable in ps_battery_get_property Benjamin Tissoires
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

Retrieve DualSense hardware and firmware information using a vendor
specific feature report. Report the data through sysfs and also
report using hid_info as there can be signficant differences between
versions.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Reviewed-by: Barnabás Pőcze <pobrn@protonmail.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 81 +++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 64193fdeaa0d..84f484fce1ee 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -34,6 +34,8 @@ struct ps_device {
 	int battery_status;
 
 	uint8_t mac_address[6]; /* Note: stored in little endian order. */
+	uint32_t hw_version;
+	uint32_t fw_version;
 
 	int (*parse_report)(struct ps_device *dev, struct hid_report *report, u8 *data, int size);
 };
@@ -64,6 +66,8 @@ struct ps_calibration_data {
 #define DS_FEATURE_REPORT_CALIBRATION_SIZE	41
 #define DS_FEATURE_REPORT_PAIRING_INFO		0x09
 #define DS_FEATURE_REPORT_PAIRING_INFO_SIZE	20
+#define DS_FEATURE_REPORT_FIRMWARE_INFO		0x20
+#define DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE	64
 
 /* Button masks for DualSense input report. */
 #define DS_BUTTONS0_HAT_SWITCH	GENMASK(3, 0)
@@ -538,6 +542,40 @@ static struct input_dev *ps_touchpad_create(struct hid_device *hdev, int width,
 	return touchpad;
 }
 
+static ssize_t firmware_version_show(struct device *dev,
+				struct device_attribute
+				*attr, char *buf)
+{
+	struct hid_device *hdev = to_hid_device(dev);
+	struct ps_device *ps_dev = hid_get_drvdata(hdev);
+
+	return sysfs_emit(buf, "0x%08x\n", ps_dev->fw_version);
+}
+
+static DEVICE_ATTR_RO(firmware_version);
+
+static ssize_t hardware_version_show(struct device *dev,
+				struct device_attribute
+				*attr, char *buf)
+{
+	struct hid_device *hdev = to_hid_device(dev);
+	struct ps_device *ps_dev = hid_get_drvdata(hdev);
+
+	return sysfs_emit(buf, "0x%08x\n", ps_dev->hw_version);
+}
+
+static DEVICE_ATTR_RO(hardware_version);
+
+static struct attribute *ps_device_attributes[] = {
+	&dev_attr_firmware_version.attr,
+	&dev_attr_hardware_version.attr,
+	NULL
+};
+
+static const struct attribute_group ps_device_attribute_group = {
+	.attrs = ps_device_attributes,
+};
+
 static int dualsense_get_calibration_data(struct dualsense *ds)
 {
 	short gyro_pitch_bias, gyro_pitch_plus, gyro_pitch_minus;
@@ -628,6 +666,30 @@ static int dualsense_get_calibration_data(struct dualsense *ds)
 	return ret;
 }
 
+static int dualsense_get_firmware_info(struct dualsense *ds)
+{
+	uint8_t *buf;
+	int ret;
+
+	buf = kzalloc(DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_FIRMWARE_INFO, buf,
+			DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE);
+	if (ret) {
+		hid_err(ds->base.hdev, "Failed to retrieve DualSense firmware info: %d\n", ret);
+		goto err_free;
+	}
+
+	ds->base.hw_version = get_unaligned_le32(&buf[24]);
+	ds->base.fw_version = get_unaligned_le32(&buf[28]);
+
+err_free:
+	kfree(buf);
+	return ret;
+}
+
 static int dualsense_get_mac_address(struct dualsense *ds)
 {
 	uint8_t *buf;
@@ -956,6 +1018,12 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	}
 	snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds->base.mac_address);
 
+	ret = dualsense_get_firmware_info(ds);
+	if (ret) {
+		hid_err(hdev, "Failed to get firmware info from DualSense\n");
+		return ERR_PTR(ret);
+	}
+
 	ret = ps_devices_list_add(ps_dev);
 	if (ret)
 		return ERR_PTR(ret);
@@ -989,6 +1057,13 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	if (ret)
 		goto err;
 
+	/*
+	 * Reporting hardware and firmware is important as there are frequent updates, which
+	 * can change behavior.
+	 */
+	hid_info(hdev, "Registered DualSense controller hw_version=0x%08x fw_version=0x%08x\n",
+			ds->base.hw_version, ds->base.fw_version);
+
 	return &ds->base;
 
 err:
@@ -1039,6 +1114,12 @@ static int ps_probe(struct hid_device *hdev, const struct hid_device_id *id)
 		}
 	}
 
+	ret = devm_device_add_group(&hdev->dev, &ps_device_attribute_group);
+	if (ret) {
+		hid_err(hdev, "Failed to register sysfs nodes.\n");
+		goto err_close;
+	}
+
 	return ret;
 
 err_close:
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 08/11] HID: playstation: fix unused variable in ps_battery_get_property.
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (6 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 07/11] HID: playstation: report DualSense hardware and firmware version Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 09/11] HID: playstation: add initial DualSense lightbar support Benjamin Tissoires
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

The ret variable in ps_battery_get_property is set in an error path,
but never actually returned. Change the function to return ret.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 84f484fce1ee..f279064e74a5 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -333,7 +333,7 @@ static int ps_battery_get_property(struct power_supply *psy,
 	uint8_t battery_capacity;
 	int battery_status;
 	unsigned long flags;
-	int ret;
+	int ret = 0;
 
 	spin_lock_irqsave(&dev->lock, flags);
 	battery_capacity = dev->battery_capacity;
@@ -358,7 +358,7 @@ static int ps_battery_get_property(struct power_supply *psy,
 		break;
 	}
 
-	return 0;
+	return ret;
 }
 
 static int ps_device_register_battery(struct ps_device *dev)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 09/11] HID: playstation: add initial DualSense lightbar support.
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (7 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 08/11] HID: playstation: fix unused variable in ps_battery_get_property Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 10/11] HID: playstation: add microphone mute support for DualSense Benjamin Tissoires
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

Provide initial support for the DualSense lightbar and configure it
with a default PlayStation blue color.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Reviewed-by: Barnabás Pőcze <pobrn@protonmail.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 65 +++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index f279064e74a5..b141b1be6453 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -103,6 +103,10 @@ struct ps_calibration_data {
 /* Flags for DualSense output report. */
 #define DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION BIT(0)
 #define DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT BIT(1)
+#define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE BIT(2)
+#define DS_OUTPUT_VALID_FLAG1_RELEASE_LEDS BIT(3)
+#define DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE BIT(1)
+#define DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT BIT(1)
 
 /* DualSense hardware limits */
 #define DS_ACC_RES_PER_G	8192
@@ -132,6 +136,12 @@ struct dualsense {
 	uint8_t motor_left;
 	uint8_t motor_right;
 
+	/* RGB lightbar */
+	bool update_lightbar;
+	uint8_t lightbar_red;
+	uint8_t lightbar_green;
+	uint8_t lightbar_blue;
+
 	struct work_struct output_worker;
 	void *output_report_dmabuf;
 	uint8_t output_seq; /* Sequence number for output report. */
@@ -796,6 +806,15 @@ static void dualsense_output_worker(struct work_struct *work)
 		ds->update_rumble = false;
 	}
 
+	if (ds->update_lightbar) {
+		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE;
+		common->lightbar_red = ds->lightbar_red;
+		common->lightbar_green = ds->lightbar_green;
+		common->lightbar_blue = ds->lightbar_blue;
+
+		ds->update_lightbar = false;
+	}
+
 	spin_unlock_irqrestore(&ds->base.lock, flags);
 
 	dualsense_send_output_report(ds, &report);
@@ -980,6 +999,41 @@ static int dualsense_play_effect(struct input_dev *dev, void *data, struct ff_ef
 	return 0;
 }
 
+static int dualsense_reset_leds(struct dualsense *ds)
+{
+	struct dualsense_output_report report;
+	uint8_t *buf;
+
+	buf = kzalloc(sizeof(struct dualsense_output_report_bt), GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	dualsense_init_output_report(ds, &report, buf);
+	/*
+	 * On Bluetooth the DualSense outputs an animation on the lightbar
+	 * during startup and maintains a color afterwards. We need to explicitly
+	 * reconfigure the lightbar before we can do any programming later on.
+	 * In USB the lightbar is not on by default, but redoing the setup there
+	 * doesn't hurt.
+	 */
+	report.common->valid_flag2 = DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE;
+	report.common->lightbar_setup = DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT; /* Fade light out. */
+	dualsense_send_output_report(ds, &report);
+
+	kfree(buf);
+	return 0;
+}
+
+static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue)
+{
+	ds->update_lightbar = true;
+	ds->lightbar_red = red;
+	ds->lightbar_green = green;
+	ds->lightbar_blue = blue;
+
+	schedule_work(&ds->output_worker);
+}
+
 static struct ps_device *dualsense_create(struct hid_device *hdev)
 {
 	struct dualsense *ds;
@@ -1057,6 +1111,17 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	if (ret)
 		goto err;
 
+	/*
+	 * The hardware may have control over the LEDs (e.g. in Bluetooth on startup).
+	 * Reset the LEDs (lightbar, mute, player leds), so we can control them
+	 * from software.
+	 */
+	ret = dualsense_reset_leds(ds);
+	if (ret)
+		goto err;
+
+	dualsense_set_lightbar(ds, 0, 0, 128); /* blue */
+
 	/*
 	 * Reporting hardware and firmware is important as there are frequent updates, which
 	 * can change behavior.
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 10/11] HID: playstation: add microphone mute support for DualSense.
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (8 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 09/11] HID: playstation: add initial DualSense lightbar support Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:31 ` [PATCH 11/11] HID: playstation: add DualSense player LED support Benjamin Tissoires
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

The DualSense controller has a built-in microphone exposed as an
audio device over USB (or HID using Bluetooth). A dedicated
button on the controller handles mute, but software has to configure
the device to mute the audio stream.

This patch captures the mute button and schedules an output report
to mute/unmute the audio stream as well as toggle the mute LED.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Reviewed-by: Barnabás Pőcze <pobrn@protonmail.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 44 +++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index b141b1be6453..04743fa0e03d 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -85,6 +85,7 @@ struct ps_calibration_data {
 #define DS_BUTTONS1_R3		BIT(7)
 #define DS_BUTTONS2_PS_HOME	BIT(0)
 #define DS_BUTTONS2_TOUCHPAD	BIT(1)
+#define DS_BUTTONS2_MIC_MUTE	BIT(2)
 
 /* Status field of DualSense input report. */
 #define DS_STATUS_BATTERY_CAPACITY	GENMASK(3, 0)
@@ -103,9 +104,12 @@ struct ps_calibration_data {
 /* Flags for DualSense output report. */
 #define DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION BIT(0)
 #define DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT BIT(1)
+#define DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE BIT(0)
+#define DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE BIT(1)
 #define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE BIT(2)
 #define DS_OUTPUT_VALID_FLAG1_RELEASE_LEDS BIT(3)
 #define DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE BIT(1)
+#define DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE BIT(4)
 #define DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT BIT(1)
 
 /* DualSense hardware limits */
@@ -142,6 +146,11 @@ struct dualsense {
 	uint8_t lightbar_green;
 	uint8_t lightbar_blue;
 
+	/* Microphone */
+	bool update_mic_mute;
+	bool mic_muted;
+	bool last_btn_mic_state;
+
 	struct work_struct output_worker;
 	void *output_report_dmabuf;
 	uint8_t output_seq; /* Sequence number for output report. */
@@ -815,6 +824,23 @@ static void dualsense_output_worker(struct work_struct *work)
 		ds->update_lightbar = false;
 	}
 
+	if (ds->update_mic_mute) {
+		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE;
+		common->mute_button_led = ds->mic_muted;
+
+		if (ds->mic_muted) {
+			/* Disable microphone */
+			common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
+			common->power_save_control |= DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE;
+		} else {
+			/* Enable microphone */
+			common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
+			common->power_save_control &= ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE;
+		}
+
+		ds->update_mic_mute = false;
+	}
+
 	spin_unlock_irqrestore(&ds->base.lock, flags);
 
 	dualsense_send_output_report(ds, &report);
@@ -829,6 +855,7 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
 	uint8_t battery_data, battery_capacity, charging_status, value;
 	int battery_status;
 	uint32_t sensor_timestamp;
+	bool btn_mic_state;
 	unsigned long flags;
 	int i;
 
@@ -884,6 +911,23 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
 	input_report_key(ds->gamepad, BTN_MODE,   ds_report->buttons[2] & DS_BUTTONS2_PS_HOME);
 	input_sync(ds->gamepad);
 
+	/*
+	 * The DualSense has an internal microphone, which can be muted through a mute button
+	 * on the device. The driver is expected to read the button state and program the device
+	 * to mute/unmute audio at the hardware level.
+	 */
+	btn_mic_state = !!(ds_report->buttons[2] & DS_BUTTONS2_MIC_MUTE);
+	if (btn_mic_state && !ds->last_btn_mic_state) {
+		spin_lock_irqsave(&ps_dev->lock, flags);
+		ds->update_mic_mute = true;
+		ds->mic_muted = !ds->mic_muted; /* toggle */
+		spin_unlock_irqrestore(&ps_dev->lock, flags);
+
+		/* Schedule updating of microphone state at hardware level. */
+		schedule_work(&ds->output_worker);
+	}
+	ds->last_btn_mic_state = btn_mic_state;
+
 	/* Parse and calibrate gyroscope data. */
 	for (i = 0; i < ARRAY_SIZE(ds_report->gyro); i++) {
 		int raw_data = (short)le16_to_cpu(ds_report->gyro[i]);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 11/11] HID: playstation: add DualSense player LED support.
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (9 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 10/11] HID: playstation: add microphone mute support for DualSense Benjamin Tissoires
@ 2021-02-17 17:31 ` Benjamin Tissoires
  2021-02-17 17:43 ` [PATCH 00/11] HID: playstation: revert LED class exposure Pavel Machek
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 17:31 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: linux-input, linux-leds, linux-kernel, Benjamin Tissoires

From: Roderick Colenbrander <roderick.colenbrander@sony.com>

The DualSense features 5 player LEDs below its touchpad, which are
meant as player id indications. The LEDs are configured with a
player ID determined by an ID allocator, which assign player ids
to ps_device instances.

This patch is a combination of the following original patches
minus use of LED framework APIs:
- HID: playstation: add DualSense player LEDs support.
- HID: playstation: DualSense set LEDs to default player id.

Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
Reviewed-by: Barnabás Pőcze <pobrn@protonmail.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-playstation.c | 83 ++++++++++++++++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 04743fa0e03d..7f65d30ca77c 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -9,6 +9,7 @@
 #include <linux/crc32.h>
 #include <linux/device.h>
 #include <linux/hid.h>
+#include <linux/idr.h>
 #include <linux/input/mt.h>
 #include <linux/module.h>
 
@@ -20,6 +21,8 @@
 static DEFINE_MUTEX(ps_devices_lock);
 static LIST_HEAD(ps_devices_list);
 
+static DEFINE_IDA(ps_player_id_allocator);
+
 #define HID_PLAYSTATION_VERSION_PATCH 0x8000
 
 /* Base class for playstation devices. */
@@ -28,6 +31,8 @@ struct ps_device {
 	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;
@@ -108,6 +113,7 @@ struct ps_calibration_data {
 #define DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE BIT(1)
 #define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE BIT(2)
 #define DS_OUTPUT_VALID_FLAG1_RELEASE_LEDS BIT(3)
+#define DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE BIT(4)
 #define DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE BIT(1)
 #define DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE BIT(4)
 #define DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT BIT(1)
@@ -151,6 +157,11 @@ struct dualsense {
 	bool mic_muted;
 	bool last_btn_mic_state;
 
+	/* Player leds */
+	bool update_player_leds;
+	uint8_t player_leds_state;
+	struct led_classdev player_leds[5];
+
 	struct work_struct output_worker;
 	void *output_report_dmabuf;
 	uint8_t output_seq; /* Sequence number for output report. */
@@ -309,6 +320,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 = U32_MAX;
+}
+
 static struct input_dev *ps_allocate_input_dev(struct hid_device *hdev, const char *name_suffix)
 {
 	struct input_dev *input_dev;
@@ -824,6 +853,13 @@ static void dualsense_output_worker(struct work_struct *work)
 		ds->update_lightbar = false;
 	}
 
+	if (ds->update_player_leds) {
+		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE;
+		common->player_leds = ds->player_leds_state;
+
+		ds->update_player_leds = false;
+	}
+
 	if (ds->update_mic_mute) {
 		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE;
 		common->mute_button_led = ds->mic_muted;
@@ -1078,6 +1114,29 @@ static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t gr
 	schedule_work(&ds->output_worker);
 }
 
+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.
+	 */
+	static const 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 % ARRAY_SIZE(player_ids);
+
+	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;
@@ -1166,6 +1225,15 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 
 	dualsense_set_lightbar(ds, 0, 0, 128); /* blue */
 
+	ret = ps_device_set_player_id(ps_dev);
+	if (ret) {
+		hid_err(hdev, "Failed to assign player id for DualSense: %d\n", ret);
+		goto err;
+	}
+
+	/* Set player LEDs to our player id. */
+	dualsense_set_player_leds(ds);
+
 	/*
 	 * Reporting hardware and firmware is important as there are frequent updates, which
 	 * can change behavior.
@@ -1243,6 +1311,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);
@@ -1263,7 +1332,19 @@ static struct hid_driver ps_driver = {
 	.raw_event	= ps_raw_event,
 };
 
-module_hid_driver(ps_driver);
+static int __init ps_init(void)
+{
+	return hid_register_driver(&ps_driver);
+}
+
+static void __exit ps_exit(void)
+{
+	hid_unregister_driver(&ps_driver);
+	ida_destroy(&ps_player_id_allocator);
+}
+
+module_init(ps_init);
+module_exit(ps_exit);
 
 MODULE_AUTHOR("Sony Interactive Entertainment");
 MODULE_DESCRIPTION("HID Driver for PlayStation peripherals.");
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 00/11] HID: playstation: revert LED class exposure
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (10 preceding siblings ...)
  2021-02-17 17:31 ` [PATCH 11/11] HID: playstation: add DualSense player LED support Benjamin Tissoires
@ 2021-02-17 17:43 ` Pavel Machek
  2021-02-18  8:22 ` Jiri Kosina
  2021-02-18 16:46 ` Benjamin Tissoires
  13 siblings, 0 replies; 15+ messages in thread
From: Pavel Machek @ 2021-02-17 17:43 UTC (permalink / raw)
  To: Benjamin Tissoires
  Cc: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze,
	linux-input, linux-leds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

On Wed 2021-02-17 18:31:47, Benjamin Tissoires wrote:
> [sending those patches on behalf of Roderick]
> 
> There is a current thread on LED LKML which basically means that
> we have to revert the LED class exposure until things are settled.
> 
> I am sending here the full series that will end up in linux-next.
> But with some git magic, the final PR to Linus will not have the
> reverts in it, just the plain patches.

Thank you!
									Pavel
									
-- 
http://www.livejournal.com/~pavelmachek

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 00/11] HID: playstation: revert LED class exposure
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (11 preceding siblings ...)
  2021-02-17 17:43 ` [PATCH 00/11] HID: playstation: revert LED class exposure Pavel Machek
@ 2021-02-18  8:22 ` Jiri Kosina
  2021-02-18 16:46 ` Benjamin Tissoires
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Kosina @ 2021-02-18  8:22 UTC (permalink / raw)
  To: Benjamin Tissoires
  Cc: Roderick Colenbrander, Barnabás Pőcze, linux-input,
	linux-leds, linux-kernel

On Wed, 17 Feb 2021, Benjamin Tissoires wrote:

> [sending those patches on behalf of Roderick]
> 
> There is a current thread on LED LKML which basically means that
> we have to revert the LED class exposure until things are settled.
> 
> I am sending here the full series that will end up in linux-next.
> But with some git magic, the final PR to Linus will not have the
> reverts in it, just the plain patches.
> 
> I am queuing in for-5.12/playstation patches 1 to 6 immediately
> (the reverts).
> 
> I am also queuing in for-5.12/playstation-v2 patches 7 and 8 on
> top of 51151098d7ab8 immediately. Those 2 patches have already
> been reviewed the usual process.
> 
> I am waiting 1 day for others to chime in regarding patches 9 to
> 11 before applying them to for-5.12/playstation-v2. They are
> basically the same patches that were already reviewed on the
> linux-input LKML, but without the LED class bits.

FWIW, as discussed elsewhere, I am fully in favor of this solution. 
Thanks!

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 00/11] HID: playstation: revert LED class exposure
  2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
                   ` (12 preceding siblings ...)
  2021-02-18  8:22 ` Jiri Kosina
@ 2021-02-18 16:46 ` Benjamin Tissoires
  13 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2021-02-18 16:46 UTC (permalink / raw)
  To: Jiri Kosina, Roderick Colenbrander, Barnabás Pőcze
  Cc: open list:HID CORE LAYER, linux-leds, lkml

On Wed, Feb 17, 2021 at 6:32 PM Benjamin Tissoires
<benjamin.tissoires@redhat.com> wrote:
>
> [sending those patches on behalf of Roderick]
>
> There is a current thread on LED LKML which basically means that
> we have to revert the LED class exposure until things are settled.
>
> I am sending here the full series that will end up in linux-next.
> But with some git magic, the final PR to Linus will not have the
> reverts in it, just the plain patches.
>
> I am queuing in for-5.12/playstation patches 1 to 6 immediately
> (the reverts).
>
> I am also queuing in for-5.12/playstation-v2 patches 7 and 8 on
> top of 51151098d7ab8 immediately. Those 2 patches have already
> been reviewed the usual process.
>
> I am waiting 1 day for others to chime in regarding patches 9 to
> 11 before applying them to for-5.12/playstation-v2. They are
> basically the same patches that were already reviewed on the
> linux-input LKML, but without the LED class bits.

And I just pushed those 3 patches to for-5.12/playstation-v2.

Cheers,
Benjamin

>
> With all that, we should have more room to discuss the exposure
> of the LEDs to userspace through the LED class.
>
> Roderick, I made small adjustments compared to the series you sent
> me privately:
> - added the 2 missing reverts/re-add, so I can have clean merges
>   for our for-next branch,
> - re-ordered the `if (ds->update_rumble)` block in
>   `dualsense_output_worker()` to match was was in linux-next
> - removed an extra new line to match the current linux-next tree.
>
> Cheers,
> Benjamin
>
> Benjamin Tissoires (2):
>   Revert "HID: playstation: fix unused variable in
>     ps_battery_get_property."
>   Revert "HID: playstation: report DualSense hardware and firmware
>     version."
>
> Roderick Colenbrander (9):
>   Revert "HID: playstation: DualSense set LEDs to default player id."
>   Revert "HID: playstation: add DualSense player LEDs support."
>   Revert "HID: playstation: add microphone mute support for DualSense."
>   Revert "HID: playstation: add DualSense lightbar support"
>   HID: playstation: report DualSense hardware and firmware version.
>   HID: playstation: fix unused variable in ps_battery_get_property.
>   HID: playstation: add initial DualSense lightbar support.
>   HID: playstation: add microphone mute support for DualSense.
>   HID: playstation: add DualSense player LED support.
>
>  drivers/hid/Kconfig           |   3 -
>  drivers/hid/hid-playstation.c | 177 +++-------------------------------
>  2 files changed, 12 insertions(+), 168 deletions(-)
>
> --
> 2.29.2
>


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-02-18 16:59 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-17 17:31 [PATCH 00/11] HID: playstation: revert LED class exposure Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 01/11] Revert "HID: playstation: fix unused variable in ps_battery_get_property." Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 02/11] Revert "HID: playstation: report DualSense hardware and firmware version." Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 03/11] Revert "HID: playstation: DualSense set LEDs to default player id." Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 04/11] Revert "HID: playstation: add DualSense player LEDs support." Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 05/11] Revert "HID: playstation: add microphone mute support for DualSense." Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 06/11] Revert "HID: playstation: add DualSense lightbar support" Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 07/11] HID: playstation: report DualSense hardware and firmware version Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 08/11] HID: playstation: fix unused variable in ps_battery_get_property Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 09/11] HID: playstation: add initial DualSense lightbar support Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 10/11] HID: playstation: add microphone mute support for DualSense Benjamin Tissoires
2021-02-17 17:31 ` [PATCH 11/11] HID: playstation: add DualSense player LED support Benjamin Tissoires
2021-02-17 17:43 ` [PATCH 00/11] HID: playstation: revert LED class exposure Pavel Machek
2021-02-18  8:22 ` Jiri Kosina
2021-02-18 16:46 ` Benjamin Tissoires

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.