1diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S 2index 31fdb55cd4e2..af8007128720 100644 3--- a/arch/arm64/kernel/vmlinux.lds.S 4+++ b/arch/arm64/kernel/vmlinux.lds.S 5@@ -201,6 +201,15 @@ SECTIONS 6 INIT_RAM_FS 7 *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */ 8 } 9+ 10+#ifdef CONFIG_DRIVERS_HDF 11+ .init.hdf_table : { 12+ _hdf_drivers_start = .; 13+ *(.hdf.driver) 14+ _hdf_drivers_end = .; 15+ } 16+#endif 17+ 18 .exit.data : { 19 EXIT_DATA 20 } 21diff --git a/drivers/Kconfig b/drivers/Kconfig 22index 216c52363bd2..e104a7c94012 100644 23--- a/drivers/Kconfig 24+++ b/drivers/Kconfig 25@@ -236,6 +236,8 @@ source "drivers/interconnect/Kconfig" 26 27 source "drivers/counter/Kconfig" 28 29+source "drivers/hdf/khdf/Kconfig" 30+ 31 source "drivers/most/Kconfig" 32 33 source "drivers/accesstokenid/Kconfig" 34diff --git a/drivers/Makefile b/drivers/Makefile 35index d0ff4fdb0dfb..eed836a925e2 100644 36--- a/drivers/Makefile 37+++ b/drivers/Makefile 38@@ -192,6 +192,7 @@ obj-$(CONFIG_SIOX) += siox/ 39 obj-$(CONFIG_GNSS) += gnss/ 40 obj-$(CONFIG_INTERCONNECT) += interconnect/ 41 obj-$(CONFIG_COUNTER) += counter/ 42+obj-$(CONFIG_DRIVERS_HDF) += hdf/ 43 obj-$(CONFIG_MOST) += most/ 44 obj-$(CONFIG_ACCESS_TOKENID) += accesstokenid/ 45 obj-$(CONFIG_VENDOR_HOOKS) += hooks/ 46diff --git a/drivers/hdf/Makefile b/drivers/hdf/Makefile 47new file mode 100644 48index 000000000000..5c5e1911c4f7 49--- /dev/null 50+++ b/drivers/hdf/Makefile 51@@ -0,0 +1,2 @@ 52+export PROJECT_ROOT := ../../../../../ 53+obj-$(CONFIG_DRIVERS_HDF) += khdf/ 54diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile 55index 4acb583c92a6..13cf16851759 100644 56--- a/drivers/hid/Makefile 57+++ b/drivers/hid/Makefile 58@@ -2,6 +2,19 @@ 59 # 60 # Makefile for the HID driver 61 # 62+HDF_ROOT_DIR = -I$(srctree)/drivers/hdf 63+ccflags-$(CONFIG_DRIVERS_HDF_INPUT) += $(HDF_ROOT_DIR)/framework/model/input/driver \ 64+ $(HDF_ROOT_DIR)/framework/include/core \ 65+ $(HDF_ROOT_DIR)/framework/core/common/include/host \ 66+ $(HDF_ROOT_DIR)/framework/include/utils \ 67+ $(HDF_ROOT_DIR)/framework/include/osal \ 68+ $(HDF_ROOT_DIR)/framework/ability/sbuf/include \ 69+ $(HDF_ROOT_DIR)/inner_api/utils \ 70+ $(HDF_ROOT_DIR)/inner_api/osal/shared \ 71+ $(HDF_ROOT_DIR)/inner_api/host/shared \ 72+ $(HDF_ROOT_DIR)/inner_api/core \ 73+ $(HDF_ROOT_DIR)/khdf/osal/include \ 74+ $(HDF_ROOT_DIR)/evdev 75 hid-y := hid-core.o hid-input.o hid-quirks.o 76 hid-$(CONFIG_DEBUG_FS) += hid-debug.o 77 78diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c 79index fefbd0cc05ea..891cae9aa84b 100644 80--- a/drivers/hid/hid-core.c 81+++ b/drivers/hid/hid-core.c 82@@ -27,12 +27,16 @@ 83 #include <linux/vmalloc.h> 84 #include <linux/sched.h> 85 #include <linux/semaphore.h> 86+#include <linux/delay.h> 87 88 #include <linux/hid.h> 89 #include <linux/hiddev.h> 90 #include <linux/hid-debug.h> 91 #include <linux/hidraw.h> 92 93+#if defined(CONFIG_DRIVERS_HDF_INPUT) 94+#include "hdf_hid_adapter.h" 95+#endif 96 #include "hid-ids.h" 97 98 /* 99@@ -1539,6 +1543,11 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field, 100 hidinput_hid_event(hid, field, usage, value); 101 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 102 hid->hiddev_hid_event(hid, field, usage, value); 103+#if defined(CONFIG_DRIVERS_HDF_INPUT) 104+ if (hid->input_dev) { 105+ HidReportEvent(hid->input_dev, usage->type, usage->code, value); 106+ } 107+#endif 108 } 109 110 /* 111@@ -1949,6 +1958,87 @@ static const struct device_attribute dev_attr_country = { 112 .show = show_country, 113 }; 114 115+#if defined(CONFIG_DRIVERS_HDF_INPUT) 116+static bool check_mouse(char *name) 117+{ 118+ int i; 119+ static char *option[]={"Mouse", "mouse", "MOUSE", "Razer"}; 120+ for (i = 0; i < 4; i++) { 121+ if (strstr(name, option[i])) 122+ return true; 123+ } 124+ return false; 125+} 126+static bool check_kbd(char *name) 127+{ 128+ int i; 129+ static char *option[]={"Keyboard", "keyboard"}; 130+ for (i = 0; i < 2; i++) { 131+ if (strstr(name, option[i])) 132+ return true; 133+ } 134+ return false; 135+} 136+static bool check_rocker(char *name) 137+{ 138+ int i; 139+ static char *option[]={"Thrustmaster"}; 140+ for (i = 0; i < 1; i++) { 141+ if (strstr(name, option[i])) 142+ return true; 143+ } 144+ return false; 145+} 146+static bool check_encoder(char *name) 147+{ 148+ if (strcmp(name, "Wired KeyBoard") == 0) { 149+ return true; 150+ } 151+ return false; 152+} 153+static bool check_trackball(char *name) 154+{ 155+ int i; 156+ static char *option[]={"Trackball"}; 157+ for (i = 0; i < 1; i++) { 158+ if (strstr(name, option[i])) 159+ return true; 160+ } 161+ return false; 162+} 163+static void notify_connect_event(struct hid_device *hdev) 164+{ 165+ bool check; 166+ int type = -1; 167+ HidInfo *dev = (HidInfo *)kmalloc(sizeof(HidInfo), GFP_KERNEL); 168+ if (dev == NULL) { 169+ printk("%s: malloc failed", __func__); 170+ return; 171+ } 172+ type = check_mouse(hdev->name)?HID_TYPE_MOUSE:type; 173+ type = check_kbd(hdev->name)?HID_TYPE_KEYBOARD:type; 174+ type = check_rocker(hdev->name)?HID_TYPE_ROCKER:type; 175+ type = check_encoder(hdev->name)?HID_TYPE_ENCODER:type; 176+ type = check_trackball(hdev->name)?HID_TYPE_TRACKBALL:type; 177+ if ( type < 0) { 178+ kfree(dev); 179+ dev = NULL; 180+ return; 181+ } 182+ 183+ if (type == 35 || type == 36) 184+ mdelay(500); 185+ dev->devType = type; 186+ dev->devName = hdev->name; 187+ hdev->input_dev = HidRegisterHdfInputDev(dev); 188+ if (hdev->input_dev == NULL) { 189+ printk("%s: RegisterInputDevice failed\n", __func__); 190+ } 191+ kfree(dev); 192+ dev = NULL; 193+} 194+#endif 195+ 196 int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 197 { 198 static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 199@@ -2041,6 +2131,9 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 200 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 201 buf, bus, hdev->version >> 8, hdev->version & 0xff, 202 type, hdev->name, hdev->phys); 203+#if defined(CONFIG_DRIVERS_HDF_INPUT) 204+ notify_connect_event(hdev); 205+#endif 206 207 return 0; 208 } 209@@ -2056,6 +2149,10 @@ void hid_disconnect(struct hid_device *hdev) 210 if (hdev->claimed & HID_CLAIMED_HIDRAW) 211 hidraw_disconnect(hdev); 212 hdev->claimed = 0; 213+#if defined(CONFIG_DRIVERS_HDF_INPUT) 214+ if (hdev->input_dev) 215+ HidUnregisterHdfInputDev(hdev->input_dev); 216+#endif 217 } 218 EXPORT_SYMBOL_GPL(hid_disconnect); 219 220@@ -2140,6 +2237,11 @@ EXPORT_SYMBOL_GPL(hid_hw_open); 221 */ 222 void hid_hw_close(struct hid_device *hdev) 223 { 224+#if defined(CONFIG_DRIVERS_HDF_INPUT) 225+ if (hdev->input_dev) { 226+ return; 227+ } 228+#endif 229 mutex_lock(&hdev->ll_open_lock); 230 if (!--hdev->ll_open_count) 231 hdev->ll_driver->close(hdev); 232diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c 233index 3399953256d8..a869b1bd2ba1 100644 234--- a/drivers/hid/hid-input.c 235+++ b/drivers/hid/hid-input.c 236@@ -20,6 +20,10 @@ 237 #include <linux/hid.h> 238 #include <linux/hid-debug.h> 239 240+#if defined(CONFIG_DRIVERS_HDF_INPUT) 241+#include "hdf_hid_adapter.h" 242+#endif 243+ 244 #include "hid-ids.h" 245 246 #define unk KEY_UNKNOWN 247@@ -1437,7 +1441,15 @@ void hidinput_report_event(struct hid_device *hid, struct hid_report *report) 248 return; 249 250 list_for_each_entry(hidinput, &hid->inputs, list) 251+#if defined(CONFIG_DRIVERS_HDF_INPUT) 252+ { 253+#endif 254 input_sync(hidinput->input); 255+#if defined(CONFIG_DRIVERS_HDF_INPUT) 256+ if(hid->input_dev) 257+ HidReportEvent(hid->input_dev, EV_SYN, SYN_REPORT, 0); 258+ } 259+#endif 260 } 261 EXPORT_SYMBOL_GPL(hidinput_report_event); 262 263@@ -1888,6 +1900,42 @@ static inline void hidinput_configure_usages(struct hid_input *hidinput, 264 report->field[i]->usage + j); 265 } 266 267+#if defined(CONFIG_DRIVERS_HDF_INPUT) 268+static void transfer_info(struct input_dev *dev) 269+{ 270+ int i; 271+ HidInfo *info = (HidInfo *)kmalloc(sizeof(HidInfo),GFP_KERNEL); 272+ if (info == NULL) { 273+ printk("%s: malloc failed\n",__func__); 274+ return; 275+ } 276+ info->devName = dev->name; 277+ memcpy(info->devProp, dev->propbit, sizeof(unsigned long) * BITS_TO_LONGS(INPUT_PROP_CNT)); 278+ memcpy(info->eventType, dev->evbit, sizeof(unsigned long) * BITS_TO_LONGS(EV_CNT)); 279+ memcpy(info->keyCode, dev->keybit, sizeof(unsigned long) * BITS_TO_LONGS(KEY_CNT)); 280+ memcpy(info->relCode, dev->relbit, sizeof(unsigned long) * BITS_TO_LONGS(REL_CNT)); 281+ memcpy(info->absCode, dev->absbit, sizeof(unsigned long) * BITS_TO_LONGS(ABS_CNT)); 282+ memcpy(info->miscCode, dev->mscbit, sizeof(unsigned long) * BITS_TO_LONGS(MSC_CNT)); 283+ memcpy(info->ledCode, dev->ledbit, sizeof(unsigned long) * BITS_TO_LONGS(LED_CNT)); 284+ memcpy(info->soundCode, dev->sndbit, sizeof(unsigned long) * BITS_TO_LONGS(SND_CNT)); 285+ memcpy(info->forceCode, dev->ffbit, sizeof(unsigned long) * BITS_TO_LONGS(FF_CNT)); 286+ memcpy(info->switchCode, dev->swbit, sizeof(unsigned long) * BITS_TO_LONGS(SW_CNT)); 287+ for (i = 0; i < BITS_TO_LONGS(ABS_CNT); i++) { 288+ if (dev->absbit[i] != 0) { 289+ memcpy(info->axisInfo, dev->absinfo, sizeof(struct input_absinfo) * ABS_CNT); 290+ break; 291+ } 292+ } 293+ info->bustype = dev->id.bustype; 294+ info->vendor = dev->id.vendor; 295+ info->product = dev->id.product; 296+ info->version = dev->id.version; 297+ SendInfoToHdf(info); 298+ kfree(info); 299+ info = NULL; 300+} 301+#endif 302+ 303 /* 304 * Register the input device; print a message. 305 * Configure the input layer interface 306@@ -1973,6 +2021,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) 307 continue; 308 } 309 310+#if defined(CONFIG_DRIVERS_HDF_INPUT) 311+ transfer_info(hidinput->input); 312+#endif 313 if (input_register_device(hidinput->input)) 314 goto out_unwind; 315 hidinput->registered = true; 316diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile 317index a48e5f2d859d..e73ac1412fec 100644 318--- a/drivers/input/misc/Makefile 319+++ b/drivers/input/misc/Makefile 320@@ -85,3 +85,21 @@ obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o 321 obj-$(CONFIG_INPUT_YEALINK) += yealink.o 322 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o 323 324+ccflags-y +=-I$(srctree)/drivers/hdf/framework/model/input/driver \ 325+ -I$(srctree)/drivers/hdf/framework/model/input/driver/input_bus_ops \ 326+ -I$(srctree)/drivers/hdf/framework/include/core \ 327+ -I$(srctree)/drivers/hdf/framework/core/common/include/host \ 328+ -I$(srctree)/drivers/hdf/framework/include/utils \ 329+ -I$(srctree)/drivers/hdf/framework/include/osal \ 330+ -I$(srctree)/drivers/hdf/framework/include/platform \ 331+ -I$(srctree)/drivers/hdf/framework/include/config \ 332+ -I$(srctree)/drivers/hdf/framework/core/host/include \ 333+ -I$(srctree)/drivers/hdf/framework/core/shared/include \ 334+ -I$(srctree)/drivers/hdf/framework/utils/include \ 335+ -I$(srctree)/drivers/hdf/inner_api/osal/shared \ 336+ -I$(srctree)/drivers/hdf/inner_api/host/shared \ 337+ -I$(srctree)/drivers/hdf/inner_api/utils \ 338+ -I$(srctree)/drivers/hdf/inner_api/core \ 339+ -I$(srctree)/drivers/hdf/khdf/osal/include 340+ccflags-y +=-I$(srctree)/bounds_checking_function/include \ 341+ -I$(srctree)/drivers/hdf/evdev 342diff --git a/drivers/input/misc/rk805-pwrkey.c b/drivers/input/misc/rk805-pwrkey.c 343index 76873aa005b4..34ed66bdc553 100644 344--- a/drivers/input/misc/rk805-pwrkey.c 345+++ b/drivers/input/misc/rk805-pwrkey.c 346@@ -14,6 +14,9 @@ 347 #include <linux/kernel.h> 348 #include <linux/module.h> 349 #include <linux/platform_device.h> 350+#include "hdf_hid_adapter.h" 351+ 352+InputDevice *HidinputDev=NULL; 353 354 static irqreturn_t pwrkey_fall_irq(int irq, void *_pwr) 355 { 356@@ -22,6 +25,8 @@ static irqreturn_t pwrkey_fall_irq(int irq, void *_pwr) 357 input_report_key(pwr, KEY_POWER, 1); 358 input_sync(pwr); 359 360+ HidReportEvent(HidinputDev, EV_KEY, KEY_POWER, 1); 361+ HidReportEvent(HidinputDev, EV_SYN, SYN_REPORT, 0); 362 return IRQ_HANDLED; 363 } 364 365@@ -32,9 +37,24 @@ static irqreturn_t pwrkey_rise_irq(int irq, void *_pwr) 366 input_report_key(pwr, KEY_POWER, 0); 367 input_sync(pwr); 368 369+ HidReportEvent(HidinputDev, EV_KEY, KEY_POWER, 0); 370+ HidReportEvent(HidinputDev, EV_SYN, SYN_REPORT, 0); 371 return IRQ_HANDLED; 372 } 373 374+static InputDevice* HidRegisterHdfPowerKeyDev(void) 375+{ 376+ InputDevice* inputDev = NULL; 377+ HidInfo Hid_keyInfo; 378+ 379+ Hid_keyInfo.devType = HID_TYPE_KEY; 380+ Hid_keyInfo.eventType[0] = SET_BIT(EV_KEY); 381+ Hid_keyInfo.keyCode[3] = SET_BIT(KEY_POWER); 382+ Hid_keyInfo.devName = "hid-powerkey"; 383+ inputDev = HidRegisterHdfInputDev(&Hid_keyInfo); 384+ return inputDev; 385+} 386+ 387 static int rk805_pwrkey_probe(struct platform_device *pdev) 388 { 389 struct input_dev *pwr; 390@@ -87,6 +107,11 @@ static int rk805_pwrkey_probe(struct platform_device *pdev) 391 platform_set_drvdata(pdev, pwr); 392 device_init_wakeup(&pdev->dev, true); 393 394+ HidinputDev = HidRegisterHdfPowerKeyDev(); 395+ if (NULL == HidinputDev) { 396+ pr_err("HidRegisterHdfInputDev error\n"); 397+ return -EINVAL; 398+ } 399 return 0; 400 } 401 402diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c 403index 505c562a5daa..67d451beba08 100644 404--- a/drivers/input/mousedev.c 405+++ b/drivers/input/mousedev.c 406@@ -869,7 +869,7 @@ static struct mousedev *mousedev_create(struct input_dev *dev, 407 408 if (mixdev) { 409 dev_set_name(&mousedev->dev, "mice"); 410- 411+ mousedev->open = 1; 412 mousedev->open_device = mixdev_open_devices; 413 mousedev->close_device = mixdev_close_devices; 414 } else { 415diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c 416index e6143663778f..8256d576c762 100644 417--- a/drivers/usb/core/notify.c 418+++ b/drivers/usb/core/notify.c 419@@ -66,3 +66,12 @@ void usb_notify_remove_bus(struct usb_bus *ubus) 420 { 421 blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus); 422 } 423+ 424+void usb_notify_online_status(bool online) 425+{ 426+ if (online) { 427+ blocking_notifier_call_chain(&usb_notifier_list, USB_GADGET_ADD, NULL); 428+ } else { 429+ blocking_notifier_call_chain(&usb_notifier_list, USB_GADGET_REMOVE, NULL); 430+ } 431+} 432diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c 433index 667fa8e8856d..aaa35ae6e3e9 100644 434--- a/drivers/usb/dwc3/gadget.c 435+++ b/drivers/usb/dwc3/gadget.c 436@@ -3706,6 +3706,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, 437 { 438 switch (event->type) { 439 case DWC3_DEVICE_EVENT_DISCONNECT: 440+ usb_notify_online_status(false); 441 dwc3_gadget_disconnect_interrupt(dwc); 442 break; 443 case DWC3_DEVICE_EVENT_RESET: 444@@ -3713,6 +3714,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, 445 break; 446 case DWC3_DEVICE_EVENT_CONNECT_DONE: 447 dwc3_gadget_conndone_interrupt(dwc); 448+ usb_notify_online_status(true); 449 break; 450 case DWC3_DEVICE_EVENT_WAKEUP: 451 dwc3_gadget_wakeup_interrupt(dwc); 452diff --git a/include/linux/hid.h b/include/linux/hid.h 453index 9e306bf9959d..bfa39304e51f 100644 454--- a/include/linux/hid.h 455+++ b/include/linux/hid.h 456@@ -624,6 +624,7 @@ struct hid_device { /* device report descriptor */ 457 struct list_head debug_list; 458 spinlock_t debug_list_lock; 459 wait_queue_head_t debug_wait; 460+ void *input_dev; 461 struct kref ref; 462 463 unsigned int id; /* system unique id */ 464diff --git a/include/linux/usb.h b/include/linux/usb.h 465index e02cf70ca52f..ef55ce0f4850 100644 466--- a/include/linux/usb.h 467+++ b/include/linux/usb.h 468@@ -2024,8 +2024,11 @@ static inline int usb_translate_errors(int error_code) 469 #define USB_DEVICE_REMOVE 0x0002 470 #define USB_BUS_ADD 0x0003 471 #define USB_BUS_REMOVE 0x0004 472+#define USB_GADGET_ADD 0x0005 473+#define USB_GADGET_REMOVE 0x0006 474 extern void usb_register_notify(struct notifier_block *nb); 475 extern void usb_unregister_notify(struct notifier_block *nb); 476+extern void usb_notify_online_status(bool online); 477 478 /* debugfs stuff */ 479 extern struct dentry *usb_debug_root; 480