From patchwork Thu Sep 7 08:37:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei-Ning Huang X-Patchwork-Id: 9941773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF230602CC for ; Thu, 7 Sep 2017 08:38:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC920283B0 for ; Thu, 7 Sep 2017 08:38:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C16612856C; Thu, 7 Sep 2017 08:38:04 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 EC3AE283B0 for ; Thu, 7 Sep 2017 08:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932077AbdIGIiD (ORCPT ); Thu, 7 Sep 2017 04:38:03 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:38811 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075AbdIGIiB (ORCPT ); Thu, 7 Sep 2017 04:38:01 -0400 Received: by mail-pg0-f42.google.com with SMTP id v66so19628701pgb.5 for ; Thu, 07 Sep 2017 01:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=wtQxZEG3az0ZYXWC05Yd8cLO2XJArm9qSaP1VH+JBQQ=; b=IdRmDVriZDeLd2nRxQwCLZQat/8oTLpqZeTCRmeIOvkJ3Vv+XS9w9yIAderfh8zc4m nBkaSvP5HRpAAMjPvy8egM9QSs9+BP6eUArLaV1TiauESJG2B2JRlUvsTSnpRo4RtGzS 28aB+yn3hY+3ojq/DOlMJ0TiTqVPm/u88pUUE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wtQxZEG3az0ZYXWC05Yd8cLO2XJArm9qSaP1VH+JBQQ=; b=LcH+BSBFcpF0kNVq7HVIS1l5YaLled4NErFXshXQoAyAIXQIQoEXWU48UAZdkLgSuc 7cQUwEd6qXJgtwBb+qoc6kYILPA5qL/ArjCFRUPPsUvQt+lHrLAfMZBVGXiwri8ADJVW h907pwPNaw0+tgTivE/JUyD7/D0B4SS1WrkYsjfnWo52vQ/TEpZ1s+i/6OXeDrpTfHPZ MMOlpv1deHyqObF8nD7cjhJGf6Y17KIiwK3IWjRIZvKyuqD++n6ZaaTTSgepMGdySky6 DAreFov5p4FxlY9s+4+2ciBma52mib7NyxYKpKviyYSmeXk6MRtPwFV2ucK5yUSX2lAV Uq+w== X-Gm-Message-State: AHPjjUiJfhyopk5UzloEQ2T8hp+Cok6xZeh5dboyxH1BYh1a3ObcqIFY ac3kcBC9klssiGhe X-Google-Smtp-Source: ADKCNb4JWtfkbz3gOqy8mbibT1/uIl0SpNYD+BgwsnHzyDMBpAlTEjIKO9dQiBEAuSVNQfM+k3wTtQ== X-Received: by 10.99.124.87 with SMTP id l23mr1906031pgn.351.1504773480986; Thu, 07 Sep 2017 01:38:00 -0700 (PDT) Received: from wnhuang0.tpe.corp.google.com ([2401:fa00:1:b:5:4807:cf63:125c]) by smtp.gmail.com with ESMTPSA id w4sm2923494pfa.8.2017.09.07.01.37.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Sep 2017 01:37:59 -0700 (PDT) From: Wei-Ning Huang X-Google-Original-From: Wei-Ning Huang To: LKML , Linux Input Cc: Dmitry Torokhov , Nicolas Boichat , Wei-Ning Huang , Wei-Ning Huang Subject: [PATCH v3] HID: google: add google hammer HID driver Date: Thu, 7 Sep 2017 16:37:43 +0800 Message-Id: <20170907083743.31389-1-wnhuang@google.com> X-Mailer: git-send-email 2.12.2 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: Wei-Ning Huang Add Google hammer HID driver. This driver allow us to control hammer keyboard backlights and support future features. Since current hid-core logic does not allow us to specify different USB interface for binding different driver, some code are added in HID core to allow us to bind the touchpad to multitouch driver, and bind keyboard to the hammer driver and the same time. Signed-off-by: Wei-Ning Huang Reviewed-by: Dmitry Torokhov --- drivers/hid/Kconfig | 6 +++ drivers/hid/Makefile | 1 + drivers/hid/hid-core.c | 33 ++++++++++-- drivers/hid/hid-google-hammer.c | 110 ++++++++++++++++++++++++++++++++++++++++ drivers/hid/hid-ids.h | 2 + include/linux/hid.h | 1 + 6 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 drivers/hid/hid-google-hammer.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 0a3117cc29e7..5373887f056e 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -329,6 +329,12 @@ config HOLTEK_FF Say Y here if you have a Holtek On Line Grip based game controller and want to have force feedback support for it. +config HID_GOOGLE_HAMMER + tristate "Google Hammer Keyboard" + depends on USB_HID && LEDS_CLASS + ---help--- + Say Y here if you have a Google Hammer device. + config HID_GT683R tristate "MSI GT68xR LED support" depends on LEDS_CLASS && USB_HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 8659d7e633a5..b5d3039286e3 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -43,6 +43,7 @@ obj-$(CONFIG_HID_ELO) += hid-elo.o obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o obj-$(CONFIG_HID_GFRM) += hid-gfrm.o +obj-$(CONFIG_HID_GOOGLE_HAMMER) += hid-google-hammer.o obj-$(CONFIG_HID_GT683R) += hid-gt683r.o obj-$(CONFIG_HID_GYRATION) += hid-gyration.o obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 9bc91160819b..78d2dbc74cce 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -44,6 +44,12 @@ #define DRIVER_DESC "HID core driver" +/* + * Qurik that is pass to the driver_data of struct hid_device_id indicating + * that some of the interfaces on the bus should not use the generic hid driver. + */ +#define QUIRK_NO_HID_GENERIC BIT(0) + int hid_debug = 0; module_param_named(debug, hid_debug, int, 0600); MODULE_PARM_DESC(debug, "toggle HID debugging messages"); @@ -2053,6 +2059,12 @@ static const struct hid_device_id hid_have_special_driver[] = { #if IS_ENABLED(CONFIG_HID_GREENASIA) { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) }, #endif +#if IS_ENABLED(CONFIG_HID_GOOGLE_HAMMER) + { HID_USB_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_HAMMER), + .driver_data = QUIRK_NO_HID_GENERIC }, + { HID_USB_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STAFF), + .driver_data = QUIRK_NO_HID_GENERIC }, +#endif #if IS_ENABLED(CONFIG_HID_GT683R) { HID_USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) }, #endif @@ -2952,11 +2964,22 @@ int hid_add_device(struct hid_device *hdev) */ if (hid_ignore_special_drivers) { hdev->group = HID_GROUP_GENERIC; - } else if (!hdev->group && - !hid_match_id(hdev, hid_have_special_driver)) { - ret = hid_scan_report(hdev); - if (ret) - hid_warn(hdev, "bad device descriptor (%d)\n", ret); + } else if (!hdev->group) { + const struct hid_device_id *matched_id = hid_match_id( + hdev, hid_have_special_driver); + + if (!matched_id || + matched_id->driver_data & QUIRK_NO_HID_GENERIC) { + ret = hid_scan_report(hdev); + if (ret) + hid_warn(hdev, "bad device descriptor (%d)\n", + ret); + + if (matched_id && + matched_id->driver_data & QUIRK_NO_HID_GENERIC && + hdev->group == HID_GROUP_GENERIC) + hdev->group = HID_GROUP_GENERIC_OVERRIDE; + } } /* XXX hack, any other cleaner solution after the driver core diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c new file mode 100644 index 000000000000..4d301e1a6707 --- /dev/null +++ b/drivers/hid/hid-google-hammer.c @@ -0,0 +1,110 @@ +/* + * HID driver for Google Hammer device. + * + * Copyright (c) 2017 Google Inc. + * Author: Wei-Ning Huang + */ + +/* + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#include +#include +#include +#include + +#include "hid-ids.h" + +#define MAX_BRIGHTNESS 100 + +struct hammer_kbd_leds { + struct led_classdev cdev; + struct hid_device *hdev; + u8 buf[2] ____cacheline_aligned; +}; + +static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev, + enum led_brightness br) +{ + struct hammer_kbd_leds *led = container_of(cdev, + struct hammer_kbd_leds, + cdev); + int ret; + + led->buf[0] = 0; + led->buf[1] = br; + + ret = hid_hw_output_report(led->hdev, led->buf, sizeof(led->buf)); + if (ret == -ENOSYS) + ret = hid_hw_raw_request(led->hdev, 0, led->buf, + sizeof(led->buf), + HID_OUTPUT_REPORT, + HID_REQ_SET_REPORT); + if (ret < 0) + hid_err(led->hdev, "failed to set keyboard backlight: %d\n", + ret); + return ret; +} + +static int hammer_register_leds(struct hid_device *hdev) +{ + struct hammer_kbd_leds *kbd_backlight; + + kbd_backlight = devm_kzalloc(&hdev->dev, + sizeof(*kbd_backlight), + GFP_KERNEL); + if (!kbd_backlight) + return -ENOMEM; + + kbd_backlight->hdev = hdev; + kbd_backlight->cdev.name = "hammer::kbd_backlight"; + kbd_backlight->cdev.max_brightness = MAX_BRIGHTNESS; + kbd_backlight->cdev.brightness_set_blocking = + hammer_kbd_brightness_set_blocking; + kbd_backlight->cdev.flags = LED_HW_PLUGGABLE; + + /* Set backlight to 0% initially. */ + hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0); + + return devm_led_classdev_register(&hdev->dev, &kbd_backlight->cdev); +} + +static int hammer_input_configured(struct hid_device *hdev, + struct hid_input *hi) +{ + struct usb_interface *intf = to_usb_interface(hdev->dev.parent); + + if (intf->cur_altsetting->desc.bInterfaceProtocol == + USB_INTERFACE_PROTOCOL_KEYBOARD) { + int err = hammer_register_leds(hdev); + + if (err) + hid_warn(hdev, + "Failed to register keyboard backlight: %d\n", + err); + } + + return 0; +} + +static const struct hid_device_id hammer_devices[] = { + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC_OVERRIDE, + USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_HAMMER) }, + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC_OVERRIDE, + USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STAFF) }, + { } +}; +MODULE_DEVICE_TABLE(hid, hammer_devices); + +static struct hid_driver hammer_driver = { + .name = "hammer", + .id_table = hammer_devices, + .input_configured = hammer_input_configured, +}; +module_hid_driver(hammer_driver); + +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index b397a14ab970..112ae4053321 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -436,7 +436,9 @@ #define USB_DEVICE_ID_GOODTOUCH_000f 0x000f #define USB_VENDOR_ID_GOOGLE 0x18d1 +#define USB_DEVICE_ID_GOOGLE_HAMMER 0x5022 #define USB_DEVICE_ID_GOOGLE_TOUCH_ROSE 0x5028 +#define USB_DEVICE_ID_GOOGLE_STAFF 0x502b #define USB_VENDOR_ID_GOTOP 0x08f2 #define USB_DEVICE_ID_SUPER_Q2 0x007f diff --git a/include/linux/hid.h b/include/linux/hid.h index ab05a86269dc..e34430cfc8b8 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -356,6 +356,7 @@ struct hid_item { #define HID_GROUP_MULTITOUCH 0x0002 #define HID_GROUP_SENSOR_HUB 0x0003 #define HID_GROUP_MULTITOUCH_WIN_8 0x0004 +#define HID_GROUP_GENERIC_OVERRIDE 0x0005 /* * Vendor specific HID device groups