1diff -Naur a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S 2--- a/arch/arm/kernel/vmlinux.lds.S 2022-04-15 21:05:12.061104033 +0800 3+++ b/arch/arm/kernel/vmlinux.lds.S 2022-04-20 19:17:58.757083993 +0800 4@@ -131,6 +131,14 @@ 5 __pv_table_end = .; 6 } 7 8+#ifdef CONFIG_DRIVERS_HDF 9+ .init.hdf_table : { 10+ _hdf_drivers_start = .; 11+ *(.hdf.driver) 12+ _hdf_drivers_end = .; 13+ } 14+#endif 15+ 16 INIT_DATA_SECTION(16) 17 18 .exit.data : { 19diff -Naur a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S 20--- a/arch/arm64/kernel/vmlinux.lds.S 2022-04-18 15:08:13.387423111 +0800 21+++ b/arch/arm64/kernel/vmlinux.lds.S 2022-04-20 19:17:58.757083993 +0800 22@@ -201,6 +201,15 @@ 23 INIT_RAM_FS 24 *(.init.rodata.* .init.bss) /* from the EFI stub */ 25 } 26+ 27+#ifdef CONFIG_DRIVERS_HDF 28+ .init.hdf_table : { 29+ _hdf_drivers_start = .; 30+ *(.hdf.driver) 31+ _hdf_drivers_end = .; 32+ } 33+#endif 34+ 35 .exit.data : { 36 EXIT_DATA 37 } 38diff -Naur a/drivers/hdf/Makefile b/drivers/hdf/Makefile 39--- a/drivers/hdf/Makefile 1970-01-01 08:00:00.000000000 +0800 40+++ b/drivers/hdf/Makefile 2022-04-20 19:17:58.761084044 +0800 41@@ -0,0 +1,2 @@ 42+export PROJECT_ROOT := ../../../../../ 43+obj-$(CONFIG_DRIVERS_HDF) += khdf/ 44diff -Naur a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c 45--- a/drivers/hid/hid-core.c 2022-04-15 21:05:13.893124179 +0800 46+++ b/drivers/hid/hid-core.c 2022-04-20 19:17:58.761084044 +0800 47@@ -33,6 +33,9 @@ 48 #include <linux/hid-debug.h> 49 #include <linux/hidraw.h> 50 51+#if defined(CONFIG_DRIVERS_HDF_INPUT) 52+#include "hdf_hid_adapter.h" 53+#endif 54 #include "hid-ids.h" 55 56 /* 57@@ -1522,6 +1525,11 @@ 58 hidinput_hid_event(hid, field, usage, value); 59 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 60 hid->hiddev_hid_event(hid, field, usage, value); 61+#if defined(CONFIG_DRIVERS_HDF_INPUT) 62+ if (hid->input_dev) { 63+ HidReportEvent(hid->input_dev, usage->type, usage->code, value); 64+ } 65+#endif 66 } 67 68 /* 69@@ -1928,6 +1936,85 @@ 70 .show = show_country, 71 }; 72 73+#if defined(CONFIG_DRIVERS_HDF_INPUT) 74+static bool check_mouse(char *name) 75+{ 76+ int i; 77+ static char *option[]={"Mouse", "mouse", "MOUSE", "Razer"}; 78+ for (i = 0; i < 4; i++) { 79+ if (strstr(name, option[i])) 80+ return true; 81+ } 82+ return false; 83+} 84+static bool check_kbd(char *name) 85+{ 86+ int i; 87+ static char *option[]={"Keyboard", "keyboard"}; 88+ for (i = 0; i < 2; i++) { 89+ if (strstr(name, option[i])) 90+ return true; 91+ } 92+ return false; 93+} 94+static bool check_rocker(char *name) 95+{ 96+ int i; 97+ static char *option[]={"Thrustmaster"}; 98+ for (i = 0; i < 1; i++) { 99+ if (strstr(name, option[i])) 100+ return true; 101+ } 102+ return false; 103+} 104+static bool check_encoder(char *name) 105+{ 106+ if (strcmp(name, "Wired KeyBoard") == 0) { 107+ return true; 108+ } 109+ return false; 110+} 111+static bool check_trackball(char *name) 112+{ 113+ int i; 114+ static char *option[]={"Trackball"}; 115+ for (i = 0; i < 1; i++) { 116+ if (strstr(name, option[i])) 117+ return true; 118+ } 119+ return false; 120+} 121+static void notify_connect_event(struct hid_device *hdev) 122+{ 123+ bool check; 124+ int type = -1; 125+ HidInfo *dev = (HidInfo *)kmalloc(sizeof(HidInfo), GFP_KERNEL); 126+ if (dev == NULL) { 127+ printk("%s: malloc failed", __func__); 128+ return; 129+ } 130+ type = check_mouse(hdev->name)?HID_TYPE_MOUSE:type; 131+ type = check_kbd(hdev->name)?HID_TYPE_KEYBOARD:type; 132+ type = check_rocker(hdev->name)?HID_TYPE_ROCKER:type; 133+ type = check_encoder(hdev->name)?HID_TYPE_ENCODER:type; 134+ type = check_trackball(hdev->name)?HID_TYPE_TRACKBALL:type; 135+ if (type < 0) { 136+ kfree(dev); 137+ dev = NULL; 138+ return; 139+ } 140+ 141+ dev->devType = type; 142+ dev->devName = hdev->name; 143+ hdev->input_dev = HidRegisterHdfInputDev(dev); 144+ if (hdev->input_dev == NULL) { 145+ printk("%s: RegisterInputDevice failed\n", __func__); 146+ } 147+ kfree(dev); 148+ dev = NULL; 149+} 150+#endif 151+ 152 int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 153 { 154 static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 155@@ -2020,6 +2107,9 @@ 156 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 157 buf, bus, hdev->version >> 8, hdev->version & 0xff, 158 type, hdev->name, hdev->phys); 159+#if defined(CONFIG_DRIVERS_HDF_INPUT) 160+ notify_connect_event(hdev); 161+#endif 162 163 return 0; 164 } 165@@ -2035,6 +2125,10 @@ 166 if (hdev->claimed & HID_CLAIMED_HIDRAW) 167 hidraw_disconnect(hdev); 168 hdev->claimed = 0; 169+#if defined(CONFIG_DRIVERS_HDF_INPUT) 170+ if (hdev->input_dev) 171+ HidUnregisterHdfInputDev(hdev->input_dev); 172+#endif 173 } 174 EXPORT_SYMBOL_GPL(hid_disconnect); 175 176@@ -2119,6 +2213,11 @@ 177 */ 178 void hid_hw_close(struct hid_device *hdev) 179 { 180+#if defined(CONFIG_DRIVERS_HDF_INPUT) 181+ if (hdev->input_dev) { 182+ return; 183+ } 184+#endif 185 mutex_lock(&hdev->ll_open_lock); 186 if (!--hdev->ll_open_count) 187 hdev->ll_driver->close(hdev); 188diff -Naur a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c 189--- a/drivers/hid/hid-input.c 2022-04-15 21:05:13.893124179 +0800 190+++ b/drivers/hid/hid-input.c 2022-04-20 19:17:58.761084044 +0800 191@@ -20,6 +20,10 @@ 192 #include <linux/hid.h> 193 #include <linux/hid-debug.h> 194 195+#if defined(CONFIG_DRIVERS_HDF_INPUT) 196+#include "hdf_hid_adapter.h" 197+#endif 198+ 199 #include "hid-ids.h" 200 201 #define unk KEY_UNKNOWN 202@@ -1416,7 +1420,15 @@ 203 return; 204 205 list_for_each_entry(hidinput, &hid->inputs, list) 206+#if defined(CONFIG_DRIVERS_HDF_INPUT) 207+ { 208+#endif 209 input_sync(hidinput->input); 210+#if defined(CONFIG_DRIVERS_HDF_INPUT) 211+ if(hid->input_dev) 212+ HidReportEvent(hid->input_dev, EV_SYN, SYN_REPORT, 0); 213+ } 214+#endif 215 } 216 EXPORT_SYMBOL_GPL(hidinput_report_event); 217 218@@ -1867,6 +1879,42 @@ 219 report->field[i]->usage + j); 220 } 221 222+#if defined(CONFIG_DRIVERS_HDF_INPUT) 223+static void transfer_info(struct input_dev *dev) 224+{ 225+ int i; 226+ HidInfo *info = (HidInfo *)kmalloc(sizeof(HidInfo),GFP_KERNEL); 227+ if (info == NULL) { 228+ printk("%s: malloc failed\n",__func__); 229+ return; 230+ } 231+ info->devName = dev->name; 232+ memcpy(info->devProp, dev->propbit, sizeof(unsigned long) * BITS_TO_LONGS(INPUT_PROP_CNT)); 233+ memcpy(info->eventType, dev->evbit, sizeof(unsigned long) * BITS_TO_LONGS(EV_CNT)); 234+ memcpy(info->keyCode, dev->keybit, sizeof(unsigned long) * BITS_TO_LONGS(KEY_CNT)); 235+ memcpy(info->relCode, dev->relbit, sizeof(unsigned long) * BITS_TO_LONGS(REL_CNT)); 236+ memcpy(info->absCode, dev->absbit, sizeof(unsigned long) * BITS_TO_LONGS(ABS_CNT)); 237+ memcpy(info->miscCode, dev->mscbit, sizeof(unsigned long) * BITS_TO_LONGS(MSC_CNT)); 238+ memcpy(info->ledCode, dev->ledbit, sizeof(unsigned long) * BITS_TO_LONGS(LED_CNT)); 239+ memcpy(info->soundCode, dev->sndbit, sizeof(unsigned long) * BITS_TO_LONGS(SND_CNT)); 240+ memcpy(info->forceCode, dev->ffbit, sizeof(unsigned long) * BITS_TO_LONGS(FF_CNT)); 241+ memcpy(info->switchCode, dev->swbit, sizeof(unsigned long) * BITS_TO_LONGS(SW_CNT)); 242+ for (i = 0; i < BITS_TO_LONGS(ABS_CNT); i++) { 243+ if (dev->absbit[i] != 0) { 244+ memcpy(info->axisInfo, dev->absinfo, sizeof(struct input_absinfo) * ABS_CNT); 245+ break; 246+ } 247+ } 248+ info->bustype = dev->id.bustype; 249+ info->vendor = dev->id.vendor; 250+ info->product = dev->id.product; 251+ info->version = dev->id.version; 252+ SendInfoToHdf(info); 253+ kfree(info); 254+ info = NULL; 255+} 256+#endif 257+ 258 /* 259 * Register the input device; print a message. 260 * Configure the input layer interface 261@@ -1952,6 +2000,9 @@ 262 continue; 263 } 264 265+#if defined(CONFIG_DRIVERS_HDF_INPUT) 266+ transfer_info(hidinput->input); 267+#endif 268 if (input_register_device(hidinput->input)) 269 goto out_unwind; 270 hidinput->registered = true; 271diff -Naur a/drivers/hid/Makefile b/drivers/hid/Makefile 272--- a/drivers/hid/Makefile 2022-04-15 21:05:13.889124134 +0800 273+++ b/drivers/hid/Makefile 2022-04-20 19:17:58.761084044 +0800 274@@ -2,6 +2,15 @@ 275 # 276 # Makefile for the HID driver 277 # 278+HDF_ROOT_DIR = -I$(srctree)/drivers/hdf 279+ccflags-$(CONFIG_DRIVERS_HDF_INPUT) += $(HDF_ROOT_DIR)/framework/model/input/driver \ 280+ $(HDF_ROOT_DIR)/framework/include/core \ 281+ $(HDF_ROOT_DIR)/framework/core/common/include/host \ 282+ $(HDF_ROOT_DIR)/framework/include/utils \ 283+ $(HDF_ROOT_DIR)/framework/include/osal \ 284+ $(HDF_ROOT_DIR)/framework/ability/sbuf/include \ 285+ $(HDF_ROOT_DIR)/khdf/osal/include \ 286+ $(HDF_ROOT_DIR)/evdev 287 hid-y := hid-core.o hid-input.o hid-quirks.o 288 hid-$(CONFIG_DEBUG_FS) += hid-debug.o 289 290diff -Naur a/drivers/input/mousedev.c b/drivers/input/mousedev.c 291--- a/drivers/input/mousedev.c 2022-04-15 21:05:14.105126510 +0800 292+++ b/drivers/input/mousedev.c 2022-04-20 19:17:58.761084044 +0800 293@@ -869,7 +869,7 @@ 294 295 if (mixdev) { 296 dev_set_name(&mousedev->dev, "mice"); 297- 298+ mousedev->open = 1; 299 mousedev->open_device = mixdev_open_devices; 300 mousedev->close_device = mixdev_close_devices; 301 } else { 302diff -Naur a/drivers/Kconfig b/drivers/Kconfig 303--- a/drivers/Kconfig 2022-04-18 15:08:13.419423461 +0800 304+++ b/drivers/Kconfig 2022-04-20 19:17:58.761084044 +0800 305@@ -238,6 +238,8 @@ 306 307 source "drivers/counter/Kconfig" 308 309+source "drivers/hdf/khdf/Kconfig" 310+ 311 source "drivers/most/Kconfig" 312 313 source "drivers/accesstokenid/Kconfig" 314diff -Naur a/drivers/Makefile b/drivers/Makefile 315--- a/drivers/Makefile 2022-04-18 15:08:13.419423461 +0800 316+++ b/drivers/Makefile 2022-04-20 19:17:58.761084044 +0800 317@@ -192,5 +192,6 @@ 318 obj-$(CONFIG_INTERCONNECT) += interconnect/ 319 obj-$(CONFIG_ARCH_MESON) += amlogic/ 320 obj-$(CONFIG_COUNTER) += counter/ 321+obj-$(CONFIG_DRIVERS_HDF) += hdf/ 322 obj-$(CONFIG_MOST) += most/ 323 obj-$(CONFIG_ACCESS_TOKENID) += accesstokenid/ 324diff -Naur a/include/linux/hid.h b/include/linux/hid.h 325--- a/include/linux/hid.h 2022-04-15 21:05:16.257150172 +0800 326+++ b/include/linux/hid.h 2022-04-20 19:17:58.765084096 +0800 327@@ -622,6 +622,7 @@ 328 struct list_head debug_list; 329 spinlock_t debug_list_lock; 330 wait_queue_head_t debug_wait; 331+ void *input_dev; 332 }; 333 334 #define to_hid_device(pdev) \ 335