aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <wnhuang@chromium.org>2018-03-14 21:28:25 -0400
committerJiri Kosina <jkosina@suse.cz>2018-03-27 08:46:54 -0400
commitbc774b8c110f7d90d13257b95b5a22f5bb7fd71b (patch)
treeb3e9dcc0b0747bdd9abff13ddf6fc8887d8f47c4
parent183b6366cf473ff0e706a6751adc082faa44843d (diff)
HID: google: add google hammer HID driver
Add Google hammer HID driver. This driver allow us to control hammer keyboard backlight and support future features. Signed-off-by: Wei-Ning Huang <wnhuang@google.com> Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/Kconfig6
-rw-r--r--drivers/hid/Makefile1
-rw-r--r--drivers/hid/hid-google-hammer.c124
-rw-r--r--drivers/hid/hid-ids.h3
4 files changed, 134 insertions, 0 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 19c499f5623d..a18e06b81165 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -331,6 +331,12 @@ config HOLTEK_FF
331 Say Y here if you have a Holtek On Line Grip based game controller 331 Say Y here if you have a Holtek On Line Grip based game controller
332 and want to have force feedback support for it. 332 and want to have force feedback support for it.
333 333
334config HID_GOOGLE_HAMMER
335 tristate "Google Hammer Keyboard"
336 depends on USB_HID && LEDS_CLASS
337 ---help---
338 Say Y here if you have a Google Hammer device.
339
334config HID_GT683R 340config HID_GT683R
335 tristate "MSI GT68xR LED support" 341 tristate "MSI GT68xR LED support"
336 depends on LEDS_CLASS && USB_HID 342 depends on LEDS_CLASS && USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index eb13b9e92d85..4e9b57a44e96 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_HID_ELO) += hid-elo.o
44obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o 44obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o
45obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o 45obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o
46obj-$(CONFIG_HID_GFRM) += hid-gfrm.o 46obj-$(CONFIG_HID_GFRM) += hid-gfrm.o
47obj-$(CONFIG_HID_GOOGLE_HAMMER) += hid-google-hammer.o
47obj-$(CONFIG_HID_GT683R) += hid-gt683r.o 48obj-$(CONFIG_HID_GT683R) += hid-gt683r.o
48obj-$(CONFIG_HID_GYRATION) += hid-gyration.o 49obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
49obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o 50obj-$(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 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * HID driver for Google Hammer device.
4 *
5 * Copyright (c) 2017 Google Inc.
6 * Author: Wei-Ning Huang <wnhuang@google.com>
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16#include <linux/hid.h>
17#include <linux/leds.h>
18#include <linux/module.h>
19
20#include "hid-ids.h"
21
22#define MAX_BRIGHTNESS 100
23
24/* HID usage for keyboard backlight (Alphanumeric display brightness) */
25#define HID_AD_BRIGHTNESS 0x00140046
26
27struct hammer_kbd_leds {
28 struct led_classdev cdev;
29 struct hid_device *hdev;
30 u8 buf[2] ____cacheline_aligned;
31};
32
33static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev,
34 enum led_brightness br)
35{
36 struct hammer_kbd_leds *led = container_of(cdev,
37 struct hammer_kbd_leds,
38 cdev);
39 int ret;
40
41 led->buf[0] = 0;
42 led->buf[1] = br;
43
44 ret = hid_hw_output_report(led->hdev, led->buf, sizeof(led->buf));
45 if (ret == -ENOSYS)
46 ret = hid_hw_raw_request(led->hdev, 0, led->buf,
47 sizeof(led->buf),
48 HID_OUTPUT_REPORT,
49 HID_REQ_SET_REPORT);
50 if (ret < 0)
51 hid_err(led->hdev, "failed to set keyboard backlight: %d\n",
52 ret);
53 return ret;
54}
55
56static int hammer_register_leds(struct hid_device *hdev)
57{
58 struct hammer_kbd_leds *kbd_backlight;
59
60 kbd_backlight = devm_kzalloc(&hdev->dev,
61 sizeof(*kbd_backlight),
62 GFP_KERNEL);
63 if (!kbd_backlight)
64 return -ENOMEM;
65
66 kbd_backlight->hdev = hdev;
67 kbd_backlight->cdev.name = "hammer::kbd_backlight";
68 kbd_backlight->cdev.max_brightness = MAX_BRIGHTNESS;
69 kbd_backlight->cdev.brightness_set_blocking =
70 hammer_kbd_brightness_set_blocking;
71 kbd_backlight->cdev.flags = LED_HW_PLUGGABLE;
72
73 /* Set backlight to 0% initially. */
74 hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0);
75
76 return devm_led_classdev_register(&hdev->dev, &kbd_backlight->cdev);
77}
78
79static int hammer_input_configured(struct hid_device *hdev,
80 struct hid_input *hi)
81{
82 struct list_head *report_list =
83 &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
84 struct hid_report *report;
85
86 if (list_empty(report_list))
87 return 0;
88
89 report = list_first_entry(report_list, struct hid_report, list);
90
91 if (report->maxfield == 1 &&
92 report->field[0]->application == HID_GD_KEYBOARD &&
93 report->field[0]->maxusage == 1 &&
94 report->field[0]->usage[0].hid == HID_AD_BRIGHTNESS) {
95 int err = hammer_register_leds(hdev);
96
97 if (err)
98 hid_warn(hdev,
99 "Failed to register keyboard backlight: %d\n",
100 err);
101 }
102
103 return 0;
104}
105
106static const struct hid_device_id hammer_devices[] = {
107 { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
108 USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_HAMMER) },
109 { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
110 USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STAFF) },
111 { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
112 USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_WAND) },
113 { }
114};
115MODULE_DEVICE_TABLE(hid, hammer_devices);
116
117static struct hid_driver hammer_driver = {
118 .name = "hammer",
119 .id_table = hammer_devices,
120 .input_configured = hammer_input_configured,
121};
122module_hid_driver(hammer_driver);
123
124MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 43ddcdfbd0da..360c2893bb2d 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -445,7 +445,10 @@
445#define USB_DEVICE_ID_GOODTOUCH_000f 0x000f 445#define USB_DEVICE_ID_GOODTOUCH_000f 0x000f
446 446
447#define USB_VENDOR_ID_GOOGLE 0x18d1 447#define USB_VENDOR_ID_GOOGLE 0x18d1
448#define USB_DEVICE_ID_GOOGLE_HAMMER 0x5022
448#define USB_DEVICE_ID_GOOGLE_TOUCH_ROSE 0x5028 449#define USB_DEVICE_ID_GOOGLE_TOUCH_ROSE 0x5028
450#define USB_DEVICE_ID_GOOGLE_STAFF 0x502b
451#define USB_DEVICE_ID_GOOGLE_WAND 0x502d
449 452
450#define USB_VENDOR_ID_GOTOP 0x08f2 453#define USB_VENDOR_ID_GOTOP 0x08f2
451#define USB_DEVICE_ID_SUPER_Q2 0x007f 454#define USB_DEVICE_ID_SUPER_Q2 0x007f