18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  HID driver for TiVo Slide Bluetooth remote
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2011 Jarod Wilson <jarod@redhat.com>
68c2ecf20Sopenharmony_ci *  based on the hid-topseed driver, which is in turn, based on hid-cherry...
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/device.h>
138c2ecf20Sopenharmony_ci#include <linux/hid.h>
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "hid-ids.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define HID_UP_TIVOVENDOR	0xffff0000
198c2ecf20Sopenharmony_ci#define tivo_map_key_clear(c)	hid_map_usage_clear(hi, usage, bit, max, \
208c2ecf20Sopenharmony_ci					EV_KEY, (c))
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic int tivo_input_mapping(struct hid_device *hdev, struct hid_input *hi,
238c2ecf20Sopenharmony_ci		struct hid_field *field, struct hid_usage *usage,
248c2ecf20Sopenharmony_ci		unsigned long **bit, int *max)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	switch (usage->hid & HID_USAGE_PAGE) {
278c2ecf20Sopenharmony_ci	case HID_UP_TIVOVENDOR:
288c2ecf20Sopenharmony_ci		switch (usage->hid & HID_USAGE) {
298c2ecf20Sopenharmony_ci		/* TiVo button */
308c2ecf20Sopenharmony_ci		case 0x3d: tivo_map_key_clear(KEY_MEDIA);	break;
318c2ecf20Sopenharmony_ci		/* Live TV */
328c2ecf20Sopenharmony_ci		case 0x3e: tivo_map_key_clear(KEY_TV);		break;
338c2ecf20Sopenharmony_ci		/* Red thumbs down */
348c2ecf20Sopenharmony_ci		case 0x41: tivo_map_key_clear(KEY_KPMINUS);	break;
358c2ecf20Sopenharmony_ci		/* Green thumbs up */
368c2ecf20Sopenharmony_ci		case 0x42: tivo_map_key_clear(KEY_KPPLUS);	break;
378c2ecf20Sopenharmony_ci		default:
388c2ecf20Sopenharmony_ci			return 0;
398c2ecf20Sopenharmony_ci		}
408c2ecf20Sopenharmony_ci		break;
418c2ecf20Sopenharmony_ci	case HID_UP_CONSUMER:
428c2ecf20Sopenharmony_ci		switch (usage->hid & HID_USAGE) {
438c2ecf20Sopenharmony_ci		/* Enter/Last (default mapping: KEY_LAST) */
448c2ecf20Sopenharmony_ci		case 0x083: tivo_map_key_clear(KEY_ENTER);	break;
458c2ecf20Sopenharmony_ci		/* Info (default mapping: KEY_PROPS) */
468c2ecf20Sopenharmony_ci		case 0x209: tivo_map_key_clear(KEY_INFO);	break;
478c2ecf20Sopenharmony_ci		default:
488c2ecf20Sopenharmony_ci			return 0;
498c2ecf20Sopenharmony_ci		}
508c2ecf20Sopenharmony_ci		break;
518c2ecf20Sopenharmony_ci	default:
528c2ecf20Sopenharmony_ci		return 0;
538c2ecf20Sopenharmony_ci	}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	/* This means we found a matching mapping here, else, look in the
568c2ecf20Sopenharmony_ci	 * standard hid mappings in hid-input.c */
578c2ecf20Sopenharmony_ci	return 1;
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic const struct hid_device_id tivo_devices[] = {
618c2ecf20Sopenharmony_ci	/* TiVo Slide Bluetooth remote, pairs with a Broadcom dongle */
628c2ecf20Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
638c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
648c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_PRO) },
658c2ecf20Sopenharmony_ci	{ }
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(hid, tivo_devices);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic struct hid_driver tivo_driver = {
708c2ecf20Sopenharmony_ci	.name = "tivo_slide",
718c2ecf20Sopenharmony_ci	.id_table = tivo_devices,
728c2ecf20Sopenharmony_ci	.input_mapping = tivo_input_mapping,
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_cimodule_hid_driver(tivo_driver);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
778c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
78