Received: by 10.213.65.68 with SMTP id h4csp1352069imn; Wed, 14 Mar 2018 18:30:04 -0700 (PDT) X-Google-Smtp-Source: AG47ELv6k8tFiWjUBbeUKKPUHuZL0MIknXqTd+lNwjVdOdCNVtlT2ECnw31OYaWICwMKphRMMXIv X-Received: by 2002:a17:902:4827:: with SMTP id s36-v6mr5943985pld.269.1521077404899; Wed, 14 Mar 2018 18:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521077404; cv=none; d=google.com; s=arc-20160816; b=vVDoQXCMecocxJhCjkciB/QfNRznDnGGaLzrFw5NLAN/JXsWni01e85RQtfJoC7Bwq muQ6b7ic4pRHt5VU12tGrOJgvd78Av3c9rDmefA9FPRn638rzWb6aekRU8CRt5WJONHf 4YqiTeUTP+8+VOU6y9bzRHImK8iO0xMDIySSREfxkYS6no08fmbbWteGIo8EmEsCICzw MyndUVDMGq+Vh6e2jEpPtGY11SKf6vcgCm3ebUEzeVXULyfMiTxVUyN7ZQvKB6L0y5f4 nlp+eQeB5TFGeoZFo2isNy3TgeRcrQ8S/2Ws0FehYyvkSFJaTYJystVfvK5uHEoZiyVE kjwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=zfcBwTEv3vxM8oSIjAX7VbRQknnPchaSwMMh74MrNaQ=; b=YbI/BTM6BTWZSjktMnC1hz1nUlSf6GTIiC1SgGPTBqj7i9XbGh0AGMuu1AjzNb/VJ1 jjX88H29/6aZwG52UO+flgHQBbl0HK5gmbKXR6thQ2ekYws9tSCOhGA8A8uG/63ShdFV CLTQnTVMquqbTxS87SPIUPfOEP2tsFcdly6q4J2/Wx++cMjEW9Jm+YbBcRP6RmWLrNWR cskjC+4+4jDPfSzFXVftemwRKC6fnNb9zXbGJTqXBi0rvcMakLhs1NIx6XP8LMe/rzlP uHynDUd+Zn+IHtB4ZYQTY2tBAzTQNO3i1DPfgLhFDqzPph2JjewopmAlzLLOKL5E0oYp 0uBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Irt0lcEK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si2930319pff.214.2018.03.14.18.29.48; Wed, 14 Mar 2018 18:30:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Irt0lcEK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751551AbeCOB2m (ORCPT + 99 others); Wed, 14 Mar 2018 21:28:42 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35981 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390AbeCOB2k (ORCPT ); Wed, 14 Mar 2018 21:28:40 -0400 Received: by mail-pg0-f65.google.com with SMTP id i14so2166251pgv.3 for ; Wed, 14 Mar 2018 18:28:40 -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=zfcBwTEv3vxM8oSIjAX7VbRQknnPchaSwMMh74MrNaQ=; b=Irt0lcEKmOswsZNAdJXdo1RS2NuUkH0BRvV2StWItOFdBtY33Lp7DOrZCbUzpUqe9z vPy79ntlLLpmAgGi49zdj/Z5m170KEitYmxI8LrUPmBAxs+VElIluQoOGkvSzpGKnVWf VzcPZBFc81lLiJp5/zaQTZLQv8WrutzEBdloQ= 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=zfcBwTEv3vxM8oSIjAX7VbRQknnPchaSwMMh74MrNaQ=; b=Dm7Um0+bvzl0IIDXeExqBLHdHUtBibRaZtQNK3zQzhz0V5eTrVQeL8eXK8+gPD9gkV D6jeR1iy+oVNDHjBdmjJkAuiKcCdi/Q0uamzLH73C98UIepsHYMUEYI4MXLiGD2Twp6m zyKB325anTkxrlH0nKVTmOoFO+vCGl2zFs7oEsmq94Uan/M9/izOKo1MzQDSDS+oSr7i jdpDYN7ZFcozCtZbKKS5FpGM2eFfYLI58p0BoG3JplDy4AqR9pHmkGiCos3n5QlOUVci 8vdg7cdv1nwvnGTLtzQhCY1Un6SMcjlPKt4SznkLRsbsz5UDW1RswCewY7zMdNHpPlCB pCtw== X-Gm-Message-State: AElRT7GttvvmQ1fD3E8EEr08NWPyRkGkGB9QwfcB2TNvMcZKfdwuwRiB 10gEz1EZvDVHzeYu6nHNRMygNFZjetM= X-Received: by 10.99.147.72 with SMTP id w8mr5457699pgm.208.1521077320243; Wed, 14 Mar 2018 18:28:40 -0700 (PDT) Received: from drinkcat.tpe.corp.google.com ([2401:fa00:1:b:9ba:cd16:d555:bacf]) by smtp.gmail.com with ESMTPSA id w129sm8616083pfd.155.2018.03.14.18.28.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 18:28:39 -0700 (PDT) From: Nicolas Boichat To: Jiri Kosina Cc: Benjamin Tissoires , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, groeck@chromium.org, dtor@chromium.org Subject: [PATCH] HID: google: add google hammer HID driver Date: Thu, 15 Mar 2018 09:28:25 +0800 Message-Id: <20180315012825.145329-1-drinkcat@chromium.org> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wei-Ning Huang Add Google hammer HID driver. This driver allow us to control hammer keyboard backlight and support future features. Signed-off-by: Wei-Ning Huang Signed-off-by: Nicolas Boichat --- Changes since v4: - HID quirk is actually not necessary, as recent kernel always prefers binding specialized drivers over hid-generic. - Rework backlight detection, relying only on HID report descriptor. We also make the test a little more specific, to make sure the output descriptor is actually a backlight control. Changes since v3: - Rebase on latest linux-next/master, which moved the quirk list from hid-core.c to hid-quirks.c. Also, completely rework the logic to make it possible to bind google-hammer driver to keyboard interface, and generic multitouch driver to touchpad interface, as it is much simpler to do now that quirks are read early in hid_add_device. - Add dynamic backlight detection support (only such devices have an output HID descriptor). - Add support for wand (one more USB product ID). - Add SPDX-License-Identifier, fix one minor formatting issue. drivers/hid/Kconfig | 6 ++ drivers/hid/Makefile | 1 + drivers/hid/hid-google-hammer.c | 124 ++++++++++++++++++++++++++++++++ drivers/hid/hid-ids.h | 3 + 4 files changed, 134 insertions(+) create mode 100644 drivers/hid/hid-google-hammer.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 1fce4c94e5ac..60252fd796f6 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -339,6 +339,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 713601c7bfa6..17a8bd97da9d 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -45,6 +45,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-google-hammer.c b/drivers/hid/hid-google-hammer.c new file mode 100644 index 000000000000..6486469ce0f6 --- /dev/null +++ b/drivers/hid/hid-google-hammer.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * 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 "hid-ids.h" + +#define MAX_BRIGHTNESS 100 + +/* HID usage for keyboard backlight (Alphanumeric display brightness) */ +#define HID_AD_BRIGHTNESS 0x00140046 + +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 list_head *report_list = + &hdev->report_enum[HID_OUTPUT_REPORT].report_list; + struct hid_report *report; + + if (list_empty(report_list)) + return 0; + + report = list_first_entry(report_list, struct hid_report, list); + + if (report->maxfield == 1 && + report->field[0]->application == HID_GD_KEYBOARD && + report->field[0]->maxusage == 1 && + report->field[0]->usage[0].hid == HID_AD_BRIGHTNESS) { + 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, + USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_HAMMER) }, + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, + USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STAFF) }, + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, + USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_WAND) }, + { } +}; +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 41f227a841fb..5a3a7ead3012 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -448,7 +448,10 @@ #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_DEVICE_ID_GOOGLE_WAND 0x502d #define USB_VENDOR_ID_GOTOP 0x08f2 #define USB_DEVICE_ID_SUPER_Q2 0x007f -- 2.16.2.804.g6dcf76e118-goog