18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Jabra USB HID Driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2017 Niels Skou Olsen <nolsen@jabra.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/*
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/hid.h>
128c2ecf20Sopenharmony_ci#include <linux/module.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "hid-ids.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define HID_UP_VENDOR_DEFINED_MIN	0xff000000
178c2ecf20Sopenharmony_ci#define HID_UP_VENDOR_DEFINED_MAX	0xffff0000
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic int jabra_input_mapping(struct hid_device *hdev,
208c2ecf20Sopenharmony_ci			       struct hid_input *hi,
218c2ecf20Sopenharmony_ci			       struct hid_field *field,
228c2ecf20Sopenharmony_ci			       struct hid_usage *usage,
238c2ecf20Sopenharmony_ci			       unsigned long **bit, int *max)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	int is_vendor_defined =
268c2ecf20Sopenharmony_ci		((usage->hid & HID_USAGE_PAGE) >= HID_UP_VENDOR_DEFINED_MIN &&
278c2ecf20Sopenharmony_ci		 (usage->hid & HID_USAGE_PAGE) <= HID_UP_VENDOR_DEFINED_MAX);
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	dbg_hid("hid=0x%08x appl=0x%08x coll_idx=0x%02x usage_idx=0x%02x: %s\n",
308c2ecf20Sopenharmony_ci		usage->hid,
318c2ecf20Sopenharmony_ci		field->application,
328c2ecf20Sopenharmony_ci		usage->collection_index,
338c2ecf20Sopenharmony_ci		usage->usage_index,
348c2ecf20Sopenharmony_ci		is_vendor_defined ? "ignored" : "defaulted");
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	/* Ignore vendor defined usages, default map standard usages */
378c2ecf20Sopenharmony_ci	return is_vendor_defined ? -1 : 0;
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic const struct hid_device_id jabra_devices[] = {
418c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, HID_ANY_ID) },
428c2ecf20Sopenharmony_ci	{ }
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(hid, jabra_devices);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic struct hid_driver jabra_driver = {
478c2ecf20Sopenharmony_ci	.name = "jabra",
488c2ecf20Sopenharmony_ci	.id_table = jabra_devices,
498c2ecf20Sopenharmony_ci	.input_mapping = jabra_input_mapping,
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_cimodule_hid_driver(jabra_driver);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciMODULE_AUTHOR("Niels Skou Olsen <nolsen@jabra.com>");
548c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Jabra USB HID Driver");
558c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
56