From patchwork Sat Mar 30 11:24:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10878415 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BBF3139A for ; Sat, 30 Mar 2019 11:24:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76A6628EC6 for ; Sat, 30 Mar 2019 11:24:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AFF228FEB; Sat, 30 Mar 2019 11:24:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C7DE28EC6 for ; Sat, 30 Mar 2019 11:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730700AbfC3LYy (ORCPT ); Sat, 30 Mar 2019 07:24:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48182 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730684AbfC3LYy (ORCPT ); Sat, 30 Mar 2019 07:24:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24F6D308339D; Sat, 30 Mar 2019 11:24:54 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AF6B18AB6; Sat, 30 Mar 2019 11:24:52 +0000 (UTC) From: Hans de Goede To: Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , Nestor Lopez Casado , linux-input@vger.kernel.org Subject: [PATCH 19/28] HID: logitech-hidpp: create a name based on the type if non available Date: Sat, 30 Mar 2019 12:24:09 +0100 Message-Id: <20190330112418.15042-20-hdegoede@redhat.com> In-Reply-To: <20190330112418.15042-1-hdegoede@redhat.com> References: <20190330112418.15042-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 30 Mar 2019 11:24:54 +0000 (UTC) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Benjamin Tissoires Some low cost devices don't even have a name (nor a serial) registered in the receiver. In those case, create a better name that "Logitech USB Receiver" or even "Logitech " if we try to get their name. Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-logitech-hidpp.c | 55 ++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index b950a44157a2..887af6068985 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -717,9 +717,28 @@ static int hidpp10_battery_event(struct hidpp_device *hidpp, u8 *data, int size) } #define HIDPP_REG_PAIRING_INFORMATION 0xB5 +#define HIDPP_PAIRING_INFORMATION 0x20 #define HIDPP_EXTENDED_PAIRING 0x30 #define HIDPP_DEVICE_NAME 0x40 +static int hidpp_unifying_get_type(struct hidpp_device *hidpp_dev) +{ + struct hidpp_report response; + int ret; + u8 params[1] = { HIDPP_PAIRING_INFORMATION }; + + ret = hidpp_send_rap_command_sync(hidpp_dev, + REPORT_ID_HIDPP_SHORT, + HIDPP_GET_LONG_REGISTER, + HIDPP_REG_PAIRING_INFORMATION, + params, 1, &response); + if (ret) + return ret; + + return response.rap.params[7]; + +} + static char *hidpp_unifying_get_name(struct hidpp_device *hidpp_dev) { struct hidpp_report response; @@ -741,6 +760,9 @@ static char *hidpp_unifying_get_name(struct hidpp_device *hidpp_dev) if (2 + len > sizeof(response.rap.params)) return NULL; + if (len < 4) /* logitech devices are usually at least Xddd */ + return 0; + name = kzalloc(len + 1, GFP_KERNEL); if (!name) return NULL; @@ -778,7 +800,7 @@ static int hidpp_unifying_get_serial(struct hidpp_device *hidpp, u32 *serial) static int hidpp_unifying_init(struct hidpp_device *hidpp) { struct hid_device *hdev = hidpp->hid_dev; - const char *name; + const char *name = NULL; u32 serial; int ret; @@ -791,8 +813,35 @@ static int hidpp_unifying_init(struct hidpp_device *hidpp) dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq); name = hidpp_unifying_get_name(hidpp); - if (!name) - return -EIO; + if (!name) { + ret = hidpp_unifying_get_type(hidpp); + if (ret < 0) + return ret; + + switch (ret) { + case 0x01: + name = "Logitech Wireless Keyboard"; + break; + case 0x02: + name = "Logitech Wireless Mouse"; + break; + case 0x03: + name = "Logitech Wireless Numpad"; + break; + case 0x04: + name = "Logitech Wireless Presenter"; + break; + case 0x08: + name = "Logitech Wireless Trackball"; + break; + case 0x09: + name = "Logitech Wireless Touchpad"; + break; + } + if (name) + snprintf(hdev->name, sizeof(hdev->name), "%s", name); + return 0; + } snprintf(hdev->name, sizeof(hdev->name), "%s", name); dbg_hid("HID++ Unifying: Got name: %s\n", name);