Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  HID driver for some samsung "special" devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (c) 1999 Andreas Gal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (c) 2006-2007 Jiri Kosina
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Copyright (c) 2008 Jiri Slaby
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  This driver supports several HID devices:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  [0419:0001] Samsung IrDA remote controller (reports as Cypress USB Mouse).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *	various hid report fixups for different variants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  [0419:0600] Creative Desktop Wireless 6000 keyboard/mouse combo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *	several key mappings used from the consumer usage page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *	deviate from the USB HUT 1.12 standard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * There are several variants for 0419:0001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * 1. 184 byte report descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * Vendor specific report #4 has a size of 48 bit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * and therefore is not accepted when inspecting the descriptors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * As a workaround we reinterpret the report as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *   Variable type, count 6, size 8 bit, log. maximum 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * The burden to reconstruct the data is moved into user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * 2. 203 byte report descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * Report #4 has an array field with logical range 0..18 instead of 1..15.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * 3. 135 byte report descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * Report #4 has an array field with logical range 0..17 instead of 1..14.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * 4. 171 byte report descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Report #3 has an array field with logical range 0..1 instead of 1..3.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static inline void samsung_irda_dev_trace(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		unsigned int rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	hid_info(hdev, "fixing up Samsung IrDA %d byte report descriptor\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		 rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (*rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			rdesc[182] == 0x40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		samsung_irda_dev_trace(hdev, 184);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		rdesc[176] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		rdesc[178] = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		rdesc[180] = 0x06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		rdesc[182] = 0x42;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (*rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			rdesc[194] == 0x25 && rdesc[195] == 0x12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		samsung_irda_dev_trace(hdev, 203);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		rdesc[193] = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		rdesc[195] = 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (*rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			rdesc[126] == 0x25 && rdesc[127] == 0x11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		samsung_irda_dev_trace(hdev, 135);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		rdesc[125] = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		rdesc[127] = 0xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (*rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			rdesc[162] == 0x25 && rdesc[163] == 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		samsung_irda_dev_trace(hdev, 171);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		rdesc[161] = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		rdesc[163] = 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define samsung_kbd_mouse_map_key_clear(c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct hid_input *hi, struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (1 != ifnum || HID_UP_CONSUMER != (usage->hid & HID_USAGE_PAGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	dbg_hid("samsung wireless keyboard/mouse input mapping event [0x%x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		usage->hid & HID_USAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	switch (usage->hid & HID_USAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	/* report 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	case 0x183: samsung_kbd_mouse_map_key_clear(KEY_MEDIA); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	case 0x195: samsung_kbd_mouse_map_key_clear(KEY_EMAIL);	break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	case 0x196: samsung_kbd_mouse_map_key_clear(KEY_CALC); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	case 0x197: samsung_kbd_mouse_map_key_clear(KEY_COMPUTER); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case 0x22b: samsung_kbd_mouse_map_key_clear(KEY_SEARCH); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	case 0x22c: samsung_kbd_mouse_map_key_clear(KEY_WWW); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	case 0x22d: samsung_kbd_mouse_map_key_clear(KEY_BACK); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case 0x22e: samsung_kbd_mouse_map_key_clear(KEY_FORWARD); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	case 0x22f: samsung_kbd_mouse_map_key_clear(KEY_FAVORITES); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	case 0x230: samsung_kbd_mouse_map_key_clear(KEY_REFRESH); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	case 0x231: samsung_kbd_mouse_map_key_clear(KEY_STOP); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static __u8 *samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		rdesc = samsung_irda_report_fixup(hdev, rdesc, rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE == hdev->product)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		ret = samsung_kbd_mouse_input_mapping(hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int samsung_probe(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	unsigned int cmask = HID_CONNECT_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (!hid_is_usb(hdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		if (hdev->rsize == 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			/* disable hidinput, force hiddev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			cmask = (cmask & ~HID_CONNECT_HIDINPUT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				HID_CONNECT_HIDDEV_FORCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ret = hid_hw_start(hdev, cmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static const struct hid_device_id samsung_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) MODULE_DEVICE_TABLE(hid, samsung_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static struct hid_driver samsung_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.name = "samsung",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.id_table = samsung_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	.report_fixup = samsung_report_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	.input_mapping = samsung_input_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	.probe = samsung_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) module_hid_driver(samsung_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MODULE_LICENSE("GPL");