From patchwork Wed Feb 17 17:31:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B5C1C433E0 for ; Wed, 17 Feb 2021 17:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D175564DCF for ; Wed, 17 Feb 2021 17:35:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234504AbhBQRep (ORCPT ); Wed, 17 Feb 2021 12:34:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25376 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234505AbhBQRdh (ORCPT ); Wed, 17 Feb 2021 12:33:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L/SLrY6Dr+of38vaWIpXiDXossh0WQU+rKd8tehKfFM=; b=RgGXo6qH91KwuQDs/n/jJOuP3cuq62DJ5pOuSPjFQEgkRMjHxK38rtHn4fm0+jaih6fBw9 GIgkurcHYw901V4e0jknn6rXm7Q9qA/UMzFvF4PJlhRPvIxTDAYSQrKtBLu06G57NgZm0H 6TTMBi4uu/XiPj+wO1X3JPTkg06QRUk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-Hx6TvH97OWiz_Mz-iszgTg-1; Wed, 17 Feb 2021 12:32:09 -0500 X-MC-Unique: Hx6TvH97OWiz_Mz-iszgTg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9CF23192CC55; Wed, 17 Feb 2021 17:32:06 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED2DA60C61; Wed, 17 Feb 2021 17:32:04 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 01/11] Revert "HID: playstation: fix unused variable in ps_battery_get_property." Date: Wed, 17 Feb 2021 18:31:48 +0100 Message-Id: <20210217173158.3122868-2-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 --- 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) From patchwork Wed Feb 17 17:31:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 571B7C4332D for ; Wed, 17 Feb 2021 17:35:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F74364EAF for ; Wed, 17 Feb 2021 17:35:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234446AbhBQRfR (ORCPT ); Wed, 17 Feb 2021 12:35:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22301 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234508AbhBQRdj (ORCPT ); Wed, 17 Feb 2021 12:33:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SalQoALVHWSDBuvFSejJz/dq2scECkvrFLmS0/hjb/M=; b=TtcFxgPxNj40BI8efzz88wlBY2sQawQWedYS05Bl0T3Kum4aFvOaHiRpa9mUoI3tUWwsiW lJZdVCTASe4iaRkurW4cngUfTTUUcWDfYFyCxEBe342e00VJO6dvgka3hKFkBNS+dvfRHU p+81XJFcVoUZwhsqk9VhVZ4/3CCB2U8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-86Izz6vOOhCf-8zeXlbJUw-1; Wed, 17 Feb 2021 12:32:10 -0500 X-MC-Unique: 86Izz6vOOhCf-8zeXlbJUw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0E63835E22; Wed, 17 Feb 2021 17:32:08 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id F24C360C61; Wed, 17 Feb 2021 17:32:06 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 02/11] Revert "HID: playstation: report DualSense hardware and firmware version." Date: Wed, 17 Feb 2021 18:31:49 +0100 Message-Id: <20210217173158.3122868-3-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 --- 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: From patchwork Wed Feb 17 17:31:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FCC5C433E9 for ; Wed, 17 Feb 2021 17:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F778600CF for ; Wed, 17 Feb 2021 17:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234443AbhBQRe7 (ORCPT ); Wed, 17 Feb 2021 12:34:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54699 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234519AbhBQRdn (ORCPT ); Wed, 17 Feb 2021 12:33:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sDTOgUIEuEM7FQrqTpcMCOXLpfzqhPkgfJcNxhVfhqQ=; b=OXQJH/ckAo1J1fEezrpsypEGu+NoblzfPvsd5Pa5YK3QQ47eqNvJxp9JnDNhCpzGSBPx3u /T1d7PIOS0infv4JNtGKR7j6cC/rLGLRU7a3WRQ7bdDTlNiiQSk63WMg1NbXM31MU01wg5 V5YLcHaXdXi35NzOI0eT0xmjjXivQlw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-562-S1I1SHYVMda519shZ8CrPQ-1; Wed, 17 Feb 2021 12:32:12 -0500 X-MC-Unique: S1I1SHYVMda519shZ8CrPQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A646A192CC40; Wed, 17 Feb 2021 17:32:10 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0196F60C61; Wed, 17 Feb 2021 17:32:08 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 03/11] Revert "HID: playstation: DualSense set LEDs to default player id." Date: Wed, 17 Feb 2021 18:31:50 +0100 Message-Id: <20210217173158.3122868-4-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Signed-off-by: Benjamin Tissoires --- 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 #include #include -#include #include #include #include @@ -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."); From patchwork Wed Feb 17 17:31:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384640 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EB89C43381 for ; Wed, 17 Feb 2021 17:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70FD064DCF for ; Wed, 17 Feb 2021 17:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234496AbhBQRfD (ORCPT ); Wed, 17 Feb 2021 12:35:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28307 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234517AbhBQRdn (ORCPT ); Wed, 17 Feb 2021 12:33:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oHL7SKw9vvLF4yISsj7spnDs+0ju5Qgji3y4L4bOR7Q=; b=cbHBDwhPzBhC57OOVywdjSe4MhnrSDXYSXmNwboBMUxfjn+NnoW9QjpYs9rgdYlXjU/pWb 7tTdXhOQsACRNFyFvFaUmzY04Mz820yP5UYw+B+G8Xhf+aI9RmbmD6hoMkzQwBlVTbH9nU vaWUQMdPwyiPgDvl6n6nMdV8eeld2Tk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-dCO1wbdNPNqRFHuJsHouHA-1; Wed, 17 Feb 2021 12:32:14 -0500 X-MC-Unique: dCO1wbdNPNqRFHuJsHouHA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ACBF2835E28; Wed, 17 Feb 2021 17:32:12 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0723F60C61; Wed, 17 Feb 2021 17:32:10 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 04/11] Revert "HID: playstation: add DualSense player LEDs support." Date: Wed, 17 Feb 2021 18:31:51 +0100 Message-Id: <20210217173158.3122868-5-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Signed-off-by: Benjamin Tissoires --- 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: From patchwork Wed Feb 17 17:31:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13C56C433E0 for ; Wed, 17 Feb 2021 17:35:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC8B760C3E for ; Wed, 17 Feb 2021 17:35:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234516AbhBQRfI (ORCPT ); Wed, 17 Feb 2021 12:35:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34284 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234522AbhBQRds (ORCPT ); Wed, 17 Feb 2021 12:33:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=54eTaxqhuG8tNqKX5nc9nYgPl0Sz+nMYu04XxF9V+rA=; b=TsNfALgxfeov4hoIRZq7i340RACANMyN4EwB8axkWWfA6wMerWOfdAmm5KrZ8Ai1mJV9zs 7vGu3DgoN9BdxOydWzvktwwgR09DIhbrnzRaFdMEOSUE6gylHYmpQKYZhASzqpyC/h84mL StjVSkDmXXDbiryGaV61LDtig4u08k0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-481-fwMzh9K0O56Js6C0zOl5Xg-1; Wed, 17 Feb 2021 12:32:16 -0500 X-MC-Unique: fwMzh9K0O56Js6C0zOl5Xg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B558A192CC42; Wed, 17 Feb 2021 17:32:14 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E0BB60C61; Wed, 17 Feb 2021 17:32:12 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 05/11] Revert "HID: playstation: add microphone mute support for DualSense." Date: Wed, 17 Feb 2021 18:31:52 +0100 Message-Id: <20210217173158.3122868-6-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Signed-off-by: Benjamin Tissoires --- 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 #include #include -#include #include #include @@ -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: From patchwork Wed Feb 17 17:31:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE867C433DB for ; Wed, 17 Feb 2021 17:36:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B98B960C3E for ; Wed, 17 Feb 2021 17:36:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234458AbhBQRfo (ORCPT ); Wed, 17 Feb 2021 12:35:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33499 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234533AbhBQRdw (ORCPT ); Wed, 17 Feb 2021 12:33:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g1ddvgYZOFZVK7/IBzi4i+hpKLqhBihRi2iOVvbUUQM=; b=OH724V0YcvdP14pHOqW1MVrDMEHTzDoVT2BkAAOl8FksCZ/C3V8A1zE4YRHchddqzkgzr2 McUHzSVY2E5Z3pUpkx2Y9tpmumFbaWBEfjfMc89BQQLeVLHwUCrY1JketfM3gX/2MoAFaV 2XRdsftqS1iHwRIU4E+RTqwPZjo9uQY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-pGpklSFMPk-Gf88Z96AGjQ-1; Wed, 17 Feb 2021 12:32:19 -0500 X-MC-Unique: pGpklSFMPk-Gf88Z96AGjQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94D01192CC42; Wed, 17 Feb 2021 17:32:18 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 166E160C61; Wed, 17 Feb 2021 17:32:14 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 06/11] Revert "HID: playstation: add DualSense lightbar support" Date: Wed, 17 Feb 2021 18:31:53 +0100 Message-Id: <20210217173158.3122868-7-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Signed-off-by: Benjamin Tissoires --- 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 #include #include -#include #include #include @@ -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: From patchwork Wed Feb 17 17:31:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA606C433E9 for ; Wed, 17 Feb 2021 17:36:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87CB960C3E for ; Wed, 17 Feb 2021 17:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234498AbhBQRfq (ORCPT ); Wed, 17 Feb 2021 12:35:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24714 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234469AbhBQRdx (ORCPT ); Wed, 17 Feb 2021 12:33:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ybFvUxcR//kDarBM6awWL2j71GwnzCbGvA+DvUqEZKw=; b=QXWr57NZ6i0xP9BPzNoTbLYX/EiZ8bMXL0d/TghiNk1x+gf9yfKUFD2mbkz20PMUG1jQ4B Fx0OJyO+5ypzlq0VXv4dMZFnZC7yhGlFIr/1Y52KPDZNOtOtqqtlV15+h820C2pFWDIwzR FdWOAtX898Ntz6pds+NUCcDMz7sWqRk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-6WG-x0ICOT-Vl-3ZcOOZfw-1; Wed, 17 Feb 2021 12:32:25 -0500 X-MC-Unique: 6WG-x0ICOT-Vl-3ZcOOZfw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0F8B801976; Wed, 17 Feb 2021 17:32:23 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id E962E60C61; Wed, 17 Feb 2021 17:32:18 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 07/11] HID: playstation: report DualSense hardware and firmware version. Date: Wed, 17 Feb 2021 18:31:54 +0100 Message-Id: <20210217173158.3122868-8-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Reviewed-by: Barnabás Pőcze Signed-off-by: Benjamin Tissoires --- 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: From patchwork Wed Feb 17 17:31:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CD87C43381 for ; Wed, 17 Feb 2021 17:36:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0376264E4D for ; Wed, 17 Feb 2021 17:36:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234531AbhBQRf7 (ORCPT ); Wed, 17 Feb 2021 12:35:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31387 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234537AbhBQRd5 (ORCPT ); Wed, 17 Feb 2021 12:33:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Umkkn1s1heqSfUE9bVr0PbKoq2Y4J9beIKh4Qxtjpc=; b=Fj2HVQokO9IUrW7j7uPup0f6goTAk399uQjEJJWXP9ytAhRwXItoNG+NJdiMrmKNg3i6WR 4c00qRbKMovRCcPaW/vnX3vW4IxE/hNeq01ilCXuG3PQsT/YsYHOik6yC9fBTYQfvxLg+Q 9r2G4NckPB4dFgzgvBfQcFAhQW+fyD4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-hK0Mxl0YOCSg5UbiiPDWOA-1; Wed, 17 Feb 2021 12:32:27 -0500 X-MC-Unique: hK0Mxl0YOCSg5UbiiPDWOA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C91F91020C21; Wed, 17 Feb 2021 17:32:25 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23DCD60C62; Wed, 17 Feb 2021 17:32:23 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 08/11] HID: playstation: fix unused variable in ps_battery_get_property. Date: Wed, 17 Feb 2021 18:31:55 +0100 Message-Id: <20210217173158.3122868-9-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Signed-off-by: Roderick Colenbrander Signed-off-by: Benjamin Tissoires --- 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) From patchwork Wed Feb 17 17:31:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384636 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65202C433E0 for ; Wed, 17 Feb 2021 17:37:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E2DD64E4B for ; Wed, 17 Feb 2021 17:37:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233886AbhBQRgg (ORCPT ); Wed, 17 Feb 2021 12:36:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21160 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234542AbhBQReB (ORCPT ); Wed, 17 Feb 2021 12:34:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5VLHujtLzR88HOeM8BSi0d3rQM8u5L0kcBDkFTPR1N4=; b=Me/zozCRm+x84uaZCu7kHNYJzkVCrOH9uDdRWC9tkj3t1HfqihtU2fkHinMmfE7POrNTDJ MHEgowY79cLcCSkXC1w7ZGJq5uL/0Jvl/HH9V3temnQWc+3Tc0acVL4SY0RnA4CI4gYw5z SxOVtgdamHg00bj3u0KgMKxpVwMfKNo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-PZM0Dt9WOeSjZO8zuYAnBQ-1; Wed, 17 Feb 2021 12:32:29 -0500 X-MC-Unique: PZM0Dt9WOeSjZO8zuYAnBQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5DAA1020C22; Wed, 17 Feb 2021 17:32:27 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4305960C61; Wed, 17 Feb 2021 17:32:25 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 09/11] HID: playstation: add initial DualSense lightbar support. Date: Wed, 17 Feb 2021 18:31:56 +0100 Message-Id: <20210217173158.3122868-10-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander Provide initial support for the DualSense lightbar and configure it with a default PlayStation blue color. Signed-off-by: Roderick Colenbrander Reviewed-by: Barnabás Pőcze Signed-off-by: Benjamin Tissoires --- 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. From patchwork Wed Feb 17 17:31:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A23DAC4332B for ; Wed, 17 Feb 2021 17:36:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8464764E4B for ; Wed, 17 Feb 2021 17:36:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234480AbhBQRgL (ORCPT ); Wed, 17 Feb 2021 12:36:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54380 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234539AbhBQReA (ORCPT ); Wed, 17 Feb 2021 12:34:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZqUM20Jnpq/LUhZZfBQ2FAbfuIXf/VVhp2IoFI1zVAE=; b=FtH+u2qN6kaDz0sH4RI5lTbggH9asUVBBCdo24DQgZZ/vZ06xGWeiw1v0BkgzoON/ved47 c+XBhs/GCt2nh0NK5lVuKCUMwgyq5cTRh7Oh0+F+RWrLswTxJvn39ElWZBAp9wkWtiwMSz 9KVvYa1FXNK+SBY3D1/vVmS/U0XXMMA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-599-Sa7LZTvfNCm7EfEkhmSyjg-1; Wed, 17 Feb 2021 12:32:31 -0500 X-MC-Unique: Sa7LZTvfNCm7EfEkhmSyjg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9C051020C20; Wed, 17 Feb 2021 17:32:29 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45E5060C61; Wed, 17 Feb 2021 17:32:28 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 10/11] HID: playstation: add microphone mute support for DualSense. Date: Wed, 17 Feb 2021 18:31:57 +0100 Message-Id: <20210217173158.3122868-11-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Reviewed-by: Barnabás Pőcze Signed-off-by: Benjamin Tissoires --- 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]); From patchwork Wed Feb 17 17:31:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 384123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E93ACC433E6 for ; Wed, 17 Feb 2021 17:36:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2E3164E58 for ; Wed, 17 Feb 2021 17:36:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231751AbhBQRgP (ORCPT ); Wed, 17 Feb 2021 12:36:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38717 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234485AbhBQReH (ORCPT ); Wed, 17 Feb 2021 12:34:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613583160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DvzCLbkZPIfmQKREojXO4UFklSzcbb7BeVXTml1eNwg=; b=TdzLY5D2Fz7hfqqYw5fXiZlx4+ICVJVjm1k8K0acXHGyuX22tlgFmyajHL3OgkNNeUafvn K2obNzKWcyS3g9W/PDG8PE5hCyJICHRkSy1T2iPW0NHg21bJ9zPMEdSu4aGcFgcXRKWfns tMmxTZk7efv/HesRFbJgyqV4C2jfqFk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219-UNrBIJHDNjCF7EOmiJaosQ-1; Wed, 17 Feb 2021 12:32:36 -0500 X-MC-Unique: UNrBIJHDNjCF7EOmiJaosQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE42380364F; Wed, 17 Feb 2021 17:32:34 +0000 (UTC) Received: from plouf.redhat.com (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EF2D60C61; Wed, 17 Feb 2021 17:32:30 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Roderick Colenbrander , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 11/11] HID: playstation: add DualSense player LED support. Date: Wed, 17 Feb 2021 18:31:58 +0100 Message-Id: <20210217173158.3122868-12-benjamin.tissoires@redhat.com> In-Reply-To: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> References: <20210217173158.3122868-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Roderick Colenbrander 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 Reviewed-by: Barnabás Pőcze Signed-off-by: Benjamin Tissoires --- 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 #include #include +#include #include #include @@ -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.");